@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,639 +0,0 @@
1
- /**
2
- * The note composer: intent, title, description, impact and an optional suggested fix, then a
3
- * review of exactly what will be sent (after local redaction), then a send through the host's
4
- * injected transport.
5
- *
6
- * Draft state lives in memory only. The submission id is minted once at the first send and reused
7
- * on retry, so a retry can never create a duplicate. The composer renders into a container the
8
- * caller owns (typically the dialog body) and writes all dynamic text with `textContent`.
9
- *
10
- * A host extends the form through `ComposerOptions` hooks (intent helper fields, copy, notices,
11
- * footer, received-screen content, exact-data view) and reads state through `phase`, `hasDraft`
12
- * and `onChange`. It never reaches into the DOM the composer builds.
13
- */
14
- import type {
15
- FeedbackActionV1,
16
- FeedbackImpact,
17
- FeedbackIntent,
18
- FeedbackReport,
19
- RedactionCounts,
20
- SubmissionReceiptV1,
21
- TargetEvidenceV1,
22
- } from "../v1/types.js";
23
- import type { FeedbackTransport, HostAdapter, SanitizedReportV1 } from "./hostAdapter.js";
24
- import { mergeCounts, PII_LIMITATION_NOTICE, redactText, describeRedactions } from "./redaction.js";
25
- import { h } from "./surface.js";
26
- import { browserFamily } from "./target.js";
27
-
28
- export const TITLE_MIN = 3;
29
- export const TITLE_MAX = 200;
30
- export const DESCRIPTION_MIN = 3;
31
- export const DESCRIPTION_MAX = 4000;
32
- export const SUGGESTED_FIX_MAX = 2000;
33
- /** Each intent helper field is folded into the description, which is capped at DESCRIPTION_MAX anyway. */
34
- export const HELPER_FIELD_MAX = 2000;
35
-
36
- export const INTENT_CHOICES: readonly { intent: FeedbackIntent; label: string; defaultImpact: FeedbackImpact }[] = [
37
- { intent: "problem", label: "Report a problem", defaultImpact: "medium" },
38
- { intent: "improvement", label: "Suggest an improvement", defaultImpact: "low" },
39
- { intent: "feature", label: "Request a feature", defaultImpact: "low" },
40
- { intent: "comment", label: "Leave a comment", defaultImpact: "low" },
41
- ];
42
-
43
- export const IMPACT_CHOICES: readonly { value: FeedbackImpact; label: string }[] = [
44
- { value: "low", label: "Minor" },
45
- { value: "medium", label: "Gets in the way" },
46
- { value: "high", label: "I cannot continue" },
47
- { value: "critical", label: "Critical" },
48
- ];
49
-
50
- export interface IntentField {
51
- key: string;
52
- label: string;
53
- }
54
-
55
- export interface ComposerDraft {
56
- intent: FeedbackIntent;
57
- impact: FeedbackImpact;
58
- title: string;
59
- /** True once the reviewer typed into the title; stops auto-suggestion. */
60
- titleEdited: boolean;
61
- /** The free-form "What would you like us to know?" text. */
62
- description: string;
63
- /** Intent helper fields keyed by `IntentField.key`, folded into the description on send. */
64
- fields: Record<string, string>;
65
- suggestedFix: string;
66
- }
67
-
68
- export interface ReportProblems {
69
- title?: string;
70
- description?: string;
71
- suggestedFix?: string;
72
- }
73
-
74
- export function emptyDraft(intent: FeedbackIntent = "comment"): ComposerDraft {
75
- const spec = INTENT_CHOICES.find((c) => c.intent === intent) ?? (INTENT_CHOICES[3] as (typeof INTENT_CHOICES)[number]);
76
- return { intent, impact: spec.defaultImpact, title: "", titleEdited: false, description: "", fields: {}, suggestedFix: "" };
77
- }
78
-
79
- /** The description that is sent: the free-form text, then each non-empty helper field under its label. */
80
- export function assembleDescription(d: ComposerDraft, fieldSpec: readonly IntentField[] = []): string {
81
- const parts: string[] = [];
82
- const body = d.description.trim();
83
- if (body) parts.push(body);
84
- for (const field of fieldSpec) {
85
- const value = (d.fields[field.key] ?? "").trim();
86
- if (value) parts.push(`${field.label}:\n${value}`);
87
- }
88
- return parts.join("\n\n");
89
- }
90
-
91
- /** A title suggested from the reviewer's own words (first sentence or line), never from the page. */
92
- export function suggestTitle(description: string): string {
93
- const source = description.replace(/^[^:\n]+:\n/, "");
94
- const first = source.trim().split(/(?<=[.!?])\s|\n/)[0]?.trim() ?? "";
95
- return first.length <= TITLE_MAX ? first : `${first.slice(0, TITLE_MAX - 1).trimEnd()}…`;
96
- }
97
-
98
- export function effectiveTitle(d: ComposerDraft, fieldSpec: readonly IntentField[] = []): string {
99
- return d.titleEdited ? d.title : d.title || suggestTitle(assembleDescription(d, fieldSpec));
100
- }
101
-
102
- export function validateReport(title: string, description: string, suggestedFix: string): ReportProblems {
103
- const problems: ReportProblems = {};
104
- if (title.trim().length < TITLE_MIN) problems.title = `Add a title of at least ${TITLE_MIN} characters.`;
105
- else if (title.length > TITLE_MAX) problems.title = `Keep the title under ${TITLE_MAX} characters.`;
106
- if (description.trim().length < DESCRIPTION_MIN) {
107
- problems.description = `Tell us a little more (at least ${DESCRIPTION_MIN} characters).`;
108
- } else if (description.length > DESCRIPTION_MAX) {
109
- problems.description = `The report is ${description.length} of ${DESCRIPTION_MAX} characters; shorten it.`;
110
- }
111
- if (suggestedFix.length > SUGGESTED_FIX_MAX) {
112
- problems.suggestedFix = `Keep the suggested fix under ${SUGGESTED_FIX_MAX} characters.`;
113
- }
114
- return problems;
115
- }
116
-
117
- export interface SanitizedReport {
118
- report: FeedbackReport;
119
- counts: RedactionCounts;
120
- }
121
-
122
- /** Run local redaction over every reviewer-authored string. Pure and deterministic. */
123
- export function sanitizeDraft(d: ComposerDraft, fieldSpec: readonly IntentField[] = []): SanitizedReport {
124
- const title = redactText(effectiveTitle(d, fieldSpec));
125
- const description = redactText(assembleDescription(d, fieldSpec));
126
- const fix = redactText(d.suggestedFix);
127
- const report: FeedbackReport = {
128
- intent: d.intent,
129
- impact: d.impact,
130
- title: title.text,
131
- description: description.text,
132
- };
133
- if (fix.text) report.suggestedFix = fix.text;
134
- return { report, counts: mergeCounts(title.counts, description.counts, fix.counts) };
135
- }
136
-
137
- function newSubmissionId(cryptoImpl: Crypto | undefined): string {
138
- if (cryptoImpl && typeof cryptoImpl.randomUUID === "function") return cryptoImpl.randomUUID();
139
- const bytes = new Uint8Array(16);
140
- if (cryptoImpl) cryptoImpl.getRandomValues(bytes);
141
- else for (let i = 0; i < 16; i += 1) bytes[i] = Math.floor(Math.random() * 256);
142
- bytes[6] = ((bytes[6] as number) & 0x0f) | 0x40;
143
- bytes[8] = ((bytes[8] as number) & 0x3f) | 0x80;
144
- const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
145
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
146
- }
147
-
148
- export type ComposerPhase = "composing" | "reviewing" | "submitting" | "retryable" | "conflict" | "received";
149
-
150
- export interface ComposerCopy {
151
- /** The sentence shown for a retryable failure code; the default says the report may not have arrived. */
152
- retry?(code: string): string | undefined;
153
- /** The message shown for a refused (non-retryable) code. */
154
- refused?(code: string): string | undefined;
155
- /** Label of the primary send button on the review screen. Default "Send". */
156
- send?: string;
157
- }
158
-
159
- export interface ComposerOptions {
160
- win: Window;
161
- doc: Document;
162
- adapter?: HostAdapter;
163
- /** Where the form renders; the caller owns it. */
164
- container: HTMLElement;
165
- /** `^[a-z0-9][a-z0-9.-]{0,31}$`; identifies the host's capture policy. */
166
- capturePolicyVersion: string;
167
- /** Overrides `adapter.transport`. */
168
- transport?: FeedbackTransport;
169
- /** Intent a fresh draft starts on. Default `comment`. */
170
- defaultIntent?: FeedbackIntent;
171
- /** Helper fields offered for an intent; each non-empty one is folded into the description. */
172
- intentFields?(intent: FeedbackIntent): readonly IntentField[];
173
- copy?: ComposerCopy;
174
- /** A notice shown above the form while it returns text (for example, a newer version is available). */
175
- notice?(): string | null | undefined;
176
- /** Nodes appended at the end of the compose and review screens. */
177
- footer?(phase: ComposerPhase): readonly Node[];
178
- /** Content appended to the received screen, after the reference. */
179
- renderReceived?(body: HTMLElement, receipt: SubmissionReceiptV1, ctx: { action: FeedbackActionV1 }): void;
180
- /** The exact data of an action, for the "Included context" disclosure on the review screen. */
181
- exactData?(action: FeedbackActionV1): string | undefined;
182
- /** Fires after every render and reset, so a host can mirror phase and draft state. */
183
- onChange?(): void;
184
- onSubmitted?(receipt: SubmissionReceiptV1): void;
185
- /** Reviewer pressed Discard. The composer has already cleared its draft. */
186
- onDiscard?(): void;
187
- /** Reviewer pressed Reselect. */
188
- onReselect?(): void;
189
- /**
190
- * One-click target widening: the host re-targets the draft (via `setTarget`) to the containing
191
- * element or back toward the original pick. The buttons show only while `adjustable` returns true.
192
- */
193
- onLarger?(): void;
194
- onSmaller?(): void;
195
- adjustable?(): boolean;
196
- }
197
-
198
- export interface Composer {
199
- /** Begin (or retarget) a draft against this evidence. `label` is the picker's orientation label. */
200
- setTarget(evidence: TargetEvidenceV1, label: string): void;
201
- render(): void;
202
- readonly phase: ComposerPhase;
203
- /** True once a target is chosen and until the draft is discarded or sent. */
204
- readonly hasDraft: boolean;
205
- /** True while an attempt is in flight, unresolved or conflicted: the draft may not change. */
206
- readonly frozen: boolean;
207
- /** The draft as typed (not yet redacted). */
208
- readonly draft: ComposerDraft;
209
- /** The exact action that would be sent, or the problems preventing it. */
210
- buildAction(): { action: FeedbackActionV1; counts: RedactionCounts } | { problems: ReportProblems };
211
- /** Send (or retry) through the transport. Resolves once the outcome is rendered. */
212
- send(): Promise<void>;
213
- /** Clear the draft and render nothing. */
214
- reset(): void;
215
- destroy(): void;
216
- }
217
-
218
- export function createComposer(options: ComposerOptions): Composer {
219
- const { win, doc, container, adapter } = options;
220
- const fieldsFor = (intent: FeedbackIntent): readonly IntentField[] => options.intentFields?.(intent) ?? [];
221
- let phase: ComposerPhase = "composing";
222
- let draft = emptyDraft(options.defaultIntent);
223
- let evidence: TargetEvidenceV1 | null = null;
224
- let targetLabel = "";
225
- let error: string | undefined;
226
- let retry: { code: string; retryAfterSeconds?: number } | null = null;
227
- let conflictCode: string | null = null;
228
- let receipt: SubmissionReceiptV1 | null = null;
229
- let sentAction: FeedbackActionV1 | null = null;
230
- let serverReview: { policyVersion: string; redactions: Record<string, number> } | undefined;
231
- /** Frozen at the first send; every retry sends exactly this. */
232
- let frozen: FeedbackActionV1 | null = null;
233
- let controller: AbortController | null = null;
234
- let destroyed = false;
235
-
236
- const button = (label: string, onClick: () => void, extra: Record<string, string> = {}) => {
237
- const b = h(doc, "button", { type: "button", text: label, ...extra });
238
- b.addEventListener("click", (e) => {
239
- e.preventDefault();
240
- onClick();
241
- });
242
- return b;
243
- };
244
-
245
- function field(id: string, labelText: string, control: HTMLElement) {
246
- control.id = id;
247
- return h(doc, "div", {}, h(doc, "label", { for: id, text: labelText }), control);
248
- }
249
-
250
- const editable = () => frozen === null;
251
-
252
- function noticeNode(): HTMLElement | null {
253
- const text = options.notice?.();
254
- return text ? h(doc, "div", { class: "notice", role: "status", text }) : null;
255
- }
256
-
257
- function footerNodes(): Node[] {
258
- return [...(options.footer?.(phase) ?? [])];
259
- }
260
-
261
- function renderCompose(body: HTMLElement) {
262
- const live = editable();
263
- body.append(
264
- h(
265
- doc,
266
- "div",
267
- { class: "target" },
268
- h(doc, "div", { text: `Selected: ${targetLabel || "Whole page"}` }),
269
- ...(live && options.adjustable?.() && options.onLarger && options.onSmaller
270
- ? [
271
- button("Larger", () => options.onLarger?.(), { "aria-label": "Select the larger containing area" }),
272
- button("Smaller", () => options.onSmaller?.(), { "aria-label": "Go back toward the element you picked" }),
273
- ]
274
- : []),
275
- button("Reselect", () => options.onReselect?.()),
276
- ),
277
- );
278
- const fieldset = h(doc, "fieldset", {}, h(doc, "legend", { text: "What kind of feedback?" }));
279
- const grid = h(doc, "div", { class: "intents" });
280
- for (const spec of INTENT_CHOICES) {
281
- const radio = h(doc, "input", { type: "radio", name: "fb-intent", value: spec.intent, checked: spec.intent === draft.intent, disabled: !live });
282
- radio.addEventListener("change", () => {
283
- const prevDefault = INTENT_CHOICES.find((c) => c.intent === draft.intent)?.defaultImpact;
284
- draft.impact = draft.impact === prevDefault ? spec.defaultImpact : draft.impact;
285
- draft.intent = spec.intent;
286
- render();
287
- container.querySelector<HTMLElement>(`input[value="${spec.intent}"]`)?.focus();
288
- });
289
- grid.append(h(doc, "label", {}, radio, spec.label));
290
- }
291
- fieldset.append(grid);
292
- body.append(fieldset);
293
-
294
- const title = h(doc, "input", { type: "text", maxlength: String(TITLE_MAX), autocomplete: "off", spellcheck: "true" }) as HTMLInputElement;
295
- title.value = effectiveTitle(draft, fieldsFor(draft.intent));
296
- title.disabled = !live;
297
- title.addEventListener("input", () => {
298
- draft.title = title.value;
299
- draft.titleEdited = true;
300
- });
301
- const description = h(doc, "textarea", { rows: "4", maxlength: String(DESCRIPTION_MAX) }) as HTMLTextAreaElement;
302
- description.value = draft.description;
303
- description.disabled = !live;
304
- const counter = h(doc, "div", { class: "muted", "aria-live": "polite" });
305
- const updateCounter = () => {
306
- const n = assembleDescription(draft, fieldsFor(draft.intent)).length;
307
- counter.textContent = `Report length ${n} / ${DESCRIPTION_MAX}`;
308
- counter.classList.toggle("error", n > DESCRIPTION_MAX);
309
- if (!draft.titleEdited) title.value = effectiveTitle(draft, fieldsFor(draft.intent));
310
- };
311
- description.addEventListener("input", () => {
312
- draft.description = description.value;
313
- updateCounter();
314
- });
315
- body.append(field("fb-title", "Short title", title), field("fb-description", "What would you like us to know?", description));
316
- for (const f of fieldsFor(draft.intent)) {
317
- const ta = h(doc, "textarea", { rows: "2", maxlength: String(HELPER_FIELD_MAX) }) as HTMLTextAreaElement;
318
- ta.value = draft.fields[f.key] ?? "";
319
- ta.disabled = !live;
320
- ta.addEventListener("input", () => {
321
- draft.fields[f.key] = ta.value;
322
- updateCounter();
323
- });
324
- body.append(field(`fb-f-${f.key}`, `${f.label} (optional)`, ta));
325
- }
326
-
327
- const impact = h(doc, "select") as HTMLSelectElement;
328
- for (const c of IMPACT_CHOICES) impact.append(h(doc, "option", { value: c.value, text: c.label, selected: c.value === draft.impact }));
329
- impact.disabled = !live;
330
- impact.addEventListener("change", () => {
331
- draft.impact = impact.value as FeedbackImpact;
332
- });
333
- const fix = h(doc, "textarea", { rows: "2", maxlength: String(SUGGESTED_FIX_MAX) }) as HTMLTextAreaElement;
334
- fix.value = draft.suggestedFix;
335
- fix.disabled = !live;
336
- fix.addEventListener("input", () => {
337
- draft.suggestedFix = fix.value;
338
- });
339
- body.append(field("fb-impact", "Impact", impact), field("fb-fix", "Suggested fix (optional)", fix), counter);
340
- updateCounter();
341
- if (error) body.append(h(doc, "p", { class: "error", role: "alert", text: error }));
342
- body.append(...footerNodes());
343
- body.append(
344
- h(
345
- doc,
346
- "div",
347
- { class: "actions" },
348
- button("Discard", () => discard()),
349
- button("Review what will be sent", () => {
350
- error = undefined;
351
- const result = composer.buildAction();
352
- if ("problems" in result) {
353
- error = result.problems.title ?? result.problems.description ?? result.problems.suggestedFix;
354
- } else phase = "reviewing";
355
- render();
356
- }, { class: "primary" }),
357
- ),
358
- );
359
- }
360
-
361
- function renderReview(body: HTMLElement) {
362
- const result = composer.buildAction();
363
- if ("problems" in result) {
364
- phase = "composing";
365
- error = result.problems.title ?? result.problems.description ?? result.problems.suggestedFix;
366
- renderCompose(body);
367
- return;
368
- }
369
- const { action, counts } = result;
370
- if (serverReview) {
371
- body.append(
372
- h(doc, "p", {
373
- class: "notice",
374
- role: "alert",
375
- text: "Token of Trust's privacy filter changed some of your text. Nothing was stored. Review the filtered version below and send it only if it is right.",
376
- }),
377
- );
378
- }
379
- body.append(h(doc, "p", { class: "muted", text: PII_LIMITATION_NOTICE }));
380
- const removed = describeRedactions(mergeCounts(counts, (serverReview?.redactions ?? {}) as RedactionCounts));
381
- if (removed) body.append(h(doc, "p", { class: "ok", text: removed }));
382
- const dl = h(doc, "dl");
383
- const row = (k: string, v: string) => dl.append(h(doc, "dt", { text: k }), h(doc, "dd", { text: v }));
384
- row("Type", INTENT_CHOICES.find((c) => c.intent === action.report.intent)?.label ?? action.report.intent);
385
- row("Impact", IMPACT_CHOICES.find((c) => c.value === action.report.impact)?.label ?? action.report.impact);
386
- row("Title", action.report.title);
387
- row("Description", action.report.description);
388
- if (action.report.suggestedFix) row("Suggested fix", action.report.suggestedFix);
389
- row("Target", `${action.evidence.target.kind} (${action.evidence.target.precision})`);
390
- if (action.evidence.selection?.excerpt) row("Selected text", action.evidence.selection.excerpt.text);
391
- body.append(h(doc, "div", { class: "review" }, dl));
392
- const exact = options.exactData?.(action);
393
- if (exact !== undefined) {
394
- body.append(h(doc, "details", {}, h(doc, "summary", { text: "Included context (exact data)" }), h(doc, "pre", { text: exact })));
395
- }
396
- if (serverReview) {
397
- body.append(h(doc, "p", { class: "notice", text: "This is the version Token of Trust's filter produced. Sending it starts a new submission." }));
398
- }
399
- body.append(...footerNodes());
400
- body.append(
401
- h(
402
- doc,
403
- "div",
404
- { class: "actions" },
405
- button("Edit", () => {
406
- phase = "composing";
407
- render();
408
- }),
409
- button(serverReview ? "Send this version" : (options.copy?.send ?? "Send"), () => {
410
- if (serverReview) {
411
- serverReview = undefined;
412
- frozen = null;
413
- }
414
- void send();
415
- }, { class: "primary" }),
416
- ),
417
- );
418
- }
419
-
420
- function render() {
421
- if (destroyed) return;
422
- container.replaceChildren();
423
- if (!evidence) {
424
- options.onChange?.();
425
- return;
426
- }
427
- const body = h(doc, "div", { class: "composer" });
428
- container.append(body);
429
- const notice = phase === "received" ? null : noticeNode();
430
- if (notice) body.append(notice);
431
- if (phase === "composing") renderCompose(body);
432
- else if (phase === "reviewing") renderReview(body);
433
- else if (phase === "submitting") body.append(h(doc, "p", { role: "status", text: "Sending…" }));
434
- else if (phase === "retryable" && retry) {
435
- const wait = retry.retryAfterSeconds ? ` Try again in about ${retry.retryAfterSeconds} seconds.` : "";
436
- body.append(
437
- h(doc, "p", { class: "error", role: "alert", text: `${options.copy?.retry?.(retry.code) ?? "We could not confirm that your report arrived."}${wait}` }),
438
- h(doc, "p", { class: "muted", text: "Your report is kept exactly as it was sent and may already have arrived. Retry sends the same report again; it will not create a duplicate." }),
439
- h(doc, "div", { class: "actions" }, button("Discard", () => discard()), button("Retry", () => void send(), { class: "primary" })),
440
- );
441
- } else if (phase === "conflict") {
442
- body.append(
443
- h(doc, "p", {
444
- class: "error",
445
- role: "alert",
446
- text: `Token of Trust already has a different report under this submission (${conflictCode ?? "conflict"}). It was not resubmitted.`,
447
- }),
448
- h(
449
- doc,
450
- "div",
451
- { class: "actions" },
452
- button("Discard", () => discard()),
453
- button("Start a new report from this text", () => {
454
- frozen = null;
455
- conflictCode = null;
456
- phase = "composing";
457
- render();
458
- }),
459
- ),
460
- );
461
- } else if (phase === "received" && receipt) {
462
- body.append(
463
- h(doc, "p", { class: "ok", role: "status", text: "Feedback received." }),
464
- h(doc, "p", { text: `Reference: ${receipt.feedbackId}` }),
465
- );
466
- if (sentAction) options.renderReceived?.(body, receipt, { action: sentAction });
467
- body.append(h(doc, "div", { class: "actions" }, button("Done", () => discard(), { class: "primary" })));
468
- }
469
- focusFirst();
470
- options.onChange?.();
471
- }
472
-
473
- function focusFirst() {
474
- const root = container.getRootNode() as Document | ShadowRoot;
475
- const active = root.activeElement;
476
- if (active && container.contains(active)) return;
477
- const first = container.querySelector<HTMLElement>("input:not([disabled]), textarea:not([disabled]), button:not([disabled]), [role=alert]");
478
- if (first) {
479
- if (first.getAttribute("role") === "alert") first.setAttribute("tabindex", "-1");
480
- first.focus();
481
- }
482
- }
483
-
484
- function discard() {
485
- controller?.abort();
486
- controller = null;
487
- composer.reset();
488
- options.onDiscard?.();
489
- }
490
-
491
- function applyNeedsReview(sanitized: SanitizedReportV1, policyVersion: string, redactions: Record<string, number>) {
492
- draft = {
493
- ...draft,
494
- intent: sanitized.intent,
495
- impact: sanitized.impact,
496
- title: sanitized.title,
497
- titleEdited: true,
498
- description: sanitized.description,
499
- fields: {},
500
- suggestedFix: sanitized.suggestedFix ?? "",
501
- };
502
- serverReview = { policyVersion, redactions };
503
- frozen = null;
504
- retry = null;
505
- phase = "reviewing";
506
- }
507
-
508
- async function send() {
509
- if (phase === "submitting" || phase === "conflict") return;
510
- if (!frozen) {
511
- const built = composer.buildAction();
512
- if ("problems" in built) {
513
- phase = "composing";
514
- error = built.problems.title ?? built.problems.description ?? built.problems.suggestedFix;
515
- render();
516
- return;
517
- }
518
- frozen = built.action;
519
- }
520
- const transport = options.transport ?? adapter?.transport;
521
- if (!transport) {
522
- phase = "composing";
523
- frozen = null;
524
- error = "Sending is not available on this page.";
525
- render();
526
- return;
527
- }
528
- phase = "submitting";
529
- render();
530
- controller = new AbortController();
531
- let result: Awaited<ReturnType<FeedbackTransport>>;
532
- const attempt = frozen;
533
- try {
534
- result = await transport(attempt, { signal: controller.signal });
535
- } catch {
536
- result = { ok: false, code: "network_error", retryable: true };
537
- }
538
- if (destroyed || phase !== "submitting") return;
539
- if (result.ok) {
540
- receipt = result.receipt;
541
- sentAction = attempt;
542
- frozen = null;
543
- phase = "received";
544
- render();
545
- options.onSubmitted?.(result.receipt);
546
- return;
547
- }
548
- if (result.outcome === "needs_review") {
549
- applyNeedsReview(result.sanitized, result.policyVersion, result.redactions);
550
- } else if (result.outcome === "conflict") {
551
- conflictCode = result.code;
552
- phase = "conflict";
553
- } else if (result.retryable) {
554
- retry = { code: result.code, ...(result.retryAfterSeconds !== undefined ? { retryAfterSeconds: result.retryAfterSeconds } : {}) };
555
- phase = "retryable";
556
- } else {
557
- frozen = null;
558
- phase = "composing";
559
- error = options.copy?.refused?.(result.code) ?? `This report was refused (${result.code}). Nothing was stored; you can edit and send again.`;
560
- }
561
- render();
562
- }
563
-
564
- const composer: Composer = {
565
- setTarget(next, label) {
566
- evidence = next;
567
- targetLabel = label;
568
- if (phase === "received" || phase === "retryable" || phase === "submitting" || phase === "conflict") {
569
- controller?.abort();
570
- if (phase === "received") draft = emptyDraft(options.defaultIntent);
571
- frozen = null;
572
- retry = null;
573
- conflictCode = null;
574
- receipt = null;
575
- sentAction = null;
576
- serverReview = undefined;
577
- }
578
- phase = "composing";
579
- error = undefined;
580
- render();
581
- },
582
- render,
583
- get phase() {
584
- return phase;
585
- },
586
- get hasDraft() {
587
- return evidence !== null;
588
- },
589
- get frozen() {
590
- return frozen !== null && phase !== "received";
591
- },
592
- get draft() {
593
- return draft;
594
- },
595
- buildAction() {
596
- if (!evidence) return { problems: { description: "Select what the feedback is about first." } };
597
- const { report, counts } = sanitizeDraft(draft, fieldsFor(draft.intent));
598
- const problems = validateReport(report.title, report.description, report.suggestedFix ?? "");
599
- if (problems.title || problems.description || problems.suggestedFix) return { problems };
600
- const evidenceCounts = evidence.selection?.excerpt?.redactionCounts;
601
- const merged = mergeCounts(counts, evidenceCounts ?? {});
602
- const action: FeedbackActionV1 = {
603
- schemaVersion: "feedback.v1",
604
- kind: "feedback.action",
605
- submissionId: frozen?.submissionId ?? newSubmissionId(win.crypto),
606
- capturePolicyVersion: options.capturePolicyVersion,
607
- report,
608
- evidence,
609
- browser: browserFamily(win.navigator?.userAgent ?? ""),
610
- };
611
- if (Object.keys(merged).length > 0) action.redactionCounts = merged;
612
- return { action, counts: merged };
613
- },
614
- send,
615
- reset() {
616
- controller?.abort();
617
- controller = null;
618
- draft = emptyDraft(options.defaultIntent);
619
- evidence = null;
620
- targetLabel = "";
621
- error = undefined;
622
- retry = null;
623
- conflictCode = null;
624
- receipt = null;
625
- sentAction = null;
626
- serverReview = undefined;
627
- frozen = null;
628
- phase = "composing";
629
- container.replaceChildren();
630
- options.onChange?.();
631
- },
632
- destroy() {
633
- controller?.abort();
634
- destroyed = true;
635
- container.replaceChildren();
636
- },
637
- };
638
- return composer;
639
- }