@delmaredigital/payload-experiments 0.4.0-rc.6 → 0.4.0-rc.9

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 (294) hide show
  1. package/README.md +12 -12
  2. package/dist/admin/blocks/BlockPanel.js +6 -4
  3. package/dist/admin/blocks/inject.js +1 -0
  4. package/dist/admin/blocks/model.d.ts +3 -2
  5. package/dist/admin/blocks/model.js +9 -5
  6. package/dist/admin/copy/blocks.d.ts +3 -2
  7. package/dist/admin/copy/blocks.js +8 -7
  8. package/dist/admin/surface/ResultsRoute.js +18 -11
  9. package/dist/admin/surface/TestsHome.d.ts +2 -1
  10. package/dist/admin/surface/TestsHome.js +131 -44
  11. package/dist/admin/surface/TestsSurface.js +3 -0
  12. package/dist/admin/surface/home.model.d.ts +2 -0
  13. package/dist/admin/surface/newTest/PageWizard.js +9 -2
  14. package/dist/admin/surface/newTest/newTest.css +1 -1
  15. package/dist/admin/surface/results/ResultsHeader.js +11 -6
  16. package/dist/admin/surface/test/TestPage.js +3 -3
  17. package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
  18. package/dist/admin/views/TestsSurfaceClient.js +11 -0
  19. package/dist/admin/views/buildSurfaceProps.js +10 -3
  20. package/dist/blocks/bindings.js +3 -2
  21. package/dist/blocks/formState.js +1 -1
  22. package/dist/blocks/placementLanguages.d.ts +7 -0
  23. package/dist/blocks/placementLanguages.js +27 -0
  24. package/dist/blocks/placementLocale.d.ts +21 -7
  25. package/dist/blocks/placementLocale.js +218 -67
  26. package/dist/collections/experiments/config.js +8 -3
  27. package/dist/collections/experiments/deleteGuard.js +2 -2
  28. package/dist/collections/experiments/lockHook.js +21 -2
  29. package/dist/collections/experiments/pickSlug.js +2 -0
  30. package/dist/collections/metricsGuards.js +2 -0
  31. package/dist/collections/serialize.js +5 -4
  32. package/dist/constants.d.ts +1 -0
  33. package/dist/constants.js +1 -0
  34. package/dist/db/adapter.d.ts +9 -1
  35. package/dist/db/adapter.js +77 -1
  36. package/dist/db/appends.d.ts +13 -0
  37. package/dist/db/appends.js +49 -0
  38. package/dist/db/bulkPlacementRemoval.js +8 -4
  39. package/dist/db/delete.d.ts +1 -1
  40. package/dist/db/delete.js +2 -4
  41. package/dist/db/events.d.ts +9 -0
  42. package/dist/db/events.js +42 -8
  43. package/dist/db/executor.d.ts +7 -1
  44. package/dist/db/executor.js +7 -3
  45. package/dist/db/results.d.ts +5 -1
  46. package/dist/db/results.js +21 -5
  47. package/dist/db/snapshots.d.ts +1 -0
  48. package/dist/endpoints/contentLocale.d.ts +6 -0
  49. package/dist/endpoints/contentLocale.js +15 -0
  50. package/dist/endpoints/deleteImpact.d.ts +6 -0
  51. package/dist/endpoints/deleteImpact.js +207 -0
  52. package/dist/endpoints/events.js +103 -39
  53. package/dist/endpoints/index.js +9 -8
  54. package/dist/endpoints/pages.js +7 -3
  55. package/dist/endpoints/placementStatus.js +13 -5
  56. package/dist/endpoints/preflight.d.ts +1 -1
  57. package/dist/endpoints/preflight.js +17 -2
  58. package/dist/endpoints/results.d.ts +1 -1
  59. package/dist/endpoints/results.js +6 -2
  60. package/dist/endpoints/routeId.d.ts +2 -2
  61. package/dist/endpoints/routeId.js +11 -5
  62. package/dist/endpoints/summary.js +46 -12
  63. package/dist/endpoints/transitions.js +37 -24
  64. package/dist/errors.d.ts +4 -0
  65. package/dist/errors.js +6 -0
  66. package/dist/events/request.d.ts +6 -2
  67. package/dist/events/request.js +35 -8
  68. package/dist/events/rows.d.ts +1 -1
  69. package/dist/events/rows.js +24 -8
  70. package/dist/events/writable.d.ts +9 -0
  71. package/dist/events/writable.js +13 -0
  72. package/dist/exports/adminClient.d.ts +1 -1
  73. package/dist/exports/adminClient.js +1 -1
  74. package/dist/exports/index.d.ts +1 -1
  75. package/dist/exports/rsc.d.ts +1 -0
  76. package/dist/exports/rsc.js +1 -0
  77. package/dist/goals/fairness.js +38 -31
  78. package/dist/hooks/blockRemovalRule.d.ts +2 -2
  79. package/dist/hooks/blockRemovalRule.js +16 -14
  80. package/dist/hooks/hostHook.js +6 -2
  81. package/dist/hooks/pageGuard.d.ts +3 -0
  82. package/dist/hooks/pageGuard.js +37 -23
  83. package/dist/hooks/puckNestedTests.d.ts +8 -0
  84. package/dist/hooks/puckNestedTests.js +36 -0
  85. package/dist/lib/fetchAllDocs.d.ts +1 -1
  86. package/dist/lib/placementPages.d.ts +2 -1
  87. package/dist/lib/placementPages.js +10 -2
  88. package/dist/manifest/compile.d.ts +2 -1
  89. package/dist/manifest/compile.js +13 -6
  90. package/dist/onInit.js +14 -0
  91. package/dist/options.js +5 -0
  92. package/dist/proxy/pageNavigation.d.ts +4 -0
  93. package/dist/proxy/pageNavigation.js +28 -0
  94. package/dist/proxy/resolve.js +52 -25
  95. package/dist/puck/ExperimentPicker.js +40 -37
  96. package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
  97. package/dist/puck/editor/ConfigureTestDrawer.js +5 -2
  98. package/dist/puck/editor/ExperimentSlotEditor.js +313 -158
  99. package/dist/puck/editor/LeftoverVersions.d.ts +1 -1
  100. package/dist/puck/editor/LeftoverVersions.js +40 -43
  101. package/dist/puck/editor/QuickTestActions.d.ts +5 -2
  102. package/dist/puck/editor/QuickTestActions.js +16 -4
  103. package/dist/puck/editor/ResultsReadout.d.ts +2 -1
  104. package/dist/puck/editor/ResultsReadout.js +2 -1
  105. package/dist/puck/editor/VersionBuilder.d.ts +31 -3
  106. package/dist/puck/editor/VersionBuilder.js +336 -74
  107. package/dist/puck/editor/armWrites.js +1 -1
  108. package/dist/puck/editor/armsCache.js +1 -3
  109. package/dist/puck/editor/blockClipboard.d.ts +16 -0
  110. package/dist/puck/editor/blockClipboard.js +20 -0
  111. package/dist/puck/editor/copy.d.ts +12 -2
  112. package/dist/puck/editor/copy.js +13 -2
  113. package/dist/puck/editor/editor.chrome.css +118 -3
  114. package/dist/puck/editor/editor.css +131 -8
  115. package/dist/puck/editor/editor.model.d.ts +3 -1
  116. package/dist/puck/editor/editor.model.js +2 -2
  117. package/dist/puck/editor/localPlacements.d.ts +1 -0
  118. package/dist/puck/editor/localPlacements.js +12 -0
  119. package/dist/puck/editor/placementsCache.d.ts +22 -12
  120. package/dist/puck/editor/placementsCache.js +62 -49
  121. package/dist/puck/editor/usePageSaveReadiness.d.ts +9 -0
  122. package/dist/puck/editor/usePageSaveReadiness.js +34 -0
  123. package/dist/puck/editor/usePlacementNotice.d.ts +2 -2
  124. package/dist/puck/editor/usePlacementNotice.js +6 -4
  125. package/dist/puck/experimentSlug.d.ts +2 -0
  126. package/dist/puck/experimentSlug.js +3 -0
  127. package/dist/puck/nestedTestCopy.d.ts +8 -0
  128. package/dist/puck/nestedTestCopy.js +22 -0
  129. package/dist/puck/nestedTests.d.ts +17 -0
  130. package/dist/puck/nestedTests.js +30 -0
  131. package/dist/puck/slotConfig.d.ts +1 -1
  132. package/dist/puck/slotConfig.js +17 -4
  133. package/dist/puck/visibility.d.ts +2 -3
  134. package/dist/puck/visibility.js +11 -7
  135. package/dist/results/aggregate.d.ts +6 -3
  136. package/dist/results/aggregate.js +9 -9
  137. package/dist/results/health.d.ts +8 -0
  138. package/dist/results/health.js +28 -0
  139. package/dist/results/identityCredit.d.ts +1 -0
  140. package/dist/results/identityCredit.js +4 -1
  141. package/dist/results/verdict.js +2 -1
  142. package/dist/runtime/cookie.d.ts +10 -2
  143. package/dist/runtime/cookie.js +38 -6
  144. package/dist/runtime/cookieOptions.d.ts +6 -0
  145. package/dist/runtime/cookieOptions.js +14 -0
  146. package/dist/runtime/proxyRuntime.d.ts +1 -0
  147. package/dist/runtime/proxyRuntime.js +18 -8
  148. package/dist/runtime/signing.d.ts +1 -0
  149. package/dist/runtime/signing.js +5 -0
  150. package/dist/sanitizeReadinessDetail.d.ts +2 -2
  151. package/dist/sanitizeReadinessDetail.js +20 -2
  152. package/dist/server/getAssignments.js +11 -10
  153. package/dist/server/recordContentChange.d.ts +1 -1
  154. package/dist/server/recordContentChange.js +45 -21
  155. package/dist/server/resolveExperimentBlocks.js +2 -4
  156. package/dist/server/resolveExperimentData.js +4 -7
  157. package/dist/server/runResults.js +52 -14
  158. package/dist/server/startExperiment.d.ts +20 -0
  159. package/dist/server/startExperiment.js +70 -0
  160. package/dist/server/trackConversion.js +10 -13
  161. package/dist/testSurface/PreviewLinks.js +6 -2
  162. package/dist/testSurface/actions/DecideDialog.d.ts +4 -1
  163. package/dist/testSurface/actions/DecideDialog.js +32 -14
  164. package/dist/testSurface/actions/MakeContentResult.d.ts +4 -3
  165. package/dist/testSurface/actions/MakeContentResult.js +9 -1
  166. package/dist/testSurface/api.d.ts +11 -8
  167. package/dist/testSurface/api.js +27 -11
  168. package/dist/testSurface/contentLocaleURL.d.ts +2 -0
  169. package/dist/testSurface/contentLocaleURL.js +3 -0
  170. package/dist/testSurface/copy/actions.d.ts +1 -0
  171. package/dist/testSurface/copy/actions.js +1 -0
  172. package/dist/testSurface/copy/common.d.ts +6 -0
  173. package/dist/testSurface/copy/common.js +11 -5
  174. package/dist/testSurface/copy/languages.d.ts +12 -0
  175. package/dist/testSurface/copy/languages.js +8 -0
  176. package/dist/testSurface/copy/metrics.d.ts +1 -0
  177. package/dist/testSurface/copy/metrics.js +1 -0
  178. package/dist/testSurface/copy/readiness.d.ts +13 -2
  179. package/dist/testSurface/copy/readiness.js +19 -2
  180. package/dist/testSurface/copy/results.d.ts +5 -2
  181. package/dist/testSurface/copy/results.js +5 -2
  182. package/dist/testSurface/copy/testPage.d.ts +40 -1
  183. package/dist/testSurface/copy/testPage.js +53 -1
  184. package/dist/testSurface/placementLabel.d.ts +8 -0
  185. package/dist/testSurface/placementLabel.js +24 -0
  186. package/dist/testSurface/placements/placementLabels.d.ts +2 -0
  187. package/dist/testSurface/placements/placementLabels.js +2 -1
  188. package/dist/testSurface/readPreflight.d.ts +5 -0
  189. package/dist/testSurface/readPreflight.js +7 -0
  190. package/dist/testSurface/readinessRead.d.ts +3 -0
  191. package/dist/testSurface/readinessRead.js +4 -0
  192. package/dist/testSurface/results/VerdictHero.d.ts +2 -1
  193. package/dist/testSurface/results/VerdictHero.js +5 -1
  194. package/dist/testSurface/results/results.css +1 -1
  195. package/dist/testSurface/results/results.model.d.ts +1 -1
  196. package/dist/testSurface/results/results.model.js +6 -2
  197. package/dist/testSurface/surface/contracts.d.ts +10 -1
  198. package/dist/testSurface/surface/editorPlacement.d.ts +7 -2
  199. package/dist/testSurface/surface/editorPlacement.js +19 -1
  200. package/dist/testSurface/surface/pageBlock/pageBlock.model.js +4 -3
  201. package/dist/testSurface/surface/pageBlock/parts.js +24 -6
  202. package/dist/testSurface/surface/pagePicker/PageCombobox.js +20 -6
  203. package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +4 -2
  204. package/dist/testSurface/surface/readiness/ActionDialogs.js +39 -34
  205. package/dist/testSurface/surface/readiness/Banner.js +23 -12
  206. package/dist/testSurface/surface/readiness/SaveStatus.d.ts +4 -3
  207. package/dist/testSurface/surface/readiness/SaveStatus.js +15 -15
  208. package/dist/testSurface/surface/readiness/readiness.model.d.ts +6 -1
  209. package/dist/testSurface/surface/readiness/readiness.model.js +116 -12
  210. package/dist/testSurface/surface/readiness/useTransition.d.ts +4 -4
  211. package/dist/testSurface/surface/readiness/useTransition.js +12 -10
  212. package/dist/testSurface/surface/results/ReleasePages.d.ts +4 -2
  213. package/dist/testSurface/surface/results/ReleasePages.js +5 -4
  214. package/dist/testSurface/surface/results/ResultsBody.d.ts +4 -2
  215. package/dist/testSurface/surface/results/ResultsBody.js +86 -43
  216. package/dist/testSurface/surface/results/useResults.d.ts +11 -7
  217. package/dist/testSurface/surface/results/useResults.js +3 -2
  218. package/dist/testSurface/surface/setting/parts.js +58 -18
  219. package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
  220. package/dist/testSurface/surface/test/DeleteTest.d.ts +19 -0
  221. package/dist/testSurface/surface/test/DeleteTest.js +262 -0
  222. package/dist/testSurface/surface/test/GoalSection.js +7 -3
  223. package/dist/testSurface/surface/test/LengthSection.js +3 -0
  224. package/dist/testSurface/surface/test/PageHoldout.js +4 -1
  225. package/dist/testSurface/surface/test/ReadinessBar.js +1 -1
  226. package/dist/testSurface/surface/test/TargetingSection.js +77 -12
  227. package/dist/testSurface/surface/test/TestSurface.js +97 -15
  228. package/dist/testSurface/surface/test/VersionsSection.js +56 -29
  229. package/dist/testSurface/surface/test/fields.d.ts +29 -4
  230. package/dist/testSurface/surface/test/fields.js +159 -39
  231. package/dist/testSurface/surface/test/pageParts.js +14 -5
  232. package/dist/testSurface/surface/test/testPage.model.d.ts +1 -0
  233. package/dist/testSurface/surface/test/testPage.model.js +6 -0
  234. package/dist/testSurface/surface/testDocument.model.d.ts +3 -0
  235. package/dist/testSurface/surface/testDocument.model.js +4 -1
  236. package/dist/testSurface/surface/useTestDocument.d.ts +23 -4
  237. package/dist/testSurface/surface/useTestDocument.js +425 -162
  238. package/dist/testSurface/useApi.d.ts +9 -6
  239. package/dist/testSurface/useOnTestReturn.d.ts +2 -0
  240. package/dist/testSurface/useOnTestReturn.js +27 -0
  241. package/dist/testSurface/useReadinessPolling.js +3 -1
  242. package/dist/transitions/addMetric.d.ts +1 -4
  243. package/dist/transitions/allocate.d.ts +2 -2
  244. package/dist/transitions/allocate.js +3 -1
  245. package/dist/transitions/archive.d.ts +1 -1
  246. package/dist/transitions/archive.js +3 -2
  247. package/dist/transitions/checkStart.d.ts +5 -1
  248. package/dist/transitions/checkStart.js +130 -16
  249. package/dist/transitions/contentFields.js +9 -5
  250. package/dist/transitions/decide.d.ts +1 -1
  251. package/dist/transitions/decide.js +5 -3
  252. package/dist/transitions/deleteExperiment.d.ts +2 -2
  253. package/dist/transitions/deleteExperiment.js +17 -7
  254. package/dist/transitions/kernel.d.ts +2 -0
  255. package/dist/transitions/kernel.js +9 -4
  256. package/dist/transitions/makeContent.d.ts +2 -1
  257. package/dist/transitions/makeContent.js +17 -12
  258. package/dist/transitions/nestedPlacementNames.d.ts +5 -0
  259. package/dist/transitions/nestedPlacementNames.js +32 -0
  260. package/dist/transitions/pageVersions.js +3 -1
  261. package/dist/transitions/phaseRecord.d.ts +2 -0
  262. package/dist/transitions/phaseRecord.js +5 -0
  263. package/dist/transitions/placementInteractions.d.ts +3 -3
  264. package/dist/transitions/placementInteractions.js +15 -11
  265. package/dist/transitions/placements.d.ts +28 -1
  266. package/dist/transitions/placements.js +223 -60
  267. package/dist/transitions/preflightData.d.ts +5 -3
  268. package/dist/transitions/preflightData.js +126 -37
  269. package/dist/transitions/releaseHoldout.d.ts +2 -1
  270. package/dist/transitions/releaseHoldout.js +3 -1
  271. package/dist/transitions/releasePages.d.ts +2 -1
  272. package/dist/transitions/releasePages.js +3 -1
  273. package/dist/transitions/resolveCaps.d.ts +2 -4
  274. package/dist/transitions/start.d.ts +6 -8
  275. package/dist/transitions/start.js +70 -34
  276. package/dist/transitions/startReads.d.ts +7 -0
  277. package/dist/transitions/startReads.js +28 -0
  278. package/dist/transitions/stop.d.ts +2 -1
  279. package/dist/transitions/stop.js +3 -2
  280. package/dist/types/contracts.d.ts +6 -3
  281. package/dist/types/endpoints.d.ts +86 -9
  282. package/dist/types/endpoints.js +1 -1
  283. package/dist/types/runtime.d.ts +15 -9
  284. package/dist/types/snapshot.d.ts +2 -0
  285. package/dist/types/surface.d.ts +2 -0
  286. package/dist/ui/Button.js +2 -2
  287. package/dist/ui/ChipsInput.d.ts +8 -1
  288. package/dist/ui/ChipsInput.js +17 -4
  289. package/dist/ui/Inputs.d.ts +4 -3
  290. package/dist/ui/Inputs.js +9 -9
  291. package/dist/ui/SelectControl.d.ts +33 -0
  292. package/dist/ui/SelectControl.js +504 -0
  293. package/dist/ui/ui.css +13 -5
  294. package/package.json +3 -2
