@delmaredigital/payload-experiments 0.4.1 → 0.5.0

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.
Files changed (290) hide show
  1. package/README.md +9 -5
  2. package/dist/admin/blocks/model.js +2 -0
  3. package/dist/admin/copy/blocks.d.ts +1 -0
  4. package/dist/admin/copy/blocks.js +1 -0
  5. package/dist/admin/copy/status.d.ts +3 -0
  6. package/dist/admin/copy/status.js +3 -0
  7. package/dist/admin/placementStatus.model.js +3 -0
  8. package/dist/admin/status.model.d.ts +3 -2
  9. package/dist/admin/status.model.js +9 -3
  10. package/dist/admin/surface/ResultsRoute.js +2 -1
  11. package/dist/admin/surface/TestsHome.d.ts +2 -1
  12. package/dist/admin/surface/TestsHome.js +31 -11
  13. package/dist/admin/surface/TestsSurface.js +4 -0
  14. package/dist/admin/surface/home.model.d.ts +11 -6
  15. package/dist/admin/surface/home.model.js +19 -8
  16. package/dist/admin/surface/newTest/PageWizard.js +13 -3
  17. package/dist/admin/surface/results/ResultsHeader.js +43 -9
  18. package/dist/admin/surface/test/TestPage.js +11 -1
  19. package/dist/admin/useLayerUsage.d.ts +1 -1
  20. package/dist/admin/views/buildSurfaceProps.js +3 -0
  21. package/dist/cohorts/build.d.ts +35 -0
  22. package/dist/cohorts/build.js +134 -0
  23. package/dist/cohorts/key.d.ts +12 -0
  24. package/dist/cohorts/key.js +15 -0
  25. package/dist/cohorts/maintenance.d.ts +10 -0
  26. package/dist/cohorts/maintenance.js +70 -0
  27. package/dist/cohorts/readiness.d.ts +30 -0
  28. package/dist/cohorts/readiness.js +54 -0
  29. package/dist/cohorts/readinessData.d.ts +29 -0
  30. package/dist/cohorts/readinessData.js +123 -0
  31. package/dist/cohorts/rule.d.ts +33 -0
  32. package/dist/cohorts/rule.js +50 -0
  33. package/dist/collections/cohortMembers.d.ts +4 -0
  34. package/dist/collections/cohortMembers.js +95 -0
  35. package/dist/collections/experiments/config.js +157 -7
  36. package/dist/collections/experiments/editability.js +10 -6
  37. package/dist/collections/experiments/lockHook.js +39 -20
  38. package/dist/collections/index.js +4 -1
  39. package/dist/collections/phases.js +4 -1
  40. package/dist/constants.d.ts +2 -0
  41. package/dist/constants.js +2 -0
  42. package/dist/db/adapter.d.ts +1 -1
  43. package/dist/db/adapter.js +14 -4
  44. package/dist/db/appends.js +1 -1
  45. package/dist/db/cohortMembership.d.ts +11 -0
  46. package/dist/db/cohortMembership.js +31 -0
  47. package/dist/db/cohortPool.d.ts +9 -0
  48. package/dist/db/cohortPool.js +53 -0
  49. package/dist/db/cohortTransactions.d.ts +3 -0
  50. package/dist/db/cohortTransactions.js +52 -0
  51. package/dist/db/cohorts.d.ts +72 -0
  52. package/dist/db/cohorts.js +280 -0
  53. package/dist/db/erase.d.ts +2 -0
  54. package/dist/db/erase.js +21 -2
  55. package/dist/db/events.d.ts +2 -0
  56. package/dist/db/events.js +8 -0
  57. package/dist/db/executor.d.ts +2 -0
  58. package/dist/db/executor.js +8 -0
  59. package/dist/db/locks.d.ts +7 -0
  60. package/dist/db/locks.js +13 -1
  61. package/dist/db/names.d.ts +95 -1
  62. package/dist/db/names.js +95 -1
  63. package/dist/db/occupancy.d.ts +21 -0
  64. package/dist/db/occupancy.js +46 -0
  65. package/dist/db/pageOccupancy.d.ts +4 -4
  66. package/dist/db/pageOccupancy.js +13 -10
  67. package/dist/db/pgExecutor.d.ts +4 -0
  68. package/dist/db/pgExecutor.js +1 -1
  69. package/dist/db/placements.js +1 -1
  70. package/dist/db/results.d.ts +5 -2
  71. package/dist/db/results.js +32 -5
  72. package/dist/db/slices.d.ts +9 -2
  73. package/dist/db/slices.js +15 -8
  74. package/dist/db/snapshots.d.ts +16 -1
  75. package/dist/db/snapshots.js +27 -2
  76. package/dist/db/sql.d.ts +2 -2
  77. package/dist/db/sql.js +1 -2
  78. package/dist/endpoints/cohortSources.d.ts +16 -0
  79. package/dist/endpoints/cohortSources.js +335 -0
  80. package/dist/endpoints/contentLocale.d.ts +1 -1
  81. package/dist/endpoints/events.js +82 -18
  82. package/dist/endpoints/index.js +45 -1
  83. package/dist/endpoints/pausedBy.d.ts +14 -0
  84. package/dist/endpoints/pausedBy.js +94 -0
  85. package/dist/endpoints/preflight.js +4 -1
  86. package/dist/endpoints/previewToken.js +2 -0
  87. package/dist/endpoints/results.d.ts +2 -2
  88. package/dist/endpoints/results.js +111 -3
  89. package/dist/endpoints/routeId.d.ts +2 -1
  90. package/dist/endpoints/routeId.js +6 -2
  91. package/dist/endpoints/summary.js +24 -1
  92. package/dist/endpoints/transitions.d.ts +7 -0
  93. package/dist/endpoints/transitions.js +50 -1
  94. package/dist/events/rows.d.ts +1 -1
  95. package/dist/events/rows.js +5 -3
  96. package/dist/exports/index.d.ts +2 -0
  97. package/dist/exports/index.js +1 -0
  98. package/dist/exports/runtimeProxy.d.ts +1 -0
  99. package/dist/exports/runtimeProxy.js +1 -0
  100. package/dist/hooks/blockRemovalRule.js +7 -4
  101. package/dist/hooks/pageGuard.js +1 -1
  102. package/dist/labels/status.d.ts +15 -0
  103. package/dist/labels/status.js +12 -0
  104. package/dist/manifest/compile.d.ts +15 -4
  105. package/dist/manifest/compile.js +91 -3
  106. package/dist/onInit.js +4 -1
  107. package/dist/options.d.ts +1 -0
  108. package/dist/options.js +10 -0
  109. package/dist/proxy/consentFallback.d.ts +1 -1
  110. package/dist/proxy/consentFallback.js +4 -4
  111. package/dist/proxy/control.d.ts +1 -1
  112. package/dist/proxy/control.js +2 -2
  113. package/dist/proxy/pageRewrite.d.ts +1 -1
  114. package/dist/proxy/pageRewrite.js +3 -2
  115. package/dist/proxy/resolve.js +76 -17
  116. package/dist/puck/ExperimentPicker.js +2 -1
  117. package/dist/puck/copy.d.ts +6 -5
  118. package/dist/puck/copy.js +3 -7
  119. package/dist/puck/editor/ExperimentSlotEditor.js +16 -5
  120. package/dist/puck/editor/QuickTestActions.js +7 -1
  121. package/dist/puck/editor/armWrites.js +6 -1
  122. package/dist/puck/editor/copy.d.ts +3 -0
  123. package/dist/puck/editor/copy.js +3 -0
  124. package/dist/puck/editor/editor.css +2 -1
  125. package/dist/puck/editor/editor.model.d.ts +2 -1
  126. package/dist/puck/editor/editor.model.js +2 -0
  127. package/dist/puck/editor/placementsCache.d.ts +1 -1
  128. package/dist/puck/editor/placementsCache.js +6 -3
  129. package/dist/results/analyse.d.ts +3 -1
  130. package/dist/results/analyse.js +20 -3
  131. package/dist/results/health.d.ts +11 -0
  132. package/dist/results/health.js +38 -0
  133. package/dist/results/power.d.ts +1 -1
  134. package/dist/results/power.js +1 -1
  135. package/dist/results/snapshot.d.ts +8 -2
  136. package/dist/results/snapshot.js +23 -1
  137. package/dist/results/unitValues.d.ts +48 -0
  138. package/dist/results/unitValues.js +166 -0
  139. package/dist/runtime/assign.d.ts +7 -3
  140. package/dist/runtime/assign.js +12 -4
  141. package/dist/runtime/cohortCookie.d.ts +15 -0
  142. package/dist/runtime/cohortCookie.js +72 -0
  143. package/dist/runtime/cohortLookup.d.ts +9 -0
  144. package/dist/runtime/cohortLookup.js +25 -0
  145. package/dist/runtime/eligibility.d.ts +11 -5
  146. package/dist/runtime/eligibility.js +33 -7
  147. package/dist/runtime/header.d.ts +1 -0
  148. package/dist/runtime/header.js +1 -1
  149. package/dist/runtime/proxyRuntime.js +5 -1
  150. package/dist/runtime/targeting.d.ts +3 -2
  151. package/dist/runtime/targeting.js +2 -1
  152. package/dist/sanitizeReadinessDetail.d.ts +2 -2
  153. package/dist/sanitizeReadinessDetail.js +41 -4
  154. package/dist/schedule/activeTime.d.ts +28 -0
  155. package/dist/schedule/activeTime.js +322 -0
  156. package/dist/schedule/ranges.d.ts +13 -0
  157. package/dist/schedule/ranges.js +11 -0
  158. package/dist/schedule/roundTime.d.ts +10 -0
  159. package/dist/schedule/roundTime.js +45 -0
  160. package/dist/schedule/types.d.ts +29 -0
  161. package/dist/schedule/types.js +1 -0
  162. package/dist/server/cohortLookup.d.ts +3 -0
  163. package/dist/server/cohortLookup.js +7 -0
  164. package/dist/server/eraseUser.d.ts +1 -0
  165. package/dist/server/getAssignments.js +63 -40
  166. package/dist/server/previewDraft.d.ts +1 -1
  167. package/dist/server/previewDraft.js +3 -2
  168. package/dist/server/recordExposures.js +4 -2
  169. package/dist/server/runResults.js +97 -150
  170. package/dist/testSurface/actions/LifecycleAction.d.ts +2 -1
  171. package/dist/testSurface/actions/LifecycleAction.js +15 -5
  172. package/dist/testSurface/actions/actions.model.d.ts +13 -2
  173. package/dist/testSurface/actions/actions.model.js +38 -5
  174. package/dist/testSurface/api.d.ts +13 -1
  175. package/dist/testSurface/api.js +19 -0
  176. package/dist/testSurface/copy/actions.d.ts +13 -0
  177. package/dist/testSurface/copy/actions.js +13 -0
  178. package/dist/testSurface/copy/cohorts.d.ts +68 -0
  179. package/dist/testSurface/copy/cohorts.js +81 -0
  180. package/dist/testSurface/copy/common.d.ts +2 -3
  181. package/dist/testSurface/copy/common.js +4 -4
  182. package/dist/testSurface/copy/inputs.d.ts +3 -0
  183. package/dist/testSurface/copy/inputs.js +3 -0
  184. package/dist/testSurface/copy/readiness.d.ts +20 -6
  185. package/dist/testSurface/copy/readiness.js +42 -9
  186. package/dist/testSurface/copy/results.d.ts +1 -0
  187. package/dist/testSurface/copy/results.js +1 -0
  188. package/dist/testSurface/copy/schedule.d.ts +58 -0
  189. package/dist/testSurface/copy/schedule.js +150 -0
  190. package/dist/testSurface/copy/surface.d.ts +2 -0
  191. package/dist/testSurface/copy/surface.js +2 -0
  192. package/dist/testSurface/copy/testPage.d.ts +12 -2
  193. package/dist/testSurface/copy/testPage.js +17 -2
  194. package/dist/testSurface/format/roundProgress.d.ts +13 -1
  195. package/dist/testSurface/format/roundProgress.js +34 -5
  196. package/dist/testSurface/format/scheduleStatus.d.ts +34 -0
  197. package/dist/testSurface/format/scheduleStatus.js +93 -0
  198. package/dist/testSurface/format/useScheduleClock.d.ts +3 -0
  199. package/dist/testSurface/format/useScheduleClock.js +20 -0
  200. package/dist/testSurface/labels.d.ts +4 -9
  201. package/dist/testSurface/labels.js +2 -7
  202. package/dist/testSurface/lockedNotice.model.d.ts +2 -2
  203. package/dist/testSurface/lockedNotice.model.js +16 -3
  204. package/dist/testSurface/readPreflight.d.ts +3 -0
  205. package/dist/testSurface/readPreflight.js +14 -0
  206. package/dist/testSurface/readinessRead.d.ts +2 -2
  207. package/dist/testSurface/results/DataQualityPanel.js +7 -7
  208. package/dist/testSurface/results/results.model.d.ts +1 -1
  209. package/dist/testSurface/results/results.model.js +34 -6
  210. package/dist/testSurface/review/cohortEstimate.d.ts +11 -0
  211. package/dist/testSurface/review/cohortEstimate.js +32 -0
  212. package/dist/testSurface/surface/contracts.d.ts +2 -1
  213. package/dist/testSurface/surface/contracts.js +1 -0
  214. package/dist/testSurface/surface/editorPlacement.d.ts +1 -0
  215. package/dist/testSurface/surface/readiness/ActionDialogs.d.ts +3 -2
  216. package/dist/testSurface/surface/readiness/ActionDialogs.js +121 -32
  217. package/dist/testSurface/surface/readiness/Banner.js +29 -11
  218. package/dist/testSurface/surface/readiness/readiness.model.d.ts +20 -2
  219. package/dist/testSurface/surface/readiness/readiness.model.js +35 -5
  220. package/dist/testSurface/surface/readiness/useTransition.js +17 -5
  221. package/dist/testSurface/surface/results/ResultsBody.js +44 -8
  222. package/dist/testSurface/surface/results/useResults.d.ts +16 -1
  223. package/dist/testSurface/surface/results/useResults.js +17 -6
  224. package/dist/testSurface/surface/test/CohortRuleEditor.d.ts +16 -0
  225. package/dist/testSurface/surface/test/CohortRuleEditor.js +492 -0
  226. package/dist/testSurface/surface/test/LengthSection.js +26 -6
  227. package/dist/testSurface/surface/test/ScheduleDateInput.d.ts +4 -0
  228. package/dist/testSurface/surface/test/ScheduleDateInput.js +15 -0
  229. package/dist/testSurface/surface/test/ScheduleSection.d.ts +2 -0
  230. package/dist/testSurface/surface/test/ScheduleSection.js +322 -0
  231. package/dist/testSurface/surface/test/Section.js +1 -1
  232. package/dist/testSurface/surface/test/TargetingSection.js +306 -182
  233. package/dist/testSurface/surface/test/TestSurface.js +9 -0
  234. package/dist/testSurface/surface/test/fields.d.ts +2 -1
  235. package/dist/testSurface/surface/test/fields.js +3 -3
  236. package/dist/testSurface/surface/test/jumpToSection.d.ts +1 -1
  237. package/dist/testSurface/surface/test/jumpToSection.js +4 -4
  238. package/dist/testSurface/surface/test/testPage.css +26 -0
  239. package/dist/testSurface/surface/testDocument.model.d.ts +12 -1
  240. package/dist/testSurface/surface/testDocument.model.js +2 -1
  241. package/dist/testSurface/surface/useTestDocument.js +11 -4
  242. package/dist/testSurface/targeting/targeting.model.d.ts +2 -1
  243. package/dist/testSurface/targeting/targeting.model.js +1 -1
  244. package/dist/testSurface/useApi.d.ts +12 -0
  245. package/dist/transitions/addMetric.js +5 -2
  246. package/dist/transitions/allocate.js +6 -1
  247. package/dist/transitions/assertNoOverlap.d.ts +9 -0
  248. package/dist/transitions/assertNoOverlap.js +24 -0
  249. package/dist/transitions/buildCohorts.d.ts +10 -0
  250. package/dist/transitions/buildCohorts.js +68 -0
  251. package/dist/transitions/cancelSchedule.d.ts +4 -0
  252. package/dist/transitions/cancelSchedule.js +42 -0
  253. package/dist/transitions/checkStart.d.ts +17 -3
  254. package/dist/transitions/checkStart.js +20 -7
  255. package/dist/transitions/decide.js +35 -11
  256. package/dist/transitions/kernel.d.ts +3 -1
  257. package/dist/transitions/kernel.js +5 -2
  258. package/dist/transitions/pause.d.ts +4 -0
  259. package/dist/transitions/pause.js +35 -0
  260. package/dist/transitions/phaseRecord.d.ts +19 -2
  261. package/dist/transitions/phaseRecord.js +50 -11
  262. package/dist/transitions/placementInteractions.js +1 -1
  263. package/dist/transitions/preflightData.d.ts +11 -3
  264. package/dist/transitions/preflightData.js +134 -81
  265. package/dist/transitions/reschedule.d.ts +4 -0
  266. package/dist/transitions/reschedule.js +58 -0
  267. package/dist/transitions/resume.d.ts +4 -0
  268. package/dist/transitions/resume.js +32 -0
  269. package/dist/transitions/scheduledRound.d.ts +18 -0
  270. package/dist/transitions/scheduledRound.js +42 -0
  271. package/dist/transitions/start.d.ts +4 -0
  272. package/dist/transitions/start.js +136 -55
  273. package/dist/transitions/startReads.d.ts +14 -0
  274. package/dist/transitions/startReads.js +27 -0
  275. package/dist/transitions/stop.d.ts +10 -0
  276. package/dist/transitions/stop.js +35 -22
  277. package/dist/types/admin.d.ts +1 -1
  278. package/dist/types/contracts.d.ts +7 -1
  279. package/dist/types/endpoints.d.ts +72 -3
  280. package/dist/types/manifest.d.ts +9 -0
  281. package/dist/types/runtime.d.ts +5 -0
  282. package/dist/types/snapshot.d.ts +10 -0
  283. package/dist/types/status.d.ts +1 -0
  284. package/dist/types/status.js +1 -0
  285. package/dist/types/surface.d.ts +1 -0
  286. package/dist/ui/Feedback.d.ts +9 -6
  287. package/dist/ui/Feedback.js +10 -9
  288. package/dist/ui/SelectControl.js +1 -1
  289. package/dist/ui/ui.css +2 -1
  290. package/package.json +2 -2
