@delmaredigital/payload-experiments 0.4.0-rc.7 → 0.4.0
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 +9 -15
- package/dist/admin/MetricSourceSelect.js +10 -3
- package/dist/admin/armSelect/armSelect.model.d.ts +1 -1
- package/dist/admin/blocks/BlockPanel.d.ts +1 -0
- package/dist/admin/blocks/BlockPanel.js +75 -29
- package/dist/admin/blocks/model.js +7 -6
- package/dist/admin/copy/blocks.d.ts +14 -11
- package/dist/admin/copy/blocks.js +33 -22
- package/dist/admin/copy/goals.d.ts +15 -8
- package/dist/admin/copy/goals.js +18 -8
- package/dist/admin/copy/newTest.d.ts +10 -7
- package/dist/admin/copy/newTest.js +14 -7
- package/dist/admin/copy/status.d.ts +1 -1
- package/dist/admin/copy/status.js +2 -1
- package/dist/admin/pageCollections.d.ts +1 -0
- package/dist/admin/pageCollections.js +3 -0
- package/dist/admin/placementStatus.model.js +5 -3
- package/dist/admin/status.model.d.ts +1 -0
- package/dist/admin/status.model.js +2 -1
- package/dist/admin/surface/ResultsRoute.js +12 -10
- package/dist/admin/surface/SurfaceShell.d.ts +4 -2
- package/dist/admin/surface/SurfaceShell.js +28 -3
- package/dist/admin/surface/TestRowMenu.d.ts +13 -0
- package/dist/admin/surface/TestRowMenu.js +163 -0
- package/dist/admin/surface/TestsHome.d.ts +4 -3
- package/dist/admin/surface/TestsHome.js +224 -52
- package/dist/admin/surface/TestsSurface.js +2 -1
- package/dist/admin/surface/goals/DeleteGoalDialog.d.ts +7 -0
- package/dist/admin/surface/goals/DeleteGoalDialog.js +42 -0
- package/dist/admin/surface/goals/GoalForm.d.ts +1 -0
- package/dist/admin/surface/goals/GoalForm.js +280 -198
- package/dist/admin/surface/goals/GoalsList.js +102 -33
- package/dist/admin/surface/goals/data.d.ts +2 -0
- package/dist/admin/surface/goals/data.js +9 -0
- package/dist/admin/surface/goals/goals.css +3 -2
- package/dist/admin/surface/goals/goals.model.d.ts +2 -2
- package/dist/admin/surface/goals/goals.model.js +7 -12
- package/dist/admin/surface/home.model.d.ts +15 -8
- package/dist/admin/surface/home.model.js +22 -18
- package/dist/admin/surface/newTest/NewTest.d.ts +3 -3
- package/dist/admin/surface/newTest/NewTest.js +156 -96
- package/dist/admin/surface/newTest/PageWizard.d.ts +4 -1
- package/dist/admin/surface/newTest/PageWizard.js +99 -68
- package/dist/admin/surface/newTest/newTest.css +28 -11
- package/dist/admin/surface/results/ResultsHeader.d.ts +1 -1
- package/dist/admin/surface/results/ResultsHeader.js +98 -66
- package/dist/admin/surface/surface.css +29 -0
- package/dist/admin/surface/test/TestPage.js +46 -38
- package/dist/admin/surface/useXpStepNav.d.ts +11 -0
- package/dist/admin/surface/useXpStepNav.js +14 -0
- package/dist/admin/views/TestsSurfaceClient.js +27 -3
- package/dist/admin/views/buildSurfaceProps.js +18 -66
- package/dist/arms/copy.d.ts +13 -3
- package/dist/arms/copy.js +5 -4
- package/dist/blocks/createExperimentBlock.js +1 -1
- package/dist/blocks/formState.js +2 -2
- package/dist/collections/experiments/armInvariants.js +8 -5
- 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/metrics.js +12 -5
- package/dist/collections/metricsGuards.js +2 -0
- package/dist/collections/serialize.js +8 -6
- 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/pageCopies.d.ts +5 -0
- package/dist/db/pageCopies.js +31 -0
- package/dist/db/results.d.ts +5 -1
- package/dist/db/results.js +21 -5
- package/dist/db/snapshots.d.ts +2 -0
- package/dist/endpoints/deleteImpact.js +2 -1
- package/dist/endpoints/duplicateOriginal.d.ts +38 -0
- package/dist/endpoints/duplicateOriginal.js +414 -0
- package/dist/endpoints/editorSurface.js +1 -1
- package/dist/endpoints/events.js +103 -39
- package/dist/endpoints/index.js +22 -8
- package/dist/endpoints/pages.js +245 -66
- package/dist/endpoints/placementStatus.js +8 -4
- package/dist/endpoints/results.d.ts +1 -1
- package/dist/endpoints/results.js +9 -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/testVersion.d.ts +2 -0
- package/dist/endpoints/testVersion.js +38 -0
- package/dist/endpoints/transitions.js +41 -29
- 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/goals/picker/copy.js +1 -1
- package/dist/goals/sourceLabel.d.ts +2 -0
- package/dist/goals/sourceLabel.js +4 -0
- package/dist/hooks/hostHook.js +6 -2
- package/dist/hooks/pageGuard.js +4 -0
- package/dist/hooks/trackPageCopies.d.ts +11 -0
- package/dist/hooks/trackPageCopies.js +7 -0
- package/dist/labels/arms.d.ts +3 -0
- package/dist/labels/arms.js +8 -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.d.ts +2 -0
- package/dist/options.js +23 -2
- package/dist/plugin.js +56 -2
- 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.d.ts +7 -7
- package/dist/puck/editor/ConfigureTestDrawer.js +40 -29
- package/dist/puck/editor/ExperimentSlotEditor.d.ts +2 -1
- package/dist/puck/editor/ExperimentSlotEditor.js +376 -139
- package/dist/puck/editor/LeftoverVersions.js +17 -32
- package/dist/puck/editor/QuickTestActions.d.ts +6 -3
- package/dist/puck/editor/QuickTestActions.js +55 -33
- package/dist/puck/editor/ResultsReadout.d.ts +4 -1
- package/dist/puck/editor/ResultsReadout.js +28 -15
- package/dist/puck/editor/VersionBuilder.d.ts +17 -4
- package/dist/puck/editor/VersionBuilder.js +175 -112
- package/dist/puck/editor/armWrites.js +2 -2
- package/dist/puck/editor/armsCache.js +1 -3
- package/dist/puck/editor/copy.d.ts +14 -7
- package/dist/puck/editor/copy.js +26 -13
- package/dist/puck/editor/editor.chrome.css +10 -8
- package/dist/puck/editor/editor.css +15 -9
- package/dist/puck/editor/editor.model.d.ts +1 -0
- package/dist/puck/editor/placementsCache.d.ts +4 -0
- package/dist/puck/editor/usePageSaveReadiness.d.ts +6 -0
- package/dist/puck/editor/usePageSaveReadiness.js +31 -0
- package/dist/puck/nestedTestCopy.js +2 -2
- package/dist/puck/slotConfig.d.ts +1 -1
- package/dist/puck/slotConfig.js +1 -1
- package/dist/results/aggregate.d.ts +6 -3
- package/dist/results/aggregate.js +9 -9
- package/dist/results/analyse.d.ts +2 -0
- package/dist/results/analyse.js +2 -2
- 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.d.ts +4 -4
- package/dist/results/verdict.js +15 -11
- 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 +54 -15
- 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.d.ts +2 -1
- package/dist/testSurface/PreviewLinks.js +3 -3
- package/dist/testSurface/actions/DecideDialog.d.ts +10 -4
- package/dist/testSurface/actions/DecideDialog.js +93 -63
- package/dist/testSurface/actions/LifecycleAction.d.ts +17 -0
- package/dist/testSurface/actions/LifecycleAction.js +107 -0
- package/dist/testSurface/actions/MakeContentResult.d.ts +4 -3
- package/dist/testSurface/actions/MakeContentResult.js +10 -2
- package/dist/testSurface/actions/actions.model.d.ts +13 -5
- package/dist/testSurface/actions/actions.model.js +75 -22
- package/dist/testSurface/actions/decide.model.d.ts +1 -0
- package/dist/testSurface/actions/decide.model.js +1 -0
- package/dist/testSurface/allocation.model.js +6 -3
- package/dist/testSurface/api.d.ts +9 -6
- package/dist/testSurface/api.js +43 -23
- package/dist/testSurface/copy/actions.d.ts +37 -14
- package/dist/testSurface/copy/actions.js +40 -17
- package/dist/testSurface/copy/advanced.d.ts +10 -0
- package/dist/testSurface/copy/advanced.js +10 -0
- package/dist/testSurface/copy/arms.d.ts +1 -1
- package/dist/testSurface/copy/arms.js +1 -1
- package/dist/testSurface/copy/audience.d.ts +4 -3
- package/dist/testSurface/copy/audience.js +5 -4
- package/dist/testSurface/copy/common.d.ts +8 -6
- package/dist/testSurface/copy/common.js +8 -6
- package/dist/testSurface/copy/languages.d.ts +1 -0
- package/dist/testSurface/copy/languages.js +1 -0
- package/dist/testSurface/copy/metrics.d.ts +7 -0
- package/dist/testSurface/copy/metrics.js +9 -0
- package/dist/testSurface/copy/pages.d.ts +67 -7
- package/dist/testSurface/copy/pages.js +74 -7
- package/dist/testSurface/copy/readiness.d.ts +20 -7
- package/dist/testSurface/copy/readiness.js +36 -10
- package/dist/testSurface/copy/recommendation.d.ts +1 -22
- package/dist/testSurface/copy/recommendation.js +2 -22
- package/dist/testSurface/copy/results.d.ts +21 -12
- package/dist/testSurface/copy/results.js +24 -13
- package/dist/testSurface/copy/review.d.ts +13 -10
- package/dist/testSurface/copy/review.js +14 -10
- package/dist/testSurface/copy/setting.d.ts +1 -2
- package/dist/testSurface/copy/setting.js +1 -2
- package/dist/testSurface/copy/surface.d.ts +11 -2
- package/dist/testSurface/copy/surface.js +14 -11
- package/dist/testSurface/copy/testPage.d.ts +36 -12
- package/dist/testSurface/copy/testPage.js +53 -16
- package/dist/testSurface/format/date.d.ts +5 -2
- package/dist/testSurface/format/date.js +24 -8
- package/dist/testSurface/format/roundProgress.d.ts +6 -0
- package/dist/testSurface/format/roundProgress.js +15 -0
- package/dist/testSurface/format/useDateFormatter.d.ts +3 -0
- package/dist/testSurface/format/useDateFormatter.js +8 -0
- package/dist/testSurface/labels.d.ts +1 -2
- package/dist/testSurface/labels.js +2 -3
- package/dist/testSurface/lockedNotice.model.d.ts +2 -0
- package/dist/testSurface/lockedNotice.model.js +31 -0
- package/dist/testSurface/readPreflight.d.ts +4 -0
- package/dist/testSurface/readPreflight.js +6 -0
- package/dist/testSurface/readinessRead.d.ts +3 -0
- package/dist/testSurface/readinessRead.js +4 -0
- package/dist/testSurface/results/CiChart.js +2 -1
- package/dist/testSurface/results/DataTable.d.ts +1 -1
- package/dist/testSurface/results/DataTable.js +4 -3
- package/dist/testSurface/results/VerdictHero.d.ts +3 -2
- package/dist/testSurface/results/VerdictHero.js +5 -1
- package/dist/testSurface/results/legacy.d.ts +0 -5
- package/dist/testSurface/results/legacy.js +0 -14
- package/dist/testSurface/results/results.css +2 -2
- package/dist/testSurface/results/results.model.d.ts +9 -4
- package/dist/testSurface/results/results.model.js +31 -23
- package/dist/testSurface/results/snapshot.d.ts +2 -0
- package/dist/testSurface/results/snapshot.js +3 -0
- package/dist/testSurface/surface/contracts.d.ts +13 -1
- package/dist/testSurface/surface/editorPlacement.d.ts +3 -3
- package/dist/testSurface/surface/editorPlacement.js +2 -2
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +3 -3
- package/dist/testSurface/surface/pageBlock/parts.js +25 -12
- package/dist/testSurface/surface/pagePicker/CopyRoute.d.ts +8 -1
- package/dist/testSurface/surface/pagePicker/CopyRoute.js +243 -22
- package/dist/testSurface/surface/pagePicker/PageCombobox.d.ts +15 -4
- package/dist/testSurface/surface/pagePicker/PageCombobox.js +300 -197
- package/dist/testSurface/surface/pagePicker/pagePicker.css +73 -10
- package/dist/testSurface/surface/pagePicker/pagePicker.model.d.ts +5 -3
- package/dist/testSurface/surface/pagePicker/pagePicker.model.js +17 -2
- package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +9 -5
- package/dist/testSurface/surface/readiness/ActionDialogs.js +241 -230
- package/dist/testSurface/surface/readiness/Banner.d.ts +5 -1
- package/dist/testSurface/surface/readiness/Banner.js +113 -141
- package/dist/testSurface/surface/readiness/SaveStatus.d.ts +8 -4
- package/dist/testSurface/surface/readiness/SaveStatus.js +23 -22
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +20 -6
- package/dist/testSurface/surface/readiness/readiness.model.js +168 -21
- package/dist/testSurface/surface/readiness/useTransition.d.ts +6 -4
- package/dist/testSurface/surface/readiness/useTransition.js +57 -14
- package/dist/testSurface/surface/results/ReleasePages.d.ts +6 -3
- package/dist/testSurface/surface/results/ReleasePages.js +42 -41
- package/dist/testSurface/surface/results/ResultsBody.d.ts +11 -4
- package/dist/testSurface/surface/results/ResultsBody.js +221 -118
- package/dist/testSurface/surface/results/recommendation.model.d.ts +6 -9
- package/dist/testSurface/surface/results/recommendation.model.js +15 -59
- package/dist/testSurface/surface/results/useResults.d.ts +13 -8
- package/dist/testSurface/surface/results/useResults.js +3 -2
- package/dist/testSurface/surface/setting/parts.js +89 -46
- package/dist/testSurface/surface/setting/setting.css +2 -1
- package/dist/testSurface/surface/test/AdvancedSection.js +11 -4
- package/dist/testSurface/surface/test/DeleteTest.d.ts +10 -2
- package/dist/testSurface/surface/test/DeleteTest.js +173 -74
- package/dist/testSurface/surface/test/GoalSection.js +18 -14
- package/dist/testSurface/surface/test/LengthSection.js +24 -13
- package/dist/testSurface/surface/test/PageHoldout.d.ts +1 -1
- package/dist/testSurface/surface/test/PageHoldout.js +11 -8
- package/dist/testSurface/surface/test/ReadinessBar.d.ts +2 -1
- package/dist/testSurface/surface/test/ReadinessBar.js +4 -10
- package/dist/testSurface/surface/test/Section.js +8 -0
- package/dist/testSurface/surface/test/TargetingSection.js +82 -12
- package/dist/testSurface/surface/test/TestSurface.js +73 -37
- package/dist/testSurface/surface/test/VersionsSection.js +141 -91
- package/dist/testSurface/surface/test/fields.d.ts +32 -6
- package/dist/testSurface/surface/test/fields.js +166 -52
- package/dist/testSurface/surface/test/pageParts.js +27 -12
- package/dist/testSurface/surface/test/testPage.css +9 -2
- 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 +21 -5
- package/dist/testSurface/surface/useTestDocument.js +472 -167
- package/dist/testSurface/surface/watchTestDocument.d.ts +15 -0
- package/dist/testSurface/surface/watchTestDocument.js +181 -0
- package/dist/testSurface/surfaceUrls.d.ts +1 -0
- package/dist/testSurface/surfaceUrls.js +4 -0
- package/dist/testSurface/useApi.d.ts +8 -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 +2 -5
- package/dist/transitions/addMetric.js +5 -1
- 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 +4 -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/pageAddress.d.ts +6 -0
- package/dist/transitions/pageAddress.js +71 -0
- package/dist/transitions/pageVersions.d.ts +1 -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 +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 +77 -43
- 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 +7 -9
- package/dist/transitions/start.js +75 -39
- 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/armKey.d.ts +2 -0
- package/dist/types/armKey.js +1 -0
- package/dist/types/contracts.d.ts +17 -4
- package/dist/types/endpoints.d.ts +89 -17
- 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 +7 -9
- package/dist/ui/ChipsInput.d.ts +8 -1
- package/dist/ui/ChipsInput.js +17 -4
- package/dist/ui/Dialog.d.ts +21 -2
- package/dist/ui/Dialog.js +101 -4
- package/dist/ui/Inputs.js +0 -1
- package/dist/ui/ui.css +5 -1
- package/package.json +2 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DocId } from '../../types/contracts.js';
|
|
2
|
+
/** Broadcast a completed mutation when its caller has no mounted document watcher. */
|
|
3
|
+
export declare function notifyTestDocument(apiRoute: string, id: DocId): void;
|
|
4
|
+
type Check = (reasons: {
|
|
5
|
+
broadcast: boolean;
|
|
6
|
+
returned: boolean;
|
|
7
|
+
}) => Promise<'ok' | 'retry' | 'stop'>;
|
|
8
|
+
type CheckResult = Awaited<ReturnType<Check>>;
|
|
9
|
+
/** Owns the single background read and its timer for one mounted test. */
|
|
10
|
+
export declare function watchTestDocument(apiRoute: string, id: DocId, check: Check): {
|
|
11
|
+
start(initial: CheckResult): void;
|
|
12
|
+
notify(): void;
|
|
13
|
+
close(): void;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
const POLL_MS = 5_000;
|
|
2
|
+
const IDLE_MS = 10 * 60_000;
|
|
3
|
+
const WINDOW_AWAY_MS = 250;
|
|
4
|
+
const RETRY_MS = [
|
|
5
|
+
4_000,
|
|
6
|
+
8_000,
|
|
7
|
+
16_000,
|
|
8
|
+
30_000
|
|
9
|
+
];
|
|
10
|
+
function openChannel(apiRoute, id) {
|
|
11
|
+
const key = JSON.stringify([
|
|
12
|
+
apiRoute.replace(/\/$/, ''),
|
|
13
|
+
String(id)
|
|
14
|
+
]);
|
|
15
|
+
try {
|
|
16
|
+
return new BroadcastChannel(`xp-test:${key}`);
|
|
17
|
+
} catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Broadcast a completed mutation when its caller has no mounted document watcher. */ export function notifyTestDocument(apiRoute, id) {
|
|
22
|
+
const sender = openChannel(apiRoute, id);
|
|
23
|
+
sender?.postMessage(null);
|
|
24
|
+
sender?.close();
|
|
25
|
+
}
|
|
26
|
+
/** Owns the single background read and its timer for one mounted test. */ export function watchTestDocument(apiRoute, id, check) {
|
|
27
|
+
const channel = openChannel(apiRoute, id);
|
|
28
|
+
const inputEvents = [
|
|
29
|
+
'pointerdown',
|
|
30
|
+
'pointermove',
|
|
31
|
+
'keydown',
|
|
32
|
+
'scroll'
|
|
33
|
+
];
|
|
34
|
+
let timer;
|
|
35
|
+
let lastInput = Date.now();
|
|
36
|
+
let retryAt = 0;
|
|
37
|
+
let failures = 0;
|
|
38
|
+
let started = false;
|
|
39
|
+
let closed = false;
|
|
40
|
+
let inFlight = false;
|
|
41
|
+
let requested = false;
|
|
42
|
+
let broadcast = false;
|
|
43
|
+
let returned = false;
|
|
44
|
+
let polling = true;
|
|
45
|
+
const visible = ()=>document.visibilityState === 'visible';
|
|
46
|
+
const active = ()=>Date.now() - lastInput < IDLE_MS;
|
|
47
|
+
let wasVisible = visible();
|
|
48
|
+
let awaitingPageShow = false;
|
|
49
|
+
let blurredAt;
|
|
50
|
+
let focusCheck;
|
|
51
|
+
function record(result) {
|
|
52
|
+
polling = result !== 'stop';
|
|
53
|
+
failures = result === 'retry' ? failures + 1 : 0;
|
|
54
|
+
retryAt = failures ? Date.now() + RETRY_MS[Math.min(failures - 1, RETRY_MS.length - 1)] : 0;
|
|
55
|
+
}
|
|
56
|
+
function schedule() {
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
if (!started || closed || inFlight) return;
|
|
59
|
+
if (!broadcast && (!visible() || !requested && (!polling || !active()))) return;
|
|
60
|
+
const delay = requested || broadcast ? 0 : failures ? retryAt - Date.now() : POLL_MS;
|
|
61
|
+
const wait = Math.max(delay, retryAt - Date.now(), 0);
|
|
62
|
+
if (wait === 0) void run();
|
|
63
|
+
else timer = setTimeout(()=>{
|
|
64
|
+
void run();
|
|
65
|
+
}, wait);
|
|
66
|
+
}
|
|
67
|
+
async function run() {
|
|
68
|
+
if (closed || inFlight || !broadcast && (!visible() || !requested && !active())) return;
|
|
69
|
+
inFlight = true;
|
|
70
|
+
const reasons = {
|
|
71
|
+
broadcast,
|
|
72
|
+
returned
|
|
73
|
+
};
|
|
74
|
+
requested = false;
|
|
75
|
+
broadcast = false;
|
|
76
|
+
returned = false;
|
|
77
|
+
try {
|
|
78
|
+
record(await check(reasons));
|
|
79
|
+
} catch {
|
|
80
|
+
record('retry');
|
|
81
|
+
} finally{
|
|
82
|
+
inFlight = false;
|
|
83
|
+
schedule();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function onInput() {
|
|
87
|
+
const wasIdle = !active();
|
|
88
|
+
lastInput = Date.now();
|
|
89
|
+
if (wasIdle && visible() && polling) {
|
|
90
|
+
requested = true;
|
|
91
|
+
schedule();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function requestReturn() {
|
|
95
|
+
requested = true;
|
|
96
|
+
returned = true;
|
|
97
|
+
schedule();
|
|
98
|
+
}
|
|
99
|
+
function onVisibility() {
|
|
100
|
+
const nowVisible = visible();
|
|
101
|
+
const becameVisible = nowVisible && !wasVisible;
|
|
102
|
+
wasVisible = nowVisible;
|
|
103
|
+
if (becameVisible && !awaitingPageShow) {
|
|
104
|
+
requestReturn();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (!nowVisible) {
|
|
108
|
+
requested = false;
|
|
109
|
+
returned = false;
|
|
110
|
+
blurredAt = undefined;
|
|
111
|
+
}
|
|
112
|
+
schedule();
|
|
113
|
+
}
|
|
114
|
+
function onBlur() {
|
|
115
|
+
clearTimeout(focusCheck);
|
|
116
|
+
if (!visible()) return;
|
|
117
|
+
blurredAt = Date.now();
|
|
118
|
+
// Let focus settle. The document still has focus when it moves into
|
|
119
|
+
// a child frame, including the Puck canvas.
|
|
120
|
+
focusCheck = setTimeout(()=>{
|
|
121
|
+
if (document.hasFocus()) blurredAt = undefined;
|
|
122
|
+
}, 0);
|
|
123
|
+
}
|
|
124
|
+
function onFocus() {
|
|
125
|
+
// Switching windows can leave the document visible the whole time.
|
|
126
|
+
clearTimeout(focusCheck);
|
|
127
|
+
const returnedToWindow = blurredAt !== undefined && Date.now() - blurredAt >= WINDOW_AWAY_MS && wasVisible && visible() && !awaitingPageShow;
|
|
128
|
+
blurredAt = undefined;
|
|
129
|
+
if (returnedToWindow) requestReturn();
|
|
130
|
+
}
|
|
131
|
+
function onPageHide(event) {
|
|
132
|
+
// A restored page can become visible before pageshow. Count it as one return.
|
|
133
|
+
awaitingPageShow = event.persisted;
|
|
134
|
+
blurredAt = undefined;
|
|
135
|
+
}
|
|
136
|
+
function onPageShow(event) {
|
|
137
|
+
if (!event.persisted) return;
|
|
138
|
+
awaitingPageShow = false;
|
|
139
|
+
wasVisible = visible();
|
|
140
|
+
if (wasVisible) requestReturn();
|
|
141
|
+
}
|
|
142
|
+
channel?.addEventListener('message', ()=>{
|
|
143
|
+
broadcast = true;
|
|
144
|
+
schedule();
|
|
145
|
+
});
|
|
146
|
+
for (const event of inputEvents)document.addEventListener(event, onInput, {
|
|
147
|
+
capture: true,
|
|
148
|
+
passive: true
|
|
149
|
+
});
|
|
150
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
151
|
+
window.addEventListener('blur', onBlur);
|
|
152
|
+
window.addEventListener('focus', onFocus);
|
|
153
|
+
window.addEventListener('pagehide', onPageHide);
|
|
154
|
+
window.addEventListener('pageshow', onPageShow);
|
|
155
|
+
return {
|
|
156
|
+
start (initial) {
|
|
157
|
+
record(initial);
|
|
158
|
+
started = true;
|
|
159
|
+
schedule();
|
|
160
|
+
},
|
|
161
|
+
notify () {
|
|
162
|
+
if (!closed) channel?.postMessage(null);
|
|
163
|
+
else {
|
|
164
|
+
// A submitted save can finish after its reader has unmounted.
|
|
165
|
+
notifyTestDocument(apiRoute, id);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
close () {
|
|
169
|
+
closed = true;
|
|
170
|
+
clearTimeout(timer);
|
|
171
|
+
clearTimeout(focusCheck);
|
|
172
|
+
channel?.close();
|
|
173
|
+
for (const event of inputEvents)document.removeEventListener(event, onInput, true);
|
|
174
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
175
|
+
window.removeEventListener('blur', onBlur);
|
|
176
|
+
window.removeEventListener('focus', onFocus);
|
|
177
|
+
window.removeEventListener('pagehide', onPageHide);
|
|
178
|
+
window.removeEventListener('pageshow', onPageShow);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
@@ -2,6 +2,7 @@ type SurfaceQuery = Record<string, string | string[] | undefined>;
|
|
|
2
2
|
export declare function surfaceQuery(query?: SurfaceQuery): string;
|
|
3
3
|
export declare const surfaceUrls: {
|
|
4
4
|
home: (adminRoute: string, query?: SurfaceQuery) => string;
|
|
5
|
+
newGoal: (adminRoute: string, query?: SurfaceQuery) => string;
|
|
5
6
|
goals: (adminRoute: string, query?: SurfaceQuery) => string;
|
|
6
7
|
};
|
|
7
8
|
export {};
|
|
@@ -12,6 +12,10 @@ export const surfaceUrls = {
|
|
|
12
12
|
adminRoute,
|
|
13
13
|
path: `/collections/xp-experiments${surfaceQuery(query)}`
|
|
14
14
|
}),
|
|
15
|
+
newGoal: (adminRoute, query)=>formatAdminURL({
|
|
16
|
+
adminRoute,
|
|
17
|
+
path: `/experiments/goals/new${surfaceQuery(query)}`
|
|
18
|
+
}),
|
|
15
19
|
goals: (adminRoute, query)=>formatAdminURL({
|
|
16
20
|
adminRoute,
|
|
17
21
|
path: `/collections/xp-metrics${surfaceQuery(query)}`
|
|
@@ -14,9 +14,12 @@ export declare function useApi(apiRoute: string): {
|
|
|
14
14
|
q?: string;
|
|
15
15
|
path?: string;
|
|
16
16
|
page?: number;
|
|
17
|
+
mode?: "block";
|
|
17
18
|
}, signal?: AbortSignal) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").PagesResult>>;
|
|
19
|
+
previewPageCopy: (id: import("../types/contracts.js").DocId, arm: string, signal?: AbortSignal) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").CopyPagePlan>>;
|
|
20
|
+
makePageCopy: (id: import("../types/contracts.js").DocId, arm: string, plan: import("../types/endpoints.js").CopyPagePlan) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").CopyPageResult>>;
|
|
18
21
|
placementStatus: (body: import("../types/endpoints.js").PlacementStatusBody) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").PlacementStatusResult>>;
|
|
19
|
-
start: (id: import("../types/contracts.js").DocId) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").TransitionSuccess>>;
|
|
22
|
+
start: (id: import("../types/contracts.js").DocId, phase?: number) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").TransitionSuccess>>;
|
|
20
23
|
allocate: (id: import("../types/contracts.js").DocId, body: import("../types/endpoints.js").AllocateBody, options?: {
|
|
21
24
|
notFound?: string;
|
|
22
25
|
forbidden?: string;
|
|
@@ -29,11 +32,11 @@ export declare function useApi(apiRoute: string): {
|
|
|
29
32
|
codes?: Readonly<Record<string, string>>;
|
|
30
33
|
fallback?: string;
|
|
31
34
|
}) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").AddMetricResult>>;
|
|
32
|
-
stop: (id: import("../types/contracts.js").DocId) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").TransitionSuccess>>;
|
|
35
|
+
stop: (id: import("../types/contracts.js").DocId, phase?: number) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").TransitionSuccess>>;
|
|
33
36
|
decide: (id: import("../types/contracts.js").DocId, body: import("../types/endpoints.js").DecideBody) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").TransitionSuccess>>;
|
|
34
|
-
releaseHoldout: (id: import("../types/contracts.js").DocId) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").TransitionSuccess>>;
|
|
35
|
-
releasePages: (id: import("../types/contracts.js").DocId) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").TransitionSuccess>>;
|
|
36
|
-
makeContent: (id: import("../types/contracts.js").DocId) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").MakeContentResult>>;
|
|
37
|
+
releaseHoldout: (id: import("../types/contracts.js").DocId, phase?: number) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").TransitionSuccess>>;
|
|
38
|
+
releasePages: (id: import("../types/contracts.js").DocId, phase?: number) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").TransitionSuccess>>;
|
|
39
|
+
makeContent: (id: import("../types/contracts.js").DocId, phase?: number) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").MakeContentResult>>;
|
|
37
40
|
dismissContentEntry: (id: import("../types/contracts.js").DocId, body: import("../types/endpoints.js").DismissContentEntryBody) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").DismissContentEntryResult>>;
|
|
38
41
|
restoreContentEntry: (id: import("../types/contracts.js").DocId, body: import("../types/endpoints.js").RestoreContentEntryBody) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").RestoreContentEntryResult>>;
|
|
39
42
|
archive: (id: import("../types/contracts.js").DocId, body: import("../types/endpoints.js").ArchiveBody) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").TransitionSuccess>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
/** Focus and visibility can both fire when returning to a tab. */ export function useOnTestReturn(onReturn, enabled = true) {
|
|
4
|
+
useEffect(()=>{
|
|
5
|
+
if (!enabled) return;
|
|
6
|
+
let lastReturn = -Infinity;
|
|
7
|
+
const refresh = ()=>{
|
|
8
|
+
if (document.visibilityState !== 'visible' || Date.now() - lastReturn < 100) return;
|
|
9
|
+
lastReturn = Date.now();
|
|
10
|
+
onReturn();
|
|
11
|
+
};
|
|
12
|
+
const restored = (event)=>{
|
|
13
|
+
if (event.persisted) refresh();
|
|
14
|
+
};
|
|
15
|
+
window.addEventListener('focus', refresh);
|
|
16
|
+
window.addEventListener('pageshow', restored);
|
|
17
|
+
document.addEventListener('visibilitychange', refresh);
|
|
18
|
+
return ()=>{
|
|
19
|
+
window.removeEventListener('focus', refresh);
|
|
20
|
+
window.removeEventListener('pageshow', restored);
|
|
21
|
+
document.removeEventListener('visibilitychange', refresh);
|
|
22
|
+
};
|
|
23
|
+
}, [
|
|
24
|
+
enabled,
|
|
25
|
+
onReturn
|
|
26
|
+
]);
|
|
27
|
+
}
|
|
@@ -8,7 +8,9 @@ import { useEffect, useRef } from 'react';
|
|
|
8
8
|
let timer;
|
|
9
9
|
const schedule = ()=>{
|
|
10
10
|
clearTimeout(timer);
|
|
11
|
-
if (document.visibilityState === 'visible') timer = setTimeout(()=>
|
|
11
|
+
if (document.visibilityState === 'visible') timer = setTimeout(()=>{
|
|
12
|
+
if (document.visibilityState === 'visible') action.current();
|
|
13
|
+
}, read.pollDelay);
|
|
12
14
|
};
|
|
13
15
|
schedule();
|
|
14
16
|
document.addEventListener('visibilitychange', schedule);
|
|
@@ -3,14 +3,11 @@ import type { DocId, ResolvedOptions } from '../types/contracts.js';
|
|
|
3
3
|
import type { AddMetricBody, AddMetricWarning } from '../types/endpoints.js';
|
|
4
4
|
export declare function addMetric<TUser extends {
|
|
5
5
|
id: DocId;
|
|
6
|
-
}>(req: PayloadRequest, { experimentId, metric, role, options }: AddMetricBody & {
|
|
6
|
+
}>(req: PayloadRequest, { experimentId, metric, role, phase: expectedPhase, options }: AddMetricBody & {
|
|
7
7
|
experimentId: DocId;
|
|
8
8
|
options: ResolvedOptions<TUser>;
|
|
9
9
|
}): Promise<{
|
|
10
|
-
detail?:
|
|
11
|
-
metricId: DocId;
|
|
12
|
-
message: string;
|
|
13
|
-
}[] | undefined;
|
|
10
|
+
detail?: import("../types/endpoints.js").StartExperimentWarning[] | undefined;
|
|
14
11
|
warnings: AddMetricWarning[];
|
|
15
12
|
doc: import("payload").JsonObject & import("payload").TypeWithID;
|
|
16
13
|
revision: number;
|
|
@@ -6,9 +6,12 @@ import { relationshipId } from './checkStart.js';
|
|
|
6
6
|
import { withTransition } from './kernel.js';
|
|
7
7
|
import { readExperiment, refuse, updateExperiment } from './start.js';
|
|
8
8
|
import { resolveCaps } from './resolveCaps.js';
|
|
9
|
-
|
|
9
|
+
import { requireCurrentRound } from './phaseRecord.js';
|
|
10
|
+
export async function addMetric(req, { experimentId, metric, role, phase: expectedPhase, options }) {
|
|
10
11
|
if (role !== 'secondary' && role !== 'guardrail') refuse('invalid-body');
|
|
11
12
|
const before = await readExperiment(req, experimentId);
|
|
13
|
+
const openedPhase = before.phase;
|
|
14
|
+
requireCurrentRound(expectedPhase, openedPhase);
|
|
12
15
|
if (before.status !== 'running') refuse('invalid-status');
|
|
13
16
|
const found = await req.payload.find({
|
|
14
17
|
collection: 'xp-metrics',
|
|
@@ -62,6 +65,7 @@ export async function addMetric(req, { experimentId, metric, role, options }) {
|
|
|
62
65
|
bump: false
|
|
63
66
|
}, async ({ req, exec })=>{
|
|
64
67
|
const current = await readExperiment(req, experimentId);
|
|
68
|
+
requireCurrentRound(expectedPhase ?? openedPhase, current.phase);
|
|
65
69
|
if (current.status !== 'running') refuse('invalid-status');
|
|
66
70
|
const ids = [
|
|
67
71
|
current.metrics?.primary,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { PayloadRequest } from 'payload';
|
|
2
2
|
import type { DocId } from '../types/contracts.js';
|
|
3
|
-
|
|
3
|
+
import type { AllocateBody } from '../types/endpoints.js';
|
|
4
|
+
export declare function allocate(req: PayloadRequest, { experimentId, allocation, phase: expectedPhase }: AllocateBody & {
|
|
4
5
|
experimentId: DocId;
|
|
5
|
-
allocation: number;
|
|
6
6
|
}): Promise<{
|
|
7
7
|
doc: import("payload").JsonObject & import("payload").TypeWithID;
|
|
8
8
|
revision: number;
|
|
@@ -3,8 +3,9 @@ import { appendAllocationChange } from '../db/appends.js';
|
|
|
3
3
|
import { claimSlices } from '../db/slices.js';
|
|
4
4
|
import { relationshipId } from './checkStart.js';
|
|
5
5
|
import { withTransition } from './kernel.js';
|
|
6
|
+
import { requireCurrentRound } from './phaseRecord.js';
|
|
6
7
|
import { readExperiment, refuse, updateExperiment } from './start.js';
|
|
7
|
-
export async function allocate(req, { experimentId, allocation }) {
|
|
8
|
+
export async function allocate(req, { experimentId, allocation, phase: expectedPhase }) {
|
|
8
9
|
if (!Number.isInteger(allocation) || allocation < 1 || allocation > 100) refuse('invalid-body');
|
|
9
10
|
const before = await readExperiment(req, experimentId);
|
|
10
11
|
const { result: doc, revision } = await withTransition(req, {
|
|
@@ -12,6 +13,7 @@ export async function allocate(req, { experimentId, allocation }) {
|
|
|
12
13
|
layerId: relationshipId(before.layer)
|
|
13
14
|
}, async ({ req, exec })=>{
|
|
14
15
|
const current = await readExperiment(req, experimentId);
|
|
16
|
+
requireCurrentRound(expectedPhase, current.phase);
|
|
15
17
|
if (current.status !== 'running') refuse('invalid-status');
|
|
16
18
|
if (allocation <= current.allocation) refuse('allocation-lower');
|
|
17
19
|
const layerId = relationshipId(current.layer);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PayloadRequest } from 'payload';
|
|
2
2
|
import type { DocId } from '../types/contracts.js';
|
|
3
3
|
import type { ArchiveBody } from '../types/endpoints.js';
|
|
4
|
-
export declare function archive(req: PayloadRequest, { experimentId, mode, confirmation }: ArchiveBody & {
|
|
4
|
+
export declare function archive(req: PayloadRequest, { experimentId, mode, confirmation, phase: expectedPhase }: ArchiveBody & {
|
|
5
5
|
experimentId: DocId;
|
|
6
6
|
}): Promise<{
|
|
7
7
|
doc: import("payload").JsonObject & import("payload").TypeWithID;
|
|
@@ -2,15 +2,16 @@ import { contentDone } from '../contentDone.js';
|
|
|
2
2
|
import { relationshipId } from './checkStart.js';
|
|
3
3
|
import { expectedConfirm, matchesConfirm, storedWinnerLabel } from './confirmPhrases.js';
|
|
4
4
|
import { withTransition } from './kernel.js';
|
|
5
|
-
import { setPhaseEndedAt } from './phaseRecord.js';
|
|
5
|
+
import { requireCurrentRound, setPhaseEndedAt } from './phaseRecord.js';
|
|
6
6
|
import { readExperiment, refuse, updateExperiment } from './start.js';
|
|
7
|
-
export async function archive(req, { experimentId, mode, confirmation }) {
|
|
7
|
+
export async function archive(req, { experimentId, mode, confirmation, phase: expectedPhase }) {
|
|
8
8
|
const before = await readExperiment(req, experimentId);
|
|
9
9
|
const { result: doc, revision } = await withTransition(req, {
|
|
10
10
|
experimentId,
|
|
11
11
|
layerId: relationshipId(before.layer)
|
|
12
12
|
}, async ({ req })=>{
|
|
13
13
|
const current = await readExperiment(req, experimentId);
|
|
14
|
+
requireCurrentRound(expectedPhase, current.phase);
|
|
14
15
|
const decision = current.decision;
|
|
15
16
|
if (mode === 'stopped' ? current.status !== 'stopped' : current.status !== 'decided') refuse('invalid-status');
|
|
16
17
|
if (mode === 'hard-coded' && current.kind !== 'code') refuse('invalid-status');
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { placementLanguageSuffix } from '../testSurface/copy/languages.js';
|
|
2
2
|
import { asymmetricGoal } from '../goals/fairness.js';
|
|
3
|
+
import { withSlotsFor } from '../arms/model.js';
|
|
3
4
|
import { checkArms } from '../collections/experiments/armInvariants.js';
|
|
4
5
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
5
6
|
import { isOpValid } from '../targeting/ops.js';
|
|
@@ -31,7 +32,7 @@ const placementDetail = ({ collection, id, title, locales, allLocales, locale, l
|
|
|
31
32
|
})}`
|
|
32
33
|
});
|
|
33
34
|
/** Group only the languages with this finding, independently for each page and
|
|
34
|
-
* finding payload. Single-language occurrence details keep their original shape. */ function placementDetails(findings, all, input, findingKey = (detail)=>JSON.stringify(detail)) {
|
|
35
|
+
* finding payload. Single-language occurrence details keep their original shape. */ function placementDetails(findings, all, input, { findingKey = (detail)=>JSON.stringify(detail), includeLocaleCodes = false } = {}) {
|
|
35
36
|
const groups = new Map();
|
|
36
37
|
const ordered = [];
|
|
37
38
|
for (const { placement, detail } of findings){
|
|
@@ -92,6 +93,11 @@ const placementDetail = ({ collection, id, title, locales, allLocales, locale, l
|
|
|
92
93
|
} : {
|
|
93
94
|
locales: names
|
|
94
95
|
},
|
|
96
|
+
...includeLocaleCodes ? {
|
|
97
|
+
localeCodes: [
|
|
98
|
+
...languages.keys()
|
|
99
|
+
]
|
|
100
|
+
} : {},
|
|
95
101
|
...detail
|
|
96
102
|
};
|
|
97
103
|
});
|
|
@@ -126,7 +132,7 @@ function invalidParams(arms, point) {
|
|
|
126
132
|
} : {}
|
|
127
133
|
});
|
|
128
134
|
add('invalid-status', e.status === 'draft' || e.status === 'stopped');
|
|
129
|
-
const issues = checkArms(e.arms, e.kind);
|
|
135
|
+
const issues = checkArms(e.kind === 'block' && Array.isArray(e.arms) ? withSlotsFor(e.arms, 'block') : e.arms, e.kind);
|
|
130
136
|
for (const code of ARM_CHECK_ORDER){
|
|
131
137
|
const matches = issues.filter((issue)=>issue.code === code);
|
|
132
138
|
add(code, matches.length === 0, matches);
|
|
@@ -217,7 +223,7 @@ function invalidParams(arms, point) {
|
|
|
217
223
|
placement,
|
|
218
224
|
detail: {}
|
|
219
225
|
})), placements, input));
|
|
220
|
-
const identical = placements.filter((p)=>p.published).flatMap((placement)=>(placement.identicalSlots ?? []).filter((slot)=>e.arms.some((arm)=>arm.
|
|
226
|
+
const identical = placements.filter((p)=>p.published).flatMap((placement)=>(placement.identicalSlots ?? []).filter((slot)=>e.arms.some((arm)=>arm.key === slot && arm.kind !== 'holdout')).map((arm)=>({
|
|
221
227
|
placement,
|
|
222
228
|
detail: {
|
|
223
229
|
arm
|
|
@@ -235,13 +241,18 @@ function invalidParams(arms, point) {
|
|
|
235
241
|
}
|
|
236
242
|
});
|
|
237
243
|
}
|
|
238
|
-
const
|
|
244
|
+
const missingVersions = (slots)=>e.arms.filter((arm)=>arm.kind !== 'holdout' && arm.key !== 'holdout' && !(slots[arm.key] > 0)).map((arm)=>arm.key);
|
|
245
|
+
const empty = placements.filter((placement)=>placement.published && missingVersions(placement.slots).length > 0);
|
|
239
246
|
add('empty-slot', e.kind !== 'block' || empty.length === 0, placementDetails(empty.map((placement)=>({
|
|
240
247
|
placement,
|
|
241
248
|
detail: {
|
|
242
|
-
slots: placement.slots
|
|
249
|
+
slots: placement.slots,
|
|
250
|
+
missing: missingVersions(placement.slots)
|
|
243
251
|
}
|
|
244
|
-
})), placements, input,
|
|
252
|
+
})), placements, input, {
|
|
253
|
+
findingKey: (detail)=>JSON.stringify(detail.missing),
|
|
254
|
+
includeLocaleCodes: true
|
|
255
|
+
}));
|
|
245
256
|
add('make-content-unsupported', true);
|
|
246
257
|
const localized = placements.find((placement)=>placement.localized);
|
|
247
258
|
if (localized) Object.assign(checks[checks.length - 1], {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PayloadRequest } from 'payload';
|
|
2
2
|
import type { DocId } from '../types/contracts.js';
|
|
3
3
|
import type { DecideBody } from '../types/endpoints.js';
|
|
4
|
-
export declare function decide(req: PayloadRequest, { experimentId, winnerArm, note, confirmation }: DecideBody & {
|
|
4
|
+
export declare function decide(req: PayloadRequest, { experimentId, winnerArm, note, confirmation, phase: expectedPhase }: DecideBody & {
|
|
5
5
|
experimentId: DocId;
|
|
6
6
|
}): Promise<{
|
|
7
7
|
doc: import("payload").JsonObject & import("payload").TypeWithID;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withSlotsFor } from '../arms/model.js';
|
|
1
2
|
import { detached, scanPlacements, lockAndRescanPlacements, placementInteractions } from './placementInteractions.js';
|
|
2
3
|
import { DEFAULT_SEQUENTIAL_TUNING_PARAMETER } from '../constants.js';
|
|
3
4
|
import { refreshPlacementDocs } from '../db/placements.js';
|
|
@@ -9,9 +10,9 @@ import { routedPageTests } from '../db/pageOccupancy.js';
|
|
|
9
10
|
import { pageTargetPaths, relationshipId } from './checkStart.js';
|
|
10
11
|
import { expectedConfirm, matchesConfirm, storedWinnerLabel } from './confirmPhrases.js';
|
|
11
12
|
import { withTransition } from './kernel.js';
|
|
12
|
-
import { readPhaseRecord, setPhaseEndedAt, writePhaseRecord } from './phaseRecord.js';
|
|
13
|
+
import { requireCurrentRound, readPhaseRecord, setPhaseEndedAt, writePhaseRecord } from './phaseRecord.js';
|
|
13
14
|
import { readExperiment, refuse, updateExperiment } from './start.js';
|
|
14
|
-
export async function decide(req, { experimentId, winnerArm, note, confirmation }) {
|
|
15
|
+
export async function decide(req, { experimentId, winnerArm, note, confirmation, phase: expectedPhase }) {
|
|
15
16
|
const before = await readExperiment(req, experimentId);
|
|
16
17
|
const options = req.payload.config.custom?.xp;
|
|
17
18
|
const placements = before.status === 'stopped' && before.kind === 'block' ? await detached(req, ()=>scanPlacements(req, options, before.slug)) : [];
|
|
@@ -21,6 +22,7 @@ export async function decide(req, { experimentId, winnerArm, note, confirmation
|
|
|
21
22
|
flagPointId: before.kind === 'flag' ? before.flagPoint : undefined
|
|
22
23
|
}, async ({ req, exec })=>{
|
|
23
24
|
const current = await readExperiment(req, experimentId);
|
|
25
|
+
requireCurrentRound(expectedPhase, current.phase);
|
|
24
26
|
if (current.status !== 'running' && current.status !== 'stopped') refuse('invalid-status');
|
|
25
27
|
if (current.kind === 'flag' && current.flagPoint) {
|
|
26
28
|
// §7.8: recheck point occupancy under its lock before restoring live routing.
|
|
@@ -148,7 +150,7 @@ export async function decide(req, { experimentId, winnerArm, note, confirmation
|
|
|
148
150
|
phaseKind: 'rollout',
|
|
149
151
|
startedAt: at,
|
|
150
152
|
seed: test.seed,
|
|
151
|
-
arms,
|
|
153
|
+
arms: current.kind === 'block' ? withSlotsFor(arms, 'block') : arms,
|
|
152
154
|
allocation: test.allocation,
|
|
153
155
|
allocationChanges: [],
|
|
154
156
|
targeting: test.targeting,
|
|
@@ -3,5 +3,5 @@ import type { DocId } from '../types/contracts.js';
|
|
|
3
3
|
/** Lock the entire bulk scope before any per-document hook can take state. */
|
|
4
4
|
export declare function prepareBulkDelete(req: PayloadRequest, where: Where): Promise<void>;
|
|
5
5
|
/** Payload deleteByID owns the request transaction; never commit inside hooks. */
|
|
6
|
-
export declare function deleteExperiment(req: PayloadRequest,
|
|
7
|
-
export declare function deleteExperimentAfter(req: PayloadRequest
|
|
6
|
+
export declare function deleteExperiment(req: PayloadRequest, requestedId: DocId): Promise<void>;
|
|
7
|
+
export declare function deleteExperimentAfter(req: PayloadRequest): Promise<void>;
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { safeError } from '../log.js';
|
|
2
2
|
import { retireSlug } from '../db/slugs.js';
|
|
3
3
|
import { txExecutor } from '../db/executor.js';
|
|
4
|
+
import { assertReadCommitted } from '../db/adapter.js';
|
|
4
5
|
import { deleteExperimentSnapshots, serializeDelete } from '../db/delete.js';
|
|
5
6
|
import { deleteExperimentEvents } from '../db/events.js';
|
|
6
7
|
import { lockTransitionScope, sortLockKeys } from '../db/locks.js';
|
|
8
|
+
import { experimentId as canonicalExperimentId } from '../endpoints/routeId.js';
|
|
9
|
+
import { XpRefusal } from '../errors.js';
|
|
7
10
|
import { buildAndStoreManifest } from '../manifest/compile.js';
|
|
8
|
-
import {
|
|
11
|
+
import { API_MESSAGES } from '../testSurface/copy/common.js';
|
|
12
|
+
import { readExperiment } from './start.js';
|
|
9
13
|
/** Lock the entire bulk scope before any per-document hook can take state. */ export async function prepareBulkDelete(req, where) {
|
|
10
14
|
await serializeDelete(req, async ()=>{
|
|
15
|
+
const exec = txExecutor(req);
|
|
16
|
+
await assertReadCommitted(req);
|
|
11
17
|
// §7.8 transition exception: hook read only discovers the lock set; delete still checks access.
|
|
12
18
|
const { docs } = await req.payload.find({
|
|
13
19
|
collection: 'xp-experiments',
|
|
@@ -22,20 +28,25 @@ import { readExperiment, refuse } from './start.js';
|
|
|
22
28
|
where
|
|
23
29
|
});
|
|
24
30
|
for (const experimentId of sortLockKeys(docs.map((doc)=>String(doc.id)))){
|
|
25
|
-
await lockTransitionScope(
|
|
31
|
+
await lockTransitionScope(exec, {
|
|
26
32
|
experimentId
|
|
27
33
|
});
|
|
28
34
|
}
|
|
29
35
|
});
|
|
30
36
|
}
|
|
31
|
-
/** Payload deleteByID owns the request transaction; never commit inside hooks. */ export async function deleteExperiment(req,
|
|
37
|
+
/** Payload deleteByID owns the request transaction; never commit inside hooks. */ export async function deleteExperiment(req, requestedId) {
|
|
32
38
|
await serializeDelete(req, async (state)=>{
|
|
33
39
|
const exec = txExecutor(req);
|
|
40
|
+
await assertReadCommitted(req);
|
|
41
|
+
const experimentId = canonicalExperimentId(req, requestedId, 'payload');
|
|
42
|
+
if (experimentId === undefined) throw new XpRefusal('not-found', 'Experiment not found', undefined, 404);
|
|
34
43
|
await lockTransitionScope(exec, {
|
|
35
44
|
experimentId
|
|
36
45
|
});
|
|
37
46
|
const current = await readExperiment(req, experimentId);
|
|
38
|
-
if (current.status !== 'draft' && current.status !== 'archived')
|
|
47
|
+
if (current.status !== 'draft' && current.status !== 'archived') {
|
|
48
|
+
throw new XpRefusal('invalid-status', API_MESSAGES.deleteInvalidStatus, undefined, 409);
|
|
49
|
+
}
|
|
39
50
|
try {
|
|
40
51
|
const collection = 'xp-phases';
|
|
41
52
|
// §7.8 transition exception: cascade while FK references still exist.
|
|
@@ -76,14 +87,13 @@ import { readExperiment, refuse } from './start.js';
|
|
|
76
87
|
}
|
|
77
88
|
});
|
|
78
89
|
}
|
|
79
|
-
export async function deleteExperimentAfter(req
|
|
90
|
+
export async function deleteExperimentAfter(req) {
|
|
80
91
|
await serializeDelete(req, async (state)=>{
|
|
81
92
|
for (const slug of state.retiredSlugs)await retireSlug(txExecutor(req), slug);
|
|
82
93
|
state.retiredSlugs.clear();
|
|
83
94
|
await buildAndStoreManifest(req, {
|
|
84
95
|
excludeIds: [
|
|
85
|
-
...state.excludedIds.values()
|
|
86
|
-
experimentId
|
|
96
|
+
...state.excludedIds.values()
|
|
87
97
|
],
|
|
88
98
|
pruneFlagDefaultIds: [
|
|
89
99
|
...state.pruneFlagDefaultIds.values()
|
|
@@ -9,6 +9,10 @@ export interface TransitionScope {
|
|
|
9
9
|
bump?: boolean;
|
|
10
10
|
/** Best-effort content audit only; a borrowed transaction must never be killed here. */
|
|
11
11
|
audit?: boolean;
|
|
12
|
+
/** Trusted server-side Start must commit its own transaction. Preflight passes the request to host callbacks. */
|
|
13
|
+
requireOwnedTransaction?: boolean;
|
|
14
|
+
/** Guard an ordinary access-checked edit without bypassing the collection's lock hook. */
|
|
15
|
+
edit?: boolean;
|
|
12
16
|
excludeIds?: DocId[];
|
|
13
17
|
}
|
|
14
18
|
/** Runs transition writes on the request's transaction under ordered locks.
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { commitTransaction,
|
|
1
|
+
import { commitTransaction, killTransaction } from 'payload';
|
|
2
|
+
import { assertReadCommitted, initTransitionTransaction } from '../db/adapter.js';
|
|
2
3
|
import { pooledExecutor, txExecutor } from '../db/executor.js';
|
|
3
4
|
import { lockTransitionScope } from '../db/locks.js';
|
|
4
5
|
import { currentTxid, txidStatus } from '../db/txid.js';
|
|
5
6
|
import { contentChangeSavepoint } from '../db/appends.js';
|
|
6
7
|
import { isPageBusy } from '../db/pageBusy.js';
|
|
7
|
-
import { XpRefusal } from '../errors.js';
|
|
8
|
+
import { XpRefusal, XpStartTransactionOpen } from '../errors.js';
|
|
8
9
|
import { buildAndStoreManifest } from '../manifest/compile.js';
|
|
9
10
|
/** Runs transition writes on the request's transaction under ordered locks.
|
|
10
11
|
* Returns the callback result and, unless bump is false, the stored manifest's
|
|
@@ -17,15 +18,19 @@ import { buildAndStoreManifest } from '../manifest/compile.js';
|
|
|
17
18
|
* itself fails: the host must observe its own failed commit. Other failures kill
|
|
18
19
|
* even a borrowed transaction. Owned audits follow the ordinary owned path.
|
|
19
20
|
*/ export async function withTransition(req, scope, fn) {
|
|
21
|
+
if (scope.requireOwnedTransaction && req.transactionID != null) {
|
|
22
|
+
throw new XpStartTransactionOpen();
|
|
23
|
+
}
|
|
20
24
|
const hadTransition = Object.prototype.hasOwnProperty.call(req.context, 'xpTransition');
|
|
21
25
|
const previousTransition = req.context.xpTransition;
|
|
22
26
|
let borrowedAudit = scope.audit === true && req.transactionID != null;
|
|
23
27
|
try {
|
|
24
|
-
const owns = await
|
|
28
|
+
const owns = await initTransitionTransaction(req);
|
|
25
29
|
borrowedAudit = scope.audit === true && !owns;
|
|
26
30
|
const exec = txExecutor(req);
|
|
27
|
-
req.context.xpTransition = true;
|
|
28
31
|
const work = async ()=>{
|
|
32
|
+
if (!owns) await assertReadCommitted(req);
|
|
33
|
+
if (!scope.edit) req.context.xpTransition = true;
|
|
29
34
|
await lockTransitionScope(exec, scope);
|
|
30
35
|
return fn({
|
|
31
36
|
exec,
|