@@ -1,3 +1,6 @@
1
+ import { placementLanguages } from '../blocks/placementLanguages.js';
2
+ import { puckExperimentSlug } from '../puck/experimentSlug.js';
3
+ import { nestedTests, nestedTestLabel, nestedTestSlug } from '../puck/nestedTests.js';
1
4
  import { walkVisiblePuck } from '../puck/visibility.js';
2
5
  import { BLOCK_SLOTS, EXPERIMENT_BLOCK_SLUG, hostBlocks, slotBlocks } from '../blocks/model.js';
3
6
  import { safeError } from '../log.js';
@@ -5,18 +8,17 @@ import { pageVersionContent } from '../db/pageContent.js';
5
8
  import { comparableContent } from './pageVersions.js';
6
9
  import { isDeepStrictEqual } from 'node:util';
7
10
  import { hasLocalizedFields } from './contentFields.js';
8
- import { localeRequest, placementLocaleContent, placementLocaleViews } from '../blocks/placementLocale.js';
9
- import { placementSlugs } from '../blocks/bindings.js';
10
- import { documentEditor, puckCollections as normalisePuckCollections } from '../options.js';
11
+ import { localeRequest, placementReader } from '../blocks/placementLocale.js';
12
+ import { puckCollections as normalisePuckCollections } from '../options.js';
11
13
  const slots = [
12
14
  'control',
13
15
  'variantA',
14
16
  'variantB',
15
17
  'variantC'
16
18
  ];
