@delmaredigital/payload-experiments 0.0.0-stage → 0.1.0-rc.6

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 (466) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +590 -2
  3. package/dist/access.d.ts +1 -0
  4. package/dist/access.js +2 -0
  5. package/dist/admin/AllocationField.d.ts +2 -0
  6. package/dist/admin/AllocationField.js +80 -0
  7. package/dist/admin/FlagPointSelect.d.ts +2 -0
  8. package/dist/admin/FlagPointSelect.js +54 -0
  9. package/dist/admin/LayerUsage.d.ts +2 -0
  10. package/dist/admin/LayerUsage.js +24 -0
  11. package/dist/admin/LockedFieldNotice.d.ts +2 -0
  12. package/dist/admin/LockedFieldNotice.js +26 -0
  13. package/dist/admin/MetricSourceSelect.d.ts +2 -0
  14. package/dist/admin/MetricSourceSelect.js +32 -0
  15. package/dist/admin/PhaseHistory.d.ts +2 -0
  16. package/dist/admin/PhaseHistory.js +76 -0
  17. package/dist/admin/PreviewLinks.d.ts +11 -0
  18. package/dist/admin/PreviewLinks.js +69 -0
  19. package/dist/admin/StatusCell.d.ts +3 -0
  20. package/dist/admin/StatusCell.js +19 -0
  21. package/dist/admin/SummaryCell.d.ts +2 -0
  22. package/dist/admin/SummaryCell.js +32 -0
  23. package/dist/admin/actions/AddMetricDialog.d.ts +6 -0
  24. package/dist/admin/actions/AddMetricDialog.js +138 -0
  25. package/dist/admin/actions/AllocateDialog.d.ts +6 -0
  26. package/dist/admin/actions/AllocateDialog.js +81 -0
  27. package/dist/admin/actions/ConfirmDialog.d.ts +14 -0
  28. package/dist/admin/actions/ConfirmDialog.js +192 -0
  29. package/dist/admin/actions/DecideDialog.d.ts +7 -0
  30. package/dist/admin/actions/DecideDialog.js +173 -0
  31. package/dist/admin/actions/ExperimentActions.d.ts +3 -0
  32. package/dist/admin/actions/ExperimentActions.js +110 -0
  33. package/dist/admin/actions/MakeContentResult.d.ts +6 -0
  34. package/dist/admin/actions/MakeContentResult.js +50 -0
  35. package/dist/admin/actions/actions.model.d.ts +37 -0
  36. package/dist/admin/actions/actions.model.js +71 -0
  37. package/dist/admin/actions/decide.model.d.ts +21 -0
  38. package/dist/admin/actions/decide.model.js +38 -0
  39. package/dist/admin/allocation.model.d.ts +20 -0
  40. package/dist/admin/allocation.model.js +38 -0
  41. package/dist/admin/api.d.ts +32 -0
  42. package/dist/admin/api.js +95 -0
  43. package/dist/admin/armSelect/ArmSelectField.d.ts +2 -0
  44. package/dist/admin/armSelect/ArmSelectField.js +185 -0
  45. package/dist/admin/armSelect/armSelect.model.d.ts +30 -0
  46. package/dist/admin/armSelect/armSelect.model.js +20 -0
  47. package/dist/admin/arms/ArmsField.d.ts +2 -0
  48. package/dist/admin/arms/ArmsField.js +310 -0
  49. package/dist/admin/arms/ParamsEditor.d.ts +16 -0
  50. package/dist/admin/arms/ParamsEditor.js +79 -0
  51. package/dist/admin/arms/arms.model.d.ts +21 -0
  52. package/dist/admin/arms/arms.model.js +153 -0
  53. package/dist/admin/arms/pageTarget.model.d.ts +4 -0
  54. package/dist/admin/arms/pageTarget.model.js +19 -0
  55. package/dist/admin/arms/params.model.d.ts +7 -0
  56. package/dist/admin/arms/params.model.js +35 -0
  57. package/dist/admin/copy/actions.d.ts +38 -0
  58. package/dist/admin/copy/actions.js +38 -0
  59. package/dist/admin/copy/armSelect.d.ts +11 -0
  60. package/dist/admin/copy/armSelect.js +11 -0
  61. package/dist/admin/copy/arms.d.ts +37 -0
  62. package/dist/admin/copy/arms.js +47 -0
  63. package/dist/admin/copy/common.d.ts +20 -0
  64. package/dist/admin/copy/common.js +27 -0
  65. package/dist/admin/copy/history.d.ts +9 -0
  66. package/dist/admin/copy/history.js +9 -0
  67. package/dist/admin/copy/metrics.d.ts +9 -0
  68. package/dist/admin/copy/metrics.js +9 -0
  69. package/dist/admin/copy/results.d.ts +78 -0
  70. package/dist/admin/copy/results.js +81 -0
  71. package/dist/admin/copy/review.d.ts +33 -0
  72. package/dist/admin/copy/review.js +127 -0
  73. package/dist/admin/copy/status.d.ts +8 -0
  74. package/dist/admin/copy/status.js +8 -0
  75. package/dist/admin/copy/tabs.d.ts +7 -0
  76. package/dist/admin/copy/tabs.js +7 -0
  77. package/dist/admin/copy/who.d.ts +36 -0
  78. package/dist/admin/copy/who.js +36 -0
  79. package/dist/admin/labels.d.ts +45 -0
  80. package/dist/admin/labels.js +53 -0
  81. package/dist/admin/layerUsage.model.d.ts +15 -0
  82. package/dist/admin/layerUsage.model.js +18 -0
  83. package/dist/admin/lockedNotice.model.d.ts +3 -0
  84. package/dist/admin/lockedNotice.model.js +18 -0
  85. package/dist/admin/metricSource.model.d.ts +7 -0
  86. package/dist/admin/metricSource.model.js +11 -0
  87. package/dist/admin/paths.d.ts +16 -0
  88. package/dist/admin/paths.js +16 -0
  89. package/dist/admin/permissions.model.d.ts +10 -0
  90. package/dist/admin/permissions.model.js +4 -0
  91. package/dist/admin/phaseHistory.model.d.ts +19 -0
  92. package/dist/admin/phaseHistory.model.js +19 -0
  93. package/dist/admin/reload.d.ts +1 -0
  94. package/dist/admin/reload.js +1 -0
  95. package/dist/admin/results/ArmTable.d.ts +8 -0
  96. package/dist/admin/results/ArmTable.js +112 -0
  97. package/dist/admin/results/CappedCell.d.ts +4 -0
  98. package/dist/admin/results/CappedCell.js +24 -0
  99. package/dist/admin/results/CiChart.d.ts +10 -0
  100. package/dist/admin/results/CiChart.js +178 -0
  101. package/dist/admin/results/DataQualityPanel.d.ts +4 -0
  102. package/dist/admin/results/DataQualityPanel.js +40 -0
  103. package/dist/admin/results/ResultsView.d.ts +3 -0
  104. package/dist/admin/results/ResultsView.js +312 -0
  105. package/dist/admin/results/VerdictCard.d.ts +9 -0
  106. package/dist/admin/results/VerdictCard.js +49 -0
  107. package/dist/admin/results/chart.model.d.ts +32 -0
  108. package/dist/admin/results/chart.model.js +52 -0
  109. package/dist/admin/results/format.d.ts +10 -0
  110. package/dist/admin/results/format.js +55 -0
  111. package/dist/admin/results/results.model.d.ts +105 -0
  112. package/dist/admin/results/results.model.js +175 -0
  113. package/dist/admin/review/ReviewPanel.d.ts +2 -0
  114. package/dist/admin/review/ReviewPanel.js +268 -0
  115. package/dist/admin/review/review.model.d.ts +31 -0
  116. package/dist/admin/review/review.model.js +40 -0
  117. package/dist/admin/status.model.d.ts +16 -0
  118. package/dist/admin/status.model.js +17 -0
  119. package/dist/admin/styles.css +10 -0
  120. package/dist/admin/styles.d.ts +1 -0
  121. package/dist/admin/styles.js +2 -0
  122. package/dist/admin/summaryBatcher.d.ts +8 -0
  123. package/dist/admin/summaryBatcher.js +33 -0
  124. package/dist/admin/targeting/TargetingAttributeField.d.ts +2 -0
  125. package/dist/admin/targeting/TargetingAttributeField.js +31 -0
  126. package/dist/admin/targeting/TargetingOpField.d.ts +2 -0
  127. package/dist/admin/targeting/TargetingOpField.js +45 -0
  128. package/dist/admin/targeting/TargetingValueField.d.ts +2 -0
  129. package/dist/admin/targeting/TargetingValueField.js +142 -0
  130. package/dist/admin/targeting/targeting.model.d.ts +18 -0
  131. package/dist/admin/targeting/targeting.model.js +48 -0
  132. package/dist/admin/useApi.d.ts +20 -0
  133. package/dist/admin/useApi.js +10 -0
  134. package/dist/admin/useLayerUsage.d.ts +15 -0
  135. package/dist/admin/useLayerUsage.js +92 -0
  136. package/dist/client/ExperimentPageview.d.ts +1 -0
  137. package/dist/client/ExperimentPageview.js +27 -0
  138. package/dist/client/ExperimentsProvider.d.ts +6 -0
  139. package/dist/client/ExperimentsProvider.js +22 -0
  140. package/dist/client/ViewportExposure.d.ts +9 -0
  141. package/dist/client/ViewportExposure.js +69 -0
  142. package/dist/client/beacon.d.ts +17 -0
  143. package/dist/client/beacon.js +71 -0
  144. package/dist/client/context.d.ts +2 -0
  145. package/dist/client/context.js +2 -0
  146. package/dist/client/idempotency.d.ts +2 -0
  147. package/dist/client/idempotency.js +13 -0
  148. package/dist/client/trackConversionBeacon.d.ts +3 -0
  149. package/dist/client/trackConversionBeacon.js +16 -0
  150. package/dist/client/useExperiment.d.ts +5 -0
  151. package/dist/client/useExperiment.js +27 -0
  152. package/dist/client/useFlagPoint.d.ts +9 -0
  153. package/dist/client/useFlagPoint.js +32 -0
  154. package/dist/collections/access.d.ts +21 -0
  155. package/dist/collections/access.js +25 -0
  156. package/dist/collections/events.d.ts +3 -0
  157. package/dist/collections/events.js +117 -0
  158. package/dist/collections/experiments/armInvariants.d.ts +12 -0
  159. package/dist/collections/experiments/armInvariants.js +89 -0
  160. package/dist/collections/experiments/config.d.ts +3 -0
  161. package/dist/collections/experiments/config.js +574 -0
  162. package/dist/collections/experiments/createDefaults.d.ts +2 -0
  163. package/dist/collections/experiments/createDefaults.js +7 -0
  164. package/dist/collections/experiments/deleteGuard.d.ts +3 -0
  165. package/dist/collections/experiments/deleteGuard.js +8 -0
  166. package/dist/collections/experiments/editability.d.ts +4 -0
  167. package/dist/collections/experiments/editability.js +35 -0
  168. package/dist/collections/experiments/flagControlParams.d.ts +2 -0
  169. package/dist/collections/experiments/flagControlParams.js +32 -0
  170. package/dist/collections/experiments/lockHook.d.ts +2 -0
  171. package/dist/collections/experiments/lockHook.js +134 -0
  172. package/dist/collections/identities.d.ts +3 -0
  173. package/dist/collections/identities.js +30 -0
  174. package/dist/collections/index.d.ts +6 -0
  175. package/dist/collections/index.js +24 -0
  176. package/dist/collections/layers.d.ts +3 -0
  177. package/dist/collections/layers.js +77 -0
  178. package/dist/collections/metrics.d.ts +3 -0
  179. package/dist/collections/metrics.js +115 -0
  180. package/dist/collections/phases.d.ts +3 -0
  181. package/dist/collections/phases.js +59 -0
  182. package/dist/collections/serialize.d.ts +5 -0
  183. package/dist/collections/serialize.js +40 -0
  184. package/dist/collections/snapshots.d.ts +3 -0
  185. package/dist/collections/snapshots.js +47 -0
  186. package/dist/constants.d.ts +7 -0
  187. package/dist/constants.js +7 -0
  188. package/dist/db/adapter.d.ts +3 -0
  189. package/dist/db/adapter.js +9 -0
  190. package/dist/db/appends.d.ts +58 -0
  191. package/dist/db/appends.js +116 -0
  192. package/dist/db/delete.d.ts +17 -0
  193. package/dist/db/delete.js +35 -0
  194. package/dist/db/erase.d.ts +12 -0
  195. package/dist/db/erase.js +55 -0
  196. package/dist/db/events.d.ts +21 -0
  197. package/dist/db/events.js +100 -0
  198. package/dist/db/executor.d.ts +10 -0
  199. package/dist/db/executor.js +37 -0
  200. package/dist/db/identities.d.ts +11 -0
  201. package/dist/db/identities.js +29 -0
  202. package/dist/db/locks.d.ts +15 -0
  203. package/dist/db/locks.js +23 -0
  204. package/dist/db/manifest.d.ts +8 -0
  205. package/dist/db/manifest.js +8 -0
  206. package/dist/db/names.d.ts +271 -0
  207. package/dist/db/names.js +270 -0
  208. package/dist/db/pgExecutor.d.ts +41 -0
  209. package/dist/db/pgExecutor.js +250 -0
  210. package/dist/db/results.d.ts +53 -0
  211. package/dist/db/results.js +103 -0
  212. package/dist/db/slices.d.ts +18 -0
  213. package/dist/db/slices.js +51 -0
  214. package/dist/db/snapshots.d.ts +47 -0
  215. package/dist/db/snapshots.js +89 -0
  216. package/dist/db/sql.d.ts +5 -0
  217. package/dist/db/sql.js +5 -0
  218. package/dist/db/state.d.ts +12 -0
  219. package/dist/db/state.js +27 -0
  220. package/dist/db/sweep.d.ts +13 -0
  221. package/dist/db/sweep.js +90 -0
  222. package/dist/db/txid.d.ts +7 -0
  223. package/dist/db/txid.js +12 -0
  224. package/dist/define.d.ts +3 -0
  225. package/dist/define.js +6 -0
  226. package/dist/endpoints/events.d.ts +7 -0
  227. package/dist/endpoints/events.js +98 -0
  228. package/dist/endpoints/index.d.ts +18 -0
  229. package/dist/endpoints/index.js +160 -0
  230. package/dist/endpoints/manifest.d.ts +7 -0
  231. package/dist/endpoints/manifest.js +30 -0
  232. package/dist/endpoints/preflight.d.ts +8 -0
  233. package/dist/endpoints/preflight.js +25 -0
  234. package/dist/endpoints/previewToken.d.ts +7 -0
  235. package/dist/endpoints/previewToken.js +54 -0
  236. package/dist/endpoints/recompute.d.ts +7 -0
  237. package/dist/endpoints/recompute.js +41 -0
  238. package/dist/endpoints/results.d.ts +24 -0
  239. package/dist/endpoints/results.js +136 -0
  240. package/dist/endpoints/summary.d.ts +7 -0
  241. package/dist/endpoints/summary.js +40 -0
  242. package/dist/endpoints/transitions.d.ts +42 -0
  243. package/dist/endpoints/transitions.js +154 -0
  244. package/dist/errors.d.ts +27 -0
  245. package/dist/errors.js +33 -0
  246. package/dist/events/body.d.ts +7 -0
  247. package/dist/events/body.js +43 -0
  248. package/dist/events/dimensions.d.ts +4 -0
  249. package/dist/events/dimensions.js +51 -0
  250. package/dist/events/preview.d.ts +2 -0
  251. package/dist/events/preview.js +9 -0
  252. package/dist/events/request.d.ts +3 -0
  253. package/dist/events/request.js +14 -0
  254. package/dist/events/rows.d.ts +7 -0
  255. package/dist/events/rows.js +65 -0
  256. package/dist/exports/adminClient.d.ts +16 -0
  257. package/dist/exports/adminClient.js +17 -0
  258. package/dist/exports/client.d.ts +7 -0
  259. package/dist/exports/client.js +7 -0
  260. package/dist/exports/index.d.ts +4 -0
  261. package/dist/exports/index.js +3 -0
  262. package/dist/exports/proxy.d.ts +4 -0
  263. package/dist/exports/proxy.js +3 -0
  264. package/dist/exports/puck.d.ts +4 -0
  265. package/dist/exports/puck.js +3 -0
  266. package/dist/exports/puckEditor.d.ts +1 -0
  267. package/dist/exports/puckEditor.js +2 -0
  268. package/dist/exports/rsc.d.ts +13 -0
  269. package/dist/exports/rsc.js +13 -0
  270. package/dist/exports/runtimeProxy.d.ts +4 -0
  271. package/dist/exports/runtimeProxy.js +2 -0
  272. package/dist/exports/runtimeServer.d.ts +2 -0
  273. package/dist/exports/runtimeServer.js +1 -0
  274. package/dist/fields/armSelect.d.ts +7 -0
  275. package/dist/fields/armSelect.js +33 -0
  276. package/dist/globals/state.d.ts +3 -0
  277. package/dist/globals/state.js +31 -0
  278. package/dist/hooks/contentChanges.d.ts +3 -0
  279. package/dist/hooks/contentChanges.js +10 -0
  280. package/dist/hooks/hostHook.d.ts +5 -0
  281. package/dist/hooks/hostHook.js +20 -0
  282. package/dist/index.d.ts +1 -0
  283. package/dist/index.js +4 -0
  284. package/dist/manifest/cache.d.ts +10 -0
  285. package/dist/manifest/cache.js +51 -0
  286. package/dist/manifest/compile.d.ts +63 -0
  287. package/dist/manifest/compile.js +237 -0
  288. package/dist/onInit.d.ts +5 -0
  289. package/dist/onInit.js +13 -0
  290. package/dist/options/fromReq.d.ts +3 -0
  291. package/dist/options/fromReq.js +5 -0
  292. package/dist/options.d.ts +9 -0
  293. package/dist/options.js +107 -0
  294. package/dist/plugin.d.ts +7 -0
  295. package/dist/plugin.js +62 -0
  296. package/dist/proxy/apply.d.ts +3 -0
  297. package/dist/proxy/apply.js +5 -0
  298. package/dist/proxy/consentFallback.d.ts +5 -0
  299. package/dist/proxy/consentFallback.js +27 -0
  300. package/dist/proxy/control.d.ts +6 -0
  301. package/dist/proxy/control.js +36 -0
  302. package/dist/proxy/createProxy.d.ts +3 -0
  303. package/dist/proxy/createProxy.js +15 -0
  304. package/dist/proxy/pageRewrite.d.ts +4 -0
  305. package/dist/proxy/pageRewrite.js +41 -0
  306. package/dist/proxy/resolve.d.ts +13 -0
  307. package/dist/proxy/resolve.js +163 -0
  308. package/dist/proxy/skip.d.ts +1 -0
  309. package/dist/proxy/skip.js +9 -0
  310. package/dist/puck/ExperimentPicker.d.ts +5 -0
  311. package/dist/puck/ExperimentPicker.js +88 -0
  312. package/dist/puck/ExperimentSlot.d.ts +3 -0
  313. package/dist/puck/ExperimentSlot.js +16 -0
  314. package/dist/puck/copy.d.ts +14 -0
  315. package/dist/puck/copy.js +14 -0
  316. package/dist/puck/editor/CreateExperimentDrawer.d.ts +5 -0
  317. package/dist/puck/editor/CreateExperimentDrawer.js +120 -0
  318. package/dist/puck/editor/ExperimentSlotEditor.d.ts +3 -0
  319. package/dist/puck/editor/ExperimentSlotEditor.js +225 -0
  320. package/dist/puck/editor/cloneSlot.d.ts +3 -0
  321. package/dist/puck/editor/cloneSlot.js +41 -0
  322. package/dist/puck/editor/copy.d.ts +25 -0
  323. package/dist/puck/editor/copy.js +25 -0
  324. package/dist/puck/editor/editor.model.d.ts +16 -0
  325. package/dist/puck/editor/editor.model.js +33 -0
  326. package/dist/puck/experimentSlotField.d.ts +5 -0
  327. package/dist/puck/experimentSlotField.js +13 -0
  328. package/dist/puck/slot.model.d.ts +2 -0
  329. package/dist/puck/slot.model.js +11 -0
  330. package/dist/puck/slotConfig.d.ts +5 -0
  331. package/dist/puck/slotConfig.js +25 -0
  332. package/dist/results/aggregate.d.ts +34 -0
  333. package/dist/results/aggregate.js +66 -0
  334. package/dist/results/analyse.d.ts +79 -0
  335. package/dist/results/analyse.js +378 -0
  336. package/dist/results/cuped.d.ts +16 -0
  337. package/dist/results/cuped.js +31 -0
  338. package/dist/results/decideGuard.d.ts +3 -0
  339. package/dist/results/decideGuard.js +8 -0
  340. package/dist/results/guardrails.d.ts +17 -0
  341. package/dist/results/guardrails.js +10 -0
  342. package/dist/results/history.d.ts +13 -0
  343. package/dist/results/history.js +39 -0
  344. package/dist/results/identityCredit.d.ts +16 -0
  345. package/dist/results/identityCredit.js +46 -0
  346. package/dist/results/power.d.ts +15 -0
  347. package/dist/results/power.js +60 -0
  348. package/dist/results/rolloutUnits.d.ts +17 -0
  349. package/dist/results/rolloutUnits.js +26 -0
  350. package/dist/results/snapshot.d.ts +9 -0
  351. package/dist/results/snapshot.js +154 -0
  352. package/dist/results/srm.d.ts +9 -0
  353. package/dist/results/srm.js +22 -0
  354. package/dist/results/verdict.d.ts +82 -0
  355. package/dist/results/verdict.js +85 -0
  356. package/dist/runtime/assign.d.ts +23 -0
  357. package/dist/runtime/assign.js +104 -0
  358. package/dist/runtime/bot.d.ts +1 -0
  359. package/dist/runtime/bot.js +7 -0
  360. package/dist/runtime/cookie.d.ts +17 -0
  361. package/dist/runtime/cookie.js +35 -0
  362. package/dist/runtime/eligibility.d.ts +22 -0
  363. package/dist/runtime/eligibility.js +20 -0
  364. package/dist/runtime/header.d.ts +17 -0
  365. package/dist/runtime/header.js +97 -0
  366. package/dist/runtime/loaders.d.ts +17 -0
  367. package/dist/runtime/loaders.js +29 -0
  368. package/dist/runtime/normalisePath.d.ts +7 -0
  369. package/dist/runtime/normalisePath.js +15 -0
  370. package/dist/runtime/previewToken.d.ts +9 -0
  371. package/dist/runtime/previewToken.js +23 -0
  372. package/dist/runtime/proxyRuntime.d.ts +2 -0
  373. package/dist/runtime/proxyRuntime.js +22 -0
  374. package/dist/runtime/seed.d.ts +2 -0
  375. package/dist/runtime/seed.js +4 -0
  376. package/dist/runtime/signing.d.ts +3 -0
  377. package/dist/runtime/signing.js +16 -0
  378. package/dist/runtime/targeting.d.ts +6 -0
  379. package/dist/runtime/targeting.js +9 -0
  380. package/dist/server/context.d.ts +10 -0
  381. package/dist/server/context.js +59 -0
  382. package/dist/server/eraseUser.d.ts +7 -0
  383. package/dist/server/eraseUser.js +4 -0
  384. package/dist/server/getAssignments.d.ts +9 -0
  385. package/dist/server/getAssignments.js +227 -0
  386. package/dist/server/getFlagPoint.d.ts +11 -0
  387. package/dist/server/getFlagPoint.js +36 -0
  388. package/dist/server/headerRevision.d.ts +6 -0
  389. package/dist/server/headerRevision.js +10 -0
  390. package/dist/server/linkIdentity.d.ts +9 -0
  391. package/dist/server/linkIdentity.js +34 -0
  392. package/dist/server/metadata.d.ts +7 -0
  393. package/dist/server/metadata.js +24 -0
  394. package/dist/server/previewDraft.d.ts +7 -0
  395. package/dist/server/previewDraft.js +51 -0
  396. package/dist/server/recordContentChange.d.ts +7 -0
  397. package/dist/server/recordContentChange.js +150 -0
  398. package/dist/server/recordExposures.d.ts +7 -0
  399. package/dist/server/recordExposures.js +56 -0
  400. package/dist/server/request.d.ts +7 -0
  401. package/dist/server/request.js +39 -0
  402. package/dist/server/resolveExperimentData.d.ts +6 -0
  403. package/dist/server/resolveExperimentData.js +64 -0
  404. package/dist/server/runResults.d.ts +22 -0
  405. package/dist/server/runResults.js +307 -0
  406. package/dist/server/serverRuntime.d.ts +7 -0
  407. package/dist/server/serverRuntime.js +20 -0
  408. package/dist/server/sitemap.d.ts +3 -0
  409. package/dist/server/sitemap.js +6 -0
  410. package/dist/server/toClientAssignments.d.ts +7 -0
  411. package/dist/server/toClientAssignments.js +56 -0
  412. package/dist/server/trackConversion.d.ts +12 -0
  413. package/dist/server/trackConversion.js +69 -0
  414. package/dist/targeting/ops.d.ts +8 -0
  415. package/dist/targeting/ops.js +58 -0
  416. package/dist/transitions/addMetric.d.ts +16 -0
  417. package/dist/transitions/addMetric.js +126 -0
  418. package/dist/transitions/allocate.d.ts +9 -0
  419. package/dist/transitions/allocate.js +84 -0
  420. package/dist/transitions/archive.d.ts +9 -0
  421. package/dist/transitions/archive.js +46 -0
  422. package/dist/transitions/checkStart.d.ts +61 -0
  423. package/dist/transitions/checkStart.js +104 -0
  424. package/dist/transitions/confirmPhrases.d.ts +5 -0
  425. package/dist/transitions/confirmPhrases.js +18 -0
  426. package/dist/transitions/decide.d.ts +9 -0
  427. package/dist/transitions/decide.js +138 -0
  428. package/dist/transitions/deleteExperiment.d.ts +5 -0
  429. package/dist/transitions/deleteExperiment.js +66 -0
  430. package/dist/transitions/kernel.d.ts +31 -0
  431. package/dist/transitions/kernel.js +69 -0
  432. package/dist/transitions/makeContent.d.ts +20 -0
  433. package/dist/transitions/makeContent.js +411 -0
  434. package/dist/transitions/phaseRecord.d.ts +27 -0
  435. package/dist/transitions/phaseRecord.js +81 -0
  436. package/dist/transitions/placements.d.ts +26 -0
  437. package/dist/transitions/placements.js +89 -0
  438. package/dist/transitions/preflightData.d.ts +21 -0
  439. package/dist/transitions/preflightData.js +317 -0
  440. package/dist/transitions/releaseHoldout.d.ts +8 -0
  441. package/dist/transitions/releaseHoldout.js +30 -0
  442. package/dist/transitions/resolveCaps.d.ts +28 -0
  443. package/dist/transitions/resolveCaps.js +68 -0
  444. package/dist/transitions/start.d.ts +26 -0
  445. package/dist/transitions/start.js +220 -0
  446. package/dist/transitions/stop.d.ts +8 -0
  447. package/dist/transitions/stop.js +25 -0
  448. package/dist/types/admin.d.ts +20 -0
  449. package/dist/types/admin.js +1 -0
  450. package/dist/types/assignments.d.ts +57 -0
  451. package/dist/types/assignments.js +1 -0
  452. package/dist/types/contracts.d.ts +141 -0
  453. package/dist/types/contracts.js +1 -0
  454. package/dist/types/endpoints.d.ts +135 -0
  455. package/dist/types/endpoints.js +1 -0
  456. package/dist/types/index.d.ts +8 -0
  457. package/dist/types/index.js +8 -0
  458. package/dist/types/manifest.d.ts +42 -0
  459. package/dist/types/manifest.js +1 -0
  460. package/dist/types/puck.d.ts +23 -0
  461. package/dist/types/puck.js +1 -0
  462. package/dist/types/runtime.d.ts +59 -0
  463. package/dist/types/runtime.js +1 -0
  464. package/dist/types/snapshot.d.ts +117 -0
  465. package/dist/types/snapshot.js +1 -0
  466. package/package.json +138 -3
