@delmaredigital/payload-experiments 0.3.0-rc.4 → 0.4.0-rc.10
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 +293 -688
- package/dist/admin/LayerUsage.js +1 -1
- package/dist/admin/MetricSourceSelect.js +4 -4
- package/dist/admin/PlacementStatus.d.ts +3 -0
- package/dist/admin/PlacementStatus.js +54 -0
- 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 +5 -0
- package/dist/admin/blocks/BlockPanel.js +245 -0
- package/dist/admin/blocks/TestBlockField.d.ts +5 -0
- package/dist/admin/blocks/TestBlockField.js +163 -0
- package/dist/admin/blocks/formApi.d.ts +46 -0
- package/dist/admin/blocks/formApi.js +159 -0
- package/dist/admin/blocks/inject.d.ts +7 -0
- package/dist/admin/blocks/inject.js +42 -0
- package/dist/admin/blocks/model.d.ts +18 -0
- package/dist/admin/blocks/model.js +49 -0
- package/dist/admin/blocks/statusCache.d.ts +9 -0
- package/dist/admin/blocks/statusCache.js +92 -0
- package/dist/admin/blocks/useBlockForm.d.ts +17 -0
- package/dist/admin/blocks/useBlockForm.js +46 -0
- package/dist/admin/components/RootViewMessage.js +1 -1
- package/dist/admin/copy/blocks.d.ts +47 -0
- package/dist/admin/copy/blocks.js +72 -0
- package/dist/admin/copy/goals.d.ts +8 -1
- package/dist/admin/copy/goals.js +14 -4
- package/dist/admin/copy/newTest.d.ts +13 -4
- package/dist/admin/copy/newTest.js +16 -4
- package/dist/admin/goals/XpGoalField.d.ts +4 -0
- package/dist/admin/goals/XpGoalField.js +194 -0
- package/dist/admin/goals/xpGoalField.css +47 -0
- package/dist/admin/pageCollections.d.ts +11 -0
- package/dist/admin/pageCollections.js +23 -0
- package/dist/admin/paths.d.ts +9 -0
- package/dist/admin/paths.js +9 -0
- package/dist/admin/placementStatus.model.d.ts +2 -0
- package/dist/admin/placementStatus.model.js +19 -0
- 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.js +5 -2
- package/dist/admin/surface/TestRowMenu.d.ts +6 -0
- package/dist/admin/surface/TestRowMenu.js +156 -0
- package/dist/admin/surface/TestsHome.d.ts +5 -3
- package/dist/admin/surface/TestsHome.js +298 -59
- package/dist/admin/surface/TestsSurface.js +13 -8
- package/dist/admin/surface/goals/GoalForm.d.ts +1 -1
- package/dist/admin/surface/goals/GoalForm.js +159 -85
- package/dist/admin/surface/goals/GoalsList.d.ts +1 -1
- package/dist/admin/surface/goals/GoalsList.js +7 -6
- package/dist/admin/surface/goals/data.js +6 -3
- package/dist/admin/surface/goals/goals.css +7 -0
- package/dist/admin/surface/goals/goals.model.d.ts +12 -3
- package/dist/admin/surface/goals/goals.model.js +43 -2
- package/dist/admin/surface/home.model.d.ts +9 -8
- package/dist/admin/surface/home.model.js +28 -23
- package/dist/admin/surface/newTest/NewTest.d.ts +4 -4
- package/dist/admin/surface/newTest/NewTest.js +146 -101
- package/dist/admin/surface/newTest/PageWizard.d.ts +8 -0
- package/dist/admin/surface/newTest/PageWizard.js +244 -0
- package/dist/admin/surface/newTest/newTest.css +28 -9
- package/dist/admin/surface/results/ResultsHeader.d.ts +2 -2
- package/dist/admin/surface/results/ResultsHeader.js +58 -57
- package/dist/admin/surface/surface.css +10 -0
- package/dist/admin/surface/test/TestPage.d.ts +1 -2
- package/dist/admin/surface/test/TestPage.js +42 -161
- 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 +28 -133
- 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 +11 -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.d.ts +3 -0
- package/dist/blocks/bindings.js +28 -0
- package/dist/blocks/createExperimentBlock.d.ts +6 -0
- package/dist/blocks/createExperimentBlock.js +77 -0
- package/dist/blocks/formState.d.ts +31 -0
- package/dist/blocks/formState.js +146 -0
- package/dist/blocks/model.d.ts +41 -0
- package/dist/blocks/model.js +34 -0
- 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/client/ExperimentGroup.d.ts +6 -0
- package/dist/client/ExperimentGroup.js +9 -0
- package/dist/client/ExperimentsProvider.js +20 -4
- package/dist/client/clickGoals.d.ts +4 -0
- package/dist/client/clickGoals.js +43 -0
- package/dist/collections/experiments/config.js +29 -10
- package/dist/collections/experiments/deleteGuard.d.ts +2 -1
- package/dist/collections/experiments/deleteGuard.js +14 -3
- package/dist/collections/experiments/editability.js +4 -2
- package/dist/collections/experiments/lockHook.js +21 -2
- package/dist/collections/experiments/pickSlug.d.ts +2 -0
- package/dist/collections/experiments/pickSlug.js +10 -0
- package/dist/collections/labels.d.ts +3 -0
- package/dist/collections/labels.js +20 -0
- package/dist/collections/metrics.js +28 -6
- package/dist/collections/metricsGuards.js +2 -0
- package/dist/collections/phases.js +1 -0
- package/dist/collections/serialize.js +12 -4
- 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/clickGoals.d.ts +9 -0
- package/dist/db/clickGoals.js +22 -0
- package/dist/db/delete.d.ts +2 -1
- package/dist/db/delete.js +3 -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/locks.d.ts +8 -0
- package/dist/db/locks.js +27 -4
- package/dist/db/names.d.ts +4 -0
- package/dist/db/names.js +4 -0
- package/dist/db/pageBindings.d.ts +4 -0
- package/dist/db/pageBindings.js +17 -0
- package/dist/db/pageBusy.d.ts +2 -0
- package/dist/db/pageBusy.js +10 -0
- package/dist/db/pageContent.d.ts +10 -0
- package/dist/db/pageContent.js +79 -0
- package/dist/db/pageCopies.d.ts +5 -0
- package/dist/db/pageCopies.js +31 -0
- package/dist/db/placements.d.ts +35 -0
- package/dist/db/placements.js +62 -0
- package/dist/db/results.d.ts +5 -1
- package/dist/db/results.js +21 -5
- package/dist/db/slugs.d.ts +8 -0
- package/dist/db/slugs.js +40 -0
- package/dist/db/snapshots.d.ts +7 -0
- package/dist/db/snapshots.js +8 -5
- package/dist/endpoints/clickKeys.d.ts +5 -0
- package/dist/endpoints/clickKeys.js +17 -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 +106 -39
- package/dist/endpoints/index.js +85 -9
- package/dist/endpoints/pages.d.ts +5 -0
- package/dist/endpoints/pages.js +303 -0
- package/dist/endpoints/placementStatus.d.ts +6 -0
- package/dist/endpoints/placementStatus.js +246 -0
- package/dist/endpoints/preflight.d.ts +1 -1
- package/dist/endpoints/preflight.js +17 -2
- package/dist/endpoints/readBody.d.ts +2 -0
- package/dist/endpoints/readBody.js +24 -0
- package/dist/endpoints/results.d.ts +1 -1
- package/dist/endpoints/results.js +10 -2
- package/dist/endpoints/routeId.d.ts +2 -2
- package/dist/endpoints/routeId.js +11 -5
- package/dist/endpoints/summary.js +46 -5
- package/dist/endpoints/testVersion.d.ts +2 -0
- package/dist/endpoints/testVersion.js +38 -0
- package/dist/endpoints/transitions.js +41 -29
- package/dist/endpoints/wrapBlock.d.ts +6 -0
- package/dist/endpoints/wrapBlock.js +76 -0
- package/dist/errors.d.ts +7 -2
- package/dist/errors.js +11 -3
- 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 +25 -7
- package/dist/events/writable.d.ts +9 -0
- package/dist/events/writable.js +13 -0
- package/dist/exports/adminClient.d.ts +6 -1
- package/dist/exports/adminClient.js +6 -1
- package/dist/exports/adminRsc.d.ts +3 -0
- package/dist/exports/adminRsc.js +3 -0
- package/dist/exports/blocks.d.ts +2 -0
- package/dist/exports/blocks.js +1 -0
- package/dist/exports/client.d.ts +1 -0
- package/dist/exports/client.js +1 -0
- package/dist/exports/index.d.ts +6 -1
- package/dist/exports/index.js +3 -0
- package/dist/exports/puck.d.ts +3 -1
- package/dist/exports/puck.js +2 -0
- package/dist/exports/puckEditor.d.ts +3 -0
- package/dist/exports/puckEditor.js +2 -0
- package/dist/exports/rsc.d.ts +4 -0
- package/dist/exports/rsc.js +3 -0
- package/dist/fields/xpGoal.d.ts +3 -0
- package/dist/fields/xpGoal.js +16 -0
- package/dist/globals/state.js +10 -0
- package/dist/goals/cache.d.ts +3 -0
- package/dist/goals/cache.js +35 -0
- package/dist/goals/fairness.d.ts +40 -0
- package/dist/goals/fairness.js +209 -0
- package/dist/goals/key.d.ts +4 -0
- package/dist/goals/key.js +3 -0
- package/dist/goals/picker/clickGoalPicker.model.d.ts +36 -0
- package/dist/goals/picker/clickGoalPicker.model.js +63 -0
- package/dist/goals/picker/copy.d.ts +20 -0
- package/dist/goals/picker/copy.js +24 -0
- package/dist/goals/picker/useClickGoalPicker.d.ts +30 -0
- package/dist/goals/picker/useClickGoalPicker.js +222 -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 +30 -1
- package/dist/hooks/pageGuard.js +337 -107
- 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 +65 -0
- package/dist/options.d.ts +4 -0
- package/dist/options.js +62 -1
- package/dist/plugin.js +56 -44
- 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 +6 -1
- package/dist/puck/copy.js +6 -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.js +951 -179
- 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 +57 -0
- package/dist/puck/editor/ResultsReadout.d.ts +2 -1
- package/dist/puck/editor/ResultsReadout.js +10 -6
- package/dist/puck/editor/VersionBuilder.d.ts +66 -12
- package/dist/puck/editor/VersionBuilder.js +554 -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 +64 -19
- package/dist/puck/editor/copy.js +72 -20
- package/dist/puck/editor/createTest.d.ts +3 -0
- package/dist/puck/editor/createTest.js +33 -0
- package/dist/puck/editor/editor.chrome.css +192 -19
- package/dist/puck/editor/editor.css +329 -24
- package/dist/puck/editor/editor.model.d.ts +21 -3
- package/dist/puck/editor/editor.model.js +67 -7
- 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/integration.d.ts +10 -0
- package/dist/puck/editor/integration.js +30 -0
- 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.d.ts +7 -0
- package/dist/puck/editor/xpGoalPuckEditorField.js +153 -0
- 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/integration.d.ts +6 -0
- package/dist/puck/integration.js +21 -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 +1 -1
- package/dist/puck/slotConfig.js +17 -4
- package/dist/puck/visibility.d.ts +20 -0
- package/dist/puck/visibility.js +81 -0
- package/dist/puck/xpGoalField.d.ts +3 -0
- package/dist/puck/xpGoalField.js +6 -0
- package/dist/results/aggregate.d.ts +6 -3
- package/dist/results/aggregate.js +9 -9
- package/dist/results/health.d.ts +12 -0
- package/dist/results/health.js +55 -0
- package/dist/results/identityCredit.d.ts +1 -0
- package/dist/results/identityCredit.js +4 -1
- package/dist/results/snapshot.js +15 -2
- package/dist/results/verdict.js +2 -1
- 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 +63 -2
- package/dist/server/getAssignments.js +11 -10
- package/dist/server/pageKindSeoContract.d.ts +27 -0
- package/dist/server/pageKindSeoContract.js +80 -0
- package/dist/server/recordContentChange.d.ts +1 -1
- package/dist/server/recordContentChange.js +88 -12
- package/dist/server/resolveExperimentBlocks.d.ts +5 -0
- package/dist/server/resolveExperimentBlocks.js +52 -0
- package/dist/server/resolveExperimentData.js +8 -8
- package/dist/server/runResults.js +104 -25
- package/dist/server/startExperiment.d.ts +20 -0
- package/dist/server/startExperiment.js +70 -0
- package/dist/server/toClientAssignments.js +2 -1
- package/dist/server/trackConversion.js +10 -13
- package/dist/{admin → testSurface}/PreviewLinks.d.ts +2 -1
- package/dist/{admin → testSurface}/PreviewLinks.js +8 -4
- package/dist/testSurface/actions/DecideDialog.d.ts +16 -0
- package/dist/{admin → testSurface}/actions/DecideDialog.js +79 -56
- package/dist/testSurface/actions/LifecycleAction.d.ts +16 -0
- package/dist/testSurface/actions/LifecycleAction.js +105 -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 +122 -0
- package/dist/testSurface/api.d.ts +60 -0
- package/dist/testSurface/api.js +167 -0
- package/dist/testSurface/contentLocaleURL.d.ts +2 -0
- package/dist/testSurface/contentLocaleURL.js +3 -0
- package/dist/{admin → testSurface}/copy/actions.d.ts +30 -8
- package/dist/{admin → testSurface}/copy/actions.js +40 -11
- package/dist/{admin → testSurface}/copy/common.d.ts +13 -4
- package/dist/{admin → testSurface}/copy/common.js +18 -8
- 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 +1 -0
- package/dist/{admin → testSurface}/copy/metrics.js +1 -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 +59 -6
- package/dist/testSurface/copy/readiness.js +136 -0
- package/dist/{admin → testSurface}/copy/results.d.ts +7 -3
- package/dist/{admin → testSurface}/copy/results.js +7 -3
- package/dist/{admin → testSurface}/copy/review.d.ts +1 -1
- package/dist/{admin → testSurface}/copy/review.js +1 -1
- package/dist/{admin → testSurface}/copy/surface.d.ts +11 -2
- package/dist/{admin → testSurface}/copy/surface.js +13 -10
- package/dist/{admin → testSurface}/copy/testPage.d.ts +56 -7
- package/dist/testSurface/copy/testPage.js +165 -0
- package/dist/testSurface/format/adminURL.d.ts +7 -0
- package/dist/testSurface/format/adminURL.js +9 -0
- package/dist/{admin → testSurface}/metricSource.model.d.ts +2 -0
- package/dist/{admin → testSurface}/metricSource.model.js +4 -0
- package/dist/testSurface/placementLabel.d.ts +8 -0
- package/dist/testSurface/placementLabel.js +24 -0
- package/dist/testSurface/placements/placementLabels.d.ts +13 -0
- package/dist/testSurface/placements/placementLabels.js +22 -0
- package/dist/testSurface/placements/placementLabels.model.d.ts +13 -0
- package/dist/testSurface/placements/placementLabels.model.js +12 -0
- package/dist/testSurface/placements/usePlacementLabels.d.ts +12 -0
- package/dist/testSurface/placements/usePlacementLabels.js +102 -0
- 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/DataQualityPanel.js +4 -1
- 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 -0
- package/dist/{admin → testSurface}/results/results.model.js +14 -6
- package/dist/{admin → testSurface}/surface/contracts.d.ts +23 -8
- 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/{admin → testSurface}/surface/pageBlock/parts.js +39 -11
- 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 +503 -0
- package/dist/testSurface/surface/pagePicker/pagePicker.css +73 -0
- package/dist/testSurface/surface/pagePicker/pagePicker.model.d.ts +29 -0
- package/dist/testSurface/surface/pagePicker/pagePicker.model.js +40 -0
- package/dist/{admin → testSurface}/surface/readiness/ActionDialogs.d.ts +8 -4
- package/dist/testSurface/surface/readiness/ActionDialogs.js +351 -0
- package/dist/{admin → testSurface}/surface/readiness/Banner.d.ts +2 -3
- package/dist/testSurface/surface/readiness/Banner.js +187 -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 +10 -0
- package/dist/testSurface/surface/readiness/SaveStatus.js +66 -0
- package/dist/{admin → testSurface}/surface/readiness/parts.js +0 -2
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +57 -0
- 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/testSurface/surface/results/ReleasePages.d.ts +19 -0
- package/dist/{admin → testSurface}/surface/results/ReleasePages.js +43 -47
- package/dist/{admin → testSurface}/surface/results/ResultsBody.d.ts +7 -3
- package/dist/{admin → testSurface}/surface/results/ResultsBody.js +129 -46
- package/dist/{admin → testSurface}/surface/results/useResults.d.ts +36 -9
- package/dist/{admin → testSurface}/surface/results/useResults.js +3 -2
- package/dist/{admin → testSurface}/surface/setting/parts.js +58 -18
- package/dist/testSurface/surface/setting/setting.css +17 -0
- package/dist/testSurface/surface/test/AdvancedSection.js +169 -0
- 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/testSurface/surface/test/GoalSection.js +341 -0
- package/dist/testSurface/surface/test/LengthSection.d.ts +2 -0
- package/dist/{admin → testSurface}/surface/test/LengthSection.js +6 -2
- package/dist/testSurface/surface/test/PageHoldout.d.ts +3 -0
- package/dist/testSurface/surface/test/PageHoldout.js +70 -0
- package/dist/{admin → testSurface}/surface/test/Rail.js +7 -4
- package/dist/{admin → testSurface}/surface/test/ReadinessBar.d.ts +1 -0
- package/dist/{admin → testSurface}/surface/test/ReadinessBar.js +2 -3
- package/dist/{admin → testSurface}/surface/test/Section.d.ts +3 -1
- package/dist/testSurface/surface/test/Section.js +80 -0
- package/dist/{admin → testSurface}/surface/test/TargetingSection.js +82 -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/{admin → testSurface}/surface/test/VersionsSection.js +81 -40
- package/dist/{admin → testSurface}/surface/test/fields.d.ts +40 -8
- package/dist/testSurface/surface/test/fields.js +306 -0
- package/dist/{admin → testSurface}/surface/test/jumpToSection.d.ts +1 -1
- package/dist/{admin → testSurface}/surface/test/jumpToSection.js +4 -3
- package/dist/testSurface/surface/test/pageParts.d.ts +5 -0
- package/dist/testSurface/surface/test/pageParts.js +106 -0
- package/dist/testSurface/surface/test/testPage.css +103 -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 +4 -0
- package/dist/{admin → testSurface}/surface/testDocument.model.js +6 -2
- 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 +7 -0
- package/dist/testSurface/surfaceUrls.js +19 -0
- package/dist/testSurface/useApi.d.ts +60 -0
- package/dist/testSurface/useApi.js +8 -0
- 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 +4 -6
- package/dist/transitions/addMetric.js +33 -2
- 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 +18 -1
- package/dist/transitions/checkStart.js +207 -9
- package/dist/transitions/contentFields.js +9 -5
- package/dist/transitions/decide.d.ts +1 -1
- package/dist/transitions/decide.js +30 -3
- package/dist/transitions/deleteExperiment.d.ts +5 -3
- package/dist/transitions/deleteExperiment.js +43 -7
- package/dist/transitions/kernel.d.ts +4 -0
- package/dist/transitions/kernel.js +13 -4
- package/dist/transitions/makeContent.d.ts +7 -1
- package/dist/transitions/makeContent.js +74 -22
- 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/pageCollection.d.ts +10 -0
- package/dist/transitions/pageCollection.js +20 -0
- package/dist/transitions/pageVersions.d.ts +10 -0
- package/dist/transitions/pageVersions.js +46 -0
- package/dist/transitions/phaseRecord.d.ts +3 -0
- package/dist/transitions/phaseRecord.js +5 -0
- package/dist/transitions/placementInteractions.d.ts +40 -0
- package/dist/transitions/placementInteractions.js +98 -0
- package/dist/transitions/placements.d.ts +58 -4
- package/dist/transitions/placements.js +391 -21
- package/dist/transitions/preflightData.d.ts +7 -5
- package/dist/transitions/preflightData.js +269 -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 +3 -4
- package/dist/transitions/resolveCaps.js +6 -2
- package/dist/transitions/start.d.ts +6 -8
- package/dist/transitions/start.js +112 -31
- 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/admin.d.ts +1 -1
- package/dist/types/assignments.d.ts +1 -0
- package/dist/types/contracts.d.ts +30 -3
- package/dist/types/endpoints.d.ts +204 -13
- package/dist/types/index.d.ts +3 -0
- package/dist/types/puck.d.ts +8 -1
- package/dist/types/runtime.d.ts +15 -9
- package/dist/types/snapshot.d.ts +19 -4
- package/dist/types/surface.d.ts +20 -7
- 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 +116 -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 +7 -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 +49 -5
- package/package.json +9 -1
- package/dist/admin/actions/ConfirmDialog.d.ts +0 -18
- package/dist/admin/actions/ConfirmDialog.js +0 -149
- package/dist/admin/actions/DecideDialog.d.ts +0 -9
- package/dist/admin/actions/actions.model.js +0 -70
- package/dist/admin/api.d.ts +0 -38
- package/dist/admin/api.js +0 -99
- package/dist/admin/copy/readiness.js +0 -71
- package/dist/admin/copy/testPage.js +0 -100
- 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/readiness/ActionDialogs.js +0 -302
- package/dist/admin/surface/readiness/Banner.js +0 -166
- 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.d.ts +0 -24
- package/dist/admin/surface/readiness/readiness.model.js +0 -123
- package/dist/admin/surface/readiness/useTransition.d.ts +0 -11
- package/dist/admin/surface/readiness/useTransition.js +0 -35
- package/dist/admin/surface/results/ReleasePages.d.ts +0 -14
- package/dist/admin/surface/setting/setting.css +0 -17
- package/dist/admin/surface/test/AdvancedSection.js +0 -160
- package/dist/admin/surface/test/GoalSection.d.ts +0 -2
- package/dist/admin/surface/test/GoalSection.js +0 -228
- 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/fields.js +0 -184
- package/dist/admin/surface/test/pageParts.d.ts +0 -2
- package/dist/admin/surface/test/pageParts.js +0 -45
- package/dist/admin/surface/test/testPage.css +0 -90
- package/dist/admin/surface/useTestDocument.d.ts +0 -23
- package/dist/admin/surface/useTestDocument.js +0 -377
- package/dist/admin/useApi.d.ts +0 -35
- package/dist/admin/useApi.js +0 -10
- /package/dist/{admin → testSurface}/actions/decide.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/actions/decide.model.js +0 -0
- /package/dist/{admin → testSurface}/allocation.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/allocation.model.js +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}/copy/advanced.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/advanced.js +0 -0
- /package/dist/{admin → testSurface}/copy/arms.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/arms.js +0 -0
- /package/dist/{admin → testSurface}/copy/audience.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/audience.js +0 -0
- /package/dist/{admin → testSurface}/copy/recommendation.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/recommendation.js +0 -0
- /package/dist/{admin → testSurface}/copy/setting.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/setting.js +0 -0
- /package/dist/{admin → testSurface}/format/date.d.ts +0 -0
- /package/dist/{admin → testSurface}/format/date.js +0 -0
- /package/dist/{admin → testSurface}/labels.d.ts +0 -0
- /package/dist/{admin → testSurface}/labels.js +0 -0
- /package/dist/{admin → testSurface}/lockedNotice.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/lockedNotice.model.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/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/results/recommendation.model.js +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}/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
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { requireCurrentRound } from './phaseRecord.js';
|
|
2
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
3
|
+
import { puckExperimentSlug } from '../puck/experimentSlug.js';
|
|
4
|
+
import { puckVisibility, hiddenOnSizes, visibilitySizes } from '../puck/visibility.js';
|
|
5
|
+
import { Forbidden, NotFound, ValidationError, Locked, commitTransaction, killTransaction } from 'payload';
|
|
6
|
+
import { initTransitionTransaction } from '../db/adapter.js';
|
|
2
7
|
import { latestDraftContent, publishedContent as readPublishedContent } from '../db/publishedContent.js';
|
|
8
|
+
import { EXPERIMENT_BLOCK_SLUG, hostBlocks, slotBlocks } from '../blocks/model.js';
|
|
9
|
+
import { findRegisteredBlocksField, freshBlockIds } from '../blocks/formState.js';
|
|
3
10
|
import { contentBlocks, hasLocalizedFields } from './contentFields.js';
|
|
4
11
|
import { safeError } from '../log.js';
|
|
5
12
|
import { XpRefusal } from '../errors.js';
|
|
@@ -28,23 +35,40 @@ class LocalizedContent extends Error {
|
|
|
28
35
|
}
|
|
29
36
|
const isNotFound = (error)=>contentFailureReason(error) === 'not-found' || Boolean(error && typeof error === 'object' && 'status' in error && error.status === 404);
|
|
30
37
|
const object = (value)=>value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
31
|
-
/** Flatten selected slots in every content array, including nested selected slots. */ function unwrap(value, slug, slot) {
|
|
38
|
+
/** Flatten selected slots in every content array, including nested selected slots. */ function unwrap(value, slug, slot, visibility = puckVisibility(value)) {
|
|
32
39
|
if (Array.isArray(value)) return value.flatMap((node)=>{
|
|
40
|
+
if (object(node) && visibility.get(node)?.hidden) return [
|
|
41
|
+
node
|
|
42
|
+
];
|
|
33
43
|
if (object(node) && node.type === 'ExperimentSlot' && object(node.props)) {
|
|
34
|
-
|
|
35
|
-
if ((typeof ref === 'string' ? ref : object(ref) ? ref.slug : undefined) === slug) {
|
|
44
|
+
if (puckExperimentSlug(node.props.experiment) === slug) {
|
|
36
45
|
const content = node.props[slot];
|
|
37
46
|
if (!Array.isArray(content)) throw new Error('The winning content slot is missing.');
|
|
38
|
-
|
|
47
|
+
const selected = unwrap(content, slug, slot, visibility);
|
|
48
|
+
const hideOn = hiddenOnSizes(node.props._visibility);
|
|
49
|
+
return hideOn.length ? selected.map((child)=>{
|
|
50
|
+
if (!object(child) || !object(child.props)) return child;
|
|
51
|
+
const current = object(child.props._visibility) ? child.props._visibility : {};
|
|
52
|
+
return {
|
|
53
|
+
...child,
|
|
54
|
+
props: {
|
|
55
|
+
...child.props,
|
|
56
|
+
_visibility: {
|
|
57
|
+
...current,
|
|
58
|
+
hideOn: visibilitySizes.filter((size)=>hideOn.includes(size) || hiddenOnSizes(current).includes(size))
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}) : selected;
|
|
39
63
|
}
|
|
40
64
|
}
|
|
41
65
|
return [
|
|
42
|
-
unwrap(node, slug, slot)
|
|
66
|
+
unwrap(node, slug, slot, visibility)
|
|
43
67
|
];
|
|
44
68
|
});
|
|
45
|
-
if (object(value)) return Object.fromEntries(Object.entries(value).map(([key, child])=>[
|
|
69
|
+
if (object(value)) return visibility.get(value)?.hidden ? value : Object.fromEntries(Object.entries(value).map(([key, child])=>[
|
|
46
70
|
key,
|
|
47
|
-
unwrap(child, slug, slot)
|
|
71
|
+
unwrap(child, slug, slot, visibility)
|
|
48
72
|
]));
|
|
49
73
|
return value;
|
|
50
74
|
}
|
|
@@ -162,13 +186,18 @@ async function fieldRefusal(fields, req, doc, operation = 'update', data = doc,
|
|
|
162
186
|
/** Each placement commits independently while the outer transition retains its
|
|
163
187
|
* experiment locks. Keep the manager's exact req/user, temporarily lending it a
|
|
164
188
|
* fresh transaction; a denied host write must not kill the outer transaction.
|
|
165
|
-
*/ async function hostTransaction(req, fn) {
|
|
189
|
+
*/ export async function hostTransaction(req, experimentId, fn) {
|
|
166
190
|
const transactionID = req.transactionID;
|
|
167
191
|
const transition = req.context.xpTransition;
|
|
192
|
+
const hadHeld = Object.hasOwn(req.context, 'xpHeldExperiments');
|
|
193
|
+
const held = req.context.xpHeldExperiments;
|
|
194
|
+
req.context.xpHeldExperiments = [
|
|
195
|
+
experimentId
|
|
196
|
+
];
|
|
168
197
|
delete req.transactionID;
|
|
169
198
|
delete req.context.xpTransition;
|
|
170
199
|
try {
|
|
171
|
-
if (!await
|
|
200
|
+
if (!await initTransitionTransaction(req)) throw new Error('A content transaction could not be started.');
|
|
172
201
|
await fn();
|
|
173
202
|
const xid = await currentTxid(txExecutor(req));
|
|
174
203
|
await commitTransaction(req);
|
|
@@ -178,11 +207,13 @@ async function fieldRefusal(fields, req, doc, operation = 'update', data = doc,
|
|
|
178
207
|
throw error;
|
|
179
208
|
} finally{
|
|
180
209
|
req.transactionID = transactionID;
|
|
210
|
+
if (hadHeld) req.context.xpHeldExperiments = held;
|
|
211
|
+
else delete req.context.xpHeldExperiments;
|
|
181
212
|
if (transition === undefined) delete req.context.xpTransition;
|
|
182
213
|
else req.context.xpTransition = transition;
|
|
183
214
|
}
|
|
184
215
|
}
|
|
185
|
-
export async function makeContent(req, { experimentId, options }) {
|
|
216
|
+
export async function makeContent(req, { experimentId, options, phase: expectedPhase }) {
|
|
186
217
|
const before = await readExperiment(req, experimentId);
|
|
187
218
|
const { result } = await withTransition(req, {
|
|
188
219
|
experimentId,
|
|
@@ -191,6 +222,7 @@ export async function makeContent(req, { experimentId, options }) {
|
|
|
191
222
|
bump: false
|
|
192
223
|
}, async ({ exec })=>{
|
|
193
224
|
const current = await readExperiment(req, experimentId);
|
|
225
|
+
requireCurrentRound(expectedPhase, current.phase);
|
|
194
226
|
if (current.status !== 'decided' || ![
|
|
195
227
|
'block',
|
|
196
228
|
'flag',
|
|
@@ -217,7 +249,7 @@ export async function makeContent(req, { experimentId, options }) {
|
|
|
217
249
|
if (retainDismissed(collection, id)) return;
|
|
218
250
|
let missing = false;
|
|
219
251
|
try {
|
|
220
|
-
await hostTransaction(req, async ()=>{
|
|
252
|
+
await hostTransaction(req, experimentId, async ()=>{
|
|
221
253
|
try {
|
|
222
254
|
await fn();
|
|
223
255
|
} catch (error) {
|
|
@@ -226,7 +258,7 @@ export async function makeContent(req, { experimentId, options }) {
|
|
|
226
258
|
// Roll back any remaining writes, then check the row while still
|
|
227
259
|
// detached from the outer transition and its privileged context.
|
|
228
260
|
await killTransaction(req);
|
|
229
|
-
if (!await
|
|
261
|
+
if (!await initTransitionTransaction(req)) throw new Error('A content transaction could not be started.');
|
|
230
262
|
missing = !await readPublishedContent(req, collection, id);
|
|
231
263
|
}
|
|
232
264
|
throw error;
|
|
@@ -263,8 +295,12 @@ export async function makeContent(req, { experimentId, options }) {
|
|
|
263
295
|
}
|
|
264
296
|
};
|
|
265
297
|
if (current.kind === 'block') {
|
|
266
|
-
if (
|
|
267
|
-
const
|
|
298
|
+
if (winner.key === 'holdout') refuse('invalid-winner');
|
|
299
|
+
const winnerSlot = winner.key;
|
|
300
|
+
const registrations = [
|
|
301
|
+
...puckCollections(options),
|
|
302
|
+
...options.blocks?.collections ?? []
|
|
303
|
+
];
|
|
268
304
|
const scanned = [];
|
|
269
305
|
for (const registration of registrations){
|
|
270
306
|
const transactionID = req.transactionID;
|
|
@@ -272,9 +308,8 @@ export async function makeContent(req, { experimentId, options }) {
|
|
|
272
308
|
try {
|
|
273
309
|
scanned.push(...await scanBlockPlacements(req, {
|
|
274
310
|
slug: current.slug,
|
|
275
|
-
puckCollections:
|
|
276
|
-
|
|
277
|
-
]
|
|
311
|
+
puckCollections: puckCollections(options).filter((r)=>r === registration),
|
|
312
|
+
blocksCollections: (options.blocks?.collections ?? []).filter((r)=>r === registration)
|
|
278
313
|
}));
|
|
279
314
|
} catch (error) {
|
|
280
315
|
// A collection made unreadable since the last attempt still has
|
|
@@ -330,7 +365,7 @@ export async function makeContent(req, { experimentId, options }) {
|
|
|
330
365
|
let detail = isNotFound(error) ? 'forbidden' : contentFailureReason(error);
|
|
331
366
|
if (isNotFound(error)) {
|
|
332
367
|
try {
|
|
333
|
-
await hostTransaction(req, async ()=>{
|
|
368
|
+
await hostTransaction(req, experimentId, async ()=>{
|
|
334
369
|
missing = !await readPublishedContent(req, collection, id);
|
|
335
370
|
});
|
|
336
371
|
} catch (checkError) {
|
|
@@ -367,7 +402,7 @@ export async function makeContent(req, { experimentId, options }) {
|
|
|
367
402
|
for (const [key, { collection, id }] of placements){
|
|
368
403
|
if (skipped.has(key)) continue;
|
|
369
404
|
await attempt(collection, id, async ()=>{
|
|
370
|
-
|
|
405
|
+
let field = registrations.find((entry)=>entry.slug === collection)?.field;
|
|
371
406
|
if (!field) throw new Error('This content collection is no longer configured.');
|
|
372
407
|
const config = req.payload.config.collections.find((config)=>config.slug === collection);
|
|
373
408
|
if (hasLocalizedFields(config?.fields ?? [], req.payload.config)) throw new LocalizedContent();
|
|
@@ -382,10 +417,27 @@ export async function makeContent(req, { experimentId, options }) {
|
|
|
382
417
|
const drafts = Boolean(config?.versions && config.versions.drafts);
|
|
383
418
|
const published = await readPublishedContent(req, collection, id);
|
|
384
419
|
if (!published) throw new NotFound();
|
|
420
|
+
const editor = placementReader(req, collection, options).read(published, 'all-locales').editor;
|
|
421
|
+
const blockRegistration = options.blocks?.collections.find((r)=>r.slug === collection);
|
|
422
|
+
const contentField = editor === 'blocks' ? blockRegistration?.field : field;
|
|
423
|
+
if (!contentField) throw new Error('This content field is no longer configured.');
|
|
424
|
+
field = contentField;
|
|
425
|
+
const transform = (value)=>editor === 'blocks' ? !hostBlocks(value).some((block)=>block.blockType === (blockRegistration?.blockSlug ?? EXPERIMENT_BLOCK_SLUG) && block.experiment === current.slug) ? value : hostBlocks(value).flatMap((block)=>{
|
|
426
|
+
if (block.blockType !== (blockRegistration?.blockSlug ?? EXPERIMENT_BLOCK_SLUG) || block.experiment !== current.slug) return [
|
|
427
|
+
block
|
|
428
|
+
];
|
|
429
|
+
const rows = Array.isArray(block.slots) ? block.slots : [];
|
|
430
|
+
if (!rows.some((row)=>row?.slot === winnerSlot)) throw new Error('The winning content slot is missing.');
|
|
431
|
+
const registered = findRegisteredBlocksField(config?.fields ?? [], field);
|
|
432
|
+
if (!registered) throw new Error('This content field is no longer configured.');
|
|
433
|
+
return slotBlocks(freshBlockIds([
|
|
434
|
+
block
|
|
435
|
+
], registered.field, req.payload.config)[0], winnerSlot);
|
|
436
|
+
}) : unwrap(value, current.slug, winnerSlot);
|
|
385
437
|
const draft = drafts ? await latestDraftContent(req, collection, id) ?? published : published;
|
|
386
438
|
const draftValue = draft[field] ?? null;
|
|
387
|
-
const draftContent =
|
|
388
|
-
const publishedContent =
|
|
439
|
+
const draftContent = transform(draftValue);
|
|
440
|
+
const publishedContent = transform(published[field]);
|
|
389
441
|
const changedDraft = JSON.stringify(draftContent) !== JSON.stringify(draftValue);
|
|
390
442
|
const changedPublished = JSON.stringify(publishedContent) !== JSON.stringify(published[field]);
|
|
391
443
|
if (!changedDraft && !changedPublished) return;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
import type { BlockPlacement } from './placements.js';
|
|
3
|
+
/** Read names for preflight and Start's locked rescan. */
|
|
4
|
+
export declare function nestedPlacementNames(req: PayloadRequest, placements: readonly BlockPlacement[], system?: boolean): Promise<Map<string, string>>;
|
|
5
|
+
export declare const nameNestedPlacements: (placements: readonly BlockPlacement[], names: ReadonlyMap<string, string>) => BlockPlacement[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { findStartDocuments } from './startReads.js';
|
|
2
|
+
/** Read names for preflight and Start's locked rescan. */ export async function nestedPlacementNames(req, placements, system = false) {
|
|
3
|
+
const slugs = [
|
|
4
|
+
...new Set(placements.flatMap((p)=>(p.nestedTests ?? []).flatMap((pair)=>[
|
|
5
|
+
pair.outer,
|
|
6
|
+
pair.inner
|
|
7
|
+
])))
|
|
8
|
+
];
|
|
9
|
+
if (!slugs.length) return new Map();
|
|
10
|
+
const found = await findStartDocuments(req, {
|
|
11
|
+
collection: 'xp-experiments',
|
|
12
|
+
depth: 0,
|
|
13
|
+
pagination: false,
|
|
14
|
+
where: {
|
|
15
|
+
slug: {
|
|
16
|
+
in: slugs
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}, system);
|
|
20
|
+
return new Map(found.docs.map((doc)=>[
|
|
21
|
+
String(doc.slug),
|
|
22
|
+
String(doc.name)
|
|
23
|
+
]));
|
|
24
|
+
}
|
|
25
|
+
export const nameNestedPlacements = (placements, names)=>placements.map((p)=>({
|
|
26
|
+
...p,
|
|
27
|
+
nestedTests: p.nestedTests?.map((pair)=>({
|
|
28
|
+
...pair,
|
|
29
|
+
outer: names.get(pair.outer) ?? pair.outer,
|
|
30
|
+
inner: names.get(pair.inner) ?? pair.inner
|
|
31
|
+
}))
|
|
32
|
+
}));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
import type { ExperimentsPageCollection } from '../types/contracts.js';
|
|
3
|
+
export declare const PAGE_ADDRESS_FIELDS: string[];
|
|
4
|
+
/** Hosts can resolve drafts in findByPath. For simple addresses, the admin also
|
|
5
|
+
* recognizes never-published drafts when a host lookup only sees live pages. */
|
|
6
|
+
export declare function findDraftPageByPath(req: PayloadRequest, entry: ExperimentsPageCollection, path: string): Promise<(import("payload").JsonObject & import("payload").TypeWithID) | undefined>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { flattenTopLevelFields } from 'payload/shared';
|
|
2
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
3
|
+
import { normalisePath } from '../runtime/normalisePath.js';
|
|
4
|
+
export const PAGE_ADDRESS_FIELDS = [
|
|
5
|
+
'path',
|
|
6
|
+
'slug',
|
|
7
|
+
'pageSegment'
|
|
8
|
+
];
|
|
9
|
+
/** Hosts can resolve drafts in findByPath. For simple addresses, the admin also
|
|
10
|
+
* recognizes never-published drafts when a host lookup only sees live pages. */ export async function findDraftPageByPath(req, entry, path) {
|
|
11
|
+
const config = req.payload.collections?.[entry.slug]?.config ?? req.payload.config.collections?.find((collection)=>collection.slug === entry.slug);
|
|
12
|
+
if (!config?.versions?.drafts) return undefined;
|
|
13
|
+
const key = normalisePath(path);
|
|
14
|
+
const relative = key.replace(/^\/+/, '');
|
|
15
|
+
const segment = relative.split('/').at(-1);
|
|
16
|
+
const unprefixed = relative.slice(relative.indexOf('/') + 1);
|
|
17
|
+
const filters = flattenTopLevelFields(config.fields).flatMap((field)=>{
|
|
18
|
+
if (field.type !== 'text' || field.virtual || !PAGE_ADDRESS_FIELDS.includes(field.name)) return [];
|
|
19
|
+
const values = field.name === 'pageSegment' ? [
|
|
20
|
+
segment
|
|
21
|
+
] : [
|
|
22
|
+
relative,
|
|
23
|
+
unprefixed,
|
|
24
|
+
segment
|
|
25
|
+
];
|
|
26
|
+
const candidates = [
|
|
27
|
+
...new Set(values.flatMap((value)=>value ? [
|
|
28
|
+
value,
|
|
29
|
+
'/' + value,
|
|
30
|
+
value + '/',
|
|
31
|
+
'/' + value + '/'
|
|
32
|
+
] : []))
|
|
33
|
+
];
|
|
34
|
+
return candidates.length ? [
|
|
35
|
+
{
|
|
36
|
+
[field.name]: {
|
|
37
|
+
in: candidates
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
] : [];
|
|
41
|
+
});
|
|
42
|
+
if (!filters.length) return undefined;
|
|
43
|
+
const result = await req.payload.find({
|
|
44
|
+
collection: entry.slug,
|
|
45
|
+
req,
|
|
46
|
+
overrideAccess: false,
|
|
47
|
+
depth: 0,
|
|
48
|
+
draft: false,
|
|
49
|
+
pagination: false,
|
|
50
|
+
limit: 20,
|
|
51
|
+
where: {
|
|
52
|
+
and: [
|
|
53
|
+
{
|
|
54
|
+
_status: {
|
|
55
|
+
equals: 'draft'
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
or: filters
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const reader = placementReader(req, entry.slug);
|
|
65
|
+
const input = req.locale === 'all' ? 'all-locales' : 'localized';
|
|
66
|
+
const candidates = result.docs.filter((row)=>{
|
|
67
|
+
const address = entry.pathOf(reader.read(row, input).doc);
|
|
68
|
+
return address !== null && normalisePath(address) === key;
|
|
69
|
+
});
|
|
70
|
+
return candidates.length === 1 ? candidates[0] : undefined;
|
|
71
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
import type { ExperimentsPageCollection, ResolvedOptions } from '../types/contracts.js';
|
|
3
|
+
/** A stored collection is authoritative. Legacy tests fall back by the Original's path. */
|
|
4
|
+
export declare function resolvePageCollection(req: PayloadRequest, options: Pick<ResolvedOptions, 'pages'>, experiment: {
|
|
5
|
+
pageCollection?: string | null;
|
|
6
|
+
arms: readonly {
|
|
7
|
+
kind?: string;
|
|
8
|
+
pageTarget?: string;
|
|
9
|
+
}[];
|
|
10
|
+
}, propagateErrors?: boolean): Promise<ExperimentsPageCollection | undefined>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { safeError } from '../log.js';
|
|
2
|
+
/** A stored collection is authoritative. Legacy tests fall back by the Original's path. */ export async function resolvePageCollection(req, options, experiment, propagateErrors = false) {
|
|
3
|
+
const collections = options.pages?.collections ?? [];
|
|
4
|
+
if (experiment.pageCollection) return collections.find((entry)=>entry.slug === experiment.pageCollection);
|
|
5
|
+
if (collections.length === 1) return collections[0];
|
|
6
|
+
const path = experiment.arms.find((arm)=>arm.kind === 'control')?.pageTarget;
|
|
7
|
+
if (!path) return undefined;
|
|
8
|
+
for (const entry of collections){
|
|
9
|
+
try {
|
|
10
|
+
if (await entry.findByPath(path, req)) return entry;
|
|
11
|
+
} catch (cause) {
|
|
12
|
+
if (propagateErrors) throw cause;
|
|
13
|
+
req.payload.logger.error({
|
|
14
|
+
err: safeError(cause),
|
|
15
|
+
collection: entry.slug
|
|
16
|
+
}, 'Experiment page lookup failed');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
import type { Arm, ExperimentsPageCollection } from '../types/contracts.js';
|
|
3
|
+
/** Page copies have fresh nested row ids and editor labels; neither is rendered content. */
|
|
4
|
+
export declare function comparableContent(value: unknown): unknown;
|
|
5
|
+
export declare function identicalPageVersions(req: PayloadRequest, collection: ExperimentsPageCollection | undefined, arms: Arm[]): Promise<{
|
|
6
|
+
arm: import("../types/contracts.js").ArmKey;
|
|
7
|
+
path: string;
|
|
8
|
+
collection: string;
|
|
9
|
+
id: string | number;
|
|
10
|
+
}[]>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
2
|
+
import { safeError } from '../log.js';
|
|
3
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
4
|
+
import { pageVersionContent } from '../db/pageContent.js';
|
|
5
|
+
/** Page copies have fresh nested row ids and editor labels; neither is rendered content. */ export function comparableContent(value) {
|
|
6
|
+
if (Array.isArray(value)) return value.map(comparableContent);
|
|
7
|
+
if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).filter(([key])=>key !== 'id' && key !== 'blockName').map(([key, nested])=>[
|
|
8
|
+
key,
|
|
9
|
+
comparableContent(nested)
|
|
10
|
+
]));
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
export async function identicalPageVersions(req, collection, arms) {
|
|
14
|
+
if (!collection?.contentOf) return [];
|
|
15
|
+
const content = await Promise.all(arms.filter((arm)=>arm.kind !== 'holdout' && arm.pageTarget).map(async (arm)=>{
|
|
16
|
+
try {
|
|
17
|
+
const page = await collection.findByPath(arm.pageTarget, req);
|
|
18
|
+
if (!page?.published) return null;
|
|
19
|
+
const raw = await pageVersionContent(req, collection.slug, page.id);
|
|
20
|
+
if (!raw || raw._status === 'draft') return null;
|
|
21
|
+
const reader = placementReader(req, collection.slug);
|
|
22
|
+
return {
|
|
23
|
+
arm,
|
|
24
|
+
id: page.id,
|
|
25
|
+
value: reader.documentViews.map((view)=>comparableContent(collection.contentOf(reader.read(raw, 'all-locales', view).doc)))
|
|
26
|
+
};
|
|
27
|
+
} catch (cause) {
|
|
28
|
+
req.payload.logger.error({
|
|
29
|
+
err: safeError(cause),
|
|
30
|
+
collection: collection.slug,
|
|
31
|
+
id: arm.pageTarget
|
|
32
|
+
}, 'Experiment version comparison failed');
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
const control = content.find((row)=>row?.arm.kind === 'control');
|
|
37
|
+
if (!control) return [];
|
|
38
|
+
return content.flatMap((row)=>row && row.arm.kind === 'variant' && isDeepStrictEqual(row.value, control.value) ? [
|
|
39
|
+
{
|
|
40
|
+
arm: row.arm.key,
|
|
41
|
+
path: row.arm.pageTarget,
|
|
42
|
+
collection: collection.slug,
|
|
43
|
+
id: row.id
|
|
44
|
+
}
|
|
45
|
+
] : []);
|
|
46
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { PayloadRequest } from 'payload';
|
|
2
2
|
import type { Arm, DocId, TargetingRule } from '../types/contracts.js';
|
|
3
3
|
import type { AllocationChange, ContentChange } from '../db/appends.js';
|
|
4
|
+
/** Check the round after acquiring the experiment lock and before writing. */
|
|
5
|
+
export declare function requireCurrentRound(expected: number | undefined, current: number | undefined): void;
|
|
4
6
|
export interface PhaseRecord {
|
|
5
7
|
experiment: DocId;
|
|
6
8
|
phase: number;
|
|
@@ -16,6 +18,7 @@ export interface PhaseRecord {
|
|
|
16
18
|
analysis?: Record<string, unknown> & {
|
|
17
19
|
sequentialTuningParameter?: number | null;
|
|
18
20
|
};
|
|
21
|
+
placementDocs?: import('../db/placements.js').PlacementDoc[] | null;
|
|
19
22
|
contentChanges?: ContentChange[];
|
|
20
23
|
}
|
|
21
24
|
export declare function readPhaseRecord(req: PayloadRequest, experimentId: DocId, phase: number): Promise<PhaseRecord & {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { XpRefusal } from '../errors.js';
|
|
2
|
+
/** Check the round after acquiring the experiment lock and before writing. */ export function requireCurrentRound(expected, current) {
|
|
3
|
+
if (expected !== undefined && expected !== current) {
|
|
4
|
+
throw new XpRefusal('round-changed', 'This test is on a different round. Review the current round and try again.', undefined, 409);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
2
7
|
export async function readPhaseRecord(req, experimentId, phase) {
|
|
3
8
|
// §7.8: frozen configuration lookup serves an authorised transition.
|
|
4
9
|
const { docs } = await req.payload.find({
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
import type { Arm, DocId, ResolvedOptions } from '../types/contracts.js';
|
|
3
|
+
import type { Executor } from '../db/executor.js';
|
|
4
|
+
import { type PlacementDoc } from '../db/placements.js';
|
|
5
|
+
import { type BlockPlacement } from './placements.js';
|
|
6
|
+
export declare function detached<T>(req: PayloadRequest, fn: () => Promise<T>): Promise<T>;
|
|
7
|
+
export declare function uniquePlacementDocs(placements: readonly Pick<BlockPlacement, 'collection' | 'id'>[]): PlacementDoc[];
|
|
8
|
+
export declare function scanPlacements<TUser extends {
|
|
9
|
+
id: DocId;
|
|
10
|
+
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, slug: string, system?: boolean): Promise<BlockPlacement[]>;
|
|
11
|
+
export declare function placementPaths<TUser extends {
|
|
12
|
+
id: DocId;
|
|
13
|
+
}>(req: PayloadRequest, options: ResolvedOptions<TUser>, docs: readonly PlacementDoc[]): Promise<string[]>;
|
|
14
|
+
export interface InteractionDetail {
|
|
15
|
+
experimentId: DocId;
|
|
16
|
+
slug: string;
|
|
17
|
+
name: string;
|
|
18
|
+
status: string;
|
|
19
|
+
path: string;
|
|
20
|
+
version: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function placementInteractions<TUser extends {
|
|
23
|
+
id: DocId;
|
|
24
|
+
}>(req: PayloadRequest, exec: Executor, options: ResolvedOptions<TUser>, experiment: {
|
|
25
|
+
id: DocId;
|
|
26
|
+
kind: string;
|
|
27
|
+
arms: Arm[];
|
|
28
|
+
pageCollection?: string | null;
|
|
29
|
+
}, paths: string[], system?: boolean): Promise<InteractionDetail[]>;
|
|
30
|
+
export declare function lockAndRescanPlacements<TUser extends {
|
|
31
|
+
id: DocId;
|
|
32
|
+
}>(req: PayloadRequest, exec: Executor, options: ResolvedOptions<TUser>, experiment: {
|
|
33
|
+
id: DocId;
|
|
34
|
+
slug: string;
|
|
35
|
+
kind: string;
|
|
36
|
+
arms: Arm[];
|
|
37
|
+
}, before: readonly BlockPlacement[], system?: boolean): Promise<{
|
|
38
|
+
placements: BlockPlacement[];
|
|
39
|
+
docs: PlacementDoc[];
|
|
40
|
+
}>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { placementDocumentPaths } from '../blocks/placementLocale.js';
|
|
2
|
+
import { sortLockKeys } from '../db/locks.js';
|
|
3
|
+
import { placementPathContent, placementTests } from '../db/placements.js';
|
|
4
|
+
import { lockPagePaths } from '../db/locks.js';
|
|
5
|
+
import { normalisePath } from '../runtime/normalisePath.js';
|
|
6
|
+
import { scanBlockPlacements } from './placements.js';
|
|
7
|
+
import { interactingTestsCopy } from '../testSurface/copy/readiness.js';
|
|
8
|
+
import { XpRefusal } from '../errors.js';
|
|
9
|
+
import { pageTargetPaths } from './checkStart.js';
|
|
10
|
+
export async function detached(req, fn) {
|
|
11
|
+
const transactionID = req.transactionID;
|
|
12
|
+
delete req.transactionID;
|
|
13
|
+
try {
|
|
14
|
+
return await fn();
|
|
15
|
+
} finally{
|
|
16
|
+
req.transactionID = transactionID;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function uniquePlacementDocs(placements) {
|
|
20
|
+
return [
|
|
21
|
+
...new Map(placements.map((p)=>[
|
|
22
|
+
JSON.stringify([
|
|
23
|
+
p.collection,
|
|
24
|
+
String(p.id)
|
|
25
|
+
]),
|
|
26
|
+
{
|
|
27
|
+
collection: p.collection,
|
|
28
|
+
id: p.id
|
|
29
|
+
}
|
|
30
|
+
])).values()
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
export function scanPlacements(req, options, slug, system = false) {
|
|
34
|
+
return scanBlockPlacements(req, {
|
|
35
|
+
slug,
|
|
36
|
+
puckCollections: options.puck?.collections ?? [],
|
|
37
|
+
blocksCollections: options.blocks?.collections ?? [],
|
|
38
|
+
system
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export async function placementPaths(req, options, docs) {
|
|
42
|
+
const paths = new Set();
|
|
43
|
+
for (const doc of docs){
|
|
44
|
+
const registration = options.pages?.collections.find((r)=>r.slug === doc.collection);
|
|
45
|
+
if (!registration) continue;
|
|
46
|
+
const row = await placementPathContent(req, doc.collection, doc.id);
|
|
47
|
+
if (!row || row._status === 'draft') continue;
|
|
48
|
+
for (const path of placementDocumentPaths(req, doc.collection, [
|
|
49
|
+
row
|
|
50
|
+
], 'all-locales', (doc)=>registration.pathOf(doc)))paths.add(normalisePath(path));
|
|
51
|
+
}
|
|
52
|
+
return sortLockKeys([
|
|
53
|
+
...paths
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
const active = (test)=>test.status === 'running' || test.status === 'decided';
|
|
57
|
+
export async function placementInteractions(req, exec, options, experiment, paths, system = false) {
|
|
58
|
+
const result = [];
|
|
59
|
+
for (const test of (await placementTests(exec))){
|
|
60
|
+
if (!active(test) || String(test.id) === String(experiment.id)) continue;
|
|
61
|
+
if (experiment.kind === 'block' && test.kind === 'page') {
|
|
62
|
+
for (const path of paths.filter((path)=>pageTargetPaths(test.arms).includes(path)))result.push({
|
|
63
|
+
experimentId: test.id,
|
|
64
|
+
slug: test.slug,
|
|
65
|
+
name: test.name,
|
|
66
|
+
status: test.status,
|
|
67
|
+
path,
|
|
68
|
+
version: test.arms.some((a)=>a.kind === 'variant' && a.pageTarget && normalisePath(a.pageTarget) === path)
|
|
69
|
+
});
|
|
70
|
+
} else if (experiment.kind === 'page' && test.kind === 'block') {
|
|
71
|
+
const docs = test.placementDocs ?? uniquePlacementDocs(await detached(req, ()=>scanPlacements(req, options, test.slug, system)));
|
|
72
|
+
const relevant = docs.filter((doc)=>!experiment.pageCollection || doc.collection === experiment.pageCollection);
|
|
73
|
+
for (const path of (await placementPaths(req, options, relevant)).filter((path)=>paths.includes(path)))result.push({
|
|
74
|
+
experimentId: test.id,
|
|
75
|
+
slug: test.slug,
|
|
76
|
+
name: test.name,
|
|
77
|
+
status: test.status,
|
|
78
|
+
path,
|
|
79
|
+
version: experiment.arms.some((a)=>a.kind === 'variant' && a.pageTarget && normalisePath(a.pageTarget) === path)
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
export async function lockAndRescanPlacements(req, exec, options, experiment, before, system = false) {
|
|
86
|
+
const paths = await placementPaths(req, options, uniquePlacementDocs(before));
|
|
87
|
+
await lockPagePaths(exec, paths);
|
|
88
|
+
const placements = await detached(req, ()=>scanPlacements(req, options, experiment.slug, system));
|
|
89
|
+
const docs = uniquePlacementDocs(placements);
|
|
90
|
+
const afterPaths = await placementPaths(req, options, docs);
|
|
91
|
+
if (afterPaths.some((path)=>!paths.includes(path))) throw new XpRefusal('placements-changed', "This test's pages changed while it was starting. Try again.", undefined, 409);
|
|
92
|
+
const conflicts = await placementInteractions(req, exec, options, experiment, paths, system);
|
|
93
|
+
if (conflicts.length) throw new XpRefusal('interacting-tests', interactingTestsCopy(conflicts[0].path, conflicts[0].status, conflicts[0].name, conflicts[0].version), conflicts, 409);
|
|
94
|
+
return {
|
|
95
|
+
placements,
|
|
96
|
+
docs
|
|
97
|
+
};
|
|
98
|
+
}
|