@bearei/nest 0.0.0-stage → 2.0.0-dev.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.
Files changed (145) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/LICENSE +21 -0
  3. package/README.md +100 -2
  4. package/README.zh-CN.md +103 -0
  5. package/dist/action-log/action-log.interface.d.ts +12 -0
  6. package/dist/action-log/action-log.interface.js +2 -0
  7. package/dist/action-log/action-log.module.d.ts +2 -0
  8. package/dist/action-log/action-log.module.js +22 -0
  9. package/dist/action-log/action-log.service.d.ts +10 -0
  10. package/dist/action-log/action-log.service.js +42 -0
  11. package/dist/action-log/index.d.ts +3 -0
  12. package/dist/action-log/index.js +19 -0
  13. package/dist/authentication/authentication-context.interceptor.d.ts +7 -0
  14. package/dist/authentication/authentication-context.interceptor.js +70 -0
  15. package/dist/authentication/authentication.enum.d.ts +6 -0
  16. package/dist/authentication/authentication.enum.js +9 -0
  17. package/dist/authentication/authentication.guard.d.ts +13 -0
  18. package/dist/authentication/authentication.guard.js +92 -0
  19. package/dist/authentication/authentication.interface.d.ts +2 -0
  20. package/dist/authentication/authentication.interface.js +2 -0
  21. package/dist/authentication/index.d.ts +4 -0
  22. package/dist/authentication/index.js +20 -0
  23. package/dist/authorization/authorization.interface.d.ts +3 -0
  24. package/dist/authorization/authorization.interface.js +2 -0
  25. package/dist/authorization/authorization.module.d.ts +2 -0
  26. package/dist/authorization/authorization.module.js +22 -0
  27. package/dist/authorization/authorization.service.d.ts +10 -0
  28. package/dist/authorization/authorization.service.js +56 -0
  29. package/dist/authorization/index.d.ts +3 -0
  30. package/dist/authorization/index.js +19 -0
  31. package/dist/base-service/base-service.interface.d.ts +84 -0
  32. package/dist/base-service/base-service.interface.js +2 -0
  33. package/dist/base-service/base-service.module.d.ts +2 -0
  34. package/dist/base-service/base-service.module.js +22 -0
  35. package/dist/base-service/base-service.service.d.ts +27 -0
  36. package/dist/base-service/base-service.service.js +517 -0
  37. package/dist/base-service/index.d.ts +3 -0
  38. package/dist/base-service/index.js +19 -0
  39. package/dist/common.dto.d.ts +19 -0
  40. package/dist/common.dto.js +111 -0
  41. package/dist/common.entity.d.ts +11 -0
  42. package/dist/common.entity.js +76 -0
  43. package/dist/common.enum.d.ts +19 -0
  44. package/dist/common.enum.js +24 -0
  45. package/dist/common.interface.d.ts +19 -0
  46. package/dist/common.interface.js +2 -0
  47. package/dist/database/database.module.d.ts +5 -0
  48. package/dist/database/database.module.js +58 -0
  49. package/dist/database/index.d.ts +1 -0
  50. package/dist/database/index.js +17 -0
  51. package/dist/decorators/allow-access.decorator.d.ts +3 -0
  52. package/dist/decorators/allow-access.decorator.js +7 -0
  53. package/dist/decorators/index.d.ts +8 -0
  54. package/dist/decorators/index.js +24 -0
  55. package/dist/decorators/is-captcha.decorator.d.ts +2 -0
  56. package/dist/decorators/is-captcha.decorator.js +23 -0
  57. package/dist/decorators/is-nano-id.decorator.d.ts +2 -0
  58. package/dist/decorators/is-nano-id.decorator.js +22 -0
  59. package/dist/decorators/is-password.decorator.d.ts +2 -0
  60. package/dist/decorators/is-password.decorator.js +23 -0
  61. package/dist/decorators/is-version.decorator.d.ts +2 -0
  62. package/dist/decorators/is-version.decorator.js +22 -0
  63. package/dist/decorators/omit-entity-keys.decorator.d.ts +2 -0
  64. package/dist/decorators/omit-entity-keys.decorator.js +7 -0
  65. package/dist/decorators/require-permissions.decorator.d.ts +3 -0
  66. package/dist/decorators/require-permissions.decorator.js +7 -0
  67. package/dist/decorators/require-subscription-features.decorator.d.ts +3 -0
  68. package/dist/decorators/require-subscription-features.decorator.js +7 -0
  69. package/dist/exception/exception.enum.d.ts +12 -0
  70. package/dist/exception/exception.enum.js +16 -0
  71. package/dist/exception/exception.interface.d.ts +9 -0
  72. package/dist/exception/exception.interface.js +2 -0
  73. package/dist/exception/http.exception.d.ts +4 -0
  74. package/dist/exception/http.exception.js +47 -0
  75. package/dist/exception/index.d.ts +3 -0
  76. package/dist/exception/index.js +19 -0
  77. package/dist/external/external.interface.d.ts +58 -0
  78. package/dist/external/external.interface.js +2 -0
  79. package/dist/external/external.module.d.ts +2 -0
  80. package/dist/external/external.module.js +24 -0
  81. package/dist/external/external.service.d.ts +15 -0
  82. package/dist/external/external.service.js +160 -0
  83. package/dist/external/index.d.ts +3 -0
  84. package/dist/external/index.js +19 -0
  85. package/dist/index.d.ts +17 -0
  86. package/dist/index.js +39 -0
  87. package/dist/jwt/index.d.ts +3 -0
  88. package/dist/jwt/index.js +19 -0
  89. package/dist/jwt/jwt.interface.d.ts +15 -0
  90. package/dist/jwt/jwt.interface.js +2 -0
  91. package/dist/jwt/jwt.module.d.ts +2 -0
  92. package/dist/jwt/jwt.module.js +43 -0
  93. package/dist/jwt/jwt.service.d.ts +10 -0
  94. package/dist/jwt/jwt.service.js +52 -0
  95. package/dist/permission/index.d.ts +3 -0
  96. package/dist/permission/index.js +19 -0
  97. package/dist/permission/permission.enum.d.ts +70 -0
  98. package/dist/permission/permission.enum.js +73 -0
  99. package/dist/permission/permission.guard.d.ts +9 -0
  100. package/dist/permission/permission.guard.js +55 -0
  101. package/dist/permission/permission.interface.d.ts +2 -0
  102. package/dist/permission/permission.interface.js +2 -0
  103. package/dist/redis/index.d.ts +3 -0
  104. package/dist/redis/index.js +19 -0
  105. package/dist/redis/redis.interface.d.ts +4 -0
  106. package/dist/redis/redis.interface.js +2 -0
  107. package/dist/redis/redis.module.d.ts +2 -0
  108. package/dist/redis/redis.module.js +22 -0
  109. package/dist/redis/redis.service.d.ts +14 -0
  110. package/dist/redis/redis.service.js +51 -0
  111. package/dist/subscription-feature/index.d.ts +3 -0
  112. package/dist/subscription-feature/index.js +19 -0
  113. package/dist/subscription-feature/subscription-feature.enum.d.ts +3 -0
  114. package/dist/subscription-feature/subscription-feature.enum.js +6 -0
  115. package/dist/subscription-feature/subscription-feature.interceptor.d.ts +9 -0
  116. package/dist/subscription-feature/subscription-feature.interceptor.js +68 -0
  117. package/dist/subscription-feature/subscription-feature.interface.d.ts +2 -0
  118. package/dist/subscription-feature/subscription-feature.interface.js +2 -0
  119. package/dist/utils/create-response-sanitizer/create-response-sanitizer.utils.d.ts +1 -0
  120. package/dist/utils/create-response-sanitizer/create-response-sanitizer.utils.js +23 -0
  121. package/dist/utils/create-response-sanitizer/index.d.ts +1 -0
  122. package/dist/utils/create-response-sanitizer/index.js +17 -0
  123. package/dist/utils/extract-bearer-token/extract-bearer-token.utils.d.ts +1 -0
  124. package/dist/utils/extract-bearer-token/extract-bearer-token.utils.js +13 -0
  125. package/dist/utils/extract-bearer-token/index.d.ts +1 -0
  126. package/dist/utils/extract-bearer-token/index.js +17 -0
  127. package/dist/utils/format-mobile-number/format-mobile-number.utils.d.ts +1 -0
  128. package/dist/utils/format-mobile-number/format-mobile-number.utils.js +5 -0
  129. package/dist/utils/format-mobile-number/index.d.ts +1 -0
  130. package/dist/utils/format-mobile-number/index.js +17 -0
  131. package/dist/utils/generate-random-number-string/generate-random-number-string.utils.d.ts +1 -0
  132. package/dist/utils/generate-random-number-string/generate-random-number-string.utils.js +6 -0
  133. package/dist/utils/generate-random-number-string/index.d.ts +1 -0
  134. package/dist/utils/generate-random-number-string/index.js +17 -0
  135. package/dist/utils/index.d.ts +6 -0
  136. package/dist/utils/index.js +22 -0
  137. package/dist/utils/run-with-database-retry/index.d.ts +1 -0
  138. package/dist/utils/run-with-database-retry/index.js +17 -0
  139. package/dist/utils/run-with-database-retry/run-with-database-retry.utils.d.ts +1 -0
  140. package/dist/utils/run-with-database-retry/run-with-database-retry.utils.js +23 -0
  141. package/dist/utils/sign/index.d.ts +1 -0
  142. package/dist/utils/sign/index.js +17 -0
  143. package/dist/utils/sign/sign.utils.d.ts +5 -0
  144. package/dist/utils/sign/sign.utils.js +82 -0
  145. package/package.json +126 -3
