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