n8n-nodes-base
Version:
Base nodes of n8n
44 lines • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.scorecardApiRequest = scorecardApiRequest;
exports.simplify = simplify;
const n8n_workflow_1 = require("n8n-workflow");
async function scorecardApiRequest(method, resource, body = {}, query = {}, uri, option = {}) {
const credentials = await this.getCredentials('securityScorecardApi');
const headerWithAuthentication = { Authorization: `Token ${credentials.apiKey}` };
let options = {
headers: headerWithAuthentication,
method,
qs: query,
uri: uri || `https://api.securityscorecard.io/${resource}`,
body,
json: true,
};
if (Object.keys(option).length !== 0) {
options = Object.assign({}, options, option);
}
if (Object.keys(body).length === 0) {
delete options.body;
}
if (Object.keys(query).length === 0) {
delete options.qs;
}
try {
return await this.helpers.request(options);
}
catch (error) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
}
}
function simplify(data) {
const results = [];
for (const record of data) {
const newRecord = { date: record.date };
for (const factor of record.factors) {
newRecord[factor.name] = factor.score;
}
results.push(newRecord);
}
return results;
}
//# sourceMappingURL=GenericFunctions.js.map