@tokenoftrust/storefront-runner 7.3.2 → 7.5.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.
Files changed (420) hide show
  1. package/agency-kit/tools/lib/catalog-model/files.mjs +11 -4
  2. package/agency-kit/tools/lib/catalog-model/model.mjs +5 -1
  3. package/agency-kit/tools/lib/redirect-shadows.mjs +261 -0
  4. package/apps/storefront/astro.config.mjs +8 -2
  5. package/apps/storefront/package.json +1 -2
  6. package/apps/storefront/src/components/catalog/storefront/ProductCard.astro +20 -6
  7. package/apps/storefront/src/components/catalog/storefront/islands/ImageGallery.tsx +17 -6
  8. package/apps/storefront/src/components/compliance/storefront/islands/CheckoutComplianceGate.tsx +1 -32
  9. package/apps/storefront/src/config/compliance/rulesets.ts +1 -1
  10. package/apps/storefront/src/layouts/Layout.astro +17 -0
  11. package/apps/storefront/src/lib/access/auth/agentRoles.ts +20 -0
  12. package/apps/storefront/src/lib/access/auth/agentSessionGate.ts +32 -8
  13. package/apps/storefront/src/lib/access/auth/brokerAssertion.ts +16 -2
  14. package/apps/storefront/src/lib/access/auth/contactReaderAuthority.ts +39 -0
  15. package/apps/storefront/src/lib/access/auth/loginGate.ts +15 -17
  16. package/apps/storefront/src/lib/access/dashboard/staffAdmission.ts +5 -0
  17. package/apps/storefront/src/lib/access/dashboard/tenantSelection.ts +2 -0
  18. package/apps/storefront/src/lib/access/shared/capability.ts +14 -6
  19. package/apps/storefront/src/lib/access/shared/generated/capabilityCatalog.generated.ts +161 -0
  20. package/apps/storefront/src/lib/activity/activityScope.ts +36 -0
  21. package/apps/storefront/src/lib/activity/recordActivity.ts +23 -1
  22. package/apps/storefront/src/lib/activity/serverFanOut.ts +31 -0
  23. package/apps/storefront/src/lib/activity/store.ts +9 -3
  24. package/apps/storefront/src/lib/checkout/agent/checkoutProtocol.ts +196 -0
  25. package/apps/storefront/src/lib/checkout/agent/checkoutSession.ts +296 -0
  26. package/apps/storefront/src/lib/checkout/agent/webBotAuth.ts +347 -0
  27. package/apps/storefront/src/lib/checkout/commerce/cardCartForm.ts +2 -0
  28. package/apps/storefront/src/lib/checkout/commerce/cartSession.ts +109 -12
  29. package/apps/storefront/src/lib/checkout/commerce/checkoutHandoffRoute.ts +53 -25
  30. package/apps/storefront/src/lib/checkout/commerce/finalCartAuthorization.ts +48 -6
  31. package/apps/storefront/src/lib/checkout/proposal/cartProposal.ts +388 -0
  32. package/apps/storefront/src/lib/checkout/proposal/listMatcher.ts +149 -0
  33. package/apps/storefront/src/lib/checkout/proposal/proposalRoutes.ts +522 -0
  34. package/apps/storefront/src/lib/checkout/proposal/reviewHtml.ts +100 -0
  35. package/apps/storefront/src/lib/compliance/browser/checkoutVerificationFlow.ts +26 -2
  36. package/apps/storefront/src/lib/content/shared/redirects.ts +21 -4
  37. package/apps/storefront/src/lib/publication/shared/edgeCache.ts +5 -2
  38. package/apps/storefront/src/lib/publication/shared/previewAnnotations/renderDecorator.ts +15 -8
  39. package/apps/storefront/src/lib/publication/shared/runtimeEnv.ts +1 -1
  40. package/apps/storefront/src/middleware/controlPlane.ts +15 -1
  41. package/apps/storefront/src/middleware/index.ts +7 -3
  42. package/apps/storefront/src/middleware/renderChain.ts +46 -33
  43. package/apps/storefront/src/pages/api/cart-proposal/confirm.ts +12 -0
  44. package/apps/storefront/src/pages/api/cart-proposal/review.ts +26 -0
  45. package/apps/storefront/src/pages/api/commerce/checkout-sessions/[id].ts +9 -0
  46. package/apps/storefront/src/pages/api/commerce/checkout-sessions.ts +8 -0
  47. package/apps/storefront/src/pages/api/commerce/final-cart-authorization.ts +29 -6
  48. package/apps/storefront/src/pages/api/compliance/preflight.ts +25 -1
  49. package/apps/storefront/src/pages/products/[handle].astro +2 -15
  50. package/apps/storefront/tsconfig.astro.json +11 -0
  51. package/package.json +1 -1
  52. package/packages/public-runtime/src/activity/README.md +12 -0
  53. package/packages/public-runtime/src/activity/catalog.ts +7 -0
  54. package/packages/public-runtime/src/activity/event.ts +19 -0
  55. package/packages/public-runtime/src/activity/redaction.ts +31 -2
  56. package/packages/public-runtime/src/catalog-files.ts +3 -2
  57. package/packages/public-runtime/src/checkout-orders.ts +18 -19
  58. package/packages/public-runtime/src/checkout.ts +70 -0
  59. package/packages/public-runtime/src/compliance/evaluate.ts +60 -1
  60. package/packages/public-runtime/src/compliance/index.ts +1 -1
  61. package/packages/public-runtime/src/compliance/pact-report.ts +184 -3
  62. package/packages/public-runtime/src/compliance/profile.ts +268 -20
  63. package/packages/public-runtime/src/compliance/ruleset.ts +42 -0
  64. package/packages/public-runtime/src/customization-runtime.ts +1 -1
  65. package/packages/public-runtime/src/product.ts +9 -1
  66. package/packages/public-runtime/src/publication-content-redirects.ts +16 -3
  67. package/packages/public-runtime/tests/fixtures/compliance-decisions.golden.json +252 -52
  68. package/pnpm-lock.runner.yaml +0 -15
  69. package/scripts/tenant/materialize-tenant-content.mjs +3 -0
  70. package/scripts/tenant/validate.mjs +128 -0
  71. package/apps/storefront/dev-plugins/dev-publish.mjs +0 -55
  72. package/apps/storefront/drizzle.config.apps.ts +0 -13
  73. package/apps/storefront/integrations/preview-annotations-client-bundle.mjs +0 -80
  74. package/apps/storefront/migrations-apps/0000_fast_millenium_guard.sql +0 -129
  75. package/apps/storefront/migrations-apps/0001_woozy_lyja.sql +0 -22
  76. package/apps/storefront/migrations-apps/0002_good_switch.sql +0 -26
  77. package/apps/storefront/migrations-apps/0003_mute_marauders.sql +0 -12
  78. package/apps/storefront/migrations-apps/0004_deep_morph.sql +0 -36
  79. package/apps/storefront/migrations-apps/0005_common_mystique.sql +0 -23
  80. package/apps/storefront/migrations-apps/0006_broad_microchip.sql +0 -16
  81. package/apps/storefront/migrations-apps/0007_brave_outlaw_kid.sql +0 -15
  82. package/apps/storefront/migrations-apps/0008_blue_dazzler.sql +0 -11
  83. package/apps/storefront/migrations-apps/0009_bored_shinobi_shaw.sql +0 -15
  84. package/apps/storefront/migrations-apps/0010_ws4_verified_provider_measurement.sql +0 -35
  85. package/apps/storefront/migrations-apps/0011_dt_tracking_tenant_databases.sql +0 -23
  86. package/apps/storefront/migrations-apps/0012_test_destinations.sql +0 -29
  87. package/apps/storefront/migrations-apps/0013_publication_space_editorial.sql +0 -64
  88. package/apps/storefront/migrations-apps/0014_retire_candidate_ledger.sql +0 -12
  89. package/apps/storefront/migrations-apps/0015_merchant_calculation_settings.sql +0 -31
  90. package/apps/storefront/migrations-apps/0016_scrappy_commerce_contract.sql +0 -166
  91. package/apps/storefront/migrations-apps/0017_commerce_durable_projection.sql +0 -28
  92. package/apps/storefront/migrations-apps/0018_commerce_provider_cart_identity.sql +0 -13
  93. package/apps/storefront/migrations-apps/0019_commerce_source_authority.sql +0 -23
  94. package/apps/storefront/migrations-apps/0020_contact_messages.sql +0 -18
  95. package/apps/storefront/migrations-apps/0021_contact_vault.sql +0 -166
  96. package/apps/storefront/migrations-apps/0022_contact_vault_fields.sql +0 -342
  97. package/apps/storefront/migrations-apps/0023_principal_grant_contacts.sql +0 -15
  98. package/apps/storefront/migrations-apps/0024_order_contact_erasure_state.sql +0 -22
  99. package/apps/storefront/migrations-apps/0025_shipment_audit_order_lookup.sql +0 -2
  100. package/apps/storefront/migrations-apps/0026_fulfillment_assignment.sql +0 -44
  101. package/apps/storefront/migrations-apps/0027_app_contact_authority.sql +0 -70
  102. package/apps/storefront/migrations-apps/0028_app_jwk_and_candidates.sql +0 -133
  103. package/apps/storefront/migrations-apps/0029_inventory_locations_wms.sql +0 -38
  104. package/apps/storefront/migrations-apps/0030_assignment_split_shipments.sql +0 -149
  105. package/apps/storefront/migrations-apps/meta/0000_snapshot.json +0 -843
  106. package/apps/storefront/migrations-apps/meta/0001_snapshot.json +0 -990
  107. package/apps/storefront/migrations-apps/meta/0002_snapshot.json +0 -1160
  108. package/apps/storefront/migrations-apps/meta/0003_snapshot.json +0 -1235
  109. package/apps/storefront/migrations-apps/meta/0004_snapshot.json +0 -1474
  110. package/apps/storefront/migrations-apps/meta/0005_snapshot.json +0 -1617
  111. package/apps/storefront/migrations-apps/meta/0006_snapshot.json +0 -1716
  112. package/apps/storefront/migrations-apps/meta/0007_snapshot.json +0 -1812
  113. package/apps/storefront/migrations-apps/meta/0008_snapshot.json +0 -1881
  114. package/apps/storefront/migrations-apps/meta/0009_snapshot.json +0 -1979
  115. package/apps/storefront/migrations-apps/meta/_journal.json +0 -76
  116. package/apps/storefront/perf/README.md +0 -64
  117. package/apps/storefront/perf/assert-budgets.ts +0 -159
  118. package/apps/storefront/platform-reconcile-tenants.json +0 -3
  119. package/apps/storefront/playwright.config.ts +0 -23
  120. package/apps/storefront/public/js/dashboard-access-banner.js +0 -53
  121. package/apps/storefront/public/js/dashboard-apps.js +0 -183
  122. package/apps/storefront/public/js/dashboard-contact-capture.js +0 -52
  123. package/apps/storefront/public/js/dashboard-delegate.js +0 -167
  124. package/apps/storefront/public/js/dashboard-team.js +0 -356
  125. package/apps/storefront/public/js/dashboard-vendor-search.js +0 -115
  126. package/apps/storefront/src/components/content/storefront/AsyncStylesheet.astro +0 -26
  127. package/apps/storefront/src/components/integrations/storefront/WidgetFrame.astro +0 -34
  128. package/apps/storefront/src/config/adminTenantLookup.ts +0 -35
  129. package/apps/storefront/src/config/evidenceTenantRoster.ts +0 -25
  130. package/apps/storefront/src/config/staffProvisionProjection.ts +0 -24
  131. package/apps/storefront/src/config/storeName.ts +0 -34
  132. package/apps/storefront/src/lib/access/admin/README.md +0 -122
  133. package/apps/storefront/src/lib/access/admin/adminShell.ts +0 -281
  134. package/apps/storefront/src/lib/access/admin/envelope.ts +0 -9
  135. package/apps/storefront/src/lib/access/admin/viewmodels/settings.ts +0 -64
  136. package/apps/storefront/src/lib/access/auth/adminApiGuard.ts +0 -66
  137. package/apps/storefront/src/lib/access/auth/adminEntry.ts +0 -126
  138. package/apps/storefront/src/lib/access/auth/mcpClientAssertion.ts +0 -217
  139. package/apps/storefront/src/lib/access/auth/operatorSession.ts +0 -120
  140. package/apps/storefront/src/lib/access/dashboard/agentStoreEntry.ts +0 -253
  141. package/apps/storefront/src/lib/access/dashboard/delegateGate.ts +0 -130
  142. package/apps/storefront/src/lib/access/dashboard/staffStoreEntry.ts +0 -153
  143. package/apps/storefront/src/lib/access/dashboard/staffVendorAccess.ts +0 -474
  144. package/apps/storefront/src/lib/access/dashboard/vendorQuery.ts +0 -61
  145. package/apps/storefront/src/lib/access/fixtures/settings.ts +0 -67
  146. package/apps/storefront/src/lib/access/fixtures/tenants.ts +0 -29
  147. package/apps/storefront/src/lib/access/notifications/magicLinkInviteEmail.ts +0 -62
  148. package/apps/storefront/src/lib/access/shared/grantContactLookup.ts +0 -97
  149. package/apps/storefront/src/lib/access/shared/principalGrants.ts +0 -775
  150. package/apps/storefront/src/lib/activity/alerts.ts +0 -426
  151. package/apps/storefront/src/lib/activity/candidateSubmitLease.ts +0 -87
  152. package/apps/storefront/src/lib/activity/changeActorAttribution.ts +0 -181
  153. package/apps/storefront/src/lib/activity/evidence/evidenceReference.ts +0 -32
  154. package/apps/storefront/src/lib/activity/fixtures/evidence.ts +0 -99
  155. package/apps/storefront/src/lib/activity/query.ts +0 -403
  156. package/apps/storefront/src/lib/activity/uiActor.ts +0 -152
  157. package/apps/storefront/src/lib/admin/services/mock/index.ts +0 -12
  158. package/apps/storefront/src/lib/assets/addons/catalog.ts +0 -60
  159. package/apps/storefront/src/lib/assets/addons/storeEntitlements.ts +0 -260
  160. package/apps/storefront/src/lib/assets/durableAssetsRoute.ts +0 -65
  161. package/apps/storefront/src/lib/assets/durableR2.ts +0 -473
  162. package/apps/storefront/src/lib/assets/durableR2Bindings.ts +0 -33
  163. package/apps/storefront/src/lib/automation/admin/viewmodels/aiWorkflows.ts +0 -65
  164. package/apps/storefront/src/lib/automation/ai/approvalMode.ts +0 -20
  165. package/apps/storefront/src/lib/automation/ai/askEnvelope.ts +0 -47
  166. package/apps/storefront/src/lib/automation/ai/audit.ts +0 -12
  167. package/apps/storefront/src/lib/automation/ai/operationalRuns.ts +0 -155
  168. package/apps/storefront/src/lib/automation/ai/recommendation.ts +0 -20
  169. package/apps/storefront/src/lib/automation/fixtures/aiWorkflows.ts +0 -59
  170. package/apps/storefront/src/lib/catalog/admin/catalogSettingsClient.ts +0 -250
  171. package/apps/storefront/src/lib/catalog/admin/catalogSettingsFields.ts +0 -134
  172. package/apps/storefront/src/lib/catalog/admin/catalogSettingsPreview.ts +0 -37
  173. package/apps/storefront/src/lib/catalog/admin/catalogSettingsPricingView.ts +0 -39
  174. package/apps/storefront/src/lib/catalog/admin/catalogSettingsRuleView.ts +0 -44
  175. package/apps/storefront/src/lib/catalog/admin/catalogSettingsSkuView.ts +0 -21
  176. package/apps/storefront/src/lib/catalog/admin/catalogSettingsState.ts +0 -132
  177. package/apps/storefront/src/lib/catalog/admin/productSetupPhoto.ts +0 -23
  178. package/apps/storefront/src/lib/catalog/admin/productsTabClient.ts +0 -193
  179. package/apps/storefront/src/lib/catalog/admin/services/catalogProducts.ts +0 -32
  180. package/apps/storefront/src/lib/catalog/admin/viewmodels/catalogProducts.ts +0 -164
  181. package/apps/storefront/src/lib/catalog/admin/viewmodels/products.ts +0 -267
  182. package/apps/storefront/src/lib/catalog/fixtures/products.ts +0 -105
  183. package/apps/storefront/src/lib/catalog/tot/syncState.ts +0 -111
  184. package/apps/storefront/src/lib/checkout/admin/checkoutStyleInput.ts +0 -172
  185. package/apps/storefront/src/lib/checkout/admin/checkoutStyleTarget.ts +0 -65
  186. package/apps/storefront/src/lib/checkout/browser/checkoutExciseForm.ts +0 -152
  187. package/apps/storefront/src/lib/checkout/browser/checkoutRequirementsForm.ts +0 -72
  188. package/apps/storefront/src/lib/checkout/browser/checkoutStyleForm.ts +0 -110
  189. package/apps/storefront/src/lib/checkout/browser/settingDraftActions.ts +0 -367
  190. package/apps/storefront/src/lib/checkout/commerce/checkoutSettings.ts +0 -246
  191. package/apps/storefront/src/lib/checkout/fixtures/checkoutSettings.ts +0 -77
  192. package/apps/storefront/src/lib/content/blog/markdown.ts +0 -174
  193. package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome-assignments.example.json +0 -6
  194. package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome.example.json +0 -79
  195. package/apps/storefront/src/lib/content/index.ts +0 -27
  196. package/apps/storefront/src/lib/content/the-build/readingTime.ts +0 -35
  197. package/apps/storefront/src/lib/content/the-build/toc.ts +0 -95
  198. package/apps/storefront/src/lib/customers/admin/viewmodels/customers.ts +0 -56
  199. package/apps/storefront/src/lib/customers/contactVault/blindIndex.ts +0 -28
  200. package/apps/storefront/src/lib/customers/contactVault/contactAudit.ts +0 -149
  201. package/apps/storefront/src/lib/customers/contactVault/dataKeys.ts +0 -283
  202. package/apps/storefront/src/lib/customers/contactVault/fieldEnvelope.ts +0 -88
  203. package/apps/storefront/src/lib/customers/contactVault/isolateMetrics.ts +0 -37
  204. package/apps/storefront/src/lib/customers/contactVault/kms.ts +0 -292
  205. package/apps/storefront/src/lib/customers/contactVault/retention.ts +0 -302
  206. package/apps/storefront/src/lib/customers/contactVault/retentionPolicy.ts +0 -290
  207. package/apps/storefront/src/lib/customers/contactVault/zip3.ts +0 -24
  208. package/apps/storefront/src/lib/customers/fixtures/customers.ts +0 -86
  209. package/apps/storefront/src/lib/developer-experience/admin/memoizeByEnvelope.ts +0 -27
  210. package/apps/storefront/src/lib/developer-experience/admin/seed.ts +0 -54
  211. package/apps/storefront/src/lib/developer-experience/dev/activityIngestToken.ts +0 -85
  212. package/apps/storefront/src/lib/developer-experience/dev/activityStore.ts +0 -82
  213. package/apps/storefront/src/lib/developer-experience/dev/agentGrantAttestation.ts +0 -74
  214. package/apps/storefront/src/lib/developer-experience/dev/ai-widget-client.js +0 -308
  215. package/apps/storefront/src/lib/developer-experience/dev/apiBase.ts +0 -17
  216. package/apps/storefront/src/lib/developer-experience/dev/cliSignInCode.ts +0 -124
  217. package/apps/storefront/src/lib/developer-experience/dev/cockpit/ask.ts +0 -49
  218. package/apps/storefront/src/lib/developer-experience/dev/cockpit/clickToSource.ts +0 -71
  219. package/apps/storefront/src/lib/developer-experience/dev/cockpit/copyCommand.ts +0 -227
  220. package/apps/storefront/src/lib/developer-experience/dev/cockpit/files.ts +0 -249
  221. package/apps/storefront/src/lib/developer-experience/dev/cockpit/hostedActivity.ts +0 -500
  222. package/apps/storefront/src/lib/developer-experience/dev/cockpit/infoPopover.ts +0 -12
  223. package/apps/storefront/src/lib/developer-experience/dev/cockpit/mcpCopy.ts +0 -34
  224. package/apps/storefront/src/lib/developer-experience/dev/cockpit/monitor.ts +0 -107
  225. package/apps/storefront/src/lib/developer-experience/dev/cockpit/stepper.ts +0 -116
  226. package/apps/storefront/src/lib/developer-experience/dev/cockpit/themeToggle.ts +0 -23
  227. package/apps/storefront/src/lib/developer-experience/dev/livePreview.ts +0 -77
  228. package/apps/storefront/src/lib/developer-experience/dev/obstacleStore.ts +0 -214
  229. package/apps/storefront/src/lib/developer-experience/dev/previewStatus.ts +0 -87
  230. package/apps/storefront/src/lib/developer-experience/dev/rendezvousBroker.ts +0 -226
  231. package/apps/storefront/src/lib/developer-experience/dev/runtimeStore.ts +0 -291
  232. package/apps/storefront/src/lib/developer-experience/dev/storeStatus.ts +0 -142
  233. package/apps/storefront/src/lib/developer-experience/dev/subjectReissue.ts +0 -67
  234. package/apps/storefront/src/lib/developer-experience/fixtures/regulated-commerce-truth/index.ts +0 -540
  235. package/apps/storefront/src/lib/developer-experience/fixtures/ws3-readonly-clone-preflight/index.ts +0 -495
  236. package/apps/storefront/src/lib/engagement/contact/contactMessages.ts +0 -671
  237. package/apps/storefront/src/lib/engagement/contact/messagesTabClient.ts +0 -175
  238. package/apps/storefront/src/lib/engagement/contact/submission.ts +0 -112
  239. package/apps/storefront/src/lib/engagement/messaging/messagesClient.ts +0 -149
  240. package/apps/storefront/src/lib/engagement/newsletter/digest.ts +0 -117
  241. package/apps/storefront/src/lib/engagement/newsletter/resendClient.ts +0 -79
  242. package/apps/storefront/src/lib/engagement/newsletter/send.ts +0 -265
  243. package/apps/storefront/src/lib/engagement/social/golive.ts +0 -212
  244. package/apps/storefront/src/lib/engagement/social/notify.ts +0 -32
  245. package/apps/storefront/src/lib/engagement/social/tokenStore.ts +0 -171
  246. package/apps/storefront/src/lib/fulfillment/admin/commerceDesk.ts +0 -180
  247. package/apps/storefront/src/lib/fulfillment/admin/commerceDeskRouting.ts +0 -45
  248. package/apps/storefront/src/lib/fulfillment/admin/viewmodels/fulfillment.ts +0 -1071
  249. package/apps/storefront/src/lib/fulfillment/appShipmentEvidence.ts +0 -271
  250. package/apps/storefront/src/lib/fulfillment/carrierEvidence.ts +0 -105
  251. package/apps/storefront/src/lib/fulfillment/commerceProjection.ts +0 -157
  252. package/apps/storefront/src/lib/fulfillment/commerceReadback.ts +0 -60
  253. package/apps/storefront/src/lib/fulfillment/commerceRecovery.ts +0 -84
  254. package/apps/storefront/src/lib/fulfillment/commerceRuntime.ts +0 -41
  255. package/apps/storefront/src/lib/fulfillment/fulfillmentService.ts +0 -2842
  256. package/apps/storefront/src/lib/fulfillment/readiness.ts +0 -217
  257. package/apps/storefront/src/lib/fulfillment/splitShipments.ts +0 -388
  258. package/apps/storefront/src/lib/fulfillment/syntheticPreviewOrders.ts +0 -292
  259. package/apps/storefront/src/lib/integrations/apps/appContactAuthority.ts +0 -27
  260. package/apps/storefront/src/lib/integrations/apps/appContactConsents.ts +0 -118
  261. package/apps/storefront/src/lib/integrations/apps/appInstallEnv.ts +0 -28
  262. package/apps/storefront/src/lib/integrations/apps/gtmMigrationDraft.ts +0 -103
  263. package/apps/storefront/src/lib/integrations/apps/inventoryWrite.ts +0 -906
  264. package/apps/storefront/src/lib/integrations/apps/orders/customerHash.ts +0 -28
  265. package/apps/storefront/src/lib/integrations/apps/orders/idempotency.ts +0 -100
  266. package/apps/storefront/src/lib/integrations/apps/reports/salesVelocityReport.ts +0 -96
  267. package/apps/storefront/src/lib/integrations/apps/routeParams.ts +0 -45
  268. package/apps/storefront/src/lib/integrations/webhooks/cloudflareQueueDispatcher.ts +0 -82
  269. package/apps/storefront/src/lib/integrations/webhooks/commercePayloads.ts +0 -159
  270. package/apps/storefront/src/lib/integrations/webhooks/deliveryEngine.ts +0 -379
  271. package/apps/storefront/src/lib/integrations/webhooks/deliveryMapper.ts +0 -34
  272. package/apps/storefront/src/lib/integrations/webhooks/deliveryStore.ts +0 -903
  273. package/apps/storefront/src/lib/integrations/webhooks/dispatcher.ts +0 -168
  274. package/apps/storefront/src/lib/integrations/webhooks/emit.ts +0 -245
  275. package/apps/storefront/src/lib/integrations/webhooks/events.ts +0 -105
  276. package/apps/storefront/src/lib/integrations/webhooks/getDispatcher.ts +0 -77
  277. package/apps/storefront/src/lib/integrations/webhooks/orderFulfilledClaim.ts +0 -75
  278. package/apps/storefront/src/lib/measurement/admin/analyticsRegionPolicy.ts +0 -151
  279. package/apps/storefront/src/lib/measurement/admin/analyticsRegionsClient.ts +0 -84
  280. package/apps/storefront/src/lib/measurement/admin/consentSettingsClient.ts +0 -113
  281. package/apps/storefront/src/lib/measurement/analytics/index.ts +0 -44
  282. package/apps/storefront/src/lib/measurement/attribution/attributionService.ts +0 -206
  283. package/apps/storefront/src/lib/measurement/attribution/orderConversionD1.ts +0 -150
  284. package/apps/storefront/src/lib/measurement/attribution/verifiedProviderMeasurement.ts +0 -118
  285. package/apps/storefront/src/lib/measurement/tracking/interactionCollector.ts +0 -205
  286. package/apps/storefront/src/lib/measurement/tracking/pruneRollup.ts +0 -260
  287. package/apps/storefront/src/lib/measurement/tracking/tenantReadAccess.ts +0 -138
  288. package/apps/storefront/src/lib/measurement/tracking-writeback/rewriteTrackingIds.ts +0 -175
  289. package/apps/storefront/src/lib/measurement/tracking-writeback/writebackCandidate.ts +0 -110
  290. package/apps/storefront/src/lib/observability/diag/capture.ts +0 -162
  291. package/apps/storefront/src/lib/observability/diag/consoleLine.ts +0 -76
  292. package/apps/storefront/src/lib/observability/diag/debugConsole.ts +0 -118
  293. package/apps/storefront/src/lib/observability/diag/debugMode.ts +0 -163
  294. package/apps/storefront/src/lib/observability/diag/debugWindow.ts +0 -111
  295. package/apps/storefront/src/lib/observability/diag/redact.ts +0 -17
  296. package/apps/storefront/src/lib/observability/diag/reference.ts +0 -148
  297. package/apps/storefront/src/lib/observability/diag/referenceStore.ts +0 -113
  298. package/apps/storefront/src/lib/observability/diag/report.ts +0 -110
  299. package/apps/storefront/src/lib/observability/diag/serverResponseTime.ts +0 -91
  300. package/apps/storefront/src/lib/observability/diag/session.ts +0 -93
  301. package/apps/storefront/src/lib/observability/monitoring/manifest.ts +0 -301
  302. package/apps/storefront/src/lib/observability/performance/lighthouseReport.ts +0 -109
  303. package/apps/storefront/src/lib/observability/performance/rumAlert.ts +0 -179
  304. package/apps/storefront/src/lib/orders/admin/orderActions.ts +0 -556
  305. package/apps/storefront/src/lib/orders/admin/orderClient.ts +0 -248
  306. package/apps/storefront/src/lib/orders/admin/orderSource.ts +0 -410
  307. package/apps/storefront/src/lib/orders/admin/services/orders.ts +0 -922
  308. package/apps/storefront/src/lib/orders/admin/viewmodels/orders.ts +0 -135
  309. package/apps/storefront/src/lib/orders/data/commerceCallerConfig.ts +0 -37
  310. package/apps/storefront/src/lib/orders/data/ledgerContractOrders.ts +0 -148
  311. package/apps/storefront/src/lib/orders/data/orderForwardReceiver.ts +0 -532
  312. package/apps/storefront/src/lib/orders/data/orderMapper.ts +0 -454
  313. package/apps/storefront/src/lib/orders/data/ordersStore.ts +0 -623
  314. package/apps/storefront/src/lib/orders/data/sourceAuthorityContract.ts +0 -380
  315. package/apps/storefront/src/lib/orders/data/sourceAuthorityStore.ts +0 -830
  316. package/apps/storefront/src/lib/orders/fixtures/orders.ts +0 -186
  317. package/apps/storefront/src/lib/orders/providers/foxyOrderClient.ts +0 -207
  318. package/apps/storefront/src/lib/orders/vault/appRecipientRead.ts +0 -222
  319. package/apps/storefront/src/lib/orders/vault/contactIntake.ts +0 -63
  320. package/apps/storefront/src/lib/orders/vault/contactRoutes.ts +0 -110
  321. package/apps/storefront/src/lib/orders/vault/kmsEnv.ts +0 -11
  322. package/apps/storefront/src/lib/orders/vault/orderContact.ts +0 -96
  323. package/apps/storefront/src/lib/orders/vault/orderContactVault.ts +0 -1427
  324. package/apps/storefront/src/lib/orders/vault/vault-test-support.ts +0 -258
  325. package/apps/storefront/src/lib/publication/d1/schema-apps.ts +0 -808
  326. package/apps/storefront/src/lib/publication/notifications/candidateConflictEmail.ts +0 -80
  327. package/apps/storefront/src/lib/publication/servingMode.ts +0 -52
  328. package/apps/storefront/src/lib/publication/shared/previewAnnotations/moduleAsset.ts +0 -65
  329. package/apps/storefront/src/lib/publication/shared/routedApiParam.ts +0 -38
  330. package/apps/storefront/src/lib/reporting/admin/viewmodels/reporting.ts +0 -34
  331. package/apps/storefront/src/lib/reporting/fixtures/reporting.ts +0 -51
  332. package/apps/storefront/src/lib/subscriptions/admin/viewmodels/subscriptions.ts +0 -106
  333. package/apps/storefront/src/lib/subscriptions/fixtures/subscriptions.ts +0 -398
  334. package/apps/storefront/src/pages/api/admin/activity-alerts.ts +0 -58
  335. package/apps/storefront/src/pages/api/admin/commerce-readiness.ts +0 -172
  336. package/apps/storefront/src/pages/api/admin/fulfillment/batches.ts +0 -59
  337. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id]/address.ts +0 -66
  338. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id].ts +0 -118
  339. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contact-search.ts +0 -26
  340. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contacts.ts +0 -22
  341. package/apps/storefront/src/pages/api/admin/interaction-insights.ts +0 -101
  342. package/apps/storefront/src/pages/api/admin/orders/[id].ts +0 -63
  343. package/apps/storefront/src/pages/api/admin/orders.ts +0 -65
  344. package/apps/storefront/src/pages/api/contact.ts +0 -144
  345. package/apps/storefront/src/scheduled/contactVaultSweep.ts +0 -113
  346. package/apps/storefront/src/styles/admin.css +0 -1161
  347. package/apps/storefront/test/pipeline/fake-preview-services.ts +0 -288
  348. package/apps/storefront/test/pipeline/harness.ts +0 -209
  349. package/apps/storefront/test/pipeline/intake-worker.mjs +0 -14
  350. package/apps/storefront/test/pipeline/matrix-faults.ts +0 -366
  351. package/apps/storefront/test/pipeline/pipeline-host.ts +0 -418
  352. package/apps/storefront/test/pipeline/pool-config.cjs +0 -85
  353. package/apps/storefront/test/pipeline/publish-kinds.ts +0 -279
  354. package/apps/storefront/test/pipeline/synthetic-job.ts +0 -303
  355. package/apps/storefront/test/pipeline-faults/matrix-lib.ts +0 -696
  356. package/apps/storefront/vitest.config.cts +0 -44
  357. package/apps/storefront/vitest.faults.config.cts +0 -13
  358. package/apps/storefront/vitest.workers.config.cts +0 -7
  359. package/packages/feedback/fixtures/v1/expected-findings.json +0 -16
  360. package/packages/feedback/fixtures/v1/feedback-action/invalid/carries-transport-credential.json +0 -14
  361. package/packages/feedback/fixtures/v1/feedback-action/invalid/control-char-in-description.json +0 -13
  362. package/packages/feedback/fixtures/v1/feedback-action/invalid/legacy-schema-version.json +0 -13
  363. package/packages/feedback/fixtures/v1/feedback-action/invalid/page-path-with-query.json +0 -14
  364. package/packages/feedback/fixtures/v1/feedback-action/invalid/title-too-short.json +0 -13
  365. package/packages/feedback/fixtures/v1/feedback-action/valid/element-problem.json +0 -33
  366. package/packages/feedback/fixtures/v1/feedback-action/valid/page-comment.json +0 -20
  367. package/packages/feedback/fixtures/v1/feedback-action/valid/region-improvement.json +0 -24
  368. package/packages/feedback/fixtures/v1/feedback-action/valid/text-selection-feature.json +0 -30
  369. package/packages/feedback/fixtures/v1/submission-receipt/invalid/accepted-at-not-utc.json +0 -9
  370. package/packages/feedback/fixtures/v1/submission-receipt/invalid/bad-feedback-id.json +0 -9
  371. package/packages/feedback/fixtures/v1/submission-receipt/invalid/legacy-contract-version.json +0 -9
  372. package/packages/feedback/fixtures/v1/submission-receipt/invalid/missing-replayed.json +0 -8
  373. package/packages/feedback/fixtures/v1/submission-receipt/valid/accepted.json +0 -9
  374. package/packages/feedback/fixtures/v1/submission-receipt/valid/fractional-seconds.json +0 -9
  375. package/packages/feedback/fixtures/v1/submission-receipt/valid/replayed.json +0 -9
  376. package/packages/feedback/fixtures/v1/target-evidence/invalid/page-kind-claims-structure.json +0 -6
  377. package/packages/feedback/fixtures/v1/target-evidence/invalid/path-too-deep.json +0 -17
  378. package/packages/feedback/fixtures/v1/target-evidence/invalid/relative-region-out-of-range.json +0 -11
  379. package/packages/feedback/fixtures/v1/target-evidence/invalid/selector-uses-class.json +0 -7
  380. package/packages/feedback/fixtures/v1/target-evidence/invalid/source-precision-without-anchor.json +0 -6
  381. package/packages/feedback/fixtures/v1/target-evidence/valid/element-structure.json +0 -21
  382. package/packages/feedback/fixtures/v1/target-evidence/valid/host-iframe.json +0 -14
  383. package/packages/feedback/fixtures/v1/target-evidence/valid/source-anchor.json +0 -12
  384. package/packages/feedback/fixtures/v1/target-evidence/valid/text-selection.json +0 -26
  385. package/packages/feedback/package.json +0 -35
  386. package/packages/feedback/scripts/build-player.mjs +0 -28
  387. package/packages/feedback/src/index.ts +0 -1
  388. package/packages/feedback/src/primitives/composer.ts +0 -639
  389. package/packages/feedback/src/primitives/dialog.ts +0 -263
  390. package/packages/feedback/src/primitives/hostAdapter.ts +0 -116
  391. package/packages/feedback/src/primitives/index.ts +0 -10
  392. package/packages/feedback/src/primitives/launcher.ts +0 -200
  393. package/packages/feedback/src/primitives/picker.ts +0 -663
  394. package/packages/feedback/src/primitives/redaction.ts +0 -204
  395. package/packages/feedback/src/primitives/selection.ts +0 -49
  396. package/packages/feedback/src/primitives/shiftAccelerator.ts +0 -160
  397. package/packages/feedback/src/primitives/styles.ts +0 -77
  398. package/packages/feedback/src/primitives/surface.ts +0 -124
  399. package/packages/feedback/src/primitives/target.ts +0 -293
  400. package/packages/feedback/src/tour/canonical.ts +0 -27
  401. package/packages/feedback/src/tour/index.ts +0 -3
  402. package/packages/feedback/src/tour/player/browser.ts +0 -5
  403. package/packages/feedback/src/tour/player/host.ts +0 -12
  404. package/packages/feedback/src/tour/player/index.ts +0 -205
  405. package/packages/feedback/src/tour/player/manifest.ts +0 -76
  406. package/packages/feedback/src/tour/player/player.css +0 -130
  407. package/packages/feedback/src/tour/player/resolver.ts +0 -12
  408. package/packages/feedback/src/tour/player/surface.ts +0 -295
  409. package/packages/feedback/src/tour/player/types.ts +0 -8
  410. package/packages/feedback/src/tour/resolve/core.ts +0 -267
  411. package/packages/feedback/src/tour/resolve/dom.ts +0 -115
  412. package/packages/feedback/src/tour/resolve/index.ts +0 -29
  413. package/packages/feedback/src/tour/sanitize.ts +0 -76
  414. package/packages/feedback/src/tour/schema.ts +0 -362
  415. package/packages/feedback/src/v1/guards.ts +0 -335
  416. package/packages/feedback/src/v1/index.ts +0 -3
  417. package/packages/feedback/src/v1/protectedSurfaces.ts +0 -32
  418. package/packages/feedback/src/v1/types.ts +0 -177
  419. package/packages/feedback/tsconfig.json +0 -9
  420. package/packages/feedback/vitest.config.cts +0 -21
