@delmaredigital/payload-experiments 0.4.0-rc.7 → 0.4.0-rc.9
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 +12 -12
- package/dist/admin/blocks/model.js +2 -2
- package/dist/admin/copy/blocks.js +1 -1
- package/dist/admin/surface/ResultsRoute.js +17 -11
- package/dist/admin/surface/TestsHome.js +53 -20
- package/dist/admin/surface/newTest/PageWizard.js +8 -2
- package/dist/admin/surface/results/ResultsHeader.js +11 -6
- package/dist/admin/surface/test/TestPage.js +3 -3
- package/dist/blocks/formState.js +1 -1
- 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/metricsGuards.js +2 -0
- package/dist/collections/serialize.js +5 -4
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/db/adapter.d.ts +9 -1
- package/dist/db/adapter.js +77 -1
- package/dist/db/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/results.d.ts +5 -1
- package/dist/db/results.js +21 -5
- package/dist/db/snapshots.d.ts +1 -0
- package/dist/endpoints/deleteImpact.js +2 -1
- package/dist/endpoints/events.js +103 -39
- package/dist/endpoints/index.js +2 -8
- package/dist/endpoints/placementStatus.js +7 -4
- package/dist/endpoints/results.d.ts +1 -1
- package/dist/endpoints/results.js +6 -2
- package/dist/endpoints/routeId.d.ts +2 -2
- package/dist/endpoints/routeId.js +11 -5
- package/dist/endpoints/summary.js +46 -12
- package/dist/endpoints/transitions.js +37 -24
- 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/hooks/hostHook.js +6 -2
- package/dist/hooks/pageGuard.js +4 -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.js +5 -0
- 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.js +5 -4
- package/dist/puck/editor/ExperimentSlotEditor.js +182 -58
- package/dist/puck/editor/QuickTestActions.d.ts +5 -2
- package/dist/puck/editor/QuickTestActions.js +16 -4
- package/dist/puck/editor/ResultsReadout.d.ts +2 -1
- package/dist/puck/editor/ResultsReadout.js +2 -1
- package/dist/puck/editor/VersionBuilder.d.ts +13 -2
- package/dist/puck/editor/VersionBuilder.js +133 -49
- package/dist/puck/editor/armWrites.js +1 -1
- package/dist/puck/editor/armsCache.js +1 -3
- package/dist/puck/editor/copy.d.ts +4 -1
- package/dist/puck/editor/copy.js +4 -1
- package/dist/puck/editor/editor.chrome.css +1 -0
- package/dist/puck/editor/editor.css +1 -0
- package/dist/puck/editor/editor.model.d.ts +1 -0
- package/dist/puck/editor/placementsCache.d.ts +5 -1
- package/dist/puck/editor/placementsCache.js +17 -9
- package/dist/puck/editor/usePageSaveReadiness.d.ts +9 -0
- package/dist/puck/editor/usePageSaveReadiness.js +34 -0
- package/dist/puck/editor/usePlacementNotice.d.ts +2 -2
- package/dist/puck/editor/usePlacementNotice.js +5 -4
- package/dist/results/aggregate.d.ts +6 -3
- package/dist/results/aggregate.js +9 -9
- 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.js +2 -1
- package/dist/runtime/cookie.d.ts +10 -2
- package/dist/runtime/cookie.js +38 -6
- package/dist/runtime/cookieOptions.d.ts +6 -0
- package/dist/runtime/cookieOptions.js +14 -0
- package/dist/runtime/proxyRuntime.d.ts +1 -0
- package/dist/runtime/proxyRuntime.js +18 -8
- package/dist/runtime/signing.d.ts +1 -0
- package/dist/runtime/signing.js +5 -0
- package/dist/sanitizeReadinessDetail.d.ts +2 -2
- package/dist/sanitizeReadinessDetail.js +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 +52 -14
- 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/actions/DecideDialog.d.ts +4 -1
- package/dist/testSurface/actions/DecideDialog.js +32 -14
- package/dist/testSurface/actions/MakeContentResult.d.ts +4 -3
- package/dist/testSurface/actions/MakeContentResult.js +9 -1
- package/dist/testSurface/api.d.ts +5 -5
- package/dist/testSurface/api.js +21 -9
- package/dist/testSurface/copy/actions.d.ts +1 -0
- package/dist/testSurface/copy/actions.js +1 -0
- package/dist/testSurface/copy/common.d.ts +3 -1
- package/dist/testSurface/copy/common.js +4 -2
- package/dist/testSurface/copy/languages.d.ts +1 -0
- package/dist/testSurface/copy/languages.js +1 -0
- package/dist/testSurface/copy/metrics.d.ts +1 -0
- package/dist/testSurface/copy/metrics.js +1 -0
- package/dist/testSurface/copy/readiness.d.ts +12 -1
- package/dist/testSurface/copy/readiness.js +18 -1
- package/dist/testSurface/copy/results.d.ts +5 -2
- package/dist/testSurface/copy/results.js +5 -2
- package/dist/testSurface/copy/testPage.d.ts +20 -2
- package/dist/testSurface/copy/testPage.js +34 -3
- package/dist/testSurface/readPreflight.d.ts +5 -0
- package/dist/testSurface/readPreflight.js +7 -0
- package/dist/testSurface/readinessRead.d.ts +3 -0
- package/dist/testSurface/readinessRead.js +4 -0
- package/dist/testSurface/results/VerdictHero.d.ts +2 -1
- package/dist/testSurface/results/VerdictHero.js +5 -1
- package/dist/testSurface/results/results.model.d.ts +1 -1
- package/dist/testSurface/results/results.model.js +6 -2
- package/dist/testSurface/surface/contracts.d.ts +8 -1
- package/dist/testSurface/surface/editorPlacement.d.ts +2 -2
- package/dist/testSurface/surface/editorPlacement.js +1 -1
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +2 -2
- package/dist/testSurface/surface/pagePicker/PageCombobox.js +20 -6
- package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +4 -2
- package/dist/testSurface/surface/readiness/ActionDialogs.js +39 -34
- package/dist/testSurface/surface/readiness/Banner.js +23 -12
- package/dist/testSurface/surface/readiness/SaveStatus.d.ts +4 -3
- package/dist/testSurface/surface/readiness/SaveStatus.js +15 -15
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +6 -1
- package/dist/testSurface/surface/readiness/readiness.model.js +108 -11
- package/dist/testSurface/surface/readiness/useTransition.d.ts +4 -4
- package/dist/testSurface/surface/readiness/useTransition.js +12 -10
- package/dist/testSurface/surface/results/ReleasePages.d.ts +4 -2
- package/dist/testSurface/surface/results/ReleasePages.js +5 -4
- package/dist/testSurface/surface/results/ResultsBody.d.ts +4 -2
- package/dist/testSurface/surface/results/ResultsBody.js +86 -43
- package/dist/testSurface/surface/results/useResults.d.ts +7 -6
- package/dist/testSurface/surface/results/useResults.js +3 -2
- package/dist/testSurface/surface/setting/parts.js +58 -18
- package/dist/testSurface/surface/test/AdvancedSection.js +1 -0
- package/dist/testSurface/surface/test/DeleteTest.d.ts +6 -2
- package/dist/testSurface/surface/test/DeleteTest.js +145 -54
- package/dist/testSurface/surface/test/GoalSection.js +7 -3
- package/dist/testSurface/surface/test/LengthSection.js +3 -0
- package/dist/testSurface/surface/test/PageHoldout.js +4 -1
- package/dist/testSurface/surface/test/ReadinessBar.js +1 -1
- package/dist/testSurface/surface/test/TargetingSection.js +77 -12
- package/dist/testSurface/surface/test/TestSurface.js +81 -19
- package/dist/testSurface/surface/test/VersionsSection.js +56 -29
- package/dist/testSurface/surface/test/fields.d.ts +29 -4
- package/dist/testSurface/surface/test/fields.js +159 -39
- package/dist/testSurface/surface/test/pageParts.js +14 -5
- 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 +22 -4
- package/dist/testSurface/surface/useTestDocument.js +407 -160
- package/dist/testSurface/useApi.d.ts +5 -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 +1 -4
- 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 +2 -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/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 +67 -41
- package/dist/transitions/releaseHoldout.d.ts +2 -1
- package/dist/transitions/releaseHoldout.js +3 -1
- package/dist/transitions/releasePages.d.ts +2 -1
- package/dist/transitions/releasePages.js +3 -1
- package/dist/transitions/resolveCaps.d.ts +2 -4
- package/dist/transitions/start.d.ts +6 -8
- package/dist/transitions/start.js +67 -34
- package/dist/transitions/startReads.d.ts +7 -0
- package/dist/transitions/startReads.js +28 -0
- package/dist/transitions/stop.d.ts +2 -1
- package/dist/transitions/stop.js +3 -2
- package/dist/types/contracts.d.ts +6 -3
- package/dist/types/endpoints.d.ts +52 -9
- package/dist/types/runtime.d.ts +15 -9
- package/dist/types/snapshot.d.ts +2 -0
- package/dist/ui/ChipsInput.d.ts +8 -1
- package/dist/ui/ChipsInput.js +17 -4
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PayloadRequest } from 'payload';
|
|
2
2
|
import type { DocId } from '../types/contracts.js';
|
|
3
|
-
/**
|
|
4
|
-
export declare function experimentId(req: PayloadRequest, value: unknown): DocId | undefined;
|
|
3
|
+
/** 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
5
|
export declare function routeId(req: PayloadRequest): DocId | undefined;
|
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Use the stored spelling for PostgreSQL IDs before any lock or comparison. */ export function experimentId(req, value, source = 'route') {
|
|
2
2
|
if (typeof value !== 'string' && typeof value !== 'number') return undefined;
|
|
3
3
|
const id = String(value);
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
if (
|
|
4
|
+
const customIDType = req.payload.collections?.['xp-experiments']?.customIDType;
|
|
5
|
+
const idType = customIDType ?? req.payload.db.defaultIDType;
|
|
6
|
+
if (idType !== 'number') {
|
|
7
|
+
// The Postgres adapter reports a native UUID as text. Custom text IDs are opaque.
|
|
8
|
+
const uuid = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
|
|
9
|
+
return customIDType !== 'text' && uuid.test(id) ? id.toLowerCase() : id;
|
|
10
|
+
}
|
|
11
|
+
// Native Payload deletes already use Number() for their ID lookup.
|
|
12
|
+
if (source === 'route' && !/^\d+$/.test(id)) return undefined;
|
|
7
13
|
const number = Number(id);
|
|
8
14
|
// Payload's Postgres serial ids are int4; larger values would reach SQL and fail with 22003.
|
|
9
|
-
return Number.
|
|
15
|
+
return Number.isInteger(number) && number >= -2_147_483_648 && number <= 2_147_483_647 ? number : undefined;
|
|
10
16
|
}
|
|
11
17
|
export function routeId(req) {
|
|
12
18
|
return experimentId(req, req.routeParams?.id);
|
|
@@ -1,8 +1,28 @@
|
|
|
1
|
+
import { BLOCK_SLOTS } from '../blocks/model.js';
|
|
1
2
|
import { checkStart } from '../transitions/checkStart.js';
|
|
2
3
|
import { loadStartInputsBatch } from '../transitions/preflightData.js';
|
|
3
4
|
import { readSnapshots, resultsError } from './results.js';
|
|
4
5
|
import { experimentId } from './routeId.js';
|
|
5
6
|
import { sanitizeReadinessDetail } from './sanitizeReadinessDetail.js';
|
|
7
|
+
/** Use the batch scan's saved drafts. As in preflight, every matching block on
|
|
8
|
+
* a page in the affected language needs content before suggesting publication. */ function draftReadySlots(placements) {
|
|
9
|
+
const location = (row)=>JSON.stringify([
|
|
10
|
+
row.collection,
|
|
11
|
+
String(row.id),
|
|
12
|
+
row.locale
|
|
13
|
+
]);
|
|
14
|
+
const filledInDraft = new Map();
|
|
15
|
+
for (const row of placements){
|
|
16
|
+
if (row.published) continue;
|
|
17
|
+
const id = location(row);
|
|
18
|
+
const filled = filledInDraft.get(id) ?? BLOCK_SLOTS;
|
|
19
|
+
filledInDraft.set(id, filled.filter((slot)=>row.slots[slot] > 0));
|
|
20
|
+
}
|
|
21
|
+
return BLOCK_SLOTS.filter((slot)=>{
|
|
22
|
+
const affected = placements.filter((row)=>row.published && !(row.slots[slot] > 0));
|
|
23
|
+
return affected.length > 0 && affected.every((row)=>filledInDraft.get(location(row))?.includes(slot));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
6
26
|
export async function handleSummary(req, { options }) {
|
|
7
27
|
let ids;
|
|
8
28
|
try {
|
|
@@ -43,17 +63,30 @@ export async function handleSummary(req, { options }) {
|
|
|
43
63
|
headline: snapshot.verdict.headline
|
|
44
64
|
},
|
|
45
65
|
...snapshot.health ? {
|
|
46
|
-
health: snapshot.health.slice(0, 100).map((item)=>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
health: snapshot.health.slice(0, 100).map((item)=>{
|
|
67
|
+
switch(item.code){
|
|
68
|
+
case 'placement-unchecked':
|
|
69
|
+
return {
|
|
70
|
+
code: item.code,
|
|
71
|
+
detail: sanitizeReadinessDetail(item.code, item.detail)
|
|
72
|
+
};
|
|
73
|
+
case 'goal-in-some-versions':
|
|
74
|
+
return {
|
|
75
|
+
code: item.code,
|
|
76
|
+
metricId: item.metricId,
|
|
77
|
+
name: item.name.slice(0, 128)
|
|
78
|
+
};
|
|
79
|
+
case 'rapid-browser-events':
|
|
80
|
+
return {
|
|
81
|
+
code: item.code
|
|
82
|
+
};
|
|
83
|
+
default:
|
|
84
|
+
return {
|
|
85
|
+
code: item.code,
|
|
86
|
+
path: item.path.slice(0, 128)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
})
|
|
57
90
|
} : {}
|
|
58
91
|
} : {
|
|
59
92
|
exposures: 0,
|
|
@@ -90,7 +123,8 @@ export async function handleSummary(req, { options }) {
|
|
|
90
123
|
response[key].ready = !!input && checks.every((check)=>check.ok);
|
|
91
124
|
const next = checks.find((check)=>!check.ok && !check.warning);
|
|
92
125
|
if (next) {
|
|
93
|
-
const
|
|
126
|
+
const draftReady = next.code === 'empty-slot' && input?.placements ? draftReadySlots(input.placements) : undefined;
|
|
127
|
+
const detail = sanitizeReadinessDetail(next.code, next.detail, draftReady);
|
|
94
128
|
response[key].next = {
|
|
95
129
|
code: next.code,
|
|
96
130
|
...detail === undefined ? {} : {
|
|
@@ -33,6 +33,7 @@ async function body(req) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
const only = (value, keys)=>Object.keys(value).every((key)=>keys.includes(key));
|
|
36
|
+
const validPhase = (phase)=>phase === undefined || typeof phase === 'number' && Number.isSafeInteger(phase) && phase >= 0;
|
|
36
37
|
async function respond(req, action) {
|
|
37
38
|
const id = routeId(req);
|
|
38
39
|
if (id === undefined) return Response.json({
|
|
@@ -63,15 +64,18 @@ async function respond(req, action) {
|
|
|
63
64
|
}
|
|
64
65
|
]
|
|
65
66
|
}, {
|
|
66
|
-
status: cause.status === 409 ? 422 : cause.status
|
|
67
|
+
status: cause.status === 409 && cause.code !== 'round-changed' ? 422 : cause.status
|
|
67
68
|
});
|
|
68
69
|
throw cause;
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
export async function handleStart(req, ctx) {
|
|
72
73
|
const value = await body(req);
|
|
73
|
-
if (!value || !only(value, [
|
|
74
|
+
if (!value || !only(value, [
|
|
75
|
+
'phase'
|
|
76
|
+
]) || !validPhase(value.phase)) return invalidBody();
|
|
74
77
|
return respond(req, (id)=>start(req, {
|
|
78
|
+
...value,
|
|
75
79
|
experimentId: id,
|
|
76
80
|
options: ctx.options
|
|
77
81
|
}));
|
|
@@ -79,12 +83,12 @@ export async function handleStart(req, ctx) {
|
|
|
79
83
|
export async function handleAllocate(req, _ctx) {
|
|
80
84
|
const value = await body(req);
|
|
81
85
|
if (!value || !only(value, [
|
|
82
|
-
'allocation'
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
'allocation',
|
|
87
|
+
'phase'
|
|
88
|
+
]) || !validPhase(value.phase) || typeof value.allocation !== 'number' || !Number.isInteger(value.allocation) || value.allocation < 1 || value.allocation > 100) return invalidBody();
|
|
85
89
|
return respond(req, (id)=>allocate(req, {
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
...value,
|
|
91
|
+
experimentId: id
|
|
88
92
|
}));
|
|
89
93
|
}
|
|
90
94
|
export async function handleAddMetric(req, ctx) {
|
|
@@ -103,8 +107,11 @@ export async function handleAddMetric(req, ctx) {
|
|
|
103
107
|
}
|
|
104
108
|
export async function handleStop(req, _ctx) {
|
|
105
109
|
const value = await body(req);
|
|
106
|
-
if (!value || !only(value, [
|
|
110
|
+
if (!value || !only(value, [
|
|
111
|
+
'phase'
|
|
112
|
+
]) || !validPhase(value.phase)) return invalidBody();
|
|
107
113
|
return respond(req, (id)=>stop(req, {
|
|
114
|
+
...value,
|
|
108
115
|
experimentId: id
|
|
109
116
|
}));
|
|
110
117
|
}
|
|
@@ -113,35 +120,42 @@ export async function handleDecide(req, _ctx) {
|
|
|
113
120
|
if (!value || !only(value, [
|
|
114
121
|
'winnerArm',
|
|
115
122
|
'note',
|
|
116
|
-
'confirmation'
|
|
117
|
-
|
|
118
|
-
|
|
123
|
+
'confirmation',
|
|
124
|
+
'phase'
|
|
125
|
+
]) || !validPhase(value.phase) || typeof value.winnerArm !== 'string' || value.note !== undefined && typeof value.note !== 'string' || value.confirmation !== undefined && typeof value.confirmation !== 'string') return invalidBody();
|
|
119
126
|
return respond(req, (id)=>decide(req, {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
note,
|
|
123
|
-
confirmation
|
|
127
|
+
...value,
|
|
128
|
+
experimentId: id
|
|
124
129
|
}));
|
|
125
130
|
}
|
|
126
131
|
export async function handleReleaseHoldout(req, _ctx) {
|
|
127
132
|
const value = await body(req);
|
|
128
|
-
if (!value || !only(value, [
|
|
133
|
+
if (!value || !only(value, [
|
|
134
|
+
'phase'
|
|
135
|
+
]) || !validPhase(value.phase)) return invalidBody();
|
|
129
136
|
return respond(req, (id)=>releaseHoldout(req, {
|
|
137
|
+
...value,
|
|
130
138
|
experimentId: id
|
|
131
139
|
}));
|
|
132
140
|
}
|
|
133
141
|
export async function handleMakeContent(req, ctx) {
|
|
134
142
|
const value = await body(req);
|
|
135
|
-
if (!value || !only(value, [
|
|
143
|
+
if (!value || !only(value, [
|
|
144
|
+
'phase'
|
|
145
|
+
]) || !validPhase(value.phase)) return invalidBody();
|
|
136
146
|
return respond(req, (id)=>makeContent(req, {
|
|
147
|
+
...value,
|
|
137
148
|
experimentId: id,
|
|
138
149
|
options: ctx.options
|
|
139
150
|
}));
|
|
140
151
|
}
|
|
141
152
|
export async function handleReleasePages(req, _ctx) {
|
|
142
153
|
const value = await body(req);
|
|
143
|
-
if (!value || !only(value, [
|
|
154
|
+
if (!value || !only(value, [
|
|
155
|
+
'phase'
|
|
156
|
+
]) || !validPhase(value.phase)) return invalidBody();
|
|
144
157
|
return respond(req, (id)=>releasePages(req, {
|
|
158
|
+
...value,
|
|
145
159
|
experimentId: id
|
|
146
160
|
}));
|
|
147
161
|
}
|
|
@@ -175,17 +189,16 @@ export async function handleArchive(req, _ctx) {
|
|
|
175
189
|
const value = await body(req);
|
|
176
190
|
if (!value || !only(value, [
|
|
177
191
|
'mode',
|
|
178
|
-
'confirmation'
|
|
179
|
-
|
|
192
|
+
'confirmation',
|
|
193
|
+
'phase'
|
|
194
|
+
]) || !validPhase(value.phase) || ![
|
|
180
195
|
'stopped',
|
|
181
196
|
'after-content',
|
|
182
197
|
'discard',
|
|
183
198
|
'hard-coded'
|
|
184
199
|
].includes(value.mode) || value.confirmation !== undefined && typeof value.confirmation !== 'string') return invalidBody();
|
|
185
|
-
const { mode, confirmation } = value;
|
|
186
200
|
return respond(req, (id)=>archive(req, {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
confirmation
|
|
201
|
+
...value,
|
|
202
|
+
experimentId: id
|
|
190
203
|
}));
|
|
191
204
|
}
|
package/dist/errors.d.ts
CHANGED
|
@@ -17,6 +17,10 @@ export declare class XpNoTransactionError extends Error {
|
|
|
17
17
|
name: string;
|
|
18
18
|
constructor(message?: string);
|
|
19
19
|
}
|
|
20
|
+
export declare class XpStartTransactionOpen extends Error {
|
|
21
|
+
name: string;
|
|
22
|
+
constructor();
|
|
23
|
+
}
|
|
20
24
|
export declare class XpRefusal extends Error {
|
|
21
25
|
readonly code: RefusalCode;
|
|
22
26
|
readonly detail: unknown | undefined;
|
package/dist/errors.js
CHANGED
|
@@ -21,6 +21,12 @@ export class XpNoTransactionError extends Error {
|
|
|
21
21
|
super(message);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
export class XpStartTransactionOpen extends Error {
|
|
25
|
+
name = 'XpStartTransactionOpen';
|
|
26
|
+
constructor(){
|
|
27
|
+
super('Call startExperiment after your transaction commits.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
24
30
|
export class XpRefusal extends Error {
|
|
25
31
|
code;
|
|
26
32
|
detail;
|
package/dist/events/request.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server.js';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export declare function publicEventOrigin(value: string | undefined): string | undefined;
|
|
3
|
+
/** Fetch Metadata wins. For older clients, use only the deployment's configured origin. */
|
|
4
|
+
export declare function eventRequestContext(request: NextRequest, publicOrigin: string | undefined): {
|
|
5
|
+
allowed: boolean;
|
|
6
|
+
source: NextRequest | null;
|
|
7
|
+
};
|
package/dist/events/request.js
CHANGED
|
@@ -1,14 +1,41 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (!referrer) return null;
|
|
2
|
+
function webUrl(value) {
|
|
3
|
+
if (!value) return null;
|
|
5
4
|
try {
|
|
6
|
-
const url = new URL(
|
|
7
|
-
|
|
8
|
-
return new NextRequest(url, {
|
|
9
|
-
headers: request.headers
|
|
10
|
-
});
|
|
5
|
+
const url = new URL(value);
|
|
6
|
+
return (url.protocol === 'http:' || url.protocol === 'https:') && !url.username && !url.password ? url : null;
|
|
11
7
|
} catch {
|
|
12
8
|
return null;
|
|
13
9
|
}
|
|
14
10
|
}
|
|
11
|
+
export function publicEventOrigin(value) {
|
|
12
|
+
if (typeof value === 'string' && /^https?:\/\/[^/?#\\\s]+\/?$/i.test(value)) return webUrl(value)?.origin;
|
|
13
|
+
}
|
|
14
|
+
function browserRequestOrigin(request) {
|
|
15
|
+
// Next can construct the URL from its listener address behind a reverse proxy.
|
|
16
|
+
// Use the forwarded authority only to recover page context after Fetch Metadata passed.
|
|
17
|
+
const host = request.headers.get('x-forwarded-host') ?? request.headers.get('host');
|
|
18
|
+
const protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol.slice(0, -1);
|
|
19
|
+
if (host && /^[^\s,/?#@\\]+$/.test(host) && (protocol === 'http' || protocol === 'https')) {
|
|
20
|
+
const origin = publicEventOrigin(`${protocol}://${host}`);
|
|
21
|
+
if (origin) return origin;
|
|
22
|
+
}
|
|
23
|
+
return request.nextUrl.origin;
|
|
24
|
+
}
|
|
25
|
+
/** Fetch Metadata wins. For older clients, use only the deployment's configured origin. */ export function eventRequestContext(request, publicOrigin) {
|
|
26
|
+
const site = request.headers.get('sec-fetch-site');
|
|
27
|
+
const origin = request.headers.get('origin');
|
|
28
|
+
const referrer = request.headers.get('referer');
|
|
29
|
+
const page = webUrl(referrer);
|
|
30
|
+
// Same-site can include siblings. None describes direct navigation, not a page beacon.
|
|
31
|
+
const allowed = site !== null ? site === 'same-origin' : origin !== null ? origin === publicOrigin : referrer === null || page !== null && page.origin === publicOrigin;
|
|
32
|
+
const pageOrigin = site === 'same-origin' ? browserRequestOrigin(request) : publicOrigin;
|
|
33
|
+
const senderOrigin = publicEventOrigin(origin ?? undefined);
|
|
34
|
+
const source = allowed && page && page.origin === pageOrigin && (!senderOrigin || senderOrigin === pageOrigin) ? new NextRequest(page, {
|
|
35
|
+
headers: request.headers
|
|
36
|
+
}) : null;
|
|
37
|
+
return {
|
|
38
|
+
allowed,
|
|
39
|
+
source
|
|
40
|
+
};
|
|
41
|
+
}
|
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, userId: string | undefined, ts: string, 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>): EventRow[];
|
package/dist/events/rows.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isClickSource } from '../goals/key.js';
|
|
2
2
|
import { exposureDimensions } from './dimensions.js';
|
|
3
|
+
import { browserWritableEvent } from './writable.js';
|
|
4
|
+
import { USER_BROWSER_CONVERSION_PREFIX } from '../constants.js';
|
|
3
5
|
function record(value) {
|
|
4
6
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
5
7
|
}
|
|
@@ -10,8 +12,13 @@ function record(value) {
|
|
|
10
12
|
return definition && typeof item === definition.type && (typeof item !== 'number' || Number.isFinite(item)) && (!definition.values || typeof item === 'string' && definition.values.includes(item));
|
|
11
13
|
}));
|
|
12
14
|
}
|
|
13
|
-
export function eventRows(events, manifest, assignments, options, visitorId, userId, ts, requestAttributes = {}, clickKeys) {
|
|
15
|
+
export function eventRows(events, manifest, assignments, options, visitorId, userId, ts, unitAgeMs, requestAttributes = {}, clickKeys) {
|
|
14
16
|
const rows = new Map();
|
|
17
|
+
const telemetry = {
|
|
18
|
+
_xp: {
|
|
19
|
+
unitAgeMs
|
|
20
|
+
}
|
|
21
|
+
};
|
|
15
22
|
for (const event of events){
|
|
16
23
|
if (!record(event)) continue;
|
|
17
24
|
let row;
|
|
@@ -37,26 +44,35 @@ export function eventRows(events, manifest, assignments, options, visitorId, use
|
|
|
37
44
|
userId,
|
|
38
45
|
ts,
|
|
39
46
|
dimensions: mismatch ? null : exposureDimensions(requestAttributes, options.events?.dimensions),
|
|
47
|
+
attributes: telemetry,
|
|
40
48
|
// §5.5 / §11: diagnostics are separate rows, never exposure denominators or multi-arm counts.
|
|
41
49
|
dedupeKey: mismatch ? `mismatch:${experiment.id}:${experiment.phase}:${unitId}:${ts.slice(0, 10)}` : `exposure:${experiment.id}:${experiment.phase}:${event.arm}:${unitId}:${ts.slice(0, 10)}`
|
|
42
50
|
};
|
|
43
51
|
} else if (event.type === 'conversion') {
|
|
44
52
|
if (typeof event.eventName !== 'string' || typeof event.idempotencyKey !== 'string' || !event.idempotencyKey.trim() || event.value !== undefined && (typeof event.value !== 'number' || !Number.isFinite(event.value))) continue;
|
|
45
|
-
const source = options.metricSources?.find((source)=>source.id === event.eventName);
|
|
46
53
|
const click = isClickSource(event.eventName);
|
|
47
|
-
if (
|
|
54
|
+
if (!browserWritableEvent(event.eventName, options) || click && !clickKeys?.has(event.eventName.slice(6))) continue;
|
|
55
|
+
const unitId = visitorId ?? userId;
|
|
56
|
+
if (!unitId) continue;
|
|
48
57
|
row = {
|
|
49
58
|
type: 'conversion',
|
|
50
59
|
eventName: event.eventName,
|
|
51
60
|
value: 1,
|
|
52
|
-
unitId
|
|
53
|
-
unitType: 'visitor',
|
|
61
|
+
unitId,
|
|
62
|
+
unitType: visitorId ? 'visitor' : 'user',
|
|
54
63
|
userId,
|
|
55
64
|
ts,
|
|
56
65
|
dimensions: null,
|
|
57
|
-
attributes:
|
|
66
|
+
attributes: {
|
|
67
|
+
...click ? undefined : attributes(event.attributes, options.attributeKeys),
|
|
68
|
+
...telemetry
|
|
69
|
+
},
|
|
58
70
|
// §5.5: scoped by unit and event so one client can never pre-claim another's key.
|
|
59
|
-
dedupeKey: `conversion:c:${visitorId}:${event.eventName}:${event.idempotencyKey}`
|
|
71
|
+
dedupeKey: visitorId ? `conversion:c:${visitorId}:${event.eventName}:${event.idempotencyKey}` : USER_BROWSER_CONVERSION_PREFIX + JSON.stringify([
|
|
72
|
+
unitId,
|
|
73
|
+
event.eventName,
|
|
74
|
+
event.idempotencyKey
|
|
75
|
+
])
|
|
60
76
|
};
|
|
61
77
|
} else continue;
|
|
62
78
|
rows.set(row.dedupeKey, row);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MetricSource, ResolvedOptions } from '../types/contracts.js';
|
|
2
|
+
type Sources = Pick<ResolvedOptions, 'eventSources'> & {
|
|
3
|
+
metricSources?: ReadonlyArray<Pick<MetricSource, 'id' | 'kind' | 'clientWritable'>>;
|
|
4
|
+
};
|
|
5
|
+
/** Checks source configuration. Ingestion separately checks that the click key exists. */
|
|
6
|
+
export declare function browserWritableEvent(eventName: string, options: Sources): boolean;
|
|
7
|
+
/** Built-in event metrics use the event name after the `events:` prefix. */
|
|
8
|
+
export declare function browserWritableMetric(source: string | undefined, options: Sources): boolean;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { validClickSource } from '../goals/key.js';
|
|
2
|
+
/** Checks source configuration. Ingestion separately checks that the click key exists. */ export function browserWritableEvent(eventName, options) {
|
|
3
|
+
if (eventName.startsWith('click:')) return validClickSource(eventName);
|
|
4
|
+
const metric = options.metricSources?.find((source)=>source.id === eventName);
|
|
5
|
+
if (metric) return metric.clientWritable === true && metric.kind !== 'revenue';
|
|
6
|
+
return options.eventSources?.some((source)=>source.name === eventName && source.clientWritable) ?? false;
|
|
7
|
+
}
|
|
8
|
+
/** Built-in event metrics use the event name after the `events:` prefix. */ export function browserWritableMetric(source, options) {
|
|
9
|
+
if (!source) return false;
|
|
10
|
+
if (!source.startsWith('events:')) return browserWritableEvent(source, options);
|
|
11
|
+
const eventName = source.slice(7);
|
|
12
|
+
return options.eventSources?.some((event)=>event.name === eventName) === true && browserWritableEvent(eventName, options);
|
|
13
|
+
}
|
package/dist/exports/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { createExperimentsPlugin } from '../plugin.js';
|
|
|
2
2
|
export { defineFlagPoint, defineMetricSource } from '../define.js';
|
|
3
3
|
export { contentDone } from '../contentDone.js';
|
|
4
4
|
export { createArmSelectField } from '../fields/armSelect.js';
|
|
5
|
-
export type { SerializedFlagPoint, SerializedMetricSource, SerializedAttributeKeys, EditableField, Assignment, Assignments, FlagPointResult, ClientAssignments, RenderedExposure, DocId, PreviewPlacement, Attributes, ExposurePolicy, ExperimentKind, Status, UnitType, ArmKey, ArmKind, TargetingRule, Arm, ParamField, MetricSource, FlagPoint, RateLimiter, ExperimentsAccess, ExperimentsPluginOptions, ExperimentsPageCollection, ArmIssueCode, RefusalCode, ReadinessCode, ErrorEnvelope, TransitionSuccess, AllocateBody, AddMetricBody, AddMetricWarning, AddMetricResult, ClickKeysResult, PagesResult, PlacementStatusResult, PageTestStatus, DeleteImpactResult, DecideBody, ArchiveBody, MakeContentResult, DismissContentEntryBody, DismissContentEntryResult, RestoreContentEntryBody, RestoreContentEntryResult, ContentReport, PreflightResult, PreviewTokenResult, PhaseSummary, ResultsResponse, SummaryResponse, EventBody, FlagDefault, Manifest, ManifestExperiment, ArmSlot, ExperimentRef, ExperimentSlotProps, ExperimentsProxyRuntimeOptions, ExperimentsProxyRuntime, ExperimentsServerRuntimeOptions, ExperimentsServerRuntime, VerdictCode, Snapshot, MetricUnavailableReason, ContentReportReason, } from '../types/index.js';
|
|
5
|
+
export type { SerializedFlagPoint, SerializedMetricSource, SerializedAttributeKeys, EditableField, Assignment, Assignments, FlagPointResult, ClientAssignments, RenderedExposure, DocId, PreviewPlacement, Attributes, ExposurePolicy, ExperimentKind, Status, UnitType, ArmKey, ArmKind, TargetingRule, Arm, ParamField, MetricSource, FlagPoint, RateLimiter, ExperimentsAccess, ExperimentsPluginOptions, ExperimentsPageCollection, ArmIssueCode, RefusalCode, ReadinessCode, ErrorEnvelope, TransitionSuccess, StartExperimentFirstStartDetail, StartExperimentResult, StartExperimentWarning, AllocateBody, AddMetricBody, AddMetricWarning, AddMetricResult, ClickKeysResult, PagesResult, PlacementStatusResult, PageTestStatus, DeleteImpactResult, RoundBody, DecideBody, ArchiveBody, MakeContentResult, DismissContentEntryBody, DismissContentEntryResult, RestoreContentEntryBody, RestoreContentEntryResult, ContentReport, PreflightResult, PreviewTokenResult, PhaseSummary, ResultsResponse, SummaryResponse, EventBody, FlagDefault, Manifest, ManifestExperiment, ArmSlot, ExperimentRef, ExperimentSlotProps, ExperimentsProxyRuntimeOptions, ExperimentsProxyRuntime, ExperimentsServerRuntimeOptions, ExperimentsServerRuntime, VerdictCode, Snapshot, MetricUnavailableReason, ContentReportReason, } from '../types/index.js';
|
|
6
6
|
export { createExperimentBlock } from '../blocks/createExperimentBlock.js';
|
|
7
7
|
export { EXPERIMENT_BLOCK_SLUG } from '../blocks/model.js';
|
|
8
8
|
export type { HostBlock, ExperimentBlock, ExperimentBlockGroup, ResolvedHostBlock, ResolvedExperimentBlocks } from '../blocks/model.js';
|
package/dist/exports/rsc.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export { eraseUser } from '../server/eraseUser.js';
|
|
|
8
8
|
export type { MetricUnavailableReason, ContentReportReason } from '../types/reasons.js';
|
|
9
9
|
export type { PreviewPlacement } from '../types/contracts.js';
|
|
10
10
|
export { runResults } from '../server/runResults.js';
|
|
11
|
+
export { startExperiment } from '../server/startExperiment.js';
|
|
11
12
|
export { recordContentChange } from '../server/recordContentChange.js';
|
|
12
13
|
export { experimentSitemapFilter } from '../server/sitemap.js';
|
|
13
14
|
export { experimentMetadata } from '../server/metadata.js';
|
package/dist/exports/rsc.js
CHANGED
|
@@ -6,6 +6,7 @@ export { linkIdentity } from '../server/linkIdentity.js';
|
|
|
6
6
|
export { trackConversion } from '../server/trackConversion.js';
|
|
7
7
|
export { eraseUser } from '../server/eraseUser.js';
|
|
8
8
|
export { runResults } from '../server/runResults.js';
|
|
9
|
+
export { startExperiment } from '../server/startExperiment.js';
|
|
9
10
|
export { recordContentChange } from '../server/recordContentChange.js';
|
|
10
11
|
export { experimentSitemapFilter } from '../server/sitemap.js';
|
|
11
12
|
export { experimentMetadata } from '../server/metadata.js';
|
package/dist/goals/fairness.js
CHANGED
|
@@ -135,7 +135,7 @@ function blockLabels(req) {
|
|
|
135
135
|
if (!registration) continue;
|
|
136
136
|
for (const block of hostBlocks(doc[registration.field])){
|
|
137
137
|
if (block.blockType !== (registration.blockSlug ?? EXPERIMENT_BLOCK_SLUG) || block.experiment !== experiment.slug) continue;
|
|
138
|
-
for (const arm of experiment.arms.filter((a)=>a.kind !== 'holdout'))collect(slotBlocks(block, arm.
|
|
138
|
+
for (const arm of experiment.arms.filter((a)=>a.kind !== 'holdout'))collect(slotBlocks(block, arm.key), byArm.get(arm.key), '', labels);
|
|
139
139
|
}
|
|
140
140
|
} else {
|
|
141
141
|
const registration = puckCollections(options).find((c)=>c.slug === placement.collection);
|
|
@@ -149,7 +149,7 @@ function blockLabels(req) {
|
|
|
149
149
|
if (!isObject(value) || visibility.get(value)?.hidden) return;
|
|
150
150
|
const props = isObject(value.props) ? value.props : undefined;
|
|
151
151
|
if (value.type === 'ExperimentSlot' && props && puckExperimentSlug(props.experiment) === experiment.slug) {
|
|
152
|
-
for (const arm of experiment.arms.filter((a)=>a.kind !== 'holdout'))collect(props[arm.
|
|
152
|
+
for (const arm of experiment.arms.filter((a)=>a.kind !== 'holdout'))collect(props[arm.key], byArm.get(arm.key), '', labels, visibility);
|
|
153
153
|
return;
|
|
154
154
|
}
|
|
155
155
|
Object.values(value).forEach(walk);
|
package/dist/hooks/hostHook.js
CHANGED
|
@@ -4,7 +4,9 @@ import { safeError } from '../log.js';
|
|
|
4
4
|
try {
|
|
5
5
|
return await hook(args);
|
|
6
6
|
} catch (error) {
|
|
7
|
-
|
|
7
|
+
try {
|
|
8
|
+
console.error(`[payload-experiments] ${name} failed; the document was saved without it`, safeError(error));
|
|
9
|
+
} catch {}
|
|
8
10
|
return args.doc;
|
|
9
11
|
}
|
|
10
12
|
};
|
|
@@ -14,7 +16,9 @@ import { safeError } from '../log.js';
|
|
|
14
16
|
try {
|
|
15
17
|
return await hook(args);
|
|
16
18
|
} catch (error) {
|
|
17
|
-
|
|
19
|
+
try {
|
|
20
|
+
console.error(`[payload-experiments] ${name} failed; the document was saved without it`, safeError(error));
|
|
21
|
+
} catch {}
|
|
18
22
|
return args.data;
|
|
19
23
|
}
|
|
20
24
|
};
|
package/dist/hooks/pageGuard.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { refuseNewNestedTests } from './puckNestedTests.js';
|
|
2
2
|
import { hasLocalizedFields } from '../transitions/contentFields.js';
|
|
3
3
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
+
import { assertReadCommitted } from '../db/adapter.js';
|
|
4
5
|
import { previousPublishedContent, storedContent, placementWriteContent } from '../db/appends.js';
|
|
5
6
|
import { lockPlacementScope, sortLockKeys } from '../db/locks.js';
|
|
6
7
|
import { txExecutor, pooledExecutor } from '../db/executor.js';
|
|
@@ -242,6 +243,7 @@ export const pageGuardBeforeDelete = async ({ req, id, collection })=>{
|
|
|
242
243
|
if (!page) {
|
|
243
244
|
if (!affected.length) return;
|
|
244
245
|
if (await req.transactionID != null) {
|
|
246
|
+
await assertReadCommitted(req);
|
|
245
247
|
await lockPlacementScope(exec, guardExperimentIds([], [], collection.slug, [], req.context.xpHeldExperiments, new Set(), affected.map((test)=>test.id)), []);
|
|
246
248
|
tests = (await removableBlockTests(exec, affected.map((test)=>test.slug))).map((test)=>({
|
|
247
249
|
...test,
|
|
@@ -249,6 +251,7 @@ export const pageGuardBeforeDelete = async ({ req, id, collection })=>{
|
|
|
249
251
|
}));
|
|
250
252
|
} else tests = affected;
|
|
251
253
|
} else if (await req.transactionID != null) {
|
|
254
|
+
await assertReadCommitted(req);
|
|
252
255
|
await lockPlacementScope(exec, guardExperimentIds(tests, allPlacementSlugs(req, collection.slug, published, 'all-locales'), collection.slug, paths, req.context.xpHeldExperiments, taggedIds(published), affected.map((test)=>test.id)), paths);
|
|
253
256
|
tests = await placementTests(exec);
|
|
254
257
|
}
|
|
@@ -306,6 +309,7 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
306
309
|
if (await req.transactionID == null) noTransaction();
|
|
307
310
|
else {
|
|
308
311
|
try {
|
|
312
|
+
await assertReadCommitted(req);
|
|
309
313
|
await lockPlacementScope(exec, guardExperimentIds(tests, [
|
|
310
314
|
...beforeSlugs,
|
|
311
315
|
...afterSlugs
|
|
@@ -13,4 +13,4 @@ export declare class DocsResponseError extends Error {
|
|
|
13
13
|
/** Read every Payload REST page with the caller's credentials and cancellation. Transport,
|
|
14
14
|
* invalid successful responses and aborts throw; HTTP refusals retain their status/body. Keeps the first document per id; refuses
|
|
15
15
|
* incomplete lists after 1000 pages with page-limit-exceeded. */
|
|
16
|
-
export declare function fetchAllDocs<T>(url: string, options?: Pick<RequestInit, 'credentials' | 'signal'>): Promise<DocsResult<T>>;
|
|
16
|
+
export declare function fetchAllDocs<T>(url: string, options?: Pick<RequestInit, 'cache' | 'credentials' | 'signal'>): Promise<DocsResult<T>>;
|
package/dist/manifest/compile.js
CHANGED
|
@@ -137,7 +137,7 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
|
|
|
137
137
|
const testPhase = experiment.lastTestPhase ?? (phase?.phaseKind === 'test' ? phase : null);
|
|
138
138
|
if (!testPhase) throw new XpRefusal('invalid-status', `Missing last test phase for experiment ${experiment.slug}`, undefined, 409);
|
|
139
139
|
const winner = testPhase.arms.find((arm)=>arm.key === decision.winnerArm);
|
|
140
|
-
if (experiment.kind === 'block' && winner
|
|
140
|
+
if (experiment.kind === 'block' && winner && winner.kind !== 'holdout' && winner.key !== 'holdout') manifest.archivedWinners[experiment.slug] = winner.key;
|
|
141
141
|
if (experiment.kind === 'page' && winner?.pageTarget) {
|
|
142
142
|
for (const arm of testPhase.arms){
|
|
143
143
|
if (arm.pageTarget && arm.pageTarget !== winner.pageTarget) {
|
|
@@ -189,12 +189,14 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
|
|
|
189
189
|
phaseKind: rollout ? 'rollout' : 'test',
|
|
190
190
|
seed: phase.seed,
|
|
191
191
|
coverage: layer || experiment.status === 'decided' && !rollout ? 1 : phase.allocation / 100,
|
|
192
|
-
arms: (phase.phaseKind === 'rollout' ? experiment.lastTestPhase?.arms ?? phase.arms : phase.arms).map(({ key, kind, weight, slot, pageTarget, params })=>
|
|
192
|
+
arms: (phase.phaseKind === 'rollout' ? experiment.lastTestPhase?.arms ?? phase.arms : phase.arms).map(({ key, kind, weight, slot, pageTarget, params })=>{
|
|
193
|
+
const contentSlot = experiment.kind === 'block' ? kind !== 'holdout' && key !== 'holdout' ? key : undefined : slot;
|
|
194
|
+
return {
|
|
193
195
|
key,
|
|
194
196
|
kind,
|
|
195
197
|
weight,
|
|
196
|
-
...
|
|
197
|
-
slot
|
|
198
|
+
...contentSlot != null ? {
|
|
199
|
+
slot: contentSlot
|
|
198
200
|
} : {},
|
|
199
201
|
...pageTarget != null ? {
|
|
200
202
|
pageTarget
|
|
@@ -202,7 +204,8 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
|
|
|
202
204
|
...params != null ? {
|
|
203
205
|
params
|
|
204
206
|
} : {}
|
|
205
|
-
}
|
|
207
|
+
};
|
|
208
|
+
}),
|
|
206
209
|
targeting,
|
|
207
210
|
exposurePolicy: experiment.exposurePolicy,
|
|
208
211
|
deferrable: targeting.some((rule)=>rule.attribute === 'loggedIn' || rule.attribute === 'staff'),
|
package/dist/onInit.js
CHANGED
|
@@ -6,6 +6,10 @@ import { contentBlocks } from './transitions/contentFields.js';
|
|
|
6
6
|
import { validateDimensions } from './events/dimensions.js';
|
|
7
7
|
import { assertPostgresAdapter, probeTransactions } from './db/adapter.js';
|
|
8
8
|
import { hasHostAttributesOf } from './server/serverRuntime.js';
|
|
9
|
+
import { assertSigningSecrets } from './runtime/signing.js';
|
|
10
|
+
import { assertUnitRateLimit } from './runtime/proxyRuntime.js';
|
|
11
|
+
import { assertCookieOptions } from './runtime/cookieOptions.js';
|
|
12
|
+
import { publicEventOrigin } from './events/request.js';
|
|
9
13
|
// Diagnostic only: named containers are never accepted by the top-level readers.
|
|
10
14
|
function registeredPaths(fields, name, parent = []) {
|
|
11
15
|
return fields.flatMap((field)=>{
|
|
@@ -25,6 +29,13 @@ function registeredPaths(fields, name, parent = []) {
|
|
|
25
29
|
}
|
|
26
30
|
export function createOnInit(options) {
|
|
27
31
|
return async (payload)=>{
|
|
32
|
+
const rateLimit = options.events?.rateLimit;
|
|
33
|
+
if (rateLimit !== false && typeof rateLimit !== 'function') {
|
|
34
|
+
throw new Error('Experiments requires events.rateLimit to be a client-address rate limiter, or false if you rate-limit the events route upstream.');
|
|
35
|
+
}
|
|
36
|
+
assertSigningSecrets(options.runtime.proxyRuntime.secrets);
|
|
37
|
+
assertUnitRateLimit(options.runtime.proxyRuntime.rateLimitUnit);
|
|
38
|
+
assertCookieOptions(options.runtime.proxyRuntime.cookie);
|
|
28
39
|
const guarded = new Set([
|
|
29
40
|
...options.puck?.enabled ? puckCollections(options).map((c)=>c.slug) : [],
|
|
30
41
|
...(options.blocks?.collections ?? []).map((c)=>c.slug),
|
|
@@ -60,5 +71,8 @@ export function createOnInit(options) {
|
|
|
60
71
|
if (Object.hasOwn(options.attributeKeys ?? {}, 'staff') && !hasHostAttributesOf(options.runtime)) {
|
|
61
72
|
throw new Error('`staff` is declared in attributeKeys, so pass an `attributesOf` that identifies staff to defineExperimentsServerRuntime');
|
|
62
73
|
}
|
|
74
|
+
if (!options.events.origin && !publicEventOrigin(payload.config.serverURL)) {
|
|
75
|
+
payload.logger.warn('Experiments: set events.origin or Payload serverURL to your public HTTP(S) origin without a path. Until then, browser events with Origin or Referer and without Fetch Metadata are dropped.');
|
|
76
|
+
}
|
|
63
77
|
};
|
|
64
78
|
}
|