@mondart/nestjs-common-module 2.4.1 → 2.6.0
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/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/strategy/index.d.ts +1 -0
- package/dist/strategy/index.js +1 -0
- package/dist/strategy/type-orm-logger.strategy.d.ts +10 -0
- package/dist/strategy/type-orm-logger.strategy.js +75 -0
- 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; } });
|
package/dist/lib/index.d.ts
CHANGED
package/dist/lib/index.js
CHANGED
|
@@ -21,3 +21,5 @@ __exportStar(require("./keycloak"), exports);
|
|
|
21
21
|
__exportStar(require("./core-crud"), exports);
|
|
22
22
|
__exportStar(require("./health-check"), exports);
|
|
23
23
|
__exportStar(require("./bottleneck"), exports);
|
|
24
|
+
__exportStar(require("./captcha"), exports);
|
|
25
|
+
__exportStar(require("./request"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpMethods = void 0;
|
|
4
|
+
var HttpMethods;
|
|
5
|
+
(function (HttpMethods) {
|
|
6
|
+
HttpMethods["POST"] = "post";
|
|
7
|
+
HttpMethods["GET"] = "get";
|
|
8
|
+
HttpMethods["DELETE"] = "delete";
|
|
9
|
+
HttpMethods["PUT"] = "put";
|
|
10
|
+
HttpMethods["PATCH"] = "patch";
|
|
11
|
+
})(HttpMethods || (exports.HttpMethods = HttpMethods = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpMethods = exports.RequestService = exports.RequestModule = void 0;
|
|
4
|
+
const request_module_1 = require("./request.module");
|
|
5
|
+
Object.defineProperty(exports, "RequestModule", { enumerable: true, get: function () { return request_module_1.RequestModule; } });
|
|
6
|
+
const request_service_1 = require("./request.service");
|
|
7
|
+
Object.defineProperty(exports, "RequestService", { enumerable: true, get: function () { return request_service_1.RequestService; } });
|
|
8
|
+
const http_methods_enum_1 = require("./enums/http-methods.enum");
|
|
9
|
+
Object.defineProperty(exports, "HttpMethods", { enumerable: true, get: function () { return http_methods_enum_1.HttpMethods; } });
|
|
@@ -0,0 +1,23 @@
|
|
|
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.RequestModule = void 0;
|
|
10
|
+
const axios_1 = require("@nestjs/axios");
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const request_service_1 = require("./request.service");
|
|
13
|
+
let RequestModule = class RequestModule {
|
|
14
|
+
};
|
|
15
|
+
exports.RequestModule = RequestModule;
|
|
16
|
+
exports.RequestModule = RequestModule = __decorate([
|
|
17
|
+
(0, common_1.Global)(),
|
|
18
|
+
(0, common_1.Module)({
|
|
19
|
+
imports: [axios_1.HttpModule],
|
|
20
|
+
providers: [request_service_1.RequestService],
|
|
21
|
+
exports: [request_service_1.RequestService],
|
|
22
|
+
})
|
|
23
|
+
], RequestModule);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { HttpService } from '@nestjs/axios';
|
|
2
|
+
import { HttpMethods } from './enums/http-methods.enum';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
interface ISendRequest {
|
|
5
|
+
method: HttpMethods;
|
|
6
|
+
body?: object;
|
|
7
|
+
path: string;
|
|
8
|
+
isAdditionalPath?: boolean;
|
|
9
|
+
token?: string;
|
|
10
|
+
headers?: object;
|
|
11
|
+
params?: string;
|
|
12
|
+
}
|
|
13
|
+
interface ISubRequest {
|
|
14
|
+
body?: any;
|
|
15
|
+
path: string;
|
|
16
|
+
token?: string;
|
|
17
|
+
headers?: object;
|
|
18
|
+
params?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class RequestService<T> {
|
|
21
|
+
private readonly configService;
|
|
22
|
+
private readonly httpService;
|
|
23
|
+
constructor(configService: ConfigService, httpService: HttpService);
|
|
24
|
+
sendRaw({ method, body, isAdditionalPath, path, headers, token, }: ISendRequest): Promise<any>;
|
|
25
|
+
send({ method, body, path, headers, token, params, }: ISendRequest): Promise<any>;
|
|
26
|
+
post(payload: ISubRequest): Promise<any>;
|
|
27
|
+
get(payload: ISubRequest): Promise<any>;
|
|
28
|
+
patch(payload: ISubRequest): Promise<any>;
|
|
29
|
+
remove(payload: Omit<ISubRequest, 'body'>): Promise<any>;
|
|
30
|
+
}
|
|
31
|
+
export { HttpMethods };
|