@mimik/api-helper 2.0.8 → 2.0.9
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/README.md +2 -2
- package/index.js +3 -7
- package/lib/securityHandlers.js +2 -4
- package/package.json +1 -4
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ If the secOptions contains unused security schemes, an error is generated.
|
|
|
41
41
|
|
|
42
42
|
The default formats for validation are: `date`, `time`, `date-time`, `byte`, `uuid`, `uri`, `email`, `ipv4`, `ipv6`, `semver`, `ip`.
|
|
43
43
|
|
|
44
|
-
**Requires**: <code>module:@mimik/response-helper</code>, <code>module:@mimik/sumologic-winston-logger</code>, <code>module:
|
|
44
|
+
**Requires**: <code>module:@mimik/response-helper</code>, <code>module:@mimik/sumologic-winston-logger</code>, <code>module:openapi-backend</code>
|
|
45
45
|
|
|
46
46
|
| Param | Type | Description |
|
|
47
47
|
| --- | --- | --- |
|
|
@@ -121,7 +121,7 @@ This function is used to setup the following security handlers for the API:
|
|
|
121
121
|
- `ApiKeySecurity` - used for the API key operations, like /apikey,
|
|
122
122
|
The security handlers are used to validate the tokens and scopes for the API operations.
|
|
123
123
|
**Category**: sync
|
|
124
|
-
**Requires**: <code>module:@mimik/swagger-helper</code>, <code>module:jsonwebtoken</code
|
|
124
|
+
**Requires**: <code>module:@mimik/swagger-helper</code>, <code>module:jsonwebtoken</code>
|
|
125
125
|
|
|
126
126
|
| Param | Type | Description |
|
|
127
127
|
| --- | --- | --- |
|
package/index.js
CHANGED
|
@@ -30,8 +30,6 @@ import { OpenAPIBackend } from 'openapi-backend';
|
|
|
30
30
|
import SwaggerClient from 'swagger-client';
|
|
31
31
|
import { ajvFormats } from './lib/ajvHelpers.js';
|
|
32
32
|
import baseHandlers from './lib/baseHandlers.js';
|
|
33
|
-
import compact from 'lodash.compact';
|
|
34
|
-
import difference from 'lodash.difference';
|
|
35
33
|
import fs from 'fs';
|
|
36
34
|
import { getRichError } from '@mimik/response-helper';
|
|
37
35
|
import { load } from 'js-yaml';
|
|
@@ -62,7 +60,6 @@ const POSTFIX_INDEX = 3;
|
|
|
62
60
|
* @category sync
|
|
63
61
|
* @requires @mimik/swagger-helper
|
|
64
62
|
* @requires jsonwebtoken
|
|
65
|
-
* @requires lodash
|
|
66
63
|
* @param {object} config - Configuration of the service.
|
|
67
64
|
* @return {object} An object containing `SystemSecurity`, `AdminSecurity`, `UserSecurity`, and `ApiKeySecurity` handlers.
|
|
68
65
|
*
|
|
@@ -83,7 +80,6 @@ export { securityLib };
|
|
|
83
80
|
* @category async
|
|
84
81
|
* @requires @mimik/response-helper
|
|
85
82
|
* @requires @mimik/sumologic-winston-logger
|
|
86
|
-
* @requires lodash.difference
|
|
87
83
|
* @requires openapi-backend
|
|
88
84
|
* @param {object} setup - Object containing the apiFilename and the existing security schemes in the API definition.
|
|
89
85
|
* @param {object} registeredOperations - List of the operation to register for the API.
|
|
@@ -147,11 +143,11 @@ export const apiSetup = (setup, registeredOperations, securityHandlers, extraFor
|
|
|
147
143
|
registerDefault(ADMIN_SECURITY, AdminSecurity[mode]);
|
|
148
144
|
registerDefault(USER_SECURITY, UserSecurity[mode]);
|
|
149
145
|
registerDefault(API_KEY_SECURITY, ApiKeySecurity[mode]);
|
|
150
|
-
const remainingSecurities =
|
|
146
|
+
const remainingSecurities = definedSecuritySchemes.filter(sec => !appliedSecurities.includes(sec));
|
|
151
147
|
|
|
152
148
|
if (securityHandlers) {
|
|
153
149
|
const securityHandlerNames = Object.keys(securityHandlers);
|
|
154
|
-
const unusedSecuritySchemes =
|
|
150
|
+
const unusedSecuritySchemes = securityHandlerNames.filter(sec => !definedSecuritySchemes.includes(sec));
|
|
155
151
|
|
|
156
152
|
if (unusedSecuritySchemes.length !== EMPTY) throw getRichError('System', 'unused handlers for security schemes', { unusedSecuritySchemes });
|
|
157
153
|
|
|
@@ -497,7 +493,7 @@ export const extractProperties = (apiDefinition, controllersDirectory, buildDire
|
|
|
497
493
|
*/
|
|
498
494
|
export const setupServerFiles = (apiFilename, controllersDirectory, buildDirectory, correlationId, options) => getAPIFile(apiFilename, correlationId, options)
|
|
499
495
|
.then((apiDefinition) => {
|
|
500
|
-
const existingSecuritySchemes =
|
|
496
|
+
const existingSecuritySchemes = validateSecuritySchemes(apiDefinition, correlationId).filter(Boolean);
|
|
501
497
|
|
|
502
498
|
extractProperties(apiDefinition, controllersDirectory, buildDirectory, correlationId);
|
|
503
499
|
const schemes = apiDefinition.components?.securitySchemes;
|
package/lib/securityHandlers.js
CHANGED
|
@@ -19,8 +19,6 @@ import {
|
|
|
19
19
|
USER_SECURITY,
|
|
20
20
|
} from './common.js';
|
|
21
21
|
import { TOKEN_PARAMS } from '@mimik/swagger-helper';
|
|
22
|
-
import difference from 'lodash.difference';
|
|
23
|
-
import intersection from 'lodash.intersection';
|
|
24
22
|
import jwt from 'jsonwebtoken';
|
|
25
23
|
|
|
26
24
|
const UNAUTHORIZED_ERROR = 401;
|
|
@@ -126,10 +124,10 @@ const checkScopes = (tokenScopes, defScopes, definition) => {
|
|
|
126
124
|
}
|
|
127
125
|
const includedClaims = analyzedScope[CLAIMS_INDEX].split(CLAIMS_SEPARATOR);
|
|
128
126
|
const definitionClaims = Object.keys(includedDefinition);
|
|
129
|
-
const claimsIntersects =
|
|
127
|
+
const claimsIntersects = includedClaims.filter(cla => definitionClaims.includes(cla));
|
|
130
128
|
|
|
131
129
|
if (claimsIntersects.length !== includedClaims.length) {
|
|
132
|
-
throw getError(`incorrect claims included: ${
|
|
130
|
+
throw getError(`incorrect claims included: ${includedClaims.filter(cla => !claimsIntersects.includes(cla))}`, FORBIDDEN_ERROR);
|
|
133
131
|
}
|
|
134
132
|
claims = claims.concat(claimsIntersects);
|
|
135
133
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/api-helper",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "helper for openAPI backend and mimik service",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -35,9 +35,6 @@
|
|
|
35
35
|
"js-base64": "3.7.8",
|
|
36
36
|
"js-yaml": "4.1.1",
|
|
37
37
|
"jsonwebtoken": "9.0.3",
|
|
38
|
-
"lodash.compact": "3.0.1",
|
|
39
|
-
"lodash.difference": "4.5.0",
|
|
40
|
-
"lodash.intersection": "4.4.0",
|
|
41
38
|
"openapi-backend": "5.16.1",
|
|
42
39
|
"swagger-client": "3.36.2"
|
|
43
40
|
},
|