@delmaredigital/payload-experiments 0.4.0-rc.7 → 0.4.0-rc.9
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 +12 -12
- package/dist/admin/blocks/model.js +2 -2
- package/dist/admin/copy/blocks.js +1 -1
- package/dist/admin/surface/ResultsRoute.js +17 -11
- package/dist/admin/surface/TestsHome.js +53 -20
- package/dist/admin/surface/newTest/PageWizard.js +8 -2
- package/dist/admin/surface/results/ResultsHeader.js +11 -6
- package/dist/admin/surface/test/TestPage.js +3 -3
- package/dist/blocks/formState.js +1 -1
- package/dist/collections/experiments/config.js +8 -3
- package/dist/collections/experiments/deleteGuard.js +2 -2
- package/dist/collections/experiments/lockHook.js +21 -2
- package/dist/collections/experiments/pickSlug.js +2 -0
- package/dist/collections/metricsGuards.js +2 -0
- package/dist/collections/serialize.js +5 -4
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/db/adapter.d.ts +9 -1
- package/dist/db/adapter.js +77 -1
- package/dist/db/delete.d.ts +1 -1
- package/dist/db/delete.js +2 -4
- package/dist/db/events.d.ts +9 -0
- package/dist/db/events.js +42 -8
- package/dist/db/executor.d.ts +7 -1
- package/dist/db/executor.js +7 -3
- package/dist/db/results.d.ts +5 -1
- package/dist/db/results.js +21 -5
- package/dist/db/snapshots.d.ts +1 -0
- package/dist/endpoints/deleteImpact.js +2 -1
- package/dist/endpoints/events.js +103 -39
- package/dist/endpoints/index.js +2 -8
- package/dist/endpoints/placementStatus.js +7 -4
- package/dist/endpoints/results.d.ts +1 -1
- package/dist/endpoints/results.js +6 -2
- package/dist/endpoints/routeId.d.ts +2 -2
- package/dist/endpoints/routeId.js +11 -5
- package/dist/endpoints/summary.js +46 -12
- package/dist/endpoints/transitions.js +37 -24
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +6 -0
- package/dist/events/request.d.ts +6 -2
- package/dist/events/request.js +35 -8
- package/dist/events/rows.d.ts +1 -1
- package/dist/events/rows.js +24 -8
- package/dist/events/writable.d.ts +9 -0
- package/dist/events/writable.js +13 -0
- package/dist/exports/index.d.ts +1 -1
- package/dist/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +1 -0
- package/dist/goals/fairness.js +2 -2
- package/dist/hooks/hostHook.js +6 -2
- package/dist/hooks/pageGuard.js +4 -0
- package/dist/lib/fetchAllDocs.d.ts +1 -1
- package/dist/manifest/compile.js +8 -5
- package/dist/onInit.js +14 -0
- package/dist/options.js +5 -0
- package/dist/proxy/pageNavigation.d.ts +4 -0
- package/dist/proxy/pageNavigation.js +28 -0
- package/dist/proxy/resolve.js +52 -25
- package/dist/puck/editor/ConfigureTestDrawer.js +5 -4
- package/dist/puck/editor/ExperimentSlotEditor.js +182 -58
- package/dist/puck/editor/QuickTestActions.d.ts +5 -2
- package/dist/puck/editor/QuickTestActions.js +16 -4
- package/dist/puck/editor/ResultsReadout.d.ts +2 -1
- package/dist/puck/editor/ResultsReadout.js +2 -1
- package/dist/puck/editor/VersionBuilder.d.ts +13 -2
- package/dist/puck/editor/VersionBuilder.js +133 -49
- package/dist/puck/editor/armWrites.js +1 -1
- package/dist/puck/editor/armsCache.js +1 -3
- package/dist/puck/editor/copy.d.ts +4 -1
- package/dist/puck/editor/copy.js +4 -1
- package/dist/puck/editor/editor.chrome.css +1 -0
- package/dist/puck/editor/editor.css +1 -0
- package/dist/puck/editor/editor.model.d.ts +1 -0
- package/dist/puck/editor/placementsCache.d.ts +5 -1
- package/dist/puck/editor/placementsCache.js +17 -9
- package/dist/puck/editor/usePageSaveReadiness.d.ts +9 -0
- package/dist/puck/editor/usePageSaveReadiness.js +34 -0
- package/dist/puck/editor/usePlacementNotice.d.ts +2 -2
- package/dist/puck/editor/usePlacementNotice.js +5 -4
- package/dist/results/aggregate.d.ts +6 -3
- package/dist/results/aggregate.js +9 -9
- package/dist/results/health.d.ts +8 -0
- package/dist/results/health.js +28 -0
- package/dist/results/identityCredit.d.ts +1 -0
- package/dist/results/identityCredit.js +4 -1
- package/dist/results/verdict.js +2 -1
- package/dist/runtime/cookie.d.ts +10 -2
- package/dist/runtime/cookie.js +38 -6
- package/dist/runtime/cookieOptions.d.ts +6 -0
- package/dist/runtime/cookieOptions.js +14 -0
- package/dist/runtime/proxyRuntime.d.ts +1 -0
- package/dist/runtime/proxyRuntime.js +18 -8
- package/dist/runtime/signing.d.ts +1 -0
- package/dist/runtime/signing.js +5 -0
- package/dist/sanitizeReadinessDetail.d.ts +2 -2
- package/dist/sanitizeReadinessDetail.js +20 -2
- package/dist/server/getAssignments.js +11 -10
- package/dist/server/recordContentChange.d.ts +1 -1
- package/dist/server/recordContentChange.js +11 -2
- package/dist/server/resolveExperimentBlocks.js +2 -4
- package/dist/server/resolveExperimentData.js +2 -5
- package/dist/server/runResults.js +52 -14
- package/dist/server/startExperiment.d.ts +20 -0
- package/dist/server/startExperiment.js +70 -0
- package/dist/server/trackConversion.js +10 -13
- package/dist/testSurface/actions/DecideDialog.d.ts +4 -1
- package/dist/testSurface/actions/DecideDialog.js +32 -14
- package/dist/testSurface/actions/MakeContentResult.d.ts +4 -3
- package/dist/testSurface/actions/MakeContentResult.js +9 -1
- package/dist/testSurface/api.d.ts +5 -5
- package/dist/testSurface/api.js +21 -9
- package/dist/testSurface/copy/actions.d.ts +1 -0
- package/dist/testSurface/copy/actions.js +1 -0
- package/dist/testSurface/copy/common.d.ts +3 -1
- package/dist/testSurface/copy/common.js +4 -2
- package/dist/testSurface/copy/languages.d.ts +1 -0
- package/dist/testSurface/copy/languages.js +1 -0
- package/dist/testSurface/copy/metrics.d.ts +1 -0
- package/dist/testSurface/copy/metrics.js +1 -0
- package/dist/testSurface/copy/readiness.d.ts +12 -1
- package/dist/testSurface/copy/readiness.js +18 -1
- package/dist/testSurface/copy/results.d.ts +5 -2
- package/dist/testSurface/copy/results.js +5 -2
- package/dist/testSurface/copy/testPage.d.ts +20 -2
- package/dist/testSurface/copy/testPage.js +34 -3
- package/dist/testSurface/readPreflight.d.ts +5 -0
- package/dist/testSurface/readPreflight.js +7 -0
- package/dist/testSurface/readinessRead.d.ts +3 -0
- package/dist/testSurface/readinessRead.js +4 -0
- package/dist/testSurface/results/VerdictHero.d.ts +2 -1
- package/dist/testSurface/results/VerdictHero.js +5 -1
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/results/results.model.js +6 -2
- package/dist/testSurface/surface/contracts.d.ts +8 -1
- package/dist/testSurface/surface/editorPlacement.d.ts +2 -2
- package/dist/testSurface/surface/editorPlacement.js +1 -1
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -2
- package/dist/testSurface/surface/pagePicker/PageCombobox.js +20 -6
- package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +4 -2
- package/dist/testSurface/surface/readiness/ActionDialogs.js +39 -34
- package/dist/testSurface/surface/readiness/Banner.js +23 -12
- package/dist/testSurface/surface/readiness/SaveStatus.d.ts +4 -3
- package/dist/testSurface/surface/readiness/SaveStatus.js +15 -15
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +6 -1
- package/dist/testSurface/surface/readiness/readiness.model.js +108 -11
- package/dist/testSurface/surface/readiness/useTransition.d.ts +4 -4
- package/dist/testSurface/surface/readiness/useTransition.js +12 -10
- package/dist/testSurface/surface/results/ReleasePages.d.ts +4 -2
- package/dist/testSurface/surface/results/ReleasePages.js +5 -4
- package/dist/testSurface/surface/results/ResultsBody.d.ts +4 -2
- package/dist/testSurface/surface/results/ResultsBody.js +86 -43
- package/dist/testSurface/surface/results/useResults.d.ts +7 -6
- package/dist/testSurface/surface/results/useResults.js +3 -2
- package/dist/testSurface/surface/setting/parts.js +58 -18
- package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
- package/dist/testSurface/surface/test/DeleteTest.d.ts +6 -2
- package/dist/testSurface/surface/test/DeleteTest.js +145 -54
- package/dist/testSurface/surface/test/GoalSection.js +7 -3
- package/dist/testSurface/surface/test/LengthSection.js +3 -0
- package/dist/testSurface/surface/test/PageHoldout.js +4 -1
- package/dist/testSurface/surface/test/ReadinessBar.js +1 -1
- package/dist/testSurface/surface/test/TargetingSection.js +77 -12
- package/dist/testSurface/surface/test/TestSurface.js +81 -19
- package/dist/testSurface/surface/test/VersionsSection.js +56 -29
- package/dist/testSurface/surface/test/fields.d.ts +29 -4
- package/dist/testSurface/surface/test/fields.js +159 -39
- package/dist/testSurface/surface/test/pageParts.js +14 -5
- package/dist/testSurface/surface/test/testPage.model.d.ts +1 -0
- package/dist/testSurface/surface/test/testPage.model.js +6 -0
- package/dist/testSurface/surface/testDocument.model.d.ts +3 -0
- package/dist/testSurface/surface/testDocument.model.js +4 -1
- package/dist/testSurface/surface/useTestDocument.d.ts +22 -4
- package/dist/testSurface/surface/useTestDocument.js +407 -160
- package/dist/testSurface/useApi.d.ts +5 -5
- package/dist/testSurface/useOnTestReturn.d.ts +2 -0
- package/dist/testSurface/useOnTestReturn.js +27 -0
- package/dist/testSurface/useReadinessPolling.js +3 -1
- package/dist/transitions/addMetric.d.ts +1 -4
- package/dist/transitions/allocate.d.ts +2 -2
- package/dist/transitions/allocate.js +3 -1
- package/dist/transitions/archive.d.ts +1 -1
- package/dist/transitions/archive.js +3 -2
- package/dist/transitions/checkStart.d.ts +1 -0
- package/dist/transitions/checkStart.js +17 -6
- package/dist/transitions/decide.d.ts +1 -1
- package/dist/transitions/decide.js +5 -3
- package/dist/transitions/deleteExperiment.d.ts +2 -2
- package/dist/transitions/deleteExperiment.js +17 -7
- package/dist/transitions/kernel.d.ts +2 -0
- package/dist/transitions/kernel.js +9 -4
- package/dist/transitions/makeContent.d.ts +2 -1
- package/dist/transitions/makeContent.js +12 -8
- package/dist/transitions/nestedPlacementNames.d.ts +2 -2
- package/dist/transitions/nestedPlacementNames.js +4 -5
- package/dist/transitions/phaseRecord.d.ts +2 -0
- package/dist/transitions/phaseRecord.js +5 -0
- package/dist/transitions/placementInteractions.d.ts +3 -3
- package/dist/transitions/placementInteractions.js +8 -7
- package/dist/transitions/placements.d.ts +2 -0
- package/dist/transitions/placements.js +5 -5
- package/dist/transitions/preflightData.d.ts +3 -2
- package/dist/transitions/preflightData.js +67 -41
- package/dist/transitions/releaseHoldout.d.ts +2 -1
- package/dist/transitions/releaseHoldout.js +3 -1
- package/dist/transitions/releasePages.d.ts +2 -1
- package/dist/transitions/releasePages.js +3 -1
- package/dist/transitions/resolveCaps.d.ts +2 -4
- package/dist/transitions/start.d.ts +6 -8
- package/dist/transitions/start.js +67 -34
- package/dist/transitions/startReads.d.ts +7 -0
- package/dist/transitions/startReads.js +28 -0
- package/dist/transitions/stop.d.ts +2 -1
- package/dist/transitions/stop.js +3 -2
- package/dist/types/contracts.d.ts +6 -3
- package/dist/types/endpoints.d.ts +52 -9
- package/dist/types/runtime.d.ts +15 -9
- package/dist/types/snapshot.d.ts +2 -0
- package/dist/ui/ChipsInput.d.ts +8 -1
- package/dist/ui/ChipsInput.js +17 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
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.
|
|
4
4
|
|
|
5
|
-
> ⚠️ Upgrading
|
|
5
|
+
> ⚠️ Upgrading from 0.4.0-rc.8 to rc.9? Set `events.rateLimit` and `rateLimitUnit`, or explicitly use `false` for requests you limit upstream. Use signing keys of at least 32 characters, including previous rotation keys. Serve events on the page's origin, preserve `Sec-Fetch-Site`, `Origin`, and `Referer`, and configure the public origin in `events.origin` or Payload's `serverURL`. If you use a reverse proxy, forward the browser-facing host and protocol. Set `skipProxyUrlNormalize: true` and keep full prefetch off experiment routes. Use matching cookie settings in the proxy and event handler and cap `cookie.maxAgeDays` at 400. Deploy proxies and event handlers together because an older proxy can reissue IDs. Pre-rc.9 IDs expire on January 7, 2028 at 00:00 UTC by default. Drain older `trackConversion` writers before upgraded writers use the same event table. Update exhaustive TypeScript switches and records over `SnapshotHealth` and `RefusalCode`. See the [rc.9 upgrade steps](https://plugins.delmaredigital.com/docs/experiments/upgrading#from-040-rc7-or-rc8-to-rc9).
|
|
6
|
+
|
|
7
|
+
> ⚠️ Upgrading from 0.4.0-rc.7? Apply the rc.9 runtime steps above and set the Postgres adapter's `transactionOptions.isolationLevel` to `'read committed'` or remove the override if the database has a supported default. PostgreSQL treats `READ UNCOMMITTED` as `READ COMMITTED`, so both are supported. The app refuses to start with other levels. If your client expects HTTP `403` when a manager deletes a running, stopped, or decided test by ID, handle HTTP `409` with code `invalid-status` and ask the manager to archive the test first. See the [rc.8 release notes](https://github.com/delmaredigital/payload-experiments/blob/main/CHANGELOG.md#040-rc8---2026-12-01).
|
|
8
|
+
|
|
9
|
+
> ⚠️ Upgrading to 0.4 from 0.3? Run `payload migrate:create` for four nullable plugin columns (`xp_experiments.page_collection`, `_xp_experiments_v.version_page_collection`, `xp_phases.placement_docs`, and `xp_state.retired_slugs`), plus the Experiment block and `xpGoal` changes if you adopt them. Apply the migration and run `payload generate:importmap`. Use PostgreSQL `READ COMMITTED` for default and guarded host transactions. PostgreSQL's `READ UNCOMMITTED` is equivalent. Update clients that expect HTTP `403` when a manager deletes a running, stopped, or decided test by ID. Handle HTTP `409` with code `invalid-status` and ask the manager to archive first. Registered page and block saves can be refused with `page-busy` or `interacting-tests`. Publish draft-only placements before starting a test, and publish the Original and winning pages before deciding a stopped whole-page test. Reserve `click:` for click goals and update `admin.editorUrl` for its required `editor` argument. Apply the runtime requirements in the rc.9 callout above. See the [full 0.4 upgrade steps](https://plugins.delmaredigital.com/docs/experiments/upgrading#to-04).
|
|
6
10
|
|
|
7
11
|
## Install
|
|
8
12
|
|
|
@@ -12,7 +16,7 @@ pnpm add @delmaredigital/payload-experiments
|
|
|
12
16
|
|
|
13
17
|
### Requirements
|
|
14
18
|
|
|
15
|
-
Use Node.js `>=22.23.4`, the Next.js App Router, and Postgres through `@payloadcms/db-postgres` with transactions enabled. Puck is optional. Install the peers your application uses:
|
|
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:
|
|
16
20
|
|
|
17
21
|
| Peer | Version |
|
|
18
22
|
| --- | --- |
|
|
@@ -28,23 +32,20 @@ These examples use your existing Payload app and Pages collection. Imports start
|
|
|
28
32
|
|
|
29
33
|
### 1. Set a secret and create the runtimes
|
|
30
34
|
|
|
31
|
-
Set a private `XP_SECRET` in your server environment.
|
|
35
|
+
Set a private `XP_SECRET` of at least 32 characters in your server environment. Use the shared Postgres pool from the [rate limiter example](https://plugins.delmaredigital.com/docs/experiments/installation#rate-limit-browser-traffic).
|
|
32
36
|
|
|
33
37
|
```ts
|
|
34
38
|
// src/experiments/proxyRuntime.ts
|
|
35
|
-
import { Pool } from 'pg'
|
|
36
39
|
import {
|
|
37
40
|
defineExperimentsProxyRuntime,
|
|
38
41
|
createPostgresManifestLoader,
|
|
39
42
|
} from '@delmaredigital/payload-experiments/runtime/proxy'
|
|
43
|
+
import { allowNewVisitor, pool } from '@/experiments/rateLimit'
|
|
40
44
|
|
|
41
|
-
const pool = new Pool({
|
|
42
|
-
connectionString: process.env.DATABASE_URI,
|
|
43
|
-
connectionTimeoutMillis: 5_000,
|
|
44
|
-
})
|
|
45
45
|
export const proxyRuntime = defineExperimentsProxyRuntime({
|
|
46
46
|
secret: process.env.XP_SECRET!,
|
|
47
47
|
apiRoute: '/api', // match Payload's routes.api
|
|
48
|
+
rateLimitUnit: allowNewVisitor,
|
|
48
49
|
loadManifest: createPostgresManifestLoader({ pool }),
|
|
49
50
|
})
|
|
50
51
|
```
|
|
@@ -74,17 +75,16 @@ Add this to your existing `payload.config.ts` plugins array. Your permission che
|
|
|
74
75
|
import { createExperimentsPlugin } from '@delmaredigital/payload-experiments'
|
|
75
76
|
import { serverRuntime } from '@/experiments/serverRuntime'
|
|
76
77
|
import { canManageTests } from '@/access/tests'
|
|
77
|
-
import {
|
|
78
|
+
import { allowExperimentEvents } from '@/experiments/rateLimit'
|
|
78
79
|
|
|
79
80
|
createExperimentsPlugin({
|
|
80
81
|
runtime: serverRuntime,
|
|
81
82
|
access: { manage: canManageTests },
|
|
82
|
-
events: { rateLimit:
|
|
83
|
+
events: { rateLimit: allowExperimentEvents },
|
|
83
84
|
})
|
|
84
85
|
```
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
`{ req, unitId }` and returns `true` to permit or `false` to drop a request.
|
|
87
|
+
Use shared rate limiters keyed by a trusted client address. `events.rateLimit` receives `{ req, unitId }`, with `unitId` available as context only. `rateLimitUnit` receives the `NextRequest` before a new visitor cookie is issued. Each adapter returns `true` to allow the operation. Set either option to `false` only when a firewall or equivalent upstream control limits the corresponding events or page requests, since doing so disables the plugin's rate limit for that traffic. Serve the browser events route on the same origin as your pages and set `events.origin` or Payload's `serverURL` to that public origin. See the [shared rate limiter example](https://plugins.delmaredigital.com/docs/experiments/installation#rate-limit-browser-traffic).
|
|
88
88
|
Keep identifying attributes out of `events.dimensions`. Use the proxy runtime's `cookie.consent` to enrol only after consent (`ExperimentsProxyRuntimeOptions`); `eraseUser(payload, { userId })` from `/rsc` handles privacy erasure (typed by that exported function).
|
|
89
89
|
|
|
90
90
|
### 3. Run migrations and generate the import map
|
|
@@ -4,7 +4,7 @@ export function liveStatus(status) {
|
|
|
4
4
|
return !!status && 'status' in status;
|
|
5
5
|
}
|
|
6
6
|
export function slotLabel(slot, status) {
|
|
7
|
-
return (liveStatus(status) ? status.arms.find((arm)=>arm.key !== 'holdout' &&
|
|
7
|
+
return (liveStatus(status) ? status.arms.find((arm)=>arm.key !== 'holdout' && arm.key === slot)?.label : undefined) || BLOCK_COPY.slotLabels[slot] || slot;
|
|
8
8
|
}
|
|
9
9
|
export function statusSentence(status) {
|
|
10
10
|
if (!liveStatus(status)) return BLOCK_COPY.deleted;
|
|
@@ -27,7 +27,7 @@ export function canUnwrapOriginal(status, block) {
|
|
|
27
27
|
if (!liveStatus(status)) return true;
|
|
28
28
|
if (status.status !== 'archived') return false;
|
|
29
29
|
if (status.discarded || !status.winnerArm || status.winnerArm === 'control') return true;
|
|
30
|
-
const slot = status.
|
|
30
|
+
const slot = status.winnerArm;
|
|
31
31
|
return !!block && slotBlocks(block, slot).length === 0;
|
|
32
32
|
}
|
|
33
33
|
export function labelText(value) {
|
|
@@ -10,7 +10,7 @@ export const BLOCK_COPY = {
|
|
|
10
10
|
saveFirst: 'Save your changes, then try again.',
|
|
11
11
|
setup: 'Set up the test',
|
|
12
12
|
copy: 'Copy the Original into this version',
|
|
13
|
-
confirmCopy:
|
|
13
|
+
confirmCopy: "Replace this version's content with a copy of the Original? Edits you made to this version will be lost.",
|
|
14
14
|
unwrap: 'Unwrap',
|
|
15
15
|
removeAndUnwrap: 'Remove the test and unwrap',
|
|
16
16
|
deleteAndUnwrap: 'Delete and unwrap',
|
|
@@ -23,7 +23,9 @@ export function ResultsRoute(props) {
|
|
|
23
23
|
function ManagedResults({ id, surface, onTitleChange }) {
|
|
24
24
|
const test = useTestDocument(id, {
|
|
25
25
|
apiRoute: surface.apiRoute,
|
|
26
|
-
contentLocale: surface.contentLocale
|
|
26
|
+
contentLocale: surface.contentLocale,
|
|
27
|
+
refetchDocumentOnFocus: true,
|
|
28
|
+
refetchPreflightOnFocus: true
|
|
27
29
|
});
|
|
28
30
|
useEffect(()=>{
|
|
29
31
|
if (test.doc?.name) onTitleChange?.(test.doc.name);
|
|
@@ -39,12 +41,17 @@ function ManagedResults({ id, surface, onTitleChange }) {
|
|
|
39
41
|
test.doc.allocation,
|
|
40
42
|
test.doc.metrics
|
|
41
43
|
]) : 'loading';
|
|
42
|
-
// ResultsBody's Decide is the shared DecideDialog, which reloads the page; Recompute keeps status.
|
|
43
44
|
if (test.loadState === 'ready' && test.doc) return /*#__PURE__*/ _jsx(ResultsBody, {
|
|
45
|
+
documentVersion: bodyKey,
|
|
46
|
+
liveDocument: test.doc,
|
|
47
|
+
statusReadPending: test.statusReadPending,
|
|
44
48
|
id: id,
|
|
45
49
|
surface: surface,
|
|
46
50
|
onRecomputed: ()=>setResultsVersion((value)=>value + 1),
|
|
47
|
-
|
|
51
|
+
onChanged: (doc)=>{
|
|
52
|
+
test.acceptTransition?.({
|
|
53
|
+
doc
|
|
54
|
+
});
|
|
48
55
|
void test.reload();
|
|
49
56
|
},
|
|
50
57
|
renderPage: (parts)=>/*#__PURE__*/ _jsx(ResultsHeader, {
|
|
@@ -52,8 +59,8 @@ function ManagedResults({ id, surface, onTitleChange }) {
|
|
|
52
59
|
surface: surface,
|
|
53
60
|
resultsVersion: resultsVersion,
|
|
54
61
|
...parts
|
|
55
|
-
}, `${test.doc.id}/${test.doc.status}`)
|
|
56
|
-
}
|
|
62
|
+
}, `${test.doc.id}/${test.doc.status}/${test.doc.phase}`)
|
|
63
|
+
});
|
|
57
64
|
return /*#__PURE__*/ _jsx(ReaderResultsShell, {
|
|
58
65
|
surface: surface,
|
|
59
66
|
children: /*#__PURE__*/ _jsxs("div", {
|
|
@@ -67,14 +74,13 @@ function ManagedResults({ id, surface, onTitleChange }) {
|
|
|
67
74
|
onClick: ()=>void test.reload(),
|
|
68
75
|
children: C.retry
|
|
69
76
|
}) : null,
|
|
70
|
-
test.loadState
|
|
77
|
+
test.loadState === 'error' ? /*#__PURE__*/ _jsx(ResultsBody, {
|
|
71
78
|
id: id,
|
|
72
|
-
surface:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
void test.reload();
|
|
79
|
+
surface: {
|
|
80
|
+
...surface,
|
|
81
|
+
canManage: false
|
|
76
82
|
}
|
|
77
|
-
}
|
|
83
|
+
}) : null
|
|
78
84
|
]
|
|
79
85
|
})
|
|
80
86
|
});
|
|
@@ -3,10 +3,11 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
import { DeleteTest } from '../../testSurface/surface/test/DeleteTest.js';
|
|
4
4
|
import { DELETE_TEST } from '../../testSurface/copy/testPage.js';
|
|
5
5
|
import { surfaceUrls } from '../../testSurface/surfaceUrls.js';
|
|
6
|
-
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
import { formatAdminURL } from 'payload/shared';
|
|
8
8
|
import { fetchAllDocs } from '../../lib/fetchAllDocs.js';
|
|
9
9
|
import { createApi } from '../../testSurface/api.js';
|
|
10
|
+
import { useOnTestReturn } from '../../testSurface/useOnTestReturn.js';
|
|
10
11
|
import { noMatchesLine, SURFACE_COPY } from '../../testSurface/copy/surface.js';
|
|
11
12
|
import { Banner, EmptyState, StatusChip } from '../../ui/Feedback.js';
|
|
12
13
|
import { Button } from '../../ui/Button.js';
|
|
@@ -39,8 +40,13 @@ export function TestsHome({ adminRoute, apiRoute, contentLocale, canManage = fal
|
|
|
39
40
|
});
|
|
40
41
|
const [search, setSearch] = useState('');
|
|
41
42
|
const [attempt, setAttempt] = useState(0);
|
|
43
|
+
const reload = useCallback(()=>setAttempt((value)=>value + 1), []);
|
|
42
44
|
const [notice, setNotice] = useState();
|
|
43
45
|
const noticeRef = useRef(null);
|
|
46
|
+
const deletedIds = useRef(new Set());
|
|
47
|
+
const openDeleteId = useRef(undefined);
|
|
48
|
+
const [dialogTest, setDialogTest] = useState();
|
|
49
|
+
const refreshDeferred = useRef(false);
|
|
44
50
|
useLayoutEffect(()=>{
|
|
45
51
|
if (notice) noticeRef.current?.focus();
|
|
46
52
|
}, [
|
|
@@ -57,16 +63,28 @@ export function TestsHome({ adminRoute, apiRoute, contentLocale, canManage = fal
|
|
|
57
63
|
window.history.replaceState(window.history.state, '', `${url.pathname}${url.search}${url.hash}`);
|
|
58
64
|
}
|
|
59
65
|
}, []);
|
|
66
|
+
useOnTestReturn(reload);
|
|
60
67
|
useEffect(()=>{
|
|
61
68
|
let active = true;
|
|
62
69
|
const controller = new AbortController();
|
|
63
|
-
setState({
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
setState((current)=>current.loading || current.error ? {
|
|
71
|
+
loading: true
|
|
72
|
+
} : current);
|
|
73
|
+
function settle(next) {
|
|
74
|
+
if (!active) return;
|
|
75
|
+
// A new group can remount a row. Let its open dialog finish before replacing the list.
|
|
76
|
+
if (openDeleteId.current === undefined) {
|
|
77
|
+
setState(next);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
refreshDeferred.current = true;
|
|
81
|
+
if (!next.loading && !next.error) setDialogTest(next.tests.find((test)=>String(test.id) === openDeleteId.current));
|
|
82
|
+
}
|
|
66
83
|
async function load() {
|
|
67
84
|
try {
|
|
68
85
|
const response = await fetchAllDocs(`${apiRoute.replace(/\/$/, '')}/xp-experiments?depth=0&sort=id&${HOME_SELECT}`, {
|
|
69
86
|
credentials: 'include',
|
|
87
|
+
cache: 'no-store',
|
|
70
88
|
signal: controller.signal
|
|
71
89
|
});
|
|
72
90
|
if (!response.ok) throw new Error('list');
|
|
@@ -101,16 +119,16 @@ export function TestsHome({ adminRoute, apiRoute, contentLocale, canManage = fal
|
|
|
101
119
|
for (const goal of body?.docs ?? [])if (typeof goal.name === 'string' && goal.name.trim() && ids.includes(String(goal.id))) goalNames[String(goal.id)] = goal.name;
|
|
102
120
|
} catch {}
|
|
103
121
|
}
|
|
104
|
-
|
|
122
|
+
settle({
|
|
105
123
|
loading: false,
|
|
106
124
|
error: false,
|
|
107
|
-
tests: docs,
|
|
125
|
+
tests: docs.filter((doc)=>!deletedIds.current.has(String(doc.id))),
|
|
108
126
|
goalNames,
|
|
109
127
|
summaries,
|
|
110
128
|
summaryError: !summary.ok
|
|
111
129
|
});
|
|
112
130
|
} catch {
|
|
113
|
-
|
|
131
|
+
settle({
|
|
114
132
|
loading: false,
|
|
115
133
|
error: true
|
|
116
134
|
});
|
|
@@ -127,9 +145,27 @@ export function TestsHome({ adminRoute, apiRoute, contentLocale, canManage = fal
|
|
|
127
145
|
attempt,
|
|
128
146
|
canManage
|
|
129
147
|
]);
|
|
148
|
+
function handleDialogChange(id, open) {
|
|
149
|
+
openDeleteId.current = open ? String(id) : undefined;
|
|
150
|
+
setDialogTest(undefined);
|
|
151
|
+
if (!open && refreshDeferred.current) {
|
|
152
|
+
refreshDeferred.current = false;
|
|
153
|
+
reload();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function handleDeleted(id, outcome) {
|
|
157
|
+
deletedIds.current.add(String(id));
|
|
158
|
+
setNotice({
|
|
159
|
+
outcome
|
|
160
|
+
});
|
|
161
|
+
setState((current)=>!current.loading && !current.error ? {
|
|
162
|
+
...current,
|
|
163
|
+
tests: current.tests.filter((test)=>String(test.id) !== String(id))
|
|
164
|
+
} : current);
|
|
165
|
+
}
|
|
130
166
|
const retry = /*#__PURE__*/ _jsx(Button, {
|
|
131
167
|
size: "sm",
|
|
132
|
-
onClick:
|
|
168
|
+
onClick: reload,
|
|
133
169
|
children: SURFACE_COPY.retry
|
|
134
170
|
});
|
|
135
171
|
const newTest = /*#__PURE__*/ _jsx(Button, {
|
|
@@ -209,21 +245,16 @@ export function TestsHome({ adminRoute, apiRoute, contentLocale, canManage = fal
|
|
|
209
245
|
children: SURFACE_COPY.empty
|
|
210
246
|
}) : /*#__PURE__*/ _jsx(TestGroups, {
|
|
211
247
|
tests: state.tests,
|
|
248
|
+
dialogTest: dialogTest,
|
|
212
249
|
summaries: state.summaries,
|
|
213
250
|
goalNames: state.goalNames,
|
|
214
251
|
adminRoute: adminRoute,
|
|
215
252
|
apiRoute: apiRoute,
|
|
216
253
|
contentLocale: contentLocale,
|
|
217
254
|
canManage: canManage,
|
|
218
|
-
onDeleted:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
222
|
-
setState((current)=>!current.loading && !current.error ? {
|
|
223
|
-
...current,
|
|
224
|
-
tests: current.tests.filter((test)=>String(test.id) !== String(id))
|
|
225
|
-
} : current);
|
|
226
|
-
},
|
|
255
|
+
onDeleted: handleDeleted,
|
|
256
|
+
onDialogChange: handleDialogChange,
|
|
257
|
+
onStatusChanged: reload,
|
|
227
258
|
flagPoints: flagPoints,
|
|
228
259
|
search: search,
|
|
229
260
|
clear: ()=>setSearch('')
|
|
@@ -233,7 +264,7 @@ export function TestsHome({ adminRoute, apiRoute, contentLocale, canManage = fal
|
|
|
233
264
|
]
|
|
234
265
|
});
|
|
235
266
|
}
|
|
236
|
-
function TestGroups({ tests, summaries, goalNames, adminRoute, apiRoute, contentLocale, canManage, onDeleted, flagPoints, search, clear }) {
|
|
267
|
+
function TestGroups({ tests, dialogTest, summaries, goalNames, adminRoute, apiRoute, contentLocale, canManage, onDeleted, onDialogChange, onStatusChanged, flagPoints, search, clear }) {
|
|
237
268
|
const groups = groupTests(tests, summaries, search);
|
|
238
269
|
if (!groups.some((group)=>group.tests.length)) return /*#__PURE__*/ _jsxs("div", {
|
|
239
270
|
className: "xp-tests-no-matches",
|
|
@@ -299,11 +330,13 @@ function TestGroups({ tests, summaries, goalNames, adminRoute, apiRoute, content
|
|
|
299
330
|
className: "xp-ui-button-group",
|
|
300
331
|
children: [
|
|
301
332
|
/*#__PURE__*/ _jsx(DeleteTest, {
|
|
302
|
-
test: test,
|
|
333
|
+
test: dialogTest?.id === test.id ? dialogTest : test,
|
|
303
334
|
canManage: canManage,
|
|
304
335
|
apiRoute: apiRoute,
|
|
305
336
|
contentLocale: contentLocale,
|
|
306
|
-
onDeleted: (outcome)=>onDeleted(test.id, outcome)
|
|
337
|
+
onDeleted: (outcome)=>onDeleted(test.id, outcome),
|
|
338
|
+
onDialogChange: (open)=>onDialogChange(test.id, open),
|
|
339
|
+
onStatusChanged: onStatusChanged
|
|
307
340
|
}),
|
|
308
341
|
/*#__PURE__*/ _jsx(Button, {
|
|
309
342
|
className: "xp-tests-row-action",
|
|
@@ -3,13 +3,14 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
4
|
import { useRouter } from 'next/navigation.js';
|
|
5
5
|
import { formatAdminURL } from 'payload/shared';
|
|
6
|
-
import { canStartTest, readyToStart } from '../../../testSurface/readinessRead.js';
|
|
6
|
+
import { canStartTest, hasBrowserWritablePrimary, readyToStart } from '../../../testSurface/readinessRead.js';
|
|
7
7
|
import { useTestDocument } from '../../../testSurface/surface/useTestDocument.js';
|
|
8
8
|
import { CopyRoute } from '../../../testSurface/surface/pagePicker/CopyRoute.js';
|
|
9
9
|
import { PageCombobox } from '../../../testSurface/surface/pagePicker/PageCombobox.js';
|
|
10
10
|
import { testPageCollection, controlFirst } from '../../../testSurface/surface/pagePicker/pagePicker.model.js';
|
|
11
11
|
import { NEW_TEST_COPY as C } from '../../copy/newTest.js';
|
|
12
12
|
import { READINESS_COPY } from '../../../testSurface/copy/readiness.js';
|
|
13
|
+
import { METRICS_COPY } from '../../../testSurface/copy/metrics.js';
|
|
13
14
|
import { TEST_PAGE } from '../../../testSurface/copy/testPage.js';
|
|
14
15
|
import { SURFACE_COPY } from '../../../testSurface/copy/surface.js';
|
|
15
16
|
import { pageStepCopy } from '../../../testSurface/copy/pages.js';
|
|
@@ -18,6 +19,7 @@ import { FieldErrors } from '../../../testSurface/surface/test/fields.js';
|
|
|
18
19
|
import { SaveStatus } from '../../../testSurface/surface/readiness/SaveStatus.js';
|
|
19
20
|
import { createApi } from '../../../testSurface/api.js';
|
|
20
21
|
import { useTransition } from '../../../testSurface/surface/readiness/useTransition.js';
|
|
22
|
+
import { Banner } from '../../../ui/Feedback.js';
|
|
21
23
|
/** One session stays mounted across Collection, all page steps and Review. */ export function PageWizard({ id, surface }) {
|
|
22
24
|
const router = useRouter();
|
|
23
25
|
const collections = surface.pageCollections ?? [];
|
|
@@ -145,6 +147,10 @@ import { useTransition } from '../../../testSurface/surface/readiness/useTransit
|
|
|
145
147
|
}, `${check.code}/${index}`) : null;
|
|
146
148
|
})
|
|
147
149
|
}),
|
|
150
|
+
hasBrowserWritablePrimary(test.preflight, doc.metrics?.primary) ? /*#__PURE__*/ _jsx(Banner, {
|
|
151
|
+
tone: "warning",
|
|
152
|
+
children: METRICS_COPY.browserWritablePrimary
|
|
153
|
+
}) : null,
|
|
148
154
|
ready ? /*#__PURE__*/ _jsx("p", {
|
|
149
155
|
children: READINESS_COPY.ready
|
|
150
156
|
}) : null,
|
|
@@ -152,7 +158,7 @@ import { useTransition } from '../../../testSurface/surface/readiness/useTransit
|
|
|
152
158
|
type: "button",
|
|
153
159
|
disabled: busy || test.preflightPending || !test.preflight || ready && (!canStartTest(test) || transition.checking),
|
|
154
160
|
onClick: ()=>{
|
|
155
|
-
if (ready) void transition.run('start', ()=>createApi(surface.apiRoute).start(id));
|
|
161
|
+
if (ready) void transition.run('start', ()=>createApi(surface.apiRoute).start(id, doc.phase));
|
|
156
162
|
else if (next) jump(next.section, next.arm);
|
|
157
163
|
},
|
|
158
164
|
children: ready ? C.start : C.finishSetup
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { canStartTest, readyToStart } from '../../../testSurface/readinessRead.js';
|
|
3
|
+
import { canStartTest, hasBrowserWritablePrimary, readyToStart } from '../../../testSurface/readinessRead.js';
|
|
4
4
|
import { BlockerList } from '../../../testSurface/surface/readiness/BlockerList.js';
|
|
5
5
|
import { ReadinessReadStatus } from '../../../testSurface/surface/readiness/SaveStatus.js';
|
|
6
6
|
import { surfaceUrls } from '../../../testSurface/surfaceUrls.js';
|
|
@@ -15,6 +15,7 @@ import { AllocateAction, ConfirmAction } from '../../../testSurface/surface/read
|
|
|
15
15
|
import { READINESS, daysRemaining, displayDate, blockingSteps, pageReadinessContext } from '../../../testSurface/surface/readiness/readiness.model.js';
|
|
16
16
|
import { READINESS_COPY as R, runningCopy, stoppedCopy, decidedCopy } from '../../../testSurface/copy/readiness.js';
|
|
17
17
|
import { RESULTS_COPY as C } from '../../../testSurface/copy/results.js';
|
|
18
|
+
import { METRICS_COPY } from '../../../testSurface/copy/metrics.js';
|
|
18
19
|
import { TEST_PAGE } from '../../../testSurface/copy/testPage.js';
|
|
19
20
|
export function ResultsHeader({ test, surface, resultsVersion, children, actions, released }) {
|
|
20
21
|
const doc = test.doc;
|
|
@@ -63,7 +64,7 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
|
|
|
63
64
|
const ready = readyToStart(test);
|
|
64
65
|
const startReason = test.preflightError ?? blockers[0]?.sentence ?? (!ready ? R.checking : undefined);
|
|
65
66
|
const action = available.find((item)=>item.id === selected);
|
|
66
|
-
const sentence = doc.status === 'running' ? runningCopy(displayDate(doc.startedAt), people, daysRemaining(doc, Date.now())) : doc.status === 'stopped' ? stoppedCopy(displayDate(doc.stoppedAt)) : doc.status === 'decided' ? decidedCopy(displayDate(doc.decidedAt), winner) : doc.status === 'archived' ? R.archived : null;
|
|
67
|
+
const sentence = test.statusReadPending ? R.checking : doc.status === 'running' ? runningCopy(displayDate(doc.startedAt), people, daysRemaining(doc, Date.now())) : doc.status === 'stopped' ? stoppedCopy(displayDate(doc.stoppedAt)) : doc.status === 'decided' ? decidedCopy(displayDate(doc.decidedAt), winner) : doc.status === 'archived' ? R.archived : null;
|
|
67
68
|
const testURL = formatAdminURL({
|
|
68
69
|
adminRoute: surface.adminRoute,
|
|
69
70
|
path: `/experiments/${encodeURIComponent(String(doc.id))}`
|
|
@@ -90,9 +91,9 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
|
|
|
90
91
|
className: "xp-tests-kind",
|
|
91
92
|
children: TEST_PAGE.kinds[doc.kind]
|
|
92
93
|
}),
|
|
93
|
-
/*#__PURE__*/ _jsx(StatusChip, {
|
|
94
|
+
!test.statusReadPending ? /*#__PURE__*/ _jsx(StatusChip, {
|
|
94
95
|
status: doc.status
|
|
95
|
-
})
|
|
96
|
+
}) : null
|
|
96
97
|
]
|
|
97
98
|
}),
|
|
98
99
|
subtitle: /*#__PURE__*/ _jsxs(_Fragment, {
|
|
@@ -116,9 +117,9 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
|
|
|
116
117
|
href: testURL,
|
|
117
118
|
children: C.backToSetup
|
|
118
119
|
}),
|
|
119
|
-
available.map((item)=>/*#__PURE__*/ _jsx(Button, {
|
|
120
|
+
!test.statusReadPending && available.map((item)=>/*#__PURE__*/ _jsx(Button, {
|
|
120
121
|
variant: item.tone === 'danger' ? 'danger' : 'secondary',
|
|
121
|
-
disabled: item.id === 'start' && !canStartTest(test) || !!selected ||
|
|
122
|
+
disabled: item.id === 'start' && !canStartTest(test) || !!selected || item.id === 'allocate' && doc.allocation >= 100,
|
|
122
123
|
title: item.id === 'start' ? startReason : item.id === 'allocate' && doc.allocation >= 100 ? R.everyone : undefined,
|
|
123
124
|
onClick: ()=>setSelected(item.id),
|
|
124
125
|
children: item.id === 'allocate' ? R.allocate : item.label
|
|
@@ -138,6 +139,10 @@ export function ResultsHeader({ test, surface, resultsVersion, children, actions
|
|
|
138
139
|
setup ? /*#__PURE__*/ _jsx(BlockerList, {
|
|
139
140
|
steps: blockers
|
|
140
141
|
}) : null,
|
|
142
|
+
!test.statusReadPending && setup && hasBrowserWritablePrimary(test.preflight, doc.metrics?.primary) ? /*#__PURE__*/ _jsx(Banner, {
|
|
143
|
+
tone: "warning",
|
|
144
|
+
children: METRICS_COPY.browserWritablePrimary
|
|
145
|
+
}) : null,
|
|
141
146
|
children,
|
|
142
147
|
action?.id === 'allocate' ? /*#__PURE__*/ _jsx(AllocateAction, {
|
|
143
148
|
test: test,
|
|
@@ -32,12 +32,12 @@ export function TestPage({ id, surface, onTitleChange }) {
|
|
|
32
32
|
className: "xp-tests-kind",
|
|
33
33
|
children: C.kinds[doc.kind]
|
|
34
34
|
}),
|
|
35
|
-
/*#__PURE__*/ _jsx(StatusChip, {
|
|
35
|
+
!test.statusReadPending ? /*#__PURE__*/ _jsx(StatusChip, {
|
|
36
36
|
status: doc.status
|
|
37
|
-
})
|
|
37
|
+
}) : null
|
|
38
38
|
]
|
|
39
39
|
}) : undefined,
|
|
40
|
-
actions: doc && surface.canReadResults && [
|
|
40
|
+
actions: doc && !test.statusReadPending && surface.canReadResults && [
|
|
41
41
|
'running',
|
|
42
42
|
'stopped',
|
|
43
43
|
'decided'
|
package/dist/blocks/formState.js
CHANGED
|
@@ -86,7 +86,7 @@ function copySlotBlocks(block, slot, field, config) {
|
|
|
86
86
|
], field, config)[0], slot);
|
|
87
87
|
}
|
|
88
88
|
export function syncExperimentSlots(block, arms, field, config = {}) {
|
|
89
|
-
const wanted = arms.filter((a)=>a.kind !== 'holdout' && a.key !== 'holdout').map((a)=>a.
|
|
89
|
+
const wanted = arms.filter((a)=>a.kind !== 'holdout' && a.key !== 'holdout').map((a)=>a.key).filter((slot)=>BLOCK_SLOTS.includes(slot));
|
|
90
90
|
const slots = [
|
|
91
91
|
...new Set(wanted)
|
|
92
92
|
].map((slot)=>block.slots.find((row)=>row.slot === slot) ?? {
|
|
@@ -44,16 +44,21 @@ export function experimentsCollection(options) {
|
|
|
44
44
|
},
|
|
45
45
|
access: {
|
|
46
46
|
...managedAccess(options),
|
|
47
|
-
delete: async ({ req })=>
|
|
47
|
+
delete: async ({ req, id })=>{
|
|
48
|
+
if (await options.access.manage({
|
|
48
49
|
req
|
|
49
|
-
})
|
|
50
|
+
}) !== true) return false;
|
|
51
|
+
// Single deletes report status through the locked beforeDelete guard.
|
|
52
|
+
// Payload catches per-document hook failures in bulk deletes, so keep their status filter in access.
|
|
53
|
+
return id != null ? true : {
|
|
50
54
|
status: {
|
|
51
55
|
in: [
|
|
52
56
|
'draft',
|
|
53
57
|
'archived'
|
|
54
58
|
]
|
|
55
59
|
}
|
|
56
|
-
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
57
62
|
},
|
|
58
63
|
admin: {
|
|
59
64
|
group: SURFACE_COPY.title,
|
|
@@ -3,8 +3,8 @@ import { xpOptionsFromReq } from '../../options/fromReq.js';
|
|
|
3
3
|
export const deleteGuard = async ({ req, id })=>{
|
|
4
4
|
await deleteExperiment(req, id);
|
|
5
5
|
};
|
|
6
|
-
export const deleteGuardAfter = async ({ req,
|
|
7
|
-
await deleteExperimentAfter(req
|
|
6
|
+
export const deleteGuardAfter = async ({ req, doc })=>{
|
|
7
|
+
await deleteExperimentAfter(req);
|
|
8
8
|
return doc;
|
|
9
9
|
};
|
|
10
10
|
export const deleteGuardBeforeOperation = async ({ operation, args, req })=>{
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withSlotsFor } from '../../arms/model.js';
|
|
1
2
|
import { XpLockedFieldError, XpRefusal } from '../../errors.js';
|
|
2
3
|
import { XP_IF_UPDATED_AT_HEADER } from '../../constants.js';
|
|
3
4
|
import { txExecutor } from '../../db/executor.js';
|
|
@@ -64,6 +65,24 @@ const dates = new Set([
|
|
|
64
65
|
}
|
|
65
66
|
const same = (a, b, path)=>JSON.stringify(normalize(a, path)) === JSON.stringify(normalize(b, path));
|
|
66
67
|
export const lockHook = async ({ data, originalDoc, operation, req })=>{
|
|
68
|
+
const kind = operation === 'create' ? data.kind : originalDoc.kind;
|
|
69
|
+
const storedArms = operation === 'update' ? originalDoc.arms : undefined;
|
|
70
|
+
const canonicalSlots = (value)=>{
|
|
71
|
+
if (kind !== 'block' || !Array.isArray(value) || value.some((row)=>!isObject(row))) return value;
|
|
72
|
+
return withSlotsFor(value, 'block');
|
|
73
|
+
};
|
|
74
|
+
const canonicalArms = canonicalSlots(storedArms);
|
|
75
|
+
// Payload runs collection beforeChange before field validation on Create,
|
|
76
|
+
// Update and Restore. Derive slots here so the arms validator sees them.
|
|
77
|
+
const arms = data.arms === undefined ? storedArms : data.arms;
|
|
78
|
+
const repaired = arms === storedArms ? canonicalArms : canonicalSlots(arms);
|
|
79
|
+
if (repaired !== arms) {
|
|
80
|
+
if (operation === 'create') data = {
|
|
81
|
+
...data,
|
|
82
|
+
arms: repaired
|
|
83
|
+
};
|
|
84
|
+
else data.arms = repaired;
|
|
85
|
+
}
|
|
67
86
|
if (req.context.xpTransition === true) return data;
|
|
68
87
|
const baseline = req.headers.get(XP_IF_UPDATED_AT_HEADER);
|
|
69
88
|
if (operation === 'update' && baseline !== null) {
|
|
@@ -71,7 +90,7 @@ export const lockHook = async ({ data, originalDoc, operation, req })=>{
|
|
|
71
90
|
// so a competing save observes the preceding save's committed timestamp.
|
|
72
91
|
const stored = await lockExperimentUpdatedAt(txExecutor(req), originalDoc.id);
|
|
73
92
|
if (stored === null || new Date(baseline).getTime() !== new Date(stored).getTime()) {
|
|
74
|
-
throw new XpRefusal('stale-edit', '
|
|
93
|
+
throw new XpRefusal('stale-edit', 'This test changed. Read the latest settings and try again.', undefined, 409);
|
|
75
94
|
}
|
|
76
95
|
}
|
|
77
96
|
const admin = async ()=>{
|
|
@@ -139,7 +158,7 @@ export const lockHook = async ({ data, originalDoc, operation, req })=>{
|
|
|
139
158
|
].includes(field) && isObject(value)) {
|
|
140
159
|
for (const [key, nested] of Object.entries(value))await check(`${field}.${key}`, nested, originalDoc[field]?.[key]);
|
|
141
160
|
} else {
|
|
142
|
-
await check(field, value, originalDoc[field]);
|
|
161
|
+
await check(field, value, field === 'arms' ? canonicalArms : originalDoc[field]);
|
|
143
162
|
// Replacing the group also changes its method, including clearing it.
|
|
144
163
|
if (field === 'analysis' && !same(value, originalDoc.analysis, field) && originalDoc.analysis?.method != null && !await admin()) throw new XpLockedFieldError('analysis.method', status);
|
|
145
164
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { assertReadCommitted } from '../../db/adapter.js';
|
|
1
2
|
import { pickSlug } from '../../db/slugs.js';
|
|
2
3
|
import { pooledExecutor, txExecutor } from '../../db/executor.js';
|
|
3
4
|
export const pickExperimentSlug = async ({ req, data, operation })=>{
|
|
4
5
|
if (operation !== 'create' || typeof data.slug !== 'string' || !data.slug) return data;
|
|
5
6
|
const transactional = await req.transactionID != null;
|
|
7
|
+
if (transactional) await assertReadCommitted(req);
|
|
6
8
|
data.slug = await pickSlug(transactional ? txExecutor(req) : pooledExecutor(req.payload), data.slug, transactional);
|
|
7
9
|
return data;
|
|
8
10
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertReadCommitted } from '../db/adapter.js';
|
|
1
2
|
import { pooledExecutor, txExecutor } from '../db/executor.js';
|
|
2
3
|
import { findMetricUsage, lockMetricRow } from '../db/metricUsage.js';
|
|
3
4
|
/** Payload's REST formatter preserves public plugin errors and their 4xx status. */ export class XpGoalInUseError extends Error {
|
|
@@ -8,6 +9,7 @@ import { findMetricUsage, lockMetricRow } from '../db/metricUsage.js';
|
|
|
8
9
|
async function executor(req, id, mode) {
|
|
9
10
|
const transactionID = await req.transactionID;
|
|
10
11
|
if (transactionID != null) {
|
|
12
|
+
await assertReadCommitted(req);
|
|
11
13
|
const exec = txExecutor(req);
|
|
12
14
|
await lockMetricRow(exec, id, mode);
|
|
13
15
|
return exec;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { browserWritableMetric } from '../events/writable.js';
|
|
1
2
|
export function serializeFlagPoints(options) {
|
|
2
3
|
return (options.flagPoints ?? []).map(({ id, label, description, params, defaultParams })=>({
|
|
3
4
|
id,
|
|
@@ -19,19 +20,19 @@ export function serializeMetricSources(options) {
|
|
|
19
20
|
keyedBy: 'visitor',
|
|
20
21
|
clientWritable: true
|
|
21
22
|
},
|
|
22
|
-
...(options.metricSources ?? []).map(({ id, label, kind, keyedBy
|
|
23
|
+
...(options.metricSources ?? []).map(({ id, label, kind, keyedBy })=>({
|
|
23
24
|
id,
|
|
24
25
|
label,
|
|
25
26
|
kind,
|
|
26
27
|
keyedBy,
|
|
27
|
-
clientWritable:
|
|
28
|
+
clientWritable: browserWritableMetric(id, options)
|
|
28
29
|
})),
|
|
29
|
-
...(options.eventSources ?? []).map(({ name
|
|
30
|
+
...(options.eventSources ?? []).map(({ name })=>({
|
|
30
31
|
id: `events:${name}`,
|
|
31
32
|
label: name,
|
|
32
33
|
kind: 'binomial',
|
|
33
34
|
keyedBy: 'visitor',
|
|
34
|
-
clientWritable
|
|
35
|
+
clientWritable: browserWritableMetric(`events:${name}`, options)
|
|
35
36
|
}))
|
|
36
37
|
];
|
|
37
38
|
}
|
package/dist/constants.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export declare const XP_PREVIEW_PARAM = "xp_preview";
|
|
|
7
7
|
export declare const XP_MANIFEST_KEY_HEADER = "x-xp-manifest-key";
|
|
8
8
|
export declare const XP_REQUEST_HEADER = "x-xp-request";
|
|
9
9
|
export declare const XP_IF_UPDATED_AT_HEADER = "x-xp-if-updated-at";
|
|
10
|
+
export declare const USER_BROWSER_CONVERSION_PREFIX = "conversion:cu:";
|
package/dist/constants.js
CHANGED
|
@@ -7,3 +7,4 @@ export const XP_PREVIEW_PARAM = 'xp_preview';
|
|
|
7
7
|
export const XP_MANIFEST_KEY_HEADER = 'x-xp-manifest-key';
|
|
8
8
|
export const XP_REQUEST_HEADER = 'x-xp-request';
|
|
9
9
|
export const XP_IF_UPDATED_AT_HEADER = 'x-xp-if-updated-at';
|
|
10
|
+
export const USER_BROWSER_CONVERSION_PREFIX = 'conversion:cu:';
|
package/dist/db/adapter.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { APIError, type Payload, type PayloadRequest } from 'payload';
|
|
2
|
+
export declare class XpTransactionIsolationError extends APIError {
|
|
3
|
+
constructor();
|
|
4
|
+
}
|
|
5
|
+
/** Payload's initTransaction cannot pass options to the adapter. Like that
|
|
6
|
+
* helper, publish the pending transaction on the request before awaiting it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function initTransitionTransaction(req: PayloadRequest): Promise<boolean>;
|
|
9
|
+
export declare function assertReadCommitted(req: PayloadRequest): Promise<void>;
|
|
2
10
|
export declare function assertPostgresAdapter(payload: Payload): void;
|
|
3
11
|
export declare function probeTransactions(payload: Payload): Promise<void>;
|