@servicenow/sdk-build-plugins 3.0.2 → 4.0.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 (359) hide show
  1. package/dist/acl-plugin.d.ts +19 -0
  2. package/dist/acl-plugin.js +210 -0
  3. package/dist/acl-plugin.js.map +1 -0
  4. package/dist/application-menu-plugin.d.ts +18 -0
  5. package/dist/application-menu-plugin.js +104 -0
  6. package/dist/application-menu-plugin.js.map +1 -0
  7. package/dist/arrow-function-plugin.d.ts +16 -0
  8. package/dist/arrow-function-plugin.js +107 -0
  9. package/dist/arrow-function-plugin.js.map +1 -0
  10. package/dist/atf/step-configs.d.ts +37 -0
  11. package/dist/atf/step-configs.js +2236 -0
  12. package/dist/atf/step-configs.js.map +1 -0
  13. package/dist/atf/test-plugin.d.ts +4 -0
  14. package/dist/atf/test-plugin.js +591 -0
  15. package/dist/atf/test-plugin.js.map +1 -0
  16. package/dist/basic-syntax-plugin.d.ts +2 -0
  17. package/dist/basic-syntax-plugin.js +636 -0
  18. package/dist/basic-syntax-plugin.js.map +1 -0
  19. package/dist/business-rule-plugin.d.ts +3 -0
  20. package/dist/business-rule-plugin.js +205 -0
  21. package/dist/business-rule-plugin.js.map +1 -0
  22. package/dist/call-expression-plugin.d.ts +2 -0
  23. package/dist/call-expression-plugin.js +175 -0
  24. package/dist/call-expression-plugin.js.map +1 -0
  25. package/dist/client-script-plugin.d.ts +29 -0
  26. package/dist/client-script-plugin.js +157 -0
  27. package/dist/client-script-plugin.js.map +1 -0
  28. package/dist/column/column-helper.d.ts +12 -0
  29. package/dist/column/column-helper.js +84 -0
  30. package/dist/column/column-helper.js.map +1 -0
  31. package/dist/column/column-to-record.d.ts +3 -0
  32. package/dist/column/column-to-record.js +105 -0
  33. package/dist/column/column-to-record.js.map +1 -0
  34. package/dist/column-plugin.d.ts +8 -0
  35. package/dist/column-plugin.js +453 -0
  36. package/dist/column-plugin.js.map +1 -0
  37. package/dist/cross-scope-privilege-plugin.d.ts +15 -0
  38. package/dist/cross-scope-privilege-plugin.js +82 -0
  39. package/dist/cross-scope-privilege-plugin.js.map +1 -0
  40. package/dist/html-import-plugin.d.ts +2 -0
  41. package/dist/html-import-plugin.js +72 -0
  42. package/dist/html-import-plugin.js.map +1 -0
  43. package/dist/index.d.ts +37 -21
  44. package/dist/index.js +40 -45
  45. package/dist/index.js.map +1 -1
  46. package/dist/json-plugin.d.ts +15 -0
  47. package/dist/json-plugin.js +104 -0
  48. package/dist/json-plugin.js.map +1 -0
  49. package/dist/list-plugin.d.ts +2 -0
  50. package/dist/list-plugin.js +191 -0
  51. package/dist/list-plugin.js.map +1 -0
  52. package/dist/now-config-plugin.d.ts +4 -0
  53. package/dist/now-config-plugin.js +154 -0
  54. package/dist/now-config-plugin.js.map +1 -0
  55. package/dist/now-id-plugin.d.ts +11 -0
  56. package/dist/now-id-plugin.js +71 -0
  57. package/dist/now-id-plugin.js.map +1 -0
  58. package/dist/now-include-plugin.d.ts +16 -0
  59. package/dist/now-include-plugin.js +118 -0
  60. package/dist/now-include-plugin.js.map +1 -0
  61. package/dist/now-ref-plugin.d.ts +2 -0
  62. package/dist/now-ref-plugin.js +43 -0
  63. package/dist/now-ref-plugin.js.map +1 -0
  64. package/dist/now-unresolved-plugin.d.ts +2 -0
  65. package/dist/now-unresolved-plugin.js +32 -0
  66. package/dist/now-unresolved-plugin.js.map +1 -0
  67. package/dist/package-json-plugin.d.ts +2 -0
  68. package/dist/package-json-plugin.js +70 -0
  69. package/dist/package-json-plugin.js.map +1 -0
  70. package/dist/property-plugin.d.ts +2 -0
  71. package/dist/property-plugin.js +105 -0
  72. package/dist/property-plugin.js.map +1 -0
  73. package/dist/record-plugin.d.ts +43 -0
  74. package/dist/record-plugin.js +147 -0
  75. package/dist/record-plugin.js.map +1 -0
  76. package/dist/repack/index.d.ts +1 -0
  77. package/dist/repack/index.js +10 -2
  78. package/dist/repack/index.js.map +1 -1
  79. package/dist/repack/lint/Rules.d.ts +1 -1
  80. package/dist/repack/lint/Rules.js +7 -3
  81. package/dist/repack/lint/Rules.js.map +1 -1
  82. package/dist/repack/lint/index.js +1 -1
  83. package/dist/rest-api-plugin.d.ts +2 -0
  84. package/dist/rest-api-plugin.js +469 -0
  85. package/dist/rest-api-plugin.js.map +1 -0
  86. package/dist/role-plugin.d.ts +2 -0
  87. package/dist/role-plugin.js +117 -0
  88. package/dist/role-plugin.js.map +1 -0
  89. package/dist/script-action-plugin.d.ts +2 -0
  90. package/dist/script-action-plugin.js +62 -0
  91. package/dist/script-action-plugin.js.map +1 -0
  92. package/dist/script-include-plugin.d.ts +2 -0
  93. package/dist/script-include-plugin.js +102 -0
  94. package/dist/script-include-plugin.js.map +1 -0
  95. package/dist/server-module-plugin/index.d.ts +14 -0
  96. package/dist/server-module-plugin/index.js +378 -0
  97. package/dist/server-module-plugin/index.js.map +1 -0
  98. package/dist/server-module-plugin/sbom-builder.d.ts +45 -0
  99. package/dist/server-module-plugin/sbom-builder.js +179 -0
  100. package/dist/server-module-plugin/sbom-builder.js.map +1 -0
  101. package/dist/service-portal/angular-provider-plugin.d.ts +2 -0
  102. package/dist/service-portal/angular-provider-plugin.js +78 -0
  103. package/dist/service-portal/angular-provider-plugin.js.map +1 -0
  104. package/dist/service-portal/dependency-plugin.d.ts +2 -0
  105. package/dist/service-portal/dependency-plugin.js +235 -0
  106. package/dist/service-portal/dependency-plugin.js.map +1 -0
  107. package/dist/service-portal/widget-plugin.d.ts +6 -0
  108. package/dist/service-portal/widget-plugin.js +230 -0
  109. package/dist/service-portal/widget-plugin.js.map +1 -0
  110. package/dist/static-content-plugin.d.ts +2 -0
  111. package/dist/static-content-plugin.js +272 -0
  112. package/dist/static-content-plugin.js.map +1 -0
  113. package/dist/table-plugin.d.ts +3 -0
  114. package/dist/table-plugin.js +1324 -0
  115. package/dist/table-plugin.js.map +1 -0
  116. package/dist/ui-action-plugin.d.ts +2 -0
  117. package/dist/ui-action-plugin.js +291 -0
  118. package/dist/ui-action-plugin.js.map +1 -0
  119. package/dist/ui-page-plugin.d.ts +2 -0
  120. package/dist/ui-page-plugin.js +165 -0
  121. package/dist/ui-page-plugin.js.map +1 -0
  122. package/dist/user-preference-plugin.d.ts +15 -0
  123. package/dist/user-preference-plugin.js +63 -0
  124. package/dist/user-preference-plugin.js.map +1 -0
  125. package/dist/utils.d.ts +17 -0
  126. package/dist/utils.js +72 -0
  127. package/dist/utils.js.map +1 -0
  128. package/dist/view-plugin.d.ts +2 -0
  129. package/dist/view-plugin.js +45 -0
  130. package/dist/view-plugin.js.map +1 -0
  131. package/package.json +17 -13
  132. package/src/acl-plugin.ts +256 -0
  133. package/src/application-menu-plugin.ts +109 -0
  134. package/src/arrow-function-plugin.ts +127 -0
  135. package/src/atf/step-configs.ts +2284 -0
  136. package/src/atf/test-plugin.ts +728 -0
  137. package/src/basic-syntax-plugin.ts +729 -0
  138. package/src/business-rule-plugin.ts +266 -0
  139. package/src/call-expression-plugin.ts +202 -0
  140. package/src/client-script-plugin.ts +170 -0
  141. package/src/column/column-helper.ts +119 -0
  142. package/src/column/column-to-record.ts +131 -0
  143. package/src/column-plugin.ts +506 -0
  144. package/src/cross-scope-privilege-plugin.ts +82 -0
  145. package/src/html-import-plugin.ts +79 -0
  146. package/src/index.ts +39 -21
  147. package/src/json-plugin.ts +128 -0
  148. package/src/list-plugin.ts +222 -0
  149. package/src/now-config-plugin.ts +194 -0
  150. package/src/now-id-plugin.ts +78 -0
  151. package/src/now-include-plugin.ts +140 -0
  152. package/src/now-ref-plugin.ts +48 -0
  153. package/src/now-unresolved-plugin.ts +30 -0
  154. package/src/package-json-plugin.ts +87 -0
  155. package/src/property-plugin.ts +118 -0
  156. package/src/record-plugin.ts +171 -0
  157. package/src/repack/index.ts +10 -1
  158. package/src/repack/lint/Rules.ts +5 -4
  159. package/src/repack/lint/index.ts +1 -1
  160. package/src/rest-api-plugin.ts +651 -0
  161. package/src/role-plugin.ts +128 -0
  162. package/src/script-action-plugin.ts +63 -0
  163. package/src/script-include-plugin.ts +110 -0
  164. package/src/server-module-plugin/index.ts +470 -0
  165. package/src/server-module-plugin/sbom-builder.ts +183 -0
  166. package/src/service-portal/angular-provider-plugin.ts +83 -0
  167. package/src/service-portal/dependency-plugin.ts +284 -0
  168. package/src/service-portal/widget-plugin.ts +263 -0
  169. package/src/static-content-plugin.ts +254 -0
  170. package/src/table-plugin.ts +1698 -0
  171. package/src/ui-action-plugin.ts +324 -0
  172. package/src/ui-page-plugin.ts +168 -0
  173. package/src/user-preference-plugin.ts +62 -0
  174. package/src/utils.ts +69 -0
  175. package/src/view-plugin.ts +46 -0
  176. package/dist/AttachmentPlugin.d.ts +0 -254
  177. package/dist/AttachmentPlugin.js +0 -220
  178. package/dist/AttachmentPlugin.js.map +0 -1
  179. package/dist/BusinessRulePlugin.d.ts +0 -30
  180. package/dist/BusinessRulePlugin.js +0 -149
  181. package/dist/BusinessRulePlugin.js.map +0 -1
  182. package/dist/CrossScopePrivilegePlugin.d.ts +0 -35
  183. package/dist/CrossScopePrivilegePlugin.js +0 -80
  184. package/dist/CrossScopePrivilegePlugin.js.map +0 -1
  185. package/dist/DefaultPlugin.d.ts +0 -86
  186. package/dist/DefaultPlugin.js +0 -226
  187. package/dist/DefaultPlugin.js.map +0 -1
  188. package/dist/HtmlTemplatePlugin.d.ts +0 -21
  189. package/dist/HtmlTemplatePlugin.js +0 -29
  190. package/dist/HtmlTemplatePlugin.js.map +0 -1
  191. package/dist/IdPlugin.d.ts +0 -28
  192. package/dist/IdPlugin.js +0 -68
  193. package/dist/IdPlugin.js.map +0 -1
  194. package/dist/IncludePlugin.d.ts +0 -34
  195. package/dist/IncludePlugin.js +0 -155
  196. package/dist/IncludePlugin.js.map +0 -1
  197. package/dist/JsonPlugin.d.ts +0 -28
  198. package/dist/JsonPlugin.js +0 -69
  199. package/dist/JsonPlugin.js.map +0 -1
  200. package/dist/ListPlugin.d.ts +0 -93
  201. package/dist/ListPlugin.js +0 -456
  202. package/dist/ListPlugin.js.map +0 -1
  203. package/dist/NowConfigPlugin.d.ts +0 -45
  204. package/dist/NowConfigPlugin.js +0 -64
  205. package/dist/NowConfigPlugin.js.map +0 -1
  206. package/dist/PackageJsonPlugin.d.ts +0 -34
  207. package/dist/PackageJsonPlugin.js +0 -63
  208. package/dist/PackageJsonPlugin.js.map +0 -1
  209. package/dist/PropertyPlugin.d.ts +0 -51
  210. package/dist/PropertyPlugin.js +0 -181
  211. package/dist/PropertyPlugin.js.map +0 -1
  212. package/dist/ScriptTemplatePlugin.d.ts +0 -13
  213. package/dist/ScriptTemplatePlugin.js +0 -55
  214. package/dist/ScriptTemplatePlugin.js.map +0 -1
  215. package/dist/ServerModulePlugin.d.ts +0 -75
  216. package/dist/ServerModulePlugin.js +0 -368
  217. package/dist/ServerModulePlugin.js.map +0 -1
  218. package/dist/UserPreferencePlugin.d.ts +0 -19
  219. package/dist/UserPreferencePlugin.js +0 -32
  220. package/dist/UserPreferencePlugin.js.map +0 -1
  221. package/dist/aclAndRole/AclPlugin.d.ts +0 -82
  222. package/dist/aclAndRole/AclPlugin.js +0 -262
  223. package/dist/aclAndRole/AclPlugin.js.map +0 -1
  224. package/dist/aclAndRole/RolePlugin.d.ts +0 -66
  225. package/dist/aclAndRole/RolePlugin.js +0 -179
  226. package/dist/aclAndRole/RolePlugin.js.map +0 -1
  227. package/dist/aclAndRole/Util.d.ts +0 -3
  228. package/dist/aclAndRole/Util.js +0 -90
  229. package/dist/aclAndRole/Util.js.map +0 -1
  230. package/dist/app/ApplicationMenuPlugin.d.ts +0 -34
  231. package/dist/app/ApplicationMenuPlugin.js +0 -112
  232. package/dist/app/ApplicationMenuPlugin.js.map +0 -1
  233. package/dist/db/ColumnPlugins.d.ts +0 -750
  234. package/dist/db/ColumnPlugins.js +0 -114
  235. package/dist/db/ColumnPlugins.js.map +0 -1
  236. package/dist/db/DBUtils.d.ts +0 -2
  237. package/dist/db/DBUtils.js +0 -27
  238. package/dist/db/DBUtils.js.map +0 -1
  239. package/dist/db/DocumentationPlugin.d.ts +0 -67
  240. package/dist/db/DocumentationPlugin.js +0 -258
  241. package/dist/db/DocumentationPlugin.js.map +0 -1
  242. package/dist/db/LicensingPlugin.d.ts +0 -60
  243. package/dist/db/LicensingPlugin.js +0 -117
  244. package/dist/db/LicensingPlugin.js.map +0 -1
  245. package/dist/db/RecordPlugin.d.ts +0 -133
  246. package/dist/db/RecordPlugin.js +0 -337
  247. package/dist/db/RecordPlugin.js.map +0 -1
  248. package/dist/db/TablePlugin.d.ts +0 -231
  249. package/dist/db/TablePlugin.js +0 -1628
  250. package/dist/db/TablePlugin.js.map +0 -1
  251. package/dist/db/index.d.ts +0 -6
  252. package/dist/db/index.js +0 -32
  253. package/dist/db/index.js.map +0 -1
  254. package/dist/scriptedRESTAPI/RESTDeserializationUtils.d.ts +0 -10
  255. package/dist/scriptedRESTAPI/RESTDeserializationUtils.js +0 -373
  256. package/dist/scriptedRESTAPI/RESTDeserializationUtils.js.map +0 -1
  257. package/dist/scriptedRESTAPI/RESTSerializationUtils.d.ts +0 -13
  258. package/dist/scriptedRESTAPI/RESTSerializationUtils.js +0 -177
  259. package/dist/scriptedRESTAPI/RESTSerializationUtils.js.map +0 -1
  260. package/dist/scriptedRESTAPI/RestApiPlugin.d.ts +0 -81
  261. package/dist/scriptedRESTAPI/RestApiPlugin.js +0 -345
  262. package/dist/scriptedRESTAPI/RestApiPlugin.js.map +0 -1
  263. package/dist/scriptedRESTAPI/RestSchemaUtils.d.ts +0 -190
  264. package/dist/scriptedRESTAPI/RestSchemaUtils.js +0 -53
  265. package/dist/scriptedRESTAPI/RestSchemaUtils.js.map +0 -1
  266. package/dist/scriptedRESTAPI/RestUtils.d.ts +0 -69
  267. package/dist/scriptedRESTAPI/RestUtils.js +0 -497
  268. package/dist/scriptedRESTAPI/RestUtils.js.map +0 -1
  269. package/dist/scripts/ClientScriptPlugin.d.ts +0 -64
  270. package/dist/scripts/ClientScriptPlugin.js +0 -170
  271. package/dist/scripts/ClientScriptPlugin.js.map +0 -1
  272. package/dist/scripts/scriptUtils.d.ts +0 -1
  273. package/dist/scripts/scriptUtils.js +0 -9
  274. package/dist/scripts/scriptUtils.js.map +0 -1
  275. package/dist/uxf/ExperiencePlugin.d.ts +0 -45
  276. package/dist/uxf/ExperiencePlugin.js +0 -61
  277. package/dist/uxf/ExperiencePlugin.js.map +0 -1
  278. package/dist/uxf/RoutesPlugin.d.ts +0 -29
  279. package/dist/uxf/RoutesPlugin.js +0 -181
  280. package/dist/uxf/RoutesPlugin.js.map +0 -1
  281. package/dist/uxf/UxfFormulaParser/cleanUxValue.d.ts +0 -4
  282. package/dist/uxf/UxfFormulaParser/cleanUxValue.js +0 -65
  283. package/dist/uxf/UxfFormulaParser/cleanUxValue.js.map +0 -1
  284. package/dist/uxf/UxfFormulaParser/grammerParser/api.d.ts +0 -189
  285. package/dist/uxf/UxfFormulaParser/grammerParser/api.js +0 -158
  286. package/dist/uxf/UxfFormulaParser/grammerParser/api.js.map +0 -1
  287. package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.d.ts +0 -13
  288. package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js +0 -604
  289. package/dist/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js.map +0 -1
  290. package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.d.ts +0 -12
  291. package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.js +0 -551
  292. package/dist/uxf/UxfFormulaParser/grammerParser/grammarParser.js.map +0 -1
  293. package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.d.ts +0 -31
  294. package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.js +0 -64
  295. package/dist/uxf/UxfFormulaParser/grammerParser/spanHelpers.js.map +0 -1
  296. package/dist/uxf/UxfFormulaParser/index.d.ts +0 -3
  297. package/dist/uxf/UxfFormulaParser/index.js +0 -11
  298. package/dist/uxf/UxfFormulaParser/index.js.map +0 -1
  299. package/dist/uxf/UxfFormulaParser/parser.d.ts +0 -8
  300. package/dist/uxf/UxfFormulaParser/parser.js +0 -87
  301. package/dist/uxf/UxfFormulaParser/parser.js.map +0 -1
  302. package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.d.ts +0 -8
  303. package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.js +0 -17
  304. package/dist/uxf/UxfFormulaParser/utils/getErrorMsg.js.map +0 -1
  305. package/dist/uxf/constants.d.ts +0 -2
  306. package/dist/uxf/constants.js +0 -8
  307. package/dist/uxf/constants.js.map +0 -1
  308. package/dist/uxf/index.d.ts +0 -2
  309. package/dist/uxf/index.js +0 -11
  310. package/dist/uxf/index.js.map +0 -1
  311. package/dist/uxf/tectonicIdGenerator.d.ts +0 -12
  312. package/dist/uxf/tectonicIdGenerator.js +0 -79
  313. package/dist/uxf/tectonicIdGenerator.js.map +0 -1
  314. package/src/AttachmentPlugin.ts +0 -268
  315. package/src/BusinessRulePlugin.ts +0 -238
  316. package/src/CrossScopePrivilegePlugin.ts +0 -115
  317. package/src/DefaultPlugin.ts +0 -288
  318. package/src/HtmlTemplatePlugin.ts +0 -31
  319. package/src/IdPlugin.ts +0 -74
  320. package/src/IncludePlugin.ts +0 -206
  321. package/src/JsonPlugin.ts +0 -76
  322. package/src/ListPlugin.ts +0 -570
  323. package/src/NowConfigPlugin.ts +0 -69
  324. package/src/PackageJsonPlugin.ts +0 -68
  325. package/src/PropertyPlugin.ts +0 -237
  326. package/src/ScriptTemplatePlugin.ts +0 -53
  327. package/src/ServerModulePlugin.ts +0 -480
  328. package/src/UserPreferencePlugin.ts +0 -45
  329. package/src/aclAndRole/AclPlugin.ts +0 -420
  330. package/src/aclAndRole/RolePlugin.ts +0 -254
  331. package/src/aclAndRole/Util.ts +0 -113
  332. package/src/app/ApplicationMenuPlugin.ts +0 -165
  333. package/src/db/ColumnPlugins.ts +0 -114
  334. package/src/db/DBUtils.ts +0 -36
  335. package/src/db/DocumentationPlugin.ts +0 -316
  336. package/src/db/LicensingPlugin.ts +0 -138
  337. package/src/db/RecordPlugin.ts +0 -459
  338. package/src/db/TablePlugin.ts +0 -2070
  339. package/src/db/index.ts +0 -6
  340. package/src/scriptedRESTAPI/RESTDeserializationUtils.ts +0 -419
  341. package/src/scriptedRESTAPI/RESTSerializationUtils.ts +0 -228
  342. package/src/scriptedRESTAPI/RestApiPlugin.ts +0 -469
  343. package/src/scriptedRESTAPI/RestSchemaUtils.ts +0 -72
  344. package/src/scriptedRESTAPI/RestUtils.ts +0 -569
  345. package/src/scripts/ClientScriptPlugin.ts +0 -257
  346. package/src/scripts/scriptUtils.ts +0 -5
  347. package/src/uxf/ExperiencePlugin.ts +0 -67
  348. package/src/uxf/RoutesPlugin.ts +0 -211
  349. package/src/uxf/UxfFormulaParser/cleanUxValue.ts +0 -73
  350. package/src/uxf/UxfFormulaParser/grammerParser/api.js +0 -166
  351. package/src/uxf/UxfFormulaParser/grammerParser/clientTransformMap.js +0 -606
  352. package/src/uxf/UxfFormulaParser/grammerParser/grammarParser.js +0 -551
  353. package/src/uxf/UxfFormulaParser/grammerParser/spanHelpers.js +0 -65
  354. package/src/uxf/UxfFormulaParser/index.ts +0 -4
  355. package/src/uxf/UxfFormulaParser/parser.ts +0 -64
  356. package/src/uxf/UxfFormulaParser/utils/getErrorMsg.ts +0 -13
  357. package/src/uxf/constants.ts +0 -4
  358. package/src/uxf/index.ts +0 -2
  359. package/src/uxf/tectonicIdGenerator.ts +0 -78
