@tokenoftrust/storefront-runner 7.7.2 → 7.7.4
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.
|
@@ -123,8 +123,15 @@ export async function getVerifier(resource: string): Promise<IdentityAssertionVe
|
|
|
123
123
|
|
|
124
124
|
export { getVerifier as getIdentityVerifier };
|
|
125
125
|
|
|
126
|
-
/** Set the session cookie (HttpOnly/Secure/SameSite=Lax) for `maxAgeSeconds`.
|
|
127
|
-
|
|
126
|
+
/** Set the session cookie (HttpOnly/Secure/SameSite=Lax) for `maxAgeSeconds`.
|
|
127
|
+
* Pass the updated `session` record when rotating an in-flight session so downstream
|
|
128
|
+
* `readViewerSession` / `resolveRequestPrincipal` calls on the same request see it. */
|
|
129
|
+
export function setSessionCookie(
|
|
130
|
+
context: APIContext,
|
|
131
|
+
id: string,
|
|
132
|
+
maxAgeSeconds: number,
|
|
133
|
+
session?: SessionRecord,
|
|
134
|
+
): void {
|
|
128
135
|
context.cookies.set(SESSION_COOKIE, id, {
|
|
129
136
|
httpOnly: true,
|
|
130
137
|
secure: true,
|
|
@@ -132,11 +139,13 @@ export function setSessionCookie(context: APIContext, id: string, maxAgeSeconds:
|
|
|
132
139
|
path: "/",
|
|
133
140
|
maxAge: maxAgeSeconds,
|
|
134
141
|
});
|
|
142
|
+
if (session) rememberRequestViewerSession(context, session);
|
|
135
143
|
}
|
|
136
144
|
|
|
137
145
|
/** Clear the session cookie (logout). */
|
|
138
146
|
export function clearSessionCookie(context: APIContext): void {
|
|
139
147
|
context.cookies.delete(SESSION_COOKIE, { path: "/" });
|
|
148
|
+
if (context.request) inRequestViewerSessions.delete(context.request);
|
|
140
149
|
}
|
|
141
150
|
|
|
142
151
|
export { safeNext } from "./safeNext.js";
|
|
@@ -15,7 +15,7 @@ import { sha256Hex } from "@tot/public-runtime";
|
|
|
15
15
|
import { IMAGE_LIMITS_CEILING } from "@tot/public-runtime/image-limits";
|
|
16
16
|
import {
|
|
17
17
|
PINNED_ASSET_EXTENSION_BY_MEDIA_TYPE, PINNED_ASSET_MEDIA_TYPE_BY_EXTENSION,
|
|
18
|
-
sealedOriginalEntryAllowed, validSvgSanitizeReceipt, type SvgSanitizeReceipt,
|
|
18
|
+
UPLOADABLE_MEDIA_TYPES, sealedOriginalEntryAllowed, validSvgSanitizeReceipt, type SvgSanitizeReceipt,
|
|
19
19
|
} from "@tot/public-runtime/hosted-image-media-types";
|
|
20
20
|
import { durableAssetsStatusKey, durableCaptureRevisionId, durableRequiredStores, parseDurableAssetsStatus } from "@tot/public-runtime/durable-assets";
|
|
21
21
|
import { POOL_ASSET_SECURITY_HEADERS } from "@tot/public-runtime/pool-asset-headers";
|
|
@@ -57,6 +57,61 @@ function objectKey(tenantId: string, address: string): string {
|
|
|
57
57
|
return `original-images/${tenantId}/objects/${address}`;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
const ACTOR_ID_RE = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
61
|
+
|
|
62
|
+
function uploadRecordKey(tenantId: string, address: string): string {
|
|
63
|
+
return `original-images/${tenantId}/uploads/${address}.json`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function readUploadedOriginalEntry(
|
|
67
|
+
bucket: CapturedOriginalBucket,
|
|
68
|
+
tenantId: string,
|
|
69
|
+
address: string,
|
|
70
|
+
): Promise<ManifestEntry | null> {
|
|
71
|
+
const maxEntryBytes = IMAGE_LIMITS_CEILING.maxEncodedBytes;
|
|
72
|
+
if (!isSafeTenantId(tenantId) || !ADDRESS_RE.test(address)) return null;
|
|
73
|
+
const object = await bucket.get(uploadRecordKey(tenantId, address));
|
|
74
|
+
if (!object || typeof object !== "object") return null;
|
|
75
|
+
const body = object as { arrayBuffer?: () => Promise<ArrayBuffer> };
|
|
76
|
+
if (typeof body.arrayBuffer !== "function") return null;
|
|
77
|
+
const bytes = await body.arrayBuffer();
|
|
78
|
+
let parsed: {
|
|
79
|
+
version?: unknown;
|
|
80
|
+
address?: unknown;
|
|
81
|
+
byteLength?: unknown;
|
|
82
|
+
mediaType?: unknown;
|
|
83
|
+
provenance?: { kind?: unknown };
|
|
84
|
+
uploaderActorId?: unknown;
|
|
85
|
+
at?: unknown;
|
|
86
|
+
} | null = null;
|
|
87
|
+
try {
|
|
88
|
+
parsed = JSON.parse(new TextDecoder().decode(new Uint8Array(bytes)));
|
|
89
|
+
} catch { /* Malformed upload record fails closed. */ }
|
|
90
|
+
if (
|
|
91
|
+
!parsed ||
|
|
92
|
+
typeof parsed !== "object" ||
|
|
93
|
+
parsed.version !== 1 ||
|
|
94
|
+
parsed.address !== address ||
|
|
95
|
+
parsed.provenance?.kind !== "upload" ||
|
|
96
|
+
!Number.isSafeInteger(parsed.byteLength) ||
|
|
97
|
+
(parsed.byteLength as number) < 1 ||
|
|
98
|
+
(parsed.byteLength as number) > maxEntryBytes ||
|
|
99
|
+
typeof parsed.mediaType !== "string" ||
|
|
100
|
+
!(UPLOADABLE_MEDIA_TYPES as readonly string[]).includes(parsed.mediaType) ||
|
|
101
|
+
typeof parsed.uploaderActorId !== "string" ||
|
|
102
|
+
!ACTOR_ID_RE.test(parsed.uploaderActorId) ||
|
|
103
|
+
typeof parsed.at !== "string"
|
|
104
|
+
) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
address,
|
|
109
|
+
byteLength: parsed.byteLength as number,
|
|
110
|
+
mediaType: parsed.mediaType,
|
|
111
|
+
provenance: { kind: "upload", locator: `/_a/${address}${PINNED_ASSET_EXTENSION_BY_MEDIA_TYPE[parsed.mediaType]}` },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
60
115
|
/** Parse `/_a/<sha256>[.ext]` — null when the path is not a pinned asset URL. */
|
|
61
116
|
export function parsePinnedImagePath(pathname: string): { address: string; ext: string } | null {
|
|
62
117
|
const match = pathname.match(/^\/_a\/([0-9a-f]{64})(\.[A-Za-z0-9]+)?$/);
|
|
@@ -183,6 +238,11 @@ export async function tryServeCapturedOriginal(input: {
|
|
|
183
238
|
durable = !!entry;
|
|
184
239
|
} catch { /* Unreadable durable authority fails closed. */ }
|
|
185
240
|
}
|
|
241
|
+
if (!entry) {
|
|
242
|
+
try {
|
|
243
|
+
entry = await readUploadedOriginalEntry(input.bucket, input.tenantId, parsed.address) ?? undefined;
|
|
244
|
+
} catch { /* Unreadable upload authority fails closed. */ }
|
|
245
|
+
}
|
|
186
246
|
if (entry && parsed.ext && EXT_TYPE[parsed.ext.toLowerCase()] !== entry.mediaType) entry = undefined;
|
|
187
247
|
if (!entry) {
|
|
188
248
|
return new Response("Not found", { status: 404, headers: { "cache-control": "no-store" } });
|
|
@@ -67,22 +67,31 @@ export async function tryServeStaticBundle(
|
|
|
67
67
|
// bytes for every viewer, preview or not, whatever the live pointer says. A page from an
|
|
68
68
|
// older version — or a preview of one — keeps resolving its own sub-resources.
|
|
69
69
|
if ((method === "GET" || method === "HEAD") && versionIndependentAssetKey(assetPath)) {
|
|
70
|
+
const pinnedKey = cache && method === "GET"
|
|
71
|
+
? staticBundleCacheKey(tenant.tenant_id, "pinned", assetPath, "")
|
|
72
|
+
: null;
|
|
73
|
+
if (pinnedKey && cache) {
|
|
74
|
+
const hit = await getCachedPage(cache, pinnedKey);
|
|
75
|
+
if (hit) return hit;
|
|
76
|
+
}
|
|
77
|
+
const cacheImmutableAsset = async (response: Response) => {
|
|
78
|
+
if (!pinnedKey || !cache || response.status !== 200) return;
|
|
79
|
+
if (!(response.headers.get("cache-control") ?? "").includes("immutable")) return;
|
|
80
|
+
if (response.headers.has("set-cookie")) return;
|
|
81
|
+
const cloned = response.clone();
|
|
82
|
+
const toStore = new Response(cloned.body, cloned);
|
|
83
|
+
toStore.headers.set("X-ToT-Cache", "stored");
|
|
84
|
+
await cache.put(pinnedKey, toStore).catch(() => void 0);
|
|
85
|
+
};
|
|
70
86
|
const bucket = await readR2("STATIC_BUNDLES");
|
|
71
87
|
if (bucket) {
|
|
72
|
-
const pinnedKey = cache && method === "GET"
|
|
73
|
-
? staticBundleCacheKey(tenant.tenant_id, "pinned", assetPath, "")
|
|
74
|
-
: null;
|
|
75
|
-
if (pinnedKey && cache) {
|
|
76
|
-
const hit = await getCachedPage(cache, pinnedKey);
|
|
77
|
-
if (hit) return hit;
|
|
78
|
-
}
|
|
79
88
|
const pinned = await serveVersionIndependentAsset(
|
|
80
89
|
bucket as unknown as StaticBundleR2BucketLike,
|
|
81
90
|
assetPath,
|
|
82
91
|
method,
|
|
83
92
|
);
|
|
84
93
|
if (pinned && pinned.ok) {
|
|
85
|
-
|
|
94
|
+
await cacheImmutableAsset(pinned);
|
|
86
95
|
return pinned;
|
|
87
96
|
}
|
|
88
97
|
// `/_a/` miss: try revision-bound captured originals before the pinned 404.
|
|
@@ -96,7 +105,10 @@ export async function tryServeStaticBundle(
|
|
|
96
105
|
method,
|
|
97
106
|
...(kv ? { durable: { kv, provider: tenant.serving?.provider } } : {}),
|
|
98
107
|
});
|
|
99
|
-
if (captured)
|
|
108
|
+
if (captured) {
|
|
109
|
+
await cacheImmutableAsset(captured);
|
|
110
|
+
return captured;
|
|
111
|
+
}
|
|
100
112
|
}
|
|
101
113
|
if (pinned) return pinned;
|
|
102
114
|
} else if (input.capturedOriginal && assetPath.startsWith("/_a/")) {
|
|
@@ -109,7 +121,10 @@ export async function tryServeStaticBundle(
|
|
|
109
121
|
method,
|
|
110
122
|
...(kv ? { durable: { kv, provider: tenant.serving?.provider } } : {}),
|
|
111
123
|
});
|
|
112
|
-
if (captured)
|
|
124
|
+
if (captured) {
|
|
125
|
+
await cacheImmutableAsset(captured);
|
|
126
|
+
return captured;
|
|
127
|
+
}
|
|
113
128
|
}
|
|
114
129
|
}
|
|
115
130
|
|
|
@@ -14,7 +14,6 @@ import Section from "@/components/content/storefront/Section.astro";
|
|
|
14
14
|
import ImageGallery, { publicGalleryImages } from "@/components/catalog/storefront/islands/ImageGallery.tsx";
|
|
15
15
|
import VariantSelector, { publicSelectorVariants } from "@/components/catalog/storefront/islands/VariantSelector.tsx";
|
|
16
16
|
import RecentlyViewed from "@/components/catalog/storefront/islands/RecentlyViewed.tsx";
|
|
17
|
-
import NicotineWarning from "@/components/compliance/storefront/compliance/NicotineWarning.astro";
|
|
18
17
|
import Prop65Warning from "@/components/compliance/storefront/compliance/Prop65Warning.astro";
|
|
19
18
|
import ReviewSummary from "@/components/catalog/storefront/commerce/ReviewSummary.astro";
|
|
20
19
|
import ReviewList from "@/components/catalog/storefront/commerce/ReviewList.astro";
|
|
@@ -389,12 +388,6 @@ const structuredData = {
|
|
|
389
388
|
</p>
|
|
390
389
|
)}
|
|
391
390
|
|
|
392
|
-
{compliance?.nicotineWarning && (
|
|
393
|
-
<div class="mt-6">
|
|
394
|
-
<NicotineWarning variant="block" declaration={compliance.nicotineWarning} />
|
|
395
|
-
</div>
|
|
396
|
-
)}
|
|
397
|
-
|
|
398
391
|
{/* California Prop 65 (Cal. Code Regs. tit. 27 § 25601+): the safe-harbor
|
|
399
392
|
warning must reach the purchaser before checkout completes, so the PDP
|
|
400
393
|
— the point of sale here (no in-app cart page; checkout is an external
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "7.7.
|
|
3
|
+
"version": "7.7.4",
|
|
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",
|