@xliic/cicd-core-node
Advanced tools
Comparing version 1.1.2 to 1.2.0
136
lib/api.js
@@ -45,15 +45,25 @@ "use strict"; | ||
} | ||
function gotOptions(method, options) { | ||
const logRequest = (response, retryWithMergedOptions) => { | ||
options.logger.debug(`${method} ${response.url} ${response.statusCode}`); | ||
return response; | ||
}; | ||
return { | ||
method, | ||
prefixUrl: options.platformUrl, | ||
responseType: "json", | ||
headers: { | ||
Accept: "application/json", | ||
"X-API-KEY": options.apiToken, | ||
"User-Agent": options.userAgent, | ||
Referer: options.referer, | ||
}, | ||
hooks: { | ||
afterResponse: [logRequest], | ||
}, | ||
}; | ||
} | ||
function listApis(collectionId, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { body } = yield got_1.default(`api/v1/collections/${collectionId}/apis`, { | ||
prefixUrl: options.platformUrl, | ||
method: "GET", | ||
responseType: "json", | ||
headers: { | ||
Accept: "application/json", | ||
"X-API-KEY": options.apiToken, | ||
"User-Agent": options.userAgent, | ||
Referer: options.referer, | ||
}, | ||
}); | ||
const { body } = yield got_1.default(`api/v1/collections/${collectionId}/apis`, gotOptions("GET", options)); | ||
return body; | ||
@@ -65,13 +75,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { body } = yield got_1.default("api/v1/collections", { | ||
prefixUrl: options.platformUrl, | ||
method: "GET", | ||
responseType: "json", | ||
headers: { | ||
Accept: "application/json", | ||
"X-API-KEY": options.apiToken, | ||
"User-Agent": options.userAgent, | ||
Referer: options.referer, | ||
}, | ||
}); | ||
const { body } = yield got_1.default("api/v1/collections", gotOptions("GET", options)); | ||
return body; | ||
@@ -83,15 +83,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const log = options.logger; | ||
log.debug(`Delete API ID: ${apiId}`); | ||
const { body } = yield got_1.default(`api/v1/apis/${apiId}`, { | ||
prefixUrl: options.platformUrl, | ||
method: "DELETE", | ||
responseType: "json", | ||
headers: { | ||
Accept: "application/json", | ||
"X-API-KEY": options.apiToken, | ||
"User-Agent": options.userAgent, | ||
Referer: options.referer, | ||
}, | ||
}); | ||
const { body } = yield got_1.default(`api/v1/apis/${apiId}`, gotOptions("DELETE", options)); | ||
return body; | ||
@@ -103,4 +91,2 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const log = options.logger; | ||
log.debug(`Create API name: ${name} collection ID: ${collectionId}`); | ||
const form = new FormData(); | ||
@@ -114,14 +100,3 @@ form.append("specfile", contents.toString("utf-8"), { | ||
try { | ||
const { body } = yield got_1.default("api/v1/apis", { | ||
prefixUrl: options.platformUrl, | ||
method: "POST", | ||
body: form, | ||
responseType: "json", | ||
headers: { | ||
Accept: "application/json", | ||
"X-API-KEY": options.apiToken, | ||
"User-Agent": options.userAgent, | ||
Referer: options.referer, | ||
}, | ||
}); | ||
const { body } = yield got_1.default("api/v1/apis", Object.assign(Object.assign({}, gotOptions("POST", options)), { body: form })); | ||
return { | ||
@@ -141,16 +116,6 @@ id: body.desc.id, | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const log = options.logger; | ||
log.debug(`Read API ID: ${apiId}`); | ||
const { body } = yield got_1.default(`api/v1/apis/${apiId}`, { | ||
prefixUrl: options.platformUrl, | ||
method: "GET", | ||
responseType: "json", | ||
headers: { | ||
Accept: "application/json", | ||
"X-API-KEY": options.apiToken, | ||
"User-Agent": options.userAgent, | ||
Referer: options.referer, | ||
}, | ||
}); | ||
const lastAssessment = ((_a = body === null || body === void 0 ? void 0 : body.assessment) === null || _a === void 0 ? void 0 : _a.last) ? new Date(body.assessment.last) : new Date(0); | ||
const { body } = (yield got_1.default(`api/v1/apis/${apiId}`, gotOptions("GET", options))); | ||
const lastAssessment = ((_a = body === null || body === void 0 ? void 0 : body.assessment) === null || _a === void 0 ? void 0 : _a.last) | ||
? new Date(body.assessment.last) | ||
: new Date(0); | ||
const isProcessed = body.assessment.isProcessed; | ||
@@ -166,18 +131,5 @@ return { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const log = options.logger; | ||
log.debug(`Update API ID: ${apiId}`); | ||
try { | ||
const previousStatus = yield readApiStatus(apiId, options); | ||
const { body } = yield got_1.default(`api/v1/apis/${apiId}`, { | ||
prefixUrl: options.platformUrl, | ||
method: "PUT", | ||
json: { specfile: contents.toString("base64") }, | ||
responseType: "json", | ||
headers: { | ||
Accept: "application/json", | ||
"X-API-KEY": options.apiToken, | ||
"User-Agent": options.userAgent, | ||
Referer: options.referer, | ||
}, | ||
}); | ||
const { body } = yield got_1.default(`api/v1/apis/${apiId}`, Object.assign(Object.assign({}, gotOptions("PUT", options)), { json: { specfile: contents.toString("base64") } })); | ||
return { | ||
@@ -196,16 +148,3 @@ id: body.desc.id, | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const log = options.logger; | ||
log.debug(`Create collection: ${name}`); | ||
const { body } = yield got_1.default("api/v1/collections", { | ||
prefixUrl: options.platformUrl, | ||
method: "POST", | ||
json: { name, isShared: false }, | ||
responseType: "json", | ||
headers: { | ||
Accept: "application/json", | ||
"X-API-KEY": options.apiToken, | ||
"User-Agent": options.userAgent, | ||
Referer: options.referer, | ||
}, | ||
}); | ||
const { body } = yield got_1.default("api/v1/collections", Object.assign(Object.assign({}, gotOptions("POST", options)), { json: { name, isShared: false } })); | ||
return body; | ||
@@ -224,15 +163,6 @@ }); | ||
const ready = status.isProcessed && | ||
status.lastAssessment.getTime() > api.previousStatus.lastAssessment.getTime(); | ||
status.lastAssessment.getTime() > | ||
api.previousStatus.lastAssessment.getTime(); | ||
if (ready) { | ||
const { body } = yield got_1.default(`api/v1/apis/${api.id}/assessmentreport`, { | ||
prefixUrl: options.platformUrl, | ||
method: "GET", | ||
responseType: "json", | ||
headers: { | ||
Accept: "application/json", | ||
"X-API-KEY": options.apiToken, | ||
"User-Agent": options.userAgent, | ||
Referer: options.referer, | ||
}, | ||
}); | ||
const { body } = (yield got_1.default(`api/v1/apis/${api.id}/assessmentreport`, gotOptions("GET", options))); | ||
const report = JSON.parse(Buffer.from(body.data, "base64").toString("utf8")); | ||
@@ -239,0 +169,0 @@ return report; |
@@ -74,3 +74,3 @@ "use strict"; | ||
} | ||
throw new Error(`Cannot find entry for pointer: ${pointer}`); | ||
throw new Error(`Cannot find entry for pointer: "${pointer}"`); | ||
}); | ||
@@ -123,21 +123,26 @@ } | ||
for (const subIssue of issue.issues) { | ||
const pointer = jsonPointerIndex[subIssue.pointer]; | ||
const [file, line, node] = yield findIssueLocation(filename, mapping, pointer); | ||
const criticality = issue.criticality | ||
? issue.criticality | ||
: defaultCriticality; | ||
result.push({ | ||
id, | ||
description: subIssue.specificDescription | ||
? subIssue.specificDescription | ||
: issue.description, | ||
pointer: pointer, | ||
file, | ||
line, | ||
range: node.getRange(), | ||
score: subIssue.score ? Math.abs(subIssue.score) : 0, | ||
displayScore: transformScore(subIssue.score ? subIssue.score : 0), | ||
criticality, | ||
severity: criticalityToSeverity[criticality], | ||
}); | ||
try { | ||
const pointer = jsonPointerIndex[subIssue.pointer]; | ||
const [file, line, node] = yield findIssueLocation(filename, mapping, pointer); | ||
const criticality = issue.criticality | ||
? issue.criticality | ||
: defaultCriticality; | ||
result.push({ | ||
id, | ||
description: subIssue.specificDescription | ||
? subIssue.specificDescription | ||
: issue.description, | ||
pointer: pointer, | ||
file, | ||
line, | ||
range: node.getRange(), | ||
score: subIssue.score ? Math.abs(subIssue.score) : 0, | ||
displayScore: transformScore(subIssue.score ? subIssue.score : 0), | ||
criticality, | ||
severity: criticalityToSeverity[criticality], | ||
}); | ||
} | ||
catch (ex) { | ||
throw new Error(`Error processing issue "${id}" in ${filename}: ${ex}`); | ||
} | ||
} | ||
@@ -144,0 +149,0 @@ } |
@@ -119,2 +119,5 @@ "use strict"; | ||
} | ||
if (!(current === null || current === void 0 ? void 0 : current.value)) { | ||
return null; | ||
} | ||
const { file, hash } = current.value; | ||
@@ -121,0 +124,0 @@ if (i < path.length) { |
{ | ||
"name": "@xliic/cicd-core-node", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Performs API contract security audit to get a detailed analysis of the possible vulnerabilities and other issues in the API contract.", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": ["lib/**/*"], | ||
"scripts": { | ||
"prepare": "npm run compile", | ||
"test": "ava", | ||
"compile": "tsc -b" | ||
"test": "jest", | ||
"compile": "tsc" | ||
}, | ||
@@ -18,10 +19,2 @@ "repository": { | ||
"license": "AGPL-3.0-only", | ||
"ava": { | ||
"nodeArguments": [ | ||
"--experimental-modules" | ||
], | ||
"require": [ | ||
"esm" | ||
] | ||
}, | ||
"dependencies": { | ||
@@ -39,8 +32,9 @@ "@xliic/json-schema-ref-parser": "^9.1.6", | ||
"@types/got": "^9.6.11", | ||
"@types/jest": "^26.0.20", | ||
"@types/node": "^14.14.21", | ||
"ava": "^3.12.1", | ||
"esm": "^3.2.25", | ||
"jest": "^26.6.3", | ||
"json-schema": "^0.3.0", | ||
"ts-jest": "^26.5.2", | ||
"typescript": "^4.1.3" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92033
7
22
1358