@@ -0,0 +1,15 @@
1
+ import { Plugin } from '@servicenow/sdk-build-core';
2
+ /**
3
+ * Creates a User Preference (sys_user_preference).
4
+ *
5
+ * @see https://docs.servicenow.com/csh?topicname=c_UserPreferences.html&version=latest
6
+ *
7
+ * @param config - an object containing the following properties:
8
+ * * **$id** - unique id for the record, typically using `Now.ID["value"]`
9
+ * * **name** - name of the feature or functionality
10
+ * * **type** - the data type of entry accepted for the `value`
11
+ * * **value** - current setting for this record
12
+ * * **description**? - short description of the feature or functionality
13
+ * * **system**? - whether this record indicates the system-wide default
14
+ */
15
+ export declare const UserPreferencePlugin: Plugin;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserPreferencePlugin = void 0;
4
+ const sdk_build_core_1 = require("@servicenow/sdk-build-core");
5
+ const now_id_plugin_1 = require("./now-id-plugin");
6
+ /**
7
+ * Creates a User Preference (sys_user_preference).
8
+ *
9
+ * @see https://docs.servicenow.com/csh?topicname=c_UserPreferences.html&version=latest
10
+ *
11
+ * @param config - an object containing the following properties:
12
+ * * **$id** - unique id for the record, typically using `Now.ID["value"]`
13
+ * * **name** - name of the feature or functionality
14
+ * * **type** - the data type of entry accepted for the `value`
15
+ * * **value** - current setting for this record
16
+ * * **description**? - short description of the feature or functionality
17
+ * * **system**? - whether this record indicates the system-wide default
18
+ */
19
+ exports.UserPreferencePlugin = sdk_build_core_1.Plugin.create({
20
+ name: 'UserPreferencePlugin',
21
+ records: {
22
+ sys_user_preference: {
23
+ toShape(record) {
24
+ return {
25
+ success: true,
26
+ value: new sdk_build_core_1.CallExpressionShape({
27
+ source: record,
28
+ callee: 'UserPreference',
29
+ args: [
30
+ record.transform(({ $, merge }) => ({
31
+ $id: $.val(now_id_plugin_1.NowIdShape.from(record)),
32
+ system: $.from('system').toBoolean(),
33
+ [merge]: $,
34
+ })),
35
+ ],
36
+ }),
37
+ };
38
+ },
39
+ },
40
+ },
41
+ shapes: [
42
+ {
43
+ shape: sdk_build_core_1.CallExpressionShape,
44
+ fileTypes: ['fluent'],
45
+ toRecord(callExpression, { factory }) {
46
+ if (callExpression.getCallee() !== 'UserPreference') {
47
+ return { success: false };
48
+ }
49
+ const pref = callExpression.getArgument(0).asObject();
50
+ return {
51
+ success: true,
52
+ value: factory.createRecord({
53
+ source: callExpression,
54
+ table: 'sys_user_preference',
55
+ explicitId: pref.get('$id'),
56
+ properties: pref.pick(['name', 'type', 'value', 'description', 'system']),
57
+ }),
58
+ };
59
+ },
60
+ },
61
+ ],
62
+ });
63
+ //# sourceMappingURL=user-preference-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-preference-plugin.js","sourceRoot":"","sources":["../src/user-preference-plugin.ts"],"names":[],"mappings":";;;AAAA,+DAAwE;AACxE,mDAA4C;AAE5C;;;;;;;;;;;;GAYG;AACU,QAAA,oBAAoB,GAAG,uBAAM,CAAC,MAAM,CAAC;IAC9C,IAAI,EAAE,sBAAsB;IAC5B,OAAO,EAAE;QACL,mBAAmB,EAAE;YACjB,OAAO,CAAC,MAAM;gBACV,OAAO;oBACH,OAAO,EAAE,IAAI;oBACb,KAAK,EAAE,IAAI,oCAAmB,CAAC;wBAC3B,MAAM,EAAE,MAAM;wBACd,MAAM,EAAE,gBAAgB;wBACxB,IAAI,EAAE;4BACF,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;gCAChC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,0BAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gCACnC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,SAAS,EAAE;gCACpC,CAAC,KAAK,CAAC,EAAE,CAAC;6BACb,CAAC,CAAC;yBACN;qBACJ,CAAC;iBACL,CAAA;YACL,CAAC;SACJ;KACJ;IACD,MAAM,EAAE;QACJ;YACI,KAAK,EAAE,oCAAmB;YAC1B,SAAS,EAAE,CAAC,QAAQ,CAAC;YACrB,QAAQ,CAAC,cAAc,EAAE,EAAE,OAAO,EAAE;gBAChC,IAAI,cAAc,CAAC,SAAS,EAAE,KAAK,gBAAgB,EAAE,CAAC;oBAClD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;gBAC7B,CAAC;gBAED,MAAM,IAAI,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;gBAErD,OAAO;oBACH,OAAO,EAAE,IAAI;oBACb,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC;wBACxB,MAAM,EAAE,cAAc;wBACtB,KAAK,EAAE,qBAAqB;wBAC5B,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;wBAC3B,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;qBAC5E,CAAC;iBACL,CAAA;YACL,CAAC;SACJ;KACJ;CACJ,CAAC,CAAA"}
@@ -0,0 +1,17 @@
1
+ import { ts, type Shape, type ObjectShape, type Diagnostics } from '@servicenow/sdk-build-core';
2
+ export declare function toReference(shape: Shape): string | import("@servicenow/sdk-build-core").RecordId;
3
+ /**
4
+ * Reverses an object, swapping keys and values. **reverseObject** should only be used
5
+ * where the key/values are all known ahead of time and the values are unique.
6
+ * @example
7
+ * reverseObject({ a: 'foo', b: 'bar' }) // { foo: 'a', bar: 'b' }
8
+ */
9
+ export declare function reverseObject<K extends string, V extends string>(obj: Record<K, V>): Record<V, K>;
10
+ export declare function noThrow<T>(action: () => T): T | Error;
11
+ /**
12
+ * Regex taken from: https://github.com/oozcitak/xmlbuilder-js/blob/b20136cd1591d0f17ab2f184053c7150150428b2/src/XMLStringifier.coffee#L119C15-L119C127
13
+ */
14
+ export declare const INVALID_XML_CHARACTERS: RegExp;
15
+ export declare function applyPathMappings(path: string, mappings: Record<string, string>): string;
16
+ export declare function getCallExpressionName(node: ts.CallExpression): string;
17
+ export declare function generateDeprecatedDiagnostics(object: ObjectShape, diagnostics: Diagnostics): void;
package/dist/utils.js ADDED
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.INVALID_XML_CHARACTERS = void 0;
4
+ exports.toReference = toReference;
5
+ exports.reverseObject = reverseObject;
6
+ exports.noThrow = noThrow;
7
+ exports.applyPathMappings = applyPathMappings;
8
+ exports.getCallExpressionName = getCallExpressionName;
9
+ exports.generateDeprecatedDiagnostics = generateDeprecatedDiagnostics;
10
+ const sdk_build_core_1 = require("@servicenow/sdk-build-core");
11
+ function toReference(shape) {
12
+ return shape.ifRecord()?.getId() ?? shape.ifString()?.getValue() ?? '';
13
+ }
14
+ /**
15
+ * Reverses an object, swapping keys and values. **reverseObject** should only be used
16
+ * where the key/values are all known ahead of time and the values are unique.
17
+ * @example
18
+ * reverseObject({ a: 'foo', b: 'bar' }) // { foo: 'a', bar: 'b' }
19
+ */
20
+ function reverseObject(obj) {
21
+ const reversed = {};
22
+ for (const key in obj) {
23
+ const value = obj[key];
24
+ if (typeof value === 'string') {
25
+ reversed[value] = key;
26
+ }
27
+ }
28
+ return reversed;
29
+ }
30
+ function noThrow(action) {
31
+ try {
32
+ return action();
33
+ }
34
+ catch (error) {
35
+ return error;
36
+ }
37
+ }
38
+ /**
39
+ * Regex taken from: https://github.com/oozcitak/xmlbuilder-js/blob/b20136cd1591d0f17ab2f184053c7150150428b2/src/XMLStringifier.coffee#L119C15-L119C127
40
+ */
41
+ exports.INVALID_XML_CHARACTERS =
42
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: This is intentional
43
+ /[\0-\x08\x0B\f\x0E-\x1F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g;
44
+ function applyPathMappings(path, mappings) {
45
+ if (!mappings) {
46
+ return path;
47
+ }
48
+ // TODO: Naive implementation for now that just supports simple patterns. We can explore supporting more complex patterns later.
49
+ for (const [source, target] of Object.entries(mappings)) {
50
+ const match = path.match(`${source.replace(/\./, '\\.').replace(/\*+/, '(.*)')}$`)?.[1];
51
+ if (match !== undefined) {
52
+ return target.replace(/\*+/, match);
53
+ }
54
+ }
55
+ return path;
56
+ }
57
+ function getCallExpressionName(node) {
58
+ const expression = node.getExpression();
59
+ if (sdk_build_core_1.ts.Node.isIdentifier(expression) || sdk_build_core_1.ts.Node.isPropertyAccessExpression(expression)) {
60
+ return expression.getText();
61
+ }
62
+ throw `CallExpression does not have a name: ${expression.getText()}`;
63
+ }
64
+ function generateDeprecatedDiagnostics(object, diagnostics) {
65
+ Object.keys(object.getAliasedKeys()).forEach((key) => {
66
+ const alias = object.findAliasUsed(key);
67
+ if (alias) {
68
+ diagnostics.hint(object.get(key), `The property '${alias}' is deprecated, use '${key}' instead.`);
69
+ }
70
+ });
71
+ }
72
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAEA,kCAEC;AAQD,sCASC;AAED,0BAMC;AASD,8CAYC;AAED,sDAOC;AAED,sEAOC;AApED,+DAA+F;AAE/F,SAAgB,WAAW,CAAC,KAAY;IACpC,OAAO,KAAK,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;AAC1E,CAAC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAAqC,GAAiB;IAC/E,MAAM,QAAQ,GAAG,EAAkB,CAAA;IACnC,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAA;QACtB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,CAAA;QACzB,CAAC;IACL,CAAC;IACD,OAAO,QAAQ,CAAA;AACnB,CAAC;AAED,SAAgB,OAAO,CAAI,MAAe;IACtC,IAAI,CAAC;QACD,OAAO,MAAM,EAAE,CAAA;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,KAAc,CAAA;IACzB,CAAC;AACL,CAAC;AAED;;GAEG;AACU,QAAA,sBAAsB;AAC/B,+EAA+E;AAC/E,gHAAgH,CAAA;AAEpH,SAAgB,iBAAiB,CAAC,IAAY,EAAE,QAAgC;IAC5E,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,OAAO,IAAI,CAAA;IACf,CAAC;IACD,gIAAgI;IAChI,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QACvF,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACtB,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QACvC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAA;AACf,CAAC;AAED,SAAgB,qBAAqB,CAAC,IAAuB;IACzD,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAA;IACvC,IAAI,mBAAE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,mBAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,UAAU,CAAC,EAAE,CAAC;QACrF,OAAO,UAAU,CAAC,OAAO,EAAE,CAAA;IAC/B,CAAC;IAED,MAAM,wCAAwC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAA;AACxE,CAAC;AAED,SAAgB,6BAA6B,CAAC,MAAmB,EAAE,WAAwB;IACvF,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACjD,MAAM,KAAK,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;QACvC,IAAI,KAAK,EAAE,CAAC;YACR,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,iBAAiB,KAAK,yBAAyB,GAAG,YAAY,CAAC,CAAA;QACrG,CAAC;IACL,CAAC,CAAC,CAAA;AACN,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Plugin } from '@servicenow/sdk-build-core';
2
+ export declare const ViewPlugin: Plugin;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ViewPlugin = void 0;
4
+ const sdk_build_core_1 = require("@servicenow/sdk-build-core");
5
+ exports.ViewPlugin = sdk_build_core_1.Plugin.create({
6
+ name: 'ViewPlugin',
7
+ records: {
8
+ sys_ui_view: {
9
+ coalesce: ['name'],
10
+ },
11
+ },
12
+ shapes: [
13
+ {
14
+ shape: sdk_build_core_1.Record,
15
+ inspect(record, { diagnostics }) {
16
+ if (record.getTable() !== 'sys_ui_view') {
17
+ return;
18
+ }
19
+ if (record.get('title').equals('Default view')) {
20
+ // The default view's name will be empty, so skip the validation
21
+ return;
22
+ }
23
+ const viewName = record.get('name');
24
+ if (!viewName.isString() || !/^[a-zA-Z0-9_]+$/.test(viewName.getValue())) {
25
+ diagnostics.error(viewName.getOriginalNode(), `View name can only contain alphanumeric characters`);
26
+ }
27
+ },
28
+ },
29
+ {
30
+ shape: sdk_build_core_1.RecordId,
31
+ async commit(id, target, { commit }) {
32
+ if (id.getTable() !== 'sys_ui_view') {
33
+ return { success: false };
34
+ }
35
+ const viewName = id.getKey('name');
36
+ if (!viewName) {
37
+ return { success: false };
38
+ }
39
+ await commit(sdk_build_core_1.Shape.from(id, viewName).asString(), target);
40
+ return { success: true };
41
+ },
42
+ },
43
+ ],
44
+ });
45
+ //# sourceMappingURL=view-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view-plugin.js","sourceRoot":"","sources":["../src/view-plugin.ts"],"names":[],"mappings":";;;AAAA,+DAA4E;AAE/D,QAAA,UAAU,GAAG,uBAAM,CAAC,MAAM,CAAC;IACpC,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE;QACL,WAAW,EAAE;YACT,QAAQ,EAAE,CAAC,MAAM,CAAC;SACrB;KACJ;IACD,MAAM,EAAE;QACJ;YACI,KAAK,EAAE,uBAAM;YACb,OAAO,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE;gBAC3B,IAAI,MAAM,CAAC,QAAQ,EAAE,KAAK,aAAa,EAAE,CAAC;oBACtC,OAAM;gBACV,CAAC;gBAED,IAAI,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC;oBAC7C,gEAAgE;oBAChE,OAAM;gBACV,CAAC;gBAED,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;gBACnC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;oBACvE,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,eAAe,EAAE,EAAE,oDAAoD,CAAC,CAAA;gBACvG,CAAC;YACL,CAAC;SACJ;QACD;YACI,KAAK,EAAE,yBAAQ;YACf,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE;gBAC/B,IAAI,EAAE,CAAC,QAAQ,EAAE,KAAK,aAAa,EAAE,CAAC;oBAClC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;gBAC7B,CAAC;gBAED,MAAM,QAAQ,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;gBAClC,IAAI,CAAC,QAAQ,EAAE,CAAC;oBACZ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;gBAC7B,CAAC;gBAED,MAAM,MAAM,CAAC,sBAAK,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,CAAA;gBACzD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;YAC5B,CAAC;SACJ;KACJ;CACJ,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicenow/sdk-build-plugins",
3
- "version": "3.0.2",
3
+ "version": "4.0.0",
4
4
  "description": "ServiceNow SDK Build System Plugins",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
