@businessdash/sdk 0.9.60

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 (268) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +899 -0
  3. package/dist/adapters-revalidate.d.ts +44 -0
  4. package/dist/adapters-revalidate.d.ts.map +1 -0
  5. package/dist/adapters-revalidate.js +68 -0
  6. package/dist/adapters-revalidate.js.map +1 -0
  7. package/dist/alpha.d.ts +21 -0
  8. package/dist/alpha.d.ts.map +1 -0
  9. package/dist/alpha.js +21 -0
  10. package/dist/alpha.js.map +1 -0
  11. package/dist/analytics-core.d.ts +34 -0
  12. package/dist/analytics-core.d.ts.map +1 -0
  13. package/dist/analytics-core.js +138 -0
  14. package/dist/analytics-core.js.map +1 -0
  15. package/dist/analytics-server.d.ts +54 -0
  16. package/dist/analytics-server.d.ts.map +1 -0
  17. package/dist/analytics-server.js +78 -0
  18. package/dist/analytics-server.js.map +1 -0
  19. package/dist/attribution-logo.d.ts +2 -0
  20. package/dist/attribution-logo.d.ts.map +1 -0
  21. package/dist/attribution-logo.js +5 -0
  22. package/dist/attribution-logo.js.map +1 -0
  23. package/dist/auth-handler.d.ts +92 -0
  24. package/dist/auth-handler.d.ts.map +1 -0
  25. package/dist/auth-handler.js +277 -0
  26. package/dist/auth-handler.js.map +1 -0
  27. package/dist/biab-forms.css +484 -0
  28. package/dist/cli.d.ts +46 -0
  29. package/dist/cli.d.ts.map +1 -0
  30. package/dist/cli.js +1824 -0
  31. package/dist/cli.js.map +1 -0
  32. package/dist/client.d.ts +1681 -0
  33. package/dist/client.d.ts.map +1 -0
  34. package/dist/client.js +2845 -0
  35. package/dist/client.js.map +1 -0
  36. package/dist/collections.d.ts +13 -0
  37. package/dist/collections.d.ts.map +1 -0
  38. package/dist/collections.js +13 -0
  39. package/dist/collections.js.map +1 -0
  40. package/dist/contracts.d.ts +14609 -0
  41. package/dist/contracts.d.ts.map +1 -0
  42. package/dist/contracts.js +2428 -0
  43. package/dist/contracts.js.map +1 -0
  44. package/dist/data-model-schema.d.ts +962 -0
  45. package/dist/data-model-schema.d.ts.map +1 -0
  46. package/dist/data-model-schema.js +2295 -0
  47. package/dist/data-model-schema.js.map +1 -0
  48. package/dist/distribution.d.ts +38 -0
  49. package/dist/distribution.d.ts.map +1 -0
  50. package/dist/distribution.js +61 -0
  51. package/dist/distribution.js.map +1 -0
  52. package/dist/element.d.ts +121 -0
  53. package/dist/element.d.ts.map +1 -0
  54. package/dist/element.js +276 -0
  55. package/dist/element.js.map +1 -0
  56. package/dist/enums.d.ts +25 -0
  57. package/dist/enums.d.ts.map +1 -0
  58. package/dist/enums.js +38 -0
  59. package/dist/enums.js.map +1 -0
  60. package/dist/errors.d.ts +195 -0
  61. package/dist/errors.d.ts.map +1 -0
  62. package/dist/errors.js +188 -0
  63. package/dist/errors.js.map +1 -0
  64. package/dist/forms-core/autocomplete.d.ts +37 -0
  65. package/dist/forms-core/autocomplete.d.ts.map +1 -0
  66. package/dist/forms-core/autocomplete.js +82 -0
  67. package/dist/forms-core/autocomplete.js.map +1 -0
  68. package/dist/forms-core/business-function.d.ts +61 -0
  69. package/dist/forms-core/business-function.d.ts.map +1 -0
  70. package/dist/forms-core/business-function.js +149 -0
  71. package/dist/forms-core/business-function.js.map +1 -0
  72. package/dist/forms-core/calculation.d.ts +72 -0
  73. package/dist/forms-core/calculation.d.ts.map +1 -0
  74. package/dist/forms-core/calculation.js +103 -0
  75. package/dist/forms-core/calculation.js.map +1 -0
  76. package/dist/forms-core/controller.d.ts +249 -0
  77. package/dist/forms-core/controller.d.ts.map +1 -0
  78. package/dist/forms-core/controller.js +590 -0
  79. package/dist/forms-core/controller.js.map +1 -0
  80. package/dist/forms-core/elements.d.ts +44 -0
  81. package/dist/forms-core/elements.d.ts.map +1 -0
  82. package/dist/forms-core/elements.js +68 -0
  83. package/dist/forms-core/elements.js.map +1 -0
  84. package/dist/forms-core/email-domains.d.ts +10 -0
  85. package/dist/forms-core/email-domains.d.ts.map +1 -0
  86. package/dist/forms-core/email-domains.js +69 -0
  87. package/dist/forms-core/email-domains.js.map +1 -0
  88. package/dist/forms-core/file-rules.d.ts +51 -0
  89. package/dist/forms-core/file-rules.d.ts.map +1 -0
  90. package/dist/forms-core/file-rules.js +105 -0
  91. package/dist/forms-core/file-rules.js.map +1 -0
  92. package/dist/forms-core/formula.d.ts +114 -0
  93. package/dist/forms-core/formula.d.ts.map +1 -0
  94. package/dist/forms-core/formula.js +1170 -0
  95. package/dist/forms-core/formula.js.map +1 -0
  96. package/dist/forms-core/index.d.ts +24 -0
  97. package/dist/forms-core/index.d.ts.map +1 -0
  98. package/dist/forms-core/index.js +28 -0
  99. package/dist/forms-core/index.js.map +1 -0
  100. package/dist/forms-core/units.d.ts +49 -0
  101. package/dist/forms-core/units.d.ts.map +1 -0
  102. package/dist/forms-core/units.js +255 -0
  103. package/dist/forms-core/units.js.map +1 -0
  104. package/dist/forms-core/us-states.d.ts +14 -0
  105. package/dist/forms-core/us-states.d.ts.map +1 -0
  106. package/dist/forms-core/us-states.js +66 -0
  107. package/dist/forms-core/us-states.js.map +1 -0
  108. package/dist/forms-core/validation.d.ts +266 -0
  109. package/dist/forms-core/validation.d.ts.map +1 -0
  110. package/dist/forms-core/validation.js +850 -0
  111. package/dist/forms-core/validation.js.map +1 -0
  112. package/dist/forms.d.ts +19 -0
  113. package/dist/forms.d.ts.map +1 -0
  114. package/dist/forms.js +29 -0
  115. package/dist/forms.js.map +1 -0
  116. package/dist/gallery-types.d.ts +32 -0
  117. package/dist/gallery-types.d.ts.map +1 -0
  118. package/dist/gallery-types.js +2 -0
  119. package/dist/gallery-types.js.map +1 -0
  120. package/dist/graphql.d.ts +97 -0
  121. package/dist/graphql.d.ts.map +1 -0
  122. package/dist/graphql.js +212 -0
  123. package/dist/graphql.js.map +1 -0
  124. package/dist/index.cjs +19448 -0
  125. package/dist/index.d.cts +19 -0
  126. package/dist/index.d.mts +19 -0
  127. package/dist/index.d.ts +19 -0
  128. package/dist/index.d.ts.map +1 -0
  129. package/dist/index.js +20 -0
  130. package/dist/index.js.map +1 -0
  131. package/dist/marketing-schema.d.ts +216 -0
  132. package/dist/marketing-schema.d.ts.map +1 -0
  133. package/dist/marketing-schema.js +200 -0
  134. package/dist/marketing-schema.js.map +1 -0
  135. package/dist/mcp.d.ts +42 -0
  136. package/dist/mcp.d.ts.map +1 -0
  137. package/dist/mcp.js +87 -0
  138. package/dist/mcp.js.map +1 -0
  139. package/dist/native.d.ts +45 -0
  140. package/dist/native.d.ts.map +1 -0
  141. package/dist/native.js +43 -0
  142. package/dist/native.js.map +1 -0
  143. package/dist/next-revalidate.d.ts +43 -0
  144. package/dist/next-revalidate.d.ts.map +1 -0
  145. package/dist/next-revalidate.js +84 -0
  146. package/dist/next-revalidate.js.map +1 -0
  147. package/dist/parallel-pages.d.ts +102 -0
  148. package/dist/parallel-pages.d.ts.map +1 -0
  149. package/dist/parallel-pages.js +108 -0
  150. package/dist/parallel-pages.js.map +1 -0
  151. package/dist/payment-icons.d.ts +66 -0
  152. package/dist/payment-icons.d.ts.map +1 -0
  153. package/dist/payment-icons.js +160 -0
  154. package/dist/payment-icons.js.map +1 -0
  155. package/dist/proxy.d.ts +67 -0
  156. package/dist/proxy.d.ts.map +1 -0
  157. package/dist/proxy.js +97 -0
  158. package/dist/proxy.js.map +1 -0
  159. package/dist/react-analytics.d.ts +39 -0
  160. package/dist/react-analytics.d.ts.map +1 -0
  161. package/dist/react-analytics.js +59 -0
  162. package/dist/react-analytics.js.map +1 -0
  163. package/dist/react-attribution.d.ts +99 -0
  164. package/dist/react-attribution.d.ts.map +1 -0
  165. package/dist/react-attribution.js +52 -0
  166. package/dist/react-attribution.js.map +1 -0
  167. package/dist/react-marketing.d.ts +181 -0
  168. package/dist/react-marketing.d.ts.map +1 -0
  169. package/dist/react-marketing.js +215 -0
  170. package/dist/react-marketing.js.map +1 -0
  171. package/dist/react.d.ts +727 -0
  172. package/dist/react.d.ts.map +1 -0
  173. package/dist/react.js +2418 -0
  174. package/dist/react.js.map +1 -0
  175. package/dist/reserved-paths.d.ts +24 -0
  176. package/dist/reserved-paths.d.ts.map +1 -0
  177. package/dist/reserved-paths.js +60 -0
  178. package/dist/reserved-paths.js.map +1 -0
  179. package/dist/revalidate-verify.d.ts +30 -0
  180. package/dist/revalidate-verify.d.ts.map +1 -0
  181. package/dist/revalidate-verify.js +74 -0
  182. package/dist/revalidate-verify.js.map +1 -0
  183. package/dist/sdk.d.ts +678 -0
  184. package/dist/sdk.d.ts.map +1 -0
  185. package/dist/sdk.js +801 -0
  186. package/dist/sdk.js.map +1 -0
  187. package/dist/seo.d.ts +218 -0
  188. package/dist/seo.d.ts.map +1 -0
  189. package/dist/seo.js +309 -0
  190. package/dist/seo.js.map +1 -0
  191. package/dist/socials.d.ts +47 -0
  192. package/dist/socials.d.ts.map +1 -0
  193. package/dist/socials.js +172 -0
  194. package/dist/socials.js.map +1 -0
  195. package/dist/static.d.ts +14 -0
  196. package/dist/static.d.ts.map +1 -0
  197. package/dist/static.js +14 -0
  198. package/dist/static.js.map +1 -0
  199. package/dist/url-pattern.d.ts +47 -0
  200. package/dist/url-pattern.d.ts.map +1 -0
  201. package/dist/url-pattern.js +124 -0
  202. package/dist/url-pattern.js.map +1 -0
  203. package/dist/vanilla.d.ts +77 -0
  204. package/dist/vanilla.d.ts.map +1 -0
  205. package/dist/vanilla.js +903 -0
  206. package/dist/vanilla.js.map +1 -0
  207. package/openapi.json +13779 -0
  208. package/package.json +204 -0
  209. package/src/adapters-revalidate.ts +88 -0
  210. package/src/alpha.ts +89 -0
  211. package/src/analytics-core.ts +175 -0
  212. package/src/analytics-server.ts +99 -0
  213. package/src/angular/biab-form.component.ts +1443 -0
  214. package/src/angular/index.ts +26 -0
  215. package/src/attribution-logo.ts +5 -0
  216. package/src/auth-handler.ts +352 -0
  217. package/src/cli.ts +2517 -0
  218. package/src/client.ts +3578 -0
  219. package/src/collections.ts +101 -0
  220. package/src/contracts.ts +3390 -0
  221. package/src/data-model-schema.ts +4042 -0
  222. package/src/distribution.ts +73 -0
  223. package/src/element.ts +321 -0
  224. package/src/enums.ts +65 -0
  225. package/src/errors.ts +338 -0
  226. package/src/forms-core/autocomplete.ts +97 -0
  227. package/src/forms-core/business-function.ts +209 -0
  228. package/src/forms-core/calculation.ts +167 -0
  229. package/src/forms-core/controller.ts +922 -0
  230. package/src/forms-core/elements.ts +86 -0
  231. package/src/forms-core/email-domains.ts +68 -0
  232. package/src/forms-core/file-rules.ts +123 -0
  233. package/src/forms-core/formula.ts +1339 -0
  234. package/src/forms-core/index.ts +122 -0
  235. package/src/forms-core/units.ts +308 -0
  236. package/src/forms-core/us-states.ts +68 -0
  237. package/src/forms-core/validation.ts +1037 -0
  238. package/src/forms.ts +63 -0
  239. package/src/gallery-types.ts +31 -0
  240. package/src/graphql.ts +295 -0
  241. package/src/index.ts +505 -0
  242. package/src/marketing-schema.ts +395 -0
  243. package/src/mcp.ts +108 -0
  244. package/src/native.ts +73 -0
  245. package/src/next-revalidate.ts +124 -0
  246. package/src/parallel-pages.ts +192 -0
  247. package/src/payment-icons.ts +205 -0
  248. package/src/proxy.ts +173 -0
  249. package/src/qwik.tsx +1234 -0
  250. package/src/react-analytics.tsx +76 -0
  251. package/src/react-attribution.tsx +192 -0
  252. package/src/react-marketing.tsx +338 -0
  253. package/src/react.tsx +5495 -0
  254. package/src/reserved-paths.ts +65 -0
  255. package/src/revalidate-verify.ts +98 -0
  256. package/src/sdk.ts +1671 -0
  257. package/src/seo.ts +488 -0
  258. package/src/socials.ts +230 -0
  259. package/src/solid.tsx +1466 -0
  260. package/src/static.ts +21 -0
  261. package/src/styles/biab-forms.css +484 -0
  262. package/src/svelte/BiabForm.svelte +1069 -0
  263. package/src/svelte/context.ts +57 -0
  264. package/src/svelte/index.ts +79 -0
  265. package/src/url-pattern.ts +153 -0
  266. package/src/vanilla.ts +1290 -0
  267. package/src/vue/BiabForm.vue +1538 -0
  268. package/src/vue/index.ts +119 -0
