@nyaruka/temba-components 0.131.0 → 0.131.2

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 (430) hide show
  1. package/.github/workflows/publish.yml +4 -1
  2. package/CHANGELOG.md +67 -1
  3. package/demo/data/flows/food-order.json +2 -2
  4. package/demo/data/flows/sample-flow.json +74 -125
  5. package/dist/static/svg/index.svg +1 -1
  6. package/dist/temba-components.js +1156 -619
  7. package/dist/temba-components.js.map +1 -1
  8. package/out-tsc/src/Icons.js +4 -1
  9. package/out-tsc/src/Icons.js.map +1 -1
  10. package/out-tsc/src/events.js.map +1 -1
  11. package/out-tsc/src/flow/CanvasMenu.js +200 -0
  12. package/out-tsc/src/flow/CanvasMenu.js.map +1 -0
  13. package/out-tsc/src/flow/CanvasNode.js +327 -19
  14. package/out-tsc/src/flow/CanvasNode.js.map +1 -1
  15. package/out-tsc/src/flow/Editor.js +562 -66
  16. package/out-tsc/src/flow/Editor.js.map +1 -1
  17. package/out-tsc/src/flow/NodeEditor.js +240 -93
  18. package/out-tsc/src/flow/NodeEditor.js.map +1 -1
  19. package/out-tsc/src/flow/NodeTypeSelector.js +499 -0
  20. package/out-tsc/src/flow/NodeTypeSelector.js.map +1 -0
  21. package/out-tsc/src/flow/actions/add_contact_groups.js +3 -3
  22. package/out-tsc/src/flow/actions/add_contact_groups.js.map +1 -1
  23. package/out-tsc/src/flow/actions/add_contact_urn.js +62 -4
  24. package/out-tsc/src/flow/actions/add_contact_urn.js.map +1 -1
  25. package/out-tsc/src/flow/actions/add_input_labels.js +3 -3
  26. package/out-tsc/src/flow/actions/add_input_labels.js.map +1 -1
  27. package/out-tsc/src/flow/actions/play_audio.js +2 -2
  28. package/out-tsc/src/flow/actions/play_audio.js.map +1 -1
  29. package/out-tsc/src/flow/actions/remove_contact_groups.js +6 -5
  30. package/out-tsc/src/flow/actions/remove_contact_groups.js.map +1 -1
  31. package/out-tsc/src/flow/actions/request_optin.js +2 -2
  32. package/out-tsc/src/flow/actions/request_optin.js.map +1 -1
  33. package/out-tsc/src/flow/actions/say_msg.js +2 -2
  34. package/out-tsc/src/flow/actions/say_msg.js.map +1 -1
  35. package/out-tsc/src/flow/actions/send_broadcast.js +76 -23
  36. package/out-tsc/src/flow/actions/send_broadcast.js.map +1 -1
  37. package/out-tsc/src/flow/actions/send_email.js +4 -5
  38. package/out-tsc/src/flow/actions/send_email.js.map +1 -1
  39. package/out-tsc/src/flow/actions/send_msg.js +9 -19
  40. package/out-tsc/src/flow/actions/send_msg.js.map +1 -1
  41. package/out-tsc/src/flow/actions/set_contact_channel.js +5 -9
  42. package/out-tsc/src/flow/actions/set_contact_channel.js.map +1 -1
  43. package/out-tsc/src/flow/actions/set_contact_field.js +19 -20
  44. package/out-tsc/src/flow/actions/set_contact_field.js.map +1 -1
  45. package/out-tsc/src/flow/actions/set_contact_language.js +2 -2
  46. package/out-tsc/src/flow/actions/set_contact_language.js.map +1 -1
  47. package/out-tsc/src/flow/actions/set_contact_name.js +2 -12
  48. package/out-tsc/src/flow/actions/set_contact_name.js.map +1 -1
  49. package/out-tsc/src/flow/actions/set_contact_status.js +2 -2
  50. package/out-tsc/src/flow/actions/set_contact_status.js.map +1 -1
  51. package/out-tsc/src/flow/actions/set_run_result.js +3 -3
  52. package/out-tsc/src/flow/actions/set_run_result.js.map +1 -1
  53. package/out-tsc/src/flow/actions/start_session.js +180 -6
  54. package/out-tsc/src/flow/actions/start_session.js.map +1 -1
  55. package/out-tsc/src/flow/config.js +11 -15
  56. package/out-tsc/src/flow/config.js.map +1 -1
  57. package/out-tsc/src/flow/currencies.js +45 -0
  58. package/out-tsc/src/flow/currencies.js.map +1 -0
  59. package/out-tsc/src/flow/nodes/shared-rules.js +257 -0
  60. package/out-tsc/src/flow/nodes/shared-rules.js.map +1 -0
  61. package/out-tsc/src/flow/nodes/shared.js +17 -0
  62. package/out-tsc/src/flow/nodes/shared.js.map +1 -0
  63. package/out-tsc/src/flow/nodes/split_by_airtime.js +205 -5
  64. package/out-tsc/src/flow/nodes/split_by_airtime.js.map +1 -1
  65. package/out-tsc/src/flow/nodes/split_by_contact_field.js +147 -3
  66. package/out-tsc/src/flow/nodes/split_by_contact_field.js.map +1 -1
  67. package/out-tsc/src/flow/nodes/split_by_expression.js +68 -2
  68. package/out-tsc/src/flow/nodes/split_by_expression.js.map +1 -1
  69. package/out-tsc/src/flow/nodes/split_by_groups.js +12 -9
  70. package/out-tsc/src/flow/nodes/split_by_groups.js.map +1 -1
  71. package/out-tsc/src/flow/nodes/split_by_intent.js +7 -0
  72. package/out-tsc/src/flow/nodes/split_by_intent.js.map +1 -0
  73. package/out-tsc/src/flow/nodes/split_by_llm.js +3 -2
  74. package/out-tsc/src/flow/nodes/split_by_llm.js.map +1 -1
  75. package/out-tsc/src/flow/nodes/split_by_llm_categorize.js +2 -2
  76. package/out-tsc/src/flow/nodes/split_by_llm_categorize.js.map +1 -1
  77. package/out-tsc/src/flow/nodes/split_by_random.js +3 -3
  78. package/out-tsc/src/flow/nodes/split_by_random.js.map +1 -1
  79. package/out-tsc/src/flow/nodes/split_by_resthook.js +108 -0
  80. package/out-tsc/src/flow/nodes/split_by_resthook.js.map +1 -0
  81. package/out-tsc/src/flow/nodes/split_by_run_result.js +206 -3
  82. package/out-tsc/src/flow/nodes/split_by_run_result.js.map +1 -1
  83. package/out-tsc/src/flow/nodes/split_by_scheme.js +153 -2
  84. package/out-tsc/src/flow/nodes/split_by_scheme.js.map +1 -1
  85. package/out-tsc/src/flow/nodes/split_by_subflow.js +6 -4
  86. package/out-tsc/src/flow/nodes/split_by_subflow.js.map +1 -1
  87. package/out-tsc/src/flow/nodes/split_by_ticket.js +3 -2
  88. package/out-tsc/src/flow/nodes/split_by_ticket.js.map +1 -1
  89. package/out-tsc/src/flow/nodes/split_by_webhook.js +3 -2
  90. package/out-tsc/src/flow/nodes/split_by_webhook.js.map +1 -1
  91. package/out-tsc/src/flow/nodes/wait_for_audio.js +2 -2
  92. package/out-tsc/src/flow/nodes/wait_for_audio.js.map +1 -1
  93. package/out-tsc/src/flow/nodes/wait_for_digits.js +2 -2
  94. package/out-tsc/src/flow/nodes/wait_for_digits.js.map +1 -1
  95. package/out-tsc/src/flow/nodes/wait_for_image.js +2 -2
  96. package/out-tsc/src/flow/nodes/wait_for_image.js.map +1 -1
  97. package/out-tsc/src/flow/nodes/wait_for_location.js +2 -2
  98. package/out-tsc/src/flow/nodes/wait_for_location.js.map +1 -1
  99. package/out-tsc/src/flow/nodes/wait_for_menu.js +2 -2
  100. package/out-tsc/src/flow/nodes/wait_for_menu.js.map +1 -1
  101. package/out-tsc/src/flow/nodes/wait_for_response.js +32 -567
  102. package/out-tsc/src/flow/nodes/wait_for_response.js.map +1 -1
  103. package/out-tsc/src/flow/nodes/wait_for_video.js +2 -2
  104. package/out-tsc/src/flow/nodes/wait_for_video.js.map +1 -1
  105. package/out-tsc/src/flow/types.js +71 -12
  106. package/out-tsc/src/flow/types.js.map +1 -1
  107. package/out-tsc/src/flow/utils.js +101 -14
  108. package/out-tsc/src/flow/utils.js.map +1 -1
  109. package/out-tsc/src/form/ContactSearch.js +1 -1
  110. package/out-tsc/src/form/ContactSearch.js.map +1 -1
  111. package/out-tsc/src/form/FieldRenderer.js +2 -4
  112. package/out-tsc/src/form/FieldRenderer.js.map +1 -1
  113. package/out-tsc/src/interfaces.js +3 -0
  114. package/out-tsc/src/interfaces.js.map +1 -1
  115. package/out-tsc/src/list/SortableList.js +98 -33
  116. package/out-tsc/src/list/SortableList.js.map +1 -1
  117. package/out-tsc/src/live/ContactChat.js +15 -18
  118. package/out-tsc/src/live/ContactChat.js.map +1 -1
  119. package/out-tsc/src/store/AppState.js +53 -0
  120. package/out-tsc/src/store/AppState.js.map +1 -1
  121. package/out-tsc/src/utils.js +254 -13
  122. package/out-tsc/src/utils.js.map +1 -1
  123. package/out-tsc/temba-modules.js +4 -0
  124. package/out-tsc/temba-modules.js.map +1 -1
  125. package/out-tsc/test/ActionHelper.js +3 -3
  126. package/out-tsc/test/ActionHelper.js.map +1 -1
  127. package/out-tsc/test/NodeHelper.js +6 -3
  128. package/out-tsc/test/NodeHelper.js.map +1 -1
  129. package/out-tsc/test/actions/add_contact_urn.test.js +202 -0
  130. package/out-tsc/test/actions/add_contact_urn.test.js.map +1 -0
  131. package/out-tsc/test/actions/send_broadcast.test.js +148 -0
  132. package/out-tsc/test/actions/send_broadcast.test.js.map +1 -0
  133. package/out-tsc/test/actions/send_email.test.js +17 -23
  134. package/out-tsc/test/actions/send_email.test.js.map +1 -1
  135. package/out-tsc/test/actions/send_msg.test.js +33 -15
  136. package/out-tsc/test/actions/send_msg.test.js.map +1 -1
  137. package/out-tsc/test/actions/start_session.test.js +116 -0
  138. package/out-tsc/test/actions/start_session.test.js.map +1 -0
  139. package/out-tsc/test/nodes/split_by_airtime.test.js +604 -0
  140. package/out-tsc/test/nodes/split_by_airtime.test.js.map +1 -0
  141. package/out-tsc/test/nodes/split_by_contact_field.test.js +387 -0
  142. package/out-tsc/test/nodes/split_by_contact_field.test.js.map +1 -0
  143. package/out-tsc/test/nodes/split_by_expression.test.js +614 -0
  144. package/out-tsc/test/nodes/split_by_expression.test.js.map +1 -0
  145. package/out-tsc/test/nodes/split_by_random.test.js +3 -3
  146. package/out-tsc/test/nodes/split_by_random.test.js.map +1 -1
  147. package/out-tsc/test/nodes/split_by_resthook.test.js +337 -0
  148. package/out-tsc/test/nodes/split_by_resthook.test.js.map +1 -0
  149. package/out-tsc/test/nodes/split_by_run_result.test.js +920 -0
  150. package/out-tsc/test/nodes/split_by_run_result.test.js.map +1 -0
  151. package/out-tsc/test/nodes/split_by_scheme.test.js +399 -0
  152. package/out-tsc/test/nodes/split_by_scheme.test.js.map +1 -0
  153. package/out-tsc/test/nodes/split_by_subflow.test.js +333 -0
  154. package/out-tsc/test/nodes/split_by_subflow.test.js.map +1 -0
  155. package/out-tsc/test/nodes/wait_for_digits.test.js +2 -2
  156. package/out-tsc/test/nodes/wait_for_digits.test.js.map +1 -1
  157. package/out-tsc/test/nodes/wait_for_response.test.js +2 -1
  158. package/out-tsc/test/nodes/wait_for_response.test.js.map +1 -1
  159. package/out-tsc/test/temba-action-drag-between-nodes.test.js +252 -0
  160. package/out-tsc/test/temba-action-drag-between-nodes.test.js.map +1 -0
  161. package/out-tsc/test/temba-canvas-menu.test.js +122 -0
  162. package/out-tsc/test/temba-canvas-menu.test.js.map +1 -0
  163. package/out-tsc/test/temba-flow-editor-node.test.js +85 -2
  164. package/out-tsc/test/temba-flow-editor-node.test.js.map +1 -1
  165. package/out-tsc/test/temba-flow-editor.test.js +7 -8
  166. package/out-tsc/test/temba-flow-editor.test.js.map +1 -1
  167. package/out-tsc/test/temba-node-editor.test.js +3 -1
  168. package/out-tsc/test/temba-node-editor.test.js.map +1 -1
  169. package/out-tsc/test/temba-node-type-selector.test.js +115 -0
  170. package/out-tsc/test/temba-node-type-selector.test.js.map +1 -0
  171. package/out-tsc/test/temba-omnibox.test.js +2 -1
  172. package/out-tsc/test/temba-omnibox.test.js.map +1 -1
  173. package/out-tsc/test/temba-sortable-list.test.js +51 -0
  174. package/out-tsc/test/temba-sortable-list.test.js.map +1 -1
  175. package/out-tsc/test/temba-utils-index.test.js +1 -27
  176. package/out-tsc/test/temba-utils-index.test.js.map +1 -1
  177. package/out-tsc/test/utils.test.js +2 -0
  178. package/out-tsc/test/utils.test.js.map +1 -1
  179. package/package.json +2 -1
  180. package/screenshots/truth/actions/add_contact_groups/editor/descriptive-group-names.png +0 -0
  181. package/screenshots/truth/actions/add_contact_groups/editor/long-group-names.png +0 -0
  182. package/screenshots/truth/actions/add_contact_groups/editor/many-groups.png +0 -0
  183. package/screenshots/truth/actions/add_contact_groups/editor/multiple-groups.png +0 -0
  184. package/screenshots/truth/actions/add_contact_groups/editor/single-group.png +0 -0
  185. package/screenshots/truth/actions/add_contact_groups/render/descriptive-group-names.png +0 -0
  186. package/screenshots/truth/actions/add_contact_groups/render/long-group-names.png +0 -0
  187. package/screenshots/truth/actions/add_contact_groups/render/many-groups.png +0 -0
  188. package/screenshots/truth/actions/add_contact_groups/render/multiple-groups.png +0 -0
  189. package/screenshots/truth/actions/add_contact_groups/render/single-group.png +0 -0
  190. package/screenshots/truth/actions/add_contact_urn/editor/expression-facebook.png +0 -0
  191. package/screenshots/truth/actions/add_contact_urn/editor/expression-phone.png +0 -0
  192. package/screenshots/truth/actions/add_contact_urn/editor/facebook-id.png +0 -0
  193. package/screenshots/truth/actions/add_contact_urn/editor/instagram-handle.png +0 -0
  194. package/screenshots/truth/actions/add_contact_urn/editor/line-id.png +0 -0
  195. package/screenshots/truth/actions/add_contact_urn/editor/phone-number.png +0 -0
  196. package/screenshots/truth/actions/add_contact_urn/editor/telegram-id.png +0 -0
  197. package/screenshots/truth/actions/add_contact_urn/editor/viber-id.png +0 -0
  198. package/screenshots/truth/actions/add_contact_urn/editor/wechat-id.png +0 -0
  199. package/screenshots/truth/actions/add_contact_urn/editor/whatsapp.png +0 -0
  200. package/screenshots/truth/actions/add_contact_urn/render/expression-facebook.png +0 -0
  201. package/screenshots/truth/actions/add_contact_urn/render/expression-phone.png +0 -0
  202. package/screenshots/truth/actions/add_contact_urn/render/facebook-id.png +0 -0
  203. package/screenshots/truth/actions/add_contact_urn/render/instagram-handle.png +0 -0
  204. package/screenshots/truth/actions/add_contact_urn/render/line-id.png +0 -0
  205. package/screenshots/truth/actions/add_contact_urn/render/phone-number.png +0 -0
  206. package/screenshots/truth/actions/add_contact_urn/render/telegram-id.png +0 -0
  207. package/screenshots/truth/actions/add_contact_urn/render/viber-id.png +0 -0
  208. package/screenshots/truth/actions/add_contact_urn/render/wechat-id.png +0 -0
  209. package/screenshots/truth/actions/add_contact_urn/render/whatsapp.png +0 -0
  210. package/screenshots/truth/actions/remove_contact_groups/editor/cleanup-groups.png +0 -0
  211. package/screenshots/truth/actions/remove_contact_groups/editor/long-descriptive-group-names.png +0 -0
  212. package/screenshots/truth/actions/remove_contact_groups/editor/many-groups.png +0 -0
  213. package/screenshots/truth/actions/remove_contact_groups/editor/multiple-groups.png +0 -0
  214. package/screenshots/truth/actions/remove_contact_groups/editor/remove-from-all-groups.png +0 -0
  215. package/screenshots/truth/actions/remove_contact_groups/editor/single-group.png +0 -0
  216. package/screenshots/truth/actions/remove_contact_groups/render/cleanup-groups.png +0 -0
  217. package/screenshots/truth/actions/remove_contact_groups/render/long-descriptive-group-names.png +0 -0
  218. package/screenshots/truth/actions/remove_contact_groups/render/many-groups.png +0 -0
  219. package/screenshots/truth/actions/remove_contact_groups/render/multiple-groups.png +0 -0
  220. package/screenshots/truth/actions/remove_contact_groups/render/remove-from-all-groups.png +0 -0
  221. package/screenshots/truth/actions/remove_contact_groups/render/single-group.png +0 -0
  222. package/screenshots/truth/actions/send_broadcast/editor/contacts-only.png +0 -0
  223. package/screenshots/truth/actions/send_broadcast/editor/groups-and-contacts.png +0 -0
  224. package/screenshots/truth/actions/send_broadcast/editor/groups-only.png +0 -0
  225. package/screenshots/truth/actions/send_broadcast/editor/many-groups.png +0 -0
  226. package/screenshots/truth/actions/send_broadcast/editor/multiline-text.png +0 -0
  227. package/screenshots/truth/actions/send_broadcast/editor/with-attachments.png +0 -0
  228. package/screenshots/truth/actions/send_broadcast/render/contacts-only.png +0 -0
  229. package/screenshots/truth/actions/send_broadcast/render/groups-and-contacts.png +0 -0
  230. package/screenshots/truth/actions/send_broadcast/render/groups-only.png +0 -0
  231. package/screenshots/truth/actions/send_broadcast/render/many-groups.png +0 -0
  232. package/screenshots/truth/actions/send_broadcast/render/multiline-text.png +0 -0
  233. package/screenshots/truth/actions/send_broadcast/render/with-attachments.png +0 -0
  234. package/screenshots/truth/actions/send_email/editor/complex-business-email.png +0 -0
  235. package/screenshots/truth/actions/send_email/editor/empty-body.png +0 -0
  236. package/screenshots/truth/actions/send_email/editor/empty-subject.png +0 -0
  237. package/screenshots/truth/actions/send_email/editor/long-subject.png +0 -0
  238. package/screenshots/truth/actions/send_email/editor/multiline-body.png +0 -0
  239. package/screenshots/truth/actions/send_email/editor/multiple-recipients.png +0 -0
  240. package/screenshots/truth/actions/send_email/editor/simple-email.png +0 -0
  241. package/screenshots/truth/actions/send_email/editor/with-expressions.png +0 -0
  242. package/screenshots/truth/actions/send_email/render/complex-business-email.png +0 -0
  243. package/screenshots/truth/actions/send_email/render/empty-body.png +0 -0
  244. package/screenshots/truth/actions/send_email/render/empty-subject.png +0 -0
  245. package/screenshots/truth/actions/send_email/render/long-subject.png +0 -0
  246. package/screenshots/truth/actions/send_email/render/multiline-body.png +0 -0
  247. package/screenshots/truth/actions/send_email/render/multiple-recipients.png +0 -0
  248. package/screenshots/truth/actions/send_email/render/simple-email.png +0 -0
  249. package/screenshots/truth/actions/send_email/render/with-expressions.png +0 -0
  250. package/screenshots/truth/actions/send_msg/editor/long-quick-replies.png +0 -0
  251. package/screenshots/truth/actions/send_msg/editor/multiline-text-with-replies.png +0 -0
  252. package/screenshots/truth/actions/send_msg/editor/simple-text.png +0 -0
  253. package/screenshots/truth/actions/send_msg/editor/text-with-linebreaks.png +0 -0
  254. package/screenshots/truth/actions/send_msg/editor/text-with-many-quick-replies.png +0 -0
  255. package/screenshots/truth/actions/send_msg/editor/text-with-quick-replies.png +0 -0
  256. package/screenshots/truth/actions/send_msg/editor/text-without-quick-replies.png +0 -0
  257. package/screenshots/truth/actions/send_msg/render/long-quick-replies.png +0 -0
  258. package/screenshots/truth/actions/send_msg/render/multiline-text-with-replies.png +0 -0
  259. package/screenshots/truth/actions/send_msg/render/simple-text.png +0 -0
  260. package/screenshots/truth/actions/send_msg/render/text-with-linebreaks.png +0 -0
  261. package/screenshots/truth/actions/send_msg/render/text-with-many-quick-replies.png +0 -0
  262. package/screenshots/truth/actions/send_msg/render/text-with-quick-replies.png +0 -0
  263. package/screenshots/truth/actions/send_msg/render/text-without-quick-replies.png +0 -0
  264. package/screenshots/truth/actions/start_session/editor/contact-query.png +0 -0
  265. package/screenshots/truth/actions/start_session/editor/contacts-only.png +0 -0
  266. package/screenshots/truth/actions/start_session/editor/create-contact.png +0 -0
  267. package/screenshots/truth/actions/start_session/editor/groups-and-contacts.png +0 -0
  268. package/screenshots/truth/actions/start_session/editor/groups-only.png +0 -0
  269. package/screenshots/truth/actions/start_session/editor/many-recipients.png +0 -0
  270. package/screenshots/truth/actions/start_session/render/contact-query.png +0 -0
  271. package/screenshots/truth/actions/start_session/render/contacts-only.png +0 -0
  272. package/screenshots/truth/actions/start_session/render/create-contact.png +0 -0
  273. package/screenshots/truth/actions/start_session/render/groups-and-contacts.png +0 -0
  274. package/screenshots/truth/actions/start_session/render/groups-only.png +0 -0
  275. package/screenshots/truth/actions/start_session/render/many-recipients.png +0 -0
  276. package/screenshots/truth/canvas-menu/open.png +0 -0
  277. package/screenshots/truth/editor/router.png +0 -0
  278. package/screenshots/truth/editor/wait.png +0 -0
  279. package/screenshots/truth/list/fields-dragging.png +0 -0
  280. package/screenshots/truth/list/sortable-dragging.png +0 -0
  281. package/screenshots/truth/node-type-selector/action-mode.png +0 -0
  282. package/screenshots/truth/node-type-selector/split-mode.png +0 -0
  283. package/screenshots/truth/nodes/split_by_llm/editor/information-extraction.png +0 -0
  284. package/screenshots/truth/nodes/split_by_llm/editor/sentiment-analysis.png +0 -0
  285. package/screenshots/truth/nodes/split_by_llm/editor/summarization.png +0 -0
  286. package/screenshots/truth/nodes/split_by_llm/editor/translation-task.png +0 -0
  287. package/screenshots/truth/nodes/split_by_llm/render/information-extraction.png +0 -0
  288. package/screenshots/truth/nodes/split_by_llm/render/sentiment-analysis.png +0 -0
  289. package/screenshots/truth/nodes/split_by_llm/render/summarization.png +0 -0
  290. package/screenshots/truth/nodes/split_by_llm/render/translation-task.png +0 -0
  291. package/screenshots/truth/nodes/split_by_llm_categorize/editor/basic-categorization.png +0 -0
  292. package/screenshots/truth/nodes/split_by_llm_categorize/editor/custom-input-and-result-name.png +0 -0
  293. package/screenshots/truth/nodes/split_by_llm_categorize/editor/feedback-categorization.png +0 -0
  294. package/screenshots/truth/nodes/split_by_llm_categorize/editor/many-categories.png +0 -0
  295. package/screenshots/truth/nodes/split_by_llm_categorize/editor/minimal-categories.png +0 -0
  296. package/screenshots/truth/nodes/split_by_llm_categorize/render/basic-categorization.png +0 -0
  297. package/screenshots/truth/nodes/split_by_llm_categorize/render/custom-input-and-result-name.png +0 -0
  298. package/screenshots/truth/nodes/split_by_llm_categorize/render/feedback-categorization.png +0 -0
  299. package/screenshots/truth/nodes/split_by_llm_categorize/render/many-categories.png +0 -0
  300. package/screenshots/truth/nodes/split_by_llm_categorize/render/minimal-categories.png +0 -0
  301. package/screenshots/truth/nodes/split_by_random/editor/ab-test-multiple-variants.png +0 -0
  302. package/screenshots/truth/nodes/split_by_random/editor/sampling-split.png +0 -0
  303. package/screenshots/truth/nodes/split_by_random/editor/three-way-split.png +0 -0
  304. package/screenshots/truth/nodes/split_by_random/editor/two-bucket-split.png +0 -0
  305. package/screenshots/truth/nodes/split_by_random/render/ab-test-multiple-variants.png +0 -0
  306. package/screenshots/truth/nodes/split_by_random/render/sampling-split.png +0 -0
  307. package/screenshots/truth/nodes/split_by_random/render/three-way-split.png +0 -0
  308. package/screenshots/truth/nodes/split_by_random/render/two-bucket-split.png +0 -0
  309. package/screenshots/truth/nodes/wait_for_digits/editor/basic-digits-wait.png +0 -0
  310. package/screenshots/truth/nodes/wait_for_digits/editor/phone-number-collection.png +0 -0
  311. package/screenshots/truth/nodes/wait_for_digits/editor/single-digit-with-timeout.png +0 -0
  312. package/screenshots/truth/nodes/wait_for_digits/editor/verification-code.png +0 -0
  313. package/screenshots/truth/nodes/wait_for_digits/render/basic-digits-wait.png +0 -0
  314. package/screenshots/truth/nodes/wait_for_digits/render/phone-number-collection.png +0 -0
  315. package/screenshots/truth/nodes/wait_for_digits/render/single-digit-with-timeout.png +0 -0
  316. package/screenshots/truth/nodes/wait_for_digits/render/verification-code.png +0 -0
  317. package/screenshots/truth/nodes/wait_for_response/editor/basic-wait.png +0 -0
  318. package/screenshots/truth/nodes/wait_for_response/editor/custom-result-name.png +0 -0
  319. package/screenshots/truth/nodes/wait_for_response/editor/no-timeout.png +0 -0
  320. package/screenshots/truth/nodes/wait_for_response/editor/short-timeout.png +0 -0
  321. package/screenshots/truth/nodes/wait_for_response/render/basic-wait.png +0 -0
  322. package/screenshots/truth/nodes/wait_for_response/render/custom-result-name.png +0 -0
  323. package/screenshots/truth/nodes/wait_for_response/render/no-timeout.png +0 -0
  324. package/screenshots/truth/nodes/wait_for_response/render/short-timeout.png +0 -0
  325. package/src/Icons.ts +4 -1
  326. package/src/events.ts +2 -6
  327. package/src/flow/CanvasMenu.ts +217 -0
  328. package/src/flow/CanvasNode.ts +408 -10
  329. package/src/flow/Editor.ts +683 -44
  330. package/src/flow/NodeEditor.ts +304 -125
  331. package/src/flow/NodeTypeSelector.ts +592 -0
  332. package/src/flow/actions/add_contact_groups.ts +4 -4
  333. package/src/flow/actions/add_contact_urn.ts +76 -4
  334. package/src/flow/actions/add_input_labels.ts +4 -4
  335. package/src/flow/actions/play_audio.ts +2 -2
  336. package/src/flow/actions/remove_contact_groups.ts +14 -6
  337. package/src/flow/actions/request_optin.ts +2 -2
  338. package/src/flow/actions/say_msg.ts +2 -2
  339. package/src/flow/actions/send_broadcast.ts +85 -23
  340. package/src/flow/actions/send_email.ts +10 -6
  341. package/src/flow/actions/send_msg.ts +22 -32
  342. package/src/flow/actions/set_contact_channel.ts +5 -11
  343. package/src/flow/actions/set_contact_field.ts +20 -25
  344. package/src/flow/actions/set_contact_language.ts +9 -4
  345. package/src/flow/actions/set_contact_name.ts +3 -15
  346. package/src/flow/actions/set_contact_status.ts +3 -3
  347. package/src/flow/actions/set_run_result.ts +4 -4
  348. package/src/flow/actions/start_session.ts +208 -6
  349. package/src/flow/config.ts +13 -15
  350. package/src/flow/currencies.ts +51 -0
  351. package/src/flow/nodes/shared-rules.ts +301 -0
  352. package/src/flow/nodes/shared.ts +18 -0
  353. package/src/flow/nodes/split_by_airtime.ts +238 -5
  354. package/src/flow/nodes/split_by_contact_field.ts +185 -3
  355. package/src/flow/nodes/split_by_expression.ts +94 -2
  356. package/src/flow/nodes/split_by_groups.ts +15 -10
  357. package/src/flow/nodes/split_by_intent.ts +7 -0
  358. package/src/flow/nodes/split_by_llm.ts +4 -3
  359. package/src/flow/nodes/split_by_llm_categorize.ts +4 -4
  360. package/src/flow/nodes/split_by_random.ts +5 -5
  361. package/src/flow/nodes/split_by_resthook.ts +130 -0
  362. package/src/flow/nodes/split_by_run_result.ts +249 -3
  363. package/src/flow/nodes/split_by_scheme.ts +192 -2
  364. package/src/flow/nodes/split_by_subflow.ts +6 -4
  365. package/src/flow/nodes/split_by_ticket.ts +4 -3
  366. package/src/flow/nodes/split_by_webhook.ts +6 -5
  367. package/src/flow/nodes/wait_for_audio.ts +2 -2
  368. package/src/flow/nodes/wait_for_digits.ts +2 -2
  369. package/src/flow/nodes/wait_for_image.ts +2 -2
  370. package/src/flow/nodes/wait_for_location.ts +2 -2
  371. package/src/flow/nodes/wait_for_menu.ts +2 -2
  372. package/src/flow/nodes/wait_for_response.ts +48 -679
  373. package/src/flow/nodes/wait_for_video.ts +2 -2
  374. package/src/flow/types.ts +109 -23
  375. package/src/flow/utils.ts +108 -14
  376. package/src/form/ContactSearch.ts +1 -1
  377. package/src/form/FieldRenderer.ts +2 -4
  378. package/src/interfaces.ts +3 -0
  379. package/src/list/SortableList.ts +109 -34
  380. package/src/live/ContactChat.ts +15 -18
  381. package/src/store/AppState.ts +69 -0
  382. package/src/store/flow-definition.d.ts +2 -5
  383. package/src/utils.ts +332 -12
  384. package/static/api/channels.json +46 -0
  385. package/static/api/resthooks.json +31 -0
  386. package/static/svg/index.svg +1 -1
  387. package/static/svg/work/traced/lightning-02.svg +1 -0
  388. package/static/svg/work/used/lightning-02.svg +3 -0
  389. package/temba-modules.ts +4 -0
  390. package/test/ActionHelper.ts +3 -3
  391. package/test/NodeHelper.ts +6 -3
  392. package/test/actions/add_contact_urn.test.ts +287 -0
  393. package/test/actions/send_broadcast.test.ts +190 -0
  394. package/test/actions/send_email.test.ts +17 -23
  395. package/test/actions/send_msg.test.ts +39 -15
  396. package/test/actions/start_session.test.ts +151 -0
  397. package/test/nodes/split_by_airtime.test.ts +673 -0
  398. package/test/nodes/split_by_contact_field.test.ts +451 -0
  399. package/test/nodes/split_by_expression.test.ts +751 -0
  400. package/test/nodes/split_by_random.test.ts +3 -3
  401. package/test/nodes/split_by_resthook.test.ts +398 -0
  402. package/test/nodes/split_by_run_result.test.ts +1109 -0
  403. package/test/nodes/split_by_scheme.test.ts +486 -0
  404. package/test/nodes/split_by_subflow.test.ts +381 -0
  405. package/test/nodes/wait_for_digits.test.ts +2 -2
  406. package/test/nodes/wait_for_response.test.ts +2 -1
  407. package/test/temba-action-drag-between-nodes.test.ts +301 -0
  408. package/test/temba-canvas-menu.test.ts +156 -0
  409. package/test/temba-flow-editor-node.test.ts +102 -2
  410. package/test/temba-flow-editor.test.ts +7 -8
  411. package/test/temba-node-editor.test.ts +3 -1
  412. package/test/temba-node-type-selector.test.ts +152 -0
  413. package/test/temba-omnibox.test.ts +2 -1
  414. package/test/temba-sortable-list.test.ts +69 -0
  415. package/test/temba-utils-index.test.ts +0 -35
  416. package/test/utils.test.ts +2 -0
  417. package/test-assets/contacts/history.json +14 -20
  418. package/web-dev-server.config.mjs +3 -1
  419. package/out-tsc/src/flow/actions/call_classifier.js +0 -11
  420. package/out-tsc/src/flow/actions/call_classifier.js.map +0 -1
  421. package/out-tsc/src/flow/actions/call_resthook.js +0 -11
  422. package/out-tsc/src/flow/actions/call_resthook.js.map +0 -1
  423. package/out-tsc/src/flow/actions/split_by_expression_example.js +0 -77
  424. package/out-tsc/src/flow/actions/split_by_expression_example.js.map +0 -1
  425. package/out-tsc/src/flow/actions/transfer_airtime.js +0 -11
  426. package/out-tsc/src/flow/actions/transfer_airtime.js.map +0 -1
  427. package/src/flow/actions/call_classifier.ts +0 -12
  428. package/src/flow/actions/call_resthook.ts +0 -12
  429. package/src/flow/actions/split_by_expression_example.ts +0 -88
  430. package/src/flow/actions/transfer_airtime.ts +0 -12
