@delmaredigital/payload-experiments 0.5.2 → 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/paths.d.ts +0 -4
- package/dist/admin/paths.js +0 -4
- package/dist/admin/theme.css +43 -49
- 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/exports/adminClient.d.ts +0 -2
- package/dist/exports/adminClient.js +0 -2
- package/dist/exports/adminRsc.d.ts +0 -2
- package/dist/exports/adminRsc.js +0 -2
- 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 -109
- 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/testSurface/copy/surface.d.ts +0 -3
- package/dist/testSurface/copy/surface.js +0 -3
- 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
- package/dist/admin/TestsDashboardCards.d.ts +0 -4
- package/dist/admin/TestsDashboardCards.js +0 -48
- package/dist/admin/TestsNavLink.d.ts +0 -6
- package/dist/admin/TestsNavLink.js +0 -68
- package/dist/admin/dashboard.css +0 -35
- package/dist/admin/views/CollectionListRedirect.d.ts +0 -3
- package/dist/admin/views/CollectionListRedirect.js +0 -8
- package/dist/admin/views/TestsNavLinkServer.d.ts +0 -3
- package/dist/admin/views/TestsNavLinkServer.js +0 -43
package/dist/db/appends.js
CHANGED
|
@@ -18,13 +18,10 @@ import { qualifiedTable, quoteIdentifier as quote } from './sql.js';
|
|
|
18
18
|
});
|
|
19
19
|
return doc ?? undefined;
|
|
20
20
|
}
|
|
21
|
-
/** Payload
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* Localized status uses the main row for a single-locale publish. The caller
|
|
25
|
-
* selects that base separately. Restore uses the selected version. */ export function placementMergeBase(path) {
|
|
21
|
+
/** Payload 4 starts by-ID updates from the latest version and bulk updates
|
|
22
|
+
* from main rows except draft/trash saves. Restore uses the selected version.
|
|
23
|
+
* For a single-locale publish the caller merges the result with main. */ export function placementMergeBase(path) {
|
|
26
24
|
if (path.versionId != null) return 'restore';
|
|
27
|
-
if (path.publishSpecificLocale) return 'published';
|
|
28
25
|
return path.bulk && !path.draft && !path.trashing ? 'main' : 'latest';
|
|
29
26
|
}
|
|
30
27
|
export async function placementWriteContent(req, collection, id, main, path = {}) {
|
|
@@ -50,11 +47,7 @@ export async function placementWriteContent(req, collection, id, main, path = {}
|
|
|
50
47
|
equals: id
|
|
51
48
|
}
|
|
52
49
|
},
|
|
53
|
-
|
|
54
|
-
'version._status': {
|
|
55
|
-
equals: 'published'
|
|
56
|
-
}
|
|
57
|
-
} : {
|
|
50
|
+
{
|
|
58
51
|
latest: {
|
|
59
52
|
equals: true
|
|
60
53
|
}
|
|
@@ -66,7 +59,7 @@ export async function placementWriteContent(req, collection, id, main, path = {}
|
|
|
66
59
|
return latest.docs[0] ? {
|
|
67
60
|
...latest.docs[0].version,
|
|
68
61
|
id
|
|
69
|
-
} :
|
|
62
|
+
} : main;
|
|
70
63
|
}
|
|
71
64
|
/** Read the main collection row BEFORE the host write. Draft version retention
|
|
72
65
|
* and unpublishing cannot remove this baseline.
|
package/dist/db/clickGoals.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hasPublishedLocale, usesLocalizedPublication } from '../blocks/placementPublication.js';
|
|
1
2
|
import { COLUMNS, TABLES } from './names.js';
|
|
2
3
|
import { qualifiedTable, quoteIdentifier as q } from './sql.js';
|
|
3
4
|
/** Defined click goals only; called on the pool by the public events endpoint. */ export async function definedClickKeys(exec) {
|
|
@@ -17,6 +18,8 @@ import { qualifiedTable, quoteIdentifier as q } from './sql.js';
|
|
|
17
18
|
// Adapter read: click-goal fairness reads published content raw.
|
|
18
19
|
overrideAccess: true
|
|
19
20
|
});
|
|
20
|
-
const
|
|
21
|
-
|
|
21
|
+
const config = req.payload.config.collections?.find((c)=>c.slug === collection);
|
|
22
|
+
if (!doc || !config?.versions || !config.versions.drafts) return doc ?? undefined;
|
|
23
|
+
const published = usesLocalizedPublication(req, collection, config) ? hasPublishedLocale(doc) : doc._status === 'published';
|
|
24
|
+
return published ? doc : undefined;
|
|
22
25
|
}
|
package/dist/db/executor.d.ts
CHANGED
|
@@ -5,11 +5,7 @@ export { pgPoolExecutor, ownConnection, withStatementTimeout, raceDeadline, Resu
|
|
|
5
5
|
/** Bound statements in an owned results transition without racing a write or commit. */
|
|
6
6
|
export declare function setTransitionTimeout(exec: Executor, deadline: number): Promise<void>;
|
|
7
7
|
type TransactionRequest = Pick<PayloadRequest, 'payload' | 'transactionID'>;
|
|
8
|
-
export declare function transactionSession(req: TransactionRequest): Promise<
|
|
9
|
-
db: unknown;
|
|
10
|
-
reject: () => Promise<void>;
|
|
11
|
-
resolve: () => Promise<void>;
|
|
12
|
-
}>;
|
|
8
|
+
export declare function transactionSession(req: TransactionRequest): Promise<NonNullable<Payload['db']['sessions']>[string]>;
|
|
13
9
|
export declare function txExecutor(req: TransactionRequest): Executor & {
|
|
14
10
|
schemaName?: string;
|
|
15
11
|
};
|
package/dist/db/names.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** SQL identifiers from the Payload
|
|
1
|
+
/** SQL identifiers from the Payload 4.0.0-beta.6 generated-schema fixture (2026-12-04).
|
|
2
2
|
* All main, array, relationship and version tables are included. Access through
|
|
3
3
|
* these literal keys is checked by TypeScript; names.test.ts checks fixture parity.
|
|
4
4
|
*/
|
package/dist/db/names.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** SQL identifiers from the Payload
|
|
1
|
+
/** SQL identifiers from the Payload 4.0.0-beta.6 generated-schema fixture (2026-12-04).
|
|
2
2
|
* All main, array, relationship and version tables are included. Access through
|
|
3
3
|
* these literal keys is checked by TypeScript; names.test.ts checks fixture parity.
|
|
4
4
|
*/ export const TABLES = {
|
package/dist/db/pageContent.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { DocId } from '../types/contracts.js';
|
|
|
4
4
|
export declare function pageVersionContent(req: PayloadRequest, collection: string, id: DocId): Promise<(Record<string, unknown> & {
|
|
5
5
|
id: DocId;
|
|
6
6
|
}) | null>;
|
|
7
|
-
/** Path selection only, after checking access to the page.
|
|
7
|
+
/** Path selection only, after checking access to the page. Payload scopes the version status filter to the given locale. */
|
|
8
8
|
export declare function hasPublishedPageVersion(req: PayloadRequest, collection: string, id: DocId, locale?: string): Promise<boolean>;
|
|
9
9
|
/** §7.8: status computes a page's published (or never-published draft) path. */
|
|
10
10
|
export declare function statusPageContent(req: PayloadRequest, collection: string, id: DocId): Promise<(Record<string, unknown> & {
|
package/dist/db/pageContent.js
CHANGED
|
@@ -12,7 +12,7 @@ import { pagePublicationStatus, publicationLocale, usesLocalizedPublication } fr
|
|
|
12
12
|
overrideAccess: true
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
-
/** Path selection only, after checking access to the page.
|
|
15
|
+
/** Path selection only, after checking access to the page. Payload scopes the version status filter to the given locale. */ export async function hasPublishedPageVersion(req, collection, id, locale) {
|
|
16
16
|
const published = await req.payload.db.findVersions({
|
|
17
17
|
collection,
|
|
18
18
|
req,
|
package/dist/endpoints/pages.js
CHANGED
|
@@ -2,7 +2,7 @@ import { flattenTopLevelFields, formatAdminURL } from 'payload/shared';
|
|
|
2
2
|
import { placementReader } from '../blocks/placementLocale.js';
|
|
3
3
|
import { pagePublicationStatus, publicationLocale, usesLocalizedPublication } from '../blocks/placementPublication.js';
|
|
4
4
|
import { hasPublishedPageVersion } from '../db/pageContent.js';
|
|
5
|
-
import { findDraftPageByPath, PAGE_ADDRESS_FIELDS } from '../transitions/pageAddress.js';
|
|
5
|
+
import { findDraftPageByPath, findPublishedPageIds, PAGE_ADDRESS_FIELDS } from '../transitions/pageAddress.js';
|
|
6
6
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
7
7
|
import { blockPageSlugs, hasPuckEditor } from '../options.js';
|
|
8
8
|
import { XpRefusal } from '../errors.js';
|
|
@@ -58,7 +58,9 @@ export async function handlePages(req, { options }) {
|
|
|
58
58
|
docs: [],
|
|
59
59
|
hasNextPage: false
|
|
60
60
|
});
|
|
61
|
-
const published = !drafts ||
|
|
61
|
+
const published = !drafts || (locale ? Boolean(found && (await findPublishedPageIds(req, slug, [
|
|
62
|
+
main.id
|
|
63
|
+
], locale)).has(String(main.id))) : pagePublicationStatus(main) === 'published');
|
|
62
64
|
const useMain = published || Boolean(locale && (!found || await hasPublishedPageVersion(req, slug, main.id, locale)));
|
|
63
65
|
const row = useMain ? main : await req.payload.findByID({
|
|
64
66
|
collection: slug,
|
|
@@ -101,8 +103,9 @@ export async function handlePages(req, { options }) {
|
|
|
101
103
|
]);
|
|
102
104
|
const searchable = q ? await Promise.all(fields.map(async (field)=>{
|
|
103
105
|
if (field.type !== 'text' && field.type !== 'textarea' || field.hidden || field.virtual || !searchFields.has(field.name)) return;
|
|
104
|
-
if (field.access?.read && !await field.access.read({
|
|
105
|
-
req
|
|
106
|
+
if (config && field.access?.read && !await field.access.read({
|
|
107
|
+
req,
|
|
108
|
+
collection: config
|
|
106
109
|
})) return;
|
|
107
110
|
return field.name;
|
|
108
111
|
})) : [];
|
|
@@ -138,7 +141,8 @@ export async function handlePages(req, { options }) {
|
|
|
138
141
|
// Payload applies the read constraint to the latest version when draft is
|
|
139
142
|
// true. A manager scoped to published content needs to browse the live rows.
|
|
140
143
|
const readScope = drafts ? await config?.access?.read?.({
|
|
141
|
-
req
|
|
144
|
+
req,
|
|
145
|
+
slug
|
|
142
146
|
}) : undefined;
|
|
143
147
|
const readDrafts = drafts && !(readScope && typeof readScope === 'object' && requiresPublished(readScope));
|
|
144
148
|
let searchTruncated = false;
|
|
@@ -210,6 +214,7 @@ export async function handlePages(req, { options }) {
|
|
|
210
214
|
});
|
|
211
215
|
const localizedPaths = Boolean(locale && collection && !blockMode);
|
|
212
216
|
const draftIds = readDrafts ? result.docs.filter((doc)=>localizedPaths || pagePublicationStatus(doc, locale) === 'draft').map((doc)=>doc.id) : [];
|
|
217
|
+
const publishedIds = locale ? await findPublishedPageIds(req, slug, result.docs.map((doc)=>doc.id), locale) : undefined;
|
|
213
218
|
const mainById = new Map();
|
|
214
219
|
if (draftIds.length) {
|
|
215
220
|
// Read the matching main rows in one bounded query. Localized drafts can
|
|
@@ -236,7 +241,7 @@ export async function handlePages(req, { options }) {
|
|
|
236
241
|
}
|
|
237
242
|
});
|
|
238
243
|
await Promise.all(live.docs.map(async (doc)=>{
|
|
239
|
-
const published = pagePublicationStatus(doc
|
|
244
|
+
const published = publishedIds?.has(String(doc.id)) ?? pagePublicationStatus(doc) === 'published';
|
|
240
245
|
if (!published && !localizedPaths) return;
|
|
241
246
|
const usePath = published || await hasPublishedPageVersion(req, slug, doc.id, locale);
|
|
242
247
|
mainById.set(String(doc.id), {
|
|
@@ -251,7 +256,7 @@ export async function handlePages(req, { options }) {
|
|
|
251
256
|
const doc = placement.doc;
|
|
252
257
|
const main = mainById.get(String(row.id));
|
|
253
258
|
const versionPublished = pagePublicationStatus(row, locale) === 'published';
|
|
254
|
-
const published = !drafts || (main?.published ?? versionPublished);
|
|
259
|
+
const published = !drafts || (publishedIds?.has(String(row.id)) ?? main?.published ?? versionPublished);
|
|
255
260
|
const pathDoc = !blockMode && main?.usePath ? reader.read(main.doc, input).doc : doc;
|
|
256
261
|
const rawPath = collection?.pathOf(pathDoc) ?? null;
|
|
257
262
|
const storedAddress = blockMode ? addressFields.reduce((value, field)=>value ?? textValue(pathDoc[field]), undefined) : undefined;
|
|
@@ -2,9 +2,7 @@ export { XP_IF_UPDATED_AT_HEADER } from '../constants.js';
|
|
|
2
2
|
export { LayerUsage } from '../admin/LayerUsage.js';
|
|
3
3
|
export { MetricSourceSelect } from '../admin/MetricSourceSelect.js';
|
|
4
4
|
export { ArmSelectField } from '../admin/armSelect/ArmSelectField.js';
|
|
5
|
-
export { TestsNavLink } from '../admin/TestsNavLink.js';
|
|
6
5
|
export { TestsSurface } from '../admin/views/TestsSurfaceClient.js';
|
|
7
|
-
export { TestsDashboardCards } from '../admin/TestsDashboardCards.js';
|
|
8
6
|
export { PlacementStatus } from '../admin/PlacementStatus.js';
|
|
9
7
|
export { wrapExperimentBlock, syncExperimentSlots, copyOriginalIntoVersion, unwrapExperimentBlock, findRegisteredBlocksField } from '../blocks/formState.js';
|
|
10
8
|
export { TestBlockField } from '../admin/blocks/TestBlockField.js';
|
|
@@ -3,9 +3,7 @@ export { XP_IF_UPDATED_AT_HEADER } from '../constants.js';
|
|
|
3
3
|
export { LayerUsage } from '../admin/LayerUsage.js';
|
|
4
4
|
export { MetricSourceSelect } from '../admin/MetricSourceSelect.js';
|
|
5
5
|
export { ArmSelectField } from '../admin/armSelect/ArmSelectField.js';
|
|
6
|
-
export { TestsNavLink } from '../admin/TestsNavLink.js';
|
|
7
6
|
export { TestsSurface } from '../admin/views/TestsSurfaceClient.js';
|
|
8
|
-
export { TestsDashboardCards } from '../admin/TestsDashboardCards.js';
|
|
9
7
|
export { PlacementStatus } from '../admin/PlacementStatus.js';
|
|
10
8
|
export { wrapExperimentBlock, syncExperimentSlots, copyOriginalIntoVersion, unwrapExperimentBlock, findRegisteredBlocksField } from '../blocks/formState.js';
|
|
11
9
|
export { TestBlockField } from '../admin/blocks/TestBlockField.js';
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export { ExperimentsRootView } from '../admin/views/ExperimentsRootView.js';
|
|
2
|
-
export { CollectionListRedirect } from '../admin/views/CollectionListRedirect.js';
|
|
3
2
|
export { CollectionEditRedirect } from '../admin/views/CollectionEditRedirect.js';
|
|
4
|
-
export { TestsNavLinkServer } from '../admin/views/TestsNavLinkServer.js';
|
|
5
3
|
export { TestsCollectionListView } from '../admin/views/TestsCollectionListView.js';
|
|
6
4
|
export { GoalsCollectionListView } from '../admin/views/GoalsCollectionListView.js';
|
|
7
5
|
export { GoalEditRedirect } from '../admin/views/GoalEditRedirect.js';
|
package/dist/exports/adminRsc.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export { ExperimentsRootView } from '../admin/views/ExperimentsRootView.js';
|
|
2
|
-
export { CollectionListRedirect } from '../admin/views/CollectionListRedirect.js';
|
|
3
2
|
export { CollectionEditRedirect } from '../admin/views/CollectionEditRedirect.js';
|
|
4
|
-
export { TestsNavLinkServer } from '../admin/views/TestsNavLinkServer.js';
|
|
5
3
|
export { TestsCollectionListView } from '../admin/views/TestsCollectionListView.js';
|
|
6
4
|
export { GoalsCollectionListView } from '../admin/views/GoalsCollectionListView.js';
|
|
7
5
|
export { GoalEditRedirect } from '../admin/views/GoalEditRedirect.js';
|
package/dist/globals/state.js
CHANGED
|
@@ -5,6 +5,7 @@ export function stateGlobal(options) {
|
|
|
5
5
|
slug: 'xp-state',
|
|
6
6
|
dbName: 'xp_state',
|
|
7
7
|
graphQL: false,
|
|
8
|
+
authorship: false,
|
|
8
9
|
versions: false,
|
|
9
10
|
admin: {
|
|
10
11
|
hidden: true
|
|
@@ -12,6 +13,7 @@ export function stateGlobal(options) {
|
|
|
12
13
|
access: {
|
|
13
14
|
read: isTrue(options.access.manage),
|
|
14
15
|
update: deny,
|
|
16
|
+
validate: deny,
|
|
15
17
|
readVersions: deny
|
|
16
18
|
},
|
|
17
19
|
hooks: {
|
package/dist/goals/fairness.js
CHANGED
|
@@ -95,7 +95,9 @@ function blockLabels(req) {
|
|
|
95
95
|
continue;
|
|
96
96
|
}
|
|
97
97
|
const reader = placementReader(req, collection.slug, options);
|
|
98
|
-
for (const view of reader.documentViews)
|
|
98
|
+
for (const view of reader.documentViews){
|
|
99
|
+
if (reader.isPublished(doc, view)) collect(collection.contentOf(reader.read(doc, 'all-locales', view).doc), byArm.get(arm.key), '', labels);
|
|
100
|
+
}
|
|
99
101
|
readArms.add(arm.key);
|
|
100
102
|
} catch (error) {
|
|
101
103
|
failed(error, placement);
|
|
@@ -126,6 +128,7 @@ function blockLabels(req) {
|
|
|
126
128
|
const raw = await clickGoalContent(req, placement.collection, placement.id);
|
|
127
129
|
const reader = placementReader(req, placement.collection, options);
|
|
128
130
|
for (const view of reader.views){
|
|
131
|
+
if (!reader.isPublished(raw, view)) continue;
|
|
129
132
|
const localized = reader.read(raw, 'all-locales', view);
|
|
130
133
|
const doc = localized.doc;
|
|
131
134
|
if (!doc) continue;
|
|
@@ -11,7 +11,6 @@ type OperationFrame = PublicationFlags & {
|
|
|
11
11
|
restore: boolean;
|
|
12
12
|
versionId?: DocId;
|
|
13
13
|
isBulk?: boolean;
|
|
14
|
-
publishSpecificLocale?: string;
|
|
15
14
|
pending?: boolean;
|
|
16
15
|
scoped?: boolean;
|
|
17
16
|
complete?: boolean;
|
|
@@ -23,8 +22,6 @@ type OperationFrame = PublicationFlags & {
|
|
|
23
22
|
publicationWrites?: Map<string, Set<string>>;
|
|
24
23
|
};
|
|
25
24
|
export declare const pageGuardOperationScope: AsyncLocalStorage<OperationFrame | undefined>;
|
|
26
|
-
/** Both Publish All and Restore can return a locale-projected document. */
|
|
27
|
-
export declare function writesAllPublicationLocales(req: PayloadRequest, collection: string): boolean;
|
|
28
25
|
/** Must be first: buildBeforeOperation invokes its first hook synchronously,
|
|
29
26
|
* before the operation registers its await continuation. Later host hooks may
|
|
30
27
|
* await nested operations; those keep separate async contexts. No IO here.
|
package/dist/hooks/pageGuard.js
CHANGED
|
@@ -10,7 +10,7 @@ import { normalisePath } from '../runtime/normalisePath.js';
|
|
|
10
10
|
import { XpNoTransactionError, XpRefusal } from '../errors.js';
|
|
11
11
|
import { placementGuardCopy, pageGuardCopy, READINESS_COPY } from '../testSurface/copy/readiness.js';
|
|
12
12
|
import { allPlacementSlugs, localizedPlacementAfter, mergedPlacementLocales, placementDocumentPaths, placementReader, selectPlacementLocales } from '../blocks/placementLocale.js';
|
|
13
|
-
import { allLocalesStatus, usesLocalizedPublication } from '../blocks/placementPublication.js';
|
|
13
|
+
import { allLocalesStatus, hasPublishedLocale, usesLocalizedPublication } from '../blocks/placementPublication.js';
|
|
14
14
|
import { isObject } from '../blocks/model.js';
|
|
15
15
|
import { placementTests, removableBlockTests, appendPlacementDoc } from '../db/placements.js';
|
|
16
16
|
import { isPageBusy } from '../db/pageBusy.js';
|
|
@@ -46,10 +46,6 @@ const operationFrame = (req, slug)=>{
|
|
|
46
46
|
}
|
|
47
47
|
return frame?.scoped && frame.collection === slug && (frame.restore || frame.request === req) ? frame : undefined;
|
|
48
48
|
};
|
|
49
|
-
/** Both Publish All and Restore can return a locale-projected document. */ export function writesAllPublicationLocales(req, collection) {
|
|
50
|
-
const call = operationFrame(req, collection);
|
|
51
|
-
return Boolean(call && !call.draft && (call.publishAllLocales || call.restore));
|
|
52
|
-
}
|
|
53
49
|
/** Must be first: buildBeforeOperation invokes its first hook synchronously,
|
|
54
50
|
* before the operation registers its await continuation. Later host hooks may
|
|
55
51
|
* await nested operations; those keep separate async contexts. No IO here.
|
|
@@ -97,7 +93,6 @@ export const pageGuardBeforeOperation = ({ args, operation })=>{
|
|
|
97
93
|
restore: operation === 'restoreVersion',
|
|
98
94
|
versionId: operation === 'restoreVersion' ? call.id : undefined,
|
|
99
95
|
isBulk,
|
|
100
|
-
publishSpecificLocale: call.publishSpecificLocale,
|
|
101
96
|
publishAllLocales: call.publishAllLocales,
|
|
102
97
|
unpublishAllLocales: call.unpublishAllLocales,
|
|
103
98
|
duplicateFromID: call.duplicateFromID,
|
|
@@ -245,7 +240,7 @@ export const pageGuardBeforeDelete = async ({ req, id, collection })=>{
|
|
|
245
240
|
const localized = usesLocalizedPublication(req, collection.slug, collection);
|
|
246
241
|
const published = page && !localized ? await previousPublishedContent(req, collection.slug, id) : await storedContent(req, collection.slug, id);
|
|
247
242
|
if (!published || published._status === 'draft') return;
|
|
248
|
-
if (localized &&
|
|
243
|
+
if (localized && !hasPublishedLocale(published)) return;
|
|
249
244
|
const paths = sortLockKeys(documentPathsOf(req, collection.slug, [
|
|
250
245
|
published
|
|
251
246
|
]).map(normalisePath));
|
|
@@ -274,6 +269,7 @@ export const pageGuardBeforeDelete = async ({ req, id, collection })=>{
|
|
|
274
269
|
}
|
|
275
270
|
};
|
|
276
271
|
export const pageGuardBeforeChange = async ({ req, collection, originalDoc, operation, data })=>{
|
|
272
|
+
// Payload 4 runs beforeChange for read-only validation. Guard actual writes only.
|
|
277
273
|
if (operation !== 'create' && operation !== 'update') return data;
|
|
278
274
|
const drafts = Boolean(collection.versions && collection.versions.drafts);
|
|
279
275
|
const call = operationFrame(req, collection.slug);
|
|
@@ -297,7 +293,6 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
297
293
|
versionId: call?.versionId,
|
|
298
294
|
bulk: call?.isBulk,
|
|
299
295
|
draft: call?.draft,
|
|
300
|
-
publishSpecificLocale: call?.publishSpecificLocale,
|
|
301
296
|
trashing: Boolean(collection.trash && data.deletedAt != null)
|
|
302
297
|
});
|
|
303
298
|
const before = published?._status === 'draft' ? undefined : published;
|
|
@@ -381,10 +376,17 @@ async function guardLocalizedSave(req, collection, originalDoc, operation, data,
|
|
|
381
376
|
if (!localization) return data;
|
|
382
377
|
try {
|
|
383
378
|
const status = allLocalesStatus(req, call, data._status, operation);
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
379
|
+
let locales = localization.localeCodes;
|
|
380
|
+
if (status && localization.filterAvailableLocales) {
|
|
381
|
+
const available = await localization.filterAvailableLocales({
|
|
382
|
+
locales: localization.locales,
|
|
383
|
+
req
|
|
384
|
+
});
|
|
385
|
+
locales = available.map((entry)=>typeof entry === 'string' ? entry : entry.code);
|
|
386
|
+
// Payload writes the request locale before applying the all-locales flag
|
|
387
|
+
// to the available list.
|
|
388
|
+
if (req.locale && localization.localeCodes.includes(req.locale) && !locales.includes(req.locale)) locales.push(req.locale);
|
|
389
|
+
}
|
|
388
390
|
const all = status ? {
|
|
389
391
|
status,
|
|
390
392
|
locales
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createPayloadRequest, type Block, type Field, type Payload } from 'payload';
|
|
2
|
+
/** Payload 3 createLocalReq(options, payload) -> Payload 4 createPayloadRequest({ ...options, payload }).
|
|
3
|
+
* Differs from 3.90 for `user: null` with a user on `options.req`: 4.0 runs anonymous, 3.90 kept the req's user. */
|
|
4
|
+
export declare function createLocalReq(options: Omit<Parameters<typeof createPayloadRequest>[0], 'payload'>, payload: Payload): Promise<import("payload").PayloadRequest>;
|
|
5
|
+
/** Payload 3 blockReferences + inline blocks -> Payload 4 blocks with inline definitions or slug references. */
|
|
6
|
+
export declare function resolveContentBlocks(field: Extract<Field, {
|
|
7
|
+
type: 'blocks';
|
|
8
|
+
}>, blocks?: Block[]): Block[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createPayloadRequest } from 'payload';
|
|
2
|
+
/** Payload 3 createLocalReq(options, payload) -> Payload 4 createPayloadRequest({ ...options, payload }).
|
|
3
|
+
* Differs from 3.90 for `user: null` with a user on `options.req`: 4.0 runs anonymous, 3.90 kept the req's user. */ export function createLocalReq(options, payload) {
|
|
4
|
+
return createPayloadRequest({
|
|
5
|
+
...options,
|
|
6
|
+
payload
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
/** Payload 3 blockReferences + inline blocks -> Payload 4 blocks with inline definitions or slug references. */ export function resolveContentBlocks(field, blocks = []) {
|
|
10
|
+
return field.blocks.map((reference)=>{
|
|
11
|
+
if (typeof reference !== 'string') return reference;
|
|
12
|
+
const block = blocks.find((block)=>block.slug === reference);
|
|
13
|
+
if (!block) throw new Error('This page has an unavailable block; update it by hand.');
|
|
14
|
+
return block;
|
|
15
|
+
});
|
|
16
|
+
}
|