@@ -5,6 +5,9 @@ export declare function handleStart<TUser extends {
5
5
  } = {
6
6
  id: string | number;
7
7
  }>(req: PayloadRequest, ctx: EndpointContext<TUser>): Promise<Response>;
8
+ export declare function handleBuildCohorts<TUser extends {
9
+ id: string | number;
10
+ }>(req: PayloadRequest, ctx: EndpointContext<TUser>): Promise<Response>;
8
11
  export declare function handleAllocate<TUser extends {
9
12
  id: string | number;
10
13
  } = {
@@ -20,6 +23,10 @@ export declare function handleStop<TUser extends {
20
23
  } = {
21
24
  id: string | number;
22
25
  }>(req: PayloadRequest, _ctx: EndpointContext<TUser>): Promise<Response>;
26
+ export declare function handlePause(req: PayloadRequest): Promise<Response>;
27
+ export declare function handleResume(req: PayloadRequest): Promise<Response>;
28
+ export declare function handleReschedule(req: PayloadRequest): Promise<Response>;
29
+ export declare function handleCancelSchedule(req: PayloadRequest): Promise<Response>;
23
30
  export declare function handleDecide<TUser extends {
24
31
  id: string | number;
25
32
  } = {
@@ -1,8 +1,13 @@
1
+ import { buildCohortsNow } from '../transitions/buildCohorts.js';
1
2
  import { XpRefusal } from '../errors.js';
2
3
  import { start } from '../transitions/start.js';
3
4
  import { allocate } from '../transitions/allocate.js';
4
5
  import { addMetric } from '../transitions/addMetric.js';
5
6
  import { stop } from '../transitions/stop.js';
7
+ import { pauseExperiment } from '../transitions/pause.js';
8
+ import { resumeExperiment } from '../transitions/resume.js';
9
+ import { rescheduleExperiment } from '../transitions/reschedule.js';
10
+ import { cancelSchedule } from '../transitions/cancelSchedule.js';
6
11
  import { decide } from '../transitions/decide.js';
7
12
  import { releaseHoldout } from '../transitions/releaseHoldout.js';
8
13
  import { releasePages } from '../transitions/releasePages.js';
@@ -34,6 +39,15 @@ async function body(req) {
34
39
  }
35
40
  const only = (value, keys)=>Object.keys(value).every((key)=>keys.includes(key));
36
41
  const validPhase = (phase)=>phase === undefined || typeof phase === 'number' && Number.isSafeInteger(phase) && phase >= 0;
42
+ const conflictCodes = new Set([
43
+ 'round-changed',
44
+ 'cohort-build-timeout',
45
+ 'not-live',
46
+ 'not-pausable',
47
+ 'paused',
48
+ 'schedule-started',
49
+ 'occupied-in-range'
50
+ ]);
37
51
  async function respond(req, action) {
38
52
  const id = routeId(req);
39
53
  if (id === undefined) return Response.json({
@@ -64,7 +78,7 @@ async function respond(req, action) {
64
78
  }
65
79
  ]
66
80
  }, {
67
- status: cause.status === 409 && cause.code !== 'round-changed' ? 422 : cause.status
81
+ status: cause.status === 409 && !conflictCodes.has(cause.code) ? 422 : cause.status
68
82
  });
69
83
  throw cause;
70
84
  }
@@ -80,6 +94,11 @@ export async function handleStart(req, ctx) {
80
94
  options: ctx.options
81
95
  }));
