@tokenoftrust/storefront-runner 7.1.0 → 7.2.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.
@@ -5,8 +5,12 @@
5
5
  * an entitlement tot20 reports enabled.
6
6
  */
7
7
  import { IMAGE_TIERS, LARGE_IMAGES_ADDON_NAME } from "@tot/public-runtime/image-limits";
8
+ import {
9
+ CATALOG_SCALE_LARGE,
10
+ LARGE_CATALOG_ADDON_NAME,
11
+ } from "@tot/public-runtime/catalog-scale";
8
12
 
9
- export const ADDON_IDS = ["largeImages"] as const;
13
+ export const ADDON_IDS = ["largeImages", "largeCatalog"] as const;
10
14
  export type AddOnId = (typeof ADDON_IDS)[number];
11
15
 
12
16
  export interface AddOnDefinition {
@@ -29,6 +33,14 @@ export const ADDONS: readonly AddOnDefinition[] = Object.freeze([
29
33
  `Raises this store's image limit from the standard ${limits(IMAGE_TIERS.standard)} ` +
30
34
  `to ${limits(IMAGE_TIERS.large)}. Takes effect on the next capture or upload.`,
31
35
  },
36
+ {
37
+ id: "largeCatalog",
38
+ name: LARGE_CATALOG_ADDON_NAME,
39
+ description:
40
+ `For catalogs past ${CATALOG_SCALE_LARGE.products.toLocaleString("en-US")} products or ` +
41
+ `${CATALOG_SCALE_LARGE.bytes / 1_000_000} MB of catalog files, whose static publication takes ` +
42
+ `over ten minutes. Publishing is not blocked without it today.`,
43
+ },
32
44
  ]);
33
45
 
34
46
  /** What `/admin/addons` shows for one add-on. `unavailable` means tot20 could not be read. */
@@ -25,6 +25,7 @@ import { readEnv } from "@/lib/publication/shared/env";
25
25
  /** The add-on set as this storefront reads it. Unknown add-ons and fields are dropped. */
26
26
  export interface StoreEntitlementSet {
27
27
  largeImages?: { enabled: boolean; updatedAt?: string };
28
+ largeCatalog?: { enabled: boolean; updatedAt?: string };
28
29
  }
29
30
 
30
31
  export type EntitlementFallbackReason =
