@10x-media/form-builder 0.1.0-beta.4 → 0.1.0-beta.5

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 (356) hide show
  1. package/CHANGELOG.md +83 -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 +41 -11
  9. package/dist/actions/builtin/confirmation.js.map +1 -1
  10. package/dist/actions/builtin/emailTeam.js +77 -38
  11. package/dist/actions/builtin/emailTeam.js.map +1 -1
  12. package/dist/actions/builtin/index.d.ts +8 -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/fromAddresses.d.ts +21 -0
  17. package/dist/actions/fromAddresses.js +74 -0
  18. package/dist/actions/fromAddresses.js.map +1 -0
  19. package/dist/actions/task.js +9 -8
  20. package/dist/actions/task.js.map +1 -1
  21. package/dist/aggregation/aggregateResponses.d.ts +9 -0
  22. package/dist/aggregation/aggregateResponses.js +8 -14
  23. package/dist/aggregation/aggregateResponses.js.map +1 -1
  24. package/dist/aggregation/resolveResultsRequest.d.ts +19 -6
  25. package/dist/aggregation/resolveResultsRequest.js +58 -12
  26. package/dist/aggregation/resolveResultsRequest.js.map +1 -1
  27. package/dist/calc/computeCalcFields.js +2 -1
  28. package/dist/calc/computeCalcFields.js.map +1 -1
  29. package/dist/client/ByteSizeField.d.ts +8 -0
  30. package/dist/client/ByteSizeField.js +3 -1
  31. package/dist/client/ByteSizeField.js.map +1 -1
  32. package/dist/client/ClosePollButton.d.ts +15 -0
  33. package/dist/client/ClosePollButton.js +80 -0
  34. package/dist/client/ClosePollButton.js.map +1 -0
  35. package/dist/client/CondensedArray.d.ts +15 -0
  36. package/dist/client/CondensedArray.js +97 -0
  37. package/dist/client/CondensedArray.js.map +1 -0
  38. package/dist/client/EndpointOptionsSelect.d.ts +45 -0
  39. package/dist/client/EndpointOptionsSelect.js +103 -0
  40. package/dist/client/EndpointOptionsSelect.js.map +1 -0
  41. package/dist/client/FieldBlockLabel.d.ts +18 -0
  42. package/dist/client/FieldBlockLabel.js +34 -0
  43. package/dist/client/FieldBlockLabel.js.map +1 -0
  44. package/dist/client/FieldNameSelect.d.ts +20 -4
  45. package/dist/client/FieldNameSelect.js +25 -14
  46. package/dist/client/FieldNameSelect.js.map +1 -1
  47. package/dist/client/FlowBuilder.d.ts +2 -1
  48. package/dist/client/FlowBuilder.js +63 -57
  49. package/dist/client/FlowBuilder.js.map +1 -1
  50. package/dist/client/RuleDescription.d.ts +21 -0
  51. package/dist/client/RuleDescription.js +19 -0
  52. package/dist/client/RuleDescription.js.map +1 -0
  53. package/dist/client/admin.css +36 -0
  54. package/dist/client/endpointOptions.js +29 -0
  55. package/dist/client/endpointOptions.js.map +1 -0
  56. package/dist/client/flowAuthoring.js +114 -7
  57. package/dist/client/flowAuthoring.js.map +1 -1
  58. package/dist/client/synthesizeClientField.js +15 -8
  59. package/dist/client/synthesizeClientField.js.map +1 -1
  60. package/dist/collections/buttonFields.d.ts +34 -0
  61. package/dist/collections/buttonFields.js +35 -0
  62. package/dist/collections/buttonFields.js.map +1 -0
  63. package/dist/collections/cells/FieldCountCell.d.ts +15 -0
  64. package/dist/collections/cells/FieldCountCell.js +18 -0
  65. package/dist/collections/cells/FieldCountCell.js.map +1 -0
  66. package/dist/collections/cells/FlowStepsCell.d.ts +14 -0
  67. package/dist/collections/cells/FlowStepsCell.js +17 -0
  68. package/dist/collections/cells/FlowStepsCell.js.map +1 -0
  69. package/dist/collections/formSubmissions.js +22 -17
  70. package/dist/collections/formSubmissions.js.map +1 -1
  71. package/dist/collections/forms.js +310 -137
  72. package/dist/collections/forms.js.map +1 -1
  73. package/dist/collections/redirectFields.d.ts +29 -0
  74. package/dist/consent/applyConsentStatements.d.ts +14 -0
  75. package/dist/consent/applyConsentStatements.js +17 -0
  76. package/dist/consent/applyConsentStatements.js.map +1 -0
  77. package/dist/consent/captureConsent.d.ts +19 -8
  78. package/dist/consent/captureConsent.js +34 -11
  79. package/dist/consent/captureConsent.js.map +1 -1
  80. package/dist/consent/consentSourcesField.d.ts +58 -0
  81. package/dist/consent/consentSourcesField.js +79 -0
  82. package/dist/consent/consentSourcesField.js.map +1 -0
  83. package/dist/consent/resolveConsentEntries.d.ts +24 -0
  84. package/dist/consent/resolveConsentEntries.js +43 -0
  85. package/dist/consent/resolveConsentEntries.js.map +1 -0
  86. package/dist/consent/resolveConsentSourcesRequest.d.ts +37 -0
  87. package/dist/consent/resolveConsentSourcesRequest.js +55 -0
  88. package/dist/consent/resolveConsentSourcesRequest.js.map +1 -0
  89. package/dist/consent/resolveConsentStatements.d.ts +45 -0
  90. package/dist/consent/resolveConsentStatements.js +44 -0
  91. package/dist/consent/resolveConsentStatements.js.map +1 -0
  92. package/dist/consent/resolvePublishedVersionRef.d.ts +17 -11
  93. package/dist/consent/resolvePublishedVersionRef.js +13 -10
  94. package/dist/consent/resolvePublishedVersionRef.js.map +1 -1
  95. package/dist/consent/types.d.ts +49 -0
  96. package/dist/email/departments.d.ts +55 -0
  97. package/dist/email/departments.js +130 -0
  98. package/dist/email/departments.js.map +1 -0
  99. package/dist/email/departmentsField.d.ts +49 -0
  100. package/dist/email/departmentsField.js +69 -0
  101. package/dist/email/departmentsField.js.map +1 -0
  102. package/dist/exports/client.d.ts +8 -1
  103. package/dist/exports/client.js +8 -1
  104. package/dist/exports/react.d.ts +8 -3
  105. package/dist/exports/react.js +6 -2
  106. package/dist/exports/rsc.d.ts +3 -1
  107. package/dist/exports/rsc.js +4 -2
  108. package/dist/exports/types.d.ts +16 -8
  109. package/dist/fields/buildFieldBlocks.js +28 -13
  110. package/dist/fields/buildFieldBlocks.js.map +1 -1
  111. package/dist/fields/builtin/calculation.js +7 -0
  112. package/dist/fields/builtin/calculation.js.map +1 -1
  113. package/dist/fields/builtin/checkbox.js +8 -0
  114. package/dist/fields/builtin/checkbox.js.map +1 -1
  115. package/dist/fields/builtin/consent.js +27 -21
  116. package/dist/fields/builtin/consent.js.map +1 -1
  117. package/dist/fields/builtin/country.d.ts +13 -0
  118. package/dist/fields/builtin/country.js +30 -0
  119. package/dist/fields/builtin/country.js.map +1 -0
  120. package/dist/fields/builtin/date.js +2 -0
  121. package/dist/fields/builtin/date.js.map +1 -1
  122. package/dist/fields/builtin/file.js +5 -4
  123. package/dist/fields/builtin/file.js.map +1 -1
  124. package/dist/fields/builtin/index.d.ts +8 -6
  125. package/dist/fields/builtin/index.js +10 -9
  126. package/dist/fields/builtin/index.js.map +1 -1
  127. package/dist/fields/builtin/message.js +8 -4
  128. package/dist/fields/builtin/message.js.map +1 -1
  129. package/dist/fields/builtin/repeater.js +1 -0
  130. package/dist/fields/builtin/repeater.js.map +1 -1
  131. package/dist/fields/builtin/select.js +1 -0
  132. package/dist/fields/builtin/select.js.map +1 -1
  133. package/dist/fields/builtin/state.d.ts +13 -0
  134. package/dist/fields/builtin/state.js +30 -0
  135. package/dist/fields/builtin/state.js.map +1 -0
  136. package/dist/fields/data/regions.d.ts +21 -0
  137. package/dist/fields/data/regions.js +1238 -0
  138. package/dist/fields/data/regions.js.map +1 -0
  139. package/dist/fields/fieldKey.d.ts +15 -0
  140. package/dist/fields/fieldKey.js +16 -0
  141. package/dist/fields/fieldKey.js.map +1 -0
  142. package/dist/fields/fieldNamesOfType.js +13 -8
  143. package/dist/fields/fieldNamesOfType.js.map +1 -1
  144. package/dist/fields/instanceOptions.js +20 -0
  145. package/dist/fields/instanceOptions.js.map +1 -0
  146. package/dist/fields/registry.d.ts +1 -0
  147. package/dist/fields/registry.js +21 -2
  148. package/dist/fields/registry.js.map +1 -1
  149. package/dist/fields/sharedConfig.js +46 -9
  150. package/dist/fields/sharedConfig.js.map +1 -1
  151. package/dist/fields/types.d.ts +54 -3
  152. package/dist/flow/engine.d.ts +6 -4
  153. package/dist/flow/engine.js +11 -6
  154. package/dist/flow/engine.js.map +1 -1
  155. package/dist/flow/normalizeFlow.js +16 -7
  156. package/dist/flow/normalizeFlow.js.map +1 -1
  157. package/dist/flow/types.d.ts +12 -3
  158. package/dist/flow/types.js +11 -0
  159. package/dist/flow/types.js.map +1 -0
  160. package/dist/form/pollState.d.ts +4 -4
  161. package/dist/form/pollState.js.map +1 -1
  162. package/dist/form/toFormDocument.d.ts +37 -12
  163. package/dist/form/toFormDocument.js +43 -7
  164. package/dist/form/toFormDocument.js.map +1 -1
  165. package/dist/form/types.d.ts +31 -14
  166. package/dist/index.d.ts +143 -28
  167. package/dist/index.js +43 -14
  168. package/dist/index.js.map +1 -1
  169. package/dist/plugin/customState.js +26 -0
  170. package/dist/plugin/customState.js.map +1 -0
  171. package/dist/plugin/registerCollections.js +23 -13
  172. package/dist/plugin/registerCollections.js.map +1 -1
  173. package/dist/plugin/uploadsCollection.d.ts +2 -0
  174. package/dist/poll/applyPollOptions.js +3 -2
  175. package/dist/poll/applyPollOptions.js.map +1 -1
  176. package/dist/poll/buildPollOptionSourceFields.js +2 -5
  177. package/dist/poll/buildPollOptionSourceFields.js.map +1 -1
  178. package/dist/poll/closeJob.d.ts +52 -0
  179. package/dist/poll/closeJob.js +119 -0
  180. package/dist/poll/closeJob.js.map +1 -0
  181. package/dist/poll/definePollOptionSource.d.ts +10 -1
  182. package/dist/poll/definePollOptionSource.js.map +1 -1
  183. package/dist/poll/definePollType.d.ts +34 -0
  184. package/dist/poll/definePollType.js +6 -0
  185. package/dist/poll/definePollType.js.map +1 -0
  186. package/dist/poll/effectivePollOptions.d.ts +38 -0
  187. package/dist/poll/effectivePollOptions.js +64 -0
  188. package/dist/poll/effectivePollOptions.js.map +1 -0
  189. package/dist/poll/mostVoted.d.ts +21 -0
  190. package/dist/poll/mostVoted.js +32 -0
  191. package/dist/poll/mostVoted.js.map +1 -0
  192. package/dist/poll/outcomeBeforeChange.js +91 -0
  193. package/dist/poll/outcomeBeforeChange.js.map +1 -0
  194. package/dist/poll/outcomeFields.d.ts +38 -0
  195. package/dist/poll/outcomeFields.js +52 -0
  196. package/dist/poll/outcomeFields.js.map +1 -0
  197. package/dist/poll/pollTypeRegistry.d.ts +34 -0
  198. package/dist/poll/pollTypeRegistry.js +71 -0
  199. package/dist/poll/pollTypeRegistry.js.map +1 -0
  200. package/dist/poll/resolvePollCloseRequest.js +105 -0
  201. package/dist/poll/resolvePollCloseRequest.js.map +1 -0
  202. package/dist/poll/resolvePollOptions.d.ts +2 -1
  203. package/dist/poll/resolvePollOptions.js +5 -17
  204. package/dist/poll/resolvePollOptions.js.map +1 -1
  205. package/dist/poll/resolvePollOptionsRequest.js +51 -0
  206. package/dist/poll/resolvePollOptionsRequest.js.map +1 -0
  207. package/dist/poll/resolvePollOutcome.d.ts +22 -9
  208. package/dist/poll/resolvePollOutcome.js +54 -14
  209. package/dist/poll/resolvePollOutcome.js.map +1 -1
  210. package/dist/poll/resultsField.js +21 -0
  211. package/dist/poll/resultsField.js.map +1 -0
  212. package/dist/prefill/valuesFromSearchParams.js +2 -1
  213. package/dist/prefill/valuesFromSearchParams.js.map +1 -1
  214. package/dist/react/Form.d.ts +8 -8
  215. package/dist/react/Form.js +74 -62
  216. package/dist/react/Form.js.map +1 -1
  217. package/dist/react/FormContext.d.ts +6 -4
  218. package/dist/react/FormContext.js.map +1 -1
  219. package/dist/react/FormControls.d.ts +3 -3
  220. package/dist/react/FormControls.js +3 -3
  221. package/dist/react/FormControls.js.map +1 -1
  222. package/dist/react/FormResults.d.ts +5 -5
  223. package/dist/react/FormResults.js +6 -6
  224. package/dist/react/FormResults.js.map +1 -1
  225. package/dist/react/Poll.d.ts +2 -2
  226. package/dist/react/Poll.js +5 -5
  227. package/dist/react/Poll.js.map +1 -1
  228. package/dist/react/contract.d.ts +2 -3
  229. package/dist/react/contract.js.map +1 -1
  230. package/dist/react/primitives/Checkbox.d.ts +4 -2
  231. package/dist/react/primitives/Checkbox.js +2 -1
  232. package/dist/react/primitives/Checkbox.js.map +1 -1
  233. package/dist/react/primitives/FieldShell.d.ts +2 -4
  234. package/dist/react/primitives/FieldShell.js +12 -19
  235. package/dist/react/primitives/FieldShell.js.map +1 -1
  236. package/dist/react/renderers/calculation.js +1 -2
  237. package/dist/react/renderers/calculation.js.map +1 -1
  238. package/dist/react/renderers/checkbox.js +1 -2
  239. package/dist/react/renderers/checkbox.js.map +1 -1
  240. package/dist/react/renderers/consent.js +78 -34
  241. package/dist/react/renderers/consent.js.map +1 -1
  242. package/dist/react/renderers/date.js +1 -3
  243. package/dist/react/renderers/date.js.map +1 -1
  244. package/dist/react/renderers/email.js +1 -2
  245. package/dist/react/renderers/email.js.map +1 -1
  246. package/dist/react/renderers/file.js +1 -2
  247. package/dist/react/renderers/file.js.map +1 -1
  248. package/dist/react/renderers/index.js +3 -0
  249. package/dist/react/renderers/index.js.map +1 -1
  250. package/dist/react/renderers/number.js +1 -2
  251. package/dist/react/renderers/number.js.map +1 -1
  252. package/dist/react/renderers/region.js +45 -0
  253. package/dist/react/renderers/region.js.map +1 -0
  254. package/dist/react/renderers/repeater.js +7 -10
  255. package/dist/react/renderers/repeater.js.map +1 -1
  256. package/dist/react/renderers/select.js +1 -2
  257. package/dist/react/renderers/select.js.map +1 -1
  258. package/dist/react/renderers/text.js +1 -2
  259. package/dist/react/renderers/text.js.map +1 -1
  260. package/dist/react/renderers/textarea.js +1 -2
  261. package/dist/react/renderers/textarea.js.map +1 -1
  262. package/dist/react/state.d.ts +0 -3
  263. package/dist/react/state.js +7 -11
  264. package/dist/react/state.js.map +1 -1
  265. package/dist/react/useField.d.ts +0 -1
  266. package/dist/react/useField.js +0 -1
  267. package/dist/react/useField.js.map +1 -1
  268. package/dist/react/useFormState.d.ts +1 -1
  269. package/dist/react/useFormState.js +1 -1
  270. package/dist/react/useFormState.js.map +1 -1
  271. package/dist/react/validateField.js +3 -6
  272. package/dist/react/validateField.js.map +1 -1
  273. package/dist/recall/interpolate.d.ts +4 -3
  274. package/dist/recall/interpolate.js +5 -4
  275. package/dist/recall/interpolate.js.map +1 -1
  276. package/dist/recall/resolver.d.ts +1 -1
  277. package/dist/recall/resolver.js +14 -2
  278. package/dist/recall/resolver.js.map +1 -1
  279. package/dist/spam/captcha.d.ts +1 -1
  280. package/dist/spam/captcha.js +1 -1
  281. package/dist/spam/captcha.js.map +1 -1
  282. package/dist/submissions/SubmissionAnswers.js +6 -2
  283. package/dist/submissions/SubmissionAnswers.js.map +1 -1
  284. package/dist/submissions/SubmissionAnswersClient.js +91 -62
  285. package/dist/submissions/SubmissionAnswersClient.js.map +1 -1
  286. package/dist/submissions/createSubmission.d.ts +36 -0
  287. package/dist/submissions/createSubmission.js +26 -0
  288. package/dist/submissions/createSubmission.js.map +1 -0
  289. package/dist/submissions/runSubmission.d.ts +10 -0
  290. package/dist/submissions/runSubmission.js +29 -18
  291. package/dist/submissions/runSubmission.js.map +1 -1
  292. package/dist/submissions/types.d.ts +11 -4
  293. package/dist/submissions/validateSubmission.js +38 -23
  294. package/dist/submissions/validateSubmission.js.map +1 -1
  295. package/dist/submissions/votedCookie.js +3 -3
  296. package/dist/submissions/votedCookie.js.map +1 -1
  297. package/dist/translations/de.js +102 -26
  298. package/dist/translations/de.js.map +1 -1
  299. package/dist/translations/en.js +103 -27
  300. package/dist/translations/en.js.map +1 -1
  301. package/dist/translations/keys.d.ts +97 -21
  302. package/dist/translations/keys.js +98 -22
  303. package/dist/translations/keys.js.map +1 -1
  304. package/dist/validation/buildRuleBlocks.js +18 -17
  305. package/dist/validation/buildRuleBlocks.js.map +1 -1
  306. package/dist/validation/builtin/email.js +1 -0
  307. package/dist/validation/builtin/email.js.map +1 -1
  308. package/dist/validation/builtin/matchesField.js +3 -7
  309. package/dist/validation/builtin/matchesField.js.map +1 -1
  310. package/dist/validation/builtin/max.js +1 -0
  311. package/dist/validation/builtin/max.js.map +1 -1
  312. package/dist/validation/builtin/maxDate.js +1 -0
  313. package/dist/validation/builtin/maxDate.js.map +1 -1
  314. package/dist/validation/builtin/maxLength.js +1 -0
  315. package/dist/validation/builtin/maxLength.js.map +1 -1
  316. package/dist/validation/builtin/min.js +1 -0
  317. package/dist/validation/builtin/min.js.map +1 -1
  318. package/dist/validation/builtin/minDate.js +1 -0
  319. package/dist/validation/builtin/minDate.js.map +1 -1
  320. package/dist/validation/builtin/minLength.js +1 -0
  321. package/dist/validation/builtin/minLength.js.map +1 -1
  322. package/dist/validation/builtin/notAlreadySubmitted.js +1 -0
  323. package/dist/validation/builtin/notAlreadySubmitted.js.map +1 -1
  324. package/dist/validation/builtin/oneOf.js +1 -0
  325. package/dist/validation/builtin/oneOf.js.map +1 -1
  326. package/dist/validation/builtin/pattern.js +11 -2
  327. package/dist/validation/builtin/pattern.js.map +1 -1
  328. package/dist/validation/builtin/url.js +1 -0
  329. package/dist/validation/builtin/url.js.map +1 -1
  330. package/dist/validation/builtin/validateRegexParams.js +44 -0
  331. package/dist/validation/builtin/validateRegexParams.js.map +1 -0
  332. package/dist/validation/fieldTargetParam.d.ts +22 -0
  333. package/dist/validation/fieldTargetParam.js +38 -0
  334. package/dist/validation/fieldTargetParam.js.map +1 -0
  335. package/dist/validation/runValidation.js +8 -29
  336. package/dist/validation/runValidation.js.map +1 -1
  337. package/dist/validation/types.d.ts +5 -11
  338. package/package.json +6 -6
  339. package/dist/consent/buildConsentSourceConfig.js +0 -49
  340. package/dist/consent/buildConsentSourceConfig.js.map +0 -1
  341. package/dist/consent/builtin/index.d.ts +0 -17
  342. package/dist/consent/builtin/index.js +0 -21
  343. package/dist/consent/builtin/index.js.map +0 -1
  344. package/dist/consent/builtin/pageReference.js +0 -75
  345. package/dist/consent/builtin/pageReference.js.map +0 -1
  346. package/dist/consent/builtin/static.js +0 -48
  347. package/dist/consent/builtin/static.js.map +0 -1
  348. package/dist/consent/defineConsentSource.d.ts +0 -35
  349. package/dist/consent/defineConsentSource.js +0 -6
  350. package/dist/consent/defineConsentSource.js.map +0 -1
  351. package/dist/consent/registry.d.ts +0 -16
  352. package/dist/consent/registry.js +0 -16
  353. package/dist/consent/registry.js.map +0 -1
  354. package/dist/consent/resolveConsentLinks.d.ts +0 -19
  355. package/dist/consent/resolveConsentLinks.js +0 -26
  356. package/dist/consent/resolveConsentLinks.js.map +0 -1
