@wats/graph 0.3.25 → 0.3.27

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 (53) hide show
  1. package/README.md +1 -1
  2. package/dist/endpoints/businessManagement.d.ts +372 -1
  3. package/dist/endpoints/businessManagement.js +775 -5
  4. package/dist/endpoints/calling.d.ts +41 -1
  5. package/dist/endpoints/calling.js +100 -2
  6. package/dist/endpoints/flows/dataChannel.d.ts +139 -0
  7. package/dist/endpoints/flows/dataChannel.js +252 -0
  8. package/dist/endpoints/flows/flowDsl.d.ts +306 -0
  9. package/dist/endpoints/flows/flowDsl.js +610 -0
  10. package/dist/endpoints/flows/flowMediaUpload.d.ts +102 -0
  11. package/dist/endpoints/flows/flowMediaUpload.js +188 -0
  12. package/dist/endpoints/flows/index.d.ts +9 -1
  13. package/dist/endpoints/flows/index.js +70 -0
  14. package/dist/endpoints/flows/metricsMigration.d.ts +36 -0
  15. package/dist/endpoints/flows/metricsMigration.js +207 -0
  16. package/dist/endpoints/flows/types.d.ts +145 -0
  17. package/dist/endpoints/flows/types.js +14 -0
  18. package/dist/endpoints/flows.d.ts +2 -2
  19. package/dist/endpoints/flows.js +49 -1
  20. package/dist/endpoints/media.js +15 -1
  21. package/dist/endpoints/messages/builders-interactive.d.ts +9 -1
  22. package/dist/endpoints/messages/builders-interactive.js +49 -0
  23. package/dist/endpoints/messages/builders-template.d.ts +2 -1
  24. package/dist/endpoints/messages/builders-template.js +53 -2
  25. package/dist/endpoints/messages/deepLinks.d.ts +12 -0
  26. package/dist/endpoints/messages/deepLinks.js +38 -0
  27. package/dist/endpoints/messages/index.d.ts +4 -3
  28. package/dist/endpoints/messages/index.js +13 -2
  29. package/dist/endpoints/messages/types.d.ts +26 -3
  30. package/dist/endpoints/messages/validation.d.ts +7 -0
  31. package/dist/endpoints/messages/validation.js +12 -0
  32. package/dist/endpoints/oauth.d.ts +57 -0
  33. package/dist/endpoints/oauth.js +116 -0
  34. package/dist/endpoints/templates/advanced.d.ts +280 -0
  35. package/dist/endpoints/templates/advanced.js +519 -0
  36. package/dist/endpoints/templates/builders.js +21 -1
  37. package/dist/endpoints/templates/index.d.ts +2 -0
  38. package/dist/endpoints/templates/index.js +15 -0
  39. package/dist/endpoints/templates/shared.js +7 -1
  40. package/dist/endpoints/templates/types.d.ts +17 -2
  41. package/dist/endpoints/templates.d.ts +2 -1
  42. package/dist/endpoints/templates.js +14 -1
  43. package/dist/endpoints/wabaEndpoints.d.ts +4 -4
  44. package/dist/endpoints/wabaEndpoints.js +56 -0
  45. package/dist/index.d.ts +2 -1
  46. package/dist/index.js +1 -0
  47. package/dist/nodeMedia.d.ts +57 -0
  48. package/dist/nodeMedia.js +178 -0
  49. package/dist/subclients/phoneNumberClient.d.ts +92 -2
  50. package/dist/subclients/phoneNumberClient.js +133 -1
  51. package/dist/subclients/wabaClient.d.ts +82 -2
  52. package/dist/subclients/wabaClient.js +102 -2
  53. package/package.json +9 -11
