@mondart/nestjs-common-module 2.8.1 → 2.9.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/lib/google-recaptcha/decorators/recaptcha-result.d.ts +1 -0
- package/dist/lib/google-recaptcha/decorators/recaptcha-result.js +16 -0
- package/dist/lib/google-recaptcha/decorators/recaptcha.d.ts +2 -0
- package/dist/lib/google-recaptcha/decorators/recaptcha.js +9 -0
- package/dist/lib/google-recaptcha/decorators/set-recaptcha-options.d.ts +2 -0
- package/dist/lib/google-recaptcha/decorators/set-recaptcha-options.js +8 -0
- package/dist/lib/google-recaptcha/enums/classification-reason.d.ts +8 -0
- package/dist/lib/google-recaptcha/enums/classification-reason.js +12 -0
- package/dist/lib/google-recaptcha/enums/error-code.d.ts +16 -0
- package/dist/lib/google-recaptcha/enums/error-code.js +20 -0
- package/dist/lib/google-recaptcha/enums/google-recaptcha-context.d.ts +4 -0
- package/dist/lib/google-recaptcha/enums/google-recaptcha-context.js +8 -0
- package/dist/lib/google-recaptcha/enums/google-recaptcha-enterprise-reason.d.ts +10 -0
- package/dist/lib/google-recaptcha/enums/google-recaptcha-enterprise-reason.js +14 -0
- package/dist/lib/google-recaptcha/enums/google-recaptcha-network.d.ts +4 -0
- package/dist/lib/google-recaptcha/enums/google-recaptcha-network.js +8 -0
- package/dist/lib/google-recaptcha/exceptions/google-recaptcha-network.exception.d.ts +5 -0
- package/dist/lib/google-recaptcha/exceptions/google-recaptcha-network.exception.js +14 -0
- package/dist/lib/google-recaptcha/exceptions/google-recaptcha.exception.d.ts +8 -0
- package/dist/lib/google-recaptcha/exceptions/google-recaptcha.exception.js +54 -0
- package/dist/lib/google-recaptcha/google-recaptcha.module.d.ts +12 -0
- package/dist/lib/google-recaptcha/google-recaptcha.module.js +159 -0
- package/dist/lib/google-recaptcha/guards/google-recaptcha.guard.d.ts +15 -0
- package/dist/lib/google-recaptcha/guards/google-recaptcha.guard.js +89 -0
- package/dist/lib/google-recaptcha/helpers/get-error-info.d.ts +4 -0
- package/dist/lib/google-recaptcha/helpers/get-error-info.js +13 -0
- package/dist/lib/google-recaptcha/helpers/load-module.d.ts +2 -0
- package/dist/lib/google-recaptcha/helpers/load-module.js +15 -0
- package/dist/lib/google-recaptcha/helpers/xor.d.ts +1 -0
- package/dist/lib/google-recaptcha/helpers/xor.js +6 -0
- package/dist/lib/google-recaptcha/index.d.ts +15 -0
- package/dist/lib/google-recaptcha/index.js +31 -0
- package/dist/lib/google-recaptcha/interfaces/google-recaptcha-enterprise-options.d.ts +5 -0
- package/dist/lib/google-recaptcha/interfaces/google-recaptcha-enterprise-options.js +2 -0
- package/dist/lib/google-recaptcha/interfaces/google-recaptcha-guard-options.d.ts +7 -0
- package/dist/lib/google-recaptcha/interfaces/google-recaptcha-guard-options.js +2 -0
- package/dist/lib/google-recaptcha/interfaces/google-recaptcha-module-options.d.ts +21 -0
- package/dist/lib/google-recaptcha/interfaces/google-recaptcha-module-options.js +2 -0
- package/dist/lib/google-recaptcha/interfaces/google-recaptcha-validator-options.d.ts +12 -0
- package/dist/lib/google-recaptcha/interfaces/google-recaptcha-validator-options.js +2 -0
- package/dist/lib/google-recaptcha/interfaces/literal-object.d.ts +3 -0
- package/dist/lib/google-recaptcha/interfaces/literal-object.js +2 -0
- package/dist/lib/google-recaptcha/interfaces/verify-response-decorator-options.d.ts +13 -0
- package/dist/lib/google-recaptcha/interfaces/verify-response-decorator-options.js +2 -0
- package/dist/lib/google-recaptcha/interfaces/verify-response-enterprise.d.ts +30 -0
- package/dist/lib/google-recaptcha/interfaces/verify-response-enterprise.js +2 -0
- package/dist/lib/google-recaptcha/interfaces/verify-response.d.ts +11 -0
- package/dist/lib/google-recaptcha/interfaces/verify-response.js +2 -0
- package/dist/lib/google-recaptcha/models/recaptcha-config-ref.d.ts +12 -0
- package/dist/lib/google-recaptcha/models/recaptcha-config-ref.js +30 -0
- package/dist/lib/google-recaptcha/models/recaptcha-verification-result.d.ts +26 -0
- package/dist/lib/google-recaptcha/models/recaptcha-verification-result.js +34 -0
- package/dist/lib/google-recaptcha/provider.declarations.d.ts +4 -0
- package/dist/lib/google-recaptcha/provider.declarations.js +7 -0
- package/dist/lib/google-recaptcha/services/enterprise-reason.transformer.d.ts +5 -0
- package/dist/lib/google-recaptcha/services/enterprise-reason.transformer.js +38 -0
- package/dist/lib/google-recaptcha/services/recaptcha-request.resolver.d.ts +4 -0
- package/dist/lib/google-recaptcha/services/recaptcha-request.resolver.js +32 -0
- package/dist/lib/google-recaptcha/services/recaptcha-validator.resolver.d.ts +11 -0
- package/dist/lib/google-recaptcha/services/recaptcha-validator.resolver.js +40 -0
- package/dist/lib/google-recaptcha/services/validators/abstract-google-recaptcha-validator.d.ts +11 -0
- package/dist/lib/google-recaptcha/services/validators/abstract-google-recaptcha-validator.js +27 -0
- package/dist/lib/google-recaptcha/services/validators/google-recaptcha-enterprise.validator.d.ts +17 -0
- package/dist/lib/google-recaptcha/services/validators/google-recaptcha-enterprise.validator.js +126 -0
- package/dist/lib/google-recaptcha/services/validators/google-recaptcha.validator.d.ts +17 -0
- package/dist/lib/google-recaptcha/services/validators/google-recaptcha.validator.js +128 -0
- package/dist/lib/google-recaptcha/types.d.ts +6 -0
- package/dist/lib/google-recaptcha/types.js +2 -0
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/lib/captcha/captcha.decorator.d.ts +0 -4
- package/dist/lib/captcha/captcha.decorator.js +0 -7
- package/dist/lib/captcha/captcha.exception.d.ts +0 -4
- package/dist/lib/captcha/captcha.exception.js +0 -11
- package/dist/lib/captcha/captcha.guard.d.ts +0 -16
- package/dist/lib/captcha/captcha.guard.js +0 -86
- package/dist/lib/captcha/captcha.interface.d.ts +0 -26
- package/dist/lib/captcha/captcha.interface.js +0 -4
- package/dist/lib/captcha/captcha.module.d.ts +0 -8
- package/dist/lib/captcha/captcha.module.js +0 -97
- package/dist/lib/captcha/enums/captcha-decorators.enum.d.ts +0 -3
- package/dist/lib/captcha/enums/captcha-decorators.enum.js +0 -7
- package/dist/lib/captcha/enums/captcha-messages.enum.d.ts +0 -3
- package/dist/lib/captcha/enums/captcha-messages.enum.js +0 -7
- package/dist/lib/captcha/index.d.ts +0 -5
- package/dist/lib/captcha/index.js +0 -9
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
2
|
+
import { VerifyResponseOptions } from '../../interfaces/verify-response-decorator-options';
|
|
3
|
+
import { VerifyResponseV3 } from '../../interfaces/verify-response';
|
|
4
|
+
import { AbstractGoogleRecaptchaValidator } from './abstract-google-recaptcha-validator';
|
|
5
|
+
import { RecaptchaVerificationResult } from '../../models/recaptcha-verification-result';
|
|
6
|
+
import { AxiosInstance } from 'axios';
|
|
7
|
+
import { RecaptchaConfigRef } from '../../models/recaptcha-config-ref';
|
|
8
|
+
export declare class GoogleRecaptchaValidator extends AbstractGoogleRecaptchaValidator<VerifyResponseV3> {
|
|
9
|
+
private readonly axios;
|
|
10
|
+
private readonly logger;
|
|
11
|
+
private readonly defaultNetwork;
|
|
12
|
+
private readonly headers;
|
|
13
|
+
constructor(axios: AxiosInstance, logger: Logger, configRef: RecaptchaConfigRef);
|
|
14
|
+
validate(options: VerifyResponseOptions): Promise<RecaptchaVerificationResult<VerifyResponseV3>>;
|
|
15
|
+
private verifyResponse;
|
|
16
|
+
private isUseV3;
|
|
17
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
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.GoogleRecaptchaValidator = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const provider_declarations_1 = require("../../provider.declarations");
|
|
18
|
+
const qs = require("querystring");
|
|
19
|
+
const google_recaptcha_network_1 = require("../../enums/google-recaptcha-network");
|
|
20
|
+
const error_code_1 = require("../../enums/error-code");
|
|
21
|
+
const google_recaptcha_network_exception_1 = require("../../exceptions/google-recaptcha-network.exception");
|
|
22
|
+
const abstract_google_recaptcha_validator_1 = require("./abstract-google-recaptcha-validator");
|
|
23
|
+
const recaptcha_verification_result_1 = require("../../models/recaptcha-verification-result");
|
|
24
|
+
const google_recaptcha_context_1 = require("../../enums/google-recaptcha-context");
|
|
25
|
+
const get_error_info_1 = require("../../helpers/get-error-info");
|
|
26
|
+
const recaptcha_config_ref_1 = require("../../models/recaptcha-config-ref");
|
|
27
|
+
let GoogleRecaptchaValidator = class GoogleRecaptchaValidator extends abstract_google_recaptcha_validator_1.AbstractGoogleRecaptchaValidator {
|
|
28
|
+
constructor(axios, logger, configRef) {
|
|
29
|
+
super(configRef);
|
|
30
|
+
this.axios = axios;
|
|
31
|
+
this.logger = logger;
|
|
32
|
+
this.defaultNetwork = google_recaptcha_network_1.GoogleRecaptchaNetwork.Google;
|
|
33
|
+
this.headers = {
|
|
34
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async validate(options) {
|
|
38
|
+
const result = await this.verifyResponse(options.response, options.remoteIp);
|
|
39
|
+
if (!this.isUseV3(result)) {
|
|
40
|
+
const resV2 = result;
|
|
41
|
+
return new recaptcha_verification_result_1.RecaptchaVerificationResult({
|
|
42
|
+
nativeResponse: resV2,
|
|
43
|
+
remoteIp: options.remoteIp,
|
|
44
|
+
score: undefined,
|
|
45
|
+
action: undefined,
|
|
46
|
+
errors: resV2.errors,
|
|
47
|
+
success: resV2.success,
|
|
48
|
+
hostname: resV2.hostname,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (!this.isValidAction(result.action, options)) {
|
|
52
|
+
result.success = false;
|
|
53
|
+
result.errors.push(error_code_1.ErrorCode.ForbiddenAction);
|
|
54
|
+
}
|
|
55
|
+
if (!this.isValidScore(result.score, options.score)) {
|
|
56
|
+
result.success = false;
|
|
57
|
+
result.errors.push(error_code_1.ErrorCode.LowScore);
|
|
58
|
+
}
|
|
59
|
+
const nativeResponse = { ...result };
|
|
60
|
+
return new recaptcha_verification_result_1.RecaptchaVerificationResult({
|
|
61
|
+
nativeResponse: nativeResponse,
|
|
62
|
+
remoteIp: options.remoteIp,
|
|
63
|
+
score: result.score,
|
|
64
|
+
errors: result.errors,
|
|
65
|
+
success: result.success,
|
|
66
|
+
action: result.action,
|
|
67
|
+
hostname: result.hostname,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
verifyResponse(response, remoteIp) {
|
|
71
|
+
const body = qs.stringify({
|
|
72
|
+
secret: this.options.valueOf.secretKey,
|
|
73
|
+
response,
|
|
74
|
+
remoteip: remoteIp,
|
|
75
|
+
});
|
|
76
|
+
const url = this.options.valueOf.network || this.defaultNetwork;
|
|
77
|
+
const config = {
|
|
78
|
+
headers: this.headers,
|
|
79
|
+
};
|
|
80
|
+
if (this.options.valueOf.debug) {
|
|
81
|
+
this.logger.debug({ body }, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptcha}.request`);
|
|
82
|
+
}
|
|
83
|
+
return this.axios
|
|
84
|
+
.post(url, body, config)
|
|
85
|
+
.then((res) => res.data)
|
|
86
|
+
.then((data) => {
|
|
87
|
+
if (this.options.valueOf.debug) {
|
|
88
|
+
this.logger.debug(data, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptcha}.response`);
|
|
89
|
+
}
|
|
90
|
+
return data;
|
|
91
|
+
})
|
|
92
|
+
.then((result) => ({
|
|
93
|
+
...result,
|
|
94
|
+
errors: result['error-codes'] || [],
|
|
95
|
+
}))
|
|
96
|
+
.then((result) => {
|
|
97
|
+
delete result['error-codes'];
|
|
98
|
+
return result;
|
|
99
|
+
})
|
|
100
|
+
.catch((err) => {
|
|
101
|
+
if (this.options.valueOf.debug) {
|
|
102
|
+
this.logger.debug((0, get_error_info_1.getErrorInfo)(err), `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptcha}.error`);
|
|
103
|
+
}
|
|
104
|
+
const networkErrorCode = err.isAxiosError && !err.response && err.code;
|
|
105
|
+
if (networkErrorCode) {
|
|
106
|
+
throw new google_recaptcha_network_exception_1.GoogleRecaptchaNetworkException(networkErrorCode);
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
success: false,
|
|
110
|
+
errors: [error_code_1.ErrorCode.UnknownError],
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
isUseV3(v) {
|
|
115
|
+
return ('score' in v &&
|
|
116
|
+
typeof v['score'] === 'number' &&
|
|
117
|
+
'action' in v &&
|
|
118
|
+
typeof v['action'] === 'string');
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
exports.GoogleRecaptchaValidator = GoogleRecaptchaValidator;
|
|
122
|
+
exports.GoogleRecaptchaValidator = GoogleRecaptchaValidator = __decorate([
|
|
123
|
+
(0, common_1.Injectable)(),
|
|
124
|
+
__param(0, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_AXIOS_INSTANCE)),
|
|
125
|
+
__param(1, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_LOGGER)),
|
|
126
|
+
__metadata("design:paramtypes", [Function, common_1.Logger,
|
|
127
|
+
recaptcha_config_ref_1.RecaptchaConfigRef])
|
|
128
|
+
], GoogleRecaptchaValidator);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ContextType } from '@nestjs/common';
|
|
2
|
+
export type RecaptchaResponseProvider = (req: any) => string | Promise<string>;
|
|
3
|
+
export type RecaptchaRemoteIpProvider = (req: any) => string | Promise<string>;
|
|
4
|
+
export type ScoreValidator = number | ((score: number) => boolean);
|
|
5
|
+
export type SkipIfValue = boolean | (<Req = unknown>(request: Req) => boolean | Promise<boolean>);
|
|
6
|
+
export type RecaptchaContextType = ContextType | 'graphql';
|
package/dist/lib/index.d.ts
CHANGED
package/dist/lib/index.js
CHANGED
|
@@ -21,5 +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("./
|
|
24
|
+
__exportStar(require("./google-recaptcha"), exports);
|
|
25
25
|
__exportStar(require("./request"), exports);
|