Skip to content

Commit acaf9b6

Browse files
authored
Merge pull request #47 from Force-Config-Control/dependencyfixes
Dependency bumps and output improvements
2 parents 634cfac + 3a0ef5e commit acaf9b6

29 files changed

+566
-457
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lightning-flow-scanner-core",
3-
"version": "2.21.0",
3+
"version": "2.22.0",
44
"main": "out/**",
55
"types": "out/index.d.ts",
66
"scripts": {
@@ -9,7 +9,7 @@
99
},
1010
"keywords": [],
1111
"author": "Ruben",
12-
"license": "ISC",
12+
"license": "AGPL-3.0",
1313
"description": "",
1414
"dependencies": {
1515
"@types/chai": "^4.2.21",

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Lightning Flow Scanner(Rule Engine)
22

3-
##### _This the rule engine is used in both the [VSCode extension](https://marketplace.visualstudio.com/items?itemName=ForceConfigControl.lightningflowscanner&ssr=false#review-details) and the [SFDX plugin](https://www.npmjs.com/package/lightning-flow-scanner) of the same name._
3+
##### _This rule engine is used in both the [VS Code Extension](https://marketplace.visualstudio.com/items?itemName=ForceConfigControl.lightningflowscanner&ssr=false#review-details) and the [SFDX Plugin](https://www.npmjs.com/package/lightning-flow-scanner) of the same name._
44

55
## Rules
66

@@ -20,7 +20,7 @@ ___
2020

2121
### Old API version
2222

23-
Newer API components may cause older versions of Flows to start behaving incorrectly due to differences in the underlying mechanics. The Api Version has been available as an attribute on the Flow since API v50.0. It is recommended to limit variation between API versions and to maintain them on a regular basis.
23+
Newer API components may cause older versions of Flows to start behaving incorrectly due to differences in the underlying mechanics. The Api Version has been available as an attribute on the Flow Object since API v50.0. It is recommended to limit variation between API versions and to maintain them on a regular basis.
2424

2525
_Default Value: `>50.0`_
2626

src/index.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { FixFlows } from './main/libs/FixFlows';
44
import { GetRuleDefinitions } from './main/libs/GetRuleDefinitions';
55
import { ScanFlows } from './main/libs/ScanFlows';
66
import { Flow } from './main/models/Flow';
7-
import { FlowElement } from './main/models/FlowElement';
8-
import { FlowVariable } from './main/models/FlowVariable';
7+
import { ResultDetails } from './main/models/ResultDetails';
8+
import { RuleResult } from './main/models/RuleResult';
99
import { ScanResult } from './main/models/ScanResult';
1010

1111
export function getRules(ruleNames?: string[]): IRuleDefinition[] {
@@ -34,21 +34,14 @@ export function scan(flows: Flow[], ruleOptions?: IRulesConfig): ScanResult[] {
3434
for (const scanResult of scanResults) {
3535

3636
if (scanResult.flow.name === exceptionName) {
37-
for (const ruleResult of scanResult.ruleResults) {
37+
for (const ruleResult of scanResult.ruleResults as RuleResult[]) {
3838
if (exceptionElements[ruleResult.ruleName]) {
3939
const exceptions = exceptionElements[ruleResult.ruleName];
40-
if (ruleResult.details && typeof ruleResult.details === 'string') {
41-
if(exceptions.includes(ruleResult.details)){
42-
delete ruleResult.details;
43-
ruleResult.occurs = false;
44-
}
45-
} else {
46-
const filteredDetails = (ruleResult.details as (FlowVariable[] | FlowElement[])).filter((detail) => {
47-
return !exceptions.includes(detail.name);
48-
});
49-
ruleResult.details = filteredDetails;
50-
ruleResult.occurs = filteredDetails.length > 0;
51-
}
40+
const filteredDetails = (ruleResult.details as ResultDetails[]).filter((detail) => {
41+
return !exceptions.includes(detail.name);
42+
});
43+
ruleResult.details = filteredDetails;
44+
ruleResult.occurs = filteredDetails.length > 0;
5245
}
5346
}
5447
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {Flow} from '../models/Flow';
2-
import {RuleResult} from '../models/RuleResult';
1+
import { Flow } from '../models/Flow';
2+
import { RuleResult } from '../models/RuleResult';
33

44
export interface IRuleDefinition {
55
uri: string;
@@ -8,7 +8,9 @@ export interface IRuleDefinition {
88
description: string;
99
supportedTypes: string[];
1010
type: string;
11+
docRefs: { label: string, path: string }[];
12+
isConfigurable: boolean;
1113
severity?: string;
1214

13-
execute(flow: Flow, ruleOptions? : {}): RuleResult;
15+
execute(flow: Flow, ruleOptions?: {}): RuleResult;
1416
}

src/main/libs/FixFlows.ts

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1-
import {Flow} from '../models/Flow';
2-
import {FlowElement} from '../models/FlowElement';
3-
import {FlowVariable} from '../models/FlowVariable';
4-
import {RuleResult} from '../models/RuleResult';
5-
import {ScanResult} from '../models/ScanResult';
6-
import {UnconnectedElements} from '../rules/UnconnectedElements';
7-
import {UnusedVariables} from '../rules/UnusedVariables';
8-
import {BuildFlow} from './BuildFlow';
1+
import { Flow } from '../models/Flow';
2+
import { FlowNode } from '../models/FlowNode';
3+
import { FlowVariable } from '../models/FlowVariable';
4+
import { ResultDetails } from '../models/ResultDetails';
5+
import { RuleResult } from '../models/RuleResult';
6+
import { ScanResult } from '../models/ScanResult';
7+
import { UnconnectedElements } from '../rules/UnconnectedElements';
8+
import { UnusedVariables } from '../rules/UnusedVariables';
9+
import { BuildFlow } from './BuildFlow';
910

10-
export function FixFlows(flows: Flow[]) : ScanResult[] {
11+
export function FixFlows(flows: Flow[]): ScanResult[] {
1112

12-
const flowResults : ScanResult[] = [];
13+
const flowResults: ScanResult[] = [];
1314
for (const flow of flows) {
14-
const unconnectedElementsResult : RuleResult = new UnconnectedElements().execute(flow);
15-
const unusedVariablesResult : RuleResult = new UnusedVariables().execute(flow);
15+
const unconnectedElementsResult: RuleResult = new UnconnectedElements().execute(flow);
16+
const unusedVariablesResult: RuleResult = new UnusedVariables().execute(flow);
1617
const ruleResults: RuleResult[] = [unusedVariablesResult, unconnectedElementsResult];
17-
const unusedVariableReferences = unusedVariablesResult.details ? (unusedVariablesResult.details as FlowVariable[]).map(unusedVariable => unusedVariable.name) : [];
18-
const unconnectedElementsReferences = unconnectedElementsResult.details ? (unconnectedElementsResult.details as FlowElement[]).map(unconnectedElement => unconnectedElement.name) : [];
19-
const nodesToBuild = flow.nodes.filter(node => {
20-
switch (node.nodeType) {
21-
case 'variable':
22-
const nodeVar = node as FlowVariable;
23-
if (!unusedVariableReferences.includes(nodeVar.name)) {
24-
return node;
25-
}
26-
break;
27-
case 'element':
28-
const nodeElement = node as FlowElement;
29-
if (!unconnectedElementsReferences.includes(nodeElement.name)) {
30-
return node;
31-
}
32-
break;
33-
case 'metadata':
18+
const unusedVariableReferences = unusedVariablesResult.details ? (unusedVariablesResult.details as ResultDetails[]).map(unusedVariable => unusedVariable.name) : [];
19+
const unconnectedElementsReferences = unconnectedElementsResult.details ? (unconnectedElementsResult.details as ResultDetails[]).map(unconnectedElement => unconnectedElement.name) : [];
20+
const nodesToBuild = flow.elements.filter(node => {
21+
switch (node.metaType) {
22+
case 'variable':
23+
const nodeVar = node as FlowVariable;
24+
if (!unusedVariableReferences.includes(nodeVar.name)) {
3425
return node;
35-
}
26+
}
27+
break;
28+
case 'node':
29+
const nodeElement = node as FlowNode;
30+
if (!unconnectedElementsReferences.includes(nodeElement.name)) {
31+
return node;
32+
}
33+
break;
34+
case 'metadata':
35+
return node;
3636
}
37+
}
3738
);
3839
flow.xmldata = BuildFlow(nodesToBuild);
3940
flow.preProcessNodes();

src/main/models/Flow.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {FlowElement} from './FlowElement';
2-
import {FlowMetadata} from './FlowMetadata';
3-
import {FlowNode} from './FlowNode';
4-
import {FlowVariable} from './FlowVariable';
1+
import { FlowNode } from './FlowNode';
2+
import { FlowMetadata } from './FlowMetadata';
3+
import { FlowElement } from './FlowElement';
4+
import { FlowVariable } from './FlowVariable';
55
import * as p from 'path';
66

77
export class Flow {
@@ -19,15 +19,13 @@ export class Flow {
1919
public status?;
2020
public uri?;
2121
public root?;
22-
public nodes?: FlowNode[];
22+
public elements?: FlowElement[];
2323

2424
private flowVariables = [
2525
'choices',
2626
'constants',
2727
'dynamicChoiceSets',
2828
'formulas',
29-
'stages',
30-
'textTemplates',
3129
'variables'
3230
];
3331
private flowMetadata = [
@@ -38,10 +36,18 @@ export class Flow {
3836
'interviewLabel',
3937
'label',
4038
'status',
39+
'stages',
40+
'textTemplates',
4141
'runInMode',
4242
'startElementReference',
4343
'isTemplate',
44-
'fullName'
44+
'fullName',
45+
'timeZoneSidKey',
46+
'isAdditionalPermissionRequiredToRun',
47+
'migratedFromWorkflowRuleName',
48+
'triggerOrder',
49+
'Environments',
50+
'segment'
4551
];
4652
private flowNodes = [
4753
'actionCalls',
@@ -50,6 +56,7 @@ export class Flow {
5056
'collectionProcessors',
5157
'decisions',
5258
'loops',
59+
'orchestratedStages',
5360
'recordCreates',
5461
'recordDeletes',
5562
'recordLookups',
@@ -71,7 +78,7 @@ export class Flow {
7178
this.path = args.path;
7279
}
7380
let flowName = p.basename(p.basename(this.path), p.extname(this.path));
74-
if(flowName.includes('.')){
81+
if (flowName.includes('.')) {
7582
flowName = flowName.split('.')[0]
7683
}
7784
this.name = flowName;
@@ -89,7 +96,7 @@ export class Flow {
8996
this.status = this.xmldata.status;
9097
this.start = this.xmldata.start;
9198
this.type = this.xmldata.processType;
92-
const allNodes: (FlowVariable | FlowElement | FlowMetadata)[] = [];
99+
const allNodes: (FlowVariable | FlowNode | FlowMetadata)[] = [];
93100
for (const nodeType in this.xmldata) {
94101
const nodesOfType = this.xmldata[nodeType];
95102
// skip xmlns url
@@ -112,13 +119,13 @@ export class Flow {
112119
}
113120
} else if (this.flowNodes.includes(nodeType)) {
114121
for (const node of nodesOfType) {
115-
allNodes.push(
116-
new FlowElement(node.name, nodeType, node)
117-
);
122+
allNodes.push(
123+
new FlowNode(node.name, nodeType, node)
124+
);
118125
}
119126
}
120127
}
121-
this.nodes = allNodes;
128+
this.elements = allNodes;
122129
}
123130

124131
}

src/main/models/FlowAttribute.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export class FlowAttribute {
2+
3+
public name: string;
4+
public subtype: string;
5+
public expression: string;
6+
public metaType = 'attribute';
7+
8+
constructor(name: string, subtype: string, expression: string) {
9+
10+
this.name = name;
11+
this.subtype = subtype;
12+
this.expression = expression;
13+
}
14+
}

0 commit comments

Comments
 (0)