@10x-media/form-builder 0.1.0-beta.4 → 0.1.0-beta.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 (372) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/README.md +3 -3
  3. package/dist/actions/body/serializeBody.d.ts +8 -5
  4. package/dist/actions/body/serializeBody.js.map +1 -1
  5. package/dist/actions/body/textOfBody.d.ts +13 -0
  6. package/dist/actions/body/textOfBody.js +35 -0
  7. package/dist/actions/body/textOfBody.js.map +1 -0
  8. package/dist/actions/builtin/confirmation.js +81 -48
  9. package/dist/actions/builtin/confirmation.js.map +1 -1
  10. package/dist/actions/builtin/emailTeam.js +67 -38
  11. package/dist/actions/builtin/emailTeam.js.map +1 -1
  12. package/dist/actions/builtin/index.d.ts +9 -3
  13. package/dist/actions/builtin/index.js +8 -5
  14. package/dist/actions/builtin/index.js.map +1 -1
  15. package/dist/actions/defineAction.d.ts +1 -1
  16. package/dist/actions/emailRecipients.d.ts +12 -0
  17. package/dist/actions/emailRecipients.js +72 -0
  18. package/dist/actions/emailRecipients.js.map +1 -0
  19. package/dist/actions/fromAddresses.d.ts +21 -0
  20. package/dist/actions/fromAddresses.js +74 -0
  21. package/dist/actions/fromAddresses.js.map +1 -0
  22. package/dist/actions/task.js +9 -8
  23. package/dist/actions/task.js.map +1 -1
  24. package/dist/aggregation/aggregateResponses.d.ts +9 -0
  25. package/dist/aggregation/aggregateResponses.js +8 -14
  26. package/dist/aggregation/aggregateResponses.js.map +1 -1
  27. package/dist/aggregation/resolveResultsRequest.d.ts +19 -6
  28. package/dist/aggregation/resolveResultsRequest.js +58 -12
  29. package/dist/aggregation/resolveResultsRequest.js.map +1 -1
  30. package/dist/calc/computeCalcFields.js +2 -1
  31. package/dist/calc/computeCalcFields.js.map +1 -1
  32. package/dist/client/ByteSizeField.d.ts +8 -0
  33. package/dist/client/ByteSizeField.js +3 -1
  34. package/dist/client/ByteSizeField.js.map +1 -1
  35. package/dist/client/ClosePollButton.d.ts +15 -0
  36. package/dist/client/ClosePollButton.js +80 -0
  37. package/dist/client/ClosePollButton.js.map +1 -0
  38. package/dist/client/CondensedArray.d.ts +15 -0
  39. package/dist/client/CondensedArray.js +97 -0
  40. package/dist/client/CondensedArray.js.map +1 -0
  41. package/dist/client/ConsentBlockLabel.d.ts +15 -0
  42. package/dist/client/ConsentBlockLabel.js +71 -0
  43. package/dist/client/ConsentBlockLabel.js.map +1 -0
  44. package/dist/client/ConsentSourceRowLabel.d.ts +9 -0
  45. package/dist/client/ConsentSourceRowLabel.js +21 -0
  46. package/dist/client/ConsentSourceRowLabel.js.map +1 -0
  47. package/dist/client/EndpointOptionsSelect.d.ts +46 -0
  48. package/dist/client/EndpointOptionsSelect.js +106 -0
  49. package/dist/client/EndpointOptionsSelect.js.map +1 -0
  50. package/dist/client/FieldBlockLabel.d.ts +18 -0
  51. package/dist/client/FieldBlockLabel.js +34 -0
  52. package/dist/client/FieldBlockLabel.js.map +1 -0
  53. package/dist/client/FieldNameSelect.d.ts +21 -4
  54. package/dist/client/FieldNameSelect.js +29 -15
  55. package/dist/client/FieldNameSelect.js.map +1 -1
  56. package/dist/client/FlowBuilder.d.ts +2 -1
  57. package/dist/client/FlowBuilder.js +63 -57
  58. package/dist/client/FlowBuilder.js.map +1 -1
  59. package/dist/client/RecipientsSelect.d.ts +31 -0
  60. package/dist/client/RecipientsSelect.js +174 -0
  61. package/dist/client/RecipientsSelect.js.map +1 -0
  62. package/dist/client/RuleDescription.d.ts +21 -0
  63. package/dist/client/RuleDescription.js +19 -0
  64. package/dist/client/RuleDescription.js.map +1 -0
  65. package/dist/client/admin.css +41 -0
  66. package/dist/client/endpointOptions.js +29 -0
  67. package/dist/client/endpointOptions.js.map +1 -0
  68. package/dist/client/flowAuthoring.js +114 -7
  69. package/dist/client/flowAuthoring.js.map +1 -1
  70. package/dist/client/synthesizeClientField.js +15 -8
  71. package/dist/client/synthesizeClientField.js.map +1 -1
  72. package/dist/collections/buttonFields.d.ts +34 -0
  73. package/dist/collections/buttonFields.js +35 -0
  74. package/dist/collections/buttonFields.js.map +1 -0
  75. package/dist/collections/cells/FieldCountCell.d.ts +15 -0
  76. package/dist/collections/cells/FieldCountCell.js +18 -0
  77. package/dist/collections/cells/FieldCountCell.js.map +1 -0
  78. package/dist/collections/cells/FlowStepsCell.d.ts +14 -0
  79. package/dist/collections/cells/FlowStepsCell.js +17 -0
  80. package/dist/collections/cells/FlowStepsCell.js.map +1 -0
  81. package/dist/collections/formSubmissions.js +23 -17
  82. package/dist/collections/formSubmissions.js.map +1 -1
  83. package/dist/collections/forms.js +323 -134
  84. package/dist/collections/forms.js.map +1 -1
  85. package/dist/collections/redirectFields.d.ts +29 -0
  86. package/dist/consent/applyConsentStatements.d.ts +14 -0
  87. package/dist/consent/applyConsentStatements.js +17 -0
  88. package/dist/consent/applyConsentStatements.js.map +1 -0
  89. package/dist/consent/captureConsent.d.ts +31 -11
  90. package/dist/consent/captureConsent.js +53 -13
  91. package/dist/consent/captureConsent.js.map +1 -1
  92. package/dist/consent/consentSourcesField.d.ts +62 -0
  93. package/dist/consent/consentSourcesField.js +86 -0
  94. package/dist/consent/consentSourcesField.js.map +1 -0
  95. package/dist/consent/resolveConsentEntries.d.ts +24 -0
  96. package/dist/consent/resolveConsentEntries.js +43 -0
  97. package/dist/consent/resolveConsentEntries.js.map +1 -0
  98. package/dist/consent/resolveConsentSourcesRequest.d.ts +37 -0
  99. package/dist/consent/resolveConsentSourcesRequest.js +55 -0
  100. package/dist/consent/resolveConsentSourcesRequest.js.map +1 -0
  101. package/dist/consent/resolveConsentStatements.d.ts +45 -0
  102. package/dist/consent/resolveConsentStatements.js +44 -0
  103. package/dist/consent/resolveConsentStatements.js.map +1 -0
  104. package/dist/consent/resolvePublishedVersionRef.d.ts +17 -11
  105. package/dist/consent/resolvePublishedVersionRef.js +13 -10
  106. package/dist/consent/resolvePublishedVersionRef.js.map +1 -1
  107. package/dist/consent/types.d.ts +53 -0
  108. package/dist/email/departments.d.ts +59 -0
  109. package/dist/email/departments.js +87 -0
  110. package/dist/email/departments.js.map +1 -0
  111. package/dist/email/departmentsField.d.ts +53 -0
  112. package/dist/email/departmentsField.js +73 -0
  113. package/dist/email/departmentsField.js.map +1 -0
  114. package/dist/exports/client.d.ts +11 -1
  115. package/dist/exports/client.js +11 -1
  116. package/dist/exports/react.d.ts +8 -3
  117. package/dist/exports/react.js +6 -2
  118. package/dist/exports/rsc.d.ts +3 -1
  119. package/dist/exports/rsc.js +4 -2
  120. package/dist/exports/types.d.ts +16 -8
  121. package/dist/fields/buildFieldBlocks.js +28 -13
  122. package/dist/fields/buildFieldBlocks.js.map +1 -1
  123. package/dist/fields/builtin/calculation.js +7 -0
  124. package/dist/fields/builtin/calculation.js.map +1 -1
  125. package/dist/fields/builtin/checkbox.js +8 -0
  126. package/dist/fields/builtin/checkbox.js.map +1 -1
  127. package/dist/fields/builtin/consent.js +32 -21
  128. package/dist/fields/builtin/consent.js.map +1 -1
  129. package/dist/fields/builtin/country.d.ts +13 -0
  130. package/dist/fields/builtin/country.js +30 -0
  131. package/dist/fields/builtin/country.js.map +1 -0
  132. package/dist/fields/builtin/date.js +2 -0
  133. package/dist/fields/builtin/date.js.map +1 -1
  134. package/dist/fields/builtin/file.js +14 -7
  135. package/dist/fields/builtin/file.js.map +1 -1
  136. package/dist/fields/builtin/index.d.ts +8 -6
  137. package/dist/fields/builtin/index.js +12 -11
  138. package/dist/fields/builtin/index.js.map +1 -1
  139. package/dist/fields/builtin/message.js +8 -4
  140. package/dist/fields/builtin/message.js.map +1 -1
  141. package/dist/fields/builtin/repeater.js +1 -0
  142. package/dist/fields/builtin/repeater.js.map +1 -1
  143. package/dist/fields/builtin/select.js +1 -0
  144. package/dist/fields/builtin/select.js.map +1 -1
  145. package/dist/fields/builtin/state.d.ts +13 -0
  146. package/dist/fields/builtin/state.js +30 -0
  147. package/dist/fields/builtin/state.js.map +1 -0
  148. package/dist/fields/data/regions.d.ts +21 -0
  149. package/dist/fields/data/regions.js +1238 -0
  150. package/dist/fields/data/regions.js.map +1 -0
  151. package/dist/fields/fieldKey.d.ts +15 -0
  152. package/dist/fields/fieldKey.js +16 -0
  153. package/dist/fields/fieldKey.js.map +1 -0
  154. package/dist/fields/fieldNamesOfType.js +13 -8
  155. package/dist/fields/fieldNamesOfType.js.map +1 -1
  156. package/dist/fields/instanceOptions.js +20 -0
  157. package/dist/fields/instanceOptions.js.map +1 -0
  158. package/dist/fields/registry.d.ts +1 -0
  159. package/dist/fields/registry.js +21 -2
  160. package/dist/fields/registry.js.map +1 -1
  161. package/dist/fields/sharedConfig.js +46 -9
  162. package/dist/fields/sharedConfig.js.map +1 -1
  163. package/dist/fields/types.d.ts +63 -5
  164. package/dist/flow/engine.d.ts +6 -4
  165. package/dist/flow/engine.js +11 -6
  166. package/dist/flow/engine.js.map +1 -1
  167. package/dist/flow/normalizeFlow.js +16 -7
  168. package/dist/flow/normalizeFlow.js.map +1 -1
  169. package/dist/flow/types.d.ts +12 -3
  170. package/dist/flow/types.js +11 -0
  171. package/dist/flow/types.js.map +1 -0
  172. package/dist/form/pollState.d.ts +4 -4
  173. package/dist/form/pollState.js.map +1 -1
  174. package/dist/form/toFormDocument.d.ts +54 -12
  175. package/dist/form/toFormDocument.js +56 -8
  176. package/dist/form/toFormDocument.js.map +1 -1
  177. package/dist/form/types.d.ts +31 -14
  178. package/dist/index.d.ts +153 -29
  179. package/dist/index.js +47 -15
  180. package/dist/index.js.map +1 -1
  181. package/dist/plugin/customState.js +26 -0
  182. package/dist/plugin/customState.js.map +1 -0
  183. package/dist/plugin/registerCollections.js +24 -13
  184. package/dist/plugin/registerCollections.js.map +1 -1
  185. package/dist/plugin/uploadsCollection.d.ts +5 -0
  186. package/dist/plugin/uploadsCollection.js +10 -1
  187. package/dist/plugin/uploadsCollection.js.map +1 -1
  188. package/dist/poll/applyPollOptions.js +3 -2
  189. package/dist/poll/applyPollOptions.js.map +1 -1
  190. package/dist/poll/buildPollOptionSourceFields.js +2 -5
  191. package/dist/poll/buildPollOptionSourceFields.js.map +1 -1
  192. package/dist/poll/closeJob.d.ts +52 -0
  193. package/dist/poll/closeJob.js +119 -0
  194. package/dist/poll/closeJob.js.map +1 -0
  195. package/dist/poll/definePollOptionSource.d.ts +10 -1
  196. package/dist/poll/definePollOptionSource.js.map +1 -1
  197. package/dist/poll/definePollType.d.ts +34 -0
  198. package/dist/poll/definePollType.js +6 -0
  199. package/dist/poll/definePollType.js.map +1 -0
  200. package/dist/poll/effectivePollOptions.d.ts +38 -0
  201. package/dist/poll/effectivePollOptions.js +64 -0
  202. package/dist/poll/effectivePollOptions.js.map +1 -0
  203. package/dist/poll/mostVoted.d.ts +21 -0
  204. package/dist/poll/mostVoted.js +32 -0
  205. package/dist/poll/mostVoted.js.map +1 -0
  206. package/dist/poll/outcomeBeforeChange.js +91 -0
  207. package/dist/poll/outcomeBeforeChange.js.map +1 -0
  208. package/dist/poll/outcomeFields.d.ts +38 -0
  209. package/dist/poll/outcomeFields.js +52 -0
  210. package/dist/poll/outcomeFields.js.map +1 -0
  211. package/dist/poll/pollTypeRegistry.d.ts +34 -0
  212. package/dist/poll/pollTypeRegistry.js +71 -0
  213. package/dist/poll/pollTypeRegistry.js.map +1 -0
  214. package/dist/poll/resolvePollCloseRequest.js +105 -0
  215. package/dist/poll/resolvePollCloseRequest.js.map +1 -0
  216. package/dist/poll/resolvePollOptions.d.ts +2 -1
  217. package/dist/poll/resolvePollOptions.js +5 -17
  218. package/dist/poll/resolvePollOptions.js.map +1 -1
  219. package/dist/poll/resolvePollOptionsRequest.js +51 -0
  220. package/dist/poll/resolvePollOptionsRequest.js.map +1 -0
  221. package/dist/poll/resolvePollOutcome.d.ts +22 -9
  222. package/dist/poll/resolvePollOutcome.js +54 -14
  223. package/dist/poll/resolvePollOutcome.js.map +1 -1
  224. package/dist/poll/resultsField.js +21 -0
  225. package/dist/poll/resultsField.js.map +1 -0
  226. package/dist/prefill/valuesFromSearchParams.js +2 -1
  227. package/dist/prefill/valuesFromSearchParams.js.map +1 -1
  228. package/dist/react/Form.d.ts +8 -8
  229. package/dist/react/Form.js +74 -62
  230. package/dist/react/Form.js.map +1 -1
  231. package/dist/react/FormContext.d.ts +6 -4
  232. package/dist/react/FormContext.js.map +1 -1
  233. package/dist/react/FormControls.d.ts +3 -3
  234. package/dist/react/FormControls.js +3 -3
  235. package/dist/react/FormControls.js.map +1 -1
  236. package/dist/react/FormResults.d.ts +5 -5
  237. package/dist/react/FormResults.js +6 -6
  238. package/dist/react/FormResults.js.map +1 -1
  239. package/dist/react/Poll.d.ts +2 -2
  240. package/dist/react/Poll.js +5 -5
  241. package/dist/react/Poll.js.map +1 -1
  242. package/dist/react/contract.d.ts +2 -3
  243. package/dist/react/contract.js.map +1 -1
  244. package/dist/react/primitives/Checkbox.d.ts +4 -2
  245. package/dist/react/primitives/Checkbox.js +2 -1
  246. package/dist/react/primitives/Checkbox.js.map +1 -1
  247. package/dist/react/primitives/FieldShell.d.ts +2 -4
  248. package/dist/react/primitives/FieldShell.js +12 -19
  249. package/dist/react/primitives/FieldShell.js.map +1 -1
  250. package/dist/react/renderers/calculation.js +1 -2
  251. package/dist/react/renderers/calculation.js.map +1 -1
  252. package/dist/react/renderers/checkbox.js +1 -2
  253. package/dist/react/renderers/checkbox.js.map +1 -1
  254. package/dist/react/renderers/consent.js +78 -34
  255. package/dist/react/renderers/consent.js.map +1 -1
  256. package/dist/react/renderers/date.js +1 -3
  257. package/dist/react/renderers/date.js.map +1 -1
  258. package/dist/react/renderers/email.js +1 -2
  259. package/dist/react/renderers/email.js.map +1 -1
  260. package/dist/react/renderers/file.js +1 -2
  261. package/dist/react/renderers/file.js.map +1 -1
  262. package/dist/react/renderers/index.js +3 -0
  263. package/dist/react/renderers/index.js.map +1 -1
  264. package/dist/react/renderers/number.js +1 -2
  265. package/dist/react/renderers/number.js.map +1 -1
  266. package/dist/react/renderers/region.js +45 -0
  267. package/dist/react/renderers/region.js.map +1 -0
  268. package/dist/react/renderers/repeater.js +7 -10
  269. package/dist/react/renderers/repeater.js.map +1 -1
  270. package/dist/react/renderers/select.js +1 -2
  271. package/dist/react/renderers/select.js.map +1 -1
  272. package/dist/react/renderers/text.js +1 -2
  273. package/dist/react/renderers/text.js.map +1 -1
  274. package/dist/react/renderers/textarea.js +1 -2
  275. package/dist/react/renderers/textarea.js.map +1 -1
  276. package/dist/react/state.d.ts +0 -3
  277. package/dist/react/state.js +7 -11
  278. package/dist/react/state.js.map +1 -1
  279. package/dist/react/useField.d.ts +0 -1
  280. package/dist/react/useField.js +0 -1
  281. package/dist/react/useField.js.map +1 -1
  282. package/dist/react/useFormState.d.ts +1 -1
  283. package/dist/react/useFormState.js +1 -1
  284. package/dist/react/useFormState.js.map +1 -1
  285. package/dist/react/validateField.js +3 -6
  286. package/dist/react/validateField.js.map +1 -1
  287. package/dist/recall/interpolate.d.ts +4 -3
  288. package/dist/recall/interpolate.js +5 -4
  289. package/dist/recall/interpolate.js.map +1 -1
  290. package/dist/recall/resolver.d.ts +1 -1
  291. package/dist/recall/resolver.js +14 -2
  292. package/dist/recall/resolver.js.map +1 -1
  293. package/dist/spam/captcha.d.ts +1 -1
  294. package/dist/spam/captcha.js +1 -1
  295. package/dist/spam/captcha.js.map +1 -1
  296. package/dist/submissions/SubmissionAnswers.js +6 -2
  297. package/dist/submissions/SubmissionAnswers.js.map +1 -1
  298. package/dist/submissions/SubmissionAnswersClient.js +100 -64
  299. package/dist/submissions/SubmissionAnswersClient.js.map +1 -1
  300. package/dist/submissions/createSubmission.d.ts +36 -0
  301. package/dist/submissions/createSubmission.js +26 -0
  302. package/dist/submissions/createSubmission.js.map +1 -0
  303. package/dist/submissions/runSubmission.d.ts +10 -0
  304. package/dist/submissions/runSubmission.js +31 -19
  305. package/dist/submissions/runSubmission.js.map +1 -1
  306. package/dist/submissions/types.d.ts +11 -4
  307. package/dist/submissions/validateSubmission.js +39 -23
  308. package/dist/submissions/validateSubmission.js.map +1 -1
  309. package/dist/submissions/votedCookie.js +3 -3
  310. package/dist/submissions/votedCookie.js.map +1 -1
  311. package/dist/translations/de.js +104 -26
  312. package/dist/translations/de.js.map +1 -1
  313. package/dist/translations/en.js +105 -27
  314. package/dist/translations/en.js.map +1 -1
  315. package/dist/translations/keys.d.ts +99 -21
  316. package/dist/translations/keys.js +100 -22
  317. package/dist/translations/keys.js.map +1 -1
  318. package/dist/uploads/resolveFileRef.js +2 -1
  319. package/dist/uploads/resolveFileRef.js.map +1 -1
  320. package/dist/validation/buildRuleBlocks.js +18 -17
  321. package/dist/validation/buildRuleBlocks.js.map +1 -1
  322. package/dist/validation/builtin/email.js +1 -0
  323. package/dist/validation/builtin/email.js.map +1 -1
  324. package/dist/validation/builtin/matchesField.js +3 -7
  325. package/dist/validation/builtin/matchesField.js.map +1 -1
  326. package/dist/validation/builtin/max.js +1 -0
  327. package/dist/validation/builtin/max.js.map +1 -1
  328. package/dist/validation/builtin/maxDate.js +1 -0
  329. package/dist/validation/builtin/maxDate.js.map +1 -1
  330. package/dist/validation/builtin/maxLength.js +1 -0
  331. package/dist/validation/builtin/maxLength.js.map +1 -1
  332. package/dist/validation/builtin/min.js +1 -0
  333. package/dist/validation/builtin/min.js.map +1 -1
  334. package/dist/validation/builtin/minDate.js +1 -0
  335. package/dist/validation/builtin/minDate.js.map +1 -1
  336. package/dist/validation/builtin/minLength.js +1 -0
  337. package/dist/validation/builtin/minLength.js.map +1 -1
  338. package/dist/validation/builtin/notAlreadySubmitted.js +1 -0
  339. package/dist/validation/builtin/notAlreadySubmitted.js.map +1 -1
  340. package/dist/validation/builtin/oneOf.js +1 -0
  341. package/dist/validation/builtin/oneOf.js.map +1 -1
  342. package/dist/validation/builtin/pattern.js +11 -2
  343. package/dist/validation/builtin/pattern.js.map +1 -1
  344. package/dist/validation/builtin/url.js +1 -0
  345. package/dist/validation/builtin/url.js.map +1 -1
  346. package/dist/validation/builtin/validateRegexParams.js +44 -0
  347. package/dist/validation/builtin/validateRegexParams.js.map +1 -0
  348. package/dist/validation/fieldTargetParam.d.ts +22 -0
  349. package/dist/validation/fieldTargetParam.js +38 -0
  350. package/dist/validation/fieldTargetParam.js.map +1 -0
  351. package/dist/validation/runValidation.js +8 -29
  352. package/dist/validation/runValidation.js.map +1 -1
  353. package/dist/validation/types.d.ts +5 -11
  354. package/package.json +6 -6
  355. package/dist/consent/buildConsentSourceConfig.js +0 -49
  356. package/dist/consent/buildConsentSourceConfig.js.map +0 -1
  357. package/dist/consent/builtin/index.d.ts +0 -17
  358. package/dist/consent/builtin/index.js +0 -21
  359. package/dist/consent/builtin/index.js.map +0 -1
  360. package/dist/consent/builtin/pageReference.js +0 -75
  361. package/dist/consent/builtin/pageReference.js.map +0 -1
  362. package/dist/consent/builtin/static.js +0 -48
  363. package/dist/consent/builtin/static.js.map +0 -1
  364. package/dist/consent/defineConsentSource.d.ts +0 -35
  365. package/dist/consent/defineConsentSource.js +0 -6
  366. package/dist/consent/defineConsentSource.js.map +0 -1
  367. package/dist/consent/registry.d.ts +0 -16
  368. package/dist/consent/registry.js +0 -16
  369. package/dist/consent/registry.js.map +0 -1
  370. package/dist/consent/resolveConsentLinks.d.ts +0 -19
  371. package/dist/consent/resolveConsentLinks.js +0 -26
  372. package/dist/consent/resolveConsentLinks.js.map +0 -1
