Skip to content

Commit

Permalink
Merge pull request #47 from Force-Config-Control/dependencyfixes
Browse files Browse the repository at this point in the history
Dependency bumps and output improvements
  • Loading branch information
RubenHalman authored Sep 6, 2023
2 parents 634cfac + 3a0ef5e commit acaf9b6
Show file tree
Hide file tree
Showing 29 changed files with 566 additions and 457 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lightning-flow-scanner-core",
"version": "2.21.0",
"version": "2.22.0",
"main": "out/**",
"types": "out/index.d.ts",
"scripts": {
Expand All @@ -9,7 +9,7 @@
},
"keywords": [],
"author": "Ruben",
"license": "ISC",
"license": "AGPL-3.0",
"description": "",
"dependencies": {
"@types/chai": "^4.2.21",
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Lightning Flow Scanner(Rule Engine)

##### _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._
##### _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._

## Rules

Expand All @@ -20,7 +20,7 @@ ___

### Old API version

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.
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.

_Default Value: `>50.0`_

Expand Down
23 changes: 8 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { FixFlows } from './main/libs/FixFlows';
import { GetRuleDefinitions } from './main/libs/GetRuleDefinitions';
import { ScanFlows } from './main/libs/ScanFlows';
import { Flow } from './main/models/Flow';
import { FlowElement } from './main/models/FlowElement';
import { FlowVariable } from './main/models/FlowVariable';
import { ResultDetails } from './main/models/ResultDetails';
import { RuleResult } from './main/models/RuleResult';
import { ScanResult } from './main/models/ScanResult';

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

if (scanResult.flow.name === exceptionName) {
for (const ruleResult of scanResult.ruleResults) {
for (const ruleResult of scanResult.ruleResults as RuleResult[]) {
if (exceptionElements[ruleResult.ruleName]) {
const exceptions = exceptionElements[ruleResult.ruleName];
if (ruleResult.details && typeof ruleResult.details === 'string') {
if(exceptions.includes(ruleResult.details)){
delete ruleResult.details;
ruleResult.occurs = false;
}
} else {
const filteredDetails = (ruleResult.details as (FlowVariable[] | FlowElement[])).filter((detail) => {
return !exceptions.includes(detail.name);
});
ruleResult.details = filteredDetails;
ruleResult.occurs = filteredDetails.length > 0;
}
const filteredDetails = (ruleResult.details as ResultDetails[]).filter((detail) => {
return !exceptions.includes(detail.name);
});
ruleResult.details = filteredDetails;
ruleResult.occurs = filteredDetails.length > 0;
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/interfaces/IRuleDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Flow} from '../models/Flow';
import {RuleResult} from '../models/RuleResult';
import { Flow } from '../models/Flow';
import { RuleResult } from '../models/RuleResult';

export interface IRuleDefinition {
uri: string;
Expand All @@ -8,7 +8,9 @@ export interface IRuleDefinition {
description: string;
supportedTypes: string[];
type: string;
docRefs: { label: string, path: string }[];
isConfigurable: boolean;
severity?: string;

execute(flow: Flow, ruleOptions? : {}): RuleResult;
execute(flow: Flow, ruleOptions?: {}): RuleResult;
}
61 changes: 31 additions & 30 deletions src/main/libs/FixFlows.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
import {Flow} from '../models/Flow';
import {FlowElement} from '../models/FlowElement';
import {FlowVariable} from '../models/FlowVariable';
import {RuleResult} from '../models/RuleResult';
import {ScanResult} from '../models/ScanResult';
import {UnconnectedElements} from '../rules/UnconnectedElements';
import {UnusedVariables} from '../rules/UnusedVariables';
import {BuildFlow} from './BuildFlow';
import { Flow } from '../models/Flow';
import { FlowNode } from '../models/FlowNode';
import { FlowVariable } from '../models/FlowVariable';
import { ResultDetails } from '../models/ResultDetails';
import { RuleResult } from '../models/RuleResult';
import { ScanResult } from '../models/ScanResult';
import { UnconnectedElements } from '../rules/UnconnectedElements';
import { UnusedVariables } from '../rules/UnusedVariables';
import { BuildFlow } from './BuildFlow';

export function FixFlows(flows: Flow[]) : ScanResult[] {
export function FixFlows(flows: Flow[]): ScanResult[] {

const flowResults : ScanResult[] = [];
const flowResults: ScanResult[] = [];
for (const flow of flows) {
const unconnectedElementsResult : RuleResult = new UnconnectedElements().execute(flow);
const unusedVariablesResult : RuleResult = new UnusedVariables().execute(flow);
const unconnectedElementsResult: RuleResult = new UnconnectedElements().execute(flow);
const unusedVariablesResult: RuleResult = new UnusedVariables().execute(flow);
const ruleResults: RuleResult[] = [unusedVariablesResult, unconnectedElementsResult];
const unusedVariableReferences = unusedVariablesResult.details ? (unusedVariablesResult.details as FlowVariable[]).map(unusedVariable => unusedVariable.name) : [];
const unconnectedElementsReferences = unconnectedElementsResult.details ? (unconnectedElementsResult.details as FlowElement[]).map(unconnectedElement => unconnectedElement.name) : [];
const nodesToBuild = flow.nodes.filter(node => {
switch (node.nodeType) {
case 'variable':
const nodeVar = node as FlowVariable;
if (!unusedVariableReferences.includes(nodeVar.name)) {
return node;
}
break;
case 'element':
const nodeElement = node as FlowElement;
if (!unconnectedElementsReferences.includes(nodeElement.name)) {
return node;
}
break;
case 'metadata':
const unusedVariableReferences = unusedVariablesResult.details ? (unusedVariablesResult.details as ResultDetails[]).map(unusedVariable => unusedVariable.name) : [];
const unconnectedElementsReferences = unconnectedElementsResult.details ? (unconnectedElementsResult.details as ResultDetails[]).map(unconnectedElement => unconnectedElement.name) : [];
const nodesToBuild = flow.elements.filter(node => {
switch (node.metaType) {
case 'variable':
const nodeVar = node as FlowVariable;
if (!unusedVariableReferences.includes(nodeVar.name)) {
return node;
}
}
break;
case 'node':
const nodeElement = node as FlowNode;
if (!unconnectedElementsReferences.includes(nodeElement.name)) {
return node;
}
break;
case 'metadata':
return node;
}
}
);
flow.xmldata = BuildFlow(nodesToBuild);
flow.preProcessNodes();
Expand Down
35 changes: 21 additions & 14 deletions src/main/models/Flow.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {FlowElement} from './FlowElement';
import {FlowMetadata} from './FlowMetadata';
import {FlowNode} from './FlowNode';
import {FlowVariable} from './FlowVariable';
import { FlowNode } from './FlowNode';
import { FlowMetadata } from './FlowMetadata';
import { FlowElement } from './FlowElement';
import { FlowVariable } from './FlowVariable';
import * as p from 'path';

export class Flow {
Expand All @@ -19,15 +19,13 @@ export class Flow {
public status?;
public uri?;
public root?;
public nodes?: FlowNode[];
public elements?: FlowElement[];

private flowVariables = [
'choices',
'constants',
'dynamicChoiceSets',
'formulas',
'stages',
'textTemplates',
'variables'
];
private flowMetadata = [
Expand All @@ -38,10 +36,18 @@ export class Flow {
'interviewLabel',
'label',
'status',
'stages',
'textTemplates',
'runInMode',
'startElementReference',
'isTemplate',
'fullName'
'fullName',
'timeZoneSidKey',
'isAdditionalPermissionRequiredToRun',
'migratedFromWorkflowRuleName',
'triggerOrder',
'Environments',
'segment'
];
private flowNodes = [
'actionCalls',
Expand All @@ -50,6 +56,7 @@ export class Flow {
'collectionProcessors',
'decisions',
'loops',
'orchestratedStages',
'recordCreates',
'recordDeletes',
'recordLookups',
Expand All @@ -71,7 +78,7 @@ export class Flow {
this.path = args.path;
}
let flowName = p.basename(p.basename(this.path), p.extname(this.path));
if(flowName.includes('.')){
if (flowName.includes('.')) {
flowName = flowName.split('.')[0]
}
this.name = flowName;
Expand All @@ -89,7 +96,7 @@ export class Flow {
this.status = this.xmldata.status;
this.start = this.xmldata.start;
this.type = this.xmldata.processType;
const allNodes: (FlowVariable | FlowElement | FlowMetadata)[] = [];
const allNodes: (FlowVariable | FlowNode | FlowMetadata)[] = [];
for (const nodeType in this.xmldata) {
const nodesOfType = this.xmldata[nodeType];
// skip xmlns url
Expand All @@ -112,13 +119,13 @@ export class Flow {
}
} else if (this.flowNodes.includes(nodeType)) {
for (const node of nodesOfType) {
allNodes.push(
new FlowElement(node.name, nodeType, node)
);
allNodes.push(
new FlowNode(node.name, nodeType, node)
);
}
}
}
this.nodes = allNodes;
this.elements = allNodes;
}

}
14 changes: 14 additions & 0 deletions src/main/models/FlowAttribute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export class FlowAttribute {

public name: string;
public subtype: string;
public expression: string;
public metaType = 'attribute';

constructor(name: string, subtype: string, expression: string) {

this.name = name;
this.subtype = subtype;
this.expression = expression;
}
}
Loading

0 comments on commit acaf9b6

Please sign in to comment.