17
- async function placementDocuments(req, query, guard) {
18
- // §7.8 page guard: the hook must see test placements regardless of the editor's access.
19
- if (guard) return req.payload.find({
19
+ async function placementDocuments(req, query, readAll) {
20
+ // §7.8: page guards, visitor impact and system Start need all placements to check the visitor surface.
21
+ if (readAll) return req.payload.find({
20
22
  ...query,
21
23
  req,
22
24
  overrideAccess: true
@@ -45,16 +47,17 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
45
47
  /** Published rows only, one pass per collection across both editor registrations.
46
48
  * The exclusion predicate reads live transaction claims after each awaited page.
47
49
  */ export async function hasOtherPublishedBlockPlacement(req, options, slug, excluded) {
48
- const scanReq = req.payload.config.localization ? {
49
- ...req,
50
- locale: 'all'
51
- } : req;
50
+ const scanReq = localeRequest(req, {
51
+ locale: req.payload.config.localization ? 'all' : req.locale ?? '',
52
+ fallbackLocale: false
53
+ });
52
54
  const collections = new Set([
53
55
  ...normalisePuckCollections(options).map((entry)=>entry.slug),
54
56
  ...(options.blocks?.collections ?? []).map((entry)=>entry.slug)
55
57
  ]);
56
58
  for (const collection of collections){
57
59
  const drafts = req.payload.config.collections?.some((c)=>c.slug === collection && c.versions && c.versions.drafts);
60
+ const reader = placementReader(req, collection, options);
58
61
  let page = 1;
59
62
  while(true){
60
63
  const result = await placementDocuments(scanReq, {
@@ -76,15 +79,116 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
76
79
  }
77
80
  } : {}
78
81
  }, true);
79
- if (result.docs.some((doc)=>doc._status !== 'draft' && doc.deletedAt == null && placementLocaleViews(req, collection).some((view)=>placementSlugs(options, collection, placementLocaleContent(localeRequest(req, view), collection, doc)).includes(slug) && !excluded(collection, doc.id, view, doc)))) return true;
82
+ if (result.docs.some((doc)=>doc._status !== 'draft' && doc.deletedAt == null && reader.views.some((view)=>reader.read(doc, 'all-locales', view).slugs.includes(slug) && !excluded(collection, doc.id, view, doc)))) return true;
80
83
  if (!result.hasNextPage) break;
81
84
  page++;
82
85
  }
83
86
  }
84
87
  return false;
85
88
  }
89
+ /** Visitor-impact scan: one published read per collection page. Resolve every
90
+ * visitor locale, including configured fallbacks; the endpoint groups by page.
91
+ */ export async function* publishedBlockPlacementPages(req, options, slug) {
92
+ const scanReq = localeRequest(req, {
93
+ locale: req.payload.config.localization ? 'all' : req.locale ?? '',
94
+ fallbackLocale: false
95
+ });
96
+ const puck = options.puck?.enabled ? normalisePuckCollections(options) : [], blocks = options.blocks?.collections ?? [];
97
+ for (const collection of new Set([
98
+ ...puck,
99
+ ...blocks
100
+ ].map((entry)=>entry.slug))){
101
+ const drafts = req.payload.config.collections?.some((c)=>c.slug === collection && c.versions && c.versions.drafts);
102
+ const reader = placementReader(req, collection, options);
103
+ let page = 1;
104
+ while(true){
105
+ req.signal?.throwIfAborted();
106
+ const result = await placementDocuments(scanReq, {
107
+ collection,
108
+ overrideAccess: false,
109
+ limit: 100,
110
+ page,
111
+ depth: 0,
112
+ draft: false,
113
+ ...req.payload.config.localization ? {
114
+ locale: 'all',
115
+ fallbackLocale: false
116
+ } : {},
117
+ ...drafts ? {
118
+ where: {
119
+ _status: {
120
+ equals: 'published'
121
+ }
122
+ }
123
+ } : {}
124
+ }, true);
125
+ req.signal?.throwIfAborted();
126
+ const placements = [];
127
+ for (const raw of result.docs){
128
+ if (raw._status === 'draft' || raw.deletedAt != null) continue;
129
+ for (const view of reader.views){
130
+ const placement = reader.read(raw, 'all-locales', view);
131
+ const doc = placement.doc;
132
+ const add = (contents, editor)=>placements.push({
133
+ id: raw.id,
134
+ editor,
135
+ slots: contents,
136
+ ...view.locale ? {
137
+ locale: view.locale
138
+ } : {}
139
+ });
140
+ if (placement.editor === 'puck') {
141
+ const registration = puck.find((entry)=>entry.slug === collection);
142
+ if (registration) walkVisiblePuck(doc[registration.field], (node, visibility)=>{
143
+ if (!visibility.hidden && node.type === 'ExperimentSlot' && puckExperimentSlug(node.props.experiment) === slug) {
144
+ add(Object.fromEntries(slots.map((slot)=>[
145
+ slot,
146
+ Array.isArray(node.props[slot]) ? node.props[slot].length : 0
147
+ ])), 'puck');
148
+ }
149
+ });
150
+ } else {
151
+ const registration = blocks.find((entry)=>entry.slug === collection);
152
+ if (registration) for (const block of hostBlocks(doc[registration.field])){
153
+ if (block.blockType === (registration.blockSlug ?? EXPERIMENT_BLOCK_SLUG) && block.experiment === slug) {
154
+ add(Object.fromEntries(BLOCK_SLOTS.map((slot)=>[
155
+ slot,
156
+ slotBlocks(block, slot).length
157
+ ])), 'blocks');
158
+ }
159
+ }
160
+ }
161
+ }
162
+ }
163
+ yield {
164
+ collection,
165
+ placements
166
+ };
167
+ if (!result.hasNextPage) break;
168
+ page++;
169
+ }
170
+ }
171
+ }
86
172
  export async function scanBlockPlacements(req, args) {
87
173
  const { puckCollections } = args;
174
+ const scanReq = localeRequest(req, {
175
+ locale: req.payload.config.localization ? 'all' : req.locale ?? '',
176
+ fallbackLocale: req.payload.config.localization ? false : req.fallbackLocale ?? false
177
+ });
178
+ const comparisons = new Map();
179
+ const comparison = (collection, id)=>{
180
+ if (!req.payload.config.localization) return comparisonContent(req, collection, id);
181
+ const key = JSON.stringify([
182
+ collection,
183
+ String(id)
184
+ ]);
185
+ let pending = comparisons.get(key);
186
+ if (!pending) {
187
+ pending = comparisonContent(req, collection, id);
188
+ comparisons.set(key, pending);
189
+ }
190
+ return pending;
191
+ };
88
192
  const slugs = args.slugs ?? new Set([
89
193
  args.slug
90
194
  ]);
@@ -100,17 +204,28 @@ export async function scanBlockPlacements(req, args) {
100
204
  collections: puckCollections
101
205
  }
102
206
  })){
207
+ const reader = placementReader(req, collection, {
208
+ puck: {
209
+ enabled: true,
210
+ collections: puckCollections
211
+ },
212
+ blocks: {
213
+ collections: args.blocksCollections
214
+ }
215
+ });
103
216
  const editors = new Map();
104
217
  const publishedIds = new Set();
105
218
  const publishedSlugs = new Map();
106
219
  const draftsEnabled = req.payload.config.collections?.some((config)=>config.slug === collection && config.versions && config.versions.drafts);
107
- for (const draft of [
220
+ for (const draft of args.publishedOnly ? [
221
+ false
222
+ ] : [
108
223
  false,
109
224
  true
110
225
  ]){
111
226
  let page = 1;
112
227
  while(true){
113
- const result = await placementDocuments(req, {
228
+ const result = await placementDocuments(scanReq, {
114
229
  collection,
115
230
  req,
116
231
  overrideAccess: false,
@@ -119,6 +234,10 @@ export async function scanBlockPlacements(req, args) {
119
234
  depth: 0,
120
235
  draft,
121
236
  includeLockStatus: true,
237
+ ...req.payload.config.localization ? {
238
+ locale: 'all',
239
+ fallbackLocale: false
240
+ } : {},
122
241
  ...!draft && draftsEnabled ? {
123
242
  where: {
124
243
  _status: {
@@ -126,33 +245,34 @@ export async function scanBlockPlacements(req, args) {
126
245
  }
127
246
  }
128
247
  } : {}
129
- }, args.pageGuard);
130
- for (const doc of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled))){
248
+ }, args.pageGuard || args.system);
249
+ for (const localized of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled)))for (const view of reader.views){
250
+ const doc = reader.read(localized, 'all-locales', view).doc;
251
+ const documentKey = JSON.stringify([
252
+ String(doc.id),
253
+ view.locale
254
+ ]);
131
255
  if (!draft && doc._status === 'draft') continue;
132
- if (draft && doc._status !== 'draft' && publishedIds.has(String(doc.id))) continue;
256
+ if (draft && doc._status !== 'draft' && publishedIds.has(documentKey)) continue;
133
257
  if (!draft) {
134
- editors.set(String(doc.id), documentEditor({
135
- puck: {
136
- enabled: true,
137
- collections: puckCollections
138
- },
139
- blocks: {
140
- collections: args.blocksCollections
141
- }
142
- }, collection, doc));
143
- publishedIds.add(String(doc.id));
144
- if (typeof doc.slug === 'string') publishedSlugs.set(String(doc.id), doc.slug);
258
+ editors.set(documentKey, reader.read(doc, 'localized').editor);
259
+ publishedIds.add(documentKey);
260
+ if (typeof doc.slug === 'string') publishedSlugs.set(documentKey, doc.slug);
145
261
  }
146
- const editor = editors.get(String(doc.id)) ?? documentEditor({
147
- puck: {
148
- enabled: true,
149
- collections: puckCollections
150
- },
151
- blocks: {
152
- collections: args.blocksCollections
153
- }
154
- }, collection, doc);
262
+ const editor = editors.get(documentKey) ?? reader.read(doc, 'localized').editor;
155
263
  if (editor !== 'puck') continue;
264
+ const nearest = new Map(nestedTests(doc[field]).map((pair)=>[
265
+ pair.inner,
266
+ pair
267
+ ]));
268
+ const nested = [
269
+ ...nearest.values()
270
+ ].map(({ outer, inner })=>({
271
+ outer: nestedTestLabel(outer),
272
+ inner: nestedTestLabel(inner),
273
+ outerSlug: nestedTestSlug(outer),
274
+ innerSlug: nestedTestSlug(inner)
275
+ }));
156
276
  const offsets = new Map([
157
277
  ...placements
158
278
  ].map(([slug, list])=>[
@@ -162,18 +282,26 @@ export async function scanBlockPlacements(req, args) {
162
282
  walkVisiblePuck(doc[field], (node, visibility)=>{
163
283
  if (visibility.hidden) return;
164
284
  const props = node.props;
165
- const ref = props.experiment;
166
- const experiment = typeof ref === 'string' ? ref : ref && typeof ref === 'object' && 'slug' in ref ? ref.slug : null;
285
+ const experiment = puckExperimentSlug(props.experiment);
167
286
  if (node.type === 'ExperimentSlot' && typeof experiment === 'string' && slugs.has(experiment)) {
168
287
  placements.get(experiment).push({
169
288
  collection,
170
289
  id: doc.id,
171
290
  editor: 'puck',
172
291
  doc,
292
+ nestedTests: nested.filter((pair)=>pair.outerSlug === experiment || pair.innerSlug === experiment).map(({ outer, inner, outerSlug, innerSlug })=>({
293
+ outer,
294
+ inner,
295
+ outerSlug: outerSlug ?? '',
296
+ innerSlug: innerSlug ?? ''
297
+ })),
298
+ ...view.locale ? {
299
+ locale: view.locale
300
+ } : {},
173
301
  title: String(doc.title ?? doc.name ?? doc.id),
174
302
  published: !draft || doc._status === 'published',
175
- ...publishedSlugs.has(String(doc.id)) ? {
176
- slug: publishedSlugs.get(String(doc.id))
303
+ ...publishedSlugs.has(documentKey) ? {
304
+ slug: publishedSlugs.get(documentKey)
177
305
  } : {},
178
306
  slots: Object.fromEntries(slots.map((slot)=>[
179
307
  slot,
@@ -189,13 +317,12 @@ export async function scanBlockPlacements(req, args) {
189
317
  if (args.compareVersions && !draft && [
190
318
  ...placements
191
319
  ].some(([slug, list])=>list.length > offsets.get(slug))) {
192
- const raw = await comparisonContent(req, collection, doc.id);
320
+ const raw = reader.read(await comparison(collection, doc.id), 'all-locales', view).doc;
193
321
  const rawSlots = new Map();
194
322
  const collect = (value)=>walkVisiblePuck(value, (node, visibility)=>{
195
323
  if (visibility.hidden) return;
196
324
  const props = node.props;
197
- const ref = props?.experiment;
198
- const slug = typeof ref === 'string' ? ref : ref && typeof ref === 'object' && 'slug' in ref ? ref.slug : undefined;
325
+ const slug = puckExperimentSlug(props?.experiment);
199
326
  if (node.type === 'ExperimentSlot' && props && typeof slug === 'string') {
200
327
  const list = rawSlots.get(slug) ?? [];
201
328
  list.push(props);
@@ -216,15 +343,26 @@ export async function scanBlockPlacements(req, args) {
216
343
  }
217
344
  for (const registration of args.blocksCollections){
218
345
  const { slug: collection, field } = registration;
346
+ const reader = placementReader(req, collection, {
347
+ puck: {
348
+ enabled: true,
349
+ collections: puckCollections
350
+ },
351
+ blocks: {
352
+ collections: args.blocksCollections
353
+ }
354
+ });
219
355
  const published = new Map();
220
356
  const draftsEnabled = req.payload.config.collections?.some((c)=>c.slug === collection && c.versions && c.versions.drafts);
221
- for (const draft of [
357
+ for (const draft of args.publishedOnly ? [
358
+ false
359
+ ] : [
222
360
  false,
223
361
  true
224
362
  ]){
225
363
  let page = 1;
226
364
  while(true){
227
- const result = await placementDocuments(req, {
365
+ const result = await placementDocuments(scanReq, {
228
366
  collection,
229
367
  req,
230
368
  overrideAccess: false,
@@ -233,6 +371,10 @@ export async function scanBlockPlacements(req, args) {
233
371
  page,
234
372
  draft,
235
373
  includeLockStatus: true,
374
+ ...req.payload.config.localization ? {
375
+ locale: 'all',
376
+ fallbackLocale: false
377
+ } : {},
236
378
  ...!draft && draftsEnabled ? {
237
379
  where: {
238
380
  _status: {
@@ -240,22 +382,19 @@ export async function scanBlockPlacements(req, args) {
240
382
  }
241
383
  }
242
384
  } : {}
243
- }, args.pageGuard);
244
- for (const doc of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled))){
385
+ }, args.pageGuard || args.system);
386
+ for (const localized of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled)))for (const view of reader.views){
387
+ const doc = reader.read(localized, 'all-locales', view).doc;
388
+ const documentKey = JSON.stringify([
389
+ String(doc.id),
390
+ view.locale
391
+ ]);
245
392
  if (!draft && doc._status === 'draft') continue;
246
- if (!draft) published.set(String(doc.id), doc);
247
- else if (doc._status !== 'draft' && published.has(String(doc.id))) continue;
248
- const baseline = published.get(String(doc.id)) ?? doc;
249
- if (documentEditor({
250
- blocks: {
251
- collections: args.blocksCollections
252
- },
253
- puck: {
254
- enabled: true,
255
- collections: puckCollections
256
- }
257
- }, collection, baseline) !== 'blocks') continue;
258
- const raw = args.compareVersions && !draft && hostBlocks(doc[field]).some((block)=>block.blockType === (registration.blockSlug ?? EXPERIMENT_BLOCK_SLUG) && typeof block.experiment === 'string' && slugs.has(block.experiment)) ? await comparisonContent(req, collection, doc.id) : undefined;
393
+ if (!draft) published.set(documentKey, doc);
394
+ else if (doc._status !== 'draft' && published.has(documentKey)) continue;
395
+ const baseline = published.get(documentKey) ?? doc;
396
+ if (reader.read(baseline, 'localized').editor !== 'blocks') continue;
397
+ const raw = args.compareVersions && !draft && hostBlocks(doc[field]).some((block)=>block.blockType === (registration.blockSlug ?? EXPERIMENT_BLOCK_SLUG) && typeof block.experiment === 'string' && slugs.has(block.experiment)) ? reader.read(await comparison(collection, doc.id), 'all-locales', view).doc : undefined;
259
398
  for (const [index, block] of hostBlocks(doc[field]).entries()){
260
399
  if (block.blockType !== (registration.blockSlug ?? EXPERIMENT_BLOCK_SLUG) || typeof block.experiment !== 'string' || !slugs.has(block.experiment)) continue;
261
400
  const stored = raw ? hostBlocks(raw[field]).find((row)=>row.id === block.id) ?? hostBlocks(raw[field])[index] ?? block : block;
@@ -266,6 +405,9 @@ export async function scanBlockPlacements(req, args) {
266
405
  id: doc.id,
267
406
  editor: 'blocks',
268
407
  doc,
408
+ ...view.locale ? {
409
+ locale: view.locale
410
+ } : {},
269
411
  title: String(doc.title ?? doc.name ?? doc.id),
270
412
  published: !draft || doc._status === 'published',
271
413
  ...typeof baseline.slug === 'string' ? {
@@ -289,6 +431,27 @@ export async function scanBlockPlacements(req, args) {
289
431
  }
290
432
  }
291
433
  }
434
+ for (const list of placements.values()){
435
+ const groups = new Map();
436
+ for (const placement of list)if (placement.locale) {
437
+ const key = JSON.stringify([
438
+ placement.collection,
439
+ String(placement.id),
440
+ placement.published
441
+ ]);
442
+ const group = groups.get(key) ?? [];
443
+ group.push(placement);
444
+ groups.set(key, group);
445
+ }
446
+ for (const group of groups.values()){
447
+ const languages = placementLanguages(req, group.map((placement)=>placement.locale));
448
+ for (const placement of group)Object.assign(placement, languages, {
449
+ localeLabel: placementLanguages(req, [
450
+ placement.locale
451
+ ]).locales?.[0] ?? placement.locale
452
+ });
453
+ }
454
+ }
292
455
  return args.slugs ? placements : placements.get(args.slug);
293
456
  }
294
457
  export async function flagPlacements(options, experiment, req) {
@@ -10,9 +10,10 @@ export interface PreflightDependencies {
10
10
  /** Read-only inputs shared with Start's pre-transaction checks. Start must re-read
11
11
  * the document and lock-sensitive facts inside its transition (CORE-10b).
12
12
  */
13
+ export declare function readStartInputExperiment(req: PayloadRequest, experimentId: DocId, system?: boolean): Promise<StartExperiment | null>;
13
14
  export declare function loadStartInputs<TUser extends {
14
15
  id: DocId;
15
- }>(req: PayloadRequest, options: ResolvedOptions<TUser>, experimentId: DocId): Promise<CheckStartInput | null>;
16
+ }>(req: PayloadRequest, options: ResolvedOptions<TUser>, experimentId: DocId, system?: boolean): Promise<CheckStartInput | null>;
16
17
  /** Occupancy from the arms the runtime routes on (frozen rounds), shared by preflight and
17
18
  * Start's locked recheck. Raw SQL on the request's transaction when there is one. */
18
19
  export declare function loadPageTestsInUse(req: PayloadRequest): Promise<NonNullable<CheckStartInput['pageTestsInUse']>>;
@@ -26,10 +27,11 @@ export declare function unpublishedPageTargets<TUser extends {
26
27
  */
27
28
  export declare function loadStartInputsBatch<TUser extends {
28
29
  id: DocId;
29
- }>(req: PayloadRequest, options: ResolvedOptions<TUser>, experiments: StartExperiment[], tolerateErrors?: boolean): Promise<Map<string, CheckStartInput | null>>;
30
+ }>(req: PayloadRequest, options: ResolvedOptions<TUser>, experiments: StartExperiment[], tolerateErrors?: boolean, system?: boolean): Promise<Map<string, CheckStartInput | null>>;
30
31
  export declare function preflightData<TUser extends {
31
32
  id: DocId;
32
- }>(req: PayloadRequest, { experimentId, options }: {
33
+ }>(req: PayloadRequest, { experimentId, options, placementLocale }: {
33
34
  experimentId: DocId;
34
35
  options: ResolvedOptions<TUser>;
36
+ placementLocale?: string;
35
37
  }, { now, estimate }?: PreflightDependencies): Promise<PreflightResult | null>;