npm-audit-pipeline
Version:
Using npm audit in deployment pipelines
59 lines (58 loc) • 2.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleExecResponse = exports.handleExecYarnResponse = void 0;
var E = require("fp-ts/Either");
var function_1 = require("fp-ts/lib/function");
var t = require("io-ts");
var PathReporter_1 = require("io-ts/lib/PathReporter");
var errors_1 = require("./errors");
var NpmAuditResponseRaw = t.exact(t.type({
metadata: t.exact(t.type({
vulnerabilities: t.exact(t.type({
info: t.number,
low: t.number,
moderate: t.number,
high: t.number,
critical: t.number,
})),
})),
}));
var YarnAuditResponseRaw = t.exact(t.type({
data: t.exact(t.type({
vulnerabilities: t.exact(t.type({
info: t.number,
low: t.number,
moderate: t.number,
high: t.number,
critical: t.number,
})),
})),
}));
var handleExecYarnResponse = function (_a) {
var stderr = _a.stderr, stdout = _a.stdout;
return !stderr || (stderr && stdout)
? (0, function_1.pipe)(stdout, JSON.parse, // TODO: trycatch this
YarnAuditResponseRaw.decode, E.mapLeft(function (e) { return new Error(PathReporter_1.PathReporter.report(E.left(e)).join('\n')); }), E.map(function (x) { return ({
info: x.data.vulnerabilities.info,
low: x.data.vulnerabilities.low,
moderate: x.data.vulnerabilities.moderate,
high: x.data.vulnerabilities.high,
critical: x.data.vulnerabilities.critical,
}); }))
: E.left(new errors_1.NpmResponseError('npm audit returned an error', stderr));
};
exports.handleExecYarnResponse = handleExecYarnResponse;
var handleExecResponse = function (_a) {
var stderr = _a.stderr, stdout = _a.stdout;
return !stderr
? (0, function_1.pipe)(stdout, JSON.parse, // TODO: trycatch this
NpmAuditResponseRaw.decode, E.mapLeft(function (e) { return new Error(PathReporter_1.PathReporter.report(E.left(e)).join('\n')); }), E.map(function (x) { return ({
info: x.metadata.vulnerabilities.info,
low: x.metadata.vulnerabilities.low,
moderate: x.metadata.vulnerabilities.moderate,
high: x.metadata.vulnerabilities.high,
critical: x.metadata.vulnerabilities.critical,
}); }))
: E.left(new errors_1.NpmResponseError('npm audit returned an error', stderr));
};
exports.handleExecResponse = handleExecResponse;