@tokenoftrust/storefront-runner 6.16.0 → 6.17.1

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.
@@ -138,15 +138,18 @@ export function buildCspViolationBannerScript(basePath = ""): string {
138
138
  let box = null;
139
139
  const BASE = ${jsonForScript(basePath)};
140
140
  const path = window.location.pathname || "";
141
- const isStyleGuide = /^\\/_?style-guide(?:\\/|$)/.test(
142
- BASE && path.indexOf(BASE + "/") === 0 ? path.slice(BASE.length) : path,
143
- );
141
+ const relPath = BASE && path.indexOf(BASE + "/") === 0 ? path.slice(BASE.length) : path;
142
+ if (/^\\/admin(?:\\/|$)/.test(relPath)) return;
143
+ const isStyleGuide = /^\\/_?style-guide(?:\\/|$)/.test(relPath);
144
144
  const isPreviewInspectionStyle = (directive, uri) =>
145
145
  directive === "style-src-elem" &&
146
146
  (uri === "inline" || uri === "(inline)") &&
147
147
  (window.navigator.userAgent.includes("CodexBrowser") ||
148
148
  new URLSearchParams(window.location.search).has("__preview") ||
149
149
  isStyleGuide);
150
+ const isExtensionOrEvalNoise = (uri, sourceFile) =>
151
+ uri === "eval" ||
152
+ /^(?:chrome|moz|safari(?:-web)?|ms-browser)-extension:/i.test(String(sourceFile || ""));
150
153
  const ensureBox = () => {
151
154
  if (box) return box;
152
155
  box = document.createElement("div");
@@ -167,11 +170,12 @@ export function buildCspViolationBannerScript(basePath = ""): string {
167
170
  (document.body || document.documentElement).appendChild(box);
168
171
  return box;
169
172
  };
170
- const recordViolation = (directive, uri) => {
171
- // Preview inspection tooling injects its own nonce-less overlay stylesheet.
173
+ const recordViolation = (directive, uri, sourceFile) => {
174
+ // Preview inspection tooling injects its own nonce-less overlay stylesheet, and
175
+ // browser extensions routinely trip script-src eval in injected page scripts.
172
176
  // Automated CSP validation remains authoritative for page resources; keep
173
- // every other violation visible, and keep normal public routes diagnostic.
174
- if (isPreviewInspectionStyle(directive, uri)) return;
177
+ // every real resource block visible, and keep normal public routes diagnostic.
178
+ if (isPreviewInspectionStyle(directive, uri) || isExtensionOrEvalNoise(uri, sourceFile)) return;
175
179
  const key = directive + "|" + uri;
176
180
  if (seen.has(key)) return; seen.add(key);
177
181
  const li = document.createElement("li");
@@ -182,7 +186,7 @@ export function buildCspViolationBannerScript(basePath = ""): string {
182
186
  document.addEventListener("securitypolicyviolation", (e) => {
183
187
  const directive = e.effectiveDirective || e.violatedDirective || "";
184
188
  const uri = e.blockedURI || "(inline)";
185
- recordViolation(directive, uri);
189
+ recordViolation(directive, uri, e.sourceFile || "");
186
190
  });
187
191
  })();`;
188
192
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "6.16.0",
3
+ "version": "6.17.1",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "description": "World-shareable storefront runner: multi-tenant renderer on Astro/Cloudflare. No control plane.",
6
6
  "packageManager": "pnpm@11.9.0",
@@ -32,6 +32,7 @@
32
32
  "./responsive-renditions": "./src/responsive-renditions.ts",
33
33
  "./svg-sanitize": "./src/svg-sanitize.ts",
34
34
  "./incremental-sha256": "./src/incremental-sha256.ts",
35
+ "./catalog-scale": "./src/catalog-scale.mjs",
35
36
  "./image-limits": "./src/image-limits.mjs",
36
37
  "./tenant-record-merge": "./src/tenant-record-merge.mjs",
37
38
  "./image-release-gate": "./src/image-release-gate.ts",
@@ -0,0 +1,12 @@
1
+ export interface CatalogSize {
2
+ readonly products: number;
3
+ readonly bytes: number;
4
+ }
5
+ export type CatalogScaleLevel = "ok" | "warn" | "d1-required";
6
+
7
+ export declare const CATALOG_SCALE_WARN: Readonly<CatalogSize>;
8
+ export declare const CATALOG_SCALE_D1_REQUIRED: Readonly<CatalogSize>;
9
+ export declare function catalogScaleLevel(size: CatalogSize): CatalogScaleLevel;
10
+ export declare function catalogScaleFinding(
11
+ size: CatalogSize,
12
+ ): { level: "warn" | "d1-required"; message: string } | null;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Catalog scale thresholds: the one place the platform says how large a store's own
3
+ * `content/catalog/` may grow before each serving path stops being safe (ADR 0033).
4
+ *
5
+ * Two measures, because either can be the one that bites:
6
+ * - products: the count of `catalog/products/*.json` files;
7
+ * - bytes: the raw size of every file under `catalog/`.
8
+ *
9
+ * Evidence (synthetic Giant-shaped tenants, measured 2026-11-16 by
10
+ * `apps/storefront/src/lib/catalog/tot/catalogScale.test.ts`):
11
+ * - the listing projection parses in ~150 ms and ~47 MB of heap at 10,000 products;
12
+ * - reading the files one by one costs ~55 MB of heap at 5,000 products and ~111 MB at
13
+ * 10,000 against the Worker's 128 MB;
14
+ * - a store of 3,571 files / 42 MB failed to render in the materializer's wrangler-dev
15
+ * Worker (fb-1794371798042-4rqyh4), which is why bytes are a line of their own.
16
+ */
17
+
18
+ /** A catalog at or past either line gets a non-blocking finding naming the next line. */
19
+ export const CATALOG_SCALE_WARN = Object.freeze({ products: 3000, bytes: 25_000_000 });
20
+
21
+ /** A catalog at or past either line must declare `catalog.serving: "d1"` to be materialized. */
22
+ export const CATALOG_SCALE_D1_REQUIRED = Object.freeze({ products: 5000, bytes: 40_000_000 });
23
+
24
+ /**
25
+ * @param {{ products: number, bytes: number }} size
26
+ * @returns {"ok" | "warn" | "d1-required"}
27
+ */
28
+ export function catalogScaleLevel({ products, bytes }) {
29
+ if (products >= CATALOG_SCALE_D1_REQUIRED.products || bytes >= CATALOG_SCALE_D1_REQUIRED.bytes) return "d1-required";
30
+ if (products >= CATALOG_SCALE_WARN.products || bytes >= CATALOG_SCALE_WARN.bytes) return "warn";
31
+ return "ok";
32
+ }
33
+
34
+ const mb = (bytes) => `${(bytes / 1_000_000).toFixed(1)} MB`;
35
+
36
+ const REMEDY =
37
+ "ask Token of Trust to serve this catalog from the D1 projection (`catalog.serving` is a platform " +
38
+ "setting, not a .tot/config.json key; public and static renders never read D1, ADR 0013), " +
39
+ "or split the catalog";
40
+
41
+ /**
42
+ * The finding text for a catalog at `warn` or `d1-required`, or null when it is `ok`. Names the
43
+ * count, the size, the next line and the remedy, and says what each CDN does at the line.
44
+ *
45
+ * @param {{ products: number, bytes: number }} size
46
+ * @returns {{ level: "warn" | "d1-required", message: string } | null}
47
+ */
48
+ export function catalogScaleFinding(size) {
49
+ const level = catalogScaleLevel(size);
50
+ if (level === "ok") return null;
51
+ const have = `${size.products} products, ${mb(size.bytes)} of catalog files`;
52
+ const cdns =
53
+ "Cloudflare preview and publication read the catalog inside the Worker's 128 MB isolate; " +
54
+ "CloudFront static publication renders on a build machine, whose preview Worker bundles the catalog.";
55
+ if (level === "warn") {
56
+ return {
57
+ level,
58
+ message:
59
+ `catalog is ${have}; past ${CATALOG_SCALE_D1_REQUIRED.products} products or ` +
60
+ `${mb(CATALOG_SCALE_D1_REQUIRED.bytes)} a file-served catalog may not render. ` +
61
+ `${cdns} To stay ahead of it: ${REMEDY}.`,
62
+ };
63
+ }
64
+ return {
65
+ level,
66
+ message:
67
+ `catalog is ${have}, past the ${CATALOG_SCALE_D1_REQUIRED.products}-product / ` +
68
+ `${mb(CATALOG_SCALE_D1_REQUIRED.bytes)} line for file-served catalogs. ${cdns} Fix: ${REMEDY}.`,
69
+ };
70
+ }