@tokenoftrust/storefront-runner 7.7.3 → 7.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.
Files changed (65) hide show
  1. package/apps/storefront/dev-plugins/dev-auth-outbox.mjs +5 -3
  2. package/apps/storefront/src/components/catalog/storefront/ProductCard.astro +13 -9
  3. package/apps/storefront/src/components/catalog/storefront/islands/SearchTypeahead.tsx +2 -2
  4. package/apps/storefront/src/components/catalog/storefront/islands/VariantSelector.tsx +6 -4
  5. package/apps/storefront/src/components/catalog/storefront/plp/FacetSidebar.astro +4 -3
  6. package/apps/storefront/src/components/catalog/storefront/plp/SortSelect.astro +3 -2
  7. package/apps/storefront/src/components/compliance/storefront/islands/CheckoutComplianceGate.tsx +39 -45
  8. package/apps/storefront/src/components/publication/storefront/islands/CatalogQueryView.tsx +7 -4
  9. package/apps/storefront/src/layouts/Layout.astro +11 -7
  10. package/apps/storefront/src/lib/access/auth/agentSessionGate.ts +1 -0
  11. package/apps/storefront/src/lib/access/auth/loginGate.ts +14 -0
  12. package/apps/storefront/src/lib/access/shared/tenantRouting.ts +3 -1
  13. package/apps/storefront/src/lib/assets/captured-original-serve.ts +61 -1
  14. package/apps/storefront/src/lib/catalog/search/index.ts +3 -4
  15. package/apps/storefront/src/lib/catalog/shared/catalogIndex.ts +12 -7
  16. package/apps/storefront/src/lib/catalog/shared/catalogQueryView.ts +4 -2
  17. package/apps/storefront/src/lib/catalog/tot/query.ts +2 -1
  18. package/apps/storefront/src/lib/checkout/commerce/cartSession.ts +10 -11
  19. package/apps/storefront/src/lib/checkout/commerce/checkoutHandoffRoute.ts +81 -14
  20. package/apps/storefront/src/lib/compliance/browser/checkoutVerificationFlow.ts +35 -0
  21. package/apps/storefront/src/lib/content/seo/structuredData.ts +3 -2
  22. package/apps/storefront/src/lib/content/shared/jsonld.ts +3 -2
  23. package/apps/storefront/src/lib/customers/accounts/catalogAdmission.ts +75 -0
  24. package/apps/storefront/src/lib/customers/accounts/checkoutProof.ts +133 -0
  25. package/apps/storefront/src/lib/customers/accounts/orgKyb.ts +12 -0
  26. package/apps/storefront/src/lib/customers/accounts/pricing.ts +25 -0
  27. package/apps/storefront/src/lib/customers/accounts/purchaseAccess.ts +45 -0
  28. package/apps/storefront/src/lib/customers/accounts/scope.ts +55 -0
  29. package/apps/storefront/src/lib/customers/accounts/session.ts +173 -0
  30. package/apps/storefront/src/lib/customers/accounts/shopperPricingClient.ts +69 -0
  31. package/apps/storefront/src/lib/engagement/contact/submitToken.ts +2 -1
  32. package/apps/storefront/src/lib/inventory/allocations.ts +8 -5
  33. package/apps/storefront/src/lib/membership/eligibility.ts +2 -23
  34. package/apps/storefront/src/lib/publication/shared/cdnForward.ts +10 -3
  35. package/apps/storefront/src/lib/publication/shared/staticQuery.ts +10 -3
  36. package/apps/storefront/src/middleware/index.ts +80 -6
  37. package/apps/storefront/src/middleware/renderChain.ts +43 -26
  38. package/apps/storefront/src/middleware/routeBranch.ts +1 -0
  39. package/apps/storefront/src/middleware/staticBundle.ts +43 -13
  40. package/apps/storefront/src/pages/_sitemap.ts +14 -7
  41. package/apps/storefront/src/pages/api/cart-proposal/confirm.ts +2 -1
  42. package/apps/storefront/src/pages/api/cart-proposal/review.ts +5 -2
  43. package/apps/storefront/src/pages/api/commerce/cart-session.ts +3 -0
  44. package/apps/storefront/src/pages/api/commerce/checkout-sessions/[id].ts +2 -1
  45. package/apps/storefront/src/pages/api/commerce/checkout-sessions.ts +3 -1
  46. package/apps/storefront/src/pages/api/commerce/final-cart-authorization.ts +43 -10
  47. package/apps/storefront/src/pages/api/compliance/preflight.ts +34 -5
  48. package/apps/storefront/src/pages/cart.ts +3 -0
  49. package/apps/storefront/src/pages/catalog-index.json.ts +3 -2
  50. package/apps/storefront/src/pages/collections/[handle]/page/[n].astro +2 -1
  51. package/apps/storefront/src/pages/collections/[handle].astro +2 -1
  52. package/apps/storefront/src/pages/collections/_CollectionView.astro +8 -4
  53. package/apps/storefront/src/pages/index.astro +5 -3
  54. package/apps/storefront/src/pages/llms.txt.ts +2 -1
  55. package/apps/storefront/src/pages/products/[handle].astro +52 -15
  56. package/apps/storefront/src/pages/saved.astro +2 -1
  57. package/package.json +1 -1
  58. package/packages/cli/src/declared-config.mjs +46 -1
  59. package/packages/public-runtime/src/checkout-orders.ts +9 -1
  60. package/packages/public-runtime/src/checkout.ts +1 -1
  61. package/packages/public-runtime/src/declared-tenant-config.d.mts +11 -1
  62. package/packages/public-runtime/src/declared-tenant-config.mjs +111 -1
  63. package/packages/public-runtime/src/publication-space.ts +1 -0
  64. package/packages/public-runtime/src/static-bundle.ts +28 -3
  65. package/packages/public-runtime/src/tenant.ts +15 -0
