@delmaredigital/payload-experiments 0.3.0-rc.4 → 0.4.0-rc.10

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 (658) hide show
  1. package/README.md +293 -688
  2. package/dist/admin/LayerUsage.js +1 -1
  3. package/dist/admin/MetricSourceSelect.js +4 -4
  4. package/dist/admin/PlacementStatus.d.ts +3 -0
  5. package/dist/admin/PlacementStatus.js +54 -0
  6. package/dist/admin/TestsDashboardCards.d.ts +1 -0
  7. package/dist/admin/TestsDashboardCards.js +5 -9
  8. package/dist/admin/TestsNavLink.d.ts +1 -0
  9. package/dist/admin/TestsNavLink.js +5 -11
  10. package/dist/admin/blocks/BlockPanel.d.ts +5 -0
  11. package/dist/admin/blocks/BlockPanel.js +245 -0
  12. package/dist/admin/blocks/TestBlockField.d.ts +5 -0
  13. package/dist/admin/blocks/TestBlockField.js +163 -0
  14. package/dist/admin/blocks/formApi.d.ts +46 -0
  15. package/dist/admin/blocks/formApi.js +159 -0
  16. package/dist/admin/blocks/inject.d.ts +7 -0
  17. package/dist/admin/blocks/inject.js +42 -0
  18. package/dist/admin/blocks/model.d.ts +18 -0
  19. package/dist/admin/blocks/model.js +49 -0
  20. package/dist/admin/blocks/statusCache.d.ts +9 -0
  21. package/dist/admin/blocks/statusCache.js +92 -0
  22. package/dist/admin/blocks/useBlockForm.d.ts +17 -0
  23. package/dist/admin/blocks/useBlockForm.js +46 -0
  24. package/dist/admin/components/RootViewMessage.js +1 -1
  25. package/dist/admin/copy/blocks.d.ts +47 -0
  26. package/dist/admin/copy/blocks.js +72 -0
  27. package/dist/admin/copy/goals.d.ts +8 -1
  28. package/dist/admin/copy/goals.js +14 -4
  29. package/dist/admin/copy/newTest.d.ts +13 -4
  30. package/dist/admin/copy/newTest.js +16 -4
  31. package/dist/admin/goals/XpGoalField.d.ts +4 -0
  32. package/dist/admin/goals/XpGoalField.js +194 -0
  33. package/dist/admin/goals/xpGoalField.css +47 -0
  34. package/dist/admin/pageCollections.d.ts +11 -0
  35. package/dist/admin/pageCollections.js +23 -0
  36. package/dist/admin/paths.d.ts +9 -0
  37. package/dist/admin/paths.js +9 -0
  38. package/dist/admin/placementStatus.model.d.ts +2 -0
  39. package/dist/admin/placementStatus.model.js +19 -0
  40. package/dist/admin/status.model.js +1 -1
  41. package/dist/admin/surface/ResultsRoute.d.ts +2 -1
  42. package/dist/admin/surface/ResultsRoute.js +20 -24
  43. package/dist/admin/surface/SurfaceShell.js +5 -2
  44. package/dist/admin/surface/TestRowMenu.d.ts +6 -0
  45. package/dist/admin/surface/TestRowMenu.js +156 -0
  46. package/dist/admin/surface/TestsHome.d.ts +5 -3
  47. package/dist/admin/surface/TestsHome.js +298 -59
  48. package/dist/admin/surface/TestsSurface.js +13 -8
  49. package/dist/admin/surface/goals/GoalForm.d.ts +1 -1
  50. package/dist/admin/surface/goals/GoalForm.js +159 -85
  51. package/dist/admin/surface/goals/GoalsList.d.ts +1 -1
  52. package/dist/admin/surface/goals/GoalsList.js +7 -6
  53. package/dist/admin/surface/goals/data.js +6 -3
  54. package/dist/admin/surface/goals/goals.css +7 -0
  55. package/dist/admin/surface/goals/goals.model.d.ts +12 -3
  56. package/dist/admin/surface/goals/goals.model.js +43 -2
  57. package/dist/admin/surface/home.model.d.ts +9 -8
  58. package/dist/admin/surface/home.model.js +28 -23
  59. package/dist/admin/surface/newTest/NewTest.d.ts +4 -4
  60. package/dist/admin/surface/newTest/NewTest.js +146 -101
  61. package/dist/admin/surface/newTest/PageWizard.d.ts +8 -0
  62. package/dist/admin/surface/newTest/PageWizard.js +244 -0
  63. package/dist/admin/surface/newTest/newTest.css +28 -9
  64. package/dist/admin/surface/results/ResultsHeader.d.ts +2 -2
  65. package/dist/admin/surface/results/ResultsHeader.js +58 -57
  66. package/dist/admin/surface/surface.css +10 -0
  67. package/dist/admin/surface/test/TestPage.d.ts +1 -2
  68. package/dist/admin/surface/test/TestPage.js +42 -161
  69. package/dist/admin/theme.css +2 -0
  70. package/dist/admin/views/CollectionListRedirect.d.ts +1 -0
  71. package/dist/admin/views/CollectionListRedirect.js +1 -1
  72. package/dist/admin/views/ExperimentsRootView.js +28 -133
  73. package/dist/admin/views/GoalEditRedirect.d.ts +4 -0
  74. package/dist/admin/views/GoalEditRedirect.js +14 -0
  75. package/dist/admin/views/GoalsCollectionListView.d.ts +2 -0
  76. package/dist/admin/views/GoalsCollectionListView.js +4 -0
  77. package/dist/admin/views/TestsCollectionListView.d.ts +2 -0
  78. package/dist/admin/views/TestsCollectionListView.js +4 -0
  79. package/dist/admin/views/TestsNavLinkServer.d.ts +1 -0
  80. package/dist/admin/views/TestsNavLinkServer.js +2 -2
  81. package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
  82. package/dist/admin/views/TestsSurfaceClient.js +11 -0
  83. package/dist/admin/views/buildSurfaceProps.d.ts +8 -0
  84. package/dist/admin/views/buildSurfaceProps.js +102 -0
  85. package/dist/admin/views/renderCollectionList.d.ts +2 -0
  86. package/dist/admin/views/renderCollectionList.js +34 -0
  87. package/dist/admin/views/renderTestsSurface.d.ts +3 -0
  88. package/dist/admin/views/renderTestsSurface.js +34 -0
  89. package/dist/blocks/bindings.d.ts +3 -0
  90. package/dist/blocks/bindings.js +28 -0
  91. package/dist/blocks/createExperimentBlock.d.ts +6 -0
  92. package/dist/blocks/createExperimentBlock.js +77 -0
  93. package/dist/blocks/formState.d.ts +31 -0
  94. package/dist/blocks/formState.js +146 -0
  95. package/dist/blocks/model.d.ts +41 -0
  96. package/dist/blocks/model.js +34 -0
  97. package/dist/blocks/placementLanguages.d.ts +7 -0
  98. package/dist/blocks/placementLanguages.js +27 -0
  99. package/dist/blocks/placementLocale.d.ts +37 -0
  100. package/dist/blocks/placementLocale.js +270 -0
  101. package/dist/client/ExperimentGroup.d.ts +6 -0
  102. package/dist/client/ExperimentGroup.js +9 -0
  103. package/dist/client/ExperimentsProvider.js +20 -4
  104. package/dist/client/clickGoals.d.ts +4 -0
  105. package/dist/client/clickGoals.js +43 -0
  106. package/dist/collections/experiments/config.js +29 -10
  107. package/dist/collections/experiments/deleteGuard.d.ts +2 -1
  108. package/dist/collections/experiments/deleteGuard.js +14 -3
  109. package/dist/collections/experiments/editability.js +4 -2
  110. package/dist/collections/experiments/lockHook.js +21 -2
  111. package/dist/collections/experiments/pickSlug.d.ts +2 -0
  112. package/dist/collections/experiments/pickSlug.js +10 -0
  113. package/dist/collections/labels.d.ts +3 -0
  114. package/dist/collections/labels.js +20 -0
  115. package/dist/collections/metrics.js +28 -6
  116. package/dist/collections/metricsGuards.js +2 -0
  117. package/dist/collections/phases.js +1 -0
  118. package/dist/collections/serialize.js +12 -4
  119. package/dist/constants.d.ts +1 -0
  120. package/dist/constants.js +1 -0
  121. package/dist/db/adapter.d.ts +9 -1
  122. package/dist/db/adapter.js +77 -1
  123. package/dist/db/appends.d.ts +13 -0
  124. package/dist/db/appends.js +49 -0
  125. package/dist/db/bulkPlacementRemoval.d.ts +30 -0
  126. package/dist/db/bulkPlacementRemoval.js +111 -0
  127. package/dist/db/clickGoals.d.ts +9 -0
  128. package/dist/db/clickGoals.js +22 -0
  129. package/dist/db/delete.d.ts +2 -1
  130. package/dist/db/delete.js +3 -4
  131. package/dist/db/events.d.ts +9 -0
  132. package/dist/db/events.js +42 -8
  133. package/dist/db/executor.d.ts +7 -1
  134. package/dist/db/executor.js +7 -3
  135. package/dist/db/locks.d.ts +8 -0
  136. package/dist/db/locks.js +27 -4
  137. package/dist/db/names.d.ts +4 -0
  138. package/dist/db/names.js +4 -0
  139. package/dist/db/pageBindings.d.ts +4 -0
  140. package/dist/db/pageBindings.js +17 -0
  141. package/dist/db/pageBusy.d.ts +2 -0
  142. package/dist/db/pageBusy.js +10 -0
  143. package/dist/db/pageContent.d.ts +10 -0
  144. package/dist/db/pageContent.js +79 -0
  145. package/dist/db/pageCopies.d.ts +5 -0
  146. package/dist/db/pageCopies.js +31 -0
  147. package/dist/db/placements.d.ts +35 -0
  148. package/dist/db/placements.js +62 -0
  149. package/dist/db/results.d.ts +5 -1
  150. package/dist/db/results.js +21 -5
  151. package/dist/db/slugs.d.ts +8 -0
  152. package/dist/db/slugs.js +40 -0
  153. package/dist/db/snapshots.d.ts +7 -0
  154. package/dist/db/snapshots.js +8 -5
  155. package/dist/endpoints/clickKeys.d.ts +5 -0
  156. package/dist/endpoints/clickKeys.js +17 -0
  157. package/dist/endpoints/contentLocale.d.ts +6 -0
  158. package/dist/endpoints/contentLocale.js +15 -0
  159. package/dist/endpoints/deleteImpact.d.ts +6 -0
  160. package/dist/endpoints/deleteImpact.js +207 -0
  161. package/dist/endpoints/duplicateOriginal.d.ts +38 -0
  162. package/dist/endpoints/duplicateOriginal.js +407 -0
  163. package/dist/endpoints/editorSurface.d.ts +3 -0
  164. package/dist/endpoints/editorSurface.js +31 -0
  165. package/dist/endpoints/events.js +106 -39
  166. package/dist/endpoints/index.js +85 -9
  167. package/dist/endpoints/pages.d.ts +5 -0
  168. package/dist/endpoints/pages.js +303 -0
  169. package/dist/endpoints/placementStatus.d.ts +6 -0
  170. package/dist/endpoints/placementStatus.js +246 -0
  171. package/dist/endpoints/preflight.d.ts +1 -1
  172. package/dist/endpoints/preflight.js +17 -2
  173. package/dist/endpoints/readBody.d.ts +2 -0
  174. package/dist/endpoints/readBody.js +24 -0
  175. package/dist/endpoints/results.d.ts +1 -1
  176. package/dist/endpoints/results.js +10 -2
  177. package/dist/endpoints/routeId.d.ts +2 -2
  178. package/dist/endpoints/routeId.js +11 -5
  179. package/dist/endpoints/summary.js +46 -5
  180. package/dist/endpoints/testVersion.d.ts +2 -0
  181. package/dist/endpoints/testVersion.js +38 -0
  182. package/dist/endpoints/transitions.js +41 -29
  183. package/dist/endpoints/wrapBlock.d.ts +6 -0
  184. package/dist/endpoints/wrapBlock.js +76 -0
  185. package/dist/errors.d.ts +7 -2
  186. package/dist/errors.js +11 -3
  187. package/dist/events/request.d.ts +6 -2
  188. package/dist/events/request.js +35 -8
  189. package/dist/events/rows.d.ts +1 -1
  190. package/dist/events/rows.js +25 -7
  191. package/dist/events/writable.d.ts +9 -0
  192. package/dist/events/writable.js +13 -0
  193. package/dist/exports/adminClient.d.ts +6 -1
  194. package/dist/exports/adminClient.js +6 -1
  195. package/dist/exports/adminRsc.d.ts +3 -0
  196. package/dist/exports/adminRsc.js +3 -0
  197. package/dist/exports/blocks.d.ts +2 -0
  198. package/dist/exports/blocks.js +1 -0
  199. package/dist/exports/client.d.ts +1 -0
  200. package/dist/exports/client.js +1 -0
  201. package/dist/exports/index.d.ts +6 -1
  202. package/dist/exports/index.js +3 -0
  203. package/dist/exports/puck.d.ts +3 -1
  204. package/dist/exports/puck.js +2 -0
  205. package/dist/exports/puckEditor.d.ts +3 -0
  206. package/dist/exports/puckEditor.js +2 -0
  207. package/dist/exports/rsc.d.ts +4 -0
  208. package/dist/exports/rsc.js +3 -0
  209. package/dist/fields/xpGoal.d.ts +3 -0
  210. package/dist/fields/xpGoal.js +16 -0
  211. package/dist/globals/state.js +10 -0
  212. package/dist/goals/cache.d.ts +3 -0
  213. package/dist/goals/cache.js +35 -0
  214. package/dist/goals/fairness.d.ts +40 -0
  215. package/dist/goals/fairness.js +209 -0
  216. package/dist/goals/key.d.ts +4 -0
  217. package/dist/goals/key.js +3 -0
  218. package/dist/goals/picker/clickGoalPicker.model.d.ts +36 -0
  219. package/dist/goals/picker/clickGoalPicker.model.js +63 -0
  220. package/dist/goals/picker/copy.d.ts +20 -0
  221. package/dist/goals/picker/copy.js +24 -0
  222. package/dist/goals/picker/useClickGoalPicker.d.ts +30 -0
  223. package/dist/goals/picker/useClickGoalPicker.js +222 -0
  224. package/dist/goals/validate.d.ts +3 -0
  225. package/dist/goals/validate.js +15 -0
  226. package/dist/hooks/blockRemovalRule.d.ts +30 -0
  227. package/dist/hooks/blockRemovalRule.js +165 -0
  228. package/dist/hooks/hostHook.js +6 -2
  229. package/dist/hooks/pageGuard.d.ts +30 -1
  230. package/dist/hooks/pageGuard.js +337 -107
  231. package/dist/hooks/puckGoals.d.ts +5 -0
  232. package/dist/hooks/puckGoals.js +62 -0
  233. package/dist/hooks/puckNestedTests.d.ts +8 -0
  234. package/dist/hooks/puckNestedTests.js +36 -0
  235. package/dist/hooks/trackPageCopies.d.ts +11 -0
  236. package/dist/hooks/trackPageCopies.js +7 -0
  237. package/dist/lib/fetchAllDocs.d.ts +1 -1
  238. package/dist/lib/placementPages.d.ts +10 -0
  239. package/dist/{admin/previewLinks.model.js → lib/placementPages.js} +10 -5
  240. package/dist/manifest/compile.d.ts +2 -1
  241. package/dist/manifest/compile.js +13 -6
  242. package/dist/onInit.js +65 -0
  243. package/dist/options.d.ts +4 -0
  244. package/dist/options.js +62 -1
  245. package/dist/plugin.js +56 -44
  246. package/dist/proxy/pageNavigation.d.ts +4 -0
  247. package/dist/proxy/pageNavigation.js +28 -0
  248. package/dist/proxy/resolve.js +52 -25
  249. package/dist/puck/ExperimentPicker.d.ts +2 -1
  250. package/dist/puck/ExperimentPicker.js +62 -40
  251. package/dist/puck/ExperimentSlot.js +3 -1
  252. package/dist/puck/copy.d.ts +6 -1
  253. package/dist/puck/copy.js +6 -1
  254. package/dist/puck/editor/ConfigureTestDrawer.d.ts +25 -0
  255. package/dist/puck/editor/ConfigureTestDrawer.js +150 -0
  256. package/dist/puck/editor/CreateExperimentDrawer.d.ts +12 -2
  257. package/dist/puck/editor/CreateExperimentDrawer.js +89 -21
  258. package/dist/puck/editor/EditorControls.d.ts +14 -0
  259. package/dist/puck/editor/EditorControls.js +99 -0
  260. package/dist/puck/editor/ExperimentSlotEditor.js +951 -179
  261. package/dist/puck/editor/LeftoverVersions.d.ts +15 -0
  262. package/dist/puck/editor/LeftoverVersions.js +79 -0
  263. package/dist/puck/editor/PlacementNotice.d.ts +8 -0
  264. package/dist/puck/editor/PlacementNotice.js +22 -0
  265. package/dist/puck/editor/QuickTestActions.d.ts +6 -0
  266. package/dist/puck/editor/QuickTestActions.js +57 -0
  267. package/dist/puck/editor/ResultsReadout.d.ts +2 -1
  268. package/dist/puck/editor/ResultsReadout.js +10 -6
  269. package/dist/puck/editor/VersionBuilder.d.ts +66 -12
  270. package/dist/puck/editor/VersionBuilder.js +554 -231
  271. package/dist/puck/editor/armWrites.d.ts +11 -2
  272. package/dist/puck/editor/armWrites.js +43 -4
  273. package/dist/puck/editor/armsCache.d.ts +3 -1
  274. package/dist/puck/editor/armsCache.js +20 -4
  275. package/dist/puck/editor/blockClipboard.d.ts +16 -0
  276. package/dist/puck/editor/blockClipboard.js +20 -0
  277. package/dist/puck/editor/cloneSlot.d.ts +2 -0
  278. package/dist/puck/editor/cloneSlot.js +7 -0
  279. package/dist/puck/editor/copy.d.ts +64 -19
  280. package/dist/puck/editor/copy.js +72 -20
  281. package/dist/puck/editor/createTest.d.ts +3 -0
  282. package/dist/puck/editor/createTest.js +33 -0
  283. package/dist/puck/editor/editor.chrome.css +192 -19
  284. package/dist/puck/editor/editor.css +329 -24
  285. package/dist/puck/editor/editor.model.d.ts +21 -3
  286. package/dist/puck/editor/editor.model.js +67 -7
  287. package/dist/puck/editor/editorSurface.d.ts +10 -0
  288. package/dist/puck/editor/editorSurface.js +65 -0
  289. package/dist/puck/editor/experimentOutlinePlugin.js +96 -28
  290. package/dist/puck/editor/integration.d.ts +10 -0
  291. package/dist/puck/editor/integration.js +30 -0
  292. package/dist/puck/editor/localPlacements.d.ts +5 -0
  293. package/dist/puck/editor/localPlacements.js +43 -0
  294. package/dist/puck/editor/outlineVersion.d.ts +5 -0
  295. package/dist/puck/editor/outlineVersion.js +36 -0
  296. package/dist/puck/editor/placementsCache.d.ts +60 -0
  297. package/dist/puck/editor/placementsCache.js +263 -0
  298. package/dist/puck/editor/sidebar.d.ts +8 -0
  299. package/dist/puck/editor/sidebar.js +74 -0
  300. package/dist/puck/editor/usePageSaveReadiness.d.ts +6 -0
  301. package/dist/puck/editor/usePageSaveReadiness.js +31 -0
  302. package/dist/puck/editor/usePlacementNotice.d.ts +3 -0
  303. package/dist/puck/editor/usePlacementNotice.js +15 -0
  304. package/dist/puck/editor/xpGoalPuckEditorField.d.ts +7 -0
  305. package/dist/puck/editor/xpGoalPuckEditorField.js +153 -0
  306. package/dist/puck/experimentSlotField.d.ts +3 -0
  307. package/dist/puck/experimentSlotField.js +15 -4
  308. package/dist/puck/experimentSlug.d.ts +2 -0
  309. package/dist/puck/experimentSlug.js +3 -0
  310. package/dist/puck/integration.d.ts +6 -0
  311. package/dist/puck/integration.js +21 -0
  312. package/dist/puck/nestedTestCopy.d.ts +8 -0
  313. package/dist/puck/nestedTestCopy.js +22 -0
  314. package/dist/puck/nestedTests.d.ts +17 -0
  315. package/dist/puck/nestedTests.js +30 -0
  316. package/dist/puck/slotConfig.d.ts +1 -1
  317. package/dist/puck/slotConfig.js +17 -4
  318. package/dist/puck/visibility.d.ts +20 -0
  319. package/dist/puck/visibility.js +81 -0
  320. package/dist/puck/xpGoalField.d.ts +3 -0
  321. package/dist/puck/xpGoalField.js +6 -0
  322. package/dist/results/aggregate.d.ts +6 -3
  323. package/dist/results/aggregate.js +9 -9
  324. package/dist/results/health.d.ts +12 -0
  325. package/dist/results/health.js +55 -0
  326. package/dist/results/identityCredit.d.ts +1 -0
  327. package/dist/results/identityCredit.js +4 -1
  328. package/dist/results/snapshot.js +15 -2
  329. package/dist/results/verdict.js +2 -1
  330. package/dist/runtime/cookie.d.ts +10 -2
  331. package/dist/runtime/cookie.js +38 -6
  332. package/dist/runtime/cookieOptions.d.ts +6 -0
  333. package/dist/runtime/cookieOptions.js +14 -0
  334. package/dist/runtime/proxyRuntime.d.ts +1 -0
  335. package/dist/runtime/proxyRuntime.js +18 -8
  336. package/dist/runtime/signing.d.ts +1 -0
  337. package/dist/runtime/signing.js +5 -0
  338. package/dist/sanitizeReadinessDetail.d.ts +2 -2
  339. package/dist/sanitizeReadinessDetail.js +63 -2
  340. package/dist/server/getAssignments.js +11 -10
  341. package/dist/server/pageKindSeoContract.d.ts +27 -0
  342. package/dist/server/pageKindSeoContract.js +80 -0
  343. package/dist/server/recordContentChange.d.ts +1 -1
  344. package/dist/server/recordContentChange.js +88 -12
  345. package/dist/server/resolveExperimentBlocks.d.ts +5 -0
  346. package/dist/server/resolveExperimentBlocks.js +52 -0
  347. package/dist/server/resolveExperimentData.js +8 -8
  348. package/dist/server/runResults.js +104 -25
  349. package/dist/server/startExperiment.d.ts +20 -0
  350. package/dist/server/startExperiment.js +70 -0
  351. package/dist/server/toClientAssignments.js +2 -1
  352. package/dist/server/trackConversion.js +10 -13
  353. package/dist/{admin → testSurface}/PreviewLinks.d.ts +2 -1
  354. package/dist/{admin → testSurface}/PreviewLinks.js +8 -4
  355. package/dist/testSurface/actions/DecideDialog.d.ts +16 -0
  356. package/dist/{admin → testSurface}/actions/DecideDialog.js +79 -56
  357. package/dist/testSurface/actions/LifecycleAction.d.ts +16 -0
  358. package/dist/testSurface/actions/LifecycleAction.js +105 -0
  359. package/dist/{admin → testSurface}/actions/MakeContentResult.d.ts +4 -3
  360. package/dist/{admin → testSurface}/actions/MakeContentResult.js +10 -2
  361. package/dist/{admin → testSurface}/actions/actions.model.d.ts +13 -5
  362. package/dist/testSurface/actions/actions.model.js +122 -0
  363. package/dist/testSurface/api.d.ts +60 -0
  364. package/dist/testSurface/api.js +167 -0
  365. package/dist/testSurface/contentLocaleURL.d.ts +2 -0
  366. package/dist/testSurface/contentLocaleURL.js +3 -0
  367. package/dist/{admin → testSurface}/copy/actions.d.ts +30 -8
  368. package/dist/{admin → testSurface}/copy/actions.js +40 -11
  369. package/dist/{admin → testSurface}/copy/common.d.ts +13 -4
  370. package/dist/{admin → testSurface}/copy/common.js +18 -8
  371. package/dist/testSurface/copy/languages.d.ts +12 -0
  372. package/dist/testSurface/copy/languages.js +8 -0
  373. package/dist/{admin → testSurface}/copy/metrics.d.ts +1 -0
  374. package/dist/{admin → testSurface}/copy/metrics.js +1 -0
  375. package/dist/testSurface/copy/pages.d.ts +84 -0
  376. package/dist/testSurface/copy/pages.js +90 -0
  377. package/dist/{admin → testSurface}/copy/readiness.d.ts +59 -6
  378. package/dist/testSurface/copy/readiness.js +136 -0
  379. package/dist/{admin → testSurface}/copy/results.d.ts +7 -3
  380. package/dist/{admin → testSurface}/copy/results.js +7 -3
  381. package/dist/{admin → testSurface}/copy/review.d.ts +1 -1
  382. package/dist/{admin → testSurface}/copy/review.js +1 -1
  383. package/dist/{admin → testSurface}/copy/surface.d.ts +11 -2
  384. package/dist/{admin → testSurface}/copy/surface.js +13 -10
  385. package/dist/{admin → testSurface}/copy/testPage.d.ts +56 -7
  386. package/dist/testSurface/copy/testPage.js +165 -0
  387. package/dist/testSurface/format/adminURL.d.ts +7 -0
  388. package/dist/testSurface/format/adminURL.js +9 -0
  389. package/dist/{admin → testSurface}/metricSource.model.d.ts +2 -0
  390. package/dist/{admin → testSurface}/metricSource.model.js +4 -0
  391. package/dist/testSurface/placementLabel.d.ts +8 -0
  392. package/dist/testSurface/placementLabel.js +24 -0
  393. package/dist/testSurface/placements/placementLabels.d.ts +13 -0
  394. package/dist/testSurface/placements/placementLabels.js +22 -0
  395. package/dist/testSurface/placements/placementLabels.model.d.ts +13 -0
  396. package/dist/testSurface/placements/placementLabels.model.js +12 -0
  397. package/dist/testSurface/placements/usePlacementLabels.d.ts +12 -0
  398. package/dist/testSurface/placements/usePlacementLabels.js +102 -0
  399. package/dist/{admin → testSurface}/previewLinks.model.d.ts +1 -6
  400. package/dist/testSurface/previewLinks.model.js +4 -0
  401. package/dist/testSurface/readPreflight.d.ts +13 -0
  402. package/dist/testSurface/readPreflight.js +44 -0
  403. package/dist/testSurface/readinessRead.d.ts +53 -0
  404. package/dist/testSurface/readinessRead.js +50 -0
  405. package/dist/{admin → testSurface}/results/DataQualityPanel.js +4 -1
  406. package/dist/{admin → testSurface}/results/VerdictHero.d.ts +2 -1
  407. package/dist/{admin → testSurface}/results/VerdictHero.js +5 -1
  408. package/dist/testSurface/results/results.css +64 -0
  409. package/dist/{admin → testSurface}/results/results.model.d.ts +3 -0
  410. package/dist/{admin → testSurface}/results/results.model.js +14 -6
  411. package/dist/{admin → testSurface}/surface/contracts.d.ts +23 -8
  412. package/dist/testSurface/surface/editorPlacement.d.ts +26 -0
  413. package/dist/testSurface/surface/editorPlacement.js +78 -0
  414. package/dist/testSurface/surface/pageBlock/pageBlock.model.js +9 -0
  415. package/dist/{admin → testSurface}/surface/pageBlock/parts.js +39 -11
  416. package/dist/testSurface/surface/pagePicker/CopyRoute.d.ts +13 -0
  417. package/dist/testSurface/surface/pagePicker/CopyRoute.js +273 -0
  418. package/dist/testSurface/surface/pagePicker/PageCombobox.d.ts +21 -0
  419. package/dist/testSurface/surface/pagePicker/PageCombobox.js +503 -0
  420. package/dist/testSurface/surface/pagePicker/pagePicker.css +73 -0
  421. package/dist/testSurface/surface/pagePicker/pagePicker.model.d.ts +29 -0
  422. package/dist/testSurface/surface/pagePicker/pagePicker.model.js +40 -0
  423. package/dist/{admin → testSurface}/surface/readiness/ActionDialogs.d.ts +8 -4
  424. package/dist/testSurface/surface/readiness/ActionDialogs.js +351 -0
  425. package/dist/{admin → testSurface}/surface/readiness/Banner.d.ts +2 -3
  426. package/dist/testSurface/surface/readiness/Banner.js +187 -0
  427. package/dist/testSurface/surface/readiness/BlockerList.d.ts +11 -0
  428. package/dist/testSurface/surface/readiness/BlockerList.js +31 -0
  429. package/dist/testSurface/surface/readiness/SaveStatus.d.ts +10 -0
  430. package/dist/testSurface/surface/readiness/SaveStatus.js +66 -0
  431. package/dist/{admin → testSurface}/surface/readiness/parts.js +0 -2
  432. package/dist/testSurface/surface/readiness/readiness.model.d.ts +57 -0
  433. package/dist/testSurface/surface/readiness/readiness.model.js +377 -0
  434. package/dist/testSurface/surface/readiness/useTransition.d.ts +16 -0
  435. package/dist/testSurface/surface/readiness/useTransition.js +141 -0
  436. package/dist/testSurface/surface/results/ReleasePages.d.ts +19 -0
  437. package/dist/{admin → testSurface}/surface/results/ReleasePages.js +43 -47
  438. package/dist/{admin → testSurface}/surface/results/ResultsBody.d.ts +7 -3
  439. package/dist/{admin → testSurface}/surface/results/ResultsBody.js +129 -46
  440. package/dist/{admin → testSurface}/surface/results/useResults.d.ts +36 -9
  441. package/dist/{admin → testSurface}/surface/results/useResults.js +3 -2
  442. package/dist/{admin → testSurface}/surface/setting/parts.js +58 -18
  443. package/dist/testSurface/surface/setting/setting.css +17 -0
  444. package/dist/testSurface/surface/test/AdvancedSection.js +169 -0
  445. package/dist/testSurface/surface/test/DeleteTest.d.ts +23 -0
  446. package/dist/testSurface/surface/test/DeleteTest.js +270 -0
  447. package/dist/testSurface/surface/test/GoalSection.d.ts +4 -0
  448. package/dist/testSurface/surface/test/GoalSection.js +341 -0
  449. package/dist/testSurface/surface/test/LengthSection.d.ts +2 -0
  450. package/dist/{admin → testSurface}/surface/test/LengthSection.js +6 -2
  451. package/dist/testSurface/surface/test/PageHoldout.d.ts +3 -0
  452. package/dist/testSurface/surface/test/PageHoldout.js +70 -0
  453. package/dist/{admin → testSurface}/surface/test/Rail.js +7 -4
  454. package/dist/{admin → testSurface}/surface/test/ReadinessBar.d.ts +1 -0
  455. package/dist/{admin → testSurface}/surface/test/ReadinessBar.js +2 -3
  456. package/dist/{admin → testSurface}/surface/test/Section.d.ts +3 -1
  457. package/dist/testSurface/surface/test/Section.js +80 -0
  458. package/dist/{admin → testSurface}/surface/test/TargetingSection.js +82 -12
  459. package/dist/testSurface/surface/test/TestSurface.d.ts +19 -0
  460. package/dist/testSurface/surface/test/TestSurface.js +265 -0
  461. package/dist/testSurface/surface/test/VersionsSection.d.ts +5 -0
  462. package/dist/{admin → testSurface}/surface/test/VersionsSection.js +81 -40
  463. package/dist/{admin → testSurface}/surface/test/fields.d.ts +40 -8
  464. package/dist/testSurface/surface/test/fields.js +306 -0
  465. package/dist/{admin → testSurface}/surface/test/jumpToSection.d.ts +1 -1
  466. package/dist/{admin → testSurface}/surface/test/jumpToSection.js +4 -3
  467. package/dist/testSurface/surface/test/pageParts.d.ts +5 -0
  468. package/dist/testSurface/surface/test/pageParts.js +106 -0
  469. package/dist/testSurface/surface/test/testPage.css +103 -0
  470. package/dist/{admin → testSurface}/surface/test/testPage.model.d.ts +1 -0
  471. package/dist/{admin → testSurface}/surface/test/testPage.model.js +6 -0
  472. package/dist/{admin → testSurface}/surface/testDocument.model.d.ts +4 -0
  473. package/dist/{admin → testSurface}/surface/testDocument.model.js +6 -2
  474. package/dist/testSurface/surface/useTestDocument.d.ts +60 -0
  475. package/dist/testSurface/surface/useTestDocument.js +782 -0
  476. package/dist/testSurface/surface/watchTestDocument.d.ts +15 -0
  477. package/dist/testSurface/surface/watchTestDocument.js +181 -0
  478. package/dist/testSurface/surfaceUrls.d.ts +7 -0
  479. package/dist/testSurface/surfaceUrls.js +19 -0
  480. package/dist/testSurface/useApi.d.ts +60 -0
  481. package/dist/testSurface/useApi.js +8 -0
  482. package/dist/testSurface/useOnTestReturn.d.ts +2 -0
  483. package/dist/testSurface/useOnTestReturn.js +27 -0
  484. package/dist/testSurface/useReadinessPolling.d.ts +3 -0
  485. package/dist/testSurface/useReadinessPolling.js +26 -0
  486. package/dist/transitions/addMetric.d.ts +4 -6
  487. package/dist/transitions/addMetric.js +33 -2
  488. package/dist/transitions/allocate.d.ts +2 -2
  489. package/dist/transitions/allocate.js +3 -1
  490. package/dist/transitions/archive.d.ts +1 -1
  491. package/dist/transitions/archive.js +3 -2
  492. package/dist/transitions/checkStart.d.ts +18 -1
  493. package/dist/transitions/checkStart.js +207 -9
  494. package/dist/transitions/contentFields.js +9 -5
  495. package/dist/transitions/decide.d.ts +1 -1
  496. package/dist/transitions/decide.js +30 -3
  497. package/dist/transitions/deleteExperiment.d.ts +5 -3
  498. package/dist/transitions/deleteExperiment.js +43 -7
  499. package/dist/transitions/kernel.d.ts +4 -0
  500. package/dist/transitions/kernel.js +13 -4
  501. package/dist/transitions/makeContent.d.ts +7 -1
  502. package/dist/transitions/makeContent.js +74 -22
  503. package/dist/transitions/nestedPlacementNames.d.ts +5 -0
  504. package/dist/transitions/nestedPlacementNames.js +32 -0
  505. package/dist/transitions/pageAddress.d.ts +6 -0
  506. package/dist/transitions/pageAddress.js +71 -0
  507. package/dist/transitions/pageCollection.d.ts +10 -0
  508. package/dist/transitions/pageCollection.js +20 -0
  509. package/dist/transitions/pageVersions.d.ts +10 -0
  510. package/dist/transitions/pageVersions.js +46 -0
  511. package/dist/transitions/phaseRecord.d.ts +3 -0
  512. package/dist/transitions/phaseRecord.js +5 -0
  513. package/dist/transitions/placementInteractions.d.ts +40 -0
  514. package/dist/transitions/placementInteractions.js +98 -0
  515. package/dist/transitions/placements.d.ts +58 -4
  516. package/dist/transitions/placements.js +391 -21
  517. package/dist/transitions/preflightData.d.ts +7 -5
  518. package/dist/transitions/preflightData.js +269 -40
  519. package/dist/transitions/releaseHoldout.d.ts +2 -1
  520. package/dist/transitions/releaseHoldout.js +3 -1
  521. package/dist/transitions/releasePages.d.ts +2 -1
  522. package/dist/transitions/releasePages.js +3 -1
  523. package/dist/transitions/resolveCaps.d.ts +3 -4
  524. package/dist/transitions/resolveCaps.js +6 -2
  525. package/dist/transitions/start.d.ts +6 -8
  526. package/dist/transitions/start.js +112 -31
  527. package/dist/transitions/startReads.d.ts +7 -0
  528. package/dist/transitions/startReads.js +28 -0
  529. package/dist/transitions/stop.d.ts +2 -1
  530. package/dist/transitions/stop.js +3 -2
  531. package/dist/types/admin.d.ts +1 -1
  532. package/dist/types/assignments.d.ts +1 -0
  533. package/dist/types/contracts.d.ts +30 -3
  534. package/dist/types/endpoints.d.ts +204 -13
  535. package/dist/types/index.d.ts +3 -0
  536. package/dist/types/puck.d.ts +8 -1
  537. package/dist/types/runtime.d.ts +15 -9
  538. package/dist/types/snapshot.d.ts +19 -4
  539. package/dist/types/surface.d.ts +20 -7
  540. package/dist/ui/Button.js +2 -2
  541. package/dist/ui/Card.d.ts +2 -1
  542. package/dist/ui/Card.js +4 -4
  543. package/dist/ui/ChipsInput.d.ts +8 -1
  544. package/dist/ui/ChipsInput.js +17 -4
  545. package/dist/ui/Dialog.d.ts +24 -2
  546. package/dist/ui/Dialog.js +116 -6
  547. package/dist/ui/Drawer.d.ts +10 -0
  548. package/dist/ui/Drawer.js +29 -0
  549. package/dist/ui/Inputs.d.ts +4 -3
  550. package/dist/ui/Inputs.js +7 -4
  551. package/dist/ui/SelectControl.d.ts +33 -0
  552. package/dist/ui/SelectControl.js +504 -0
  553. package/dist/ui/Tabs.d.ts +4 -4
  554. package/dist/ui/Tabs.js +35 -32
  555. package/dist/ui/ui.css +49 -5
  556. package/package.json +9 -1
  557. package/dist/admin/actions/ConfirmDialog.d.ts +0 -18
  558. package/dist/admin/actions/ConfirmDialog.js +0 -149
  559. package/dist/admin/actions/DecideDialog.d.ts +0 -9
  560. package/dist/admin/actions/actions.model.js +0 -70
  561. package/dist/admin/api.d.ts +0 -38
  562. package/dist/admin/api.js +0 -99
  563. package/dist/admin/copy/readiness.js +0 -71
  564. package/dist/admin/copy/testPage.js +0 -100
  565. package/dist/admin/results/results.css +0 -64
  566. package/dist/admin/styles.css +0 -10
  567. package/dist/admin/styles.d.ts +0 -2
  568. package/dist/admin/styles.js +0 -3
  569. package/dist/admin/surface/pageBlock/pageBlock.model.js +0 -8
  570. package/dist/admin/surface/readiness/ActionDialogs.js +0 -302
  571. package/dist/admin/surface/readiness/Banner.js +0 -166
  572. package/dist/admin/surface/readiness/SaveStatus.d.ts +0 -5
  573. package/dist/admin/surface/readiness/SaveStatus.js +0 -53
  574. package/dist/admin/surface/readiness/readiness.model.d.ts +0 -24
  575. package/dist/admin/surface/readiness/readiness.model.js +0 -123
  576. package/dist/admin/surface/readiness/useTransition.d.ts +0 -11
  577. package/dist/admin/surface/readiness/useTransition.js +0 -35
  578. package/dist/admin/surface/results/ReleasePages.d.ts +0 -14
  579. package/dist/admin/surface/setting/setting.css +0 -17
  580. package/dist/admin/surface/test/AdvancedSection.js +0 -160
  581. package/dist/admin/surface/test/GoalSection.d.ts +0 -2
  582. package/dist/admin/surface/test/GoalSection.js +0 -228
  583. package/dist/admin/surface/test/LengthSection.d.ts +0 -2
  584. package/dist/admin/surface/test/Section.js +0 -47
  585. package/dist/admin/surface/test/VersionsSection.d.ts +0 -4
  586. package/dist/admin/surface/test/fields.js +0 -184
  587. package/dist/admin/surface/test/pageParts.d.ts +0 -2
  588. package/dist/admin/surface/test/pageParts.js +0 -45
  589. package/dist/admin/surface/test/testPage.css +0 -90
  590. package/dist/admin/surface/useTestDocument.d.ts +0 -23
  591. package/dist/admin/surface/useTestDocument.js +0 -377
  592. package/dist/admin/useApi.d.ts +0 -35
  593. package/dist/admin/useApi.js +0 -10
  594. /package/dist/{admin → testSurface}/actions/decide.model.d.ts +0 -0
  595. /package/dist/{admin → testSurface}/actions/decide.model.js +0 -0
  596. /package/dist/{admin → testSurface}/allocation.model.d.ts +0 -0
  597. /package/dist/{admin → testSurface}/allocation.model.js +0 -0
  598. /package/dist/{admin → testSurface}/arms/arms.model.d.ts +0 -0
  599. /package/dist/{admin → testSurface}/arms/arms.model.js +0 -0
  600. /package/dist/{admin → testSurface}/arms/pageTarget.model.d.ts +0 -0
  601. /package/dist/{admin → testSurface}/arms/pageTarget.model.js +0 -0
  602. /package/dist/{admin → testSurface}/arms/params.model.d.ts +0 -0
  603. /package/dist/{admin → testSurface}/arms/params.model.js +0 -0
  604. /package/dist/{admin → testSurface}/copy/advanced.d.ts +0 -0
  605. /package/dist/{admin → testSurface}/copy/advanced.js +0 -0
  606. /package/dist/{admin → testSurface}/copy/arms.d.ts +0 -0
  607. /package/dist/{admin → testSurface}/copy/arms.js +0 -0
  608. /package/dist/{admin → testSurface}/copy/audience.d.ts +0 -0
  609. /package/dist/{admin → testSurface}/copy/audience.js +0 -0
  610. /package/dist/{admin → testSurface}/copy/recommendation.d.ts +0 -0
  611. /package/dist/{admin → testSurface}/copy/recommendation.js +0 -0
  612. /package/dist/{admin → testSurface}/copy/setting.d.ts +0 -0
  613. /package/dist/{admin → testSurface}/copy/setting.js +0 -0
  614. /package/dist/{admin → testSurface}/format/date.d.ts +0 -0
  615. /package/dist/{admin → testSurface}/format/date.js +0 -0
  616. /package/dist/{admin → testSurface}/labels.d.ts +0 -0
  617. /package/dist/{admin → testSurface}/labels.js +0 -0
  618. /package/dist/{admin → testSurface}/lockedNotice.model.d.ts +0 -0
  619. /package/dist/{admin → testSurface}/lockedNotice.model.js +0 -0
  620. /package/dist/{admin → testSurface}/reload.d.ts +0 -0
  621. /package/dist/{admin → testSurface}/reload.js +0 -0
  622. /package/dist/{admin → testSurface}/results/CappedCell.d.ts +0 -0
  623. /package/dist/{admin → testSurface}/results/CappedCell.js +0 -0
  624. /package/dist/{admin → testSurface}/results/CiChart.d.ts +0 -0
  625. /package/dist/{admin → testSurface}/results/CiChart.js +0 -0
  626. /package/dist/{admin → testSurface}/results/DataQualityPanel.d.ts +0 -0
  627. /package/dist/{admin → testSurface}/results/DataTable.d.ts +0 -0
  628. /package/dist/{admin → testSurface}/results/DataTable.js +0 -0
  629. /package/dist/{admin → testSurface}/results/StatTile.d.ts +0 -0
  630. /package/dist/{admin → testSurface}/results/StatTile.js +0 -0
  631. /package/dist/{admin → testSurface}/results/chart.model.d.ts +0 -0
  632. /package/dist/{admin → testSurface}/results/chart.model.js +0 -0
  633. /package/dist/{admin → testSurface}/results/format.d.ts +0 -0
  634. /package/dist/{admin → testSurface}/results/format.js +0 -0
  635. /package/dist/{admin → testSurface}/results/legacy.d.ts +0 -0
  636. /package/dist/{admin → testSurface}/results/legacy.js +0 -0
  637. /package/dist/{admin → testSurface}/results/releasePages.model.d.ts +0 -0
  638. /package/dist/{admin → testSurface}/results/releasePages.model.js +0 -0
  639. /package/dist/{admin → testSurface}/results/snapshot.d.ts +0 -0
  640. /package/dist/{admin → testSurface}/results/snapshot.js +0 -0
  641. /package/dist/{admin → testSurface}/review/review.model.d.ts +0 -0
  642. /package/dist/{admin → testSurface}/review/review.model.js +0 -0
  643. /package/dist/{admin → testSurface}/surface/contracts.js +0 -0
  644. /package/dist/{admin → testSurface}/surface/pageBlock/pageBlock.model.d.ts +0 -0
  645. /package/dist/{admin → testSurface}/surface/pageBlock/parts.d.ts +0 -0
  646. /package/dist/{admin → testSurface}/surface/readiness/parts.d.ts +0 -0
  647. /package/dist/{admin → testSurface}/surface/results/recommendation.model.d.ts +0 -0
  648. /package/dist/{admin → testSurface}/surface/results/recommendation.model.js +0 -0
  649. /package/dist/{admin → testSurface}/surface/setting/parts.d.ts +0 -0
  650. /package/dist/{admin → testSurface}/surface/setting/setting.model.d.ts +0 -0
  651. /package/dist/{admin → testSurface}/surface/setting/setting.model.js +0 -0
  652. /package/dist/{admin → testSurface}/surface/test/AdvancedSection.d.ts +0 -0
  653. /package/dist/{admin → testSurface}/surface/test/Rail.d.ts +0 -0
  654. /package/dist/{admin → testSurface}/surface/test/TargetingSection.d.ts +0 -0
  655. /package/dist/{admin → testSurface}/targeting/targeting.model.d.ts +0 -0
  656. /package/dist/{admin → testSurface}/targeting/targeting.model.js +0 -0
  657. /package/dist/{admin → testSurface}/theme.d.ts +0 -0
  658. /package/dist/{admin → testSurface}/theme.js +0 -0
