@delmaredigital/payload-experiments 0.4.0-rc.1 → 0.4.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +284 -772
- package/dist/admin/LayerUsage.js +1 -1
- package/dist/admin/MetricSourceSelect.js +12 -5
- package/dist/admin/PlacementStatus.js +1 -1
- package/dist/admin/TestsDashboardCards.d.ts +1 -0
- package/dist/admin/TestsDashboardCards.js +5 -9
- package/dist/admin/TestsNavLink.d.ts +1 -0
- package/dist/admin/TestsNavLink.js +5 -11
- package/dist/admin/blocks/BlockPanel.d.ts +1 -0
- package/dist/admin/blocks/BlockPanel.js +129 -37
- package/dist/admin/blocks/TestBlockField.js +3 -3
- package/dist/admin/blocks/formApi.d.ts +3 -0
- package/dist/admin/blocks/formApi.js +10 -4
- package/dist/admin/blocks/inject.js +1 -0
- package/dist/admin/blocks/model.d.ts +3 -2
- package/dist/admin/blocks/model.js +10 -6
- package/dist/admin/blocks/statusCache.d.ts +2 -0
- package/dist/admin/blocks/statusCache.js +12 -3
- package/dist/admin/components/RootViewMessage.js +1 -1
- package/dist/admin/copy/blocks.d.ts +21 -1
- package/dist/admin/copy/blocks.js +40 -6
- package/dist/admin/copy/goals.d.ts +21 -9
- package/dist/admin/copy/goals.js +28 -11
- package/dist/admin/copy/newTest.d.ts +7 -7
- package/dist/admin/copy/newTest.js +10 -7
- package/dist/admin/goals/XpGoalField.d.ts +2 -0
- package/dist/admin/goals/XpGoalField.js +156 -114
- package/dist/admin/goals/xpGoalField.css +47 -0
- package/dist/admin/pageCollections.d.ts +1 -0
- package/dist/admin/pageCollections.js +3 -0
- package/dist/admin/paths.d.ts +3 -0
- package/dist/admin/paths.js +3 -0
- package/dist/admin/placementStatus.model.js +1 -1
- package/dist/admin/status.model.js +1 -1
- package/dist/admin/surface/ResultsRoute.d.ts +2 -1
- package/dist/admin/surface/ResultsRoute.js +20 -24
- package/dist/admin/surface/SurfaceShell.d.ts +4 -2
- package/dist/admin/surface/SurfaceShell.js +29 -4
- package/dist/admin/surface/TestRowMenu.d.ts +13 -0
- package/dist/admin/surface/TestRowMenu.js +163 -0
- package/dist/admin/surface/TestsHome.d.ts +5 -3
- package/dist/admin/surface/TestsHome.js +273 -58
- package/dist/admin/surface/TestsSurface.js +8 -7
- package/dist/admin/surface/goals/DeleteGoalDialog.d.ts +7 -0
- package/dist/admin/surface/goals/DeleteGoalDialog.js +42 -0
- package/dist/admin/surface/goals/GoalForm.d.ts +2 -1
- package/dist/admin/surface/goals/GoalForm.js +342 -212
- package/dist/admin/surface/goals/GoalsList.d.ts +1 -1
- package/dist/admin/surface/goals/GoalsList.js +107 -37
- package/dist/admin/surface/goals/data.d.ts +2 -0
- package/dist/admin/surface/goals/data.js +11 -2
- package/dist/admin/surface/goals/goals.css +9 -1
- package/dist/admin/surface/goals/goals.model.d.ts +12 -2
- package/dist/admin/surface/goals/goals.model.js +39 -1
- package/dist/admin/surface/home.model.d.ts +10 -8
- package/dist/admin/surface/home.model.js +27 -22
- package/dist/admin/surface/newTest/NewTest.d.ts +4 -4
- package/dist/admin/surface/newTest/NewTest.js +149 -118
- package/dist/admin/surface/newTest/PageWizard.d.ts +5 -2
- package/dist/admin/surface/newTest/PageWizard.js +115 -80
- package/dist/admin/surface/newTest/newTest.css +28 -9
- package/dist/admin/surface/results/ResultsHeader.d.ts +3 -3
- package/dist/admin/surface/results/ResultsHeader.js +115 -83
- package/dist/admin/surface/surface.css +29 -0
- package/dist/admin/surface/test/TestPage.d.ts +1 -2
- package/dist/admin/surface/test/TestPage.js +44 -152
- package/dist/admin/surface/useXpStepNav.d.ts +11 -0
- package/dist/admin/surface/useXpStepNav.js +14 -0
- package/dist/admin/theme.css +2 -0
- package/dist/admin/views/CollectionListRedirect.d.ts +1 -0
- package/dist/admin/views/CollectionListRedirect.js +1 -1
- package/dist/admin/views/ExperimentsRootView.js +18 -165
- package/dist/admin/views/GoalEditRedirect.d.ts +4 -0
- package/dist/admin/views/GoalEditRedirect.js +14 -0
- package/dist/admin/views/GoalsCollectionListView.d.ts +2 -0
- package/dist/admin/views/GoalsCollectionListView.js +4 -0
- package/dist/admin/views/TestsCollectionListView.d.ts +2 -0
- package/dist/admin/views/TestsCollectionListView.js +4 -0
- package/dist/admin/views/TestsNavLinkServer.d.ts +1 -0
- package/dist/admin/views/TestsNavLinkServer.js +2 -2
- package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
- package/dist/admin/views/TestsSurfaceClient.js +35 -0
- package/dist/admin/views/buildSurfaceProps.d.ts +8 -0
- package/dist/admin/views/buildSurfaceProps.js +102 -0
- package/dist/admin/views/renderCollectionList.d.ts +2 -0
- package/dist/admin/views/renderCollectionList.js +34 -0
- package/dist/admin/views/renderTestsSurface.d.ts +3 -0
- package/dist/admin/views/renderTestsSurface.js +34 -0
- package/dist/blocks/bindings.js +8 -14
- package/dist/blocks/createExperimentBlock.js +1 -1
- package/dist/blocks/formState.js +2 -2
- package/dist/blocks/placementLanguages.d.ts +7 -0
- package/dist/blocks/placementLanguages.js +27 -0
- package/dist/blocks/placementLocale.d.ts +37 -0
- package/dist/blocks/placementLocale.js +270 -0
- package/dist/collections/experiments/config.js +17 -8
- package/dist/collections/experiments/deleteGuard.js +2 -2
- package/dist/collections/experiments/lockHook.js +21 -2
- package/dist/collections/experiments/pickSlug.js +2 -0
- package/dist/collections/metrics.js +28 -9
- package/dist/collections/metricsGuards.js +2 -0
- package/dist/collections/serialize.js +8 -6
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/db/adapter.d.ts +9 -1
- package/dist/db/adapter.js +77 -1
- package/dist/db/appends.d.ts +13 -0
- package/dist/db/appends.js +49 -0
- package/dist/db/bulkPlacementRemoval.d.ts +30 -0
- package/dist/db/bulkPlacementRemoval.js +111 -0
- package/dist/db/delete.d.ts +1 -1
- package/dist/db/delete.js +2 -4
- package/dist/db/events.d.ts +9 -0
- package/dist/db/events.js +42 -8
- package/dist/db/executor.d.ts +7 -1
- package/dist/db/executor.js +7 -3
- package/dist/db/pageCopies.d.ts +5 -0
- package/dist/db/pageCopies.js +31 -0
- package/dist/db/placements.d.ts +2 -0
- package/dist/db/placements.js +8 -0
- package/dist/db/results.d.ts +5 -1
- package/dist/db/results.js +21 -5
- package/dist/db/snapshots.d.ts +2 -0
- package/dist/endpoints/contentLocale.d.ts +6 -0
- package/dist/endpoints/contentLocale.js +15 -0
- package/dist/endpoints/deleteImpact.d.ts +6 -0
- package/dist/endpoints/deleteImpact.js +207 -0
- package/dist/endpoints/duplicateOriginal.d.ts +38 -0
- package/dist/endpoints/duplicateOriginal.js +407 -0
- package/dist/endpoints/editorSurface.d.ts +3 -0
- package/dist/endpoints/editorSurface.js +31 -0
- package/dist/endpoints/events.js +103 -39
- package/dist/endpoints/index.js +57 -9
- package/dist/endpoints/pages.js +247 -64
- package/dist/endpoints/placementStatus.js +13 -5
- package/dist/endpoints/preflight.d.ts +1 -1
- package/dist/endpoints/preflight.js +17 -2
- package/dist/endpoints/results.d.ts +1 -1
- package/dist/endpoints/results.js +6 -2
- package/dist/endpoints/routeId.d.ts +2 -2
- package/dist/endpoints/routeId.js +11 -5
- package/dist/endpoints/summary.js +46 -12
- package/dist/endpoints/testVersion.d.ts +2 -0
- package/dist/endpoints/testVersion.js +38 -0
- package/dist/endpoints/transitions.js +41 -29
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +8 -0
- package/dist/events/request.d.ts +6 -2
- package/dist/events/request.js +35 -8
- package/dist/events/rows.d.ts +1 -1
- package/dist/events/rows.js +24 -8
- package/dist/events/writable.d.ts +9 -0
- package/dist/events/writable.js +13 -0
- package/dist/exports/adminClient.d.ts +1 -1
- package/dist/exports/adminClient.js +1 -1
- package/dist/exports/adminRsc.d.ts +3 -0
- package/dist/exports/adminRsc.js +3 -0
- package/dist/exports/index.d.ts +1 -1
- package/dist/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +1 -0
- package/dist/fields/xpGoal.js +3 -15
- package/dist/goals/fairness.d.ts +1 -1
- package/dist/goals/fairness.js +44 -35
- package/dist/goals/picker/clickGoalPicker.model.d.ts +8 -1
- package/dist/goals/picker/clickGoalPicker.model.js +20 -2
- package/dist/goals/picker/copy.d.ts +6 -2
- package/dist/goals/picker/copy.js +11 -2
- package/dist/goals/picker/useClickGoalPicker.d.ts +1 -1
- package/dist/goals/picker/useClickGoalPicker.js +4 -2
- package/dist/goals/sourceLabel.d.ts +2 -0
- package/dist/goals/sourceLabel.js +4 -0
- package/dist/goals/validate.d.ts +3 -0
- package/dist/goals/validate.js +15 -0
- package/dist/hooks/blockRemovalRule.d.ts +30 -0
- package/dist/hooks/blockRemovalRule.js +165 -0
- package/dist/hooks/hostHook.js +6 -2
- package/dist/hooks/pageGuard.d.ts +27 -2
- package/dist/hooks/pageGuard.js +213 -45
- package/dist/hooks/puckGoals.d.ts +5 -0
- package/dist/hooks/puckGoals.js +62 -0
- package/dist/hooks/puckNestedTests.d.ts +8 -0
- package/dist/hooks/puckNestedTests.js +36 -0
- package/dist/hooks/trackPageCopies.d.ts +11 -0
- package/dist/hooks/trackPageCopies.js +7 -0
- package/dist/lib/fetchAllDocs.d.ts +1 -1
- package/dist/lib/placementPages.d.ts +10 -0
- package/dist/{admin/previewLinks.model.js → lib/placementPages.js} +10 -5
- package/dist/manifest/compile.d.ts +2 -1
- package/dist/manifest/compile.js +13 -6
- package/dist/onInit.js +36 -0
- package/dist/options.d.ts +2 -0
- package/dist/options.js +23 -2
- package/dist/plugin.js +70 -21
- package/dist/proxy/pageNavigation.d.ts +4 -0
- package/dist/proxy/pageNavigation.js +28 -0
- package/dist/proxy/resolve.js +52 -25
- package/dist/puck/ExperimentPicker.d.ts +2 -1
- package/dist/puck/ExperimentPicker.js +62 -40
- package/dist/puck/ExperimentSlot.js +3 -1
- package/dist/puck/copy.d.ts +5 -1
- package/dist/puck/copy.js +5 -1
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +25 -0
- package/dist/puck/editor/ConfigureTestDrawer.js +150 -0
- package/dist/puck/editor/CreateExperimentDrawer.d.ts +12 -2
- package/dist/puck/editor/CreateExperimentDrawer.js +89 -21
- package/dist/puck/editor/EditorControls.d.ts +14 -0
- package/dist/puck/editor/EditorControls.js +99 -0
- package/dist/puck/editor/ExperimentSlotEditor.d.ts +2 -1
- package/dist/puck/editor/ExperimentSlotEditor.js +1007 -182
- package/dist/puck/editor/LeftoverVersions.d.ts +15 -0
- package/dist/puck/editor/LeftoverVersions.js +79 -0
- package/dist/puck/editor/PlacementNotice.d.ts +8 -0
- package/dist/puck/editor/PlacementNotice.js +22 -0
- package/dist/puck/editor/QuickTestActions.d.ts +6 -0
- package/dist/puck/editor/QuickTestActions.js +72 -0
- package/dist/puck/editor/ResultsReadout.d.ts +4 -1
- package/dist/puck/editor/ResultsReadout.js +35 -19
- package/dist/puck/editor/VersionBuilder.d.ts +67 -12
- package/dist/puck/editor/VersionBuilder.js +560 -231
- package/dist/puck/editor/armWrites.d.ts +11 -2
- package/dist/puck/editor/armWrites.js +43 -4
- package/dist/puck/editor/armsCache.d.ts +3 -1
- package/dist/puck/editor/armsCache.js +20 -4
- package/dist/puck/editor/blockClipboard.d.ts +16 -0
- package/dist/puck/editor/blockClipboard.js +20 -0
- package/dist/puck/editor/cloneSlot.d.ts +2 -0
- package/dist/puck/editor/cloneSlot.js +7 -0
- package/dist/puck/editor/copy.d.ts +65 -20
- package/dist/puck/editor/copy.js +73 -21
- package/dist/puck/editor/createTest.d.ts +3 -0
- package/dist/puck/editor/createTest.js +33 -0
- package/dist/puck/editor/editor.chrome.css +200 -20
- package/dist/puck/editor/editor.css +338 -25
- package/dist/puck/editor/editor.model.d.ts +17 -1
- package/dist/puck/editor/editor.model.js +61 -4
- package/dist/puck/editor/editorSurface.d.ts +10 -0
- package/dist/puck/editor/editorSurface.js +65 -0
- package/dist/puck/editor/experimentOutlinePlugin.js +96 -28
- package/dist/puck/editor/localPlacements.d.ts +5 -0
- package/dist/puck/editor/localPlacements.js +43 -0
- package/dist/puck/editor/outlineVersion.d.ts +5 -0
- package/dist/puck/editor/outlineVersion.js +36 -0
- package/dist/puck/editor/placementsCache.d.ts +60 -0
- package/dist/puck/editor/placementsCache.js +263 -0
- package/dist/puck/editor/sidebar.d.ts +8 -0
- package/dist/puck/editor/sidebar.js +74 -0
- package/dist/puck/editor/usePageSaveReadiness.d.ts +6 -0
- package/dist/puck/editor/usePageSaveReadiness.js +31 -0
- package/dist/puck/editor/usePlacementNotice.d.ts +3 -0
- package/dist/puck/editor/usePlacementNotice.js +15 -0
- package/dist/puck/editor/xpGoalPuckEditorField.js +105 -86
- package/dist/puck/experimentSlotField.d.ts +3 -0
- package/dist/puck/experimentSlotField.js +15 -4
- package/dist/puck/experimentSlug.d.ts +2 -0
- package/dist/puck/experimentSlug.js +3 -0
- package/dist/puck/nestedTestCopy.d.ts +8 -0
- package/dist/puck/nestedTestCopy.js +22 -0
- package/dist/puck/nestedTests.d.ts +17 -0
- package/dist/puck/nestedTests.js +30 -0
- package/dist/puck/slotConfig.d.ts +2 -2
- package/dist/puck/slotConfig.js +18 -5
- package/dist/puck/visibility.d.ts +20 -0
- package/dist/puck/visibility.js +81 -0
- package/dist/results/aggregate.d.ts +6 -3
- package/dist/results/aggregate.js +9 -9
- package/dist/results/analyse.d.ts +2 -0
- package/dist/results/analyse.js +2 -2
- package/dist/results/health.d.ts +8 -0
- package/dist/results/health.js +28 -0
- package/dist/results/identityCredit.d.ts +1 -0
- package/dist/results/identityCredit.js +4 -1
- package/dist/results/verdict.d.ts +1 -1
- package/dist/results/verdict.js +9 -7
- package/dist/runtime/cookie.d.ts +10 -2
- package/dist/runtime/cookie.js +38 -6
- package/dist/runtime/cookieOptions.d.ts +6 -0
- package/dist/runtime/cookieOptions.js +14 -0
- package/dist/runtime/proxyRuntime.d.ts +1 -0
- package/dist/runtime/proxyRuntime.js +18 -8
- package/dist/runtime/signing.d.ts +1 -0
- package/dist/runtime/signing.js +5 -0
- package/dist/sanitizeReadinessDetail.d.ts +2 -2
- package/dist/sanitizeReadinessDetail.js +22 -2
- package/dist/server/getAssignments.js +11 -10
- package/dist/server/recordContentChange.d.ts +1 -1
- package/dist/server/recordContentChange.js +48 -22
- package/dist/server/resolveExperimentBlocks.js +2 -4
- package/dist/server/resolveExperimentData.js +8 -8
- package/dist/server/runResults.js +54 -15
- package/dist/server/startExperiment.d.ts +20 -0
- package/dist/server/startExperiment.js +70 -0
- package/dist/server/trackConversion.js +10 -13
- package/dist/{admin → testSurface}/PreviewLinks.d.ts +2 -1
- package/dist/{admin → testSurface}/PreviewLinks.js +9 -5
- package/dist/testSurface/actions/DecideDialog.d.ts +17 -0
- package/dist/testSurface/actions/DecideDialog.js +222 -0
- package/dist/testSurface/actions/LifecycleAction.d.ts +17 -0
- package/dist/testSurface/actions/LifecycleAction.js +107 -0
- package/dist/{admin → testSurface}/actions/MakeContentResult.d.ts +4 -3
- package/dist/{admin → testSurface}/actions/MakeContentResult.js +10 -2
- package/dist/{admin → testSurface}/actions/actions.model.d.ts +13 -5
- package/dist/testSurface/actions/actions.model.js +123 -0
- package/dist/{admin → testSurface}/actions/decide.model.d.ts +1 -0
- package/dist/{admin → testSurface}/actions/decide.model.js +1 -0
- package/dist/{admin → testSurface}/allocation.model.js +6 -3
- package/dist/{admin → testSurface}/api.d.ts +20 -7
- package/dist/{admin → testSurface}/api.js +72 -22
- package/dist/testSurface/contentLocaleURL.d.ts +2 -0
- package/dist/testSurface/contentLocaleURL.js +3 -0
- package/dist/{admin → testSurface}/copy/actions.d.ts +37 -14
- package/dist/{admin → testSurface}/copy/actions.js +40 -17
- package/dist/{admin → testSurface}/copy/advanced.d.ts +10 -0
- package/dist/{admin → testSurface}/copy/advanced.js +10 -0
- package/dist/{admin → testSurface}/copy/arms.d.ts +1 -1
- package/dist/{admin → testSurface}/copy/arms.js +1 -1
- package/dist/{admin → testSurface}/copy/audience.d.ts +4 -3
- package/dist/{admin → testSurface}/copy/audience.js +5 -4
- package/dist/{admin → testSurface}/copy/common.d.ts +15 -6
- package/dist/{admin → testSurface}/copy/common.js +20 -10
- package/dist/testSurface/copy/languages.d.ts +12 -0
- package/dist/testSurface/copy/languages.js +8 -0
- package/dist/{admin → testSurface}/copy/metrics.d.ts +7 -0
- package/dist/testSurface/copy/metrics.js +18 -0
- package/dist/testSurface/copy/pages.d.ts +84 -0
- package/dist/testSurface/copy/pages.js +90 -0
- package/dist/{admin → testSurface}/copy/readiness.d.ts +40 -6
- package/dist/{admin → testSurface}/copy/readiness.js +54 -9
- package/dist/{admin → testSurface}/copy/recommendation.d.ts +4 -4
- package/dist/{admin → testSurface}/copy/recommendation.js +4 -4
- package/dist/{admin → testSurface}/copy/results.d.ts +19 -12
- package/dist/{admin → testSurface}/copy/results.js +21 -12
- package/dist/testSurface/copy/review.d.ts +20 -0
- package/dist/testSurface/copy/review.js +21 -0
- package/dist/{admin → testSurface}/copy/setting.d.ts +1 -2
- package/dist/{admin → testSurface}/copy/setting.js +1 -2
- package/dist/{admin → testSurface}/copy/surface.d.ts +11 -2
- package/dist/{admin → testSurface}/copy/surface.js +14 -11
- package/dist/{admin → testSurface}/copy/testPage.d.ts +61 -12
- package/dist/testSurface/copy/testPage.js +168 -0
- package/dist/testSurface/format/adminURL.d.ts +7 -0
- package/dist/testSurface/format/adminURL.js +9 -0
- package/dist/{admin → testSurface}/format/date.d.ts +1 -0
- package/dist/testSurface/format/date.js +21 -0
- package/dist/{admin → testSurface}/labels.d.ts +1 -2
- package/dist/{admin → testSurface}/labels.js +2 -3
- package/dist/{admin → testSurface}/lockedNotice.model.d.ts +2 -0
- package/dist/{admin → testSurface}/lockedNotice.model.js +31 -0
- package/dist/testSurface/placementLabel.d.ts +8 -0
- package/dist/testSurface/placementLabel.js +24 -0
- package/dist/{admin → testSurface}/placements/placementLabels.d.ts +2 -0
- package/dist/{admin → testSurface}/placements/placementLabels.js +3 -2
- package/dist/{admin → testSurface}/previewLinks.model.d.ts +1 -6
- package/dist/testSurface/previewLinks.model.js +4 -0
- package/dist/testSurface/readPreflight.d.ts +13 -0
- package/dist/testSurface/readPreflight.js +44 -0
- package/dist/testSurface/readinessRead.d.ts +53 -0
- package/dist/testSurface/readinessRead.js +50 -0
- package/dist/{admin → testSurface}/results/VerdictHero.d.ts +2 -1
- package/dist/{admin → testSurface}/results/VerdictHero.js +5 -1
- package/dist/testSurface/results/results.css +64 -0
- package/dist/{admin → testSurface}/results/results.model.d.ts +3 -2
- package/dist/{admin → testSurface}/results/results.model.js +16 -11
- package/dist/{admin → testSurface}/surface/contracts.d.ts +17 -3
- package/dist/testSurface/surface/editorPlacement.d.ts +26 -0
- package/dist/testSurface/surface/editorPlacement.js +78 -0
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +9 -0
- package/dist/testSurface/surface/pageBlock/parts.js +107 -0
- package/dist/testSurface/surface/pagePicker/CopyRoute.d.ts +13 -0
- package/dist/testSurface/surface/pagePicker/CopyRoute.js +273 -0
- package/dist/testSurface/surface/pagePicker/PageCombobox.d.ts +21 -0
- package/dist/testSurface/surface/pagePicker/PageCombobox.js +498 -0
- package/dist/testSurface/surface/pagePicker/pagePicker.css +73 -0
- package/dist/{admin → testSurface}/surface/pagePicker/pagePicker.model.d.ts +7 -3
- package/dist/{admin → testSurface}/surface/pagePicker/pagePicker.model.js +17 -2
- package/dist/{admin → testSurface}/surface/readiness/ActionDialogs.d.ts +9 -5
- package/dist/testSurface/surface/readiness/ActionDialogs.js +372 -0
- package/dist/{admin → testSurface}/surface/readiness/Banner.d.ts +4 -3
- package/dist/testSurface/surface/readiness/Banner.js +198 -0
- package/dist/testSurface/surface/readiness/BlockerList.d.ts +11 -0
- package/dist/testSurface/surface/readiness/BlockerList.js +31 -0
- package/dist/testSurface/surface/readiness/SaveStatus.d.ts +13 -0
- package/dist/testSurface/surface/readiness/SaveStatus.js +67 -0
- package/dist/{admin → testSurface}/surface/readiness/parts.js +0 -2
- package/dist/{admin → testSurface}/surface/readiness/readiness.model.d.ts +28 -2
- package/dist/testSurface/surface/readiness/readiness.model.js +377 -0
- package/dist/testSurface/surface/readiness/useTransition.d.ts +16 -0
- package/dist/testSurface/surface/readiness/useTransition.js +141 -0
- package/dist/{admin → testSurface}/surface/results/ReleasePages.d.ts +6 -3
- package/dist/{admin → testSurface}/surface/results/ReleasePages.js +40 -40
- package/dist/{admin → testSurface}/surface/results/ResultsBody.d.ts +11 -4
- package/dist/{admin → testSurface}/surface/results/ResultsBody.js +207 -104
- package/dist/{admin → testSurface}/surface/results/recommendation.model.js +3 -3
- package/dist/{admin → testSurface}/surface/results/useResults.d.ts +26 -8
- package/dist/{admin → testSurface}/surface/results/useResults.js +3 -2
- package/dist/{admin → testSurface}/surface/setting/parts.js +89 -46
- package/dist/testSurface/surface/setting/setting.css +18 -0
- package/dist/{admin → testSurface}/surface/test/AdvancedSection.js +12 -4
- package/dist/testSurface/surface/test/DeleteTest.d.ts +23 -0
- package/dist/testSurface/surface/test/DeleteTest.js +270 -0
- package/dist/testSurface/surface/test/GoalSection.d.ts +4 -0
- package/dist/{admin → testSurface}/surface/test/GoalSection.js +119 -89
- package/dist/testSurface/surface/test/LengthSection.d.ts +2 -0
- package/dist/{admin → testSurface}/surface/test/LengthSection.js +25 -14
- package/dist/{admin → testSurface}/surface/test/PageHoldout.d.ts +1 -1
- package/dist/{admin → testSurface}/surface/test/PageHoldout.js +11 -8
- package/dist/{admin → testSurface}/surface/test/Rail.js +7 -4
- package/dist/{admin → testSurface}/surface/test/ReadinessBar.d.ts +2 -1
- package/dist/{admin → testSurface}/surface/test/ReadinessBar.js +4 -11
- package/dist/{admin → testSurface}/surface/test/Section.d.ts +3 -1
- package/dist/testSurface/surface/test/Section.js +88 -0
- package/dist/{admin → testSurface}/surface/test/TargetingSection.js +87 -12
- package/dist/testSurface/surface/test/TestSurface.d.ts +19 -0
- package/dist/testSurface/surface/test/TestSurface.js +265 -0
- package/dist/testSurface/surface/test/VersionsSection.d.ts +5 -0
- package/dist/testSurface/surface/test/VersionsSection.js +301 -0
- package/dist/{admin → testSurface}/surface/test/fields.d.ts +33 -9
- package/dist/testSurface/surface/test/fields.js +300 -0
- package/dist/{admin → testSurface}/surface/test/pageParts.js +30 -44
- package/dist/testSurface/surface/test/testPage.css +111 -0
- package/dist/{admin → testSurface}/surface/test/testPage.model.d.ts +1 -0
- package/dist/{admin → testSurface}/surface/test/testPage.model.js +6 -0
- package/dist/{admin → testSurface}/surface/testDocument.model.d.ts +3 -0
- package/dist/{admin → testSurface}/surface/testDocument.model.js +4 -1
- package/dist/testSurface/surface/useTestDocument.d.ts +60 -0
- package/dist/testSurface/surface/useTestDocument.js +782 -0
- package/dist/testSurface/surface/watchTestDocument.d.ts +15 -0
- package/dist/testSurface/surface/watchTestDocument.js +181 -0
- package/dist/testSurface/surfaceUrls.d.ts +8 -0
- package/dist/testSurface/surfaceUrls.js +23 -0
- package/dist/{admin → testSurface}/useApi.d.ts +21 -5
- package/dist/testSurface/useOnTestReturn.d.ts +2 -0
- package/dist/testSurface/useOnTestReturn.js +27 -0
- package/dist/testSurface/useReadinessPolling.d.ts +3 -0
- package/dist/testSurface/useReadinessPolling.js +26 -0
- package/dist/transitions/addMetric.d.ts +2 -5
- package/dist/transitions/addMetric.js +5 -1
- package/dist/transitions/allocate.d.ts +2 -2
- package/dist/transitions/allocate.js +3 -1
- package/dist/transitions/archive.d.ts +1 -1
- package/dist/transitions/archive.js +3 -2
- package/dist/transitions/checkStart.d.ts +6 -1
- package/dist/transitions/checkStart.js +133 -17
- package/dist/transitions/contentFields.js +9 -5
- package/dist/transitions/decide.d.ts +1 -1
- package/dist/transitions/decide.js +6 -3
- package/dist/transitions/deleteExperiment.d.ts +2 -2
- package/dist/transitions/deleteExperiment.js +17 -7
- package/dist/transitions/kernel.d.ts +4 -0
- package/dist/transitions/kernel.js +9 -4
- package/dist/transitions/makeContent.d.ts +2 -1
- package/dist/transitions/makeContent.js +41 -17
- package/dist/transitions/nestedPlacementNames.d.ts +5 -0
- package/dist/transitions/nestedPlacementNames.js +32 -0
- package/dist/transitions/pageAddress.d.ts +6 -0
- package/dist/transitions/pageAddress.js +71 -0
- package/dist/transitions/pageVersions.js +3 -1
- package/dist/transitions/phaseRecord.d.ts +2 -0
- package/dist/transitions/phaseRecord.js +5 -0
- package/dist/transitions/placementInteractions.d.ts +3 -3
- package/dist/transitions/placementInteractions.js +16 -12
- package/dist/transitions/placements.d.ts +54 -8
- package/dist/transitions/placements.js +304 -81
- package/dist/transitions/preflightData.d.ts +5 -3
- package/dist/transitions/preflightData.js +137 -40
- package/dist/transitions/releaseHoldout.d.ts +2 -1
- package/dist/transitions/releaseHoldout.js +3 -1
- package/dist/transitions/releasePages.d.ts +2 -1
- package/dist/transitions/releasePages.js +3 -1
- package/dist/transitions/resolveCaps.d.ts +2 -4
- package/dist/transitions/start.d.ts +6 -8
- package/dist/transitions/start.js +72 -35
- package/dist/transitions/startReads.d.ts +7 -0
- package/dist/transitions/startReads.js +28 -0
- package/dist/transitions/stop.d.ts +2 -1
- package/dist/transitions/stop.js +3 -2
- package/dist/types/contracts.d.ts +15 -3
- package/dist/types/endpoints.d.ts +121 -17
- package/dist/types/puck.d.ts +1 -0
- package/dist/types/runtime.d.ts +15 -9
- package/dist/types/snapshot.d.ts +2 -0
- package/dist/types/surface.d.ts +9 -9
- package/dist/ui/Button.js +2 -2
- package/dist/ui/Card.d.ts +2 -1
- package/dist/ui/Card.js +4 -4
- package/dist/ui/ChipsInput.d.ts +8 -1
- package/dist/ui/ChipsInput.js +17 -4
- package/dist/ui/Dialog.d.ts +24 -2
- package/dist/ui/Dialog.js +141 -6
- package/dist/ui/Drawer.d.ts +10 -0
- package/dist/ui/Drawer.js +29 -0
- package/dist/ui/Inputs.d.ts +4 -3
- package/dist/ui/Inputs.js +6 -4
- package/dist/ui/SelectControl.d.ts +33 -0
- package/dist/ui/SelectControl.js +504 -0
- package/dist/ui/Tabs.d.ts +4 -4
- package/dist/ui/Tabs.js +35 -32
- package/dist/ui/ui.css +50 -5
- package/package.json +3 -2
- package/dist/admin/actions/ConfirmDialog.d.ts +0 -19
- package/dist/admin/actions/ConfirmDialog.js +0 -149
- package/dist/admin/actions/DecideDialog.d.ts +0 -10
- package/dist/admin/actions/DecideDialog.js +0 -190
- package/dist/admin/actions/actions.model.js +0 -70
- package/dist/admin/copy/metrics.js +0 -9
- package/dist/admin/copy/pages.d.ts +0 -26
- package/dist/admin/copy/pages.js +0 -26
- package/dist/admin/copy/review.d.ts +0 -17
- package/dist/admin/copy/review.js +0 -17
- package/dist/admin/copy/testPage.js +0 -104
- package/dist/admin/format/date.js +0 -10
- package/dist/admin/results/results.css +0 -64
- package/dist/admin/styles.css +0 -10
- package/dist/admin/styles.d.ts +0 -2
- package/dist/admin/styles.js +0 -3
- package/dist/admin/surface/pageBlock/pageBlock.model.js +0 -8
- package/dist/admin/surface/pageBlock/parts.js +0 -69
- package/dist/admin/surface/pagePicker/CopyRoute.d.ts +0 -6
- package/dist/admin/surface/pagePicker/CopyRoute.js +0 -53
- package/dist/admin/surface/pagePicker/PagePicker.d.ts +0 -10
- package/dist/admin/surface/pagePicker/PagePicker.js +0 -172
- package/dist/admin/surface/readiness/ActionDialogs.js +0 -337
- package/dist/admin/surface/readiness/Banner.js +0 -190
- package/dist/admin/surface/readiness/SaveStatus.d.ts +0 -5
- package/dist/admin/surface/readiness/SaveStatus.js +0 -53
- package/dist/admin/surface/readiness/readiness.model.js +0 -205
- package/dist/admin/surface/readiness/useTransition.d.ts +0 -11
- package/dist/admin/surface/readiness/useTransition.js +0 -35
- package/dist/admin/surface/setting/setting.css +0 -17
- package/dist/admin/surface/test/GoalSection.d.ts +0 -2
- package/dist/admin/surface/test/LengthSection.d.ts +0 -2
- package/dist/admin/surface/test/Section.js +0 -47
- package/dist/admin/surface/test/VersionsSection.d.ts +0 -4
- package/dist/admin/surface/test/VersionsSection.js +0 -247
- package/dist/admin/surface/test/fields.js +0 -216
- package/dist/admin/surface/test/testPage.css +0 -97
- package/dist/admin/surface/useTestDocument.d.ts +0 -32
- package/dist/admin/surface/useTestDocument.js +0 -415
- /package/dist/{admin → testSurface}/allocation.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/arms.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/arms.model.js +0 -0
- /package/dist/{admin → testSurface}/arms/pageTarget.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/pageTarget.model.js +0 -0
- /package/dist/{admin → testSurface}/arms/params.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/params.model.js +0 -0
- /package/dist/{admin → testSurface}/metricSource.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/metricSource.model.js +0 -0
- /package/dist/{admin → testSurface}/placements/placementLabels.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/placements/placementLabels.model.js +0 -0
- /package/dist/{admin → testSurface}/placements/usePlacementLabels.d.ts +0 -0
- /package/dist/{admin → testSurface}/placements/usePlacementLabels.js +0 -0
- /package/dist/{admin → testSurface}/reload.d.ts +0 -0
- /package/dist/{admin → testSurface}/reload.js +0 -0
- /package/dist/{admin → testSurface}/results/CappedCell.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/CappedCell.js +0 -0
- /package/dist/{admin → testSurface}/results/CiChart.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/CiChart.js +0 -0
- /package/dist/{admin → testSurface}/results/DataQualityPanel.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/DataQualityPanel.js +0 -0
- /package/dist/{admin → testSurface}/results/DataTable.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/DataTable.js +0 -0
- /package/dist/{admin → testSurface}/results/StatTile.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/StatTile.js +0 -0
- /package/dist/{admin → testSurface}/results/chart.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/chart.model.js +0 -0
- /package/dist/{admin → testSurface}/results/format.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/format.js +0 -0
- /package/dist/{admin → testSurface}/results/legacy.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/legacy.js +0 -0
- /package/dist/{admin → testSurface}/results/releasePages.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/releasePages.model.js +0 -0
- /package/dist/{admin → testSurface}/results/snapshot.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/snapshot.js +0 -0
- /package/dist/{admin → testSurface}/review/review.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/review/review.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/contracts.js +0 -0
- /package/dist/{admin → testSurface}/surface/pageBlock/pageBlock.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pageBlock/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/recommendation.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/setting/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/setting/setting.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/setting/setting.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/AdvancedSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/Rail.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/TargetingSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/jumpToSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/jumpToSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/pageParts.d.ts +0 -0
- /package/dist/{admin → testSurface}/targeting/targeting.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/targeting/targeting.model.js +0 -0
- /package/dist/{admin → testSurface}/theme.d.ts +0 -0
- /package/dist/{admin → testSurface}/theme.js +0 -0
- /package/dist/{admin → testSurface}/useApi.js +0 -0
|
@@ -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
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { assertReadCommitted } from '../../db/adapter.js';
|
|
1
2
|
import { pickSlug } from '../../db/slugs.js';
|
|
2
3
|
import { pooledExecutor, txExecutor } from '../../db/executor.js';
|
|
3
4
|
export const pickExperimentSlug = async ({ req, data, operation })=>{
|
|
4
5
|
if (operation !== 'create' || typeof data.slug !== 'string' || !data.slug) return data;
|
|
5
6
|
const transactional = await req.transactionID != null;
|
|
7
|
+
if (transactional) await assertReadCommitted(req);
|
|
6
8
|
data.slug = await pickSlug(transactional ? txExecutor(req) : pooledExecutor(req.payload), data.slug, transactional);
|
|
7
9
|
return data;
|
|
8
10
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { SURFACE_COPY } from '../testSurface/copy/surface.js';
|
|
1
2
|
import { CLICK_KEY, isClickSource, validClickSource } from '../goals/key.js';
|
|
2
|
-
import { XP_METRIC_SOURCE_SELECT } from '../admin/paths.js';
|
|
3
|
+
import { XP_METRIC_SOURCE_SELECT, XP_GOALS_COLLECTION_LIST, XP_GOAL_EDIT_REDIRECT } from '../admin/paths.js';
|
|
3
4
|
import { managedAccess } from './access.js';
|
|
4
5
|
import { serializeMetricSources } from './serialize.js';
|
|
5
6
|
import { validateCappingType, validateCappingValue } from './metricValidation.js';
|
|
@@ -11,14 +12,31 @@ export function metricsCollection(options) {
|
|
|
11
12
|
graphQL: false,
|
|
12
13
|
disableDuplicate: true,
|
|
13
14
|
versions: false,
|
|
14
|
-
// group:false hides navigation while keeping collection routes reachable (hidden causes 404s).
|
|
15
15
|
labels: {
|
|
16
16
|
singular: 'Goal',
|
|
17
17
|
plural: 'Goals'
|
|
18
18
|
},
|
|
19
19
|
admin: {
|
|
20
|
-
group:
|
|
21
|
-
useAsTitle: 'name'
|
|
20
|
+
group: SURFACE_COPY.title,
|
|
21
|
+
useAsTitle: 'name',
|
|
22
|
+
meta: {
|
|
23
|
+
title: {
|
|
24
|
+
absolute: 'Goals · Tests'
|
|
25
|
+
},
|
|
26
|
+
titleSuffix: ''
|
|
27
|
+
},
|
|
28
|
+
components: {
|
|
29
|
+
views: {
|
|
30
|
+
list: {
|
|
31
|
+
Component: XP_GOALS_COLLECTION_LIST
|
|
32
|
+
},
|
|
33
|
+
edit: {
|
|
34
|
+
default: {
|
|
35
|
+
Component: XP_GOAL_EDIT_REDIRECT
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
22
40
|
},
|
|
23
41
|
access: managedAccess(options),
|
|
24
42
|
hooks: {
|
|
@@ -42,11 +60,12 @@ export function metricsCollection(options) {
|
|
|
42
60
|
const source = sources.find((source)=>source.id === (data.source ?? originalDoc?.source));
|
|
43
61
|
const capping = data.capping === undefined ? originalDoc?.capping : data.capping;
|
|
44
62
|
// Payload may submit an empty optional group as { type: null, value: null }.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
63
|
+
if (source?.kind === 'revenue' && capping?.type == null && capping?.value == null) {
|
|
64
|
+
data.capping = {
|
|
65
|
+
type: 'percentile',
|
|
66
|
+
value: 0.99
|
|
67
|
+
};
|
|
68
|
+
}
|
|
50
69
|
return data;
|
|
51
70
|
}
|
|
52
71
|
]
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertReadCommitted } from '../db/adapter.js';
|
|
1
2
|
import { pooledExecutor, txExecutor } from '../db/executor.js';
|
|
2
3
|
import { findMetricUsage, lockMetricRow } from '../db/metricUsage.js';
|
|
3
4
|
/** Payload's REST formatter preserves public plugin errors and their 4xx status. */ export class XpGoalInUseError extends Error {
|
|
@@ -8,6 +9,7 @@ import { findMetricUsage, lockMetricRow } from '../db/metricUsage.js';
|
|
|
8
9
|
async function executor(req, id, mode) {
|
|
9
10
|
const transactionID = await req.transactionID;
|
|
10
11
|
if (transactionID != null) {
|
|
12
|
+
await assertReadCommitted(req);
|
|
11
13
|
const exec = txExecutor(req);
|
|
12
14
|
await lockMetricRow(exec, id, mode);
|
|
13
15
|
return exec;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { browserWritableMetric } from '../events/writable.js';
|
|
2
|
+
import { goalSourceLabel } from '../goals/sourceLabel.js';
|
|
1
3
|
export function serializeFlagPoints(options) {
|
|
2
4
|
return (options.flagPoints ?? []).map(({ id, label, description, params, defaultParams })=>({
|
|
3
5
|
id,
|
|
@@ -19,19 +21,19 @@ export function serializeMetricSources(options) {
|
|
|
19
21
|
keyedBy: 'visitor',
|
|
20
22
|
clientWritable: true
|
|
21
23
|
},
|
|
22
|
-
...(options.metricSources ?? []).map(({ id, label, kind, keyedBy
|
|
24
|
+
...(options.metricSources ?? []).map(({ id, label, kind, keyedBy })=>({
|
|
23
25
|
id,
|
|
24
|
-
label,
|
|
26
|
+
label: label?.trim() || goalSourceLabel(id),
|
|
25
27
|
kind,
|
|
26
28
|
keyedBy,
|
|
27
|
-
clientWritable:
|
|
29
|
+
clientWritable: browserWritableMetric(id, options)
|
|
28
30
|
})),
|
|
29
|
-
...(options.eventSources ?? []).map(({ name
|
|
31
|
+
...(options.eventSources ?? []).map(({ name })=>({
|
|
30
32
|
id: `events:${name}`,
|
|
31
|
-
label: name,
|
|
33
|
+
label: goalSourceLabel(name),
|
|
32
34
|
kind: 'binomial',
|
|
33
35
|
keyedBy: 'visitor',
|
|
34
|
-
clientWritable
|
|
36
|
+
clientWritable: browserWritableMetric(`events:${name}`, options)
|
|
35
37
|
}))
|
|
36
38
|
];
|
|
37
39
|
}
|
package/dist/constants.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export declare const XP_PREVIEW_PARAM = "xp_preview";
|
|
|
7
7
|
export declare const XP_MANIFEST_KEY_HEADER = "x-xp-manifest-key";
|
|
8
8
|
export declare const XP_REQUEST_HEADER = "x-xp-request";
|
|
9
9
|
export declare const XP_IF_UPDATED_AT_HEADER = "x-xp-if-updated-at";
|
|
10
|
+
export declare const USER_BROWSER_CONVERSION_PREFIX = "conversion:cu:";
|
package/dist/constants.js
CHANGED
|
@@ -7,3 +7,4 @@ export const XP_PREVIEW_PARAM = 'xp_preview';
|
|
|
7
7
|
export const XP_MANIFEST_KEY_HEADER = 'x-xp-manifest-key';
|
|
8
8
|
export const XP_REQUEST_HEADER = 'x-xp-request';
|
|
9
9
|
export const XP_IF_UPDATED_AT_HEADER = 'x-xp-if-updated-at';
|
|
10
|
+
export const USER_BROWSER_CONVERSION_PREFIX = 'conversion:cu:';
|
package/dist/db/adapter.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { APIError, type Payload, type PayloadRequest } from 'payload';
|
|
2
|
+
export declare class XpTransactionIsolationError extends APIError {
|
|
3
|
+
constructor();
|
|
4
|
+
}
|
|
5
|
+
/** Payload's initTransaction cannot pass options to the adapter. Like that
|
|
6
|
+
* helper, publish the pending transaction on the request before awaiting it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function initTransitionTransaction(req: PayloadRequest): Promise<boolean>;
|
|
9
|
+
export declare function assertReadCommitted(req: PayloadRequest): Promise<void>;
|
|
2
10
|
export declare function assertPostgresAdapter(payload: Payload): void;
|
|
3
11
|
export declare function probeTransactions(payload: Payload): Promise<void>;
|
package/dist/db/adapter.js
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
import { XpNoTransactionError } from '../errors.js';
|
|
3
|
+
import { API_MESSAGES } from '../testSurface/copy/common.js';
|
|
4
|
+
import { transactionSession, txExecutor } from './executor.js';
|
|
5
|
+
const transitionIsolation = 'read committed';
|
|
6
|
+
const isolationMessage = 'Experiments requires PostgreSQL READ COMMITTED so it can see changes committed while waiting for locks. Set the Postgres adapter\'s transactionOptions.isolationLevel to "read committed" or remove the override.';
|
|
7
|
+
const checkedSessions = new WeakMap();
|
|
8
|
+
export class XpTransactionIsolationError extends APIError {
|
|
9
|
+
constructor(){
|
|
10
|
+
super(API_MESSAGES.transactionIsolation, 500, null, true);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Payload's initTransaction cannot pass options to the adapter. Like that
|
|
14
|
+
* helper, publish the pending transaction on the request before awaiting it.
|
|
15
|
+
*/ export async function initTransitionTransaction(req) {
|
|
16
|
+
if (req.transactionID != null) {
|
|
17
|
+
await req.transactionID;
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const db = req.payload.db;
|
|
21
|
+
const pending = db.beginTransaction({
|
|
22
|
+
...db.transactionOptions || {},
|
|
23
|
+
isolationLevel: transitionIsolation
|
|
24
|
+
}).then((id)=>{
|
|
25
|
+
if (id == null) throw new XpNoTransactionError();
|
|
26
|
+
const session = db.sessions?.[id];
|
|
27
|
+
if (session) checkedSessions.set(session, Promise.resolve());
|
|
28
|
+
req.transactionID = id;
|
|
29
|
+
return id;
|
|
30
|
+
});
|
|
31
|
+
req.transactionID = pending;
|
|
32
|
+
try {
|
|
33
|
+
await pending;
|
|
34
|
+
return true;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (req.transactionID === pending) delete req.transactionID;
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** A borrowed transaction may already have taken its snapshot. Check the
|
|
41
|
+
* effective isolation on that session before relying on a post-lock read.
|
|
42
|
+
*/ async function isReadCommitted(exec) {
|
|
43
|
+
const { rows } = await exec.query('SHOW transaction_isolation');
|
|
44
|
+
const level = rows[0]?.transaction_isolation;
|
|
45
|
+
// PostgreSQL implements READ UNCOMMITTED as READ COMMITTED (docs §13.2).
|
|
46
|
+
return level === transitionIsolation || level === 'read uncommitted';
|
|
47
|
+
}
|
|
48
|
+
export async function assertReadCommitted(req) {
|
|
49
|
+
const transaction = {
|
|
50
|
+
payload: req.payload,
|
|
51
|
+
transactionID: await req.transactionID
|
|
52
|
+
};
|
|
53
|
+
// The adapter resolves the ID to a unique session object until commit or
|
|
54
|
+
// rollback. Cache the pending check so concurrent hooks share the same query.
|
|
55
|
+
const session = await transactionSession(transaction);
|
|
56
|
+
let checked = checkedSessions.get(session);
|
|
57
|
+
if (!checked) {
|
|
58
|
+
checked = isReadCommitted(txExecutor(transaction)).then((valid)=>{
|
|
59
|
+
if (!valid) {
|
|
60
|
+
try {
|
|
61
|
+
console.error('Experiments requires PostgreSQL READ COMMITTED so it can see changes committed while waiting for locks. Set the Postgres adapter\'s transactionOptions.isolationLevel to "read committed" or remove the override.');
|
|
62
|
+
} catch {}
|
|
63
|
+
throw new XpTransactionIsolationError();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
checkedSessions.set(session, checked);
|
|
67
|
+
}
|
|
68
|
+
await checked;
|
|
69
|
+
}
|
|
1
70
|
export function assertPostgresAdapter(payload) {
|
|
2
71
|
// @payloadcms/db-postgres/dist/index.js:133 declares this package marker.
|
|
3
72
|
if (payload.db.packageName !== '@payloadcms/db-postgres') throw new Error('Experiments requires @payloadcms/db-postgres');
|
|
@@ -5,5 +74,12 @@ export function assertPostgresAdapter(payload) {
|
|
|
5
74
|
export async function probeTransactions(payload) {
|
|
6
75
|
const id = await payload.db.beginTransaction();
|
|
7
76
|
if (id == null) throw new Error('Experiments transactions are disabled');
|
|
8
|
-
|
|
77
|
+
try {
|
|
78
|
+
if (!await isReadCommitted(txExecutor({
|
|
79
|
+
payload,
|
|
80
|
+
transactionID: id
|
|
81
|
+
}))) throw new Error(isolationMessage);
|
|
82
|
+
} finally{
|
|
83
|
+
await payload.db.rollbackTransaction(id);
|
|
84
|
+
}
|
|
9
85
|
}
|
package/dist/db/appends.d.ts
CHANGED
|
@@ -24,6 +24,19 @@ type AppendArgs<T> = {
|
|
|
24
24
|
* before the audit savepoint can recover.
|
|
25
25
|
*/
|
|
26
26
|
export declare function storedContent(req: PayloadRequest, collection: string, id: DocId): Promise<Record<string, unknown> | undefined>;
|
|
27
|
+
export interface PlacementSavePath {
|
|
28
|
+
versionId?: DocId;
|
|
29
|
+
bulk?: boolean;
|
|
30
|
+
draft?: boolean;
|
|
31
|
+
trashing?: boolean;
|
|
32
|
+
publishSpecificLocale?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Payload 3.90.2: updateByID starts from the latest version; update (bulk)
|
|
35
|
+
* starts from main rows except draft/trash saves. utilities/update then replaces
|
|
36
|
+
* unselected locales with the latest published version (publishSpecificLocale).
|
|
37
|
+
* Localized publication status is refused at init. Restore uses the selected version. */
|
|
38
|
+
export declare function placementMergeBase(path: PlacementSavePath): 'restore' | 'main' | 'published' | 'latest';
|
|
39
|
+
export declare function placementWriteContent(req: PayloadRequest, collection: string, id: DocId, main: Record<string, unknown> | undefined, path?: PlacementSavePath): Promise<Record<string, unknown> | undefined>;
|
|
27
40
|
/** Read the main collection row BEFORE the host write. Draft version retention
|
|
28
41
|
* and unpublishing cannot remove this baseline.
|
|
29
42
|
*/
|
package/dist/db/appends.js
CHANGED
|
@@ -18,6 +18,55 @@ import { qualifiedTable, quoteIdentifier as quote } from './sql.js';
|
|
|
18
18
|
});
|
|
19
19
|
return doc ?? undefined;
|
|
20
20
|
}
|
|
21
|
+
/** Payload 3.90.2: updateByID starts from the latest version; update (bulk)
|
|
22
|
+
* starts from main rows except draft/trash saves. utilities/update then replaces
|
|
23
|
+
* unselected locales with the latest published version (publishSpecificLocale).
|
|
24
|
+
* Localized publication status is refused at init. Restore uses the selected version. */ export function placementMergeBase(path) {
|
|
25
|
+
if (path.versionId != null) return 'restore';
|
|
26
|
+
if (path.publishSpecificLocale) return 'published';
|
|
27
|
+
return path.bulk && !path.draft && !path.trashing ? 'main' : 'latest';
|
|
28
|
+
}
|
|
29
|
+
export async function placementWriteContent(req, collection, id, main, path = {}) {
|
|
30
|
+
const config = req.payload.config.collections?.find((entry)=>entry.slug === collection);
|
|
31
|
+
if (!config?.versions || !config.versions.drafts) return main;
|
|
32
|
+
const base = placementMergeBase(path);
|
|
33
|
+
if (base === 'main') return main;
|
|
34
|
+
// Adapter read on the guarded write's transaction; no Local API hook recursion.
|
|
35
|
+
const latest = await req.payload.db.findVersions({
|
|
36
|
+
collection,
|
|
37
|
+
req,
|
|
38
|
+
limit: 1,
|
|
39
|
+
pagination: false,
|
|
40
|
+
sort: '-updatedAt',
|
|
41
|
+
where: base === 'restore' ? {
|
|
42
|
+
id: {
|
|
43
|
+
equals: path.versionId
|
|
44
|
+
}
|
|
45
|
+
} : {
|
|
46
|
+
and: [
|
|
47
|
+
{
|
|
48
|
+
parent: {
|
|
49
|
+
equals: id
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
base === 'published' ? {
|
|
53
|
+
'version._status': {
|
|
54
|
+
equals: 'published'
|
|
55
|
+
}
|
|
56
|
+
} : {
|
|
57
|
+
latest: {
|
|
58
|
+
equals: true
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
overrideAccess: false
|
|
64
|
+
});
|
|
65
|
+
return latest.docs[0] ? {
|
|
66
|
+
...latest.docs[0].version,
|
|
67
|
+
id
|
|
68
|
+
} : base === 'published' ? undefined : main;
|
|
69
|
+
}
|
|
21
70
|
/** Read the main collection row BEFORE the host write. Draft version retention
|
|
22
71
|
* and unpublishing cannot remove this baseline.
|
|
23
72
|
*/ export async function previousPublishedContent(req, collection, id) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PayloadRequest, Where } from 'payload';
|
|
2
|
+
import { type PlacementLocaleView } from '../blocks/placementLocale.js';
|
|
3
|
+
import type { DocId } from '../types/contracts.js';
|
|
4
|
+
export interface BulkPlacementRemoval {
|
|
5
|
+
documents: Set<string>;
|
|
6
|
+
change?: {
|
|
7
|
+
collection: string;
|
|
8
|
+
data?: Record<string, unknown>;
|
|
9
|
+
draft: boolean;
|
|
10
|
+
deleting: boolean;
|
|
11
|
+
};
|
|
12
|
+
refusals: Map<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export declare function usesBulkDocumentTransactions(req: PayloadRequest): boolean;
|
|
15
|
+
/** A distinct operation identity without copying the transaction/context. Native
|
|
16
|
+
* Request accessors and methods must use the original receiver.
|
|
17
|
+
*/
|
|
18
|
+
export declare function placementOperationRequest(req: PayloadRequest, fields: Map<PropertyKey, unknown>, failed?: () => void): PayloadRequest;
|
|
19
|
+
/** Observe Payload's actual, access-filtered bulk selection before it dispatches
|
|
20
|
+
* any document hooks. This request-only proxy adds no reads and never replaces
|
|
21
|
+
* the shared adapter. Matching the original Where node avoids capturing nested
|
|
22
|
+
* access-hook reads. queryDrafts prefixes keys but preserves condition objects.
|
|
23
|
+
* Payload 3's update/delete operations select the entire set before Promise.all.
|
|
24
|
+
*/
|
|
25
|
+
export declare function bulkPlacementRequest(req: PayloadRequest, collection: string, where: Where, data: Record<string, unknown> | undefined, draft: boolean, deleting: boolean, bulk: BulkPlacementRemoval): PayloadRequest;
|
|
26
|
+
/** Evaluate the common change against the published row seen under E, rather
|
|
27
|
+
* than a draft version or a selection snapshot from before the lock. */
|
|
28
|
+
export declare function bulkRemoves(bulk: BulkPlacementRemoval | undefined, req: PayloadRequest, collection: string, doc: Record<string, unknown> & {
|
|
29
|
+
id: DocId;
|
|
30
|
+
}, slug: string, view: PlacementLocaleView): boolean;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { placementLocaleContent, mergedPlacementLocales, removedPlacementViews, placementDocumentKey } from '../blocks/placementLocale.js';
|
|
2
|
+
// Payload starts/ends a transaction per bulk document with this adapter option.
|
|
3
|
+
export function usesBulkDocumentTransactions(req) {
|
|
4
|
+
return req.payload.db.bulkOperationsSingleTransaction === true;
|
|
5
|
+
}
|
|
6
|
+
const operationRequestState = Symbol('xpPlacementRequestState');
|
|
7
|
+
/** A distinct operation identity without copying the transaction/context. Native
|
|
8
|
+
* Request accessors and methods must use the original receiver.
|
|
9
|
+
*/ export function placementOperationRequest(req, fields, failed) {
|
|
10
|
+
const parent = req[operationRequestState];
|
|
11
|
+
const state = {
|
|
12
|
+
target: parent?.target ?? req,
|
|
13
|
+
failed: failed ?? parent?.failed
|
|
14
|
+
};
|
|
15
|
+
return new Proxy(req, {
|
|
16
|
+
deleteProperty (target, key) {
|
|
17
|
+
// Transaction deletion must reach the shared request without ending any
|
|
18
|
+
// ancestor operation. Extra wrappers of this operation inherit its cleanup.
|
|
19
|
+
if (key === 'transactionID') {
|
|
20
|
+
state.failed?.();
|
|
21
|
+
return Reflect.deleteProperty(state.target, key);
|
|
22
|
+
}
|
|
23
|
+
return Reflect.deleteProperty(target, key);
|
|
24
|
+
},
|
|
25
|
+
get (target, key) {
|
|
26
|
+
if (key === operationRequestState) return state;
|
|
27
|
+
if (fields.has(key)) return fields.get(key);
|
|
28
|
+
const value = Reflect.get(target, key, target);
|
|
29
|
+
return typeof Object.getOwnPropertyDescriptor(Request.prototype, key)?.value === 'function' ? value.bind(target) : value;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** Observe Payload's actual, access-filtered bulk selection before it dispatches
|
|
34
|
+
* any document hooks. This request-only proxy adds no reads and never replaces
|
|
35
|
+
* the shared adapter. Matching the original Where node avoids capturing nested
|
|
36
|
+
* access-hook reads. queryDrafts prefixes keys but preserves condition objects.
|
|
37
|
+
* Payload 3's update/delete operations select the entire set before Promise.all.
|
|
38
|
+
*/ export function bulkPlacementRequest(req, collection, where, data, draft, deleting, bulk) {
|
|
39
|
+
const config = req.payload.config.collections.find((entry)=>entry.slug === collection);
|
|
40
|
+
const draftOnly = draft && Boolean(config?.versions && config.versions.drafts) && data?._status !== 'published';
|
|
41
|
+
bulk.change = {
|
|
42
|
+
collection,
|
|
43
|
+
data,
|
|
44
|
+
draft: draftOnly,
|
|
45
|
+
deleting
|
|
46
|
+
};
|
|
47
|
+
let captured = false;
|
|
48
|
+
const matches = (value, expected, versions)=>{
|
|
49
|
+
if (value === expected) return true;
|
|
50
|
+
if (!versions) return false;
|
|
51
|
+
if (!value || !expected || typeof value !== 'object' || typeof expected !== 'object') return false;
|
|
52
|
+
const actual = value;
|
|
53
|
+
return Object.entries(expected).every(([key, condition])=>{
|
|
54
|
+
if (key === 'and' || key === 'or') return Array.isArray(actual[key]) && Array.isArray(condition) && condition.length === actual[key].length && condition.every((entry, i)=>matches(actual[key][i], entry, versions));
|
|
55
|
+
return actual[versions ? key === 'id' ? 'parent' : `version.${key}` : key] === condition;
|
|
56
|
+
}) && Object.keys(actual).length === Object.keys(expected).length;
|
|
57
|
+
};
|
|
58
|
+
const contains = (value, versions)=>matches(value, where, versions) || !!value && typeof value === 'object' && [
|
|
59
|
+
'and',
|
|
60
|
+
'or'
|
|
61
|
+
].some((key)=>{
|
|
62
|
+
const children = value[key];
|
|
63
|
+
return Array.isArray(children) && children.some((child)=>contains(child, versions));
|
|
64
|
+
});
|
|
65
|
+
const database = new Proxy(req.payload.db, {
|
|
66
|
+
get (target, key, receiver) {
|
|
67
|
+
const method = Reflect.get(target, key, receiver);
|
|
68
|
+
if (key !== 'find' && key !== 'queryDrafts') return method;
|
|
69
|
+
return async (query)=>{
|
|
70
|
+
const selection = !captured && (key !== 'queryDrafts' || 'pagination' in query && query.pagination === false) && query.req === scoped && query.collection === collection && contains(query.where, key === 'queryDrafts');
|
|
71
|
+
const result = await method.call(target, query);
|
|
72
|
+
if (selection) {
|
|
73
|
+
captured = true;
|
|
74
|
+
for (const doc of result.docs)bulk.documents.add(JSON.stringify([
|
|
75
|
+
collection,
|
|
76
|
+
String(doc.id)
|
|
77
|
+
]));
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const payload = new Proxy(req.payload, {
|
|
84
|
+
get: (target, key, receiver)=>key === 'db' ? database : Reflect.get(target, key, receiver)
|
|
85
|
+
});
|
|
86
|
+
const scoped = placementOperationRequest(req, new Map([
|
|
87
|
+
[
|
|
88
|
+
'payload',
|
|
89
|
+
payload
|
|
90
|
+
]
|
|
91
|
+
]));
|
|
92
|
+
return scoped;
|
|
93
|
+
}
|
|
94
|
+
/** Evaluate the common change against the published row seen under E, rather
|
|
95
|
+
* than a draft version or a selection snapshot from before the lock. */ export function bulkRemoves(bulk, req, collection, doc, slug, view) {
|
|
96
|
+
const change = bulk?.change;
|
|
97
|
+
if (!change || change.draft || change.collection !== collection || !bulk.documents.has(JSON.stringify([
|
|
98
|
+
collection,
|
|
99
|
+
String(doc.id)
|
|
100
|
+
]))) return false;
|
|
101
|
+
// locale=all data and the adapter row share the same all-language shape.
|
|
102
|
+
// A single-locale write instead merges its flattened values once.
|
|
103
|
+
const input = req.locale === 'all' ? 'all-locales' : 'localized';
|
|
104
|
+
const pending = {
|
|
105
|
+
...input === 'all-locales' ? doc : placementLocaleContent(req, collection, doc, 'all-locales'),
|
|
106
|
+
...change.data
|
|
107
|
+
};
|
|
108
|
+
const after = input === 'all-locales' ? pending : mergedPlacementLocales(req, collection, doc, pending);
|
|
109
|
+
const views = removedPlacementViews(req, collection, doc, after, change.deleting || after.deletedAt != null || after._status === 'draft', 'all-locales');
|
|
110
|
+
return (views.get(slug) ?? []).some((removed)=>placementDocumentKey(collection, doc.id, removed) === placementDocumentKey(collection, doc.id, view));
|
|
111
|
+
}
|
package/dist/db/delete.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PayloadRequest } from 'payload';
|
|
2
2
|
import type { DocId } from '../types/contracts.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type Executor } from './executor.js';
|
|
4
4
|
interface DeleteState {
|
|
5
5
|
tail: Promise<void>;
|
|
6
6
|
retiredSlugs: Set<string>;
|
package/dist/db/delete.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { transactionSession } from './executor.js';
|
|
2
2
|
import { COLUMNS, TABLES } from './names.js';
|
|
3
3
|
import { qualifiedTable, quoteIdentifier as quote } from './sql.js';
|
|
4
4
|
// Key by the actual session: borrowed requests in one transaction share a queue,
|
|
@@ -9,9 +9,7 @@ const transactions = new WeakMap();
|
|
|
9
9
|
* Successful beforeDelete bodies retain exclusions until the transaction ends:
|
|
10
10
|
* another row can be between hooks with its children gone but its row present.
|
|
11
11
|
*/ export async function serializeDelete(req, fn) {
|
|
12
|
-
const
|
|
13
|
-
const session = id == null ? undefined : req.payload.db.sessions?.[id];
|
|
14
|
-
if (!session) throw new XpNoTransactionError();
|
|
12
|
+
const session = await transactionSession(req);
|
|
15
13
|
let state = transactions.get(session);
|
|
16
14
|
if (!state) {
|
|
17
15
|
state = {
|
package/dist/db/events.d.ts
CHANGED
|
@@ -17,5 +17,14 @@ export interface EventRow {
|
|
|
17
17
|
attributes?: Record<string, unknown>;
|
|
18
18
|
dedupeKey: string;
|
|
19
19
|
}
|
|
20
|
+
type ServerConversion = Pick<EventRow, 'unitId' | 'unitType' | 'userId' | 'ts'> & {
|
|
21
|
+
eventName: string;
|
|
22
|
+
value: number;
|
|
23
|
+
idempotencyKey: string;
|
|
24
|
+
};
|
|
25
|
+
/** A retained legacy row suppresses retries for its event name. The scoped key's
|
|
26
|
+
* unique index handles concurrent writes after the old writers have been drained. */
|
|
27
|
+
export declare function insertServerConversion(exec: Executor, event: ServerConversion, log: (message: string) => void): Promise<void>;
|
|
20
28
|
/** Pooled/autocommit executor required: an FK failure must not poison a caller's transaction. */
|
|
21
29
|
export declare function insertEvents(exec: Executor, rows: EventRow[], log?: (message: string) => void): Promise<number>;
|
|
30
|
+
export {};
|
package/dist/db/events.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { exposureDimensions } from '../events/dimensions.js';
|
|
2
3
|
import { COLUMNS, TABLES } from './names.js';
|
|
3
4
|
import { qualifiedTable, quoteIdentifier } from './sql.js';
|
|
@@ -6,7 +7,7 @@ import { qualifiedTable, quoteIdentifier } from './sql.js';
|
|
|
6
7
|
experimentId
|
|
7
8
|
]);
|
|
8
9
|
}
|
|
9
|
-
const quote =
|
|
10
|
+
const quote = quoteIdentifier;
|
|
10
11
|
const c = COLUMNS.events;
|
|
11
12
|
function foreignKeyViolation(error) {
|
|
12
13
|
const seen = new Set();
|
|
@@ -28,15 +29,48 @@ function foreignKeyViolation(error) {
|
|
|
28
29
|
return null;
|
|
29
30
|
}
|
|
30
31
|
}
|
|
32
|
+
function hasFiniteValue(value, log) {
|
|
33
|
+
if (value === undefined || Number.isFinite(value)) return true;
|
|
34
|
+
log('Experiments: dropped event with non-finite value');
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
/** A retained legacy row suppresses retries for its event name. The scoped key's
|
|
38
|
+
* unique index handles concurrent writes after the old writers have been drained. */ export async function insertServerConversion(exec, event, log) {
|
|
39
|
+
if (!hasFiniteValue(event.value, log)) return;
|
|
40
|
+
const table = qualifiedTable(exec, TABLES.events);
|
|
41
|
+
const digest = createHash('sha256').update(JSON.stringify([
|
|
42
|
+
event.eventName,
|
|
43
|
+
event.idempotencyKey
|
|
44
|
+
])).digest('hex');
|
|
45
|
+
await exec.query(`INSERT INTO ${table} (${[
|
|
46
|
+
c.type,
|
|
47
|
+
c.unitId,
|
|
48
|
+
c.unitType,
|
|
49
|
+
c.userId,
|
|
50
|
+
c.eventName,
|
|
51
|
+
c.value,
|
|
52
|
+
c.ts,
|
|
53
|
+
c.dedupeKey,
|
|
54
|
+
c.createdAt,
|
|
55
|
+
c.updatedAt
|
|
56
|
+
].map(quote).join(', ')})
|
|
57
|
+
SELECT 'conversion', $1, $2, $3, $4, $5, $6, $7, now(), now()
|
|
58
|
+
WHERE NOT EXISTS (SELECT 1 FROM ${table} WHERE ${quote(c.dedupeKey)} = $8 AND ${quote(c.eventName)} = $4)
|
|
59
|
+
ON CONFLICT (${quote(c.dedupeKey)}) DO NOTHING`, [
|
|
60
|
+
event.unitId,
|
|
61
|
+
event.unitType,
|
|
62
|
+
event.userId ?? null,
|
|
63
|
+
event.eventName,
|
|
64
|
+
event.value,
|
|
65
|
+
event.ts,
|
|
66
|
+
`conversion:s2:${digest}`,
|
|
67
|
+
`conversion:s:${event.idempotencyKey}`
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
31
70
|
/** Pooled/autocommit executor required: an FK failure must not poison a caller's transaction. */ export async function insertEvents(exec, rows, log = console.error) {
|
|
32
|
-
const valid = rows.filter((row)=>
|
|
33
|
-
if (row.value === undefined || Number.isFinite(row.value)) return true;
|
|
34
|
-
log('Experiments: dropped event with non-finite value');
|
|
35
|
-
return false;
|
|
36
|
-
});
|
|
71
|
+
const valid = rows.filter((row)=>hasFiniteValue(row.value, log));
|
|
37
72
|
if (!valid.length) return 0;
|
|
38
|
-
const
|
|
39
|
-
const table = `${schema ? `${quote(schema)}.` : ''}${quote(TABLES.events)}`;
|
|
73
|
+
const table = qualifiedTable(exec, TABLES.events);
|
|
40
74
|
async function insert(batch) {
|
|
41
75
|
const params = [];
|
|
42
76
|
const values = batch.map((row)=>{
|
package/dist/db/executor.d.ts
CHANGED
|
@@ -2,7 +2,13 @@ import type { Payload, PayloadRequest } from 'payload';
|
|
|
2
2
|
import type { Executor } from './pgExecutor.js';
|
|
3
3
|
export type { Executor } from './pgExecutor.js';
|
|
4
4
|
export { pgPoolExecutor, ownConnection, withStatementTimeout, raceDeadline, ResultsBudgetError, RESULTS_TIMEOUT_MARGIN_MS } from './pgExecutor.js';
|
|
5
|
-
|
|
5
|
+
type TransactionRequest = Pick<PayloadRequest, 'payload' | 'transactionID'>;
|
|
6
|
+
export declare function transactionSession(req: TransactionRequest): Promise<{
|
|
7
|
+
db: unknown;
|
|
8
|
+
reject: () => Promise<void>;
|
|
9
|
+
resolve: () => Promise<void>;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function txExecutor(req: TransactionRequest): Executor & {
|
|
6
12
|
schemaName?: string;
|
|
7
13
|
};
|
|
8
14
|
export declare function pooledExecutor(payload: Payload): Executor & {
|
package/dist/db/executor.js
CHANGED
|
@@ -14,14 +14,18 @@ export { pgPoolExecutor, ownConnection, withStatementTimeout, raceDeadline, Resu
|
|
|
14
14
|
chunks.push(sql.raw(text.slice(start)));
|
|
15
15
|
return sql.join(chunks, sql.raw(''));
|
|
16
16
|
}
|
|
17
|
+
export async function transactionSession(req) {
|
|
18
|
+
const id = await req.transactionID;
|
|
19
|
+
const session = id == null ? undefined : req.payload.db.sessions?.[id];
|
|
20
|
+
if (!session) throw new XpNoTransactionError();
|
|
21
|
+
return session;
|
|
22
|
+
}
|
|
17
23
|
export function txExecutor(req) {
|
|
18
24
|
const db = req.payload.db;
|
|
19
25
|
return {
|
|
20
26
|
schemaName: db.schemaName,
|
|
21
27
|
async query (text, params = []) {
|
|
22
|
-
const
|
|
23
|
-
const session = id == null ? undefined : db.sessions?.[id];
|
|
24
|
-
if (!session) throw new XpNoTransactionError();
|
|
28
|
+
const session = await transactionSession(req);
|
|
25
29
|
return normalise(await session.db.execute(bind(text, params)));
|
|
26
30
|
}
|
|
27
31
|
};
|