@tokenoftrust/storefront-runner 6.7.1 → 6.8.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/layouts/Layout.astro +2 -2
- package/apps/storefront/src/lib/checkout/commerce/checkoutRequirements.ts +11 -0
- package/apps/storefront/src/lib/checkout/commerce/sharedStoreAdmission.ts +4 -0
- package/apps/storefront/src/lib/compliance/complianceSections.ts +5 -4
- package/apps/storefront/src/lib/compliance/enforcement.ts +18 -5
- package/apps/storefront/src/lib/content/shared/rawChrome.ts +2 -7
- package/apps/storefront/src/lib/content/shared/rawMarketingHtml.ts +18 -0
- package/apps/storefront/src/pages/[...slug].astro +3 -1
- package/apps/storefront/src/pages/api/commerce/final-cart-authorization.ts +24 -4
- package/apps/storefront/src/pages/index.astro +3 -1
- package/package.json +1 -1
- package/packages/cli/src/declared-config.mjs +20 -1
- package/packages/public-runtime/src/compliance-obligations.ts +27 -3
- package/packages/public-runtime/src/declared-tenant-config.mjs +1 -0
- package/packages/public-runtime/src/raw-html-policy.ts +1 -1
- package/packages/public-runtime/src/tenant.ts +17 -4
|
@@ -239,7 +239,7 @@ if (sharedChrome && !brandIsH1) {
|
|
|
239
239
|
const compliance = tenant.compliance;
|
|
240
240
|
const sections = complianceSections({
|
|
241
241
|
compliance,
|
|
242
|
-
|
|
242
|
+
arrivalPopup: features.ageGate,
|
|
243
243
|
exciseTaxEnabled: capabilities.exciseTax.enabled,
|
|
244
244
|
catalog: features.catalog,
|
|
245
245
|
});
|
|
@@ -495,7 +495,7 @@ const footerWidgets = await renderWidgetSlot(
|
|
|
495
495
|
</div>
|
|
496
496
|
))}
|
|
497
497
|
|
|
498
|
-
{sections.includes("age-gate") &&
|
|
498
|
+
{sections.includes("age-gate") && compliance?.minAge && (
|
|
499
499
|
<IsolatedAgeGate
|
|
500
500
|
client:only="preact"
|
|
501
501
|
minAge={compliance.minAge}
|
|
@@ -89,3 +89,14 @@ export async function readCheckoutRequirements(tenantId: string, env: Customizat
|
|
|
89
89
|
return null;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* What the Checkout requirements panel shows. A regulated store's compliance profile enforces every
|
|
95
|
+
* requirement whatever it saved, so it gets a statement and no switches; the save route refuses it too.
|
|
96
|
+
*/
|
|
97
|
+
export type CheckoutRequirementsPanelState = "own-store" | "enforced" | "unreadable" | "switches";
|
|
98
|
+
export function checkoutRequirementsPanelState(input: { shared: boolean; regulated: boolean; saved: CheckoutRequirements | null }): CheckoutRequirementsPanelState {
|
|
99
|
+
if (!input.shared) return "own-store";
|
|
100
|
+
if (input.regulated) return "enforced";
|
|
101
|
+
return input.saved === null ? "unreadable" : "switches";
|
|
102
|
+
}
|
|
@@ -45,6 +45,10 @@ export const SHARED_STORE_POLICY_SOURCE = "shared-test-store-default";
|
|
|
45
45
|
export const SHARED_STORE_POLICY_REVISION = "shared-test-store-v1";
|
|
46
46
|
/** Provenance stamped on verification the live provider confirmed for a store that requires it. */
|
|
47
47
|
export const SHARED_STORE_VERIFICATION_SOURCE = "tot-verification-provider";
|
|
48
|
+
/** Provenance stamped on verification the sandbox profile simulated for an internal-test tenant. */
|
|
49
|
+
export const SHARED_STORE_SANDBOX_VERIFICATION_SOURCE = "tot-sandbox-verification";
|
|
50
|
+
/** The cart's signed `verification` ref that asks the sandbox profile to simulate a cleared verification. */
|
|
51
|
+
export const SANDBOX_CLEARED_REF = /^sandbox-cleared:[a-zA-Z0-9._-]{1,64}$/;
|
|
48
52
|
|
|
49
53
|
/**
|
|
50
54
|
* What the shared test store requires of a tenant. A regulated tenant (`isRegulated`) always
|
|
@@ -33,7 +33,8 @@ export type ComplianceSectionId = (typeof COMPLIANCE_SECTION_IDS)[number];
|
|
|
33
33
|
|
|
34
34
|
export interface ComplianceSectionInput {
|
|
35
35
|
compliance?: ComplianceConfig | null;
|
|
36
|
-
|
|
36
|
+
/** The store's arrival popup setting (`resolveTenantFeatures(tenant).ageGate`). */
|
|
37
|
+
arrivalPopup: boolean;
|
|
37
38
|
exciseTaxEnabled: boolean;
|
|
38
39
|
catalog: boolean;
|
|
39
40
|
}
|
|
@@ -45,7 +46,7 @@ export function complianceSections(input: ComplianceSectionInput): ComplianceSec
|
|
|
45
46
|
if (compliance?.nicotineWarning) sections.push("nicotine-warning");
|
|
46
47
|
if (compliance?.pactAct) sections.push("pact-act");
|
|
47
48
|
if (compliance?.shippingRestriction) sections.push("shipping-restriction");
|
|
48
|
-
if (input.
|
|
49
|
+
if (input.arrivalPopup && compliance?.minAge) sections.push("age-gate");
|
|
49
50
|
if (input.exciseTaxEnabled && input.catalog) sections.push("excise-tax");
|
|
50
51
|
return sections;
|
|
51
52
|
}
|
|
@@ -63,7 +64,7 @@ export const VAPE_NICOTINE_US_PRIMARY: ComplianceSectionInput = {
|
|
|
63
64
|
shippingRestriction:
|
|
64
65
|
"Adult signature (21+) required on delivery. Some destinations are restricted — verified at checkout.",
|
|
65
66
|
},
|
|
66
|
-
|
|
67
|
+
arrivalPopup: true,
|
|
67
68
|
exciseTaxEnabled: true,
|
|
68
69
|
catalog: true,
|
|
69
70
|
};
|
|
@@ -104,7 +105,7 @@ export function complianceChromeForTenant(
|
|
|
104
105
|
return rawComplianceChrome(
|
|
105
106
|
complianceSections({
|
|
106
107
|
compliance: tenant.compliance,
|
|
107
|
-
|
|
108
|
+
arrivalPopup: features.ageGate,
|
|
108
109
|
exciseTaxEnabled: capabilities.exciseTax.enabled,
|
|
109
110
|
catalog: features.catalog,
|
|
110
111
|
}),
|
|
@@ -17,7 +17,12 @@ import type {
|
|
|
17
17
|
ComplianceRuleset,
|
|
18
18
|
EnforcementEvidenceSignals,
|
|
19
19
|
} from "@tot/public-runtime";
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
ageVerificationRequired,
|
|
22
|
+
arrivalPopupEnabled,
|
|
23
|
+
enforcementSignals,
|
|
24
|
+
isRegulated,
|
|
25
|
+
} from "@tot/public-runtime";
|
|
21
26
|
import { readEnv } from "@/lib/publication/shared/env";
|
|
22
27
|
import { COMPLIANCE_RULE_PROFILES } from "@/config/compliance/rulesets";
|
|
23
28
|
|
|
@@ -91,6 +96,9 @@ const PACT_REPORTING_CAPTURE_WIRED = true;
|
|
|
91
96
|
* regulated tenant (the caller must then fail closed). Wires the live verification
|
|
92
97
|
* provider from env. An unregulated tenant returns `null` too — callers key on
|
|
93
98
|
* {@link isRegulatedTenant} to distinguish "no ruleset needed" from "fail closed".
|
|
99
|
+
* A store that declared `compliance.ageVerificationRequired: false` gets the profile's
|
|
100
|
+
* rules without checkout verification — unless it sells nicotine, where
|
|
101
|
+
* `ageVerificationRequired` keeps the profile's verification requirement.
|
|
94
102
|
*/
|
|
95
103
|
export async function resolveTenantRuleset(
|
|
96
104
|
tenant: Pick<TenantConfig, "tenant_id" | "compliance">,
|
|
@@ -100,15 +108,20 @@ export async function resolveTenantRuleset(
|
|
|
100
108
|
if (!buildRuleset) return null;
|
|
101
109
|
const base = buildRuleset(tenant.tenant_id);
|
|
102
110
|
const provider = (await readEnv("TOT_VERIFICATION_PROVIDER")) || undefined;
|
|
111
|
+
const required = base.verification.required && ageVerificationRequired(tenant);
|
|
103
112
|
return {
|
|
104
113
|
...base,
|
|
105
|
-
verification: { ...base.verification, provider },
|
|
114
|
+
verification: { ...base.verification, required, provider },
|
|
106
115
|
};
|
|
107
116
|
}
|
|
108
117
|
|
|
109
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* Build the enforcement→evidence signals for a tenant (for the promote gate). A store
|
|
120
|
+
* that turned its arrival popup off (`features.ageGate: false`) has no popup to bypass,
|
|
121
|
+
* so its absence is never reported against `ageGateRenderable`.
|
|
122
|
+
*/
|
|
110
123
|
export async function resolveEnforcementEvidenceSignals(
|
|
111
|
-
tenant: Pick<TenantConfig, "tenant_id" | "compliance"
|
|
124
|
+
tenant: Pick<TenantConfig, "tenant_id" | "compliance"> & Partial<Pick<TenantConfig, "features">>,
|
|
112
125
|
opts: { ageGateBypassedByRawHtml?: boolean } = {},
|
|
113
126
|
): Promise<EnforcementEvidenceSignals> {
|
|
114
127
|
const regulated = isRegulatedTenant(tenant);
|
|
@@ -116,6 +129,6 @@ export async function resolveEnforcementEvidenceSignals(
|
|
|
116
129
|
return enforcementSignals(ruleset, {
|
|
117
130
|
regulated,
|
|
118
131
|
reportingCaptureWired: PACT_REPORTING_CAPTURE_WIRED,
|
|
119
|
-
ageGateBypassedByRawHtml: !!opts.ageGateBypassedByRawHtml,
|
|
132
|
+
ageGateBypassedByRawHtml: arrivalPopupEnabled(tenant) && !!opts.ageGateBypassedByRawHtml,
|
|
120
133
|
});
|
|
121
134
|
}
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
CHROME_BODY_MARKER,
|
|
30
30
|
CHROME_HEAD_MARKER,
|
|
31
31
|
isHomePath,
|
|
32
|
+
stripRawChromeAgeGateConfig,
|
|
32
33
|
} from "./rawMarketingHtml.js";
|
|
33
34
|
import { isCurrentNavHref } from "../chrome/navCurrent.js";
|
|
34
35
|
import { ctaIdentityAttr } from "../chrome/ctaIdentity.js";
|
|
@@ -486,13 +487,7 @@ function renderAgeGate(g: ChromeAgeGate): string {
|
|
|
486
487
|
return `<script type="application/json" id="tot-age-gate-config">${json}</script>`;
|
|
487
488
|
}
|
|
488
489
|
|
|
489
|
-
|
|
490
|
-
export function stripRawChromeAgeGateConfig(html: string): string {
|
|
491
|
-
return html.replace(
|
|
492
|
-
/<script\b(?=[^>]*\bid=["']tot-age-gate-config["'])[^>]*>[\s\S]*?<\/script>\s*/gi,
|
|
493
|
-
"",
|
|
494
|
-
);
|
|
495
|
-
}
|
|
490
|
+
export { stripRawChromeAgeGateConfig };
|
|
496
491
|
|
|
497
492
|
/** Neutralize the reserved light-DOM marker before tenant-authored chrome is inserted. */
|
|
498
493
|
export function stripReservedComplianceMarkers(html: string): string {
|
|
@@ -80,6 +80,17 @@ export function demoteBrandH1(html: string): string {
|
|
|
80
80
|
);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Remove a raw chrome's age-gate payload (`<script id="tot-age-gate-config">`), the
|
|
85
|
+
* data the chrome's behaviour script builds the arrival popup from.
|
|
86
|
+
*/
|
|
87
|
+
export function stripRawChromeAgeGateConfig(html: string): string {
|
|
88
|
+
return html.replace(
|
|
89
|
+
/<script\b(?=[^>]*\bid=["']tot-age-gate-config["'])[^>]*>[\s\S]*?<\/script>\s*/gi,
|
|
90
|
+
"",
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
83
94
|
/**
|
|
84
95
|
* Splice a body-only fragment into a tenant chrome wrapper at CHROME_BODY_MARKER.
|
|
85
96
|
* When the fragment carries its own `<h1>`, the wrapper's brand h1 is unwrapped.
|
|
@@ -408,12 +419,19 @@ export function rawHtmlResponse(
|
|
|
408
419
|
*/
|
|
409
420
|
complianceTop?: string;
|
|
410
421
|
complianceBottom?: string;
|
|
422
|
+
/**
|
|
423
|
+
* The store's arrival popup setting (`arrivalPopupEnabled(tenant)`). `false`
|
|
424
|
+
* removes the chrome's age-gate payload, so a store that turned its arrival
|
|
425
|
+
* popup off serves none on this path either. Omitted keeps the document's own.
|
|
426
|
+
*/
|
|
427
|
+
arrivalPopup?: boolean;
|
|
411
428
|
},
|
|
412
429
|
): Response {
|
|
413
430
|
let composed =
|
|
414
431
|
isFullDocument(html) || !opts.chromeWrapper
|
|
415
432
|
? html
|
|
416
433
|
: wrapFragmentInChrome(html, opts.chromeWrapper);
|
|
434
|
+
if (opts.arrivalPopup === false) composed = stripRawChromeAgeGateConfig(composed);
|
|
417
435
|
// HEALTH: a raw surface bypasses governed chrome, so `validateChromeConfig`
|
|
418
436
|
// never saw it and `trackingAttributes()` never stamped it. If NOT ONE of its
|
|
419
437
|
// actionable elements carries an identity, no click on this page can ever be
|
|
@@ -14,6 +14,7 @@ import { breadcrumbLd } from "@/lib/content/shared/jsonld";
|
|
|
14
14
|
import { truncate } from "@/lib/content/shared/format";
|
|
15
15
|
import { faqFromHtml, faqFromSections } from "@/lib/content/seo/faqItems";
|
|
16
16
|
import { rawHtmlPolicy, rawHtmlResponse, rawPageCanonicalUrl } from "@/lib/content/shared/rawMarketingHtml";
|
|
17
|
+
import { arrivalPopupEnabled } from "@tot/public-runtime";
|
|
17
18
|
import { complianceSections, rawComplianceChrome } from "@/lib/compliance/complianceSections";
|
|
18
19
|
import { styleGuideAliasRewrite } from "@/lib/content/shared/styleGuidePaths";
|
|
19
20
|
import { getBlogSettings } from "@/lib/content/blog/provider.js";
|
|
@@ -87,7 +88,7 @@ if (!blogPostProps) {
|
|
|
87
88
|
};
|
|
88
89
|
const complianceChrome = rawComplianceChrome(complianceSections({
|
|
89
90
|
compliance: tenant.compliance,
|
|
90
|
-
|
|
91
|
+
arrivalPopup: features.ageGate,
|
|
91
92
|
exciseTaxEnabled: capabilities.exciseTax.enabled,
|
|
92
93
|
catalog: features.catalog,
|
|
93
94
|
}), notices);
|
|
@@ -101,6 +102,7 @@ if (!blogPostProps) {
|
|
|
101
102
|
canonicalUrl: rawPageCanonicalUrl(canonicalBase, slug),
|
|
102
103
|
complianceTop: complianceChrome.top || undefined,
|
|
103
104
|
complianceBottom: complianceChrome.bottom || undefined,
|
|
105
|
+
arrivalPopup: arrivalPopupEnabled(tenant),
|
|
104
106
|
});
|
|
105
107
|
}
|
|
106
108
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { APIContext } from "astro";
|
|
3
3
|
import { createLocalJWKSet, decodeProtectedHeader, jwtVerify, type JSONWebKeySet } from "jose";
|
|
4
4
|
import {
|
|
5
|
-
commerceTenantId, isRegulated, totalsMatch, shippingMinorFor, isContentVersionId, catalogPinDigestFinding, cartLineKey,
|
|
5
|
+
commerceTenantId, isRegulated, isInternalTestTenant, totalsMatch, shippingMinorFor, isContentVersionId, catalogPinDigestFinding, cartLineKey,
|
|
6
6
|
type CallerToken, type CatalogProduct, type CatalogVariant, type CommerceEvidence, type CommerceEvidenceProvenance,
|
|
7
7
|
type CommerceProviderCartSnapshot, type FinalCartBinding, type TenantConfig,
|
|
8
8
|
} from "@tot/public-runtime";
|
|
@@ -16,8 +16,9 @@ import { admissionMatches, readCommerceAdmission, admissionSnapshotStatement } f
|
|
|
16
16
|
import { evaluatePreflight } from "../compliance/preflight.js";
|
|
17
17
|
import {
|
|
18
18
|
admitSharedStoreTenant, testStoreEvidencePolicy, SHARED_STORE_POLICY_REVISION, SHARED_STORE_POLICY_SOURCE,
|
|
19
|
-
SHARED_STORE_VERIFICATION_SOURCE, type SharedStoreEvidencePolicy,
|
|
19
|
+
SHARED_STORE_VERIFICATION_SOURCE, SHARED_STORE_SANDBOX_VERIFICATION_SOURCE, SANDBOX_CLEARED_REF, type SharedStoreEvidencePolicy,
|
|
20
20
|
} from "@/lib/checkout/commerce/sharedStoreAdmission.js";
|
|
21
|
+
import { isSandboxVerificationProvider } from "@/lib/compliance/enforcement.js";
|
|
21
22
|
import { readCheckoutRequirements } from "@/lib/checkout/commerce/checkoutRequirements.js";
|
|
22
23
|
import { DeclaredTenantConfigUnreadError, withDeclaredTenantConfig } from "@/config/declaredTenantConfig";
|
|
23
24
|
import { resolveStoreCurrency } from "@tot/public-runtime/declared-tenant-config";
|
|
@@ -100,7 +101,25 @@ function keyedLines(wire: CommerceProviderCartSnapshot): CommerceProviderCartSna
|
|
|
100
101
|
* cart's verification ref goes to preflight, whose live provider re-reads its real status
|
|
101
102
|
* server-side; `verified` is true only when that read satisfied the requirement.
|
|
102
103
|
*/
|
|
103
|
-
async function seam(context: APIContext, snapshot: CommerceProviderCartSnapshot, selected: ReadonlyMap<string, CatalogProduct>, policy: SharedStoreEvidencePolicy): Promise<SeamView & { verified: boolean }> {
|
|
104
|
+
async function seam(context: APIContext, snapshot: CommerceProviderCartSnapshot, selected: ReadonlyMap<string, CatalogProduct>, policy: SharedStoreEvidencePolicy): Promise<SeamView & { verified: boolean; sandbox: boolean }> {
|
|
105
|
+
const sandbox = await sandboxVerificationApplies(context.locals.tenant, snapshot);
|
|
106
|
+
const view = await evaluateSeam(context, snapshot, selected, policy, sandbox);
|
|
107
|
+
return { ...view, sandbox: sandbox && view.verified };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The sandbox verification profile satisfies the final cart's verification only when ALL hold:
|
|
111
|
+
* the resolved provider is an explicit sandbox value, the checkout resolves to the shared test
|
|
112
|
+
* store on the test tier (already enforced by admission), the tenant is internal-test, and the cart
|
|
113
|
+
* carries the signed sandbox-cleared verification ref. Any other tenant, tier or provider keeps
|
|
114
|
+
* the real provider's outcome as the only evidence.
|
|
115
|
+
*/
|
|
116
|
+
async function sandboxVerificationApplies(tenant: TenantConfig, snapshot: CommerceProviderCartSnapshot): Promise<boolean> {
|
|
117
|
+
return isSandboxVerificationProvider((await readEnv("TOT_VERIFICATION_PROVIDER")) || undefined)
|
|
118
|
+
&& (await readEnv("COMMERCE_DEMO_CHECKOUT_TIER")) === "test"
|
|
119
|
+
&& isInternalTestTenant(tenant)
|
|
120
|
+
&& SANDBOX_CLEARED_REF.test(snapshot.verificationRef ?? "");
|
|
121
|
+
}
|
|
122
|
+
async function evaluateSeam(context: APIContext, snapshot: CommerceProviderCartSnapshot, selected: ReadonlyMap<string, CatalogProduct>, policy: SharedStoreEvidencePolicy, sandbox: boolean): Promise<SeamView & { verified: boolean }> {
|
|
104
123
|
if (policy.rules === "off" && policy.verification === "not-required") return { status: "clear", verified: false };
|
|
105
124
|
const products = [...selected.values()];
|
|
106
125
|
try {
|
|
@@ -114,6 +133,7 @@ async function seam(context: APIContext, snapshot: CommerceProviderCartSnapshot,
|
|
|
114
133
|
}),
|
|
115
134
|
destination: snapshot.destination,
|
|
116
135
|
...(policy.verification === "required" && snapshot.verificationRef ? { verificationRef: snapshot.verificationRef } : {}),
|
|
136
|
+
...(sandbox ? { ageAffirmed: true } : {}),
|
|
117
137
|
}, { verification: policy.verification, rules: policy.rules });
|
|
118
138
|
const verified = policy.verification === "required" && decision.requirements.ageVerification === "satisfied";
|
|
119
139
|
const blocks = decision.blocks;
|
|
@@ -330,7 +350,7 @@ async function authorize(context: APIContext): Promise<Response> {
|
|
|
330
350
|
}
|
|
331
351
|
if (policy.verification === "required" && seamView.verified) {
|
|
332
352
|
evidence.verification = "fresh";
|
|
333
|
-
provenance.verification = { requirement: "required", state: "satisfied", source: SHARED_STORE_VERIFICATION_SOURCE, policyRevision: SHARED_STORE_POLICY_REVISION, expiresAt };
|
|
353
|
+
provenance.verification = { requirement: "required", state: "satisfied", source: seamView.sandbox ? SHARED_STORE_SANDBOX_VERIFICATION_SOURCE : SHARED_STORE_VERIFICATION_SOURCE, policyRevision: SHARED_STORE_POLICY_REVISION, expiresAt };
|
|
334
354
|
}
|
|
335
355
|
const decision = await evaluateFinalCart({ now, routedTenantId: commerceTenantId(tenant), quoted: presented, presented, evidence,
|
|
336
356
|
seam: seamView, catalogAvailable: true, browserConfirmed: false, token,
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
} from "@/lib/content/storyblok/content-model";
|
|
35
35
|
import type { Tier } from "@/lib/membership/model";
|
|
36
36
|
import {
|
|
37
|
+
arrivalPopupEnabled,
|
|
37
38
|
normalizeProductSectionSource,
|
|
38
39
|
} from "@tot/public-runtime";
|
|
39
40
|
import { resolveSectionSource } from "@/lib/content/shared/sections";
|
|
@@ -82,7 +83,7 @@ if (rawHtml && rawPolicy.allowed) {
|
|
|
82
83
|
};
|
|
83
84
|
const complianceChrome = rawComplianceChrome(complianceSections({
|
|
84
85
|
compliance: tenant.compliance,
|
|
85
|
-
|
|
86
|
+
arrivalPopup: features.ageGate,
|
|
86
87
|
exciseTaxEnabled: capabilities.exciseTax.enabled,
|
|
87
88
|
catalog: features.catalog,
|
|
88
89
|
}), notices);
|
|
@@ -96,6 +97,7 @@ if (rawHtml && rawPolicy.allowed) {
|
|
|
96
97
|
canonicalUrl: new URL("/", canonicalBase + "/").toString(),
|
|
97
98
|
complianceTop: complianceChrome.top || undefined,
|
|
98
99
|
complianceBottom: complianceChrome.bottom || undefined,
|
|
100
|
+
arrivalPopup: arrivalPopupEnabled(tenant),
|
|
99
101
|
});
|
|
100
102
|
}
|
|
101
103
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.8.0",
|
|
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",
|
|
@@ -24,7 +24,7 @@ export const TOT_CONFIG_KEYS = [
|
|
|
24
24
|
// Keys other tooling has written that the platform does NOT read, with the key it does.
|
|
25
25
|
const RENAMED_CONFIG_KEYS = { appDomain: "scope", tenantId: "tenant" };
|
|
26
26
|
export const COMPLIANCE_KEYS = [
|
|
27
|
-
"ruleProfile", "minAge", "nicotineWarning", "shippingRestriction", "pactAct",
|
|
27
|
+
"ruleProfile", "minAge", "ageVerificationRequired", "nicotineWarning", "shippingRestriction", "pactAct",
|
|
28
28
|
"adultSignature", "prop65", "purchaseLimit", "stateEligibility", "exciseTax",
|
|
29
29
|
];
|
|
30
30
|
export const FEATURE_KEYS = [
|
|
@@ -352,6 +352,7 @@ function shippingProblemMessage(problems) {
|
|
|
352
352
|
export const COMPLIANCE_NOTICES = {
|
|
353
353
|
ruleProfile: "checkout compliance rules",
|
|
354
354
|
minAge: "age gate",
|
|
355
|
+
ageVerificationRequired: "age verification",
|
|
355
356
|
nicotineWarning: "FDA nicotine warning",
|
|
356
357
|
shippingRestriction: "shipping-restriction notice",
|
|
357
358
|
pactAct: "PACT Act notice",
|
|
@@ -395,6 +396,16 @@ export const COMPLIANCE_OBLIGATIONS = Object.freeze([
|
|
|
395
396
|
{ id: "jurisdiction", surface: "commerce", keys: ["stateEligibility", "shippingRestriction"] },
|
|
396
397
|
]);
|
|
397
398
|
|
|
399
|
+
/**
|
|
400
|
+
* Does the declared block require age/identity verification? Mirrors
|
|
401
|
+
* `ageVerificationRequired` in compliance-obligations.ts: required unless
|
|
402
|
+
* `ageVerificationRequired: false`, and always for a store that sells nicotine.
|
|
403
|
+
* @param {Record<string, any> | null | undefined} compliance
|
|
404
|
+
*/
|
|
405
|
+
export function declaresAgeVerificationRequired(compliance) {
|
|
406
|
+
return compliance?.ageVerificationRequired !== false || !!compliance?.nicotineWarning;
|
|
407
|
+
}
|
|
408
|
+
|
|
398
409
|
/**
|
|
399
410
|
* The obligations a declared compliance block switches on, as `resolveObligations` returns
|
|
400
411
|
* them (id + surface), in registry order.
|
|
@@ -404,6 +415,7 @@ export const COMPLIANCE_OBLIGATIONS = Object.freeze([
|
|
|
404
415
|
export function declaredObligations(compliance) {
|
|
405
416
|
return COMPLIANCE_OBLIGATIONS
|
|
406
417
|
.filter((o) => o.keys.some((key) => !!compliance?.[key]))
|
|
418
|
+
.filter((o) => o.id !== "age_gate" || declaresAgeVerificationRequired(compliance))
|
|
407
419
|
.map(({ id, surface }) => ({ id, surface }));
|
|
408
420
|
}
|
|
409
421
|
|
|
@@ -572,6 +584,13 @@ export function complianceFindings(config, file = ".tot/config.json") {
|
|
|
572
584
|
"`capabilities.exciseTax` cannot be disabled for a store with `compliance.nicotineWarning` or `compliance.exciseTax` — the hosted preview refuses this revision.",
|
|
573
585
|
"Remove `capabilities.exciseTax.enabled: false` from .tot/config.json."));
|
|
574
586
|
}
|
|
587
|
+
if (compliance?.ageVerificationRequired === false && compliance?.nicotineWarning) {
|
|
588
|
+
out.push(mk(WARN, "compliance-age-verification-policy", `${file} compliance`,
|
|
589
|
+
"`compliance.ageVerificationRequired: false` has no effect on a store that sells nicotine " +
|
|
590
|
+
"(`compliance.nicotineWarning`): platform policy keeps age/ID verification required at checkout.",
|
|
591
|
+
"Remove `compliance.ageVerificationRequired` from .tot/config.json, or turn only the arrival popup off " +
|
|
592
|
+
"with `features.ageGate: false`."));
|
|
593
|
+
}
|
|
575
594
|
if (isRegulatedObligationSet(obligations) && !compliance?.ruleProfile) {
|
|
576
595
|
out.push(mk(WARN, "compliance-rule-profile", `${file} compliance`,
|
|
577
596
|
`This store is regulated (${regulatedBy(compliance, obligations)}) but declares no ` +
|
|
@@ -34,7 +34,28 @@ export const COMPLIANCE_OBLIGATION_MODEL = "compliance-obligation-model@1" as co
|
|
|
34
34
|
export type ComplianceObligationModel = typeof COMPLIANCE_OBLIGATION_MODEL;
|
|
35
35
|
|
|
36
36
|
/** The only input to obligation resolution: the tenant's authoritative config. */
|
|
37
|
-
export type ObligationTenant = Pick<TenantConfig, "compliance" | "siteType"
|
|
37
|
+
export type ObligationTenant = Pick<TenantConfig, "compliance" | "siteType"> &
|
|
38
|
+
Partial<Pick<TenantConfig, "features">>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Does this store require age/identity verification? Required unless the store
|
|
42
|
+
* declares `compliance.ageVerificationRequired: false`, and always required for a
|
|
43
|
+
* store that sells nicotine (`compliance.nicotineWarning`): that is platform policy,
|
|
44
|
+
* not a store setting. Governs the `age_gate` duty and checkout verification.
|
|
45
|
+
*/
|
|
46
|
+
export function ageVerificationRequired(tenant: Pick<TenantConfig, "compliance">): boolean {
|
|
47
|
+
const c = tenant.compliance;
|
|
48
|
+
return c?.ageVerificationRequired !== false || !!c?.nicotineWarning;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Does this store show the arrival popup (the soft age-affirmation dialog on entry)?
|
|
53
|
+
* On unless the store declares `features.ageGate: false`. It renders only for a store
|
|
54
|
+
* with `compliance.minAge`; turning it off never weakens checkout verification.
|
|
55
|
+
*/
|
|
56
|
+
export function arrivalPopupEnabled(tenant: Partial<Pick<TenantConfig, "features">>): boolean {
|
|
57
|
+
return tenant.features?.ageGate !== false;
|
|
58
|
+
}
|
|
38
59
|
|
|
39
60
|
/**
|
|
40
61
|
* Platform-owned protected UI/preflight anchors. A third-party integration can
|
|
@@ -114,7 +135,7 @@ const BUILTIN_OBLIGATIONS: readonly ObligationSpec[] = [
|
|
|
114
135
|
label: "Age/identity verification gate",
|
|
115
136
|
surface: "regulated",
|
|
116
137
|
protectedSurfaces: ["age-gate", "cart-preflight"],
|
|
117
|
-
applies: (t) => !!t.compliance?.minAge,
|
|
138
|
+
applies: (t) => !!t.compliance?.minAge && ageVerificationRequired(t),
|
|
118
139
|
},
|
|
119
140
|
{
|
|
120
141
|
id: "excise",
|
|
@@ -217,13 +238,16 @@ export function isRegulated(tenant: ObligationTenant): boolean {
|
|
|
217
238
|
/**
|
|
218
239
|
* The union of platform-owned protected anchors the tenant's applied obligations
|
|
219
240
|
* render, in canonical order. Drives the conformance suite and the ext-policy-09
|
|
220
|
-
* sentinels — the set an integration can never disable (D-R7).
|
|
241
|
+
* sentinels — the set an integration can never disable (D-R7). A store that turned
|
|
242
|
+
* its arrival popup off (`arrivalPopupEnabled`) owes no `age-gate` anchor; its
|
|
243
|
+
* checkout verification (`cart-preflight`) stays protected.
|
|
221
244
|
*/
|
|
222
245
|
export function protectedSurfacesFor(tenant: ObligationTenant): ProtectedSurface[] {
|
|
223
246
|
const seen = new Set<ProtectedSurface>();
|
|
224
247
|
for (const o of resolveObligations(tenant)) {
|
|
225
248
|
for (const s of o.protectedSurfaces) seen.add(s);
|
|
226
249
|
}
|
|
250
|
+
if (!arrivalPopupEnabled(tenant)) seen.delete("age-gate");
|
|
227
251
|
return PROTECTED_SURFACES.filter((s) => seen.has(s));
|
|
228
252
|
}
|
|
229
253
|
|
|
@@ -65,7 +65,7 @@ export interface RawHtmlPolicyDecision {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
export function rawHtmlPolicy(
|
|
68
|
-
tenant: Pick<TenantConfig, "siteType" | "compliance"
|
|
68
|
+
tenant: Pick<TenantConfig, "siteType" | "compliance"> & Partial<Pick<TenantConfig, "features">>,
|
|
69
69
|
): RawHtmlPolicyDecision {
|
|
70
70
|
const regulated = isRegulated(tenant);
|
|
71
71
|
const required = protectedSurfacesFor(tenant);
|
|
@@ -315,6 +315,14 @@ export interface ComplianceConfig {
|
|
|
315
315
|
ruleProfile?: ComplianceRuleProfile;
|
|
316
316
|
/** Minimum age to enter. Drives the soft affirmation gate (e.g. 21). */
|
|
317
317
|
minAge?: number;
|
|
318
|
+
/**
|
|
319
|
+
* Whether this store requires age/identity verification at all. Undeclared means
|
|
320
|
+
* required. `false` waives the verification duty and checkout verification, except
|
|
321
|
+
* for a store that sells nicotine (`nicotineWarning`), where platform policy keeps
|
|
322
|
+
* it required (`ageVerificationRequired` in compliance-obligations.ts). The arrival
|
|
323
|
+
* popup is a separate declaration, `features.ageGate`.
|
|
324
|
+
*/
|
|
325
|
+
ageVerificationRequired?: boolean;
|
|
318
326
|
/**
|
|
319
327
|
* Render the FDA nicotine warning sitewide + reinforced on PDP. `true` renders the
|
|
320
328
|
* default preset; an object picks a validated preset and, optionally, a custom style
|
|
@@ -440,7 +448,11 @@ export interface TenantFeatures {
|
|
|
440
448
|
commerceSitemap: boolean;
|
|
441
449
|
/** Product-offer JSON-LD on product/collection pages. */
|
|
442
450
|
productJsonLd: boolean;
|
|
443
|
-
/**
|
|
451
|
+
/**
|
|
452
|
+
* The arrival popup: the soft age-affirmation dialog a visitor meets on entry (also
|
|
453
|
+
* needs `compliance.minAge`). Undeclared, it is on for every store with a `minAge`;
|
|
454
|
+
* `false` turns it off. Checkout verification is independent of it.
|
|
455
|
+
*/
|
|
444
456
|
ageGate: boolean;
|
|
445
457
|
}
|
|
446
458
|
|
|
@@ -487,8 +499,9 @@ export function tenantRendersPublicly(
|
|
|
487
499
|
/**
|
|
488
500
|
* Resolve a tenant's effective features: siteType defaults, with any explicit
|
|
489
501
|
* `features` overrides layered on top (undefined entries ignored, so a tenant
|
|
490
|
-
* can flip one flag without restating the rest). Unset `siteType` == "commerce"
|
|
491
|
-
*
|
|
502
|
+
* can flip one flag without restating the rest). Unset `siteType` == "commerce".
|
|
503
|
+
* A store with `compliance.minAge` that declares no `features.ageGate` gets the
|
|
504
|
+
* arrival popup; a declared `features.ageGate` always wins.
|
|
492
505
|
*/
|
|
493
506
|
export function resolveTenantFeatures(
|
|
494
507
|
tenant: Pick<TenantConfig, "siteType" | "features" | "compliance">,
|
|
@@ -499,7 +512,7 @@ export function resolveTenantFeatures(
|
|
|
499
512
|
if (v !== undefined) base[k as keyof TenantFeatures] = v;
|
|
500
513
|
}
|
|
501
514
|
}
|
|
502
|
-
if (tenant.compliance?.minAge) base.ageGate = true;
|
|
515
|
+
if (tenant.compliance?.minAge && tenant.features?.ageGate === undefined) base.ageGate = true;
|
|
503
516
|
return base;
|
|
504
517
|
}
|
|
505
518
|
|