@mondart/nestjs-common-module 2.5.0 → 2.6.5
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/dist/decorators/iam-context.decorator.d.ts +2 -0
- package/dist/decorators/iam-context.decorator.js +25 -15
- package/dist/dto/response/iam-context.dto.d.ts +4 -5
- package/dist/dto/response/iam-context.dto.js +10 -15
- package/dist/interfaces/get-agent.interface.d.ts +0 -1
- package/dist/lib/captcha/captcha.decorator.d.ts +4 -0
- package/dist/lib/captcha/captcha.decorator.js +7 -0
- package/dist/lib/captcha/captcha.exception.d.ts +4 -0
- package/dist/lib/captcha/captcha.exception.js +11 -0
- package/dist/lib/captcha/captcha.guard.d.ts +16 -0
- package/dist/lib/captcha/captcha.guard.js +83 -0
- package/dist/lib/captcha/captcha.interface.d.ts +26 -0
- package/dist/lib/captcha/captcha.interface.js +4 -0
- package/dist/lib/captcha/captcha.module.d.ts +8 -0
- package/dist/lib/captcha/captcha.module.js +97 -0
- package/dist/lib/captcha/enums/captcha-decorators.enum.d.ts +3 -0
- package/dist/lib/captcha/enums/captcha-decorators.enum.js +7 -0
- package/dist/lib/captcha/enums/captcha-messages.enum.d.ts +3 -0
- package/dist/lib/captcha/enums/captcha-messages.enum.js +7 -0
- package/dist/lib/captcha/index.d.ts +5 -0
- package/dist/lib/captcha/index.js +9 -0
- package/dist/lib/core-crud/controllers/core-crud.controller.js +10 -7
- package/dist/lib/core-crud/services/core-crud.service.d.ts +16 -16
- package/dist/lib/core-crud/services/core-crud.service.js +16 -16
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +2 -0
- package/dist/lib/request/enums/http-methods.enum.d.ts +7 -0
- package/dist/lib/request/enums/http-methods.enum.js +11 -0
- package/dist/lib/request/index.d.ts +4 -0
- package/dist/lib/request/index.js +9 -0
- package/dist/lib/request/request.module.d.ts +2 -0
- package/dist/lib/request/request.module.js +23 -0
- package/dist/lib/request/request.service.d.ts +31 -0
- package/dist/lib/request/request.service.js +75 -0
- package/dist/lib/saga/exceptions/saga-invocation.exception.js +1 -1
- package/dist/lib/saga/index.d.ts +1 -0
- package/dist/lib/saga/index.js +3 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -1,44 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IamContext = void 0;
|
|
3
|
+
exports.getIamContext = exports.IamContext = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const crypto_1 = require("crypto");
|
|
6
6
|
const iam_context_dto_1 = require("../dto/response/iam-context.dto");
|
|
7
7
|
exports.IamContext = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
8
8
|
const request = ctx.switchToHttp().getRequest();
|
|
9
|
-
|
|
9
|
+
return (0, exports.getIamContext)(request);
|
|
10
|
+
});
|
|
11
|
+
const getIamContext = (request) => {
|
|
10
12
|
const injectedPayload = request?.headers?.['injectedpayload'];
|
|
11
|
-
|
|
12
|
-
request?.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const ip = request?.headers['x-forwarded-for'] ||
|
|
14
|
+
request?.socket?.remoteAddress ||
|
|
15
|
+
null;
|
|
16
|
+
const requestId = request?.headers['request-id'] ?? (0, crypto_1.randomUUID)();
|
|
17
|
+
const timestamp = new Date(request?.headers?.['timestamp']);
|
|
18
|
+
let isAgent = false;
|
|
19
|
+
let user;
|
|
20
|
+
let agent;
|
|
17
21
|
if (injectedPayload) {
|
|
18
22
|
const data = JSON.parse(injectedPayload);
|
|
19
23
|
const token = request?.headers?.['authorization'];
|
|
20
24
|
if (data) {
|
|
21
25
|
if (!data?.is_agent && (data?.contact_id || data?.store_id)) {
|
|
22
|
-
|
|
26
|
+
user = {
|
|
23
27
|
userId: data?.sub,
|
|
24
28
|
contactId: data?.contact_id,
|
|
25
29
|
storeId: data?.store_id,
|
|
26
30
|
token,
|
|
27
31
|
};
|
|
28
|
-
iam.userId = data?.sub;
|
|
29
32
|
}
|
|
30
33
|
else if (data?.is_agent) {
|
|
31
|
-
|
|
34
|
+
isAgent = true;
|
|
35
|
+
agent = {
|
|
32
36
|
agentId: data?.sub,
|
|
33
|
-
isAgent: data?.is_agent,
|
|
34
37
|
storeIds: data?.store_ids,
|
|
35
38
|
groupsMembership: data?.groups_membership,
|
|
36
39
|
token,
|
|
37
40
|
};
|
|
38
|
-
iam.agentId = data?.sub;
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
delete request?.headers?.['authorization'];
|
|
42
44
|
}
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
+
return new iam_context_dto_1.IamContextDto({
|
|
46
|
+
ip,
|
|
47
|
+
requestId,
|
|
48
|
+
timestamp,
|
|
49
|
+
isAgent,
|
|
50
|
+
user,
|
|
51
|
+
agent,
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
exports.getIamContext = getIamContext;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { GetUserInterface } from '../../interfaces
|
|
2
|
-
import { GetAgentInterface } from '../../interfaces/get-agent.interface';
|
|
1
|
+
import { GetUserInterface, GetAgentInterface } from '../../interfaces';
|
|
3
2
|
export declare class IamContextDto {
|
|
4
3
|
timestamp: Date;
|
|
5
4
|
requestId: string;
|
|
6
5
|
ip?: string;
|
|
6
|
+
agentId: string;
|
|
7
7
|
user?: GetUserInterface;
|
|
8
8
|
userId: string;
|
|
9
|
-
contactId: number;
|
|
10
9
|
agent?: GetAgentInterface;
|
|
11
|
-
|
|
12
|
-
constructor(init?: Partial<
|
|
10
|
+
isAgent?: boolean;
|
|
11
|
+
constructor(init?: Partial<Omit<IamContextDto, 'agentId' | 'userId'>>);
|
|
13
12
|
}
|
|
@@ -16,14 +16,10 @@ const crypto_1 = require("crypto");
|
|
|
16
16
|
class IamContextDto {
|
|
17
17
|
constructor(init) {
|
|
18
18
|
this.ip = init?.ip;
|
|
19
|
+
this.agentId = init?.agent ? init?.agent?.agentId : undefined;
|
|
19
20
|
this.agent = init?.agent;
|
|
20
|
-
|
|
21
|
-
this.agentId = init?.agent?.agentId;
|
|
21
|
+
this.userId = init?.user ? init?.user?.userId : undefined;
|
|
22
22
|
this.user = init?.user;
|
|
23
|
-
if (init?.user?.contactId)
|
|
24
|
-
this.contactId = init?.user?.contactId;
|
|
25
|
-
if (init?.user?.userId)
|
|
26
|
-
this.userId = init?.user?.userId;
|
|
27
23
|
this.requestId = init?.requestId ?? (0, crypto_1.randomUUID)();
|
|
28
24
|
this.timestamp = init?.timestamp ?? new Date();
|
|
29
25
|
}
|
|
@@ -44,6 +40,11 @@ __decorate([
|
|
|
44
40
|
(0, class_validator_1.IsString)(),
|
|
45
41
|
__metadata("design:type", String)
|
|
46
42
|
], IamContextDto.prototype, "ip", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, swagger_1.ApiResponseProperty)({ type: String }),
|
|
45
|
+
(0, class_validator_1.IsString)(),
|
|
46
|
+
__metadata("design:type", String)
|
|
47
|
+
], IamContextDto.prototype, "agentId", void 0);
|
|
47
48
|
__decorate([
|
|
48
49
|
(0, swagger_1.ApiResponseProperty)({ type: Object }),
|
|
49
50
|
(0, class_validator_1.IsObject)(),
|
|
@@ -54,18 +55,12 @@ __decorate([
|
|
|
54
55
|
(0, class_validator_1.IsString)(),
|
|
55
56
|
__metadata("design:type", String)
|
|
56
57
|
], IamContextDto.prototype, "userId", void 0);
|
|
57
|
-
__decorate([
|
|
58
|
-
(0, swagger_1.ApiResponseProperty)({ type: Number }),
|
|
59
|
-
(0, class_validator_1.IsNumber)(),
|
|
60
|
-
__metadata("design:type", Number)
|
|
61
|
-
], IamContextDto.prototype, "contactId", void 0);
|
|
62
58
|
__decorate([
|
|
63
59
|
(0, swagger_1.ApiResponseProperty)({ type: Object }),
|
|
64
60
|
(0, class_validator_1.IsObject)(),
|
|
65
61
|
__metadata("design:type", Object)
|
|
66
62
|
], IamContextDto.prototype, "agent", void 0);
|
|
67
63
|
__decorate([
|
|
68
|
-
(0, swagger_1.ApiResponseProperty)({ type:
|
|
69
|
-
(
|
|
70
|
-
|
|
71
|
-
], IamContextDto.prototype, "agentId", void 0);
|
|
64
|
+
(0, swagger_1.ApiResponseProperty)({ type: Boolean }),
|
|
65
|
+
__metadata("design:type", Boolean)
|
|
66
|
+
], IamContextDto.prototype, "isAgent", void 0);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Captcha = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const captcha_decorators_enum_1 = require("./enums/captcha-decorators.enum");
|
|
6
|
+
const Captcha = (params) => (0, common_1.SetMetadata)(captcha_decorators_enum_1.CaptchaDecorators.CAPTCHA, params);
|
|
7
|
+
exports.Captcha = Captcha;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvalidCaptcha = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const captcha_messages_enum_1 = require("./enums/captcha-messages.enum");
|
|
6
|
+
class InvalidCaptcha extends common_1.UnauthorizedException {
|
|
7
|
+
constructor(cause) {
|
|
8
|
+
super(captcha_messages_enum_1.CaptchaErrors.INVALID_CAPTCHA, { cause });
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.InvalidCaptcha = InvalidCaptcha;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { CaptchaModuleOptions, IGoogleResponse } from './captcha.interface';
|
|
3
|
+
import { RequestService } from '../request';
|
|
4
|
+
import { Reflector } from '@nestjs/core';
|
|
5
|
+
import { CachingService } from '../caching';
|
|
6
|
+
export declare class CaptchaGuard implements CanActivate {
|
|
7
|
+
private reflector;
|
|
8
|
+
private captchaModuleOptions;
|
|
9
|
+
private readonly requestService;
|
|
10
|
+
private readonly cachingService;
|
|
11
|
+
constructor(reflector: Reflector, captchaModuleOptions: CaptchaModuleOptions, requestService: RequestService<IGoogleResponse>, cachingService: CachingService);
|
|
12
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
13
|
+
private getCaptchaDetails;
|
|
14
|
+
private incExecutionTimes;
|
|
15
|
+
private isCaptchaValid;
|
|
16
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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 __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CaptchaGuard = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const captcha_interface_1 = require("./captcha.interface");
|
|
18
|
+
const request_1 = require("../request");
|
|
19
|
+
const core_1 = require("@nestjs/core");
|
|
20
|
+
const captcha_decorators_enum_1 = require("./enums/captcha-decorators.enum");
|
|
21
|
+
const captcha_exception_1 = require("./captcha.exception");
|
|
22
|
+
const request_2 = require("../request");
|
|
23
|
+
const caching_1 = require("../caching");
|
|
24
|
+
const decorators_1 = require("../../decorators");
|
|
25
|
+
let CaptchaGuard = class CaptchaGuard {
|
|
26
|
+
constructor(reflector, captchaModuleOptions, requestService, cachingService) {
|
|
27
|
+
this.reflector = reflector;
|
|
28
|
+
this.captchaModuleOptions = captchaModuleOptions;
|
|
29
|
+
this.requestService = requestService;
|
|
30
|
+
this.cachingService = cachingService;
|
|
31
|
+
}
|
|
32
|
+
async canActivate(context) {
|
|
33
|
+
const captchaSettings = this.getCaptchaDetails(context);
|
|
34
|
+
const request = context.switchToHttp().getRequest();
|
|
35
|
+
const iamContext = (0, decorators_1.getIamContext)(request);
|
|
36
|
+
if (iamContext?.agentId || iamContext?.userId)
|
|
37
|
+
return true;
|
|
38
|
+
if (captchaSettings && captchaSettings.executeAfter) {
|
|
39
|
+
const ip = request.headers['x-forwarded-for'] || request.socket.remoteAddress;
|
|
40
|
+
const result = await this.incExecutionTimes(ip, captchaSettings.executeAfter);
|
|
41
|
+
if (result)
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
const text = request.headers['captcha-token'];
|
|
45
|
+
if (!text)
|
|
46
|
+
throw new captcha_exception_1.InvalidCaptcha();
|
|
47
|
+
await this.isCaptchaValid(text);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
getCaptchaDetails(context) {
|
|
51
|
+
const captchaDetailsForEndpoint = this.reflector.get(captcha_decorators_enum_1.CaptchaDecorators.CAPTCHA, context.getHandler());
|
|
52
|
+
const captchaDetailsForController = this.reflector.get(captcha_decorators_enum_1.CaptchaDecorators.CAPTCHA, context.getClass());
|
|
53
|
+
return captchaDetailsForEndpoint || captchaDetailsForController;
|
|
54
|
+
}
|
|
55
|
+
async incExecutionTimes(ip, executionCount) {
|
|
56
|
+
const cacheKey = `captcha-execution-count-${ip}`;
|
|
57
|
+
const executionTimes = await this.cachingService.get(cacheKey);
|
|
58
|
+
if (executionTimes < executionCount) {
|
|
59
|
+
await this.cachingService.set(cacheKey, (executionTimes || 0) + 1, this.captchaModuleOptions.executionAfterTtlSeconds);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async isCaptchaValid(text) {
|
|
64
|
+
const params = new URLSearchParams();
|
|
65
|
+
params.append('secret', this.captchaModuleOptions.secret);
|
|
66
|
+
params.append('response', text);
|
|
67
|
+
const result = await this.requestService.send({
|
|
68
|
+
path: this.captchaModuleOptions.verifyUrl,
|
|
69
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
70
|
+
params: params.toString(),
|
|
71
|
+
method: request_2.HttpMethods.POST,
|
|
72
|
+
});
|
|
73
|
+
if (!result.success)
|
|
74
|
+
throw new captcha_exception_1.InvalidCaptcha(result?.['error-codes']?.join(', '));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
exports.CaptchaGuard = CaptchaGuard;
|
|
78
|
+
exports.CaptchaGuard = CaptchaGuard = __decorate([
|
|
79
|
+
(0, common_1.Injectable)(),
|
|
80
|
+
__param(1, (0, common_1.Inject)(captcha_interface_1.CAPTCHA_MODULE_OPTIONS)),
|
|
81
|
+
__metadata("design:paramtypes", [core_1.Reflector, Object, request_1.RequestService,
|
|
82
|
+
caching_1.CachingService])
|
|
83
|
+
], CaptchaGuard);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
+
export declare const CAPTCHA_MODULE_OPTIONS = "CAPTCHA_MODULE_OPTIONS";
|
|
3
|
+
export interface CaptchaModuleOptions {
|
|
4
|
+
secret: string;
|
|
5
|
+
verifyUrl: string;
|
|
6
|
+
executionAfterTtlSeconds: number;
|
|
7
|
+
}
|
|
8
|
+
export interface CaptchaModuleFactory {
|
|
9
|
+
createModuleOptions: () => Promise<CaptchaModuleOptions> | CaptchaModuleOptions;
|
|
10
|
+
}
|
|
11
|
+
export interface CaptchaModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
12
|
+
inject?: any[];
|
|
13
|
+
useClass?: Type<CaptchaModuleFactory>;
|
|
14
|
+
useExisting?: Type<CaptchaModuleFactory>;
|
|
15
|
+
useFactory?: (...args: any[]) => Promise<CaptchaModuleOptions> | CaptchaModuleOptions;
|
|
16
|
+
}
|
|
17
|
+
export interface IGoogleResponse {
|
|
18
|
+
success: boolean;
|
|
19
|
+
challenge_ts: Date;
|
|
20
|
+
hostname?: string;
|
|
21
|
+
apk_package_name?: string;
|
|
22
|
+
error_codes: Array<string>;
|
|
23
|
+
}
|
|
24
|
+
export interface ICaptchaSettings {
|
|
25
|
+
executeAfter: number;
|
|
26
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { CaptchaModuleAsyncOptions, CaptchaModuleOptions } from './captcha.interface';
|
|
3
|
+
export declare class CaptchaModule {
|
|
4
|
+
static register(options: CaptchaModuleOptions): DynamicModule;
|
|
5
|
+
static registerAsync(options: CaptchaModuleAsyncOptions): DynamicModule;
|
|
6
|
+
private static createAsyncOptionsProvider;
|
|
7
|
+
private static createAsyncProviders;
|
|
8
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
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 CaptchaModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.CaptchaModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const captcha_interface_1 = require("./captcha.interface");
|
|
13
|
+
const core_1 = require("@nestjs/core");
|
|
14
|
+
const captcha_guard_1 = require("./captcha.guard");
|
|
15
|
+
const request_1 = require("../request");
|
|
16
|
+
let CaptchaModule = CaptchaModule_1 = class CaptchaModule {
|
|
17
|
+
static register(options) {
|
|
18
|
+
return {
|
|
19
|
+
module: CaptchaModule_1,
|
|
20
|
+
imports: [request_1.RequestModule],
|
|
21
|
+
providers: [
|
|
22
|
+
{
|
|
23
|
+
provide: core_1.APP_GUARD,
|
|
24
|
+
useClass: captcha_guard_1.CaptchaGuard,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
provide: captcha_interface_1.CAPTCHA_MODULE_OPTIONS,
|
|
28
|
+
useValue: options,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
controllers: [],
|
|
32
|
+
exports: [],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
static registerAsync(options) {
|
|
36
|
+
const asyncOptionsProvider = this.createAsyncOptionsProvider(options);
|
|
37
|
+
return {
|
|
38
|
+
module: CaptchaModule_1,
|
|
39
|
+
imports: [...(options.imports || []), asyncOptionsProvider],
|
|
40
|
+
providers: [],
|
|
41
|
+
controllers: [],
|
|
42
|
+
exports: [],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
static createAsyncOptionsProvider(options) {
|
|
46
|
+
const providers = this.createAsyncProviders(options);
|
|
47
|
+
return {
|
|
48
|
+
module: CaptchaModule_1,
|
|
49
|
+
imports: [request_1.RequestModule],
|
|
50
|
+
providers,
|
|
51
|
+
exports: [captcha_interface_1.CAPTCHA_MODULE_OPTIONS],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
static createAsyncProviders(options) {
|
|
55
|
+
if (options.useFactory) {
|
|
56
|
+
return [
|
|
57
|
+
{
|
|
58
|
+
provide: core_1.APP_GUARD,
|
|
59
|
+
useClass: captcha_guard_1.CaptchaGuard,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
provide: captcha_interface_1.CAPTCHA_MODULE_OPTIONS,
|
|
63
|
+
useFactory: options.useFactory,
|
|
64
|
+
inject: options.inject || [],
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
const useClass = options.useClass || options.useExisting;
|
|
69
|
+
if (useClass) {
|
|
70
|
+
return [
|
|
71
|
+
{
|
|
72
|
+
provide: captcha_interface_1.CAPTCHA_MODULE_OPTIONS,
|
|
73
|
+
useFactory: async (optionsFactory) => await optionsFactory.createModuleOptions(),
|
|
74
|
+
inject: [options.useExisting || options.useClass],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
provide: core_1.APP_GUARD,
|
|
78
|
+
useClass: captcha_guard_1.CaptchaGuard,
|
|
79
|
+
},
|
|
80
|
+
...(options.useClass
|
|
81
|
+
? [
|
|
82
|
+
{
|
|
83
|
+
provide: options.useClass,
|
|
84
|
+
useClass: options.useClass,
|
|
85
|
+
},
|
|
86
|
+
]
|
|
87
|
+
: []),
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
throw new Error('Invalid CaptchaModuleAsyncOptions');
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
exports.CaptchaModule = CaptchaModule;
|
|
94
|
+
exports.CaptchaModule = CaptchaModule = CaptchaModule_1 = __decorate([
|
|
95
|
+
(0, common_1.Global)(),
|
|
96
|
+
(0, common_1.Module)({})
|
|
97
|
+
], CaptchaModule);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CaptchaDecorators = void 0;
|
|
4
|
+
var CaptchaDecorators;
|
|
5
|
+
(function (CaptchaDecorators) {
|
|
6
|
+
CaptchaDecorators["CAPTCHA"] = "captcha";
|
|
7
|
+
})(CaptchaDecorators || (exports.CaptchaDecorators = CaptchaDecorators = {}));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CaptchaErrors = void 0;
|
|
4
|
+
var CaptchaErrors;
|
|
5
|
+
(function (CaptchaErrors) {
|
|
6
|
+
CaptchaErrors["INVALID_CAPTCHA"] = "captcha.INVALID_CAPTCHA";
|
|
7
|
+
})(CaptchaErrors || (exports.CaptchaErrors = CaptchaErrors = {}));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CAPTCHA_MODULE_OPTIONS } from './captcha.interface';
|
|
2
|
+
import { CaptchaModule } from './captcha.module';
|
|
3
|
+
import { CaptchaModuleOptions } from './captcha.interface';
|
|
4
|
+
import { CaptchaGuard } from './captcha.guard';
|
|
5
|
+
export { CaptchaGuard, CaptchaModule, CAPTCHA_MODULE_OPTIONS, CaptchaModuleOptions, };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CAPTCHA_MODULE_OPTIONS = exports.CaptchaModule = exports.CaptchaGuard = void 0;
|
|
4
|
+
const captcha_interface_1 = require("./captcha.interface");
|
|
5
|
+
Object.defineProperty(exports, "CAPTCHA_MODULE_OPTIONS", { enumerable: true, get: function () { return captcha_interface_1.CAPTCHA_MODULE_OPTIONS; } });
|
|
6
|
+
const captcha_module_1 = require("./captcha.module");
|
|
7
|
+
Object.defineProperty(exports, "CaptchaModule", { enumerable: true, get: function () { return captcha_module_1.CaptchaModule; } });
|
|
8
|
+
const captcha_guard_1 = require("./captcha.guard");
|
|
9
|
+
Object.defineProperty(exports, "CaptchaGuard", { enumerable: true, get: function () { return captcha_guard_1.CaptchaGuard; } });
|
|
@@ -11,39 +11,42 @@ class CoreCrudController {
|
|
|
11
11
|
CoreCrudController.responseDto = responseDto;
|
|
12
12
|
}
|
|
13
13
|
async findAllWithPagination(query, paginateConfig, options, ...args) {
|
|
14
|
-
const response = await this.coreService.findAllWithPagination(query, paginateConfig, options);
|
|
14
|
+
const response = await this.coreService.findAllWithPagination(query, paginateConfig, options, ...args);
|
|
15
15
|
if (!response)
|
|
16
16
|
throw new common_1.NotFoundException(enums_1.SharedMessages.FETCH_FAILED);
|
|
17
17
|
const serializedData = response.data.map((item) => new this.responseDto(item));
|
|
18
|
-
return new dto_1.SuccessResponse(serializedData, enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK, {
|
|
18
|
+
return new dto_1.SuccessResponse(serializedData, enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK, {
|
|
19
|
+
...response.meta,
|
|
20
|
+
links: response.links,
|
|
21
|
+
});
|
|
19
22
|
}
|
|
20
23
|
async findOneById(id, options, ...args) {
|
|
21
|
-
const response = await this.coreService.findOneById(id, options);
|
|
24
|
+
const response = await this.coreService.findOneById(id, options, ...args);
|
|
22
25
|
if (!response)
|
|
23
26
|
throw new common_1.NotFoundException(enums_1.SharedMessages.RESOURCE_NOT_FOUND);
|
|
24
27
|
return new dto_1.SuccessResponse(new this.responseDto(response), enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK);
|
|
25
28
|
}
|
|
26
29
|
async create(createDto, options, ...args) {
|
|
27
|
-
const response = await this.coreService.create(createDto, options);
|
|
30
|
+
const response = await this.coreService.create(createDto, options, ...args);
|
|
28
31
|
if (!response)
|
|
29
32
|
throw new common_1.BadRequestException(enums_1.SharedMessages.CREATE_FAILED);
|
|
30
33
|
return new dto_1.SuccessResponse(new this.responseDto(response), enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.CREATED);
|
|
31
34
|
}
|
|
32
35
|
async update({ id }, updateDto, options, ...args) {
|
|
33
|
-
const response = await this.coreService.update(id, updateDto, options);
|
|
36
|
+
const response = await this.coreService.update(id, updateDto, options, ...args);
|
|
34
37
|
if (!response)
|
|
35
38
|
throw new common_1.BadRequestException(enums_1.SharedMessages.UPDATE_FAILED);
|
|
36
39
|
const foundItem = await this.coreService.findOneById(id, options);
|
|
37
40
|
return new dto_1.SuccessResponse(new this.responseDto(foundItem), enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK);
|
|
38
41
|
}
|
|
39
42
|
async deleteById({ id }, options, ...args) {
|
|
40
|
-
const result = await this.coreService.deleteById(id, options);
|
|
43
|
+
const result = await this.coreService.deleteById(id, options, ...args);
|
|
41
44
|
if (!result)
|
|
42
45
|
throw new common_1.BadRequestException(enums_1.SharedMessages.DELETE_FAILED);
|
|
43
46
|
return new dto_1.SuccessResponse(undefined, enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK);
|
|
44
47
|
}
|
|
45
48
|
async softDeleteById({ id }, options, ...args) {
|
|
46
|
-
const result = await this.coreService.softDeleteById(id, options);
|
|
49
|
+
const result = await this.coreService.softDeleteById(id, options, ...args);
|
|
47
50
|
if (!result)
|
|
48
51
|
throw new common_1.BadRequestException(enums_1.SharedMessages.DELETE_FAILED);
|
|
49
52
|
return new dto_1.SuccessResponse(undefined, enums_1.SharedMessages.SUCCESSFUL, common_1.HttpStatus.OK);
|
|
@@ -11,22 +11,22 @@ export declare abstract class CoreCrudService<T extends BaseModelEntity, CreateD
|
|
|
11
11
|
protected readonly repository: Repository<T>;
|
|
12
12
|
private readonly relationsPath;
|
|
13
13
|
protected constructor(repository: Repository<T>);
|
|
14
|
-
create(createDto: CreateDto, options?: CoreBaseServiceOption): Promise<T>;
|
|
15
|
-
update(id: number, updateDto: Partial<UpdateDto> | DeepPartial<T> | QueryDeepPartialEntity<T>, options?: CoreUpdateServiceOption<T
|
|
16
|
-
updateMany(query: FindManyOptions<T>, updateDto: Partial<UpdateDto> | DeepPartial<T> | QueryDeepPartialEntity<T>, options?: CoreUpdateServiceOption<T
|
|
17
|
-
upsert(upsertDto: QueryDeepPartialEntity<T>, upsertOptions: UpsertOptions<T>, options?: CoreBaseServiceOption): Promise<InsertResult>;
|
|
18
|
-
findAllWithPagination(query: PaginationQueryCustom, paginateConfig: PaginateConfig<T>, options?: CoreFindAllWithPaginationServiceOption<T
|
|
19
|
-
findAll(query: FindManyOptions<T>, options?: CoreFindAllServiceOption): Promise<T[]>;
|
|
20
|
-
findOneById(id: number, options?: CoreFindOneByIdServiceOption<T
|
|
21
|
-
findOne(query: FindManyOptions<T>, options?: CoreFindOneServiceOption): Promise<T>;
|
|
22
|
-
isExists(query: FindManyOptions<T>, options?: CoreBaseServiceOption): Promise<boolean>;
|
|
23
|
-
count(query: FindManyOptions<T>, options?: CoreBaseServiceOption): Promise<number>;
|
|
24
|
-
softDelete(query: FindOptionsWhere<T>, options?: CoreBaseServiceOption): Promise<UpdateResult>;
|
|
25
|
-
softDeleteById(id: string | string[] | number | number[], options?: CoreBaseServiceOption): Promise<UpdateResult>;
|
|
26
|
-
restore(query: FindOptionsWhere<T>, options?: CoreBaseServiceOption): Promise<UpdateResult>;
|
|
27
|
-
restoreById(id: string | string[] | number | number[], options?: CoreBaseServiceOption): Promise<UpdateResult>;
|
|
28
|
-
delete(query: FindOptionsWhere<T>, options?: CoreBaseServiceOption): Promise<DeleteResult>;
|
|
29
|
-
deleteById(id: string | string[] | number | number[], options?: CoreBaseServiceOption): Promise<DeleteResult>;
|
|
14
|
+
create(createDto: CreateDto, options?: CoreBaseServiceOption, ...args: any[]): Promise<T>;
|
|
15
|
+
update(id: number, updateDto: Partial<UpdateDto> | DeepPartial<T> | QueryDeepPartialEntity<T>, options?: CoreUpdateServiceOption<T>, ...args: any[]): Promise<UpdateResult>;
|
|
16
|
+
updateMany(query: FindManyOptions<T>, updateDto: Partial<UpdateDto> | DeepPartial<T> | QueryDeepPartialEntity<T>, options?: CoreUpdateServiceOption<T>, ...args: any[]): Promise<void>;
|
|
17
|
+
upsert(upsertDto: QueryDeepPartialEntity<T>, upsertOptions: UpsertOptions<T>, options?: CoreBaseServiceOption, ...args: any[]): Promise<InsertResult>;
|
|
18
|
+
findAllWithPagination(query: PaginationQueryCustom, paginateConfig: PaginateConfig<T>, options?: CoreFindAllWithPaginationServiceOption<T>, ...args: any[]): Promise<Paginated<T>>;
|
|
19
|
+
findAll(query: FindManyOptions<T>, options?: CoreFindAllServiceOption, ...args: any[]): Promise<T[]>;
|
|
20
|
+
findOneById(id: number, options?: CoreFindOneByIdServiceOption<T>, ...args: any[]): Promise<T>;
|
|
21
|
+
findOne(query: FindManyOptions<T>, options?: CoreFindOneServiceOption, ...args: any[]): Promise<T>;
|
|
22
|
+
isExists(query: FindManyOptions<T>, options?: CoreBaseServiceOption, ...args: any[]): Promise<boolean>;
|
|
23
|
+
count(query: FindManyOptions<T>, options?: CoreBaseServiceOption, ...args: any[]): Promise<number>;
|
|
24
|
+
softDelete(query: FindOptionsWhere<T>, options?: CoreBaseServiceOption, ...args: any[]): Promise<UpdateResult>;
|
|
25
|
+
softDeleteById(id: string | string[] | number | number[], options?: CoreBaseServiceOption, ...args: any[]): Promise<UpdateResult>;
|
|
26
|
+
restore(query: FindOptionsWhere<T>, options?: CoreBaseServiceOption, ...args: any[]): Promise<UpdateResult>;
|
|
27
|
+
restoreById(id: string | string[] | number | number[], options?: CoreBaseServiceOption, ...args: any[]): Promise<UpdateResult>;
|
|
28
|
+
delete(query: FindOptionsWhere<T>, options?: CoreBaseServiceOption, ...args: any[]): Promise<DeleteResult>;
|
|
29
|
+
deleteById(id: string | string[] | number | number[], options?: CoreBaseServiceOption, ...args: any[]): Promise<DeleteResult>;
|
|
30
30
|
private relatedPropertyTransformer;
|
|
31
31
|
private whereQueryTransformer;
|
|
32
32
|
private isObject;
|