@delmaredigital/payload-experiments 0.4.0-rc.2 → 0.4.0-rc.4
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 +283 -775
- package/dist/admin/LayerUsage.js +1 -1
- package/dist/admin/MetricSourceSelect.js +2 -2
- package/dist/admin/PlacementStatus.js +1 -1
- package/dist/admin/TestsDashboardCards.js +2 -2
- package/dist/admin/TestsNavLink.js +2 -2
- package/dist/admin/blocks/BlockPanel.js +3 -3
- package/dist/admin/blocks/TestBlockField.js +3 -3
- package/dist/admin/blocks/formApi.js +1 -1
- package/dist/admin/blocks/model.js +1 -1
- package/dist/admin/blocks/statusCache.js +1 -1
- package/dist/admin/components/RootViewMessage.js +1 -1
- package/dist/admin/copy/blocks.d.ts +2 -2
- package/dist/admin/copy/blocks.js +3 -2
- package/dist/admin/copy/goals.d.ts +6 -1
- package/dist/admin/copy/goals.js +10 -3
- package/dist/admin/goals/XpGoalField.js +155 -129
- package/dist/admin/goals/xpGoalField.css +2 -3
- package/dist/admin/status.model.js +1 -1
- package/dist/admin/surface/ResultsRoute.d.ts +2 -1
- package/dist/admin/surface/ResultsRoute.js +4 -3
- package/dist/admin/surface/SurfaceShell.js +2 -2
- package/dist/admin/surface/TestsHome.d.ts +1 -1
- package/dist/admin/surface/TestsHome.js +3 -3
- package/dist/admin/surface/TestsSurface.js +2 -2
- package/dist/admin/surface/goals/GoalForm.d.ts +1 -1
- package/dist/admin/surface/goals/GoalForm.js +69 -15
- package/dist/admin/surface/goals/GoalsList.d.ts +1 -1
- package/dist/admin/surface/goals/GoalsList.js +4 -4
- package/dist/admin/surface/goals/data.js +2 -2
- package/dist/admin/surface/goals/goals.css +7 -0
- package/dist/admin/surface/goals/goals.model.d.ts +11 -1
- package/dist/admin/surface/goals/goals.model.js +43 -0
- package/dist/admin/surface/home.model.d.ts +1 -1
- package/dist/admin/surface/home.model.js +5 -5
- package/dist/admin/surface/newTest/NewTest.d.ts +1 -1
- package/dist/admin/surface/newTest/NewTest.js +1 -1
- package/dist/admin/surface/newTest/PageWizard.d.ts +1 -1
- package/dist/admin/surface/newTest/PageWizard.js +13 -13
- package/dist/admin/surface/results/ResultsHeader.d.ts +2 -2
- package/dist/admin/surface/results/ResultsHeader.js +8 -8
- package/dist/admin/surface/test/TestPage.d.ts +1 -2
- package/dist/admin/surface/test/TestPage.js +45 -156
- package/dist/admin/views/ExperimentsRootView.js +1 -1
- package/dist/admin/views/TestsNavLinkServer.js +1 -1
- package/dist/admin/views/renderCollectionList.js +1 -1
- package/dist/admin/views/renderTestsSurface.js +1 -1
- package/dist/blocks/placementLocale.d.ts +21 -0
- package/dist/blocks/placementLocale.js +115 -0
- package/dist/collections/experiments/config.js +1 -1
- package/dist/collections/metrics.js +1 -1
- package/dist/db/bulkPlacementRemoval.d.ts +30 -0
- package/dist/db/bulkPlacementRemoval.js +107 -0
- package/dist/db/placements.d.ts +2 -0
- package/dist/db/placements.js +8 -0
- package/dist/endpoints/editorSurface.d.ts +3 -0
- package/dist/endpoints/editorSurface.js +31 -0
- package/dist/endpoints/index.js +28 -1
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fields/xpGoal.js +1 -1
- package/dist/goals/picker/clickGoalPicker.model.d.ts +8 -1
- package/dist/goals/picker/clickGoalPicker.model.js +20 -2
- package/dist/goals/picker/copy.d.ts +6 -2
- package/dist/goals/picker/copy.js +11 -2
- package/dist/goals/picker/useClickGoalPicker.d.ts +1 -1
- package/dist/goals/picker/useClickGoalPicker.js +4 -2
- package/dist/goals/validate.js +3 -2
- package/dist/hooks/blockRemovalRule.d.ts +29 -0
- package/dist/hooks/blockRemovalRule.js +141 -0
- package/dist/hooks/pageGuard.d.ts +24 -2
- package/dist/hooks/pageGuard.js +178 -24
- package/dist/hooks/puckGoals.d.ts +2 -0
- package/dist/hooks/puckGoals.js +34 -10
- package/dist/lib/placementPages.d.ts +9 -0
- package/dist/{admin/previewLinks.model.js → lib/placementPages.js} +1 -4
- package/dist/onInit.js +22 -0
- package/dist/plugin.js +2 -1
- package/dist/puck/ExperimentPicker.js +25 -10
- package/dist/puck/copy.d.ts +4 -1
- package/dist/puck/copy.js +4 -1
- package/dist/puck/editor/ConfigureTestDrawer.d.ts +21 -0
- package/dist/puck/editor/ConfigureTestDrawer.js +147 -0
- package/dist/puck/editor/CreateExperimentDrawer.d.ts +11 -2
- package/dist/puck/editor/CreateExperimentDrawer.js +69 -9
- package/dist/puck/editor/EditorControls.d.ts +14 -0
- package/dist/puck/editor/EditorControls.js +99 -0
- package/dist/puck/editor/ExperimentSlotEditor.js +317 -51
- package/dist/puck/editor/ResultsReadout.js +3 -5
- package/dist/puck/editor/VersionBuilder.js +2 -2
- package/dist/puck/editor/armsCache.d.ts +3 -1
- package/dist/puck/editor/armsCache.js +20 -3
- package/dist/puck/editor/copy.d.ts +18 -2
- package/dist/puck/editor/copy.js +19 -3
- package/dist/puck/editor/editor.chrome.css +33 -0
- package/dist/puck/editor/editor.css +39 -0
- package/dist/puck/editor/editor.model.d.ts +14 -0
- package/dist/puck/editor/editor.model.js +58 -1
- package/dist/puck/editor/editorSurface.d.ts +10 -0
- package/dist/puck/editor/editorSurface.js +65 -0
- package/dist/puck/editor/localPlacements.d.ts +2 -0
- package/dist/puck/editor/localPlacements.js +29 -0
- package/dist/puck/editor/placementsCache.d.ts +19 -0
- package/dist/puck/editor/placementsCache.js +83 -0
- package/dist/puck/editor/xpGoalPuckEditorField.js +109 -98
- package/dist/puck/experimentSlotField.d.ts +3 -0
- package/dist/puck/experimentSlotField.js +15 -4
- package/dist/{admin → testSurface}/actions/DecideDialog.d.ts +2 -1
- package/dist/{admin → testSurface}/actions/DecideDialog.js +6 -4
- package/dist/{admin → testSurface}/api.js +4 -5
- package/dist/{admin → testSurface}/copy/common.d.ts +2 -0
- package/dist/{admin → testSurface}/copy/common.js +2 -0
- package/dist/{admin → testSurface}/copy/readiness.d.ts +3 -0
- package/dist/{admin → testSurface}/copy/readiness.js +3 -0
- package/dist/{admin → testSurface}/copy/testPage.d.ts +3 -0
- package/dist/{admin → testSurface}/copy/testPage.js +7 -2
- package/dist/testSurface/format/adminURL.d.ts +7 -0
- package/dist/testSurface/format/adminURL.js +9 -0
- package/dist/{admin → testSurface}/placements/placementLabels.js +1 -1
- package/dist/{admin → testSurface}/previewLinks.model.d.ts +1 -6
- package/dist/testSurface/previewLinks.model.js +4 -0
- package/dist/testSurface/results/results.css +64 -0
- package/dist/{admin → testSurface}/surface/contracts.d.ts +1 -0
- package/dist/{admin → testSurface}/surface/pageBlock/parts.js +6 -6
- package/dist/testSurface/surface/pagePicker/pagePicker.css +10 -0
- package/dist/{admin → testSurface}/surface/readiness/useTransition.js +1 -0
- package/dist/{admin → testSurface}/surface/results/ResultsBody.d.ts +2 -2
- package/dist/{admin → testSurface}/surface/results/ResultsBody.js +18 -11
- package/dist/testSurface/surface/setting/setting.css +17 -0
- package/dist/testSurface/surface/test/GoalSection.d.ts +4 -0
- package/dist/{admin → testSurface}/surface/test/GoalSection.js +3 -2
- package/dist/{admin → testSurface}/surface/test/Section.js +9 -8
- package/dist/testSurface/surface/test/TestSurface.d.ts +18 -0
- package/dist/testSurface/surface/test/TestSurface.js +152 -0
- package/dist/testSurface/surface/test/VersionsSection.d.ts +5 -0
- package/dist/{admin → testSurface}/surface/test/VersionsSection.js +12 -6
- package/dist/testSurface/surface/test/testPage.css +92 -0
- package/dist/{admin → testSurface}/surface/useTestDocument.d.ts +5 -1
- package/dist/{admin → testSurface}/surface/useTestDocument.js +34 -3
- package/dist/{admin → testSurface}/surfaceUrls.js +1 -1
- package/dist/transitions/placementInteractions.js +1 -1
- package/dist/transitions/placements.d.ts +27 -8
- package/dist/transitions/placements.js +77 -6
- package/dist/transitions/start.js +2 -2
- package/dist/types/endpoints.d.ts +1 -1
- package/dist/ui/Dialog.d.ts +4 -1
- package/dist/ui/Dialog.js +41 -3
- package/dist/ui/Drawer.d.ts +10 -0
- package/dist/ui/Drawer.js +29 -0
- package/dist/ui/Tabs.d.ts +3 -3
- package/dist/ui/Tabs.js +35 -33
- package/dist/ui/ui.css +6 -0
- package/package.json +1 -1
- package/dist/admin/actions/ConfirmDialog.d.ts +0 -19
- package/dist/admin/actions/ConfirmDialog.js +0 -149
- package/dist/admin/results/results.css +0 -64
- package/dist/admin/styles.css +0 -10
- package/dist/admin/styles.d.ts +0 -2
- package/dist/admin/styles.js +0 -3
- package/dist/admin/surface/pagePicker/pagePicker.css +0 -10
- package/dist/admin/surface/setting/setting.css +0 -17
- package/dist/admin/surface/test/GoalSection.d.ts +0 -2
- package/dist/admin/surface/test/VersionsSection.d.ts +0 -4
- package/dist/admin/surface/test/testPage.css +0 -92
- /package/dist/{admin → testSurface}/PreviewLinks.d.ts +0 -0
- /package/dist/{admin → testSurface}/PreviewLinks.js +0 -0
- /package/dist/{admin → testSurface}/actions/MakeContentResult.d.ts +0 -0
- /package/dist/{admin → testSurface}/actions/MakeContentResult.js +0 -0
- /package/dist/{admin → testSurface}/actions/actions.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/actions/actions.model.js +0 -0
- /package/dist/{admin → testSurface}/actions/decide.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/actions/decide.model.js +0 -0
- /package/dist/{admin → testSurface}/allocation.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/allocation.model.js +0 -0
- /package/dist/{admin → testSurface}/api.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/arms.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/arms.model.js +0 -0
- /package/dist/{admin → testSurface}/arms/pageTarget.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/pageTarget.model.js +0 -0
- /package/dist/{admin → testSurface}/arms/params.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/arms/params.model.js +0 -0
- /package/dist/{admin → testSurface}/copy/actions.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/actions.js +0 -0
- /package/dist/{admin → testSurface}/copy/advanced.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/advanced.js +0 -0
- /package/dist/{admin → testSurface}/copy/arms.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/arms.js +0 -0
- /package/dist/{admin → testSurface}/copy/audience.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/audience.js +0 -0
- /package/dist/{admin → testSurface}/copy/metrics.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/metrics.js +0 -0
- /package/dist/{admin → testSurface}/copy/pages.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/pages.js +0 -0
- /package/dist/{admin → testSurface}/copy/recommendation.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/recommendation.js +0 -0
- /package/dist/{admin → testSurface}/copy/results.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/results.js +0 -0
- /package/dist/{admin → testSurface}/copy/review.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/review.js +0 -0
- /package/dist/{admin → testSurface}/copy/setting.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/setting.js +0 -0
- /package/dist/{admin → testSurface}/copy/surface.d.ts +0 -0
- /package/dist/{admin → testSurface}/copy/surface.js +0 -0
- /package/dist/{admin → testSurface}/format/date.d.ts +0 -0
- /package/dist/{admin → testSurface}/format/date.js +0 -0
- /package/dist/{admin → testSurface}/labels.d.ts +0 -0
- /package/dist/{admin → testSurface}/labels.js +0 -0
- /package/dist/{admin → testSurface}/lockedNotice.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/lockedNotice.model.js +0 -0
- /package/dist/{admin → testSurface}/metricSource.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/metricSource.model.js +0 -0
- /package/dist/{admin → testSurface}/placements/placementLabels.d.ts +0 -0
- /package/dist/{admin → testSurface}/placements/placementLabels.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/placements/placementLabels.model.js +0 -0
- /package/dist/{admin → testSurface}/placements/usePlacementLabels.d.ts +0 -0
- /package/dist/{admin → testSurface}/placements/usePlacementLabels.js +0 -0
- /package/dist/{admin → testSurface}/reload.d.ts +0 -0
- /package/dist/{admin → testSurface}/reload.js +0 -0
- /package/dist/{admin → testSurface}/results/CappedCell.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/CappedCell.js +0 -0
- /package/dist/{admin → testSurface}/results/CiChart.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/CiChart.js +0 -0
- /package/dist/{admin → testSurface}/results/DataQualityPanel.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/DataQualityPanel.js +0 -0
- /package/dist/{admin → testSurface}/results/DataTable.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/DataTable.js +0 -0
- /package/dist/{admin → testSurface}/results/StatTile.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/StatTile.js +0 -0
- /package/dist/{admin → testSurface}/results/VerdictHero.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/VerdictHero.js +0 -0
- /package/dist/{admin → testSurface}/results/chart.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/chart.model.js +0 -0
- /package/dist/{admin → testSurface}/results/format.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/format.js +0 -0
- /package/dist/{admin → testSurface}/results/legacy.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/legacy.js +0 -0
- /package/dist/{admin → testSurface}/results/releasePages.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/releasePages.model.js +0 -0
- /package/dist/{admin → testSurface}/results/results.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/results.model.js +0 -0
- /package/dist/{admin → testSurface}/results/snapshot.d.ts +0 -0
- /package/dist/{admin → testSurface}/results/snapshot.js +0 -0
- /package/dist/{admin → testSurface}/review/review.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/review/review.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/contracts.js +0 -0
- /package/dist/{admin → testSurface}/surface/pageBlock/pageBlock.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pageBlock/pageBlock.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/pageBlock/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/CopyRoute.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/CopyRoute.js +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/PageCombobox.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/PageCombobox.js +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/pagePicker.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/pagePicker/pagePicker.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/ActionDialogs.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/ActionDialogs.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/Banner.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/Banner.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/SaveStatus.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/SaveStatus.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/parts.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/readiness.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/readiness.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/readiness/useTransition.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/ReleasePages.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/ReleasePages.js +0 -0
- /package/dist/{admin → testSurface}/surface/results/recommendation.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/recommendation.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/results/useResults.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/results/useResults.js +0 -0
- /package/dist/{admin → testSurface}/surface/setting/parts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/setting/parts.js +0 -0
- /package/dist/{admin → testSurface}/surface/setting/setting.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/setting/setting.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/AdvancedSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/AdvancedSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/LengthSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/LengthSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/PageHoldout.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/PageHoldout.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/Rail.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/Rail.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/ReadinessBar.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/ReadinessBar.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/Section.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/TargetingSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/TargetingSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/fields.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/fields.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/jumpToSection.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/jumpToSection.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/pageParts.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/pageParts.js +0 -0
- /package/dist/{admin → testSurface}/surface/test/testPage.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/test/testPage.model.js +0 -0
- /package/dist/{admin → testSurface}/surface/testDocument.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/surface/testDocument.model.js +0 -0
- /package/dist/{admin → testSurface}/surfaceUrls.d.ts +0 -0
- /package/dist/{admin → testSurface}/targeting/targeting.model.d.ts +0 -0
- /package/dist/{admin → testSurface}/targeting/targeting.model.js +0 -0
- /package/dist/{admin → testSurface}/theme.d.ts +0 -0
- /package/dist/{admin → testSurface}/theme.js +0 -0
- /package/dist/{admin → testSurface}/useApi.d.ts +0 -0
- /package/dist/{admin → testSurface}/useApi.js +0 -0
package/dist/hooks/pageGuard.js
CHANGED
|
@@ -1,37 +1,161 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
1
2
|
import { previousPublishedContent, storedContent } from '../db/appends.js';
|
|
2
3
|
import { lockPlacementScope, sortLockKeys } from '../db/locks.js';
|
|
3
4
|
import { txExecutor, pooledExecutor } from '../db/executor.js';
|
|
4
5
|
import { normalisePath } from '../runtime/normalisePath.js';
|
|
5
6
|
import { XpNoTransactionError, XpRefusal } from '../errors.js';
|
|
6
|
-
import { placementGuardCopy, pageGuardCopy, READINESS_COPY } from '../
|
|
7
|
+
import { placementGuardCopy, pageGuardCopy, READINESS_COPY } from '../testSurface/copy/readiness.js';
|
|
7
8
|
import { placementSlugs } from '../blocks/bindings.js';
|
|
8
9
|
import { isObject } from '../blocks/model.js';
|
|
9
|
-
import { placementTests, appendPlacementDoc } from '../db/placements.js';
|
|
10
|
+
import { placementTests, removableBlockTests, appendPlacementDoc } from '../db/placements.js';
|
|
10
11
|
import { isPageBusy } from '../db/pageBusy.js';
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
import { blockRemovalRule, releaseRemovalClaim, observeUnpublishedRemoval, releaseRestoredRemovalClaims } from './blockRemovalRule.js';
|
|
13
|
+
import { bulkPlacementRequest, placementOperationRequest, usesBulkDocumentTransactions } from '../db/bulkPlacementRemoval.js';
|
|
14
|
+
const operationIdentity = Symbol('xpPlacementOperation');
|
|
15
|
+
// Execution-local identity survives both concurrent bulk siblings and Payload's
|
|
16
|
+
// restoreVersion operation, which caches req before beforeOperation runs.
|
|
17
|
+
export const pageGuardOperationScope = new AsyncLocalStorage();
|
|
18
|
+
const entryIsFirst = (config)=>!config?.hooks?.beforeOperation || config.hooks.beforeOperation[0] === pageGuardEnterOperation;
|
|
13
19
|
const operations = (req)=>req.context.xpPageGuardOperations;
|
|
20
|
+
const requestFrame = (req)=>req[operationIdentity];
|
|
21
|
+
const operationFrame = (req, slug)=>{
|
|
22
|
+
const ordered = entryIsFirst(req.payload.config.collections?.find((c)=>c.slug === slug));
|
|
23
|
+
const own = requestFrame(req);
|
|
24
|
+
// With broken entry order, only this operation's returned token can prove a
|
|
25
|
+
// draft save. Restore bypasses that token on its cached request; Payload sets
|
|
26
|
+
// this sticky marker there before beforeChange (restoreVersion.js:162). Any
|
|
27
|
+
// ambiguity runs the rule: it may refuse, but must never borrow a draft save.
|
|
28
|
+
if (!ordered) return !req.context.isRestoringVersion && own?.collection === slug && !own.restore && !own.complete ? own : undefined;
|
|
29
|
+
let frame = pageGuardOperationScope.getStore();
|
|
30
|
+
while(frame && (frame.complete || frame.detached))frame = frame.parent;
|
|
31
|
+
// The request token wins when a preceding hook breaks async entry propagation.
|
|
32
|
+
// Restore alone caches the original request before beforeOperation; accept its
|
|
33
|
+
// execution identity only when the request belongs to its ancestor operation.
|
|
34
|
+
if (own) {
|
|
35
|
+
if (frame?.scoped && frame.restore && frame.collection === slug && frame !== own) {
|
|
36
|
+
let parent = frame.parent;
|
|
37
|
+
while(parent && parent !== own)parent = parent.parent;
|
|
38
|
+
if (parent === own) return frame;
|
|
39
|
+
}
|
|
40
|
+
return own.collection === slug && !own.complete ? own : undefined;
|
|
41
|
+
}
|
|
42
|
+
return frame?.scoped && frame.collection === slug && (frame.restore || frame.request === req) ? frame : undefined;
|
|
43
|
+
};
|
|
44
|
+
/** Must be first: buildBeforeOperation invokes its first hook synchronously,
|
|
45
|
+
* before the operation registers its await continuation. Later host hooks may
|
|
46
|
+
* await nested operations; those keep separate async contexts. No IO here.
|
|
47
|
+
*/ export const pageGuardEnterOperation = ({ args, operation })=>{
|
|
48
|
+
if (operation !== 'create' && operation !== 'update' && operation !== 'restoreVersion' && operation !== 'delete') return;
|
|
49
|
+
const call = args;
|
|
50
|
+
if (!entryIsFirst(call.collection.config)) return;
|
|
51
|
+
pageGuardOperationScope.enterWith({
|
|
52
|
+
collection: call.collection.config.slug,
|
|
53
|
+
request: args.req,
|
|
54
|
+
draft: call.draft === true,
|
|
55
|
+
restore: operation === 'restoreVersion',
|
|
56
|
+
pending: true,
|
|
57
|
+
scoped: true,
|
|
58
|
+
parent: pageGuardOperationScope.getStore()
|
|
59
|
+
});
|
|
60
|
+
};
|
|
14
61
|
export const pageGuardBeforeOperation = ({ args, operation })=>{
|
|
15
|
-
|
|
62
|
+
const req = args.req;
|
|
63
|
+
req.context.xpPlacementRemovals ??= {
|
|
64
|
+
transaction: undefined,
|
|
65
|
+
tests: new Map()
|
|
66
|
+
};
|
|
67
|
+
if (operation !== 'create' && operation !== 'update' && operation !== 'restoreVersion' && operation !== 'delete') return;
|
|
16
68
|
const call = args;
|
|
17
69
|
let collections = operations(call.req);
|
|
18
70
|
if (!collections) call.req.context.xpPageGuardOperations = collections = new Map();
|
|
19
71
|
const slug = call.collection.config.slug;
|
|
20
72
|
const stack = collections.get(slug) ?? [];
|
|
21
|
-
|
|
73
|
+
const entered = pageGuardOperationScope.getStore();
|
|
74
|
+
const frame = entryIsFirst(call.collection.config) && entered?.pending && entered.collection === slug ? entered : {
|
|
75
|
+
collection: slug,
|
|
76
|
+
request: req,
|
|
77
|
+
draft: false,
|
|
78
|
+
restore: false
|
|
79
|
+
};
|
|
80
|
+
const isBulk = Boolean(call.where) && (operation === 'update' || operation === 'delete');
|
|
81
|
+
const bulk = frame.scoped && isBulk ? {
|
|
82
|
+
documents: new Set(),
|
|
83
|
+
refusals: new Map()
|
|
84
|
+
} : undefined;
|
|
85
|
+
Object.assign(frame, {
|
|
86
|
+
request: req,
|
|
22
87
|
draft: call.draft === true,
|
|
23
|
-
restore: operation === 'restoreVersion'
|
|
88
|
+
restore: operation === 'restoreVersion',
|
|
89
|
+
bulk,
|
|
90
|
+
pending: false
|
|
24
91
|
});
|
|
92
|
+
stack.push(frame);
|
|
25
93
|
collections.set(slug, stack);
|
|
94
|
+
const scoped = placementOperationRequest(req, new Map([
|
|
95
|
+
[
|
|
96
|
+
operationIdentity,
|
|
97
|
+
frame
|
|
98
|
+
]
|
|
99
|
+
]), ()=>{
|
|
100
|
+
// Only ordered execution identity can attribute a cached-request rollback
|
|
101
|
+
// to a restore. An unscoped stack entry may be a stale failed restore.
|
|
102
|
+
const executing = pageGuardOperationScope.getStore();
|
|
103
|
+
if (executing?.scoped && executing.restore && !executing.complete && !executing.detached && executing.collection === slug) {
|
|
104
|
+
let parent = executing.parent;
|
|
105
|
+
while(parent && parent !== frame)parent = parent.parent;
|
|
106
|
+
if (parent === frame) {
|
|
107
|
+
finishOperation(executing.request ?? req, executing);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Payload uses the same request for per-document completion and its outer
|
|
112
|
+
// catch. Always detach shared tracking; the exact request token alone keeps
|
|
113
|
+
// bulk policy/selection for later siblings until afterOperation completes it.
|
|
114
|
+
if (isBulk && usesBulkDocumentTransactions(req)) detachOperation(req, frame);
|
|
115
|
+
else finishOperation(req, frame);
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
...args,
|
|
119
|
+
req: bulk ? bulkPlacementRequest(scoped, slug, call.where, call.data, call.draft === true, operation === 'delete', bulk) : scoped
|
|
120
|
+
};
|
|
26
121
|
};
|
|
122
|
+
function detachOperation(req, frame) {
|
|
123
|
+
const collections = operations(req), stack = collections?.get(frame.collection);
|
|
124
|
+
const index = stack?.lastIndexOf(frame);
|
|
125
|
+
if (index != null && index >= 0) stack.splice(index, 1);
|
|
126
|
+
if (!stack?.length) collections?.delete(frame.collection);
|
|
127
|
+
frame.detached = true;
|
|
128
|
+
if (pageGuardOperationScope.getStore() === frame) pageGuardOperationScope.enterWith(frame.parent);
|
|
129
|
+
}
|
|
130
|
+
function finishOperation(req, frame) {
|
|
131
|
+
frame.complete = true;
|
|
132
|
+
detachOperation(req, frame);
|
|
133
|
+
}
|
|
134
|
+
// Collection afterError has no operation identity and is REST-only
|
|
135
|
+
// (Payload 3.90.2 utilities/routeError.js:69-78). Local API failures call
|
|
136
|
+
// killTransaction(args.req) (operations/update.js:362, delete.js:274), whose
|
|
137
|
+
// transactionID deletion is observed by the operation's request proxy above.
|
|
138
|
+
// Bulk transaction deletion detaches tracking; its request token keeps policy.
|
|
27
139
|
export const pageGuardAfterOperation = ({ req, collection, operation, result })=>{
|
|
140
|
+
// buildAfterOperation passes args.req, including the restore's returned token
|
|
141
|
+
// (Payload 3.90.2 utilities/buildAfterOperation.js:11). Never finish a caller's
|
|
142
|
+
// token as a fallback for an unidentified restore.
|
|
143
|
+
const own = requestFrame(req);
|
|
144
|
+
const identified = own?.collection === collection.slug && !own.complete ? own : operationFrame(req, collection.slug);
|
|
145
|
+
const frame = operation === 'restoreVersion' && !identified?.restore ? undefined : identified;
|
|
146
|
+
const bulk = frame?.bulk;
|
|
28
147
|
// beforeOperation reports by-id updates as 'update'; afterOperation reports 'updateByID'.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
148
|
+
const mutates = operation === 'create' || operation === 'update' || operation === 'updateByID' || operation === 'restoreVersion' || operation === 'delete' || operation === 'deleteByID';
|
|
149
|
+
// Bulk Local API errors are returned per document, without invoking afterError.
|
|
150
|
+
if (result && typeof result === 'object' && 'errors' in result && Array.isArray(result.errors)) {
|
|
151
|
+
const failed = result.errors.some((error)=>error && !bulk?.refusals.has(error.message));
|
|
152
|
+
if (failed && bulk) for (const error of result.errors){
|
|
153
|
+
const conservative = bulk.refusals.get(error?.message);
|
|
154
|
+
if (conservative) error.message = conservative;
|
|
155
|
+
}
|
|
156
|
+
for (const error of result.errors)if (error && error.id != null) releaseRemovalClaim(req, collection.slug, error.id);
|
|
34
157
|
}
|
|
158
|
+
if (mutates && frame) finishOperation(req, frame);
|
|
35
159
|
return result;
|
|
36
160
|
};
|
|
37
161
|
function optionsOf(req) {
|
|
@@ -58,9 +182,15 @@ const pathsOf = (req, collection, rows)=>{
|
|
|
58
182
|
}
|
|
59
183
|
return ids;
|
|
60
184
|
}
|
|
61
|
-
export function guardExperimentIds(tests, slugs, collection, paths, held, tags = new Set()) {
|
|
185
|
+
export function guardExperimentIds(tests, slugs, collection, paths, held, tags = new Set(), discovered = []) {
|
|
62
186
|
const excluded = new Set(Array.isArray(held) ? held.map(String) : []);
|
|
63
|
-
|
|
187
|
+
const ids = tests.filter((test)=>slugs.includes(test.slug) || tags.has(String(test.id)) || test.kind === 'page' && (!test.pageCollection || test.pageCollection === collection) && test.arms.some((a)=>typeof a.pageTarget === 'string' && paths.includes(normalisePath(a.pageTarget)))).map((test)=>String(test.id));
|
|
188
|
+
// A candidate may have committed after the broad audit discovery. Its indexed
|
|
189
|
+
// removal lookup must still contribute E, including when it is not running yet.
|
|
190
|
+
return sortLockKeys([
|
|
191
|
+
...ids,
|
|
192
|
+
...discovered.map(String)
|
|
193
|
+
].filter((id)=>!excluded.has(id)));
|
|
64
194
|
}
|
|
65
195
|
function protect(tests, path) {
|
|
66
196
|
for (const test of tests){
|
|
@@ -98,29 +228,43 @@ function mapBusy(error) {
|
|
|
98
228
|
throw error;
|
|
99
229
|
}
|
|
100
230
|
export const pageGuardBeforeDelete = async ({ req, id, collection })=>{
|
|
101
|
-
const page = registration(req, collection.slug);
|
|
102
|
-
if (!page) return;
|
|
103
231
|
try {
|
|
104
|
-
const
|
|
232
|
+
const page = registration(req, collection.slug);
|
|
233
|
+
// Keep the earlier page guard's baseline read and every refusal intact.
|
|
234
|
+
const published = page ? await previousPublishedContent(req, collection.slug, id) : await storedContent(req, collection.slug, id);
|
|
105
235
|
if (!published || published._status === 'draft') return;
|
|
106
236
|
const paths = pathsOf(req, collection.slug, [
|
|
107
237
|
published
|
|
108
238
|
]);
|
|
109
239
|
const exec = await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload);
|
|
110
|
-
let tests = await placementTests(exec);
|
|
111
|
-
|
|
112
|
-
|
|
240
|
+
let tests = page ? await placementTests(exec) : undefined;
|
|
241
|
+
const { views, affected } = await blockRemovalRule.prepare(req, collection.slug, collection.trash && published.deletedAt != null ? undefined : published, {}, true, exec, tests);
|
|
242
|
+
if (!page) {
|
|
243
|
+
if (!affected.length) return;
|
|
244
|
+
if (await req.transactionID != null) {
|
|
245
|
+
await lockPlacementScope(exec, guardExperimentIds([], [], collection.slug, [], req.context.xpHeldExperiments, new Set(), affected.map((test)=>test.id)), []);
|
|
246
|
+
tests = (await removableBlockTests(exec, affected.map((test)=>test.slug))).map((test)=>({
|
|
247
|
+
...test,
|
|
248
|
+
kind: 'block'
|
|
249
|
+
}));
|
|
250
|
+
} else tests = affected;
|
|
251
|
+
} else if (await req.transactionID != null) {
|
|
252
|
+
await lockPlacementScope(exec, guardExperimentIds(tests, placementSlugs(optionsOf(req), collection.slug, published), collection.slug, paths, req.context.xpHeldExperiments, taggedIds(published), affected.map((test)=>test.id)), paths);
|
|
113
253
|
tests = await placementTests(exec);
|
|
114
254
|
}
|
|
115
255
|
for (const path of paths)protect(tests.filter((t)=>!t.pageCollection || t.pageCollection === collection.slug), path);
|
|
256
|
+
if (affected.length) await blockRemovalRule.check(req, tests, affected, collection.slug, id, true, views, operationFrame(req, collection.slug)?.bulk);
|
|
116
257
|
} catch (error) {
|
|
117
258
|
mapBusy(error);
|
|
118
259
|
}
|
|
119
260
|
};
|
|
120
261
|
export const pageGuardBeforeChange = async ({ req, collection, originalDoc, operation, data })=>{
|
|
121
262
|
const drafts = Boolean(collection.versions && collection.versions.drafts);
|
|
122
|
-
const call =
|
|
123
|
-
if (drafts && call?.draft && (call.restore || data._status !== 'published'))
|
|
263
|
+
const call = operationFrame(req, collection.slug);
|
|
264
|
+
if (drafts && call?.draft && (call.restore || data._status !== 'published')) {
|
|
265
|
+
await blockRemovalRule.prepare(req, collection.slug, undefined, data, false);
|
|
266
|
+
return data;
|
|
267
|
+
}
|
|
124
268
|
const after = operation === 'create' ? data : {
|
|
125
269
|
...originalDoc,
|
|
126
270
|
...data
|
|
@@ -142,6 +286,8 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
142
286
|
]);
|
|
143
287
|
const exec = await req.transactionID != null ? txExecutor(req) : pooledExecutor(req.payload);
|
|
144
288
|
let tests = await placementTests(exec);
|
|
289
|
+
const trashing = Boolean(collection.trash && after.deletedAt != null);
|
|
290
|
+
const { views, affected } = await blockRemovalRule.prepare(req, collection.slug, collection.trash && before?.deletedAt != null ? undefined : before, after, trashing || drafts && after._status !== 'published', exec, tests);
|
|
145
291
|
const publishes = !drafts || after._status === 'published';
|
|
146
292
|
const noTransaction = ()=>{
|
|
147
293
|
if (publishes && tests.some((t)=>t.kind === 'block' && active(t) && afterSlugs.includes(t.slug))) throw new XpNoTransactionError('Save this page with transactions on.');
|
|
@@ -155,7 +301,7 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
155
301
|
], collection.slug, paths, req.context.xpHeldExperiments, taggedIds([
|
|
156
302
|
before,
|
|
157
303
|
after
|
|
158
|
-
])), paths);
|
|
304
|
+
]), affected.map((test)=>test.id)), paths);
|
|
159
305
|
tests = await placementTests(exec);
|
|
160
306
|
} catch (error) {
|
|
161
307
|
if (!(error instanceof XpNoTransactionError)) throw error;
|
|
@@ -173,26 +319,34 @@ export const pageGuardBeforeChange = async ({ req, collection, originalDoc, oper
|
|
|
173
319
|
if (old != null && (unpublishing || trashing || page.pathOf(after) !== old)) protect(tests.filter((t)=>!t.pageCollection || t.pageCollection === collection.slug), normalisePath(old));
|
|
174
320
|
}
|
|
175
321
|
if (publishes) refuseInteraction(tests, beforeSlugs, afterSlugs, beforePaths, afterPaths, collection.slug);
|
|
322
|
+
if (affected.length) await blockRemovalRule.check(req, tests, affected, collection.slug, originalDoc.id, trashing || drafts && after._status !== 'published', views, call?.bulk);
|
|
176
323
|
return data;
|
|
177
324
|
} catch (error) {
|
|
178
325
|
mapBusy(error);
|
|
179
326
|
}
|
|
180
327
|
};
|
|
181
328
|
/** Unwrapped: these writes must fail the publish closed, unlike the best-effort audit. */ export const pageGuardAfterChange = async ({ req, collection, doc })=>{
|
|
182
|
-
const call =
|
|
329
|
+
const call = operationFrame(req, collection.slug);
|
|
183
330
|
const drafts = Boolean(collection.versions && collection.versions.drafts);
|
|
331
|
+
if (!call?.draft && (drafts && doc._status !== 'published' || collection.trash && doc.deletedAt != null)) observeUnpublishedRemoval(req, collection.slug, doc.id);
|
|
184
332
|
if (drafts && (doc._status !== 'published' || call?.draft && call.restore)) return doc;
|
|
185
333
|
if (await req.transactionID == null) return doc;
|
|
186
334
|
try {
|
|
187
335
|
const stored = await storedContent(req, collection.slug, doc.id);
|
|
188
336
|
if (!stored) throw new Error('The saved placement row was not found.');
|
|
189
337
|
const slugs = placementSlugs(optionsOf(req), collection.slug, stored);
|
|
338
|
+
// A later publish in this transaction can restore an earlier removal. Only
|
|
339
|
+
// clear its claim once the stored published row actually contains the block.
|
|
340
|
+
const claims = req.context.xpPlacementRemovals;
|
|
190
341
|
const exec = txExecutor(req);
|
|
191
342
|
for (const test of (await placementTests(exec))){
|
|
192
343
|
if (test.kind === 'block' && active(test) && slugs.includes(test.slug)) await appendPlacementDoc(exec, test.id, test.phase, {
|
|
193
344
|
collection: collection.slug,
|
|
194
345
|
id: doc.id
|
|
195
346
|
});
|
|
347
|
+
if (test.kind === 'block' && claims && claims.transaction === await req.transactionID && stored._status !== 'draft' && stored.deletedAt == null) {
|
|
348
|
+
releaseRestoredRemovalClaims(req, collection.slug, stored, test);
|
|
349
|
+
}
|
|
196
350
|
}
|
|
197
351
|
return doc;
|
|
198
352
|
} catch (error) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { type CollectionBeforeChangeHook } from 'payload';
|
|
2
|
+
/** Host component labels are not passed to the plugin; display their type as words. */
|
|
3
|
+
export declare function puckBlockName(rawType: string): string;
|
|
2
4
|
/** Validate only the Puck JSON included in a publishing write. */
|
|
3
5
|
export declare function puckGoalsBeforeChange(field: string): CollectionBeforeChangeHook;
|
package/dist/hooks/puckGoals.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { ValidationError } from 'payload';
|
|
2
2
|
import { validateClickGoal } from '../goals/validate.js';
|
|
3
|
+
import { CLICK_KEY } from '../goals/key.js';
|
|
4
|
+
import { puckGoalRefusal } from '../goals/picker/copy.js';
|
|
5
|
+
/** Host component labels are not passed to the plugin; display their type as words. */ export function puckBlockName(rawType) {
|
|
6
|
+
// Cap before any regex: the type comes from saved page JSON and the first pattern backtracks on long capital runs.
|
|
7
|
+
const type = rawType.slice(0, 64);
|
|
8
|
+
const words = type.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2').replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/([A-Za-z])([0-9])/g, '$1 $2').replace(/[\s_-]+/g, ' ').trim();
|
|
9
|
+
return words ? words[0].toUpperCase() + words.slice(1) : 'Page';
|
|
10
|
+
}
|
|
3
11
|
/** Validate only the Puck JSON included in a publishing write. */ export function puckGoalsBeforeChange(field) {
|
|
4
12
|
return async function validatePuckGoals({ collection, data, originalDoc, req }) {
|
|
5
13
|
const drafts = Boolean(collection.versions && collection.versions.drafts);
|
|
@@ -15,24 +23,40 @@ import { validateClickGoal } from '../goals/validate.js';
|
|
|
15
23
|
}
|
|
16
24
|
}
|
|
17
25
|
const errors = [];
|
|
18
|
-
|
|
26
|
+
let first;
|
|
27
|
+
// Holds the raw component type; it is humanised once, for the first refusal only.
|
|
28
|
+
async function walk(value, path, block = '') {
|
|
19
29
|
if (!value || typeof value !== 'object') return;
|
|
30
|
+
const item = value;
|
|
31
|
+
if (typeof item.type === 'string' && item.props && typeof item.props === 'object' && !Array.isArray(item.props)) {
|
|
32
|
+
block = item.type;
|
|
33
|
+
}
|
|
20
34
|
for (const [key, prop] of Object.entries(value)){
|
|
21
35
|
const propPath = `${path}.${key}`;
|
|
22
36
|
if (key === 'xpGoal' && typeof prop === 'string') {
|
|
23
37
|
const result = await validateClickGoal(prop, req);
|
|
24
|
-
if (result !== true)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
if (result !== true) {
|
|
39
|
+
first ??= {
|
|
40
|
+
key: prop,
|
|
41
|
+
block
|
|
42
|
+
};
|
|
43
|
+
errors.push({
|
|
44
|
+
path: propPath,
|
|
45
|
+
message: result
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
} else await walk(prop, propPath, block);
|
|
29
49
|
}
|
|
30
50
|
}
|
|
31
51
|
await walk(value, field);
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
52
|
+
if (first) {
|
|
53
|
+
const error = new ValidationError({
|
|
54
|
+
collection: collection.slug,
|
|
55
|
+
errors
|
|
56
|
+
});
|
|
57
|
+
error.message = puckGoalRefusal(first.key, first.block ? puckBlockName(first.block) : 'Page', !CLICK_KEY.test(first.key), errors.length - 1);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
36
60
|
return data;
|
|
37
61
|
};
|
|
38
62
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PreflightResult } from '../types/endpoints.js';
|
|
2
|
+
type Placement = PreflightResult['placements'][number];
|
|
3
|
+
export type PreviewPage = Placement & {
|
|
4
|
+
key: string;
|
|
5
|
+
slotCount: number;
|
|
6
|
+
};
|
|
7
|
+
/** Preview URLs identify pages; counts use the most placements in any one version. */
|
|
8
|
+
export declare function placementPages(placements: readonly Placement[], flagPoint?: string): PreviewPage[];
|
|
9
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Preview URLs identify pages; counts use the most placements in any one version. */ export function
|
|
1
|
+
/** Preview URLs identify pages; counts use the most placements in any one version. */ export function placementPages(placements, flagPoint) {
|
|
2
2
|
const pages = new Map();
|
|
3
3
|
for (const [index, placement] of placements.entries()){
|
|
4
4
|
const key = `${placement.collection}\u0000${String(placement.id)}${placement.collection === flagPoint ? `\u0000${index}` : ''}`;
|
|
@@ -30,6 +30,3 @@
|
|
|
30
30
|
...pages.values()
|
|
31
31
|
].map(({ page })=>page);
|
|
32
32
|
}
|
|
33
|
-
/** Pages that offer something to do: a preview or an editor link. The section is hidden when none do. */ export function actionablePreviewPages(placements, flagPoint) {
|
|
34
|
-
return previewPages(placements, flagPoint).filter((page)=>page.url || page.editorUrl);
|
|
35
|
-
}
|
package/dist/onInit.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { puckCollections } from './options.js';
|
|
2
|
+
import { pageGuardEnterOperation } from './hooks/pageGuard.js';
|
|
1
3
|
import { findRegisteredBlocksField } from './blocks/formState.js';
|
|
2
4
|
import { EXPERIMENT_BLOCK_SLUG } from './blocks/model.js';
|
|
3
5
|
import { contentBlocks } from './transitions/contentFields.js';
|
|
@@ -23,6 +25,26 @@ function registeredPaths(fields, name, parent = []) {
|
|
|
23
25
|
}
|
|
24
26
|
export function createOnInit(options) {
|
|
25
27
|
return async (payload)=>{
|
|
28
|
+
const guarded = new Set([
|
|
29
|
+
...options.puck?.enabled ? puckCollections(options).map((c)=>c.slug) : [],
|
|
30
|
+
...(options.blocks?.collections ?? []).map((c)=>c.slug),
|
|
31
|
+
...(options.pages?.collections ?? []).map((c)=>c.slug)
|
|
32
|
+
]);
|
|
33
|
+
for (const collection of payload.config.collections ?? []){
|
|
34
|
+
if (!guarded.has(collection.slug)) continue;
|
|
35
|
+
// Page-only guards also read the raw main row's scalar _status when
|
|
36
|
+
// protecting unpublishes and restores; localized status breaks those too.
|
|
37
|
+
if (payload.config.localization && payload.config.experimental?.localizeStatus && collection.versions && collection.versions.drafts && collection.versions.drafts.localizeStatus) {
|
|
38
|
+
throw new Error(`Experiments collection ${collection.slug} does not support versions.drafts.localizeStatus. Use a shared publication status.`);
|
|
39
|
+
}
|
|
40
|
+
if (collection.hooks) {
|
|
41
|
+
const hooks = collection.hooks.beforeOperation ?? [];
|
|
42
|
+
collection.hooks.beforeOperation = [
|
|
43
|
+
pageGuardEnterOperation,
|
|
44
|
+
...hooks.filter((hook)=>hook !== pageGuardEnterOperation)
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
26
48
|
for (const registration of options.blocks?.collections ?? []){
|
|
27
49
|
const config = payload.config.collections.find((c)=>c.slug === registration.slug);
|
|
28
50
|
const found = findRegisteredBlocksField(config?.fields ?? [], registration.field);
|
package/dist/plugin.js
CHANGED
|
@@ -2,7 +2,7 @@ import { buildCollections } from './collections/index.js';
|
|
|
2
2
|
import { buildEndpoints } from './endpoints/index.js';
|
|
3
3
|
import { contentChangesBeforeHook, contentChangesHook } from './hooks/contentChanges.js';
|
|
4
4
|
import { puckGoalsBeforeChange } from './hooks/puckGoals.js';
|
|
5
|
-
import { pageGuardAfterChange, pageGuardAfterOperation, pageGuardBeforeChange, pageGuardBeforeDelete, pageGuardBeforeOperation } from './hooks/pageGuard.js';
|
|
5
|
+
import { pageGuardAfterChange, pageGuardAfterOperation, pageGuardEnterOperation, pageGuardBeforeChange, pageGuardBeforeDelete, pageGuardBeforeOperation } from './hooks/pageGuard.js';
|
|
6
6
|
import { createOnInit } from './onInit.js';
|
|
7
7
|
import { puckCollections, resolveOptions } from './options.js';
|
|
8
8
|
import { injectTestBlock } from './admin/blocks/inject.js';
|
|
@@ -84,6 +84,7 @@ export function createExperimentsPlugin(input) {
|
|
|
84
84
|
] : []
|
|
85
85
|
],
|
|
86
86
|
beforeOperation: [
|
|
87
|
+
pageGuardEnterOperation,
|
|
87
88
|
...collection.hooks?.beforeOperation ?? [],
|
|
88
89
|
pageGuardBeforeOperation
|
|
89
90
|
],
|
|
@@ -26,7 +26,7 @@ export function ExperimentPicker({ value, onChange }) {
|
|
|
26
26
|
});
|
|
27
27
|
if (!active) return;
|
|
28
28
|
if (!response.ok) {
|
|
29
|
-
setState(response.status === 403 ? 'forbidden' : 'error');
|
|
29
|
+
setState(response.status === 401 || response.status === 403 ? 'forbidden' : 'error');
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
setExperiments(response.docs.filter(isExperimentOption).sort((a, b)=>(Date.parse(b.updatedAt ?? '') || 0) - (Date.parse(a.updatedAt ?? '') || 0)));
|
|
@@ -46,6 +46,29 @@ export function ExperimentPicker({ value, onChange }) {
|
|
|
46
46
|
const selected = value ? String(value.id) : '';
|
|
47
47
|
const query = search.trim().toLocaleLowerCase('en-US');
|
|
48
48
|
const visible = experiments.filter((doc)=>String(doc.id) === selected || doc.name.toLocaleLowerCase('en-US').includes(query) || doc.slug.toLocaleLowerCase('en-US').includes(query));
|
|
49
|
+
if (state === 'loading') return /*#__PURE__*/ _jsxs("div", {
|
|
50
|
+
className: "xp-ui-field",
|
|
51
|
+
children: [
|
|
52
|
+
/*#__PURE__*/ _jsx("span", {
|
|
53
|
+
children: pickerCopy.label
|
|
54
|
+
}),
|
|
55
|
+
/*#__PURE__*/ _jsx("p", {
|
|
56
|
+
role: "status",
|
|
57
|
+
children: pickerCopy.loading
|
|
58
|
+
})
|
|
59
|
+
]
|
|
60
|
+
});
|
|
61
|
+
if (state === 'forbidden') return /*#__PURE__*/ _jsxs("div", {
|
|
62
|
+
className: "xp-ui-field",
|
|
63
|
+
children: [
|
|
64
|
+
/*#__PURE__*/ _jsx("span", {
|
|
65
|
+
children: pickerCopy.label
|
|
66
|
+
}),
|
|
67
|
+
/*#__PURE__*/ _jsx("p", {
|
|
68
|
+
children: value ? pickerCopy.forbidden : pickerCopy.forbiddenUnbound
|
|
69
|
+
})
|
|
70
|
+
]
|
|
71
|
+
});
|
|
49
72
|
return /*#__PURE__*/ _jsxs("div", {
|
|
50
73
|
className: "xp-ui-field",
|
|
51
74
|
children: [
|
|
@@ -73,7 +96,6 @@ export function ExperimentPicker({ value, onChange }) {
|
|
|
73
96
|
id: id,
|
|
74
97
|
className: "xp-ui-input xp-ui-select",
|
|
75
98
|
value: selected,
|
|
76
|
-
disabled: state === 'loading',
|
|
77
99
|
onChange: (event)=>{
|
|
78
100
|
const experiment = experiments.find((doc)=>String(doc.id) === event.currentTarget.value);
|
|
79
101
|
onChange(experiment ? {
|
|
@@ -100,14 +122,7 @@ export function ExperimentPicker({ value, onChange }) {
|
|
|
100
122
|
}, doc.id))
|
|
101
123
|
]
|
|
102
124
|
}),
|
|
103
|
-
state === '
|
|
104
|
-
className: "xp-ui-banner",
|
|
105
|
-
role: "status",
|
|
106
|
-
children: /*#__PURE__*/ _jsx("p", {
|
|
107
|
-
children: pickerCopy.loading
|
|
108
|
-
})
|
|
109
|
-
}) : null,
|
|
110
|
-
state === 'error' || state === 'forbidden' ? /*#__PURE__*/ _jsx("div", {
|
|
125
|
+
state === 'error' ? /*#__PURE__*/ _jsx("div", {
|
|
111
126
|
className: "xp-ui-banner xp-ui-banner--error",
|
|
112
127
|
role: "alert",
|
|
113
128
|
children: /*#__PURE__*/ _jsx("p", {
|
package/dist/puck/copy.d.ts
CHANGED
|
@@ -11,7 +11,10 @@ export declare const pickerCopy: {
|
|
|
11
11
|
readonly search: "Search tests";
|
|
12
12
|
readonly loading: "Loading tests…";
|
|
13
13
|
readonly error: "Couldn't load tests.";
|
|
14
|
-
readonly forbidden: "You
|
|
14
|
+
readonly forbidden: "You don't have access to this test. You can still edit its content.";
|
|
15
|
+
readonly forbiddenUnbound: "You don't have access to tests.";
|
|
16
|
+
readonly unavailable: "This test isn't available to you. You can still edit its content.";
|
|
17
|
+
readonly resultsOnly: "You can view this test's results.";
|
|
15
18
|
readonly statuses: {
|
|
16
19
|
readonly draft: "Draft";
|
|
17
20
|
readonly running: "Running";
|
package/dist/puck/copy.js
CHANGED
|
@@ -12,7 +12,10 @@ export const pickerCopy = {
|
|
|
12
12
|
search: 'Search tests',
|
|
13
13
|
loading: 'Loading tests…',
|
|
14
14
|
error: "Couldn't load tests.",
|
|
15
|
-
forbidden: "You
|
|
15
|
+
forbidden: "You don't have access to this test. You can still edit its content.",
|
|
16
|
+
forbiddenUnbound: "You don't have access to tests.",
|
|
17
|
+
unavailable: "This test isn't available to you. You can still edit its content.",
|
|
18
|
+
resultsOnly: "You can view this test's results.",
|
|
16
19
|
statuses: {
|
|
17
20
|
draft: 'Draft',
|
|
18
21
|
running: 'Running',
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DocId } from '../../types/contracts.js';
|
|
2
|
+
import type { resolvePuckRoutes } from '../routes.js';
|
|
3
|
+
import './editor.css';
|
|
4
|
+
export declare function ConfigureTestDrawer({ id, routes, onClose }: {
|
|
5
|
+
id: DocId;
|
|
6
|
+
routes: ReturnType<typeof resolvePuckRoutes>;
|
|
7
|
+
onClose: () => void;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
9
|
+
/** Separate document root, like the creation dialog: Puck has no ancestor handlers here. */
|
|
10
|
+
export declare function openConfigureTestDrawer(source: HTMLElement, routes: ReturnType<typeof resolvePuckRoutes>, id: DocId): {
|
|
11
|
+
close: () => void;
|
|
12
|
+
};
|
|
13
|
+
/** The canvas already has current permissions; use them without a second read. */
|
|
14
|
+
export declare function ConfigureTestControl({ id, routes }: {
|
|
15
|
+
id: DocId;
|
|
16
|
+
routes: ReturnType<typeof resolvePuckRoutes>;
|
|
17
|
+
}): import("react").JSX.Element;
|
|
18
|
+
export declare function ConfigureTestButton({ id, routes }: {
|
|
19
|
+
id: DocId;
|
|
20
|
+
routes: ReturnType<typeof resolvePuckRoutes>;
|
|
21
|
+
}): import("react").JSX.Element | null;
|