@tokenoftrust/storefront-runner 8.0.1 → 8.1.1

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.
Files changed (21) hide show
  1. package/apps/storefront/src/components/catalog/storefront/ProductCard.astro +15 -7
  2. package/apps/storefront/src/components/publication/storefront/islands/CatalogQueryView.tsx +6 -1
  3. package/apps/storefront/src/layouts/Layout.astro +39 -1
  4. package/apps/storefront/src/lib/compliance/shopper/statePickerClient.ts +622 -67
  5. package/apps/storefront/src/lib/compliance/shopper/staticEligibilityArtifact.ts +182 -0
  6. package/apps/storefront/src/lib/compliance/shopper/staticEligibilityPointerGate.ts +13 -0
  7. package/apps/storefront/src/middleware/renderChain.ts +44 -25
  8. package/apps/storefront/src/middleware/routeBranch.ts +1 -0
  9. package/apps/storefront/src/middleware/staticBundle.ts +3 -0
  10. package/apps/storefront/src/pages/eligibility.json.ts +23 -0
  11. package/package.json +1 -1
  12. package/packages/cli/src/publication-spaces.mjs +1 -1
  13. package/packages/public-runtime/package.json +1 -0
  14. package/packages/public-runtime/schemas/publication-space/v1/manifest.schema.json +1 -1
  15. package/packages/public-runtime/schemas/publication-space/v1/normalized-mount.schema.json +1 -1
  16. package/packages/public-runtime/src/compliance/evaluate.ts +13 -0
  17. package/packages/public-runtime/src/compliance/state-directory.ts +16 -2
  18. package/packages/public-runtime/src/compliance/static-eligibility.d.mts +92 -0
  19. package/packages/public-runtime/src/compliance/static-eligibility.mjs +394 -0
  20. package/packages/public-runtime/src/declared-tenant-config.mjs +1 -1
  21. package/packages/public-runtime/src/publication-space.ts +1 -0
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import type { CatalogProduct } from "@tot/public-runtime";
10
10
  import { deriveProductProfile } from "@tot/public-runtime";
11
- import { extractDirectoryStatesFromTags } from "@tot/public-runtime/compliance/state-directory";
11
+ import { extractDirectoryStatesFromTags, normalizeUsStateCode } from "@tot/public-runtime/compliance/state-directory";
12
12
  import { hidesPublicCatalogPrices, resolveShopperAccessPolicy } from "@tot/public-runtime/declared-tenant-config";
13
13
  import { discountPercent, truncate } from "@/lib/content/shared/format";
14
14
  import { isOnSale, isNew, isAvailable, fromPrice } from "@/lib/catalog/tot/query";
@@ -140,10 +140,14 @@ const quickview = {
140
140
  };
141
141
  const complianceProfile = deriveProductProfile(product);
142
142
  const directoryStates = extractDirectoryStatesFromTags(product.tags);
143
+ const allowedStateCodes = complianceProfile.allowedRegions === null
144
+ ? null
145
+ : complianceProfile.allowedRegions.map((code) => normalizeUsStateCode(code)).filter((code): code is string => code !== null);
146
+ // An allow-list that names no valid state (`[]`) ships nowhere. It is encoded explicitly: an empty
147
+ // `data-eligible-states` reads as "no allow-list", which is the opposite meaning.
148
+ const shipsNowhere = allowedStateCodes !== null && allowedStateCodes.length === 0;
143
149
  const eligibleStatesAttr =
144
- complianceProfile.allowedRegions && complianceProfile.allowedRegions.length > 0
145
- ? complianceProfile.allowedRegions.join(",")
146
- : undefined;
150
+ allowedStateCodes && allowedStateCodes.length > 0 ? allowedStateCodes.join(",") : undefined;
147
151
  const restrictedStatesAttr =
148
152
  complianceProfile.restrictedRegions.length > 0
149
153
  ? complianceProfile.restrictedRegions.join(",")
@@ -158,6 +162,7 @@ const directoryStatesAttr =
158
162
  data-product-card
159
163
  data-product-handle={product.handle}
160
164
  data-eligible-states={eligibleStatesAttr}
165
+ data-ships-nowhere={shipsNowhere ? "true" : undefined}
161
166
  data-restricted-states={restrictedStatesAttr}
