@delmaredigital/payload-experiments 0.4.0-rc.6 → 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/BlockPanel.js +6 -4
- package/dist/admin/blocks/inject.js +1 -0
- package/dist/admin/blocks/model.d.ts +3 -2
- package/dist/admin/blocks/model.js +9 -5
- package/dist/admin/copy/blocks.d.ts +3 -2
- package/dist/admin/copy/blocks.js +8 -7
- package/dist/admin/surface/ResultsRoute.js +18 -11
- package/dist/admin/surface/TestsHome.d.ts +2 -1
- package/dist/admin/surface/TestsHome.js +131 -44
- package/dist/admin/surface/TestsSurface.js +3 -0
- package/dist/admin/surface/home.model.d.ts +2 -0
- package/dist/admin/surface/newTest/PageWizard.js +9 -2
- package/dist/admin/surface/newTest/newTest.css +1 -1
- package/dist/admin/surface/results/ResultsHeader.js +11 -6
- package/dist/admin/surface/test/TestPage.js +3 -3
- package/dist/admin/views/TestsSurfaceClient.d.ts +3 -0
- package/dist/admin/views/TestsSurfaceClient.js +11 -0
- package/dist/admin/views/buildSurfaceProps.js +10 -3
- package/dist/blocks/bindings.js +3 -2
- package/dist/blocks/formState.js +1 -1
- package/dist/blocks/placementLanguages.d.ts +7 -0
- package/dist/blocks/placementLanguages.js +27 -0
- package/dist/blocks/placementLocale.d.ts +21 -7
- package/dist/blocks/placementLocale.js +218 -67
- 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/appends.d.ts +13 -0
- package/dist/db/appends.js +49 -0
- package/dist/db/bulkPlacementRemoval.js +8 -4
- 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/contentLocale.d.ts +6 -0
- package/dist/endpoints/contentLocale.js +15 -0
- package/dist/endpoints/deleteImpact.d.ts +6 -0
- package/dist/endpoints/deleteImpact.js +207 -0
- package/dist/endpoints/events.js +103 -39
- package/dist/endpoints/index.js +9 -8
- package/dist/endpoints/pages.js +7 -3
- package/dist/endpoints/placementStatus.js +13 -5
- package/dist/endpoints/preflight.d.ts +1 -1
- package/dist/endpoints/preflight.js +17 -2
- package/dist/endpoints/results.d.ts +1 -1
- package/dist/endpoints/results.js +6 -2
- package/dist/endpoints/routeId.d.ts +2 -2
- package/dist/endpoints/routeId.js +11 -5
- package/dist/endpoints/summary.js +46 -12
- package/dist/endpoints/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/adminClient.d.ts +1 -1
- package/dist/exports/adminClient.js +1 -1
- 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 +38 -31
- package/dist/hooks/blockRemovalRule.d.ts +2 -2
- package/dist/hooks/blockRemovalRule.js +16 -14
- package/dist/hooks/hostHook.js +6 -2
- package/dist/hooks/pageGuard.d.ts +3 -0
- package/dist/hooks/pageGuard.js +37 -23
- package/dist/hooks/puckNestedTests.d.ts +8 -0
- package/dist/hooks/puckNestedTests.js +36 -0
- package/dist/lib/fetchAllDocs.d.ts +1 -1
- package/dist/lib/placementPages.d.ts +2 -1
- package/dist/lib/placementPages.js +10 -2
- package/dist/manifest/compile.d.ts +2 -1
- package/dist/manifest/compile.js +13 -6
- 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/ExperimentPicker.js +40 -37
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +8 -4
- package/dist/puck/editor/ConfigureTestDrawer.js +5 -2
- package/dist/puck/editor/ExperimentSlotEditor.js +313 -158
- package/dist/puck/editor/LeftoverVersions.d.ts +1 -1
- package/dist/puck/editor/LeftoverVersions.js +40 -43
- 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 +31 -3
- package/dist/puck/editor/VersionBuilder.js +336 -74
- package/dist/puck/editor/armWrites.js +1 -1
- package/dist/puck/editor/armsCache.js +1 -3
- package/dist/puck/editor/blockClipboard.d.ts +16 -0
- package/dist/puck/editor/blockClipboard.js +20 -0
- package/dist/puck/editor/copy.d.ts +12 -2
- package/dist/puck/editor/copy.js +13 -2
- package/dist/puck/editor/editor.chrome.css +118 -3
- package/dist/puck/editor/editor.css +131 -8
- package/dist/puck/editor/editor.model.d.ts +3 -1
- package/dist/puck/editor/editor.model.js +2 -2
- package/dist/puck/editor/localPlacements.d.ts +1 -0
- package/dist/puck/editor/localPlacements.js +12 -0
- package/dist/puck/editor/placementsCache.d.ts +22 -12
- package/dist/puck/editor/placementsCache.js +62 -49
- 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 +6 -4
- package/dist/puck/experimentSlug.d.ts +2 -0
- package/dist/puck/experimentSlug.js +3 -0
- package/dist/puck/nestedTestCopy.d.ts +8 -0
- package/dist/puck/nestedTestCopy.js +22 -0
- package/dist/puck/nestedTests.d.ts +17 -0
- package/dist/puck/nestedTests.js +30 -0
- package/dist/puck/slotConfig.d.ts +1 -1
- package/dist/puck/slotConfig.js +17 -4
- package/dist/puck/visibility.d.ts +2 -3
- package/dist/puck/visibility.js +11 -7
- 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 +45 -21
- package/dist/server/resolveExperimentBlocks.js +2 -4
- package/dist/server/resolveExperimentData.js +4 -7
- 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/PreviewLinks.js +6 -2
- 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 +11 -8
- package/dist/testSurface/api.js +27 -11
- package/dist/testSurface/contentLocaleURL.d.ts +2 -0
- package/dist/testSurface/contentLocaleURL.js +3 -0
- package/dist/testSurface/copy/actions.d.ts +1 -0
- package/dist/testSurface/copy/actions.js +1 -0
- package/dist/testSurface/copy/common.d.ts +6 -0
- package/dist/testSurface/copy/common.js +11 -5
- package/dist/testSurface/copy/languages.d.ts +12 -0
- package/dist/testSurface/copy/languages.js +8 -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 +13 -2
- package/dist/testSurface/copy/readiness.js +19 -2
- package/dist/testSurface/copy/results.d.ts +5 -2
- package/dist/testSurface/copy/results.js +5 -2
- package/dist/testSurface/copy/testPage.d.ts +40 -1
- package/dist/testSurface/copy/testPage.js +53 -1
- package/dist/testSurface/placementLabel.d.ts +8 -0
- package/dist/testSurface/placementLabel.js +24 -0
- package/dist/testSurface/placements/placementLabels.d.ts +2 -0
- package/dist/testSurface/placements/placementLabels.js +2 -1
- 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.css +1 -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 +10 -1
- package/dist/testSurface/surface/editorPlacement.d.ts +7 -2
- package/dist/testSurface/surface/editorPlacement.js +19 -1
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +4 -3
- package/dist/testSurface/surface/pageBlock/parts.js +24 -6
- 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 +116 -12
- 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 +11 -7
- 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 +19 -0
- package/dist/testSurface/surface/test/DeleteTest.js +262 -0
- 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 +97 -15
- 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 +23 -4
- package/dist/testSurface/surface/useTestDocument.js +425 -162
- package/dist/testSurface/useApi.d.ts +9 -6
- 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 +5 -1
- package/dist/transitions/checkStart.js +130 -16
- package/dist/transitions/contentFields.js +9 -5
- 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 +17 -12
- package/dist/transitions/nestedPlacementNames.d.ts +5 -0
- package/dist/transitions/nestedPlacementNames.js +32 -0
- package/dist/transitions/pageVersions.js +3 -1
- package/dist/transitions/phaseRecord.d.ts +2 -0
- package/dist/transitions/phaseRecord.js +5 -0
- package/dist/transitions/placementInteractions.d.ts +3 -3
- package/dist/transitions/placementInteractions.js +15 -11
- package/dist/transitions/placements.d.ts +28 -1
- package/dist/transitions/placements.js +223 -60
- package/dist/transitions/preflightData.d.ts +5 -3
- package/dist/transitions/preflightData.js +126 -37
- 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 +70 -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 +86 -9
- package/dist/types/endpoints.js +1 -1
- package/dist/types/runtime.d.ts +15 -9
- package/dist/types/snapshot.d.ts +2 -0
- package/dist/types/surface.d.ts +2 -0
- package/dist/ui/Button.js +2 -2
- package/dist/ui/ChipsInput.d.ts +8 -1
- package/dist/ui/ChipsInput.js +17 -4
- package/dist/ui/Inputs.d.ts +4 -3
- package/dist/ui/Inputs.js +9 -9
- package/dist/ui/SelectControl.d.ts +33 -0
- package/dist/ui/SelectControl.js +504 -0
- package/dist/ui/ui.css +13 -5
- package/package.json +3 -2
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type PayloadRequest } from 'payload';
|
|
2
|
+
import type { EndpointContext } from '../types/endpoints.js';
|
|
3
|
+
/** Advisory read only. Delete keeps its own access check, status guard and transaction. */
|
|
4
|
+
export declare function handleDeleteImpact<TUser extends {
|
|
5
|
+
id: string | number;
|
|
6
|
+
}>(req: PayloadRequest, { options }: EndpointContext<TUser>): Promise<Response>;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { contentLocale } from './contentLocale.js';
|
|
2
|
+
import { placementLanguages } from '../blocks/placementLanguages.js';
|
|
3
|
+
import { localeRequest, placementReader } from '../blocks/placementLocale.js';
|
|
4
|
+
import { Forbidden } from 'payload';
|
|
5
|
+
import { XpRefusal } from '../errors.js';
|
|
6
|
+
import { compileManifest, loadManifestInputs } from '../manifest/compile.js';
|
|
7
|
+
import { publishedBlockPlacementPages } from '../transitions/placements.js';
|
|
8
|
+
import { API_MESSAGES } from '../testSurface/copy/common.js';
|
|
9
|
+
import { routeId } from './routeId.js';
|
|
10
|
+
/** Advisory read only. Delete keeps its own access check, status guard and transaction. */ export async function handleDeleteImpact(req, { options }) {
|
|
11
|
+
const headers = {
|
|
12
|
+
'Cache-Control': 'no-store'
|
|
13
|
+
};
|
|
14
|
+
const reply = (result)=>Response.json(result, {
|
|
15
|
+
headers
|
|
16
|
+
});
|
|
17
|
+
const { locale, fallbackLocale } = contentLocale(req);
|
|
18
|
+
const metadataReq = localeRequest(req, {
|
|
19
|
+
locale: locale ?? '',
|
|
20
|
+
fallbackLocale: fallbackLocale ?? false
|
|
21
|
+
});
|
|
22
|
+
// Payload Local API setup mutates locale/fallback on its request. Keep those reads scoped.
|
|
23
|
+
req = localeRequest(req, {
|
|
24
|
+
locale: req.locale ?? '',
|
|
25
|
+
fallbackLocale: req.fallbackLocale ?? false
|
|
26
|
+
});
|
|
27
|
+
const id = routeId(req);
|
|
28
|
+
if (id === undefined) throw new XpRefusal('not-found', 'Experiment not found', undefined, 404);
|
|
29
|
+
const { docs } = await req.payload.find({
|
|
30
|
+
collection: 'xp-experiments',
|
|
31
|
+
req,
|
|
32
|
+
overrideAccess: false,
|
|
33
|
+
depth: 0,
|
|
34
|
+
limit: 1,
|
|
35
|
+
where: {
|
|
36
|
+
id: {
|
|
37
|
+
equals: id
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const experiment = docs[0];
|
|
42
|
+
if (!experiment) throw new XpRefusal('not-found', 'Experiment not found', undefined, 404);
|
|
43
|
+
if (experiment.status !== 'draft' && experiment.status !== 'archived') throw new XpRefusal('invalid-status', API_MESSAGES.deleteInvalidStatus, undefined, 409);
|
|
44
|
+
const { decision, kind } = experiment;
|
|
45
|
+
if (experiment.status === 'draft' || !decision?.winnerArm || decision.discardedAt || kind !== 'block' && kind !== 'page' || kind === 'page' && decision.pagesReleasedAt || kind === 'block' && decision.winnerArm === 'control') return reply({
|
|
46
|
+
effect: 'none'
|
|
47
|
+
});
|
|
48
|
+
// Use the live builder's complete inputs and ordering, including archived address collisions.
|
|
49
|
+
req.signal?.throwIfAborted();
|
|
50
|
+
let inputs;
|
|
51
|
+
let manifest;
|
|
52
|
+
try {
|
|
53
|
+
inputs = await loadManifestInputs(req, {
|
|
54
|
+
signal: req.signal
|
|
55
|
+
});
|
|
56
|
+
manifest = compileManifest(inputs, 0, {
|
|
57
|
+
attributeKeys: options.attributeKeys
|
|
58
|
+
});
|
|
59
|
+
} catch (cause) {
|
|
60
|
+
req.signal?.throwIfAborted();
|
|
61
|
+
throw new XpRefusal('placement-unchecked', 'The effect of deleting this test could not be determined.', undefined, 422, {
|
|
62
|
+
cause
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
req.signal?.throwIfAborted();
|
|
66
|
+
if (kind === 'page') {
|
|
67
|
+
const after = compileManifest({
|
|
68
|
+
...inputs,
|
|
69
|
+
excludeIds: [
|
|
70
|
+
id
|
|
71
|
+
]
|
|
72
|
+
}, 0, {
|
|
73
|
+
attributeKeys: options.attributeKeys
|
|
74
|
+
});
|
|
75
|
+
const routes = Object.entries(manifest.archivedPages).filter(([path, route])=>route.slug === experiment.slug && (after.archivedPages[path]?.winnerPath ?? path) !== route.winnerPath);
|
|
76
|
+
const afterPaths = Object.fromEntries(routes.flatMap(([path])=>after.archivedPages[path] ? [
|
|
77
|
+
[
|
|
78
|
+
path,
|
|
79
|
+
after.archivedPages[path].winnerPath
|
|
80
|
+
]
|
|
81
|
+
] : []));
|
|
82
|
+
return reply(routes.length ? {
|
|
83
|
+
effect: 'page',
|
|
84
|
+
winnerPath: routes[0][1].winnerPath,
|
|
85
|
+
addresses: routes.map(([path])=>path),
|
|
86
|
+
...Object.keys(afterPaths).length ? {
|
|
87
|
+
afterPaths
|
|
88
|
+
} : {}
|
|
89
|
+
} : {
|
|
90
|
+
effect: 'none'
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const winnerSlot = manifest.archivedWinners[experiment.slug];
|
|
94
|
+
if (!winnerSlot || winnerSlot === 'control') return reply({
|
|
95
|
+
effect: 'none'
|
|
96
|
+
});
|
|
97
|
+
const phase = inputs.experiments.find((test)=>String(test.id) === String(id))?.lastTestPhase;
|
|
98
|
+
const winner = phase?.arms.find((arm)=>arm.key === decision.winnerArm);
|
|
99
|
+
const control = phase?.arms.find((arm)=>arm.key === 'control');
|
|
100
|
+
if (!winner || !control) throw new XpRefusal('placement-unchecked', 'The effect of deleting this test could not be determined.', undefined, 422);
|
|
101
|
+
const affected = [];
|
|
102
|
+
const changedPages = new Set(), readablePages = new Set();
|
|
103
|
+
for await (const { collection, placements } of publishedBlockPlacementPages(req, options, experiment.slug)){
|
|
104
|
+
const changed = placements.filter((place)=>(place.editor !== 'blocks' || place.slots[winnerSlot]) && (place.slots[winnerSlot] || place.slots.control));
|
|
105
|
+
if (!changed.length) continue;
|
|
106
|
+
const byPage = new Map();
|
|
107
|
+
for (const place of changed){
|
|
108
|
+
const key = String(place.id);
|
|
109
|
+
changedPages.add(JSON.stringify([
|
|
110
|
+
collection,
|
|
111
|
+
key
|
|
112
|
+
]));
|
|
113
|
+
const page = byPage.get(key) ?? [];
|
|
114
|
+
page.push(place);
|
|
115
|
+
byPage.set(key, page);
|
|
116
|
+
}
|
|
117
|
+
req.signal?.throwIfAborted();
|
|
118
|
+
// find applies Where-scoped read access as well as a boolean refusal. Never disclose the privileged document.
|
|
119
|
+
let readable = [];
|
|
120
|
+
try {
|
|
121
|
+
const result = await req.payload.find({
|
|
122
|
+
collection,
|
|
123
|
+
req: metadataReq,
|
|
124
|
+
overrideAccess: false,
|
|
125
|
+
depth: 0,
|
|
126
|
+
draft: false,
|
|
127
|
+
pagination: false,
|
|
128
|
+
limit: 0,
|
|
129
|
+
locale,
|
|
130
|
+
fallbackLocale,
|
|
131
|
+
where: {
|
|
132
|
+
id: {
|
|
133
|
+
in: [
|
|
134
|
+
...byPage.values()
|
|
135
|
+
].map((places)=>places[0].id)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
readable = result.docs;
|
|
140
|
+
} catch (cause) {
|
|
141
|
+
if (!(cause instanceof Forbidden) && cause?.status !== 403) throw cause;
|
|
142
|
+
}
|
|
143
|
+
req.signal?.throwIfAborted();
|
|
144
|
+
const reader = placementReader(metadataReq, collection, options);
|
|
145
|
+
for (const localized of readable){
|
|
146
|
+
const doc = reader.read(localized, 'localized').doc;
|
|
147
|
+
const places = byPage.get(String(doc.id));
|
|
148
|
+
if (!places?.length) continue;
|
|
149
|
+
readablePages.add(JSON.stringify([
|
|
150
|
+
collection,
|
|
151
|
+
String(doc.id)
|
|
152
|
+
]));
|
|
153
|
+
const registration = options.pages?.collections.find((entry)=>entry.slug === collection);
|
|
154
|
+
let path = null;
|
|
155
|
+
try {
|
|
156
|
+
const value = registration?.pathOf(doc);
|
|
157
|
+
if (typeof value === 'string' && value.startsWith('/') && !value.startsWith('//') && !/[\s\x00-\x1f\x7f-\x9f\\]/.test(value) && !/[\x00-\x1f\x7f-\x9f\\]/.test(decodeURIComponent(value)) && !value.split(/[/?#]/).some((segment)=>{
|
|
158
|
+
const decoded = decodeURIComponent(segment);
|
|
159
|
+
return /^(undefined|null|\[object Object\]|\.\.?)$/i.test(decoded);
|
|
160
|
+
})) path = value;
|
|
161
|
+
} catch {}
|
|
162
|
+
const titleField = req.payload.config.collections?.find((entry)=>entry.slug === collection)?.admin?.useAsTitle;
|
|
163
|
+
const languages = placementLanguages(req, places.flatMap((place)=>place.locale ? [
|
|
164
|
+
place.locale
|
|
165
|
+
] : []));
|
|
166
|
+
const title = (titleField ? doc[titleField] : undefined) ?? doc.title ?? doc.name;
|
|
167
|
+
const version = (slot, arm)=>{
|
|
168
|
+
const values = new Map(places.map((place)=>place.slots[slot] ? [
|
|
169
|
+
arm.key,
|
|
170
|
+
arm.label
|
|
171
|
+
] : [
|
|
172
|
+
'empty',
|
|
173
|
+
'Nothing'
|
|
174
|
+
]));
|
|
175
|
+
return {
|
|
176
|
+
key: [
|
|
177
|
+
...values.keys()
|
|
178
|
+
].join(','),
|
|
179
|
+
label: [
|
|
180
|
+
...values.values()
|
|
181
|
+
].join(' / ')
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
// Page access controls metadata disclosure; a hidden layout field does not hide a readable page's visitor effect.
|
|
185
|
+
affected.push({
|
|
186
|
+
collection,
|
|
187
|
+
id: doc.id,
|
|
188
|
+
title: typeof title === 'string' && title.trim() ? title : typeof title === 'number' && Number.isFinite(title) ? String(title) : title instanceof Date && Number.isFinite(title.getTime()) ? title.toISOString() : String(doc.id),
|
|
189
|
+
path,
|
|
190
|
+
...languages,
|
|
191
|
+
before: version(winnerSlot, winner),
|
|
192
|
+
after: version('control', control)
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return reply(changedPages.size ? {
|
|
197
|
+
effect: 'block',
|
|
198
|
+
controlLabel: control.label,
|
|
199
|
+
pageCount: changedPages.size,
|
|
200
|
+
unreadablePages: [
|
|
201
|
+
...changedPages
|
|
202
|
+
].filter((key)=>!readablePages.has(key)).length,
|
|
203
|
+
placements: affected
|
|
204
|
+
} : {
|
|
205
|
+
effect: 'none'
|
|
206
|
+
});
|
|
207
|
+
}
|
package/dist/endpoints/events.js
CHANGED
|
@@ -7,90 +7,154 @@ import { pooledExecutor } from '../db/executor.js';
|
|
|
7
7
|
import { insertEvents } from '../db/events.js';
|
|
8
8
|
import { EventsBodyError, readEvents } from '../events/body.js';
|
|
9
9
|
import { isPreview } from '../events/preview.js';
|
|
10
|
-
import {
|
|
10
|
+
import { eventRequestContext, publicEventOrigin } from '../events/request.js';
|
|
11
11
|
import { eventRows } from '../events/rows.js';
|
|
12
12
|
import { assign } from '../runtime/assign.js';
|
|
13
13
|
import { isBot } from '../runtime/bot.js';
|
|
14
|
-
import {
|
|
14
|
+
import { readSignedUnit } from '../runtime/cookie.js';
|
|
15
15
|
import { requestAttributes } from '../runtime/normalisePath.js';
|
|
16
16
|
import { serverManifest } from '../server/context.js';
|
|
17
17
|
const accepted = ()=>Response.json({}, {
|
|
18
18
|
status: 202
|
|
19
19
|
});
|
|
20
|
+
const originDrops = new WeakMap();
|
|
21
|
+
function logSessionLookupError(payload, error) {
|
|
22
|
+
try {
|
|
23
|
+
payload.logger.error({
|
|
24
|
+
err: safeError(error)
|
|
25
|
+
}, 'Experiments: events session lookup failed');
|
|
26
|
+
} catch {}
|
|
27
|
+
}
|
|
28
|
+
function countOriginDrop(payload, now) {
|
|
29
|
+
const drops = originDrops.get(payload) ?? {
|
|
30
|
+
count: 0,
|
|
31
|
+
nextLogAt: 0
|
|
32
|
+
};
|
|
33
|
+
originDrops.set(payload, drops);
|
|
34
|
+
drops.count++;
|
|
35
|
+
if (now < drops.nextLogAt) return;
|
|
36
|
+
drops.nextLogAt = now + 60_000;
|
|
37
|
+
try {
|
|
38
|
+
payload.logger.warn({
|
|
39
|
+
droppedRequests: drops.count
|
|
40
|
+
}, 'Experiments: browser event requests dropped by origin check');
|
|
41
|
+
drops.count = 0;
|
|
42
|
+
} catch {}
|
|
43
|
+
}
|
|
20
44
|
export async function handleEvents(req, { options }) {
|
|
45
|
+
const receivedAt = Date.now();
|
|
21
46
|
const runtime = options.runtime, proxy = runtime.proxyRuntime;
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
code: 'unauthenticated',
|
|
27
|
-
message: 'Invalid unit cookie'
|
|
28
|
-
}
|
|
29
|
-
]
|
|
30
|
-
}, {
|
|
31
|
-
status: 401
|
|
32
|
-
});
|
|
33
|
-
let events;
|
|
34
|
-
try {
|
|
35
|
-
events = await readEvents(req.body, options.events?.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES);
|
|
36
|
-
} catch (error) {
|
|
37
|
-
if (error instanceof EventsBodyError) return Response.json({
|
|
38
|
-
errors: [
|
|
39
|
-
{
|
|
40
|
-
code: error.code,
|
|
41
|
-
message: error.message
|
|
42
|
-
}
|
|
43
|
-
]
|
|
44
|
-
}, {
|
|
45
|
-
status: error.status
|
|
46
|
-
});
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
47
|
+
const unitCookie = readSignedUnit(req.headers, proxy, receivedAt);
|
|
48
|
+
const visitorId = unitCookie?.unitId;
|
|
49
|
+
const issuedAtMs = unitCookie?.issuedAtMs;
|
|
50
|
+
const unitAgeMs = typeof issuedAtMs === 'number' ? receivedAt >= issuedAtMs ? receivedAt - issuedAtMs : null : issuedAtMs ?? null;
|
|
49
51
|
try {
|
|
50
52
|
const request = new NextRequest(req.url ?? 'https://xp.invalid/', {
|
|
51
53
|
headers: req.headers,
|
|
52
54
|
method: req.method
|
|
53
55
|
});
|
|
56
|
+
const { allowed, source } = eventRequestContext(request, options.events?.origin ?? publicEventOrigin(req.payload.config?.serverURL));
|
|
57
|
+
if (!allowed) {
|
|
58
|
+
countOriginDrop(req.payload, receivedAt);
|
|
59
|
+
return accepted();
|
|
60
|
+
}
|
|
54
61
|
// API paths bypass the proxy: re-check consent even when a stale signed cookie exists.
|
|
55
62
|
try {
|
|
56
63
|
if (proxy.cookie.consent?.(request) === false) return accepted();
|
|
57
64
|
} catch {
|
|
58
65
|
return accepted();
|
|
59
66
|
}
|
|
60
|
-
|
|
67
|
+
const limit = options.events?.rateLimit;
|
|
68
|
+
if (visitorId && limit !== false && await limit?.({
|
|
61
69
|
req,
|
|
62
|
-
unitId: visitorId
|
|
70
|
+
unitId: visitorId,
|
|
71
|
+
unitType: 'visitor'
|
|
63
72
|
}) !== true) return accepted();
|
|
73
|
+
// Payload and the host runtime verify sessions server-side. The page URL below
|
|
74
|
+
// supplies targeting attributes only, so it can never select a user identity.
|
|
75
|
+
let user = req.user ?? null;
|
|
76
|
+
let sessionUnresolved = false;
|
|
77
|
+
if (!user && runtime.getUser) {
|
|
78
|
+
try {
|
|
79
|
+
user = await runtime.getUser();
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (!visitorId) throw error;
|
|
82
|
+
sessionUnresolved = true;
|
|
83
|
+
logSessionLookupError(req.payload, error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const useProxySession = !user && !runtime.getUser;
|
|
87
|
+
let requestUnit;
|
|
88
|
+
if (useProxySession) {
|
|
89
|
+
try {
|
|
90
|
+
requestUnit = await proxy.getUnit?.(request);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (!visitorId) throw error;
|
|
93
|
+
sessionUnresolved = true;
|
|
94
|
+
logSessionLookupError(req.payload, error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const userId = user ? runtime.userIdOf(user) : requestUnit?.sessionUnknown ? undefined : requestUnit?.userId;
|
|
98
|
+
if (!visitorId) {
|
|
99
|
+
if (!userId) return Response.json({
|
|
100
|
+
errors: [
|
|
101
|
+
{
|
|
102
|
+
code: 'unauthenticated',
|
|
103
|
+
message: 'A valid visitor cookie or signed-in session is required'
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
}, {
|
|
107
|
+
status: 401
|
|
108
|
+
});
|
|
109
|
+
if (limit !== false && await limit?.({
|
|
110
|
+
req,
|
|
111
|
+
unitId: userId,
|
|
112
|
+
unitType: 'user'
|
|
113
|
+
}) !== true) return accepted();
|
|
114
|
+
}
|
|
115
|
+
const events = await readEvents(req.body, options.events?.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES);
|
|
64
116
|
const manifest = await serverManifest(proxy);
|
|
65
117
|
if (!manifest) return accepted();
|
|
66
|
-
const
|
|
67
|
-
const unit = await proxy.getUnit?.(source ?? request);
|
|
68
|
-
const user = req.user ?? null;
|
|
69
|
-
const userId = user ? runtime.userIdOf(user) : undefined;
|
|
118
|
+
const unit = source || !useProxySession ? await proxy.getUnit?.(source ?? request) : requestUnit;
|
|
70
119
|
// The beacon URL is an API route, not the page whose content was rendered.
|
|
71
120
|
// A referrer supplies page context only, never an identity or an assigned arm.
|
|
121
|
+
const serverAttributes = userId && !user ? {
|
|
122
|
+
loggedIn: true
|
|
123
|
+
} : runtime.attributesOf(user);
|
|
72
124
|
const attributes = requestAttributes({
|
|
73
125
|
...unit?.attributes,
|
|
74
|
-
...
|
|
126
|
+
...serverAttributes
|
|
75
127
|
}, source?.nextUrl.pathname);
|
|
76
|
-
const unresolvedStaff = Boolean(options.attributeKeys?.staff && unit?.sessionUnknown
|
|
128
|
+
const unresolvedStaff = Boolean(options.attributeKeys?.staff && !user && (sessionUnresolved || unit?.sessionUnknown || requestUnit?.sessionUnknown));
|
|
77
129
|
const assignments = assign(manifest, {
|
|
78
130
|
visitorId,
|
|
79
131
|
userId
|
|
80
132
|
}, attributes, {
|
|
81
133
|
now: Math.floor(Date.now() / 1000),
|
|
82
134
|
method: req.method,
|
|
83
|
-
|
|
135
|
+
sessionUnknown: sessionUnresolved,
|
|
136
|
+
staff: requestUnit?.attributes.staff === true || unit?.attributes.staff === true || attributes.staff === true,
|
|
84
137
|
bot: isBot(req.headers.get('user-agent')),
|
|
85
138
|
preview: isPreview(request)
|
|
86
139
|
});
|
|
87
140
|
if (unresolvedStaff) for (const assignment of Object.values(assignments.bySlug))assignment.exposable = false;
|
|
88
141
|
const keys = events.some((event)=>event && typeof event === 'object' && 'eventName' in event && validClickSource(event.eventName)) ? await clickKeys(req.payload) : undefined;
|
|
89
|
-
|
|
142
|
+
// Age measures arrival. Keep attribution at the time the round was validated.
|
|
143
|
+
const rows = eventRows(events, manifest, assignments, options, visitorId, userId, new Date().toISOString(), unitAgeMs, attributes, keys);
|
|
90
144
|
// §7.8 events insert / assignment lookup exception: pooled SQL and cached manifest,
|
|
91
145
|
// no Local API calls (and hence no implicit overrideAccess defaults).
|
|
92
146
|
if (rows.length) await insertEvents(pooledExecutor(req.payload), rows, (message)=>req.payload.logger.error(message));
|
|
93
147
|
} catch (error) {
|
|
148
|
+
if (error instanceof EventsBodyError) return Response.json({
|
|
149
|
+
errors: [
|
|
150
|
+
{
|
|
151
|
+
code: error.code,
|
|
152
|
+
message: error.message
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
}, {
|
|
156
|
+
status: error.status
|
|
157
|
+
});
|
|
94
158
|
try {
|
|
95
159
|
req.payload.logger.error({
|
|
96
160
|
err: safeError(error)
|
package/dist/endpoints/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { handleDeleteImpact } from './deleteImpact.js';
|
|
1
2
|
import { handleEditorSurface } from './editorSurface.js';
|
|
2
3
|
import { handleClickKeys } from './clickKeys.js';
|
|
3
4
|
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
4
5
|
import { XP_MANIFEST_KEY_HEADER } from '../constants.js';
|
|
5
6
|
import { XpNotImplemented, XpRefusal } from '../errors.js';
|
|
6
|
-
import { readUnitCookie } from '../runtime/cookie.js';
|
|
7
7
|
import { handleManifest } from './manifest.js';
|
|
8
8
|
import { handleEvents } from './events.js';
|
|
9
9
|
import { handleStart, handleAllocate, handleAddMetric, handleStop, handleDecide, handleReleaseHoldout, handleReleasePages, handleMakeContent, handleDismissContentEntry, handleRestoreContentEntry, handleArchive } from './transitions.js';
|
|
@@ -25,7 +25,7 @@ export const ROUTES = [
|
|
|
25
25
|
{
|
|
26
26
|
method: 'post',
|
|
27
27
|
path: '/xp/events',
|
|
28
|
-
access: '
|
|
28
|
+
access: 'browserEvents',
|
|
29
29
|
handler: handleEvents
|
|
30
30
|
},
|
|
31
31
|
{
|
|
@@ -94,6 +94,12 @@ export const ROUTES = [
|
|
|
94
94
|
access: 'manage',
|
|
95
95
|
handler: handleArchive
|
|
96
96
|
},
|
|
97
|
+
{
|
|
98
|
+
method: 'get',
|
|
99
|
+
path: '/xp/experiments/:id/delete-impact',
|
|
100
|
+
access: 'manage',
|
|
101
|
+
handler: handleDeleteImpact
|
|
102
|
+
},
|
|
97
103
|
{
|
|
98
104
|
method: 'get',
|
|
99
105
|
path: '/xp/experiments/:id/preflight',
|
|
@@ -215,13 +221,8 @@ export function buildEndpoints(ctx) {
|
|
|
215
221
|
if (!supplied || Buffer.byteLength(supplied) !== Buffer.byteLength(expected) || !timingSafeEqual(Buffer.from(supplied), Buffer.from(expected))) {
|
|
216
222
|
return error(401, 'unauthenticated', 'Invalid manifest key');
|
|
217
223
|
}
|
|
218
|
-
} else {
|
|
219
|
-
const visitorId = readUnitCookie(req.headers, options.runtime.proxyRuntime);
|
|
220
|
-
if (!visitorId) return error(401, 'unauthenticated', 'Invalid unit cookie');
|
|
221
|
-
handlerContext.unit = {
|
|
222
|
-
visitorId
|
|
223
|
-
};
|
|
224
224
|
}
|
|
225
|
+
// The browser events handler checks consent, origin and both possible credentials.
|
|
225
226
|
return await route.handler(req, handlerContext);
|
|
226
227
|
} catch (cause) {
|
|
227
228
|
if (cause instanceof XpRefusal) return error(cause.status, cause.code, cause.message, cause.detail);
|
package/dist/endpoints/pages.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
1
2
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
2
3
|
import { XpRefusal } from '../errors.js';
|
|
3
4
|
export async function handlePages(req, { options }) {
|
|
4
5
|
const query = new URL(req.url ?? 'http://xp.invalid').searchParams;
|
|
5
6
|
const collection = options.pages?.collections.find((entry)=>entry.slug === query.get('collection'));
|
|
6
7
|
if (!collection) throw new XpRefusal('unknown-collection', "That page type isn't set up for tests.", undefined, 422);
|
|
8
|
+
const reader = placementReader(req, collection.slug, options);
|
|
7
9
|
const path = query.get('path');
|
|
8
10
|
if (path !== null && (!path.length || path.length > 2048 || query.has('q'))) throw new XpRefusal('invalid-body', 'Enter a valid request body.', undefined, 422);
|
|
9
11
|
const page = Number(query.get('page') ?? 1);
|
|
@@ -40,7 +42,7 @@ export async function handlePages(req, { options }) {
|
|
|
40
42
|
}
|
|
41
43
|
});
|
|
42
44
|
const published = !drafts || main._status === 'published';
|
|
43
|
-
const
|
|
45
|
+
const row = published ? main : await req.payload.findByID({
|
|
44
46
|
collection: collection.slug,
|
|
45
47
|
id: main.id,
|
|
46
48
|
req,
|
|
@@ -49,7 +51,7 @@ export async function handlePages(req, { options }) {
|
|
|
49
51
|
draft: true,
|
|
50
52
|
disableErrors: true
|
|
51
53
|
});
|
|
52
|
-
if (!
|
|
54
|
+
if (!row) return Response.json({
|
|
53
55
|
docs: [],
|
|
54
56
|
hasNextPage: false
|
|
55
57
|
}, {
|
|
@@ -57,6 +59,7 @@ export async function handlePages(req, { options }) {
|
|
|
57
59
|
'Cache-Control': 'no-store'
|
|
58
60
|
}
|
|
59
61
|
});
|
|
62
|
+
const doc = reader.read(row, req.locale === 'all' ? 'all-locales' : 'localized').doc;
|
|
60
63
|
const rawPath = collection.pathOf(doc);
|
|
61
64
|
return Response.json({
|
|
62
65
|
docs: [
|
|
@@ -92,7 +95,7 @@ export async function handlePages(req, { options }) {
|
|
|
92
95
|
});
|
|
93
96
|
const docs = await Promise.all(result.docs.map(async (main)=>{
|
|
94
97
|
const published = !drafts || main._status === 'published';
|
|
95
|
-
const
|
|
98
|
+
const row = published ? main : await req.payload.findByID({
|
|
96
99
|
collection: collection.slug,
|
|
97
100
|
id: main.id,
|
|
98
101
|
req,
|
|
@@ -100,6 +103,7 @@ export async function handlePages(req, { options }) {
|
|
|
100
103
|
depth: 0,
|
|
101
104
|
draft: true
|
|
102
105
|
});
|
|
106
|
+
const doc = reader.read(row, req.locale === 'all' ? 'all-locales' : 'localized').doc;
|
|
103
107
|
const path = collection.pathOf(doc);
|
|
104
108
|
return {
|
|
105
109
|
id: main.id,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
1
2
|
import { readBody } from './readBody.js';
|
|
2
3
|
import { safeError } from '../log.js';
|
|
3
4
|
import { statusPageContent } from '../db/pageContent.js';
|
|
@@ -133,16 +134,22 @@ export async function handlePlacementStatus(req, { options }) {
|
|
|
133
134
|
name: test.name,
|
|
134
135
|
status: test.status,
|
|
135
136
|
kind: test.kind,
|
|
136
|
-
arms: round.arms.map(({ key, label, slot })=>
|
|
137
|
+
arms: round.arms.map(({ key, kind, label, slot })=>{
|
|
138
|
+
const contentSlot = test.kind === 'block' ? kind !== 'holdout' && key !== 'holdout' ? key : undefined : slot;
|
|
139
|
+
return {
|
|
137
140
|
key,
|
|
138
141
|
label,
|
|
139
|
-
...
|
|
140
|
-
slot
|
|
142
|
+
...contentSlot ? {
|
|
143
|
+
slot: contentSlot
|
|
141
144
|
} : {}
|
|
142
|
-
}
|
|
145
|
+
};
|
|
146
|
+
}),
|
|
143
147
|
...test.decision?.winnerArm ? {
|
|
144
148
|
winnerArm: test.decision.winnerArm
|
|
145
149
|
} : {},
|
|
150
|
+
...test.decision?.discardedAt ? {
|
|
151
|
+
discarded: true
|
|
152
|
+
} : {},
|
|
146
153
|
rollout: round.rollout
|
|
147
154
|
};
|
|
148
155
|
}
|
|
@@ -160,7 +167,8 @@ export async function handlePlacementStatus(req, { options }) {
|
|
|
160
167
|
});
|
|
161
168
|
const registration = options.pages?.collections.find((entry)=>entry.slug === collection);
|
|
162
169
|
const raw = registration ? await statusPageContent(req, collection, id) : null;
|
|
163
|
-
const
|
|
170
|
+
const doc = placementReader(req, collection, options).read(raw, 'all-locales').doc;
|
|
171
|
+
const rawPath = doc && registration ? registration.pathOf(doc) : null;
|
|
164
172
|
const path = rawPath;
|
|
165
173
|
const pathKey = path === null ? null : normalisePath(path);
|
|
166
174
|
const status = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type PayloadRequest } from 'payload';
|
|
2
2
|
import type { EndpointContext } from '../types/endpoints.js';
|
|
3
3
|
import type { PreflightDependencies } from '../transitions/preflightData.js';
|
|
4
4
|
export declare function handlePreflight<TUser extends {
|
|
@@ -1,10 +1,25 @@
|
|
|
1
|
+
import { contentLocale } from './contentLocale.js';
|
|
2
|
+
import { sanitizeFallbackLocale } from 'payload';
|
|
3
|
+
import { localeRequest } from '../blocks/placementLocale.js';
|
|
1
4
|
import { preflightData } from '../transitions/preflightData.js';
|
|
2
5
|
import { routeId } from './routeId.js';
|
|
3
6
|
export async function handlePreflight(req, ctx, dependencies) {
|
|
4
7
|
const id = routeId(req);
|
|
5
|
-
const
|
|
8
|
+
const placementLocale = contentLocale(req).locale ?? undefined;
|
|
9
|
+
const localization = req.payload.config.localization;
|
|
10
|
+
// The query selects readiness labels only. Host reads must match Start's default request.
|
|
11
|
+
const readinessReq = localization ? localeRequest(req, {
|
|
12
|
+
locale: localization.defaultLocale,
|
|
13
|
+
fallbackLocale: sanitizeFallbackLocale({
|
|
14
|
+
fallbackLocale: null,
|
|
15
|
+
locale: localization.defaultLocale,
|
|
16
|
+
localization
|
|
17
|
+
})
|
|
18
|
+
}) : req;
|
|
19
|
+
const result = id !== undefined ? await preflightData(readinessReq, {
|
|
6
20
|
experimentId: id,
|
|
7
|
-
options: ctx.options
|
|
21
|
+
options: ctx.options,
|
|
22
|
+
placementLocale
|
|
8
23
|
}, dependencies) : null;
|
|
9
24
|
const headers = {
|
|
10
25
|
'Cache-Control': 'no-store'
|
|
@@ -21,4 +21,4 @@ export declare function handleResults<TUser extends {
|
|
|
21
21
|
id: string | number;
|
|
22
22
|
} = {
|
|
23
23
|
id: string | number;
|
|
24
|
-
}>(req: PayloadRequest,
|
|
24
|
+
}>(req: PayloadRequest, { options }: EndpointContext<TUser>): Promise<Response>;
|
|
@@ -2,6 +2,7 @@ import { resultsMetadata, newestSnapshotIds } from '../db/snapshots.js';
|
|
|
2
2
|
import { pooledExecutor } from '../db/executor.js';
|
|
3
3
|
import { routeId } from './routeId.js';
|
|
4
4
|
import { isClickSource } from '../goals/key.js';
|
|
5
|
+
import { browserWritableMetric } from '../events/writable.js';
|
|
5
6
|
const headers = {
|
|
6
7
|
'Cache-Control': 'no-store'
|
|
7
8
|
};
|
|
@@ -53,7 +54,7 @@ export async function readSnapshots(req, ids, { per = 'phase', decisionId, serie
|
|
|
53
54
|
numeric: true
|
|
54
55
|
}));
|
|
55
56
|
}
|
|
56
|
-
export async function handleResults(req,
|
|
57
|
+
export async function handleResults(req, { options }) {
|
|
57
58
|
const id = routeId(req);
|
|
58
59
|
if (id === undefined) return resultsError(404, 'not-found', 'Experiment not found');
|
|
59
60
|
const params = new URL(req.url ?? 'http://localhost').searchParams;
|
|
@@ -86,7 +87,7 @@ export async function handleResults(req, _ctx) {
|
|
|
86
87
|
label,
|
|
87
88
|
kind
|
|
88
89
|
})),
|
|
89
|
-
metrics: record.metricDefinitions.map(({ metricId, name, kind, role, source, resolvedCap, historyUnits, capNotice })=>({
|
|
90
|
+
metrics: record.metricDefinitions.map(({ metricId, name, kind, role, source, browserWritable, resolvedCap, historyUnits, capNotice })=>({
|
|
90
91
|
metricId,
|
|
91
92
|
name,
|
|
92
93
|
kind,
|
|
@@ -94,6 +95,9 @@ export async function handleResults(req, _ctx) {
|
|
|
94
95
|
...isClickSource(source) ? {
|
|
95
96
|
clickGoal: true
|
|
96
97
|
} : {},
|
|
98
|
+
...browserWritable === true || browserWritableMetric(source, options) ? {
|
|
99
|
+
browserWritable: true
|
|
100
|
+
} : {},
|
|
97
101
|
...resolvedCap === undefined ? {} : {
|
|
98
102
|
resolvedCap
|
|
99
103
|
},
|
|
@@ -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;
|