@flow-scanner/lightning-flow-scanner-core
Version:
A lightweight engine for Flow metadata in Node.js, and browser environments. Assess and enhance Salesforce Flow automations for best practices, security, governor limits, and performance issues.
112 lines (111 loc) • 3.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "parse", {
enumerable: true,
get: function() {
return parse;
}
});
const _fastxmlparser = require("fast-xml-parser");
const _fs = require("fs");
const _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
const _Flow = require("../models/Flow");
const _ParsedFlow = require("../models/ParsedFlow");
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _async_to_generator(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
function parse(selectedUris) {
return _async_to_generator(function*() {
const parseResults = [];
const parser = new _fastxmlparser.XMLParser({
attributeNamePrefix: "@_",
ignoreAttributes: false,
// @ts-expect-error type issue
ignoreNameSpace: false,
parseTagValue: false,
textNodeName: "#text"
});
for (const uri of selectedUris){
try {
const normalizedURI = _path.normalize(uri);
const content = yield _fs.promises.readFile(normalizedURI, "utf8");
const parsed = parser.parse(content);
const flowObj = parsed.Flow;
parseResults.push(new _ParsedFlow.ParsedFlow(uri, new _Flow.Flow(uri, flowObj)));
} catch (e) {
var _e_message;
parseResults.push(new _ParsedFlow.ParsedFlow(uri, undefined, (_e_message = e.message) !== null && _e_message !== void 0 ? _e_message : e.toString()));
}
}
return parseResults;
})();
}