@servicenow/sdk-build-plugins 4.2.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (349) hide show
  1. package/dist/acl-plugin.js +11 -0
  2. package/dist/acl-plugin.js.map +1 -1
  3. package/dist/applicability-plugin.d.ts +2 -0
  4. package/dist/applicability-plugin.js +72 -0
  5. package/dist/applicability-plugin.js.map +1 -0
  6. package/dist/atf/test-plugin.js +5 -2
  7. package/dist/atf/test-plugin.js.map +1 -1
  8. package/dist/basic-syntax-plugin.js +7 -1
  9. package/dist/basic-syntax-plugin.js.map +1 -1
  10. package/dist/business-rule-plugin.js +1 -0
  11. package/dist/business-rule-plugin.js.map +1 -1
  12. package/dist/call-expression-plugin.js +1 -107
  13. package/dist/call-expression-plugin.js.map +1 -1
  14. package/dist/column/column-to-record.d.ts +10 -3
  15. package/dist/column/column-to-record.js +44 -7
  16. package/dist/column/column-to-record.js.map +1 -1
  17. package/dist/column-plugin.d.ts +3 -1
  18. package/dist/column-plugin.js +12 -12
  19. package/dist/column-plugin.js.map +1 -1
  20. package/dist/dashboard/dashboard-component-property-defaults.d.ts +152 -0
  21. package/dist/dashboard/dashboard-component-property-defaults.js +264 -0
  22. package/dist/dashboard/dashboard-component-property-defaults.js.map +1 -0
  23. package/dist/dashboard/dashboard-component-resolver.d.ts +13 -0
  24. package/dist/dashboard/dashboard-component-resolver.js +69 -0
  25. package/dist/dashboard/dashboard-component-resolver.js.map +1 -0
  26. package/dist/dashboard/dashboard-plugin.d.ts +12 -0
  27. package/dist/dashboard/dashboard-plugin.js +397 -0
  28. package/dist/dashboard/dashboard-plugin.js.map +1 -0
  29. package/dist/data-plugin.d.ts +3 -0
  30. package/dist/data-plugin.js +61 -113
  31. package/dist/data-plugin.js.map +1 -1
  32. package/dist/email-notification-plugin.d.ts +2 -0
  33. package/dist/email-notification-plugin.js +541 -0
  34. package/dist/email-notification-plugin.js.map +1 -0
  35. package/dist/flow/constants/flow-plugin-constants.d.ts +58 -0
  36. package/dist/flow/constants/flow-plugin-constants.js +70 -0
  37. package/dist/flow/constants/flow-plugin-constants.js.map +1 -0
  38. package/dist/flow/flow-logic/flow-logic-constants.d.ts +38 -0
  39. package/dist/flow/flow-logic/flow-logic-constants.js +118 -0
  40. package/dist/flow/flow-logic/flow-logic-constants.js.map +1 -0
  41. package/dist/flow/flow-logic/flow-logic-diagnostics.d.ts +19 -0
  42. package/dist/flow/flow-logic/flow-logic-diagnostics.js +503 -0
  43. package/dist/flow/flow-logic/flow-logic-diagnostics.js.map +1 -0
  44. package/dist/flow/flow-logic/flow-logic-plugin-helpers.d.ts +62 -0
  45. package/dist/flow/flow-logic/flow-logic-plugin-helpers.js +2092 -0
  46. package/dist/flow/flow-logic/flow-logic-plugin-helpers.js.map +1 -0
  47. package/dist/flow/flow-logic/flow-logic-plugin.d.ts +52 -0
  48. package/dist/flow/flow-logic/flow-logic-plugin.js +283 -0
  49. package/dist/flow/flow-logic/flow-logic-plugin.js.map +1 -0
  50. package/dist/flow/flow-logic/flow-logic-shapes.d.ts +104 -0
  51. package/dist/flow/flow-logic/flow-logic-shapes.js +201 -0
  52. package/dist/flow/flow-logic/flow-logic-shapes.js.map +1 -0
  53. package/dist/flow/plugins/approval-rules-plugin.d.ts +2 -0
  54. package/dist/flow/plugins/approval-rules-plugin.js +49 -0
  55. package/dist/flow/plugins/approval-rules-plugin.js.map +1 -0
  56. package/dist/flow/plugins/flow-action-definition-plugin.d.ts +2 -0
  57. package/dist/flow/plugins/flow-action-definition-plugin.js +286 -0
  58. package/dist/flow/plugins/flow-action-definition-plugin.js.map +1 -0
  59. package/dist/flow/plugins/flow-data-pill-plugin.d.ts +9 -0
  60. package/dist/flow/plugins/flow-data-pill-plugin.js +212 -0
  61. package/dist/flow/plugins/flow-data-pill-plugin.js.map +1 -0
  62. package/dist/flow/plugins/flow-definition-plugin.d.ts +2 -0
  63. package/dist/flow/plugins/flow-definition-plugin.js +1668 -0
  64. package/dist/flow/plugins/flow-definition-plugin.js.map +1 -0
  65. package/dist/flow/plugins/flow-diagnostics-plugin.d.ts +26 -0
  66. package/dist/flow/plugins/flow-diagnostics-plugin.js +217 -0
  67. package/dist/flow/plugins/flow-diagnostics-plugin.js.map +1 -0
  68. package/dist/flow/plugins/flow-instance-plugin.d.ts +12 -0
  69. package/dist/flow/plugins/flow-instance-plugin.js +1205 -0
  70. package/dist/flow/plugins/flow-instance-plugin.js.map +1 -0
  71. package/dist/flow/plugins/flow-trigger-instance-plugin.d.ts +2 -0
  72. package/dist/flow/plugins/flow-trigger-instance-plugin.js +338 -0
  73. package/dist/flow/plugins/flow-trigger-instance-plugin.js.map +1 -0
  74. package/dist/flow/plugins/inline-script-plugin.d.ts +39 -0
  75. package/dist/flow/plugins/inline-script-plugin.js +80 -0
  76. package/dist/flow/plugins/inline-script-plugin.js.map +1 -0
  77. package/dist/flow/plugins/step-definition-plugin.d.ts +5 -0
  78. package/dist/flow/plugins/step-definition-plugin.js +71 -0
  79. package/dist/flow/plugins/step-definition-plugin.js.map +1 -0
  80. package/dist/flow/plugins/step-instance-plugin.d.ts +31 -0
  81. package/dist/flow/plugins/step-instance-plugin.js +339 -0
  82. package/dist/flow/plugins/step-instance-plugin.js.map +1 -0
  83. package/dist/flow/plugins/trigger-plugin.d.ts +2 -0
  84. package/dist/flow/plugins/trigger-plugin.js +96 -0
  85. package/dist/flow/plugins/trigger-plugin.js.map +1 -0
  86. package/dist/flow/plugins/wfa-datapill-plugin.d.ts +15 -0
  87. package/dist/flow/plugins/wfa-datapill-plugin.js +178 -0
  88. package/dist/flow/plugins/wfa-datapill-plugin.js.map +1 -0
  89. package/dist/flow/utils/approval-rules-processor.d.ts +13 -0
  90. package/dist/flow/utils/approval-rules-processor.js +267 -0
  91. package/dist/flow/utils/approval-rules-processor.js.map +1 -0
  92. package/dist/flow/utils/built-in-complex-objects.d.ts +19 -0
  93. package/dist/flow/utils/built-in-complex-objects.js +62 -0
  94. package/dist/flow/utils/built-in-complex-objects.js.map +1 -0
  95. package/dist/flow/utils/complex-object-resolver.d.ts +8 -0
  96. package/dist/flow/utils/complex-object-resolver.js +614 -0
  97. package/dist/flow/utils/complex-object-resolver.js.map +1 -0
  98. package/dist/flow/utils/complex-objects.d.ts +36 -0
  99. package/dist/flow/utils/complex-objects.js +481 -0
  100. package/dist/flow/utils/complex-objects.js.map +1 -0
  101. package/dist/flow/utils/data-pill-shapes.d.ts +58 -0
  102. package/dist/flow/utils/data-pill-shapes.js +135 -0
  103. package/dist/flow/utils/data-pill-shapes.js.map +1 -0
  104. package/dist/flow/utils/datapill-transformer.d.ts +110 -0
  105. package/dist/flow/utils/datapill-transformer.js +503 -0
  106. package/dist/flow/utils/datapill-transformer.js.map +1 -0
  107. package/dist/flow/utils/flow-constants.d.ts +72 -0
  108. package/dist/flow/utils/flow-constants.js +230 -0
  109. package/dist/flow/utils/flow-constants.js.map +1 -0
  110. package/dist/flow/utils/flow-io-to-record.d.ts +44 -0
  111. package/dist/flow/utils/flow-io-to-record.js +409 -0
  112. package/dist/flow/utils/flow-io-to-record.js.map +1 -0
  113. package/dist/flow/utils/flow-shapes.d.ts +161 -0
  114. package/dist/flow/utils/flow-shapes.js +255 -0
  115. package/dist/flow/utils/flow-shapes.js.map +1 -0
  116. package/dist/flow/utils/flow-to-xml.d.ts +16 -0
  117. package/dist/flow/utils/flow-to-xml.js +237 -0
  118. package/dist/flow/utils/flow-to-xml.js.map +1 -0
  119. package/dist/flow/utils/flow-variable-processor.d.ts +51 -0
  120. package/dist/flow/utils/flow-variable-processor.js +69 -0
  121. package/dist/flow/utils/flow-variable-processor.js.map +1 -0
  122. package/dist/flow/utils/label-cache-parser.d.ts +7 -0
  123. package/dist/flow/utils/label-cache-parser.js +24 -0
  124. package/dist/flow/utils/label-cache-parser.js.map +1 -0
  125. package/dist/flow/utils/label-cache-processor.d.ts +119 -0
  126. package/dist/flow/utils/label-cache-processor.js +719 -0
  127. package/dist/flow/utils/label-cache-processor.js.map +1 -0
  128. package/dist/flow/utils/pill-string-parser.d.ts +88 -0
  129. package/dist/flow/utils/pill-string-parser.js +306 -0
  130. package/dist/flow/utils/pill-string-parser.js.map +1 -0
  131. package/dist/flow/utils/schema-to-flow-object.d.ts +22 -0
  132. package/dist/flow/utils/schema-to-flow-object.js +318 -0
  133. package/dist/flow/utils/schema-to-flow-object.js.map +1 -0
  134. package/dist/flow/utils/service-catalog.d.ts +47 -0
  135. package/dist/flow/utils/service-catalog.js +137 -0
  136. package/dist/flow/utils/service-catalog.js.map +1 -0
  137. package/dist/flow/utils/utils.d.ts +117 -0
  138. package/dist/flow/utils/utils.js +345 -0
  139. package/dist/flow/utils/utils.js.map +1 -0
  140. package/dist/index.d.ts +20 -1
  141. package/dist/index.js +21 -1
  142. package/dist/index.js.map +1 -1
  143. package/dist/list-plugin.js +1 -1
  144. package/dist/list-plugin.js.map +1 -1
  145. package/dist/now-attach-plugin.d.ts +1 -0
  146. package/dist/now-attach-plugin.js +10 -10
  147. package/dist/now-attach-plugin.js.map +1 -1
  148. package/dist/now-ref-plugin.js +1 -1
  149. package/dist/now-ref-plugin.js.map +1 -1
  150. package/dist/record-plugin.d.ts +29 -0
  151. package/dist/record-plugin.js +66 -7
  152. package/dist/record-plugin.js.map +1 -1
  153. package/dist/repack/index.d.ts +2 -0
  154. package/dist/repack/index.js +8 -0
  155. package/dist/repack/index.js.map +1 -1
  156. package/dist/rest-api-plugin.js +54 -44
  157. package/dist/rest-api-plugin.js.map +1 -1
  158. package/dist/server-module-plugin/index.d.ts +10 -0
  159. package/dist/server-module-plugin/index.js +83 -59
  160. package/dist/server-module-plugin/index.js.map +1 -1
  161. package/dist/service-catalog/catalog-clientscript-plugin.d.ts +2 -0
  162. package/dist/service-catalog/catalog-clientscript-plugin.js +117 -0
  163. package/dist/service-catalog/catalog-clientscript-plugin.js.map +1 -0
  164. package/dist/service-catalog/catalog-item-plugin.d.ts +2 -0
  165. package/dist/service-catalog/catalog-item-plugin.js +115 -0
  166. package/dist/service-catalog/catalog-item-plugin.js.map +1 -0
  167. package/dist/service-catalog/catalog-ui-policy-plugin.d.ts +2 -0
  168. package/dist/service-catalog/catalog-ui-policy-plugin.js +266 -0
  169. package/dist/service-catalog/catalog-ui-policy-plugin.js.map +1 -0
  170. package/dist/service-catalog/index.d.ts +5 -0
  171. package/dist/service-catalog/index.js +22 -0
  172. package/dist/service-catalog/index.js.map +1 -0
  173. package/dist/service-catalog/record-to-shape.d.ts +6 -0
  174. package/dist/service-catalog/record-to-shape.js +93 -0
  175. package/dist/service-catalog/record-to-shape.js.map +1 -0
  176. package/dist/service-catalog/sc-record-producer-plugin.d.ts +2 -0
  177. package/dist/service-catalog/sc-record-producer-plugin.js +140 -0
  178. package/dist/service-catalog/sc-record-producer-plugin.js.map +1 -0
  179. package/dist/service-catalog/service-catalog-base.d.ts +311 -0
  180. package/dist/service-catalog/service-catalog-base.js +542 -0
  181. package/dist/service-catalog/service-catalog-base.js.map +1 -0
  182. package/dist/service-catalog/service-catalog-diagnostics.d.ts +45 -0
  183. package/dist/service-catalog/service-catalog-diagnostics.js +172 -0
  184. package/dist/service-catalog/service-catalog-diagnostics.js.map +1 -0
  185. package/dist/service-catalog/shape-to-record.d.ts +8 -0
  186. package/dist/service-catalog/shape-to-record.js +235 -0
  187. package/dist/service-catalog/shape-to-record.js.map +1 -0
  188. package/dist/service-catalog/utils.d.ts +323 -0
  189. package/dist/service-catalog/utils.js +1216 -0
  190. package/dist/service-catalog/utils.js.map +1 -0
  191. package/dist/service-catalog/variable-helper.d.ts +43 -0
  192. package/dist/service-catalog/variable-helper.js +92 -0
  193. package/dist/service-catalog/variable-helper.js.map +1 -0
  194. package/dist/service-catalog/variable-set-plugin.d.ts +2 -0
  195. package/dist/service-catalog/variable-set-plugin.js +175 -0
  196. package/dist/service-catalog/variable-set-plugin.js.map +1 -0
  197. package/dist/service-catalog/variables-transform.d.ts +139 -0
  198. package/dist/service-catalog/variables-transform.js +403 -0
  199. package/dist/service-catalog/variables-transform.js.map +1 -0
  200. package/dist/sla/sla-validators.d.ts +61 -0
  201. package/dist/sla/sla-validators.js +224 -0
  202. package/dist/sla/sla-validators.js.map +1 -0
  203. package/dist/sla-plugin.d.ts +5 -0
  204. package/dist/sla-plugin.js +280 -0
  205. package/dist/sla-plugin.js.map +1 -0
  206. package/dist/static-content-plugin.js +25 -2
  207. package/dist/static-content-plugin.js.map +1 -1
  208. package/dist/table-plugin.js +32 -15
  209. package/dist/table-plugin.js.map +1 -1
  210. package/dist/ui-page-plugin.js +832 -19
  211. package/dist/ui-page-plugin.js.map +1 -1
  212. package/dist/ui-policy-plugin.js +5 -7
  213. package/dist/ui-policy-plugin.js.map +1 -1
  214. package/dist/utils.d.ts +10 -1
  215. package/dist/utils.js +16 -0
  216. package/dist/utils.js.map +1 -1
  217. package/dist/ux-list-menu-config-plugin.d.ts +2 -0
  218. package/dist/ux-list-menu-config-plugin.js +292 -0
  219. package/dist/ux-list-menu-config-plugin.js.map +1 -0
  220. package/dist/workspace-plugin/chrome-tab.d.ts +2 -0
  221. package/dist/workspace-plugin/chrome-tab.js +46 -0
  222. package/dist/workspace-plugin/chrome-tab.js.map +1 -0
  223. package/dist/workspace-plugin/constants.d.ts +52 -0
  224. package/dist/workspace-plugin/constants.js +56 -0
  225. package/dist/workspace-plugin/constants.js.map +1 -0
  226. package/dist/workspace-plugin/fluent-utils.d.ts +9 -0
  227. package/dist/workspace-plugin/fluent-utils.js +60 -0
  228. package/dist/workspace-plugin/fluent-utils.js.map +1 -0
  229. package/dist/workspace-plugin/page.d.ts +8 -0
  230. package/dist/workspace-plugin/page.js +108 -0
  231. package/dist/workspace-plugin/page.js.map +1 -0
  232. package/dist/workspace-plugin/screen.d.ts +1 -0
  233. package/dist/workspace-plugin/screen.js +38 -0
  234. package/dist/workspace-plugin/screen.js.map +1 -0
  235. package/dist/workspace-plugin/templates/index.d.ts +10 -0
  236. package/dist/workspace-plugin/templates/index.js +20 -0
  237. package/dist/workspace-plugin/templates/index.js.map +1 -0
  238. package/dist/workspace-plugin/templates/record-page-composition.d.ts +1 -0
  239. package/dist/workspace-plugin/templates/record-page-composition.js +4043 -0
  240. package/dist/workspace-plugin/templates/record-page-composition.js.map +1 -0
  241. package/dist/workspace-plugin/templates/record-page-data.d.ts +1 -0
  242. package/dist/workspace-plugin/templates/record-page-data.js +527 -0
  243. package/dist/workspace-plugin/templates/record-page-data.js.map +1 -0
  244. package/dist/workspace-plugin/templates/record-page-interalEventMappings.d.ts +1 -0
  245. package/dist/workspace-plugin/templates/record-page-interalEventMappings.js +39 -0
  246. package/dist/workspace-plugin/templates/record-page-interalEventMappings.js.map +1 -0
  247. package/dist/workspace-plugin/templates/record-page-layoutModel.d.ts +1 -0
  248. package/dist/workspace-plugin/templates/record-page-layoutModel.js +55 -0
  249. package/dist/workspace-plugin/templates/record-page-layoutModel.js.map +1 -0
  250. package/dist/workspace-plugin/templates/record-page-properties.d.ts +1 -0
  251. package/dist/workspace-plugin/templates/record-page-properties.js +135 -0
  252. package/dist/workspace-plugin/templates/record-page-properties.js.map +1 -0
  253. package/dist/workspace-plugin/templates/record-page.d.ts +3 -0
  254. package/dist/workspace-plugin/templates/record-page.js +8 -0
  255. package/dist/workspace-plugin/templates/record-page.js.map +1 -0
  256. package/dist/workspace-plugin.d.ts +2 -0
  257. package/dist/workspace-plugin.js +453 -0
  258. package/dist/workspace-plugin.js.map +1 -0
  259. package/package.json +10 -12
  260. package/src/acl-plugin.ts +16 -1
  261. package/src/applicability-plugin.ts +82 -0
  262. package/src/atf/test-plugin.ts +6 -3
  263. package/src/basic-syntax-plugin.ts +10 -1
  264. package/src/business-rule-plugin.ts +2 -1
  265. package/src/call-expression-plugin.ts +2 -130
  266. package/src/column/column-to-record.ts +54 -8
  267. package/src/column-plugin.ts +29 -13
  268. package/src/dashboard/dashboard-component-property-defaults.ts +277 -0
  269. package/src/dashboard/dashboard-component-resolver.ts +69 -0
  270. package/src/dashboard/dashboard-plugin.ts +450 -0
  271. package/src/data-plugin.ts +67 -139
  272. package/src/email-notification-plugin.ts +850 -0
  273. package/src/flow/constants/flow-plugin-constants.ts +79 -0
  274. package/src/flow/flow-logic/flow-logic-constants.ts +120 -0
  275. package/src/flow/flow-logic/flow-logic-diagnostics.ts +591 -0
  276. package/src/flow/flow-logic/flow-logic-plugin-helpers.ts +2550 -0
  277. package/src/flow/flow-logic/flow-logic-plugin.ts +337 -0
  278. package/src/flow/flow-logic/flow-logic-shapes.ts +215 -0
  279. package/src/flow/plugins/approval-rules-plugin.ts +48 -0
  280. package/src/flow/plugins/flow-action-definition-plugin.ts +295 -0
  281. package/src/flow/plugins/flow-data-pill-plugin.ts +258 -0
  282. package/src/flow/plugins/flow-definition-plugin.ts +2173 -0
  283. package/src/flow/plugins/flow-diagnostics-plugin.ts +280 -0
  284. package/src/flow/plugins/flow-instance-plugin.ts +1499 -0
  285. package/src/flow/plugins/flow-trigger-instance-plugin.ts +444 -0
  286. package/src/flow/plugins/inline-script-plugin.ts +83 -0
  287. package/src/flow/plugins/step-definition-plugin.ts +67 -0
  288. package/src/flow/plugins/step-instance-plugin.ts +431 -0
  289. package/src/flow/plugins/trigger-plugin.ts +95 -0
  290. package/src/flow/plugins/wfa-datapill-plugin.ts +213 -0
  291. package/src/flow/utils/approval-rules-processor.ts +298 -0
  292. package/src/flow/utils/built-in-complex-objects.ts +81 -0
  293. package/src/flow/utils/complex-object-resolver.ts +875 -0
  294. package/src/flow/utils/complex-objects.ts +656 -0
  295. package/src/flow/utils/data-pill-shapes.ts +165 -0
  296. package/src/flow/utils/datapill-transformer.ts +632 -0
  297. package/src/flow/utils/flow-constants.ts +285 -0
  298. package/src/flow/utils/flow-io-to-record.ts +533 -0
  299. package/src/flow/utils/flow-shapes.ts +296 -0
  300. package/src/flow/utils/flow-to-xml.ts +318 -0
  301. package/src/flow/utils/flow-variable-processor.ts +100 -0
  302. package/src/flow/utils/label-cache-parser.ts +37 -0
  303. package/src/flow/utils/label-cache-processor.ts +870 -0
  304. package/src/flow/utils/pill-string-parser.ts +375 -0
  305. package/src/flow/utils/schema-to-flow-object.ts +385 -0
  306. package/src/flow/utils/service-catalog.ts +174 -0
  307. package/src/flow/utils/utils.ts +395 -0
  308. package/src/index.ts +20 -1
  309. package/src/list-plugin.ts +1 -1
  310. package/src/now-attach-plugin.ts +14 -11
  311. package/src/now-ref-plugin.ts +1 -1
  312. package/src/record-plugin.ts +76 -11
  313. package/src/repack/index.ts +14 -0
  314. package/src/rest-api-plugin.ts +62 -50
  315. package/src/server-module-plugin/index.ts +112 -86
  316. package/src/service-catalog/catalog-clientscript-plugin.ts +140 -0
  317. package/src/service-catalog/catalog-item-plugin.ts +162 -0
  318. package/src/service-catalog/catalog-ui-policy-plugin.ts +324 -0
  319. package/src/service-catalog/index.ts +5 -0
  320. package/src/service-catalog/record-to-shape.ts +109 -0
  321. package/src/service-catalog/sc-record-producer-plugin.ts +201 -0
  322. package/src/service-catalog/service-catalog-base.ts +600 -0
  323. package/src/service-catalog/service-catalog-diagnostics.ts +254 -0
  324. package/src/service-catalog/shape-to-record.ts +279 -0
  325. package/src/service-catalog/utils.ts +1455 -0
  326. package/src/service-catalog/variable-helper.ts +135 -0
  327. package/src/service-catalog/variable-set-plugin.ts +197 -0
  328. package/src/service-catalog/variables-transform.ts +438 -0
  329. package/src/sla/sla-validators.ts +331 -0
  330. package/src/sla-plugin.ts +358 -0
  331. package/src/static-content-plugin.ts +25 -2
  332. package/src/table-plugin.ts +49 -16
  333. package/src/ui-page-plugin.ts +1063 -20
  334. package/src/ui-policy-plugin.ts +5 -9
  335. package/src/utils.ts +24 -1
  336. package/src/ux-list-menu-config-plugin.ts +312 -0
  337. package/src/workspace-plugin/chrome-tab.ts +44 -0
  338. package/src/workspace-plugin/constants.ts +53 -0
  339. package/src/workspace-plugin/fluent-utils.ts +60 -0
  340. package/src/workspace-plugin/page.ts +139 -0
  341. package/src/workspace-plugin/screen.ts +34 -0
  342. package/src/workspace-plugin/templates/index.ts +17 -0
  343. package/src/workspace-plugin/templates/record-page-composition.ts +4051 -0
  344. package/src/workspace-plugin/templates/record-page-data.ts +523 -0
  345. package/src/workspace-plugin/templates/record-page-interalEventMappings.ts +35 -0
  346. package/src/workspace-plugin/templates/record-page-layoutModel.ts +51 -0
  347. package/src/workspace-plugin/templates/record-page-properties.ts +131 -0
  348. package/src/workspace-plugin/templates/record-page.ts +6 -0
  349. package/src/workspace-plugin.ts +574 -0