@@ -1,139 +1,369 @@
1
- import { previousPublishedContent } from '../db/appends.js';
2
- import { lockPagePaths } from '../db/locks.js';
3
- import { txExecutor } from '../db/executor.js';
1
+ import { refuseNewNestedTests } from './puckNestedTests.js';
2
+ import { hasLocalizedFields } from '../transitions/contentFields.js';
3
+ import { AsyncLocalStorage } from 'node:async_hooks';
4
+ import { assertReadCommitted } from '../db/adapter.js';
5
+ import { previousPublishedContent, storedContent, placementWriteContent } from '../db/appends.js';
6
+ import { lockPlacementScope, sortLockKeys } from '../db/locks.js';
7
+ import { txExecutor, pooledExecutor } from '../db/executor.js';
4
8
  import { normalisePath } from '../runtime/normalisePath.js';
5
9
  import { XpNoTransactionError, XpRefusal } from '../errors.js';
6
- import { pageGuardCopy, READINESS_COPY } from '../admin/copy/readiness.js';
7
- // createLocalReq replaces context with a shallow copy on nested calls. Keep
8
- // the shared stack in that context so both the outer req and its proxies see it.
10
+ import { placementGuardCopy, pageGuardCopy, READINESS_COPY } from '../testSurface/copy/readiness.js';
11
+ import { allPlacementSlugs, mergedPlacementLocales, placementDocumentPaths } from '../blocks/placementLocale.js';
12
+ import { isObject } from '../blocks/model.js';
13
+ import { placementTests, removableBlockTests, appendPlacementDoc } from '../db/placements.js';
14
+ import { isPageBusy } from '../db/pageBusy.js';
15
+ import { blockRemovalRule, releaseRemovalClaim, observeUnpublishedRemoval, releaseRestoredRemovalClaims } from './blockRemovalRule.js';
16
+ import { bulkPlacementRequest, placementOperationRequest, usesBulkDocumentTransactions } from '../db/bulkPlacementRemoval.js';
17
+ const operationIdentity = Symbol('xpPlacementOperation');
18
+ // Execution-local identity survives both concurrent bulk siblings and Payload's
19
+ // restoreVersion operation, which caches req before beforeOperation runs.
20
+ export const pageGuardOperationScope = new AsyncLocalStorage();
21
+ const entryIsFirst = (config)=>!config?.hooks?.beforeOperation || config.hooks.beforeOperation[0] === pageGuardEnterOperation;
9
22
  const operations = (req)=>req.context.xpPageGuardOperations;
