@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.
Files changed (54) hide show
  1. package/README.md +15 -4
  2. package/dist/admin/blocks/formApi.js +17 -15
  3. package/dist/admin/blocks/model.js +1 -1
  4. package/dist/admin/theme.css +43 -47
  5. package/dist/admin/views/renderCollectionList.js +1 -1
  6. package/dist/blocks/formState.d.ts +1 -1
  7. package/dist/blocks/formState.js +2 -5
  8. package/dist/blocks/placementLocale.js +10 -13
  9. package/dist/blocks/placementPublication.d.ts +1 -1
  10. package/dist/blocks/placementPublication.js +6 -5
  11. package/dist/collections/access.d.ts +2 -0
  12. package/dist/collections/access.js +2 -0
  13. package/dist/collections/cohortMembers.js +1 -0
  14. package/dist/collections/events.js +1 -0
  15. package/dist/collections/experiments/config.js +2 -1
  16. package/dist/collections/experiments/createDefaults.js +4 -3
  17. package/dist/collections/experiments/flagControlParams.js +2 -1
  18. package/dist/collections/experiments/lockHook.js +6 -4
  19. package/dist/collections/identities.js +1 -0
  20. package/dist/collections/layers.js +1 -0
  21. package/dist/collections/metrics.js +1 -0
  22. package/dist/collections/phases.js +1 -0
  23. package/dist/collections/snapshots.js +1 -0
  24. package/dist/db/appends.d.ts +4 -7
  25. package/dist/db/appends.js +5 -12
  26. package/dist/db/clickGoals.js +5 -2
  27. package/dist/db/executor.d.ts +1 -5
  28. package/dist/db/names.d.ts +1 -1
  29. package/dist/db/names.js +1 -1
  30. package/dist/db/pageContent.d.ts +1 -1
  31. package/dist/db/pageContent.js +1 -1
  32. package/dist/endpoints/pages.js +12 -7
  33. package/dist/globals/state.js +2 -0
  34. package/dist/goals/fairness.js +4 -1
  35. package/dist/hooks/pageGuard.d.ts +0 -3
  36. package/dist/hooks/pageGuard.js +14 -12
  37. package/dist/payloadCompat.d.ts +8 -0
  38. package/dist/payloadCompat.js +16 -0
  39. package/dist/puck/editor/editor.css +103 -103
  40. package/dist/server/previewDraft.js +0 -1
  41. package/dist/server/recordContentChange.d.ts +1 -1
  42. package/dist/server/recordContentChange.js +11 -15
  43. package/dist/server/runResults.d.ts +1 -1
  44. package/dist/server/runResults.js +1 -1
  45. package/dist/server/startExperiment.d.ts +1 -1
  46. package/dist/server/startExperiment.js +1 -1
  47. package/dist/transitions/contentFields.d.ts +3 -6
  48. package/dist/transitions/contentFields.js +3 -9
  49. package/dist/transitions/makeContent.js +34 -16
  50. package/dist/transitions/pageAddress.d.ts +3 -1
  51. package/dist/transitions/pageAddress.js +33 -3
  52. package/dist/ui/accent.d.ts +5 -1
  53. package/dist/ui/accent.js +6 -5
  54. package/package.json +11 -11
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @delmaredigital/payload-experiments
2
2
 
