@delmaredigital/payload-experiments 0.4.0-rc.6 → 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/BlockPanel.js +6 -4
- package/dist/admin/blocks/inject.js +1 -0
- package/dist/admin/blocks/model.d.ts +3 -2
- package/dist/admin/blocks/model.js +9 -5
- package/dist/admin/copy/blocks.d.ts +3 -2
- package/dist/admin/copy/blocks.js +8 -7
- package/dist/admin/surface/ResultsRoute.js +18 -11
- package/dist/admin/surface/TestsHome.d.ts +2 -1
- package/dist/admin/surface/TestsHome.js +131 -44
- package/dist/admin/surface/TestsSurface.js +3 -0
- package/dist/admin/surface/home.model.d.ts +2 -0
- package/dist/admin/surface/newTest/PageWizard.js +9 -2
- package/dist/admin/surface/newTest/newTest.css +1 -1
- package/dist/admin/surface/results/ResultsHeader.js +11 -6
- package/dist/admin/surface/test/TestPage.js +3 -3
- package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
- package/dist/admin/views/TestsSurfaceClient.js +11 -0
- package/dist/admin/views/buildSurfaceProps.js +10 -3
- package/dist/blocks/bindings.js +3 -2
- package/dist/blocks/formState.js +1 -1
- package/dist/blocks/placementLanguages.d.ts +7 -0
- package/dist/blocks/placementLanguages.js +27 -0
- package/dist/blocks/placementLocale.d.ts +21 -7
- package/dist/blocks/placementLocale.js +218 -67
- 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/appends.d.ts +13 -0
- package/dist/db/appends.js +49 -0
- package/dist/db/bulkPlacementRemoval.js +8 -4
- 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/contentLocale.d.ts +6 -0
- package/dist/endpoints/contentLocale.js +15 -0
- package/dist/endpoints/deleteImpact.d.ts +6 -0
- package/dist/endpoints/deleteImpact.js +207 -0
- package/dist/endpoints/events.js +103 -39
- package/dist/endpoints/index.js +9 -8
- package/dist/endpoints/pages.js +7 -3
- package/dist/endpoints/placementStatus.js +13 -5
- package/dist/endpoints/preflight.d.ts +1 -1
- package/dist/endpoints/preflight.js +17 -2
- 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/adminClient.d.ts +1 -1
- package/dist/exports/adminClient.js +1 -1
- 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 +38 -31
- package/dist/hooks/blockRemovalRule.d.ts +2 -2
- package/dist/hooks/blockRemovalRule.js +16 -14
- package/dist/hooks/hostHook.js +6 -2
- package/dist/hooks/pageGuard.d.ts +3 -0
- package/dist/hooks/pageGuard.js +37 -23
- package/dist/hooks/puckNestedTests.d.ts +8 -0
- package/dist/hooks/puckNestedTests.js +36 -0
- package/dist/lib/fetchAllDocs.d.ts +1 -1
- package/dist/lib/placementPages.d.ts +2 -1
- package/dist/lib/placementPages.js +10 -2
- package/dist/manifest/compile.d.ts +2 -1
- package/dist/manifest/compile.js +13 -6
- 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/ExperimentPicker.js +40 -37
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
- package/dist/puck/editor/ConfigureTestDrawer.js +5 -2
- package/dist/puck/editor/ExperimentSlotEditor.js +313 -158
- package/dist/puck/editor/LeftoverVersions.d.ts +1 -1
- package/dist/puck/editor/LeftoverVersions.js +40 -43
- 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 +31 -3
- package/dist/puck/editor/VersionBuilder.js +336 -74
- package/dist/puck/editor/armWrites.js +1 -1
- package/dist/puck/editor/armsCache.js +1 -3
- package/dist/puck/editor/blockClipboard.d.ts +16 -0
- package/dist/puck/editor/blockClipboard.js +20 -0
- package/dist/puck/editor/copy.d.ts +12 -2
- package/dist/puck/editor/copy.js +13 -2
- package/dist/puck/editor/editor.chrome.css +118 -3
- package/dist/puck/editor/editor.css +131 -8
- package/dist/puck/editor/editor.model.d.ts +3 -1
- package/dist/puck/editor/editor.model.js +2 -2
- package/dist/puck/editor/localPlacements.d.ts +1 -0
- package/dist/puck/editor/localPlacements.js +12 -0
- package/dist/puck/editor/placementsCache.d.ts +22 -12
- package/dist/puck/editor/placementsCache.js +62 -49
- 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 +6 -4
- package/dist/puck/experimentSlug.d.ts +2 -0
- package/dist/puck/experimentSlug.js +3 -0
- package/dist/puck/nestedTestCopy.d.ts +8 -0
- package/dist/puck/nestedTestCopy.js +22 -0
- package/dist/puck/nestedTests.d.ts +17 -0
- package/dist/puck/nestedTests.js +30 -0
- package/dist/puck/slotConfig.d.ts +1 -1
- package/dist/puck/slotConfig.js +17 -4
- package/dist/puck/visibility.d.ts +2 -3
- package/dist/puck/visibility.js +11 -7
- 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 +45 -21
- package/dist/server/resolveExperimentBlocks.js +2 -4
- package/dist/server/resolveExperimentData.js +4 -7
- 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/PreviewLinks.js +6 -2
- 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 +11 -8
- package/dist/testSurface/api.js +27 -11
- package/dist/testSurface/contentLocaleURL.d.ts +2 -0
- package/dist/testSurface/contentLocaleURL.js +3 -0
- package/dist/testSurface/copy/actions.d.ts +1 -0
- package/dist/testSurface/copy/actions.js +1 -0
- package/dist/testSurface/copy/common.d.ts +6 -0
- package/dist/testSurface/copy/common.js +11 -5
- package/dist/testSurface/copy/languages.d.ts +12 -0
- package/dist/testSurface/copy/languages.js +8 -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 +13 -2
- package/dist/testSurface/copy/readiness.js +19 -2
- package/dist/testSurface/copy/results.d.ts +5 -2
- package/dist/testSurface/copy/results.js +5 -2
- package/dist/testSurface/copy/testPage.d.ts +40 -1
- package/dist/testSurface/copy/testPage.js +53 -1
- package/dist/testSurface/placementLabel.d.ts +8 -0
- package/dist/testSurface/placementLabel.js +24 -0
- package/dist/testSurface/placements/placementLabels.d.ts +2 -0
- package/dist/testSurface/placements/placementLabels.js +2 -1
- 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.css +1 -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 +10 -1
- package/dist/testSurface/surface/editorPlacement.d.ts +7 -2
- package/dist/testSurface/surface/editorPlacement.js +19 -1
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +4 -3
- package/dist/testSurface/surface/pageBlock/parts.js +24 -6
- 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 +116 -12
- 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 +11 -7
- 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 +19 -0
- package/dist/testSurface/surface/test/DeleteTest.js +262 -0
- 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 +97 -15
- 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 +23 -4
- package/dist/testSurface/surface/useTestDocument.js +425 -162
- package/dist/testSurface/useApi.d.ts +9 -6
- 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 +5 -1
- package/dist/transitions/checkStart.js +130 -16
- package/dist/transitions/contentFields.js +9 -5
- 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 +17 -12
- package/dist/transitions/nestedPlacementNames.d.ts +5 -0
- package/dist/transitions/nestedPlacementNames.js +32 -0
- package/dist/transitions/pageVersions.js +3 -1
- 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 +15 -11
- package/dist/transitions/placements.d.ts +28 -1
- package/dist/transitions/placements.js +223 -60
- package/dist/transitions/preflightData.d.ts +5 -3
- package/dist/transitions/preflightData.js +126 -37
- 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 +70 -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 +86 -9
- package/dist/types/endpoints.js +1 -1
- package/dist/types/runtime.d.ts +15 -9
- package/dist/types/snapshot.d.ts +2 -0
- package/dist/types/surface.d.ts +2 -0
- package/dist/ui/Button.js +2 -2
- package/dist/ui/ChipsInput.d.ts +8 -1
- package/dist/ui/ChipsInput.js +17 -4
- package/dist/ui/Inputs.d.ts +4 -3
- package/dist/ui/Inputs.js +9 -9
- package/dist/ui/SelectControl.d.ts +33 -0
- package/dist/ui/SelectControl.js +504 -0
- package/dist/ui/ui.css +13 -5
- package/package.json +3 -2
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { nestedPlacementNames, nameNestedPlacements } from './nestedPlacementNames.js';
|
|
2
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
3
|
+
import { BLOCK_SLOTS } from '../blocks/model.js';
|
|
4
|
+
import { placementLanguageNames, placementLanguages } from '../blocks/placementLanguages.js';
|
|
1
5
|
import { goalContent, OUTSIDE_GOAL } from '../goals/fairness.js';
|
|
6
|
+
import { browserWritableMetric } from '../events/writable.js';
|
|
2
7
|
import { placementInteractions, placementPaths, uniquePlacementDocs } from './placementInteractions.js';
|
|
3
8
|
import { Forbidden, NotFound } from 'payload';
|
|
4
9
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
@@ -10,17 +15,16 @@ import { checkStart, relationshipId } from './checkStart.js';
|
|
|
10
15
|
import { flagPlacements, scanBlockPlacements } from './placements.js';
|
|
11
16
|
import { routedPageTests } from '../db/pageOccupancy.js';
|
|
12
17
|
import { pooledExecutor, txExecutor } from '../db/executor.js';
|
|
18
|
+
import { findStartDocuments, readStartState } from './startReads.js';
|
|
13
19
|
const failureDetail = (cause)=>{
|
|
14
20
|
const name = cause instanceof Error ? cause.name : undefined;
|
|
15
21
|
return cause instanceof Forbidden || name === 'Forbidden' ? 'forbidden' : cause instanceof NotFound || name === 'NotFound' ? 'not-found' : 'placements-failed';
|
|
16
22
|
};
|
|
17
23
|
/** Read-only inputs shared with Start's pre-transaction checks. Start must re-read
|
|
18
24
|
* the document and lock-sensitive facts inside its transition (CORE-10b).
|
|
19
|
-
*/ export async function
|
|
20
|
-
const found = await req
|
|
25
|
+
*/ export async function readStartInputExperiment(req, experimentId, system = false) {
|
|
26
|
+
const found = await findStartDocuments(req, {
|
|
21
27
|
collection: 'xp-experiments',
|
|
22
|
-
req,
|
|
23
|
-
overrideAccess: false,
|
|
24
28
|
depth: 0,
|
|
25
29
|
limit: 1,
|
|
26
30
|
where: {
|
|
@@ -28,12 +32,15 @@ const failureDetail = (cause)=>{
|
|
|
28
32
|
equals: experimentId
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
}, system);
|
|
36
|
+
return found.docs[0] ?? null;
|
|
37
|
+
}
|
|
38
|
+
export async function loadStartInputs(req, options, experimentId, system = false) {
|
|
39
|
+
const experiment = await readStartInputExperiment(req, experimentId, system);
|
|
40
|
+
if (!experiment) return null;
|
|
34
41
|
return (await loadStartInputsBatch(req, options, [
|
|
35
42
|
experiment
|
|
36
|
-
])).get(String(experiment.id)) ?? null;
|
|
43
|
+
], false, system)).get(String(experiment.id)) ?? null;
|
|
37
44
|
}
|
|
38
45
|
/** Occupancy from the arms the runtime routes on (frozen rounds), shared by preflight and
|
|
39
46
|
* Start's locked recheck. Raw SQL on the request's transaction when there is one. */ export async function loadPageTestsInUse(req) {
|
|
@@ -71,16 +78,14 @@ const metricIds = (experiment)=>[
|
|
|
71
78
|
].map(relationshipId).filter((id)=>id !== undefined);
|
|
72
79
|
/** Shared, request-scoped reads for summary; a failed row is null in tolerant mode.
|
|
73
80
|
* Preflight/Start use the same builder and retain their throwing read behaviour.
|
|
74
|
-
*/ export async function loadStartInputsBatch(req, options, experiments, tolerateErrors = false) {
|
|
81
|
+
*/ export async function loadStartInputsBatch(req, options, experiments, tolerateErrors = false, system = false) {
|
|
75
82
|
const ids = [
|
|
76
83
|
...new Set(experiments.flatMap(metricIds))
|
|
77
84
|
];
|
|
78
85
|
const metrics = (async ()=>{
|
|
79
86
|
if (!ids.length) return [];
|
|
80
|
-
const result = await req
|
|
87
|
+
const result = await findStartDocuments(req, {
|
|
81
88
|
collection: 'xp-metrics',
|
|
82
|
-
req,
|
|
83
|
-
overrideAccess: false,
|
|
84
89
|
depth: 0,
|
|
85
90
|
pagination: false,
|
|
86
91
|
limit: ids.length,
|
|
@@ -89,13 +94,14 @@ const metricIds = (experiment)=>[
|
|
|
89
94
|
in: ids
|
|
90
95
|
}
|
|
91
96
|
}
|
|
92
|
-
});
|
|
97
|
+
}, system);
|
|
93
98
|
return result.docs;
|
|
94
99
|
})();
|
|
95
100
|
const blockSlugs = new Set(experiments.filter((e)=>e.kind === 'block').map((e)=>e.slug));
|
|
96
101
|
// Lazy promises prevent unhandled rejections and share failed reads as well as successful ones.
|
|
97
102
|
let pageTestsInUse;
|
|
98
103
|
let blocks;
|
|
104
|
+
let nestedNames;
|
|
99
105
|
let state;
|
|
100
106
|
const busyPoints = new Map();
|
|
101
107
|
const layers = new Map();
|
|
@@ -103,7 +109,11 @@ const metricIds = (experiment)=>[
|
|
|
103
109
|
for (const experiment of experiments){
|
|
104
110
|
try {
|
|
105
111
|
const ownIds = new Set(metricIds(experiment).map(String));
|
|
112
|
+
const localization = req.payload.config.localization;
|
|
106
113
|
const input = {
|
|
114
|
+
placementLocaleCodes: localization ? localization.localeCodes : undefined,
|
|
115
|
+
placementLocale: req.locale ?? undefined,
|
|
116
|
+
placementDefaultLocale: localization ? localization.defaultLocale : undefined,
|
|
107
117
|
experiment,
|
|
108
118
|
metrics: (await metrics).filter((metric)=>ownIds.has(String(metric.id))),
|
|
109
119
|
metricSources: options.metricSources,
|
|
@@ -136,9 +146,16 @@ const metricIds = (experiment)=>[
|
|
|
136
146
|
slugs: blockSlugs,
|
|
137
147
|
compareVersions: true,
|
|
138
148
|
puckCollections: options.puck?.collections ?? [],
|
|
139
|
-
blocksCollections: options.blocks?.collections ?? []
|
|
149
|
+
blocksCollections: options.blocks?.collections ?? [],
|
|
150
|
+
system
|
|
140
151
|
});
|
|
141
152
|
input.placements = (await blocks).get(experiment.slug) ?? [];
|
|
153
|
+
if (input.placements.some((p)=>p.nestedTests?.length)) {
|
|
154
|
+
nestedNames ??= nestedPlacementNames(req, [
|
|
155
|
+
...(await blocks).values()
|
|
156
|
+
].flat(), system);
|
|
157
|
+
input.placements = nameNestedPlacements(input.placements, await nestedNames);
|
|
158
|
+
}
|
|
142
159
|
} catch (cause) {
|
|
143
160
|
input.placementError = placementFailure(cause);
|
|
144
161
|
}
|
|
@@ -148,12 +165,7 @@ const metricIds = (experiment)=>[
|
|
|
148
165
|
if (point) {
|
|
149
166
|
state ??= (async ()=>{
|
|
150
167
|
try {
|
|
151
|
-
const doc = await req
|
|
152
|
-
slug: 'xp-state',
|
|
153
|
-
req,
|
|
154
|
-
overrideAccess: false,
|
|
155
|
-
depth: 0
|
|
156
|
-
});
|
|
168
|
+
const doc = await readStartState(req, system);
|
|
157
169
|
return doc.flagDefaults;
|
|
158
170
|
} catch (cause) {
|
|
159
171
|
const error = cause;
|
|
@@ -181,10 +193,8 @@ const metricIds = (experiment)=>[
|
|
|
181
193
|
const key = experiment.flagPoint;
|
|
182
194
|
if (!busyPoints.has(key)) busyPoints.set(key, (async ()=>{
|
|
183
195
|
// Two rows suffice to find a peer, including when the batch contains that peer.
|
|
184
|
-
const busy = await req
|
|
196
|
+
const busy = await findStartDocuments(req, {
|
|
185
197
|
collection: 'xp-experiments',
|
|
186
|
-
req,
|
|
187
|
-
overrideAccess: false,
|
|
188
198
|
depth: 0,
|
|
189
199
|
limit: 2,
|
|
190
200
|
where: {
|
|
@@ -204,7 +214,7 @@ const metricIds = (experiment)=>[
|
|
|
204
214
|
}
|
|
205
215
|
]
|
|
206
216
|
}
|
|
207
|
-
});
|
|
217
|
+
}, system);
|
|
208
218
|
return busy.docs;
|
|
209
219
|
})());
|
|
210
220
|
input.flagPointBusy = (await busyPoints.get(key)).some((doc)=>String(doc.id) !== String(experiment.id));
|
|
@@ -214,10 +224,8 @@ const metricIds = (experiment)=>[
|
|
|
214
224
|
if (layerId !== undefined) {
|
|
215
225
|
const key = String(layerId);
|
|
216
226
|
if (!layers.has(key)) layers.set(key, (async ()=>{
|
|
217
|
-
const result = await req
|
|
227
|
+
const result = await findStartDocuments(req, {
|
|
218
228
|
collection: 'xp-layers',
|
|
219
|
-
req,
|
|
220
|
-
overrideAccess: false,
|
|
221
229
|
depth: 0,
|
|
222
230
|
limit: 1,
|
|
223
231
|
where: {
|
|
@@ -225,15 +233,13 @@ const metricIds = (experiment)=>[
|
|
|
225
233
|
equals: layerId
|
|
226
234
|
}
|
|
227
235
|
}
|
|
228
|
-
});
|
|
236
|
+
}, system);
|
|
229
237
|
const layer = result.docs[0];
|
|
230
238
|
const usedSlices = [];
|
|
231
239
|
let page = 1;
|
|
232
240
|
while(true){
|
|
233
|
-
const usage = await req
|
|
241
|
+
const usage = await findStartDocuments(req, {
|
|
234
242
|
collection: 'xp-experiments',
|
|
235
|
-
req,
|
|
236
|
-
overrideAccess: false,
|
|
237
243
|
depth: 0,
|
|
238
244
|
limit: 100,
|
|
239
245
|
page,
|
|
@@ -254,7 +260,7 @@ const metricIds = (experiment)=>[
|
|
|
254
260
|
}
|
|
255
261
|
]
|
|
256
262
|
}
|
|
257
|
-
});
|
|
263
|
+
}, system);
|
|
258
264
|
for (const doc of usage.docs)if (Array.isArray(doc.layerSlices)) usedSlices.push(...doc.layerSlices);
|
|
259
265
|
if (!usage.hasNextPage) break;
|
|
260
266
|
page++;
|
|
@@ -270,7 +276,7 @@ const metricIds = (experiment)=>[
|
|
|
270
276
|
const paths = experiment.kind === 'page' ? experiment.arms.flatMap((a)=>typeof a.pageTarget === 'string' ? [
|
|
271
277
|
a.pageTarget
|
|
272
278
|
] : []) : await placementPaths(req, options, uniquePlacementDocs(input.placements ?? []));
|
|
273
|
-
input.interactions = await placementInteractions(req, await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload), options, experiment, paths.map(normalisePath));
|
|
279
|
+
input.interactions = await placementInteractions(req, await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload), options, experiment, paths.map(normalisePath), system);
|
|
274
280
|
}
|
|
275
281
|
if (input.metrics.some((metric)=>metric.source.startsWith('click:'))) input.goalContent = await goalContent(req, options, experiment, input.placements ? uniquePlacementDocs(input.placements.filter((placement)=>placement.published)) : undefined);
|
|
276
282
|
inputs.set(String(experiment.id), input);
|
|
@@ -292,7 +298,10 @@ async function placementUrls(options, placement, pendingPreviews, onFailure, pre
|
|
|
292
298
|
const key = JSON.stringify([
|
|
293
299
|
collection,
|
|
294
300
|
String(id),
|
|
295
|
-
published
|
|
301
|
+
published,
|
|
302
|
+
...placement.locale ? [
|
|
303
|
+
placement.locale
|
|
304
|
+
] : []
|
|
296
305
|
]);
|
|
297
306
|
let preview = previews.get(key);
|
|
298
307
|
if (!preview) previews.set(key, preview = previewLookup(options, placement, pendingPreviews, onFailure));
|
|
@@ -376,9 +385,11 @@ async function primaryHistory(source, now) {
|
|
|
376
385
|
return null;
|
|
377
386
|
}
|
|
378
387
|
}
|
|
379
|
-
export async function preflightData(req, { experimentId, options }, { now = new Date(), estimate = powerMetricWeeks } = {}) {
|
|
388
|
+
export async function preflightData(req, { experimentId, options, placementLocale }, { now = new Date(), estimate = powerMetricWeeks } = {}) {
|
|
380
389
|
const input = await loadStartInputs(req, options, experimentId);
|
|
381
390
|
if (!input) return null;
|
|
391
|
+
// Advisory title selection never changes the request used by scans or host adapters.
|
|
392
|
+
if (placementLocale !== undefined) input.placementLocale = placementLocale;
|
|
382
393
|
const { experiment: e } = input;
|
|
383
394
|
const primaryId = relationshipId(e.metrics?.primary);
|
|
384
395
|
const metric = input.metrics.find((metric)=>String(metric.id) === String(primaryId));
|
|
@@ -456,9 +467,11 @@ export async function preflightData(req, { experimentId, options }, { now = new
|
|
|
456
467
|
} catch {}
|
|
457
468
|
}
|
|
458
469
|
}
|
|
459
|
-
const requiredSlots = e.arms.
|
|
470
|
+
const requiredSlots = e.arms.flatMap((arm)=>arm.kind === 'holdout' || arm.key === 'holdout' ? [] : [
|
|
471
|
+
arm.key
|
|
472
|
+
]);
|
|
460
473
|
const blocks = input.placements ?? [];
|
|
461
|
-
|
|
474
|
+
let placements = new Array(blocks.length);
|
|
462
475
|
let nextPlacement = 0;
|
|
463
476
|
const pendingPreviews = {
|
|
464
477
|
count: 0
|
|
@@ -492,6 +505,70 @@ export async function preflightData(req, { experimentId, options }, { now = new
|
|
|
492
505
|
};
|
|
493
506
|
}
|
|
494
507
|
}));
|
|
508
|
+
let contentLocales;
|
|
509
|
+
if (blocks.some((placement)=>placement.locale)) {
|
|
510
|
+
const { placementLocale, placementDefaultLocale, placementLocaleCodes } = input;
|
|
511
|
+
const selected = placementLocale && placementLocaleCodes?.includes(placementLocale) ? placementLocale : placementDefaultLocale;
|
|
512
|
+
if (selected && placementLocaleCodes) {
|
|
513
|
+
const labels = placementLanguageNames(req, placementLocaleCodes);
|
|
514
|
+
contentLocales = {
|
|
515
|
+
selected,
|
|
516
|
+
labels: Object.fromEntries(placementLocaleCodes.map((code, index)=>[
|
|
517
|
+
code,
|
|
518
|
+
labels[index] ?? code
|
|
519
|
+
]))
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
// Summarize occurrences within one language and publication state first.
|
|
523
|
+
// Combine languages only when the complete displayed row agrees.
|
|
524
|
+
const languageRows = new Map();
|
|
525
|
+
blocks.forEach((placement, index)=>{
|
|
526
|
+
const key = JSON.stringify([
|
|
527
|
+
placement.collection,
|
|
528
|
+
String(placement.id),
|
|
529
|
+
placement.published,
|
|
530
|
+
placement.locale
|
|
531
|
+
]);
|
|
532
|
+
const group = languageRows.get(key) ?? [];
|
|
533
|
+
group.push(index);
|
|
534
|
+
languageRows.set(key, group);
|
|
535
|
+
});
|
|
536
|
+
const groups = new Map();
|
|
537
|
+
for (const indices of languageRows.values()){
|
|
538
|
+
const rows = indices.map((index)=>placements[index]), first = rows[0];
|
|
539
|
+
const slots = Object.fromEntries(BLOCK_SLOTS.map((slot)=>[
|
|
540
|
+
slot,
|
|
541
|
+
Math.min(...rows.map((row)=>row.slots[slot]))
|
|
542
|
+
]));
|
|
543
|
+
const partlyFilledSlots = first.detail === 'Draft' ? BLOCK_SLOTS.filter((slot)=>slots[slot] === 0 && rows.some((row)=>row.slots[slot] > 0)) : [];
|
|
544
|
+
const row = {
|
|
545
|
+
...first,
|
|
546
|
+
slotCount: rows.length,
|
|
547
|
+
ok: rows.every((row)=>row.ok),
|
|
548
|
+
slots,
|
|
549
|
+
...partlyFilledSlots.length ? {
|
|
550
|
+
partlyFilledSlots
|
|
551
|
+
} : {}
|
|
552
|
+
};
|
|
553
|
+
const key = JSON.stringify(row);
|
|
554
|
+
const group = groups.get(key) ?? {
|
|
555
|
+
row,
|
|
556
|
+
codes: []
|
|
557
|
+
};
|
|
558
|
+
const locale = blocks[indices[0]].locale;
|
|
559
|
+
if (locale) group.codes.push(locale);
|
|
560
|
+
groups.set(key, group);
|
|
561
|
+
}
|
|
562
|
+
placements = [
|
|
563
|
+
...groups.values()
|
|
564
|
+
].map(({ row, codes })=>({
|
|
565
|
+
...row,
|
|
566
|
+
...placementLanguages(req, codes),
|
|
567
|
+
...codes.length ? {
|
|
568
|
+
localeCodes: codes
|
|
569
|
+
} : {}
|
|
570
|
+
}));
|
|
571
|
+
}
|
|
495
572
|
for (const placement of input.flagPlacements ?? [])placements.push({
|
|
496
573
|
collection: e.flagPoint ?? '',
|
|
497
574
|
id: placement.arm,
|
|
@@ -567,6 +644,7 @@ export async function preflightData(req, { experimentId, options }, { now = new
|
|
|
567
644
|
});
|
|
568
645
|
continue;
|
|
569
646
|
}
|
|
647
|
+
doc = placementReader(req, collection.slug, options).read(doc, req.locale === 'all' ? 'all-locales' : 'localized').doc;
|
|
570
648
|
const titleField = req.payload.config.collections?.find((entry)=>entry.slug === collection.slug)?.admin.useAsTitle ?? 'title';
|
|
571
649
|
const placement = {
|
|
572
650
|
collection: collection.slug,
|
|
@@ -600,7 +678,15 @@ export async function preflightData(req, { experimentId, options }, { now = new
|
|
|
600
678
|
}
|
|
601
679
|
}
|
|
602
680
|
return {
|
|
681
|
+
document: {
|
|
682
|
+
status: e.status,
|
|
683
|
+
phase: e.phase,
|
|
684
|
+
updatedAt: e.updatedAt
|
|
685
|
+
},
|
|
603
686
|
checks: checkStart(input),
|
|
687
|
+
...metric && browserWritableMetric(metric.source, options) ? {
|
|
688
|
+
browserWritablePrimaryId: metric.id
|
|
689
|
+
} : {},
|
|
604
690
|
...input.goalContent ? {
|
|
605
691
|
goalNotes: input.metrics.filter((m)=>m.source.startsWith('click:') && input.goalContent && !input.goalContent.skipped && !input.goalContent.unchecked.length && !input.goalContent.keys.some((k)=>`click:${k.key}` === m.source)).map((m)=>({
|
|
606
692
|
metricId: m.id,
|
|
@@ -608,6 +694,9 @@ export async function preflightData(req, { experimentId, options }, { now = new
|
|
|
608
694
|
}))
|
|
609
695
|
} : {},
|
|
610
696
|
placements,
|
|
697
|
+
...contentLocales ? {
|
|
698
|
+
contentLocales
|
|
699
|
+
} : {},
|
|
611
700
|
...e.kind === 'page' ? {
|
|
612
701
|
pagePlacements
|
|
613
702
|
} : {},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { RoundBody } from '../types/endpoints.js';
|
|
1
2
|
import type { PayloadRequest } from 'payload';
|
|
2
3
|
import type { DocId } from '../types/contracts.js';
|
|
3
|
-
export declare function releaseHoldout(req: PayloadRequest, { experimentId }: {
|
|
4
|
+
export declare function releaseHoldout(req: PayloadRequest, { experimentId, phase: expectedPhase }: RoundBody & {
|
|
4
5
|
experimentId: DocId;
|
|
5
6
|
}): Promise<{
|
|
6
7
|
doc: import("payload").JsonObject & import("payload").TypeWithID;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { requireCurrentRound } from './phaseRecord.js';
|
|
1
2
|
import { relationshipId } from './checkStart.js';
|
|
2
3
|
import { withTransition } from './kernel.js';
|
|
3
4
|
import { readPhaseRecord, setPhaseEndedAt } from './phaseRecord.js';
|
|
4
5
|
import { readExperiment, refuse, updateExperiment } from './start.js';
|
|
5
|
-
export async function releaseHoldout(req, { experimentId }) {
|
|
6
|
+
export async function releaseHoldout(req, { experimentId, phase: expectedPhase }) {
|
|
6
7
|
const before = await readExperiment(req, experimentId);
|
|
7
8
|
const { result: doc, revision } = await withTransition(req, {
|
|
8
9
|
experimentId,
|
|
9
10
|
layerId: relationshipId(before.layer)
|
|
10
11
|
}, async ({ req })=>{
|
|
11
12
|
const current = await readExperiment(req, experimentId);
|
|
13
|
+
requireCurrentRound(expectedPhase, current.phase);
|
|
12
14
|
const decision = current.decision;
|
|
13
15
|
if (current.status !== 'decided' || !decision?.winnerArm || decision.holdoutReleasedAt) refuse('invalid-status');
|
|
14
16
|
const phase = await readPhaseRecord(req, experimentId, current.phase);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { RoundBody } from '../types/endpoints.js';
|
|
1
2
|
import type { PayloadRequest } from 'payload';
|
|
2
3
|
import type { DocId } from '../types/contracts.js';
|
|
3
|
-
export declare function releasePages(req: PayloadRequest, { experimentId }: {
|
|
4
|
+
export declare function releasePages(req: PayloadRequest, { experimentId, phase: expectedPhase }: RoundBody & {
|
|
4
5
|
experimentId: DocId;
|
|
5
6
|
}): Promise<{
|
|
6
7
|
doc: import("payload").JsonObject & import("payload").TypeWithID;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { requireCurrentRound } from './phaseRecord.js';
|
|
1
2
|
import { relationshipId } from './checkStart.js';
|
|
2
3
|
import { withTransition } from './kernel.js';
|
|
3
4
|
import { readExperiment, refuse, updateExperiment } from './start.js';
|
|
4
|
-
export async function releasePages(req, { experimentId }) {
|
|
5
|
+
export async function releasePages(req, { experimentId, phase: expectedPhase }) {
|
|
5
6
|
const before = await readExperiment(req, experimentId);
|
|
6
7
|
const { result: doc, revision } = await withTransition(req, {
|
|
7
8
|
experimentId,
|
|
8
9
|
layerId: relationshipId(before.layer)
|
|
9
10
|
}, async ({ req })=>{
|
|
10
11
|
const current = await readExperiment(req, experimentId);
|
|
12
|
+
requireCurrentRound(expectedPhase, current.phase);
|
|
11
13
|
const decision = current.decision;
|
|
12
14
|
if (current.kind !== 'page' || current.status !== 'archived' || !decision?.winnerArm || decision.discardedAt || decision.pagesReleasedAt) refuse('invalid-status');
|
|
13
15
|
const at = new Date().toISOString();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DocId, MetricSource } from '../types/contracts.js';
|
|
2
|
+
import type { StartExperimentWarning } from '../types/endpoints.js';
|
|
2
3
|
export interface MetricDefinition extends Record<string, unknown> {
|
|
3
4
|
id: DocId;
|
|
4
5
|
source: string;
|
|
@@ -22,8 +23,5 @@ export declare function resolveCaps(metrics: MetricDefinition[], sources: Metric
|
|
|
22
23
|
historyUnits?: number;
|
|
23
24
|
capNotice?: "no-history";
|
|
24
25
|
})[];
|
|
25
|
-
detail:
|
|
26
|
-
metricId: DocId;
|
|
27
|
-
message: string;
|
|
28
|
-
}[];
|
|
26
|
+
detail: StartExperimentWarning[];
|
|
29
27
|
}>;
|
|
@@ -3,24 +3,22 @@ import type { DocId, ResolvedOptions } from '../types/contracts.js';
|
|
|
3
3
|
import type { RefusalCode } from '../types/endpoints.js';
|
|
4
4
|
import { type StartExperiment } from './checkStart.js';
|
|
5
5
|
export type TransitionExperiment = StartExperiment & Record<string, unknown> & {
|
|
6
|
-
phase?: number;
|
|
7
6
|
seed?: string;
|
|
8
|
-
updatedAt?: string;
|
|
9
7
|
layerSlices?: number[] | null;
|
|
10
8
|
};
|
|
11
9
|
export declare function readExperiment(req: PayloadRequest, id: DocId): Promise<TransitionExperiment>;
|
|
12
10
|
export declare function refuse(code: RefusalCode, detail?: unknown): never;
|
|
13
|
-
export declare function updateExperiment(req: PayloadRequest, id: DocId, data: Record<string, unknown
|
|
11
|
+
export declare function updateExperiment(req: PayloadRequest, id: DocId, data: Record<string, unknown>, system?: boolean): Promise<import("payload").JsonObject & import("payload").TypeWithID>;
|
|
14
12
|
export declare function start<TUser extends {
|
|
15
13
|
id: DocId;
|
|
16
|
-
}>(req: PayloadRequest, { experimentId, options }: {
|
|
14
|
+
}>(req: PayloadRequest, { experimentId, options, phase: expectedPhase, system, onlyIfNeverStarted, }: {
|
|
17
15
|
experimentId: DocId;
|
|
18
16
|
options: ResolvedOptions<TUser>;
|
|
17
|
+
phase?: number;
|
|
18
|
+
system?: boolean;
|
|
19
|
+
onlyIfNeverStarted?: boolean;
|
|
19
20
|
}): Promise<{
|
|
20
|
-
detail?:
|
|
21
|
-
metricId: DocId;
|
|
22
|
-
message: string;
|
|
23
|
-
}[] | undefined;
|
|
21
|
+
detail?: import("../types/endpoints.js").StartExperimentWarning[] | undefined;
|
|
24
22
|
doc: import("payload").JsonObject & import("payload").TypeWithID;
|
|
25
23
|
revision: number;
|
|
26
24
|
}>;
|