@tokenoftrust/storefront-runner 6.3.2 → 6.3.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.
@@ -0,0 +1,52 @@
1
+ /** One shopper-readable sentence for every final-cart refusal finding. Closed text only; never cart or tenant data. */
2
+ export const GENERIC_REFUSAL_SENTENCE = "We couldn't confirm your order right now. Please review your cart and try again, or contact the store if it keeps happening.";
3
+
4
+ const SENTENCES: Readonly<Record<string, string>> = {
5
+ "tenant-not-admitted": "This store isn't set up to accept orders yet. Please contact the store for help.",
6
+ "tenant-unregistered": "This store isn't set up to accept orders yet. Please contact the store for help.",
7
+ "shared-store-unavailable": "Checkout is temporarily unavailable. Please try again later.",
8
+ "checkout-unconfigured": "Checkout isn't set up for this store yet. Please contact the store for help.",
9
+ "tenant-own-store": "This store checks out through its own payment page, so this cart can't be confirmed here.",
10
+ "caller-unconfigured": "Checkout is temporarily unavailable. Please try again later.",
11
+ "store-unconfigured": "Checkout is temporarily unavailable. Please try again later.",
12
+ "config-unreadable": "Checkout is temporarily unavailable. Please try again later.",
13
+ "catalog-unavailable": "We couldn't load the product catalog. Please try again in a moment.",
14
+ "checkout-requirements-unreadable": "Checkout is temporarily unavailable. Please try again later.",
15
+ "authority-error": "Something went wrong confirming your order. Please try again.",
16
+ "authority-unavailable": "We couldn't check stock for your cart right now. Please try again in a moment.",
17
+ "malformed-request": "We couldn't read your cart. Please return to the cart and try again.",
18
+ "catalog-cart-mismatch": "Something in your cart is no longer available as listed. Please review your cart and try again.",
19
+ "catalog-not-authority": "Something in your cart is no longer available as listed. Please review your cart and try again.",
20
+ "shipping-unavailable": "We couldn't work out shipping for your cart. Please review your cart and try again.",
21
+ "shipping-changed": "Shipping for your cart has changed. Please review your cart and try again.",
22
+ "stock-unavailable": "One or more items in your cart are out of stock.",
23
+ "stock-unknown": "We couldn't confirm stock for your cart. Please try again in a moment.",
24
+ "provider-cart-conflict": "Your cart changed in another window. Please reload the cart and try again.",
25
+ "provider-cart-changed": "Your cart changed since it was checked. Please review your cart and try again.",
26
+ "admission-consumed": "This cart has already been used for an order. Please start a new cart.",
27
+ "admission-expired": "Your cart check expired. Please return to the cart and try again.",
28
+ "evidence-expired": "Your cart check expired. Please return to the cart and try again.",
29
+ "tenant-changed": "Your cart changed since it was checked. Please review your cart and try again.",
30
+ "stage-changed": "Your cart changed since it was checked. Please review your cart and try again.",
31
+ "currency-changed": "The currency for your cart changed. Please review your cart and try again.",
32
+ "destination-changed": "Your shipping destination changed. Please review your cart and try again.",
33
+ "product-changed": "Your cart changed since it was checked. Please review your cart and try again.",
34
+ "price-changed": "A price in your cart changed. Please review your cart and try again.",
35
+ "quantity-changed": "A quantity in your cart changed. Please review your cart and try again.",
36
+ "evidence-window-changed": "Your cart check expired. Please return to the cart and try again.",
37
+ "cart-unbound": "Your cart changed since it was checked. Please review your cart and try again.",
38
+ "verification-seam-absent": "We couldn't verify your age and eligibility right now. Please try again in a moment.",
39
+ "verification-provider-unconfigured": "Age verification isn't available for this store right now. Please contact the store for help.",
40
+ "verification-refused": "Your order can't be completed because it didn't pass the store's eligibility checks.",
41
+ "payment-reconcile": "We couldn't confirm payment for your order. Please try again.",
42
+ "payment-refused": "Payment for your order couldn't be confirmed. Please try again.",
43
+ "fulfillment-refused": "This order can't be fulfilled as requested. Please review your cart and try again.",
44
+ };
45
+
46
+ /** The sentence for a finding; unknown findings, including a bare code, get the generic sentence. */
47
+ export function refusalSentence(finding: string): string {
48
+ if (Object.hasOwn(SENTENCES, finding)) return SENTENCES[finding]!;
49
+ if (finding.startsWith("verification-refused:")) return SENTENCES["verification-refused"]!;
50
+ if (finding.startsWith("evidence-")) return "We couldn't confirm the checks for your order right now. Please try again in a moment.";
51
+ return GENERIC_REFUSAL_SENTENCE;
52
+ }
@@ -23,6 +23,7 @@ import { DeclaredTenantConfigUnreadError, withDeclaredTenantConfig } from "@/con
23
23
  import { resolveStoreCurrency } from "@tot/public-runtime/declared-tenant-config";
24
24
  import { createContentProvider } from "@/lib/content/storyblok/provider";
25
25
  import { createToTClient } from "@/lib/catalog/tot/ToTClient";
26
+ import { refusalSentence } from "@/lib/commerce/refusalSentence";
26
27
  export const prerender = false;
27
28
  const HEX = /^[a-f0-9]{64}$/;
28
29
  /** The shopper's verification correlation handle, as the signed `verification` cart option carries it. */
@@ -30,7 +31,7 @@ const VERIFICATION_REF = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,199}$/;
30
31
  function json(body: unknown, status = 200): Response {
31
32
  return new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" } });
32
33
  }
33
- function deny(finding: string, status = 409, owner?: string): Response { return json({ ok: false, finding, ...(owner ? { owner } : {}) }, status); }
34
+ function deny(finding: string, status = 409, owner?: string): Response { return json({ ok: false, finding, message: refusalSentence(finding), ...(owner ? { owner } : {}) }, status); }
34
35
  /**
35
36
  * Which check refused, and on which cart line (its index in the presented snapshot). Logged on
36
37
  * the decision line only: closed check names and an index, never a SKU, price or cart value.
@@ -329,7 +330,7 @@ async function authorize(context: APIContext): Promise<Response> {
329
330
  trustedIssuers: issuers, expectedAudience: audience, activeKids, stockTracked, authorities });
330
331
  if (!decision.ok) {
331
332
  if (decision.finding.startsWith("verification-refused") && (seamView.flavors || seamView.lines)) {
332
- return json({ ok: false, finding: decision.finding,
333
+ return json({ ok: false, finding: decision.finding, message: refusalSentence(decision.finding),
333
334
  ...(decision.finding === "verification-refused:flavored_prohibited" && seamView.flavors ? { flavors: seamView.flavors } : {}),
334
335
  ...(seamView.lines ? { lines: seamView.lines } : {}) }, 409);
335
336
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "6.3.2",
3
+ "version": "6.3.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",