@@ -0,0 +1,850 @@
1
+ /**
2
+ * Framework-agnostic, isomorphic form validation + condition evaluation.
3
+ *
4
+ * Zero UI deps, zero React, zero DOM. This is the single source of truth every
5
+ * `<BiabForm>` binding (React / Vue / Svelte / Solid / Qwik / Angular / Element /
6
+ * vanilla) shares. It is a faithful port of three existing BIAB modules so the
7
+ * client never disagrees with the server:
8
+ *
9
+ * - `src/server/forms/validate.ts` — isEmpty / validateValue /
10
+ * evalCondition / findMissingRequired
11
+ * - `src/app/.../builder/FormPreview.tsx` — seedInitialData / concurrentRevealCount /
12
+ * the or_condition + condition_block walk
13
+ * - `biab-dev/src/sdk.ts` validateFormSubmission — the wire-level submission check
14
+ *
15
+ * The schema published by `client.forms.schema(slug)` carries the FULL nested
16
+ * field tree (layout nodes, `condition_block`, `or_condition`, `input_group`,
17
+ * `flex_row` with `children`, plus the resolved output `key` on each
18
+ * value-bearing field). These helpers walk that tree, NOT the flattened
19
+ * `FormFieldDef[]` view.
20
+ */
21
+ import { getEmailDomain, isConsumerEmailDomain } from "./email-domains.js";
22
+ import { baseUnitFor, isMeasurementCategory, isUnitInCategory, unitsForCategory, } from "./units.js";
23
+ import { isValidUsZip } from "./us-states.js";
24
+ // ─────────────────────────────────────────────────────────────────────────────
25
+ // Shared constants — kept in sync with validate.ts / FormPreview / output-keys.
26
+ // ─────────────────────────────────────────────────────────────────────────────
27
+ /** Local part @ domain . TLD (TLD ≥ 2 chars). Mirrors validate.ts EMAIL_RE. */
28
+ const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
29
+ /** An icon name: lowercase kebab-case slug. Mirrors validate.ts ICON_NAME_RE. */
30
+ const ICON_NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
31
+ /** Valid web address. Mirrors validate.ts URL_RE. */
32
+ const URL_RE = /^(https?:\/\/)?([a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}(?::\d{1,5})?(?:[/?#]\S*)?$/i;
33
+ /** A hex color: #rgb or #rrggbb. Mirrors validate.ts HEX_COLOR_RE. */
34
+ const HEX_COLOR_RE = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
35
+ const MAX_STRING_LEN = 50_000;
36
+ const MAX_ARRAY_LEN = 500;
37
+ const MAX_PHONE_LEN = 64;
38
+ const MAX_DATE_LEN = 64;
39
+ const MAX_ADDRESS_FIELD_LEN = 512;
40
+ const MAX_FILE_FIELD_LEN = 4096;
41
+ /**
42
+ * Pure layout / static / grouping types that never carry a submitted value.
43
+ * Mirrors `STATIC_OR_LAYOUT` in validate.ts + FormPreview (note: numeric
44
+ * "stepper" IS value-bearing, so it stays in this skip-set for the tree walk
45
+ * but is still validated when it carries a value).
46
+ */
47
+ const STATIC_OR_LAYOUT = new Set([
48
+ "title",
49
+ "subtitle",
50
+ "separator",
51
+ "flex_row",
52
+ "input_group",
53
+ "condition_block",
54
+ "or_condition",
55
+ "image",
56
+ "richtext",
57
+ "body_text",
58
+ "bullet_list",
59
+ "table",
60
+ "stepper",
61
+ // `calculation` is computed server-side, never user-input → skip validation.
62
+ "calculation",
63
+ ]);
64
+ /** Containers whose own id never holds a value (their children do). */
65
+ const STEP_CONTAINERS = new Set([
66
+ "input_group",
67
+ "condition_block",
68
+ "or_condition",
69
+ ]);
70
+ /** Static elements that carry no value AND get no seeded default. */
71
+ const NO_SEED_STATIC = new Set([
72
+ "title",
73
+ "subtitle",
74
+ "separator",
75
+ "image",
76
+ "richtext",
77
+ "body_text",
78
+ "bullet_list",
79
+ "table",
80
+ // computed on submit — never seeded with a user default.
81
+ "calculation",
82
+ ]);
83
+ // ─────────────────────────────────────────────────────────────────────────────
84
+ // isEmpty — per-type "is this answered?" rule. Mirrors validate.ts isEmpty.
85
+ // ─────────────────────────────────────────────────────────────────────────────
86
+ /** True when a field's value should be treated as missing for required checks. */
87
+ export function isEmpty(field, value) {
88
+ switch (field.type) {
89
+ case "checkbox":
90
+ case "tags":
91
+ return !Array.isArray(value) || value.length === 0;
92
+ case "multi_populator":
93
+ return (!Array.isArray(value) ||
94
+ !value.some((inst) => inst != null &&
95
+ typeof inst === "object" &&
96
+ Object.values(inst).some((v) => !(v === undefined ||
97
+ v === null ||
98
+ v === "" ||
99
+ (Array.isArray(v) && v.length === 0)))));
100
+ case "measurement": {
101
+ const mv = value;
102
+ return !mv || typeof mv.value !== "number";
103
+ }
104
+ case "url": {
105
+ const v = value;
106
+ return !v || typeof v.url !== "string" || v.url === "";
107
+ }
108
+ case "choice_cards":
109
+ return field.choiceConfig?.mode === "multi"
110
+ ? !Array.isArray(value) || value.length === 0
111
+ : typeof value !== "string" || value === "";
112
+ case "boolean":
113
+ // mustBeTrue (consent) → empty unless exactly `true`; otherwise answered
114
+ // by either choice (an optional yes/no can stay "no" and still submit).
115
+ return field.mustBeTrue ? value !== true : typeof value !== "boolean";
116
+ case "file_upload":
117
+ return !Array.isArray(value) || value.length === 0;
118
+ case "schedule": {
119
+ const s = (value ?? {});
120
+ return !((typeof s.slotStartAt === "string" && s.slotStartAt.length > 0) ||
121
+ s.asap === true ||
122
+ (Array.isArray(s.days) && s.days.length > 0) ||
123
+ (Array.isArray(s.times) && s.times.length > 0));
124
+ }
125
+ case "date_range": {
126
+ const v = value;
127
+ return !v?.start || !v.end;
128
+ }
129
+ case "address": {
130
+ const v = value;
131
+ return !v?.line1 || !v.city || !v.state || !v.zip;
132
+ }
133
+ case "time_picker": {
134
+ const mode = field.timeConfig?.mode ?? "simple";
135
+ if (mode === "time_block") {
136
+ const v = value;
137
+ return !v?.start || !v.end;
138
+ }
139
+ if (mode === "appointment") {
140
+ const v = value;
141
+ return !v?.date || !v.time;
142
+ }
143
+ return value === undefined || value === null || value === "";
144
+ }
145
+ case "star_rating":
146
+ case "happiness_rating":
147
+ return typeof value !== "number" || value <= 0;
148
+ default:
149
+ return value === undefined || value === null || value === "";
150
+ }
151
+ }
152
+ // ─────────────────────────────────────────────────────────────────────────────
153
+ // validateValue — per-value type / constraint check. Mirrors validate.ts.
154
+ // Returns an error reason string, or null when the value conforms. Empty values
155
+ // pass here (required-ness is checked separately).
156
+ // ─────────────────────────────────────────────────────────────────────────────
157
+ function regexFail(field, value) {
158
+ const pattern = field.regexPattern;
159
+ if (!pattern)
160
+ return null;
161
+ try {
162
+ if (!new RegExp(pattern).test(value))
163
+ return "regex";
164
+ }
165
+ catch {
166
+ // A broken stored pattern shouldn't block a submission.
167
+ }
168
+ return null;
169
+ }
170
+ function isPlainObject(v) {
171
+ return typeof v === "object" && v !== null && !Array.isArray(v);
172
+ }
173
+ /** True when every leaf is a bounded primitive (no nesting). */
174
+ function onlyBoundedPrimitives(obj, maxLen) {
175
+ for (const v of Object.values(obj)) {
176
+ if (v == null)
177
+ continue;
178
+ if (typeof v === "string") {
179
+ if (v.length > maxLen)
180
+ return false;
181
+ continue;
182
+ }
183
+ if (typeof v === "number" || typeof v === "boolean")
184
+ continue;
185
+ return false;
186
+ }
187
+ return true;
188
+ }
189
+ /**
190
+ * Validate one value against its field definition. Returns an error reason
191
+ * (`"type"`, `"format"`, `"min"`, `"max"`, `"options"`, `"regex"`), or null when
192
+ * the value conforms. Lenient where the renderer's output is ambiguous (numeric
193
+ * fields accept numeric strings) so legitimate live submissions never break.
194
+ * Faithful port of `validateValue` in src/server/forms/validate.ts.
195
+ */
196
+ export function validateValue(field, value) {
197
+ if (value === undefined || value === null || value === "")
198
+ return null;
199
+ const opts = Array.isArray(field.options) ? field.options : null;
200
+ switch (field.type) {
201
+ case "email": {
202
+ if (typeof value !== "string")
203
+ return "type";
204
+ if (value.length > MAX_STRING_LEN)
205
+ return "max";
206
+ if (!EMAIL_RE.test(value))
207
+ return "format";
208
+ if (field.emailConfig
209
+ ?.businessOnly &&
210
+ isConsumerEmailDomain(getEmailDomain(value) ?? "")) {
211
+ return "business_email";
212
+ }
213
+ return null;
214
+ }
215
+ case "url": {
216
+ // Value object: { url, verified } (verified is stamped server-side).
217
+ if (!isPlainObject(value))
218
+ return "type";
219
+ const u = value["url"];
220
+ if (u === undefined || u === null || u === "")
221
+ return null;
222
+ if (typeof u !== "string")
223
+ return "type";
224
+ if (u.length > MAX_STRING_LEN)
225
+ return "max";
226
+ if (!URL_RE.test(u.trim()))
227
+ return "format";
228
+ const verified = value["verified"];
229
+ if (verified !== undefined &&
230
+ verified !== "unverified" &&
231
+ verified !== "safe" &&
232
+ verified !== "unsafe") {
233
+ return "options";
234
+ }
235
+ return onlyBoundedPrimitives(value, MAX_STRING_LEN) ? null : "type";
236
+ }
237
+ case "phone": {
238
+ if (typeof value !== "string")
239
+ return "type";
240
+ if (value.length > MAX_PHONE_LEN)
241
+ return "max";
242
+ const rx = regexFail(field, value);
243
+ if (rx)
244
+ return rx;
245
+ const digits = value.replace(/\D/g, "");
246
+ if (field.phoneConfig?.international === true) {
247
+ return digits.length >= 7 && digits.length <= 15 ? null : "format";
248
+ }
249
+ const national = digits.length === 11 && digits.startsWith("1")
250
+ ? digits.slice(1)
251
+ : digits;
252
+ return national.length === 10 ? null : "format";
253
+ }
254
+ case "number":
255
+ case "slider":
256
+ case "stepper": {
257
+ const n = typeof value === "number"
258
+ ? value
259
+ : typeof value === "string" &&
260
+ value.trim() !== "" &&
261
+ !Number.isNaN(Number(value))
262
+ ? Number(value)
263
+ : Number.NaN;
264
+ if (Number.isNaN(n))
265
+ return "type";
266
+ if (field.type === "number" &&
267
+ field.allowDecimal === false &&
268
+ !Number.isInteger(n))
269
+ return "format";
270
+ // number "allow negative" off → enforce >= 0.
271
+ if (field.type === "number" &&
272
+ field.allowNegative === false &&
273
+ n < 0)
274
+ return "min";
275
+ const min = field.validation?.min ?? field.sliderConfig?.min;
276
+ const max = field.validation?.max ?? field.sliderConfig?.max;
277
+ if (typeof min === "number" && n < min)
278
+ return "min";
279
+ if (typeof max === "number" && n > max)
280
+ return "max";
281
+ return null;
282
+ }
283
+ case "star_rating":
284
+ case "happiness_rating": {
285
+ if (typeof value !== "number")
286
+ return "type";
287
+ const maxStars = field.starRatingConfig?.maxStars ?? 5;
288
+ if (value < 0 || value > maxStars + 0.0001)
289
+ return "max";
290
+ return null;
291
+ }
292
+ case "boolean":
293
+ return typeof value === "boolean" ? null : "type";
294
+ case "select":
295
+ case "radio":
296
+ if (typeof value !== "string")
297
+ return "type";
298
+ if (value.length > MAX_STRING_LEN)
299
+ return "max";
300
+ if (opts && !field.allowCustom && !opts.includes(value))
301
+ return "options";
302
+ return null;
303
+ case "color_picker":
304
+ // A color is a hex value — presets and the "Other" custom picker both
305
+ // emit one, so validate the format rather than options membership.
306
+ if (typeof value !== "string")
307
+ return "type";
308
+ if (value !== "" && !HEX_COLOR_RE.test(value))
309
+ return "format";
310
+ return null;
311
+ case "icon_select": {
312
+ // An icon NAME (kebab-case slug), e.g. "cloud-sun". Checked as a slug
313
+ // rather than against a pinned icon manifest, matching the server —
314
+ // the set can grow without either side needing a release.
315
+ if (typeof value !== "string")
316
+ return "type";
317
+ if (value === "")
318
+ return null;
319
+ if (value.length > 64)
320
+ return "max";
321
+ if (!ICON_NAME_RE.test(value))
322
+ return "format";
323
+ const allowed = field
324
+ .iconConfig?.allowedIcons;
325
+ if (allowed && allowed.length > 0 && !allowed.includes(value)) {
326
+ return "options";
327
+ }
328
+ return null;
329
+ }
330
+ case "image_input":
331
+ // One image URL, whether uploaded or pasted. A plain string — unlike
332
+ // `url`, which carries a { url, verified } object.
333
+ if (typeof value !== "string")
334
+ return "type";
335
+ if (value === "")
336
+ return null;
337
+ if (value.length > MAX_STRING_LEN)
338
+ return "max";
339
+ if (!URL_RE.test(value.trim()))
340
+ return "format";
341
+ return null;
342
+ case "tags": {
343
+ // Free-text tag array — string items, no fixed options list.
344
+ if (!Array.isArray(value))
345
+ return "type";
346
+ if (value.length > MAX_ARRAY_LEN)
347
+ return "max";
348
+ for (const v of value) {
349
+ if (typeof v !== "string")
350
+ return "type";
351
+ if (v.length > MAX_STRING_LEN)
352
+ return "max";
353
+ }
354
+ return null;
355
+ }
356
+ case "checkbox": {
357
+ if (!Array.isArray(value))
358
+ return "type";
359
+ if (value.length > MAX_ARRAY_LEN)
360
+ return "max";
361
+ for (const v of value) {
362
+ if (typeof v !== "string")
363
+ return "type";
364
+ if (opts && !field.allowCustom && !opts.includes(v))
365
+ return "options";
366
+ }
367
+ return null;
368
+ }
369
+ case "currency": {
370
+ if (typeof value !== "number" || Number.isNaN(value))
371
+ return "type";
372
+ if (field.currencyConfig?.allowNegative !== true && value < 0)
373
+ return "format";
374
+ if (field.currencyConfig?.allowDecimal === false &&
375
+ !Number.isInteger(value))
376
+ return "format";
377
+ return null;
378
+ }
379
+ case "measurement": {
380
+ if (typeof value !== "object" || value === null || Array.isArray(value))
381
+ return "type";
382
+ const mv = value;
383
+ if (mv.value === "" || mv.value === undefined || mv.value === null)
384
+ return null;
385
+ if (typeof mv.value !== "number" || Number.isNaN(mv.value))
386
+ return "type";
387
+ if (typeof mv.unit !== "string")
388
+ return "type";
389
+ const cat = field.unitConfig?.category;
390
+ if (cat && isMeasurementCategory(cat) && !isUnitInCategory(mv.unit, cat))
391
+ return "options";
392
+ if (field.unitConfig?.allowDecimal === false &&
393
+ !Number.isInteger(mv.value))
394
+ return "format";
395
+ return null;
396
+ }
397
+ case "multi_populator": {
398
+ // Lenient client check (the server validates each instance deeply):
399
+ // must be an array within the instance cap.
400
+ if (!Array.isArray(value))
401
+ return "type";
402
+ const max = field.populatorConfig?.maxInstances ?? 10;
403
+ if (value.length > Math.min(max, MAX_ARRAY_LEN))
404
+ return "max";
405
+ return null;
406
+ }
407
+ case "choice_cards": {
408
+ const labels = (field.choiceConfig?.options ?? []).map((o) => o.label);
409
+ if (field.choiceConfig?.mode === "multi") {
410
+ if (!Array.isArray(value))
411
+ return "type";
412
+ if (value.length > MAX_ARRAY_LEN)
413
+ return "max";
414
+ for (const v of value) {
415
+ if (typeof v !== "string")
416
+ return "type";
417
+ if (labels.length && !labels.includes(v))
418
+ return "options";
419
+ }
420
+ return null;
421
+ }
422
+ if (typeof value !== "string")
423
+ return "type";
424
+ if (value.length > MAX_STRING_LEN)
425
+ return "max";
426
+ if (labels.length && !labels.includes(value))
427
+ return "options";
428
+ return null;
429
+ }
430
+ case "file_upload": {
431
+ if (!Array.isArray(value))
432
+ return "type";
433
+ const maxFiles = Math.min(field.fileConfig?.maxFiles ?? MAX_ARRAY_LEN, MAX_ARRAY_LEN);
434
+ if (value.length > maxFiles)
435
+ return "max";
436
+ for (const item of value) {
437
+ if (!isPlainObject(item))
438
+ return "type";
439
+ if (!onlyBoundedPrimitives(item, MAX_FILE_FIELD_LEN))
440
+ return "type";
441
+ }
442
+ return null;
443
+ }
444
+ case "date_range": {
445
+ if (!isPlainObject(value))
446
+ return "type";
447
+ return onlyBoundedPrimitives(value, MAX_DATE_LEN) ? null : "type";
448
+ }
449
+ case "time_picker": {
450
+ const mode = field.timeConfig?.mode ?? "simple";
451
+ if (mode === "simple") {
452
+ if (typeof value !== "string")
453
+ return "type";
454
+ return value.length > MAX_DATE_LEN ? "max" : null;
455
+ }
456
+ if (!isPlainObject(value))
457
+ return "type";
458
+ return onlyBoundedPrimitives(value, MAX_DATE_LEN) ? null : "type";
459
+ }
460
+ case "address": {
461
+ if (!isPlainObject(value))
462
+ return "type";
463
+ if (!onlyBoundedPrimitives(value, MAX_ADDRESS_FIELD_LEN))
464
+ return "type";
465
+ // ZIP, when present, must be a US ZIP (5 digits or ZIP+4) — numbers only.
466
+ const zip = value.zip;
467
+ if (typeof zip === "string" && !isValidUsZip(zip))
468
+ return "format";
469
+ return null;
470
+ }
471
+ case "schedule": {
472
+ // Availability value: { asap?, days?: string[], times?: string[], notes? }.
473
+ // Auto value: { slotStartAt: <ISO> } (the chosen instant-booking slot).
474
+ if (!isPlainObject(value))
475
+ return "type";
476
+ const s = value;
477
+ if (s.slotStartAt !== undefined) {
478
+ if (typeof s.slotStartAt !== "string")
479
+ return "type";
480
+ if (s.slotStartAt.length > MAX_DATE_LEN)
481
+ return "max";
482
+ if (Number.isNaN(Date.parse(s.slotStartAt)))
483
+ return "format";
484
+ }
485
+ if (s.asap !== undefined && typeof s.asap !== "boolean")
486
+ return "type";
487
+ for (const key of ["days", "times"]) {
488
+ const arr = s[key];
489
+ if (arr === undefined)
490
+ continue;
491
+ if (!Array.isArray(arr))
492
+ return "type";
493
+ if (arr.length > MAX_ARRAY_LEN)
494
+ return "max";
495
+ for (const item of arr) {
496
+ if (typeof item !== "string")
497
+ return "type";
498
+ if (item.length > MAX_DATE_LEN)
499
+ return "max";
500
+ }
501
+ }
502
+ if (s.notes !== undefined) {
503
+ if (typeof s.notes !== "string")
504
+ return "type";
505
+ if (s.notes.length > MAX_STRING_LEN)
506
+ return "max";
507
+ }
508
+ return null;
509
+ }
510
+ default: {
511
+ // text / textarea / date / and any plain-text input.
512
+ if (typeof value === "number" || typeof value === "boolean")
513
+ return null;
514
+ if (typeof value !== "string")
515
+ return "type";
516
+ if (value.length > MAX_STRING_LEN)
517
+ return "max";
518
+ return regexFail(field, value);
519
+ }
520
+ }
521
+ }
522
+ // ─────────────────────────────────────────────────────────────────────────────
523
+ // Condition evaluation — condition_block + or_condition. Mirrors validate.ts.
524
+ // ─────────────────────────────────────────────────────────────────────────────
525
+ function evalClause(value, operator, target) {
526
+ switch (operator) {
527
+ case "eq":
528
+ return String(value ?? "") === target;
529
+ case "neq":
530
+ return String(value ?? "") !== target;
531
+ case "contains":
532
+ return String(value ?? "")
533
+ .toLowerCase()
534
+ .includes(target.toLowerCase());
535
+ case "gt":
536
+ return Number(value) > Number(target);
537
+ case "lt":
538
+ return Number(value) < Number(target);
539
+ case "is_empty":
540
+ return value === undefined || value === null || value === "";
541
+ case "is_not_empty":
542
+ return value !== undefined && value !== null && value !== "";
543
+ default:
544
+ return true;
545
+ }
546
+ }
547
+ /**
548
+ * A condition passes when its field satisfies ALL clauses (AND). Back-compat: a
549
+ * legacy single `{ operator, value }` rule is read as one clause. An absent rule
550
+ * (or one without a `fieldId`) passes. Faithful port of `evalCondition`.
551
+ */
552
+ export function evalCondition(rule, data) {
553
+ if (!rule?.fieldId)
554
+ return true;
555
+ const clauses = rule.clauses && rule.clauses.length > 0
556
+ ? rule.clauses
557
+ : rule.operator
558
+ ? [{ operator: rule.operator, value: rule.value }]
559
+ : [];
560
+ if (clauses.length === 0)
561
+ return true;
562
+ const value = data[rule.fieldId];
563
+ const test = (c) => evalClause(value, c.operator, c.value ?? "");
564
+ // `match: "any"` is OR across clauses. This used to always AND, so a rule the
565
+ // builder saved as "ANY of" behaved as "ALL of" once it rendered through the
566
+ // SDK — the dashboard and a consumer's site disagreed about the same form.
567
+ return rule.match === "any" ? clauses.some(test) : clauses.every(test);
568
+ }
569
+ /**
570
+ * Is a gating container currently visible?
571
+ *
572
+ * `condition_block` has always gated on its rule. `input_group` now does too:
573
+ * at the root of a consecutive form a group IS a page, so a rule there makes the
574
+ * whole page conditional. Every other type is unconditionally visible — a stray
575
+ * rule on a text field is ignored rather than hiding it.
576
+ */
577
+ export function isNodeVisible(node, data) {
578
+ if (node.type !== "condition_block" && node.type !== "input_group") {
579
+ return true;
580
+ }
581
+ return evalCondition(node.conditionRule, data);
582
+ }
583
+ // ─────────────────────────────────────────────────────────────────────────────
584
+ // Tree walks — subtreeHasValue / findMissingRequired / concurrentRevealCount.
585
+ // Mirrors FormPreview.tsx exactly so the binding matches the dashboard renderer.
586
+ // ─────────────────────────────────────────────────────────────────────────────
587
+ /** Recurse a subtree; report whether any non-static leaf has a non-empty value.
588
+ * Used by `or_condition` to detect which side the user chose. */
589
+ function subtreeHasValue(nodes, data) {
590
+ for (const f of nodes) {
591
+ if (f.type === "condition_block") {
592
+ if (!evalCondition(f.conditionRule, data))
593
+ continue;
594
+ if (f.children && subtreeHasValue(f.children, data))
595
+ return true;
596
+ continue;
597
+ }
598
+ if (f.type === "or_condition" ||
599
+ f.type === "input_group" ||
600
+ f.type === "flex_row") {
601
+ // Stale data behind a hidden group must not decide an or_condition
602
+ // branch — as far as the visitor is concerned it holds nothing.
603
+ if (!isNodeVisible(f, data))
604
+ continue;
605
+ if (f.children && subtreeHasValue(f.children, data))
606
+ return true;
607
+ continue;
608
+ }
609
+ if (STATIC_OR_LAYOUT.has(f.type))
610
+ continue;
611
+ if (f.id && !isEmpty(f, data[f.id]))
612
+ return true;
613
+ }
614
+ return false;
615
+ }
616
+ /**
617
+ * Returns the required fields that haven't been filled in, evaluated under the
618
+ * current condition state. A `condition_block` whose rule is false is skipped
619
+ * with its children; an `or_condition` requires at least one side filled, then
620
+ * recurses only into filled sides. Non-empty text/number values must also
621
+ * satisfy the field's regex pattern. Faithful port of FormPreview's
622
+ * `findMissingRequired`.
623
+ */
624
+ export function findMissingRequired(fields, data) {
625
+ const missing = [];
626
+ // `scope` is the data context: the whole submission, or one instance record
627
+ // inside a multi_populator.
628
+ const walk = (nodes, scope) => {
629
+ for (const f of nodes) {
630
+ if (f.type === "condition_block") {
631
+ if (!evalCondition(f.conditionRule, scope))
632
+ continue;
633
+ if (f.children)
634
+ walk(f.children, scope);
635
+ continue;
636
+ }
637
+ if (f.type === "or_condition") {
638
+ // Up to N branches (sides). At least one must be filled; then every
639
+ // filled branch is walked for its own required fields.
640
+ const children = f.children ?? [];
641
+ const filled = children.map((c) => subtreeHasValue([c], scope));
642
+ if (children.length > 0 && !filled.some(Boolean)) {
643
+ missing.push({
644
+ id: f.id,
645
+ label: f.label || "Either side required",
646
+ });
647
+ continue;
648
+ }
649
+ children.forEach((c, i) => {
650
+ if (filled[i])
651
+ walk([c], scope);
652
+ });
653
+ continue;
654
+ }
655
+ if (f.type === "input_group" || f.type === "flex_row") {
656
+ // A conditional PAGE that isn't showing requires nothing — the
657
+ // visitor never saw it, so it must not block Next or Submit.
658
+ if (!isNodeVisible(f, scope))
659
+ continue;
660
+ if (f.children)
661
+ walk(f.children, scope);
662
+ continue;
663
+ }
664
+ if (f.type === "multi_populator") {
665
+ const raw = scope[f.id];
666
+ const instances = (Array.isArray(raw) ? raw : []).filter((x) => x != null && typeof x === "object" && !Array.isArray(x));
667
+ const nonEmpty = instances.filter((inst) => Object.values(inst).some((v) => !(v === undefined ||
668
+ v === null ||
669
+ v === "" ||
670
+ (Array.isArray(v) && v.length === 0))));
671
+ if (f.required && nonEmpty.length === 0) {
672
+ missing.push({
673
+ id: f.id,
674
+ label: f.label || "At least one entry required",
675
+ });
676
+ continue;
677
+ }
678
+ for (const inst of nonEmpty)
679
+ walk(f.children ?? [], inst);
680
+ continue;
681
+ }
682
+ if (STATIC_OR_LAYOUT.has(f.type))
683
+ continue;
684
+ if ((f.required || f.mustBeTrue) && f.id && isEmpty(f, scope[f.id])) {
685
+ missing.push({ id: f.id, label: f.label || "Untitled" });
686
+ }
687
+ else if (f.id && (f.type === "text" || f.type === "number")) {
688
+ const pattern = f.regexPattern;
689
+ const v = String(scope[f.id] ?? "");
690
+ if (pattern && v) {
691
+ try {
692
+ if (!new RegExp(pattern).test(v)) {
693
+ missing.push({ id: f.id, label: f.label || "Invalid format" });
694
+ }
695
+ }
696
+ catch {
697
+ /* ignore an invalid pattern */
698
+ }
699
+ }
700
+ }
701
+ }
702
+ };
703
+ walk(fields, data);
704
+ return missing;
705
+ }
706
+ /**
707
+ * For a "concurrent questions" group: how many leading children to reveal. Shows
708
+ * every already-satisfied child plus the first unsatisfied one (the active
709
+ * question), so each required field gates the next. Optional/empty fields count
710
+ * as satisfied. Faithful port of FormPreview's `concurrentRevealCount`.
711
+ */
712
+ export function concurrentRevealCount(children, data) {
713
+ for (let i = 0; i < children.length; i++) {
714
+ const child = children[i];
715
+ if (child && findMissingRequired([child], data).length > 0)
716
+ return i + 1;
717
+ }
718
+ return children.length;
719
+ }
720
+ // ─────────────────────────────────────────────────────────────────────────────
721
+ // seedInitialData — walk the tree once, seed every input's id with a default.
722
+ // Mirrors FormPreview's seedInitialData + defaultValueFor.
723
+ // ─────────────────────────────────────────────────────────────────────────────
724
+ function defaultValueFor(field) {
725
+ switch (field.type) {
726
+ case "checkbox":
727
+ case "tags":
728
+ return [];
729
+ case "choice_cards":
730
+ return field.choiceConfig?.mode === "multi" ? [] : "";
731
+ case "multi_populator":
732
+ return [{}];
733
+ case "measurement": {
734
+ const cat = isMeasurementCategory(field.unitConfig?.category)
735
+ ? field.unitConfig.category
736
+ : "length";
737
+ const units = unitsForCategory(cat);
738
+ const unit = field.unitConfig?.defaultUnit ?? units[0] ?? "";
739
+ return { value: "", unit, baseUnit: baseUnitFor(cat) };
740
+ }
741
+ case "boolean":
742
+ return field.defaultValue === true;
743
+ case "number":
744
+ case "stepper":
745
+ case "slider":
746
+ case "star_rating":
747
+ case "happiness_rating":
748
+ return 0;
749
+ case "date_range":
750
+ return { start: "", end: "" };
751
+ case "time_picker": {
752
+ const mode = field.timeConfig?.mode ?? "simple";
753
+ if (mode === "time_block")
754
+ return { start: "", end: "" };
755
+ if (mode === "appointment")
756
+ return { date: "", time: "" };
757
+ return "";
758
+ }
759
+ default:
760
+ return typeof field.defaultValue === "string" ? field.defaultValue : "";
761
+ }
762
+ }
763
+ /**
764
+ * Walk the field tree once and seed every value-bearing input's id with a
765
+ * type-appropriate default. Static/layout/container nodes are skipped so no
766
+ * UUID-keyed empty string leaks into the payload (which the server would reject
767
+ * as an unknown field). Faithful port of FormPreview's `seedInitialData`.
768
+ */
769
+ export function seedInitialData(fields) {
770
+ const out = {};
771
+ const walk = (nodes) => {
772
+ for (const f of nodes) {
773
+ // A populator is value-bearing (array of instances); its children live
774
+ // inside that array, so seed its value and DON'T hoist children up.
775
+ if (f.type === "multi_populator") {
776
+ if (f.id)
777
+ out[f.id] = defaultValueFor(f);
778
+ continue;
779
+ }
780
+ if (f.id &&
781
+ !NO_SEED_STATIC.has(f.type) &&
782
+ !STEP_CONTAINERS.has(f.type) &&
783
+ f.type !== "flex_row") {
784
+ out[f.id] = defaultValueFor(f);
785
+ }
786
+ if (f.children)
787
+ walk(f.children);
788
+ }
789
+ };
790
+ walk(fields);
791
+ return out;
792
+ }
793
+ // ─────────────────────────────────────────────────────────────────────────────
794
+ // Submission-key remapping — id ⇆ output key. Lets the controller emit a
795
+ // payload keyed by the published `key` (preferred wire contract) while working
796
+ // internally by `id`. The server accepts either (back-compat).
797
+ // ─────────────────────────────────────────────────────────────────────────────
798
+ /** Flat list of value-bearing fields (depth-first, document order). */
799
+ export function flattenValueFields(fields) {
800
+ const out = [];
801
+ const walk = (nodes) => {
802
+ for (const f of nodes) {
803
+ // A populator is a single array-valued field; its children are nested in
804
+ // the array, not top-level — include it but don't descend.
805
+ if (f.type === "multi_populator") {
806
+ if (f.id)
807
+ out.push(f);
808
+ continue;
809
+ }
810
+ if (!STATIC_OR_LAYOUT.has(f.type) && f.id)
811
+ out.push(f);
812
+ // "stepper" is in STATIC_OR_LAYOUT for the layout-skip semantics but is a
813
+ // value-bearing numeric input — include it explicitly.
814
+ else if (f.type === "stepper" && f.id)
815
+ out.push(f);
816
+ if (f.children)
817
+ walk(f.children);
818
+ }
819
+ };
820
+ walk(fields);
821
+ return out;
822
+ }
823
+ /**
824
+ * Re-key working data (keyed by field `id`) to the published output `key` for
825
+ * the wire payload. Fields without a published `key` keep their `id`. Only
826
+ * value-bearing fields present in `data` are emitted.
827
+ */
828
+ export function toSubmissionPayload(fields, data) {
829
+ const remapScope = (scopeFields, scopeData) => {
830
+ const byId = new Map(flattenValueFields(scopeFields).map((field) => [field.id, field]));
831
+ const out = {};
832
+ for (const [id, inputValue] of Object.entries(scopeData)) {
833
+ const field = byId.get(id);
834
+ if (!field) {
835
+ out[id] = inputValue;
836
+ continue;
837
+ }
838
+ let value = inputValue;
839
+ if (field.type === "multi_populator" && Array.isArray(inputValue)) {
840
+ value = inputValue.map((instance) => instance && typeof instance === "object" && !Array.isArray(instance)
841
+ ? remapScope(field.children ?? [], instance)
842
+ : instance);
843
+ }
844
+ out[field.key ?? id] = value;
845
+ }
846
+ return out;
847
+ };
848
+ return remapScope(fields, data);
849
+ }
850
+ //# sourceMappingURL=validation.js.map