@@ -0,0 +1,134 @@
1
+ import { XpLockedFieldError } from '../../errors.js';
2
+ import { xpOptionsFromReq } from '../../options/fromReq.js';
3
+ import { EDITABLE_BY_STATUS } from './editability.js';
4
+ import { defaultArms } from './armInvariants.js';
5
+ const isObject = (value)=>typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof Date);
6
+ const relationships = new Set([
7
+ 'layer',
8
+ 'metrics.primary',
9
+ 'metrics.secondary',
10
+ 'metrics.guardrails',
11
+ 'decision.decidedBy',
12
+ 'decision.snapshotId'
13
+ ]);
14
+ const dates = new Set([
15
+ 'startedAt',
16
+ 'stoppedAt',
17
+ 'decidedAt',
18
+ 'archivedAt',
19
+ 'decision.discardedAt',
20
+ 'decision.holdoutReleasedAt'
21
+ ]);
22
+ /** Schema-aware: JSON retains its own ids and date-like strings. */ function normalize(value, path, json = false) {
23
+ json ||= [
24
+ 'arms.params',
25
+ 'targeting.value',
26
+ 'decision.contentReport'
27
+ ].includes(path);
28
+ if (value === undefined || value === null && !json) return undefined;
29
+ if (value === null) return null;
30
+ if (!json && relationships.has(path)) {
31
+ if (Array.isArray(value)) return value.length ? value.map((item)=>normalize(item, path)) : undefined;
32
+ if (isObject(value) && 'id' in value) return value.id == null ? undefined : String(value.id);
33
+ if (typeof value === 'string' || typeof value === 'number') return String(value);
34
+ }
35
+ if (!json && (value instanceof Date || dates.has(path))) {
36
+ const date = new Date(value);
37
+ if (!Number.isNaN(date.valueOf())) return date.toISOString();
38
+ }
39
+ if (Array.isArray(value)) return value.map((item)=>{
40
+ if (!json && [
41
+ 'arms',
42
+ 'targeting'
43
+ ].includes(path) && isObject(item)) {
44
+ const { id: _rowId, ...row } = item;
45
+ return normalize(row, path);
46
+ }
47
+ return normalize(item, path, json);
48
+ });
49
+ if (isObject(value)) return Object.fromEntries(Object.keys(value).sort().flatMap((key)=>{
50
+ const nested = normalize(value[key], `${path}.${key}`, json);
51
+ return nested === undefined ? [] : [
52
+ [
53
+ key,
54
+ nested
55
+ ]
56
+ ];
57
+ }));
58
+ return value;
59
+ }
60
+ const same = (a, b, path)=>JSON.stringify(normalize(a, path)) === JSON.stringify(normalize(b, path));
61
+ export const lockHook = async ({ data, originalDoc, operation, req })=>{
62
+ if (req.context.xpTransition === true) return data;
63
+ const admin = async ()=>{
64
+ const options = xpOptionsFromReq(req);
65
+ return await (options.access.admin ?? options.access.manage)({
66
+ req
67
+ }) === true;
68
+ };
69
+ if (operation === 'create') {
70
+ const result = {
71
+ ...data,
72
+ status: 'draft',
73
+ phase: 0
74
+ };
75
+ // Timestamps are Payload's: a client-sent value is never stored.
76
+ delete result.createdAt;
77
+ delete result.updatedAt;
78
+ for (const field of [
79
+ 'seed',
80
+ 'layerSlices',
81
+ 'startedAt',
82
+ 'stoppedAt',
83
+ 'decidedAt',
84
+ 'archivedAt',
85
+ 'decision'
86
+ ])result[field] = undefined;
87
+ if (!data.arms || Array.isArray(data.arms) && data.arms.length === 0) {
88
+ result.arms = defaultArms(data.kind);
89
+ }
90
+ if (data.kind === 'code' && !await admin()) throw new XpLockedFieldError('kind', 'draft');
91
+ if (data.analysis?.method != null && data.analysis.method !== 'sequential' && !await admin()) throw new XpLockedFieldError('analysis.method', 'draft');
92
+ return result;
93
+ }
94
+ const status = originalDoc.status;
95
+ const editable = EDITABLE_BY_STATUS[status] ?? [];
96
+ const check = async (field, value, before)=>{
97
+ if (same(value, before, field)) return;
98
+ if (!editable.includes(field.split('.')[0])) throw new XpLockedFieldError(field, status);
99
+ if (field === 'analysis.method' && !await admin()) throw new XpLockedFieldError(field, status);
100
+ if (field === 'arms' && status !== 'draft') {
101
+ if (Array.isArray(value) && Array.isArray(before)) {
102
+ const byId = new Map(before.filter((arm)=>arm.id != null).map((arm)=>[
103
+ String(arm.id),
104
+ arm
105
+ ]));
106
+ const changedKey = value.some((arm, index)=>{
107
+ // An unmatched id is a new row; without ids, position identifies an existing row.
108
+ const previous = arm.id != null && byId.size > 0 ? byId.get(String(arm.id)) : before[index];
109
+ return previous !== undefined && arm.key !== previous.key;
110
+ });
111
+ if (changedKey) throw new XpLockedFieldError('arms.key', status);
112
+ }
113
+ }
114
+ };
115
+ // Payload owns the timestamps. It rewrites `updatedAt` on every save, but stores a
116
+ // client-sent `createdAt` as given, so pin it to the stored value (a Restore's
117
+ // version carries the same value, so Restores are unaffected).
118
+ if ('createdAt' in data) data.createdAt = originalDoc.createdAt;
119
+ for (const [field, value] of Object.entries(data)){
120
+ if (field === 'updatedAt' || field === 'createdAt') continue;
121
+ if ([
122
+ 'analysis',
123
+ 'metrics',
124
+ 'decision'
125
+ ].includes(field) && isObject(value)) {
126
+ for (const [key, nested] of Object.entries(value))await check(`${field}.${key}`, nested, originalDoc[field]?.[key]);
127
+ } else {
128
+ await check(field, value, originalDoc[field]);
129
+ // Replacing the group also changes its method, including clearing it.
130
+ if (field === 'analysis' && !same(value, originalDoc.analysis, field) && originalDoc.analysis?.method != null && !await admin()) throw new XpLockedFieldError('analysis.method', status);
131
+ }
132
+ }
133
+ return data;
134
+ };
@@ -0,0 +1,3 @@
1
+ import type { CollectionConfig } from 'payload';
2
+ import type { ResolvedOptions } from '../types/contracts.js';
3
+ export declare function identitiesCollection(options: ResolvedOptions): CollectionConfig;
@@ -0,0 +1,30 @@
1
+ import { readOnlyAccess } from './access.js';
2
+ export function identitiesCollection(options) {
3
+ return {
4
+ slug: 'xp-identities',
5
+ graphQL: false,
6
+ disableDuplicate: true,
7
+ admin: {
8
+ hidden: true
9
+ },
10
+ access: readOnlyAccess(options.access.readIdentities ?? options.access.admin ?? options.access.manage),
11
+ fields: [
12
+ {
13
+ name: 'anonymousId',
14
+ type: 'text',
15
+ unique: true,
16
+ required: true
17
+ },
18
+ {
19
+ name: 'userId',
20
+ type: 'text',
21
+ required: true
22
+ },
23
+ {
24
+ name: 'linkedAt',
25
+ type: 'date',
26
+ required: true
27
+ }
28
+ ]
29
+ };
30
+ }
@@ -0,0 +1,6 @@
1
+ import type { CollectionConfig, GlobalConfig } from 'payload';
2
+ import type { ResolvedOptions } from '../types/contracts.js';
3
+ export declare function buildCollections(options: ResolvedOptions): {
4
+ collections: CollectionConfig[];
5
+ globals: GlobalConfig[];
6
+ };
@@ -0,0 +1,24 @@
1
+ import { experimentsCollection } from './experiments/config.js';
2
+ import { phasesCollection } from './phases.js';
3
+ import { layersCollection } from './layers.js';
4
+ import { metricsCollection } from './metrics.js';
5
+ import { eventsCollection } from './events.js';
6
+ import { identitiesCollection } from './identities.js';
7
+ import { snapshotsCollection } from './snapshots.js';
8
+ import { stateGlobal } from '../globals/state.js';
9
+ export function buildCollections(options) {
10
+ return {
11
+ collections: [
12
+ experimentsCollection(options),
13
+ phasesCollection(options),
14
+ layersCollection(options),
15
+ metricsCollection(options),
16
+ eventsCollection(options),
17
+ identitiesCollection(options),
18
+ snapshotsCollection(options)
19
+ ],
20
+ globals: [
21
+ stateGlobal(options)
22
+ ]
23
+ };
24
+ }
@@ -0,0 +1,3 @@
1
+ import type { CollectionConfig } from 'payload';
2
+ import type { ResolvedOptions } from '../types/contracts.js';
3
+ export declare function layersCollection(options: ResolvedOptions): CollectionConfig;
@@ -0,0 +1,77 @@
1
+ import { XpRefusal } from '../errors.js';
2
+ import { XP_LAYER_USAGE } from '../admin/paths.js';
3
+ import { managedAccess } from './access.js';
4
+ export function layersCollection(options) {
5
+ return {
6
+ slug: 'xp-layers',
7
+ graphQL: false,
8
+ disableDuplicate: true,
9
+ admin: {
10
+ useAsTitle: 'name'
11
+ },
12
+ access: managedAccess(options),
13
+ fields: [
14
+ {
15
+ name: 'name',
16
+ type: 'text',
17
+ required: true
18
+ },
19
+ {
20
+ name: 'slug',
21
+ type: 'text',
22
+ unique: true,
23
+ required: true,
24
+ validate: (value, { operation, previousValue })=>{
25
+ if (operation === 'update' && value === undefined) return true;
26
+ if (typeof value !== 'string' || !value.length) return 'Enter a slug.';
27
+ return operation !== 'update' || value === previousValue || 'slug is set when the layer is created.';
28
+ }
29
+ },
30
+ {
31
+ name: 'unitType',
32
+ type: 'select',
33
+ required: true,
34
+ options: [
35
+ 'visitor',
36
+ 'user'
37
+ ],
38
+ validate: (value, { operation, previousValue })=>{
39
+ if (operation === 'update' && value === undefined) return true;
40
+ if (value !== 'visitor' && value !== 'user') return 'Choose visitors or signed-in users.';
41
+ return operation !== 'update' || value === previousValue || 'unitType is set when the layer is created.';
42
+ }
43
+ },
44
+ {
45
+ name: 'description',
46
+ type: 'textarea'
47
+ },
48
+ {
49
+ name: 'usage',
50
+ type: 'ui',
51
+ admin: {
52
+ components: {
53
+ Field: XP_LAYER_USAGE
54
+ }
55
+ }
56
+ }
57
+ ],
58
+ hooks: {
59
+ beforeDelete: [
60
+ async ({ id, req })=>{
61
+ const references = await req.payload.find({
62
+ collection: 'xp-experiments',
63
+ where: {
64
+ layer: {
65
+ equals: id
66
+ }
67
+ },
68
+ limit: 1,
69
+ overrideAccess: false,
70
+ req
71
+ });
72
+ if (references.docs.length) throw new XpRefusal('invalid-status', 'This layer is still referenced by an experiment.', undefined, 409);
73
+ }
74
+ ]
75
+ }
76
+ };
77
+ }
@@ -0,0 +1,3 @@
1
+ import type { CollectionConfig } from 'payload';
2
+ import type { ResolvedOptions } from '../types/contracts.js';
3
+ export declare function metricsCollection(options: ResolvedOptions): CollectionConfig;
@@ -0,0 +1,115 @@
1
+ import { XP_METRIC_SOURCE_SELECT } from '../admin/paths.js';
2
+ import { managedAccess } from './access.js';
3
+ import { serializeMetricSources } from './serialize.js';
4
+ export function metricsCollection(options) {
5
+ const sources = serializeMetricSources(options);
6
+ return {
7
+ slug: 'xp-metrics',
8
+ graphQL: false,
9
+ disableDuplicate: true,
10
+ admin: {
11
+ useAsTitle: 'name'
12
+ },
13
+ access: managedAccess(options),
14
+ hooks: {
15
+ beforeValidate: [
16
+ ({ data, originalDoc })=>{
17
+ if (!data) return data;
18
+ const source = sources.find((source)=>source.id === (data.source ?? originalDoc?.source));
19
+ const capping = data.capping === undefined ? originalDoc?.capping : data.capping;
20
+ // Payload may submit an empty optional group as { type: null, value: null }.
21
+ const hasCapping = capping != null && (capping.type != null || capping.value != null);
22
+ if (source?.kind === 'revenue' && !hasCapping) data.capping = {
23
+ type: 'percentile',
24
+ value: 0.99
25
+ };
26
+ return data;
27
+ }
28
+ ]
29
+ },
30
+ fields: [
31
+ {
32
+ name: 'name',
33
+ type: 'text',
34
+ required: true
35
+ },
36
+ {
37
+ name: 'slug',
38
+ type: 'text',
39
+ required: true,
40
+ unique: true
41
+ },
42
+ {
43
+ name: 'source',
44
+ type: 'text',
45
+ required: true,
46
+ validate: (value)=>sources.some((source)=>source.id === value) || 'Choose a registered metric source.',
47
+ admin: {
48
+ components: {
49
+ Field: XP_METRIC_SOURCE_SELECT
50
+ },
51
+ custom: {
52
+ sources
53
+ }
54
+ }
55
+ },
56
+ {
57
+ name: 'direction',
58
+ type: 'select',
59
+ required: true,
60
+ defaultValue: 'increase',
61
+ options: [
62
+ 'increase',
63
+ 'decrease'
64
+ ]
65
+ },
66
+ {
67
+ name: 'attributionWindowHours',
68
+ type: 'number',
69
+ defaultValue: 168,
70
+ min: 1
71
+ },
72
+ {
73
+ name: 'capping',
74
+ type: 'group',
75
+ fields: [
76
+ {
77
+ name: 'type',
78
+ type: 'select',
79
+ options: [
80
+ 'percentile',
81
+ 'absolute'
82
+ ],
83
+ validate: (value, { data, siblingData })=>{
84
+ const hasCapping = value != null || siblingData?.value != null;
85
+ const source = sources.find((source)=>source.id === data?.source);
86
+ if (hasCapping && source && source.kind !== 'revenue') return 'Count and conversion metrics cannot be capped.';
87
+ return !hasCapping || value === 'percentile' || value === 'absolute' || 'Choose a capping type.';
88
+ }
89
+ },
90
+ {
91
+ name: 'value',
92
+ type: 'number',
93
+ min: 0,
94
+ validate: (value, { siblingData })=>{
95
+ if (value == null && !siblingData?.type) return true;
96
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0 && (siblingData?.type === 'absolute' || siblingData?.type === 'percentile' && value > 0 && value <= 1) || 'Enter a valid cap (percentiles must be greater than 0 and at most 1).';
97
+ }
98
+ }
99
+ ]
100
+ },
101
+ {
102
+ name: 'minSampleSize',
103
+ type: 'number',
104
+ defaultValue: 150,
105
+ min: 1
106
+ },
107
+ {
108
+ name: 'guardrailThreshold',
109
+ type: 'number',
110
+ defaultValue: 0.05,
111
+ min: 0
112
+ }
113
+ ]
114
+ };
115
+ }
@@ -0,0 +1,3 @@
1
+ import type { CollectionConfig } from 'payload';
2
+ import type { ResolvedOptions } from '../types/contracts.js';
3
+ export declare function phasesCollection(options: ResolvedOptions): CollectionConfig;
@@ -0,0 +1,59 @@
1
+ import { readOnlyAccess } from './access.js';
2
+ export function phasesCollection(options) {
3
+ return {
4
+ slug: 'xp-phases',
5
+ graphQL: false,
6
+ disableDuplicate: true,
7
+ admin: {
8
+ hidden: true
9
+ },
10
+ access: readOnlyAccess(options.access.readResults ?? options.access.manage),
11
+ fields: [
12
+ {
13
+ name: 'experiment',
14
+ type: 'relationship',
15
+ relationTo: 'xp-experiments'
16
+ },
17
+ {
18
+ name: 'phase',
19
+ type: 'number',
20
+ required: true
21
+ },
22
+ {
23
+ name: 'phaseKind',
24
+ type: 'select',
25
+ required: true,
26
+ options: [
27
+ 'test',
28
+ 'rollout'
29
+ ]
30
+ },
31
+ {
32
+ name: 'startedAt',
33
+ type: 'date',
34
+ required: true
35
+ },
36
+ {
37
+ name: 'endedAt',
38
+ type: 'date'
39
+ },
40
+ {
41
+ name: 'seed',
42
+ type: 'text',
43
+ required: true
44
+ },
45
+ ...[
46
+ 'arms',
47
+ 'allocation',
48
+ 'allocationChanges',
49
+ 'targeting',
50
+ 'metricDefinitions',
51
+ 'analysis',
52
+ 'contentChanges'
53
+ ].map((name)=>({
54
+ name,
55
+ type: 'json'
56
+ }))
57
+ ]
58
+ };
59
+ }
@@ -0,0 +1,5 @@
1
+ import type { ResolvedOptions } from '../types/contracts.js';
2
+ import type { SerializedAttributeKeys, SerializedFlagPoint, SerializedMetricSource } from '../types/admin.js';
3
+ export declare function serializeFlagPoints(options: ResolvedOptions): SerializedFlagPoint[];
4
+ export declare function serializeMetricSources(options: ResolvedOptions): SerializedMetricSource[];
5
+ export declare function serializeAttributeKeys(options: ResolvedOptions): SerializedAttributeKeys;
@@ -0,0 +1,40 @@
1
+ export function serializeFlagPoints(options) {
2
+ return (options.flagPoints ?? []).map(({ id, label, params, defaultParams })=>({
3
+ id,
4
+ label,
5
+ params,
6
+ defaultParams,
7
+ effectiveDefaults: defaultParams
8
+ }));
9
+ }
10
+ export function serializeMetricSources(options) {
11
+ return [
12
+ ...(options.metricSources ?? []).map(({ id, label, kind, keyedBy, clientWritable })=>({
13
+ id,
14
+ label,
15
+ kind,
16
+ keyedBy,
17
+ clientWritable: clientWritable === true
18
+ })),
19
+ ...(options.eventSources ?? []).map(({ name, clientWritable })=>({
20
+ id: `events:${name}`,
21
+ label: name,
22
+ kind: 'binomial',
23
+ keyedBy: 'visitor',
24
+ clientWritable
25
+ }))
26
+ ];
27
+ }
28
+ export function serializeAttributeKeys(options) {
29
+ return Object.fromEntries(Object.entries(options.attributeKeys ?? {}).map(([key, { type, values }])=>[
30
+ key,
31
+ {
32
+ type,
33
+ ...values ? {
34
+ values: [
35
+ ...values
36
+ ]
37
+ } : {}
38
+ }
39
+ ]));
40
+ }
@@ -0,0 +1,3 @@
1
+ import type { CollectionConfig } from 'payload';
2
+ import type { ResolvedOptions } from '../types/contracts.js';
3
+ export declare function snapshotsCollection(options: ResolvedOptions): CollectionConfig;
@@ -0,0 +1,47 @@
1
+ import { readOnlyAccess } from './access.js';
2
+ export function snapshotsCollection(options) {
3
+ return {
4
+ slug: 'xp-results-snapshots',
5
+ graphQL: false,
6
+ disableDuplicate: true,
7
+ admin: {
8
+ hidden: true
9
+ },
10
+ access: readOnlyAccess(options.access.readResults ?? options.access.manage),
11
+ indexes: [
12
+ {
13
+ fields: [
14
+ 'experiment',
15
+ 'computedAt'
16
+ ]
17
+ }
18
+ ],
19
+ fields: [
20
+ {
21
+ name: 'experiment',
22
+ type: 'relationship',
23
+ relationTo: 'xp-experiments'
24
+ },
25
+ {
26
+ name: 'phase',
27
+ type: 'number',
28
+ required: true
29
+ },
30
+ {
31
+ name: 'computedAt',
32
+ type: 'date',
33
+ required: true
34
+ },
35
+ {
36
+ name: 'window',
37
+ type: 'json',
38
+ required: true
39
+ },
40
+ {
41
+ name: 'snapshot',
42
+ type: 'json',
43
+ required: true
44
+ }
45
+ ]
46
+ };
47
+ }
@@ -0,0 +1,7 @@
1
+ export declare const MAX_EVENTS_PER_BODY = 20;
2
+ export declare const DEFAULT_MAX_BODY_BYTES = 8192;
3
+ export declare const XP_COOKIE = "xp_id";
4
+ export declare const XP_HEADER = "x-xp-assignments";
5
+ export declare const XP_PREVIEW_PARAM = "xp_preview";
6
+ export declare const XP_MANIFEST_KEY_HEADER = "x-xp-manifest-key";
7
+ export declare const XP_REQUEST_HEADER = "x-xp-request";
@@ -0,0 +1,7 @@
1
+ export const MAX_EVENTS_PER_BODY = 20;
2
+ export const DEFAULT_MAX_BODY_BYTES = 8192;
3
+ export const XP_COOKIE = 'xp_id';
4
+ export const XP_HEADER = 'x-xp-assignments';
5
+ export const XP_PREVIEW_PARAM = 'xp_preview';
6
+ export const XP_MANIFEST_KEY_HEADER = 'x-xp-manifest-key';
7
+ export const XP_REQUEST_HEADER = 'x-xp-request';
@@ -0,0 +1,3 @@
1
+ import type { Payload } from 'payload';
2
+ export declare function assertPostgresAdapter(payload: Payload): void;
3
+ export declare function probeTransactions(payload: Payload): Promise<void>;
@@ -0,0 +1,9 @@
1
+ export function assertPostgresAdapter(payload) {
2
+ // @payloadcms/db-postgres/dist/index.js:133 declares this package marker.
3
+ if (payload.db.packageName !== '@payloadcms/db-postgres') throw new Error('Experiments requires @payloadcms/db-postgres');
4
+ }
5
+ export async function probeTransactions(payload) {
6
+ const id = await payload.db.beginTransaction();
7
+ if (id == null) throw new Error('Experiments transactions are disabled');
8
+ await payload.db.rollbackTransaction(id);
9
+ }
@@ -0,0 +1,58 @@
1
+ import type { Executor } from './executor.js';
2
+ import type { PayloadRequest } from 'payload';
3
+ import type { DocId } from '../types/contracts.js';
4
+ export interface AllocationChange {
5
+ at: string;
6
+ from: number;
7
+ to: number;
8
+ }
9
+ export interface ContentChange {
10
+ at: string;
11
+ doc: {
12
+ collection: string;
13
+ id: DocId;
14
+ };
15
+ by: DocId | null;
16
+ }
17
+ type AppendArgs<T> = {
18
+ experimentId: DocId;
19
+ phase: number;
20
+ entry: T;
21
+ };
22
+ /** Read the main collection row BEFORE the host write. Draft version retention
23
+ * and unpublishing cannot remove this baseline. Adapter reads avoid Local API
24
+ * error handling killing the host transaction before savepoint recovery.
25
+ */
26
+ export declare function previousPublishedContent(req: PayloadRequest, collection: string, id: DocId): Promise<Record<string, unknown> | undefined>;
27
+ /** Serialize flagDefaults read/modify/write before the manifest builder bumps. */
28
+ export declare function lockContentDefaults(exec: Executor): Promise<void>;
29
+ /** §7.8 contentChanges exception: internal lookup on the host transaction.
30
+ * Use the executor directly: Payload Local API read errors kill the caller's
31
+ * transaction before a never-throw hook can recover its audit savepoint.
32
+ */
33
+ export declare function runningContentExperiment(exec: Executor, binding: {
34
+ field: 'id' | 'slug';
35
+ value: DocId;
36
+ }): Promise<{
37
+ id: DocId;
38
+ phase: number;
39
+ } | undefined>;
40
+ /** Requires the experiment lock on the transaction executor (withTransition).
41
+ * The generated schema stores allocationChanges as one JSONB column, not rows.
42
+ */
43
+ export declare function appendAllocationChange(exec: Executor, args: AppendArgs<AllocationChange>): Promise<void>;
44
+ /** Requires the experiment lock on the transaction executor (withTransition).
45
+ * The generated schema stores contentChanges as one JSONB column, not rows.
46
+ */
47
+ export declare function appendContentChange(exec: Executor, args: AppendArgs<ContentChange>): Promise<void>;
48
+ /** A best-effort audit must not abort the host write sharing its transaction.
49
+ * Recover SQL errors before returning them: catching alone leaves Postgres aborted.
50
+ */
51
+ export declare function contentChangeSavepoint<T>(exec: Executor, fn: () => Promise<T>): Promise<{
52
+ ok: true;
53
+ result: T;
54
+ } | {
55
+ ok: false;
56
+ error: unknown;
57
+ }>;
58
+ export {};