@tokenoftrust/storefront-runner 7.3.2 → 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 (415) 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/commerce/cardCartForm.ts +2 -0
  25. package/apps/storefront/src/lib/checkout/commerce/cartSession.ts +109 -12
  26. package/apps/storefront/src/lib/checkout/commerce/checkoutHandoffRoute.ts +53 -25
  27. package/apps/storefront/src/lib/checkout/commerce/finalCartAuthorization.ts +48 -6
  28. package/apps/storefront/src/lib/checkout/proposal/cartProposal.ts +388 -0
  29. package/apps/storefront/src/lib/checkout/proposal/listMatcher.ts +149 -0
  30. package/apps/storefront/src/lib/checkout/proposal/proposalRoutes.ts +447 -0
  31. package/apps/storefront/src/lib/checkout/proposal/reviewHtml.ts +100 -0
  32. package/apps/storefront/src/lib/compliance/browser/checkoutVerificationFlow.ts +26 -2
  33. package/apps/storefront/src/lib/content/shared/redirects.ts +21 -4
  34. package/apps/storefront/src/lib/publication/shared/edgeCache.ts +5 -2
  35. package/apps/storefront/src/lib/publication/shared/previewAnnotations/renderDecorator.ts +15 -8
  36. package/apps/storefront/src/lib/publication/shared/runtimeEnv.ts +1 -1
  37. package/apps/storefront/src/middleware/controlPlane.ts +15 -1
  38. package/apps/storefront/src/middleware/index.ts +7 -3
  39. package/apps/storefront/src/middleware/renderChain.ts +46 -33
  40. package/apps/storefront/src/pages/api/cart-proposal/confirm.ts +12 -0
  41. package/apps/storefront/src/pages/api/cart-proposal/review.ts +26 -0
  42. package/apps/storefront/src/pages/api/commerce/final-cart-authorization.ts +29 -6
  43. package/apps/storefront/src/pages/api/compliance/preflight.ts +25 -1
  44. package/apps/storefront/src/pages/products/[handle].astro +2 -15
  45. package/apps/storefront/tsconfig.astro.json +11 -0
  46. package/package.json +1 -1
  47. package/packages/public-runtime/src/activity/README.md +12 -0
  48. package/packages/public-runtime/src/activity/catalog.ts +7 -0
  49. package/packages/public-runtime/src/activity/event.ts +19 -0
  50. package/packages/public-runtime/src/activity/redaction.ts +31 -2
  51. package/packages/public-runtime/src/catalog-files.ts +3 -2
  52. package/packages/public-runtime/src/checkout-orders.ts +18 -19
  53. package/packages/public-runtime/src/checkout.ts +70 -0
  54. package/packages/public-runtime/src/compliance/evaluate.ts +60 -1
  55. package/packages/public-runtime/src/compliance/index.ts +1 -1
  56. package/packages/public-runtime/src/compliance/pact-report.ts +184 -3
  57. package/packages/public-runtime/src/compliance/profile.ts +268 -20
  58. package/packages/public-runtime/src/compliance/ruleset.ts +42 -0
  59. package/packages/public-runtime/src/customization-runtime.ts +1 -1
  60. package/packages/public-runtime/src/product.ts +9 -1
  61. package/packages/public-runtime/src/publication-content-redirects.ts +16 -3
  62. package/packages/public-runtime/tests/fixtures/compliance-decisions.golden.json +252 -52
  63. package/pnpm-lock.runner.yaml +0 -15
  64. package/scripts/tenant/materialize-tenant-content.mjs +3 -0
  65. package/scripts/tenant/validate.mjs +128 -0
  66. package/apps/storefront/dev-plugins/dev-publish.mjs +0 -55
  67. package/apps/storefront/drizzle.config.apps.ts +0 -13
  68. package/apps/storefront/integrations/preview-annotations-client-bundle.mjs +0 -80
  69. package/apps/storefront/migrations-apps/0000_fast_millenium_guard.sql +0 -129
  70. package/apps/storefront/migrations-apps/0001_woozy_lyja.sql +0 -22
  71. package/apps/storefront/migrations-apps/0002_good_switch.sql +0 -26
  72. package/apps/storefront/migrations-apps/0003_mute_marauders.sql +0 -12
  73. package/apps/storefront/migrations-apps/0004_deep_morph.sql +0 -36
  74. package/apps/storefront/migrations-apps/0005_common_mystique.sql +0 -23
  75. package/apps/storefront/migrations-apps/0006_broad_microchip.sql +0 -16
  76. package/apps/storefront/migrations-apps/0007_brave_outlaw_kid.sql +0 -15
  77. package/apps/storefront/migrations-apps/0008_blue_dazzler.sql +0 -11
  78. package/apps/storefront/migrations-apps/0009_bored_shinobi_shaw.sql +0 -15
  79. package/apps/storefront/migrations-apps/0010_ws4_verified_provider_measurement.sql +0 -35
  80. package/apps/storefront/migrations-apps/0011_dt_tracking_tenant_databases.sql +0 -23
  81. package/apps/storefront/migrations-apps/0012_test_destinations.sql +0 -29
  82. package/apps/storefront/migrations-apps/0013_publication_space_editorial.sql +0 -64
  83. package/apps/storefront/migrations-apps/0014_retire_candidate_ledger.sql +0 -12
  84. package/apps/storefront/migrations-apps/0015_merchant_calculation_settings.sql +0 -31
  85. package/apps/storefront/migrations-apps/0016_scrappy_commerce_contract.sql +0 -166
  86. package/apps/storefront/migrations-apps/0017_commerce_durable_projection.sql +0 -28
  87. package/apps/storefront/migrations-apps/0018_commerce_provider_cart_identity.sql +0 -13
  88. package/apps/storefront/migrations-apps/0019_commerce_source_authority.sql +0 -23
  89. package/apps/storefront/migrations-apps/0020_contact_messages.sql +0 -18
  90. package/apps/storefront/migrations-apps/0021_contact_vault.sql +0 -166
  91. package/apps/storefront/migrations-apps/0022_contact_vault_fields.sql +0 -342
  92. package/apps/storefront/migrations-apps/0023_principal_grant_contacts.sql +0 -15
  93. package/apps/storefront/migrations-apps/0024_order_contact_erasure_state.sql +0 -22
  94. package/apps/storefront/migrations-apps/0025_shipment_audit_order_lookup.sql +0 -2
  95. package/apps/storefront/migrations-apps/0026_fulfillment_assignment.sql +0 -44
  96. package/apps/storefront/migrations-apps/0027_app_contact_authority.sql +0 -70
  97. package/apps/storefront/migrations-apps/0028_app_jwk_and_candidates.sql +0 -133
  98. package/apps/storefront/migrations-apps/0029_inventory_locations_wms.sql +0 -38
  99. package/apps/storefront/migrations-apps/0030_assignment_split_shipments.sql +0 -149
  100. package/apps/storefront/migrations-apps/meta/0000_snapshot.json +0 -843
  101. package/apps/storefront/migrations-apps/meta/0001_snapshot.json +0 -990
  102. package/apps/storefront/migrations-apps/meta/0002_snapshot.json +0 -1160
  103. package/apps/storefront/migrations-apps/meta/0003_snapshot.json +0 -1235
  104. package/apps/storefront/migrations-apps/meta/0004_snapshot.json +0 -1474
  105. package/apps/storefront/migrations-apps/meta/0005_snapshot.json +0 -1617
  106. package/apps/storefront/migrations-apps/meta/0006_snapshot.json +0 -1716
  107. package/apps/storefront/migrations-apps/meta/0007_snapshot.json +0 -1812
  108. package/apps/storefront/migrations-apps/meta/0008_snapshot.json +0 -1881
  109. package/apps/storefront/migrations-apps/meta/0009_snapshot.json +0 -1979
  110. package/apps/storefront/migrations-apps/meta/_journal.json +0 -76
  111. package/apps/storefront/perf/README.md +0 -64
  112. package/apps/storefront/perf/assert-budgets.ts +0 -159
  113. package/apps/storefront/platform-reconcile-tenants.json +0 -3
  114. package/apps/storefront/playwright.config.ts +0 -23
  115. package/apps/storefront/public/js/dashboard-access-banner.js +0 -53
  116. package/apps/storefront/public/js/dashboard-apps.js +0 -183
  117. package/apps/storefront/public/js/dashboard-contact-capture.js +0 -52
  118. package/apps/storefront/public/js/dashboard-delegate.js +0 -167
  119. package/apps/storefront/public/js/dashboard-team.js +0 -356
  120. package/apps/storefront/public/js/dashboard-vendor-search.js +0 -115
  121. package/apps/storefront/src/components/content/storefront/AsyncStylesheet.astro +0 -26
  122. package/apps/storefront/src/components/integrations/storefront/WidgetFrame.astro +0 -34
  123. package/apps/storefront/src/config/adminTenantLookup.ts +0 -35
  124. package/apps/storefront/src/config/evidenceTenantRoster.ts +0 -25
  125. package/apps/storefront/src/config/staffProvisionProjection.ts +0 -24
  126. package/apps/storefront/src/config/storeName.ts +0 -34
  127. package/apps/storefront/src/lib/access/admin/README.md +0 -122
  128. package/apps/storefront/src/lib/access/admin/adminShell.ts +0 -281
  129. package/apps/storefront/src/lib/access/admin/envelope.ts +0 -9
  130. package/apps/storefront/src/lib/access/admin/viewmodels/settings.ts +0 -64
  131. package/apps/storefront/src/lib/access/auth/adminApiGuard.ts +0 -66
  132. package/apps/storefront/src/lib/access/auth/adminEntry.ts +0 -126
  133. package/apps/storefront/src/lib/access/auth/mcpClientAssertion.ts +0 -217
  134. package/apps/storefront/src/lib/access/auth/operatorSession.ts +0 -120
  135. package/apps/storefront/src/lib/access/dashboard/agentStoreEntry.ts +0 -253
  136. package/apps/storefront/src/lib/access/dashboard/delegateGate.ts +0 -130
  137. package/apps/storefront/src/lib/access/dashboard/staffStoreEntry.ts +0 -153
  138. package/apps/storefront/src/lib/access/dashboard/staffVendorAccess.ts +0 -474
  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/agentGrantAttestation.ts +0 -74
  209. package/apps/storefront/src/lib/developer-experience/dev/ai-widget-client.js +0 -308
  210. package/apps/storefront/src/lib/developer-experience/dev/apiBase.ts +0 -17
  211. package/apps/storefront/src/lib/developer-experience/dev/cliSignInCode.ts +0 -124
  212. package/apps/storefront/src/lib/developer-experience/dev/cockpit/ask.ts +0 -49
  213. package/apps/storefront/src/lib/developer-experience/dev/cockpit/clickToSource.ts +0 -71
  214. package/apps/storefront/src/lib/developer-experience/dev/cockpit/copyCommand.ts +0 -227
  215. package/apps/storefront/src/lib/developer-experience/dev/cockpit/files.ts +0 -249
  216. package/apps/storefront/src/lib/developer-experience/dev/cockpit/hostedActivity.ts +0 -500
  217. package/apps/storefront/src/lib/developer-experience/dev/cockpit/infoPopover.ts +0 -12
  218. package/apps/storefront/src/lib/developer-experience/dev/cockpit/mcpCopy.ts +0 -34
  219. package/apps/storefront/src/lib/developer-experience/dev/cockpit/monitor.ts +0 -107
  220. package/apps/storefront/src/lib/developer-experience/dev/cockpit/stepper.ts +0 -116
  221. package/apps/storefront/src/lib/developer-experience/dev/cockpit/themeToggle.ts +0 -23
  222. package/apps/storefront/src/lib/developer-experience/dev/livePreview.ts +0 -77
  223. package/apps/storefront/src/lib/developer-experience/dev/obstacleStore.ts +0 -214
  224. package/apps/storefront/src/lib/developer-experience/dev/previewStatus.ts +0 -87
  225. package/apps/storefront/src/lib/developer-experience/dev/rendezvousBroker.ts +0 -226
  226. package/apps/storefront/src/lib/developer-experience/dev/runtimeStore.ts +0 -291
  227. package/apps/storefront/src/lib/developer-experience/dev/storeStatus.ts +0 -142
  228. package/apps/storefront/src/lib/developer-experience/dev/subjectReissue.ts +0 -67
  229. package/apps/storefront/src/lib/developer-experience/fixtures/regulated-commerce-truth/index.ts +0 -540
  230. package/apps/storefront/src/lib/developer-experience/fixtures/ws3-readonly-clone-preflight/index.ts +0 -495
  231. package/apps/storefront/src/lib/engagement/contact/contactMessages.ts +0 -671
  232. package/apps/storefront/src/lib/engagement/contact/messagesTabClient.ts +0 -175
  233. package/apps/storefront/src/lib/engagement/contact/submission.ts +0 -112
  234. package/apps/storefront/src/lib/engagement/messaging/messagesClient.ts +0 -149
  235. package/apps/storefront/src/lib/engagement/newsletter/digest.ts +0 -117
  236. package/apps/storefront/src/lib/engagement/newsletter/resendClient.ts +0 -79
  237. package/apps/storefront/src/lib/engagement/newsletter/send.ts +0 -265
  238. package/apps/storefront/src/lib/engagement/social/golive.ts +0 -212
  239. package/apps/storefront/src/lib/engagement/social/notify.ts +0 -32
  240. package/apps/storefront/src/lib/engagement/social/tokenStore.ts +0 -171
  241. package/apps/storefront/src/lib/fulfillment/admin/commerceDesk.ts +0 -180
  242. package/apps/storefront/src/lib/fulfillment/admin/commerceDeskRouting.ts +0 -45
  243. package/apps/storefront/src/lib/fulfillment/admin/viewmodels/fulfillment.ts +0 -1071
  244. package/apps/storefront/src/lib/fulfillment/appShipmentEvidence.ts +0 -271
  245. package/apps/storefront/src/lib/fulfillment/carrierEvidence.ts +0 -105
  246. package/apps/storefront/src/lib/fulfillment/commerceProjection.ts +0 -157
  247. package/apps/storefront/src/lib/fulfillment/commerceReadback.ts +0 -60
  248. package/apps/storefront/src/lib/fulfillment/commerceRecovery.ts +0 -84
  249. package/apps/storefront/src/lib/fulfillment/commerceRuntime.ts +0 -41
  250. package/apps/storefront/src/lib/fulfillment/fulfillmentService.ts +0 -2842
  251. package/apps/storefront/src/lib/fulfillment/readiness.ts +0 -217
  252. package/apps/storefront/src/lib/fulfillment/splitShipments.ts +0 -388
  253. package/apps/storefront/src/lib/fulfillment/syntheticPreviewOrders.ts +0 -292
  254. package/apps/storefront/src/lib/integrations/apps/appContactAuthority.ts +0 -27
  255. package/apps/storefront/src/lib/integrations/apps/appContactConsents.ts +0 -118
  256. package/apps/storefront/src/lib/integrations/apps/appInstallEnv.ts +0 -28
  257. package/apps/storefront/src/lib/integrations/apps/gtmMigrationDraft.ts +0 -103
  258. package/apps/storefront/src/lib/integrations/apps/inventoryWrite.ts +0 -906
  259. package/apps/storefront/src/lib/integrations/apps/orders/customerHash.ts +0 -28
  260. package/apps/storefront/src/lib/integrations/apps/orders/idempotency.ts +0 -100
  261. package/apps/storefront/src/lib/integrations/apps/reports/salesVelocityReport.ts +0 -96
  262. package/apps/storefront/src/lib/integrations/apps/routeParams.ts +0 -45
  263. package/apps/storefront/src/lib/integrations/webhooks/cloudflareQueueDispatcher.ts +0 -82
  264. package/apps/storefront/src/lib/integrations/webhooks/commercePayloads.ts +0 -159
  265. package/apps/storefront/src/lib/integrations/webhooks/deliveryEngine.ts +0 -379
  266. package/apps/storefront/src/lib/integrations/webhooks/deliveryMapper.ts +0 -34
  267. package/apps/storefront/src/lib/integrations/webhooks/deliveryStore.ts +0 -903
  268. package/apps/storefront/src/lib/integrations/webhooks/dispatcher.ts +0 -168
  269. package/apps/storefront/src/lib/integrations/webhooks/emit.ts +0 -245
  270. package/apps/storefront/src/lib/integrations/webhooks/events.ts +0 -105
  271. package/apps/storefront/src/lib/integrations/webhooks/getDispatcher.ts +0 -77
  272. package/apps/storefront/src/lib/integrations/webhooks/orderFulfilledClaim.ts +0 -75
  273. package/apps/storefront/src/lib/measurement/admin/analyticsRegionPolicy.ts +0 -151
  274. package/apps/storefront/src/lib/measurement/admin/analyticsRegionsClient.ts +0 -84
  275. package/apps/storefront/src/lib/measurement/admin/consentSettingsClient.ts +0 -113
  276. package/apps/storefront/src/lib/measurement/analytics/index.ts +0 -44
  277. package/apps/storefront/src/lib/measurement/attribution/attributionService.ts +0 -206
  278. package/apps/storefront/src/lib/measurement/attribution/orderConversionD1.ts +0 -150
  279. package/apps/storefront/src/lib/measurement/attribution/verifiedProviderMeasurement.ts +0 -118
  280. package/apps/storefront/src/lib/measurement/tracking/interactionCollector.ts +0 -205
  281. package/apps/storefront/src/lib/measurement/tracking/pruneRollup.ts +0 -260
  282. package/apps/storefront/src/lib/measurement/tracking/tenantReadAccess.ts +0 -138
  283. package/apps/storefront/src/lib/measurement/tracking-writeback/rewriteTrackingIds.ts +0 -175
  284. package/apps/storefront/src/lib/measurement/tracking-writeback/writebackCandidate.ts +0 -110
  285. package/apps/storefront/src/lib/observability/diag/capture.ts +0 -162
  286. package/apps/storefront/src/lib/observability/diag/consoleLine.ts +0 -76
  287. package/apps/storefront/src/lib/observability/diag/debugConsole.ts +0 -118
  288. package/apps/storefront/src/lib/observability/diag/debugMode.ts +0 -163
  289. package/apps/storefront/src/lib/observability/diag/debugWindow.ts +0 -111
  290. package/apps/storefront/src/lib/observability/diag/redact.ts +0 -17
  291. package/apps/storefront/src/lib/observability/diag/reference.ts +0 -148
  292. package/apps/storefront/src/lib/observability/diag/referenceStore.ts +0 -113
  293. package/apps/storefront/src/lib/observability/diag/report.ts +0 -110
  294. package/apps/storefront/src/lib/observability/diag/serverResponseTime.ts +0 -91
  295. package/apps/storefront/src/lib/observability/diag/session.ts +0 -93
  296. package/apps/storefront/src/lib/observability/monitoring/manifest.ts +0 -301
  297. package/apps/storefront/src/lib/observability/performance/lighthouseReport.ts +0 -109
  298. package/apps/storefront/src/lib/observability/performance/rumAlert.ts +0 -179
  299. package/apps/storefront/src/lib/orders/admin/orderActions.ts +0 -556
  300. package/apps/storefront/src/lib/orders/admin/orderClient.ts +0 -248
  301. package/apps/storefront/src/lib/orders/admin/orderSource.ts +0 -410
  302. package/apps/storefront/src/lib/orders/admin/services/orders.ts +0 -922
  303. package/apps/storefront/src/lib/orders/admin/viewmodels/orders.ts +0 -135
  304. package/apps/storefront/src/lib/orders/data/commerceCallerConfig.ts +0 -37
  305. package/apps/storefront/src/lib/orders/data/ledgerContractOrders.ts +0 -148
  306. package/apps/storefront/src/lib/orders/data/orderForwardReceiver.ts +0 -532
  307. package/apps/storefront/src/lib/orders/data/orderMapper.ts +0 -454
  308. package/apps/storefront/src/lib/orders/data/ordersStore.ts +0 -623
  309. package/apps/storefront/src/lib/orders/data/sourceAuthorityContract.ts +0 -380
  310. package/apps/storefront/src/lib/orders/data/sourceAuthorityStore.ts +0 -830
  311. package/apps/storefront/src/lib/orders/fixtures/orders.ts +0 -186
  312. package/apps/storefront/src/lib/orders/providers/foxyOrderClient.ts +0 -207
  313. package/apps/storefront/src/lib/orders/vault/appRecipientRead.ts +0 -222
  314. package/apps/storefront/src/lib/orders/vault/contactIntake.ts +0 -63
  315. package/apps/storefront/src/lib/orders/vault/contactRoutes.ts +0 -110
  316. package/apps/storefront/src/lib/orders/vault/kmsEnv.ts +0 -11
  317. package/apps/storefront/src/lib/orders/vault/orderContact.ts +0 -96
  318. package/apps/storefront/src/lib/orders/vault/orderContactVault.ts +0 -1427
  319. package/apps/storefront/src/lib/orders/vault/vault-test-support.ts +0 -258
  320. package/apps/storefront/src/lib/publication/d1/schema-apps.ts +0 -808
  321. package/apps/storefront/src/lib/publication/notifications/candidateConflictEmail.ts +0 -80
  322. package/apps/storefront/src/lib/publication/servingMode.ts +0 -52
  323. package/apps/storefront/src/lib/publication/shared/previewAnnotations/moduleAsset.ts +0 -65
  324. package/apps/storefront/src/lib/publication/shared/routedApiParam.ts +0 -38
  325. package/apps/storefront/src/lib/reporting/admin/viewmodels/reporting.ts +0 -34
  326. package/apps/storefront/src/lib/reporting/fixtures/reporting.ts +0 -51
  327. package/apps/storefront/src/lib/subscriptions/admin/viewmodels/subscriptions.ts +0 -106
  328. package/apps/storefront/src/lib/subscriptions/fixtures/subscriptions.ts +0 -398
  329. package/apps/storefront/src/pages/api/admin/activity-alerts.ts +0 -58
  330. package/apps/storefront/src/pages/api/admin/commerce-readiness.ts +0 -172
  331. package/apps/storefront/src/pages/api/admin/fulfillment/batches.ts +0 -59
  332. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id]/address.ts +0 -66
  333. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id].ts +0 -118
  334. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contact-search.ts +0 -26
  335. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contacts.ts +0 -22
  336. package/apps/storefront/src/pages/api/admin/interaction-insights.ts +0 -101
  337. package/apps/storefront/src/pages/api/admin/orders/[id].ts +0 -63
  338. package/apps/storefront/src/pages/api/admin/orders.ts +0 -65
  339. package/apps/storefront/src/pages/api/contact.ts +0 -144
  340. package/apps/storefront/src/scheduled/contactVaultSweep.ts +0 -113
  341. package/apps/storefront/src/styles/admin.css +0 -1161
  342. package/apps/storefront/test/pipeline/fake-preview-services.ts +0 -288
  343. package/apps/storefront/test/pipeline/harness.ts +0 -209
  344. package/apps/storefront/test/pipeline/intake-worker.mjs +0 -14
  345. package/apps/storefront/test/pipeline/matrix-faults.ts +0 -366
  346. package/apps/storefront/test/pipeline/pipeline-host.ts +0 -418
  347. package/apps/storefront/test/pipeline/pool-config.cjs +0 -85
  348. package/apps/storefront/test/pipeline/publish-kinds.ts +0 -279
  349. package/apps/storefront/test/pipeline/synthetic-job.ts +0 -303
  350. package/apps/storefront/test/pipeline-faults/matrix-lib.ts +0 -696
  351. package/apps/storefront/vitest.config.cts +0 -44
  352. package/apps/storefront/vitest.faults.config.cts +0 -13
  353. package/apps/storefront/vitest.workers.config.cts +0 -7
  354. package/packages/feedback/fixtures/v1/expected-findings.json +0 -16
  355. package/packages/feedback/fixtures/v1/feedback-action/invalid/carries-transport-credential.json +0 -14
  356. package/packages/feedback/fixtures/v1/feedback-action/invalid/control-char-in-description.json +0 -13
  357. package/packages/feedback/fixtures/v1/feedback-action/invalid/legacy-schema-version.json +0 -13
  358. package/packages/feedback/fixtures/v1/feedback-action/invalid/page-path-with-query.json +0 -14
  359. package/packages/feedback/fixtures/v1/feedback-action/invalid/title-too-short.json +0 -13
  360. package/packages/feedback/fixtures/v1/feedback-action/valid/element-problem.json +0 -33
  361. package/packages/feedback/fixtures/v1/feedback-action/valid/page-comment.json +0 -20
  362. package/packages/feedback/fixtures/v1/feedback-action/valid/region-improvement.json +0 -24
  363. package/packages/feedback/fixtures/v1/feedback-action/valid/text-selection-feature.json +0 -30
  364. package/packages/feedback/fixtures/v1/submission-receipt/invalid/accepted-at-not-utc.json +0 -9
  365. package/packages/feedback/fixtures/v1/submission-receipt/invalid/bad-feedback-id.json +0 -9
  366. package/packages/feedback/fixtures/v1/submission-receipt/invalid/legacy-contract-version.json +0 -9
  367. package/packages/feedback/fixtures/v1/submission-receipt/invalid/missing-replayed.json +0 -8
  368. package/packages/feedback/fixtures/v1/submission-receipt/valid/accepted.json +0 -9
  369. package/packages/feedback/fixtures/v1/submission-receipt/valid/fractional-seconds.json +0 -9
  370. package/packages/feedback/fixtures/v1/submission-receipt/valid/replayed.json +0 -9
  371. package/packages/feedback/fixtures/v1/target-evidence/invalid/page-kind-claims-structure.json +0 -6
  372. package/packages/feedback/fixtures/v1/target-evidence/invalid/path-too-deep.json +0 -17
  373. package/packages/feedback/fixtures/v1/target-evidence/invalid/relative-region-out-of-range.json +0 -11
  374. package/packages/feedback/fixtures/v1/target-evidence/invalid/selector-uses-class.json +0 -7
  375. package/packages/feedback/fixtures/v1/target-evidence/invalid/source-precision-without-anchor.json +0 -6
  376. package/packages/feedback/fixtures/v1/target-evidence/valid/element-structure.json +0 -21
  377. package/packages/feedback/fixtures/v1/target-evidence/valid/host-iframe.json +0 -14
  378. package/packages/feedback/fixtures/v1/target-evidence/valid/source-anchor.json +0 -12
  379. package/packages/feedback/fixtures/v1/target-evidence/valid/text-selection.json +0 -26
  380. package/packages/feedback/package.json +0 -35
  381. package/packages/feedback/scripts/build-player.mjs +0 -28
  382. package/packages/feedback/src/index.ts +0 -1
  383. package/packages/feedback/src/primitives/composer.ts +0 -639
  384. package/packages/feedback/src/primitives/dialog.ts +0 -263
  385. package/packages/feedback/src/primitives/hostAdapter.ts +0 -116
  386. package/packages/feedback/src/primitives/index.ts +0 -10
  387. package/packages/feedback/src/primitives/launcher.ts +0 -200
  388. package/packages/feedback/src/primitives/picker.ts +0 -663
  389. package/packages/feedback/src/primitives/redaction.ts +0 -204
  390. package/packages/feedback/src/primitives/selection.ts +0 -49
  391. package/packages/feedback/src/primitives/shiftAccelerator.ts +0 -160
  392. package/packages/feedback/src/primitives/styles.ts +0 -77
  393. package/packages/feedback/src/primitives/surface.ts +0 -124
  394. package/packages/feedback/src/primitives/target.ts +0 -293
  395. package/packages/feedback/src/tour/canonical.ts +0 -27
  396. package/packages/feedback/src/tour/index.ts +0 -3
  397. package/packages/feedback/src/tour/player/browser.ts +0 -5
  398. package/packages/feedback/src/tour/player/host.ts +0 -12
  399. package/packages/feedback/src/tour/player/index.ts +0 -205
  400. package/packages/feedback/src/tour/player/manifest.ts +0 -76
  401. package/packages/feedback/src/tour/player/player.css +0 -130
  402. package/packages/feedback/src/tour/player/resolver.ts +0 -12
  403. package/packages/feedback/src/tour/player/surface.ts +0 -295
  404. package/packages/feedback/src/tour/player/types.ts +0 -8
  405. package/packages/feedback/src/tour/resolve/core.ts +0 -267
  406. package/packages/feedback/src/tour/resolve/dom.ts +0 -115
  407. package/packages/feedback/src/tour/resolve/index.ts +0 -29
  408. package/packages/feedback/src/tour/sanitize.ts +0 -76
  409. package/packages/feedback/src/tour/schema.ts +0 -362
  410. package/packages/feedback/src/v1/guards.ts +0 -335
  411. package/packages/feedback/src/v1/index.ts +0 -3
  412. package/packages/feedback/src/v1/protectedSurfaces.ts +0 -32
  413. package/packages/feedback/src/v1/types.ts +0 -177
  414. package/packages/feedback/tsconfig.json +0 -9
  415. package/packages/feedback/vitest.config.cts +0 -21