3
- > ⚠️ Upgrading to 0.5? Run `payload migrate:create` and apply the migration. [Upgrade instructions](https://plugins.delmaredigital.com/docs/experiments/upgrading)
3
+ > ⚠️ Upgrading to 0.20? This is the Payload 4 `next` line. Install a matching set of Payload 4 packages, regenerate the host import map, and create, review, and apply your migration for the 0.5.0 schema changes. [Upgrade instructions](https://plugins.delmaredigital.com/docs/experiments/upgrading)
4
4
 
5
5
  A/B testing for Payload CMS and Next.js, from the content you already manage. Test a block on a page, a whole page against another page, or a setting your developer makes testable. Pick a goal, including click goals you name and attach to buttons and links, then compare the Original with your new versions. Results appear in the admin: they count only people who actually saw the content, warn when traffic looks wrong, and check guardrail goals (goals you don't want to hurt). You pick a winner and can make it permanent. Your data stays in your own Postgres database. There is no vendor.
6
6
 
@@ -11,16 +11,27 @@ A/B testing for Payload CMS and Next.js, from the content you already manage. Te
11
11
  ## Install
12
12
 
13
13
  ```bash
14
- pnpm add @delmaredigital/payload-experiments
14
+ pnpm add @delmaredigital/payload-experiments@next
15
15
  ```
16
16
 
17
+ This line tracks Payload 4. For Payload 3, install the `latest` tag.
18
+
19
+ Install a **matching set** of all four Payload packages: beta packages pin each
20
+ other to the exact same release. Canaries 0–36 are excluded. This line lives
21
+ on `payload-4`; shared fixes flow from main into that branch.
22
+ The admin theme uses v4 tokens, and every plugin collection and global except
23
+ Tests opts out of v4's default versioning (Tests keep their version history). Local API calls keep explicit `overrideAccess`
24
+ values despite v4's new `false` default. Hosts own the migration and import map.
25
+ Payload now peers `graphql ^16.8.1`; the plugin disables GraphQL for its data
26
+ and does not import or peer it. A host using GraphQL must satisfy that peer.
27
+
17
28
  ### Requirements
18
29
 
19
- Use Node.js `>=22.23.4`, the Next.js App Router, and Postgres through `@payloadcms/db-postgres` with transactions enabled and `READ COMMITTED` (or its PostgreSQL equivalent, `READ UNCOMMITTED`) as the default isolation level. Puck is optional. Install the peers your application uses:
30
+ Use Node.js `>=24.22.1`, the Next.js App Router, and Postgres through `@payloadcms/db-postgres` with transactions enabled and `READ COMMITTED` (or its PostgreSQL equivalent, `READ UNCOMMITTED`) as the default isolation level. Puck is optional. Install the peers your application uses:
20
31
 
21
32
  | Peer | Version |
22
33
  | --- | --- |
23
- | `payload`, `@payloadcms/db-postgres`, `@payloadcms/next`, `@payloadcms/ui` | `>=3.90.0 <4` |
34
+ | `payload`, `@payloadcms/db-postgres`, `@payloadcms/next`, `@payloadcms/ui` | `>=4.0.0-beta.0 <4.0.0-canary.0 \|\| >=4.0.0-canary.37 <5` |
24
35
  | `next` | `>=16.4.1 <17` |
25
36
  | `react`, `react-dom` | `>=19.2.1 <20` |
26
37
  | `pg` | `>=8.13.0 <9` |
@@ -25,25 +25,27 @@ export const wrapMode = 'form-api';
25
25
  /** Only schema structure is needed by the pure helpers, never server validators.
26
26
  * Resolve references at every depth, including inside the Experiment slots field.
27
27
  */ export function adaptClientBlocksField(field, config) {
28
- function block(block) {
29
- return {
30
- ...block,
31
- fields: block.fields.map(adapt)
28
+ const adaptedBlocks = new WeakMap();
29
+ function block(source) {
30
+ const cached = adaptedBlocks.get(source);
31
+ if (cached) return cached;
32
+ const adapted = {
33
+ ...source,
34
+ fields: []
32
35
  };
36
+ adaptedBlocks.set(source, adapted);
37
+ adapted.fields = source.fields.map(adapt);
38
+ return adapted;
33
39
  }
34
40
  function adapt(field) {
35
41
  if (field.type === 'blocks') return {
36
42
  ...field,
37
- blocks: [
38
- ...field.blocks.map(block),
39
- ...(field.blockReferences ?? []).flatMap((reference)=>{
40
- const resolved = typeof reference === 'string' ? config.blocks?.find((item)=>item.slug === reference) : reference;
41
- return resolved ? [
42
- block(resolved)
43
- ] : [];
44
- })
45
- ],
46
- blockReferences: []
43
+ blocks: field.blocks.flatMap((reference)=>{
44
+ const resolved = typeof reference === 'string' ? config.blocks?.find((item)=>item.slug === reference) : reference;
45
+ return resolved ? [
46
+ block(resolved)
47
+ ] : [];
48
+ })
47
49
  };
48
50
  if ('fields' in field) return {
49
51
  ...field,
@@ -61,7 +63,7 @@ export const wrapMode = 'form-api';
61
63
  return adapt(field);
62
64
  }
63
65
  export function experimentBlockSlug(field) {
64
- return field.blocks.find((block)=>block.fields.some((field)=>'name' in field && field.name === 'xpBlockStatus'))?.slug ?? EXPERIMENT_BLOCK_SLUG;
66
+ return field.blocks.find((block)=>typeof block !== 'string' && block.fields.some((field)=>'name' in field && field.name === 'xpBlockStatus'))?.slug ?? EXPERIMENT_BLOCK_SLUG;
65
67
  }
66
68
  export function rowLocation(path) {
67
69
  const match = /^([^.]+)\.(\d+)(?:\.|$)/.exec(path);
@@ -39,7 +39,7 @@ export function labelText(value) {
39
39
  export function blockChoices(value, field, blockSlug) {
40
40
  return hostBlocks(value).flatMap((block, index)=>{
41
41
  if (block.blockType === blockSlug) return [];
42
- const label = labelText(field.blocks.find((config)=>config.slug === block.blockType)?.labels?.singular) || block.blockType;
42
+ const label = labelText(field.blocks.find((config)=>typeof config !== 'string' && config.slug === block.blockType)?.labels?.singular) || block.blockType;
43
43
  return [
44
44
  {
45
45
  block,
@@ -1,31 +1,25 @@
1
- /* The only Payload token boundary. Reference: Payload 3.90.2; nearest neutral
2
- elevation by RGB distance to the approved mockup, advancing toward the mockup
3
- on collision so all five surface steps stay distinct (light / dark):
4
- bg 50/0; surface 0/50; surface-2 100/100; surface-3 150/150;
5
- accent-subtle 200/200;
6
- border 100/100; border-strong 250/200; text 850/800;
7
- text-2 650/550; text-3 450/350; accent 800/800; hover 900/900;
8
- accent-fg 0/0; focus 800/800; series-muted 300/250.
9
- Semantic and series hues are fixed mockup literals; only neutrals use Payload. */
1
+ /* The only Payload token boundary. Reference: Payload 4.0.0-beta.6.
2
+ Semantic and series hues are fixed mockup literals. Neutral literals provide
3
+ the missing fifth surface step and AA light secondary text; see each comment. */
10
4
  :root, [data-theme] {
11
- --xp-bg: var(--theme-elevation-50);
12
- --xp-surface: var(--theme-elevation-0);
13
- --xp-surface-2: var(--theme-elevation-100);
14
- --xp-surface-3: var(--theme-elevation-150);
15
- --xp-border: var(--theme-elevation-100);
16
- --xp-border-strong: var(--theme-elevation-250);
17
- --xp-text: var(--theme-elevation-850);
18
- --xp-text-2: var(--theme-elevation-650);
19
- --xp-text-3: var(--theme-elevation-450);
20
- --xp-accent: var(--theme-elevation-800);
21
- --xp-accent-hover: var(--theme-elevation-900);
22
- --xp-accent-active: var(--theme-elevation-950);
23
- --xp-accent-subtle: var(--theme-elevation-200);
24
- --xp-accent-fg: var(--theme-elevation-0);
5
+ --xp-bg: var(--color-bg-secondary);
6
+ --xp-surface: var(--color-bg);
7
+ --xp-surface-2: var(--color-bg-tertiary);
8
+ --xp-surface-3: var(--color-bg-secondary-pressed);
9
+ --xp-border: var(--color-border);
10
+ --xp-border-strong: var(--color-border-control-strong);
11
+ --xp-text: var(--color-text);
12
+ --xp-text-2: #595959; /* Payload secondary text alpha falls below AA in light mode. */
13
+ --xp-text-3: var(--color-text-secondary);
14
+ --xp-accent: var(--color-bg-inverse);
15
+ --xp-accent-hover: var(--color-bg-inverse-hover);
16
+ --xp-accent-active: var(--color-bg-inverse-pressed);
17
+ --xp-accent-subtle: #d0d0d0; /* No fifth neutral surface step in Payload 4. */
18
+ --xp-accent-fg: var(--color-text-oninverse);
25
19
  --xp-accent-text: var(--xp-text);
26
20
  --xp-accent-text-decoration: none;
27
- --xp-focus: var(--theme-elevation-800);
28
- --xp-series-muted: var(--theme-elevation-300);
21
+ --xp-focus: var(--color-bg-inverse);
22
+ --xp-series-muted: var(--color-icon-tertiary);
29
23
  --xp-success: #1a6a3a;
30
24
  --xp-success-bg: #e8f4ec;
31
25
  --xp-success-border: #bddfc9;
@@ -64,19 +58,19 @@
64
58
  --xp-space-4: 16px;
65
59
  --xp-space-5: 20px;
66
60
  /* Payload's gap between form fields. */
67
- --xp-field-gap: var(--base);
61
+ --xp-field-gap: var(--spacing-field);
68
62
  --xp-space-6: 24px;
69
63
  --xp-space-7: 28px;
70
64
  --xp-space-8: 32px;
71
65
  --xp-surface-raised: var(--xp-surface-2);
72
- --xp-border-control: var(--theme-elevation-250);
73
- --xp-input-border: var(--theme-elevation-300);
74
- --xp-border-accent: var(--theme-elevation-400);
66
+ --xp-border-control: var(--color-border-control-strong);
67
+ --xp-input-border: var(--color-icon-tertiary);
68
+ --xp-border-accent: var(--color-icon-secondary);
75
69
  --xp-text-muted: var(--xp-text-2);
76
70
  --xp-text-strong: var(--xp-text);
77
71
  --xp-text-emphasis: var(--xp-text);
78
- --xp-input-bg: var(--theme-input-bg);
79
- --xp-overlay: var(--theme-overlay);
72
+ --xp-input-bg: var(--field-color-bg);
73
+ --xp-overlay: var(--color-modalbackdrop);
80
74
  --xp-success-surface: var(--xp-success-bg);
81
75
  --xp-success-text: var(--xp-success);
82
76
  --xp-success-text-strong: var(--xp-success);
@@ -92,22 +86,24 @@
92
86
  --xp-font-size-body: 15px;
93
87
  }
94
88
  [data-theme="dark"] {
95
- --xp-bg: var(--theme-elevation-0);
96
- --xp-surface: var(--theme-elevation-50);
97
- --xp-surface-2: var(--theme-elevation-100);
98
- --xp-surface-3: var(--theme-elevation-150);
99
- --xp-border: var(--theme-elevation-100);
100
- --xp-border-strong: var(--theme-elevation-200);
101
- --xp-text: var(--theme-elevation-800);
102
- --xp-text-2: var(--theme-elevation-550);
103
- --xp-text-3: var(--theme-elevation-350);
104
- --xp-accent: var(--theme-elevation-800);
105
- --xp-accent-hover: var(--theme-elevation-900);
106
- --xp-accent-active: var(--theme-elevation-1000);
107
- --xp-accent-subtle: var(--theme-elevation-200);
108
- --xp-accent-fg: var(--theme-elevation-0);
109
- --xp-focus: var(--theme-elevation-800);
110
- --xp-series-muted: var(--theme-elevation-250);
89
+ --xp-bg: var(--color-bg-elevated);
90
+ --xp-surface: var(--color-bg);
91
+ --xp-surface-2: var(--color-bg-secondary);
92
+ --xp-surface-3: var(--color-bg-tertiary);
93
+ --xp-border: var(--color-border);
94
+ --xp-border-strong: var(--color-border-control-strong);
95
+ --xp-text: var(--color-text);
96
+ --xp-text-2: var(--color-text-secondary);
97
+ --xp-text-3: var(--color-text-tertiary);
98
+ --xp-accent: var(--color-bg-inverse);
99
+ --xp-accent-hover: var(--color-bg-inverse-hover);
100
+ --xp-accent-active: var(--color-bg-inverse-pressed);
101
+ --xp-accent-subtle: #4f4f4f; /* No fifth neutral surface step in Payload 4. */
102
+ --xp-accent-fg: var(--color-text-oninverse);
103
+ --xp-focus: var(--color-bg-inverse);
104
+ --xp-series-muted: var(--color-border-control-strong);
105
+ --xp-input-border: var(--color-border-control-strong);
106
+ --xp-border-accent: var(--color-icon-tertiary);
111
107
  --xp-success: #7fd49c;
112
108
  --xp-success-bg: #142b1d;
113
109
  --xp-success-border: #23492f;
@@ -1,4 +1,4 @@
1
- import { createLocalReq } from 'payload';
1
+ import { createLocalReq } from '../../payloadCompat.js';
2
2
  import { formatAdminURL } from 'payload/shared';
3
3
  import { headers } from 'next/headers.js';
4
4
  import { redirect } from 'next/navigation.js';
@@ -10,7 +10,7 @@ type RowsField = Extract<Field, {
10
10
  /** Mirror Payload 3.90.2's collections/operations/utilities/copyDataWithFreshRowIDs.js:
11
11
  * walk configured row/subfield containers only. Mint ids for array/blocks rows, leaving
12
12
  * opaque values (including json, richText, relationships and uploads) unchanged.
13
- * Global block definitions resolve blockReferences; inline slot blocks retain host configs.
13
+ * Global block definitions resolve slug references; inline slot blocks retain host configs.
14
14
  */
15
15
  export declare function freshBlockIds<T>(value: T, field: RowsField, config?: RowConfig, mint?: () => string): T;
16
16
  export declare function wrapExperimentBlock(block: HostBlock, experiment: string, field: RowsField, config?: RowConfig, blockSlug?: string): ExperimentBlock;
@@ -2,7 +2,7 @@ import { BLOCK_SLOTS, EXPERIMENT_BLOCK_SLUG, isObject, slotBlocks } from './mode
2
2
  /** Mirror Payload 3.90.2's collections/operations/utilities/copyDataWithFreshRowIDs.js:
3
3
  * walk configured row/subfield containers only. Mint ids for array/blocks rows, leaving
4
4
  * opaque values (including json, richText, relationships and uploads) unchanged.
5
- * Global block definitions resolve blockReferences; inline slot blocks retain host configs.
5
+ * Global block definitions resolve slug references; inline slot blocks retain host configs.
6
6
  */ export function freshBlockIds(value, field, config = {}, mint = ()=>globalThis.crypto.randomUUID()) {
7
7
  function copyObject(data, fields, parentIsLocalized = false) {
8
8
  const result = {
@@ -37,10 +37,7 @@ import { BLOCK_SLOTS, EXPERIMENT_BLOCK_SLUG, isObject, slotBlocks } from './mode
37
37
  function copyRows(data, rowsField, parentIsLocalized = false) {
38
38
  if (Array.isArray(data)) return data.map((row)=>{
39
39
  if (!isObject(row)) return row;
40
- const fields = rowsField.type === 'array' ? rowsField.fields : (config.blocks?.find((block)=>block.slug === row.blockType) ?? [
41
- ...rowsField.blocks,
42
- ...(rowsField.blockReferences ?? []).filter((block)=>typeof block !== 'string')
43
- ].find((block)=>block.slug === row.blockType))?.fields ?? [];
40
+ const fields = rowsField.type === 'array' ? rowsField.fields : (config.blocks?.find((block)=>block.slug === row.blockType) ?? rowsField.blocks.find((block)=>typeof block !== 'string' && block.slug === row.blockType))?.fields ?? [];
44
41
  return {
45
42
  ...copyObject(row, fields, parentIsLocalized),
46
43
  id: mint()
@@ -4,7 +4,7 @@ import { documentEditor, puckCollections } from '../options.js';
4
4
  import { placementSlugs } from './bindings.js';
5
5
  import { contentBlocks, hasLocalizedFields } from '../transitions/contentFields.js';
6
6
  import { isObject } from './model.js';
7
- import { isPublicationStatus, payloadPublishesAllByDefault, publicationStatusInLocale, publishedInLocale, usesLocalizedPublication } from './placementPublication.js';
7
+ import { isPublicationStatus, publicationStatusInLocale, publishedInLocale, usesLocalizedPublication } from './placementPublication.js';
8
8
  import { usesRelationalBlocks } from '../db/adapter.js';
9
9
  const identity = (data)=>data;
10
10
  // Sanitized schemas are immutable. Weak ownership keeps separate Payload configs
@@ -50,10 +50,7 @@ const localeTransforms = new WeakMap();
50
50
  'array',
51
51
  'tab'
52
52
  ].includes(field.type) ? compile(field.fields, parent) : undefined;
53
- const variants = field.type === 'blocks' ? new Map([
54
- ...field.blocks ?? [],
55
- ...field.blockReferences ?? []
56
- ].flatMap((ref)=>{
53
+ const variants = field.type === 'blocks' ? new Map(field.blocks.flatMap((ref)=>{
57
54
  const block = typeof ref === 'string' ? blocks.find((block)=>block.slug === ref) : ref;
58
55
  return block && hasLocalizedFields(block.fields, payloadConfig) ? [
59
56
  [
@@ -80,9 +77,9 @@ const localeTransforms = new WeakMap();
80
77
  ...existing,
81
78
  [locale]: storedValue(value)
82
79
  };
83
- else if (payloadPublishesAllByDefault) value = {
80
+ else if (isObject(value)) value = {
84
81
  ...existing,
85
- ...Object.fromEntries(Object.entries(isObject(value) ? value : {}).map(([code, input])=>[
82
+ ...Object.fromEntries(Object.entries(value).map(([code, input])=>[
86
83
  code,
87
84
  storedValue(input)
88
85
  ]))
@@ -297,10 +294,10 @@ export function selectPlacementLocales(req, collection, doc, keep) {
297
294
  if (!localization) return data;
298
295
  const locale = req.locale || localization.defaultLocale;
299
296
  const selected = isObject(status) ? status[locale] : status;
300
- // V3 merges every single-locale live update with main. V4 does that on
301
- // publish, while unpublish uses the unmerged result of beforeChange.
302
- const isolatedPublish = !restore && !all && payloadPublishesAllByDefault && selected === 'published' && locale !== 'all';
303
- let source = !restore && !all && main && (!payloadPublishesAllByDefault || isolatedPublish) ? main : base;
297
+ // Payload 4 merges a single-locale publish with the published locales of
298
+ // the main row. Unpublish writes from the operation's own merge base.
299
+ const isolatedPublish = !restore && !all && selected === 'published' && locale !== 'all';
300
+ let source = isolatedPublish && main ? main : base;
304
301
  const before = isObject(source?._status) ? source._status : {};
305
302
  const statuses = {
306
303
  ...before
@@ -310,8 +307,8 @@ export function selectPlacementLocales(req, collection, doc, keep) {
310
307
  }
311
308
  if (all) for (const code of all.locales)statuses[code] = all.status;
312
309
  else if (locale !== 'all' && isPublicationStatus(selected)) statuses[locale] = selected;
313
- else if (locale === 'all' && isObject(status) && (payloadPublishesAllByDefault || !main)) Object.assign(statuses, status);
314
- else if (locale === 'all' && payloadPublishesAllByDefault && isPublicationStatus(status) && !Object.keys(before).length) {
310
+ else if (locale === 'all' && isObject(status)) Object.assign(statuses, status);
311
+ else if (locale === 'all' && isPublicationStatus(status) && !Object.keys(before).length) {
315
312
  for (const code of localization.localeCodes)statuses[code] = status;
316
313
  }
317
314
  const merged = localeTransform(req.payload.config, collection, locale, false)(data, true, source, {
@@ -1,5 +1,4 @@
1
1
  import type { PayloadRequest, SanitizedCollectionConfig } from 'payload';
2
- export declare const payloadPublishesAllByDefault: boolean;
3
2
  export declare function usesLocalizedPublication(req: PayloadRequest, collection: string, config?: SanitizedCollectionConfig): boolean;
4
3
  export type PublicationStatus = 'published' | 'draft';
5
4
  export type PublicationFlags = {
@@ -12,6 +11,7 @@ export declare function isPublicationStatus(value: unknown): value is Publicatio
12
11
  export declare function allLocalesStatus(req: PayloadRequest, flags: PublicationFlags | undefined, status: unknown, operation: 'create' | 'update'): PublicationStatus | undefined;
13
12
  export declare function publicationStatusInLocale(doc: Record<string, unknown> | null | undefined, locale: string): PublicationStatus | undefined;
14
13
  export declare function publishedInLocale(doc: Record<string, unknown> | null | undefined, locale: string): boolean;
14
+ export declare function hasPublishedLocale(doc: Record<string, unknown>): boolean;
15
15
  /** The locale of a single-document read. All-locale callers can choose an explicit view. */
16
16
  export declare function publicationLocale(req: PayloadRequest): string | undefined;
17
17
  /** Local API reads can already have projected the status to the selected locale. */
@@ -1,8 +1,4 @@
1
- import * as payloadCore from 'payload';
2
1
  import { isObject } from './model.js';
3
- // Payload 4 dropped createLocalReq and made a non-draft locale=all save an
4
- // all-locale publish by default. Payload 3 requires the explicit flag.
5
- export const payloadPublishesAllByDefault = !('createLocalReq' in payloadCore);
6
2
  export function usesLocalizedPublication(req, collection, config) {
7
3
  const versions = (config ?? req.payload.config.collections?.find((entry)=>entry.slug === collection))?.versions;
8
4
  return Boolean(req.payload.config.localization && versions && versions.drafts && versions.drafts.localizeStatus);
@@ -12,7 +8,9 @@ export function isPublicationStatus(value) {
12
8
  }
13
9
  export function allLocalesStatus(req, flags, status, operation) {
14
10
  if (flags?.unpublishAllLocales && status === 'draft') return 'draft';
15
- const publishAll = flags?.publishAllLocales ?? (operation === 'update' && payloadPublishesAllByDefault && req.locale === 'all');
11
+ // Payload 4's create operation omits locale from the default calculation.
12
+ // For localized drafts, only a non-draft locale=all update defaults to Publish All.
13
+ const publishAll = flags?.publishAllLocales ?? (operation === 'update' && req.locale === 'all');
16
14
  if (!flags?.draft && publishAll && status === 'published') return 'published';
17
15
  }
18
16
  export function publicationStatusInLocale(doc, locale) {
@@ -22,6 +20,9 @@ export function publicationStatusInLocale(doc, locale) {
22
20
  export function publishedInLocale(doc, locale) {
23
21
  return publicationStatusInLocale(doc, locale) === 'published';
24
22
  }
23
+ export function hasPublishedLocale(doc) {
24
+ return isObject(doc._status) && Object.keys(doc._status).some((locale)=>publishedInLocale(doc, locale));
25
+ }
25
26
  /** The locale of a single-document read. All-locale callers can choose an explicit view. */ export function publicationLocale(req) {
26
27
  return req.locale && req.locale !== 'all' ? req.locale : req.payload.config.localization ? req.payload.config.localization.defaultLocale : undefined;
27
28
  }
@@ -7,6 +7,7 @@ export declare function managedAccess(options: ResolvedOptions): {
7
7
  create: Access;
8
8
  read: Access;
9
9
  update: Access;
10
+ validate: Access;
10
11
  delete: Access;
11
12
  readVersions: Access;
12
13
  unlock: Access;
@@ -15,6 +16,7 @@ export declare function readOnlyAccess(read: ExperimentsAccess): {
15
16
  create: Access;
16
17
  read: Access;
17
18
  update: Access;
19
+ validate: Access;
18
20
  delete: Access;
19
21
  readVersions: Access;
20
22
  unlock: Access;
@@ -8,6 +8,7 @@ export function managedAccess(options) {
8
8
  create: manage,
9
9
  read: manage,
10
10
  update: manage,
11
+ validate: manage,
11
12
  delete: manage,
12
13
  readVersions: manage,
13
14
  unlock: manage
@@ -18,6 +19,7 @@ export function readOnlyAccess(read) {
18
19
  create: deny,
19
20
  read: isTrue(read),
20
21
  update: deny,
22
+ validate: deny,
21
23
  delete: deny,
22
24
  readVersions: deny,
23
25
  unlock: deny
@@ -2,6 +2,7 @@ import { readOnlyAccess } from './access.js';
2
2
  function hiddenCollection(options) {
3
3
  return {
4
4
  graphQL: false,
5
+ authorship: false,
5
6
  versions: false,
6
7
  disableDuplicate: true,
7
8
  admin: {
@@ -3,6 +3,7 @@ export function eventsCollection(options) {
3
3
  return {
4
4
  slug: 'xp-events',
5
5
  graphQL: false,
6
+ authorship: false,
6
7
  disableDuplicate: true,
7
8
  versions: false,
8
9
  admin: {
@@ -48,6 +48,7 @@ export function experimentsCollection(options) {
48
48
  return {
49
49
  slug: 'xp-experiments',
50
50
  graphQL: false,
51
+ authorship: false,
51
52
  disableDuplicate: true,
52
53
  versions: {
53
54
  drafts: false,
@@ -541,7 +542,7 @@ export function experimentsCollection(options) {
541
542
  type: 'text',
542
543
  hooks: {
543
544
  beforeValidate: [
544
- ({ operation, value })=>operation === 'create' && value === undefined ? options.timeZone : value
545
+ ({ operation, originalDoc, value })=>(operation === 'create' || operation === 'validate' && originalDoc?.id == null) && value === undefined ? options.timeZone : value
545
546
  ]
546
547
  },
547
548
  validate: (value)=>value == null || value === '' || isValidTimeZone(value) || SCHEDULE_VALIDATION.timeZone
@@ -1,9 +1,10 @@
1
1
  import { defaultArms } from './armInvariants.js';
2
- export const createDefaults = ({ data, operation })=>{
3
- if (operation === 'create' && data && (!data.arms || Array.isArray(data.arms) && data.arms.length === 0)) {
2
+ export const createDefaults = ({ data, operation, originalDoc })=>{
3
+ const creating = operation === 'create' || operation === 'validate' && originalDoc?.id == null;
4
+ if (creating && data && (!data.arms || Array.isArray(data.arms) && data.arms.length === 0)) {
4
5
  data.arms = defaultArms(data.kind);
5
6
  }
6
- if (operation === 'create' && data && data.analysis?.plannedDurationDays == null) {
7
+ if (creating && data && data.analysis?.plannedDurationDays == null) {
7
8
  data.analysis = {
8
9
  ...data.analysis,
9
10
  plannedDurationDays: 28
@@ -1,7 +1,8 @@
1
1
  import { xpOptionsFromReq } from '../../options/fromReq.js';
2
2
  export const flagControlParams = async ({ data, originalDoc, operation, req })=>{
3
3
  const kind = data.kind ?? originalDoc?.kind;
4
- const status = operation === 'create' ? 'draft' : originalDoc?.status;
4
+ const creating = operation === 'create' || operation === 'validate' && originalDoc?.id == null;
5
+ const status = creating ? 'draft' : originalDoc?.status;
5
6
  if (kind !== 'flag' || status !== 'draft' && status !== 'stopped') return data;
6
7
  const pointId = data.flagPoint ?? originalDoc?.flagPoint;
7
8
  const point = xpOptionsFromReq(req).flagPoints?.find((point)=>point.id === pointId);
@@ -78,8 +78,10 @@ const dates = new Set([
78
78
  }
79
79
  const same = (a, b, path)=>JSON.stringify(normalize(a, path)) === JSON.stringify(normalize(b, path));
80
80
  export const lockHook = async ({ data, originalDoc, operation, req })=>{
81
- const kind = operation === 'create' ? data.kind : originalDoc.kind;
82
- const storedArms = operation === 'update' ? originalDoc.arms : undefined;
81
+ // Payload supplies an empty originalDoc for create validation and the stored doc for update validation.
82
+ const creating = operation === 'create' || operation === 'validate' && originalDoc?.id == null;
83
+ const kind = creating ? data.kind : originalDoc.kind;
84
+ const storedArms = creating ? undefined : originalDoc.arms;
83
85
  const canonicalSlots = (value)=>{
84
86
  if (kind !== 'block' || !Array.isArray(value) || value.some((row)=>!isObject(row))) return value;
85
87
  return withSlotsFor(value, 'block');
@@ -90,7 +92,7 @@ export const lockHook = async ({ data, originalDoc, operation, req })=>{
90
92
  const arms = data.arms === undefined ? storedArms : data.arms;
91
93
  const repaired = arms === storedArms ? canonicalArms : canonicalSlots(arms);
92
94
  if (repaired !== arms) {
93
- if (operation === 'create') data = {
95
+ if (creating) data = {
94
96
  ...data,
95
97
  arms: repaired
96
98
  };
@@ -112,7 +114,7 @@ export const lockHook = async ({ data, originalDoc, operation, req })=>{
112
114
  req
113
115
  }) === true;
114
116
  };
115
- if (operation === 'create') {
117
+ if (creating) {
116
118
  const result = {
117
119
  ...data,
118
120
  status: 'draft',
@@ -3,6 +3,7 @@ export function identitiesCollection(options) {
3
3
  return {
4
4
  slug: 'xp-identities',
5
5
  graphQL: false,
6
+ authorship: false,
6
7
  disableDuplicate: true,
7
8
  versions: false,
8
9
  admin: {
@@ -11,6 +11,7 @@ export function layersCollection(options) {
11
11
  return {
12
12
  slug: 'xp-layers',
13
13
  graphQL: false,
14
+ authorship: false,
14
15
  disableDuplicate: true,
15
16
  versions: false,
16
17
  // group:false hides navigation while keeping collection routes reachable (hidden causes 404s).
@@ -10,6 +10,7 @@ export function metricsCollection(options) {
10
10
  return {
11
11
  slug: 'xp-metrics',
12
12
  graphQL: false,
13
+ authorship: false,
13
14
  disableDuplicate: true,
14
15
  versions: false,
15
16
  labels: {
@@ -3,6 +3,7 @@ export function phasesCollection(options) {
3
3
  return {
4
4
  slug: 'xp-phases',
5
5
  graphQL: false,
6
+ authorship: false,
6
7
  disableDuplicate: true,
7
8
  versions: false,
8
9
  admin: {
@@ -3,6 +3,7 @@ export function snapshotsCollection(options) {
3
3
  return {
4
4
  slug: 'xp-results-snapshots',
5
5
  graphQL: false,
6
+ authorship: false,
6
7
  disableDuplicate: true,
7
8
  versions: false,
8
9
  admin: {
@@ -29,14 +29,11 @@ export interface PlacementSavePath {
29
29
  bulk?: boolean;
30
30
  draft?: boolean;
31
31
  trashing?: boolean;
32
- publishSpecificLocale?: string;
33
32
  }
34
- /** Payload 3.90.2: updateByID starts from the latest version; update (bulk)
35
- * starts from main rows except draft/trash saves. utilities/update then replaces
36
- * unselected locales with the latest published version (publishSpecificLocale).
37
- * Localized status uses the main row for a single-locale publish. The caller
38
- * selects that base separately. Restore uses the selected version. */
39
- export declare function placementMergeBase(path: PlacementSavePath): 'restore' | 'main' | 'published' | 'latest';
33
+ /** Payload 4 starts by-ID updates from the latest version and bulk updates
34
+ * from main rows except draft/trash saves. Restore uses the selected version.
35
+ * For a single-locale publish the caller merges the result with main. */
36
+ export declare function placementMergeBase(path: PlacementSavePath): 'restore' | 'main' | 'latest';
40
37
  export declare function placementWriteContent(req: PayloadRequest, collection: string, id: DocId, main: Record<string, unknown> | undefined, path?: PlacementSavePath): Promise<Record<string, unknown> | undefined>;
41
38
  /** Read the main collection row BEFORE the host write. Draft version retention
42
39
  * and unpublishing cannot remove this baseline.
@@ -18,13 +18,10 @@ import { qualifiedTable, quoteIdentifier as quote } from './sql.js';
18
18
  });
19
19
  return doc ?? undefined;
20
20
  }
21
- /** Payload 3.90.2: updateByID starts from the latest version; update (bulk)
22
- * starts from main rows except draft/trash saves. utilities/update then replaces
23
- * unselected locales with the latest published version (publishSpecificLocale).
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
- base === 'published' ? {
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
- } : base === 'published' ? undefined : main;
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.
@@ -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 drafts = req.payload.config.collections?.find((c)=>c.slug === collection)?.versions;
21
- return doc && (!(drafts && drafts.drafts) || doc._status === 'published') ? doc : undefined;
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
  }