@@ -0,0 +1,337 @@
1
+ import {
2
+ Plugin,
3
+ CallExpressionShape,
4
+ type Record,
5
+ UndefinedShape,
6
+ type Shape,
7
+ VariableStatementShape,
8
+ type Logger,
9
+ } from '@servicenow/sdk-build-core'
10
+ import { FLOW_LOGIC, FLOW_LOGIC_SYS_ID_MAP, FlowLogicSysId, DO_IN_PARALLEL_BLOCK_SYS_ID } from './flow-logic-constants'
11
+ import { FlowInstancePlugin } from '../plugins/flow-instance-plugin'
12
+ import { FlowLogicInstanceShape } from './flow-logic-shapes'
13
+ import {
14
+ isConditionalLogicShape,
15
+ isForEachShape,
16
+ isDoInParallelShape,
17
+ createEmptyFlowLogicValues,
18
+ } from './flow-logic-plugin-helpers'
19
+ import { getFlowLogicArguments, getFlowLogicInstanceRecord } from './flow-logic-plugin-helpers'
20
+ import { getRecordFromFlowInstaceShape, sysIdToUuid, getOrder, getDirectVariableIdentifier } from '../utils/utils'
21
+ import type { ArrowFunctionShape } from '../../arrow-function-plugin'
22
+
23
+ /**
24
+ * FlowLogicPlugin handles flow logic instances (If, ElseIf, Else, GoBackTo) in flow definitions.
25
+ *
26
+ * ## Architecture Overview
27
+ *
28
+ * This plugin provides bidirectional conversion between Fluent TypeScript code and ServiceNow XML flow records:
29
+ *
30
+ * **Fluent → XML (Build Time):**
31
+ * ```
32
+ * If({ condition: "user.role === 'admin'" }, () => { ... })
33
+ * ↓ (FlowLogicValueProcessor.prepare)
34
+ * sys_hub_flow_logic_instance_v2 record with gzipped JSON values
35
+ * ```
36
+ *
37
+ * **XML → Fluent (transform):**
38
+ * ```
39
+ * sys_hub_flow_logic_instance_v2 record with gzipped values
40
+ * ↓ (FlowLogicValueProcessor.parse)
41
+ * If({ condition: "user.role === 'admin'" }, () => { ... })
42
+ * ```
43
+ *
44
+ * ## Adding New Flow Logic Types
45
+ *
46
+ * To add a new flow logic type (e.g., `DoInParallel`, `ForEach`), follow these steps:
47
+ *
48
+ * ### 1. Update Constants (`flow-logic-constants.ts`)
49
+ * Add new enum values to FLOW_LOGIC, and FLOW_LOGIC_MAP
50
+ *
51
+ * ### 2. Create Shape Types (`flow-logic-shapes.ts`)
52
+ * Define TypeScript interfaces extending FlowLogicInstanceShape with specific methods
53
+ *
54
+ * ### 3. Update FlowLogicValueProcessor
55
+ * - **Add Value Preparers**: Functions to convert Fluent config to FlowLogicValues (forward flow)
56
+ * - **Add Value Parsers**: Functions to convert FlowLogicValues back to config objects (reverse flow)
57
+ *
58
+ * ### 4. Add Argument Builders
59
+ * Create functions in FLOW_LOGIC_ARGUMENT_BUILDERS to reconstruct Fluent function arguments
60
+ *
61
+ * ### 5. Add Type Guards and Validation
62
+ * Create type guard functions and add validation rules in flow-logic-diagnostics.ts
63
+ *
64
+ *
65
+ * ## Data Flow Summary
66
+ *
67
+ * ```
68
+ * Fluent Code → FlowLogicInstanceShape → prepare() → XML Record
69
+ * ↑ ↓
70
+ * CallExpressionShape ← buildArguments() ← parse() ← XML Record
71
+ * ```
72
+ */
73
+ export const FlowLogicPlugin = Plugin.create({
74
+ name: 'FlowLogicPlugin',
75
+ records: {
76
+ sys_hub_flow_logic_instance_v2: {
77
+ relationships: {
78
+ sys_hub_sub_flow_instance_v2: {
79
+ via: { parent_ui_id: 'ui_id' },
80
+ descendant: true,
81
+ },
82
+ sys_hub_action_instance_v2: {
83
+ via: { parent_ui_id: 'ui_id' },
84
+ descendant: true,
85
+ },
86
+ sys_hub_flow_logic_instance_v2: {
87
+ via: { parent_ui_id: 'ui_id' },
88
+ descendant: true,
89
+ },
90
+ },
91
+
92
+ async toShape(record, { transform, database, descendants }) {
93
+ const logicDefinition = record.get('logic_definition').asString().getValue()
94
+ const logicName = FlowLogicSysId.getLogicName(logicDefinition) as FLOW_LOGIC
95
+
96
+ if (!logicName || !(logicName in FLOW_LOGIC_SYS_ID_MAP)) {
97
+ return { success: false }
98
+ }
99
+ const logicBodyShapes: Shape[] = []
100
+ const flowSysId = record.get('flow').getValue()
101
+ const allDescendants = [
102
+ ...descendants.query('sys_hub_sub_flow_instance_v2', {
103
+ parent_ui_id: record.get('ui_id').getValue(),
104
+ flow: flowSysId, // This is to skip snapshot records
105
+ }),
106
+ ...descendants.query('sys_hub_action_instance_v2', {
107
+ parent_ui_id: record.get('ui_id').getValue(),
108
+ flow: flowSysId,
109
+ }),
110
+ ...descendants.query('sys_hub_flow_logic_instance_v2', {
111
+ parent_ui_id: record.get('ui_id').getValue(),
112
+ flow: flowSysId,
113
+ }),
114
+ ]
115
+
116
+ // Sort descendants by order field to ensure correct statement sequencing
117
+ allDescendants.sort((a, b) => getOrder(a) - getOrder(b))
118
+
119
+ for (const record of allDescendants) {
120
+ const result = await transform.recordToShape(record, database, FlowInstancePlugin, FlowLogicPlugin)
121
+ if (!result.success) {
122
+ return result
123
+ }
124
+ logicBodyShapes.push(result.value)
125
+ }
126
+
127
+ const flowLogicArguments: Shape<unknown>[] = getFlowLogicArguments(
128
+ logicName,
129
+ record,
130
+ logicBodyShapes,
131
+ database
132
+ )
133
+
134
+ const callExpression = new CallExpressionShape({
135
+ source: record,
136
+ callee: logicName,
137
+ args: flowLogicArguments,
138
+ })
139
+
140
+ if (logicName === FLOW_LOGIC.WAIT_FOR_A_DURATION) {
141
+ const order = record.get('order')?.getValue()
142
+ const variableName =
143
+ getDirectVariableIdentifier(record.getOriginalSource()) ?? `waitForDuration_${order}`
144
+
145
+ return {
146
+ success: true,
147
+ value: new VariableStatementShape({
148
+ source: record,
149
+ variableName,
150
+ initializer: callExpression,
151
+ isExported: false,
152
+ }),
153
+ }
154
+ }
155
+
156
+ return {
157
+ success: true,
158
+ value: callExpression,
159
+ }
160
+ },
161
+ },
162
+ },
163
+ shapes: [
164
+ {
165
+ shape: FlowLogicInstanceShape,
166
+ fileTypes: ['fluent'],
167
+ async toRecord(expr, { diagnostics, factory, transform, logger }) {
168
+ const result = await getFlowLogicInstanceRecord(expr, { diagnostics, factory, transform })
169
+ if (!result.success) {
170
+ return result
171
+ }
172
+ const instanceRecord = result.value
173
+ const allInstances: Shape[] = []
174
+ const functions: ArrowFunctionShape[] = []
175
+ const relatedRecords: Record[] = []
176
+ // Special handling for DoInParallel - create separate flow logic records for each arrow function
177
+ if (isDoInParallelShape(expr)) {
178
+ const parallelFunctions = expr.getParallelFunctions()
179
+ const mainUiId = instanceRecord.get('ui_id').getValue()
180
+ const mainNowId = instanceRecord.getId().getNowIdKey()
181
+
182
+ for (let index = 0; index < parallelFunctions.length; index++) {
183
+ const parallelFunction = parallelFunctions[index]
184
+ if (!parallelFunction) {
185
+ continue
186
+ }
187
+ const statements = parallelFunction
188
+ .getStatements()
189
+ .filter((stmt) => !(stmt instanceof UndefinedShape))
190
+ if (statements.length === 0) {
191
+ continue
192
+ }
193
+
194
+ const parallelBlockSysId = `${mainNowId}_block_${index}`
195
+
196
+ const parallelRecord = await factory.createRecord({
197
+ source: parallelFunction,
198
+ table: 'sys_hub_flow_logic_instance_v2',
199
+ explicitId: parallelBlockSysId,
200
+ properties: {
201
+ logic_definition: DO_IN_PARALLEL_BLOCK_SYS_ID,
202
+ values: createEmptyFlowLogicValues(),
203
+ },
204
+ })
205
+
206
+ const parallelUiId = sysIdToUuid(parallelRecord.getId().getValue())
207
+ const finalParallelRecord = await parallelRecord.merge({
208
+ ui_id: parallelUiId,
209
+ parent_ui_id: mainUiId,
210
+ })
211
+
212
+ relatedRecords.push(finalParallelRecord)
213
+
214
+ // Process statements within this parallel function
215
+ parallelFunction
216
+ .getStatements()
217
+ .filter((stmt) => !(stmt instanceof UndefinedShape))
218
+ .forEach((stmt) => {
219
+ const record = stmt.is(VariableStatementShape)
220
+ ? stmt.getInitializer()?.asRecord()
221
+ : stmt.asRecord()
222
+ if (record) {
223
+ relatedRecords.push(record.merge({ parent_ui_id: parallelUiId }))
224
+ }
225
+ })
226
+ }
227
+
228
+ return { success: true, value: instanceRecord.with(...relatedRecords) }
229
+ }
230
+
231
+ // Standard handling for other flow logic types
232
+ if (isConditionalLogicShape(expr) || isForEachShape(expr)) {
233
+ functions.push(expr.getBody())
234
+ }
235
+ functions.forEach((fn) => {
236
+ allInstances.push(...(fn.getStatements().filter((stmt) => !(stmt instanceof UndefinedShape)) ?? []))
237
+ })
238
+
239
+ // for instances with body, set parent_ui_id for child records
240
+ for (const [, v] of (allInstances ?? []).entries()) {
241
+ const record = await getRecordFromFlowInstaceShape(v, transform)
242
+
243
+ if (record) {
244
+ if (isForEachShape(expr)) {
245
+ // Get the parameter name from the forEach arrow function
246
+ const forEachBody = expr.getBody()
247
+ const parameters = forEachBody.getParameters()
248
+ const parameterName =
249
+ parameters.length > 0 && parameters[0] ? parameters[0].getName() : 'item'
250
+ const updatedRecord = updateRecordsWithDataPills(
251
+ record,
252
+ instanceRecord,
253
+ parameterName,
254
+ logger
255
+ )
256
+
257
+ relatedRecords.push(
258
+ updatedRecord.merge({
259
+ parent_ui_id: instanceRecord.get('ui_id').getValue(),
260
+ })
261
+ )
262
+ } else {
263
+ relatedRecords.push(record.merge({ parent_ui_id: instanceRecord.get('ui_id').getValue() }))
264
+ }
265
+ }
266
+ }
267
+
268
+ return { success: true, value: instanceRecord.with(...relatedRecords) }
269
+ },
270
+ },
271
+ ],
272
+ })
273
+
274
+ /**
275
+ * Recursively updates data pill references in forEach loop records
276
+ *
277
+ * When a forEach loop is processed, data pills referencing the loop item need to be updated
278
+ * to use the forEach instance's UUID instead of the generic 'forEach' prefix.
279
+ *
280
+ * This function:
281
+ * - Recursively processes a record and all its related records
282
+ * - Data pill references are updated by decompressing the 'values' field, performing string replacement,
283
+ * and re-compressing the result
284
+ * - Relationships between records are preserved through the recursive update process
285
+ * - Only replaces data pills that match the specific parameter name to handle nested forEach loops correctly
286
+ * - The parameterName is used for matching, but the output always uses 'item' (ServiceNow platform requirement)
287
+ *
288
+ * @param record - The record to update
289
+ * @param instanceRecord - The forEach instance record containing the UUID
290
+ * @param parameterName - The arrow function parameter name used for matching (e.g., 'dept', 'category')
291
+ *
292
+ * @example
293
+ * // Outer forEach with parameterName='dept'
294
+ * // Before: `{{forEach.dept.name}}`
295
+ * // After: `{{outerUUID.item.name}}`
296
+ *
297
+ * @example
298
+ * // Nested forEach: inner loop with parameterName='category' won't replace `{{forEach.dept.name}}`
299
+ * // Before: `{{forEach.category.name}}` and `{{forEach.dept.manager}}`
300
+ * // After: `{{innerUUID.item.name}}` and `{{forEach.dept.manager}}` (dept unchanged by inner loop)
301
+ */
302
+ function updateRecordsWithDataPills(
303
+ record: Record,
304
+ instanceRecord: Record,
305
+ parameterName: string,
306
+ logger: Logger
307
+ ): Record {
308
+ const relatedRecords = record.getRelated()
309
+
310
+ const valuesJson = record.get('values')?.getValue()
311
+
312
+ if (!valuesJson) {
313
+ return record
314
+ }
315
+
316
+ try {
317
+ // Create a regex that matches {{forEach.parameterName followed by . or }} or |
318
+ // This ensures we only replace pills for this specific forEach parameter
319
+ // The parameterName is used for matching, but always replaced with 'item' in the output
320
+ // The pattern must include | to handle type annotations like {{forEach.user|reference}}
321
+ const pattern = new RegExp(`\\{\\{forEach\\.${parameterName}([.}|])`, 'g')
322
+ const replacement = `{{${instanceRecord.get('ui_id').getValue()}.item$1`
323
+ const updatedValuesJson = JSON.stringify(valuesJson).replace(pattern, replacement)
324
+
325
+ const updatedRecord = record.merge({
326
+ values: JSON.parse(updatedValuesJson),
327
+ })
328
+ const updatedRelatedRecords: Record[] = []
329
+ for (const rec of relatedRecords) {
330
+ updatedRelatedRecords.push(updateRecordsWithDataPills(rec, instanceRecord, parameterName, logger))
331
+ }
332
+ return updatedRecord.with(...updatedRelatedRecords)
333
+ } catch (error) {
334
+ logger.error(`Failed to update data pills in forEach record: ${error instanceof Error ? error.message : error}`)
335
+ return record.with(...relatedRecords)
336
+ }
337
+ }
@@ -0,0 +1,215 @@
1
+ import {
2
+ type Source,
3
+ ObjectShape,
4
+ type Record,
5
+ type StringShape,
6
+ PropertyAccessShape,
7
+ } from '@servicenow/sdk-build-core'
8
+ import { ArrowFunctionShape } from '../../arrow-function-plugin'
9
+ import { NowIdShape } from '../../now-id-plugin'
10
+ import { FLOW_LOGIC } from './flow-logic-constants'
11
+ import { FDInstanceShape } from '../utils/flow-shapes'
12
+
13
+ /**
14
+ * Base class for flow logic constructs that use config + additional arguments pattern.
15
+ * Provides common functionality for accessing config, sysId, and annotation.
16
+ */
17
+ export class FlowLogicInstanceShape extends FDInstanceShape {
18
+ getConfig(): ObjectShape {
19
+ return this.getArgument(0).as(ObjectShape)
20
+ }
21
+
22
+ getSysId(): NowIdShape {
23
+ return this.getConfig().get('$id').as(NowIdShape)
24
+ }
25
+
26
+ getAnnotation(): StringShape | undefined {
27
+ const annotationShape = this.getConfig().get('annotation')
28
+ if (annotationShape?.isUndefined()) {
29
+ return undefined
30
+ }
31
+ return annotationShape?.asString() ?? undefined
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Shape class for conditional flow logic constructs (If/ElseIf/Else).
37
+ * Handles the pattern: If/ElseIf/Else(config, body)
38
+ *
39
+ * @example
40
+ * If({ $id: Now.ID['if_1'], condition: 'user.role === "admin"', label: 'Admin Check' }, () => { ... })
41
+ * ElseIf({ $id: Now.ID['elseif_1'], condition: 'user.role === "user"' }, () => { ... })
42
+ * Else({ $id: Now.ID['else_1'], annotation: 'Default case' }, () => { ... })
43
+ */
44
+ export class ConditionalLogicInstanceShape extends FlowLogicInstanceShape {
45
+ getBody(): ArrowFunctionShape {
46
+ return this.getArgument(1).as(ArrowFunctionShape)
47
+ }
48
+
49
+ getCondition(): StringShape | undefined {
50
+ return this.getConfig().get('condition')?.asString()
51
+ }
52
+
53
+ getLabel(): StringShape | undefined {
54
+ return this.getConfig().get('label')?.asString()
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Shape class for ForEach loop logic.
60
+ * Handles the pattern: ForEach(config, items, body)
61
+ *
62
+ * @example
63
+ * ForEach({ $id: Now.ID['foreach_1'], annotation: 'Process items' }, ['a', 'b', 'c'], (item) => { ... })
64
+ */
65
+ export class ForEachInstanceShape extends FlowLogicInstanceShape {
66
+ override getConfig(): ObjectShape {
67
+ return this.getArgument(1).as(ObjectShape)
68
+ }
69
+
70
+ getItems(): PropertyAccessShape {
71
+ return this.getArgument(0, false).as(PropertyAccessShape)
72
+ }
73
+
74
+ getBody(): ArrowFunctionShape {
75
+ return this.getArgument(2).as(ArrowFunctionShape)
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Shape class for GoBackTo navigation logic.
81
+ * Handles the pattern: GoBackTo(config, step)
82
+ *
83
+ * @example
84
+ * GoBackTo({ $id: Now.ID['goback_1'], annotation: 'Retry logic' }, previousStep)
85
+ */
86
+ export class GoBackToInstanceShape extends FlowLogicInstanceShape {
87
+ getStep(): Record | StringShape {
88
+ const step = this.getArgument(1)
89
+ return step?.isRecord() ? step.asRecord() : step?.asString()
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Shape class for TryCatch error handling logic.
95
+ * Handles the pattern: TryCatch(config, handlers)
96
+ *
97
+ * @example
98
+ * TryCatch({ $id: Now.ID['trycatch_1'] }, { try: tryFn, catch: catchFn })
99
+ */
100
+ export class TryCatchInstanceShape extends FlowLogicInstanceShape {
101
+ getHandlers(): ObjectShape {
102
+ return this.getArgument(1)?.as(ObjectShape)
103
+ }
104
+
105
+ getTryHandler(): ArrowFunctionShape {
106
+ return this.getHandlers()?.get('try')?.as(ArrowFunctionShape)
107
+ }
108
+
109
+ getCatchHandler(): ArrowFunctionShape {
110
+ return this.getHandlers()?.get('catch')?.as(ArrowFunctionShape)
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Shape class for SetFlowVariables logic.
116
+ * Handles the pattern: SetFlowVariables(config, variables)
117
+ *
118
+ * @example
119
+ * SetFlowVariables({ $id: Now.ID['set_flow_variables_1'] }, _params.flow_variables, { variable1: 'value1', variable2: 'value2' })
120
+ */
121
+ export class SetFlowVariablesInstanceShape extends FlowLogicInstanceShape {
122
+ getVariablesToSet(): ObjectShape {
123
+ return this.getArgument(2)?.as(ObjectShape)
124
+ }
125
+
126
+ getVariablesToSetAsString(): string {
127
+ const variables = this.getVariablesToSet()
128
+ const entries = variables.entries({ resolve: false })
129
+ return Array.from(entries, ([key]) => key).join(',')
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Shape class for AssignSubflowOutputs logic.
135
+ * Handles the pattern: AssignSubflowOutputs(config, outputs)
136
+ *
137
+ * @example
138
+ * AssignSubflowOutputs({ $id: Now.ID['assign_subflow_outputs_1'] }, _params.outputs, { output1: 'value1', output2: 'value2' })
139
+ */
140
+ export class AssignSubflowOutputsInstanceShape extends FlowLogicInstanceShape {
141
+ getAssignedSubflowOutputs(): ObjectShape {
142
+ return this.getArgument(2)?.as(ObjectShape)
143
+ }
144
+
145
+ getAssignedSubflowOutputsAsString(): string {
146
+ const assignedSubflowOutputs = this.getAssignedSubflowOutputs()
147
+ const entries = assignedSubflowOutputs.entries({ resolve: false })
148
+ return Array.from(entries, ([key]) => key).join(',')
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Shape class for DoInParallel execution logic.
154
+ * Handles the pattern: DoInParallel(config, ...functions)
155
+ *
156
+ * @example
157
+ * DoInParallel({ $id: Now.ID['do_in_parallel_1'] }, fn1, fn2, fn3)
158
+ */
159
+ export class DoInParallelInstanceShape extends FlowLogicInstanceShape {
160
+ getParallelFunctions(): ArrowFunctionShape[] {
161
+ const functions: ArrowFunctionShape[] = []
162
+ const allArgs = this.getArguments()
163
+ // Start from argument 1 (after config) and collect all arrow functions
164
+ for (let i = 1; i < allArgs.length; i++) {
165
+ const arg = this.getArgument(i)
166
+ if (arg) {
167
+ functions.push(arg.as(ArrowFunctionShape))
168
+ }
169
+ }
170
+ return functions
171
+ }
172
+
173
+ getParallelFunctionCount(): number {
174
+ return this.getArguments().length - 1 // Subtract 1 for config argument
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Factory function to create the appropriate specific flow logic shape based on the logic type.
180
+ * This provides type-safe access to flow logic constructs while maintaining backward compatibility.
181
+ *
182
+ * @param expr - The CallExpressionShape to convert
183
+ * @param callee - The flow logic type (If, ElseIf, Else, ForEach, etc.)
184
+ * @param args - The arguments for the flow logic construct
185
+ * @returns The appropriate specific shape instance
186
+ */
187
+ export function createFlowLogicInstanceShape(expr: Source, callee: string, args: unknown[]): FlowLogicInstanceShape {
188
+ switch (callee) {
189
+ case FLOW_LOGIC.IF:
190
+ case FLOW_LOGIC.ELSEIF:
191
+ case FLOW_LOGIC.ELSE:
192
+ return new ConditionalLogicInstanceShape(expr, callee, args)
193
+ case FLOW_LOGIC.FOR_EACH:
194
+ return new ForEachInstanceShape(expr, callee, args)
195
+ case FLOW_LOGIC.GOBACKTO:
196
+ return new GoBackToInstanceShape(expr, callee, args)
197
+ case FLOW_LOGIC.TRY_CATCH:
198
+ return new TryCatchInstanceShape(expr, callee, args)
199
+ case FLOW_LOGIC.DO_IN_PARALLEL:
200
+ return new DoInParallelInstanceShape(expr, callee, args)
201
+ case FLOW_LOGIC.SET_FLOW_VARIABLES:
202
+ return new SetFlowVariablesInstanceShape(expr, callee, args)
203
+ case FLOW_LOGIC.ASSIGN_SUBFLOW_OUTPUTS:
204
+ return new AssignSubflowOutputsInstanceShape(expr, callee, args)
205
+ case FLOW_LOGIC.WAIT_FOR_A_DURATION:
206
+ case FLOW_LOGIC.ENDFLOW:
207
+ case FLOW_LOGIC.EXITLOOP:
208
+ case FLOW_LOGIC.SKIP_ITERATION:
209
+ return new FlowLogicInstanceShape(expr, callee, args)
210
+
211
+ default:
212
+ // Fallback to the deprecated generic shape for unknown types
213
+ throw new Error(`Unknown flow logic type: ${callee}`)
214
+ }
215
+ }
@@ -0,0 +1,48 @@
1
+ import { Plugin } from '@servicenow/sdk-build-core'
2
+ import { APPROVAL_DUE_DATE_API_NAME, APPROVAL_RULES_API_NAME } from '../utils/flow-constants'
3
+ import { ApprovalDueDateShape, ApprovalRulesShape } from '../utils/flow-shapes'
4
+ import { getCallExpressionName } from '../../utils'
5
+
6
+ export const ApprovalRulesPlugin = Plugin.create({
7
+ name: 'ApprovalRulesPlugin',
8
+ nodes: [
9
+ {
10
+ node: 'CallExpression',
11
+ fileTypes: ['fluent'],
12
+ entryPoint: true,
13
+ async toShape(node, { transform }) {
14
+ const callee = getCallExpressionName(node)
15
+ if (callee !== APPROVAL_RULES_API_NAME && callee !== APPROVAL_DUE_DATE_API_NAME) {
16
+ return { success: false }
17
+ }
18
+ const nodeData = node.getArguments()[0]
19
+
20
+ if (!nodeData) {
21
+ return { success: false }
22
+ }
23
+
24
+ const result = await transform.toShape(nodeData)
25
+ if (!result.success) {
26
+ return result
27
+ }
28
+ const value = result.value.asObject().properties({ resolve: false })
29
+ if (callee === APPROVAL_DUE_DATE_API_NAME) {
30
+ return {
31
+ success: true,
32
+ value: new ApprovalDueDateShape({
33
+ source: node,
34
+ value: value,
35
+ }),
36
+ }
37
+ }
38
+ return {
39
+ success: true,
40
+ value: new ApprovalRulesShape({
41
+ source: node,
42
+ value: value,
43
+ }),
44
+ }
45
+ },
46
+ },
47
+ ],
48
+ })