@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,1205 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowInstancePlugin = void 0;
4
+ exports.normalizeInputValue = normalizeInputValue;
5
+ const sdk_build_core_1 = require("@servicenow/sdk-build-core");
6
+ const now_id_plugin_1 = require("../../now-id-plugin");
7
+ const node_zlib_1 = require("node:zlib");
8
+ const complex_object_resolver_1 = require("../utils/complex-object-resolver");
9
+ const utils_1 = require("../utils/utils");
10
+ const service_catalog_1 = require("../utils/service-catalog");
11
+ const schema_to_flow_object_1 = require("../utils/schema-to-flow-object");
12
+ const flow_shapes_1 = require("../utils/flow-shapes");
13
+ const inline_script_plugin_1 = require("./inline-script-plugin");
14
+ const flow_constants_1 = require("../utils/flow-constants");
15
+ /**
16
+ * Helper function to check if a field is hidden based on visible or visible_in_fd attributes
17
+ * @param attributes The attributes string from the field definition
18
+ * @returns true if the field has visible='false' or visible_in_fd='false'
19
+ */
20
+ function isHiddenField(attributes) {
21
+ if (!attributes) {
22
+ return false;
23
+ }
24
+ const visibleAttr = (0, schema_to_flow_object_1.getAttributeValue)(attributes, 'visible');
25
+ const visibleInFdAttr = (0, schema_to_flow_object_1.getAttributeValue)(attributes, 'visible_in_fd');
26
+ return visibleAttr === 'false' || visibleInFdAttr === 'false';
27
+ }
28
+ /**
29
+ * Parses a complex object format where values are nested under $cv.$v
30
+ * @param obj The complex object to parse
31
+ * @returns A simplified object with direct values
32
+ */
33
+ function parseComplexObjectValues(obj) {
34
+ /**
35
+ * Recursively parse a value that may contain Flow Designer complex-object wrappers.
36
+ * Handles:
37
+ * • Primitive values – returned as-is
38
+ * • Objects with `$cv` – unwrap to `$cv.$v`
39
+ * • Objects with `$COCollectionField` – treat as an array and recurse
40
+ * • Arrays – recurse over each element
41
+ * • Plain objects – recurse over each property
42
+ */
43
+ const parseValue = (val) => {
44
+ if (val === null || val === undefined) {
45
+ return val;
46
+ }
47
+ // Arrays – recurse element-wise
48
+ if (Array.isArray(val)) {
49
+ return val.map(parseValue);
50
+ }
51
+ // Objects
52
+ if (typeof val === 'object') {
53
+ const obj = val;
54
+ // Direct complex-value wrapper
55
+ if ('$cv' in obj) {
56
+ const cv = obj['$cv'];
57
+ return parseValue(cv?.['$v']);
58
+ }
59
+ // Flow Designer collection array wrapper
60
+ if ('$COCollectionField' in obj) {
61
+ return parseValue(obj['$COCollectionField']);
62
+ }
63
+ // Plain object – recurse on each property
64
+ const out = {};
65
+ for (const [k, v] of Object.entries(val)) {
66
+ out[k] = parseValue(v);
67
+ }
68
+ return out;
69
+ }
70
+ // Primitive
71
+ return val;
72
+ };
73
+ return parseValue(obj);
74
+ }
75
+ /**
76
+ * Normalize raw input value based on uiType.
77
+ * - Attempts to JSON.parse strings.
78
+ * - Resolves FlowDesigner complexObject structures via parseComplexObjectValues.
79
+ * - For array uiTypes, ensures the result is an array (falling back to raw).
80
+ * - For glide_time, parses the time string and returns a TimeShape object.
81
+ * - For glide_duration, parses the duration string and returns a DurationShape object.
82
+ * - For template_value, parses the time string and returns a TemplateValueShape object.
83
+ */
84
+ function normalizeInputValue(value, uiType, source, logger) {
85
+ // Handle glide_time type specially - parse the time string and return TimeShape
86
+ if (source) {
87
+ try {
88
+ if (uiType === flow_constants_1.TIME_DATA_TYPE_VALUE) {
89
+ // Create a StringShape from the value and use TimeShape.from() to parse it.
90
+ // Uses UTC timezone value to show in fluent flow to be in sync with Flow designer UI
91
+ return sdk_build_core_1.TimeShape.from(source, sdk_build_core_1.Shape.from(source, value).asString(), flow_constants_1.UTC_TIMEZONE_VALUE);
92
+ }
93
+ else if (uiType === flow_constants_1.DURATION_DATA_TYPE_VALUE) {
94
+ // Create a StringShape from the value and use DurationShape.from() to parse it
95
+ return sdk_build_core_1.DurationShape.from(source, sdk_build_core_1.Shape.from(source, value).asString());
96
+ }
97
+ else if (uiType === flow_constants_1.TEMPLATE_DATA_TYPE_VALUE) {
98
+ // Create a StringShape from the value and use TemplateValueShape.from() to parse it
99
+ return sdk_build_core_1.TemplateValueShape.from(source, sdk_build_core_1.Shape.from(source, value).asString());
100
+ }
101
+ else if (uiType === flow_constants_1.APPROVAL_RULES_DATA_TYPE_VALUE) {
102
+ // Create a StringShape from the value and use ApprovalRulesShape.from() to parse it
103
+ return flow_shapes_1.ApprovalRulesShape.from(source, sdk_build_core_1.Shape.from(source, value).asString());
104
+ }
105
+ else if (uiType === flow_constants_1.APPROVAL_DUE_DATE_DATA_TYPE_VALUE) {
106
+ // Check if source is a Record before accessing action_type
107
+ if (source instanceof sdk_build_core_1.Record) {
108
+ const actionType = source.get(flow_constants_1.ACTION_TYPE_KEY_NAME)?.ifDefined()?.asString()?.getValue();
109
+ if (flow_constants_1.APPROVAL_DUE_DATE_INPUT_FIELD_ACTIONS.includes(actionType)) {
110
+ // Create a StringShape from the value and use ApprovalDueDateShape.from() to parse it
111
+ return flow_shapes_1.ApprovalDueDateShape.from(source, sdk_build_core_1.Shape.from(source, value).asString());
112
+ }
113
+ }
114
+ }
115
+ }
116
+ catch (e) {
117
+ // If parsing fails, fall through to normal handling
118
+ logger?.error(`Failed to parse value ${value} for ${uiType} in record ${source}: ${e instanceof Error ? e.message : e}`);
119
+ return value;
120
+ }
121
+ }
122
+ let parsed = value;
123
+ try {
124
+ if (uiType !== 'string') {
125
+ parsed = JSON.parse(value);
126
+ }
127
+ }
128
+ catch {
129
+ // handle internal string types
130
+ if (uiType === 'glide_list') {
131
+ // comma separated sys_ids – return [] if empty
132
+ return value && value.trim() !== '' ? value.split(',') : [];
133
+ }
134
+ return value; // any string literal value (other than a valid stringified JSON)
135
+ }
136
+ if (parsed && typeof parsed === 'object' && 'complexObject' in parsed) {
137
+ return parseComplexObjectValues(parsed.complexObject);
138
+ }
139
+ if (uiType?.startsWith('array')) {
140
+ return Array.isArray(parsed) ? parsed : value;
141
+ }
142
+ /**
143
+ * Handle internal non-string types for primitive data types
144
+ * Ex. Instances store boolean values as '1' or '0' instead of true or false. But we show it as true/false in UI/fluent
145
+ */
146
+ if (uiType === 'boolean') {
147
+ parsed = Boolean(parsed); // 1 or true = true, 0 or false = false
148
+ }
149
+ return parsed;
150
+ }
151
+ function buildInstanceToShape({ defColumn, // e.g. "action_type" | "subflow"
152
+ inputsTableName, // e.g. "sys_hub_action_input" | "sys_hub_flow_input"
153
+ zippedColumn, // e.g. "values" | "subflow_inputs"
154
+ callee, // "wfa.action" | "wfa.subflow"
155
+ }) {
156
+ return function toShape(record, { database, logger }) {
157
+ // Resolve the instance definition - either from the source shape or from the database record
158
+ const source = record.getSource();
159
+ const instanceDef = source instanceof flow_shapes_1.ActionSubflowInstanceShape
160
+ ? source.getInstanceDefinition()
161
+ : record.get(defColumn)?.ifDefined()?.asString();
162
+ const definitionInputs = instanceDef instanceof sdk_build_core_1.Record
163
+ ? instanceDef.flat().filter((v) => v.getTable() === inputsTableName)
164
+ : undefined;
165
+ const zippedInputs = record.get(zippedColumn)?.ifString()?.getValue() ?? '';
166
+ // ── Identifier discovery ────────────────────────────────────────────────
167
+ let identifierShapeOrSysId = instanceDef;
168
+ if (instanceDef instanceof sdk_build_core_1.Record) {
169
+ // check for core actions in existing fluent code, if so below condition will keep the existing identifier.
170
+ // Otherwise action.core.log will be replaced with the log.
171
+ const sysId = instanceDef.getId().getValue();
172
+ const coreActionIdentifier = (0, utils_1.getCoreActionIdentifier)(sysId);
173
+ if (coreActionIdentifier) {
174
+ identifierShapeOrSysId = new sdk_build_core_1.IdentifierShape({
175
+ source: record,
176
+ name: coreActionIdentifier,
177
+ });
178
+ }
179
+ else {
180
+ const original = instanceDef.getOriginalSource();
181
+ if (sdk_build_core_1.ts.Node.isNode(original)) {
182
+ const varDecl = original.getFirstAncestorByKind(sdk_build_core_1.ts.SyntaxKind.VariableDeclaration);
183
+ const idNode = varDecl?.getNameNode();
184
+ if (idNode) {
185
+ identifierShapeOrSysId = new sdk_build_core_1.IdentifierShape({
186
+ source: idNode,
187
+ name: idNode.getText(),
188
+ });
189
+ }
190
+ }
191
+ }
192
+ }
193
+ else {
194
+ // When definition is not a Record, try to resolve from database by sys_id
195
+ if (defColumn === flow_constants_1.ACTION_DEF_COLUMN_NAME) {
196
+ const sysId = instanceDef?.ifString()?.getValue();
197
+ if (!sysId) {
198
+ return { success: false };
199
+ }
200
+ const coreActionIdentifier = (0, utils_1.getCoreActionIdentifier)(sysId);
201
+ if (callee === flow_constants_1.ACTION_INSTANCE_API_NAME && !coreActionIdentifier) {
202
+ logger.warn(`Custom actions are not supported, action = ${sysId}`);
203
+ return { success: false };
204
+ }
205
+ const action = database
206
+ .query('sys_hub_action_type_definition')
207
+ .find((v) => v.getId().getValue() === sysId);
208
+ const actionSource = action?.getSource();
209
+ if (actionSource instanceof sdk_build_core_1.CallExpressionShape) {
210
+ const identifierName = (0, utils_1.getIdentifierFromShape)(actionSource);
211
+ if (identifierName) {
212
+ identifierShapeOrSysId = new sdk_build_core_1.IdentifierShape({
213
+ source: actionSource.getOriginalSource(),
214
+ name: identifierName,
215
+ });
216
+ }
217
+ }
218
+ else if (coreActionIdentifier) {
219
+ //Special case handling for core actions
220
+ identifierShapeOrSysId = new sdk_build_core_1.IdentifierShape({ source: record, name: coreActionIdentifier });
221
+ }
222
+ }
223
+ else if (defColumn === 'subflow') {
224
+ const sysId = instanceDef?.getValue();
225
+ const subflow = database.query('sys_hub_flow').find((v) => v.getId().getValue() === sysId);
226
+ const actionSource = subflow?.getSource();
227
+ if (actionSource instanceof sdk_build_core_1.CallExpressionShape) {
228
+ const identifierName = (0, utils_1.getIdentifierFromShape)(actionSource);
229
+ if (identifierName) {
230
+ identifierShapeOrSysId = new sdk_build_core_1.IdentifierShape({
231
+ source: actionSource.getOriginalSource(),
232
+ name: identifierName,
233
+ });
234
+ }
235
+ }
236
+ }
237
+ }
238
+ let inputsShape = buildInputsShapeFromZipped({
239
+ zippedInputs,
240
+ definitionInputs,
241
+ actionDefinition: instanceDef,
242
+ record,
243
+ logger,
244
+ database,
245
+ });
246
+ if (inputsShape === undefined) {
247
+ return { success: false };
248
+ }
249
+ const waitForCompletion = record.get('wait_for_completion')?.getValue() === true ||
250
+ record.get('wait_for_completion')?.getValue() === 'true';
251
+ if (waitForCompletion) {
252
+ inputsShape = inputsShape
253
+ ? inputsShape.merge({ waitForCompletion })
254
+ : sdk_build_core_1.Shape.from(record, { waitForCompletion }).asObject();
255
+ }
256
+ const configArg = new sdk_build_core_1.ObjectShape({
257
+ source: record,
258
+ properties: record.transform(({ $ }) => ({
259
+ $id: $.val(now_id_plugin_1.NowIdShape.from(record)),
260
+ annotation: $.from('comment').def(''),
261
+ uuid: $.from('ui_id').def(''),
262
+ })),
263
+ });
264
+ // Create the CallExpressionShape for the action/subflow instance
265
+ const callExpression = new sdk_build_core_1.CallExpressionShape({
266
+ source: record,
267
+ callee,
268
+ args: [identifierShapeOrSysId, configArg, inputsShape],
269
+ });
270
+ // Generate variable name from existing source or fallback to callee + ID
271
+ const order = record.get('order')?.getValue();
272
+ let identifierPrefix = '';
273
+ if (callee.toLowerCase() === flow_constants_1.ACTION_INSTANCE_API_NAME) {
274
+ identifierPrefix = 'action';
275
+ }
276
+ else if (callee.toLowerCase() === flow_constants_1.SUBFLOW_INSTANCE_API_NAME) {
277
+ identifierPrefix = 'subflow';
278
+ }
279
+ // Use getDirectVariableIdentifier to only check direct parent VariableDeclaration
280
+ // This prevents actions inside Subflows from inheriting the parent Subflow's variable name
281
+ const variableName = (0, utils_1.getDirectVariableIdentifier)(record.getOriginalSource()) ?? `${identifierPrefix}Instance_${order}`; // _${instanceId.slice(0, 8)}`
282
+ // Wrap in VariableStatementShape with isExported: false
283
+ return {
284
+ success: true,
285
+ value: new sdk_build_core_1.VariableStatementShape({
286
+ source: record,
287
+ variableName,
288
+ initializer: callExpression,
289
+ isExported: false,
290
+ }),
291
+ };
292
+ };
293
+ }
294
+ /**
295
+ * Validates that all property accesses on a getCatalogVariables action output variable
296
+ * are declared in its catalog_variables input.
297
+ *
298
+ * Runs once per getCatalogVariables action instance (forward search from declaration to usages)
299
+ * rather than once per template expression (backward search from usage to declaration).
300
+ */
301
+ function validateCatalogVariableOutputReferences(callExpression, instanceInputs, diagnostics) {
302
+ // Extract allowed variable names from the catalog_variables input
303
+ const catalogVarsShape = instanceInputs.get('catalog_variables');
304
+ if (!catalogVarsShape) {
305
+ return;
306
+ }
307
+ const allowedVariables = [];
308
+ if (catalogVarsShape.isArray()) {
309
+ for (const el of catalogVarsShape.asArray().getElements(false)) {
310
+ if (el instanceof sdk_build_core_1.PropertyAccessShape) {
311
+ const propElements = el.getElements();
312
+ const lastEl = propElements[propElements.length - 1];
313
+ if (lastEl instanceof sdk_build_core_1.IdentifierShape) {
314
+ allowedVariables.push(lastEl.getName());
315
+ }
316
+ }
317
+ }
318
+ }
319
+ if (allowedVariables.length === 0) {
320
+ return;
321
+ }
322
+ // Navigate from the wfa.action(...) call to its parent variable declaration
323
+ const originalNode = callExpression.getOriginalNode();
324
+ if (!sdk_build_core_1.ts.Node.isCallExpression(originalNode)) {
325
+ return;
326
+ }
327
+ const parent = originalNode.getParent();
328
+ if (!sdk_build_core_1.ts.Node.isVariableDeclaration(parent)) {
329
+ return;
330
+ }
331
+ const nameNode = parent.getNameNode();
332
+ if (!sdk_build_core_1.ts.Node.isIdentifier(nameNode)) {
333
+ return;
334
+ }
335
+ // Find all references to the action output variable and validate each property access
336
+ for (const ref of nameNode.findReferencesAsNodes()) {
337
+ const refParent = ref.getParent();
338
+ if (!sdk_build_core_1.ts.Node.isPropertyAccessExpression(refParent)) {
339
+ continue;
340
+ }
341
+ if (refParent.getExpression() !== ref) {
342
+ continue;
343
+ } // ref must be the object base, not the property name
344
+ const propertyName = refParent.getName();
345
+ if (propertyName && !allowedVariables.includes(propertyName)) {
346
+ diagnostics.error(catalogVarsShape, `Property '${propertyName}' is not available in the getCatalogVariables output. ` +
347
+ `Only the following variables are accessible: ${allowedVariables.join(', ')}. ` +
348
+ `Please add '${propertyName}' to the catalog_variables input if you need to access it.`);
349
+ }
350
+ }
351
+ }
352
+ exports.FlowInstancePlugin = sdk_build_core_1.Plugin.create({
353
+ name: 'FlowInstancePlugin',
354
+ records: {
355
+ sys_hub_action_instance_v2: {
356
+ toShape: buildInstanceToShape({
357
+ defColumn: flow_constants_1.ACTION_DEF_COLUMN_NAME,
358
+ inputsTableName: 'sys_hub_action_input',
359
+ zippedColumn: 'values',
360
+ callee: flow_constants_1.ACTION_INSTANCE_API_NAME,
361
+ }),
362
+ },
363
+ sys_hub_sub_flow_instance_v2: {
364
+ toShape: buildInstanceToShape({
365
+ defColumn: 'subflow',
366
+ inputsTableName: 'sys_hub_flow_input',
367
+ zippedColumn: 'subflow_inputs',
368
+ callee: flow_constants_1.SUBFLOW_INSTANCE_API_NAME,
369
+ }),
370
+ },
371
+ },
372
+ shapes: [
373
+ {
374
+ // Look for FDInstanceShape and return instance records as needed for Flow plugin
375
+ shape: flow_shapes_1.ActionSubflowInstanceShape,
376
+ fileTypes: ['fluent'],
377
+ async toRecord(callExpression, { factory, transform, diagnostics, logger }) {
378
+ const instanceType = callExpression.getInstanceType();
379
+ // Shortcut for unsupported instance types
380
+ if (instanceType !== flow_constants_1.ACTION_INSTANCE_API_NAME && instanceType !== flow_constants_1.SUBFLOW_INSTANCE_API_NAME) {
381
+ return { success: false };
382
+ }
383
+ const instanceParentDef = callExpression.getInstanceDefinition();
384
+ const instanceSysId = callExpression.getSysId();
385
+ const instanceInputs = callExpression.getInstanceProps();
386
+ const instanceAnnotation = callExpression.getAnnotation()?.getValue();
387
+ const instanceUUID = callExpression.getInstanceUUID()?.getValue();
388
+ if (!instanceInputs || !instanceSysId || !instanceParentDef) {
389
+ diagnostics.error(callExpression, `Failed to extract inputs, sysId, or definition from ${instanceType}`);
390
+ return { success: false };
391
+ }
392
+ let instanceRecord;
393
+ if (instanceType === flow_constants_1.ACTION_INSTANCE_API_NAME) {
394
+ // Validate getCatalogVariables output references once, from the declaration
395
+ if (instanceParentDef?.isRecord()) {
396
+ const actionSysId = instanceParentDef.as(sdk_build_core_1.Record).getId().getValue();
397
+ const actionName = flow_constants_1.CORE_ACTIONS_SYS_ID_NAME_MAP[actionSysId];
398
+ if (actionName === 'getCatalogVariables') {
399
+ validateCatalogVariableOutputReferences(callExpression, instanceInputs, diagnostics);
400
+ }
401
+ }
402
+ instanceRecord = await buildActionInstance({
403
+ actionDef: instanceParentDef,
404
+ inputs: instanceInputs,
405
+ sysId: instanceSysId,
406
+ annotation: instanceAnnotation,
407
+ uuid: instanceUUID,
408
+ factory,
409
+ source: callExpression,
410
+ transform,
411
+ logger,
412
+ });
413
+ }
414
+ else if (instanceType === flow_constants_1.SUBFLOW_INSTANCE_API_NAME) {
415
+ instanceRecord = await buildSubflowInstance({
416
+ subflowDef: instanceParentDef,
417
+ inputs: instanceInputs,
418
+ sysId: instanceSysId,
419
+ annotation: instanceAnnotation,
420
+ uuid: instanceUUID,
421
+ factory,
422
+ source: callExpression,
423
+ transform,
424
+ });
425
+ }
426
+ return instanceRecord ? { success: true, value: instanceRecord } : { success: false };
427
+ },
428
+ },
429
+ ],
430
+ });
431
+ // -------------------------
432
+ // Shared helpers
433
+ // -------------------------
434
+ /**
435
+ * Builds an FDInlineScriptCallShape from XML inline script data.
436
+ *
437
+ * **Inline Script Detection:**
438
+ * Detects inputs with `scriptActive: true` and extracts the script content from
439
+ * the `script[fieldName].script` property. Creates an FDInlineScriptCallShape that represents
440
+ * `wfa.inlineScript('script content')` in Fluent code.
441
+ *
442
+ * @param fieldName - The name of the input field
443
+ * @param scriptActive - Whether this field contains an active script
444
+ * @param script - The script object containing script content keyed by field name
445
+ * @param source - The source Record for creating the shape
446
+ * @returns FDInlineScriptCallShape if this is an inline script, undefined otherwise
447
+ */
448
+ function buildInlineScriptShapeFromXml(fieldName, scriptActive, script, source) {
449
+ if (scriptActive === true && script && script[fieldName]?.script) {
450
+ const scriptContent = script[fieldName].script;
451
+ return new inline_script_plugin_1.FDInlineScriptCallShape({
452
+ source,
453
+ scriptContent,
454
+ });
455
+ }
456
+ return undefined;
457
+ }
458
+ /**
459
+ * Build an ObjectShape representing instance inputs from a base64-zipped JSON payload.
460
+ * This is used by both subflow and action instances.
461
+ * Supports bi-directional conversion for inline scripts (XML ↔ Fluent).
462
+ */
463
+ function buildInputsShapeFromZipped({ zippedInputs, definitionInputs, actionDefinition, record, logger, database, }) {
464
+ if (!zippedInputs) {
465
+ return undefined;
466
+ }
467
+ const props = {};
468
+ try {
469
+ const unzipped = (0, node_zlib_1.gunzipSync)(Buffer.from(zippedInputs, 'base64')).toString();
470
+ const values = JSON.parse(unzipped);
471
+ // Check if this is a catalog-related action (getCatalogVariables or createCatalogTask)
472
+ const catalogAction = (0, service_catalog_1.isCatalogAction)(actionDefinition);
473
+ let catalogItemRecord;
474
+ if (catalogAction) {
475
+ // Find the catalog item record
476
+ const templateCatalogItemValue = values.find((v) => v.name === 'template_catalog_item');
477
+ catalogItemRecord = (0, service_catalog_1.findCatalogItemBySysId)(templateCatalogItemValue?.value, database);
478
+ if (!catalogItemRecord) {
479
+ logger.warn(`Catalog item not found for sys_id '${templateCatalogItemValue?.value}'. ` +
480
+ `template_catalog_item and catalog_variables will fall back to raw string values.`);
481
+ }
482
+ }
483
+ for (const { name, value, scriptActive, script, parameter } of values) {
484
+ const attributes = definitionInputs
485
+ ?.find((v) => v.get('element').asString()?.getValue() === name)
486
+ ?.get('attributes')
487
+ ?.ifString()
488
+ ?.getValue();
489
+ const uiType = attributes ? (0, schema_to_flow_object_1.getAttributeValue)(attributes, 'uiType') : undefined;
490
+ // Skip hidden fields during transformation
491
+ // Convert parameter.attributes object to string format (key=value,key=value)
492
+ const paramAttributesStr = parameter?.attributes
493
+ ? Object.entries(parameter.attributes)
494
+ .map(([key, value]) => `${key}=${value}`)
495
+ .join(',')
496
+ : undefined;
497
+ if (isHiddenField(attributes) || isHiddenField(paramAttributesStr)) {
498
+ continue;
499
+ }
500
+ try {
501
+ if (flow_constants_1.UNSUPPORTED_DATA_TYPES.includes(parameter?.type)) {
502
+ logger.warn(`input ${name} has unsupported data type ${parameter?.type}`);
503
+ return undefined;
504
+ }
505
+ // Check if this is an inline script and convert to wfa.inlineScript() format
506
+ const inlineScriptShape = buildInlineScriptShapeFromXml(name, scriptActive, script, record);
507
+ // Determine the appropriate shape for this input
508
+ let inputShape;
509
+ if (inlineScriptShape) {
510
+ props[name] = inlineScriptShape;
511
+ }
512
+ else {
513
+ if (catalogAction) {
514
+ if (name === 'template_catalog_item' && catalogItemRecord) {
515
+ // Create template expression: `${catalogItemIdentifier}`
516
+ const catalogItemIdentifier = (0, utils_1.getIdentifierFromRecord)(catalogItemRecord);
517
+ inputShape = catalogItemIdentifier
518
+ ? (0, service_catalog_1.createTemplateExpressionFromIdentifier)(catalogItemIdentifier, record)
519
+ : undefined;
520
+ }
521
+ else if (name === 'catalog_variables' && catalogItemRecord) {
522
+ // Convert slushbucket to array of catalog variable references
523
+ inputShape = (0, service_catalog_1.convertSlushBucketToCatalogVariableArray)(value, catalogItemRecord, record);
524
+ }
525
+ }
526
+ // Use the specialized shape or fallback to normalized value
527
+ props[name] =
528
+ inputShape ?? normalizeInputValue(value, uiType ?? parameter.type, record, logger);
529
+ }
530
+ }
531
+ catch (e) {
532
+ const recordInfo = `${record.getTable()}.${record.getId().getValue()}`;
533
+ logger.warn(`Failed to parse value for ${name} in record ${recordInfo}: ${e instanceof Error ? e.message : e}`);
534
+ props[name] = value;
535
+ }
536
+ }
537
+ return new sdk_build_core_1.ObjectShape({ source: record, properties: props });
538
+ }
539
+ catch (error) {
540
+ logger.error(`Malformed/unsupported input payload in subflow_inputs: ${error}`);
541
+ return undefined;
542
+ }
543
+ }
544
+ // -------------------------
545
+ // Helper builders
546
+ // -------------------------
547
+ async function buildActionInstance({ actionDef, inputs, sysId, annotation, uuid, factory, source, transform, logger, }) {
548
+ const values = actionDef ? await prepareActionInstanceValueJson(inputs, actionDef, transform, logger) : undefined;
549
+ const actionDefRecord = actionDef instanceof sdk_build_core_1.Record ? actionDef : undefined;
550
+ const instanceProps = inputs.transform(({ $ }) => ({
551
+ active: $.val(true),
552
+ // if actionDef is not a Record (sysId fallback cases), actionDef?.getValue() should get get the string value (sysId) as is
553
+ action_type: $.val(actionDefRecord?.getId()?.getValue() || actionDef?.getValue() || ''),
554
+ action_type_parent: $.val(actionDefRecord?.getId()?.getValue() || actionDef?.getValue() || ''),
555
+ comment: $.val(annotation || actionDefRecord?.get('comment')?.getValue() || ''),
556
+ display_text: $.val(''),
557
+ generation_source: $.val(''),
558
+ sys_class_name: $.val('sys_hub_action_instance_v2'),
559
+ updation_source: $.val(''),
560
+ values: $.val(values),
561
+ parent_ui_id: $.val(''),
562
+ }));
563
+ if (!instanceProps) {
564
+ return undefined;
565
+ }
566
+ const record = await factory.createRecord({
567
+ source,
568
+ explicitId: sysId,
569
+ table: 'sys_hub_action_instance_v2',
570
+ properties: instanceProps,
571
+ });
572
+ // UUID can come from either instance uuid property (for fd ui authored actions) or generated from sysid (for fluent authored actions).
573
+ const instanceUUID = uuid ? uuid : (0, utils_1.sysIdToUuid)(record.getId().getValue());
574
+ return record.merge({ ui_id: instanceUUID });
575
+ }
576
+ async function buildSubflowInstance({ subflowDef, inputs, sysId, annotation, factory, uuid, source, transform, }) {
577
+ const values = subflowDef ? await prepareSubflowInstanceValueJson(inputs, subflowDef, transform) : undefined;
578
+ const subflowDefRecord = subflowDef instanceof sdk_build_core_1.Record ? subflowDef : undefined;
579
+ const instanceProps = inputs.transform(({ $ }) => ({
580
+ order: $.val(1),
581
+ flow: $.val(''),
582
+ attributes: $.val(''),
583
+ comment: $.val(annotation || subflowDefRecord?.get('comment')?.getValue() || ''),
584
+ display_text: $.val(''),
585
+ generation_source: $.val(''),
586
+ subflow: $.val(subflowDefRecord?.getId()?.getValue() || subflowDef?.getValue() || ''),
587
+ subflow_inputs: $.val(values),
588
+ wait_for_completion: $.from('waitForCompletion').def(false),
589
+ sys_class_name: $.val('sys_hub_sub_flow_instance_v2'),
590
+ parent_ui_id: $.def(''),
591
+ }));
592
+ if (!instanceProps) {
593
+ return undefined;
594
+ }
595
+ const record = await factory.createRecord({
596
+ source,
597
+ explicitId: sysId,
598
+ table: 'sys_hub_sub_flow_instance_v2',
599
+ properties: instanceProps,
600
+ });
601
+ // UUID can come from either instance uuid property (for fd ui authored subflows) or generated from sysid (for fluent authored subflows).
602
+ const instanceUUID = uuid ? uuid : (0, utils_1.sysIdToUuid)(record.getId().getValue());
603
+ return record.merge({ ui_id: instanceUUID });
604
+ }
605
+ /**
606
+ * Checks for inline script patterns in the input properties and resolves them
607
+ * to their appropriate format (either script format or primitive value).
608
+ *
609
+ * Supports inline scripts via wfa.inlineScript('script') (detected as CallExpressionShape/FDInlineScriptCallShape).
610
+ *
611
+ * Architecture note:
612
+ * This function detects inline scripts based on context - only template literals and Now.include()
613
+ * calls used as Action/Subflow inputs are treated as inline scripts. This avoids incorrectly
614
+ * converting template literals used elsewhere in the codebase (logging, formatting, etc.).
615
+ *
616
+ * Similar to data pills processing, this function:
617
+ * - Uses .entries({ resolve: false }) to preserve shape types
618
+ * - Checks if each shape is a TemplateExpressionShape or Now.include() call
619
+ * - Returns special serialization format for inline scripts
620
+ * - Falls back to regular getValue() for non-script shapes
621
+ *
622
+ * @param instanceInputs - The ObjectShape containing input properties
623
+ * @param transform - Transform context for shape conversion
624
+ * @returns Array of [name, value] tuples where inline scripts are serialized appropriately
625
+ */
626
+ async function checkAndResolveInlineScripts(instanceInputs, _transform) {
627
+ const entries = instanceInputs.entries({ resolve: false });
628
+ const results = [];
629
+ for (const [key, shape] of entries) {
630
+ // Handle wfa.inlineScript() calls - they should already be FDInlineScriptCallShape after plugin processing
631
+ if (shape instanceof inline_script_plugin_1.FDInlineScriptCallShape) {
632
+ const scriptContent = shape.getValue();
633
+ if (typeof scriptContent === 'string') {
634
+ // Wrap the script content in a TemplateExpressionShape
635
+ const templateShape = new sdk_build_core_1.TemplateExpressionShape({
636
+ source: shape,
637
+ literalText: scriptContent,
638
+ });
639
+ // Create InlineScriptShape for Flow Designer serialization
640
+ const inlineScript = new flow_shapes_1.InlineScriptShape({
641
+ source: templateShape,
642
+ scriptContent,
643
+ });
644
+ const scriptValue = inlineScript.toFlowDesignerJson(key);
645
+ results.push([key, scriptValue]);
646
+ }
647
+ }
648
+ }
649
+ return results;
650
+ }
651
+ /**
652
+ * Resolves complex object input values for subflow/action instance preparation.
653
+ * @param name - Input field name
654
+ * @param value - Raw input value
655
+ * @param parentDef - Record containing input and complex object definitions
656
+ * @param inputTableName - Table name to look up input definitions (e.g. 'sys_hub_flow_input' or 'sys_hub_action_input')
657
+ */
658
+ // Deprecated: kept for backward-compat but delegates to shared resolver
659
+ function resolveComplexInput(name, value, parentDef, inputTableName, logger) {
660
+ return (0, complex_object_resolver_1.resolveComplexInput)(name, value, parentDef, inputTableName, undefined, logger);
661
+ }
662
+ /**
663
+ * Checks if a given value is a serialized inline script object.
664
+ * This is used to identify inputs that have already been processed into the final
665
+ * Flow Designer JSON format for scripts.
666
+ *
667
+ * @param value - The value to check.
668
+ * @returns `true` if the value is a script object, `false` otherwise.
669
+ */
670
+ function isInlineScriptValue(value) {
671
+ return typeof value === 'object' && value !== null && value.scriptActive === true;
672
+ }
673
+ /**
674
+ * Processes an input value from objShape and returns the appropriate result object.
675
+ * Handles inline scripts by returning them as-is, or creates a standard input object.
676
+ *
677
+ * @param inputName - The name of the input field
678
+ * @param objShape - The ObjectShape containing all input values
679
+ * @param options - Optional processing options
680
+ * @param options.type - The parameter type to use (defaults to 'string' if not provided)
681
+ * @param options.actionDefRecord - Action definition record for complex input resolution
682
+ * @param options.inputTableName - Table name for input definitions (e.g., 'sys_hub_action_input')
683
+ * @returns The processed input object
684
+ */
685
+ function processInputValue(inputName, objShape, options, displayValues) {
686
+ const value = objShape.get(inputName);
687
+ const primitiveValue = value.getValue();
688
+ // If it's an inline script object, return it as-is
689
+ if (isInlineScriptValue(primitiveValue)) {
690
+ return primitiveValue;
691
+ }
692
+ let finalValue = primitiveValue;
693
+ let finalType = options?.type ?? 'string';
694
+ // If action definition is provided, resolve complex input
695
+ if (options?.actionDefRecord && options?.inputTableName) {
696
+ const resolvedValue = resolveComplexInput(inputName, primitiveValue, options.actionDefRecord, options.inputTableName, options?.logger);
697
+ finalValue = resolvedValue.value;
698
+ finalType = resolvedValue.internalType;
699
+ }
700
+ // Return standard input object
701
+ return {
702
+ name: inputName,
703
+ value: finalValue,
704
+ displayValue: displayValues && displayValues.has(inputName) ? displayValues.get(inputName) : finalValue,
705
+ scriptActive: false,
706
+ parameter: {
707
+ type: finalType,
708
+ },
709
+ };
710
+ }
711
+ /**
712
+ * Processes a definition input that was not provided by the user.
713
+ * Handles hidden fields and default values by creating appropriate input objects.
714
+ *
715
+ * @param inputDef - The input definition record from the action/subflow definition
716
+ * @param inputName - The name of the input field
717
+ * @returns The processed input object if the field is hidden or has a default value, undefined otherwise
718
+ */
719
+ function processDefaultOrHiddenInput(inputDef, inputName) {
720
+ // Get attributes and check if hidden
721
+ const attributes = inputDef.get('attributes')?.ifString()?.getValue();
722
+ const visibleAttr = attributes ? (0, schema_to_flow_object_1.getAttributeValue)(attributes, 'visible') : undefined;
723
+ const visibleInFdAttr = attributes ? (0, schema_to_flow_object_1.getAttributeValue)(attributes, 'visible_in_fd') : undefined;
724
+ const isHidden = visibleAttr === 'false' || visibleInFdAttr === 'false';
725
+ // Get default value and internal type
726
+ const defaultValue = inputDef.get('default_value')?.getValue();
727
+ const hasDefaultValue = defaultValue !== undefined && defaultValue !== null && defaultValue !== '';
728
+ const internalType = inputDef.get('internal_type')?.asString()?.getValue() || 'string';
729
+ // For hidden fields or fields with default values, add them to result
730
+ if (isHidden || hasDefaultValue) {
731
+ const valueToUse = hasDefaultValue ? defaultValue : '';
732
+ const paramAttributes = {};
733
+ if (visibleAttr === 'false') {
734
+ paramAttributes.visible = false;
735
+ }
736
+ if (visibleInFdAttr === 'false') {
737
+ paramAttributes.visible_in_fd = false;
738
+ }
739
+ return {
740
+ name: inputName,
741
+ value: valueToUse,
742
+ displayValue: valueToUse,
743
+ scriptActive: false,
744
+ parameter: {
745
+ type: internalType,
746
+ ...(Object.keys(paramAttributes).length > 0 && { attributes: paramAttributes }),
747
+ },
748
+ };
749
+ }
750
+ return undefined;
751
+ }
752
+ /**
753
+ * Resolve a catalog item record from a Shape (direct Record, TemplateExpressionShape, or IdentifierShape).
754
+ */
755
+ function resolveCatalogItemRecord(shape) {
756
+ // Handle direct record reference (e.g., softwareInstallationCatalogItem)
757
+ if (shape?.isRecord && shape.isRecord()) {
758
+ return shape.as(sdk_build_core_1.Record);
759
+ }
760
+ // Handle template expression (e.g., `${softwareInstallationCatalogItem}`)
761
+ if (shape instanceof sdk_build_core_1.TemplateExpressionShape) {
762
+ const spans = shape.getSpans();
763
+ if (spans[0]) {
764
+ const expr = spans[0].getExpression();
765
+ const resolved = expr instanceof sdk_build_core_1.IdentifierShape ? expr.resolve() : undefined;
766
+ if (resolved?.isRecord()) {
767
+ return resolved.as(sdk_build_core_1.Record);
768
+ }
769
+ }
770
+ }
771
+ // Handle identifier (e.g., variable reference)
772
+ if (shape instanceof sdk_build_core_1.IdentifierShape) {
773
+ const resolved = shape.resolve();
774
+ if (resolved?.isRecord()) {
775
+ return resolved.as(sdk_build_core_1.Record);
776
+ }
777
+ }
778
+ return undefined;
779
+ }
780
+ /**
781
+ * Convert comma-separated variable names to SlushBucket format with sys_ids.
782
+ * Input: "html,email" + catalog item record
783
+ * Output: "sys_id1:item_option_new,sys_id2:item_option_new"
784
+ */
785
+ function convertVariableNamesToSlushBucket(variableNames, catalogItemRecord, logger) {
786
+ const names = variableNames
787
+ .split(',')
788
+ .map((n) => n.trim())
789
+ .filter(Boolean);
790
+ if (names.length === 0) {
791
+ return '';
792
+ }
793
+ // Create a map of variable name to sys_id for quick lookup
794
+ const variableMap = new Map();
795
+ // Single loop: flatten records and build the map
796
+ for (const rec of catalogItemRecord.flat()) {
797
+ // Check direct record
798
+ if (rec.getTable() === flow_constants_1.CATALOG_VARIABLE_TABLE) {
799
+ const varName = rec.get('name')?.asString()?.getValue();
800
+ if (varName && !variableMap.has(varName)) {
801
+ const sysId = rec.getId().getValue();
802
+ if (sysId && typeof sysId === 'string') {
803
+ variableMap.set(varName, sysId);
804
+ }
805
+ }
806
+ }
807
+ // Check variable set records and their nested variables
808
+ if (rec.getTable() === flow_constants_1.CATALOG_VARIABLE_SET_TABLE) {
809
+ const variableSetRef = rec.get('variable_set');
810
+ if (!variableSetRef?.isRecord()) {
811
+ continue;
812
+ }
813
+ for (const nestedRec of variableSetRef.flat().filter((r) => r.getTable() === flow_constants_1.CATALOG_VARIABLE_TABLE)) {
814
+ const varName = nestedRec.get('name')?.asString()?.getValue();
815
+ if (varName && !variableMap.has(varName)) {
816
+ const sysId = nestedRec.getId().getValue();
817
+ if (sysId) {
818
+ variableMap.set(varName, sysId);
819
+ }
820
+ }
821
+ }
822
+ }
823
+ }
824
+ // Generate entries in the same order as input names
825
+ const entries = [];
826
+ for (const name of names) {
827
+ const variableSysId = variableMap.get(name);
828
+ if (variableSysId) {
829
+ entries.push(`${variableSysId}:${flow_constants_1.CATALOG_VARIABLE_TABLE}`);
830
+ }
831
+ else {
832
+ logger.warn(`Catalog variable '${name}' not found in catalog item. It will be skipped.`);
833
+ }
834
+ }
835
+ return entries.join(',');
836
+ }
837
+ /**
838
+ * Process getCatalogVariables action inputs to extract sys_ids and display values.
839
+ * Handles:
840
+ * - template_catalog_item: extracts catalog item sys_id and name
841
+ * - catalog_variables: converts variable names to slushbucket format
842
+ */
843
+ function processGetCatalogVariablesInputs(instanceInputs, logger) {
844
+ const overrideValues = new Map();
845
+ const displayValues = new Map();
846
+ // Get catalog item record from template_catalog_item input
847
+ const templateShape = instanceInputs.get('template_catalog_item');
848
+ const catalogItemRecord = resolveCatalogItemRecord(templateShape);
849
+ if (!catalogItemRecord) {
850
+ return { overrideValues, displayValues };
851
+ }
852
+ // Extract sys_id and name for template_catalog_item
853
+ const sysId = catalogItemRecord.getId().getValue();
854
+ const name = catalogItemRecord.get('name')?.asString()?.getValue();
855
+ if (sysId && typeof sysId === 'string') {
856
+ overrideValues.set('template_catalog_item', sysId);
857
+ if (name) {
858
+ displayValues.set('template_catalog_item', name);
859
+ }
860
+ }
861
+ // Convert catalog_variables to slushbucket format
862
+ const catalogVariablesShape = instanceInputs.get('catalog_variables');
863
+ // Handle string format: "html,email,ipAddress"
864
+ if (catalogVariablesShape?.isString()) {
865
+ const variableNames = catalogVariablesShape.asString().getValue();
866
+ if (variableNames) {
867
+ const slushBucketString = convertVariableNamesToSlushBucket(variableNames, catalogItemRecord, logger);
868
+ if (slushBucketString) {
869
+ overrideValues.set('catalog_variables', slushBucketString);
870
+ }
871
+ }
872
+ }
873
+ // Handle array format: [catalogItem.variables.html, catalogItem.variables.email, ...]
874
+ else if (catalogVariablesShape?.isArray()) {
875
+ const arrayShape = catalogVariablesShape.asArray();
876
+ const elements = arrayShape.getElements(false); // Get unresolved elements
877
+ const variableNames = [];
878
+ // Extract variable names from PropertyAccessShapes
879
+ for (const element of elements) {
880
+ if (element instanceof sdk_build_core_1.PropertyAccessShape) {
881
+ const propElements = element.getElements();
882
+ const lastElement = propElements[propElements.length - 1];
883
+ if (lastElement instanceof sdk_build_core_1.IdentifierShape) {
884
+ const varName = lastElement.getName();
885
+ variableNames.push(varName);
886
+ }
887
+ }
888
+ }
889
+ // Look up sys_ids from catalog item's item_option_new descendants
890
+ if (variableNames.length > 0) {
891
+ const variableNamesString = variableNames.join(',');
892
+ const slushBucketString = convertVariableNamesToSlushBucket(variableNamesString, catalogItemRecord, logger);
893
+ if (slushBucketString) {
894
+ overrideValues.set('catalog_variables', slushBucketString);
895
+ }
896
+ }
897
+ }
898
+ return { overrideValues, displayValues };
899
+ }
900
+ async function prepareActionInstanceValueJson(instanceInputs, actionDef, transform, logger) {
901
+ const actionDefRecord = actionDef.isRecord() ? actionDef.as(sdk_build_core_1.Record) : undefined;
902
+ if (!instanceInputs) {
903
+ return [];
904
+ }
905
+ const isActionDefString = actionDef instanceof sdk_build_core_1.StringShape;
906
+ // Special handling for getCatalogVariables action
907
+ let overrideValues = new Map();
908
+ let displayValues = new Map();
909
+ if (actionDefRecord) {
910
+ const actionSysId = actionDefRecord.getId().getValue();
911
+ const actionName = typeof actionSysId === 'string' ? flow_constants_1.CORE_ACTIONS_SYS_ID_NAME_MAP[actionSysId] : undefined;
912
+ // Check if this is the getCatalogVariables action or createCatalogTask action
913
+ if (actionName === 'getCatalogVariables' || actionName === 'createCatalogTask') {
914
+ try {
915
+ const result = processGetCatalogVariablesInputs(instanceInputs, logger);
916
+ overrideValues = result.overrideValues;
917
+ displayValues = result.displayValues;
918
+ }
919
+ catch (error) {
920
+ logger.error('[getCatalogVariables] Error:', error);
921
+ }
922
+ }
923
+ }
924
+ // Check for datapills and resolve them (skip keys already in overrideValues)
925
+ const dataPillResults = await checkAndResolveDataPills(instanceInputs, transform, overrideValues);
926
+ // Check for inline script tags and resolve them (only returns scripts)
927
+ const inlineScriptResults = await checkAndResolveInlineScripts(instanceInputs, transform);
928
+ const inlineScriptMap = new Map(inlineScriptResults);
929
+ // Merge: use inline scripts where they exist, otherwise use datapill results
930
+ // Note: Inline script can be applied to only top level properties; No need to handle nested objects
931
+ // Merge results: prioritize overrideValues > inline scripts > datapill results
932
+ const mergedResults = dataPillResults.map(([key, value]) => {
933
+ // Use override value if available (catalog item sys_id or slushbucket string)
934
+ if (overrideValues.has(key)) {
935
+ return [key, overrideValues.get(key)];
936
+ }
937
+ // Otherwise use inline script if available
938
+ return inlineScriptMap.has(key) ? [key, inlineScriptMap.get(key)] : [key, value];
939
+ });
940
+ const objShape = new sdk_build_core_1.ObjectShape({
941
+ source: instanceInputs.getSource(),
942
+ properties: Object.fromEntries(mergedResults),
943
+ });
944
+ const result = [];
945
+ // When isActionDefString is true, there's no action definition in fluent
946
+ // We expect arbitrary inputs and should process all provided inputs directly
947
+ if (actionDefRecord) {
948
+ // When action definition record is present, process only definition inputs
949
+ const definitionInputs = actionDefRecord.flat().filter((v) => v.getTable() === 'sys_hub_action_input');
950
+ const providedInputNames = new Set(objShape.keys());
951
+ for (const inputDef of definitionInputs) {
952
+ const inputName = inputDef.get('element')?.asString()?.getValue();
953
+ if (!inputName) {
954
+ continue;
955
+ }
956
+ // If input is provided in objShape(ie provided by user), process it
957
+ if (providedInputNames.has(inputName)) {
958
+ const processedValue = processInputValue(inputName, objShape, {
959
+ actionDefRecord,
960
+ inputTableName: 'sys_hub_action_input',
961
+ logger,
962
+ }, displayValues);
963
+ result.push(processedValue);
964
+ }
965
+ else {
966
+ // Process default or hidden input
967
+ const processedValue = processDefaultOrHiddenInput(inputDef, inputName);
968
+ if (processedValue) {
969
+ result.push(processedValue);
970
+ }
971
+ }
972
+ }
973
+ }
974
+ else if (isActionDefString) {
975
+ for (const inputName of objShape.keys()) {
976
+ const processedValue = processInputValue(inputName, objShape, { type: 'string' }, displayValues);
977
+ result.push(processedValue);
978
+ }
979
+ }
980
+ return result;
981
+ }
982
+ async function prepareSubflowInstanceValueJson(instanceInputs, subflowDef, transform) {
983
+ // Check for datapills and resolve them
984
+ const dataPillResults = await checkAndResolveDataPills(instanceInputs, transform);
985
+ // Check for inline script tags and resolve them (only returns scripts)
986
+ const inlineScriptResults = await checkAndResolveInlineScripts(instanceInputs, transform);
987
+ const inlineScriptMap = new Map(inlineScriptResults);
988
+ // Merge: use inline scripts where they exist, otherwise use datapill results
989
+ const mergedResults = dataPillResults.map(([key, value]) => {
990
+ return inlineScriptMap.has(key) ? [key, inlineScriptMap.get(key)] : [key, value];
991
+ });
992
+ const objShape = new sdk_build_core_1.ObjectShape({
993
+ source: instanceInputs.getSource(),
994
+ properties: Object.fromEntries(mergedResults),
995
+ });
996
+ return objShape
997
+ .keys()
998
+ .filter((key) => key !== 'waitForCompletion')
999
+ .map((key) => {
1000
+ const value = objShape.get(key);
1001
+ const primitiveValue = value.getValue();
1002
+ // If checkAndResolveInlineScripts already returned a script object, return it as-is
1003
+ if (isInlineScriptValue(primitiveValue)) {
1004
+ return primitiveValue;
1005
+ }
1006
+ let resolvedValue = {
1007
+ value: primitiveValue,
1008
+ internalType: undefined,
1009
+ };
1010
+ if (subflowDef.isRecord()) {
1011
+ resolvedValue = resolveComplexInput(key, primitiveValue, subflowDef.as(sdk_build_core_1.Record), 'sys_hub_flow_input');
1012
+ }
1013
+ const result = {
1014
+ name: key,
1015
+ value: resolvedValue.value,
1016
+ displayValue: resolvedValue.value,
1017
+ parameter: {
1018
+ type: resolvedValue.internalType,
1019
+ }, // populate later if needed
1020
+ };
1021
+ // Add children array if present (for FlowObject with datapills)
1022
+ if (resolvedValue.children && resolvedValue.children.length > 0) {
1023
+ result['children'] = resolvedValue.children;
1024
+ }
1025
+ return result;
1026
+ });
1027
+ }
1028
+ /**
1029
+ * Type guard to check if a shape is a data pill shape that needs resolution.
1030
+ * Data pill shapes include PropertyAccessShape, TemplateExpressionShape, and IdentifierShape.
1031
+ * @param shape - The shape to check
1032
+ * @returns true if the shape is a data pill shape, false otherwise
1033
+ */
1034
+ function isDataPillShape(shape) {
1035
+ return (shape instanceof sdk_build_core_1.PropertyAccessShape ||
1036
+ shape instanceof sdk_build_core_1.TemplateExpressionShape ||
1037
+ shape instanceof sdk_build_core_1.IdentifierShape);
1038
+ }
1039
+ /**
1040
+ * Recursively resolves data pills in nested object structures.
1041
+ * Handles objects with nested data pills and constructs the resolved object back.
1042
+ * Special shapes like TemplateValueShape and ApprovalRulesShape are also processed recursively
1043
+ * since they can contain data pills in their nested structures.
1044
+ * @param shape - The ObjectShape to process
1045
+ * @param transform - The transform instance
1046
+ * @returns Resolved object with all nested data pills resolved
1047
+ */
1048
+ async function resolveObjectShapeRecursively(shape, transform) {
1049
+ const entries = shape.entries({ resolve: false });
1050
+ const resolvedObject = {};
1051
+ for (const [key, valueShape] of entries) {
1052
+ if (isDataPillShape(valueShape)) {
1053
+ // Resolve data pill shapes
1054
+ resolvedObject[key] = await (0, utils_1.resolveDataPillShape)(valueShape, transform);
1055
+ }
1056
+ else if (valueShape.isObject()) {
1057
+ // Recursively resolve all ObjectShapes including special types
1058
+ // TemplateValueShape and ApprovalRulesShape can contain data pills in their nested structures
1059
+ // DurationShape only contains primitive numbers, but handling it recursively is harmless
1060
+ resolvedObject[key] = await resolveObjectShapeRecursively(valueShape.asObject(), transform);
1061
+ }
1062
+ else if (valueShape.isArray()) {
1063
+ // Handle array: recursively resolve each element
1064
+ const arrayShape = valueShape.asArray();
1065
+ const elements = arrayShape.getElements(false);
1066
+ const resolvedArray = [];
1067
+ for (const element of elements) {
1068
+ if (isDataPillShape(element)) {
1069
+ resolvedArray.push(await (0, utils_1.resolveDataPillShape)(element, transform));
1070
+ }
1071
+ else if (element.isObject()) {
1072
+ resolvedArray.push(await resolveObjectShapeRecursively(element.asObject(), transform));
1073
+ }
1074
+ else if (element.isArray()) {
1075
+ // Recursively handle nested arrays by creating a temporary ObjectShape wrapper
1076
+ const tempShape = new sdk_build_core_1.ObjectShape({
1077
+ source: element.getSource(),
1078
+ properties: { temp: element },
1079
+ });
1080
+ const resolved = await resolveObjectShapeRecursively(tempShape, transform);
1081
+ resolvedArray.push(resolved.temp);
1082
+ }
1083
+ else {
1084
+ resolvedArray.push(element.getValue());
1085
+ }
1086
+ }
1087
+ resolvedObject[key] = resolvedArray;
1088
+ }
1089
+ else {
1090
+ // For all other shapes (primitives), get the value directly
1091
+ resolvedObject[key] = valueShape.getValue();
1092
+ }
1093
+ }
1094
+ return resolvedObject;
1095
+ }
1096
+ /**
1097
+ * Wraps special shape types (ApprovalRulesShape, TemplateValueShape, DurationShape) with their string representations.
1098
+ * @param shape - The original shape
1099
+ * @param resolvedValue - The resolved value
1100
+ * @param source - The source for creating new shapes
1101
+ * @returns The appropriately wrapped value or the original resolved value
1102
+ */
1103
+ function wrapSpecialShape(shape, resolvedValue, source) {
1104
+ if (shape.is(flow_shapes_1.ApprovalRulesShape)) {
1105
+ return new flow_shapes_1.ApprovalRulesShape({
1106
+ source,
1107
+ value: resolvedValue,
1108
+ }).toString();
1109
+ }
1110
+ else if (shape.is(sdk_build_core_1.TemplateValueShape)) {
1111
+ return new sdk_build_core_1.TemplateValueShape({
1112
+ source,
1113
+ value: resolvedValue,
1114
+ }).toString();
1115
+ }
1116
+ else if (shape.is(sdk_build_core_1.DurationShape)) {
1117
+ return new sdk_build_core_1.DurationShape({
1118
+ source,
1119
+ value: resolvedValue,
1120
+ }).toString();
1121
+ }
1122
+ else if (shape.is(flow_shapes_1.ApprovalDueDateShape)) {
1123
+ return new flow_shapes_1.ApprovalDueDateShape({
1124
+ source,
1125
+ value: resolvedValue,
1126
+ }).toString();
1127
+ }
1128
+ return resolvedValue;
1129
+ }
1130
+ /**
1131
+ * Checks for datapills and resolves them in instance inputs.
1132
+ * Similar to resolveObjectShapeRecursively but returns key-value pairs and handles special shapes.
1133
+ * @param instanceInputs - The instance inputs object shape
1134
+ * @param transform - The transform instance
1135
+ * @returns Array of [key, value] pairs with resolved datapills
1136
+ */
1137
+ async function checkAndResolveDataPills(instanceInputs, transform, skipKeys) {
1138
+ const entries = instanceInputs.entries({ resolve: false });
1139
+ const results = [];
1140
+ for (const [key, shape] of entries) {
1141
+ // Skip datapill resolution for keys that have already been processed (e.g., catalog_variables in array format)
1142
+ // But still add the override value so the key exists in results
1143
+ if (skipKeys?.has(key)) {
1144
+ results.push([key, skipKeys.get(key)]);
1145
+ continue;
1146
+ }
1147
+ if (shape && isDataPillShape(shape)) {
1148
+ const resolvedValue = await (0, utils_1.resolveDataPillShape)(shape, transform);
1149
+ results.push([key, resolvedValue]);
1150
+ }
1151
+ else if (shape.is(sdk_build_core_1.DurationShape)) {
1152
+ // Handle DurationShape specially - convert to string representation
1153
+ // DurationShape.getValue() returns a symbol, so we need to get the duration value differently
1154
+ const durationShape = shape.as(sdk_build_core_1.DurationShape);
1155
+ const durationValue = durationShape.getDuration();
1156
+ const wrappedValue = wrapSpecialShape(shape, durationValue, instanceInputs.getSource());
1157
+ results.push([key, wrappedValue]);
1158
+ }
1159
+ else if (shape.isObject() || shape.is(sdk_build_core_1.TemplateValueShape)) {
1160
+ const objShape = shape.is(sdk_build_core_1.TemplateValueShape) ? shape.getTemplateValue() : shape.asObject();
1161
+ // Recursively resolve object shapes
1162
+ const resolvedValue = await resolveObjectShapeRecursively(objShape, transform);
1163
+ // Preserve special shapes like TemplateValue by passing the original shape
1164
+ const wrappedValue = wrapSpecialShape(shape, resolvedValue, instanceInputs.getSource());
1165
+ results.push([key, wrappedValue]);
1166
+ }
1167
+ else if (shape.isArray()) {
1168
+ // Resolve arrays using the shared recursive logic
1169
+ const resolvedArray = await resolveArrayElements(shape.asArray(), transform);
1170
+ results.push([key, resolvedArray]);
1171
+ }
1172
+ else {
1173
+ results.push([key, shape.getValue()]);
1174
+ }
1175
+ }
1176
+ return results;
1177
+ }
1178
+ /**
1179
+ * Resolves all elements in an array shape, handling datapills, objects, and nested arrays.
1180
+ * Shared logic extracted from both resolveObjectShapeRecursively and checkAndResolveDataPills.
1181
+ * @param arrayShape - The array shape to resolve
1182
+ * @param transform - The transform instance
1183
+ * @returns Resolved array with all datapills resolved
1184
+ */
1185
+ async function resolveArrayElements(arrayShape, transform) {
1186
+ const elements = arrayShape.asArray().getElements(false);
1187
+ const resolvedArray = [];
1188
+ for (const element of elements) {
1189
+ if (isDataPillShape(element)) {
1190
+ resolvedArray.push(await (0, utils_1.resolveDataPillShape)(element, transform));
1191
+ }
1192
+ else if (element.isObject()) {
1193
+ resolvedArray.push(await resolveObjectShapeRecursively(element.asObject(), transform));
1194
+ }
1195
+ else if (element.isArray()) {
1196
+ // Recursively handle nested arrays
1197
+ resolvedArray.push(await resolveArrayElements(element, transform));
1198
+ }
1199
+ else {
1200
+ resolvedArray.push(element.getValue());
1201
+ }
1202
+ }
1203
+ return resolvedArray;
1204
+ }
1205
+ //# sourceMappingURL=flow-instance-plugin.js.map