@tokenoftrust/storefront-runner 7.9.10 → 7.9.11
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* <CheckoutComplianceGate> — browser preflight for a regulated add-to-cart submit.
|
|
3
3
|
*
|
|
4
|
-
* The dialog collects the age affirmation
|
|
4
|
+
* The dialog collects the age affirmation, plus a ship-to state only when the server requires one (never on the sandbox provider), then asks
|
|
5
5
|
* `/api/compliance/preflight` whether this browser may submit the form. Only a
|
|
6
6
|
* server `clear` releases that submit. A hard block (restricted destination,
|
|
7
7
|
* flavored ban, per-order limit, failed or unconfigured verification) stops it.
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* never hydrates, or scripts are disabled, the form posts on its own.
|
|
24
24
|
*/
|
|
25
25
|
import { useCallback, useEffect, useRef, useState } from "preact/hooks";
|
|
26
|
-
import type
|
|
26
|
+
import { US_REGIONS, type CartComplianceDecision } from "@tot/public-runtime";
|
|
27
27
|
import {
|
|
28
28
|
arrivalAgeAffirmed,
|
|
29
29
|
bypassesComplianceGate,
|
|
@@ -67,6 +67,9 @@ const STORE_NOT_PUBLIC_MESSAGE =
|
|
|
67
67
|
export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props) {
|
|
68
68
|
const [pending, setPending] = useState<PendingLine | null>(null);
|
|
69
69
|
const activeDialogLine = useRef<PendingLine | null>(null);
|
|
70
|
+
const [region, setRegion] = useState("");
|
|
71
|
+
/** The server asked for a ship-to state (live providers only; the sandbox never does). */
|
|
72
|
+
const [stateRequired, setStateRequired] = useState(false);
|
|
70
73
|
const [affirmed, setAffirmed] = useState(false);
|
|
71
74
|
const [loading, setLoading] = useState(false);
|
|
72
75
|
const [decision, setDecision] = useState<CartComplianceDecision | null>(null);
|
|
@@ -114,7 +117,7 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
|
|
|
114
117
|
// readable "not-required" + clear answer skips the dialog; anything else opens it.
|
|
115
118
|
void probe(line).then((res) => {
|
|
116
119
|
if (bypassesComplianceGate(res)) proceedRef.current?.(line, res?.verification?.ref ?? null);
|
|
117
|
-
else open(line);
|
|
120
|
+
else open(line, res);
|
|
118
121
|
});
|
|
119
122
|
}
|
|
120
123
|
async function probe(line: PendingLine): Promise<PreflightResponse | null> {
|
|
@@ -134,8 +137,10 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
|
|
|
134
137
|
return null;
|
|
135
138
|
}
|
|
136
139
|
}
|
|
137
|
-
function open(line: PendingLine) {
|
|
140
|
+
function open(line: PendingLine, probed: PreflightResponse | null) {
|
|
138
141
|
stopPolling();
|
|
142
|
+
setRegion("");
|
|
143
|
+
setStateRequired(probed?.decision.requirements.destination === "required");
|
|
139
144
|
activeDialogLine.current = line;
|
|
140
145
|
setPending(line);
|
|
141
146
|
setDecision(null);
|
|
@@ -251,7 +256,7 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
|
|
|
251
256
|
quantity: line.quantity,
|
|
252
257
|
},
|
|
253
258
|
],
|
|
254
|
-
destination: null,
|
|
259
|
+
destination: region ? { region, country: "US" } : null,
|
|
255
260
|
ageAffirmed: affirmed,
|
|
256
261
|
...(opts.ref ? { verificationRef: opts.ref } : {}),
|
|
257
262
|
...(opts.includeShopper && trimmedEmail
|
|
@@ -274,7 +279,7 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
|
|
|
274
279
|
return null;
|
|
275
280
|
}
|
|
276
281
|
},
|
|
277
|
-
[preflightUrl, affirmed, email, givenName, familyName],
|
|
282
|
+
[preflightUrl, region, affirmed, email, givenName, familyName],
|
|
278
283
|
);
|
|
279
284
|
|
|
280
285
|
/**
|
|
@@ -344,6 +349,7 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
|
|
|
344
349
|
if (meta?.continuationUrl) setContinuationUrl(meta.continuationUrl);
|
|
345
350
|
|
|
346
351
|
setDecision(res.decision);
|
|
352
|
+
if (res.decision.requirements.destination === "required") setStateRequired(true);
|
|
347
353
|
// Only the server's own verdict releases the handoff.
|
|
348
354
|
if (res.decision.status === "clear") {
|
|
349
355
|
proceed(line, ref);
|
|
@@ -461,6 +467,29 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
|
|
|
461
467
|
</p>
|
|
462
468
|
|
|
463
469
|
<div class="mt-5 flex flex-col gap-4">
|
|
470
|
+
{stateRequired && (
|
|
471
|
+
<label class="flex flex-col gap-1.5">
|
|
472
|
+
<span class="font-mono text-xs uppercase tracking-[0.12em] text-[var(--color-muted)]">
|
|
473
|
+
Ship to state
|
|
474
|
+
</span>
|
|
475
|
+
<select
|
|
476
|
+
class="rounded-[var(--radius-md)] border border-[var(--color-border)] bg-[var(--color-bg)] px-3 py-2.5 text-[var(--color-text)]"
|
|
477
|
+
value={region}
|
|
478
|
+
onChange={(e) => {
|
|
479
|
+
setRegion((e.target as HTMLSelectElement).value);
|
|
480
|
+
setDecision(null);
|
|
481
|
+
}}
|
|
482
|
+
>
|
|
483
|
+
<option value="">Select a state…</option>
|
|
484
|
+
{US_REGIONS.map((r) => (
|
|
485
|
+
<option key={r.code} value={r.code}>
|
|
486
|
+
{r.name}
|
|
487
|
+
</option>
|
|
488
|
+
))}
|
|
489
|
+
</select>
|
|
490
|
+
</label>
|
|
491
|
+
)}
|
|
492
|
+
|
|
464
493
|
<label class="flex items-start gap-2.5 text-sm text-[var(--color-text)]">
|
|
465
494
|
<input
|
|
466
495
|
type="checkbox"
|
|
@@ -460,12 +460,11 @@ export async function evaluatePreflight(
|
|
|
460
460
|
ageAffirmed: body.ageAffirmed === true,
|
|
461
461
|
});
|
|
462
462
|
|
|
463
|
-
// Add-to-cart happens before any shipping address exists. On the sandbox provider
|
|
464
|
-
//
|
|
465
|
-
//
|
|
463
|
+
// Add-to-cart happens before any shipping address exists. On the sandbox provider a missing
|
|
464
|
+
// destination is never a block: the shopper is not asked for a state, and the destination
|
|
465
|
+
// rules run once checkout supplies the address. Other providers keep `destination_required`.
|
|
466
466
|
const preAddress =
|
|
467
467
|
!destination &&
|
|
468
|
-
body.ageAffirmed === true &&
|
|
469
468
|
!!ruleset &&
|
|
470
469
|
isSandboxVerificationProvider(ruleset.verification.provider);
|
|
471
470
|
const base = preAddress ? withoutDestinationRequired(decision) : decision;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "7.9.
|
|
3
|
+
"version": "7.9.11",
|
|
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",
|