@tokenoftrust/storefront-runner 8.0.0 → 8.1.0
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/catalog/storefront/ProductCard.astro +15 -7
- package/apps/storefront/src/components/publication/storefront/islands/CatalogQueryView.tsx +6 -1
- package/apps/storefront/src/layouts/Layout.astro +39 -1
- package/apps/storefront/src/lib/checkout/commerce/finalCartAuthorization.ts +4 -4
- package/apps/storefront/src/lib/compliance/shopper/statePickerClient.ts +622 -67
- package/apps/storefront/src/lib/compliance/shopper/staticEligibilityArtifact.ts +182 -0
- package/apps/storefront/src/lib/compliance/shopper/staticEligibilityPointerGate.ts +13 -0
- package/apps/storefront/src/middleware/routeBranch.ts +1 -0
- package/apps/storefront/src/pages/api/commerce/final-cart-authorization.ts +45 -28
- package/apps/storefront/src/pages/api/compliance/preflight.ts +162 -66
- package/apps/storefront/src/pages/eligibility.json.ts +23 -0
- package/package.json +1 -1
- package/packages/cli/src/publication-spaces.mjs +1 -1
- package/packages/public-runtime/package.json +1 -0
- package/packages/public-runtime/schemas/publication-space/v1/manifest.schema.json +1 -1
- package/packages/public-runtime/schemas/publication-space/v1/normalized-mount.schema.json +1 -1
- package/packages/public-runtime/src/compliance/evaluate.ts +13 -0
- package/packages/public-runtime/src/compliance/state-directory.ts +16 -2
- package/packages/public-runtime/src/compliance/static-eligibility.d.mts +92 -0
- package/packages/public-runtime/src/compliance/static-eligibility.mjs +394 -0
- package/packages/public-runtime/src/declared-tenant-config.mjs +1 -1
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
{
|
|
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 />}
|
|
@@ -149,7 +149,7 @@ function evidenceFinding(evidence: CommerceEvidence | null, stockTracked: boolea
|
|
|
149
149
|
return null;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
const RULE_BLOCK_CODES: ReadonlySet<string> = new Set([
|
|
152
|
+
export const RULE_BLOCK_CODES: ReadonlySet<string> = new Set([
|
|
153
153
|
"invalid_ruleset",
|
|
154
154
|
"postal_code_required",
|
|
155
155
|
"flavored_prohibited",
|
|
@@ -162,15 +162,15 @@ const RULE_BLOCK_CODES: ReadonlySet<string> = new Set([
|
|
|
162
162
|
"purchase_limit_exceeded",
|
|
163
163
|
]);
|
|
164
164
|
|
|
165
|
-
function seamRuleFinding(seam: SeamView | null): { finding: string } | null {
|
|
166
|
-
if (!seam || seam.status !== "blocked") return null;
|
|
165
|
+
export function seamRuleFinding(seam: SeamView | null): { finding: string } | null {
|
|
166
|
+
if (!seam || (seam.status !== "blocked" && seam.failedClosed !== true)) return null;
|
|
167
167
|
const code = (seam.codes ?? []).find((c) => RULE_BLOCK_CODES.has(c));
|
|
168
168
|
return code ? { finding: `verification-refused:${code}` } : null;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
export function seamFinding(seam: SeamView | null): { finding: string; owner?: string } | null {
|
|
172
172
|
if (!seam || seam.status === "absent") return { finding: "verification-seam-absent" };
|
|
173
|
-
if (seam.status === "clear") return null;
|
|
173
|
+
if (seam.status === "clear" && seam.failedClosed !== true) return null;
|
|
174
174
|
const codes = (seam.codes ?? []).filter((code) => /^[a-z0-9_-]+$/.test(code));
|
|
175
175
|
if (seam.failedClosed && codes.some((code) => code === "verification_unconfigured" || code === "ruleset_unavailable")) {
|
|
176
176
|
return { finding: "verification-provider-unconfigured", owner: VERIFICATION_PROVIDER_OWNER };
|