@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
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { puckExperimentSlug } from '../puck/experimentSlug.js';
|
|
1
2
|
import { walkVisiblePuck } from '../puck/visibility.js';
|
|
2
|
-
import {
|
|
3
|
+
import { puckCollections } from '../options.js';
|
|
3
4
|
import { removableBlockTests } from '../db/placements.js';
|
|
4
5
|
import { XpNoTransactionError, XpRefusal } from '../errors.js';
|
|
5
6
|
import { lastBlockPlacementCopy, hiddenBlockPlacementCopy, pendingBlockRemovalCopy, bulkBlockRemovalCopy } from '../testSurface/copy/readiness.js';
|
|
6
7
|
import { hasOtherPublishedBlockPlacement } from '../transitions/placements.js';
|
|
7
8
|
import { bulkRemoves } from '../db/bulkPlacementRemoval.js';
|
|
8
|
-
import {
|
|
9
|
-
import { placementSlugs } from '../blocks/bindings.js';
|
|
9
|
+
import { placementReader, removedPlacementViews, placementDocumentKey, mergedPlacementLocales } from '../blocks/placementLocale.js';
|
|
10
10
|
export function releaseRemovalClaim(req, collection, id, ownKeys) {
|
|
11
11
|
const claims = req.context.xpPlacementRemovals;
|
|
12
12
|
for (const [test, documents] of claims?.tests ?? [])for (const key of documents){
|
|
@@ -40,7 +40,7 @@ export function releaseRestoredRemovalClaims(req, collection, doc, test) {
|
|
|
40
40
|
const [slug, id, view] = JSON.parse(key);
|
|
41
41
|
if (slug !== collection || id !== String(doc.id)) continue;
|
|
42
42
|
const marker = `${test.id}:${key}`;
|
|
43
|
-
if (!
|
|
43
|
+
if (!placementReader(req, collection).read(doc, 'all-locales', view).slugs.includes(test.slug)) claims.absent.add(marker);
|
|
44
44
|
else if (claims.absent.has(marker) && (claims.counts?.get(String(test.id))?.get(key) ?? 1) === 1) {
|
|
45
45
|
claims.tests.get(String(test.id)).delete(`${key}`);
|
|
46
46
|
claims.counts?.get(String(test.id))?.delete(`${key}`);
|
|
@@ -51,26 +51,28 @@ export function releaseRestoredRemovalClaims(req, collection, doc, test) {
|
|
|
51
51
|
// Separate removal-rule entry points let tests observe its IO independently
|
|
52
52
|
// of the earlier page-path and publish guards.
|
|
53
53
|
export const blockRemovalRule = {
|
|
54
|
-
async prepare (req, collection, before, after, removingPage, exec, tests) {
|
|
55
|
-
const views = removedPlacementViews(req, collection, before, after, removingPage);
|
|
54
|
+
async prepare (req, collection, before, after, removingPage, exec, tests, input = 'localized') {
|
|
55
|
+
const views = removedPlacementViews(req, collection, before, after, removingPage, input);
|
|
56
56
|
const affected = views.size ? await blockRemovalRule.discover(exec, [
|
|
57
57
|
...views.keys()
|
|
58
58
|
], tests) : [];
|
|
59
59
|
const hidden = new Set();
|
|
60
60
|
const options = req.payload.config.custom.xp;
|
|
61
61
|
const registration = puckCollections(options).find((entry)=>entry.slug === collection);
|
|
62
|
-
const rawAfter = mergedPlacementLocales(req, collection, before, after);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
const rawAfter = input === 'all-locales' ? after : mergedPlacementLocales(req, collection, before, after);
|
|
63
|
+
const reader = placementReader(req, collection);
|
|
64
|
+
if (views.size && !removingPage && registration) {
|
|
65
|
+
for (const view of reader.views){
|
|
66
|
+
const previous = reader.read(before, 'all-locales', view);
|
|
67
|
+
const next = reader.read(rawAfter, 'all-locales', view);
|
|
68
|
+
if (next.editor !== 'puck') continue;
|
|
66
69
|
const visibleBefore = new Set();
|
|
67
|
-
walkVisiblePuck(
|
|
70
|
+
walkVisiblePuck(previous.doc?.[registration.field], (block, visibility)=>{
|
|
68
71
|
if (!visibility.hidden && block.type === 'ExperimentSlot') visibleBefore.add(String(block.props.id));
|
|
69
72
|
});
|
|
70
|
-
walkVisiblePuck(
|
|
73
|
+
walkVisiblePuck(next.doc?.[registration.field], (block, visibility)=>{
|
|
71
74
|
if (!visibility.hidden || block.type !== 'ExperimentSlot' || !visibleBefore.has(String(block.props.id))) return;
|
|
72
|
-
const
|
|
73
|
-
const slug = typeof ref === 'string' ? ref : ref && typeof ref === 'object' && 'slug' in ref ? ref.slug : undefined;
|
|
75
|
+
const slug = puckExperimentSlug(block.props.experiment);
|
|
74
76
|
if (typeof slug === 'string') hidden.add(slug);
|
|
75
77
|
});
|
|
76
78
|
}
|
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,11 +1,14 @@
|
|
|
1
|
+
import { refuseNewNestedTests } from './puckNestedTests.js';
|
|
2
|
+
import { hasLocalizedFields } from '../transitions/contentFields.js';
|
|
1
3
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import {
|
|
4
|
+
import { assertReadCommitted } from '../db/adapter.js';
|
|
5
|
+
import { previousPublishedContent, storedContent, placementWriteContent } from '../db/appends.js';
|
|
3
6
|
import { lockPlacementScope, sortLockKeys } from '../db/locks.js';
|
|
4
7
|
import { txExecutor, pooledExecutor } from '../db/executor.js';
|
|
5
8
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
6
9
|
import { XpNoTransactionError, XpRefusal } from '../errors.js';
|
|
7
10
|
import { placementGuardCopy, pageGuardCopy, READINESS_COPY } from '../testSurface/copy/readiness.js';
|
|
8
|
-
import {
|
|
11
|
+
import { allPlacementSlugs, mergedPlacementLocales, placementDocumentPaths } from '../blocks/placementLocale.js';
|
|
9
12
|
import { isObject } from '../blocks/model.js';
|
|
10
13
|
import { placementTests, removableBlockTests, appendPlacementDoc } from '../db/placements.js';
|
|
11
14
|
import { isPageBusy } from '../db/pageBusy.js';
|
|
@@ -86,6 +89,9 @@ export const pageGuardBeforeOperation = ({ args, operation })=>{
|
|
|
86
89
|
request: req,
|
|
87
90
|
draft: call.draft === true,
|
|
88
91
|
restore: operation === 'restoreVersion',
|
|
92
|
+
versionId: operation === 'restoreVersion' ? call.id : undefined,
|
|
93
|
+
isBulk,
|
|
94
|
+
publishSpecificLocale: call.publishSpecificLocale,
|
|
89
95
|
bulk,
|
|
90
96
|
pending: false
|
|
91
97
|
});
|
|
@@ -165,14 +171,9 @@ function registration(req, slug) {
|
|
|
165
171
|
return optionsOf(req).pages?.collections.find((entry)=>entry.slug === slug);
|
|
166
172
|
}
|
|
167
173
|
const active = (test)=>test.status === 'running' || test.status === 'decided';
|
|
168
|
-
const
|
|
174
|
+
const documentPathsOf = (req, collection, rows)=>{
|
|
169
175
|
const page = registration(req, collection);
|
|
170
|
-
return page ?
|
|
171
|
-
const path = row ? page.pathOf(row) : null;
|
|
172
|
-
return path === null ? [] : [
|
|
173
|
-
normalisePath(path)
|
|
174
|
-
];
|
|
175
|
-
})) : [];
|
|
176
|
+
return page ? placementDocumentPaths(req, collection, rows, 'all-locales', (doc)=>page.pathOf(doc)) : [];
|
|
176
177
|
};
|
|
177
178
|
/** The later audit also recognises arm-select tags; include those ids in its lock superset. */ function taggedIds(value, ids = new Set()) {
|
|
178
179
|
if (Array.isArray(value)) value.forEach((v)=>taggedIds(v, ids));
|
|
@@ -233,15 +234,16 @@ export const pageGuardBeforeDelete = async ({ req, id, collection })=>{
|
|
|
233
234
|
// Keep the earlier page guard's baseline read and every refusal intact.
|
|
234
235
|
const published = page ? await previousPublishedContent(req, collection.slug, id) : await storedContent(req, collection.slug, id);
|
|
235
236
|
if (!published || published._status === 'draft') return;
|
|
236
|
-
const paths =
|
|
237
|
+
const paths = sortLockKeys(documentPathsOf(req, collection.slug, [
|
|
237
238
|
published
|
|
238
|
-
]);
|
|
239
|
+
]).map(normalisePath));
|
|
239
240
|
const exec = await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload);
|
|
240
241
|
let tests = page ? await placementTests(exec) : undefined;
|
|
241
242
|
const { views, affected } = await blockRemovalRule.prepare(req, collection.slug, collection.trash && published.deletedAt != null ? undefined : published, {}, true, exec, tests);
|
|
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,7 +251,8 @@ export const pageGuardBeforeDelete = async ({ req, id, collection })=>{
|
|
|
249
251
|
}));
|
|
250
252
|
} else tests = affected;
|
|
251
253
|
} else if (await req.transactionID != null) {
|
|
252
|
-
await
|
|
254
|
+
await assertReadCommitted(req);
|
|
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
|
}
|
|
255
258
|
for (const path of paths)protect(tests.filter((t)=>!t.pageCollection || t.pageCollection === collection.slug), path);
|
|
@@ -272,14 +275,25 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
272
275
|
const options = optionsOf(req);
|
|
273
276
|
try {
|
|
274
277
|
const published = operation === 'create' ? undefined : await previousPublishedContent(req, collection.slug, originalDoc.id);
|
|
278
|
+
// Preserve the localization-off path and its IO. Localized writes mirror
|
|
279
|
+
// the base Payload uses for this operation's unselected languages.
|
|
280
|
+
const stored = operation === 'create' || !hasLocalizedFields(req.payload.config.collections?.find((entry)=>entry.slug === collection.slug)?.fields ?? [], req.payload.config) ? published : await placementWriteContent(req, collection.slug, originalDoc.id, published ?? await storedContent(req, collection.slug, originalDoc.id), {
|
|
281
|
+
versionId: call?.versionId,
|
|
282
|
+
bulk: call?.isBulk,
|
|
283
|
+
draft: call?.draft,
|
|
284
|
+
publishSpecificLocale: call?.publishSpecificLocale,
|
|
285
|
+
trashing: Boolean(collection.trash && data.deletedAt != null)
|
|
286
|
+
});
|
|
275
287
|
const before = published?._status === 'draft' ? undefined : published;
|
|
276
|
-
const beforeSlugs =
|
|
277
|
-
const
|
|
278
|
-
const
|
|
288
|
+
const beforeSlugs = allPlacementSlugs(req, collection.slug, before, 'all-locales');
|
|
289
|
+
const rawAfter = mergedPlacementLocales(req, collection.slug, stored, after);
|
|
290
|
+
const afterSlugs = allPlacementSlugs(req, collection.slug, rawAfter, 'all-locales');
|
|
291
|
+
const oldPaths = documentPathsOf(req, collection.slug, [
|
|
279
292
|
before
|
|
280
|
-
]),
|
|
281
|
-
|
|
293
|
+
]), newPaths = documentPathsOf(req, collection.slug, [
|
|
294
|
+
rawAfter
|
|
282
295
|
]);
|
|
296
|
+
const beforePaths = sortLockKeys(oldPaths.map(normalisePath)), afterPaths = sortLockKeys(newPaths.map(normalisePath));
|
|
283
297
|
const paths = sortLockKeys([
|
|
284
298
|
...beforePaths,
|
|
285
299
|
...afterPaths
|
|
@@ -287,7 +301,7 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
287
301
|
const exec = await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload);
|
|
288
302
|
let tests = await placementTests(exec);
|
|
289
303
|
const trashing = Boolean(collection.trash && after.deletedAt != null);
|
|
290
|
-
const { views, affected, hidden } = await blockRemovalRule.prepare(req, collection.slug, collection.trash && before?.deletedAt != null ? undefined : before,
|
|
304
|
+
const { views, affected, hidden } = await blockRemovalRule.prepare(req, collection.slug, collection.trash && before?.deletedAt != null ? undefined : before, rawAfter, trashing || drafts && after._status !== 'published', exec, tests, 'all-locales');
|
|
291
305
|
const publishes = !drafts || after._status === 'published';
|
|
292
306
|
const noTransaction = ()=>{
|
|
293
307
|
if (publishes && tests.some((t)=>t.kind === 'block' && active(t) && afterSlugs.includes(t.slug))) throw new XpNoTransactionError('Save this page with transactions on.');
|
|
@@ -295,12 +309,13 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
295
309
|
if (await req.transactionID == null) noTransaction();
|
|
296
310
|
else {
|
|
297
311
|
try {
|
|
312
|
+
await assertReadCommitted(req);
|
|
298
313
|
await lockPlacementScope(exec, guardExperimentIds(tests, [
|
|
299
314
|
...beforeSlugs,
|
|
300
315
|
...afterSlugs
|
|
301
316
|
], collection.slug, paths, req.context.xpHeldExperiments, taggedIds([
|
|
302
317
|
before,
|
|
303
|
-
|
|
318
|
+
rawAfter
|
|
304
319
|
]), affected.map((test)=>test.id)), paths);
|
|
305
320
|
tests = await placementTests(exec);
|
|
306
321
|
} catch (error) {
|
|
@@ -312,12 +327,11 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
312
327
|
}
|
|
313
328
|
}
|
|
314
329
|
if (operation === 'update' && before) {
|
|
315
|
-
const page = registration(req, collection.slug);
|
|
316
|
-
const old = page?.pathOf(before);
|
|
317
330
|
const unpublishing = drafts && data._status === 'draft';
|
|
318
331
|
const trashing = collection.trash && data.deletedAt != null && !originalDoc.deletedAt;
|
|
319
|
-
|
|
332
|
+
for (const old of oldPaths)if (unpublishing || trashing || !newPaths.includes(old)) protect(tests.filter((t)=>!t.pageCollection || t.pageCollection === collection.slug), normalisePath(old));
|
|
320
333
|
}
|
|
334
|
+
if (publishes) refuseNewNestedTests(req, collection.slug, before, rawAfter, tests);
|
|
321
335
|
if (publishes) refuseInteraction(tests, beforeSlugs, afterSlugs, beforePaths, afterPaths, collection.slug);
|
|
322
336
|
if (affected.length) await blockRemovalRule.check(req, tests, affected, collection.slug, originalDoc.id, trashing || drafts && after._status !== 'published', views, call?.bulk, hidden);
|
|
323
337
|
return data;
|
|
@@ -334,7 +348,7 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
334
348
|
try {
|
|
335
349
|
const stored = await storedContent(req, collection.slug, doc.id);
|
|
336
350
|
if (!stored) throw new Error('The saved placement row was not found.');
|
|
337
|
-
const slugs =
|
|
351
|
+
const slugs = allPlacementSlugs(req, collection.slug, stored, 'all-locales');
|
|
338
352
|
// A later publish in this transaction can restore an earlier removal. Only
|
|
339
353
|
// clear its claim once the stored published row actually contains the block.
|
|
340
354
|
const claims = req.context.xpPlacementRemovals;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type PayloadRequest } from 'payload';
|
|
2
|
+
/** Called by the page guard with its published baseline and merged write, only on publish.
|
|
3
|
+
* Puck's public reducer bypasses slot disallow; this server check covers that path.
|
|
4
|
+
*/
|
|
5
|
+
export declare function refuseNewNestedTests(req: PayloadRequest, collection: string, before: Record<string, unknown> | undefined, after: Record<string, unknown>, tests: readonly {
|
|
6
|
+
slug: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}[]): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ValidationError } from 'payload';
|
|
2
|
+
import { placementReader } from '../blocks/placementLocale.js';
|
|
3
|
+
import { puckCollections } from '../options.js';
|
|
4
|
+
import { nestedTests, nestedTestKey, nestedTestLabel, nestedTestSlug, nearestOuterTest } from '../puck/nestedTests.js';
|
|
5
|
+
import { nestedTestCopy } from '../puck/nestedTestCopy.js';
|
|
6
|
+
/** Called by the page guard with its published baseline and merged write, only on publish.
|
|
7
|
+
* Puck's public reducer bypasses slot disallow; this server check covers that path.
|
|
8
|
+
*/ export function refuseNewNestedTests(req, collection, before, after, tests) {
|
|
9
|
+
const options = req.payload.config.custom?.xp;
|
|
10
|
+
const registration = puckCollections(options).find((entry)=>entry.slug === collection);
|
|
11
|
+
if (!registration) return;
|
|
12
|
+
const reader = placementReader(req, collection, options);
|
|
13
|
+
for (const view of reader.views){
|
|
14
|
+
const read = (doc)=>{
|
|
15
|
+
const content = reader.read(doc, 'all-locales', view);
|
|
16
|
+
return content.editor === 'puck' ? nestedTests(content.doc?.[registration.field]) : [];
|
|
17
|
+
};
|
|
18
|
+
const existing = new Set(read(before).map(nestedTestKey));
|
|
19
|
+
const additions = read(after).filter((pair)=>!existing.has(nestedTestKey(pair)));
|
|
20
|
+
const added = additions[0];
|
|
21
|
+
if (!added) continue;
|
|
22
|
+
const name = (block)=>tests.find((test)=>test.slug === nestedTestSlug(block))?.name ?? nestedTestLabel(block);
|
|
23
|
+
const message = nestedTestCopy.publish(name(nearestOuterTest(additions, added.inner.props.id)), name(added.inner));
|
|
24
|
+
const error = new ValidationError({
|
|
25
|
+
collection,
|
|
26
|
+
errors: [
|
|
27
|
+
{
|
|
28
|
+
path: registration.field,
|
|
29
|
+
message
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
error.message = message;
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -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>>;
|
|
@@ -4,6 +4,7 @@ export type PreviewPage = Placement & {
|
|
|
4
4
|
key: string;
|
|
5
5
|
slotCount: number;
|
|
6
6
|
};
|
|
7
|
-
/**
|
|
7
|
+
/** Localized responses are already grouped by the server. Legacy single-language
|
|
8
|
+
* responses contain occurrences; preserve their page grouping and version counts. */
|
|
8
9
|
export declare function placementPages(placements: readonly Placement[], flagPoint?: string): PreviewPage[];
|
|
9
10
|
export {};
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Localized responses are already grouped by the server. Legacy single-language
|
|
2
|
+
* responses contain occurrences; preserve their page grouping and version counts. */ export function placementPages(placements, flagPoint) {
|
|
3
|
+
if (placements.some((placement)=>placement.allLocales || placement.locales?.length)) {
|
|
4
|
+
return placements.map((placement, index)=>({
|
|
5
|
+
...placement,
|
|
6
|
+
key: String(index),
|
|
7
|
+
slotCount: placement.slotCount ?? 1
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
2
10
|
const pages = new Map();
|
|
3
11
|
for (const [index, placement] of placements.entries()){
|
|
4
12
|
const key = `${placement.collection}\u0000${String(placement.id)}${placement.collection === flagPoint ? `\u0000${index}` : ''}`;
|
|
@@ -15,7 +23,7 @@
|
|
|
15
23
|
page: {
|
|
16
24
|
...placement,
|
|
17
25
|
key,
|
|
18
|
-
slotCount: 1
|
|
26
|
+
slotCount: placement.slotCount ?? 1
|
|
19
27
|
},
|
|
20
28
|
versions: new Map([
|
|
21
29
|
[
|
|
@@ -46,9 +46,10 @@ export interface ManifestInputs {
|
|
|
46
46
|
excludeIds?: DocId[];
|
|
47
47
|
pruneFlagDefaultIds?: DocId[];
|
|
48
48
|
}
|
|
49
|
-
export declare function loadManifestInputs(req: PayloadRequest, { excludeIds, pruneFlagDefaultIds }?: {
|
|
49
|
+
export declare function loadManifestInputs(req: PayloadRequest, { excludeIds, pruneFlagDefaultIds, signal }?: {
|
|
50
50
|
excludeIds?: DocId[];
|
|
51
51
|
pruneFlagDefaultIds?: DocId[];
|
|
52
|
+
signal?: AbortSignal;
|
|
52
53
|
}): Promise<ManifestInputs>;
|
|
53
54
|
/** Pure compiler. Assignment config comes exclusively from the frozen phase. */
|
|
54
55
|
/**
|
package/dist/manifest/compile.js
CHANGED
|
@@ -2,7 +2,8 @@ import { txExecutor } from '../db/executor.js';
|
|
|
2
2
|
import { bumpRevision, writeManifest } from '../db/state.js';
|
|
3
3
|
import { XpRefusal } from '../errors.js';
|
|
4
4
|
import { xpOptionsFromReq } from '../options/fromReq.js';
|
|
5
|
-
export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaultIds = [] } = {}) {
|
|
5
|
+
export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaultIds = [], signal } = {}) {
|
|
6
|
+
signal?.throwIfAborted();
|
|
6
7
|
// §7.8 manifest reads: transitions compile all live/archived routing state.
|
|
7
8
|
const result = await req.payload.find({
|
|
8
9
|
collection: 'xp-experiments',
|
|
@@ -20,6 +21,7 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
});
|
|
24
|
+
signal?.throwIfAborted();
|
|
23
25
|
const excluded = new Set(excludeIds.map(String));
|
|
24
26
|
const experiments = [];
|
|
25
27
|
for (const doc of result.docs){
|
|
@@ -44,6 +46,7 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
|
|
|
44
46
|
},
|
|
45
47
|
sort: '-phase'
|
|
46
48
|
});
|
|
49
|
+
signal?.throwIfAborted();
|
|
47
50
|
const rollout = phases.docs[0]?.phaseKind === 'rollout';
|
|
48
51
|
// §7.8 manifest reads: runtime rollout ranges use the test's full weights (including their exact
|
|
49
52
|
// floating-point sum) and its control content. The rollout record has only
|
|
@@ -64,6 +67,7 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
|
|
|
64
67
|
},
|
|
65
68
|
sort: '-phase'
|
|
66
69
|
}) : null;
|
|
70
|
+
signal?.throwIfAborted();
|
|
67
71
|
if (rollout && !test?.docs[0]) throw new Error('Missing test phase for rollout ' + doc.id);
|
|
68
72
|
experiments.push({
|
|
69
73
|
...doc,
|
|
@@ -133,7 +137,7 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
|
|
|
133
137
|
const testPhase = experiment.lastTestPhase ?? (phase?.phaseKind === 'test' ? phase : null);
|
|
134
138
|
if (!testPhase) throw new XpRefusal('invalid-status', `Missing last test phase for experiment ${experiment.slug}`, undefined, 409);
|
|
135
139
|
const winner = testPhase.arms.find((arm)=>arm.key === decision.winnerArm);
|
|
136
|
-
if (experiment.kind === 'block' && winner
|
|
140
|
+
if (experiment.kind === 'block' && winner && winner.kind !== 'holdout' && winner.key !== 'holdout') manifest.archivedWinners[experiment.slug] = winner.key;
|
|
137
141
|
if (experiment.kind === 'page' && winner?.pageTarget) {
|
|
138
142
|
for (const arm of testPhase.arms){
|
|
139
143
|
if (arm.pageTarget && arm.pageTarget !== winner.pageTarget) {
|
|
@@ -185,12 +189,14 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
|
|
|
185
189
|
phaseKind: rollout ? 'rollout' : 'test',
|
|
186
190
|
seed: phase.seed,
|
|
187
191
|
coverage: layer || experiment.status === 'decided' && !rollout ? 1 : phase.allocation / 100,
|
|
188
|
-
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 {
|
|
189
195
|
key,
|
|
190
196
|
kind,
|
|
191
197
|
weight,
|
|
192
|
-
...
|
|
193
|
-
slot
|
|
198
|
+
...contentSlot != null ? {
|
|
199
|
+
slot: contentSlot
|
|
194
200
|
} : {},
|
|
195
201
|
...pageTarget != null ? {
|
|
196
202
|
pageTarget
|
|
@@ -198,7 +204,8 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
|
|
|
198
204
|
...params != null ? {
|
|
199
205
|
params
|
|
200
206
|
} : {}
|
|
201
|
-
}
|
|
207
|
+
};
|
|
208
|
+
}),
|
|
202
209
|
targeting,
|
|
203
210
|
exposurePolicy: experiment.exposurePolicy,
|
|
204
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
|
}
|
package/dist/options.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { validateAccent } from './ui/accent.js';
|
|
2
2
|
import { DEFAULT_MAX_BODY_BYTES } from './constants.js';
|
|
3
|
+
import { publicEventOrigin } from './events/request.js';
|
|
3
4
|
const normalisedCollections = new WeakMap();
|
|
4
5
|
/** Resolve once per registration list; every consumer shares the same field defaults. */ export function puckCollections(options) {
|
|
5
6
|
const entries = options.puck?.collections;
|
|
@@ -19,6 +20,8 @@ const normalisedCollections = new WeakMap();
|
|
|
19
20
|
}
|
|
20
21
|
export function resolveOptions(input) {
|
|
21
22
|
if (typeof input?.access?.manage !== 'function') throw new Error('Experiments access.manage must be a function');
|
|
23
|
+
const origin = publicEventOrigin(input.events?.origin);
|
|
24
|
+
if (input.events?.origin !== undefined && !origin) throw new Error('Experiments events.origin must be a public HTTP(S) origin with no path, query or credentials');
|
|
22
25
|
const { manage, admin = manage, readResults = manage, readIdentities = admin } = input.access;
|
|
23
26
|
for (const [name, access] of Object.entries({
|
|
24
27
|
admin,
|
|
@@ -163,6 +166,8 @@ export function resolveOptions(input) {
|
|
|
163
166
|
])),
|
|
164
167
|
events: {
|
|
165
168
|
...input.events,
|
|
169
|
+
origin,
|
|
170
|
+
rateLimit: input.events?.rateLimit,
|
|
166
171
|
retentionDays,
|
|
167
172
|
maxBodyBytes,
|
|
168
173
|
dimensions: Array.isArray(dimensions) ? [
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NextRequest } from 'next/server';
|
|
2
|
+
/** A document or an App Router navigation can mint the cookie for its own render. */
|
|
3
|
+
export declare function isPageNavigation({ method, headers }: NextRequest): boolean;
|
|
4
|
+
export declare function looksLikeNormalizedAppRouterRequest({ method, headers }: NextRequest): boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** A document or an App Router navigation can mint the cookie for its own render. */ export function isPageNavigation({ method, headers }) {
|
|
2
|
+
if (method !== 'GET') return false;
|
|
3
|
+
if (headers.has('x-nextjs-data') || headers.has('next-router-prefetch') || headers.has('next-router-segment-prefetch') || headers.has('x-middleware-prefetch') || headers.has('next-hmr-refresh') || headers.get('next-test-fetch-priority') === 'low' || [
|
|
4
|
+
'purpose',
|
|
5
|
+
'sec-purpose',
|
|
6
|
+
'x-moz'
|
|
7
|
+
].some((name)=>/\b(?:prefetch|prerender)\b/i.test(headers.get(name) ?? ''))) return false;
|
|
8
|
+
const mode = headers.get('sec-fetch-mode');
|
|
9
|
+
const destination = headers.get('sec-fetch-dest');
|
|
10
|
+
if (headers.has('rsc')) {
|
|
11
|
+
// Next sends the router state on navigation and refresh. Explicit full prefetch can
|
|
12
|
+
// share this shape, so hosts must avoid full prefetch on routes covered by the proxy.
|
|
13
|
+
const site = headers.get('sec-fetch-site');
|
|
14
|
+
return headers.get('rsc') === '1' && Boolean(headers.get('next-router-state-tree')) && (mode === null || mode === 'cors' || mode === 'same-origin') && (destination === null || destination === 'empty') && (site === null || site === 'same-origin');
|
|
15
|
+
}
|
|
16
|
+
if (mode !== null && mode !== 'navigate') return false;
|
|
17
|
+
if (destination !== null) return destination === 'document';
|
|
18
|
+
// Older browsers still advertise HTML for a document navigation.
|
|
19
|
+
return (headers.get('accept') ?? '').split(',').some((value)=>{
|
|
20
|
+
const [type, ...params] = value.trim().toLowerCase().split(';');
|
|
21
|
+
return (type === 'text/html' || type === 'application/xhtml+xml') && !params.some((param)=>/^\s*q\s*=\s*0(?:\.0*)?\s*$/.test(param));
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function looksLikeNormalizedAppRouterRequest({ method, headers }) {
|
|
25
|
+
// Next-Url survives normalization when the App Router sends it for interception.
|
|
26
|
+
// Fetch Metadata and Accept alone also match ordinary same-origin fetches.
|
|
27
|
+
return method === 'GET' && !headers.has('rsc') && headers.get('next-url')?.startsWith('/') === true && headers.get('accept') === '*/*' && headers.get('sec-fetch-mode') === 'cors' && headers.get('sec-fetch-dest') === 'empty' && headers.get('sec-fetch-site') === 'same-origin';
|
|
28
|
+
}
|