@flow-scanner/lightning-flow-scanner-core 6.6.4 → 6.6.5

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 (231) hide show
  1. package/CONTRIBUTING.md +31 -0
  2. package/README.md +426 -0
  3. package/SECURITY.md +54 -0
  4. package/package.json +7 -57
  5. package/.husky/pre-commit +0 -1
  6. package/.husky/pre-push +0 -1
  7. package/.prettierignore +0 -5
  8. package/.swcrc +0 -26
  9. package/eslint.config.mjs +0 -36
  10. package/jest.config.cjs +0 -32
  11. package/jest.env-setup.js +0 -101
  12. package/lint-staged.config.mjs +0 -8
  13. package/out/assets/media/banner.png +0 -0
  14. package/prettier.config.mjs +0 -5
  15. package/src/index.ts +0 -44
  16. package/src/main/interfaces/IExceptions.ts +0 -6
  17. package/src/main/interfaces/IRuleConfig.ts +0 -3
  18. package/src/main/interfaces/IRuleDefinition.ts +0 -12
  19. package/src/main/interfaces/IRuleOptions.ts +0 -5
  20. package/src/main/interfaces/IRulesConfig.ts +0 -15
  21. package/src/main/internals/internals.ts +0 -35
  22. package/src/main/libs/BuildFlow.ts +0 -11
  23. package/src/main/libs/Compiler.ts +0 -69
  24. package/src/main/libs/ConvertFlowNodes.ts +0 -4
  25. package/src/main/libs/DynamicRule.ts +0 -11
  26. package/src/main/libs/FixFlows.ts +0 -61
  27. package/src/main/libs/GetRuleDefinitions.ts +0 -65
  28. package/src/main/libs/ParseFlows.ts +0 -34
  29. package/src/main/libs/ScanFlows.ts +0 -112
  30. package/src/main/libs/exportAsDetails.ts +0 -26
  31. package/src/main/libs/exportAsSarif.ts +0 -88
  32. package/src/main/models/FlatViolation.ts +0 -8
  33. package/src/main/models/Flow.ts +0 -214
  34. package/src/main/models/FlowAttribute.ts +0 -12
  35. package/src/main/models/FlowElement.ts +0 -15
  36. package/src/main/models/FlowElementConnector.ts +0 -28
  37. package/src/main/models/FlowMetadata.ts +0 -7
  38. package/src/main/models/FlowNode.ts +0 -171
  39. package/src/main/models/FlowResource.ts +0 -10
  40. package/src/main/models/FlowType.ts +0 -52
  41. package/src/main/models/FlowVariable.ts +0 -12
  42. package/src/main/models/LoopRuleCommon.ts +0 -55
  43. package/src/main/models/ParsedFlow.ts +0 -15
  44. package/src/main/models/RuleCommon.ts +0 -68
  45. package/src/main/models/RuleInfo.ts +0 -43
  46. package/src/main/models/RuleResult.ts +0 -25
  47. package/src/main/models/ScanResult.ts +0 -12
  48. package/src/main/models/Violation.ts +0 -78
  49. package/src/main/rules/APIVersion.ts +0 -59
  50. package/src/main/rules/ActionCallsInLoop.ts +0 -24
  51. package/src/main/rules/AutoLayout.ts +0 -44
  52. package/src/main/rules/CopyAPIName.ts +0 -29
  53. package/src/main/rules/CyclomaticComplexity.ts +0 -67
  54. package/src/main/rules/DMLStatementInLoop.ts +0 -24
  55. package/src/main/rules/DuplicateDMLOperation.ts +0 -114
  56. package/src/main/rules/FlowDescription.ts +0 -32
  57. package/src/main/rules/FlowName.ts +0 -40
  58. package/src/main/rules/GetRecordAllFields.ts +0 -59
  59. package/src/main/rules/HardcodedId.ts +0 -37
  60. package/src/main/rules/HardcodedUrl.ts +0 -42
  61. package/src/main/rules/InactiveFlow.ts +0 -31
  62. package/src/main/rules/MissingFaultPath.ts +0 -89
  63. package/src/main/rules/MissingMetadataDescription.ts +0 -39
  64. package/src/main/rules/MissingNullHandler.ts +0 -95
  65. package/src/main/rules/ProcessBuilder.ts +0 -33
  66. package/src/main/rules/RecursiveAfterUpdate.ts +0 -88
  67. package/src/main/rules/SOQLQueryInLoop.ts +0 -24
  68. package/src/main/rules/SameRecordFieldUpdates.ts +0 -64
  69. package/src/main/rules/TriggerOrder.ts +0 -44
  70. package/src/main/rules/UnconnectedElement.ts +0 -48
  71. package/src/main/rules/UnsafeRunningContext.ts +0 -44
  72. package/src/main/rules/UnusedVariable.ts +0 -64
  73. package/src/main/store/DefaultRuleStore.ts +0 -54
  74. package/stryker.config.mjs +0 -23
  75. package/tests/APIVersion.test.ts +0 -83
  76. package/tests/AutoLayout.test.ts +0 -39
  77. package/tests/Config.test.ts +0 -119
  78. package/tests/ConfigBetaMode.test.ts +0 -26
  79. package/tests/CopyAPIName.test.ts +0 -43
  80. package/tests/CyclomaticComplexity.test.ts +0 -123
  81. package/tests/DMLStatementInLoop.test.ts +0 -31
  82. package/tests/DuplicateDMLOperation.test.ts +0 -41
  83. package/tests/Exceptions.test.ts +0 -813
  84. package/tests/ExportSarif.test.ts +0 -61
  85. package/tests/FlowDescription.test.ts +0 -42
  86. package/tests/FlowName.test.ts +0 -62
  87. package/tests/GetRecordElementAllFields.test.ts +0 -180
  88. package/tests/HardcodedId.test.ts +0 -16
  89. package/tests/HardcodedUrl.test.ts +0 -252
  90. package/tests/InactiveFlow.test.ts +0 -99
  91. package/tests/MissingFaultPath.test.ts +0 -50
  92. package/tests/MissingMetadataDescription.test.ts +0 -24
  93. package/tests/MissingNullHandler.test.ts +0 -43
  94. package/tests/No_Missing_Null_Handler.test.ts +0 -30
  95. package/tests/RecursiveAfterUpdate.test.ts +0 -160
  96. package/tests/SOQLQueryInLoop.test.ts +0 -32
  97. package/tests/SameRecordFieldUpdates.test.ts +0 -241
  98. package/tests/SanityTest.test.ts +0 -15
  99. package/tests/TriggerOrder.test.ts +0 -92
  100. package/tests/UnconnectedElement.test.ts +0 -74
  101. package/tests/UnsafeRunningContext.test.ts +0 -46
  102. package/tests/UnusedVariable.test.ts +0 -56
  103. package/tests/jsonfiles/MissingFaultPath_BeforeSave_Bypass.json +0 -128
  104. package/tests/jsonfiles/MissingFaultPath_WaitConditions.json +0 -102
  105. package/tests/jsonfiles/MissingFaultPath_WaitDate.json +0 -88
  106. package/tests/jsonfiles/MissingFaultPath_WaitDuration.json +0 -90
  107. package/tests/models/Flow.test.ts +0 -107
  108. package/tests/models/LoopRuleCommon.test.ts +0 -253
  109. package/tests/models/RuleCommon.test.ts +0 -47
  110. package/tsconfig.json +0 -19
  111. package/tsconfig.tsbuildinfo +0 -1
  112. package/tsconfig.types.json +0 -25
  113. package/vite.config.ts +0 -28
  114. /package/{out/index.d.ts → index.d.ts} +0 -0
  115. /package/{out/index.js → index.js} +0 -0
  116. /package/{out/main → main}/interfaces/IExceptions.d.ts +0 -0
  117. /package/{out/main → main}/interfaces/IExceptions.js +0 -0
  118. /package/{out/main → main}/interfaces/IRuleConfig.d.ts +0 -0
  119. /package/{out/main → main}/interfaces/IRuleConfig.js +0 -0
  120. /package/{out/main → main}/interfaces/IRuleDefinition.d.ts +0 -0
  121. /package/{out/main → main}/interfaces/IRuleDefinition.js +0 -0
  122. /package/{out/main → main}/interfaces/IRuleOptions.d.ts +0 -0
  123. /package/{out/main → main}/interfaces/IRuleOptions.js +0 -0
  124. /package/{out/main → main}/interfaces/IRulesConfig.d.ts +0 -0
  125. /package/{out/main → main}/interfaces/IRulesConfig.js +0 -0
  126. /package/{out/main → main}/internals/internals.d.ts +0 -0
  127. /package/{out/main → main}/internals/internals.js +0 -0
  128. /package/{out/main → main}/libs/BuildFlow.d.ts +0 -0
  129. /package/{out/main → main}/libs/BuildFlow.js +0 -0
  130. /package/{out/main → main}/libs/Compiler.d.ts +0 -0
  131. /package/{out/main → main}/libs/Compiler.js +0 -0
  132. /package/{out/main → main}/libs/ConvertFlowNodes.d.ts +0 -0
  133. /package/{out/main → main}/libs/ConvertFlowNodes.js +0 -0
  134. /package/{out/main → main}/libs/DynamicRule.d.ts +0 -0
  135. /package/{out/main → main}/libs/DynamicRule.js +0 -0
  136. /package/{out/main → main}/libs/FixFlows.d.ts +0 -0
  137. /package/{out/main → main}/libs/FixFlows.js +0 -0
  138. /package/{out/main → main}/libs/GetRuleDefinitions.d.ts +0 -0
  139. /package/{out/main → main}/libs/GetRuleDefinitions.js +0 -0
  140. /package/{out/main → main}/libs/ParseFlows.d.ts +0 -0
  141. /package/{out/main → main}/libs/ParseFlows.js +0 -0
  142. /package/{out/main → main}/libs/ScanFlows.d.ts +0 -0
  143. /package/{out/main → main}/libs/ScanFlows.js +0 -0
  144. /package/{out/main → main}/libs/exportAsDetails.d.ts +0 -0
  145. /package/{out/main → main}/libs/exportAsDetails.js +0 -0
  146. /package/{out/main → main}/libs/exportAsSarif.d.ts +0 -0
  147. /package/{out/main → main}/libs/exportAsSarif.js +0 -0
  148. /package/{out/main → main}/models/FlatViolation.d.ts +0 -0
  149. /package/{out/main → main}/models/FlatViolation.js +0 -0
  150. /package/{out/main → main}/models/Flow.d.ts +0 -0
  151. /package/{out/main → main}/models/Flow.js +0 -0
  152. /package/{out/main → main}/models/FlowAttribute.d.ts +0 -0
  153. /package/{out/main → main}/models/FlowAttribute.js +0 -0
  154. /package/{out/main → main}/models/FlowElement.d.ts +0 -0
  155. /package/{out/main → main}/models/FlowElement.js +0 -0
  156. /package/{out/main → main}/models/FlowElementConnector.d.ts +0 -0
  157. /package/{out/main → main}/models/FlowElementConnector.js +0 -0
  158. /package/{out/main → main}/models/FlowMetadata.d.ts +0 -0
  159. /package/{out/main → main}/models/FlowMetadata.js +0 -0
  160. /package/{out/main → main}/models/FlowNode.d.ts +0 -0
  161. /package/{out/main → main}/models/FlowNode.js +0 -0
  162. /package/{out/main → main}/models/FlowResource.d.ts +0 -0
  163. /package/{out/main → main}/models/FlowResource.js +0 -0
  164. /package/{out/main → main}/models/FlowType.d.ts +0 -0
  165. /package/{out/main → main}/models/FlowType.js +0 -0
  166. /package/{out/main → main}/models/FlowVariable.d.ts +0 -0
  167. /package/{out/main → main}/models/FlowVariable.js +0 -0
  168. /package/{out/main → main}/models/LoopRuleCommon.d.ts +0 -0
  169. /package/{out/main → main}/models/LoopRuleCommon.js +0 -0
  170. /package/{out/main → main}/models/ParsedFlow.d.ts +0 -0
  171. /package/{out/main → main}/models/ParsedFlow.js +0 -0
  172. /package/{out/main → main}/models/RuleCommon.d.ts +0 -0
  173. /package/{out/main → main}/models/RuleCommon.js +0 -0
  174. /package/{out/main → main}/models/RuleInfo.d.ts +0 -0
  175. /package/{out/main → main}/models/RuleInfo.js +0 -0
  176. /package/{out/main → main}/models/RuleResult.d.ts +0 -0
  177. /package/{out/main → main}/models/RuleResult.js +0 -0
  178. /package/{out/main → main}/models/ScanResult.d.ts +0 -0
  179. /package/{out/main → main}/models/ScanResult.js +0 -0
  180. /package/{out/main → main}/models/Violation.d.ts +0 -0
  181. /package/{out/main → main}/models/Violation.js +0 -0
  182. /package/{out/main → main}/rules/APIVersion.d.ts +0 -0
  183. /package/{out/main → main}/rules/APIVersion.js +0 -0
  184. /package/{out/main → main}/rules/ActionCallsInLoop.d.ts +0 -0
  185. /package/{out/main → main}/rules/ActionCallsInLoop.js +0 -0
  186. /package/{out/main → main}/rules/AutoLayout.d.ts +0 -0
  187. /package/{out/main → main}/rules/AutoLayout.js +0 -0
  188. /package/{out/main → main}/rules/CopyAPIName.d.ts +0 -0
  189. /package/{out/main → main}/rules/CopyAPIName.js +0 -0
  190. /package/{out/main → main}/rules/CyclomaticComplexity.d.ts +0 -0
  191. /package/{out/main → main}/rules/CyclomaticComplexity.js +0 -0
  192. /package/{out/main → main}/rules/DMLStatementInLoop.d.ts +0 -0
  193. /package/{out/main → main}/rules/DMLStatementInLoop.js +0 -0
  194. /package/{out/main → main}/rules/DuplicateDMLOperation.d.ts +0 -0
  195. /package/{out/main → main}/rules/DuplicateDMLOperation.js +0 -0
  196. /package/{out/main → main}/rules/FlowDescription.d.ts +0 -0
  197. /package/{out/main → main}/rules/FlowDescription.js +0 -0
  198. /package/{out/main → main}/rules/FlowName.d.ts +0 -0
  199. /package/{out/main → main}/rules/FlowName.js +0 -0
  200. /package/{out/main → main}/rules/GetRecordAllFields.d.ts +0 -0
  201. /package/{out/main → main}/rules/GetRecordAllFields.js +0 -0
  202. /package/{out/main → main}/rules/HardcodedId.d.ts +0 -0
  203. /package/{out/main → main}/rules/HardcodedId.js +0 -0
  204. /package/{out/main → main}/rules/HardcodedUrl.d.ts +0 -0
  205. /package/{out/main → main}/rules/HardcodedUrl.js +0 -0
  206. /package/{out/main → main}/rules/InactiveFlow.d.ts +0 -0
  207. /package/{out/main → main}/rules/InactiveFlow.js +0 -0
  208. /package/{out/main → main}/rules/MissingFaultPath.d.ts +0 -0
  209. /package/{out/main → main}/rules/MissingFaultPath.js +0 -0
  210. /package/{out/main → main}/rules/MissingMetadataDescription.d.ts +0 -0
  211. /package/{out/main → main}/rules/MissingMetadataDescription.js +0 -0
  212. /package/{out/main → main}/rules/MissingNullHandler.d.ts +0 -0
  213. /package/{out/main → main}/rules/MissingNullHandler.js +0 -0
  214. /package/{out/main → main}/rules/ProcessBuilder.d.ts +0 -0
  215. /package/{out/main → main}/rules/ProcessBuilder.js +0 -0
  216. /package/{out/main → main}/rules/RecursiveAfterUpdate.d.ts +0 -0
  217. /package/{out/main → main}/rules/RecursiveAfterUpdate.js +0 -0
  218. /package/{out/main → main}/rules/SOQLQueryInLoop.d.ts +0 -0
  219. /package/{out/main → main}/rules/SOQLQueryInLoop.js +0 -0
  220. /package/{out/main → main}/rules/SameRecordFieldUpdates.d.ts +0 -0
  221. /package/{out/main → main}/rules/SameRecordFieldUpdates.js +0 -0
  222. /package/{out/main → main}/rules/TriggerOrder.d.ts +0 -0
  223. /package/{out/main → main}/rules/TriggerOrder.js +0 -0
  224. /package/{out/main → main}/rules/UnconnectedElement.d.ts +0 -0
  225. /package/{out/main → main}/rules/UnconnectedElement.js +0 -0
  226. /package/{out/main → main}/rules/UnsafeRunningContext.d.ts +0 -0
  227. /package/{out/main → main}/rules/UnsafeRunningContext.js +0 -0
  228. /package/{out/main → main}/rules/UnusedVariable.d.ts +0 -0
  229. /package/{out/main → main}/rules/UnusedVariable.js +0 -0
  230. /package/{out/main → main}/store/DefaultRuleStore.d.ts +0 -0
  231. /package/{out/main → main}/store/DefaultRuleStore.js +0 -0
