@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,12 +1,18 @@
1
- /** Match Payload's relationship ID type before passing an HTTP ID to Local API or SQL. */ export function experimentId(req, value) {
1
+ /** Use the stored spelling for PostgreSQL IDs before any lock or comparison. */ export function experimentId(req, value, source = 'route') {
2
2
  if (typeof value !== 'string' && typeof value !== 'number') return undefined;
3
3
  const id = String(value);
4
- const idType = req.payload.collections?.['xp-experiments']?.customIDType ?? req.payload.db.defaultIDType;
5
- if (idType !== 'number') return id;
6
- if (!/^\d+$/.test(id)) return undefined;
4
+ const customIDType = req.payload.collections?.['xp-experiments']?.customIDType;
5
+ const idType = customIDType ?? req.payload.db.defaultIDType;
6
+ if (idType !== 'number') {
7
+ // The Postgres adapter reports a native UUID as text. Custom text IDs are opaque.
8
+ const uuid = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
9
+ return customIDType !== 'text' && uuid.test(id) ? id.toLowerCase() : id;
10
+ }
11
+ // Native Payload deletes already use Number() for their ID lookup.
12
+ if (source === 'route' && !/^\d+$/.test(id)) return undefined;
7
13
  const number = Number(id);
8
14
  // Payload's Postgres serial ids are int4; larger values would reach SQL and fail with 22003.
9
- return Number.isSafeInteger(number) && number <= 2_147_483_647 ? number : undefined;
15
+ return Number.isInteger(number) && number >= -2_147_483_648 && number <= 2_147_483_647 ? number : undefined;
10
16
  }
11
17
  export function routeId(req) {
12
18
  return experimentId(req, req.routeParams?.id);
@@ -1,8 +1,28 @@
1
+ import { BLOCK_SLOTS } from '../blocks/model.js';
1
2
  import { checkStart } from '../transitions/checkStart.js';
2
3
  import { loadStartInputsBatch } from '../transitions/preflightData.js';
3
4
  import { readSnapshots, resultsError } from './results.js';
4
5
  import { experimentId } from './routeId.js';
5
6
  import { sanitizeReadinessDetail } from './sanitizeReadinessDetail.js';
7
+ /** Use the batch scan's saved drafts. As in preflight, every matching block on
8
+ * a page in the affected language needs content before suggesting publication. */ function draftReadySlots(placements) {
9
+ const location = (row)=>JSON.stringify([
10
+ row.collection,
11
+ String(row.id),
12
+ row.locale
13
+ ]);
14
+ const filledInDraft = new Map();
15
+ for (const row of placements){
16
+ if (row.published) continue;
17
+ const id = location(row);
18
+ const filled = filledInDraft.get(id) ?? BLOCK_SLOTS;
19
+ filledInDraft.set(id, filled.filter((slot)=>row.slots[slot] > 0));
20
+ }
21
+ return BLOCK_SLOTS.filter((slot)=>{
22
+ const affected = placements.filter((row)=>row.published && !(row.slots[slot] > 0));
23
+ return affected.length > 0 && affected.every((row)=>filledInDraft.get(location(row))?.includes(slot));
24
+ });
25
+ }
6
26
  export async function handleSummary(req, { options }) {
7
27
  let ids;
8
28
  try {
@@ -43,17 +63,30 @@ export async function handleSummary(req, { options }) {
43
63
  headline: snapshot.verdict.headline
44
64
  },
45
65
  ...snapshot.health ? {
46
- health: snapshot.health.slice(0, 100).map((item)=>item.code === 'placement-unchecked' ? {
47
- code: item.code,
48
- detail: sanitizeReadinessDetail('placement-unchecked', item.detail)
49
- } : item.code === 'goal-in-some-versions' ? {
50
- code: item.code,
51
- metricId: item.metricId,
52
- name: item.name.slice(0, 128)
53
- } : {
54
- code: item.code,
55
- path: item.path.slice(0, 128)
56
- })
66
+ health: snapshot.health.slice(0, 100).map((item)=>{
67
+ switch(item.code){
68
+ case 'placement-unchecked':
69
+ return {
70
+ code: item.code,
71
+ detail: sanitizeReadinessDetail(item.code, item.detail)
72
+ };
73
+ case 'goal-in-some-versions':
74
+ return {
75
+ code: item.code,
76
+ metricId: item.metricId,
77
+ name: item.name.slice(0, 128)
78
+ };
79
+ case 'rapid-browser-events':
80
+ return {
81
+ code: item.code
82
+ };
83
+ default:
84
+ return {
85
+ code: item.code,
86
+ path: item.path.slice(0, 128)
87
+ };
88
+ }
89
+ })
57
90
  } : {}
58
91
  } : {
59
92
  exposures: 0,
@@ -90,7 +123,8 @@ export async function handleSummary(req, { options }) {
90
123
  response[key].ready = !!input && checks.every((check)=>check.ok);
91
124
  const next = checks.find((check)=>!check.ok && !check.warning);
92
125
  if (next) {
93
- const detail = sanitizeReadinessDetail(next.code, next.detail);
126
+ const draftReady = next.code === 'empty-slot' && input?.placements ? draftReadySlots(input.placements) : undefined;
127
+ const detail = sanitizeReadinessDetail(next.code, next.detail, draftReady);
94
128
  response[key].next = {
95
129
  code: next.code,
96
130
  ...detail === undefined ? {} : {
@@ -33,6 +33,7 @@ async function body(req) {
33
33
  }
34
34
  }
35
35
  const only = (value, keys)=>Object.keys(value).every((key)=>keys.includes(key));
36
+ const validPhase = (phase)=>phase === undefined || typeof phase === 'number' && Number.isSafeInteger(phase) && phase >= 0;
36
37
  async function respond(req, action) {
37
38
  const id = routeId(req);
38
39
  if (id === undefined) return Response.json({
@@ -63,15 +64,18 @@ async function respond(req, action) {
63
64
  }
64
65
  ]
65
66
  }, {
66
- status: cause.status === 409 ? 422 : cause.status
67
+ status: cause.status === 409 && cause.code !== 'round-changed' ? 422 : cause.status
67
68
  });
68
69
  throw cause;
69
70
  }
70
71
  }
71
72
  export async function handleStart(req, ctx) {
72
73
  const value = await body(req);
73
- if (!value || !only(value, [])) return invalidBody();
74
+ if (!value || !only(value, [
75
+ 'phase'
76
+ ]) || !validPhase(value.phase)) return invalidBody();
74
77
  return respond(req, (id)=>start(req, {
78
+ ...value,
75
79
  experimentId: id,
76
80
  options: ctx.options
77
81
  }));
@@ -79,12 +83,12 @@ export async function handleStart(req, ctx) {
79
83
  export async function handleAllocate(req, _ctx) {
80
84
  const value = await body(req);
81
85
  if (!value || !only(value, [
82
- 'allocation'
83
- ]) || typeof value.allocation !== 'number' || !Number.isInteger(value.allocation) || value.allocation < 1 || value.allocation > 100) return invalidBody();
84
- const allocation = value.allocation;
86
+ 'allocation',
87
+ 'phase'
88
+ ]) || !validPhase(value.phase) || typeof value.allocation !== 'number' || !Number.isInteger(value.allocation) || value.allocation < 1 || value.allocation > 100) return invalidBody();
85
89
  return respond(req, (id)=>allocate(req, {
86
- experimentId: id,
87
- allocation
90
+ ...value,
91
+ experimentId: id
88
92
  }));
89
93
  }
90
94
  export async function handleAddMetric(req, ctx) {
@@ -103,8 +107,11 @@ export async function handleAddMetric(req, ctx) {
103
107
  }
104
108
  export async function handleStop(req, _ctx) {
105
109
  const value = await body(req);
106
- if (!value || !only(value, [])) return invalidBody();
110
+ if (!value || !only(value, [
111
+ 'phase'
112
+ ]) || !validPhase(value.phase)) return invalidBody();
107
113
  return respond(req, (id)=>stop(req, {
114
+ ...value,
108
115
  experimentId: id
109
116
  }));
110
117
  }
@@ -113,35 +120,42 @@ export async function handleDecide(req, _ctx) {
113
120
  if (!value || !only(value, [
114
121
  'winnerArm',
115
122
  'note',
116
- 'confirmation'
117
- ]) || typeof value.winnerArm !== 'string' || value.note !== undefined && typeof value.note !== 'string' || value.confirmation !== undefined && typeof value.confirmation !== 'string') return invalidBody();
118
- const { winnerArm, note, confirmation } = value;
123
+ 'confirmation',
124
+ 'phase'
125
+ ]) || !validPhase(value.phase) || typeof value.winnerArm !== 'string' || value.note !== undefined && typeof value.note !== 'string' || value.confirmation !== undefined && typeof value.confirmation !== 'string') return invalidBody();
119
126
  return respond(req, (id)=>decide(req, {
120
- experimentId: id,
121
- winnerArm,
122
- note,
123
- confirmation
127
+ ...value,
128
+ experimentId: id
124
129
  }));
125
130
  }
126
131
  export async function handleReleaseHoldout(req, _ctx) {
127
132
  const value = await body(req);
128
- if (!value || !only(value, [])) return invalidBody();
133
+ if (!value || !only(value, [
134
+ 'phase'
135
+ ]) || !validPhase(value.phase)) return invalidBody();
129
136
  return respond(req, (id)=>releaseHoldout(req, {
137
+ ...value,
130
138
  experimentId: id
131
139
  }));
132
140
  }
133
141
  export async function handleMakeContent(req, ctx) {
134
142
  const value = await body(req);
135
- if (!value || !only(value, [])) return invalidBody();
143
+ if (!value || !only(value, [
144
+ 'phase'
145
+ ]) || !validPhase(value.phase)) return invalidBody();
136
146
  return respond(req, (id)=>makeContent(req, {
147
+ ...value,
137
148
  experimentId: id,
138
149
  options: ctx.options
139
150
  }));
140
151
  }
141
152
  export async function handleReleasePages(req, _ctx) {
142
153
  const value = await body(req);
143
- if (!value || !only(value, [])) return invalidBody();
154
+ if (!value || !only(value, [
155
+ 'phase'
156
+ ]) || !validPhase(value.phase)) return invalidBody();
144
157
  return respond(req, (id)=>releasePages(req, {
158
+ ...value,
145
159
  experimentId: id
146
160
  }));
147
161
  }
@@ -175,17 +189,16 @@ export async function handleArchive(req, _ctx) {
175
189
  const value = await body(req);
176
190
  if (!value || !only(value, [
177
191
  'mode',
178
- 'confirmation'
179
- ]) || ![
192
+ 'confirmation',
193
+ 'phase'
194
+ ]) || !validPhase(value.phase) || ![
180
195
  'stopped',
181
196
  'after-content',
182
197
  'discard',
183
198
  'hard-coded'
184
199
  ].includes(value.mode) || value.confirmation !== undefined && typeof value.confirmation !== 'string') return invalidBody();
185
- const { mode, confirmation } = value;
186
200
  return respond(req, (id)=>archive(req, {
187
- experimentId: id,
188
- mode,
189
- confirmation
201
+ ...value,
202
+ experimentId: id
190
203
  }));
191
204
  }
package/dist/errors.d.ts CHANGED
@@ -17,6 +17,10 @@ export declare class XpNoTransactionError extends Error {
17
17
  name: string;
18
18
  constructor(message?: string);
19
19
  }
20
+ export declare class XpStartTransactionOpen extends Error {
21
+ name: string;
22
+ constructor();
23
+ }
20
24
  export declare class XpRefusal extends Error {
21
25
  readonly code: RefusalCode;
22
26
  readonly detail: unknown | undefined;
package/dist/errors.js CHANGED
@@ -21,6 +21,12 @@ export class XpNoTransactionError extends Error {
21
21
  super(message);
22
22
  }
23
23
  }
24
+ export class XpStartTransactionOpen extends Error {
25
+ name = 'XpStartTransactionOpen';
26
+ constructor(){
27
+ super('Call startExperiment after your transaction commits.');
28
+ }
29
+ }
24
30
  export class XpRefusal extends Error {
25
31
  code;
26
32
  detail;
@@ -1,3 +1,7 @@
1
1
  import { NextRequest } from 'next/server.js';
2
- /** Browser beacons carry their page URL in Referer. It supplies targeting context only. */
3
- export declare function sourceRequest(request: NextRequest): NextRequest | null;
2
+ export declare function publicEventOrigin(value: string | undefined): string | undefined;
3
+ /** Fetch Metadata wins. For older clients, use only the deployment's configured origin. */
4
+ export declare function eventRequestContext(request: NextRequest, publicOrigin: string | undefined): {
5
+ allowed: boolean;
6
+ source: NextRequest | null;
7
+ };
@@ -1,14 +1,41 @@
1
1
  import { NextRequest } from 'next/server.js';
2
- /** Browser beacons carry their page URL in Referer. It supplies targeting context only. */ export function sourceRequest(request) {
3
- const referrer = request.headers.get('referer');
4
- if (!referrer) return null;
2
+ function webUrl(value) {
3
+ if (!value) return null;
5
4
  try {
6
- const url = new URL(referrer);
7
- if (url.origin !== request.nextUrl.origin) return null;
8
- return new NextRequest(url, {
9
- headers: request.headers
10
- });
5
+ const url = new URL(value);
6
+ return (url.protocol === 'http:' || url.protocol === 'https:') && !url.username && !url.password ? url : null;
11
7
  } catch {
12
8
  return null;
13
9
  }
14
10
  }
11
+ export function publicEventOrigin(value) {
12
+ if (typeof value === 'string' && /^https?:\/\/[^/?#\\\s]+\/?$/i.test(value)) return webUrl(value)?.origin;
13
+ }
14
+ function browserRequestOrigin(request) {
15
+ // Next can construct the URL from its listener address behind a reverse proxy.
16
+ // Use the forwarded authority only to recover page context after Fetch Metadata passed.
17
+ const host = request.headers.get('x-forwarded-host') ?? request.headers.get('host');
18
+ const protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol.slice(0, -1);
19
+ if (host && /^[^\s,/?#@\\]+$/.test(host) && (protocol === 'http' || protocol === 'https')) {
20
+ const origin = publicEventOrigin(`${protocol}://${host}`);
21
+ if (origin) return origin;
22
+ }
23
+ return request.nextUrl.origin;
24
+ }
25
+ /** Fetch Metadata wins. For older clients, use only the deployment's configured origin. */ export function eventRequestContext(request, publicOrigin) {
26
+ const site = request.headers.get('sec-fetch-site');
27
+ const origin = request.headers.get('origin');
28
+ const referrer = request.headers.get('referer');
29
+ const page = webUrl(referrer);
30
+ // Same-site can include siblings. None describes direct navigation, not a page beacon.
31
+ const allowed = site !== null ? site === 'same-origin' : origin !== null ? origin === publicOrigin : referrer === null || page !== null && page.origin === publicOrigin;
32
+ const pageOrigin = site === 'same-origin' ? browserRequestOrigin(request) : publicOrigin;
33
+ const senderOrigin = publicEventOrigin(origin ?? undefined);
34
+ const source = allowed && page && page.origin === pageOrigin && (!senderOrigin || senderOrigin === pageOrigin) ? new NextRequest(page, {
35
+ headers: request.headers
36
+ }) : null;
37
+ return {
38
+ allowed,
39
+ source
40
+ };
41
+ }
@@ -4,4 +4,4 @@ import type { ResolvedOptions } from '../types/contracts.js';
4
4
  import type { Manifest } from '../types/manifest.js';
5
5
  export declare function eventRows<TUser extends {
6
6
  id: string | number;
7
- }>(events: unknown[], manifest: Manifest, assignments: AssignmentResult, options: ResolvedOptions<TUser>, visitorId: string, userId: string | undefined, ts: string, requestAttributes?: Readonly<Record<string, unknown>>, clickKeys?: ReadonlySet<string>): EventRow[];
7
+ }>(events: unknown[], manifest: Manifest, assignments: AssignmentResult, options: ResolvedOptions<TUser>, visitorId: string | undefined, userId: string | undefined, ts: string, unitAgeMs: number | 'legacy' | null, requestAttributes?: Readonly<Record<string, unknown>>, clickKeys?: ReadonlySet<string>): EventRow[];
@@ -1,5 +1,7 @@
1
- import { validClickSource, isClickSource } from '../goals/key.js';
1
+ import { isClickSource } from '../goals/key.js';
2
2
  import { exposureDimensions } from './dimensions.js';
3
+ import { browserWritableEvent } from './writable.js';
4
+ import { USER_BROWSER_CONVERSION_PREFIX } from '../constants.js';
3
5
  function record(value) {
4
6
  return value !== null && typeof value === 'object' && !Array.isArray(value);
5
7
  }
@@ -10,8 +12,13 @@ function record(value) {
10
12
  return definition && typeof item === definition.type && (typeof item !== 'number' || Number.isFinite(item)) && (!definition.values || typeof item === 'string' && definition.values.includes(item));
11
13
  }));
12
14
  }
13
- export function eventRows(events, manifest, assignments, options, visitorId, userId, ts, requestAttributes = {}, clickKeys) {
15
+ export function eventRows(events, manifest, assignments, options, visitorId, userId, ts, unitAgeMs, requestAttributes = {}, clickKeys) {
14
16
  const rows = new Map();
17
+ const telemetry = {
18
+ _xp: {
19
+ unitAgeMs
20
+ }
21
+ };
15
22
  for (const event of events){
16
23
  if (!record(event)) continue;
17
24
  let row;
@@ -37,26 +44,35 @@ export function eventRows(events, manifest, assignments, options, visitorId, use
37
44
  userId,
38
45
  ts,
39
46
  dimensions: mismatch ? null : exposureDimensions(requestAttributes, options.events?.dimensions),
47
+ attributes: telemetry,
40
48
  // §5.5 / §11: diagnostics are separate rows, never exposure denominators or multi-arm counts.
41
49
  dedupeKey: mismatch ? `mismatch:${experiment.id}:${experiment.phase}:${unitId}:${ts.slice(0, 10)}` : `exposure:${experiment.id}:${experiment.phase}:${event.arm}:${unitId}:${ts.slice(0, 10)}`
42
50
  };
43
51
  } else if (event.type === 'conversion') {
44
52
  if (typeof event.eventName !== 'string' || typeof event.idempotencyKey !== 'string' || !event.idempotencyKey.trim() || event.value !== undefined && (typeof event.value !== 'number' || !Number.isFinite(event.value))) continue;
45
- const source = options.metricSources?.find((source)=>source.id === event.eventName);
46
53
  const click = isClickSource(event.eventName);
47
- if (click ? !validClickSource(event.eventName) || !clickKeys?.has(event.eventName.slice(6)) : source ? source.clientWritable !== true || source.kind === 'revenue' : !options.eventSources?.some((source)=>source.name === event.eventName && source.clientWritable)) continue;
54
+ if (!browserWritableEvent(event.eventName, options) || click && !clickKeys?.has(event.eventName.slice(6))) continue;
55
+ const unitId = visitorId ?? userId;
56
+ if (!unitId) continue;
48
57
  row = {
49
58
  type: 'conversion',
50
59
  eventName: event.eventName,
51
60
  value: 1,
52
- unitId: visitorId,
53
- unitType: 'visitor',
61
+ unitId,
62
+ unitType: visitorId ? 'visitor' : 'user',
54
63
  userId,
55
64
  ts,
56
65
  dimensions: null,
57
- attributes: click ? undefined : attributes(event.attributes, options.attributeKeys),
66
+ attributes: {
67
+ ...click ? undefined : attributes(event.attributes, options.attributeKeys),
68
+ ...telemetry
69
+ },
58
70
  // §5.5: scoped by unit and event so one client can never pre-claim another's key.
59
- dedupeKey: `conversion:c:${visitorId}:${event.eventName}:${event.idempotencyKey}`
71
+ dedupeKey: visitorId ? `conversion:c:${visitorId}:${event.eventName}:${event.idempotencyKey}` : USER_BROWSER_CONVERSION_PREFIX + JSON.stringify([
72
+ unitId,
73
+ event.eventName,
74
+ event.idempotencyKey
75
+ ])
60
76
  };
61
77
  } else continue;
62
78
  rows.set(row.dedupeKey, row);
@@ -0,0 +1,9 @@
1
+ import type { MetricSource, ResolvedOptions } from '../types/contracts.js';
2
+ type Sources = Pick<ResolvedOptions, 'eventSources'> & {
3
+ metricSources?: ReadonlyArray<Pick<MetricSource, 'id' | 'kind' | 'clientWritable'>>;
4
+ };
5
+ /** Checks source configuration. Ingestion separately checks that the click key exists. */
6
+ export declare function browserWritableEvent(eventName: string, options: Sources): boolean;
7
+ /** Built-in event metrics use the event name after the `events:` prefix. */
8
+ export declare function browserWritableMetric(source: string | undefined, options: Sources): boolean;
9
+ export {};
@@ -0,0 +1,13 @@
1
+ import { validClickSource } from '../goals/key.js';
2
+ /** Checks source configuration. Ingestion separately checks that the click key exists. */ export function browserWritableEvent(eventName, options) {
3
+ if (eventName.startsWith('click:')) return validClickSource(eventName);
4
+ const metric = options.metricSources?.find((source)=>source.id === eventName);
5
+ if (metric) return metric.clientWritable === true && metric.kind !== 'revenue';
6
+ return options.eventSources?.some((source)=>source.name === eventName && source.clientWritable) ?? false;
7
+ }
8
+ /** Built-in event metrics use the event name after the `events:` prefix. */ export function browserWritableMetric(source, options) {
9
+ if (!source) return false;
10
+ if (!source.startsWith('events:')) return browserWritableEvent(source, options);
11
+ const eventName = source.slice(7);
12
+ return options.eventSources?.some((event)=>event.name === eventName) === true && browserWritableEvent(eventName, options);
13
+ }
@@ -3,7 +3,7 @@ export { LayerUsage } from '../admin/LayerUsage.js';
3
3
  export { MetricSourceSelect } from '../admin/MetricSourceSelect.js';
4
4
  export { ArmSelectField } from '../admin/armSelect/ArmSelectField.js';
5
5
  export { TestsNavLink } from '../admin/TestsNavLink.js';
6
- export { TestsSurface } from '../admin/surface/TestsSurface.js';
6
+ export { TestsSurface } from '../admin/views/TestsSurfaceClient.js';
7
7
  export { TestsDashboardCards } from '../admin/TestsDashboardCards.js';
8
8
  export { PlacementStatus } from '../admin/PlacementStatus.js';
9
9
  export { wrapExperimentBlock, syncExperimentSlots, copyOriginalIntoVersion, unwrapExperimentBlock, findRegisteredBlocksField } from '../blocks/formState.js';
@@ -4,7 +4,7 @@ export { LayerUsage } from '../admin/LayerUsage.js';
4
4
  export { MetricSourceSelect } from '../admin/MetricSourceSelect.js';
5
5
  export { ArmSelectField } from '../admin/armSelect/ArmSelectField.js';
6
6
  export { TestsNavLink } from '../admin/TestsNavLink.js';
7
- export { TestsSurface } from '../admin/surface/TestsSurface.js';
7
+ export { TestsSurface } from '../admin/views/TestsSurfaceClient.js';
8
8
  export { TestsDashboardCards } from '../admin/TestsDashboardCards.js';
9
9
  export { PlacementStatus } from '../admin/PlacementStatus.js';
10
10
  export { wrapExperimentBlock, syncExperimentSlots, copyOriginalIntoVersion, unwrapExperimentBlock, findRegisteredBlocksField } from '../blocks/formState.js';
@@ -2,7 +2,7 @@ export { createExperimentsPlugin } from '../plugin.js';
2
2
  export { defineFlagPoint, defineMetricSource } from '../define.js';
3
3
  export { contentDone } from '../contentDone.js';
4
4
  export { createArmSelectField } from '../fields/armSelect.js';
5
- export type { SerializedFlagPoint, SerializedMetricSource, SerializedAttributeKeys, EditableField, Assignment, Assignments, FlagPointResult, ClientAssignments, RenderedExposure, DocId, PreviewPlacement, Attributes, ExposurePolicy, ExperimentKind, Status, UnitType, ArmKey, ArmKind, TargetingRule, Arm, ParamField, MetricSource, FlagPoint, RateLimiter, ExperimentsAccess, ExperimentsPluginOptions, ExperimentsPageCollection, ArmIssueCode, RefusalCode, ReadinessCode, ErrorEnvelope, TransitionSuccess, AllocateBody, AddMetricBody, AddMetricWarning, AddMetricResult, ClickKeysResult, DecideBody, ArchiveBody, MakeContentResult, DismissContentEntryBody, DismissContentEntryResult, RestoreContentEntryBody, RestoreContentEntryResult, ContentReport, PreflightResult, PreviewTokenResult, PhaseSummary, ResultsResponse, SummaryResponse, EventBody, FlagDefault, Manifest, ManifestExperiment, ArmSlot, ExperimentRef, ExperimentSlotProps, ExperimentsProxyRuntimeOptions, ExperimentsProxyRuntime, ExperimentsServerRuntimeOptions, ExperimentsServerRuntime, VerdictCode, Snapshot, MetricUnavailableReason, ContentReportReason, } from '../types/index.js';
5
+ export type { SerializedFlagPoint, SerializedMetricSource, SerializedAttributeKeys, EditableField, Assignment, Assignments, FlagPointResult, ClientAssignments, RenderedExposure, DocId, PreviewPlacement, Attributes, ExposurePolicy, ExperimentKind, Status, UnitType, ArmKey, ArmKind, TargetingRule, Arm, ParamField, MetricSource, FlagPoint, RateLimiter, ExperimentsAccess, ExperimentsPluginOptions, ExperimentsPageCollection, ArmIssueCode, RefusalCode, ReadinessCode, ErrorEnvelope, TransitionSuccess, StartExperimentFirstStartDetail, StartExperimentResult, StartExperimentWarning, AllocateBody, AddMetricBody, AddMetricWarning, AddMetricResult, ClickKeysResult, PagesResult, PlacementStatusResult, PageTestStatus, DeleteImpactResult, RoundBody, DecideBody, ArchiveBody, MakeContentResult, DismissContentEntryBody, DismissContentEntryResult, RestoreContentEntryBody, RestoreContentEntryResult, ContentReport, PreflightResult, PreviewTokenResult, PhaseSummary, ResultsResponse, SummaryResponse, EventBody, FlagDefault, Manifest, ManifestExperiment, ArmSlot, ExperimentRef, ExperimentSlotProps, ExperimentsProxyRuntimeOptions, ExperimentsProxyRuntime, ExperimentsServerRuntimeOptions, ExperimentsServerRuntime, VerdictCode, Snapshot, MetricUnavailableReason, ContentReportReason, } from '../types/index.js';
6
6
  export { createExperimentBlock } from '../blocks/createExperimentBlock.js';
7
7
  export { EXPERIMENT_BLOCK_SLUG } from '../blocks/model.js';
8
8
  export type { HostBlock, ExperimentBlock, ExperimentBlockGroup, ResolvedHostBlock, ResolvedExperimentBlocks } from '../blocks/model.js';
@@ -8,6 +8,7 @@ export { eraseUser } from '../server/eraseUser.js';
8
8
  export type { MetricUnavailableReason, ContentReportReason } from '../types/reasons.js';
9
9
  export type { PreviewPlacement } from '../types/contracts.js';
10
10
  export { runResults } from '../server/runResults.js';
11
+ export { startExperiment } from '../server/startExperiment.js';
11
12
  export { recordContentChange } from '../server/recordContentChange.js';
12
13
  export { experimentSitemapFilter } from '../server/sitemap.js';
13
14
  export { experimentMetadata } from '../server/metadata.js';
@@ -6,6 +6,7 @@ export { linkIdentity } from '../server/linkIdentity.js';
6
6
  export { trackConversion } from '../server/trackConversion.js';
7
7
  export { eraseUser } from '../server/eraseUser.js';
8
8
  export { runResults } from '../server/runResults.js';
9
+ export { startExperiment } from '../server/startExperiment.js';
9
10
  export { recordContentChange } from '../server/recordContentChange.js';
10
11
  export { experimentSitemapFilter } from '../server/sitemap.js';
11
12
  export { experimentMetadata } from '../server/metadata.js';
@@ -1,7 +1,9 @@
1
+ import { placementReader } from '../blocks/placementLocale.js';
2
+ import { puckExperimentSlug } from '../puck/experimentSlug.js';
1
3
  import { puckVisibility } from '../puck/visibility.js';
2
4
  import { clickGoalContent } from '../db/clickGoals.js';
3
5
  import { safeError } from '../log.js';
4
- import { documentEditor, puckCollections } from '../options.js';
6
+ import { puckCollections } from '../options.js';
5
7
  import { EXPERIMENT_BLOCK_SLUG, hostBlocks, isObject, slotBlocks } from '../blocks/model.js';
6
8
  import { resolvePageCollection } from '../transitions/pageCollection.js';
7
9
  import { scanPlacements, uniquePlacementDocs } from '../transitions/placementInteractions.js';
@@ -92,7 +94,8 @@ function blockLabels(req) {
92
94
  unchecked.push(placement);
93
95
  continue;
94
96
  }
95
- collect(collection.contentOf(doc), byArm.get(arm.key), '', labels);
97
+ const reader = placementReader(req, collection.slug, options);
98
+ for (const view of reader.documentViews)collect(collection.contentOf(reader.read(doc, 'all-locales', view).doc), byArm.get(arm.key), '', labels);
96
99
  readArms.add(arm.key);
97
100
  } catch (error) {
98
101
  failed(error, placement);
@@ -120,37 +123,41 @@ function blockLabels(req) {
120
123
  }
121
124
  for (const placement of docs){
122
125
  try {
123
- const doc = await clickGoalContent(req, placement.collection, placement.id);
124
- if (!doc) continue;
125
- const editor = documentEditor(options, placement.collection, doc);
126
- if (editor === 'blocks') {
127
- const registration = options.blocks?.collections.find((c)=>c.slug === placement.collection);
128
- if (!registration) continue;
129
- for (const block of hostBlocks(doc[registration.field])){
130
- if (block.blockType !== (registration.blockSlug ?? EXPERIMENT_BLOCK_SLUG) || block.experiment !== experiment.slug) continue;
131
- for (const arm of experiment.arms.filter((a)=>a.kind !== 'holdout'))collect(slotBlocks(block, arm.slot ?? arm.key), byArm.get(arm.key), '', labels);
132
- }
133
- } else {
134
- const registration = puckCollections(options).find((c)=>c.slug === placement.collection);
135
- if (!registration) continue;
136
- const visibility = puckVisibility(doc[registration.field]);
137
- const walk = (value)=>{
138
- if (Array.isArray(value)) {
139
- value.forEach(walk);
140
- return;
141
- }
142
- if (!isObject(value) || visibility.get(value)?.hidden) return;
143
- const props = isObject(value.props) ? value.props : undefined;
144
- const ref = props?.experiment;
145
- if (value.type === 'ExperimentSlot' && props && (typeof ref === 'string' ? ref : isObject(ref) ? ref.slug : undefined) === experiment.slug) {
146
- for (const arm of experiment.arms.filter((a)=>a.kind !== 'holdout'))collect(props[arm.slot ?? arm.key], byArm.get(arm.key), '', labels, visibility);
147
- return;
126
+ const raw = await clickGoalContent(req, placement.collection, placement.id);
127
+ const reader = placementReader(req, placement.collection, options);
128
+ for (const view of reader.views){
129
+ const localized = reader.read(raw, 'all-locales', view);
130
+ const doc = localized.doc;
131
+ if (!doc) continue;
132
+ const editor = localized.editor;
133
+ if (editor === 'blocks') {
134
+ const registration = options.blocks?.collections.find((c)=>c.slug === placement.collection);
135
+ if (!registration) continue;
136
+ for (const block of hostBlocks(doc[registration.field])){
137
+ if (block.blockType !== (registration.blockSlug ?? EXPERIMENT_BLOCK_SLUG) || block.experiment !== experiment.slug) continue;
138
+ for (const arm of experiment.arms.filter((a)=>a.kind !== 'holdout'))collect(slotBlocks(block, arm.key), byArm.get(arm.key), '', labels);
148
139
  }
149
- Object.values(value).forEach(walk);
150
- };
151
- walk(doc[registration.field]);
140
+ } else {
141
+ const registration = puckCollections(options).find((c)=>c.slug === placement.collection);
142
+ if (!registration) continue;
143
+ const visibility = puckVisibility(doc[registration.field]);
144
+ const walk = (value)=>{
145
+ if (Array.isArray(value)) {
146
+ value.forEach(walk);
147
+ return;
148
+ }
149
+ if (!isObject(value) || visibility.get(value)?.hidden) return;
150
+ const props = isObject(value.props) ? value.props : undefined;
151
+ if (value.type === 'ExperimentSlot' && props && puckExperimentSlug(props.experiment) === experiment.slug) {
152
+ for (const arm of experiment.arms.filter((a)=>a.kind !== 'holdout'))collect(props[arm.key], byArm.get(arm.key), '', labels, visibility);
153
+ return;
154
+ }
155
+ Object.values(value).forEach(walk);
156
+ };
157
+ walk(doc[registration.field]);
158
+ }
159
+ for (const arm of byArm.keys())readArms.add(arm);
152
160
  }
153
- for (const arm of byArm.keys())readArms.add(arm);
154
161
  } catch (error) {
155
162
  failed(error, placement);
156
163
  }
@@ -2,7 +2,7 @@ import type { PayloadRequest } from 'payload';
2
2
  import type { Executor } from '../db/executor.js';
3
3
  import { type PlacementTest } from '../db/placements.js';
4
4
  import { type BulkPlacementRemoval } from '../db/bulkPlacementRemoval.js';
5
- import { type RemovedPlacementViews } from '../blocks/placementLocale.js';
5
+ import { type RemovedPlacementViews, type PlacementInput } from '../blocks/placementLocale.js';
6
6
  import type { DocId } from '../types/contracts.js';
7
7
  export type RemovalClaims = {
8
8
  transaction: unknown;
@@ -19,7 +19,7 @@ export declare function releaseRestoredRemovalClaims(req: PayloadRequest, collec
19
19
  id: DocId;
20
20
  }, test: PlacementTest): void;
21
21
  export declare const blockRemovalRule: {
22
- prepare(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, removingPage: boolean, exec?: Executor, tests?: readonly PlacementTest[]): Promise<{
22
+ prepare(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, removingPage: boolean, exec?: Executor, tests?: readonly PlacementTest[], input?: PlacementInput): Promise<{
23
23
  views: RemovedPlacementViews;
24
24
  affected: PlacementTest[];
25
25
  hidden: Set<string>;