@delmaredigital/payload-experiments 0.4.0-rc.1 → 0.4.0-rc.11
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 +284 -772
- package/dist/admin/LayerUsage.js +1 -1
- package/dist/admin/MetricSourceSelect.js +12 -5
- package/dist/admin/PlacementStatus.js +1 -1
- package/dist/admin/TestsDashboardCards.d.ts +1 -0
- package/dist/admin/TestsDashboardCards.js +5 -9
- package/dist/admin/TestsNavLink.d.ts +1 -0
- package/dist/admin/TestsNavLink.js +5 -11
- package/dist/admin/blocks/BlockPanel.d.ts +1 -0
- package/dist/admin/blocks/BlockPanel.js +129 -37
- package/dist/admin/blocks/TestBlockField.js +3 -3
- package/dist/admin/blocks/formApi.d.ts +3 -0
- package/dist/admin/blocks/formApi.js +10 -4
- package/dist/admin/blocks/inject.js +1 -0
- package/dist/admin/blocks/model.d.ts +3 -2
- package/dist/admin/blocks/model.js +10 -6
- package/dist/admin/blocks/statusCache.d.ts +2 -0
- package/dist/admin/blocks/statusCache.js +12 -3
- package/dist/admin/components/RootViewMessage.js +1 -1
- package/dist/admin/copy/blocks.d.ts +21 -1
- package/dist/admin/copy/blocks.js +40 -6
- package/dist/admin/copy/goals.d.ts +21 -9
- package/dist/admin/copy/goals.js +28 -11
- package/dist/admin/copy/newTest.d.ts +7 -7
- package/dist/admin/copy/newTest.js +10 -7
- package/dist/admin/goals/XpGoalField.d.ts +2 -0
- package/dist/admin/goals/XpGoalField.js +156 -114
- package/dist/admin/goals/xpGoalField.css +47 -0
- package/dist/admin/pageCollections.d.ts +1 -0
- package/dist/admin/pageCollections.js +3 -0
- package/dist/admin/paths.d.ts +3 -0
- package/dist/admin/paths.js +3 -0
- package/dist/admin/placementStatus.model.js +1 -1
- package/dist/admin/status.model.js +1 -1
- package/dist/admin/surface/ResultsRoute.d.ts +2 -1
- package/dist/admin/surface/ResultsRoute.js +20 -24
- package/dist/admin/surface/SurfaceShell.d.ts +4 -2
- package/dist/admin/surface/SurfaceShell.js +29 -4
- package/dist/admin/surface/TestRowMenu.d.ts +13 -0
- package/dist/admin/surface/TestRowMenu.js +163 -0
- package/dist/admin/surface/TestsHome.d.ts +5 -3
- package/dist/admin/surface/TestsHome.js +273 -58
- package/dist/admin/surface/TestsSurface.js +8 -7
- 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 +2 -1
- package/dist/admin/surface/goals/GoalForm.js +342 -212
- package/dist/admin/surface/goals/GoalsList.d.ts +1 -1
- package/dist/admin/surface/goals/GoalsList.js +107 -37
- package/dist/admin/surface/goals/data.d.ts +2 -0
- package/dist/admin/surface/goals/data.js +11 -2
- package/dist/admin/surface/goals/goals.css +9 -1
- package/dist/admin/surface/goals/goals.model.d.ts +12 -2
- package/dist/admin/surface/goals/goals.model.js +39 -1
- package/dist/admin/surface/home.model.d.ts +10 -8
- package/dist/admin/surface/home.model.js +27 -22
- package/dist/admin/surface/newTest/NewTest.d.ts +4 -4
- package/dist/admin/surface/newTest/NewTest.js +149 -118
- package/dist/admin/surface/newTest/PageWizard.d.ts +5 -2
- package/dist/admin/surface/newTest/PageWizard.js +115 -80
- package/dist/admin/surface/newTest/newTest.css +28 -9
- package/dist/admin/surface/results/ResultsHeader.d.ts +3 -3
- package/dist/admin/surface/results/ResultsHeader.js +115 -83
- package/dist/admin/surface/surface.css +29 -0
- package/dist/admin/surface/test/TestPage.d.ts +1 -2
- package/dist/admin/surface/test/TestPage.js +44 -152
- package/dist/admin/surface/useXpStepNav.d.ts +11 -0
- package/dist/admin/surface/useXpStepNav.js +14 -0
- package/dist/admin/theme.css +2 -0
- package/dist/admin/views/CollectionListRedirect.d.ts +1 -0
- package/dist/admin/views/CollectionListRedirect.js +1 -1
- package/dist/admin/views/ExperimentsRootView.js +18 -165
- package/dist/admin/views/GoalEditRedirect.d.ts +4 -0
- package/dist/admin/views/GoalEditRedirect.js +14 -0
- package/dist/admin/views/GoalsCollectionListView.d.ts +2 -0
- package/dist/admin/views/GoalsCollectionListView.js +4 -0
- package/dist/admin/views/TestsCollectionListView.d.ts +2 -0
- package/dist/admin/views/TestsCollectionListView.js +4 -0
- package/dist/admin/views/TestsNavLinkServer.d.ts +1 -0
- package/dist/admin/views/TestsNavLinkServer.js +2 -2
- package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
- package/dist/admin/views/TestsSurfaceClient.js +35 -0
- package/dist/admin/views/buildSurfaceProps.d.ts +8 -0
- package/dist/admin/views/buildSurfaceProps.js +102 -0
- package/dist/admin/views/renderCollectionList.d.ts +2 -0
- package/dist/admin/views/renderCollectionList.js +34 -0
- package/dist/admin/views/renderTestsSurface.d.ts +3 -0
- package/dist/admin/views/renderTestsSurface.js +34 -0
- package/dist/blocks/bindings.js +8 -14
- package/dist/blocks/createExperimentBlock.js +1 -1
- package/dist/blocks/formState.js +2 -2
- package/dist/blocks/placementLanguages.d.ts +7 -0
- package/dist/blocks/placementLanguages.js +27 -0
- package/dist/blocks/placementLocale.d.ts +37 -0
- package/dist/blocks/placementLocale.js +270 -0
- package/dist/collections/experiments/config.js +17 -8
- 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 +28 -9
- 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/appends.d.ts +13 -0
- package/dist/db/appends.js +49 -0
- package/dist/db/bulkPlacementRemoval.d.ts +30 -0
- package/dist/db/bulkPlacementRemoval.js +111 -0
- 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/placements.d.ts +2 -0
- package/dist/db/placements.js +8 -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/contentLocale.d.ts +6 -0
- package/dist/endpoints/contentLocale.js +15 -0
- package/dist/endpoints/deleteImpact.d.ts +6 -0
- package/dist/endpoints/deleteImpact.js +207 -0
- package/dist/endpoints/duplicateOriginal.d.ts +38 -0
- package/dist/endpoints/duplicateOriginal.js +407 -0
- package/dist/endpoints/editorSurface.d.ts +3 -0
- package/dist/endpoints/editorSurface.js +31 -0
- package/dist/endpoints/events.js +103 -39
- package/dist/endpoints/index.js +57 -9
- package/dist/endpoints/pages.js +247 -64
- package/dist/endpoints/placementStatus.js +13 -5
- package/dist/endpoints/preflight.d.ts +1 -1
- package/dist/endpoints/preflight.js +17 -2
- package/dist/endpoints/results.d.ts +1 -1
- package/dist/endpoints/results.js +6 -2
- package/dist/endpoints/routeId.d.ts +2 -2
- package/dist/endpoints/routeId.js +11 -5
- package/dist/endpoints/summary.js +46 -12
- package/dist/endpoints/testVersion.d.ts +2 -0
- package/dist/endpoints/testVersion.js +38 -0
- package/dist/endpoints/transitions.js +41 -29
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +8 -0
- package/dist/events/request.d.ts +6 -2
- package/dist/events/request.js +35 -8
- package/dist/events/rows.d.ts +1 -1
- package/dist/events/rows.js +24 -8
- package/dist/events/writable.d.ts +9 -0
- package/dist/events/writable.js +13 -0
- package/dist/exports/adminClient.d.ts +1 -1
- package/dist/exports/adminClient.js +1 -1
- package/dist/exports/adminRsc.d.ts +3 -0
- package/dist/exports/adminRsc.js +3 -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/fields/xpGoal.js +3 -15
- package/dist/goals/fairness.d.ts +1 -1
- package/dist/goals/fairness.js +44 -35
- package/dist/goals/picker/clickGoalPicker.model.d.ts +8 -1
- package/dist/goals/picker/clickGoalPicker.model.js +20 -2
- package/dist/goals/picker/copy.d.ts +6 -2
- package/dist/goals/picker/copy.js +11 -2
- package/dist/goals/picker/useClickGoalPicker.d.ts +1 -1
- package/dist/goals/picker/useClickGoalPicker.js +4 -2
- package/dist/goals/sourceLabel.d.ts +2 -0
- package/dist/goals/sourceLabel.js +4 -0
- package/dist/goals/validate.d.ts +3 -0
- package/dist/goals/validate.js +15 -0
- package/dist/hooks/blockRemovalRule.d.ts +30 -0
- package/dist/hooks/blockRemovalRule.js +165 -0
- package/dist/hooks/hostHook.js +6 -2
- package/dist/hooks/pageGuard.d.ts +27 -2
- package/dist/hooks/pageGuard.js +213 -45
- package/dist/hooks/puckGoals.d.ts +5 -0
- package/dist/hooks/puckGoals.js +62 -0
- package/dist/hooks/puckNestedTests.d.ts +8 -0
- package/dist/hooks/puckNestedTests.js +36 -0
- package/dist/hooks/trackPageCopies.d.ts +11 -0
- package/dist/hooks/trackPageCopies.js +7 -0
- package/dist/lib/fetchAllDocs.d.ts +1 -1
- package/dist/lib/placementPages.d.ts +10 -0
- package/dist/{admin/previewLinks.model.js → lib/placementPages.js} +10 -5
- package/dist/manifest/compile.d.ts +2 -1
- package/dist/manifest/compile.js +13 -6
- package/dist/onInit.js +36 -0
- package/dist/options.d.ts +2 -0
- package/dist/options.js +23 -2
- package/dist/plugin.js +70 -21
- package/dist/proxy/pageNavigation.d.ts +4 -0
- package/dist/proxy/pageNavigation.js +28 -0
- package/dist/proxy/resolve.js +52 -25
- package/dist/puck/ExperimentPicker.d.ts +2 -1
- package/dist/puck/ExperimentPicker.js +62 -40
- package/dist/puck/ExperimentSlot.js +3 -1
- package/dist/puck/copy.d.ts +5 -1
- package/dist/puck/copy.js +5 -1
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +25 -0
- package/dist/puck/editor/ConfigureTestDrawer.js +150 -0
- package/dist/puck/editor/CreateExperimentDrawer.d.ts +12 -2
- package/dist/puck/editor/CreateExperimentDrawer.js +89 -21
- package/dist/puck/editor/EditorControls.d.ts +14 -0
- package/dist/puck/editor/EditorControls.js +99 -0
- package/dist/puck/editor/ExperimentSlotEditor.d.ts +2 -1
- package/dist/puck/editor/ExperimentSlotEditor.js +1007 -182
- package/dist/puck/editor/LeftoverVersions.d.ts +15 -0
- package/dist/puck/editor/LeftoverVersions.js +79 -0
- package/dist/puck/editor/PlacementNotice.d.ts +8 -0
- package/dist/puck/editor/PlacementNotice.js +22 -0
- package/dist/puck/editor/QuickTestActions.d.ts +6 -0
- package/dist/puck/editor/QuickTestActions.js +72 -0
- package/dist/puck/editor/ResultsReadout.d.ts +4 -1
- package/dist/puck/editor/ResultsReadout.js +35 -19
- package/dist/puck/editor/VersionBuilder.d.ts +67 -12
- package/dist/puck/editor/VersionBuilder.js +560 -231
- package/dist/puck/editor/armWrites.d.ts +11 -2
- package/dist/puck/editor/armWrites.js +43 -4
- package/dist/puck/editor/armsCache.d.ts +3 -1
- package/dist/puck/editor/armsCache.js +20 -4
- package/dist/puck/editor/blockClipboard.d.ts +16 -0
- package/dist/puck/editor/blockClipboard.js +20 -0
- package/dist/puck/editor/cloneSlot.d.ts +2 -0
- package/dist/puck/editor/cloneSlot.js +7 -0
- package/dist/puck/editor/copy.d.ts +65 -20
- package/dist/puck/editor/copy.js +73 -21
- package/dist/puck/editor/createTest.d.ts +3 -0
- package/dist/puck/editor/createTest.js +33 -0
- package/dist/puck/editor/editor.chrome.css +200 -20
- package/dist/puck/editor/editor.css +338 -25
- package/dist/puck/editor/editor.model.d.ts +17 -1
- package/dist/puck/editor/editor.model.js +61 -4
- package/dist/puck/editor/editorSurface.d.ts +10 -0
- package/dist/puck/editor/editorSurface.js +65 -0
- package/dist/puck/editor/experimentOutlinePlugin.js +96 -28
- package/dist/puck/editor/localPlacements.d.ts +5 -0
- package/dist/puck/editor/localPlacements.js +43 -0
- package/dist/puck/editor/outlineVersion.d.ts +5 -0
- package/dist/puck/editor/outlineVersion.js +36 -0
- package/dist/puck/editor/placementsCache.d.ts +60 -0
- package/dist/puck/editor/placementsCache.js +263 -0
- package/dist/puck/editor/sidebar.d.ts +8 -0
- package/dist/puck/editor/sidebar.js +74 -0
- package/dist/puck/editor/usePageSaveReadiness.d.ts +6 -0
- package/dist/puck/editor/usePageSaveReadiness.js +31 -0
- package/dist/puck/editor/usePlacementNotice.d.ts +3 -0
- package/dist/puck/editor/usePlacementNotice.js +15 -0
- package/dist/puck/editor/xpGoalPuckEditorField.js +105 -86
- package/dist/puck/experimentSlotField.d.ts +3 -0
- package/dist/puck/experimentSlotField.js +15 -4
- package/dist/puck/experimentSlug.d.ts +2 -0
- package/dist/puck/experimentSlug.js +3 -0
- package/dist/puck/nestedTestCopy.d.ts +8 -0
- package/dist/puck/nestedTestCopy.js +22 -0
- package/dist/puck/nestedTests.d.ts +17 -0
- package/dist/puck/nestedTests.js +30 -0
- package/dist/puck/slotConfig.d.ts +2 -2
- package/dist/puck/slotConfig.js +18 -5
- package/dist/puck/visibility.d.ts +20 -0
- package/dist/puck/visibility.js +81 -0
- 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 +1 -1
- package/dist/results/verdict.js +9 -7
- 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 +22 -2
- package/dist/server/getAssignments.js +11 -10
- package/dist/server/recordContentChange.d.ts +1 -1
- package/dist/server/recordContentChange.js +48 -22
- package/dist/server/resolveExperimentBlocks.js +2 -4
- package/dist/server/resolveExperimentData.js +8 -8
- 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/{admin → testSurface}/PreviewLinks.d.ts +2 -1
- package/dist/{admin → testSurface}/PreviewLinks.js +9 -5
- package/dist/testSurface/actions/DecideDialog.d.ts +17 -0
- package/dist/testSurface/actions/DecideDialog.js +222 -0
- package/dist/testSurface/actions/LifecycleAction.d.ts +17 -0
- package/dist/testSurface/actions/LifecycleAction.js +107 -0
- package/dist/{admin → testSurface}/actions/MakeContentResult.d.ts +4 -3
- package/dist/{admin → testSurface}/actions/MakeContentResult.js +10 -2
- package/dist/{admin → testSurface}/actions/actions.model.d.ts +13 -5
- package/dist/testSurface/actions/actions.model.js +123 -0
- package/dist/{admin → testSurface}/actions/decide.model.d.ts +1 -0
- package/dist/{admin → testSurface}/actions/decide.model.js +1 -0
- package/dist/{admin → testSurface}/allocation.model.js +6 -3
- package/dist/{admin → testSurface}/api.d.ts +20 -7
- package/dist/{admin → testSurface}/api.js +72 -22
- package/dist/testSurface/contentLocaleURL.d.ts +2 -0
- package/dist/testSurface/contentLocaleURL.js +3 -0
- package/dist/{admin → testSurface}/copy/actions.d.ts +37 -14
- package/dist/{admin → testSurface}/copy/actions.js +40 -17
- package/dist/{admin → testSurface}/copy/advanced.d.ts +10 -0
- package/dist/{admin → testSurface}/copy/advanced.js +10 -0
- package/dist/{admin → testSurface}/copy/arms.d.ts +1 -1
- package/dist/{admin → testSurface}/copy/arms.js +1 -1
- package/dist/{admin → testSurface}/copy/audience.d.ts +4 -3
- package/dist/{admin → testSurface}/copy/audience.js +5 -4
- package/dist/{admin → testSurface}/copy/common.d.ts +15 -6
- package/dist/{admin → testSurface}/copy/common.js +20 -10
- package/dist/testSurface/copy/languages.d.ts +12 -0
- package/dist/testSurface/copy/languages.js +8 -0
- package/dist/{admin → testSurface}/copy/metrics.d.ts +7 -0
- package/dist/testSurface/copy/metrics.js +18 -0
- package/dist/testSurface/copy/pages.d.ts +84 -0
- package/dist/testSurface/copy/pages.js +90 -0
- package/dist/{admin → testSurface}/copy/readiness.d.ts +40 -6
- package/dist/{admin → testSurface}/copy/readiness.js +54 -9
- package/dist/{admin → testSurface}/copy/recommendation.d.ts +4 -4
- package/dist/{admin → testSurface}/copy/recommendation.js +4 -4
- package/dist/{admin → testSurface}/copy/results.d.ts +19 -12
- package/dist/{admin → testSurface}/copy/results.js +21 -12
- package/dist/testSurface/copy/review.d.ts +20 -0
- package/dist/testSurface/copy/review.js +21 -0
- package/dist/{admin → testSurface}/copy/setting.d.ts +1 -2
- package/dist/{admin → testSurface}/copy/setting.js +1 -2
- package/dist/{admin → testSurface}/copy/surface.d.ts +11 -2
- package/dist/{admin → testSurface}/copy/surface.js +14 -11
- package/dist/{admin → testSurface}/copy/testPage.d.ts +61 -12
- package/dist/testSurface/copy/testPage.js +168 -0
- package/dist/testSurface/format/adminURL.d.ts +7 -0
- package/dist/testSurface/format/adminURL.js +9 -0
- package/dist/{admin → testSurface}/format/date.d.ts +1 -0
- package/dist/testSurface/format/date.js +21 -0
- package/dist/{admin → testSurface}/labels.d.ts +1 -2
- package/dist/{admin → testSurface}/labels.js +2 -3
- package/dist/{admin → testSurface}/lockedNotice.model.d.ts +2 -0
- package/dist/{admin → testSurface}/lockedNotice.model.js +31 -0
- package/dist/testSurface/placementLabel.d.ts +8 -0
- package/dist/testSurface/placementLabel.js +24 -0
- package/dist/{admin → testSurface}/placements/placementLabels.d.ts +2 -0
- package/dist/{admin → testSurface}/placements/placementLabels.js +3 -2
- package/dist/{admin → testSurface}/previewLinks.model.d.ts +1 -6
- package/dist/testSurface/previewLinks.model.js +4 -0
- package/dist/testSurface/readPreflight.d.ts +13 -0
- package/dist/testSurface/readPreflight.js +44 -0
- package/dist/testSurface/readinessRead.d.ts +53 -0
- package/dist/testSurface/readinessRead.js +50 -0
- package/dist/{admin → testSurface}/results/VerdictHero.d.ts +2 -1
- package/dist/{admin → testSurface}/results/VerdictHero.js +5 -1
- package/dist/testSurface/results/results.css +64 -0
- package/dist/{admin → testSurface}/results/results.model.d.ts +3 -2
- package/dist/{admin → testSurface}/results/results.model.js +16 -11
- package/dist/{admin → testSurface}/surface/contracts.d.ts +17 -3
- package/dist/testSurface/surface/editorPlacement.d.ts +26 -0
- package/dist/testSurface/surface/editorPlacement.js +78 -0
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +9 -0
- package/dist/testSurface/surface/pageBlock/parts.js +107 -0
- package/dist/testSurface/surface/pagePicker/CopyRoute.d.ts +13 -0
- package/dist/testSurface/surface/pagePicker/CopyRoute.js +273 -0
- package/dist/testSurface/surface/pagePicker/PageCombobox.d.ts +21 -0
- package/dist/testSurface/surface/pagePicker/PageCombobox.js +498 -0
- package/dist/testSurface/surface/pagePicker/pagePicker.css +73 -0
- package/dist/{admin → testSurface}/surface/pagePicker/pagePicker.model.d.ts +7 -3
- package/dist/{admin → testSurface}/surface/pagePicker/pagePicker.model.js +17 -2
- package/dist/{admin → testSurface}/surface/readiness/ActionDialogs.d.ts +9 -5
- package/dist/testSurface/surface/readiness/ActionDialogs.js +372 -0
- package/dist/{admin → testSurface}/surface/readiness/Banner.d.ts +4 -3
- package/dist/testSurface/surface/readiness/Banner.js +198 -0
- package/dist/testSurface/surface/readiness/BlockerList.d.ts +11 -0
- package/dist/testSurface/surface/readiness/BlockerList.js +31 -0
- package/dist/testSurface/surface/readiness/SaveStatus.d.ts +13 -0
- package/dist/testSurface/surface/readiness/SaveStatus.js +67 -0
- package/dist/{admin → testSurface}/surface/readiness/parts.js +0 -2
- package/dist/{admin → testSurface}/surface/readiness/readiness.model.d.ts +28 -2
- package/dist/testSurface/surface/readiness/readiness.model.js +377 -0
- package/dist/testSurface/surface/readiness/useTransition.d.ts +16 -0
- package/dist/testSurface/surface/readiness/useTransition.js +141 -0
- package/dist/{admin → testSurface}/surface/results/ReleasePages.d.ts +6 -3
- package/dist/{admin → testSurface}/surface/results/ReleasePages.js +40 -40
- package/dist/{admin → testSurface}/surface/results/ResultsBody.d.ts +11 -4
- package/dist/{admin → testSurface}/surface/results/ResultsBody.js +207 -104
- package/dist/{admin → testSurface}/surface/results/recommendation.model.js +3 -3
- package/dist/{admin → testSurface}/surface/results/useResults.d.ts +26 -8
- package/dist/{admin → testSurface}/surface/results/useResults.js +3 -2
- package/dist/{admin → testSurface}/surface/setting/parts.js +89 -46
- package/dist/testSurface/surface/setting/setting.css +18 -0
- package/dist/{admin → testSurface}/surface/test/AdvancedSection.js +12 -4
- package/dist/testSurface/surface/test/DeleteTest.d.ts +23 -0
- package/dist/testSurface/surface/test/DeleteTest.js +270 -0
- package/dist/testSurface/surface/test/GoalSection.d.ts +4 -0
- package/dist/{admin → testSurface}/surface/test/GoalSection.js +119 -89
- package/dist/testSurface/surface/test/LengthSection.d.ts +2 -0
- package/dist/{admin → testSurface}/surface/test/LengthSection.js +25 -14
- package/dist/{admin → testSurface}/surface/test/PageHoldout.d.ts +1 -1
- package/dist/{admin → testSurface}/surface/test/PageHoldout.js +11 -8
- package/dist/{admin → testSurface}/surface/test/Rail.js +7 -4
- package/dist/{admin → testSurface}/surface/test/ReadinessBar.d.ts +2 -1
- package/dist/{admin → testSurface}/surface/test/ReadinessBar.js +4 -11
- package/dist/{admin → testSurface}/surface/test/Section.d.ts +3 -1
- package/dist/testSurface/surface/test/Section.js +88 -0
- package/dist/{admin → testSurface}/surface/test/TargetingSection.js +87 -12
- package/dist/testSurface/surface/test/TestSurface.d.ts +19 -0
- package/dist/testSurface/surface/test/TestSurface.js +265 -0
- package/dist/testSurface/surface/test/VersionsSection.d.ts +5 -0
- package/dist/testSurface/surface/test/VersionsSection.js +301 -0
- package/dist/{admin → testSurface}/surface/test/fields.d.ts +33 -9
- package/dist/testSurface/surface/test/fields.js +300 -0
- package/dist/{admin → testSurface}/surface/test/pageParts.js +30 -44
- package/dist/testSurface/surface/test/testPage.css +111 -0
- package/dist/{admin → testSurface}/surface/test/testPage.model.d.ts +1 -0
- package/dist/{admin → testSurface}/surface/test/testPage.model.js +6 -0
- package/dist/{admin → testSurface}/surface/testDocument.model.d.ts +3 -0
- package/dist/{admin → testSurface}/surface/testDocument.model.js +4 -1
- package/dist/testSurface/surface/useTestDocument.d.ts +60 -0
- package/dist/testSurface/surface/useTestDocument.js +782 -0
- package/dist/testSurface/surface/watchTestDocument.d.ts +15 -0
- package/dist/testSurface/surface/watchTestDocument.js +181 -0
- package/dist/testSurface/surfaceUrls.d.ts +8 -0
- package/dist/testSurface/surfaceUrls.js +23 -0
- package/dist/{admin → testSurface}/useApi.d.ts +21 -5
- package/dist/testSurface/useOnTestReturn.d.ts +2 -0
- package/dist/testSurface/useOnTestReturn.js +27 -0
- package/dist/testSurface/useReadinessPolling.d.ts +3 -0
- package/dist/testSurface/useReadinessPolling.js +26 -0
- 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 +6 -1
- package/dist/transitions/checkStart.js +133 -17
- package/dist/transitions/contentFields.js +9 -5
- package/dist/transitions/decide.d.ts +1 -1
- package/dist/transitions/decide.js +6 -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 +41 -17
- package/dist/transitions/nestedPlacementNames.d.ts +5 -0
- package/dist/transitions/nestedPlacementNames.js +32 -0
- package/dist/transitions/pageAddress.d.ts +6 -0
- package/dist/transitions/pageAddress.js +71 -0
- package/dist/transitions/pageVersions.js +3 -1
- package/dist/transitions/phaseRecord.d.ts +2 -0
- package/dist/transitions/phaseRecord.js +5 -0
- package/dist/transitions/placementInteractions.d.ts +3 -3
- package/dist/transitions/placementInteractions.js +16 -12
- package/dist/transitions/placements.d.ts +54 -8
- package/dist/transitions/placements.js +304 -81
- package/dist/transitions/preflightData.d.ts +5 -3
- package/dist/transitions/preflightData.js +137 -40
- package/dist/transitions/releaseHoldout.d.ts +2 -1
- package/dist/transitions/releaseHoldout.js +3 -1
- package/dist/transitions/releasePages.d.ts +2 -1
- package/dist/transitions/releasePages.js +3 -1
- package/dist/transitions/resolveCaps.d.ts +2 -4
- package/dist/transitions/start.d.ts +6 -8
- package/dist/transitions/start.js +72 -35
- package/dist/transitions/startReads.d.ts +7 -0
- package/dist/transitions/startReads.js +28 -0
- package/dist/transitions/stop.d.ts +2 -1
- package/dist/transitions/stop.js +3 -2
- package/dist/types/contracts.d.ts +15 -3
- package/dist/types/endpoints.d.ts +121 -17
- package/dist/types/puck.d.ts +1 -0
- package/dist/types/runtime.d.ts +15 -9
- package/dist/types/snapshot.d.ts +2 -0
- package/dist/types/surface.d.ts +9 -9
- package/dist/ui/Button.js +2 -2
- package/dist/ui/Card.d.ts +2 -1
- package/dist/ui/Card.js +4 -4
- package/dist/ui/ChipsInput.d.ts +8 -1
- package/dist/ui/ChipsInput.js +17 -4
- package/dist/ui/Dialog.d.ts +24 -2
- package/dist/ui/Dialog.js +141 -6
- package/dist/ui/Drawer.d.ts +10 -0
- package/dist/ui/Drawer.js +29 -0
- package/dist/ui/Inputs.d.ts +4 -3
- package/dist/ui/Inputs.js +6 -4
- package/dist/ui/SelectControl.d.ts +33 -0
- package/dist/ui/SelectControl.js +504 -0
- package/dist/ui/Tabs.d.ts +4 -4
- package/dist/ui/Tabs.js +35 -32
- package/dist/ui/ui.css +50 -5
- package/package.json +3 -2
- package/dist/admin/actions/ConfirmDialog.d.ts +0 -19
- package/dist/admin/actions/ConfirmDialog.js +0 -149
- package/dist/admin/actions/DecideDialog.d.ts +0 -10
- package/dist/admin/actions/DecideDialog.js +0 -190
- package/dist/admin/actions/actions.model.js +0 -70
- package/dist/admin/copy/metrics.js +0 -9
- package/dist/admin/copy/pages.d.ts +0 -26
- package/dist/admin/copy/pages.js +0 -26
- package/dist/admin/copy/review.d.ts +0 -17
- package/dist/admin/copy/review.js +0 -17
- package/dist/admin/copy/testPage.js +0 -104
- package/dist/admin/format/date.js +0 -10
- package/dist/admin/results/results.css +0 -64
- package/dist/admin/styles.css +0 -10
- package/dist/admin/styles.d.ts +0 -2
- package/dist/admin/styles.js +0 -3
- package/dist/admin/surface/pageBlock/pageBlock.model.js +0 -8
- package/dist/admin/surface/pageBlock/parts.js +0 -69
- package/dist/admin/surface/pagePicker/CopyRoute.d.ts +0 -6
- package/dist/admin/surface/pagePicker/CopyRoute.js +0 -53
- package/dist/admin/surface/pagePicker/PagePicker.d.ts +0 -10
- package/dist/admin/surface/pagePicker/PagePicker.js +0 -172
- package/dist/admin/surface/readiness/ActionDialogs.js +0 -337
- package/dist/admin/surface/readiness/Banner.js +0 -190
- package/dist/admin/surface/readiness/SaveStatus.d.ts +0 -5
- package/dist/admin/surface/readiness/SaveStatus.js +0 -53
- package/dist/admin/surface/readiness/readiness.model.js +0 -205
- package/dist/admin/surface/readiness/useTransition.d.ts +0 -11
- package/dist/admin/surface/readiness/useTransition.js +0 -35
- package/dist/admin/surface/setting/setting.css +0 -17
- package/dist/admin/surface/test/GoalSection.d.ts +0 -2
- package/dist/admin/surface/test/LengthSection.d.ts +0 -2
- package/dist/admin/surface/test/Section.js +0 -47
- package/dist/admin/surface/test/VersionsSection.d.ts +0 -4
- package/dist/admin/surface/test/VersionsSection.js +0 -247
- package/dist/admin/surface/test/fields.js +0 -216
- package/dist/admin/surface/test/testPage.css +0 -97
- package/dist/admin/surface/useTestDocument.d.ts +0 -32
- package/dist/admin/surface/useTestDocument.js +0 -415
- /package/dist/{admin → testSurface}/allocation.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/arms.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/arms.model.js +0 -0
- /package/dist/{admin → testSurface}/arms/pageTarget.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/pageTarget.model.js +0 -0
- /package/dist/{admin → testSurface}/arms/params.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/params.model.js +0 -0
- /package/dist/{admin → testSurface}/metricSource.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/metricSource.model.js +0 -0
- /package/dist/{admin → testSurface}/placements/placementLabels.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/placements/placementLabels.model.js +0 -0
- /package/dist/{admin → testSurface}/placements/usePlacementLabels.d.ts +0 -0
- /package/dist/{admin → testSurface}/placements/usePlacementLabels.js +0 -0
- /package/dist/{admin → testSurface}/reload.d.ts +0 -0
- /package/dist/{admin → testSurface}/reload.js +0 -0
- /package/dist/{admin → testSurface}/results/CappedCell.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/CappedCell.js +0 -0
- /package/dist/{admin → testSurface}/results/CiChart.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/CiChart.js +0 -0
- /package/dist/{admin → testSurface}/results/DataQualityPanel.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/DataQualityPanel.js +0 -0
- /package/dist/{admin → testSurface}/results/DataTable.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/DataTable.js +0 -0
- /package/dist/{admin → testSurface}/results/StatTile.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/StatTile.js +0 -0
- /package/dist/{admin → testSurface}/results/chart.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/chart.model.js +0 -0
- /package/dist/{admin → testSurface}/results/format.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/format.js +0 -0
- /package/dist/{admin → testSurface}/results/legacy.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/legacy.js +0 -0
- /package/dist/{admin → testSurface}/results/releasePages.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/releasePages.model.js +0 -0
- /package/dist/{admin → testSurface}/results/snapshot.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/snapshot.js +0 -0
- /package/dist/{admin → testSurface}/review/review.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/review/review.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/contracts.js +0 -0
- /package/dist/{admin → testSurface}/surface/pageBlock/pageBlock.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pageBlock/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/recommendation.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/setting/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/setting/setting.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/setting/setting.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/AdvancedSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/Rail.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/TargetingSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/jumpToSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/jumpToSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/pageParts.d.ts +0 -0
- /package/dist/{admin → testSurface}/targeting/targeting.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/targeting/targeting.model.js +0 -0
- /package/dist/{admin → testSurface}/theme.d.ts +0 -0
- /package/dist/{admin → testSurface}/theme.js +0 -0
- /package/dist/{admin → testSurface}/useApi.js +0 -0
package/dist/endpoints/index.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
import { handleDeleteImpact } from './deleteImpact.js';
|
|
2
|
+
import { handleEditorSurface } from './editorSurface.js';
|
|
1
3
|
import { handleClickKeys } from './clickKeys.js';
|
|
2
4
|
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
3
5
|
import { XP_MANIFEST_KEY_HEADER } from '../constants.js';
|
|
4
6
|
import { XpNotImplemented, XpRefusal } from '../errors.js';
|
|
5
|
-
import { readUnitCookie } from '../runtime/cookie.js';
|
|
6
7
|
import { handleManifest } from './manifest.js';
|
|
7
8
|
import { handleEvents } from './events.js';
|
|
8
9
|
import { handleStart, handleAllocate, handleAddMetric, handleStop, handleDecide, handleReleaseHoldout, handleReleasePages, handleMakeContent, handleDismissContentEntry, handleRestoreContentEntry, handleArchive } from './transitions.js';
|
|
9
10
|
import { handlePreflight } from './preflight.js';
|
|
11
|
+
import { handleTestVersion } from './testVersion.js';
|
|
10
12
|
import { handlePreviewToken } from './previewToken.js';
|
|
11
13
|
import { handleResults } from './results.js';
|
|
12
14
|
import { handleRecompute } from './recompute.js';
|
|
13
15
|
import { handleWrapBlock } from './wrapBlock.js';
|
|
16
|
+
import { handleDuplicateOriginal } from './duplicateOriginal.js';
|
|
14
17
|
import { handlePages } from './pages.js';
|
|
15
18
|
import { handlePlacementStatus } from './placementStatus.js';
|
|
16
19
|
import { handleSummary } from './summary.js';
|
|
@@ -24,7 +27,7 @@ export const ROUTES = [
|
|
|
24
27
|
{
|
|
25
28
|
method: 'post',
|
|
26
29
|
path: '/xp/events',
|
|
27
|
-
access: '
|
|
30
|
+
access: 'browserEvents',
|
|
28
31
|
handler: handleEvents
|
|
29
32
|
},
|
|
30
33
|
{
|
|
@@ -93,12 +96,24 @@ export const ROUTES = [
|
|
|
93
96
|
access: 'manage',
|
|
94
97
|
handler: handleArchive
|
|
95
98
|
},
|
|
99
|
+
{
|
|
100
|
+
method: 'get',
|
|
101
|
+
path: '/xp/experiments/:id/delete-impact',
|
|
102
|
+
access: 'manage',
|
|
103
|
+
handler: handleDeleteImpact
|
|
104
|
+
},
|
|
96
105
|
{
|
|
97
106
|
method: 'get',
|
|
98
107
|
path: '/xp/experiments/:id/preflight',
|
|
99
108
|
access: 'manage',
|
|
100
109
|
handler: handlePreflight
|
|
101
110
|
},
|
|
111
|
+
{
|
|
112
|
+
method: 'get',
|
|
113
|
+
path: '/xp/experiments/:id/version',
|
|
114
|
+
access: 'manage',
|
|
115
|
+
handler: handleTestVersion
|
|
116
|
+
},
|
|
102
117
|
{
|
|
103
118
|
method: 'get',
|
|
104
119
|
path: '/xp/experiments/:id/preview-token',
|
|
@@ -141,14 +156,32 @@ export const ROUTES = [
|
|
|
141
156
|
access: 'manage',
|
|
142
157
|
handler: handlePages
|
|
143
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
|
+
},
|
|
144
171
|
{
|
|
145
172
|
method: 'post',
|
|
146
173
|
path: '/xp/placements/status',
|
|
147
174
|
access: 'manage',
|
|
148
175
|
handler: handlePlacementStatus
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
method: 'get',
|
|
179
|
+
path: '/xp/editor-surface',
|
|
180
|
+
access: 'surface',
|
|
181
|
+
handler: handleEditorSurface
|
|
149
182
|
}
|
|
150
183
|
];
|
|
151
|
-
function
|
|
184
|
+
function endpointError(status, code, message, detail) {
|
|
152
185
|
return Response.json({
|
|
153
186
|
errors: [
|
|
154
187
|
{
|
|
@@ -172,6 +205,11 @@ export function buildEndpoints(ctx) {
|
|
|
172
205
|
const handlerContext = {
|
|
173
206
|
options
|
|
174
207
|
};
|
|
208
|
+
const error = (status, code, message, detail)=>{
|
|
209
|
+
const response = endpointError(status, code, message, detail);
|
|
210
|
+
if (route.access === 'surface') response.headers.set('Cache-Control', 'private, no-store');
|
|
211
|
+
return response;
|
|
212
|
+
};
|
|
175
213
|
try {
|
|
176
214
|
if (route.access === 'manage' || route.access === 'readResults') {
|
|
177
215
|
if (!req.user) return error(401, 'unauthenticated', 'Authentication required');
|
|
@@ -179,6 +217,21 @@ export function buildEndpoints(ctx) {
|
|
|
179
217
|
if (await access({
|
|
180
218
|
req
|
|
181
219
|
}) !== true) return error(403, 'forbidden', 'Access denied');
|
|
220
|
+
} else if (route.access === 'surface') {
|
|
221
|
+
if (!req.user) return error(401, 'unauthenticated', 'Authentication required');
|
|
222
|
+
// Match the admin surface: a failed host access check denies that permission.
|
|
223
|
+
const permits = async (access)=>{
|
|
224
|
+
try {
|
|
225
|
+
return await access({
|
|
226
|
+
req
|
|
227
|
+
}) === true;
|
|
228
|
+
} catch {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
const manage = await permits(options.access.manage);
|
|
233
|
+
const read = options.access.readResults ? await permits(options.access.readResults) : manage;
|
|
234
|
+
if (!manage && !read) return error(403, 'forbidden', 'Access denied');
|
|
182
235
|
} else if (route.access === 'manifestKey') {
|
|
183
236
|
const secret = options.runtime.proxyRuntime.secrets[0];
|
|
184
237
|
if (!secret) return error(401, 'unauthenticated', 'Invalid manifest key');
|
|
@@ -188,13 +241,8 @@ export function buildEndpoints(ctx) {
|
|
|
188
241
|
if (!supplied || Buffer.byteLength(supplied) !== Buffer.byteLength(expected) || !timingSafeEqual(Buffer.from(supplied), Buffer.from(expected))) {
|
|
189
242
|
return error(401, 'unauthenticated', 'Invalid manifest key');
|
|
190
243
|
}
|
|
191
|
-
} else {
|
|
192
|
-
const visitorId = readUnitCookie(req.headers, options.runtime.proxyRuntime);
|
|
193
|
-
if (!visitorId) return error(401, 'unauthenticated', 'Invalid unit cookie');
|
|
194
|
-
handlerContext.unit = {
|
|
195
|
-
visitorId
|
|
196
|
-
};
|
|
197
244
|
}
|
|
245
|
+
// The browser events handler checks consent, origin and both possible credentials.
|
|
198
246
|
return await route.handler(req, handlerContext);
|
|
199
247
|
} catch (cause) {
|
|
200
248
|
if (cause instanceof XpRefusal) return error(cause.status, cause.code, cause.message, cause.detail);
|
package/dist/endpoints/pages.js
CHANGED
|
@@ -1,47 +1,63 @@
|
|
|
1
|
+
import { flattenTopLevelFields, formatAdminURL } from 'payload/shared';
|
|
2
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
3
|
+
import { findDraftPageByPath, PAGE_ADDRESS_FIELDS } from '../transitions/pageAddress.js';
|
|
1
4
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
5
|
+
import { blockPageSlugs, hasPuckEditor } from '../options.js';
|
|
2
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
|
+
}
|
|
3
24
|
export async function handlePages(req, { options }) {
|
|
4
25
|
const query = new URL(req.url ?? 'http://xp.invalid').searchParams;
|
|
5
|
-
const
|
|
6
|
-
|
|
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';
|
|
7
34
|
const path = query.get('path');
|
|
8
|
-
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);
|
|
9
36
|
const page = Number(query.get('page') ?? 1);
|
|
10
|
-
if (!Number.isSafeInteger(page) || page < 1 || page >
|
|
11
|
-
const config = req.payload.config.collections.find((entry)=>entry.slug ===
|
|
12
|
-
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';
|
|
13
42
|
const drafts = Boolean(config?.versions && config.versions.drafts);
|
|
14
|
-
|
|
15
|
-
if (path !== null) {
|
|
43
|
+
if (path !== null && collection) {
|
|
16
44
|
const found = await collection.findByPath(path, req);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
hasNextPage: false
|
|
20
|
-
}, {
|
|
21
|
-
headers: {
|
|
22
|
-
'Cache-Control': 'no-store'
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const main = await req.payload.findByID({
|
|
26
|
-
collection: collection.slug,
|
|
45
|
+
const main = found ? await req.payload.findByID({
|
|
46
|
+
collection: slug,
|
|
27
47
|
id: found.id,
|
|
28
48
|
req,
|
|
29
49
|
overrideAccess: false,
|
|
30
50
|
depth: 0,
|
|
31
51
|
draft: false,
|
|
32
52
|
disableErrors: true
|
|
33
|
-
});
|
|
34
|
-
if (!main) return
|
|
53
|
+
}) : await findDraftPageByPath(req, collection, path);
|
|
54
|
+
if (!main) return pageResponse({
|
|
35
55
|
docs: [],
|
|
36
56
|
hasNextPage: false
|
|
37
|
-
}, {
|
|
38
|
-
headers: {
|
|
39
|
-
'Cache-Control': 'no-store'
|
|
40
|
-
}
|
|
41
57
|
});
|
|
42
58
|
const published = !drafts || main._status === 'published';
|
|
43
|
-
const
|
|
44
|
-
collection:
|
|
59
|
+
const row = published ? main : await req.payload.findByID({
|
|
60
|
+
collection: slug,
|
|
45
61
|
id: main.id,
|
|
46
62
|
req,
|
|
47
63
|
overrideAccess: false,
|
|
@@ -49,72 +65,239 @@ export async function handlePages(req, { options }) {
|
|
|
49
65
|
draft: true,
|
|
50
66
|
disableErrors: true
|
|
51
67
|
});
|
|
52
|
-
if (!
|
|
68
|
+
if (!row) return pageResponse({
|
|
53
69
|
docs: [],
|
|
54
70
|
hasNextPage: false
|
|
55
|
-
}, {
|
|
56
|
-
headers: {
|
|
57
|
-
'Cache-Control': 'no-store'
|
|
58
|
-
}
|
|
59
71
|
});
|
|
72
|
+
const doc = reader.read(row, input).doc;
|
|
60
73
|
const rawPath = collection.pathOf(doc);
|
|
61
|
-
return
|
|
74
|
+
if (!found && (!rawPath || normalisePath(rawPath) !== normalisePath(path))) return pageResponse({
|
|
75
|
+
docs: [],
|
|
76
|
+
hasNextPage: false
|
|
77
|
+
});
|
|
78
|
+
return pageResponse({
|
|
62
79
|
docs: [
|
|
63
80
|
{
|
|
64
81
|
id: main.id,
|
|
65
|
-
title: titleField !== 'id'
|
|
82
|
+
title: titleField !== 'id' ? textValue(doc[titleField]) ?? '' : '',
|
|
66
83
|
path: rawPath,
|
|
67
84
|
pathKey: rawPath === null ? null : normalisePath(rawPath),
|
|
68
85
|
published
|
|
69
86
|
}
|
|
70
87
|
],
|
|
71
88
|
hasNextPage: false
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
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
|
|
75
126
|
}
|
|
76
127
|
});
|
|
77
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)
|
|
171
|
+
}
|
|
172
|
+
});
|
|
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
|
+
]));
|
|
78
191
|
const result = await req.payload.find({
|
|
79
|
-
collection:
|
|
192
|
+
collection: slug,
|
|
80
193
|
req,
|
|
81
194
|
overrideAccess: false,
|
|
82
195
|
depth: 0,
|
|
83
|
-
draft:
|
|
84
|
-
sort:
|
|
85
|
-
|
|
196
|
+
draft: readDrafts,
|
|
197
|
+
sort: hasTimestamp ? [
|
|
198
|
+
'-updatedAt',
|
|
199
|
+
'-id'
|
|
200
|
+
] : '-id',
|
|
201
|
+
limit: PAGE_SIZE,
|
|
86
202
|
page,
|
|
87
|
-
where
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
} : undefined
|
|
203
|
+
where,
|
|
204
|
+
// Host callbacks can inspect arbitrary fields. Only picker metadata leaves this endpoint.
|
|
205
|
+
select: hasDocCallbacks ? undefined : metadata
|
|
92
206
|
});
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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,
|
|
98
214
|
req,
|
|
99
215
|
overrideAccess: false,
|
|
100
216
|
depth: 0,
|
|
101
|
-
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
|
+
}
|
|
102
230
|
});
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
+
} : {}
|
|
110
261
|
};
|
|
111
|
-
|
|
112
|
-
|
|
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({
|
|
113
293
|
docs,
|
|
114
|
-
hasNextPage
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
294
|
+
hasNextPage,
|
|
295
|
+
...pageLimitReached ? {
|
|
296
|
+
pageLimitReached
|
|
297
|
+
} : {},
|
|
298
|
+
...mayFilter || searchTruncated ? {} : {
|
|
299
|
+
totalDocs: result.totalDocs,
|
|
300
|
+
pagingCounter: result.pagingCounter
|
|
118
301
|
}
|
|
119
302
|
});
|
|
120
303
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
1
2
|
import { readBody } from './readBody.js';
|
|
2
3
|
import { safeError } from '../log.js';
|
|
3
4
|
import { statusPageContent } from '../db/pageContent.js';
|
|
@@ -133,16 +134,22 @@ export async function handlePlacementStatus(req, { options }) {
|
|
|
133
134
|
name: test.name,
|
|
134
135
|
status: test.status,
|
|
135
136
|
kind: test.kind,
|
|
136
|
-
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 {
|
|
137
140
|
key,
|
|
138
141
|
label,
|
|
139
|
-
...
|
|
140
|
-
slot
|
|
142
|
+
...contentSlot ? {
|
|
143
|
+
slot: contentSlot
|
|
141
144
|
} : {}
|
|
142
|
-
}
|
|
145
|
+
};
|
|
146
|
+
}),
|
|
143
147
|
...test.decision?.winnerArm ? {
|
|
144
148
|
winnerArm: test.decision.winnerArm
|
|
145
149
|
} : {},
|
|
150
|
+
...test.decision?.discardedAt ? {
|
|
151
|
+
discarded: true
|
|
152
|
+
} : {},
|
|
146
153
|
rollout: round.rollout
|
|
147
154
|
};
|
|
148
155
|
}
|
|
@@ -160,7 +167,8 @@ export async function handlePlacementStatus(req, { options }) {
|
|
|
160
167
|
});
|
|
161
168
|
const registration = options.pages?.collections.find((entry)=>entry.slug === collection);
|
|
162
169
|
const raw = registration ? await statusPageContent(req, collection, id) : null;
|
|
163
|
-
const
|
|
170
|
+
const doc = placementReader(req, collection, options).read(raw, 'all-locales').doc;
|
|
171
|
+
const rawPath = doc && registration ? registration.pathOf(doc) : null;
|
|
164
172
|
const path = rawPath;
|
|
165
173
|
const pathKey = path === null ? null : normalisePath(path);
|
|
166
174
|
const status = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type PayloadRequest } from 'payload';
|
|
2
2
|
import type { EndpointContext } from '../types/endpoints.js';
|
|
3
3
|
import type { PreflightDependencies } from '../transitions/preflightData.js';
|
|
4
4
|
export declare function handlePreflight<TUser extends {
|
|
@@ -1,10 +1,25 @@
|
|
|
1
|
+
import { contentLocale } from './contentLocale.js';
|
|
2
|
+
import { sanitizeFallbackLocale } from 'payload';
|
|
3
|
+
import { localeRequest } from '../blocks/placementLocale.js';
|
|
1
4
|
import { preflightData } from '../transitions/preflightData.js';
|
|
2
5
|
import { routeId } from './routeId.js';
|
|
3
6
|
export async function handlePreflight(req, ctx, dependencies) {
|
|
4
7
|
const id = routeId(req);
|
|
5
|
-
const
|
|
8
|
+
const placementLocale = contentLocale(req).locale ?? undefined;
|
|
9
|
+
const localization = req.payload.config.localization;
|
|
10
|
+
// The query selects readiness labels only. Host reads must match Start's default request.
|
|
11
|
+
const readinessReq = localization ? localeRequest(req, {
|
|
12
|
+
locale: localization.defaultLocale,
|
|
13
|
+
fallbackLocale: sanitizeFallbackLocale({
|
|
14
|
+
fallbackLocale: null,
|
|
15
|
+
locale: localization.defaultLocale,
|
|
16
|
+
localization
|
|
17
|
+
})
|
|
18
|
+
}) : req;
|
|
19
|
+
const result = id !== undefined ? await preflightData(readinessReq, {
|
|
6
20
|
experimentId: id,
|
|
7
|
-
options: ctx.options
|
|
21
|
+
options: ctx.options,
|
|
22
|
+
placementLocale
|
|
8
23
|
}, dependencies) : null;
|
|
9
24
|
const headers = {
|
|
10
25
|
'Cache-Control': 'no-store'
|
|
@@ -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;
|
|
@@ -86,7 +87,7 @@ export async function handleResults(req, _ctx) {
|
|
|
86
87
|
label,
|
|
87
88
|
kind
|
|
88
89
|
})),
|
|
89
|
-
metrics: record.metricDefinitions.map(({ metricId, name, kind, role, source, resolvedCap, historyUnits, capNotice })=>({
|
|
90
|
+
metrics: record.metricDefinitions.map(({ metricId, name, kind, role, source, browserWritable, resolvedCap, historyUnits, capNotice })=>({
|
|
90
91
|
metricId,
|
|
91
92
|
name,
|
|
92
93
|
kind,
|
|
@@ -94,6 +95,9 @@ export async function handleResults(req, _ctx) {
|
|
|
94
95
|
...isClickSource(source) ? {
|
|
95
96
|
clickGoal: true
|
|
96
97
|
} : {},
|
|
98
|
+
...browserWritable === true || browserWritableMetric(source, options) ? {
|
|
99
|
+
browserWritable: true
|
|
100
|
+
} : {},
|
|
97
101
|
...resolvedCap === undefined ? {} : {
|
|
98
102
|
resolvedCap
|
|
99
103
|
},
|
|
@@ -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);
|