@tokenoftrust/storefront-runner 6.7.0 → 6.7.2
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/lib/checkout/commerce/checkoutRequirements.ts +11 -0
- package/apps/storefront/src/lib/checkout/commerce/commerceAdmission.ts +1 -1
- package/apps/storefront/src/lib/checkout/commerce/finalCartAuthorization.ts +1 -1
- package/apps/storefront/src/lib/checkout/commerce/sharedStoreAdmission.ts +13 -8
- package/apps/storefront/src/lib/fulfillment/readiness.ts +1 -0
- package/apps/storefront/src/lib/orders/admin/services/orders.ts +6 -4
- package/apps/storefront/src/lib/orders/data/orderMapper.ts +1 -1
- package/apps/storefront/src/pages/api/commerce/final-cart-authorization.ts +32 -5
- package/package.json +1 -1
- package/packages/public-runtime/src/checkout-orders.ts +3 -3
|
@@ -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
|
+
}
|
|
@@ -106,7 +106,7 @@ function parseCommerceAdmission(
|
|
|
106
106
|
!proof.policyRevision ||
|
|
107
107
|
!Number.isFinite(Date.parse(proof.expiresAt)) ||
|
|
108
108
|
!["required", "not-required"].includes(proof.requirement) ||
|
|
109
|
-
!["satisfied", "not-required"].includes(proof.state)
|
|
109
|
+
!["satisfied", "not-required", "not-computed"].includes(proof.state)
|
|
110
110
|
)
|
|
111
111
|
return null;
|
|
112
112
|
}
|
|
@@ -110,7 +110,7 @@ function evidenceFinding(evidence: CommerceEvidence | null, stockTracked: boolea
|
|
|
110
110
|
if (!evidence) return "missing-evidence";
|
|
111
111
|
for (const field of EVIDENCE_FIELDS) {
|
|
112
112
|
const state: EvidenceState | string = evidence[field];
|
|
113
|
-
if (state === "fresh" || (state === "not-required" && (field !== "stock" || !stockTracked))) continue;
|
|
113
|
+
if (state === "fresh" || (field === "tax" && state === "not-computed") || (state === "not-required" && (field !== "stock" || !stockTracked))) continue;
|
|
114
114
|
if (state === "UNKNOWN") return `evidence-${field}-unknown`;
|
|
115
115
|
if (state === "stale" || state === "unreadable" || state === "absent") return `evidence-${field}-${state}`;
|
|
116
116
|
return `evidence-${field}-unreadable`;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* secret is therefore never issued to a partner. Production never declares the test tier, so it
|
|
8
8
|
* admits no one here.
|
|
9
9
|
*/
|
|
10
|
-
import { commerceTenantId, SHARED_DEMO_CHECKOUT, type CustomizationEnv, type TenantConfig } from "@tot/public-runtime";
|
|
10
|
+
import { commerceTenantId, isRegulated, SHARED_DEMO_CHECKOUT, type CustomizationEnv, type TenantConfig } from "@tot/public-runtime";
|
|
11
11
|
import { resolveAdminTargetTenant } from "@/config/adminTargetTenant";
|
|
12
12
|
import { resolveTenantCommerce } from "@/lib/checkout/shared/checkoutCommerce";
|
|
13
13
|
import { readEnv } from "@/lib/publication/shared/runtimeEnv";
|
|
@@ -45,16 +45,21 @@ 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
|
-
* What the shared test store requires of a tenant
|
|
51
|
-
*
|
|
52
|
-
*
|
|
54
|
+
* What the shared test store requires of a tenant. A regulated tenant (`isRegulated`) always
|
|
55
|
+
* requires verification, tax and enforced rules, whatever the store saved. For any other tenant
|
|
56
|
+
* nothing blocks by default, and each switch the store turns on in /admin only adds a
|
|
57
|
+
* requirement. Requirements that cannot be read (`null`) require everything, so a
|
|
53
58
|
* corrupt or unreachable setting is never weaker than what the store saved. Nothing produces risk
|
|
54
59
|
* evidence, so risk is never required here.
|
|
55
60
|
*/
|
|
56
|
-
export function testStoreEvidencePolicy(requirements: CheckoutRequirements | null): SharedStoreEvidencePolicy {
|
|
57
|
-
const saved = requirements
|
|
61
|
+
export function testStoreEvidencePolicy(requirements: CheckoutRequirements | null, regulated = false): SharedStoreEvidencePolicy {
|
|
62
|
+
const saved = regulated || !requirements ? { verification: true, tax: true, rules: true } : requirements;
|
|
58
63
|
return {
|
|
59
64
|
verification: saved.verification ? "required" : "not-required",
|
|
60
65
|
tax: saved.tax ? "required" : "not-required",
|
|
@@ -68,12 +73,12 @@ export function testStoreEvidencePolicy(requirements: CheckoutRequirements | nul
|
|
|
68
73
|
* other checkout (its own store, or any tier but test), which keeps the full fail-closed contract.
|
|
69
74
|
*/
|
|
70
75
|
export async function sharedStorePolicy(
|
|
71
|
-
tenant: Pick<TenantConfig, "tenant_id">,
|
|
76
|
+
tenant: Pick<TenantConfig, "tenant_id" | "compliance">,
|
|
72
77
|
commerce: { storeSubDomain?: string } | null | undefined,
|
|
73
78
|
env: CustomizationEnv,
|
|
74
79
|
): Promise<SharedStoreEvidencePolicy | null> {
|
|
75
80
|
if (!(await usesSharedTestStore(commerce))) return null;
|
|
76
|
-
return testStoreEvidencePolicy(await readCheckoutRequirements(tenant.tenant_id, env));
|
|
81
|
+
return testStoreEvidencePolicy(await readCheckoutRequirements(tenant.tenant_id, env), isRegulated({ compliance: tenant.compliance }));
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
/** True when this checkout resolves to the shared ToT test store on the test tier. */
|
|
@@ -77,6 +77,7 @@ export interface ReadinessInput {
|
|
|
77
77
|
const EVIDENCE_HOLDS: Record<EvidenceState, ReleaseHold | null> = {
|
|
78
78
|
fresh: null,
|
|
79
79
|
"not-required": null,
|
|
80
|
+
"not-computed": null,
|
|
80
81
|
UNKNOWN: "evidence-unknown",
|
|
81
82
|
stale: "evidence-stale",
|
|
82
83
|
unreadable: "evidence-unreadable",
|
|
@@ -59,7 +59,7 @@ import type { CheckoutOrderClient } from "../orderClient";
|
|
|
59
59
|
import { DEFAULT_TIMEZONE, resolveStoreTimeZone } from "@tot/public-runtime/declared-tenant-config";
|
|
60
60
|
import { DeclaredTenantConfigUnreadError, withDeclaredTenantConfig } from "@/config/declaredTenantConfig";
|
|
61
61
|
|
|
62
|
-
const EVIDENCE_STATES: readonly EvidenceState[] = ["fresh", "not-required", "UNKNOWN", "stale", "unreadable", "absent"];
|
|
62
|
+
const EVIDENCE_STATES: readonly EvidenceState[] = ["fresh", "not-required", "not-computed", "UNKNOWN", "stale", "unreadable", "absent"];
|
|
63
63
|
const REFUND_PAYMENTS: ReadonlySet<PaymentState> = new Set(["refunded", "refund_requested", "refund_unknown"]);
|
|
64
64
|
|
|
65
65
|
/** Read the selected store's declared clock from its actual Orders scope's channel. */
|
|
@@ -494,10 +494,12 @@ function deriveReadinessChecks(d: CheckoutOrderDetail, scope: CommerceScope): Or
|
|
|
494
494
|
key: "tax_and_fees",
|
|
495
495
|
label: "Tax and fees",
|
|
496
496
|
value: tax.state,
|
|
497
|
-
detail:
|
|
498
|
-
|
|
497
|
+
detail: tax.state === "not-computed"
|
|
498
|
+
? "Tax is required and the provider did not compute it for this order."
|
|
499
|
+
: `Tax evidence is ${tax.state}.`,
|
|
500
|
+
tone: tax.state === "fresh" || tax.state === "not-required" ? "blue" : "amber",
|
|
499
501
|
action: "View total",
|
|
500
|
-
blocking: !["fresh", "not-required"].includes(tax.state),
|
|
502
|
+
blocking: !["fresh", "not-required", "not-computed"].includes(tax.state),
|
|
501
503
|
},
|
|
502
504
|
{
|
|
503
505
|
key: "identity_and_age",
|
|
@@ -234,7 +234,7 @@ function readEvidence(value: unknown): CommerceEvidence {
|
|
|
234
234
|
if (!isRecord(value)) return { ...UNKNOWN_EVIDENCE };
|
|
235
235
|
const pick = (key: keyof CommerceEvidence): CommerceEvidence[keyof CommerceEvidence] => {
|
|
236
236
|
const found = value[key];
|
|
237
|
-
if (found === "fresh" || found === "not-required" || found === "UNKNOWN" || found === "stale" || found === "unreadable" || found === "absent") {
|
|
237
|
+
if (found === "fresh" || found === "not-required" || found === "not-computed" || found === "UNKNOWN" || found === "stale" || found === "unreadable" || found === "absent") {
|
|
238
238
|
return found;
|
|
239
239
|
}
|
|
240
240
|
return "UNKNOWN";
|
|
@@ -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, 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;
|
|
@@ -295,7 +315,7 @@ async function authorize(context: APIContext): Promise<Response> {
|
|
|
295
315
|
if (existing && !admissionMatches(existing, snapshot)) return deny("provider-cart-changed");
|
|
296
316
|
const requirements = await readCheckoutRequirements(tenant.tenant_id, contentEnv);
|
|
297
317
|
if (!requirements) return deny("checkout-requirements-unreadable", 503);
|
|
298
|
-
const policy = testStoreEvidencePolicy(requirements);
|
|
318
|
+
const policy = testStoreEvidencePolicy(requirements, isRegulated({ compliance: tenant.compliance }));
|
|
299
319
|
// A declared mirror provider is admitted only against a fresh positive balance. An undeclared
|
|
300
320
|
// tenant with no movements records stock as `not-required`. A non-positive balance already refused.
|
|
301
321
|
const stockTracked = tenant.inventory?.provider === "mirror";
|
|
@@ -321,9 +341,16 @@ async function authorize(context: APIContext): Promise<Response> {
|
|
|
321
341
|
const presented: FinalCartBinding = { tenantId: snapshot.tenantId, stage: snapshot.stage, currency: snapshot.currency, lines: snapshot.lines,
|
|
322
342
|
destinationDigest: snapshot.destinationDigest, verificationExpiresAt: expiresAt, taxExpiresAt: expiresAt };
|
|
323
343
|
const seamView = await seam(authorityContext, snapshot, selected, policy);
|
|
344
|
+
if (policy.tax === "required") {
|
|
345
|
+
const computed = snapshot.totals.taxMinor > 0;
|
|
346
|
+
evidence.tax = computed ? "fresh" : "not-computed";
|
|
347
|
+
provenance.tax = computed
|
|
348
|
+
? { requirement: "required", state: "satisfied", source: "provider-computed-tax", policyRevision: SHARED_STORE_POLICY_REVISION, expiresAt }
|
|
349
|
+
: { requirement: "required", state: "not-computed", source: "provider-computed-tax", policyRevision: SHARED_STORE_POLICY_REVISION, expiresAt };
|
|
350
|
+
}
|
|
324
351
|
if (policy.verification === "required" && seamView.verified) {
|
|
325
352
|
evidence.verification = "fresh";
|
|
326
|
-
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 };
|
|
327
354
|
}
|
|
328
355
|
const decision = await evaluateFinalCart({ now, routedTenantId: commerceTenantId(tenant), quoted: presented, presented, evidence,
|
|
329
356
|
seam: seamView, catalogAvailable: true, browserConfirmed: false, token,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenoftrust/storefront-runner",
|
|
3
|
-
"version": "6.7.
|
|
3
|
+
"version": "6.7.2",
|
|
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",
|
|
@@ -234,7 +234,7 @@ export const LABEL_STATES = [
|
|
|
234
234
|
] as const;
|
|
235
235
|
export type LabelState = (typeof LABEL_STATES)[number];
|
|
236
236
|
|
|
237
|
-
export const EVIDENCE_STATES = ["fresh", "not-required", "UNKNOWN", "stale", "unreadable", "absent"] as const;
|
|
237
|
+
export const EVIDENCE_STATES = ["fresh", "not-required", "not-computed", "UNKNOWN", "stale", "unreadable", "absent"] as const;
|
|
238
238
|
export type EvidenceState = (typeof EVIDENCE_STATES)[number];
|
|
239
239
|
|
|
240
240
|
export const PROVIDER_OUTCOMES = ["intent", "accepted", "unknown", "voided", "refunded"] as const;
|
|
@@ -440,7 +440,7 @@ export async function catalogPinDigestFinding(snapshot: {
|
|
|
440
440
|
/** Safe source references explaining each server-owned authority decision. */
|
|
441
441
|
export interface CommerceAuthoritySource {
|
|
442
442
|
requirement: "required" | "not-required";
|
|
443
|
-
state: "satisfied" | "not-required";
|
|
443
|
+
state: "satisfied" | "not-required" | "not-computed";
|
|
444
444
|
source: string;
|
|
445
445
|
policyRevision: string;
|
|
446
446
|
expiresAt: string;
|
|
@@ -484,7 +484,7 @@ export type CallerTokenRefusal =
|
|
|
484
484
|
|
|
485
485
|
export function evidencePermitsRelease(evidence: CommerceEvidence): boolean {
|
|
486
486
|
return (["verification", "tax", "risk", "stock"] as const)
|
|
487
|
-
.every(field => evidence[field] === "fresh" || evidence[field] === "not-required");
|
|
487
|
+
.every(field => evidence[field] === "fresh" || evidence[field] === "not-required" || (field === "tax" && evidence[field] === "not-computed"));
|
|
488
488
|
}
|
|
489
489
|
|
|
490
490
|
export function paymentIsCaptured(payment: PaymentState): boolean {
|