@delmaredigital/payload-experiments 0.4.0-rc.5 → 0.4.0-rc.7
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.
- package/dist/admin/blocks/BlockPanel.js +6 -4
- package/dist/admin/blocks/inject.js +1 -0
- package/dist/admin/blocks/model.d.ts +3 -2
- package/dist/admin/blocks/model.js +8 -4
- package/dist/admin/copy/blocks.d.ts +3 -2
- package/dist/admin/copy/blocks.js +7 -6
- package/dist/admin/copy/newTest.d.ts +1 -1
- package/dist/admin/copy/newTest.js +1 -1
- package/dist/admin/surface/ResultsRoute.js +2 -1
- package/dist/admin/surface/TestsHome.d.ts +2 -1
- package/dist/admin/surface/TestsHome.js +91 -37
- package/dist/admin/surface/TestsSurface.js +3 -0
- package/dist/admin/surface/home.model.d.ts +2 -0
- package/dist/admin/surface/newTest/NewTest.js +16 -18
- package/dist/admin/surface/newTest/PageWizard.js +1 -0
- package/dist/admin/surface/newTest/newTest.css +3 -1
- package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
- package/dist/admin/views/TestsSurfaceClient.js +11 -0
- package/dist/admin/views/buildSurfaceProps.js +10 -3
- package/dist/blocks/bindings.js +8 -14
- package/dist/blocks/placementLanguages.d.ts +7 -0
- package/dist/blocks/placementLanguages.js +27 -0
- package/dist/blocks/placementLocale.d.ts +23 -7
- package/dist/blocks/placementLocale.js +221 -66
- package/dist/db/appends.d.ts +13 -0
- package/dist/db/appends.js +49 -0
- package/dist/db/bulkPlacementRemoval.js +8 -4
- package/dist/endpoints/contentLocale.d.ts +6 -0
- package/dist/endpoints/contentLocale.js +15 -0
- package/dist/endpoints/deleteImpact.d.ts +6 -0
- package/dist/endpoints/deleteImpact.js +206 -0
- package/dist/endpoints/index.js +7 -0
- package/dist/endpoints/pages.js +7 -3
- package/dist/endpoints/placementStatus.js +6 -1
- package/dist/endpoints/preflight.d.ts +1 -1
- package/dist/endpoints/preflight.js +17 -2
- package/dist/exports/adminClient.d.ts +1 -1
- package/dist/exports/adminClient.js +1 -1
- package/dist/exports/index.d.ts +1 -1
- package/dist/goals/fairness.js +43 -34
- package/dist/hooks/blockRemovalRule.d.ts +4 -3
- package/dist/hooks/blockRemovalRule.js +33 -9
- package/dist/hooks/pageGuard.d.ts +3 -0
- package/dist/hooks/pageGuard.js +34 -24
- package/dist/hooks/puckNestedTests.d.ts +8 -0
- package/dist/hooks/puckNestedTests.js +36 -0
- package/dist/lib/placementPages.d.ts +2 -1
- package/dist/lib/placementPages.js +10 -2
- package/dist/manifest/compile.d.ts +2 -1
- package/dist/manifest/compile.js +5 -1
- package/dist/puck/ExperimentPicker.d.ts +2 -1
- package/dist/puck/ExperimentPicker.js +37 -30
- package/dist/puck/ExperimentSlot.js +3 -1
- package/dist/puck/copy.d.ts +1 -0
- package/dist/puck/copy.js +1 -0
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
- package/dist/puck/editor/ConfigureTestDrawer.js +4 -2
- package/dist/puck/editor/CreateExperimentDrawer.d.ts +2 -1
- package/dist/puck/editor/CreateExperimentDrawer.js +24 -20
- package/dist/puck/editor/EditorControls.d.ts +1 -1
- package/dist/puck/editor/EditorControls.js +1 -1
- package/dist/puck/editor/ExperimentSlotEditor.js +405 -394
- package/dist/puck/editor/LeftoverVersions.d.ts +4 -2
- package/dist/puck/editor/LeftoverVersions.js +23 -44
- package/dist/puck/editor/QuickTestActions.js +2 -2
- package/dist/puck/editor/VersionBuilder.d.ts +41 -13
- package/dist/puck/editor/VersionBuilder.js +461 -224
- package/dist/puck/editor/armWrites.d.ts +9 -2
- package/dist/puck/editor/armWrites.js +40 -2
- package/dist/puck/editor/armsCache.d.ts +1 -1
- package/dist/puck/editor/armsCache.js +2 -1
- package/dist/puck/editor/blockClipboard.d.ts +16 -0
- package/dist/puck/editor/blockClipboard.js +20 -0
- package/dist/puck/editor/copy.d.ts +27 -26
- package/dist/puck/editor/copy.js +28 -26
- package/dist/puck/editor/createTest.d.ts +3 -0
- package/dist/puck/editor/createTest.js +33 -0
- package/dist/puck/editor/editor.chrome.css +138 -17
- package/dist/puck/editor/editor.css +156 -22
- package/dist/puck/editor/editor.model.d.ts +2 -1
- package/dist/puck/editor/editor.model.js +3 -3
- package/dist/puck/editor/experimentOutlinePlugin.js +1 -1
- package/dist/puck/editor/localPlacements.d.ts +5 -2
- package/dist/puck/editor/localPlacements.js +32 -18
- package/dist/puck/editor/placementsCache.d.ts +18 -12
- package/dist/puck/editor/placementsCache.js +52 -47
- package/dist/puck/editor/sidebar.d.ts +2 -6
- package/dist/puck/editor/sidebar.js +3 -6
- package/dist/puck/editor/usePlacementNotice.d.ts +1 -1
- package/dist/puck/editor/usePlacementNotice.js +4 -3
- package/dist/puck/experimentSlug.d.ts +2 -0
- package/dist/puck/experimentSlug.js +3 -0
- package/dist/puck/nestedTestCopy.d.ts +8 -0
- package/dist/puck/nestedTestCopy.js +22 -0
- package/dist/puck/nestedTests.d.ts +17 -0
- package/dist/puck/nestedTests.js +30 -0
- package/dist/puck/slotConfig.d.ts +1 -1
- package/dist/puck/slotConfig.js +17 -4
- package/dist/puck/visibility.d.ts +20 -0
- package/dist/puck/visibility.js +81 -0
- package/dist/server/recordContentChange.js +37 -20
- package/dist/server/resolveExperimentData.js +6 -3
- package/dist/testSurface/PreviewLinks.js +6 -2
- package/dist/testSurface/api.d.ts +6 -3
- package/dist/testSurface/api.js +10 -6
- package/dist/testSurface/contentLocaleURL.d.ts +2 -0
- package/dist/testSurface/contentLocaleURL.js +3 -0
- package/dist/testSurface/copy/common.d.ts +4 -0
- package/dist/testSurface/copy/common.js +8 -4
- package/dist/testSurface/copy/languages.d.ts +11 -0
- package/dist/testSurface/copy/languages.js +7 -0
- package/dist/testSurface/copy/readiness.d.ts +2 -1
- package/dist/testSurface/copy/readiness.js +2 -1
- package/dist/testSurface/copy/testPage.d.ts +28 -6
- package/dist/testSurface/copy/testPage.js +28 -6
- package/dist/testSurface/placementLabel.d.ts +8 -0
- package/dist/testSurface/placementLabel.js +24 -0
- package/dist/testSurface/placements/placementLabels.d.ts +2 -0
- package/dist/testSurface/placements/placementLabels.js +2 -1
- package/dist/testSurface/results/results.css +1 -1
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/surface/contracts.d.ts +2 -0
- package/dist/testSurface/surface/editorPlacement.d.ts +5 -0
- package/dist/testSurface/surface/editorPlacement.js +18 -0
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -1
- package/dist/testSurface/surface/pageBlock/parts.js +24 -6
- package/dist/testSurface/surface/readiness/ActionDialogs.js +28 -34
- package/dist/testSurface/surface/readiness/readiness.model.js +9 -2
- package/dist/testSurface/surface/results/useResults.d.ts +4 -1
- package/dist/testSurface/surface/test/DeleteTest.d.ts +15 -0
- package/dist/testSurface/surface/test/DeleteTest.js +171 -0
- package/dist/testSurface/surface/test/GoalSection.js +101 -74
- package/dist/testSurface/surface/test/TestSurface.js +29 -9
- package/dist/testSurface/surface/test/fields.d.ts +1 -3
- package/dist/testSurface/surface/test/fields.js +5 -35
- package/dist/testSurface/surface/useTestDocument.d.ts +2 -1
- package/dist/testSurface/surface/useTestDocument.js +20 -4
- package/dist/testSurface/useApi.d.ts +4 -1
- package/dist/transitions/checkStart.d.ts +4 -1
- package/dist/transitions/checkStart.js +117 -14
- package/dist/transitions/contentFields.js +9 -5
- package/dist/transitions/makeContent.js +29 -9
- package/dist/transitions/nestedPlacementNames.d.ts +5 -0
- package/dist/transitions/nestedPlacementNames.js +33 -0
- package/dist/transitions/pageVersions.js +3 -1
- package/dist/transitions/placementInteractions.js +7 -4
- package/dist/transitions/placements.d.ts +26 -1
- package/dist/transitions/placements.js +239 -87
- package/dist/transitions/preflightData.d.ts +2 -1
- package/dist/transitions/preflightData.js +66 -3
- package/dist/transitions/start.js +4 -1
- package/dist/types/endpoints.d.ts +35 -1
- package/dist/types/endpoints.js +1 -1
- package/dist/types/puck.d.ts +1 -0
- package/dist/types/surface.d.ts +2 -0
- package/dist/ui/Button.js +2 -2
- package/dist/ui/Inputs.d.ts +4 -3
- package/dist/ui/Inputs.js +7 -4
- package/dist/ui/SelectControl.d.ts +33 -0
- package/dist/ui/SelectControl.js +504 -0
- package/dist/ui/Tabs.d.ts +0 -1
- package/dist/ui/Tabs.js +28 -40
- package/dist/ui/ui.css +18 -5
- package/package.json +3 -2
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { contentLocale } from './contentLocale.js';
|
|
2
|
+
import { placementLanguages } from '../blocks/placementLanguages.js';
|
|
3
|
+
import { localeRequest, placementReader } from '../blocks/placementLocale.js';
|
|
4
|
+
import { Forbidden } from 'payload';
|
|
5
|
+
import { XpRefusal } from '../errors.js';
|
|
6
|
+
import { compileManifest, loadManifestInputs } from '../manifest/compile.js';
|
|
7
|
+
import { publishedBlockPlacementPages } from '../transitions/placements.js';
|
|
8
|
+
import { routeId } from './routeId.js';
|
|
9
|
+
/** Advisory read only. Delete keeps its own access check, status guard and transaction. */ export async function handleDeleteImpact(req, { options }) {
|
|
10
|
+
const headers = {
|
|
11
|
+
'Cache-Control': 'no-store'
|
|
12
|
+
};
|
|
13
|
+
const reply = (result)=>Response.json(result, {
|
|
14
|
+
headers
|
|
15
|
+
});
|
|
16
|
+
const { locale, fallbackLocale } = contentLocale(req);
|
|
17
|
+
const metadataReq = localeRequest(req, {
|
|
18
|
+
locale: locale ?? '',
|
|
19
|
+
fallbackLocale: fallbackLocale ?? false
|
|
20
|
+
});
|
|
21
|
+
// Payload Local API setup mutates locale/fallback on its request. Keep those reads scoped.
|
|
22
|
+
req = localeRequest(req, {
|
|
23
|
+
locale: req.locale ?? '',
|
|
24
|
+
fallbackLocale: req.fallbackLocale ?? false
|
|
25
|
+
});
|
|
26
|
+
const id = routeId(req);
|
|
27
|
+
if (id === undefined) throw new XpRefusal('not-found', 'Experiment not found', undefined, 404);
|
|
28
|
+
const { docs } = await req.payload.find({
|
|
29
|
+
collection: 'xp-experiments',
|
|
30
|
+
req,
|
|
31
|
+
overrideAccess: false,
|
|
32
|
+
depth: 0,
|
|
33
|
+
limit: 1,
|
|
34
|
+
where: {
|
|
35
|
+
id: {
|
|
36
|
+
equals: id
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const experiment = docs[0];
|
|
41
|
+
if (!experiment) throw new XpRefusal('not-found', 'Experiment not found', undefined, 404);
|
|
42
|
+
if (experiment.status !== 'draft' && experiment.status !== 'archived') throw new XpRefusal('invalid-status', 'This test cannot be deleted in its current status.', undefined, 409);
|
|
43
|
+
const { decision, kind } = experiment;
|
|
44
|
+
if (experiment.status === 'draft' || !decision?.winnerArm || decision.discardedAt || kind !== 'block' && kind !== 'page' || kind === 'page' && decision.pagesReleasedAt || kind === 'block' && decision.winnerArm === 'control') return reply({
|
|
45
|
+
effect: 'none'
|
|
46
|
+
});
|
|
47
|
+
// Use the live builder's complete inputs and ordering, including archived address collisions.
|
|
48
|
+
req.signal?.throwIfAborted();
|
|
49
|
+
let inputs;
|
|
50
|
+
let manifest;
|
|
51
|
+
try {
|
|
52
|
+
inputs = await loadManifestInputs(req, {
|
|
53
|
+
signal: req.signal
|
|
54
|
+
});
|
|
55
|
+
manifest = compileManifest(inputs, 0, {
|
|
56
|
+
attributeKeys: options.attributeKeys
|
|
57
|
+
});
|
|
58
|
+
} catch (cause) {
|
|
59
|
+
req.signal?.throwIfAborted();
|
|
60
|
+
throw new XpRefusal('placement-unchecked', 'The effect of deleting this test could not be determined.', undefined, 422, {
|
|
61
|
+
cause
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
req.signal?.throwIfAborted();
|
|
65
|
+
if (kind === 'page') {
|
|
66
|
+
const after = compileManifest({
|
|
67
|
+
...inputs,
|
|
68
|
+
excludeIds: [
|
|
69
|
+
id
|
|
70
|
+
]
|
|
71
|
+
}, 0, {
|
|
72
|
+
attributeKeys: options.attributeKeys
|
|
73
|
+
});
|
|
74
|
+
const routes = Object.entries(manifest.archivedPages).filter(([path, route])=>route.slug === experiment.slug && (after.archivedPages[path]?.winnerPath ?? path) !== route.winnerPath);
|
|
75
|
+
const afterPaths = Object.fromEntries(routes.flatMap(([path])=>after.archivedPages[path] ? [
|
|
76
|
+
[
|
|
77
|
+
path,
|
|
78
|
+
after.archivedPages[path].winnerPath
|
|
79
|
+
]
|
|
80
|
+
] : []));
|
|
81
|
+
return reply(routes.length ? {
|
|
82
|
+
effect: 'page',
|
|
83
|
+
winnerPath: routes[0][1].winnerPath,
|
|
84
|
+
addresses: routes.map(([path])=>path),
|
|
85
|
+
...Object.keys(afterPaths).length ? {
|
|
86
|
+
afterPaths
|
|
87
|
+
} : {}
|
|
88
|
+
} : {
|
|
89
|
+
effect: 'none'
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const winnerSlot = manifest.archivedWinners[experiment.slug];
|
|
93
|
+
if (!winnerSlot || winnerSlot === 'control') return reply({
|
|
94
|
+
effect: 'none'
|
|
95
|
+
});
|
|
96
|
+
const phase = inputs.experiments.find((test)=>String(test.id) === String(id))?.lastTestPhase;
|
|
97
|
+
const winner = phase?.arms.find((arm)=>arm.key === decision.winnerArm);
|
|
98
|
+
const control = phase?.arms.find((arm)=>arm.key === 'control');
|
|
99
|
+
if (!winner || !control) throw new XpRefusal('placement-unchecked', 'The effect of deleting this test could not be determined.', undefined, 422);
|
|
100
|
+
const affected = [];
|
|
101
|
+
const changedPages = new Set(), readablePages = new Set();
|
|
102
|
+
for await (const { collection, placements } of publishedBlockPlacementPages(req, options, experiment.slug)){
|
|
103
|
+
const changed = placements.filter((place)=>(place.editor !== 'blocks' || place.slots[winnerSlot]) && (place.slots[winnerSlot] || place.slots.control));
|
|
104
|
+
if (!changed.length) continue;
|
|
105
|
+
const byPage = new Map();
|
|
106
|
+
for (const place of changed){
|
|
107
|
+
const key = String(place.id);
|
|
108
|
+
changedPages.add(JSON.stringify([
|
|
109
|
+
collection,
|
|
110
|
+
key
|
|
111
|
+
]));
|
|
112
|
+
const page = byPage.get(key) ?? [];
|
|
113
|
+
page.push(place);
|
|
114
|
+
byPage.set(key, page);
|
|
115
|
+
}
|
|
116
|
+
req.signal?.throwIfAborted();
|
|
117
|
+
// find applies Where-scoped read access as well as a boolean refusal. Never disclose the privileged document.
|
|
118
|
+
let readable = [];
|
|
119
|
+
try {
|
|
120
|
+
const result = await req.payload.find({
|
|
121
|
+
collection,
|
|
122
|
+
req: metadataReq,
|
|
123
|
+
overrideAccess: false,
|
|
124
|
+
depth: 0,
|
|
125
|
+
draft: false,
|
|
126
|
+
pagination: false,
|
|
127
|
+
limit: 0,
|
|
128
|
+
locale,
|
|
129
|
+
fallbackLocale,
|
|
130
|
+
where: {
|
|
131
|
+
id: {
|
|
132
|
+
in: [
|
|
133
|
+
...byPage.values()
|
|
134
|
+
].map((places)=>places[0].id)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
readable = result.docs;
|
|
139
|
+
} catch (cause) {
|
|
140
|
+
if (!(cause instanceof Forbidden) && cause?.status !== 403) throw cause;
|
|
141
|
+
}
|
|
142
|
+
req.signal?.throwIfAborted();
|
|
143
|
+
const reader = placementReader(metadataReq, collection, options);
|
|
144
|
+
for (const localized of readable){
|
|
145
|
+
const doc = reader.read(localized, 'localized').doc;
|
|
146
|
+
const places = byPage.get(String(doc.id));
|
|
147
|
+
if (!places?.length) continue;
|
|
148
|
+
readablePages.add(JSON.stringify([
|
|
149
|
+
collection,
|
|
150
|
+
String(doc.id)
|
|
151
|
+
]));
|
|
152
|
+
const registration = options.pages?.collections.find((entry)=>entry.slug === collection);
|
|
153
|
+
let path = null;
|
|
154
|
+
try {
|
|
155
|
+
const value = registration?.pathOf(doc);
|
|
156
|
+
if (typeof value === 'string' && value.startsWith('/') && !value.startsWith('//') && !/[\s\x00-\x1f\x7f-\x9f\\]/.test(value) && !/[\x00-\x1f\x7f-\x9f\\]/.test(decodeURIComponent(value)) && !value.split(/[/?#]/).some((segment)=>{
|
|
157
|
+
const decoded = decodeURIComponent(segment);
|
|
158
|
+
return /^(undefined|null|\[object Object\]|\.\.?)$/i.test(decoded);
|
|
159
|
+
})) path = value;
|
|
160
|
+
} catch {}
|
|
161
|
+
const titleField = req.payload.config.collections?.find((entry)=>entry.slug === collection)?.admin?.useAsTitle;
|
|
162
|
+
const languages = placementLanguages(req, places.flatMap((place)=>place.locale ? [
|
|
163
|
+
place.locale
|
|
164
|
+
] : []));
|
|
165
|
+
const title = (titleField ? doc[titleField] : undefined) ?? doc.title ?? doc.name;
|
|
166
|
+
const version = (slot, arm)=>{
|
|
167
|
+
const values = new Map(places.map((place)=>place.slots[slot] ? [
|
|
168
|
+
arm.key,
|
|
169
|
+
arm.label
|
|
170
|
+
] : [
|
|
171
|
+
'empty',
|
|
172
|
+
'Nothing'
|
|
173
|
+
]));
|
|
174
|
+
return {
|
|
175
|
+
key: [
|
|
176
|
+
...values.keys()
|
|
177
|
+
].join(','),
|
|
178
|
+
label: [
|
|
179
|
+
...values.values()
|
|
180
|
+
].join(' / ')
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
// Page access controls metadata disclosure; a hidden layout field does not hide a readable page's visitor effect.
|
|
184
|
+
affected.push({
|
|
185
|
+
collection,
|
|
186
|
+
id: doc.id,
|
|
187
|
+
title: typeof title === 'string' && title.trim() ? title : typeof title === 'number' && Number.isFinite(title) ? String(title) : title instanceof Date && Number.isFinite(title.getTime()) ? title.toISOString() : String(doc.id),
|
|
188
|
+
path,
|
|
189
|
+
...languages,
|
|
190
|
+
before: version(winnerSlot, winner),
|
|
191
|
+
after: version('control', control)
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return reply(changedPages.size ? {
|
|
196
|
+
effect: 'block',
|
|
197
|
+
controlLabel: control.label,
|
|
198
|
+
pageCount: changedPages.size,
|
|
199
|
+
unreadablePages: [
|
|
200
|
+
...changedPages
|
|
201
|
+
].filter((key)=>!readablePages.has(key)).length,
|
|
202
|
+
placements: affected
|
|
203
|
+
} : {
|
|
204
|
+
effect: 'none'
|
|
205
|
+
});
|
|
206
|
+
}
|
package/dist/endpoints/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { handleDeleteImpact } from './deleteImpact.js';
|
|
1
2
|
import { handleEditorSurface } from './editorSurface.js';
|
|
2
3
|
import { handleClickKeys } from './clickKeys.js';
|
|
3
4
|
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
@@ -94,6 +95,12 @@ export const ROUTES = [
|
|
|
94
95
|
access: 'manage',
|
|
95
96
|
handler: handleArchive
|
|
96
97
|
},
|
|
98
|
+
{
|
|
99
|
+
method: 'get',
|
|
100
|
+
path: '/xp/experiments/:id/delete-impact',
|
|
101
|
+
access: 'manage',
|
|
102
|
+
handler: handleDeleteImpact
|
|
103
|
+
},
|
|
97
104
|
{
|
|
98
105
|
method: 'get',
|
|
99
106
|
path: '/xp/experiments/:id/preflight',
|
package/dist/endpoints/pages.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
1
2
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
2
3
|
import { XpRefusal } from '../errors.js';
|
|
3
4
|
export async function handlePages(req, { options }) {
|
|
4
5
|
const query = new URL(req.url ?? 'http://xp.invalid').searchParams;
|
|
5
6
|
const collection = options.pages?.collections.find((entry)=>entry.slug === query.get('collection'));
|
|
6
7
|
if (!collection) throw new XpRefusal('unknown-collection', "That page type isn't set up for tests.", undefined, 422);
|
|
8
|
+
const reader = placementReader(req, collection.slug, options);
|
|
7
9
|
const path = query.get('path');
|
|
8
10
|
if (path !== null && (!path.length || path.length > 2048 || query.has('q'))) throw new XpRefusal('invalid-body', 'Enter a valid request body.', undefined, 422);
|
|
9
11
|
const page = Number(query.get('page') ?? 1);
|
|
@@ -40,7 +42,7 @@ export async function handlePages(req, { options }) {
|
|
|
40
42
|
}
|
|
41
43
|
});
|
|
42
44
|
const published = !drafts || main._status === 'published';
|
|
43
|
-
const
|
|
45
|
+
const row = published ? main : await req.payload.findByID({
|
|
44
46
|
collection: collection.slug,
|
|
45
47
|
id: main.id,
|
|
46
48
|
req,
|
|
@@ -49,7 +51,7 @@ export async function handlePages(req, { options }) {
|
|
|
49
51
|
draft: true,
|
|
50
52
|
disableErrors: true
|
|
51
53
|
});
|
|
52
|
-
if (!
|
|
54
|
+
if (!row) return Response.json({
|
|
53
55
|
docs: [],
|
|
54
56
|
hasNextPage: false
|
|
55
57
|
}, {
|
|
@@ -57,6 +59,7 @@ export async function handlePages(req, { options }) {
|
|
|
57
59
|
'Cache-Control': 'no-store'
|
|
58
60
|
}
|
|
59
61
|
});
|
|
62
|
+
const doc = reader.read(row, req.locale === 'all' ? 'all-locales' : 'localized').doc;
|
|
60
63
|
const rawPath = collection.pathOf(doc);
|
|
61
64
|
return Response.json({
|
|
62
65
|
docs: [
|
|
@@ -92,7 +95,7 @@ export async function handlePages(req, { options }) {
|
|
|
92
95
|
});
|
|
93
96
|
const docs = await Promise.all(result.docs.map(async (main)=>{
|
|
94
97
|
const published = !drafts || main._status === 'published';
|
|
95
|
-
const
|
|
98
|
+
const row = published ? main : await req.payload.findByID({
|
|
96
99
|
collection: collection.slug,
|
|
97
100
|
id: main.id,
|
|
98
101
|
req,
|
|
@@ -100,6 +103,7 @@ export async function handlePages(req, { options }) {
|
|
|
100
103
|
depth: 0,
|
|
101
104
|
draft: true
|
|
102
105
|
});
|
|
106
|
+
const doc = reader.read(row, req.locale === 'all' ? 'all-locales' : 'localized').doc;
|
|
103
107
|
const path = collection.pathOf(doc);
|
|
104
108
|
return {
|
|
105
109
|
id: main.id,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
1
2
|
import { readBody } from './readBody.js';
|
|
2
3
|
import { safeError } from '../log.js';
|
|
3
4
|
import { statusPageContent } from '../db/pageContent.js';
|
|
@@ -143,6 +144,9 @@ export async function handlePlacementStatus(req, { options }) {
|
|
|
143
144
|
...test.decision?.winnerArm ? {
|
|
144
145
|
winnerArm: test.decision.winnerArm
|
|
145
146
|
} : {},
|
|
147
|
+
...test.decision?.discardedAt ? {
|
|
148
|
+
discarded: true
|
|
149
|
+
} : {},
|
|
146
150
|
rollout: round.rollout
|
|
147
151
|
};
|
|
148
152
|
}
|
|
@@ -160,7 +164,8 @@ export async function handlePlacementStatus(req, { options }) {
|
|
|
160
164
|
});
|
|
161
165
|
const registration = options.pages?.collections.find((entry)=>entry.slug === collection);
|
|
162
166
|
const raw = registration ? await statusPageContent(req, collection, id) : null;
|
|
163
|
-
const
|
|
167
|
+
const doc = placementReader(req, collection, options).read(raw, 'all-locales').doc;
|
|
168
|
+
const rawPath = doc && registration ? registration.pathOf(doc) : null;
|
|
164
169
|
const path = rawPath;
|
|
165
170
|
const pathKey = path === null ? null : normalisePath(path);
|
|
166
171
|
const status = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type PayloadRequest } from 'payload';
|
|
2
2
|
import type { EndpointContext } from '../types/endpoints.js';
|
|
3
3
|
import type { PreflightDependencies } from '../transitions/preflightData.js';
|
|
4
4
|
export declare function handlePreflight<TUser extends {
|
|
@@ -1,10 +1,25 @@
|
|
|
1
|
+
import { contentLocale } from './contentLocale.js';
|
|
2
|
+
import { sanitizeFallbackLocale } from 'payload';
|
|
3
|
+
import { localeRequest } from '../blocks/placementLocale.js';
|
|
1
4
|
import { preflightData } from '../transitions/preflightData.js';
|
|
2
5
|
import { routeId } from './routeId.js';
|
|
3
6
|
export async function handlePreflight(req, ctx, dependencies) {
|
|
4
7
|
const id = routeId(req);
|
|
5
|
-
const
|
|
8
|
+
const placementLocale = contentLocale(req).locale ?? undefined;
|
|
9
|
+
const localization = req.payload.config.localization;
|
|
10
|
+
// The query selects readiness labels only. Host reads must match Start's default request.
|
|
11
|
+
const readinessReq = localization ? localeRequest(req, {
|
|
12
|
+
locale: localization.defaultLocale,
|
|
13
|
+
fallbackLocale: sanitizeFallbackLocale({
|
|
14
|
+
fallbackLocale: null,
|
|
15
|
+
locale: localization.defaultLocale,
|
|
16
|
+
localization
|
|
17
|
+
})
|
|
18
|
+
}) : req;
|
|
19
|
+
const result = id !== undefined ? await preflightData(readinessReq, {
|
|
6
20
|
experimentId: id,
|
|
7
|
-
options: ctx.options
|
|
21
|
+
options: ctx.options,
|
|
22
|
+
placementLocale
|
|
8
23
|
}, dependencies) : null;
|
|
9
24
|
const headers = {
|
|
10
25
|
'Cache-Control': 'no-store'
|
|
@@ -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/
|
|
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/
|
|
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';
|
package/dist/exports/index.d.ts
CHANGED
|
@@ -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, AllocateBody, AddMetricBody, AddMetricWarning, AddMetricResult, ClickKeysResult, PagesResult, PlacementStatusResult, PageTestStatus, DeleteImpactResult, 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';
|
package/dist/goals/fairness.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
2
|
+
import { puckExperimentSlug } from '../puck/experimentSlug.js';
|
|
3
|
+
import { puckVisibility } from '../puck/visibility.js';
|
|
1
4
|
import { clickGoalContent } from '../db/clickGoals.js';
|
|
2
5
|
import { safeError } from '../log.js';
|
|
3
|
-
import {
|
|
6
|
+
import { puckCollections } from '../options.js';
|
|
4
7
|
import { EXPERIMENT_BLOCK_SLUG, hostBlocks, isObject, slotBlocks } from '../blocks/model.js';
|
|
5
8
|
import { resolvePageCollection } from '../transitions/pageCollection.js';
|
|
6
9
|
import { scanPlacements, uniquePlacementDocs } from '../transitions/placementInteractions.js';
|
|
7
10
|
import { CLICK_KEY } from './key.js';
|
|
8
11
|
export const OUTSIDE_GOAL = (name = 'Selected goal', kind = 'block')=>kind === 'block' ? `Heads up: the click goal “${name}” is outside this test's block, so every version shows the same button. The test can still start. To compare different buttons, move the goal inside each version.` : `Heads up: the click goal “${name}” isn't on any of this test's pages. The test can still start. Add the goal to every version's page to measure those clicks.`;
|
|
9
12
|
export const LEGACY_FAIRNESS = "Goal fairness isn't checked for tests started before this update.";
|
|
10
|
-
/** Inspect inline JSON only; depth-zero relationship ids never dereference another document. */ function collect(value, into, label = '', labels) {
|
|
13
|
+
/** Inspect inline JSON only; depth-zero relationship ids never dereference another document. */ function collect(value, into, label = '', labels, visibility) {
|
|
11
14
|
if (Array.isArray(value)) {
|
|
12
|
-
value.forEach((item)=>collect(item, into, label, labels));
|
|
15
|
+
value.forEach((item)=>collect(item, into, label, labels, visibility));
|
|
13
16
|
return;
|
|
14
17
|
}
|
|
15
|
-
if (!isObject(value)) return;
|
|
18
|
+
if (!isObject(value) || visibility?.get(value)?.hidden) return;
|
|
16
19
|
const blockType = typeof value.blockType === 'string' ? value.blockType : typeof value.type === 'string' ? value.type : '';
|
|
17
20
|
const containing = labels.get(blockType) ?? (blockType || label);
|
|
18
21
|
if (typeof value.xpGoal === 'string' && CLICK_KEY.test(value.xpGoal)) into.set(value.xpGoal, containing || value.xpGoal);
|
|
19
|
-
Object.values(value).forEach((item)=>collect(item, into, containing, labels));
|
|
22
|
+
Object.values(value).forEach((item)=>collect(item, into, containing, labels, visibility));
|
|
20
23
|
}
|
|
21
24
|
function blockLabels(req) {
|
|
22
25
|
const labels = new Map();
|
|
@@ -91,7 +94,8 @@ function blockLabels(req) {
|
|
|
91
94
|
unchecked.push(placement);
|
|
92
95
|
continue;
|
|
93
96
|
}
|
|
94
|
-
|
|
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);
|
|
95
99
|
readArms.add(arm.key);
|
|
96
100
|
} catch (error) {
|
|
97
101
|
failed(error, placement);
|
|
@@ -119,36 +123,41 @@ function blockLabels(req) {
|
|
|
119
123
|
}
|
|
120
124
|
for (const placement of docs){
|
|
121
125
|
try {
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
if (!
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const walk = (value)=>{
|
|
136
|
-
if (Array.isArray(value)) {
|
|
137
|
-
value.forEach(walk);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
if (!isObject(value)) return;
|
|
141
|
-
const props = isObject(value.props) ? value.props : undefined;
|
|
142
|
-
const ref = props?.experiment;
|
|
143
|
-
if (value.type === 'ExperimentSlot' && props && (typeof ref === 'string' ? ref : isObject(ref) ? ref.slug : undefined) === experiment.slug) {
|
|
144
|
-
for (const arm of experiment.arms.filter((a)=>a.kind !== 'holdout'))collect(props[arm.slot ?? arm.key], byArm.get(arm.key), '', labels);
|
|
145
|
-
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.slot ?? arm.key), byArm.get(arm.key), '', labels);
|
|
146
139
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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.slot ?? 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);
|
|
150
160
|
}
|
|
151
|
-
for (const arm of byArm.keys())readArms.add(arm);
|
|
152
161
|
} catch (error) {
|
|
153
162
|
failed(error, placement);
|
|
154
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,11 +19,12 @@ 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
|
+
hidden: Set<string>;
|
|
25
26
|
}>;
|
|
26
27
|
discover(exec: Executor, removed: string[], tests?: readonly PlacementTest[]): Promise<PlacementTest[]>;
|
|
27
28
|
claim(req: PayloadRequest, transaction: unknown, affected: readonly PlacementTest[], collection: string, id: DocId, views: RemovedPlacementViews): RemovalClaims;
|
|
28
|
-
check(req: PayloadRequest, current: readonly PlacementTest[], affected: readonly PlacementTest[], collection: string, id: DocId, removingPage: boolean, views: RemovedPlacementViews, bulk?: BulkPlacementRemoval): Promise<void>;
|
|
29
|
+
check(req: PayloadRequest, current: readonly PlacementTest[], affected: readonly PlacementTest[], collection: string, id: DocId, removingPage: boolean, views: RemovedPlacementViews, bulk?: BulkPlacementRemoval, hidden?: ReadonlySet<string>): Promise<void>;
|
|
29
30
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { puckExperimentSlug } from '../puck/experimentSlug.js';
|
|
2
|
+
import { walkVisiblePuck } from '../puck/visibility.js';
|
|
3
|
+
import { puckCollections } from '../options.js';
|
|
1
4
|
import { removableBlockTests } from '../db/placements.js';
|
|
2
5
|
import { XpNoTransactionError, XpRefusal } from '../errors.js';
|
|
3
|
-
import { lastBlockPlacementCopy, pendingBlockRemovalCopy, bulkBlockRemovalCopy } from '../testSurface/copy/readiness.js';
|
|
6
|
+
import { lastBlockPlacementCopy, hiddenBlockPlacementCopy, pendingBlockRemovalCopy, bulkBlockRemovalCopy } from '../testSurface/copy/readiness.js';
|
|
4
7
|
import { hasOtherPublishedBlockPlacement } from '../transitions/placements.js';
|
|
5
8
|
import { bulkRemoves } from '../db/bulkPlacementRemoval.js';
|
|
6
|
-
import {
|
|
7
|
-
import { placementSlugs } from '../blocks/bindings.js';
|
|
9
|
+
import { placementReader, removedPlacementViews, placementDocumentKey, mergedPlacementLocales } from '../blocks/placementLocale.js';
|
|
8
10
|
export function releaseRemovalClaim(req, collection, id, ownKeys) {
|
|
9
11
|
const claims = req.context.xpPlacementRemovals;
|
|
10
12
|
for (const [test, documents] of claims?.tests ?? [])for (const key of documents){
|
|
@@ -38,7 +40,7 @@ export function releaseRestoredRemovalClaims(req, collection, doc, test) {
|
|
|
38
40
|
const [slug, id, view] = JSON.parse(key);
|
|
39
41
|
if (slug !== collection || id !== String(doc.id)) continue;
|
|
40
42
|
const marker = `${test.id}:${key}`;
|
|
41
|
-
if (!
|
|
43
|
+
if (!placementReader(req, collection).read(doc, 'all-locales', view).slugs.includes(test.slug)) claims.absent.add(marker);
|
|
42
44
|
else if (claims.absent.has(marker) && (claims.counts?.get(String(test.id))?.get(key) ?? 1) === 1) {
|
|
43
45
|
claims.tests.get(String(test.id)).delete(`${key}`);
|
|
44
46
|
claims.counts?.get(String(test.id))?.delete(`${key}`);
|
|
@@ -49,14 +51,36 @@ export function releaseRestoredRemovalClaims(req, collection, doc, test) {
|
|
|
49
51
|
// Separate removal-rule entry points let tests observe its IO independently
|
|
50
52
|
// of the earlier page-path and publish guards.
|
|
51
53
|
export const blockRemovalRule = {
|
|
52
|
-
async prepare (req, collection, before, after, removingPage, exec, tests) {
|
|
53
|
-
const views = removedPlacementViews(req, collection, before, after, removingPage);
|
|
54
|
+
async prepare (req, collection, before, after, removingPage, exec, tests, input = 'localized') {
|
|
55
|
+
const views = removedPlacementViews(req, collection, before, after, removingPage, input);
|
|
54
56
|
const affected = views.size ? await blockRemovalRule.discover(exec, [
|
|
55
57
|
...views.keys()
|
|
56
58
|
], tests) : [];
|
|
59
|
+
const hidden = new Set();
|
|
60
|
+
const options = req.payload.config.custom.xp;
|
|
61
|
+
const registration = puckCollections(options).find((entry)=>entry.slug === collection);
|
|
62
|
+
const rawAfter = input === 'all-locales' ? after : mergedPlacementLocales(req, collection, before, after);
|
|
63
|
+
const reader = placementReader(req, collection);
|
|
64
|
+
if (views.size && !removingPage && registration) {
|
|
65
|
+
for (const view of reader.views){
|
|
66
|
+
const previous = reader.read(before, 'all-locales', view);
|
|
67
|
+
const next = reader.read(rawAfter, 'all-locales', view);
|
|
68
|
+
if (next.editor !== 'puck') continue;
|
|
69
|
+
const visibleBefore = new Set();
|
|
70
|
+
walkVisiblePuck(previous.doc?.[registration.field], (block, visibility)=>{
|
|
71
|
+
if (!visibility.hidden && block.type === 'ExperimentSlot') visibleBefore.add(String(block.props.id));
|
|
72
|
+
});
|
|
73
|
+
walkVisiblePuck(next.doc?.[registration.field], (block, visibility)=>{
|
|
74
|
+
if (!visibility.hidden || block.type !== 'ExperimentSlot' || !visibleBefore.has(String(block.props.id))) return;
|
|
75
|
+
const slug = puckExperimentSlug(block.props.experiment);
|
|
76
|
+
if (typeof slug === 'string') hidden.add(slug);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
57
80
|
return {
|
|
58
81
|
views,
|
|
59
|
-
affected
|
|
82
|
+
affected,
|
|
83
|
+
hidden
|
|
60
84
|
};
|
|
61
85
|
},
|
|
62
86
|
async discover (exec, removed, tests) {
|
|
@@ -101,7 +125,7 @@ export const blockRemovalRule = {
|
|
|
101
125
|
}
|
|
102
126
|
return claims;
|
|
103
127
|
},
|
|
104
|
-
async check (req, current, affected, collection, id, removingPage, views, bulk) {
|
|
128
|
+
async check (req, current, affected, collection, id, removingPage, views, bulk, hidden) {
|
|
105
129
|
const transaction = await req.transactionID;
|
|
106
130
|
// Claim only after every earlier guard passed. These claims cover subsequent
|
|
107
131
|
// writes; the complete bulk selection covers siblings before any can decide.
|
|
@@ -127,7 +151,7 @@ export const blockRemovalRule = {
|
|
|
127
151
|
if (transaction == null) throw new XpNoTransactionError('Save this page with transactions on.');
|
|
128
152
|
// Bulk selection is immutable through every sibling's decision, including
|
|
129
153
|
// earlier rule refusals. afterOperation explains unrelated failed writes.
|
|
130
|
-
const message = excludedSibling ? bulk ? bulkBlockRemovalCopy(test.name) : pendingBlockRemovalCopy(test.name) : lastBlockPlacementCopy(test.name, removingPage);
|
|
154
|
+
const message = excludedSibling ? bulk ? bulkBlockRemovalCopy(test.name) : pendingBlockRemovalCopy(test.name) : hidden?.has(test.slug) ? hiddenBlockPlacementCopy(test.name) : lastBlockPlacementCopy(test.name, removingPage);
|
|
131
155
|
if (bulk && excludedSibling) bulk.refusals.set(message, pendingBlockRemovalCopy(test.name));
|
|
132
156
|
throw new XpRefusal('locked-placement', message, {
|
|
133
157
|
experimentId: test.id
|