denwa-nest-shared 1.0.34 → 1.0.36

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 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.36](https://github.com/Denwa799/nest-shared/compare/v1.0.35...v1.0.36) (2025-06-08)
6
+
7
+ ### [1.0.35](https://github.com/web-bee-ru/openapi-axios/compare/v1.0.34...v1.0.35) (2025-05-29)
8
+
5
9
  ### [1.0.34](https://github.com/web-bee-ru/openapi-axios/compare/v1.0.33...v1.0.34) (2025-05-22)
6
10
 
7
11
  ### [1.0.33](https://github.com/web-bee-ru/openapi-axios/compare/v1.0.32...v1.0.33) (2025-05-22)
@@ -1,5 +1,5 @@
1
1
  import { CustomDecorator } from '@nestjs/common';
2
- export declare const ApiProperty: ({ type, enumObject, min, max, arrayMinSize, arrayMaxSize, example, description, isOptional, isUUID, isArray, isJson, isJWT, isUrl, isPositive, isNegative, isEmail, isMobilePhone, isPhoneNumber, isLatitude, isLongitude, isStrongPassword, isArrayNotEmpty, isArrayUnique, }: {
2
+ export declare const ApiValidationProperty: ({ type, enumObject, min, max, arrayMinSize, arrayMaxSize, example, description, isOptional, isUUID, isArray, isJson, isJWT, isUrl, isPositive, isNegative, isEmail, isMobilePhone, isPhoneNumber, isLatitude, isLongitude, isStrongPassword, isArrayNotEmpty, isArrayUnique, }: {
3
3
  type: "string" | "int" | "float" | "date" | "boolean";
4
4
  enumObject?: object;
5
5
  min?: number;
package/cjs/decorators.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CheckFieldsRoles = exports.CHECK_FIELDS_ROLES_KEY = exports.Public = exports.GetCurrentUser = exports.GetCurrentRoles = exports.GetCurrentUserId = exports.Roles = exports.ApiProperty = void 0;
3
+ exports.CheckFieldsRoles = exports.CHECK_FIELDS_ROLES_KEY = exports.Public = exports.GetCurrentUser = exports.GetCurrentRoles = exports.GetCurrentUserId = exports.Roles = exports.ApiValidationProperty = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const graphql_1 = require("@nestjs/graphql");
6
6
  const swagger_1 = require("@nestjs/swagger");
7
7
  const class_validator_1 = require("class-validator");
8
8
  const const_1 = require("./const");
9
9
  const lib_1 = require("./lib");
10
- const ApiProperty = ({ type, enumObject, min, max, arrayMinSize, arrayMaxSize, example, description, isOptional = false, isUUID = false, isArray = false, isJson = false, isJWT = false, isUrl = false, isPositive = false, isNegative = false, isEmail = false, isMobilePhone = false, isPhoneNumber = false, isLatitude = false, isLongitude = false, isStrongPassword = false, isArrayNotEmpty = false, isArrayUnique = false, }) => {
10
+ const ApiValidationProperty = ({ type, enumObject, min, max, arrayMinSize, arrayMaxSize, example, description, isOptional = false, isUUID = false, isArray = false, isJson = false, isJWT = false, isUrl = false, isPositive = false, isNegative = false, isEmail = false, isMobilePhone = false, isPhoneNumber = false, isLatitude = false, isLongitude = false, isStrongPassword = false, isArrayNotEmpty = false, isArrayUnique = false, }) => {
11
11
  const decorators = [];
12
12
  if (isOptional) {
13
13
  decorators.push((0, swagger_1.ApiPropertyOptional)({
@@ -140,7 +140,7 @@ const ApiProperty = ({ type, enumObject, min, max, arrayMinSize, arrayMaxSize, e
140
140
  }
141
141
  return (0, common_1.applyDecorators)(...decorators);
142
142
  };
143
- exports.ApiProperty = ApiProperty;
143
+ exports.ApiValidationProperty = ApiValidationProperty;
144
144
  const Roles = (roles) => (0, common_1.SetMetadata)(const_1.ROLES_KEY, roles);
145
145
  exports.Roles = Roles;
146
146
  exports.GetCurrentUserId = (0, common_1.createParamDecorator)((_data, context) => {
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AAAA,2CAMwB;AACxB,6CAAoD;AACpD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ClD,MAAM,gBAAgB,GAAG,CAAC,cAEhC,EAA2B,EAAE,CAAC,IAAA,oBAAW,EAAC,8BAAsB,EAAE,cAAc,CAAC,CAAC;AAFtE,QAAA,gBAAgB,oBAEsD","sourcesContent":["import {\n applyDecorators,\n createParamDecorator,\n CustomDecorator,\n ExecutionContext,\n SetMetadata,\n} from '@nestjs/common';\nimport { Field, Float, Int } from '@nestjs/graphql';\nimport { ApiProperty as SwaggerApiProperty, ApiPropertyOptional } from '@nestjs/swagger';\nimport {\n ArrayMaxSize,\n ArrayMinSize,\n ArrayNotEmpty,\n ArrayUnique,\n IsArray,\n IsBoolean,\n IsDate,\n IsEmail,\n IsEnum,\n IsInt,\n IsJSON,\n IsJWT,\n IsLatitude,\n IsLongitude,\n IsMobilePhone,\n IsNegative,\n IsNumber,\n IsOptional,\n IsPhoneNumber,\n IsPositive,\n IsString,\n IsStrongPassword,\n IsUrl,\n IsUUID,\n Max,\n MaxLength,\n Min,\n MinLength,\n} from 'class-validator';\nimport { ROLES_KEY } from './const';\nimport { prepareRequestContext } from './lib';\n\nexport const ApiProperty = ({\n type,\n enumObject,\n min,\n max,\n arrayMinSize,\n arrayMaxSize,\n example,\n description,\n isOptional = false,\n isUUID = false,\n isArray = false,\n isJson = false,\n isJWT = false,\n isUrl = false,\n isPositive = false,\n isNegative = false,\n isEmail = false,\n isMobilePhone = false,\n isPhoneNumber = false,\n isLatitude = false,\n isLongitude = false,\n isStrongPassword = false,\n isArrayNotEmpty = false,\n isArrayUnique = false,\n}: {\n type: 'string' | 'int' | 'float' | 'date' | 'boolean';\n enumObject?: object;\n min?: number;\n max?: number;\n arrayMinSize?: number;\n arrayMaxSize?: number;\n example?: string;\n description?: string;\n isOptional?: boolean;\n isUUID?: boolean;\n isArray?: boolean;\n isJson?: boolean;\n isJWT?: boolean;\n isUrl?: boolean;\n isPositive?: boolean;\n isNegative?: boolean;\n isEmail?: boolean;\n isMobilePhone?: boolean;\n isPhoneNumber?: boolean;\n isLatitude?: boolean;\n isLongitude?: boolean;\n isStrongPassword?: boolean;\n isArrayNotEmpty?: boolean;\n isArrayUnique?: boolean;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n}): (<TFunction extends Function, Y>(\n target: TFunction | object,\n propertyKey?: string | symbol,\n descriptor?: TypedPropertyDescriptor<Y>,\n) => void) => {\n const decorators = [];\n\n if (isOptional) {\n decorators.push(\n ApiPropertyOptional({\n example,\n description,\n }),\n );\n } else {\n decorators.push(SwaggerApiProperty({ example, description }));\n }\n\n switch (type) {\n case 'int':\n decorators.push(Field(() => (isArray ? [Int] : Int), { nullable: isOptional }));\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsNumber());\n decorators.push(IsInt());\n\n if (min) decorators.push(Min(min, { each: isArray }));\n if (max) decorators.push(Max(max, { each: isArray }));\n\n break;\n case 'float':\n decorators.push(Field(() => (isArray ? [Float] : Float), { nullable: isOptional }));\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsNumber());\n\n if (min) decorators.push(Min(min, { each: isArray }));\n if (max) decorators.push(Max(max, { each: isArray }));\n\n break;\n case 'date':\n decorators.push(Field(() => (isArray ? [Date] : Date), { nullable: isOptional }));\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsDate({ each: isArray }));\n break;\n case 'boolean':\n decorators.push(Field({ nullable: isOptional }));\n if (isOptional) decorators.push(IsOptional());\n decorators.push(IsBoolean());\n break;\n case 'string':\n default:\n if (enumObject) {\n decorators.push(\n Field(() => (isArray ? [enumObject] : enumObject), { nullable: isOptional }),\n );\n } else {\n decorators.push(Field(() => (isArray ? [String] : String), { nullable: isOptional }));\n }\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsString({ each: isArray }));\n\n if (isUUID) decorators.push(IsUUID(undefined, { each: isArray }));\n if (isEmail) decorators.push(IsEmail(undefined, { each: isArray }));\n if (isMobilePhone) decorators.push(IsMobilePhone(undefined, undefined, { each: isArray }));\n if (isPhoneNumber) decorators.push(IsPhoneNumber(undefined, { each: isArray }));\n if (isPositive) decorators.push(IsPositive({ each: isArray }));\n if (isNegative) decorators.push(IsNegative({ each: isArray }));\n if (min) decorators.push(MinLength(min, { each: isArray }));\n if (max) decorators.push(MaxLength(max, { each: isArray }));\n if (enumObject) decorators.push(IsEnum(enumObject, { each: isArray }));\n if (isJson) decorators.push(IsJSON({ each: isArray }));\n if (isJWT) decorators.push(IsJWT({ each: isArray }));\n if (isUrl) decorators.push(IsUrl(undefined, { each: isArray }));\n if (isLatitude) decorators.push(IsLatitude({ each: isArray }));\n if (isLongitude) decorators.push(IsLongitude({ each: isArray }));\n if (isStrongPassword) decorators.push(IsStrongPassword(undefined, { each: isArray }));\n }\n\n return applyDecorators(...decorators);\n};\n\nexport const Roles = (roles: string[]): CustomDecorator<string[]> => SetMetadata(ROLES_KEY, roles);\n\nexport const GetCurrentUserId = createParamDecorator(\n (_data: undefined, context: ExecutionContext): string => {\n const request = prepareRequestContext(context);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return request.user['id'];\n },\n);\n\nexport const GetCurrentRoles = createParamDecorator(\n (_data: undefined, context: ExecutionContext): string => {\n const request = prepareRequestContext(context);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return (\n request.user['roles']?.map((item: { value: string } | string) => {\n if (typeof item === 'string') return item;\n return item.value;\n }) ?? []\n );\n },\n);\n\nexport const GetCurrentUser = createParamDecorator(\n (data: string | undefined, context: ExecutionContext) => {\n const request = prepareRequestContext(context);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n if (!data) return request.user;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return request.user[data];\n },\n);\n\nexport const Public = (): CustomDecorator<string> => SetMetadata('isPublic', true);\n\nexport const CHECK_FIELDS_ROLES_KEY = 'checkFieldsRoles';\nexport const CheckFieldsRoles = (fieldsRolesMap: {\n [field: string]: string[];\n}): CustomDecorator<string> => SetMetadata(CHECK_FIELDS_ROLES_KEY, fieldsRolesMap);\n"]}
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AAAA,2CAMwB;AACxB,6CAAoD;AACpD,6CAAmE;AACnE,qDA6ByB;AACzB,mCAAoC;AACpC,+BAA8C;AAEvC,MAAM,qBAAqB,GAAG,CAAC,EACpC,IAAI,EACJ,UAAU,EACV,GAAG,EACH,GAAG,EACH,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,WAAW,EACX,UAAU,GAAG,KAAK,EAClB,MAAM,GAAG,KAAK,EACd,OAAO,GAAG,KAAK,EACf,MAAM,GAAG,KAAK,EACd,KAAK,GAAG,KAAK,EACb,KAAK,GAAG,KAAK,EACb,UAAU,GAAG,KAAK,EAClB,UAAU,GAAG,K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B,CAAC,CACF,CAAC;AAEW,QAAA,eAAe,GAAG,IAAA,6BAAoB,EACjD,CAAC,KAAgB,EAAE,OAAyB,EAAU,EAAE;IACtD,MAAM,OAAO,GAAG,IAAA,2BAAqB,EAAC,OAAO,CAAC,CAAC;IAE/C,OAAO,CACL,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,IAAgC,EAAE,EAAE;QAC9D,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QAC1C,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC,CAAC,IAAI,EAAE,CACT,CAAC;AACJ,CAAC,CACF,CAAC;AAEW,QAAA,cAAc,GAAG,IAAA,6BAAoB,EAChD,CAAC,IAAwB,EAAE,OAAyB,EAAE,EAAE;IACtD,MAAM,OAAO,GAAG,IAAA,2BAAqB,EAAC,OAAO,CAAC,CAAC;IAG/C,IAAI,CAAC,IAAI;QAAE,OAAO,OAAO,CAAC,IAAI,CAAC;IAE/B,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC,CACF,CAAC;AAEK,MAAM,MAAM,GAAG,GAA4B,EAAE,CAAC,IAAA,oBAAW,EAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAAtE,QAAA,MAAM,UAAgE;AAEtE,QAAA,sBAAsB,GAAG,kBAAkB,CAAC;AAClD,MAAM,gBAAgB,GAAG,CAAC,cAEhC,EAA2B,EAAE,CAAC,IAAA,oBAAW,EAAC,8BAAsB,EAAE,cAAc,CAAC,CAAC;AAFtE,QAAA,gBAAgB,oBAEsD","sourcesContent":["import {\n applyDecorators,\n createParamDecorator,\n CustomDecorator,\n ExecutionContext,\n SetMetadata,\n} from '@nestjs/common';\nimport { Field, Float, Int } from '@nestjs/graphql';\nimport { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';\nimport {\n ArrayMaxSize,\n ArrayMinSize,\n ArrayNotEmpty,\n ArrayUnique,\n IsArray,\n IsBoolean,\n IsDate,\n IsEmail,\n IsEnum,\n IsInt,\n IsJSON,\n IsJWT,\n IsLatitude,\n IsLongitude,\n IsMobilePhone,\n IsNegative,\n IsNumber,\n IsOptional,\n IsPhoneNumber,\n IsPositive,\n IsString,\n IsStrongPassword,\n IsUrl,\n IsUUID,\n Max,\n MaxLength,\n Min,\n MinLength,\n} from 'class-validator';\nimport { ROLES_KEY } from './const';\nimport { prepareRequestContext } from './lib';\n\nexport const ApiValidationProperty = ({\n type,\n enumObject,\n min,\n max,\n arrayMinSize,\n arrayMaxSize,\n example,\n description,\n isOptional = false,\n isUUID = false,\n isArray = false,\n isJson = false,\n isJWT = false,\n isUrl = false,\n isPositive = false,\n isNegative = false,\n isEmail = false,\n isMobilePhone = false,\n isPhoneNumber = false,\n isLatitude = false,\n isLongitude = false,\n isStrongPassword = false,\n isArrayNotEmpty = false,\n isArrayUnique = false,\n}: {\n type: 'string' | 'int' | 'float' | 'date' | 'boolean';\n enumObject?: object;\n min?: number;\n max?: number;\n arrayMinSize?: number;\n arrayMaxSize?: number;\n example?: string;\n description?: string;\n isOptional?: boolean;\n isUUID?: boolean;\n isArray?: boolean;\n isJson?: boolean;\n isJWT?: boolean;\n isUrl?: boolean;\n isPositive?: boolean;\n isNegative?: boolean;\n isEmail?: boolean;\n isMobilePhone?: boolean;\n isPhoneNumber?: boolean;\n isLatitude?: boolean;\n isLongitude?: boolean;\n isStrongPassword?: boolean;\n isArrayNotEmpty?: boolean;\n isArrayUnique?: boolean;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n}): (<TFunction extends Function, Y>(\n target: TFunction | object,\n propertyKey?: string | symbol,\n descriptor?: TypedPropertyDescriptor<Y>,\n) => void) => {\n const decorators = [];\n\n if (isOptional) {\n decorators.push(\n ApiPropertyOptional({\n example,\n description,\n }),\n );\n } else {\n decorators.push(ApiProperty({ example, description }));\n }\n\n switch (type) {\n case 'int':\n decorators.push(Field(() => (isArray ? [Int] : Int), { nullable: isOptional }));\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsNumber());\n decorators.push(IsInt());\n\n if (min) decorators.push(Min(min, { each: isArray }));\n if (max) decorators.push(Max(max, { each: isArray }));\n\n break;\n case 'float':\n decorators.push(Field(() => (isArray ? [Float] : Float), { nullable: isOptional }));\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsNumber());\n\n if (min) decorators.push(Min(min, { each: isArray }));\n if (max) decorators.push(Max(max, { each: isArray }));\n\n break;\n case 'date':\n decorators.push(Field(() => (isArray ? [Date] : Date), { nullable: isOptional }));\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsDate({ each: isArray }));\n break;\n case 'boolean':\n decorators.push(Field({ nullable: isOptional }));\n if (isOptional) decorators.push(IsOptional());\n decorators.push(IsBoolean());\n break;\n case 'string':\n default:\n if (enumObject) {\n decorators.push(\n Field(() => (isArray ? [enumObject] : enumObject), { nullable: isOptional }),\n );\n } else {\n decorators.push(Field(() => (isArray ? [String] : String), { nullable: isOptional }));\n }\n\n if (isOptional) decorators.push(IsOptional());\n\n if (isArray) {\n decorators.push(IsArray());\n if (isArrayNotEmpty) decorators.push(ArrayNotEmpty());\n if (isArrayUnique) decorators.push(ArrayUnique());\n if (arrayMinSize) decorators.push(ArrayMinSize(arrayMinSize));\n if (arrayMaxSize) decorators.push(ArrayMaxSize(arrayMaxSize));\n }\n\n decorators.push(IsString({ each: isArray }));\n\n if (isUUID) decorators.push(IsUUID(undefined, { each: isArray }));\n if (isEmail) decorators.push(IsEmail(undefined, { each: isArray }));\n if (isMobilePhone) decorators.push(IsMobilePhone(undefined, undefined, { each: isArray }));\n if (isPhoneNumber) decorators.push(IsPhoneNumber(undefined, { each: isArray }));\n if (isPositive) decorators.push(IsPositive({ each: isArray }));\n if (isNegative) decorators.push(IsNegative({ each: isArray }));\n if (min) decorators.push(MinLength(min, { each: isArray }));\n if (max) decorators.push(MaxLength(max, { each: isArray }));\n if (enumObject) decorators.push(IsEnum(enumObject, { each: isArray }));\n if (isJson) decorators.push(IsJSON({ each: isArray }));\n if (isJWT) decorators.push(IsJWT({ each: isArray }));\n if (isUrl) decorators.push(IsUrl(undefined, { each: isArray }));\n if (isLatitude) decorators.push(IsLatitude({ each: isArray }));\n if (isLongitude) decorators.push(IsLongitude({ each: isArray }));\n if (isStrongPassword) decorators.push(IsStrongPassword(undefined, { each: isArray }));\n }\n\n return applyDecorators(...decorators);\n};\n\nexport const Roles = (roles: string[]): CustomDecorator<string[]> => SetMetadata(ROLES_KEY, roles);\n\nexport const GetCurrentUserId = createParamDecorator(\n (_data: undefined, context: ExecutionContext): string => {\n const request = prepareRequestContext(context);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return request.user['id'];\n },\n);\n\nexport const GetCurrentRoles = createParamDecorator(\n (_data: undefined, context: ExecutionContext): string => {\n const request = prepareRequestContext(context);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return (\n request.user['roles']?.map((item: { value: string } | string) => {\n if (typeof item === 'string') return item;\n return item.value;\n }) ?? []\n );\n },\n);\n\nexport const GetCurrentUser = createParamDecorator(\n (data: string | undefined, context: ExecutionContext) => {\n const request = prepareRequestContext(context);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n if (!data) return request.user;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return request.user[data];\n },\n);\n\nexport const Public = (): CustomDecorator<string> => SetMetadata('isPublic', true);\n\nexport const CHECK_FIELDS_ROLES_KEY = 'checkFieldsRoles';\nexport const CheckFieldsRoles = (fieldsRolesMap: {\n [field: string]: string[];\n}): CustomDecorator<string> => SetMetadata(CHECK_FIELDS_ROLES_KEY, fieldsRolesMap);\n"]}
@@ -33,10 +33,7 @@ let FieldsRolesInterceptor = class FieldsRolesInterceptor {
33
33
  if (fieldsRolesMap[field]) {
34
34
  const requiredRoles = fieldsRolesMap[field];
35
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;
36
+ return requiredRoles.includes(role) || role === 'super-admin';
40
37
  })) {
41
38
  throw new common_1.ForbiddenException(`Access to field "${field}" is denied`);
42
39
  }
@@ -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,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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E,EAAE,CAAC,IAAA,eAAK,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QAEnD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AApDY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;qCAE6B,gBAAS;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"]}
1
+ {"version":3,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,KAAK,aAAa,CAAC,CAAC;gBACvE,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;IAEO,sBAAsB,CAAC,UAAoC;QACjE,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,MAAM,OAAO,GAAG;YACd,KAAK,CAAC,IAAe;gBACnB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC/B,CAAC;SACF,CAAC;QAEF,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,eAAK,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QAEnD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AAnDY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;qCAE6B,gBAAS;GADtC,sBAAsB,CAmDlC","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\n if (\n !user?.roles?.some((role: string) => {\n return requiredRoles.includes(role) || role === 'super-admin';\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"]}