@my-nestjs-kit/auth 0.0.0-stage → 0.1.0-dev.20261129010337

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.
Files changed (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +27 -2
  3. package/dist/access-tokens/access-token.d.ts +13 -0
  4. package/dist/access-tokens/access-token.js +10 -0
  5. package/dist/access-tokens/access-tokens.module.d.ts +2 -0
  6. package/dist/access-tokens/access-tokens.module.js +22 -0
  7. package/dist/access-tokens/access-tokens.service.d.ts +16 -0
  8. package/dist/access-tokens/access-tokens.service.js +72 -0
  9. package/dist/access-tokens/access-tokens.types.d.ts +5 -0
  10. package/dist/access-tokens/access-tokens.types.js +9 -0
  11. package/dist/access-tokens/dto/access-token.dto.d.ts +13 -0
  12. package/dist/access-tokens/dto/access-token.dto.js +33 -0
  13. package/dist/auth-sessions/devices/dto/create-device.dto.d.ts +6 -0
  14. package/dist/auth-sessions/devices/dto/create-device.dto.js +33 -0
  15. package/dist/auth-sessions/dto/create-auth-session.dto.d.ts +8 -0
  16. package/dist/auth-sessions/dto/create-auth-session.dto.js +36 -0
  17. package/dist/auth.constants.d.ts +30 -0
  18. package/dist/auth.constants.js +36 -0
  19. package/dist/decorators/GetAuthParams.decorator.d.ts +34 -0
  20. package/dist/decorators/GetAuthParams.decorator.js +64 -0
  21. package/dist/decorators/GetSession.decorator.d.ts +2 -0
  22. package/dist/decorators/GetSession.decorator.js +13 -0
  23. package/dist/decorators/GetUser.decorator.d.ts +2 -0
  24. package/dist/decorators/GetUser.decorator.js +13 -0
  25. package/dist/decorators/Public.decorator.d.ts +3 -0
  26. package/dist/decorators/Public.decorator.js +18 -0
  27. package/dist/decorators/SetAuthConfig.decorator.d.ts +3 -0
  28. package/dist/decorators/SetAuthConfig.decorator.js +13 -0
  29. package/dist/dto/confirm-secure-action.dto.d.ts +8 -0
  30. package/dist/dto/confirm-secure-action.dto.js +46 -0
  31. package/dist/dto/log-in-by-email.dto.d.ts +16 -0
  32. package/dist/dto/log-in-by-email.dto.js +15 -0
  33. package/dist/dto/login-user-auth.dto.d.ts +4 -0
  34. package/dist/dto/login-user-auth.dto.js +29 -0
  35. package/dist/dto/verify-user-registration.dto.d.ts +4 -0
  36. package/dist/dto/verify-user-registration.dto.js +25 -0
  37. package/dist/entities/abstract-device-base.entity.d.ts +10 -0
  38. package/dist/entities/abstract-device-base.entity.js +77 -0
  39. package/dist/entities/abstract-o-auth-connection.entity.d.ts +28 -0
  40. package/dist/entities/abstract-o-auth-connection.entity.js +100 -0
  41. package/dist/entities/abstract-o-auth-profile.entity.d.ts +10 -0
  42. package/dist/entities/abstract-o-auth-profile.entity.js +38 -0
  43. package/dist/entities/auth-session-base.entity.d.ts +18 -0
  44. package/dist/entities/auth-session-base.entity.js +73 -0
  45. package/dist/guards/AbstractRefreshJwtToken.guard.d.ts +9 -0
  46. package/dist/guards/AbstractRefreshJwtToken.guard.js +45 -0
  47. package/dist/guards/abstract/AppAuthGuard-abstract.d.ts +219 -0
  48. package/dist/guards/abstract/AppAuthGuard-abstract.js +187 -0
  49. package/dist/guards/index.d.ts +0 -0
  50. package/dist/guards/index.js +0 -0
  51. package/dist/helper/base-auth-service.helper.d.ts +60 -0
  52. package/dist/helper/base-auth-service.helper.js +184 -0
  53. package/dist/helper/jsw-auth-controller-abstract.d.ts +33 -0
  54. package/dist/helper/jsw-auth-controller-abstract.js +89 -0
  55. package/dist/helper/jwt-auth-service-abstract.d.ts +40 -0
  56. package/dist/helper/jwt-auth-service-abstract.js +181 -0
  57. package/dist/index.d.ts +31 -0
  58. package/dist/index.js +55 -0
  59. package/dist/jwt/index.d.ts +5 -0
  60. package/dist/jwt/index.js +21 -0
  61. package/dist/jwt/jwt-auth.module.d.ts +6 -0
  62. package/dist/jwt/jwt-auth.module.js +45 -0
  63. package/dist/jwt/jwt-auth.service.d.ts +33 -0
  64. package/dist/jwt/jwt-auth.service.js +170 -0
  65. package/dist/jwt/jwt-keys.helper.d.ts +12 -0
  66. package/dist/jwt/jwt-keys.helper.js +32 -0
  67. package/dist/jwt/types/enums.d.ts +19 -0
  68. package/dist/jwt/types/enums.js +26 -0
  69. package/dist/jwt/types/index.d.ts +2 -0
  70. package/dist/jwt/types/index.js +18 -0
  71. package/dist/jwt/types/jwt-auth.types.d.ts +44 -0
  72. package/dist/jwt/types/jwt-auth.types.js +2 -0
  73. package/dist/o-auth/abstract-o-auth.service.d.ts +30 -0
  74. package/dist/o-auth/abstract-o-auth.service.js +64 -0
  75. package/dist/o-auth/o-auth.namespace.d.ts +131 -0
  76. package/dist/o-auth/o-auth.namespace.js +256 -0
  77. package/dist/o-auth/sdk/base-ext-o-auth-sdk.d.ts +104 -0
  78. package/dist/o-auth/sdk/base-ext-o-auth-sdk.js +56 -0
  79. package/dist/route-auth-configs.helper.d.ts +29 -0
  80. package/dist/route-auth-configs.helper.js +36 -0
  81. package/dist/services/abstrac-auth-sessions.service.d.ts +28 -0
  82. package/dist/services/abstrac-auth-sessions.service.js +41 -0
  83. package/dist/services/abstract-sessions-repo.service.d.ts +28 -0
  84. package/dist/services/abstract-sessions-repo.service.js +28 -0
  85. package/dist/types/app-request.inteface.d.ts +14 -0
  86. package/dist/types/app-request.inteface.js +2 -0
  87. package/dist/types/auth.types.d.ts +43 -0
  88. package/dist/types/auth.types.js +12 -0
  89. package/dist/types/ws-client.types.d.ts +14 -0
  90. package/dist/types/ws-client.types.js +2 -0
  91. package/package.json +95 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sabationok
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,28 @@
1
- # Temporary Holding Version
1
+ # @my-nestjs-kit/auth
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ JWT auth bases for NestJS. Depends on `@my-nestjs-kit/core` (installed with it).
4
+
5
+ ```sh
6
+ npm i @my-nestjs-kit/auth
7
+ ```
8
+
9
+ Peers: `@nestjs/common`, `@nestjs/core`, `@nestjs/swagger`, `typeorm`, `jsonwebtoken`, `bcryptjs`, `class-validator`,
10
+ `date-fns`, `axios`, `lodash`, `rxjs`, plus core's peers. Optional: `@types/express`.
11
+
12
+ ## What's in
13
+
14
+ - **JWT engine:** `JwtAuthModule` / `JwtAuthService`: token types ACCESS / REFRESH / VERIFICATION /
15
+ CREDENTIALS_CONFIRM, `kid` key rotation with verify-only keys, `typ` checked on verify, `aud` / `iss` enforced,
16
+ HMAC only, every verify failure is a 401 `AppHttpException`. `parseJwtKeys` reads a key list or a plain secret.
17
+ - **Service bases:** `AbstractAuthService`, `JwtAuthServiceAbstract` (password hashing, verification codes through
18
+ `AccessTokensService`), `JwtAuthControllerAbstract`, session bases (`AuthSessionBaseEntity`,
19
+ `AbstractAuthSessionRepoService`, `AbstractAuthSessionsAuthService`), OAuth bases, `AccessTokensModule`.
20
+ - **Guards:** `AbstractAuthGuard`, `AbstractRefreshJwtTokenGuard`. Route config wins over controller config;
21
+ `@Public()` / `SetAuthConfig({ isPublic: true })` opens a route (guards with `ignorePublic` still run); a guarded
22
+ route with no auth config is denied; `isServerAction` routes pass only with their own server-token guard.
23
+ - **Request auth context:** `SetAuthConfig`, `Public`, `AuthConfigsMetaStorage`, `GetUser`, `GetSession`,
24
+ `GetAuthParams`, `AuthParams`, `ErpRequestTarget`, `AuthConfigs`, `AuthTokenType`, `AppWs`.
25
+
26
+ ## License
27
+
28
+ MIT
@@ -0,0 +1,13 @@
1
+ import { AccessTokenTypeEnum } from './access-tokens.types';
2
+ export declare class AccessToken {
3
+ value?: string;
4
+ type?: AccessTokenTypeEnum;
5
+ holderId?: string;
6
+ trackId?: string;
7
+ emitterId?: string;
8
+ holderType?: string;
9
+ ttl?: number;
10
+ encoded?: boolean;
11
+ secretVersion?: string | number;
12
+ constructor(payload?: AccessToken);
13
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccessToken = void 0;
4
+ class AccessToken {
5
+ constructor(payload) {
6
+ if (payload)
7
+ Object.assign(this, payload);
8
+ }
9
+ }
10
+ exports.AccessToken = AccessToken;
@@ -0,0 +1,2 @@
1
+ export declare class AccessTokensModule {
2
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AccessTokensModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const access_tokens_service_1 = require("./access-tokens.service");
12
+ // Redis-backed one-time codes / verification tokens. Needs the kit RedisModule (global) in the app.
13
+ let AccessTokensModule = class AccessTokensModule {
14
+ };
15
+ exports.AccessTokensModule = AccessTokensModule;
16
+ exports.AccessTokensModule = AccessTokensModule = __decorate([
17
+ (0, common_1.Global)(),
18
+ (0, common_1.Module)({
19
+ providers: [access_tokens_service_1.AccessTokensService],
20
+ exports: [access_tokens_service_1.AccessTokensService],
21
+ })
22
+ ], AccessTokensModule);
@@ -0,0 +1,16 @@
1
+ import { GetAccessTokenQuery, SetAccessTokenDto } from './dto/access-token.dto';
2
+ import { RedisService } from '@my-nestjs-kit/core';
3
+ import { AccessToken } from './access-token';
4
+ export declare class AccessTokensService {
5
+ private readonly redisSrv;
6
+ constructor(redisSrv: RedisService);
7
+ getCodeMaxAge(amount?: number): number;
8
+ generateCode: (size?: number) => string;
9
+ generateUniqueCode(getTracker: (code: string) => string): Promise<string>;
10
+ getTracker: (namespace: string, query: Record<string, string>) => string;
11
+ set(dto: SetAccessTokenDto): Promise<AccessToken>;
12
+ get({ namespace, key, value, queries, }: GetAccessTokenQuery): Promise<AccessToken>;
13
+ delete({ namespace, key, value, queries }: GetAccessTokenQuery): Promise<{
14
+ result: boolean;
15
+ }>;
16
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AccessTokensService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const date_fns_1 = require("date-fns");
15
+ const core_1 = require("@my-nestjs-kit/core");
16
+ const access_token_1 = require("./access-token");
17
+ const nanoid_1 = require("nanoid");
18
+ let AccessTokensService = class AccessTokensService {
19
+ constructor(redisSrv) {
20
+ this.redisSrv = redisSrv;
21
+ this.generateCode = (0, nanoid_1.customAlphabet)('0123456789', 8);
22
+ this.getTracker = (namespace, query) => {
23
+ return [[namespace]]
24
+ .concat(Object.entries(query))
25
+ .map((entry) => entry.join('_'))
26
+ .join(':');
27
+ };
28
+ }
29
+ getCodeMaxAge(amount = 10) {
30
+ return (0, date_fns_1.minutesToSeconds)(amount);
31
+ }
32
+ async generateUniqueCode(getTracker) {
33
+ let code;
34
+ let isUnique = false;
35
+ while (!isUnique) {
36
+ code = this.generateCode(); // Ваш генератор випадкових кодів
37
+ const tracker = getTracker(code);
38
+ // Перевіряємо, чи існує такий код у Redis для цього clientId
39
+ const exists = await this.redisSrv.redis.exists(tracker);
40
+ if (!exists) {
41
+ isUnique = true; // Якщо не існує, можемо використовувати цей код
42
+ }
43
+ }
44
+ // Реалізація генерації унікального коду (наприклад, через crypto.randomBytes)
45
+ return code;
46
+ }
47
+ async set(dto) {
48
+ const { key, value, queries, namespace, data } = dto;
49
+ const tracker = this.getTracker(namespace, queries ?? { [key]: value });
50
+ const token = new access_token_1.AccessToken(data);
51
+ const res = await this.redisSrv.redis.setex(tracker, data.ttl ?? this.getCodeMaxAge(), JSON.stringify(token));
52
+ if (res === 'OK') {
53
+ return token;
54
+ }
55
+ return null;
56
+ }
57
+ async get({ namespace, key, value, queries, }) {
58
+ const tracker = this.getTracker(namespace, queries ?? { [key]: value });
59
+ const token = new access_token_1.AccessToken(await this.redisSrv.get(tracker));
60
+ return token;
61
+ }
62
+ async delete({ namespace, key, value, queries }) {
63
+ const tracker = this.getTracker(namespace, queries ?? { [key]: value });
64
+ const count = await this.redisSrv.del(tracker);
65
+ return { result: !!count };
66
+ }
67
+ };
68
+ exports.AccessTokensService = AccessTokensService;
69
+ exports.AccessTokensService = AccessTokensService = __decorate([
70
+ (0, common_1.Injectable)(),
71
+ __metadata("design:paramtypes", [core_1.RedisService])
72
+ ], AccessTokensService);
@@ -0,0 +1,5 @@
1
+ export declare enum AccessTokenTypeEnum {
2
+ code = "code",
3
+ token = "token",
4
+ Bearer = "Bearer"
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccessTokenTypeEnum = void 0;
4
+ var AccessTokenTypeEnum;
5
+ (function (AccessTokenTypeEnum) {
6
+ AccessTokenTypeEnum["code"] = "code";
7
+ AccessTokenTypeEnum["token"] = "token";
8
+ AccessTokenTypeEnum["Bearer"] = "Bearer";
9
+ })(AccessTokenTypeEnum || (exports.AccessTokenTypeEnum = AccessTokenTypeEnum = {}));
@@ -0,0 +1,13 @@
1
+ import { AccessToken } from '../access-token';
2
+ declare class AccessTokenBaseDto<Namespace extends string = string, Key extends string | number | symbol = string> {
3
+ namespace: Namespace;
4
+ value?: Key;
5
+ key?: string;
6
+ queries?: Record<string, string>;
7
+ }
8
+ export declare class SetAccessTokenDto<Namespace extends string = string, Value extends string | number | symbol = string> extends AccessTokenBaseDto<Namespace, Value> {
9
+ data: AccessToken;
10
+ }
11
+ export declare class GetAccessTokenQuery<Namespace extends string = string, Value extends string | number | symbol = string> extends AccessTokenBaseDto<Namespace, Value> {
12
+ }
13
+ export {};
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GetAccessTokenQuery = exports.SetAccessTokenDto = void 0;
13
+ const core_1 = require("@my-nestjs-kit/core");
14
+ class AccessTokenBaseDto {
15
+ }
16
+ __decorate([
17
+ (0, core_1.IsString255)(),
18
+ __metadata("design:type", String)
19
+ ], AccessTokenBaseDto.prototype, "namespace", void 0);
20
+ __decorate([
21
+ (0, core_1.IsString500)(),
22
+ __metadata("design:type", Object)
23
+ ], AccessTokenBaseDto.prototype, "value", void 0);
24
+ __decorate([
25
+ (0, core_1.IsString255)(),
26
+ __metadata("design:type", String)
27
+ ], AccessTokenBaseDto.prototype, "key", void 0);
28
+ class SetAccessTokenDto extends AccessTokenBaseDto {
29
+ }
30
+ exports.SetAccessTokenDto = SetAccessTokenDto;
31
+ class GetAccessTokenQuery extends AccessTokenBaseDto {
32
+ }
33
+ exports.GetAccessTokenQuery = GetAccessTokenQuery;
@@ -0,0 +1,6 @@
1
+ export declare class CreateDeviceDto {
2
+ userId: string;
3
+ os?: string;
4
+ userAgent?: string;
5
+ trackId?: string;
6
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CreateDeviceDto = void 0;
13
+ const core_1 = require("@my-nestjs-kit/core");
14
+ const core_2 = require("@my-nestjs-kit/core");
15
+ class CreateDeviceDto {
16
+ }
17
+ exports.CreateDeviceDto = CreateDeviceDto;
18
+ __decorate([
19
+ (0, core_1.IsUUIDParam)({ optional: false }),
20
+ __metadata("design:type", String)
21
+ ], CreateDeviceDto.prototype, "userId", void 0);
22
+ __decorate([
23
+ (0, core_2.IsString128)(),
24
+ __metadata("design:type", String)
25
+ ], CreateDeviceDto.prototype, "os", void 0);
26
+ __decorate([
27
+ (0, core_2.IsString255)(),
28
+ __metadata("design:type", String)
29
+ ], CreateDeviceDto.prototype, "userAgent", void 0);
30
+ __decorate([
31
+ (0, core_1.IsUUIDParam)(),
32
+ __metadata("design:type", String)
33
+ ], CreateDeviceDto.prototype, "trackId", void 0);
@@ -0,0 +1,8 @@
1
+ import { CreateDeviceDto } from '../devices/dto/create-device.dto';
2
+ export declare class CreateAuthSessionDto {
3
+ userId: string;
4
+ ip?: string;
5
+ device?: CreateDeviceDto;
6
+ extId?: string;
7
+ connectionId?: string;
8
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CreateAuthSessionDto = void 0;
13
+ const class_validator_1 = require("class-validator");
14
+ const core_1 = require("@my-nestjs-kit/core");
15
+ const core_2 = require("@my-nestjs-kit/core");
16
+ class CreateAuthSessionDto {
17
+ }
18
+ exports.CreateAuthSessionDto = CreateAuthSessionDto;
19
+ __decorate([
20
+ (0, core_1.IsUUIDParam)({ optional: false }),
21
+ __metadata("design:type", String)
22
+ ], CreateAuthSessionDto.prototype, "userId", void 0);
23
+ __decorate([
24
+ (0, class_validator_1.IsIP)(),
25
+ (0, class_validator_1.IsOptional)(),
26
+ (0, core_1.ApiPropDescriptor)(),
27
+ __metadata("design:type", String)
28
+ ], CreateAuthSessionDto.prototype, "ip", void 0);
29
+ __decorate([
30
+ (0, core_2.IsString255)({ api: { hidden: true } }),
31
+ __metadata("design:type", String)
32
+ ], CreateAuthSessionDto.prototype, "extId", void 0);
33
+ __decorate([
34
+ (0, core_1.IsUUIDParam)({ api: { hidden: true } }),
35
+ __metadata("design:type", String)
36
+ ], CreateAuthSessionDto.prototype, "connectionId", void 0);
@@ -0,0 +1,30 @@
1
+ import { KeysOf } from '@my-nestjs-kit/core';
2
+ export declare const AUTH_PREFIX = "auth";
3
+ export declare const OAUTH_PATH = "auth/o-auth";
4
+ export declare const AUTH_O_PATH = "auth/o";
5
+ export declare const USER_ALREADY_EXIST_ERROR = "\u0422\u0430\u043A\u0438\u0439 \u043A\u043E\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447 \u0443\u0436\u0435 \u0437\u0430\u0440\u0435\u0454\u0441\u0442\u0440\u043E\u0432\u0430\u043D\u0438\u0439";
6
+ export declare const USER_NOT_FOUND_ERROR = "\u041A\u043E\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447 \u0456\u0437 \u0442\u0430\u043A\u043E\u044E \u0430\u0434\u0440\u0435\u0441\u043E\u044E \u043D\u0435 \u0437\u043D\u0430\u0439\u0434\u0435\u043D\u0438\u0439";
7
+ export declare const UNAUTHORIZED_USER = "\u041D\u0435 \u0430\u0432\u0442\u043E\u0440\u0438\u0437\u043E\u0432\u0430\u043D\u0438\u0439 \u043A\u043E\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447";
8
+ export declare const WRONG_CREDENTIALS_ERROR = "\u0425\u0438\u0431\u043D\u0456 \u0434\u0430\u043D\u0456";
9
+ export declare const LOGIN_SUCCESS = "\u0412\u0445\u0456\u0434 \u0443 \u0441\u0438\u0441\u0442\u0435\u043C\u0443 \u0443\u0441\u043F\u0456\u0448\u043D\u0438\u0439";
10
+ export declare const LOGOUT_SUCCESS = "\u0421\u0435\u0430\u043D\u0441 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043D\u043E";
11
+ export declare const LOGOUT_ERROR = "\u041F\u043E\u043C\u0438\u043B\u043A\u0430 \u043F\u0456\u0434 \u0447\u0430\u0441 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043D\u043D\u044F \u0441\u0435\u0430\u043D\u0441\u0443";
12
+ export declare const ROLE_UPDATE_SUCCESS: (email?: string, role?: string) => string;
13
+ export declare const ROLE_UPDATE_ERROR = "\u041F\u043E\u043C\u0438\u043B\u043A\u0430 \u043F\u0456\u0434 \u0447\u0430\u0441 \u0437\u043C\u0456\u043D\u0438 \u0440\u043E\u043B\u0456 \u043A\u043E\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447\u0430";
14
+ export declare const authMessagesPack: {
15
+ en: {
16
+ USER_ALREADY_EXIST_ERROR: string;
17
+ USER_NOT_FOUND_ERROR: string;
18
+ UNAUTHORIZED_USER: string;
19
+ WRONG_CREDENTIALS_ERROR: string;
20
+ LOGIN_SUCCESS: string;
21
+ LOGOUT_SUCCESS: string;
22
+ refresh_token_success: string;
23
+ LOGOUT_ERROR: string;
24
+ ROLE_UPDATE_SUCCESS: (email?: string, role?: string) => string;
25
+ ROLE_UPDATE_ERROR: string;
26
+ };
27
+ };
28
+ type AuthMsgsLangKeyType = KeysOf<typeof authMessagesPack> | string;
29
+ export declare function getAuthMessages(langKey?: AuthMsgsLangKeyType): any;
30
+ export {};
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAuthMessages = exports.authMessagesPack = exports.ROLE_UPDATE_ERROR = exports.ROLE_UPDATE_SUCCESS = exports.LOGOUT_ERROR = exports.LOGOUT_SUCCESS = exports.LOGIN_SUCCESS = exports.WRONG_CREDENTIALS_ERROR = exports.UNAUTHORIZED_USER = exports.USER_NOT_FOUND_ERROR = exports.USER_ALREADY_EXIST_ERROR = exports.AUTH_O_PATH = exports.OAUTH_PATH = exports.AUTH_PREFIX = void 0;
4
+ exports.AUTH_PREFIX = 'auth';
5
+ exports.OAUTH_PATH = `${exports.AUTH_PREFIX}/o-auth`;
6
+ exports.AUTH_O_PATH = `${exports.AUTH_PREFIX}/o`;
7
+ // *****************************************
8
+ exports.USER_ALREADY_EXIST_ERROR = 'Такий користувач уже зареєстрований';
9
+ exports.USER_NOT_FOUND_ERROR = 'Користувач із такою адресою не знайдений';
10
+ exports.UNAUTHORIZED_USER = 'Не авторизований користувач';
11
+ exports.WRONG_CREDENTIALS_ERROR = 'Хибні дані';
12
+ exports.LOGIN_SUCCESS = 'Вхід у систему успішний';
13
+ exports.LOGOUT_SUCCESS = 'Сеанс завершено';
14
+ exports.LOGOUT_ERROR = 'Помилка під час завершення сеансу';
15
+ const ROLE_UPDATE_SUCCESS = (email, role) => `Роль користувача "${email}" успішно змінено на "${role}"`;
16
+ exports.ROLE_UPDATE_SUCCESS = ROLE_UPDATE_SUCCESS;
17
+ exports.ROLE_UPDATE_ERROR = 'Помилка під час зміни ролі користувача';
18
+ const authMessages_en = {
19
+ USER_ALREADY_EXIST_ERROR: exports.USER_ALREADY_EXIST_ERROR,
20
+ USER_NOT_FOUND_ERROR: exports.USER_NOT_FOUND_ERROR,
21
+ UNAUTHORIZED_USER: exports.UNAUTHORIZED_USER,
22
+ WRONG_CREDENTIALS_ERROR: exports.WRONG_CREDENTIALS_ERROR,
23
+ LOGIN_SUCCESS: exports.LOGIN_SUCCESS,
24
+ LOGOUT_SUCCESS: exports.LOGOUT_SUCCESS,
25
+ refresh_token_success: 'Refresh token success',
26
+ LOGOUT_ERROR: exports.LOGOUT_ERROR,
27
+ ROLE_UPDATE_SUCCESS: exports.ROLE_UPDATE_SUCCESS,
28
+ ROLE_UPDATE_ERROR: exports.ROLE_UPDATE_ERROR,
29
+ };
30
+ exports.authMessagesPack = {
31
+ en: authMessages_en,
32
+ };
33
+ function getAuthMessages(langKey = 'en') {
34
+ return exports.authMessagesPack[langKey];
35
+ }
36
+ exports.getAuthMessages = getAuthMessages;
@@ -0,0 +1,34 @@
1
+ import { ContextType } from '@nestjs/common';
2
+ import { JwtIssuerEnum, PartialRecord, PermissionHolderEnum } from '@my-nestjs-kit/core';
3
+ import { DecoratorForReqOptions } from '@my-nestjs-kit/core';
4
+ import { AuthTokenType } from '../types/auth.types';
5
+ export interface AuthParamsExtraTyped {
6
+ access?: string;
7
+ role?: string;
8
+ session?: string;
9
+ status?: string;
10
+ }
11
+ export declare class AuthParams<Extra extends AuthParamsExtraTyped = AuthParamsExtraTyped> {
12
+ model?: JwtIssuerEnum;
13
+ modelIs?: PartialRecord<JwtIssuerEnum | string, boolean>;
14
+ holder?: PermissionHolderEnum;
15
+ holderIs?: PartialRecord<PermissionHolderEnum | string, boolean>;
16
+ role?: Extra['role'];
17
+ roleIs?: PartialRecord<NonNullable<Extra['role']>, boolean>;
18
+ session?: Extra['session'];
19
+ sessionIs?: PartialRecord<NonNullable<Extra['session']>, boolean>;
20
+ status?: Extra['status'];
21
+ statusIs?: PartialRecord<NonNullable<Extra['status']>, boolean>;
22
+ access?: Extra['access'];
23
+ accessIs?: PartialRecord<NonNullable<Extra['access']>, boolean>;
24
+ isPublic?: boolean;
25
+ tokenTypeIs?: PartialRecord<AuthTokenType, boolean>;
26
+ tokenType?: string;
27
+ isServerToServer?: boolean;
28
+ isSecure?: boolean;
29
+ contextType?: ContextType;
30
+ constructor(params?: AuthParams<Extra>);
31
+ }
32
+ export declare const InitialAuthParams: AuthParams<AuthParamsExtraTyped>;
33
+ export declare const GetAuthParams: (...dataOrPipes: (DecoratorForReqOptions | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
34
+ export declare const GetWsAuthParams: (...dataOrPipes: unknown[]) => ParameterDecorator;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.GetWsAuthParams = exports.GetAuthParams = exports.InitialAuthParams = exports.AuthParams = void 0;
27
+ const common_1 = require("@nestjs/common");
28
+ const _ = __importStar(require("lodash"));
29
+ class AuthParams {
30
+ constructor(params) {
31
+ this.modelIs = {
32
+ erp: false,
33
+ crm: false,
34
+ };
35
+ this.holderIs = {
36
+ user: false,
37
+ integration: false,
38
+ };
39
+ if (params) {
40
+ Object.keys(params).forEach((key) => {
41
+ if (typeof params[key] === 'object') {
42
+ this[key] = _.merge(this[key], params[key]);
43
+ }
44
+ else {
45
+ this[key] = params[key];
46
+ }
47
+ });
48
+ }
49
+ }
50
+ }
51
+ exports.AuthParams = AuthParams;
52
+ exports.InitialAuthParams = new AuthParams();
53
+ exports.GetAuthParams = (0, common_1.createParamDecorator)((_data, ctx) => {
54
+ const type = _data?.ctxType || ctx.getType();
55
+ const getTarget = () => {
56
+ if (type === 'ws')
57
+ return ctx.switchToWs().getClient();
58
+ return ctx.switchToHttp().getRequest();
59
+ };
60
+ return getTarget()?.authParams;
61
+ });
62
+ exports.GetWsAuthParams = (0, common_1.createParamDecorator)((_data, ctx) => {
63
+ return ctx.switchToWs().getClient()?.authParams;
64
+ });
@@ -0,0 +1,2 @@
1
+ import { DecoratorForReqOptions } from '@my-nestjs-kit/core';
2
+ export declare const GetSession: (...dataOrPipes: (DecoratorForReqOptions | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetSession = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ exports.GetSession = (0, common_1.createParamDecorator)((_data, ctx) => {
6
+ const type = _data?.ctxType || ctx.getType();
7
+ const getTarget = () => {
8
+ if (type === 'ws')
9
+ return ctx.switchToWs().getClient();
10
+ return ctx.switchToHttp().getRequest();
11
+ };
12
+ return getTarget()?.session ?? null;
13
+ });
@@ -0,0 +1,2 @@
1
+ import { DecoratorForReqOptions } from '@my-nestjs-kit/core';
2
+ export declare const GetUser: (...dataOrPipes: (DecoratorForReqOptions | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetUser = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ exports.GetUser = (0, common_1.createParamDecorator)((_data, ctx) => {
6
+ const type = _data?.ctxType || ctx.getType();
7
+ const getTarget = () => {
8
+ if (type === 'ws')
9
+ return ctx.switchToWs().getClient();
10
+ return ctx.switchToHttp().getRequest();
11
+ };
12
+ return getTarget()?.user;
13
+ });
@@ -0,0 +1,3 @@
1
+ import { Reflector } from '@nestjs/core';
2
+ export declare const Public: () => import("@nestjs/common").CustomDecorator<string>;
3
+ export declare function isPublicRoute(reflector: Reflector, ...targets: any[]): boolean;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPublicRoute = exports.Public = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const route_auth_configs_helper_1 = require("../route-auth-configs.helper");
6
+ const Public = () => {
7
+ return (0, common_1.SetMetadata)(route_auth_configs_helper_1.AuthConfigsMetaStorage.IS_PUBLIC_KEY, new route_auth_configs_helper_1.AuthConfigsMetaStorage({
8
+ isPublic: true,
9
+ }));
10
+ };
11
+ exports.Public = Public;
12
+ const isPublic = (reflector) => (target) => {
13
+ return reflector.get(route_auth_configs_helper_1.AuthConfigsMetaStorage.IS_PUBLIC_KEY, target);
14
+ };
15
+ function isPublicRoute(reflector, ...targets) {
16
+ return targets.some(isPublic(reflector));
17
+ }
18
+ exports.isPublicRoute = isPublicRoute;
@@ -0,0 +1,3 @@
1
+ import type { AuthConfigs } from '../types/auth.types';
2
+ export declare const AUTH_CONFIGS_META_STORAGE_KEY = "auth_configs_meta_storage";
3
+ export declare const SetAuthConfig: <Roles extends string = string, Session extends string = any, Action extends string = string>(config?: AuthConfigs<Roles, Session, Action>) => import("@nestjs/common").CustomDecorator<string>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SetAuthConfig = exports.AUTH_CONFIGS_META_STORAGE_KEY = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const route_auth_configs_helper_1 = require("../route-auth-configs.helper");
6
+ exports.AUTH_CONFIGS_META_STORAGE_KEY = 'auth_configs_meta_storage';
7
+ const SetAuthConfig = (config = {
8
+ model: { erp: true },
9
+ holder: { user: true },
10
+ }) => {
11
+ return (0, common_1.SetMetadata)(route_auth_configs_helper_1.AuthConfigsMetaStorage.KEY, new route_auth_configs_helper_1.AuthConfigsMetaStorage(config));
12
+ };
13
+ exports.SetAuthConfig = SetAuthConfig;
@@ -0,0 +1,8 @@
1
+ import { AccessTokenTypeEnum } from '../access-tokens/access-tokens.types';
2
+ import { PartialRecord } from '@my-nestjs-kit/core';
3
+ export declare class ConfirmSecureActionDto implements PartialRecord<keyof typeof AccessTokenTypeEnum, string> {
4
+ token?: string;
5
+ code?: string;
6
+ Bearer?: string;
7
+ verifyBy?: AccessTokenTypeEnum;
8
+ }