@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,556 +0,0 @@
1
- /**
2
- * Orders workspace actions. Every button in the order detail answers: it opens the part of the
3
- * order it names, moves to the tab that resolves it, loads the customer contact details, or says why
4
- * nothing can be done from here. `planOrderAction` decides on the server; `mountOrderActions`
5
- * carries the plan out in the browser. Neither ever leaves a click without a visible result.
6
- */
7
-
8
- export type OrderActionKind = "reveal" | "tab" | "address" | "explain";
9
-
10
- export interface OrderActionPlan {
11
- kind: OrderActionKind;
12
- /** `reveal`: selector of the section inside the order record. `tab`: the admin tab id. */
13
- target: string;
14
- message: string;
15
- }
16
-
17
- export interface OrderActionInput {
18
- /** The readiness check key, or `blocker` for the order-level Resolve hold / next-step buttons. */
19
- check: string;
20
- /** The state the check reports, e.g. `captured`, `UNKNOWN`, `fresh`. */
21
- state: string;
22
- /** The order's blocker label when the order is held. */
23
- blocker?: string | null;
24
- }
25
-
26
- const CLEAR_STATES = new Set(["fresh", "not-required"]);
27
-
28
- function evidenceMessage(label: string, state: string): string {
29
- if (CLEAR_STATES.has(state)) return `${label} evidence is ${state}. Activity and evidence below shows how this order got here.`;
30
- return `${label} evidence is ${state}, so this order stays held. Evidence is recorded when the shopper passes final cart; an order whose final cart is not on record cannot be cleared from admin.`;
31
- }
32
-
33
- export function planOrderAction(input: OrderActionInput): OrderActionPlan {
34
- switch (input.check) {
35
- case "payment_capture":
36
- return {
37
- kind: "explain",
38
- target: "",
39
- message:
40
- input.state === "captured" || input.state === "Captured"
41
- ? "Payment is captured."
42
- : "Payment is captured by the checkout provider and recorded here when it confirms. Admin cannot capture it; check the transaction at the provider.",
43
- };
44
- case "tax_and_fees":
45
- return { kind: "reveal", target: "[data-orders-totals]", message: "Items and totals are open below." };
46
- case "identity_and_age":
47
- return { kind: "reveal", target: "[data-orders-evidence]", message: evidenceMessage("Identity and age", input.state) };
48
- case "risk":
49
- return { kind: "reveal", target: "[data-orders-evidence]", message: evidenceMessage("Risk", input.state) };
50
- case "address":
51
- return { kind: "address", target: "[data-orders-address]", message: "" };
52
- case "stock":
53
- return {
54
- kind: "explain",
55
- target: "",
56
- message:
57
- input.state === "confirmed"
58
- ? "Stock is confirmed for this order."
59
- : `Stock is ${input.state} for this order. Stock is confirmed when the final-cart reservation matches the paid order.`,
60
- };
61
- case "fulfillment":
62
- return { kind: "tab", target: "fulfillment", message: "Fulfillment holds are worked in the Fulfillment tab." };
63
- case "blocker":
64
- return blockerPlan(input);
65
- default:
66
- return { kind: "explain", target: "", message: "Nothing can be done for this check from here." };
67
- }
68
- }
69
-
70
- function blockerPlan(input: OrderActionInput): OrderActionPlan {
71
- if (!input.blocker) {
72
- return { kind: "explain", target: "", message: "This order has no hold." };
73
- }
74
- if (input.blocker === "Payment capture") return planOrderAction({ check: "payment_capture", state: input.state });
75
- if (input.blocker === "Evidence review" || input.blocker === "Age verification hold" || input.blocker === "Verification unknown") {
76
- return planOrderAction({ check: "identity_and_age", state: input.state });
77
- }
78
- return { kind: "tab", target: "fulfillment", message: `${input.blocker}: holds are worked in the Fulfillment tab.` };
79
- }
80
-
81
- /** Address fields shown, in this order. Anything else in a response is dropped. */
82
- const ADDRESS_FIELDS = ["name", "company", "line1", "line2", "city", "region", "postalCode", "country"] as const;
83
-
84
- export function addressLines(address: unknown): string[] {
85
- if (address === null || typeof address !== "object" || Array.isArray(address)) return [];
86
- const record = address as Record<string, unknown>;
87
- const lines: string[] = [];
88
- for (const key of ADDRESS_FIELDS) {
89
- const value = record[key];
90
- if (typeof value === "string" && value.trim() !== "") lines.push(value.trim());
91
- }
92
- return lines;
93
- }
94
-
95
- export const CONTACT_NONE =
96
- "No customer contact details are on file for this order. They are kept for a limited time and are gone once expired or erased.";
97
- export const CONTACT_DENIED = "You cannot view customer contact details for this order.";
98
- export const CONTACT_GRANT_REQUIRED =
99
- "The store owner has not granted ToT support access to customer contact details. Ask the owner to grant it on the " +
100
- "store's Team page, or, if the owner already agreed, record their consent there under Customer contact access.";
101
- export const CONTACT_QUOTA = "The hourly limit for reading customer contact details has been reached. Try again later.";
102
- export const CONTACT_UNAVAILABLE = "Customer contact details are temporarily unavailable. Try again shortly.";
103
- export const CONTACT_FAILED = "The contact details could not be loaded. Try again.";
104
- export const CONTACT_ERASED = "Customer contact details were erased.";
105
- export const ERASE_FAILED = "The contact details could not be erased. Try again.";
106
- export const ERASE_CONFIRM =
107
- "Permanently erase this customer's name, email, phone and addresses? This cannot be undone and the details cannot be recovered.";
108
- export const TICKET_INVALID = "Enter a ticket reference of letters, digits, dot, dash or underscore, up to 64 characters.";
109
-
110
- const TICKET_PATTERN = /^[A-Za-z0-9._-]{1,64}$/;
111
-
112
- /** Support-read reason codes, as the server accepts them. */
113
- export const SUPPORT_REASONS: readonly { code: string; label: string }[] = [
114
- { code: "customer-request", label: "Customer request" },
115
- { code: "delivery-issue", label: "Delivery issue" },
116
- { code: "payment-dispute", label: "Payment dispute" },
117
- { code: "compliance-review", label: "Compliance review" },
118
- { code: "merchant-request", label: "Merchant request" },
119
- ];
120
-
121
- export interface OrderActionDeps {
122
- fetch: typeof fetch;
123
- /** The fulfillment API root for the selected store, or null when this page cannot reach it. */
124
- api: string | null;
125
- navigate: (tab: string) => boolean;
126
- /** Asks the person to confirm an irreversible action. */
127
- confirm: (message: string) => boolean;
128
- }
129
-
130
- export type ContactGroup = "identity" | "email" | "phone" | "ship" | "bill";
131
-
132
- /** The field groups the vault keeps, in display order. */
133
- export const CONTACT_GROUPS: readonly { group: ContactGroup; label: string }[] = [
134
- { group: "identity", label: "Name" },
135
- { group: "email", label: "Email" },
136
- { group: "phone", label: "Phone" },
137
- { group: "ship", label: "Ship to" },
138
- { group: "bill", label: "Bill to" },
139
- ];
140
-
141
- /** Short human labels for the retention rules that hold a group. */
142
- export const RULE_LABELS: Readonly<Record<string, string>> = {
143
- "fulfillment-and-service": "Order fulfillment and service",
144
- "card-disputes": "Card disputes",
145
- "returns-and-warranty": "Returns and warranty",
146
- "returns-and-warranty-eu-eea-uk": "Returns and warranty (EU, EEA, UK)",
147
- "sales-tax-sourcing": "Sales tax sourcing",
148
- "legal-claims": "Legal claims",
149
- "pact-delivery-sale": "PACT delivery-sale record",
150
- };
151
-
152
- export function ruleLabel(id: unknown): string {
153
- if (typeof id !== "string" || id.trim() === "") return "Retention rule";
154
- if (Object.prototype.hasOwnProperty.call(RULE_LABELS, id)) return RULE_LABELS[id]!;
155
- const spaced = id.replace(/[-_]+/g, " ").trim();
156
- return spaced.charAt(0).toUpperCase() + spaced.slice(1);
157
- }
158
-
159
- interface GroupView {
160
- expiresAt: string;
161
- rule: string | null;
162
- }
163
-
164
- interface OrderContact {
165
- customer: unknown;
166
- shipTo: unknown;
167
- billTo: unknown;
168
- /** Only the groups readable now; an expired group is absent. */
169
- groups: Partial<Record<ContactGroup, GroupView>>;
170
- /** Groups the server refused to erase, with the date each is held until. */
171
- held: Partial<Record<ContactGroup, string>>;
172
- }
173
-
174
- function show(note: HTMLElement | null, lines: readonly string[]): void {
175
- if (!note) return;
176
- note.replaceChildren(...lines.map((line) => Object.assign(document.createElement("span"), { textContent: line })));
177
- note.hidden = false;
178
- }
179
-
180
- function node<K extends keyof HTMLElementTagNameMap>(tag: K, text = "", className = ""): HTMLElementTagNameMap[K] {
181
- const element = document.createElement(tag);
182
- if (text) element.textContent = text;
183
- if (className) element.className = className;
184
- return element;
185
- }
186
-
187
- function parseContact(body: unknown): OrderContact | null {
188
- if (body === null || typeof body !== "object" || Array.isArray(body)) return null;
189
- const record = body as Record<string, unknown>;
190
- const raw = record.groups;
191
- if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
192
- const groups: Partial<Record<ContactGroup, GroupView>> = {};
193
- for (const { group } of CONTACT_GROUPS) {
194
- const entry = (raw as Record<string, unknown>)[group];
195
- if (entry === null || typeof entry !== "object") continue;
196
- const { expiresAt, rule } = entry as { expiresAt?: unknown; rule?: unknown };
197
- if (typeof expiresAt !== "string" || Number.isNaN(new Date(expiresAt).getTime())) continue;
198
- groups[group] = { expiresAt, rule: typeof rule === "string" ? rule : null };
199
- }
200
- if (Object.keys(groups).length === 0) return null;
201
- return { customer: record.customer ?? {}, shipTo: record.shipTo ?? {}, billTo: record.billTo ?? {}, groups, held: {} };
202
- }
203
-
204
- function customerField(customer: unknown, key: "name" | "email" | "phone"): string[] {
205
- if (customer === null || typeof customer !== "object") return [];
206
- const value = (customer as Record<string, unknown>)[key];
207
- return typeof value === "string" && value.trim() !== "" ? [value.trim()] : [];
208
- }
209
-
210
- function formatDay(iso: string): string {
211
- return new Date(iso).toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" });
212
- }
213
-
214
- function groupLines(contact: OrderContact, group: ContactGroup): string[] {
215
- if (group === "identity") return customerField(contact.customer, "name");
216
- if (group === "email") return customerField(contact.customer, "email");
217
- if (group === "phone") return customerField(contact.customer, "phone");
218
- return addressLines(group === "ship" ? contact.shipTo : contact.billTo);
219
- }
220
-
221
- function keptUntil(view: GroupView): string {
222
- return `Kept until ${formatDay(view.expiresAt)}. Held by: ${ruleLabel(view.rule)}.`;
223
- }
224
-
225
- function group(label: string, lines: readonly string[], view: GroupView): HTMLElement {
226
- const wrap = node("div", "", "orders-contact-group");
227
- wrap.append(node("strong", label), ...lines.map((line) => node("span", line)), node("small", keptUntil(view)));
228
- return wrap;
229
- }
230
-
231
- async function readJson(response: Response): Promise<unknown> {
232
- try {
233
- return await response.json();
234
- } catch (error) {
235
- // A body that is not JSON shows the status message for this response; anything else is a fault.
236
- if (error instanceof SyntaxError) return null;
237
- throw error;
238
- }
239
- }
240
-
241
- function errorCode(body: unknown): string {
242
- if (body !== null && typeof body === "object" && typeof (body as { error?: unknown }).error === "string") {
243
- return (body as { error: string }).error;
244
- }
245
- return "";
246
- }
247
-
248
- type ContactVia = "owner" | "support";
249
-
250
- interface ContactView {
251
- orderId: string;
252
- panel: HTMLElement;
253
- deps: OrderActionDeps;
254
- }
255
-
256
- /** Turn any contact response into what the panel shows: the details, a reason form, or why there are none. */
257
- async function settleContact(response: Response, via: ContactVia, view: ContactView): Promise<void> {
258
- const { panel } = view;
259
- if (response.status === 404) return show(panel, [CONTACT_NONE]);
260
- if (response.status === 429) return show(panel, [CONTACT_QUOTA]);
261
- if (response.status === 503) return show(panel, [CONTACT_UNAVAILABLE]);
262
- if (response.status === 401 || response.status === 403) {
263
- const code = errorCode(await readJson(response));
264
- if (code === "support-read-required") return renderReasonForm(view);
265
- if (code === "grant-required") return show(panel, [CONTACT_GRANT_REQUIRED]);
266
- return show(panel, [CONTACT_DENIED]);
267
- }
268
- if (!response.ok) return show(panel, [CONTACT_FAILED]);
269
- const contact = parseContact(await readJson(response));
270
- if (!contact) return show(panel, [CONTACT_FAILED]);
271
- renderContact(contact, via, view);
272
- }
273
-
274
- export const ERASE_HELD = (label: string, until: string): string =>
275
- `${label} cannot be erased yet: it must be kept until ${formatDay(until)}.`;
276
- export const ERASE_NONE_SELECTED = "Pick at least one group to erase.";
277
-
278
- function renderContact(contact: OrderContact, via: ContactVia, view: ContactView, notice = ""): void {
279
- const { panel } = view;
280
- const status = node("p", "", "orders-contact-status");
281
- status.setAttribute("role", "status");
282
- status.hidden = true;
283
- const children: HTMLElement[] = [];
284
- for (const { group: key, label } of CONTACT_GROUPS) {
285
- const groupView = contact.groups[key];
286
- if (groupView) children.push(group(label, groupLines(contact, key), groupView));
287
- }
288
- if (via === "owner") {
289
- const picker = node("fieldset", "", "orders-contact-erase-groups");
290
- picker.append(node("legend", "Erase these details"));
291
- const boxes = new Map<ContactGroup, HTMLInputElement>();
292
- for (const { group: key, label } of CONTACT_GROUPS) {
293
- if (!contact.groups[key]) continue;
294
- const holdUntil = contact.held[key];
295
- const box = node("input");
296
- box.type = "checkbox";
297
- box.checked = holdUntil === undefined;
298
- box.disabled = holdUntil !== undefined;
299
- box.setAttribute("data-orders-erase-group", key);
300
- const row = node("label", "", "orders-contact-erase-row");
301
- row.append(box, node("span", holdUntil ? ERASE_HELD(label, holdUntil) : label));
302
- picker.append(row);
303
- boxes.set(key, box);
304
- }
305
- const erase = node("button", "Erase selected", "btn");
306
- erase.type = "button";
307
- erase.setAttribute("data-orders-contact-erase", "");
308
- erase.addEventListener("click", () => void eraseContact(contact, view, boxes, erase, status));
309
- children.push(picker, erase);
310
- }
311
- children.push(status);
312
- if (notice) show(status, [notice]);
313
- panel.replaceChildren(...children);
314
- panel.hidden = false;
315
- }
316
-
317
- async function eraseContact(
318
- contact: OrderContact,
319
- view: ContactView,
320
- boxes: ReadonlyMap<ContactGroup, HTMLInputElement>,
321
- button: HTMLButtonElement,
322
- status: HTMLElement,
323
- ): Promise<void> {
324
- const { deps, orderId, panel } = view;
325
- if (!deps.api) return show(status, [ERASE_FAILED]);
326
- const groups = [...boxes].filter(([, box]) => box.checked && !box.disabled).map(([key]) => key);
327
- if (groups.length === 0) return show(status, [ERASE_NONE_SELECTED]);
328
- if (!deps.confirm(ERASE_CONFIRM)) return;
329
- button.disabled = true;
330
- try {
331
- const response = await deps.fetch(`${deps.api}/orders/${encodeURIComponent(orderId)}/address`, {
332
- method: "DELETE",
333
- credentials: "same-origin",
334
- cache: "no-store",
335
- headers: { "content-type": "application/json" },
336
- body: JSON.stringify({ groups }),
337
- });
338
- const body = await readJson(response);
339
- if (response.ok && (body as { erased?: unknown } | null)?.erased === true) {
340
- const reported = (body as { groups?: unknown }).groups;
341
- const erased = Array.isArray(reported)
342
- ? CONTACT_GROUPS.map((g) => g.group).filter((key) => reported.includes(key))
343
- : groups;
344
- for (const key of erased) delete contact.groups[key];
345
- if (Object.keys(contact.groups).length === 0) return show(panel, [CONTACT_ERASED]);
346
- const names = CONTACT_GROUPS.filter((g) => erased.includes(g.group)).map((g) => g.label).join(", ");
347
- return renderContact(contact, "owner", view, `Erased: ${names}.`);
348
- }
349
- if (response.status === 404) return show(panel, [CONTACT_NONE]);
350
- if (response.status === 409 && errorCode(body) === "retention-hold") {
351
- const held = body as { group?: unknown; holdUntil?: unknown };
352
- const entry = CONTACT_GROUPS.find((g) => g.group === held.group);
353
- if (entry && typeof held.holdUntil === "string" && !Number.isNaN(new Date(held.holdUntil).getTime())) {
354
- contact.held[entry.group] = held.holdUntil;
355
- return renderContact(contact, "owner", view, ERASE_HELD(entry.label, held.holdUntil));
356
- }
357
- }
358
- button.disabled = false;
359
- show(status, [ERASE_FAILED]);
360
- } catch {
361
- button.disabled = false;
362
- show(status, [ERASE_FAILED]);
363
- }
364
- }
365
-
366
- function renderReasonForm(view: ContactView): void {
367
- const { deps, orderId, panel } = view;
368
- const form = node("form", "", "orders-contact-reason");
369
- form.noValidate = true;
370
- const select = node("select");
371
- select.setAttribute("aria-label", "Reason for reading customer contact details");
372
- select.required = true;
373
- for (const reason of SUPPORT_REASONS) select.append(Object.assign(document.createElement("option"), { value: reason.code, textContent: reason.label }));
374
- const ticket = node("input");
375
- ticket.type = "text";
376
- ticket.maxLength = 64;
377
- ticket.autocomplete = "off";
378
- ticket.placeholder = "Ticket reference";
379
- ticket.setAttribute("aria-label", "Support ticket reference");
380
- const submit = node("button", "Read contact details", "btn primary");
381
- submit.type = "submit";
382
- const status = node("p", "", "orders-contact-status");
383
- status.setAttribute("role", "status");
384
- status.hidden = true;
385
- form.append(node("span", "Reading customer contact details as ToT support needs a reason and a ticket. Every read is recorded."), select, ticket, submit, status);
386
- form.addEventListener("submit", (event) => {
387
- event.preventDefault();
388
- if (!deps.api) return show(status, [CONTACT_FAILED]);
389
- const ticketRef = ticket.value.trim();
390
- if (!TICKET_PATTERN.test(ticketRef)) return show(status, [TICKET_INVALID]);
391
- submit.disabled = true;
392
- void (async () => {
393
- try {
394
- const response = await deps.fetch(`${deps.api}/orders/${encodeURIComponent(orderId)}/contact/support-read`, {
395
- method: "POST",
396
- credentials: "same-origin",
397
- cache: "no-store",
398
- headers: { "content-type": "application/json" },
399
- body: JSON.stringify({ reasonCode: select.value, ticketRef }),
400
- });
401
- await settleContact(response, "support", view);
402
- } catch {
403
- submit.disabled = false;
404
- show(status, [CONTACT_FAILED]);
405
- }
406
- })();
407
- });
408
- panel.replaceChildren(form);
409
- panel.hidden = false;
410
- }
411
-
412
- async function loadContact(orderId: string, panel: HTMLElement | null, deps: OrderActionDeps): Promise<void> {
413
- if (!panel) return;
414
- if (!deps.api) return show(panel, [CONTACT_FAILED]);
415
- show(panel, ["Loading contact details…"]);
416
- try {
417
- const response = await deps.fetch(`${deps.api}/orders/${encodeURIComponent(orderId)}/address`, {
418
- credentials: "same-origin",
419
- cache: "no-store",
420
- });
421
- await settleContact(response, "owner", { orderId, panel, deps });
422
- } catch {
423
- show(panel, [CONTACT_FAILED]);
424
- }
425
- }
426
-
427
- export const SEARCH_MALFORMED = "Enter a complete email address or phone number.";
428
- export const SEARCH_NONE = "No orders match that contact.";
429
- export const SEARCH_FAILED = "The search could not be run. Try again.";
430
- export const SEARCH_OWNER_ONLY = "Searching by customer contact is for the store owner.";
431
-
432
- /**
433
- * Exact-match contact search: `form[data-orders-contact-search]` with a `kind` select (email|phone) and a
434
- * `value` input. The value travels only as a JSON POST body, never in a URL, and is never logged.
435
- */
436
- function mountContactSearch(root: HTMLElement, deps: OrderActionDeps): void {
437
- const form = root.querySelector<HTMLFormElement>("form[data-orders-contact-search]");
438
- const results = root.querySelector<HTMLElement>("[data-orders-contact-search-results]");
439
- if (!form || !results) return;
440
- const say = (lines: readonly string[]): void => {
441
- results.replaceChildren(...lines.map((line) => node("span", line)));
442
- results.hidden = false;
443
- };
444
- form.addEventListener("submit", (event) => {
445
- event.preventDefault();
446
- const kind = (form.elements.namedItem("kind") as HTMLSelectElement | null)?.value;
447
- const value = ((form.elements.namedItem("value") as HTMLInputElement | null)?.value ?? "").trim();
448
- if (!value || (kind !== "email" && kind !== "phone")) return say([SEARCH_MALFORMED]);
449
- if (!deps.api) return say([SEARCH_FAILED]);
450
- void (async () => {
451
- try {
452
- const response = await deps.fetch(`${deps.api}/orders/contact-search`, {
453
- method: "POST",
454
- credentials: "same-origin",
455
- cache: "no-store",
456
- headers: { "content-type": "application/json" },
457
- body: JSON.stringify({ [kind]: value }),
458
- });
459
- if (response.status === 400) return say([SEARCH_MALFORMED]);
460
- if (response.status === 403) return say([SEARCH_OWNER_ONLY]);
461
- if (response.status === 429) return say([CONTACT_QUOTA]);
462
- if (response.status === 503) return say([CONTACT_UNAVAILABLE]);
463
- const body = (await readJson(response)) as { orderIds?: unknown } | null;
464
- if (!response.ok || !body || !Array.isArray(body.orderIds)) return say([SEARCH_FAILED]);
465
- const ids = body.orderIds.filter((id): id is string => typeof id === "string");
466
- if (ids.length === 0) return say([SEARCH_NONE]);
467
- const list = node("ul", "", "orders-contact-search-list");
468
- for (const id of ids) list.append(node("li", id));
469
- results.replaceChildren(node("span", `${ids.length} matching order${ids.length === 1 ? "" : "s"}:`), list);
470
- results.hidden = false;
471
- } catch {
472
- say([SEARCH_FAILED]);
473
- }
474
- })();
475
- });
476
- }
477
-
478
- /**
479
- * Wire every `[data-orders-action]` button under `root`. The button carries its plan as
480
- * `data-orders-action-kind|target|message`; its note is the nearest `[data-orders-action-note]` in
481
- * the same record. Order-level buttons (`data-orders-resolve-hold`) act through the selected record's
482
- * `[data-orders-blocker-action]`.
483
- */
484
- export function mountOrderActions(root: HTMLElement, deps: OrderActionDeps): void {
485
- mountContactSearch(root, deps);
486
- const run = (button: HTMLElement, record: HTMLElement): void => {
487
- const kind = button.dataset.ordersActionKind as OrderActionKind | undefined;
488
- const target = button.dataset.ordersActionTarget ?? "";
489
- const message = button.dataset.ordersActionMessage ?? "";
490
- const orderId = record.dataset.ordersDetailRecord ?? "";
491
- const scope = button.closest<HTMLElement>("[data-orders-action-scope]");
492
- const note = scope
493
- ? scope.querySelector<HTMLElement>("[data-orders-action-note]")
494
- : record.querySelector<HTMLElement>("[data-orders-record-note]");
495
- if (kind === "reveal") {
496
- const section = record.querySelector<HTMLDetailsElement>(target);
497
- if (section) {
498
- section.open = true;
499
- section.scrollIntoView?.({ block: "nearest" });
500
- }
501
- show(note, [message]);
502
- } else if (kind === "tab") {
503
- show(note, [deps.navigate(target) ? message : `${message} The ${target} tab is not available to this account.`]);
504
- } else if (kind === "address") {
505
- void loadContact(orderId, record.querySelector<HTMLElement>(target) ?? note, deps);
506
- } else {
507
- show(note, [message || "Nothing can be done from here."]);
508
- }
509
- };
510
-
511
- // Contact details are not kept in the page once another order is selected.
512
- const detailRoot = root.querySelector<HTMLElement>("[data-orders-detail-root]");
513
- if (detailRoot && typeof MutationObserver !== "undefined") {
514
- new MutationObserver(() => {
515
- for (const record of detailRoot.querySelectorAll<HTMLElement>("[data-orders-detail-record]")) {
516
- if (record.dataset.ordersDetailRecord === detailRoot.dataset.adminSelectedId) continue;
517
- const panel = record.querySelector<HTMLElement>("[data-orders-address]");
518
- if (panel && !panel.hidden) {
519
- panel.replaceChildren();
520
- panel.hidden = true;
521
- }
522
- }
523
- }).observe(detailRoot, { attributes: true, attributeFilter: ["data-admin-selected-id"] });
524
- }
525
-
526
- root.addEventListener("click", (event) => {
527
- const origin = event.target instanceof Element ? event.target : null;
528
- const button = origin?.closest<HTMLElement>("[data-orders-action]");
529
- if (button && root.contains(button)) {
530
- const record = button.closest<HTMLElement>("[data-orders-detail-record]");
531
- if (record) run(button, record);
532
- return;
533
- }
534
- const orderLevel = origin?.closest<HTMLElement>("[data-orders-resolve-hold], [data-orders-next-step]");
535
- if (!orderLevel || !root.contains(orderLevel)) return;
536
- const selected = orderLevel.dataset.ordersNextStep ?? root.querySelector<HTMLElement>("[data-orders-detail-root]")?.dataset.adminSelectedId ?? "";
537
- const record = Array.from(root.querySelectorAll<HTMLElement>("[data-orders-detail-record]")).find(
538
- (item) => item.dataset.ordersDetailRecord === selected,
539
- );
540
- const action = record?.querySelector<HTMLElement>("[data-orders-blocker-action]");
541
- if (!record || !action) {
542
- show(root.querySelector<HTMLElement>("[data-orders-root-note]"), ["Select an order first."]);
543
- return;
544
- }
545
- record.hidden = false;
546
- record.scrollIntoView?.({ block: "nearest" });
547
- run(action, record);
548
- });
549
- }
550
-
551
- /** Switch the admin shell to a tab by id; false when the tab is not in this page. */
552
- export function navigateAdminTab(tab: string): boolean {
553
- if (!document.getElementById(tab)) return false;
554
- window.location.hash = `#${tab}`;
555
- return true;
556
- }