@endora-commerce/contracts 0.109.0 → 0.110.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/dist/actor.d.ts +16 -0
  2. package/dist/actor.d.ts.map +1 -1
  3. package/dist/addresses.d.ts +35 -0
  4. package/dist/addresses.d.ts.map +1 -1
  5. package/dist/addresses.js +8 -1
  6. package/dist/addresses.js.map +1 -1
  7. package/dist/admin-contributions.d.ts +62 -7
  8. package/dist/admin-contributions.d.ts.map +1 -1
  9. package/dist/admin-contributions.js +27 -8
  10. package/dist/admin-contributions.js.map +1 -1
  11. package/dist/admin-roles.d.ts +8 -2
  12. package/dist/admin-roles.d.ts.map +1 -1
  13. package/dist/admin-roles.js.map +1 -1
  14. package/dist/admin-users.d.ts +9 -0
  15. package/dist/admin-users.d.ts.map +1 -1
  16. package/dist/admin.d.ts +77 -4
  17. package/dist/admin.d.ts.map +1 -1
  18. package/dist/admin.js +79 -3
  19. package/dist/admin.js.map +1 -1
  20. package/dist/assets-library.d.ts +26 -0
  21. package/dist/assets-library.d.ts.map +1 -1
  22. package/dist/assets-library.js +6 -3
  23. package/dist/assets-library.js.map +1 -1
  24. package/dist/audit-logs.d.ts +12 -0
  25. package/dist/audit-logs.d.ts.map +1 -1
  26. package/dist/audit-logs.js +12 -0
  27. package/dist/audit-logs.js.map +1 -1
  28. package/dist/blog.d.ts +382 -22
  29. package/dist/blog.d.ts.map +1 -1
  30. package/dist/blog.js +199 -17
  31. package/dist/blog.js.map +1 -1
  32. package/dist/carts.d.ts +394 -36
  33. package/dist/carts.d.ts.map +1 -1
  34. package/dist/carts.js +131 -8
  35. package/dist/carts.js.map +1 -1
  36. package/dist/catalog.d.ts +351 -219
  37. package/dist/catalog.d.ts.map +1 -1
  38. package/dist/catalog.js +209 -157
  39. package/dist/catalog.js.map +1 -1
  40. package/dist/cms-brand.d.ts +14 -14
  41. package/dist/cms.d.ts +41 -16
  42. package/dist/cms.d.ts.map +1 -1
  43. package/dist/cms.js.map +1 -1
  44. package/dist/common.d.ts +23 -6
  45. package/dist/common.d.ts.map +1 -1
  46. package/dist/common.js +25 -2
  47. package/dist/common.js.map +1 -1
  48. package/dist/comparisons.d.ts +28 -21
  49. package/dist/comparisons.d.ts.map +1 -1
  50. package/dist/comparisons.js +2 -1
  51. package/dist/comparisons.js.map +1 -1
  52. package/dist/credit-limits.d.ts +1 -0
  53. package/dist/credit-limits.d.ts.map +1 -1
  54. package/dist/credit-limits.js +14 -0
  55. package/dist/credit-limits.js.map +1 -1
  56. package/dist/crm.d.ts +79 -49
  57. package/dist/crm.d.ts.map +1 -1
  58. package/dist/crm.js +6 -0
  59. package/dist/crm.js.map +1 -1
  60. package/dist/custom-fields.d.ts +27 -13
  61. package/dist/custom-fields.d.ts.map +1 -1
  62. package/dist/custom-fields.js +15 -1
  63. package/dist/custom-fields.js.map +1 -1
  64. package/dist/customer-accounts.d.ts +186 -22
  65. package/dist/customer-accounts.d.ts.map +1 -1
  66. package/dist/customer-accounts.js +39 -0
  67. package/dist/customer-accounts.js.map +1 -1
  68. package/dist/customers.d.ts +40 -73
  69. package/dist/customers.d.ts.map +1 -1
  70. package/dist/customers.js +45 -10
  71. package/dist/customers.js.map +1 -1
  72. package/dist/document-templates.d.ts +12 -12
  73. package/dist/errors.d.ts +119 -1
  74. package/dist/errors.d.ts.map +1 -1
  75. package/dist/errors.js +146 -1
  76. package/dist/errors.js.map +1 -1
  77. package/dist/forms-logic.d.ts +79 -0
  78. package/dist/forms-logic.d.ts.map +1 -0
  79. package/dist/forms-logic.fixtures.d.ts +52 -0
  80. package/dist/forms-logic.fixtures.d.ts.map +1 -0
  81. package/dist/forms-logic.fixtures.js +610 -0
  82. package/dist/forms-logic.fixtures.js.map +1 -0
  83. package/dist/forms-logic.js +699 -0
  84. package/dist/forms-logic.js.map +1 -0
  85. package/dist/forms.d.ts +9833 -0
  86. package/dist/forms.d.ts.map +1 -0
  87. package/dist/forms.js +827 -0
  88. package/dist/forms.js.map +1 -0
  89. package/dist/import-export.d.ts +180 -0
  90. package/dist/import-export.d.ts.map +1 -1
  91. package/dist/import-export.js +60 -0
  92. package/dist/import-export.js.map +1 -1
  93. package/dist/index.d.ts +10 -1
  94. package/dist/index.d.ts.map +1 -1
  95. package/dist/index.js +18 -0
  96. package/dist/index.js.map +1 -1
  97. package/dist/inventory.d.ts +9 -9
  98. package/dist/invoice-ledger.d.ts +7 -7
  99. package/dist/invoices.d.ts.map +1 -1
  100. package/dist/invoices.js +4 -0
  101. package/dist/invoices.js.map +1 -1
  102. package/dist/mfa.d.ts +124 -4
  103. package/dist/mfa.d.ts.map +1 -1
  104. package/dist/mfa.js +46 -0
  105. package/dist/mfa.js.map +1 -1
  106. package/dist/modules.d.ts +36 -4
  107. package/dist/modules.d.ts.map +1 -1
  108. package/dist/modules.js +68 -0
  109. package/dist/modules.js.map +1 -1
  110. package/dist/money-decimal.d.ts +54 -0
  111. package/dist/money-decimal.d.ts.map +1 -1
  112. package/dist/money-decimal.js +95 -0
  113. package/dist/money-decimal.js.map +1 -1
  114. package/dist/newsletter.d.ts +4 -4
  115. package/dist/orders.d.ts +105 -12
  116. package/dist/orders.d.ts.map +1 -1
  117. package/dist/orders.js +60 -4
  118. package/dist/orders.js.map +1 -1
  119. package/dist/organization-registry-lookup.d.ts +362 -0
  120. package/dist/organization-registry-lookup.d.ts.map +1 -0
  121. package/dist/organization-registry-lookup.js +196 -0
  122. package/dist/organization-registry-lookup.js.map +1 -0
  123. package/dist/organization-roles.d.ts +340 -0
  124. package/dist/organization-roles.d.ts.map +1 -0
  125. package/dist/organization-roles.js +211 -0
  126. package/dist/organization-roles.js.map +1 -0
  127. package/dist/organizations.d.ts +123 -89
  128. package/dist/organizations.d.ts.map +1 -1
  129. package/dist/organizations.js +68 -24
  130. package/dist/organizations.js.map +1 -1
  131. package/dist/page-builder-props.d.ts +56 -56
  132. package/dist/pim-connector.d.ts +7 -3
  133. package/dist/pim-connector.d.ts.map +1 -1
  134. package/dist/pim-connector.js +6 -2
  135. package/dist/pim-connector.js.map +1 -1
  136. package/dist/pim-field-path.d.ts +5 -1
  137. package/dist/pim-field-path.d.ts.map +1 -1
  138. package/dist/pim-field-path.js +37 -81
  139. package/dist/pim-field-path.js.map +1 -1
  140. package/dist/pim-locale-mapping.d.ts +131 -0
  141. package/dist/pim-locale-mapping.d.ts.map +1 -0
  142. package/dist/pim-locale-mapping.js +193 -0
  143. package/dist/pim-locale-mapping.js.map +1 -0
  144. package/dist/price-books.d.ts +67 -63
  145. package/dist/price-books.d.ts.map +1 -1
  146. package/dist/price-books.js +6 -2
  147. package/dist/price-books.js.map +1 -1
  148. package/dist/price-lists.d.ts +8 -8
  149. package/dist/product-feeds.d.ts +94 -94
  150. package/dist/product-feeds.d.ts.map +1 -1
  151. package/dist/product-feeds.js +5 -0
  152. package/dist/product-feeds.js.map +1 -1
  153. package/dist/product-scope-model.d.ts +161 -0
  154. package/dist/product-scope-model.d.ts.map +1 -0
  155. package/dist/product-scope-model.js +161 -0
  156. package/dist/product-scope-model.js.map +1 -0
  157. package/dist/product-scope-overrides.d.ts +0 -103
  158. package/dist/product-scope-overrides.d.ts.map +1 -1
  159. package/dist/product-scope-overrides.js +0 -54
  160. package/dist/product-scope-overrides.js.map +1 -1
  161. package/dist/product-scoped-values.d.ts +2610 -0
  162. package/dist/product-scoped-values.d.ts.map +1 -0
  163. package/dist/product-scoped-values.js +425 -0
  164. package/dist/product-scoped-values.js.map +1 -0
  165. package/dist/product-scopes.d.ts +182 -64
  166. package/dist/product-scopes.d.ts.map +1 -1
  167. package/dist/product-scopes.js +89 -18
  168. package/dist/product-scopes.js.map +1 -1
  169. package/dist/product-tax-rates.d.ts +38 -0
  170. package/dist/product-tax-rates.d.ts.map +1 -0
  171. package/dist/product-tax-rates.js +45 -0
  172. package/dist/product-tax-rates.js.map +1 -0
  173. package/dist/product-url-keys.d.ts +51 -45
  174. package/dist/product-url-keys.d.ts.map +1 -1
  175. package/dist/product-url-keys.js +73 -39
  176. package/dist/product-url-keys.js.map +1 -1
  177. package/dist/product-value-resolver.d.ts +37 -60
  178. package/dist/product-value-resolver.d.ts.map +1 -1
  179. package/dist/product-value-resolver.js +36 -96
  180. package/dist/product-value-resolver.js.map +1 -1
  181. package/dist/projects.d.ts +15 -0
  182. package/dist/projects.d.ts.map +1 -1
  183. package/dist/projects.js +6 -0
  184. package/dist/projects.js.map +1 -1
  185. package/dist/promotions.d.ts +10 -10
  186. package/dist/pwa.d.ts +2 -2
  187. package/dist/quick-order.d.ts +150 -6
  188. package/dist/quick-order.d.ts.map +1 -1
  189. package/dist/quick-order.js +75 -1
  190. package/dist/quick-order.js.map +1 -1
  191. package/dist/quote-requests.d.ts +63 -12
  192. package/dist/quote-requests.d.ts.map +1 -1
  193. package/dist/quote-requests.js +42 -1
  194. package/dist/quote-requests.js.map +1 -1
  195. package/dist/record-references.d.ts.map +1 -1
  196. package/dist/record-references.js +2 -3
  197. package/dist/record-references.js.map +1 -1
  198. package/dist/record-rich-text.d.ts.map +1 -1
  199. package/dist/record-rich-text.js +2 -1
  200. package/dist/record-rich-text.js.map +1 -1
  201. package/dist/returns.d.ts +208 -52
  202. package/dist/returns.d.ts.map +1 -1
  203. package/dist/returns.js +139 -26
  204. package/dist/returns.js.map +1 -1
  205. package/dist/saved-list-views.d.ts +28 -0
  206. package/dist/saved-list-views.d.ts.map +1 -1
  207. package/dist/saved-list-views.js +14 -1
  208. package/dist/saved-list-views.js.map +1 -1
  209. package/dist/scoped-write-encoding.d.ts +100 -0
  210. package/dist/scoped-write-encoding.d.ts.map +1 -0
  211. package/dist/scoped-write-encoding.js +135 -0
  212. package/dist/scoped-write-encoding.js.map +1 -0
  213. package/dist/search.d.ts +18 -16
  214. package/dist/search.d.ts.map +1 -1
  215. package/dist/seo.d.ts +81 -28
  216. package/dist/seo.d.ts.map +1 -1
  217. package/dist/seo.js +8 -1
  218. package/dist/seo.js.map +1 -1
  219. package/dist/settings.d.ts +129 -0
  220. package/dist/settings.d.ts.map +1 -1
  221. package/dist/settings.js +36 -0
  222. package/dist/settings.js.map +1 -1
  223. package/dist/shopping-lists.d.ts +24 -3
  224. package/dist/shopping-lists.d.ts.map +1 -1
  225. package/dist/shopping-lists.js +20 -0
  226. package/dist/shopping-lists.js.map +1 -1
  227. package/dist/storefront-cache-tags.d.ts +12 -0
  228. package/dist/storefront-cache-tags.d.ts.map +1 -1
  229. package/dist/storefront-cache-tags.js +12 -0
  230. package/dist/storefront-cache-tags.js.map +1 -1
  231. package/dist/storefront-value-overrides.d.ts +18 -56
  232. package/dist/storefront-value-overrides.d.ts.map +1 -1
  233. package/dist/storefront-value-overrides.js +11 -86
  234. package/dist/storefront-value-overrides.js.map +1 -1
  235. package/dist/tasks.d.ts +6 -6
  236. package/dist/transactional-emails.d.ts +9 -9
  237. package/package.json +2 -2
  238. package/dist/scoped-translations.d.ts +0 -48
  239. package/dist/scoped-translations.d.ts.map +0 -1
  240. package/dist/scoped-translations.js +0 -78
  241. package/dist/scoped-translations.js.map +0 -1
