@fifthbell/brokaw 0.1.71 → 0.1.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -0
- package/dist/captured-catalog-browser.d.ts +26 -0
- package/dist/captured-catalog-browser.js +42 -0
- package/dist/captured-catalog-reader.d.ts +16 -0
- package/dist/captured-catalog-reader.js +113 -0
- package/dist/captured-catalog.d.ts +28 -0
- package/dist/captured-catalog.js +124 -0
- package/dist/components/live-program/LiveProgram.js +119 -311
- package/dist/components/live-program/components/WorldClocks.js +2 -1
- package/dist/components/live-program/components/slides/LiveEventSlide.js +2 -4
- package/dist/components/live-program/events.d.ts +7 -0
- package/dist/components/live-program/events.js +28 -5
- package/dist/components/live-program/hooks/useSSE.js +1 -2
- package/dist/components/live-program/i18n.js +1 -1
- package/dist/components/live-program/live-program-config.d.ts +70 -0
- package/dist/components/live-program/live-program-config.js +228 -0
- package/dist/components/live-program/program-data.d.ts +22 -0
- package/dist/components/live-program/program-data.js +23 -0
- package/dist/components/live-program/program-reload.d.ts +11 -0
- package/dist/components/live-program/program-reload.js +21 -0
- package/dist/components/live-program/segments/ArticlesSegment.d.ts +5 -0
- package/dist/components/live-program/segments/ArticlesSegment.js +15 -11
- package/dist/components/live-program/segments/EarthquakeSegment.d.ts +4 -0
- package/dist/components/live-program/segments/EarthquakeSegment.js +13 -10
- package/dist/components/live-program/segments/MarketsSegment.js +7 -2
- package/dist/components/live-program/segments/WeatherSegment.d.ts +5 -0
- package/dist/components/live-program/segments/WeatherSegment.js +7 -2
- package/dist/components/live-program/segments/fetchLiveEvents.d.ts +6 -0
- package/dist/components/live-program/segments/fetchLiveEvents.js +42 -27
- package/dist/components/live-program/source-retention.d.ts +14 -0
- package/dist/components/live-program/source-retention.js +26 -0
- package/dist/cronkite-manifest.d.ts +35 -0
- package/dist/cronkite-manifest.js +5 -26
- package/dist/cronkite-manifest.json +48 -1
- package/dist/layouts.d.ts +1 -1
- package/dist/live-program-page/index.html +2 -2
- package/dist/live-program-page/live-program-manifest.json +8 -8
- package/dist/live-program-page/live-program.v0.1.73.css +3 -0
- package/dist/live-program-page/live-program.v0.1.73.js +76 -0
- package/dist/manifest-validation.js +3 -1
- package/dist/renderer.browser.js +2 -0
- package/dist/renderer.core.js +3 -7
- package/dist/schemas/canonical-document.schema.json +69 -1
- package/dist/system-pages.d.ts +66 -0
- package/dist/system-pages.js +35 -0
- package/dist/types/canonical-article.js +3 -2
- package/dist/types/canonical-document-schema.generated.d.ts +132 -0
- package/dist/types/canonical-document-schema.generated.js +146 -0
- package/dist/types/canonical-document.generated.d.ts +34 -0
- package/package.json +10 -4
- package/src/partial-deps.json +9 -0
- package/src/styles/compiled.css +1 -1
- package/src/templates/partials/components/article-main.hbs +6 -5
- package/src/templates/partials/components/media/main.hbs +3 -2
- package/src/templates/partials/components/search/main.hbs +3 -3
- package/src/templates/partials/headers/header-main.hbs +11 -19
- package/src/templates/partials/shell/captured-catalog.hbs +1 -0
- package/dist/live-program-page/live-program.v0.1.71.css +0 -3
- package/dist/live-program-page/live-program.v0.1.71.js +0 -76
package/README.md
CHANGED
|
@@ -53,6 +53,11 @@ The root module also exports `cronkiteManifest`, `outletConfig`, `version`,
|
|
|
53
53
|
`liveProgramReleaseFiles`. See [docs/cronkite-compatibility.md](docs/cronkite-compatibility.md)
|
|
54
54
|
for ownership, validation, system-page, asset, and release-ordering details.
|
|
55
55
|
|
|
56
|
+
A document may carry an optional `capturedSelection`. When it does, every runtime
|
|
57
|
+
reader on the page (weather, menu navigation and previews, search, Mediathek)
|
|
58
|
+
reads that captured generation instead of its current source. Without one, the
|
|
59
|
+
page is unchanged. See [docs/captured-catalog-readers.md](docs/captured-catalog-readers.md).
|
|
60
|
+
|
|
56
61
|
## Fifthbell live-program bundle
|
|
57
62
|
|
|
58
63
|
`liveProgramPageFiles()` returns the deployable bundle as deterministic `{ key, body, contentType }` entries. It includes `index.html`, versioned JavaScript and CSS, every image/audio/font dependency, and `live-program-manifest.json`. The manifest records the Brokaw package version, renderer schema version, file byte sizes, content types, and SHA-256 digests. It is also an `alcantara.program-template` contract: it declares the renderer entrypoint, supported capabilities, accepted signals, and the runtime parameters Alcantara supplies. A publisher such as Cronkite must upload every returned key under the same public prefix; the relative URLs then work at any Cronkite-owned path.
|
|
@@ -100,6 +105,47 @@ npm pack --dry-run
|
|
|
100
105
|
npm run storybook
|
|
101
106
|
```
|
|
102
107
|
|
|
108
|
+
`npm run storybook`, `npm run build-storybook`, and `npm run test:storybook`
|
|
109
|
+
first build the package and prepare its public declaration and outlet metadata.
|
|
110
|
+
The metadata stories read those actual build artifacts from `package-metadata/`;
|
|
111
|
+
they do not import the Node renderer into a browser. Preparation rejects missing
|
|
112
|
+
or inconsistent package/version/manifest artifacts and removes previously served
|
|
113
|
+
metadata on failure. Only `cronkite-manifest.json` and `outlet-config.json` are
|
|
114
|
+
served from the generated `.cache/storybook-package-metadata` directory.
|
|
115
|
+
|
|
116
|
+
For headless browser checks, install the repository-pinned Chromium with
|
|
117
|
+
`npx playwright install chromium`, then run `npm run test:storybook`. These checks
|
|
118
|
+
exercise the registered stories in a real browser; unit tests remain available
|
|
119
|
+
separately through `npm run test:unit`.
|
|
120
|
+
|
|
121
|
+
`npm run test:coverage` runs the unit and browser projects together and writes
|
|
122
|
+
native Istanbul measurements to `coverage/coverage-final.json`. Each run keeps
|
|
123
|
+
its original reports and config observations in a new `coverage/run-*` directory.
|
|
124
|
+
The config supplement evaluates the unchanged actual Vitest config in two Node
|
|
125
|
+
ESM host contexts: with `__dirname` absent and with its real directory explicitly
|
|
126
|
+
provided. This exercises both supported config branches; it does not establish
|
|
127
|
+
historical CommonJS-loader acceptance. The collector verifies exact runtime
|
|
128
|
+
text, source identity and native ranges, then uses the same official AST
|
|
129
|
+
remapper and upstream Istanbul aggregation as the test toolchain. Overlapping
|
|
130
|
+
application/config records or changed source identities fail rather than
|
|
131
|
+
replacing counters.
|
|
132
|
+
|
|
133
|
+
Failed tests remain failures even when their native measurements are retained.
|
|
134
|
+
A generated report is not a 100% coverage claim or a Clouseau approval. The
|
|
135
|
+
complete-source gate also checks the scripts and configuration, not only `src`.
|
|
136
|
+
After coverage, generated `dist` and `storybook-static` JavaScript are removed
|
|
137
|
+
so they cannot duplicate the actual source inventory; run `npm run build` or
|
|
138
|
+
`npm run build-storybook` again when those artifacts are needed.
|
|
139
|
+
|
|
140
|
+
Live program refreshes adopt post-relevance changes even when event/post IDs and
|
|
141
|
+
counts stay the same. Audio bus updates preserve each instant's base gain and
|
|
142
|
+
apply mute/gain changes to an already playing song. Scene crossfades keep progress
|
|
143
|
+
within its valid range, and old fade/load callbacks cannot clear a newer scene's
|
|
144
|
+
media ownership. Unmounting cancels the component's pending media work and stops
|
|
145
|
+
its own media without stopping unrelated players. Acceptance stories use actual
|
|
146
|
+
browser decoding/playback with valid local PCM WAVs and normal pointer activation;
|
|
147
|
+
they do not claim physical audio-output verification.
|
|
148
|
+
|
|
103
149
|
## Publish flow
|
|
104
150
|
|
|
105
151
|
- CI validates typecheck, unit tests, and package build on pull requests and `main` pushes.
|
|
@@ -111,3 +157,62 @@ The `media-page` renderer emits one shared page for `/mediathek/<assignment-key>
|
|
|
111
157
|
Its browser script selects the assignment from the URL and fetches
|
|
112
158
|
`contents/assignments/<key>.json`; neither the HTML nor its canonical document is
|
|
113
159
|
assignment-specific. Storybook `Pages/MediaPage` uses Mediathek URLs.
|
|
160
|
+
|
|
161
|
+
Every `media-page` document must supply `assignmentMediaBaseUrl`: a completed
|
|
162
|
+
absolute HTTP(S) directory ending in `/contents/assignments/`, including its
|
|
163
|
+
trailing slash, without credentials, query or fragment. The browser appends only
|
|
164
|
+
the encoded opaque assignment key and `.json`; it does not infer an origin from
|
|
165
|
+
the page URL or use a package fallback. The static manifest document explicitly
|
|
166
|
+
supplies Fifthbell's preview value. Cronkite replaces it from its configured
|
|
167
|
+
tenant CDN directory for basement publication; a direct CMS render supplies its
|
|
168
|
+
own completed value.
|
|
169
|
+
|
|
170
|
+
The manifest declares this shell as a single `media-page` system variant at
|
|
171
|
+
`html/mediathek/index.html`. A basement refresh publishes it alongside search,
|
|
172
|
+
404 pages, and static assets. Ariston's successful-publication receipt handler
|
|
173
|
+
requests that refresh when it detects a new CLS version. Restarting Cronkite
|
|
174
|
+
loads npm `latest`; publication follows the CMS refresh, rather than startup.
|
|
175
|
+
Storybook `Pages/MediaPage/SharedSystemPage` previews the manifest document.
|
|
176
|
+
|
|
177
|
+
Local packed-consumer checks verify the source candidate; they do not publish or
|
|
178
|
+
adopt it. The current-main `0.1.72` article candidate and the earlier Mediathek
|
|
179
|
+
`0.1.72` rehearsal have different contents. A combined package needs its own
|
|
180
|
+
reviewed release artifact and explicit publication decision before normal
|
|
181
|
+
Cronkite adoption and the CMS-triggered refresh are verified together.
|
|
182
|
+
|
|
183
|
+
## Pull request verification
|
|
184
|
+
|
|
185
|
+
Local agent review uses the shared `clouseau` skill with the developer's
|
|
186
|
+
authenticated coding harness and the `.clouseau-local.json` recipe; it needs no
|
|
187
|
+
CI provider keys. `AGENTS.md` owns the rule: run it against the final committed
|
|
188
|
+
change before opening a PR, repair findings, and publish the passing signed
|
|
189
|
+
receipt in the initial ready PR body. Never push directly to `main`.
|
|
190
|
+
|
|
191
|
+
Every PR runs:
|
|
192
|
+
|
|
193
|
+
- `npm run typecheck`,
|
|
194
|
+
- the Vitest `unit` project also covers `scripts/*.test.ts` (packed-contract checks run against a fictional package through an offline `npm` shim) and `.storybook/*.test.ts` (Storybook main configuration),
|
|
195
|
+
- `npm run test:coverage`: the Vitest `unit` project under V8 coverage with exactly 100% line and branch coverage required over `src`,
|
|
196
|
+
- `npm run build` and the packed declarative contract check (`node scripts/verify-packed-contract.mjs`),
|
|
197
|
+
- the workflow-contract tests in `.github/tests`.
|
|
198
|
+
|
|
199
|
+
The Clouseau gate requires exactly 100% line and branch coverage over every
|
|
200
|
+
non-test file in `src`; new behaviour needs a test, never a coverage pragma.
|
|
201
|
+
Until the suite reaches that bar the coverage step fails, so a PR stays in
|
|
202
|
+
human review and is merged by the owner rather than automatically.
|
|
203
|
+
|
|
204
|
+
A PR carrying an authenticated local review stamp is verified by the pinned
|
|
205
|
+
Clouseau engine without AI credentials; unstamped PRs use the CI reviewer.
|
|
206
|
+
Passing reviews receive a bot approval and native auto-merge. Unresolved
|
|
207
|
+
product-direction questions go to the owner, and changes to review controls need
|
|
208
|
+
the owner's `/approve-intent <head SHA>` comment. See [the purpose
|
|
209
|
+
contract](.github/clouseau.md). The CI engine is resolved from protected
|
|
210
|
+
Clouseau `main` at the start of each run (see
|
|
211
|
+
[automatic Clouseau CI upgrades](https://github.com/gaulatti/clouseau/blob/main/docs/automatic-ci-upgrades.md)).
|
|
212
|
+
|
|
213
|
+
Package publication and the Storybook deployment stay separate, explicitly
|
|
214
|
+
authorized workflows outside this review contract.
|
|
215
|
+
|
|
216
|
+
CI needs these repository secrets: `DEEPSEEK_API_KEY` and `TYPESAFE_API_KEY` for
|
|
217
|
+
the CI reviewer, and `DEPLOYMENT_TOKEN` (a token with contents write access
|
|
218
|
+
from an identity other than `github-actions[bot]`) for automatic repairs.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type CapturedCatalogReader, type CapturedFetch } from './captured-catalog-reader.js';
|
|
2
|
+
/** The element `shell/captured-catalog` renders the CMS-issued selection into. */
|
|
3
|
+
export declare const CAPTURED_SELECTION_ELEMENT_ID = "brokaw-captured-selection";
|
|
4
|
+
interface ElementLike {
|
|
5
|
+
readonly textContent: string | null;
|
|
6
|
+
getAttribute(name: string): string | null;
|
|
7
|
+
}
|
|
8
|
+
/** The parts of a browser window the installer reads. */
|
|
9
|
+
export interface CapturedCatalogHost {
|
|
10
|
+
readonly document: {
|
|
11
|
+
readonly documentElement: {
|
|
12
|
+
readonly lang: string;
|
|
13
|
+
};
|
|
14
|
+
getElementById(id: string): ElementLike | null;
|
|
15
|
+
querySelector(selector: string): ElementLike | null;
|
|
16
|
+
};
|
|
17
|
+
fetch: CapturedFetch;
|
|
18
|
+
brokawCapturedCatalog?: CapturedCatalogReader;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Installs `brokawCapturedCatalog` for the page's readers. A selection that
|
|
22
|
+
* cannot be read installs a reader whose every read rejects, so the readers
|
|
23
|
+
* show their unavailable state and never fall back to their current sources.
|
|
24
|
+
*/
|
|
25
|
+
export declare function installCapturedCatalog(host: CapturedCatalogHost): void;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { CapturedCatalogError } from './captured-catalog.js';
|
|
2
|
+
import { CapturedReaderError, createCapturedCatalogReader, } from './captured-catalog-reader.js';
|
|
3
|
+
/** The element `shell/captured-catalog` renders the CMS-issued selection into. */
|
|
4
|
+
export const CAPTURED_SELECTION_ELEMENT_ID = 'brokaw-captured-selection';
|
|
5
|
+
function failingReader(error) {
|
|
6
|
+
return Object.freeze({
|
|
7
|
+
read: (_kind, _key) => Promise.reject(error),
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function canonicalOrigin(host) {
|
|
11
|
+
const href = host.document.querySelector("link[rel='canonical']")?.getAttribute('href');
|
|
12
|
+
try {
|
|
13
|
+
return new URL(String(href)).origin;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
throw new CapturedReaderError('page_mismatch');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Installs `brokawCapturedCatalog` for the page's readers. A selection that
|
|
21
|
+
* cannot be read installs a reader whose every read rejects, so the readers
|
|
22
|
+
* show their unavailable state and never fall back to their current sources.
|
|
23
|
+
*/
|
|
24
|
+
export function installCapturedCatalog(host) {
|
|
25
|
+
let reader;
|
|
26
|
+
try {
|
|
27
|
+
const element = host.document.getElementById(CAPTURED_SELECTION_ELEMENT_ID);
|
|
28
|
+
let selection;
|
|
29
|
+
try {
|
|
30
|
+
selection = JSON.parse(element?.textContent ?? '');
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
throw new CapturedCatalogError('invalid_selection');
|
|
34
|
+
}
|
|
35
|
+
const page = { origin: canonicalOrigin(host), locale: host.document.documentElement.lang };
|
|
36
|
+
reader = createCapturedCatalogReader(selection, page, (url, init) => host.fetch(url, init));
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
reader = failingReader(error);
|
|
40
|
+
}
|
|
41
|
+
host.brokawCapturedCatalog = reader;
|
|
42
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type CapturedResourceKind } from './captured-catalog.js';
|
|
2
|
+
export type CapturedReaderErrorCode = 'unavailable' | 'invalid_json' | 'page_mismatch' | 'resource_too_large';
|
|
3
|
+
export declare class CapturedReaderError extends Error {
|
|
4
|
+
readonly code: CapturedReaderErrorCode;
|
|
5
|
+
constructor(code: CapturedReaderErrorCode);
|
|
6
|
+
}
|
|
7
|
+
/** What the rendered page itself states, independently of the catalog. */
|
|
8
|
+
export interface CapturedPage {
|
|
9
|
+
readonly origin: string;
|
|
10
|
+
readonly locale: string;
|
|
11
|
+
}
|
|
12
|
+
export type CapturedFetch = (url: string, init: RequestInit) => Promise<Response>;
|
|
13
|
+
export interface CapturedCatalogReader {
|
|
14
|
+
read(kind: CapturedResourceKind, key: string): Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
export declare function createCapturedCatalogReader(selection: unknown, page: CapturedPage, fetchImpl: CapturedFetch): CapturedCatalogReader;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { CapturedCatalogError, resolveCapturedCatalog, } from './captured-catalog.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reader adapter for the captured-catalog contract (#29). A page whose
|
|
4
|
+
* document carries `capturedSelection` reads every runtime resource through
|
|
5
|
+
* this adapter; a page without one keeps its current sources untouched.
|
|
6
|
+
*/
|
|
7
|
+
// The catalog document has no issued checksum, so it gets the same ceiling
|
|
8
|
+
// the contract applies to resource bytes.
|
|
9
|
+
const MAX_CATALOG_BYTES = 8 * 1024 * 1024;
|
|
10
|
+
const MAX_RESOURCE_BYTES = 8 * 1024 * 1024;
|
|
11
|
+
export class CapturedReaderError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
constructor(code) {
|
|
14
|
+
super(`Captured catalog reader: ${code}`);
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.name = 'CapturedReaderError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// Issued locations are used exactly: no cookies, no cache and no redirect to
|
|
20
|
+
// a location the catalog did not issue.
|
|
21
|
+
const REQUEST = { cache: 'no-store', credentials: 'omit', redirect: 'error' };
|
|
22
|
+
/**
|
|
23
|
+
* Validates the selection without a catalog. The contract checks the selection
|
|
24
|
+
* before the catalog, so a well-formed selection fails only on the catalog.
|
|
25
|
+
*/
|
|
26
|
+
function assertSelection(selection) {
|
|
27
|
+
try {
|
|
28
|
+
resolveCapturedCatalog(selection, null);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error instanceof CapturedCatalogError && error.code === 'invalid_catalog')
|
|
32
|
+
return;
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
throw new CapturedCatalogError('invalid_selection');
|
|
36
|
+
}
|
|
37
|
+
async function readLimited(response, limit) {
|
|
38
|
+
if (!response.ok || !response.body)
|
|
39
|
+
throw new CapturedReaderError('unavailable');
|
|
40
|
+
if (Number(response.headers.get('content-length')) > limit)
|
|
41
|
+
throw new CapturedReaderError('resource_too_large');
|
|
42
|
+
const reader = response.body.getReader();
|
|
43
|
+
const chunks = [];
|
|
44
|
+
let total = 0;
|
|
45
|
+
for (;;) {
|
|
46
|
+
const { done, value } = await reader.read();
|
|
47
|
+
if (done)
|
|
48
|
+
break;
|
|
49
|
+
total += value.byteLength;
|
|
50
|
+
if (total > limit) {
|
|
51
|
+
await reader.cancel();
|
|
52
|
+
throw new CapturedReaderError('resource_too_large');
|
|
53
|
+
}
|
|
54
|
+
chunks.push(value);
|
|
55
|
+
}
|
|
56
|
+
const bytes = new Uint8Array(total);
|
|
57
|
+
let offset = 0;
|
|
58
|
+
for (const chunk of chunks) {
|
|
59
|
+
bytes.set(chunk, offset);
|
|
60
|
+
offset += chunk.byteLength;
|
|
61
|
+
}
|
|
62
|
+
return bytes;
|
|
63
|
+
}
|
|
64
|
+
function parseJson(bytes) {
|
|
65
|
+
try {
|
|
66
|
+
return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
throw new CapturedReaderError('invalid_json');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function fetchBytes(fetchImpl, url, limit) {
|
|
73
|
+
let response;
|
|
74
|
+
try {
|
|
75
|
+
response = await fetchImpl(url, REQUEST);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
throw new CapturedReaderError('unavailable');
|
|
79
|
+
}
|
|
80
|
+
return readLimited(response, limit);
|
|
81
|
+
}
|
|
82
|
+
export function createCapturedCatalogReader(selection, page, fetchImpl) {
|
|
83
|
+
let expected;
|
|
84
|
+
let setupError;
|
|
85
|
+
try {
|
|
86
|
+
assertSelection(selection);
|
|
87
|
+
const candidate = selection;
|
|
88
|
+
if (candidate.context.origin !== page.origin || candidate.locale !== page.locale) {
|
|
89
|
+
throw new CapturedReaderError('page_mismatch');
|
|
90
|
+
}
|
|
91
|
+
expected = candidate;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
setupError = error;
|
|
95
|
+
}
|
|
96
|
+
// Each read resolves the catalog again, so a withdrawal reaches the next
|
|
97
|
+
// read instead of being masked by an earlier resolution.
|
|
98
|
+
async function resolveCatalog() {
|
|
99
|
+
if (!expected)
|
|
100
|
+
throw setupError;
|
|
101
|
+
const raw = parseJson(await fetchBytes(fetchImpl, expected.catalogUrl, MAX_CATALOG_BYTES));
|
|
102
|
+
return resolveCapturedCatalog(selection, raw);
|
|
103
|
+
}
|
|
104
|
+
return Object.freeze({
|
|
105
|
+
async read(kind, key) {
|
|
106
|
+
const catalog = await resolveCatalog();
|
|
107
|
+
const descriptor = catalog.resource(key, kind);
|
|
108
|
+
const bytes = await fetchBytes(fetchImpl, descriptor.url, MAX_RESOURCE_BYTES);
|
|
109
|
+
await catalog.verifyBytes(key, kind, bytes);
|
|
110
|
+
return parseJson(bytes);
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { outletConfig } from './outlet-config.js';
|
|
2
|
+
declare const CONTEXT_KEYS: readonly ["rendererVersion", "templateVersion", "tenant", "origin", "build"];
|
|
3
|
+
declare const RESOURCE_KINDS: readonly ["navigation", "homepage", "category", "assignment", "media", "search", "weather", "system"];
|
|
4
|
+
export type CapturedContext = Readonly<Record<typeof CONTEXT_KEYS[number], string>>;
|
|
5
|
+
export type CapturedResourceKind = typeof RESOURCE_KINDS[number];
|
|
6
|
+
export type CapturedLocale = typeof outletConfig.supportedLanguages[number];
|
|
7
|
+
export type CapturedCatalogErrorCode = 'invalid_selection' | 'invalid_catalog' | 'context_mismatch' | 'withdrawn' | 'unknown_resource' | 'invalid_bytes' | 'resource_too_large' | 'integrity_unavailable' | 'integrity_mismatch';
|
|
8
|
+
export declare class CapturedCatalogError extends Error {
|
|
9
|
+
readonly code: CapturedCatalogErrorCode;
|
|
10
|
+
constructor(code: CapturedCatalogErrorCode);
|
|
11
|
+
}
|
|
12
|
+
export interface CapturedResource {
|
|
13
|
+
readonly key: string;
|
|
14
|
+
readonly kind: CapturedResourceKind;
|
|
15
|
+
readonly url: string;
|
|
16
|
+
readonly sha256: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ResolvedCapturedCatalog {
|
|
19
|
+
readonly selectionId: string;
|
|
20
|
+
readonly catalogUrl: string;
|
|
21
|
+
readonly context: CapturedContext;
|
|
22
|
+
readonly locale: CapturedLocale;
|
|
23
|
+
resource(key: string, kind: CapturedResourceKind): CapturedResource;
|
|
24
|
+
verifyBytes(key: string, kind: CapturedResourceKind, bytes: Uint8Array): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/** Dormant internal contract. No renderer, browser script or root export calls it. */
|
|
27
|
+
export declare function resolveCapturedCatalog(selection: unknown, rawCatalog: unknown): ResolvedCapturedCatalog | null;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { outletConfig } from './outlet-config.js';
|
|
2
|
+
const CONTEXT_KEYS = ['rendererVersion', 'templateVersion', 'tenant', 'origin', 'build'];
|
|
3
|
+
const RESOURCE_KINDS = ['navigation', 'homepage', 'category', 'assignment', 'media', 'search', 'weather', 'system'];
|
|
4
|
+
const TOKEN = /^[^\s\p{Cc}]{1,200}$/u;
|
|
5
|
+
const HASH = /^[a-f0-9]{64}$/;
|
|
6
|
+
const MAX_RESOURCES = 512;
|
|
7
|
+
const MAX_BYTES = 8 * 1024 * 1024;
|
|
8
|
+
export class CapturedCatalogError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
constructor(code) {
|
|
11
|
+
super(`Captured catalog: ${code}`);
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.name = 'CapturedCatalogError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function fail(code) {
|
|
17
|
+
throw new CapturedCatalogError(code);
|
|
18
|
+
}
|
|
19
|
+
function record(raw, keys, code) {
|
|
20
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
21
|
+
fail(code);
|
|
22
|
+
const actual = Object.keys(raw);
|
|
23
|
+
if (actual.length !== keys.length || keys.some(key => !Object.hasOwn(raw, key)))
|
|
24
|
+
fail(code);
|
|
25
|
+
return raw;
|
|
26
|
+
}
|
|
27
|
+
function token(raw, code) {
|
|
28
|
+
if (typeof raw !== 'string' || !TOKEN.test(raw))
|
|
29
|
+
fail(code);
|
|
30
|
+
return raw;
|
|
31
|
+
}
|
|
32
|
+
function url(raw, code, originOnly = false) {
|
|
33
|
+
const value = token(raw, code);
|
|
34
|
+
let parsed;
|
|
35
|
+
try {
|
|
36
|
+
parsed = new URL(value);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return fail(code);
|
|
40
|
+
}
|
|
41
|
+
if (parsed.protocol !== 'https:' || parsed.username || parsed.password || value.includes('#'))
|
|
42
|
+
fail(code);
|
|
43
|
+
// Reject normalization instead of silently repairing an issued location.
|
|
44
|
+
if ((originOnly ? parsed.origin : parsed.href) !== value)
|
|
45
|
+
fail(code);
|
|
46
|
+
return parsed;
|
|
47
|
+
}
|
|
48
|
+
function context(raw, code) {
|
|
49
|
+
const fields = record(raw, CONTEXT_KEYS, code);
|
|
50
|
+
const result = {};
|
|
51
|
+
for (const key of CONTEXT_KEYS)
|
|
52
|
+
result[key] = token(fields[key], code);
|
|
53
|
+
url(result.origin, code, true);
|
|
54
|
+
return Object.freeze(result);
|
|
55
|
+
}
|
|
56
|
+
function locale(raw, code) {
|
|
57
|
+
if (!outletConfig.supportedLanguages.includes(raw))
|
|
58
|
+
fail(code);
|
|
59
|
+
return raw;
|
|
60
|
+
}
|
|
61
|
+
/** Dormant internal contract. No renderer, browser script or root export calls it. */
|
|
62
|
+
export function resolveCapturedCatalog(selection, rawCatalog) {
|
|
63
|
+
if (selection === undefined)
|
|
64
|
+
return null;
|
|
65
|
+
const expected = record(selection, ['selectionId', 'catalogUrl', 'context', 'locale'], 'invalid_selection');
|
|
66
|
+
const selectionId = token(expected.selectionId, 'invalid_selection');
|
|
67
|
+
const catalogOrigin = url(expected.catalogUrl, 'invalid_selection').origin;
|
|
68
|
+
const expectedContext = context(expected.context, 'invalid_selection');
|
|
69
|
+
const expectedLocale = locale(expected.locale, 'invalid_selection');
|
|
70
|
+
const catalog = record(rawCatalog, ['contractVersion', 'selectionId', 'context', 'locale', 'state', 'resources'], 'invalid_catalog');
|
|
71
|
+
if (catalog.contractVersion !== 1 || (catalog.state !== 'selected' && catalog.state !== 'withdrawn'))
|
|
72
|
+
fail('invalid_catalog');
|
|
73
|
+
const catalogId = token(catalog.selectionId, 'invalid_catalog');
|
|
74
|
+
const actualContext = context(catalog.context, 'invalid_catalog');
|
|
75
|
+
const actualLocale = locale(catalog.locale, 'invalid_catalog');
|
|
76
|
+
if (catalogId !== selectionId || actualLocale !== expectedLocale || CONTEXT_KEYS.some(key => actualContext[key] !== expectedContext[key]))
|
|
77
|
+
fail('context_mismatch');
|
|
78
|
+
if (catalog.state === 'withdrawn')
|
|
79
|
+
fail('withdrawn');
|
|
80
|
+
if (!Array.isArray(catalog.resources) || catalog.resources.length === 0 || catalog.resources.length > MAX_RESOURCES)
|
|
81
|
+
fail('invalid_catalog');
|
|
82
|
+
const resources = new Map();
|
|
83
|
+
for (const raw of catalog.resources) {
|
|
84
|
+
const fields = record(raw, ['key', 'kind', 'url', 'sha256'], 'invalid_catalog');
|
|
85
|
+
const key = token(fields.key, 'invalid_catalog');
|
|
86
|
+
if (!RESOURCE_KINDS.includes(fields.kind) || resources.has(key))
|
|
87
|
+
fail('invalid_catalog');
|
|
88
|
+
if (url(fields.url, 'invalid_catalog').origin !== catalogOrigin)
|
|
89
|
+
fail('context_mismatch');
|
|
90
|
+
if (typeof fields.sha256 !== 'string' || !HASH.test(fields.sha256))
|
|
91
|
+
fail('invalid_catalog');
|
|
92
|
+
resources.set(key, Object.freeze({ key, kind: fields.kind, url: fields.url, sha256: fields.sha256 }));
|
|
93
|
+
}
|
|
94
|
+
const resource = (key, kind) => {
|
|
95
|
+
const found = resources.get(key);
|
|
96
|
+
if (!found || found.kind !== kind)
|
|
97
|
+
fail('unknown_resource');
|
|
98
|
+
return found;
|
|
99
|
+
};
|
|
100
|
+
return Object.freeze({
|
|
101
|
+
selectionId,
|
|
102
|
+
catalogUrl: expected.catalogUrl,
|
|
103
|
+
context: expectedContext,
|
|
104
|
+
locale: expectedLocale,
|
|
105
|
+
resource,
|
|
106
|
+
async verifyBytes(key, kind, bytes) {
|
|
107
|
+
const expectedHash = resource(key, kind).sha256;
|
|
108
|
+
if (!(bytes instanceof Uint8Array))
|
|
109
|
+
fail('invalid_bytes');
|
|
110
|
+
if (bytes.byteLength > MAX_BYTES)
|
|
111
|
+
fail('resource_too_large');
|
|
112
|
+
let digest;
|
|
113
|
+
try {
|
|
114
|
+
digest = await globalThis.crypto.subtle.digest('SHA-256', new Uint8Array(bytes).buffer);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return fail('integrity_unavailable');
|
|
118
|
+
}
|
|
119
|
+
const actual = Array.from(new Uint8Array(digest), byte => byte.toString(16).padStart(2, '0')).join('');
|
|
120
|
+
if (actual !== expectedHash)
|
|
121
|
+
fail('integrity_mismatch');
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}
|