@@ -8,41 +8,45 @@
8
8
  "dist",
9
9
  "src"
10
10
  ],
11
+ "exports": {
12
+ ".": "./dist/index.js"
13
+ },
11
14
  "dependencies": {
15
+ "@cyclonedx/cyclonedx-library": "7.1.0",
12
16
  "@servicenow/glide": "26.0.1",
13
17
  "eslint": "8.50.0",
14
18
  "eslint-formatter-stylish": "8.40.0",
15
19
  "eslint-plugin-es-x": "7.2.0",
20
+ "fast-xml-parser": "4.4.1",
16
21
  "globals": "13.23.0",
17
22
  "lodash": "4.17.21",
23
+ "md5.js": "1.3.5",
24
+ "mime-types": "2.1.35",
18
25
  "moo": "0.5.2",
19
26
  "nearley": "2.20.1",
27
+ "packageurl-js": "2.0.1",
20
28
  "xmlbuilder2": "3.1.1",
21
29
  "zod": "3.22.4",
22
- "md5.js": "1.3.5",
23
- "@servicenow/eslint-plugin-sdk-app-plugin": "3.0.2",
24
- "@servicenow/sdk-core": "3.0.2",
25
- "@servicenow/sdk-build-core": "3.0.2",
26
- "@servicenow/sdk-project": "3.0.2",
27
- "@servicenow/sdk-repack": "3.0.2"
30
+ "@servicenow/sdk-build-core": "4.0.0",
31
+ "@servicenow/sdk-repack": "4.0.0",
32
+ "@servicenow/eslint-plugin-sdk-app-plugin": "4.0.0",
33
+ "@servicenow/sdk-core": "4.0.0"
28
34
  },
