@servicenow/sdk-build-plugins 4.1.1 → 4.3.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 (388) hide show
  1. package/dist/acl-plugin.js +22 -4
  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/application-menu-plugin.js +1 -0
  7. package/dist/application-menu-plugin.js.map +1 -1
  8. package/dist/atf/step-configs.d.ts +13 -12
  9. package/dist/atf/step-configs.js.map +1 -1
  10. package/dist/atf/test-plugin.d.ts +1 -1
  11. package/dist/atf/test-plugin.js +13 -7
  12. package/dist/atf/test-plugin.js.map +1 -1
  13. package/dist/basic-syntax-plugin.js +58 -14
  14. package/dist/basic-syntax-plugin.js.map +1 -1
  15. package/dist/business-rule-plugin.js +1 -0
  16. package/dist/business-rule-plugin.js.map +1 -1
  17. package/dist/call-expression-plugin.js +1 -107
  18. package/dist/call-expression-plugin.js.map +1 -1
  19. package/dist/claims-plugin.js +1 -1
  20. package/dist/claims-plugin.js.map +1 -1
  21. package/dist/client-script-plugin.js +5 -17
  22. package/dist/client-script-plugin.js.map +1 -1
  23. package/dist/column/column-helper.d.ts +1 -1
  24. package/dist/column/column-helper.js +46 -2
  25. package/dist/column/column-helper.js.map +1 -1
  26. package/dist/column/column-to-record.js +6 -4
  27. package/dist/column/column-to-record.js.map +1 -1
  28. package/dist/column-plugin.js +107 -28
  29. package/dist/column-plugin.js.map +1 -1
  30. package/dist/dashboard/dashboard-component-property-defaults.d.ts +152 -0
  31. package/dist/dashboard/dashboard-component-property-defaults.js +264 -0
  32. package/dist/dashboard/dashboard-component-property-defaults.js.map +1 -0
  33. package/dist/dashboard/dashboard-component-resolver.d.ts +13 -0
  34. package/dist/dashboard/dashboard-component-resolver.js +69 -0
  35. package/dist/dashboard/dashboard-component-resolver.js.map +1 -0
  36. package/dist/dashboard/dashboard-plugin.d.ts +12 -0
  37. package/dist/dashboard/dashboard-plugin.js +397 -0
  38. package/dist/dashboard/dashboard-plugin.js.map +1 -0
  39. package/dist/data-plugin.d.ts +6 -0
  40. package/dist/data-plugin.js +156 -0
  41. package/dist/data-plugin.js.map +1 -0
  42. package/dist/email-notification-plugin.d.ts +2 -0
  43. package/dist/email-notification-plugin.js +541 -0
  44. package/dist/email-notification-plugin.js.map +1 -0
  45. package/dist/flow/constants/flow-plugin-constants.d.ts +58 -0
  46. package/dist/flow/constants/flow-plugin-constants.js +70 -0
  47. package/dist/flow/constants/flow-plugin-constants.js.map +1 -0
  48. package/dist/flow/flow-logic/flow-logic-constants.d.ts +38 -0
  49. package/dist/flow/flow-logic/flow-logic-constants.js +118 -0
  50. package/dist/flow/flow-logic/flow-logic-constants.js.map +1 -0
  51. package/dist/flow/flow-logic/flow-logic-diagnostics.d.ts +19 -0
  52. package/dist/flow/flow-logic/flow-logic-diagnostics.js +503 -0
  53. package/dist/flow/flow-logic/flow-logic-diagnostics.js.map +1 -0
  54. package/dist/flow/flow-logic/flow-logic-plugin-helpers.d.ts +62 -0
  55. package/dist/flow/flow-logic/flow-logic-plugin-helpers.js +2092 -0
  56. package/dist/flow/flow-logic/flow-logic-plugin-helpers.js.map +1 -0
  57. package/dist/flow/flow-logic/flow-logic-plugin.d.ts +52 -0
  58. package/dist/flow/flow-logic/flow-logic-plugin.js +283 -0
  59. package/dist/flow/flow-logic/flow-logic-plugin.js.map +1 -0
  60. package/dist/flow/flow-logic/flow-logic-shapes.d.ts +104 -0
  61. package/dist/flow/flow-logic/flow-logic-shapes.js +201 -0
  62. package/dist/flow/flow-logic/flow-logic-shapes.js.map +1 -0
  63. package/dist/flow/plugins/approval-rules-plugin.d.ts +2 -0
  64. package/dist/flow/plugins/approval-rules-plugin.js +49 -0
  65. package/dist/flow/plugins/approval-rules-plugin.js.map +1 -0
  66. package/dist/flow/plugins/flow-action-definition-plugin.d.ts +2 -0
  67. package/dist/flow/plugins/flow-action-definition-plugin.js +286 -0
  68. package/dist/flow/plugins/flow-action-definition-plugin.js.map +1 -0
  69. package/dist/flow/plugins/flow-data-pill-plugin.d.ts +9 -0
  70. package/dist/flow/plugins/flow-data-pill-plugin.js +212 -0
  71. package/dist/flow/plugins/flow-data-pill-plugin.js.map +1 -0
  72. package/dist/flow/plugins/flow-definition-plugin.d.ts +2 -0
  73. package/dist/flow/plugins/flow-definition-plugin.js +1668 -0
  74. package/dist/flow/plugins/flow-definition-plugin.js.map +1 -0
  75. package/dist/flow/plugins/flow-diagnostics-plugin.d.ts +26 -0
  76. package/dist/flow/plugins/flow-diagnostics-plugin.js +217 -0
  77. package/dist/flow/plugins/flow-diagnostics-plugin.js.map +1 -0
  78. package/dist/flow/plugins/flow-instance-plugin.d.ts +12 -0
  79. package/dist/flow/plugins/flow-instance-plugin.js +930 -0
  80. package/dist/flow/plugins/flow-instance-plugin.js.map +1 -0
  81. package/dist/flow/plugins/flow-trigger-instance-plugin.d.ts +2 -0
  82. package/dist/flow/plugins/flow-trigger-instance-plugin.js +324 -0
  83. package/dist/flow/plugins/flow-trigger-instance-plugin.js.map +1 -0
  84. package/dist/flow/plugins/inline-script-plugin.d.ts +39 -0
  85. package/dist/flow/plugins/inline-script-plugin.js +80 -0
  86. package/dist/flow/plugins/inline-script-plugin.js.map +1 -0
  87. package/dist/flow/plugins/step-definition-plugin.d.ts +5 -0
  88. package/dist/flow/plugins/step-definition-plugin.js +71 -0
  89. package/dist/flow/plugins/step-definition-plugin.js.map +1 -0
  90. package/dist/flow/plugins/step-instance-plugin.d.ts +31 -0
  91. package/dist/flow/plugins/step-instance-plugin.js +339 -0
  92. package/dist/flow/plugins/step-instance-plugin.js.map +1 -0
  93. package/dist/flow/plugins/trigger-plugin.d.ts +2 -0
  94. package/dist/flow/plugins/trigger-plugin.js +96 -0
  95. package/dist/flow/plugins/trigger-plugin.js.map +1 -0
  96. package/dist/flow/plugins/wfa-datapill-plugin.d.ts +15 -0
  97. package/dist/flow/plugins/wfa-datapill-plugin.js +178 -0
  98. package/dist/flow/plugins/wfa-datapill-plugin.js.map +1 -0
  99. package/dist/flow/utils/approval-rules-processor.d.ts +13 -0
  100. package/dist/flow/utils/approval-rules-processor.js +267 -0
  101. package/dist/flow/utils/approval-rules-processor.js.map +1 -0
  102. package/dist/flow/utils/built-in-complex-objects.d.ts +19 -0
  103. package/dist/flow/utils/built-in-complex-objects.js +62 -0
  104. package/dist/flow/utils/built-in-complex-objects.js.map +1 -0
  105. package/dist/flow/utils/complex-object-resolver.d.ts +8 -0
  106. package/dist/flow/utils/complex-object-resolver.js +614 -0
  107. package/dist/flow/utils/complex-object-resolver.js.map +1 -0
  108. package/dist/flow/utils/complex-objects.d.ts +36 -0
  109. package/dist/flow/utils/complex-objects.js +481 -0
  110. package/dist/flow/utils/complex-objects.js.map +1 -0
  111. package/dist/flow/utils/data-pill-shapes.d.ts +58 -0
  112. package/dist/flow/utils/data-pill-shapes.js +135 -0
  113. package/dist/flow/utils/data-pill-shapes.js.map +1 -0
  114. package/dist/flow/utils/datapill-transformer.d.ts +110 -0
  115. package/dist/flow/utils/datapill-transformer.js +503 -0
  116. package/dist/flow/utils/datapill-transformer.js.map +1 -0
  117. package/dist/flow/utils/flow-constants.d.ts +65 -0
  118. package/dist/flow/utils/flow-constants.js +223 -0
  119. package/dist/flow/utils/flow-constants.js.map +1 -0
  120. package/dist/flow/utils/flow-io-to-record.d.ts +44 -0
  121. package/dist/flow/utils/flow-io-to-record.js +409 -0
  122. package/dist/flow/utils/flow-io-to-record.js.map +1 -0
  123. package/dist/flow/utils/flow-shapes.d.ts +161 -0
  124. package/dist/flow/utils/flow-shapes.js +255 -0
  125. package/dist/flow/utils/flow-shapes.js.map +1 -0
  126. package/dist/flow/utils/flow-to-xml.d.ts +16 -0
  127. package/dist/flow/utils/flow-to-xml.js +237 -0
  128. package/dist/flow/utils/flow-to-xml.js.map +1 -0
  129. package/dist/flow/utils/flow-variable-processor.d.ts +51 -0
  130. package/dist/flow/utils/flow-variable-processor.js +69 -0
  131. package/dist/flow/utils/flow-variable-processor.js.map +1 -0
  132. package/dist/flow/utils/label-cache-parser.d.ts +7 -0
  133. package/dist/flow/utils/label-cache-parser.js +24 -0
  134. package/dist/flow/utils/label-cache-parser.js.map +1 -0
  135. package/dist/flow/utils/label-cache-processor.d.ts +119 -0
  136. package/dist/flow/utils/label-cache-processor.js +719 -0
  137. package/dist/flow/utils/label-cache-processor.js.map +1 -0
  138. package/dist/flow/utils/pill-string-parser.d.ts +88 -0
  139. package/dist/flow/utils/pill-string-parser.js +306 -0
  140. package/dist/flow/utils/pill-string-parser.js.map +1 -0
  141. package/dist/flow/utils/schema-to-flow-object.d.ts +22 -0
  142. package/dist/flow/utils/schema-to-flow-object.js +318 -0
  143. package/dist/flow/utils/schema-to-flow-object.js.map +1 -0
  144. package/dist/flow/utils/utils.d.ts +117 -0
  145. package/dist/flow/utils/utils.js +345 -0
  146. package/dist/flow/utils/utils.js.map +1 -0
  147. package/dist/import-sets-plugin.d.ts +2 -0
  148. package/dist/import-sets-plugin.js +412 -0
  149. package/dist/import-sets-plugin.js.map +1 -0
  150. package/dist/index.d.ts +24 -1
  151. package/dist/index.js +25 -1
  152. package/dist/index.js.map +1 -1
  153. package/dist/json-plugin.d.ts +4 -4
  154. package/dist/json-plugin.js +21 -7
  155. package/dist/json-plugin.js.map +1 -1
  156. package/dist/list-plugin.js +83 -1
  157. package/dist/list-plugin.js.map +1 -1
  158. package/dist/now-attach-plugin.d.ts +36 -0
  159. package/dist/now-attach-plugin.js +320 -0
  160. package/dist/now-attach-plugin.js.map +1 -0
  161. package/dist/now-config-plugin.js +3 -0
  162. package/dist/now-config-plugin.js.map +1 -1
  163. package/dist/now-include-plugin.js +7 -1
  164. package/dist/now-include-plugin.js.map +1 -1
  165. package/dist/package-json-plugin.js +2 -2
  166. package/dist/package-json-plugin.js.map +1 -1
  167. package/dist/record-plugin.d.ts +35 -0
  168. package/dist/record-plugin.js +109 -23
  169. package/dist/record-plugin.js.map +1 -1
  170. package/dist/repack/index.d.ts +2 -0
  171. package/dist/repack/index.js +8 -0
  172. package/dist/repack/index.js.map +1 -1
  173. package/dist/repack/lint/Rules.js.map +1 -1
  174. package/dist/rest-api-plugin.js +81 -74
  175. package/dist/rest-api-plugin.js.map +1 -1
  176. package/dist/role-plugin.js +1 -0
  177. package/dist/role-plugin.js.map +1 -1
  178. package/dist/server-module-plugin/index.js +53 -6
  179. package/dist/server-module-plugin/index.js.map +1 -1
  180. package/dist/service-catalog/catalog-clientscript-plugin.d.ts +2 -0
  181. package/dist/service-catalog/catalog-clientscript-plugin.js +117 -0
  182. package/dist/service-catalog/catalog-clientscript-plugin.js.map +1 -0
  183. package/dist/service-catalog/catalog-item-plugin.d.ts +2 -0
  184. package/dist/service-catalog/catalog-item-plugin.js +115 -0
  185. package/dist/service-catalog/catalog-item-plugin.js.map +1 -0
  186. package/dist/service-catalog/catalog-ui-policy-plugin.d.ts +2 -0
  187. package/dist/service-catalog/catalog-ui-policy-plugin.js +266 -0
  188. package/dist/service-catalog/catalog-ui-policy-plugin.js.map +1 -0
  189. package/dist/service-catalog/index.d.ts +5 -0
  190. package/dist/service-catalog/index.js +22 -0
  191. package/dist/service-catalog/index.js.map +1 -0
  192. package/dist/service-catalog/record-to-shape.d.ts +6 -0
  193. package/dist/service-catalog/record-to-shape.js +93 -0
  194. package/dist/service-catalog/record-to-shape.js.map +1 -0
  195. package/dist/service-catalog/sc-record-producer-plugin.d.ts +2 -0
  196. package/dist/service-catalog/sc-record-producer-plugin.js +139 -0
  197. package/dist/service-catalog/sc-record-producer-plugin.js.map +1 -0
  198. package/dist/service-catalog/service-catalog-base.d.ts +311 -0
  199. package/dist/service-catalog/service-catalog-base.js +542 -0
  200. package/dist/service-catalog/service-catalog-base.js.map +1 -0
  201. package/dist/service-catalog/service-catalog-diagnostics.d.ts +45 -0
  202. package/dist/service-catalog/service-catalog-diagnostics.js +169 -0
  203. package/dist/service-catalog/service-catalog-diagnostics.js.map +1 -0
  204. package/dist/service-catalog/shape-to-record.d.ts +7 -0
  205. package/dist/service-catalog/shape-to-record.js +232 -0
  206. package/dist/service-catalog/shape-to-record.js.map +1 -0
  207. package/dist/service-catalog/utils.d.ts +313 -0
  208. package/dist/service-catalog/utils.js +1144 -0
  209. package/dist/service-catalog/utils.js.map +1 -0
  210. package/dist/service-catalog/variable-helper.d.ts +43 -0
  211. package/dist/service-catalog/variable-helper.js +92 -0
  212. package/dist/service-catalog/variable-helper.js.map +1 -0
  213. package/dist/service-catalog/variable-set-plugin.d.ts +2 -0
  214. package/dist/service-catalog/variable-set-plugin.js +175 -0
  215. package/dist/service-catalog/variable-set-plugin.js.map +1 -0
  216. package/dist/service-catalog/variables-transform.d.ts +139 -0
  217. package/dist/service-catalog/variables-transform.js +403 -0
  218. package/dist/service-catalog/variables-transform.js.map +1 -0
  219. package/dist/service-portal/widget-plugin.js +4 -1
  220. package/dist/service-portal/widget-plugin.js.map +1 -1
  221. package/dist/sla/sla-validators.d.ts +61 -0
  222. package/dist/sla/sla-validators.js +224 -0
  223. package/dist/sla/sla-validators.js.map +1 -0
  224. package/dist/sla-plugin.d.ts +5 -0
  225. package/dist/sla-plugin.js +280 -0
  226. package/dist/sla-plugin.js.map +1 -0
  227. package/dist/static-content-plugin.d.ts +1 -0
  228. package/dist/static-content-plugin.js +4 -3
  229. package/dist/static-content-plugin.js.map +1 -1
  230. package/dist/table-plugin.js +49 -4
  231. package/dist/table-plugin.js.map +1 -1
  232. package/dist/ui-page-plugin.js +2 -1
  233. package/dist/ui-page-plugin.js.map +1 -1
  234. package/dist/ui-policy-plugin.d.ts +2 -0
  235. package/dist/ui-policy-plugin.js +405 -0
  236. package/dist/ui-policy-plugin.js.map +1 -0
  237. package/dist/utils.d.ts +19 -1
  238. package/dist/utils.js +40 -0
  239. package/dist/utils.js.map +1 -1
  240. package/dist/ux-list-menu-config-plugin.d.ts +2 -0
  241. package/dist/ux-list-menu-config-plugin.js +292 -0
  242. package/dist/ux-list-menu-config-plugin.js.map +1 -0
  243. package/dist/view-plugin.js +1 -1
  244. package/dist/view-plugin.js.map +1 -1
  245. package/dist/workspace-plugin/chrome-tab.d.ts +2 -0
  246. package/dist/workspace-plugin/chrome-tab.js +46 -0
  247. package/dist/workspace-plugin/chrome-tab.js.map +1 -0
  248. package/dist/workspace-plugin/constants.d.ts +52 -0
  249. package/dist/workspace-plugin/constants.js +56 -0
  250. package/dist/workspace-plugin/constants.js.map +1 -0
  251. package/dist/workspace-plugin/fluent-utils.d.ts +9 -0
  252. package/dist/workspace-plugin/fluent-utils.js +60 -0
  253. package/dist/workspace-plugin/fluent-utils.js.map +1 -0
  254. package/dist/workspace-plugin/page.d.ts +8 -0
  255. package/dist/workspace-plugin/page.js +108 -0
  256. package/dist/workspace-plugin/page.js.map +1 -0
  257. package/dist/workspace-plugin/screen.d.ts +1 -0
  258. package/dist/workspace-plugin/screen.js +38 -0
  259. package/dist/workspace-plugin/screen.js.map +1 -0
  260. package/dist/workspace-plugin/templates/index.d.ts +10 -0
  261. package/dist/workspace-plugin/templates/index.js +20 -0
  262. package/dist/workspace-plugin/templates/index.js.map +1 -0
  263. package/dist/workspace-plugin/templates/record-page-composition.d.ts +1 -0
  264. package/dist/workspace-plugin/templates/record-page-composition.js +4043 -0
  265. package/dist/workspace-plugin/templates/record-page-composition.js.map +1 -0
  266. package/dist/workspace-plugin/templates/record-page-data.d.ts +1 -0
  267. package/dist/workspace-plugin/templates/record-page-data.js +527 -0
  268. package/dist/workspace-plugin/templates/record-page-data.js.map +1 -0
  269. package/dist/workspace-plugin/templates/record-page-interalEventMappings.d.ts +1 -0
  270. package/dist/workspace-plugin/templates/record-page-interalEventMappings.js +39 -0
  271. package/dist/workspace-plugin/templates/record-page-interalEventMappings.js.map +1 -0
  272. package/dist/workspace-plugin/templates/record-page-layoutModel.d.ts +1 -0
  273. package/dist/workspace-plugin/templates/record-page-layoutModel.js +55 -0
  274. package/dist/workspace-plugin/templates/record-page-layoutModel.js.map +1 -0
  275. package/dist/workspace-plugin/templates/record-page-properties.d.ts +1 -0
  276. package/dist/workspace-plugin/templates/record-page-properties.js +135 -0
  277. package/dist/workspace-plugin/templates/record-page-properties.js.map +1 -0
  278. package/dist/workspace-plugin/templates/record-page.d.ts +3 -0
  279. package/dist/workspace-plugin/templates/record-page.js +8 -0
  280. package/dist/workspace-plugin/templates/record-page.js.map +1 -0
  281. package/dist/workspace-plugin.d.ts +2 -0
  282. package/dist/workspace-plugin.js +453 -0
  283. package/dist/workspace-plugin.js.map +1 -0
  284. package/package.json +10 -12
  285. package/src/_types/eslint-plugin-es-x.d.ts +17 -0
  286. package/src/_types/md5.js.d.ts +8 -0
  287. package/src/acl-plugin.ts +33 -10
  288. package/src/applicability-plugin.ts +82 -0
  289. package/src/application-menu-plugin.ts +1 -0
  290. package/src/atf/step-configs.ts +14 -12
  291. package/src/atf/test-plugin.ts +46 -24
  292. package/src/basic-syntax-plugin.ts +71 -14
  293. package/src/business-rule-plugin.ts +9 -5
  294. package/src/call-expression-plugin.ts +2 -130
  295. package/src/claims-plugin.ts +1 -1
  296. package/src/client-script-plugin.ts +8 -22
  297. package/src/column/column-helper.ts +65 -3
  298. package/src/column/column-to-record.ts +6 -4
  299. package/src/column-plugin.ts +142 -40
  300. package/src/dashboard/dashboard-component-property-defaults.ts +277 -0
  301. package/src/dashboard/dashboard-component-resolver.ts +69 -0
  302. package/src/dashboard/dashboard-plugin.ts +450 -0
  303. package/src/data-plugin.ts +194 -0
  304. package/src/email-notification-plugin.ts +850 -0
  305. package/src/flow/constants/flow-plugin-constants.ts +79 -0
  306. package/src/flow/flow-logic/flow-logic-constants.ts +120 -0
  307. package/src/flow/flow-logic/flow-logic-diagnostics.ts +591 -0
  308. package/src/flow/flow-logic/flow-logic-plugin-helpers.ts +2550 -0
  309. package/src/flow/flow-logic/flow-logic-plugin.ts +337 -0
  310. package/src/flow/flow-logic/flow-logic-shapes.ts +215 -0
  311. package/src/flow/plugins/approval-rules-plugin.ts +48 -0
  312. package/src/flow/plugins/flow-action-definition-plugin.ts +295 -0
  313. package/src/flow/plugins/flow-data-pill-plugin.ts +258 -0
  314. package/src/flow/plugins/flow-definition-plugin.ts +2173 -0
  315. package/src/flow/plugins/flow-diagnostics-plugin.ts +280 -0
  316. package/src/flow/plugins/flow-instance-plugin.ts +1148 -0
  317. package/src/flow/plugins/flow-trigger-instance-plugin.ts +426 -0
  318. package/src/flow/plugins/inline-script-plugin.ts +83 -0
  319. package/src/flow/plugins/step-definition-plugin.ts +67 -0
  320. package/src/flow/plugins/step-instance-plugin.ts +431 -0
  321. package/src/flow/plugins/trigger-plugin.ts +95 -0
  322. package/src/flow/plugins/wfa-datapill-plugin.ts +213 -0
  323. package/src/flow/utils/approval-rules-processor.ts +298 -0
  324. package/src/flow/utils/built-in-complex-objects.ts +81 -0
  325. package/src/flow/utils/complex-object-resolver.ts +875 -0
  326. package/src/flow/utils/complex-objects.ts +656 -0
  327. package/src/flow/utils/data-pill-shapes.ts +165 -0
  328. package/src/flow/utils/datapill-transformer.ts +632 -0
  329. package/src/flow/utils/flow-constants.ts +276 -0
  330. package/src/flow/utils/flow-io-to-record.ts +533 -0
  331. package/src/flow/utils/flow-shapes.ts +296 -0
  332. package/src/flow/utils/flow-to-xml.ts +318 -0
  333. package/src/flow/utils/flow-variable-processor.ts +100 -0
  334. package/src/flow/utils/label-cache-parser.ts +37 -0
  335. package/src/flow/utils/label-cache-processor.ts +870 -0
  336. package/src/flow/utils/pill-string-parser.ts +375 -0
  337. package/src/flow/utils/schema-to-flow-object.ts +385 -0
  338. package/src/flow/utils/utils.ts +395 -0
  339. package/src/import-sets-plugin.ts +542 -0
  340. package/src/index.ts +25 -1
  341. package/src/json-plugin.ts +31 -12
  342. package/src/list-plugin.ts +91 -1
  343. package/src/now-attach-plugin.ts +403 -0
  344. package/src/now-config-plugin.ts +6 -2
  345. package/src/now-include-plugin.ts +8 -1
  346. package/src/package-json-plugin.ts +3 -3
  347. package/src/record-plugin.ts +126 -30
  348. package/src/repack/index.ts +14 -0
  349. package/src/repack/lint/Rules.ts +1 -10
  350. package/src/rest-api-plugin.ts +106 -100
  351. package/src/role-plugin.ts +1 -0
  352. package/src/server-module-plugin/index.ts +74 -22
  353. package/src/service-catalog/catalog-clientscript-plugin.ts +140 -0
  354. package/src/service-catalog/catalog-item-plugin.ts +162 -0
  355. package/src/service-catalog/catalog-ui-policy-plugin.ts +324 -0
  356. package/src/service-catalog/index.ts +5 -0
  357. package/src/service-catalog/record-to-shape.ts +109 -0
  358. package/src/service-catalog/sc-record-producer-plugin.ts +201 -0
  359. package/src/service-catalog/service-catalog-base.ts +600 -0
  360. package/src/service-catalog/service-catalog-diagnostics.ts +251 -0
  361. package/src/service-catalog/shape-to-record.ts +275 -0
  362. package/src/service-catalog/utils.ts +1362 -0
  363. package/src/service-catalog/variable-helper.ts +135 -0
  364. package/src/service-catalog/variable-set-plugin.ts +197 -0
  365. package/src/service-catalog/variables-transform.ts +438 -0
  366. package/src/service-portal/widget-plugin.ts +4 -1
  367. package/src/sla/sla-validators.ts +331 -0
  368. package/src/sla-plugin.ts +358 -0
  369. package/src/static-content-plugin.ts +2 -2
  370. package/src/table-plugin.ts +66 -9
  371. package/src/ui-page-plugin.ts +2 -1
  372. package/src/ui-policy-plugin.ts +505 -0
  373. package/src/utils.ts +50 -1
  374. package/src/ux-list-menu-config-plugin.ts +312 -0
  375. package/src/view-plugin.ts +1 -1
  376. package/src/workspace-plugin/chrome-tab.ts +44 -0
  377. package/src/workspace-plugin/constants.ts +53 -0
  378. package/src/workspace-plugin/fluent-utils.ts +60 -0
  379. package/src/workspace-plugin/page.ts +139 -0
  380. package/src/workspace-plugin/screen.ts +34 -0
  381. package/src/workspace-plugin/templates/index.ts +17 -0
  382. package/src/workspace-plugin/templates/record-page-composition.ts +4051 -0
  383. package/src/workspace-plugin/templates/record-page-data.ts +523 -0
  384. package/src/workspace-plugin/templates/record-page-interalEventMappings.ts +35 -0
  385. package/src/workspace-plugin/templates/record-page-layoutModel.ts +51 -0
  386. package/src/workspace-plugin/templates/record-page-properties.ts +131 -0
  387. package/src/workspace-plugin/templates/record-page.ts +6 -0
  388. package/src/workspace-plugin.ts +574 -0