@@ -19,7 +19,7 @@
19
19
 
20
20
  export const TOT_CONFIG_KEYS = [
21
21
  "$schema", "tenant", "scope", "mappings", "hostPlatform", "sample", "seed",
22
- "displayName", "siteType", "compliance", "capabilities", "features", "embeds", "seo", "currency", "timezone", "shipping", "catalog",
22
+ "displayName", "siteType", "compliance", "capabilities", "features", "embeds", "seo", "currency", "timezone", "shipping", "catalog", "accessPolicy", "verification",
23
23
  ];
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" };
@@ -32,6 +32,41 @@ export const FEATURE_KEYS = [
32
32
  ];
33
33
  export const SITE_TYPES = ["commerce", "marketing"];
34
34
 
35
+ const ACCESS_MODES = ["open", "checkout_gated", "closed_store"];
36
+ const REGISTRATION_MODES = ["self_serve", "approval_required"];
37
+ const ACCESS_POLICY_KEYS = ["mode", "hidePricesForGuests", "registrationMode", "b2bKybOrgVerification"];
38
+
39
+ /** @param {unknown} value */
40
+ export function accessPolicyDeclarationProblems(value) {
41
+ if (!isObject(value)) return ["accessPolicy must be an object"];
42
+ /** @type {Record<string, unknown>} */
43
+ const policy = value;
44
+ const problems = [];
45
+ if (Object.keys(policy).some(key => !ACCESS_POLICY_KEYS.includes(key))) problems.push("accessPolicy has an unknown field");
46
+ if (typeof policy.mode !== "string" || !ACCESS_MODES.includes(policy.mode)) problems.push("accessPolicy.mode is invalid");
47
+ if (policy.registrationMode !== undefined &&
48
+ (typeof policy.registrationMode !== "string" || !REGISTRATION_MODES.includes(policy.registrationMode))) {
49
+ problems.push("accessPolicy.registrationMode is invalid");
50
+ }
51
+ for (const field of ["hidePricesForGuests", "b2bKybOrgVerification"]) {
52
+ if (policy[field] !== undefined && typeof policy[field] !== "boolean") problems.push(`accessPolicy.${field} must be boolean`);
53
+ }
54
+ return problems;
55
+ }
56
+
57
+ /** @param {unknown} value */
58
+ export function verificationDeclarationProblems(value) {
59
+ if (!isObject(value)) return ["verification must be an object"];
60
+ /** @type {Record<string, unknown>} */
61
+ const policy = value;
62
+ const problems = [];
63
+ if (Object.keys(policy).some(key => key !== "allowCrossStoreReuse")) problems.push("verification has an unknown field");
64
+ if (policy.allowCrossStoreReuse !== undefined && typeof policy.allowCrossStoreReuse !== "boolean") {
65
+ problems.push("verification.allowCrossStoreReuse must be boolean");
66
+ }
67
+ return problems;
68
+ }
69
+
35
70
  /** The currency a store sells in when `.tot/config.json` declares none. */
