@tokenoftrust/storefront-runner 7.3.1 → 7.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (414) 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 +147 -0
  13. package/apps/storefront/src/lib/access/auth/brokerAssertion.ts +67 -1
  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/auth/session.ts +79 -0
  17. package/apps/storefront/src/lib/access/dashboard/staffAdmission.ts +5 -0
  18. package/apps/storefront/src/lib/access/dashboard/tenantSelection.ts +2 -0
  19. package/apps/storefront/src/lib/access/shared/capability.ts +14 -6
  20. package/apps/storefront/src/lib/access/shared/generated/capabilityCatalog.generated.ts +161 -0
  21. package/apps/storefront/src/lib/activity/activityScope.ts +36 -0
  22. package/apps/storefront/src/lib/activity/recordActivity.ts +23 -1
  23. package/apps/storefront/src/lib/activity/serverFanOut.ts +31 -0
  24. package/apps/storefront/src/lib/activity/store.ts +9 -3
  25. package/apps/storefront/src/lib/checkout/commerce/cardCartForm.ts +2 -0
  26. package/apps/storefront/src/lib/checkout/commerce/cartSession.ts +109 -12
  27. package/apps/storefront/src/lib/checkout/commerce/checkoutHandoffRoute.ts +53 -25
  28. package/apps/storefront/src/lib/checkout/commerce/finalCartAuthorization.ts +48 -6
  29. package/apps/storefront/src/lib/checkout/proposal/cartProposal.ts +388 -0
  30. package/apps/storefront/src/lib/checkout/proposal/listMatcher.ts +149 -0
  31. package/apps/storefront/src/lib/checkout/proposal/proposalRoutes.ts +447 -0
  32. package/apps/storefront/src/lib/checkout/proposal/reviewHtml.ts +100 -0
  33. package/apps/storefront/src/lib/compliance/browser/checkoutVerificationFlow.ts +26 -2
  34. package/apps/storefront/src/lib/content/shared/redirects.ts +21 -4
  35. package/apps/storefront/src/lib/publication/shared/edgeCache.ts +5 -2
  36. package/apps/storefront/src/lib/publication/shared/previewAnnotations/renderDecorator.ts +15 -8
  37. package/apps/storefront/src/lib/publication/shared/runtimeEnv.ts +1 -1
  38. package/apps/storefront/src/middleware/controlPlane.ts +15 -1
  39. package/apps/storefront/src/middleware/index.ts +40 -1
  40. package/apps/storefront/src/middleware/renderChain.ts +46 -33
  41. package/apps/storefront/src/pages/api/cart-proposal/confirm.ts +12 -0
  42. package/apps/storefront/src/pages/api/cart-proposal/review.ts +26 -0
  43. package/apps/storefront/src/pages/api/commerce/final-cart-authorization.ts +29 -6
  44. package/apps/storefront/src/pages/api/compliance/preflight.ts +25 -1
  45. package/apps/storefront/src/pages/products/[handle].astro +2 -15
  46. package/apps/storefront/tsconfig.astro.json +11 -0
  47. package/package.json +1 -1
  48. package/packages/public-runtime/src/activity/README.md +12 -0
  49. package/packages/public-runtime/src/activity/catalog.ts +7 -0
  50. package/packages/public-runtime/src/activity/event.ts +19 -0
  51. package/packages/public-runtime/src/activity/redaction.ts +31 -2
  52. package/packages/public-runtime/src/catalog-files.ts +3 -2
  53. package/packages/public-runtime/src/checkout-orders.ts +18 -19
  54. package/packages/public-runtime/src/checkout.ts +70 -0
  55. package/packages/public-runtime/src/compliance/evaluate.ts +60 -1
  56. package/packages/public-runtime/src/compliance/index.ts +1 -1
  57. package/packages/public-runtime/src/compliance/pact-report.ts +184 -3
  58. package/packages/public-runtime/src/compliance/profile.ts +268 -20
  59. package/packages/public-runtime/src/compliance/ruleset.ts +42 -0
  60. package/packages/public-runtime/src/customization-runtime.ts +1 -1
  61. package/packages/public-runtime/src/product.ts +9 -1
  62. package/packages/public-runtime/src/publication-content-redirects.ts +16 -3
  63. package/packages/public-runtime/tests/fixtures/compliance-decisions.golden.json +252 -52
  64. package/pnpm-lock.runner.yaml +0 -15
  65. package/scripts/tenant/materialize-tenant-content.mjs +3 -0
  66. package/scripts/tenant/validate.mjs +128 -0
  67. package/apps/storefront/dev-plugins/dev-publish.mjs +0 -55
  68. package/apps/storefront/drizzle.config.apps.ts +0 -13
  69. package/apps/storefront/integrations/preview-annotations-client-bundle.mjs +0 -80
  70. package/apps/storefront/migrations-apps/0000_fast_millenium_guard.sql +0 -129
  71. package/apps/storefront/migrations-apps/0001_woozy_lyja.sql +0 -22
  72. package/apps/storefront/migrations-apps/0002_good_switch.sql +0 -26
  73. package/apps/storefront/migrations-apps/0003_mute_marauders.sql +0 -12
  74. package/apps/storefront/migrations-apps/0004_deep_morph.sql +0 -36
  75. package/apps/storefront/migrations-apps/0005_common_mystique.sql +0 -23
  76. package/apps/storefront/migrations-apps/0006_broad_microchip.sql +0 -16
  77. package/apps/storefront/migrations-apps/0007_brave_outlaw_kid.sql +0 -15
  78. package/apps/storefront/migrations-apps/0008_blue_dazzler.sql +0 -11
  79. package/apps/storefront/migrations-apps/0009_bored_shinobi_shaw.sql +0 -15
  80. package/apps/storefront/migrations-apps/0010_ws4_verified_provider_measurement.sql +0 -35
  81. package/apps/storefront/migrations-apps/0011_dt_tracking_tenant_databases.sql +0 -23
  82. package/apps/storefront/migrations-apps/0012_test_destinations.sql +0 -29
  83. package/apps/storefront/migrations-apps/0013_publication_space_editorial.sql +0 -64
  84. package/apps/storefront/migrations-apps/0014_retire_candidate_ledger.sql +0 -12
  85. package/apps/storefront/migrations-apps/0015_merchant_calculation_settings.sql +0 -31
  86. package/apps/storefront/migrations-apps/0016_scrappy_commerce_contract.sql +0 -166
  87. package/apps/storefront/migrations-apps/0017_commerce_durable_projection.sql +0 -28
  88. package/apps/storefront/migrations-apps/0018_commerce_provider_cart_identity.sql +0 -13
  89. package/apps/storefront/migrations-apps/0019_commerce_source_authority.sql +0 -23
  90. package/apps/storefront/migrations-apps/0020_contact_messages.sql +0 -18
  91. package/apps/storefront/migrations-apps/0021_contact_vault.sql +0 -166
  92. package/apps/storefront/migrations-apps/0022_contact_vault_fields.sql +0 -342
  93. package/apps/storefront/migrations-apps/0023_principal_grant_contacts.sql +0 -15
  94. package/apps/storefront/migrations-apps/0024_order_contact_erasure_state.sql +0 -22
  95. package/apps/storefront/migrations-apps/0025_shipment_audit_order_lookup.sql +0 -2
  96. package/apps/storefront/migrations-apps/0026_fulfillment_assignment.sql +0 -44
  97. package/apps/storefront/migrations-apps/0027_app_contact_authority.sql +0 -70
  98. package/apps/storefront/migrations-apps/0028_app_jwk_and_candidates.sql +0 -133
  99. package/apps/storefront/migrations-apps/0029_inventory_locations_wms.sql +0 -38
  100. package/apps/storefront/migrations-apps/0030_assignment_split_shipments.sql +0 -149
  101. package/apps/storefront/migrations-apps/meta/0000_snapshot.json +0 -843
  102. package/apps/storefront/migrations-apps/meta/0001_snapshot.json +0 -990
  103. package/apps/storefront/migrations-apps/meta/0002_snapshot.json +0 -1160
  104. package/apps/storefront/migrations-apps/meta/0003_snapshot.json +0 -1235
  105. package/apps/storefront/migrations-apps/meta/0004_snapshot.json +0 -1474
  106. package/apps/storefront/migrations-apps/meta/0005_snapshot.json +0 -1617
  107. package/apps/storefront/migrations-apps/meta/0006_snapshot.json +0 -1716
  108. package/apps/storefront/migrations-apps/meta/0007_snapshot.json +0 -1812
  109. package/apps/storefront/migrations-apps/meta/0008_snapshot.json +0 -1881
  110. package/apps/storefront/migrations-apps/meta/0009_snapshot.json +0 -1979
  111. package/apps/storefront/migrations-apps/meta/_journal.json +0 -76
  112. package/apps/storefront/perf/README.md +0 -64
  113. package/apps/storefront/perf/assert-budgets.ts +0 -159
  114. package/apps/storefront/platform-reconcile-tenants.json +0 -3
  115. package/apps/storefront/playwright.config.ts +0 -23
  116. package/apps/storefront/public/js/dashboard-access-banner.js +0 -53
  117. package/apps/storefront/public/js/dashboard-apps.js +0 -183
  118. package/apps/storefront/public/js/dashboard-contact-capture.js +0 -52
  119. package/apps/storefront/public/js/dashboard-delegate.js +0 -167
  120. package/apps/storefront/public/js/dashboard-team.js +0 -356
  121. package/apps/storefront/public/js/dashboard-vendor-search.js +0 -115
  122. package/apps/storefront/src/components/content/storefront/AsyncStylesheet.astro +0 -26
  123. package/apps/storefront/src/components/integrations/storefront/WidgetFrame.astro +0 -34
  124. package/apps/storefront/src/config/adminTenantLookup.ts +0 -35
  125. package/apps/storefront/src/config/evidenceTenantRoster.ts +0 -25
  126. package/apps/storefront/src/config/staffProvisionProjection.ts +0 -24
  127. package/apps/storefront/src/config/storeName.ts +0 -34
  128. package/apps/storefront/src/lib/access/admin/README.md +0 -122
  129. package/apps/storefront/src/lib/access/admin/adminShell.ts +0 -281
  130. package/apps/storefront/src/lib/access/admin/envelope.ts +0 -9
  131. package/apps/storefront/src/lib/access/admin/viewmodels/settings.ts +0 -64
  132. package/apps/storefront/src/lib/access/auth/adminApiGuard.ts +0 -66
  133. package/apps/storefront/src/lib/access/auth/adminEntry.ts +0 -126
  134. package/apps/storefront/src/lib/access/auth/mcpClientAssertion.ts +0 -217
  135. package/apps/storefront/src/lib/access/auth/operatorSession.ts +0 -120
  136. package/apps/storefront/src/lib/access/dashboard/delegateGate.ts +0 -130
  137. package/apps/storefront/src/lib/access/dashboard/staffStoreEntry.ts +0 -150
  138. package/apps/storefront/src/lib/access/dashboard/staffVendorAccess.ts +0 -452
  139. package/apps/storefront/src/lib/access/dashboard/vendorQuery.ts +0 -61
  140. package/apps/storefront/src/lib/access/fixtures/settings.ts +0 -67
  141. package/apps/storefront/src/lib/access/fixtures/tenants.ts +0 -29
  142. package/apps/storefront/src/lib/access/notifications/magicLinkInviteEmail.ts +0 -62
  143. package/apps/storefront/src/lib/access/shared/grantContactLookup.ts +0 -97
  144. package/apps/storefront/src/lib/access/shared/principalGrants.ts +0 -775
  145. package/apps/storefront/src/lib/activity/alerts.ts +0 -426
  146. package/apps/storefront/src/lib/activity/candidateSubmitLease.ts +0 -87
  147. package/apps/storefront/src/lib/activity/changeActorAttribution.ts +0 -181
  148. package/apps/storefront/src/lib/activity/evidence/evidenceReference.ts +0 -32
  149. package/apps/storefront/src/lib/activity/fixtures/evidence.ts +0 -99
  150. package/apps/storefront/src/lib/activity/query.ts +0 -403
  151. package/apps/storefront/src/lib/activity/uiActor.ts +0 -152
  152. package/apps/storefront/src/lib/admin/services/mock/index.ts +0 -12
  153. package/apps/storefront/src/lib/assets/addons/catalog.ts +0 -60
  154. package/apps/storefront/src/lib/assets/addons/storeEntitlements.ts +0 -260
  155. package/apps/storefront/src/lib/assets/durableAssetsRoute.ts +0 -65
  156. package/apps/storefront/src/lib/assets/durableR2.ts +0 -473
  157. package/apps/storefront/src/lib/assets/durableR2Bindings.ts +0 -33
  158. package/apps/storefront/src/lib/automation/admin/viewmodels/aiWorkflows.ts +0 -65
  159. package/apps/storefront/src/lib/automation/ai/approvalMode.ts +0 -20
  160. package/apps/storefront/src/lib/automation/ai/askEnvelope.ts +0 -47
  161. package/apps/storefront/src/lib/automation/ai/audit.ts +0 -12
  162. package/apps/storefront/src/lib/automation/ai/operationalRuns.ts +0 -155
  163. package/apps/storefront/src/lib/automation/ai/recommendation.ts +0 -20
  164. package/apps/storefront/src/lib/automation/fixtures/aiWorkflows.ts +0 -59
  165. package/apps/storefront/src/lib/catalog/admin/catalogSettingsClient.ts +0 -250
  166. package/apps/storefront/src/lib/catalog/admin/catalogSettingsFields.ts +0 -134
  167. package/apps/storefront/src/lib/catalog/admin/catalogSettingsPreview.ts +0 -37
  168. package/apps/storefront/src/lib/catalog/admin/catalogSettingsPricingView.ts +0 -39
  169. package/apps/storefront/src/lib/catalog/admin/catalogSettingsRuleView.ts +0 -44
  170. package/apps/storefront/src/lib/catalog/admin/catalogSettingsSkuView.ts +0 -21
  171. package/apps/storefront/src/lib/catalog/admin/catalogSettingsState.ts +0 -132
  172. package/apps/storefront/src/lib/catalog/admin/productSetupPhoto.ts +0 -23
  173. package/apps/storefront/src/lib/catalog/admin/productsTabClient.ts +0 -193
  174. package/apps/storefront/src/lib/catalog/admin/services/catalogProducts.ts +0 -32
  175. package/apps/storefront/src/lib/catalog/admin/viewmodels/catalogProducts.ts +0 -164
  176. package/apps/storefront/src/lib/catalog/admin/viewmodels/products.ts +0 -267
  177. package/apps/storefront/src/lib/catalog/fixtures/products.ts +0 -105
  178. package/apps/storefront/src/lib/catalog/tot/syncState.ts +0 -111
  179. package/apps/storefront/src/lib/checkout/admin/checkoutStyleInput.ts +0 -172
  180. package/apps/storefront/src/lib/checkout/admin/checkoutStyleTarget.ts +0 -65
  181. package/apps/storefront/src/lib/checkout/browser/checkoutExciseForm.ts +0 -152
  182. package/apps/storefront/src/lib/checkout/browser/checkoutRequirementsForm.ts +0 -72
  183. package/apps/storefront/src/lib/checkout/browser/checkoutStyleForm.ts +0 -110
  184. package/apps/storefront/src/lib/checkout/browser/settingDraftActions.ts +0 -367
  185. package/apps/storefront/src/lib/checkout/commerce/checkoutSettings.ts +0 -246
  186. package/apps/storefront/src/lib/checkout/fixtures/checkoutSettings.ts +0 -77
  187. package/apps/storefront/src/lib/content/blog/markdown.ts +0 -174
  188. package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome-assignments.example.json +0 -6
  189. package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome.example.json +0 -79
  190. package/apps/storefront/src/lib/content/index.ts +0 -27
  191. package/apps/storefront/src/lib/content/the-build/readingTime.ts +0 -35
  192. package/apps/storefront/src/lib/content/the-build/toc.ts +0 -95
  193. package/apps/storefront/src/lib/customers/admin/viewmodels/customers.ts +0 -56
  194. package/apps/storefront/src/lib/customers/contactVault/blindIndex.ts +0 -28
  195. package/apps/storefront/src/lib/customers/contactVault/contactAudit.ts +0 -149
  196. package/apps/storefront/src/lib/customers/contactVault/dataKeys.ts +0 -283
  197. package/apps/storefront/src/lib/customers/contactVault/fieldEnvelope.ts +0 -88
  198. package/apps/storefront/src/lib/customers/contactVault/isolateMetrics.ts +0 -37
  199. package/apps/storefront/src/lib/customers/contactVault/kms.ts +0 -292
  200. package/apps/storefront/src/lib/customers/contactVault/retention.ts +0 -302
  201. package/apps/storefront/src/lib/customers/contactVault/retentionPolicy.ts +0 -290
  202. package/apps/storefront/src/lib/customers/contactVault/zip3.ts +0 -24
  203. package/apps/storefront/src/lib/customers/fixtures/customers.ts +0 -86
  204. package/apps/storefront/src/lib/developer-experience/admin/memoizeByEnvelope.ts +0 -27
  205. package/apps/storefront/src/lib/developer-experience/admin/seed.ts +0 -54
  206. package/apps/storefront/src/lib/developer-experience/dev/activityIngestToken.ts +0 -85
  207. package/apps/storefront/src/lib/developer-experience/dev/activityStore.ts +0 -82
  208. package/apps/storefront/src/lib/developer-experience/dev/ai-widget-client.js +0 -308
  209. package/apps/storefront/src/lib/developer-experience/dev/apiBase.ts +0 -17
  210. package/apps/storefront/src/lib/developer-experience/dev/cliSignInCode.ts +0 -124
  211. package/apps/storefront/src/lib/developer-experience/dev/cockpit/ask.ts +0 -49
  212. package/apps/storefront/src/lib/developer-experience/dev/cockpit/clickToSource.ts +0 -71
  213. package/apps/storefront/src/lib/developer-experience/dev/cockpit/copyCommand.ts +0 -227
  214. package/apps/storefront/src/lib/developer-experience/dev/cockpit/files.ts +0 -249
  215. package/apps/storefront/src/lib/developer-experience/dev/cockpit/hostedActivity.ts +0 -500
  216. package/apps/storefront/src/lib/developer-experience/dev/cockpit/infoPopover.ts +0 -12
  217. package/apps/storefront/src/lib/developer-experience/dev/cockpit/mcpCopy.ts +0 -34
  218. package/apps/storefront/src/lib/developer-experience/dev/cockpit/monitor.ts +0 -107
  219. package/apps/storefront/src/lib/developer-experience/dev/cockpit/stepper.ts +0 -116
  220. package/apps/storefront/src/lib/developer-experience/dev/cockpit/themeToggle.ts +0 -23
  221. package/apps/storefront/src/lib/developer-experience/dev/livePreview.ts +0 -77
  222. package/apps/storefront/src/lib/developer-experience/dev/obstacleStore.ts +0 -214
  223. package/apps/storefront/src/lib/developer-experience/dev/previewStatus.ts +0 -87
  224. package/apps/storefront/src/lib/developer-experience/dev/rendezvousBroker.ts +0 -226
  225. package/apps/storefront/src/lib/developer-experience/dev/runtimeStore.ts +0 -291
  226. package/apps/storefront/src/lib/developer-experience/dev/storeStatus.ts +0 -142
  227. package/apps/storefront/src/lib/developer-experience/dev/subjectReissue.ts +0 -67
  228. package/apps/storefront/src/lib/developer-experience/fixtures/regulated-commerce-truth/index.ts +0 -540
  229. package/apps/storefront/src/lib/developer-experience/fixtures/ws3-readonly-clone-preflight/index.ts +0 -495
  230. package/apps/storefront/src/lib/engagement/contact/contactMessages.ts +0 -671
  231. package/apps/storefront/src/lib/engagement/contact/messagesTabClient.ts +0 -175
  232. package/apps/storefront/src/lib/engagement/contact/submission.ts +0 -112
  233. package/apps/storefront/src/lib/engagement/messaging/messagesClient.ts +0 -149
  234. package/apps/storefront/src/lib/engagement/newsletter/digest.ts +0 -117
  235. package/apps/storefront/src/lib/engagement/newsletter/resendClient.ts +0 -79
  236. package/apps/storefront/src/lib/engagement/newsletter/send.ts +0 -265
  237. package/apps/storefront/src/lib/engagement/social/golive.ts +0 -212
  238. package/apps/storefront/src/lib/engagement/social/notify.ts +0 -32
  239. package/apps/storefront/src/lib/engagement/social/tokenStore.ts +0 -171
  240. package/apps/storefront/src/lib/fulfillment/admin/commerceDesk.ts +0 -180
  241. package/apps/storefront/src/lib/fulfillment/admin/commerceDeskRouting.ts +0 -45
  242. package/apps/storefront/src/lib/fulfillment/admin/viewmodels/fulfillment.ts +0 -1071
  243. package/apps/storefront/src/lib/fulfillment/appShipmentEvidence.ts +0 -271
  244. package/apps/storefront/src/lib/fulfillment/carrierEvidence.ts +0 -105
  245. package/apps/storefront/src/lib/fulfillment/commerceProjection.ts +0 -157
  246. package/apps/storefront/src/lib/fulfillment/commerceReadback.ts +0 -60
  247. package/apps/storefront/src/lib/fulfillment/commerceRecovery.ts +0 -84
  248. package/apps/storefront/src/lib/fulfillment/commerceRuntime.ts +0 -41
  249. package/apps/storefront/src/lib/fulfillment/fulfillmentService.ts +0 -2842
  250. package/apps/storefront/src/lib/fulfillment/readiness.ts +0 -217
  251. package/apps/storefront/src/lib/fulfillment/splitShipments.ts +0 -388
  252. package/apps/storefront/src/lib/fulfillment/syntheticPreviewOrders.ts +0 -292
  253. package/apps/storefront/src/lib/integrations/apps/appContactAuthority.ts +0 -27
  254. package/apps/storefront/src/lib/integrations/apps/appContactConsents.ts +0 -118
  255. package/apps/storefront/src/lib/integrations/apps/appInstallEnv.ts +0 -28
  256. package/apps/storefront/src/lib/integrations/apps/gtmMigrationDraft.ts +0 -103
  257. package/apps/storefront/src/lib/integrations/apps/inventoryWrite.ts +0 -906
  258. package/apps/storefront/src/lib/integrations/apps/orders/customerHash.ts +0 -28
  259. package/apps/storefront/src/lib/integrations/apps/orders/idempotency.ts +0 -100
  260. package/apps/storefront/src/lib/integrations/apps/reports/salesVelocityReport.ts +0 -96
  261. package/apps/storefront/src/lib/integrations/apps/routeParams.ts +0 -45
  262. package/apps/storefront/src/lib/integrations/webhooks/cloudflareQueueDispatcher.ts +0 -82
  263. package/apps/storefront/src/lib/integrations/webhooks/commercePayloads.ts +0 -159
  264. package/apps/storefront/src/lib/integrations/webhooks/deliveryEngine.ts +0 -379
  265. package/apps/storefront/src/lib/integrations/webhooks/deliveryMapper.ts +0 -34
  266. package/apps/storefront/src/lib/integrations/webhooks/deliveryStore.ts +0 -903
  267. package/apps/storefront/src/lib/integrations/webhooks/dispatcher.ts +0 -168
  268. package/apps/storefront/src/lib/integrations/webhooks/emit.ts +0 -245
  269. package/apps/storefront/src/lib/integrations/webhooks/events.ts +0 -105
  270. package/apps/storefront/src/lib/integrations/webhooks/getDispatcher.ts +0 -77
  271. package/apps/storefront/src/lib/integrations/webhooks/orderFulfilledClaim.ts +0 -75
  272. package/apps/storefront/src/lib/measurement/admin/analyticsRegionPolicy.ts +0 -151
  273. package/apps/storefront/src/lib/measurement/admin/analyticsRegionsClient.ts +0 -84
  274. package/apps/storefront/src/lib/measurement/admin/consentSettingsClient.ts +0 -113
  275. package/apps/storefront/src/lib/measurement/analytics/index.ts +0 -44
  276. package/apps/storefront/src/lib/measurement/attribution/attributionService.ts +0 -206
  277. package/apps/storefront/src/lib/measurement/attribution/orderConversionD1.ts +0 -150
  278. package/apps/storefront/src/lib/measurement/attribution/verifiedProviderMeasurement.ts +0 -118
  279. package/apps/storefront/src/lib/measurement/tracking/interactionCollector.ts +0 -205
  280. package/apps/storefront/src/lib/measurement/tracking/pruneRollup.ts +0 -260
  281. package/apps/storefront/src/lib/measurement/tracking/tenantReadAccess.ts +0 -138
  282. package/apps/storefront/src/lib/measurement/tracking-writeback/rewriteTrackingIds.ts +0 -175
  283. package/apps/storefront/src/lib/measurement/tracking-writeback/writebackCandidate.ts +0 -110
  284. package/apps/storefront/src/lib/observability/diag/capture.ts +0 -162
  285. package/apps/storefront/src/lib/observability/diag/consoleLine.ts +0 -76
  286. package/apps/storefront/src/lib/observability/diag/debugConsole.ts +0 -118
  287. package/apps/storefront/src/lib/observability/diag/debugMode.ts +0 -163
  288. package/apps/storefront/src/lib/observability/diag/debugWindow.ts +0 -111
  289. package/apps/storefront/src/lib/observability/diag/redact.ts +0 -17
  290. package/apps/storefront/src/lib/observability/diag/reference.ts +0 -148
  291. package/apps/storefront/src/lib/observability/diag/referenceStore.ts +0 -113
  292. package/apps/storefront/src/lib/observability/diag/report.ts +0 -110
  293. package/apps/storefront/src/lib/observability/diag/serverResponseTime.ts +0 -91
  294. package/apps/storefront/src/lib/observability/diag/session.ts +0 -93
  295. package/apps/storefront/src/lib/observability/monitoring/manifest.ts +0 -301
  296. package/apps/storefront/src/lib/observability/performance/lighthouseReport.ts +0 -109
  297. package/apps/storefront/src/lib/observability/performance/rumAlert.ts +0 -179
  298. package/apps/storefront/src/lib/orders/admin/orderActions.ts +0 -556
  299. package/apps/storefront/src/lib/orders/admin/orderClient.ts +0 -248
  300. package/apps/storefront/src/lib/orders/admin/orderSource.ts +0 -410
  301. package/apps/storefront/src/lib/orders/admin/services/orders.ts +0 -922
  302. package/apps/storefront/src/lib/orders/admin/viewmodels/orders.ts +0 -135
  303. package/apps/storefront/src/lib/orders/data/commerceCallerConfig.ts +0 -37
  304. package/apps/storefront/src/lib/orders/data/ledgerContractOrders.ts +0 -148
  305. package/apps/storefront/src/lib/orders/data/orderForwardReceiver.ts +0 -532
  306. package/apps/storefront/src/lib/orders/data/orderMapper.ts +0 -454
  307. package/apps/storefront/src/lib/orders/data/ordersStore.ts +0 -623
  308. package/apps/storefront/src/lib/orders/data/sourceAuthorityContract.ts +0 -380
  309. package/apps/storefront/src/lib/orders/data/sourceAuthorityStore.ts +0 -830
  310. package/apps/storefront/src/lib/orders/fixtures/orders.ts +0 -186
  311. package/apps/storefront/src/lib/orders/providers/foxyOrderClient.ts +0 -207
  312. package/apps/storefront/src/lib/orders/vault/appRecipientRead.ts +0 -222
  313. package/apps/storefront/src/lib/orders/vault/contactIntake.ts +0 -63
  314. package/apps/storefront/src/lib/orders/vault/contactRoutes.ts +0 -110
  315. package/apps/storefront/src/lib/orders/vault/kmsEnv.ts +0 -11
  316. package/apps/storefront/src/lib/orders/vault/orderContact.ts +0 -96
  317. package/apps/storefront/src/lib/orders/vault/orderContactVault.ts +0 -1427
  318. package/apps/storefront/src/lib/orders/vault/vault-test-support.ts +0 -258
  319. package/apps/storefront/src/lib/publication/d1/schema-apps.ts +0 -808
  320. package/apps/storefront/src/lib/publication/notifications/candidateConflictEmail.ts +0 -80
  321. package/apps/storefront/src/lib/publication/servingMode.ts +0 -52
  322. package/apps/storefront/src/lib/publication/shared/previewAnnotations/moduleAsset.ts +0 -65
  323. package/apps/storefront/src/lib/publication/shared/routedApiParam.ts +0 -38
  324. package/apps/storefront/src/lib/reporting/admin/viewmodels/reporting.ts +0 -34
  325. package/apps/storefront/src/lib/reporting/fixtures/reporting.ts +0 -51
  326. package/apps/storefront/src/lib/subscriptions/admin/viewmodels/subscriptions.ts +0 -106
  327. package/apps/storefront/src/lib/subscriptions/fixtures/subscriptions.ts +0 -398
  328. package/apps/storefront/src/pages/api/admin/activity-alerts.ts +0 -58
  329. package/apps/storefront/src/pages/api/admin/commerce-readiness.ts +0 -172
  330. package/apps/storefront/src/pages/api/admin/fulfillment/batches.ts +0 -59
  331. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id]/address.ts +0 -66
  332. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id].ts +0 -118
  333. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contact-search.ts +0 -26
  334. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contacts.ts +0 -22
  335. package/apps/storefront/src/pages/api/admin/interaction-insights.ts +0 -101
  336. package/apps/storefront/src/pages/api/admin/orders/[id].ts +0 -63
  337. package/apps/storefront/src/pages/api/admin/orders.ts +0 -65
  338. package/apps/storefront/src/pages/api/contact.ts +0 -144
  339. package/apps/storefront/src/scheduled/contactVaultSweep.ts +0 -113
  340. package/apps/storefront/src/styles/admin.css +0 -1161
  341. package/apps/storefront/test/pipeline/fake-preview-services.ts +0 -288
  342. package/apps/storefront/test/pipeline/harness.ts +0 -209
  343. package/apps/storefront/test/pipeline/intake-worker.mjs +0 -14
  344. package/apps/storefront/test/pipeline/matrix-faults.ts +0 -366
  345. package/apps/storefront/test/pipeline/pipeline-host.ts +0 -418
  346. package/apps/storefront/test/pipeline/pool-config.cjs +0 -85
  347. package/apps/storefront/test/pipeline/publish-kinds.ts +0 -279
  348. package/apps/storefront/test/pipeline/synthetic-job.ts +0 -303
  349. package/apps/storefront/test/pipeline-faults/matrix-lib.ts +0 -696
  350. package/apps/storefront/vitest.config.cts +0 -44
  351. package/apps/storefront/vitest.faults.config.cts +0 -13
  352. package/apps/storefront/vitest.workers.config.cts +0 -7
  353. package/packages/feedback/fixtures/v1/expected-findings.json +0 -16
  354. package/packages/feedback/fixtures/v1/feedback-action/invalid/carries-transport-credential.json +0 -14
  355. package/packages/feedback/fixtures/v1/feedback-action/invalid/control-char-in-description.json +0 -13
  356. package/packages/feedback/fixtures/v1/feedback-action/invalid/legacy-schema-version.json +0 -13
  357. package/packages/feedback/fixtures/v1/feedback-action/invalid/page-path-with-query.json +0 -14
  358. package/packages/feedback/fixtures/v1/feedback-action/invalid/title-too-short.json +0 -13
  359. package/packages/feedback/fixtures/v1/feedback-action/valid/element-problem.json +0 -33
  360. package/packages/feedback/fixtures/v1/feedback-action/valid/page-comment.json +0 -20
  361. package/packages/feedback/fixtures/v1/feedback-action/valid/region-improvement.json +0 -24
  362. package/packages/feedback/fixtures/v1/feedback-action/valid/text-selection-feature.json +0 -30
  363. package/packages/feedback/fixtures/v1/submission-receipt/invalid/accepted-at-not-utc.json +0 -9
  364. package/packages/feedback/fixtures/v1/submission-receipt/invalid/bad-feedback-id.json +0 -9
  365. package/packages/feedback/fixtures/v1/submission-receipt/invalid/legacy-contract-version.json +0 -9
  366. package/packages/feedback/fixtures/v1/submission-receipt/invalid/missing-replayed.json +0 -8
  367. package/packages/feedback/fixtures/v1/submission-receipt/valid/accepted.json +0 -9
  368. package/packages/feedback/fixtures/v1/submission-receipt/valid/fractional-seconds.json +0 -9
  369. package/packages/feedback/fixtures/v1/submission-receipt/valid/replayed.json +0 -9
  370. package/packages/feedback/fixtures/v1/target-evidence/invalid/page-kind-claims-structure.json +0 -6
  371. package/packages/feedback/fixtures/v1/target-evidence/invalid/path-too-deep.json +0 -17
  372. package/packages/feedback/fixtures/v1/target-evidence/invalid/relative-region-out-of-range.json +0 -11
  373. package/packages/feedback/fixtures/v1/target-evidence/invalid/selector-uses-class.json +0 -7
  374. package/packages/feedback/fixtures/v1/target-evidence/invalid/source-precision-without-anchor.json +0 -6
  375. package/packages/feedback/fixtures/v1/target-evidence/valid/element-structure.json +0 -21
  376. package/packages/feedback/fixtures/v1/target-evidence/valid/host-iframe.json +0 -14
  377. package/packages/feedback/fixtures/v1/target-evidence/valid/source-anchor.json +0 -12
  378. package/packages/feedback/fixtures/v1/target-evidence/valid/text-selection.json +0 -26
  379. package/packages/feedback/package.json +0 -35
  380. package/packages/feedback/scripts/build-player.mjs +0 -28
  381. package/packages/feedback/src/index.ts +0 -1
  382. package/packages/feedback/src/primitives/composer.ts +0 -639
  383. package/packages/feedback/src/primitives/dialog.ts +0 -263
  384. package/packages/feedback/src/primitives/hostAdapter.ts +0 -116
  385. package/packages/feedback/src/primitives/index.ts +0 -10
  386. package/packages/feedback/src/primitives/launcher.ts +0 -200
  387. package/packages/feedback/src/primitives/picker.ts +0 -663
  388. package/packages/feedback/src/primitives/redaction.ts +0 -204
  389. package/packages/feedback/src/primitives/selection.ts +0 -49
  390. package/packages/feedback/src/primitives/shiftAccelerator.ts +0 -160
  391. package/packages/feedback/src/primitives/styles.ts +0 -77
  392. package/packages/feedback/src/primitives/surface.ts +0 -124
  393. package/packages/feedback/src/primitives/target.ts +0 -293
  394. package/packages/feedback/src/tour/canonical.ts +0 -27
  395. package/packages/feedback/src/tour/index.ts +0 -3
  396. package/packages/feedback/src/tour/player/browser.ts +0 -5
  397. package/packages/feedback/src/tour/player/host.ts +0 -12
  398. package/packages/feedback/src/tour/player/index.ts +0 -205
  399. package/packages/feedback/src/tour/player/manifest.ts +0 -76
  400. package/packages/feedback/src/tour/player/player.css +0 -130
  401. package/packages/feedback/src/tour/player/resolver.ts +0 -12
  402. package/packages/feedback/src/tour/player/surface.ts +0 -295
  403. package/packages/feedback/src/tour/player/types.ts +0 -8
  404. package/packages/feedback/src/tour/resolve/core.ts +0 -267
  405. package/packages/feedback/src/tour/resolve/dom.ts +0 -115
  406. package/packages/feedback/src/tour/resolve/index.ts +0 -29
  407. package/packages/feedback/src/tour/sanitize.ts +0 -76
  408. package/packages/feedback/src/tour/schema.ts +0 -362
  409. package/packages/feedback/src/v1/guards.ts +0 -335
  410. package/packages/feedback/src/v1/index.ts +0 -3
  411. package/packages/feedback/src/v1/protectedSurfaces.ts +0 -32
  412. package/packages/feedback/src/v1/types.ts +0 -177
  413. package/packages/feedback/tsconfig.json +0 -9
  414. package/packages/feedback/vitest.config.cts +0 -21