@@ -0,0 +1,610 @@
1
+ import { flowJsonClone } from "./flowJson.js";
2
+ import {
3
+ FLOW_JSON_MAX_ARRAY_LENGTH,
4
+ flowArray,
5
+ flowAssertPlainRecord,
6
+ flowError,
7
+ flowHasControlChar,
8
+ flowIsUnsafeObjectKey,
9
+ flowString
10
+ } from "./shared.js";
11
+ export const FLOW_DSL_MAX_CONTROL_DEPTH = 5;
12
+ function wire(entries) {
13
+ const out = {};
14
+ for (const [key, value] of entries) {
15
+ if (value !== undefined)
16
+ out[key] = value;
17
+ }
18
+ return out;
19
+ }
20
+ function assertProps(value, helper) {
21
+ return flowAssertPlainRecord(value, helper);
22
+ }
23
+ function reqString(value, field, helper, max = 4096) {
24
+ return flowString(value, field, helper, max);
25
+ }
26
+ function optString(value, field, helper, max = 4096) {
27
+ if (value === undefined)
28
+ return;
29
+ return flowString(value, field, helper, max);
30
+ }
31
+ function optBool(value, field, helper) {
32
+ if (value === undefined)
33
+ return;
34
+ if (typeof value !== "boolean") {
35
+ throw flowError(`Invalid ${helper} input: ${field} must be a boolean.`);
36
+ }
37
+ return value;
38
+ }
39
+ function optInt(value, field, helper) {
40
+ if (value === undefined)
41
+ return;
42
+ if (typeof value !== "number" || !Number.isInteger(value)) {
43
+ throw flowError(`Invalid ${helper} input: ${field} must be an integer.`);
44
+ }
45
+ return value;
46
+ }
47
+ function reqEnum(value, field, helper, allowed) {
48
+ const str = flowString(value, field, helper, 256);
49
+ if (!allowed.includes(str)) {
50
+ throw flowError(`Invalid ${helper} input: ${field} must be one of ${allowed.join(", ")}.`);
51
+ }
52
+ return str;
53
+ }
54
+ function optEnum(value, field, helper, allowed) {
55
+ if (value === undefined)
56
+ return;
57
+ return reqEnum(value, field, helper, allowed);
58
+ }
59
+ function optStringArray(value, field, helper, min = 0) {
60
+ if (value === undefined)
61
+ return;
62
+ const arr = flowArray(value, field, min, FLOW_JSON_MAX_ARRAY_LENGTH, helper);
63
+ return arr.map((item, index) => flowString(item, `${field}[${index}]`, helper, 4096));
64
+ }
65
+ function reqTextValue(value, field, helper) {
66
+ if (Array.isArray(value)) {
67
+ const arr = flowArray(value, field, 1, FLOW_JSON_MAX_ARRAY_LENGTH, helper);
68
+ return arr.map((item, index) => flowString(item, `${field}[${index}]`, helper, 16384));
69
+ }
70
+ return flowString(value, field, helper, 16384);
71
+ }
72
+ function cloneRecord(value, field, helper) {
73
+ flowAssertPlainRecord(value, helper, field);
74
+ return flowJsonClone(value, helper, field);
75
+ }
76
+ function optRecord(value, field, helper) {
77
+ if (value === undefined)
78
+ return;
79
+ return cloneRecord(value, field, helper);
80
+ }
81
+ function cloneChildren(value, field, helper, min) {
82
+ flowArray(value, field, min, FLOW_JSON_MAX_ARRAY_LENGTH, helper);
83
+ return flowJsonClone(value, helper, field);
84
+ }
85
+ function optAction(value, field, helper) {
86
+ if (value === undefined)
87
+ return;
88
+ if (typeof value === "string") {
89
+ if (flowHasControlChar(value) || value.length === 0) {
90
+ throw flowError(`Invalid ${helper} input: ${field} must be a non-empty action ref string.`);
91
+ }
92
+ return value;
93
+ }
94
+ return cloneRecord(value, field, helper);
95
+ }
96
+ function dataSourceValue(value, field, helper) {
97
+ if (typeof value === "string") {
98
+ return flowString(value, field, helper, 4096);
99
+ }
100
+ return cloneChildren(value, field, helper, 1);
101
+ }
102
+ function maxControlDepth(value) {
103
+ if (Array.isArray(value)) {
104
+ let max = 0;
105
+ for (const item of value)
106
+ max = Math.max(max, maxControlDepth(item));
107
+ return max;
108
+ }
109
+ if (value !== null && typeof value === "object") {
110
+ const record = value;
111
+ let childMax = 0;
112
+ for (const nested of Object.values(record)) {
113
+ childMax = Math.max(childMax, maxControlDepth(nested));
114
+ }
115
+ if (record.type === "If" || record.type === "Switch")
116
+ return 1 + childMax;
117
+ return childMax;
118
+ }
119
+ return 0;
120
+ }
121
+ function assertControlDepth(node, helper) {
122
+ if (maxControlDepth(node) > FLOW_DSL_MAX_CONTROL_DEPTH) {
123
+ throw flowError(`Invalid ${helper} input: control-flow nesting exceeds maximum depth ${FLOW_DSL_MAX_CONTROL_DEPTH}.`);
124
+ }
125
+ }
126
+ export function flowJson(props) {
127
+ const record = assertProps(props, "flowJson");
128
+ const version = reqString(record.version, "version", "flowJson", 64);
129
+ const screens = cloneChildren(record.screens, "screens", "flowJson", 1);
130
+ let routingModel;
131
+ if (record.routingModel !== undefined) {
132
+ const rm = cloneRecord(record.routingModel, "routingModel", "flowJson");
133
+ for (const [key, value] of Object.entries(rm)) {
134
+ flowArray(value, `routingModel.${key}`, 0, FLOW_JSON_MAX_ARRAY_LENGTH, "flowJson");
135
+ }
136
+ routingModel = rm;
137
+ }
138
+ return wire([
139
+ ["version", version],
140
+ ["screens", screens],
141
+ ["data_api_version", optString(record.dataApiVersion, "dataApiVersion", "flowJson", 64)],
142
+ ["routing_model", routingModel],
143
+ ["data_channel_uri", optString(record.dataChannelUri, "dataChannelUri", "flowJson", 2048)]
144
+ ]);
145
+ }
146
+ export function screen(props) {
147
+ const record = assertProps(props, "screen");
148
+ const id = reqString(record.id, "id", "screen", 256);
149
+ const layout = cloneRecord(record.layout, "layout", "screen");
150
+ return wire([
151
+ ["id", id],
152
+ ["layout", layout],
153
+ ["title", optString(record.title, "title", "screen", 1024)],
154
+ ["data", optRecord(record.data, "data", "screen")],
155
+ ["terminal", optBool(record.terminal, "terminal", "screen")],
156
+ ["success", optBool(record.success, "success", "screen")],
157
+ ["refresh_on_back", optBool(record.refreshOnBack, "refreshOnBack", "screen")],
158
+ ["sensitive", optStringArray(record.sensitive, "sensitive", "screen")]
159
+ ]);
160
+ }
161
+ export function singleColumnLayout(children) {
162
+ const cloned = cloneChildren(children, "children", "singleColumnLayout", 1);
163
+ return { type: "SingleColumnLayout", children: cloned };
164
+ }
165
+ export function form(props) {
166
+ const record = assertProps(props, "form");
167
+ return wire([
168
+ ["type", "Form"],
169
+ ["name", reqString(record.name, "name", "form", 256)],
170
+ ["children", cloneChildren(record.children, "children", "form", 1)],
171
+ ["init-values", optRecord(record.initValues, "initValues", "form")],
172
+ ["error-messages", optRecord(record.errorMessages, "errorMessages", "form")]
173
+ ]);
174
+ }
175
+ export function textHeading(props) {
176
+ const r = assertProps(props, "textHeading");
177
+ return wire([
178
+ ["type", "TextHeading"],
179
+ ["text", reqString(r.text, "text", "textHeading", 16384)],
180
+ ["visible", optBool(r.visible, "visible", "textHeading")]
181
+ ]);
182
+ }
183
+ export function textSubheading(props) {
184
+ const r = assertProps(props, "textSubheading");
185
+ return wire([
186
+ ["type", "TextSubheading"],
187
+ ["text", reqString(r.text, "text", "textSubheading", 16384)],
188
+ ["visible", optBool(r.visible, "visible", "textSubheading")]
189
+ ]);
190
+ }
191
+ const FONT_WEIGHTS = ["normal", "bold", "italic", "bold_italic"];
192
+ export function textBody(props) {
193
+ const r = assertProps(props, "textBody");
194
+ return wire([
195
+ ["type", "TextBody"],
196
+ ["text", reqTextValue(r.text, "text", "textBody")],
197
+ ["markdown", optBool(r.markdown, "markdown", "textBody")],
198
+ ["font-weight", optEnum(r.fontWeight, "fontWeight", "textBody", FONT_WEIGHTS)],
199
+ ["strikethrough", optBool(r.strikethrough, "strikethrough", "textBody")],
200
+ ["visible", optBool(r.visible, "visible", "textBody")]
201
+ ]);
202
+ }
203
+ export function textCaption(props) {
204
+ const r = assertProps(props, "textCaption");
205
+ return wire([
206
+ ["type", "TextCaption"],
207
+ ["text", reqTextValue(r.text, "text", "textCaption")],
208
+ ["markdown", optBool(r.markdown, "markdown", "textCaption")],
209
+ ["font-weight", optEnum(r.fontWeight, "fontWeight", "textCaption", FONT_WEIGHTS)],
210
+ ["strikethrough", optBool(r.strikethrough, "strikethrough", "textCaption")],
211
+ ["visible", optBool(r.visible, "visible", "textCaption")]
212
+ ]);
213
+ }
214
+ export function richText(props) {
215
+ const r = assertProps(props, "richText");
216
+ return wire([
217
+ ["type", "RichText"],
218
+ ["text", reqTextValue(r.text, "text", "richText")],
219
+ ["visible", optBool(r.visible, "visible", "richText")]
220
+ ]);
221
+ }
222
+ const INPUT_TYPES = ["text", "number", "email", "password", "passcode", "phone"];
223
+ const LABEL_VARIANTS = ["large"];
224
+ export function textInput(props) {
225
+ const r = assertProps(props, "textInput");
226
+ return wire([
227
+ ["type", "TextInput"],
228
+ ["name", reqString(r.name, "name", "textInput", 256)],
229
+ ["label", reqString(r.label, "label", "textInput", 1024)],
230
+ ["input-type", optEnum(r.inputType, "inputType", "textInput", INPUT_TYPES)],
231
+ ["label-variant", optEnum(r.labelVariant, "labelVariant", "textInput", LABEL_VARIANTS)],
232
+ ["pattern", optString(r.pattern, "pattern", "textInput")],
233
+ ["required", optBool(r.required, "required", "textInput")],
234
+ ["min-chars", optInt(r.minChars, "minChars", "textInput")],
235
+ ["max-chars", optInt(r.maxChars, "maxChars", "textInput")],
236
+ ["helper-text", optString(r.helperText, "helperText", "textInput", 4096)],
237
+ ["enabled", optBool(r.enabled, "enabled", "textInput")],
238
+ ["visible", optBool(r.visible, "visible", "textInput")],
239
+ ["init-value", optString(r.initValue, "initValue", "textInput", 16384)],
240
+ ["error-message", optString(r.errorMessage, "errorMessage", "textInput", 4096)]
241
+ ]);
242
+ }
243
+ export function textArea(props) {
244
+ const r = assertProps(props, "textArea");
245
+ return wire([
246
+ ["type", "TextArea"],
247
+ ["name", reqString(r.name, "name", "textArea", 256)],
248
+ ["label", reqString(r.label, "label", "textArea", 1024)],
249
+ ["label-variant", optEnum(r.labelVariant, "labelVariant", "textArea", LABEL_VARIANTS)],
250
+ ["required", optBool(r.required, "required", "textArea")],
251
+ ["max-length", optInt(r.maxLength, "maxLength", "textArea")],
252
+ ["helper-text", optString(r.helperText, "helperText", "textArea", 4096)],
253
+ ["enabled", optBool(r.enabled, "enabled", "textArea")],
254
+ ["visible", optBool(r.visible, "visible", "textArea")],
255
+ ["init-value", optString(r.initValue, "initValue", "textArea", 16384)],
256
+ ["error-message", optString(r.errorMessage, "errorMessage", "textArea", 4096)]
257
+ ]);
258
+ }
259
+ const MEDIA_SIZES = ["regular", "large"];
260
+ export function checkboxGroup(props) {
261
+ const r = assertProps(props, "checkboxGroup");
262
+ return wire([
263
+ ["type", "CheckboxGroup"],
264
+ ["name", reqString(r.name, "name", "checkboxGroup", 256)],
265
+ ["data-source", dataSourceValue(r.dataSource, "dataSource", "checkboxGroup")],
266
+ ["label", optString(r.label, "label", "checkboxGroup", 1024)],
267
+ ["description", optString(r.description, "description", "checkboxGroup", 4096)],
268
+ ["min-selected-items", optInt(r.minSelectedItems, "minSelectedItems", "checkboxGroup")],
269
+ ["max-selected-items", optInt(r.maxSelectedItems, "maxSelectedItems", "checkboxGroup")],
270
+ ["required", optBool(r.required, "required", "checkboxGroup")],
271
+ ["visible", optBool(r.visible, "visible", "checkboxGroup")],
272
+ ["enabled", optBool(r.enabled, "enabled", "checkboxGroup")],
273
+ ["init-value", optStringArray(r.initValue, "initValue", "checkboxGroup")],
274
+ ["media-size", optEnum(r.mediaSize, "mediaSize", "checkboxGroup", MEDIA_SIZES)],
275
+ ["on-select-action", optAction(r.onSelectAction, "onSelectAction", "checkboxGroup")],
276
+ ["on-unselect-action", optAction(r.onUnselectAction, "onUnselectAction", "checkboxGroup")]
277
+ ]);
278
+ }
279
+ export function radioButtonsGroup(props) {
280
+ const r = assertProps(props, "radioButtonsGroup");
281
+ return wire([
282
+ ["type", "RadioButtonsGroup"],
283
+ ["name", reqString(r.name, "name", "radioButtonsGroup", 256)],
284
+ ["data-source", dataSourceValue(r.dataSource, "dataSource", "radioButtonsGroup")],
285
+ ["label", optString(r.label, "label", "radioButtonsGroup", 1024)],
286
+ ["description", optString(r.description, "description", "radioButtonsGroup", 4096)],
287
+ ["required", optBool(r.required, "required", "radioButtonsGroup")],
288
+ ["visible", optBool(r.visible, "visible", "radioButtonsGroup")],
289
+ ["enabled", optBool(r.enabled, "enabled", "radioButtonsGroup")],
290
+ ["init-value", optString(r.initValue, "initValue", "radioButtonsGroup", 4096)],
291
+ ["media-size", optEnum(r.mediaSize, "mediaSize", "radioButtonsGroup", MEDIA_SIZES)],
292
+ ["on-select-action", optAction(r.onSelectAction, "onSelectAction", "radioButtonsGroup")],
293
+ ["on-unselect-action", optAction(r.onUnselectAction, "onUnselectAction", "radioButtonsGroup")]
294
+ ]);
295
+ }
296
+ export function dropdown(props) {
297
+ const r = assertProps(props, "dropdown");
298
+ return wire([
299
+ ["type", "Dropdown"],
300
+ ["name", reqString(r.name, "name", "dropdown", 256)],
301
+ ["label", reqString(r.label, "label", "dropdown", 1024)],
302
+ ["data-source", dataSourceValue(r.dataSource, "dataSource", "dropdown")],
303
+ ["enabled", optBool(r.enabled, "enabled", "dropdown")],
304
+ ["required", optBool(r.required, "required", "dropdown")],
305
+ ["visible", optBool(r.visible, "visible", "dropdown")],
306
+ ["init-value", optString(r.initValue, "initValue", "dropdown", 4096)],
307
+ ["on-select-action", optAction(r.onSelectAction, "onSelectAction", "dropdown")],
308
+ ["on-unselect-action", optAction(r.onUnselectAction, "onUnselectAction", "dropdown")]
309
+ ]);
310
+ }
311
+ export function chipsSelector(props) {
312
+ const r = assertProps(props, "chipsSelector");
313
+ return wire([
314
+ ["type", "ChipsSelector"],
315
+ ["name", reqString(r.name, "name", "chipsSelector", 256)],
316
+ ["data-source", dataSourceValue(r.dataSource, "dataSource", "chipsSelector")],
317
+ ["label", reqString(r.label, "label", "chipsSelector", 1024)],
318
+ ["description", optString(r.description, "description", "chipsSelector", 4096)],
319
+ ["min-selected-items", optInt(r.minSelectedItems, "minSelectedItems", "chipsSelector")],
320
+ ["max-selected-items", optInt(r.maxSelectedItems, "maxSelectedItems", "chipsSelector")],
321
+ ["required", optBool(r.required, "required", "chipsSelector")],
322
+ ["visible", optBool(r.visible, "visible", "chipsSelector")],
323
+ ["enabled", optBool(r.enabled, "enabled", "chipsSelector")],
324
+ ["init-value", optStringArray(r.initValue, "initValue", "chipsSelector")],
325
+ ["on-select-action", optAction(r.onSelectAction, "onSelectAction", "chipsSelector")],
326
+ ["on-unselect-action", optAction(r.onUnselectAction, "onUnselectAction", "chipsSelector")]
327
+ ]);
328
+ }
329
+ export function footer(props) {
330
+ const r = assertProps(props, "footer");
331
+ return wire([
332
+ ["type", "Footer"],
333
+ ["label", reqString(r.label, "label", "footer", 1024)],
334
+ ["on-click-action", requireAction(r.onClickAction, "onClickAction", "footer")],
335
+ ["left-caption", optString(r.leftCaption, "leftCaption", "footer", 4096)],
336
+ ["center-caption", optString(r.centerCaption, "centerCaption", "footer", 4096)],
337
+ ["right-caption", optString(r.rightCaption, "rightCaption", "footer", 4096)],
338
+ ["enabled", optBool(r.enabled, "enabled", "footer")]
339
+ ]);
340
+ }
341
+ function requireAction(value, field, helper) {
342
+ if (value === undefined) {
343
+ throw flowError(`Invalid ${helper} input: ${field} is required.`);
344
+ }
345
+ return optAction(value, field, helper);
346
+ }
347
+ export function optIn(props) {
348
+ const r = assertProps(props, "optIn");
349
+ return wire([
350
+ ["type", "OptIn"],
351
+ ["name", reqString(r.name, "name", "optIn", 256)],
352
+ ["label", reqString(r.label, "label", "optIn", 4096)],
353
+ ["required", optBool(r.required, "required", "optIn")],
354
+ ["visible", optBool(r.visible, "visible", "optIn")],
355
+ ["init-value", optBool(r.initValue, "initValue", "optIn")],
356
+ ["on-click-action", optAction(r.onClickAction, "onClickAction", "optIn")],
357
+ ["on-select-action", optAction(r.onSelectAction, "onSelectAction", "optIn")],
358
+ ["on-unselect-action", optAction(r.onUnselectAction, "onUnselectAction", "optIn")]
359
+ ]);
360
+ }
361
+ export function embeddedLink(props) {
362
+ const r = assertProps(props, "embeddedLink");
363
+ return wire([
364
+ ["type", "EmbeddedLink"],
365
+ ["text", reqString(r.text, "text", "embeddedLink", 4096)],
366
+ ["on-click-action", requireAction(r.onClickAction, "onClickAction", "embeddedLink")],
367
+ ["visible", optBool(r.visible, "visible", "embeddedLink")]
368
+ ]);
369
+ }
370
+ export function navigationItem(props) {
371
+ const r = assertProps(props, "navigationItem");
372
+ return wire([
373
+ ["id", reqString(r.id, "id", "navigationItem", 256)],
374
+ ["main-content", cloneRecord(r.mainContent, "mainContent", "navigationItem")],
375
+ ["start", optRecord(r.start, "start", "navigationItem")],
376
+ ["end", optRecord(r.end, "end", "navigationItem")],
377
+ ["badge", optString(r.badge, "badge", "navigationItem", 1024)],
378
+ ["tags", optStringArray(r.tags, "tags", "navigationItem")],
379
+ ["on-click-action", optAction(r.onClickAction, "onClickAction", "navigationItem")]
380
+ ]);
381
+ }
382
+ export function navigationList(props) {
383
+ const r = assertProps(props, "navigationList");
384
+ return wire([
385
+ ["type", "NavigationList"],
386
+ ["name", reqString(r.name, "name", "navigationList", 256)],
387
+ ["list-items", cloneChildren(r.listItems, "listItems", "navigationList", 1)],
388
+ ["label", optString(r.label, "label", "navigationList", 1024)],
389
+ ["description", optString(r.description, "description", "navigationList", 4096)],
390
+ ["media-size", optEnum(r.mediaSize, "mediaSize", "navigationList", MEDIA_SIZES)],
391
+ ["on-click-action", optAction(r.onClickAction, "onClickAction", "navigationList")]
392
+ ]);
393
+ }
394
+ export function datePicker(props) {
395
+ const r = assertProps(props, "datePicker");
396
+ return wire([
397
+ ["type", "DatePicker"],
398
+ ["name", reqString(r.name, "name", "datePicker", 256)],
399
+ ["label", reqString(r.label, "label", "datePicker", 1024)],
400
+ ["min-date", optString(r.minDate, "minDate", "datePicker", 64)],
401
+ ["max-date", optString(r.maxDate, "maxDate", "datePicker", 64)],
402
+ ["unavailable-dates", optStringArray(r.unavailableDates, "unavailableDates", "datePicker")],
403
+ ["helper-text", optString(r.helperText, "helperText", "datePicker", 4096)],
404
+ ["enabled", optBool(r.enabled, "enabled", "datePicker")],
405
+ ["required", optBool(r.required, "required", "datePicker")],
406
+ ["visible", optBool(r.visible, "visible", "datePicker")],
407
+ ["init-value", optString(r.initValue, "initValue", "datePicker", 64)],
408
+ ["error-message", optString(r.errorMessage, "errorMessage", "datePicker", 4096)],
409
+ ["on-select-action", optAction(r.onSelectAction, "onSelectAction", "datePicker")]
410
+ ]);
411
+ }
412
+ const CALENDAR_MODES = ["single", "range"];
413
+ const INCLUDE_DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
414
+ export function calendarPicker(props) {
415
+ const r = assertProps(props, "calendarPicker");
416
+ let includeDays;
417
+ if (r.includeDays !== undefined) {
418
+ const arr = optStringArray(r.includeDays, "includeDays", "calendarPicker") ?? [];
419
+ for (const day of arr) {
420
+ if (!INCLUDE_DAYS.includes(day)) {
421
+ throw flowError(`Invalid calendarPicker input: includeDays must be among ${INCLUDE_DAYS.join(", ")}.`);
422
+ }
423
+ }
424
+ includeDays = arr;
425
+ }
426
+ let initValue;
427
+ if (r.initValue !== undefined) {
428
+ initValue = typeof r.initValue === "string" ? flowString(r.initValue, "initValue", "calendarPicker", 256) : cloneRecord(r.initValue, "initValue", "calendarPicker");
429
+ }
430
+ return wire([
431
+ ["type", "CalendarPicker"],
432
+ ["name", reqString(r.name, "name", "calendarPicker", 256)],
433
+ ["label", reqString(r.label, "label", "calendarPicker", 1024)],
434
+ ["title", optString(r.title, "title", "calendarPicker", 1024)],
435
+ ["description", optString(r.description, "description", "calendarPicker", 4096)],
436
+ ["mode", optEnum(r.mode, "mode", "calendarPicker", CALENDAR_MODES)],
437
+ ["min-date", optString(r.minDate, "minDate", "calendarPicker", 64)],
438
+ ["max-date", optString(r.maxDate, "maxDate", "calendarPicker", 64)],
439
+ ["unavailable-dates", optStringArray(r.unavailableDates, "unavailableDates", "calendarPicker")],
440
+ ["min-days", optInt(r.minDays, "minDays", "calendarPicker")],
441
+ ["max-days", optInt(r.maxDays, "maxDays", "calendarPicker")],
442
+ ["include-days", includeDays],
443
+ ["helper-text", optString(r.helperText, "helperText", "calendarPicker", 4096)],
444
+ ["enabled", optBool(r.enabled, "enabled", "calendarPicker")],
445
+ ["required", optBool(r.required, "required", "calendarPicker")],
446
+ ["visible", optBool(r.visible, "visible", "calendarPicker")],
447
+ ["init-value", initValue],
448
+ ["error-message", optString(r.errorMessage, "errorMessage", "calendarPicker", 4096)],
449
+ ["on-select-action", optAction(r.onSelectAction, "onSelectAction", "calendarPicker")]
450
+ ]);
451
+ }
452
+ const SCALE_TYPES = ["cover", "contain"];
453
+ export function image(props) {
454
+ const r = assertProps(props, "image");
455
+ const aspectRatio = optInt(r.aspectRatio, "aspectRatio", "image");
456
+ if (aspectRatio === undefined) {
457
+ throw flowError("Invalid image input: aspectRatio is required.");
458
+ }
459
+ return wire([
460
+ ["type", "Image"],
461
+ ["src", reqString(r.src, "src", "image", 1e6)],
462
+ ["aspect-ratio", aspectRatio],
463
+ ["width", optInt(r.width, "width", "image")],
464
+ ["height", optInt(r.height, "height", "image")],
465
+ ["scale-type", optEnum(r.scaleType, "scaleType", "image", SCALE_TYPES)],
466
+ ["alt-text", optString(r.altText, "altText", "image", 4096)],
467
+ ["visible", optBool(r.visible, "visible", "image")]
468
+ ]);
469
+ }
470
+ export function imageCarouselItem(props) {
471
+ const r = assertProps(props, "imageCarouselItem");
472
+ return wire([
473
+ ["src", reqString(r.src, "src", "imageCarouselItem", 1e6)],
474
+ ["alt-text", reqString(r.altText, "altText", "imageCarouselItem", 4096)]
475
+ ]);
476
+ }
477
+ export function imageCarousel(props) {
478
+ const r = assertProps(props, "imageCarousel");
479
+ return wire([
480
+ ["type", "ImageCarousel"],
481
+ ["images", cloneChildren(r.images, "images", "imageCarousel", 1)],
482
+ ["aspect-ratio", optString(r.aspectRatio, "aspectRatio", "imageCarousel", 16)],
483
+ ["scale-type", optEnum(r.scaleType, "scaleType", "imageCarousel", SCALE_TYPES)],
484
+ ["visible", optBool(r.visible, "visible", "imageCarousel")]
485
+ ]);
486
+ }
487
+ const PHOTO_SOURCES = ["camera_gallery", "camera", "gallery"];
488
+ export function photoPicker(props) {
489
+ const r = assertProps(props, "photoPicker");
490
+ return wire([
491
+ ["type", "PhotoPicker"],
492
+ ["name", reqString(r.name, "name", "photoPicker", 256)],
493
+ ["label", reqString(r.label, "label", "photoPicker", 1024)],
494
+ ["description", optString(r.description, "description", "photoPicker", 4096)],
495
+ ["photo-source", optEnum(r.photoSource, "photoSource", "photoPicker", PHOTO_SOURCES)],
496
+ ["max-file-size-kb", optInt(r.maxFileSizeKb, "maxFileSizeKb", "photoPicker")],
497
+ ["min-uploaded-photos", optInt(r.minUploadedPhotos, "minUploadedPhotos", "photoPicker")],
498
+ ["max-uploaded-photos", optInt(r.maxUploadedPhotos, "maxUploadedPhotos", "photoPicker")],
499
+ ["enabled", optBool(r.enabled, "enabled", "photoPicker")],
500
+ ["visible", optBool(r.visible, "visible", "photoPicker")],
501
+ ["error-message", optString(r.errorMessage, "errorMessage", "photoPicker", 4096)]
502
+ ]);
503
+ }
504
+ export function documentPicker(props) {
505
+ const r = assertProps(props, "documentPicker");
506
+ return wire([
507
+ ["type", "DocumentPicker"],
508
+ ["name", reqString(r.name, "name", "documentPicker", 256)],
509
+ ["label", reqString(r.label, "label", "documentPicker", 1024)],
510
+ ["description", optString(r.description, "description", "documentPicker", 4096)],
511
+ ["max-file-size-kb", optInt(r.maxFileSizeKb, "maxFileSizeKb", "documentPicker")],
512
+ ["min-uploaded-documents", optInt(r.minUploadedDocuments, "minUploadedDocuments", "documentPicker")],
513
+ ["max-uploaded-documents", optInt(r.maxUploadedDocuments, "maxUploadedDocuments", "documentPicker")],
514
+ ["allowed-mime-types", optStringArray(r.allowedMimeTypes, "allowedMimeTypes", "documentPicker")],
515
+ ["enabled", optBool(r.enabled, "enabled", "documentPicker")],
516
+ ["visible", optBool(r.visible, "visible", "documentPicker")],
517
+ ["error-message", optString(r.errorMessage, "errorMessage", "documentPicker", 4096)]
518
+ ]);
519
+ }
520
+ export function ifComponent(props) {
521
+ const r = assertProps(props, "ifComponent");
522
+ const elseInput = r.else !== undefined ? r.else : r.else_;
523
+ const node = wire([
524
+ ["type", "If"],
525
+ ["condition", reqString(r.condition, "condition", "ifComponent", 4096)],
526
+ ["then", cloneChildren(r.then, "then", "ifComponent", 1)],
527
+ ["else", elseInput === undefined ? undefined : cloneChildren(elseInput, "else", "ifComponent", 1)]
528
+ ]);
529
+ assertControlDepth(node, "ifComponent");
530
+ return node;
531
+ }
532
+ export function switchComponent(props) {
533
+ const r = assertProps(props, "switchComponent");
534
+ const casesRecord = flowAssertPlainRecord(r.cases, "switchComponent", "cases");
535
+ const caseKeys = Object.keys(casesRecord);
536
+ if (caseKeys.length === 0) {
537
+ throw flowError("Invalid switchComponent input: cases must contain at least one branch.");
538
+ }
539
+ const cases = {};
540
+ for (const key of caseKeys) {
541
+ if (flowIsUnsafeObjectKey(key)) {
542
+ throw flowError("Invalid switchComponent input: cases contains an unsafe prototype key.");
543
+ }
544
+ cases[key] = cloneChildren(casesRecord[key], `cases.${key}`, "switchComponent", 1);
545
+ }
546
+ const node = wire([
547
+ ["type", "Switch"],
548
+ ["value", reqString(r.value, "value", "switchComponent", 4096)],
549
+ ["cases", cases]
550
+ ]);
551
+ assertControlDepth(node, "switchComponent");
552
+ return node;
553
+ }
554
+ export function dataSource(props) {
555
+ const r = assertProps(props, "dataSource");
556
+ return wire([
557
+ ["id", reqString(r.id, "id", "dataSource", 256)],
558
+ ["title", reqString(r.title, "title", "dataSource", 4096)],
559
+ ["on-select-action", optAction(r.onSelectAction, "onSelectAction", "dataSource")],
560
+ ["on-unselect-action", optAction(r.onUnselectAction, "onUnselectAction", "dataSource")],
561
+ ["description", optString(r.description, "description", "dataSource", 4096)],
562
+ ["metadata", optRecord(r.metadata, "metadata", "dataSource")],
563
+ ["enabled", optBool(r.enabled, "enabled", "dataSource")],
564
+ ["image", optString(r.image, "image", "dataSource", 1e6)],
565
+ ["alt-text", optString(r.altText, "altText", "dataSource", 4096)],
566
+ ["color", optString(r.color, "color", "dataSource", 64)]
567
+ ]);
568
+ }
569
+ export function dataExchangeAction(props) {
570
+ const r = props === undefined ? {} : assertProps(props, "dataExchangeAction");
571
+ const payload = r.payload === undefined ? {} : cloneRecord(r.payload, "payload", "dataExchangeAction");
572
+ return { name: "data_exchange", payload };
573
+ }
574
+ const NAVIGATE_TARGET_TYPES = ["screen", "plugin"];
575
+ export function navigateAction(props) {
576
+ const r = assertProps(props, "navigateAction");
577
+ const nextRecord = flowAssertPlainRecord(r.next, "navigateAction", "next");
578
+ const next = wire([
579
+ ["name", reqString(nextRecord.name, "next.name", "navigateAction", 256)],
580
+ ["type", reqEnum(nextRecord.type ?? "screen", "next.type", "navigateAction", NAVIGATE_TARGET_TYPES)]
581
+ ]);
582
+ const payload = r.payload === undefined ? {} : cloneRecord(r.payload, "payload", "navigateAction");
583
+ return { name: "navigate", next, payload };
584
+ }
585
+ export function completeAction(props) {
586
+ const r = props === undefined ? {} : assertProps(props, "completeAction");
587
+ const payload = r.payload === undefined ? {} : cloneRecord(r.payload, "payload", "completeAction");
588
+ return { name: "complete", payload };
589
+ }
590
+ export function updateDataAction(props) {
591
+ const r = assertProps(props, "updateDataAction");
592
+ if (r.payload === undefined) {
593
+ throw flowError("Invalid updateDataAction input: payload is required.");
594
+ }
595
+ return { name: "update_data", payload: cloneRecord(r.payload, "payload", "updateDataAction") };
596
+ }
597
+ export function openUrlAction(props) {
598
+ const r = assertProps(props, "openUrlAction");
599
+ const url = reqString(r.url, "url", "openUrlAction", 2048);
600
+ let parsed;
601
+ try {
602
+ parsed = new URL(url);
603
+ } catch {
604
+ throw flowError("Invalid openUrlAction input: url must be an absolute http(s) URL.");
605
+ }
606
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
607
+ throw flowError("Invalid openUrlAction input: url protocol must be http: or https:.");
608
+ }
609
+ return { name: "open_url", url };
610
+ }