@tokenoftrust/storefront-runner 7.3.1 → 7.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (414) hide show
  1. package/agency-kit/tools/lib/catalog-model/files.mjs +11 -4
  2. package/agency-kit/tools/lib/catalog-model/model.mjs +5 -1
  3. package/agency-kit/tools/lib/redirect-shadows.mjs +261 -0
  4. package/apps/storefront/astro.config.mjs +8 -2
  5. package/apps/storefront/package.json +1 -2
  6. package/apps/storefront/src/components/catalog/storefront/ProductCard.astro +20 -6
  7. package/apps/storefront/src/components/catalog/storefront/islands/ImageGallery.tsx +17 -6
  8. package/apps/storefront/src/components/compliance/storefront/islands/CheckoutComplianceGate.tsx +1 -32
  9. package/apps/storefront/src/config/compliance/rulesets.ts +1 -1
  10. package/apps/storefront/src/layouts/Layout.astro +17 -0
  11. package/apps/storefront/src/lib/access/auth/agentRoles.ts +20 -0
  12. package/apps/storefront/src/lib/access/auth/agentSessionGate.ts +147 -0
  13. package/apps/storefront/src/lib/access/auth/brokerAssertion.ts +67 -1
  14. package/apps/storefront/src/lib/access/auth/contactReaderAuthority.ts +39 -0
  15. package/apps/storefront/src/lib/access/auth/loginGate.ts +15 -17
  16. package/apps/storefront/src/lib/access/auth/session.ts +79 -0
  17. package/apps/storefront/src/lib/access/dashboard/staffAdmission.ts +5 -0
  18. package/apps/storefront/src/lib/access/dashboard/tenantSelection.ts +2 -0
  19. package/apps/storefront/src/lib/access/shared/capability.ts +14 -6
  20. package/apps/storefront/src/lib/access/shared/generated/capabilityCatalog.generated.ts +161 -0
  21. package/apps/storefront/src/lib/activity/activityScope.ts +36 -0
  22. package/apps/storefront/src/lib/activity/recordActivity.ts +23 -1
  23. package/apps/storefront/src/lib/activity/serverFanOut.ts +31 -0
  24. package/apps/storefront/src/lib/activity/store.ts +9 -3
  25. package/apps/storefront/src/lib/checkout/commerce/cardCartForm.ts +2 -0
  26. package/apps/storefront/src/lib/checkout/commerce/cartSession.ts +109 -12
  27. package/apps/storefront/src/lib/checkout/commerce/checkoutHandoffRoute.ts +53 -25
  28. package/apps/storefront/src/lib/checkout/commerce/finalCartAuthorization.ts +48 -6
  29. package/apps/storefront/src/lib/checkout/proposal/cartProposal.ts +388 -0
  30. package/apps/storefront/src/lib/checkout/proposal/listMatcher.ts +149 -0
  31. package/apps/storefront/src/lib/checkout/proposal/proposalRoutes.ts +447 -0
  32. package/apps/storefront/src/lib/checkout/proposal/reviewHtml.ts +100 -0
  33. package/apps/storefront/src/lib/compliance/browser/checkoutVerificationFlow.ts +26 -2
  34. package/apps/storefront/src/lib/content/shared/redirects.ts +21 -4
  35. package/apps/storefront/src/lib/publication/shared/edgeCache.ts +5 -2
  36. package/apps/storefront/src/lib/publication/shared/previewAnnotations/renderDecorator.ts +15 -8
  37. package/apps/storefront/src/lib/publication/shared/runtimeEnv.ts +1 -1
  38. package/apps/storefront/src/middleware/controlPlane.ts +15 -1
  39. package/apps/storefront/src/middleware/index.ts +40 -1
  40. package/apps/storefront/src/middleware/renderChain.ts +46 -33
  41. package/apps/storefront/src/pages/api/cart-proposal/confirm.ts +12 -0
  42. package/apps/storefront/src/pages/api/cart-proposal/review.ts +26 -0
  43. package/apps/storefront/src/pages/api/commerce/final-cart-authorization.ts +29 -6
  44. package/apps/storefront/src/pages/api/compliance/preflight.ts +25 -1
  45. package/apps/storefront/src/pages/products/[handle].astro +2 -15
  46. package/apps/storefront/tsconfig.astro.json +11 -0
  47. package/package.json +1 -1
  48. package/packages/public-runtime/src/activity/README.md +12 -0
  49. package/packages/public-runtime/src/activity/catalog.ts +7 -0
  50. package/packages/public-runtime/src/activity/event.ts +19 -0
  51. package/packages/public-runtime/src/activity/redaction.ts +31 -2
  52. package/packages/public-runtime/src/catalog-files.ts +3 -2
  53. package/packages/public-runtime/src/checkout-orders.ts +18 -19
  54. package/packages/public-runtime/src/checkout.ts +70 -0
  55. package/packages/public-runtime/src/compliance/evaluate.ts +60 -1
  56. package/packages/public-runtime/src/compliance/index.ts +1 -1
  57. package/packages/public-runtime/src/compliance/pact-report.ts +184 -3
  58. package/packages/public-runtime/src/compliance/profile.ts +268 -20
  59. package/packages/public-runtime/src/compliance/ruleset.ts +42 -0
  60. package/packages/public-runtime/src/customization-runtime.ts +1 -1
  61. package/packages/public-runtime/src/product.ts +9 -1
  62. package/packages/public-runtime/src/publication-content-redirects.ts +16 -3
  63. package/packages/public-runtime/tests/fixtures/compliance-decisions.golden.json +252 -52
  64. package/pnpm-lock.runner.yaml +0 -15
  65. package/scripts/tenant/materialize-tenant-content.mjs +3 -0
  66. package/scripts/tenant/validate.mjs +128 -0
  67. package/apps/storefront/dev-plugins/dev-publish.mjs +0 -55
  68. package/apps/storefront/drizzle.config.apps.ts +0 -13
  69. package/apps/storefront/integrations/preview-annotations-client-bundle.mjs +0 -80
  70. package/apps/storefront/migrations-apps/0000_fast_millenium_guard.sql +0 -129
  71. package/apps/storefront/migrations-apps/0001_woozy_lyja.sql +0 -22
  72. package/apps/storefront/migrations-apps/0002_good_switch.sql +0 -26
  73. package/apps/storefront/migrations-apps/0003_mute_marauders.sql +0 -12
  74. package/apps/storefront/migrations-apps/0004_deep_morph.sql +0 -36
  75. package/apps/storefront/migrations-apps/0005_common_mystique.sql +0 -23
  76. package/apps/storefront/migrations-apps/0006_broad_microchip.sql +0 -16
  77. package/apps/storefront/migrations-apps/0007_brave_outlaw_kid.sql +0 -15
  78. package/apps/storefront/migrations-apps/0008_blue_dazzler.sql +0 -11
  79. package/apps/storefront/migrations-apps/0009_bored_shinobi_shaw.sql +0 -15
  80. package/apps/storefront/migrations-apps/0010_ws4_verified_provider_measurement.sql +0 -35
  81. package/apps/storefront/migrations-apps/0011_dt_tracking_tenant_databases.sql +0 -23
  82. package/apps/storefront/migrations-apps/0012_test_destinations.sql +0 -29
  83. package/apps/storefront/migrations-apps/0013_publication_space_editorial.sql +0 -64
  84. package/apps/storefront/migrations-apps/0014_retire_candidate_ledger.sql +0 -12
  85. package/apps/storefront/migrations-apps/0015_merchant_calculation_settings.sql +0 -31
  86. package/apps/storefront/migrations-apps/0016_scrappy_commerce_contract.sql +0 -166
  87. package/apps/storefront/migrations-apps/0017_commerce_durable_projection.sql +0 -28
  88. package/apps/storefront/migrations-apps/0018_commerce_provider_cart_identity.sql +0 -13
  89. package/apps/storefront/migrations-apps/0019_commerce_source_authority.sql +0 -23
  90. package/apps/storefront/migrations-apps/0020_contact_messages.sql +0 -18
  91. package/apps/storefront/migrations-apps/0021_contact_vault.sql +0 -166
  92. package/apps/storefront/migrations-apps/0022_contact_vault_fields.sql +0 -342
  93. package/apps/storefront/migrations-apps/0023_principal_grant_contacts.sql +0 -15
  94. package/apps/storefront/migrations-apps/0024_order_contact_erasure_state.sql +0 -22
  95. package/apps/storefront/migrations-apps/0025_shipment_audit_order_lookup.sql +0 -2
  96. package/apps/storefront/migrations-apps/0026_fulfillment_assignment.sql +0 -44
  97. package/apps/storefront/migrations-apps/0027_app_contact_authority.sql +0 -70
  98. package/apps/storefront/migrations-apps/0028_app_jwk_and_candidates.sql +0 -133
  99. package/apps/storefront/migrations-apps/0029_inventory_locations_wms.sql +0 -38
  100. package/apps/storefront/migrations-apps/0030_assignment_split_shipments.sql +0 -149
  101. package/apps/storefront/migrations-apps/meta/0000_snapshot.json +0 -843
  102. package/apps/storefront/migrations-apps/meta/0001_snapshot.json +0 -990
  103. package/apps/storefront/migrations-apps/meta/0002_snapshot.json +0 -1160
  104. package/apps/storefront/migrations-apps/meta/0003_snapshot.json +0 -1235
  105. package/apps/storefront/migrations-apps/meta/0004_snapshot.json +0 -1474
  106. package/apps/storefront/migrations-apps/meta/0005_snapshot.json +0 -1617
  107. package/apps/storefront/migrations-apps/meta/0006_snapshot.json +0 -1716
  108. package/apps/storefront/migrations-apps/meta/0007_snapshot.json +0 -1812
  109. package/apps/storefront/migrations-apps/meta/0008_snapshot.json +0 -1881
  110. package/apps/storefront/migrations-apps/meta/0009_snapshot.json +0 -1979
  111. package/apps/storefront/migrations-apps/meta/_journal.json +0 -76
  112. package/apps/storefront/perf/README.md +0 -64
  113. package/apps/storefront/perf/assert-budgets.ts +0 -159
  114. package/apps/storefront/platform-reconcile-tenants.json +0 -3
  115. package/apps/storefront/playwright.config.ts +0 -23
  116. package/apps/storefront/public/js/dashboard-access-banner.js +0 -53
  117. package/apps/storefront/public/js/dashboard-apps.js +0 -183
  118. package/apps/storefront/public/js/dashboard-contact-capture.js +0 -52
  119. package/apps/storefront/public/js/dashboard-delegate.js +0 -167
  120. package/apps/storefront/public/js/dashboard-team.js +0 -356
  121. package/apps/storefront/public/js/dashboard-vendor-search.js +0 -115
  122. package/apps/storefront/src/components/content/storefront/AsyncStylesheet.astro +0 -26
  123. package/apps/storefront/src/components/integrations/storefront/WidgetFrame.astro +0 -34
  124. package/apps/storefront/src/config/adminTenantLookup.ts +0 -35
  125. package/apps/storefront/src/config/evidenceTenantRoster.ts +0 -25
  126. package/apps/storefront/src/config/staffProvisionProjection.ts +0 -24
  127. package/apps/storefront/src/config/storeName.ts +0 -34
  128. package/apps/storefront/src/lib/access/admin/README.md +0 -122
  129. package/apps/storefront/src/lib/access/admin/adminShell.ts +0 -281
  130. package/apps/storefront/src/lib/access/admin/envelope.ts +0 -9
  131. package/apps/storefront/src/lib/access/admin/viewmodels/settings.ts +0 -64
  132. package/apps/storefront/src/lib/access/auth/adminApiGuard.ts +0 -66
  133. package/apps/storefront/src/lib/access/auth/adminEntry.ts +0 -126
  134. package/apps/storefront/src/lib/access/auth/mcpClientAssertion.ts +0 -217
  135. package/apps/storefront/src/lib/access/auth/operatorSession.ts +0 -120
  136. package/apps/storefront/src/lib/access/dashboard/delegateGate.ts +0 -130
  137. package/apps/storefront/src/lib/access/dashboard/staffStoreEntry.ts +0 -150
  138. package/apps/storefront/src/lib/access/dashboard/staffVendorAccess.ts +0 -452
  139. package/apps/storefront/src/lib/access/dashboard/vendorQuery.ts +0 -61
  140. package/apps/storefront/src/lib/access/fixtures/settings.ts +0 -67
  141. package/apps/storefront/src/lib/access/fixtures/tenants.ts +0 -29
  142. package/apps/storefront/src/lib/access/notifications/magicLinkInviteEmail.ts +0 -62
  143. package/apps/storefront/src/lib/access/shared/grantContactLookup.ts +0 -97
  144. package/apps/storefront/src/lib/access/shared/principalGrants.ts +0 -775
  145. package/apps/storefront/src/lib/activity/alerts.ts +0 -426
  146. package/apps/storefront/src/lib/activity/candidateSubmitLease.ts +0 -87
  147. package/apps/storefront/src/lib/activity/changeActorAttribution.ts +0 -181
  148. package/apps/storefront/src/lib/activity/evidence/evidenceReference.ts +0 -32
  149. package/apps/storefront/src/lib/activity/fixtures/evidence.ts +0 -99
  150. package/apps/storefront/src/lib/activity/query.ts +0 -403
  151. package/apps/storefront/src/lib/activity/uiActor.ts +0 -152
  152. package/apps/storefront/src/lib/admin/services/mock/index.ts +0 -12
  153. package/apps/storefront/src/lib/assets/addons/catalog.ts +0 -60
  154. package/apps/storefront/src/lib/assets/addons/storeEntitlements.ts +0 -260
  155. package/apps/storefront/src/lib/assets/durableAssetsRoute.ts +0 -65
  156. package/apps/storefront/src/lib/assets/durableR2.ts +0 -473
  157. package/apps/storefront/src/lib/assets/durableR2Bindings.ts +0 -33
  158. package/apps/storefront/src/lib/automation/admin/viewmodels/aiWorkflows.ts +0 -65
  159. package/apps/storefront/src/lib/automation/ai/approvalMode.ts +0 -20
  160. package/apps/storefront/src/lib/automation/ai/askEnvelope.ts +0 -47
  161. package/apps/storefront/src/lib/automation/ai/audit.ts +0 -12
  162. package/apps/storefront/src/lib/automation/ai/operationalRuns.ts +0 -155
  163. package/apps/storefront/src/lib/automation/ai/recommendation.ts +0 -20
  164. package/apps/storefront/src/lib/automation/fixtures/aiWorkflows.ts +0 -59
  165. package/apps/storefront/src/lib/catalog/admin/catalogSettingsClient.ts +0 -250
  166. package/apps/storefront/src/lib/catalog/admin/catalogSettingsFields.ts +0 -134
  167. package/apps/storefront/src/lib/catalog/admin/catalogSettingsPreview.ts +0 -37
  168. package/apps/storefront/src/lib/catalog/admin/catalogSettingsPricingView.ts +0 -39
  169. package/apps/storefront/src/lib/catalog/admin/catalogSettingsRuleView.ts +0 -44
  170. package/apps/storefront/src/lib/catalog/admin/catalogSettingsSkuView.ts +0 -21
  171. package/apps/storefront/src/lib/catalog/admin/catalogSettingsState.ts +0 -132
  172. package/apps/storefront/src/lib/catalog/admin/productSetupPhoto.ts +0 -23
  173. package/apps/storefront/src/lib/catalog/admin/productsTabClient.ts +0 -193
  174. package/apps/storefront/src/lib/catalog/admin/services/catalogProducts.ts +0 -32
  175. package/apps/storefront/src/lib/catalog/admin/viewmodels/catalogProducts.ts +0 -164
  176. package/apps/storefront/src/lib/catalog/admin/viewmodels/products.ts +0 -267
  177. package/apps/storefront/src/lib/catalog/fixtures/products.ts +0 -105
  178. package/apps/storefront/src/lib/catalog/tot/syncState.ts +0 -111
  179. package/apps/storefront/src/lib/checkout/admin/checkoutStyleInput.ts +0 -172
  180. package/apps/storefront/src/lib/checkout/admin/checkoutStyleTarget.ts +0 -65
  181. package/apps/storefront/src/lib/checkout/browser/checkoutExciseForm.ts +0 -152
  182. package/apps/storefront/src/lib/checkout/browser/checkoutRequirementsForm.ts +0 -72
  183. package/apps/storefront/src/lib/checkout/browser/checkoutStyleForm.ts +0 -110
  184. package/apps/storefront/src/lib/checkout/browser/settingDraftActions.ts +0 -367
  185. package/apps/storefront/src/lib/checkout/commerce/checkoutSettings.ts +0 -246
  186. package/apps/storefront/src/lib/checkout/fixtures/checkoutSettings.ts +0 -77
  187. package/apps/storefront/src/lib/content/blog/markdown.ts +0 -174
  188. package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome-assignments.example.json +0 -6
  189. package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome.example.json +0 -79
  190. package/apps/storefront/src/lib/content/index.ts +0 -27
  191. package/apps/storefront/src/lib/content/the-build/readingTime.ts +0 -35
  192. package/apps/storefront/src/lib/content/the-build/toc.ts +0 -95
  193. package/apps/storefront/src/lib/customers/admin/viewmodels/customers.ts +0 -56
  194. package/apps/storefront/src/lib/customers/contactVault/blindIndex.ts +0 -28
  195. package/apps/storefront/src/lib/customers/contactVault/contactAudit.ts +0 -149
  196. package/apps/storefront/src/lib/customers/contactVault/dataKeys.ts +0 -283
  197. package/apps/storefront/src/lib/customers/contactVault/fieldEnvelope.ts +0 -88
  198. package/apps/storefront/src/lib/customers/contactVault/isolateMetrics.ts +0 -37
  199. package/apps/storefront/src/lib/customers/contactVault/kms.ts +0 -292
  200. package/apps/storefront/src/lib/customers/contactVault/retention.ts +0 -302
  201. package/apps/storefront/src/lib/customers/contactVault/retentionPolicy.ts +0 -290
  202. package/apps/storefront/src/lib/customers/contactVault/zip3.ts +0 -24
  203. package/apps/storefront/src/lib/customers/fixtures/customers.ts +0 -86
  204. package/apps/storefront/src/lib/developer-experience/admin/memoizeByEnvelope.ts +0 -27
  205. package/apps/storefront/src/lib/developer-experience/admin/seed.ts +0 -54
  206. package/apps/storefront/src/lib/developer-experience/dev/activityIngestToken.ts +0 -85
  207. package/apps/storefront/src/lib/developer-experience/dev/activityStore.ts +0 -82
  208. package/apps/storefront/src/lib/developer-experience/dev/ai-widget-client.js +0 -308
  209. package/apps/storefront/src/lib/developer-experience/dev/apiBase.ts +0 -17
  210. package/apps/storefront/src/lib/developer-experience/dev/cliSignInCode.ts +0 -124
  211. package/apps/storefront/src/lib/developer-experience/dev/cockpit/ask.ts +0 -49
  212. package/apps/storefront/src/lib/developer-experience/dev/cockpit/clickToSource.ts +0 -71
  213. package/apps/storefront/src/lib/developer-experience/dev/cockpit/copyCommand.ts +0 -227
  214. package/apps/storefront/src/lib/developer-experience/dev/cockpit/files.ts +0 -249
  215. package/apps/storefront/src/lib/developer-experience/dev/cockpit/hostedActivity.ts +0 -500
  216. package/apps/storefront/src/lib/developer-experience/dev/cockpit/infoPopover.ts +0 -12
  217. package/apps/storefront/src/lib/developer-experience/dev/cockpit/mcpCopy.ts +0 -34
  218. package/apps/storefront/src/lib/developer-experience/dev/cockpit/monitor.ts +0 -107
  219. package/apps/storefront/src/lib/developer-experience/dev/cockpit/stepper.ts +0 -116
  220. package/apps/storefront/src/lib/developer-experience/dev/cockpit/themeToggle.ts +0 -23
  221. package/apps/storefront/src/lib/developer-experience/dev/livePreview.ts +0 -77
  222. package/apps/storefront/src/lib/developer-experience/dev/obstacleStore.ts +0 -214
  223. package/apps/storefront/src/lib/developer-experience/dev/previewStatus.ts +0 -87
  224. package/apps/storefront/src/lib/developer-experience/dev/rendezvousBroker.ts +0 -226
  225. package/apps/storefront/src/lib/developer-experience/dev/runtimeStore.ts +0 -291
  226. package/apps/storefront/src/lib/developer-experience/dev/storeStatus.ts +0 -142
  227. package/apps/storefront/src/lib/developer-experience/dev/subjectReissue.ts +0 -67
  228. package/apps/storefront/src/lib/developer-experience/fixtures/regulated-commerce-truth/index.ts +0 -540
  229. package/apps/storefront/src/lib/developer-experience/fixtures/ws3-readonly-clone-preflight/index.ts +0 -495
  230. package/apps/storefront/src/lib/engagement/contact/contactMessages.ts +0 -671
  231. package/apps/storefront/src/lib/engagement/contact/messagesTabClient.ts +0 -175
  232. package/apps/storefront/src/lib/engagement/contact/submission.ts +0 -112
  233. package/apps/storefront/src/lib/engagement/messaging/messagesClient.ts +0 -149
  234. package/apps/storefront/src/lib/engagement/newsletter/digest.ts +0 -117
  235. package/apps/storefront/src/lib/engagement/newsletter/resendClient.ts +0 -79
  236. package/apps/storefront/src/lib/engagement/newsletter/send.ts +0 -265
  237. package/apps/storefront/src/lib/engagement/social/golive.ts +0 -212
  238. package/apps/storefront/src/lib/engagement/social/notify.ts +0 -32
  239. package/apps/storefront/src/lib/engagement/social/tokenStore.ts +0 -171
  240. package/apps/storefront/src/lib/fulfillment/admin/commerceDesk.ts +0 -180
  241. package/apps/storefront/src/lib/fulfillment/admin/commerceDeskRouting.ts +0 -45
  242. package/apps/storefront/src/lib/fulfillment/admin/viewmodels/fulfillment.ts +0 -1071
  243. package/apps/storefront/src/lib/fulfillment/appShipmentEvidence.ts +0 -271
  244. package/apps/storefront/src/lib/fulfillment/carrierEvidence.ts +0 -105
  245. package/apps/storefront/src/lib/fulfillment/commerceProjection.ts +0 -157
  246. package/apps/storefront/src/lib/fulfillment/commerceReadback.ts +0 -60
  247. package/apps/storefront/src/lib/fulfillment/commerceRecovery.ts +0 -84
  248. package/apps/storefront/src/lib/fulfillment/commerceRuntime.ts +0 -41
  249. package/apps/storefront/src/lib/fulfillment/fulfillmentService.ts +0 -2842
  250. package/apps/storefront/src/lib/fulfillment/readiness.ts +0 -217
  251. package/apps/storefront/src/lib/fulfillment/splitShipments.ts +0 -388
  252. package/apps/storefront/src/lib/fulfillment/syntheticPreviewOrders.ts +0 -292
  253. package/apps/storefront/src/lib/integrations/apps/appContactAuthority.ts +0 -27
  254. package/apps/storefront/src/lib/integrations/apps/appContactConsents.ts +0 -118
  255. package/apps/storefront/src/lib/integrations/apps/appInstallEnv.ts +0 -28
  256. package/apps/storefront/src/lib/integrations/apps/gtmMigrationDraft.ts +0 -103
  257. package/apps/storefront/src/lib/integrations/apps/inventoryWrite.ts +0 -906
  258. package/apps/storefront/src/lib/integrations/apps/orders/customerHash.ts +0 -28
  259. package/apps/storefront/src/lib/integrations/apps/orders/idempotency.ts +0 -100
  260. package/apps/storefront/src/lib/integrations/apps/reports/salesVelocityReport.ts +0 -96
  261. package/apps/storefront/src/lib/integrations/apps/routeParams.ts +0 -45
  262. package/apps/storefront/src/lib/integrations/webhooks/cloudflareQueueDispatcher.ts +0 -82
  263. package/apps/storefront/src/lib/integrations/webhooks/commercePayloads.ts +0 -159
  264. package/apps/storefront/src/lib/integrations/webhooks/deliveryEngine.ts +0 -379
  265. package/apps/storefront/src/lib/integrations/webhooks/deliveryMapper.ts +0 -34
  266. package/apps/storefront/src/lib/integrations/webhooks/deliveryStore.ts +0 -903
  267. package/apps/storefront/src/lib/integrations/webhooks/dispatcher.ts +0 -168
  268. package/apps/storefront/src/lib/integrations/webhooks/emit.ts +0 -245
  269. package/apps/storefront/src/lib/integrations/webhooks/events.ts +0 -105
  270. package/apps/storefront/src/lib/integrations/webhooks/getDispatcher.ts +0 -77
  271. package/apps/storefront/src/lib/integrations/webhooks/orderFulfilledClaim.ts +0 -75
  272. package/apps/storefront/src/lib/measurement/admin/analyticsRegionPolicy.ts +0 -151
  273. package/apps/storefront/src/lib/measurement/admin/analyticsRegionsClient.ts +0 -84
  274. package/apps/storefront/src/lib/measurement/admin/consentSettingsClient.ts +0 -113
  275. package/apps/storefront/src/lib/measurement/analytics/index.ts +0 -44
  276. package/apps/storefront/src/lib/measurement/attribution/attributionService.ts +0 -206
  277. package/apps/storefront/src/lib/measurement/attribution/orderConversionD1.ts +0 -150
  278. package/apps/storefront/src/lib/measurement/attribution/verifiedProviderMeasurement.ts +0 -118
  279. package/apps/storefront/src/lib/measurement/tracking/interactionCollector.ts +0 -205
  280. package/apps/storefront/src/lib/measurement/tracking/pruneRollup.ts +0 -260
  281. package/apps/storefront/src/lib/measurement/tracking/tenantReadAccess.ts +0 -138
  282. package/apps/storefront/src/lib/measurement/tracking-writeback/rewriteTrackingIds.ts +0 -175
  283. package/apps/storefront/src/lib/measurement/tracking-writeback/writebackCandidate.ts +0 -110
  284. package/apps/storefront/src/lib/observability/diag/capture.ts +0 -162
  285. package/apps/storefront/src/lib/observability/diag/consoleLine.ts +0 -76
  286. package/apps/storefront/src/lib/observability/diag/debugConsole.ts +0 -118
  287. package/apps/storefront/src/lib/observability/diag/debugMode.ts +0 -163
  288. package/apps/storefront/src/lib/observability/diag/debugWindow.ts +0 -111
  289. package/apps/storefront/src/lib/observability/diag/redact.ts +0 -17
  290. package/apps/storefront/src/lib/observability/diag/reference.ts +0 -148
  291. package/apps/storefront/src/lib/observability/diag/referenceStore.ts +0 -113
  292. package/apps/storefront/src/lib/observability/diag/report.ts +0 -110
  293. package/apps/storefront/src/lib/observability/diag/serverResponseTime.ts +0 -91
  294. package/apps/storefront/src/lib/observability/diag/session.ts +0 -93
  295. package/apps/storefront/src/lib/observability/monitoring/manifest.ts +0 -301
  296. package/apps/storefront/src/lib/observability/performance/lighthouseReport.ts +0 -109
  297. package/apps/storefront/src/lib/observability/performance/rumAlert.ts +0 -179
  298. package/apps/storefront/src/lib/orders/admin/orderActions.ts +0 -556
  299. package/apps/storefront/src/lib/orders/admin/orderClient.ts +0 -248
  300. package/apps/storefront/src/lib/orders/admin/orderSource.ts +0 -410
  301. package/apps/storefront/src/lib/orders/admin/services/orders.ts +0 -922
  302. package/apps/storefront/src/lib/orders/admin/viewmodels/orders.ts +0 -135
  303. package/apps/storefront/src/lib/orders/data/commerceCallerConfig.ts +0 -37
  304. package/apps/storefront/src/lib/orders/data/ledgerContractOrders.ts +0 -148
  305. package/apps/storefront/src/lib/orders/data/orderForwardReceiver.ts +0 -532
  306. package/apps/storefront/src/lib/orders/data/orderMapper.ts +0 -454
  307. package/apps/storefront/src/lib/orders/data/ordersStore.ts +0 -623
  308. package/apps/storefront/src/lib/orders/data/sourceAuthorityContract.ts +0 -380
  309. package/apps/storefront/src/lib/orders/data/sourceAuthorityStore.ts +0 -830
  310. package/apps/storefront/src/lib/orders/fixtures/orders.ts +0 -186
  311. package/apps/storefront/src/lib/orders/providers/foxyOrderClient.ts +0 -207
  312. package/apps/storefront/src/lib/orders/vault/appRecipientRead.ts +0 -222
  313. package/apps/storefront/src/lib/orders/vault/contactIntake.ts +0 -63
  314. package/apps/storefront/src/lib/orders/vault/contactRoutes.ts +0 -110
  315. package/apps/storefront/src/lib/orders/vault/kmsEnv.ts +0 -11
  316. package/apps/storefront/src/lib/orders/vault/orderContact.ts +0 -96
  317. package/apps/storefront/src/lib/orders/vault/orderContactVault.ts +0 -1427
  318. package/apps/storefront/src/lib/orders/vault/vault-test-support.ts +0 -258
  319. package/apps/storefront/src/lib/publication/d1/schema-apps.ts +0 -808
  320. package/apps/storefront/src/lib/publication/notifications/candidateConflictEmail.ts +0 -80
  321. package/apps/storefront/src/lib/publication/servingMode.ts +0 -52
  322. package/apps/storefront/src/lib/publication/shared/previewAnnotations/moduleAsset.ts +0 -65
  323. package/apps/storefront/src/lib/publication/shared/routedApiParam.ts +0 -38
  324. package/apps/storefront/src/lib/reporting/admin/viewmodels/reporting.ts +0 -34
  325. package/apps/storefront/src/lib/reporting/fixtures/reporting.ts +0 -51
  326. package/apps/storefront/src/lib/subscriptions/admin/viewmodels/subscriptions.ts +0 -106
  327. package/apps/storefront/src/lib/subscriptions/fixtures/subscriptions.ts +0 -398
  328. package/apps/storefront/src/pages/api/admin/activity-alerts.ts +0 -58
  329. package/apps/storefront/src/pages/api/admin/commerce-readiness.ts +0 -172
  330. package/apps/storefront/src/pages/api/admin/fulfillment/batches.ts +0 -59
  331. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id]/address.ts +0 -66
  332. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id].ts +0 -118
  333. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contact-search.ts +0 -26
  334. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contacts.ts +0 -22
  335. package/apps/storefront/src/pages/api/admin/interaction-insights.ts +0 -101
  336. package/apps/storefront/src/pages/api/admin/orders/[id].ts +0 -63
  337. package/apps/storefront/src/pages/api/admin/orders.ts +0 -65
  338. package/apps/storefront/src/pages/api/contact.ts +0 -144
  339. package/apps/storefront/src/scheduled/contactVaultSweep.ts +0 -113
  340. package/apps/storefront/src/styles/admin.css +0 -1161
  341. package/apps/storefront/test/pipeline/fake-preview-services.ts +0 -288
  342. package/apps/storefront/test/pipeline/harness.ts +0 -209
  343. package/apps/storefront/test/pipeline/intake-worker.mjs +0 -14
  344. package/apps/storefront/test/pipeline/matrix-faults.ts +0 -366
  345. package/apps/storefront/test/pipeline/pipeline-host.ts +0 -418
  346. package/apps/storefront/test/pipeline/pool-config.cjs +0 -85
  347. package/apps/storefront/test/pipeline/publish-kinds.ts +0 -279
  348. package/apps/storefront/test/pipeline/synthetic-job.ts +0 -303
  349. package/apps/storefront/test/pipeline-faults/matrix-lib.ts +0 -696
  350. package/apps/storefront/vitest.config.cts +0 -44
  351. package/apps/storefront/vitest.faults.config.cts +0 -13
  352. package/apps/storefront/vitest.workers.config.cts +0 -7
  353. package/packages/feedback/fixtures/v1/expected-findings.json +0 -16
  354. package/packages/feedback/fixtures/v1/feedback-action/invalid/carries-transport-credential.json +0 -14
  355. package/packages/feedback/fixtures/v1/feedback-action/invalid/control-char-in-description.json +0 -13
  356. package/packages/feedback/fixtures/v1/feedback-action/invalid/legacy-schema-version.json +0 -13
  357. package/packages/feedback/fixtures/v1/feedback-action/invalid/page-path-with-query.json +0 -14
  358. package/packages/feedback/fixtures/v1/feedback-action/invalid/title-too-short.json +0 -13
  359. package/packages/feedback/fixtures/v1/feedback-action/valid/element-problem.json +0 -33
  360. package/packages/feedback/fixtures/v1/feedback-action/valid/page-comment.json +0 -20
  361. package/packages/feedback/fixtures/v1/feedback-action/valid/region-improvement.json +0 -24
  362. package/packages/feedback/fixtures/v1/feedback-action/valid/text-selection-feature.json +0 -30
  363. package/packages/feedback/fixtures/v1/submission-receipt/invalid/accepted-at-not-utc.json +0 -9
  364. package/packages/feedback/fixtures/v1/submission-receipt/invalid/bad-feedback-id.json +0 -9
  365. package/packages/feedback/fixtures/v1/submission-receipt/invalid/legacy-contract-version.json +0 -9
  366. package/packages/feedback/fixtures/v1/submission-receipt/invalid/missing-replayed.json +0 -8
  367. package/packages/feedback/fixtures/v1/submission-receipt/valid/accepted.json +0 -9
  368. package/packages/feedback/fixtures/v1/submission-receipt/valid/fractional-seconds.json +0 -9
  369. package/packages/feedback/fixtures/v1/submission-receipt/valid/replayed.json +0 -9
  370. package/packages/feedback/fixtures/v1/target-evidence/invalid/page-kind-claims-structure.json +0 -6
  371. package/packages/feedback/fixtures/v1/target-evidence/invalid/path-too-deep.json +0 -17
  372. package/packages/feedback/fixtures/v1/target-evidence/invalid/relative-region-out-of-range.json +0 -11
  373. package/packages/feedback/fixtures/v1/target-evidence/invalid/selector-uses-class.json +0 -7
  374. package/packages/feedback/fixtures/v1/target-evidence/invalid/source-precision-without-anchor.json +0 -6
  375. package/packages/feedback/fixtures/v1/target-evidence/valid/element-structure.json +0 -21
  376. package/packages/feedback/fixtures/v1/target-evidence/valid/host-iframe.json +0 -14
  377. package/packages/feedback/fixtures/v1/target-evidence/valid/source-anchor.json +0 -12
  378. package/packages/feedback/fixtures/v1/target-evidence/valid/text-selection.json +0 -26
  379. package/packages/feedback/package.json +0 -35
  380. package/packages/feedback/scripts/build-player.mjs +0 -28
  381. package/packages/feedback/src/index.ts +0 -1
  382. package/packages/feedback/src/primitives/composer.ts +0 -639
  383. package/packages/feedback/src/primitives/dialog.ts +0 -263
  384. package/packages/feedback/src/primitives/hostAdapter.ts +0 -116
  385. package/packages/feedback/src/primitives/index.ts +0 -10
  386. package/packages/feedback/src/primitives/launcher.ts +0 -200
  387. package/packages/feedback/src/primitives/picker.ts +0 -663
  388. package/packages/feedback/src/primitives/redaction.ts +0 -204
  389. package/packages/feedback/src/primitives/selection.ts +0 -49
  390. package/packages/feedback/src/primitives/shiftAccelerator.ts +0 -160
  391. package/packages/feedback/src/primitives/styles.ts +0 -77
  392. package/packages/feedback/src/primitives/surface.ts +0 -124
  393. package/packages/feedback/src/primitives/target.ts +0 -293
  394. package/packages/feedback/src/tour/canonical.ts +0 -27
  395. package/packages/feedback/src/tour/index.ts +0 -3
  396. package/packages/feedback/src/tour/player/browser.ts +0 -5
  397. package/packages/feedback/src/tour/player/host.ts +0 -12
  398. package/packages/feedback/src/tour/player/index.ts +0 -205
  399. package/packages/feedback/src/tour/player/manifest.ts +0 -76
  400. package/packages/feedback/src/tour/player/player.css +0 -130
  401. package/packages/feedback/src/tour/player/resolver.ts +0 -12
  402. package/packages/feedback/src/tour/player/surface.ts +0 -295
  403. package/packages/feedback/src/tour/player/types.ts +0 -8
  404. package/packages/feedback/src/tour/resolve/core.ts +0 -267
  405. package/packages/feedback/src/tour/resolve/dom.ts +0 -115
  406. package/packages/feedback/src/tour/resolve/index.ts +0 -29
  407. package/packages/feedback/src/tour/sanitize.ts +0 -76
  408. package/packages/feedback/src/tour/schema.ts +0 -362
  409. package/packages/feedback/src/v1/guards.ts +0 -335
  410. package/packages/feedback/src/v1/index.ts +0 -3
  411. package/packages/feedback/src/v1/protectedSurfaces.ts +0 -32
  412. package/packages/feedback/src/v1/types.ts +0 -177
  413. package/packages/feedback/tsconfig.json +0 -9
  414. package/packages/feedback/vitest.config.cts +0 -21