@@ -1,150 +0,0 @@
1
- /**
2
- * A ToT-staff principal ENTERING a store: the one audited act behind every staff
3
- * cross-store admission (#8425 staff access).
4
- *
5
- * Shared by the staff console (`POST /api/dashboard/enter-vendor`) and the preview
6
- * token mint (`POST /api/preview/token`, what `tot preview token` calls), so a staff
7
- * CLI principal records exactly the selection the console does:
8
- *
9
- * 1. prove the staff actor to tot20 with a fresh storefront-signed broker assertion
10
- * minted from the VERIFIED session email (no plaintext email on the wire);
11
- * 2. tot20 re-checks staff scope, scopes the capability, and writes the AUDIT row —
12
- * it is the authority, and nothing is admitted without its ok;
13
- * 3. persist the short-lived {@link StaffSelection} under a fresh session id (never a
14
- * `tenants[]` entry), preserving the original expiry; re-entry re-audits;
15
- * 4. hand every exit's outcome to the caller's `emit`, which records it as
16
- * `dashboard.vendor_entered` against its opaque admin actor id (the email is
17
- * never stored).
18
- */
19
- import type { SessionRecord, SessionStore, StaffSelection } from "@/lib/access/auth/session";
20
- import { readSession, rotateSession } from "@/lib/access/auth/session";
21
- import { isStaffSession, buildStaffSelection, STAFF_SELECTION_TTL_SECONDS } from "./staffAdmission";
22
- import {
23
- createStaffVendorAccessClient,
24
- staffAccessFailureMessage,
25
- staffAccessHttpStatus,
26
- StaffVendorAccessClientError,
27
- } from "./staffVendorAccess";
28
- import { mintBrokerAssertion, BrokerAssertionError } from "@/lib/access/auth/brokerAssertion";
29
- /** One `dashboard.vendor_entered` outcome, for the caller to record against its actor. */
30
- export interface StaffEntryEvent {
31
- outcome: { status: "succeeded" | "failed" | "refused"; errorClass?: string };
32
- scope: { tenantId: string };
33
- payload: { args: { resource: string; capability?: string } };
34
- }
35
-
36
- export interface StaffStoreEntryInput {
37
- /** The verified viewer session. Must carry ToT-staff scope. */
38
- session: SessionRecord;
39
- /** The store to enter, by appDomain. */
40
- vendorAppDomain: string;
41
- /** Records each entry outcome; the route binds it to its opaque admin actor. */
42
- emit: (event: StaffEntryEvent) => void;
43
- /** The persisted session to stamp the selection on; null when there is no store. */
44
- /** A null id is a freshly verified, not-yet-persisted sign-in record. */
45
- sessionHandle: () => Promise<{ store: SessionStore; id: string | null } | null>;
46
- }
47
-
48
- export type StaffStoreEntryResult =
49
- | { ok: true; selection: StaffSelection; capability: string; sessionId: string; expiresIn: number }
50
- | {
51
- ok: false;
52
- status: number;
53
- body: { error: string; reason?: string; code?: string };
54
- };
55
-
56
- /** Audit with tot20, then persist the selection under a fresh, expiry-preserving id. */
57
- export async function enterStoreAsStaff(input: StaffStoreEntryInput): Promise<StaffStoreEntryResult> {
58
- const { session, emit } = input;
59
- const vendorAppDomain = input.vendorAppDomain.trim();
60
- if (!isStaffSession(session)) {
61
- return { ok: false, status: 403, body: { error: "staff access required", reason: "notStaff" } };
62
- }
63
-
64
- let client;
65
- try {
66
- client = await createStaffVendorAccessClient();
67
- } catch (err) {
68
- if (err instanceof StaffVendorAccessClientError) {
69
- return { ok: false, status: 503, body: { error: "staff-access integration not configured" } };
70
- }
71
- throw err;
72
- }
73
-
74
- let brokerAssertion: string;
75
- try {
76
- brokerAssertion = await mintBrokerAssertion(session.email);
77
- } catch (err) {
78
- if (err instanceof BrokerAssertionError) {
79
- return { ok: false, status: 503, body: { error: "staff-proof signing not configured" } };
80
- }
81
- throw err;
82
- }
83
-
84
- const result = await client.grantStaffAccess(brokerAssertion, vendorAppDomain);
85
- if (!result.ok) {
86
- emit({
87
- outcome: { status: "refused", errorClass: result.reason ?? `http_${result.status}` },
88
- scope: { tenantId: vendorAppDomain },
89
- payload: { args: { resource: vendorAppDomain } },
90
- });
91
- return {
92
- ok: false,
93
- status: staffAccessHttpStatus(result.reason, result.status),
94
- body: { error: staffAccessFailureMessage(result.reason), reason: result.reason, code: result.code },
95
- };
96
- }
97
-
98
- const nowSeconds = Math.floor(Date.now() / 1000);
99
- const selection = buildStaffSelection({
100
- resource: vendorAppDomain,
101
- capability: result.capability,
102
- nowSeconds,
103
- ttlSeconds: Math.max(1, Math.min(STAFF_SELECTION_TTL_SECONDS, session.exp - nowSeconds)),
104
- });
105
- const handle = await input.sessionHandle();
106
- if (!handle) {
107
- // The audit row is written but the marker cannot persist (no SESSION KV / no
108
- // cookie): fail closed so the caller is never told it is admitted.
109
- emit({
110
- outcome: { status: "failed", errorClass: "session_store_unavailable" },
111
- scope: { tenantId: vendorAppDomain },
112
- payload: { args: { resource: vendorAppDomain, capability: result.capability } },
113
- });
114
- return { ok: false, status: 503, body: { error: "session store unavailable; cannot persist admission" } };
115
- }
116
- let updated;
117
- try {
118
- const current = handle.id ? await readSession(handle.store, handle.id, nowSeconds) : session;
119
- updated = current && current.email === session.email && current.subject === session.subject && isStaffSession(current) && current.exp > nowSeconds
120
- ? await rotateSession(handle.store, {
121
- ...current,
122
- createdAt: session.createdAt,
123
- exp: Math.min(current.exp, session.exp),
124
- staffSelection: { ...selection, exp: Math.min(selection.exp, current.exp, session.exp) },
125
- }, nowSeconds)
126
- : null;
127
- } catch {
128
- emit({
129
- outcome: { status: "failed", errorClass: "session_store_unavailable" },
130
- scope: { tenantId: vendorAppDomain },
131
- payload: { args: { resource: vendorAppDomain, capability: result.capability } },
132
- });
133
- return { ok: false, status: 503, body: { error: "session store unavailable; cannot persist admission" } };
134
- }
135
- if (!updated) {
136
- emit({
137
- outcome: { status: "failed", errorClass: "session_expired" },
138
- scope: { tenantId: vendorAppDomain },
139
- payload: { args: { resource: vendorAppDomain, capability: result.capability } },
140
- });
141
- return { ok: false, status: 401, body: { error: "session expired; sign in again" } };
142
- }
143
-
144
- emit({
145
- outcome: { status: "succeeded" },
146
- scope: { tenantId: vendorAppDomain },
147
- payload: { args: { resource: vendorAppDomain, capability: result.capability } },
148
- });
149
- return { ok: true, selection, capability: result.capability, sessionId: updated.id, expiresIn: updated.record.exp - nowSeconds };
150
- }
@@ -1,452 +0,0 @@
1
- /**
2
- * StaffVendorAccessClient — the storefront's seam to tot20's two ToT-STAFF
3
- * cross-vendor endpoints (#8425 staff access). A ToT-staff user isn't a member of
4
- * a bounded set of vendors; they reach ANY vendor by explicit SEARCH-and-ENTER.
5
- * Both endpoints are operator-authed (storefront's OWN per-tier credentials) and
6
- * PROVE the staff actor with a storefront-signed BROKER ASSERTION in the
7
- * `X-ToT-Broker-Assertion` header (#8453 `staff-invite-proof-via-broker`) — NOT a
8
- * plaintext email field (spoofable, removed). tot20 verifies the assertion, derives
9
- * the staff actor from its `sub`, scopes the capability to that user's staffRoles,
10
- * and writes the server-side AUDIT row.
11
- *
12
- * GET /api/clients/vendorSearch?q=<prefix>&limit=<n> (operator secretKey; staff via header)
13
- * → { content: { code, vendors: [{ appDomain, displayName }] } }
14
- * POST /api/clients/staffVendorAccess { vendorAppDomain } (operator secretKey; staff via header)
15
- * → { content: { code, capability } } (WRITES the audit row; capability is
16
- * staffRoles-scoped)
17
- *
18
- * AUTH WIRE (mirrors `@/lib/grants/developerInvites` + `@/lib/auth/totAccessClient`,
19
- * verified against live qa): tot20's swagger `normalizeSecureUserRequest` extracts
20
- * machine creds from the request BODY/QUERY fields `totApiKey`/`totSecretKey`, NOT
21
- * custom `x-tot-*` headers. That is the ONLY integration-sensitive spot
22
- * ({@link credentialFields}). tot20 wraps every response in a `{ content, metadata }`
23
- * envelope.
24
- *
25
- * TIER: host + operator credential are per-DEPLOY env (`TOT_CORE_URL` +
26
- * `TOT_API_KEY`/`TOT_SECRET_KEY`) — the SAME env the sibling access + invite
27
- * clients read; no hardcoded hosts, no secrets in code.
28
- *
29
- * Built like `@/lib/grants/developerInvites` (interface + Http impl + Mock + env
30
- * factory) so the routes develop/test against `MockStaffVendorAccessClient` and
31
- * swap in the Http client with no call-site change.
32
- */
33
- import { readEnv } from "@/lib/publication/shared/env";
34
- import { decodeJwt } from "jose";
35
-
36
- /**
37
- * The header carrying the storefront-signed staff BROKER ASSERTION to tot20 (#8453
38
- * `staff-invite-proof-via-broker`). The staff actor is PROVEN by this signed JWT,
39
- * not by a plaintext `email` field (which was spoofable and has been removed from
40
- * the wire). Minted server-side (`@/lib/auth/brokerAssertion`) from the verified
41
- * `session.email`; tot20 verifies signature + replay and derives the staff actor
42
- * from the VERIFIED `sub`, scopes the capability to their staffRoles, and writes
43
- * the audit row. The literal is inlined (not imported) to keep this module's
44
- * transport seam self-contained, mirroring the sibling grants client.
45
- */
46
- const BROKER_ASSERTION_HEADER = "X-ToT-Broker-Assertion";
47
-
48
- /** One vendor hit from a search — the minimum needed to render + select. */
49
- export interface VendorHit {
50
- appDomain: string;
51
- displayName: string;
52
- }
53
-
54
- /** Result of a vendor search (typed failure, fail-closed). */
55
- export type VendorSearchResult =
56
- | { ok: true; vendors: VendorHit[] }
57
- | { ok: false; status: number; reason: StaffAccessFailureReason; message: string; code?: string };
58
-
59
- /** Result of a staff-vendor-access grant — the staffRoles-scoped capability. */
60
- export type StaffVendorAccessResult =
61
- | { ok: true; capability: string }
62
- | { ok: false; status: number; reason: StaffAccessFailureReason; message: string; code?: string };
63
-
64
- /** Typed failure reasons mapped from tot20's error codes / HTTP status. */
65
- export type StaffAccessFailureReason =
66
- | "notStaff" // 403 — the email holds no ToT-staff scope (server-authoritative)
67
- | "notFound" // 404/422 — the vendor appDomain isn't a resolvable app
68
- | "invalid" // 400/422 — bad/empty query or vendor
69
- | "notAuthenticated" // 401/403 — storefront's operator credential was rejected
70
- | "error"; // transport / unexpected upstream fault
71
-
72
- export interface StaffVendorAccessClient {
73
- /**
74
- * Search vendors by appDomain prefix. `brokerAssertion` is the storefront-signed
75
- * staff proof (presented in the `X-ToT-Broker-Assertion` header); tot20 derives
76
- * the staff actor from its verified `sub` and scopes results to their staffRoles.
77
- */
78
- searchVendors(brokerAssertion: string, query: string, limit?: number): Promise<VendorSearchResult>;
79
- /**
80
- * Admit the staff actor (proven by `brokerAssertion`) to `vendorAppDomain`: tot20
81
- * verifies the assertion, writes the audit row, and returns the staffRoles-scoped
82
- * capability. Called on explicit enter, never a silent per-host grant.
83
- */
84
- grantStaffAccess(brokerAssertion: string, vendorAppDomain: string): Promise<StaffVendorAccessResult>;
85
- }
86
-
87
- // --- HTTP transport seam (injected by tests) --------------------------------
88
-
89
- export interface HttpResponseLike {
90
- status: number;
91
- json(): Promise<unknown>;
92
- }
93
- export interface HttpTransport {
94
- get(url: string, headers: Record<string, string>): Promise<HttpResponseLike>;
95
- post(url: string, headers: Record<string, string>, body: unknown): Promise<HttpResponseLike>;
96
- }
97
-
98
- /** Default transport: JSON `fetch` GET/POST. */
99
- export class FetchHttpTransport implements HttpTransport {
100
- async get(url: string, headers: Record<string, string>) {
101
- return fetch(url, { method: "GET", headers: { accept: "application/json", ...headers }, redirect: "manual" });
102
- }
103
- async post(url: string, headers: Record<string, string>, body: unknown) {
104
- return fetch(url, {
105
- method: "POST",
106
- headers: { "content-type": "application/json", accept: "application/json", ...headers },
107
- body: JSON.stringify(body),
108
- redirect: "manual",
109
- });
110
- }
111
- }
112
-
113
- export interface HttpStaffVendorAccessClientConfig {
114
- /** tot20 core API base (no trailing slash), e.g. https://qa.tokenoftrust.com */
115
- baseUrl: string;
116
- /** Storefront's OWN per-tier ToT credentials (machine auth to the operator API). */
117
- apiKey: string;
118
- secretKey?: string;
119
- transport?: HttpTransport;
120
- /** Default result cap when a caller passes no limit. */
121
- defaultLimit?: number;
122
- }
123
-
124
- export class StaffVendorAccessClientError extends Error {}
125
-
126
- const DEFAULT_LIMIT = 10;
127
- const MAX_LIMIT = 50;
128
-
129
- /** Clamp a caller-supplied limit into (0, MAX_LIMIT], defaulting when absent/bad. */
130
- function clampLimit(limit: number | undefined, fallback: number): number {
131
- const n = typeof limit === "number" ? Math.floor(limit) : NaN;
132
- if (!Number.isFinite(n) || n <= 0) return fallback;
133
- return Math.min(n, MAX_LIMIT);
134
- }
135
-
136
- // --- HTTP impl --------------------------------------------------------------
137
-
138
- export class HttpStaffVendorAccessClient implements StaffVendorAccessClient {
139
- private readonly baseUrl: string;
140
- private readonly apiKey: string;
141
- private readonly secretKey?: string;
142
- private readonly transport: HttpTransport;
143
- private readonly defaultLimit: number;
144
-
145
- constructor(config: HttpStaffVendorAccessClientConfig) {
146
- if (!config.baseUrl) {
147
- throw new StaffVendorAccessClientError("staffVendorAccess: TOT_CORE_URL is not configured");
148
- }
149
- if (!config.apiKey) {
150
- throw new StaffVendorAccessClientError(
151
- "staffVendorAccess: storefront ToT credentials are not configured",
152
- );
153
- }
154
- this.baseUrl = config.baseUrl.replace(/\/+$/, "");
155
- this.apiKey = config.apiKey;
156
- this.secretKey = config.secretKey;
157
- this.transport = config.transport ?? new FetchHttpTransport();
158
- this.defaultLimit = clampLimit(config.defaultLimit, DEFAULT_LIMIT);
159
- }
160
-
161
- /**
162
- * The one integration-sensitive spot: tot20 reads `totApiKey`/`totSecretKey`
163
- * from the request body/query (`normalizeSecureUserRequest`). Swap for a
164
- * machine-JWT `Authorization: Bearer` here if tot20 ever requires it.
165
- */
166
- private credentialFields(): Record<string, string> {
167
- const f: Record<string, string> = { totApiKey: this.apiKey };
168
- if (this.secretKey) f.totSecretKey = this.secretKey;
169
- return f;
170
- }
171
-
172
- async searchVendors(brokerAssertion: string, query: string, limit?: number): Promise<VendorSearchResult> {
173
- const q = (query ?? "").trim();
174
- if (!q) return { ok: true, vendors: [] }; // empty prefix → nothing to search
175
- // #8453 `staff-invite-proof-via-broker`: the staff actor is proven by the signed
176
- // assertion header — NEVER a plaintext `email` query param.
177
- const params = new URLSearchParams({
178
- q,
179
- limit: String(clampLimit(limit, this.defaultLimit)),
180
- ...this.credentialFields(),
181
- });
182
- const headers: Record<string, string> = {};
183
- if (brokerAssertion) headers[BROKER_ASSERTION_HEADER] = brokerAssertion;
184
- let res: HttpResponseLike;
185
- try {
186
- res = await this.transport.get(`${this.baseUrl}/api/clients/vendorSearch?${params.toString()}`, headers);
187
- } catch (cause) {
188
- return {
189
- ok: false,
190
- status: 0,
191
- reason: "error",
192
- message: "staffVendorAccess: transport failure searching vendors",
193
- };
194
- }
195
- if (res.status >= 300 && res.status < 400) {
196
- return { ok: false, status: res.status, reason: "error", message: "staffVendorAccess: redirects are not accepted" };
197
- }
198
- let parsed: unknown;
199
- try {
200
- parsed = await res.json();
201
- } catch {
202
- return {
203
- ok: false,
204
- status: res.status,
205
- reason: "error",
206
- message: `staffVendorAccess: tot20 returned a non-JSON body (status ${res.status})`,
207
- };
208
- }
209
- return normalizeVendorSearch(res.status, parsed);
210
- }
211
-
212
- async grantStaffAccess(brokerAssertion: string, vendorAppDomain: string): Promise<StaffVendorAccessResult> {
213
- const vendor = (vendorAppDomain ?? "").trim();
214
- if (!vendor) {
215
- return { ok: false, status: 400, reason: "invalid", message: "a vendor appDomain is required" };
216
- }
217
- // #8453 `staff-invite-proof-via-broker`: the staff actor is proven by the signed
218
- // assertion header — NEVER a plaintext `email` body field.
219
- const headers: Record<string, string> = {};
220
- if (brokerAssertion) headers[BROKER_ASSERTION_HEADER] = brokerAssertion;
221
- let res: HttpResponseLike;
222
- try {
223
- res = await this.transport.post(
224
- `${this.baseUrl}/api/clients/staffVendorAccess`,
225
- headers,
226
- { vendorAppDomain: vendor, ...this.credentialFields() },
227
- );
228
- } catch (cause) {
229
- return {
230
- ok: false,
231
- status: 0,
232
- reason: "error",
233
- message: "staffVendorAccess: transport failure granting access",
234
- };
235
- }
236
- if (res.status >= 300 && res.status < 400) {
237
- return { ok: false, status: res.status, reason: "error", message: "staffVendorAccess: redirects are not accepted" };
238
- }
239
- let parsed: unknown;
240
- try {
241
- parsed = await res.json();
242
- } catch {
243
- return {
244
- ok: false,
245
- status: res.status,
246
- reason: "error",
247
- message: `staffVendorAccess: tot20 returned a non-JSON body (status ${res.status})`,
248
- };
249
- }
250
- return normalizeStaffAccess(res.status, parsed);
251
- }
252
- }
253
-
254
- /** Unwrap tot20's `{ content, metadata }` envelope (fall back to the raw body). */
255
- function unwrap(body: unknown): Record<string, unknown> {
256
- const raw = (body ?? {}) as Record<string, unknown>;
257
- return (raw.content && typeof raw.content === "object" ? raw.content : raw) as Record<string, unknown>;
258
- }
259
-
260
- /** Parse tot20's vendorSearch response into a typed result (fail closed). */
261
- export function normalizeVendorSearch(status: number, body: unknown): VendorSearchResult {
262
- const c = unwrap(body);
263
- const code = typeof c.code === "string" ? c.code : undefined;
264
- const isOk =
265
- code === "vendorSearch:ok" || (status >= 200 && status < 300 && Array.isArray(c.vendors));
266
- if (isOk) {
267
- const vendors: VendorHit[] = (Array.isArray(c.vendors) ? c.vendors : [])
268
- .map((raw2) => {
269
- const r = (raw2 ?? {}) as Record<string, unknown>;
270
- const appDomain = typeof r.appDomain === "string" ? r.appDomain : "";
271
- return {
272
- appDomain,
273
- displayName: typeof r.displayName === "string" && r.displayName ? r.displayName : appDomain,
274
- };
275
- })
276
- .filter((v) => v.appDomain);
277
- return { ok: true, vendors };
278
- }
279
- return failure(status, c);
280
- }
281
-
282
- /** Parse tot20's staffVendorAccess response into a typed result (fail closed). */
283
- export function normalizeStaffAccess(status: number, body: unknown): StaffVendorAccessResult {
284
- const c = unwrap(body);
285
- const code = typeof c.code === "string" ? c.code : undefined;
286
- const isOk =
287
- code === "staffVendorAccess:granted" ||
288
- (status >= 200 && status < 300 && typeof c.capability === "string");
289
- if (isOk) {
290
- return { ok: true, capability: typeof c.capability === "string" ? c.capability : "staff" };
291
- }
292
- return failure(status, c);
293
- }
294
-
295
- /** Map an error envelope onto a typed failure by tot20 `code` then HTTP status. */
296
- function failure(
297
- status: number,
298
- c: Record<string, unknown>,
299
- ): { ok: false; status: number; reason: StaffAccessFailureReason; message: string; code?: string } {
300
- const code = typeof c.code === "string" ? c.code : undefined;
301
- const reason = reasonFor(code, status);
302
- return { ok: false, status, reason, message: staffAccessFailureMessage(reason), ...(code ? { code } : {}) };
303
- }
304
-
305
- function reasonFor(code: string | undefined, status: number): StaffAccessFailureReason {
306
- switch (code) {
307
- case "staffVendorAccess:notStaff":
308
- return "notStaff";
309
- case "staffVendorAccess:vendorNotFound":
310
- case "vendorSearch:vendorNotFound":
311
- return "notFound";
312
- case "staffVendorAccess:invalid":
313
- case "vendorSearch:invalid":
314
- return "invalid";
315
- case "operatorGrants:notAuthenticated":
316
- return "notAuthenticated";
317
- default:
318
- if (status === 401) return "notAuthenticated";
319
- if (status === 403) return "notStaff";
320
- if (status === 404) return "notFound";
321
- if (status === 400 || status === 422) return "invalid";
322
- return "error";
323
- }
324
- }
325
-
326
- /**
327
- * Map a typed failure onto the HTTP status a storefront endpoint should return:
328
- * notStaff/notAuthenticated → 403; notFound → 404; invalid → 400; a transport /
329
- * unexpected fault → the upstream status if it's an error, else 502.
330
- */
331
- export function staffAccessHttpStatus(reason: StaffAccessFailureReason, upstreamStatus: number): number {
332
- switch (reason) {
333
- case "notStaff":
334
- case "notAuthenticated":
335
- return 403;
336
- case "notFound":
337
- return 404;
338
- case "invalid":
339
- return 400;
340
- default:
341
- return upstreamStatus >= 400 ? upstreamStatus : 502;
342
- }
343
- }
344
-
345
- /** Finite staff-facing copy for a staff-access refusal — the only text a route returns. */
346
- export function staffAccessFailureMessage(reason: StaffAccessFailureReason): string {
347
- switch (reason) {
348
- case "notStaff":
349
- return "this account doesn't hold ToT-staff access to that vendor";
350
- case "notAuthenticated":
351
- return "storefront's operator credential was rejected";
352
- case "notFound":
353
- return "that vendor is not a resolvable Token of Trust app";
354
- case "invalid":
355
- return "a valid vendor is required";
356
- default:
357
- return "Token of Trust couldn't complete the staff-access request; try again shortly";
358
- }
359
- }
360
-
361
- // --- Mock (tests + local dev) -----------------------------------------------
362
-
363
- /**
364
- * In-memory StaffVendorAccessClient. Seeded with a directory of vendors and the
365
- * set of staff emails, it drives route + client tests deterministically and lets
366
- * local dev exercise the search+enter flow before/without the live tot20 endpoint.
367
- */
368
- export class MockStaffVendorAccessClient implements StaffVendorAccessClient {
369
- private readonly vendors: VendorHit[];
370
- private readonly staff: Set<string>;
371
- private readonly capability: string;
372
- /** Recorded admissions, for assertions (the audit row tot20 would write). */
373
- granted: Array<{ email: string; vendorAppDomain: string }> = [];
374
-
375
- constructor(opts: { vendors?: VendorHit[]; staffEmails?: string[]; capability?: string } = {}) {
376
- this.vendors = opts.vendors ?? [];
377
- this.staff = new Set((opts.staffEmails ?? []).map((e) => e.toLowerCase()));
378
- this.capability = opts.capability ?? "staff";
379
- }
380
-
381
- /**
382
- * Derive the staff actor's email from the broker assertion's `sub` — simulating
383
- * tot20 deriving it from the VERIFIED assertion. The Mock only DECODES (never
384
- * verifies the signature); the real tot20 verifies. Returns "" for an
385
- * absent/malformed assertion so a proofless call fails the staff check.
386
- */
387
- private actorEmail(brokerAssertion: string): string {
388
- if (!brokerAssertion || !brokerAssertion.trim()) return "";
389
- try {
390
- const sub = decodeJwt(brokerAssertion).sub;
391
- return typeof sub === "string" ? sub.toLowerCase() : "";
392
- } catch {
393
- return "";
394
- }
395
- }
396
-
397
- async searchVendors(_brokerAssertion: string, query: string, limit?: number): Promise<VendorSearchResult> {
398
- const q = (query ?? "").trim().toLowerCase();
399
- if (!q) return { ok: true, vendors: [] };
400
- const cap = clampLimit(limit, DEFAULT_LIMIT);
401
- const vendors = this.vendors
402
- .filter(
403
- (v) =>
404
- v.appDomain.toLowerCase().startsWith(q) || v.displayName.toLowerCase().includes(q),
405
- )
406
- .slice(0, cap);
407
- return { ok: true, vendors };
408
- }
409
-
410
- async grantStaffAccess(brokerAssertion: string, vendorAppDomain: string): Promise<StaffVendorAccessResult> {
411
- const vendor = (vendorAppDomain ?? "").trim();
412
- if (!vendor) return { ok: false, status: 400, reason: "invalid", message: "a vendor appDomain is required" };
413
- const email = this.actorEmail(brokerAssertion);
414
- if (!email || !this.staff.has(email)) {
415
- return {
416
- ok: false,
417
- status: 403,
418
- reason: "notStaff",
419
- message: "this account doesn't hold ToT-staff access to that vendor",
420
- code: "staffVendorAccess:notStaff",
421
- };
422
- }
423
- if (!this.vendors.some((v) => v.appDomain === vendor)) {
424
- return {
425
- ok: false,
426
- status: 404,
427
- reason: "notFound",
428
- message: "that vendor is not a resolvable Token of Trust app",
429
- code: "staffVendorAccess:vendorNotFound",
430
- };
431
- }
432
- this.granted.push({ email, vendorAppDomain: vendor });
433
- return { ok: true, capability: this.capability };
434
- }
435
- }
436
-
437
- // --- Factory ----------------------------------------------------------------
438
-
439
- /**
440
- * Build the env-configured client:
441
- * - `TOT_CORE_URL` — tot20 core API base (tier-matching per deploy).
442
- * - `TOT_API_KEY` (+ optional `TOT_SECRET_KEY`) — storefront's own operator creds.
443
- * Throws {@link StaffVendorAccessClientError} when unconfigured (routes map that to 503).
444
- */
445
- export async function createStaffVendorAccessClient(
446
- overrides: Partial<HttpStaffVendorAccessClientConfig> = {},
447
- ): Promise<HttpStaffVendorAccessClient> {
448
- const baseUrl = overrides.baseUrl ?? (await readEnv("TOT_CORE_URL")) ?? "";
449
- const apiKey = overrides.apiKey ?? (await readEnv("TOT_API_KEY")) ?? "";
450
- const secretKey = overrides.secretKey ?? (await readEnv("TOT_SECRET_KEY"));
451
- return new HttpStaffVendorAccessClient({ ...overrides, baseUrl, apiKey, secretKey });
452
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * Anchor syntax for the ToT-STAFF vendor search (#8425). tot20's vendorSearch does a
3
- * plain SUBSTRING match over appDomain OR displayName, so a common term like
4
- * `tokenoftrust.com` surfaces every subdomain/displayName that contains it and buries
5
- * (or caps out) the one exact hit. These anchors let a staffer narrow it, mirroring
6
- * regex/grep intuition — but they are LITERAL anchors, not a regex engine:
7
- *
8
- * ^acme.com → appDomain STARTS WITH "acme.com"
9
- * acme.com$ → appDomain ENDS WITH "acme.com"
10
- * ^acme.com$ → appDomain EXACTLY "acme.com"
11
- * acme → unchanged substring search (appDomain OR displayName, tot20-side)
12
- *
13
- * Anchors match the **appDomain** only (the domain the operator is targeting), case-
14
- * insensitively. Only a leading `^` and a trailing `$` are treated as anchors; the
15
- * characters elsewhere are literal. The core term (anchors stripped) is what we send
16
- * upstream, so tot20 still returns a superset we filter locally.
17
- */
18
-
19
- /** Upstream fetch cap for an anchored query — widened so the exact hit is in the set we filter. */
20
- export const ANCHORED_FETCH_LIMIT = 50;
21
-
22
- /** Max rows returned to the client after an anchored post-filter (the visible autocomplete list). */
23
- export const ANCHORED_DISPLAY_LIMIT = 10;
24
-
25
- export interface ParsedVendorQuery {
26
- /** The search term with any anchors stripped — what we send upstream to tot20. */
27
- core: string;
28
- /** True when `^`/`$` anchors are present AND there is a non-empty core to match. */
29
- anchored: boolean;
30
- /** Predicate applied to a vendor `appDomain` when `anchored` (always true otherwise). */
31
- matches: (appDomain: string) => boolean;
32
- }
33
-
34
- /**
35
- * Parse a raw search string into its core term + an anchor predicate. Pure + total:
36
- * a bare `^`, `$`, or `^$` (no core) yields `anchored:false` and an empty core, so the
37
- * caller sends an empty query upstream (→ no results) rather than matching everything.
38
- */
39
- export function parseVendorQuery(raw: string): ParsedVendorQuery {
40
- const q = (raw ?? "").trim();
41
- const start = q.startsWith("^");
42
- const end = q.endsWith("$");
43
- let core = q;
44
- if (start) core = core.slice(1);
45
- if (end) core = core.slice(0, core.length - 1);
46
- core = core.trim();
47
- const needle = core.toLowerCase();
48
- const anchored = (start || end) && core.length > 0;
49
-
50
- let matches: (appDomain: string) => boolean;
51
- if (start && end) {
52
- matches = (d) => (d ?? "").toLowerCase() === needle;
53
- } else if (start) {
54
- matches = (d) => (d ?? "").toLowerCase().startsWith(needle);
55
- } else if (end) {
56
- matches = (d) => (d ?? "").toLowerCase().endsWith(needle);
57
- } else {
58
- matches = () => true;
59
- }
60
- return { core, anchored, matches };
61
- }