@delmaredigital/payload-experiments 0.5.3 → 0.20.0-next.2
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/README.md +15 -4
- package/dist/admin/blocks/formApi.js +17 -15
- package/dist/admin/blocks/model.js +1 -1
- package/dist/admin/theme.css +43 -47
- package/dist/admin/views/renderCollectionList.js +1 -1
- package/dist/blocks/formState.d.ts +1 -1
- package/dist/blocks/formState.js +2 -5
- package/dist/blocks/placementLocale.js +10 -13
- package/dist/blocks/placementPublication.d.ts +1 -1
- package/dist/blocks/placementPublication.js +6 -5
- package/dist/collections/access.d.ts +2 -0
- package/dist/collections/access.js +2 -0
- package/dist/collections/cohortMembers.js +1 -0
- package/dist/collections/events.js +1 -0
- package/dist/collections/experiments/config.js +2 -1
- package/dist/collections/experiments/createDefaults.js +4 -3
- package/dist/collections/experiments/flagControlParams.js +2 -1
- package/dist/collections/experiments/lockHook.js +6 -4
- package/dist/collections/identities.js +1 -0
- package/dist/collections/layers.js +1 -0
- package/dist/collections/metrics.js +1 -0
- package/dist/collections/phases.js +1 -0
- package/dist/collections/snapshots.js +1 -0
- package/dist/db/appends.d.ts +4 -7
- package/dist/db/appends.js +5 -12
- package/dist/db/clickGoals.js +5 -2
- package/dist/db/executor.d.ts +1 -5
- package/dist/db/names.d.ts +1 -1
- package/dist/db/names.js +1 -1
- package/dist/db/pageContent.d.ts +1 -1
- package/dist/db/pageContent.js +1 -1
- package/dist/endpoints/pages.js +12 -7
- package/dist/globals/state.js +2 -0
- package/dist/goals/fairness.js +4 -1
- package/dist/hooks/pageGuard.d.ts +0 -3
- package/dist/hooks/pageGuard.js +14 -12
- package/dist/payloadCompat.d.ts +8 -0
- package/dist/payloadCompat.js +16 -0
- package/dist/puck/editor/editor.css +103 -103
- package/dist/server/previewDraft.js +0 -1
- package/dist/server/recordContentChange.d.ts +1 -1
- package/dist/server/recordContentChange.js +11 -15
- package/dist/server/runResults.d.ts +1 -1
- package/dist/server/runResults.js +1 -1
- package/dist/server/startExperiment.d.ts +1 -1
- package/dist/server/startExperiment.js +1 -1
- package/dist/transitions/contentFields.d.ts +3 -6
- package/dist/transitions/contentFields.js +3 -9
- package/dist/transitions/makeContent.js +34 -16
- package/dist/transitions/pageAddress.d.ts +3 -1
- package/dist/transitions/pageAddress.js +33 -3
- package/dist/ui/accent.d.ts +5 -1
- package/dist/ui/accent.js +6 -5
- package/package.json +11 -11
|
@@ -10,7 +10,6 @@ import { appendContentChange, contentChangeSavepoint, previousPublishedContent,
|
|
|
10
10
|
import { txExecutor } from '../db/executor.js';
|
|
11
11
|
import { pageContentBindings } from '../db/pageBindings.js';
|
|
12
12
|
import { sortLockKeys } from '../db/locks.js';
|
|
13
|
-
import { writesAllPublicationLocales } from '../hooks/pageGuard.js';
|
|
14
13
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
15
14
|
import { comparableContent } from '../transitions/pageVersions.js';
|
|
16
15
|
import { puckCollections } from '../options.js';
|
|
@@ -67,7 +66,9 @@ function bindings(data, puck) {
|
|
|
67
66
|
return found;
|
|
68
67
|
}
|
|
69
68
|
const baselineKey = (collection, id)=>`${collection}:${id}`;
|
|
70
|
-
/** Paired raw beforeChange capture: previousDoc may be an autosaved draft. */ export async function capturePublishedContent({ req, collection, originalDoc, operation
|
|
69
|
+
/** Paired raw beforeChange capture: previousDoc may be an autosaved draft. */ export async function capturePublishedContent({ req, collection, originalDoc, operation }) {
|
|
70
|
+
// Payload 4 validation runs beforeChange on the caller's transaction; it writes nothing, so there is nothing to audit.
|
|
71
|
+
if (operation === 'validate') return;
|
|
71
72
|
if (await req.transactionID == null) {
|
|
72
73
|
req.payload.logger?.debug('[payload-experiments] contentChanges baseline skipped without a transaction');
|
|
73
74
|
return;
|
|
@@ -78,14 +79,10 @@ const baselineKey = (collection, id)=>`${collection}:${id}`;
|
|
|
78
79
|
delete baselines[key];
|
|
79
80
|
const audit = await contentChangeSavepoint(txExecutor(req), async ()=>operation === 'create' ? undefined : collection.versions && collection.versions.drafts ? previousPublishedContent(req, collection.slug, id) : storedContent(req, collection.slug, id));
|
|
80
81
|
if (!audit.ok) throw audit.error;
|
|
81
|
-
// Payload 3 passes the original status map to beforeChange on Publish All,
|
|
82
|
-
// including on host collections that install the audit without the guard.
|
|
83
|
-
const publishAllLocales = data?._status === 'published' && object(originalDoc?._status);
|
|
84
82
|
baselines[key] = {
|
|
85
83
|
collection: collection.slug,
|
|
86
84
|
id,
|
|
87
|
-
doc: audit.result
|
|
88
|
-
publishAllLocales
|
|
85
|
+
doc: audit.result
|
|
89
86
|
};
|
|
90
87
|
}
|
|
91
88
|
/** Publish-only host helper. Audit failures are logged after savepoint recovery. */ export async function recordContentChange(args) {
|
|
@@ -104,14 +101,13 @@ const baselineKey = (collection, id)=>`${collection}:${id}`;
|
|
|
104
101
|
async function auditContentChange({ doc, previousDoc, req, collection }) {
|
|
105
102
|
const drafts = Boolean(collection.versions && collection.versions.drafts);
|
|
106
103
|
const localizedStatus = usesLocalizedPublication(req, collection.slug, collection);
|
|
107
|
-
|
|
104
|
+
// For localized drafts, the hook result may be a projected version. The main
|
|
105
|
+
// row is authoritative even when a write returns 'draft' in the requested locale.
|
|
106
|
+
if (drafts && !localizedStatus && doc._status !== 'published') return;
|
|
108
107
|
const baselines = req.context.xpPublishedContent;
|
|
109
108
|
const creating = previousDoc?.id == null;
|
|
110
109
|
const key = baselineKey(collection.slug, creating ? '__create__' : doc.id);
|
|
111
110
|
const baseline = baselines?.[key];
|
|
112
|
-
// Restore can supply the raw previous version alongside a projected result.
|
|
113
|
-
const allLocales = localizedStatus && (statusMap || req.locale === 'all' || baseline?.publishAllLocales || object(previousDoc?._status) || creating && doc._status === 'published' || writesAllPublicationLocales(req, collection.slug));
|
|
114
|
-
if (drafts && !allLocales && doc._status !== 'published') return;
|
|
115
111
|
if (await req.transactionID == null) {
|
|
116
112
|
req.payload.logger?.debug('[payload-experiments] contentChanges skipped without a transaction');
|
|
117
113
|
return;
|
|
@@ -181,15 +177,15 @@ async function auditContentChange({ doc, previousDoc, req, collection }) {
|
|
|
181
177
|
}
|
|
182
178
|
const previous = object(beforeRow) ? beforeRow : undefined;
|
|
183
179
|
const current = object(afterRow) ? afterRow : undefined;
|
|
184
|
-
const locale = req.locale || (localization ? localization.defaultLocale : '');
|
|
185
180
|
const contentViews = (input)=>{
|
|
186
181
|
const views = input === 'all-locales' ? reader.documentViews : [
|
|
187
182
|
undefined
|
|
188
183
|
];
|
|
189
184
|
return views.flatMap((view)=>{
|
|
190
|
-
//
|
|
191
|
-
//
|
|
192
|
-
|
|
185
|
+
// A single-locale publish can change shared fields and fallback content
|
|
186
|
+
// in other locales. Use the main row's status, since the saved version
|
|
187
|
+
// may carry draft data for those locales.
|
|
188
|
+
if (localizedStatus && view && !publishedInLocale(current, view.locale)) return [];
|
|
193
189
|
const before = localizedStatus && view && !publishedInLocale(previous, view.locale) ? undefined : previous;
|
|
194
190
|
return [
|
|
195
191
|
[
|
|
@@ -7,7 +7,7 @@ import { asymmetricGoal, goalContent, goalPlacementDetail, LEGACY_FAIRNESS } fro
|
|
|
7
7
|
import { XpAnalysisError } from '../errors.js';
|
|
8
8
|
import { canonicalHealth, cohortNoExposures, mergePageHealth, rapidBrowserEvents } from '../results/health.js';
|
|
9
9
|
import { safeError } from '../log.js';
|
|
10
|
-
import { createLocalReq } from '
|
|
10
|
+
import { createLocalReq } from '../payloadCompat.js';
|
|
11
11
|
import { dueScheduledStops, resultsCandidates, resultsExecutor, writeSnapshots } from '../db/snapshots.js';
|
|
12
12
|
import { DAY_MS } from '../schedule/roundTime.js';
|
|
13
13
|
import { sweepEvents } from '../db/sweep.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Payload, PayloadRequest } from 'payload';
|
|
2
2
|
import type { DocId } from '../types/contracts.js';
|
|
3
3
|
import type { StartExperimentResult } from '../types/endpoints.js';
|
|
4
4
|
/** Start a test from trusted host code. Call this after your own transaction commits.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createLocalReq } from '
|
|
1
|
+
import { createLocalReq } from '../payloadCompat.js';
|
|
2
2
|
import { experimentId } from '../endpoints/routeId.js';
|
|
3
3
|
import { XpRefusal, XpStartTransactionOpen } from '../errors.js';
|
|
4
4
|
import { xpOptionsFromReq } from '../options/fromReq.js';
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type: 'blocks';
|
|
5
|
-
}>, blocks?: Block[]): Block[];
|
|
6
|
-
/** Any localized data makes a full-document publish unsafe in Payload 3.90. */
|
|
1
|
+
import type { Field, SanitizedConfig } from 'payload';
|
|
2
|
+
export { resolveContentBlocks as contentBlocks } from '../payloadCompat.js';
|
|
3
|
+
/** Any localized data makes a full-document publish unsafe when rebuilding host documents. */
|
|
7
4
|
export declare function hasLocalizedFields(fields: Field[], config: Pick<SanitizedConfig, 'localization' | 'blocks'>, seen?: Set<Field>): boolean;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
...(field.blockReferences ?? []).flatMap((reference)=>typeof reference === 'string' ? blocks.filter((block)=>block.slug === reference) : [
|
|
5
|
-
reference
|
|
6
|
-
])
|
|
7
|
-
];
|
|
8
|
-
}
|
|
9
|
-
/** Any localized data makes a full-document publish unsafe in Payload 3.90. */ export function hasLocalizedFields(fields, config, seen = new Set()) {
|
|
1
|
+
export { resolveContentBlocks as contentBlocks } from '../payloadCompat.js';
|
|
2
|
+
import { resolveContentBlocks as contentBlocks } from '../payloadCompat.js';
|
|
3
|
+
/** Any localized data makes a full-document publish unsafe when rebuilding host documents. */ export function hasLocalizedFields(fields, config, seen = new Set()) {
|
|
10
4
|
if (!config.localization) return false;
|
|
11
5
|
const blocks = config.blocks ?? [];
|
|
12
6
|
return fields.some((field)=>{
|
|
@@ -2,7 +2,7 @@ import { requireCurrentRound } from './phaseRecord.js';
|
|
|
2
2
|
import { placementReader } from '../blocks/placementLocale.js';
|
|
3
3
|
import { puckExperimentSlug } from '../puck/experimentSlug.js';
|
|
4
4
|
import { puckVisibility, hiddenOnSizes, visibilitySizes } from '../puck/visibility.js';
|
|
5
|
-
import { Forbidden, NotFound, ValidationError, Locked, commitTransaction, killTransaction } from 'payload';
|
|
5
|
+
import { createCreatedByField, createUpdatedByField, Forbidden, NotFound, ValidationError, Locked, commitTransaction, killTransaction } from 'payload';
|
|
6
6
|
import { initTransitionTransaction } from '../db/adapter.js';
|
|
7
7
|
import { latestDraftContent, publishedContent as readPublishedContent } from '../db/publishedContent.js';
|
|
8
8
|
import { EXPERIMENT_BLOCK_SLUG, hostBlocks, slotBlocks } from '../blocks/model.js';
|
|
@@ -72,21 +72,35 @@ const object = (value)=>value !== null && typeof value === 'object' && !Array.is
|
|
|
72
72
|
]));
|
|
73
73
|
return value;
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
// Public v4 field factories retain their stamping hooks when hosts customize
|
|
76
|
+
// authorship. Match those hooks rather than exempting arbitrary same-name fields.
|
|
77
|
+
const authorshipHooks = {
|
|
78
|
+
createdBy: createCreatedByField().hooks?.beforeChange?.[0],
|
|
79
|
+
updatedBy: createUpdatedByField().hooks?.beforeChange?.[0]
|
|
80
|
+
};
|
|
81
|
+
function managedAuthorship(field, collection) {
|
|
82
|
+
if (field.type !== 'relationship' || field.name !== 'createdBy' && field.name !== 'updatedBy' || !collection.authorship?.[field.name]) return false;
|
|
83
|
+
const hook = authorshipHooks[field.name];
|
|
84
|
+
return Boolean(hook && field.hooks?.beforeChange?.includes(hook));
|
|
85
|
+
}
|
|
86
|
+
const contentMetadata = new Set([
|
|
78
87
|
'id',
|
|
79
88
|
'createdAt',
|
|
80
89
|
'updatedAt',
|
|
81
90
|
'_isLocked',
|
|
82
91
|
'_userEditing'
|
|
83
92
|
]);
|
|
84
|
-
|
|
93
|
+
/** Payload update merges omissions from the latest version even on publish.
|
|
94
|
+
* Restore each captured document's fields, omitting API/adapter metadata.
|
|
95
|
+
*/ function contentData(doc, field, content, collection, blocks = []) {
|
|
85
96
|
const data = {
|
|
86
97
|
...Object.fromEntries(Object.entries(doc).filter(([key])=>!contentMetadata.has(key))),
|
|
87
98
|
[field]: content
|
|
88
99
|
};
|
|
89
|
-
|
|
100
|
+
const result = fillContentFields(collection.fields, data, blocks);
|
|
101
|
+
// Omit after null-filling so Payload stamps managed v4 authorship itself.
|
|
102
|
+
for (const field of collection.fields)if (managedAuthorship(field, collection)) delete result[field.name];
|
|
103
|
+
return result;
|
|
90
104
|
}
|
|
91
105
|
/** Adapter reads can omit empty fields (notably single polymorphic links).
|
|
92
106
|
* Make every stored value explicit so Payload cannot fill it from the other version.
|
|
@@ -129,15 +143,17 @@ function contentData(doc, field, content, fields, blocks = []) {
|
|
|
129
143
|
* refuse when that substitution would change the proposed value (KI-1).
|
|
130
144
|
*/ // Payload beforeChange/getExistingRowDoc.js matches array/block rows by ID.
|
|
131
145
|
const existingRow = (row, original)=>object(row) && row.id && Array.isArray(original) ? original.find((value)=>object(value) && value.id === row.id) ?? {} : {};
|
|
132
|
-
async function fieldRefusal(fields, req, doc, operation = 'update', data = doc, siblingData = data, blockData, originalSibling = fillContentFields(fields, doc, req.payload.config.blocks)) {
|
|
146
|
+
async function fieldRefusal(fields, collection, req, doc, operation = 'update', data = doc, siblingData = data, blockData, originalSibling = fillContentFields(fields, doc, req.payload.config.blocks)) {
|
|
133
147
|
for (const field of fields){
|
|
134
148
|
if (field.type === 'ui' || field.type === 'join' || 'virtual' in field && field.virtual) continue;
|
|
135
|
-
|
|
149
|
+
const stamped = fields === collection.fields && managedAuthorship(field, collection);
|
|
150
|
+
if (!stamped && 'name' in field && ![
|
|
136
151
|
'id',
|
|
137
152
|
'createdAt',
|
|
138
153
|
'updatedAt'
|
|
139
154
|
].includes(field.name) && JSON.stringify(siblingData[field.name] ?? null) !== JSON.stringify(originalSibling[field.name] ?? null) && 'access' in field && field.access?.[operation] && !await field.access[operation]({
|
|
140
155
|
id: doc.id,
|
|
156
|
+
collection,
|
|
141
157
|
req,
|
|
142
158
|
doc,
|
|
143
159
|
data,
|
|
@@ -150,6 +166,7 @@ async function fieldRefusal(fields, req, doc, operation = 'update', data = doc,
|
|
|
150
166
|
if ('tabs' in field) for (const tab of field.tabs){
|
|
151
167
|
if ('name' in tab && tab.name && JSON.stringify(siblingData[tab.name] ?? null) !== JSON.stringify(originalSibling[tab.name] ?? null) && 'access' in tab && tab.access?.[operation] && !await tab.access[operation]({
|
|
152
168
|
id: doc.id,
|
|
169
|
+
collection,
|
|
153
170
|
req,
|
|
154
171
|
doc,
|
|
155
172
|
data,
|
|
@@ -160,7 +177,7 @@ async function fieldRefusal(fields, req, doc, operation = 'update', data = doc,
|
|
|
160
177
|
}
|
|
161
178
|
const tabData = 'name' in tab && tab.name ? siblingData[tab.name] : siblingData;
|
|
162
179
|
const originalTab = 'name' in tab && tab.name ? originalSibling[tab.name] : originalSibling;
|
|
163
|
-
const refusal = await fieldRefusal(tab.fields, req, doc, operation, data, object(tabData) ? tabData : {}, blockData, object(originalTab) ? originalTab : {});
|
|
180
|
+
const refusal = await fieldRefusal(tab.fields, collection, req, doc, operation, data, object(tabData) ? tabData : {}, blockData, object(originalTab) ? originalTab : {});
|
|
164
181
|
if (refusal) return refusal;
|
|
165
182
|
}
|
|
166
183
|
const originalValue = 'name' in field ? originalSibling[field.name] : originalSibling;
|
|
@@ -168,7 +185,7 @@ async function fieldRefusal(fields, req, doc, operation = 'update', data = doc,
|
|
|
168
185
|
value
|
|
169
186
|
]){
|
|
170
187
|
const original = Array.isArray(value) ? existingRow(row, originalValue) : originalValue;
|
|
171
|
-
const refusal = await fieldRefusal(field.fields, req, doc, operation, data, object(row) ? row : {}, blockData, object(original) ? original : {});
|
|
188
|
+
const refusal = await fieldRefusal(field.fields, collection, req, doc, operation, data, object(row) ? row : {}, blockData, object(original) ? original : {});
|
|
172
189
|
if (refusal) return refusal;
|
|
173
190
|
}
|
|
174
191
|
if (field.type === 'blocks') {
|
|
@@ -177,7 +194,7 @@ async function fieldRefusal(fields, req, doc, operation = 'update', data = doc,
|
|
|
177
194
|
const block = object(row) ? blocks.find((block)=>block.slug === row.blockType) : undefined;
|
|
178
195
|
if (!block || !object(row)) continue;
|
|
179
196
|
const original = existingRow(row, originalValue);
|
|
180
|
-
const refusal = await fieldRefusal(block.fields, req, doc, operation, data, row, row, object(original) ? original : {});
|
|
197
|
+
const refusal = await fieldRefusal(block.fields, collection, req, doc, operation, data, row, row, object(original) ? original : {});
|
|
181
198
|
if (refusal) return refusal;
|
|
182
199
|
}
|
|
183
200
|
}
|
|
@@ -405,7 +422,8 @@ export async function makeContent(req, { experimentId, options, phase: expectedP
|
|
|
405
422
|
let field = registrations.find((entry)=>entry.slug === collection)?.field;
|
|
406
423
|
if (!field) throw new Error('This content collection is no longer configured.');
|
|
407
424
|
const config = req.payload.config.collections.find((config)=>config.slug === collection);
|
|
408
|
-
if (
|
|
425
|
+
if (!config) throw new Error('This content collection is no longer configured.');
|
|
426
|
+
if (hasLocalizedFields(config.fields, req.payload.config)) throw new LocalizedContent();
|
|
409
427
|
await req.payload.findByID({
|
|
410
428
|
collection,
|
|
411
429
|
id,
|
|
@@ -441,15 +459,15 @@ export async function makeContent(req, { experimentId, options, phase: expectedP
|
|
|
441
459
|
const changedDraft = JSON.stringify(draftContent) !== JSON.stringify(draftValue);
|
|
442
460
|
const changedPublished = JSON.stringify(publishedContent) !== JSON.stringify(published[field]);
|
|
443
461
|
if (!changedDraft && !changedPublished) return;
|
|
444
|
-
const publishedData = contentData(published, field, publishedContent, config
|
|
462
|
+
const publishedData = contentData(published, field, publishedContent, config, req.payload.config.blocks);
|
|
445
463
|
const draftData = {
|
|
446
|
-
...contentData(draft, field, draftContent, config
|
|
464
|
+
...contentData(draft, field, draftContent, config, req.payload.config.blocks),
|
|
447
465
|
_status: 'draft'
|
|
448
466
|
};
|
|
449
467
|
// Payload beforeValidate receives the latest version as doc, and the
|
|
450
468
|
// proposed write as data/siblingData (blockData is the proposed row).
|
|
451
469
|
if (changedPublished) {
|
|
452
|
-
const publicationRefusal = await fieldRefusal(config
|
|
470
|
+
const publicationRefusal = await fieldRefusal(config.fields, config, req, draft, 'update', publishedData);
|
|
453
471
|
if (publicationRefusal) throw new ValidationError({
|
|
454
472
|
errors: [
|
|
455
473
|
{
|
|
@@ -464,7 +482,7 @@ export async function makeContent(req, { experimentId, options, phase: expectedP
|
|
|
464
482
|
...published,
|
|
465
483
|
...publishedData
|
|
466
484
|
} : draft;
|
|
467
|
-
const draftRefusal = await fieldRefusal(config
|
|
485
|
+
const draftRefusal = await fieldRefusal(config.fields, config, req, draftOriginal, 'update', draftData);
|
|
468
486
|
if (draftRefusal) throw new ValidationError({
|
|
469
487
|
errors: [
|
|
470
488
|
{
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { PayloadRequest } from 'payload';
|
|
2
|
-
import type { ExperimentsPageCollection } from '../types/contracts.js';
|
|
2
|
+
import type { DocId, ExperimentsPageCollection } from '../types/contracts.js';
|
|
3
3
|
export declare const PAGE_ADDRESS_FIELDS: string[];
|
|
4
|
+
/** Local API output can inherit a fallback locale's status. The filter reads the selected locale's main row. */
|
|
5
|
+
export declare function findPublishedPageIds(req: PayloadRequest, collection: string, ids: DocId[], locale: string): Promise<Set<string>>;
|
|
4
6
|
/** Hosts can resolve drafts in findByPath. For simple addresses, the admin also
|
|
5
7
|
* recognizes never-published drafts when a host lookup only sees live pages. */
|
|
6
8
|
export declare function findDraftPageByPath(req: PayloadRequest, entry: ExperimentsPageCollection, path: string): Promise<(import("payload").JsonObject & import("payload").TypeWithID) | undefined>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { flattenTopLevelFields } from 'payload/shared';
|
|
2
|
-
import { placementReader } from '../blocks/placementLocale.js';
|
|
3
|
-
import {
|
|
2
|
+
import { localeRequest, placementReader } from '../blocks/placementLocale.js';
|
|
3
|
+
import { publicationLocale, usesLocalizedPublication } from '../blocks/placementPublication.js';
|
|
4
4
|
import { hasPublishedPageVersion } from '../db/pageContent.js';
|
|
5
5
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
6
6
|
export const PAGE_ADDRESS_FIELDS = [
|
|
@@ -8,6 +8,35 @@ export const PAGE_ADDRESS_FIELDS = [
|
|
|
8
8
|
'slug',
|
|
9
9
|
'pageSegment'
|
|
10
10
|
];
|
|
11
|
+
/** Local API output can inherit a fallback locale's status. The filter reads the selected locale's main row. */ export async function findPublishedPageIds(req, collection, ids, locale) {
|
|
12
|
+
if (!ids.length) return new Set();
|
|
13
|
+
const viewReq = localeRequest(req, {
|
|
14
|
+
locale,
|
|
15
|
+
fallbackLocale: false
|
|
16
|
+
});
|
|
17
|
+
const { docs } = await req.payload.find({
|
|
18
|
+
collection,
|
|
19
|
+
req: viewReq,
|
|
20
|
+
fallbackLocale: false,
|
|
21
|
+
overrideAccess: false,
|
|
22
|
+
depth: 0,
|
|
23
|
+
draft: false,
|
|
24
|
+
pagination: false,
|
|
25
|
+
limit: ids.length,
|
|
26
|
+
select: {
|
|
27
|
+
id: true
|
|
28
|
+
},
|
|
29
|
+
where: {
|
|
30
|
+
id: {
|
|
31
|
+
in: ids
|
|
32
|
+
},
|
|
33
|
+
_status: {
|
|
34
|
+
equals: 'published'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return new Set(docs.map((doc)=>String(doc.id)));
|
|
39
|
+
}
|
|
11
40
|
/** Hosts can resolve drafts in findByPath. For simple addresses, the admin also
|
|
12
41
|
* recognizes never-published drafts when a host lookup only sees live pages. */ export async function findDraftPageByPath(req, entry, path) {
|
|
13
42
|
const config = req.payload.collections?.[entry.slug]?.config ?? req.payload.config.collections?.find((collection)=>collection.slug === entry.slug);
|
|
@@ -93,12 +122,13 @@ export const PAGE_ADDRESS_FIELDS = [
|
|
|
93
122
|
]
|
|
94
123
|
}
|
|
95
124
|
});
|
|
125
|
+
const published = await findPublishedPageIds(req, entry.slug, main.docs.map((row)=>row.id), locale);
|
|
96
126
|
const draftById = new Map(candidates.map((row)=>[
|
|
97
127
|
String(row.id),
|
|
98
128
|
row
|
|
99
129
|
]));
|
|
100
130
|
const eligible = await Promise.all(main.docs.map(async (row)=>{
|
|
101
|
-
if (
|
|
131
|
+
if (published.has(String(row.id))) return undefined;
|
|
102
132
|
if (await hasPublishedPageVersion(req, entry.slug, row.id, locale)) return matchesPath(row) ? row : undefined;
|
|
103
133
|
return draftById.get(String(row.id));
|
|
104
134
|
}));
|
package/dist/ui/accent.d.ts
CHANGED
|
@@ -16,7 +16,11 @@ type Floors = {
|
|
|
16
16
|
text: number;
|
|
17
17
|
focus: number;
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
export declare const ACCENT_REFERENCE_SURFACES: {
|
|
20
|
+
readonly light: "#ffffff";
|
|
21
|
+
readonly dark: "#2c2c2c";
|
|
22
|
+
};
|
|
23
|
+
/** Pure shared host-accent derivation using Payload 4 reference surfaces. */
|
|
20
24
|
export declare function deriveAccent(input: string): {
|
|
21
25
|
light: AccentSet;
|
|
22
26
|
dark: AccentSet;
|
package/dist/ui/accent.js
CHANGED
|
@@ -100,11 +100,12 @@ function set(accent, surface, dark = false, floors = FLOORS) {
|
|
|
100
100
|
accentTextDecoration: accentText ? 'none' : 'underline'
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
export const ACCENT_REFERENCE_SURFACES = {
|
|
104
|
+
light: '#ffffff',
|
|
105
|
+
dark: '#2c2c2c'
|
|
106
|
+
};
|
|
107
|
+
/** Pure shared host-accent derivation using Payload 4 reference surfaces. */ export function deriveAccent(input) {
|
|
108
|
+
return deriveAccentFor(input, ACCENT_REFERENCE_SURFACES);
|
|
108
109
|
}
|
|
109
110
|
/** Module-only surface injection; not a package API. Dark adjustment raises HSL
|
|
110
111
|
* lightness to 3:1. Interaction steps preserve the foreground and prefer the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delmaredigital/payload-experiments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0-next.2",
|
|
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",
|
|
@@ -84,14 +84,14 @@
|
|
|
84
84
|
"README.md"
|
|
85
85
|
],
|
|
86
86
|
"peerDependencies": {
|
|
87
|
-
"@payloadcms/next": ">=
|
|
88
|
-
"@payloadcms/ui": ">=
|
|
87
|
+
"@payloadcms/next": ">=4.0.0-beta.0 <4.0.0-canary.0 || >=4.0.0-canary.37 <5",
|
|
88
|
+
"@payloadcms/ui": ">=4.0.0-beta.0 <4.0.0-canary.0 || >=4.0.0-canary.37 <5",
|
|
89
89
|
"@puckeditor/core": ">=0.24.0",
|
|
90
90
|
"next": ">=16.4.1 <17",
|
|
91
|
-
"payload": ">=
|
|
91
|
+
"payload": ">=4.0.0-beta.0 <4.0.0-canary.0 || >=4.0.0-canary.37 <5",
|
|
92
92
|
"react": ">=19.2.1 <20",
|
|
93
93
|
"react-dom": ">=19.2.1 <20",
|
|
94
|
-
"@payloadcms/db-postgres": ">=
|
|
94
|
+
"@payloadcms/db-postgres": ">=4.0.0-beta.0 <4.0.0-canary.0 || >=4.0.0-canary.37 <5",
|
|
95
95
|
"pg": ">=8.13.0 <9"
|
|
96
96
|
},
|
|
97
97
|
"peerDependenciesMeta": {
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
}
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@payloadcms/translations": ">=
|
|
103
|
+
"@payloadcms/translations": ">=4.0.0-beta.0 <4.0.0-canary.0 || >=4.0.0-canary.37 <5",
|
|
104
104
|
"@delmaredigital/experiments-stats": "0.1.0"
|
|
105
105
|
},
|
|
106
106
|
"keywords": [
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"nextjs"
|
|
115
115
|
],
|
|
116
116
|
"engines": {
|
|
117
|
-
"node": ">=22.
|
|
117
|
+
"node": ">=24.22.1"
|
|
118
118
|
},
|
|
119
119
|
"author": "Delmare Digital",
|
|
120
120
|
"repository": {
|
|
@@ -128,10 +128,10 @@
|
|
|
128
128
|
"homepage": "https://plugins.delmaredigital.com/experiments",
|
|
129
129
|
"devDependencies": {
|
|
130
130
|
"@delmaredigital/payload-puck": "0.12.5",
|
|
131
|
-
"payload": "
|
|
132
|
-
"@payloadcms/db-postgres": "
|
|
133
|
-
"@payloadcms/ui": "
|
|
134
|
-
"@payloadcms/next": "
|
|
131
|
+
"payload": "4.0.0-beta.6",
|
|
132
|
+
"@payloadcms/db-postgres": "4.0.0-beta.6",
|
|
133
|
+
"@payloadcms/ui": "4.0.0-beta.6",
|
|
134
|
+
"@payloadcms/next": "4.0.0-beta.6",
|
|
135
135
|
"next": "^16.4.2",
|
|
136
136
|
"react": "^19.2.8",
|
|
137
137
|
"react-dom": "^19.2.8",
|