@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,28 +0,0 @@
1
- /**
2
- * Opaque customer hash — the `customerHash`
3
- * every order/attribution surface exposes instead of a raw customer id (see
4
- * `docs/private-apps/api-event-reference.md`'s PII-minimization matrix and
5
- * `contract/openapi.yaml`'s `Order.customerHash`).
6
- *
7
- * Stable per **(tenant, app-install)**: the same customer always resolves to
8
- * the same hash within one install, so an app stays internally consistent
9
- * across its own `order.created`/`order.fulfilled`/`attribution.finalized`
10
- * events. Deliberately NOT comparable across installs on the same tenant
11
- * (each install's hash is salted by its own `installId`) — two apps must
12
- * never be able to correlate the same customer against each other.
13
- *
14
- * Reuses `@tot/public-runtime`'s `sha256Hex` (Web Crypto, no `node:*`) rather
15
- * than a new hash primitive — same primitive `apps/credentials.ts` uses for
16
- * client-secret hashing.
17
- */
18
- import { sha256Hex } from "@tot/public-runtime";
19
-
20
- /**
21
- * Hash a raw (tenant-scoped) customer identifier into the opaque, per-install
22
- * `customerHash` the contract exposes. One-way — never reversible to the raw
23
- * `rawCustomerId`, and never logged/stored anywhere in its raw form by this
24
- * module's callers.
25
- */
26
- export function customerHash(tenantId: string, installId: string, rawCustomerId: string): Promise<string> {
27
- return sha256Hex(`${tenantId}:${installId}:${rawCustomerId}`);
28
- }
@@ -1,100 +0,0 @@
1
- /**
2
- * Idempotency-Key ledger. Backs the
3
- * `idempotency_keys` table `schema.ts` declares: the one real (not
4
- * presence-only) idempotency ledger in this codebase, and the one
5
- * `POST /attribution` (`docs/private-apps/contract/openapi.yaml`'s
6
- * `writeAttribution`) requires — a reused key with a body hash that doesn't
7
- * match the one first stored is a 409, not a silent overwrite or a second
8
- * row. Contrast the webhook replay endpoint (`webhooks/deliveries/{id}/replay.ts`),
9
- * which only checks the header's presence because it has no request body to
10
- * hash and no table backing it.
11
- *
12
- * Pure over the `Queryable` seam, same shape every other orders store uses.
13
- * Route-agnostic by design: `attribution.ts` is one caller, but any
14
- * idempotent write route can reuse this.
15
- */
16
- import { sha256Hex } from "@tot/public-runtime";
17
- import type { Queryable } from "../../../catalog/d1/catalog.js";
18
-
19
- export type IdempotencyCheck =
20
- | { status: "proceed" }
21
- | { status: "replay"; responseBody: unknown }
22
- | { status: "conflict" };
23
-
24
- interface IdempotencyKeyRow {
25
- install_id: string;
26
- idempotency_key: string;
27
- body_hash: string;
28
- response_body: string;
29
- created_at: string;
30
- }
31
-
32
- /**
33
- * Recursively sort object keys before `JSON.stringify` so two requests with
34
- * the same logical content — but different key order or whitespace — hash
35
- * identically. Arrays keep their order (order is meaningful there).
36
- */
37
- function canonicalize(value: unknown): unknown {
38
- if (Array.isArray(value)) return value.map(canonicalize);
39
- if (value !== null && typeof value === "object") {
40
- const sorted: Record<string, unknown> = {};
41
- for (const key of Object.keys(value as Record<string, unknown>).sort()) {
42
- sorted[key] = canonicalize((value as Record<string, unknown>)[key]);
43
- }
44
- return sorted;
45
- }
46
- return value;
47
- }
48
-
49
- /** Hash a request body into the `bodyHash` the ledger keys idempotency on. */
50
- export function computeBodyHash(body: unknown): Promise<string> {
51
- return sha256Hex(JSON.stringify(canonicalize(body)));
52
- }
53
-
54
- /**
55
- * Look up a prior `(installId, idempotencyKey)` write. A matching
56
- * `bodyHash` is a stable replay — the caller should return the ORIGINAL
57
- * response body, not re-run the write, so a retried request gets back
58
- * exactly what the first one produced. A mismatched `bodyHash` is a
59
- * conflict: the same key was reused for a genuinely different request. No
60
- * row at all is a green light to proceed.
61
- */
62
- export async function checkIdempotency(
63
- db: Queryable,
64
- installId: string,
65
- idempotencyKey: string,
66
- bodyHash: string,
67
- ): Promise<IdempotencyCheck> {
68
- const row = await db.first<IdempotencyKeyRow>(
69
- `SELECT * FROM idempotency_keys WHERE install_id = ? AND idempotency_key = ?`,
70
- installId,
71
- idempotencyKey,
72
- );
73
- if (!row) return { status: "proceed" };
74
- if (row.body_hash !== bodyHash) return { status: "conflict" };
75
- return { status: "replay", responseBody: JSON.parse(row.response_body) };
76
- }
77
-
78
- /**
79
- * Record a fresh `(installId, idempotencyKey)` write alongside the response
80
- * body a replay should return. Callers run this AFTER the write it guards
81
- * succeeds, never before — a failed write must leave no idempotency row
82
- * behind to (wrongly) short-circuit a legitimate retry.
83
- */
84
- export async function recordIdempotency(
85
- db: Queryable,
86
- installId: string,
87
- idempotencyKey: string,
88
- bodyHash: string,
89
- responseBody: unknown,
90
- ): Promise<void> {
91
- await db.run(
92
- `INSERT INTO idempotency_keys (install_id, idempotency_key, body_hash, response_body, created_at)
93
- VALUES (?,?,?,?,?)`,
94
- installId,
95
- idempotencyKey,
96
- bodyHash,
97
- JSON.stringify(responseBody),
98
- new Date().toISOString(),
99
- );
100
- }
@@ -1,96 +0,0 @@
1
- /**
2
- * The per-sku sold / unsold / velocity report behind `GET /api/apps/v1/reports`.
3
- *
4
- * Scoped to one tenant and one commerce stage. Sold units come from the paid orders in that stage's
5
- * order ledger whose placement falls inside the window (cancelled, voided and refunded orders do not
6
- * count); unsold units are the stage's projected availability balance; velocity is sold units per
7
- * day over the window; days of cover is unsold units over velocity (null when nothing sold).
8
- */
9
- import type { CommerceStage } from "@tot/public-runtime";
10
- import { readAvailabilityBalances } from "@/lib/inventory/mirrorStock.js";
11
- import { readLedgerContractOrderRecords } from "@/lib/orders/data/ledgerContractOrders.js";
12
- import { ScrappyOrderLedger } from "@/lib/orders/data/ordersStore.js";
13
-
14
- export const SALES_VELOCITY_REPORT_ID = "sales-velocity";
15
- export const DEFAULT_REPORT_WINDOW_DAYS = 30;
16
- export const MAX_REPORT_WINDOW_DAYS = 365;
17
-
18
- type Queryable = ConstructorParameters<typeof ScrappyOrderLedger>[0];
19
-
20
- const DAY_MS = 86_400_000;
21
-
22
- export interface SalesVelocitySku {
23
- sku: string;
24
- soldUnits: number;
25
- unsoldUnits: number;
26
- velocityPerDay: number;
27
- daysOfCover: number | null;
28
- }
29
-
30
- export interface SalesVelocityReport {
31
- id: typeof SALES_VELOCITY_REPORT_ID;
32
- title: string;
33
- generatedAt: string;
34
- format: "json";
35
- window: { days: number; from: string; to: string };
36
- skus: SalesVelocitySku[];
37
- }
38
-
39
- /** A valid `windowDays` query value, or null when it is not an integer in 1..MAX_REPORT_WINDOW_DAYS. */
40
- export function parseReportWindowDays(raw: string | null): number | null {
41
- if (raw === null) return DEFAULT_REPORT_WINDOW_DAYS;
42
- if (!/^[0-9]{1,4}$/.test(raw)) return null;
43
- const days = Number(raw);
44
- return days >= 1 && days <= MAX_REPORT_WINDOW_DAYS ? days : null;
45
- }
46
-
47
- function round(value: number, places: number): number {
48
- const factor = 10 ** places;
49
- return Math.round(value * factor) / factor;
50
- }
51
-
52
- export async function buildSalesVelocityReport(
53
- db: Queryable,
54
- input: { tenantId: string; stage: CommerceStage; windowDays: number; now: Date },
55
- ): Promise<SalesVelocityReport> {
56
- const toMs = input.now.getTime();
57
- const fromMs = toMs - input.windowDays * DAY_MS;
58
-
59
- const records = await readLedgerContractOrderRecords(
60
- new ScrappyOrderLedger(db),
61
- { tenantId: input.tenantId, stage: input.stage },
62
- async () => "",
63
- );
64
- const sold = new Map<string, number>();
65
- for (const { order } of records) {
66
- if (order.status === "cancelled") continue;
67
- const placedMs = Date.parse(order.createdAt);
68
- if (!Number.isFinite(placedMs) || placedMs < fromMs || placedMs > toMs) continue;
69
- for (const line of order.lineItems ?? []) {
70
- sold.set(line.sku, (sold.get(line.sku) ?? 0) + line.quantity);
71
- }
72
- }
73
-
74
- const balances = await readAvailabilityBalances(db, { tenantId: input.tenantId, stage: input.stage });
75
- const skus = [...new Set([...sold.keys(), ...balances.keys()])].sort();
76
-
77
- return {
78
- id: SALES_VELOCITY_REPORT_ID,
79
- title: "Sold, unsold and sales velocity by sku",
80
- generatedAt: input.now.toISOString(),
81
- format: "json",
82
- window: { days: input.windowDays, from: new Date(fromMs).toISOString(), to: input.now.toISOString() },
83
- skus: skus.map((sku) => {
84
- const soldUnits = sold.get(sku) ?? 0;
85
- const unsoldUnits = Math.max(0, balances.get(sku)?.balance ?? 0);
86
- const velocity = soldUnits / input.windowDays;
87
- return {
88
- sku,
89
- soldUnits,
90
- unsoldUnits,
91
- velocityPerDay: round(velocity, 4),
92
- daysOfCover: velocity > 0 ? round(unsoldUnits / velocity, 2) : null,
93
- };
94
- }),
95
- };
96
- }
@@ -1,45 +0,0 @@
1
- /**
2
- * operationParam — resolve the managed-analytics v1 `[operation]` path param
3
- * robustly on BOTH admin surfaces.
4
- *
5
- * On the host-routed surface Astro populates `context.params.operation` normally.
6
- * On the TENANT surface (`/<domain>/api/…`) the middleware selects the tenant by
7
- * path prefix and rewrites via `next(renderPath)` — and across that rewrite this
8
- * flat dynamic route comes back with an EMPTY `context.params` too (mirrors the
9
- * identical rewrite defect `changeIdParam` solves for the change routes;
10
- * `[operation].ts` is single-segment, so it has no nested-route case to worry
11
- * about).
12
- *
13
- * Fallback: parse the operation from the pathname tail, which is stable on both
14
- * surfaces and both sides of the rewrite (`request.url` is the original request,
15
- * unaffected by the rewrite — see tenantPreview.ts's `stripBasePath`). No static
16
- * sibling reaches this handler — Astro matches static routes first — so the tail
17
- * capture is unambiguous wherever this helper runs.
18
- */
19
- import type { APIContext } from "astro";
20
-
21
- const TAIL = /\/api\/integrations\/v1\/([^/]+)\/?$/;
22
-
23
- function fromPathname(pathname: string | undefined): string | undefined {
24
- if (!pathname) return undefined;
25
- const m = pathname.match(TAIL);
26
- if (!m?.[1]) return undefined;
27
- let id: string = m[1];
28
- try {
29
- id = decodeURIComponent(id);
30
- } catch {
31
- // keep the raw segment — the allowlist lookup downstream will refuse garbage
32
- }
33
- const trimmed = id.trim();
34
- return trimmed || undefined;
35
- }
36
-
37
- export function operationParam(context: APIContext): string | undefined {
38
- const fromParams = context.params.operation?.trim();
39
- if (fromParams) return fromParams;
40
- try {
41
- return fromPathname(new URL(context.request.url).pathname);
42
- } catch {
43
- return undefined;
44
- }
45
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * Cloudflare Queues adapter for the `WebhookDispatcher` seam — PrivateApps
3
- * epic, D4 (Chunk C). NOT V1's production path (see `dispatcher.ts`'s header
4
- * for the full `d4-design-resolutions` context + the `@astrojs/cloudflare` v14
5
- * investigation): `InMemoryDispatcher` is what actually runs deliveries today.
6
- * This file exists so the Queues-backed path is built and unit-tested ahead of
7
- * the infra decision to provision a real Queue — `getDispatcher.ts` only
8
- * selects it when `env.WEBHOOK_DELIVERY_QUEUE` is bound, and no such binding
9
- * is declared in `wrangler.toml` yet, so that branch is dead code for now.
10
- *
11
- * Local minimal interfaces below (not `@cloudflare/workers-types`, which
12
- * isn't a dependency here) mirror how `../d1/catalog.ts`'s `D1Like` avoids a
13
- * types dep on the real Cloudflare D1Database shape — same idea, for Queues.
14
- */
15
- import { computeBackoffDelaySeconds } from "./dispatcher.js";
16
- import type { DispatchJob, AttemptDeliveryFn, WebhookDispatcher } from "./dispatcher.js";
17
-
18
- /** The slice of a Cloudflare Queue producer binding we use. */
19
- export interface CloudflareQueueSender<Body = DispatchJob> {
20
- send(body: Body, options?: { delaySeconds?: number }): Promise<void>;
21
- }
22
-
23
- /** The slice of a Cloudflare Queue consumer message we use. */
24
- export interface CloudflareQueueMessage<Body = DispatchJob> {
25
- readonly body: Body;
26
- /** The queue's own native redelivery count (distinct from the delivery row's `attempts`). */
27
- readonly attempts: number;
28
- ack(): void;
29
- retry(options?: { delaySeconds?: number }): void;
30
- }
31
-
32
- /** The slice of a Cloudflare Queue consumer batch we use. */
33
- export interface CloudflareQueueBatch<Body = DispatchJob> {
34
- readonly messages: ReadonlyArray<CloudflareQueueMessage<Body>>;
35
- }
36
-
37
- /** `enqueue()` calls `env.WEBHOOK_DELIVERY_QUEUE.send()` — `notBefore` (if in the future) becomes the send's `delaySeconds`. */
38
- export class CloudflareQueueDispatcher implements WebhookDispatcher {
39
- constructor(private readonly queue: CloudflareQueueSender) {}
40
-
41
- async enqueue(job: DispatchJob): Promise<void> {
42
- const delaySeconds = job.notBefore ? secondsUntil(job.notBefore) : undefined;
43
- await this.queue.send(job, delaySeconds ? { delaySeconds } : undefined);
44
- }
45
- }
46
-
47
- function secondsUntil(iso: string): number | undefined {
48
- const ms = Date.parse(iso) - Date.now();
49
- return ms > 0 ? Math.ceil(ms / 1000) : undefined;
50
- }
51
-
52
- /**
53
- * The Queue CONSUMER logic a Worker `queue(batch, env, ctx)` export would call
54
- * per batch, once the entry-wiring TODO in `dispatcher.ts`'s header is
55
- * resolved — exported as a plain function (not tied to a `queue()` export
56
- * signature) so it's unit-testable against a fake batch/message with no real
57
- * Queues binding or Worker runtime involved.
58
- *
59
- * Judgment call: the retry delay uses `message.attempts` — the QUEUE's own
60
- * native redelivery counter — via `computeBackoffDelaySeconds`, not the
61
- * `nextAttemptAt` `attemptDelivery` already computed from the delivery row's
62
- * own attempt count. Those two counters normally march together, but a
63
- * message the queue redelivers for a reason unrelated to `attemptDelivery`
64
- * (e.g. an uncaught throw) would only bump `message.attempts`, not the row —
65
- * this keeps the seam correct against the queue's actual retry accounting.
66
- * `attemptDelivery` has already written the delivery's own terminal/interim
67
- * state to the store either way; `ack`/`retry` here only affect the QUEUE
68
- * message, never the delivery's own state.
69
- */
70
- export async function queue(batch: CloudflareQueueBatch, attempt: AttemptDeliveryFn): Promise<void> {
71
- for (const message of batch.messages) {
72
- const outcome = await attempt(message.body.deliveryId);
73
- if (outcome.kind === "retrying") {
74
- message.retry({ delaySeconds: computeBackoffDelaySeconds(message.attempts) });
75
- } else {
76
- // delivered, or dead-lettered (max attempts / install unavailable) —
77
- // the delivery's own state is already terminal; nothing more for the
78
- // queue to do with this message.
79
- message.ack();
80
- }
81
- }
82
- }
@@ -1,159 +0,0 @@
1
- /**
2
- * Payload admission for the commerce topics the single commerce emitter writes:
3
- * `fulfillment.assignment.created`, `fulfillment.assignment.updated`, `fulfillment.label.voided`, `order.fulfilled`,
4
- * `order.partially_fulfilled` and `inventory.changed`.
5
- *
6
- * Each topic has a closed key set (`asyncapi.yaml` `FulfillmentAssignmentData`, `OrderData`
7
- * and `InventoryChangedData`) and every payload also passes the private-identity check. Both
8
- * run when the event row is written and again before the delivery engine signs and POSTs it.
9
- */
10
- import type { WebhookTopic } from "./deliveryStore.js";
11
-
12
- export type CommerceTopic =
13
- | "fulfillment.assignment.created"
14
- | "fulfillment.assignment.updated"
15
- | "fulfillment.label.voided"
16
- | "order.paid"
17
- | "order.fulfilled"
18
- | "order.partially_fulfilled"
19
- | "order.cancelled"
20
- | "order.updated"
21
- | "inventory.changed";
22
-
23
- export const COMMERCE_TOPICS: readonly CommerceTopic[] = [
24
- "fulfillment.assignment.created",
25
- "fulfillment.assignment.updated",
26
- "fulfillment.label.voided",
27
- "order.paid",
28
- "order.fulfilled",
29
- "order.partially_fulfilled",
30
- "order.cancelled",
31
- "order.updated",
32
- "inventory.changed",
33
- ];
34
-
35
- /** Keys that identify a person or an address. None may appear at any depth of a commerce payload. */
36
- export const COMMERCE_PRIVATE_KEYS = new Set([
37
- "customer",
38
- "customerEmail",
39
- "customerName",
40
- "email",
41
- "phone",
42
- "line1",
43
- "line2",
44
- "city",
45
- "company",
46
- "postalCode",
47
- "shippingAddress",
48
- "billingAddress",
49
- "shipTo",
50
- "billTo",
51
- "address",
52
- "firstName",
53
- "lastName",
54
- "name",
55
- ]);
56
-
57
- const ASSIGNMENT_KEYS = ["assignmentId", "orderId", "stage", "state", "eventVersion", "occurredAt"] as const;
58
- const ASSIGNMENT_STATES = new Set(["active", "held", "cancelled"]);
59
- const LABEL_VOIDED_KEYS = ["assignmentId", "orderId", "purchaseId", "occurredAt"] as const;
60
- const ORDER_DATA_KEYS = new Set(["id", "status", "currency", "customerHash", "subtotal", "total", "lineItems"]);
61
- const LINE_ITEM_KEYS = new Set(["sku", "handle", "quantity", "lineTotal"]);
62
- export const INVENTORY_CHANGED_KEYS = ["sku", "locationId", "balance", "available", "asOf"] as const;
63
- const LOCATION_ID_RE = /^[A-Za-z0-9._:-]{1,128}$/;
64
-
65
- export function isCommerceTopic(topic: WebhookTopic): topic is CommerceTopic {
66
- return (COMMERCE_TOPICS as readonly string[]).includes(topic);
67
- }
68
-
69
- export function commercePayloadHasPrivateIdentity(value: unknown): boolean {
70
- if (value === null || typeof value !== "object") return false;
71
- if (Array.isArray(value)) return value.some((item) => commercePayloadHasPrivateIdentity(item));
72
- return Object.entries(value as Record<string, unknown>).some(
73
- ([key, child]) => COMMERCE_PRIVATE_KEYS.has(key) || commercePayloadHasPrivateIdentity(child),
74
- );
75
- }
76
-
77
- function isRecord(value: unknown): value is Record<string, unknown> {
78
- return typeof value === "object" && value !== null && !Array.isArray(value);
79
- }
80
-
81
- function nonEmptyString(value: unknown): value is string {
82
- return typeof value === "string" && value.length > 0 && value.length <= 256;
83
- }
84
-
85
- function assignmentAdmissible(topic: CommerceTopic, payload: Record<string, unknown>): boolean {
86
- const keys = Object.keys(payload);
87
- if (keys.length !== ASSIGNMENT_KEYS.length || !ASSIGNMENT_KEYS.every((key) => keys.includes(key))) return false;
88
- if (!nonEmptyString(payload.assignmentId) || !nonEmptyString(payload.orderId)) return false;
89
- if (payload.stage !== "preview" && payload.stage !== "publication") return false;
90
- if (typeof payload.state !== "string" || !ASSIGNMENT_STATES.has(payload.state)) return false;
91
- if (topic === "fulfillment.assignment.created" && payload.state !== "active") return false;
92
- if (!Number.isSafeInteger(payload.eventVersion) || Number(payload.eventVersion) < 0) return false;
93
- return typeof payload.occurredAt === "string" && Number.isFinite(Date.parse(payload.occurredAt));
94
- }
95
-
96
- function labelVoidedAdmissible(payload: Record<string, unknown>): boolean {
97
- const keys = Object.keys(payload);
98
- if (keys.length !== LABEL_VOIDED_KEYS.length || !LABEL_VOIDED_KEYS.every((key) => keys.includes(key))) return false;
99
- if (!nonEmptyString(payload.assignmentId) || !nonEmptyString(payload.orderId) || !nonEmptyString(payload.purchaseId)) return false;
100
- return typeof payload.occurredAt === "string" && Number.isFinite(Date.parse(payload.occurredAt));
101
- }
102
-
103
- /** `OrderData` with `status` in `allowedStatuses` and optional/required `lineItems`. */
104
- function orderDataAdmissible(
105
- payload: Record<string, unknown>,
106
- allowedStatuses: readonly ("created" | "fulfilled" | "cancelled")[],
107
- requireLineItems = false,
108
- ): boolean {
109
- if (Object.keys(payload).some((key) => !ORDER_DATA_KEYS.has(key))) return false;
110
- if (
111
- !nonEmptyString(payload.id) ||
112
- typeof payload.status !== "string" ||
113
- !(allowedStatuses as readonly string[]).includes(payload.status) ||
114
- !nonEmptyString(payload.currency)
115
- ) {
116
- return false;
117
- }
118
- if (payload.customerHash !== undefined && typeof payload.customerHash !== "string") return false;
119
- for (const key of ["subtotal", "total"] as const) {
120
- if (payload[key] !== undefined && (typeof payload[key] !== "number" || !Number.isFinite(payload[key]))) return false;
121
- }
122
- if (payload.lineItems === undefined) return !requireLineItems;
123
- if (!Array.isArray(payload.lineItems)) return false;
124
- if (requireLineItems && payload.lineItems.length === 0) return false;
125
- return payload.lineItems.every(
126
- (item) =>
127
- isRecord(item) &&
128
- Object.keys(item).every((key) => LINE_ITEM_KEYS.has(key)) &&
129
- nonEmptyString(item.sku) &&
130
- Number.isSafeInteger(item.quantity) &&
131
- (item.handle === undefined || typeof item.handle === "string") &&
132
- (item.lineTotal === undefined || (typeof item.lineTotal === "number" && Number.isFinite(item.lineTotal))),
133
- );
134
- }
135
-
136
- export function inventoryChangedAdmissible(payload: unknown): boolean {
137
- if (!isRecord(payload) || commercePayloadHasPrivateIdentity(payload)) return false;
138
- const keys = Object.keys(payload);
139
- if (keys.length !== INVENTORY_CHANGED_KEYS.length || !INVENTORY_CHANGED_KEYS.every((key) => keys.includes(key))) {
140
- return false;
141
- }
142
- if (!nonEmptyString(payload.sku) || payload.sku.trim() !== payload.sku) return false;
143
- if (typeof payload.locationId !== "string" || !LOCATION_ID_RE.test(payload.locationId)) return false;
144
- if (!Number.isSafeInteger(payload.balance) || !Number.isSafeInteger(payload.available)) return false;
145
- return typeof payload.asOf === "string" && Number.isFinite(Date.parse(payload.asOf));
146
- }
147
-
148
- /** True when `payload` is exactly the closed shape `topic` allows and carries no private identity. */
149
- export function commercePayloadAdmissible(topic: CommerceTopic, payload: unknown): boolean {
150
- if (!isRecord(payload) || commercePayloadHasPrivateIdentity(payload)) return false;
151
- if (topic === "order.paid") return orderDataAdmissible(payload, ["created", "fulfilled"], true);
152
- if (topic === "order.fulfilled") return orderDataAdmissible(payload, ["fulfilled"]);
153
- if (topic === "order.partially_fulfilled") return orderDataAdmissible(payload, ["created"]);
154
- if (topic === "order.cancelled") return orderDataAdmissible(payload, ["cancelled"], true);
155
- if (topic === "order.updated") return orderDataAdmissible(payload, ["created", "fulfilled", "cancelled"], true);
156
- if (topic === "inventory.changed") return inventoryChangedAdmissible(payload);
157
- if (topic === "fulfillment.label.voided") return labelVoidedAdmissible(payload);
158
- return assignmentAdmissible(topic, payload);
159
- }