@@ -1,67 +0,0 @@
1
- /**
2
- * Re-issue a FRESH tot20-signed id_token for an already-signed-in developer — the
3
- * `subject_token` proof the cockpit sends when APPROVING a browserless CLI sign-in
4
- * rendezvous (Part A / Finding 3).
5
- *
6
- * WHY re-issue: the storefront verifies tot20's id_token OFFLINE at sign-in and then
7
- * DISCARDS it (only derived claims live in the KV session), and it's short-lived —
8
- * long expired by the time the developer approves. So at approve time we MINT a fresh
9
- * single-use sign-in token for the session's VERIFIED email and exchange it for a
10
- * freshly-signed id_token.
11
- *
12
- * WHY it closes Finding 3: the mint + exchange authenticate with the storefront's tot20
13
- * CORE machine credential (TOT_API_KEY/TOT_SECRET_KEY) — a DIFFERENT secret from the MCP
14
- * broker key. A compromised broker key alone cannot produce this proof.
15
- *
16
- * WHY mint, NOT developerInvites: tot20's access-code `/mint` is NOT operator-grant-gated
17
- * per tenant, whereas developerInvites is (it 403s `notGranted` for a non-staff developer
18
- * re-attesting themselves on a tenant the storefront doesn't operate). `/mint` binds the
19
- * token to (email, aud = the storefront's OWN appDomain) — which equals the storefront's
20
- * MCP client_id, exactly what the MCP binds the subject_token audience to. This is the
21
- * same non-gated mint the MCP itself uses to power rendezvous creation.
22
- */
23
- import { getAccessClient } from "@/lib/access/auth/route";
24
- import type { TotAccessClient } from "@/lib/access/auth/totAccessClient";
25
-
26
- /** Short — the proof is minted and used immediately at approve time. */
27
- const SUBJECT_TOKEN_TTL_SECONDS = 120;
28
-
29
- export type SubjectReissueResult =
30
- | { ok: true; idToken: string }
31
- | { ok: false; reason: string };
32
-
33
- export interface SubjectReissueDeps {
34
- accessClient?: TotAccessClient | null;
35
- }
36
-
37
- /**
38
- * Produce a fresh subject id_token for `email`. Fail-closed: any gap (unconfigured seam,
39
- * mint refused, exchange failed / step-up required) returns a typed `{ ok:false, reason }`
40
- * and NEVER throws — the caller maps that to a refusal to approve. The id_token is returned
41
- * only to the server; it is never logged.
42
- */
43
- export async function reissueSubjectToken(
44
- email: string,
45
- deps: SubjectReissueDeps = {},
46
- ): Promise<SubjectReissueResult> {
47
- if (!email) return { ok: false, reason: "missing-identity" };
48
-
49
- const accessClient =
50
- deps.accessClient !== undefined ? deps.accessClient : await getAccessClient();
51
- if (!accessClient) return { ok: false, reason: "access-client-unconfigured" };
52
-
53
- // Mint a fresh single-use sign-in token for the developer's OWN email (bound to the
54
- // storefront's appDomain as audience — not grant-gated per tenant).
55
- const minted = await accessClient.mintSignInToken(email, SUBJECT_TOKEN_TTL_SECONDS);
56
- if (!minted.ok || !minted.token) {
57
- return { ok: false, reason: minted.ok ? "no-signin-token" : `mint-${minted.reason}` };
58
- }
59
-
60
- // Exchange (single-use; tot20 burns it) → a signed federated id_token whose aud is the
61
- // storefront appDomain and whose email is this developer.
62
- const exchanged = await accessClient.exchangeSignInToken(minted.token);
63
- if (!exchanged.ok || !exchanged.id_token) {
64
- return { ok: false, reason: exchanged.ok ? "no-id-token" : `exchange-${exchanged.reason}` };
65
- }
66
- return { ok: true, idToken: exchanged.id_token };
67
- }
@@ -1,540 +0,0 @@
1
- /**
2
- * Synthetic regulated-commerce truth used by cross-workstream conformance tests.
3
- *
4
- * This module is deliberately fixture-only. It does not call an integration API,
5
- * deliver an order, import a report, or mutate a tenant. Consumers receive a
6
- * validated, detached snapshot whose identifiers can never name a live tenant or
7
- * destination.
8
- */
9
-
10
- export const REGULATED_COMMERCE_TRUTH_SCHEMA = "regulated-commerce-truth.v1" as const;
11
-
12
- export type ExpectedInvariant =
13
- | { disposition: "allow"; violations: [] }
14
- | { disposition: "closed-failure"; violations: ["age-verification-required"] };
15
-
16
- export interface RegulatedCommerceTruthFixture {
17
- schemaVersion: typeof REGULATED_COMMERCE_TRUTH_SCHEMA;
18
- fixtureId: string;
19
- synthetic: true;
20
- capturedAt: string;
21
- tenant: {
22
- tenantId: string;
23
- /** Canonical public-runtime TenantTier vocabulary. */
24
- tenantTier: "regulated-commerce";
25
- jurisdiction: string;
26
- minimumAge: number;
27
- ageVerificationRequired: true;
28
- };
29
- integrations: Array<{
30
- reference: string;
31
- kind: "order-risk";
32
- destination: string;
33
- enabled: boolean;
34
- }>;
35
- orders: Array<{
36
- orderReference: string;
37
- integrationReference: string;
38
- occurredAt: string;
39
- status: "paid" | "closed";
40
- currency: "USD";
41
- totalMinor: number;
42
- destinationCountry: "US";
43
- regulatedItems: Array<{
44
- sku: string;
45
- category: "age-restricted";
46
- quantity: number;
47
- unitPriceMinor: number;
48
- }>;
49
- compliance: {
50
- ageVerification: "passed" | "missing";
51
- consentRecorded: boolean;
52
- taxCollectedMinor: number;
53
- };
54
- expectedInvariant: ExpectedInvariant;
55
- }>;
56
- }
57
-
58
- const FIXTURE_SOURCE = {
59
- schemaVersion: REGULATED_COMMERCE_TRUTH_SCHEMA,
60
- fixtureId: "synthetic-regulated-commerce-risk-v1",
61
- synthetic: true,
62
- capturedAt: "2026-08-29T12:00:00.000Z",
63
- tenant: {
64
- tenantId: "synthetic-regulated-merchant.test",
65
- tenantTier: "regulated-commerce",
66
- jurisdiction: "US-MN",
67
- minimumAge: 21,
68
- ageVerificationRequired: true,
69
- },
70
- integrations: [
71
- {
72
- reference: "integration:synthetic:order-risk-v1",
73
- kind: "order-risk",
74
- destination: "fake://synthetic-order-risk/deliveries",
75
- enabled: true,
76
- },
77
- ],
78
- orders: [
79
- {
80
- orderReference: "order:synthetic:verified-001",
81
- integrationReference: "integration:synthetic:order-risk-v1",
82
- occurredAt: "2026-08-29T12:01:00.000Z",
83
- status: "paid",
84
- currency: "USD",
85
- totalMinor: 6499,
86
- destinationCountry: "US",
87
- regulatedItems: [
88
- {
89
- sku: "SYNTH-AGE-21-001",
90
- category: "age-restricted",
91
- quantity: 1,
92
- unitPriceMinor: 5999,
93
- },
94
- ],
95
- compliance: {
96
- ageVerification: "passed",
97
- consentRecorded: true,
98
- taxCollectedMinor: 500,
99
- },
100
- expectedInvariant: { disposition: "allow", violations: [] },
101
- },
102
- {
103
- orderReference: "order:synthetic:closed-002",
104
- integrationReference: "integration:synthetic:order-risk-v1",
105
- occurredAt: "2026-08-29T12:02:00.000Z",
106
- status: "closed",
107
- currency: "USD",
108
- totalMinor: 3299,
109
- destinationCountry: "US",
110
- regulatedItems: [
111
- {
112
- sku: "SYNTH-AGE-21-002",
113
- category: "age-restricted",
114
- quantity: 1,
115
- unitPriceMinor: 2999,
116
- },
117
- ],
118
- compliance: {
119
- ageVerification: "missing",
120
- consentRecorded: false,
121
- taxCollectedMinor: 300,
122
- },
123
- expectedInvariant: {
124
- disposition: "closed-failure",
125
- violations: ["age-verification-required"],
126
- },
127
- },
128
- ],
129
- } satisfies RegulatedCommerceTruthFixture;
130
-
131
- const UNSAFE_KEY = /(authorization|credential|secret|password|api[-_]?key|access[-_]?token|refresh[-_]?token|email|phone|address|(?:^|[-_])name(?:$|[-_]))/i;
132
- const CREDENTIAL_VALUE = /(-----BEGIN [A-Z ]*PRIVATE KEY-----|\bBearer\s+[A-Za-z0-9._~-]+|\bAKIA[0-9A-Z]{16}\b)/;
133
- const EMAIL_VALUE = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i;
134
- const PHONE_VALUE = /\b(?:\+?\d{1,3}[-. ]?)?(?:\(\d{3}\)|\d{3})[-. ]\d{3}[-. ]\d{4}\b/;
135
- const PAYMENT_VALUE = /(?:^|[^0-9])(?:\d{4}[- ]?){3}\d{4}(?:$|[^0-9])|(?:^|[^0-9])\d{13,19}(?:$|[^0-9])/;
136
- /** US SSN/EIN-like nine-digit identifiers, contiguous or in their common hyphenated forms. */
137
- const GOVERNMENT_ID_VALUE = /(?:^|[^0-9])(?:\d{3}-\d{2}-\d{4}|\d{2}-\d{7}|\d{9})(?:$|[^0-9])/;
138
- const ADDRESS_VALUE = /\b\d{1,6}(?:[- ]+[A-Za-z][A-Za-z0-9.']*){1,5}[- ]+(?:street|st|avenue|ave|road|rd|boulevard|blvd|lane|ln|drive|dr|court|ct|way)\b/i;
139
- const PERSON_NAME_VALUE = /\b(?:[A-Z][a-z]{1,30}\s+[A-Z][a-z]{1,30}|(?:jane|john)[-_ ]doe)\b/i;
140
- const LIVE_URL_VALUE = /\b(?:https?|wss?):\/\//i;
141
- const CODE_VALUE = /(?:<\/?script\b|javascript:|\{\{|=>|\bfunction\s*\(|\b(?:window|document)\.|\bdataLayer\b|\bGTM-[A-Z0-9-]+\b)/i;
142
-
143
- // This is one local golden fixture, not a public extensible identity contract.
144
- const FIXTURE_ID = /^synthetic-regulated-commerce-risk-v1$/;
145
- const TENANT_ID = /^synthetic-regulated-merchant\.test$/;
146
- const JURISDICTION = /^US-MN$/;
147
- const INTEGRATION_REFERENCE = /^integration:synthetic:order-risk-v1$/;
148
- const FAKE_DESTINATION = /^fake:\/\/synthetic-order-risk\/deliveries$/;
149
- const ORDER_REFERENCE = /^order:synthetic:(?:verified|closed)-\d{3}$/;
150
- const SYNTHETIC_SKU = /^SYNTH-AGE-21-\d{3}$/;
151
- const MAX_MINIMUM_AGE = 125;
152
- const MAX_ITEM_QUANTITY = 10_000;
153
- const MAX_MINOR_AMOUNT = 99_999_999;
154
-
155
- class FixtureValidationError extends Error {}
156
- const VALIDATION_ERRORS = new WeakSet<object>();
157
-
158
- function fail(path: string, message: string): never {
159
- const error = new FixtureValidationError(`Invalid regulated-commerce truth at ${path}: ${message}`);
160
- VALIDATION_ERRORS.add(error);
161
- throw Object.freeze(error);
162
- }
163
-
164
- function record(value: unknown, path: string): Record<string, unknown> {
165
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
166
- fail(path, "expected a plain data object");
167
- }
168
- const prototype = Object.getPrototypeOf(value);
169
- if (prototype !== Object.prototype && prototype !== null) fail(path, "expected a plain data object");
170
- return value as Record<string, unknown>;
171
- }
172
-
173
- function ownDataValue(value: Record<string, unknown>, key: string): unknown {
174
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
175
- return descriptor && descriptor.enumerable && Object.hasOwn(descriptor, "value")
176
- ? descriptor.value
177
- : undefined;
178
- }
179
-
180
- function arrayDataValues(value: unknown, path: string): unknown[] {
181
- if (!Array.isArray(value) || Object.getPrototypeOf(value) !== Array.prototype) {
182
- fail(path, "expected an ordinary data array");
183
- }
184
- const lengthDescriptor = Object.getOwnPropertyDescriptor(value, "length");
185
- const length = lengthDescriptor && Object.hasOwn(lengthDescriptor, "value")
186
- ? lengthDescriptor.value
187
- : -1;
188
- if (!Number.isSafeInteger(length) || (length as number) < 0) fail(path, "array length is invalid");
189
- const result: unknown[] = [];
190
- for (let index = 0; index < (length as number); index += 1) {
191
- const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
192
- if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) {
193
- fail(`${path}[${index}]`, "expected an own enumerable data item");
194
- }
195
- result.push(descriptor.value);
196
- }
197
- for (const key of Reflect.ownKeys(value)) {
198
- if (key === "length") continue;
199
- if (typeof key !== "string" || !/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= (length as number)) {
200
- fail(path, "array contains unexpected metadata");
201
- }
202
- }
203
- return result;
204
- }
205
-
206
- function string(value: unknown, path: string): string {
207
- if (typeof value !== "string" || value.length === 0) fail(path, "expected a non-empty string");
208
- return value;
209
- }
210
-
211
- function boundedInteger(value: unknown, path: string, minimum: number, maximum: number): number {
212
- if (!Number.isSafeInteger(value) || (value as number) < minimum || (value as number) > maximum) {
213
- fail(path, `expected an integer from ${minimum} through ${maximum}`);
214
- }
215
- return value as number;
216
- }
217
-
218
- function exactKeys(value: Record<string, unknown>, keys: string[], path: string): void {
219
- const expected = new Set(keys);
220
- for (const key of Reflect.ownKeys(value)) {
221
- if (typeof key !== "string" || !expected.has(key)) fail(path, "contains an unexpected field");
222
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
223
- if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) {
224
- fail(`${path}.${key}`, "must be an own enumerable data field");
225
- }
226
- }
227
- for (const key of keys) {
228
- if (ownDataValue(value, key) === undefined) fail(`${path}.${key}`, "required data field is missing");
229
- }
230
- }
231
-
232
- function literal<T extends string | boolean>(value: unknown, expected: T, path: string): T {
233
- if (value !== expected) fail(path, `expected ${JSON.stringify(expected)}`);
234
- return expected;
235
- }
236
-
237
- function oneOf<T extends string>(value: unknown, allowed: readonly T[], path: string): T {
238
- if (typeof value !== "string" || !allowed.includes(value as T)) {
239
- fail(path, `expected one of ${allowed.join(", ")}`);
240
- }
241
- return value as T;
242
- }
243
-
244
- function isoTimestamp(value: unknown, path: string): string {
245
- const parsed = string(value, path);
246
- if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(parsed) || Number.isNaN(Date.parse(parsed))) {
247
- fail(path, "expected a canonical UTC timestamp");
248
- }
249
- return parsed;
250
- }
251
-
252
- function assertSanitized(value: unknown, path = "fixture"): void {
253
- if (typeof value === "string") {
254
- if (CREDENTIAL_VALUE.test(value)) fail(path, "credential-shaped value is forbidden");
255
- if (
256
- EMAIL_VALUE.test(value) ||
257
- PHONE_VALUE.test(value) ||
258
- PAYMENT_VALUE.test(value) ||
259
- GOVERNMENT_ID_VALUE.test(value) ||
260
- ADDRESS_VALUE.test(value) ||
261
- PERSON_NAME_VALUE.test(value)
262
- ) {
263
- fail(path, "PII-shaped value is forbidden");
264
- }
265
- if (LIVE_URL_VALUE.test(value)) fail(path, "live URL value is forbidden");
266
- if (CODE_VALUE.test(value)) fail(path, "code-bearing value is forbidden");
267
- return;
268
- }
269
- if (Array.isArray(value)) {
270
- const entries = arrayDataValues(value, path);
271
- for (let index = 0; index < entries.length; index += 1) {
272
- assertSanitized(entries[index], `${path}[${index}]`);
273
- }
274
- return;
275
- }
276
- if (value !== null && typeof value === "object") {
277
- const object = record(value, path);
278
- for (const key of Reflect.ownKeys(object)) {
279
- if (typeof key !== "string") fail(path, "contains a non-JSON field");
280
- const descriptor = Object.getOwnPropertyDescriptor(object, key);
281
- if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) {
282
- fail(path, "contains a non-data field");
283
- }
284
- if (UNSAFE_KEY.test(key)) fail(path, "contains a PII/secret-shaped field");
285
- // Do not include caller-controlled property names in diagnostics.
286
- assertSanitized(descriptor.value, path);
287
- }
288
- }
289
- }
290
-
291
- function parseTenant(value: unknown): RegulatedCommerceTruthFixture["tenant"] {
292
- const input = record(value, "fixture.tenant");
293
- exactKeys(
294
- input,
295
- ["tenantId", "tenantTier", "jurisdiction", "minimumAge", "ageVerificationRequired"],
296
- "fixture.tenant",
297
- );
298
- const tenantId = string(ownDataValue(input, "tenantId"), "fixture.tenant.tenantId");
299
- if (!TENANT_ID.test(tenantId)) {
300
- fail("fixture.tenant.tenantId", "must use the closed synthetic tenant-id format");
301
- }
302
- const jurisdiction = string(ownDataValue(input, "jurisdiction"), "fixture.tenant.jurisdiction");
303
- if (!JURISDICTION.test(jurisdiction)) {
304
- fail("fixture.tenant.jurisdiction", "must use the closed jurisdiction format");
305
- }
306
- return {
307
- tenantId,
308
- tenantTier: literal(ownDataValue(input, "tenantTier"), "regulated-commerce", "fixture.tenant.tenantTier"),
309
- jurisdiction,
310
- minimumAge: boundedInteger(
311
- ownDataValue(input, "minimumAge"),
312
- "fixture.tenant.minimumAge",
313
- 18,
314
- MAX_MINIMUM_AGE,
315
- ),
316
- ageVerificationRequired: literal(
317
- ownDataValue(input, "ageVerificationRequired"),
318
- true,
319
- "fixture.tenant.ageVerificationRequired",
320
- ),
321
- };
322
- }
323
-
324
- function parseIntegrations(value: unknown): RegulatedCommerceTruthFixture["integrations"] {
325
- const inputs = arrayDataValues(value, "fixture.integrations");
326
- if (inputs.length === 0) fail("fixture.integrations", "at least one integration reference is required");
327
- const integrations: RegulatedCommerceTruthFixture["integrations"] = [];
328
- for (let index = 0; index < inputs.length; index += 1) {
329
- const path = `fixture.integrations[${index}]`;
330
- const input = record(inputs[index], path);
331
- exactKeys(input, ["reference", "kind", "destination", "enabled"], path);
332
- const reference = string(ownDataValue(input, "reference"), `${path}.reference`);
333
- if (!INTEGRATION_REFERENCE.test(reference)) {
334
- fail(`${path}.reference`, "must use the closed synthetic integration-reference format");
335
- }
336
- const destination = string(ownDataValue(input, "destination"), `${path}.destination`);
337
- if (!FAKE_DESTINATION.test(destination)) {
338
- fail(`${path}.destination`, "must use the closed fake destination format");
339
- }
340
- const enabled = ownDataValue(input, "enabled");
341
- if (typeof enabled !== "boolean") fail(`${path}.enabled`, "expected a boolean");
342
- integrations.push({
343
- reference,
344
- kind: literal(ownDataValue(input, "kind"), "order-risk", `${path}.kind`),
345
- destination,
346
- enabled,
347
- });
348
- }
349
- return integrations;
350
- }
351
-
352
- function parseExpectedInvariant(value: unknown, path: string): ExpectedInvariant {
353
- const input = record(value, path);
354
- exactKeys(input, ["disposition", "violations"], path);
355
- const disposition = oneOf(
356
- ownDataValue(input, "disposition"),
357
- ["allow", "closed-failure"] as const,
358
- `${path}.disposition`,
359
- );
360
- const violationInputs = arrayDataValues(ownDataValue(input, "violations"), `${path}.violations`);
361
- const violations: Array<"age-verification-required"> = [];
362
- for (let index = 0; index < violationInputs.length; index += 1) {
363
- violations.push(
364
- literal(violationInputs[index], "age-verification-required", `${path}.violations[${index}]`),
365
- );
366
- }
367
- if (disposition === "allow") {
368
- if (violations.length !== 0) fail(`${path}.violations`, "allow must have no violations");
369
- return { disposition, violations: [] };
370
- }
371
- if (violations.length !== 1) {
372
- fail(`${path}.violations`, "closed-failure must contain the age-verification-required violation");
373
- }
374
- return { disposition, violations: ["age-verification-required"] };
375
- }
376
-
377
- function parseOrders(
378
- value: unknown,
379
- integrations: RegulatedCommerceTruthFixture["integrations"],
380
- ): RegulatedCommerceTruthFixture["orders"] {
381
- const inputs = arrayDataValues(value, "fixture.orders");
382
- if (inputs.length === 0) fail("fixture.orders", "at least one truth order is required");
383
- const integrationReferences = new Set<string>();
384
- for (const integration of integrations) integrationReferences.add(integration.reference);
385
- const orders: RegulatedCommerceTruthFixture["orders"] = [];
386
- for (let index = 0; index < inputs.length; index += 1) {
387
- const path = `fixture.orders[${index}]`;
388
- const input = record(inputs[index], path);
389
- exactKeys(
390
- input,
391
- [
392
- "orderReference",
393
- "integrationReference",
394
- "occurredAt",
395
- "status",
396
- "currency",
397
- "totalMinor",
398
- "destinationCountry",
399
- "regulatedItems",
400
- "compliance",
401
- "expectedInvariant",
402
- ],
403
- path,
404
- );
405
- const orderReference = string(ownDataValue(input, "orderReference"), `${path}.orderReference`);
406
- if (!ORDER_REFERENCE.test(orderReference)) {
407
- fail(`${path}.orderReference`, "must use the closed synthetic order-reference format");
408
- }
409
- const integrationReference = string(
410
- ownDataValue(input, "integrationReference"),
411
- `${path}.integrationReference`,
412
- );
413
- if (!integrationReferences.has(integrationReference)) {
414
- fail(`${path}.integrationReference`, "does not reference a declared integration");
415
- }
416
- const itemInputs = arrayDataValues(ownDataValue(input, "regulatedItems"), `${path}.regulatedItems`);
417
- if (itemInputs.length === 0) fail(`${path}.regulatedItems`, "at least one regulated item is required");
418
- const regulatedItems: RegulatedCommerceTruthFixture["orders"][number]["regulatedItems"] = [];
419
- for (let itemIndex = 0; itemIndex < itemInputs.length; itemIndex += 1) {
420
- const itemPath = `${path}.regulatedItems[${itemIndex}]`;
421
- const item = record(itemInputs[itemIndex], itemPath);
422
- exactKeys(item, ["sku", "category", "quantity", "unitPriceMinor"], itemPath);
423
- const sku = string(ownDataValue(item, "sku"), `${itemPath}.sku`);
424
- if (!SYNTHETIC_SKU.test(sku)) fail(`${itemPath}.sku`, "must use the closed synthetic SKU format");
425
- regulatedItems.push({
426
- sku,
427
- category: literal(ownDataValue(item, "category"), "age-restricted", `${itemPath}.category`),
428
- quantity: boundedInteger(
429
- ownDataValue(item, "quantity"),
430
- `${itemPath}.quantity`,
431
- 1,
432
- MAX_ITEM_QUANTITY,
433
- ),
434
- unitPriceMinor: boundedInteger(
435
- ownDataValue(item, "unitPriceMinor"),
436
- `${itemPath}.unitPriceMinor`,
437
- 1,
438
- MAX_MINOR_AMOUNT,
439
- ),
440
- });
441
- }
442
- const complianceInput = record(ownDataValue(input, "compliance"), `${path}.compliance`);
443
- exactKeys(complianceInput, ["ageVerification", "consentRecorded", "taxCollectedMinor"], `${path}.compliance`);
444
- const consentRecorded = ownDataValue(complianceInput, "consentRecorded");
445
- if (typeof consentRecorded !== "boolean") {
446
- fail(`${path}.compliance.consentRecorded`, "expected a boolean");
447
- }
448
- const compliance = {
449
- ageVerification: oneOf(
450
- ownDataValue(complianceInput, "ageVerification"),
451
- ["passed", "missing"] as const,
452
- `${path}.compliance.ageVerification`,
453
- ),
454
- consentRecorded,
455
- taxCollectedMinor: boundedInteger(
456
- ownDataValue(complianceInput, "taxCollectedMinor"),
457
- `${path}.compliance.taxCollectedMinor`,
458
- 0,
459
- MAX_MINOR_AMOUNT,
460
- ),
461
- };
462
- const status = oneOf(ownDataValue(input, "status"), ["paid", "closed"] as const, `${path}.status`);
463
- const expectedInvariant = parseExpectedInvariant(
464
- ownDataValue(input, "expectedInvariant"),
465
- `${path}.expectedInvariant`,
466
- );
467
- const shouldFailClosed = status === "closed" || compliance.ageVerification !== "passed";
468
- if (shouldFailClosed !== (expectedInvariant.disposition === "closed-failure")) {
469
- fail(`${path}.expectedInvariant`, "does not match the fixture's regulated-commerce facts");
470
- }
471
- orders.push({
472
- orderReference,
473
- integrationReference,
474
- occurredAt: isoTimestamp(ownDataValue(input, "occurredAt"), `${path}.occurredAt`),
475
- status,
476
- currency: literal(ownDataValue(input, "currency"), "USD", `${path}.currency`),
477
- totalMinor: boundedInteger(
478
- ownDataValue(input, "totalMinor"),
479
- `${path}.totalMinor`,
480
- 1,
481
- MAX_MINOR_AMOUNT,
482
- ),
483
- destinationCountry: literal(
484
- ownDataValue(input, "destinationCountry"),
485
- "US",
486
- `${path}.destinationCountry`,
487
- ),
488
- regulatedItems,
489
- compliance,
490
- expectedInvariant,
491
- });
492
- }
493
- return orders;
494
- }
495
-
496
- function deepFreeze<T>(value: T): T {
497
- if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
498
- Object.freeze(value);
499
- for (const child of Object.values(value)) deepFreeze(child);
500
- }
501
- return value;
502
- }
503
-
504
- function parseRegulatedCommerceTruth(value: unknown): Readonly<RegulatedCommerceTruthFixture> {
505
- assertSanitized(value);
506
- const input = record(value, "fixture");
507
- exactKeys(input, ["schemaVersion", "fixtureId", "synthetic", "capturedAt", "tenant", "integrations", "orders"], "fixture");
508
- const fixtureId = string(ownDataValue(input, "fixtureId"), "fixture.fixtureId");
509
- if (!FIXTURE_ID.test(fixtureId)) fail("fixture.fixtureId", "must use the closed synthetic fixture-id format");
510
- const integrations = parseIntegrations(ownDataValue(input, "integrations"));
511
- const parsed: RegulatedCommerceTruthFixture = {
512
- schemaVersion: literal(
513
- ownDataValue(input, "schemaVersion"),
514
- REGULATED_COMMERCE_TRUTH_SCHEMA,
515
- "fixture.schemaVersion",
516
- ),
517
- fixtureId,
518
- synthetic: literal(ownDataValue(input, "synthetic"), true, "fixture.synthetic"),
519
- capturedAt: isoTimestamp(ownDataValue(input, "capturedAt"), "fixture.capturedAt"),
520
- tenant: parseTenant(ownDataValue(input, "tenant")),
521
- integrations,
522
- orders: parseOrders(ownDataValue(input, "orders"), integrations),
523
- };
524
- return deepFreeze(parsed);
525
- }
526
-
527
- /** Validate unknown fixture input and return a detached, immutable truth snapshot. */
528
- export function loadRegulatedCommerceTruth(value: unknown): Readonly<RegulatedCommerceTruthFixture> {
529
- try {
530
- return parseRegulatedCommerceTruth(value);
531
- } catch (error) {
532
- if (error !== null && typeof error === "object" && VALIDATION_ERRORS.has(error)) throw error;
533
- throw new FixtureValidationError("Invalid regulated-commerce truth: input could not be safely inspected");
534
- }
535
- }
536
-
537
- /** Load the repository's canonical deterministic fixture as a fresh snapshot. */
538
- export function loadSyntheticRegulatedCommerceTruth(): Readonly<RegulatedCommerceTruthFixture> {
539
- return loadRegulatedCommerceTruth(FIXTURE_SOURCE);
540
- }