@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
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { sanitizeFallbackLocale } from 'payload';
|
|
2
|
+
import { fieldShouldBeLocalized, flattenTopLevelFields } from 'payload/shared';
|
|
3
|
+
import { documentEditor, puckCollections } from '../options.js';
|
|
4
|
+
import { placementSlugs } from './bindings.js';
|
|
5
|
+
import { contentBlocks, hasLocalizedFields } from '../transitions/contentFields.js';
|
|
6
|
+
import { isObject } from './model.js';
|
|
7
|
+
const identity = (data)=>data;
|
|
8
|
+
// Sanitized schemas are immutable. Weak ownership keeps separate Payload configs
|
|
9
|
+
// (and test harnesses) isolated; locale transforms survive individual readers/saves.
|
|
10
|
+
const localeTransforms = new WeakMap();
|
|
11
|
+
/** Compile only schema-marked localized branches. Opaque field values are never traversed.
|
|
12
|
+
* Copy ancestors only when a localized descendant changes; ordinary branches retain identity.
|
|
13
|
+
*/ function localeTransform(payloadConfig, collection, locale, fallback) {
|
|
14
|
+
const config = payloadConfig.collections?.find((entry)=>entry.slug === collection);
|
|
15
|
+
if (!payloadConfig.localization || !config) return identity;
|
|
16
|
+
let collections = localeTransforms.get(payloadConfig);
|
|
17
|
+
if (!collections) localeTransforms.set(payloadConfig, collections = new WeakMap());
|
|
18
|
+
let cached = collections.get(config);
|
|
19
|
+
if (!cached || cached.fields !== config.fields) collections.set(config, cached = {
|
|
20
|
+
fields: config.fields,
|
|
21
|
+
transforms: new Map()
|
|
22
|
+
});
|
|
23
|
+
const key = JSON.stringify([
|
|
24
|
+
locale,
|
|
25
|
+
fallback
|
|
26
|
+
]);
|
|
27
|
+
const existing = cached.transforms.get(key);
|
|
28
|
+
if (existing) return existing;
|
|
29
|
+
const blocks = payloadConfig.blocks ?? [];
|
|
30
|
+
const compiled = new Map();
|
|
31
|
+
function compile(fields, parentIsLocalized = false) {
|
|
32
|
+
if (parentIsLocalized) return (data)=>data;
|
|
33
|
+
const cached = compiled.get(fields);
|
|
34
|
+
if (cached) return cached;
|
|
35
|
+
let project;
|
|
36
|
+
const transform = (data, write, previous)=>project(data, write, previous);
|
|
37
|
+
compiled.set(fields, transform);
|
|
38
|
+
const steps = flattenTopLevelFields(fields).flatMap((field)=>{
|
|
39
|
+
if (!('name' in field) || !field.name) return [];
|
|
40
|
+
const name = field.name;
|
|
41
|
+
const localized = fieldShouldBeLocalized({
|
|
42
|
+
field,
|
|
43
|
+
parentIsLocalized
|
|
44
|
+
});
|
|
45
|
+
const parent = parentIsLocalized || localized;
|
|
46
|
+
const children = 'fields' in field && hasLocalizedFields(field.fields, payloadConfig) && [
|
|
47
|
+
'group',
|
|
48
|
+
'array',
|
|
49
|
+
'tab'
|
|
50
|
+
].includes(field.type) ? compile(field.fields, parent) : undefined;
|
|
51
|
+
const variants = field.type === 'blocks' ? new Map([
|
|
52
|
+
...field.blocks ?? [],
|
|
53
|
+
...field.blockReferences ?? []
|
|
54
|
+
].flatMap((ref)=>{
|
|
55
|
+
const block = typeof ref === 'string' ? blocks.find((block)=>block.slug === ref) : ref;
|
|
56
|
+
return block && hasLocalizedFields(block.fields, payloadConfig) ? [
|
|
57
|
+
[
|
|
58
|
+
block.slug,
|
|
59
|
+
compile(block.fields, parent)
|
|
60
|
+
]
|
|
61
|
+
] : [];
|
|
62
|
+
})) : undefined;
|
|
63
|
+
if (!localized && !children && !variants) return [];
|
|
64
|
+
return [
|
|
65
|
+
(data, write, previous)=>{
|
|
66
|
+
if (!(name in data)) return data;
|
|
67
|
+
let value = data[name];
|
|
68
|
+
const prior = previous?.[name];
|
|
69
|
+
if (localized && write) value = {
|
|
70
|
+
...isObject(prior) ? prior : {},
|
|
71
|
+
[locale]: value
|
|
72
|
+
};
|
|
73
|
+
else {
|
|
74
|
+
if (localized) {
|
|
75
|
+
const values = isObject(value) ? value : {};
|
|
76
|
+
value = values[locale];
|
|
77
|
+
if (fallback && fallback !== locale && (value == null || (field.type === 'text' || field.type === 'textarea') && value === '')) {
|
|
78
|
+
for (const code of Array.isArray(fallback) ? fallback : [
|
|
79
|
+
fallback
|
|
80
|
+
]){
|
|
81
|
+
const candidate = values[code];
|
|
82
|
+
if (candidate != null && candidate !== '') {
|
|
83
|
+
value = candidate;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const visit = (row, old)=>{
|
|
90
|
+
if (!isObject(row)) return row;
|
|
91
|
+
const transform = children ?? (variants && typeof row.blockType === 'string' ? variants.get(row.blockType) : undefined);
|
|
92
|
+
return transform ? transform(row, write, isObject(old) ? old : undefined) : row;
|
|
93
|
+
};
|
|
94
|
+
if (children || variants) {
|
|
95
|
+
if (Array.isArray(value)) {
|
|
96
|
+
const rows = value.map((row, index)=>visit(row, Array.isArray(prior) ? isObject(row) && row.id != null ? prior.find((old)=>isObject(old) && old.id === row.id) : prior[index] : undefined));
|
|
97
|
+
if (rows.some((row, index)=>row !== value[index])) value = rows;
|
|
98
|
+
} else value = visit(value, prior);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return value === data[name] ? data : {
|
|
102
|
+
...data,
|
|
103
|
+
[name]: value
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
];
|
|
107
|
+
});
|
|
108
|
+
project = (data, write = false, previous)=>steps.reduce((result, step)=>step(result, write, previous), data);
|
|
109
|
+
return transform;
|
|
110
|
+
}
|
|
111
|
+
const transform = hasLocalizedFields(config.fields ?? [], payloadConfig) ? compile(config.fields ?? []) : identity;
|
|
112
|
+
cached.transforms.set(key, transform);
|
|
113
|
+
return transform;
|
|
114
|
+
}
|
|
115
|
+
export function placementLocaleContent(req, collection, doc, input) {
|
|
116
|
+
return placementReader(req, collection).read(doc, input).doc;
|
|
117
|
+
}
|
|
118
|
+
/** The single document → locale view → editor/placements boundary. Compiled schemas are shared per sanitized config.
|
|
119
|
+
* Local API and form documents explicitly bypass all-locale projection.
|
|
120
|
+
*/ export function placementReader(req, collection, options = req.payload.config.custom?.xp) {
|
|
121
|
+
const views = placementLocaleViews(req, collection, options);
|
|
122
|
+
const transforms = new Map();
|
|
123
|
+
return {
|
|
124
|
+
views,
|
|
125
|
+
documentViews: schemaLocaleViews(req, collection),
|
|
126
|
+
read (doc, input, view) {
|
|
127
|
+
const requested = view ?? {
|
|
128
|
+
locale: req.locale ?? '',
|
|
129
|
+
fallbackLocale: req.fallbackLocale ?? false
|
|
130
|
+
};
|
|
131
|
+
const selected = requested.locale === 'all' ? {
|
|
132
|
+
...requested,
|
|
133
|
+
locale: req.payload.config.localization ? req.payload.config.localization.defaultLocale : ''
|
|
134
|
+
} : requested;
|
|
135
|
+
let content, resolved = false;
|
|
136
|
+
const resolve = ()=>{
|
|
137
|
+
if (resolved) return content;
|
|
138
|
+
resolved = true;
|
|
139
|
+
content = doc ?? undefined;
|
|
140
|
+
if (doc && input === 'all-locales' && req.payload.config.localization && selected.locale !== 'all') {
|
|
141
|
+
const locale = selected.locale || req.payload.config.localization.defaultLocale;
|
|
142
|
+
const key = JSON.stringify([
|
|
143
|
+
locale,
|
|
144
|
+
selected.fallbackLocale
|
|
145
|
+
]);
|
|
146
|
+
let transform = transforms.get(key);
|
|
147
|
+
if (!transform) {
|
|
148
|
+
transform = localeTransform(req.payload.config, collection, locale, sanitizeFallbackLocale({
|
|
149
|
+
fallbackLocale: selected.fallbackLocale,
|
|
150
|
+
locale,
|
|
151
|
+
localization: req.payload.config.localization
|
|
152
|
+
}));
|
|
153
|
+
transforms.set(key, transform);
|
|
154
|
+
}
|
|
155
|
+
content = transform(doc);
|
|
156
|
+
}
|
|
157
|
+
return content;
|
|
158
|
+
};
|
|
159
|
+
let editor, slugs;
|
|
160
|
+
return {
|
|
161
|
+
view: selected,
|
|
162
|
+
get doc () {
|
|
163
|
+
return resolve();
|
|
164
|
+
},
|
|
165
|
+
get editor () {
|
|
166
|
+
return editor ??= doc ? documentEditor(options ?? {}, collection, resolve()) : 'page';
|
|
167
|
+
},
|
|
168
|
+
get slugs () {
|
|
169
|
+
return slugs ??= placementSlugs(options ?? {}, collection, resolve());
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export function allPlacementSlugs(req, collection, doc, input) {
|
|
176
|
+
const reader = placementReader(req, collection);
|
|
177
|
+
return [
|
|
178
|
+
...new Set(reader.views.flatMap((view)=>reader.read(doc, input, view).slugs))
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
export const placementDocumentKey = (collection, id, view)=>JSON.stringify([
|
|
182
|
+
collection,
|
|
183
|
+
String(id),
|
|
184
|
+
view
|
|
185
|
+
]);
|
|
186
|
+
export function localeRequest(req, view) {
|
|
187
|
+
// Fetch Request properties are prototype getters and disappear in a spread.
|
|
188
|
+
// Local API setup needs headers/url; hooks also retain method and cancellation.
|
|
189
|
+
return {
|
|
190
|
+
...req,
|
|
191
|
+
headers: req.headers,
|
|
192
|
+
url: req.url,
|
|
193
|
+
method: req.method,
|
|
194
|
+
signal: req.signal,
|
|
195
|
+
...view
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/** Audits may contain localized arm-select tags outside registered editors. */ function schemaLocaleViews(req, collection) {
|
|
199
|
+
const localization = req.payload.config.localization;
|
|
200
|
+
const config = req.payload.config.collections?.find((entry)=>entry.slug === collection);
|
|
201
|
+
return localization && hasLocalizedFields(config?.fields ?? [], req.payload.config) ? (localization.localeCodes ?? localization.locales.map((entry)=>typeof entry === 'string' ? entry : entry.code)).map((locale)=>({
|
|
202
|
+
locale,
|
|
203
|
+
fallbackLocale: sanitizeFallbackLocale({
|
|
204
|
+
fallbackLocale: null,
|
|
205
|
+
locale,
|
|
206
|
+
localization
|
|
207
|
+
})
|
|
208
|
+
})) : [
|
|
209
|
+
{
|
|
210
|
+
locale: '',
|
|
211
|
+
fallbackLocale: false
|
|
212
|
+
}
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
/** Canonical views of registered content, without multiplying nonlocalized rows. */ export function placementLocaleViews(req, collection, options = req.payload.config.custom?.xp ?? {}) {
|
|
216
|
+
const localization = req.payload.config.localization;
|
|
217
|
+
const config = req.payload.config.collections?.find((entry)=>entry.slug === collection);
|
|
218
|
+
const names = new Set([
|
|
219
|
+
...puckCollections(options).filter((entry)=>entry.slug === collection).map((entry)=>entry.field),
|
|
220
|
+
...(options.blocks?.collections ?? []).filter((entry)=>entry.slug === collection).map((entry)=>entry.field)
|
|
221
|
+
]);
|
|
222
|
+
const localized = config && hasLocalizedFields(config.fields ?? [], req.payload.config) && (Boolean(options.blocks?.collections.some((entry)=>entry.slug === collection && entry.appliesTo)) || flattenTopLevelFields(config.fields ?? []).some((field)=>'name' in field && names.has(field.name) && ('localized' in field && field.localized || 'fields' in field && hasLocalizedFields(field.fields, req.payload.config) || field.type === 'blocks' && hasLocalizedFields(contentBlocks(field, req.payload.config.blocks).flatMap((block)=>block.fields), req.payload.config))));
|
|
223
|
+
return localization && localized ? (localization.localeCodes ?? localization.locales.map((entry)=>typeof entry === 'string' ? entry : entry.code)).map((locale)=>({
|
|
224
|
+
locale,
|
|
225
|
+
fallbackLocale: sanitizeFallbackLocale({
|
|
226
|
+
fallbackLocale: null,
|
|
227
|
+
locale,
|
|
228
|
+
localization
|
|
229
|
+
})
|
|
230
|
+
})) : [
|
|
231
|
+
{
|
|
232
|
+
locale: '',
|
|
233
|
+
fallbackLocale: false
|
|
234
|
+
}
|
|
235
|
+
];
|
|
236
|
+
}
|
|
237
|
+
/** Compare every locale view: a localized edit can also change fallback
|
|
238
|
+
* content in another locale. Whole-row removals replace every view with absence.
|
|
239
|
+
* The incoming hook document is already flattened to the writing locale.
|
|
240
|
+
*/ export function removedPlacementViews(req, collection, before, after, removingPage, input = 'localized') {
|
|
241
|
+
const result = new Map();
|
|
242
|
+
if (!before) return result;
|
|
243
|
+
const reader = placementReader(req, collection);
|
|
244
|
+
const rawAfter = input === 'all-locales' ? after : mergedPlacementLocales(req, collection, before, after);
|
|
245
|
+
for (const view of reader.views){
|
|
246
|
+
const previous = reader.read(before, 'all-locales', view).slugs;
|
|
247
|
+
const next = removingPage ? [] : reader.read(rawAfter, 'all-locales', view).slugs;
|
|
248
|
+
for (const slug of previous.filter((slug)=>!next.includes(slug)))result.set(slug, [
|
|
249
|
+
...result.get(slug) ?? [],
|
|
250
|
+
view
|
|
251
|
+
]);
|
|
252
|
+
}
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
255
|
+
/** Rebuild unchanged locale maps around a flattened hook write before reading each view. */ export function mergedPlacementLocales(req, collection, before, after) {
|
|
256
|
+
const localization = req.payload.config.localization;
|
|
257
|
+
if (!localization || req.locale === 'all') return after;
|
|
258
|
+
return localeTransform(req.payload.config, collection, req.locale || localization.defaultLocale, false)(after, true, before);
|
|
259
|
+
}
|
|
260
|
+
/** Project host document adapters before they run. Callers own path normalization
|
|
261
|
+
* and use sortLockKeys for the existing experiment → page-path lock ordering. */ export function placementDocumentPaths(req, collection, docs, input, pathOf) {
|
|
262
|
+
const reader = placementReader(req, collection);
|
|
263
|
+
return docs.flatMap((raw)=>reader.documentViews.flatMap((view)=>{
|
|
264
|
+
const doc = reader.read(raw, input, view).doc;
|
|
265
|
+
const path = doc ? pathOf(doc) : null;
|
|
266
|
+
return path === null ? [] : [
|
|
267
|
+
path
|
|
268
|
+
];
|
|
269
|
+
}));
|
|
270
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { ViewportExposure } from './ViewportExposure.js';
|
|
4
|
+
export function ExperimentGroup({ expose, children }) {
|
|
5
|
+
return /*#__PURE__*/ _jsx(ViewportExposure, {
|
|
6
|
+
expose: expose,
|
|
7
|
+
children: children
|
|
8
|
+
});
|
|
9
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useLayoutEffect, useRef } from 'react';
|
|
3
|
+
import { createContext, useContext, useLayoutEffect, useRef } from 'react';
|
|
4
4
|
import { registerApiRoute, unregisterApiRoute } from './beacon.js';
|
|
5
|
+
import { registerClickGoals, unregisterClickGoals } from './clickGoals.js';
|
|
5
6
|
import { ExperimentsContext } from './context.js';
|
|
7
|
+
const DepthContext = /*#__PURE__*/ createContext(0);
|
|
6
8
|
export function ExperimentsProvider(props) {
|
|
9
|
+
const depth = useContext(DepthContext) + 1;
|
|
7
10
|
const token = useRef(Symbol()).current;
|
|
8
11
|
// Register committed providers before descendants can send from passive effects.
|
|
9
12
|
useLayoutEffect(()=>{
|
|
@@ -15,8 +18,21 @@ export function ExperimentsProvider(props) {
|
|
|
15
18
|
useLayoutEffect(()=>()=>unregisterApiRoute(token), [
|
|
16
19
|
token
|
|
17
20
|
]);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
useLayoutEffect(()=>{
|
|
22
|
+
registerClickGoals(token, depth, props.value);
|
|
23
|
+
}, [
|
|
24
|
+
token,
|
|
25
|
+
depth,
|
|
26
|
+
props.value
|
|
27
|
+
]);
|
|
28
|
+
useLayoutEffect(()=>()=>unregisterClickGoals(token), [
|
|
29
|
+
token
|
|
30
|
+
]);
|
|
31
|
+
return /*#__PURE__*/ _jsx(DepthContext.Provider, {
|
|
32
|
+
value: depth,
|
|
33
|
+
children: /*#__PURE__*/ _jsx(ExperimentsContext.Provider, {
|
|
34
|
+
value: props.value,
|
|
35
|
+
children: props.children
|
|
36
|
+
})
|
|
21
37
|
});
|
|
22
38
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ClientAssignments } from '../types/assignments.js';
|
|
2
|
+
/** One delegated listener; depth, rather than React's child-first commit order, decides ownership. */
|
|
3
|
+
export declare function registerClickGoals(token: symbol, depth: number, value: ClientAssignments): void;
|
|
4
|
+
export declare function unregisterClickGoals(token: symbol): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { CLICK_KEY } from '../goals/key.js';
|
|
3
|
+
import { sendEvent } from './beacon.js';
|
|
4
|
+
import { idempotencyKey } from './idempotency.js';
|
|
5
|
+
const providers = new Map();
|
|
6
|
+
let listening;
|
|
7
|
+
function onClick(event) {
|
|
8
|
+
let owner;
|
|
9
|
+
for (const provider of providers.values()){
|
|
10
|
+
if (provider.value.clickGoalsArmed && (!owner || provider.depth >= owner.depth)) owner = provider;
|
|
11
|
+
}
|
|
12
|
+
if (!owner) return;
|
|
13
|
+
const target = event.target;
|
|
14
|
+
const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
|
|
15
|
+
const key = element?.closest('[data-xp-goal]')?.getAttribute('data-xp-goal');
|
|
16
|
+
if (!key || !CLICK_KEY.test(key)) return;
|
|
17
|
+
sendEvent(owner.value.apiRoute, {
|
|
18
|
+
type: 'conversion',
|
|
19
|
+
eventName: `click:${key}`,
|
|
20
|
+
idempotencyKey: `${owner.pageviewId}:${key}`
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** One delegated listener; depth, rather than React's child-first commit order, decides ownership. */ export function registerClickGoals(token, depth, value) {
|
|
24
|
+
const previous = providers.get(token);
|
|
25
|
+
const pageviewId = previous?.value === value ? previous.pageviewId : idempotencyKey();
|
|
26
|
+
providers.delete(token);
|
|
27
|
+
providers.set(token, {
|
|
28
|
+
depth,
|
|
29
|
+
value,
|
|
30
|
+
pageviewId
|
|
31
|
+
});
|
|
32
|
+
if (!listening && typeof document !== 'undefined') {
|
|
33
|
+
listening = document;
|
|
34
|
+
listening.addEventListener('click', onClick);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function unregisterClickGoals(token) {
|
|
38
|
+
providers.delete(token);
|
|
39
|
+
if (!providers.size && listening) {
|
|
40
|
+
listening.removeEventListener('click', onClick);
|
|
41
|
+
listening = undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SURFACE_COPY } from '../../testSurface/copy/surface.js';
|
|
1
2
|
import * as paths from '../../admin/paths.js';
|
|
2
3
|
import { managedAccess } from '../access.js';
|
|
3
4
|
import { serializeAttributeKeys, serializeFlagPoints } from '../serialize.js';
|
|
@@ -5,8 +6,9 @@ import { TARGETING_OPS, isOpValid } from '../../targeting/ops.js';
|
|
|
5
6
|
import { readListValue } from '../../targeting/values.js';
|
|
6
7
|
import { createDefaults } from './createDefaults.js';
|
|
7
8
|
import { flagControlParams } from './flagControlParams.js';
|
|
9
|
+
import { pickExperimentSlug } from './pickSlug.js';
|
|
8
10
|
import { lockHook } from './lockHook.js';
|
|
9
|
-
import { deleteGuard, deleteGuardAfter } from './deleteGuard.js';
|
|
11
|
+
import { deleteGuard, deleteGuardAfter, deleteGuardBeforeOperation } from './deleteGuard.js';
|
|
10
12
|
import { checkArms } from './armInvariants.js';
|
|
11
13
|
import { XpNotImplemented, XpRefusal } from '../../errors.js';
|
|
12
14
|
const targetingValue = (rule)=>rule.op === 'in' || rule.op === 'nin' ? readListValue(rule.value) : rule.value;
|
|
@@ -36,22 +38,30 @@ export function experimentsCollection(options) {
|
|
|
36
38
|
drafts: false,
|
|
37
39
|
maxPerDoc: 50
|
|
38
40
|
},
|
|
41
|
+
labels: {
|
|
42
|
+
singular: SURFACE_COPY.test,
|
|
43
|
+
plural: SURFACE_COPY.navAllTests
|
|
44
|
+
},
|
|
39
45
|
access: {
|
|
40
46
|
...managedAccess(options),
|
|
41
|
-
delete: async ({ req })=>
|
|
47
|
+
delete: async ({ req, id })=>{
|
|
48
|
+
if (await options.access.manage({
|
|
42
49
|
req
|
|
43
|
-
})
|
|
50
|
+
}) !== true) return false;
|
|
51
|
+
// Single deletes report status through the locked beforeDelete guard.
|
|
52
|
+
// Payload catches per-document hook failures in bulk deletes, so keep their status filter in access.
|
|
53
|
+
return id != null ? true : {
|
|
44
54
|
status: {
|
|
45
55
|
in: [
|
|
46
56
|
'draft',
|
|
47
57
|
'archived'
|
|
48
58
|
]
|
|
49
59
|
}
|
|
50
|
-
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
51
62
|
},
|
|
52
63
|
admin: {
|
|
53
|
-
|
|
54
|
-
group: false,
|
|
64
|
+
group: SURFACE_COPY.title,
|
|
55
65
|
useAsTitle: 'name',
|
|
56
66
|
defaultColumns: [
|
|
57
67
|
'name',
|
|
@@ -62,7 +72,7 @@ export function experimentsCollection(options) {
|
|
|
62
72
|
components: {
|
|
63
73
|
views: {
|
|
64
74
|
list: {
|
|
65
|
-
Component: paths.
|
|
75
|
+
Component: paths.XP_TESTS_COLLECTION_LIST
|
|
66
76
|
},
|
|
67
77
|
edit: {
|
|
68
78
|
default: {
|
|
@@ -81,12 +91,16 @@ export function experimentsCollection(options) {
|
|
|
81
91
|
}
|
|
82
92
|
},
|
|
83
93
|
hooks: {
|
|
94
|
+
beforeOperation: [
|
|
95
|
+
deleteGuardBeforeOperation
|
|
96
|
+
],
|
|
84
97
|
beforeValidate: [
|
|
85
98
|
createDefaults
|
|
86
99
|
],
|
|
87
100
|
beforeChange: [
|
|
88
101
|
flagControlParams,
|
|
89
|
-
lockHook
|
|
102
|
+
lockHook,
|
|
103
|
+
pickExperimentSlug
|
|
90
104
|
],
|
|
91
105
|
beforeDelete: [
|
|
92
106
|
deleteGuard
|
|
@@ -96,8 +110,8 @@ export function experimentsCollection(options) {
|
|
|
96
110
|
],
|
|
97
111
|
afterError: [
|
|
98
112
|
({ error })=>{
|
|
99
|
-
// Payload preserves public Error status/message, but omits custom codes.
|
|
100
|
-
if (error instanceof XpRefusal
|
|
113
|
+
// Payload preserves public Error status/message, but omits custom codes; the admin maps refusals by code.
|
|
114
|
+
if (error instanceof XpRefusal) {
|
|
101
115
|
return {
|
|
102
116
|
status: error.status,
|
|
103
117
|
response: {
|
|
@@ -166,6 +180,11 @@ export function experimentsCollection(options) {
|
|
|
166
180
|
read: async (args)=>args.doc?.kind !== 'code' || adminOnly(args)
|
|
167
181
|
}
|
|
168
182
|
},
|
|
183
|
+
{
|
|
184
|
+
name: 'pageCollection',
|
|
185
|
+
type: 'text',
|
|
186
|
+
validate: (value, { previousValue })=>value === previousValue || value == null || value === '' || options.pages?.collections.some((entry)=>entry.slug === value) || 'Choose a registered page collection.'
|
|
187
|
+
},
|
|
169
188
|
{
|
|
170
189
|
name: 'flagPoint',
|
|
171
190
|
type: 'text',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { CollectionAfterDeleteHook, CollectionBeforeDeleteHook } from 'payload';
|
|
1
|
+
import type { CollectionBeforeOperationHook, CollectionAfterDeleteHook, CollectionBeforeDeleteHook } from 'payload';
|
|
2
2
|
export declare const deleteGuard: CollectionBeforeDeleteHook;
|
|
3
3
|
export declare const deleteGuardAfter: CollectionAfterDeleteHook;
|
|
4
|
+
export declare const deleteGuardBeforeOperation: CollectionBeforeOperationHook;
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import { deleteExperiment, deleteExperimentAfter } from '../../transitions/deleteExperiment.js';
|
|
1
|
+
import { deleteExperiment, deleteExperimentAfter, prepareBulkDelete } from '../../transitions/deleteExperiment.js';
|
|
2
|
+
import { xpOptionsFromReq } from '../../options/fromReq.js';
|
|
2
3
|
export const deleteGuard = async ({ req, id })=>{
|
|
3
4
|
await deleteExperiment(req, id);
|
|
4
5
|
};
|
|
5
|
-
export const deleteGuardAfter = async ({ req,
|
|
6
|
-
await deleteExperimentAfter(req
|
|
6
|
+
export const deleteGuardAfter = async ({ req, doc })=>{
|
|
7
|
+
await deleteExperimentAfter(req);
|
|
7
8
|
return doc;
|
|
8
9
|
};
|
|
10
|
+
export const deleteGuardBeforeOperation = async ({ operation, args, req })=>{
|
|
11
|
+
if (operation === 'delete' && 'where' in args && args.where) {
|
|
12
|
+
// Payload runs beforeOperation before access; only a manager, or an explicit overrideAccess call, may make the plugin discover and lock the delete scope.
|
|
13
|
+
if (args.overrideAccess !== true && await xpOptionsFromReq(req).access.manage({
|
|
14
|
+
req
|
|
15
|
+
}) !== true) return args;
|
|
16
|
+
await prepareBulkDelete(req, args.where);
|
|
17
|
+
}
|
|
18
|
+
return args;
|
|
19
|
+
};
|
|
@@ -8,7 +8,8 @@ export const EDITABLE_BY_STATUS = {
|
|
|
8
8
|
'flagPoint',
|
|
9
9
|
'metrics',
|
|
10
10
|
'analysis',
|
|
11
|
-
'exposurePolicy'
|
|
11
|
+
'exposurePolicy',
|
|
12
|
+
'pageCollection'
|
|
12
13
|
],
|
|
13
14
|
stopped: [
|
|
14
15
|
'name',
|
|
@@ -18,7 +19,8 @@ export const EDITABLE_BY_STATUS = {
|
|
|
18
19
|
'allocation',
|
|
19
20
|
'metrics',
|
|
20
21
|
'analysis',
|
|
21
|
-
'exposurePolicy'
|
|
22
|
+
'exposurePolicy',
|
|
23
|
+
'pageCollection'
|
|
22
24
|
],
|
|
23
25
|
running: [
|
|
24
26
|
'name',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withSlotsFor } from '../../arms/model.js';
|
|
1
2
|
import { XpLockedFieldError, XpRefusal } from '../../errors.js';
|
|
2
3
|
import { XP_IF_UPDATED_AT_HEADER } from '../../constants.js';
|
|
3
4
|
import { txExecutor } from '../../db/executor.js';
|
|
@@ -64,6 +65,24 @@ const dates = new Set([
|
|
|
64
65
|
}
|
|
65
66
|
const same = (a, b, path)=>JSON.stringify(normalize(a, path)) === JSON.stringify(normalize(b, path));
|
|
66
67
|
export const lockHook = async ({ data, originalDoc, operation, req })=>{
|
|
68
|
+
const kind = operation === 'create' ? data.kind : originalDoc.kind;
|
|
69
|
+
const storedArms = operation === 'update' ? originalDoc.arms : undefined;
|
|
70
|
+
const canonicalSlots = (value)=>{
|
|
71
|
+
if (kind !== 'block' || !Array.isArray(value) || value.some((row)=>!isObject(row))) return value;
|
|
72
|
+
return withSlotsFor(value, 'block');
|
|
73
|
+
};
|
|
74
|
+
const canonicalArms = canonicalSlots(storedArms);
|
|
75
|
+
// Payload runs collection beforeChange before field validation on Create,
|
|
76
|
+
// Update and Restore. Derive slots here so the arms validator sees them.
|
|
77
|
+
const arms = data.arms === undefined ? storedArms : data.arms;
|
|
78
|
+
const repaired = arms === storedArms ? canonicalArms : canonicalSlots(arms);
|
|
79
|
+
if (repaired !== arms) {
|
|
80
|
+
if (operation === 'create') data = {
|
|
81
|
+
...data,
|
|
82
|
+
arms: repaired
|
|
83
|
+
};
|
|
84
|
+
else data.arms = repaired;
|
|
85
|
+
}
|
|
67
86
|
if (req.context.xpTransition === true) return data;
|
|
68
87
|
const baseline = req.headers.get(XP_IF_UPDATED_AT_HEADER);
|
|
69
88
|
if (operation === 'update' && baseline !== null) {
|
|
@@ -71,7 +90,7 @@ export const lockHook = async ({ data, originalDoc, operation, req })=>{
|
|
|
71
90
|
// so a competing save observes the preceding save's committed timestamp.
|
|
72
91
|
const stored = await lockExperimentUpdatedAt(txExecutor(req), originalDoc.id);
|
|
73
92
|
if (stored === null || new Date(baseline).getTime() !== new Date(stored).getTime()) {
|
|
74
|
-
throw new XpRefusal('stale-edit', '
|
|
93
|
+
throw new XpRefusal('stale-edit', 'This test changed. Read the latest settings and try again.', undefined, 409);
|
|
75
94
|
}
|
|
76
95
|
}
|
|
77
96
|
const admin = async ()=>{
|
|
@@ -139,7 +158,7 @@ export const lockHook = async ({ data, originalDoc, operation, req })=>{
|
|
|
139
158
|
].includes(field) && isObject(value)) {
|
|
140
159
|
for (const [key, nested] of Object.entries(value))await check(`${field}.${key}`, nested, originalDoc[field]?.[key]);
|
|
141
160
|
} else {
|
|
142
|
-
await check(field, value, originalDoc[field]);
|
|
161
|
+
await check(field, value, field === 'arms' ? canonicalArms : originalDoc[field]);
|
|
143
162
|
// Replacing the group also changes its method, including clearing it.
|
|
144
163
|
if (field === 'analysis' && !same(value, originalDoc.analysis, field) && originalDoc.analysis?.method != null && !await admin()) throw new XpLockedFieldError('analysis.method', status);
|
|
145
164
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { assertReadCommitted } from '../../db/adapter.js';
|
|
2
|
+
import { pickSlug } from '../../db/slugs.js';
|
|
3
|
+
import { pooledExecutor, txExecutor } from '../../db/executor.js';
|
|
4
|
+
export const pickExperimentSlug = async ({ req, data, operation })=>{
|
|
5
|
+
if (operation !== 'create' || typeof data.slug !== 'string' || !data.slug) return data;
|
|
6
|
+
const transactional = await req.transactionID != null;
|
|
7
|
+
if (transactional) await assertReadCommitted(req);
|
|
8
|
+
data.slug = await pickSlug(transactional ? txExecutor(req) : pooledExecutor(req.payload), data.slug, transactional);
|
|
9
|
+
return data;
|
|
10
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Payload labels may be translated strings or functions. Keep server entries dependency-safe. */ export function collectionLabel(label, slug, req) {
|
|
2
|
+
try {
|
|
3
|
+
if (typeof label === 'function') {
|
|
4
|
+
const value = label({
|
|
5
|
+
i18n: req.i18n,
|
|
6
|
+
t: req.i18n.t
|
|
7
|
+
});
|
|
8
|
+
return typeof value === 'string' ? value : slug;
|
|
9
|
+
}
|
|
10
|
+
if (typeof label === 'string') return label;
|
|
11
|
+
const translations = label && typeof label === 'object' ? label : {};
|
|
12
|
+
return [
|
|
13
|
+
translations[req.i18n?.language ?? 'en'],
|
|
14
|
+
translations.en,
|
|
15
|
+
...Object.values(translations)
|
|
16
|
+
].find((value)=>typeof value === 'string') ?? slug;
|
|
17
|
+
} catch {
|
|
18
|
+
return slug;
|
|
19
|
+
}
|
|
20
|
+
}
|