@delmaredigital/payload-experiments 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/README.md +9 -5
  2. package/dist/admin/blocks/model.js +2 -0
  3. package/dist/admin/copy/blocks.d.ts +1 -0
  4. package/dist/admin/copy/blocks.js +1 -0
  5. package/dist/admin/copy/status.d.ts +3 -0
  6. package/dist/admin/copy/status.js +3 -0
  7. package/dist/admin/placementStatus.model.js +3 -0
  8. package/dist/admin/status.model.d.ts +3 -2
  9. package/dist/admin/status.model.js +9 -3
  10. package/dist/admin/surface/ResultsRoute.js +2 -1
  11. package/dist/admin/surface/TestsHome.d.ts +2 -1
  12. package/dist/admin/surface/TestsHome.js +31 -11
  13. package/dist/admin/surface/TestsSurface.js +4 -0
  14. package/dist/admin/surface/home.model.d.ts +11 -6
  15. package/dist/admin/surface/home.model.js +19 -8
  16. package/dist/admin/surface/newTest/PageWizard.js +13 -3
  17. package/dist/admin/surface/results/ResultsHeader.js +43 -9
  18. package/dist/admin/surface/test/TestPage.js +11 -1
  19. package/dist/admin/useLayerUsage.d.ts +1 -1
  20. package/dist/admin/views/buildSurfaceProps.js +3 -0
  21. package/dist/blocks/placementLocale.d.ts +14 -0
  22. package/dist/blocks/placementLocale.js +80 -13
  23. package/dist/blocks/placementPublication.d.ts +14 -0
  24. package/dist/blocks/placementPublication.js +24 -0
  25. package/dist/cohorts/build.d.ts +35 -0
  26. package/dist/cohorts/build.js +134 -0
  27. package/dist/cohorts/key.d.ts +12 -0
  28. package/dist/cohorts/key.js +15 -0
  29. package/dist/cohorts/maintenance.d.ts +10 -0
  30. package/dist/cohorts/maintenance.js +70 -0
  31. package/dist/cohorts/readiness.d.ts +30 -0
  32. package/dist/cohorts/readiness.js +54 -0
  33. package/dist/cohorts/readinessData.d.ts +29 -0
  34. package/dist/cohorts/readinessData.js +123 -0
  35. package/dist/cohorts/rule.d.ts +33 -0
  36. package/dist/cohorts/rule.js +50 -0
  37. package/dist/collections/cohortMembers.d.ts +4 -0
  38. package/dist/collections/cohortMembers.js +95 -0
  39. package/dist/collections/experiments/config.js +157 -7
  40. package/dist/collections/experiments/editability.js +10 -6
  41. package/dist/collections/experiments/lockHook.js +39 -20
  42. package/dist/collections/index.js +4 -1
  43. package/dist/collections/phases.js +4 -1
  44. package/dist/constants.d.ts +2 -0
  45. package/dist/constants.js +2 -0
  46. package/dist/db/adapter.d.ts +2 -1
  47. package/dist/db/adapter.js +17 -4
  48. package/dist/db/appends.d.ts +2 -1
  49. package/dist/db/appends.js +3 -2
  50. package/dist/db/bulkPlacementRemoval.d.ts +5 -0
  51. package/dist/db/bulkPlacementRemoval.js +7 -2
  52. package/dist/db/cohortMembership.d.ts +11 -0
  53. package/dist/db/cohortMembership.js +31 -0
  54. package/dist/db/cohortPool.d.ts +9 -0
  55. package/dist/db/cohortPool.js +53 -0
  56. package/dist/db/cohortTransactions.d.ts +3 -0
  57. package/dist/db/cohortTransactions.js +52 -0
  58. package/dist/db/cohorts.d.ts +72 -0
  59. package/dist/db/cohorts.js +280 -0
  60. package/dist/db/erase.d.ts +2 -0
  61. package/dist/db/erase.js +21 -2
  62. package/dist/db/events.d.ts +2 -0
  63. package/dist/db/events.js +8 -0
  64. package/dist/db/executor.d.ts +2 -0
  65. package/dist/db/executor.js +8 -0
  66. package/dist/db/locks.d.ts +7 -0
  67. package/dist/db/locks.js +13 -1
  68. package/dist/db/names.d.ts +95 -1
  69. package/dist/db/names.js +95 -1
  70. package/dist/db/occupancy.d.ts +21 -0
  71. package/dist/db/occupancy.js +46 -0
  72. package/dist/db/pageBindings.d.ts +2 -2
  73. package/dist/db/pageBindings.js +3 -3
  74. package/dist/db/pageOccupancy.d.ts +4 -4
  75. package/dist/db/pageOccupancy.js +13 -10
  76. package/dist/db/pgExecutor.d.ts +4 -0
  77. package/dist/db/pgExecutor.js +1 -1
  78. package/dist/db/placements.d.ts +6 -1
  79. package/dist/db/placements.js +27 -1
  80. package/dist/db/results.d.ts +5 -2
  81. package/dist/db/results.js +32 -5
  82. package/dist/db/slices.d.ts +9 -2
  83. package/dist/db/slices.js +15 -8
  84. package/dist/db/snapshots.d.ts +16 -1
  85. package/dist/db/snapshots.js +27 -2
  86. package/dist/db/sql.d.ts +2 -2
  87. package/dist/db/sql.js +1 -2
  88. package/dist/endpoints/cohortSources.d.ts +16 -0
  89. package/dist/endpoints/cohortSources.js +335 -0
  90. package/dist/endpoints/contentLocale.d.ts +1 -1
  91. package/dist/endpoints/duplicateOriginal.d.ts +1 -0
  92. package/dist/endpoints/events.js +82 -18
  93. package/dist/endpoints/index.js +45 -1
  94. package/dist/endpoints/pausedBy.d.ts +14 -0
  95. package/dist/endpoints/pausedBy.js +94 -0
  96. package/dist/endpoints/preflight.js +4 -1
  97. package/dist/endpoints/previewToken.js +2 -0
  98. package/dist/endpoints/results.d.ts +2 -2
  99. package/dist/endpoints/results.js +111 -3
  100. package/dist/endpoints/routeId.d.ts +2 -1
  101. package/dist/endpoints/routeId.js +6 -2
  102. package/dist/endpoints/summary.js +24 -1
  103. package/dist/endpoints/transitions.d.ts +7 -0
  104. package/dist/endpoints/transitions.js +50 -1
  105. package/dist/events/rows.d.ts +1 -1
  106. package/dist/events/rows.js +5 -3
  107. package/dist/exports/index.d.ts +2 -0
  108. package/dist/exports/index.js +1 -0
  109. package/dist/exports/runtimeProxy.d.ts +1 -0
  110. package/dist/exports/runtimeProxy.js +1 -0
  111. package/dist/hooks/blockRemovalRule.d.ts +1 -1
  112. package/dist/hooks/blockRemovalRule.js +12 -8
  113. package/dist/hooks/pageGuard.d.ts +7 -1
  114. package/dist/hooks/pageGuard.js +177 -4
  115. package/dist/hooks/puckNestedTests.d.ts +1 -1
  116. package/dist/hooks/puckNestedTests.js +3 -1
  117. package/dist/labels/status.d.ts +15 -0
  118. package/dist/labels/status.js +12 -0
  119. package/dist/manifest/compile.d.ts +15 -4
  120. package/dist/manifest/compile.js +91 -3
  121. package/dist/onInit.js +4 -6
  122. package/dist/options.d.ts +1 -0
  123. package/dist/options.js +10 -0
  124. package/dist/proxy/consentFallback.d.ts +1 -1
  125. package/dist/proxy/consentFallback.js +4 -4
  126. package/dist/proxy/control.d.ts +1 -1
  127. package/dist/proxy/control.js +2 -2
  128. package/dist/proxy/pageRewrite.d.ts +1 -1
  129. package/dist/proxy/pageRewrite.js +3 -2
  130. package/dist/proxy/resolve.js +76 -17
  131. package/dist/puck/ExperimentPicker.js +2 -1
  132. package/dist/puck/copy.d.ts +6 -5
  133. package/dist/puck/copy.js +3 -7
  134. package/dist/puck/editor/ExperimentSlotEditor.js +16 -5
  135. package/dist/puck/editor/QuickTestActions.js +7 -1
  136. package/dist/puck/editor/armWrites.js +6 -1
  137. package/dist/puck/editor/copy.d.ts +3 -0
  138. package/dist/puck/editor/copy.js +3 -0
  139. package/dist/puck/editor/editor.css +2 -1
  140. package/dist/puck/editor/editor.model.d.ts +2 -1
  141. package/dist/puck/editor/editor.model.js +2 -0
  142. package/dist/puck/editor/placementsCache.d.ts +1 -1
  143. package/dist/puck/editor/placementsCache.js +6 -3
  144. package/dist/results/analyse.d.ts +3 -1
  145. package/dist/results/analyse.js +20 -3
  146. package/dist/results/health.d.ts +11 -0
  147. package/dist/results/health.js +38 -0
  148. package/dist/results/power.d.ts +1 -1
  149. package/dist/results/power.js +1 -1
  150. package/dist/results/snapshot.d.ts +8 -2
  151. package/dist/results/snapshot.js +23 -1
  152. package/dist/results/unitValues.d.ts +48 -0
  153. package/dist/results/unitValues.js +166 -0
  154. package/dist/runtime/assign.d.ts +7 -3
  155. package/dist/runtime/assign.js +12 -4
  156. package/dist/runtime/cohortCookie.d.ts +15 -0
  157. package/dist/runtime/cohortCookie.js +72 -0
  158. package/dist/runtime/cohortLookup.d.ts +9 -0
  159. package/dist/runtime/cohortLookup.js +25 -0
  160. package/dist/runtime/eligibility.d.ts +11 -5
  161. package/dist/runtime/eligibility.js +33 -7
  162. package/dist/runtime/header.d.ts +1 -0
  163. package/dist/runtime/header.js +1 -1
  164. package/dist/runtime/proxyRuntime.js +5 -1
  165. package/dist/runtime/targeting.d.ts +3 -2
  166. package/dist/runtime/targeting.js +2 -1
  167. package/dist/sanitizeReadinessDetail.d.ts +2 -2
  168. package/dist/sanitizeReadinessDetail.js +41 -4
  169. package/dist/schedule/activeTime.d.ts +28 -0
  170. package/dist/schedule/activeTime.js +322 -0
  171. package/dist/schedule/ranges.d.ts +13 -0
  172. package/dist/schedule/ranges.js +11 -0
  173. package/dist/schedule/roundTime.d.ts +10 -0
  174. package/dist/schedule/roundTime.js +45 -0
  175. package/dist/schedule/types.d.ts +29 -0
  176. package/dist/schedule/types.js +1 -0
  177. package/dist/server/cohortLookup.d.ts +3 -0
  178. package/dist/server/cohortLookup.js +7 -0
  179. package/dist/server/eraseUser.d.ts +1 -0
  180. package/dist/server/getAssignments.js +63 -40
  181. package/dist/server/previewDraft.d.ts +1 -1
  182. package/dist/server/previewDraft.js +3 -2
  183. package/dist/server/recordContentChange.d.ts +1 -1
  184. package/dist/server/recordContentChange.js +42 -20
  185. package/dist/server/recordExposures.js +4 -2
  186. package/dist/server/runResults.js +97 -150
  187. package/dist/testSurface/actions/LifecycleAction.d.ts +2 -1
  188. package/dist/testSurface/actions/LifecycleAction.js +15 -5
  189. package/dist/testSurface/actions/actions.model.d.ts +13 -2
  190. package/dist/testSurface/actions/actions.model.js +38 -5
  191. package/dist/testSurface/api.d.ts +13 -1
  192. package/dist/testSurface/api.js +19 -0
  193. package/dist/testSurface/copy/actions.d.ts +13 -0
  194. package/dist/testSurface/copy/actions.js +13 -0
  195. package/dist/testSurface/copy/cohorts.d.ts +68 -0
  196. package/dist/testSurface/copy/cohorts.js +81 -0
  197. package/dist/testSurface/copy/common.d.ts +2 -3
  198. package/dist/testSurface/copy/common.js +4 -4
  199. package/dist/testSurface/copy/inputs.d.ts +3 -0
  200. package/dist/testSurface/copy/inputs.js +3 -0
  201. package/dist/testSurface/copy/readiness.d.ts +20 -6
  202. package/dist/testSurface/copy/readiness.js +42 -9
  203. package/dist/testSurface/copy/results.d.ts +1 -0
  204. package/dist/testSurface/copy/results.js +1 -0
  205. package/dist/testSurface/copy/schedule.d.ts +58 -0
  206. package/dist/testSurface/copy/schedule.js +150 -0
  207. package/dist/testSurface/copy/surface.d.ts +2 -0
  208. package/dist/testSurface/copy/surface.js +2 -0
  209. package/dist/testSurface/copy/testPage.d.ts +12 -2
  210. package/dist/testSurface/copy/testPage.js +17 -2
  211. package/dist/testSurface/format/roundProgress.d.ts +13 -1
  212. package/dist/testSurface/format/roundProgress.js +34 -5
  213. package/dist/testSurface/format/scheduleStatus.d.ts +34 -0
  214. package/dist/testSurface/format/scheduleStatus.js +93 -0
  215. package/dist/testSurface/format/useScheduleClock.d.ts +3 -0
  216. package/dist/testSurface/format/useScheduleClock.js +20 -0
  217. package/dist/testSurface/labels.d.ts +4 -9
  218. package/dist/testSurface/labels.js +2 -7
  219. package/dist/testSurface/lockedNotice.model.d.ts +2 -2
  220. package/dist/testSurface/lockedNotice.model.js +16 -3
  221. package/dist/testSurface/readPreflight.d.ts +3 -0
  222. package/dist/testSurface/readPreflight.js +14 -0
  223. package/dist/testSurface/readinessRead.d.ts +2 -2
  224. package/dist/testSurface/results/DataQualityPanel.js +7 -7
  225. package/dist/testSurface/results/results.model.d.ts +1 -1
  226. package/dist/testSurface/results/results.model.js +34 -6
  227. package/dist/testSurface/review/cohortEstimate.d.ts +11 -0
  228. package/dist/testSurface/review/cohortEstimate.js +32 -0
  229. package/dist/testSurface/surface/contracts.d.ts +2 -1
  230. package/dist/testSurface/surface/contracts.js +1 -0
  231. package/dist/testSurface/surface/editorPlacement.d.ts +1 -0
  232. package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +3 -2
  233. package/dist/testSurface/surface/readiness/ActionDialogs.js +121 -32
  234. package/dist/testSurface/surface/readiness/Banner.js +29 -11
  235. package/dist/testSurface/surface/readiness/readiness.model.d.ts +20 -2
  236. package/dist/testSurface/surface/readiness/readiness.model.js +35 -5
  237. package/dist/testSurface/surface/readiness/useTransition.js +17 -5
  238. package/dist/testSurface/surface/results/ResultsBody.js +44 -8
  239. package/dist/testSurface/surface/results/useResults.d.ts +16 -1
  240. package/dist/testSurface/surface/results/useResults.js +17 -6
  241. package/dist/testSurface/surface/test/CohortRuleEditor.d.ts +16 -0
  242. package/dist/testSurface/surface/test/CohortRuleEditor.js +492 -0
  243. package/dist/testSurface/surface/test/LengthSection.js +26 -6
  244. package/dist/testSurface/surface/test/ScheduleDateInput.d.ts +4 -0
  245. package/dist/testSurface/surface/test/ScheduleDateInput.js +15 -0
  246. package/dist/testSurface/surface/test/ScheduleSection.d.ts +2 -0
  247. package/dist/testSurface/surface/test/ScheduleSection.js +322 -0
  248. package/dist/testSurface/surface/test/Section.js +1 -1
  249. package/dist/testSurface/surface/test/TargetingSection.js +306 -182
  250. package/dist/testSurface/surface/test/TestSurface.js +9 -0
  251. package/dist/testSurface/surface/test/fields.d.ts +2 -1
  252. package/dist/testSurface/surface/test/fields.js +3 -3
  253. package/dist/testSurface/surface/test/jumpToSection.d.ts +1 -1
  254. package/dist/testSurface/surface/test/jumpToSection.js +4 -4
  255. package/dist/testSurface/surface/test/testPage.css +26 -0
  256. package/dist/testSurface/surface/testDocument.model.d.ts +12 -1
  257. package/dist/testSurface/surface/testDocument.model.js +2 -1
  258. package/dist/testSurface/surface/useTestDocument.js +11 -4
  259. package/dist/testSurface/targeting/targeting.model.d.ts +2 -1
  260. package/dist/testSurface/targeting/targeting.model.js +1 -1
  261. package/dist/testSurface/useApi.d.ts +12 -0
  262. package/dist/transitions/addMetric.js +5 -2
  263. package/dist/transitions/allocate.js +6 -1
  264. package/dist/transitions/assertNoOverlap.d.ts +9 -0
  265. package/dist/transitions/assertNoOverlap.js +24 -0
  266. package/dist/transitions/buildCohorts.d.ts +10 -0
  267. package/dist/transitions/buildCohorts.js +68 -0
  268. package/dist/transitions/cancelSchedule.d.ts +4 -0
  269. package/dist/transitions/cancelSchedule.js +42 -0
  270. package/dist/transitions/checkStart.d.ts +17 -3
  271. package/dist/transitions/checkStart.js +20 -7
  272. package/dist/transitions/decide.js +40 -13
  273. package/dist/transitions/kernel.d.ts +3 -1
  274. package/dist/transitions/kernel.js +5 -2
  275. package/dist/transitions/pause.d.ts +4 -0
  276. package/dist/transitions/pause.js +35 -0
  277. package/dist/transitions/phaseRecord.d.ts +19 -2
  278. package/dist/transitions/phaseRecord.js +50 -11
  279. package/dist/transitions/placementInteractions.d.ts +7 -2
  280. package/dist/transitions/placementInteractions.js +9 -7
  281. package/dist/transitions/placements.d.ts +4 -3
  282. package/dist/transitions/placements.js +28 -14
  283. package/dist/transitions/preflightData.d.ts +11 -3
  284. package/dist/transitions/preflightData.js +134 -81
  285. package/dist/transitions/reschedule.d.ts +4 -0
  286. package/dist/transitions/reschedule.js +58 -0
  287. package/dist/transitions/resume.d.ts +4 -0
  288. package/dist/transitions/resume.js +32 -0
  289. package/dist/transitions/scheduledRound.d.ts +18 -0
  290. package/dist/transitions/scheduledRound.js +42 -0
  291. package/dist/transitions/start.d.ts +4 -0
  292. package/dist/transitions/start.js +139 -56
  293. package/dist/transitions/startReads.d.ts +14 -0
  294. package/dist/transitions/startReads.js +27 -0
  295. package/dist/transitions/stop.d.ts +10 -0
  296. package/dist/transitions/stop.js +35 -22
  297. package/dist/types/admin.d.ts +1 -1
  298. package/dist/types/contracts.d.ts +7 -1
  299. package/dist/types/endpoints.d.ts +72 -3
  300. package/dist/types/manifest.d.ts +9 -0
  301. package/dist/types/runtime.d.ts +5 -0
  302. package/dist/types/snapshot.d.ts +10 -0
  303. package/dist/types/status.d.ts +1 -0
  304. package/dist/types/status.js +1 -0
  305. package/dist/types/surface.d.ts +1 -0
  306. package/dist/ui/Feedback.d.ts +9 -6
  307. package/dist/ui/Feedback.js +10 -9
  308. package/dist/ui/SelectControl.js +1 -1
  309. package/dist/ui/ui.css +2 -1
  310. package/package.json +2 -2