@@ -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,49 @@
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
+ type ConsentSourcesResolver = (args: {
41
+ req: PayloadRequest;
42
+ form: {
43
+ id: number | string;
44
+ title?: string;
45
+ };
46
+ }) => ConsentSourceEntry[] | Promise<ConsentSourceEntry[]>;
47
+ //#endregion
48
+ export { ConsentSourceEntry, ConsentSourcePage, ConsentSourcesResolver };
49
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,55 @@
1
+ import { Payload, PayloadRequest } from "payload";
2
+
3
+ //#region src/email/departments.d.ts
4
+ /** One selectable department for the `emailTeam` action; `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 `to` (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 as `to` (an email address); `label` is how the department is
14
+ * named in the admin select. Mirrors {@link FromAddressesResolver}. {@link resolveDepartmentOptions}
15
+ * builds this from a `departmentsField()`-bearing document with the reusable locale fallback, so a
16
+ * host does not reimplement it.
17
+ */
18
+ type DepartmentEmailsResolver = (args: {
19
+ req: PayloadRequest;
20
+ }) => Promise<DepartmentOption[]> | DepartmentOption[];
21
+ type ResolveDepartmentsRequestArgs = {
22
+ /** Whether the caller is authenticated (an admin/user). */isAuthed: boolean;
23
+ req: PayloadRequest;
24
+ resolver: DepartmentEmailsResolver;
25
+ };
26
+ type ResolveDepartmentsRequestResult = {
27
+ status: number;
28
+ body: {
29
+ options: DepartmentOption[];
30
+ } | {
31
+ errors: {
32
+ message: string;
33
+ }[];
34
+ };
35
+ };
36
+ type ResolveDepartmentOptionsArgs = {
37
+ payload: Payload;
38
+ req: PayloadRequest; /** A document fetched at `locale: 'all'`, so each localized subfield is a `{ locale: value }` map. */
39
+ doc: Record<string, unknown>; /** The array field name the departments live under; defaults to `departmentEmails`. */
40
+ field?: string;
41
+ };
42
+ /**
43
+ * Build the `emailTeam` `to` options from a `departmentsField()`-bearing document (a settings global,
44
+ * a tenants row, wherever the host placed it), fetched at `locale: 'all'`. Each row's `label` and
45
+ * `email` are resolved for `req.locale` via the current -> default -> next-available chain (see
46
+ * {@link pickLocaleValue}), reading `defaultLocale`/`localeCodes` from `payload.config.localization`
47
+ * (a bare string is used as-is when localization is disabled). Rows with no resolvable email are
48
+ * dropped; a row's label is resolved independently of its email and falls back to the email when
49
+ * absent. This is the reusable seam a host's `email.departments` resolver returns, so tenant scoping
50
+ * (which document is read) stays the host's call while the locale fallback stays consistent.
51
+ */
52
+ declare const resolveDepartmentOptions: (args: ResolveDepartmentOptionsArgs) => DepartmentOption[];
53
+ //#endregion
54
+ export { DepartmentEmailsResolver, DepartmentOption, ResolveDepartmentOptionsArgs, ResolveDepartmentsRequestArgs, ResolveDepartmentsRequestResult, resolveDepartmentOptions };
55
+ //# sourceMappingURL=departments.d.ts.map
@@ -0,0 +1,130 @@
1
+ import { localizedIf } from "../fields/localizedIf.js";
2
+ import { keys } from "../translations/keys.js";
3
+ import { asTranslate, labelFor } from "../translations/server.js";
4
+ //#region src/email/departments.ts
5
+ const TO_FIELD_REF = "@10x-media/form-builder/client#EndpointOptionsSelect";
6
+ /**
7
+ * Validate for the `to` field, closed over the host resolver (mirrors `validateFromField`): unset is
8
+ * fine, otherwise the value must be one of the resolver's options for this request. A throwing
9
+ * resolver fails closed with a translated message rather than surfacing a raw error on save.
10
+ *
11
+ * Payload runs this on every save, not only when `to` changed, so while the resolver is down no form
12
+ * carrying an email-team action with a `to` set can be saved at all, including edits that never touch
13
+ * the address. That is the deliberate trade: failing open would persist a routing target the host can
14
+ * no longer vouch for. A resolver reaching a flaky upstream should cache or fall back internally
15
+ * rather than throw.
16
+ */
17
+ const validateToField = (resolver) => async (value, { req }) => {
18
+ if (typeof value !== "string" || value.length === 0) return true;
19
+ let options;
20
+ try {
21
+ options = await resolver({ req });
22
+ } catch {
23
+ return asTranslate(req.t)(keys.validationToUnavailable);
24
+ }
25
+ return options.some((option) => option.value === value) ? true : asTranslate(req.t)(keys.validationToUnknown);
26
+ };
27
+ /**
28
+ * The `emailTeam` `to` select when `email.departments` is set: an `EndpointOptionsSelect` backed by
29
+ * the forms collection's `/:id/departments` endpoint (registered only then). Localized (following
30
+ * `localizeContent`), so each admin locale stores its own resolved department address and the
31
+ * submission's locale selects the stored `to` at send. Mirrors `buildFromField`; the route's document
32
+ * id goes unused server-side (the option set is request-scoped, not per-form).
33
+ */
34
+ const buildToField = (resolver, localizeContent) => ({
35
+ name: "to",
36
+ type: "text",
37
+ label: labelFor(keys.actionConfigTo),
38
+ validate: validateToField(resolver),
39
+ ...localizedIf(localizeContent),
40
+ admin: { components: { Field: {
41
+ path: TO_FIELD_REF,
42
+ clientProps: { endpoint: "departments" }
43
+ } } }
44
+ });
45
+ /**
46
+ * Authorize and resolve the `GET /:id/departments` request backing the `to` select: authenticated
47
+ * callers get the host resolver's current options for this request; anonymous callers are always
48
+ * refused. The route id is unused (see `buildToField`). Statuses mirror `resolveFromAddressesRequest`:
49
+ * 403 unauthenticated, 503 when the resolver throws (fail closed).
50
+ */
51
+ const resolveDepartmentsRequest = async (args) => {
52
+ const { isAuthed, req, resolver } = args;
53
+ if (!isAuthed) return {
54
+ status: 403,
55
+ body: { errors: [{ message: "Forbidden" }] }
56
+ };
57
+ try {
58
+ return {
59
+ status: 200,
60
+ body: { options: await resolver({ req }) }
61
+ };
62
+ } catch {
63
+ return {
64
+ status: 503,
65
+ body: { errors: [{ message: "Departments unavailable" }] }
66
+ };
67
+ }
68
+ };
69
+ /**
70
+ * Resolve one localized subfield value for `reqLocale` with the current -> default -> next-available
71
+ * chain. A non-localized subfield (fetched at `locale: 'all'` on a host without localization) is a
72
+ * bare string, used as-is; a localized one is a `{ [locale]: value }` map, from which `reqLocale`,
73
+ * then `defaultLocale`, then the first non-empty configured locale wins. Empty strings are skipped
74
+ * (they fall through the chain), and undefined is returned when nothing resolves.
75
+ */
76
+ const pickLocaleValue = (value, reqLocale, defaultLocale, localeCodes) => {
77
+ if (typeof value === "string") return value.length > 0 ? value : void 0;
78
+ if (value == null || typeof value !== "object") return;
79
+ const map = value;
80
+ const nonEmpty = (entry) => typeof entry === "string" && entry.length > 0 ? entry : void 0;
81
+ const ordered = [
82
+ reqLocale,
83
+ defaultLocale,
84
+ ...localeCodes
85
+ ].filter((code) => typeof code === "string" && code.length > 0);
86
+ for (const code of ordered) {
87
+ const hit = nonEmpty(map[code]);
88
+ if (hit !== void 0) return hit;
89
+ }
90
+ for (const key of Object.keys(map)) {
91
+ const hit = nonEmpty(map[key]);
92
+ if (hit !== void 0) return hit;
93
+ }
94
+ };
95
+ /**
96
+ * Build the `emailTeam` `to` options from a `departmentsField()`-bearing document (a settings global,
97
+ * a tenants row, wherever the host placed it), fetched at `locale: 'all'`. Each row's `label` and
98
+ * `email` are resolved for `req.locale` via the current -> default -> next-available chain (see
99
+ * {@link pickLocaleValue}), reading `defaultLocale`/`localeCodes` from `payload.config.localization`
100
+ * (a bare string is used as-is when localization is disabled). Rows with no resolvable email are
101
+ * dropped; a row's label is resolved independently of its email and falls back to the email when
102
+ * absent. This is the reusable seam a host's `email.departments` resolver returns, so tenant scoping
103
+ * (which document is read) stays the host's call while the locale fallback stays consistent.
104
+ */
105
+ const resolveDepartmentOptions = (args) => {
106
+ const { payload, req, doc, field } = args;
107
+ const rows = doc[field ?? "departmentEmails"];
108
+ if (!Array.isArray(rows)) return [];
109
+ const localization = payload.config.localization;
110
+ const localeCodes = localization ? localization.localeCodes : [];
111
+ const defaultLocale = localization ? localization.defaultLocale : void 0;
112
+ const reqLocale = typeof req.locale === "string" ? req.locale : void 0;
113
+ const options = [];
114
+ for (const row of rows) {
115
+ if (row == null || typeof row !== "object") continue;
116
+ const entry = row;
117
+ const email = pickLocaleValue(entry.email, reqLocale, defaultLocale, localeCodes);
118
+ if (email === void 0) continue;
119
+ const label = pickLocaleValue(entry.label, reqLocale, defaultLocale, localeCodes) ?? email;
120
+ options.push({
121
+ label,
122
+ value: email
123
+ });
124
+ }
125
+ return options;
126
+ };
127
+ //#endregion
128
+ export { buildToField, resolveDepartmentOptions, resolveDepartmentsRequest };
129
+
130
+ //# sourceMappingURL=departments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"departments.js","names":[],"sources":["../../src/email/departments.ts"],"sourcesContent":["import type { Payload, PayloadRequest, TextField } from 'payload'\nimport { localizedIf } from '../fields/localizedIf'\nimport { keys } from '../translations/keys'\nimport { asTranslate, labelFor } from '../translations/server'\n\n/** One selectable department for the `emailTeam` action; `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 `to` (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 as `to` (an email address); `label` is how the department is\n * named in the admin select. Mirrors {@link FromAddressesResolver}. {@link resolveDepartmentOptions}\n * builds this from a `departmentsField()`-bearing document with the reusable locale fallback, so a\n * host does not reimplement it.\n */\nexport type DepartmentEmailsResolver = (args: {\n\treq: PayloadRequest\n}) => Promise<DepartmentOption[]> | DepartmentOption[]\n\nconst TO_FIELD_REF = '@10x-media/form-builder/client#EndpointOptionsSelect'\n\n/**\n * Validate for the `to` field, closed over the host resolver (mirrors `validateFromField`): unset is\n * fine, otherwise the value must be one of the resolver's options for this request. A throwing\n * resolver fails closed with a translated message rather than surfacing a raw error on save.\n *\n * Payload runs this on every save, not only when `to` changed, so while the resolver is down no form\n * carrying an email-team action with a `to` set can be saved at all, including edits that never touch\n * the address. That is the deliberate trade: failing open would persist a routing target the host can\n * no longer vouch for. A resolver reaching a flaky upstream should cache or fall back internally\n * rather than throw.\n */\nexport const validateToField =\n\t(resolver: DepartmentEmailsResolver) =>\n\tasync (value: unknown, { req }: { req: PayloadRequest }): Promise<string | true> => {\n\t\tif (typeof value !== 'string' || value.length === 0) {\n\t\t\treturn true\n\t\t}\n\t\tlet options: DepartmentOption[]\n\t\ttry {\n\t\t\toptions = await resolver({ req })\n\t\t} catch {\n\t\t\treturn asTranslate(req.t)(keys.validationToUnavailable)\n\t\t}\n\t\treturn options.some((option) => option.value === value)\n\t\t\t? true\n\t\t\t: asTranslate(req.t)(keys.validationToUnknown)\n\t}\n\n/**\n * The `emailTeam` `to` select when `email.departments` is set: an `EndpointOptionsSelect` backed by\n * the forms collection's `/:id/departments` endpoint (registered only then). Localized (following\n * `localizeContent`), so each admin locale stores its own resolved department address and the\n * submission's locale selects the stored `to` at send. Mirrors `buildFromField`; the route's document\n * id goes unused server-side (the option set is request-scoped, not per-form).\n */\nexport const buildToField = (\n\tresolver: DepartmentEmailsResolver,\n\tlocalizeContent: boolean\n): TextField => ({\n\tname: 'to',\n\ttype: 'text',\n\tlabel: labelFor(keys.actionConfigTo),\n\tvalidate: validateToField(resolver),\n\t...localizedIf(localizeContent),\n\tadmin: {\n\t\tcomponents: {\n\t\t\tField: {\n\t\t\t\tpath: TO_FIELD_REF,\n\t\t\t\tclientProps: {\n\t\t\t\t\tendpoint: 'departments',\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t},\n})\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 `to` select: authenticated\n * callers get the host resolver's current options for this request; anonymous callers are always\n * refused. The route id is unused (see `buildToField`). Statuses mirror `resolveFromAddressesRequest`:\n * 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` `to` options from a `departmentsField()`-bearing document (a settings global,\n * a tenants row, wherever the host placed it), fetched at `locale: 'all'`. Each row's `label` and\n * `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":";;;;AAqBA,MAAM,eAAe;;;;;;;;;;;;AAarB,MAAa,mBACX,aACD,OAAO,OAAgB,EAAE,UAA2D;CACnF,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GACjD,OAAO;CAER,IAAI;CACJ,IAAI;EACH,UAAU,MAAM,SAAS,EAAE,IAAI,CAAC;CACjC,QAAQ;EACP,OAAO,YAAY,IAAI,CAAC,EAAE,KAAK,uBAAuB;CACvD;CACA,OAAO,QAAQ,MAAM,WAAW,OAAO,UAAU,KAAK,IACnD,OACA,YAAY,IAAI,CAAC,EAAE,KAAK,mBAAmB;AAC/C;;;;;;;;AASD,MAAa,gBACZ,UACA,qBACgB;CAChB,MAAM;CACN,MAAM;CACN,OAAO,SAAS,KAAK,cAAc;CACnC,UAAU,gBAAgB,QAAQ;CAClC,GAAG,YAAY,eAAe;CAC9B,OAAO,EACN,YAAY,EACX,OAAO;EACN,MAAM;EACN,aAAa,EACZ,UAAU,cACX;CACD,EACD,EACD;AACD;;;;;;;AAoBA,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,49 @@
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
+ declare const departmentsField: (options?: DepartmentsFieldOptions) => ArrayField;
47
+ //#endregion
48
+ export { DepartmentsFieldOptions, departmentsField };
49
+ //# sourceMappingURL=departmentsField.d.ts.map