@tokenoftrust/storefront-runner 1.4.2-rc.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/apps/storefront/astro.config.mjs +3 -3
  2. package/apps/storefront/dev-plugins/tenant-hot-reload.mjs +8 -3
  3. package/apps/storefront/env.d.ts +54 -5
  4. package/apps/storefront/integrations/materialize-guard.mjs +12 -14
  5. package/apps/storefront/migrations-apps/0004_deep_morph.sql +36 -0
  6. package/apps/storefront/migrations-apps/0005_common_mystique.sql +23 -0
  7. package/apps/storefront/migrations-apps/0006_broad_microchip.sql +16 -0
  8. package/apps/storefront/migrations-apps/0007_brave_outlaw_kid.sql +15 -0
  9. package/apps/storefront/migrations-apps/0008_blue_dazzler.sql +11 -0
  10. package/apps/storefront/migrations-apps/0009_bored_shinobi_shaw.sql +15 -0
  11. package/apps/storefront/migrations-apps/0010_ws4_verified_provider_measurement.sql +35 -0
  12. package/apps/storefront/migrations-apps/meta/0004_snapshot.json +1474 -0
  13. package/apps/storefront/migrations-apps/meta/0005_snapshot.json +1617 -0
  14. package/apps/storefront/migrations-apps/meta/0006_snapshot.json +1716 -0
  15. package/apps/storefront/migrations-apps/meta/0007_snapshot.json +1812 -0
  16. package/apps/storefront/migrations-apps/meta/0008_snapshot.json +1881 -0
  17. package/apps/storefront/migrations-apps/meta/0009_snapshot.json +1979 -0
  18. package/apps/storefront/migrations-apps/meta/_journal.json +42 -0
  19. package/apps/storefront/public/apps/tot.demo.analytics/0.1.0/entry.js +42 -0
  20. package/apps/storefront/public/platform/amplitude-http/v1/entry.mjs +19 -0
  21. package/apps/storefront/public/platform/google-measurement/v1/entry.mjs +19 -0
  22. package/apps/storefront/public/shared/commerce-chrome.css +20 -2
  23. package/apps/storefront/scripts/build-v84-clean-clone-standalone.mjs +68 -0
  24. package/apps/storefront/scripts/deny-v84-clean-clone-standalone-capabilities.mjs +111 -0
  25. package/apps/storefront/scripts/deny-v84-dogfood-capabilities.mjs +2 -0
  26. package/apps/storefront/scripts/deny-v84-lifecycle-capabilities.mjs +247 -0
  27. package/apps/storefront/scripts/dogfood-v84-nonportable-routes.ts +73 -0
  28. package/apps/storefront/scripts/fixed-v84-native-install-producer.ts +79 -0
  29. package/apps/storefront/scripts/generated/v84-clean-clone-replay.bundle.mjs +10982 -0
  30. package/apps/storefront/scripts/import-v84-through-ws2.ts +38 -0
  31. package/apps/storefront/scripts/initialize-v84-lifecycle-tooling-dependency.ts +2 -0
  32. package/apps/storefront/scripts/initialize-v84-lifecycle-tooling.ts +4 -0
  33. package/apps/storefront/scripts/install-v84-native-through-ws1.ts +185 -0
  34. package/apps/storefront/scripts/prove-clone-isolation.ts +506 -0
  35. package/apps/storefront/scripts/replay-v84-clean-clone-pass.ts +148 -0
  36. package/apps/storefront/scripts/replay-v84-clean-clone-standalone.ts +35 -0
  37. package/apps/storefront/scripts/replay-v84-clean-clone.ts +214 -0
  38. package/apps/storefront/scripts/run-fixed-v84-native-install-producer.mjs +18 -0
  39. package/apps/storefront/scripts/run-v84-clone-isolation-proof.mjs +18 -0
  40. package/apps/storefront/scripts/run-v84-clone-lifecycle-proof.mjs +18 -0
  41. package/apps/storefront/scripts/run-v84-import-through-ws2-proof.mjs +17 -0
  42. package/apps/storefront/scripts/run-v84-nonportable-route-dogfood.mjs +15 -0
  43. package/apps/storefront/scripts/sanitize-v84-proof-environment.mjs +21 -0
  44. package/apps/storefront/scripts/v84CleanCloneGraphPin.ts +42 -0
  45. package/apps/storefront/scripts/v84CleanCloneSourceGraph.ts +145 -0
  46. package/apps/storefront/scripts/validate-v84-clone-lifecycle.ts +18 -0
  47. package/apps/storefront/src/components/Img.astro +1 -1
  48. package/apps/storefront/src/components/admin/AdminBlogTab.astro +19 -16
  49. package/apps/storefront/src/components/admin/AdminIntegrationsTab.astro +105 -0
  50. package/apps/storefront/src/components/admin/AdminPublishTab.astro +1057 -412
  51. package/apps/storefront/src/components/admin/AdminSettingsTab.astro +2 -2
  52. package/apps/storefront/src/components/admin/orders/OrdersWorkspace.astro +5 -5
  53. package/apps/storefront/src/components/chrome/NavDropdown.astro +12 -0
  54. package/apps/storefront/src/components/chrome/SiteFooter.astro +7 -2
  55. package/apps/storefront/src/components/chrome/SiteHeader.astro +46 -10
  56. package/apps/storefront/src/components/compliance/AdultSignatureNotice.astro +1 -1
  57. package/apps/storefront/src/components/compliance/ComplianceNotice.astro +1 -2
  58. package/apps/storefront/src/components/compliance/ExciseTaxNotice.astro +1 -2
  59. package/apps/storefront/src/components/compliance/PactActNotice.astro +1 -1
  60. package/apps/storefront/src/components/compliance/Prop65Warning.astro +1 -2
  61. package/apps/storefront/src/components/compliance/PurchaseLimitNotice.astro +2 -3
  62. package/apps/storefront/src/components/compliance/ShippingRestrictionNotice.astro +2 -2
  63. package/apps/storefront/src/components/compliance/StateEligibilityNotice.astro +2 -3
  64. package/apps/storefront/src/components/content/TrustStrip.astro +4 -4
  65. package/apps/storefront/src/components/islands/MobileNav.tsx +26 -1
  66. package/apps/storefront/src/components/islands/VariantSelector.tsx +27 -2
  67. package/apps/storefront/src/components/islands/useCheckoutHandoffCorrelation.ts +75 -0
  68. package/apps/storefront/src/components/membership/IllustrativeLabel.astro +1 -2
  69. package/apps/storefront/src/components/membership/TierCards.astro +2 -2
  70. package/apps/storefront/src/components/membership/TierComparisonTable.astro +2 -2
  71. package/apps/storefront/src/components/subscription/SavingsExplainer.astro +2 -2
  72. package/apps/storefront/src/config/adminTenantLookup.ts +35 -0
  73. package/apps/storefront/src/config/devTenantSeed.ts +9 -9
  74. package/apps/storefront/src/config/resolver.ts +18 -10
  75. package/apps/storefront/src/layouts/Layout.astro +100 -20
  76. package/apps/storefront/src/lib/activity/candidateSubmitLease.ts +87 -0
  77. package/apps/storefront/src/lib/activity/changeActorAttribution.ts +86 -6
  78. package/apps/storefront/src/lib/activity/deployVersion.ts +1 -1
  79. package/apps/storefront/src/lib/admin/adminShell.ts +2 -0
  80. package/apps/storefront/src/lib/admin/envelope.ts +1 -2
  81. package/apps/storefront/src/lib/apps/adminService.ts +10 -0
  82. package/apps/storefront/src/lib/apps/adminSession.ts +1 -1
  83. package/apps/storefront/src/lib/apps/appVersionStore.ts +281 -0
  84. package/apps/storefront/src/lib/apps/consentConfigStore.ts +228 -0
  85. package/apps/storefront/src/lib/apps/gtmMigrationInstall.ts +447 -0
  86. package/apps/storefront/src/lib/apps/gtmMigrationReport.ts +367 -0
  87. package/apps/storefront/src/lib/apps/gtmMigrationTab.ts +315 -0
  88. package/apps/storefront/src/lib/apps/integrationLifecycle.ts +614 -0
  89. package/apps/storefront/src/lib/apps/integrationLifecycleController.ts +125 -0
  90. package/apps/storefront/src/lib/apps/integrationReadModel.ts +563 -0
  91. package/apps/storefront/src/lib/apps/integrationsTab.ts +547 -0
  92. package/apps/storefront/src/lib/apps/integrationsView.ts +106 -0
  93. package/apps/storefront/src/lib/apps/managedAnalyticsService.ts +599 -0
  94. package/apps/storefront/src/lib/apps/orders/orderConversionD1.ts +150 -0
  95. package/apps/storefront/src/lib/apps/orders/orderForwardReceiver.ts +8 -0
  96. package/apps/storefront/src/lib/apps/orders/ordersStore.ts +1 -1
  97. package/apps/storefront/src/lib/apps/orders/verifiedProviderMeasurement.ts +117 -0
  98. package/apps/storefront/src/lib/apps/registryService.ts +264 -10
  99. package/apps/storefront/src/lib/apps/tenantIntegrationMaterialization.ts +170 -0
  100. package/apps/storefront/src/lib/apps/v84CleanCloneReplayContext.ts +16 -0
  101. package/apps/storefront/src/lib/apps/v84CloneLifecycleCacheEvidence.ts +105 -0
  102. package/apps/storefront/src/lib/apps/v84CloneLifecycleEvidence.ts +177 -0
  103. package/apps/storefront/src/lib/apps/v84CloneLifecycleMaterialization.ts +251 -0
  104. package/apps/storefront/src/lib/apps/v84CloneLifecycleSemantics.ts +241 -0
  105. package/apps/storefront/src/lib/apps/v84CloneMigrationEvidence.ts +211 -0
  106. package/apps/storefront/src/lib/apps/v84CloneNativeInstallEvidence.ts +409 -0
  107. package/apps/storefront/src/lib/apps/v84NonportableCodeCoaching.ts +368 -0
  108. package/apps/storefront/src/lib/apps/v84NonportableRouteContract.ts +188 -0
  109. package/apps/storefront/src/lib/apps/v84NonportableRouteDogfood.ts +291 -0
  110. package/apps/storefront/src/lib/apps/ws1ManagedAnalyticsClient.ts +95 -0
  111. package/apps/storefront/src/lib/auth/adminApiGuard.ts +66 -0
  112. package/apps/storefront/src/lib/auth/adminEntry.ts +2 -2
  113. package/apps/storefront/src/lib/auth/adminLanding.ts +88 -0
  114. package/apps/storefront/src/lib/blog/collection.ts +114 -17
  115. package/apps/storefront/src/lib/blog/markdown.ts +1 -1
  116. package/apps/storefront/src/lib/blog/provider.ts +76 -9
  117. package/apps/storefront/src/lib/blog/types.ts +9 -9
  118. package/apps/storefront/src/lib/chrome/examples/tokenoftrust.chrome-assignments.example.json +6 -0
  119. package/apps/storefront/src/lib/chrome/examples/tokenoftrust.chrome.example.json +79 -0
  120. package/apps/storefront/src/lib/chrome/model.ts +48 -253
  121. package/apps/storefront/src/lib/chrome/navCurrent.ts +29 -0
  122. package/apps/storefront/src/lib/chrome/parseConfig.ts +18 -32
  123. package/apps/storefront/src/lib/chrome/variant.ts +39 -0
  124. package/apps/storefront/src/lib/commerce/checkoutHandoffCorrelation.ts +105 -0
  125. package/apps/storefront/src/lib/compliance/tamper-sentinel-boot.ts +152 -0
  126. package/apps/storefront/src/lib/compliance/tamper-sentinel.ts +327 -0
  127. package/apps/storefront/src/lib/content/index.ts +5 -5
  128. package/apps/storefront/src/lib/content-edit/applyDiff.ts +1 -1
  129. package/apps/storefront/src/lib/content-edit/route.ts +1 -1
  130. package/apps/storefront/src/lib/d1/catalog.ts +12 -0
  131. package/apps/storefront/src/lib/d1/schema-apps.ts +276 -0
  132. package/apps/storefront/src/lib/dev/cockpit/ask.ts +49 -0
  133. package/apps/storefront/src/lib/dev/cockpit/clickToSource.ts +71 -0
  134. package/apps/storefront/src/lib/dev/cockpit/copyCommand.ts +227 -0
  135. package/apps/storefront/src/lib/dev/cockpit/files.ts +249 -0
  136. package/apps/storefront/src/lib/dev/cockpit/hostedActivity.ts +500 -0
  137. package/apps/storefront/src/lib/dev/cockpit/infoPopover.ts +12 -0
  138. package/apps/storefront/src/lib/dev/cockpit/mcpCopy.ts +34 -0
  139. package/apps/storefront/src/lib/dev/cockpit/monitor.ts +107 -0
  140. package/apps/storefront/src/lib/dev/cockpit/stepper.ts +116 -0
  141. package/apps/storefront/src/lib/dev/cockpit/themeToggle.ts +23 -0
  142. package/apps/storefront/src/lib/dev/runtimeStore.ts +1 -1
  143. package/apps/storefront/src/lib/edgeCache.ts +18 -6
  144. package/apps/storefront/src/lib/email/candidateConflictEmail.ts +80 -0
  145. package/apps/storefront/src/lib/integration/browserEnvironment.ts +137 -0
  146. package/apps/storefront/src/lib/integration/managedInstallDeclarations.ts +72 -0
  147. package/apps/storefront/src/lib/integration/nonceStamp.ts +49 -0
  148. package/apps/storefront/src/lib/integration/tenantDeclarations.ts +116 -0
  149. package/apps/storefront/src/lib/membership/eligibility.ts +1 -1
  150. package/apps/storefront/src/lib/membership/model.ts +1 -2
  151. package/apps/storefront/src/lib/newsletter/confirmationEmail.ts +2 -2
  152. package/apps/storefront/src/lib/newsletter/consent.ts +2 -2
  153. package/apps/storefront/src/lib/newsletter/send.ts +3 -3
  154. package/apps/storefront/src/lib/previewReload.ts +57 -1
  155. package/apps/storefront/src/lib/publish/adminPublishTab.ts +1775 -669
  156. package/apps/storefront/src/lib/publish/buildStream.ts +269 -0
  157. package/apps/storefront/src/lib/publish/collapsePersistence.ts +72 -0
  158. package/apps/storefront/src/lib/publish/lifecycleState.ts +369 -0
  159. package/apps/storefront/src/lib/publish/liveReleaseSummary.ts +29 -0
  160. package/apps/storefront/src/lib/publish/mergeDoctorOnFailure.ts +78 -0
  161. package/apps/storefront/src/lib/publish/mergeHealthBanner.ts +62 -0
  162. package/apps/storefront/src/lib/publish/mergeRowFindings.ts +124 -0
  163. package/apps/storefront/src/lib/publish/mergeSupportEscalation.ts +75 -0
  164. package/apps/storefront/src/lib/publish/publish-guard.ts +88 -0
  165. package/apps/storefront/src/lib/publish/publishFormat.ts +165 -0
  166. package/apps/storefront/src/lib/publish/publishHero.ts +177 -0
  167. package/apps/storefront/src/lib/publish/reviewRelease/changeState.ts +66 -0
  168. package/apps/storefront/src/lib/publish/reviewRelease/copy.ts +141 -0
  169. package/apps/storefront/src/lib/publish/reviewRelease/index.ts +41 -0
  170. package/apps/storefront/src/lib/publish/reviewRelease/permissions.ts +47 -0
  171. package/apps/storefront/src/lib/publish/reviewRelease/releaseState.ts +42 -0
  172. package/apps/storefront/src/lib/publish/reviewRelease/types.ts +59 -0
  173. package/apps/storefront/src/lib/publish/reviewRelease/viewModel.ts +440 -0
  174. package/apps/storefront/src/lib/publish/reviewReleaseWorkspace/actions.ts +161 -0
  175. package/apps/storefront/src/lib/publish/reviewReleaseWorkspace/controller.ts +325 -0
  176. package/apps/storefront/src/lib/publish/reviewReleaseWorkspace/render.ts +241 -0
  177. package/apps/storefront/src/lib/publish/shipWorkspace.ts +22 -3
  178. package/apps/storefront/src/lib/publish/sseRoute.ts +119 -0
  179. package/apps/storefront/src/lib/publish/streamLogConsole.ts +142 -0
  180. package/apps/storefront/src/lib/publish/versionNumber.ts +52 -0
  181. package/apps/storefront/src/lib/rawChrome.ts +125 -47
  182. package/apps/storefront/src/lib/rawMarketingHtml.ts +74 -3
  183. package/apps/storefront/src/lib/seo/alternates.ts +1 -1
  184. package/apps/storefront/src/lib/social/notify.ts +4 -4
  185. package/apps/storefront/src/lib/storyblok/content-model.ts +7 -33
  186. package/apps/storefront/src/lib/storyblok/provider.ts +203 -69
  187. package/apps/storefront/src/lib/subscription/model.ts +4 -4
  188. package/apps/storefront/src/lib/the-build/provider.ts +9 -4
  189. package/apps/storefront/src/middleware/index.ts +273 -51
  190. package/apps/storefront/src/pages/[...slug].astro +9 -4
  191. package/apps/storefront/src/pages/admin/review-release.astro +265 -0
  192. package/apps/storefront/src/pages/admin/select.astro +96 -0
  193. package/apps/storefront/src/pages/admin.astro +16 -2
  194. package/apps/storefront/src/pages/api/activity.ts +8 -8
  195. package/apps/storefront/src/pages/api/admin/activity-alerts.ts +5 -20
  196. package/apps/storefront/src/pages/api/admin/orders/[id].ts +7 -2
  197. package/apps/storefront/src/pages/api/admin/orders.ts +8 -2
  198. package/apps/storefront/src/pages/api/apps/admin/gtm-migration-install.ts +174 -0
  199. package/apps/storefront/src/pages/api/apps/admin/gtm-migration.ts +96 -0
  200. package/apps/storefront/src/pages/api/apps/admin/integration-lifecycle.ts +118 -0
  201. package/apps/storefront/src/pages/api/apps/admin/integrations.ts +89 -0
  202. package/apps/storefront/src/pages/api/apps/admin/platform-adapters.ts +85 -0
  203. package/apps/storefront/src/pages/api/apps/internal/order-forward.ts +74 -2
  204. package/apps/storefront/src/pages/api/commerce/checkout-handoff.ts +77 -0
  205. package/apps/storefront/src/pages/api/compliance/tamper.ts +88 -0
  206. package/apps/storefront/src/pages/api/integrations/v1/[operation].ts +108 -0
  207. package/apps/storefront/src/pages/api/rum/vitals.ts +1 -2
  208. package/apps/storefront/src/pages/blog/[slug].astro +5 -5
  209. package/apps/storefront/src/pages/blog/author/[author].astro +3 -3
  210. package/apps/storefront/src/pages/blog/category/[category].astro +2 -2
  211. package/apps/storefront/src/pages/blog/index.astro +2 -2
  212. package/apps/storefront/src/pages/blog/tag/[tag].astro +2 -2
  213. package/apps/storefront/src/pages/cockpit.astro +61 -1362
  214. package/apps/storefront/src/pages/index.astro +10 -5
  215. package/apps/storefront/src/pages/llms.txt.ts +1 -1
  216. package/apps/storefront/src/pages/products/[handle].astro +7 -6
  217. package/apps/storefront/src/pages/sitemap.xml.ts +2 -2
  218. package/apps/storefront/src/pages/style-guide/[tenant]/[theme].astro +42 -31
  219. package/apps/storefront/src/pages/style-guide/[tenant]/chrome/[theme].astro +8 -3
  220. package/apps/storefront/src/pages/style-guide/[tenant]/guide/[theme].astro +6 -2
  221. package/apps/storefront/src/pages/style-guide/[tenant]/index.astro +6 -2
  222. package/apps/storefront/src/pages/style-guide/index.astro +19 -5
  223. package/apps/storefront/src/pages/tenants/[id]/[...path].ts +38 -2
  224. package/apps/storefront/src/pages/the-build/[slug].astro +4 -4
  225. package/apps/storefront/src/pages/the-build/index.astro +2 -2
  226. package/apps/storefront/src/pages/the-build/rss.xml.ts +2 -2
  227. package/apps/storefront/src/styles/admin.css +27 -1
  228. package/apps/storefront/src/themes/tenants/index.ts +19 -7
  229. package/apps/storefront/tsconfig.json +1 -1
  230. package/package.json +1 -1
  231. package/packages/public-runtime/package.json +2 -1
  232. package/packages/public-runtime/schemas/managed-analytics/v1/adapter-definition.schema.json +427 -0
  233. package/packages/public-runtime/schemas/managed-analytics/v1/create-integration-install-request.schema.json +161 -0
  234. package/packages/public-runtime/schemas/managed-analytics/v1/create-migration-draft-request.schema.json +157 -0
  235. package/packages/public-runtime/schemas/managed-analytics/v1/delete-integration-install-request.schema.json +84 -0
  236. package/packages/public-runtime/schemas/managed-analytics/v1/delete-migration-draft-request.schema.json +84 -0
  237. package/packages/public-runtime/schemas/managed-analytics/v1/error-envelope.schema.json +180 -0
  238. package/packages/public-runtime/schemas/managed-analytics/v1/get-adapter-definition-request.schema.json +52 -0
  239. package/packages/public-runtime/schemas/managed-analytics/v1/get-integration-install-request.schema.json +52 -0
  240. package/packages/public-runtime/schemas/managed-analytics/v1/get-integration-revision-request.schema.json +79 -0
  241. package/packages/public-runtime/schemas/managed-analytics/v1/get-migration-draft-request.schema.json +52 -0
  242. package/packages/public-runtime/schemas/managed-analytics/v1/integration-install.schema.json +167 -0
  243. package/packages/public-runtime/schemas/managed-analytics/v1/integration-revision.schema.json +208 -0
  244. package/packages/public-runtime/schemas/managed-analytics/v1/list-adapter-definitions-request.schema.json +53 -0
  245. package/packages/public-runtime/schemas/managed-analytics/v1/list-integration-installs-request.schema.json +53 -0
  246. package/packages/public-runtime/schemas/managed-analytics/v1/list-integration-revisions-request.schema.json +82 -0
  247. package/packages/public-runtime/schemas/managed-analytics/v1/migration-draft.schema.json +218 -0
  248. package/packages/public-runtime/schemas/managed-analytics/v1/mutation-request.schema.json +52 -0
  249. package/packages/public-runtime/schemas/managed-analytics/v1/mutation-success-envelope.schema.json +49 -0
  250. package/packages/public-runtime/schemas/managed-analytics/v1/read-request.schema.json +20 -0
  251. package/packages/public-runtime/schemas/managed-analytics/v1/read-success-envelope.schema.json +45 -0
  252. package/packages/public-runtime/schemas/managed-analytics/v1/revise-integration-install-request.schema.json +156 -0
  253. package/packages/public-runtime/schemas/managed-analytics/v1/set-integration-install-status-request.schema.json +92 -0
  254. package/packages/public-runtime/schemas/managed-analytics/v1/update-migration-draft-request.schema.json +184 -0
  255. package/packages/public-runtime/scripts/generate-managed-analytics-api-v1-schemas.mjs +13 -0
  256. package/packages/public-runtime/src/activity/catalog.ts +41 -37
  257. package/packages/public-runtime/src/activity/event.ts +6 -6
  258. package/packages/public-runtime/src/activity/index.ts +2 -2
  259. package/packages/public-runtime/src/activity/redaction.ts +4 -4
  260. package/packages/public-runtime/src/candidate-index.ts +42 -8
  261. package/packages/public-runtime/src/checkout-orders.ts +2 -2
  262. package/packages/public-runtime/src/checkout-style-publish.ts +2 -2
  263. package/packages/public-runtime/src/checkout-style.ts +7 -7
  264. package/packages/public-runtime/src/checkout.ts +3 -3
  265. package/packages/public-runtime/src/chrome.ts +777 -0
  266. package/packages/public-runtime/src/compliance-obligations.ts +310 -0
  267. package/packages/public-runtime/src/csp.ts +99 -0
  268. package/packages/public-runtime/src/customization-runtime.ts +32 -1
  269. package/packages/public-runtime/src/destination-webhook/contract.ts +353 -0
  270. package/packages/public-runtime/src/embed-catalog.d.mts +9 -0
  271. package/packages/public-runtime/src/embed-catalog.mjs +40 -0
  272. package/packages/public-runtime/src/evidence.ts +288 -0
  273. package/packages/public-runtime/src/gtm-migration/bounds.ts +138 -0
  274. package/packages/public-runtime/src/gtm-migration/disposition-rules.ts +361 -0
  275. package/packages/public-runtime/src/gtm-migration/dispositions.ts +181 -0
  276. package/packages/public-runtime/src/gtm-migration/draft-generator.ts +400 -0
  277. package/packages/public-runtime/src/gtm-migration/graph.ts +468 -0
  278. package/packages/public-runtime/src/gtm-migration/index.ts +95 -0
  279. package/packages/public-runtime/src/gtm-migration/parse.ts +410 -0
  280. package/packages/public-runtime/src/gtm-migration/references.ts +266 -0
  281. package/packages/public-runtime/src/gtm-migration/types.ts +86 -0
  282. package/packages/public-runtime/src/index.ts +16 -1
  283. package/packages/public-runtime/src/integration/assurance-decision.ts +259 -0
  284. package/packages/public-runtime/src/integration/assurance.ts +228 -0
  285. package/packages/public-runtime/src/integration/candidate-evidence.ts +377 -0
  286. package/packages/public-runtime/src/integration/commerce-broker.ts +497 -0
  287. package/packages/public-runtime/src/integration/consent-broker.ts +337 -0
  288. package/packages/public-runtime/src/integration/consent-cmp-demand.ts +115 -0
  289. package/packages/public-runtime/src/integration/consent-config.ts +260 -0
  290. package/packages/public-runtime/src/integration/consent-preview.ts +125 -0
  291. package/packages/public-runtime/src/integration/correlation-token.ts +444 -0
  292. package/packages/public-runtime/src/integration/csp-compiler.ts +267 -0
  293. package/packages/public-runtime/src/integration/csp.ts +105 -0
  294. package/packages/public-runtime/src/integration/digest.ts +43 -0
  295. package/packages/public-runtime/src/integration/environment.ts +228 -0
  296. package/packages/public-runtime/src/integration/events-catalog.ts +186 -0
  297. package/packages/public-runtime/src/integration/events.ts +701 -0
  298. package/packages/public-runtime/src/integration/g2-action-boundary.ts +106 -0
  299. package/packages/public-runtime/src/integration/index.ts +90 -0
  300. package/packages/public-runtime/src/integration/interim-bridge.ts +138 -0
  301. package/packages/public-runtime/src/integration/lifecycle-boot.ts +317 -0
  302. package/packages/public-runtime/src/integration/lifecycle-runtime.ts +393 -0
  303. package/packages/public-runtime/src/integration/lifecycle.ts +94 -0
  304. package/packages/public-runtime/src/integration/managed-analytics-api-v1-safety.d.mts +2 -0
  305. package/packages/public-runtime/src/integration/managed-analytics-api-v1-safety.mjs +10 -0
  306. package/packages/public-runtime/src/integration/managed-analytics-api-v1.schemas.ts +382 -0
  307. package/packages/public-runtime/src/integration/managed-analytics-api-v1.ts +684 -0
  308. package/packages/public-runtime/src/integration/managed-analytics-bridge.ts +383 -0
  309. package/packages/public-runtime/src/integration/managed-analytics-value-safety.ts +14 -0
  310. package/packages/public-runtime/src/integration/managed-analytics.ts +277 -0
  311. package/packages/public-runtime/src/integration/manifest.ts +470 -0
  312. package/packages/public-runtime/src/integration/native-amplitude.ts +362 -0
  313. package/packages/public-runtime/src/integration/native-ga4.ts +352 -0
  314. package/packages/public-runtime/src/integration/observability.ts +451 -0
  315. package/packages/public-runtime/src/integration/order-conversion.ts +0 -0
  316. package/packages/public-runtime/src/integration/phases.ts +182 -0
  317. package/packages/public-runtime/src/integration/plan.ts +112 -0
  318. package/packages/public-runtime/src/integration/platform-adapter-runtime.ts +146 -0
  319. package/packages/public-runtime/src/integration/platform-adapters.ts +671 -0
  320. package/packages/public-runtime/src/integration/promotion-gate.ts +451 -0
  321. package/packages/public-runtime/src/integration/provider-checkout-extension.ts +425 -0
  322. package/packages/public-runtime/src/integration/receipt-measurement.ts +370 -0
  323. package/packages/public-runtime/src/integration/regulated-parent-cert.ts +311 -0
  324. package/packages/public-runtime/src/integration/render-phases.ts +267 -0
  325. package/packages/public-runtime/src/integration/resolve.ts +465 -0
  326. package/packages/public-runtime/src/integration/result.ts +239 -0
  327. package/packages/public-runtime/src/integration/secrets.ts +92 -0
  328. package/packages/public-runtime/src/integration/tamper-evidence.ts +205 -0
  329. package/packages/public-runtime/src/integration/tamper-recovery.ts +127 -0
  330. package/packages/public-runtime/src/integration/version.ts +92 -0
  331. package/packages/public-runtime/src/integration-capabilities.ts +520 -0
  332. package/packages/public-runtime/src/membership.ts +2 -2
  333. package/packages/public-runtime/src/raw-html-policy.ts +2 -4
  334. package/packages/public-runtime/src/regulated-commerce/broker/consent-dedupe.ts +144 -0
  335. package/packages/public-runtime/src/regulated-commerce/correlation/contract.ts +177 -0
  336. package/packages/public-runtime/src/regulated-commerce/diagnostics/local-dispatch.ts +24 -0
  337. package/packages/public-runtime/src/regulated-commerce/diagnostics/read-model.ts +69 -0
  338. package/packages/public-runtime/src/regulated-commerce/dispatch/core.ts +134 -0
  339. package/packages/public-runtime/src/regulated-commerce/events/contract.ts +113 -0
  340. package/packages/public-runtime/src/regulated-commerce/ledger/core.ts +81 -0
  341. package/packages/public-runtime/src/regulated-commerce/mappings/ga4-ads.ts +87 -0
  342. package/packages/public-runtime/src/regulated-commerce/provider-order/bridge.ts +52 -0
  343. package/packages/public-runtime/src/regulated-commerce/purchase-truth/contract.ts +252 -0
  344. package/packages/public-runtime/src/regulated-commerce/sources/accepted-browser-operation.ts +67 -0
  345. package/packages/public-runtime/src/regulated-commerce/testing/fake-destination.ts +93 -0
  346. package/packages/public-runtime/src/static-bundle.ts +5 -5
  347. package/packages/public-runtime/src/tenant-assets.ts +143 -4
  348. package/packages/public-runtime/src/tenant.ts +136 -9
  349. package/packages/public-runtime/tests/fixtures/integration/browser-environment.example.json +8 -0
  350. package/packages/public-runtime/tests/fixtures/integration/commerce-event.example.json +44 -0
  351. package/packages/public-runtime/tests/fixtures/integration/commerce-order-event.example.json +44 -0
  352. package/packages/public-runtime/tests/fixtures/integration/compliance-assurance-record.example.json +50 -0
  353. package/packages/public-runtime/tests/fixtures/integration/integration-manifest-v2.example.json +120 -0
  354. package/packages/public-runtime/tests/fixtures/integration/managed-analytics-v1/fake-adapter-catalog.json +35 -0
  355. package/packages/public-runtime/tests/fixtures/integration/tenant-action-registry.example.json +11 -0
  356. package/packages/public-runtime/tests/fixtures/integration/tenant-local-example/README.md +22 -0
  357. package/packages/public-runtime/tests/fixtures/integration/tenant-local-example/entry.js +30 -0
  358. package/packages/public-runtime/tests/fixtures/integration/tenant-local-example/manifest.json +75 -0
  359. package/packages/public-runtime/tests/fixtures/integration/tenant-local-example/public-config.json +3 -0
  360. package/packages/public-runtime/tests/fixtures/regulated-commerce/fake-destinations.ts +38 -0
  361. package/packages/public-runtime/tests/gtm-migration/fixtures/gtm-sample-container-v84.provenance.json +29 -0
  362. package/packages/public-runtime/tests/gtm-migration/fixtures/gtm-sample-container-v84.redacted.json +3397 -0
  363. package/scripts/build/copy-tenant-assets.mjs +12 -5
  364. package/scripts/dev/ai-edit.mjs +2 -1
  365. package/scripts/dev/file-browser.mjs +2 -2
  366. package/scripts/dev/file-writer.mjs +2 -2
  367. package/scripts/dev/integration-guardrails.mjs +498 -0
  368. package/scripts/dev/safe-path.mjs +2 -2
  369. package/scripts/dev/tenant-source-root.mjs +3 -2
  370. package/scripts/tot-dev.mjs +5 -4
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Exact-clone, offline lifecycle validation composed from public product seams.
3
+ *
4
+ * It consumes the already-reviewed native-install evidence, then exercises only
5
+ * public-value environment, consent, semantic-event, lifecycle-bridge, and cache
6
+ * contracts. It has no renderer, integration loader, destination runtime, network,
7
+ * persistence, GTM, eval, or publish authority.
8
+ */
9
+ import {
10
+ APPROVED_MARKETING_ACTION_NAMES,
11
+ planCacheIdentity,
12
+ sha256Hex,
13
+ snapshotManagedAnalyticsDeclarativeInput,
14
+ stableIntegrationStringify,
15
+ } from "@tot/public-runtime";
16
+ import { buildV84CloneCacheEvidence } from "./v84CloneLifecycleCacheEvidence.js";
17
+ import {
18
+ validateV84DisabledInstallMaterialization,
19
+ type V84LifecycleMaterializationDependencies,
20
+ } from "./v84CloneLifecycleMaterialization.js";
21
+ import { buildV84CloneLifecycleSemantics } from "./v84CloneLifecycleSemantics.js";
22
+ import {
23
+ V84_NATIVE_CLONE_TENANT,
24
+ V84_NATIVE_SOURCE_TENANT,
25
+ V84_WS1_API_CONTRACT,
26
+ V84_WS1_FINAL,
27
+ V84_WS2_EVIDENCE_SHA256,
28
+ V84_WS2_FINAL,
29
+ type V84NativeInstallEvidence,
30
+ } from "./v84CloneNativeInstallEvidence.js";
31
+ import {
32
+ sameV84ReplayValue,
33
+ type V84CleanCloneReplayContext,
34
+ } from "./v84CleanCloneReplayContext.js";
35
+
36
+ /** SHA-256 of the full canonical native-install evidence accepted by this unit. */
37
+ export const V84_NATIVE_INSTALL_EVIDENCE_SHA256 = "d479a8b07cdde0808c75abea7410c7f1c685ed8d79f5e62f21a6261d1087eda8" as const;
38
+
39
+ function assertNativeEvidence(evidence: V84NativeInstallEvidence): void {
40
+ if (
41
+ evidence.scope.sourceTenant !== V84_NATIVE_SOURCE_TENANT ||
42
+ evidence.scope.sourceMode !== "read-only" ||
43
+ evidence.scope.cloneTenant !== V84_NATIVE_CLONE_TENANT ||
44
+ evidence.scope.destinationMode !== "offline-in-memory-fake-only" ||
45
+ evidence.contractPins.ws1Final !== V84_WS1_FINAL ||
46
+ evidence.contractPins.ws1ApiContract !== V84_WS1_API_CONTRACT ||
47
+ evidence.contractPins.ws2Final !== V84_WS2_FINAL ||
48
+ evidence.contractPins.ws2EvidenceSha256 !== V84_WS2_EVIDENCE_SHA256 ||
49
+ evidence.installations.length !== 2 ||
50
+ evidence.installations.some((item) =>
51
+ item.desired.installStatus !== "disabled" ||
52
+ item.desired.revisionStatus !== "draft" ||
53
+ item.effective.activeRevisionId !== null ||
54
+ item.effective.materialized !== false
55
+ ) ||
56
+ stableIntegrationStringify(evidence.semanticActions) !==
57
+ stableIntegrationStringify(APPROVED_MARKETING_ACTION_NAMES) ||
58
+ evidence.operationCounts.reviseIntegrationInstall !== 0 ||
59
+ evidence.operationCounts.setIntegrationInstallStatus !== 0 ||
60
+ evidence.operationCounts.publish !== 0 ||
61
+ evidence.safety.sourceMutationCount !== 0 ||
62
+ evidence.safety.liveDestinationCount !== 0 ||
63
+ evidence.safety.externalNetworkRequestCount !== 0 ||
64
+ evidence.safety.importedCodeExecuted ||
65
+ evidence.safety.runtimeLoaded ||
66
+ evidence.safety.lifecycle !== "reviewed-disabled-draft-only"
67
+ ) {
68
+ throw new Error("The supplied native-install evidence is outside the exact disabled v84 proof.");
69
+ }
70
+ }
71
+
72
+ /** Build deterministic, sanitized evidence. Every delivery remains an in-memory callback. */
73
+ export async function buildV84CloneLifecycleEvidence(
74
+ unsafeNativeEvidence: unknown,
75
+ materializationDependencies?: V84LifecycleMaterializationDependencies,
76
+ replayContext?: V84CleanCloneReplayContext,
77
+ ) {
78
+ const snapshot = snapshotManagedAnalyticsDeclarativeInput<V84NativeInstallEvidence>(unsafeNativeEvidence);
79
+ if (!snapshot.ok) throw new Error("The native-install evidence could not be snapshotted safely.");
80
+ const nativeEvidence = snapshot.value;
81
+ assertNativeEvidence(nativeEvidence);
82
+ if (replayContext && !sameV84ReplayValue(
83
+ replayContext.read<V84NativeInstallEvidence>("stage/native/handoff"),
84
+ nativeEvidence,
85
+ )) {
86
+ throw new Error("The lifecycle proof did not receive the shared native handoff.");
87
+ }
88
+ const nativeEvidenceSha256 = await sha256Hex(stableIntegrationStringify(nativeEvidence));
89
+ if (nativeEvidenceSha256 !== V84_NATIVE_INSTALL_EVIDENCE_SHA256) {
90
+ throw new Error("The supplied native-install evidence does not match the pinned exact proof.");
91
+ }
92
+
93
+ const semantics = buildV84CloneLifecycleSemantics();
94
+ const materialization = await validateV84DisabledInstallMaterialization(
95
+ nativeEvidence.installations,
96
+ semantics.candidateEnvironment,
97
+ semantics.stagedEnvironment,
98
+ materializationDependencies,
99
+ replayContext,
100
+ );
101
+ const candidatePlan = materialization.candidatePlanAfter;
102
+ const stagedPlan = materialization.stagedPlanAfter;
103
+ const cache = await buildV84CloneCacheEvidence(materialization, replayContext);
104
+
105
+ const evidence = {
106
+ schemaVersion: 1 as const,
107
+ scope: {
108
+ sourceTenant: V84_NATIVE_SOURCE_TENANT,
109
+ sourceMode: "read-only" as const,
110
+ cloneTenant: V84_NATIVE_CLONE_TENANT,
111
+ destinationMode: "offline-in-memory-callback-only" as const,
112
+ environments: ["candidate", "staged"] as const,
113
+ },
114
+ contractPins: {
115
+ ws1Final: V84_WS1_FINAL,
116
+ ws1ApiContract: V84_WS1_API_CONTRACT,
117
+ ws2Final: V84_WS2_FINAL,
118
+ ws2EvidenceSha256: V84_WS2_EVIDENCE_SHA256,
119
+ nativeInstallEvidenceSha256: nativeEvidenceSha256,
120
+ },
121
+ disabledDrafts: {
122
+ count: nativeEvidence.installations.length,
123
+ statuses: nativeEvidence.installations.map(({ desired }) => ({
124
+ install: desired.installStatus,
125
+ revision: desired.revisionStatus,
126
+ })),
127
+ activeRevisionCount: nativeEvidence.installations.filter(({ effective }) => effective.activeRevisionId !== null).length,
128
+ materializedCount: candidatePlan.integrations.length + stagedPlan.integrations.length,
129
+ materializedDeclarationCount: materialization.materializedDeclarationCount,
130
+ materializedAssetCount: materialization.materializedAssetCount,
131
+ readModelUnmaterializedCount: materialization.readModelUnmaterializedCount,
132
+ lifecycleRefusalCount: materialization.lifecycleRefusalCount,
133
+ lifecycleMutationCount: materialization.lifecycleMutationCount,
134
+ },
135
+ environment: {
136
+ candidate: semantics.candidateEnvironment,
137
+ staged: semantics.stagedEnvironment,
138
+ candidatePlanIdentity: planCacheIdentity(candidatePlan),
139
+ stagedPlanIdentity: planCacheIdentity(stagedPlan),
140
+ distinctPlanIdentities: planCacheIdentity(candidatePlan) !== planCacheIdentity(stagedPlan),
141
+ liveEnvironmentCount: 0,
142
+ },
143
+ consent: semantics.consent,
144
+ lifecycle: semantics.lifecycle,
145
+ routes: semantics.routes,
146
+ actions: semantics.actions,
147
+ warmCache: cache.warmCache,
148
+ operationCounts: {
149
+ sourceReads: 0,
150
+ sourceWrites: 0,
151
+ managedMaterializationReads: materialization.materializationReadCount,
152
+ managedReadModelAssemblies: materialization.readModelAssemblyCount,
153
+ managedLifecycleLoads: materialization.lifecycleLoadCount,
154
+ cloneCacheReads: cache.cloneCacheReads,
155
+ cloneCacheWrites: cache.cloneCacheWrites,
156
+ inMemoryEventDeliveries: semantics.inMemoryEventDeliveries,
157
+ externalNetworkRequests: 0,
158
+ lifecycleMutations: 0,
159
+ publishes: 0,
160
+ },
161
+ safety: {
162
+ importedCodeExecuted: false,
163
+ rendererCalled: false,
164
+ integrationLifecycleRuntimeInitialized: false,
165
+ nativeDestinationRuntimeInvoked: false,
166
+ gtmLoaded: false,
167
+ markupEvaluated: false,
168
+ externalNetworkUsed: false,
169
+ liveSecretUsed: false,
170
+ productionUsed: false,
171
+ sourceMutated: false,
172
+ diagnosticsCarryDestinationValues: false,
173
+ },
174
+ };
175
+ replayContext?.write("stage/lifecycle/handoff", evidence);
176
+ return evidence;
177
+ }
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Fake/local adapter that proves disabled managed-install rows remain absent from
3
+ * the real declaration, admin read-model, and lifecycle seams.
4
+ */
5
+ import {
6
+ resolveEffectivePlan,
7
+ stableIntegrationStringify,
8
+ type BrowserEnvironment,
9
+ type EffectivePlan,
10
+ type IntegrationDeclarationInput,
11
+ } from "@tot/public-runtime";
12
+ import type { Queryable } from "../d1/catalog.js";
13
+ import { loadActiveManagedInstallDeclarations } from "../integration/managedInstallDeclarations.js";
14
+ import { assembleIntegrationReadModel } from "./integrationReadModel.js";
15
+ import { handleLifecycleRequest } from "./integrationLifecycleController.js";
16
+ import {
17
+ V84_NATIVE_CLONE_TENANT,
18
+ type V84NativeInstallEvidence,
19
+ } from "./v84CloneNativeInstallEvidence.js";
20
+ import type { V84CleanCloneReplayContext } from "./v84CleanCloneReplayContext.js";
21
+
22
+ type NativeInstall = V84NativeInstallEvidence["installations"][number];
23
+
24
+ interface LocalManagedRow {
25
+ readonly install_id: string;
26
+ readonly tenant_id: string;
27
+ readonly managed_kind: "managed-analytics-v1";
28
+ readonly status: "suspended";
29
+ readonly app_id: string;
30
+ readonly app_version: string;
31
+ readonly manifest: "{}";
32
+ readonly revision_status: "draft";
33
+ }
34
+
35
+ export interface V84LifecycleMaterializationDependencies {
36
+ readonly loadDeclarations: typeof loadActiveManagedInstallDeclarations;
37
+ }
38
+
39
+ const dependencies: V84LifecycleMaterializationDependencies = {
40
+ loadDeclarations: loadActiveManagedInstallDeclarations,
41
+ };
42
+
43
+ function resolvePlan(
44
+ environment: BrowserEnvironment,
45
+ declarations: readonly IntegrationDeclarationInput[],
46
+ ): EffectivePlan {
47
+ const result = resolveEffectivePlan({
48
+ tenantPublicId: V84_NATIVE_CLONE_TENANT,
49
+ environment,
50
+ declarations,
51
+ });
52
+ if (!result.ok) throw new Error("The local managed-install plan failed safely.");
53
+ return result.value;
54
+ }
55
+
56
+ function localRows(installations: readonly NativeInstall[]): LocalManagedRow[] {
57
+ return installations.map((install, index) => ({
58
+ install_id: `v84-local-managed-${index + 1}`,
59
+ tenant_id: V84_NATIVE_CLONE_TENANT,
60
+ managed_kind: "managed-analytics-v1",
61
+ status: "suspended",
62
+ app_id: install.adapterId,
63
+ app_version: install.adapterVersion,
64
+ manifest: "{}",
65
+ revision_status: install.desired.revisionStatus,
66
+ }));
67
+ }
68
+
69
+ /** Minimal local Queryable that executes the materializer's active-row predicate. */
70
+ function localManagedInstallDb(rows: readonly LocalManagedRow[]): Queryable {
71
+ const unexpected = async (): Promise<never> => {
72
+ throw new Error("The disabled managed-install proof reached an unexpected persistence operation.");
73
+ };
74
+ return {
75
+ all: async <T>(sql: string, ...params: unknown[]) => {
76
+ const normalized = sql.replace(/\s+/g, " ").trim();
77
+ if (
78
+ !normalized.includes("FROM app_installs") ||
79
+ !normalized.includes("tenant_id = ?") ||
80
+ !normalized.includes("managed_kind = ?") ||
81
+ !normalized.includes("status = 'active'") ||
82
+ params.length !== 2
83
+ ) {
84
+ throw new Error("The managed-install materializer widened its active-row boundary.");
85
+ }
86
+ const [tenantId, managedKind] = params;
87
+ return rows
88
+ .filter((row) =>
89
+ row.tenant_id === tenantId &&
90
+ row.managed_kind === managedKind &&
91
+ row.status === ("active" as string)
92
+ )
93
+ .map(({ install_id, app_id, app_version, manifest }) => ({
94
+ install_id,
95
+ app_id,
96
+ app_version,
97
+ manifest,
98
+ })) as T[];
99
+ },
100
+ first: unexpected,
101
+ run: unexpected,
102
+ exec: unexpected,
103
+ };
104
+ }
105
+
106
+ export interface V84DisabledInstallMaterializationResult {
107
+ readonly candidatePlanBefore: EffectivePlan;
108
+ readonly candidatePlanAfter: EffectivePlan;
109
+ readonly stagedPlanAfter: EffectivePlan;
110
+ readonly managedInstallStateChanged: true;
111
+ readonly readModelUnmaterializedCount: 2;
112
+ readonly lifecycleRefusalCount: 2;
113
+ readonly materializedDeclarationCount: 0;
114
+ readonly materializedAssetCount: 0;
115
+ readonly materializationReadCount: 2;
116
+ readonly readModelAssemblyCount: 1;
117
+ readonly lifecycleLoadCount: 2;
118
+ readonly lifecycleMutationCount: 0;
119
+ }
120
+
121
+ /**
122
+ * Exercise the actual managed-install declaration loader, admin read model, and
123
+ * lifecycle controller over local rows derived from the canonical install output.
124
+ */
125
+ export async function validateV84DisabledInstallMaterialization(
126
+ installations: readonly NativeInstall[],
127
+ candidateEnvironment: BrowserEnvironment,
128
+ stagedEnvironment: BrowserEnvironment,
129
+ deps: V84LifecycleMaterializationDependencies = dependencies,
130
+ replayContext?: V84CleanCloneReplayContext,
131
+ ): Promise<V84DisabledInstallMaterializationResult> {
132
+ const localBeforeRows: readonly LocalManagedRow[] = [];
133
+ const localAfterRows = localRows(installations);
134
+ if (replayContext) {
135
+ replayContext.write("stage/lifecycle/materialization/before", localBeforeRows);
136
+ replayContext.write("stage/lifecycle/materialization/after", localAfterRows);
137
+ }
138
+ const beforeRows = replayContext
139
+ ? replayContext.read<readonly LocalManagedRow[]>("stage/lifecycle/materialization/before") ?? []
140
+ : localBeforeRows;
141
+ const afterRows = replayContext
142
+ ? replayContext.read<readonly LocalManagedRow[]>("stage/lifecycle/materialization/after") ?? []
143
+ : localAfterRows;
144
+ if (
145
+ afterRows.length !== 2 ||
146
+ afterRows.some((row) => row.status !== "suspended" || row.revision_status !== "draft") ||
147
+ stableIntegrationStringify(beforeRows) === stableIntegrationStringify(afterRows)
148
+ ) {
149
+ throw new Error("The local disabled managed-install state was not exact.");
150
+ }
151
+
152
+ let materializationReadCount = 0;
153
+ const loadDeclarations = async (db: Queryable) => {
154
+ materializationReadCount += 1;
155
+ return deps.loadDeclarations(db, V84_NATIVE_CLONE_TENANT);
156
+ };
157
+ const beforeDeclarations = await loadDeclarations(
158
+ localManagedInstallDb(beforeRows),
159
+ );
160
+ const afterDeclarations = await loadDeclarations(
161
+ localManagedInstallDb(afterRows),
162
+ );
163
+ if (beforeDeclarations.length !== 0 || afterDeclarations.length !== 0) {
164
+ throw new Error("A disabled draft was treated as a materializable managed install.");
165
+ }
166
+
167
+ const candidatePlanBefore = resolvePlan(candidateEnvironment, beforeDeclarations);
168
+ const candidatePlanAfter = resolvePlan(candidateEnvironment, afterDeclarations);
169
+ const stagedPlanAfter = resolvePlan(stagedEnvironment, afterDeclarations);
170
+ let readModelAssemblyCount = 0;
171
+ readModelAssemblyCount += 1;
172
+ const readModel = assembleIntegrationReadModel({
173
+ tenantPublicId: V84_NATIVE_CLONE_TENANT,
174
+ stage: "candidate",
175
+ items: afterRows.map((row) => ({
176
+ install: {
177
+ installId: row.install_id,
178
+ appId: row.app_id,
179
+ appVersion: row.app_version,
180
+ tenantId: row.tenant_id,
181
+ status: row.status,
182
+ },
183
+ purpose: "Reviewed managed analytics destination.",
184
+ desiredConfig: { destinationConfigured: true },
185
+ declaredTier: "platform-adapter",
186
+ effectivePlan: null,
187
+ effectiveCsp: null,
188
+ consentSnapshot: null,
189
+ candidate: null,
190
+ knownGood: null,
191
+ })),
192
+ });
193
+ if (
194
+ !readModel.ok ||
195
+ readModel.value.items.length !== 2 ||
196
+ readModel.value.items.some((item) => item.effective !== null || !item.drift.unmaterialized)
197
+ ) {
198
+ throw new Error("The disabled managed-install read model materialized an effective state.");
199
+ }
200
+
201
+ let lifecycleMutationCount = 0;
202
+ let lifecycleRefusalCount = 0;
203
+ let lifecycleLoadCount = 0;
204
+ for (const row of afterRows) {
205
+ const response = await handleLifecycleRequest({
206
+ load: async () => { lifecycleLoadCount += 1; return null; },
207
+ save: async () => { lifecycleMutationCount += 1; },
208
+ resolveCandidateEvidence: async () => {
209
+ throw new Error("An unmaterialized disabled install must not resolve candidate evidence.");
210
+ },
211
+ resolveGate: async () => {
212
+ throw new Error("An unmaterialized disabled install must not resolve a publish gate.");
213
+ },
214
+ }, {
215
+ action: "preview",
216
+ installId: row.install_id,
217
+ actor: "v84-local-reviewer",
218
+ });
219
+ if (response.status !== 409 || JSON.stringify(response.body) !== JSON.stringify({
220
+ error: "integration is not materialized",
221
+ code: "not_materialized",
222
+ })) {
223
+ throw new Error("The disabled managed-install lifecycle did not fail closed.");
224
+ }
225
+ lifecycleRefusalCount += 1;
226
+ }
227
+ if (
228
+ materializationReadCount !== 2 ||
229
+ readModelAssemblyCount !== 1 ||
230
+ lifecycleLoadCount !== 2 ||
231
+ lifecycleMutationCount !== 0 ||
232
+ lifecycleRefusalCount !== 2
233
+ ) {
234
+ throw new Error("The disabled managed-install lifecycle changed local state.");
235
+ }
236
+
237
+ return {
238
+ candidatePlanBefore,
239
+ candidatePlanAfter,
240
+ stagedPlanAfter,
241
+ managedInstallStateChanged: true,
242
+ readModelUnmaterializedCount: 2,
243
+ lifecycleRefusalCount: 2,
244
+ materializedDeclarationCount: afterDeclarations.length as 0,
245
+ materializedAssetCount: afterDeclarations.flatMap((item) => item.materializedAssets).length as 0,
246
+ materializationReadCount: materializationReadCount as 2,
247
+ readModelAssemblyCount: readModelAssemblyCount as 1,
248
+ lifecycleLoadCount: lifecycleLoadCount as 2,
249
+ lifecycleMutationCount,
250
+ };
251
+ }
@@ -0,0 +1,241 @@
1
+ /** Offline semantic-lifecycle evidence built only from public product contracts. */
2
+ import {
3
+ APPROVED_MARKETING_ACTION_NAMES,
4
+ CommerceEventBroker,
5
+ CONSENT_CONFIG_SCHEMA_VERSION,
6
+ ManagedAnalyticsEventBrokerBridge,
7
+ buildTenantConsentBroker,
8
+ resolveBrowserEnvironment,
9
+ stableIntegrationStringify,
10
+ validateBrowserEnvironment,
11
+ validateConsentConfig,
12
+ validateTenantActionRegistry,
13
+ type CommerceEvent,
14
+ type ManagedAnalyticsBridgeResult,
15
+ } from "@tot/public-runtime";
16
+ import { V84_NATIVE_CLONE_TENANT } from "./v84CloneNativeInstallEvidence.js";
17
+
18
+ const AT = "2026-08-29T00:00:00.000Z";
19
+ const CORRELATION = { id: "corr-v84-lifecycle", expiresAt: "2026-08-29T02:00:00.000Z" };
20
+ const DIAGNOSTIC_HOST = "gtm-migration-v84.invalid";
21
+
22
+ function emitted(result: ManagedAnalyticsBridgeResult): boolean {
23
+ return result.ok && result.emitted;
24
+ }
25
+
26
+ function skipped(result: ManagedAnalyticsBridgeResult, reason: string): boolean {
27
+ return result.ok && !result.emitted && result.skipReason === reason;
28
+ }
29
+
30
+ /** Exercise candidate/staged environments, consent, routes, actions, and disposal. */
31
+ export function buildV84CloneLifecycleSemantics() {
32
+ const candidateEnvironment = resolveBrowserEnvironment({
33
+ siteSurface: "marketing",
34
+ canonicalHost: DIAGNOSTIC_HOST,
35
+ revision: "v84-lifecycle-candidate",
36
+ dev: false,
37
+ localHost: false,
38
+ candidate: true,
39
+ previewHost: false,
40
+ customizationEnv: "test",
41
+ });
42
+ const stagedEnvironment = resolveBrowserEnvironment({
43
+ siteSurface: "marketing",
44
+ canonicalHost: DIAGNOSTIC_HOST,
45
+ revision: "v84-lifecycle-staged",
46
+ dev: false,
47
+ localHost: false,
48
+ candidate: false,
49
+ previewHost: true,
50
+ customizationEnv: "test",
51
+ });
52
+ if (!validateBrowserEnvironment(candidateEnvironment).ok || !validateBrowserEnvironment(stagedEnvironment).ok) {
53
+ throw new Error("The product environment resolver emitted an invalid public environment.");
54
+ }
55
+
56
+ const consentResult = validateConsentConfig({
57
+ schemaVersion: CONSENT_CONFIG_SCHEMA_VERSION,
58
+ purposes: [{ purpose: "analytics", legalBasis: "consent", defaultState: "denied" }],
59
+ cmp: { mode: "none" },
60
+ });
61
+ if (!consentResult.ok) throw new Error("The fixed analytics consent policy failed validation.");
62
+ const consent = buildTenantConsentBroker(consentResult.value);
63
+ const defaultSnapshot = consent.getSnapshot();
64
+ const registryResult = validateTenantActionRegistry({
65
+ schemaVersion: 1,
66
+ actions: APPROVED_MARKETING_ACTION_NAMES.map((name) => ({ name })),
67
+ });
68
+ if (!registryResult.ok) throw new Error("The canonical action registry failed validation.");
69
+
70
+ const candidateEvents: CommerceEvent[] = [];
71
+ const candidateBroker = new CommerceEventBroker({
72
+ trusted: {
73
+ tenant: V84_NATIVE_CLONE_TENANT,
74
+ environment: candidateEnvironment.environment,
75
+ siteSurface: candidateEnvironment.siteSurface,
76
+ },
77
+ source: "urn:tot:storefront:v84-lifecycle-candidate",
78
+ consentSnapshot: () => consent.getSnapshot(),
79
+ tenantActionRegistry: registryResult.value,
80
+ now: () => AT,
81
+ });
82
+ candidateBroker.subscribe({
83
+ id: "offline-v84-candidate-receiver",
84
+ consentPurpose: "analytics",
85
+ sink: { kind: "callback", handler: (event) => candidateEvents.push(event) },
86
+ });
87
+ const candidateBridge = new ManagedAnalyticsEventBrokerBridge({ broker: candidateBroker });
88
+ const deniedInitialize = candidateBridge.initialize({
89
+ logicalId: "page-v84-candidate-initial",
90
+ path: "/v84-lifecycle",
91
+ correlation: CORRELATION,
92
+ });
93
+ if (!skipped(deniedInitialize, "consent-ineligible")) {
94
+ throw new Error("Default-denied analytics unexpectedly emitted.");
95
+ }
96
+ const grantedSnapshot = consent.setDecisions({ analytics: "granted" });
97
+ const consentUpdate = candidateBridge.consentUpdated();
98
+ const actionResults = APPROVED_MARKETING_ACTION_NAMES.map((name, index) =>
99
+ candidateBridge.activate({
100
+ logicalId: `action-v84-${index + 1}`,
101
+ name,
102
+ correlation: CORRELATION,
103
+ })
104
+ );
105
+ const documentRoute = candidateBridge.navigationCommitted({
106
+ logicalId: "route-v84-document",
107
+ path: "/v84-document",
108
+ correlation: CORRELATION,
109
+ kind: "document",
110
+ });
111
+ const redirectRoute = candidateBridge.navigationCommitted({
112
+ logicalId: "route-v84-redirect",
113
+ path: "/v84-redirect",
114
+ correlation: CORRELATION,
115
+ kind: "redirect",
116
+ });
117
+ const backForwardRoute = candidateBridge.navigationCommitted({
118
+ logicalId: "route-v84-back-forward",
119
+ path: "/v84-back-forward",
120
+ correlation: CORRELATION,
121
+ kind: "back-forward",
122
+ });
123
+ const hashRoute = candidateBridge.navigationCommitted({
124
+ logicalId: "route-v84-hash",
125
+ path: "/v84-lifecycle#review",
126
+ correlation: CORRELATION,
127
+ kind: "hash",
128
+ });
129
+ const abortedRoute = candidateBridge.navigationCommitted({
130
+ logicalId: "route-v84-aborted",
131
+ path: "/v84-aborted",
132
+ correlation: CORRELATION,
133
+ kind: "redirect",
134
+ aborted: true,
135
+ });
136
+ const duplicateInitialize = candidateBridge.initialize({
137
+ logicalId: "page-v84-duplicate",
138
+ path: "/v84-duplicate",
139
+ correlation: CORRELATION,
140
+ });
141
+ candidateBridge.dispose();
142
+ const afterDispose = candidateBridge.activate({
143
+ logicalId: "action-v84-after-dispose",
144
+ name: APPROVED_MARKETING_ACTION_NAMES[0],
145
+ correlation: CORRELATION,
146
+ });
147
+ if (
148
+ !skipped(consentUpdate, "lifecycle-unchanged") ||
149
+ actionResults.some((result) => !emitted(result)) ||
150
+ !skipped(documentRoute, "not-page-view-owner") ||
151
+ !emitted(redirectRoute) ||
152
+ !emitted(backForwardRoute) ||
153
+ !skipped(hashRoute, "not-page-view-owner") ||
154
+ !skipped(abortedRoute, "not-page-view-owner") ||
155
+ !skipped(duplicateInitialize, "already-initialized") ||
156
+ !skipped(afterDispose, "disposed")
157
+ ) {
158
+ throw new Error("The managed semantic bridge lifecycle changed.");
159
+ }
160
+
161
+ const stagedEvents: CommerceEvent[] = [];
162
+ const stagedBroker = new CommerceEventBroker({
163
+ trusted: {
164
+ tenant: V84_NATIVE_CLONE_TENANT,
165
+ environment: stagedEnvironment.environment,
166
+ siteSurface: stagedEnvironment.siteSurface,
167
+ },
168
+ source: "urn:tot:storefront:v84-lifecycle-staged",
169
+ consentSnapshot: () => consent.getSnapshot(),
170
+ tenantActionRegistry: registryResult.value,
171
+ now: () => AT,
172
+ });
173
+ stagedBroker.subscribe({
174
+ id: "offline-v84-staged-receiver",
175
+ consentPurpose: "analytics",
176
+ sink: { kind: "callback", handler: (event) => stagedEvents.push(event) },
177
+ });
178
+ const stagedBridge = new ManagedAnalyticsEventBrokerBridge({ broker: stagedBroker });
179
+ const stagedInitialize = stagedBridge.initialize({
180
+ logicalId: "page-v84-staged-initial",
181
+ path: "/v84-lifecycle",
182
+ correlation: CORRELATION,
183
+ });
184
+ stagedBridge.dispose();
185
+ if (!emitted(stagedInitialize)) throw new Error("The staged in-memory lifecycle did not initialize once.");
186
+
187
+ const allEvents = [...candidateEvents, ...stagedEvents];
188
+ const actionEvents = candidateEvents.filter((event) => event.type === "storefront.action.activated.v1");
189
+ const routeEvents = candidateEvents.filter((event) => event.type === "storefront.page.viewed.v2");
190
+ const actionPayloadKeys = actionEvents[0] ? Object.keys(actionEvents[0].data).sort() : [];
191
+ if (
192
+ candidateEvents.length !== 7 ||
193
+ stagedEvents.length !== 1 ||
194
+ actionEvents.length !== APPROVED_MARKETING_ACTION_NAMES.length ||
195
+ stableIntegrationStringify(actionEvents.map((event) => event.data["name"])) !==
196
+ stableIntegrationStringify(APPROVED_MARKETING_ACTION_NAMES) ||
197
+ actionEvents.some((event) => stableIntegrationStringify(Object.keys(event.data).sort()) !== '["name"]') ||
198
+ stableIntegrationStringify(routeEvents.map((event) => event.data)) !==
199
+ stableIntegrationStringify([{ path: "/v84-redirect" }, { path: "/v84-back-forward" }]) ||
200
+ stableIntegrationStringify(stagedEvents.map((event) => event.data)) !==
201
+ stableIntegrationStringify([{ path: "/v84-lifecycle" }]) ||
202
+ allEvents.some((event) => event.storefront.tenant !== V84_NATIVE_CLONE_TENANT) ||
203
+ allEvents.some((event) => event.storefront.environment === "live")
204
+ ) {
205
+ throw new Error("The in-memory event evidence escaped its clone/non-live scope.");
206
+ }
207
+
208
+ return {
209
+ candidateEnvironment,
210
+ stagedEnvironment,
211
+ consent: {
212
+ purpose: "analytics" as const,
213
+ defaultEligible: defaultSnapshot.eligiblePurposes,
214
+ grantedEligible: grantedSnapshot.eligiblePurposes,
215
+ defaultInitializeEmitted: false,
216
+ consentUpdateReinitialized: false,
217
+ },
218
+ lifecycle: {
219
+ candidateInitializeCount: 1,
220
+ stagedInitializeCount: 1,
221
+ duplicateInitializeEmitted: false,
222
+ disposeTerminal: true,
223
+ destinationKind: "in-memory-callback" as const,
224
+ },
225
+ routes: {
226
+ documentOwner: "document-bootstrap" as const,
227
+ redirectOwner: "navigation-commit" as const,
228
+ backForwardOwner: "navigation-commit" as const,
229
+ hashOwner: "none" as const,
230
+ abortedOwner: "none" as const,
231
+ emittedRouteCount: 2,
232
+ },
233
+ actions: {
234
+ approvedNames: [...APPROVED_MARKETING_ACTION_NAMES],
235
+ emittedCount: actionResults.length,
236
+ duplicateNames: new Set(APPROVED_MARKETING_ACTION_NAMES).size === APPROVED_MARKETING_ACTION_NAMES.length ? 0 : 1,
237
+ payloadKeys: actionPayloadKeys,
238
+ },
239
+ inMemoryEventDeliveries: allEvents.length,
240
+ };
241
+ }