@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/endpoints/index.js
CHANGED
|
@@ -4,15 +4,16 @@ import { handleClickKeys } from './clickKeys.js';
|
|
|
4
4
|
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
5
5
|
import { XP_MANIFEST_KEY_HEADER } from '../constants.js';
|
|
6
6
|
import { XpNotImplemented, XpRefusal } from '../errors.js';
|
|
7
|
-
import { readUnitCookie } from '../runtime/cookie.js';
|
|
8
7
|
import { handleManifest } from './manifest.js';
|
|
9
8
|
import { handleEvents } from './events.js';
|
|
10
9
|
import { handleStart, handleAllocate, handleAddMetric, handleStop, handleDecide, handleReleaseHoldout, handleReleasePages, handleMakeContent, handleDismissContentEntry, handleRestoreContentEntry, handleArchive } from './transitions.js';
|
|
11
10
|
import { handlePreflight } from './preflight.js';
|
|
11
|
+
import { handleTestVersion } from './testVersion.js';
|
|
12
12
|
import { handlePreviewToken } from './previewToken.js';
|
|
13
13
|
import { handleResults } from './results.js';
|
|
14
14
|
import { handleRecompute } from './recompute.js';
|
|
15
15
|
import { handleWrapBlock } from './wrapBlock.js';
|
|
16
|
+
import { handleDuplicateOriginal } from './duplicateOriginal.js';
|
|
16
17
|
import { handlePages } from './pages.js';
|
|
17
18
|
import { handlePlacementStatus } from './placementStatus.js';
|
|
18
19
|
import { handleSummary } from './summary.js';
|
|
@@ -26,7 +27,7 @@ export const ROUTES = [
|
|
|
26
27
|
{
|
|
27
28
|
method: 'post',
|
|
28
29
|
path: '/xp/events',
|
|
29
|
-
access: '
|
|
30
|
+
access: 'browserEvents',
|
|
30
31
|
handler: handleEvents
|
|
31
32
|
},
|
|
32
33
|
{
|
|
@@ -107,6 +108,12 @@ export const ROUTES = [
|
|
|
107
108
|
access: 'manage',
|
|
108
109
|
handler: handlePreflight
|
|
109
110
|
},
|
|
111
|
+
{
|
|
112
|
+
method: 'get',
|
|
113
|
+
path: '/xp/experiments/:id/version',
|
|
114
|
+
access: 'manage',
|
|
115
|
+
handler: handleTestVersion
|
|
116
|
+
},
|
|
110
117
|
{
|
|
111
118
|
method: 'get',
|
|
112
119
|
path: '/xp/experiments/:id/preview-token',
|
|
@@ -149,6 +156,18 @@ export const ROUTES = [
|
|
|
149
156
|
access: 'manage',
|
|
150
157
|
handler: handlePages
|
|
151
158
|
},
|
|
159
|
+
{
|
|
160
|
+
method: 'get',
|
|
161
|
+
path: '/xp/experiments/:id/duplicate-original',
|
|
162
|
+
access: 'manage',
|
|
163
|
+
handler: handleDuplicateOriginal
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
method: 'post',
|
|
167
|
+
path: '/xp/experiments/:id/duplicate-original',
|
|
168
|
+
access: 'manage',
|
|
169
|
+
handler: handleDuplicateOriginal
|
|
170
|
+
},
|
|
152
171
|
{
|
|
153
172
|
method: 'post',
|
|
154
173
|
path: '/xp/placements/status',
|
|
@@ -222,13 +241,8 @@ export function buildEndpoints(ctx) {
|
|
|
222
241
|
if (!supplied || Buffer.byteLength(supplied) !== Buffer.byteLength(expected) || !timingSafeEqual(Buffer.from(supplied), Buffer.from(expected))) {
|
|
223
242
|
return error(401, 'unauthenticated', 'Invalid manifest key');
|
|
224
243
|
}
|
|
225
|
-
} else {
|
|
226
|
-
const visitorId = readUnitCookie(req.headers, options.runtime.proxyRuntime);
|
|
227
|
-
if (!visitorId) return error(401, 'unauthenticated', 'Invalid unit cookie');
|
|
228
|
-
handlerContext.unit = {
|
|
229
|
-
visitorId
|
|
230
|
-
};
|
|
231
244
|
}
|
|
245
|
+
// The browser events handler checks consent, origin and both possible credentials.
|
|
232
246
|
return await route.handler(req, handlerContext);
|
|
233
247
|
} catch (cause) {
|
|
234
248
|
if (cause instanceof XpRefusal) return error(cause.status, cause.code, cause.message, cause.detail);
|
package/dist/endpoints/pages.js
CHANGED
|
@@ -1,49 +1,63 @@
|
|
|
1
|
+
import { flattenTopLevelFields, formatAdminURL } from 'payload/shared';
|
|
1
2
|
import { placementReader } from '../blocks/placementLocale.js';
|
|
3
|
+
import { findDraftPageByPath, PAGE_ADDRESS_FIELDS } from '../transitions/pageAddress.js';
|
|
2
4
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
5
|
+
import { blockPageSlugs, hasPuckEditor } from '../options.js';
|
|
3
6
|
import { XpRefusal } from '../errors.js';
|
|
7
|
+
const PAGE_SIZE = 20;
|
|
8
|
+
const MAX_PAGE = 1000;
|
|
9
|
+
const MAX_SEARCH_IDS = PAGE_SIZE * MAX_PAGE;
|
|
10
|
+
const pageResponse = (body)=>Response.json(body, {
|
|
11
|
+
headers: {
|
|
12
|
+
'Cache-Control': 'private, no-store'
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
const textValue = (value)=>typeof value === 'string' && value.trim() ? value : undefined;
|
|
16
|
+
const anyFilter = (filters)=>filters.length > 1 ? {
|
|
17
|
+
or: filters
|
|
18
|
+
} : filters[0];
|
|
19
|
+
function requiresPublished(where) {
|
|
20
|
+
const status = Array.isArray(where._status) ? undefined : where._status;
|
|
21
|
+
const allowed = status?.in;
|
|
22
|
+
return status?.equals === 'published' || allowed === 'published' || Array.isArray(allowed) && allowed.length === 1 && allowed[0] === 'published' || Boolean(where.and?.some(requiresPublished)) || Boolean(where.or?.length && where.or.every(requiresPublished));
|
|
23
|
+
}
|
|
4
24
|
export async function handlePages(req, { options }) {
|
|
5
25
|
const query = new URL(req.url ?? 'http://xp.invalid').searchParams;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const
|
|
26
|
+
const slug = query.get('collection') ?? '';
|
|
27
|
+
const collection = options.pages?.collections.find((entry)=>entry.slug === slug);
|
|
28
|
+
const blockMode = query.get('mode') === 'block';
|
|
29
|
+
if (blockMode ? !blockPageSlugs(options).includes(slug) : !collection) {
|
|
30
|
+
throw new XpRefusal('unknown-collection', "That page type isn't set up for tests.", undefined, 422);
|
|
31
|
+
}
|
|
32
|
+
const reader = placementReader(req, slug, options);
|
|
33
|
+
const input = req.locale === 'all' ? 'all-locales' : 'localized';
|
|
9
34
|
const path = query.get('path');
|
|
10
|
-
if (path !== null && (!path.length || path.length > 2048 || query.has('q'))) throw new XpRefusal('invalid-body', 'Enter a valid request body.', undefined, 422);
|
|
35
|
+
if (path !== null && (blockMode || !path.length || path.length > 2048 || query.has('q'))) throw new XpRefusal('invalid-body', 'Enter a valid request body.', undefined, 422);
|
|
11
36
|
const page = Number(query.get('page') ?? 1);
|
|
12
|
-
if (!Number.isSafeInteger(page) || page < 1 || page >
|
|
13
|
-
const config = req.payload.config.collections.find((entry)=>entry.slug ===
|
|
14
|
-
const
|
|
37
|
+
if (!Number.isSafeInteger(page) || page < 1 || page > MAX_PAGE) throw new XpRefusal('invalid-body', 'Choose a valid page.', undefined, 422);
|
|
38
|
+
const config = req.payload.config.collections.find((entry)=>entry.slug === slug);
|
|
39
|
+
const fields = flattenTopLevelFields(config?.fields ?? []);
|
|
40
|
+
const title = config?.admin.useAsTitle;
|
|
41
|
+
const titleField = title && title !== 'id' ? title : fields.some((field)=>field.name === 'title') ? 'title' : title ?? 'id';
|
|
15
42
|
const drafts = Boolean(config?.versions && config.versions.drafts);
|
|
16
|
-
|
|
17
|
-
if (path !== null) {
|
|
43
|
+
if (path !== null && collection) {
|
|
18
44
|
const found = await collection.findByPath(path, req);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
hasNextPage: false
|
|
22
|
-
}, {
|
|
23
|
-
headers: {
|
|
24
|
-
'Cache-Control': 'no-store'
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
const main = await req.payload.findByID({
|
|
28
|
-
collection: collection.slug,
|
|
45
|
+
const main = found ? await req.payload.findByID({
|
|
46
|
+
collection: slug,
|
|
29
47
|
id: found.id,
|
|
30
48
|
req,
|
|
31
49
|
overrideAccess: false,
|
|
32
50
|
depth: 0,
|
|
33
51
|
draft: false,
|
|
34
52
|
disableErrors: true
|
|
35
|
-
});
|
|
36
|
-
if (!main) return
|
|
53
|
+
}) : await findDraftPageByPath(req, collection, path);
|
|
54
|
+
if (!main) return pageResponse({
|
|
37
55
|
docs: [],
|
|
38
56
|
hasNextPage: false
|
|
39
|
-
}, {
|
|
40
|
-
headers: {
|
|
41
|
-
'Cache-Control': 'no-store'
|
|
42
|
-
}
|
|
43
57
|
});
|
|
44
58
|
const published = !drafts || main._status === 'published';
|
|
45
59
|
const row = published ? main : await req.payload.findByID({
|
|
46
|
-
collection:
|
|
60
|
+
collection: slug,
|
|
47
61
|
id: main.id,
|
|
48
62
|
req,
|
|
49
63
|
overrideAccess: false,
|
|
@@ -51,74 +65,239 @@ export async function handlePages(req, { options }) {
|
|
|
51
65
|
draft: true,
|
|
52
66
|
disableErrors: true
|
|
53
67
|
});
|
|
54
|
-
if (!row) return
|
|
68
|
+
if (!row) return pageResponse({
|
|
55
69
|
docs: [],
|
|
56
70
|
hasNextPage: false
|
|
57
|
-
}, {
|
|
58
|
-
headers: {
|
|
59
|
-
'Cache-Control': 'no-store'
|
|
60
|
-
}
|
|
61
71
|
});
|
|
62
|
-
const doc = reader.read(row,
|
|
72
|
+
const doc = reader.read(row, input).doc;
|
|
63
73
|
const rawPath = collection.pathOf(doc);
|
|
64
|
-
return
|
|
74
|
+
if (!found && (!rawPath || normalisePath(rawPath) !== normalisePath(path))) return pageResponse({
|
|
75
|
+
docs: [],
|
|
76
|
+
hasNextPage: false
|
|
77
|
+
});
|
|
78
|
+
return pageResponse({
|
|
65
79
|
docs: [
|
|
66
80
|
{
|
|
67
81
|
id: main.id,
|
|
68
|
-
title: titleField !== 'id'
|
|
82
|
+
title: titleField !== 'id' ? textValue(doc[titleField]) ?? '' : '',
|
|
69
83
|
path: rawPath,
|
|
70
84
|
pathKey: rawPath === null ? null : normalisePath(rawPath),
|
|
71
85
|
published
|
|
72
86
|
}
|
|
73
87
|
],
|
|
74
88
|
hasNextPage: false
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const q = query.get('q')?.trim().slice(0, 100) ?? '';
|
|
92
|
+
const addressFields = PAGE_ADDRESS_FIELDS.filter((name)=>fields.some((field)=>field.name === name));
|
|
93
|
+
const searchFields = new Set([
|
|
94
|
+
titleField,
|
|
95
|
+
...addressFields,
|
|
96
|
+
...config?.admin.listSearchableFields ?? []
|
|
97
|
+
]);
|
|
98
|
+
const searchable = q ? await Promise.all(fields.map(async (field)=>{
|
|
99
|
+
if (field.type !== 'text' && field.type !== 'textarea' || field.hidden || field.virtual || !searchFields.has(field.name)) return;
|
|
100
|
+
if (field.access?.read && !await field.access.read({
|
|
101
|
+
req
|
|
102
|
+
})) return;
|
|
103
|
+
return field.name;
|
|
104
|
+
})) : [];
|
|
105
|
+
const filters = searchable.flatMap((field)=>{
|
|
106
|
+
if (!field) return [];
|
|
107
|
+
const term = field === 'slug' || field === 'pageSegment' ? q.replace(/^\/+|\/+$/g, '') : q;
|
|
108
|
+
return term ? [
|
|
109
|
+
{
|
|
110
|
+
[field]: {
|
|
111
|
+
like: term
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
] : [];
|
|
115
|
+
});
|
|
116
|
+
const fieldFilter = anyFilter([
|
|
117
|
+
...filters
|
|
118
|
+
]);
|
|
119
|
+
// A generated address may not have its own queryable field, and a live path
|
|
120
|
+
// can differ from the latest draft. The host's exact lookup covers both cases.
|
|
121
|
+
if (q.startsWith('/') && collection) {
|
|
122
|
+
const found = await collection.findByPath(q, req);
|
|
123
|
+
if (found) filters.push({
|
|
124
|
+
id: {
|
|
125
|
+
equals: found.id
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (q && !filters.length) return pageResponse({
|
|
130
|
+
docs: [],
|
|
131
|
+
hasNextPage: false,
|
|
132
|
+
totalDocs: 0
|
|
133
|
+
});
|
|
134
|
+
// Payload applies the read constraint to the latest version when draft is
|
|
135
|
+
// true. A manager scoped to published content needs to browse the live rows.
|
|
136
|
+
const readScope = drafts ? await config?.access?.read?.({
|
|
137
|
+
req
|
|
138
|
+
}) : undefined;
|
|
139
|
+
const readDrafts = drafts && !(readScope && typeof readScope === 'object' && requiresPublished(readScope));
|
|
140
|
+
let searchTruncated = false;
|
|
141
|
+
if (readDrafts && fieldFilter) {
|
|
142
|
+
// Include live matches in the draft query before sorting and paging.
|
|
143
|
+
// Cap the ID lookup to the number of rows the picker can show.
|
|
144
|
+
const matches = await req.payload.find({
|
|
145
|
+
collection: slug,
|
|
146
|
+
req,
|
|
147
|
+
overrideAccess: false,
|
|
148
|
+
depth: 0,
|
|
149
|
+
draft: false,
|
|
150
|
+
where: {
|
|
151
|
+
and: [
|
|
152
|
+
{
|
|
153
|
+
_status: {
|
|
154
|
+
equals: 'published'
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
fieldFilter
|
|
158
|
+
]
|
|
159
|
+
},
|
|
160
|
+
select: {
|
|
161
|
+
id: true
|
|
162
|
+
},
|
|
163
|
+
pagination: false,
|
|
164
|
+
sort: '-id',
|
|
165
|
+
limit: MAX_SEARCH_IDS + 1
|
|
166
|
+
});
|
|
167
|
+
searchTruncated = matches.docs.length > MAX_SEARCH_IDS;
|
|
168
|
+
if (matches.docs.length) filters.push({
|
|
169
|
+
id: {
|
|
170
|
+
in: matches.docs.slice(0, MAX_SEARCH_IDS).map((doc)=>doc.id)
|
|
78
171
|
}
|
|
79
172
|
});
|
|
80
173
|
}
|
|
174
|
+
const where = anyFilter(filters);
|
|
175
|
+
const block = options.blocks?.collections.find((entry)=>entry.slug === slug);
|
|
176
|
+
const hasTimestamp = config?.timestamps !== false;
|
|
177
|
+
const hasDocCallbacks = collection || blockMode && (block?.appliesTo || options.admin?.editorUrl);
|
|
178
|
+
const metadata = Object.fromEntries([
|
|
179
|
+
titleField,
|
|
180
|
+
...addressFields,
|
|
181
|
+
...hasTimestamp ? [
|
|
182
|
+
'updatedAt'
|
|
183
|
+
] : [],
|
|
184
|
+
...drafts ? [
|
|
185
|
+
'_status'
|
|
186
|
+
] : []
|
|
187
|
+
].map((field)=>[
|
|
188
|
+
field,
|
|
189
|
+
true
|
|
190
|
+
]));
|
|
81
191
|
const result = await req.payload.find({
|
|
82
|
-
collection:
|
|
192
|
+
collection: slug,
|
|
83
193
|
req,
|
|
84
194
|
overrideAccess: false,
|
|
85
195
|
depth: 0,
|
|
86
|
-
draft:
|
|
87
|
-
sort:
|
|
88
|
-
|
|
196
|
+
draft: readDrafts,
|
|
197
|
+
sort: hasTimestamp ? [
|
|
198
|
+
'-updatedAt',
|
|
199
|
+
'-id'
|
|
200
|
+
] : '-id',
|
|
201
|
+
limit: PAGE_SIZE,
|
|
89
202
|
page,
|
|
90
|
-
where
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
} : undefined
|
|
203
|
+
where,
|
|
204
|
+
// Host callbacks can inspect arbitrary fields. Only picker metadata leaves this endpoint.
|
|
205
|
+
select: hasDocCallbacks ? undefined : metadata
|
|
95
206
|
});
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
207
|
+
const draftIds = readDrafts ? result.docs.filter((doc)=>doc._status === 'draft').map((doc)=>doc.id) : [];
|
|
208
|
+
const publishedById = new Map();
|
|
209
|
+
if (draftIds.length) {
|
|
210
|
+
// Read only the matching live rows, in one bounded query. Whole-page choices
|
|
211
|
+
// use the currently served path even when a newer edit changes that path.
|
|
212
|
+
const live = await req.payload.find({
|
|
213
|
+
collection: slug,
|
|
101
214
|
req,
|
|
102
215
|
overrideAccess: false,
|
|
103
216
|
depth: 0,
|
|
104
|
-
draft:
|
|
217
|
+
draft: false,
|
|
218
|
+
where: {
|
|
219
|
+
id: {
|
|
220
|
+
in: draftIds
|
|
221
|
+
},
|
|
222
|
+
_status: {
|
|
223
|
+
equals: 'published'
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
limit: PAGE_SIZE,
|
|
227
|
+
select: !blockMode && collection ? undefined : {
|
|
228
|
+
_status: true
|
|
229
|
+
}
|
|
105
230
|
});
|
|
106
|
-
const doc
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
231
|
+
for (const doc of live.docs)if (doc._status === 'published') publishedById.set(String(doc.id), doc);
|
|
232
|
+
}
|
|
233
|
+
const docs = result.docs.flatMap((row)=>{
|
|
234
|
+
const placement = reader.read(row, input);
|
|
235
|
+
const doc = placement.doc;
|
|
236
|
+
const live = publishedById.get(String(row.id));
|
|
237
|
+
const published = !drafts || row._status === 'published' || live !== undefined;
|
|
238
|
+
const pathDoc = !blockMode && live ? reader.read(live, input).doc : doc;
|
|
239
|
+
const rawPath = collection?.pathOf(pathDoc) ?? null;
|
|
240
|
+
const storedAddress = blockMode ? addressFields.reduce((value, field)=>value ?? textValue(pathDoc[field]), undefined) : undefined;
|
|
241
|
+
const address = rawPath ?? storedAddress;
|
|
242
|
+
const draftAddress = !blockMode && live ? collection?.pathOf(doc) : null;
|
|
243
|
+
const updatedAt = textValue(doc.updatedAt);
|
|
244
|
+
const title = doc[titleField];
|
|
245
|
+
const item = {
|
|
246
|
+
id: row.id,
|
|
247
|
+
title: textValue(title) ?? (typeof title === 'number' ? String(title) : String(row.id)),
|
|
248
|
+
path: rawPath,
|
|
249
|
+
pathKey: rawPath === null ? null : normalisePath(rawPath),
|
|
250
|
+
published,
|
|
251
|
+
status: live ? 'changed' : published ? 'published' : 'draft',
|
|
252
|
+
...address ? {
|
|
253
|
+
address
|
|
254
|
+
} : {},
|
|
255
|
+
...draftAddress && draftAddress !== rawPath ? {
|
|
256
|
+
draftAddress
|
|
257
|
+
} : {},
|
|
258
|
+
...updatedAt ? {
|
|
259
|
+
updatedAt
|
|
260
|
+
} : {}
|
|
114
261
|
};
|
|
115
|
-
|
|
116
|
-
|
|
262
|
+
if (!blockMode) return [
|
|
263
|
+
item
|
|
264
|
+
];
|
|
265
|
+
const editor = placement.editor;
|
|
266
|
+
if (editor === 'page') return [];
|
|
267
|
+
let customUrl;
|
|
268
|
+
try {
|
|
269
|
+
customUrl = textValue(options.admin?.editorUrl?.({
|
|
270
|
+
collection: slug,
|
|
271
|
+
id: row.id,
|
|
272
|
+
draft: true,
|
|
273
|
+
editor,
|
|
274
|
+
doc
|
|
275
|
+
}));
|
|
276
|
+
} catch {}
|
|
277
|
+
const editorUrl = customUrl ?? formatAdminURL({
|
|
278
|
+
adminRoute: req.payload.config.routes.admin,
|
|
279
|
+
path: `/collections/${slug}/${encodeURIComponent(String(row.id))}`
|
|
280
|
+
});
|
|
281
|
+
return [
|
|
282
|
+
{
|
|
283
|
+
...item,
|
|
284
|
+
editor,
|
|
285
|
+
editorUrl
|
|
286
|
+
}
|
|
287
|
+
];
|
|
288
|
+
});
|
|
289
|
+
const mayFilter = blockMode && Boolean(block?.appliesTo) && !hasPuckEditor(options, slug);
|
|
290
|
+
const hasNextPage = page < MAX_PAGE && result.hasNextPage;
|
|
291
|
+
const pageLimitReached = !hasNextPage && (result.hasNextPage || searchTruncated);
|
|
292
|
+
return pageResponse({
|
|
117
293
|
docs,
|
|
118
|
-
hasNextPage
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
294
|
+
hasNextPage,
|
|
295
|
+
...pageLimitReached ? {
|
|
296
|
+
pageLimitReached
|
|
297
|
+
} : {},
|
|
298
|
+
...mayFilter || searchTruncated ? {} : {
|
|
299
|
+
totalDocs: result.totalDocs,
|
|
300
|
+
pagingCounter: result.pagingCounter
|
|
122
301
|
}
|
|
123
302
|
});
|
|
124
303
|
}
|
|
@@ -134,13 +134,16 @@ export async function handlePlacementStatus(req, { options }) {
|
|
|
134
134
|
name: test.name,
|
|
135
135
|
status: test.status,
|
|
136
136
|
kind: test.kind,
|
|
137
|
-
arms: round.arms.map(({ key, label, slot })=>
|
|
137
|
+
arms: round.arms.map(({ key, kind, label, slot })=>{
|
|
138
|
+
const contentSlot = test.kind === 'block' ? kind !== 'holdout' && key !== 'holdout' ? key : undefined : slot;
|
|
139
|
+
return {
|
|
138
140
|
key,
|
|
139
141
|
label,
|
|
140
|
-
...
|
|
141
|
-
slot
|
|
142
|
+
...contentSlot ? {
|
|
143
|
+
slot: contentSlot
|
|
142
144
|
} : {}
|
|
143
|
-
}
|
|
145
|
+
};
|
|
146
|
+
}),
|
|
144
147
|
...test.decision?.winnerArm ? {
|
|
145
148
|
winnerArm: test.decision.winnerArm
|
|
146
149
|
} : {},
|
|
@@ -215,6 +218,7 @@ export async function handlePlacementStatus(req, { options }) {
|
|
|
215
218
|
status: test.status,
|
|
216
219
|
role: arm.kind === 'control' ? 'original' : 'version',
|
|
217
220
|
armLabel: arm.label,
|
|
221
|
+
controlLabel: original?.label,
|
|
218
222
|
winner: [
|
|
219
223
|
'decided',
|
|
220
224
|
'archived'
|
|
@@ -21,4 +21,4 @@ export declare function handleResults<TUser extends {
|
|
|
21
21
|
id: string | number;
|
|
22
22
|
} = {
|
|
23
23
|
id: string | number;
|
|
24
|
-
}>(req: PayloadRequest,
|
|
24
|
+
}>(req: PayloadRequest, { options }: EndpointContext<TUser>): Promise<Response>;
|
|
@@ -2,6 +2,7 @@ import { resultsMetadata, newestSnapshotIds } from '../db/snapshots.js';
|
|
|
2
2
|
import { pooledExecutor } from '../db/executor.js';
|
|
3
3
|
import { routeId } from './routeId.js';
|
|
4
4
|
import { isClickSource } from '../goals/key.js';
|
|
5
|
+
import { browserWritableMetric } from '../events/writable.js';
|
|
5
6
|
const headers = {
|
|
6
7
|
'Cache-Control': 'no-store'
|
|
7
8
|
};
|
|
@@ -53,7 +54,7 @@ export async function readSnapshots(req, ids, { per = 'phase', decisionId, serie
|
|
|
53
54
|
numeric: true
|
|
54
55
|
}));
|
|
55
56
|
}
|
|
56
|
-
export async function handleResults(req,
|
|
57
|
+
export async function handleResults(req, { options }) {
|
|
57
58
|
const id = routeId(req);
|
|
58
59
|
if (id === undefined) return resultsError(404, 'not-found', 'Experiment not found');
|
|
59
60
|
const params = new URL(req.url ?? 'http://localhost').searchParams;
|
|
@@ -81,12 +82,15 @@ export async function handleResults(req, _ctx) {
|
|
|
81
82
|
phaseKind: record.phaseKind,
|
|
82
83
|
startedAt: String(record.startedAt),
|
|
83
84
|
endedAt: record.endedAt == null ? null : String(record.endedAt),
|
|
85
|
+
...record.phaseKind === 'test' && record.analysis?.plannedDurationDays != null ? {
|
|
86
|
+
plannedDurationDays: record.analysis.plannedDurationDays
|
|
87
|
+
} : {},
|
|
84
88
|
arms: record.arms.map(({ key, label, kind })=>({
|
|
85
89
|
key,
|
|
86
90
|
label,
|
|
87
91
|
kind
|
|
88
92
|
})),
|
|
89
|
-
metrics: record.metricDefinitions.map(({ metricId, name, kind, role, source, resolvedCap, historyUnits, capNotice })=>({
|
|
93
|
+
metrics: record.metricDefinitions.map(({ metricId, name, kind, role, source, browserWritable, resolvedCap, historyUnits, capNotice })=>({
|
|
90
94
|
metricId,
|
|
91
95
|
name,
|
|
92
96
|
kind,
|
|
@@ -94,6 +98,9 @@ export async function handleResults(req, _ctx) {
|
|
|
94
98
|
...isClickSource(source) ? {
|
|
95
99
|
clickGoal: true
|
|
96
100
|
} : {},
|
|
101
|
+
...browserWritable === true || browserWritableMetric(source, options) ? {
|
|
102
|
+
browserWritable: true
|
|
103
|
+
} : {},
|
|
97
104
|
...resolvedCap === undefined ? {} : {
|
|
98
105
|
resolvedCap
|
|
99
106
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PayloadRequest } from 'payload';
|
|
2
2
|
import type { DocId } from '../types/contracts.js';
|
|
3
|
-
/**
|
|
4
|
-
export declare function experimentId(req: PayloadRequest, value: unknown): DocId | undefined;
|
|
3
|
+
/** Use the stored spelling for PostgreSQL IDs before any lock or comparison. */
|
|
4
|
+
export declare function experimentId(req: PayloadRequest, value: unknown, source?: 'route' | 'payload'): DocId | undefined;
|
|
5
5
|
export declare function routeId(req: PayloadRequest): DocId | undefined;
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Use the stored spelling for PostgreSQL IDs before any lock or comparison. */ export function experimentId(req, value, source = 'route') {
|
|
2
2
|
if (typeof value !== 'string' && typeof value !== 'number') return undefined;
|
|
3
3
|
const id = String(value);
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
if (
|
|
4
|
+
const customIDType = req.payload.collections?.['xp-experiments']?.customIDType;
|
|
5
|
+
const idType = customIDType ?? req.payload.db.defaultIDType;
|
|
6
|
+
if (idType !== 'number') {
|
|
7
|
+
// The Postgres adapter reports a native UUID as text. Custom text IDs are opaque.
|
|
8
|
+
const uuid = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
|
|
9
|
+
return customIDType !== 'text' && uuid.test(id) ? id.toLowerCase() : id;
|
|
10
|
+
}
|
|
11
|
+
// Native Payload deletes already use Number() for their ID lookup.
|
|
12
|
+
if (source === 'route' && !/^\d+$/.test(id)) return undefined;
|
|
7
13
|
const number = Number(id);
|
|
8
14
|
// Payload's Postgres serial ids are int4; larger values would reach SQL and fail with 22003.
|
|
9
|
-
return Number.
|
|
15
|
+
return Number.isInteger(number) && number >= -2_147_483_648 && number <= 2_147_483_647 ? number : undefined;
|
|
10
16
|
}
|
|
11
17
|
export function routeId(req) {
|
|
12
18
|
return experimentId(req, req.routeParams?.id);
|
|
@@ -1,8 +1,28 @@
|
|
|
1
|
+
import { BLOCK_SLOTS } from '../blocks/model.js';
|
|
1
2
|
import { checkStart } from '../transitions/checkStart.js';
|
|
2
3
|
import { loadStartInputsBatch } from '../transitions/preflightData.js';
|
|
3
4
|
import { readSnapshots, resultsError } from './results.js';
|
|
4
5
|
import { experimentId } from './routeId.js';
|
|
5
6
|
import { sanitizeReadinessDetail } from './sanitizeReadinessDetail.js';
|
|
7
|
+
/** Use the batch scan's saved drafts. As in preflight, every matching block on
|
|
8
|
+
* a page in the affected language needs content before suggesting publication. */ function draftReadySlots(placements) {
|
|
9
|
+
const location = (row)=>JSON.stringify([
|
|
10
|
+
row.collection,
|
|
11
|
+
String(row.id),
|
|
12
|
+
row.locale
|
|
13
|
+
]);
|
|
14
|
+
const filledInDraft = new Map();
|
|
15
|
+
for (const row of placements){
|
|
16
|
+
if (row.published) continue;
|
|
17
|
+
const id = location(row);
|
|
18
|
+
const filled = filledInDraft.get(id) ?? BLOCK_SLOTS;
|
|
19
|
+
filledInDraft.set(id, filled.filter((slot)=>row.slots[slot] > 0));
|
|
20
|
+
}
|
|
21
|
+
return BLOCK_SLOTS.filter((slot)=>{
|
|
22
|
+
const affected = placements.filter((row)=>row.published && !(row.slots[slot] > 0));
|
|
23
|
+
return affected.length > 0 && affected.every((row)=>filledInDraft.get(location(row))?.includes(slot));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
6
26
|
export async function handleSummary(req, { options }) {
|
|
7
27
|
let ids;
|
|
8
28
|
try {
|
|
@@ -43,17 +63,30 @@ export async function handleSummary(req, { options }) {
|
|
|
43
63
|
headline: snapshot.verdict.headline
|
|
44
64
|
},
|
|
45
65
|
...snapshot.health ? {
|
|
46
|
-
health: snapshot.health.slice(0, 100).map((item)=>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
health: snapshot.health.slice(0, 100).map((item)=>{
|
|
67
|
+
switch(item.code){
|
|
68
|
+
case 'placement-unchecked':
|
|
69
|
+
return {
|
|
70
|
+
code: item.code,
|
|
71
|
+
detail: sanitizeReadinessDetail(item.code, item.detail)
|
|
72
|
+
};
|
|
73
|
+
case 'goal-in-some-versions':
|
|
74
|
+
return {
|
|
75
|
+
code: item.code,
|
|
76
|
+
metricId: item.metricId,
|
|
77
|
+
name: item.name.slice(0, 128)
|
|
78
|
+
};
|
|
79
|
+
case 'rapid-browser-events':
|
|
80
|
+
return {
|
|
81
|
+
code: item.code
|
|
82
|
+
};
|
|
83
|
+
default:
|
|
84
|
+
return {
|
|
85
|
+
code: item.code,
|
|
86
|
+
path: item.path.slice(0, 128)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
})
|
|
57
90
|
} : {}
|
|
58
91
|
} : {
|
|
59
92
|
exposures: 0,
|
|
@@ -90,7 +123,8 @@ export async function handleSummary(req, { options }) {
|
|
|
90
123
|
response[key].ready = !!input && checks.every((check)=>check.ok);
|
|
91
124
|
const next = checks.find((check)=>!check.ok && !check.warning);
|
|
92
125
|
if (next) {
|
|
93
|
-
const
|
|
126
|
+
const draftReady = next.code === 'empty-slot' && input?.placements ? draftReadySlots(input.placements) : undefined;
|
|
127
|
+
const detail = sanitizeReadinessDetail(next.code, next.detail, draftReady);
|
|
94
128
|
response[key].next = {
|
|
95
129
|
code: next.code,
|
|
96
130
|
...detail === undefined ? {} : {
|