@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,175 +0,0 @@
1
- /**
2
- * Client logic for the admin Messages tab (`/api/admin/messages`).
3
- *
4
- * Every visitor-supplied value is written with `textContent`; nothing from a
5
- * message is ever parsed as markup.
6
- *
7
- * Optional exact-match filter: a `form[data-messages-filter]` with a `kind`
8
- * control (`email` | `phone`) and a `value` input. A filtered load POSTs
9
- * `{ [kind]: value }` as the body — never a URL parameter — and an empty value
10
- * (or `[data-messages-filter-clear]`) returns to the full inbox.
11
- */
12
-
13
- type MessageFilter = { kind: "email" | "phone"; value: string } | null;
14
-
15
- interface InboxMessage {
16
- id: string;
17
- status: string;
18
- name?: string | null;
19
- email?: string | null;
20
- phone?: string | null;
21
- message?: string | null;
22
- pagePath?: string | null;
23
- createdAt: string;
24
- }
25
-
26
- interface ApiResult {
27
- ok: boolean;
28
- status: number;
29
- data: { ok?: boolean; error?: string; messages?: InboxMessage[]; unread?: number };
30
- }
31
-
32
- const UNREADABLE = { ok: false, error: "unreadable_response" } as const;
33
-
34
- async function call(url: string, init?: RequestInit): Promise<ApiResult> {
35
- const res = await fetch(url, init);
36
- const text = await res.text();
37
- let data: ApiResult["data"] = { ...UNREADABLE };
38
- try {
39
- data = JSON.parse(text) as ApiResult["data"];
40
- } catch {
41
- data = { ...UNREADABLE };
42
- }
43
- return { ok: res.ok && data.ok === true, status: res.status, data };
44
- }
45
-
46
- function setText(row: HTMLElement, field: string, value: string | null | undefined): void {
47
- const el = row.querySelector<HTMLElement>(`[data-field="${field}"]`);
48
- if (!el) return;
49
- el.textContent = value || "";
50
- el.hidden = !value;
51
- }
52
-
53
- export function initMessagesTab(root: HTMLElement): void {
54
- const statusEl = root.querySelector<HTMLElement>("[data-messages-status]");
55
- const panel = root.querySelector<HTMLElement>("[data-messages-panel]");
56
- const list = root.querySelector<HTMLElement>("[data-messages-list]");
57
- const empty = root.querySelector<HTMLElement>("[data-messages-empty]");
58
- const unreadEl = root.querySelector<HTMLElement>("[data-messages-unread]");
59
- const template = root.querySelector<HTMLTemplateElement>("template[data-messages-row]");
60
- const refresh = root.querySelector<HTMLElement>("[data-messages-refresh]");
61
- if (!statusEl || !panel || !list || !empty || !unreadEl || !template || !refresh) return;
62
- const filterForm = root.querySelector<HTMLFormElement>("form[data-messages-filter]");
63
- let loaded = false;
64
- let filter: MessageFilter = null;
65
-
66
- const setStatus = (text: string, tone: "error" | null): void => {
67
- statusEl.textContent = text;
68
- if (tone) statusEl.setAttribute("data-tone", tone);
69
- else statusEl.removeAttribute("data-tone");
70
- statusEl.hidden = !text;
71
- };
72
-
73
- const renderRow = (message: InboxMessage): HTMLElement => {
74
- const row = template.content.firstElementChild!.cloneNode(true) as HTMLElement;
75
- row.dataset.messageId = message.id;
76
- row.dataset.status = message.status;
77
- setText(row, "name", message.name || "(no name)");
78
- setText(row, "email", message.email);
79
- setText(row, "phone", message.phone);
80
- setText(row, "message", message.message);
81
- setText(row, "pagePath", message.pagePath ? `Sent from ${message.pagePath}` : "");
82
- const when = row.querySelector<HTMLElement>('[data-field="createdAt"]')!;
83
- when.setAttribute("datetime", message.createdAt);
84
- when.textContent = new Date(message.createdAt).toLocaleString();
85
- row.querySelector<HTMLElement>('[data-field="unread"]')!.hidden = message.status !== "unread";
86
- const readBtn = row.querySelector<HTMLButtonElement>('[data-message-action="read"]')!;
87
- readBtn.hidden = message.status !== "unread";
88
- readBtn.addEventListener("click", () => void act(row, "read"));
89
- row
90
- .querySelector<HTMLButtonElement>('[data-message-action="delete"]')!
91
- .addEventListener("click", () => void act(row, "delete"));
92
- return row;
93
- };
94
-
95
- const load = async (): Promise<void> => {
96
- loaded = true;
97
- setStatus("Loading messages…", null);
98
- try {
99
- const { ok, status, data } = await call(
100
- "/api/admin/messages",
101
- filter
102
- ? {
103
- method: "POST",
104
- headers: { accept: "application/json", "content-type": "application/json" },
105
- body: JSON.stringify({ [filter.kind]: filter.value }),
106
- }
107
- : { headers: { accept: "application/json" } },
108
- );
109
- if (!ok) {
110
- setStatus(`Could not load messages (${data.error || status}).`, "error");
111
- return;
112
- }
113
- const messages = data.messages ?? [];
114
- list.replaceChildren(...messages.map(renderRow));
115
- empty.hidden = messages.length !== 0;
116
- unreadEl.textContent = `${data.unread ?? 0} unread`;
117
- panel.hidden = false;
118
- setStatus("", null);
119
- } catch {
120
- setStatus("Could not load messages: the request did not reach the server.", "error");
121
- }
122
- };
123
-
124
- const act = async (row: HTMLElement, action: "read" | "delete"): Promise<void> => {
125
- const id = row.dataset.messageId ?? "";
126
- if (action === "delete" && !confirm("Delete this message? This cannot be undone.")) return;
127
- const url = `/api/admin/messages/${encodeURIComponent(id)}`;
128
- const init: RequestInit =
129
- action === "delete"
130
- ? { method: "DELETE" }
131
- : {
132
- method: "POST",
133
- headers: { "content-type": "application/json" },
134
- body: JSON.stringify({ action: "read" }),
135
- };
136
- const buttons = row.querySelectorAll<HTMLButtonElement>("button");
137
- buttons.forEach((b) => (b.disabled = true));
138
- try {
139
- const { ok, status, data } = await call(url, init);
140
- if (!ok) {
141
- setStatus(`Could not update the message (${data.error || status}).`, "error");
142
- return;
143
- }
144
- await load();
145
- } catch {
146
- setStatus("Could not update the message: the request did not reach the server.", "error");
147
- } finally {
148
- buttons.forEach((b) => (b.disabled = false));
149
- }
150
- };
151
-
152
- refresh.addEventListener("click", () => void load());
153
- if (filterForm) {
154
- filterForm.addEventListener("submit", (event) => {
155
- event.preventDefault();
156
- const kind = (filterForm.elements.namedItem("kind") as HTMLSelectElement | null)?.value;
157
- const value = ((filterForm.elements.namedItem("value") as HTMLInputElement | null)?.value ?? "").trim();
158
- filter = value && (kind === "email" || kind === "phone") ? { kind, value } : null;
159
- void load();
160
- });
161
- filterForm.querySelector<HTMLElement>("[data-messages-filter-clear]")?.addEventListener("click", () => {
162
- filterForm.reset();
163
- filter = null;
164
- void load();
165
- });
166
- }
167
- const loadIfShown = (): void => {
168
- if (!loaded && document.documentElement.dataset.adminTab === "messages") void load();
169
- };
170
- new MutationObserver(loadIfShown).observe(document.documentElement, {
171
- attributes: true,
172
- attributeFilter: ["data-admin-tab"],
173
- });
174
- loadIfShown();
175
- }
@@ -1,112 +0,0 @@
1
- /**
2
- * Server-side parsing of one contact-form submission: a byte-capped body read,
3
- * field caps, and header-injection stripping. Pure apart from reading the body.
4
- */
5
- import { CONTACT_LIMITS, type ContactField } from "./contract.js";
6
-
7
- const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
8
- const SINGLE_LINE_STRIP = /[\r\n\0]/g;
9
- const NUL = /\0/g;
10
-
11
- export type BodyRead = { ok: true; text: string } | { ok: false; reason: "too_large" };
12
-
13
- /** Read the body, refusing as soon as it exceeds `maxBytes`. */
14
- export async function readCappedBody(request: Request, maxBytes: number = CONTACT_LIMITS.bodyBytes): Promise<BodyRead> {
15
- const declared = Number(request.headers.get("content-length") ?? "");
16
- if (Number.isFinite(declared) && declared > maxBytes) return { ok: false, reason: "too_large" };
17
- if (!request.body) return { ok: true, text: "" };
18
- const reader = request.body.getReader();
19
- const chunks: Uint8Array[] = [];
20
- let total = 0;
21
- for (;;) {
22
- const { done, value } = await reader.read();
23
- if (done) break;
24
- total += value.byteLength;
25
- if (total > maxBytes) {
26
- await reader.cancel();
27
- return { ok: false, reason: "too_large" };
28
- }
29
- chunks.push(value);
30
- }
31
- const bytes = new Uint8Array(total);
32
- let offset = 0;
33
- for (const chunk of chunks) {
34
- bytes.set(chunk, offset);
35
- offset += chunk.byteLength;
36
- }
37
- return { ok: true, text: new TextDecoder().decode(bytes) };
38
- }
39
-
40
- export interface ParsedContactFields {
41
- name: string;
42
- email: string;
43
- phone: string;
44
- message: string;
45
- }
46
-
47
- export type FieldParse = { ok: true; fields: ParsedContactFields } | { ok: false; field: ContactField };
48
-
49
- /** Remove CR, LF and NUL, then trim: these values may later reach mail headers. */
50
- export function singleLine(value: string): string {
51
- return value.replace(SINGLE_LINE_STRIP, "").trim();
52
- }
53
-
54
- function stringField(body: Record<string, unknown>, key: string): string | undefined {
55
- const value = body[key];
56
- if (value === undefined || value === null) return "";
57
- return typeof value === "string" ? value : undefined;
58
- }
59
-
60
- export function parseContactFields(body: Record<string, unknown>): FieldParse {
61
- const rawName = stringField(body, "name");
62
- const rawEmail = stringField(body, "email");
63
- const rawPhone = stringField(body, "phone");
64
- const rawMessage = stringField(body, "message");
65
- if (rawName === undefined) return { ok: false, field: "name" };
66
- if (rawEmail === undefined) return { ok: false, field: "email" };
67
- if (rawPhone === undefined) return { ok: false, field: "phone" };
68
- if (rawMessage === undefined) return { ok: false, field: "message" };
69
-
70
- const name = singleLine(rawName);
71
- const email = singleLine(rawEmail).toLowerCase();
72
- const phone = singleLine(rawPhone);
73
- const message = rawMessage.replace(NUL, "").trim();
74
-
75
- if (name.length > CONTACT_LIMITS.name) return { ok: false, field: "name" };
76
- if (email.length > CONTACT_LIMITS.email || !EMAIL_RE.test(email)) return { ok: false, field: "email" };
77
- if (phone.length > CONTACT_LIMITS.phone) return { ok: false, field: "phone" };
78
- if (message.length < CONTACT_LIMITS.messageMin || message.length > CONTACT_LIMITS.message) {
79
- return { ok: false, field: "message" };
80
- }
81
- return { ok: true, fields: { name, email, phone, message } };
82
- }
83
-
84
- /** True when the honeypot field carries anything. */
85
- export function honeypotFilled(body: Record<string, unknown>): boolean {
86
- const value = body.company;
87
- if (value === undefined || value === null) return false;
88
- return typeof value !== "string" || value.trim() !== "";
89
- }
90
-
91
- export type ChallengeVerdict = { ok: true } | { ok: false };
92
-
93
- /**
94
- * The bot-challenge seam. Turnstile verification plugs in here; until then every
95
- * submission passes.
96
- */
97
- export async function verifyChallenge(_input: {
98
- tenantId: string;
99
- challenge: string | undefined;
100
- request: Request;
101
- }): Promise<ChallengeVerdict> {
102
- return { ok: true };
103
- }
104
-
105
- /** The submitting page's path from Referer, when it is same-origin. */
106
- export function sameOriginPagePath(request: Request, expectedOrigin: string): string | null {
107
- const referer = request.headers.get("referer");
108
- if (!referer || !URL.canParse(referer)) return null;
109
- const url = new URL(referer);
110
- if (url.origin !== expectedOrigin) return null;
111
- return url.pathname.slice(0, 512);
112
- }
@@ -1,149 +0,0 @@
1
- /**
2
- * MessagesClient — the storefront's seam to tot20's inline-body send (`POST /api/messages`).
3
- *
4
- * The storefront RENDERS its own branded email HTML and hands it to tot20 to TRANSMIT, so we
5
- * reuse tot20's Mandrill SPF/DKIM deliverability (the whole point) while owning the body/brand.
6
- * Used for the magic-link invite email (see lib/access/grants/magicLinkInvite.ts).
7
- *
8
- * POST <core>/api/messages
9
- * { channel:"email", to, subject, html, totApiKey, totSecretKey } → 200 { sent:true, id? }
10
- *
11
- * Creds go in the BODY (`totApiKey`/`totSecretKey`) — tot20's `normalizeSecureUserRequest`, same
12
- * wire rule as the other operator clients. The storefront's operator key already holds
13
- * `messaging:send`. DELIVERABILITY: do NOT set a non-`@tokenoftrust.com` From — omit it so the
14
- * send stays SPF/DKIM-aligned with tot20's domain (a misaligned From lands in spam).
15
- *
16
- * Built like `@/lib/grants/developerInvites` (interface + Http impl + Mock + env factory).
17
- */
18
- import { readEnv } from "@/lib/publication/shared/env";
19
- import {
20
- failureReasonForStatus,
21
- type FailureReason,
22
- } from "@/lib/observability/diag/failureReason";
23
-
24
- export interface InlineEmail {
25
- /** Recipient address. */
26
- to: string;
27
- /** Subject line (your copy). */
28
- subject: string;
29
- /** Fully-rendered branded HTML body (your template). */
30
- html: string;
31
- }
32
-
33
- /**
34
- * `reason` is a finite category. Upstream failure text (exception messages, tot20's
35
- * `message`/`reason` fields) can echo the recipient address, so it never leaves this client.
36
- */
37
- export type MessageSendResult =
38
- | { sent: true; id?: string }
39
- | { sent: false; status: number; reason: FailureReason };
40
-
41
- export interface MessagesClient {
42
- sendInlineEmail(msg: InlineEmail): Promise<MessageSendResult>;
43
- }
44
-
45
- // --- HTTP transport seam (injected by tests) --------------------------------
46
- export interface HttpResponseLike {
47
- status: number;
48
- json(): Promise<unknown>;
49
- }
50
- export interface HttpTransport {
51
- post(url: string, headers: Record<string, string>, body: unknown): Promise<HttpResponseLike>;
52
- }
53
- export class FetchHttpTransport implements HttpTransport {
54
- async post(url: string, headers: Record<string, string>, body: unknown) {
55
- return fetch(url, {
56
- method: "POST",
57
- headers: { "content-type": "application/json", accept: "application/json", ...headers },
58
- body: JSON.stringify(body),
59
- });
60
- }
61
- }
62
-
63
- export class MessagesClientError extends Error {}
64
-
65
- export interface HttpMessagesClientConfig {
66
- baseUrl: string;
67
- apiKey: string;
68
- secretKey?: string;
69
- transport?: HttpTransport;
70
- }
71
-
72
- export class HttpMessagesClient implements MessagesClient {
73
- private readonly baseUrl: string;
74
- private readonly apiKey: string;
75
- private readonly secretKey?: string;
76
- private readonly transport: HttpTransport;
77
-
78
- constructor(config: HttpMessagesClientConfig) {
79
- if (!config.baseUrl) throw new MessagesClientError("messages: TOT_CORE_URL is not configured");
80
- if (!config.apiKey) throw new MessagesClientError("messages: storefront ToT credentials are not configured");
81
- this.baseUrl = config.baseUrl.replace(/\/+$/, "");
82
- this.apiKey = config.apiKey;
83
- this.secretKey = config.secretKey;
84
- this.transport = config.transport ?? new FetchHttpTransport();
85
- }
86
-
87
- private credentialFields(): Record<string, string> {
88
- const f: Record<string, string> = { totApiKey: this.apiKey };
89
- if (this.secretKey) f.totSecretKey = this.secretKey;
90
- return f;
91
- }
92
-
93
- async sendInlineEmail(msg: InlineEmail): Promise<MessageSendResult> {
94
- let res: HttpResponseLike;
95
- try {
96
- res = await this.transport.post(
97
- `${this.baseUrl}/api/messages`,
98
- {},
99
- {
100
- channel: "email",
101
- to: msg.to,
102
- subject: msg.subject,
103
- html: msg.html,
104
- // No fromEmail/fromName → stays SPF/DKIM-aligned with tot20's domain (deliverability).
105
- ...this.credentialFields(),
106
- },
107
- );
108
- } catch {
109
- return { sent: false, status: 0, reason: "transport" };
110
- }
111
- let body: unknown;
112
- try {
113
- body = await res.json();
114
- } catch {
115
- return { sent: false, status: res.status, reason: "non-json" };
116
- }
117
- return normalizeSend(res.status, body);
118
- }
119
- }
120
-
121
- /** Parse tot20's `{ content, metadata }` send response into a typed result (fail closed). */
122
- export function normalizeSend(status: number, body: unknown): MessageSendResult {
123
- const raw = (body ?? {}) as Record<string, unknown>;
124
- const c = (raw.content && typeof raw.content === "object" ? raw.content : raw) as Record<string, unknown>;
125
- if (c.sent === true || (status >= 200 && status < 300 && c.sent !== false)) {
126
- return { sent: true, ...(typeof c.id === "string" ? { id: c.id } : {}) };
127
- }
128
- return { sent: false, status, reason: failureReasonForStatus(status) };
129
- }
130
-
131
- // --- Mock (tests + local dev) -----------------------------------------------
132
- export class MockMessagesClient implements MessagesClient {
133
- sent: InlineEmail[] = [];
134
- constructor(private readonly result: MessageSendResult = { sent: true, id: "mock-msg" }) {}
135
- async sendInlineEmail(msg: InlineEmail): Promise<MessageSendResult> {
136
- this.sent.push(msg);
137
- return this.result;
138
- }
139
- }
140
-
141
- // --- Factory ----------------------------------------------------------------
142
- export async function createMessagesClient(
143
- overrides: Partial<HttpMessagesClientConfig> = {},
144
- ): Promise<HttpMessagesClient> {
145
- const baseUrl = overrides.baseUrl ?? (await readEnv("TOT_CORE_URL")) ?? "";
146
- const apiKey = overrides.apiKey ?? (await readEnv("TOT_API_KEY")) ?? "";
147
- const secretKey = overrides.secretKey ?? (await readEnv("TOT_SECRET_KEY"));
148
- return new HttpMessagesClient({ ...overrides, baseUrl, apiKey, secretKey });
149
- }
@@ -1,117 +0,0 @@
1
- /**
2
- * Hand-rolled newsletter digest HTML builder — the email analogue of
3
- * `renderRssFeed` (src/lib/content/blog/rss.ts): pure string concatenation, no
4
- * templating dependency. Fed the engine's live-visible post list, so drafts /
5
- * unlisted / not-yet-scheduled posts can never reach an inbox.
6
- *
7
- * The digest is built ONCE per send and carries a per-recipient unsubscribe
8
- * token PLACEHOLDER ({@link UNSUBSCRIBE_TOKEN_PLACEHOLDER}); the send pipeline
9
- * interpolates each subscriber's real token before handing the message to the
10
- * ESP (see send.ts). The RFC 8058 `List-Unsubscribe` headers are set on the
11
- * SEND call, not in this HTML body.
12
- */
13
- import type { BlogPostSummary } from "../../content/blog/types.js";
14
-
15
- /** Replaced per-recipient with the subscriber's opaque token at send time. */
16
- export const UNSUBSCRIBE_TOKEN_PLACEHOLDER = "{{unsubscribe_token}}";
17
-
18
- /** The unsubscribe endpoint path (N3 owns the route); shared with the send headers. */
19
- export const UNSUBSCRIBE_PATH = "/api/newsletter/unsubscribe";
20
-
21
- export interface DigestConfig {
22
- /** CAN-SPAM physical postal address, rendered in the footer (per-tenant config). */
23
- postalAddress: string;
24
- /** Sender display name; used only for the digest heading here. */
25
- fromName?: string;
26
- /** Resolved canonical base, e.g. `https://x.com` — post links + unsubscribe URL. */
27
- canonicalBase: string;
28
- }
29
-
30
- /** Build the one-click unsubscribe URL for a given token (or placeholder). */
31
- export function unsubscribeUrl(canonicalBase: string, token: string): string {
32
- const base = canonicalBase.replace(/\/$/, "");
33
- return `${base}${UNSUBSCRIBE_PATH}?token=${token}`;
34
- }
35
-
36
- /** HTML-escape text placed in element content or a quoted attribute. */
37
- function escapeHtml(value: string): string {
38
- return value
39
- .replace(/&/g, "&amp;")
40
- .replace(/</g, "&lt;")
41
- .replace(/>/g, "&gt;")
42
- .replace(/"/g, "&quot;")
43
- .replace(/'/g, "&#39;");
44
- }
45
-
46
- const MONTHS = [
47
- "January", "February", "March", "April", "May", "June",
48
- "July", "August", "September", "October", "November", "December",
49
- ];
50
-
51
- /** Deterministic UTC "Month D, YYYY" (no locale/timezone drift in tests). */
52
- function formatDate(iso: string): string {
53
- const d = new Date(iso);
54
- if (Number.isNaN(d.getTime())) return "";
55
- return `${MONTHS[d.getUTCMonth()]} ${d.getUTCDate()}, ${d.getUTCFullYear()}`;
56
- }
57
-
58
- /**
59
- * Render the digest email body. `collection` fixes the route base (`/<collection>`,
60
- * mirroring the RSS renderer's `collectionBase`) so post links resolve to the
61
- * live article. Every message carries an unsubscribe link (placeholder token)
62
- * and the CAN-SPAM postal address in the footer.
63
- */
64
- export function buildDigestHtml(
65
- tenantId: string,
66
- collection: string,
67
- posts: BlogPostSummary[],
68
- config: DigestConfig,
69
- ): string {
70
- const base = config.canonicalBase.replace(/\/$/, "");
71
- const collectionBase = `/${collection.replace(/^\/+|\/+$/g, "")}`;
72
- const heading = escapeHtml(config.fromName ?? "The latest");
73
-
74
- const items = posts
75
- .map((post) => {
76
- const link = `${base}${collectionBase}/${post.slug}/`;
77
- const date = formatDate(post.publishedAt);
78
- const image = post.featuredImage
79
- ? ` <p><a href="${escapeHtml(link)}"><img src="${escapeHtml(post.featuredImage.src)}" alt="${escapeHtml(post.featuredImage.alt)}" style="max-width:100%;height:auto;border-radius:8px;" /></a></p>`
80
- : "";
81
- return [
82
- ` <article style="margin:0 0 2rem;">`,
83
- image,
84
- ` <h2 style="margin:0 0 .35rem;font-size:1.25rem;"><a href="${escapeHtml(link)}" style="color:#2f3a34;text-decoration:none;">${escapeHtml(post.title)}</a></h2>`,
85
- date ? ` <p style="margin:0 0 .5rem;color:#8a938c;font-size:.85rem;">${escapeHtml(date)}</p>` : "",
86
- ` <p style="margin:0 0 .5rem;color:#5a655e;line-height:1.6;">${escapeHtml(post.excerpt)}</p>`,
87
- ` <p style="margin:0;"><a href="${escapeHtml(link)}" style="color:#2f3a34;font-weight:600;">Read more &rarr;</a></p>`,
88
- ` </article>`,
89
- ]
90
- .filter(Boolean)
91
- .join("\n");
92
- })
93
- .join("\n");
94
-
95
- const unsubUrl = unsubscribeUrl(config.canonicalBase, UNSUBSCRIBE_TOKEN_PLACEHOLDER);
96
- const postalHtml = escapeHtml(config.postalAddress).replace(/\n/g, "<br />");
97
-
98
- return `<!doctype html>
99
- <html lang="en">
100
- <head>
101
- <meta charset="utf-8" />
102
- <meta name="viewport" content="width=device-width, initial-scale=1" />
103
- </head>
104
- <body style="margin:0;background:#f4f1ea;color:#2f3a34;font-family:ui-serif,Georgia,serif;">
105
- <div style="max-width:37.5rem;margin:0 auto;padding:2rem 1.5rem;">
106
- <h1 style="font-size:1.5rem;margin:0 0 1.5rem;">${heading}</h1>
107
- ${items}
108
- <hr style="border:none;border-top:1px solid #d8d3c6;margin:2rem 0 1rem;" />
109
- <p style="color:#8a938c;font-size:.8rem;line-height:1.6;margin:0 0 .5rem;">
110
- You're receiving this because you subscribed. <a href="${escapeHtml(unsubUrl)}" style="color:#8a938c;">Unsubscribe</a>.
111
- </p>
112
- <p style="color:#8a938c;font-size:.8rem;line-height:1.6;margin:0;">${postalHtml}</p>
113
- </div>
114
- </body>
115
- </html>
116
- `;
117
- }
@@ -1,79 +0,0 @@
1
- /**
2
- * Thin `fetch`-based Resend client — no SDK, no npm dependency (the newsletter
3
- * spike's Workers-native rationale, docs/plans/2026-08-22-newsletter-send-spike.md
4
- * §1). We use Resend purely as an SMTP-over-HTTPS sender via its batch endpoint
5
- * (`POST /emails/batch`, up to 100 messages/call); audience/consent/unsubscribe
6
- * state stays first-party in our D1, never in a vendor list.
7
- */
8
- import { readEnv } from "../../publication/shared/env.js";
9
-
10
- /** Resend's batch limit: at most 100 messages per `/emails/batch` call. */
11
- export const RESEND_BATCH_LIMIT = 100;
12
-
13
- const RESEND_BATCH_URL = "https://api.resend.com/emails/batch";
14
-
15
- /** One message in a batch. `reply_to`/`headers` use Resend's wire field names. */
16
- export interface ResendEmail {
17
- from: string;
18
- to: string | string[];
19
- subject: string;
20
- html: string;
21
- reply_to?: string;
22
- headers?: Record<string, string>;
23
- }
24
-
25
- export interface SendBatchResult {
26
- ok: boolean;
27
- status: number;
28
- /** Provider message ids (`data[].id`), one per accepted message. */
29
- ids: string[];
30
- /** Present when `ok` is false — the provider error text, for logging. */
31
- error?: string;
32
- }
33
-
34
- /** The send seam — real impl below; injected as a fake in tests. */
35
- export type SendBatchFn = (apiKey: string, emails: ResendEmail[]) => Promise<SendBatchResult>;
36
-
37
- /** The `RESEND_API_KEY` secret, read via the runtime env accessor (undefined if unset). */
38
- export function readResendApiKey(): Promise<string | undefined> {
39
- return readEnv("RESEND_API_KEY");
40
- }
41
-
42
- /**
43
- * Send up to {@link RESEND_BATCH_LIMIT} messages in one call. An empty list is a
44
- * no-op success (nothing to send). Never throws for a transport/HTTP error —
45
- * returns `{ ok:false }` so the caller decides whether a partial send should
46
- * still record its ledger row.
47
- */
48
- export const sendBatch: SendBatchFn = async (apiKey, emails) => {
49
- if (emails.length === 0) return { ok: true, status: 200, ids: [] };
50
- if (emails.length > RESEND_BATCH_LIMIT) {
51
- throw new Error(`sendBatch received ${emails.length} messages; max is ${RESEND_BATCH_LIMIT}`);
52
- }
53
- let res: Response;
54
- try {
55
- res = await fetch(RESEND_BATCH_URL, {
56
- method: "POST",
57
- headers: {
58
- authorization: `Bearer ${apiKey}`,
59
- "content-type": "application/json",
60
- },
61
- body: JSON.stringify(emails),
62
- });
63
- } catch (err) {
64
- return { ok: false, status: 0, ids: [], error: String(err) };
65
- }
66
-
67
- const bodyText = await res.text();
68
- if (!res.ok) {
69
- return { ok: false, status: res.status, ids: [], error: bodyText };
70
- }
71
- let ids: string[] = [];
72
- try {
73
- const parsed = JSON.parse(bodyText) as { data?: Array<{ id?: string }> };
74
- ids = (parsed.data ?? []).map((d) => d.id ?? "").filter(Boolean);
75
- } catch {
76
- // Accepted (2xx) but unparseable body — treat as sent, no ids surfaced.
77
- }
78
- return { ok: true, status: res.status, ids };
79
- };