@tokenoftrust/storefront-runner 7.2.3 → 7.2.5
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/apps/storefront/src/lib/publication/shared/previewReload.ts +104 -0
- package/apps/storefront/src/middleware/renderChain.ts +24 -1
- package/package.json +1 -1
- package/packages/feedback/package.json +1 -1
- package/packages/feedback/src/tour/player/player.css +5 -5
- package/packages/feedback/src/tour/player/surface.ts +1 -1
|
@@ -266,3 +266,107 @@ export async function maybeInjectPreviewReload(
|
|
|
266
266
|
if (opts.renderPath && isPreviewOperatorSurfacePath(opts.renderPath)) return response;
|
|
267
267
|
return injectPreviewReload(response, opts);
|
|
268
268
|
}
|
|
269
|
+
|
|
270
|
+
const SHARE_STATE_TTL_SECONDS = 24 * 3600;
|
|
271
|
+
|
|
272
|
+
export interface PreviewShareLinkState {
|
|
273
|
+
revokedAtSeconds?: number;
|
|
274
|
+
revokedSigs?: string[];
|
|
275
|
+
seenSigs?: string[];
|
|
276
|
+
lastOpenedAt?: string;
|
|
277
|
+
lastOpenedMobile?: boolean;
|
|
278
|
+
openCount?: number;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface PreviewShareKvLike {
|
|
282
|
+
get(key: string): Promise<string | null>;
|
|
283
|
+
put(key: string, value: string, options?: { expirationTtl?: number }): Promise<unknown>;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function previewShareStateKey(tenantId: string): string {
|
|
287
|
+
return `preview-share-state:${tenantId}`;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function extractPreviewTokenSignature(token: string | null | undefined): string | null {
|
|
291
|
+
const raw = String(token || "").trim();
|
|
292
|
+
const dot = raw.indexOf(".");
|
|
293
|
+
if (dot <= 0 || dot === raw.length - 1) return null;
|
|
294
|
+
return raw.slice(dot + 1);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export async function readPreviewShareState(
|
|
298
|
+
kvGet: (key: string) => Promise<string | null>,
|
|
299
|
+
tenantId: string,
|
|
300
|
+
): Promise<PreviewShareLinkState> {
|
|
301
|
+
const raw = await kvGet(previewShareStateKey(tenantId));
|
|
302
|
+
if (!raw) return {};
|
|
303
|
+
try {
|
|
304
|
+
const parsed = JSON.parse(raw);
|
|
305
|
+
return parsed && typeof parsed === "object" ? (parsed as PreviewShareLinkState) : {};
|
|
306
|
+
} catch (err) {
|
|
307
|
+
if (err instanceof SyntaxError) return {};
|
|
308
|
+
throw err;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export async function isPreviewShareTokenRevoked(
|
|
313
|
+
kvGet: (key: string) => Promise<string | null>,
|
|
314
|
+
tenantId: string,
|
|
315
|
+
token: string | null | undefined,
|
|
316
|
+
): Promise<boolean> {
|
|
317
|
+
const sig = extractPreviewTokenSignature(token);
|
|
318
|
+
if (!sig) return false;
|
|
319
|
+
const state = await readPreviewShareState(kvGet, tenantId);
|
|
320
|
+
return Array.isArray(state.revokedSigs) && state.revokedSigs.includes(sig);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export async function recordPreviewShareOpen(
|
|
324
|
+
kv: PreviewShareKvLike,
|
|
325
|
+
tenantId: string,
|
|
326
|
+
token: string,
|
|
327
|
+
userAgent?: string | null,
|
|
328
|
+
nowIso: string = new Date().toISOString(),
|
|
329
|
+
): Promise<PreviewShareLinkState> {
|
|
330
|
+
const state = await readPreviewShareState((k) => kv.get(k), tenantId);
|
|
331
|
+
const sig = extractPreviewTokenSignature(token);
|
|
332
|
+
const seen = new Set(Array.isArray(state.seenSigs) ? state.seenSigs : []);
|
|
333
|
+
if (sig) seen.add(sig);
|
|
334
|
+
const next: PreviewShareLinkState = {
|
|
335
|
+
...state,
|
|
336
|
+
seenSigs: [...seen].slice(-64),
|
|
337
|
+
lastOpenedAt: nowIso,
|
|
338
|
+
lastOpenedMobile: /Mobile|Android|iPhone|iPad|iPod/i.test(String(userAgent || "")),
|
|
339
|
+
openCount: (state.openCount ?? 0) + 1,
|
|
340
|
+
};
|
|
341
|
+
await kv.put(previewShareStateKey(tenantId), JSON.stringify(next), {
|
|
342
|
+
expirationTtl: SHARE_STATE_TTL_SECONDS,
|
|
343
|
+
});
|
|
344
|
+
return next;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export async function revokePreviewShareLinks(
|
|
348
|
+
kv: PreviewShareKvLike,
|
|
349
|
+
tenantId: string,
|
|
350
|
+
activeTokens: readonly string[] = [],
|
|
351
|
+
nowSeconds: number = Math.floor(Date.now() / 1000),
|
|
352
|
+
): Promise<PreviewShareLinkState> {
|
|
353
|
+
const state = await readPreviewShareState((k) => kv.get(k), tenantId);
|
|
354
|
+
const revoked = new Set(Array.isArray(state.revokedSigs) ? state.revokedSigs : []);
|
|
355
|
+
for (const sig of state.seenSigs ?? []) {
|
|
356
|
+
if (typeof sig === "string" && sig) revoked.add(sig);
|
|
357
|
+
}
|
|
358
|
+
for (const tok of activeTokens) {
|
|
359
|
+
const sig = extractPreviewTokenSignature(tok);
|
|
360
|
+
if (sig) revoked.add(sig);
|
|
361
|
+
}
|
|
362
|
+
const next: PreviewShareLinkState = {
|
|
363
|
+
revokedAtSeconds: nowSeconds,
|
|
364
|
+
revokedSigs: [...revoked].slice(-128),
|
|
365
|
+
seenSigs: [],
|
|
366
|
+
openCount: 0,
|
|
367
|
+
};
|
|
368
|
+
await kv.put(previewShareStateKey(tenantId), JSON.stringify(next), {
|
|
369
|
+
expirationTtl: SHARE_STATE_TTL_SECONDS,
|
|
370
|
+
});
|
|
371
|
+
return next;
|
|
372
|
+
}
|
|
@@ -29,7 +29,12 @@ import {
|
|
|
29
29
|
} from "@/lib/publication/shared/edgeCache";
|
|
30
30
|
import { STATIC_SCRIPT_HASHES, STATIC_STYLE_HASHES } from "@/lib/access/shared/cspStaticHashes";
|
|
31
31
|
import { applySecurityHeaders } from "@/lib/access/shared/securityHeaders";
|
|
32
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
isPreviewOperatorSurfacePath,
|
|
34
|
+
isPreviewShareTokenRevoked,
|
|
35
|
+
maybeInjectPreviewReload,
|
|
36
|
+
recordPreviewShareOpen,
|
|
37
|
+
} from "@/lib/publication/shared/previewReload";
|
|
33
38
|
import {
|
|
34
39
|
decoratePreviewAnnotations,
|
|
35
40
|
isPublicationCapture,
|
|
@@ -234,7 +239,25 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
|
|
|
234
239
|
return previewContextRefusalResponse(preview.context);
|
|
235
240
|
}
|
|
236
241
|
const verifiedPreview = preview.context.status === "valid" ? preview.context : null;
|
|
242
|
+
if (verifiedPreview && kv) {
|
|
243
|
+
const revoked = await isPreviewShareTokenRevoked(
|
|
244
|
+
(key) => kv.get(key),
|
|
245
|
+
tenantRecord.tenant_id,
|
|
246
|
+
verifiedPreview.token,
|
|
247
|
+
);
|
|
248
|
+
if (revoked) {
|
|
249
|
+
return previewContextRefusalResponse({ httpStatus: 403, reason: "expired" });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
237
252
|
const queryToken = verifiedPreview?.source === "query" ? verifiedPreview.token : null;
|
|
253
|
+
if (queryToken && kv && typeof kv.put === "function" && !isPreviewOperatorSurfacePath(renderPath)) {
|
|
254
|
+
await recordPreviewShareOpen(
|
|
255
|
+
kv,
|
|
256
|
+
tenantRecord.tenant_id,
|
|
257
|
+
queryToken,
|
|
258
|
+
request.headers.get("user-agent"),
|
|
259
|
+
);
|
|
260
|
+
}
|
|
238
261
|
// The cookie itself, when the context verified: the revision cookie below checks
|
|
239
262
|
// its own binding against it.
|
|
240
263
|
const cookieToken = verifiedPreview ? preview.cookieValue : null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.5",
|
|
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",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"build:tour-player": "node scripts/build-player.mjs",
|
|
26
26
|
"test:tour-player-browser": "node --test tests/player.browser.test.mjs",
|
|
27
27
|
"test:tour-player-static": "node --test tests/player-static.test.mjs",
|
|
28
|
-
"test": "tot-gate vitest run
|
|
28
|
+
"test": "tot-gate vitest run"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"happy-dom": "20.11.2",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
.tour-launcher button:hover { background: #193ba3; }
|
|
92
92
|
.tour-launcher button:focus-visible { outline: 3px solid #1447d5; outline-offset: 3px; }
|
|
93
93
|
|
|
94
|
-
.tour-highlight {
|
|
94
|
+
.tour-target-highlight {
|
|
95
95
|
position: fixed;
|
|
96
96
|
border: 3px solid #315cdb;
|
|
97
97
|
border-radius: 8px;
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
animation: tour-glow 1.8s ease-in-out infinite alternate;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
.tour-highlight-neutral { border-color: #46536b; }
|
|
102
|
+
.tour-target-highlight-neutral { border-color: #46536b; }
|
|
103
103
|
|
|
104
104
|
.tour-arrow {
|
|
105
105
|
position: absolute;
|
|
@@ -120,11 +120,11 @@
|
|
|
120
120
|
to { box-shadow: 0 0 0 7px rgb(49 92 219 / 32%); }
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
:host([data-reduced-motion="true"]) .tour-highlight { animation: none; }
|
|
123
|
+
:host([data-reduced-motion="true"]) .tour-target-highlight { animation: none; }
|
|
124
124
|
@media (prefers-reduced-motion: reduce) {
|
|
125
|
-
.tour-highlight { animation: none; }
|
|
125
|
+
.tour-target-highlight { animation: none; }
|
|
126
126
|
}
|
|
127
127
|
@media (forced-colors: active) {
|
|
128
|
-
.tour-highlight { border-color: Highlight; animation: none; }
|
|
128
|
+
.tour-target-highlight { border-color: Highlight; animation: none; }
|
|
129
129
|
.tour-panel, .tour-controls button { border-color: ButtonText; }
|
|
130
130
|
}
|
|
@@ -222,7 +222,7 @@ export function createSurface(doc: Document, cssUrl: string): PlayerSurface {
|
|
|
222
222
|
}
|
|
223
223
|
if (step.kind === "highlight") {
|
|
224
224
|
border = doc.createElement("div");
|
|
225
|
-
border.className = `tour-highlight tour-highlight-${step.tone ?? "accent"}`;
|
|
225
|
+
border.className = `tour-target-highlight tour-target-highlight-${step.tone ?? "accent"}`;
|
|
226
226
|
border.setAttribute("aria-hidden", "true");
|
|
227
227
|
content.append(border);
|
|
228
228
|
}
|