@delmaredigital/payload-experiments 0.4.0-rc.9 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -7
- package/dist/admin/MetricSourceSelect.js +10 -3
- package/dist/admin/armSelect/armSelect.model.d.ts +1 -1
- package/dist/admin/blocks/BlockPanel.d.ts +1 -0
- package/dist/admin/blocks/BlockPanel.js +75 -29
- package/dist/admin/blocks/model.js +5 -4
- package/dist/admin/copy/blocks.d.ts +14 -11
- package/dist/admin/copy/blocks.js +33 -22
- package/dist/admin/copy/goals.d.ts +15 -8
- package/dist/admin/copy/goals.js +18 -8
- package/dist/admin/copy/newTest.d.ts +10 -7
- package/dist/admin/copy/newTest.js +14 -7
- package/dist/admin/copy/status.d.ts +1 -1
- package/dist/admin/copy/status.js +2 -1
- package/dist/admin/pageCollections.d.ts +1 -0
- package/dist/admin/pageCollections.js +3 -0
- package/dist/admin/placementStatus.model.js +5 -3
- package/dist/admin/status.model.d.ts +1 -0
- package/dist/admin/status.model.js +2 -1
- package/dist/admin/surface/ResultsRoute.js +4 -8
- package/dist/admin/surface/SurfaceShell.d.ts +4 -2
- package/dist/admin/surface/SurfaceShell.js +28 -3
- package/dist/admin/surface/TestRowMenu.d.ts +13 -0
- package/dist/admin/surface/TestRowMenu.js +163 -0
- package/dist/admin/surface/TestsHome.d.ts +4 -3
- package/dist/admin/surface/TestsHome.js +186 -47
- package/dist/admin/surface/TestsSurface.js +2 -1
- package/dist/admin/surface/goals/DeleteGoalDialog.d.ts +7 -0
- package/dist/admin/surface/goals/DeleteGoalDialog.js +42 -0
- package/dist/admin/surface/goals/GoalForm.d.ts +1 -0
- package/dist/admin/surface/goals/GoalForm.js +280 -198
- package/dist/admin/surface/goals/GoalsList.js +102 -33
- package/dist/admin/surface/goals/data.d.ts +2 -0
- package/dist/admin/surface/goals/data.js +9 -0
- package/dist/admin/surface/goals/goals.css +3 -2
- package/dist/admin/surface/goals/goals.model.d.ts +2 -2
- package/dist/admin/surface/goals/goals.model.js +7 -12
- package/dist/admin/surface/home.model.d.ts +15 -8
- package/dist/admin/surface/home.model.js +22 -18
- package/dist/admin/surface/newTest/NewTest.d.ts +3 -3
- package/dist/admin/surface/newTest/NewTest.js +156 -96
- package/dist/admin/surface/newTest/PageWizard.d.ts +4 -1
- package/dist/admin/surface/newTest/PageWizard.js +93 -68
- package/dist/admin/surface/newTest/newTest.css +28 -11
- package/dist/admin/surface/results/ResultsHeader.d.ts +1 -1
- package/dist/admin/surface/results/ResultsHeader.js +90 -63
- package/dist/admin/surface/surface.css +29 -0
- package/dist/admin/surface/test/TestPage.js +46 -38
- package/dist/admin/surface/useXpStepNav.d.ts +11 -0
- package/dist/admin/surface/useXpStepNav.js +14 -0
- package/dist/admin/views/TestsSurfaceClient.js +27 -3
- package/dist/admin/views/buildSurfaceProps.js +18 -66
- package/dist/arms/copy.d.ts +13 -3
- package/dist/arms/copy.js +5 -4
- package/dist/blocks/createExperimentBlock.js +1 -1
- package/dist/blocks/formState.js +1 -1
- package/dist/collections/experiments/armInvariants.js +8 -5
- package/dist/collections/metrics.js +12 -5
- package/dist/collections/serialize.js +3 -2
- package/dist/db/pageCopies.d.ts +5 -0
- package/dist/db/pageCopies.js +31 -0
- package/dist/db/snapshots.d.ts +1 -0
- package/dist/endpoints/duplicateOriginal.d.ts +38 -0
- package/dist/endpoints/duplicateOriginal.js +414 -0
- package/dist/endpoints/editorSurface.js +1 -1
- package/dist/endpoints/index.js +20 -0
- package/dist/endpoints/pages.js +245 -66
- package/dist/endpoints/placementStatus.js +1 -0
- package/dist/endpoints/results.js +3 -0
- package/dist/endpoints/testVersion.d.ts +2 -0
- package/dist/endpoints/testVersion.js +38 -0
- package/dist/endpoints/transitions.js +4 -5
- package/dist/exports/index.d.ts +1 -1
- package/dist/goals/picker/copy.js +1 -1
- package/dist/goals/sourceLabel.d.ts +2 -0
- package/dist/goals/sourceLabel.js +4 -0
- package/dist/hooks/trackPageCopies.d.ts +11 -0
- package/dist/hooks/trackPageCopies.js +7 -0
- package/dist/labels/arms.d.ts +3 -0
- package/dist/labels/arms.js +8 -0
- package/dist/options.d.ts +2 -0
- package/dist/options.js +18 -2
- package/dist/plugin.js +56 -2
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +7 -7
- package/dist/puck/editor/ConfigureTestDrawer.js +36 -26
- package/dist/puck/editor/ExperimentSlotEditor.d.ts +2 -1
- package/dist/puck/editor/ExperimentSlotEditor.js +219 -106
- package/dist/puck/editor/LeftoverVersions.js +17 -32
- package/dist/puck/editor/QuickTestActions.d.ts +2 -2
- package/dist/puck/editor/QuickTestActions.js +44 -34
- package/dist/puck/editor/ResultsReadout.d.ts +3 -1
- package/dist/puck/editor/ResultsReadout.js +28 -16
- package/dist/puck/editor/VersionBuilder.d.ts +4 -2
- package/dist/puck/editor/VersionBuilder.js +42 -63
- package/dist/puck/editor/armWrites.js +1 -1
- package/dist/puck/editor/copy.d.ts +10 -6
- package/dist/puck/editor/copy.js +22 -12
- package/dist/puck/editor/editor.chrome.css +9 -8
- package/dist/puck/editor/editor.css +14 -9
- package/dist/puck/editor/placementsCache.d.ts +1 -1
- package/dist/puck/editor/placementsCache.js +9 -17
- package/dist/puck/editor/usePageSaveReadiness.d.ts +1 -4
- package/dist/puck/editor/usePageSaveReadiness.js +18 -21
- package/dist/puck/editor/usePlacementNotice.d.ts +2 -2
- package/dist/puck/editor/usePlacementNotice.js +4 -5
- package/dist/puck/nestedTestCopy.js +2 -2
- package/dist/puck/slotConfig.d.ts +1 -1
- package/dist/puck/slotConfig.js +1 -1
- package/dist/results/analyse.d.ts +2 -0
- package/dist/results/analyse.js +2 -2
- package/dist/results/verdict.d.ts +4 -4
- package/dist/results/verdict.js +13 -10
- package/dist/server/runResults.js +2 -1
- package/dist/testSurface/PreviewLinks.d.ts +2 -1
- package/dist/testSurface/PreviewLinks.js +3 -3
- package/dist/testSurface/actions/DecideDialog.d.ts +7 -4
- package/dist/testSurface/actions/DecideDialog.js +71 -59
- package/dist/testSurface/actions/LifecycleAction.d.ts +17 -0
- package/dist/testSurface/actions/LifecycleAction.js +107 -0
- package/dist/testSurface/actions/MakeContentResult.js +1 -1
- package/dist/testSurface/actions/actions.model.d.ts +13 -5
- package/dist/testSurface/actions/actions.model.js +75 -22
- package/dist/testSurface/actions/decide.model.d.ts +1 -0
- package/dist/testSurface/actions/decide.model.js +1 -0
- package/dist/testSurface/allocation.model.js +6 -3
- package/dist/testSurface/api.d.ts +4 -1
- package/dist/testSurface/api.js +22 -14
- package/dist/testSurface/copy/actions.d.ts +36 -14
- package/dist/testSurface/copy/actions.js +39 -17
- package/dist/testSurface/copy/advanced.d.ts +10 -0
- package/dist/testSurface/copy/advanced.js +10 -0
- package/dist/testSurface/copy/arms.d.ts +1 -1
- package/dist/testSurface/copy/arms.js +1 -1
- package/dist/testSurface/copy/audience.d.ts +4 -3
- package/dist/testSurface/copy/audience.js +5 -4
- package/dist/testSurface/copy/common.d.ts +6 -6
- package/dist/testSurface/copy/common.js +6 -6
- package/dist/testSurface/copy/metrics.d.ts +6 -0
- package/dist/testSurface/copy/metrics.js +8 -0
- package/dist/testSurface/copy/pages.d.ts +67 -7
- package/dist/testSurface/copy/pages.js +74 -7
- package/dist/testSurface/copy/readiness.d.ts +8 -6
- package/dist/testSurface/copy/readiness.js +19 -10
- package/dist/testSurface/copy/recommendation.d.ts +1 -22
- package/dist/testSurface/copy/recommendation.js +2 -22
- package/dist/testSurface/copy/results.d.ts +16 -10
- package/dist/testSurface/copy/results.js +19 -11
- package/dist/testSurface/copy/review.d.ts +13 -10
- package/dist/testSurface/copy/review.js +14 -10
- package/dist/testSurface/copy/setting.d.ts +1 -2
- package/dist/testSurface/copy/setting.js +1 -2
- package/dist/testSurface/copy/surface.d.ts +11 -2
- package/dist/testSurface/copy/surface.js +14 -11
- package/dist/testSurface/copy/testPage.d.ts +16 -10
- package/dist/testSurface/copy/testPage.js +24 -18
- package/dist/testSurface/format/date.d.ts +5 -2
- package/dist/testSurface/format/date.js +24 -8
- package/dist/testSurface/format/roundProgress.d.ts +6 -0
- package/dist/testSurface/format/roundProgress.js +15 -0
- package/dist/testSurface/format/useDateFormatter.d.ts +3 -0
- package/dist/testSurface/format/useDateFormatter.js +8 -0
- package/dist/testSurface/labels.d.ts +1 -2
- package/dist/testSurface/labels.js +2 -3
- package/dist/testSurface/lockedNotice.model.d.ts +2 -0
- package/dist/testSurface/lockedNotice.model.js +31 -0
- package/dist/testSurface/readPreflight.d.ts +0 -1
- package/dist/testSurface/readPreflight.js +0 -1
- package/dist/testSurface/results/CiChart.js +2 -1
- package/dist/testSurface/results/DataTable.d.ts +1 -1
- package/dist/testSurface/results/DataTable.js +4 -3
- package/dist/testSurface/results/VerdictHero.d.ts +1 -1
- package/dist/testSurface/results/legacy.d.ts +0 -5
- package/dist/testSurface/results/legacy.js +0 -14
- package/dist/testSurface/results/results.css +2 -2
- package/dist/testSurface/results/results.model.d.ts +8 -3
- package/dist/testSurface/results/results.model.js +25 -21
- package/dist/testSurface/results/snapshot.d.ts +2 -0
- package/dist/testSurface/results/snapshot.js +3 -0
- package/dist/testSurface/surface/contracts.d.ts +6 -1
- package/dist/testSurface/surface/editorPlacement.d.ts +1 -1
- package/dist/testSurface/surface/editorPlacement.js +1 -1
- package/dist/testSurface/surface/pageBlock/pageBlock.model.js +1 -1
- package/dist/testSurface/surface/pageBlock/parts.js +25 -12
- package/dist/testSurface/surface/pagePicker/CopyRoute.d.ts +8 -1
- package/dist/testSurface/surface/pagePicker/CopyRoute.js +243 -22
- package/dist/testSurface/surface/pagePicker/PageCombobox.d.ts +15 -4
- package/dist/testSurface/surface/pagePicker/PageCombobox.js +298 -209
- package/dist/testSurface/surface/pagePicker/pagePicker.css +73 -10
- package/dist/testSurface/surface/pagePicker/pagePicker.model.d.ts +5 -3
- package/dist/testSurface/surface/pagePicker/pagePicker.model.js +17 -2
- package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +5 -3
- package/dist/testSurface/surface/readiness/ActionDialogs.js +213 -207
- package/dist/testSurface/surface/readiness/Banner.d.ts +5 -1
- package/dist/testSurface/surface/readiness/Banner.js +109 -148
- package/dist/testSurface/surface/readiness/SaveStatus.d.ts +5 -2
- package/dist/testSurface/surface/readiness/SaveStatus.js +8 -7
- package/dist/testSurface/surface/readiness/readiness.model.d.ts +14 -5
- package/dist/testSurface/surface/readiness/readiness.model.js +62 -12
- package/dist/testSurface/surface/readiness/useTransition.d.ts +3 -1
- package/dist/testSurface/surface/readiness/useTransition.js +49 -8
- package/dist/testSurface/surface/results/ReleasePages.d.ts +4 -3
- package/dist/testSurface/surface/results/ReleasePages.js +41 -41
- package/dist/testSurface/surface/results/ResultsBody.d.ts +7 -2
- package/dist/testSurface/surface/results/ResultsBody.js +170 -110
- package/dist/testSurface/surface/results/recommendation.model.d.ts +6 -9
- package/dist/testSurface/surface/results/recommendation.model.js +15 -59
- package/dist/testSurface/surface/results/useResults.d.ts +6 -2
- package/dist/testSurface/surface/setting/parts.js +31 -28
- package/dist/testSurface/surface/setting/setting.css +2 -1
- package/dist/testSurface/surface/test/AdvancedSection.js +10 -4
- package/dist/testSurface/surface/test/DeleteTest.d.ts +5 -1
- package/dist/testSurface/surface/test/DeleteTest.js +63 -55
- package/dist/testSurface/surface/test/GoalSection.js +11 -11
- package/dist/testSurface/surface/test/LengthSection.js +21 -13
- package/dist/testSurface/surface/test/PageHoldout.d.ts +1 -1
- package/dist/testSurface/surface/test/PageHoldout.js +7 -7
- package/dist/testSurface/surface/test/ReadinessBar.d.ts +2 -1
- package/dist/testSurface/surface/test/ReadinessBar.js +4 -10
- package/dist/testSurface/surface/test/Section.js +8 -0
- package/dist/testSurface/surface/test/TargetingSection.js +7 -2
- package/dist/testSurface/surface/test/TestSurface.js +17 -43
- package/dist/testSurface/surface/test/VersionsSection.js +93 -70
- package/dist/testSurface/surface/test/fields.d.ts +4 -3
- package/dist/testSurface/surface/test/fields.js +10 -16
- package/dist/testSurface/surface/test/pageParts.js +13 -7
- package/dist/testSurface/surface/test/testPage.css +9 -2
- package/dist/testSurface/surface/useTestDocument.d.ts +1 -3
- package/dist/testSurface/surface/useTestDocument.js +110 -52
- package/dist/testSurface/surface/watchTestDocument.d.ts +15 -0
- package/dist/testSurface/surface/watchTestDocument.js +181 -0
- package/dist/testSurface/surfaceUrls.d.ts +1 -0
- package/dist/testSurface/surfaceUrls.js +4 -0
- package/dist/testSurface/useApi.d.ts +3 -0
- package/dist/transitions/addMetric.d.ts +1 -1
- package/dist/transitions/addMetric.js +5 -1
- package/dist/transitions/kernel.d.ts +2 -0
- package/dist/transitions/kernel.js +1 -1
- package/dist/transitions/pageAddress.d.ts +6 -0
- package/dist/transitions/pageAddress.js +71 -0
- package/dist/transitions/pageVersions.d.ts +1 -1
- package/dist/transitions/preflightData.js +10 -2
- package/dist/transitions/start.d.ts +1 -1
- package/dist/transitions/start.js +8 -5
- package/dist/types/armKey.d.ts +2 -0
- package/dist/types/armKey.js +1 -0
- package/dist/types/contracts.d.ts +11 -1
- package/dist/types/endpoints.d.ts +38 -9
- package/dist/types/endpoints.js +1 -1
- package/dist/types/surface.d.ts +7 -9
- package/dist/ui/Dialog.d.ts +21 -2
- package/dist/ui/Dialog.js +101 -4
- package/dist/ui/Inputs.js +0 -1
- package/dist/ui/ui.css +5 -1
- package/package.json +2 -2
|
@@ -32,7 +32,11 @@
|
|
|
32
32
|
:where(.xp-test-surface) .xp-ui-checkbox-list { display: flex; flex-wrap: wrap; gap: var(--xp-space-2) var(--xp-space-4); }
|
|
33
33
|
:where(.xp-test-surface) .xp-duration-suggestion { align-items: center; margin-top: var(--xp-space-4); }
|
|
34
34
|
:where(.xp-test-surface) .xp-read-only { padding-block: .5rem; }
|
|
35
|
-
:where(.xp-test-surface) .xp-read-only p { margin-block: .5rem; }
|
|
35
|
+
:where(.xp-test-surface) .xp-read-only p { margin-block: .5rem; color: var(--xp-text); font: var(--xp-text-body); }
|
|
36
|
+
:where(.xp-test-surface) .xp-section-lock { margin-block: 0; }
|
|
37
|
+
:where(.xp-test-surface) .xp-page-binding-row { align-items: center; }
|
|
38
|
+
:where(.xp-test-surface) .xp-page-binding { margin-block-end: var(--xp-space-4); }
|
|
39
|
+
:where(.xp-test-surface) .xp-page-binding > .xp-ui-help { margin-block: var(--xp-space-2) 0; }
|
|
36
40
|
:where(.xp-test-surface) .xp-field-error { color: var(--xp-error-text); }
|
|
37
41
|
|
|
38
42
|
:where(.xp-test-surface) .xp-targeting-row { display: grid; grid-template-columns: var(--xp-targeting-attribute-width) var(--xp-targeting-comparison-width) minmax(0, 1fr); align-items: start; gap: var(--xp-space-3); border: 1px solid var(--xp-border); border-radius: var(--xp-radius-control); padding: var(--xp-space-4); margin-bottom: var(--xp-space-4); }
|
|
@@ -46,6 +50,10 @@
|
|
|
46
50
|
:where(.xp-test-surface) .xp-targeting-row, :where(.xp-test-surface) .xp-field-grid { grid-template-columns: 1fr; }
|
|
47
51
|
}
|
|
48
52
|
|
|
53
|
+
:where(.xp-test-surface) .xp-version-rows.xp-version-rows--setting { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
|
|
54
|
+
:where(.xp-test-surface) .xp-version-rows--setting .xp-version-row { align-items: start; }
|
|
55
|
+
:where(.xp-test-surface) .xp-version-rows--setting .xp-setting-values { grid-column: 2; min-width: 0; }
|
|
56
|
+
|
|
49
57
|
:where(.xp-test-surface) .xp-test-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); align-items: start; gap: var(--xp-space-8); }
|
|
50
58
|
:where(.xp-test-surface) .xp-test-content { display: grid; gap: var(--xp-space-8); min-width: 0; max-width: 760px; }
|
|
51
59
|
:where(.xp-test-surface) .xp-test-rail { position: sticky; top: var(--xp-space-6); min-width: 0; }
|
|
@@ -98,7 +106,6 @@
|
|
|
98
106
|
|
|
99
107
|
:where(.xp-test-surface) .xp-readiness--bar { grid-template-columns: minmax(0, 1fr); }
|
|
100
108
|
:where(.xp-test-surface) .xp-readiness--bar > .xp-readiness__actions { grid-column: 1; grid-row: auto; justify-content: flex-start; }
|
|
101
|
-
:where(.xp-test-surface) .xp-readiness-action-reason { display: block; }
|
|
102
109
|
|
|
103
110
|
:where(.xp-test-surface) .xp-test-advanced.xp-ui-section--blocked { border-color: var(--xp-error-border); }
|
|
104
111
|
:where(.xp-test-surface) .xp-test-rail-mark--blocked { display: grid; place-items: center; width: 20px; height: 20px; border: 1px solid var(--xp-error-border); border-radius: 50%; }
|
|
@@ -11,11 +11,9 @@ export type FieldDraft = {
|
|
|
11
11
|
retry?: boolean;
|
|
12
12
|
};
|
|
13
13
|
/** Section data only: staging never saves. Call commit on blur or a section action. */
|
|
14
|
-
export declare function useTestDocument(id: DocId, { apiRoute, contentLocale,
|
|
14
|
+
export declare function useTestDocument(id: DocId, { apiRoute, contentLocale, enabled, onDocument, onPreflight, requestPreflight }: {
|
|
15
15
|
apiRoute: string;
|
|
16
16
|
contentLocale?: string;
|
|
17
|
-
refetchPreflightOnFocus?: boolean;
|
|
18
|
-
refetchDocumentOnFocus?: boolean;
|
|
19
17
|
enabled?: boolean;
|
|
20
18
|
onDocument?: (doc: TestDocument) => void;
|
|
21
19
|
onPreflight?: (preflight: PreflightResult) => void;
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
import { contentLocaleURL } from '../contentLocaleURL.js';
|
|
3
3
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
4
|
import { API_MESSAGES } from '../copy/common.js';
|
|
5
|
-
import { documentChanged, readPreflight,
|
|
5
|
+
import { documentChanged, readPreflight, statusOrRoundChanged } from '../readPreflight.js';
|
|
6
6
|
import { XP_IF_UPDATED_AT_HEADER } from '../../constants.js';
|
|
7
|
-
import { useReadinessPolling } from '../useReadinessPolling.js';
|
|
8
|
-
import { useOnTestReturn } from '../useOnTestReturn.js';
|
|
9
7
|
import { classifyReadinessRead } from '../readinessRead.js';
|
|
10
8
|
import { TEST_PAGE } from '../copy/testPage.js';
|
|
11
9
|
import { changedPatch, editablePatch, payloadFieldErrors, sameTestValue } from './testDocument.model.js';
|
|
10
|
+
import { watchTestDocument } from './watchTestDocument.js';
|
|
12
11
|
// Saves outlive their mounted reader. Reopening the same document must wait for its queue.
|
|
13
12
|
const drainingSaves = new Map();
|
|
14
13
|
const initialView = ()=>({
|
|
@@ -161,7 +160,7 @@ function adoptDocumentRead(session, doc, unsent) {
|
|
|
161
160
|
}
|
|
162
161
|
session.saved = doc;
|
|
163
162
|
}
|
|
164
|
-
/** Section data only: staging never saves. Call commit on blur or a section action. */ export function useTestDocument(id, { apiRoute, contentLocale,
|
|
163
|
+
/** Section data only: staging never saves. Call commit on blur or a section action. */ export function useTestDocument(id, { apiRoute, contentLocale, enabled = true, onDocument, onPreflight, requestPreflight }) {
|
|
165
164
|
const observers = useRef({
|
|
166
165
|
onDocument,
|
|
167
166
|
onPreflight,
|
|
@@ -225,8 +224,9 @@ function adoptDocumentRead(session, doc, unsent) {
|
|
|
225
224
|
};
|
|
226
225
|
current.current = session;
|
|
227
226
|
const url = `${base}/xp-experiments/${encodeURIComponent(documentId)}?depth=0`;
|
|
227
|
+
const hasQueuedSave = ()=>session.activePatch || session.queue.length > 0;
|
|
228
228
|
async function refreshFromPreflight(read) {
|
|
229
|
-
if (!session.saved || !read || document.visibilityState !== 'visible') return;
|
|
229
|
+
if (!session.saved || !read || hasQueuedSave() || document.visibilityState !== 'visible') return;
|
|
230
230
|
const answer = read.answer?.document;
|
|
231
231
|
if (answer?.updatedAt && session.saved.updatedAt && answer.updatedAt < session.saved.updatedAt) return;
|
|
232
232
|
if (!documentChanged(answer, session.saved) && ![
|
|
@@ -239,7 +239,8 @@ function adoptDocumentRead(session, doc, unsent) {
|
|
|
239
239
|
session.publish();
|
|
240
240
|
}
|
|
241
241
|
if (!session.view.documentFailure?.retry) await refreshDocument({
|
|
242
|
-
fromPreflight: true
|
|
242
|
+
fromPreflight: true,
|
|
243
|
+
deferWhileSaving: true
|
|
243
244
|
});
|
|
244
245
|
}
|
|
245
246
|
let preflightRevision = 0;
|
|
@@ -267,7 +268,7 @@ function adoptDocumentRead(session, doc, unsent) {
|
|
|
267
268
|
if (requestedLocale !== observers.current.contentLocale) return refreshPreflight(initial, supersede);
|
|
268
269
|
const read = classifyReadinessRead(status, body, session.preflightFailures + 1);
|
|
269
270
|
// A preflight refusal can also reflect its own access rules. Confirm with the document endpoint.
|
|
270
|
-
if (read.answer?.document || !initial &&
|
|
271
|
+
if (read.answer?.document || !initial && [
|
|
271
272
|
401,
|
|
272
273
|
403,
|
|
273
274
|
404
|
|
@@ -278,12 +279,9 @@ function adoptDocumentRead(session, doc, unsent) {
|
|
|
278
279
|
const failure = session.view.documentFailure?.loadState;
|
|
279
280
|
if (failure === 'missing' || failure === 'forbidden') return;
|
|
280
281
|
session.preflightLoading = false;
|
|
281
|
-
session.view.preflightRead = read
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
} : read;
|
|
285
|
-
session.preflightFailures = session.view.preflightRead.failed ? session.preflightFailures + 1 : 0;
|
|
286
|
-
const data = session.view.preflightRead.answer;
|
|
282
|
+
session.view.preflightRead = read;
|
|
283
|
+
session.preflightFailures = read.failed ? session.preflightFailures + 1 : 0;
|
|
284
|
+
const data = read.answer;
|
|
287
285
|
if (data) {
|
|
288
286
|
observers.current.onPreflight?.(data);
|
|
289
287
|
session.view.preflight = data;
|
|
@@ -335,7 +333,7 @@ function adoptDocumentRead(session, doc, unsent) {
|
|
|
335
333
|
let documentRevision = 0;
|
|
336
334
|
const draining = drainingSaves.get(key);
|
|
337
335
|
const drain = draining ? waitForDrain(draining, controller.signal) : undefined;
|
|
338
|
-
async function refreshDocument({ reload = false, discardDrafts = false, checkReadiness = false, fromPreflight = false } = {}) {
|
|
336
|
+
async function refreshDocument({ reload = false, discardDrafts = false, checkReadiness = false, fromPreflight = false, deferWhileSaving = false } = {}) {
|
|
339
337
|
if (controller.signal.aborted) return;
|
|
340
338
|
if (discardDrafts) {
|
|
341
339
|
// Reset the edits present when the person clicks Reload. Typing during the read starts a new draft.
|
|
@@ -356,7 +354,8 @@ function adoptDocumentRead(session, doc, unsent) {
|
|
|
356
354
|
const initial = session.view.loadState !== 'ready' && !fromPreflight;
|
|
357
355
|
try {
|
|
358
356
|
const doc = await readDocument();
|
|
359
|
-
|
|
357
|
+
// A save may have started while the background document read was in flight.
|
|
358
|
+
if (controller.signal.aborted || revision !== documentRevision || deferWhileSaving && hasQueuedSave()) return;
|
|
360
359
|
session.view.statusReadPending = false;
|
|
361
360
|
session.documentFailures = 0;
|
|
362
361
|
session.view.documentFailure = undefined;
|
|
@@ -368,24 +367,101 @@ function adoptDocumentRead(session, doc, unsent) {
|
|
|
368
367
|
session.view.errors = {};
|
|
369
368
|
session.view.chosenPages = {};
|
|
370
369
|
}
|
|
371
|
-
const changed = adopted && documentChanged(doc, previous ?? doc);
|
|
372
370
|
if (!adopted || reload) session.publish();
|
|
373
|
-
if (!fromPreflight && (reload || initial || checkReadiness ||
|
|
371
|
+
if (!fromPreflight && (reload || initial || checkReadiness || adopted)) {
|
|
372
|
+
await refreshPreflight(initial, !initial || reload);
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
374
375
|
} catch (error) {
|
|
375
376
|
if (controller.signal.aborted || revision !== documentRevision || session.saved !== previous) return;
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
377
|
+
publishDocumentFailure(error instanceof DocumentReadError ? error.status : 0);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function publishDocumentFailure(status) {
|
|
381
|
+
const read = classifyReadinessRead(status, undefined, ++session.documentFailures, {
|
|
382
|
+
kind: 'document'
|
|
383
|
+
});
|
|
384
|
+
session.view.documentFailure = read;
|
|
385
|
+
if (session.view.loadState !== 'ready' || read.loadState === 'forbidden' || read.loadState === 'missing') {
|
|
386
|
+
session.preflightLoading = false;
|
|
387
|
+
session.view.preflightRead = read;
|
|
388
|
+
session.view.loadState = read.loadState;
|
|
389
|
+
}
|
|
390
|
+
session.publish();
|
|
391
|
+
}
|
|
392
|
+
function refreshOutcome() {
|
|
393
|
+
if (controller.signal.aborted) return 'stop';
|
|
394
|
+
if (session.view.documentFailure) return session.view.documentFailure.retry ? 'retry' : 'stop';
|
|
395
|
+
if (session.view.preflightRead?.retry && !observers.current.requestPreflight) return 'retry';
|
|
396
|
+
return session.view.loadState === 'ready' ? 'ok' : 'stop';
|
|
397
|
+
}
|
|
398
|
+
const versionUrl = `${base}/xp/experiments/${encodeURIComponent(documentId)}/version`;
|
|
399
|
+
const watch = watchTestDocument(apiRoute, documentId, async ({ broadcast, returned })=>{
|
|
400
|
+
if (broadcast) {
|
|
401
|
+
await refreshDocument({
|
|
402
|
+
checkReadiness: true
|
|
379
403
|
});
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
404
|
+
return refreshOutcome();
|
|
405
|
+
}
|
|
406
|
+
if (!returned && session.view.documentFailure?.retry && !hasQueuedSave()) {
|
|
407
|
+
await refreshDocument({
|
|
408
|
+
checkReadiness: true,
|
|
409
|
+
deferWhileSaving: true
|
|
410
|
+
});
|
|
411
|
+
return refreshOutcome();
|
|
412
|
+
}
|
|
413
|
+
const { response, body } = await readPreflight((signal)=>fetch(versionUrl, {
|
|
414
|
+
method: 'GET',
|
|
415
|
+
credentials: 'include',
|
|
416
|
+
cache: 'no-store',
|
|
417
|
+
signal
|
|
418
|
+
}), controller.signal).catch(()=>({
|
|
419
|
+
response: undefined,
|
|
420
|
+
body: undefined
|
|
421
|
+
}));
|
|
422
|
+
if (controller.signal.aborted) return 'stop';
|
|
423
|
+
const version = body;
|
|
424
|
+
if (!response?.ok || !version?.status || typeof version.updatedAt !== 'string' || typeof version.phase !== 'number') {
|
|
425
|
+
if (response && [
|
|
426
|
+
400,
|
|
427
|
+
401,
|
|
428
|
+
403,
|
|
429
|
+
404,
|
|
430
|
+
501
|
|
431
|
+
].includes(response.status)) {
|
|
432
|
+
publishDocumentFailure(response.status);
|
|
433
|
+
return 'stop';
|
|
385
434
|
}
|
|
386
|
-
session.
|
|
435
|
+
if (returned && session.view.loadState === 'ready' && document.visibilityState === 'visible') await refreshPreflight(false, true);
|
|
436
|
+
return 'retry';
|
|
387
437
|
}
|
|
388
|
-
|
|
438
|
+
if (document.visibilityState !== 'visible') return 'ok';
|
|
439
|
+
// The version endpoint can see this tab's write before its PATCH response arrives.
|
|
440
|
+
if (!hasQueuedSave()) {
|
|
441
|
+
const saved = session.saved;
|
|
442
|
+
const currentVersion = saved ? {
|
|
443
|
+
status: saved.status,
|
|
444
|
+
phase: saved.phase ?? 0,
|
|
445
|
+
updatedAt: saved.updatedAt
|
|
446
|
+
} : undefined;
|
|
447
|
+
const changed = currentVersion && (!currentVersion.updatedAt || version.updatedAt >= currentVersion.updatedAt) && documentChanged(version, currentVersion);
|
|
448
|
+
if (changed && statusOrRoundChanged(version, currentVersion)) {
|
|
449
|
+
session.view.statusReadPending = true;
|
|
450
|
+
session.publish();
|
|
451
|
+
}
|
|
452
|
+
if (changed || session.view.documentFailure || session.view.loadState !== 'ready') {
|
|
453
|
+
const readinessRefreshed = await refreshDocument({
|
|
454
|
+
checkReadiness: true,
|
|
455
|
+
deferWhileSaving: true
|
|
456
|
+
});
|
|
457
|
+
if (readinessRefreshed || !returned || session.view.loadState !== 'ready') return refreshOutcome();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (returned || !hasQueuedSave() && session.view.preflightRead?.retry && !session.preflightLoading && !observers.current.requestPreflight) {
|
|
461
|
+
await refreshPreflight(false, returned);
|
|
462
|
+
}
|
|
463
|
+
return refreshOutcome();
|
|
464
|
+
});
|
|
389
465
|
// Capture each commit now, then diff against the latest server document when its turn arrives.
|
|
390
466
|
function commit() {
|
|
391
467
|
if (!session.saved || session.view.stale || controller.signal.aborted || !Object.keys(session.pending.patch).length) return session.tail;
|
|
@@ -443,6 +519,7 @@ function adoptDocumentRead(session, doc, unsent) {
|
|
|
443
519
|
session.pending = emptyEdit();
|
|
444
520
|
}
|
|
445
521
|
} else {
|
|
522
|
+
watch.notify();
|
|
446
523
|
// Payload collection PATCH returns { doc, message }; GET returns the doc itself.
|
|
447
524
|
const doc = body?.doc;
|
|
448
525
|
const readable = doc && doc.id != null && doc.status;
|
|
@@ -524,7 +601,8 @@ function adoptDocumentRead(session, doc, unsent) {
|
|
|
524
601
|
commit,
|
|
525
602
|
refreshDocument,
|
|
526
603
|
refreshFromPreflight,
|
|
527
|
-
refreshPreflight: (supersede)=>refreshPreflight(false, supersede)
|
|
604
|
+
refreshPreflight: (supersede)=>refreshPreflight(false, supersede),
|
|
605
|
+
notifyChange: watch.notify
|
|
528
606
|
};
|
|
529
607
|
session.publish();
|
|
530
608
|
void refreshDocument().then(async ()=>{
|
|
@@ -539,8 +617,9 @@ function adoptDocumentRead(session, doc, unsent) {
|
|
|
539
617
|
});
|
|
540
618
|
await commit();
|
|
541
619
|
}
|
|
542
|
-
});
|
|
620
|
+
}).finally(()=>watch.start(refreshOutcome()));
|
|
543
621
|
return ()=>{
|
|
622
|
+
watch.close();
|
|
544
623
|
controller.abort();
|
|
545
624
|
if (!session.queue.length && !session.activePatch) return;
|
|
546
625
|
const draining = session.tail;
|
|
@@ -645,29 +724,6 @@ function adoptDocumentRead(session, doc, unsent) {
|
|
|
645
724
|
}, [
|
|
646
725
|
key
|
|
647
726
|
]);
|
|
648
|
-
const documentFailure = state.key === key ? state.view.documentFailure : undefined;
|
|
649
|
-
const settledRead = state.key === key ? state.view.preflightRead : undefined;
|
|
650
|
-
useReadinessPolling(documentFailure?.pollDelay ? documentFailure : settledRead, ()=>{
|
|
651
|
-
const entry = commitRef.current;
|
|
652
|
-
if (entry?.session.key !== key) return;
|
|
653
|
-
if (documentFailure?.retry || state.view.loadState !== 'ready') void entry.refreshDocument({
|
|
654
|
-
checkReadiness: true
|
|
655
|
-
});
|
|
656
|
-
else void refreshPreflight();
|
|
657
|
-
}, enabled && (!requestPreflight || !!documentFailure?.retry), state.view.preflightPending);
|
|
658
|
-
useOnTestReturn(useCallback(()=>{
|
|
659
|
-
const entry = commitRef.current;
|
|
660
|
-
if (refetchDocumentOnFocus && entry?.session.key === key) {
|
|
661
|
-
void entry.refreshDocument({
|
|
662
|
-
checkReadiness: refetchPreflightOnFocus
|
|
663
|
-
});
|
|
664
|
-
} else if (refetchPreflightOnFocus) void refreshPreflight();
|
|
665
|
-
}, [
|
|
666
|
-
key,
|
|
667
|
-
refetchDocumentOnFocus,
|
|
668
|
-
refetchPreflightOnFocus,
|
|
669
|
-
refreshPreflight
|
|
670
|
-
]), enabled && (refetchDocumentOnFocus || refetchPreflightOnFocus));
|
|
671
727
|
const choosePage = useCallback((arm, page)=>{
|
|
672
728
|
const session = current.current;
|
|
673
729
|
const doc = session?.key === key ? optimistic(session) : null;
|
|
@@ -691,8 +747,10 @@ function adoptDocumentRead(session, doc, unsent) {
|
|
|
691
747
|
]);
|
|
692
748
|
// Transition responses outlive this mount just like submitted PATCHes. Publish
|
|
693
749
|
// their authoritative document before attempting a mount-dependent reload.
|
|
750
|
+
const notifyChange = commitRef.current?.session.key === key ? commitRef.current.notifyChange : undefined;
|
|
694
751
|
const transitionActions = {
|
|
695
752
|
acceptTransition (result) {
|
|
753
|
+
notifyChange?.();
|
|
696
754
|
const doc = result?.doc;
|
|
697
755
|
if (!doc || doc.id == null || !doc.status || !Array.isArray(doc.arms) || String(doc.id) !== documentId) return;
|
|
698
756
|
const session = current.current;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DocId } from '../../types/contracts.js';
|
|
2
|
+
/** Broadcast a completed mutation when its caller has no mounted document watcher. */
|
|
3
|
+
export declare function notifyTestDocument(apiRoute: string, id: DocId): void;
|
|
4
|
+
type Check = (reasons: {
|
|
5
|
+
broadcast: boolean;
|
|
6
|
+
returned: boolean;
|
|
7
|
+
}) => Promise<'ok' | 'retry' | 'stop'>;
|
|
8
|
+
type CheckResult = Awaited<ReturnType<Check>>;
|
|
9
|
+
/** Owns the single background read and its timer for one mounted test. */
|
|
10
|
+
export declare function watchTestDocument(apiRoute: string, id: DocId, check: Check): {
|
|
11
|
+
start(initial: CheckResult): void;
|
|
12
|
+
notify(): void;
|
|
13
|
+
close(): void;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
const POLL_MS = 5_000;
|
|
2
|
+
const IDLE_MS = 10 * 60_000;
|
|
3
|
+
const WINDOW_AWAY_MS = 250;
|
|
4
|
+
const RETRY_MS = [
|
|
5
|
+
4_000,
|
|
6
|
+
8_000,
|
|
7
|
+
16_000,
|
|
8
|
+
30_000
|
|
9
|
+
];
|
|
10
|
+
function openChannel(apiRoute, id) {
|
|
11
|
+
const key = JSON.stringify([
|
|
12
|
+
apiRoute.replace(/\/$/, ''),
|
|
13
|
+
String(id)
|
|
14
|
+
]);
|
|
15
|
+
try {
|
|
16
|
+
return new BroadcastChannel(`xp-test:${key}`);
|
|
17
|
+
} catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Broadcast a completed mutation when its caller has no mounted document watcher. */ export function notifyTestDocument(apiRoute, id) {
|
|
22
|
+
const sender = openChannel(apiRoute, id);
|
|
23
|
+
sender?.postMessage(null);
|
|
24
|
+
sender?.close();
|
|
25
|
+
}
|
|
26
|
+
/** Owns the single background read and its timer for one mounted test. */ export function watchTestDocument(apiRoute, id, check) {
|
|
27
|
+
const channel = openChannel(apiRoute, id);
|
|
28
|
+
const inputEvents = [
|
|
29
|
+
'pointerdown',
|
|
30
|
+
'pointermove',
|
|
31
|
+
'keydown',
|
|
32
|
+
'scroll'
|
|
33
|
+
];
|
|
34
|
+
let timer;
|
|
35
|
+
let lastInput = Date.now();
|
|
36
|
+
let retryAt = 0;
|
|
37
|
+
let failures = 0;
|
|
38
|
+
let started = false;
|
|
39
|
+
let closed = false;
|
|
40
|
+
let inFlight = false;
|
|
41
|
+
let requested = false;
|
|
42
|
+
let broadcast = false;
|
|
43
|
+
let returned = false;
|
|
44
|
+
let polling = true;
|
|
45
|
+
const visible = ()=>document.visibilityState === 'visible';
|
|
46
|
+
const active = ()=>Date.now() - lastInput < IDLE_MS;
|
|
47
|
+
let wasVisible = visible();
|
|
48
|
+
let awaitingPageShow = false;
|
|
49
|
+
let blurredAt;
|
|
50
|
+
let focusCheck;
|
|
51
|
+
function record(result) {
|
|
52
|
+
polling = result !== 'stop';
|
|
53
|
+
failures = result === 'retry' ? failures + 1 : 0;
|
|
54
|
+
retryAt = failures ? Date.now() + RETRY_MS[Math.min(failures - 1, RETRY_MS.length - 1)] : 0;
|
|
55
|
+
}
|
|
56
|
+
function schedule() {
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
if (!started || closed || inFlight) return;
|
|
59
|
+
if (!broadcast && (!visible() || !requested && (!polling || !active()))) return;
|
|
60
|
+
const delay = requested || broadcast ? 0 : failures ? retryAt - Date.now() : POLL_MS;
|
|
61
|
+
const wait = Math.max(delay, retryAt - Date.now(), 0);
|
|
62
|
+
if (wait === 0) void run();
|
|
63
|
+
else timer = setTimeout(()=>{
|
|
64
|
+
void run();
|
|
65
|
+
}, wait);
|
|
66
|
+
}
|
|
67
|
+
async function run() {
|
|
68
|
+
if (closed || inFlight || !broadcast && (!visible() || !requested && !active())) return;
|
|
69
|
+
inFlight = true;
|
|
70
|
+
const reasons = {
|
|
71
|
+
broadcast,
|
|
72
|
+
returned
|
|
73
|
+
};
|
|
74
|
+
requested = false;
|
|
75
|
+
broadcast = false;
|
|
76
|
+
returned = false;
|
|
77
|
+
try {
|
|
78
|
+
record(await check(reasons));
|
|
79
|
+
} catch {
|
|
80
|
+
record('retry');
|
|
81
|
+
} finally{
|
|
82
|
+
inFlight = false;
|
|
83
|
+
schedule();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function onInput() {
|
|
87
|
+
const wasIdle = !active();
|
|
88
|
+
lastInput = Date.now();
|
|
89
|
+
if (wasIdle && visible() && polling) {
|
|
90
|
+
requested = true;
|
|
91
|
+
schedule();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function requestReturn() {
|
|
95
|
+
requested = true;
|
|
96
|
+
returned = true;
|
|
97
|
+
schedule();
|
|
98
|
+
}
|
|
99
|
+
function onVisibility() {
|
|
100
|
+
const nowVisible = visible();
|
|
101
|
+
const becameVisible = nowVisible && !wasVisible;
|
|
102
|
+
wasVisible = nowVisible;
|
|
103
|
+
if (becameVisible && !awaitingPageShow) {
|
|
104
|
+
requestReturn();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (!nowVisible) {
|
|
108
|
+
requested = false;
|
|
109
|
+
returned = false;
|
|
110
|
+
blurredAt = undefined;
|
|
111
|
+
}
|
|
112
|
+
schedule();
|
|
113
|
+
}
|
|
114
|
+
function onBlur() {
|
|
115
|
+
clearTimeout(focusCheck);
|
|
116
|
+
if (!visible()) return;
|
|
117
|
+
blurredAt = Date.now();
|
|
118
|
+
// Let focus settle. The document still has focus when it moves into
|
|
119
|
+
// a child frame, including the Puck canvas.
|
|
120
|
+
focusCheck = setTimeout(()=>{
|
|
121
|
+
if (document.hasFocus()) blurredAt = undefined;
|
|
122
|
+
}, 0);
|
|
123
|
+
}
|
|
124
|
+
function onFocus() {
|
|
125
|
+
// Switching windows can leave the document visible the whole time.
|
|
126
|
+
clearTimeout(focusCheck);
|
|
127
|
+
const returnedToWindow = blurredAt !== undefined && Date.now() - blurredAt >= WINDOW_AWAY_MS && wasVisible && visible() && !awaitingPageShow;
|
|
128
|
+
blurredAt = undefined;
|
|
129
|
+
if (returnedToWindow) requestReturn();
|
|
130
|
+
}
|
|
131
|
+
function onPageHide(event) {
|
|
132
|
+
// A restored page can become visible before pageshow. Count it as one return.
|
|
133
|
+
awaitingPageShow = event.persisted;
|
|
134
|
+
blurredAt = undefined;
|
|
135
|
+
}
|
|
136
|
+
function onPageShow(event) {
|
|
137
|
+
if (!event.persisted) return;
|
|
138
|
+
awaitingPageShow = false;
|
|
139
|
+
wasVisible = visible();
|
|
140
|
+
if (wasVisible) requestReturn();
|
|
141
|
+
}
|
|
142
|
+
channel?.addEventListener('message', ()=>{
|
|
143
|
+
broadcast = true;
|
|
144
|
+
schedule();
|
|
145
|
+
});
|
|
146
|
+
for (const event of inputEvents)document.addEventListener(event, onInput, {
|
|
147
|
+
capture: true,
|
|
148
|
+
passive: true
|
|
149
|
+
});
|
|
150
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
151
|
+
window.addEventListener('blur', onBlur);
|
|
152
|
+
window.addEventListener('focus', onFocus);
|
|
153
|
+
window.addEventListener('pagehide', onPageHide);
|
|
154
|
+
window.addEventListener('pageshow', onPageShow);
|
|
155
|
+
return {
|
|
156
|
+
start (initial) {
|
|
157
|
+
record(initial);
|
|
158
|
+
started = true;
|
|
159
|
+
schedule();
|
|
160
|
+
},
|
|
161
|
+
notify () {
|
|
162
|
+
if (!closed) channel?.postMessage(null);
|
|
163
|
+
else {
|
|
164
|
+
// A submitted save can finish after its reader has unmounted.
|
|
165
|
+
notifyTestDocument(apiRoute, id);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
close () {
|
|
169
|
+
closed = true;
|
|
170
|
+
clearTimeout(timer);
|
|
171
|
+
clearTimeout(focusCheck);
|
|
172
|
+
channel?.close();
|
|
173
|
+
for (const event of inputEvents)document.removeEventListener(event, onInput, true);
|
|
174
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
175
|
+
window.removeEventListener('blur', onBlur);
|
|
176
|
+
window.removeEventListener('focus', onFocus);
|
|
177
|
+
window.removeEventListener('pagehide', onPageHide);
|
|
178
|
+
window.removeEventListener('pageshow', onPageShow);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
@@ -2,6 +2,7 @@ type SurfaceQuery = Record<string, string | string[] | undefined>;
|
|
|
2
2
|
export declare function surfaceQuery(query?: SurfaceQuery): string;
|
|
3
3
|
export declare const surfaceUrls: {
|
|
4
4
|
home: (adminRoute: string, query?: SurfaceQuery) => string;
|
|
5
|
+
newGoal: (adminRoute: string, query?: SurfaceQuery) => string;
|
|
5
6
|
goals: (adminRoute: string, query?: SurfaceQuery) => string;
|
|
6
7
|
};
|
|
7
8
|
export {};
|
|
@@ -12,6 +12,10 @@ export const surfaceUrls = {
|
|
|
12
12
|
adminRoute,
|
|
13
13
|
path: `/collections/xp-experiments${surfaceQuery(query)}`
|
|
14
14
|
}),
|
|
15
|
+
newGoal: (adminRoute, query)=>formatAdminURL({
|
|
16
|
+
adminRoute,
|
|
17
|
+
path: `/experiments/goals/new${surfaceQuery(query)}`
|
|
18
|
+
}),
|
|
15
19
|
goals: (adminRoute, query)=>formatAdminURL({
|
|
16
20
|
adminRoute,
|
|
17
21
|
path: `/collections/xp-metrics${surfaceQuery(query)}`
|
|
@@ -14,7 +14,10 @@ export declare function useApi(apiRoute: string): {
|
|
|
14
14
|
q?: string;
|
|
15
15
|
path?: string;
|
|
16
16
|
page?: number;
|
|
17
|
+
mode?: "block";
|
|
17
18
|
}, signal?: AbortSignal) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").PagesResult>>;
|
|
19
|
+
previewPageCopy: (id: import("../types/contracts.js").DocId, arm: string, signal?: AbortSignal) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").CopyPagePlan>>;
|
|
20
|
+
makePageCopy: (id: import("../types/contracts.js").DocId, arm: string, plan: import("../types/endpoints.js").CopyPagePlan) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").CopyPageResult>>;
|
|
18
21
|
placementStatus: (body: import("../types/endpoints.js").PlacementStatusBody) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").PlacementStatusResult>>;
|
|
19
22
|
start: (id: import("../types/contracts.js").DocId, phase?: number) => Promise<import("./api.js").ApiResult<import("../types/endpoints.js").TransitionSuccess>>;
|
|
20
23
|
allocate: (id: import("../types/contracts.js").DocId, body: import("../types/endpoints.js").AllocateBody, options?: {
|
|
@@ -3,7 +3,7 @@ import type { DocId, ResolvedOptions } from '../types/contracts.js';
|
|
|
3
3
|
import type { AddMetricBody, AddMetricWarning } from '../types/endpoints.js';
|
|
4
4
|
export declare function addMetric<TUser extends {
|
|
5
5
|
id: DocId;
|
|
6
|
-
}>(req: PayloadRequest, { experimentId, metric, role, options }: AddMetricBody & {
|
|
6
|
+
}>(req: PayloadRequest, { experimentId, metric, role, phase: expectedPhase, options }: AddMetricBody & {
|
|
7
7
|
experimentId: DocId;
|
|
8
8
|
options: ResolvedOptions<TUser>;
|
|
9
9
|
}): Promise<{
|
|
@@ -6,9 +6,12 @@ import { relationshipId } from './checkStart.js';
|
|
|
6
6
|
import { withTransition } from './kernel.js';
|
|
7
7
|
import { readExperiment, refuse, updateExperiment } from './start.js';
|
|
8
8
|
import { resolveCaps } from './resolveCaps.js';
|
|
9
|
-
|
|
9
|
+
import { requireCurrentRound } from './phaseRecord.js';
|
|
10
|
+
export async function addMetric(req, { experimentId, metric, role, phase: expectedPhase, options }) {
|
|
10
11
|
if (role !== 'secondary' && role !== 'guardrail') refuse('invalid-body');
|
|
11
12
|
const before = await readExperiment(req, experimentId);
|
|
13
|
+
const openedPhase = before.phase;
|
|
14
|
+
requireCurrentRound(expectedPhase, openedPhase);
|
|
12
15
|
if (before.status !== 'running') refuse('invalid-status');
|
|
13
16
|
const found = await req.payload.find({
|
|
14
17
|
collection: 'xp-metrics',
|
|
@@ -62,6 +65,7 @@ export async function addMetric(req, { experimentId, metric, role, options }) {
|
|
|
62
65
|
bump: false
|
|
63
66
|
}, async ({ req, exec })=>{
|
|
64
67
|
const current = await readExperiment(req, experimentId);
|
|
68
|
+
requireCurrentRound(expectedPhase ?? openedPhase, current.phase);
|
|
65
69
|
if (current.status !== 'running') refuse('invalid-status');
|
|
66
70
|
const ids = [
|
|
67
71
|
current.metrics?.primary,
|
|
@@ -11,6 +11,8 @@ export interface TransitionScope {
|
|
|
11
11
|
audit?: boolean;
|
|
12
12
|
/** Trusted server-side Start must commit its own transaction. Preflight passes the request to host callbacks. */
|
|
13
13
|
requireOwnedTransaction?: boolean;
|
|
14
|
+
/** Guard an ordinary access-checked edit without bypassing the collection's lock hook. */
|
|
15
|
+
edit?: boolean;
|
|
14
16
|
excludeIds?: DocId[];
|
|
15
17
|
}
|
|
16
18
|
/** Runs transition writes on the request's transaction under ordered locks.
|
|
@@ -30,7 +30,7 @@ import { buildAndStoreManifest } from '../manifest/compile.js';
|
|
|
30
30
|
const exec = txExecutor(req);
|
|
31
31
|
const work = async ()=>{
|
|
32
32
|
if (!owns) await assertReadCommitted(req);
|
|
33
|
-
req.context.xpTransition = true;
|
|
33
|
+
if (!scope.edit) req.context.xpTransition = true;
|
|
34
34
|
await lockTransitionScope(exec, scope);
|
|
35
35
|
return fn({
|
|
36
36
|
exec,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
import type { ExperimentsPageCollection } from '../types/contracts.js';
|
|
3
|
+
export declare const PAGE_ADDRESS_FIELDS: string[];
|
|
4
|
+
/** Hosts can resolve drafts in findByPath. For simple addresses, the admin also
|
|
5
|
+
* recognizes never-published drafts when a host lookup only sees live pages. */
|
|
6
|
+
export declare function findDraftPageByPath(req: PayloadRequest, entry: ExperimentsPageCollection, path: string): Promise<(import("payload").JsonObject & import("payload").TypeWithID) | undefined>;
|