82
96
  }
97
+ export async function handleBuildCohorts(req, ctx) {
98
+ const value = await body(req);
99
+ if (!value || !only(value, [])) return invalidBody();
100
+ return respond(req, (id)=>buildCohortsNow(req, id, ctx.options));
101
+ }
83
102
  export async function handleAllocate(req, _ctx) {
84
103
  const value = await body(req);
85
104
  if (!value || !only(value, [
@@ -114,6 +133,36 @@ export async function handleStop(req, _ctx) {
114
133
  experimentId: id
115
134
  }));
116
135
  }
136
+ export async function handlePause(req) {
137
+ const value = await body(req);
138
+ if (!value || !only(value, [
139
+ 'reason',
140
+ 'phase'
141
+ ]) || !validPhase(value.phase) || value.reason !== undefined && (typeof value.reason !== 'string' || value.reason.length > 500)) return invalidBody();
142
+ return respond(req, (id)=>pauseExperiment(req, id, value));
143
+ }
144
+ export async function handleResume(req) {
145
+ const value = await body(req);
146
+ if (!value || !only(value, [
147
+ 'phase'
148
+ ]) || !validPhase(value.phase)) return invalidBody();
149
+ return respond(req, (id)=>resumeExperiment(req, id, value));
150
+ }
151
+ export async function handleReschedule(req) {
152
+ const value = await body(req);
153
+ if (!value || !only(value, [
154
+ 'endAt',
155
+ 'phase'
156
+ ]) || !validPhase(value.phase) || value.endAt !== null && (typeof value.endAt !== 'string' || !Number.isFinite(Date.parse(value.endAt)))) return invalidBody();
157
+ return respond(req, (id)=>rescheduleExperiment(req, id, value));
158
+ }
159
+ export async function handleCancelSchedule(req) {
160
+ const value = await body(req);
161
+ if (!value || !only(value, [
162
+ 'phase'
163
+ ]) || !validPhase(value.phase)) return invalidBody();
164
+ return respond(req, (id)=>cancelSchedule(req, id, value));
165
+ }
117
166
  export async function handleDecide(req, _ctx) {
118
167
  const value = await body(req);
119
168
  if (!value || !only(value, [
@@ -4,4 +4,4 @@ import type { ResolvedOptions } from '../types/contracts.js';
4
4
  import type { Manifest } from '../types/manifest.js';
5
5
  export declare function eventRows<TUser extends {
6
6
  id: string | number;
7
- }>(events: unknown[], manifest: Manifest, assignments: AssignmentResult, options: ResolvedOptions<TUser>, visitorId: string | undefined, userId: string | undefined, ts: string, unitAgeMs: number | 'legacy' | null, requestAttributes?: Readonly<Record<string, unknown>>, clickKeys?: ReadonlySet<string>): EventRow[];
7
+ }>(events: unknown[], manifest: Manifest, assignments: AssignmentResult, options: ResolvedOptions<TUser>, visitorId: string | undefined, userId: string | undefined, ts: string, unitAgeMs: number | 'legacy' | null, requestAttributes?: Readonly<Record<string, unknown>>, clickKeys?: ReadonlySet<string>, cohortRejected?: ReadonlySet<string>): EventRow[];
@@ -12,7 +12,7 @@ function record(value) {
12
12
  return definition && typeof item === definition.type && (typeof item !== 'number' || Number.isFinite(item)) && (!definition.values || typeof item === 'string' && definition.values.includes(item));
13
13
  }));
14
14
  }
15
- export function eventRows(events, manifest, assignments, options, visitorId, userId, ts, unitAgeMs, requestAttributes = {}, clickKeys) {
15
+ export function eventRows(events, manifest, assignments, options, visitorId, userId, ts, unitAgeMs, requestAttributes = {}, clickKeys, cohortRejected) {
16
16
  const rows = new Map();
17
17
  const telemetry = {
18
18
  _xp: {
@@ -30,10 +30,12 @@ export function eventRows(events, manifest, assignments, options, visitorId, use
30
30
  ].includes(String(event.policy))) continue;
31
31
  const experiment = manifest.experiments.find((exp)=>exp.slug === event.experiment);
32
32
  const assigned = assignments.bySlug[event.experiment];
33
- if (!experiment || !assigned?.exposable || event.phase !== experiment.phase || event.policy !== experiment.exposurePolicy) continue;
33
+ if (!experiment || !assigned || event.phase !== experiment.phase || event.policy !== experiment.exposurePolicy) continue;
34
+ const mismatch = event.arm !== assigned.arm;
35
+ // A cohort rejection can diagnose a variant mismatch, but cannot record an exposure.
36
+ if (!assigned.exposable && !(mismatch && cohortRejected?.has(event.experiment) && !assignments.staff && !assignments.bot && !assignments.preview && assignments.method.toUpperCase() !== 'HEAD')) continue;
34
37
  const unitId = experiment.unitType === 'visitor' ? visitorId : userId;
35
38
  if (!unitId) continue;
36
- const mismatch = event.arm !== assigned.arm;
37
39
  row = {
38
40
  type: mismatch ? 'arm-mismatch' : 'exposure',
39
41
  experimentId: experiment.id,
@@ -1,4 +1,6 @@
1
+ export type { CohortRule, FrozenCohortRule } from '../cohorts/rule.js';
1
2
  export { createExperimentsPlugin } from '../plugin.js';
3
+ export { isValidTimeZone } from '../options.js';
2
4
  export { defineFlagPoint, defineMetricSource } from '../define.js';
3
5
  export { contentDone } from '../contentDone.js';
4
6
  export { createArmSelectField } from '../fields/armSelect.js';
@@ -1,4 +1,5 @@
1
1
  export { createExperimentsPlugin } from '../plugin.js';
2
+ export { isValidTimeZone } from '../options.js';
2
3
  export { defineFlagPoint, defineMetricSource } from '../define.js';
3
4
  export { contentDone } from '../contentDone.js';
4
5
  export { createArmSelectField } from '../fields/armSelect.js';
@@ -1,4 +1,5 @@
1
1
  export { defineExperimentsProxyRuntime } from '../runtime/proxyRuntime.js';
2
2
  export { createPostgresManifestLoader, createHttpManifestLoader } from '../runtime/loaders.js';
3
+ export { createPostgresCohortLookup, type CohortLookup } from '../runtime/cohortLookup.js';
3
4
  export type { ExperimentsProxyRuntime, ExperimentsProxyRuntimeOptions, Manifest } from '../types/index.js';
4
5
  export type { PostgresManifestLoaderOptions, HttpManifestLoaderOptions, ManifestLoader } from '../runtime/loaders.js';
@@ -1,2 +1,3 @@
1
1
  export { defineExperimentsProxyRuntime } from '../runtime/proxyRuntime.js';
2
2
  export { createPostgresManifestLoader, createHttpManifestLoader } from '../runtime/loaders.js';
3
+ export { createPostgresCohortLookup } from '../runtime/cohortLookup.js';
@@ -87,7 +87,8 @@ export const blockRemovalRule = {
87
87
  if (tests) return tests.filter((test)=>test.kind === 'block' && [
88
88
  'draft',
89
89
  'stopped',
90
- 'running'
90
+ 'running',
91
+ 'paused'
91
92
  ].includes(test.status) && removed.includes(test.slug));
92
93
  return (await removableBlockTests(exec, removed)).map((test)=>({
93
94
  ...test,
@@ -136,7 +137,8 @@ export const blockRemovalRule = {
136
137
  ]));
137
138
  try {
138
139
  for (const test of affected){
139
- if (!current.some((row)=>String(row.id) === String(test.id) && row.kind === 'block' && row.status === 'running')) continue;
140
+ const live = current.find((row)=>String(row.id) === String(test.id) && row.kind === 'block');
141
+ if (!live || live.status !== 'running' && live.status !== 'paused') continue;
140
142
  const documents = claims?.tests.get(String(test.id));
141
143
  let excludedSibling = false;
142
144
  if (await hasOtherPublishedBlockPlacement(req, req.payload.config.custom.xp, test.slug, (slug, docId, view, doc)=>{
@@ -151,8 +153,9 @@ export const blockRemovalRule = {
151
153
  if (transaction == null) throw new XpNoTransactionError('Save this page with transactions on.');
152
154
  // Bulk selection is immutable through every sibling's decision, including
153
155
  // earlier rule refusals. afterOperation explains unrelated failed writes.
154
- const message = excludedSibling ? bulk ? bulkBlockRemovalCopy(test.name) : pendingBlockRemovalCopy(test.name) : hidden?.has(test.slug) ? hiddenBlockPlacementCopy(test.name) : lastBlockPlacementCopy(test.name, removingPage);
155
- if (bulk && excludedSibling) bulk.refusals.set(message, pendingBlockRemovalCopy(test.name));
156
+ const pending = pendingBlockRemovalCopy(live.name, live.status);
157
+ const message = excludedSibling ? bulk ? bulkBlockRemovalCopy(live.name, live.status) : pending : hidden?.has(test.slug) ? hiddenBlockPlacementCopy(live.name, live.status) : lastBlockPlacementCopy(live.name, removingPage, live.status);
158
+ if (bulk && excludedSibling) bulk.refusals.set(message, pending);
156
159
  throw new XpRefusal('locked-placement', message, {
157
160
  experimentId: test.id
158
161
  }, 409);
@@ -170,7 +170,7 @@ function optionsOf(req) {
170
170
  function registration(req, slug) {
171
171
  return optionsOf(req).pages?.collections.find((entry)=>entry.slug === slug);
172
172
  }
173
- const active = (test)=>test.status === 'running' || test.status === 'decided';
173
+ const active = (test)=>test.status === 'running' || test.status === 'paused' || test.status === 'decided';
174
174
  const documentPathsOf = (req, collection, rows)=>{
175
175
  const page = registration(req, collection);
176
176
  return page ? placementDocumentPaths(req, collection, rows, 'all-locales', (doc)=>page.pathOf(doc)) : [];
@@ -0,0 +1,15 @@
1
+ import type { Status } from '../types/status.js';
2
+ export declare const STATUS_LABELS: {
3
+ draft: string;
4
+ running: string;
5
+ stopped: string;
6
+ decided: string;
7
+ archived: string;
8
+ scheduled: string;
9
+ paused: string;
10
+ };
11
+ export type DisplayStatus = keyof typeof STATUS_LABELS;
12
+ export declare function displayStatus({ status, startedAt }: {
13
+ status: Status;
14
+ startedAt?: string | null;
15
+ }, now?: number): DisplayStatus;
@@ -0,0 +1,12 @@
1
+ export const STATUS_LABELS = {
2
+ draft: 'Draft',
3
+ running: 'Running',
4
+ stopped: 'Stopped',
5
+ decided: 'Decided',
6
+ archived: 'Archived',
7
+ scheduled: 'Scheduled',
8
+ paused: 'Paused'
9
+ };
10
+ export function displayStatus({ status, startedAt }, now = Date.now()) {
11
+ return status === 'running' && Date.parse(startedAt ?? '') > now ? 'scheduled' : status;
12
+ }
@@ -1,10 +1,14 @@
1
+ import { type FrozenCohortRule } from '../cohorts/rule.js';
1
2
  import type { PayloadRequest } from 'payload';
2
3
  import type { Arm, DocId, ExperimentKind, ExposurePolicy, Status, TargetingRule, UnitType } from '../types/contracts.js';
3
4
  import type { Manifest, ManifestExperiment } from '../types/manifest.js';
4
5
  import type { AttributeKeys } from '../runtime/targeting.js';
6
+ import type { ExperimentSchedule, PauseInterval } from '../schedule/types.js';
5
7
  type TypedTargetingRule = ManifestExperiment['targeting'][number];
6
8
  export interface ManifestCompileOptions {
7
9
  attributeKeys?: AttributeKeys;
10
+ /** @internal */
11
+ now?: () => Date;
8
12
  onInvalid?(slug: string, reason: string): void;
9
13
  }
10
14
  export interface ManifestPhase {
@@ -13,10 +17,13 @@ export interface ManifestPhase {
13
17
  seed: string;
14
18
  arms: Arm[];
15
19
  allocation: number;
16
- targeting: Array<TargetingRule & {
20
+ targeting: Array<(TargetingRule & {
17
21
  type?: TypedTargetingRule['type'];
18
- }>;
22
+ }) | FrozenCohortRule>;
19
23
  endedAt?: string | null;
24
+ startedAt?: string | null;
25
+ schedule?: ExperimentSchedule | null;
26
+ pauses?: PauseInterval[] | null;
20
27
  }
21
28
  export interface ManifestInputExperiment {
22
29
  id: DocId;
@@ -43,6 +50,11 @@ export interface ManifestInputExperiment {
43
50
  export interface ManifestInputs {
44
51
  experiments: ManifestInputExperiment[];
45
52
  flagDefaults: Manifest['flagDefaults'];
53
+ cohortSourcePhases?: Array<{
54
+ experiment: DocId;
55
+ phase: number;
56
+ endedAt?: string | null;
57
+ }>;
46
58
  excludeIds?: DocId[];
47
59
  pruneFlagDefaultIds?: DocId[];
48
60
  }
@@ -51,12 +63,11 @@ export declare function loadManifestInputs(req: PayloadRequest, { excludeIds, pr
51
63
  pruneFlagDefaultIds?: DocId[];
52
64
  signal?: AbortSignal;
53
65
  }): Promise<ManifestInputs>;
54
- /** Pure compiler. Assignment config comes exclusively from the frozen phase. */
55
66
  /**
56
67
  * Pure manifest builder (exported from `/rsc` for host tests). Pass the same `attributeKeys` as the plugin options,
57
68
  * or legacy untyped targeting rules are dropped. Its input shape may change in a pre-1.0 minor.
58
69
  */
59
- export declare function compileManifest(inputs: ManifestInputs, revision: number, { attributeKeys, onInvalid }?: ManifestCompileOptions): Manifest;
70
+ export declare function compileManifest(inputs: ManifestInputs, revision: number, { attributeKeys, onInvalid, now }?: ManifestCompileOptions): Manifest;
60
71
  /** Take the state lock before reading inputs. Under READ COMMITTED, a builder
61
72
  * waiting for another transition then sees that transition's committed changes,
62
73
  * so a later revision cannot overwrite the manifest with pre-lock input state.
@@ -1,7 +1,13 @@
1
+ import { isCohortRule } from '../cohorts/rule.js';
1
2
  import { txExecutor } from '../db/executor.js';
2
3
  import { bumpRevision, writeManifest } from '../db/state.js';
4
+ import { LATE_BEACON_GRACE_MS } from '../db/snapshots.js';
3
5
  import { XpRefusal } from '../errors.js';
4
6
  import { xpOptionsFromReq } from '../options/fromReq.js';
7
+ const sourceId = (experiment, phase)=>JSON.stringify([
8
+ String(experiment),
9
+ phase
10
+ ]);
5
11
  export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaultIds = [], signal } = {}) {
6
12
  signal?.throwIfAborted();
7
13
  // §7.8 manifest reads: transitions compile all live/archived routing state.
@@ -80,6 +86,42 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
80
86
  } : {}
81
87
  });
82
88
  }
89
+ const sources = new Map();
90
+ for (const experiment of experiments){
91
+ for (const rule of experiment.currentPhase?.targeting ?? []){
92
+ if (isCohortRule(rule) && 'key' in rule) sources.set(sourceId(rule.experiment, rule.phase), rule);
93
+ }
94
+ }
95
+ let cohortSourcePhases;
96
+ if (sources.size) {
97
+ // §7.8 manifest reads: frozen cohort rules refer to exact rounds, including stopped sources.
98
+ const phases = await req.payload.find({
99
+ collection: 'xp-phases',
100
+ req,
101
+ overrideAccess: true,
102
+ depth: 0,
103
+ limit: 0,
104
+ where: {
105
+ or: [
106
+ ...sources.values()
107
+ ].map((rule)=>({
108
+ experiment: {
109
+ equals: rule.experiment
110
+ },
111
+ phase: {
112
+ equals: rule.phase
113
+ }
114
+ }))
115
+ },
116
+ select: {
117
+ experiment: true,
118
+ phase: true,
119
+ endedAt: true
120
+ }
121
+ });
122
+ signal?.throwIfAborted();
123
+ cohortSourcePhases = phases.docs;
124
+ }
83
125
  // §7.8 manifest reads: defaults are part of the private compiled manifest.
84
126
  const state = await req.payload.findGlobal({
85
127
  slug: 'xp-state',
@@ -90,6 +132,7 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
90
132
  return {
91
133
  experiments,
92
134
  flagDefaults: state.flagDefaults ?? {},
135
+ cohortSourcePhases,
93
136
  excludeIds,
94
137
  pruneFlagDefaultIds
95
138
  };
@@ -111,12 +154,34 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
111
154
  });
112
155
  inputs.flagDefaults = defaults;
113
156
  }
114
- /** Pure compiler. Assignment config comes exclusively from the frozen phase. */ /**
157
+ function compileActive(phase, now) {
158
+ const { schedule, startedAt } = phase;
159
+ // The phase may open at a later instant than the configured start.
160
+ let from = schedule?.startAt;
161
+ if (startedAt && Date.parse(startedAt) > now.getTime() && (!from || Date.parse(startedAt) > Date.parse(from))) from = startedAt;
162
+ if (!schedule && !from) return undefined;
163
+ return {
164
+ tz: schedule?.timeZone ?? 'UTC',
165
+ windows: schedule?.windows ?? [],
166
+ ...from ? {
167
+ from: new Date(from).toISOString()
168
+ } : {},
169
+ ...schedule?.endAt ? {
170
+ to: new Date(schedule.endAt).toISOString()
171
+ } : {}
172
+ };
173
+ }
174
+ /**
115
175
  * Pure manifest builder (exported from `/rsc` for host tests). Pass the same `attributeKeys` as the plugin options,
116
176
  * or legacy untyped targeting rules are dropped. Its input shape may change in a pre-1.0 minor.
117
- */ export function compileManifest(inputs, revision, { attributeKeys, onInvalid } = {}) {
177
+ */ export function compileManifest(inputs, revision, { attributeKeys, onInvalid, now = ()=>new Date() } = {}) {
178
+ const compiledAt = now();
118
179
  const excluded = new Set(inputs.excludeIds?.map(String));
119
180
  const prunedDefaults = new Set(inputs.pruneFlagDefaultIds?.map(String));
181
+ const sourceEnds = new Map(inputs.cohortSourcePhases?.map((source)=>[
182
+ sourceId(source.experiment, source.phase),
183
+ source.endedAt
184
+ ]));
120
185
  const manifest = {
121
186
  v: 1,
122
187
  revision,
@@ -153,7 +218,19 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
153
218
  if (experiment.status !== 'running' && experiment.status !== 'decided') continue;
154
219
  if (!phase) throw new Error(`Missing current phase for experiment ${experiment.slug}`);
155
220
  const targeting = [];
221
+ const cohorts = [];
156
222
  for (const rule of phase.targeting ?? []){
223
+ if (isCohortRule(rule)) {
224
+ if (!('key' in rule) || !rule.key) break;
225
+ const endedAt = sourceEnds.get(sourceId(rule.experiment, rule.phase));
226
+ const closedAtMs = endedAt ? Date.parse(endedAt) + LATE_BEACON_GRACE_MS : NaN;
227
+ cohorts.push({
228
+ key: rule.key,
229
+ include: rule.include,
230
+ sourceClosedAt: Number.isFinite(closedAtMs) ? new Date(closedAtMs).toISOString() : null
231
+ });
232
+ continue;
233
+ }
157
234
  // Legacy phases have no stored type. Only those consult today's registry.
158
235
  const type = rule.type ?? (attributeKeys && Object.hasOwn(attributeKeys, rule.attribute) ? attributeKeys[rule.attribute]?.type : undefined);
159
236
  if (type !== 'string' && type !== 'number' && type !== 'boolean') break;
@@ -164,7 +241,7 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
164
241
  type
165
242
  });
166
243
  }
167
- if (targeting.length !== (phase.targeting ?? []).length) {
244
+ if (targeting.length + cohorts.length !== (phase.targeting ?? []).length) {
168
245
  onInvalid?.(experiment.slug, 'untyped-targeting-rule');
169
246
  continue;
170
247
  }
@@ -179,6 +256,8 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
179
256
  slices: experiment.layerSlices
180
257
  };
181
258
  }
259
+ const active = experiment.status === 'running' ? compileActive(phase, compiledAt) : undefined;
260
+ const resumedAt = experiment.status === 'running' ? phase.pauses?.at(-1)?.to : undefined;
182
261
  const compiled = {
183
262
  id: experiment.id,
184
263
  slug: experiment.slug,
@@ -208,6 +287,9 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
208
287
  }),
209
288
  targeting,
210
289
  exposurePolicy: experiment.exposurePolicy,
290
+ ...cohorts.length ? {
291
+ cohorts
292
+ } : {},
211
293
  deferrable: targeting.some((rule)=>rule.attribute === 'loggedIn' || rule.attribute === 'staff'),
212
294
  ...experiment.flagPoint ? {
213
295
  flagPoint: experiment.flagPoint
@@ -215,6 +297,12 @@ export async function loadManifestInputs(req, { excludeIds = [], pruneFlagDefaul
215
297
  ...layer ? {
216
298
  layer
217
299
  } : {},
300
+ ...active ? {
301
+ active
302
+ } : {},
303
+ ...resumedAt ? {
304
+ resumedAt: new Date(resumedAt).toISOString()
305
+ } : {},
218
306
  ...decision?.winnerArm ? {
219
307
  winnerArm: decision.winnerArm
220
308
  } : {}
package/dist/onInit.js CHANGED
@@ -1,4 +1,4 @@
1
- import { puckCollections } from './options.js';
1
+ import { isValidTimeZone, puckCollections } from './options.js';
2
2
  import { pageGuardEnterOperation } from './hooks/pageGuard.js';
3
3
  import { findRegisteredBlocksField } from './blocks/formState.js';
4
4
  import { EXPERIMENT_BLOCK_SLUG } from './blocks/model.js';
@@ -29,6 +29,9 @@ function registeredPaths(fields, name, parent = []) {
29
29
  }
30
30
  export function createOnInit(options) {
31
31
  return async (payload)=>{
32
+ if (options.timeZone !== undefined && !isValidTimeZone(options.timeZone)) {
33
+ throw new Error('Experiments timeZone must be an IANA time zone');
34
+ }
32
35
  const rateLimit = options.events?.rateLimit;
33
36
  if (rateLimit !== false && typeof rateLimit !== 'function') {
34
37
  throw new Error('Experiments requires events.rateLimit to be a client-address rate limiter, or false if you rate-limit the events route upstream.');
package/dist/options.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { ExperimentsPluginOptions, ResolvedOptions } from './types/contracts.js';
2
+ export { isValidTimeZone } from './schedule/activeTime.js';
2
3
  /** Resolve once per registration list; every consumer shares the same field defaults. */
3
4
  export declare function puckCollections(options: Pick<ExperimentsPluginOptions, 'puck'>): Array<{
4
5
  slug: string;
package/dist/options.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { validateAccent } from './ui/accent.js';
2
2
  import { DEFAULT_MAX_BODY_BYTES } from './constants.js';
3
3
  import { publicEventOrigin } from './events/request.js';
4
+ export { isValidTimeZone } from './schedule/activeTime.js';
4
5
  const normalisedCollections = new WeakMap();
5
6
  /** Resolve once per registration list; every consumer shares the same field defaults. */ export function puckCollections(options) {
6
7
  const entries = options.puck?.collections;
@@ -33,6 +34,15 @@ export function resolveOptions(input) {
33
34
  })){
34
35
  if (typeof access !== 'function') throw new Error(`Experiments access.${name} must be a function`);
35
36
  }
37
+ if (input.cohorts !== undefined) {
38
+ const cohorts = input.cohorts;
39
+ if (!cohorts || typeof cohorts !== 'object' || Array.isArray(cohorts) || typeof cohorts.proxyLookup !== 'boolean') {
40
+ throw new Error('Experiments cohorts requires a boolean proxyLookup option');
41
+ }
42
+ for (const key of Object.keys(cohorts)){
43
+ if (key !== 'proxyLookup') throw new Error(`Unknown experiments cohorts option: ${key}`);
44
+ }
45
+ }
36
46
  if (input.admin !== undefined) {
37
47
  const admin = input.admin;
38
48
  if (!admin || typeof admin !== 'object' || Array.isArray(admin)) throw new Error('Experiments admin must be an object');
@@ -2,4 +2,4 @@ import { type AssignmentResult } from '../runtime/assign.js';
2
2
  import type { Attributes } from '../types/contracts.js';
3
3
  import type { Manifest } from '../types/manifest.js';
4
4
  /** Serve deterministic site content without assigning, hashing or retaining a unit id. */
5
- export declare function consentFallback(manifest: Manifest, attributes: Attributes, context: Pick<AssignmentResult, 'staff' | 'bot' | 'preview' | 'sessionUnknown' | 'method'>): AssignmentResult;
5
+ export declare function consentFallback(manifest: Manifest, attributes: Attributes, context: Pick<AssignmentResult, 'staff' | 'bot' | 'preview' | 'sessionUnknown' | 'method'>, now?: Date): AssignmentResult;
@@ -1,12 +1,12 @@
1
1
  import { fillFlagPoints } from '../runtime/assign.js';
2
2
  import { evaluateTargeting } from '../runtime/targeting.js';
3
3
  import { controlAssignments } from './control.js';
4
- /** Serve deterministic site content without assigning, hashing or retaining a unit id. */ export function consentFallback(manifest, attributes, context) {
4
+ /** Serve deterministic site content without assigning, hashing or retaining a unit id. */ export function consentFallback(manifest, attributes, context, now) {
5
5
  const result = controlAssignments(manifest, {
6
6
  ...context,
7
7
  visitorId: undefined,
8
8
  userId: undefined
9
- });
9
+ }, now);
10
10
  const identityFreeAttributes = {
11
11
  ...attributes
12
12
  };
@@ -17,11 +17,11 @@ import { controlAssignments } from './control.js';
17
17
  delete identityFreeAttributes.staff;
18
18
  }
19
19
  for (const experiment of manifest.experiments){
20
- if (experiment.status !== 'decided' || experiment.phaseKind === 'rollout') continue;
20
+ if (experiment.status !== 'decided' || experiment.phaseKind === 'rollout' || experiment.cohorts?.length) continue;
21
21
  const winner = experiment.arms.find((arm)=>arm.key === experiment.winnerArm);
22
22
  if (!winner || !evaluateTargeting(experiment.targeting, identityFreeAttributes)) continue;
23
23
  result.bySlug[experiment.slug].arm = winner.key;
24
24
  }
25
- fillFlagPoints(result, manifest);
25
+ fillFlagPoints(result, manifest, now);
26
26
  return result;
27
27
  }
@@ -1,6 +1,6 @@
1
1
  import { type AssignmentResult } from '../runtime/assign.js';
2
2
  import type { Manifest } from '../types/manifest.js';
3
3
  /** Explicit control entries prevent deferred user/session assignments from becoming exposable. */
4
- export declare function controlAssignments(manifest: Manifest, context: Pick<AssignmentResult, 'visitorId' | 'userId' | 'staff' | 'bot' | 'preview' | 'sessionUnknown' | 'method'>): AssignmentResult;
4
+ export declare function controlAssignments(manifest: Manifest, context: Pick<AssignmentResult, 'visitorId' | 'userId' | 'staff' | 'bot' | 'preview' | 'sessionUnknown' | 'method'>, now?: Date): AssignmentResult;
5
5
  /** Last resort: do not inspect a manifest that could not even produce controls. */
6
6
  export declare function emptyAssignments(context: Pick<AssignmentResult, 'visitorId' | 'userId' | 'staff' | 'bot' | 'preview' | 'sessionUnknown' | 'method'>): AssignmentResult;
@@ -1,5 +1,5 @@
1
1
  import { fillFlagPoints } from '../runtime/assign.js';
2
- /** Explicit control entries prevent deferred user/session assignments from becoming exposable. */ export function controlAssignments(manifest, context) {
2
+ /** Explicit control entries prevent deferred user/session assignments from becoming exposable. */ export function controlAssignments(manifest, context, now) {
3
3
  const result = {
4
4
  ...context,
5
5
  revision: manifest.revision,
@@ -21,7 +21,7 @@ import { fillFlagPoints } from '../runtime/assign.js';
21
21
  source: 'fallback'
22
22
  };
23
23
  }
24
- fillFlagPoints(result, manifest);
24
+ fillFlagPoints(result, manifest, now);
25
25
  return result;
26
26
  }
27
27
  /** Last resort: do not inspect a manifest that could not even produce controls. */ export function emptyAssignments(context) {
@@ -1,4 +1,4 @@
1
1
  import type { AssignmentResult } from '../runtime/assign.js';
2
2
  import type { Manifest } from '../types/manifest.js';
3
3
  import type { NextRequest } from 'next/server';
4
- export declare function pageRewrite(manifest: Manifest, assignments: AssignmentResult, requestURL: NextRequest['nextUrl']): URL | undefined;
4
+ export declare function pageRewrite(manifest: Manifest, assignments: AssignmentResult, requestURL: NextRequest['nextUrl'], now: Date): URL | undefined;
@@ -1,4 +1,5 @@
1
1
  import { findNormalisedPathKey, normalisePath } from '../runtime/normalisePath.js';
2
+ import { isEntryActive } from '../runtime/eligibility.js';
2
3
  // Manifest targets are local paths. A malformed target must never become an open rewrite.
3
4
  function targetURL(path, requestURL) {
4
5
  if (!path?.startsWith('/') || path.startsWith('//') || /[\\\r\n?#]/.test(path)) return undefined;
@@ -11,8 +12,8 @@ function targetURL(path, requestURL) {
11
12
  return undefined;
12
13
  }
13
14
  }
14
- export function pageRewrite(manifest, assignments, requestURL) {
15
- const experiment = manifest.experiments.find((experiment)=>experiment.kind === 'page' && (experiment.status === 'running' || experiment.status === 'decided') && experiment.arms.some((arm)=>arm.pageTarget !== undefined && normalisePath(arm.pageTarget) === normalisePath(requestURL.pathname)));
15
+ export function pageRewrite(manifest, assignments, requestURL, now) {
16
+ const experiment = manifest.experiments.find((experiment)=>experiment.kind === 'page' && (experiment.status === 'running' || experiment.status === 'decided') && isEntryActive(experiment, now) && experiment.arms.some((arm)=>arm.pageTarget !== undefined && normalisePath(arm.pageTarget) === normalisePath(requestURL.pathname)));
16
17
  if (experiment) {
17
18
  const assignment = assignments.bySlug[experiment.slug];
18
19
  const control = experiment.arms.find((arm)=>arm.kind === 'control');