@@ -0,0 +1,1144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultSaveScript = exports.defaultpostInsertScript = exports.defaultScript = exports.DEFAULT_DELIVERY_TIME = exports.INTERNAL_NAME_MAX_LENGTH = exports.INTERNAL_NAME_REGEX = exports.APPLIES_TO_CATALOG_ITEM = void 0;
4
+ exports.validateRequestedForVariable = validateRequestedForVariable;
5
+ exports.validateVariableSetVariables = validateVariableSetVariables;
6
+ exports.validateVariableTypesForMultiRow = validateVariableTypesForMultiRow;
7
+ exports.validateRequestedForVariableConflict = validateRequestedForVariableConflict;
8
+ exports.validateVariableNameConflicts = validateVariableNameConflicts;
9
+ exports.convertToNumber = convertToNumber;
10
+ exports.getUITypeFromId = getUITypeFromId;
11
+ exports.getUITypeId = getUITypeId;
12
+ exports.getVariableSetTypeFromDb = getVariableSetTypeFromDb;
13
+ exports.getVariableSetTypeToDb = getVariableSetTypeToDb;
14
+ exports.getRedirectUrlFromDb = getRedirectUrlFromDb;
15
+ exports.getRedirectUrlToDb = getRedirectUrlToDb;
16
+ exports.getFulfillmentAutomationLevelFromDb = getFulfillmentAutomationLevelFromDb;
17
+ exports.getFulfillmentAutomationLevelToDb = getFulfillmentAutomationLevelToDb;
18
+ exports.getAvailabilityFromDb = getAvailabilityFromDb;
19
+ exports.getAvailabilityToDb = getAvailabilityToDb;
20
+ exports.getMobilePictureTypeFromDb = getMobilePictureTypeFromDb;
21
+ exports.getMobilePictureTypeToDb = getMobilePictureTypeToDb;
22
+ exports.getValueActionFromDb = getValueActionFromDb;
23
+ exports.getValueActionToDb = getValueActionToDb;
24
+ exports.getVisibilityFromId = getVisibilityFromId;
25
+ exports.getVisibilityId = getVisibilityId;
26
+ exports.findNameInParent = findNameInParent;
27
+ exports.resolveVariableId = resolveVariableId;
28
+ exports.resolveCatalogReferences = resolveCatalogReferences;
29
+ exports.resolveRecordReference = resolveRecordReference;
30
+ exports.parentIdentifier = parentIdentifier;
31
+ exports.createVariablePropertyAccess = createVariablePropertyAccess;
32
+ exports.getTargetRecord = getTargetRecord;
33
+ exports.resolveVariableAccess = resolveVariableAccess;
34
+ exports.processCatalogCondition = processCatalogCondition;
35
+ exports.parseConditionPart = parseConditionPart;
36
+ exports.processCatalogConditionsToShape = processCatalogConditionsToShape;
37
+ exports.convertTitleToInternalName = convertTitleToInternalName;
38
+ exports.validateInternalName = validateInternalName;
39
+ exports.convertRolesToString = convertRolesToString;
40
+ exports.parseString = parseString;
41
+ exports.shouldWriteAsCallExpression = shouldWriteAsCallExpression;
42
+ exports.toValidIdentifier = toValidIdentifier;
43
+ exports.createScript = createScript;
44
+ exports.validateVariableBelongsToTarget = validateVariableBelongsToTarget;
45
+ exports.resolveAndValidateVariableId = resolveAndValidateVariableId;
46
+ exports.APPLIES_TO_CATALOG_ITEM = 'item';
47
+ const sdk_build_core_1 = require("@servicenow/sdk-build-core");
48
+ const now_include_plugin_1 = require("../now-include-plugin");
49
+ const variable_helper_1 = require("./variable-helper");
50
+ // Note: Database, ObjectShape, Diagnostics, and CallExpressionShape are imported for validateRequestedForVariable
51
+ // and other utility functions that validate variable configurations
52
+ /**
53
+ * Validates that there's at most one RequestedForVariable in a variables configuration (used only for VariableSet)
54
+ * @param variablesShape - The ObjectShape containing the variables configuration
55
+ * @param diagnostics - Diagnostics instance for reporting errors
56
+ * @param context - Context where the validation is being performed ('VariableSet')
57
+ * @returns True if validation passes, false otherwise
58
+ */
59
+ function validateRequestedForVariable(variablesShape, diagnostics, context = 'VariableSet') {
60
+ let requestedForCount = 0;
61
+ const entries = Array.from(variablesShape.entries());
62
+ for (const [, value] of entries) {
63
+ const callExpr = value.as(sdk_build_core_1.CallExpressionShape);
64
+ const calleeName = callExpr.getCallee();
65
+ if (calleeName === variable_helper_1.VariableTypeName.REQUESTED_FOR) {
66
+ requestedForCount++;
67
+ if (requestedForCount > 1) {
68
+ diagnostics.error(variablesShape.getOriginalNode(), `Only one RequestedForVariable is allowed in a ${context}`);
69
+ return false;
70
+ }
71
+ }
72
+ }
73
+ return true;
74
+ }
75
+ /**
76
+ * Combined validation for variable sets that performs multiple checks in a single loop:
77
+ * - At most one RequestedForVariable
78
+ * - Variable types not supported in multiRow variable sets
79
+ * @param variablesShape - The ObjectShape containing the variables configuration
80
+ * @param variableSetType - The type of the variable set ('singleRow' or 'multiRow')
81
+ * @param diagnostics - Diagnostics instance for reporting errors
82
+ * @param context - Context where the validation is being performed ('VariableSet')
83
+ * @returns True if validation passes, false otherwise
84
+ */
85
+ function validateVariableSetVariables(variablesShape, variableSetType, diagnostics, context = 'VariableSet') {
86
+ let requestedForCount = 0;
87
+ // Only validate multiRow restrictions for multiRow variable sets
88
+ const isMultiRow = variableSetType === 'multiRow';
89
+ const unsupportedVariableTypes = isMultiRow
90
+ ? new Set([
91
+ variable_helper_1.VariableTypeName.ATTACHMENT,
92
+ variable_helper_1.VariableTypeName.BREAK,
93
+ variable_helper_1.VariableTypeName.CONTAINER_END,
94
+ variable_helper_1.VariableTypeName.CONTAINER_START,
95
+ variable_helper_1.VariableTypeName.CONTAINER_SPLIT,
96
+ variable_helper_1.VariableTypeName.HTML,
97
+ variable_helper_1.VariableTypeName.LABEL,
98
+ variable_helper_1.VariableTypeName.CUSTOM, // Macro
99
+ variable_helper_1.VariableTypeName.CUSTOM_WITH_LABEL, // Macro with label
100
+ variable_helper_1.VariableTypeName.RICH_TEXT_LABEL,
101
+ variable_helper_1.VariableTypeName.UI_PAGE,
102
+ ])
103
+ : null;
104
+ const entries = Array.from(variablesShape.entries());
105
+ for (const [variableName, value] of entries) {
106
+ const callExpr = value.as(sdk_build_core_1.CallExpressionShape);
107
+ const calleeName = callExpr.getCallee();
108
+ // Check RequestedForVariable count
109
+ if (calleeName === variable_helper_1.VariableTypeName.REQUESTED_FOR) {
110
+ requestedForCount++;
111
+ if (requestedForCount > 1) {
112
+ diagnostics.error(variablesShape.getOriginalNode(), `Only one RequestedForVariable is allowed in a ${context}`);
113
+ return false;
114
+ }
115
+ }
116
+ // Check multiRow variable type restrictions
117
+ if (isMultiRow && unsupportedVariableTypes && unsupportedVariableTypes.has(calleeName)) {
118
+ diagnostics.error(value.getOriginalNode(), `Variable type '${calleeName}' is not supported in multiRow variable sets. Variable '${variableName}' cannot be used.`);
119
+ return false;
120
+ }
121
+ }
122
+ return true;
123
+ }
124
+ /**
125
+ * @deprecated Use validateVariableSetVariables instead
126
+ * Validates that certain variable types are not used in multiRow variable sets.
127
+ * MultiRow variable sets don't support certain display/layout variables.
128
+ * @param variablesShape - The ObjectShape containing the variables configuration
129
+ * @param variableSetType - The type of the variable set ('singleRow' or 'multiRow')
130
+ * @param diagnostics - Diagnostics instance for reporting errors
131
+ * @returns True if validation passes, false otherwise
132
+ */
133
+ function validateVariableTypesForMultiRow(variablesShape, variableSetType, diagnostics) {
134
+ return validateVariableSetVariables(variablesShape, variableSetType, diagnostics, 'VariableSet');
135
+ }
136
+ /**
137
+ * Optimized validation that checks all RequestedForVariable constraints in a single pass:
138
+ * - At most one RequestedForVariable in direct variables
139
+ * - Not used in both direct variables and attached variable sets
140
+ * - Only one RequestedForVariable across all attached variable sets
141
+ * @param arg - The ObjectShape containing the catalog item/record producer configuration
142
+ * @param diagnostics - Diagnostics instance for reporting errors
143
+ * @param context - Context where the validation is being performed ('CatalogItem' or 'RecordProducer')
144
+ * @returns True if validation passes, false otherwise
145
+ */
146
+ function validateRequestedForVariableConflict(arg, diagnostics, context) {
147
+ // Single pass through direct variables: count RequestedForVariable instances
148
+ let requestedForCountInDirectVariables = 0;
149
+ if (arg.get('variables').isDefined()) {
150
+ const variablesConfig = arg.get('variables').asObject();
151
+ const entries = Array.from(variablesConfig.entries());
152
+ for (const [, value] of entries) {
153
+ const callExpr = value.as(sdk_build_core_1.CallExpressionShape);
154
+ const calleeName = callExpr.getCallee();
155
+ if (calleeName === 'RequestedForVariable') {
156
+ requestedForCountInDirectVariables++;
157
+ // Validate at most one in direct variables
158
+ if (requestedForCountInDirectVariables > 1) {
159
+ diagnostics.error(variablesConfig.getOriginalNode(), `Only one RequestedForVariable is allowed in a ${context}`);
160
+ return false;
161
+ }
162
+ }
163
+ }
164
+ }
165
+ // Check for RequestedForVariable conflicts across variable sets and direct variables
166
+ if (arg.get('variableSets').isDefined()) {
167
+ const variableSets = arg.get('variableSets').ifArray()?.getElements() ?? [];
168
+ let requestedForVariableSetCount = 0;
169
+ for (const variableSet of variableSets) {
170
+ const varObj = variableSet.asObject();
171
+ if (varObj.get('variableSet').isRecord()) {
172
+ const vsRecord = varObj.get('variableSet').asRecord();
173
+ const variableSetRelRecords = vsRecord.flat().filter((r) => r.getTable() === 'item_option_new');
174
+ if (variableSetRelRecords && variableSetRelRecords.length > 0) {
175
+ for (const variableRecord of variableSetRelRecords) {
176
+ const varType = variableRecord.get('type')?.getValue();
177
+ const varTypeName = variable_helper_1.VARIABLE_TYPE_TO_NAME[varType];
178
+ if (varTypeName === 'RequestedForVariable') {
179
+ requestedForVariableSetCount++;
180
+ // If direct variables also have RequestedForVariable
181
+ if (requestedForCountInDirectVariables > 0) {
182
+ diagnostics.error(arg.get('variables').getOriginalNode(), `RequestedForVariable cannot be used in both ${context} variables and attached VariableSets. Remove RequestedForVariable from either the ${context} variables or the attached VariableSet.`);
183
+ return false;
184
+ }
185
+ // If multiple variable sets have RequestedForVariable
186
+ if (requestedForVariableSetCount > 1) {
187
+ diagnostics.error(arg.get('variableSets').getOriginalNode(), `RequestedForVariable cannot be used in multiple VariableSets attached to the same ${context}. Only one RequestedForVariable is allowed across all VariableSets.`);
188
+ return false;
189
+ }
190
+ }
191
+ }
192
+ }
193
+ }
194
+ }
195
+ }
196
+ return true;
197
+ }
198
+ /**
199
+ * Validates that variable names (keys) in attached variable sets don't conflict with direct variable names
200
+ * @param arg - The ObjectShape containing the catalog item/record producer configuration
201
+ * @param diagnostics - Diagnostics instance for reporting errors
202
+ * @param context - Context where the validation is being performed ('CatalogItem' or 'RecordProducer')
203
+ * @returns True if validation passes, false otherwise
204
+ */
205
+ function validateVariableNameConflicts(arg, diagnostics, context) {
206
+ // Collect all variable names from direct variables
207
+ const directVariableNames = new Set();
208
+ if (arg.get('variables').isDefined()) {
209
+ const variablesConfig = arg.get('variables').asObject();
210
+ const entries = Array.from(variablesConfig.entries());
211
+ for (const [key] of entries) {
212
+ directVariableNames.add(key);
213
+ }
214
+ }
215
+ // If no direct variables, no conflict possible
216
+ if (directVariableNames.size === 0) {
217
+ return true;
218
+ }
219
+ // Check for name conflicts in attached variable sets
220
+ if (arg.get('variableSets').isDefined()) {
221
+ const variableSets = arg.get('variableSets').ifArray()?.getElements() ?? [];
222
+ for (const variableSet of variableSets) {
223
+ const varObj = variableSet.asObject();
224
+ if (varObj.get('variableSet').isRecord()) {
225
+ const vsRecord = varObj.get('variableSet').asRecord();
226
+ const variableSetRelRecords = vsRecord.flat().filter((r) => r.getTable() === 'item_option_new');
227
+ if (variableSetRelRecords && variableSetRelRecords.length > 0) {
228
+ for (const variableRecord of variableSetRelRecords) {
229
+ const varName = variableRecord.get('name')?.getValue();
230
+ if (varName && directVariableNames.has(varName)) {
231
+ diagnostics.error(arg.get('variables').getOriginalNode(), `Variable name conflict: '${varName}' is defined in both ${context} variables and an attached VariableSet. Each variable must have a unique name across the ${context} and all attached VariableSets.`);
232
+ return false;
233
+ }
234
+ }
235
+ }
236
+ }
237
+ }
238
+ }
239
+ return true;
240
+ }
241
+ /**
242
+ * Safely converts a value to a number with a default fallback
243
+ * Handles empty strings and undefined values
244
+ * @param value - The value to convert
245
+ * @param defaultValue - The default value to use if conversion fails or value is empty/undefined
246
+ * @returns The converted number or default value
247
+ */
248
+ function convertToNumber(value, defaultValue = 0) {
249
+ if (!value || value.isUndefined() || value.ifString()?.isEmpty()) {
250
+ return defaultValue;
251
+ }
252
+ return value.toNumber()?.getValue() ?? defaultValue;
253
+ }
254
+ function getUITypeFromId(id) {
255
+ switch (id) {
256
+ case 0:
257
+ return 'desktop';
258
+ case 1:
259
+ return 'mobileOrServicePortal';
260
+ case 10:
261
+ return 'all';
262
+ default:
263
+ throw Error('Invalid UI Type encountered, check XML data before transforming again.');
264
+ }
265
+ }
266
+ function getUITypeId(value) {
267
+ switch (value) {
268
+ case 'desktop':
269
+ return 0;
270
+ case 'mobileOrServicePortal':
271
+ return 1;
272
+ case 'all':
273
+ return 10;
274
+ default:
275
+ return 0; // Default to desktop
276
+ }
277
+ }
278
+ /**
279
+ * Mapping between ServiceNow variable set type database values and TypeScript enum values
280
+ */
281
+ const VariableSetTypeMapping = {
282
+ one_to_one: 'singleRow',
283
+ one_to_many: 'multiRow',
284
+ };
285
+ /**
286
+ * Converts ServiceNow variable set type database value to camelCase enum value
287
+ * @param dbValue - Database value ('one_to_one' or 'one_to_many')
288
+ * @returns TypeScript enum value ('singleRow' or 'multiRow')
289
+ */
290
+ function getVariableSetTypeFromDb(dbValue) {
291
+ const type = VariableSetTypeMapping[dbValue];
292
+ if (!type) {
293
+ return 'singleRow'; // Default to singleRow if invalid
294
+ }
295
+ return type;
296
+ }
297
+ /**
298
+ * Converts TypeScript enum value to ServiceNow variable set type database value
299
+ * @param value - TypeScript enum value ('singleRow' or 'multiRow')
300
+ * @returns Database value ('one_to_one' or 'one_to_many')
301
+ */
302
+ function getVariableSetTypeToDb(value) {
303
+ switch (value) {
304
+ case 'singleRow':
305
+ return 'one_to_one';
306
+ case 'multiRow':
307
+ return 'one_to_many';
308
+ default:
309
+ return 'one_to_one'; // Default to one_to_one if invalid
310
+ }
311
+ }
312
+ /**
313
+ * Mapping between ServiceNow redirect URL database values and TypeScript enum values
314
+ */
315
+ const RedirectUrlMapping = {
316
+ generated_record: 'generatedRecord',
317
+ catalog_home: 'catalogHomePage',
318
+ };
319
+ /**
320
+ * Converts ServiceNow redirect URL database value to camelCase enum value
321
+ * @param dbValue - Database value ('generated_record' or 'catalog_home')
322
+ * @returns TypeScript enum value ('generatedRecord' or 'catalogHomePage')
323
+ */
324
+ function getRedirectUrlFromDb(dbValue) {
325
+ const type = RedirectUrlMapping[dbValue];
326
+ if (!type) {
327
+ return 'generatedRecord'; // Default to generatedRecord if invalid
328
+ }
329
+ return type;
330
+ }
331
+ /**
332
+ * Converts TypeScript enum value to ServiceNow redirect URL database value
333
+ * @param value - TypeScript enum value ('generatedRecord' or 'catalogHomePage')
334
+ * @returns Database value ('generated_record' or 'catalog_home')
335
+ */
336
+ function getRedirectUrlToDb(value) {
337
+ switch (value) {
338
+ case 'generatedRecord':
339
+ return 'generated_record';
340
+ case 'catalogHomePage':
341
+ return 'catalog_home';
342
+ default:
343
+ return 'generated_record'; // Default to generated_record if invalid
344
+ }
345
+ }
346
+ /**
347
+ * Mapping between ServiceNow fulfillment automation level database values and TypeScript enum values
348
+ */
349
+ const FulfillmentAutomationLevelMapping = {
350
+ unspecified: 'unspecified',
351
+ manual: 'manual',
352
+ semi_automated: 'semiAutomated',
353
+ fully_automated: 'fullyAutomated',
354
+ };
355
+ /**
356
+ * Converts ServiceNow fulfillment automation level database value to camelCase enum value
357
+ * @param dbValue - Database value ('unspecified', 'manual', 'semi_automated', or 'fully_automated')
358
+ * @returns TypeScript enum value ('unspecified', 'manual', 'semiAutomated', or 'fullyAutomated')
359
+ */
360
+ function getFulfillmentAutomationLevelFromDb(dbValue) {
361
+ const type = FulfillmentAutomationLevelMapping[dbValue];
362
+ if (!type) {
363
+ return 'unspecified'; // Default to unspecified if invalid
364
+ }
365
+ return type;
366
+ }
367
+ /**
368
+ * Converts TypeScript enum value to ServiceNow fulfillment automation level database value
369
+ * @param value - TypeScript enum value ('unspecified', 'manual', 'semiAutomated', or 'fullyAutomated')
370
+ * @returns Database value ('unspecified', 'manual', 'semi_automated', or 'fully_automated')
371
+ */
372
+ function getFulfillmentAutomationLevelToDb(value) {
373
+ switch (value) {
374
+ case 'unspecified':
375
+ return 'unspecified';
376
+ case 'manual':
377
+ return 'manual';
378
+ case 'semiAutomated':
379
+ return 'semi_automated';
380
+ case 'fullyAutomated':
381
+ return 'fully_automated';
382
+ default:
383
+ return 'unspecified'; // Default to unspecified if invalid
384
+ }
385
+ }
386
+ /**
387
+ * Mapping between ServiceNow availability database values and TypeScript enum values
388
+ */
389
+ const AvailabilityMapping = {
390
+ on_desktop: 'desktopOnly',
391
+ on_mobile: 'mobileOnly',
392
+ on_both: 'both',
393
+ };
394
+ /**
395
+ * Converts ServiceNow availability database value to camelCase enum value
396
+ * @param dbValue - Database value ('on_desktop', 'on_mobile', or 'on_both')
397
+ * @returns TypeScript enum value ('desktopOnly', 'mobileOnly', or 'both')
398
+ */
399
+ function getAvailabilityFromDb(dbValue) {
400
+ const type = AvailabilityMapping[dbValue];
401
+ if (!type) {
402
+ return 'desktopOnly'; // Default to desktopOnly if invalid
403
+ }
404
+ return type;
405
+ }
406
+ /**
407
+ * Converts TypeScript enum value to ServiceNow availability database value
408
+ * @param value - TypeScript enum value ('desktopOnly', 'mobileOnly', or 'both')
409
+ * @returns Database value ('on_desktop', 'on_mobile', or 'on_both')
410
+ */
411
+ function getAvailabilityToDb(value) {
412
+ switch (value) {
413
+ case 'desktopOnly':
414
+ return 'on_desktop';
415
+ case 'mobileOnly':
416
+ return 'on_mobile';
417
+ case 'both':
418
+ return 'on_both';
419
+ default:
420
+ return 'on_desktop'; // Default to on_desktop if invalid
421
+ }
422
+ }
423
+ /**
424
+ * Mapping between ServiceNow mobile picture type database values and TypeScript enum values
425
+ */
426
+ const MobilePictureTypeMapping = {
427
+ use_desktop_picture: 'desktopPicture',
428
+ use_mobile_picture: 'mobilePicture',
429
+ use_no_picture: 'noPicture',
430
+ };
431
+ /**
432
+ * Converts ServiceNow mobile picture type database value to camelCase enum value
433
+ * @param dbValue - Database value ('use_desktop_picture', 'use_mobile_picture', or 'use_no_picture')
434
+ * @returns TypeScript enum value ('desktopPicture', 'mobilePicture', or 'noPicture')
435
+ */
436
+ function getMobilePictureTypeFromDb(dbValue) {
437
+ const type = MobilePictureTypeMapping[dbValue];
438
+ if (!type) {
439
+ return 'desktopPicture'; // Default to desktopPicture if invalid
440
+ }
441
+ return type;
442
+ }
443
+ /**
444
+ * Converts TypeScript enum value to ServiceNow mobile picture type database value
445
+ * @param value - TypeScript enum value ('desktopPicture', 'mobilePicture', or 'noPicture')
446
+ * @returns Database value ('use_desktop_picture', 'use_mobile_picture', or 'use_no_picture')
447
+ */
448
+ function getMobilePictureTypeToDb(value) {
449
+ switch (value) {
450
+ case 'desktopPicture':
451
+ return 'use_desktop_picture';
452
+ case 'mobilePicture':
453
+ return 'use_mobile_picture';
454
+ case 'noPicture':
455
+ return 'use_no_picture';
456
+ default:
457
+ return 'use_desktop_picture'; // Default to use_desktop_picture if invalid
458
+ }
459
+ }
460
+ /**
461
+ * Mapping between ServiceNow value action database values and TypeScript enum values
462
+ */
463
+ const ValueActionMapping = {
464
+ clear_value: 'clearValue',
465
+ set_value: 'setValue',
466
+ };
467
+ /**
468
+ * Converts ServiceNow value action database value to camelCase enum value
469
+ * @param dbValue - Database value ('clear_value', 'set_value', or 'ignore')
470
+ * @returns TypeScript enum value ('clearValue', 'setValue'), or undefined if 'ignore'
471
+ */
472
+ function getValueActionFromDb(dbValue) {
473
+ if (dbValue === 'ignore') {
474
+ return undefined;
475
+ }
476
+ const type = ValueActionMapping[dbValue];
477
+ if (!type) {
478
+ return undefined; // Return undefined for 'ignore' or invalid values
479
+ }
480
+ return type;
481
+ }
482
+ /**
483
+ * Converts TypeScript enum value to ServiceNow value action database value
484
+ * @param value - TypeScript enum value ('clearValue', 'setValue', or 'ignore')
485
+ * @returns Database value ('clear_value', 'set_value', or 'ignore')
486
+ */
487
+ function getValueActionToDb(value) {
488
+ switch (value) {
489
+ case 'clearValue':
490
+ return 'clear_value';
491
+ case 'setValue':
492
+ return 'set_value';
493
+ case 'ignore':
494
+ return 'ignore';
495
+ default:
496
+ return 'ignore'; // Default to ignore if invalid
497
+ }
498
+ }
499
+ const VisibilityTypeMapping = {
500
+ Always: 1,
501
+ Bundle: 2,
502
+ Standalone: 3,
503
+ };
504
+ function getVisibilityFromId(id) {
505
+ const entry = Object.entries(VisibilityTypeMapping).find(([, value]) => value === id);
506
+ if (!entry) {
507
+ return 'Always'; // Default to Always if invalid
508
+ }
509
+ return entry[0];
510
+ }
511
+ function getVisibilityId(value) {
512
+ if (value in VisibilityTypeMapping) {
513
+ return VisibilityTypeMapping[value];
514
+ }
515
+ return 1; // Default to Always
516
+ }
517
+ /**
518
+ * Finds a variable record from a catalog item's related records by variable name
519
+ * @param catalogItemRecord - The catalog item Record to search in
520
+ * @param variableName - The name of the variable to find
521
+ * @returns The variable record if found, undefined otherwise
522
+ */
523
+ function findNameInParent(catalogItemRecord, variableName) {
524
+ const relatedRecords = catalogItemRecord.flat();
525
+ return relatedRecords.find((record) => record.getTable() === 'item_option_new' && record.get('name')?.ifString()?.getValue() === variableName);
526
+ }
527
+ /**
528
+ * Resolves a variable ID from a parent record and variable name with fallback logic
529
+ * @param parentRecord - The resolved parent record (may or may not be a Record instance)
530
+ * @param variableName - The name of the variable to resolve
531
+ * @returns The formatted variable ID with IO: prefix
532
+ */
533
+ function resolveVariableId(parentRecord, variableName) {
534
+ if (parentRecord.isRecord()) {
535
+ const variableRecord = findNameInParent(parentRecord, variableName);
536
+ if (variableRecord) {
537
+ return `IO:${variableRecord.getId().getValue()}`;
538
+ }
539
+ }
540
+ // Fallback to string value if variable record not found or parentRecord is not a Record
541
+ return `IO:${variableName}`;
542
+ }
543
+ /**
544
+ * Resolves catalog item and variable set references based on the applies_to field
545
+ * @param record - The source record containing catalog_item/cat_item and variable_set fields
546
+ * @param database - The database instance for looking up records
547
+ * @returns Object with catalogItemReference and variableSetReference
548
+ */
549
+ function resolveCatalogReferences(record, database) {
550
+ const appliesTo = record.get('applies_to')?.ifString()?.getValue() || exports.APPLIES_TO_CATALOG_ITEM;
551
+ let catalogItemReference;
552
+ let variableSetReference;
553
+ const targetRecord = getTargetRecord(record, database);
554
+ if (targetRecord?.isRecord()) {
555
+ const identifier = parentIdentifier(targetRecord);
556
+ const recordId = targetRecord.getId().getValue();
557
+ if (appliesTo === exports.APPLIES_TO_CATALOG_ITEM) {
558
+ catalogItemReference = identifier || recordId;
559
+ }
560
+ else if (appliesTo === 'set') {
561
+ variableSetReference = identifier || recordId;
562
+ }
563
+ }
564
+ else {
565
+ if (appliesTo === exports.APPLIES_TO_CATALOG_ITEM) {
566
+ catalogItemReference =
567
+ record.get('catalog_item')?.ifString()?.getValue() || record.get('cat_item')?.ifString()?.getValue();
568
+ }
569
+ else if (appliesTo === 'set') {
570
+ variableSetReference = record.get('variable_set')?.ifString()?.getValue();
571
+ }
572
+ }
573
+ return { catalogItemReference, variableSetReference };
574
+ }
575
+ /**
576
+ * Resolves a record reference (catalog item or variable set) to an IdentifierShape
577
+ * @param recordId - The sys_id of the record to resolve
578
+ * @param tableName - The table name ('sc_cat_item' or 'item_option_new_set')
579
+ * @param database - The database instance for looking up records
580
+ * @returns IdentifierShape if the record exists and has a name, otherwise the original sys_id or undefined
581
+ */
582
+ function resolveRecordReference(recordId, tableName, database) {
583
+ if (!recordId || recordId.trim() === '') {
584
+ return undefined;
585
+ }
586
+ const record = database.get(tableName, recordId);
587
+ if (record?.isRecord()) {
588
+ const identifier = parentIdentifier(record);
589
+ return identifier || recordId;
590
+ }
591
+ return recordId;
592
+ }
593
+ function parentIdentifier(parentRecord) {
594
+ // First try to get the name from the AST (for Fluent → platform transformation)
595
+ if (parentRecord.getCreator()) {
596
+ const parentName = parentRecord
597
+ ?.getOriginalNode()
598
+ ?.getFirstAncestorByKind(sdk_build_core_1.ts.SyntaxKind.VariableDeclaration)
599
+ ?.getName();
600
+ if (parentName) {
601
+ return new sdk_build_core_1.IdentifierShape({
602
+ source: parentRecord.getOriginalNode(),
603
+ name: parentName,
604
+ value: parentRecord,
605
+ });
606
+ }
607
+ }
608
+ // Fallback: generate identifier name from record's name field (for platform → Fluent transformation)
609
+ const recordName = parentRecord.get('sys_class_name')?.ifString()?.getValue() === 'item_option_new_set'
610
+ ? parentRecord.get('title')?.ifString()?.getValue()
611
+ : parentRecord.get('name')?.ifString()?.getValue();
612
+ if (recordName) {
613
+ const identifierName = toValidIdentifier(recordName);
614
+ return new sdk_build_core_1.IdentifierShape({
615
+ source: parentRecord,
616
+ name: identifierName,
617
+ value: parentRecord,
618
+ });
619
+ }
620
+ return undefined;
621
+ }
622
+ /**
623
+ * Creates a PropertyAccessShape for a catalog variable from an item record
624
+ * @param itemId - The item_option_new record
625
+ * @param source - The source record for the PropertyAccessShape
626
+ * @param parent - The parent record from the record
627
+ * @returns PropertyAccessShape representing catalogItem.variables.variableName
628
+ */
629
+ function createVariablePropertyAccess(variableRecord, source, parent) {
630
+ if (!variableRecord.getCreator()) {
631
+ return undefined;
632
+ }
633
+ // Extract the catalog item variable name from the AST
634
+ const parentName = variableRecord
635
+ ?.getOriginalNode()
636
+ ?.getFirstAncestorByKind(sdk_build_core_1.ts.SyntaxKind.VariableDeclaration)
637
+ ?.getName();
638
+ if (!parentName) {
639
+ return undefined;
640
+ }
641
+ // Extract the variable property name
642
+ const varName = variableRecord?.getOriginalNode()?.getParent()?.asKind(sdk_build_core_1.ts.SyntaxKind.PropertyAssignment)?.getName();
643
+ if (!varName) {
644
+ return undefined;
645
+ }
646
+ // Create identifier for the catalog item using parent's original node for proper import tracking
647
+ const parentIdentifier = new sdk_build_core_1.IdentifierShape({
648
+ source: parent.getOriginalNode(),
649
+ name: parentName,
650
+ value: parent,
651
+ });
652
+ // Create and return the property access shape
653
+ return new sdk_build_core_1.PropertyAccessShape({
654
+ source: source,
655
+ elements: [parentIdentifier, 'variables', varName],
656
+ });
657
+ }
658
+ /**
659
+ * Resolves the appropriate record for catalog item or variable set operations
660
+ * @param record - The source record containing catalog_item/cat_item or variable_set references
661
+ * @param database - The database instance for looking up records by ID
662
+ * @returns The resolved record (sc_cat_item or item_option_new_set) or undefined if not found
663
+ */
664
+ function getTargetRecord(record, database) {
665
+ if (record.get('applies_to')?.ifString()?.getValue() === exports.APPLIES_TO_CATALOG_ITEM) {
666
+ // Try catalog_item field (used in UI policies)
667
+ if (record.get('catalog_item')?.isDefined() && record.get('catalog_item')?.isRecord()) {
668
+ return record.get('catalog_item').asRecord();
669
+ }
670
+ // Try cat_item field (used in client scripts)
671
+ else if (record.get('cat_item')?.isDefined() && record.get('cat_item')?.isRecord()) {
672
+ return record.get('cat_item').asRecord();
673
+ }
674
+ // Try catalog_item string reference (used in UI policies)
675
+ else if (record.get('catalog_item')?.isDefined() && !record.get('catalog_item')?.ifString()?.isEmpty()) {
676
+ return database.get('sc_cat_item', record.get('catalog_item').asString()?.getValue());
677
+ }
678
+ // Try cat_item string reference (used in client scripts)
679
+ else if (record.get('cat_item')?.isDefined() && !record.get('cat_item')?.ifString()?.isEmpty()) {
680
+ return database.get('sc_cat_item', record.get('cat_item').asString()?.getValue());
681
+ }
682
+ //Fallback to sys_id
683
+ return undefined;
684
+ }
685
+ else {
686
+ // Handle variable set record reference
687
+ if (record.get('variable_set')?.isRecord()) {
688
+ return record.get('variable_set').asRecord();
689
+ }
690
+ // Handle variable set string reference
691
+ else if (!record.get('variable_set')?.ifString()?.isEmpty()) {
692
+ return database.get('item_option_new_set', record.get('variable_set').asString()?.getValue());
693
+ }
694
+ return undefined;
695
+ }
696
+ }
697
+ /**
698
+ * Resolves a variable name from a PropertyAccessShape
699
+ * @param variableNameShape - The shape containing the property access
700
+ * @returns An object containing the parent record and variable name
701
+ */
702
+ function resolveVariableAccess(variableNameShape) {
703
+ const propertyAccess = variableNameShape;
704
+ const variableName = propertyAccess.getLastElement().getName();
705
+ const parentIdentifier = propertyAccess.getElements()[0];
706
+ try {
707
+ const resolved = parentIdentifier.resolve(true);
708
+ if (!resolved || !resolved.isRecord()) {
709
+ return undefined;
710
+ }
711
+ const parentRecord = resolved.asRecord();
712
+ return { parentRecord, variableName };
713
+ }
714
+ catch (error) {
715
+ // Resolution failed, return undefined to allow fallback
716
+ return undefined;
717
+ }
718
+ }
719
+ /**
720
+ * Processes a catalog condition template expression
721
+ * @param conditionShape - The shape containing the catalog condition
722
+ * @param appliesTo - Optional appliesTo value for validation
723
+ * @param variableSetShape - Optional variable set shape for validation
724
+ * @param catalogItemShape - Optional catalog item shape for validation
725
+ * @param diagnostics - Optional diagnostics instance for reporting validation errors
726
+ * @returns The processed condition string with resolved variable references
727
+ */
728
+ function processCatalogCondition(conditionShape, appliesTo, variableSetShape, catalogItemShape, diagnostics) {
729
+ // Handle template expressions with variable references
730
+ if (conditionShape.is(sdk_build_core_1.TemplateExpressionShape)) {
731
+ const templateExpr = conditionShape.as(sdk_build_core_1.TemplateExpressionShape);
732
+ let result = templateExpr.getLiteralText();
733
+ // Process each span (interpolated expression)
734
+ for (const span of templateExpr.getSpans()) {
735
+ const expr = span.getExpression();
736
+ // Handle property access (e.g., catalogItem.variables.name)
737
+ if (expr.is(sdk_build_core_1.PropertyAccessShape)) {
738
+ const variableAccess = resolveVariableAccess(expr.as(sdk_build_core_1.PropertyAccessShape));
739
+ if (variableAccess) {
740
+ const variableId = resolveVariableId(variableAccess.parentRecord, variableAccess.variableName);
741
+ result += variableId;
742
+ // Validate variable belongs to target based on appliesTo
743
+ const targetShape = appliesTo === 'set' ? variableSetShape : catalogItemShape;
744
+ if (appliesTo && targetShape?.is(sdk_build_core_1.IdentifierShape)) {
745
+ validateVariableBelongsToTarget(targetShape.as(sdk_build_core_1.IdentifierShape), variableAccess.parentRecord, appliesTo, diagnostics);
746
+ }
747
+ }
748
+ else {
749
+ result += expr.toString().getValue();
750
+ }
751
+ }
752
+ else {
753
+ // Fallback to string value
754
+ result += expr.toString().getValue();
755
+ }
756
+ result += span.getLiteralText();
757
+ }
758
+ return result;
759
+ }
760
+ else {
761
+ // Handle plain string
762
+ if (conditionShape.ifString()?.isEmpty()) {
763
+ return undefined;
764
+ }
765
+ const conditionValue = conditionShape.toString()?.getValue();
766
+ if (!conditionValue) {
767
+ return undefined;
768
+ }
769
+ // Add IO: prefixes back for XML format
770
+ // Handle patterns like: c34b1842b7321010e54deb56ee11a92b=21^ORc34b1842b7321010e54deb56ee11a92b=18^...
771
+ // Should become: IO:c34b1842b7321010e54deb56ee11a92b=21^ORIO:c34b1842b7321010e54deb56ee11a92b=18^...
772
+ // Match the correct ServiceNow catalog condition format
773
+ return conditionValue
774
+ .replace(/^(?!IO:)/, 'IO:') // Add IO: if not already present
775
+ .replace(/\^OR(?!IO:)/g, '^ORIO:') // Convert ^OR to ^ORIO: (but not if already ^ORIO:)
776
+ .replace(/\^NQ(?!IO:)/g, '^NQIO:') // Convert ^NQ to ^NQIO: (but not if already ^NQIO:)
777
+ .replace(/\^(?!(ORIO:|NQIO:|EQ))/g, '^IO:') // Add IO: after ^ except for ORIO:, NQIO:, EQ
778
+ .replace(/(?<!\^EQ)$/, '^EQ'); // Add ^EQ at end if not already present
779
+ }
780
+ }
781
+ /**
782
+ * Parses a single catalog condition part and extracts logical operators and variable references
783
+ * @param part - The condition part to parse
784
+ * @param record - The source record
785
+ * @param database - The database instance for looking up records
786
+ * @returns Parsed condition part with extracted components
787
+ */
788
+ function parseConditionPart(part, record, database) {
789
+ // Skip empty parts
790
+ if (!part.trim()) {
791
+ return undefined;
792
+ }
793
+ // Check for logical operators at the beginning (only OR and NQ are valid prefixes)
794
+ const logicalOperatorMatch = part.match(/^(OR|NQ)/);
795
+ const logicalOperator = logicalOperatorMatch?.[1] || '';
796
+ const remainingPart = logicalOperator ? part.substring(logicalOperator.length) : part;
797
+ // Handle different possible ID formats
798
+ let conditionVarId = '';
799
+ let operatorSuffix = '';
800
+ if (remainingPart.length >= 32) {
801
+ // Try standard 32-character ID first
802
+ const potentialId = remainingPart.substring(0, 32);
803
+ if ((0, sdk_build_core_1.isGUID)(potentialId)) {
804
+ conditionVarId = potentialId;
805
+ operatorSuffix = remainingPart.substring(32);
806
+ }
807
+ else {
808
+ // Look for other patterns like variable names
809
+ const varMatch = remainingPart.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(.*)/);
810
+ if (varMatch?.[1]) {
811
+ conditionVarId = varMatch[1];
812
+ operatorSuffix = varMatch[2] || '';
813
+ }
814
+ }
815
+ }
816
+ const conditionVarRecord = conditionVarId.length === 32 ? database.get('item_option_new', conditionVarId) : null;
817
+ const appliesToRecord = getTargetRecord(record, database);
818
+ if (conditionVarRecord && conditionVarId.length === 32 && appliesToRecord) {
819
+ const propAccess = createVariablePropertyAccess(conditionVarRecord, record, appliesToRecord);
820
+ if (propAccess) {
821
+ return {
822
+ logicalOperator,
823
+ processedContent: propAccess,
824
+ operatorSuffix,
825
+ hasPropertyAccess: true,
826
+ };
827
+ }
828
+ }
829
+ // Fallback: treat as literal text if no variable found
830
+ // Use remainingPart (without logical operator) to avoid duplicating the OR/NQ prefix
831
+ return {
832
+ logicalOperator,
833
+ processedContent: remainingPart,
834
+ operatorSuffix: '',
835
+ hasPropertyAccess: false,
836
+ };
837
+ }
838
+ /**
839
+ * Processes catalog conditions and converts them to either a TemplateExpressionShape or a string
840
+ * @param record - The record containing the catalog conditions
841
+ * @param database - The database instance for looking up records
842
+ * @returns The processed conditions as a TemplateExpressionShape or string, or undefined if no conditions
843
+ */
844
+ function processCatalogConditionsToShape(record, database) {
845
+ let conditionsValue = record.get('catalog_conditions')?.ifString()?.getValue();
846
+ if (!conditionsValue) {
847
+ return undefined;
848
+ }
849
+ // Handle the real ServiceNow catalog condition format
850
+ // Real format: ^ORIO:OR needs to become ^OR (not ^OROR!)
851
+ conditionsValue = conditionsValue
852
+ .replace(/\^ORIO:/g, '^OR') // Handle ^ORIO: -> ^OR
853
+ .replace(/\^NQIO:/g, '^NQ') // Handle ^NQIO: -> ^NQ
854
+ .replace(/IO:/g, '') // Remove all remaining IO: prefixes
855
+ .replace(/(?<!\^EQ)$/, '^EQ'); // Add ^EQ at end if not already present
856
+ // Don't process ^OR again since we've already handled ^ORIO: above
857
+ if (!conditionsValue) {
858
+ return undefined;
859
+ }
860
+ const conditionParts = conditionsValue.split('^');
861
+ let hasPropertyAccess = false;
862
+ const processedParts = [];
863
+ conditionParts.forEach((part, index) => {
864
+ const parsed = parseConditionPart(part, record, database);
865
+ if (!parsed) {
866
+ return; // Skip empty parts
867
+ }
868
+ if (parsed.hasPropertyAccess) {
869
+ hasPropertyAccess = true;
870
+ }
871
+ // Build the complete part string with logical operator and suffix
872
+ let partString = '';
873
+ // Add logical operator prefix if present
874
+ if (parsed.logicalOperator) {
875
+ partString += parsed.logicalOperator;
876
+ }
877
+ // Add the main content (property access or literal)
878
+ if (typeof parsed.processedContent === 'string') {
879
+ partString += parsed.processedContent;
880
+ // Add operator suffix if present
881
+ if (parsed.operatorSuffix) {
882
+ partString += parsed.operatorSuffix;
883
+ }
884
+ processedParts.push(partString);
885
+ }
886
+ else {
887
+ // For property access, push logical operator prefix as literal text first
888
+ if (partString) {
889
+ processedParts.push(partString);
890
+ }
891
+ processedParts.push(parsed.processedContent);
892
+ // Push operator suffix as literal text after the property access
893
+ if (parsed.operatorSuffix) {
894
+ processedParts.push(parsed.operatorSuffix);
895
+ }
896
+ }
897
+ // Add separator between parts (but not after last)
898
+ if (index < conditionParts.length - 1) {
899
+ processedParts.push('^');
900
+ }
901
+ });
902
+ if (!hasPropertyAccess) {
903
+ return processedParts.join('');
904
+ }
905
+ // Build template expression
906
+ const spans = [];
907
+ let currentIndex = 0;
908
+ for (const part of processedParts) {
909
+ if (part instanceof sdk_build_core_1.PropertyAccessShape) {
910
+ const nextPropIndex = processedParts.findIndex((p, idx) => idx > currentIndex && p instanceof sdk_build_core_1.PropertyAccessShape);
911
+ const endIndex = nextPropIndex === -1 ? processedParts.length : nextPropIndex;
912
+ const literalText = processedParts.slice(currentIndex + 1, endIndex).join('');
913
+ spans.push(new sdk_build_core_1.TemplateSpanShape({
914
+ source: record,
915
+ expression: part,
916
+ literalText,
917
+ }));
918
+ }
919
+ currentIndex++;
920
+ }
921
+ const firstPropIndex = processedParts.findIndex((p) => p instanceof sdk_build_core_1.PropertyAccessShape);
922
+ const initialLiteral = processedParts.slice(0, firstPropIndex).join('');
923
+ return new sdk_build_core_1.TemplateExpressionShape({
924
+ source: record,
925
+ literalText: initialLiteral,
926
+ spans,
927
+ });
928
+ }
929
+ /**
930
+ * Converts a title to a valid ServiceNow internal name (snake_case)
931
+ * @param title - The title to convert
932
+ * @returns Snake_case internal name
933
+ */
934
+ function convertTitleToInternalName(title) {
935
+ return title
936
+ .trim()
937
+ .toLowerCase()
938
+ .replace(/[^a-z0-9]+/g, '_')
939
+ .replace(/^_+|_+$/g, '');
940
+ }
941
+ /**
942
+ * Validation constants for internal names
943
+ */
944
+ exports.INTERNAL_NAME_REGEX = /^[a-z][a-z0-9_]*$/;
945
+ exports.INTERNAL_NAME_MAX_LENGTH = 80;
946
+ /**
947
+ * Validates an internal name for ServiceNow compatibility
948
+ * @param internalName - The internal name to validate
949
+ * @returns Validation result with error message if invalid
950
+ */
951
+ function validateInternalName(internalName) {
952
+ if (!exports.INTERNAL_NAME_REGEX.test(internalName)) {
953
+ return {
954
+ valid: false,
955
+ error: 'VariableSet internalName must start with a lowercase letter and contain only lowercase letters, numbers, and underscores (snake_case format). ' +
956
+ 'No spaces, hyphens, or uppercase letters allowed.',
957
+ };
958
+ }
959
+ if (internalName.length > exports.INTERNAL_NAME_MAX_LENGTH) {
960
+ return {
961
+ valid: false,
962
+ error: `VariableSet internalName must be ${exports.INTERNAL_NAME_MAX_LENGTH} characters or less. ` +
963
+ `Current length: ${internalName.length}`,
964
+ };
965
+ }
966
+ return { valid: true };
967
+ }
968
+ /**
969
+ * Converts role values (arrays or Role records) to comma-separated string for ServiceNow storage
970
+ * Handles both string arrays and Role record references
971
+ * @param v - Shape value containing role data
972
+ * @returns Comma-separated role string or undefined
973
+ */
974
+ function convertRolesToString(v) {
975
+ return v
976
+ .ifArray()
977
+ ?.pipe((r) => Array.from(new Set(r.getElements().map((role) => role.ifRecord()?.get('name').getValue() ?? role.getValue()))).join(','));
978
+ }
979
+ /**
980
+ * Parses comma-separated string into an array
981
+ * @param string - Comma-separated string (e.g., "admin,itil")
982
+ * @returns Array of trimmed strings
983
+ */
984
+ function parseString(commaSeparatedString) {
985
+ if (commaSeparatedString.isUndefined() || commaSeparatedString.toString().isEmpty()) {
986
+ return [];
987
+ }
988
+ return commaSeparatedString
989
+ .toString()
990
+ .getValue()
991
+ .split(',')
992
+ .map((s) => s.trim())
993
+ .filter(Boolean);
994
+ }
995
+ /**
996
+ * Checks if the record should be written as a call expression
997
+ * @param record - The record to check
998
+ * @returns True if the record should be written as a call expression, false otherwise
999
+ */
1000
+ function shouldWriteAsCallExpression(record) {
1001
+ const originalSource = record.getOriginalSource();
1002
+ return sdk_build_core_1.ts.Node.isNode(originalSource) && originalSource.isKind(sdk_build_core_1.ts.SyntaxKind.CallExpression);
1003
+ }
1004
+ /**
1005
+ * Converts a name to a valid JavaScript identifier
1006
+ * Examples:
1007
+ * "Backend item" -> "backendItem"
1008
+ * "Developer Workstation" -> "developerWorkstation"
1009
+ * "My-Special_Item 123" -> "mySpecialItem123"
1010
+ */
1011
+ function toValidIdentifier(name) {
1012
+ return (name
1013
+ .trim()
1014
+ // Replace non-alphanumeric characters with spaces
1015
+ .replace(/[^a-zA-Z0-9]+/g, ' ')
1016
+ // Convert to camelCase
1017
+ .split(' ')
1018
+ .filter(Boolean)
1019
+ .map((word, index) => {
1020
+ const lowerWord = word.toLowerCase();
1021
+ return index === 0 ? lowerWord : lowerWord.charAt(0).toUpperCase() + lowerWord.slice(1);
1022
+ })
1023
+ .join('')
1024
+ // Ensure it doesn't start with a number
1025
+ .replace(/^[0-9]/, '_$&'));
1026
+ }
1027
+ /**
1028
+ * Default delivery time value used when no delivery time is specified
1029
+ */
1030
+ exports.DEFAULT_DELIVERY_TIME = '1970-01-01 00:00:00';
1031
+ /**
1032
+ * Creates a NowIncludeShape with a custom file path suffix for script separation
1033
+ */
1034
+ async function createScript(record, scriptContent, transform, suffix) {
1035
+ const baseName = await transform.getUpdateName(record);
1036
+ const content = scriptContent instanceof sdk_build_core_1.Shape ? scriptContent.toString().getValue() : scriptContent;
1037
+ return new now_include_plugin_1.NowIncludeShape({
1038
+ source: record,
1039
+ path: `./${baseName}-${suffix}.js`,
1040
+ includedText: content,
1041
+ });
1042
+ }
1043
+ /**
1044
+ * Default script
1045
+ */
1046
+ exports.defaultScript = `/** This script is executed before the Record is generated
1047
+ * \`current\`- GlideRecord produced by Record Producer
1048
+ * Don't use \`current.update()\` or \`current.insert()\` as the record is generated by Record Producer
1049
+ * Don't use \`current.setValue('sys_class_name', 'xxx')\` as this will trigger reparent flow and can cause data loss
1050
+ * Avoid \`current.setAbortAction()\` and generate a separate record
1051
+ * Use \`producer.var1\` to access variables
1052
+ */`;
1053
+ /**
1054
+ * Default post insert script
1055
+ */
1056
+ exports.defaultpostInsertScript = `/**
1057
+ * This script is executed after the record is generated.
1058
+ * \`current\` Is the GlideRecord produced by Record Producer. Use \`current.update()\` to update the record
1059
+ * To access the variables, use \`producer.var1\` where var1 is the name of the variable
1060
+ * To access the Record Producer use \`cat_item\`
1061
+ */`;
1062
+ /**
1063
+ * Default save script
1064
+ */
1065
+ exports.defaultSaveScript = `/**
1066
+ * This script is executed at every step save in Catalog Builder.
1067
+ * This script is executed before \`Script\` is executed.
1068
+ * \`current\` Is the GlideRecord produced by Record Producer.
1069
+ * To access the variables, use \`producer.var1\` where var1 is the name of the variable
1070
+ * To access the Record Producer use \`cat_item\`
1071
+ */`;
1072
+ /**
1073
+ * Validates that a variable belongs to a target record (variable set or catalog item)
1074
+ * Reports diagnostic error if validation fails
1075
+ * @param targetShape - The IdentifierShape for the target reference (variable set or catalog item)
1076
+ * @param parentRecord - The parent record where the variable is defined
1077
+ * @param appliesTo - Whether the validation is for 'set' (variable set) or 'item' (catalog item)
1078
+ * @param diagnostics - Optional diagnostics instance for reporting errors
1079
+ * @returns true if the variable belongs to the target, false otherwise
1080
+ */
1081
+ function validateVariableBelongsToTarget(targetShape, parentRecord, appliesTo, diagnostics) {
1082
+ const resolved = targetShape.resolve(true);
1083
+ if (!resolved?.isRecord()) {
1084
+ return false;
1085
+ }
1086
+ const targetRecord = resolved.asRecord();
1087
+ // Validate that parentRecord ID matches target record ID
1088
+ if (parentRecord.getId().getValue() === targetRecord.getId().getValue()) {
1089
+ return true;
1090
+ }
1091
+ if (appliesTo === 'item') {
1092
+ // Validate that variable is from variable set AND that variable set is added to the catalog item
1093
+ const isValid = targetRecord
1094
+ .flat()
1095
+ .some((r) => r.getTable() === 'io_set_item' &&
1096
+ r.get('sc_cat_item')?.asRecord()?.getId()?.getValue() === targetRecord.getId()?.getValue());
1097
+ if (!isValid && diagnostics) {
1098
+ diagnostics.error(targetShape.getOriginalNode(), 'Variable is not in the catalog item');
1099
+ }
1100
+ return isValid;
1101
+ }
1102
+ // For 'set' case
1103
+ if (diagnostics) {
1104
+ diagnostics.error(targetShape.getOriginalNode(), 'Variable is not in the variable set');
1105
+ }
1106
+ return false;
1107
+ }
1108
+ /**
1109
+ * Resolves a variable ID from variableNameShape and validates it belongs to the variable set if appliesTo is 'set'
1110
+ * @param variableNameShape - The shape from get('variableName', false)
1111
+ * @param appliesTo - The value from get('appliesTo')
1112
+ * @param variableSetShape - The shape from get('variableSet', false)
1113
+ * @param diagnostics - Diagnostics instance for reporting errors
1114
+ * @returns The resolved variable ID with IO: prefix, or undefined if resolution fails
1115
+ */
1116
+ function resolveAndValidateVariableId(variableNameShape, appliesTo, variableSetShape, catalogItemShape, diagnostics) {
1117
+ if (!variableNameShape) {
1118
+ return undefined;
1119
+ }
1120
+ let variableId;
1121
+ if (variableNameShape.is(sdk_build_core_1.PropertyAccessShape)) {
1122
+ const variableAccess = resolveVariableAccess(variableNameShape.as(sdk_build_core_1.PropertyAccessShape));
1123
+ if (variableAccess) {
1124
+ const { parentRecord, variableName } = variableAccess;
1125
+ variableId = resolveVariableId(parentRecord, variableName);
1126
+ // Validate variable belongs to target based on appliesTo (default to 'item')
1127
+ const appliesToValue = appliesTo === 'set' ? 'set' : 'item';
1128
+ const targetShape = appliesToValue === 'set' ? variableSetShape : catalogItemShape;
1129
+ if (targetShape?.is(sdk_build_core_1.IdentifierShape)) {
1130
+ validateVariableBelongsToTarget(targetShape.as(sdk_build_core_1.IdentifierShape), parentRecord, appliesToValue, diagnostics);
1131
+ }
1132
+ }
1133
+ else {
1134
+ // Fallback to string value if resolution fails
1135
+ variableId = `IO:${variableNameShape.toString()?.getValue()}`;
1136
+ }
1137
+ }
1138
+ else {
1139
+ // Handle non-PropertyAccessShape case
1140
+ variableId = `IO:${variableNameShape.toString()?.getValue()}`;
1141
+ }
1142
+ return variableId;
1143
+ }
1144
+ //# sourceMappingURL=utils.js.map