162
167
  data-directory-states={directoryStatesAttr}
163
168
  >
@@ -271,15 +276,18 @@ const directoryStatesAttr =
271
276
  data-product-title={product.title}
272
277
  data-variant-id={cardCart.variantId}
273
278
  data-variant-sku={cardCart.sku}
279
+ data-eligibility-blocked={shipsNowhere ? "ships-nowhere" : undefined}
274
280
  class="relative z-10 mt-3"
275
281
  >
276
282
  {cardCart.hidden.map((field) => (
277
- <input type="hidden" name={field.name} value={field.value} />
283
+ <input type="hidden" name={field.name} value={field.value} disabled={shipsNowhere} />
278
284
  ))}
279
- <input type="hidden" name={cardCart.quantityName} value="1" />
285
+ <input type="hidden" name={cardCart.quantityName} value="1" disabled={shipsNowhere} />
280
286
  <button
281
287
  type="submit"
282
- class="w-full rounded-full bg-[var(--color-primary)] px-4 py-3 font-display text-sm font-medium text-[var(--color-primary-contrast)]"
288
+ disabled={shipsNowhere}
289
+ aria-disabled={shipsNowhere ? "true" : undefined}
290
+ class="w-full rounded-full bg-[var(--color-primary)] px-4 py-3 font-display text-sm font-medium text-[var(--color-primary-contrast)] disabled:cursor-not-allowed disabled:opacity-50"
283
291
  >
284
292
  Add to cart
285
293
  </button>
@@ -24,6 +24,7 @@ import {
24
24
  togglePriceBucket,
25
25
  } from "@/lib/publication/shared/url";
26
26
  import { formatPrice } from "@/lib/content/shared/format";
27
+ import { reapplyStaticEligibility } from "@/lib/compliance/shopper/statePickerClient";
27
28
  import { clientBasePath, withClientBase } from "@/lib/publication/shared/basePath";
28
29
 
29
30
  type Props =
