@tokenoftrust/storefront-runner 6.7.0 → 6.7.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.
@@ -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";
@@ -47,14 +47,15 @@ export const SHARED_STORE_POLICY_REVISION = "shared-test-store-v1";
47
47
  export const SHARED_STORE_VERIFICATION_SOURCE = "tot-verification-provider";
48
48
 
49
49
  /**
50
- * What the shared test store requires of a tenant, from the store's saved checkout requirements.
51
- * Nothing blocks by default, regulated tenants included. Each switch the store turns on in /admin
52
- * only adds a requirement. Requirements that cannot be read (`null`) require everything, so a
50
+ * What the shared test store requires of a tenant. A regulated tenant (`isRegulated`) always
51
+ * requires verification, tax and enforced rules, whatever the store saved. For any other tenant
52
+ * nothing blocks by default, and each switch the store turns on in /admin only adds a
53
+ * requirement. Requirements that cannot be read (`null`) require everything, so a
53
54
  * corrupt or unreachable setting is never weaker than what the store saved. Nothing produces risk
54
55
  * evidence, so risk is never required here.
55
56
  */
56
- export function testStoreEvidencePolicy(requirements: CheckoutRequirements | null): SharedStoreEvidencePolicy {
57
- const saved = requirements ?? { verification: true, tax: true, rules: true };
57
+ export function testStoreEvidencePolicy(requirements: CheckoutRequirements | null, regulated = false): SharedStoreEvidencePolicy {
58
+ const saved = regulated || !requirements ? { verification: true, tax: true, rules: true } : requirements;
58
59
  return {
59
60
  verification: saved.verification ? "required" : "not-required",
60
61
  tax: saved.tax ? "required" : "not-required",
@@ -68,12 +69,12 @@ export function testStoreEvidencePolicy(requirements: CheckoutRequirements | nul
68
69
  * other checkout (its own store, or any tier but test), which keeps the full fail-closed contract.
69
70
  */
70
71
  export async function sharedStorePolicy(
71
- tenant: Pick<TenantConfig, "tenant_id">,
72
+ tenant: Pick<TenantConfig, "tenant_id" | "compliance">,
72
73
  commerce: { storeSubDomain?: string } | null | undefined,
73
74
  env: CustomizationEnv,
74
75
  ): Promise<SharedStoreEvidencePolicy | null> {
75
76
  if (!(await usesSharedTestStore(commerce))) return null;
76
- return testStoreEvidencePolicy(await readCheckoutRequirements(tenant.tenant_id, env));
77
+ return testStoreEvidencePolicy(await readCheckoutRequirements(tenant.tenant_id, env), isRegulated({ compliance: tenant.compliance }));
77
78
  }
78
79
 
79
80
  /** 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: `Tax evidence is ${tax.state}.`,
498
- tone: ["fresh", "not-required"].includes(tax.state) ? "blue" : "amber",
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, 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";
@@ -295,7 +295,7 @@ async function authorize(context: APIContext): Promise<Response> {
295
295
  if (existing && !admissionMatches(existing, snapshot)) return deny("provider-cart-changed");
296
296
  const requirements = await readCheckoutRequirements(tenant.tenant_id, contentEnv);
297
297
  if (!requirements) return deny("checkout-requirements-unreadable", 503);
298
- const policy = testStoreEvidencePolicy(requirements);
298
+ const policy = testStoreEvidencePolicy(requirements, isRegulated({ compliance: tenant.compliance }));
299
299
  // A declared mirror provider is admitted only against a fresh positive balance. An undeclared
300
300
  // tenant with no movements records stock as `not-required`. A non-positive balance already refused.
301
301
  const stockTracked = tenant.inventory?.provider === "mirror";
@@ -321,6 +321,13 @@ async function authorize(context: APIContext): Promise<Response> {
321
321
  const presented: FinalCartBinding = { tenantId: snapshot.tenantId, stage: snapshot.stage, currency: snapshot.currency, lines: snapshot.lines,
322
322
  destinationDigest: snapshot.destinationDigest, verificationExpiresAt: expiresAt, taxExpiresAt: expiresAt };
323
323
  const seamView = await seam(authorityContext, snapshot, selected, policy);
324
+ if (policy.tax === "required") {
325
+ const computed = snapshot.totals.taxMinor > 0;
326
+ evidence.tax = computed ? "fresh" : "not-computed";
327
+ provenance.tax = computed
328
+ ? { requirement: "required", state: "satisfied", source: "provider-computed-tax", policyRevision: SHARED_STORE_POLICY_REVISION, expiresAt }
329
+ : { requirement: "required", state: "not-computed", source: "provider-computed-tax", policyRevision: SHARED_STORE_POLICY_REVISION, expiresAt };
330
+ }
324
331
  if (policy.verification === "required" && seamView.verified) {
325
332
  evidence.verification = "fresh";
326
333
  provenance.verification = { requirement: "required", state: "satisfied", source: SHARED_STORE_VERIFICATION_SOURCE, policyRevision: SHARED_STORE_POLICY_REVISION, expiresAt };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/storefront-runner",
3
- "version": "6.7.0",
3
+ "version": "6.7.1",
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 {