29
35
  "overrides": {
30
36
  "micromatch": "4.0.7"
31
37
  },
32
38
  "devDependencies": {
33
39
  "@types/eslint": "8.56.0",
34
- "@types/lodash": "4.14.195"
40
+ "@types/lodash": "4.14.195",
41
+ "@types/mime-types": "2.1.4"
35
42
  },
36
43
  "engines": {
37
- "node": ">=18.16.1",
38
- "pnpm": ">=9.4.0"
44
+ "node": ">=20.18.0",
45
+ "pnpm": ">=10.8.0"
39
46
  },
40
47
  "scripts": {
41
48
  "build": "tsc -b",
42
49
  "clean": "tsc -b --clean",
43
- "lint": "eslint . --ext .ts",
44
- "prettier:check": "prettier --check --ignore-path=../../.prettierignore .",
45
- "prettier:write": "prettier --write --ignore-path=../../.prettierignore .",
46
50
  "watch": "tsc -b -w"
47
51
  }
48
52
  }
@@ -0,0 +1,256 @@
1
+ import { CallExpressionShape, isGUID, Plugin } from '@servicenow/sdk-build-core'
2
+ import { AclTypes, AclOperations, AclAttributes, AclNamedTypes } from '@servicenow/sdk-core/runtime/app'
3
+ import { ModuleFunctionShape } from './server-module-plugin'
4
+ import { NowIdShape } from './now-id-plugin'
5
+ import { generateDeprecatedDiagnostics } from './utils'
6
+
7
+ const ExecuteOnlyTypes = new Set([
8
+ 'client_callable_flow_object',
9
+ 'client_callable_script_include',
10
+ 'graphql',
11
+ 'processor',
12
+ 'rest_endpoint',
13
+ ])
14
+
15
+ const aclAliases = {
16
+ adminOverrides: ['admin_overrides'],
17
+ decisionType: ['decision_type'],
18
+ localOrExisting: ['local_or_existing'],
19
+ securityAttribute: ['security_attribute'],
20
+ appliesTo: ['applies_to'],
21
+ }
22
+
23
+ /**
24
+ * @param config - an object containing the following properties:
25
+ * * **$id** - unique id for the record, typically using `Now.ID["value"]`
26
+ * * **operation** - the operation this ACL rule secure
27
+ * * **active**? - whether the ACL is enabled
28
+ * * **adminOverrides**? - indicates whether users with the admin role automatically pass the permissions check for this ACL rule
29
+ * * **condition**? - a filter query that specifies the fields and values that must be true for users to access the object
30
+ * * **decisionType**? - whether the ACL should allow or deny access
31
+ * * **description**? - description of the object or permissions this ACL rule secures
32
+ * * **localOrExisting**? - if `"Local"`: A security attribute based on the
33
+ * condition property that is saved only for the ACL it is created in\
34
+ * if `"Exisiting"`: An existing security attribute to reference in the `security_attribute` property
35
+ * * **roles**? - `Role` objects or sys_ids of roles that a user must have to access the object
36
+ * * **script**? - a function or inline script preceded by a `script` tagged
37
+ * template literal. The script should define the permissions required to access the object
38
+ * * **securityAttribute**? - pre-defined conditions to use. For example, whether a user is impersonating another user
39
+ */
40
+ export const AclPlugin = Plugin.create({
41
+ name: 'AclPlugin',
42
+ records: {
43
+ sys_security_acl: {
44
+ relationships: {
45
+ sys_security_acl_role: {
46
+ via: 'sys_security_acl',
47
+ descendant: true,
48
+ relationships: {
49
+ sys_user_role: {
50
+ via: 'sys_user_role',
51
+ inverse: true,
52
+ },
53
+ },
54
+ },
55
+ },
56
+ toShape(record, { descendants }) {
57
+ const type = reverseLookup(AclTypes, record.get('type').getValue()) || record.get('type')
58
+ const roles = descendants.query('sys_security_acl_role').map((m2m) => m2m.get('sys_user_role'))
59
+
60
+ return {
61
+ success: true,
62
+ value: new CallExpressionShape({
63
+ source: record,
64
+ callee: 'Acl',
65
+ args: [
66
+ record
67
+ .transform(({ $, merge }) => ({
68
+ $id: $.val(NowIdShape.from(record)),
69
+ condition: $.def(''),
70
+ description: $.def(''),
71
+ localOrExisting: $.from('local_or_existing').def('Local'),
72
+ active: $.toBoolean().def(true),
73
+ decisionType: $.from('decision_type').def('allow'),
74
+ adminOverrides: $.from('admin_overrides').toBoolean().def(true),
75
+ appliesTo: $.from('applies_to').def(''),
76
+ type: $.val(type),
77
+ securityAttribute: $.from('security_attribute')
78
+ .map((v) => reverseLookup(AclAttributes, v.getValue()) || v)
79
+ .def(''),
80
+ operation: $.map((v) => reverseLookup(AclOperations, v.getValue()) || v),
81
+ script: $.map((v) => v.ifString()?.getValue()).def(''),
82
+ roles: $.val(roles.length > 0 ? roles : undefined),
83
+ [merge]: $.from('type', 'name').map((type, name) =>
84
+ getTableOrName(
85
+ type.pipe((t) => reverseLookup(AclTypes, t.getValue())),
86
+ name.asString().getValue()
87
+ )
88
+ ),
89
+ }))
90
+ .withAliasedKeys(aclAliases),
91
+ ],
92
+ }),
93
+ }
94
+ },
95
+ },
96
+ sys_security_acl_role: {
97
+ coalesce: ['sys_security_acl', 'sys_user_role'],
98
+ },
99
+ },
100
+ shapes: [
101
+ {
102
+ shape: CallExpressionShape,
103
+ fileTypes: ['fluent'],
104
+ async toRecord(callExpression, { config, diagnostics, factory }) {
105
+ if (callExpression.getCallee() !== 'Acl') {
106
+ return { success: false }
107
+ }
108
+
109
+ const arg = callExpression.getArgument(0).asObject().withAliasedKeys(aclAliases)
110
+ generateDeprecatedDiagnostics(arg, diagnostics)
111
+ const operation = arg.get('operation')
112
+ const type = arg.get('type').asString()
113
+ if (!operation.equals('execute') && ExecuteOnlyTypes.has(type.getValue())) {
114
+ diagnostics.error(
115
+ operation,
116
+ `ACL must use operation 'execute', because it is of type '${type.getValue()}'`
117
+ )
118
+ }
119
+
120
+ const script = arg.get('script')
121
+ const advanced = !script.isUndefined()
122
+ if (advanced && type.equals('graphql')) {
123
+ diagnostics.error(script, `ACL does not support scripts, because it is of type graphql`)
124
+ }
125
+
126
+ const appliesTo = arg.get('appliesTo').ifString()
127
+ if (appliesTo && !type.equals('record')) {
128
+ diagnostics.error(appliesTo, `ACL cannot set applies_to unless its type is 'record'`)
129
+ }
130
+
131
+ if (operation.equals('add_to_list')) {
132
+ const condition = arg.get('condition').ifString()
133
+ if (advanced) {
134
+ diagnostics.error(script, `ACL cannot have a script due to its 'add_to_list' operation`)
135
+ } else if (condition) {
136
+ diagnostics.error(condition, `ACL cannot have a condition due to its 'add_to_list' operation`)
137
+ }
138
+ }
139
+
140
+ if (arg.get('script').isUnresolved()) {
141
+ diagnostics.error(
142
+ arg.get('script').getOriginalNode(),
143
+ `Unable to resolve the script reference, ensure the imported module is within the ${config.serverModulesDir} directory.`
144
+ )
145
+ }
146
+
147
+ const acl = factory.createRecord({
148
+ source: callExpression,
149
+ table: 'sys_security_acl',
150
+ explicitId: arg.get('$id'),
151
+ properties: arg.transform(({ $ }) => ({
152
+ active: $.def(true),
153
+ decision_type: $.from('decisionType').def('allow'),
154
+ description: $.def(''),
155
+ local_or_existing: $.from('localOrExisting').def('Local'),
156
+ admin_overrides: $.from('adminOverrides').def(true),
157
+ condition: $.def(''),
158
+ applies_to: $.from('appliesTo').def(''),
159
+ name: $.from('name', 'table', 'field').map(
160
+ (n, t, f) => n.ifString() ?? (f.ifString() ? `${t.getValue()}.${f.getValue()}` : t)
161
+ ),
162
+ type: $.map((type) => AclTypes[type.asString().getValue()] ?? type),
163
+ operation: $.map((op) => AclOperations[op.asString().getValue()] ?? op),
164
+ advanced: $.val(advanced),
165
+ script: $.map(
166
+ (v) =>
167
+ v.if(ModuleFunctionShape)?.toString((n) => `answer = ${n}({{PARAMS}})`, ['current']) ??
168
+ v
169
+ ).toCdata(),
170
+ security_attribute: $.from('securityAttribute').map(
171
+ (v) => v.ifString()?.pipe((v) => AclAttributes[v.getValue()]) ?? v
172
+ ),
173
+ })),
174
+ })
175
+
176
+ const roles = arg.get('roles').ifArray()?.getElements() ?? []
177
+ const securityAttribute = arg.get('securityAttribute')
178
+ const attributeRecord = securityAttribute.ifRecord()
179
+ if (roles.length < 1) {
180
+ if (!securityAttribute.getValue() && !advanced && !arg.get('condition').getValue()) {
181
+ diagnostics.warn(
182
+ callExpression,
183
+ 'ACLs must have at least one of the following: roles, security_attribute, condition, or script'
184
+ )
185
+ } else if (attributeRecord) {
186
+ const localOrExisting = arg.get('localOrExisting').ifString()?.getValue()
187
+ if (
188
+ localOrExisting === 'Existing' &&
189
+ (attributeRecord.get('type').getValue() !== 'compound' ||
190
+ attributeRecord.get('is_localized').getValue())
191
+ ) {
192
+ diagnostics.error(
193
+ arg,
194
+ `Invalid ACL with 'Existing' security_attribute: Must have a security_attribute with a type of 'compound' and is_localized set to false.`
195
+ )
196
+ } else if (
197
+ (!localOrExisting || localOrExisting === 'Local') &&
198
+ !attributeRecord.get('is_localized').ifBoolean()?.getValue()
199
+ ) {
200
+ diagnostics.error(
201
+ arg,
202
+ `Invalid ACL with 'Local' security_attribute: security_attribute must have is_localized set to true`
203
+ )
204
+ }
205
+ }
206
+ }
207
+
208
+ return {
209
+ success: true,
210
+ value: acl.with(
211
+ ...roles.map((role) =>
212
+ factory.createRecord({
213
+ source: callExpression,
214
+ table: 'sys_security_acl_role',
215
+ properties: {
216
+ sys_security_acl: acl,
217
+ sys_user_role:
218
+ role.ifString()?.pipe((roleNameOrGuid) =>
219
+ isGUID(roleNameOrGuid.getValue())
220
+ ? factory.createReference({
221
+ source: roleNameOrGuid,
222
+ table: 'sys_user_role',
223
+ guid: roleNameOrGuid.getValue(),
224
+ })
225
+ : factory.createReference({
226
+ source: roleNameOrGuid,
227
+ table: 'sys_user_role',
228
+ keys: { name: roleNameOrGuid },
229
+ })
230
+ ) ?? role,
231
+ },
232
+ })
233
+ )
234
+ ),
235
+ }
236
+ },
237
+ },
238
+ ],
239
+ })
240
+
241
+ function getTableOrName(type: keyof typeof AclTypes, name: string) {
242
+ if (AclNamedTypes[type]) {
243
+ return { name }
244
+ }
245
+ const split = name.indexOf('.')
246
+ const table = split === -1 ? name : name.substring(0, split)
247
+ const field = split === -1 ? '' : name.substring(split + 1)
248
+
249
+ return { table, ...(field ? { field } : {}) }
250
+ }
251
+
252
+ function reverseLookup<T extends object>(obj: T, sysId): keyof T {
253
+ return (Object.entries(obj)
254
+ .filter(([_, id]) => id === sysId)
255
+ .map(([key]) => key)[0] || '') as keyof T
256
+ }