@delmaredigital/payload-experiments 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocks/placementLocale.d.ts +14 -0
- package/dist/blocks/placementLocale.js +80 -13
- package/dist/blocks/placementPublication.d.ts +14 -0
- package/dist/blocks/placementPublication.js +24 -0
- package/dist/db/adapter.d.ts +1 -0
- package/dist/db/adapter.js +3 -0
- package/dist/db/appends.d.ts +2 -1
- package/dist/db/appends.js +2 -1
- package/dist/db/bulkPlacementRemoval.d.ts +5 -0
- package/dist/db/bulkPlacementRemoval.js +7 -2
- package/dist/db/pageBindings.d.ts +2 -2
- package/dist/db/pageBindings.js +3 -3
- package/dist/db/placements.d.ts +6 -1
- package/dist/db/placements.js +26 -0
- package/dist/endpoints/duplicateOriginal.d.ts +1 -0
- package/dist/hooks/blockRemovalRule.d.ts +1 -1
- package/dist/hooks/blockRemovalRule.js +5 -4
- package/dist/hooks/pageGuard.d.ts +7 -1
- package/dist/hooks/pageGuard.js +176 -3
- package/dist/hooks/puckNestedTests.d.ts +1 -1
- package/dist/hooks/puckNestedTests.js +3 -1
- package/dist/onInit.js +0 -5
- package/dist/server/recordContentChange.d.ts +1 -1
- package/dist/server/recordContentChange.js +42 -20
- package/dist/transitions/decide.js +5 -2
- package/dist/transitions/placementInteractions.d.ts +7 -2
- package/dist/transitions/placementInteractions.js +8 -6
- package/dist/transitions/placements.d.ts +4 -3
- package/dist/transitions/placements.js +28 -14
- package/dist/transitions/start.js +3 -1
- package/package.json +2 -2
|
@@ -10,6 +10,8 @@ import { isDeepStrictEqual } from 'node:util';
|
|
|
10
10
|
import { hasLocalizedFields } from './contentFields.js';
|
|
11
11
|
import { localeRequest, placementReader } from '../blocks/placementLocale.js';
|
|
12
12
|
import { puckCollections as normalisePuckCollections } from '../options.js';
|
|
13
|
+
import { publishedInLocale, usesLocalizedPublication } from '../blocks/placementPublication.js';
|
|
14
|
+
import { storedPlacementStatuses } from '../db/placements.js';
|
|
13
15
|
const slots = [
|
|
14
16
|
'control',
|
|
15
17
|
'variantA',
|
|
@@ -18,6 +20,8 @@ const slots = [
|
|
|
18
20
|
];
|
|
19
21
|
async function placementDocuments(req, query, readAll) {
|
|
20
22
|
// §7.8: page guards, visitor impact and system Start need all placements to check the visitor surface.
|
|
23
|
+
// For draft:false, the adapter hydrates _status from the main locale rows
|
|
24
|
+
// alongside the localized fields. Draft versions are read separately.
|
|
21
25
|
if (readAll) return req.payload.find({
|
|
22
26
|
...query,
|
|
23
27
|
req,
|
|
@@ -46,7 +50,7 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
|
|
|
46
50
|
}
|
|
47
51
|
/** Published rows only, one pass per collection across both editor registrations.
|
|
48
52
|
* The exclusion predicate reads live transaction claims after each awaited page.
|
|
49
|
-
*/ export async function hasOtherPublishedBlockPlacement(req, options, slug, excluded) {
|
|
53
|
+
*/ export async function hasOtherPublishedBlockPlacement(req, options, slug, excluded, bulk) {
|
|
50
54
|
const scanReq = localeRequest(req, {
|
|
51
55
|
locale: req.payload.config.localization ? 'all' : req.locale ?? '',
|
|
52
56
|
fallbackLocale: false
|
|
@@ -56,6 +60,7 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
|
|
|
56
60
|
...(options.blocks?.collections ?? []).map((entry)=>entry.slug)
|
|
57
61
|
]);
|
|
58
62
|
for (const collection of collections){
|
|
63
|
+
const localized = usesLocalizedPublication(req, collection);
|
|
59
64
|
const drafts = req.payload.config.collections?.some((c)=>c.slug === collection && c.versions && c.versions.drafts);
|
|
60
65
|
const reader = placementReader(req, collection, options);
|
|
61
66
|
let page = 1;
|
|
@@ -71,7 +76,7 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
|
|
|
71
76
|
locale: 'all',
|
|
72
77
|
fallbackLocale: false
|
|
73
78
|
} : {},
|
|
74
|
-
...drafts ? {
|
|
79
|
+
...drafts && !localized ? {
|
|
75
80
|
where: {
|
|
76
81
|
_status: {
|
|
77
82
|
equals: 'published'
|
|
@@ -79,7 +84,10 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
|
|
|
79
84
|
}
|
|
80
85
|
} : {}
|
|
81
86
|
}, true);
|
|
82
|
-
|
|
87
|
+
const statuses = localized && bulk?.change?.collection === collection ? await storedPlacementStatuses(req, collection, result.docs.map((doc)=>doc.id)) : undefined;
|
|
88
|
+
if (result.docs.some((doc)=>doc._status !== 'draft' && doc.deletedAt == null && reader.views.some((view)=>reader.isPublished(doc, view) && (!statuses || publishedInLocale({
|
|
89
|
+
_status: statuses.get(String(doc.id))
|
|
90
|
+
}, view.locale)) && reader.read(doc, 'all-locales', view).slugs.includes(slug) && !excluded(collection, doc.id, view, doc)))) return true;
|
|
83
91
|
if (!result.hasNextPage) break;
|
|
84
92
|
page++;
|
|
85
93
|
}
|
|
@@ -98,6 +106,7 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
|
|
|
98
106
|
...puck,
|
|
99
107
|
...blocks
|
|
100
108
|
].map((entry)=>entry.slug))){
|
|
109
|
+
const localized = usesLocalizedPublication(req, collection);
|
|
101
110
|
const drafts = req.payload.config.collections?.some((c)=>c.slug === collection && c.versions && c.versions.drafts);
|
|
102
111
|
const reader = placementReader(req, collection, options);
|
|
103
112
|
let page = 1;
|
|
@@ -114,7 +123,7 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
|
|
|
114
123
|
locale: 'all',
|
|
115
124
|
fallbackLocale: false
|
|
116
125
|
} : {},
|
|
117
|
-
...drafts ? {
|
|
126
|
+
...drafts && !localized ? {
|
|
118
127
|
where: {
|
|
119
128
|
_status: {
|
|
120
129
|
equals: 'published'
|
|
@@ -127,6 +136,7 @@ function changedDocuments(docs, change, collection, draft, page, draftsEnabled)
|
|
|
127
136
|
for (const raw of result.docs){
|
|
128
137
|
if (raw._status === 'draft' || raw.deletedAt != null) continue;
|
|
129
138
|
for (const view of reader.views){
|
|
139
|
+
if (!reader.isPublished(raw, view)) continue;
|
|
130
140
|
const placement = reader.read(raw, 'all-locales', view);
|
|
131
141
|
const doc = placement.doc;
|
|
132
142
|
const add = (contents, editor)=>placements.push({
|
|
@@ -204,6 +214,7 @@ export async function scanBlockPlacements(req, args) {
|
|
|
204
214
|
collections: puckCollections
|
|
205
215
|
}
|
|
206
216
|
})){
|
|
217
|
+
const localizedStatus = usesLocalizedPublication(req, collection);
|
|
207
218
|
const reader = placementReader(req, collection, {
|
|
208
219
|
puck: {
|
|
209
220
|
enabled: true,
|
|
@@ -217,7 +228,8 @@ export async function scanBlockPlacements(req, args) {
|
|
|
217
228
|
const publishedIds = new Set();
|
|
218
229
|
const publishedSlugs = new Map();
|
|
219
230
|
const draftsEnabled = req.payload.config.collections?.some((config)=>config.slug === collection && config.versions && config.versions.drafts);
|
|
220
|
-
|
|
231
|
+
const publishedOnly = args.publishedOnly === true || args.publishedOnly === 'localized' && localizedStatus;
|
|
232
|
+
for (const draft of publishedOnly ? [
|
|
221
233
|
false
|
|
222
234
|
] : [
|
|
223
235
|
false,
|
|
@@ -238,7 +250,7 @@ export async function scanBlockPlacements(req, args) {
|
|
|
238
250
|
locale: 'all',
|
|
239
251
|
fallbackLocale: false
|
|
240
252
|
} : {},
|
|
241
|
-
...!draft && draftsEnabled ? {
|
|
253
|
+
...!draft && draftsEnabled && !localizedStatus ? {
|
|
242
254
|
where: {
|
|
243
255
|
_status: {
|
|
244
256
|
equals: 'published'
|
|
@@ -252,8 +264,8 @@ export async function scanBlockPlacements(req, args) {
|
|
|
252
264
|
String(doc.id),
|
|
253
265
|
view.locale
|
|
254
266
|
]);
|
|
255
|
-
if (!draft && doc._status === 'draft') continue;
|
|
256
|
-
if (draft && doc._status !== 'draft' && publishedIds.has(documentKey)) continue;
|
|
267
|
+
if (!draft && (doc._status === 'draft' || !reader.isPublished(localized, view))) continue;
|
|
268
|
+
if (draft && (localizedStatus ? reader.isPublished(localized, view) : doc._status !== 'draft') && publishedIds.has(documentKey)) continue;
|
|
257
269
|
if (!draft) {
|
|
258
270
|
editors.set(documentKey, reader.read(doc, 'localized').editor);
|
|
259
271
|
publishedIds.add(documentKey);
|
|
@@ -299,7 +311,7 @@ export async function scanBlockPlacements(req, args) {
|
|
|
299
311
|
locale: view.locale
|
|
300
312
|
} : {},
|
|
301
313
|
title: String(doc.title ?? doc.name ?? doc.id),
|
|
302
|
-
published: !draft || doc._status === 'published',
|
|
314
|
+
published: !draft || !localizedStatus && doc._status === 'published',
|
|
303
315
|
...publishedSlugs.has(documentKey) ? {
|
|
304
316
|
slug: publishedSlugs.get(documentKey)
|
|
305
317
|
} : {},
|
|
@@ -343,6 +355,7 @@ export async function scanBlockPlacements(req, args) {
|
|
|
343
355
|
}
|
|
344
356
|
for (const registration of args.blocksCollections){
|
|
345
357
|
const { slug: collection, field } = registration;
|
|
358
|
+
const localizedStatus = usesLocalizedPublication(req, collection);
|
|
346
359
|
const reader = placementReader(req, collection, {
|
|
347
360
|
puck: {
|
|
348
361
|
enabled: true,
|
|
@@ -354,7 +367,8 @@ export async function scanBlockPlacements(req, args) {
|
|
|
354
367
|
});
|
|
355
368
|
const published = new Map();
|
|
356
369
|
const draftsEnabled = req.payload.config.collections?.some((c)=>c.slug === collection && c.versions && c.versions.drafts);
|
|
357
|
-
|
|
370
|
+
const publishedOnly = args.publishedOnly === true || args.publishedOnly === 'localized' && localizedStatus;
|
|
371
|
+
for (const draft of publishedOnly ? [
|
|
358
372
|
false
|
|
359
373
|
] : [
|
|
360
374
|
false,
|
|
@@ -375,7 +389,7 @@ export async function scanBlockPlacements(req, args) {
|
|
|
375
389
|
locale: 'all',
|
|
376
390
|
fallbackLocale: false
|
|
377
391
|
} : {},
|
|
378
|
-
...!draft && draftsEnabled ? {
|
|
392
|
+
...!draft && draftsEnabled && !localizedStatus ? {
|
|
379
393
|
where: {
|
|
380
394
|
_status: {
|
|
381
395
|
equals: 'published'
|
|
@@ -389,9 +403,9 @@ export async function scanBlockPlacements(req, args) {
|
|
|
389
403
|
String(doc.id),
|
|
390
404
|
view.locale
|
|
391
405
|
]);
|
|
392
|
-
if (!draft && doc._status === 'draft') continue;
|
|
406
|
+
if (!draft && (doc._status === 'draft' || !reader.isPublished(localized, view))) continue;
|
|
393
407
|
if (!draft) published.set(documentKey, doc);
|
|
394
|
-
else if (doc._status !== 'draft' && published.has(documentKey)) continue;
|
|
408
|
+
else if ((localizedStatus ? reader.isPublished(localized, view) : doc._status !== 'draft') && published.has(documentKey)) continue;
|
|
395
409
|
const baseline = published.get(documentKey) ?? doc;
|
|
396
410
|
if (reader.read(baseline, 'localized').editor !== 'blocks') continue;
|
|
397
411
|
const raw = args.compareVersions && !draft && hostBlocks(doc[field]).some((block)=>block.blockType === (registration.blockSlug ?? EXPERIMENT_BLOCK_SLUG) && typeof block.experiment === 'string' && slugs.has(block.experiment)) ? reader.read(await comparison(collection, doc.id), 'all-locales', view).doc : undefined;
|
|
@@ -409,7 +423,7 @@ export async function scanBlockPlacements(req, args) {
|
|
|
409
423
|
locale: view.locale
|
|
410
424
|
} : {},
|
|
411
425
|
title: String(doc.title ?? doc.name ?? doc.id),
|
|
412
|
-
published: !draft || doc._status === 'published',
|
|
426
|
+
published: !draft || !localizedStatus && doc._status === 'published',
|
|
413
427
|
...typeof baseline.slug === 'string' ? {
|
|
414
428
|
slug: baseline.slug
|
|
415
429
|
} : {},
|
|
@@ -238,7 +238,9 @@ export async function start(req, { experimentId, options, phase: expectedPhase,
|
|
|
238
238
|
const controlLabel = current.arms.find((arm)=>arm.kind === 'control')?.label;
|
|
239
239
|
let placementDocs;
|
|
240
240
|
if (current.kind === 'block') {
|
|
241
|
-
const rescan = await lockAndRescanPlacements(req, exec, options, current, input.placements ?? [],
|
|
241
|
+
const rescan = await lockAndRescanPlacements(req, exec, options, current, input.placements ?? [], {
|
|
242
|
+
system
|
|
243
|
+
});
|
|
242
244
|
placementDocs = rescan.docs;
|
|
243
245
|
const failure = checkStart({
|
|
244
246
|
...input,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delmaredigital/payload-experiments",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "No-code A/B testing for Payload CMS and Next.js: block, page and flag experiments with holdouts, layers, exposure logging and honest statistics inside the admin — no vendor",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
"bugs": {
|
|
126
126
|
"url": "https://github.com/delmaredigital/payload-experiments/issues"
|
|
127
127
|
},
|
|
128
|
-
"homepage": "https://plugins.delmaredigital.com/
|
|
128
|
+
"homepage": "https://plugins.delmaredigital.com/experiments",
|
|
129
129
|
"devDependencies": {
|
|
130
130
|
"@delmaredigital/payload-puck": "0.12.5",
|
|
131
131
|
"payload": "^3.90.2",
|