denwa-nest-shared 1.0.28 → 1.0.30
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/CHANGELOG.md +4 -0
- package/cjs/interceptors/fields-roles.interceptor.js +7 -2
- package/cjs/interceptors/fields-roles.interceptor.js.map +1 -1
- package/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/interceptors/fields-roles.interceptor.js +7 -2
- package/dist/interceptors/fields-roles.interceptor.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.0.30](https://github.com/web-bee-ru/openapi-axios/compare/v1.0.29...v1.0.30) (2025-05-06)
|
|
6
|
+
|
|
7
|
+
### [1.0.29](https://github.com/web-bee-ru/openapi-axios/compare/v1.0.28...v1.0.29) (2025-05-05)
|
|
8
|
+
|
|
5
9
|
### [1.0.28](https://github.com/web-bee-ru/openapi-axios/compare/v1.0.27...v1.0.28) (2025-05-05)
|
|
6
10
|
|
|
7
11
|
### [1.0.27](https://github.com/web-bee-ru/openapi-axios/compare/v1.0.26...v1.0.27) (2025-05-05)
|
|
@@ -14,7 +14,7 @@ const common_1 = require("@nestjs/common");
|
|
|
14
14
|
const core_1 = require("@nestjs/core");
|
|
15
15
|
const graphql_1 = require("@nestjs/graphql");
|
|
16
16
|
const graphql_2 = require("graphql");
|
|
17
|
-
const decorators_1 = require("
|
|
17
|
+
const decorators_1 = require("../decorators");
|
|
18
18
|
let FieldsRolesInterceptor = class FieldsRolesInterceptor {
|
|
19
19
|
reflector;
|
|
20
20
|
constructor(reflector) {
|
|
@@ -32,7 +32,12 @@ let FieldsRolesInterceptor = class FieldsRolesInterceptor {
|
|
|
32
32
|
for (const field of requestedFields) {
|
|
33
33
|
if (fieldsRolesMap[field]) {
|
|
34
34
|
const requiredRoles = fieldsRolesMap[field];
|
|
35
|
-
if (!
|
|
35
|
+
if (!user?.roles?.some((role) => {
|
|
36
|
+
if ('value' in role && typeof role.value === 'string')
|
|
37
|
+
return requiredRoles.includes(role.value) || role.value === 'super-admin';
|
|
38
|
+
else
|
|
39
|
+
return false;
|
|
40
|
+
})) {
|
|
36
41
|
throw new common_1.ForbiddenException(`Access to field "${field}" is denied`);
|
|
37
42
|
}
|
|
38
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields-roles.interceptor.js","sourceRoot":"","sources":["../../src/interceptors/fields-roles.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAMwB;AAExB,uCAAyC;AACzC,6CAAsD;AACtD,qCAA2C;AAE3C,
|
|
1
|
+
{"version":3,"file":"fields-roles.interceptor.js","sourceRoot":"","sources":["../../src/interceptors/fields-roles.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAMwB;AAExB,uCAAyC;AACzC,6CAAsD;AACtD,qCAA2C;AAE3C,8CAAuD;AAGhD,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACJ;IAA7B,YAA6B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAErD,SAAS,CAAC,OAAyB,EAAE,IAAiB;QACpD,MAAM,GAAG,GAAG,6BAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;QAEvC,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CACrD,mCAAsB,EACtB,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAC3C,CAAC;QAEF,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO,IAAI,CAA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S;GADtC,sBAAsB,CAoDlC","sourcesContent":["import {\n Injectable,\n NestInterceptor,\n ExecutionContext,\n CallHandler,\n ForbiddenException,\n} from '@nestjs/common';\nimport { Observable } from 'rxjs';\nimport { Reflector } from '@nestjs/core';\nimport { GqlExecutionContext } from '@nestjs/graphql';\nimport { FieldNode, visit } from 'graphql';\n\nimport { CHECK_FIELDS_ROLES_KEY } from '../decorators';\n\n@Injectable()\nexport class FieldsRolesInterceptor implements NestInterceptor {\n constructor(private readonly reflector: Reflector) {}\n\n intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {\n const ctx = GqlExecutionContext.create(context);\n const user = ctx.getContext().req.user;\n\n const fieldsRolesMap = this.reflector.getAllAndOverride<{ [field: string]: string[] }>(\n CHECK_FIELDS_ROLES_KEY,\n [context.getHandler(), context.getClass()],\n );\n\n if (!fieldsRolesMap) {\n return next.handle();\n }\n\n const info = ctx.getInfo();\n const requestedFields = this.extractRequestedFields(\n info.fieldNodes as ReadonlyArray<FieldNode>,\n );\n\n for (const field of requestedFields) {\n if (fieldsRolesMap[field]) {\n const requiredRoles = fieldsRolesMap[field];\n if (\n !user?.roles?.some((role: object) => {\n if ('value' in role && typeof role.value === 'string')\n return requiredRoles.includes(role.value) || role.value === 'super-admin';\n else return false;\n })\n ) {\n throw new ForbiddenException(`Access to field \"${field}\" is denied`);\n }\n }\n }\n\n return next.handle();\n }\n\n private extractRequestedFields(fieldNodes: ReadonlyArray<FieldNode>): string[] {\n const fields: string[] = [];\n\n const visitor = {\n Field(node: FieldNode): void {\n fields.push(node.name.value);\n },\n };\n\n fieldNodes.forEach((node) => visit(node, visitor));\n\n return fields;\n }\n}\n"]}
|