23
+ const requestFrame = (req)=>req[operationIdentity];
24
+ const operationFrame = (req, slug)=>{
25
+ const ordered = entryIsFirst(req.payload.config.collections?.find((c)=>c.slug === slug));
26
+ const own = requestFrame(req);
27
+ // With broken entry order, only this operation's returned token can prove a
28
+ // draft save. Restore bypasses that token on its cached request; Payload sets
29
+ // this sticky marker there before beforeChange (restoreVersion.js:162). Any
30
+ // ambiguity runs the rule: it may refuse, but must never borrow a draft save.
31
+ if (!ordered) return !req.context.isRestoringVersion && own?.collection === slug && !own.restore && !own.complete ? own : undefined;
32
+ let frame = pageGuardOperationScope.getStore();
33
+ while(frame && (frame.complete || frame.detached))frame = frame.parent;
34
+ // The request token wins when a preceding hook breaks async entry propagation.
35
+ // Restore alone caches the original request before beforeOperation; accept its
36
+ // execution identity only when the request belongs to its ancestor operation.
37
+ if (own) {
38
+ if (frame?.scoped && frame.restore && frame.collection === slug && frame !== own) {
39
+ let parent = frame.parent;
40
+ while(parent && parent !== own)parent = parent.parent;
41
+ if (parent === own) return frame;
42
+ }
43
+ return own.collection === slug && !own.complete ? own : undefined;
44
+ }
45
+ return frame?.scoped && frame.collection === slug && (frame.restore || frame.request === req) ? frame : undefined;
46
+ };
47
+ /** Must be first: buildBeforeOperation invokes its first hook synchronously,
48
+ * before the operation registers its await continuation. Later host hooks may
49
+ * await nested operations; those keep separate async contexts. No IO here.
50
+ */ export const pageGuardEnterOperation = ({ args, operation })=>{
51
+ if (operation !== 'create' && operation !== 'update' && operation !== 'restoreVersion' && operation !== 'delete') return;
52
+ const call = args;
53
+ if (!entryIsFirst(call.collection.config)) return;
54
+ pageGuardOperationScope.enterWith({
55
+ collection: call.collection.config.slug,
56
+ request: args.req,
57
+ draft: call.draft === true,
58
+ restore: operation === 'restoreVersion',
59
+ pending: true,
60
+ scoped: true,
61
+ parent: pageGuardOperationScope.getStore()
62
+ });
63
+ };
10
64
  export const pageGuardBeforeOperation = ({ args, operation })=>{
11
- if (operation !== 'update' && operation !== 'restoreVersion') return;
65
+ const req = args.req;
66
+ req.context.xpPlacementRemovals ??= {
67
+ transaction: undefined,
68
+ tests: new Map()
69
+ };
70
+ if (operation !== 'create' && operation !== 'update' && operation !== 'restoreVersion' && operation !== 'delete') return;
12
71
  const call = args;
13
72
  let collections = operations(call.req);
14
73
  if (!collections) call.req.context.xpPageGuardOperations = collections = new Map();
15
74
  const slug = call.collection.config.slug;
16
75
  const stack = collections.get(slug) ?? [];
17
- stack.push({
76
+ const entered = pageGuardOperationScope.getStore();
77
+ const frame = entryIsFirst(call.collection.config) && entered?.pending && entered.collection === slug ? entered : {
78
+ collection: slug,
79
+ request: req,
80
+ draft: false,
81
+ restore: false
82
+ };
83
+ const isBulk = Boolean(call.where) && (operation === 'update' || operation === 'delete');
84
+ const bulk = frame.scoped && isBulk ? {
85
+ documents: new Set(),
86
+ refusals: new Map()
87
+ } : undefined;
88
+ Object.assign(frame, {
89
+ request: req,
18
90
  draft: call.draft === true,
19
- restore: operation === 'restoreVersion'
91
+ restore: operation === 'restoreVersion',
92
+ versionId: operation === 'restoreVersion' ? call.id : undefined,
93
+ isBulk,
94
+ publishSpecificLocale: call.publishSpecificLocale,
95
+ bulk,
96
+ pending: false
20
97
  });
98
+ stack.push(frame);
21
99
  collections.set(slug, stack);
100
+ const scoped = placementOperationRequest(req, new Map([
101
+ [
102
+ operationIdentity,
103
+ frame
104
+ ]
105
+ ]), ()=>{
106
+ // Only ordered execution identity can attribute a cached-request rollback
107
+ // to a restore. An unscoped stack entry may be a stale failed restore.
108
+ const executing = pageGuardOperationScope.getStore();
109
+ if (executing?.scoped && executing.restore && !executing.complete && !executing.detached && executing.collection === slug) {
110
+ let parent = executing.parent;
111
+ while(parent && parent !== frame)parent = parent.parent;
112
+ if (parent === frame) {
113
+ finishOperation(executing.request ?? req, executing);
114
+ return;
115
+ }
116
+ }
117
+ // Payload uses the same request for per-document completion and its outer
118
+ // catch. Always detach shared tracking; the exact request token alone keeps
119
+ // bulk policy/selection for later siblings until afterOperation completes it.
120
+ if (isBulk && usesBulkDocumentTransactions(req)) detachOperation(req, frame);
121
+ else finishOperation(req, frame);
122
+ });
123
+ return {
124
+ ...args,
125
+ req: bulk ? bulkPlacementRequest(scoped, slug, call.where, call.data, call.draft === true, operation === 'delete', bulk) : scoped
126
+ };
22
127
  };
128
+ function detachOperation(req, frame) {
129
+ const collections = operations(req), stack = collections?.get(frame.collection);
130
+ const index = stack?.lastIndexOf(frame);
131
+ if (index != null && index >= 0) stack.splice(index, 1);
132
+ if (!stack?.length) collections?.delete(frame.collection);
133
+ frame.detached = true;
134
+ if (pageGuardOperationScope.getStore() === frame) pageGuardOperationScope.enterWith(frame.parent);
135
+ }
136
+ function finishOperation(req, frame) {
137
+ frame.complete = true;
138
+ detachOperation(req, frame);
139
+ }
140
+ // Collection afterError has no operation identity and is REST-only
141
+ // (Payload 3.90.2 utilities/routeError.js:69-78). Local API failures call
142
+ // killTransaction(args.req) (operations/update.js:362, delete.js:274), whose
143
+ // transactionID deletion is observed by the operation's request proxy above.
144
+ // Bulk transaction deletion detaches tracking; its request token keeps policy.
23
145
  export const pageGuardAfterOperation = ({ req, collection, operation, result })=>{
146
+ // buildAfterOperation passes args.req, including the restore's returned token
147
+ // (Payload 3.90.2 utilities/buildAfterOperation.js:11). Never finish a caller's
148
+ // token as a fallback for an unidentified restore.
149
+ const own = requestFrame(req);
150
+ const identified = own?.collection === collection.slug && !own.complete ? own : operationFrame(req, collection.slug);
151
+ const frame = operation === 'restoreVersion' && !identified?.restore ? undefined : identified;
152
+ const bulk = frame?.bulk;
24
153
  // beforeOperation reports by-id updates as 'update'; afterOperation reports 'updateByID'.
25
- if (operation === 'update' || operation === 'updateByID' || operation === 'restoreVersion') {
26
- const collections = operations(req);
27
- const stack = collections?.get(collection.slug);
28
- stack?.pop();
29
- if (!stack?.length) collections?.delete(collection.slug);
154
+ const mutates = operation === 'create' || operation === 'update' || operation === 'updateByID' || operation === 'restoreVersion' || operation === 'delete' || operation === 'deleteByID';
155
+ // Bulk Local API errors are returned per document, without invoking afterError.
156
+ if (result && typeof result === 'object' && 'errors' in result && Array.isArray(result.errors)) {
157
+ const failed = result.errors.some((error)=>error && !bulk?.refusals.has(error.message));
158
+ if (failed && bulk) for (const error of result.errors){
159
+ const conservative = bulk.refusals.get(error?.message);
160
+ if (conservative) error.message = conservative;
161
+ }
162
+ for (const error of result.errors)if (error && error.id != null) releaseRemovalClaim(req, collection.slug, error.id);
30
163
  }
164
+ if (mutates && frame) finishOperation(req, frame);
31
165
  return result;
32
166
  };
33
- async function protect(req, path) {
34
- // Serialise with Start (CORE-52 path locks, taken there after the experiment lock): a concurrent Start
35
- // either commits first, so this check sees it, or waits and then sees this change. Raw SQL on the
36
- // host's transaction; without one there is nothing to hold the lock for.
37
- if (await req.transactionID != null) {
38
- try {
39
- await lockPagePaths(txExecutor(req), [
40
- normalisePath(path)
41
- ]);
42
- } catch (error) {
43
- // A request id without a database session (e.g. a transaction already killed) has no lock to take.
44
- if (!(error instanceof XpNoTransactionError)) throw error;
45
- }
167
+ function optionsOf(req) {
168
+ return req.payload.config.custom?.xp;
169
+ }
170
+ function registration(req, slug) {
171
+ return optionsOf(req).pages?.collections.find((entry)=>entry.slug === slug);
172
+ }
173
+ const active = (test)=>test.status === 'running' || test.status === 'decided';
174
+ const documentPathsOf = (req, collection, rows)=>{
175
+ const page = registration(req, collection);
176
+ return page ? placementDocumentPaths(req, collection, rows, 'all-locales', (doc)=>page.pathOf(doc)) : [];
177
+ };
178
+ /** The later audit also recognises arm-select tags; include those ids in its lock superset. */ function taggedIds(value, ids = new Set()) {
179
+ if (Array.isArray(value)) value.forEach((v)=>taggedIds(v, ids));
180
+ else if (isObject(value)) {
181
+ if (typeof value.experiment === 'string' && typeof value.arm === 'string') ids.add(value.experiment);
182
+ Object.values(value).forEach((v)=>taggedIds(v, ids));
46
183
  }
47
- // page guard: the hook must see test placements regardless of the editor's access
48
- const tests = await req.payload.find({
49
- collection: 'xp-experiments',
50
- req,
51
- overrideAccess: true,
52
- depth: 0,
53
- limit: 0,
54
- where: {
55
- and: [
56
- {
57
- kind: {
58
- equals: 'page'
59
- }
60
- },
61
- {
62
- status: {
63
- in: [
64
- 'running',
65
- 'decided',
66
- 'archived'
67
- ]
68
- }
69
- }
70
- ]
71
- }
72
- });
73
- for (const test of tests.docs){
74
- const decision = test.decision;
184
+ return ids;
185
+ }
186
+ export function guardExperimentIds(tests, slugs, collection, paths, held, tags = new Set(), discovered = []) {
187
+ const excluded = new Set(Array.isArray(held) ? held.map(String) : []);
188
+ const ids = tests.filter((test)=>slugs.includes(test.slug) || tags.has(String(test.id)) || test.kind === 'page' && (!test.pageCollection || test.pageCollection === collection) && test.arms.some((a)=>typeof a.pageTarget === 'string' && paths.includes(normalisePath(a.pageTarget)))).map((test)=>String(test.id));
189
+ // A candidate may have committed after the broad audit discovery. Its indexed
190
+ // removal lookup must still contribute E, including when it is not running yet.
191
+ return sortLockKeys([
192
+ ...ids,
193
+ ...discovered.map(String)
194
+ ].filter((id)=>!excluded.has(id)));
195
+ }
196
+ function protect(tests, path) {
197
+ for (const test of tests){
198
+ if (test.kind !== 'page' || !active(test) && test.status !== 'archived') continue;
75
199
  const archived = test.status === 'archived';
76
- if (archived && (!decision?.winnerArm || decision.discardedAt || decision.pagesReleasedAt)) continue;
77
- // page guard: the hook must see test placements regardless of the editor's access
78
- const phases = await req.payload.find({
79
- collection: 'xp-phases',
80
- req,
81
- overrideAccess: true,
82
- depth: 0,
83
- limit: 1,
84
- sort: '-phase',
85
- where: {
86
- experiment: {
87
- equals: test.id
88
- },
89
- phaseKind: {
90
- equals: 'test'
91
- }
92
- }
93
- });
94
- const phase = phases.docs[0];
95
- if (!phase) throw new XpRefusal('invalid-phase', READINESS_COPY.missingVersions, {
200
+ if (archived && (!test.winnerArm || test.discardedAt || test.pagesReleasedAt)) continue;
201
+ if (!test.arms.length) throw new XpRefusal('invalid-phase', READINESS_COPY.missingVersions, {
202
+ experimentId: test.id
203
+ }, 409);
204
+ const arms = archived ? test.arms.filter((a)=>a.kind === 'control' || a.key === test.winnerArm) : test.arms;
205
+ const matched = arms.find((a)=>typeof a.pageTarget === 'string' && normalisePath(a.pageTarget) === path);
206
+ if (matched) throw new XpRefusal('locked-placement', pageGuardCopy(test.name, test.status, archived && matched.key !== test.winnerArm ? 'original' : 'winner'), {
96
207
  experimentId: test.id
97
208
  }, 409);
98
- const arms = phase.arms;
99
- const protectedArms = archived ? arms.filter((arm)=>arm.kind === 'control' || arm.key === decision.winnerArm) : arms;
100
- const matched = protectedArms.find((arm)=>arm.pageTarget !== undefined && normalisePath(arm.pageTarget) === normalisePath(path));
101
- if (matched) {
102
- const role = archived && matched.key !== decision.winnerArm ? 'original' : 'winner';
103
- throw new XpRefusal('locked-placement', pageGuardCopy(String(test.name), test.status, role), {
104
- experimentId: test.id
105
- }, 409);
106
- }
107
209
  }
108
210
  }
109
- function registration(req, slug) {
110
- return (req.payload.config.custom?.xp).pages?.collections.find((entry)=>entry.slug === slug);
211
+ function refuseInteraction(tests, beforeSlugs, afterSlugs, beforePaths, afterPaths, collection) {
212
+ const blocks = tests.filter((test)=>test.kind === 'block' && active(test) && afterSlugs.includes(test.slug));
213
+ const pages = tests.filter((test)=>test.kind === 'page' && active(test) && (!test.pageCollection || test.pageCollection === collection));
214
+ for (const page of pages){
215
+ if (!page.arms.some((a)=>typeof a.pageTarget === 'string' && afterPaths.includes(normalisePath(a.pageTarget)))) continue;
216
+ const block = blocks[0];
217
+ if (!block) continue;
218
+ const preExisting = beforeSlugs.includes(block.slug) && page.arms.some((a)=>typeof a.pageTarget === 'string' && beforePaths.includes(normalisePath(a.pageTarget)));
219
+ throw new XpRefusal('interacting-tests', placementGuardCopy(page, block, preExisting), {
220
+ experimentId: page.id,
221
+ blockId: block.id
222
+ }, 409);
223
+ }
224
+ }
225
+ function mapBusy(error) {
226
+ if (isPageBusy(error)) throw new XpRefusal('page-busy', 'This page is being updated by a test right now. Try again in a moment.', undefined, 409, {
227
+ cause: error
228
+ });
229
+ throw error;
111
230
  }
112
231
  export const pageGuardBeforeDelete = async ({ req, id, collection })=>{
113
- const page = registration(req, collection.slug);
114
- if (!page) return;
115
- const published = await previousPublishedContent(req, collection.slug, id);
116
- if (!published || published._status === 'draft') return;
117
- const path = page.pathOf(published);
118
- if (path !== null) await protect(req, path);
232
+ try {
233
+ const page = registration(req, collection.slug);
234
+ // Keep the earlier page guard's baseline read and every refusal intact.
235
+ const published = page ? await previousPublishedContent(req, collection.slug, id) : await storedContent(req, collection.slug, id);
236
+ if (!published || published._status === 'draft') return;
237
+ const paths = sortLockKeys(documentPathsOf(req, collection.slug, [
238
+ published
239
+ ]).map(normalisePath));
240
+ const exec = await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload);
241
+ let tests = page ? await placementTests(exec) : undefined;
242
+ const { views, affected } = await blockRemovalRule.prepare(req, collection.slug, collection.trash && published.deletedAt != null ? undefined : published, {}, true, exec, tests);
243
+ if (!page) {
244
+ if (!affected.length) return;
245
+ if (await req.transactionID != null) {
246
+ await assertReadCommitted(req);
247
+ await lockPlacementScope(exec, guardExperimentIds([], [], collection.slug, [], req.context.xpHeldExperiments, new Set(), affected.map((test)=>test.id)), []);
248
+ tests = (await removableBlockTests(exec, affected.map((test)=>test.slug))).map((test)=>({
249
+ ...test,
250
+ kind: 'block'
251
+ }));
252
+ } else tests = affected;
253
+ } else if (await req.transactionID != null) {
254
+ await assertReadCommitted(req);
255
+ await lockPlacementScope(exec, guardExperimentIds(tests, allPlacementSlugs(req, collection.slug, published, 'all-locales'), collection.slug, paths, req.context.xpHeldExperiments, taggedIds(published), affected.map((test)=>test.id)), paths);
256
+ tests = await placementTests(exec);
257
+ }
258
+ for (const path of paths)protect(tests.filter((t)=>!t.pageCollection || t.pageCollection === collection.slug), path);
259
+ if (affected.length) await blockRemovalRule.check(req, tests, affected, collection.slug, id, true, views, operationFrame(req, collection.slug)?.bulk);
260
+ } catch (error) {
261
+ mapBusy(error);
262
+ }
119
263
  };
120
264
  export const pageGuardBeforeChange = async ({ req, collection, originalDoc, operation, data })=>{
121
- if (operation !== 'update') return data;
122
- const page = registration(req, collection.slug);
123
- if (!page) return data;
124
265
  const drafts = Boolean(collection.versions && collection.versions.drafts);
125
- // updateDocument computes isSavingDraft from draftArg and _status before
126
- // beforeChange, and writes the main row only when !isSavingDraft.
127
- const call = operations(req)?.get(collection.slug)?.at(-1);
128
- if (drafts && call?.draft && (call.restore || data._status !== 'published')) return data;
129
- const published = await previousPublishedContent(req, collection.slug, originalDoc.id);
130
- if (!published || published._status === 'draft') return data;
131
- const path = page.pathOf(published);
132
- const unpublishing = drafts && data._status === 'draft';
133
- const trashing = collection.trash && data.deletedAt != null && !originalDoc.deletedAt;
134
- if (path !== null && (trashing || unpublishing || page.pathOf({
266
+ const call = operationFrame(req, collection.slug);
267
+ if (drafts && call?.draft && (call.restore || data._status !== 'published')) {
268
+ await blockRemovalRule.prepare(req, collection.slug, undefined, data, false);
269
+ return data;
270
+ }
271
+ const after = operation === 'create' ? data : {
135
272
  ...originalDoc,
136
273
  ...data
137
- }) !== path)) await protect(req, path);
138
- return data;
274
+ };
275
+ const options = optionsOf(req);
276
+ try {
277
+ const published = operation === 'create' ? undefined : await previousPublishedContent(req, collection.slug, originalDoc.id);
278
+ // Preserve the localization-off path and its IO. Localized writes mirror
279
+ // the base Payload uses for this operation's unselected languages.
280
+ const stored = operation === 'create' || !hasLocalizedFields(req.payload.config.collections?.find((entry)=>entry.slug === collection.slug)?.fields ?? [], req.payload.config) ? published : await placementWriteContent(req, collection.slug, originalDoc.id, published ?? await storedContent(req, collection.slug, originalDoc.id), {
281
+ versionId: call?.versionId,
282
+ bulk: call?.isBulk,
283
+ draft: call?.draft,
284
+ publishSpecificLocale: call?.publishSpecificLocale,
285
+ trashing: Boolean(collection.trash && data.deletedAt != null)
286
+ });
287
+ const before = published?._status === 'draft' ? undefined : published;
288
+ const beforeSlugs = allPlacementSlugs(req, collection.slug, before, 'all-locales');
289
+ const rawAfter = mergedPlacementLocales(req, collection.slug, stored, after);
290
+ const afterSlugs = allPlacementSlugs(req, collection.slug, rawAfter, 'all-locales');
291
+ const oldPaths = documentPathsOf(req, collection.slug, [
292
+ before
293
+ ]), newPaths = documentPathsOf(req, collection.slug, [
294
+ rawAfter
295
+ ]);
296
+ const beforePaths = sortLockKeys(oldPaths.map(normalisePath)), afterPaths = sortLockKeys(newPaths.map(normalisePath));
297
+ const paths = sortLockKeys([
298
+ ...beforePaths,
299
+ ...afterPaths
300
+ ]);
301
+ const exec = await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload);
302
+ let tests = await placementTests(exec);
303
+ const trashing = Boolean(collection.trash && after.deletedAt != null);
304
+ const { views, affected, hidden } = await blockRemovalRule.prepare(req, collection.slug, collection.trash && before?.deletedAt != null ? undefined : before, rawAfter, trashing || drafts && after._status !== 'published', exec, tests, 'all-locales');
305
+ const publishes = !drafts || after._status === 'published';
306
+ const noTransaction = ()=>{
307
+ if (publishes && tests.some((t)=>t.kind === 'block' && active(t) && afterSlugs.includes(t.slug))) throw new XpNoTransactionError('Save this page with transactions on.');
308
+ };
309
+ if (await req.transactionID == null) noTransaction();
310
+ else {
311
+ try {
312
+ await assertReadCommitted(req);
313
+ await lockPlacementScope(exec, guardExperimentIds(tests, [
314
+ ...beforeSlugs,
315
+ ...afterSlugs
316
+ ], collection.slug, paths, req.context.xpHeldExperiments, taggedIds([
317
+ before,
318
+ rawAfter
319
+ ]), affected.map((test)=>test.id)), paths);
320
+ tests = await placementTests(exec);
321
+ } catch (error) {
322
+ if (!(error instanceof XpNoTransactionError)) throw error;
323
+ // Only a session lost after discovery reaches this fallback. The first discovery
324
+ // read and delete have no fallback: a dead session fails those operations closed.
325
+ tests = await placementTests(pooledExecutor(req.payload));
326
+ noTransaction();
327
+ }
328
+ }
329
+ if (operation === 'update' && before) {
330
+ const unpublishing = drafts && data._status === 'draft';
331
+ const trashing = collection.trash && data.deletedAt != null && !originalDoc.deletedAt;
332
+ for (const old of oldPaths)if (unpublishing || trashing || !newPaths.includes(old)) protect(tests.filter((t)=>!t.pageCollection || t.pageCollection === collection.slug), normalisePath(old));
333
+ }
334
+ if (publishes) refuseNewNestedTests(req, collection.slug, before, rawAfter, tests);
335
+ if (publishes) refuseInteraction(tests, beforeSlugs, afterSlugs, beforePaths, afterPaths, collection.slug);
336
+ if (affected.length) await blockRemovalRule.check(req, tests, affected, collection.slug, originalDoc.id, trashing || drafts && after._status !== 'published', views, call?.bulk, hidden);
337
+ return data;
338
+ } catch (error) {
339
+ mapBusy(error);
340
+ }
341
+ };
342
+ /** Unwrapped: these writes must fail the publish closed, unlike the best-effort audit. */ export const pageGuardAfterChange = async ({ req, collection, doc })=>{
343
+ const call = operationFrame(req, collection.slug);
344
+ const drafts = Boolean(collection.versions && collection.versions.drafts);
345
+ if (!call?.draft && (drafts && doc._status !== 'published' || collection.trash && doc.deletedAt != null)) observeUnpublishedRemoval(req, collection.slug, doc.id);
346
+ if (drafts && (doc._status !== 'published' || call?.draft && call.restore)) return doc;
347
+ if (await req.transactionID == null) return doc;
348
+ try {
349
+ const stored = await storedContent(req, collection.slug, doc.id);
350
+ if (!stored) throw new Error('The saved placement row was not found.');
351
+ const slugs = allPlacementSlugs(req, collection.slug, stored, 'all-locales');
352
+ // A later publish in this transaction can restore an earlier removal. Only
353
+ // clear its claim once the stored published row actually contains the block.
354
+ const claims = req.context.xpPlacementRemovals;
355
+ const exec = txExecutor(req);
356
+ for (const test of (await placementTests(exec))){
357
+ if (test.kind === 'block' && active(test) && slugs.includes(test.slug)) await appendPlacementDoc(exec, test.id, test.phase, {
358
+ collection: collection.slug,
359
+ id: doc.id
360
+ });
361
+ if (test.kind === 'block' && claims && claims.transaction === await req.transactionID && stored._status !== 'draft' && stored.deletedAt == null) {
362
+ releaseRestoredRemovalClaims(req, collection.slug, stored, test);
363
+ }
364
+ }
365
+ return doc;
366
+ } catch (error) {
367
+ mapBusy(error);
368
+ }
139
369
  };
@@ -0,0 +1,5 @@
1
+ import { type CollectionBeforeChangeHook } from 'payload';
2
+ /** Host component labels are not passed to the plugin; display their type as words. */
3
+ export declare function puckBlockName(rawType: string): string;
4
+ /** Validate only the Puck JSON included in a publishing write. */
5
+ export declare function puckGoalsBeforeChange(field: string): CollectionBeforeChangeHook;
@@ -0,0 +1,62 @@
1
+ import { ValidationError } from 'payload';
2
+ import { validateClickGoal } from '../goals/validate.js';
3
+ import { CLICK_KEY } from '../goals/key.js';
4
+ import { puckGoalRefusal } from '../goals/picker/copy.js';
5
+ /** Host component labels are not passed to the plugin; display their type as words. */ export function puckBlockName(rawType) {
6
+ // Cap before any regex: the type comes from saved page JSON and the first pattern backtracks on long capital runs.
7
+ const type = rawType.slice(0, 64);
8
+ const words = type.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2').replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/([A-Za-z])([0-9])/g, '$1 $2').replace(/[\s_-]+/g, ' ').trim();
9
+ return words ? words[0].toUpperCase() + words.slice(1) : 'Page';
10
+ }
11
+ /** Validate only the Puck JSON included in a publishing write. */ export function puckGoalsBeforeChange(field) {
12
+ return async function validatePuckGoals({ collection, data, originalDoc, req }) {
13
+ const drafts = Boolean(collection.versions && collection.versions.drafts);
14
+ if (drafts && data._status !== 'published') return data;
15
+ // Publishing a stored draft without resending its JSON publishes the draft's JSON.
16
+ let value = data[field] !== undefined ? data[field] : drafts ? originalDoc?.[field] : undefined;
17
+ if (value === undefined) return data;
18
+ if (typeof value === 'string') {
19
+ try {
20
+ value = JSON.parse(value);
21
+ } catch {
22
+ return data;
23
+ }
24
+ }
25
+ const errors = [];
26
+ let first;
27
+ // Holds the raw component type; it is humanised once, for the first refusal only.
28
+ async function walk(value, path, block = '') {
29
+ if (!value || typeof value !== 'object') return;
30
+ const item = value;
31
+ if (typeof item.type === 'string' && item.props && typeof item.props === 'object' && !Array.isArray(item.props)) {
32
+ block = item.type;
33
+ }
34
+ for (const [key, prop] of Object.entries(value)){
35
+ const propPath = `${path}.${key}`;
36
+ if (key === 'xpGoal' && typeof prop === 'string') {
37
+ const result = await validateClickGoal(prop, req);
38
+ if (result !== true) {
39
+ first ??= {
40
+ key: prop,
41
+ block
42
+ };
43
+ errors.push({
44
+ path: propPath,
45
+ message: result
46
+ });
47
+ }
48
+ } else await walk(prop, propPath, block);
49
+ }
50
+ }
51
+ await walk(value, field);
52
+ if (first) {
53
+ const error = new ValidationError({
54
+ collection: collection.slug,
55
+ errors
56
+ });
57
+ error.message = puckGoalRefusal(first.key, first.block ? puckBlockName(first.block) : 'Page', !CLICK_KEY.test(first.key), errors.length - 1);
58
+ throw error;
59
+ }
60
+ return data;
61
+ };
62
+ }
@@ -0,0 +1,8 @@
1
+ import { type PayloadRequest } from 'payload';
2
+ /** Called by the page guard with its published baseline and merged write, only on publish.
3
+ * Puck's public reducer bypasses slot disallow; this server check covers that path.
4
+ */
5
+ export declare function refuseNewNestedTests(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, tests: readonly {
6
+ slug: string;
7
+ name: string;
8
+ }[]): void;
@@ -0,0 +1,36 @@
1
+ import { ValidationError } from 'payload';
2
+ import { placementReader } from '../blocks/placementLocale.js';
3
+ import { puckCollections } from '../options.js';
4
+ import { nestedTests, nestedTestKey, nestedTestLabel, nestedTestSlug, nearestOuterTest } from '../puck/nestedTests.js';
5
+ import { nestedTestCopy } from '../puck/nestedTestCopy.js';
6
+ /** Called by the page guard with its published baseline and merged write, only on publish.
7
+ * Puck's public reducer bypasses slot disallow; this server check covers that path.
8
+ */ export function refuseNewNestedTests(req, collection, before, after, tests) {
9
+ const options = req.payload.config.custom?.xp;
10
+ const registration = puckCollections(options).find((entry)=>entry.slug === collection);
11
+ if (!registration) return;
12
+ const reader = placementReader(req, collection, options);
13
+ for (const view of reader.views){
14
+ const read = (doc)=>{
15
+ const content = reader.read(doc, 'all-locales', view);
16
+ return content.editor === 'puck' ? nestedTests(content.doc?.[registration.field]) : [];
17
+ };
18
+ const existing = new Set(read(before).map(nestedTestKey));
19
+ const additions = read(after).filter((pair)=>!existing.has(nestedTestKey(pair)));
20
+ const added = additions[0];
21
+ if (!added) continue;
22
+ const name = (block)=>tests.find((test)=>test.slug === nestedTestSlug(block))?.name ?? nestedTestLabel(block);
23
+ const message = nestedTestCopy.publish(name(nearestOuterTest(additions, added.inner.props.id)), name(added.inner));
24
+ const error = new ValidationError({
25
+ collection,
26
+ errors: [
27
+ {
28
+ path: registration.field,
29
+ message
30
+ }
31
+ ]
32
+ });
33
+ error.message = message;
34
+ throw error;
35
+ }
36
+ }
@@ -0,0 +1,11 @@
1
+ import type { CollectionAfterChangeHook } from 'payload';
2
+ import type { DocId } from '../types/contracts.js';
3
+ declare module 'payload' {
4
+ interface RequestContext {
5
+ xpDuplicate?: {
6
+ collection: string;
7
+ created: DocId[];
8
+ };
9
+ }
10
+ }
11
+ export declare const trackPageCopies: CollectionAfterChangeHook;
@@ -0,0 +1,7 @@
1
+ export const trackPageCopies = ({ collection, context, operation, doc })=>{
2
+ const tracking = context.xpDuplicate;
3
+ if (operation === 'create' && tracking?.collection === collection.slug) {
4
+ tracking.created.push(doc.id);
5
+ }
6
+ return doc;
7
+ };
@@ -13,4 +13,4 @@ export declare class DocsResponseError extends Error {
13
13
  /** Read every Payload REST page with the caller's credentials and cancellation. Transport,
14
14
  * invalid successful responses and aborts throw; HTTP refusals retain their status/body. Keeps the first document per id; refuses
15
15
  * incomplete lists after 1000 pages with page-limit-exceeded. */
16
- export declare function fetchAllDocs<T>(url: string, options?: Pick<RequestInit, 'credentials' | 'signal'>): Promise<DocsResult<T>>;
16
+ export declare function fetchAllDocs<T>(url: string, options?: Pick<RequestInit, 'cache' | 'credentials' | 'signal'>): Promise<DocsResult<T>>;
@@ -0,0 +1,10 @@
1
+ import type { PreflightResult } from '../types/endpoints.js';
2
+ type Placement = PreflightResult['placements'][number];
3
+ export type PreviewPage = Placement & {
4
+ key: string;
5
+ slotCount: number;
6
+ };
7
+ /** Localized responses are already grouped by the server. Legacy single-language
8
+ * responses contain occurrences; preserve their page grouping and version counts. */
9
+ export declare function placementPages(placements: readonly Placement[], flagPoint?: string): PreviewPage[];
10
+ export {};