@@ -96,6 +97,8 @@ export default function CatalogQueryView(props: Props) {
96
97
  if (!view || view.kind === "error") return;
97
98
  const region = renderedRegion();
98
99
  if (region) region.style.display = "none";
100
+ // The replaced results are enforced against the same artifact as the rendered ones.
101
+ reapplyStaticEligibility();
99
102
  if (view.kind === "search") {
100
103
  const heading = document.querySelector<HTMLElement>("[data-search-heading]");
101
104
  if (heading) heading.textContent = view.q ? `Results for “${view.q}”` : "What are you after?";
@@ -142,7 +145,9 @@ function Grid(props: {
142
145
  {props.products.map((p) => {
143
146
  const img = p.image;
144
147
  return (
145
- <li class="group relative">
148
+ // A result is a product card to the static eligibility enforcement: it is evaluated
149
+ // against the release's artifact by handle, and a handle the artifact does not carry is hidden.
150
+ <li class="group relative" data-product-card data-product-handle={p.handle}>
146
151
  <div class="relative aspect-[4/5] overflow-hidden rounded-md bg-[var(--color-border)] ring-1 ring-[var(--color-border)]">
147
152
  {img?.url && (
148
153
  <img
@@ -27,6 +27,9 @@ import IsolatedAgeGate from "@/components/compliance/storefront/islands/Isolated
27
27
  import CheckoutComplianceGate from "@/components/compliance/storefront/islands/CheckoutComplianceGate.tsx";
28
28
  import { isLocalSampleCheckout } from "@/config/declaredTenantConfig";
29
29
  import { isRegulatedTenant } from "@/lib/compliance/enforcement";
30
+ import { staticEligibilityRulesetVersion } from "@/lib/compliance/shopper/staticEligibilityArtifact";
31
+ import { STATIC_ELIGIBILITY_ROUTE, staticEligibilityPointerTag } from "@tot/public-runtime/compliance/static-eligibility";
32
+ import { staticEligibilityPointerAllowed } from "@/lib/compliance/shopper/staticEligibilityPointerGate";
30
33
  import AuthBadge from "@/components/access/storefront/auth/AuthBadge.astro";
31
34
  import { referenceTheme } from "@/themes/reference";
32
35
  import { mergeTheme } from "@/themes/schema";
@@ -253,6 +256,23 @@ const sections = complianceSections({
253
256
  });
254
257
  const cartHref = managedCartHref(publicCommerce);
255
258
 
259
+ // The static eligibility pointer: every page of a tenant with an eligibility surface (a declared
260
+ // rule profile or declared state eligibility) names the one artifact the browser filters and gates
261
+ // add-to-cart on. It is independent of the chrome (a shared-chrome page has no state picker but is
262
+ // gated all the same). Publication rewrites it to the content-addressed address and binds the
263
+ // release's digest and provenance (scripts/publish/lib/materialize.mjs). A closed store serves the
264
+ // artifact only to an admitted shopper (`closedCatalogPath` "admit"), so its public "allow" routes
265
+ // carry no pointer, status shell or boot: an unadmitted visitor there would be redirected to sign-in
266
+ // and read as an unavailable artifact.
267
+ const eligibilityRulesetVersion = staticEligibilityRulesetVersion(tenant);
268
+ const eligibilityPointer = eligibilityRulesetVersion && staticEligibilityPointerAllowed(shopperPolicy.mode, path)
269
+ ? staticEligibilityPointerTag({
270
+ url: withBase(basePath, STATIC_ELIGIBILITY_ROUTE),
271
+ tenant: tenant.tenant_id,
272
+ rulesetVersion: eligibilityRulesetVersion,
273
+ })
274
+ : null;
275
+
256
276
  // Site-chrome data resolution (chrome/* is the canonical, prop-driven
257
277
  // component set; this Layout is the ONE place that resolves session/feature/
258
278
  // theme state into their props. Skipped entirely when sharedChrome (a raw
@@ -353,6 +373,8 @@ const footerWidgets = await renderWidgetSlot(
353
373
 
354
374
  <link rel="icon" type="image/svg+xml" href={theme.brand.favicon} />
355
375
 
376
+ {eligibilityPointer && <Fragment set:html={eligibilityPointer} />}
377
+
356
378
  {/* Per-tenant theme tokens injected at the edge (brief §7). The id is the
357
379
  dev-loop hot-patch target: tenant-hot-reload.mjs recomputes this same
358
380
  `:root{...}` block on a theme.json save and the script below swaps its
@@ -445,13 +467,22 @@ const footerWidgets = await renderWidgetSlot(
445
467
  </>
446
468
  )}
447
469
 
448
- {compliance?.stateEligibility && (
470
+ {eligibilityPointer && (
449
471
  <div class="container-prose space-y-2 pt-2">
472
+ {/* STATIC guard shell: server-rendered, never mutated by the client, so the tamper
473
+ sentinel can baseline it (`data-compliance="state-eligibility"` is a protected
474
+ shipping-jurisdiction surface). The notices below are CLIENT-MUTATED live regions and
475
+ deliberately carry no `data-compliance`: stamping them would make every valid
476
+ shopper notice read as tampering and be reverted. */}
477
+ <p class="sr-only" data-compliance="state-eligibility">
478
+ Product availability depends on your ship-to state. Final eligibility is confirmed at checkout.
479
+ </p>
450
480
  <p
451
481
  hidden
452
482
  role="status"
453
483
  aria-live="polite"
454
484
  data-state-filter-status
485
+ data-state-live
455
486
  class="rounded-md border border-border bg-surface px-3 py-2 text-xs text-text"
456
487
  />
457
488
  <p
@@ -459,10 +490,17 @@ const footerWidgets = await renderWidgetSlot(
459
490
  role="alert"
460
491
  aria-live="assertive"
461
492
  data-state-cart-notice
493
+ data-state-live
462
494
  class="rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs font-medium text-text"
463
495
  />
464
496
  </div>
465
497
  )}
498
+ {eligibilityPointer && (
499
+ <script>
500
+ import { bootStaticEligibilityFromDom } from "@/lib/compliance/shopper/statePickerClient";
501
+ void bootStaticEligibilityFromDom();
502
+ </script>
503
+ )}
466
504
 
467
505
  <main id="main">
468
506
  {homeSlotHtml !== null ? <Fragment set:html={homeSlotHtml} /> : <slot />}