@delmaredigital/payload-experiments 0.4.0-rc.6 → 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/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/PageWizard.js +1 -0
- package/dist/admin/surface/newTest/newTest.css +1 -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 +3 -2
- package/dist/blocks/placementLanguages.d.ts +7 -0
- package/dist/blocks/placementLanguages.js +27 -0
- package/dist/blocks/placementLocale.d.ts +21 -7
- package/dist/blocks/placementLocale.js +218 -67
- 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 +38 -31
- package/dist/hooks/blockRemovalRule.d.ts +2 -2
- package/dist/hooks/blockRemovalRule.js +16 -14
- package/dist/hooks/pageGuard.d.ts +3 -0
- package/dist/hooks/pageGuard.js +33 -23
- 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.js +40 -37
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
- package/dist/puck/editor/ConfigureTestDrawer.js +4 -2
- package/dist/puck/editor/ExperimentSlotEditor.js +135 -104
- package/dist/puck/editor/LeftoverVersions.d.ts +1 -1
- package/dist/puck/editor/LeftoverVersions.js +40 -43
- package/dist/puck/editor/VersionBuilder.d.ts +18 -1
- package/dist/puck/editor/VersionBuilder.js +217 -39
- package/dist/puck/editor/blockClipboard.d.ts +16 -0
- package/dist/puck/editor/blockClipboard.js +20 -0
- package/dist/puck/editor/copy.d.ts +8 -1
- package/dist/puck/editor/copy.js +9 -1
- package/dist/puck/editor/editor.chrome.css +117 -3
- package/dist/puck/editor/editor.css +130 -8
- package/dist/puck/editor/editor.model.d.ts +2 -1
- package/dist/puck/editor/editor.model.js +2 -2
- package/dist/puck/editor/localPlacements.d.ts +1 -0
- package/dist/puck/editor/localPlacements.js +12 -0
- package/dist/puck/editor/placementsCache.d.ts +18 -12
- package/dist/puck/editor/placementsCache.js +52 -47
- 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 +2 -3
- package/dist/puck/visibility.js +11 -7
- package/dist/server/recordContentChange.js +34 -19
- package/dist/server/resolveExperimentData.js +2 -2
- 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 +1 -1
- package/dist/testSurface/copy/readiness.js +1 -1
- package/dist/testSurface/copy/testPage.d.ts +21 -0
- package/dist/testSurface/copy/testPage.js +21 -0
- 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/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/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/TestSurface.js +29 -9
- 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 +5 -4
- 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 +219 -56
- 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/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 +9 -9
- package/dist/ui/SelectControl.d.ts +33 -0
- package/dist/ui/SelectControl.js +504 -0
- package/dist/ui/ui.css +13 -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,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 {
|
|
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
|
-
|
|
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
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
if (!
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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.slot ?? arm.key), byArm.get(arm.key), '', labels);
|
|
148
139
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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);
|
|
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>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { puckExperimentSlug } from '../puck/experimentSlug.js';
|
|
1
2
|
import { walkVisiblePuck } from '../puck/visibility.js';
|
|
2
|
-
import {
|
|
3
|
+
import { puckCollections } from '../options.js';
|
|
3
4
|
import { removableBlockTests } from '../db/placements.js';
|
|
4
5
|
import { XpNoTransactionError, XpRefusal } from '../errors.js';
|
|
5
6
|
import { lastBlockPlacementCopy, hiddenBlockPlacementCopy, pendingBlockRemovalCopy, bulkBlockRemovalCopy } from '../testSurface/copy/readiness.js';
|
|
6
7
|
import { hasOtherPublishedBlockPlacement } from '../transitions/placements.js';
|
|
7
8
|
import { bulkRemoves } from '../db/bulkPlacementRemoval.js';
|
|
8
|
-
import {
|
|
9
|
-
import { placementSlugs } from '../blocks/bindings.js';
|
|
9
|
+
import { placementReader, removedPlacementViews, placementDocumentKey, mergedPlacementLocales } from '../blocks/placementLocale.js';
|
|
10
10
|
export function releaseRemovalClaim(req, collection, id, ownKeys) {
|
|
11
11
|
const claims = req.context.xpPlacementRemovals;
|
|
12
12
|
for (const [test, documents] of claims?.tests ?? [])for (const key of documents){
|
|
@@ -40,7 +40,7 @@ export function releaseRestoredRemovalClaims(req, collection, doc, test) {
|
|
|
40
40
|
const [slug, id, view] = JSON.parse(key);
|
|
41
41
|
if (slug !== collection || id !== String(doc.id)) continue;
|
|
42
42
|
const marker = `${test.id}:${key}`;
|
|
43
|
-
if (!
|
|
43
|
+
if (!placementReader(req, collection).read(doc, 'all-locales', view).slugs.includes(test.slug)) claims.absent.add(marker);
|
|
44
44
|
else if (claims.absent.has(marker) && (claims.counts?.get(String(test.id))?.get(key) ?? 1) === 1) {
|
|
45
45
|
claims.tests.get(String(test.id)).delete(`${key}`);
|
|
46
46
|
claims.counts?.get(String(test.id))?.delete(`${key}`);
|
|
@@ -51,26 +51,28 @@ export function releaseRestoredRemovalClaims(req, collection, doc, test) {
|
|
|
51
51
|
// Separate removal-rule entry points let tests observe its IO independently
|
|
52
52
|
// of the earlier page-path and publish guards.
|
|
53
53
|
export const blockRemovalRule = {
|
|
54
|
-
async prepare (req, collection, before, after, removingPage, exec, tests) {
|
|
55
|
-
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);
|
|
56
56
|
const affected = views.size ? await blockRemovalRule.discover(exec, [
|
|
57
57
|
...views.keys()
|
|
58
58
|
], tests) : [];
|
|
59
59
|
const hidden = new Set();
|
|
60
60
|
const options = req.payload.config.custom.xp;
|
|
61
61
|
const registration = puckCollections(options).find((entry)=>entry.slug === collection);
|
|
62
|
-
const rawAfter = mergedPlacementLocales(req, collection, before, after);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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;
|
|
66
69
|
const visibleBefore = new Set();
|
|
67
|
-
walkVisiblePuck(
|
|
70
|
+
walkVisiblePuck(previous.doc?.[registration.field], (block, visibility)=>{
|
|
68
71
|
if (!visibility.hidden && block.type === 'ExperimentSlot') visibleBefore.add(String(block.props.id));
|
|
69
72
|
});
|
|
70
|
-
walkVisiblePuck(
|
|
73
|
+
walkVisiblePuck(next.doc?.[registration.field], (block, visibility)=>{
|
|
71
74
|
if (!visibility.hidden || block.type !== 'ExperimentSlot' || !visibleBefore.has(String(block.props.id))) return;
|
|
72
|
-
const
|
|
73
|
-
const slug = typeof ref === 'string' ? ref : ref && typeof ref === 'object' && 'slug' in ref ? ref.slug : undefined;
|
|
75
|
+
const slug = puckExperimentSlug(block.props.experiment);
|
|
74
76
|
if (typeof slug === 'string') hidden.add(slug);
|
|
75
77
|
});
|
|
76
78
|
}
|