@@ -0,0 +1,673 @@
1
+ import { expect } from '@open-wc/testing';
2
+ import { split_by_airtime } from '../../src/flow/nodes/split_by_airtime';
3
+ import { Node, TransferAirtime } from '../../src/store/flow-definition';
4
+ import { NodeTest } from '../NodeHelper';
5
+
6
+ /**
7
+ * Test suite for the split_by_airtime node configuration.
8
+ */
9
+ describe('split_by_airtime node config', () => {
10
+ const helper = new NodeTest(split_by_airtime, 'split_by_airtime');
11
+
12
+ describe('basic properties', () => {
13
+ helper.testBasicProperties();
14
+
15
+ it('has correct name', () => {
16
+ expect(split_by_airtime.name).to.equal('Send Airtime');
17
+ });
18
+
19
+ it('has correct type', () => {
20
+ expect(split_by_airtime.type).to.equal('split_by_airtime');
21
+ });
22
+
23
+ it('should show as action', () => {
24
+ expect(split_by_airtime.showAsAction).to.be.true;
25
+ });
26
+ });
27
+
28
+ describe('toFormData', () => {
29
+ it('should transform node with single currency to form data correctly', () => {
30
+ const node: Node = {
31
+ uuid: 'test-node-uuid',
32
+ actions: [
33
+ {
34
+ type: 'transfer_airtime',
35
+ uuid: 'action-uuid',
36
+ amounts: {
37
+ USD: 10
38
+ }
39
+ } as TransferAirtime
40
+ ],
41
+ router: {
42
+ type: 'switch',
43
+ operand: '@locals._new_transfer',
44
+ cases: [
45
+ {
46
+ uuid: 'case-1',
47
+ type: 'has_text',
48
+ arguments: [],
49
+ category_uuid: 'cat-success'
50
+ }
51
+ ],
52
+ categories: [
53
+ { uuid: 'cat-success', name: 'Success', exit_uuid: 'exit-success' },
54
+ { uuid: 'cat-failure', name: 'Failure', exit_uuid: 'exit-failure' }
55
+ ],
56
+ default_category_uuid: 'cat-failure'
57
+ },
58
+ exits: [
59
+ { uuid: 'exit-success', destination_uuid: null },
60
+ { uuid: 'exit-failure', destination_uuid: null }
61
+ ]
62
+ };
63
+
64
+ const formData = split_by_airtime.toFormData!(node);
65
+
66
+ expect(formData.uuid).to.equal('test-node-uuid');
67
+ expect(formData.amounts).to.have.lengthOf(1);
68
+ expect(formData.amounts[0].currency[0].value).to.equal('USD');
69
+ expect(formData.amounts[0].currency[0].name).to.equal('US Dollar (USD)');
70
+ expect(formData.amounts[0].amount).to.equal('10');
71
+ expect(formData.result_name).to.equal('');
72
+ });
73
+
74
+ it('should transform node with multiple currencies to form data correctly', () => {
75
+ const node: Node = {
76
+ uuid: 'test-node-uuid',
77
+ actions: [
78
+ {
79
+ type: 'transfer_airtime',
80
+ uuid: 'action-uuid',
81
+ amounts: {
82
+ USD: 10,
83
+ EUR: 15,
84
+ GBP: 8
85
+ }
86
+ } as TransferAirtime
87
+ ],
88
+ router: {
89
+ type: 'switch',
90
+ operand: '@locals._new_transfer',
91
+ cases: [
92
+ {
93
+ uuid: 'case-1',
94
+ type: 'has_text',
95
+ arguments: [],
96
+ category_uuid: 'cat-success'
97
+ }
98
+ ],
99
+ categories: [
100
+ { uuid: 'cat-success', name: 'Success', exit_uuid: 'exit-success' },
101
+ { uuid: 'cat-failure', name: 'Failure', exit_uuid: 'exit-failure' }
102
+ ],
103
+ default_category_uuid: 'cat-failure'
104
+ },
105
+ exits: [
106
+ { uuid: 'exit-success', destination_uuid: null },
107
+ { uuid: 'exit-failure', destination_uuid: null }
108
+ ]
109
+ };
110
+
111
+ const formData = split_by_airtime.toFormData!(node);
112
+
113
+ expect(formData.uuid).to.equal('test-node-uuid');
114
+ expect(formData.amounts).to.have.lengthOf(3);
115
+
116
+ // Check currencies are present (order not guaranteed in object iteration)
117
+ const currencies = formData.amounts.map((a: any) => a.currency[0].value);
118
+ expect(currencies).to.include('USD');
119
+ expect(currencies).to.include('EUR');
120
+ expect(currencies).to.include('GBP');
121
+ });
122
+
123
+ it('should handle result_name in toFormData', () => {
124
+ const node: Node = {
125
+ uuid: 'test-node-uuid',
126
+ actions: [
127
+ {
128
+ type: 'transfer_airtime',
129
+ uuid: 'action-uuid',
130
+ amounts: {
131
+ USD: 10
132
+ }
133
+ } as TransferAirtime
134
+ ],
135
+ router: {
136
+ type: 'switch',
137
+ operand: '@locals._new_transfer',
138
+ result_name: 'airtime_result',
139
+ cases: [
140
+ {
141
+ uuid: 'case-1',
142
+ type: 'has_text',
143
+ arguments: [],
144
+ category_uuid: 'cat-success'
145
+ }
146
+ ],
147
+ categories: [
148
+ { uuid: 'cat-success', name: 'Success', exit_uuid: 'exit-success' },
149
+ { uuid: 'cat-failure', name: 'Failure', exit_uuid: 'exit-failure' }
150
+ ],
151
+ default_category_uuid: 'cat-failure'
152
+ },
153
+ exits: [
154
+ { uuid: 'exit-success', destination_uuid: null },
155
+ { uuid: 'exit-failure', destination_uuid: null }
156
+ ]
157
+ };
158
+
159
+ const formData = split_by_airtime.toFormData!(node);
160
+ expect(formData.result_name).to.equal('airtime_result');
161
+ });
162
+
163
+ it('should handle empty amounts', () => {
164
+ const node: Node = {
165
+ uuid: 'test-node-uuid',
166
+ actions: [
167
+ {
168
+ type: 'transfer_airtime',
169
+ uuid: 'action-uuid',
170
+ amounts: {}
171
+ } as TransferAirtime
172
+ ],
173
+ router: {
174
+ type: 'switch',
175
+ operand: '@locals._new_transfer',
176
+ cases: [],
177
+ categories: [
178
+ { uuid: 'cat-failure', name: 'Failure', exit_uuid: 'exit-failure' }
179
+ ],
180
+ default_category_uuid: 'cat-failure'
181
+ },
182
+ exits: [{ uuid: 'exit-failure', destination_uuid: null }]
183
+ };
184
+
185
+ const formData = split_by_airtime.toFormData!(node);
186
+ expect(formData.amounts).to.have.lengthOf(0);
187
+ });
188
+ });
189
+
190
+ describe('fromFormData', () => {
191
+ it('should create node with single currency from form data', () => {
192
+ const originalNode: Node = {
193
+ uuid: 'test-node-uuid',
194
+ actions: [],
195
+ exits: []
196
+ };
197
+
198
+ const formData = {
199
+ uuid: 'test-node-uuid',
200
+ amounts: [
201
+ {
202
+ currency: [{ value: 'USD', name: 'US Dollar (USD)' }],
203
+ amount: '10'
204
+ }
205
+ ],
206
+ result_name: ''
207
+ };
208
+
209
+ const node = split_by_airtime.fromFormData!(formData, originalNode);
210
+
211
+ expect(node.uuid).to.equal('test-node-uuid');
212
+ expect(node.actions).to.have.lengthOf(1);
213
+
214
+ const action: any = node.actions![0];
215
+ expect(action.type).to.equal('transfer_airtime');
216
+ expect(action.amounts).to.deep.equal({ USD: 10 });
217
+
218
+ expect(node.router?.type).to.equal('switch');
219
+ expect(node.router?.categories).to.have.lengthOf(2);
220
+ expect(node.router?.categories![0].name).to.equal('Success');
221
+ expect(node.router?.categories![1].name).to.equal('Failure');
222
+ expect(node.exits).to.have.lengthOf(2);
223
+ });
224
+
225
+ it('should create node with multiple currencies from form data', () => {
226
+ const originalNode: Node = {
227
+ uuid: 'test-node-uuid',
228
+ actions: [],
229
+ exits: []
230
+ };
231
+
232
+ const formData = {
233
+ uuid: 'test-node-uuid',
234
+ amounts: [
235
+ {
236
+ currency: [{ value: 'USD', name: 'US Dollar (USD)' }],
237
+ amount: '10'
238
+ },
239
+ {
240
+ currency: [{ value: 'EUR', name: 'Euro (EUR)' }],
241
+ amount: '15.5'
242
+ },
243
+ {
244
+ currency: [{ value: 'GBP', name: 'Pound Sterling (GBP)' }],
245
+ amount: '8'
246
+ }
247
+ ],
248
+ result_name: ''
249
+ };
250
+
251
+ const node = split_by_airtime.fromFormData!(formData, originalNode);
252
+
253
+ expect(node.actions).to.have.lengthOf(1);
254
+
255
+ const action: any = node.actions![0];
256
+ expect(action.type).to.equal('transfer_airtime');
257
+ expect(action.amounts).to.deep.equal({
258
+ USD: 10,
259
+ EUR: 15.5,
260
+ GBP: 8
261
+ });
262
+ });
263
+
264
+ it('should handle result_name in fromFormData', () => {
265
+ const originalNode: Node = {
266
+ uuid: 'test-node-uuid',
267
+ actions: [],
268
+ exits: []
269
+ };
270
+
271
+ const formData = {
272
+ uuid: 'test-node-uuid',
273
+ amounts: [
274
+ {
275
+ currency: [{ value: 'USD', name: 'US Dollar (USD)' }],
276
+ amount: '10'
277
+ }
278
+ ],
279
+ result_name: 'airtime_result'
280
+ };
281
+
282
+ const node = split_by_airtime.fromFormData!(formData, originalNode);
283
+ expect(node.router?.result_name).to.equal('airtime_result');
284
+ });
285
+
286
+ it('should filter out empty amounts', () => {
287
+ const originalNode: Node = {
288
+ uuid: 'test-node-uuid',
289
+ actions: [],
290
+ exits: []
291
+ };
292
+
293
+ const formData = {
294
+ uuid: 'test-node-uuid',
295
+ amounts: [
296
+ {
297
+ currency: [{ value: 'USD', name: 'US Dollar (USD)' }],
298
+ amount: '10'
299
+ },
300
+ {
301
+ currency: [{ value: 'EUR', name: 'Euro (EUR)' }],
302
+ amount: ''
303
+ },
304
+ {
305
+ currency: null,
306
+ amount: '5'
307
+ }
308
+ ],
309
+ result_name: ''
310
+ };
311
+
312
+ const node = split_by_airtime.fromFormData!(formData, originalNode);
313
+
314
+ const action: any = node.actions![0];
315
+ expect(action.amounts).to.deep.equal({ USD: 10 });
316
+ });
317
+
318
+ it('should preserve existing action UUID', () => {
319
+ const originalNode: Node = {
320
+ uuid: 'test-node-uuid',
321
+ actions: [
322
+ {
323
+ type: 'transfer_airtime',
324
+ uuid: 'existing-action-uuid',
325
+ amounts: { USD: 5 }
326
+ } as TransferAirtime
327
+ ],
328
+ router: {
329
+ type: 'switch',
330
+ operand: '@locals._new_transfer',
331
+ cases: [],
332
+ categories: [],
333
+ default_category_uuid: 'cat-1'
334
+ },
335
+ exits: []
336
+ };
337
+
338
+ const formData = {
339
+ uuid: 'test-node-uuid',
340
+ amounts: [
341
+ {
342
+ currency: [{ value: 'EUR', name: 'Euro (EUR)' }],
343
+ amount: '20'
344
+ }
345
+ ],
346
+ result_name: ''
347
+ };
348
+
349
+ const node = split_by_airtime.fromFormData!(formData, originalNode);
350
+
351
+ const action: any = node.actions![0];
352
+ expect(action.uuid).to.equal('existing-action-uuid');
353
+ });
354
+
355
+ it('should preserve existing category and exit UUIDs', () => {
356
+ const originalNode: Node = {
357
+ uuid: 'test-node-uuid',
358
+ actions: [
359
+ {
360
+ type: 'transfer_airtime',
361
+ uuid: 'action-uuid',
362
+ amounts: { USD: 5 }
363
+ } as TransferAirtime
364
+ ],
365
+ router: {
366
+ type: 'switch',
367
+ operand: '@locals._new_transfer',
368
+ cases: [
369
+ {
370
+ uuid: 'case-1',
371
+ type: 'has_text',
372
+ arguments: [],
373
+ category_uuid: 'cat-success'
374
+ }
375
+ ],
376
+ categories: [
377
+ { uuid: 'cat-success', name: 'Success', exit_uuid: 'exit-success' },
378
+ { uuid: 'cat-failure', name: 'Failure', exit_uuid: 'exit-failure' }
379
+ ],
380
+ default_category_uuid: 'cat-failure'
381
+ },
382
+ exits: [
383
+ { uuid: 'exit-success', destination_uuid: 'next-node-1' },
384
+ { uuid: 'exit-failure', destination_uuid: 'next-node-2' }
385
+ ]
386
+ };
387
+
388
+ const formData = {
389
+ uuid: 'test-node-uuid',
390
+ amounts: [
391
+ {
392
+ currency: [{ value: 'EUR', name: 'Euro (EUR)' }],
393
+ amount: '20'
394
+ }
395
+ ],
396
+ result_name: ''
397
+ };
398
+
399
+ const node = split_by_airtime.fromFormData!(formData, originalNode);
400
+
401
+ // Check that UUIDs are preserved
402
+ expect(node.router?.categories![0].uuid).to.equal('cat-success');
403
+ expect(node.router?.categories![1].uuid).to.equal('cat-failure');
404
+ expect(node.exits![0].uuid).to.equal('exit-success');
405
+ expect(node.exits![1].uuid).to.equal('exit-failure');
406
+
407
+ // Check that destinations are preserved
408
+ expect(node.exits![0].destination_uuid).to.equal('next-node-1');
409
+ expect(node.exits![1].destination_uuid).to.equal('next-node-2');
410
+ });
411
+ });
412
+
413
+ describe('validate', () => {
414
+ it('should validate when at least one valid amount is provided', () => {
415
+ const formData = {
416
+ amounts: [
417
+ {
418
+ currency: [{ value: 'USD', name: 'US Dollar (USD)' }],
419
+ amount: '10'
420
+ }
421
+ ]
422
+ };
423
+
424
+ const result = split_by_airtime.validate!(formData);
425
+ expect(result.valid).to.be.true;
426
+ expect(Object.keys(result.errors)).to.have.lengthOf(0);
427
+ });
428
+
429
+ it('should fail validation when no amounts are provided', () => {
430
+ const formData = {
431
+ amounts: []
432
+ };
433
+
434
+ const result = split_by_airtime.validate!(formData);
435
+ expect(result.valid).to.be.false;
436
+ expect(result.errors.amounts).to.exist;
437
+ });
438
+
439
+ it('should fail validation when amounts are empty', () => {
440
+ const formData = {
441
+ amounts: [
442
+ {
443
+ currency: [{ value: 'USD', name: 'US Dollar (USD)' }],
444
+ amount: ''
445
+ }
446
+ ]
447
+ };
448
+
449
+ const result = split_by_airtime.validate!(formData);
450
+ expect(result.valid).to.be.false;
451
+ expect(result.errors.amounts).to.exist;
452
+ });
453
+
454
+ it('should fail validation when currency is not selected', () => {
455
+ const formData = {
456
+ amounts: [
457
+ {
458
+ currency: null,
459
+ amount: '10'
460
+ }
461
+ ]
462
+ };
463
+
464
+ const result = split_by_airtime.validate!(formData);
465
+ expect(result.valid).to.be.false;
466
+ expect(result.errors.amounts).to.exist;
467
+ });
468
+
469
+ it('should fail validation for duplicate currencies', () => {
470
+ const formData = {
471
+ amounts: [
472
+ {
473
+ currency: [{ value: 'USD', name: 'US Dollar (USD)' }],
474
+ amount: '10'
475
+ },
476
+ {
477
+ currency: [{ value: 'USD', name: 'US Dollar (USD)' }],
478
+ amount: '20'
479
+ }
480
+ ]
481
+ };
482
+
483
+ const result = split_by_airtime.validate!(formData);
484
+ expect(result.valid).to.be.false;
485
+ expect(result.errors.amounts).to.include('Duplicate');
486
+ });
487
+
488
+ it('should fail validation for non-numeric amounts', () => {
489
+ const formData = {
490
+ amounts: [
491
+ {
492
+ currency: [{ value: 'USD', name: 'US Dollar (USD)' }],
493
+ amount: 'abc'
494
+ }
495
+ ]
496
+ };
497
+
498
+ const result = split_by_airtime.validate!(formData);
499
+ expect(result.valid).to.be.false;
500
+ expect(result.errors.amounts).to.include('valid positive numbers');
501
+ });
502
+
503
+ it('should fail validation for negative amounts', () => {
504
+ const formData = {
505
+ amounts: [
506
+ {
507
+ currency: [{ value: 'USD', name: 'US Dollar (USD)' }],
508
+ amount: '-10'
509
+ }
510
+ ]
511
+ };
512
+
513
+ const result = split_by_airtime.validate!(formData);
514
+ expect(result.valid).to.be.false;
515
+ expect(result.errors.amounts).to.include('valid positive numbers');
516
+ });
517
+
518
+ it('should fail validation for zero amounts', () => {
519
+ const formData = {
520
+ amounts: [
521
+ {
522
+ currency: [{ value: 'USD', name: 'US Dollar (USD)' }],
523
+ amount: '0'
524
+ }
525
+ ]
526
+ };
527
+
528
+ const result = split_by_airtime.validate!(formData);
529
+ expect(result.valid).to.be.false;
530
+ expect(result.errors.amounts).to.include('valid positive numbers');
531
+ });
532
+
533
+ it('should validate multiple valid amounts', () => {
534
+ const formData = {
535
+ amounts: [
536
+ {
537
+ currency: [{ value: 'USD', name: 'US Dollar (USD)' }],
538
+ amount: '10'
539
+ },
540
+ {
541
+ currency: [{ value: 'EUR', name: 'Euro (EUR)' }],
542
+ amount: '15.5'
543
+ }
544
+ ]
545
+ };
546
+
547
+ const result = split_by_airtime.validate!(formData);
548
+ expect(result.valid).to.be.true;
549
+ expect(Object.keys(result.errors)).to.have.lengthOf(0);
550
+ });
551
+ });
552
+
553
+ describe('render', () => {
554
+ it('should render single currency', () => {
555
+ const node: Node = {
556
+ uuid: 'test-node-uuid',
557
+ actions: [
558
+ {
559
+ type: 'transfer_airtime',
560
+ uuid: 'action-uuid',
561
+ amounts: {
562
+ USD: 10
563
+ }
564
+ } as TransferAirtime
565
+ ],
566
+ exits: []
567
+ };
568
+
569
+ const result = split_by_airtime.render!(node);
570
+ expect(result).to.exist;
571
+ });
572
+
573
+ it('should render multiple currencies', () => {
574
+ const node: Node = {
575
+ uuid: 'test-node-uuid',
576
+ actions: [
577
+ {
578
+ type: 'transfer_airtime',
579
+ uuid: 'action-uuid',
580
+ amounts: {
581
+ USD: 10,
582
+ EUR: 15,
583
+ GBP: 8
584
+ }
585
+ } as TransferAirtime
586
+ ],
587
+ exits: []
588
+ };
589
+
590
+ const result = split_by_airtime.render!(node);
591
+ expect(result).to.exist;
592
+ });
593
+
594
+ it('should render placeholder when no amounts', () => {
595
+ const node: Node = {
596
+ uuid: 'test-node-uuid',
597
+ actions: [
598
+ {
599
+ type: 'transfer_airtime',
600
+ uuid: 'action-uuid',
601
+ amounts: {}
602
+ } as TransferAirtime
603
+ ],
604
+ exits: []
605
+ };
606
+
607
+ const result = split_by_airtime.render!(node);
608
+ expect(result).to.exist;
609
+ });
610
+ });
611
+
612
+ describe('round-trip conversion', () => {
613
+ it('should maintain data through toFormData -> fromFormData cycle', () => {
614
+ const originalNode: Node = {
615
+ uuid: 'test-node-uuid',
616
+ actions: [
617
+ {
618
+ type: 'transfer_airtime',
619
+ uuid: 'action-uuid',
620
+ amounts: {
621
+ USD: 10,
622
+ EUR: 15.5
623
+ }
624
+ } as TransferAirtime
625
+ ],
626
+ router: {
627
+ type: 'switch',
628
+ operand: '@locals._new_transfer',
629
+ result_name: 'airtime_result',
630
+ cases: [
631
+ {
632
+ uuid: 'case-1',
633
+ type: 'has_text',
634
+ arguments: [],
635
+ category_uuid: 'cat-success'
636
+ }
637
+ ],
638
+ categories: [
639
+ { uuid: 'cat-success', name: 'Success', exit_uuid: 'exit-success' },
640
+ { uuid: 'cat-failure', name: 'Failure', exit_uuid: 'exit-failure' }
641
+ ],
642
+ default_category_uuid: 'cat-failure'
643
+ },
644
+ exits: [
645
+ { uuid: 'exit-success', destination_uuid: 'next-1' },
646
+ { uuid: 'exit-failure', destination_uuid: 'next-2' }
647
+ ]
648
+ };
649
+
650
+ // Convert to form data
651
+ const formData = split_by_airtime.toFormData!(originalNode);
652
+
653
+ // Convert back to node
654
+ const resultNode = split_by_airtime.fromFormData!(formData, originalNode);
655
+
656
+ // Check the action
657
+ const action: any = resultNode.actions![0];
658
+ expect(action.type).to.equal('transfer_airtime');
659
+ expect(action.amounts).to.deep.equal({
660
+ USD: 10,
661
+ EUR: 15.5
662
+ });
663
+
664
+ // Check result_name is preserved
665
+ expect(resultNode.router?.result_name).to.equal('airtime_result');
666
+
667
+ // Check UUIDs are preserved
668
+ expect(action.uuid).to.equal('action-uuid');
669
+ expect(resultNode.router?.categories![0].uuid).to.equal('cat-success');
670
+ expect(resultNode.router?.categories![1].uuid).to.equal('cat-failure');
671
+ });
672
+ });
673
+ });