@@ -0,0 +1,76 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CommonEntity = void 0;
16
+ const dayjs_1 = __importDefault(require("dayjs"));
17
+ const nanoid_1 = require("nanoid");
18
+ const typeorm_1 = require("typeorm");
19
+ let CommonEntity = class CommonEntity extends typeorm_1.BaseEntity {
20
+ internalId;
21
+ id;
22
+ version;
23
+ createdAt;
24
+ updatedAt;
25
+ deletedAt;
26
+ beforeInsert() {
27
+ const now = dayjs_1.default.utc().toISOString();
28
+ this.createdAt = this.createdAt || now;
29
+ this.id = this.id || (0, nanoid_1.nanoid)();
30
+ this.updatedAt = now;
31
+ }
32
+ beforeUpdate() {
33
+ this.updatedAt = dayjs_1.default.utc().toISOString();
34
+ }
35
+ };
36
+ exports.CommonEntity = CommonEntity;
37
+ __decorate([
38
+ (0, typeorm_1.PrimaryGeneratedColumn)('identity', { name: 'internal_id' }),
39
+ __metadata("design:type", Number)
40
+ ], CommonEntity.prototype, "internalId", void 0);
41
+ __decorate([
42
+ (0, typeorm_1.Column)({ length: 32, nullable: false, type: 'varchar' }),
43
+ __metadata("design:type", String)
44
+ ], CommonEntity.prototype, "id", void 0);
45
+ __decorate([
46
+ (0, typeorm_1.VersionColumn)({ nullable: false }),
47
+ __metadata("design:type", Number)
48
+ ], CommonEntity.prototype, "version", void 0);
49
+ __decorate([
50
+ (0, typeorm_1.CreateDateColumn)({ name: 'created_at', nullable: false, type: 'timestamptz' }),
51
+ __metadata("design:type", Object)
52
+ ], CommonEntity.prototype, "createdAt", void 0);
53
+ __decorate([
54
+ (0, typeorm_1.UpdateDateColumn)({ name: 'updated_at', nullable: false, type: 'timestamptz' }),
55
+ __metadata("design:type", Object)
56
+ ], CommonEntity.prototype, "updatedAt", void 0);
57
+ __decorate([
58
+ (0, typeorm_1.DeleteDateColumn)({ default: null, name: 'deleted_at', type: 'timestamptz' }),
59
+ __metadata("design:type", Object)
60
+ ], CommonEntity.prototype, "deletedAt", void 0);
61
+ __decorate([
62
+ (0, typeorm_1.BeforeInsert)(),
63
+ __metadata("design:type", Function),
64
+ __metadata("design:paramtypes", []),
65
+ __metadata("design:returntype", void 0)
66
+ ], CommonEntity.prototype, "beforeInsert", null);
67
+ __decorate([
68
+ (0, typeorm_1.BeforeUpdate)(),
69
+ __metadata("design:type", Function),
70
+ __metadata("design:paramtypes", []),
71
+ __metadata("design:returntype", void 0)
72
+ ], CommonEntity.prototype, "beforeUpdate", null);
73
+ exports.CommonEntity = CommonEntity = __decorate([
74
+ (0, typeorm_1.Index)(['createdAt']),
75
+ (0, typeorm_1.Index)(['id'], { unique: true })
76
+ ], CommonEntity);
@@ -0,0 +1,19 @@
1
+ export { LANGUAGE, ORDER } from '@bearei/contracts';
2
+ export declare const ACTION_RESULT: {
3
+ readonly FAILURE: "FAILURE";
4
+ readonly SUCCESS: "SUCCESS";
5
+ };
6
+ export declare const ACTION: {
7
+ readonly CREATE: "CREATE";
8
+ readonly DELETE: "DELETE";
9
+ readonly EXPORT: "EXPORT";
10
+ readonly IMPORT: "IMPORT";
11
+ readonly SIGN_IN: "SIGN_IN";
12
+ readonly SIGN_OUT: "SIGN_OUT";
13
+ readonly SIGN_UP: "SIGN_UP";
14
+ readonly UPDATE: "UPDATE";
15
+ };
16
+ export declare const VALIDATION_METHOD: {
17
+ readonly AND: "AND";
18
+ readonly OR: "OR";
19
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VALIDATION_METHOD = exports.ACTION = exports.ACTION_RESULT = exports.ORDER = exports.LANGUAGE = void 0;
4
+ var contracts_1 = require("@bearei/contracts");
5
+ Object.defineProperty(exports, "LANGUAGE", { enumerable: true, get: function () { return contracts_1.LANGUAGE; } });
6
+ Object.defineProperty(exports, "ORDER", { enumerable: true, get: function () { return contracts_1.ORDER; } });
7
+ exports.ACTION_RESULT = {
8
+ FAILURE: 'FAILURE',
9
+ SUCCESS: 'SUCCESS'
10
+ };
11
+ exports.ACTION = {
12
+ CREATE: 'CREATE',
13
+ DELETE: 'DELETE',
14
+ EXPORT: 'EXPORT',
15
+ IMPORT: 'IMPORT',
16
+ SIGN_IN: 'SIGN_IN',
17
+ SIGN_OUT: 'SIGN_OUT',
18
+ SIGN_UP: 'SIGN_UP',
19
+ UPDATE: 'UPDATE'
20
+ };
21
+ exports.VALIDATION_METHOD = {
22
+ AND: 'AND',
23
+ OR: 'OR'
24
+ };
@@ -0,0 +1,19 @@
1
+ import type { ReservedRequestHeaderName } from '@bearei/contracts';
2
+ import type { AxiosRequestConfig } from 'axios';
3
+ import type { ACTION, ACTION_RESULT, VALIDATION_METHOD } from './common.enum';
4
+ export type { Language, Order, PaginatedResult } from '@bearei/contracts';
5
+ export type ReservedRequestHeaders = Record<ReservedRequestHeaderName, string>;
6
+ export type RequestHeaders = Record<string, string> | (ReservedRequestHeaders & Record<string, string | undefined>) | NonNullable<AxiosRequestConfig['headers']>;
7
+ export interface AuthenticatedRequest {
8
+ audience?: string;
9
+ headers: RequestHeaders;
10
+ isInternalAccess?: boolean;
11
+ isSubscriptionEvaluated?: boolean;
12
+ issuer: string;
13
+ params: Record<string, string>;
14
+ query: Record<string, string>;
15
+ subject: string;
16
+ }
17
+ export type Action = (typeof ACTION)[keyof typeof ACTION];
18
+ export type ActionResult = (typeof ACTION_RESULT)[keyof typeof ACTION_RESULT];
19
+ export type ValidationMethod = (typeof VALIDATION_METHOD)[keyof typeof VALIDATION_METHOD];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { TypeOrmModuleOptions } from '@nestjs/typeorm';
3
+ export declare class DatabaseModule {
4
+ static forRoot(options?: Partial<TypeOrmModuleOptions>): DynamicModule;
5
+ }
@@ -0,0 +1,58 @@
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 DatabaseModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.DatabaseModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const config_1 = require("@nestjs/config");
13
+ const typeorm_1 = require("@nestjs/typeorm");
14
+ let DatabaseModule = DatabaseModule_1 = class DatabaseModule {
15
+ static forRoot(options = {}) {
16
+ return {
17
+ imports: [
18
+ config_1.ConfigModule,
19
+ typeorm_1.TypeOrmModule.forRootAsync({
20
+ imports: [config_1.ConfigModule],
21
+ inject: [config_1.ConfigService],
22
+ useFactory: async (configService) => {
23
+ const baseConfig = {
24
+ database: configService.get('database.database'),
25
+ entities: configService.get('database.entities'),
26
+ extra: {
27
+ connectionTimeoutMillis: configService.get('database.connectionTimeoutMillis') ?? 5000,
28
+ idleTimeoutMillis: configService.get('database.idleTimeoutMillis') ?? 5000,
29
+ keepAliveInitialDelayMillis: configService.get('database.keepAliveInitialDelayMillis') ?? 10000,
30
+ max: configService.get('database.max') ?? 10,
31
+ maxLifetimeSeconds: configService.get('database.maxLifetimeSeconds') ?? 1800,
32
+ min: configService.get('database.min') ?? 0
33
+ },
34
+ host: configService.get('database.host'),
35
+ logging: false,
36
+ password: configService.get('database.password'),
37
+ port: configService.get('database.port'),
38
+ synchronize: false,
39
+ type: configService.get('database.type'),
40
+ username: configService.get('database.username'),
41
+ ...(process.env.NODE_ENV !== 'production' && {
42
+ logger: 'advanced-console',
43
+ logging: true
44
+ }),
45
+ ...options
46
+ };
47
+ return baseConfig;
48
+ }
49
+ })
50
+ ],
51
+ module: DatabaseModule_1
52
+ };
53
+ }
54
+ };
55
+ exports.DatabaseModule = DatabaseModule;
56
+ exports.DatabaseModule = DatabaseModule = DatabaseModule_1 = __decorate([
57
+ (0, common_1.Module)({})
58
+ ], DatabaseModule);
@@ -0,0 +1 @@
1
+ export * from './database.module';
@@ -0,0 +1,17 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./database.module"), exports);
@@ -0,0 +1,3 @@
1
+ import type { AccessType } from '../authentication';
2
+ export declare const ALLOWED_ACCESS_TYPES = "allowedAccessTypes";
3
+ export declare const AllowAccess: (accessTypes: AccessType[]) => import("@nestjs/common").CustomDecorator<string>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AllowAccess = exports.ALLOWED_ACCESS_TYPES = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ exports.ALLOWED_ACCESS_TYPES = 'allowedAccessTypes';
6
+ const AllowAccess = (accessTypes) => (0, common_1.SetMetadata)(exports.ALLOWED_ACCESS_TYPES, accessTypes);
7
+ exports.AllowAccess = AllowAccess;
@@ -0,0 +1,8 @@
1
+ export * from './allow-access.decorator';
2
+ export * from './is-captcha.decorator';
3
+ export * from './is-nano-id.decorator';
4
+ export * from './is-password.decorator';
5
+ export * from './is-version.decorator';
6
+ export * from './omit-entity-keys.decorator';
7
+ export * from './require-permissions.decorator';
8
+ export * from './require-subscription-features.decorator';
@@ -0,0 +1,24 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./allow-access.decorator"), exports);
18
+ __exportStar(require("./is-captcha.decorator"), exports);
19
+ __exportStar(require("./is-nano-id.decorator"), exports);
20
+ __exportStar(require("./is-password.decorator"), exports);
21
+ __exportStar(require("./is-version.decorator"), exports);
22
+ __exportStar(require("./omit-entity-keys.decorator"), exports);
23
+ __exportStar(require("./require-permissions.decorator"), exports);
24
+ __exportStar(require("./require-subscription-features.decorator"), exports);
@@ -0,0 +1,2 @@
1
+ import type { ValidationOptions } from 'class-validator';
2
+ export declare const IsCaptcha: <T extends object>(validationOptions?: ValidationOptions) => (object: T, propertyName: string) => void;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsCaptcha = void 0;
4
+ const class_validator_1 = require("class-validator");
5
+ const IsCaptcha = (validationOptions) => (object, propertyName) => {
6
+ const captchaRegex = /^\d{6}$/;
7
+ return (0, class_validator_1.registerDecorator)({
8
+ name: 'IsCaptcha',
9
+ options: {
10
+ ...validationOptions,
11
+ message: validationOptions?.message ??
12
+ `${propertyName} must be a valid captcha. Captchas should follow the pattern: ${captchaRegex}.`
13
+ },
14
+ propertyName: propertyName,
15
+ target: object.constructor,
16
+ validator: {
17
+ validate(value) {
18
+ return typeof value === 'string' && captchaRegex.test(value);
19
+ }
20
+ }
21
+ });
22
+ };
23
+ exports.IsCaptcha = IsCaptcha;
@@ -0,0 +1,2 @@
1
+ import type { ValidationOptions } from 'class-validator';
2
+ export declare const IsNanoId: <T extends object>(validationOptions?: ValidationOptions) => (object: T, propertyName: string) => void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsNanoId = void 0;
4
+ const class_validator_1 = require("class-validator");
5
+ const IsNanoId = (validationOptions) => (object, propertyName) => {
6
+ const nanoIdRegex = /^[A-Za-z0-9_-]{8,32}$/;
7
+ return (0, class_validator_1.registerDecorator)({
8
+ name: 'isNanoId',
9
+ options: {
10
+ ...validationOptions,
11
+ message: validationOptions?.message ?? `${propertyName} must be a valid nanoId.`
12
+ },
13
+ propertyName: propertyName,
14
+ target: object.constructor,
15
+ validator: {
16
+ validate(value) {
17
+ return typeof value === 'string' && nanoIdRegex.test(value);
18
+ }
19
+ }
20
+ });
21
+ };
22
+ exports.IsNanoId = IsNanoId;
@@ -0,0 +1,2 @@
1
+ import type { ValidationOptions } from 'class-validator';
2
+ export declare const IsPassword: <T extends object>(validationOptions?: ValidationOptions) => (object: T, propertyName: string) => void;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsPassword = void 0;
4
+ const class_validator_1 = require("class-validator");
5
+ const IsPassword = (validationOptions) => (object, propertyName) => {
6
+ const passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[A-Za-z\d!@#$%^&*()_+\-=[{};':"\\|,.<>/?]{8,32}$/;
7
+ return (0, class_validator_1.registerDecorator)({
8
+ name: 'isPassword',
9
+ options: {
10
+ ...validationOptions,
11
+ message: validationOptions?.message ??
12
+ `${propertyName} is not a valid password. Passwords should follow the pattern: ${passwordRegex}.`
13
+ },
14
+ propertyName: propertyName,
15
+ target: object.constructor,
16
+ validator: {
17
+ validate(value) {
18
+ return typeof value === 'string' && passwordRegex.test(value);
19
+ }
20
+ }
21
+ });
22
+ };
23
+ exports.IsPassword = IsPassword;
@@ -0,0 +1,2 @@
1
+ import type { ValidationOptions } from 'class-validator';
2
+ export declare const IsVersion: <T extends object>(validationOptions?: ValidationOptions) => (object: T, propertyName: string) => void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsVersion = void 0;
4
+ const class_validator_1 = require("class-validator");
5
+ const IsVersion = (validationOptions) => (object, propertyName) => {
6
+ const versionRegex = /^\d+\.\d+\.\d+$/;
7
+ return (0, class_validator_1.registerDecorator)({
8
+ name: 'isVersion',
9
+ options: {
10
+ ...validationOptions,
11
+ message: validationOptions?.message ?? `${propertyName} must be a valid version number.`
12
+ },
13
+ propertyName: propertyName,
14
+ target: object.constructor,
15
+ validator: {
16
+ validate(value) {
17
+ return typeof value === 'string' && versionRegex.test(value);
18
+ }
19
+ }
20
+ });
21
+ };
22
+ exports.IsVersion = IsVersion;
@@ -0,0 +1,2 @@
1
+ export declare const OMIT_ENTITY_KEYS = "omitEntityKeys";
2
+ export declare const OmitEntityKeys: (keys: string[]) => import("@nestjs/common").CustomDecorator<string>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OmitEntityKeys = exports.OMIT_ENTITY_KEYS = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ exports.OMIT_ENTITY_KEYS = 'omitEntityKeys';
6
+ const OmitEntityKeys = (keys) => (0, common_1.SetMetadata)(exports.OMIT_ENTITY_KEYS, keys);
7
+ exports.OmitEntityKeys = OmitEntityKeys;
@@ -0,0 +1,3 @@
1
+ import type { Permission } from '../permission';
2
+ export declare const REQUIRED_PERMISSIONS = "requiredPermissions";
3
+ export declare const RequirePermissions: (permissions: Permission[]) => import("@nestjs/common").CustomDecorator<string>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequirePermissions = exports.REQUIRED_PERMISSIONS = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ exports.REQUIRED_PERMISSIONS = 'requiredPermissions';
6
+ const RequirePermissions = (permissions) => (0, common_1.SetMetadata)(exports.REQUIRED_PERMISSIONS, permissions);
7
+ exports.RequirePermissions = RequirePermissions;
@@ -0,0 +1,3 @@
1
+ import type { SubscriptionFeature } from '../subscription-feature';
2
+ export declare const REQUIRED_SUBSCRIPTION_FEATURES = "requiredSubscriptionFeatures";
3
+ export declare const RequireSubscriptionFeatures: (subscriptionFeatures: SubscriptionFeature[]) => import("@nestjs/common").CustomDecorator<string>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequireSubscriptionFeatures = exports.REQUIRED_SUBSCRIPTION_FEATURES = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ exports.REQUIRED_SUBSCRIPTION_FEATURES = 'requiredSubscriptionFeatures';
6
+ const RequireSubscriptionFeatures = (subscriptionFeatures) => (0, common_1.SetMetadata)(exports.REQUIRED_SUBSCRIPTION_FEATURES, subscriptionFeatures);
7
+ exports.RequireSubscriptionFeatures = RequireSubscriptionFeatures;
@@ -0,0 +1,12 @@
1
+ export { HTTP_EXCEPTION_CODE } from '@bearei/contracts';
2
+ export declare const HTTP_EXCEPTION: {
3
+ readonly BAD_GATEWAY: "BAD_GATEWAY";
4
+ readonly BAD_REQUEST: "BAD_REQUEST";
5
+ readonly FORBIDDEN: "FORBIDDEN";
6
+ readonly GENERIC: "GENERIC";
7
+ readonly INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR";
8
+ readonly NOT_FOUND: "NOT_FOUND";
9
+ readonly REQUEST_TIMEOUT: "REQUEST_TIMEOUT";
10
+ readonly UNAUTHORIZED: "UNAUTHORIZED";
11
+ readonly UNPROCESSABLE_ENTITY: "UNPROCESSABLE_ENTITY";
12
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HTTP_EXCEPTION = exports.HTTP_EXCEPTION_CODE = void 0;
4
+ var contracts_1 = require("@bearei/contracts");
5
+ Object.defineProperty(exports, "HTTP_EXCEPTION_CODE", { enumerable: true, get: function () { return contracts_1.HTTP_EXCEPTION_CODE; } });
6
+ exports.HTTP_EXCEPTION = {
7
+ BAD_GATEWAY: 'BAD_GATEWAY',
8
+ BAD_REQUEST: 'BAD_REQUEST',
9
+ FORBIDDEN: 'FORBIDDEN',
10
+ GENERIC: 'GENERIC',
11
+ INTERNAL_SERVER_ERROR: 'INTERNAL_SERVER_ERROR',
12
+ NOT_FOUND: 'NOT_FOUND',
13
+ REQUEST_TIMEOUT: 'REQUEST_TIMEOUT',
14
+ UNAUTHORIZED: 'UNAUTHORIZED',
15
+ UNPROCESSABLE_ENTITY: 'UNPROCESSABLE_ENTITY'
16
+ };
@@ -0,0 +1,9 @@
1
+ import type { HTTP_EXCEPTION } from './exception.enum';
2
+ export type { ApiErrorBody, HttpExceptionCode } from '@bearei/contracts';
3
+ export interface ThrowHttpExceptionOptions {
4
+ code?: number;
5
+ message?: string;
6
+ service?: string;
7
+ status?: number;
8
+ }
9
+ export type HttpExceptionKind = (typeof HTTP_EXCEPTION)[keyof typeof HTTP_EXCEPTION];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { HttpException } from '@nestjs/common';
2
+ import type { HttpExceptionKind, ThrowHttpExceptionOptions } from './exception.interface';
3
+ export declare const createHttpException: (httpExceptionKind: HttpExceptionKind, options: ThrowHttpExceptionOptions) => HttpException;
4
+ export declare const throwHttpException: (httpExceptionKind: HttpExceptionKind, options: ThrowHttpExceptionOptions) => never;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwHttpException = exports.createHttpException = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const exception_enum_1 = require("./exception.enum");
6
+ const buildMessage = (message, service) => (service ? `${message} service:${service}` : message);
7
+ const EXCEPTION_FACTORY_MAP = {
8
+ [exception_enum_1.HTTP_EXCEPTION.BAD_GATEWAY]: ({ code = exception_enum_1.HTTP_EXCEPTION_CODE.BAD_GATEWAY, message = 'Bad Gateway.', service }) => new common_1.BadGatewayException({
9
+ code,
10
+ message: buildMessage(message, service),
11
+ statusCode: common_1.HttpStatus.BAD_GATEWAY
12
+ }),
13
+ [exception_enum_1.HTTP_EXCEPTION.BAD_REQUEST]: ({ code = exception_enum_1.HTTP_EXCEPTION_CODE.BAD_REQUEST, message = 'Bad Request.', service }) => new common_1.BadRequestException({
14
+ code,
15
+ message: buildMessage(message, service),
16
+ statusCode: common_1.HttpStatus.BAD_REQUEST
17
+ }),
18
+ [exception_enum_1.HTTP_EXCEPTION.FORBIDDEN]: ({ code = exception_enum_1.HTTP_EXCEPTION_CODE.FORBIDDEN, message = 'Forbidden', service }) => new common_1.ForbiddenException({ code, message: buildMessage(message, service), statusCode: common_1.HttpStatus.FORBIDDEN }),
19
+ [exception_enum_1.HTTP_EXCEPTION.GENERIC]: ({ code = exception_enum_1.HTTP_EXCEPTION_CODE.INTERNAL_SERVER_ERROR, message = 'Internal Server Error', service, status = common_1.HttpStatus.INTERNAL_SERVER_ERROR }) => new common_1.HttpException({ code, message: buildMessage(message, service), statusCode: status }, status),
20
+ [exception_enum_1.HTTP_EXCEPTION.INTERNAL_SERVER_ERROR]: ({ code = exception_enum_1.HTTP_EXCEPTION_CODE.INTERNAL_SERVER_ERROR, message = 'Internal Server Error', service }) => new common_1.InternalServerErrorException({
21
+ code,
22
+ message: buildMessage(message, service),
23
+ statusCode: common_1.HttpStatus.INTERNAL_SERVER_ERROR
24
+ }),
25
+ [exception_enum_1.HTTP_EXCEPTION.NOT_FOUND]: ({ code = exception_enum_1.HTTP_EXCEPTION_CODE.NOT_FOUND, message = 'Not Found', service }) => new common_1.NotFoundException({ code, message: buildMessage(message, service), statusCode: common_1.HttpStatus.NOT_FOUND }),
26
+ [exception_enum_1.HTTP_EXCEPTION.REQUEST_TIMEOUT]: ({ code = exception_enum_1.HTTP_EXCEPTION_CODE.REQUEST_TIMEOUT, message = 'Request Timeout.', service }) => new common_1.RequestTimeoutException({
27
+ code,
28
+ message: buildMessage(message, service),
29
+ statusCode: common_1.HttpStatus.REQUEST_TIMEOUT
30
+ }),
31
+ [exception_enum_1.HTTP_EXCEPTION.UNAUTHORIZED]: ({ code = exception_enum_1.HTTP_EXCEPTION_CODE.UNAUTHORIZED, message = 'Unauthorized', service }) => new common_1.UnauthorizedException({
32
+ code,
33
+ message: buildMessage(message, service),
34
+ statusCode: common_1.HttpStatus.UNAUTHORIZED
35
+ }),
36
+ [exception_enum_1.HTTP_EXCEPTION.UNPROCESSABLE_ENTITY]: ({ code = exception_enum_1.HTTP_EXCEPTION_CODE.UNPROCESSABLE_ENTITY, message = 'Unprocessable Entity', service }) => new common_1.UnprocessableEntityException({
37
+ code,
38
+ message: buildMessage(message, service),
39
+ statusCode: common_1.HttpStatus.UNPROCESSABLE_ENTITY
40
+ })
41
+ };
42
+ const createHttpException = (httpExceptionKind, options) => EXCEPTION_FACTORY_MAP[httpExceptionKind](options);
43
+ exports.createHttpException = createHttpException;
44
+ const throwHttpException = (httpExceptionKind, options) => {
45
+ throw (0, exports.createHttpException)(httpExceptionKind, options);
46
+ };
47
+ exports.throwHttpException = throwHttpException;
@@ -0,0 +1,3 @@
1
+ export * from './exception.enum';
2
+ export * from './exception.interface';
3
+ export * from './http.exception';
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./exception.enum"), exports);
18
+ __exportStar(require("./exception.interface"), exports);
19
+ __exportStar(require("./http.exception"), exports);
@@ -0,0 +1,58 @@
1
+ import type { AxiosRequestConfig } from 'axios';
2
+ import type { Action, ActionResult, RequestHeaders } from '../common.interface';
3
+ import type { Permission } from '../permission';
4
+ import type { SubscriptionFeature } from '../subscription-feature';
5
+ import { ListQueryDto } from '../common.dto';
6
+ import { CommonEntity } from '../common.entity';
7
+ export interface ExternalRequestOptions extends Omit<AxiosRequestConfig, 'headers'> {
8
+ headers: RequestHeaders;
9
+ isAsyncInvocation?: boolean;
10
+ path?: string;
11
+ serviceName: string;
12
+ version?: string;
13
+ }
14
+ export interface ExternalCreateActionLogOptions {
15
+ action: Action;
16
+ data: Record<string, unknown>;
17
+ message?: string;
18
+ raw: Record<string, unknown>;
19
+ result: ActionResult;
20
+ serviceName: string;
21
+ }
22
+ export interface FindUserPermissionsOptions extends ListQueryDto {
23
+ domainId: string;
24
+ keys: Permission[];
25
+ userId: string;
26
+ }
27
+ export interface FindUserSubscriptionFeaturesOptions extends ListQueryDto {
28
+ domainId: string;
29
+ keys: SubscriptionFeature[];
30
+ userId: string;
31
+ }
32
+ export interface ExternalRequestError {
33
+ cause?: {
34
+ code?: number | string;
35
+ };
36
+ code?: number | string;
37
+ message?: string;
38
+ response?: {
39
+ data?: {
40
+ code?: number;
41
+ message?: string;
42
+ };
43
+ status?: number;
44
+ };
45
+ status?: number;
46
+ }
47
+ export interface PermissionResult extends CommonEntity {
48
+ description: string;
49
+ domainId: string;
50
+ key: Permission;
51
+ protected: boolean;
52
+ resourceId: string;
53
+ }
54
+ export interface SubscriptionFeatureResult extends CommonEntity {
55
+ description: string;
56
+ domainId: string;
57
+ key: SubscriptionFeature;
58
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export declare class ExternalModule {
2
+ }