@delmaredigital/payload-experiments 0.4.1 → 0.5.1
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 -5
- package/dist/admin/blocks/model.js +2 -0
- package/dist/admin/copy/blocks.d.ts +1 -0
- package/dist/admin/copy/blocks.js +1 -0
- package/dist/admin/copy/status.d.ts +3 -0
- package/dist/admin/copy/status.js +3 -0
- package/dist/admin/placementStatus.model.js +3 -0
- package/dist/admin/status.model.d.ts +3 -2
- package/dist/admin/status.model.js +9 -3
- package/dist/admin/surface/ResultsRoute.js +2 -1
- package/dist/admin/surface/TestsHome.d.ts +2 -1
- package/dist/admin/surface/TestsHome.js +31 -11
- package/dist/admin/surface/TestsSurface.js +4 -0
- package/dist/admin/surface/home.model.d.ts +11 -6
- package/dist/admin/surface/home.model.js +19 -8
- package/dist/admin/surface/newTest/PageWizard.js +13 -3
- package/dist/admin/surface/results/ResultsHeader.js +43 -9
- package/dist/admin/surface/test/TestPage.js +11 -1
- package/dist/admin/useLayerUsage.d.ts +1 -1
- package/dist/admin/views/buildSurfaceProps.js +3 -0
- package/dist/blocks/placementLocale.d.ts +14 -0
- package/dist/blocks/placementLocale.js +80 -13
- package/dist/blocks/placementPublication.d.ts +14 -0
- package/dist/blocks/placementPublication.js +24 -0
- package/dist/cohorts/build.d.ts +35 -0
- package/dist/cohorts/build.js +134 -0
- package/dist/cohorts/key.d.ts +12 -0
- package/dist/cohorts/key.js +15 -0
- package/dist/cohorts/maintenance.d.ts +10 -0
- package/dist/cohorts/maintenance.js +70 -0
- package/dist/cohorts/readiness.d.ts +30 -0
- package/dist/cohorts/readiness.js +54 -0
- package/dist/cohorts/readinessData.d.ts +29 -0
- package/dist/cohorts/readinessData.js +123 -0
- package/dist/cohorts/rule.d.ts +33 -0
- package/dist/cohorts/rule.js +50 -0
- package/dist/collections/cohortMembers.d.ts +4 -0
- package/dist/collections/cohortMembers.js +95 -0
- package/dist/collections/experiments/config.js +157 -7
- package/dist/collections/experiments/editability.js +10 -6
- package/dist/collections/experiments/lockHook.js +39 -20
- package/dist/collections/index.js +4 -1
- package/dist/collections/phases.js +4 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/db/adapter.d.ts +2 -1
- package/dist/db/adapter.js +17 -4
- package/dist/db/appends.d.ts +2 -1
- package/dist/db/appends.js +3 -2
- package/dist/db/bulkPlacementRemoval.d.ts +5 -0
- package/dist/db/bulkPlacementRemoval.js +7 -2
- package/dist/db/cohortMembership.d.ts +11 -0
- package/dist/db/cohortMembership.js +31 -0
- package/dist/db/cohortPool.d.ts +9 -0
- package/dist/db/cohortPool.js +53 -0
- package/dist/db/cohortTransactions.d.ts +3 -0
- package/dist/db/cohortTransactions.js +52 -0
- package/dist/db/cohorts.d.ts +72 -0
- package/dist/db/cohorts.js +280 -0
- package/dist/db/erase.d.ts +2 -0
- package/dist/db/erase.js +21 -2
- package/dist/db/events.d.ts +2 -0
- package/dist/db/events.js +8 -0
- package/dist/db/executor.d.ts +2 -0
- package/dist/db/executor.js +8 -0
- package/dist/db/locks.d.ts +7 -0
- package/dist/db/locks.js +13 -1
- package/dist/db/names.d.ts +95 -1
- package/dist/db/names.js +95 -1
- package/dist/db/occupancy.d.ts +21 -0
- package/dist/db/occupancy.js +46 -0
- package/dist/db/pageBindings.d.ts +2 -2
- package/dist/db/pageBindings.js +3 -3
- package/dist/db/pageOccupancy.d.ts +4 -4
- package/dist/db/pageOccupancy.js +13 -10
- package/dist/db/pgExecutor.d.ts +4 -0
- package/dist/db/pgExecutor.js +1 -1
- package/dist/db/placements.d.ts +6 -1
- package/dist/db/placements.js +27 -1
- package/dist/db/results.d.ts +5 -2
- package/dist/db/results.js +32 -5
- package/dist/db/slices.d.ts +9 -2
- package/dist/db/slices.js +15 -8
- package/dist/db/snapshots.d.ts +16 -1
- package/dist/db/snapshots.js +27 -2
- package/dist/db/sql.d.ts +2 -2
- package/dist/db/sql.js +1 -2
- package/dist/endpoints/cohortSources.d.ts +16 -0
- package/dist/endpoints/cohortSources.js +335 -0
- package/dist/endpoints/contentLocale.d.ts +1 -1
- package/dist/endpoints/duplicateOriginal.d.ts +1 -0
- package/dist/endpoints/events.js +82 -18
- package/dist/endpoints/index.js +45 -1
- package/dist/endpoints/pausedBy.d.ts +14 -0
- package/dist/endpoints/pausedBy.js +94 -0
- package/dist/endpoints/preflight.js +4 -1
- package/dist/endpoints/previewToken.js +2 -0
- package/dist/endpoints/results.d.ts +2 -2
- package/dist/endpoints/results.js +111 -3
- package/dist/endpoints/routeId.d.ts +2 -1
- package/dist/endpoints/routeId.js +6 -2
- package/dist/endpoints/summary.js +24 -1
- package/dist/endpoints/transitions.d.ts +7 -0
- package/dist/endpoints/transitions.js +50 -1
- package/dist/events/rows.d.ts +1 -1
- package/dist/events/rows.js +5 -3
- package/dist/exports/index.d.ts +2 -0
- package/dist/exports/index.js +1 -0
- package/dist/exports/runtimeProxy.d.ts +1 -0
- package/dist/exports/runtimeProxy.js +1 -0
- package/dist/hooks/blockRemovalRule.d.ts +1 -1
- package/dist/hooks/blockRemovalRule.js +12 -8
- package/dist/hooks/pageGuard.d.ts +7 -1
- package/dist/hooks/pageGuard.js +177 -4
- package/dist/hooks/puckNestedTests.d.ts +1 -1
- package/dist/hooks/puckNestedTests.js +3 -1
- package/dist/labels/status.d.ts +15 -0
- package/dist/labels/status.js +12 -0
- package/dist/manifest/compile.d.ts +15 -4
- package/dist/manifest/compile.js +91 -3
- package/dist/onInit.js +4 -6
- package/dist/options.d.ts +1 -0
- package/dist/options.js +10 -0
- package/dist/proxy/consentFallback.d.ts +1 -1
- package/dist/proxy/consentFallback.js +4 -4
- package/dist/proxy/control.d.ts +1 -1
- package/dist/proxy/control.js +2 -2
- package/dist/proxy/pageRewrite.d.ts +1 -1
- package/dist/proxy/pageRewrite.js +3 -2
- package/dist/proxy/resolve.js +76 -17
- package/dist/puck/ExperimentPicker.js +2 -1
- package/dist/puck/copy.d.ts +6 -5
- package/dist/puck/copy.js +3 -7
- package/dist/puck/editor/ExperimentSlotEditor.js +16 -5
- package/dist/puck/editor/QuickTestActions.js +7 -1
- package/dist/puck/editor/armWrites.js +6 -1
- package/dist/puck/editor/copy.d.ts +3 -0
- package/dist/puck/editor/copy.js +3 -0
- package/dist/puck/editor/editor.css +2 -1
- package/dist/puck/editor/editor.model.d.ts +2 -1
- package/dist/puck/editor/editor.model.js +2 -0
- package/dist/puck/editor/placementsCache.d.ts +1 -1
- package/dist/puck/editor/placementsCache.js +6 -3
- package/dist/results/analyse.d.ts +3 -1
- package/dist/results/analyse.js +20 -3
- package/dist/results/health.d.ts +11 -0
- package/dist/results/health.js +38 -0
- package/dist/results/power.d.ts +1 -1
- package/dist/results/power.js +1 -1
- package/dist/results/snapshot.d.ts +8 -2
- package/dist/results/snapshot.js +23 -1
- package/dist/results/unitValues.d.ts +48 -0
- package/dist/results/unitValues.js +166 -0
- package/dist/runtime/assign.d.ts +7 -3
- package/dist/runtime/assign.js +12 -4
- package/dist/runtime/cohortCookie.d.ts +15 -0
- package/dist/runtime/cohortCookie.js +72 -0
- package/dist/runtime/cohortLookup.d.ts +9 -0
- package/dist/runtime/cohortLookup.js +25 -0
- package/dist/runtime/eligibility.d.ts +11 -5
- package/dist/runtime/eligibility.js +33 -7
- package/dist/runtime/header.d.ts +1 -0
- package/dist/runtime/header.js +1 -1
- package/dist/runtime/proxyRuntime.js +5 -1
- package/dist/runtime/targeting.d.ts +3 -2
- package/dist/runtime/targeting.js +2 -1
- package/dist/sanitizeReadinessDetail.d.ts +2 -2
- package/dist/sanitizeReadinessDetail.js +41 -4
- package/dist/schedule/activeTime.d.ts +28 -0
- package/dist/schedule/activeTime.js +322 -0
- package/dist/schedule/ranges.d.ts +13 -0
- package/dist/schedule/ranges.js +11 -0
- package/dist/schedule/roundTime.d.ts +10 -0
- package/dist/schedule/roundTime.js +45 -0
- package/dist/schedule/types.d.ts +29 -0
- package/dist/schedule/types.js +1 -0
- package/dist/server/cohortLookup.d.ts +3 -0
- package/dist/server/cohortLookup.js +7 -0
- package/dist/server/eraseUser.d.ts +1 -0
- package/dist/server/getAssignments.js +63 -40
- package/dist/server/previewDraft.d.ts +1 -1
- package/dist/server/previewDraft.js +3 -2
- package/dist/server/recordContentChange.d.ts +1 -1
- package/dist/server/recordContentChange.js +42 -20
- package/dist/server/recordExposures.js +4 -2
- package/dist/server/runResults.js +97 -150
- package/dist/testSurface/actions/LifecycleAction.d.ts +2 -1
- package/dist/testSurface/actions/LifecycleAction.js +15 -5
- package/dist/testSurface/actions/actions.model.d.ts +13 -2
- package/dist/testSurface/actions/actions.model.js +38 -5
- package/dist/testSurface/api.d.ts +13 -1
- package/dist/testSurface/api.js +19 -0
- package/dist/testSurface/copy/actions.d.ts +13 -0
- package/dist/testSurface/copy/actions.js +13 -0
- package/dist/testSurface/copy/cohorts.d.ts +68 -0
- package/dist/testSurface/copy/cohorts.js +81 -0
- package/dist/testSurface/copy/common.d.ts +2 -3
- package/dist/testSurface/copy/common.js +4 -4
- package/dist/testSurface/copy/inputs.d.ts +3 -0
- package/dist/testSurface/copy/inputs.js +3 -0
- package/dist/testSurface/copy/readiness.d.ts +20 -6
- package/dist/testSurface/copy/readiness.js +42 -9
- package/dist/testSurface/copy/results.d.ts +1 -0
- package/dist/testSurface/copy/results.js +1 -0
- package/dist/testSurface/copy/schedule.d.ts +58 -0
- package/dist/testSurface/copy/schedule.js +150 -0
- package/dist/testSurface/copy/surface.d.ts +2 -0
- package/dist/testSurface/copy/surface.js +2 -0
- package/dist/testSurface/copy/testPage.d.ts +12 -2
- package/dist/testSurface/copy/testPage.js +17 -2
- package/dist/testSurface/format/roundProgress.d.ts +13 -1
- package/dist/testSurface/format/roundProgress.js +34 -5
- package/dist/testSurface/format/scheduleStatus.d.ts +34 -0
- package/dist/testSurface/format/scheduleStatus.js +93 -0
- package/dist/testSurface/format/useScheduleClock.d.ts +3 -0
- package/dist/testSurface/format/useScheduleClock.js +20 -0
- package/dist/testSurface/labels.d.ts +4 -9
- package/dist/testSurface/labels.js +2 -7
- package/dist/testSurface/lockedNotice.model.d.ts +2 -2
- package/dist/testSurface/lockedNotice.model.js +16 -3
- package/dist/testSurface/readPreflight.d.ts +3 -0
- package/dist/testSurface/readPreflight.js +14 -0
- package/dist/testSurface/readinessRead.d.ts +2 -2
- package/dist/testSurface/results/DataQualityPanel.js +7 -7
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/results/results.model.js +34 -6
- package/dist/testSurface/review/cohortEstimate.d.ts +11 -0
- package/dist/testSurface/review/cohortEstimate.js +32 -0
- package/dist/testSurface/surface/contracts.d.ts +2 -1
- package/dist/testSurface/surface/contracts.js +1 -0
- package/dist/testSurface/surface/editorPlacement.d.ts +1 -0
- package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +3 -2
- package/dist/testSurface/surface/readiness/ActionDialogs.js +121 -32
- package/dist/testSurface/surface/readiness/Banner.js +29 -11
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +20 -2
- package/dist/testSurface/surface/readiness/readiness.model.js +35 -5
- package/dist/testSurface/surface/readiness/useTransition.js +17 -5
- package/dist/testSurface/surface/results/ResultsBody.js +44 -8
- package/dist/testSurface/surface/results/useResults.d.ts +16 -1
- package/dist/testSurface/surface/results/useResults.js +17 -6
- package/dist/testSurface/surface/test/CohortRuleEditor.d.ts +16 -0
- package/dist/testSurface/surface/test/CohortRuleEditor.js +492 -0
- package/dist/testSurface/surface/test/LengthSection.js +26 -6
- package/dist/testSurface/surface/test/ScheduleDateInput.d.ts +4 -0
- package/dist/testSurface/surface/test/ScheduleDateInput.js +15 -0
- package/dist/testSurface/surface/test/ScheduleSection.d.ts +2 -0
- package/dist/testSurface/surface/test/ScheduleSection.js +322 -0
- package/dist/testSurface/surface/test/Section.js +1 -1
- package/dist/testSurface/surface/test/TargetingSection.js +306 -182
- package/dist/testSurface/surface/test/TestSurface.js +9 -0
- package/dist/testSurface/surface/test/fields.d.ts +2 -1
- package/dist/testSurface/surface/test/fields.js +3 -3
- package/dist/testSurface/surface/test/jumpToSection.d.ts +1 -1
- package/dist/testSurface/surface/test/jumpToSection.js +4 -4
- package/dist/testSurface/surface/test/testPage.css +26 -0
- package/dist/testSurface/surface/testDocument.model.d.ts +12 -1
- package/dist/testSurface/surface/testDocument.model.js +2 -1
- package/dist/testSurface/surface/useTestDocument.js +11 -4
- package/dist/testSurface/targeting/targeting.model.d.ts +2 -1
- package/dist/testSurface/targeting/targeting.model.js +1 -1
- package/dist/testSurface/useApi.d.ts +12 -0
- package/dist/transitions/addMetric.js +5 -2
- package/dist/transitions/allocate.js +6 -1
- package/dist/transitions/assertNoOverlap.d.ts +9 -0
- package/dist/transitions/assertNoOverlap.js +24 -0
- package/dist/transitions/buildCohorts.d.ts +10 -0
- package/dist/transitions/buildCohorts.js +68 -0
- package/dist/transitions/cancelSchedule.d.ts +4 -0
- package/dist/transitions/cancelSchedule.js +42 -0
- package/dist/transitions/checkStart.d.ts +17 -3
- package/dist/transitions/checkStart.js +20 -7
- package/dist/transitions/decide.js +40 -13
- package/dist/transitions/kernel.d.ts +3 -1
- package/dist/transitions/kernel.js +5 -2
- package/dist/transitions/pause.d.ts +4 -0
- package/dist/transitions/pause.js +35 -0
- package/dist/transitions/phaseRecord.d.ts +19 -2
- package/dist/transitions/phaseRecord.js +50 -11
- package/dist/transitions/placementInteractions.d.ts +7 -2
- package/dist/transitions/placementInteractions.js +9 -7
- package/dist/transitions/placements.d.ts +4 -3
- package/dist/transitions/placements.js +28 -14
- package/dist/transitions/preflightData.d.ts +11 -3
- package/dist/transitions/preflightData.js +134 -81
- package/dist/transitions/reschedule.d.ts +4 -0
- package/dist/transitions/reschedule.js +58 -0
- package/dist/transitions/resume.d.ts +4 -0
- package/dist/transitions/resume.js +32 -0
- package/dist/transitions/scheduledRound.d.ts +18 -0
- package/dist/transitions/scheduledRound.js +42 -0
- package/dist/transitions/start.d.ts +4 -0
- package/dist/transitions/start.js +139 -56
- package/dist/transitions/startReads.d.ts +14 -0
- package/dist/transitions/startReads.js +27 -0
- package/dist/transitions/stop.d.ts +10 -0
- package/dist/transitions/stop.js +35 -22
- package/dist/types/admin.d.ts +1 -1
- package/dist/types/contracts.d.ts +7 -1
- package/dist/types/endpoints.d.ts +72 -3
- package/dist/types/manifest.d.ts +9 -0
- package/dist/types/runtime.d.ts +5 -0
- package/dist/types/snapshot.d.ts +10 -0
- package/dist/types/status.d.ts +1 -0
- package/dist/types/status.js +1 -0
- package/dist/types/surface.d.ts +1 -0
- package/dist/ui/Feedback.d.ts +9 -6
- package/dist/ui/Feedback.js +10 -9
- package/dist/ui/SelectControl.js +1 -1
- package/dist/ui/ui.css +2 -1
- package/package.json +2 -2
package/dist/endpoints/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { XP_MANIFEST_KEY_HEADER } from '../constants.js';
|
|
|
6
6
|
import { XpNotImplemented, XpRefusal } from '../errors.js';
|
|
7
7
|
import { handleManifest } from './manifest.js';
|
|
8
8
|
import { handleEvents } from './events.js';
|
|
9
|
-
import { handleStart, handleAllocate, handleAddMetric, handleStop, handleDecide, handleReleaseHoldout, handleReleasePages, handleMakeContent, handleDismissContentEntry, handleRestoreContentEntry, handleArchive } from './transitions.js';
|
|
9
|
+
import { handleBuildCohorts, handleStart, handleAllocate, handleAddMetric, handleStop, handlePause, handleResume, handleReschedule, handleCancelSchedule, handleDecide, handleReleaseHoldout, handleReleasePages, handleMakeContent, handleDismissContentEntry, handleRestoreContentEntry, handleArchive } from './transitions.js';
|
|
10
10
|
import { handlePreflight } from './preflight.js';
|
|
11
11
|
import { handleTestVersion } from './testVersion.js';
|
|
12
12
|
import { handlePreviewToken } from './previewToken.js';
|
|
@@ -14,9 +14,11 @@ import { handleResults } from './results.js';
|
|
|
14
14
|
import { handleRecompute } from './recompute.js';
|
|
15
15
|
import { handleWrapBlock } from './wrapBlock.js';
|
|
16
16
|
import { handleDuplicateOriginal } from './duplicateOriginal.js';
|
|
17
|
+
import { handleCohortSources } from './cohortSources.js';
|
|
17
18
|
import { handlePages } from './pages.js';
|
|
18
19
|
import { handlePlacementStatus } from './placementStatus.js';
|
|
19
20
|
import { handleSummary } from './summary.js';
|
|
21
|
+
import { handlePausedBy } from './pausedBy.js';
|
|
20
22
|
export const ROUTES = [
|
|
21
23
|
{
|
|
22
24
|
method: 'get',
|
|
@@ -30,6 +32,12 @@ export const ROUTES = [
|
|
|
30
32
|
access: 'browserEvents',
|
|
31
33
|
handler: handleEvents
|
|
32
34
|
},
|
|
35
|
+
{
|
|
36
|
+
method: 'post',
|
|
37
|
+
path: '/xp/experiments/:id/build-cohorts',
|
|
38
|
+
access: 'manage',
|
|
39
|
+
handler: handleBuildCohorts
|
|
40
|
+
},
|
|
33
41
|
{
|
|
34
42
|
method: 'post',
|
|
35
43
|
path: '/xp/experiments/:id/start',
|
|
@@ -54,6 +62,30 @@ export const ROUTES = [
|
|
|
54
62
|
access: 'manage',
|
|
55
63
|
handler: handleStop
|
|
56
64
|
},
|
|
65
|
+
{
|
|
66
|
+
method: 'post',
|
|
67
|
+
path: '/xp/experiments/:id/pause',
|
|
68
|
+
access: 'manage',
|
|
69
|
+
handler: handlePause
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
method: 'post',
|
|
73
|
+
path: '/xp/experiments/:id/resume',
|
|
74
|
+
access: 'manage',
|
|
75
|
+
handler: handleResume
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
method: 'post',
|
|
79
|
+
path: '/xp/experiments/:id/reschedule',
|
|
80
|
+
access: 'manage',
|
|
81
|
+
handler: handleReschedule
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
method: 'post',
|
|
85
|
+
path: '/xp/experiments/:id/cancel-schedule',
|
|
86
|
+
access: 'manage',
|
|
87
|
+
handler: handleCancelSchedule
|
|
88
|
+
},
|
|
57
89
|
{
|
|
58
90
|
method: 'post',
|
|
59
91
|
path: '/xp/experiments/:id/decide',
|
|
@@ -138,6 +170,12 @@ export const ROUTES = [
|
|
|
138
170
|
access: 'readResults',
|
|
139
171
|
handler: handleSummary
|
|
140
172
|
},
|
|
173
|
+
{
|
|
174
|
+
method: 'get',
|
|
175
|
+
path: '/xp/experiments/paused-by',
|
|
176
|
+
access: 'manage',
|
|
177
|
+
handler: handlePausedBy
|
|
178
|
+
},
|
|
141
179
|
{
|
|
142
180
|
method: 'post',
|
|
143
181
|
path: '/xp/blocks/wrap',
|
|
@@ -156,6 +194,12 @@ export const ROUTES = [
|
|
|
156
194
|
access: 'manage',
|
|
157
195
|
handler: handlePages
|
|
158
196
|
},
|
|
197
|
+
{
|
|
198
|
+
method: 'get',
|
|
199
|
+
path: '/xp/cohort-sources',
|
|
200
|
+
access: 'manage',
|
|
201
|
+
handler: handleCohortSources
|
|
202
|
+
},
|
|
159
203
|
{
|
|
160
204
|
method: 'get',
|
|
161
205
|
path: '/xp/experiments/:id/duplicate-original',
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
import type { DocId, Status } from '../types/contracts.js';
|
|
3
|
+
import type { PauseAttribution } from '../types/endpoints.js';
|
|
4
|
+
type TestPause = {
|
|
5
|
+
id: DocId;
|
|
6
|
+
status: Status;
|
|
7
|
+
pausedAt?: string | null;
|
|
8
|
+
pausedBy?: string | null;
|
|
9
|
+
};
|
|
10
|
+
/** Resolve only the host's configured title, through the viewing manager's access. */
|
|
11
|
+
export declare function readPauseAttributions(req: PayloadRequest, tests: readonly TestPause[]): Promise<Map<string, PauseAttribution>>;
|
|
12
|
+
/** Supply every paused list row with at most one host user collection read. */
|
|
13
|
+
export declare function handlePausedBy(req: PayloadRequest): Promise<Response>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { collectionIDType } from './routeId.js';
|
|
2
|
+
/** Resolve only the host's configured title, through the viewing manager's access. */ export async function readPauseAttributions(req, tests) {
|
|
3
|
+
const paused = tests.filter((test)=>test.status === 'paused' && typeof test.pausedBy === 'string' && test.pausedBy.length > 0);
|
|
4
|
+
const ids = [
|
|
5
|
+
...new Set(paused.map((test)=>test.pausedBy))
|
|
6
|
+
];
|
|
7
|
+
const [id] = ids;
|
|
8
|
+
const attributions = new Map();
|
|
9
|
+
const collection = req.payload.config.admin?.user;
|
|
10
|
+
if (!id || !collection) return attributions;
|
|
11
|
+
const config = req.payload.config.collections.find((entry)=>entry.slug === collection);
|
|
12
|
+
if (!config) return attributions;
|
|
13
|
+
const title = config.admin?.useAsTitle;
|
|
14
|
+
const field = title && title !== 'id' ? title : 'email';
|
|
15
|
+
const select = {
|
|
16
|
+
[field]: true
|
|
17
|
+
};
|
|
18
|
+
const userIds = collectionIDType(req, collection) === 'number' ? ids.map(Number).filter(Number.isFinite) : ids;
|
|
19
|
+
const [userId] = userIds;
|
|
20
|
+
if (userId === undefined) return attributions;
|
|
21
|
+
try {
|
|
22
|
+
// A single test can use collection read rules that depend on the requested user id.
|
|
23
|
+
const { docs } = userIds.length === 1 ? {
|
|
24
|
+
docs: [
|
|
25
|
+
await req.payload.findByID({
|
|
26
|
+
collection,
|
|
27
|
+
id: userId,
|
|
28
|
+
req,
|
|
29
|
+
overrideAccess: false,
|
|
30
|
+
depth: 0,
|
|
31
|
+
select,
|
|
32
|
+
disableErrors: true
|
|
33
|
+
})
|
|
34
|
+
]
|
|
35
|
+
} : await req.payload.find({
|
|
36
|
+
collection,
|
|
37
|
+
req,
|
|
38
|
+
overrideAccess: false,
|
|
39
|
+
depth: 0,
|
|
40
|
+
select,
|
|
41
|
+
pagination: false,
|
|
42
|
+
limit: 0,
|
|
43
|
+
where: {
|
|
44
|
+
id: {
|
|
45
|
+
in: userIds
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const names = new Map(docs.flatMap((doc)=>{
|
|
50
|
+
if (!doc) return [];
|
|
51
|
+
const value = doc[field];
|
|
52
|
+
return typeof value === 'string' && value.trim() ? [
|
|
53
|
+
[
|
|
54
|
+
String(doc.id),
|
|
55
|
+
value.trim()
|
|
56
|
+
]
|
|
57
|
+
] : [];
|
|
58
|
+
}));
|
|
59
|
+
for (const test of paused){
|
|
60
|
+
const name = names.get(test.pausedBy);
|
|
61
|
+
if (name) attributions.set(String(test.id), {
|
|
62
|
+
name,
|
|
63
|
+
pausedAt: test.pausedAt ?? null
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
} catch {}
|
|
67
|
+
return attributions;
|
|
68
|
+
}
|
|
69
|
+
/** Supply every paused list row with at most one host user collection read. */ export async function handlePausedBy(req) {
|
|
70
|
+
const { docs } = await req.payload.find({
|
|
71
|
+
collection: 'xp-experiments',
|
|
72
|
+
req,
|
|
73
|
+
overrideAccess: false,
|
|
74
|
+
depth: 0,
|
|
75
|
+
pagination: false,
|
|
76
|
+
limit: 0,
|
|
77
|
+
where: {
|
|
78
|
+
status: {
|
|
79
|
+
equals: 'paused'
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
select: {
|
|
83
|
+
status: true,
|
|
84
|
+
pausedAt: true,
|
|
85
|
+
pausedBy: true
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
const attributions = await readPauseAttributions(req, docs);
|
|
89
|
+
return Response.json(Object.fromEntries(attributions), {
|
|
90
|
+
headers: {
|
|
91
|
+
'Cache-Control': 'private, no-store'
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -5,6 +5,7 @@ import { preflightData } from '../transitions/preflightData.js';
|
|
|
5
5
|
import { routeId } from './routeId.js';
|
|
6
6
|
export async function handlePreflight(req, ctx, dependencies) {
|
|
7
7
|
const id = routeId(req);
|
|
8
|
+
const seenPause = new URL(req.url ?? 'http://xp.invalid').searchParams.get('seenPause');
|
|
8
9
|
const placementLocale = contentLocale(req).locale ?? undefined;
|
|
9
10
|
const localization = req.payload.config.localization;
|
|
10
11
|
// The query selects readiness labels only. Host reads must match Start's default request.
|
|
@@ -19,7 +20,9 @@ export async function handlePreflight(req, ctx, dependencies) {
|
|
|
19
20
|
const result = id !== undefined ? await preflightData(readinessReq, {
|
|
20
21
|
experimentId: id,
|
|
21
22
|
options: ctx.options,
|
|
22
|
-
placementLocale
|
|
23
|
+
placementLocale,
|
|
24
|
+
viewingReq: req,
|
|
25
|
+
seenPause
|
|
23
26
|
}, dependencies) : null;
|
|
24
27
|
const headers = {
|
|
25
28
|
'Cache-Control': 'no-store'
|
|
@@ -31,9 +31,11 @@ export async function handlePreviewToken(req, { options }) {
|
|
|
31
31
|
});
|
|
32
32
|
const experiment = result.docs[0];
|
|
33
33
|
if (!experiment) return refuse(404, 'not-found', 'Experiment not found');
|
|
34
|
+
// 0.5 T3/T8 refines
|
|
34
35
|
if (![
|
|
35
36
|
'draft',
|
|
36
37
|
'running',
|
|
38
|
+
'paused',
|
|
37
39
|
'stopped',
|
|
38
40
|
'decided'
|
|
39
41
|
].includes(experiment.status)) return refuse(409, 'invalid-status', 'This experiment cannot be previewed');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { type SnapshotWithLegacyExposures } from '../results/snapshot.js';
|
|
1
2
|
import type { PayloadRequest } from 'payload';
|
|
2
3
|
import type { EndpointContext, RefusalCode } from '../types/endpoints.js';
|
|
3
4
|
import type { DocId } from '../types/contracts.js';
|
|
4
|
-
import type { Snapshot } from '../types/snapshot.js';
|
|
5
5
|
export declare function resultsError(status: number, code: RefusalCode, message: string): Response;
|
|
6
6
|
export type SnapshotDocument = {
|
|
7
7
|
id: DocId;
|
|
@@ -10,7 +10,7 @@ export type SnapshotDocument = {
|
|
|
10
10
|
};
|
|
11
11
|
phase: number;
|
|
12
12
|
computedAt: string;
|
|
13
|
-
snapshot:
|
|
13
|
+
snapshot: SnapshotWithLegacyExposures;
|
|
14
14
|
};
|
|
15
15
|
export declare function readSnapshots(req: PayloadRequest, ids: DocId[], { per, decisionId, seriesPhase }?: {
|
|
16
16
|
per?: 'phase' | 'experiment';
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { cohortRelationshipId, readCohortRule } from '../cohorts/rule.js';
|
|
2
|
+
import { cohortRuleSummary } from '../testSurface/copy/cohorts.js';
|
|
3
|
+
import { withCohortExitDefault } from '../results/snapshot.js';
|
|
1
4
|
import { resultsMetadata, newestSnapshotIds } from '../db/snapshots.js';
|
|
2
5
|
import { pooledExecutor } from '../db/executor.js';
|
|
3
6
|
import { routeId } from './routeId.js';
|
|
4
7
|
import { isClickSource } from '../goals/key.js';
|
|
5
8
|
import { browserWritableMetric } from '../events/writable.js';
|
|
9
|
+
import { publicRoundTiming } from '../schedule/roundTime.js';
|
|
6
10
|
const headers = {
|
|
7
11
|
'Cache-Control': 'no-store'
|
|
8
12
|
};
|
|
@@ -54,6 +58,97 @@ export async function readSnapshots(req, ids, { per = 'phase', decisionId, serie
|
|
|
54
58
|
numeric: true
|
|
55
59
|
}));
|
|
56
60
|
}
|
|
61
|
+
async function readAudienceSummaries(req, records, canManage) {
|
|
62
|
+
const rulesByRound = records.map((record)=>(record.targeting ?? []).flatMap((row)=>{
|
|
63
|
+
const rule = readCohortRule(row);
|
|
64
|
+
return rule ? [
|
|
65
|
+
rule
|
|
66
|
+
] : [];
|
|
67
|
+
}));
|
|
68
|
+
const rules = rulesByRound.flat();
|
|
69
|
+
if (!rules.length) return [];
|
|
70
|
+
const ids = [
|
|
71
|
+
...new Set(rules.map((rule)=>rule.experiment))
|
|
72
|
+
];
|
|
73
|
+
const sources = await req.payload.find({
|
|
74
|
+
collection: 'xp-phases',
|
|
75
|
+
req,
|
|
76
|
+
overrideAccess: false,
|
|
77
|
+
depth: 0,
|
|
78
|
+
pagination: false,
|
|
79
|
+
limit: 0,
|
|
80
|
+
where: {
|
|
81
|
+
and: [
|
|
82
|
+
{
|
|
83
|
+
experiment: {
|
|
84
|
+
in: ids
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
phaseKind: {
|
|
89
|
+
equals: 'test'
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
phase: {
|
|
94
|
+
in: [
|
|
95
|
+
...new Set(rules.flatMap((rule)=>typeof rule.phase === 'number' ? [
|
|
96
|
+
rule.phase
|
|
97
|
+
] : []))
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
select: {
|
|
104
|
+
experiment: true,
|
|
105
|
+
phase: true,
|
|
106
|
+
arms: true,
|
|
107
|
+
metricDefinitions: true
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const sourceByRound = new Map(sources.docs.map((source)=>[
|
|
111
|
+
JSON.stringify([
|
|
112
|
+
String(cohortRelationshipId(source.experiment)),
|
|
113
|
+
source.phase
|
|
114
|
+
]),
|
|
115
|
+
source
|
|
116
|
+
]));
|
|
117
|
+
const names = new Map();
|
|
118
|
+
if (await canManage()) {
|
|
119
|
+
const { docs } = await req.payload.find({
|
|
120
|
+
collection: 'xp-experiments',
|
|
121
|
+
req,
|
|
122
|
+
overrideAccess: false,
|
|
123
|
+
depth: 0,
|
|
124
|
+
pagination: false,
|
|
125
|
+
limit: 0,
|
|
126
|
+
where: {
|
|
127
|
+
id: {
|
|
128
|
+
in: ids
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
select: {
|
|
132
|
+
name: true
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
for (const doc of docs)if (typeof doc.name === 'string') names.set(String(doc.id), doc.name);
|
|
136
|
+
}
|
|
137
|
+
return rulesByRound.map((entries)=>entries.map((rule)=>{
|
|
138
|
+
const source = sourceByRound.get(JSON.stringify([
|
|
139
|
+
rule.experiment,
|
|
140
|
+
rule.phase
|
|
141
|
+
]));
|
|
142
|
+
return cohortRuleSummary(rule, {
|
|
143
|
+
experiment: names.get(rule.experiment),
|
|
144
|
+
arms: source && Object.fromEntries(source.arms.map((arm)=>[
|
|
145
|
+
arm.key,
|
|
146
|
+
arm.label
|
|
147
|
+
])),
|
|
148
|
+
goal: source?.metricDefinitions.find((goal)=>String(goal.metricId) === rule.goal?.metricId)?.name
|
|
149
|
+
});
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
57
152
|
export async function handleResults(req, { options }) {
|
|
58
153
|
const id = routeId(req);
|
|
59
154
|
if (id === undefined) return resultsError(404, 'not-found', 'Experiment not found');
|
|
@@ -77,11 +172,24 @@ export async function handleResults(req, { options }) {
|
|
|
77
172
|
sort: 'phase'
|
|
78
173
|
});
|
|
79
174
|
const records = docs.sort((a, b)=>a.phase - b.phase);
|
|
80
|
-
const
|
|
175
|
+
const cohortSummaries = await readAudienceSummaries(req, records, async ()=>{
|
|
176
|
+
try {
|
|
177
|
+
return await options.access.manage({
|
|
178
|
+
req
|
|
179
|
+
}) === true;
|
|
180
|
+
} catch {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
const phases = records.map((record, index)=>({
|
|
81
185
|
phase: record.phase,
|
|
82
186
|
phaseKind: record.phaseKind,
|
|
83
187
|
startedAt: String(record.startedAt),
|
|
84
188
|
endedAt: record.endedAt == null ? null : String(record.endedAt),
|
|
189
|
+
...publicRoundTiming(record),
|
|
190
|
+
...cohortSummaries[index]?.length ? {
|
|
191
|
+
cohortSummaries: cohortSummaries[index]
|
|
192
|
+
} : {},
|
|
85
193
|
...record.phaseKind === 'test' && record.analysis?.plannedDurationDays != null ? {
|
|
86
194
|
plannedDurationDays: record.analysis.plannedDurationDays
|
|
87
195
|
} : {},
|
|
@@ -128,9 +236,9 @@ export async function handleResults(req, { options }) {
|
|
|
128
236
|
status: metadata.status
|
|
129
237
|
},
|
|
130
238
|
phases,
|
|
131
|
-
snapshot,
|
|
239
|
+
snapshot: snapshot ? withCohortExitDefault(snapshot) : null,
|
|
132
240
|
...decision ? {
|
|
133
|
-
decisionSnapshot: decision
|
|
241
|
+
decisionSnapshot: withCohortExitDefault(decision)
|
|
134
242
|
} : {}
|
|
135
243
|
};
|
|
136
244
|
const decisionPhase = decision?.phase ?? records.filter((record)=>record.phaseKind === 'test').at(-1)?.phase;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PayloadRequest } from 'payload';
|
|
2
2
|
import type { DocId } from '../types/contracts.js';
|
|
3
|
+
export declare function collectionIDType(req: PayloadRequest, collection: string): "number" | "text";
|
|
3
4
|
/** Use the stored spelling for PostgreSQL IDs before any lock or comparison. */
|
|
4
|
-
export declare function experimentId(req: PayloadRequest, value: unknown, source?: 'route' | 'payload'): DocId | undefined;
|
|
5
|
+
export declare function experimentId(req: PayloadRequest, value: unknown, source?: 'route' | 'payload' | 'query'): DocId | undefined;
|
|
5
6
|
export declare function routeId(req: PayloadRequest): DocId | undefined;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
export function collectionIDType(req, collection) {
|
|
2
|
+
return req.payload.collections?.[collection]?.customIDType ?? req.payload.db.defaultIDType;
|
|
3
|
+
}
|
|
1
4
|
/** Use the stored spelling for PostgreSQL IDs before any lock or comparison. */ export function experimentId(req, value, source = 'route') {
|
|
2
5
|
if (typeof value !== 'string' && typeof value !== 'number') return undefined;
|
|
3
6
|
const id = String(value);
|
|
4
7
|
const customIDType = req.payload.collections?.['xp-experiments']?.customIDType;
|
|
5
|
-
const idType =
|
|
8
|
+
const idType = collectionIDType(req, 'xp-experiments');
|
|
6
9
|
if (idType !== 'number') {
|
|
7
10
|
// The Postgres adapter reports a native UUID as text. Custom text IDs are opaque.
|
|
8
11
|
const uuid = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
|
|
12
|
+
if (source === 'query' && idType === 'text' && customIDType !== 'text' && !uuid.test(id)) return undefined;
|
|
9
13
|
return customIDType !== 'text' && uuid.test(id) ? id.toLowerCase() : id;
|
|
10
14
|
}
|
|
11
15
|
// Native Payload deletes already use Number() for their ID lookup.
|
|
12
|
-
if (source
|
|
16
|
+
if (source !== 'payload' && !/^\d+$/.test(id)) return undefined;
|
|
13
17
|
const number = Number(id);
|
|
14
18
|
// Payload's Postgres serial ids are int4; larger values would reach SQL and fail with 22003.
|
|
15
19
|
return Number.isInteger(number) && number >= -2_147_483_648 && number <= 2_147_483_647 ? number : undefined;
|
|
@@ -4,6 +4,9 @@ import { loadStartInputsBatch } from '../transitions/preflightData.js';
|
|
|
4
4
|
import { readSnapshots, resultsError } from './results.js';
|
|
5
5
|
import { experimentId } from './routeId.js';
|
|
6
6
|
import { sanitizeReadinessDetail } from './sanitizeReadinessDetail.js';
|
|
7
|
+
import { currentRoundTiming } from '../db/snapshots.js';
|
|
8
|
+
import { pooledExecutor } from '../db/executor.js';
|
|
9
|
+
import { hasRoundTiming, publicRoundTiming } from '../schedule/roundTime.js';
|
|
7
10
|
/** Use the batch scan's saved drafts. As in preflight, every matching block on
|
|
8
11
|
* a page in the affected language needs content before suggesting publication. */ function draftReadySlots(placements) {
|
|
9
12
|
const location = (row)=>JSON.stringify([
|
|
@@ -52,12 +55,13 @@ export async function handleSummary(req, { options }) {
|
|
|
52
55
|
const snapshots = uniqueIds.length ? await readSnapshots(req, uniqueIds, {
|
|
53
56
|
per: 'experiment'
|
|
54
57
|
}) : [];
|
|
58
|
+
const timing = uniqueIds.length ? await currentRoundTiming(pooledExecutor(req.payload), uniqueIds) : [];
|
|
55
59
|
const response = Object.create(null);
|
|
56
60
|
for (const { key, id } of requested){
|
|
57
61
|
const snapshot = snapshots.find((row)=>String(typeof row.experiment === 'object' ? row.experiment.id : row.experiment) === String(id))?.snapshot;
|
|
58
62
|
response[key] = snapshot ? {
|
|
59
63
|
exposures: snapshot.exposures.total,
|
|
60
|
-
days: Math.max(0, (Date.parse(snapshot.window.to) - Date.parse(snapshot.window.from)) / 86_400_000),
|
|
64
|
+
days: snapshot.activeDays ?? Math.max(0, (Date.parse(snapshot.window.to) - Date.parse(snapshot.window.from)) / 86_400_000),
|
|
61
65
|
verdict: {
|
|
62
66
|
code: snapshot.verdict.code,
|
|
63
67
|
headline: snapshot.verdict.headline
|
|
@@ -80,6 +84,20 @@ export async function handleSummary(req, { options }) {
|
|
|
80
84
|
return {
|
|
81
85
|
code: item.code
|
|
82
86
|
};
|
|
87
|
+
case 'cohort-no-exposures':
|
|
88
|
+
return {
|
|
89
|
+
code: item.code
|
|
90
|
+
};
|
|
91
|
+
case 'paused-share':
|
|
92
|
+
return {
|
|
93
|
+
code: item.code,
|
|
94
|
+
pausedDays: item.pausedDays
|
|
95
|
+
};
|
|
96
|
+
case 'schedule-population':
|
|
97
|
+
return {
|
|
98
|
+
code: item.code,
|
|
99
|
+
summary: item.summary.slice(0, 512)
|
|
100
|
+
};
|
|
83
101
|
default:
|
|
84
102
|
return {
|
|
85
103
|
code: item.code,
|
|
@@ -93,6 +111,11 @@ export async function handleSummary(req, { options }) {
|
|
|
93
111
|
days: 0,
|
|
94
112
|
verdict: null
|
|
95
113
|
};
|
|
114
|
+
const current = timing.find((row)=>String(row.experiment) === String(id));
|
|
115
|
+
if (current && hasRoundTiming(current)) response[key].timing = {
|
|
116
|
+
phase: Number(current.phase),
|
|
117
|
+
...publicRoundTiming(current)
|
|
118
|
+
};
|
|
96
119
|
}
|
|
97
120
|
try {
|
|
98
121
|
if (uniqueIds.length && await options.access.manage({
|
|
@@ -5,6 +5,9 @@ export declare function handleStart<TUser extends {
|
|
|
5
5
|
} = {
|
|
6
6
|
id: string | number;
|
|
7
7
|
}>(req: PayloadRequest, ctx: EndpointContext<TUser>): Promise<Response>;
|
|
8
|
+
export declare function handleBuildCohorts<TUser extends {
|
|
9
|
+
id: string | number;
|
|
10
|
+
}>(req: PayloadRequest, ctx: EndpointContext<TUser>): Promise<Response>;
|
|
8
11
|
export declare function handleAllocate<TUser extends {
|
|
9
12
|
id: string | number;
|
|
10
13
|
} = {
|
|
@@ -20,6 +23,10 @@ export declare function handleStop<TUser extends {
|
|
|
20
23
|
} = {
|
|
21
24
|
id: string | number;
|
|
22
25
|
}>(req: PayloadRequest, _ctx: EndpointContext<TUser>): Promise<Response>;
|
|
26
|
+
export declare function handlePause(req: PayloadRequest): Promise<Response>;
|
|
27
|
+
export declare function handleResume(req: PayloadRequest): Promise<Response>;
|
|
28
|
+
export declare function handleReschedule(req: PayloadRequest): Promise<Response>;
|
|
29
|
+
export declare function handleCancelSchedule(req: PayloadRequest): Promise<Response>;
|
|
23
30
|
export declare function handleDecide<TUser extends {
|
|
24
31
|
id: string | number;
|
|
25
32
|
} = {
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import { buildCohortsNow } from '../transitions/buildCohorts.js';
|
|
1
2
|
import { XpRefusal } from '../errors.js';
|
|
2
3
|
import { start } from '../transitions/start.js';
|
|
3
4
|
import { allocate } from '../transitions/allocate.js';
|
|
4
5
|
import { addMetric } from '../transitions/addMetric.js';
|
|
5
6
|
import { stop } from '../transitions/stop.js';
|
|
7
|
+
import { pauseExperiment } from '../transitions/pause.js';
|
|
8
|
+
import { resumeExperiment } from '../transitions/resume.js';
|
|
9
|
+
import { rescheduleExperiment } from '../transitions/reschedule.js';
|
|
10
|
+
import { cancelSchedule } from '../transitions/cancelSchedule.js';
|
|
6
11
|
import { decide } from '../transitions/decide.js';
|
|
7
12
|
import { releaseHoldout } from '../transitions/releaseHoldout.js';
|
|
8
13
|
import { releasePages } from '../transitions/releasePages.js';
|
|
@@ -34,6 +39,15 @@ async function body(req) {
|
|
|
34
39
|
}
|
|
35
40
|
const only = (value, keys)=>Object.keys(value).every((key)=>keys.includes(key));
|
|
36
41
|
const validPhase = (phase)=>phase === undefined || typeof phase === 'number' && Number.isSafeInteger(phase) && phase >= 0;
|
|
42
|
+
const conflictCodes = new Set([
|
|
43
|
+
'round-changed',
|
|
44
|
+
'cohort-build-timeout',
|
|
45
|
+
'not-live',
|
|
46
|
+
'not-pausable',
|
|
47
|
+
'paused',
|
|
48
|
+
'schedule-started',
|
|
49
|
+
'occupied-in-range'
|
|
50
|
+
]);
|
|
37
51
|
async function respond(req, action) {
|
|
38
52
|
const id = routeId(req);
|
|
39
53
|
if (id === undefined) return Response.json({
|
|
@@ -64,7 +78,7 @@ async function respond(req, action) {
|
|
|
64
78
|
}
|
|
65
79
|
]
|
|
66
80
|
}, {
|
|
67
|
-
status: cause.status === 409 && cause.code
|
|
81
|
+
status: cause.status === 409 && !conflictCodes.has(cause.code) ? 422 : cause.status
|
|
68
82
|
});
|
|
69
83
|
throw cause;
|
|
70
84
|
}
|
|
@@ -80,6 +94,11 @@ export async function handleStart(req, ctx) {
|
|
|
80
94
|
options: ctx.options
|
|
81
95
|
}));
|
|
82
96
|
}
|
|
97
|
+
export async function handleBuildCohorts(req, ctx) {
|
|
98
|
+
const value = await body(req);
|
|
99
|
+
if (!value || !only(value, [])) return invalidBody();
|
|
100
|
+
return respond(req, (id)=>buildCohortsNow(req, id, ctx.options));
|
|
101
|
+
}
|
|
83
102
|
export async function handleAllocate(req, _ctx) {
|
|
84
103
|
const value = await body(req);
|
|
85
104
|
if (!value || !only(value, [
|
|
@@ -114,6 +133,36 @@ export async function handleStop(req, _ctx) {
|
|
|
114
133
|
experimentId: id
|
|
115
134
|
}));
|
|
116
135
|
}
|
|
136
|
+
export async function handlePause(req) {
|
|
137
|
+
const value = await body(req);
|
|
138
|
+
if (!value || !only(value, [
|
|
139
|
+
'reason',
|
|
140
|
+
'phase'
|
|
141
|
+
]) || !validPhase(value.phase) || value.reason !== undefined && (typeof value.reason !== 'string' || value.reason.length > 500)) return invalidBody();
|
|
142
|
+
return respond(req, (id)=>pauseExperiment(req, id, value));
|
|
143
|
+
}
|
|
144
|
+
export async function handleResume(req) {
|
|
145
|
+
const value = await body(req);
|
|
146
|
+
if (!value || !only(value, [
|
|
147
|
+
'phase'
|
|
148
|
+
]) || !validPhase(value.phase)) return invalidBody();
|
|
149
|
+
return respond(req, (id)=>resumeExperiment(req, id, value));
|
|
150
|
+
}
|
|
151
|
+
export async function handleReschedule(req) {
|
|
152
|
+
const value = await body(req);
|
|
153
|
+
if (!value || !only(value, [
|
|
154
|
+
'endAt',
|
|
155
|
+
'phase'
|
|
156
|
+
]) || !validPhase(value.phase) || value.endAt !== null && (typeof value.endAt !== 'string' || !Number.isFinite(Date.parse(value.endAt)))) return invalidBody();
|
|
157
|
+
return respond(req, (id)=>rescheduleExperiment(req, id, value));
|
|
158
|
+
}
|
|
159
|
+
export async function handleCancelSchedule(req) {
|
|
160
|
+
const value = await body(req);
|
|
161
|
+
if (!value || !only(value, [
|
|
162
|
+
'phase'
|
|
163
|
+
]) || !validPhase(value.phase)) return invalidBody();
|
|
164
|
+
return respond(req, (id)=>cancelSchedule(req, id, value));
|
|
165
|
+
}
|
|
117
166
|
export async function handleDecide(req, _ctx) {
|
|
118
167
|
const value = await body(req);
|
|
119
168
|
if (!value || !only(value, [
|
package/dist/events/rows.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ import type { ResolvedOptions } from '../types/contracts.js';
|
|
|
4
4
|
import type { Manifest } from '../types/manifest.js';
|
|
5
5
|
export declare function eventRows<TUser extends {
|
|
6
6
|
id: string | number;
|
|
7
|
-
}>(events: unknown[], manifest: Manifest, assignments: AssignmentResult, options: ResolvedOptions<TUser>, visitorId: string | undefined, userId: string | undefined, ts: string, unitAgeMs: number | 'legacy' | null, requestAttributes?: Readonly<Record<string, unknown>>, clickKeys?: ReadonlySet<string>): EventRow[];
|
|
7
|
+
}>(events: unknown[], manifest: Manifest, assignments: AssignmentResult, options: ResolvedOptions<TUser>, visitorId: string | undefined, userId: string | undefined, ts: string, unitAgeMs: number | 'legacy' | null, requestAttributes?: Readonly<Record<string, unknown>>, clickKeys?: ReadonlySet<string>, cohortRejected?: ReadonlySet<string>): EventRow[];
|
package/dist/events/rows.js
CHANGED
|
@@ -12,7 +12,7 @@ function record(value) {
|
|
|
12
12
|
return definition && typeof item === definition.type && (typeof item !== 'number' || Number.isFinite(item)) && (!definition.values || typeof item === 'string' && definition.values.includes(item));
|
|
13
13
|
}));
|
|
14
14
|
}
|
|
15
|
-
export function eventRows(events, manifest, assignments, options, visitorId, userId, ts, unitAgeMs, requestAttributes = {}, clickKeys) {
|
|
15
|
+
export function eventRows(events, manifest, assignments, options, visitorId, userId, ts, unitAgeMs, requestAttributes = {}, clickKeys, cohortRejected) {
|
|
16
16
|
const rows = new Map();
|
|
17
17
|
const telemetry = {
|
|
18
18
|
_xp: {
|
|
@@ -30,10 +30,12 @@ export function eventRows(events, manifest, assignments, options, visitorId, use
|
|
|
30
30
|
].includes(String(event.policy))) continue;
|
|
31
31
|
const experiment = manifest.experiments.find((exp)=>exp.slug === event.experiment);
|
|
32
32
|
const assigned = assignments.bySlug[event.experiment];
|
|
33
|
-
if (!experiment || !assigned
|
|
33
|
+
if (!experiment || !assigned || event.phase !== experiment.phase || event.policy !== experiment.exposurePolicy) continue;
|
|
34
|
+
const mismatch = event.arm !== assigned.arm;
|
|
35
|
+
// A cohort rejection can diagnose a variant mismatch, but cannot record an exposure.
|
|
36
|
+
if (!assigned.exposable && !(mismatch && cohortRejected?.has(event.experiment) && !assignments.staff && !assignments.bot && !assignments.preview && assignments.method.toUpperCase() !== 'HEAD')) continue;
|
|
34
37
|
const unitId = experiment.unitType === 'visitor' ? visitorId : userId;
|
|
35
38
|
if (!unitId) continue;
|
|
36
|
-
const mismatch = event.arm !== assigned.arm;
|
|
37
39
|
row = {
|
|
38
40
|
type: mismatch ? 'arm-mismatch' : 'exposure',
|
|
39
41
|
experimentId: experiment.id,
|
package/dist/exports/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export type { CohortRule, FrozenCohortRule } from '../cohorts/rule.js';
|
|
1
2
|
export { createExperimentsPlugin } from '../plugin.js';
|
|
3
|
+
export { isValidTimeZone } from '../options.js';
|
|
2
4
|
export { defineFlagPoint, defineMetricSource } from '../define.js';
|
|
3
5
|
export { contentDone } from '../contentDone.js';
|
|
4
6
|
export { createArmSelectField } from '../fields/armSelect.js';
|
package/dist/exports/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createExperimentsPlugin } from '../plugin.js';
|
|
2
|
+
export { isValidTimeZone } from '../options.js';
|
|
2
3
|
export { defineFlagPoint, defineMetricSource } from '../define.js';
|
|
3
4
|
export { contentDone } from '../contentDone.js';
|
|
4
5
|
export { createArmSelectField } from '../fields/armSelect.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { defineExperimentsProxyRuntime } from '../runtime/proxyRuntime.js';
|
|
2
2
|
export { createPostgresManifestLoader, createHttpManifestLoader } from '../runtime/loaders.js';
|
|
3
|
+
export { createPostgresCohortLookup, type CohortLookup } from '../runtime/cohortLookup.js';
|
|
3
4
|
export type { ExperimentsProxyRuntime, ExperimentsProxyRuntimeOptions, Manifest } from '../types/index.js';
|
|
4
5
|
export type { PostgresManifestLoaderOptions, HttpManifestLoaderOptions, ManifestLoader } from '../runtime/loaders.js';
|