@tokenoftrust/storefront-runner 7.3.2 → 7.5.1

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 (420) 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/agent/checkoutProtocol.ts +196 -0
  25. package/apps/storefront/src/lib/checkout/agent/checkoutSession.ts +296 -0
  26. package/apps/storefront/src/lib/checkout/agent/webBotAuth.ts +347 -0
  27. package/apps/storefront/src/lib/checkout/commerce/cardCartForm.ts +2 -0
  28. package/apps/storefront/src/lib/checkout/commerce/cartSession.ts +109 -12
  29. package/apps/storefront/src/lib/checkout/commerce/checkoutHandoffRoute.ts +53 -25
  30. package/apps/storefront/src/lib/checkout/commerce/finalCartAuthorization.ts +48 -6
  31. package/apps/storefront/src/lib/checkout/proposal/cartProposal.ts +388 -0
  32. package/apps/storefront/src/lib/checkout/proposal/listMatcher.ts +149 -0
  33. package/apps/storefront/src/lib/checkout/proposal/proposalRoutes.ts +522 -0
  34. package/apps/storefront/src/lib/checkout/proposal/reviewHtml.ts +100 -0
  35. package/apps/storefront/src/lib/compliance/browser/checkoutVerificationFlow.ts +26 -2
  36. package/apps/storefront/src/lib/content/shared/redirects.ts +21 -4
  37. package/apps/storefront/src/lib/publication/shared/edgeCache.ts +5 -2
  38. package/apps/storefront/src/lib/publication/shared/previewAnnotations/renderDecorator.ts +15 -8
  39. package/apps/storefront/src/lib/publication/shared/runtimeEnv.ts +1 -1
  40. package/apps/storefront/src/middleware/controlPlane.ts +15 -1
  41. package/apps/storefront/src/middleware/index.ts +7 -3
  42. package/apps/storefront/src/middleware/renderChain.ts +46 -33
  43. package/apps/storefront/src/pages/api/cart-proposal/confirm.ts +12 -0
  44. package/apps/storefront/src/pages/api/cart-proposal/review.ts +26 -0
  45. package/apps/storefront/src/pages/api/commerce/checkout-sessions/[id].ts +9 -0
  46. package/apps/storefront/src/pages/api/commerce/checkout-sessions.ts +8 -0
  47. package/apps/storefront/src/pages/api/commerce/final-cart-authorization.ts +29 -6
  48. package/apps/storefront/src/pages/api/compliance/preflight.ts +25 -1
  49. package/apps/storefront/src/pages/products/[handle].astro +2 -15
  50. package/apps/storefront/tsconfig.astro.json +11 -0
  51. package/package.json +1 -1
  52. package/packages/public-runtime/src/activity/README.md +12 -0
  53. package/packages/public-runtime/src/activity/catalog.ts +7 -0
  54. package/packages/public-runtime/src/activity/event.ts +19 -0
  55. package/packages/public-runtime/src/activity/redaction.ts +31 -2
  56. package/packages/public-runtime/src/catalog-files.ts +3 -2
  57. package/packages/public-runtime/src/checkout-orders.ts +18 -19
  58. package/packages/public-runtime/src/checkout.ts +70 -0
  59. package/packages/public-runtime/src/compliance/evaluate.ts +60 -1
  60. package/packages/public-runtime/src/compliance/index.ts +1 -1
  61. package/packages/public-runtime/src/compliance/pact-report.ts +184 -3
  62. package/packages/public-runtime/src/compliance/profile.ts +268 -20
  63. package/packages/public-runtime/src/compliance/ruleset.ts +42 -0
  64. package/packages/public-runtime/src/customization-runtime.ts +1 -1
  65. package/packages/public-runtime/src/product.ts +9 -1
  66. package/packages/public-runtime/src/publication-content-redirects.ts +16 -3
  67. package/packages/public-runtime/tests/fixtures/compliance-decisions.golden.json +252 -52
  68. package/pnpm-lock.runner.yaml +0 -15
  69. package/scripts/tenant/materialize-tenant-content.mjs +3 -0
  70. package/scripts/tenant/validate.mjs +128 -0
  71. package/apps/storefront/dev-plugins/dev-publish.mjs +0 -55
  72. package/apps/storefront/drizzle.config.apps.ts +0 -13
  73. package/apps/storefront/integrations/preview-annotations-client-bundle.mjs +0 -80
  74. package/apps/storefront/migrations-apps/0000_fast_millenium_guard.sql +0 -129
  75. package/apps/storefront/migrations-apps/0001_woozy_lyja.sql +0 -22
  76. package/apps/storefront/migrations-apps/0002_good_switch.sql +0 -26
  77. package/apps/storefront/migrations-apps/0003_mute_marauders.sql +0 -12
  78. package/apps/storefront/migrations-apps/0004_deep_morph.sql +0 -36
  79. package/apps/storefront/migrations-apps/0005_common_mystique.sql +0 -23
  80. package/apps/storefront/migrations-apps/0006_broad_microchip.sql +0 -16
  81. package/apps/storefront/migrations-apps/0007_brave_outlaw_kid.sql +0 -15
  82. package/apps/storefront/migrations-apps/0008_blue_dazzler.sql +0 -11
  83. package/apps/storefront/migrations-apps/0009_bored_shinobi_shaw.sql +0 -15
  84. package/apps/storefront/migrations-apps/0010_ws4_verified_provider_measurement.sql +0 -35
  85. package/apps/storefront/migrations-apps/0011_dt_tracking_tenant_databases.sql +0 -23
  86. package/apps/storefront/migrations-apps/0012_test_destinations.sql +0 -29
  87. package/apps/storefront/migrations-apps/0013_publication_space_editorial.sql +0 -64
  88. package/apps/storefront/migrations-apps/0014_retire_candidate_ledger.sql +0 -12
  89. package/apps/storefront/migrations-apps/0015_merchant_calculation_settings.sql +0 -31
  90. package/apps/storefront/migrations-apps/0016_scrappy_commerce_contract.sql +0 -166
  91. package/apps/storefront/migrations-apps/0017_commerce_durable_projection.sql +0 -28
  92. package/apps/storefront/migrations-apps/0018_commerce_provider_cart_identity.sql +0 -13
  93. package/apps/storefront/migrations-apps/0019_commerce_source_authority.sql +0 -23
  94. package/apps/storefront/migrations-apps/0020_contact_messages.sql +0 -18
  95. package/apps/storefront/migrations-apps/0021_contact_vault.sql +0 -166
  96. package/apps/storefront/migrations-apps/0022_contact_vault_fields.sql +0 -342
  97. package/apps/storefront/migrations-apps/0023_principal_grant_contacts.sql +0 -15
  98. package/apps/storefront/migrations-apps/0024_order_contact_erasure_state.sql +0 -22
  99. package/apps/storefront/migrations-apps/0025_shipment_audit_order_lookup.sql +0 -2
  100. package/apps/storefront/migrations-apps/0026_fulfillment_assignment.sql +0 -44
  101. package/apps/storefront/migrations-apps/0027_app_contact_authority.sql +0 -70
  102. package/apps/storefront/migrations-apps/0028_app_jwk_and_candidates.sql +0 -133
  103. package/apps/storefront/migrations-apps/0029_inventory_locations_wms.sql +0 -38
  104. package/apps/storefront/migrations-apps/0030_assignment_split_shipments.sql +0 -149
  105. package/apps/storefront/migrations-apps/meta/0000_snapshot.json +0 -843
  106. package/apps/storefront/migrations-apps/meta/0001_snapshot.json +0 -990
  107. package/apps/storefront/migrations-apps/meta/0002_snapshot.json +0 -1160
  108. package/apps/storefront/migrations-apps/meta/0003_snapshot.json +0 -1235
  109. package/apps/storefront/migrations-apps/meta/0004_snapshot.json +0 -1474
  110. package/apps/storefront/migrations-apps/meta/0005_snapshot.json +0 -1617
  111. package/apps/storefront/migrations-apps/meta/0006_snapshot.json +0 -1716
  112. package/apps/storefront/migrations-apps/meta/0007_snapshot.json +0 -1812
  113. package/apps/storefront/migrations-apps/meta/0008_snapshot.json +0 -1881
  114. package/apps/storefront/migrations-apps/meta/0009_snapshot.json +0 -1979
  115. package/apps/storefront/migrations-apps/meta/_journal.json +0 -76
  116. package/apps/storefront/perf/README.md +0 -64
  117. package/apps/storefront/perf/assert-budgets.ts +0 -159
  118. package/apps/storefront/platform-reconcile-tenants.json +0 -3
  119. package/apps/storefront/playwright.config.ts +0 -23
  120. package/apps/storefront/public/js/dashboard-access-banner.js +0 -53
  121. package/apps/storefront/public/js/dashboard-apps.js +0 -183
  122. package/apps/storefront/public/js/dashboard-contact-capture.js +0 -52
  123. package/apps/storefront/public/js/dashboard-delegate.js +0 -167
  124. package/apps/storefront/public/js/dashboard-team.js +0 -356
  125. package/apps/storefront/public/js/dashboard-vendor-search.js +0 -115
  126. package/apps/storefront/src/components/content/storefront/AsyncStylesheet.astro +0 -26
  127. package/apps/storefront/src/components/integrations/storefront/WidgetFrame.astro +0 -34
  128. package/apps/storefront/src/config/adminTenantLookup.ts +0 -35
  129. package/apps/storefront/src/config/evidenceTenantRoster.ts +0 -25
  130. package/apps/storefront/src/config/staffProvisionProjection.ts +0 -24
  131. package/apps/storefront/src/config/storeName.ts +0 -34
  132. package/apps/storefront/src/lib/access/admin/README.md +0 -122
  133. package/apps/storefront/src/lib/access/admin/adminShell.ts +0 -281
  134. package/apps/storefront/src/lib/access/admin/envelope.ts +0 -9
  135. package/apps/storefront/src/lib/access/admin/viewmodels/settings.ts +0 -64
  136. package/apps/storefront/src/lib/access/auth/adminApiGuard.ts +0 -66
  137. package/apps/storefront/src/lib/access/auth/adminEntry.ts +0 -126
  138. package/apps/storefront/src/lib/access/auth/mcpClientAssertion.ts +0 -217
  139. package/apps/storefront/src/lib/access/auth/operatorSession.ts +0 -120
  140. package/apps/storefront/src/lib/access/dashboard/agentStoreEntry.ts +0 -253
  141. package/apps/storefront/src/lib/access/dashboard/delegateGate.ts +0 -130
  142. package/apps/storefront/src/lib/access/dashboard/staffStoreEntry.ts +0 -153
  143. package/apps/storefront/src/lib/access/dashboard/staffVendorAccess.ts +0 -474
  144. package/apps/storefront/src/lib/access/dashboard/vendorQuery.ts +0 -61
  145. package/apps/storefront/src/lib/access/fixtures/settings.ts +0 -67
  146. package/apps/storefront/src/lib/access/fixtures/tenants.ts +0 -29
  147. package/apps/storefront/src/lib/access/notifications/magicLinkInviteEmail.ts +0 -62
  148. package/apps/storefront/src/lib/access/shared/grantContactLookup.ts +0 -97
  149. package/apps/storefront/src/lib/access/shared/principalGrants.ts +0 -775
  150. package/apps/storefront/src/lib/activity/alerts.ts +0 -426
  151. package/apps/storefront/src/lib/activity/candidateSubmitLease.ts +0 -87
  152. package/apps/storefront/src/lib/activity/changeActorAttribution.ts +0 -181
  153. package/apps/storefront/src/lib/activity/evidence/evidenceReference.ts +0 -32
  154. package/apps/storefront/src/lib/activity/fixtures/evidence.ts +0 -99
  155. package/apps/storefront/src/lib/activity/query.ts +0 -403
  156. package/apps/storefront/src/lib/activity/uiActor.ts +0 -152
  157. package/apps/storefront/src/lib/admin/services/mock/index.ts +0 -12
  158. package/apps/storefront/src/lib/assets/addons/catalog.ts +0 -60
  159. package/apps/storefront/src/lib/assets/addons/storeEntitlements.ts +0 -260
  160. package/apps/storefront/src/lib/assets/durableAssetsRoute.ts +0 -65
  161. package/apps/storefront/src/lib/assets/durableR2.ts +0 -473
  162. package/apps/storefront/src/lib/assets/durableR2Bindings.ts +0 -33
  163. package/apps/storefront/src/lib/automation/admin/viewmodels/aiWorkflows.ts +0 -65
  164. package/apps/storefront/src/lib/automation/ai/approvalMode.ts +0 -20
  165. package/apps/storefront/src/lib/automation/ai/askEnvelope.ts +0 -47
  166. package/apps/storefront/src/lib/automation/ai/audit.ts +0 -12
  167. package/apps/storefront/src/lib/automation/ai/operationalRuns.ts +0 -155
  168. package/apps/storefront/src/lib/automation/ai/recommendation.ts +0 -20
  169. package/apps/storefront/src/lib/automation/fixtures/aiWorkflows.ts +0 -59
  170. package/apps/storefront/src/lib/catalog/admin/catalogSettingsClient.ts +0 -250
  171. package/apps/storefront/src/lib/catalog/admin/catalogSettingsFields.ts +0 -134
  172. package/apps/storefront/src/lib/catalog/admin/catalogSettingsPreview.ts +0 -37
  173. package/apps/storefront/src/lib/catalog/admin/catalogSettingsPricingView.ts +0 -39
  174. package/apps/storefront/src/lib/catalog/admin/catalogSettingsRuleView.ts +0 -44
  175. package/apps/storefront/src/lib/catalog/admin/catalogSettingsSkuView.ts +0 -21
  176. package/apps/storefront/src/lib/catalog/admin/catalogSettingsState.ts +0 -132
  177. package/apps/storefront/src/lib/catalog/admin/productSetupPhoto.ts +0 -23
  178. package/apps/storefront/src/lib/catalog/admin/productsTabClient.ts +0 -193
  179. package/apps/storefront/src/lib/catalog/admin/services/catalogProducts.ts +0 -32
  180. package/apps/storefront/src/lib/catalog/admin/viewmodels/catalogProducts.ts +0 -164
  181. package/apps/storefront/src/lib/catalog/admin/viewmodels/products.ts +0 -267
  182. package/apps/storefront/src/lib/catalog/fixtures/products.ts +0 -105
  183. package/apps/storefront/src/lib/catalog/tot/syncState.ts +0 -111
  184. package/apps/storefront/src/lib/checkout/admin/checkoutStyleInput.ts +0 -172
  185. package/apps/storefront/src/lib/checkout/admin/checkoutStyleTarget.ts +0 -65
  186. package/apps/storefront/src/lib/checkout/browser/checkoutExciseForm.ts +0 -152
  187. package/apps/storefront/src/lib/checkout/browser/checkoutRequirementsForm.ts +0 -72
  188. package/apps/storefront/src/lib/checkout/browser/checkoutStyleForm.ts +0 -110
  189. package/apps/storefront/src/lib/checkout/browser/settingDraftActions.ts +0 -367
  190. package/apps/storefront/src/lib/checkout/commerce/checkoutSettings.ts +0 -246
  191. package/apps/storefront/src/lib/checkout/fixtures/checkoutSettings.ts +0 -77
  192. package/apps/storefront/src/lib/content/blog/markdown.ts +0 -174
  193. package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome-assignments.example.json +0 -6
  194. package/apps/storefront/src/lib/content/chrome/examples/tokenoftrust.chrome.example.json +0 -79
  195. package/apps/storefront/src/lib/content/index.ts +0 -27
  196. package/apps/storefront/src/lib/content/the-build/readingTime.ts +0 -35
  197. package/apps/storefront/src/lib/content/the-build/toc.ts +0 -95
  198. package/apps/storefront/src/lib/customers/admin/viewmodels/customers.ts +0 -56
  199. package/apps/storefront/src/lib/customers/contactVault/blindIndex.ts +0 -28
  200. package/apps/storefront/src/lib/customers/contactVault/contactAudit.ts +0 -149
  201. package/apps/storefront/src/lib/customers/contactVault/dataKeys.ts +0 -283
  202. package/apps/storefront/src/lib/customers/contactVault/fieldEnvelope.ts +0 -88
  203. package/apps/storefront/src/lib/customers/contactVault/isolateMetrics.ts +0 -37
  204. package/apps/storefront/src/lib/customers/contactVault/kms.ts +0 -292
  205. package/apps/storefront/src/lib/customers/contactVault/retention.ts +0 -302
  206. package/apps/storefront/src/lib/customers/contactVault/retentionPolicy.ts +0 -290
  207. package/apps/storefront/src/lib/customers/contactVault/zip3.ts +0 -24
  208. package/apps/storefront/src/lib/customers/fixtures/customers.ts +0 -86
  209. package/apps/storefront/src/lib/developer-experience/admin/memoizeByEnvelope.ts +0 -27
  210. package/apps/storefront/src/lib/developer-experience/admin/seed.ts +0 -54
  211. package/apps/storefront/src/lib/developer-experience/dev/activityIngestToken.ts +0 -85
  212. package/apps/storefront/src/lib/developer-experience/dev/activityStore.ts +0 -82
  213. package/apps/storefront/src/lib/developer-experience/dev/agentGrantAttestation.ts +0 -74
  214. package/apps/storefront/src/lib/developer-experience/dev/ai-widget-client.js +0 -308
  215. package/apps/storefront/src/lib/developer-experience/dev/apiBase.ts +0 -17
  216. package/apps/storefront/src/lib/developer-experience/dev/cliSignInCode.ts +0 -124
  217. package/apps/storefront/src/lib/developer-experience/dev/cockpit/ask.ts +0 -49
  218. package/apps/storefront/src/lib/developer-experience/dev/cockpit/clickToSource.ts +0 -71
  219. package/apps/storefront/src/lib/developer-experience/dev/cockpit/copyCommand.ts +0 -227
  220. package/apps/storefront/src/lib/developer-experience/dev/cockpit/files.ts +0 -249
  221. package/apps/storefront/src/lib/developer-experience/dev/cockpit/hostedActivity.ts +0 -500
  222. package/apps/storefront/src/lib/developer-experience/dev/cockpit/infoPopover.ts +0 -12
  223. package/apps/storefront/src/lib/developer-experience/dev/cockpit/mcpCopy.ts +0 -34
  224. package/apps/storefront/src/lib/developer-experience/dev/cockpit/monitor.ts +0 -107
  225. package/apps/storefront/src/lib/developer-experience/dev/cockpit/stepper.ts +0 -116
  226. package/apps/storefront/src/lib/developer-experience/dev/cockpit/themeToggle.ts +0 -23
  227. package/apps/storefront/src/lib/developer-experience/dev/livePreview.ts +0 -77
  228. package/apps/storefront/src/lib/developer-experience/dev/obstacleStore.ts +0 -214
  229. package/apps/storefront/src/lib/developer-experience/dev/previewStatus.ts +0 -87
  230. package/apps/storefront/src/lib/developer-experience/dev/rendezvousBroker.ts +0 -226
  231. package/apps/storefront/src/lib/developer-experience/dev/runtimeStore.ts +0 -291
  232. package/apps/storefront/src/lib/developer-experience/dev/storeStatus.ts +0 -142
  233. package/apps/storefront/src/lib/developer-experience/dev/subjectReissue.ts +0 -67
  234. package/apps/storefront/src/lib/developer-experience/fixtures/regulated-commerce-truth/index.ts +0 -540
  235. package/apps/storefront/src/lib/developer-experience/fixtures/ws3-readonly-clone-preflight/index.ts +0 -495
  236. package/apps/storefront/src/lib/engagement/contact/contactMessages.ts +0 -671
  237. package/apps/storefront/src/lib/engagement/contact/messagesTabClient.ts +0 -175
  238. package/apps/storefront/src/lib/engagement/contact/submission.ts +0 -112
  239. package/apps/storefront/src/lib/engagement/messaging/messagesClient.ts +0 -149
  240. package/apps/storefront/src/lib/engagement/newsletter/digest.ts +0 -117
  241. package/apps/storefront/src/lib/engagement/newsletter/resendClient.ts +0 -79
  242. package/apps/storefront/src/lib/engagement/newsletter/send.ts +0 -265
  243. package/apps/storefront/src/lib/engagement/social/golive.ts +0 -212
  244. package/apps/storefront/src/lib/engagement/social/notify.ts +0 -32
  245. package/apps/storefront/src/lib/engagement/social/tokenStore.ts +0 -171
  246. package/apps/storefront/src/lib/fulfillment/admin/commerceDesk.ts +0 -180
  247. package/apps/storefront/src/lib/fulfillment/admin/commerceDeskRouting.ts +0 -45
  248. package/apps/storefront/src/lib/fulfillment/admin/viewmodels/fulfillment.ts +0 -1071
  249. package/apps/storefront/src/lib/fulfillment/appShipmentEvidence.ts +0 -271
  250. package/apps/storefront/src/lib/fulfillment/carrierEvidence.ts +0 -105
  251. package/apps/storefront/src/lib/fulfillment/commerceProjection.ts +0 -157
  252. package/apps/storefront/src/lib/fulfillment/commerceReadback.ts +0 -60
  253. package/apps/storefront/src/lib/fulfillment/commerceRecovery.ts +0 -84
  254. package/apps/storefront/src/lib/fulfillment/commerceRuntime.ts +0 -41
  255. package/apps/storefront/src/lib/fulfillment/fulfillmentService.ts +0 -2842
  256. package/apps/storefront/src/lib/fulfillment/readiness.ts +0 -217
  257. package/apps/storefront/src/lib/fulfillment/splitShipments.ts +0 -388
  258. package/apps/storefront/src/lib/fulfillment/syntheticPreviewOrders.ts +0 -292
  259. package/apps/storefront/src/lib/integrations/apps/appContactAuthority.ts +0 -27
  260. package/apps/storefront/src/lib/integrations/apps/appContactConsents.ts +0 -118
  261. package/apps/storefront/src/lib/integrations/apps/appInstallEnv.ts +0 -28
  262. package/apps/storefront/src/lib/integrations/apps/gtmMigrationDraft.ts +0 -103
  263. package/apps/storefront/src/lib/integrations/apps/inventoryWrite.ts +0 -906
  264. package/apps/storefront/src/lib/integrations/apps/orders/customerHash.ts +0 -28
  265. package/apps/storefront/src/lib/integrations/apps/orders/idempotency.ts +0 -100
  266. package/apps/storefront/src/lib/integrations/apps/reports/salesVelocityReport.ts +0 -96
  267. package/apps/storefront/src/lib/integrations/apps/routeParams.ts +0 -45
  268. package/apps/storefront/src/lib/integrations/webhooks/cloudflareQueueDispatcher.ts +0 -82
  269. package/apps/storefront/src/lib/integrations/webhooks/commercePayloads.ts +0 -159
  270. package/apps/storefront/src/lib/integrations/webhooks/deliveryEngine.ts +0 -379
  271. package/apps/storefront/src/lib/integrations/webhooks/deliveryMapper.ts +0 -34
  272. package/apps/storefront/src/lib/integrations/webhooks/deliveryStore.ts +0 -903
  273. package/apps/storefront/src/lib/integrations/webhooks/dispatcher.ts +0 -168
  274. package/apps/storefront/src/lib/integrations/webhooks/emit.ts +0 -245
  275. package/apps/storefront/src/lib/integrations/webhooks/events.ts +0 -105
  276. package/apps/storefront/src/lib/integrations/webhooks/getDispatcher.ts +0 -77
  277. package/apps/storefront/src/lib/integrations/webhooks/orderFulfilledClaim.ts +0 -75
  278. package/apps/storefront/src/lib/measurement/admin/analyticsRegionPolicy.ts +0 -151
  279. package/apps/storefront/src/lib/measurement/admin/analyticsRegionsClient.ts +0 -84
  280. package/apps/storefront/src/lib/measurement/admin/consentSettingsClient.ts +0 -113
  281. package/apps/storefront/src/lib/measurement/analytics/index.ts +0 -44
  282. package/apps/storefront/src/lib/measurement/attribution/attributionService.ts +0 -206
  283. package/apps/storefront/src/lib/measurement/attribution/orderConversionD1.ts +0 -150
  284. package/apps/storefront/src/lib/measurement/attribution/verifiedProviderMeasurement.ts +0 -118
  285. package/apps/storefront/src/lib/measurement/tracking/interactionCollector.ts +0 -205
  286. package/apps/storefront/src/lib/measurement/tracking/pruneRollup.ts +0 -260
  287. package/apps/storefront/src/lib/measurement/tracking/tenantReadAccess.ts +0 -138
  288. package/apps/storefront/src/lib/measurement/tracking-writeback/rewriteTrackingIds.ts +0 -175
  289. package/apps/storefront/src/lib/measurement/tracking-writeback/writebackCandidate.ts +0 -110
  290. package/apps/storefront/src/lib/observability/diag/capture.ts +0 -162
  291. package/apps/storefront/src/lib/observability/diag/consoleLine.ts +0 -76
  292. package/apps/storefront/src/lib/observability/diag/debugConsole.ts +0 -118
  293. package/apps/storefront/src/lib/observability/diag/debugMode.ts +0 -163
  294. package/apps/storefront/src/lib/observability/diag/debugWindow.ts +0 -111
  295. package/apps/storefront/src/lib/observability/diag/redact.ts +0 -17
  296. package/apps/storefront/src/lib/observability/diag/reference.ts +0 -148
  297. package/apps/storefront/src/lib/observability/diag/referenceStore.ts +0 -113
  298. package/apps/storefront/src/lib/observability/diag/report.ts +0 -110
  299. package/apps/storefront/src/lib/observability/diag/serverResponseTime.ts +0 -91
  300. package/apps/storefront/src/lib/observability/diag/session.ts +0 -93
  301. package/apps/storefront/src/lib/observability/monitoring/manifest.ts +0 -301
  302. package/apps/storefront/src/lib/observability/performance/lighthouseReport.ts +0 -109
  303. package/apps/storefront/src/lib/observability/performance/rumAlert.ts +0 -179
  304. package/apps/storefront/src/lib/orders/admin/orderActions.ts +0 -556
  305. package/apps/storefront/src/lib/orders/admin/orderClient.ts +0 -248
  306. package/apps/storefront/src/lib/orders/admin/orderSource.ts +0 -410
  307. package/apps/storefront/src/lib/orders/admin/services/orders.ts +0 -922
  308. package/apps/storefront/src/lib/orders/admin/viewmodels/orders.ts +0 -135
  309. package/apps/storefront/src/lib/orders/data/commerceCallerConfig.ts +0 -37
  310. package/apps/storefront/src/lib/orders/data/ledgerContractOrders.ts +0 -148
  311. package/apps/storefront/src/lib/orders/data/orderForwardReceiver.ts +0 -532
  312. package/apps/storefront/src/lib/orders/data/orderMapper.ts +0 -454
  313. package/apps/storefront/src/lib/orders/data/ordersStore.ts +0 -623
  314. package/apps/storefront/src/lib/orders/data/sourceAuthorityContract.ts +0 -380
  315. package/apps/storefront/src/lib/orders/data/sourceAuthorityStore.ts +0 -830
  316. package/apps/storefront/src/lib/orders/fixtures/orders.ts +0 -186
  317. package/apps/storefront/src/lib/orders/providers/foxyOrderClient.ts +0 -207
  318. package/apps/storefront/src/lib/orders/vault/appRecipientRead.ts +0 -222
  319. package/apps/storefront/src/lib/orders/vault/contactIntake.ts +0 -63
  320. package/apps/storefront/src/lib/orders/vault/contactRoutes.ts +0 -110
  321. package/apps/storefront/src/lib/orders/vault/kmsEnv.ts +0 -11
  322. package/apps/storefront/src/lib/orders/vault/orderContact.ts +0 -96
  323. package/apps/storefront/src/lib/orders/vault/orderContactVault.ts +0 -1427
  324. package/apps/storefront/src/lib/orders/vault/vault-test-support.ts +0 -258
  325. package/apps/storefront/src/lib/publication/d1/schema-apps.ts +0 -808
  326. package/apps/storefront/src/lib/publication/notifications/candidateConflictEmail.ts +0 -80
  327. package/apps/storefront/src/lib/publication/servingMode.ts +0 -52
  328. package/apps/storefront/src/lib/publication/shared/previewAnnotations/moduleAsset.ts +0 -65
  329. package/apps/storefront/src/lib/publication/shared/routedApiParam.ts +0 -38
  330. package/apps/storefront/src/lib/reporting/admin/viewmodels/reporting.ts +0 -34
  331. package/apps/storefront/src/lib/reporting/fixtures/reporting.ts +0 -51
  332. package/apps/storefront/src/lib/subscriptions/admin/viewmodels/subscriptions.ts +0 -106
  333. package/apps/storefront/src/lib/subscriptions/fixtures/subscriptions.ts +0 -398
  334. package/apps/storefront/src/pages/api/admin/activity-alerts.ts +0 -58
  335. package/apps/storefront/src/pages/api/admin/commerce-readiness.ts +0 -172
  336. package/apps/storefront/src/pages/api/admin/fulfillment/batches.ts +0 -59
  337. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id]/address.ts +0 -66
  338. package/apps/storefront/src/pages/api/admin/fulfillment/orders/[id].ts +0 -118
  339. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contact-search.ts +0 -26
  340. package/apps/storefront/src/pages/api/admin/fulfillment/orders/contacts.ts +0 -22
  341. package/apps/storefront/src/pages/api/admin/interaction-insights.ts +0 -101
  342. package/apps/storefront/src/pages/api/admin/orders/[id].ts +0 -63
  343. package/apps/storefront/src/pages/api/admin/orders.ts +0 -65
  344. package/apps/storefront/src/pages/api/contact.ts +0 -144
  345. package/apps/storefront/src/scheduled/contactVaultSweep.ts +0 -113
  346. package/apps/storefront/src/styles/admin.css +0 -1161
  347. package/apps/storefront/test/pipeline/fake-preview-services.ts +0 -288
  348. package/apps/storefront/test/pipeline/harness.ts +0 -209
  349. package/apps/storefront/test/pipeline/intake-worker.mjs +0 -14
  350. package/apps/storefront/test/pipeline/matrix-faults.ts +0 -366
  351. package/apps/storefront/test/pipeline/pipeline-host.ts +0 -418
  352. package/apps/storefront/test/pipeline/pool-config.cjs +0 -85
  353. package/apps/storefront/test/pipeline/publish-kinds.ts +0 -279
  354. package/apps/storefront/test/pipeline/synthetic-job.ts +0 -303
  355. package/apps/storefront/test/pipeline-faults/matrix-lib.ts +0 -696
  356. package/apps/storefront/vitest.config.cts +0 -44
  357. package/apps/storefront/vitest.faults.config.cts +0 -13
  358. package/apps/storefront/vitest.workers.config.cts +0 -7
  359. package/packages/feedback/fixtures/v1/expected-findings.json +0 -16
  360. package/packages/feedback/fixtures/v1/feedback-action/invalid/carries-transport-credential.json +0 -14
  361. package/packages/feedback/fixtures/v1/feedback-action/invalid/control-char-in-description.json +0 -13
  362. package/packages/feedback/fixtures/v1/feedback-action/invalid/legacy-schema-version.json +0 -13
  363. package/packages/feedback/fixtures/v1/feedback-action/invalid/page-path-with-query.json +0 -14
  364. package/packages/feedback/fixtures/v1/feedback-action/invalid/title-too-short.json +0 -13
  365. package/packages/feedback/fixtures/v1/feedback-action/valid/element-problem.json +0 -33
  366. package/packages/feedback/fixtures/v1/feedback-action/valid/page-comment.json +0 -20
  367. package/packages/feedback/fixtures/v1/feedback-action/valid/region-improvement.json +0 -24
  368. package/packages/feedback/fixtures/v1/feedback-action/valid/text-selection-feature.json +0 -30
  369. package/packages/feedback/fixtures/v1/submission-receipt/invalid/accepted-at-not-utc.json +0 -9
  370. package/packages/feedback/fixtures/v1/submission-receipt/invalid/bad-feedback-id.json +0 -9
  371. package/packages/feedback/fixtures/v1/submission-receipt/invalid/legacy-contract-version.json +0 -9
  372. package/packages/feedback/fixtures/v1/submission-receipt/invalid/missing-replayed.json +0 -8
  373. package/packages/feedback/fixtures/v1/submission-receipt/valid/accepted.json +0 -9
  374. package/packages/feedback/fixtures/v1/submission-receipt/valid/fractional-seconds.json +0 -9
  375. package/packages/feedback/fixtures/v1/submission-receipt/valid/replayed.json +0 -9
  376. package/packages/feedback/fixtures/v1/target-evidence/invalid/page-kind-claims-structure.json +0 -6
  377. package/packages/feedback/fixtures/v1/target-evidence/invalid/path-too-deep.json +0 -17
  378. package/packages/feedback/fixtures/v1/target-evidence/invalid/relative-region-out-of-range.json +0 -11
  379. package/packages/feedback/fixtures/v1/target-evidence/invalid/selector-uses-class.json +0 -7
  380. package/packages/feedback/fixtures/v1/target-evidence/invalid/source-precision-without-anchor.json +0 -6
  381. package/packages/feedback/fixtures/v1/target-evidence/valid/element-structure.json +0 -21
  382. package/packages/feedback/fixtures/v1/target-evidence/valid/host-iframe.json +0 -14
  383. package/packages/feedback/fixtures/v1/target-evidence/valid/source-anchor.json +0 -12
  384. package/packages/feedback/fixtures/v1/target-evidence/valid/text-selection.json +0 -26
  385. package/packages/feedback/package.json +0 -35
  386. package/packages/feedback/scripts/build-player.mjs +0 -28
  387. package/packages/feedback/src/index.ts +0 -1
  388. package/packages/feedback/src/primitives/composer.ts +0 -639
  389. package/packages/feedback/src/primitives/dialog.ts +0 -263
  390. package/packages/feedback/src/primitives/hostAdapter.ts +0 -116
  391. package/packages/feedback/src/primitives/index.ts +0 -10
  392. package/packages/feedback/src/primitives/launcher.ts +0 -200
  393. package/packages/feedback/src/primitives/picker.ts +0 -663
  394. package/packages/feedback/src/primitives/redaction.ts +0 -204
  395. package/packages/feedback/src/primitives/selection.ts +0 -49
  396. package/packages/feedback/src/primitives/shiftAccelerator.ts +0 -160
  397. package/packages/feedback/src/primitives/styles.ts +0 -77
  398. package/packages/feedback/src/primitives/surface.ts +0 -124
  399. package/packages/feedback/src/primitives/target.ts +0 -293
  400. package/packages/feedback/src/tour/canonical.ts +0 -27
  401. package/packages/feedback/src/tour/index.ts +0 -3
  402. package/packages/feedback/src/tour/player/browser.ts +0 -5
  403. package/packages/feedback/src/tour/player/host.ts +0 -12
  404. package/packages/feedback/src/tour/player/index.ts +0 -205
  405. package/packages/feedback/src/tour/player/manifest.ts +0 -76
  406. package/packages/feedback/src/tour/player/player.css +0 -130
  407. package/packages/feedback/src/tour/player/resolver.ts +0 -12
  408. package/packages/feedback/src/tour/player/surface.ts +0 -295
  409. package/packages/feedback/src/tour/player/types.ts +0 -8
  410. package/packages/feedback/src/tour/resolve/core.ts +0 -267
  411. package/packages/feedback/src/tour/resolve/dom.ts +0 -115
  412. package/packages/feedback/src/tour/resolve/index.ts +0 -29
  413. package/packages/feedback/src/tour/sanitize.ts +0 -76
  414. package/packages/feedback/src/tour/schema.ts +0 -362
  415. package/packages/feedback/src/v1/guards.ts +0 -335
  416. package/packages/feedback/src/v1/index.ts +0 -3
  417. package/packages/feedback/src/v1/protectedSurfaces.ts +0 -32
  418. package/packages/feedback/src/v1/types.ts +0 -177
  419. package/packages/feedback/tsconfig.json +0 -9
  420. package/packages/feedback/vitest.config.cts +0 -21