36
71
  export const DEFAULT_CURRENCY = "USD";
37
72
 
@@ -844,6 +879,16 @@ export function validateDeclaredConfig(config, file = ".tot/config.json") {
844
879
  'declare e.g. `"shipping": { "tiers": [ { "rate": 5.99 }, { "atOrAbove": 100, "rate": 0, "label": "Free shipping" } ] }`, or remove `shipping` to charge none'));
845
880
  }
846
881
  }
882
+ if (config.accessPolicy !== undefined) {
883
+ for (const problem of accessPolicyDeclarationProblems(config.accessPolicy)) {
884
+ out.push(mk(ERROR, "config-access-policy", file, problem));
885
+ }
886
+ }
887
+ if (config.verification !== undefined) {
888
+ for (const problem of verificationDeclarationProblems(config.verification)) {
889
+ out.push(mk(ERROR, "config-shopper-verification", file, problem));
890
+ }
891
+ }
847
892
  if (config.catalog !== undefined) {
848
893
  const problems = catalogDeclarationProblems(config.catalog);
849
894
  if (problems.length > 0) {
@@ -437,6 +437,8 @@ export interface CommerceProviderCartSnapshot {
437
437
  * present. A preview authority reads that pin's catalog; a publication cart still reads live.
438
438
  */
439
439
  contentVersionId?: string;
440
+ /** Digest of the signed buyer-bound checkout context, present on scoped shopper carts. */
441
+ checkoutContextDigest?: string;
440
442
  /**
441
443
  * The shopper's verification correlation handle, from the signed `verification` cart option.
442
444
  * Present only when the cart carries one; outside the cart digest. A handle, not a claim: the
@@ -469,6 +471,7 @@ export function providerCartDigestMaterial(snapshot: {
469
471
  totals: MinorTotals;
470
472
  destinationDigest: string;
471
473
  contentVersionId?: string;
474
+ checkoutContextDigest?: string;
472
475
  }): {
473
476
  tenantId: string;
474
477
  stage: string;
@@ -477,6 +480,7 @@ export function providerCartDigestMaterial(snapshot: {
477
480
  totals: MinorTotals;
478
481
  destinationDigest: string;
479
482
  contentVersionId?: string;
483
+ checkoutContextDigest?: string;
480
484
  } {
481
485
  const lines = [...snapshot.lines].sort((a, b) => a.sku.localeCompare(b.sku) || a.unitMinor - b.unitMinor || a.quantity - b.quantity);
482
486
  const totals: MinorTotals = {
@@ -495,7 +499,10 @@ export function providerCartDigestMaterial(snapshot: {
495
499
  totals,
496
500
  destinationDigest: snapshot.destinationDigest,
497
501
  };
498
- return snapshot.contentVersionId === undefined ? material : { ...material, contentVersionId: snapshot.contentVersionId };
502
+ return { ...material,
503
+ ...(snapshot.contentVersionId === undefined ? {} : { contentVersionId: snapshot.contentVersionId }),
504
+ ...(snapshot.checkoutContextDigest === undefined ? {} : { checkoutContextDigest: snapshot.checkoutContextDigest }),
505
+ };
499
506
  }
500
507
 
501
508
  /** Finding when the provider-cart digest was not computed over the rendered content pin. */
@@ -516,6 +523,7 @@ export async function catalogPinDigestFinding(snapshot: {
516
523
  totals: MinorTotals;
517
524
  destinationDigest: string;
518
525
  contentVersionId?: string;
526
+ checkoutContextDigest?: string;
519
527
  }): Promise<typeof PROVIDER_CART_DIGEST_FINDING | null> {
520
528
  const expected = await sha256Hex(canonicalJson(providerCartDigestMaterial(snapshot)));
521
529
  return snapshot.providerCartDigest === expected ? null : PROVIDER_CART_DIGEST_FINDING;
@@ -334,7 +334,7 @@ export class CartSigningUnavailableError extends Error {
334
334
  * content pin the page rendered, and only then. `excise` carries the store's excise setting
335
335
  * (`withExcise`), `on` or `off`.
336
336
  */
337
- export const INTERNAL_CART_FIELDS = ["currency", "tenant", "verification", "shipping_policy", "return_url", "content_version", "excise"] as const;
337
+ export const INTERNAL_CART_FIELDS = ["currency", "tenant", "verification", "shipping_policy", "return_url", "content_version", "excise", "shopper_checkout"] as const;
338
338
 
339
339
  /** Signed cart option naming the content version the preview page rendered. */
340
340
  export const CONTENT_VERSION_CART_FIELD = "content_version";
@@ -1,7 +1,7 @@
1
1
  /** Types for the dependency-free declared-tenant-config module (declared-tenant-config.mjs). */
2
2
  import type { TenantConfig } from "./tenant.js";
3
3
 
4
- export type DeclaredTenantConfigField = "displayName" | "siteType" | "compliance" | "capabilities" | "features" | "embeds" | "seo" | "currency" | "timezone" | "shipping";
4
+ export type DeclaredTenantConfigField = "displayName" | "siteType" | "compliance" | "capabilities" | "features" | "embeds" | "seo" | "currency" | "timezone" | "shipping" | "catalog" | "accessPolicy" | "verification";
5
5
  export type DeclaredTenantConfig = Partial<Pick<TenantConfig, DeclaredTenantConfigField>>;
6
6
 
7
7
  export const DECLARED_TENANT_CONFIG_FIELDS: readonly DeclaredTenantConfigField[];
@@ -29,6 +29,16 @@ export const MAX_SHIPPING_AMOUNT: number;
29
29
  export const MAX_SHIPPING_TIERS: number;
30
30
  export const MAX_SHIPPING_LABEL_LENGTH: number;
31
31
  export function shippingDeclarationProblems(shipping: unknown): string[];
32
+ export function accessPolicyDeclarationProblems(policy: unknown): string[];
33
+ export function verificationDeclarationProblems(policy: unknown): string[];
34
+ export function resolveShopperAccessPolicy(tenant: Pick<TenantConfig, "accessPolicy">): Required<import("./tenant.js").ShopperAccessPolicy>;
35
+ export function hidesPublicCatalogPrices(tenant: Pick<TenantConfig, "accessPolicy">): boolean;
36
+ export interface ShopperDeliveryPolicy { mode: import("./tenant.js").ShopperAccessPolicy["mode"]; pricesHidden: boolean }
37
+ export function shopperDeliveryPolicy(tenant: Pick<TenantConfig, "accessPolicy">): ShopperDeliveryPolicy | null;
38
+ export function validShopperDeliveryPolicy(value: unknown): value is ShopperDeliveryPolicy;
39
+ export function closedCatalogPath(uri: string): "allow" | "admit" | "deny";
40
+ export function catalogAdmissionWindow(token: string, now: number): { issued: number; expires: number; mac: string } | null;
41
+ export function catalogAdmissionMessage(tenant: string, stage: string, host: string, issued: number, expires: number): string;
32
42
  export function declaredTenantConfig(config: unknown): DeclaredTenantConfig;
33
43
  export function isEmptyDeclaredTenantConfig(declared: DeclaredTenantConfig | null | undefined): boolean;
34
44
  /**
@@ -30,6 +30,8 @@ export const DECLARED_TENANT_CONFIG_FIELDS = Object.freeze([
30
30
  "timezone",
31
31
  "shipping",
32
32
  "catalog",
33
+ "accessPolicy",
34
+ "verification",
33
35
  ]);
34
36
 
35
37
  /**
@@ -408,7 +410,7 @@ export function declaredTenantConfig(config) {
408
410
  /** @type {Record<string, unknown>} */
409
411
  const out = {};
410
412
  if (!isPlainObject(config)) return out;
411
- const { displayName, siteType, compliance, capabilities, features, embeds, seo, currency, timezone, shipping, catalog } = /** @type {Record<string, unknown>} */ (config);
413
+ const { displayName, siteType, compliance, capabilities, features, embeds, seo, currency, timezone, shipping, catalog, accessPolicy, verification } = /** @type {Record<string, unknown>} */ (config);
412
414
  // The store's name as visitors read it: the `<title>` suffix, og:site_name,
413
415
  // Organization JSON-LD, breadcrumbs, the default blog heading, the copyright line.
414
416
  if (typeof displayName === "string" && displayName.trim()) out.displayName = displayName.trim();
@@ -433,9 +435,117 @@ export function declaredTenantConfig(config) {
433
435
  && isPlainObject(catalog) && typeof catalog.cdnSegment === "string") {
434
436
  out.catalog = { cdnSegment: catalog.cdnSegment };
435
437
  }
438
+ if (accessPolicy !== undefined) {
439
+ if (accessPolicyDeclarationProblems(accessPolicy).length) throw new Error("Invalid shopper access policy");
440
+ out.accessPolicy = accessPolicy;
441
+ }
442
+ if (verification !== undefined) {
443
+ if (verificationDeclarationProblems(verification).length) throw new Error("Invalid shopper verification policy");
444
+ out.verification = verification;
445
+ }
436
446
  return out;
437
447
  }
438
448
 
449
+ const ACCESS_MODES = ["open", "checkout_gated", "closed_store"];
450
+ const REGISTRATION_MODES = ["self_serve", "approval_required"];
451
+ const ACCESS_POLICY_KEYS = ["mode", "hidePricesForGuests", "registrationMode", "b2bKybOrgVerification"];
452
+
453
+ /** @param {unknown} value */
454
+ export function accessPolicyDeclarationProblems(value) {
455
+ if (!isPlainObject(value)) return ["accessPolicy must be an object"];
456
+ /** @type {Record<string, unknown>} */
457
+ const policy = value;
458
+ const problems = [];
459
+ if (Object.keys(policy).some(key => !ACCESS_POLICY_KEYS.includes(key))) problems.push("accessPolicy has an unknown field");
460
+ if (typeof policy.mode !== "string" || !ACCESS_MODES.includes(policy.mode)) problems.push("accessPolicy.mode is invalid");
461
+ if (policy.registrationMode !== undefined &&
462
+ (typeof policy.registrationMode !== "string" || !REGISTRATION_MODES.includes(policy.registrationMode))) {
463
+ problems.push("accessPolicy.registrationMode is invalid");
464
+ }
465
+ for (const field of ["hidePricesForGuests", "b2bKybOrgVerification"]) {
466
+ if (policy[field] !== undefined && typeof policy[field] !== "boolean") problems.push(`accessPolicy.${field} must be boolean`);
467
+ }
468
+ return problems;
469
+ }
470
+
471
+ /** @param {unknown} value */
472
+ export function verificationDeclarationProblems(value) {
473
+ if (!isPlainObject(value)) return ["verification must be an object"];
474
+ /** @type {Record<string, unknown>} */
475
+ const policy = value;
476
+ const problems = [];
477
+ if (Object.keys(policy).some(key => key !== "allowCrossStoreReuse")) problems.push("verification has an unknown field");
478
+ if (policy.allowCrossStoreReuse !== undefined && typeof policy.allowCrossStoreReuse !== "boolean") {
479
+ problems.push("verification.allowCrossStoreReuse must be boolean");
480
+ }
481
+ return problems;
482
+ }
483
+
484
+ /** @param {{accessPolicy?: import("./tenant.js").ShopperAccessPolicy}} tenant */
485
+ export function resolveShopperAccessPolicy(tenant) {
486
+ const policy = tenant.accessPolicy;
487
+ if (policy !== undefined && accessPolicyDeclarationProblems(policy).length) throw new Error("Invalid shopper access policy");
488
+ return {
489
+ mode: policy?.mode ?? /** @type {const} */ ("open"),
490
+ hidePricesForGuests: policy?.hidePricesForGuests ?? false,
491
+ registrationMode: policy?.registrationMode ?? /** @type {const} */ ("self_serve"),
492
+ b2bKybOrgVerification: policy?.b2bKybOrgVerification ?? false,
493
+ };
494
+ }
495
+
496
+ /** @param {{accessPolicy?: import("./tenant.js").ShopperAccessPolicy}} tenant */
497
+ export function hidesPublicCatalogPrices(tenant) {
498
+ const policy = resolveShopperAccessPolicy(tenant);
499
+ return policy.hidePricesForGuests || policy.mode === "closed_store";
500
+ }
501
+
502
+ /** @param {{accessPolicy?: import("./tenant.js").ShopperAccessPolicy}} tenant */
503
+ export function shopperDeliveryPolicy(tenant) {
504
+ const policy = resolveShopperAccessPolicy(tenant);
505
+ const pricesHidden = policy.hidePricesForGuests || policy.mode === "closed_store";
506
+ if (policy.mode === "open" && !pricesHidden && !policy.b2bKybOrgVerification) return null;
507
+ return { mode: policy.mode, pricesHidden };
508
+ }
509
+
510
+ /** @param {unknown} value */
511
+ export function validShopperDeliveryPolicy(value) {
512
+ if (!isPlainObject(value)) return false;
513
+ /** @type {Record<string, unknown>} */
514
+ const policy = value;
515
+ return typeof policy.mode === "string" && ACCESS_MODES.includes(policy.mode) &&
516
+ typeof policy.pricesHidden === "boolean" && (policy.mode !== "closed_store" || policy.pricesHidden);
517
+ }
518
+
519
+ /** @param {string} uri @returns {"allow" | "admit" | "deny"} */
520
+ export function closedCatalogPath(uri) {
521
+ let path;
522
+ try { path = decodeURIComponent(uri).toLowerCase().replace(/\/{2,}/g, "/"); }
523
+ catch { return "deny"; }
524
+ if (/[\\%\x00-\x1f]/.test(path) || /(?:^|\/)\.{1,2}(?:\/|$)/.test(path)) return "deny";
525
+ if (/^\/(?:versions|live|assets)(?:\/|$)/.test(path)) return "deny";
526
+ if (path === "/manifest.json" && uri !== path) return "deny";
527
+ if (/^\/(?:products|collections|search|saved|_availability|publication-discovery|tenants)(?:\/|$)/.test(path)) return "admit";
528
+ if (/^\/(?:catalog-index\.json|search-index\.json|llms\.txt|feed\.json|sitemap-(?:products|collections)-[0-9]+\.xml)(?:\/|$)/.test(path)) return "admit";
529
+ if (path.startsWith("/_a/") && !/\.(?:css|js|mjs|woff2?)$/.test(path)) return "admit";
530
+ return "allow";
531
+ }
532
+
533
+ /** @param {string} token @param {number} now */
534
+ export function catalogAdmissionWindow(token, now) {
535
+ const match = /^v1\.([0-9]{1,12})\.([0-9]{1,12})\.([a-f0-9]{64})$/.exec(token);
536
+ if (!match) return null;
537
+ const issued = Number(match[1]);
538
+ const expires = Number(match[2]);
539
+ return issued <= now && expires > now && expires - issued <= 120
540
+ ? { issued, expires, mac: match[3] }
541
+ : null;
542
+ }
543
+
544
+ /** @param {string} tenant @param {string} stage @param {string} host @param {number} issued @param {number} expires */
545
+ export function catalogAdmissionMessage(tenant, stage, host, issued, expires) {
546
+ return ["tot-shopper-catalog:v1", tenant, stage, host.toLowerCase(), issued, expires].join("\n");
547
+ }
548
+
439
549
  /** True when the declaration sets nothing. */
440
550
  export function isEmptyDeclaredTenantConfig(declared) {
441
551
  return !declared || Object.keys(declared).length === 0;
@@ -73,6 +73,7 @@ export const PUBLICATION_SPACE_RESERVED_MOUNTS = [
73
73
  "/_astro",
74
74
  "/_availability",
75
75
  "/_style-guide",
76
+ "/account",
76
77
  "/admin",
77
78
  "/api",
78
79
  "/apps",
@@ -40,6 +40,7 @@
40
40
  * back to the OLD `versions/<digest>/<rel>` lookup — fail-closed on a miss
41
41
  * either way, never a guess.
42
42
  */
43
+ import { closedCatalogPath, validShopperDeliveryPolicy } from "./declared-tenant-config.mjs";
43
44
  import { assetContentType } from "./tenant-assets.js";
44
45
  import { formatHtmlCacheControl } from "./html-cache-policy.js";
45
46
  import { CONTENT_NAMED_ASSET_PREFIXES } from "./content-named-asset-prefixes.mjs";
@@ -158,6 +159,7 @@ export interface StaticBundleFileEntry {
158
159
 
159
160
  /** The slice of `materialize-tenant.mjs`'s manifest this read path needs. */
160
161
  export interface StaticBundleManifest {
162
+ shopperDelivery?: import("./declared-tenant-config.mjs").ShopperDeliveryPolicy;
161
163
  treeDigest: string;
162
164
  pinnedNonce: string;
163
165
  csp: { headerName: string; value: string } | null;
@@ -224,6 +226,7 @@ function parseManifest(raw: string): StaticBundleManifest | null {
224
226
  typeof (m.csp as { value?: unknown }).value === "string"
225
227
  ? (m.csp as { headerName: string; value: string })
226
228
  : null;
229
+ if (m.shopperDelivery !== undefined && !validShopperDeliveryPolicy(m.shopperDelivery)) return null;
227
230
  let perRouteCsp: StaticBundleManifest["perRouteCsp"];
228
231
  if (m.perRouteCsp && typeof m.perRouteCsp === "object") {
229
232
  perRouteCsp = {};
@@ -265,7 +268,7 @@ function parseManifest(raw: string): StaticBundleManifest | null {
265
268
  }
266
269
  }
267
270
  const htmlCacheControl = typeof m.htmlCacheControl === "string" ? m.htmlCacheControl : undefined;
268
- return { treeDigest: m.treeDigest, pinnedNonce: m.pinnedNonce, csp, perRouteCsp, htmlCacheControl, files, redirects };
271
+ return { treeDigest: m.treeDigest, pinnedNonce: m.pinnedNonce, csp, perRouteCsp, htmlCacheControl, files, redirects, shopperDelivery: m.shopperDelivery };
269
272
  } catch {
270
273
  return null;
271
274
  }
@@ -298,6 +301,7 @@ export interface ServeStaticBundleDeps {
298
301
  * "fall through to SSR" signal.
299
302
  */
300
303
  digest: string | null;
304
+ expectedShopperDelivery?: StaticBundleManifest["shopperDelivery"] | null;
301
305
  /** Best-effort diagnostic sink (never throws, never blocks the response). */
302
306
  onFailClosed?: (detail: string) => void;
303
307
  }
@@ -453,13 +457,17 @@ export async function serveStaticBundle(
453
457
  method = "GET",
454
458
  ): Promise<Response | null> {
455
459
  const { bucket, digest } = deps;
456
- const pinned = await serveVersionIndependentAsset(bucket, pathname, method);
460
+ const privateAsset = deps.expectedShopperDelivery?.mode === "closed_store" &&
461
+ pathname.startsWith("/_a/") && closedCatalogPath(pathname) === "admit";
462
+ const pinned = privateAsset ? null : await serveVersionIndependentAsset(bucket, pathname, method);
457
463
  if (pinned) return pinned;
458
464
  if (!digest) {
459
465
  return failClosed(deps, "pointer-serving tenant has no resolved live digest");
460
466
  }
461
467
 
462
- const rel = staticBundleRelPath(pathname);
468
+ const rel = staticBundleRelPath(deps.expectedShopperDelivery?.mode === "closed_store" && pathname === "/manifest.json"
469
+ ? "/_public-release.json"
470
+ : pathname);
463
471
  if (!rel) {
464
472
  return failClosed(deps, `unsafe/unparseable path: ${JSON.stringify(pathname)}`);
465
473
  }
@@ -468,10 +476,24 @@ export async function serveStaticBundle(
468
476
  if (!manifest) {
469
477
  return failClosed(deps, `missing/unreadable manifest for digest ${digest}`);
470
478
  }
479
+ if (deps.expectedShopperDelivery !== undefined &&
480
+ (manifest.shopperDelivery?.mode !== deps.expectedShopperDelivery?.mode ||
481
+ manifest.shopperDelivery?.pricesHidden !== deps.expectedShopperDelivery?.pricesHidden)) {
482
+ return new Response(null, { status: 503, headers: { "cache-control": "private, no-store" } });
483
+ }
471
484
 
472
485
  const redirectTo = staticBundleRedirectLocation(manifest.redirects, pathname);
473
486
  if (redirectTo !== null) {
474
487
  const query = redirectTo.startsWith("/") ? search : "";
488
+ if (deps.expectedShopperDelivery?.mode === "closed_store" && redirectTo.startsWith("/")) {
489
+ const target = closedCatalogPath(redirectTo);
490
+ const headers = new Headers({ "cache-control": "private, no-store", "x-robots-tag": "noindex, nofollow" });
491
+ if (target === "deny") return new Response(null, { status: 404, headers });
492
+ if (target === "admit" && closedCatalogPath(pathname) === "allow") {
493
+ headers.set("location", `/account/sign-in?next=${encodeURIComponent(redirectTo)}`);
494
+ return new Response(null, { status: 303, headers });
495
+ }
496
+ }
475
497
  return new Response(null, {
476
498
  status: 308,
477
499
  headers: { location: `${redirectTo}${query}`, "cache-control": "public, max-age=300" },
@@ -484,6 +506,9 @@ export async function serveStaticBundle(
484
506
  // /cockpit, …) or a route this version never materialized. SSR owns it.
485
507
  return null;
486
508
  }
509
+ if (privateAsset && entry?.kind !== "route") {
510
+ return new Response(null, { status: 404, headers: { "cache-control": "private, no-store" } });
511
+ }
487
512
  const objectKey = resolveStaticBundleObjectKey(digest, rel, manifest.files);
488
513
  const object = await bucket.get(objectKey);
489
514
  if (!object) {
@@ -13,6 +13,17 @@ import type { EuUkVisitorPolicy } from "./integration/plan.js";
13
13
  import type { PublicationSpaceManifestV1 } from "./publication-space.js";
14
14
  import type { HtmlCachePolicy } from "./html-cache-policy.js";
15
15
 
16
+ export interface ShopperAccessPolicy {
17
+ mode: "open" | "checkout_gated" | "closed_store";
18
+ hidePricesForGuests?: boolean;
19
+ registrationMode?: "self_serve" | "approval_required";
20
+ b2bKybOrgVerification?: boolean;
21
+ }
22
+
23
+ export interface ShopperVerificationPolicy {
24
+ allowCrossStoreReuse?: boolean;
25
+ }
26
+
16
27
  /**
17
28
  * The shared semantic COLOR contract — the widget library's public API.
18
29
  *
@@ -813,6 +824,10 @@ export interface TenantConfig {
813
824
  * shipping. Amounts are in the cart's own currency.
814
825
  */
815
826
  shipping?: ShippingPolicy;
827
+ /** Catalog visibility, shopper enrollment and checkout admission. */
828
+ accessPolicy?: ShopperAccessPolicy;
829
+ /** Optional evidence reuse for shopper verification. */
830
+ verification?: ShopperVerificationPolicy;
816
831
  }
817
832
 
818
833
  /**