@@ -1,148 +0,0 @@
1
- /**
2
- * The DIAGNOSTIC REFERENCE — one short, self-describing handle a tenant can quote when something
3
- * goes wrong, and the key every diagnostic surface correlates on.
4
- *
5
- * WHY A NEW ID WHEN WE ALREADY MINT SEVERAL. We do not lack correlation ids — `dispatchId`,
6
- * `operationId`, `runUrl` and the activity rows all exist and all work. What none of them is, is
7
- * QUOTABLE. The publish dialog's support reference today is the raw dispatch id
8
- * (`dsp:rcpt:tenant.com:preview:run-<uuid>:5:<uuid>`): correct, unambiguous, and unusable by a human
9
- * who has to read it off a screen, type it into a message, or say it on a call. So a tenant hitting
10
- * a problem either pastes something they cannot check, or — as actually happened — opens an agent
11
- * session to file a report on their behalf.
12
- *
13
- * This is a KEY, NOT A CONTAINER. It carries no diagnostic data of its own and replaces none of the
14
- * ids above; it resolves TO them. Nothing moves, and the existing per-surface redaction rules keep
15
- * deciding who may see what.
16
- *
17
- * FORMAT: `TOT-<stage><YYMMDD>-<token>` — e.g. `TOT-P260923-K7M4QX`.
18
- *
19
- * stage `P` preview / `L` live. Which substrate this happened on, before opening anything —
20
- * the first question asked of every report, answered by the reference itself.
21
- * YYMMDD the UTC day. Makes retention self-evident: a reference older than the window cannot
22
- * resolve, and reads as old rather than as broken.
23
- * token 6 chars of Crockford base32, an alphabet that omits I, L, O and U by construction. The
24
- * first three cannot be misread as 1/1/0 on a screen or over a call, and the absence of U
25
- * is what keeps a random token from spelling something unfortunate in front of a merchant.
26
- *
27
- * Case-insensitive on the way in, canonical upper on the way out, because it WILL be retyped.
28
- */
29
-
30
- /** Stages a reference can be minted for, and the letter each contributes. */
31
- export type DiagnosticStage = "preview" | "live";
32
-
33
- const STAGE_LETTER: Readonly<Record<DiagnosticStage, string>> = Object.freeze({
34
- preview: "P",
35
- live: "L",
36
- });
37
-
38
- const LETTER_STAGE: Readonly<Record<string, DiagnosticStage>> = Object.freeze({
39
- P: "preview",
40
- L: "live",
41
- });
42
-
43
- /**
44
- * Crockford base32 — 32 symbols that already omit I, L, O and U, which is exactly why it is the
45
- * right alphabet here rather than something to be filtered after the fact. 6 chars gives 32^6 ≈
46
- * 1.07 billion, ample for a handle scoped to one stage and one day.
47
- */
48
- const TOKEN_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
49
-
50
- /** How many token characters a reference carries. */
51
- const TOKEN_LENGTH = 6;
52
-
53
- /** The canonical shape, anchored — used to validate anything arriving from a URL or a paste. */
54
- const REFERENCE_RE = new RegExp(`^TOT-([PL])(\\d{6})-([${TOKEN_ALPHABET}]{${TOKEN_LENGTH}})$`);
55
-
56
- /** The parts a reference encodes, recovered from the string itself. */
57
- export interface ParsedDiagnosticReference {
58
- /** Which substrate the problem occurred on. */
59
- stage: DiagnosticStage;
60
- /** The UTC day, as `YYMMDD` — exactly the characters in the reference, not a re-derivation. */
61
- day: string;
62
- /** The random token, canonical upper-case. */
63
- token: string;
64
- /** The whole reference, canonicalised. */
65
- reference: string;
66
- }
67
-
68
- /** `YYMMDD` in UTC. Deliberately UTC: a reference must mean the same day to a reporter and to us. */
69
- function utcDay(now: Date): string {
70
- const yy = String(now.getUTCFullYear() % 100).padStart(2, "0");
71
- const mm = String(now.getUTCMonth() + 1).padStart(2, "0");
72
- const dd = String(now.getUTCDate()).padStart(2, "0");
73
- return `${yy}${mm}${dd}`;
74
- }
75
-
76
- /**
77
- * Mint a reference for a problem that just occurred.
78
- *
79
- * `randomBytes` is injected so this stays pure and testable; real callers omit it and get
80
- * `crypto.getRandomValues`, which exists on Workers and in the browser.
81
- */
82
- export function mintDiagnosticReference(args: {
83
- stage: DiagnosticStage;
84
- /** When it happened. Injected so a test is not at the mercy of the clock. */
85
- now?: Date;
86
- /** Fill a byte array with randomness. Injected for tests; defaults to WebCrypto. */
87
- randomBytes?: (n: number) => Uint8Array;
88
- }): string {
89
- const now = args.now ?? new Date();
90
- return `TOT-${STAGE_LETTER[args.stage]}${utcDay(now)}-${mintToken(TOKEN_LENGTH, args.randomBytes)}`;
91
- }
92
-
93
- /**
94
- * `length` characters of the reading-safe alphabet. Exported so every human-quotable id in the
95
- * diagnostics surface — the reference, the session id — draws from ONE alphabet. A second id that
96
- * quietly used a different one would reintroduce exactly the characters this alphabet exists to
97
- * keep out, on the id nobody thought to check.
98
- */
99
- export function mintToken(length: number, randomBytes?: (n: number) => Uint8Array): string {
100
- const fill = randomBytes ?? ((n: number) => crypto.getRandomValues(new Uint8Array(n)));
101
- // 256 is a whole multiple of 32, so a plain modulo is already uniform here and `limit` is 256 —
102
- // nothing is ever discarded. It is written as rejection sampling anyway so that changing the
103
- // alphabet to a non-power-of-two length stays correct instead of silently skewing the token.
104
- const limit = Math.floor(256 / TOKEN_ALPHABET.length) * TOKEN_ALPHABET.length;
105
- let token = "";
106
- while (token.length < length) {
107
- for (const byte of fill(length * 2)) {
108
- if (token.length >= length) break;
109
- if (byte >= limit) continue;
110
- token += TOKEN_ALPHABET[byte % TOKEN_ALPHABET.length];
111
- }
112
- }
113
- return token;
114
- }
115
-
116
- /**
117
- * Parse a reference a human supplied — from a URL, a pasted message, a screenshot they retyped.
118
- * Tolerant of case and surrounding whitespace, strict about everything else: an id that is not
119
- * exactly this shape is not one of ours, and saying so beats a lookup that mysteriously finds
120
- * nothing.
121
- *
122
- * Returns null rather than throwing — every caller here is handling someone's typo, not an
123
- * exceptional condition.
124
- */
125
- export function parseDiagnosticReference(raw: string | null | undefined): ParsedDiagnosticReference | null {
126
- if (!raw) return null;
127
- const canonical = raw.trim().toUpperCase();
128
- const m = REFERENCE_RE.exec(canonical);
129
- if (!m) return null;
130
- const [, letter, day, token] = m;
131
- const stage = LETTER_STAGE[letter!];
132
- if (!stage) return null;
133
- return { stage, day: day!, token: token!, reference: canonical };
134
- }
135
-
136
- /** Is this a well-formed reference? Sugar over {@link parseDiagnosticReference} for guard clauses. */
137
- export function isDiagnosticReference(raw: string | null | undefined): boolean {
138
- return parseDiagnosticReference(raw) !== null;
139
- }
140
-
141
- /**
142
- * The path a reference resolves at. Kept here, beside the format, because the WHOLE POINT of the
143
- * reference is that holding it is enough to reach the diagnostics — so the code and the door it
144
- * opens must never drift apart in two files.
145
- */
146
- export function diagnosticPathFor(reference: string): string {
147
- return `/diag/${reference.trim().toUpperCase()}`;
148
- }
@@ -1,113 +0,0 @@
1
- /**
2
- * Where a diagnostic reference resolves TO.
3
- *
4
- * The reference is a key (see `reference.ts`); this is the record it opens. Without it `/diag/<ref>`
5
- * has nothing to show and the code is just a nicer-looking dispatch id — so this is the module that
6
- * makes the whole contract true rather than merely well-formed.
7
- *
8
- * WHAT IT HOLDS, AND WHAT IT DELIBERATELY DOES NOT. Only the correlation ids we minted plus the
9
- * merchant-facing text the surface was already showing. No request bodies, no error messages, no
10
- * tenant content. A record is read by whoever holds the code, and the code travels in screenshots
11
- * and support threads — so its contents must be safe wherever the code itself is safe.
12
- *
13
- * TTL, NOT FOREVER. A reference encodes its own date, so an expired one reads as old rather than as
14
- * broken. Thirty days is long enough that a merchant who reports something a fortnight later still
15
- * gets an answer, and short enough that this never becomes an archive of everything that ever went
16
- * wrong on every tenant.
17
- */
18
- import type { DiagnosticStage } from "./reference";
19
-
20
- /** How long a record outlives the problem it describes. */
21
- export const DIAGNOSTIC_RECORD_TTL_SECONDS = 30 * 24 * 60 * 60;
22
-
23
- /** What `/diag/<ref>` shows, and what a report quotes. */
24
- export interface DiagnosticRecord {
25
- reference: string;
26
- /** Which substrate — matches the letter in the reference itself. */
27
- stage: DiagnosticStage;
28
- /** The tenant this happened on. */
29
- tenant: string;
30
- /** Merchant-facing summary: the text the surface already displayed, never an exception message. */
31
- summary: string;
32
- /** ISO timestamp. */
33
- at: string;
34
- /** The operation's problem code, when it had one. */
35
- code?: string | null;
36
- /** Our own correlation ids, for tracing through build and delivery logs. */
37
- dispatchId?: string | null;
38
- receiptId?: string | null;
39
- pinnedSha?: string | null;
40
- /** The CI run URL. Subject to the same non-owner redaction as everywhere else. */
41
- runUrl?: string | null;
42
- }
43
-
44
- /** The minimal KV surface this needs, so tests need no Workers runtime. */
45
- export interface DiagnosticKv {
46
- get(key: string): Promise<string | null>;
47
- put(key: string, value: string, options?: { expirationTtl?: number }): Promise<void>;
48
- }
49
-
50
- /** Namespaced so a reference can never collide with tenant content or another subsystem's keys. */
51
- export function diagnosticRecordKey(reference: string): string {
52
- return `diag:ref:${reference.trim().toUpperCase()}`;
53
- }
54
-
55
- /**
56
- * Persist a record. NEVER THROWS.
57
- *
58
- * A diagnostic record is a secondary artifact of a failure that has already happened. If writing it
59
- * fails, the merchant must still get their error, their retry and their reference — losing the
60
- * ability to explain a problem must never also lose the problem's own handling. Returns whether it
61
- * landed so a caller can say "reference unavailable" rather than print a code that resolves to
62
- * nothing.
63
- */
64
- export async function putDiagnosticRecord(
65
- kv: DiagnosticKv | null | undefined,
66
- record: DiagnosticRecord,
67
- ttlSeconds: number = DIAGNOSTIC_RECORD_TTL_SECONDS,
68
- ): Promise<boolean> {
69
- if (!kv) return false;
70
- try {
71
- await kv.put(diagnosticRecordKey(record.reference), JSON.stringify(record), {
72
- expirationTtl: ttlSeconds,
73
- });
74
- return true;
75
- } catch {
76
- return false;
77
- }
78
- }
79
-
80
- /**
81
- * Read a record back, or null.
82
- *
83
- * Null covers every failure mode on purpose — absent, expired, unreadable KV, malformed JSON, or a
84
- * record whose shape we no longer recognise. `/diag` shows one honest "we can't find that
85
- * reference" for all of them, because to the person holding the code they are the same situation.
86
- */
87
- export async function getDiagnosticRecord(
88
- kv: DiagnosticKv | null | undefined,
89
- reference: string,
90
- ): Promise<DiagnosticRecord | null> {
91
- if (!kv) return null;
92
- try {
93
- const raw = await kv.get(diagnosticRecordKey(reference));
94
- if (!raw) return null;
95
- const parsed = JSON.parse(raw) as unknown;
96
- return isDiagnosticRecord(parsed) ? parsed : null;
97
- } catch {
98
- return null;
99
- }
100
- }
101
-
102
- /** Structural check on a record read back from storage. Anything we cannot vouch for is not shown. */
103
- function isDiagnosticRecord(value: unknown): value is DiagnosticRecord {
104
- if (!value || typeof value !== "object") return false;
105
- const r = value as Record<string, unknown>;
106
- return (
107
- typeof r.reference === "string" &&
108
- (r.stage === "preview" || r.stage === "live") &&
109
- typeof r.tenant === "string" &&
110
- typeof r.summary === "string" &&
111
- typeof r.at === "string"
112
- );
113
- }
@@ -1,110 +0,0 @@
1
- /**
2
- * "REPORT THIS" — turn a problem the merchant is already looking at into a filed report, with the
3
- * diagnostic reference already in it.
4
- *
5
- * THE LOOP THIS CLOSES. Filing friction has required an MCP tool call, which means a signed-in agent
6
- * session. A tenant developer hitting a publish failure therefore had two options: describe it in
7
- * prose to a human, or open an agent session so something else could file on their behalf. Both
8
- * happened this week. Neither is a reporting path — they are workarounds for the absence of one.
9
- *
10
- * WHAT THIS MODULE IS. The pure payload builder: problem + reference in, a `feedback_submit`-shaped
11
- * report out. It performs no I/O, so the rule about what a report may contain is testable on its own
12
- * and does not depend on whichever surface ends up posting it.
13
- *
14
- * PII IS THE WHOLE RISK HERE. `feedback_submit` clusters reports by title and description and may
15
- * show them to OTHER builders — so those fields carry only our own identifiers and closed-vocabulary
16
- * text. Nothing typed by a person and nothing read from the page goes in them. The tool has a
17
- * dedicated `sensitive` field that is private to ToT admins and never matched; a merchant's own note
18
- * goes THERE, not into the description, because the merchant cannot be expected to know which field
19
- * is which.
20
- */
21
- import { diagnosticPathFor } from "./reference";
22
-
23
- /** The `feedback_submit` fields this builder populates. Deliberately a subset — anything not listed
24
- * is not ours to guess at from a UI click. */
25
- export interface DiagnosticReport {
26
- type: "bug";
27
- category: "platform-bug";
28
- severity: "critical" | "high" | "medium" | "low";
29
- title: string;
30
- description: string;
31
- project: string;
32
- scope: "project";
33
- /** Free text the merchant typed, kept out of the clustered fields. Omitted when they typed none. */
34
- sensitive?: string;
35
- /** Stable class for triage, when the problem carried a code. */
36
- errorClass?: string;
37
- }
38
-
39
- /** What the surface knows when the merchant clicks Report. */
40
- export interface DiagnosticReportInput {
41
- /** The quotable reference for this problem. */
42
- reference: string;
43
- /** The tenant this happened on. */
44
- tenant: string;
45
- /** Merchant-facing summary already on screen — our text, not an exception message. */
46
- summary: string;
47
- /** The operation's problem code, when it had one. Closed enum; used for triage clustering. */
48
- code?: string | null;
49
- /** The browser session, when one was established. */
50
- sessionId?: string | null;
51
- /** Whether debug capture was on, so triage knows whether a trail exists before going to look. */
52
- debugCaptureOn?: boolean;
53
- /** Anything the merchant typed. Goes to `sensitive`, never to the clustered fields. */
54
- note?: string | null;
55
- }
56
-
57
- /** Severity by problem code. A publish that cannot proceed is blocking; everything else defaults to
58
- * high rather than critical, because a human triages these and over-claiming is its own noise. */
59
- function severityFor(code: string | null | undefined): DiagnosticReport["severity"] {
60
- switch (code) {
61
- case "delivery-undeliverable":
62
- case "bundle-unavailable":
63
- return "critical";
64
- case "checks-blocked":
65
- case "compliance-review":
66
- case "needs-confirmation":
67
- case "not-ready":
68
- return "medium";
69
- default:
70
- return "high";
71
- }
72
- }
73
-
74
- /**
75
- * Build the report.
76
- *
77
- * The title leads with the reference so the queue is searchable by the thing the merchant is
78
- * holding — someone who quotes only the code in a thread can be matched to their own report without
79
- * a lookup.
80
- */
81
- export function buildDiagnosticReport(input: DiagnosticReportInput): DiagnosticReport {
82
- const lines = [
83
- `Reported from the storefront UI by a tenant, using the in-product report action.`,
84
- ``,
85
- `Reference: ${input.reference}`,
86
- `Diagnostics: ${diagnosticPathFor(input.reference)}`,
87
- `Tenant: ${input.tenant}`,
88
- `What the merchant was shown: ${input.summary}`,
89
- input.code ? `Problem code: ${input.code}` : null,
90
- input.sessionId ? `Session: ${input.sessionId}` : null,
91
- // Say plainly whether a trail exists. Triage otherwise opens the reference, finds nothing, and
92
- // cannot tell "no events" from "capture was off" — which is the ambiguity that wastes the hour.
93
- `Debug capture: ${input.debugCaptureOn ? "on — a session trail is attached to the reference" : "off — no client trail was recorded"}`,
94
- ].filter((l): l is string => l !== null);
95
-
96
- const report: DiagnosticReport = {
97
- type: "bug",
98
- category: "platform-bug",
99
- severity: severityFor(input.code),
100
- title: `${input.reference}: ${input.summary}`.slice(0, 200),
101
- description: lines.join("\n").slice(0, 4000),
102
- project: "storefront",
103
- scope: "project",
104
- };
105
- if (input.code) report.errorClass = input.code;
106
- // The merchant's own words are the one field that can contain anything at all.
107
- const note = input.note?.trim();
108
- if (note) report.sensitive = note.slice(0, 4000);
109
- return report;
110
- }
@@ -1,91 +0,0 @@
1
- /**
2
- * The document's server response time for the evidence panel, measured in the viewer's browser
3
- * (a Worker fetching its own zone is answered by the origin, never by this Worker, so a
4
- * server-side self-fetch cannot see the render). The panel script fetches the home document
5
- * same-origin with the viewer's credentials and `__preview` grant, then reports the `total` the
6
- * Worker stamps in `Server-Timing` (`lib/observability/shared/serverTiming.ts`) beside the time to
7
- * first byte. Advisory — never gates promotion.
8
- *
9
- * A gate page or any non-200 answer is not the render a reviewer gets, so it is reported as not
10
- * measured rather than as a number.
11
- */
12
-
13
- export interface ServerResponseTime {
14
- measured: true;
15
- /** `total;dur` from the document's `Server-Timing`, or null when the header is absent. */
16
- serverTotalMs: number | null;
17
- /** Time to first byte. */
18
- ttfbMs: number;
19
- /** The isolate was serving its first request (`isolate;desc="cold"`). */
20
- cold: boolean;
21
- }
22
-
23
- export interface ServerResponseTimeUnmeasured {
24
- measured: false;
25
- reason: string;
26
- }
27
-
28
- export type ServerResponseTimeResult = ServerResponseTime | ServerResponseTimeUnmeasured;
29
-
30
- /** Pull `total;dur` and the cold marker out of a `Server-Timing` header value. */
31
- export function parseServerTiming(header: string | null | undefined): Pick<ServerResponseTime, "serverTotalMs" | "cold"> {
32
- if (!header) return { serverTotalMs: null, cold: false };
33
- const entries = header.split(",").map((e) => e.trim());
34
- const total = entries.find((e) => /^total(;|$)/.test(e))?.match(/;\s*dur=([0-9.]+)/);
35
- return {
36
- serverTotalMs: total ? Number(total[1]) : null,
37
- cold: entries.some((e) => /^isolate;\s*desc="cold"$/.test(e)),
38
- };
39
- }
40
-
41
- /** Turn the home document's response into a measurement, or the reason it is not one. */
42
- export function classifyHomeResponse(
43
- res: { status: number; headers: { get(name: string): string | null } },
44
- ttfbMs: number,
45
- ): ServerResponseTimeResult {
46
- const gate = res.headers.get("x-tot-gate");
47
- if (gate) return { measured: false, reason: `the fetch was answered by the access gate (${gate}), not the store render` };
48
- if (res.status !== 200) return { measured: false, reason: `the home document answered ${res.status}, not a render` };
49
- return { measured: true, ...parseServerTiming(res.headers.get("server-timing")), ttfbMs: Math.round(ttfbMs) };
50
- }
51
-
52
- /** The sentence the panel shows for a result. */
53
- export function describeServerResponseTime(result: ServerResponseTimeResult): string {
54
- if (!result.measured) return `Not measured: ${result.reason}.`;
55
- const server = result.serverTotalMs !== null ? `${result.serverTotalMs} ms server total (Server-Timing)` : "no Server-Timing header";
56
- return `Home document: ${server} · ${result.ttfbMs} ms to first byte${result.cold ? " · cold isolate" : ""}. A hosted preview is a Worker render; a published static site is served from the CDN and is faster.`;
57
- }
58
-
59
- export interface BrowserDeps {
60
- fetch: typeof fetch;
61
- /** Resource-timing entries for a URL (`performance.getEntriesByName`). */
62
- entries: (url: string) => PerformanceEntry[];
63
- now: () => number;
64
- }
65
-
66
- /**
67
- * Fetch the home document as the viewer and measure it. TTFB is the resource-timing
68
- * `responseStart - requestStart` for that request, falling back to the wall time to headers.
69
- */
70
- export async function measureHomeDocument(homeUrl: URL, deps: BrowserDeps): Promise<ServerResponseTimeResult> {
71
- try {
72
- const started = deps.now();
73
- const res = await deps.fetch(homeUrl.href, { credentials: "include", redirect: "manual", cache: "no-store" });
74
- const wallMs = deps.now() - started;
75
- await res.arrayBuffer();
76
- const timing = deps.entries(homeUrl.href).at(-1) as PerformanceResourceTiming | undefined;
77
- const ttfbMs = timing && timing.responseStart > 0 && timing.requestStart > 0 ? timing.responseStart - timing.requestStart : wallMs;
78
- return classifyHomeResponse(res, ttfbMs);
79
- } catch {
80
- return { measured: false, reason: "the home document could not be fetched" };
81
- }
82
- }
83
-
84
- /** Measure the home document and write the sentence into `target`. */
85
- export async function mountServerResponseTime(target: Element, pageUrl: string, deps: BrowserDeps): Promise<void> {
86
- const page = new URL(pageUrl);
87
- const homeUrl = new URL(target.getAttribute("data-home-path") ?? "/", page.origin);
88
- const grant = page.searchParams.get("__preview");
89
- if (grant) homeUrl.searchParams.set("__preview", grant);
90
- target.textContent = describeServerResponseTime(await measureHomeDocument(homeUrl, deps));
91
- }
@@ -1,93 +0,0 @@
1
- /**
2
- * The DIAGNOSTIC SESSION ID — a correlation handle for everything one browser session did, so a
3
- * report can be read as a sequence rather than as a single failing call.
4
- *
5
- * WHY, GIVEN WE ALREADY MINT A REFERENCE PER PROBLEM. A reference answers "what broke". Most reports
6
- * also contain some version of "it did something odd just before", and that half has never been
7
- * answerable: each failure is its own island, with nothing tying it to the navigation, the retry, or
8
- * the earlier error that actually explains it. The session id is what lets the trail be assembled.
9
- *
10
- * `TOTS-<8>`, from the SAME reading-safe alphabet as the reference, because it appears in the same
11
- * console line and gets retyped the same way.
12
- *
13
- * DELIBERATELY PER-SESSION, NOT PER-USER. It is a correlation handle with a natural lifetime, not an
14
- * identifier of a person: it lives in `sessionStorage`, so it dies with the tab and never follows
15
- * anyone between visits. On a regulated storefront that distinction is the difference between a
16
- * diagnostic aid and a tracking identifier, and `sessionStorage` is what enforces it rather than a
17
- * promise that we will not join it to anything.
18
- */
19
- import { mintToken } from "./reference";
20
-
21
- /** The key the session id is cached under. Namespaced so it cannot collide with tenant content. */
22
- export const SESSION_STORAGE_KEY = "tot.diag.session";
23
-
24
- /** How many token characters a session id carries — longer than a reference's, and never retyped
25
- * from a screenshot as often, but still readable aloud. */
26
- const SESSION_TOKEN_LENGTH = 8;
27
-
28
- /** The canonical session-id shape. */
29
- const SESSION_RE = /^TOTS-[0-9A-HJKMNP-TV-Z]{8}$/;
30
-
31
- /**
32
- * The minimal storage surface this needs. Typed structurally rather than as `Storage` so a test can
33
- * pass a plain object, and so a caller can hand over any equivalent store without a cast.
34
- */
35
- export interface SessionStore {
36
- getItem(key: string): string | null;
37
- setItem(key: string, value: string): void;
38
- }
39
-
40
- /** Is this a well-formed session id? */
41
- export function isSessionId(raw: string | null | undefined): boolean {
42
- return typeof raw === "string" && SESSION_RE.test(raw.trim().toUpperCase());
43
- }
44
-
45
- /** Mint a fresh session id. */
46
- export function mintSessionId(randomBytes?: (n: number) => Uint8Array): string {
47
- return `TOTS-${mintToken(SESSION_TOKEN_LENGTH, randomBytes)}`;
48
- }
49
-
50
- /**
51
- * The session id for this browser session, creating one on first use.
52
- *
53
- * NEVER THROWS, and that is the point rather than politeness: `sessionStorage` throws outright in a
54
- * Safari private window and wherever site data is blocked, and this is DIAGNOSTIC code. Code that
55
- * exists to explain failures must not become one — a storefront that will not render because its
56
- * diagnostics could not find a place to keep an id is a worse bug than any it would have reported.
57
- * When storage is unavailable the id is still minted and returned; it just does not survive the
58
- * navigation, which degrades the trail rather than the page.
59
- */
60
- export function readOrCreateSessionId(args?: {
61
- store?: SessionStore | null;
62
- randomBytes?: (n: number) => Uint8Array;
63
- }): string {
64
- const store = args?.store !== undefined ? args.store : safeSessionStore();
65
- if (store) {
66
- try {
67
- const existing = store.getItem(SESSION_STORAGE_KEY);
68
- if (isSessionId(existing)) return existing!.trim().toUpperCase();
69
- } catch {
70
- // Readable-in-principle, unreadable-in-fact. Fall through and mint.
71
- }
72
- }
73
- const minted = mintSessionId(args?.randomBytes);
74
- if (store) {
75
- try {
76
- store.setItem(SESSION_STORAGE_KEY, minted);
77
- } catch {
78
- // Storage refused the write (private mode, quota, blocked site data). The id is still good
79
- // for this page; it simply will not be the same one after a navigation.
80
- }
81
- }
82
- return minted;
83
- }
84
-
85
- /** `sessionStorage` when it exists AND is usable, else null. Merely existing is not enough — the
86
- * accessor itself throws in some configurations. */
87
- function safeSessionStore(): SessionStore | null {
88
- try {
89
- return typeof sessionStorage === "undefined" ? null : sessionStorage;
90
- } catch {
91
- return null;
92
- }
93
- }