@delmaredigital/payload-experiments 0.4.0-rc.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -15
- package/dist/admin/MetricSourceSelect.js +10 -3
- package/dist/admin/armSelect/armSelect.model.d.ts +1 -1
- package/dist/admin/blocks/BlockPanel.d.ts +1 -0
- package/dist/admin/blocks/BlockPanel.js +75 -29
- package/dist/admin/blocks/model.js +7 -6
- package/dist/admin/copy/blocks.d.ts +14 -11
- package/dist/admin/copy/blocks.js +33 -22
- package/dist/admin/copy/goals.d.ts +15 -8
- package/dist/admin/copy/goals.js +18 -8
- package/dist/admin/copy/newTest.d.ts +10 -7
- package/dist/admin/copy/newTest.js +14 -7
- package/dist/admin/copy/status.d.ts +1 -1
- package/dist/admin/copy/status.js +2 -1
- package/dist/admin/pageCollections.d.ts +1 -0
- package/dist/admin/pageCollections.js +3 -0
- package/dist/admin/placementStatus.model.js +5 -3
- package/dist/admin/status.model.d.ts +1 -0
- package/dist/admin/status.model.js +2 -1
- package/dist/admin/surface/ResultsRoute.js +12 -10
- package/dist/admin/surface/SurfaceShell.d.ts +4 -2
- package/dist/admin/surface/SurfaceShell.js +28 -3
- package/dist/admin/surface/TestRowMenu.d.ts +13 -0
- package/dist/admin/surface/TestRowMenu.js +163 -0
- package/dist/admin/surface/TestsHome.d.ts +4 -3
- package/dist/admin/surface/TestsHome.js +224 -52
- package/dist/admin/surface/TestsSurface.js +2 -1
- package/dist/admin/surface/goals/DeleteGoalDialog.d.ts +7 -0
- package/dist/admin/surface/goals/DeleteGoalDialog.js +42 -0
- package/dist/admin/surface/goals/GoalForm.d.ts +1 -0
- package/dist/admin/surface/goals/GoalForm.js +280 -198
- package/dist/admin/surface/goals/GoalsList.js +102 -33
- package/dist/admin/surface/goals/data.d.ts +2 -0
- package/dist/admin/surface/goals/data.js +9 -0
- package/dist/admin/surface/goals/goals.css +3 -2
- package/dist/admin/surface/goals/goals.model.d.ts +2 -2
- package/dist/admin/surface/goals/goals.model.js +7 -12
- package/dist/admin/surface/home.model.d.ts +15 -8
- package/dist/admin/surface/home.model.js +22 -18
- package/dist/admin/surface/newTest/NewTest.d.ts +3 -3
- package/dist/admin/surface/newTest/NewTest.js +156 -96
- package/dist/admin/surface/newTest/PageWizard.d.ts +4 -1
- package/dist/admin/surface/newTest/PageWizard.js +99 -68
- package/dist/admin/surface/newTest/newTest.css +28 -11
- package/dist/admin/surface/results/ResultsHeader.d.ts +1 -1
- package/dist/admin/surface/results/ResultsHeader.js +98 -66
- package/dist/admin/surface/surface.css +29 -0
- package/dist/admin/surface/test/TestPage.js +46 -38
- package/dist/admin/surface/useXpStepNav.d.ts +11 -0
- package/dist/admin/surface/useXpStepNav.js +14 -0
- package/dist/admin/views/TestsSurfaceClient.js +27 -3
- package/dist/admin/views/buildSurfaceProps.js +18 -66
- package/dist/arms/copy.d.ts +13 -3
- package/dist/arms/copy.js +5 -4
- package/dist/blocks/createExperimentBlock.js +1 -1
- package/dist/blocks/formState.js +2 -2
- package/dist/collections/experiments/armInvariants.js +8 -5
- package/dist/collections/experiments/config.js +8 -3
- package/dist/collections/experiments/deleteGuard.js +2 -2
- package/dist/collections/experiments/lockHook.js +21 -2
- package/dist/collections/experiments/pickSlug.js +2 -0
- package/dist/collections/metrics.js +12 -5
- package/dist/collections/metricsGuards.js +2 -0
- package/dist/collections/serialize.js +8 -6
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/db/adapter.d.ts +9 -1
- package/dist/db/adapter.js +77 -1
- package/dist/db/delete.d.ts +1 -1
- package/dist/db/delete.js +2 -4
- package/dist/db/events.d.ts +9 -0
- package/dist/db/events.js +42 -8
- package/dist/db/executor.d.ts +7 -1
- package/dist/db/executor.js +7 -3
- package/dist/db/pageCopies.d.ts +5 -0
- package/dist/db/pageCopies.js +31 -0
- package/dist/db/results.d.ts +5 -1
- package/dist/db/results.js +21 -5
- package/dist/db/snapshots.d.ts +2 -0
- package/dist/endpoints/deleteImpact.js +2 -1
- package/dist/endpoints/duplicateOriginal.d.ts +38 -0
- package/dist/endpoints/duplicateOriginal.js +414 -0
- package/dist/endpoints/editorSurface.js +1 -1
- package/dist/endpoints/events.js +103 -39
- package/dist/endpoints/index.js +22 -8
- package/dist/endpoints/pages.js +245 -66
- package/dist/endpoints/placementStatus.js +8 -4
- package/dist/endpoints/results.d.ts +1 -1
- package/dist/endpoints/results.js +9 -2
- package/dist/endpoints/routeId.d.ts +2 -2
- package/dist/endpoints/routeId.js +11 -5
- package/dist/endpoints/summary.js +46 -12
- package/dist/endpoints/testVersion.d.ts +2 -0
- package/dist/endpoints/testVersion.js +38 -0
- package/dist/endpoints/transitions.js +41 -29
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +6 -0
- package/dist/events/request.d.ts +6 -2
- package/dist/events/request.js +35 -8
- package/dist/events/rows.d.ts +1 -1
- package/dist/events/rows.js +24 -8
- package/dist/events/writable.d.ts +9 -0
- package/dist/events/writable.js +13 -0
- package/dist/exports/index.d.ts +1 -1
- package/dist/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +1 -0
- package/dist/goals/fairness.js +2 -2
- package/dist/goals/picker/copy.js +1 -1
- package/dist/goals/sourceLabel.d.ts +2 -0
- package/dist/goals/sourceLabel.js +4 -0
- package/dist/hooks/hostHook.js +6 -2
- package/dist/hooks/pageGuard.js +4 -0
- package/dist/hooks/trackPageCopies.d.ts +11 -0
- package/dist/hooks/trackPageCopies.js +7 -0
- package/dist/labels/arms.d.ts +3 -0
- package/dist/labels/arms.js +8 -0
- package/dist/lib/fetchAllDocs.d.ts +1 -1
- package/dist/manifest/compile.js +8 -5
- package/dist/onInit.js +14 -0
- package/dist/options.d.ts +2 -0
- package/dist/options.js +23 -2
- package/dist/plugin.js +56 -2
- package/dist/proxy/pageNavigation.d.ts +4 -0
- package/dist/proxy/pageNavigation.js +28 -0
- package/dist/proxy/resolve.js +52 -25
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +7 -7
- package/dist/puck/editor/ConfigureTestDrawer.js +40 -29
- package/dist/puck/editor/ExperimentSlotEditor.d.ts +2 -1
- package/dist/puck/editor/ExperimentSlotEditor.js +376 -139
- package/dist/puck/editor/LeftoverVersions.js +17 -32
- package/dist/puck/editor/QuickTestActions.d.ts +6 -3
- package/dist/puck/editor/QuickTestActions.js +55 -33
- package/dist/puck/editor/ResultsReadout.d.ts +4 -1
- package/dist/puck/editor/ResultsReadout.js +28 -15
- package/dist/puck/editor/VersionBuilder.d.ts +17 -4
- package/dist/puck/editor/VersionBuilder.js +175 -112
- package/dist/puck/editor/armWrites.js +2 -2
- package/dist/puck/editor/armsCache.js +1 -3
- package/dist/puck/editor/copy.d.ts +14 -7
- package/dist/puck/editor/copy.js +26 -13
- package/dist/puck/editor/editor.chrome.css +10 -8
- package/dist/puck/editor/editor.css +15 -9
- package/dist/puck/editor/editor.model.d.ts +1 -0
- package/dist/puck/editor/placementsCache.d.ts +4 -0
- package/dist/puck/editor/usePageSaveReadiness.d.ts +6 -0
- package/dist/puck/editor/usePageSaveReadiness.js +31 -0
- package/dist/puck/nestedTestCopy.js +2 -2
- package/dist/puck/slotConfig.d.ts +1 -1
- package/dist/puck/slotConfig.js +1 -1
- package/dist/results/aggregate.d.ts +6 -3
- package/dist/results/aggregate.js +9 -9
- package/dist/results/analyse.d.ts +2 -0
- package/dist/results/analyse.js +2 -2
- package/dist/results/health.d.ts +8 -0
- package/dist/results/health.js +28 -0
- package/dist/results/identityCredit.d.ts +1 -0
- package/dist/results/identityCredit.js +4 -1
- package/dist/results/verdict.d.ts +4 -4
- package/dist/results/verdict.js +15 -11
- package/dist/runtime/cookie.d.ts +10 -2
- package/dist/runtime/cookie.js +38 -6
- package/dist/runtime/cookieOptions.d.ts +6 -0
- package/dist/runtime/cookieOptions.js +14 -0
- package/dist/runtime/proxyRuntime.d.ts +1 -0
- package/dist/runtime/proxyRuntime.js +18 -8
- package/dist/runtime/signing.d.ts +1 -0
- package/dist/runtime/signing.js +5 -0
- package/dist/sanitizeReadinessDetail.d.ts +2 -2
- package/dist/sanitizeReadinessDetail.js +20 -2
- package/dist/server/getAssignments.js +11 -10
- package/dist/server/recordContentChange.d.ts +1 -1
- package/dist/server/recordContentChange.js +11 -2
- package/dist/server/resolveExperimentBlocks.js +2 -4
- package/dist/server/resolveExperimentData.js +2 -5
- package/dist/server/runResults.js +54 -15
- package/dist/server/startExperiment.d.ts +20 -0
- package/dist/server/startExperiment.js +70 -0
- package/dist/server/trackConversion.js +10 -13
- package/dist/testSurface/PreviewLinks.d.ts +2 -1
- package/dist/testSurface/PreviewLinks.js +3 -3
- package/dist/testSurface/actions/DecideDialog.d.ts +10 -4
- package/dist/testSurface/actions/DecideDialog.js +93 -63
- package/dist/testSurface/actions/LifecycleAction.d.ts +17 -0
- package/dist/testSurface/actions/LifecycleAction.js +107 -0
- package/dist/testSurface/actions/MakeContentResult.d.ts +4 -3
- package/dist/testSurface/actions/MakeContentResult.js +10 -2
- package/dist/testSurface/actions/actions.model.d.ts +13 -5
- package/dist/testSurface/actions/actions.model.js +75 -22
- package/dist/testSurface/actions/decide.model.d.ts +1 -0
- package/dist/testSurface/actions/decide.model.js +1 -0
- package/dist/testSurface/allocation.model.js +6 -3
- package/dist/testSurface/api.d.ts +9 -6
- package/dist/testSurface/api.js +43 -23
- package/dist/testSurface/copy/actions.d.ts +37 -14
- package/dist/testSurface/copy/actions.js +40 -17
- package/dist/testSurface/copy/advanced.d.ts +10 -0
- package/dist/testSurface/copy/advanced.js +10 -0
- package/dist/testSurface/copy/arms.d.ts +1 -1
- package/dist/testSurface/copy/arms.js +1 -1
- package/dist/testSurface/copy/audience.d.ts +4 -3
- package/dist/testSurface/copy/audience.js +5 -4
- package/dist/testSurface/copy/common.d.ts +8 -6
- package/dist/testSurface/copy/common.js +8 -6
- package/dist/testSurface/copy/languages.d.ts +1 -0
- package/dist/testSurface/copy/languages.js +1 -0
- package/dist/testSurface/copy/metrics.d.ts +7 -0
- package/dist/testSurface/copy/metrics.js +9 -0
- package/dist/testSurface/copy/pages.d.ts +67 -7
- package/dist/testSurface/copy/pages.js +74 -7
- package/dist/testSurface/copy/readiness.d.ts +20 -7
- package/dist/testSurface/copy/readiness.js +36 -10
- package/dist/testSurface/copy/recommendation.d.ts +1 -22
- package/dist/testSurface/copy/recommendation.js +2 -22
- package/dist/testSurface/copy/results.d.ts +21 -12
- package/dist/testSurface/copy/results.js +24 -13
- package/dist/testSurface/copy/review.d.ts +13 -10
- package/dist/testSurface/copy/review.js +14 -10
- package/dist/testSurface/copy/setting.d.ts +1 -2
- package/dist/testSurface/copy/setting.js +1 -2
- package/dist/testSurface/copy/surface.d.ts +11 -2
- package/dist/testSurface/copy/surface.js +14 -11
- package/dist/testSurface/copy/testPage.d.ts +36 -12
- package/dist/testSurface/copy/testPage.js +53 -16
- package/dist/testSurface/format/date.d.ts +5 -2
- package/dist/testSurface/format/date.js +24 -8
- package/dist/testSurface/format/roundProgress.d.ts +6 -0
- package/dist/testSurface/format/roundProgress.js +15 -0
- package/dist/testSurface/format/useDateFormatter.d.ts +3 -0
- package/dist/testSurface/format/useDateFormatter.js +8 -0
- package/dist/testSurface/labels.d.ts +1 -2
- package/dist/testSurface/labels.js +2 -3
- package/dist/testSurface/lockedNotice.model.d.ts +2 -0
- package/dist/testSurface/lockedNotice.model.js +31 -0
- package/dist/testSurface/readPreflight.d.ts +4 -0
- package/dist/testSurface/readPreflight.js +6 -0
- package/dist/testSurface/readinessRead.d.ts +3 -0
- package/dist/testSurface/readinessRead.js +4 -0
- package/dist/testSurface/results/CiChart.js +2 -1
- package/dist/testSurface/results/DataTable.d.ts +1 -1
- package/dist/testSurface/results/DataTable.js +4 -3
- package/dist/testSurface/results/VerdictHero.d.ts +3 -2
- package/dist/testSurface/results/VerdictHero.js +5 -1
- package/dist/testSurface/results/legacy.d.ts +0 -5
- package/dist/testSurface/results/legacy.js +0 -14
- package/dist/testSurface/results/results.css +2 -2
- package/dist/testSurface/results/results.model.d.ts +9 -4
- package/dist/testSurface/results/results.model.js +31 -23
- package/dist/testSurface/results/snapshot.d.ts +2 -0
- package/dist/testSurface/results/snapshot.js +3 -0
- package/dist/testSurface/surface/contracts.d.ts +13 -1
- package/dist/testSurface/surface/editorPlacement.d.ts +3 -3
- package/dist/testSurface/surface/editorPlacement.js +2 -2
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +3 -3
- package/dist/testSurface/surface/pageBlock/parts.js +25 -12
- package/dist/testSurface/surface/pagePicker/CopyRoute.d.ts +8 -1
- package/dist/testSurface/surface/pagePicker/CopyRoute.js +243 -22
- package/dist/testSurface/surface/pagePicker/PageCombobox.d.ts +15 -4
- package/dist/testSurface/surface/pagePicker/PageCombobox.js +300 -197
- package/dist/testSurface/surface/pagePicker/pagePicker.css +73 -10
- package/dist/testSurface/surface/pagePicker/pagePicker.model.d.ts +5 -3
- package/dist/testSurface/surface/pagePicker/pagePicker.model.js +17 -2
- package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +9 -5
- package/dist/testSurface/surface/readiness/ActionDialogs.js +241 -230
- package/dist/testSurface/surface/readiness/Banner.d.ts +5 -1
- package/dist/testSurface/surface/readiness/Banner.js +113 -141
- package/dist/testSurface/surface/readiness/SaveStatus.d.ts +8 -4
- package/dist/testSurface/surface/readiness/SaveStatus.js +23 -22
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +20 -6
- package/dist/testSurface/surface/readiness/readiness.model.js +168 -21
- package/dist/testSurface/surface/readiness/useTransition.d.ts +6 -4
- package/dist/testSurface/surface/readiness/useTransition.js +57 -14
- package/dist/testSurface/surface/results/ReleasePages.d.ts +6 -3
- package/dist/testSurface/surface/results/ReleasePages.js +42 -41
- package/dist/testSurface/surface/results/ResultsBody.d.ts +11 -4
- package/dist/testSurface/surface/results/ResultsBody.js +221 -118
- package/dist/testSurface/surface/results/recommendation.model.d.ts +6 -9
- package/dist/testSurface/surface/results/recommendation.model.js +15 -59
- package/dist/testSurface/surface/results/useResults.d.ts +13 -8
- package/dist/testSurface/surface/results/useResults.js +3 -2
- package/dist/testSurface/surface/setting/parts.js +89 -46
- package/dist/testSurface/surface/setting/setting.css +2 -1
- package/dist/testSurface/surface/test/AdvancedSection.js +11 -4
- package/dist/testSurface/surface/test/DeleteTest.d.ts +10 -2
- package/dist/testSurface/surface/test/DeleteTest.js +173 -74
- package/dist/testSurface/surface/test/GoalSection.js +18 -14
- package/dist/testSurface/surface/test/LengthSection.js +24 -13
- package/dist/testSurface/surface/test/PageHoldout.d.ts +1 -1
- package/dist/testSurface/surface/test/PageHoldout.js +11 -8
- package/dist/testSurface/surface/test/ReadinessBar.d.ts +2 -1
- package/dist/testSurface/surface/test/ReadinessBar.js +4 -10
- package/dist/testSurface/surface/test/Section.js +8 -0
- package/dist/testSurface/surface/test/TargetingSection.js +82 -12
- package/dist/testSurface/surface/test/TestSurface.js +73 -37
- package/dist/testSurface/surface/test/VersionsSection.js +141 -91
- package/dist/testSurface/surface/test/fields.d.ts +32 -6
- package/dist/testSurface/surface/test/fields.js +166 -52
- package/dist/testSurface/surface/test/pageParts.js +27 -12
- package/dist/testSurface/surface/test/testPage.css +9 -2
- package/dist/testSurface/surface/test/testPage.model.d.ts +1 -0
- package/dist/testSurface/surface/test/testPage.model.js +6 -0
- package/dist/testSurface/surface/testDocument.model.d.ts +3 -0
- package/dist/testSurface/surface/testDocument.model.js +4 -1
- package/dist/testSurface/surface/useTestDocument.d.ts +21 -5
- package/dist/testSurface/surface/useTestDocument.js +472 -167
- package/dist/testSurface/surface/watchTestDocument.d.ts +15 -0
- package/dist/testSurface/surface/watchTestDocument.js +181 -0
- package/dist/testSurface/surfaceUrls.d.ts +1 -0
- package/dist/testSurface/surfaceUrls.js +4 -0
- package/dist/testSurface/useApi.d.ts +8 -5
- package/dist/testSurface/useOnTestReturn.d.ts +2 -0
- package/dist/testSurface/useOnTestReturn.js +27 -0
- package/dist/testSurface/useReadinessPolling.js +3 -1
- package/dist/transitions/addMetric.d.ts +2 -5
- package/dist/transitions/addMetric.js +5 -1
- package/dist/transitions/allocate.d.ts +2 -2
- package/dist/transitions/allocate.js +3 -1
- package/dist/transitions/archive.d.ts +1 -1
- package/dist/transitions/archive.js +3 -2
- package/dist/transitions/checkStart.d.ts +1 -0
- package/dist/transitions/checkStart.js +17 -6
- package/dist/transitions/decide.d.ts +1 -1
- package/dist/transitions/decide.js +5 -3
- package/dist/transitions/deleteExperiment.d.ts +2 -2
- package/dist/transitions/deleteExperiment.js +17 -7
- package/dist/transitions/kernel.d.ts +4 -0
- package/dist/transitions/kernel.js +9 -4
- package/dist/transitions/makeContent.d.ts +2 -1
- package/dist/transitions/makeContent.js +12 -8
- package/dist/transitions/nestedPlacementNames.d.ts +2 -2
- package/dist/transitions/nestedPlacementNames.js +4 -5
- package/dist/transitions/pageAddress.d.ts +6 -0
- package/dist/transitions/pageAddress.js +71 -0
- package/dist/transitions/pageVersions.d.ts +1 -1
- package/dist/transitions/phaseRecord.d.ts +2 -0
- package/dist/transitions/phaseRecord.js +5 -0
- package/dist/transitions/placementInteractions.d.ts +3 -3
- package/dist/transitions/placementInteractions.js +8 -7
- package/dist/transitions/placements.d.ts +2 -0
- package/dist/transitions/placements.js +5 -5
- package/dist/transitions/preflightData.d.ts +3 -2
- package/dist/transitions/preflightData.js +77 -43
- package/dist/transitions/releaseHoldout.d.ts +2 -1
- package/dist/transitions/releaseHoldout.js +3 -1
- package/dist/transitions/releasePages.d.ts +2 -1
- package/dist/transitions/releasePages.js +3 -1
- package/dist/transitions/resolveCaps.d.ts +2 -4
- package/dist/transitions/start.d.ts +7 -9
- package/dist/transitions/start.js +75 -39
- package/dist/transitions/startReads.d.ts +7 -0
- package/dist/transitions/startReads.js +28 -0
- package/dist/transitions/stop.d.ts +2 -1
- package/dist/transitions/stop.js +3 -2
- package/dist/types/armKey.d.ts +2 -0
- package/dist/types/armKey.js +1 -0
- package/dist/types/contracts.d.ts +17 -4
- package/dist/types/endpoints.d.ts +89 -17
- package/dist/types/endpoints.js +1 -1
- package/dist/types/runtime.d.ts +15 -9
- package/dist/types/snapshot.d.ts +2 -0
- package/dist/types/surface.d.ts +7 -9
- package/dist/ui/ChipsInput.d.ts +8 -1
- package/dist/ui/ChipsInput.js +17 -4
- package/dist/ui/Dialog.d.ts +21 -2
- package/dist/ui/Dialog.js +101 -4
- package/dist/ui/Inputs.js +0 -1
- package/dist/ui/ui.css +5 -1
- package/package.json +2 -2
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
import { XP_COOKIE } from '../constants.js';
|
|
2
|
+
import { assertSigningSecrets } from './signing.js';
|
|
3
|
+
import { assertCookieOptions } from './cookieOptions.js';
|
|
4
|
+
export function assertUnitRateLimit(rateLimitUnit) {
|
|
5
|
+
if (rateLimitUnit !== false && typeof rateLimitUnit !== 'function') {
|
|
6
|
+
throw new Error('Experiments requires rateLimitUnit to be a client-address rate limiter, or false if you rate-limit unit issuance upstream.');
|
|
7
|
+
}
|
|
8
|
+
}
|
|
2
9
|
export function defineExperimentsProxyRuntime(opts) {
|
|
3
10
|
const secrets = typeof opts.secret === 'string' ? [
|
|
4
11
|
opts.secret
|
|
5
|
-
] :
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
] : opts.secret;
|
|
13
|
+
assertSigningSecrets(secrets);
|
|
14
|
+
assertUnitRateLimit(opts.rateLimitUnit);
|
|
15
|
+
const maxAgeDays = opts.cookie?.maxAgeDays;
|
|
9
16
|
const cookie = Object.freeze({
|
|
10
17
|
...opts.cookie,
|
|
11
18
|
name: opts.cookie?.name ?? XP_COOKIE,
|
|
12
|
-
maxAgeDays:
|
|
19
|
+
maxAgeDays: maxAgeDays === undefined ? 365 : maxAgeDays
|
|
13
20
|
});
|
|
14
|
-
|
|
21
|
+
assertCookieOptions(cookie);
|
|
15
22
|
return Object.freeze({
|
|
16
|
-
secrets
|
|
23
|
+
secrets: Object.freeze([
|
|
24
|
+
...secrets
|
|
25
|
+
]),
|
|
17
26
|
apiRoute: opts.apiRoute,
|
|
18
27
|
cookie,
|
|
19
28
|
loadManifest: opts.loadManifest,
|
|
20
|
-
getUnit: opts.getUnit
|
|
29
|
+
getUnit: opts.getUnit,
|
|
30
|
+
rateLimitUnit: opts.rateLimitUnit
|
|
21
31
|
});
|
|
22
32
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare function assertSigningSecrets(secrets: readonly string[]): void;
|
|
1
2
|
/** New signatures use the first key; verification accepts the entire rotation. */
|
|
2
3
|
export declare function sign(value: string, secrets: readonly string[]): string;
|
|
3
4
|
export declare function verify(value: string, mac: string, secrets: readonly string[]): boolean;
|
package/dist/runtime/signing.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
export function assertSigningSecrets(secrets) {
|
|
3
|
+
if (!Array.isArray(secrets) || !secrets.length || Array.from(secrets).some((secret)=>typeof secret !== 'string' || secret.trim().length < 32)) {
|
|
4
|
+
throw new Error('Experiments requires at least one signing secret. Each signing secret must contain at least 32 characters.');
|
|
5
|
+
}
|
|
6
|
+
}
|
|
2
7
|
/** New signatures use the first key; verification accepts the entire rotation. */ export function sign(value, secrets) {
|
|
3
8
|
if (!secrets.length || !secrets[0]) throw new Error('A signing secret is required');
|
|
4
9
|
return createHmac('sha256', secrets[0]).update(value).digest('base64url');
|
|
@@ -2,6 +2,6 @@ import type { ReadinessCode } from './types/endpoints.js';
|
|
|
2
2
|
/** Summary details contain identifiers only. Project known shapes rather than
|
|
3
3
|
* recursively copying host objects: titles, messages and placement detail are text.
|
|
4
4
|
* Other checks use authored client fallbacks and need no detail (including slot
|
|
5
|
-
* counts and layer capacity, which are not identifiers).
|
|
5
|
+
* counts and layer capacity, which are not identifiers). Empty slots carry only version keys.
|
|
6
6
|
*/
|
|
7
|
-
export declare function sanitizeReadinessDetail(code: ReadinessCode, detail: unknown): unknown;
|
|
7
|
+
export declare function sanitizeReadinessDetail(code: ReadinessCode, detail: unknown, draftReadySlots?: readonly string[]): unknown;
|
|
@@ -13,8 +13,8 @@ const failure = (value)=>value === 'placements-failed' || value === 'forbidden'
|
|
|
13
13
|
/** Summary details contain identifiers only. Project known shapes rather than
|
|
14
14
|
* recursively copying host objects: titles, messages and placement detail are text.
|
|
15
15
|
* Other checks use authored client fallbacks and need no detail (including slot
|
|
16
|
-
* counts and layer capacity, which are not identifiers).
|
|
17
|
-
*/ export function sanitizeReadinessDetail(code, detail) {
|
|
16
|
+
* counts and layer capacity, which are not identifiers). Empty slots carry only version keys.
|
|
17
|
+
*/ export function sanitizeReadinessDetail(code, detail, draftReadySlots = []) {
|
|
18
18
|
switch(code){
|
|
19
19
|
case 'goal-in-some-versions':
|
|
20
20
|
{
|
|
@@ -63,6 +63,24 @@ const failure = (value)=>value === 'placements-failed' || value === 'forbidden'
|
|
|
63
63
|
} : undefined;
|
|
64
64
|
case 'no-placements':
|
|
65
65
|
return failure(detail) ? detail : undefined;
|
|
66
|
+
case 'empty-slot':
|
|
67
|
+
{
|
|
68
|
+
const rows = (Array.isArray(detail) ? detail : [
|
|
69
|
+
detail
|
|
70
|
+
]).filter(object);
|
|
71
|
+
const missing = [
|
|
72
|
+
...new Set(rows.flatMap((row)=>Array.isArray(row.missing) ? row.missing : []).filter((value)=>arm(value) && value !== 'holdout'))
|
|
73
|
+
];
|
|
74
|
+
if (!missing.length) return undefined;
|
|
75
|
+
const reportedReady = object(detail) && Array.isArray(detail.draftReady) ? detail.draftReady : draftReadySlots;
|
|
76
|
+
const draftReady = missing.filter((slot)=>reportedReady.includes(slot));
|
|
77
|
+
return {
|
|
78
|
+
missing,
|
|
79
|
+
...draftReady.length ? {
|
|
80
|
+
draftReady
|
|
81
|
+
} : {}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
66
84
|
case 'placement-removed':
|
|
67
85
|
return undefined;
|
|
68
86
|
case 'page-in-use':
|
|
@@ -53,7 +53,8 @@ async function readAssignments(runtime, suppliedUser) {
|
|
|
53
53
|
sessionUnknown: unit.sessionUnknown
|
|
54
54
|
};
|
|
55
55
|
let user = consent === false ? null : suppliedUser;
|
|
56
|
-
const
|
|
56
|
+
const canAssignUser = consent !== false && (hasContext || Boolean(visitorId));
|
|
57
|
+
const canResolveUser = canAssignUser && (suppliedUser !== undefined || Boolean(runtime.getUser));
|
|
57
58
|
let userFailed = false;
|
|
58
59
|
const resolveUser = async ()=>{
|
|
59
60
|
if (user !== undefined) return user;
|
|
@@ -68,14 +69,14 @@ async function readAssignments(runtime, suppliedUser) {
|
|
|
68
69
|
};
|
|
69
70
|
const value = requestHeaders.get(XP_HEADER);
|
|
70
71
|
// Consent-false proxy headers are signed without either identity.
|
|
71
|
-
let headerUserId =
|
|
72
|
+
let headerUserId = canAssignUser ? unit.userId : undefined;
|
|
72
73
|
const authenticate = (userId)=>verifiedHeaderRevision(value, {
|
|
73
74
|
secrets: proxy.secrets,
|
|
74
75
|
visitorId,
|
|
75
76
|
userId
|
|
76
77
|
});
|
|
77
78
|
let revision = authenticate(headerUserId);
|
|
78
|
-
if (revision === null &&
|
|
79
|
+
if (revision === null && value && canResolveUser) {
|
|
79
80
|
const resolved = await resolveUser();
|
|
80
81
|
if (resolved) {
|
|
81
82
|
const resolvedId = runtime.userIdOf(resolved);
|
|
@@ -108,13 +109,14 @@ async function readAssignments(runtime, suppliedUser) {
|
|
|
108
109
|
userFailed = true;
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
|
-
const userId =
|
|
112
|
+
const userId = canAssignUser ? user === undefined ? unit.userId : user ? runtime.userIdOf(user) : undefined : undefined;
|
|
113
|
+
const token = hasContext ? verifyPreviewToken(request.nextUrl.searchParams.get('xp_preview') ?? '', proxy.secrets) : null;
|
|
112
114
|
const context = {
|
|
113
115
|
visitorId,
|
|
114
116
|
userId,
|
|
115
117
|
staff: decoded?.staff === true || unit.attributes.staff === true || attributes.staff === true,
|
|
116
118
|
bot: decoded?.bot === true || isBot(requestHeaders.get('user-agent')),
|
|
117
|
-
preview: decoded?.preview
|
|
119
|
+
preview: decoded?.preview === true || !visitorId && token !== null,
|
|
118
120
|
sessionUnknown: needsUser && canResolveUser && !userFailed ? false : decoded?.sessionUnknown ?? unit.sessionUnknown ?? false,
|
|
119
121
|
method: request.method
|
|
120
122
|
};
|
|
@@ -159,10 +161,10 @@ async function readAssignments(runtime, suppliedUser) {
|
|
|
159
161
|
}
|
|
160
162
|
};
|
|
161
163
|
const slugs = new Set(hasContext ? decoded.deferred : []);
|
|
162
|
-
if (
|
|
164
|
+
if (canAssignUser && user !== undefined && userId !== headerUserId) {
|
|
163
165
|
for (const e of manifest.experiments)if (e.unitType === 'user') slugs.add(e.slug);
|
|
164
166
|
}
|
|
165
|
-
if (
|
|
167
|
+
if (slugs.size && canResolveUser && !userFailed) {
|
|
166
168
|
try {
|
|
167
169
|
const resolved = assign(manifest, {
|
|
168
170
|
visitorId,
|
|
@@ -179,7 +181,7 @@ async function readAssignments(runtime, suppliedUser) {
|
|
|
179
181
|
userFailed = true;
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
|
-
} else if (!visitorId || !hasContext) result = controlAssignments(manifest, context);
|
|
184
|
+
} else if (!visitorId && !userId || !hasContext) result = controlAssignments(manifest, context);
|
|
183
185
|
else {
|
|
184
186
|
try {
|
|
185
187
|
result = assign(manifest, {
|
|
@@ -202,7 +204,6 @@ async function readAssignments(runtime, suppliedUser) {
|
|
|
202
204
|
}
|
|
203
205
|
fillFlagPoints(result, manifest);
|
|
204
206
|
fillHostDefaults(result);
|
|
205
|
-
const token = hasContext ? verifyPreviewToken(request.nextUrl.searchParams.get('xp_preview') ?? '', proxy.secrets) : null;
|
|
206
207
|
if (token && visitorId && payload) {
|
|
207
208
|
const live = manifest.experiments.find((e)=>e.id === token.e && e.phase === token.p && e.arms.some((a)=>a.key === token.a));
|
|
208
209
|
if (live) {
|
|
@@ -219,7 +220,7 @@ async function readAssignments(runtime, suppliedUser) {
|
|
|
219
220
|
fillFlagPoints(result, manifest);
|
|
220
221
|
} else await previewDraft(payload, await resolveUser(), token, result, requestHeaders);
|
|
221
222
|
}
|
|
222
|
-
if (suppressExposure(result) || !hasContext ||
|
|
223
|
+
if (suppressExposure(result) || !hasContext || payloadFailed || userFailed || mustResolveStaff && !runtime.getUser && suppliedUser === undefined) {
|
|
223
224
|
for (const assignment of Object.values(result.bySlug))assignment.exposable = false;
|
|
224
225
|
for (const point of Object.values(result.flagPoints))point.exposable = false;
|
|
225
226
|
}
|
|
@@ -2,6 +2,6 @@ import type { CollectionAfterChangeHook, CollectionBeforeChangeHook } from 'payl
|
|
|
2
2
|
/** Paired raw beforeChange capture: previousDoc may be an autosaved draft. */
|
|
3
3
|
export declare function capturePublishedContent({ req, collection, originalDoc, operation }: Parameters<CollectionBeforeChangeHook>[0]): Promise<void>;
|
|
4
4
|
type ContentChangeArgs = Pick<Parameters<CollectionAfterChangeHook>[0], 'doc' | 'previousDoc' | 'req' | 'collection'>;
|
|
5
|
-
/** Publish-only host helper. Audit failures are logged
|
|
5
|
+
/** Publish-only host helper. Audit failures are logged after savepoint recovery. */
|
|
6
6
|
export declare function recordContentChange(args: ContentChangeArgs): Promise<void>;
|
|
7
7
|
export {};
|
|
@@ -4,6 +4,7 @@ import { puckVisibility } from '../puck/visibility.js';
|
|
|
4
4
|
import { EXPERIMENT_BLOCK_SLUG, hostBlocks } from '../blocks/model.js';
|
|
5
5
|
import { safeError } from '../log.js';
|
|
6
6
|
import { isDeepStrictEqual } from 'node:util';
|
|
7
|
+
import { XpTransactionIsolationError } from '../db/adapter.js';
|
|
7
8
|
import { appendContentChange, contentChangeSavepoint, previousPublishedContent, runningContentExperiment, storedContent } from '../db/appends.js';
|
|
8
9
|
import { txExecutor } from '../db/executor.js';
|
|
9
10
|
import { pageContentBindings } from '../db/pageBindings.js';
|
|
@@ -81,11 +82,17 @@ const baselineKey = (collection, id)=>`${collection}:${id}`;
|
|
|
81
82
|
doc: audit.result
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
|
-
/** Publish-only host helper. Audit failures are logged
|
|
85
|
+
/** Publish-only host helper. Audit failures are logged after savepoint recovery. */ export async function recordContentChange(args) {
|
|
85
86
|
try {
|
|
86
87
|
await auditContentChange(args);
|
|
87
88
|
} catch (error) {
|
|
88
|
-
|
|
89
|
+
try {
|
|
90
|
+
// The isolation check already logged the reason once for this transaction.
|
|
91
|
+
if (error instanceof XpTransactionIsolationError) return;
|
|
92
|
+
} catch {}
|
|
93
|
+
try {
|
|
94
|
+
console.error('[payload-experiments] contentChanges failed; the document was saved without it', safeError(error));
|
|
95
|
+
} catch {}
|
|
89
96
|
}
|
|
90
97
|
}
|
|
91
98
|
async function auditContentChange({ doc, previousDoc, req, collection }) {
|
|
@@ -203,6 +210,8 @@ async function auditContentChange({ doc, previousDoc, req, collection }) {
|
|
|
203
210
|
bump: false,
|
|
204
211
|
audit: true
|
|
205
212
|
}, async ({ exec })=>{
|
|
213
|
+
// Keep the recheck and append on the executor. A failed nested Local API
|
|
214
|
+
// call would kill the host transaction before the savepoint could recover.
|
|
206
215
|
const experiment = await runningContentExperiment(exec, {
|
|
207
216
|
field: 'id',
|
|
208
217
|
value: experimentId
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BLOCK_SLOTS, EXPERIMENT_BLOCK_SLUG, hostBlocks, slotBlocks } from '../blocks/model.js';
|
|
2
|
-
import {
|
|
2
|
+
import { suppressExposure } from './context.js';
|
|
3
3
|
export function resolveExperimentBlocks(blocks, assignments, { blockSlug = EXPERIMENT_BLOCK_SLUG } = {}) {
|
|
4
4
|
const result = {
|
|
5
5
|
blocks: [],
|
|
@@ -18,10 +18,8 @@ export function resolveExperimentBlocks(blocks, assignments, { blockSlug = EXPER
|
|
|
18
18
|
}
|
|
19
19
|
const slug = typeof block.experiment === 'string' ? block.experiment : '';
|
|
20
20
|
const assignment = Object.hasOwn(assignments.bySlug, slug) ? assignments.bySlug[slug] : undefined;
|
|
21
|
-
const experiment = manifestOf(assignments)?.experiments.find((e)=>e.slug === slug);
|
|
22
|
-
const arm = experiment?.arms.find((a)=>a.key === assignment?.arm);
|
|
23
21
|
const archived = Object.hasOwn(assignments.archivedWinners, slug) ? assignments.archivedWinners[slug] : undefined;
|
|
24
|
-
const slot = assignment ? assignment.arm === 'holdout' ? 'control' :
|
|
22
|
+
const slot = assignment ? assignment.arm === 'holdout' ? 'control' : assignment.arm : archived ?? 'control';
|
|
25
23
|
const selected = BLOCK_SLOTS.includes(slot) ? slotBlocks(block, slot) : [];
|
|
26
24
|
const content = selected.length ? selected : slotBlocks(block, 'control');
|
|
27
25
|
const group = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { puckExperimentSlug } from '../puck/experimentSlug.js';
|
|
2
2
|
import { puckVisibility } from '../puck/visibility.js';
|
|
3
|
-
import {
|
|
3
|
+
import { suppressExposure } from './context.js';
|
|
4
4
|
export function resolveExperimentData(puckData, assignments) {
|
|
5
5
|
const visibility = puckVisibility(puckData);
|
|
6
6
|
const rendered = new Map();
|
|
@@ -10,7 +10,6 @@ export function resolveExperimentData(puckData, assignments) {
|
|
|
10
10
|
'variantB',
|
|
11
11
|
'variantC'
|
|
12
12
|
];
|
|
13
|
-
const manifest = manifestOf(assignments);
|
|
14
13
|
function walk(value) {
|
|
15
14
|
if (Array.isArray(value)) return value.map(walk).filter((item)=>item !== undefined);
|
|
16
15
|
if (!value || typeof value !== 'object') return value;
|
|
@@ -30,10 +29,8 @@ export function resolveExperimentData(puckData, assignments) {
|
|
|
30
29
|
delete clean.xpExpose;
|
|
31
30
|
const slug = puckExperimentSlug(props.experiment);
|
|
32
31
|
const assignment = slug && Object.hasOwn(assignments.bySlug, slug) ? assignments.bySlug[slug] : undefined;
|
|
33
|
-
const experiment = manifest?.experiments.find((e)=>e.slug === slug);
|
|
34
|
-
const arm = experiment?.arms.find((a)=>a.key === assignment?.arm);
|
|
35
32
|
const archived = slug && Object.hasOwn(assignments.archivedWinners, slug) ? assignments.archivedWinners[slug] : undefined;
|
|
36
|
-
const selected = assignment ? assignment.arm === 'holdout' ? 'control' :
|
|
33
|
+
const selected = assignment ? assignment.arm === 'holdout' ? 'control' : assignment.arm : archived ?? 'control';
|
|
37
34
|
const slot = slots.includes(selected) ? selected : 'control';
|
|
38
35
|
clean.xpSlot = slot;
|
|
39
36
|
if (assignment) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { asymmetricGoal, goalContent, goalPlacementDetail, LEGACY_FAIRNESS } from '../goals/fairness.js';
|
|
2
2
|
import { XpAnalysisError } from '../errors.js';
|
|
3
|
-
import { canonicalHealth, mergePageHealth } from '../results/health.js';
|
|
3
|
+
import { canonicalHealth, mergePageHealth, rapidBrowserEvents } from '../results/health.js';
|
|
4
4
|
import { safeError } from '../log.js';
|
|
5
5
|
import { createLocalReq } from 'payload';
|
|
6
6
|
import { resultsCandidates, resultsExecutor, writeSnapshots } from '../db/snapshots.js';
|
|
@@ -11,6 +11,14 @@ import { analysePhase } from '../results/analyse.js';
|
|
|
11
11
|
import { firstExposures, perUnitValues, timestampMs } from '../results/aggregate.js';
|
|
12
12
|
import { rolloutAnalysisUnits } from '../results/rolloutUnits.js';
|
|
13
13
|
import { creditUserEvents, eligibleIdentityLinks } from '../results/identityCredit.js';
|
|
14
|
+
function* convertingUnits(units, values, ages) {
|
|
15
|
+
for (const [id, value] of values){
|
|
16
|
+
if (value > 0) yield {
|
|
17
|
+
arm: units.get(id).arm,
|
|
18
|
+
unitAgeMs: ages.get(id)?.unitAgeMs
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
14
22
|
async function analyseCandidate(exec, candidate, options, now, deadline, unavailableMetrics, logger) {
|
|
15
23
|
const { phase } = candidate;
|
|
16
24
|
// Rollout assignment preserves the original test ranges, but its SRM compares
|
|
@@ -53,6 +61,10 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
53
61
|
...units
|
|
54
62
|
].filter(([id])=>eligible.has(id)));
|
|
55
63
|
}
|
|
64
|
+
const comparedArms = new Set(analysisPhase.arms.filter((arm)=>phase.phaseKind === 'rollout' || arm.kind !== 'holdout').map((arm)=>arm.key));
|
|
65
|
+
// An age on an exposure is only written by browser ingestion, including
|
|
66
|
+
// browser-side manual exposures. Server-recorded exposures have unknown age.
|
|
67
|
+
let rapidActivity = rapidBrowserEvents(comparedArms, units.values());
|
|
56
68
|
const ids = [
|
|
57
69
|
...units.keys()
|
|
58
70
|
];
|
|
@@ -93,9 +105,8 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
93
105
|
// browser even if an earlier linked browser saw another arm or is ineligible.
|
|
94
106
|
const direct = userKeyed ? [] : events.filter((event)=>units.has(event.unitId) || event.userId == null || !linked.has(event.userId));
|
|
95
107
|
const userEvents = events.filter((event)=>userKeyed || !units.has(event.unitId) && event.userId != null && linked.has(event.userId)).map((event)=>({
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
ts: event.ts
|
|
108
|
+
...event,
|
|
109
|
+
userId: String(event.userId ?? event.unitId)
|
|
99
110
|
}));
|
|
100
111
|
const credited = creditUserEvents(units, identities, userEvents, (userId)=>identityConflicts.add(userId)).events;
|
|
101
112
|
for (const event of direct)if (event.userId != null && linked.has(event.userId)) {
|
|
@@ -121,8 +132,10 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
121
132
|
...units.values()
|
|
122
133
|
].reduce((earliest, unit)=>Math.min(earliest, +unit.firstTs), timestampMs(phase.startedAt)));
|
|
123
134
|
const preFrom = new Date(+from - 14 * 86_400_000);
|
|
135
|
+
const storedEvents = definition.source.startsWith('events:') || definition.source.startsWith('click:');
|
|
136
|
+
const readAge = storedEvents && definition.role === 'primary' && !rapidActivity;
|
|
124
137
|
let events, covariates;
|
|
125
|
-
if (
|
|
138
|
+
if (storedEvents) {
|
|
126
139
|
const eventName = definition.source.startsWith('click:') ? definition.source : definition.source.slice(7);
|
|
127
140
|
if (!definition.source.startsWith('click:') && !options.eventSources?.some((source)=>source.name === eventName)) throw new XpAnalysisError('source-unavailable');
|
|
128
141
|
const read = async (start)=>{
|
|
@@ -130,19 +143,24 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
130
143
|
eventName,
|
|
131
144
|
userIds: ids,
|
|
132
145
|
from: start,
|
|
133
|
-
to
|
|
146
|
+
to,
|
|
147
|
+
readAge
|
|
134
148
|
});
|
|
135
149
|
const direct = await metricEventRows(exec, {
|
|
136
150
|
eventName,
|
|
137
151
|
unitIds: ids,
|
|
138
152
|
from: start,
|
|
139
|
-
to
|
|
153
|
+
to,
|
|
154
|
+
readAge,
|
|
155
|
+
forVisitors: true
|
|
140
156
|
});
|
|
141
157
|
const signedIn = await metricEventRows(exec, {
|
|
142
158
|
eventName,
|
|
143
159
|
userIds,
|
|
144
160
|
from: start,
|
|
145
|
-
to
|
|
161
|
+
to,
|
|
162
|
+
readAge,
|
|
163
|
+
forVisitors: true
|
|
146
164
|
});
|
|
147
165
|
// The two lookups overlap when a linked user's own browser was exposed.
|
|
148
166
|
return [
|
|
@@ -226,13 +244,26 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
226
244
|
// The click-goal delta supersedes whole-phase attribution for mid-test adds.
|
|
227
245
|
// Retain pre-period events for CUPED above; exclude them from the outcome.
|
|
228
246
|
const outcomeEvents = definition.source.startsWith('click:') && definition.addedAt ? events.filter((event)=>timestampMs(event.ts) >= timestampMs(definition.addedAt)) : events;
|
|
247
|
+
const ages = new Map();
|
|
248
|
+
const values = perUnitValues(units, outcomeEvents, {
|
|
249
|
+
kind,
|
|
250
|
+
windowHours,
|
|
251
|
+
endedAt: to,
|
|
252
|
+
onAttributed: readAge ? (event, ts)=>{
|
|
253
|
+
if (event.unitAgeMs === undefined) return;
|
|
254
|
+
const previous = ages.get(event.unitId);
|
|
255
|
+
if (!previous || ts < previous.ts || ts === previous.ts && event.unitAgeMs > previous.unitAgeMs) {
|
|
256
|
+
ages.set(event.unitId, {
|
|
257
|
+
ts,
|
|
258
|
+
unitAgeMs: event.unitAgeMs
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
} : undefined
|
|
262
|
+
});
|
|
263
|
+
if (ages.size) rapidActivity = rapidBrowserEvents(comparedArms, convertingUnits(units, values, ages));
|
|
229
264
|
metricData.push({
|
|
230
265
|
metricId: definition.metricId,
|
|
231
|
-
values
|
|
232
|
-
kind,
|
|
233
|
-
windowHours,
|
|
234
|
-
endedAt: to
|
|
235
|
-
}),
|
|
266
|
+
values,
|
|
236
267
|
...covariates ? {
|
|
237
268
|
covariates
|
|
238
269
|
} : {}
|
|
@@ -284,9 +315,15 @@ async function analyseCandidate(exec, candidate, options, now, deadline, unavail
|
|
|
284
315
|
armMismatch: await armMismatchCount(exec, query),
|
|
285
316
|
identityConflictShare: userIds.length ? identityConflicts.size / userIds.length : 0,
|
|
286
317
|
...phase.phaseKind === 'rollout' ? {
|
|
287
|
-
winnerArm: phase.arms.find((arm)=>arm.kind !== 'holdout').key
|
|
318
|
+
winnerArm: phase.arms.find((arm)=>arm.kind !== 'holdout').key,
|
|
319
|
+
controlLabel: candidate.testArms.find((arm)=>arm.kind === 'control')?.label
|
|
288
320
|
} : {}
|
|
289
321
|
});
|
|
322
|
+
if (rapidActivity) snapshot.health = [
|
|
323
|
+
{
|
|
324
|
+
code: 'rapid-browser-events'
|
|
325
|
+
}
|
|
326
|
+
];
|
|
290
327
|
return snapshot;
|
|
291
328
|
}
|
|
292
329
|
export async function runResults(payload, { budgetMs = 20_000, experimentId, sweep = true } = {}) {
|
|
@@ -407,10 +444,12 @@ export async function runResults(payload, { budgetMs = 20_000, experimentId, swe
|
|
|
407
444
|
for (const [index, snapshot] of snapshots.entries()){
|
|
408
445
|
const previous = phases[index].previousHealth ?? phases[index].frozenSnapshot?.health ?? [];
|
|
409
446
|
const unjudged = previous.filter((row)=>row.code === 'goal-in-some-versions' && content && content.unchecked.length > 0 && clicks.some((metric)=>metric.metricId === row.metricId && !asymmetricGoal(content, metric.source, arms)));
|
|
447
|
+
const activity = snapshot.health?.filter((row)=>row.code === 'rapid-browser-events') ?? [];
|
|
410
448
|
snapshot.health = mergePageHealth(unjudged, [
|
|
411
449
|
...health,
|
|
412
450
|
...goals,
|
|
413
|
-
...unchecked
|
|
451
|
+
...unchecked,
|
|
452
|
+
...activity
|
|
414
453
|
]);
|
|
415
454
|
if (content?.skipped && current.kind === 'block') snapshot.goalFairnessNotice = LEGACY_FAIRNESS;
|
|
416
455
|
else delete snapshot.goalFairnessNotice;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Payload, type PayloadRequest } from 'payload';
|
|
2
|
+
import type { DocId } from '../types/contracts.js';
|
|
3
|
+
import type { StartExperimentResult } from '../types/endpoints.js';
|
|
4
|
+
/** Start a test from trusted host code. Call this after your own transaction commits.
|
|
5
|
+
* Pass the caller's Payload request if available so an open transaction can be refused.
|
|
6
|
+
* Without it, Start can hang waiting for a lock your transaction already holds.
|
|
7
|
+
* If a thrown error has code `commit-unverified`, read the test's status before retrying.
|
|
8
|
+
* Start may have committed even though it could not verify the commit.
|
|
9
|
+
*/
|
|
10
|
+
export declare function startExperiment(payload: Payload, { experiment, req, onlyIfNeverStarted }: {
|
|
11
|
+
experiment: {
|
|
12
|
+
id: DocId;
|
|
13
|
+
} | {
|
|
14
|
+
slug: string;
|
|
15
|
+
};
|
|
16
|
+
/** Pass the caller's request, if available, to detect an open transaction. */
|
|
17
|
+
req?: Pick<PayloadRequest, 'transactionID'>;
|
|
18
|
+
/** Require a draft with no prior round. By default, a stopped test can start a new round. */
|
|
19
|
+
onlyIfNeverStarted?: boolean;
|
|
20
|
+
}): Promise<StartExperimentResult>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createLocalReq } from 'payload';
|
|
2
|
+
import { experimentId } from '../endpoints/routeId.js';
|
|
3
|
+
import { XpRefusal, XpStartTransactionOpen } from '../errors.js';
|
|
4
|
+
import { xpOptionsFromReq } from '../options/fromReq.js';
|
|
5
|
+
import { start } from '../transitions/start.js';
|
|
6
|
+
import { findStartDocuments } from '../transitions/startReads.js';
|
|
7
|
+
/** Start a test from trusted host code. Call this after your own transaction commits.
|
|
8
|
+
* Pass the caller's Payload request if available so an open transaction can be refused.
|
|
9
|
+
* Without it, Start can hang waiting for a lock your transaction already holds.
|
|
10
|
+
* If a thrown error has code `commit-unverified`, read the test's status before retrying.
|
|
11
|
+
* Start may have committed even though it could not verify the commit.
|
|
12
|
+
*/ export async function startExperiment(payload, { experiment, req, onlyIfNeverStarted }) {
|
|
13
|
+
try {
|
|
14
|
+
if (req?.transactionID != null) throw new XpStartTransactionOpen();
|
|
15
|
+
const systemReq = await createLocalReq({}, payload);
|
|
16
|
+
const options = xpOptionsFromReq(systemReq);
|
|
17
|
+
const id = 'id' in experiment ? experimentId(systemReq, experiment.id) : (await findStartDocuments(systemReq, {
|
|
18
|
+
collection: 'xp-experiments',
|
|
19
|
+
depth: 0,
|
|
20
|
+
limit: 1,
|
|
21
|
+
where: {
|
|
22
|
+
slug: {
|
|
23
|
+
equals: experiment.slug
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}, true)).docs[0]?.id;
|
|
27
|
+
if (id === undefined) return {
|
|
28
|
+
status: 'not-found'
|
|
29
|
+
};
|
|
30
|
+
const { doc, revision, detail } = await start(systemReq, {
|
|
31
|
+
experimentId: id,
|
|
32
|
+
options,
|
|
33
|
+
system: true,
|
|
34
|
+
onlyIfNeverStarted
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
status: 'started',
|
|
38
|
+
phase: doc.phase,
|
|
39
|
+
revision,
|
|
40
|
+
warnings: detail ?? []
|
|
41
|
+
};
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error instanceof XpStartTransactionOpen) return {
|
|
44
|
+
status: 'refused',
|
|
45
|
+
code: 'transaction-open',
|
|
46
|
+
message: error.message
|
|
47
|
+
};
|
|
48
|
+
if (!(error instanceof XpRefusal) || error.status === 500 || error.code === 'commit-unverified') throw error;
|
|
49
|
+
if (error.code === 'not-found') return {
|
|
50
|
+
status: 'not-found'
|
|
51
|
+
};
|
|
52
|
+
const { code, message, detail } = error;
|
|
53
|
+
if (code === 'first-start-only') {
|
|
54
|
+
return {
|
|
55
|
+
status: 'refused',
|
|
56
|
+
code,
|
|
57
|
+
message,
|
|
58
|
+
detail: detail
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
status: 'refused',
|
|
63
|
+
code,
|
|
64
|
+
message,
|
|
65
|
+
...detail === undefined ? {} : {
|
|
66
|
+
detail
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { safeError } from '../log.js';
|
|
2
2
|
import { NextRequest } from 'next/server.js';
|
|
3
3
|
import { pooledExecutor } from '../db/executor.js';
|
|
4
|
-
import {
|
|
4
|
+
import { insertServerConversion } from '../db/events.js';
|
|
5
5
|
import { readUnitCookie } from '../runtime/cookie.js';
|
|
6
6
|
export async function trackConversion(serverRuntime, event) {
|
|
7
7
|
let payload;
|
|
@@ -46,18 +46,15 @@ export async function trackConversion(serverRuntime, event) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
if (!visitorId && !userId) return;
|
|
49
|
-
await
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
ts: new Date().toISOString()
|
|
59
|
-
}
|
|
60
|
-
], (message)=>payload.logger.error(message));
|
|
49
|
+
await insertServerConversion(pooledExecutor(payload), {
|
|
50
|
+
eventName: event.eventName,
|
|
51
|
+
value: event.value ?? 1,
|
|
52
|
+
unitId: visitorId ?? userId,
|
|
53
|
+
unitType: visitorId ? 'visitor' : 'user',
|
|
54
|
+
userId,
|
|
55
|
+
idempotencyKey: event.idempotencyKey,
|
|
56
|
+
ts: new Date().toISOString()
|
|
57
|
+
}, (message)=>payload.logger.error(message));
|
|
61
58
|
} catch (error) {
|
|
62
59
|
try {
|
|
63
60
|
payload?.logger.error({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DocId } from '../types/contracts.js';
|
|
2
2
|
import type { PreflightResult } from '../types/endpoints.js';
|
|
3
|
-
export declare function PreviewLinks({ experimentId, placements, arms, flagPoint, apiRoute }: {
|
|
3
|
+
export declare function PreviewLinks({ experimentId, placements, arms, flagPoint, apiRoute, showEditLinks }: {
|
|
4
|
+
showEditLinks?: boolean;
|
|
4
5
|
apiRoute: string;
|
|
5
6
|
flagPoint?: string;
|
|
6
7
|
experimentId: DocId;
|
|
@@ -9,7 +9,7 @@ import { placementLabel } from './placementLabel.js';
|
|
|
9
9
|
import { TEST_PAGE } from './copy/testPage.js';
|
|
10
10
|
import { API_MESSAGES, refusalMessage } from './copy/common.js';
|
|
11
11
|
import { actionablePreviewPages } from './previewLinks.model.js';
|
|
12
|
-
export function PreviewLinks({ experimentId, placements, arms, flagPoint, apiRoute }) {
|
|
12
|
+
export function PreviewLinks({ experimentId, placements, arms, flagPoint, apiRoute, showEditLinks = true }) {
|
|
13
13
|
const api = useApi(apiRoute);
|
|
14
14
|
const inFlight = useRef(false);
|
|
15
15
|
const [busy, setBusy] = useState(false);
|
|
@@ -86,8 +86,8 @@ export function PreviewLinks({ experimentId, placements, arms, flagPoint, apiRou
|
|
|
86
86
|
arm.label?.trim() || armLabel(arm.key)
|
|
87
87
|
]
|
|
88
88
|
}, arm.key)) : null,
|
|
89
|
-
placement.editorUrl ? /*#__PURE__*/ _jsx(Button, {
|
|
90
|
-
variant: "
|
|
89
|
+
showEditLinks && placement.editorUrl ? /*#__PURE__*/ _jsx(Button, {
|
|
90
|
+
variant: "secondary",
|
|
91
91
|
size: "sm",
|
|
92
92
|
href: placement.editorUrl,
|
|
93
93
|
"aria-label": pages.length > 1 ? `${TEST_PAGE.editOnPage}: ${placementLabel(placement)}` : undefined,
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { DocId } from '../../types/contracts.js';
|
|
2
|
-
import type { PreflightResult } from '../../types/endpoints.js';
|
|
3
|
-
import type
|
|
4
|
-
export declare function DecideDialog({ id, arms, checks, onClose, apiRoute, onSuccess }: {
|
|
2
|
+
import type { ResultsResponse, PreflightResult } from '../../types/endpoints.js';
|
|
3
|
+
import { type ActionGroup } from './actions.model.js';
|
|
4
|
+
export declare function DecideDialog({ id, name, phase, arms, results, checks, unavailable, pending, onClose, apiRoute, onSuccess, onRefusal }: {
|
|
5
5
|
apiRoute: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
phase?: number;
|
|
8
|
+
onRefusal?: () => void;
|
|
9
|
+
unavailable?: boolean;
|
|
10
|
+
pending?: boolean;
|
|
6
11
|
onSuccess?: (doc?: Record<string, unknown>) => void;
|
|
7
12
|
id: DocId;
|
|
8
|
-
arms
|
|
13
|
+
arms?: readonly ActionGroup[];
|
|
14
|
+
results?: ResultsResponse;
|
|
9
15
|
checks?: PreflightResult['checks'];
|
|
10
16
|
onClose: () => void;
|
|
11
17
|
}): import("react").JSX.Element;
|