@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,253 +0,0 @@
1
- /**
2
- * A SPONSORED AGENT entering a store: the one way an agent session gains any standing
3
- * on a tenant (#8500 sponsored agents; ADR capabilities-management §11; review X4).
4
- *
5
- * An agent session holds nothing locally (`staff []`, `tenants []`, no email). tot20
6
- * decides every entry, and it decides from proof the storefront cannot forge alone:
7
- *
8
- * 1. a FRESH grant attestation, fetched from the trusted MCP that introspected the
9
- * agent's token (`POST /internal/dev-access/agent-grant-attestation`, bound by the
10
- * route as `fetchAttestation`). tot-mcp
11
- * re-reads the grant live and answers `{ attestation: null }` once it is revoked
12
- * or expired, so a dead grant is refused here (403) without reaching tot20;
13
- * 2. a DELEGATED broker assertion: `sub` and `act.sub` are the agent, `grantId` the
14
- * grant, `tenant` the one store. Never a sponsor-email assertion;
15
- * 3. tot20 `staffVendorAccess`, presented with both. The ONLY capability accepted
16
- * back is `read`; anything else is refused and nothing is stamped.
17
- *
18
- * On success a short selection keyed to `actor.id` + `actor.grantId` is persisted under
19
- * a fresh, expiry-preserving session id. It lasts at most one staff-selection window
20
- * (and never past the session), and re-entry repeats all three steps.
21
- *
22
- * Every fault fails closed: an MCP or tot20 fault is 503, and nothing falls back to the
23
- * human path, a sponsor assertion or a cached attestation. The attestation is used in
24
- * flight for the one tot20 call and is never stored or logged.
25
- */
26
- import type { SessionRecord, SessionStore, StaffSelection } from "@/lib/access/auth/session";
27
- import { isAgentSession, readSession, rotateSession } from "@/lib/access/auth/session";
28
- import { STAFF_SELECTION_TTL_SECONDS } from "./staffAdmission";
29
- import {
30
- createStaffVendorAccessClient,
31
- staffAccessFailureMessage,
32
- staffAccessHttpStatus,
33
- StaffVendorAccessClientError,
34
- } from "./staffVendorAccess";
35
- import { BrokerAssertionError, mintDelegatedBrokerAssertion } from "@/lib/access/auth/brokerAssertion";
36
- import type { StaffEntryEvent, StaffStoreEntryResult } from "./staffStoreEntry";
37
-
38
- /** The only capability an agent entry may hold (PII-blind rules arrive separately). */
39
- export const AGENT_ENTRY_CAPABILITY = "read";
40
-
41
- /**
42
- * Fetches a fresh grant attestation from the session's own MCP: the attestation when
43
- * the grant is live, `null` when it is dead, `"fault"` when that cannot be known
44
- * (including an untrusted origin). The route binds the tot-mcp seam implementation
45
- * (`fetchAgentGrantAttestation`).
46
- */
47
- export type AgentGrantAttestationFetcher = (request: {
48
- grantId: string;
49
- agentId: string;
50
- mcpOrigin: string;
51
- }) => Promise<string | null | "fault">;
52
-
53
- /** True when the grant names this tenant (by appDomain or tenant id), or any tenant. */
54
- export function grantNamesTenant(
55
- grantTenants: readonly string[] | "*",
56
- tenant: { appDomain?: string; tenant_id?: string } | string,
57
- ): boolean {
58
- if (grantTenants === "*") return true;
59
- const names = typeof tenant === "string"
60
- ? [tenant]
61
- : [tenant.appDomain, tenant.tenant_id];
62
- const wanted = names.filter((n): n is string => !!n).map((n) => n.trim().toLowerCase());
63
- return grantTenants.some((t) => typeof t === "string" && wanted.includes(t.trim().toLowerCase()));
64
- }
65
-
66
- /**
67
- * True when the agent session holds a LIVE delegated selection for `resource`: decided
68
- * for THIS agent and grant, `read` only, unexpired. Anything else is not live, so the
69
- * caller re-enters (and tot20 decides again).
70
- */
71
- export function agentSelectionLive(
72
- session: SessionRecord | null | undefined,
73
- resource: string,
74
- nowSeconds: number,
75
- ): boolean {
76
- if (!isAgentSession(session)) return false;
77
- const selection = session.staffSelection;
78
- return !!selection &&
79
- selection.resource === resource &&
80
- selection.capability === AGENT_ENTRY_CAPABILITY &&
81
- selection.agentId === session.actor.id &&
82
- selection.grantId === session.actor.grantId &&
83
- selection.exp > nowSeconds;
84
- }
85
-
86
- export interface AgentStoreEntryInput {
87
- /** The agent session (must carry `actor.kind 'agent'`). */
88
- session: SessionRecord;
89
- /** The store to enter, by appDomain. Must be the session's bound tenant. */
90
- vendorAppDomain: string;
91
- /** Records each entry outcome; the route binds it to its activity actor. */
92
- emit: (event: StaffEntryEvent) => void;
93
- /** The persisted session to stamp the selection on (null id = not yet persisted). */
94
- sessionHandle: () => Promise<{ store: SessionStore; id: string | null } | null>;
95
- /** Fetches a fresh grant attestation, pinned to `actor.mcpOrigin`. */
96
- fetchAttestation: AgentGrantAttestationFetcher;
97
- }
98
-
99
- type Refusal = Extract<StaffStoreEntryResult, { ok: false }>;
100
-
101
- /** The closed set of local refusal reasons: a code, never free text. */
102
- type AgentRefusalReason =
103
- | "notAgent"
104
- | "tenantNotGranted"
105
- | "sessionExpired"
106
- | "unconfigured"
107
- | "mcpUnavailable"
108
- | "grantInactive"
109
- | "capabilityNotRead"
110
- | "sessionStoreUnavailable";
111
-
112
- function refusal(status: number, error: string, reason: AgentRefusalReason): Refusal {
113
- return { ok: false, status, body: { error, reason } };
114
- }
115
-
116
- /** Ask tot20 to decide this agent's entry, then persist the `read` selection it grants. */
117
- export async function enterStoreAsAgent(input: AgentStoreEntryInput): Promise<StaffStoreEntryResult> {
118
- const { session, emit } = input;
119
- if (!isAgentSession(session)) {
120
- return refusal(403, "agent session required", "notAgent");
121
- }
122
- const actor = session.actor;
123
- const vendorAppDomain = input.vendorAppDomain.trim();
124
- const refused = (errorClass: string, capability?: string): void =>
125
- emit({
126
- outcome: { status: "refused", errorClass },
127
- scope: { tenantId: vendorAppDomain },
128
- payload: { args: { resource: vendorAppDomain, ...(capability ? { capability } : {}) } },
129
- });
130
- const failed = (errorClass: string): void =>
131
- emit({
132
- outcome: { status: "failed", errorClass },
133
- scope: { tenantId: vendorAppDomain },
134
- payload: { args: { resource: vendorAppDomain, capability: AGENT_ENTRY_CAPABILITY } },
135
- });
136
-
137
- // One tenant per session: refused locally, so tot20 is never asked about any other
138
- // store. `boundTenant` was admitted against the grant's tenants when the session was
139
- // minted (cli-session), and the server-side record cannot change it.
140
- if (!vendorAppDomain || !actor.boundTenant || vendorAppDomain !== actor.boundTenant) {
141
- refused("tenant_not_granted");
142
- return refusal(403, "this agent session is not granted that store", "tenantNotGranted");
143
- }
144
- const nowSeconds = Math.floor(Date.now() / 1000);
145
- if (session.exp <= nowSeconds) {
146
- return refusal(401, "session expired; sign in again", "sessionExpired");
147
- }
148
- let client;
149
- try {
150
- client = await createStaffVendorAccessClient();
151
- } catch (err) {
152
- if (err instanceof StaffVendorAccessClientError) {
153
- return refusal(503, "staff-access integration not configured", "unconfigured");
154
- }
155
- throw err;
156
- }
157
-
158
- let attestation: string | null | "fault";
159
- try {
160
- attestation = await input.fetchAttestation({ grantId: actor.grantId, agentId: actor.id, mcpOrigin: actor.mcpOrigin });
161
- } catch {
162
- attestation = "fault";
163
- }
164
- if (attestation === "fault") {
165
- failed("attestation_unavailable");
166
- return refusal(503, "agent grant authority unavailable; retry shortly", "mcpUnavailable");
167
- }
168
- if (attestation === null) {
169
- refused("grant_inactive");
170
- return refusal(403, "this agent's grant is not active", "grantInactive");
171
- }
172
-
173
- let assertion: string;
174
- try {
175
- assertion = await mintDelegatedBrokerAssertion({
176
- sub: actor.id,
177
- act: { sub: actor.id },
178
- grantId: actor.grantId,
179
- tenant: vendorAppDomain,
180
- });
181
- } catch (err) {
182
- if (err instanceof BrokerAssertionError) {
183
- return refusal(503, "staff-proof signing not configured", "unconfigured");
184
- }
185
- throw err;
186
- }
187
-
188
- const result = await client.grantStaffAccess(assertion, vendorAppDomain, { grantAttestation: attestation });
189
- if (!result.ok) {
190
- refused(result.reason ?? `http_${result.status}`);
191
- const status = result.reason === "error" ? 503 : staffAccessHttpStatus(result.reason, result.status);
192
- return {
193
- ok: false,
194
- status,
195
- body: { error: staffAccessFailureMessage(result.reason), reason: result.reason, code: result.code },
196
- };
197
- }
198
- if (result.capability !== AGENT_ENTRY_CAPABILITY) {
199
- // tot20 is the authority, but an agent entry is read-only by contract: a wider
200
- // answer is refused rather than stamped.
201
- refused("capability_not_read", result.capability);
202
- return refusal(403, "an agent may enter a store read-only", "capabilityNotRead");
203
- }
204
-
205
- const selection: StaffSelection = {
206
- resource: vendorAppDomain,
207
- capability: AGENT_ENTRY_CAPABILITY,
208
- exp: nowSeconds + Math.max(1, Math.min(STAFF_SELECTION_TTL_SECONDS, session.exp - nowSeconds)),
209
- agentId: actor.id,
210
- grantId: actor.grantId,
211
- };
212
- const handle = await input.sessionHandle();
213
- if (!handle) {
214
- failed("session_store_unavailable");
215
- return refusal(503, "session store unavailable; cannot persist admission", "sessionStoreUnavailable");
216
- }
217
- let updated;
218
- try {
219
- const current = handle.id ? await readSession(handle.store, handle.id, nowSeconds) : session;
220
- updated = isAgentSession(current) &&
221
- current.actor.id === actor.id &&
222
- current.actor.grantId === actor.grantId &&
223
- current.actor.boundTenant === actor.boundTenant &&
224
- current.exp > nowSeconds
225
- ? await rotateSession(handle.store, {
226
- ...current,
227
- createdAt: session.createdAt,
228
- exp: Math.min(current.exp, session.exp),
229
- staffSelection: { ...selection, exp: Math.min(selection.exp, current.exp, session.exp) },
230
- }, nowSeconds)
231
- : null;
232
- } catch {
233
- failed("session_store_unavailable");
234
- return refusal(503, "session store unavailable; cannot persist admission", "sessionStoreUnavailable");
235
- }
236
- if (!updated) {
237
- failed("session_expired");
238
- return refusal(401, "session expired; sign in again", "sessionExpired");
239
- }
240
-
241
- emit({
242
- outcome: { status: "succeeded" },
243
- scope: { tenantId: vendorAppDomain },
244
- payload: { args: { resource: vendorAppDomain, capability: AGENT_ENTRY_CAPABILITY } },
245
- });
246
- return {
247
- ok: true,
248
- selection: updated.record.staffSelection ?? selection,
249
- capability: AGENT_ENTRY_CAPABILITY,
250
- sessionId: updated.id,
251
- expiresIn: updated.record.exp - nowSeconds,
252
- };
253
- }
@@ -1,130 +0,0 @@
1
- /**
2
- * The owner "Grant access" gate on /dashboard/<appDomain>/team, as a PURE
3
- * decision — who sees the control, and what everyone else is told instead.
4
- *
5
- * The gate itself is unchanged and stays OWNER-ONLY: `/api/grants/principal`
6
- * refuses anything but a real owner (mirroring tot20's `ownsTenant`), so showing
7
- * the control to an admin would only ever produce a 403. What changes here is
8
- * that every OTHER viewer now gets an explicit sentence naming their actual role,
9
- * instead of the section vanishing with no explanation — a hidden control is
10
- * indistinguishable from a broken one, and that ambiguity has already cost a
11
- * live debugging session.
12
- *
13
- * Why staff get a REFUSAL and not a bypass: `ship-on-behalf` is a grant-required
14
- * operation under `guidance://access-authority` — it is not required to keep the
15
- * store's service running, so it runs on owner consent even when an admin or ToT
16
- * staff performs it. Staff capture that consent and issue the grant with their
17
- * own attestation on the record; they never self-serve it from a staff boolean.
18
- * Do NOT "fix" the staff state by widening {@link resolveDelegateGate} to admit
19
- * `mode: "staff"` — that is the confused-deputy hole the model exists to close.
20
- *
21
- * PURE (no I/O, no Astro) so all four states are unit-testable without rendering
22
- * the page, matching `@/lib/dashboard/tenantSelection` and `@/lib/auth/loginGate`.
23
- */
24
- import { storefrontModeAllowsGoLive } from "@tot/public-runtime";
25
- import { membershipFor, staffAdmits } from "@/lib/access/dashboard/tenantSelection";
26
- import type { StaffAdmission, TenantMembership } from "@/lib/access/dashboard/tenantSelection";
27
-
28
- /** What every viewer of an unpaid store is told in place of the delegate section. */
29
- export const UNPAID_DELEGATION_NOTE =
30
- "Developers you've invited can already add changes and publish them while the store is " +
31
- "unpaid — no delegation needed. Ship-on-behalf delegation becomes available once the live " +
32
- "site is activated.";
33
-
34
- /** A capability the owner's grant form offers. */
35
- export type OwnerGrantCapability = "ship-on-behalf" | "customer-contact-read";
36
-
37
- /**
38
- * What the owner's "Grant access" form offers this viewer. Customer contact access is a support
39
- * grant unrelated to payment, so a real owner always gets it. Ship-on-behalf is offered only once
40
- * the store can go live: before that an invited developer can already add changes AND publish
41
- * them (both `merge-to-preview` and `publish-live` admit the "unpaid-store-developer" basis,
42
- * lib/publication/pipeline/admission.ts), so the owner sees {@link UNPAID_DELEGATION_NOTE} for it
43
- * instead. A non-owner gets no form and the gate's explanation. PURE.
44
- */
45
- export function resolveOwnerGrantForm(
46
- storefrontMode: string | null | undefined,
47
- tenants: readonly TenantMembership[] | undefined,
48
- resource: string,
49
- staff?: StaffAdmission,
50
- ): { offers: OwnerGrantCapability[]; note: string | null; gate: DelegateGate } {
51
- const gate = resolveDelegateGate(tenants, resource, staff);
52
- if (gate.mode !== "owner") return { offers: [], note: gate.explanation, gate };
53
- const paid = storefrontModeAllowsGoLive(storefrontMode);
54
- return {
55
- offers: paid ? ["ship-on-behalf", "customer-contact-read"] : ["customer-contact-read"],
56
- note: paid ? null : UNPAID_DELEGATION_NOTE,
57
- gate,
58
- };
59
- }
60
-
61
- /**
62
- * What the delegate section renders for this viewer.
63
- *
64
- * - `owner` — a real `tenants[]` membership with coarse role `owner`. The only
65
- * state that renders the control.
66
- * - `member` — a real membership that is not owner (`admin`, `member`, …).
67
- * - `staff` — no real membership; admitted by a LIVE ToT-staff vendor selection.
68
- * `role` is the selection's capability, not a membership role.
69
- * - `none` — neither. Unreachable from team.astro (its `membershipFor` guard
70
- * redirects to /dashboard first), but represented so the function is total and
71
- * no input can ever produce a silently blank section.
72
- */
73
- export type DelegateGate =
74
- | { mode: "owner" }
75
- | { mode: "member"; role: string; explanation: string }
76
- | { mode: "staff"; role: string; explanation: string }
77
- | { mode: "none"; role: null; explanation: string };
78
-
79
- /**
80
- * Resolve the delegate gate for a viewer.
81
- *
82
- * Order matters and mirrors {@link membershipFor}: a REAL membership always wins
83
- * over a staff selection, so a ToT staffer who is also a genuine owner of this
84
- * store is treated as the owner they are. Only a viewer with no membership at all
85
- * falls through to the staff branch.
86
- *
87
- * The role string is surfaced verbatim in the explanation on purpose. The coarse
88
- * role reaching `tenants[]` is the end of a five-hop chain (tot20 `appSpec.users`
89
- * → `collapseCapability` → `coarseRole` → the signed id_token → the storefront's
90
- * `coerceRole`, which defaults anything unrecognised to `member`). Naming the
91
- * value the page actually received turns "why is this hidden?" into a one-glance
92
- * answer instead of a trace through both repos.
93
- */
94
- export function resolveDelegateGate(
95
- tenants: readonly TenantMembership[] | undefined,
96
- resource: string,
97
- staff?: StaffAdmission,
98
- ): DelegateGate {
99
- const target = (resource ?? "").trim();
100
- const membership = membershipFor(tenants, target);
101
- if (membership) {
102
- if (membership.role === "owner") return { mode: "owner" };
103
- return {
104
- mode: "member",
105
- role: membership.role,
106
- explanation:
107
- `Only the store owner can delegate ship-on-behalf. Your role on ${target} is ` +
108
- `“${membership.role}”. Ask an owner to set up the delegation, or to make you one.`,
109
- };
110
- }
111
-
112
- if (staffAdmits(staff, target)) {
113
- const role = staff!.selection!.capability;
114
- return {
115
- mode: "staff",
116
- role,
117
- explanation:
118
- `You’re here through Token of Trust staff access (“${role}”), not as a member of ` +
119
- `${target}. Delegating ship-on-behalf is the owner’s own control, so it isn’t ` +
120
- `offered here — capture the owner’s consent and issue the grant on their behalf instead.`,
121
- };
122
- }
123
-
124
- return {
125
- mode: "none",
126
- role: null,
127
- explanation:
128
- `You don’t hold a role on ${target}, so ship-on-behalf delegation isn’t available here.`,
129
- };
130
- }
@@ -1,153 +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 { isAgentSession, 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
- // A sponsored agent never enters as staff: it holds no staff standing, and a
61
- // sponsor-email assertion would hand it the sponsor's capability (review X4). Its
62
- // only entry is the delegated one tot20 decides (`enterStoreAsAgent`).
63
- if (isAgentSession(session) || !isStaffSession(session)) {
64
- return { ok: false, status: 403, body: { error: "staff access required", reason: "notStaff" } };
65
- }
66
-
67
- let client;
68
- try {
69
- client = await createStaffVendorAccessClient();
70
- } catch (err) {
71
- if (err instanceof StaffVendorAccessClientError) {
72
- return { ok: false, status: 503, body: { error: "staff-access integration not configured" } };
73
- }
74
- throw err;
75
- }
76
-
77
- let brokerAssertion: string;
78
- try {
79
- brokerAssertion = await mintBrokerAssertion(session.email);
80
- } catch (err) {
81
- if (err instanceof BrokerAssertionError) {
82
- return { ok: false, status: 503, body: { error: "staff-proof signing not configured" } };
83
- }
84
- throw err;
85
- }
86
-
87
- const result = await client.grantStaffAccess(brokerAssertion, vendorAppDomain);
88
- if (!result.ok) {
89
- emit({
90
- outcome: { status: "refused", errorClass: result.reason ?? `http_${result.status}` },
91
- scope: { tenantId: vendorAppDomain },
92
- payload: { args: { resource: vendorAppDomain } },
93
- });
94
- return {
95
- ok: false,
96
- status: staffAccessHttpStatus(result.reason, result.status),
97
- body: { error: staffAccessFailureMessage(result.reason), reason: result.reason, code: result.code },
98
- };
99
- }
100
-
101
- const nowSeconds = Math.floor(Date.now() / 1000);
102
- const selection = buildStaffSelection({
103
- resource: vendorAppDomain,
104
- capability: result.capability,
105
- nowSeconds,
106
- ttlSeconds: Math.max(1, Math.min(STAFF_SELECTION_TTL_SECONDS, session.exp - nowSeconds)),
107
- });
108
- const handle = await input.sessionHandle();
109
- if (!handle) {
110
- // The audit row is written but the marker cannot persist (no SESSION KV / no
111
- // cookie): fail closed so the caller is never told it is admitted.
112
- emit({
113
- outcome: { status: "failed", errorClass: "session_store_unavailable" },
114
- scope: { tenantId: vendorAppDomain },
115
- payload: { args: { resource: vendorAppDomain, capability: result.capability } },
116
- });
117
- return { ok: false, status: 503, body: { error: "session store unavailable; cannot persist admission" } };
118
- }
119
- let updated;
120
- try {
121
- const current = handle.id ? await readSession(handle.store, handle.id, nowSeconds) : session;
122
- updated = current && current.email === session.email && current.subject === session.subject && isStaffSession(current) && current.exp > nowSeconds
123
- ? await rotateSession(handle.store, {
124
- ...current,
125
- createdAt: session.createdAt,
126
- exp: Math.min(current.exp, session.exp),
127
- staffSelection: { ...selection, exp: Math.min(selection.exp, current.exp, session.exp) },
128
- }, nowSeconds)
129
- : null;
130
- } catch {
131
- emit({
132
- outcome: { status: "failed", errorClass: "session_store_unavailable" },
133
- scope: { tenantId: vendorAppDomain },
134
- payload: { args: { resource: vendorAppDomain, capability: result.capability } },
135
- });
136
- return { ok: false, status: 503, body: { error: "session store unavailable; cannot persist admission" } };
137
- }
138
- if (!updated) {
139
- emit({
140
- outcome: { status: "failed", errorClass: "session_expired" },
141
- scope: { tenantId: vendorAppDomain },
142
- payload: { args: { resource: vendorAppDomain, capability: result.capability } },
143
- });
144
- return { ok: false, status: 401, body: { error: "session expired; sign in again" } };
145
- }
146
-
147
- emit({
148
- outcome: { status: "succeeded" },
149
- scope: { tenantId: vendorAppDomain },
150
- payload: { args: { resource: vendorAppDomain, capability: result.capability } },
151
- });
152
- return { ok: true, selection, capability: result.capability, sessionId: updated.id, expiresIn: updated.record.exp - nowSeconds };
153
- }