@tokenoftrust/storefront-runner 6.14.1 → 6.14.3
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/public/js/dashboard-apps.js +11 -1
- package/apps/storefront/src/lib/fulfillment/fulfillmentService.ts +21 -6
- package/apps/storefront/src/lib/integrations/webhooks/commercePayloads.ts +12 -1
- package/apps/storefront/src/lib/integrations/webhooks/deliveryStore.ts +18 -1
- package/apps/storefront/src/lib/integrations/webhooks/events.ts +1 -0
- package/apps/storefront/src/lib/orders/vault/appRecipientRead.ts +11 -6
- package/apps/storefront/src/lib/publication/shared/previewAnnotations/inject.ts +6 -0
- package/apps/storefront/src/lib/publication/shared/previewAnnotations/protectedSurfaces.ts +122 -0
- package/apps/storefront/src/lib/publication/shared/previewAnnotations/renderContext.ts +14 -14
- package/apps/storefront/src/lib/publication/shared/previewAnnotations/renderDecorator.ts +8 -0
- package/apps/storefront/src/middleware/renderChain.ts +2 -0
- package/package.json +1 -1
- package/packages/public-runtime/src/tenant.ts +14 -0
|
@@ -22,6 +22,13 @@
|
|
|
22
22
|
return ms >= 1000 ? (ms / 1000).toFixed(1) + "s" : ms + "ms";
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
function fmtAge(seconds) {
|
|
26
|
+
if (seconds < 60) return seconds + "s";
|
|
27
|
+
if (seconds < 3600) return Math.floor(seconds / 60) + "m";
|
|
28
|
+
if (seconds < 86400) return Math.floor(seconds / 3600) + "h";
|
|
29
|
+
return Math.floor(seconds / 86400) + "d";
|
|
30
|
+
}
|
|
31
|
+
|
|
25
32
|
function badge(text, cls) {
|
|
26
33
|
const span = document.createElement("span");
|
|
27
34
|
span.className = "badge " + cls;
|
|
@@ -61,7 +68,10 @@
|
|
|
61
68
|
row("Webhook", app.hasWebhookEndpoint ? "configured" : "not configured");
|
|
62
69
|
row("p95 delivery", fmtDuration(app.health.p95DeliveryMs));
|
|
63
70
|
row("Failure streak", String(app.health.failureStreak));
|
|
64
|
-
row("Dead-lettered", String(app.
|
|
71
|
+
row("Dead-lettered", String(app.deadLetterCount));
|
|
72
|
+
if (app.deadLetterCount > 0 && app.oldestDeadLetterAgeSeconds !== null) {
|
|
73
|
+
row("Oldest dead letter", fmtAge(app.oldestDeadLetterAgeSeconds) + " ago");
|
|
74
|
+
}
|
|
65
75
|
if (app.health.lastSuccessAt) row("Last success", app.health.lastSuccessAt);
|
|
66
76
|
card.appendChild(dl);
|
|
67
77
|
|
|
@@ -1354,11 +1354,8 @@ export class FulfillmentService {
|
|
|
1354
1354
|
params: [order.tenantId, order.stage, order.orderId, version],
|
|
1355
1355
|
};
|
|
1356
1356
|
const next = await purchaseIdFor(order.tenantId, order.stage, order.orderId, state.labelGeneration + 1);
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
sourceAdvance: false,
|
|
1360
|
-
deliveries: [],
|
|
1361
|
-
statements: [
|
|
1357
|
+
const plan: PlanStatements = { deliveries: [], statements: [] };
|
|
1358
|
+
plan.statements.push(
|
|
1362
1359
|
{
|
|
1363
1360
|
sql: `UPDATE scrappy_commerce_orders
|
|
1364
1361
|
SET label_state = 'none', event_version = event_version + 1
|
|
@@ -1403,7 +1400,25 @@ export class FulfillmentService {
|
|
|
1403
1400
|
version,
|
|
1404
1401
|
stamp(this.now(), state.auditCount + 1),
|
|
1405
1402
|
),
|
|
1406
|
-
|
|
1403
|
+
);
|
|
1404
|
+
this.appendCommerceEvent(plan, {
|
|
1405
|
+
tenantId: order.tenantId,
|
|
1406
|
+
stage: order.stage,
|
|
1407
|
+
topic: "fulfillment.label.voided",
|
|
1408
|
+
payload: {
|
|
1409
|
+
assignmentId: binding.assignmentId,
|
|
1410
|
+
orderId: order.orderId,
|
|
1411
|
+
purchaseId: evidence.purchaseId,
|
|
1412
|
+
occurredAt: this.now(),
|
|
1413
|
+
},
|
|
1414
|
+
gate: atVersion,
|
|
1415
|
+
installIds: [binding.installId],
|
|
1416
|
+
});
|
|
1417
|
+
return {
|
|
1418
|
+
type: "write",
|
|
1419
|
+
sourceAdvance: false,
|
|
1420
|
+
deliveries: plan.deliveries,
|
|
1421
|
+
statements: plan.statements,
|
|
1407
1422
|
view: appShipmentView(state, next, { version, label: "none", facts: null }),
|
|
1408
1423
|
};
|
|
1409
1424
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Payload admission for the commerce topics the single commerce emitter writes:
|
|
3
|
-
* `fulfillment.assignment.created`, `fulfillment.assignment.updated`, `order.fulfilled`,
|
|
3
|
+
* `fulfillment.assignment.created`, `fulfillment.assignment.updated`, `fulfillment.label.voided`, `order.fulfilled`,
|
|
4
4
|
* `order.partially_fulfilled` and `inventory.changed`.
|
|
5
5
|
*
|
|
6
6
|
* Each topic has a closed key set (`asyncapi.yaml` `FulfillmentAssignmentData`, `OrderData`
|
|
@@ -12,6 +12,7 @@ import type { WebhookTopic } from "./deliveryStore.js";
|
|
|
12
12
|
export type CommerceTopic =
|
|
13
13
|
| "fulfillment.assignment.created"
|
|
14
14
|
| "fulfillment.assignment.updated"
|
|
15
|
+
| "fulfillment.label.voided"
|
|
15
16
|
| "order.paid"
|
|
16
17
|
| "order.fulfilled"
|
|
17
18
|
| "order.partially_fulfilled"
|
|
@@ -22,6 +23,7 @@ export type CommerceTopic =
|
|
|
22
23
|
export const COMMERCE_TOPICS: readonly CommerceTopic[] = [
|
|
23
24
|
"fulfillment.assignment.created",
|
|
24
25
|
"fulfillment.assignment.updated",
|
|
26
|
+
"fulfillment.label.voided",
|
|
25
27
|
"order.paid",
|
|
26
28
|
"order.fulfilled",
|
|
27
29
|
"order.partially_fulfilled",
|
|
@@ -54,6 +56,7 @@ export const COMMERCE_PRIVATE_KEYS = new Set([
|
|
|
54
56
|
|
|
55
57
|
const ASSIGNMENT_KEYS = ["assignmentId", "orderId", "stage", "state", "eventVersion", "occurredAt"] as const;
|
|
56
58
|
const ASSIGNMENT_STATES = new Set(["active", "held", "cancelled"]);
|
|
59
|
+
const LABEL_VOIDED_KEYS = ["assignmentId", "orderId", "purchaseId", "occurredAt"] as const;
|
|
57
60
|
const ORDER_DATA_KEYS = new Set(["id", "status", "currency", "customerHash", "subtotal", "total", "lineItems"]);
|
|
58
61
|
const LINE_ITEM_KEYS = new Set(["sku", "handle", "quantity", "lineTotal"]);
|
|
59
62
|
export const INVENTORY_CHANGED_KEYS = ["sku", "locationId", "balance", "available", "asOf"] as const;
|
|
@@ -90,6 +93,13 @@ function assignmentAdmissible(topic: CommerceTopic, payload: Record<string, unkn
|
|
|
90
93
|
return typeof payload.occurredAt === "string" && Number.isFinite(Date.parse(payload.occurredAt));
|
|
91
94
|
}
|
|
92
95
|
|
|
96
|
+
function labelVoidedAdmissible(payload: Record<string, unknown>): boolean {
|
|
97
|
+
const keys = Object.keys(payload);
|
|
98
|
+
if (keys.length !== LABEL_VOIDED_KEYS.length || !LABEL_VOIDED_KEYS.every((key) => keys.includes(key))) return false;
|
|
99
|
+
if (!nonEmptyString(payload.assignmentId) || !nonEmptyString(payload.orderId) || !nonEmptyString(payload.purchaseId)) return false;
|
|
100
|
+
return typeof payload.occurredAt === "string" && Number.isFinite(Date.parse(payload.occurredAt));
|
|
101
|
+
}
|
|
102
|
+
|
|
93
103
|
/** `OrderData` with `status` in `allowedStatuses` and optional/required `lineItems`. */
|
|
94
104
|
function orderDataAdmissible(
|
|
95
105
|
payload: Record<string, unknown>,
|
|
@@ -144,5 +154,6 @@ export function commercePayloadAdmissible(topic: CommerceTopic, payload: unknown
|
|
|
144
154
|
if (topic === "order.cancelled") return orderDataAdmissible(payload, ["cancelled"], true);
|
|
145
155
|
if (topic === "order.updated") return orderDataAdmissible(payload, ["created", "fulfilled", "cancelled"], true);
|
|
146
156
|
if (topic === "inventory.changed") return inventoryChangedAdmissible(payload);
|
|
157
|
+
if (topic === "fulfillment.label.voided") return labelVoidedAdmissible(payload);
|
|
147
158
|
return assignmentAdmissible(topic, payload);
|
|
148
159
|
}
|
|
@@ -60,7 +60,8 @@ export type WebhookTopic =
|
|
|
60
60
|
| "customer.marketing_consent.updated"
|
|
61
61
|
| "attribution.finalized"
|
|
62
62
|
| "fulfillment.assignment.created"
|
|
63
|
-
| "fulfillment.assignment.updated"
|
|
63
|
+
| "fulfillment.assignment.updated"
|
|
64
|
+
| "fulfillment.label.voided";
|
|
64
65
|
|
|
65
66
|
/** Mirrors `Delivery.state` in `docs/private-apps/contract/openapi.yaml` EXACTLY. */
|
|
66
67
|
export type DeliveryState = "pending" | "retrying" | "delivered" | "dead-lettered";
|
|
@@ -104,6 +105,12 @@ export interface InstallHealth {
|
|
|
104
105
|
recentTraceIds: string[];
|
|
105
106
|
}
|
|
106
107
|
|
|
108
|
+
/** The install's current dead-lettered deliveries: how many, and when the oldest parked. */
|
|
109
|
+
export interface DeadLetterSummary {
|
|
110
|
+
count: number;
|
|
111
|
+
oldestAt: string | null;
|
|
112
|
+
}
|
|
113
|
+
|
|
107
114
|
export interface CreateEventInput {
|
|
108
115
|
/** Optional caller-supplied event id (e.g. for a caller-owned idempotency key). Defaults to a fresh UUID. */
|
|
109
116
|
eventId?: string;
|
|
@@ -545,6 +552,16 @@ export class WebhookDeliveryStore {
|
|
|
545
552
|
return p95DeliveryMs != null ? { ...health, p95DeliveryMs } : health;
|
|
546
553
|
}
|
|
547
554
|
|
|
555
|
+
/** Counts the install's deliveries in `dead-lettered` now; `oldestAt` is when the oldest one parked. */
|
|
556
|
+
async deadLetterSummary(installId: string): Promise<DeadLetterSummary> {
|
|
557
|
+
const row = await this.db.first<{ count: number; oldest_at: string | null }>(
|
|
558
|
+
`SELECT COUNT(*) AS count, MIN(updated_at) AS oldest_at
|
|
559
|
+
FROM webhook_deliveries WHERE install_id = ? AND state = 'dead-lettered'`,
|
|
560
|
+
installId,
|
|
561
|
+
);
|
|
562
|
+
return { count: Number(row?.count ?? 0), oldestAt: row?.oldest_at ?? null };
|
|
563
|
+
}
|
|
564
|
+
|
|
548
565
|
/**
|
|
549
566
|
* p95 across `webhook_delivery_attempts.duration_ms` for the install's
|
|
550
567
|
* {@link P95_SAMPLE_SIZE} most recent deliveries — one bounded `IN (...)`
|
|
@@ -35,6 +35,7 @@ export const TOPIC_REQUIRED_SCOPE: Record<WebhookTopic, string | null> = {
|
|
|
35
35
|
"attribution.finalized": "attribution:write",
|
|
36
36
|
"fulfillment.assignment.created": "fulfillment:process",
|
|
37
37
|
"fulfillment.assignment.updated": "fulfillment:process",
|
|
38
|
+
"fulfillment.label.voided": "fulfillment:process",
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
/** `type`'s reverse-DNS prefix (asyncapi.yaml `CloudEventEnvelope.type`). */
|
|
@@ -66,7 +66,7 @@ export type AppRecipientCode =
|
|
|
66
66
|
|
|
67
67
|
export type AppRecipientOutcome =
|
|
68
68
|
| { ok: true; recipient: AppRecipient }
|
|
69
|
-
| { ok: false; status: number; code: AppRecipientCode };
|
|
69
|
+
| { ok: false; status: number; code: AppRecipientCode; retryAfterSeconds?: number };
|
|
70
70
|
|
|
71
71
|
export interface AppRecipientInput {
|
|
72
72
|
tenantId: string;
|
|
@@ -131,7 +131,7 @@ async function classifyRefusal(
|
|
|
131
131
|
deps: AppRecipientDeps,
|
|
132
132
|
input: AppRecipientInput,
|
|
133
133
|
admitted: { eventVersion: number },
|
|
134
|
-
): Promise<{ status: number; code: AppRecipientCode } | null> {
|
|
134
|
+
): Promise<{ status: number; code: AppRecipientCode; retryAfterSeconds?: number } | null> {
|
|
135
135
|
const { db } = deps;
|
|
136
136
|
const { tenantId, stage, installId, now } = input;
|
|
137
137
|
const current = await eligibility(deps, input);
|
|
@@ -154,11 +154,16 @@ async function classifyRefusal(
|
|
|
154
154
|
return { status: 403, code: latest.revoked_at !== null ? "consent-revoked" : "consent-expired" };
|
|
155
155
|
}
|
|
156
156
|
const hourAgo = new Date(now.getTime() - HOUR_MS).toISOString();
|
|
157
|
-
const used = await db.first<{ n: number }>(
|
|
158
|
-
"SELECT COUNT(*) AS n FROM app_contact_access_audit WHERE install_id = ? AND tenant_id = ? AND at > ?",
|
|
157
|
+
const used = await db.first<{ n: number; oldest: string | null }>(
|
|
158
|
+
"SELECT COUNT(*) AS n, MIN(at) AS oldest FROM app_contact_access_audit WHERE install_id = ? AND tenant_id = ? AND at > ?",
|
|
159
159
|
installId, tenantId, hourAgo,
|
|
160
160
|
);
|
|
161
|
-
if (Number(used?.n ?? 0) >= APP_CONTACT_READS_PER_HOUR)
|
|
161
|
+
if (Number(used?.n ?? 0) >= APP_CONTACT_READS_PER_HOUR) {
|
|
162
|
+
// The oldest counted read leaves the window an hour after it was admitted.
|
|
163
|
+
const oldest = used?.oldest ? Date.parse(used.oldest) : Number.NaN;
|
|
164
|
+
const wait = Number.isFinite(oldest) ? Math.ceil((oldest + HOUR_MS - now.getTime()) / 1000) : 1;
|
|
165
|
+
return { status: 429, code: "quota", retryAfterSeconds: Math.max(1, wait) };
|
|
166
|
+
}
|
|
162
167
|
return null;
|
|
163
168
|
}
|
|
164
169
|
|
|
@@ -205,7 +210,7 @@ export async function readAppRecipient(deps: AppRecipientDeps, input: AppRecipie
|
|
|
205
210
|
}
|
|
206
211
|
if (read.ok) return { ok: true, recipient: exported(input.orderId, read.shipTo) };
|
|
207
212
|
if (read.reason !== "not-admitted") return { ok: false, status: read.status, code: read.reason };
|
|
208
|
-
let why: { status: number; code: AppRecipientCode } | null;
|
|
213
|
+
let why: { status: number; code: AppRecipientCode; retryAfterSeconds?: number } | null;
|
|
209
214
|
try {
|
|
210
215
|
why = await classifyRefusal(deps, input, eligible);
|
|
211
216
|
} catch {
|
|
@@ -35,6 +35,8 @@ export interface PreviewAnnotationBootstrapConfig {
|
|
|
35
35
|
capturePolicyVersion: string;
|
|
36
36
|
nonce?: string;
|
|
37
37
|
receiptExpiresAt: string;
|
|
38
|
+
/** May a session record capture this document? Mirrors the receipt's claim. */
|
|
39
|
+
recordable: boolean;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
export interface ReviewerCookieJar {
|
|
@@ -46,6 +48,8 @@ export interface AnnotationBootstrapInput {
|
|
|
46
48
|
secret: string | null;
|
|
47
49
|
nowSeconds: number;
|
|
48
50
|
document: RenderedDocument;
|
|
51
|
+
/** The server's recording verdict for this route (`protectedSurfaces.ts`). */
|
|
52
|
+
recordable: boolean;
|
|
49
53
|
/** Expiry of the preview capability this render rode in on, when it has one. */
|
|
50
54
|
capabilityExpiresAt?: number | null;
|
|
51
55
|
cookies: ReviewerCookieJar;
|
|
@@ -94,6 +98,7 @@ export async function buildAnnotationBootstrap(
|
|
|
94
98
|
const receipt = await signRenderReceipt(input.secret, {
|
|
95
99
|
...input.document,
|
|
96
100
|
reviewer: await reviewerPseudonym(input.secret, input.document.tenant, key),
|
|
101
|
+
recordable: input.recordable,
|
|
97
102
|
originalIssuedAt: input.nowSeconds,
|
|
98
103
|
issuedAt: input.nowSeconds,
|
|
99
104
|
expiresAt,
|
|
@@ -105,6 +110,7 @@ export async function buildAnnotationBootstrap(
|
|
|
105
110
|
capturePolicyVersion: PREVIEW_CAPTURE_POLICY_VERSION,
|
|
106
111
|
nonce: input.nonce,
|
|
107
112
|
receiptExpiresAt: new Date(expiresAt * 1000).toISOString(),
|
|
113
|
+
recordable: input.recordable,
|
|
108
114
|
};
|
|
109
115
|
}
|
|
110
116
|
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Surfaces a preview record never captures, and the route roots whose deeper segments never
|
|
3
|
+
* survive into a stored page reference. One list, imported by `safePageRef` (server) and by the
|
|
4
|
+
* session recorder (browser), so the two can never disagree.
|
|
5
|
+
*
|
|
6
|
+
* The server decides: a route is recordable only when its first segment is not a platform root
|
|
7
|
+
* below and it falls under no tenant-declared or member-area prefix. The receipt and bootstrap carry
|
|
8
|
+
* that verdict as `recordable`; the browser probe (`protectedProbe.ts`) can only narrow it.
|
|
9
|
+
*
|
|
10
|
+
* Pure and dependency-free: it ships in the Worker and in the browser client.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Route roots that can name a customer, an order, a credential or a payment, or that are platform
|
|
15
|
+
* surfaces: checkout, cart, payment, authentication, account and member areas, admin, `/cockpit`,
|
|
16
|
+
* `/api`, and age and identity verification.
|
|
17
|
+
*/
|
|
18
|
+
export const PROTECTED_ROUTE_ROOTS: ReadonlySet<string> = new Set([
|
|
19
|
+
"account", "accounts", "admin", "api", "auth", "cart", "checkout", "cockpit", "customer",
|
|
20
|
+
"customers", "invite", "invites", "login", "logout", "member", "members", "my", "order",
|
|
21
|
+
"orders", "password", "pay", "payment", "profile", "register", "reset", "signup",
|
|
22
|
+
"subscription", "subscriptions", "unsubscribe", "verify",
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Origins whose iframes collect payment details. A page embedding one is never recorded. A payment
|
|
27
|
+
* provider is added here, never by tenant config.
|
|
28
|
+
*/
|
|
29
|
+
export const PAYMENT_FRAME_ORIGINS: ReadonlySet<string> = new Set([
|
|
30
|
+
"https://js.stripe.com",
|
|
31
|
+
"https://checkout.stripe.com",
|
|
32
|
+
"https://hooks.stripe.com",
|
|
33
|
+
"https://www.paypal.com",
|
|
34
|
+
"https://www.sandbox.paypal.com",
|
|
35
|
+
"https://assets.braintreegateway.com",
|
|
36
|
+
"https://web.squarecdn.com",
|
|
37
|
+
"https://sandbox.web.squarecdn.com",
|
|
38
|
+
"https://accept.authorize.net",
|
|
39
|
+
"https://test.authorize.net",
|
|
40
|
+
"https://checkoutshopper-live.adyen.com",
|
|
41
|
+
"https://checkoutshopper-test.adyen.com",
|
|
42
|
+
"https://pay.google.com",
|
|
43
|
+
"https://js.klarna.com",
|
|
44
|
+
"https://foxycart.tokenoftrust.com",
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
/** The declared tenant configuration this module reads: additive prefixes only. */
|
|
48
|
+
export interface ProtectedSurfaceConfig {
|
|
49
|
+
/** Tenant-declared prefixes that are never recorded (`recording.protectedPrefixes`). */
|
|
50
|
+
recording?: { protectedPrefixes?: readonly string[] } | null;
|
|
51
|
+
/** ADR 0013 gated member-area prefixes (`serving.memberPrefixes`). */
|
|
52
|
+
serving?: { memberPrefixes?: readonly string[] } | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const PREFIX_PATTERN = /^\/[A-Za-z0-9._~-]+(?:\/[A-Za-z0-9._~-]+)*$/;
|
|
56
|
+
const MAX_PREFIXES = 64;
|
|
57
|
+
|
|
58
|
+
/** One prefix in canonical form (leading slash, no trailing slash, lowercase), or null. */
|
|
59
|
+
export function normalizeProtectedPrefix(value: unknown): string | null {
|
|
60
|
+
if (typeof value !== "string" || value.length > 256) return null;
|
|
61
|
+
const trimmed = value.trim().replace(/\/+$/, "");
|
|
62
|
+
if (!PREFIX_PATTERN.test(trimmed)) return null;
|
|
63
|
+
if (trimmed.split("/").some((segment) => segment === "." || segment === "..")) return null;
|
|
64
|
+
return trimmed.toLowerCase();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The tenant's protected prefixes: its declared `recording.protectedPrefixes` merged with its ADR
|
|
69
|
+
* 0013 member-area prefixes. Additive only: a tenant can protect more, never unprotect a platform
|
|
70
|
+
* root. A malformed entry is dropped (it could only ever have narrowed, never widened, recording).
|
|
71
|
+
*/
|
|
72
|
+
export function tenantProtectedPrefixes(config: ProtectedSurfaceConfig | null | undefined): string[] {
|
|
73
|
+
const declared = [
|
|
74
|
+
...(config?.recording?.protectedPrefixes ?? []),
|
|
75
|
+
...(config?.serving?.memberPrefixes ?? []),
|
|
76
|
+
];
|
|
77
|
+
const out = new Set<string>();
|
|
78
|
+
for (const entry of declared) {
|
|
79
|
+
const prefix = normalizeProtectedPrefix(entry);
|
|
80
|
+
if (prefix) out.add(prefix);
|
|
81
|
+
if (out.size >= MAX_PREFIXES) break;
|
|
82
|
+
}
|
|
83
|
+
return [...out].sort();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function decodedSegments(path: string): string[] | null {
|
|
87
|
+
const segments: string[] = [];
|
|
88
|
+
for (const raw of path.split("/")) {
|
|
89
|
+
if (raw.length === 0) continue;
|
|
90
|
+
try {
|
|
91
|
+
segments.push(decodeURIComponent(raw).toLowerCase());
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (error instanceof URIError) return null;
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return segments;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Is this route root a platform-protected surface? */
|
|
101
|
+
export function isProtectedRoot(segment: string): boolean {
|
|
102
|
+
return PROTECTED_ROUTE_ROOTS.has(segment.toLowerCase());
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* May a record capture this tenant-relative route? False for a platform root, a route under any
|
|
107
|
+
* declared prefix, or a path that cannot be decoded (fails closed).
|
|
108
|
+
*/
|
|
109
|
+
export function isRecordableRoute(renderPath: string, protectedPrefixes: readonly string[]): boolean {
|
|
110
|
+
const path = renderPath.split(/[?#]/, 1)[0] ?? "";
|
|
111
|
+
const segments = decodedSegments(path);
|
|
112
|
+
if (!segments) return false;
|
|
113
|
+
const first = segments[0];
|
|
114
|
+
if (first !== undefined && isProtectedRoot(first)) return false;
|
|
115
|
+
const canonical = `/${segments.join("/")}`;
|
|
116
|
+
for (const entry of protectedPrefixes) {
|
|
117
|
+
const prefix = normalizeProtectedPrefix(entry);
|
|
118
|
+
if (!prefix) continue;
|
|
119
|
+
if (canonical === prefix || canonical.startsWith(`${prefix}/`)) return false;
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
@@ -11,12 +11,14 @@
|
|
|
11
11
|
* - the tenant-scoped reviewer pseudonym (`rv1_…`), derived server-side from that
|
|
12
12
|
* key, so one browser has unrelated pseudonyms on different stores;
|
|
13
13
|
* - the rendered-context receipt: tenant, preview kind, rendered revision, platform
|
|
14
|
-
* build, safe page reference, the reviewer pseudonym,
|
|
15
|
-
* minted at render from server state only
|
|
14
|
+
* build, safe page reference, the reviewer pseudonym, whether a session record may
|
|
15
|
+
* capture the page, and an expiry. It is minted at render from server state only
|
|
16
|
+
* and verified again on submission.
|
|
16
17
|
*
|
|
17
18
|
* The receipt is evidence, never authority: every submission and renewal re-checks
|
|
18
19
|
* current preview access. Renderer-safe: WebCrypto only, no control-plane imports.
|
|
19
20
|
*/
|
|
21
|
+
import { isProtectedRoot } from "./protectedSurfaces";
|
|
20
22
|
|
|
21
23
|
export const PREVIEW_REVIEWER_COOKIE = "tot_pf_reviewer";
|
|
22
24
|
export const RENDER_RECEIPT_PREFIX = "pfr1";
|
|
@@ -57,6 +59,11 @@ export interface RenderedDocument {
|
|
|
57
59
|
|
|
58
60
|
export interface RenderReceiptClaims extends RenderedDocument {
|
|
59
61
|
reviewer: string;
|
|
62
|
+
/**
|
|
63
|
+
* May a session record capture this document? Decided at render from the route and the
|
|
64
|
+
* tenant's declared protected prefixes; an absent claim reads as false.
|
|
65
|
+
*/
|
|
66
|
+
recordable: boolean;
|
|
60
67
|
/** Issue time of the render that first produced this document identity. */
|
|
61
68
|
originalIssuedAt: number;
|
|
62
69
|
issuedAt: number;
|
|
@@ -153,6 +160,7 @@ export async function signRenderReceipt(secret: string, claims: RenderReceiptCla
|
|
|
153
160
|
p: claims.platformSha,
|
|
154
161
|
g: claims.pageRef,
|
|
155
162
|
rv: claims.reviewer,
|
|
163
|
+
rc: claims.recordable,
|
|
156
164
|
oiat: claims.originalIssuedAt,
|
|
157
165
|
iat: claims.issuedAt,
|
|
158
166
|
exp: claims.expiresAt,
|
|
@@ -197,6 +205,7 @@ export async function verifyRenderReceipt(
|
|
|
197
205
|
platformSha: String(raw.p ?? ""),
|
|
198
206
|
pageRef: String(raw.g ?? ""),
|
|
199
207
|
reviewer: raw.rv,
|
|
208
|
+
recordable: raw.rc === true,
|
|
200
209
|
originalIssuedAt: raw.oiat,
|
|
201
210
|
issuedAt: raw.iat,
|
|
202
211
|
expiresAt: raw.exp,
|
|
@@ -215,22 +224,13 @@ export function receiptExpiry(nowSeconds: number, capabilityExpiresAt?: number |
|
|
|
215
224
|
|
|
216
225
|
// ---- safe page reference ---------------------------------------------------
|
|
217
226
|
|
|
218
|
-
/**
|
|
219
|
-
* Routes whose path segments can name a customer, an order or a credential. Only
|
|
220
|
-
* their first segment survives; every segment under them becomes a placeholder.
|
|
221
|
-
*/
|
|
222
|
-
const PRIVATE_ROOTS = new Set([
|
|
223
|
-
"account", "accounts", "admin", "api", "auth", "cart", "checkout", "cockpit", "customer",
|
|
224
|
-
"customers", "invite", "invites", "login", "logout", "member", "members", "my", "order",
|
|
225
|
-
"orders", "password", "profile", "register", "reset", "signup", "subscription",
|
|
226
|
-
"subscriptions", "unsubscribe", "verify",
|
|
227
|
-
]);
|
|
228
227
|
const SAFE_SEGMENT = /^[a-z](?:[a-z-]{0,62}[a-z])?$/;
|
|
229
228
|
const MAX_PAGE_SEGMENTS = 12;
|
|
230
229
|
|
|
231
230
|
/**
|
|
232
231
|
* A page reference safe to store: the tenant-relative route with every segment that
|
|
233
|
-
* could carry a dynamic or private value replaced by `[segment]`.
|
|
232
|
+
* could carry a dynamic or private value replaced by `[segment]`. Under a protected route root
|
|
233
|
+
* (`protectedSurfaces.ts`) only the root survives. Query and fragment
|
|
234
234
|
* never survive. A segment is kept only when it is a short lowercase word or
|
|
235
235
|
* hyphenated words with no digits, no encoding and no dots — so ids, slugs with
|
|
236
236
|
* numbers, emails, tokens and encoded values are never presumed public.
|
|
@@ -248,7 +248,7 @@ export function safePageRef(renderPath: string): string {
|
|
|
248
248
|
}
|
|
249
249
|
const keep = !privateRoot && SAFE_SEGMENT.test(segment);
|
|
250
250
|
out.push(keep ? segment : "[segment]");
|
|
251
|
-
if (i === 0 && keep &&
|
|
251
|
+
if (i === 0 && keep && isProtectedRoot(segment)) privateRoot = true;
|
|
252
252
|
}
|
|
253
253
|
const ref = `/${out.join("/")}`;
|
|
254
254
|
return isSafePageRef(ref) ? ref : "page:unresolved";
|
|
@@ -11,9 +11,14 @@
|
|
|
11
11
|
* live/public render, or a document whose revision or platform build cannot be named. A host
|
|
12
12
|
* name or `NODE_ENV` alone never qualifies a render. The bootstrap is evidence for a later
|
|
13
13
|
* submission, never authority: the bridge re-checks current preview access on every call.
|
|
14
|
+
*
|
|
15
|
+
* Every decorated document also carries the server's recording verdict: a route under a platform
|
|
16
|
+
* protected root or a tenant-declared or member-area prefix (`protectedSurfaces.ts`) is minted
|
|
17
|
+
* `recordable:false`, and the client then mounts no recorder for it.
|
|
14
18
|
*/
|
|
15
19
|
import { HTML_CACHE_POLICY_CAPTURE_PROBE, verifyPreviewToken } from "@tot/public-runtime";
|
|
16
20
|
import { injectPreviewAnnotations, type ReviewerCookieJar } from "./inject";
|
|
21
|
+
import { isRecordableRoute } from "./protectedSurfaces";
|
|
17
22
|
import {
|
|
18
23
|
PLATFORM_SHA_PATTERN,
|
|
19
24
|
PREVIEW_REVIEWER_COOKIE,
|
|
@@ -67,6 +72,8 @@ export interface PreviewAnnotationDecoration {
|
|
|
67
72
|
candidatePin: { versionId: string; integrationStage: "candidate" | "staged" } | null;
|
|
68
73
|
tenantId: string;
|
|
69
74
|
renderPath: string;
|
|
75
|
+
/** The tenant's declared protected prefixes (`tenantProtectedPrefixes(tenant)`). */
|
|
76
|
+
protectedPrefixes: readonly string[];
|
|
70
77
|
secret: string | null;
|
|
71
78
|
nowSeconds: number;
|
|
72
79
|
cookies: ReviewerCookieJar;
|
|
@@ -123,6 +130,7 @@ export async function decoratePreviewAnnotations(
|
|
|
123
130
|
platformSha,
|
|
124
131
|
pageRef: safePageRef(input.renderPath),
|
|
125
132
|
},
|
|
133
|
+
recordable: isRecordableRoute(input.renderPath, input.protectedPrefixes),
|
|
126
134
|
capabilityExpiresAt,
|
|
127
135
|
cookies: input.cookies,
|
|
128
136
|
pageBase: input.pageBase,
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
decoratePreviewAnnotations,
|
|
35
35
|
isPublicationCapture,
|
|
36
36
|
} from "@/lib/publication/shared/previewAnnotations/renderDecorator";
|
|
37
|
+
import { tenantProtectedPrefixes } from "@/lib/publication/shared/previewAnnotations/protectedSurfaces";
|
|
37
38
|
import {
|
|
38
39
|
resolveCustomizationEnv,
|
|
39
40
|
buildCsp,
|
|
@@ -865,6 +866,7 @@ export async function runRenderChain(input: RenderChainInput): Promise<Response>
|
|
|
865
866
|
candidatePin: candidatePin ?? null,
|
|
866
867
|
tenantId: tenant.tenant_id,
|
|
867
868
|
renderPath,
|
|
869
|
+
protectedPrefixes: tenantProtectedPrefixes(tenant),
|
|
868
870
|
secret: previewSecret,
|
|
869
871
|
nowSeconds,
|
|
870
872
|
cookies: context.cookies,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "6.14.
|
|
3
|
+
"version": "6.14.3",
|
|
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",
|
|
@@ -715,6 +715,20 @@ export interface TenantConfig {
|
|
|
715
715
|
* while a fresh one is fetched. All in seconds. Absent ⇒ {@link DEFAULT_HTML_CACHE_POLICY}.
|
|
716
716
|
*/
|
|
717
717
|
htmlCachePolicy?: HtmlCachePolicy;
|
|
718
|
+
/**
|
|
719
|
+
* Gated member-area route prefixes (ADR 0013: member areas are path-scoped), e.g.
|
|
720
|
+
* `["/club"]`. Each is routed to the Worker origin with caching off, and a preview
|
|
721
|
+
* session record never captures a page under one.
|
|
722
|
+
*/
|
|
723
|
+
memberPrefixes?: string[];
|
|
724
|
+
};
|
|
725
|
+
/**
|
|
726
|
+
* Preview session recording (feedback record contract §6). `protectedPrefixes` names
|
|
727
|
+
* tenant routes a record never captures, in addition to the platform's protected roots
|
|
728
|
+
* and `serving.memberPrefixes`. Additive only: it cannot unprotect a platform root.
|
|
729
|
+
*/
|
|
730
|
+
recording?: {
|
|
731
|
+
protectedPrefixes?: string[];
|
|
718
732
|
};
|
|
719
733
|
/**
|
|
720
734
|
* Catalog serving (ADR 0033). The store's own `content/catalog/` files are the
|