@@ -0,0 +1,43 @@
1
+ import { customStateOf, stashCustomState } from "../plugin/customState.js";
2
+ //#region src/consent/resolveConsentEntries.ts
3
+ /** Park the host's resolver on the config so root-level helpers can find it via `payload.config`. */
4
+ const stashConsentSources = (custom, sources) => stashCustomState(custom, { consentSources: sources });
5
+ const consentSourcesOf = (payload) => customStateOf(payload).consentSources;
6
+ const CACHE_KEY = "formBuilderConsentSourcesCache";
7
+ const cacheOf = (req) => {
8
+ if (!req.context) return;
9
+ const existing = req.context[CACHE_KEY];
10
+ if (existing instanceof Map) return existing;
11
+ const created = /* @__PURE__ */ new Map();
12
+ req.context[CACHE_KEY] = created;
13
+ return created;
14
+ };
15
+ /**
16
+ * The host's consent sources for this request, or an empty list when no resolver is configured
17
+ * (in which case the `consent` field type is not registered either, so nothing can reference one).
18
+ * Throws whatever the resolver throws: every caller decides how to fail, and none of them fail open.
19
+ * Cached per request and form id, so one submission resolves the host's sources once no matter how
20
+ * many consent fields the form carries.
21
+ */
22
+ const resolveConsentEntries = async (args) => {
23
+ const { payload, req, form } = args;
24
+ const resolver = args.sources ?? consentSourcesOf(payload);
25
+ if (!resolver) return [];
26
+ const cache = cacheOf(req);
27
+ const cacheKey = String(form.id);
28
+ const cached = cache?.get(cacheKey);
29
+ if (cached) return cached;
30
+ const entries = await resolver({
31
+ req,
32
+ form: {
33
+ id: form.id,
34
+ title: typeof form.title === "string" ? form.title : void 0
35
+ }
36
+ });
37
+ cache?.set(cacheKey, entries);
38
+ return entries;
39
+ };
40
+ //#endregion
41
+ export { resolveConsentEntries, stashConsentSources };
42
+
43
+ //# sourceMappingURL=resolveConsentEntries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveConsentEntries.js","names":[],"sources":["../../src/consent/resolveConsentEntries.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\nimport { customStateOf, stashCustomState } from '../plugin/customState'\nimport type { ConsentSourceEntry, ConsentSourcesResolver } from './types'\n\ntype ConsentCustomState = { consentSources: ConsentSourcesResolver }\n\n/** Park the host's resolver on the config so root-level helpers can find it via `payload.config`. */\nexport const stashConsentSources = (\n\tcustom: Record<string, unknown> | undefined,\n\tsources: ConsentSourcesResolver\n): Record<string, unknown> =>\n\tstashCustomState<ConsentCustomState>(custom, { consentSources: sources })\n\nexport const consentSourcesOf = (payload: Payload): ConsentSourcesResolver | undefined =>\n\tcustomStateOf<ConsentCustomState>(payload).consentSources\n\nconst CACHE_KEY = 'formBuilderConsentSourcesCache'\n\ntype EntriesCache = Map<string, ConsentSourceEntry[]>\n\nconst cacheOf = (req: PayloadRequest): EntriesCache | undefined => {\n\tif (!req.context) {\n\t\treturn undefined\n\t}\n\tconst existing = req.context[CACHE_KEY]\n\tif (existing instanceof Map) {\n\t\treturn existing as EntriesCache\n\t}\n\tconst created: EntriesCache = new Map()\n\treq.context[CACHE_KEY] = created\n\treturn created\n}\n\nexport type ResolveConsentEntriesArgs = {\n\tpayload: Payload\n\treq: PayloadRequest\n\t/** The form whose consent fields are being resolved; handed to the resolver for per-form scoping. */\n\tform: { id: number | string; title?: string | null }\n\t/** Resolver override for plugin-internal callers; defaults to the one the plugin stashed on the config. */\n\tsources?: ConsentSourcesResolver\n}\n\n/**\n * The host's consent sources for this request, or an empty list when no resolver is configured\n * (in which case the `consent` field type is not registered either, so nothing can reference one).\n * Throws whatever the resolver throws: every caller decides how to fail, and none of them fail open.\n * Cached per request and form id, so one submission resolves the host's sources once no matter how\n * many consent fields the form carries.\n */\nexport const resolveConsentEntries = async (\n\targs: ResolveConsentEntriesArgs\n): Promise<ConsentSourceEntry[]> => {\n\tconst { payload, req, form } = args\n\tconst resolver = args.sources ?? consentSourcesOf(payload)\n\tif (!resolver) {\n\t\treturn []\n\t}\n\tconst cache = cacheOf(req)\n\tconst cacheKey = String(form.id)\n\tconst cached = cache?.get(cacheKey)\n\tif (cached) {\n\t\treturn cached\n\t}\n\tconst entries = await resolver({\n\t\treq,\n\t\tform: { id: form.id, title: typeof form.title === 'string' ? form.title : undefined },\n\t})\n\tcache?.set(cacheKey, entries)\n\treturn entries\n}\n"],"mappings":";;;AAOA,MAAa,uBACZ,QACA,YAEA,iBAAqC,QAAQ,EAAE,gBAAgB,QAAQ,CAAC;AAEzE,MAAa,oBAAoB,YAChC,cAAkC,OAAO,EAAE;AAE5C,MAAM,YAAY;AAIlB,MAAM,WAAW,QAAkD;CAClE,IAAI,CAAC,IAAI,SACR;CAED,MAAM,WAAW,IAAI,QAAQ;CAC7B,IAAI,oBAAoB,KACvB,OAAO;CAER,MAAM,0BAAwB,IAAI,IAAI;CACtC,IAAI,QAAQ,aAAa;CACzB,OAAO;AACR;;;;;;;;AAkBA,MAAa,wBAAwB,OACpC,SACmC;CACnC,MAAM,EAAE,SAAS,KAAK,SAAS;CAC/B,MAAM,WAAW,KAAK,WAAW,iBAAiB,OAAO;CACzD,IAAI,CAAC,UACJ,OAAO,CAAC;CAET,MAAM,QAAQ,QAAQ,GAAG;CACzB,MAAM,WAAW,OAAO,KAAK,EAAE;CAC/B,MAAM,SAAS,OAAO,IAAI,QAAQ;CAClC,IAAI,QACH,OAAO;CAER,MAAM,UAAU,MAAM,SAAS;EAC9B;EACA,MAAM;GAAE,IAAI,KAAK;GAAI,OAAO,OAAO,KAAK,UAAU,WAAW,KAAK,QAAQ,KAAA;EAAU;CACrF,CAAC;CACD,OAAO,IAAI,UAAU,OAAO;CAC5B,OAAO;AACR"}
@@ -0,0 +1,37 @@
1
+ import { ConsentSourcesResolver } from "./types.js";
2
+ import { Payload, PayloadRequest } from "payload";
3
+
4
+ //#region src/consent/resolveConsentSourcesRequest.d.ts
5
+ /** One selectable consent source for the consent field's `source` select. */
6
+ type ConsentSourceOption = {
7
+ label: string;
8
+ value: string;
9
+ };
10
+ type ResolveConsentSourcesRequestArgs = {
11
+ payload: Payload;
12
+ formId: number | string | undefined; /** Whether the caller is authenticated (an admin/user). */
13
+ isAuthed: boolean;
14
+ req: PayloadRequest;
15
+ resolver: ConsentSourcesResolver;
16
+ };
17
+ type ResolveConsentSourcesRequestResult = {
18
+ status: number;
19
+ body: {
20
+ options: ConsentSourceOption[];
21
+ } | {
22
+ errors: {
23
+ message: string;
24
+ }[];
25
+ };
26
+ };
27
+ /**
28
+ * Authorize and resolve the `GET /:id/consent-sources` request backing the consent `source` select:
29
+ * authenticated callers get the host's sources for this request (a multi-tenant resolver scoping by
30
+ * `req` therefore offers an author only their own tenant's), anonymous callers are always refused.
31
+ * Statuses mirror the poll-options endpoint: 400 missing id, 403 unauthenticated, 404 unknown form,
32
+ * 503 when the resolver throws (fail closed).
33
+ */
34
+ declare const resolveConsentSourcesRequest: (args: ResolveConsentSourcesRequestArgs) => Promise<ResolveConsentSourcesRequestResult>;
35
+ //#endregion
36
+ export { ConsentSourceOption, ResolveConsentSourcesRequestArgs, ResolveConsentSourcesRequestResult, resolveConsentSourcesRequest };
37
+ //# sourceMappingURL=resolveConsentSourcesRequest.d.ts.map
@@ -0,0 +1,55 @@
1
+ import { resolveConsentEntries } from "./resolveConsentEntries.js";
2
+ import { FORMS_SLUG } from "../collections/forms.js";
3
+ //#region src/consent/resolveConsentSourcesRequest.ts
4
+ /**
5
+ * Authorize and resolve the `GET /:id/consent-sources` request backing the consent `source` select:
6
+ * authenticated callers get the host's sources for this request (a multi-tenant resolver scoping by
7
+ * `req` therefore offers an author only their own tenant's), anonymous callers are always refused.
8
+ * Statuses mirror the poll-options endpoint: 400 missing id, 403 unauthenticated, 404 unknown form,
9
+ * 503 when the resolver throws (fail closed).
10
+ */
11
+ const resolveConsentSourcesRequest = async (args) => {
12
+ const { payload, formId, isAuthed, req, resolver } = args;
13
+ if (!isAuthed) return {
14
+ status: 403,
15
+ body: { errors: [{ message: "Forbidden" }] }
16
+ };
17
+ if (formId == null) return {
18
+ status: 400,
19
+ body: { errors: [{ message: "Missing form id" }] }
20
+ };
21
+ const form = await payload.findByID({
22
+ collection: FORMS_SLUG,
23
+ id: formId,
24
+ depth: 0,
25
+ overrideAccess: true,
26
+ req
27
+ }).catch(() => null);
28
+ if (!form) return {
29
+ status: 404,
30
+ body: { errors: [{ message: "Not found" }] }
31
+ };
32
+ try {
33
+ return {
34
+ status: 200,
35
+ body: { options: (await resolveConsentEntries({
36
+ payload,
37
+ req,
38
+ form,
39
+ sources: resolver
40
+ })).map((entry) => ({
41
+ label: entry.name ?? entry.id,
42
+ value: entry.id
43
+ })) }
44
+ };
45
+ } catch {
46
+ return {
47
+ status: 503,
48
+ body: { errors: [{ message: "Consent sources unavailable" }] }
49
+ };
50
+ }
51
+ };
52
+ //#endregion
53
+ export { resolveConsentSourcesRequest };
54
+
55
+ //# sourceMappingURL=resolveConsentSourcesRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveConsentSourcesRequest.js","names":[],"sources":["../../src/consent/resolveConsentSourcesRequest.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\nimport { FORMS_SLUG } from '../collections/forms'\nimport { resolveConsentEntries } from './resolveConsentEntries'\nimport type { ConsentSourcesResolver } from './types'\n\n/** One selectable consent source for the consent field's `source` select. */\nexport type ConsentSourceOption = { label: string; value: string }\n\nexport type ResolveConsentSourcesRequestArgs = {\n\tpayload: Payload\n\tformId: number | string | undefined\n\t/** Whether the caller is authenticated (an admin/user). */\n\tisAuthed: boolean\n\treq: PayloadRequest\n\tresolver: ConsentSourcesResolver\n}\n\nexport type ResolveConsentSourcesRequestResult = {\n\tstatus: number\n\tbody: { options: ConsentSourceOption[] } | { errors: { message: string }[] }\n}\n\n/**\n * Authorize and resolve the `GET /:id/consent-sources` request backing the consent `source` select:\n * authenticated callers get the host's sources for this request (a multi-tenant resolver scoping by\n * `req` therefore offers an author only their own tenant's), anonymous callers are always refused.\n * Statuses mirror the poll-options endpoint: 400 missing id, 403 unauthenticated, 404 unknown form,\n * 503 when the resolver throws (fail closed).\n */\nexport const resolveConsentSourcesRequest = async (\n\targs: ResolveConsentSourcesRequestArgs\n): Promise<ResolveConsentSourcesRequestResult> => {\n\tconst { payload, formId, isAuthed, req, resolver } = args\n\tif (!isAuthed) {\n\t\treturn { status: 403, body: { errors: [{ message: 'Forbidden' }] } }\n\t}\n\tif (formId == null) {\n\t\treturn { status: 400, body: { errors: [{ message: 'Missing form id' }] } }\n\t}\n\tconst form = await payload\n\t\t.findByID({ collection: FORMS_SLUG, id: formId, depth: 0, overrideAccess: true, req })\n\t\t.catch(() => null)\n\tif (!form) {\n\t\treturn { status: 404, body: { errors: [{ message: 'Not found' }] } }\n\t}\n\ttry {\n\t\tconst entries = await resolveConsentEntries({ payload, req, form, sources: resolver })\n\t\treturn {\n\t\t\tstatus: 200,\n\t\t\tbody: {\n\t\t\t\toptions: entries.map((entry) => ({ label: entry.name ?? entry.id, value: entry.id })),\n\t\t\t},\n\t\t}\n\t} catch {\n\t\treturn { status: 503, body: { errors: [{ message: 'Consent sources unavailable' }] } }\n\t}\n}\n"],"mappings":";;;;;;;;;;AA6BA,MAAa,+BAA+B,OAC3C,SACiD;CACjD,MAAM,EAAE,SAAS,QAAQ,UAAU,KAAK,aAAa;CACrD,IAAI,CAAC,UACJ,OAAO;EAAE,QAAQ;EAAK,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,YAAY,CAAC,EAAE;CAAE;CAEpE,IAAI,UAAU,MACb,OAAO;EAAE,QAAQ;EAAK,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,kBAAkB,CAAC,EAAE;CAAE;CAE1E,MAAM,OAAO,MAAM,QACjB,SAAS;EAAE,YAAY;EAAY,IAAI;EAAQ,OAAO;EAAG,gBAAgB;EAAM;CAAI,CAAC,EACpF,YAAY,IAAI;CAClB,IAAI,CAAC,MACJ,OAAO;EAAE,QAAQ;EAAK,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,YAAY,CAAC,EAAE;CAAE;CAEpE,IAAI;EAEH,OAAO;GACN,QAAQ;GACR,MAAM,EACL,UAAS,MAJW,sBAAsB;IAAE;IAAS;IAAK;IAAM,SAAS;GAAS,CAAC,GAIlE,KAAK,WAAW;IAAE,OAAO,MAAM,QAAQ,MAAM;IAAI,OAAO,MAAM;GAAG,EAAE,EACrF;EACD;CACD,QAAQ;EACP,OAAO;GAAE,QAAQ;GAAK,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,8BAA8B,CAAC,EAAE;EAAE;CACtF;AACD"}
@@ -0,0 +1,45 @@
1
+ import { ConsentSourcesResolver } from "./types.js";
2
+ import { Payload, PayloadRequest } from "payload";
3
+
4
+ //#region src/consent/resolveConsentStatements.d.ts
5
+ /** What a consent field shows the visitor, resolved from its source at request time. */
6
+ type ConsentStatement = {
7
+ /** Rich text state (or whatever the host's resolver returned), for the request's locale. */statement?: unknown; /** The policy link beside the statement, present only when the source carries both a `url` and a `label`. */
8
+ link?: {
9
+ label: string;
10
+ url: string;
11
+ };
12
+ };
13
+ /** Resolved statements keyed by consent field name, as `toFormDocument`'s `consentStatements` takes them. */
14
+ type ConsentStatements = Record<string, ConsentStatement>;
15
+ type ResolveConsentStatementsArgs = {
16
+ payload: Payload;
17
+ req: PayloadRequest; /** A loaded forms document; its consent fields' `source` ids drive resolution. */
18
+ form: {
19
+ id: number | string;
20
+ title?: string | null;
21
+ fields?: {
22
+ blockType: string;
23
+ name?: string;
24
+ [key: string]: unknown;
25
+ }[] | null;
26
+ }; /** Resolver override for plugin-internal callers; defaults to the one the plugin stashed on the config. */
27
+ sources?: ConsentSourcesResolver;
28
+ };
29
+ /**
30
+ * Resolve every consent field's statement for this request, ready to hand to
31
+ * `toFormDocument(doc, { consentStatements })`.
32
+ *
33
+ * The statement is a live reference, not a copy: a form stores only its source id, and the
34
+ * sentence the visitor reads is resolved here, in their locale, from whatever the source says
35
+ * right now. So correcting a policy sentence corrects every form referencing it, with nothing to
36
+ * re-save, and a form rendered without this step shows no statement at all rather than a stale one.
37
+ *
38
+ * Call it server-side (a Server Component, a route handler) before rendering `<Form>`. Throws
39
+ * whatever the host's resolver throws, so a page can decide between failing and rendering without
40
+ * consent; a submit resolves the source again regardless, and the proof is built from that.
41
+ */
42
+ declare const resolveConsentStatements: (args: ResolveConsentStatementsArgs) => Promise<ConsentStatements>;
43
+ //#endregion
44
+ export { ConsentStatement, ConsentStatements, ResolveConsentStatementsArgs, resolveConsentStatements };
45
+ //# sourceMappingURL=resolveConsentStatements.d.ts.map
@@ -0,0 +1,44 @@
1
+ import { resolveConsentEntries } from "./resolveConsentEntries.js";
2
+ //#region src/consent/resolveConsentStatements.ts
3
+ /**
4
+ * Resolve every consent field's statement for this request, ready to hand to
5
+ * `toFormDocument(doc, { consentStatements })`.
6
+ *
7
+ * The statement is a live reference, not a copy: a form stores only its source id, and the
8
+ * sentence the visitor reads is resolved here, in their locale, from whatever the source says
9
+ * right now. So correcting a policy sentence corrects every form referencing it, with nothing to
10
+ * re-save, and a form rendered without this step shows no statement at all rather than a stale one.
11
+ *
12
+ * Call it server-side (a Server Component, a route handler) before rendering `<Form>`. Throws
13
+ * whatever the host's resolver throws, so a page can decide between failing and rendering without
14
+ * consent; a submit resolves the source again regardless, and the proof is built from that.
15
+ */
16
+ const resolveConsentStatements = async (args) => {
17
+ const { payload, req, form, sources } = args;
18
+ const consentFields = (form.fields ?? []).filter((field) => field.blockType === "consent" && typeof field.name === "string" && field.name.length > 0);
19
+ if (consentFields.length === 0) return {};
20
+ const entries = await resolveConsentEntries({
21
+ payload,
22
+ req,
23
+ form,
24
+ sources
25
+ });
26
+ const statements = {};
27
+ for (const field of consentFields) {
28
+ const entry = entries.find((candidate) => candidate.id === field.source);
29
+ if (!entry) continue;
30
+ const label = typeof entry.name === "string" && entry.name.trim() !== "" ? entry.name : "";
31
+ statements[field.name] = {
32
+ ...entry.statement != null ? { statement: entry.statement } : {},
33
+ ...label && typeof entry.url === "string" && entry.url.length > 0 ? { link: {
34
+ label,
35
+ url: entry.url
36
+ } } : {}
37
+ };
38
+ }
39
+ return statements;
40
+ };
41
+ //#endregion
42
+ export { resolveConsentStatements };
43
+
44
+ //# sourceMappingURL=resolveConsentStatements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveConsentStatements.js","names":[],"sources":["../../src/consent/resolveConsentStatements.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\nimport { resolveConsentEntries } from './resolveConsentEntries'\nimport type { ConsentSourcesResolver } from './types'\n\n/** What a consent field shows the visitor, resolved from its source at request time. */\nexport type ConsentStatement = {\n\t/** Rich text state (or whatever the host's resolver returned), for the request's locale. */\n\tstatement?: unknown\n\t/** The policy link beside the statement, present only when the source carries both a `url` and a `label`. */\n\tlink?: { label: string; url: string }\n}\n\n/** Resolved statements keyed by consent field name, as `toFormDocument`'s `consentStatements` takes them. */\nexport type ConsentStatements = Record<string, ConsentStatement>\n\nexport type ResolveConsentStatementsArgs = {\n\tpayload: Payload\n\treq: PayloadRequest\n\t/** A loaded forms document; its consent fields' `source` ids drive resolution. */\n\tform: {\n\t\tid: number | string\n\t\ttitle?: string | null\n\t\tfields?: { blockType: string; name?: string; [key: string]: unknown }[] | null\n\t}\n\t/** Resolver override for plugin-internal callers; defaults to the one the plugin stashed on the config. */\n\tsources?: ConsentSourcesResolver\n}\n\n/**\n * Resolve every consent field's statement for this request, ready to hand to\n * `toFormDocument(doc, { consentStatements })`.\n *\n * The statement is a live reference, not a copy: a form stores only its source id, and the\n * sentence the visitor reads is resolved here, in their locale, from whatever the source says\n * right now. So correcting a policy sentence corrects every form referencing it, with nothing to\n * re-save, and a form rendered without this step shows no statement at all rather than a stale one.\n *\n * Call it server-side (a Server Component, a route handler) before rendering `<Form>`. Throws\n * whatever the host's resolver throws, so a page can decide between failing and rendering without\n * consent; a submit resolves the source again regardless, and the proof is built from that.\n */\nexport const resolveConsentStatements = async (\n\targs: ResolveConsentStatementsArgs\n): Promise<ConsentStatements> => {\n\tconst { payload, req, form, sources } = args\n\tconst consentFields = (form.fields ?? []).filter(\n\t\t(field): field is { blockType: string; name: string; source?: unknown } =>\n\t\t\tfield.blockType === 'consent' && typeof field.name === 'string' && field.name.length > 0\n\t)\n\tif (consentFields.length === 0) {\n\t\treturn {}\n\t}\n\tconst entries = await resolveConsentEntries({ payload, req, form, sources })\n\tconst statements: ConsentStatements = {}\n\tfor (const field of consentFields) {\n\t\tconst entry = entries.find((candidate) => candidate.id === field.source)\n\t\tif (!entry) {\n\t\t\tcontinue\n\t\t}\n\t\t// The link needs a name of its own, so it takes the source's `name` and never falls back to\n\t\t// the `id`: the id is a machine identifier, and showing it as the words a visitor clicks is\n\t\t// worse than no link at all. A source with a url and no name simply has no link.\n\t\tconst label = typeof entry.name === 'string' && entry.name.trim() !== '' ? entry.name : ''\n\t\tstatements[field.name] = {\n\t\t\t...(entry.statement != null ? { statement: entry.statement } : {}),\n\t\t\t...(label && typeof entry.url === 'string' && entry.url.length > 0\n\t\t\t\t? { link: { label, url: entry.url } }\n\t\t\t\t: {}),\n\t\t}\n\t}\n\treturn statements\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyCA,MAAa,2BAA2B,OACvC,SACgC;CAChC,MAAM,EAAE,SAAS,KAAK,MAAM,YAAY;CACxC,MAAM,iBAAiB,KAAK,UAAU,CAAC,GAAG,QACxC,UACA,MAAM,cAAc,aAAa,OAAO,MAAM,SAAS,YAAY,MAAM,KAAK,SAAS,CACzF;CACA,IAAI,cAAc,WAAW,GAC5B,OAAO,CAAC;CAET,MAAM,UAAU,MAAM,sBAAsB;EAAE;EAAS;EAAK;EAAM;CAAQ,CAAC;CAC3E,MAAM,aAAgC,CAAC;CACvC,KAAK,MAAM,SAAS,eAAe;EAClC,MAAM,QAAQ,QAAQ,MAAM,cAAc,UAAU,OAAO,MAAM,MAAM;EACvE,IAAI,CAAC,OACJ;EAKD,MAAM,QAAQ,OAAO,MAAM,SAAS,YAAY,MAAM,KAAK,KAAK,MAAM,KAAK,MAAM,OAAO;EACxF,WAAW,MAAM,QAAQ;GACxB,GAAI,MAAM,aAAa,OAAO,EAAE,WAAW,MAAM,UAAU,IAAI,CAAC;GAChE,GAAI,SAAS,OAAO,MAAM,QAAQ,YAAY,MAAM,IAAI,SAAS,IAC9D,EAAE,MAAM;IAAE;IAAO,KAAK,MAAM;GAAI,EAAE,IAClC,CAAC;EACL;CACD;CACA,OAAO;AACR"}
@@ -1,17 +1,23 @@
1
- import { Payload } from "payload";
1
+ import { Payload, PayloadRequest } from "payload";
2
2
 