package/eslint.config.mjs DELETED
@@ -1,36 +0,0 @@
1
- import deMorgan from "eslint-plugin-de-morgan";
2
- import github from "eslint-plugin-github";
3
- import pluginJest from "eslint-plugin-jest";
4
- import perfectionist from "eslint-plugin-perfectionist";
5
- import sonarjs from "eslint-plugin-sonarjs";
6
- import globals from "globals";
7
- import tseslint from "typescript-eslint";
8
-
9
- export default [
10
- { languageOptions: { globals: globals.browser } },
11
- ...tseslint.configs.recommended,
12
- {
13
- files: ["tests/*.test.ts"],
14
- languageOptions: {
15
- globals: pluginJest.environments.globals.globals,
16
- },
17
- plugins: { jest: pluginJest },
18
- rules: {
19
- "jest/no-alias-methods": "error",
20
- "jest/no-disabled-tests": "warn",
21
- "jest/no-focused-tests": "error",
22
- "jest/no-identical-title": "error",
23
- "jest/prefer-to-have-length": "warn",
24
- "jest/valid-expect": "error",
25
- },
26
- },
27
- {
28
- ignores: ["jest.config.ts", "assets/example-flows/**"],
29
- },
30
- perfectionist.configs["recommended-alphabetical"],
31
- perfectionist.configs["recommended-line-length"],
32
- perfectionist.configs["recommended-natural"],
33
- sonarjs.configs.recommended,
34
- deMorgan.configs.recommended,
35
- ...github.getFlatConfigs().typescript,
36
- ];
package/jest.config.cjs DELETED
@@ -1,32 +0,0 @@
1
- module.exports = {
2
- automock: false,
3
- clearMocks: true,
4
- collectCoverage: true,
5
- coverageDirectory: "coverage",
6
- coverageProvider: "v8",
7
- coverageReporters: ["json", "text", "lcov"],
8
- modulePathIgnorePatterns: ["./jest.config.cjs", "./out/"],
9
- setupFilesAfterEnv: ["<rootDir>/jest.env-setup.js"],
10
- testEnvironment: "node",
11
- testPathIgnorePatterns: ["/node_modules/"],
12
- transform: {
13
- "^.+\\.(t|j)sx?$": [
14
- "@swc-node/jest",
15
- {
16
- module: "commonjs",
17
- swc: {
18
- jsc: {
19
- target: "es2020",
20
- parser: {
21
- syntax: "typescript",
22
- tsx: false,
23
- },
24
- },
25
- sourceMaps: "inline",
26
- minify: false,
27
- },
28
- },
29
- ],
30
- },
31
- transformIgnorePatterns: ["/node_modules/", "\\.pnp\\.[^\\/]+$"],
32
- };
package/jest.env-setup.js DELETED
@@ -1,101 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
-
4
- module.exports = () => {
5
- if (!process.env.UMD_PATH) {
6
- console.log("UMD Setup: No UMD_PATH—skipping (Node-only mode)");
7
- return;
8
- }
9
-
10
- const umdFilePath = path.resolve(process.env.UMD_PATH);
11
-
12
- if (!fs.existsSync(umdFilePath)) {
13
- console.warn("UMD Setup: File not found at", umdFilePath, "—skipping.");
14
- return;
15
- }
16
-
17
- let umdCode = fs.readFileSync(umdFilePath, "utf8");
18
- const fastXmlParser = require("fast-xml-parser");
19
-
20
- // Vite UMD pattern: (function(global, factory) { ... })(this, function(exports, dependency) { ... });
21
- // We need to extract and execute the factory function
22
-
23
- // Try to match Vite's UMD pattern more flexibly
24
- const viteUmdMatch = umdCode.match(
25
- /\(function\s*\([^,]+,\s*(\w+)\)\s*\{[\s\S]*?\}\)\s*\(this,\s*function\s*\((\w+)(?:,\s*(\w+))?\)\s*\{([\s\S]+)\}\s*\)\s*;?\s*$/
26
- );
27
-
28
- if (viteUmdMatch) {
29
- const factoryBody = viteUmdMatch[4];
30
- const exportsParam = viteUmdMatch[2];
31
- const depParam = viteUmdMatch[3];
32
-
33
- try {
34
- // Create the factory function with proper parameters
35
- const factoryFn = depParam
36
- ? new Function(exportsParam, depParam, factoryBody)
37
- : new Function(exportsParam, factoryBody);
38
-
39
- // Create exports object and invoke factory
40
- const exports = {};
41
- if (depParam) {
42
- factoryFn(exports, fastXmlParser);
43
- } else {
44
- factoryFn(exports);
45
- }
46
-
47
- // Assign to global
48
- global.lightningflowscanner = exports;
49
-
50
- if (Object.keys(exports).length === 0) {
51
- console.error("UMD Setup: WARNING - exports object is empty!");
52
- }
53
- } catch (e) {
54
- console.error("UMD Factory error:", e.message);
55
- console.error("Stack:", e.stack);
56
- }
57
- } else {
58
- // Fallback: Try direct execution approach
59
-
60
- try {
61
- // Create a mock global/window context
62
- const mockGlobal = {};
63
- const mockFactory = new Function(
64
- "global",
65
- "factory",
66
- `
67
- return (function(root, factoryFn) {
68
- if (typeof exports === 'object' && typeof module !== 'undefined') {
69
- factoryFn(exports, require('fast-xml-parser'));
70
- } else {
71
- factoryFn((root.lightningflowscanner = {}), root.fastXmlParser);
72
- }
73
- })(global, factory);
74
- `
75
- );
76
-
77
- // Execute in controlled context
78
- const vm = require("vm");
79
- const sandbox = {
80
- exports: {},
81
- require: (id) => (id === "fast-xml-parser" ? fastXmlParser : require(id)),
82
- module: { exports: {} },
83
- console: console,
84
- };
85
-
86
- vm.runInNewContext(umdCode, sandbox);
87
-
88
- // Check what got exported
89
- const exports = sandbox.exports.default || sandbox.exports || sandbox.module.exports;
90
-
91
- if (exports && Object.keys(exports).length > 0) {
92
- global.lightningflowscanner = exports;
93
- } else {
94
- console.error("UMD Setup: Direct execution failed - no exports found");
95
- }
96
- } catch (e) {
97
- console.error("UMD Direct execution error:", e.message);
98
- console.error("Stack:", e.stack.slice(0, 400));
99
- }
100
- }
101
- };
@@ -1,8 +0,0 @@
1
- import micromatch from "micromatch";
2
-
3
- const isNotExampleFlows = (files) => micromatch.not(files, ["assets/example-flows/**"]);
4
-
5
- export default {
6
- "**/*.{js,json,md,xml,yaml,yml}": (files) =>
7
- isNotExampleFlows(files).map((f) => `prettier --write "${f}"`),
8
- };
Binary file
@@ -1,5 +0,0 @@
1
- export default {
2
- printWidth: 100,
3
- tabWidth: 2,
4
- trailingComma: "es5",
5
- };
package/src/index.ts DELETED
@@ -1,44 +0,0 @@
1
- import type { IRuleDefinition } from "./main/interfaces/IRuleDefinition";
2
- import type { IRulesConfig } from "./main/interfaces/IRulesConfig";
3
- import type { FlatViolation } from "./main/models/FlatViolation";
4
-
5
- import { Compiler } from "./main/libs/Compiler";
6
- import { exportDetails } from "./main/libs/exportAsDetails";
7
- import { exportSarif } from "./main/libs/exportAsSarif";
8
- import { fix } from "./main/libs/FixFlows";
9
- import { getRules } from "./main/libs/GetRuleDefinitions";
10
- import { parse } from "./main/libs/ParseFlows";
11
- import { scan } from "./main/libs/ScanFlows";
12
- import { Flow } from "./main/models/Flow";
13
- import { FlowAttribute } from "./main/models/FlowAttribute";
14
- import { FlowElement } from "./main/models/FlowElement";
15
- import { FlowNode } from "./main/models/FlowNode";
16
- import { FlowResource } from "./main/models/FlowResource";
17
- import { FlowType } from "./main/models/FlowType";
18
- import { FlowVariable } from "./main/models/FlowVariable";
19
- import { ParsedFlow } from "./main/models/ParsedFlow";
20
- import { RuleResult } from "./main/models/RuleResult";
21
- import { ScanResult } from "./main/models/ScanResult";
22
- import { Violation } from "./main/models/Violation";
23
-
24
- export {
25
- Compiler,
26
- exportDetails,
27
- exportSarif,
28
- fix,
29
- Flow,
30
- FlowAttribute,
31
- FlowElement,
32
- FlowNode,
33
- FlowResource,
34
- FlowType,
35
- FlowVariable,
36
- getRules,
37
- parse,
38
- ParsedFlow,
39
- Violation,
40
- RuleResult,
41
- scan,
42
- ScanResult,
43
- };
44
- export type { FlatViolation, IRuleDefinition, IRulesConfig };
@@ -1,6 +0,0 @@
1
- export interface IExceptions {
2
- [exceptionName: string]: {
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- [property: string]: any[];
5
- };
6
- }
@@ -1,3 +0,0 @@
1
- export interface IRuleConfig {
2
- severity?: string;
3
- }
@@ -1,12 +0,0 @@
1
- import { Flow, RuleResult } from "../internals/internals";
2
- export interface IRuleDefinition {
3
- description: string;
4
- docRefs: Array<{ label: string; path: string }>;
5
- execute(flow: Flow, options?: object, suppressions?: string[]): RuleResult;
6
- isConfigurable: boolean;
7
- label: string;
8
- name: string;
9
- severity?: string;
10
- supportedTypes: string[];
11
- uri?: string;
12
- }
@@ -1,5 +0,0 @@
1
- import { IRuleConfig } from "./IRuleConfig";
2
-
3
- export interface IRuleOptions {
4
- [ruleName: string]: IRuleConfig;
5
- }
@@ -1,15 +0,0 @@
1
- import { IExceptions } from "./IExceptions";
2
- import { IRuleOptions } from "./IRuleOptions";
3
-
4
- export enum DetailLevel {
5
- ENRICHED = 'enriched',
6
- SIMPLE = 'simple'
7
- }
8
-
9
- export interface IRulesConfig {
10
- betaMode?: boolean; // Toggles beta rules; defaults to false
11
- betamode?: boolean; // Use betaMode instead; to be removed
12
- detailLevel?: 'enriched' | 'simple' | DetailLevel;
13
- exceptions?: IExceptions;
14
- rules?: IRuleOptions;
15
- }
@@ -1,35 +0,0 @@
1
- import type { IRuleDefinition } from "../interfaces/IRuleDefinition";
2
- import type { IRulesConfig } from "../interfaces/IRulesConfig";
3
-
4
- import { Compiler } from "../libs/Compiler";
5
- import { FlatViolation } from "../models/FlatViolation";
6
- import { Flow } from "../models/Flow";
7
- import { FlowAttribute } from "../models/FlowAttribute";
8
- import { FlowElement } from "../models/FlowElement";
9
- import { FlowNode } from "../models/FlowNode";
10
- import { FlowResource } from "../models/FlowResource";
11
- import { FlowType } from "../models/FlowType";
12
- import { FlowVariable } from "../models/FlowVariable";
13
- import { ParsedFlow } from "../models/ParsedFlow";
14
- import { RuleCommon } from "../models/RuleCommon";
15
- import { RuleResult } from "../models/RuleResult";
16
- import { ScanResult } from "../models/ScanResult";
17
- import { Violation } from "../models/Violation";
18
-
19
- // Used to prevent circular dependencies in Common JS
20
- export {
21
- FlowAttribute,
22
- FlowElement,
23
- FlowNode,
24
- FlowType,
25
- FlowVariable,
26
- FlowResource,
27
- Flow,
28
- Compiler,
29
- ScanResult,
30
- RuleResult,
31
- Violation,
32
- RuleCommon,
33
- ParsedFlow,
34
- };
35
- export type { IRuleDefinition, IRulesConfig, FlatViolation };
@@ -1,11 +0,0 @@
1
- import { convertFlowNodes } from "./ConvertFlowNodes";
2
-
3
- export function BuildFlow(nodesToMerge) {
4
- let res = {};
5
- for (const nodeToMerge of nodesToMerge) {
6
- const subtype = nodeToMerge.subtype;
7
- const nodesOfType = nodesToMerge.filter((node) => subtype === node.subtype);
8
- res = convertFlowNodes(res, nodesOfType, subtype);
9
- }
10
- return res;
11
- }
@@ -1,69 +0,0 @@
1
- import { Flow } from "../models/Flow";
2
- import { FlowNode } from "../models/FlowNode";
3
-
4
- export class Compiler {
5
- public visitedElements: Set<string>;
6
-
7
- constructor() {
8
- this.visitedElements = new Set<string>();
9
- }
10
-
11
- traverseFlow(
12
- flow: Flow,
13
- startElementName: string,
14
- visitCallback: (element: FlowNode) => void,
15
- endElementName?: string
16
- ) {
17
- // Iterative Deepening Depth-First Search (IDDFS)
18
- let elementsToVisit = [startElementName];
19
-
20
- while (elementsToVisit.length > 0) {
21
- const nextElements: string[] = [];
22
-
23
- for (const elementName of elementsToVisit) {
24
- if (!this.visitedElements.has(elementName)) {
25
- const currentElement = flow.elements?.find(
26
- (element) => element.name === elementName
27
- ) as FlowNode;
28
- if (currentElement) {
29
- visitCallback(currentElement);
30
- this.visitedElements.add(elementName);
31
- nextElements.push(...this.findNextElements(flow, currentElement, endElementName));
32
- }
33
- }
34
- }
35
-
36
- if (nextElements.length === 0) {
37
- // If no more next elements
38
- break; // Terminate the traversal
39
- }
40
-
41
- elementsToVisit = nextElements;
42
- }
43
- }
44
-
45
- private findNextElements(
46
- flow: Flow,
47
- currentElement: FlowNode,
48
- endElementName?: string
49
- ): string[] {
50
- const nextElements: string[] = [];
51
-
52
- if (!currentElement.connectors || currentElement.connectors.length === 0) {
53
- return nextElements;
54
- }
55
-
56
- for (const connector of currentElement.connectors) {
57
- const targetReference =
58
- connector?.connectorTargetReference?.targetReference ?? connector.reference;
59
- // Check if the reference exists in the flow elements
60
- const nextElement = flow.elements?.find(
61
- (element) => element.metaType === "node" && element.name === targetReference
62
- );
63
- if (nextElement && nextElement.metaType === "node" && nextElement.name !== endElementName) {
64
- nextElements.push(nextElement!.name as string);
65
- }
66
- }
67
- return nextElements;
68
- }
69
- }
@@ -1,4 +0,0 @@
1
- export function convertFlowNodes(obj, nodes, key) {
2
- obj[key] = nodes.map((node) => node.element);
3
- return obj;
4
- }
@@ -1,11 +0,0 @@
1
- import { IRuleDefinition } from "../interfaces/IRuleDefinition";
2
- import { BetaRuleStore, DefaultRuleStore } from "../store/DefaultRuleStore";
3
-
4
- export class DynamicRule<T extends IRuleDefinition> {
5
- constructor(className: string, betaMode = false) {
6
- if (betaMode && BetaRuleStore.hasOwnProperty(className)) {
7
- return new BetaRuleStore[className]() as T;
8
- }
9
- return new DefaultRuleStore[className]() as T;
10
- }
11
- }
@@ -1,61 +0,0 @@
1
- import * as core from "../internals/internals";
2
- import { BuildFlow } from "./BuildFlow";
3
-
4
- export function fix(results: core.ScanResult[]): core.ScanResult[] {
5
- const newResults: core.ScanResult[] = [];
6
-
7
- for (const result of results) {
8
- if (!result.ruleResults || result.ruleResults.length === 0) continue;
9
-
10
- const fixables: core.RuleResult[] = result.ruleResults.filter(
11
- (r) =>
12
- (r.ruleName === "UnusedVariable" && r.occurs) ||
13
- (r.ruleName === "UnconnectedElement" && r.occurs)
14
- );
15
-
16
- if (fixables.length === 0) continue;
17
-
18
- const newFlow = FixFlows(result.flow, fixables);
19
-
20
- const hasRemainingElements = newFlow.elements && newFlow.elements.length > 0;
21
- if (hasRemainingElements) {
22
- result.flow = newFlow;
23
- newResults.push(result);
24
- }
25
- }
26
-
27
- return newResults;
28
- }
29
-
30
- export function FixFlows(flow: core.Flow, ruleResults: core.RuleResult[]): core.Flow {
31
- const unusedVariableRes = ruleResults.find((r) => r.ruleName === "UnusedVariable");
32
- const unusedVariableNames = new Set(
33
- unusedVariableRes?.details?.map((d) => d.name) ?? []
34
- );
35
-
36
- const unconnectedElementsRes = ruleResults.find((r) => r.ruleName === "UnconnectedElement");
37
- const unconnectedElementNames = new Set(
38
- unconnectedElementsRes?.details?.map((d) => d.name) ?? []
39
- );
40
-
41
- const nodesToKeep = flow.elements?.filter((node) => {
42
- switch (node.metaType) {
43
- case "metadata":
44
- case "resource":
45
- return true;
46
- case "node": {
47
- const nodeElement = node as core.FlowNode;
48
- return !unconnectedElementNames.has(nodeElement.name);
49
- }
50
- case "variable": {
51
- const nodeVar = node as core.FlowVariable;
52
- return !unusedVariableNames.has(nodeVar.name);
53
- }
54
- default:
55
- return false;
56
- }
57
- }) ?? [];
58
-
59
- const xmldata = BuildFlow(nodesToKeep);
60
- return new core.Flow(flow.fsPath, xmldata);
61
- }
@@ -1,65 +0,0 @@
1
- import { IRuleDefinition } from "../interfaces/IRuleDefinition";
2
- import { IRulesConfig } from "../interfaces/IRulesConfig";
3
- import { BetaRuleStore, DefaultRuleStore } from "../store/DefaultRuleStore";
4
- import { DynamicRule } from "./DynamicRule";
5
-
6
- export function GetRuleDefinitions(
7
- ruleConfig?: Map<string, unknown>,
8
- options?: IRulesConfig
9
- ): IRuleDefinition[] {
10
- const selectedRules: IRuleDefinition[] = [];
11
- const includeBeta = options?.betaMode === true || options?.betamode === true;
12
-
13
- if (ruleConfig && ruleConfig instanceof Map) {
14
- for (const ruleName of ruleConfig.keys()) {
15
- let severity = "warning";
16
- try {
17
- const configuredSeverity = ruleConfig.get(ruleName)?.["severity"];
18
- if (
19
- configuredSeverity &&
20
- (configuredSeverity === "error" ||
21
- configuredSeverity === "warning" ||
22
- configuredSeverity === "note")
23
- ) {
24
- severity = configuredSeverity;
25
- }
26
-
27
- // Pass betaMode to DynamicRule
28
- const matchedRule = new DynamicRule(ruleName, includeBeta) as IRuleDefinition;
29
- if (configuredSeverity) matchedRule.severity = severity;
30
- selectedRules.push(matchedRule);
31
-
32
- } catch (error) {
33
- console.log(error.message);
34
- }
35
- }
36
- } else {
37
- // Load all defaults
38
- for (const rule in DefaultRuleStore) {
39
- const matchedRule = new DynamicRule(rule, includeBeta) as IRuleDefinition;
40
- selectedRules.push(matchedRule);
41
- }
42
- }
43
-
44
- // Optionally add beta-only rules that are not in defaults
45
- if (includeBeta) {
46
- for (const betaRuleName in BetaRuleStore) {
47
- if (!selectedRules.some(r => r.name === betaRuleName)) {
48
- const betaRule = new DynamicRule(betaRuleName, true) as IRuleDefinition;
49
- selectedRules.push(betaRule);
50
- }
51
- }
52
- }
53
-
54
- return selectedRules;
55
- }
56
-
57
- export function getRules(ruleNames?: string[], options?: IRulesConfig): IRuleDefinition[] {
58
- if (ruleNames && ruleNames.length > 0) {
59
- const ruleSeverityMap = new Map<string, { severity: string }>(
60
- ruleNames.map(name => [name, { severity: "error" }])
61
- );
62
- return GetRuleDefinitions(ruleSeverityMap, options);
63
- }
64
- return GetRuleDefinitions(undefined, options);
65
- }
@@ -1,34 +0,0 @@
1
- import { XMLParser } from "fast-xml-parser";
2
- import { promises as fs } from "fs";
3
- import * as p from "path";
4
-
5
- import { Flow } from "../models/Flow";
6
- import { ParsedFlow } from "../models/ParsedFlow";
7
-
8
-
9
- export async function parse(selectedUris: string[]): Promise<ParsedFlow[]> {
10
- const parseResults: ParsedFlow[] = [];
11
- const parser = new XMLParser({
12
- attributeNamePrefix: "@_",
13
- ignoreAttributes: false,
14
- // @ts-expect-error type issue
15
- ignoreNameSpace: false,
16
- parseTagValue: false,
17
- textNodeName: "#text"
18
- });
19
-
20
- for (const uri of selectedUris) {
21
- try {
22
- const normalizedURI = p.normalize(uri);
23
- const content = await fs.readFile(normalizedURI, "utf8");
24
- const parsed = parser.parse(content);
25
- const flowObj = parsed.Flow;
26
- parseResults.push(new ParsedFlow(uri, new Flow(uri, flowObj)));
27
- } catch (e: any) {
28
- parseResults.push(
29
- new ParsedFlow(uri, undefined, e.message ?? e.toString())
30
- );
31
- }
32
- }
33
- return parseResults;
34
- }