@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
@@ -1,15 +0,0 @@
1
- import * as core from "../src";
2
-
3
- test("core exports sanity", () => {
4
- expect(core.scan).toBeDefined();
5
- expect(core.parse).toBeDefined();
6
- });
7
-
8
- describe('UMD Global', () => {
9
- it('exposes exports', () => {
10
- const scanner = global.lightningflowscanner;
11
- expect(scanner).toBeDefined();
12
- expect(typeof scanner.scan).toBe('function');
13
- expect(scanner.Flow).toBeDefined();
14
- });
15
- });
@@ -1,92 +0,0 @@
1
- import { describe, expect, it } from "@jest/globals";
2
-
3
- import { Flow, RuleResult, scan, ScanResult } from "../src";
4
- import { ParsedFlow } from "../src/main/models/ParsedFlow";
5
- import { TriggerOrder } from "../src/main/rules/TriggerOrder";
6
-
7
- describe("TriggerOrder", () => {
8
- it("should not trigger from default configuration on store", async () => {
9
- const ruleConfig = {
10
- exceptions: {},
11
- rules: {
12
- FlowDescription: {
13
- severity: "error",
14
- },
15
- },
16
- };
17
- const flows: ParsedFlow[] = [
18
- {
19
- flow: {
20
- type: "AutoLaunchedFlow",
21
- },
22
- } as Partial<ParsedFlow> as ParsedFlow,
23
- ];
24
- const results: ScanResult[] = scan(flows, ruleConfig);
25
- const scanResults = results.pop();
26
-
27
- const ruleResults = scanResults?.ruleResults.find((rule) => {
28
- return rule.ruleDefinition.name === "TriggerOrder";
29
- });
30
- expect(ruleResults).toBeFalsy();
31
- });
32
-
33
- it("should trigger when opt-in configuration", async () => {
34
- const flows: ParsedFlow[] = [
35
- {
36
- flow: {
37
- start: {
38
- object: "Account",
39
- },
40
- type: "AutoLaunchedFlow",
41
- },
42
- } as Partial<ParsedFlow> as ParsedFlow,
43
- ];
44
-
45
- const ruleConfig = {
46
- exceptions: {},
47
- rules: {
48
- TriggerOrder: {
49
- severity: "error",
50
- },
51
- },
52
- };
53
- const results: ScanResult[] = scan(flows, ruleConfig);
54
- const scanResults = results.pop();
55
-
56
- const expectedRule = scanResults?.ruleResults.find((rule) => rule.ruleName === "TriggerOrder");
57
- expect(expectedRule).toBeTruthy();
58
- expect(expectedRule?.occurs).toBe(true);
59
- expect(expectedRule?.details[0].details).toEqual({ expression: "10, 20, 30 ..." });
60
- });
61
-
62
- it("should flag trigger order when not present", async () => {
63
- const testData: ParsedFlow = {
64
- flow: {
65
- start: {
66
- object: "Account",
67
- },
68
- type: "AutoLaunchedFlow",
69
- },
70
- } as Partial<ParsedFlow> as ParsedFlow;
71
-
72
- const ruleResult: RuleResult = new TriggerOrder().execute(testData.flow as Flow);
73
-
74
- expect(ruleResult.occurs).toBeTruthy();
75
- });
76
-
77
- it("should not flag trigger order when present", async () => {
78
- const testData: ParsedFlow = {
79
- flow: {
80
- start: {
81
- object: "Account",
82
- },
83
- triggerOrder: 10,
84
- type: "AutoLaunchedFlow",
85
- },
86
- } as Partial<ParsedFlow> as ParsedFlow;
87
-
88
- const ruleResult: RuleResult = new TriggerOrder().execute(testData.flow as Flow);
89
-
90
- expect(ruleResult.occurs).toBeFalsy();
91
- });
92
- });
@@ -1,74 +0,0 @@
1
- import * as core from "../src";
2
- import * as path from "path";
3
- import { parse } from "../src/main/libs/ParseFlows";
4
- import { ParsedFlow } from "../src/main/models/ParsedFlow";
5
- import { UnconnectedElement } from "../src/main/rules/UnconnectedElement";
6
- import { describe, it, expect } from "@jest/globals";
7
-
8
- describe("UnconnectedElement", () => {
9
- const unconnectedElementRule: UnconnectedElement = new UnconnectedElement();
10
- it("there should be checks for unconnected element", async () => {
11
- const connectedElementTestFile = path.join(
12
- __dirname,
13
- "../../../assets/example-flows/force-app/main/default/flows/demo/Unconnected_Element.flow-meta.xml"
14
- );
15
- const parsed: ParsedFlow = (await parse([connectedElementTestFile])).pop() as ParsedFlow;
16
- const ruleResult: core.RuleResult = unconnectedElementRule.execute(parsed.flow as core.Flow);
17
- expect(ruleResult.occurs).toBe(true);
18
- expect(ruleResult.details).not.toHaveLength(0);
19
- ruleResult.details.forEach((detail) => {
20
- expect(detail.name).toBe("unused_assignment");
21
- });
22
- });
23
- it("async path there should be checks for unconnected element", async () => {
24
- const connectedElementTestFile = path.join(
25
- __dirname,
26
- "../../../assets/example-flows/force-app/main/default/flows/testing/Unconnected_Element_Async.flow-meta.xml"
27
- );
28
- const parsed: ParsedFlow = (await parse([connectedElementTestFile])).pop() as ParsedFlow;
29
- const ruleResult: core.RuleResult = unconnectedElementRule.execute(parsed.flow as core.Flow);
30
- expect(ruleResult.occurs).toBe(true);
31
- ruleResult.details.forEach((ruleDetail) => {
32
- expect(ruleDetail.name).toBe("UnconnectedElementTestOnAsync");
33
- });
34
- });
35
- it("should fix the unconnected element error", async () => {
36
- const connectedElementTestFile = path.join(
37
- __dirname,
38
- "../../../assets/example-flows/force-app/main/default/flows/demo/Unconnected_Element.flow-meta.xml"
39
- );
40
- const flows = await core.parse([connectedElementTestFile]);
41
- const ruleConfig = {
42
- rules: {
43
- UnconnectedElement: {
44
- severity: "error",
45
- },
46
- },
47
- };
48
- const results: core.ScanResult[] = core.scan(flows, ruleConfig);
49
- const fixedResults: core.ScanResult[] = core.fix(results);
50
- const fixedFlow: ParsedFlow = new ParsedFlow(connectedElementTestFile, fixedResults[0].flow);
51
- const newResults: core.ScanResult[] = core.scan([fixedFlow], ruleConfig);
52
- const fixedResultsOccurring = newResults[0].ruleResults.filter((rule) => rule.occurs);
53
- expect(fixedResultsOccurring).toHaveLength(0);
54
- });
55
- it("should not include enriched details with detailLevel simple", async () => {
56
- const testFile = path.join(
57
- __dirname,
58
- "../../../assets/example-flows/force-app/main/default/flows/demo/Unconnected_Element.flow-meta.xml"
59
- );
60
- const flows = await core.parse([testFile]);
61
- const ruleConfig = {
62
- detailLevel: "simple",
63
- };
64
- const results: core.ScanResult[] = core.scan(flows, ruleConfig);
65
- const ruleResult = results[0].ruleResults.find((r) => r.ruleName === "UnconnectedElement");
66
- expect(ruleResult).toBeDefined();
67
- expect(ruleResult.occurs).toBe(true);
68
- expect(ruleResult.details).not.toHaveLength(0);
69
- ruleResult.details.forEach((detail) => {
70
- expect(detail.name).toBe("unused_assignment");
71
- expect(detail.details).toBeUndefined();
72
- });
73
- });
74
- });
@@ -1,46 +0,0 @@
1
- import * as core from "../src";
2
- import * as path from "path";
3
-
4
- import { parse } from "../src/main/libs/ParseFlows";
5
- import { ParsedFlow } from "../src/main/models/ParsedFlow";
6
-
7
- import { describe, it, expect } from "@jest/globals";
8
- import { UnsafeRunningContext } from "../src/main/rules/UnsafeRunningContext";
9
-
10
- describe("UnsafeRunningContext", () => {
11
- const unsafeRunningContext: UnsafeRunningContext = new UnsafeRunningContext();
12
-
13
- it("should have a scan result for without sharing system mode", async () => {
14
- const unsafeContextTestFile = path.join(
15
- __dirname,
16
- "../../../assets/example-flows/force-app/main/default/flows/demo/Unsafe_Running_Context.flow-meta.xml"
17
- );
18
- const parsed: ParsedFlow = (await parse([unsafeContextTestFile])).pop() as ParsedFlow;
19
- const ruleResult: core.RuleResult = unsafeRunningContext.execute(parsed.flow as core.Flow);
20
- expect(ruleResult.occurs).toBe(true);
21
- expect(ruleResult.details).not.toHaveLength(0);
22
- expect(ruleResult.ruleDefinition.severity).toBe("warning");
23
- });
24
-
25
- it("should not have a scan result for with sharing system mode", async () => {
26
- const unsafeContextTestFile = path.join(
27
- __dirname,
28
- "../../../assets/example-flows/force-app/main/default/flows/testing/Unsafe_Running_Context_WithSharing.flow-meta.xml"
29
- );
30
- const parsed: ParsedFlow = (await parse([unsafeContextTestFile])).pop() as ParsedFlow;
31
- const ruleResult: core.RuleResult = unsafeRunningContext.execute(parsed.flow as core.Flow);
32
- expect(ruleResult.occurs).toBe(false);
33
- expect(ruleResult.details).toHaveLength(0);
34
- });
35
-
36
- it("should not have a scan result for default mode", async () => {
37
- const unsafeContextTestFile = path.join(
38
- __dirname,
39
- "../../../assets/example-flows/force-app/main/default/flows/testing/Unsafe_Running_Context_Default.flow-meta.xml"
40
- );
41
- const parsed: ParsedFlow = (await parse([unsafeContextTestFile])).pop() as ParsedFlow;
42
- const ruleResult: core.RuleResult = unsafeRunningContext.execute(parsed.flow as core.Flow);
43
- expect(ruleResult.occurs).toBe(false);
44
- expect(ruleResult.details).toHaveLength(0);
45
- });
46
- });
@@ -1,56 +0,0 @@
1
- import * as core from "../src";
2
- import * as path from "path";
3
- import { ParsedFlow } from "../src/main/models/ParsedFlow";
4
-
5
- import { describe, it, expect } from "@jest/globals";
6
-
7
- describe("UnusedVariable Rule", () => {
8
- const example_uri = path.join(__dirname, "../../../assets/example-flows/force-app/main/default/flows/demo/Unused_Variable.flow-meta.xml");
9
- const fixed_uri = path.join(__dirname, "../../../assets/example-flows/force-app/main/default/flows/testing/Unused_Variable_Fixed.flow-meta.xml");
10
-
11
- it("there should be a result for unused variables", async () => {
12
- const flows = await core.parse([example_uri]);
13
- const ruleConfig = {
14
- rules: {
15
- UnusedVariable: {
16
- severity: "error",
17
- },
18
- },
19
- };
20
- const results: core.ScanResult[] = core.scan(flows, ruleConfig);
21
- const occurringResults = results[0].ruleResults.filter((rule) => rule.occurs);
22
- expect(occurringResults).toHaveLength(1);
23
- });
24
-
25
- it("there should be no result for variables used in text elements", async () => {
26
- const flows = await core.parse([fixed_uri]);
27
- const ruleConfig = {
28
- rules: {
29
- UnusedVariable: {
30
- severity: "error",
31
- },
32
- },
33
- };
34
-
35
- const results: core.ScanResult[] = core.scan(flows, ruleConfig);
36
- const occurringResults = results[0].ruleResults.filter((rule) => rule.occurs);
37
- expect(occurringResults).toHaveLength(0);
38
- });
39
-
40
- it("should fix the unused variable error", async () => {
41
- const flows = await core.parse([example_uri]);
42
- const ruleConfig = {
43
- rules: {
44
- UnusedVariable: {
45
- severity: "error",
46
- },
47
- },
48
- };
49
- const results: core.ScanResult[] = core.scan(flows, ruleConfig);
50
- const fixedResults: core.ScanResult[] = core.fix(results);
51
- const fixedFlow: ParsedFlow = new ParsedFlow(example_uri, fixedResults[0].flow);
52
- const newResults: core.ScanResult[] = core.scan([fixedFlow], ruleConfig);
53
- const fixedResultsOccurring = newResults[0].ruleResults.filter((rule) => rule.occurs);
54
- expect(fixedResultsOccurring).toHaveLength(0);
55
- });
56
- });
@@ -1,128 +0,0 @@
1
- [
2
- {
3
- "flow": {
4
- "name": "Test_Flow",
5
- "xmldata": {
6
- "@xmlns": "http://soap.sforce.com/2006/04/metadata",
7
- "apiVersion": "62.0",
8
- "environments": "Default",
9
- "interviewLabel": "Test Flow {!$Flow.CurrentDateTime}",
10
- "label": "Test Flow",
11
- "processMetadataValues": [
12
- { "name": "BuilderType", "value": { "stringValue": "LightningFlowBuilder" } },
13
- { "name": "CanvasMode", "value": { "stringValue": "AUTO_LAYOUT_CANVAS" } },
14
- { "name": "OriginBuilderType", "value": { "stringValue": "LightningFlowBuilder" } }
15
- ],
16
- "processType": "AutoLaunchedFlow",
17
- "recordUpdates": {
18
- "description": "test",
19
- "name": "Update_triggering_records",
20
- "label": "Update triggering records",
21
- "locationX": "176",
22
- "locationY": "287",
23
- "inputAssignments": { "field": "Active__c", "value": { "stringValue": "Yes" } },
24
- "inputReference": "$Record"
25
- },
26
- "start": {
27
- "locationX": "50",
28
- "locationY": "0",
29
- "connector": { "targetReference": "Update_triggering_records" },
30
- "object": "Account",
31
- "recordTriggerType": "Create",
32
- "triggerType": "RecordBeforeSave"
33
- },
34
- "status": "Draft"
35
- },
36
- "label": "Test Flow",
37
- "interviewLabel": "Test Flow {!$Flow.CurrentDateTime}",
38
- "processType": "AutoLaunchedFlow",
39
- "processMetadataValues": [
40
- { "name": "BuilderType", "value": { "stringValue": "LightningFlowBuilder" } },
41
- { "name": "CanvasMode", "value": { "stringValue": "AUTO_LAYOUT_CANVAS" } },
42
- { "name": "OriginBuilderType", "value": { "stringValue": "LightningFlowBuilder" } }
43
- ],
44
- "start": {
45
- "locationX": "50",
46
- "locationY": "0",
47
- "connector": { "targetReference": "Update_triggering_records" },
48
- "object": "Account",
49
- "recordTriggerType": "Create",
50
- "triggerType": "RecordBeforeSave"
51
- },
52
- "status": "Draft",
53
- "type": "AutoLaunchedFlow",
54
- "elements": [
55
- { "element": "62.0", "subtype": "apiVersion", "metaType": "metadata" },
56
- { "element": "Default", "subtype": "environments", "metaType": "metadata" },
57
- {
58
- "element": "Test Flow {!$Flow.CurrentDateTime}",
59
- "subtype": "interviewLabel",
60
- "metaType": "metadata"
61
- },
62
- { "element": "Test Flow", "subtype": "label", "metaType": "metadata" },
63
- {
64
- "element": { "name": "BuilderType", "value": { "stringValue": "LightningFlowBuilder" } },
65
- "subtype": "processMetadataValues",
66
- "metaType": "metadata"
67
- },
68
- {
69
- "element": { "name": "CanvasMode", "value": { "stringValue": "AUTO_LAYOUT_CANVAS" } },
70
- "subtype": "processMetadataValues",
71
- "metaType": "metadata"
72
- },
73
- {
74
- "element": {
75
- "name": "OriginBuilderType",
76
- "value": { "stringValue": "LightningFlowBuilder" }
77
- },
78
- "subtype": "processMetadataValues",
79
- "metaType": "metadata"
80
- },
81
- { "element": "AutoLaunchedFlow", "subtype": "processType", "metaType": "metadata" },
82
- {
83
- "element": {
84
- "description": "test",
85
- "name": "Update_triggering_records",
86
- "label": "Update triggering records",
87
- "locationX": "176",
88
- "locationY": "287",
89
- "inputAssignments": { "field": "Active__c", "value": { "stringValue": "Yes" } },
90
- "inputReference": "$Record"
91
- },
92
- "subtype": "recordUpdates",
93
- "metaType": "node",
94
- "connectors": [],
95
- "name": "Update_triggering_records",
96
- "locationX": "176",
97
- "locationY": "287"
98
- },
99
- {
100
- "element": {
101
- "locationX": "50",
102
- "locationY": "0",
103
- "connector": { "targetReference": "Update_triggering_records" },
104
- "object": "Account",
105
- "recordTriggerType": "Create",
106
- "triggerType": "RecordBeforeSave"
107
- },
108
- "subtype": "start",
109
- "metaType": "node",
110
- "connectors": [
111
- {
112
- "element": { "targetReference": "Update_triggering_records" },
113
- "processed": false,
114
- "type": "connector",
115
- "reference": "Update_triggering_records"
116
- }
117
- ],
118
- "name": "flowstart",
119
- "locationX": "50",
120
- "locationY": "0"
121
- },
122
- { "element": "Draft", "subtype": "status", "metaType": "metadata" }
123
- ],
124
- "startReference": "Update_triggering_records",
125
- "triggerOrder": 10
126
- }
127
- }
128
- ]
@@ -1,102 +0,0 @@
1
- [
2
- {
3
- "flow": {
4
- "name": "Test_Flow_WaitConditions",
5
- "xmldata": {
6
- "@xmlns": "http://soap.sforce.com/2006/04/metadata",
7
- "apiVersion": "62.0",
8
- "label": "Test Flow Wait Conditions",
9
- "processType": "AutoLaunchedFlow",
10
- "waits": {
11
- "name": "Wait_For_Conditions",
12
- "label": "Wait For Conditions",
13
- "locationX": "176",
14
- "locationY": "287",
15
- "waitEvents": {
16
- "name": "myWaitEvent",
17
- "conditionLogic": "and",
18
- "conditions": {
19
- "leftValueReference": "myVariable_current.Status",
20
- "operator": "EqualTo",
21
- "rightValue": { "stringValue": "Completed" }
22
- }
23
- }
24
- },
25
- "start": {
26
- "locationX": "50",
27
- "locationY": "0",
28
- "connector": { "targetReference": "Wait_For_Conditions" },
29
- "triggerType": "RecordAfterSave",
30
- "object": "Account",
31
- "recordTriggerType": "Create"
32
- },
33
- "status": "Draft"
34
- },
35
- "label": "Test Flow Wait Conditions",
36
- "processType": "AutoLaunchedFlow",
37
- "start": {
38
- "locationX": "50",
39
- "locationY": "0",
40
- "connector": { "targetReference": "Wait_For_Conditions" },
41
- "triggerType": "RecordAfterSave",
42
- "object": "Account",
43
- "recordTriggerType": "Create"
44
- },
45
- "status": "Draft",
46
- "type": "AutoLaunchedFlow",
47
- "elements": [
48
- { "element": "62.0", "subtype": "apiVersion", "metaType": "metadata" },
49
- { "element": "Test Flow Wait Conditions", "subtype": "label", "metaType": "metadata" },
50
- { "element": "AutoLaunchedFlow", "subtype": "processType", "metaType": "metadata" },
51
- {
52
- "element": {
53
- "name": "Wait_For_Conditions",
54
- "label": "Wait For Conditions",
55
- "locationX": "176",
56
- "locationY": "287",
57
- "waitEvents": {
58
- "name": "myWaitEvent",
59
- "conditionLogic": "and",
60
- "conditions": {
61
- "leftValueReference": "myVariable_current.Status",
62
- "operator": "EqualTo",
63
- "rightValue": { "stringValue": "Completed" }
64
- }
65
- }
66
- },
67
- "subtype": "waits",
68
- "metaType": "node",
69
- "connectors": [],
70
- "name": "Wait_For_Conditions",
71
- "locationX": "176",
72
- "locationY": "287"
73
- },
74
- {
75
- "element": {
76
- "locationX": "50",
77
- "locationY": "0",
78
- "connector": { "targetReference": "Wait_For_Conditions" },
79
- "triggerType": "RecordAfterSave",
80
- "object": "Account",
81
- "recordTriggerType": "Create"
82
- },
83
- "subtype": "start",
84
- "metaType": "node",
85
- "connectors": [
86
- {
87
- "element": { "targetReference": "Wait_For_Conditions" },
88
- "processed": false,
89
- "type": "connector",
90
- "reference": "Wait_For_Conditions"
91
- }
92
- ],
93
- "name": "flowstart",
94
- "locationX": "50",
95
- "locationY": "0"
96
- },
97
- { "element": "Draft", "subtype": "status", "metaType": "metadata" }
98
- ],
99
- "startReference": "Wait_For_Conditions"
100
- }
101
- }
102
- ]
@@ -1,88 +0,0 @@
1
- [
2
- {
3
- "flow": {
4
- "name": "Test_Flow_WaitDate",
5
- "xmldata": {
6
- "@xmlns": "http://soap.sforce.com/2006/04/metadata",
7
- "apiVersion": "62.0",
8
- "label": "Test Flow WaitDate",
9
- "processType": "AutoLaunchedFlow",
10
- "waits": {
11
- "name": "Wait_Until_Date",
12
- "label": "Wait Until Date",
13
- "locationX": "176",
14
- "locationY": "287",
15
- "elementSubtype": "WaitDate",
16
- "dateTimeValue": "2025-12-31T00:00:00.000Z"
17
- },
18
- "start": {
19
- "locationX": "50",
20
- "locationY": "0",
21
- "connector": { "targetReference": "Wait_Until_Date" },
22
- "triggerType": "RecordAfterSave",
23
- "object": "Account",
24
- "recordTriggerType": "Create"
25
- },
26
- "status": "Draft"
27
- },
28
- "label": "Test Flow WaitDate",
29
- "processType": "AutoLaunchedFlow",
30
- "start": {
31
- "locationX": "50",
32
- "locationY": "0",
33
- "connector": { "targetReference": "Wait_Until_Date" },
34
- "triggerType": "RecordAfterSave",
35
- "object": "Account",
36
- "recordTriggerType": "Create"
37
- },
38
- "status": "Draft",
39
- "type": "AutoLaunchedFlow",
40
- "elements": [
41
- { "element": "62.0", "subtype": "apiVersion", "metaType": "metadata" },
42
- { "element": "Test Flow WaitDate", "subtype": "label", "metaType": "metadata" },
43
- { "element": "AutoLaunchedFlow", "subtype": "processType", "metaType": "metadata" },
44
- {
45
- "element": {
46
- "name": "Wait_Until_Date",
47
- "label": "Wait Until Date",
48
- "locationX": "176",
49
- "locationY": "287",
50
- "elementSubtype": "WaitDate",
51
- "dateTimeValue": "2025-12-31T00:00:00.000Z"
52
- },
53
- "subtype": "waits",
54
- "metaType": "node",
55
- "connectors": [],
56
- "name": "Wait_Until_Date",
57
- "locationX": "176",
58
- "locationY": "287"
59
- },
60
- {
61
- "element": {
62
- "locationX": "50",
63
- "locationY": "0",
64
- "connector": { "targetReference": "Wait_Until_Date" },
65
- "triggerType": "RecordAfterSave",
66
- "object": "Account",
67
- "recordTriggerType": "Create"
68
- },
69
- "subtype": "start",
70
- "metaType": "node",
71
- "connectors": [
72
- {
73
- "element": { "targetReference": "Wait_Until_Date" },
74
- "processed": false,
75
- "type": "connector",
76
- "reference": "Wait_Until_Date"
77
- }
78
- ],
79
- "name": "flowstart",
80
- "locationX": "50",
81
- "locationY": "0"
82
- },
83
- { "element": "Draft", "subtype": "status", "metaType": "metadata" }
84
- ],
85
- "startReference": "Wait_Until_Date"
86
- }
87
- }
88
- ]