@@ -105,19 +106,21 @@ function isRecord(value: unknown): value is Record<string, unknown> {
105
106
  /** Project the wire add-on set to the fields this module knows; `undefined` when malformed. */
106
107
  function projectSet(raw: unknown): StoreEntitlementSet | undefined {
107
108
  if (!isRecord(raw)) return undefined;
108
- const large = raw.largeImages;
109
- if (large === undefined) return {};
110
- if (!isRecord(large) || typeof large.enabled !== "boolean") return undefined;
111
- return {
112
- largeImages: {
113
- enabled: large.enabled,
114
- ...(typeof large.updatedAt === "string" ? { updatedAt: large.updatedAt } : {}),
115
- },
116
- };
109
+ const out: StoreEntitlementSet = {};
110
+ for (const key of ["largeImages", "largeCatalog"] as const) {
111
+ const value = raw[key];
112
+ if (value === undefined) continue;
113
+ if (!isRecord(value) || typeof value.enabled !== "boolean") return undefined;
114
+ out[key] = {
115
+ enabled: value.enabled,
116
+ ...(typeof value.updatedAt === "string" ? { updatedAt: value.updatedAt } : {}),
117
+ };
118
+ }
119
+ return out;
117
120
  }
118
121
 
119
122
  function classify(entitlements: StoreEntitlementSet): StoreEntitlements {
120
- return entitlements.largeImages?.enabled === true
123
+ return entitlements.largeImages?.enabled === true || entitlements.largeCatalog?.enabled === true
121
124
  ? { status: "ok", entitlements }
122
125
  : { status: "not-entitled", entitlements };
123
126
  }
@@ -139,7 +139,7 @@ export function buildCspViolationBannerScript(basePath = ""): string {
139
139
  const BASE = ${jsonForScript(basePath)};
140
140
  const path = window.location.pathname || "";
141
141
  const relPath = BASE && path.indexOf(BASE + "/") === 0 ? path.slice(BASE.length) : path;
142
- if (/^\\/admin(?:\\/|$)/.test(relPath)) return;
142
+ if (/^\\/(?:admin|cockpit|dashboard)(?:\\/|$)/.test(relPath) || /(?:^|\\/)admin(?:\\/|$)/.test(path)) return;
143
143
  const isStyleGuide = /^\\/_?style-guide(?:\\/|$)/.test(relPath);
144
144
  const isPreviewInspectionStyle = (directive, uri) =>
145
145
  directive === "style-src-elem" &&
@@ -147,8 +147,10 @@ export function buildCspViolationBannerScript(basePath = ""): string {
147
147
  (window.navigator.userAgent.includes("CodexBrowser") ||
148
148
  new URLSearchParams(window.location.search).has("__preview") ||
149
149
  isStyleGuide);
150
- const isExtensionOrEvalNoise = (uri, sourceFile) =>
150
+ const isExtensionOrEvalNoise = (directive, uri, sourceFile) =>
151
151
  uri === "eval" ||
152
+ uri === "wasm-eval" ||
153
+ (directive === "script-src" && (uri === "inline" || uri === "(inline)")) ||
152
154
  /^(?:chrome|moz|safari(?:-web)?|ms-browser)-extension:/i.test(String(sourceFile || ""));
153
155
  const ensureBox = () => {
154
156
  if (box) return box;
@@ -175,7 +177,7 @@ export function buildCspViolationBannerScript(basePath = ""): string {
175
177
  // browser extensions routinely trip script-src eval in injected page scripts.
176
178
  // Automated CSP validation remains authoritative for page resources; keep
177
179
  // every real resource block visible, and keep normal public routes diagnostic.
178
- if (isPreviewInspectionStyle(directive, uri) || isExtensionOrEvalNoise(uri, sourceFile)) return;
180
+ if (isPreviewInspectionStyle(directive, uri) || isExtensionOrEvalNoise(directive, uri, sourceFile)) return;
179
181
  const key = directive + "|" + uri;
180
182
  if (seen.has(key)) return; seen.add(key);
181
183
  const li = document.createElement("li");
@@ -237,11 +239,17 @@ export async function injectPreviewReload(
237
239
  });
238
240
  }
239
241
 
242
+ /** True when a tenant-relative route is a control-plane operator surface, not a previewed storefront page. */
243
+ export function isPreviewOperatorSurfacePath(renderPath = ""): boolean {
244
+ return /^\/(?:admin|cockpit|dashboard|auth)(?:\/|$)/i.test(renderPath);
245
+ }
246
+
240
247
  /**
241
248
  * Env-gated entrypoint the middleware calls: inject the reload client ONLY for
242
- * the SHARED preview (`test`) — NEVER `live`. Returns the response unchanged for
243
- * `live` (or any non-HTML response). This is the single guardrail seam, so the
244
- * "present in test, absent in live" contract is unit-testable here.
249
+ * the SHARED preview (`test`) — NEVER `live`, and never on operator control-plane
250
+ * surfaces (`/admin`, `/cockpit`, `/dashboard`, `/auth`). Returns the response
251
+ * unchanged for `live` (or any non-HTML response). This is the single guardrail
252
+ * seam, so the "present in test, absent in live" contract is unit-testable here.
245
253
  */
246
254
  export async function maybeInjectPreviewReload(
247
255
  response: Response,
@@ -250,9 +258,11 @@ export async function maybeInjectPreviewReload(
250
258
  tenantId: string;
251
259
  basePath: string;
252
260
  nonce: string;
261
+ renderPath?: string;
253
262
  pollMs?: number;
254
263
  },
255
264
  ): Promise<Response> {
256
265
  if (opts.env !== "test") return response;
266
+ if (opts.renderPath && isPreviewOperatorSurfacePath(opts.renderPath)) return response;
257
267
  return injectPreviewReload(response, opts);
258
268
  }
@@ -853,6 +853,7 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
853
853
  tenantId: tenant.tenant_id,
854
854
  basePath,
855
855
  nonce: cspNonce,
856
+ renderPath,
856
857
  });
857
858
 
858
859
  // Preview annotations: an authorized interactive preview (shared preview token, or a
@@ -70,15 +70,22 @@ button {
70
70
  cursor: pointer;
71
71
  }
72
72
 
73
- svg {
73
+ summary button > * {
74
+ pointer-events: none;
75
+ }
76
+
77
+ :where(svg) {
74
78
  width: 18px;
75
79
  height: 18px;
80
+ flex: 0 0 auto;
81
+ }
82
+
83
+ :where(svg:not([stroke="none"]):not([fill="currentColor"])) {
76
84
  stroke: currentColor;
77
85
  stroke-width: 1.9;
78
86
  stroke-linecap: round;
79
87
  stroke-linejoin: round;
80
88
  fill: none;
81
- flex: 0 0 auto;
82
89
  }
83
90
 
84
91
  .shell {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.1.0",
3
+ "version": "7.2.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",
@@ -3,9 +3,12 @@ export interface CatalogSize {
3
3
  readonly bytes: number;
4
4
  }
5
5
  export type CatalogScaleLevel = "ok" | "warn" | "large";
6
+ export type CatalogTier = "standard" | "large";
6
7
 
7
8
  export declare const CATALOG_SCALE_WARN: Readonly<CatalogSize>;
8
9
  export declare const CATALOG_SCALE_LARGE: Readonly<CatalogSize>;
10
+ export declare const LARGE_CATALOG_ADDON_NAME: string;
11
+ export declare function resolveCatalogTier(entitlements: unknown): CatalogTier;
9
12
  export declare function catalogScaleLevel(size: CatalogSize): CatalogScaleLevel;
10
13
  export declare function catalogScaleFinding(
11
14
  size: CatalogSize,
@@ -41,6 +41,21 @@ export function catalogScaleLevel({ products, bytes }) {
41
41
  return "ok";
42
42
  }
43
43
 
44
+ export const LARGE_CATALOG_ADDON_NAME = "Large Catalog";
45
+
46
+ /**
47
+ * The catalog tier a store's add-on entitlements grant. `entitlements` is untrusted input; only
48
+ * `largeCatalog.enabled === true` exactly grants `large`, everything else is `standard`.
49
+ * @param {unknown} entitlements
50
+ * @returns {"standard" | "large"}
51
+ */
52
+ export function resolveCatalogTier(entitlements) {
53
+ if (!entitlements || typeof entitlements !== "object" || Array.isArray(entitlements)) return "standard";
54
+ const addOn = /** @type {Record<string, unknown>} */ (entitlements).largeCatalog;
55
+ if (!addOn || typeof addOn !== "object" || Array.isArray(addOn)) return "standard";
56
+ return /** @type {Record<string, unknown>} */ (addOn).enabled === true ? "large" : "standard";
57
+ }
58
+
44
59
  const mb = (bytes) => `${(bytes / 1_000_000).toFixed(1)} MB`;
45
60
 
46
61
  /**
@@ -71,6 +86,8 @@ export function catalogScaleFinding(size) {
71
86
  message:
72
87
  `catalog is ${have}, past the ${CATALOG_SCALE_LARGE.products}-product / ` +
73
88
  `${mb(CATALOG_SCALE_LARGE.bytes)} line. Static publication took 11 minutes at 5,000 products ` +
74
- `and 21 minutes at 7,000 in measurement, growing faster than the catalog. ${cdns}`,
89
+ `and 21 minutes at 7,000 in measurement, growing faster than the catalog. ` +
90
+ `Catalogs past this line belong on the ${LARGE_CATALOG_ADDON_NAME} add-on; publishing is not ` +
91
+ `blocked today. ${cdns}`,
75
92
  };
76
93
  }