@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,14 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { contentLocaleURL } from '../../testSurface/contentLocaleURL.js';
|
|
2
|
+
import { isPreflightResult, readPreflight, READINESS_REFRESH_MS } from '../../testSurface/readPreflight.js';
|
|
2
3
|
import { classifyReadinessRead } from '../../testSurface/readinessRead.js';
|
|
3
4
|
const cache = new Map();
|
|
4
5
|
const latest = new Map();
|
|
5
6
|
const consumers = new Map();
|
|
6
|
-
const keyFor = (api, id)=>JSON.stringify([
|
|
7
|
+
const keyFor = (api, id, contentLocale)=>JSON.stringify([
|
|
7
8
|
api,
|
|
8
|
-
String(id)
|
|
9
|
+
String(id),
|
|
10
|
+
...contentLocale ? [
|
|
11
|
+
contentLocale
|
|
12
|
+
] : []
|
|
9
13
|
]);
|
|
10
|
-
function read(api, id, fresh, blocking = false) {
|
|
11
|
-
const key = keyFor(api, id);
|
|
14
|
+
function read(api, id, fresh, blocking = false, contentLocale) {
|
|
15
|
+
const key = keyFor(api, id, contentLocale);
|
|
12
16
|
const cached = cache.get(key);
|
|
13
17
|
if (cached && (!fresh || cached.pending)) return cached;
|
|
14
18
|
const controller = new AbortController();
|
|
@@ -29,7 +33,7 @@ function read(api, id, fresh, blocking = false) {
|
|
|
29
33
|
for (const notify of consumers.get(key)?.listeners ?? [])notify(entry.value);
|
|
30
34
|
entry.promise = (async ()=>{
|
|
31
35
|
try {
|
|
32
|
-
const { response, body: data } = await readPreflight((signal)=>fetch(`${api}/xp/experiments/${encodeURIComponent(id)}/preflight`, {
|
|
36
|
+
const { response, body: data } = await readPreflight((signal)=>fetch(contentLocaleURL(`${api}/xp/experiments/${encodeURIComponent(id)}/preflight`, contentLocale), {
|
|
33
37
|
credentials: 'include',
|
|
34
38
|
cache: 'no-store',
|
|
35
39
|
signal
|
|
@@ -66,23 +70,23 @@ function read(api, id, fresh, blocking = false) {
|
|
|
66
70
|
});
|
|
67
71
|
return entry;
|
|
68
72
|
}
|
|
69
|
-
/** Share mounted reads, but destructive actions always bypass settled cached knowledge. */ export function refreshPlacements(api, id) {
|
|
70
|
-
return read(api, id, true).promise;
|
|
73
|
+
/** Share mounted reads, but destructive actions always bypass settled cached knowledge. */ export function refreshPlacements(api, id, contentLocale) {
|
|
74
|
+
return read(api, id, true, false, contentLocale).promise;
|
|
71
75
|
}
|
|
72
|
-
/** Focus storms share the last attempt (including polling), at most once per ten seconds. */ export function focusPlacements(api, id) {
|
|
73
|
-
const previous = latest.get(keyFor(api, id));
|
|
76
|
+
/** Focus storms share the last attempt (including polling), at most once per ten seconds. */ export function focusPlacements(api, id, contentLocale) {
|
|
77
|
+
const previous = latest.get(keyFor(api, id, contentLocale));
|
|
74
78
|
if (previous && Date.now() - previous.startedAt < 10_000) return previous.promise;
|
|
75
|
-
return read(api, id, true).promise;
|
|
79
|
+
return read(api, id, true, false, contentLocale).promise;
|
|
76
80
|
}
|
|
77
|
-
export function invalidatePlacements(api, id) {
|
|
78
|
-
const key = keyFor(api, id);
|
|
81
|
+
export function invalidatePlacements(api, id, contentLocale) {
|
|
82
|
+
const key = keyFor(api, id, contentLocale);
|
|
79
83
|
cache.get(key)?.controller.abort();
|
|
80
84
|
cache.delete(key);
|
|
81
|
-
if (consumers.get(key)?.listeners.size) void read(api, id, true, true).promise;
|
|
85
|
+
if (consumers.get(key)?.listeners.size) void read(api, id, true, true, contentLocale).promise;
|
|
82
86
|
else latest.delete(key);
|
|
83
87
|
}
|
|
84
|
-
/** Listen without starting a request; the drawer already owns its initial preflight. */ export function subscribePlacements(api, id, notify) {
|
|
85
|
-
const key = keyFor(api, id);
|
|
88
|
+
/** Listen without starting a request; the drawer already owns its initial preflight. */ export function subscribePlacements(api, id, notify, contentLocale) {
|
|
89
|
+
const key = keyFor(api, id, contentLocale);
|
|
86
90
|
let group = consumers.get(key);
|
|
87
91
|
if (!group) {
|
|
88
92
|
const listeners = new Set();
|
|
@@ -109,10 +113,10 @@ export function invalidatePlacements(api, id) {
|
|
|
109
113
|
}
|
|
110
114
|
};
|
|
111
115
|
}
|
|
112
|
-
export function acquirePlacements(api, id, notify, fresh = false) {
|
|
113
|
-
const release = subscribePlacements(api, id, notify);
|
|
114
|
-
const key = keyFor(api, id);
|
|
115
|
-
const entry = read(api, id, fresh);
|
|
116
|
+
export function acquirePlacements(api, id, notify, fresh = false, contentLocale) {
|
|
117
|
+
const release = subscribePlacements(api, id, notify, contentLocale);
|
|
118
|
+
const key = keyFor(api, id, contentLocale);
|
|
119
|
+
const entry = read(api, id, fresh, false, contentLocale);
|
|
116
120
|
if (entry.value !== undefined) notify(entry.value);
|
|
117
121
|
let active = true;
|
|
118
122
|
void entry.promise.then(()=>{
|
|
@@ -123,24 +127,24 @@ export function acquirePlacements(api, id, notify, fresh = false) {
|
|
|
123
127
|
release();
|
|
124
128
|
};
|
|
125
129
|
}
|
|
126
|
-
/** Drawer preflight uses this same producer and follows a superseding post-write read. */ export async function readEditorPreflight(api, id, signal, supersede = false) {
|
|
130
|
+
/** Drawer preflight uses this same producer and follows a superseding post-write read. */ export async function readEditorPreflight(api, id, signal, supersede = false, contentLocale) {
|
|
127
131
|
if (signal.aborted) return new Response(null, {
|
|
128
132
|
status: 503
|
|
129
133
|
});
|
|
130
|
-
const release = subscribePlacements(api, id, ()=>{});
|
|
134
|
+
const release = subscribePlacements(api, id, ()=>{}, contentLocale);
|
|
131
135
|
signal.addEventListener('abort', release, {
|
|
132
136
|
once: true
|
|
133
137
|
});
|
|
134
138
|
try {
|
|
135
|
-
if (supersede) invalidatePlacements(api, id);
|
|
136
|
-
const previous = latest.get(keyFor(api, id));
|
|
137
|
-
let entry = previous && Date.now() - previous.startedAt < 10_000 ? previous : read(api, id, true);
|
|
139
|
+
if (supersede) invalidatePlacements(api, id, contentLocale);
|
|
140
|
+
const previous = latest.get(keyFor(api, id, contentLocale));
|
|
141
|
+
let entry = previous && Date.now() - previous.startedAt < 10_000 ? previous : read(api, id, true, false, contentLocale);
|
|
138
142
|
while(!signal.aborted){
|
|
139
143
|
await entry.promise;
|
|
140
144
|
if (signal.aborted) return new Response(null, {
|
|
141
145
|
status: 503
|
|
142
146
|
});
|
|
143
|
-
const current = latest.get(keyFor(api, id));
|
|
147
|
+
const current = latest.get(keyFor(api, id, contentLocale));
|
|
144
148
|
if (current && current !== entry) {
|
|
145
149
|
entry = current;
|
|
146
150
|
continue;
|
|
@@ -157,27 +161,31 @@ export function acquirePlacements(api, id, notify, fresh = false) {
|
|
|
157
161
|
release();
|
|
158
162
|
}
|
|
159
163
|
}
|
|
160
|
-
/** Current readiness shares the same request and lifetime as placements. */ export function cachedPreflight(api, id) {
|
|
161
|
-
const entry = latest.get(keyFor(api, id));
|
|
164
|
+
/** Current readiness shares the same request and lifetime as placements. */ export function cachedPreflight(api, id, contentLocale) {
|
|
165
|
+
const entry = latest.get(keyFor(api, id, contentLocale));
|
|
162
166
|
return entry?.preflight ?? (entry?.pending ? entry.previousPreflight : undefined);
|
|
163
167
|
}
|
|
164
|
-
/** Mandatory post-write/refusal reads guard Start in every shared consumer. */ export function placementsBlocking(api, id) {
|
|
165
|
-
const entry = cache.get(keyFor(api, id));
|
|
168
|
+
/** Mandatory post-write/refusal reads guard Start in every shared consumer. */ export function placementsBlocking(api, id, contentLocale) {
|
|
169
|
+
const entry = cache.get(keyFor(api, id, contentLocale));
|
|
166
170
|
return entry?.pending === true && entry.blocking;
|
|
167
171
|
}
|
|
168
|
-
export function placementsPending(api, id) {
|
|
169
|
-
return cache.get(keyFor(api, id))?.pending === true;
|
|
172
|
+
export function placementsPending(api, id, contentLocale) {
|
|
173
|
+
return cache.get(keyFor(api, id, contentLocale))?.pending === true;
|
|
170
174
|
}
|
|
171
|
-
/** Pending reads retain the complete settled classification, including terminal outcomes. */ export function cachedReadinessRead(api, id) {
|
|
172
|
-
const entry = latest.get(keyFor(api, id));
|
|
175
|
+
/** Pending reads retain the complete settled classification, including terminal outcomes. */ export function cachedReadinessRead(api, id, contentLocale) {
|
|
176
|
+
const entry = latest.get(keyFor(api, id, contentLocale));
|
|
173
177
|
return entry?.pending ? entry.previousRead : entry?.read;
|
|
174
178
|
}
|
|
175
|
-
export function placementReadError(api, id) {
|
|
176
|
-
return cachedReadinessRead(api, id)?.message;
|
|
179
|
+
export function placementReadError(api, id, contentLocale) {
|
|
180
|
+
return cachedReadinessRead(api, id, contentLocale)?.message;
|
|
177
181
|
}
|
|
178
182
|
const notices = new WeakMap();
|
|
179
|
-
const noticeDelay = (api, id
|
|
180
|
-
|
|
183
|
+
const noticeDelay = ({ api, id, contentLocale, noticeSubscribers })=>{
|
|
184
|
+
const read = cachedReadinessRead(api, id, contentLocale);
|
|
185
|
+
if (read?.pollDelay && (read.failed || noticeSubscribers)) return read.pollDelay;
|
|
186
|
+
return read?.answer?.document ? READINESS_REFRESH_MS : null;
|
|
187
|
+
};
|
|
188
|
+
export function watchPlacementNotice(api, id, doc, contentLocale, showingNotice = true) {
|
|
181
189
|
let session = notices.get(doc);
|
|
182
190
|
if (!session) {
|
|
183
191
|
const requests = new Map();
|
|
@@ -196,17 +204,17 @@ export function watchPlacementNotice(api, id, doc) {
|
|
|
196
204
|
}
|
|
197
205
|
const eligible = [
|
|
198
206
|
...created.requests.values()
|
|
199
|
-
].filter((request)=>!request.pending && noticeDelay(request
|
|
207
|
+
].filter((request)=>!request.pending && noticeDelay(request) !== null);
|
|
200
208
|
if (doc.visibilityState !== 'visible' || !eligible.length) return;
|
|
201
209
|
created.timer = setTimeout(()=>{
|
|
202
210
|
created.timer = undefined;
|
|
203
211
|
if (doc.visibilityState !== 'visible') return;
|
|
204
|
-
const due = eligible.filter((request)=>created.requests.get(keyFor(request.api, request.id)) === request && request.nextAt <= Date.now());
|
|
212
|
+
const due = eligible.filter((request)=>created.requests.get(keyFor(request.api, request.id, request.contentLocale)) === request && request.nextAt <= Date.now());
|
|
205
213
|
for (const request of due){
|
|
206
214
|
request.pending = true;
|
|
207
|
-
void refreshPlacements(request.api, request.id).then(()=>{
|
|
215
|
+
void refreshPlacements(request.api, request.id, request.contentLocale).then(()=>{
|
|
208
216
|
request.pending = false;
|
|
209
|
-
request.nextAt = Date.now() + (noticeDelay(request
|
|
217
|
+
request.nextAt = Date.now() + (noticeDelay(request) ?? 0);
|
|
210
218
|
if (notices.get(doc) === created) created.schedule();
|
|
211
219
|
});
|
|
212
220
|
}
|
|
@@ -214,7 +222,7 @@ export function watchPlacementNotice(api, id, doc) {
|
|
|
214
222
|
}, Math.max(0, Math.min(...eligible.map((request)=>request.nextAt)) - Date.now()));
|
|
215
223
|
};
|
|
216
224
|
created.visibility = ()=>{
|
|
217
|
-
for (const request of created.requests.values())request.nextAt = Date.now() + (noticeDelay(request
|
|
225
|
+
for (const request of created.requests.values())request.nextAt = Date.now() + (noticeDelay(request) ?? 0);
|
|
218
226
|
created.schedule();
|
|
219
227
|
};
|
|
220
228
|
session = created;
|
|
@@ -222,29 +230,34 @@ export function watchPlacementNotice(api, id, doc) {
|
|
|
222
230
|
doc.addEventListener('visibilitychange', created.visibility);
|
|
223
231
|
}
|
|
224
232
|
const current = session;
|
|
225
|
-
const key = keyFor(api, id);
|
|
233
|
+
const key = keyFor(api, id, contentLocale);
|
|
226
234
|
const existing = current.requests.get(key);
|
|
227
235
|
const request = existing ?? {
|
|
228
236
|
api,
|
|
229
237
|
id,
|
|
238
|
+
contentLocale,
|
|
230
239
|
subscribers: 0,
|
|
231
|
-
|
|
240
|
+
noticeSubscribers: 0,
|
|
241
|
+
nextAt: 0,
|
|
232
242
|
pending: false,
|
|
233
243
|
release: ()=>{}
|
|
234
244
|
};
|
|
235
245
|
request.subscribers++;
|
|
246
|
+
if (showingNotice) request.noticeSubscribers++;
|
|
247
|
+
if (!existing || request.noticeSubscribers === 1 && showingNotice) request.nextAt = Date.now() + (noticeDelay(request) ?? 0);
|
|
236
248
|
current.requests.set(key, request);
|
|
237
249
|
if (!existing) request.release = subscribePlacements(api, id, ()=>{
|
|
238
|
-
if (placementsPending(api, id)) return;
|
|
250
|
+
if (placementsPending(api, id, contentLocale)) return;
|
|
239
251
|
// Manual/focus retries also reset the backoff after recovery.
|
|
240
|
-
request.nextAt = Date.now() + (noticeDelay(
|
|
252
|
+
request.nextAt = Date.now() + (noticeDelay(request) ?? 0);
|
|
241
253
|
current.schedule();
|
|
242
|
-
});
|
|
243
|
-
|
|
254
|
+
}, contentLocale);
|
|
255
|
+
current.schedule();
|
|
244
256
|
let active = true;
|
|
245
257
|
return ()=>{
|
|
246
258
|
if (!active) return;
|
|
247
259
|
active = false;
|
|
260
|
+
if (showingNotice && --request.noticeSubscribers === 0) request.nextAt = Date.now() + (noticeDelay(request) ?? 0);
|
|
248
261
|
if (--request.subscribers === 0) {
|
|
249
262
|
current.removeRequest(key);
|
|
250
263
|
request.release();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DocId } from '../../types/contracts.js';
|
|
2
|
+
/** Payload Puck's built-in editor exposes no save callback through integrations.
|
|
3
|
+
* Observe its completed same-origin page request. Custom editors and browsers
|
|
4
|
+
* without Resource Timing still use the placement watcher.
|
|
5
|
+
*/
|
|
6
|
+
export declare function usePageSaveReadiness(api: string, id: DocId | undefined, page: {
|
|
7
|
+
collection: string;
|
|
8
|
+
id: string;
|
|
9
|
+
} | undefined, contentLocale?: string): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { invalidatePlacements } from './placementsCache.js';
|
|
4
|
+
/** Payload Puck's built-in editor exposes no save callback through integrations.
|
|
5
|
+
* Observe its completed same-origin page request. Custom editors and browsers
|
|
6
|
+
* without Resource Timing still use the placement watcher.
|
|
7
|
+
*/ export function usePageSaveReadiness(api, id, page, contentLocale) {
|
|
8
|
+
const collection = page?.collection;
|
|
9
|
+
const pageId = page?.id;
|
|
10
|
+
useEffect(()=>{
|
|
11
|
+
if (id === undefined || !collection || !pageId || !globalThis.PerformanceObserver?.supportedEntryTypes?.includes('resource')) return;
|
|
12
|
+
const endpoint = new URL(`/api/puck/${encodeURIComponent(collection)}/${encodeURIComponent(pageId)}`, window.location.origin);
|
|
13
|
+
const observer = new PerformanceObserver((entries)=>{
|
|
14
|
+
const completed = entries.getEntriesByType('resource').some((entry)=>{
|
|
15
|
+
const response = entry;
|
|
16
|
+
const status = response.responseStatus;
|
|
17
|
+
if (response.initiatorType !== 'fetch' || status && (status < 200 || status >= 300)) return false;
|
|
18
|
+
const url = new URL(response.name);
|
|
19
|
+
return url.origin === endpoint.origin && url.pathname === endpoint.pathname;
|
|
20
|
+
});
|
|
21
|
+
if (completed) invalidatePlacements(api, id, contentLocale);
|
|
22
|
+
});
|
|
23
|
+
observer.observe({
|
|
24
|
+
type: 'resource'
|
|
25
|
+
});
|
|
26
|
+
return ()=>observer.disconnect();
|
|
27
|
+
}, [
|
|
28
|
+
api,
|
|
29
|
+
id,
|
|
30
|
+
collection,
|
|
31
|
+
pageId,
|
|
32
|
+
contentLocale
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { DocId } from '../../types/contracts.js';
|
|
2
|
-
/**
|
|
3
|
-
export declare function usePlacementNotice(api: string, id: DocId | undefined, message: string | undefined): void;
|
|
2
|
+
/** Visible guidance refreshes sooner than idle status. */
|
|
3
|
+
export declare function usePlacementNotice(api: string, id: DocId | undefined, message: string | undefined, contentLocale?: string, watchStatus?: boolean): void;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
3
|
import { watchPlacementNotice } from './placementsCache.js';
|
|
4
|
-
/**
|
|
4
|
+
/** Visible guidance refreshes sooner than idle status. */ export function usePlacementNotice(api, id, message, contentLocale, watchStatus = false) {
|
|
5
5
|
const showing = message !== undefined && id !== undefined;
|
|
6
6
|
useEffect(()=>{
|
|
7
|
-
if (id === undefined || !showing) return;
|
|
8
|
-
return watchPlacementNotice(api, id, document);
|
|
7
|
+
if (id === undefined || !showing && !watchStatus) return;
|
|
8
|
+
return watchPlacementNotice(api, id, document, contentLocale, showing);
|
|
9
9
|
}, [
|
|
10
10
|
api,
|
|
11
11
|
id,
|
|
12
|
-
showing
|
|
12
|
+
showing,
|
|
13
|
+
contentLocale,
|
|
14
|
+
watchStatus
|
|
13
15
|
]);
|
|
14
16
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const nestedTestCopy: {
|
|
2
|
+
start: (outer?: string, inner?: string) => string;
|
|
3
|
+
readinessFallback: string;
|
|
4
|
+
editor: (outer?: string, inner?: string) => string;
|
|
5
|
+
publish: (outer?: string, inner?: string) => string;
|
|
6
|
+
hidden: (outer?: string) => string;
|
|
7
|
+
readiness: (detail: unknown) => string;
|
|
8
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const innerLabel = (inner)=>inner ? `“${inner}”` : 'An Experiment block with no test chosen';
|
|
2
|
+
const outerLabel = (outer)=>outer ? `“${outer}”` : 'another test';
|
|
3
|
+
const moveLabel = (inner)=>inner ? `“${inner}”` : 'that block';
|
|
4
|
+
const location = (outer, inner)=>`${innerLabel(inner)} is inside a version of ${outerLabel(outer)}.`;
|
|
5
|
+
const start = (outer, inner)=>`${location(outer, inner)} A test can't go inside another test's version. Move ${moveLabel(inner)} out of that version before you start either test.`;
|
|
6
|
+
const readinessFallback = "A test is inside another test's version on this page. A test can't go inside another test's version. Move the inner test out of that version before you start either test.";
|
|
7
|
+
export const nestedTestCopy = {
|
|
8
|
+
start,
|
|
9
|
+
readinessFallback,
|
|
10
|
+
editor: (outer, inner)=>inner ? start(outer, inner) : `This test is inside a version of ${outerLabel(outer)}. A test can't go inside another test's version. Move this test out of that version before you start either test.`,
|
|
11
|
+
publish: (outer, inner)=>`${location(outer, inner)} A test can't go inside another test's version, so this page can't be published. Move ${moveLabel(inner)} out of that version, then publish.`,
|
|
12
|
+
hidden: (outer)=>`This test is inside a version of ${outerLabel(outer)}. It is hidden, so nothing is blocked now. If you show it again, the page can't be published until you move it out of that version.`,
|
|
13
|
+
readiness: (detail)=>(Array.isArray(detail) && detail.length ? detail : [
|
|
14
|
+
{}
|
|
15
|
+
]).map((value)=>{
|
|
16
|
+
const pair = value && typeof value === 'object' ? value : {};
|
|
17
|
+
const text = (value)=>typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
18
|
+
const message = typeof pair.outer === 'string' && typeof pair.inner === 'string' ? start(text(pair.outer), text(pair.inner)) : readinessFallback;
|
|
19
|
+
const title = text(pair.title);
|
|
20
|
+
return title ? `On ${title}: ${message}` : message;
|
|
21
|
+
}).join('\n')
|
|
22
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type PuckBlock } from './visibility.js';
|
|
2
|
+
export interface NestedTest {
|
|
3
|
+
outer: PuckBlock;
|
|
4
|
+
inner: PuckBlock;
|
|
5
|
+
}
|
|
6
|
+
/** The placement traversal owns block shape, legacy zones and inherited visibility.
|
|
7
|
+
* Paste supplies its destination ancestors and includes hidden/unbound blocks.
|
|
8
|
+
*/
|
|
9
|
+
export declare function nestedTests(data: unknown, { includeHidden, ancestors }?: {
|
|
10
|
+
includeHidden?: boolean;
|
|
11
|
+
ancestors?: readonly PuckBlock[];
|
|
12
|
+
}): NestedTest[];
|
|
13
|
+
export declare const nestedTestSlug: (block: PuckBlock) => string | undefined;
|
|
14
|
+
export declare const nestedTestLabel: (block: PuckBlock) => string;
|
|
15
|
+
export declare const nestedTestKey: ({ outer, inner }: NestedTest) => string;
|
|
16
|
+
/** Traversal records all ancestors, from furthest to nearest for each inner block. */
|
|
17
|
+
export declare const nearestOuterTest: (pairs: readonly NestedTest[], innerId: unknown) => PuckBlock | undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EXPERIMENT_SLOT_TYPE } from '../types/puck.js';
|
|
2
|
+
import { puckExperimentSlug } from './experimentSlug.js';
|
|
3
|
+
import { walkVisiblePuck } from './visibility.js';
|
|
4
|
+
/** The placement traversal owns block shape, legacy zones and inherited visibility.
|
|
5
|
+
* Paste supplies its destination ancestors and includes hidden/unbound blocks.
|
|
6
|
+
*/ export function nestedTests(data, { includeHidden = false, ancestors = [] } = {}) {
|
|
7
|
+
const result = [];
|
|
8
|
+
walkVisiblePuck(data, (inner, visibility, parents)=>{
|
|
9
|
+
if (!includeHidden && visibility.hidden || inner.type !== EXPERIMENT_SLOT_TYPE) return;
|
|
10
|
+
for (const outer of [
|
|
11
|
+
...ancestors,
|
|
12
|
+
...parents
|
|
13
|
+
]){
|
|
14
|
+
if (outer.type === EXPERIMENT_SLOT_TYPE) result.push({
|
|
15
|
+
outer,
|
|
16
|
+
inner
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
export const nestedTestSlug = (block)=>puckExperimentSlug(block.props.experiment);
|
|
23
|
+
export const nestedTestLabel = (block)=>nestedTestSlug(block) ?? '';
|
|
24
|
+
export const nestedTestKey = ({ outer, inner })=>JSON.stringify([
|
|
25
|
+
outer.props.id,
|
|
26
|
+
nestedTestSlug(outer),
|
|
27
|
+
inner.props.id,
|
|
28
|
+
nestedTestSlug(inner)
|
|
29
|
+
]);
|
|
30
|
+
/** Traversal records all ancestors, from furthest to nearest for each inner block. */ export const nearestOuterTest = (pairs, innerId)=>pairs.filter((pair)=>pair.inner.props.id === innerId).at(-1)?.outer;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentConfig } from '@puckeditor/core';
|
|
2
|
-
import type
|
|
2
|
+
import { type ExperimentSlotProps } from '../types/puck.js';
|
|
3
3
|
export declare const experimentSlotLabel = "Experiment block";
|
|
4
4
|
export declare const experimentSlotFields: NonNullable<ComponentConfig<ExperimentSlotProps>['fields']>;
|
|
5
5
|
export declare const experimentSlotDefaultProps: NonNullable<ComponentConfig<ExperimentSlotProps>['defaultProps']>;
|
package/dist/puck/slotConfig.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EXPERIMENT_SLOT_TYPE } from '../types/puck.js';
|
|
1
2
|
import { createExperimentSlotField } from './experimentSlotField.js';
|
|
2
3
|
import { slotLabels } from './copy.js';
|
|
3
4
|
export const experimentSlotLabel = 'Experiment block';
|
|
@@ -6,19 +7,31 @@ export const experimentSlotFields = {
|
|
|
6
7
|
// Puck 0.24's defaultSlots prepends each slot, reversing declaration order in the outline.
|
|
7
8
|
variantC: {
|
|
8
9
|
type: 'slot',
|
|
9
|
-
label: slotLabels.variantC
|
|
10
|
+
label: slotLabels.variantC,
|
|
11
|
+
disallow: [
|
|
12
|
+
EXPERIMENT_SLOT_TYPE
|
|
13
|
+
]
|
|
10
14
|
},
|
|
11
15
|
variantB: {
|
|
12
16
|
type: 'slot',
|
|
13
|
-
label: slotLabels.variantB
|
|
17
|
+
label: slotLabels.variantB,
|
|
18
|
+
disallow: [
|
|
19
|
+
EXPERIMENT_SLOT_TYPE
|
|
20
|
+
]
|
|
14
21
|
},
|
|
15
22
|
variantA: {
|
|
16
23
|
type: 'slot',
|
|
17
|
-
label: slotLabels.variantA
|
|
24
|
+
label: slotLabels.variantA,
|
|
25
|
+
disallow: [
|
|
26
|
+
EXPERIMENT_SLOT_TYPE
|
|
27
|
+
]
|
|
18
28
|
},
|
|
19
29
|
control: {
|
|
20
30
|
type: 'slot',
|
|
21
|
-
label: slotLabels.control
|
|
31
|
+
label: slotLabels.control,
|
|
32
|
+
disallow: [
|
|
33
|
+
EXPERIMENT_SLOT_TYPE
|
|
34
|
+
]
|
|
22
35
|
}
|
|
23
36
|
};
|
|
24
37
|
export const experimentSlotDefaultProps = {
|
|
@@ -8,14 +8,13 @@ export type BlockVisibility = {
|
|
|
8
8
|
hidden: boolean;
|
|
9
9
|
hideOn: VisibilitySize[];
|
|
10
10
|
};
|
|
11
|
-
type PuckBlock = Record<string, unknown> & {
|
|
11
|
+
export type PuckBlock = Record<string, unknown> & {
|
|
12
12
|
type: string;
|
|
13
13
|
props: Record<string, unknown>;
|
|
14
14
|
};
|
|
15
15
|
/** Visit blocks with their ancestors' visibility, including legacy owner-id:zone edges.
|
|
16
16
|
* Orphan zones retain their historical discovery behavior and count as shown.
|
|
17
17
|
*/
|
|
18
|
-
export declare function walkVisiblePuck(data: unknown, visit: (block: PuckBlock, visibility: BlockVisibility) => void): void;
|
|
18
|
+
export declare function walkVisiblePuck(data: unknown, visit: (block: PuckBlock, visibility: BlockVisibility, ancestors: readonly PuckBlock[]) => void): void;
|
|
19
19
|
/** Identity-keyed index shared by discovery and the public resolver. */
|
|
20
20
|
export declare function puckVisibility(data: unknown): Map<object, BlockVisibility>;
|
|
21
|
-
export {};
|
package/dist/puck/visibility.js
CHANGED
|
@@ -44,9 +44,9 @@ export function fullyHidden(value) {
|
|
|
44
44
|
}
|
|
45
45
|
index(data);
|
|
46
46
|
const seen = new WeakSet();
|
|
47
|
-
function walk(value, inherited) {
|
|
47
|
+
function walk(value, inherited, ancestors) {
|
|
48
48
|
if (Array.isArray(value)) {
|
|
49
|
-
value.forEach((child)=>walk(child, inherited));
|
|
49
|
+
value.forEach((child)=>walk(child, inherited, ancestors));
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
if (!object(value) || seen.has(value)) return;
|
|
@@ -58,17 +58,21 @@ export function fullyHidden(value) {
|
|
|
58
58
|
hidden: inherited.hidden || fullyHidden(props._visibility),
|
|
59
59
|
hideOn: visibilitySizes.filter((size)=>inherited.hideOn.includes(size) || hiddenOnSizes(props._visibility).includes(size))
|
|
60
60
|
};
|
|
61
|
-
visit(value, visibility);
|
|
62
|
-
|
|
61
|
+
visit(value, visibility, ancestors);
|
|
62
|
+
ancestors = [
|
|
63
|
+
...ancestors,
|
|
64
|
+
value
|
|
65
|
+
];
|
|
66
|
+
if (typeof props.id === 'string') for (const content of zones.get(props.id) ?? [])walk(content, visibility, ancestors);
|
|
63
67
|
}
|
|
64
|
-
for (const [key, child] of Object.entries(value))if (value !== data || key !== 'zones' || !object(child)) walk(child, visibility);
|
|
68
|
+
for (const [key, child] of Object.entries(value))if (value !== data || key !== 'zones' || !object(child)) walk(child, visibility, ancestors);
|
|
65
69
|
}
|
|
66
70
|
const shown = {
|
|
67
71
|
hidden: false,
|
|
68
72
|
hideOn: []
|
|
69
73
|
};
|
|
70
|
-
walk(data, shown);
|
|
71
|
-
for (const root of roots)if (!owners.has(root.owner)) walk(root.content, shown);
|
|
74
|
+
walk(data, shown, []);
|
|
75
|
+
for (const root of roots)if (!owners.has(root.owner)) walk(root.content, shown, []);
|
|
72
76
|
}
|
|
73
77
|
/** Identity-keyed index shared by discovery and the public resolver. */ export function puckVisibility(data) {
|
|
74
78
|
const result = new Map();
|
|
@@ -2,11 +2,13 @@ export type Timestamp = Date | string | number;
|
|
|
2
2
|
export interface ExposedUnit {
|
|
3
3
|
arm: string;
|
|
4
4
|
firstTs: Timestamp;
|
|
5
|
+
unitAgeMs?: number;
|
|
5
6
|
}
|
|
6
7
|
export interface MetricEvent {
|
|
7
8
|
unitId: string;
|
|
8
9
|
value: number;
|
|
9
10
|
ts: Timestamp;
|
|
11
|
+
unitAgeMs?: number;
|
|
10
12
|
}
|
|
11
13
|
/** Accept Date, timestamp text, or epoch milliseconds; reject invalid dates. */
|
|
12
14
|
export declare function timestampMs(ts: Timestamp): number;
|
|
@@ -17,18 +19,19 @@ export declare function firstExposures(rows: readonly {
|
|
|
17
19
|
unitId: string;
|
|
18
20
|
arm: string;
|
|
19
21
|
ts: Timestamp;
|
|
22
|
+
unitAgeMs?: number;
|
|
20
23
|
}[], { endedAt }?: {
|
|
21
24
|
endedAt?: Timestamp;
|
|
22
25
|
}): {
|
|
23
|
-
units: Map<string, {
|
|
24
|
-
arm: string;
|
|
26
|
+
units: Map<string, ExposedUnit & {
|
|
25
27
|
firstTs: Date;
|
|
26
28
|
}>;
|
|
27
29
|
excludedMultiArm: number;
|
|
28
30
|
};
|
|
29
31
|
/** Spec §7.6/§8.2: zero-filled outcomes over each exposed unit's half-open window. */
|
|
30
|
-
export declare function perUnitValues(units: ReadonlyMap<string, ExposedUnit>, events: readonly MetricEvent[], { kind, windowHours, endedAt }: {
|
|
32
|
+
export declare function perUnitValues(units: ReadonlyMap<string, ExposedUnit>, events: readonly MetricEvent[], { kind, windowHours, endedAt, onAttributed }: {
|
|
31
33
|
kind: 'binomial' | 'count' | 'revenue';
|
|
32
34
|
windowHours: number;
|
|
33
35
|
endedAt?: Timestamp;
|
|
36
|
+
onAttributed?: (event: MetricEvent, ts: number) => void;
|
|
34
37
|
}): Map<string, number>;
|
|
@@ -21,24 +21,23 @@ import { XpAnalysisError } from '../errors.js';
|
|
|
21
21
|
const ts = timestampMs(row.ts);
|
|
22
22
|
if (ts >= end || excluded.has(row.unitId)) continue;
|
|
23
23
|
const unit = first.get(row.unitId);
|
|
24
|
-
if (
|
|
25
|
-
arm: row.arm,
|
|
26
|
-
firstTs: ts
|
|
27
|
-
});
|
|
28
|
-
else if (unit.arm !== row.arm) {
|
|
24
|
+
if (unit && unit.arm !== row.arm) {
|
|
29
25
|
first.delete(row.unitId);
|
|
30
26
|
excluded.add(row.unitId);
|
|
31
|
-
} else if (ts < unit.firstTs) {
|
|
27
|
+
} else if (!unit || ts < unit.firstTs) {
|
|
32
28
|
first.set(row.unitId, {
|
|
33
29
|
arm: row.arm,
|
|
34
|
-
firstTs: ts
|
|
30
|
+
firstTs: ts,
|
|
31
|
+
...row.unitAgeMs === undefined ? {} : {
|
|
32
|
+
unitAgeMs: row.unitAgeMs
|
|
33
|
+
}
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
const units = new Map();
|
|
39
38
|
for (const [unitId, unit] of first){
|
|
40
39
|
units.set(unitId, {
|
|
41
|
-
|
|
40
|
+
...unit,
|
|
42
41
|
firstTs: new Date(unit.firstTs)
|
|
43
42
|
});
|
|
44
43
|
}
|
|
@@ -47,7 +46,7 @@ import { XpAnalysisError } from '../errors.js';
|
|
|
47
46
|
excludedMultiArm: excluded.size
|
|
48
47
|
};
|
|
49
48
|
}
|
|
50
|
-
/** Spec §7.6/§8.2: zero-filled outcomes over each exposed unit's half-open window. */ export function perUnitValues(units, events, { kind, windowHours, endedAt }) {
|
|
49
|
+
/** Spec §7.6/§8.2: zero-filled outcomes over each exposed unit's half-open window. */ export function perUnitValues(units, events, { kind, windowHours, endedAt, onAttributed }) {
|
|
51
50
|
const values = new Map();
|
|
52
51
|
const starts = new Map();
|
|
53
52
|
const duration = windowMs(windowHours);
|
|
@@ -61,6 +60,7 @@ import { XpAnalysisError } from '../errors.js';
|
|
|
61
60
|
const start = starts.get(event.unitId);
|
|
62
61
|
if (start === undefined) continue;
|
|
63
62
|
if (ts < start || ts >= Math.min(start + duration, phaseEnd)) continue;
|
|
63
|
+
onAttributed?.(event, ts);
|
|
64
64
|
values.set(event.unitId, kind === 'binomial' ? 1 : values.get(event.unitId) + (kind === 'count' ? 1 : event.value));
|
|
65
65
|
}
|
|
66
66
|
return values;
|
package/dist/results/health.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import type { Snapshot, SnapshotHealth } from '../types/snapshot.js';
|
|
2
|
+
/** A diagnostic for a large difference in rapid activity, not an inference test.
|
|
3
|
+
* Compare only arms with enough observations and age coverage. Ordinary
|
|
4
|
+
* same-speed activity (including immediate pageviews) should not warn.
|
|
5
|
+
*/
|
|
6
|
+
export declare function rapidBrowserEvents(arms: ReadonlySet<string>, units: Iterable<{
|
|
7
|
+
arm: string;
|
|
8
|
+
unitAgeMs?: number;
|
|
9
|
+
}>): boolean;
|
|
2
10
|
/** Refresh page health while retaining health produced by other checks. */
|
|
3
11
|
export declare function mergePageHealth(previous: readonly SnapshotHealth[], pages: readonly SnapshotHealth[]): SnapshotHealth[];
|
|
4
12
|
export declare function canonicalHealth(snapshot: Pick<Snapshot, 'health' | 'goalFairnessNotice'>, ignoreUncheckedPlacements?: boolean): string;
|
package/dist/results/health.js
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
const rapidAgeMs = 5_000;
|
|
2
|
+
const minimumKnownPerArm = 30;
|
|
3
|
+
/** A diagnostic for a large difference in rapid activity, not an inference test.
|
|
4
|
+
* Compare only arms with enough observations and age coverage. Ordinary
|
|
5
|
+
* same-speed activity (including immediate pageviews) should not warn.
|
|
6
|
+
*/ export function rapidBrowserEvents(arms, units) {
|
|
7
|
+
const counts = new Map();
|
|
8
|
+
for (const { arm, unitAgeMs } of units){
|
|
9
|
+
if (!arms.has(arm)) continue;
|
|
10
|
+
const count = counts.get(arm) ?? {
|
|
11
|
+
total: 0,
|
|
12
|
+
known: 0,
|
|
13
|
+
rapid: 0
|
|
14
|
+
};
|
|
15
|
+
count.total++;
|
|
16
|
+
if (unitAgeMs !== undefined) {
|
|
17
|
+
count.known++;
|
|
18
|
+
if (unitAgeMs <= rapidAgeMs) count.rapid++;
|
|
19
|
+
}
|
|
20
|
+
counts.set(arm, count);
|
|
21
|
+
}
|
|
22
|
+
const usable = [
|
|
23
|
+
...counts.values()
|
|
24
|
+
].filter((count)=>count.known >= minimumKnownPerArm && 2 * count.known >= count.total);
|
|
25
|
+
// A fast arm needs ≥25% rapid activity and a gap of ≥20 percentage points.
|
|
26
|
+
// Compare counts directly so exact boundaries don't depend on rounding.
|
|
27
|
+
return usable.some((high)=>4 * high.rapid >= high.known && usable.some((low)=>5 * (high.rapid * low.known - low.rapid * high.known) >= high.known * low.known));
|
|
28
|
+
}
|
|
1
29
|
const healthKey = (row)=>JSON.stringify(row.code === 'placement-unchecked' ? [
|
|
2
30
|
row.code,
|
|
3
31
|
row.detail.collection ?? '',
|