@@ -1,474 +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
- /**
49
- * The header carrying tot-mcp's short-lived GRANT ATTESTATION beside a DELEGATED
50
- * (sponsored-agent) broker assertion. tot20 accepts it only from the pinned tot-mcp
51
- * broker and resolves the sponsor only from it. Sent only on an agent entry; never
52
- * stored or logged by the storefront.
53
- */
54
- export const AGENT_GRANT_ATTESTATION_HEADER = "X-ToT-Agent-Grant-Attestation";
55
-
56
- /** Extra proof an agent entry carries (absent on every human staff entry). */
57
- export interface StaffVendorAccessOptions {
58
- grantAttestation?: string;
59
- }
60
-
61
- /** One vendor hit from a search — the minimum needed to render + select. */
62
- export interface VendorHit {
63
- appDomain: string;
64
- displayName: string;
65
- }
66
-
67
- /** Result of a vendor search (typed failure, fail-closed). */
68
- export type VendorSearchResult =
69
- | { ok: true; vendors: VendorHit[] }
70
- | { ok: false; status: number; reason: StaffAccessFailureReason; message: string; code?: string };
71
-
72
- /** Result of a staff-vendor-access grant — the staffRoles-scoped capability. */
73
- export type StaffVendorAccessResult =
74
- | { ok: true; capability: string }
75
- | { ok: false; status: number; reason: StaffAccessFailureReason; message: string; code?: string };
76
-
77
- /** Typed failure reasons mapped from tot20's error codes / HTTP status. */
78
- export type StaffAccessFailureReason =
79
- | "notStaff" // 403 — the email holds no ToT-staff scope (server-authoritative)
80
- | "notFound" // 404/422 — the vendor appDomain isn't a resolvable app
81
- | "invalid" // 400/422 — bad/empty query or vendor
82
- | "notAuthenticated" // 401/403 — storefront's operator credential was rejected
83
- | "error"; // transport / unexpected upstream fault
84
-
85
- export interface StaffVendorAccessClient {
86
- /**
87
- * Search vendors by appDomain prefix. `brokerAssertion` is the storefront-signed
88
- * staff proof (presented in the `X-ToT-Broker-Assertion` header); tot20 derives
89
- * the staff actor from its verified `sub` and scopes results to their staffRoles.
90
- */
91
- searchVendors(brokerAssertion: string, query: string, limit?: number): Promise<VendorSearchResult>;
92
- /**
93
- * Admit the staff actor (proven by `brokerAssertion`) to `vendorAppDomain`: tot20
94
- * verifies the assertion, writes the audit row, and returns the staffRoles-scoped
95
- * capability. Called on explicit enter, never a silent per-host grant.
96
- */
97
- grantStaffAccess(
98
- brokerAssertion: string,
99
- vendorAppDomain: string,
100
- options?: StaffVendorAccessOptions,
101
- ): Promise<StaffVendorAccessResult>;
102
- }
103
-
104
- // --- HTTP transport seam (injected by tests) --------------------------------
105
-
106
- export interface HttpResponseLike {
107
- status: number;
108
- json(): Promise<unknown>;
109
- }
110
- export interface HttpTransport {
111
- get(url: string, headers: Record<string, string>): Promise<HttpResponseLike>;
112
- post(url: string, headers: Record<string, string>, body: unknown): Promise<HttpResponseLike>;
113
- }
114
-
115
- /** Default transport: JSON `fetch` GET/POST. */
116
- export class FetchHttpTransport implements HttpTransport {
117
- async get(url: string, headers: Record<string, string>) {
118
- return fetch(url, { method: "GET", headers: { accept: "application/json", ...headers }, redirect: "manual" });
119
- }
120
- async post(url: string, headers: Record<string, string>, body: unknown) {
121
- return fetch(url, {
122
- method: "POST",
123
- headers: { "content-type": "application/json", accept: "application/json", ...headers },
124
- body: JSON.stringify(body),
125
- redirect: "manual",
126
- });
127
- }
128
- }
129
-
130
- export interface HttpStaffVendorAccessClientConfig {
131
- /** tot20 core API base (no trailing slash), e.g. https://qa.tokenoftrust.com */
132
- baseUrl: string;
133
- /** Storefront's OWN per-tier ToT credentials (machine auth to the operator API). */
134
- apiKey: string;
135
- secretKey?: string;
136
- transport?: HttpTransport;
137
- /** Default result cap when a caller passes no limit. */
138
- defaultLimit?: number;
139
- }
140
-
141
- export class StaffVendorAccessClientError extends Error {}
142
-
143
- const DEFAULT_LIMIT = 10;
144
- const MAX_LIMIT = 50;
145
-
146
- /** Clamp a caller-supplied limit into (0, MAX_LIMIT], defaulting when absent/bad. */
147
- function clampLimit(limit: number | undefined, fallback: number): number {
148
- const n = typeof limit === "number" ? Math.floor(limit) : NaN;
149
- if (!Number.isFinite(n) || n <= 0) return fallback;
150
- return Math.min(n, MAX_LIMIT);
151
- }
152
-
153
- // --- HTTP impl --------------------------------------------------------------
154
-
155
- export class HttpStaffVendorAccessClient implements StaffVendorAccessClient {
156
- private readonly baseUrl: string;
157
- private readonly apiKey: string;
158
- private readonly secretKey?: string;
159
- private readonly transport: HttpTransport;
160
- private readonly defaultLimit: number;
161
-
162
- constructor(config: HttpStaffVendorAccessClientConfig) {
163
- if (!config.baseUrl) {
164
- throw new StaffVendorAccessClientError("staffVendorAccess: TOT_CORE_URL is not configured");
165
- }
166
- if (!config.apiKey) {
167
- throw new StaffVendorAccessClientError(
168
- "staffVendorAccess: storefront ToT credentials are not configured",
169
- );
170
- }
171
- this.baseUrl = config.baseUrl.replace(/\/+$/, "");
172
- this.apiKey = config.apiKey;
173
- this.secretKey = config.secretKey;
174
- this.transport = config.transport ?? new FetchHttpTransport();
175
- this.defaultLimit = clampLimit(config.defaultLimit, DEFAULT_LIMIT);
176
- }
177
-
178
- /**
179
- * The one integration-sensitive spot: tot20 reads `totApiKey`/`totSecretKey`
180
- * from the request body/query (`normalizeSecureUserRequest`). Swap for a
181
- * machine-JWT `Authorization: Bearer` here if tot20 ever requires it.
182
- */
183
- private credentialFields(): Record<string, string> {
184
- const f: Record<string, string> = { totApiKey: this.apiKey };
185
- if (this.secretKey) f.totSecretKey = this.secretKey;
186
- return f;
187
- }
188
-
189
- async searchVendors(brokerAssertion: string, query: string, limit?: number): Promise<VendorSearchResult> {
190
- const q = (query ?? "").trim();
191
- if (!q) return { ok: true, vendors: [] }; // empty prefix → nothing to search
192
- // #8453 `staff-invite-proof-via-broker`: the staff actor is proven by the signed
193
- // assertion header — NEVER a plaintext `email` query param.
194
- const params = new URLSearchParams({
195
- q,
196
- limit: String(clampLimit(limit, this.defaultLimit)),
197
- ...this.credentialFields(),
198
- });
199
- const headers: Record<string, string> = {};
200
- if (brokerAssertion) headers[BROKER_ASSERTION_HEADER] = brokerAssertion;
201
- let res: HttpResponseLike;
202
- try {
203
- res = await this.transport.get(`${this.baseUrl}/api/clients/vendorSearch?${params.toString()}`, headers);
204
- } catch (cause) {
205
- return {
206
- ok: false,
207
- status: 0,
208
- reason: "error",
209
- message: "staffVendorAccess: transport failure searching vendors",
210
- };
211
- }
212
- if (res.status >= 300 && res.status < 400) {
213
- return { ok: false, status: res.status, reason: "error", message: "staffVendorAccess: redirects are not accepted" };
214
- }
215
- let parsed: unknown;
216
- try {
217
- parsed = await res.json();
218
- } catch {
219
- return {
220
- ok: false,
221
- status: res.status,
222
- reason: "error",
223
- message: `staffVendorAccess: tot20 returned a non-JSON body (status ${res.status})`,
224
- };
225
- }
226
- return normalizeVendorSearch(res.status, parsed);
227
- }
228
-
229
- async grantStaffAccess(
230
- brokerAssertion: string,
231
- vendorAppDomain: string,
232
- options: StaffVendorAccessOptions = {},
233
- ): Promise<StaffVendorAccessResult> {
234
- const vendor = (vendorAppDomain ?? "").trim();
235
- if (!vendor) {
236
- return { ok: false, status: 400, reason: "invalid", message: "a vendor appDomain is required" };
237
- }
238
- // #8453 `staff-invite-proof-via-broker`: the staff actor is proven by the signed
239
- // assertion header — NEVER a plaintext `email` body field.
240
- const headers: Record<string, string> = {};
241
- if (brokerAssertion) headers[BROKER_ASSERTION_HEADER] = brokerAssertion;
242
- if (options.grantAttestation) headers[AGENT_GRANT_ATTESTATION_HEADER] = options.grantAttestation;
243
- let res: HttpResponseLike;
244
- try {
245
- res = await this.transport.post(
246
- `${this.baseUrl}/api/clients/staffVendorAccess`,
247
- headers,
248
- { vendorAppDomain: vendor, ...this.credentialFields() },
249
- );
250
- } catch (cause) {
251
- return {
252
- ok: false,
253
- status: 0,
254
- reason: "error",
255
- message: "staffVendorAccess: transport failure granting access",
256
- };
257
- }
258
- if (res.status >= 300 && res.status < 400) {
259
- return { ok: false, status: res.status, reason: "error", message: "staffVendorAccess: redirects are not accepted" };
260
- }
261
- let parsed: unknown;
262
- try {
263
- parsed = await res.json();
264
- } catch {
265
- return {
266
- ok: false,
267
- status: res.status,
268
- reason: "error",
269
- message: `staffVendorAccess: tot20 returned a non-JSON body (status ${res.status})`,
270
- };
271
- }
272
- return normalizeStaffAccess(res.status, parsed);
273
- }
274
- }
275
-
276
- /** Unwrap tot20's `{ content, metadata }` envelope (fall back to the raw body). */
277
- function unwrap(body: unknown): Record<string, unknown> {
278
- const raw = (body ?? {}) as Record<string, unknown>;
279
- return (raw.content && typeof raw.content === "object" ? raw.content : raw) as Record<string, unknown>;
280
- }
281
-
282
- /** Parse tot20's vendorSearch response into a typed result (fail closed). */
283
- export function normalizeVendorSearch(status: number, body: unknown): VendorSearchResult {
284
- const c = unwrap(body);
285
- const code = typeof c.code === "string" ? c.code : undefined;
286
- const isOk =
287
- code === "vendorSearch:ok" || (status >= 200 && status < 300 && Array.isArray(c.vendors));
288
- if (isOk) {
289
- const vendors: VendorHit[] = (Array.isArray(c.vendors) ? c.vendors : [])
290
- .map((raw2) => {
291
- const r = (raw2 ?? {}) as Record<string, unknown>;
292
- const appDomain = typeof r.appDomain === "string" ? r.appDomain : "";
293
- return {
294
- appDomain,
295
- displayName: typeof r.displayName === "string" && r.displayName ? r.displayName : appDomain,
296
- };
297
- })
298
- .filter((v) => v.appDomain);
299
- return { ok: true, vendors };
300
- }
301
- return failure(status, c);
302
- }
303
-
304
- /** Parse tot20's staffVendorAccess response into a typed result (fail closed). */
305
- export function normalizeStaffAccess(status: number, body: unknown): StaffVendorAccessResult {
306
- const c = unwrap(body);
307
- const code = typeof c.code === "string" ? c.code : undefined;
308
- const isOk =
309
- code === "staffVendorAccess:granted" ||
310
- (status >= 200 && status < 300 && typeof c.capability === "string");
311
- if (isOk) {
312
- return { ok: true, capability: typeof c.capability === "string" ? c.capability : "staff" };
313
- }
314
- return failure(status, c);
315
- }
316
-
317
- /** Map an error envelope onto a typed failure by tot20 `code` then HTTP status. */
318
- function failure(
319
- status: number,
320
- c: Record<string, unknown>,
321
- ): { ok: false; status: number; reason: StaffAccessFailureReason; message: string; code?: string } {
322
- const code = typeof c.code === "string" ? c.code : undefined;
323
- const reason = reasonFor(code, status);
324
- return { ok: false, status, reason, message: staffAccessFailureMessage(reason), ...(code ? { code } : {}) };
325
- }
326
-
327
- function reasonFor(code: string | undefined, status: number): StaffAccessFailureReason {
328
- switch (code) {
329
- case "staffVendorAccess:notStaff":
330
- return "notStaff";
331
- case "staffVendorAccess:vendorNotFound":
332
- case "vendorSearch:vendorNotFound":
333
- return "notFound";
334
- case "staffVendorAccess:invalid":
335
- case "vendorSearch:invalid":
336
- return "invalid";
337
- case "operatorGrants:notAuthenticated":
338
- return "notAuthenticated";
339
- default:
340
- if (status === 401) return "notAuthenticated";
341
- if (status === 403) return "notStaff";
342
- if (status === 404) return "notFound";
343
- if (status === 400 || status === 422) return "invalid";
344
- return "error";
345
- }
346
- }
347
-
348
- /**
349
- * Map a typed failure onto the HTTP status a storefront endpoint should return:
350
- * notStaff/notAuthenticated → 403; notFound → 404; invalid → 400; a transport /
351
- * unexpected fault → the upstream status if it's an error, else 502.
352
- */
353
- export function staffAccessHttpStatus(reason: StaffAccessFailureReason, upstreamStatus: number): number {
354
- switch (reason) {
355
- case "notStaff":
356
- case "notAuthenticated":
357
- return 403;
358
- case "notFound":
359
- return 404;
360
- case "invalid":
361
- return 400;
362
- default:
363
- return upstreamStatus >= 400 ? upstreamStatus : 502;
364
- }
365
- }
366
-
367
- /** Finite staff-facing copy for a staff-access refusal — the only text a route returns. */
368
- export function staffAccessFailureMessage(reason: StaffAccessFailureReason): string {
369
- switch (reason) {
370
- case "notStaff":
371
- return "this account doesn't hold ToT-staff access to that vendor";
372
- case "notAuthenticated":
373
- return "storefront's operator credential was rejected";
374
- case "notFound":
375
- return "that vendor is not a resolvable Token of Trust app";
376
- case "invalid":
377
- return "a valid vendor is required";
378
- default:
379
- return "Token of Trust couldn't complete the staff-access request; try again shortly";
380
- }
381
- }
382
-
383
- // --- Mock (tests + local dev) -----------------------------------------------
384
-
385
- /**
386
- * In-memory StaffVendorAccessClient. Seeded with a directory of vendors and the
387
- * set of staff emails, it drives route + client tests deterministically and lets
388
- * local dev exercise the search+enter flow before/without the live tot20 endpoint.
389
- */
390
- export class MockStaffVendorAccessClient implements StaffVendorAccessClient {
391
- private readonly vendors: VendorHit[];
392
- private readonly staff: Set<string>;
393
- private readonly capability: string;
394
- /** Recorded admissions, for assertions (the audit row tot20 would write). */
395
- granted: Array<{ email: string; vendorAppDomain: string }> = [];
396
-
397
- constructor(opts: { vendors?: VendorHit[]; staffEmails?: string[]; capability?: string } = {}) {
398
- this.vendors = opts.vendors ?? [];
399
- this.staff = new Set((opts.staffEmails ?? []).map((e) => e.toLowerCase()));
400
- this.capability = opts.capability ?? "staff";
401
- }
402
-
403
- /**
404
- * Derive the staff actor's email from the broker assertion's `sub` — simulating
405
- * tot20 deriving it from the VERIFIED assertion. The Mock only DECODES (never
406
- * verifies the signature); the real tot20 verifies. Returns "" for an
407
- * absent/malformed assertion so a proofless call fails the staff check.
408
- */
409
- private actorEmail(brokerAssertion: string): string {
410
- if (!brokerAssertion || !brokerAssertion.trim()) return "";
411
- try {
412
- const sub = decodeJwt(brokerAssertion).sub;
413
- return typeof sub === "string" ? sub.toLowerCase() : "";
414
- } catch {
415
- return "";
416
- }
417
- }
418
-
419
- async searchVendors(_brokerAssertion: string, query: string, limit?: number): Promise<VendorSearchResult> {
420
- const q = (query ?? "").trim().toLowerCase();
421
- if (!q) return { ok: true, vendors: [] };
422
- const cap = clampLimit(limit, DEFAULT_LIMIT);
423
- const vendors = this.vendors
424
- .filter(
425
- (v) =>
426
- v.appDomain.toLowerCase().startsWith(q) || v.displayName.toLowerCase().includes(q),
427
- )
428
- .slice(0, cap);
429
- return { ok: true, vendors };
430
- }
431
-
432
- async grantStaffAccess(brokerAssertion: string, vendorAppDomain: string): Promise<StaffVendorAccessResult> {
433
- const vendor = (vendorAppDomain ?? "").trim();
434
- if (!vendor) return { ok: false, status: 400, reason: "invalid", message: "a vendor appDomain is required" };
435
- const email = this.actorEmail(brokerAssertion);
436
- if (!email || !this.staff.has(email)) {
437
- return {
438
- ok: false,
439
- status: 403,
440
- reason: "notStaff",
441
- message: "this account doesn't hold ToT-staff access to that vendor",
442
- code: "staffVendorAccess:notStaff",
443
- };
444
- }
445
- if (!this.vendors.some((v) => v.appDomain === vendor)) {
446
- return {
447
- ok: false,
448
- status: 404,
449
- reason: "notFound",
450
- message: "that vendor is not a resolvable Token of Trust app",
451
- code: "staffVendorAccess:vendorNotFound",
452
- };
453
- }
454
- this.granted.push({ email, vendorAppDomain: vendor });
455
- return { ok: true, capability: this.capability };
456
- }
457
- }
458
-
459
- // --- Factory ----------------------------------------------------------------
460
-
461
- /**
462
- * Build the env-configured client:
463
- * - `TOT_CORE_URL` — tot20 core API base (tier-matching per deploy).
464
- * - `TOT_API_KEY` (+ optional `TOT_SECRET_KEY`) — storefront's own operator creds.
465
- * Throws {@link StaffVendorAccessClientError} when unconfigured (routes map that to 503).
466
- */
467
- export async function createStaffVendorAccessClient(
468
- overrides: Partial<HttpStaffVendorAccessClientConfig> = {},
469
- ): Promise<HttpStaffVendorAccessClient> {
470
- const baseUrl = overrides.baseUrl ?? (await readEnv("TOT_CORE_URL")) ?? "";
471
- const apiKey = overrides.apiKey ?? (await readEnv("TOT_API_KEY")) ?? "";
472
- const secretKey = overrides.secretKey ?? (await readEnv("TOT_SECRET_KEY"));
473
- return new HttpStaffVendorAccessClient({ ...overrides, baseUrl, apiKey, secretKey });
474
- }
@@ -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
- }
@@ -1,67 +0,0 @@
1
- import { DEFAULT_CHECKOUT_STYLE } from "@tot/public-runtime";
2
- import type { AdminTenantEnvelope } from "../admin/envelope";
3
- import { memoizeByEnvelope } from "../../developer-experience/admin/memoizeByEnvelope";
4
- import { MOCK_ANCHOR_ISO, offsetIso, randomInt, seededRandom } from "../../developer-experience/admin/seed";
5
- import type { SettingsAuditEvent, SettingsSection, SettingsViewModel } from "../admin/viewmodels/settings";
6
-
7
- const SECTION_DEFS: Omit<SettingsSection, "riskyChangeReview">[] = [
8
- { key: "store", label: "Store", summary: "Store profile, branding, and white-label copy." },
9
- { key: "checkout", label: "Checkout", summary: "Checkout assurance and identity/age verification flow." },
10
- { key: "cart_appearance", label: "Cart & checkout appearance", summary: "Hosted checkout colors and templates, prepopulated from the theme." },
11
- { key: "payments", label: "Payments", summary: "Payment capture timing and gateway configuration." },
12
- { key: "shipping", label: "Shipping", summary: "Carriers, rates, and shipping restrictions by region." },
13
- { key: "taxes", label: "Taxes", summary: "Excise and sales tax configuration by jurisdiction." },
14
- { key: "products", label: "Products", summary: "Catalog and category-to-tax-class mappings." },
15
- { key: "customers", label: "Customers", summary: "Segmentation and support-flag rules." },
16
- { key: "notifications", label: "Notifications", summary: "Merchant and customer notification templates." },
17
- { key: "users_access", label: "Users & access", summary: "Staff roles, permissions, and internal tenant picker access." },
18
- { key: "integrations", label: "Integrations", summary: "Connected services and API credentials." },
19
- { key: "compliance", label: "Compliance", summary: "Evidence retention and reporting cadence." },
20
- { key: "ai_admin_policy", label: "AI / admin policy", summary: "AI guardrails and approval mode for assist surfaces." },
21
- ];
22
-
23
- const RISKY_SECTIONS = new Set(["payments", "shipping", "taxes", "users_access", "ai_admin_policy"]);
24
-
25
- function computeSettingsViewModel(envelope: AdminTenantEnvelope): SettingsViewModel {
26
- const { targetTenant } = envelope;
27
- const rng = seededRandom(`settings:${targetTenant}`);
28
-
29
- const sections: SettingsSection[] = SECTION_DEFS.map((def) => ({
30
- ...def,
31
- riskyChangeReview: RISKY_SECTIONS.has(def.key),
32
- }));
33
-
34
- const auditTrail: SettingsAuditEvent[] = [
35
- {
36
- operator: "internal-staff@tokenoftrust.com",
37
- targetTenant,
38
- action: "settings.shipping_restrictions.updated",
39
- change: "Updated shipping restriction list",
40
- at: offsetIso(MOCK_ANCHOR_ISO, -randomInt(rng, 60, 5000)),
41
- },
42
- ];
43
-
44
- return {
45
- targetTenant,
46
- sections,
47
- shippingRestrictions: [
48
- { region: "Utah", reason: "Vapor product shipping restriction" },
49
- { region: "Massachusetts", reason: "Flavored tobacco restriction" },
50
- ],
51
- aiPolicyMode: "approval_required",
52
- internalTenantPickerEnabled: true,
53
- auditTrail,
54
- // The neutral baseline (an un-styled tenant). The Settings tab renders the
55
- // store's draft (resolveCheckoutStyle on `test`) in its place, and falls
56
- // back to this only when the store cannot be read. Cloning keeps the shared
57
- // DEFAULT_CHECKOUT_STYLE constant immutable if a caller mutates the view model.
58
- checkoutStyle: {
59
- ...DEFAULT_CHECKOUT_STYLE,
60
- colors: { ...DEFAULT_CHECKOUT_STYLE.colors },
61
- typography: { ...DEFAULT_CHECKOUT_STYLE.typography },
62
- button: { ...DEFAULT_CHECKOUT_STYLE.button },
63
- },
64
- };
65
- }
66
-
67
- export const getSettingsViewModel = memoizeByEnvelope(computeSettingsViewModel);
@@ -1,29 +0,0 @@
1
- /**
2
- * Seeded tenant registry for admin mock data. Two curated tenants give the
3
- * console realistic, vertical-flavored demo data; any other `targetTenant`
4
- * still gets a stable (if generic) profile via deterministic fallback, so no
5
- * caller has to special-case "unknown" tenants.
6
- */
7
-
8
- export type MockVertical = "vape" | "tobacco";
9
-
10
- export interface SeededTenantProfile {
11
- targetTenant: string;
12
- displayName: string;
13
- vertical: MockVertical;
14
- }
15
-
16
- export const SEEDED_TENANTS: readonly SeededTenantProfile[] = [
17
- { targetTenant: "northridge-vapor.com", displayName: "Northridge Vapor Co.", vertical: "vape" },
18
- { targetTenant: "cascade-tobacco.com", displayName: "Cascade Tobacco Exchange", vertical: "tobacco" },
19
- ];
20
-
21
- /** Deterministic fallback profile for any tenant not in `SEEDED_TENANTS`. */
22
- function fallbackProfile(targetTenant: string): SeededTenantProfile {
23
- const vertical: MockVertical = targetTenant.length % 2 === 0 ? "vape" : "tobacco";
24
- return { targetTenant, displayName: targetTenant, vertical };
25
- }
26
-
27
- export function tenantProfile(targetTenant: string): SeededTenantProfile {
28
- return SEEDED_TENANTS.find((t) => t.targetTenant === targetTenant) ?? fallbackProfile(targetTenant);
29
- }