@@ -7,15 +7,21 @@ import { reclaimSlices } from '../db/slices.js';
7
7
  import { decideGuard } from '../results/decideGuard.js';
8
8
  import { lockPagePaths } from '../db/locks.js';
9
9
  import { routedPageTests } from '../db/pageOccupancy.js';
10
+ import { OCCUPYING_STATUSES, overlapsClaim } from '../db/occupancy.js';
11
+ import { assertNoOverlap } from './assertNoOverlap.js';
10
12
  import { pageTargetPaths, relationshipId } from './checkStart.js';
11
13
  import { expectedConfirm, matchesConfirm, storedWinnerLabel } from './confirmPhrases.js';
12
14
  import { withTransition } from './kernel.js';
13
15
  import { requireCurrentRound, readPhaseRecord, setPhaseEndedAt, writePhaseRecord } from './phaseRecord.js';
14
16
  import { readExperiment, refuse, updateExperiment } from './start.js';
17
+ import { requireStarted } from './scheduledRound.js';
15
18
  export async function decide(req, { experimentId, winnerArm, note, confirmation, phase: expectedPhase }) {
16
19
  const before = await readExperiment(req, experimentId);
17
20
  const options = req.payload.config.custom?.xp;
18
- const placements = before.status === 'stopped' && before.kind === 'block' ? await detached(req, ()=>scanPlacements(req, options, before.slug)) : [];
21
+ const placementScan = {
22
+ publishedOnly: 'localized'
23
+ };
24
+ const placements = before.status === 'stopped' && before.kind === 'block' ? await detached(req, ()=>scanPlacements(req, options, before.slug, placementScan)) : [];
19
25
  const { result: doc, revision } = await withTransition(req, {
20
26
  experimentId,
21
27
  layerId: relationshipId(before.layer),
@@ -23,8 +29,14 @@ export async function decide(req, { experimentId, winnerArm, note, confirmation,
23
29
  }, async ({ req, exec })=>{
24
30
  const current = await readExperiment(req, experimentId);
25
31
  requireCurrentRound(expectedPhase, current.phase);
26
- if (current.status !== 'running' && current.status !== 'stopped') refuse('invalid-status');
27
- if (current.kind === 'flag' && current.flagPoint) {
32
+ const open = current.status === 'running' || current.status === 'paused';
33
+ if (!open && current.status !== 'stopped') refuse('invalid-status');
34
+ requireStarted(current.startedAt, new Date());
35
+ const claim = {
36
+ from: new Date(),
37
+ to: null
38
+ };
39
+ if (current.kind === 'flag' && current.flagPoint && !(open && current.claimTo)) {
28
40
  // §7.8: recheck point occupancy under its lock before restoring live routing.
29
41
  const busy = await req.payload.find({
30
42
  collection: 'xp-experiments',
@@ -41,16 +53,13 @@ export async function decide(req, { experimentId, winnerArm, note, confirmation,
41
53
  },
42
54
  {
43
55
  status: {
44
- in: [
45
- 'running',
46
- 'decided'
47
- ]
56
+ in: OCCUPYING_STATUSES
48
57
  }
49
58
  }
50
59
  ]
51
60
  }
52
61
  });
53
- if (busy.docs.some((doc)=>String(doc.id) !== String(experimentId))) refuse('flag-point-busy');
62
+ if (busy.docs.some((doc)=>String(doc.id) !== String(experimentId) && overlapsClaim(doc, claim))) refuse('flag-point-busy');
54
63
  }
55
64
  const test = await readPhaseRecord(req, experimentId, current.phase);
56
65
  if (test.phaseKind !== 'test') refuse('invalid-status');
@@ -58,7 +67,7 @@ export async function decide(req, { experimentId, winnerArm, note, confirmation,
58
67
  const rescan = await lockAndRescanPlacements(req, exec, options, {
59
68
  ...current,
60
69
  arms: test.arms
61
- }, placements);
70
+ }, placements, placementScan);
62
71
  if (rescan.placements.length === 0) refuse('placement-removed');
63
72
  await refreshPlacementDocs(exec, experimentId, test.phase, rescan.docs);
64
73
  }
@@ -69,7 +78,7 @@ export async function decide(req, { experimentId, winnerArm, note, confirmation,
69
78
  const mine = pageTargetPaths(test.arms);
70
79
  await lockPagePaths(exec, mine);
71
80
  // Other tests' routed (frozen-round) arms, as the runtime matches them.
72
- const occupied = new Set((await routedPageTests(exec)).filter((other)=>String(other.id) !== String(experimentId)).flatMap((other)=>pageTargetPaths(other.arms)));
81
+ const occupied = new Set((await routedPageTests(exec)).filter((other)=>String(other.id) !== String(experimentId) && overlapsClaim(other, claim)).flatMap((other)=>pageTargetPaths(other.arms)));
73
82
  const shared = mine.filter((path)=>occupied.has(path));
74
83
  if (shared.length) refuse('page-in-use', {
75
84
  paths: shared
@@ -118,20 +127,36 @@ export async function decide(req, { experimentId, winnerArm, note, confirmation,
118
127
  const snapshotDoc = snapshots.docs[0];
119
128
  const snapshot = snapshotDoc?.snapshot;
120
129
  if (decideGuard(snapshot ?? null, winnerArm) && (!note?.trim() || !matchesConfirm(expectedConfirm('decide', storedWinnerLabel(winner)), confirmation))) refuse('confirmation-required');
121
- const at = new Date().toISOString();
122
130
  const holdout = test.arms.find((arm)=>arm.kind === 'holdout');
123
131
  const rollout = holdout !== undefined && winner.kind !== 'control';
124
132
  let slices = current.layerSlices ?? [];
133
+ if (open && current.claimTo) {
134
+ // Deciding removes the schedule end. A later reservation must still be usable.
135
+ if (current.kind === 'page') await lockPagePaths(exec, pageTargetPaths(test.arms));
136
+ await assertNoOverlap(exec, {
137
+ ...current,
138
+ arms: test.arms,
139
+ layerSlices: rollout ? slices : []
140
+ }, {
141
+ from: new Date(),
142
+ to: null
143
+ });
144
+ }
125
145
  if (rollout && current.status === 'stopped' && relationshipId(current.layer) !== undefined) {
126
146
  const original = test.analysis?.layerSlices;
127
147
  if (!Array.isArray(original) || original.length !== test.allocation || !original.every((slice)=>Number.isInteger(slice) && slice >= 0 && slice < 100) || new Set(original).size !== original.length) refuse('slices-taken');
128
148
  slices = await reclaimSlices(exec, {
129
149
  layerId: relationshipId(current.layer),
130
150
  experimentId,
131
- slices: original
151
+ slices: original,
152
+ claim
132
153
  });
133
154
  }
134
- await setPhaseEndedAt(req, experimentId, test.phase, at);
155
+ const at = new Date().toISOString();
156
+ const scheduledEnd = test.schedule?.endAt;
157
+ const endedAt = current.status === 'paused' ? current.pausedAt : scheduledEnd && new Date(scheduledEnd) < new Date(at) ? new Date(scheduledEnd).toISOString() : at;
158
+ if (!endedAt) refuse('invalid-phase');
159
+ await setPhaseEndedAt(req, experimentId, test.phase, endedAt);
135
160
  const phase = rollout ? test.phase + 1 : test.phase;
136
161
  if (rollout) {
137
162
  const arms = [
@@ -168,6 +193,8 @@ export async function decide(req, { experimentId, winnerArm, note, confirmation,
168
193
  phase,
169
194
  seed: test.seed,
170
195
  decidedAt: at,
196
+ claimFrom: at,
197
+ claimTo: null,
171
198
  layerSlices: rollout ? slices : [],
172
199
  decision: {
173
200
  winnerArm,
@@ -9,8 +9,10 @@ export interface TransitionScope {
9
9
  bump?: boolean;
10
10
  /** Best-effort content audit only; a borrowed transaction must never be killed here. */
11
11
  audit?: boolean;
12
- /** Trusted server-side Start must commit its own transaction. Preflight passes the request to host callbacks. */
12
+ /** Trusted system transitions must commit their own transactions. */
13
13
  requireOwnedTransaction?: boolean;
14
+ /** Limit statement time for a scheduled stop run by results. */
15
+ deadline?: number;
14
16
  /** Guard an ordinary access-checked edit without bypassing the collection's lock hook. */
15
17
  edit?: boolean;
16
18
  excludeIds?: DocId[];
@@ -1,6 +1,6 @@
1
1
  import { commitTransaction, killTransaction } from 'payload';
2
2
  import { assertReadCommitted, initTransitionTransaction } from '../db/adapter.js';
3
- import { pooledExecutor, txExecutor } from '../db/executor.js';
3
+ import { pooledExecutor, setTransitionTimeout, txExecutor } from '../db/executor.js';
4
4
  import { lockTransitionScope } from '../db/locks.js';
5
5
  import { currentTxid, txidStatus } from '../db/txid.js';
6
6
  import { contentChangeSavepoint } from '../db/appends.js';
@@ -25,10 +25,11 @@ import { buildAndStoreManifest } from '../manifest/compile.js';
25
25
  const previousTransition = req.context.xpTransition;
26
26
  let borrowedAudit = scope.audit === true && req.transactionID != null;
27
27
  try {
28
- const owns = await initTransitionTransaction(req);
28
+ const owns = await initTransitionTransaction(req, scope.deadline);
29
29
  borrowedAudit = scope.audit === true && !owns;
30
30
  const exec = txExecutor(req);
31
31
  const work = async ()=>{
32
+ if (scope.deadline !== undefined) await setTransitionTimeout(exec, scope.deadline);
32
33
  if (!owns) await assertReadCommitted(req);
33
34
  if (!scope.edit) req.context.xpTransition = true;
34
35
  await lockTransitionScope(exec, scope);
@@ -45,10 +46,12 @@ import { buildAndStoreManifest } from '../manifest/compile.js';
45
46
  }
46
47
  result = audit.result;
47
48
  } else result = await work();
49
+ if (scope.deadline !== undefined) await setTransitionTimeout(exec, scope.deadline);
48
50
  const revision = scope.bump === false ? undefined : (await buildAndStoreManifest(req, {
49
51
  excludeIds: scope.excludeIds
50
52
  })).revision;
51
53
  if (owns) {
54
+ if (scope.deadline !== undefined) await setTransitionTimeout(exec, scope.deadline);
52
55
  const xid = await currentTxid(exec);
53
56
  await commitTransaction(req);
54
57
  const status = await txidStatus(pooledExecutor(req.payload), xid);
@@ -0,0 +1,4 @@
1
+ import type { PayloadRequest } from 'payload';
2
+ import type { DocId } from '../types/contracts.js';
3
+ import type { PauseBody, TransitionSuccess } from '../types/endpoints.js';
4
+ export declare function pauseExperiment(req: PayloadRequest, id: DocId, { reason, phase: expectedPhase }: PauseBody): Promise<TransitionSuccess>;
@@ -0,0 +1,35 @@
1
+ import { readPhaseRecord, requireCurrentRound, updatePhaseRecord } from './phaseRecord.js';
2
+ import { requireStarted, withScheduledRound } from './scheduledRound.js';
3
+ import { refuse, updateExperiment } from './start.js';
4
+ export async function pauseExperiment(req, id, { reason, phase: expectedPhase }) {
5
+ if (reason !== undefined && (typeof reason !== 'string' || reason.length > 500)) refuse('invalid-body');
6
+ return withScheduledRound(req, id, async (req, _exec, current)=>{
7
+ requireCurrentRound(expectedPhase, current.phase);
8
+ const now = new Date();
9
+ if (current.status !== 'running' && current.status !== 'decided') refuse('not-live');
10
+ requireStarted(current.startedAt, now);
11
+ const phase = await readPhaseRecord(req, id, current.phase);
12
+ if (phase.phaseKind === 'rollout') refuse('not-pausable');
13
+ if (current.status !== 'running') refuse('not-live');
14
+ const from = now.toISOString();
15
+ const by = String(req.user.id);
16
+ await updatePhaseRecord(req, phase.id, {
17
+ pauses: [
18
+ ...phase.pauses,
19
+ {
20
+ from,
21
+ by,
22
+ ...reason !== undefined ? {
23
+ reason
24
+ } : {}
25
+ }
26
+ ]
27
+ });
28
+ return updateExperiment(req, id, {
29
+ status: 'paused',
30
+ pausedAt: from,
31
+ pausedBy: by,
32
+ pauseReason: reason ?? null
33
+ });
34
+ });
35
+ }
@@ -1,6 +1,8 @@
1
+ import type { FrozenCohortRule } from '../cohorts/rule.js';
1
2
  import type { PayloadRequest } from 'payload';
2
3
  import type { Arm, DocId, TargetingRule } from '../types/contracts.js';
3
4
  import type { AllocationChange, ContentChange } from '../db/appends.js';
5
+ import type { ExperimentSchedule, PauseInterval } from '../schedule/types.js';
4
6
  /** Check the round after acquiring the experiment lock and before writing. */
5
7
  export declare function requireCurrentRound(expected: number | undefined, current: number | undefined): void;
6
8
  export interface PhaseRecord {
@@ -13,23 +15,38 @@ export interface PhaseRecord {
13
15
  arms: Arm[];
14
16
  allocation: number;
15
17
  allocationChanges?: AllocationChange[];
16
- targeting: TargetingRule[];
18
+ targeting: Array<TargetingRule | FrozenCohortRule>;
17
19
  metricDefinitions?: Array<Record<string, unknown>>;
18
20
  analysis?: Record<string, unknown> & {
19
21
  sequentialTuningParameter?: number | null;
22
+ beforeSchedule?: {
23
+ arms?: Arm[];
24
+ timeZone?: string | null;
25
+ };
20
26
  };
21
27
  placementDocs?: import('../db/placements.js').PlacementDoc[] | null;
22
28
  contentChanges?: ContentChange[];
29
+ pauses: PauseInterval[];
30
+ schedule?: ExperimentSchedule;
31
+ scheduleChanges: Array<{
32
+ at: string;
33
+ from: string | null;
34
+ to: string | null;
35
+ by: string;
36
+ }>;
23
37
  }
24
38
  export declare function readPhaseRecord(req: PayloadRequest, experimentId: DocId, phase: number): Promise<PhaseRecord & {
25
39
  id: DocId;
26
40
  }>;
27
41
  /** Caller holds the experiment lock and passes the kernel's transaction req. */
28
- export declare function writePhaseRecord(req: PayloadRequest, record: PhaseRecord & {
42
+ export declare function writePhaseRecord(req: PayloadRequest, record: Omit<PhaseRecord, 'pauses' | 'scheduleChanges'> & Partial<Pick<PhaseRecord, 'pauses' | 'scheduleChanges'>> & {
29
43
  analysis: Record<string, unknown> & {
30
44
  sequentialTuningParameter: number;
31
45
  };
32
46
  }): Promise<import("payload").JsonObject & import("payload").TypeWithID>;
47
+ export declare function readLatestPhase(req: PayloadRequest, experimentId: DocId): Promise<Pick<PhaseRecord, "phase" | "seed" | "startedAt" | "endedAt"> | undefined>;
48
+ export declare function latestPhaseNumber(req: PayloadRequest, experimentId: DocId): Promise<number>;
49
+ export declare function updatePhaseRecord(req: PayloadRequest, id: DocId, data: Partial<Pick<PhaseRecord, 'pauses' | 'schedule' | 'scheduleChanges' | 'endedAt'>>): Promise<import("payload").JsonObject & import("payload").TypeWithID>;
33
50
  /** End only an open phase, preserving the original stop time on a later decide.
34
51
  * Caller holds the experiment lock and passes the kernel's transaction req.
35
52
  */
@@ -31,14 +31,60 @@ export async function readPhaseRecord(req, experimentId, phase) {
31
31
  experimentId,
32
32
  phase
33
33
  }, 404);
34
- return docs[0];
34
+ const record = docs[0];
35
+ return {
36
+ ...record,
37
+ pauses: record.pauses ?? [],
38
+ schedule: record.schedule ?? undefined,
39
+ scheduleChanges: record.scheduleChanges ?? []
40
+ };
35
41
  }
36
42
  /** Caller holds the experiment lock and passes the kernel's transaction req. */ export async function writePhaseRecord(req, record) {
37
43
  // §7.8: transition endpoints' writes to plugin collections.
38
44
  return req.payload.create({
39
45
  collection: 'xp-phases',
40
- data: record,
46
+ data: {
47
+ ...record,
48
+ pauses: record.pauses ?? [],
49
+ scheduleChanges: record.scheduleChanges ?? []
50
+ },
51
+ req,
52
+ overrideAccess: true
53
+ });
54
+ }
55
+ export async function readLatestPhase(req, experimentId) {
56
+ // §7.8: Start and Cancel schedule read phase history inside the authorized transition.
57
+ const { docs } = await req.payload.find({
58
+ collection: 'xp-phases',
59
+ req,
60
+ overrideAccess: true,
61
+ depth: 0,
62
+ limit: 1,
63
+ select: {
64
+ phase: true,
65
+ seed: true,
66
+ startedAt: true,
67
+ endedAt: true
68
+ },
69
+ where: {
70
+ experiment: {
71
+ equals: experimentId
72
+ }
73
+ },
74
+ sort: '-phase'
75
+ });
76
+ return docs[0];
77
+ }
78
+ export async function latestPhaseNumber(req, experimentId) {
79
+ return Number((await readLatestPhase(req, experimentId))?.phase ?? 0);
80
+ }
81
+ export async function updatePhaseRecord(req, id, data) {
82
+ // §7.8: the authorized transition writes the phase audit or close under the experiment lock.
83
+ return req.payload.update({
84
+ collection: 'xp-phases',
41
85
  req,
86
+ id,
87
+ data,
42
88
  overrideAccess: true
43
89
  });
44
90
  }
@@ -73,14 +119,7 @@ export async function readPhaseRecord(req, experimentId, phase) {
73
119
  phase
74
120
  }, 404);
75
121
  if (record.endedAt) return record;
76
- // §7.8: transition endpoints' writes to plugin collections.
77
- return req.payload.update({
78
- collection: 'xp-phases',
79
- req,
80
- id: record.id,
81
- data: {
82
- endedAt: at
83
- },
84
- overrideAccess: true
122
+ return updatePhaseRecord(req, record.id, {
123
+ endedAt: at
85
124
  });
86
125
  }
@@ -5,9 +5,13 @@ import { type PlacementDoc } from '../db/placements.js';
5
5
  import { type BlockPlacement } from './placements.js';
6
6
  export declare function detached<T>(req: PayloadRequest, fn: () => Promise<T>): Promise<T>;
7
7
  export declare function uniquePlacementDocs(placements: readonly Pick<BlockPlacement, 'collection' | 'id'>[]): PlacementDoc[];
8
+ type PlacementScanOptions = {
9
+ system?: boolean;
10
+ publishedOnly?: 'localized';
11
+ };
8
12
  export declare function scanPlacements<TUser extends {
9
13
  id: DocId;
10
- }>(req: PayloadRequest, options: ResolvedOptions<TUser>, slug: string, system?: boolean): Promise<BlockPlacement[]>;
14
+ }>(req: PayloadRequest, options: ResolvedOptions<TUser>, slug: string, scan?: PlacementScanOptions): Promise<BlockPlacement[]>;
11
15
  export declare function placementPaths<TUser extends {
12
16
  id: DocId;
13
17
  }>(req: PayloadRequest, options: ResolvedOptions<TUser>, docs: readonly PlacementDoc[]): Promise<string[]>;
@@ -34,7 +38,8 @@ export declare function lockAndRescanPlacements<TUser extends {
34
38
  slug: string;
35
39
  kind: string;
36
40
  arms: Arm[];
37
- }, before: readonly BlockPlacement[], system?: boolean): Promise<{
41
+ }, before: readonly BlockPlacement[], scan?: PlacementScanOptions): Promise<{
38
42
  placements: BlockPlacement[];
39
43
  docs: PlacementDoc[];
40
44
  }>;
45
+ export {};
@@ -30,12 +30,12 @@ export function uniquePlacementDocs(placements) {
30
30
  ])).values()
31
31
  ];
32
32
  }
33
- export function scanPlacements(req, options, slug, system = false) {
33
+ export function scanPlacements(req, options, slug, scan) {
34
34
  return scanBlockPlacements(req, {
35
35
  slug,
36
36
  puckCollections: options.puck?.collections ?? [],
37
37
  blocksCollections: options.blocks?.collections ?? [],
38
- system
38
+ ...scan
39
39
  });
40
40
  }
41
41
  export async function placementPaths(req, options, docs) {
@@ -53,7 +53,7 @@ export async function placementPaths(req, options, docs) {
53
53
  ...paths
54
54
  ]);
55
55
  }
56
- const active = (test)=>test.status === 'running' || test.status === 'decided';
56
+ const active = (test)=>test.status === 'running' || test.status === 'paused' || test.status === 'decided';
57
57
  export async function placementInteractions(req, exec, options, experiment, paths, system = false) {
58
58
  const result = [];
59
59
  for (const test of (await placementTests(exec))){
@@ -68,7 +68,9 @@ export async function placementInteractions(req, exec, options, experiment, path
68
68
  version: test.arms.some((a)=>a.kind === 'variant' && a.pageTarget && normalisePath(a.pageTarget) === path)
69
69
  });
70
70
  } else if (experiment.kind === 'page' && test.kind === 'block') {
71
- const docs = test.placementDocs ?? uniquePlacementDocs(await detached(req, ()=>scanPlacements(req, options, test.slug, system)));
71
+ const docs = test.placementDocs ?? uniquePlacementDocs(await detached(req, ()=>scanPlacements(req, options, test.slug, {
72
+ system
73
+ })));
72
74
  const relevant = docs.filter((doc)=>!experiment.pageCollection || doc.collection === experiment.pageCollection);
73
75
  for (const path of (await placementPaths(req, options, relevant)).filter((path)=>paths.includes(path)))result.push({
74
76
  experimentId: test.id,
@@ -82,14 +84,14 @@ export async function placementInteractions(req, exec, options, experiment, path
82
84
  }
83
85
  return result;
84
86
  }
85
- export async function lockAndRescanPlacements(req, exec, options, experiment, before, system = false) {
87
+ export async function lockAndRescanPlacements(req, exec, options, experiment, before, scan) {
86
88
  const paths = await placementPaths(req, options, uniquePlacementDocs(before));
87
89
  await lockPagePaths(exec, paths);
88
- const placements = await detached(req, ()=>scanPlacements(req, options, experiment.slug, system));
90
+ const placements = await detached(req, ()=>scanPlacements(req, options, experiment.slug, scan));
89
91
  const docs = uniquePlacementDocs(placements);
90
92
  const afterPaths = await placementPaths(req, options, docs);
91
93
  if (afterPaths.some((path)=>!paths.includes(path))) throw new XpRefusal('placements-changed', "This test's pages changed while it was starting. Try again.", undefined, 409);
92
- const conflicts = await placementInteractions(req, exec, options, experiment, paths, system);
94
+ const conflicts = await placementInteractions(req, exec, options, experiment, paths, scan?.system);
93
95
  if (conflicts.length) throw new XpRefusal('interacting-tests', interactingTestsCopy(conflicts[0].path, conflicts[0].status, conflicts[0].name, conflicts[0].version), conflicts, 409);
94
96
  return {
95
97
  placements,
@@ -2,6 +2,7 @@ import type { PayloadRequest } from 'payload';
2
2
  import type { Arm, DocId, FlagPoint, PreviewPlacement, ResolvedOptions } from '../types/contracts.js';
3
3
  import type { ArmSlot } from '../types/puck.js';
4
4
  import { type PlacementLocaleView } from '../blocks/placementLocale.js';
5
+ import type { BulkPlacementRemoval } from '../db/bulkPlacementRemoval.js';
5
6
  export interface BlockPlacement extends PreviewPlacement {
6
7
  nestedTests?: Array<{
7
8
  outer: string;
@@ -35,8 +36,8 @@ interface ScanOptions {
35
36
  puckCollections: NonNullable<ResolvedOptions['puck']>['collections'];
36
37
  blocksCollections: NonNullable<ResolvedOptions['blocks']>['collections'];
37
38
  compareVersions?: boolean;
38
- /** Read the current visitor surface without fetching newer unpublished drafts. */
39
- publishedOnly?: boolean;
39
+ /** Read the visitor surface, optionally keeping legacy draft discovery for scalar collections. */
40
+ publishedOnly?: boolean | 'localized';
40
41
  /** Hooks and manager-authorized visitor-impact reads must see every placement (CORE-21). */
41
42
  pageGuard?: true;
42
43
  /** Trusted server-side Start checks placements without a manager actor. */
@@ -48,7 +49,7 @@ interface ScanOptions {
48
49
  */
49
50
  export declare function hasOtherPublishedBlockPlacement(req: PayloadRequest, options: ResolvedOptions, slug: string, excluded: (collection: string, id: DocId, view: PlacementLocaleView, doc: Record<string, unknown> & {
50
51
  id: DocId;
51
- }) => boolean): Promise<boolean>;
52
+ }) => boolean, bulk?: BulkPlacementRemoval): Promise<boolean>;
52
53
  interface PublishedBlockPlacement {
53
54
  id: DocId;
54
55
  editor: 'puck' | 'blocks';
@@ -10,6 +10,8 @@ import { isDeepStrictEqual } from 'node:util';
10
10
  import { hasLocalizedFields } from './contentFields.js';
11
11
  import { localeRequest, placementReader } from '../blocks/placementLocale.js';
12
12
  import { puckCollections as normalisePuckCollections } from '../options.js';
13
+ import { publishedInLocale, usesLocalizedPublication } from '../blocks/placementPublication.js';
14
+ import { storedPlacementStatuses } from '../db/placements.js';
13
15
  const slots = [
14
16
  'control',
15
17
  'variantA',
@@ -18,6 +20,8 @@ const slots = [
18
20
  ];
19
21
  async function placementDocuments(req, query, readAll) {
20
22
  // §7.8: page guards, visitor impact and system Start need all placements to check the visitor surface.
23
+ // For draft:false, the adapter hydrates _status from the main locale rows
24
+ // alongside the localized fields. Draft versions are read separately.
21
25
  if (readAll) return req.payload.find({
22
26
  ...query,
23
27
  req,
@@ -46,7 +50,7 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
46
50
  }
47
51
  /** Published rows only, one pass per collection across both editor registrations.
48
52
  * The exclusion predicate reads live transaction claims after each awaited page.
49
- */ export async function hasOtherPublishedBlockPlacement(req, options, slug, excluded) {
53
+ */ export async function hasOtherPublishedBlockPlacement(req, options, slug, excluded, bulk) {
50
54
  const scanReq = localeRequest(req, {
51
55
  locale: req.payload.config.localization ? 'all' : req.locale ?? '',
52
56
  fallbackLocale: false
@@ -56,6 +60,7 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
56
60
  ...(options.blocks?.collections ?? []).map((entry)=>entry.slug)
57
61
  ]);
58
62
  for (const collection of collections){
63
+ const localized = usesLocalizedPublication(req, collection);
59
64
  const drafts = req.payload.config.collections?.some((c)=>c.slug === collection && c.versions && c.versions.drafts);
60
65
  const reader = placementReader(req, collection, options);
61
66
  let page = 1;
@@ -71,7 +76,7 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
71
76
  locale: 'all',
72
77
  fallbackLocale: false
73
78
  } : {},
74
- ...drafts ? {
79
+ ...drafts && !localized ? {
75
80
  where: {
76
81
  _status: {
77
82
  equals: 'published'
@@ -79,7 +84,10 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
79
84
  }
80
85
  } : {}
81
86
  }, 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;
87
+ const statuses = localized && bulk?.change?.collection === collection ? await storedPlacementStatuses(req, collection, result.docs.map((doc)=>doc.id)) : undefined;
88
+ if (result.docs.some((doc)=>doc._status !== 'draft' && doc.deletedAt == null && reader.views.some((view)=>reader.isPublished(doc, view) && (!statuses || publishedInLocale({
89
+ _status: statuses.get(String(doc.id))
90
+ }, view.locale)) && reader.read(doc, 'all-locales', view).slugs.includes(slug) && !excluded(collection, doc.id, view, doc)))) return true;
83
91
  if (!result.hasNextPage) break;
84
92
  page++;
85
93
  }
@@ -98,6 +106,7 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
98
106
  ...puck,
99
107
  ...blocks
100
108
  ].map((entry)=>entry.slug))){
109
+ const localized = usesLocalizedPublication(req, collection);
101
110
  const drafts = req.payload.config.collections?.some((c)=>c.slug === collection && c.versions && c.versions.drafts);
102
111
  const reader = placementReader(req, collection, options);
103
112
  let page = 1;
@@ -114,7 +123,7 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
114
123
  locale: 'all',
115
124
  fallbackLocale: false
116
125
  } : {},
117
- ...drafts ? {
126
+ ...drafts && !localized ? {
118
127
  where: {
119
128
  _status: {
120
129
  equals: 'published'
@@ -127,6 +136,7 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
127
136
  for (const raw of result.docs){
128
137
  if (raw._status === 'draft' || raw.deletedAt != null) continue;
129
138
  for (const view of reader.views){
139
+ if (!reader.isPublished(raw, view)) continue;
130
140
  const placement = reader.read(raw, 'all-locales', view);
131
141
  const doc = placement.doc;
132
142
  const add = (contents, editor)=>placements.push({
@@ -204,6 +214,7 @@ export async function scanBlockPlacements(req, args) {
204
214
  collections: puckCollections
205
215
  }
206
216
  })){
217
+ const localizedStatus = usesLocalizedPublication(req, collection);
207
218
  const reader = placementReader(req, collection, {
208
219
  puck: {
209
220
  enabled: true,
@@ -217,7 +228,8 @@ export async function scanBlockPlacements(req, args) {
217
228
  const publishedIds = new Set();
218
229
  const publishedSlugs = new Map();
219
230
  const draftsEnabled = req.payload.config.collections?.some((config)=>config.slug === collection && config.versions && config.versions.drafts);
220
- for (const draft of args.publishedOnly ? [
231
+ const publishedOnly = args.publishedOnly === true || args.publishedOnly === 'localized' && localizedStatus;
232
+ for (const draft of publishedOnly ? [
221
233
  false
222
234
  ] : [
223
235
  false,
@@ -238,7 +250,7 @@ export async function scanBlockPlacements(req, args) {
238
250
  locale: 'all',
239
251
  fallbackLocale: false
240
252
  } : {},
241
- ...!draft && draftsEnabled ? {
253
+ ...!draft && draftsEnabled && !localizedStatus ? {
242
254
  where: {
243
255
  _status: {
244
256
  equals: 'published'
@@ -252,8 +264,8 @@ export async function scanBlockPlacements(req, args) {
252
264
  String(doc.id),
253
265
  view.locale
254
266
  ]);
255
- if (!draft && doc._status === 'draft') continue;
256
- if (draft && doc._status !== 'draft' && publishedIds.has(documentKey)) continue;
267
+ if (!draft && (doc._status === 'draft' || !reader.isPublished(localized, view))) continue;
268
+ if (draft && (localizedStatus ? reader.isPublished(localized, view) : doc._status !== 'draft') && publishedIds.has(documentKey)) continue;
257
269
  if (!draft) {
258
270
  editors.set(documentKey, reader.read(doc, 'localized').editor);
259
271
  publishedIds.add(documentKey);
@@ -299,7 +311,7 @@ export async function scanBlockPlacements(req, args) {
299
311
  locale: view.locale
300
312
  } : {},
301
313
  title: String(doc.title ?? doc.name ?? doc.id),
302
- published: !draft || doc._status === 'published',
314
+ published: !draft || !localizedStatus && doc._status === 'published',
303
315
  ...publishedSlugs.has(documentKey) ? {
304
316
  slug: publishedSlugs.get(documentKey)
305
317
  } : {},
@@ -343,6 +355,7 @@ export async function scanBlockPlacements(req, args) {
343
355
  }
344
356
  for (const registration of args.blocksCollections){
345
357
  const { slug: collection, field } = registration;
358
+ const localizedStatus = usesLocalizedPublication(req, collection);
346
359
  const reader = placementReader(req, collection, {
347
360
  puck: {
348
361
  enabled: true,
@@ -354,7 +367,8 @@ export async function scanBlockPlacements(req, args) {
354
367
  });
355
368
  const published = new Map();
356
369
  const draftsEnabled = req.payload.config.collections?.some((c)=>c.slug === collection && c.versions && c.versions.drafts);
357
- for (const draft of args.publishedOnly ? [
370
+ const publishedOnly = args.publishedOnly === true || args.publishedOnly === 'localized' && localizedStatus;
371
+ for (const draft of publishedOnly ? [
358
372
  false
359
373
  ] : [
360
374
  false,
@@ -375,7 +389,7 @@ export async function scanBlockPlacements(req, args) {
375
389
  locale: 'all',
376
390
  fallbackLocale: false
377
391
  } : {},
378
- ...!draft && draftsEnabled ? {
392
+ ...!draft && draftsEnabled && !localizedStatus ? {
379
393
  where: {
380
394
  _status: {
381
395
  equals: 'published'
@@ -389,9 +403,9 @@ export async function scanBlockPlacements(req, args) {
389
403
  String(doc.id),
390
404
  view.locale
391
405
  ]);
392
- if (!draft && doc._status === 'draft') continue;
406
+ if (!draft && (doc._status === 'draft' || !reader.isPublished(localized, view))) continue;
393
407
  if (!draft) published.set(documentKey, doc);
394
- else if (doc._status !== 'draft' && published.has(documentKey)) continue;
408
+ else if ((localizedStatus ? reader.isPublished(localized, view) : doc._status !== 'draft') && published.has(documentKey)) continue;
395
409
  const baseline = published.get(documentKey) ?? doc;
396
410
  if (reader.read(baseline, 'localized').editor !== 'blocks') continue;
397
411
  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;
@@ -409,7 +423,7 @@ export async function scanBlockPlacements(req, args) {
409
423
  locale: view.locale
410
424
  } : {},
411
425
  title: String(doc.title ?? doc.name ?? doc.id),
412
- published: !draft || doc._status === 'published',
426
+ published: !draft || !localizedStatus && doc._status === 'published',
413
427
  ...typeof baseline.slug === 'string' ? {
414
428
  slug: baseline.slug
415
429
  } : {},