package/dist/forms.js ADDED
@@ -0,0 +1,827 @@
1
+ import { z } from 'zod';
2
+ import { isoDateTimeSchema } from './common.js';
3
+ /**
4
+ * Forms (`specs/170-forms-module/`) — the definition of a form, the admin and public API shapes,
5
+ * the events, and the module's constants. Normative: `contracts/form-definition.md` §1,
6
+ * `contracts/admin-api.md`, `contracts/public-api.md`, `contracts/events-and-webhook.md` §1–§2.
7
+ *
8
+ * The behaviour over these shapes — visibility, the publish rules, server-side validation — is
9
+ * `forms-logic.ts`, beside this file, so the backend, the storefront renderer and the admin preview
10
+ * evaluate one implementation (research R-5).
11
+ *
12
+ * Every object schema is strict: a definition refuses an unknown key, so a client cannot smuggle
13
+ * recipients or flags into it, and the public submission refuses an attribution it did not earn.
14
+ */
15
+ // --- Constants ---------------------------------------------------------------------------------
16
+ /** Research R-27. */
17
+ export const FORMS_LIMITS = {
18
+ fieldsPerForm: 100,
19
+ sectionsPerForm: 30,
20
+ optionsPerChoice: 200,
21
+ conditionsPerRule: 20,
22
+ groupsPerRule: 10,
23
+ singleLineChars: 1000,
24
+ multiLineChars: 10000,
25
+ hiddenChars: 1000,
26
+ richTextChars: 20000,
27
+ keyChars: 64,
28
+ nameChars: 200,
29
+ recipients: 10,
30
+ channelOverrides: 50,
31
+ noteChars: 5000,
32
+ retentionDaysMax: 3650,
33
+ bulkDeleteMax: 200,
34
+ submissionBytes: 262144,
35
+ searchTextChars: 20000,
36
+ pageUrlChars: 2048,
37
+ };
38
+ export const FORM_FIELD_TYPES = [
39
+ 'text',
40
+ 'email',
41
+ 'phone',
42
+ 'number',
43
+ 'textarea',
44
+ 'select',
45
+ 'radio',
46
+ 'checkboxes',
47
+ 'checkbox',
48
+ 'datetime',
49
+ 'country',
50
+ 'address',
51
+ 'hidden',
52
+ 'content',
53
+ 'section_break',
54
+ 'privacy_consent',
55
+ 'marketing_consent',
56
+ 'terms',
57
+ ];
58
+ /** The layout elements: they take no answer and carry no key. */
59
+ export const FORM_LAYOUT_ELEMENT_TYPES = ['content', 'section_break'];
60
+ /** Every type that takes an answer. */
61
+ export const FORM_INPUT_FIELD_TYPES = FORM_FIELD_TYPES.filter((type) => !FORM_LAYOUT_ELEMENT_TYPES.includes(type));
62
+ /** The three consent types; their answer is also recorded with the text shown (FR-029). */
63
+ export const FORM_CONSENT_TYPES = ['privacy_consent', 'marketing_consent', 'terms'];
64
+ export const FORM_CONDITION_OPERATORS = [
65
+ 'equals',
66
+ 'not_equals',
67
+ 'greater_than',
68
+ 'less_than',
69
+ 'contains',
70
+ 'not_contains',
71
+ 'is_empty',
72
+ 'is_not_empty',
73
+ ];
74
+ const EMPTY_TESTS = ['is_empty', 'is_not_empty'];
75
+ const TEXT_OPERATORS = ['equals', 'not_equals', 'contains', 'not_contains', ...EMPTY_TESTS];
76
+ const ORDERED_OPERATORS = ['equals', 'not_equals', 'greater_than', 'less_than', ...EMPTY_TESTS];
77
+ const CHOICE_OPERATORS = ['equals', 'not_equals', ...EMPTY_TESTS];
78
+ const GROUP_OPERATORS = ['contains', 'not_contains', ...EMPTY_TESTS];
79
+ const BOOLEAN_OPERATORS = ['equals', ...EMPTY_TESTS];
80
+ /** Which operators a condition may apply to a referenced field of each type (data-model §3.2). */
81
+ export const FORM_CONDITION_OPERATORS_BY_TYPE = {
82
+ text: TEXT_OPERATORS,
83
+ email: TEXT_OPERATORS,
84
+ phone: TEXT_OPERATORS,
85
+ textarea: TEXT_OPERATORS,
86
+ hidden: TEXT_OPERATORS,
87
+ number: ORDERED_OPERATORS,
88
+ datetime: ORDERED_OPERATORS,
89
+ select: CHOICE_OPERATORS,
90
+ radio: CHOICE_OPERATORS,
91
+ country: CHOICE_OPERATORS,
92
+ checkboxes: GROUP_OPERATORS,
93
+ checkbox: BOOLEAN_OPERATORS,
94
+ privacy_consent: BOOLEAN_OPERATORS,
95
+ marketing_consent: BOOLEAN_OPERATORS,
96
+ terms: BOOLEAN_OPERATORS,
97
+ address: EMPTY_TESTS,
98
+ content: [],
99
+ section_break: [],
100
+ };
101
+ export const FORM_STATUSES = ['draft', 'published', 'closed'];
102
+ export const FORM_ENTRY_STATUSES = ['new', 'read', 'closed', 'spam'];
103
+ export const FORM_AVAILABILITY = ['open', 'closed', 'not_yet_open', 'full', 'unavailable'];
104
+ /** The refusal tokens of `FORM_NOT_ACCEPTING` (research R-25). */
105
+ export const FORM_NOT_ACCEPTING_REASONS = ['closed', 'not_yet_open', 'full', 'sign_in_required', 'unavailable'];
106
+ export const FORM_FIELD_ERROR_CODES = [
107
+ 'required',
108
+ 'invalid_email',
109
+ 'invalid_phone',
110
+ 'invalid_number',
111
+ 'too_short',
112
+ 'too_long',
113
+ 'below_min',
114
+ 'above_max',
115
+ 'step_mismatch',
116
+ 'invalid_date',
117
+ 'too_early',
118
+ 'too_late',
119
+ 'too_few',
120
+ 'too_many',
121
+ 'unknown_option',
122
+ 'pattern',
123
+ 'single_line',
124
+ 'invalid_country',
125
+ 'consent_required',
126
+ ];
127
+ /** The publish rules (data-model §3.5), the tokens of `FORM_DEFINITION_INVALID`. */
128
+ export const FORM_DEFINITION_ISSUE_CODES = [
129
+ 'duplicate_key',
130
+ 'invalid_key',
131
+ 'missing_options',
132
+ 'duplicate_option_value',
133
+ 'unknown_condition_field',
134
+ 'condition_on_layout_element',
135
+ 'operator_not_allowed',
136
+ 'cyclic_visibility',
137
+ 'multiple_submitter_email',
138
+ 'min_above_max',
139
+ 'invalid_redirect_url',
140
+ 'invalid_page_reference',
141
+ 'consent_must_be_required',
142
+ 'marketing_consent_required',
143
+ 'width_exceeds_columns',
144
+ 'too_many_fields',
145
+ 'too_many_sections',
146
+ 'too_many_options',
147
+ 'too_many_conditions',
148
+ 'invalid_window',
149
+ 'missing_default_language_label',
150
+ ];
151
+ /** The error codes this module raises (research R-25). Each joins `ERROR_CODES` with its first raise site. */
152
+ export const FORMS_ERROR_CODES = {
153
+ FORM_NOT_FOUND: 'FORM_NOT_FOUND',
154
+ FORM_KEY_TAKEN: 'FORM_KEY_TAKEN',
155
+ FORM_DEFINITION_INVALID: 'FORM_DEFINITION_INVALID',
156
+ FORM_REVISION_CONFLICT: 'FORM_REVISION_CONFLICT',
157
+ FORM_HAS_ENTRIES: 'FORM_HAS_ENTRIES',
158
+ FORM_SCOPE_REQUIRED: 'FORM_SCOPE_REQUIRED',
159
+ FORM_NOT_ACCEPTING: 'FORM_NOT_ACCEPTING',
160
+ FORM_SUBMISSION_INVALID: 'FORM_SUBMISSION_INVALID',
161
+ FORM_SUBMISSION_TOO_LARGE: 'FORM_SUBMISSION_TOO_LARGE',
162
+ FORM_CAPTCHA_FAILED: 'FORM_CAPTCHA_FAILED',
163
+ FORM_CAPTCHA_UNAVAILABLE: 'FORM_CAPTCHA_UNAVAILABLE',
164
+ FORM_ENTRY_NOT_FOUND: 'FORM_ENTRY_NOT_FOUND',
165
+ FORM_ENTRY_STATUS_CONFLICT: 'FORM_ENTRY_STATUS_CONFLICT',
166
+ };
167
+ export const FORMS_EVENTS = {
168
+ /** An entry was accepted; the webhook payload too (events-and-webhook.md §1). */
169
+ ENTRY_SUBMITTED: 'forms.entry.submitted.v1',
170
+ /** What the public read answers changed — internal, drives storefront revalidation (§2). */
171
+ FORM_CHANGED: 'forms.form.changed',
172
+ };
173
+ export const FORMS_WEBHOOK_EVENT_TYPES = [FORMS_EVENTS.ENTRY_SUBMITTED];
174
+ export const FORMS_SETTING_CODES = {
175
+ ENABLED: 'forms.enabled',
176
+ CAPTCHA_PROVIDER: 'forms.captcha_provider',
177
+ CAPTCHA_SITE_KEY: 'forms.captcha_site_key',
178
+ CAPTCHA_SECRET_KEY: 'forms.captcha_secret_key',
179
+ };
180
+ export const FORM_CAPTCHA_PROVIDERS = ['none', 'turnstile', 'hcaptcha'];
181
+ export const FORMS_PERMISSIONS = {
182
+ READ: 'forms:read',
183
+ WRITE: 'forms:write',
184
+ ENTRIES_READ: 'forms:entries_read',
185
+ ENTRIES_WRITE: 'forms:entries_write',
186
+ ENTRIES_EXPORT: 'forms:entries_export',
187
+ };
188
+ export const FORM_TEXT_PATTERNS = ['digits', 'letters', 'alphanumeric', 'url'];
189
+ export const FORM_DATETIME_MODES = ['date', 'time', 'datetime'];
190
+ export const FORM_HIDDEN_SOURCES = ['static', 'page_url', 'page_title', 'query_param', 'referrer'];
191
+ export const FORM_ADDRESS_PARTS = ['street', 'line2', 'postalCode', 'city', 'country'];
192
+ /** The shape of a `datetime` value in each mode — also the shape of its bounds. */
193
+ export const FORM_DATETIME_PATTERNS = {
194
+ date: /^\d{4}-\d{2}-\d{2}$/,
195
+ time: /^([01]\d|2[0-3]):[0-5]\d$/,
196
+ datetime: /^\d{4}-\d{2}-\d{2}T([01]\d|2[0-3]):[0-5]\d$/,
197
+ };
198
+ // --- Identifiers -------------------------------------------------------------------------------
199
+ /** A field key: the column name of an answer, in the export and the webhook payload. */
200
+ export const formKeySchema = z.string().regex(/^[a-z][a-z0-9_]{0,63}$/, 'a-z, 0-9 and _, starting with a letter');
201
+ /** A stable element id (section, field, option) — text ids are derived from it (R-7). */
202
+ export const formElementIdSchema = z.string().regex(/^[A-Za-z0-9_-]{1,40}$/);
203
+ /** A BCP-47-shaped language code, as the storefront languages are spelled. */
204
+ export const formLanguageSchema = z
205
+ .string()
206
+ .min(2)
207
+ .max(16)
208
+ .regex(/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/);
209
+ const textIdSchema = z.string().regex(/^[A-Za-z0-9_.-]{1,200}$/);
210
+ const widthSchema = z.number().int().min(1).max(3);
211
+ const lengthSchema = (max) => z.number().int().min(0).max(max);
212
+ // --- Visibility --------------------------------------------------------------------------------
213
+ export const formConditionSchema = z
214
+ .object({
215
+ fieldId: formElementIdSchema,
216
+ operator: z.enum(FORM_CONDITION_OPERATORS),
217
+ value: z.union([z.string().max(FORMS_LIMITS.singleLineChars), z.number().finite()]).optional(),
218
+ })
219
+ .strict();
220
+ /** Conditions inside a group are joined by `connective`, groups by the opposite one (FR-030). */
221
+ export const visibilityRuleSchema = z
222
+ .object({
223
+ connective: z.enum(['and', 'or']),
224
+ groups: z.array(z.array(formConditionSchema).min(1)).min(1).max(FORMS_LIMITS.groupsPerRule),
225
+ })
226
+ .strict()
227
+ .refine((rule) => rule.groups.flat().length <= FORMS_LIMITS.conditionsPerRule, {
228
+ message: `At most ${FORMS_LIMITS.conditionsPerRule} conditions`,
229
+ path: ['groups'],
230
+ });
231
+ // --- Fields ------------------------------------------------------------------------------------
232
+ const optionSchema = z
233
+ .object({
234
+ id: formElementIdSchema,
235
+ value: z.string().trim().min(1).max(FORMS_LIMITS.nameChars),
236
+ })
237
+ .strict();
238
+ const optionsSchema = z.array(optionSchema).max(FORMS_LIMITS.optionsPerChoice);
239
+ const countryCodeSchema = z.string().regex(/^[A-Z]{2}$/);
240
+ const addressPartSchema = z.object({ enabled: z.boolean(), required: z.boolean() }).strict();
241
+ /** `street` and `city` are always part of an address (data-model §3.1). */
242
+ const alwaysEnabledPartSchema = z.object({ enabled: z.literal(true), required: z.boolean() }).strict();
243
+ /** What every input field carries (data-model §3.1). */
244
+ const inputBase = {
245
+ id: formElementIdSchema,
246
+ key: formKeySchema,
247
+ width: widthSchema.default(1),
248
+ required: z.boolean().default(false),
249
+ visibility: visibilityRuleSchema.optional(),
250
+ shareWithIntegrations: z.boolean().default(false),
251
+ };
252
+ /** What a layout element carries. */
253
+ const layoutBase = {
254
+ id: formElementIdSchema,
255
+ width: widthSchema.default(1),
256
+ visibility: visibilityRuleSchema.optional(),
257
+ };
258
+ /** The type-specific settings of each type, shared by the definition and the public read. */
259
+ const typeSettings = {
260
+ text: {
261
+ minLength: lengthSchema(FORMS_LIMITS.singleLineChars).optional(),
262
+ maxLength: lengthSchema(FORMS_LIMITS.singleLineChars).optional(),
263
+ pattern: z.enum(FORM_TEXT_PATTERNS).optional(),
264
+ defaultValue: z.string().max(FORMS_LIMITS.singleLineChars).optional(),
265
+ },
266
+ email: {
267
+ /** The answer that is the submitter's address: Reply-To and the confirmation (≤ 1 per form). */
268
+ submitterEmail: z.boolean().default(false),
269
+ defaultValue: z.string().max(FORMS_LIMITS.singleLineChars).optional(),
270
+ },
271
+ phone: {
272
+ defaultValue: z.string().max(FORMS_LIMITS.singleLineChars).optional(),
273
+ },
274
+ number: {
275
+ min: z.number().finite().optional(),
276
+ max: z.number().finite().optional(),
277
+ step: z.number().finite().positive().optional(),
278
+ defaultValue: z.number().finite().optional(),
279
+ },
280
+ textarea: {
281
+ minLength: lengthSchema(FORMS_LIMITS.multiLineChars).optional(),
282
+ maxLength: lengthSchema(FORMS_LIMITS.multiLineChars).optional(),
283
+ defaultValue: z.string().max(FORMS_LIMITS.multiLineChars).optional(),
284
+ },
285
+ choice: {
286
+ defaultValue: z.string().max(FORMS_LIMITS.nameChars).optional(),
287
+ },
288
+ checkboxes: {
289
+ minSelected: z.number().int().min(0).max(FORMS_LIMITS.optionsPerChoice).optional(),
290
+ maxSelected: z.number().int().min(0).max(FORMS_LIMITS.optionsPerChoice).optional(),
291
+ defaultValue: z.array(z.string().max(FORMS_LIMITS.nameChars)).max(FORMS_LIMITS.optionsPerChoice).optional(),
292
+ },
293
+ checkbox: {
294
+ defaultChecked: z.boolean().optional(),
295
+ },
296
+ datetime: {
297
+ mode: z.enum(FORM_DATETIME_MODES),
298
+ earliest: z.string().max(16).optional(),
299
+ latest: z.string().max(16).optional(),
300
+ },
301
+ country: {
302
+ allowedCountries: z.array(countryCodeSchema).max(300).optional(),
303
+ defaultValue: countryCodeSchema.optional(),
304
+ },
305
+ hidden: {
306
+ source: z.enum(FORM_HIDDEN_SOURCES),
307
+ staticValue: z.string().max(FORMS_LIMITS.hiddenChars).optional(),
308
+ paramName: z
309
+ .string()
310
+ .regex(/^[A-Za-z0-9_.-]{1,64}$/)
311
+ .optional(),
312
+ },
313
+ };
314
+ /** A `datetime` field's bounds are written in the shape of its mode. */
315
+ function datetimeBoundsHold(field) {
316
+ const pattern = FORM_DATETIME_PATTERNS[field.mode];
317
+ return [field.earliest, field.latest].every((bound) => bound === undefined || pattern.test(bound));
318
+ }
319
+ const datetimeBoundsMessage = { message: 'Bounds must be written in the shape of the mode', path: ['earliest'] };
320
+ export const formFieldSchema = z.discriminatedUnion('type', [
321
+ z.object({ type: z.literal('text'), ...inputBase, ...typeSettings.text }).strict(),
322
+ z.object({ type: z.literal('email'), ...inputBase, ...typeSettings.email }).strict(),
323
+ z.object({ type: z.literal('phone'), ...inputBase, ...typeSettings.phone }).strict(),
324
+ z.object({ type: z.literal('number'), ...inputBase, ...typeSettings.number }).strict(),
325
+ z.object({ type: z.literal('textarea'), ...inputBase, ...typeSettings.textarea }).strict(),
326
+ z.object({ type: z.literal('select'), ...inputBase, options: optionsSchema, ...typeSettings.choice }).strict(),
327
+ z.object({ type: z.literal('radio'), ...inputBase, options: optionsSchema, ...typeSettings.choice }).strict(),
328
+ z.object({ type: z.literal('checkboxes'), ...inputBase, options: optionsSchema, ...typeSettings.checkboxes }).strict(),
329
+ z.object({ type: z.literal('checkbox'), ...inputBase, ...typeSettings.checkbox }).strict(),
330
+ z
331
+ .object({ type: z.literal('datetime'), ...inputBase, ...typeSettings.datetime })
332
+ .strict()
333
+ .refine(datetimeBoundsHold, datetimeBoundsMessage),
334
+ z.object({ type: z.literal('country'), ...inputBase, ...typeSettings.country }).strict(),
335
+ z
336
+ .object({
337
+ type: z.literal('address'),
338
+ ...inputBase,
339
+ parts: z
340
+ .object({
341
+ street: alwaysEnabledPartSchema,
342
+ line2: addressPartSchema,
343
+ postalCode: addressPartSchema,
344
+ city: alwaysEnabledPartSchema,
345
+ country: addressPartSchema,
346
+ })
347
+ .strict(),
348
+ })
349
+ .strict(),
350
+ z.object({ type: z.literal('hidden'), ...inputBase, ...typeSettings.hidden }).strict(),
351
+ z.object({ type: z.literal('content'), ...layoutBase }).strict(),
352
+ z.object({ type: z.literal('section_break'), ...layoutBase }).strict(),
353
+ // Consents are never pre-ticked: there is no `defaultChecked` to set (FR-029).
354
+ z.object({ type: z.literal('privacy_consent'), ...inputBase }).strict(),
355
+ z.object({ type: z.literal('marketing_consent'), ...inputBase }).strict(),
356
+ z.object({ type: z.literal('terms'), ...inputBase }).strict(),
357
+ ]);
358
+ export const formSectionSchema = z
359
+ .object({
360
+ id: formElementIdSchema,
361
+ columns: z.union([z.literal(1), z.literal(2), z.literal(3)]),
362
+ visibility: visibilityRuleSchema.optional(),
363
+ fields: z.array(formFieldSchema),
364
+ })
365
+ .strict();
366
+ // --- Behaviour, restrictions, texts ------------------------------------------------------------
367
+ export const formConfirmationSchema = z.discriminatedUnion('type', [
368
+ z.object({ type: z.literal('message') }).strict(),
369
+ z.object({ type: z.literal('redirect'), url: z.string().max(FORMS_LIMITS.pageUrlChars) }).strict(),
370
+ z.object({ type: z.literal('page'), cmsPageId: z.string().max(64) }).strict(),
371
+ ]);
372
+ export const formBehaviourSchema = z
373
+ .object({
374
+ confirmation: formConfirmationSchema,
375
+ captchaRequired: z.boolean(),
376
+ confirmationEmail: z.object({ enabled: z.boolean(), includeSummary: z.boolean() }).strict(),
377
+ })
378
+ .strict();
379
+ export const formRestrictionsSchema = z
380
+ .object({
381
+ maxEntries: z.number().int().min(1).max(1_000_000).nullable(),
382
+ availableFrom: isoDateTimeSchema.nullable(),
383
+ availableUntil: isoDateTimeSchema.nullable(),
384
+ signedInOnly: z.boolean(),
385
+ })
386
+ .strict()
387
+ .refine((r) => r.availableFrom === null || r.availableUntil === null || Date.parse(r.availableUntil) > Date.parse(r.availableFrom), { message: 'The window must end after it starts', path: ['availableUntil'] });
388
+ /** `texts[language][textId]` — the text ids of data-model §3.6. */
389
+ export const formTextsSchema = z.record(formLanguageSchema, z.record(textIdSchema, z.string().max(FORMS_LIMITS.richTextChars)));
390
+ /** Every element id of a definition: sections and fields, once each. */
391
+ function elementIdsAreUnique(sections) {
392
+ const ids = sections.flatMap((section) => [section.id, ...section.fields.map((field) => field.id)]);
393
+ return new Set(ids).size === ids.length;
394
+ }
395
+ /**
396
+ * The working copy and every published version. **Shape only**: a half-built form can be saved;
397
+ * the publish rules are `definitionIssues` (FR-011). The shape holds the limits and the element-id
398
+ * uniqueness the builder guarantees, which no shopper input can break.
399
+ */
400
+ export const formDefinitionSchema = z
401
+ .object({
402
+ schemaVersion: z.literal(1),
403
+ sections: z.array(formSectionSchema).min(1).max(FORMS_LIMITS.sectionsPerForm),
404
+ behaviour: formBehaviourSchema,
405
+ restrictions: formRestrictionsSchema,
406
+ texts: formTextsSchema,
407
+ })
408
+ .strict()
409
+ .refine((d) => d.sections.reduce((n, s) => n + s.fields.length, 0) <= FORMS_LIMITS.fieldsPerForm, {
410
+ message: `At most ${FORMS_LIMITS.fieldsPerForm} fields`,
411
+ path: ['sections'],
412
+ })
413
+ .refine((d) => elementIdsAreUnique(d.sections), { message: 'Element ids must be unique', path: ['sections'] });
414
+ export const formDefinitionIssueSchema = z
415
+ .object({
416
+ code: z.enum(FORM_DEFINITION_ISSUE_CODES),
417
+ /** The element the issue is about; `null` for a form-level rule (the window, the redirect). */
418
+ elementId: z.string().nullable(),
419
+ /** Where in the definition, e.g. `sections[0].fields[2].key`. */
420
+ path: z.string(),
421
+ })
422
+ .strict();
423
+ // --- Answers -----------------------------------------------------------------------------------
424
+ export const formAddressAnswerSchema = z
425
+ .object({
426
+ street: z.string().optional(),
427
+ line2: z.string().optional(),
428
+ postalCode: z.string().optional(),
429
+ city: z.string().optional(),
430
+ country: z.string().optional(),
431
+ })
432
+ .strict();
433
+ export const answerValueSchema = z.union([
434
+ z.string(),
435
+ z.number(),
436
+ z.boolean(),
437
+ z.array(z.string()),
438
+ formAddressAnswerSchema,
439
+ ]);
440
+ export const FORM_CONSENT_KINDS = ['privacy', 'marketing', 'terms'];
441
+ /** A consent as stored: what the shopper saw (sanitised HTML, submission language) and said. */
442
+ export const formConsentRecordSchema = z
443
+ .object({
444
+ fieldKey: formKeySchema,
445
+ kind: z.enum(FORM_CONSENT_KINDS),
446
+ given: z.boolean(),
447
+ text: z.string().max(FORMS_LIMITS.richTextChars),
448
+ })
449
+ .strict();
450
+ // --- Admin API: forms (admin-api.md §1) ----------------------------------------------------------
451
+ const recipientSchema = z.string().email().max(254);
452
+ const recipientListSchema = z.array(recipientSchema).max(FORMS_LIMITS.recipients);
453
+ export const formWarningSchema = z.discriminatedUnion('code', [
454
+ z.object({ code: z.literal('no_recipients') }).strict(),
455
+ z.object({ code: z.literal('captcha_not_configured') }).strict(),
456
+ z.object({ code: z.literal('untranslated'), language: formLanguageSchema, missing: z.number().int().min(1) }).strict(),
457
+ ]);
458
+ export const formSummarySchema = z
459
+ .object({
460
+ id: z.string().uuid(),
461
+ key: formKeySchema,
462
+ name: z.string().min(1).max(FORMS_LIMITS.nameChars),
463
+ status: z.enum(FORM_STATUSES),
464
+ defaultLanguage: formLanguageSchema,
465
+ publishedVersionNumber: z.number().int().min(0),
466
+ entryCount: z.number().int().min(0),
467
+ updatedAt: isoDateTimeSchema,
468
+ warnings: z.array(formWarningSchema),
469
+ })
470
+ .strict();
471
+ export const formListQuerySchema = z
472
+ .object({
473
+ status: z.enum(FORM_STATUSES).optional(),
474
+ q: z.string().trim().max(FORMS_LIMITS.nameChars).optional(),
475
+ page: z.coerce.number().int().min(1).default(1),
476
+ pageSize: z.coerce.number().int().min(1).max(100).default(20),
477
+ })
478
+ .strict();
479
+ export const formListResponseSchema = z
480
+ .object({ items: z.array(formSummarySchema), total: z.number().int().min(0) })
481
+ .strict();
482
+ export const formCreateBodySchema = z
483
+ .object({
484
+ name: z.string().trim().min(1).max(FORMS_LIMITS.nameChars),
485
+ key: formKeySchema.optional(),
486
+ defaultLanguage: formLanguageSchema,
487
+ })
488
+ .strict();
489
+ export const formDetailSchema = formSummarySchema
490
+ .extend({
491
+ definition: formDefinitionSchema,
492
+ recipients: recipientListSchema,
493
+ channelRecipients: z.record(z.string().uuid(), recipientListSchema),
494
+ retentionDays: z.number().int().min(1).max(FORMS_LIMITS.retentionDaysMax).nullable(),
495
+ revision: z.number().int().min(1),
496
+ publishedDefinition: formDefinitionSchema.nullable(),
497
+ })
498
+ .strict();
499
+ export const formUpdateBodySchema = z
500
+ .object({
501
+ expectedRevision: z.number().int().min(1),
502
+ name: z.string().trim().min(1).max(FORMS_LIMITS.nameChars).optional(),
503
+ key: formKeySchema.optional(),
504
+ defaultLanguage: formLanguageSchema.optional(),
505
+ definition: formDefinitionSchema.optional(),
506
+ })
507
+ .strict();
508
+ export const formNotificationsBodySchema = z
509
+ .object({
510
+ expectedRevision: z.number().int().min(1),
511
+ recipients: recipientListSchema,
512
+ channelRecipients: z
513
+ .record(z.string().uuid(), recipientListSchema)
514
+ .refine((r) => Object.keys(r).length <= FORMS_LIMITS.channelOverrides, {
515
+ message: `At most ${FORMS_LIMITS.channelOverrides} channel overrides`,
516
+ }),
517
+ })
518
+ .strict();
519
+ export const formRetentionBodySchema = z
520
+ .object({
521
+ expectedRevision: z.number().int().min(1),
522
+ retentionDays: z.number().int().min(1).max(FORMS_LIMITS.retentionDaysMax).nullable(),
523
+ })
524
+ .strict();
525
+ export const formRetentionImpactQuerySchema = z
526
+ .object({ days: z.coerce.number().int().min(1).max(FORMS_LIMITS.retentionDaysMax) })
527
+ .strict();
528
+ export const formRetentionImpactResponseSchema = z.object({ entriesToDelete: z.number().int().min(0) }).strict();
529
+ /** Publish, close and reopen name the revision they act on (R-26). */
530
+ export const formRevisionBodySchema = z.object({ expectedRevision: z.number().int().min(1) }).strict();
531
+ export const formDuplicateBodySchema = z
532
+ .object({ name: z.string().trim().min(1).max(FORMS_LIMITS.nameChars).optional() })
533
+ .strict();
534
+ export const formDeleteQuerySchema = z
535
+ .object({
536
+ expectedRevision: z.coerce.number().int().min(1),
537
+ confirmEntriesDeletion: z.enum(['true', 'false']).optional(),
538
+ })
539
+ .strict();
540
+ export const formVersionsResponseSchema = z
541
+ .object({
542
+ items: z.array(z
543
+ .object({
544
+ number: z.number().int().min(1),
545
+ publishedAt: isoDateTimeSchema,
546
+ publishedByAdminUserId: z.string().uuid().nullable(),
547
+ })
548
+ .strict()),
549
+ })
550
+ .strict();
551
+ export const formVersionResponseSchema = z
552
+ .object({
553
+ number: z.number().int().min(1),
554
+ definition: formDefinitionSchema,
555
+ defaultLanguage: formLanguageSchema,
556
+ publishedAt: isoDateTimeSchema,
557
+ })
558
+ .strict();
559
+ export const formPreviewQuerySchema = z
560
+ .object({
561
+ language: formLanguageSchema.optional(),
562
+ source: z.enum(['working', 'published']).default('working'),
563
+ })
564
+ .strict();
565
+ /**
566
+ * `GET …/admin/forms/languages` — the storefront languages of the active channels, which a form's
567
+ * default language must be one of at create, and the builder's translation tabs; `defaultLanguage`
568
+ * is the system-default channel's. Read with `forms:read`, so the builder needs no sales-channel
569
+ * permission of its own.
570
+ */
571
+ export const formLanguagesResponseSchema = z
572
+ .object({ languages: z.array(formLanguageSchema).min(1), defaultLanguage: formLanguageSchema })
573
+ .strict()
574
+ .refine((value) => value.languages.includes(value.defaultLanguage), {
575
+ message: 'The default language must be one of the languages',
576
+ path: ['defaultLanguage'],
577
+ });
578
+ // --- Public read (public-api.md §1) ------------------------------------------------------------
579
+ const publicErrorsSchema = z.partialRecord(z.enum(FORM_FIELD_ERROR_CODES), z.string());
580
+ /** Every input field in the public read: the definition minus the share flag, texts resolved. */
581
+ const publicInputBase = {
582
+ id: formElementIdSchema,
583
+ key: formKeySchema,
584
+ width: widthSchema,
585
+ required: z.boolean(),
586
+ visibility: visibilityRuleSchema.optional(),
587
+ label: z.string(),
588
+ placeholder: z.string().optional(),
589
+ help: z.string().optional(),
590
+ /** Operator overrides of the built-in messages, resolved for the language (R-24). */
591
+ errors: publicErrorsSchema.optional(),
592
+ };
593
+ const publicLayoutBase = {
594
+ id: formElementIdSchema,
595
+ width: widthSchema,
596
+ visibility: visibilityRuleSchema.optional(),
597
+ };
598
+ const publicOptionSchema = z.object({ id: formElementIdSchema, value: z.string(), label: z.string() }).strict();
599
+ const publicOptionsSchema = z.array(publicOptionSchema);
600
+ const publicAddressPartSchema = z.object({ enabled: z.boolean(), required: z.boolean(), label: z.string() }).strict();
601
+ export const publicFormFieldSchema = z.discriminatedUnion('type', [
602
+ z.object({ type: z.literal('text'), ...publicInputBase, ...typeSettings.text }).strict(),
603
+ z
604
+ .object({ type: z.literal('email'), ...publicInputBase, defaultValue: typeSettings.email.defaultValue })
605
+ .strict(),
606
+ z.object({ type: z.literal('phone'), ...publicInputBase, ...typeSettings.phone }).strict(),
607
+ z.object({ type: z.literal('number'), ...publicInputBase, ...typeSettings.number }).strict(),
608
+ z.object({ type: z.literal('textarea'), ...publicInputBase, ...typeSettings.textarea }).strict(),
609
+ z.object({ type: z.literal('select'), ...publicInputBase, options: publicOptionsSchema, ...typeSettings.choice }).strict(),
610
+ z.object({ type: z.literal('radio'), ...publicInputBase, options: publicOptionsSchema, ...typeSettings.choice }).strict(),
611
+ z
612
+ .object({ type: z.literal('checkboxes'), ...publicInputBase, options: publicOptionsSchema, ...typeSettings.checkboxes })
613
+ .strict(),
614
+ z.object({ type: z.literal('checkbox'), ...publicInputBase, ...typeSettings.checkbox }).strict(),
615
+ z.object({ type: z.literal('datetime'), ...publicInputBase, ...typeSettings.datetime }).strict(),
616
+ z.object({ type: z.literal('country'), ...publicInputBase, ...typeSettings.country }).strict(),
617
+ z
618
+ .object({
619
+ type: z.literal('address'),
620
+ ...publicInputBase,
621
+ parts: z
622
+ .object({
623
+ street: publicAddressPartSchema,
624
+ line2: publicAddressPartSchema,
625
+ postalCode: publicAddressPartSchema,
626
+ city: publicAddressPartSchema,
627
+ country: publicAddressPartSchema,
628
+ })
629
+ .strict(),
630
+ })
631
+ .strict(),
632
+ z.object({ type: z.literal('hidden'), ...publicInputBase, ...typeSettings.hidden }).strict(),
633
+ /** Rich text, sanitised by the renderer. */
634
+ z.object({ type: z.literal('content'), ...publicLayoutBase, content: z.string() }).strict(),
635
+ z.object({ type: z.literal('section_break'), ...publicLayoutBase, title: z.string() }).strict(),
636
+ /** `content` is the consent's rich text — what the shopper agrees to. */
637
+ z.object({ type: z.literal('privacy_consent'), ...publicInputBase, content: z.string() }).strict(),
638
+ z.object({ type: z.literal('marketing_consent'), ...publicInputBase, content: z.string() }).strict(),
639
+ z.object({ type: z.literal('terms'), ...publicInputBase, content: z.string() }).strict(),
640
+ ]);
641
+ export const publicFormSectionSchema = z
642
+ .object({
643
+ id: formElementIdSchema,
644
+ columns: z.union([z.literal(1), z.literal(2), z.literal(3)]),
645
+ visibility: visibilityRuleSchema.optional(),
646
+ title: z.string().optional(),
647
+ description: z.string().optional(),
648
+ fields: z.array(publicFormFieldSchema),
649
+ })
650
+ .strict();
651
+ export const publicFormConfirmationSchema = z.discriminatedUnion('type', [
652
+ z.object({ type: z.literal('message') }).strict(),
653
+ z.object({ type: z.literal('redirect'), url: z.string().max(FORMS_LIMITS.pageUrlChars) }).strict(),
654
+ z.object({ type: z.literal('page'), path: z.string().max(FORMS_LIMITS.pageUrlChars) }).strict(),
655
+ ]);
656
+ /**
657
+ * `formId` echoes the requested id, which need not be a UUID: a malformed id names no form and gets
658
+ * this body too (owner ruling of 2026-11-05, contracts/public-api.md §1).
659
+ */
660
+ const publicFormUnavailableSchema = z
661
+ .object({ formId: z.string().min(1), availability: z.literal('unavailable') })
662
+ .strict();
663
+ const publicFormAvailableSchema = z
664
+ .object({
665
+ formId: z.string().uuid(),
666
+ key: formKeySchema,
667
+ version: z.number().int().min(1),
668
+ language: formLanguageSchema,
669
+ availability: z.enum(['open', 'closed', 'not_yet_open', 'full']),
670
+ signedInOnly: z.boolean(),
671
+ /** Only when the version requires CAPTCHA **and** a provider is configured (R-14). */
672
+ captcha: z
673
+ .object({ provider: z.enum(['turnstile', 'hcaptcha']), siteKey: z.string().min(1) })
674
+ .strict()
675
+ .nullable(),
676
+ texts: z
677
+ .object({
678
+ title: z.string().optional(),
679
+ description: z.string().optional(),
680
+ submitLabel: z.string().optional(),
681
+ closed: z.string().optional(),
682
+ notYetOpen: z.string().optional(),
683
+ full: z.string().optional(),
684
+ signIn: z.string().optional(),
685
+ success: z.string().optional(),
686
+ })
687
+ .strict(),
688
+ sections: z.array(publicFormSectionSchema),
689
+ confirmation: publicFormConfirmationSchema,
690
+ })
691
+ .strict();
692
+ /** Always a `200`: draft, deleted, never-existing and malformed ids are all `unavailable` (R-11). */
693
+ export const publicFormDefinitionSchema = z.union([publicFormUnavailableSchema, publicFormAvailableSchema]);
694
+ /** `GET …/admin/forms/:id/preview` — the public read of the chosen copy, plus the form's status. */
695
+ export const formPreviewResponseSchema = z.union([
696
+ publicFormUnavailableSchema.extend({ status: z.enum(FORM_STATUSES) }).strict(),
697
+ publicFormAvailableSchema.extend({ status: z.enum(FORM_STATUSES) }).strict(),
698
+ ]);
699
+ export const publicFormQuerySchema = z.object({ language: formLanguageSchema.optional() }).strict();
700
+ // --- Public submit (public-api.md §2) ----------------------------------------------------------
701
+ /**
702
+ * The raw posted values, by field key and `<key>.<part>` for address parts. **No attribution
703
+ * field**: the server stamps account and organisation from the session (FR-045).
704
+ */
705
+ export const formSubmitBodySchema = z
706
+ .object({
707
+ values: z.record(z.string().max(200), z.union([z.string(), z.array(z.string()).max(FORMS_LIMITS.optionsPerChoice)])),
708
+ pageUrl: z
709
+ .string()
710
+ .max(FORMS_LIMITS.pageUrlChars)
711
+ .regex(/^\/(?!\/)/, 'A same-origin path')
712
+ .optional(),
713
+ hp: z.string().max(FORMS_LIMITS.singleLineChars).optional(),
714
+ captchaToken: z.string().max(4096).optional(),
715
+ })
716
+ .strict();
717
+ export const formSubmitConfirmationSchema = z.discriminatedUnion('type', [
718
+ z.object({ type: z.literal('message'), message: z.string() }).strict(),
719
+ z.object({ type: z.literal('redirect'), url: z.string() }).strict(),
720
+ z.object({ type: z.literal('page'), path: z.string() }).strict(),
721
+ ]);
722
+ export const formSubmitResponseSchema = z
723
+ .object({ status: z.literal('accepted'), confirmation: formSubmitConfirmationSchema })
724
+ .strict();
725
+ /** `details` of `400 FORM_SUBMISSION_INVALID`: one message per field, in the submission language. */
726
+ export const formSubmissionInvalidDetailsSchema = z
727
+ .object({
728
+ fields: z.array(z.object({ fieldKey: z.string(), code: z.enum(FORM_FIELD_ERROR_CODES), message: z.string() }).strict()),
729
+ })
730
+ .strict();
731
+ // --- Admin API: entries (admin-api.md §2) --------------------------------------------------------
732
+ const statusListSchema = z.preprocess((value) => (typeof value === 'string' ? [value] : value), z.array(z.enum(FORM_ENTRY_STATUSES)).max(FORM_ENTRY_STATUSES.length));
733
+ const entryFilterShape = {
734
+ formId: z.string().uuid().optional(),
735
+ status: statusListSchema.optional(),
736
+ submittedFrom: isoDateTimeSchema.optional(),
737
+ submittedTo: isoDateTimeSchema.optional(),
738
+ salesChannelId: z.string().uuid().optional(),
739
+ q: z.string().trim().max(FORMS_LIMITS.nameChars).optional(),
740
+ };
741
+ export const formEntryListQuerySchema = z
742
+ .object({
743
+ ...entryFilterShape,
744
+ cursor: z.string().max(512).optional(),
745
+ limit: z.coerce.number().int().min(1).max(100).default(50),
746
+ })
747
+ .strict();
748
+ /** The export's columns are per form, so the form is required (R-18). */
749
+ export const formEntryExportQuerySchema = z
750
+ .object({ ...entryFilterShape, formId: z.string().uuid() })
751
+ .strict();
752
+ export const formEntrySummarySchema = z
753
+ .object({
754
+ id: z.string().uuid(),
755
+ formId: z.string().uuid(),
756
+ formName: z.string(),
757
+ formVersion: z.number().int().min(1),
758
+ status: z.enum(FORM_ENTRY_STATUSES),
759
+ salesChannelId: z.string().uuid(),
760
+ language: formLanguageSchema,
761
+ submittedAt: isoDateTimeSchema,
762
+ submitterEmail: z.string().nullable(),
763
+ attributed: z.boolean(),
764
+ })
765
+ .strict();
766
+ export const formEntryListResponseSchema = z
767
+ .object({ items: z.array(formEntrySummarySchema), nextCursor: z.string().nullable() })
768
+ .strict();
769
+ export const formEntryNoteSchema = z
770
+ .object({
771
+ id: z.string().uuid(),
772
+ body: z.string(),
773
+ authorAdminUserId: z.string().uuid().nullable(),
774
+ createdAt: isoDateTimeSchema,
775
+ })
776
+ .strict();
777
+ export const formEntryDetailSchema = formEntrySummarySchema
778
+ .extend({
779
+ pageUrl: z.string().nullable(),
780
+ /** In the version's order with the version's labels; a field removed later is still listed. */
781
+ answers: z.array(z
782
+ .object({ fieldKey: z.string(), label: z.string(), type: z.enum(FORM_FIELD_TYPES), value: answerValueSchema })
783
+ .strict()),
784
+ consents: z.array(formConsentRecordSchema),
785
+ customerAccountId: z.string().uuid().nullable(),
786
+ organizationId: z.string().uuid().nullable(),
787
+ notes: z.array(formEntryNoteSchema),
788
+ })
789
+ .strict();
790
+ export const formEntryStatusBodySchema = z
791
+ .object({ status: z.enum(FORM_ENTRY_STATUSES), expectedStatus: z.enum(FORM_ENTRY_STATUSES) })
792
+ .strict();
793
+ export const formEntryNoteBodySchema = z
794
+ .object({ body: z.string().trim().min(1).max(FORMS_LIMITS.noteChars) })
795
+ .strict();
796
+ export const formEntriesDeleteBodySchema = z
797
+ .object({ ids: z.array(z.string().uuid()).min(1).max(FORMS_LIMITS.bulkDeleteMax) })
798
+ .strict();
799
+ export const formEntriesDeleteResponseSchema = z.object({ deleted: z.number().int().min(0) }).strict();
800
+ // --- Events (events-and-webhook.md §1–§2) --------------------------------------------------------
801
+ /** The domain event and webhook payload of an accepted entry. Never notes, recipients or consent texts. */
802
+ export const FormEntrySubmittedEventV1Schema = z
803
+ .object({
804
+ eventId: z.string().min(1),
805
+ occurredAt: isoDateTimeSchema,
806
+ eventType: z.literal(FORMS_EVENTS.ENTRY_SUBMITTED),
807
+ entryId: z.string().uuid(),
808
+ formId: z.string().uuid(),
809
+ formKey: formKeySchema,
810
+ formVersion: z.number().int().min(1),
811
+ salesChannelId: z.string().uuid(),
812
+ organizationId: z.string().uuid().nullable(),
813
+ language: z.string().min(2).max(16),
814
+ pageUrl: z.string().max(FORMS_LIMITS.pageUrlChars).nullable(),
815
+ submittedAt: isoDateTimeSchema,
816
+ /** Visible answers of fields this version marks "Share with integrations"; `{}` when none. */
817
+ answers: z.record(formKeySchema, answerValueSchema),
818
+ })
819
+ .strict();
820
+ /** Internal: what the public read answers changed (publish, close, reopen, delete). */
821
+ export const FormChangedEventSchema = z
822
+ .object({ eventId: z.string().min(1), occurredAt: isoDateTimeSchema, formId: z.string().uuid() })
823
+ .strict();
824
+ export const FORMS_WEBHOOK_EVENT_SCHEMAS = {
825
+ [FORMS_EVENTS.ENTRY_SUBMITTED]: FormEntrySubmittedEventV1Schema,
826
+ };
827
+ //# sourceMappingURL=forms.js.map