@tokenoftrust/storefront-runner 8.1.0 → 8.1.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.
|
@@ -462,6 +462,8 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
|
|
|
462
462
|
? input.managedIntegrationDeclarations
|
|
463
463
|
: await readBakedManagedInstalls(request, tenant.tenant_id, readEnv);
|
|
464
464
|
|
|
465
|
+
const materializeMode = (await readEnv(MATERIALIZE_MODE_BINDING)) === "1";
|
|
466
|
+
|
|
465
467
|
// Digest-addressed static-bundle serving. Deliberately before the edge page
|
|
466
468
|
// cache/catalog/theme machinery. A selected publication bypasses this legacy
|
|
467
469
|
// whole-site bundle until B1 can compose mounted spaces into it reproducibly.
|
|
@@ -492,6 +494,7 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
|
|
|
492
494
|
hasCandidatePin: !!candidatePin,
|
|
493
495
|
hasDraftCookie: !!draftCookie,
|
|
494
496
|
hasManagedInstalls: managedIntegrationDeclarations.length > 0,
|
|
497
|
+
isMaterializeMode: materializeMode,
|
|
495
498
|
...(originalsBucket
|
|
496
499
|
? {
|
|
497
500
|
capturedOriginal: {
|
|
@@ -575,7 +578,7 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
|
|
|
575
578
|
// Either gate failing ⇒ fall through to the caller-supplied reader (control plane
|
|
576
579
|
// only), never a caller-supplied snapshot.
|
|
577
580
|
let bakedConsent: ReturnType<typeof parseConsentSnapshot> = null;
|
|
578
|
-
if (
|
|
581
|
+
if (materializeMode) {
|
|
579
582
|
const consentInputHeader = request.headers.get(CONSENT_SNAPSHOT_INPUT_HEADER);
|
|
580
583
|
const consentSig = request.headers.get(CONSENT_SNAPSHOT_SIG_HEADER);
|
|
581
584
|
const hmacSecret = await readEnv(CONSENT_SNAPSHOT_HMAC_SECRET_BINDING);
|
|
@@ -613,8 +616,11 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
|
|
|
613
616
|
// API in .wrangler/state, so a cached page would be served stale across edits AND
|
|
614
617
|
// restarts — silently defeating hot-reload (edits look "lost"). Dev must always
|
|
615
618
|
// re-render. import.meta.env.DEV statically drops this guard from the prod build.
|
|
619
|
+
// Materialize mode renders fresh pages with request-bound baked inputs and capture
|
|
620
|
+
// headers, so it bypasses the edge page cache completely.
|
|
616
621
|
const pageCacheEligible =
|
|
617
622
|
!import.meta.env.DEV &&
|
|
623
|
+
!materializeMode &&
|
|
618
624
|
request.method.toUpperCase() === "GET" &&
|
|
619
625
|
!isPreviewHost &&
|
|
620
626
|
!preview.presented &&
|
|
@@ -644,10 +650,13 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
|
|
|
644
650
|
const key = pageKey;
|
|
645
651
|
const hit = await timed(timing, "page-cache", () => getCachedPage(cache, key));
|
|
646
652
|
timing?.note("cache", hit ? "hit" : "miss");
|
|
647
|
-
// The cached artifact is nonce-free (carries the placeholder)
|
|
648
|
-
//
|
|
649
|
-
//
|
|
650
|
-
if (hit)
|
|
653
|
+
// The cached artifact is nonce-free (carries the placeholder) and stored without
|
|
654
|
+
// materialize capture headers. Stamp any capture headers requested on this probe
|
|
655
|
+
// and a fresh per-response nonce so a warm hit matches a cold render.
|
|
656
|
+
if (hit) {
|
|
657
|
+
applyMaterializeCaptureHeaders(hit, request, tenant, shopperDelivery, materializeMode);
|
|
658
|
+
return await stampResponseNonce(hit, freshNonce());
|
|
659
|
+
}
|
|
651
660
|
}
|
|
652
661
|
|
|
653
662
|
const proto = url.protocol === "http:" ? "http" : "https";
|
|
@@ -927,7 +936,7 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
|
|
|
927
936
|
pageBase: locals.basePath ?? basePath,
|
|
928
937
|
apiBase: basePath,
|
|
929
938
|
nonce: cspNonce,
|
|
930
|
-
capture: isPublicationCapture(request.headers,
|
|
939
|
+
capture: isPublicationCapture(request.headers, materializeMode ? "1" : null),
|
|
931
940
|
cdnForwarded: locals.cdnForwarded === true,
|
|
932
941
|
internalPublication: isInternalPublication,
|
|
933
942
|
// Annotations and tours both identify the document; one KV read serves both.
|
|
@@ -1066,25 +1075,7 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
|
|
|
1066
1075
|
// A preview-token (`test`) render is unpublished content shown to one viewer: no
|
|
1067
1076
|
// browser, proxy, or CDN may keep it or hand it to the next visitor of this URL.
|
|
1068
1077
|
if (customization.env === "test") response.headers.set("Cache-Control", "private, no-store");
|
|
1069
|
-
|
|
1070
|
-
// Cache-Control so the publish/materialize plane can bake it into the bundle
|
|
1071
|
-
// manifest (the same capture pattern as CSP). Gated on the materialize probe
|
|
1072
|
-
// request header, so it NEVER reaches a public client — the LIVE served header
|
|
1073
|
-
// comes from the manifest via `static-bundle`, not from this signal.
|
|
1074
|
-
if (request.headers.get(HTML_CACHE_POLICY_CAPTURE_PROBE)) {
|
|
1075
|
-
response.headers.set(
|
|
1076
|
-
HTML_CACHE_POLICY_CAPTURE_HEADER,
|
|
1077
|
-
formatHtmlCacheControl(locals.tenant?.serving?.htmlCachePolicy),
|
|
1078
|
-
);
|
|
1079
|
-
// The tenant's declared origins — the same `domains` the Worker's own image scans use. The
|
|
1080
|
-
// materializer ships images a page references absolutely on them (og:image is always
|
|
1081
|
-
// absolute), and the publish scan classifies such references by path instead of as
|
|
1082
|
-
// third-party hotlinks.
|
|
1083
|
-
response.headers.set(TENANT_ORIGINS_CAPTURE_HEADER, declaredTenantOrigins(tenant).join(","));
|
|
1084
|
-
if (await readEnv(MATERIALIZE_MODE_BINDING) === "1") {
|
|
1085
|
-
response.headers.set("x-tot-shopper-delivery", JSON.stringify(shopperDelivery));
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1078
|
+
applyMaterializeCaptureHeaders(response, request, locals.tenant ?? tenant, shopperDelivery, materializeMode);
|
|
1088
1079
|
if (isInternalPublication) applyInternalContentResponsePolicy(response.headers);
|
|
1089
1080
|
// Stamp a fresh per-response nonce into this cold response's body + CSP header
|
|
1090
1081
|
// (the warm-hit path above stamps its own). Both paths therefore serve a fresh,
|
|
@@ -1093,6 +1084,34 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
|
|
|
1093
1084
|
return await timed(timing, "nonce", () => stampResponseNonce(stamped, freshNonce()));
|
|
1094
1085
|
}
|
|
1095
1086
|
|
|
1087
|
+
/**
|
|
1088
|
+
* Materialize-only capture headers (ADR 0013): expose the tenant's route-document
|
|
1089
|
+
* Cache-Control, declared origins, and (in materialize mode) shopper delivery policy
|
|
1090
|
+
* when requested by the materialize capture probe. Applied after page-cache writes
|
|
1091
|
+
* and on warm hits so cached artifacts never retain capture headers.
|
|
1092
|
+
*/
|
|
1093
|
+
function applyMaterializeCaptureHeaders(
|
|
1094
|
+
response: Response,
|
|
1095
|
+
request: Request,
|
|
1096
|
+
tenant: TenantConfig,
|
|
1097
|
+
shopperDelivery: ReturnType<typeof shopperDeliveryPolicy>,
|
|
1098
|
+
materializeMode: boolean,
|
|
1099
|
+
): void {
|
|
1100
|
+
if (!request.headers.get(HTML_CACHE_POLICY_CAPTURE_PROBE)) return;
|
|
1101
|
+
response.headers.set(
|
|
1102
|
+
HTML_CACHE_POLICY_CAPTURE_HEADER,
|
|
1103
|
+
formatHtmlCacheControl(tenant.serving?.htmlCachePolicy),
|
|
1104
|
+
);
|
|
1105
|
+
// The tenant's declared origins — the same `domains` the Worker's own image scans use. The
|
|
1106
|
+
// materializer ships images a page references absolutely on them (og:image is always
|
|
1107
|
+
// absolute), and the publish scan classifies such references by path instead of as
|
|
1108
|
+
// third-party hotlinks.
|
|
1109
|
+
response.headers.set(TENANT_ORIGINS_CAPTURE_HEADER, declaredTenantOrigins(tenant).join(","));
|
|
1110
|
+
if (materializeMode) {
|
|
1111
|
+
response.headers.set("x-tot-shopper-delivery", JSON.stringify(shopperDelivery));
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1096
1115
|
/**
|
|
1097
1116
|
* Inline a run of distinct tenant theme stylesheets into a preview document.
|
|
1098
1117
|
* Bytes follow the `/tenants/<id>/` route: publication root, then the preview
|
|
@@ -32,6 +32,8 @@ export interface StaticBundleAttemptInput {
|
|
|
32
32
|
hasDraftCookie: boolean;
|
|
33
33
|
/** Managed installs inject document markup, so a bundled DOCUMENT would be stale. */
|
|
34
34
|
hasManagedInstalls: boolean;
|
|
35
|
+
/** Materialize mode renders fresh source documents, never a prior static bundle. */
|
|
36
|
+
isMaterializeMode?: boolean;
|
|
35
37
|
/**
|
|
36
38
|
* When set, a `/_a/<sha>` miss falls through to revision-bound captured
|
|
37
39
|
* originals (hosted preview image capture) before returning 404.
|
|
@@ -151,6 +153,7 @@ export async function tryServeStaticBundle(
|
|
|
151
153
|
!input.hasCandidatePin &&
|
|
152
154
|
!input.hasDraftCookie &&
|
|
153
155
|
!input.hasManagedInstalls &&
|
|
156
|
+
!input.isMaterializeMode &&
|
|
154
157
|
!/^\/(?:api|account)(?:\/|$)/i.test(url.pathname);
|
|
155
158
|
if (!eligible) return null;
|
|
156
159
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.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",
|