@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,172 +0,0 @@
1
- /**
2
- * Validate + sanitize merchant-submitted checkout styling into a safe, complete
3
- * `CheckoutStyle` before it is published to the versioned spine (the save path).
4
- *
5
- * The submitted body is a partial (`DeepPartial<CheckoutStyle>`): a merchant may
6
- * set one field without restating the rest, so this merges any valid override
7
- * over `DEFAULT_CHECKOUT_STYLE` (reusing `mergeCheckoutStyle`) and returns a
8
- * complete descriptor. It is the WRITE-side guard; the GateReport
9
- * still does the deeper compliance/contrast/perf pass on promote.
10
- *
11
- * Two hard constraints enforced here:
12
- * - **ASCII-safe.** Hosted checkout cache pass is not Unicode-safe — a non-ASCII
13
- * byte in a value rendered into the pushed CSS can blank the checkout.
14
- * Every provided string leaf must be printable ASCII.
15
- * - **CSS-token hygiene.** These values are interpolated into generated CSS,
16
- * so we reject the characters that could break out of a declaration
17
- * (`;` `{` `}` `<` `>` and newlines). Defense-in-depth, not the full gate.
18
- *
19
- * Pure + dependency-free (no I/O, no Astro): unit-testable in isolation and safe
20
- * to reuse from the gate or the CSS renderer if promoted to
21
- * public-runtime later.
22
- */
23
- import {
24
- DEFAULT_CHECKOUT_STYLE,
25
- mergeCheckoutStyle,
26
- type CheckoutStyle,
27
- type CheckoutStyleColors,
28
- } from "@tot/public-runtime";
29
-
30
- export type CheckoutStyleInputResult =
31
- | { ok: true; style: CheckoutStyle }
32
- | { ok: false; errors: string[] };
33
-
34
- /** Per-field length ceilings — generous enough for real stacks, tight enough to
35
- * bound what gets pushed to checkout. */
36
- const MAX = {
37
- color: 64,
38
- fontFamily: 200,
39
- length: 16,
40
- logoUrl: 500,
41
- } as const;
42
-
43
- const COLOR_KEYS: (keyof CheckoutStyleColors)[] = [
44
- "background",
45
- "surface",
46
- "primary",
47
- "primaryContrast",
48
- "accent",
49
- "text",
50
- ];
51
-
52
- /** Printable ASCII only (0x20–0x7E). Rejects control chars, newlines, and any
53
- * non-ASCII (the hosted-checkout Unicode hazard). */
54
- function isPrintableAscii(value: string): boolean {
55
- return /^[\x20-\x7E]*$/.test(value);
56
- }
57
-
58
- /** CSS-value hygiene: no declaration/selector-breaking characters. */
59
- function hasUnsafeCssChars(value: string): boolean {
60
- return /[;{}<>]/.test(value);
61
- }
62
-
63
- /**
64
- * Validate one string leaf: must be a string, printable ASCII, within `max`, free
65
- * of CSS-breaking characters, and (unless `allowEmpty`) non-empty after trim.
66
- * Returns the trimmed value or pushes a labeled error.
67
- */
68
- function takeString(
69
- raw: unknown,
70
- label: string,
71
- max: number,
72
- errors: string[],
73
- allowEmpty = false,
74
- ): string | undefined {
75
- if (raw === undefined) return undefined;
76
- if (typeof raw !== "string") {
77
- errors.push(`${label} must be a string`);
78
- return undefined;
79
- }
80
- const value = raw.trim();
81
- if (!value) {
82
- if (allowEmpty) return "";
83
- errors.push(`${label} must not be empty`);
84
- return undefined;
85
- }
86
- if (value.length > max) {
87
- errors.push(`${label} must be at most ${max} characters`);
88
- return undefined;
89
- }
90
- if (!isPrintableAscii(value)) {
91
- errors.push(`${label} must be printable ASCII (hosted checkout is not Unicode-safe)`);
92
- return undefined;
93
- }
94
- if (hasUnsafeCssChars(value)) {
95
- errors.push(`${label} must not contain ; { } < or >`);
96
- return undefined;
97
- }
98
- return value;
99
- }
100
-
101
- function asObject(raw: unknown): Record<string, unknown> | null {
102
- return raw && typeof raw === "object" && !Array.isArray(raw)
103
- ? (raw as Record<string, unknown>)
104
- : null;
105
- }
106
-
107
- /**
108
- * Validate + sanitize an untrusted checkout-style body into a complete
109
- * `CheckoutStyle`. On any field error, returns every error (not just the first)
110
- * so the editor can surface them together. On success, the returned style is the
111
- * default with the validated overrides merged on top.
112
- */
113
- export function validateCheckoutStyleInput(raw: unknown): CheckoutStyleInputResult {
114
- const body = asObject(raw);
115
- if (!body) return { ok: false, errors: ["body must be a JSON object"] };
116
-
117
- const errors: string[] = [];
118
- const override: {
119
- colors?: Partial<CheckoutStyleColors>;
120
- typography?: { fontFamily?: string; baseSize?: string };
121
- button?: { radius?: string };
122
- logoUrl?: string;
123
- } = {};
124
-
125
- const colors = asObject(body.colors);
126
- if (body.colors !== undefined && !colors) {
127
- errors.push("colors must be an object");
128
- } else if (colors) {
129
- const out: Partial<CheckoutStyleColors> = {};
130
- for (const key of COLOR_KEYS) {
131
- const v = takeString(colors[key], `colors.${key}`, MAX.color, errors);
132
- if (v !== undefined) out[key] = v;
133
- }
134
- if (Object.keys(out).length > 0) override.colors = out;
135
- }
136
-
137
- const typography = asObject(body.typography);
138
- if (body.typography !== undefined && !typography) {
139
- errors.push("typography must be an object");
140
- } else if (typography) {
141
- const out: { fontFamily?: string; baseSize?: string } = {};
142
- const fontFamily = takeString(typography.fontFamily, "typography.fontFamily", MAX.fontFamily, errors);
143
- if (fontFamily !== undefined) out.fontFamily = fontFamily;
144
- const baseSize = takeString(typography.baseSize, "typography.baseSize", MAX.length, errors);
145
- if (baseSize !== undefined) out.baseSize = baseSize;
146
- if (Object.keys(out).length > 0) override.typography = out;
147
- }
148
-
149
- const button = asObject(body.button);
150
- if (body.button !== undefined && !button) {
151
- errors.push("button must be an object");
152
- } else if (button) {
153
- const radius = takeString(button.radius, "button.radius", MAX.length, errors);
154
- if (radius !== undefined) override.button = { radius };
155
- }
156
-
157
- // logoUrl: optional. An empty string clears it (falls back to default = none);
158
- // a set value must be an absolute https URL within the length cap.
159
- if (body.logoUrl !== undefined) {
160
- const logo = takeString(body.logoUrl, "logoUrl", MAX.logoUrl, errors, true);
161
- if (logo) {
162
- if (!/^https:\/\/\S+$/.test(logo)) {
163
- errors.push("logoUrl must be an absolute https URL");
164
- } else {
165
- override.logoUrl = logo;
166
- }
167
- }
168
- }
169
-
170
- if (errors.length > 0) return { ok: false, errors };
171
- return { ok: true, style: mergeCheckoutStyle(DEFAULT_CHECKOUT_STYLE, override) };
172
- }
@@ -1,65 +0,0 @@
1
- /**
2
- * Decide which tenant a checkout-style save may write to — staff cross-tenant
3
- * save.
4
- *
5
- * The base save gate (`resolveOwnerSession`) resolves the operator's OWN tenant
6
- * (the routed appDomain). But a ToT-staff operator can
7
- * "operate as" another tenant via the admin picker (`?asTenant=`), and their
8
- * save must land on THAT tenant's artifact — provided they're actually
9
- * authorized for it. This resolver makes that decision, and it deliberately
10
- * reuses `resolveAdminTenantMode` — the SAME staff-membership/admission gate the
11
- * admin shell renders the picker envelope from — so there is ONE authorization
12
- * model, not a parallel one.
13
- *
14
- * Deny-by-default: a requested target that differs from the owner is honored only
15
- * when `resolveAdminTenantMode` authorizes it (staff + a real membership or a live
16
- * staff selection for that exact tenant). The merchant / own-tenant path is
17
- * unchanged: no target (or a target equal to the owner) writes to the owner, with
18
- * no session read required.
19
- *
20
- * Pure (no I/O, no Astro) — the caller supplies the already-read viewer session —
21
- * so it is unit-testable in isolation.
22
- */
23
- import { resolveAdminTenantMode } from "@/lib/access/shared/adminTenantEnvelope";
24
- import type { SessionRecord } from "@/lib/access/auth/session";
25
-
26
- export type WriteTargetResult =
27
- | { ok: true; targetTenant: string }
28
- | { ok: false; status: number; message: string };
29
-
30
- export function resolveCheckoutStyleWriteTarget(input: {
31
- /** The operator's own tenant appDomain (from resolveOwnerSession = routed tenant). */
32
- owner: string;
33
- /** The tenant the caller asked to write, from the request body (the picker target). */
34
- requestedTarget: string | null | undefined;
35
- /** The signed-in viewer session — only needed (and only read) for a cross-tenant write. */
36
- session: SessionRecord | null | undefined;
37
- /** Current time (epoch seconds), for the staff-selection expiry check. */
38
- nowSeconds: number;
39
- }): WriteTargetResult {
40
- const requested = (input.requestedTarget ?? "").trim();
41
-
42
- // Merchant / own-tenant path — unchanged. No requested target, or a target that
43
- // is just the operator's own tenant, writes to the owner.
44
- if (!requested || requested === input.owner) {
45
- return { ok: true, targetTenant: input.owner };
46
- }
47
-
48
- // Cross-tenant: authorize EXACTLY as the admin shell does. adminAppTenant is the
49
- // routed tenant (the owner); a staff session with a real membership or a live
50
- // staff selection for `requested` yields envelope.targetTenant === requested.
51
- const mode = resolveAdminTenantMode({
52
- session: input.session,
53
- adminAppTenant: input.owner,
54
- requestedTarget: requested,
55
- nowSeconds: input.nowSeconds,
56
- });
57
- if (mode.deniedTarget || mode.envelope.targetTenant !== requested) {
58
- return {
59
- ok: false,
60
- status: 403,
61
- message: `not authorized to write checkout styling for tenant: ${requested}`,
62
- };
63
- }
64
- return { ok: true, targetTenant: requested };
65
- }
@@ -1,152 +0,0 @@
1
- /** Browser wiring for the /admin "Excise tax" form: collect the switch, POST, report. */
2
-
3
- import { saveResultStatus } from "./checkoutRequirementsForm";
4
- import { announceSettingChanged } from "./settingDraftActions";
5
-
6
- export function mountCheckoutExciseForm(form: HTMLElement): void {
7
- const endpoint = form.dataset.endpoint || "/api/preview/checkout-excise";
8
- const targetTenant = form.dataset.targetTenant || "";
9
- const field = form.querySelector<HTMLInputElement>("[data-excise-field]");
10
- const status = form.querySelector<HTMLElement>("[data-excise-status]");
11
- const saveBtn = form.querySelector<HTMLButtonElement>("[data-excise-save]");
12
- const setStatus = (message: string, state?: "ok" | "err") => {
13
- if (!status) return;
14
- status.textContent = message;
15
- if (state) status.dataset.state = state;
16
- else delete status.dataset.state;
17
- };
18
- saveBtn?.addEventListener("click", async () => {
19
- const body: Record<string, unknown> = { excise: field?.checked ?? false, ...(targetTenant ? { targetTenant } : {}) };
20
- setStatus("Saving…");
21
- saveBtn.disabled = true;
22
- try {
23
- const res = await fetch(endpoint, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
24
- let data: Parameters<typeof saveResultStatus>[2] = {};
25
- try {
26
- data = await res.json();
27
- } catch {
28
- // non-JSON error body
29
- }
30
- const result = saveResultStatus(res.ok, res.status, data);
31
- setStatus(result.message, result.state);
32
- if (res.ok) announceSettingChanged("checkout-excise");
33
- } catch {
34
- setStatus("Save failed — network error", "err");
35
- } finally {
36
- saveBtn.disabled = false;
37
- }
38
- });
39
- }
40
-
41
- const SKU_CHIP_CLASSES: Record<"registered" | "missing" | "refused" | "unavailable", string> = {
42
- registered: "green",
43
- missing: "amber",
44
- refused: "red",
45
- unavailable: "amber",
46
- };
47
-
48
- const SKU_CHIP_LABELS: Record<"registered" | "missing" | "refused" | "unavailable", string> = {
49
- registered: "Registered",
50
- missing: "Missing",
51
- refused: "Refused",
52
- unavailable: "Unavailable",
53
- };
54
-
55
- function readRowProduct(row: Element, sku: string, action: string): Record<string, unknown> {
56
- if (action !== "add") return { sku };
57
- const getVal = (name: string): string | boolean | undefined => {
58
- const el = row.querySelector<HTMLInputElement | HTMLSelectElement>(`[data-excise-attr="${name}"]`);
59
- if (!el) return undefined;
60
- if (el instanceof HTMLInputElement && el.type === "checkbox") return el.checked;
61
- return el.value;
62
- };
63
- return {
64
- sku,
65
- type: getVal("type"),
66
- vapeSystemType: getVal("vapeSystemType"),
67
- volumeInMl: getVal("volumeInMl"),
68
- wholesaleCost: getVal("wholesaleCost"),
69
- wholesalePrice: getVal("wholesalePrice"),
70
- msrp: getVal("msrp"),
71
- retailPrice: getVal("retailPrice"),
72
- packQuantity: getVal("packQuantity"),
73
- hasNicotine: Boolean(getVal("hasNicotine")),
74
- };
75
- }
76
-
77
- function applyRowResult(
78
- row: Element,
79
- item: { state?: string; message?: string } | null | undefined,
80
- ): void {
81
- const badge = row.querySelector<HTMLElement>("[data-excise-sku-state]");
82
- const msg = row.querySelector<HTMLElement>("[data-excise-sku-message]");
83
- const state: "registered" | "missing" | "refused" | "unavailable" =
84
- item &&
85
- (item.state === "registered" ||
86
- item.state === "missing" ||
87
- item.state === "refused" ||
88
- item.state === "unavailable")
89
- ? item.state
90
- : "refused";
91
- if (badge) {
92
- badge.setAttribute("data-excise-sku-state", state);
93
- badge.className = `chip ${SKU_CHIP_CLASSES[state]}`;
94
- badge.textContent = SKU_CHIP_LABELS[state];
95
- }
96
- if (msg && item && typeof item.message === "string") {
97
- msg.textContent = item.message;
98
- }
99
- }
100
-
101
- export function mountExciseProductsPanel(panel: HTMLElement): void {
102
- const endpoint = panel.getAttribute("data-endpoint") || "/api/admin/excise-products";
103
- const statusEl = panel.querySelector<HTMLElement>("[data-excise-products-status]");
104
-
105
- panel.addEventListener("click", async (event) => {
106
- const target = event.target instanceof Element ? event.target.closest("[data-excise-sku-action]") : null;
107
- if (!target) return;
108
- const action = target.getAttribute("data-excise-sku-action");
109
- const sku = target.getAttribute("data-excise-sku");
110
- const row = target.closest("[data-excise-sku-row]");
111
- if (!action || !sku || !row) return;
112
-
113
- const buttons = row.querySelectorAll<HTMLButtonElement>("button[data-excise-sku-action]");
114
- buttons.forEach((b) => {
115
- b.disabled = true;
116
- });
117
- if (statusEl) {
118
- statusEl.textContent = action === "add" ? `Registering ${sku}...` : `Deactivating ${sku}...`;
119
- }
120
-
121
- try {
122
- const product = readRowProduct(row, sku, action);
123
- const res = await fetch(endpoint, {
124
- method: "POST",
125
- headers: { "content-type": "application/json" },
126
- body: JSON.stringify({ action, products: [product] }),
127
- });
128
- const data = (await res.json()) as {
129
- message?: string;
130
- results?: Array<{ sku?: string; state?: string; message?: string }>;
131
- };
132
- const entry = Array.isArray(data?.results)
133
- ? data.results.find((r) => r && r.sku === sku)
134
- : null;
135
- if (entry) {
136
- applyRowResult(row, entry);
137
- }
138
- if (statusEl) {
139
- statusEl.textContent =
140
- entry?.message || data?.message || (res.ok ? "Updated." : "Request refused.");
141
- }
142
- } catch {
143
- if (statusEl) {
144
- statusEl.textContent = "Could not reach the excise registration service.";
145
- }
146
- } finally {
147
- buttons.forEach((b) => {
148
- b.disabled = false;
149
- });
150
- }
151
- });
152
- }
@@ -1,72 +0,0 @@
1
- /** Browser wiring for the /admin "Checkout requirements" form: collect the switches, POST, report. */
2
-
3
- import { SETTING_SAVED_EVENT, savedMessage } from "./settingDraftActions";
4
-
5
- type StatusState = "ok" | "err";
6
-
7
- interface SaveResponse {
8
- readBack?: string;
9
- inEffect?: string[];
10
- notice?: string;
11
- error?: string;
12
- errors?: unknown;
13
- }
14
-
15
- export function saveFailureMessage(status: number, data: SaveResponse): string {
16
- if (Array.isArray(data.errors) && data.errors.length) return data.errors.join(" ");
17
- return data.error || `Save failed (${status})`;
18
- }
19
-
20
- /**
21
- * What the form reports for a save response. "Saved" only when the server read the save back
22
- * through the readers' own resolver (`readBack: "in-effect"`), naming where it is in effect: the
23
- * draft the preview reads, or also live on a store with no live site. An accepted save the edge has
24
- * not picked up yet reports its notice without the ok state.
25
- */
26
- export function saveResultStatus(httpOk: boolean, status: number, data: SaveResponse): { message: string; state?: StatusState } {
27
- if (!httpOk) return { message: saveFailureMessage(status, data), state: "err" };
28
- if (data.readBack === "in-effect") return { message: savedMessage(data.inEffect), state: "ok" };
29
- if (data.readBack === "pending") return { message: data.notice || "Accepted. Reload to confirm it is in effect." };
30
- return { message: "The save could not be confirmed in effect. Reload to check.", state: "err" };
31
- }
32
-
33
- export function mountCheckoutRequirementsForm(form: HTMLElement): void {
34
- const endpoint = form.dataset.endpoint || "/api/preview/checkout-requirements";
35
- const targetTenant = form.dataset.targetTenant || "";
36
- const status = form.querySelector<HTMLElement>("[data-checkout-requirements-status]");
37
- const saveBtn = form.querySelector<HTMLButtonElement>("[data-checkout-requirements-save]");
38
- const setStatus = (message: string, state?: StatusState) => {
39
- if (!status) return;
40
- status.textContent = message;
41
- if (state) status.dataset.state = state;
42
- else delete status.dataset.state;
43
- };
44
- saveBtn?.addEventListener("click", async () => {
45
- const body: Record<string, unknown> = targetTenant ? { targetTenant } : {};
46
- for (const input of form.querySelectorAll<HTMLInputElement>("[data-cr-field]")) {
47
- body[input.dataset.crField ?? ""] = input.checked;
48
- }
49
- setStatus("Saving…");
50
- saveBtn.disabled = true;
51
- try {
52
- const res = await fetch(endpoint, {
53
- method: "POST",
54
- headers: { "content-type": "application/json" },
55
- body: JSON.stringify(body),
56
- });
57
- let data: SaveResponse = {};
58
- try {
59
- data = (await res.json()) as SaveResponse;
60
- } catch {
61
- // non-JSON error body
62
- }
63
- const result = saveResultStatus(res.ok, res.status, data);
64
- setStatus(result.message, result.state);
65
- if (res.ok) document.dispatchEvent(new CustomEvent(SETTING_SAVED_EVENT, { detail: { kind: "checkout-requirements" } }));
66
- } catch {
67
- setStatus("Save failed — network error", "err");
68
- } finally {
69
- saveBtn.disabled = false;
70
- }
71
- });
72
- }
@@ -1,110 +0,0 @@
1
- /** Browser wiring for the /admin "Checkout styling" editor: live preview, collect the fields, POST, report. */
2
-
3
- import { saveResultStatus } from "./checkoutRequirementsForm";
4
- import { SETTING_SAVED_EVENT } from "./settingDraftActions";
5
-
6
- type StatusState = "ok" | "err";
7
-
8
- /** data-cs-field → the preview CSS custom property it drives. */
9
- const CSS_VAR: Readonly<Record<string, string>> = {
10
- "colors.background": "--cs-bg",
11
- "colors.surface": "--cs-surface",
12
- "colors.primary": "--cs-primary",
13
- "colors.primaryContrast": "--cs-primary-contrast",
14
- "colors.accent": "--cs-accent",
15
- "colors.text": "--cs-text",
16
- "typography.fontFamily": "--cs-font",
17
- "typography.baseSize": "--cs-size",
18
- "button.radius": "--cs-radius",
19
- };
20
-
21
- export interface CheckoutStyleFields {
22
- colors: Record<string, string>;
23
- typography: Record<string, string>;
24
- button: Record<string, string>;
25
- logoUrl?: string;
26
- }
27
-
28
- /** The CheckoutStyle partial the save endpoint validates, from `[field path, value]` pairs. */
29
- export function collectCheckoutStyle(entries: Iterable<readonly [string, string]>): CheckoutStyleFields {
30
- const style: CheckoutStyleFields = { colors: {}, typography: {}, button: {} };
31
- for (const [path, raw] of entries) {
32
- const value = raw.trim();
33
- if (path === "logoUrl") {
34
- if (value) style.logoUrl = value;
35
- continue;
36
- }
37
- const dot = path.indexOf(".");
38
- const group = path.slice(0, dot);
39
- if (group === "colors" || group === "typography" || group === "button") style[group][path.slice(dot + 1)] = value;
40
- }
41
- return style;
42
- }
43
-
44
- export function mountCheckoutStyleForm(form: HTMLElement): void {
45
- const endpoint = form.dataset.endpoint || "/api/preview/checkout-style";
46
- // The tenant this save targets: the routed tenant for a merchant, or the staff picker's
47
- // "operating as" tenant. The endpoint re-authorizes it.
48
- const targetTenant = form.dataset.targetTenant || "";
49
- const preview = form.querySelector<HTMLElement>("[data-cs-preview]");
50
- const logoImg = form.querySelector<HTMLImageElement>("[data-cs-logo]");
51
- const status = form.querySelector<HTMLElement>("[data-checkout-style-status]");
52
- const saveBtn = form.querySelector<HTMLButtonElement>("[data-checkout-style-save]");
53
- const fields = Array.from(form.querySelectorAll<HTMLInputElement | HTMLSelectElement>("[data-cs-field]"));
54
-
55
- const setStatus = (message: string, state?: StatusState) => {
56
- if (!status) return;
57
- status.textContent = message;
58
- if (state) status.dataset.state = state;
59
- else delete status.dataset.state;
60
- };
61
-
62
- // Reflect edits into the preview live. Inline style ATTRIBUTES are the one CSP-tolerated
63
- // relaxation (style-src-attr 'unsafe-inline'); no <style> tag is injected.
64
- const applyPreview = () => {
65
- for (const el of fields) {
66
- const path = el.dataset.csField ?? "";
67
- const value = el.value.trim();
68
- const cssVar = CSS_VAR[path];
69
- if (cssVar && preview) preview.style.setProperty(cssVar, value);
70
- const swatch = form.querySelector<HTMLElement>(`[data-cs-swatch="${path}"]`);
71
- if (swatch) swatch.style.background = value;
72
- if (path === "logoUrl" && logoImg) {
73
- if (value) logoImg.src = value;
74
- else logoImg.removeAttribute("src");
75
- logoImg.hidden = !value;
76
- }
77
- }
78
- };
79
- for (const el of fields) el.addEventListener("input", applyPreview);
80
-
81
- saveBtn?.addEventListener("click", async () => {
82
- setStatus("Saving…");
83
- saveBtn.disabled = true;
84
- try {
85
- const style = collectCheckoutStyle(fields.map((el) => [el.dataset.csField ?? "", el.value] as const));
86
- const res = await fetch(endpoint, {
87
- method: "POST",
88
- headers: { "content-type": "application/json" },
89
- body: JSON.stringify(targetTenant ? { ...style, targetTenant } : style),
90
- });
91
- let data: Parameters<typeof saveResultStatus>[2] & { versionId?: unknown } = {};
92
- try {
93
- data = (await res.json()) as typeof data;
94
- } catch {
95
- // non-JSON error body
96
- }
97
- const result = saveResultStatus(res.ok, res.status, data);
98
- const version = result.state === "ok" && typeof data.versionId === "string" ? ` (version ${data.versionId.slice(0, 8)})` : "";
99
- setStatus(result.message + version, result.state);
100
- if (res.ok) document.dispatchEvent(new CustomEvent(SETTING_SAVED_EVENT, { detail: { kind: "checkout-style" } }));
101
- } catch {
102
- setStatus("Save failed — network error", "err");
103
- } finally {
104
- saveBtn.disabled = false;
105
- }
106
- });
107
-
108
- // The preview coupon link is illustrative only; don't navigate.
109
- form.querySelector("[data-checkout-styling-noop]")?.addEventListener("click", (e) => e.preventDefault());
110
- }