3
3
  //#region src/consent/resolvePublishedVersionRef.d.ts
4
+ type ResolvePublishedVersionRefArgs = {
5
+ payload: Payload;
6
+ collection: string;
7
+ id: number | string; /** Threaded into `findVersions` so a version written earlier in the same transaction is visible. */
8
+ req?: PayloadRequest;
9
+ };
4
10
  /**
5
- * Returns the latest published version of a doc, or null when versions/drafts are off or nothing
6
- * is published. Never throws.
11
+ * The id of a document's latest published version, or null when nothing is published.
12
+ *
13
+ * Drafts-only, and deliberately not a versions check: `_status` exists only where
14
+ * `versions.drafts` is on (Payload adds the base version fields inside that branch when
15
+ * sanitizing), so on a collection with plain versions and no drafts this query matches nothing and
16
+ * returns null, which is indistinguishable from having no versions at all. Callers must decide the
17
+ * difference themselves with `hasDraftsEnabled` rather than reading null as "no versions" (see
18
+ * `captureConsent`). Never throws.
7
19
  */
8
- declare const resolvePublishedVersionRef: (payload: Payload, args: {
9
- collection: string;
10
- id: string | number;
11
- }) => Promise<{
12
- versionId: string;
13
- updatedAt: string;
14
- } | null>;
20
+ declare const resolvePublishedVersionRef: (args: ResolvePublishedVersionRefArgs) => Promise<string | null>;
15
21
  //#endregion
