@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,34 +0,0 @@
1
- ---
2
- /**
3
- * <WidgetFrame> — renders a tenant-registered widget (isolation:"sandbox") in a
4
- * sandboxed iframe. The sandbox token list (`allow-scripts`, no
5
- * `allow-same-origin`) puts the widget in an opaque origin, so it cannot read the
6
- * page's cookies/DOM or its own storage, even though the bundle is served from our
7
- * own origin. The widget bundle is hash-pinned in CSP and placed into a
8
- * platform-defined slot.
9
- */
10
- import { widgetFrameAttrs, type ScriptStrategy } from "@tot/public-runtime";
11
-
12
- interface Props {
13
- /** Same-origin URL that loads the tenant's widget bundle. */
14
- src: string;
15
- /** Accessible title for the iframe (required for a11y). */
16
- title: string;
17
- strategy?: ScriptStrategy;
18
- /** Optional fixed height; widgets may also self-size via postMessage later. */
19
- height?: string;
20
- }
21
-
22
- const { src, title, strategy = "on-idle", height = "auto" } = Astro.props;
23
- const attrs = widgetFrameAttrs(strategy);
24
- ---
25
-
26
- <iframe
27
- src={src}
28
- title={title}
29
- sandbox={attrs.sandbox}
30
- loading={attrs.loading}
31
- referrerpolicy={attrs.referrerpolicy}
32
- class="tot-widget-frame"
33
- style={`border:0;width:100%;height:${height};`}
34
- ></iframe>
@@ -1,35 +0,0 @@
1
- /**
2
- * Admin integration plane — arbitrary-tenant lookup provider (ext-kernel-09).
3
- *
4
- * The `/api/apps/admin/*` integration routes resolve a tenant named in the operator
5
- * session (`auth.tenantId` — a vendor may administer a tenant that is NOT the
6
- * request's own host scope, so `Astro.locals.tenant` does not apply). Materializing
7
- * a tenant's OWN (tenant-local) declarations needs its full config (`compliance`,
8
- * `siteType`, `integrations`), which requires the concrete resolver selection — and
9
- * the `tenancy-resolver-fence` extractability invariant forbids pages/lib from
10
- * importing that directly.
11
- *
12
- * This module lives in `src/config` (an approved location) and encapsulates
13
- * `getTenantResolver()` + `staticTenants`, exposing exactly the by-id lookup the
14
- * admin routes need, typed against the public `TenantConfig`. Mirrors
15
- * `previewTenantLookup.ts`; the concrete resolver selection stays in `config`, so a
16
- * constant single-tenant resolver remains a drop-in and the codebase stays
17
- * always-extractable.
18
- */
19
- import type { TenantConfig } from "@tot/public-runtime";
20
- import { getTenantResolver } from "@/config/resolver";
21
- import { staticTenants } from "@/config/tenants";
22
-
23
- /**
24
- * Resolve the admin operator's tenant id (== appDomain for the built-in tenants) to
25
- * its config. Strict domain match first (KV-backed in prod, static in dev), then the
26
- * static registry by appDomain or tenant_id. Null for an unknown tenant.
27
- */
28
- export async function resolveAdminTenant(tenantId: string): Promise<TenantConfig | null> {
29
- const resolver = await getTenantResolver();
30
- return (
31
- (await resolver.resolveStrict(tenantId)) ??
32
- staticTenants.find((t) => t.appDomain === tenantId || t.tenant_id === tenantId) ??
33
- null
34
- );
35
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * The evidence-URL tenant roster, derived from the live tenant registry.
3
- *
4
- * Lives in `src/config` (not a `pages`/`lib` file) so it — not the `.well-known` route — is the
5
- * one place allowed to import the concrete `staticTenants` map (`tenancy-resolver-fence`:
6
- * pages/components/layouts/lib may depend only on the `TenantResolver` interface, never the
7
- * concrete static map, so a constant single-tenant resolver stays a drop-in).
8
- */
9
- import { listedTenants } from "@tot/public-runtime";
10
- import { staticTenants } from "@/config/tenants";
11
-
12
- /**
13
- * Tenant id -> canonical domain for every real, registered tenant. For a real tenant
14
- * `tenant_id === appDomain === canonicalDomain` (see `config/tenants.ts`), so onboarding a
15
- * tenant in the registry is enough to publish its evidence URL — no separate hand-maintained
16
- * map to update. Internal/e2e test tenants are excluded (never real merchants, never a real
17
- * evidence surface).
18
- */
19
- export function evidenceRegistryRoster(): Record<string, string> {
20
- const roster: Record<string, string> = {};
21
- for (const tenant of listedTenants(staticTenants)) {
22
- roster[tenant.tenant_id] = tenant.canonicalDomain;
23
- }
24
- return roster;
25
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * TENANT_CACHE projection for staff/operator store provision.
3
- *
4
- * Lives under src/config so pages/lib may call it without crossing the
5
- * tenancy-resolver-fence (only config/middleware may import kvTenantResolver).
6
- */
7
- import type { TenantConfig } from "@tot/public-runtime";
8
- import { putTenant } from "@/config/kvTenantResolver";
9
-
10
- export async function projectProvisionedTenant(
11
- kv: KVNamespace,
12
- config: TenantConfig,
13
- repoMeta: { owner: string; repo: string; cloneUrl: string | null },
14
- ): Promise<void> {
15
- await putTenant(kv, config);
16
- await kv.put(
17
- `repo:${config.tenant_id}`,
18
- JSON.stringify({
19
- owner: repoMeta.owner,
20
- repo: repoMeta.repo,
21
- cloneUrl: repoMeta.cloneUrl,
22
- }),
23
- );
24
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * Best-effort friendly store name for a tenant's appDomain, used to humanize the
3
- * developer magic-link invite — the email subject/body ("Your invitation to …")
4
- * and the /auth/magic "Signing in to …" card, which otherwise fall back to the
5
- * bare appDomain (the "generic" tell in the deployed invite UX).
6
- *
7
- * Resolves via the SAME canonical TenantResolver the middleware uses on every
8
- * request (config/resolver), so the name is only ever the tenant's real
9
- * displayName — never fabricated. Returns undefined when no tenant resolves or it
10
- * carries no displayName; callers then omit `storeName` and the flow shows the
11
- * appDomain as before. NEVER throws: a display-label lookup must not be able to
12
- * break sending (or resending) an invite.
13
- *
14
- * Lives in the config layer (not lib) so this appDomain→displayName lookup can
15
- * consume the CONCRETE resolver behind the `tenancy-resolver-fence`
16
- * (.dependency-cruiser.cjs) — mirroring `config/adminTargetTenant` and
17
- * `config/previewTenantLookup`, the other sanctioned resolver-consuming seams —
18
- * so a single-tenant extraction stays a drop-in (the resolver is swapped, not the
19
- * callers).
20
- */
21
- import { getTenantResolver } from "@/config/resolver";
22
-
23
- export async function resolveStoreName(appDomain: string): Promise<string | undefined> {
24
- const domain = appDomain.trim();
25
- if (!domain) return undefined;
26
- try {
27
- const resolver = await getTenantResolver();
28
- const tenant = await resolver.resolveStrict(domain);
29
- const name = tenant?.displayName?.trim();
30
- return name || undefined;
31
- } catch {
32
- return undefined;
33
- }
34
- }
@@ -1,122 +0,0 @@
1
- # `lib/admin` — admin data/view + AI/evidence contracts
2
-
3
- Read-oriented view models and deterministic mock services for the 8 admin
4
- domains (orders, products, subscriptions, customers, fulfillment, reporting, settings,
5
- ai-workflows), plus the AI/evidence substrate (`ai/`, `evidence/`) those
6
- domains' assist surfaces build on. See
7
- `docs/handoffs/admin-app-implementation-baseline.md` for the product spec
8
- these implement.
9
-
10
- ## Tenant envelope
11
-
12
- The canonical tenant envelope is `AdminTenantEnvelope`, defined in
13
- `lib/access/shared/adminTenantEnvelope.ts` (admin-tenant-mode) and re-exported from
14
- `lib/access/admin/envelope.ts` so everything under `lib/admin/**` can import it from
15
- a stable relative path:
16
-
17
- ```ts
18
- interface AdminTenantEnvelope {
19
- adminAppTenant: string; // the tenant that actually served this request
20
- targetTenant: string; // the merchant tenant this page's data/actions are scoped to
21
- operator: string | null; // the signed-in viewer's email, or null when anonymous
22
- }
23
- ```
24
-
25
- For merchant-facing admin `adminAppTenant` and `targetTenant` are equal; only
26
- a real ToT-staff session may move `targetTenant` away from the routed tenant
27
- (see `resolveAdminTenantMode` for the authorization rule — deny-by-default,
28
- refused not hidden-only). `targetTenant` is the sole key mock services use to
29
- select/derive data. **Authorization must always be evaluated against
30
- `targetTenant`, never `adminAppTenant`** (decision `tenant-envelope-contract`).
31
-
32
- (`lib/access/admin/envelope.ts` used to declare its own 2-field copy of this
33
- interface — data-view-contracts and admin-tenant-mode were built in parallel
34
- per that decision, with no live coordination. Reconciled here per decision
35
- `envelope-type-duplication-follow-up`: one canonical type, re-exported.)
36
-
37
- ## Layout
38
-
39
- ```
40
- lib/admin/
41
- envelope.ts # re-exports the canonical AdminTenantEnvelope
42
- seed.ts # deterministic PRNG + timestamp helpers
43
- viewmodels/<domain>.ts # types only, no I/O
44
- services/mock/<domain>.ts # getXViewModel(envelope) -> X ViewModel
45
- services/mock/evidence.ts # getEvidenceViewModel(envelope) -> EvidenceReference[]
46
- services/mock/tenants.ts # seeded tenant registry + fallback profile
47
- services/mock/index.ts # barrel re-export
48
- ai/
49
- approvalMode.ts # canonical ApprovalMode + isDraftOnly/requiresHumanApproval/isAutomationAllowed
50
- audit.ts # canonical AuditEvent (operator + targetTenant + action + at)
51
- recommendation.ts # AiRecommendation — the recommendation-shaped record every AI suggestion should use
52
- askEnvelope.ts # AskEnvelope + buildAskEnvelope() — the floating Ask button's context
53
- evidence/
54
- evidenceReference.ts # EvidenceReference + EvidenceKind — the evidence graph's typed pointer
55
- ```
56
-
57
- ## AI / evidence substrate
58
-
59
- - **Approval state machine** (`ai/approvalMode.ts`): `draft_only` |
60
- `approval_required` | `guarded_automation`. `settings.ts` and
61
- `aiWorkflows.ts` both import this rather than declaring their own copy.
62
- - **Audit events** (`ai/audit.ts`): `{ operator, targetTenant, action, at }`.
63
- `SettingsAuditEvent` extends it with a human-readable `change` string;
64
- `WorkflowRecord.auditTrail` uses it directly.
65
- - **Recommendations** (`ai/recommendation.ts`): `AiRecommendation` is the
66
- shape every AI-suggested action should carry — `summary`, `confidence`
67
- (0–1), `evidenceRefs` (ids into the evidence graph), `owner`,
68
- `approvalMode`, `auditTrail`. `WorkflowRecord.suggestedAction` uses this
69
- today; later per-tab assist surfaces (Order Assist, Fulfillment Assist,
70
- etc.) should reuse it instead of inventing a parallel "suggestion" shape.
71
- - **Evidence graph** (`evidence/evidenceReference.ts` +
72
- `services/mock/evidence.ts`): a typed, tenant-scoped pointer
73
- (`EvidenceReference`) connecting orders, customers, products, payments,
74
- verification events, fulfillment/tracking, support/contact events, policy
75
- acceptance, tax/excise evidence, and admin/user actions
76
- (`EvidenceKind`). The mock service builds real edges by cross-referencing
77
- the orders/customers/products mock services already in this directory
78
- (an order's evidence ref links to its customer and product refs via
79
- `relatedRefs`) rather than inventing disconnected fixture data.
80
- - **Ask envelope** (`ai/askEnvelope.ts`): `buildAskEnvelope()` is the pure,
81
- testable source of truth for what the floating Ask button emits — the full
82
- tenant envelope, active tab, selected record id (if any), role +
83
- permissions (derived from `isStaff`), active filters, and evidence context.
84
- The processed `adminShell.ts` client imports this builder and emits its
85
- result on Ask-button click as
86
- `window.__toTAdminAsk` and a `tot:admin-ask` `CustomEvent` — **dev-inspectable
87
- only, no chat backend yet.** The envelope changes whenever the active tab
88
- changes (kept current by `setAskContext`) and is rebuilt fresh on click so a
89
- selection made via `data-admin-selected-id` (a hook future tab units can set
90
- on their selected row/detail panel — none do yet) is picked up.
91
-
92
- ## Determinism
93
-
94
- Every mock service seeds its randomness from `seededRandom(`<domain>:${targetTenant}`)`
95
- (`seed.ts`), so **the same `targetTenant` always returns the same data** within
96
- a process — no reliance on `Date.now()` or other wall-clock state. Two tenants
97
- are curated with vertical-flavored data (`northridge-vapor.com` — vape,
98
- `cascade-tobacco.com` — tobacco); any other `targetTenant` string still gets a
99
- stable fallback profile via `tenantProfile()`, so callers never need to
100
- special-case an "unknown" tenant.
101
-
102
- ## Usage
103
-
104
- ```ts
105
- import { getOrdersViewModel } from "@/lib/admin/services/mock";
106
-
107
- const orders = getOrdersViewModel({
108
- adminAppTenant: tenant.tenant_id,
109
- targetTenant: tenant.tenant_id,
110
- operator: viewerEmail,
111
- });
112
- ```
113
-
114
- ## Boundaries
115
-
116
- - **Read-only.** No write/mutation paths exist yet — that is a later unit.
117
- - **Tabs/pages → lib, never lib → tabs/pages.** Nothing under `lib/admin/**`
118
- imports from `components/admin/**` or `pages/admin.astro`. Tab components
119
- and `admin.astro` are free to import from here (`admin.astro` already does,
120
- for `resolveAdminTenantMode` and the shared shell configuration).
121
- - Gaps in these contracts should go back to the workstream board as a
122
- decision, not get patched from a tab's unit.
@@ -1,281 +0,0 @@
1
- /**
2
- * Admin console shell client logic — hash-router tab switching, the floating
3
- * Ask envelope, tenant-picker navigation, and roving-tabindex keyboard nav for
4
- * the tablists. Imported from a processed `<script>` in admin.astro (ADR 0013):
5
- * type-checked, bundled, tree-shaken, and its bundle hash is in the enforced
6
- * CSP. The Ask envelope is built with the shared, unit-tested
7
- * `buildAskEnvelope` (ai/askEnvelope).
8
- *
9
- * There is no chat backend yet — the Ask envelope is emitted for dev inspection
10
- * only (window.__toTAdminAsk + a "tot:admin-ask" CustomEvent), never sent over
11
- * the network.
12
- */
13
- import { buildAskEnvelope, type AskEnvelope } from "../../automation/ai/askEnvelope";
14
-
15
- /** Static shell data shared by server-rendered navigation and browser startup. */
16
- export const ADMIN_SHELL_CONFIG = {
17
- workAreas: [
18
- { id: "orders", label: "Orders", icon: "i-file" },
19
- { id: "products", label: "Products", icon: "i-box" },
20
- { id: "subscriptions", label: "Subscriptions", icon: "i-refresh" },
21
- { id: "customers", label: "Customers", icon: "i-users" },
22
- { id: "fulfillment", label: "Fulfillment", icon: "i-truck" },
23
- { id: "reporting", label: "Reporting", icon: "i-chart" },
24
- { id: "ai-workflows", label: "AI Workflows", icon: "i-workflows" },
25
- { id: "blog", label: "Blog", icon: "i-file" },
26
- { id: "messages", label: "Messages", icon: "i-user" },
27
- { id: "publish", label: "Publish", icon: "i-export" },
28
- { id: "integrations", label: "Integrations", icon: "i-workflows" },
29
- { id: "settings", label: "Settings", icon: "i-gear" },
30
- ],
31
- defaultTabs: { staff: "orders", merchant: "settings" },
32
- } as const;
33
-
34
- declare global {
35
- interface Window {
36
- __toTAdminAsk?: AskEnvelope;
37
- }
38
- }
39
-
40
- export function initAdminShell(): void {
41
- const tabIds = ADMIN_SHELL_CONFIG.workAreas.map(({ id }) => id);
42
- const tabSet = new Set<string>(tabIds);
43
- const tabHashPattern = new RegExp(`^#(${tabIds.join("|")})$`);
44
- const canViewInternalGuide =
45
- document.documentElement.dataset.internalAdminGuide === "true";
46
- const defaultTab =
47
- ADMIN_SHELL_CONFIG.defaultTabs[canViewInternalGuide ? "staff" : "merchant"];
48
-
49
- const buildAskEnvelopeForTab = (id: string): AskEnvelope => {
50
- const root = document.documentElement.dataset;
51
- const isStaff = root.adminIsStaff === "true";
52
- const panel = document.getElementById(id);
53
- const selectedRecordId =
54
- panel?.querySelector<HTMLElement>("[data-admin-selected-id]")?.dataset
55
- .adminSelectedId || null;
56
-
57
- return buildAskEnvelope({
58
- tenant: {
59
- adminAppTenant: root.adminAppTenant ?? "",
60
- targetTenant: root.adminTargetTenant ?? "",
61
- operator: root.adminOperator || null,
62
- },
63
- isStaff,
64
- activeTab: id,
65
- selectedRecordId,
66
- });
67
- };
68
-
69
- const setAskContext = (id: string): void => {
70
- const label =
71
- ADMIN_SHELL_CONFIG.workAreas.find((area) => area.id === id)?.label ??
72
- "Storefront";
73
- const askButton = document.querySelector<HTMLElement>("[data-admin-ask]");
74
- const askContext = document.querySelector<HTMLElement>(
75
- "[data-admin-ask-context]",
76
- );
77
-
78
- if (askContext) askContext.textContent = label;
79
- if (askButton) {
80
- askButton.setAttribute("aria-label", `Ask about ${label}`);
81
- askButton.setAttribute("title", `Ask about ${label}`);
82
- askButton.dataset.askScope = id;
83
- }
84
-
85
- window.__toTAdminAsk = buildAskEnvelopeForTab(id);
86
- };
87
-
88
- const panelIdFromHash = (): string | null => {
89
- const rawHash = window.location.hash.slice(1);
90
- // The tab id is the part before any "?" query suffix (#publish?pr=42);
91
- // the raw hash is still used for internal-guide anchor resolution.
92
- const hash = rawHash.split("?")[0] ?? "";
93
- if (!rawHash) return defaultTab;
94
- if (tabSet.has(hash)) return hash;
95
- if (!canViewInternalGuide) return defaultTab;
96
-
97
- const target = rawHash ? document.getElementById(rawHash) : null;
98
- const panel = target?.closest<HTMLElement>("[data-admin-panel]");
99
- if (panel?.id && tabSet.has(panel.id)) return panel.id;
100
-
101
- return null;
102
- };
103
-
104
- const setActiveTab = (id: string): void => {
105
- if (!tabSet.has(id)) return;
106
-
107
- document.documentElement.dataset.adminMode = "work-area";
108
- document.documentElement.dataset.adminTab = id;
109
- setAskContext(id);
110
-
111
- document.querySelectorAll<HTMLElement>("[data-admin-panel]").forEach((panel) => {
112
- const active = panel.id === id;
113
- panel.hidden = !active;
114
- panel.setAttribute("aria-hidden", active ? "false" : "true");
115
- });
116
-
117
- document
118
- .querySelectorAll<HTMLAnchorElement>("[data-admin-tab-link]")
119
- .forEach((link) => {
120
- const active = link.hash === `#${id}`;
121
- link.classList.toggle("active", active);
122
-
123
- if (link.getAttribute("role") === "tab") {
124
- link.setAttribute("aria-selected", active ? "true" : "false");
125
- link.tabIndex = active ? 0 : -1;
126
- }
127
- });
128
- };
129
-
130
- const setGuideMode = (): void => {
131
- if (!canViewInternalGuide) {
132
- setActiveTab(defaultTab);
133
- return;
134
- }
135
-
136
- document.documentElement.dataset.adminMode = "guide";
137
- setAskContext(defaultTab);
138
-
139
- document.querySelectorAll<HTMLElement>("[data-admin-panel]").forEach((panel) => {
140
- panel.hidden = true;
141
- panel.setAttribute("aria-hidden", "true");
142
- });
143
-
144
- document
145
- .querySelectorAll<HTMLAnchorElement>("[data-admin-tab-link]")
146
- .forEach((link) => {
147
- link.classList.remove("active");
148
-
149
- if (link.getAttribute("role") === "tab") {
150
- link.setAttribute("aria-selected", "false");
151
- link.tabIndex = 0;
152
- }
153
- });
154
- };
155
-
156
- const scrollWorkspaceToTop = (): void => {
157
- const scroller = document.querySelector<HTMLElement>(".main");
158
- const reset = (): void => {
159
- if (scroller) {
160
- scroller.scrollTo({ top: 0, left: 0 });
161
- return;
162
- }
163
-
164
- window.scrollTo({ top: 0, left: 0 });
165
- };
166
-
167
- reset();
168
- requestAnimationFrame(reset);
169
- setTimeout(reset, 0);
170
- };
171
-
172
- const scrollToHashTarget = (panelId: string): void => {
173
- const hash = window.location.hash.slice(1);
174
- const target = hash ? document.getElementById(hash) : null;
175
-
176
- if (!target || tabSet.has(hash) || target.id === panelId) {
177
- scrollWorkspaceToTop();
178
- return;
179
- }
180
-
181
- target?.scrollIntoView({ block: "start" });
182
- };
183
-
184
- const activateFromHash = ({ scroll = false }: { scroll?: boolean } = {}): void => {
185
- const panelId = panelIdFromHash();
186
-
187
- if (panelId) {
188
- setActiveTab(panelId);
189
- // Strip any query suffix before deciding whether the hash names a
190
- // real tab — a valid deep link like #publish?pr=42 must not be
191
- // normalized away to #settings for merchant viewers.
192
- const hashTab = window.location.hash.slice(1).split("?")[0] ?? "";
193
- if (!canViewInternalGuide && !tabSet.has(hashTab)) {
194
- history.replaceState(null, "", `#${defaultTab}`);
195
- }
196
- if (scroll) requestAnimationFrame(() => scrollToHashTarget(panelId));
197
- return;
198
- }
199
-
200
- setGuideMode();
201
- if (scroll) {
202
- const hash = window.location.hash.slice(1);
203
- requestAnimationFrame(() =>
204
- document.getElementById(hash)?.scrollIntoView({ block: "start" }),
205
- );
206
- }
207
- };
208
-
209
- document
210
- .querySelector<HTMLSelectElement>("[data-admin-tenant-picker-select]")
211
- ?.addEventListener("change", (event) => {
212
- const params = new URLSearchParams(window.location.search);
213
- params.set("asTenant", (event.target as HTMLSelectElement).value);
214
- window.location.assign(
215
- `${window.location.pathname}?${params}${window.location.hash}`,
216
- );
217
- });
218
-
219
- // Emit the Ask envelope on open. No chat backend yet — dev-inspectable
220
- // only via window.__toTAdminAsk (already kept current by setAskContext)
221
- // and this "tot:admin-ask" CustomEvent.
222
- document.querySelector("[data-admin-ask]")?.addEventListener("click", () => {
223
- const activeTab = document.documentElement.dataset.adminTab ?? defaultTab;
224
- const envelope = buildAskEnvelopeForTab(activeTab);
225
- window.__toTAdminAsk = envelope;
226
- document.dispatchEvent(new CustomEvent("tot:admin-ask", { detail: envelope }));
227
- });
228
-
229
- document.addEventListener("click", (event) => {
230
- const target =
231
- event.target instanceof Element
232
- ? event.target
233
- : (event.target as Node | null)?.parentElement ?? null;
234
- const link = target?.closest<HTMLAnchorElement>("a[href^='#']");
235
- if (!link || !tabHashPattern.test(link.hash)) return;
236
-
237
- event.preventDefault();
238
- const id = link.hash.slice(1);
239
- setActiveTab(id);
240
- history.pushState(null, "", link.hash);
241
- scrollWorkspaceToTop();
242
- });
243
-
244
- document.addEventListener("keydown", (event) => {
245
- const target = event.target instanceof Element ? event.target : null;
246
- const currentTab = target?.closest<HTMLElement>(
247
- "[role='tab'][data-admin-tab-link]",
248
- );
249
- if (!currentTab) return;
250
-
251
- // Filter to visible tabs only: the mobile tab bar and the internal
252
- // Admin Tab Map can both be present in the DOM at once (one hidden
253
- // via CSS depending on viewport/viewer), and this selector matches
254
- // role="tab" elements in either — without this filter, arrow/home/
255
- // end navigation could walk into a display:none tablist whose
256
- // .focus() is a silent no-op.
257
- const tabs = Array.from(
258
- document.querySelectorAll<HTMLElement>("[role='tab'][data-admin-tab-link]"),
259
- ).filter((el) => el.offsetParent !== null);
260
- const currentIndex = tabs.indexOf(currentTab);
261
- let nextIndex = currentIndex;
262
-
263
- if (event.key === "ArrowRight") nextIndex = (currentIndex + 1) % tabs.length;
264
- if (event.key === "ArrowLeft")
265
- nextIndex = (currentIndex - 1 + tabs.length) % tabs.length;
266
- if (event.key === "Home") nextIndex = 0;
267
- if (event.key === "End") nextIndex = tabs.length - 1;
268
-
269
- if (nextIndex === currentIndex) return;
270
-
271
- const nextTab = tabs[nextIndex];
272
- if (!nextTab) return;
273
-
274
- event.preventDefault();
275
- nextTab.focus();
276
- nextTab.click();
277
- });
278
-
279
- window.addEventListener("hashchange", () => activateFromHash({ scroll: true }));
280
- activateFromHash({ scroll: Boolean(window.location.hash) });
281
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * Canonical tenant envelope for the admin console lives in
3
- * `lib/access/shared/adminTenantEnvelope.ts` (admin-tenant-mode) — it carries the real
4
- * staff-override authorization (`resolveAdminTenantMode`) that admin.astro
5
- * actually runs. This module re-exports that type so every mock service under
6
- * `lib/admin/**` can keep importing it from a stable relative path
7
- * (`../../envelope`) without declaring a second, competing interface.
8
- */
9
- export type { AdminTenantEnvelope } from "@/lib/access/shared/adminTenantEnvelope";
@@ -1,64 +0,0 @@
1
- /**
2
- * Settings view model (baseline §Settings) — admin policy, AI guardrails,
3
- * regulated storefront policy, and audited changes. `ApprovalMode` and
4
- * `SettingsAuditEvent` reuse the canonical substrate types from
5
- * `lib/admin/ai` (ai-evidence-substrate) now that both domains live in the
6
- * same lib/admin/** area.
7
- */
8
-
9
- import type { CheckoutStyle } from "@tot/public-runtime";
10
- import type { ApprovalMode } from "../../../automation/ai/approvalMode";
11
- import type { AuditEvent } from "../../../automation/ai/audit";
12
-
13
- export type { ApprovalMode };
14
- export type { CheckoutStyle };
15
-
16
- export type SettingsSectionKey =
17
- | "store"
18
- | "checkout"
19
- | "cart_appearance"
20
- | "payments"
21
- | "shipping"
22
- | "taxes"
23
- | "products"
24
- | "customers"
25
- | "notifications"
26
- | "users_access"
27
- | "integrations"
28
- | "compliance"
29
- | "ai_admin_policy";
30
-
31
- export interface SettingsSection {
32
- key: SettingsSectionKey;
33
- label: string;
34
- summary: string;
35
- riskyChangeReview: boolean;
36
- }
37
-
38
- export interface ShippingRestriction {
39
- region: string;
40
- reason: string;
41
- }
42
-
43
- export interface SettingsAuditEvent extends AuditEvent {
44
- /** Human-readable summary of what changed — `AuditEvent.action` is the machine-facing form. */
45
- change: string;
46
- }
47
-
48
- export interface SettingsViewModel {
49
- targetTenant: string;
50
- sections: SettingsSection[];
51
- shippingRestrictions: ShippingRestriction[];
52
- aiPolicyMode: ApprovalMode;
53
- internalTenantPickerEnabled: boolean;
54
- auditTrail: SettingsAuditEvent[];
55
- /**
56
- * The target tenant's current checkout styling — the editable descriptor the
57
- * "Checkout styling" section renders in its editor and saves back through
58
- * the versioned publish spine (`POST /api/admin/checkout-style` →
59
- * `publishToTest` on `tenants/<id>/checkout-style.json`). Always a complete
60
- * `CheckoutStyle` (the resolved default merged with any published override), so
61
- * the editor never has to reason about missing fields.
62
- */
63
- checkoutStyle: CheckoutStyle;
64
- }