@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
package/dist/db/adapter.js
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
import { XpNoTransactionError } from '../errors.js';
|
|
3
|
+
import { API_MESSAGES } from '../testSurface/copy/common.js';
|
|
4
|
+
import { transactionSession, txExecutor } from './executor.js';
|
|
5
|
+
const transitionIsolation = 'read committed';
|
|
6
|
+
const isolationMessage = 'Experiments requires PostgreSQL READ COMMITTED so it can see changes committed while waiting for locks. Set the Postgres adapter\'s transactionOptions.isolationLevel to "read committed" or remove the override.';
|
|
7
|
+
const checkedSessions = new WeakMap();
|
|
8
|
+
export class XpTransactionIsolationError extends APIError {
|
|
9
|
+
constructor(){
|
|
10
|
+
super(API_MESSAGES.transactionIsolation, 500, null, true);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Payload's initTransaction cannot pass options to the adapter. Like that
|
|
14
|
+
* helper, publish the pending transaction on the request before awaiting it.
|
|
15
|
+
*/ export async function initTransitionTransaction(req) {
|
|
16
|
+
if (req.transactionID != null) {
|
|
17
|
+
await req.transactionID;
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const db = req.payload.db;
|
|
21
|
+
const pending = db.beginTransaction({
|
|
22
|
+
...db.transactionOptions || {},
|
|
23
|
+
isolationLevel: transitionIsolation
|
|
24
|
+
}).then((id)=>{
|
|
25
|
+
if (id == null) throw new XpNoTransactionError();
|
|
26
|
+
const session = db.sessions?.[id];
|
|
27
|
+
if (session) checkedSessions.set(session, Promise.resolve());
|
|
28
|
+
req.transactionID = id;
|
|
29
|
+
return id;
|
|
30
|
+
});
|
|
31
|
+
req.transactionID = pending;
|
|
32
|
+
try {
|
|
33
|
+
await pending;
|
|
34
|
+
return true;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (req.transactionID === pending) delete req.transactionID;
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** A borrowed transaction may already have taken its snapshot. Check the
|
|
41
|
+
* effective isolation on that session before relying on a post-lock read.
|
|
42
|
+
*/ async function isReadCommitted(exec) {
|
|
43
|
+
const { rows } = await exec.query('SHOW transaction_isolation');
|
|
44
|
+
const level = rows[0]?.transaction_isolation;
|
|
45
|
+
// PostgreSQL implements READ UNCOMMITTED as READ COMMITTED (docs §13.2).
|
|
46
|
+
return level === transitionIsolation || level === 'read uncommitted';
|
|
47
|
+
}
|
|
48
|
+
export async function assertReadCommitted(req) {
|
|
49
|
+
const transaction = {
|
|
50
|
+
payload: req.payload,
|
|
51
|
+
transactionID: await req.transactionID
|
|
52
|
+
};
|
|
53
|
+
// The adapter resolves the ID to a unique session object until commit or
|
|
54
|
+
// rollback. Cache the pending check so concurrent hooks share the same query.
|
|
55
|
+
const session = await transactionSession(transaction);
|
|
56
|
+
let checked = checkedSessions.get(session);
|
|
57
|
+
if (!checked) {
|
|
58
|
+
checked = isReadCommitted(txExecutor(transaction)).then((valid)=>{
|
|
59
|
+
if (!valid) {
|
|
60
|
+
try {
|
|
61
|
+
console.error('Experiments requires PostgreSQL READ COMMITTED so it can see changes committed while waiting for locks. Set the Postgres adapter\'s transactionOptions.isolationLevel to "read committed" or remove the override.');
|
|
62
|
+
} catch {}
|
|
63
|
+
throw new XpTransactionIsolationError();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
checkedSessions.set(session, checked);
|
|
67
|
+
}
|
|
68
|
+
await checked;
|
|
69
|
+
}
|
|
1
70
|
export function assertPostgresAdapter(payload) {
|
|
2
71
|
// @payloadcms/db-postgres/dist/index.js:133 declares this package marker.
|
|
3
72
|
if (payload.db.packageName !== '@payloadcms/db-postgres') throw new Error('Experiments requires @payloadcms/db-postgres');
|
|
@@ -5,5 +74,12 @@ export function assertPostgresAdapter(payload) {
|
|
|
5
74
|
export async function probeTransactions(payload) {
|
|
6
75
|
const id = await payload.db.beginTransaction();
|
|
7
76
|
if (id == null) throw new Error('Experiments transactions are disabled');
|
|
8
|
-
|
|
77
|
+
try {
|
|
78
|
+
if (!await isReadCommitted(txExecutor({
|
|
79
|
+
payload,
|
|
80
|
+
transactionID: id
|
|
81
|
+
}))) throw new Error(isolationMessage);
|
|
82
|
+
} finally{
|
|
83
|
+
await payload.db.rollbackTransaction(id);
|
|
84
|
+
}
|
|
9
85
|
}
|
package/dist/db/delete.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PayloadRequest } from 'payload';
|
|
2
2
|
import type { DocId } from '../types/contracts.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type Executor } from './executor.js';
|
|
4
4
|
interface DeleteState {
|
|
5
5
|
tail: Promise<void>;
|
|
6
6
|
retiredSlugs: Set<string>;
|
package/dist/db/delete.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { transactionSession } from './executor.js';
|
|
2
2
|
import { COLUMNS, TABLES } from './names.js';
|
|
3
3
|
import { qualifiedTable, quoteIdentifier as quote } from './sql.js';
|
|
4
4
|
// Key by the actual session: borrowed requests in one transaction share a queue,
|
|
@@ -9,9 +9,7 @@ const transactions = new WeakMap();
|
|
|
9
9
|
* Successful beforeDelete bodies retain exclusions until the transaction ends:
|
|
10
10
|
* another row can be between hooks with its children gone but its row present.
|
|
11
11
|
*/ export async function serializeDelete(req, fn) {
|
|
12
|
-
const
|
|
13
|
-
const session = id == null ? undefined : req.payload.db.sessions?.[id];
|
|
14
|
-
if (!session) throw new XpNoTransactionError();
|
|
12
|
+
const session = await transactionSession(req);
|
|
15
13
|
let state = transactions.get(session);
|
|
16
14
|
if (!state) {
|
|
17
15
|
state = {
|
package/dist/db/events.d.ts
CHANGED
|
@@ -17,5 +17,14 @@ export interface EventRow {
|
|
|
17
17
|
attributes?: Record<string, unknown>;
|
|
18
18
|
dedupeKey: string;
|
|
19
19
|
}
|
|
20
|
+
type ServerConversion = Pick<EventRow, 'unitId' | 'unitType' | 'userId' | 'ts'> & {
|
|
21
|
+
eventName: string;
|
|
22
|
+
value: number;
|
|
23
|
+
idempotencyKey: string;
|
|
24
|
+
};
|
|
25
|
+
/** A retained legacy row suppresses retries for its event name. The scoped key's
|
|
26
|
+
* unique index handles concurrent writes after the old writers have been drained. */
|
|
27
|
+
export declare function insertServerConversion(exec: Executor, event: ServerConversion, log: (message: string) => void): Promise<void>;
|
|
20
28
|
/** Pooled/autocommit executor required: an FK failure must not poison a caller's transaction. */
|
|
21
29
|
export declare function insertEvents(exec: Executor, rows: EventRow[], log?: (message: string) => void): Promise<number>;
|
|
30
|
+
export {};
|
package/dist/db/events.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { exposureDimensions } from '../events/dimensions.js';
|
|
2
3
|
import { COLUMNS, TABLES } from './names.js';
|
|
3
4
|
import { qualifiedTable, quoteIdentifier } from './sql.js';
|
|
@@ -6,7 +7,7 @@ import { qualifiedTable, quoteIdentifier } from './sql.js';
|
|
|
6
7
|
experimentId
|
|
7
8
|
]);
|
|
8
9
|
}
|
|
9
|
-
const quote =
|
|
10
|
+
const quote = quoteIdentifier;
|
|
10
11
|
const c = COLUMNS.events;
|
|
11
12
|
function foreignKeyViolation(error) {
|
|
12
13
|
const seen = new Set();
|
|
@@ -28,15 +29,48 @@ function foreignKeyViolation(error) {
|
|
|
28
29
|
return null;
|
|
29
30
|
}
|
|
30
31
|
}
|
|
32
|
+
function hasFiniteValue(value, log) {
|
|
33
|
+
if (value === undefined || Number.isFinite(value)) return true;
|
|
34
|
+
log('Experiments: dropped event with non-finite value');
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
/** A retained legacy row suppresses retries for its event name. The scoped key's
|
|
38
|
+
* unique index handles concurrent writes after the old writers have been drained. */ export async function insertServerConversion(exec, event, log) {
|
|
39
|
+
if (!hasFiniteValue(event.value, log)) return;
|
|
40
|
+
const table = qualifiedTable(exec, TABLES.events);
|
|
41
|
+
const digest = createHash('sha256').update(JSON.stringify([
|
|
42
|
+
event.eventName,
|
|
43
|
+
event.idempotencyKey
|
|
44
|
+
])).digest('hex');
|
|
45
|
+
await exec.query(`INSERT INTO ${table} (${[
|
|
46
|
+
c.type,
|
|
47
|
+
c.unitId,
|
|
48
|
+
c.unitType,
|
|
49
|
+
c.userId,
|
|
50
|
+
c.eventName,
|
|
51
|
+
c.value,
|
|
52
|
+
c.ts,
|
|
53
|
+
c.dedupeKey,
|
|
54
|
+
c.createdAt,
|
|
55
|
+
c.updatedAt
|
|
56
|
+
].map(quote).join(', ')})
|
|
57
|
+
SELECT 'conversion', $1, $2, $3, $4, $5, $6, $7, now(), now()
|
|
58
|
+
WHERE NOT EXISTS (SELECT 1 FROM ${table} WHERE ${quote(c.dedupeKey)} = $8 AND ${quote(c.eventName)} = $4)
|
|
59
|
+
ON CONFLICT (${quote(c.dedupeKey)}) DO NOTHING`, [
|
|
60
|
+
event.unitId,
|
|
61
|
+
event.unitType,
|
|
62
|
+
event.userId ?? null,
|
|
63
|
+
event.eventName,
|
|
64
|
+
event.value,
|
|
65
|
+
event.ts,
|
|
66
|
+
`conversion:s2:${digest}`,
|
|
67
|
+
`conversion:s:${event.idempotencyKey}`
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
31
70
|
/** Pooled/autocommit executor required: an FK failure must not poison a caller's transaction. */ export async function insertEvents(exec, rows, log = console.error) {
|
|
32
|
-
const valid = rows.filter((row)=>
|
|
33
|
-
if (row.value === undefined || Number.isFinite(row.value)) return true;
|
|
34
|
-
log('Experiments: dropped event with non-finite value');
|
|
35
|
-
return false;
|
|
36
|
-
});
|
|
71
|
+
const valid = rows.filter((row)=>hasFiniteValue(row.value, log));
|
|
37
72
|
if (!valid.length) return 0;
|
|
38
|
-
const
|
|
39
|
-
const table = `${schema ? `${quote(schema)}.` : ''}${quote(TABLES.events)}`;
|
|
73
|
+
const table = qualifiedTable(exec, TABLES.events);
|
|
40
74
|
async function insert(batch) {
|
|
41
75
|
const params = [];
|
|
42
76
|
const values = batch.map((row)=>{
|
package/dist/db/executor.d.ts
CHANGED
|
@@ -2,7 +2,13 @@ import type { Payload, PayloadRequest } from 'payload';
|
|
|
2
2
|
import type { Executor } from './pgExecutor.js';
|
|
3
3
|
export type { Executor } from './pgExecutor.js';
|
|
4
4
|
export { pgPoolExecutor, ownConnection, withStatementTimeout, raceDeadline, ResultsBudgetError, RESULTS_TIMEOUT_MARGIN_MS } from './pgExecutor.js';
|
|
5
|
-
|
|
5
|
+
type TransactionRequest = Pick<PayloadRequest, 'payload' | 'transactionID'>;
|
|
6
|
+
export declare function transactionSession(req: TransactionRequest): Promise<{
|
|
7
|
+
db: unknown;
|
|
8
|
+
reject: () => Promise<void>;
|
|
9
|
+
resolve: () => Promise<void>;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function txExecutor(req: TransactionRequest): Executor & {
|
|
6
12
|
schemaName?: string;
|
|
7
13
|
};
|
|
8
14
|
export declare function pooledExecutor(payload: Payload): Executor & {
|
package/dist/db/executor.js
CHANGED
|
@@ -14,14 +14,18 @@ export { pgPoolExecutor, ownConnection, withStatementTimeout, raceDeadline, Resu
|
|
|
14
14
|
chunks.push(sql.raw(text.slice(start)));
|
|
15
15
|
return sql.join(chunks, sql.raw(''));
|
|
16
16
|
}
|
|
17
|
+
export async function transactionSession(req) {
|
|
18
|
+
const id = await req.transactionID;
|
|
19
|
+
const session = id == null ? undefined : req.payload.db.sessions?.[id];
|
|
20
|
+
if (!session) throw new XpNoTransactionError();
|
|
21
|
+
return session;
|
|
22
|
+
}
|
|
17
23
|
export function txExecutor(req) {
|
|
18
24
|
const db = req.payload.db;
|
|
19
25
|
return {
|
|
20
26
|
schemaName: db.schemaName,
|
|
21
27
|
async query (text, params = []) {
|
|
22
|
-
const
|
|
23
|
-
const session = id == null ? undefined : db.sessions?.[id];
|
|
24
|
-
if (!session) throw new XpNoTransactionError();
|
|
28
|
+
const session = await transactionSession(req);
|
|
25
29
|
return normalise(await session.db.execute(bind(text, params)));
|
|
26
30
|
}
|
|
27
31
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Payload } from 'payload';
|
|
2
|
+
import type { DocId } from '../types/contracts.js';
|
|
3
|
+
/** Read only the tracked IDs. Omitting req puts this adapter read on the pool,
|
|
4
|
+
* so a row visible here survived the copy transaction. */
|
|
5
|
+
export declare function committedPageCopyIds(payload: Payload, collection: string, created: DocId[]): Promise<DocId[]>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Read only the tracked IDs. Omitting req puts this adapter read on the pool,
|
|
2
|
+
* so a row visible here survived the copy transaction. */ export async function committedPageCopyIds(payload, collection, created) {
|
|
3
|
+
const ids = [
|
|
4
|
+
...new Set(created)
|
|
5
|
+
];
|
|
6
|
+
if (!ids.length) return [];
|
|
7
|
+
const adapter = payload.db;
|
|
8
|
+
// The original transaction may have died before the adapter marked its write.
|
|
9
|
+
// Always check the primary so replica lag can't hide a committed draft.
|
|
10
|
+
const primary = adapter.primaryDrizzle ? {
|
|
11
|
+
...adapter,
|
|
12
|
+
drizzle: adapter.primaryDrizzle
|
|
13
|
+
} : adapter;
|
|
14
|
+
const { docs } = await primary.find({
|
|
15
|
+
collection,
|
|
16
|
+
where: {
|
|
17
|
+
id: {
|
|
18
|
+
in: ids
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
select: {
|
|
22
|
+
id: true
|
|
23
|
+
},
|
|
24
|
+
sort: 'id',
|
|
25
|
+
limit: ids.length,
|
|
26
|
+
pagination: false,
|
|
27
|
+
// The adapter has no access layer. Only IDs from this write are checked here.
|
|
28
|
+
overrideAccess: false
|
|
29
|
+
});
|
|
30
|
+
return docs.map((doc)=>doc.id);
|
|
31
|
+
}
|
package/dist/db/results.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export interface PhaseExposureRow {
|
|
|
5
5
|
unitId: string;
|
|
6
6
|
arm: string;
|
|
7
7
|
ts: number;
|
|
8
|
+
unitAgeMs?: number;
|
|
8
9
|
}
|
|
9
10
|
export interface RolloutExposureRow {
|
|
10
11
|
unitId: string;
|
|
@@ -16,6 +17,7 @@ export interface MetricEventRow {
|
|
|
16
17
|
userId: string | null;
|
|
17
18
|
value: number;
|
|
18
19
|
ts: number;
|
|
20
|
+
unitAgeMs?: number;
|
|
19
21
|
}
|
|
20
22
|
export interface IdentityRow {
|
|
21
23
|
anonymousId: string;
|
|
@@ -41,12 +43,14 @@ export declare function rolloutExposureRows(exec: Executor, { experimentId, resp
|
|
|
41
43
|
* or userIds for stored user_id (user units and visitor identity credit). Each distinct
|
|
42
44
|
* ID occurs in one ANY array of at most 10,000, so batching cannot duplicate rows.
|
|
43
45
|
*/
|
|
44
|
-
export declare function metricEventRows(exec: Executor, { eventName, unitIds, userIds, from, to }: {
|
|
46
|
+
export declare function metricEventRows(exec: Executor, { eventName, unitIds, userIds, from, to, readAge, forVisitors }: {
|
|
45
47
|
eventName: string;
|
|
46
48
|
unitIds?: readonly string[];
|
|
47
49
|
userIds?: readonly string[];
|
|
48
50
|
from: Timestamp;
|
|
49
51
|
to: Timestamp;
|
|
52
|
+
readAge?: boolean;
|
|
53
|
+
forVisitors?: boolean;
|
|
50
54
|
}): Promise<MetricEventRow[]>;
|
|
51
55
|
/** Linked visitors for creditUserEvents; disjoint ANY batches of ≤ 10,000 IDs. */
|
|
52
56
|
export declare function identityRows(exec: Executor, { anonymousIds }: {
|
package/dist/db/results.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { timestampMs } from '../results/aggregate.js';
|
|
2
2
|
import { COLUMNS, TABLES } from './names.js';
|
|
3
|
+
import { USER_BROWSER_CONVERSION_PREFIX } from '../constants.js';
|
|
3
4
|
import { qualifiedTable, quoteIdentifier as q } from './sql.js';
|
|
4
5
|
const c = COLUMNS.events;
|
|
5
6
|
const batchSize = 10_000;
|
|
6
7
|
const iso = (ts)=>new Date(timestampMs(ts)).toISOString();
|
|
7
8
|
// round()::bigint keeps exact milliseconds on servers where extract() returns a float (PG ≤ 13).
|
|
8
9
|
const epochMs = `round(extract(epoch from ${q(c.ts)}) * 1000)::bigint`;
|
|
10
|
+
const signedAge = `${q(c.attributes)}->'_xp'->'unitAgeMs' AS "unitAgeMs"`;
|
|
11
|
+
function knownAge(unitAgeMs) {
|
|
12
|
+
// A reissued legacy ID counts as known and older than the rapid activity window.
|
|
13
|
+
if (unitAgeMs === 'legacy') return {
|
|
14
|
+
unitAgeMs: Infinity
|
|
15
|
+
};
|
|
16
|
+
return typeof unitAgeMs === 'number' && Number.isSafeInteger(unitAgeMs) && unitAgeMs >= 0 ? {
|
|
17
|
+
unitAgeMs
|
|
18
|
+
} : {};
|
|
19
|
+
}
|
|
9
20
|
function phaseFilter({ experimentId, phase, endedAt }, type) {
|
|
10
21
|
const params = [
|
|
11
22
|
experimentId,
|
|
@@ -24,11 +35,12 @@ function phaseFilter({ experimentId, phase, endedAt }, type) {
|
|
|
24
35
|
}
|
|
25
36
|
/** All phase exposures, including multi-arm rows for firstExposures to exclude. */ export async function phaseExposureRows(exec, opts) {
|
|
26
37
|
const filter = phaseFilter(opts, 'exposure');
|
|
27
|
-
const { rows } = await exec.query(`SELECT ${q(c.unitId)} AS "unitId", ${q(c.arm)} AS "arm", ${epochMs} AS "ts" FROM ${qualifiedTable(exec, TABLES.events)} WHERE ${filter.text} ORDER BY ${q(c.ts)}, ${q(c.unitId)}`, filter.params);
|
|
38
|
+
const { rows } = await exec.query(`SELECT ${q(c.unitId)} AS "unitId", ${q(c.arm)} AS "arm", ${epochMs} AS "ts", ${signedAge} FROM ${qualifiedTable(exec, TABLES.events)} WHERE ${filter.text} ORDER BY ${q(c.ts)}, ${q(c.unitId)}`, filter.params);
|
|
28
39
|
return rows.map((row)=>({
|
|
29
40
|
unitId: row.unitId,
|
|
30
41
|
arm: row.arm,
|
|
31
|
-
ts: Number(row.ts)
|
|
42
|
+
ts: Number(row.ts),
|
|
43
|
+
...knownAge(row.unitAgeMs)
|
|
32
44
|
}));
|
|
33
45
|
}
|
|
34
46
|
/** Diagnostic distinct units only; this never contributes to multi-arm exclusion. */ export async function armMismatchCount(exec, opts) {
|
|
@@ -52,7 +64,7 @@ function phaseFilter({ experimentId, phase, endedAt }, type) {
|
|
|
52
64
|
/** events:<name> conversion rows in [from, to). Choose unitIds for stored unit_id,
|
|
53
65
|
* or userIds for stored user_id (user units and visitor identity credit). Each distinct
|
|
54
66
|
* ID occurs in one ANY array of at most 10,000, so batching cannot duplicate rows.
|
|
55
|
-
*/ export async function metricEventRows(exec, { eventName, unitIds, userIds, from, to }) {
|
|
67
|
+
*/ export async function metricEventRows(exec, { eventName, unitIds, userIds, from, to, readAge = false, forVisitors = false }) {
|
|
56
68
|
if (unitIds !== undefined && userIds !== undefined) throw new RangeError('Choose unitIds or userIds');
|
|
57
69
|
const params = [
|
|
58
70
|
'conversion',
|
|
@@ -60,7 +72,10 @@ function phaseFilter({ experimentId, phase, endedAt }, type) {
|
|
|
60
72
|
iso(from),
|
|
61
73
|
iso(to)
|
|
62
74
|
];
|
|
63
|
-
|
|
75
|
+
// A browser conversion without a visitor cookie cannot count for a visitor,
|
|
76
|
+
// even through the separate linked-user lookup.
|
|
77
|
+
const visitorFilter = forVisitors ? ` AND ${q(c.dedupeKey)} NOT LIKE '${USER_BROWSER_CONVERSION_PREFIX}%'` : '';
|
|
78
|
+
const text = `SELECT ${q(c.unitId)} AS "unitId", ${q(c.userId)} AS "userId", ${q(c.value)} AS "value", ${epochMs} AS "ts"${readAge ? `, ${signedAge}` : ''} FROM ${qualifiedTable(exec, TABLES.events)} WHERE ${q(c.type)} = $1 AND ${q(c.eventName)} = $2 AND ${q(c.ts)} >= $3 AND ${q(c.ts)} < $4${visitorFilter}`;
|
|
64
79
|
const filterIds = userIds ?? unitIds;
|
|
65
80
|
const column = userIds === undefined ? c.unitId : c.userId;
|
|
66
81
|
const ids = filterIds === undefined ? undefined : [
|
|
@@ -77,7 +92,8 @@ function phaseFilter({ experimentId, phase, endedAt }, type) {
|
|
|
77
92
|
unitId: row.unitId,
|
|
78
93
|
userId: row.userId == null ? null : String(row.userId),
|
|
79
94
|
value: Number(row.value),
|
|
80
|
-
ts: Number(row.ts)
|
|
95
|
+
ts: Number(row.ts),
|
|
96
|
+
...knownAge(row.unitAgeMs)
|
|
81
97
|
});
|
|
82
98
|
}
|
|
83
99
|
if (ids === undefined) break;
|
package/dist/db/snapshots.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface ResultsPhase extends AnalysisPhase {
|
|
|
13
13
|
addedAt?: string;
|
|
14
14
|
keyedBy?: UnitType;
|
|
15
15
|
capNotice?: 'no-history';
|
|
16
|
+
browserWritable?: boolean;
|
|
16
17
|
}>;
|
|
17
18
|
}
|
|
18
19
|
export interface ResultsCandidate {
|
|
@@ -32,6 +33,7 @@ export interface ResultsCandidate {
|
|
|
32
33
|
key: string;
|
|
33
34
|
weight: number;
|
|
34
35
|
kind?: string;
|
|
36
|
+
label?: string;
|
|
35
37
|
pageTarget?: string;
|
|
36
38
|
}>;
|
|
37
39
|
layerSlug: string | null;
|
|
@@ -5,6 +5,7 @@ import { Forbidden } from 'payload';
|
|
|
5
5
|
import { XpRefusal } from '../errors.js';
|
|
6
6
|
import { compileManifest, loadManifestInputs } from '../manifest/compile.js';
|
|
7
7
|
import { publishedBlockPlacementPages } from '../transitions/placements.js';
|
|
8
|
+
import { API_MESSAGES } from '../testSurface/copy/common.js';
|
|
8
9
|
import { routeId } from './routeId.js';
|
|
9
10
|
/** Advisory read only. Delete keeps its own access check, status guard and transaction. */ export async function handleDeleteImpact(req, { options }) {
|
|
10
11
|
const headers = {
|
|
@@ -39,7 +40,7 @@ import { routeId } from './routeId.js';
|
|
|
39
40
|
});
|
|
40
41
|
const experiment = docs[0];
|
|
41
42
|
if (!experiment) throw new XpRefusal('not-found', 'Experiment not found', undefined, 404);
|
|
42
|
-
if (experiment.status !== 'draft' && experiment.status !== 'archived') throw new XpRefusal('invalid-status',
|
|
43
|
+
if (experiment.status !== 'draft' && experiment.status !== 'archived') throw new XpRefusal('invalid-status', API_MESSAGES.deleteInvalidStatus, undefined, 409);
|
|
43
44
|
const { decision, kind } = experiment;
|
|
44
45
|
if (experiment.status === 'draft' || !decision?.winnerArm || decision.discardedAt || kind !== 'block' && kind !== 'page' || kind === 'page' && decision.pagesReleasedAt || kind === 'block' && decision.winnerArm === 'control') return reply({
|
|
45
46
|
effect: 'none'
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type PayloadRequest } from 'payload';
|
|
2
|
+
import type { Arm, DocId, ExperimentsPageCollection, ResolvedOptions } from '../types/contracts.js';
|
|
3
|
+
import type { CopyPagePlan, EndpointContext } from '../types/endpoints.js';
|
|
4
|
+
declare function readTest(req: PayloadRequest, id: DocId): Promise<import("payload").JsonObject & import("payload").TypeWithID>;
|
|
5
|
+
export declare function preparePageCopy<TUser extends {
|
|
6
|
+
id: DocId;
|
|
7
|
+
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, test: Awaited<ReturnType<typeof readTest>>, key: string, confirmed?: CopyPagePlan): Promise<{
|
|
8
|
+
plan: {
|
|
9
|
+
title: string;
|
|
10
|
+
path: string;
|
|
11
|
+
phase: number;
|
|
12
|
+
updatedAt: string;
|
|
13
|
+
originalId: string | number;
|
|
14
|
+
originalUpdatedAt: string;
|
|
15
|
+
};
|
|
16
|
+
data: Record<string, unknown>;
|
|
17
|
+
entry: ExperimentsPageCollection;
|
|
18
|
+
titleField: string;
|
|
19
|
+
homeFlags: string[];
|
|
20
|
+
hasSlugHistory: boolean;
|
|
21
|
+
requiredUniqueFields: string[];
|
|
22
|
+
original: import("payload").JsonObject & import("payload").TypeWithID;
|
|
23
|
+
arms: Arm[];
|
|
24
|
+
reader: {
|
|
25
|
+
views: import("../blocks/placementLocale.js").PlacementLocaleView[];
|
|
26
|
+
documentViews: import("../blocks/placementLocale.js").PlacementLocaleView[];
|
|
27
|
+
read(doc: Record<string, unknown> | null | undefined, input: import("../blocks/placementLocale.js").PlacementInput, view?: import("../blocks/placementLocale.js").PlacementLocaleView): {
|
|
28
|
+
view: import("../blocks/placementLocale.js").PlacementLocaleView;
|
|
29
|
+
readonly doc: Record<string, unknown> | undefined;
|
|
30
|
+
readonly editor: "page" | "puck" | "blocks";
|
|
31
|
+
readonly slugs: string[];
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
}>;
|
|
35
|
+
export declare function handleDuplicateOriginal<TUser extends {
|
|
36
|
+
id: DocId;
|
|
37
|
+
}>(req: PayloadRequest, { options }: EndpointContext<TUser>): Promise<Response>;
|
|
38
|
+
export {};
|