@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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RoundBody } from '../types/endpoints.js';
|
|
1
2
|
import { type PayloadRequest } from 'payload';
|
|
2
3
|
import type { ContentReportReason } from '../types/reasons.js';
|
|
3
4
|
import type { DocId, ResolvedOptions } from '../types/contracts.js';
|
|
@@ -17,7 +18,7 @@ type ContentDoc = {
|
|
|
17
18
|
export declare function hostTransaction(req: PayloadRequest, experimentId: DocId, fn: () => Promise<void>): Promise<void>;
|
|
18
19
|
export declare function makeContent<TUser extends {
|
|
19
20
|
id: DocId;
|
|
20
|
-
}>(req: PayloadRequest, { experimentId, options }: {
|
|
21
|
+
}>(req: PayloadRequest, { experimentId, options, phase: expectedPhase }: RoundBody & {
|
|
21
22
|
experimentId: DocId;
|
|
22
23
|
options: ResolvedOptions<TUser>;
|
|
23
24
|
}): Promise<{
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { requireCurrentRound } from './phaseRecord.js';
|
|
1
2
|
import { placementReader } from '../blocks/placementLocale.js';
|
|
2
3
|
import { puckExperimentSlug } from '../puck/experimentSlug.js';
|
|
3
4
|
import { puckVisibility, hiddenOnSizes, visibilitySizes } from '../puck/visibility.js';
|
|
4
|
-
import { Forbidden, NotFound, ValidationError, Locked, commitTransaction,
|
|
5
|
+
import { Forbidden, NotFound, ValidationError, Locked, commitTransaction, killTransaction } from 'payload';
|
|
6
|
+
import { initTransitionTransaction } from '../db/adapter.js';
|
|
5
7
|
import { latestDraftContent, publishedContent as readPublishedContent } from '../db/publishedContent.js';
|
|
6
8
|
import { EXPERIMENT_BLOCK_SLUG, hostBlocks, slotBlocks } from '../blocks/model.js';
|
|
7
9
|
import { findRegisteredBlocksField, freshBlockIds } from '../blocks/formState.js';
|
|
@@ -195,7 +197,7 @@ async function fieldRefusal(fields, req, doc, operation = 'update', data = doc,
|
|
|
195
197
|
delete req.transactionID;
|
|
196
198
|
delete req.context.xpTransition;
|
|
197
199
|
try {
|
|
198
|
-
if (!await
|
|
200
|
+
if (!await initTransitionTransaction(req)) throw new Error('A content transaction could not be started.');
|
|
199
201
|
await fn();
|
|
200
202
|
const xid = await currentTxid(txExecutor(req));
|
|
201
203
|
await commitTransaction(req);
|
|
@@ -211,7 +213,7 @@ async function fieldRefusal(fields, req, doc, operation = 'update', data = doc,
|
|
|
211
213
|
else req.context.xpTransition = transition;
|
|
212
214
|
}
|
|
213
215
|
}
|
|
214
|
-
export async function makeContent(req, { experimentId, options }) {
|
|
216
|
+
export async function makeContent(req, { experimentId, options, phase: expectedPhase }) {
|
|
215
217
|
const before = await readExperiment(req, experimentId);
|
|
216
218
|
const { result } = await withTransition(req, {
|
|
217
219
|
experimentId,
|
|
@@ -220,6 +222,7 @@ export async function makeContent(req, { experimentId, options }) {
|
|
|
220
222
|
bump: false
|
|
221
223
|
}, async ({ exec })=>{
|
|
222
224
|
const current = await readExperiment(req, experimentId);
|
|
225
|
+
requireCurrentRound(expectedPhase, current.phase);
|
|
223
226
|
if (current.status !== 'decided' || ![
|
|
224
227
|
'block',
|
|
225
228
|
'flag',
|
|
@@ -255,7 +258,7 @@ export async function makeContent(req, { experimentId, options }) {
|
|
|
255
258
|
// Roll back any remaining writes, then check the row while still
|
|
256
259
|
// detached from the outer transition and its privileged context.
|
|
257
260
|
await killTransaction(req);
|
|
258
|
-
if (!await
|
|
261
|
+
if (!await initTransitionTransaction(req)) throw new Error('A content transaction could not be started.');
|
|
259
262
|
missing = !await readPublishedContent(req, collection, id);
|
|
260
263
|
}
|
|
261
264
|
throw error;
|
|
@@ -292,7 +295,8 @@ export async function makeContent(req, { experimentId, options }) {
|
|
|
292
295
|
}
|
|
293
296
|
};
|
|
294
297
|
if (current.kind === 'block') {
|
|
295
|
-
if (
|
|
298
|
+
if (winner.key === 'holdout') refuse('invalid-winner');
|
|
299
|
+
const winnerSlot = winner.key;
|
|
296
300
|
const registrations = [
|
|
297
301
|
...puckCollections(options),
|
|
298
302
|
...options.blocks?.collections ?? []
|
|
@@ -423,13 +427,13 @@ export async function makeContent(req, { experimentId, options }) {
|
|
|
423
427
|
block
|
|
424
428
|
];
|
|
425
429
|
const rows = Array.isArray(block.slots) ? block.slots : [];
|
|
426
|
-
if (!rows.some((row)=>row?.slot ===
|
|
430
|
+
if (!rows.some((row)=>row?.slot === winnerSlot)) throw new Error('The winning content slot is missing.');
|
|
427
431
|
const registered = findRegisteredBlocksField(config?.fields ?? [], field);
|
|
428
432
|
if (!registered) throw new Error('This content field is no longer configured.');
|
|
429
433
|
return slotBlocks(freshBlockIds([
|
|
430
434
|
block
|
|
431
|
-
], registered.field, req.payload.config)[0],
|
|
432
|
-
}) : unwrap(value, current.slug,
|
|
435
|
+
], registered.field, req.payload.config)[0], winnerSlot);
|
|
436
|
+
}) : unwrap(value, current.slug, winnerSlot);
|
|
433
437
|
const draft = drafts ? await latestDraftContent(req, collection, id) ?? published : published;
|
|
434
438
|
const draftValue = draft[field] ?? null;
|
|
435
439
|
const draftContent = transform(draftValue);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PayloadRequest } from 'payload';
|
|
2
2
|
import type { BlockPlacement } from './placements.js';
|
|
3
|
-
/** Read
|
|
4
|
-
export declare function nestedPlacementNames(req: PayloadRequest, placements: readonly BlockPlacement[]): Promise<Map<string, string>>;
|
|
3
|
+
/** Read names for preflight and Start's locked rescan. */
|
|
4
|
+
export declare function nestedPlacementNames(req: PayloadRequest, placements: readonly BlockPlacement[], system?: boolean): Promise<Map<string, string>>;
|
|
5
5
|
export declare const nameNestedPlacements: (placements: readonly BlockPlacement[], names: ReadonlyMap<string, string>) => BlockPlacement[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { findStartDocuments } from './startReads.js';
|
|
2
|
+
/** Read names for preflight and Start's locked rescan. */ export async function nestedPlacementNames(req, placements, system = false) {
|
|
2
3
|
const slugs = [
|
|
3
4
|
...new Set(placements.flatMap((p)=>(p.nestedTests ?? []).flatMap((pair)=>[
|
|
4
5
|
pair.outer,
|
|
@@ -6,10 +7,8 @@
|
|
|
6
7
|
])))
|
|
7
8
|
];
|
|
8
9
|
if (!slugs.length) return new Map();
|
|
9
|
-
const found = await req
|
|
10
|
+
const found = await findStartDocuments(req, {
|
|
10
11
|
collection: 'xp-experiments',
|
|
11
|
-
req,
|
|
12
|
-
overrideAccess: false,
|
|
13
12
|
depth: 0,
|
|
14
13
|
pagination: false,
|
|
15
14
|
where: {
|
|
@@ -17,7 +16,7 @@
|
|
|
17
16
|
in: slugs
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
|
-
});
|
|
19
|
+
}, system);
|
|
21
20
|
return new Map(found.docs.map((doc)=>[
|
|
22
21
|
String(doc.slug),
|
|
23
22
|
String(doc.name)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
import type { ExperimentsPageCollection } from '../types/contracts.js';
|
|
3
|
+
export declare const PAGE_ADDRESS_FIELDS: string[];
|
|
4
|
+
/** Hosts can resolve drafts in findByPath. For simple addresses, the admin also
|
|
5
|
+
* recognizes never-published drafts when a host lookup only sees live pages. */
|
|
6
|
+
export declare function findDraftPageByPath(req: PayloadRequest, entry: ExperimentsPageCollection, path: string): Promise<(import("payload").JsonObject & import("payload").TypeWithID) | undefined>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { flattenTopLevelFields } from 'payload/shared';
|
|
2
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
3
|
+
import { normalisePath } from '../runtime/normalisePath.js';
|
|
4
|
+
export const PAGE_ADDRESS_FIELDS = [
|
|
5
|
+
'path',
|
|
6
|
+
'slug',
|
|
7
|
+
'pageSegment'
|
|
8
|
+
];
|
|
9
|
+
/** Hosts can resolve drafts in findByPath. For simple addresses, the admin also
|
|
10
|
+
* recognizes never-published drafts when a host lookup only sees live pages. */ export async function findDraftPageByPath(req, entry, path) {
|
|
11
|
+
const config = req.payload.collections?.[entry.slug]?.config ?? req.payload.config.collections?.find((collection)=>collection.slug === entry.slug);
|
|
12
|
+
if (!config?.versions?.drafts) return undefined;
|
|
13
|
+
const key = normalisePath(path);
|
|
14
|
+
const relative = key.replace(/^\/+/, '');
|
|
15
|
+
const segment = relative.split('/').at(-1);
|
|
16
|
+
const unprefixed = relative.slice(relative.indexOf('/') + 1);
|
|
17
|
+
const filters = flattenTopLevelFields(config.fields).flatMap((field)=>{
|
|
18
|
+
if (field.type !== 'text' || field.virtual || !PAGE_ADDRESS_FIELDS.includes(field.name)) return [];
|
|
19
|
+
const values = field.name === 'pageSegment' ? [
|
|
20
|
+
segment
|
|
21
|
+
] : [
|
|
22
|
+
relative,
|
|
23
|
+
unprefixed,
|
|
24
|
+
segment
|
|
25
|
+
];
|
|
26
|
+
const candidates = [
|
|
27
|
+
...new Set(values.flatMap((value)=>value ? [
|
|
28
|
+
value,
|
|
29
|
+
'/' + value,
|
|
30
|
+
value + '/',
|
|
31
|
+
'/' + value + '/'
|
|
32
|
+
] : []))
|
|
33
|
+
];
|
|
34
|
+
return candidates.length ? [
|
|
35
|
+
{
|
|
36
|
+
[field.name]: {
|
|
37
|
+
in: candidates
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
] : [];
|
|
41
|
+
});
|
|
42
|
+
if (!filters.length) return undefined;
|
|
43
|
+
const result = await req.payload.find({
|
|
44
|
+
collection: entry.slug,
|
|
45
|
+
req,
|
|
46
|
+
overrideAccess: false,
|
|
47
|
+
depth: 0,
|
|
48
|
+
draft: false,
|
|
49
|
+
pagination: false,
|
|
50
|
+
limit: 20,
|
|
51
|
+
where: {
|
|
52
|
+
and: [
|
|
53
|
+
{
|
|
54
|
+
_status: {
|
|
55
|
+
equals: 'draft'
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
or: filters
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const reader = placementReader(req, entry.slug);
|
|
65
|
+
const input = req.locale === 'all' ? 'all-locales' : 'localized';
|
|
66
|
+
const candidates = result.docs.filter((row)=>{
|
|
67
|
+
const address = entry.pathOf(reader.read(row, input).doc);
|
|
68
|
+
return address !== null && normalisePath(address) === key;
|
|
69
|
+
});
|
|
70
|
+
return candidates.length === 1 ? candidates[0] : undefined;
|
|
71
|
+
}
|
|
@@ -3,7 +3,7 @@ import type { Arm, ExperimentsPageCollection } from '../types/contracts.js';
|
|
|
3
3
|
/** Page copies have fresh nested row ids and editor labels; neither is rendered content. */
|
|
4
4
|
export declare function comparableContent(value: unknown): unknown;
|
|
5
5
|
export declare function identicalPageVersions(req: PayloadRequest, collection: ExperimentsPageCollection | undefined, arms: Arm[]): Promise<{
|
|
6
|
-
arm: import("../types/
|
|
6
|
+
arm: import("../types/armKey.js").ArmKey;
|
|
7
7
|
path: string;
|
|
8
8
|
collection: string;
|
|
9
9
|
id: string | number;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { PayloadRequest } from 'payload';
|
|
2
2
|
import type { Arm, DocId, TargetingRule } from '../types/contracts.js';
|
|
3
3
|
import type { AllocationChange, ContentChange } from '../db/appends.js';
|
|
4
|
+
/** Check the round after acquiring the experiment lock and before writing. */
|
|
5
|
+
export declare function requireCurrentRound(expected: number | undefined, current: number | undefined): void;
|
|
4
6
|
export interface PhaseRecord {
|
|
5
7
|
experiment: DocId;
|
|
6
8
|
phase: number;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { XpRefusal } from '../errors.js';
|
|
2
|
+
/** Check the round after acquiring the experiment lock and before writing. */ export function requireCurrentRound(expected, current) {
|
|
3
|
+
if (expected !== undefined && expected !== current) {
|
|
4
|
+
throw new XpRefusal('round-changed', 'This test is on a different round. Review the current round and try again.', undefined, 409);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
2
7
|
export async function readPhaseRecord(req, experimentId, phase) {
|
|
3
8
|
// §7.8: frozen configuration lookup serves an authorised transition.
|
|
4
9
|
const { docs } = await req.payload.find({
|
|
@@ -7,7 +7,7 @@ export declare function detached<T>(req: PayloadRequest, fn: () => Promise<T>):
|
|
|
7
7
|
export declare function uniquePlacementDocs(placements: readonly Pick<BlockPlacement, 'collection' | 'id'>[]): PlacementDoc[];
|
|
8
8
|
export declare function scanPlacements<TUser extends {
|
|
9
9
|
id: DocId;
|
|
10
|
-
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, slug: string): Promise<BlockPlacement[]>;
|
|
10
|
+
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, slug: string, system?: boolean): Promise<BlockPlacement[]>;
|
|
11
11
|
export declare function placementPaths<TUser extends {
|
|
12
12
|
id: DocId;
|
|
13
13
|
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, docs: readonly PlacementDoc[]): Promise<string[]>;
|
|
@@ -26,7 +26,7 @@ export declare function placementInteractions<TUser extends {
|
|
|
26
26
|
kind: string;
|
|
27
27
|
arms: Arm[];
|
|
28
28
|
pageCollection?: string | null;
|
|
29
|
-
}, paths: string[]): Promise<InteractionDetail[]>;
|
|
29
|
+
}, paths: string[], system?: boolean): Promise<InteractionDetail[]>;
|
|
30
30
|
export declare function lockAndRescanPlacements<TUser extends {
|
|
31
31
|
id: DocId;
|
|
32
32
|
}>(req: PayloadRequest, exec: Executor, options: ResolvedOptions<TUser>, experiment: {
|
|
@@ -34,7 +34,7 @@ export declare function lockAndRescanPlacements<TUser extends {
|
|
|
34
34
|
slug: string;
|
|
35
35
|
kind: string;
|
|
36
36
|
arms: Arm[];
|
|
37
|
-
}, before: readonly BlockPlacement[]): Promise<{
|
|
37
|
+
}, before: readonly BlockPlacement[], system?: boolean): Promise<{
|
|
38
38
|
placements: BlockPlacement[];
|
|
39
39
|
docs: PlacementDoc[];
|
|
40
40
|
}>;
|
|
@@ -30,11 +30,12 @@ export function uniquePlacementDocs(placements) {
|
|
|
30
30
|
])).values()
|
|
31
31
|
];
|
|
32
32
|
}
|
|
33
|
-
export function scanPlacements(req, options, slug) {
|
|
33
|
+
export function scanPlacements(req, options, slug, system = false) {
|
|
34
34
|
return scanBlockPlacements(req, {
|
|
35
35
|
slug,
|
|
36
36
|
puckCollections: options.puck?.collections ?? [],
|
|
37
|
-
blocksCollections: options.blocks?.collections ?? []
|
|
37
|
+
blocksCollections: options.blocks?.collections ?? [],
|
|
38
|
+
system
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
41
|
export async function placementPaths(req, options, docs) {
|
|
@@ -53,7 +54,7 @@ export async function placementPaths(req, options, docs) {
|
|
|
53
54
|
]);
|
|
54
55
|
}
|
|
55
56
|
const active = (test)=>test.status === 'running' || test.status === 'decided';
|
|
56
|
-
export async function placementInteractions(req, exec, options, experiment, paths) {
|
|
57
|
+
export async function placementInteractions(req, exec, options, experiment, paths, system = false) {
|
|
57
58
|
const result = [];
|
|
58
59
|
for (const test of (await placementTests(exec))){
|
|
59
60
|
if (!active(test) || String(test.id) === String(experiment.id)) continue;
|
|
@@ -67,7 +68,7 @@ export async function placementInteractions(req, exec, options, experiment, path
|
|
|
67
68
|
version: test.arms.some((a)=>a.kind === 'variant' && a.pageTarget && normalisePath(a.pageTarget) === path)
|
|
68
69
|
});
|
|
69
70
|
} else if (experiment.kind === 'page' && test.kind === 'block') {
|
|
70
|
-
const docs = test.placementDocs ?? uniquePlacementDocs(await detached(req, ()=>scanPlacements(req, options, test.slug)));
|
|
71
|
+
const docs = test.placementDocs ?? uniquePlacementDocs(await detached(req, ()=>scanPlacements(req, options, test.slug, system)));
|
|
71
72
|
const relevant = docs.filter((doc)=>!experiment.pageCollection || doc.collection === experiment.pageCollection);
|
|
72
73
|
for (const path of (await placementPaths(req, options, relevant)).filter((path)=>paths.includes(path)))result.push({
|
|
73
74
|
experimentId: test.id,
|
|
@@ -81,14 +82,14 @@ export async function placementInteractions(req, exec, options, experiment, path
|
|
|
81
82
|
}
|
|
82
83
|
return result;
|
|
83
84
|
}
|
|
84
|
-
export async function lockAndRescanPlacements(req, exec, options, experiment, before) {
|
|
85
|
+
export async function lockAndRescanPlacements(req, exec, options, experiment, before, system = false) {
|
|
85
86
|
const paths = await placementPaths(req, options, uniquePlacementDocs(before));
|
|
86
87
|
await lockPagePaths(exec, paths);
|
|
87
|
-
const placements = await detached(req, ()=>scanPlacements(req, options, experiment.slug));
|
|
88
|
+
const placements = await detached(req, ()=>scanPlacements(req, options, experiment.slug, system));
|
|
88
89
|
const docs = uniquePlacementDocs(placements);
|
|
89
90
|
const afterPaths = await placementPaths(req, options, docs);
|
|
90
91
|
if (afterPaths.some((path)=>!paths.includes(path))) throw new XpRefusal('placements-changed', "This test's pages changed while it was starting. Try again.", undefined, 409);
|
|
91
|
-
const conflicts = await placementInteractions(req, exec, options, experiment, paths);
|
|
92
|
+
const conflicts = await placementInteractions(req, exec, options, experiment, paths, system);
|
|
92
93
|
if (conflicts.length) throw new XpRefusal('interacting-tests', interactingTestsCopy(conflicts[0].path, conflicts[0].status, conflicts[0].name, conflicts[0].version), conflicts, 409);
|
|
93
94
|
return {
|
|
94
95
|
placements,
|
|
@@ -39,6 +39,8 @@ interface ScanOptions {
|
|
|
39
39
|
publishedOnly?: boolean;
|
|
40
40
|
/** Hooks and manager-authorized visitor-impact reads must see every placement (CORE-21). */
|
|
41
41
|
pageGuard?: true;
|
|
42
|
+
/** Trusted server-side Start checks placements without a manager actor. */
|
|
43
|
+
system?: boolean;
|
|
42
44
|
change?: PlacementChange;
|
|
43
45
|
}
|
|
44
46
|
/** Published rows only, one pass per collection across both editor registrations.
|
|
@@ -16,9 +16,9 @@ const slots = [
|
|
|
16
16
|
'variantB',
|
|
17
17
|
'variantC'
|
|
18
18
|
];
|
|
19
|
-
async function placementDocuments(req, query,
|
|
20
|
-
// §7.8 page
|
|
21
|
-
if (
|
|
19
|
+
async function placementDocuments(req, query, readAll) {
|
|
20
|
+
// §7.8: page guards, visitor impact and system Start need all placements to check the visitor surface.
|
|
21
|
+
if (readAll) return req.payload.find({
|
|
22
22
|
...query,
|
|
23
23
|
req,
|
|
24
24
|
overrideAccess: true
|
|
@@ -245,7 +245,7 @@ export async function scanBlockPlacements(req, args) {
|
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
} : {}
|
|
248
|
-
}, args.pageGuard);
|
|
248
|
+
}, args.pageGuard || args.system);
|
|
249
249
|
for (const localized of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled)))for (const view of reader.views){
|
|
250
250
|
const doc = reader.read(localized, 'all-locales', view).doc;
|
|
251
251
|
const documentKey = JSON.stringify([
|
|
@@ -382,7 +382,7 @@ export async function scanBlockPlacements(req, args) {
|
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
384
|
} : {}
|
|
385
|
-
}, args.pageGuard);
|
|
385
|
+
}, args.pageGuard || args.system);
|
|
386
386
|
for (const localized of changedDocuments(result.docs, args.change, collection, draft, page, Boolean(draftsEnabled)))for (const view of reader.views){
|
|
387
387
|
const doc = reader.read(localized, 'all-locales', view).doc;
|
|
388
388
|
const documentKey = JSON.stringify([
|
|
@@ -10,9 +10,10 @@ export interface PreflightDependencies {
|
|
|
10
10
|
/** Read-only inputs shared with Start's pre-transaction checks. Start must re-read
|
|
11
11
|
* the document and lock-sensitive facts inside its transition (CORE-10b).
|
|
12
12
|
*/
|
|
13
|
+
export declare function readStartInputExperiment(req: PayloadRequest, experimentId: DocId, system?: boolean): Promise<StartExperiment | null>;
|
|
13
14
|
export declare function loadStartInputs<TUser extends {
|
|
14
15
|
id: DocId;
|
|
15
|
-
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, experimentId: DocId): Promise<CheckStartInput | null>;
|
|
16
|
+
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, experimentId: DocId, system?: boolean): Promise<CheckStartInput | null>;
|
|
16
17
|
/** Occupancy from the arms the runtime routes on (frozen rounds), shared by preflight and
|
|
17
18
|
* Start's locked recheck. Raw SQL on the request's transaction when there is one. */
|
|
18
19
|
export declare function loadPageTestsInUse(req: PayloadRequest): Promise<NonNullable<CheckStartInput['pageTestsInUse']>>;
|
|
@@ -26,7 +27,7 @@ export declare function unpublishedPageTargets<TUser extends {
|
|
|
26
27
|
*/
|
|
27
28
|
export declare function loadStartInputsBatch<TUser extends {
|
|
28
29
|
id: DocId;
|
|
29
|
-
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, experiments: StartExperiment[], tolerateErrors?: boolean): Promise<Map<string, CheckStartInput | null>>;
|
|
30
|
+
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, experiments: StartExperiment[], tolerateErrors?: boolean, system?: boolean): Promise<Map<string, CheckStartInput | null>>;
|
|
30
31
|
export declare function preflightData<TUser extends {
|
|
31
32
|
id: DocId;
|
|
32
33
|
}>(req: PayloadRequest, { experimentId, options, placementLocale }: {
|