@tokenoftrust/storefront-runner 7.8.6 → 7.8.8
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/components/compliance/storefront/islands/CheckoutComplianceGate.tsx +47 -2
- package/apps/storefront/src/lib/access/shared/tenantRouting.ts +1 -1
- package/apps/storefront/src/lib/compliance/browser/checkoutVerificationFlow.ts +49 -0
- package/package.json +1 -1
- package/packages/public-runtime/src/image-dependencies.ts +83 -2
package/apps/storefront/src/components/compliance/storefront/islands/CheckoutComplianceGate.tsx
CHANGED
|
@@ -29,10 +29,12 @@ import {
|
|
|
29
29
|
carryCheckoutVerification,
|
|
30
30
|
checkoutLineFromForm,
|
|
31
31
|
clearStoredRef,
|
|
32
|
+
isGuestShopper,
|
|
32
33
|
isStoreNotPublicRefusal,
|
|
33
34
|
parsePreflightResponse,
|
|
34
35
|
pollVerification,
|
|
35
36
|
readStoredRef,
|
|
37
|
+
requestFastTrackAccountSave,
|
|
36
38
|
verificationPhase,
|
|
37
39
|
verificationRefKey,
|
|
38
40
|
verifiedRefKey,
|
|
@@ -63,6 +65,7 @@ const STORE_NOT_PUBLIC_MESSAGE =
|
|
|
63
65
|
|
|
64
66
|
export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props) {
|
|
65
67
|
const [pending, setPending] = useState<PendingLine | null>(null);
|
|
68
|
+
const activeDialogLine = useRef<PendingLine | null>(null);
|
|
66
69
|
const [region, setRegion] = useState("");
|
|
67
70
|
const [affirmed, setAffirmed] = useState(false);
|
|
68
71
|
const [loading, setLoading] = useState(false);
|
|
@@ -75,6 +78,9 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
|
|
|
75
78
|
const [email, setEmail] = useState("");
|
|
76
79
|
const [givenName, setGivenName] = useState("");
|
|
77
80
|
const [familyName, setFamilyName] = useState("");
|
|
81
|
+
const [guestShopper, setGuestShopper] = useState(false);
|
|
82
|
+
const [saveForFastTrack, setSaveForFastTrack] = useState(true);
|
|
83
|
+
const fastTrackSentRef = useRef(false);
|
|
78
84
|
const [verificationRef, setVerificationRef] = useState<string | null>(null);
|
|
79
85
|
const [continuationUrl, setContinuationUrl] = useState<string | null>(null);
|
|
80
86
|
const [popupBlocked, setPopupBlocked] = useState(false);
|
|
@@ -129,12 +135,18 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
|
|
|
129
135
|
}
|
|
130
136
|
}
|
|
131
137
|
function open(line: PendingLine) {
|
|
138
|
+
stopPolling();
|
|
139
|
+
activeDialogLine.current = line;
|
|
132
140
|
setPending(line);
|
|
133
141
|
setDecision(null);
|
|
134
142
|
setError(null);
|
|
143
|
+
setLoading(false);
|
|
135
144
|
setPhase("none");
|
|
136
145
|
setContinuationUrl(null);
|
|
137
146
|
setPopupBlocked(false);
|
|
147
|
+
setGuestShopper(false);
|
|
148
|
+
setSaveForFastTrack(true);
|
|
149
|
+
fastTrackSentRef.current = false;
|
|
138
150
|
// A reload mid-trip must not lose the correlation: replay the stored ref so
|
|
139
151
|
// the server re-reads THIS attempt's verification instead of starting over.
|
|
140
152
|
setVerificationRef(line.shopperCart ? null :
|
|
@@ -150,10 +162,21 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
|
|
|
150
162
|
}
|
|
151
163
|
document.addEventListener("submit", onSubmit, true);
|
|
152
164
|
return () => document.removeEventListener("submit", onSubmit, true);
|
|
153
|
-
}, [preflightUrl]);
|
|
165
|
+
}, [preflightUrl, stopPolling]);
|
|
166
|
+
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
if (phase !== "collect" || !pending || pending.shopperCart) return;
|
|
169
|
+
// An open store uses the managed cart for signed-in shoppers too.
|
|
170
|
+
let cancelled = false;
|
|
171
|
+
void isGuestShopper(preflightUrl).then((guest) => {
|
|
172
|
+
if (!cancelled && activeDialogLine.current === pending) setGuestShopper(guest);
|
|
173
|
+
});
|
|
174
|
+
return () => { cancelled = true; };
|
|
175
|
+
}, [pending, phase, preflightUrl]);
|
|
154
176
|
|
|
155
177
|
const close = useCallback(() => {
|
|
156
178
|
stopPolling();
|
|
179
|
+
activeDialogLine.current = null;
|
|
157
180
|
setPending(null);
|
|
158
181
|
setDecision(null);
|
|
159
182
|
setError(null);
|
|
@@ -183,6 +206,7 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
|
|
|
183
206
|
line.form.dataset.complianceCleared = "1";
|
|
184
207
|
line.form.dataset.paymentAuthority = "none";
|
|
185
208
|
document.documentElement.style.overflow = "";
|
|
209
|
+
activeDialogLine.current = null;
|
|
186
210
|
setPending(null);
|
|
187
211
|
if (typeof line.form.requestSubmit === "function") line.form.requestSubmit();
|
|
188
212
|
else line.form.submit();
|
|
@@ -353,14 +377,22 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
|
|
|
353
377
|
ref: verificationRef,
|
|
354
378
|
includeShopper: phase === "collect" || phase === "stalled",
|
|
355
379
|
});
|
|
380
|
+
if (activeDialogLine.current !== pending) return;
|
|
356
381
|
setLoading(false);
|
|
357
382
|
if (!res) {
|
|
358
383
|
// Fail closed: a regulated tenant never proceeds on an unreadable result.
|
|
359
384
|
setError(gateRefused.current ? STORE_NOT_PUBLIC_MESSAGE : FAIL_CLOSED_MESSAGE);
|
|
360
385
|
return;
|
|
361
386
|
}
|
|
387
|
+
if (phase === "collect" && guestShopper && !fastTrackSentRef.current && saveForFastTrack && email.trim()) {
|
|
388
|
+
const next = verificationPhase(res);
|
|
389
|
+
if (next === "continue" || next === "waiting" || next === "cleared") {
|
|
390
|
+
fastTrackSentRef.current = true;
|
|
391
|
+
void requestFastTrackAccountSave({ preflightUrl, email, saveForFastTrack, shopperCart: pending.shopperCart });
|
|
392
|
+
}
|
|
393
|
+
}
|
|
362
394
|
apply(pending, res);
|
|
363
|
-
}, [pending, send, apply, verificationRef, phase, stopPolling]);
|
|
395
|
+
}, [pending, send, apply, verificationRef, phase, stopPolling, guestShopper, email, saveForFastTrack, preflightUrl]);
|
|
364
396
|
|
|
365
397
|
/** Abandon a denied attempt and start a brand-new verification (new ref). */
|
|
366
398
|
const restartVerification = useCallback(() => {
|
|
@@ -501,6 +533,19 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
|
|
|
501
533
|
/>
|
|
502
534
|
</label>
|
|
503
535
|
</div>
|
|
536
|
+
{guestShopper && (
|
|
537
|
+
<label class="flex items-start gap-2.5 text-sm text-[var(--color-text)]">
|
|
538
|
+
<input
|
|
539
|
+
type="checkbox"
|
|
540
|
+
name="tot-save-fast-track"
|
|
541
|
+
class="mt-0.5 h-4 w-4"
|
|
542
|
+
checked={saveForFastTrack}
|
|
543
|
+
disabled={loading}
|
|
544
|
+
onChange={(e) => setSaveForFastTrack((e.target as HTMLInputElement).checked)}
|
|
545
|
+
/>
|
|
546
|
+
<span>Save my verified info for 1-click fast-track checkout & order history.</span>
|
|
547
|
+
</label>
|
|
548
|
+
)}
|
|
504
549
|
</div>
|
|
505
550
|
)}
|
|
506
551
|
</div>
|
|
@@ -145,7 +145,7 @@ export async function resolveTenantRouting(
|
|
|
145
145
|
if (selfMatch && hostSegments[1] === "preview") {
|
|
146
146
|
return {
|
|
147
147
|
tenant: byHost,
|
|
148
|
-
basePath:
|
|
148
|
+
basePath: "",
|
|
149
149
|
renderPath: normalizePath(hostSegments.slice(1).join("/")),
|
|
150
150
|
};
|
|
151
151
|
}
|
|
@@ -134,6 +134,55 @@ export function bypassesComplianceGate(res: PreflightResponse | null): boolean {
|
|
|
134
134
|
return res !== null && res.gate === "not-required" && res.decision.status === "clear";
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
function shopperAccountUrl(preflightUrl: string, endpoint: string): string {
|
|
138
|
+
return preflightUrl.replace(/\/api\/compliance\/preflight$/, `/api/account/${endpoint}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function shopperAuthSendUrl(preflightUrl: string): string {
|
|
142
|
+
return shopperAccountUrl(preflightUrl, "auth/send");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export async function isGuestShopper(preflightUrl: string): Promise<boolean> {
|
|
146
|
+
const url = shopperAccountUrl(preflightUrl, "me");
|
|
147
|
+
if (url === preflightUrl) return false;
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const response = await fetch(url, { credentials: "same-origin" });
|
|
151
|
+
return response.status === 401 && (await response.json())?.signedIn === false;
|
|
152
|
+
} catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export async function requestFastTrackAccountSave(opts: {
|
|
158
|
+
preflightUrl: string;
|
|
159
|
+
email: string;
|
|
160
|
+
saveForFastTrack: boolean;
|
|
161
|
+
shopperCart: boolean;
|
|
162
|
+
fetchImpl?: typeof fetch;
|
|
163
|
+
}): Promise<boolean> {
|
|
164
|
+
const identifier = opts.email.trim().toLowerCase();
|
|
165
|
+
if (!opts.saveForFastTrack || opts.shopperCart || !identifier) return false;
|
|
166
|
+
|
|
167
|
+
const url = shopperAuthSendUrl(opts.preflightUrl);
|
|
168
|
+
if (url === opts.preflightUrl) return false;
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
const response = await (opts.fetchImpl ?? fetch)(url, {
|
|
172
|
+
method: "POST",
|
|
173
|
+
headers: { "content-type": "application/json" },
|
|
174
|
+
credentials: "same-origin",
|
|
175
|
+
keepalive: true,
|
|
176
|
+
body: JSON.stringify({ identifier }),
|
|
177
|
+
});
|
|
178
|
+
if (!response.ok) return false;
|
|
179
|
+
await response.json();
|
|
180
|
+
return true;
|
|
181
|
+
} catch {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
137
186
|
export interface PendingLine {
|
|
138
187
|
form: HTMLFormElement;
|
|
139
188
|
shopperCart: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "7.8.
|
|
3
|
+
"version": "7.8.8",
|
|
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",
|
|
@@ -531,7 +531,88 @@ function adoptCssReferences(refs: ExtractedReference[], cssRefs: readonly Extrac
|
|
|
531
531
|
for (const ref of cssRefs) refs.push(afterBase ? { ...ref, afterBase: true } : ref);
|
|
532
532
|
}
|
|
533
533
|
|
|
534
|
-
|
|
534
|
+
/**
|
|
535
|
+
* CSS custom properties the platform always provides on every page (`themeToCssVars` in
|
|
536
|
+
* `apps/storefront/src/themes/schema.ts` and `@theme` / `@layer base` in `styles/global.css`).
|
|
537
|
+
* None of these ever resolve to an image URL, so a tenant stylesheet that reads `var(--color-bg)`
|
|
538
|
+
* or `var(--font-display)` in a `background` or `font` declaration is never deferred as an
|
|
539
|
+
* unknown image variable.
|
|
540
|
+
*/
|
|
541
|
+
const PLATFORM_CUSTOM_PROPERTIES = [
|
|
542
|
+
"--color-bg",
|
|
543
|
+
"--color-surface",
|
|
544
|
+
"--color-surface-2",
|
|
545
|
+
"--color-text",
|
|
546
|
+
"--color-muted",
|
|
547
|
+
"--color-primary",
|
|
548
|
+
"--color-primary-contrast",
|
|
549
|
+
"--color-primary-hover",
|
|
550
|
+
"--color-accent",
|
|
551
|
+
"--color-accent-ink",
|
|
552
|
+
"--color-accent-contrast",
|
|
553
|
+
"--color-accent-hover",
|
|
554
|
+
"--color-border",
|
|
555
|
+
"--color-field-border",
|
|
556
|
+
"--color-success",
|
|
557
|
+
"--color-sale",
|
|
558
|
+
"--color-warning",
|
|
559
|
+
"--color-error",
|
|
560
|
+
"--color-info",
|
|
561
|
+
"--color-focus-ring",
|
|
562
|
+
"--color-disabled",
|
|
563
|
+
"--color-disabled-contrast",
|
|
564
|
+
"--color-star",
|
|
565
|
+
"--color-cta",
|
|
566
|
+
"--color-cta-hover",
|
|
567
|
+
"--color-cta-contrast",
|
|
568
|
+
"--color-trust",
|
|
569
|
+
"--color-hero-eyebrow",
|
|
570
|
+
"--font-display",
|
|
571
|
+
"--font-body",
|
|
572
|
+
"--font-mono",
|
|
573
|
+
"--type-scale",
|
|
574
|
+
"--type-tracking",
|
|
575
|
+
"--fs-xs",
|
|
576
|
+
"--fs-sm",
|
|
577
|
+
"--fs-base",
|
|
578
|
+
"--fs-md",
|
|
579
|
+
"--fs-lg",
|
|
580
|
+
"--fs-xl",
|
|
581
|
+
"--fs-2xl",
|
|
582
|
+
"--fs-3xl",
|
|
583
|
+
"--fs-4xl",
|
|
584
|
+
"--fs-5xl",
|
|
585
|
+
"--heading-hero",
|
|
586
|
+
"--heading-h1",
|
|
587
|
+
"--heading-h2",
|
|
588
|
+
"--heading-h3",
|
|
589
|
+
"--space-base",
|
|
590
|
+
"--space-0",
|
|
591
|
+
"--space-1",
|
|
592
|
+
"--space-2",
|
|
593
|
+
"--space-3",
|
|
594
|
+
"--space-4",
|
|
595
|
+
"--space-5",
|
|
596
|
+
"--space-6",
|
|
597
|
+
"--space-7",
|
|
598
|
+
"--space-8",
|
|
599
|
+
"--space-9",
|
|
600
|
+
"--container-max",
|
|
601
|
+
"--section-rhythm",
|
|
602
|
+
"--radius-sm",
|
|
603
|
+
"--radius-md",
|
|
604
|
+
"--radius-lg",
|
|
605
|
+
"--radius-full",
|
|
606
|
+
"--border-thin",
|
|
607
|
+
"--border-medium",
|
|
608
|
+
"--border-thick",
|
|
609
|
+
"--shadow-sm",
|
|
610
|
+
"--shadow-md",
|
|
611
|
+
"--shadow-lg",
|
|
612
|
+
"--tap-target",
|
|
613
|
+
] as const;
|
|
614
|
+
|
|
615
|
+
const NO_DECLARED_CUSTOM_PROPERTIES: ReadonlySet<string> = new Set(PLATFORM_CUSTOM_PROPERTIES);
|
|
535
616
|
|
|
536
617
|
/**
|
|
537
618
|
* CSS extraction uses a JavaScript parser because this module is imported by
|
|
@@ -1496,7 +1577,7 @@ function rawCssChunksInHtml(html: string): Array<{ css: string; kind: "styleshee
|
|
|
1496
1577
|
* captured at the declaration itself.
|
|
1497
1578
|
*/
|
|
1498
1579
|
export function collectDeclaredCustomProperties(artifacts: readonly ImageDependencyArtifact[]): Set<string> {
|
|
1499
|
-
const declared = new Set<string>();
|
|
1580
|
+
const declared = new Set<string>(PLATFORM_CUSTOM_PROPERTIES);
|
|
1500
1581
|
for (const artifact of artifacts) {
|
|
1501
1582
|
const kind = inferKind(artifact);
|
|
1502
1583
|
if (kind === "css") {
|