Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
packs: the URL override reads from the host (#523)
nyblnete6a5389b26d7
diff --git a/scripts/test-packs.ts b/scripts/test-packs.tsindex e94c9642..b14d7518 100644--- a/scripts/test-packs.ts+++ b/scripts/test-packs.ts@@ -63,10 +63,14 @@ const sha256Hex = async (bytes: Uint8Array): Promise<string> =>.join('')// --- browser globals the module graph expects -------------------------------+/** what the dev override slot holds; cases set it */+let storedPacksUrl: string | null = nullObject.defineProperty(globalThis, 'localStorage', {configurable: true,- value: { getItem: () => null, setItem: () => {}, removeItem: () => {} },+ value: { getItem: (k: string) => (k === 'bento-packs-url' ? storedPacksUrl : null), setItem: () => {}, removeItem: () => {} },})+/** every URL fetched, in order — which channel the module actually spoke to */+const fetched: string[] = []// Swap ONLY the trust root: any EC JWK import (there is exactly one call site,// verifySigned's) resolves to the test public key. Everything else passes@@ -123,6 +127,7 @@ const res = (body: Uint8Array | string, status = 200) => ({Object.defineProperty(globalThis, 'fetch', {configurable: true,value: async (url: string, init?: { method?: string }) => {+ fetched.push(url)if (url === `${CHANNEL}/packs.json`) return servedIndex === null ? res('', 404) : res(servedIndex)if (url === `${CHANNEL}/${PACK_URL}`) {if (servedPack === null) return res('', 404)@@ -261,6 +266,34 @@ i18n.setLocale('tl')ok(i18n.t('Delete') === 'Delete', 'removing the pack removes its alias too')i18n.setLocale('en')+// --- the channel override reads from the host ------------------------------+//+// 'bento-packs-url' is a boot-read override. Where every local document+// shares one storage (file://, an opaque origin — kernel net.ts+// sharedStorageOrigin), it is ignored; on a real web origin it is honoured.+// Node has no `location`, so the module sees a shared origin by default —+// the fail-safe reading.+console.log('\nthe channel override')+{+ storedPacksUrl = 'https://evil.example/channel'+ fetched.length = 0+ await packs.availablePacks()+ ok(fetched.length > 0 && fetched.every((u) => u.startsWith(CHANNEL + '/')) && !fetched.some((u) => u.includes('evil.example')), `shared storage (the default here): the override is ignored, the default channel is spoken to (${fetched[0]})`)+ // a real web origin: the override is a developer's own setting and is honoured+ Object.defineProperty(globalThis, 'location', { configurable: true, value: { protocol: 'https:', origin: 'https://dev.example' } })+ Object.defineProperty(globalThis, 'self', { configurable: true, value: { origin: 'https://dev.example' } })+ fetched.length = 0+ await packs.availablePacks()+ ok(fetched.length > 0 && fetched.every((u) => u.startsWith('https://evil.example/channel/')), `a real origin: the override is honoured (${fetched[0]})`)+ // file:// is shared even with a location+ Object.defineProperty(globalThis, 'location', { configurable: true, value: { protocol: 'file:', origin: 'null' } })+ Object.defineProperty(globalThis, 'self', { configurable: true, value: { origin: 'null' } })+ fetched.length = 0+ await packs.availablePacks()+ ok(fetched.length > 0 && fetched.every((u) => u.startsWith(CHANNEL + '/')), 'file://: the override is ignored')+ storedPacksUrl = null+}+console.log(`\n${checks - failures}/${checks} checks passed`)if (failures) {console.error(`${failures} FAILED`)diff --git a/slides/src/packs.ts b/slides/src/packs.tsindex 8ae6c906..218d53fc 100644--- a/slides/src/packs.ts+++ b/slides/src/packs.ts@@ -22,20 +22,25 @@ import { appConfig } from '../../kernel/src/app.ts'import { addPack, removePack, type LanguagePack } from '../../kernel/src/i18n.ts'import { readShellBlocks, type ShellBlock } from '../../kernel/src/save.ts'import { fetchPinned, verifySigned } from '../../kernel/src/update.ts'-import { netFetch } from '../../kernel/src/net.ts'+import { netFetch, sharedStorageOrigin } from '../../kernel/src/net.ts'// Extension-explicit like the kernel imports above, so this module also loads// under plain node — scripts/test-packs.ts exercises the real thing.import { PACKED } from './i18n/packed.ts'import { lsGet } from '../../kernel/src/storage.ts'+const DEFAULT_CHANNEL = 'https://bento.page/releases/slides'+/*** Where the release channel publishes the pack index and the packs.* Dev override: localStorage 'bento-packs-url' — the same convention the* updater uses for 'bento-update-url', so a local channel can be pointed at* without a rebuild. (A URL, not pack data: nothing durable lives here.)+ * The override reads from the host: it is honoured only where storage is+ * this document's own (kernel net.ts sharedStorageOrigin), never where every+ * local document shares one.*/const channel = (): string =>- lsGet('bento-packs-url') ?? 'https://bento.page/releases/slides'+ (sharedStorageOrigin() ? null : lsGet('bento-packs-url')) ?? DEFAULT_CHANNELexport interface PackListing {lang: string