16
- export { resolvePublishedVersionRef };
22
+ export { ResolvePublishedVersionRefArgs, resolvePublishedVersionRef };
17
23
  //# sourceMappingURL=resolvePublishedVersionRef.d.ts.map
@@ -1,22 +1,25 @@
1
1
  //#region src/consent/resolvePublishedVersionRef.ts
2
2
  /**
3
- * Returns the latest published version of a doc, or null when versions/drafts are off or nothing
4
- * is published. Never throws.
3
+ * The id of a document's latest published version, or null when nothing is published.
4
+ *
5
+ * Drafts-only, and deliberately not a versions check: `_status` exists only where
6
+ * `versions.drafts` is on (Payload adds the base version fields inside that branch when
7
+ * sanitizing), so on a collection with plain versions and no drafts this query matches nothing and
8
+ * returns null, which is indistinguishable from having no versions at all. Callers must decide the
9
+ * difference themselves with `hasDraftsEnabled` rather than reading null as "no versions" (see
10
+ * `captureConsent`). Never throws.
5
11
  */
6
- const resolvePublishedVersionRef = async (payload, args) => {
12
+ const resolvePublishedVersionRef = async (args) => {
7
13
  try {
8
- const doc = (await payload.findVersions({
14
+ const doc = (await args.payload.findVersions({
9
15
  collection: args.collection,
10
16
  where: { and: [{ parent: { equals: args.id } }, { "version._status": { equals: "published" } }] },
11
17
  sort: "-updatedAt",
12
18
  limit: 1,
13
- depth: 0
19
+ depth: 0,
20
+ req: args.req
14
21
  }))?.docs?.[0];
15
- if (!doc) return null;
16
- return {
17
- versionId: String(doc.id),
18
- updatedAt: String(doc.updatedAt)
19
- };
22
+ return doc ? String(doc.id) : null;
20
23
  } catch {
21
24
  return null;
22
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resolvePublishedVersionRef.js","names":[],"sources":["../../src/consent/resolvePublishedVersionRef.ts"],"sourcesContent":["import type { Payload } from 'payload'\n\n/**\n * Returns the latest published version of a doc, or null when versions/drafts are off or nothing\n * is published. Never throws.\n */\nexport const resolvePublishedVersionRef = async (\n\tpayload: Payload,\n\targs: { collection: string; id: string | number }\n): Promise<{ versionId: string; updatedAt: string } | null> => {\n\ttry {\n\t\tconst result = await payload.findVersions({\n\t\t\tcollection: args.collection as never,\n\t\t\twhere: {\n\t\t\t\tand: [{ parent: { equals: args.id } }, { 'version._status': { equals: 'published' } }],\n\t\t\t},\n\t\t\tsort: '-updatedAt',\n\t\t\tlimit: 1,\n\t\t\tdepth: 0,\n\t\t})\n\t\tconst doc = result?.docs?.[0]\n\t\tif (!doc) {\n\t\t\treturn null\n\t\t}\n\t\treturn { versionId: String(doc.id), updatedAt: String(doc.updatedAt) }\n\t} catch {\n\t\treturn null\n\t}\n}\n"],"mappings":";;;;;AAMA,MAAa,6BAA6B,OACzC,SACA,SAC8D;CAC9D,IAAI;EAUH,MAAM,OAAM,MATS,QAAQ,aAAa;GACzC,YAAY,KAAK;GACjB,OAAO,EACN,KAAK,CAAC,EAAE,QAAQ,EAAE,QAAQ,KAAK,GAAG,EAAE,GAAG,EAAE,mBAAmB,EAAE,QAAQ,YAAY,EAAE,CAAC,EACtF;GACA,MAAM;GACN,OAAO;GACP,OAAO;EACR,CAAC,IACmB,OAAO;EAC3B,IAAI,CAAC,KACJ,OAAO;EAER,OAAO;GAAE,WAAW,OAAO,IAAI,EAAE;GAAG,WAAW,OAAO,IAAI,SAAS;EAAE;CACtE,QAAQ;EACP,OAAO;CACR;AACD"}
1
+ {"version":3,"file":"resolvePublishedVersionRef.js","names":[],"sources":["../../src/consent/resolvePublishedVersionRef.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\n\nexport type ResolvePublishedVersionRefArgs = {\n\tpayload: Payload\n\tcollection: string\n\tid: number | string\n\t/** Threaded into `findVersions` so a version written earlier in the same transaction is visible. */\n\treq?: PayloadRequest\n}\n\n/**\n * The id of a document's latest published version, or null when nothing is published.\n *\n * Drafts-only, and deliberately not a versions check: `_status` exists only where\n * `versions.drafts` is on (Payload adds the base version fields inside that branch when\n * sanitizing), so on a collection with plain versions and no drafts this query matches nothing and\n * returns null, which is indistinguishable from having no versions at all. Callers must decide the\n * difference themselves with `hasDraftsEnabled` rather than reading null as \"no versions\" (see\n * `captureConsent`). Never throws.\n */\nexport const resolvePublishedVersionRef = async (\n\targs: ResolvePublishedVersionRefArgs\n): Promise<string | null> => {\n\ttry {\n\t\tconst result = await args.payload.findVersions({\n\t\t\tcollection: args.collection as never,\n\t\t\twhere: {\n\t\t\t\tand: [{ parent: { equals: args.id } }, { 'version._status': { equals: 'published' } }],\n\t\t\t},\n\t\t\tsort: '-updatedAt',\n\t\t\tlimit: 1,\n\t\t\tdepth: 0,\n\t\t\treq: args.req,\n\t\t})\n\t\tconst doc = result?.docs?.[0]\n\t\treturn doc ? String(doc.id) : null\n\t} catch {\n\t\treturn null\n\t}\n}\n"],"mappings":";;;;;;;;;;;AAoBA,MAAa,6BAA6B,OACzC,SAC4B;CAC5B,IAAI;EAWH,MAAM,OAAM,MAVS,KAAK,QAAQ,aAAa;GAC9C,YAAY,KAAK;GACjB,OAAO,EACN,KAAK,CAAC,EAAE,QAAQ,EAAE,QAAQ,KAAK,GAAG,EAAE,GAAG,EAAE,mBAAmB,EAAE,QAAQ,YAAY,EAAE,CAAC,EACtF;GACA,MAAM;GACN,OAAO;GACP,OAAO;GACP,KAAK,KAAK;EACX,CAAC,IACmB,OAAO;EAC3B,OAAO,MAAM,OAAO,IAAI,EAAE,IAAI;CAC/B,QAAQ;EACP,OAAO;CACR;AACD"}
@@ -0,0 +1,53 @@
1
+ import { PayloadRequest } from "payload";
2
+
3
+ //#region src/consent/types.d.ts
4
+ /** A document reference, kept id-based so renaming or re-slugging the page never breaks it. */
5
+ type ConsentSourcePage = {
6
+ relationTo: string;
7
+ id: number | string;
8
+ };
9
+ /**
10
+ * One consent source a form author can reference by `id`: the statement the visitor agrees to, and
11
+ * optionally the policy document that statement belongs to. Produced by the host's
12
+ * {@link ConsentSourcesResolver}, normally by mapping the rows of a placed `consentSourcesField()`.
13
+ *
14
+ * `id` is the array row's own auto-assigned identifier, so it survives name edits and reordering
15
+ * and is the stable reference stored on the consent field and in every proof. `statement` is rich
16
+ * text state (the visitor-facing sentence), already resolved for the request's locale by virtue of
17
+ * the resolver reading its own localized field under `req.locale`. `page` drives proof: an id and
18
+ * its collection, never a URL, so the document can be renamed, re-slugged, or re-routed without
19
+ * stranding past proofs. `url` is the visitor-facing link the renderer shows beside the statement;
20
+ * only the host knows how a document id maps to a public route, so the plugin never derives one.
21
+ */
22
+ type ConsentSourceEntry = {
23
+ id: string;
24
+ name?: string;
25
+ statement?: unknown;
26
+ page?: ConsentSourcePage;
27
+ url?: string;
28
+ };
29
+ /**
30
+ * Host seam resolving the consent sources a form's authors can reference (plugin option
31
+ * `consent.sources`). Without it there are no sources, so the `consent` field type is not
32
+ * registered at all.
33
+ *
34
+ * The intended shape: place `consentSourcesField()` on a collection or global you own, then read it
35
+ * back here. Multi-tenant hosts scope the read by the tenant derived from `req` (host header,
36
+ * cookie, or auth context) and return only that tenant's sources, so one tenant's statements are
37
+ * never selectable, resolvable, or provable under another's. Read under `req.locale` so the
38
+ * statement the visitor agrees to is the one they were shown.
39
+ *
40
+ * Do not thread the save's `req` into a `find({ locale: 'all' })` from within a form's save
41
+ * validation: it flips `req.locale` to `all` and corrupts the localized write of the document being
42
+ * saved. Read the settings document without the save's `req` (already-committed data, no transaction).
43
+ */
44
+ type ConsentSourcesResolver = (args: {
45
+ req: PayloadRequest;
46
+ form: {
47
+ id: number | string;
48
+ title?: string;
49
+ };
50
+ }) => ConsentSourceEntry[] | Promise<ConsentSourceEntry[]>;
51
+ //#endregion
52
+ export { ConsentSourceEntry, ConsentSourcePage, ConsentSourcesResolver };
53
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,59 @@
1
+ import { Payload, PayloadRequest } from "payload";
2
+
3
+ //#region src/email/departments.d.ts
4
+ /** One selectable department for the `emailTeam` recipients; `value` is the email address routed to. */
5
+ type DepartmentOption = {
6
+ label: string;
7
+ value: string;
8
+ };
9
+ /**
10
+ * Host seam resolving the selectable departments for `emailTeam`'s recipient fields (plugin option
11
+ * `email.departments`). Req-scoped, so multi-tenant hosts derive tenant scoping from `req` (host
12
+ * header, cookie, or auth context) and return only that tenant's departments. `value` is the literal
13
+ * string `payload.sendEmail` accepts (an email address); `label` is how the department is named in the
14
+ * admin select. Mirrors {@link FromAddressesResolver}. {@link resolveDepartmentOptions} builds this
15
+ * from a `departmentsField()`-bearing document with the reusable locale fallback, so a host does not
16
+ * reimplement it.
17
+ *
18
+ * Do not thread the save's `req` into a `find({ locale: 'all' })` from within a form's save
19
+ * validation: it flips `req.locale` to `all` and corrupts the localized write of the document being
20
+ * saved. Read the settings document without the save's `req` (already-committed data, no transaction).
21
+ */
22
+ type DepartmentEmailsResolver = (args: {
23
+ req: PayloadRequest;
24
+ }) => Promise<DepartmentOption[]> | DepartmentOption[];
25
+ type ResolveDepartmentsRequestArgs = {
26
+ /** Whether the caller is authenticated (an admin/user). */isAuthed: boolean;
27
+ req: PayloadRequest;
28
+ resolver: DepartmentEmailsResolver;
29
+ };
30
+ type ResolveDepartmentsRequestResult = {
31
+ status: number;
32
+ body: {
33
+ options: DepartmentOption[];
34
+ } | {
35
+ errors: {
36
+ message: string;
37
+ }[];
38
+ };
39
+ };
40
+ type ResolveDepartmentOptionsArgs = {
41
+ payload: Payload;
42
+ req: PayloadRequest; /** A document fetched at `locale: 'all'`, so each localized subfield is a `{ locale: value }` map. */
43
+ doc: Record<string, unknown>; /** The array field name the departments live under; defaults to `departmentEmails`. */
44
+ field?: string;
45
+ };
46
+ /**
47
+ * Build the `emailTeam` recipient options from a `departmentsField()`-bearing document (a settings
48
+ * global, a tenants row, wherever the host placed it), fetched at `locale: 'all'`. Each row's `label`
49
+ * and `email` are resolved for `req.locale` via the current -> default -> next-available chain (see
50
+ * {@link pickLocaleValue}), reading `defaultLocale`/`localeCodes` from `payload.config.localization`
51
+ * (a bare string is used as-is when localization is disabled). Rows with no resolvable email are
52
+ * dropped; a row's label is resolved independently of its email and falls back to the email when
53
+ * absent. This is the reusable seam a host's `email.departments` resolver returns, so tenant scoping
54
+ * (which document is read) stays the host's call while the locale fallback stays consistent.
55
+ */
56
+ declare const resolveDepartmentOptions: (args: ResolveDepartmentOptionsArgs) => DepartmentOption[];
57
+ //#endregion
58
+ export { DepartmentEmailsResolver, DepartmentOption, ResolveDepartmentOptionsArgs, ResolveDepartmentsRequestArgs, ResolveDepartmentsRequestResult, resolveDepartmentOptions };
59
+ //# sourceMappingURL=departments.d.ts.map
@@ -0,0 +1,87 @@
1
+ //#region src/email/departments.ts
2
+ /**
3
+ * Authorize and resolve the `GET /:id/departments` request backing the recipient selects: authenticated
4
+ * callers get the host resolver's current options for this request; anonymous callers are always
5
+ * refused. The route id is unused (the option set is request-scoped, not per-form). Statuses mirror
6
+ * `resolveFromAddressesRequest`: 403 unauthenticated, 503 when the resolver throws (fail closed).
7
+ */
8
+ const resolveDepartmentsRequest = async (args) => {
9
+ const { isAuthed, req, resolver } = args;
10
+ if (!isAuthed) return {
11
+ status: 403,
12
+ body: { errors: [{ message: "Forbidden" }] }
13
+ };
14
+ try {
15
+ return {
16
+ status: 200,
17
+ body: { options: await resolver({ req }) }
18
+ };
19
+ } catch {
20
+ return {
21
+ status: 503,
22
+ body: { errors: [{ message: "Departments unavailable" }] }
23
+ };
24
+ }
25
+ };
26
+ /**
27
+ * Resolve one localized subfield value for `reqLocale` with the current -> default -> next-available
28
+ * chain. A non-localized subfield (fetched at `locale: 'all'` on a host without localization) is a
29
+ * bare string, used as-is; a localized one is a `{ [locale]: value }` map, from which `reqLocale`,
30
+ * then `defaultLocale`, then the first non-empty configured locale wins. Empty strings are skipped
31
+ * (they fall through the chain), and undefined is returned when nothing resolves.
32
+ */
33
+ const pickLocaleValue = (value, reqLocale, defaultLocale, localeCodes) => {
34
+ if (typeof value === "string") return value.length > 0 ? value : void 0;
35
+ if (value == null || typeof value !== "object") return;
36
+ const map = value;
37
+ const nonEmpty = (entry) => typeof entry === "string" && entry.length > 0 ? entry : void 0;
38
+ const ordered = [
39
+ reqLocale,
40
+ defaultLocale,
41
+ ...localeCodes
42
+ ].filter((code) => typeof code === "string" && code.length > 0);
43
+ for (const code of ordered) {
44
+ const hit = nonEmpty(map[code]);
45
+ if (hit !== void 0) return hit;
46
+ }
47
+ for (const key of Object.keys(map)) {
48
+ const hit = nonEmpty(map[key]);
49
+ if (hit !== void 0) return hit;
50
+ }
51
+ };
52
+ /**
53
+ * Build the `emailTeam` recipient options from a `departmentsField()`-bearing document (a settings
54
+ * global, a tenants row, wherever the host placed it), fetched at `locale: 'all'`. Each row's `label`
55
+ * and `email` are resolved for `req.locale` via the current -> default -> next-available chain (see
56
+ * {@link pickLocaleValue}), reading `defaultLocale`/`localeCodes` from `payload.config.localization`
57
+ * (a bare string is used as-is when localization is disabled). Rows with no resolvable email are
58
+ * dropped; a row's label is resolved independently of its email and falls back to the email when
59
+ * absent. This is the reusable seam a host's `email.departments` resolver returns, so tenant scoping
60
+ * (which document is read) stays the host's call while the locale fallback stays consistent.
61
+ */
62
+ const resolveDepartmentOptions = (args) => {
63
+ const { payload, req, doc, field } = args;
64
+ const rows = doc[field ?? "departmentEmails"];
65
+ if (!Array.isArray(rows)) return [];
66
+ const localization = payload.config.localization;
67
+ const localeCodes = localization ? localization.localeCodes : [];
68
+ const defaultLocale = localization ? localization.defaultLocale : void 0;
69
+ const reqLocale = typeof req.locale === "string" ? req.locale : void 0;
70
+ const options = [];
71
+ for (const row of rows) {
72
+ if (row == null || typeof row !== "object") continue;
73
+ const entry = row;
74
+ const email = pickLocaleValue(entry.email, reqLocale, defaultLocale, localeCodes);
75
+ if (email === void 0) continue;
76
+ const label = pickLocaleValue(entry.label, reqLocale, defaultLocale, localeCodes) ?? email;
77
+ options.push({
78
+ label,
79
+ value: email
80
+ });
81
+ }
82
+ return options;
83
+ };
84
+ //#endregion
85
+ export { resolveDepartmentOptions, resolveDepartmentsRequest };
86
+
87
+ //# sourceMappingURL=departments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"departments.js","names":[],"sources":["../../src/email/departments.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\n\n/** One selectable department for the `emailTeam` recipients; `value` is the email address routed to. */\nexport type DepartmentOption = { label: string; value: string }\n\n/**\n * Host seam resolving the selectable departments for `emailTeam`'s recipient fields (plugin option\n * `email.departments`). Req-scoped, so multi-tenant hosts derive tenant scoping from `req` (host\n * header, cookie, or auth context) and return only that tenant's departments. `value` is the literal\n * string `payload.sendEmail` accepts (an email address); `label` is how the department is named in the\n * admin select. Mirrors {@link FromAddressesResolver}. {@link resolveDepartmentOptions} builds this\n * from a `departmentsField()`-bearing document with the reusable locale fallback, so a host does not\n * reimplement it.\n *\n * Do not thread the save's `req` into a `find({ locale: 'all' })` from within a form's save\n * validation: it flips `req.locale` to `all` and corrupts the localized write of the document being\n * saved. Read the settings document without the save's `req` (already-committed data, no transaction).\n */\nexport type DepartmentEmailsResolver = (args: {\n\treq: PayloadRequest\n}) => Promise<DepartmentOption[]> | DepartmentOption[]\n\nexport type ResolveDepartmentsRequestArgs = {\n\t/** Whether the caller is authenticated (an admin/user). */\n\tisAuthed: boolean\n\treq: PayloadRequest\n\tresolver: DepartmentEmailsResolver\n}\n\nexport type ResolveDepartmentsRequestResult = {\n\tstatus: number\n\tbody: { options: DepartmentOption[] } | { errors: { message: string }[] }\n}\n\n/**\n * Authorize and resolve the `GET /:id/departments` request backing the recipient selects: authenticated\n * callers get the host resolver's current options for this request; anonymous callers are always\n * refused. The route id is unused (the option set is request-scoped, not per-form). Statuses mirror\n * `resolveFromAddressesRequest`: 403 unauthenticated, 503 when the resolver throws (fail closed).\n */\nexport const resolveDepartmentsRequest = async (\n\targs: ResolveDepartmentsRequestArgs\n): Promise<ResolveDepartmentsRequestResult> => {\n\tconst { isAuthed, req, resolver } = args\n\tif (!isAuthed) {\n\t\treturn { status: 403, body: { errors: [{ message: 'Forbidden' }] } }\n\t}\n\ttry {\n\t\tconst options = await resolver({ req })\n\t\treturn { status: 200, body: { options } }\n\t} catch {\n\t\treturn { status: 503, body: { errors: [{ message: 'Departments unavailable' }] } }\n\t}\n}\n\n/**\n * Resolve one localized subfield value for `reqLocale` with the current -> default -> next-available\n * chain. A non-localized subfield (fetched at `locale: 'all'` on a host without localization) is a\n * bare string, used as-is; a localized one is a `{ [locale]: value }` map, from which `reqLocale`,\n * then `defaultLocale`, then the first non-empty configured locale wins. Empty strings are skipped\n * (they fall through the chain), and undefined is returned when nothing resolves.\n */\n// biome-ignore lint/complexity/useMaxParams: the locale-fallback inputs are the minimal surface (value, reqLocale, defaultLocale, localeCodes)\nexport const pickLocaleValue = (\n\tvalue: unknown,\n\treqLocale: string | undefined,\n\tdefaultLocale: string | undefined,\n\tlocaleCodes: string[]\n): string | undefined => {\n\tif (typeof value === 'string') {\n\t\treturn value.length > 0 ? value : undefined\n\t}\n\tif (value == null || typeof value !== 'object') {\n\t\treturn undefined\n\t}\n\tconst map = value as Record<string, unknown>\n\tconst nonEmpty = (entry: unknown): string | undefined =>\n\t\ttypeof entry === 'string' && entry.length > 0 ? entry : undefined\n\tconst ordered = [reqLocale, defaultLocale, ...localeCodes].filter(\n\t\t(code): code is string => typeof code === 'string' && code.length > 0\n\t)\n\tfor (const code of ordered) {\n\t\tconst hit = nonEmpty(map[code])\n\t\tif (hit !== undefined) {\n\t\t\treturn hit\n\t\t}\n\t}\n\t// Defensive: a `locale: 'all'` fetch keys by configured locales, but a key outside them still\n\t// counts toward \"next available\" so a value is never silently dropped.\n\tfor (const key of Object.keys(map)) {\n\t\tconst hit = nonEmpty(map[key])\n\t\tif (hit !== undefined) {\n\t\t\treturn hit\n\t\t}\n\t}\n\treturn undefined\n}\n\nexport type ResolveDepartmentOptionsArgs = {\n\tpayload: Payload\n\treq: PayloadRequest\n\t/** A document fetched at `locale: 'all'`, so each localized subfield is a `{ locale: value }` map. */\n\tdoc: Record<string, unknown>\n\t/** The array field name the departments live under; defaults to `departmentEmails`. */\n\tfield?: string\n}\n\n/**\n * Build the `emailTeam` recipient options from a `departmentsField()`-bearing document (a settings\n * global, a tenants row, wherever the host placed it), fetched at `locale: 'all'`. Each row's `label`\n * and `email` are resolved for `req.locale` via the current -> default -> next-available chain (see\n * {@link pickLocaleValue}), reading `defaultLocale`/`localeCodes` from `payload.config.localization`\n * (a bare string is used as-is when localization is disabled). Rows with no resolvable email are\n * dropped; a row's label is resolved independently of its email and falls back to the email when\n * absent. This is the reusable seam a host's `email.departments` resolver returns, so tenant scoping\n * (which document is read) stays the host's call while the locale fallback stays consistent.\n */\nexport const resolveDepartmentOptions = (\n\targs: ResolveDepartmentOptionsArgs\n): DepartmentOption[] => {\n\tconst { payload, req, doc, field } = args\n\tconst rows = doc[field ?? 'departmentEmails']\n\tif (!Array.isArray(rows)) {\n\t\treturn []\n\t}\n\tconst localization = payload.config.localization\n\tconst localeCodes = localization ? localization.localeCodes : []\n\tconst defaultLocale = localization ? localization.defaultLocale : undefined\n\tconst reqLocale = typeof req.locale === 'string' ? req.locale : undefined\n\tconst options: DepartmentOption[] = []\n\tfor (const row of rows) {\n\t\tif (row == null || typeof row !== 'object') {\n\t\t\tcontinue\n\t\t}\n\t\tconst entry = row as Record<string, unknown>\n\t\tconst email = pickLocaleValue(entry.email, reqLocale, defaultLocale, localeCodes)\n\t\tif (email === undefined) {\n\t\t\tcontinue\n\t\t}\n\t\tconst label = pickLocaleValue(entry.label, reqLocale, defaultLocale, localeCodes) ?? email\n\t\toptions.push({ label, value: email })\n\t}\n\treturn options\n}\n"],"mappings":";;;;;;;AAwCA,MAAa,4BAA4B,OACxC,SAC8C;CAC9C,MAAM,EAAE,UAAU,KAAK,aAAa;CACpC,IAAI,CAAC,UACJ,OAAO;EAAE,QAAQ;EAAK,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,YAAY,CAAC,EAAE;CAAE;CAEpE,IAAI;EAEH,OAAO;GAAE,QAAQ;GAAK,MAAM,EAAE,SAAA,MADR,SAAS,EAAE,IAAI,CAAC,EACA;EAAE;CACzC,QAAQ;EACP,OAAO;GAAE,QAAQ;GAAK,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,0BAA0B,CAAC,EAAE;EAAE;CAClF;AACD;;;;;;;;AAUA,MAAa,mBACZ,OACA,WACA,eACA,gBACwB;CACxB,IAAI,OAAO,UAAU,UACpB,OAAO,MAAM,SAAS,IAAI,QAAQ,KAAA;CAEnC,IAAI,SAAS,QAAQ,OAAO,UAAU,UACrC;CAED,MAAM,MAAM;CACZ,MAAM,YAAY,UACjB,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ,KAAA;CACzD,MAAM,UAAU;EAAC;EAAW;EAAe,GAAG;CAAW,EAAE,QACzD,SAAyB,OAAO,SAAS,YAAY,KAAK,SAAS,CACrE;CACA,KAAK,MAAM,QAAQ,SAAS;EAC3B,MAAM,MAAM,SAAS,IAAI,KAAK;EAC9B,IAAI,QAAQ,KAAA,GACX,OAAO;CAET;CAGA,KAAK,MAAM,OAAO,OAAO,KAAK,GAAG,GAAG;EACnC,MAAM,MAAM,SAAS,IAAI,IAAI;EAC7B,IAAI,QAAQ,KAAA,GACX,OAAO;CAET;AAED;;;;;;;;;;;AAqBA,MAAa,4BACZ,SACwB;CACxB,MAAM,EAAE,SAAS,KAAK,KAAK,UAAU;CACrC,MAAM,OAAO,IAAI,SAAS;CAC1B,IAAI,CAAC,MAAM,QAAQ,IAAI,GACtB,OAAO,CAAC;CAET,MAAM,eAAe,QAAQ,OAAO;CACpC,MAAM,cAAc,eAAe,aAAa,cAAc,CAAC;CAC/D,MAAM,gBAAgB,eAAe,aAAa,gBAAgB,KAAA;CAClE,MAAM,YAAY,OAAO,IAAI,WAAW,WAAW,IAAI,SAAS,KAAA;CAChE,MAAM,UAA8B,CAAC;CACrC,KAAK,MAAM,OAAO,MAAM;EACvB,IAAI,OAAO,QAAQ,OAAO,QAAQ,UACjC;EAED,MAAM,QAAQ;EACd,MAAM,QAAQ,gBAAgB,MAAM,OAAO,WAAW,eAAe,WAAW;EAChF,IAAI,UAAU,KAAA,GACb;EAED,MAAM,QAAQ,gBAAgB,MAAM,OAAO,WAAW,eAAe,WAAW,KAAK;EACrF,QAAQ,KAAK;GAAE;GAAO,OAAO;EAAM,CAAC;CACrC;CACA,OAAO;AACR"}
@@ -0,0 +1,53 @@
1
+ import { ArrayField } from "payload";
2
+
3
+ //#region src/email/departmentsField.d.ts
4
+ type DepartmentsFieldOptions = {
5
+ /** Field name, i.e. what the row array is stored under. Defaults to `departmentEmails`. */name?: string; /** Field label. Defaults to the plugin's translated one. */
6
+ label?: ArrayField['label'];
7
+ /**
8
+ * Whether each row's `email` (and its `label`) carry `localized: true`, so the same field can
9
+ * hold a different address per locale. Default `true`; Payload strips the flag on hosts without
10
+ * `localization`, so it is safe either way.
11
+ */
12
+ localized?: boolean;
13
+ };
14
+ /**
15
+ * The department-emails array, for the host to place on any collection or global they own: a
16
+ * settings global, a tenants collection, a departments parent, wherever the addresses belong. The
17
+ * plugin never registers it and never guesses where it lives; the `email.departments` resolver reads
18
+ * it back, which is also where multi-tenant scoping goes: place this on the tenant-scoped document
19
+ * and have the resolver return only that tenant's addresses, derived from `req`.
20
+ *
21
+ * A row is a `label` (how the address is named when routing a submission to it) and the `email` it
22
+ * resolves to. Because `email` is `localized` by default, a host can hold a different address per
23
+ * locale without changing the stored shape. The array itself is not localized, so per-locale edits
24
+ * must address existing rows by their own auto-assigned `id` rather than re-sending id-less rows.
25
+ *
26
+ * It renders condensed: `admin.components.Field` is {@link CondensedArray}, which lays each row out
27
+ * flat as `[label, email]` at 50% each with no per-row collapsible, while keeping Payload's native
28
+ * per-locale storage and row ids.
29
+ *
30
+ * ```ts
31
+ * // The host's own collection or global:
32
+ * fields: [departmentsField()]
33
+ *
34
+ * // The plugin, reading it back to route a submission. `resolveDepartmentOptions` reads the array
35
+ * // (fetched at `locale: 'all'`) and resolves each row's address for the requesting locale:
36
+ * formBuilder({
37
+ * email: {
38
+ * departments: async ({ req }) => {
39
+ * const settings = await req.payload.findGlobal({ slug: 'settings', depth: 0, locale: 'all' })
40
+ * return resolveDepartmentOptions({ payload: req.payload, req, doc: settings })
41
+ * },
42
+ * },
43
+ * })
44
+ * ```
45
+ *
46
+ * The read above omits the save's `req` on purpose: threading it into a `locale: 'all'` read from
47
+ * within a form's save validation flips `req.locale` to `all` and corrupts the localized write of the
48
+ * document being saved. It reads already-committed data, so no transaction (`req`) is needed.
49
+ */
50
+ declare const departmentsField: (options?: DepartmentsFieldOptions) => ArrayField;
51
+ //#endregion
52
+ export { DepartmentsFieldOptions, departmentsField };
53
+ //# sourceMappingURL=departmentsField.d.ts.map