@@ -1,164 +0,0 @@
1
- /**
2
- * The admin Products tab's view of the store's real catalog. Two readiness measures stay separate:
3
- * listing readiness (can this product be listed: active, photographed, every variant priced and
4
- * SKU'd) and catalog completeness (how many accepted catalog facts are known). Tax readiness is
5
- * neither, and is not judged here. On a regulated store, listing readiness also requires the
6
- * compliance classification checkout enforces: a product missing it is refused in flavour-ban
7
- * states until the merchant classifies it
8
- * (docs/devkit-staging/books/storefront-devbook-compliance-classification.md).
9
- */
10
- import { complianceClassificationGaps, deriveProductProfile } from "@tot/public-runtime";
11
- import type { CatalogFact, CatalogProduct, ComplianceClassificationGap } from "@tot/public-runtime";
12
- import type { AdminCatalog, CatalogOrigin } from "../services/catalogProducts";
13
-
14
- export interface ListingReadiness {
15
- ready: boolean;
16
- missing: string[];
17
- }
18
-
19
- export interface CatalogCompleteness {
20
- linkedVariants: number;
21
- /** Percent of applicable accepted facts that are known; null when nothing is catalog-linked. */
22
- percent: number | null;
23
- unresolved: number;
24
- }
25
-
26
- export interface CatalogVariantRow {
27
- id: string;
28
- title: string;
29
- sku: string | null;
30
- price: string;
31
- linkedItemId: string | null;
32
- acceptedRevisionId: string | null;
33
- acceptedAt: string | null;
34
- unresolvedFacts: Array<Pick<CatalogFact, "label" | "state">>;
35
- }
36
-
37
- export interface CatalogProductRow {
38
- handle: string;
39
- title: string;
40
- productType: string;
41
- vendor: string;
42
- status: CatalogProduct["status"];
43
- variantCount: number;
44
- priceLabel: string;
45
- imageUrl: string | null;
46
- listing: ListingReadiness;
47
- catalog: CatalogCompleteness;
48
- }
49
-
50
- export interface CatalogProductDetail extends CatalogProductRow {
51
- variants: CatalogVariantRow[];
52
- images: Array<{ url: string; alt: string; variantScoped: boolean }>;
53
- overrides: string[];
54
- collections: string[];
55
- }
56
-
57
- export type CatalogProductsViewModel =
58
- | {
59
- state: "ready" | "empty";
60
- origin: CatalogOrigin;
61
- rows: CatalogProductRow[];
62
- detailsByHandle: Record<string, CatalogProductDetail>;
63
- }
64
- | { state: "error"; message: string; failures: ReadonlyArray<{ path: string; issues: readonly string[] }> };
65
-
66
- const UNRESOLVED = new Set<CatalogFact["state"]>(["unknown", "invalid", "conflict"]);
67
-
68
- function money(amount: number, currency: string, locale: string): string {
69
- try {
70
- return new Intl.NumberFormat(locale, { style: "currency", currency }).format(amount);
71
- } catch {
72
- return `${amount.toFixed(2)} ${currency}`;
73
- }
74
- }
75
-
76
- const plural = (n: number, one: string, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
77
-
78
- const CLASSIFICATION_MISSING: Record<ComplianceClassificationGap, string> = {
79
- category: "Compliance category not classified",
80
- flavor: "Flavour not classified",
81
- };
82
-
83
- /**
84
- * The compliance classifications any of the product's variants is missing, in a stable order. A
85
- * listing-projection record carries no metafields, so it cannot show a classification: it reports
86
- * no gap rather than a false one.
87
- */
88
- export function classificationGaps(product: CatalogProduct): ComplianceClassificationGap[] {
89
- if (!Array.isArray(product.metafields)) return [];
90
- const variants = product.variants.length ? product.variants : [null];
91
- const gaps = new Set(variants.flatMap((v) => complianceClassificationGaps(deriveProductProfile(product, v))));
92
- return (["category", "flavor"] as const).filter((g) => gaps.has(g));
93
- }
94
-
95
- export function listingReadiness(product: CatalogProduct, regulated = false): ListingReadiness {
96
- const missing: string[] = [];
97
- if (regulated) {
98
- for (const gap of classificationGaps(product)) missing.push(`${CLASSIFICATION_MISSING[gap]} (refused in flavour-ban states)`);
99
- }
100
- if (product.status !== "active") missing.push(`Status is ${product.status}`);
101
- if (!product.title.trim()) missing.push("No title");
102
- if (product.images.length === 0) missing.push("No photo");
103
- if (product.variants.length === 0) missing.push("No variants");
104
- const noSku = product.variants.filter((v) => !v.sku?.trim()).length;
105
- const noPrice = product.variants.filter((v) => !(v.price > 0)).length;
106
- if (noSku) missing.push(`${plural(noSku, "variant")} without a SKU`);
107
- if (noPrice) missing.push(`${plural(noPrice, "variant")} without a price`);
108
- return { ready: missing.length === 0, missing };
109
- }
110
-
111
- export function catalogCompleteness(product: CatalogProduct): CatalogCompleteness {
112
- const facts = product.variants.flatMap((v) => v.catalog_link?.facts ?? []);
113
- const applicable = facts.filter((f) => f.state !== "not_applicable");
114
- const linkedVariants = product.variants.filter((v) => v.catalog_link).length;
115
- return {
116
- linkedVariants,
117
- percent: linkedVariants && applicable.length ? Math.round((100 * applicable.filter((f) => f.state === "known").length) / applicable.length) : linkedVariants ? 100 : null,
118
- unresolved: facts.filter((f) => UNRESOLVED.has(f.state)).length,
119
- };
120
- }
121
-
122
- export function toCatalogProductsViewModel(catalog: AdminCatalog, locale: string, regulated = false): CatalogProductsViewModel {
123
- if (!catalog.ok) return { state: "error", message: catalog.message, failures: catalog.failures ?? [] };
124
- const rows: CatalogProductRow[] = [];
125
- const detailsByHandle: Record<string, CatalogProductDetail> = {};
126
- const sorted = [...catalog.products].sort((a, b) => a.title.localeCompare(b.title));
127
- for (const p of sorted) {
128
- const { min, max, currency } = p.price_range;
129
- const row: CatalogProductRow = {
130
- handle: p.handle,
131
- title: p.title,
132
- productType: p.product_type ?? "",
133
- vendor: p.vendor ?? "",
134
- status: p.status,
135
- variantCount: p.variants.length,
136
- priceLabel: min === max ? money(min, currency, locale) : `${money(min, currency, locale)} – ${money(max, currency, locale)}`,
137
- imageUrl: [...p.images].sort((a, b) => a.position - b.position)[0]?.url ?? null,
138
- listing: listingReadiness(p, regulated),
139
- catalog: catalogCompleteness(p),
140
- };
141
- rows.push(row);
142
- detailsByHandle[p.handle] = {
143
- ...row,
144
- variants: [...p.variants]
145
- .sort((a, b) => a.position - b.position)
146
- .map((v) => ({
147
- id: v.id,
148
- title: v.title,
149
- sku: v.sku?.trim() || null,
150
- price: v.price > 0 ? money(v.price, v.currency, locale) : "—",
151
- linkedItemId: v.catalog_link?.item_id ?? null,
152
- acceptedRevisionId: v.catalog_link?.accepted_revision_id ?? null,
153
- acceptedAt: v.catalog_link?.accepted_at ?? null,
154
- unresolvedFacts: (v.catalog_link?.facts ?? []).filter((f) => UNRESOLVED.has(f.state)).map((f) => ({ label: f.label, state: f.state })),
155
- })),
156
- images: [...p.images]
157
- .sort((a, b) => a.position - b.position)
158
- .map((img) => ({ url: img.url, alt: img.alt ?? "", variantScoped: Boolean(img.variant_ids?.length) })),
159
- overrides: p.catalog_overrides ?? [],
160
- collections: p.collections,
161
- };
162
- }
163
- return { state: rows.length ? "ready" : "empty", origin: catalog.origin, rows, detailsByHandle };
164
- }
@@ -1,267 +0,0 @@
1
- /**
2
- * Products view model (baseline §Products) — catalog readiness and
3
- * sellability, including the explicit excise-metadata readiness checks called
4
- * out in the baseline doc (tax class, exempt flag, nicotine flag, wholesale
5
- * basis, retail price, pack quantity, volume/weight, category).
6
- */
7
-
8
- export type ExciseCheckKey =
9
- | "tax_class"
10
- | "exempt_flag"
11
- | "nicotine_flag"
12
- | "wholesale_basis"
13
- | "retail_price"
14
- | "pack_quantity"
15
- | "volume_or_weight"
16
- | "category";
17
-
18
- export interface ExciseReadinessCheck {
19
- key: ExciseCheckKey;
20
- label: string;
21
- present: boolean;
22
- value: string | null;
23
- }
24
-
25
- export interface ProductVariant {
26
- sku: string;
27
- name: string;
28
- inventory: number;
29
- price: number;
30
- }
31
-
32
- export interface ProductMediaAsset {
33
- url: string;
34
- alt: string;
35
- kind: "image" | "video";
36
- }
37
-
38
- export interface ProductActivityEvent {
39
- title: string;
40
- detail: string;
41
- at: string;
42
- }
43
-
44
- export interface ProductRow {
45
- id: string;
46
- name: string;
47
- productType: string;
48
- category: string;
49
- status: "active" | "draft" | "archived";
50
- readinessScore: number;
51
- sellable: boolean;
52
- aiChannelReady: boolean;
53
- missingExciseCount: number;
54
- }
55
-
56
- export interface ProductDetail extends ProductRow {
57
- variants: ProductVariant[];
58
- media: ProductMediaAsset[];
59
- exciseChecks: ExciseReadinessCheck[];
60
- activity: ProductActivityEvent[];
61
- complianceNotes: string[];
62
- }
63
-
64
- export interface ProductSavedView {
65
- key: string;
66
- label: string;
67
- }
68
-
69
- export interface ProductsViewModel {
70
- targetTenant: string;
71
- savedViews: ProductSavedView[];
72
- rows: ProductRow[];
73
- detailsById: Record<string, ProductDetail>;
74
- }
75
-
76
- /**
77
- * Closed per-SKU outcome returned by tot-foxycart's excise SKU registration route
78
- * (`POST /api/commerce/excise/products`).
79
- */
80
- export const EXCISE_SKU_OUTCOMES = [
81
- "registered",
82
- "already-registered",
83
- "found",
84
- "not-found",
85
- "deactivated",
86
- "refused-invalid-sku",
87
- "refused-registry",
88
- "refused-owned-by-other-tenant",
89
- ] as const;
90
-
91
- export type ExciseSkuOutcome = (typeof EXCISE_SKU_OUTCOMES)[number];
92
-
93
- /**
94
- * The admin view states for a catalog SKU in the Excise tax section (`ac-1`).
95
- */
96
- export type ExciseSkuState = "registered" | "missing" | "refused" | "unavailable";
97
-
98
- export const EXCISE_UNAVAILABLE_MESSAGE =
99
- "Registry status is unavailable right now; reload to try again.";
100
-
101
- export type ExciseProductType = "vape" | "nicotinePouch" | "hemp";
102
-
103
- export type ExciseVapeSystemType =
104
- | "open"
105
- | "closed"
106
- | "isLiquid"
107
- | "isPart"
108
- | "isOpen"
109
- | "closedSingleUse"
110
- | "closedCartridge"
111
- | "batteryOnly"
112
- | "pack";
113
-
114
- export interface ExciseSkuAttributes {
115
- type: ExciseProductType;
116
- vapeSystemType: ExciseVapeSystemType;
117
- volumeInMl: number;
118
- wholesaleCost: number;
119
- wholesalePrice: number;
120
- msrp: number;
121
- retailPrice: number;
122
- hasNicotine: boolean;
123
- packQuantity: number;
124
- }
125
-
126
- export interface ExciseCatalogSkuRow {
127
- sku: string;
128
- productHandle: string;
129
- productTitle: string;
130
- variantId: string;
131
- variantTitle: string;
132
- brand: string;
133
- currency: string;
134
- state: ExciseSkuState;
135
- outcome: ExciseSkuOutcome | null;
136
- message: string;
137
- attributes: Partial<ExciseSkuAttributes>;
138
- }
139
-
140
- export interface ExciseRegistrySkuSnapshot {
141
- outcome: ExciseSkuOutcome;
142
- active?: boolean;
143
- attributes?: Partial<ExciseSkuAttributes>;
144
- }
145
-
146
- const CLOSED_OUTCOME_MESSAGES: Readonly<Record<ExciseSkuOutcome, string>> = Object.freeze({
147
- registered: "Registered in the excise tax registry.",
148
- "already-registered": "Already registered in the excise tax registry.",
149
- found: "Registered in the excise tax registry.",
150
- "not-found": "Not registered in the excise tax registry yet.",
151
- deactivated: "Deactivated in the excise tax registry (exempt).",
152
- "refused-invalid-sku": "Registration refused: invalid SKU or engine attributes.",
153
- "refused-registry": "Registration refused: the excise tax registry could not complete this request.",
154
- "refused-owned-by-other-tenant": "Registration refused: this SKU code is owned by another store.",
155
- });
156
-
157
- export function isExciseSkuOutcome(value: unknown): value is ExciseSkuOutcome {
158
- return typeof value === "string" && (EXCISE_SKU_OUTCOMES as readonly string[]).includes(value);
159
- }
160
-
161
- /**
162
- * Map a closed registry outcome into the admin SKU state (`registered`, `missing`, or `refused`).
163
- */
164
- export function mapExciseOutcomeToState(
165
- outcome: ExciseSkuOutcome | null | undefined,
166
- active?: boolean,
167
- ): ExciseSkuState {
168
- if (!outcome || outcome === "not-found" || outcome === "deactivated") return "missing";
169
- if (outcome === "found") return active === false ? "missing" : "registered";
170
- if (outcome === "registered" || outcome === "already-registered") return "registered";
171
- return "refused";
172
- }
173
-
174
- /**
175
- * Return the closed, truthful message for a SKU's registration outcome (`ac-3`).
176
- * Upstream response bodies are never interpolated here.
177
- */
178
- export function exciseOutcomeMessage(
179
- outcome: ExciseSkuOutcome | null | undefined,
180
- active?: boolean,
181
- ): string {
182
- if (!outcome) return CLOSED_OUTCOME_MESSAGES["not-found"];
183
- if (outcome === "found" && active === false) return CLOSED_OUTCOME_MESSAGES.deactivated;
184
- return CLOSED_OUTCOME_MESSAGES[outcome] ?? CLOSED_OUTCOME_MESSAGES["refused-registry"];
185
- }
186
-
187
- /**
188
- * Validate a bare catalog SKU before any U4 call: 1..200 chars, trimmed, no whitespace,
189
- * no colon (`:`), and no wildcard (`*`).
190
- */
191
- export function isValidBareCatalogSku(value: unknown): value is string {
192
- if (typeof value !== "string") return false;
193
- const trimmed = value.trim();
194
- if (!trimmed || trimmed !== value || trimmed.length > 200) return false;
195
- if (/[\s:*]/.test(trimmed)) return false;
196
- return true;
197
- }
198
-
199
- export interface CatalogProductLike {
200
- handle: string;
201
- title: string;
202
- vendor?: string;
203
- product_type?: string;
204
- metafields?: ReadonlyArray<{ namespace: string; key: string; value: string }>;
205
- variants: ReadonlyArray<{
206
- id: string;
207
- title: string;
208
- sku?: string;
209
- price: number;
210
- compare_at_price?: number;
211
- currency: string;
212
- }>;
213
- }
214
-
215
- /**
216
- * Build the admin excise SKU rows from the store's catalog products and optional registry read-back.
217
- * Only variants with a valid bare SKU in the store's catalog are included.
218
- * Regulated engine attributes are never guessed from catalog prices; only registry-returned
219
- * attributes are populated. When a registry read fails (`registryUnavailable: true`), rows with no
220
- * snapshot are marked `"unavailable"` rather than `"missing"`.
221
- */
222
- export function toExciseCatalogSkuRows(
223
- products: readonly CatalogProductLike[],
224
- registryBySku?: ReadonlyMap<string, ExciseRegistrySkuSnapshot>,
225
- options?: { registryUnavailable?: boolean },
226
- ): ExciseCatalogSkuRow[] {
227
- const rows: ExciseCatalogSkuRow[] = [];
228
- const seen = new Set<string>();
229
- const registryUnavailable = options?.registryUnavailable === true;
230
- const sortedProducts = [...products].sort((a, b) => a.title.localeCompare(b.title));
231
- for (const product of sortedProducts) {
232
- for (const variant of product.variants) {
233
- const sku = typeof variant.sku === "string" ? variant.sku.trim() : "";
234
- if (!isValidBareCatalogSku(sku) || seen.has(sku)) continue;
235
- seen.add(sku);
236
- const snapshot = registryBySku?.get(sku);
237
- const outcome = snapshot?.outcome ?? null;
238
- const state: ExciseSkuState = snapshot
239
- ? mapExciseOutcomeToState(outcome, snapshot.active)
240
- : registryUnavailable
241
- ? "unavailable"
242
- : "missing";
243
- const message = snapshot
244
- ? exciseOutcomeMessage(outcome, snapshot.active)
245
- : registryUnavailable
246
- ? EXCISE_UNAVAILABLE_MESSAGE
247
- : exciseOutcomeMessage(null);
248
- const attributes: Partial<ExciseSkuAttributes> = snapshot?.attributes
249
- ? { ...snapshot.attributes }
250
- : {};
251
- rows.push({
252
- sku,
253
- productHandle: product.handle,
254
- productTitle: product.title,
255
- variantId: variant.id,
256
- variantTitle: variant.title,
257
- brand: (product.vendor ?? "").trim() || product.title,
258
- currency: variant.currency || "USD",
259
- state,
260
- outcome,
261
- message,
262
- attributes,
263
- });
264
- }
265
- }
266
- return rows;
267
- }
@@ -1,105 +0,0 @@
1
- import type { AdminTenantEnvelope } from "../../access/admin/envelope";
2
- import { MOCK_ANCHOR_ISO, offsetIso, pick, randomBool, randomInt, seededRandom } from "../../developer-experience/admin/seed";
3
- import type {
4
- ExciseCheckKey,
5
- ExciseReadinessCheck,
6
- ProductDetail,
7
- ProductRow,
8
- ProductsViewModel,
9
- ProductVariant,
10
- } from "../admin/viewmodels/products";
11
- import { tenantProfile } from "../../access/fixtures/tenants";
12
- import { memoizeByEnvelope } from "../../developer-experience/admin/memoizeByEnvelope";
13
-
14
- // Must stay index-aligned with orders.ts's ITEM_POOLS: a product's id is
15
- // `prod-<tenant>-<position here>`, and orders.ts derives each order's productId
16
- // from the same position, so the evidence graph can join order→product by id.
17
- const PRODUCT_NAMES: Record<string, string[]> = {
18
- vape: ["Vape Pen Starter Kit", "Disposable Vape 5000", "Nicotine Pouches 6mg", "Replacement Coil 3-Pack"],
19
- tobacco: ["Pipe Tobacco 1oz", "Cigar Sampler Pack", "Rolling Papers 32ct", "Loose Leaf Blend"],
20
- };
21
-
22
- const EXCISE_CHECK_DEFS: { key: ExciseCheckKey; label: string }[] = [
23
- { key: "tax_class", label: "Tax class" },
24
- { key: "exempt_flag", label: "Exempt flag" },
25
- { key: "nicotine_flag", label: "Nicotine flag" },
26
- { key: "wholesale_basis", label: "Wholesale basis" },
27
- { key: "retail_price", label: "Retail price" },
28
- { key: "pack_quantity", label: "Pack quantity" },
29
- { key: "volume_or_weight", label: "Volume or weight" },
30
- { key: "category", label: "Product category" },
31
- ];
32
-
33
- function buildExciseChecks(rng: () => number): ExciseReadinessCheck[] {
34
- return EXCISE_CHECK_DEFS.map((def) => {
35
- const present = randomBool(rng, 0.82);
36
- return {
37
- key: def.key,
38
- label: def.label,
39
- present,
40
- value: present ? pick(rng, ["Set", "Confirmed", "20mg", "Case of 12", "Vape"]) : null,
41
- };
42
- });
43
- }
44
-
45
- function computeProductsViewModel(envelope: AdminTenantEnvelope): ProductsViewModel {
46
- const { targetTenant } = envelope;
47
- const profile = tenantProfile(targetTenant);
48
- const rng = seededRandom(`products:${targetTenant}`);
49
- const names = PRODUCT_NAMES[profile.vertical] ?? PRODUCT_NAMES.vape!;
50
-
51
- const rows: ProductRow[] = [];
52
- const detailsById: Record<string, ProductDetail> = {};
53
-
54
- names.forEach((name, index) => {
55
- const id = `prod-${targetTenant}-${index}`;
56
- const exciseChecks = buildExciseChecks(rng);
57
- const missingExciseCount = exciseChecks.filter((c) => !c.present).length;
58
- const readinessScore = Math.max(0, 100 - missingExciseCount * 15);
59
- const sellable = missingExciseCount === 0;
60
-
61
- const row: ProductRow = {
62
- id,
63
- name,
64
- productType: profile.vertical === "vape" ? "Vaping device" : "Tobacco product",
65
- category: profile.vertical === "vape" ? "Vape" : "Tobacco",
66
- status: "active",
67
- readinessScore,
68
- sellable,
69
- aiChannelReady: sellable && randomBool(rng, 0.6),
70
- missingExciseCount,
71
- };
72
- rows.push(row);
73
-
74
- const variants: ProductVariant[] = Array.from({ length: randomInt(rng, 1, 3) }, (_, vIndex) => ({
75
- sku: `${id}-v${vIndex}`,
76
- name: vIndex === 0 ? "Default" : `Variant ${vIndex}`,
77
- inventory: randomInt(rng, 0, 250),
78
- price: randomInt(rng, 15, 65),
79
- }));
80
-
81
- detailsById[id] = {
82
- ...row,
83
- variants,
84
- media: [{ url: `/mock/admin/products/${id}.png`, alt: name, kind: "image" }],
85
- exciseChecks,
86
- activity: [
87
- { title: "Listed", detail: `${name} added to catalog.`, at: offsetIso(MOCK_ANCHOR_ISO, -randomInt(rng, 1000, 20000)) },
88
- ],
89
- complianceNotes: missingExciseCount > 0 ? [`${missingExciseCount} excise metadata field(s) missing before this can sell.`] : [],
90
- };
91
- });
92
-
93
- return {
94
- targetTenant,
95
- savedViews: [
96
- { key: "all", label: "All products" },
97
- { key: "not_sellable", label: "Not sellable" },
98
- { key: "ai_channel_ready", label: "AI channel ready" },
99
- ],
100
- rows,
101
- detailsById,
102
- };
103
- }
104
-
105
- export const getProductsViewModel = memoizeByEnvelope(computeProductsViewModel);
@@ -1,111 +0,0 @@
1
- /**
2
- * Worker-side reader for the durable per-tenant catalog sync state (hsby-B1).
3
- * The migration CLI writes one JSON document per tenant scope at
4
- * out/catalog/<scope>/sync-state.json (packages/migration/src/load/sync-state.ts,
5
- * `SyncStateStore`/`nextSyncState`) — this module is the Worker's read side of
6
- * that same file, via the same Vite glob mechanism `ToTClient.ts` uses for
7
- * products.json/collections.json/reviews.json. OPTIONAL: a tenant with no
8
- * recorded sync (or one migrated before hsby-B1 landed) just gets `null`.
9
- *
10
- * This is intentionally a thin, standalone read — not wired into `ToTClient`,
11
- * since not every caller needs sync provenance. hsby-B3's readiness projection
12
- * is the expected first consumer.
13
- */
14
-
15
- /** Mirrors packages/migration/src/load/sync-state.ts's `SourcePlatform`. */
16
- export type SyncStateSourcePlatform =
17
- | "shopify-admin"
18
- | "shopify-public"
19
- | "fixtures"
20
- | "existing";
21
-
22
- /** Mirrors packages/migration/src/load/sync-state.ts's `FidelityLevel`. */
23
- export type SyncStateFidelityLevel = "full" | "reduced" | "unknown";
24
-
25
- export interface SyncStateFidelity {
26
- level: SyncStateFidelityLevel;
27
- note: string;
28
- missing: string[];
29
- }
30
-
31
- export interface SyncStateSourceMode {
32
- platform: SyncStateSourcePlatform;
33
- mode: "full" | "incremental";
34
- fullSweepOnly: boolean;
35
- }
36
-
37
- export interface SyncStateEntity {
38
- checksums: Record<string, string>;
39
- lastUpdatedAt: string | null;
40
- }
41
-
42
- /** Mirrors packages/migration/src/load/sync-state.ts's `EntityChangeSet`. */
43
- export interface SyncStateEntityChangeSet {
44
- added: string[];
45
- updated: string[];
46
- removed: string[];
47
- unchanged: number;
48
- }
49
-
50
- /** Mirrors packages/migration/src/load/sync-state.ts's `SweepChanges`. */
51
- export interface SyncStateSweepChanges {
52
- computedAt: string;
53
- mode: "full" | "incremental";
54
- removalsAssessed: boolean;
55
- fullSweepOnly: boolean;
56
- products: SyncStateEntityChangeSet;
57
- collections: SyncStateEntityChangeSet;
58
- }
59
-
60
- /** The on-disk shape written by the migration CLI (schema "tot.sync-state/1"). */
61
- export interface CatalogSyncState {
62
- schema: string;
63
- tenantId: string;
64
- scope: string;
65
- source: SyncStateSourceMode;
66
- fidelity: SyncStateFidelity;
67
- lastSyncAt: string | null;
68
- /** True when the most recent sync loaded with record errors; absent on a pre-hsby-B3 catalog. */
69
- lastSyncHadErrors?: boolean;
70
- products: SyncStateEntity;
71
- collections: SyncStateEntity;
72
- /**
73
- * The content-hash delta of the most recent sweep. Optional: a catalog
74
- * migrated before hsby-B2 (change detection) has no `lastChanges`.
75
- */
76
- lastChanges?: SyncStateSweepChanges;
77
- }
78
-
79
- // Vite resolves this glob at build time and bundles every tenant's sync-state
80
- // document, so the Worker has no runtime filesystem dependency — same pattern
81
- // as productGlobs/collectionGlobs/reviewGlobs in ToTClient.ts.
82
- const syncStateGlobs = import.meta.glob<CatalogSyncState>(
83
- "../../../../../../packages/migration/out/catalog/*/sync-state.json",
84
- { import: "default" },
85
- );
86
-
87
- const syncStateCacheByScope = new Map<string, CatalogSyncState | null>();
88
-
89
- /** Pick the glob entry for a tenant scope (matches .../catalog/<scope>/file). */
90
- function pickByScope(scope: string): (() => Promise<CatalogSyncState>) | null {
91
- const suffix = `/catalog/${scope}/`;
92
- const key = Object.keys(syncStateGlobs).find((k) => k.includes(suffix));
93
- return (key ? syncStateGlobs[key] : null) ?? null;
94
- }
95
-
96
- /**
97
- * The tenant's durable sync state, or null when none was ever recorded (no
98
- * migration run yet, or a pre-hsby-B1 catalog). Never throws.
99
- */
100
- export async function getSyncState(scope: string): Promise<CatalogSyncState | null> {
101
- if (syncStateCacheByScope.has(scope)) return syncStateCacheByScope.get(scope)!;
102
- const loader = pickByScope(scope);
103
- const state = loader ? await loader() : null;
104
- syncStateCacheByScope.set(scope, state);
105
- return state;
106
- }
107
-
108
- /** Test seam: drop the per-isolate cache. */
109
- export function clearSyncStateCache(): void {
110
- syncStateCacheByScope.clear();
111
- }