@mimik/api-helper 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -2
- package/lib/extract-helper.js +5 -5
- package/lib/securityHandlers.js +4 -3
- package/package.json +20 -18
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@ const { OpenAPIBackend } = require('openapi-backend');
|
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const pathLib = require('path');
|
|
4
4
|
const yaml = require('js-yaml');
|
|
5
|
-
const
|
|
5
|
+
const compact = require('lodash.compact');
|
|
6
6
|
const SwaggerClient = require('swagger-client');
|
|
7
7
|
const { Base64 } = require('js-base64');
|
|
8
8
|
|
|
@@ -421,7 +421,7 @@ const extractProperties = (apiDefinition, controllersDirectory, buildDirectory,
|
|
|
421
421
|
*/
|
|
422
422
|
const setupServerFiles = (apiFilename, controllersDirectory, buildDirectory, correlationId, options) => getAPIFile(apiFilename, correlationId, options)
|
|
423
423
|
.then((apiDefinition) => {
|
|
424
|
-
const existingSecuritySchemes =
|
|
424
|
+
const existingSecuritySchemes = compact(validateSecuritySchemes(apiDefinition, correlationId));
|
|
425
425
|
|
|
426
426
|
extractProperties(apiDefinition, controllersDirectory, buildDirectory, correlationId);
|
|
427
427
|
return { apiDefinition, apiFilename, existingSecuritySchemes };
|
package/lib/extract-helper.js
CHANGED
|
@@ -33,17 +33,17 @@ const saveProperties = (extractResult, buildDirectory, controllersDirectoryName,
|
|
|
33
33
|
controllers.forEach((controller) => {
|
|
34
34
|
itemToSave = '';
|
|
35
35
|
extractResult[controller].forEach((operationId) => {
|
|
36
|
-
itemToSave
|
|
36
|
+
itemToSave += ` ${operationId},\n`;
|
|
37
37
|
operationIds.push(operationId);
|
|
38
38
|
});
|
|
39
|
-
stringToSave
|
|
39
|
+
stringToSave += `const {\n${itemToSave}} = require('../${controllersDirectoryName}/${controller}');\n`;
|
|
40
40
|
});
|
|
41
|
-
stringToSave
|
|
41
|
+
stringToSave += '\nmodule.exports = {\n';
|
|
42
42
|
itemToSave = '';
|
|
43
43
|
operationIds.forEach((operationId) => {
|
|
44
|
-
itemToSave
|
|
44
|
+
itemToSave += ` ${operationId},\n`;
|
|
45
45
|
});
|
|
46
|
-
stringToSave
|
|
46
|
+
stringToSave += `${itemToSave}};\n`;
|
|
47
47
|
logger.info(`creating ${filename}`, { filename }, correlationId);
|
|
48
48
|
try {
|
|
49
49
|
fs.writeFileSync(filename, stringToSave);
|
package/lib/securityHandlers.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const jwt = require('jsonwebtoken');
|
|
2
|
-
const
|
|
2
|
+
const intersection = require('lodash.intersection');
|
|
3
|
+
const difference = require('lodash.difference');
|
|
3
4
|
|
|
4
5
|
const { TOKEN_PARAMS } = require('@mimik/swagger-helper');
|
|
5
6
|
const {
|
|
@@ -109,10 +110,10 @@ const checkScopes = (tokenScopes, defScopes, definition) => {
|
|
|
109
110
|
}
|
|
110
111
|
const includedClaims = analyzedScope[1].split(CLAIMS_SEPARATOR);
|
|
111
112
|
const definitionClaims = Object.keys(includedDefinition);
|
|
112
|
-
const claimsIntersects =
|
|
113
|
+
const claimsIntersects = intersection(includedClaims, definitionClaims);
|
|
113
114
|
|
|
114
115
|
if (claimsIntersects.length !== includedClaims.length) {
|
|
115
|
-
throw getError(`incorrect claims included: ${
|
|
116
|
+
throw getError(`incorrect claims included: ${difference(includedClaims, claimsIntersects)}`, 403);
|
|
116
117
|
}
|
|
117
118
|
claims = claims.concat(claimsIntersects);
|
|
118
119
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/api-helper",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "helper for openAPI backend and mimik service",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,27 +30,29 @@
|
|
|
30
30
|
"url": "https://bitbucket.org/mimiktech/api-helper"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@mimik/request-helper":"^1.7.
|
|
34
|
-
"@mimik/request-retry": "^3.0.
|
|
35
|
-
"@mimik/response-helper": "^3.0.
|
|
36
|
-
"@mimik/sumologic-winston-logger": "^1.6.
|
|
37
|
-
"@mimik/swagger-helper": "^4.0.
|
|
38
|
-
"ajv-formats": "
|
|
33
|
+
"@mimik/request-helper":"^1.7.10",
|
|
34
|
+
"@mimik/request-retry": "^3.0.1",
|
|
35
|
+
"@mimik/response-helper": "^3.0.1",
|
|
36
|
+
"@mimik/sumologic-winston-logger": "^1.6.20",
|
|
37
|
+
"@mimik/swagger-helper": "^4.0.9",
|
|
38
|
+
"ajv-formats": "3.0.0-rc.0",
|
|
39
39
|
"js-base64": "3.7.5",
|
|
40
|
-
"js-yaml":"
|
|
41
|
-
"jsonwebtoken": "
|
|
42
|
-
"lodash": "
|
|
43
|
-
"
|
|
44
|
-
"
|
|
40
|
+
"js-yaml":"4.1.0",
|
|
41
|
+
"jsonwebtoken": "9.0.2",
|
|
42
|
+
"lodash.compact": "3.0.1",
|
|
43
|
+
"lodash.difference": "4.5.0",
|
|
44
|
+
"lodash.intersection": "4.4.0",
|
|
45
|
+
"openapi-backend": "5.10.5",
|
|
46
|
+
"swagger-client": "3.24.5"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
|
-
"@mimik/eslint-plugin-dependencies": "^2.4.
|
|
48
|
-
"@mimik/eslint-plugin-document-env": "^1.0.
|
|
49
|
-
"eslint": "8.
|
|
49
|
+
"@mimik/eslint-plugin-dependencies": "^2.4.6",
|
|
50
|
+
"@mimik/eslint-plugin-document-env": "^1.0.6",
|
|
51
|
+
"eslint": "8.55.0",
|
|
50
52
|
"eslint-config-airbnb": "19.0.4",
|
|
51
|
-
"eslint-plugin-import": "2.
|
|
52
|
-
"eslint-plugin-jsx-a11y": "6.
|
|
53
|
-
"eslint-plugin-react": "7.
|
|
53
|
+
"eslint-plugin-import": "2.29.0",
|
|
54
|
+
"eslint-plugin-jsx-a11y": "6.8.0",
|
|
55
|
+
"eslint-plugin-react": "7.33.2",
|
|
54
56
|
"eslint-plugin-react-hooks": "4.6.0",
|
|
55
57
|
"husky": "8.0.3",
|
|
56
58
|
"jsdoc-to-markdown": "8.0.0"
|