@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,162 +0,0 @@
1
- /**
2
- * What debug mode is ALLOWED to capture (ADR 0034).
3
- *
4
- * THE DIRECTION IS THE DECISION. This is an allowlist, not a denylist. A denylist captures every new
5
- * field until someone remembers to exclude it, which makes the leak the default and guarantees that
6
- * the one field nobody thought about is the one that ships. Here a new field is invisible until
7
- * somebody deliberately adds it, and the cost — some bugs still need us — is accepted.
8
- *
9
- * The permitted set is derived from what the flows actually emit, not invented:
10
- * - operation stages are a CLOSED set (`operation-contract.ts`), so they cannot carry tenant data;
11
- * - problem codes are a CLOSED enum;
12
- * - routes are captured as PATTERNS from a fixed list, never as URLs — a raw URL carries path
13
- * params and query strings, which on a regulated storefront is exactly where the data is;
14
- * - timings and viewport are numbers.
15
- *
16
- * Everything else is dropped: raw URLs, query strings and fragments, form values, request/response
17
- * bodies, error MESSAGE text (the name only), cookies, storage contents, headers, DOM content, and
18
- * the full user-agent.
19
- */
20
- /**
21
- * Stages the client may report.
22
- *
23
- * Declared here rather than imported from the operation contract, for two reasons that point the
24
- * same way. The architectural one: `lib/diag` is renderer core and `lib/change` is the control-plane
25
- * moat, and the renderer must stay carve-able into a source-available distributable
26
- * (`renderer-no-controlplane`). The behavioural one: this is an ALLOWLIST, so a stage added to the
27
- * contract must be considered before it becomes capturable — inheriting it automatically is exactly
28
- * the drift this file exists to prevent.
29
- */
30
- export const CAPTURABLE_STAGES: readonly string[] = Object.freeze([
31
- "queued",
32
- "preparing",
33
- "publishing",
34
- "verifying",
35
- "live",
36
- ]);
37
-
38
- /** Routes the client may report timing/status for. Fixed list: an unlisted route is DROPPED, not
39
- * recorded as "other" — a route we did not anticipate is one we have not reasoned about. */
40
- export const CAPTURABLE_ROUTES: readonly string[] = Object.freeze([
41
- "/api/changes",
42
- "/api/changes/ship",
43
- "/api/changes/accept",
44
- "/api/changes/accept-issue",
45
- "/api/changes/reconcile-delivery",
46
- "/api/publish/stage-bundle",
47
- "/api/preview/build",
48
- ]);
49
-
50
- /** Problem codes the client may report. Closed enum from the operation contract. */
51
- export const CAPTURABLE_PROBLEM_CODES: readonly string[] = Object.freeze([
52
- "needs-confirmation",
53
- "entitlement-required",
54
- "bundle-unavailable",
55
- "not-ready",
56
- "delivery-undeliverable",
57
- "checks-blocked",
58
- "compliance-review",
59
- ]);
60
-
61
- /** A captured event, after the allowlist has had its say. Every variant is closed-vocabulary. */
62
- export type CaptureEvent =
63
- | { kind: "stage"; operation: string; stage: string; at: string }
64
- | { kind: "request"; route: string; status: number; durationMs: number; at: string }
65
- | { kind: "problem"; code: string; at: string }
66
- | { kind: "navigation"; route: string; ttfbMs: number; loadMs: number; at: string }
67
- | { kind: "error"; name: string; at: string }
68
- | { kind: "viewport"; width: number; height: number; online: boolean; at: string };
69
-
70
- /**
71
- * Reduce a URL to an allowlisted route PATTERN, or null.
72
- *
73
- * Only the pathname is ever consulted — `search` and `hash` are discarded before matching rather
74
- * than after, so a query string cannot reach the comparison, let alone the output. A path that is
75
- * not on the list returns null and the caller drops the event entirely.
76
- */
77
- export function captureRoute(rawUrl: string | null | undefined): string | null {
78
- if (!rawUrl) return null;
79
- let pathname: string;
80
- try {
81
- // A base is supplied so relative URLs parse; its origin is never read.
82
- pathname = new URL(rawUrl, "https://example.invalid").pathname;
83
- } catch {
84
- return null;
85
- }
86
- const normalised = pathname.length > 1 ? pathname.replace(/\/+$/, "") : pathname;
87
- return CAPTURABLE_ROUTES.includes(normalised) ? normalised : null;
88
- }
89
-
90
- /** A finite, non-negative number rounded to a whole millisecond, or null. Guards against `Infinity`
91
- * and `NaN` reaching the ingest as a "timing". */
92
- function millis(value: unknown): number | null {
93
- if (typeof value !== "number" || !Number.isFinite(value) || value < 0) return null;
94
- return Math.round(value);
95
- }
96
-
97
- /** A plausible HTTP status, or null. */
98
- function httpStatus(value: unknown): number | null {
99
- if (typeof value !== "number" || !Number.isInteger(value) || value < 100 || value > 599) return null;
100
- return value;
101
- }
102
-
103
- /**
104
- * Build a `request` event, or null when anything about it is not capturable.
105
- *
106
- * Returning null rather than a partially-populated event is the fail-closed half: a half-recorded
107
- * request is worse than none, because it looks like evidence.
108
- */
109
- export function captureRequest(input: {
110
- url: string | null | undefined;
111
- status: unknown;
112
- durationMs: unknown;
113
- at: string;
114
- }): CaptureEvent | null {
115
- const route = captureRoute(input.url);
116
- const status = httpStatus(input.status);
117
- const durationMs = millis(input.durationMs);
118
- if (!route || status === null || durationMs === null) return null;
119
- return { kind: "request", route, status, durationMs, at: input.at };
120
- }
121
-
122
- /** Build a `navigation` event, or null. Same fail-closed rule, same route allowlist. */
123
- export function captureNavigation(input: {
124
- url: string | null | undefined;
125
- ttfbMs: unknown;
126
- loadMs: unknown;
127
- at: string;
128
- }): CaptureEvent | null {
129
- const route = captureRoute(input.url);
130
- const ttfbMs = millis(input.ttfbMs);
131
- const loadMs = millis(input.loadMs);
132
- if (!route || ttfbMs === null || loadMs === null) return null;
133
- return { kind: "navigation", route, ttfbMs, loadMs, at: input.at };
134
- }
135
-
136
- /** Build a `stage` event, or null when the stage is not one this allowlist admits. */
137
- export function captureStage(operation: unknown, stage: unknown, at: string): CaptureEvent | null {
138
- if (typeof operation !== "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(operation)) return null;
139
- if (typeof stage !== "string" || !CAPTURABLE_STAGES.includes(stage)) return null;
140
- return { kind: "stage", operation, stage, at };
141
- }
142
-
143
- /** Build a `problem` event from a closed-enum code, or null when the code is not one of ours. */
144
- export function captureProblem(code: unknown, at: string): CaptureEvent | null {
145
- if (typeof code !== "string" || !CAPTURABLE_PROBLEM_CODES.includes(code)) return null;
146
- return { kind: "problem", code, at };
147
- }
148
-
149
- /**
150
- * Build an `error` event carrying the error's NAME only.
151
- *
152
- * `message` is deliberately never captured. An exception message is free text assembled at the
153
- * throw site, and on a storefront it routinely interpolates a URL, an id, or a value — the exact
154
- * content this allowlist exists to keep out. The name is a type, and a type is a fact about our
155
- * code rather than about the tenant's data.
156
- */
157
- export function captureError(error: unknown, at: string): CaptureEvent | null {
158
- const name =
159
- error instanceof Error ? error.name : typeof error === "object" && error && "name" in error ? String((error as { name: unknown }).name) : null;
160
- if (!name || !/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(name)) return null;
161
- return { kind: "error", name, at };
162
- }
@@ -1,76 +0,0 @@
1
- /**
2
- * The one console line a tenant can screenshot.
3
- *
4
- * A merchant who hits a problem does one of two things: reads the dialog, or opens devtools. Today
5
- * those two surfaces share nothing — the dialog has a support reference, the console has whatever
6
- * the error happened to throw, and neither can be joined to the other or to our logs. So a console
7
- * screenshot, which is what people actually send, has been the least useful artifact in a report.
8
- *
9
- * This emits the SAME reference the dialog shows, plus the session id and the path that resolves
10
- * them. Holding the line is then equivalent to holding the dialog, and either one is enough.
11
- *
12
- * ONE LINE, NEVER A DUMP. It is pasted into chat and photographed off a screen, so it has to survive
13
- * both. It also must never carry anything sensitive: a console line goes wherever a screenshot goes,
14
- * including into a support thread with people who should not see tenant data. Everything here is an
15
- * identifier we minted — no URLs, no message bodies, no tenant content.
16
- */
17
- import { diagnosticPathFor } from "./reference";
18
-
19
- /** What the line describes. `summary` is merchant-facing text we already show, never raw error text. */
20
- export interface DiagnosticConsoleLine {
21
- /** The quotable reference for this problem. */
22
- reference: string;
23
- /** A short merchant-safe description — reuse what the dialog says, never an exception message. */
24
- summary: string;
25
- /** The browser session this happened in, when one could be established. */
26
- sessionId?: string | null;
27
- /**
28
- * Advertise `tot.debug()` — pass true when capture is AVAILABLE here and currently OFF.
29
- *
30
- * This is the discovery mechanism for the console toggle, and the timing is the whole point: the
31
- * merchant is looking at a failure with devtools already open, which is the one moment they will
32
- * read a hint about how to record one. Suppressed when capture is already on (nothing to offer)
33
- * and on live (where the answer is no).
34
- */
35
- offerDebug?: boolean;
36
- }
37
-
38
- /**
39
- * Format the line. Pure, so its exact shape is testable and cannot drift from what support is told
40
- * to look for.
41
- *
42
- * The `[tot]` prefix is deliberate: it is what someone greps a noisy console for, and what lets a
43
- * reader tell OUR line from a tenant's own logging in a screenshot full of both.
44
- */
45
- export function formatDiagnosticConsoleLine(input: DiagnosticConsoleLine): string {
46
- const parts = [
47
- `[tot] ${input.reference}`,
48
- input.summary,
49
- input.sessionId ? `session ${input.sessionId}` : null,
50
- `diagnostics: ${diagnosticPathFor(input.reference)}`,
51
- // Last, so it never pushes the reference — the thing they must copy — off the readable part of
52
- // a narrow console or a screenshot.
53
- input.offerDebug ? "run tot.debug() to record more detail" : null,
54
- ].filter((p): p is string => Boolean(p));
55
- return parts.join(" · ");
56
- }
57
-
58
- /**
59
- * Emit the line, once, for a problem.
60
- *
61
- * `console.warn` rather than `.error`: this is a pointer to diagnostics, not an exception. Sites
62
- * that fail their own builds on console errors should not start failing because we explained
63
- * ourselves, and a merchant scanning a red console should see THEIR problem first.
64
- *
65
- * Never throws — a console that refuses to print must not take the page down with it.
66
- */
67
- export function emitDiagnosticConsoleLine(
68
- input: DiagnosticConsoleLine,
69
- sink: Pick<Console, "warn"> = console,
70
- ): void {
71
- try {
72
- sink.warn(formatDiagnosticConsoleLine(input));
73
- } catch {
74
- // A sandboxed or replaced console. Losing the line is acceptable; losing the page is not.
75
- }
76
- }
@@ -1,118 +0,0 @@
1
- /**
2
- * `tot.debug()` — the console entry point a merchant can actually type.
3
- *
4
- * WHY A CONSOLE FUNCTION AT ALL. The admin toggle arms capture for everyone, which is the right tool
5
- * when the problem happens to someone else. But a developer who is already looking at the broken
6
- * page, with devtools open, should not have to go to another surface, find a setting, and come back
7
- * — by which point they have navigated away from the state they were trying to capture. Typing one
8
- * word is the shortest path from "this is broken right now" to "I am recording it".
9
- *
10
- * IT ANSWERS, IT DOES NOT JUST ACT. Every call prints what happened and what is true now. A silent
11
- * toggle in a console is indistinguishable from a typo, and the only thing worse than capture being
12
- * off is believing it is on.
13
- *
14
- * DISCOVERABILITY IS THE HARD PART, and it is not solved here: a function nobody knows about is not
15
- * an entry point. The `[tot]` problem line advertises it (see `consoleLine.ts`), which is the moment
16
- * it is relevant — the merchant is already looking at a failure and already has the console open.
17
- */
18
- import type { IntegrationEnvironment } from "@tot/public-runtime";
19
- import {
20
- isDebugAvailable,
21
- setDebugEnabled,
22
- resolveDebugMode,
23
- readSessionPreference,
24
- debugUnavailableReason,
25
- } from "./debugMode";
26
- import type { SessionStore } from "./session";
27
- import { describeDebugWindow, type TenantDebugWindow } from "./debugWindow";
28
-
29
- /** The surface `window.tot` exposes. Kept to one verb — this is a debugging aid, not an API. */
30
- export interface TotConsoleApi {
31
- /** Turn capture on (default), off, or report the current state with no argument. */
32
- debug(on?: boolean): string;
33
- }
34
-
35
- export interface DebugConsoleContext {
36
- environment: IntegrationEnvironment | null | undefined;
37
- store?: SessionStore | null;
38
- /** The tenant-wide window, when the page was rendered with one. */
39
- tenantWindow?: TenantDebugWindow | null;
40
- now?: () => Date;
41
- }
42
-
43
- /**
44
- * Build the console API. Pure — returns an object rather than touching `window`, so its wording is
45
- * testable and so nothing is attached to the global scope as a side effect of an import.
46
- */
47
- export function createTotConsoleApi(ctx: DebugConsoleContext): TotConsoleApi {
48
- const now = () => ctx.now?.() ?? new Date();
49
-
50
- const state = (): string => {
51
- const resolution = resolveDebugMode({
52
- environment: ctx.environment,
53
- sessionPreference: readSessionPreference(ctx.store),
54
- tenantWindow: ctx.tenantWindow ?? null,
55
- now: now(),
56
- });
57
- if (!resolution.enabled) {
58
- // Say WHY it is off, not just that it is. "Off" with no reason is what sends someone to
59
- // support to ask whether the feature is broken.
60
- if (resolution.source === "stage-ineligible") return `Debug logging is off. ${debugUnavailableReason(ctx.environment)}`;
61
- return "Debug logging is off. Run tot.debug() to turn it on for this browser tab.";
62
- }
63
- const via =
64
- resolution.source === "tenant-window"
65
- ? describeDebugWindow(ctx.tenantWindow, now())
66
- : "Debug logging is on for this browser tab.";
67
- return `${via} Run tot.debug(false) to turn it off here.`;
68
- };
69
-
70
- return {
71
- debug(on?: boolean): string {
72
- // No argument = "tell me", not "toggle me". A bare `tot.debug()` typed by someone who is
73
- // unsure of the current state must never flip it to the opposite of what they wanted.
74
- if (on === undefined) {
75
- const resolution = resolveDebugMode({
76
- environment: ctx.environment,
77
- sessionPreference: readSessionPreference(ctx.store),
78
- tenantWindow: ctx.tenantWindow ?? null,
79
- now: now(),
80
- });
81
- // ...except when it is off and CAN be on, where the obvious intent of typing it is to start.
82
- if (!resolution.enabled && isDebugAvailable(ctx.environment)) return this.debug(true);
83
- return state();
84
- }
85
-
86
- const outcome = setDebugEnabled(on, { environment: ctx.environment, store: ctx.store });
87
- if (!outcome.changed) {
88
- if (outcome.reason === "stage-ineligible") {
89
- return `Not turned on. ${debugUnavailableReason(ctx.environment)}`;
90
- }
91
- return "Not changed — this browser is blocking site data, so the setting cannot be remembered. Debug logging needs session storage.";
92
- }
93
- return state();
94
- },
95
- };
96
- }
97
-
98
- /**
99
- * Attach the API to a global. Never throws and never overwrites an existing `tot` object's other
100
- * keys — a tenant may well have their own `window.tot`, and clobbering it would be a bug we
101
- * introduced into their site while trying to diagnose one.
102
- */
103
- export function installTotConsoleApi(
104
- ctx: DebugConsoleContext,
105
- globalObject: Record<string, unknown> = globalThis as unknown as Record<string, unknown>,
106
- ): void {
107
- try {
108
- const api = createTotConsoleApi(ctx);
109
- const existing = globalObject.tot;
110
- if (existing && typeof existing === "object") {
111
- (existing as Record<string, unknown>).debug = api.debug.bind(api);
112
- return;
113
- }
114
- globalObject.tot = api;
115
- } catch {
116
- // A frozen or exotic global. Losing the shortcut is acceptable; breaking the page is not.
117
- }
118
- }
@@ -1,163 +0,0 @@
1
- /**
2
- * DEBUG MODE — a tenant developer can turn on richer client-side capture while reproducing a
3
- * problem, and turn it off again. Off by default, and impossible to turn on where it does not belong.
4
- *
5
- * NEVER ON A LIVE PUBLIC SITE, and the gate is structural rather than advisory (ADR 0034):
6
- *
7
- * - the public path is CDN → content-addressed storage with at most ONE submillisecond edge
8
- * function (ADR 0013). A debug beacon in that path is origin compute on a ranked,
9
- * revenue-bearing surface, which is a direct commercial cost on every cache miss;
10
- * - increased client-side logging is precisely where PII leaks, and this is a REGULATED
11
- * storefront;
12
- * - the people who need it are previewing, which is where the failures happen anyway.
13
- *
14
- * So `live` is refused at BOTH the read and the write: a stored `on` flag carried into a live
15
- * document — by a shared sessionStorage, a copied profile, or a stage that changed under it — still
16
- * reads as off. Enabling is the request; eligibility is the answer, and eligibility is re-decided
17
- * every time rather than trusted from what was stored.
18
- */
19
- import type { IntegrationEnvironment } from "@tot/public-runtime";
20
- import type { SessionStore } from "./session";
21
- import { isDebugWindowActive, type TenantDebugWindow } from "./debugWindow";
22
-
23
- /** Where the toggle is remembered. Session-scoped, like the session id: debug is for one sitting. */
24
- export const DEBUG_STORAGE_KEY = "tot.diag.debug";
25
-
26
- /**
27
- * Stages where debug capture may run. Written as the ALLOWED set, not as `!== "live"`: a fifth stage
28
- * added later must be considered deliberately rather than inheriting permission from a negation.
29
- */
30
- export const DEBUG_ELIGIBLE_STAGES: readonly IntegrationEnvironment[] = Object.freeze([
31
- "local",
32
- "candidate",
33
- "staged",
34
- ]);
35
-
36
- /** May debug mode run at all here? The stage decides; the stored flag never overrides this. */
37
- export function isDebugAvailable(environment: IntegrationEnvironment | null | undefined): boolean {
38
- return !!environment && DEBUG_ELIGIBLE_STAGES.includes(environment);
39
- }
40
-
41
- /**
42
- * This browser session's explicit choice, or null when the developer has not expressed one.
43
- *
44
- * The three states are load-bearing. "Not set" and "explicitly off" look identical while capture is
45
- * off anyway, but they differ the moment the merchant arms a tenant-wide window: an untouched
46
- * session joins it, and a session someone deliberately switched off stays off. Collapsing them would
47
- * silently re-enable capture in a tab where a person had just turned it off.
48
- */
49
- export function readSessionPreference(store?: SessionStore | null): SessionDebugPreference {
50
- if (!store) return null;
51
- try {
52
- const raw = store.getItem(DEBUG_STORAGE_KEY);
53
- return raw === "on" || raw === "off" ? raw : null;
54
- } catch {
55
- return null;
56
- }
57
- }
58
-
59
- /** A session's explicit choice: on, off, or never asked. */
60
- export type SessionDebugPreference = "on" | "off" | null;
61
-
62
- /** Why capture is on or off, so a surface can explain itself rather than just showing a state. */
63
- export type DebugModeSource = "stage-ineligible" | "session" | "tenant-window" | "default-off";
64
-
65
- export interface DebugModeResolution {
66
- enabled: boolean;
67
- source: DebugModeSource;
68
- }
69
-
70
- /**
71
- * Resolve whether capture is on, from the three things that can say so.
72
- *
73
- * PRECEDENCE, and why:
74
- *
75
- * 1. STAGE first, and it can only ever say no. `live` refuses regardless of what any session or
76
- * any armed window claims (ADR 0034). A tenant-wide window is stored per tenant, not per stage,
77
- * so this is the check that stops an armed window following a merchant onto their public site.
78
- * 2. The SESSION's explicit choice next, either way. Someone who turned it on in their own tab
79
- * gets it without waiting for an admin, and someone who turned it OFF while a tenant window is
80
- * running stays off — otherwise the only way to quieten your own console would be to disarm
81
- * capture for every colleague mid-investigation.
82
- * 3. The tenant WINDOW, for every session that has not expressed a preference. This is the whole
83
- * point of the window: it reaches the sessions nobody has touched, including the colleague who
84
- * can actually reproduce the bug.
85
- * 4. Off.
86
- */
87
- export function resolveDebugMode(args: {
88
- environment: IntegrationEnvironment | null | undefined;
89
- sessionPreference?: SessionDebugPreference;
90
- tenantWindow?: TenantDebugWindow | null;
91
- now?: Date;
92
- }): DebugModeResolution {
93
- if (!isDebugAvailable(args.environment)) return { enabled: false, source: "stage-ineligible" };
94
- const preference = args.sessionPreference ?? null;
95
- if (preference === "on") return { enabled: true, source: "session" };
96
- if (preference === "off") return { enabled: false, source: "session" };
97
- if (isDebugWindowActive(args.tenantWindow, args.now ?? new Date())) {
98
- return { enabled: true, source: "tenant-window" };
99
- }
100
- return { enabled: false, source: "default-off" };
101
- }
102
-
103
- /**
104
- * Is capture ON right now?
105
- *
106
- * Fails closed on every uncertainty: no stage, an ineligible stage, no store, a store that throws,
107
- * or anything in storage other than our exact markers.
108
- */
109
- export function isDebugEnabled(args: {
110
- environment: IntegrationEnvironment | null | undefined;
111
- store?: SessionStore | null;
112
- tenantWindow?: TenantDebugWindow | null;
113
- now?: Date;
114
- }): boolean {
115
- return resolveDebugMode({
116
- environment: args.environment,
117
- sessionPreference: readSessionPreference(args.store),
118
- tenantWindow: args.tenantWindow ?? null,
119
- ...(args.now ? { now: args.now } : {}),
120
- }).enabled;
121
- }
122
-
123
- /** What a toggle attempt did — returned so the UI can explain a refusal instead of silently no-oping. */
124
- export type DebugToggleOutcome =
125
- | { changed: true; enabled: boolean }
126
- | { changed: false; reason: "stage-ineligible"; environment: string | null }
127
- | { changed: false; reason: "no-store" };
128
-
129
- /**
130
- * Turn capture on or off.
131
- *
132
- * Turning it ON at an ineligible stage is REFUSED and says so — it is never silently ignored, and
133
- * never silently honoured. A developer who asked for debug on a live site deserves to be told the
134
- * stage is why, rather than left wondering why no events appear.
135
- *
136
- * Turning it OFF is always allowed, at any stage: switching something off must never be gated by the
137
- * same condition that makes it dangerous to have on.
138
- */
139
- export function setDebugEnabled(
140
- enabled: boolean,
141
- args: { environment: IntegrationEnvironment | null | undefined; store?: SessionStore | null },
142
- ): DebugToggleOutcome {
143
- const store = args.store;
144
- if (!store) return { changed: false, reason: "no-store" };
145
- if (enabled && !isDebugAvailable(args.environment)) {
146
- return { changed: false, reason: "stage-ineligible", environment: args.environment ?? null };
147
- }
148
- try {
149
- store.setItem(DEBUG_STORAGE_KEY, enabled ? "on" : "off");
150
- return { changed: true, enabled };
151
- } catch {
152
- // Private mode or blocked site data. The toggle did not take; say so rather than report success.
153
- return { changed: false, reason: "no-store" };
154
- }
155
- }
156
-
157
- /** The merchant-facing sentence for why debug is unavailable here, or null when it is available. */
158
- export function debugUnavailableReason(
159
- environment: IntegrationEnvironment | null | undefined,
160
- ): string | null {
161
- if (isDebugAvailable(environment)) return null;
162
- return "Debug logging is available on preview, not on your live site. Turn it on there, reproduce the problem, then quote the reference.";
163
- }
@@ -1,111 +0,0 @@
1
- /**
2
- * TENANT-WIDE DEBUG WINDOW — a merchant switches debug capture on from their admin console and it
3
- * applies to EVERY session on that tenant until it expires.
4
- *
5
- * WHY THIS EXISTS ALONGSIDE THE PER-SESSION TOGGLE. The console toggle only helps someone who can
6
- * already reproduce the problem in their own browser. The reports that are hardest to act on are the
7
- * ones where they cannot: it happens to a colleague, on a phone, once a day, or only to whoever
8
- * happens to hit it next. A window lets the merchant arm capture and then go and reproduce it
9
- * however it actually occurs.
10
- *
11
- * IT EXPIRES, AND THAT IS THE DESIGN. Capture that can be left on forever eventually is, and then it
12
- * is collecting on a tenant nobody is debugging — which is both a cost and a liability on a regulated
13
- * storefront. An expiry means the safe state is reached by doing nothing, which is the only kind of
14
- * safe state that survives people being busy. There is deliberately no "on indefinitely".
15
- *
16
- * Still gated by stage. A window has no effect on `live` — the resolver refuses there regardless of
17
- * what any record says, so an armed window cannot follow a tenant onto their public site.
18
- */
19
-
20
- /** A merchant-armed capture window. Absent/expired ⇒ tenant-wide capture is off. */
21
- export interface TenantDebugWindow {
22
- /** When the window stops applying — ISO 8601, UTC. */
23
- enabledUntil: string;
24
- /** When it was armed, for the admin surface to show "turned on 2 hours ago". */
25
- enabledAt: string;
26
- /** Who armed it, for the audit trail. An opaque actor id, never a name or email. */
27
- enabledBy?: string;
28
- }
29
-
30
- /** The default a merchant gets when they just click the toggle: long enough to reproduce something
31
- * that happens a few times a day, short enough that forgetting is not a problem. */
32
- export const DEFAULT_DEBUG_WINDOW_MS = 24 * 60 * 60 * 1000;
33
-
34
- /** The shortest window worth arming — below this the merchant cannot get to the other tab in time. */
35
- export const MIN_DEBUG_WINDOW_MS = 15 * 60 * 1000;
36
-
37
- /**
38
- * The longest window anyone may arm. A ceiling rather than a preference: the whole value of an
39
- * expiry is that it is not negotiable, and "just set it to a year" is how an expiry becomes
40
- * decoration. A merchant who genuinely needs longer re-arms it, which is a deliberate act that
41
- * leaves a fresh audit entry.
42
- */
43
- export const MAX_DEBUG_WINDOW_MS = 7 * 24 * 60 * 60 * 1000;
44
-
45
- /** Clamp a requested duration into the permitted range. Invalid input falls back to the default
46
- * rather than refusing — a bad number must not leave the merchant unable to turn capture on. */
47
- export function clampDebugWindowMs(requestedMs: unknown): number {
48
- if (typeof requestedMs !== "number" || !Number.isFinite(requestedMs) || requestedMs <= 0) {
49
- return DEFAULT_DEBUG_WINDOW_MS;
50
- }
51
- return Math.min(MAX_DEBUG_WINDOW_MS, Math.max(MIN_DEBUG_WINDOW_MS, Math.round(requestedMs)));
52
- }
53
-
54
- /**
55
- * Arm a window. Duration is a parameter with a default, so the admin surface can offer choices
56
- * (an hour, a day, a week) without any further change here.
57
- */
58
- export function openDebugWindow(args: {
59
- now?: Date;
60
- durationMs?: number;
61
- enabledBy?: string;
62
- }): TenantDebugWindow {
63
- const now = args.now ?? new Date();
64
- const durationMs = clampDebugWindowMs(args.durationMs);
65
- const window: TenantDebugWindow = {
66
- enabledAt: now.toISOString(),
67
- enabledUntil: new Date(now.getTime() + durationMs).toISOString(),
68
- };
69
- if (args.enabledBy) window.enabledBy = args.enabledBy;
70
- return window;
71
- }
72
-
73
- /**
74
- * Is a window currently in force?
75
- *
76
- * Fails closed on anything it cannot read: absent, malformed, or an unparseable timestamp all mean
77
- * off. A record we cannot interpret must never be treated as permission to capture.
78
- */
79
- export function isDebugWindowActive(
80
- window: TenantDebugWindow | null | undefined,
81
- now: Date = new Date(),
82
- ): boolean {
83
- if (!window || typeof window.enabledUntil !== "string") return false;
84
- const until = Date.parse(window.enabledUntil);
85
- if (!Number.isFinite(until)) return false;
86
- return until > now.getTime();
87
- }
88
-
89
- /** Milliseconds left on a window, or 0 when it is not active. For the admin surface's countdown. */
90
- export function debugWindowRemainingMs(
91
- window: TenantDebugWindow | null | undefined,
92
- now: Date = new Date(),
93
- ): number {
94
- if (!isDebugWindowActive(window, now)) return 0;
95
- return Date.parse(window!.enabledUntil) - now.getTime();
96
- }
97
-
98
- /** A merchant-facing summary of the window's state — "Debug logging is on for another 3 hours". */
99
- export function describeDebugWindow(
100
- window: TenantDebugWindow | null | undefined,
101
- now: Date = new Date(),
102
- ): string {
103
- const remaining = debugWindowRemainingMs(window, now);
104
- if (remaining <= 0) return "Debug logging is off for this store.";
105
- const hours = Math.floor(remaining / (60 * 60 * 1000));
106
- if (hours >= 1) {
107
- return `Debug logging is on for this store for another ${hours} hour${hours === 1 ? "" : "s"}.`;
108
- }
109
- const minutes = Math.max(1, Math.round(remaining / (60 * 1000)));
110
- return `Debug logging is on for this store for another ${minutes} minute${minutes === 1 ? "" : "s"}.`;
111
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * Redaction helpers for diagnostic logs. An email address never appears in a diagnostic
3
- * line in any build: not the local part, not its first character, not the domain.
4
- * Correlate with an opaque reference (for example `hashActorId`) instead.
5
- */
6
-
7
- export const REDACTED_EMAIL = "[redacted-email]";
8
-
9
- /** A log-safe stand-in for an email address. Reveals nothing about the input. */
10
- export function maskEmail(_email: string): string {
11
- return REDACTED_EMAIL;
12
- }
13
-
14
- /** Email for a diagnostic line. Fully redacted in local dev and deployed builds alike. */
15
- export function diagEmail(_email: string): string {
16
- return REDACTED_EMAIL;
17
- }