@tokenoftrust/storefront-runner 7.8.9 → 7.8.10

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.
@@ -80,7 +80,7 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
80
80
  const [familyName, setFamilyName] = useState("");
81
81
  const [guestShopper, setGuestShopper] = useState(false);
82
82
  const [saveForFastTrack, setSaveForFastTrack] = useState(true);
83
- const fastTrackSentRef = useRef(false);
83
+ const fastTrackSendRef = useRef<Promise<boolean> | null>(null);
84
84
  const [verificationRef, setVerificationRef] = useState<string | null>(null);
85
85
  const [continuationUrl, setContinuationUrl] = useState<string | null>(null);
86
86
  const [popupBlocked, setPopupBlocked] = useState(false);
@@ -146,7 +146,7 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
146
146
  setPopupBlocked(false);
147
147
  setGuestShopper(false);
148
148
  setSaveForFastTrack(true);
149
- fastTrackSentRef.current = false;
149
+ fastTrackSendRef.current = null;
150
150
  // A reload mid-trip must not lose the correlation: replay the stored ref so
151
151
  // the server re-reads THIS attempt's verification instead of starting over.
152
152
  setVerificationRef(line.shopperCart ? null :
@@ -185,7 +185,7 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
185
185
  document.documentElement.style.overflow = "";
186
186
  }, [stopPolling]);
187
187
 
188
- const proceed = useCallback((line: PendingLine, ref: string | null) => {
188
+ const submitClearedLine = useCallback((line: PendingLine, ref: string | null) => {
189
189
  stopPolling();
190
190
  if (line.shopperCart) {
191
191
  const current = checkoutLineFromForm(line.form);
@@ -212,6 +212,19 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
212
212
  else line.form.submit();
213
213
  if (line.shopperCart) delete line.form.dataset.complianceCleared;
214
214
  }, [close, preflightUrl, stopPolling]);
215
+
216
+ const proceed = useCallback((line: PendingLine, ref: string | null) => {
217
+ const fastTrackSend = activeDialogLine.current === line ? fastTrackSendRef.current : null;
218
+ if (!fastTrackSend) {
219
+ submitClearedLine(line, ref);
220
+ return;
221
+ }
222
+ // The native fallback can leave the page before the challenge is stored.
223
+ setLoading(true);
224
+ void fastTrackSend.then(() => {
225
+ if (activeDialogLine.current === line) submitClearedLine(line, ref);
226
+ });
227
+ }, [submitClearedLine]);
215
228
  proceedRef.current = proceed;
216
229
 
217
230
  /**
@@ -384,11 +397,12 @@ export default function CheckoutComplianceGate({ preflightUrl, minAge }: Props)
384
397
  setError(gateRefused.current ? STORE_NOT_PUBLIC_MESSAGE : FAIL_CLOSED_MESSAGE);
385
398
  return;
386
399
  }
387
- if (phase === "collect" && guestShopper && !fastTrackSentRef.current && saveForFastTrack && email.trim()) {
400
+ if (phase === "collect" && guestShopper && !fastTrackSendRef.current && saveForFastTrack && email.trim()) {
388
401
  const next = verificationPhase(res);
389
402
  if (next === "continue" || next === "waiting" || next === "cleared") {
390
- fastTrackSentRef.current = true;
391
- void requestFastTrackAccountSave({ preflightUrl, email, saveForFastTrack, shopperCart: pending.shopperCart });
403
+ fastTrackSendRef.current = requestFastTrackAccountSave({
404
+ preflightUrl, email, saveForFastTrack, shopperCart: pending.shopperCart,
405
+ });
392
406
  }
393
407
  }
394
408
  apply(pending, res);
@@ -142,6 +142,17 @@ export function shopperAuthSendUrl(preflightUrl: string): string {
142
142
  return shopperAccountUrl(preflightUrl, "auth/send");
143
143
  }
144
144
 
145
+ export const SHOPPER_CHALLENGE_TTL_MS = 600_000;
146
+ const SHOPPER_CHALLENGE_REQUEST_TIMEOUT_MS = 5_000;
147
+
148
+ export function shopperChallengeKey(apiBase: string): string {
149
+ return `tot:shopper-challenge:${apiBase.replace(/\/+$/, "")}`;
150
+ }
151
+
152
+ function isShopperChallengeId(value: unknown): value is string {
153
+ return typeof value === "string" && /^[\w-]{43}$/.test(value);
154
+ }
155
+
145
156
  export async function isGuestShopper(preflightUrl: string): Promise<boolean> {
146
157
  const url = shopperAccountUrl(preflightUrl, "me");
147
158
  if (url === preflightUrl) return false;
@@ -173,10 +184,23 @@ export async function requestFastTrackAccountSave(opts: {
173
184
  headers: { "content-type": "application/json" },
174
185
  credentials: "same-origin",
175
186
  keepalive: true,
187
+ signal: AbortSignal.timeout(SHOPPER_CHALLENGE_REQUEST_TIMEOUT_MS),
176
188
  body: JSON.stringify({ identifier }),
177
189
  });
178
190
  if (!response.ok) return false;
179
- await response.json();
191
+ const body: unknown = await response.json();
192
+ if (body && typeof body === "object" && "ok" in body && body.ok === true &&
193
+ "challengeId" in body && isShopperChallengeId(body.challengeId)) {
194
+ const apiBase = opts.preflightUrl.slice(0, -"/api/compliance/preflight".length);
195
+ try {
196
+ sessionStorage.setItem(shopperChallengeKey(apiBase), JSON.stringify({
197
+ challengeId: body.challengeId,
198
+ expiresAt: Date.now() + SHOPPER_CHALLENGE_TTL_MS,
199
+ }));
200
+ } catch {
201
+ // Storage failure does not change the send result.
202
+ }
203
+ }
180
204
  return true;
181
205
  } catch {
182
206
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "7.8.9",
3
+ "version": "7.8.10",
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",