@nestlab/google-recaptcha 3.1.2 → 3.1.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/README.md +5 -0
- package/decorators/recaptcha-result.js +1 -6
- package/decorators/recaptcha-result.js.map +1 -1
- package/decorators/recaptcha.js.map +1 -1
- package/decorators/set-recaptcha-options.js.map +1 -1
- package/enums/classification-reason.js.map +1 -1
- package/enums/google-recaptcha-context.js.map +1 -1
- package/enums/google-recaptcha-enterprise-reason.js.map +1 -1
- package/enums/google-recaptcha-network.js.map +1 -1
- package/exceptions/google-recaptcha-network.exception.js.map +1 -1
- package/exceptions/google-recaptcha.exception.js.map +1 -1
- package/google-recaptcha.module.d.ts +0 -1
- package/google-recaptcha.module.js +9 -36
- package/google-recaptcha.module.js.map +1 -1
- package/guards/google-recaptcha.guard.js +2 -6
- package/guards/google-recaptcha.guard.js.map +1 -1
- package/helpers/get-error-info.d.ts +4 -0
- package/helpers/get-error-info.js +16 -0
- package/helpers/get-error-info.js.map +1 -0
- package/helpers/load-module.js.map +1 -1
- package/helpers/xor.js.map +1 -1
- package/models/recaptcha-verification-result.d.ts +2 -2
- package/models/recaptcha-verification-result.js.map +1 -1
- package/package.json +88 -89
- package/services/enterprise-reason.transformer.js.map +1 -1
- package/services/recaptcha-request.resolver.js +1 -4
- package/services/recaptcha-request.resolver.js.map +1 -1
- package/services/recaptcha-validator.resolver.js +1 -2
- package/services/recaptcha-validator.resolver.js.map +1 -1
- package/services/validators/abstract-google-recaptcha-validator.js +1 -3
- package/services/validators/abstract-google-recaptcha-validator.js.map +1 -1
- package/services/validators/google-recaptcha-enterprise.validator.js +12 -9
- package/services/validators/google-recaptcha-enterprise.validator.js.map +1 -1
- package/services/validators/google-recaptcha.validator.d.ts +1 -1
- package/services/validators/google-recaptcha.validator.js +19 -12
- package/services/validators/google-recaptcha.validator.js.map +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
# Google recaptcha module
|
|
2
|
+
[](https://www.npmjs.com/package/@nestlab/google-recaptcha)
|
|
3
|
+
[](https://github.com/chvarkov/google-recaptcha/blob/master/LICENSE)
|
|
4
|
+
[](https://www.npmjs.com/package/@nestlab/google-recaptcha)
|
|
5
|
+
[](https://github.com/chvarkov/google-recaptcha/tree/master)
|
|
6
|
+
[](https://coveralls.io/github/chvarkov/google-recaptcha?branch=master)
|
|
2
7
|
|
|
3
8
|
The [NestJS](https://docs.nestjs.com/) module to protect your endpoints via [google recaptcha](https://www.google.com/recaptcha/about/).
|
|
4
9
|
|
|
@@ -9,12 +9,7 @@ exports.RecaptchaResult = (0, common_1.createParamDecorator)((data, context) =>
|
|
|
9
9
|
case 'http':
|
|
10
10
|
return context.switchToHttp().getRequest().recaptchaValidationResult;
|
|
11
11
|
case 'graphql':
|
|
12
|
-
return (_d = (_c = (_b = (_a = (0, load_module_1.loadModule)('@nestjs/graphql', true)
|
|
13
|
-
.GqlExecutionContext
|
|
14
|
-
.create(context)
|
|
15
|
-
.getContext().req) === null || _a === void 0 ? void 0 : _a.connection) === null || _b === void 0 ? void 0 : _b._httpMessage) === null || _c === void 0 ? void 0 : _c.req) === null || _d === void 0 ? void 0 : _d.recaptchaValidationResult;
|
|
16
|
-
default:
|
|
17
|
-
return null;
|
|
12
|
+
return (_d = (_c = (_b = (_a = (0, load_module_1.loadModule)('@nestjs/graphql', true).GqlExecutionContext.create(context).getContext().req) === null || _a === void 0 ? void 0 : _a.connection) === null || _b === void 0 ? void 0 : _b._httpMessage) === null || _c === void 0 ? void 0 : _c.req) === null || _d === void 0 ? void 0 : _d.recaptchaValidationResult;
|
|
18
13
|
}
|
|
19
14
|
});
|
|
20
15
|
//# sourceMappingURL=recaptcha-result.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recaptcha-result.js","sourceRoot":"","sources":["../../src/decorators/recaptcha-result.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AACxE,wDAAoD;AAEvC,QAAA,eAAe,GAAG,IAAA,6BAAoB,EAAC,CAAC,IAAI,EAAE,OAAyB,EAAE,EAAE;;
|
|
1
|
+
{"version":3,"file":"recaptcha-result.js","sourceRoot":"","sources":["../../src/decorators/recaptcha-result.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AACxE,wDAAoD;AAEvC,QAAA,eAAe,GAAG,IAAA,6BAAoB,EAAC,CAAC,IAAI,EAAE,OAAyB,EAAE,EAAE;;IACvF,QAAQ,OAAO,CAAC,OAAO,EAAsB,EAAE;QAC9C,KAAK,MAAM;YACV,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC,yBAAyB,CAAC;QACtE,KAAK,SAAS;YACb,OAAO,MAAA,MAAA,MAAA,MAAA,IAAA,wBAAU,EAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC,GAAG,0CAAE,UAAU,0CAAE,YAAY,0CAAE,GAAG,0CAC3H,yBAAyB,CAAC;KAC9B;AACF,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recaptcha.js","sourceRoot":"","sources":["../../src/decorators/recaptcha.ts"],"names":[],"mappings":";;;AAAA,2CAA4D;AAC5D,6EAAwE;AAExE,mEAA8D;AAE9D,SAAgB,SAAS,CAAC,OAAwC;
|
|
1
|
+
{"version":3,"file":"recaptcha.js","sourceRoot":"","sources":["../../src/decorators/recaptcha.ts"],"names":[],"mappings":";;;AAAA,2CAA4D;AAC5D,6EAAwE;AAExE,mEAA8D;AAE9D,SAAgB,SAAS,CAAC,OAAwC;IACjE,OAAO,IAAA,wBAAe,EAAC,IAAA,2CAAmB,EAAC,OAAO,CAAC,EAAE,IAAA,kBAAS,EAAC,6CAAoB,CAAC,CAAC,CAAC;AACvF,CAAC;AAFD,8BAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-recaptcha-options.js","sourceRoot":"","sources":["../../src/decorators/set-recaptcha-options.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,oEAAwE;AAExE,SAAgB,mBAAmB,CAAC,OAAwC;
|
|
1
|
+
{"version":3,"file":"set-recaptcha-options.js","sourceRoot":"","sources":["../../src/decorators/set-recaptcha-options.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,oEAAwE;AAExE,SAAgB,mBAAmB,CAAC,OAAwC;IAC3E,OAAO,IAAA,oBAAW,EAAC,oDAA4B,EAAE,OAAO,CAAC,CAAC;AAC3D,CAAC;AAFD,kDAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classification-reason.js","sourceRoot":"","sources":["../../src/enums/classification-reason.ts"],"names":[],"mappings":";;;AAAA,IAAY,oBAOX;AAPD,WAAY,oBAAoB;
|
|
1
|
+
{"version":3,"file":"classification-reason.js","sourceRoot":"","sources":["../../src/enums/classification-reason.ts"],"names":[],"mappings":";;;AAAA,IAAY,oBAOX;AAPD,WAAY,oBAAoB;IAC/B,+FAAuE,CAAA;IACvE,iDAAyB,CAAA;IACzB,yEAAiD,CAAA;IACjD,6DAAqC,CAAA;IACrC,+EAAuD,CAAA;IACvD,qEAA6C,CAAA;AAC9C,CAAC,EAPW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAO/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-recaptcha-context.js","sourceRoot":"","sources":["../../src/enums/google-recaptcha-context.ts"],"names":[],"mappings":";;;AAAA,IAAY,sBAGX;AAHD,WAAY,sBAAsB;
|
|
1
|
+
{"version":3,"file":"google-recaptcha-context.js","sourceRoot":"","sources":["../../src/enums/google-recaptcha-context.ts"],"names":[],"mappings":";;;AAAA,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IACjC,6DAAmC,CAAA;IACnC,iFAAuD,CAAA;AACxD,CAAC,EAHW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAGjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-recaptcha-enterprise-reason.js","sourceRoot":"","sources":["../../src/enums/google-recaptcha-enterprise-reason.ts"],"names":[],"mappings":";;;AAAA,IAAY,+BASX;AATD,WAAY,+BAA+B;
|
|
1
|
+
{"version":3,"file":"google-recaptcha-enterprise-reason.js","sourceRoot":"","sources":["../../src/enums/google-recaptcha-enterprise-reason.ts"],"names":[],"mappings":";;;AAAA,IAAY,+BASX;AATD,WAAY,+BAA+B;IAC1C,0FAAuD,CAAA;IACvD,kFAA+C,CAAA;IAC/C,0DAAuB,CAAA;IACvB,sDAAmB,CAAA;IACnB,gDAAa,CAAA;IACb,iEAA8B,CAAA;IAC9B,sDAAmB,CAAA;IACnB,iEAA8B,CAAA;AAC/B,CAAC,EATW,+BAA+B,GAA/B,uCAA+B,KAA/B,uCAA+B,QAS1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-recaptcha-network.js","sourceRoot":"","sources":["../../src/enums/google-recaptcha-network.ts"],"names":[],"mappings":";;;AAAA,IAAY,sBAGX;AAHD,WAAY,sBAAsB;
|
|
1
|
+
{"version":3,"file":"google-recaptcha-network.js","sourceRoot":"","sources":["../../src/enums/google-recaptcha-network.ts"],"names":[],"mappings":";;;AAAA,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IACjC,oFAA0D,CAAA;IAC1D,sFAA4D,CAAA;AAC7D,CAAC,EAHW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAGjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-recaptcha-network.exception.js","sourceRoot":"","sources":["../../src/exceptions/google-recaptcha-network.exception.ts"],"names":[],"mappings":";;;AAAA,6EAAwE;AACxE,oDAAgD;AAEhD,MAAa,+BAAgC,SAAQ,qDAAwB;
|
|
1
|
+
{"version":3,"file":"google-recaptcha-network.exception.js","sourceRoot":"","sources":["../../src/exceptions/google-recaptcha-network.exception.ts"],"names":[],"mappings":";;;AAAA,6EAAwE;AACxE,oDAAgD;AAEhD,MAAa,+BAAgC,SAAQ,qDAAwB;IAC5E,YAA4B,gBAAyB;QACpD,KAAK,CAAC,CAAC,sBAAS,CAAC,YAAY,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,kBAAkB,gBAAgB,IAAI,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC;QAD3F,qBAAgB,GAAhB,gBAAgB,CAAS;IAErD,CAAC;CACD;AAJD,0EAIC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-recaptcha.exception.js","sourceRoot":"","sources":["../../src/exceptions/google-recaptcha.exception.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"google-recaptcha.exception.js","sourceRoot":"","sources":["../../src/exceptions/google-recaptcha.exception.ts"],"names":[],"mappings":";;;AAAA,2CAA2D;AAC3D,oDAAgD;AAEhD,MAAa,wBAAyB,SAAQ,sBAAa;IAC1D,YAA4B,UAAuB,EAAE,YAAqB;QACzE,KAAK,CACJ,YAAY,IAAI,wBAAwB,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EACvE,wBAAwB,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CACtD,CAAC;QAJyB,eAAU,GAAV,UAAU,CAAa;IAKnD,CAAC;IAEO,MAAM,CAAC,eAAe,CAAC,SAAoB;QAClD,QAAQ,SAAS,EAAE;YAClB,KAAK,sBAAS,CAAC,oBAAoB;gBAClC,OAAO,iDAAiD,CAAC;YAE1D,KAAK,sBAAS,CAAC,oBAAoB;gBAClC,OAAO,oCAAoC,CAAC;YAC7C,KAAK,sBAAS,CAAC,kBAAkB;gBAChC,OAAO,iFAAiF,CAAC;YAE1F,KAAK,sBAAS,CAAC,kBAAkB,CAAC;YAClC,KAAK,sBAAS,CAAC,kBAAkB;gBAChC,OAAO,gEAAgE,CAAC;YAEzE,KAAK,sBAAS,CAAC,WAAW;gBACzB,OAAO,gDAAgD,CAAC;YAEzD,KAAK,sBAAS,CAAC,QAAQ;gBACtB,OAAO,sBAAsB,CAAC;YAE/B,KAAK,sBAAS,CAAC,eAAe;gBAC7B,OAAO,6BAA6B,CAAC;YAEtC,KAAK,sBAAS,CAAC,YAAY;gBAC1B,OAAO,kEAAkE,CAAC;YAE3E,KAAK,sBAAS,CAAC,YAAY;gBAC1B,OAAO,oEAAoE,CAAC;YAE7E,KAAK,sBAAS,CAAC,mBAAmB;gBACjC,OAAO,uBAAuB,CAAC;YAEhC,KAAK,sBAAS,CAAC,YAAY,CAAC;YAC5B,KAAK,sBAAS,CAAC,UAAU,CAAC;YAC1B;gBACC,OAAO,qEAAqE,CAAC;SAC9E;IACF,CAAC;IAEO,MAAM,CAAC,cAAc,CAAC,SAAoB;QACjD,OAAO,SAAS,KAAK,sBAAS,CAAC,oBAAoB;YAClD,SAAS,KAAK,sBAAS,CAAC,oBAAoB;YAC5C,SAAS,KAAK,sBAAS,CAAC,kBAAkB;YAC1C,SAAS,KAAK,sBAAS,CAAC,eAAe;YACvC,SAAS,KAAK,sBAAS,CAAC,YAAY;YACpC,SAAS,KAAK,sBAAS,CAAC,YAAY;YACpC,SAAS,KAAK,sBAAS,CAAC,mBAAmB;YAC3C,SAAS,KAAK,sBAAS,CAAC,QAAQ;YAChC,SAAS,KAAK,sBAAS,CAAC,WAAW;YACnC,CAAC,CAAC,mBAAU,CAAC,WAAW;YACxB,CAAC,CAAC,mBAAU,CAAC,qBAAqB,CAAC;IACrC,CAAC;CACD;AA5DD,4DA4DC"}
|
|
@@ -4,7 +4,6 @@ export declare class GoogleRecaptchaModule {
|
|
|
4
4
|
private static axiosDefaultConfig;
|
|
5
5
|
static forRoot(options: GoogleRecaptchaModuleOptions): DynamicModule;
|
|
6
6
|
static forRootAsync(options: GoogleRecaptchaModuleAsyncOptions): DynamicModule;
|
|
7
|
-
private static resolveHttpModule;
|
|
8
7
|
private static transformAxiosConfig;
|
|
9
8
|
private static createAsyncProviders;
|
|
10
9
|
private static createAsyncOptionsProvider;
|
|
@@ -7,13 +7,13 @@ const google_recaptcha_validator_1 = require("./services/validators/google-recap
|
|
|
7
7
|
const google_recaptcha_enterprise_validator_1 = require("./services/validators/google-recaptcha-enterprise.validator");
|
|
8
8
|
const provider_declarations_1 = require("./provider.declarations");
|
|
9
9
|
const recaptcha_request_resolver_1 = require("./services/recaptcha-request.resolver");
|
|
10
|
-
const load_module_1 = require("./helpers/load-module");
|
|
11
10
|
const core_1 = require("@nestjs/core");
|
|
12
11
|
const axios = require("axios");
|
|
13
12
|
const https_1 = require("https");
|
|
14
13
|
const recaptcha_validator_resolver_1 = require("./services/recaptcha-validator.resolver");
|
|
15
14
|
const enterprise_reason_transformer_1 = require("./services/enterprise-reason.transformer");
|
|
16
15
|
const xor_1 = require("./helpers/xor");
|
|
16
|
+
const axios_1 = require("@nestjs/axios");
|
|
17
17
|
class GoogleRecaptchaModule {
|
|
18
18
|
static forRoot(options) {
|
|
19
19
|
const providers = [
|
|
@@ -34,14 +34,11 @@ class GoogleRecaptchaModule {
|
|
|
34
34
|
},
|
|
35
35
|
];
|
|
36
36
|
this.validateOptions(options);
|
|
37
|
-
const httpModule = this.resolveHttpModule();
|
|
38
37
|
const internalProviders = [
|
|
39
38
|
{
|
|
40
39
|
provide: provider_declarations_1.RECAPTCHA_HTTP_SERVICE,
|
|
41
|
-
useFactory: (axiosInstance) => new
|
|
42
|
-
inject: [
|
|
43
|
-
provider_declarations_1.RECAPTCHA_AXIOS_INSTANCE,
|
|
44
|
-
],
|
|
40
|
+
useFactory: (axiosInstance) => new axios_1.HttpService(axiosInstance),
|
|
41
|
+
inject: [provider_declarations_1.RECAPTCHA_AXIOS_INSTANCE],
|
|
45
42
|
},
|
|
46
43
|
{
|
|
47
44
|
provide: provider_declarations_1.RECAPTCHA_AXIOS_INSTANCE,
|
|
@@ -51,9 +48,6 @@ class GoogleRecaptchaModule {
|
|
|
51
48
|
return {
|
|
52
49
|
global: true,
|
|
53
50
|
module: GoogleRecaptchaModule,
|
|
54
|
-
imports: [
|
|
55
|
-
httpModule.HttpModule,
|
|
56
|
-
],
|
|
57
51
|
providers: providers.concat(internalProviders),
|
|
58
52
|
exports: providers,
|
|
59
53
|
};
|
|
@@ -64,9 +58,7 @@ class GoogleRecaptchaModule {
|
|
|
64
58
|
{
|
|
65
59
|
provide: provider_declarations_1.RECAPTCHA_LOGGER,
|
|
66
60
|
useFactory: (options) => options.logger || new common_1.Logger(),
|
|
67
|
-
inject: [
|
|
68
|
-
provider_declarations_1.RECAPTCHA_OPTIONS,
|
|
69
|
-
],
|
|
61
|
+
inject: [provider_declarations_1.RECAPTCHA_OPTIONS],
|
|
70
62
|
},
|
|
71
63
|
google_recaptcha_guard_1.GoogleRecaptchaGuard,
|
|
72
64
|
google_recaptcha_validator_1.GoogleRecaptchaValidator,
|
|
@@ -76,14 +68,11 @@ class GoogleRecaptchaModule {
|
|
|
76
68
|
enterprise_reason_transformer_1.EnterpriseReasonTransformer,
|
|
77
69
|
...this.createAsyncProviders(options),
|
|
78
70
|
];
|
|
79
|
-
const httpModule = this.resolveHttpModule();
|
|
80
71
|
const internalProviders = [
|
|
81
72
|
{
|
|
82
73
|
provide: provider_declarations_1.RECAPTCHA_HTTP_SERVICE,
|
|
83
|
-
useFactory: (axiosInstance) => new
|
|
84
|
-
inject: [
|
|
85
|
-
provider_declarations_1.RECAPTCHA_AXIOS_INSTANCE,
|
|
86
|
-
],
|
|
74
|
+
useFactory: (axiosInstance) => new axios_1.HttpService(axiosInstance),
|
|
75
|
+
inject: [provider_declarations_1.RECAPTCHA_AXIOS_INSTANCE],
|
|
87
76
|
},
|
|
88
77
|
{
|
|
89
78
|
provide: provider_declarations_1.RECAPTCHA_AXIOS_INSTANCE,
|
|
@@ -92,34 +81,18 @@ class GoogleRecaptchaModule {
|
|
|
92
81
|
const transformedAxiosConfig = this.transformAxiosConfig(Object.assign(Object.assign(Object.assign({}, this.axiosDefaultConfig), options.axiosConfig), { headers: null }));
|
|
93
82
|
return axios.default.create(transformedAxiosConfig);
|
|
94
83
|
},
|
|
95
|
-
inject: [
|
|
96
|
-
provider_declarations_1.RECAPTCHA_OPTIONS,
|
|
97
|
-
],
|
|
84
|
+
inject: [provider_declarations_1.RECAPTCHA_OPTIONS],
|
|
98
85
|
},
|
|
99
86
|
];
|
|
100
87
|
return {
|
|
101
88
|
global: true,
|
|
102
89
|
module: GoogleRecaptchaModule,
|
|
103
|
-
imports:
|
|
104
|
-
...options.imports || [],
|
|
105
|
-
httpModule.HttpModule,
|
|
106
|
-
],
|
|
90
|
+
imports: options.imports,
|
|
107
91
|
providers: providers.concat(internalProviders),
|
|
108
92
|
exports: providers,
|
|
109
93
|
};
|
|
110
94
|
}
|
|
111
|
-
static resolveHttpModule() {
|
|
112
|
-
try {
|
|
113
|
-
return (0, load_module_1.loadModule)('@nestjs/axios');
|
|
114
|
-
}
|
|
115
|
-
catch (e) {
|
|
116
|
-
return (0, load_module_1.loadModule)('@nestjs/common');
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
95
|
static transformAxiosConfig(axiosConfig) {
|
|
120
|
-
if (!axiosConfig) {
|
|
121
|
-
return {};
|
|
122
|
-
}
|
|
123
96
|
const config = Object.assign({}, axiosConfig);
|
|
124
97
|
delete config.baseURL;
|
|
125
98
|
delete config.url;
|
|
@@ -155,7 +128,7 @@ class GoogleRecaptchaModule {
|
|
|
155
128
|
provide: provider_declarations_1.RECAPTCHA_OPTIONS,
|
|
156
129
|
useFactory: async (optionsFactory) => {
|
|
157
130
|
if (!this.isGoogleRecaptchaFactory(optionsFactory)) {
|
|
158
|
-
throw new Error(
|
|
131
|
+
throw new Error("Factory must be implement 'GoogleRecaptchaOptionsFactory' interface.");
|
|
159
132
|
}
|
|
160
133
|
return optionsFactory.createGoogleRecaptchaOptions();
|
|
161
134
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-recaptcha.module.js","sourceRoot":"","sources":["../src/google-recaptcha.module.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"google-recaptcha.module.js","sourceRoot":"","sources":["../src/google-recaptcha.module.ts"],"names":[],"mappings":";;;AAAA,2CAAiE;AACjE,4EAAuE;AACvE,iGAA4F;AAC5F,uHAAiH;AAMjH,mEAAgI;AAChI,sFAAiF;AACjF,uCAAyC;AACzC,+BAA+B;AAC/B,iCAA8B;AAC9B,0FAAqF;AACrF,4FAAuF;AACvF,uCAAoC;AACpC,yCAA4C;AAE5C,MAAa,qBAAqB;IAMjC,MAAM,CAAC,OAAO,CAAC,OAAqC;QACnD,MAAM,SAAS,GAAe;YAC7B,gBAAS;YACT,6CAAoB;YACpB,qDAAwB;YACxB,0EAAkC;YAClC,qDAAwB;YACxB,yDAA0B;YAC1B,2DAA2B;YAC3B;gBACC,OAAO,EAAE,yCAAiB;gBAC1B,QAAQ,EAAE,OAAO;aACjB;YACD;gBACC,OAAO,EAAE,wCAAgB;gBACzB,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,eAAM,EAAE;aAChD;SACD,CAAC;QAEF,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAE9B,MAAM,iBAAiB,GAAe;YACrC;gBACC,OAAO,EAAE,8CAAsB;gBAC/B,UAAU,EAAE,CAAC,aAAkC,EAAE,EAAE,CAAC,IAAI,mBAAW,CAAC,aAAa,CAAC;gBAClF,MAAM,EAAE,CAAC,gDAAwB,CAAC;aAClC;YACD;gBACC,OAAO,EAAE,gDAAwB;gBACjC,UAAU,EAAE,GAAG,EAAE,CAChB,KAAK,CAAC,OAAO,CAAC,MAAM,CACnB,IAAI,CAAC,oBAAoB,+CACrB,IAAI,CAAC,kBAAkB,GACvB,OAAO,CAAC,WAAW,KACtB,OAAO,EAAE,IAAI,IACZ,CACF;aACF;SACD,CAAC;QAEF,OAAO;YACN,MAAM,EAAE,IAAI;YAC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CAAC,IAAI,CAAC,wBAAwB,CAAC,cAAc,CAAC,EAAE;oBACnD,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;iBACxF;gBACD,OAAO,cAAc,CAAC,4BAA4B,EAAE,CAAC;YACtD,CAAC;YACD,MAAM,EAAE,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,QAAQ,CAAC;SACjD,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,eAAe,CAAC,OAAqC;QACnE,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QAC5E,IAAI,CAAC,IAAA,SAAG,EAAC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,oBAAoB,CAAC,EAAE;YACpD,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;SAC3F;IACF,CAAC;IAEO,MAAM,CAAC,wBAAwB,CAAC,MAAsC;QAC7E,OAAO,CAAC,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,4BAA4B,KAAK,UAAU,CAAC;IAC9E,CAAC;;AAlKF,sDAmKC;AAlKe,wCAAkB,GAA6B;IAC7D,OAAO,EAAE,KAAM;IACf,UAAU,EAAE,IAAI,aAAK,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;CAC1C,CAAC"}
|
|
@@ -31,16 +31,12 @@ let GoogleRecaptchaGuard = class GoogleRecaptchaGuard {
|
|
|
31
31
|
}
|
|
32
32
|
async canActivate(context) {
|
|
33
33
|
const request = this.requestResolver.resolve(context);
|
|
34
|
-
const skip = typeof this.options.skipIf === 'function'
|
|
35
|
-
? await this.options.skipIf(request)
|
|
36
|
-
: !!this.options.skipIf;
|
|
34
|
+
const skip = typeof this.options.skipIf === 'function' ? await this.options.skipIf(request) : !!this.options.skipIf;
|
|
37
35
|
if (skip) {
|
|
38
36
|
return true;
|
|
39
37
|
}
|
|
40
38
|
const options = this.reflector.get(provider_declarations_1.RECAPTCHA_VALIDATION_OPTIONS, context.getHandler());
|
|
41
|
-
const response = (options === null || options === void 0 ? void 0 : options.response)
|
|
42
|
-
? await (options === null || options === void 0 ? void 0 : options.response(request))
|
|
43
|
-
: await this.options.response(request);
|
|
39
|
+
const response = (options === null || options === void 0 ? void 0 : options.response) ? await options.response(request) : await this.options.response(request);
|
|
44
40
|
const score = (options === null || options === void 0 ? void 0 : options.score) || this.options.score;
|
|
45
41
|
const action = options === null || options === void 0 ? void 0 : options.action;
|
|
46
42
|
const validator = this.validatorResolver.resolve();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-recaptcha.guard.js","sourceRoot":"","sources":["../../src/guards/google-recaptcha.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA0G;AAC1G,oEAA6G;AAC7G,yFAAoF;AACpF,uCAAyC;AACzC,uFAAkF;AAGlF,2FAAsF;AACtF,gFAA2E;AAE3E,wHAAkH;
|
|
1
|
+
{"version":3,"file":"google-recaptcha.guard.js","sourceRoot":"","sources":["../../src/guards/google-recaptcha.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA0G;AAC1G,oEAA6G;AAC7G,yFAAoF;AACpF,uCAAyC;AACzC,uFAAkF;AAGlF,2FAAsF;AACtF,gFAA2E;AAE3E,wHAAkH;AAG3G,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAChC,YACkB,SAAoB,EACpB,eAAyC,EACzC,iBAA6C,EACnB,MAAc,EACb,OAAqC;QAJhE,cAAS,GAAT,SAAS,CAAW;QACpB,oBAAe,GAAf,eAAe,CAA0B;QACzC,sBAAiB,GAAjB,iBAAiB,CAA4B;QACnB,WAAM,GAAN,MAAM,CAAQ;QACb,YAAO,GAAP,OAAO,CAA8B;IAC/E,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,OAAyB;QAC1C,MAAM,OAAO,GAAkB,IAAI,CAAC,eAAe,CAAC,OAA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I,OAAO,CAAC,yBAAyB,CAAC,OAAO,EAAE;YAC9C,OAAO,IAAI,CAAC;SACZ;QAED,MAAM,IAAI,qDAAwB,CAAC,OAAO,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAC9E,CAAC;IAEO,iBAAiB,CAAC,SAAoD;QAC7E,OAAO,SAAS,YAAY,0EAAkC;YAC7D,CAAC,CAAC,iDAAsB,CAAC,yBAAyB;YAClD,CAAC,CAAC,iDAAsB,CAAC,eAAe,CAAC;IAC3C,CAAC;CACD,CAAA;AA9CY,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAMV,WAAA,IAAA,eAAM,EAAC,wCAAgB,CAAC,CAAA;IACxB,WAAA,IAAA,eAAM,EAAC,yCAAiB,CAAC,CAAA;qCAJE,gBAAS;QACH,qDAAwB;QACtB,yDAA0B;QACX,eAAM;GAL9C,oBAAoB,CA8ChC;AA9CY,oDAAoB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getErrorInfo = exports.isAxiosError = void 0;
|
|
4
|
+
function isAxiosError(error) {
|
|
5
|
+
return error.isAxiosError;
|
|
6
|
+
}
|
|
7
|
+
exports.isAxiosError = isAxiosError;
|
|
8
|
+
function getErrorInfo(error) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (isAxiosError(error)) {
|
|
11
|
+
return ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.code || 'Unknown axios error';
|
|
12
|
+
}
|
|
13
|
+
return { error: error.name, message: error.message, stack: error.stack };
|
|
14
|
+
}
|
|
15
|
+
exports.getErrorInfo = getErrorInfo;
|
|
16
|
+
//# sourceMappingURL=get-error-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-error-info.js","sourceRoot":"","sources":["../../src/helpers/get-error-info.ts"],"names":[],"mappings":";;;AAGA,SAAgB,YAAY,CAAC,KAA+B;IAC3D,OAA0B,KAAM,CAAC,YAAY,CAAC;AAC/C,CAAC;AAFD,oCAEC;AAED,SAAgB,YAAY,CAAC,KAAY;;IACxC,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,IAAI,KAAI,KAAK,CAAC,IAAI,IAAI,qBAAqB,CAAC;KACnE;IAED,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;AAC1E,CAAC;AAND,oCAMC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-module.js","sourceRoot":"","sources":["../../src/helpers/load-module.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AAEvD,SAAgB,UAAU,CAAC,UAAkB,EAAE,QAAQ,GAAG,KAAK;
|
|
1
|
+
{"version":3,"file":"load-module.js","sourceRoot":"","sources":["../../src/helpers/load-module.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AAEvD,SAAgB,UAAU,CAAC,UAAkB,EAAE,QAAQ,GAAG,KAAK;IAC9D,IAAI;QACH,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;KAC3B;IAAC,OAAO,CAAC,EAAE;QACX,IAAI,QAAQ,EAAE;YACb,eAAM,CAAC,KAAK,CAAC,WAAW,UAAU,4CAA4C,UAAU,EAAE,CAAC,CAAC;SAC5F;QACD,MAAM,CAAC,CAAC;KACR;AACF,CAAC;AATD,gCASC"}
|
package/helpers/xor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xor.js","sourceRoot":"","sources":["../../src/helpers/xor.ts"],"names":[],"mappings":";;;AAAA,SAAgB,GAAG,CAAC,CAAU,EAAE,CAAU;
|
|
1
|
+
{"version":3,"file":"xor.js","sourceRoot":"","sources":["../../src/helpers/xor.ts"],"names":[],"mappings":";;;AAAA,SAAgB,GAAG,CAAC,CAAU,EAAE,CAAU;IACzC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC;AAFD,kBAEC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ErrorCode } from '../enums/error-code';
|
|
2
|
-
import {
|
|
2
|
+
import { VerifyResponseEnterpriseRiskAnalysis } from '../interfaces/verify-response-enterprise';
|
|
3
3
|
import { LiteralObject } from '@nestjs/common';
|
|
4
4
|
export interface RecaptchaVerificationResultOptions<Res> {
|
|
5
5
|
success: boolean;
|
|
@@ -19,5 +19,5 @@ export declare class RecaptchaVerificationResult<Res = LiteralObject> {
|
|
|
19
19
|
readonly errors: ErrorCode[];
|
|
20
20
|
constructor(options: RecaptchaVerificationResultOptions<Res>);
|
|
21
21
|
getResponse(): Res;
|
|
22
|
-
getEnterpriseRiskAnalytics():
|
|
22
|
+
getEnterpriseRiskAnalytics(): VerifyResponseEnterpriseRiskAnalysis | null;
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recaptcha-verification-result.js","sourceRoot":"","sources":["../../src/models/recaptcha-verification-result.ts"],"names":[],"mappings":";;;AAaA,MAAa,2BAA2B;
|
|
1
|
+
{"version":3,"file":"recaptcha-verification-result.js","sourceRoot":"","sources":["../../src/models/recaptcha-verification-result.ts"],"names":[],"mappings":";;;AAaA,MAAa,2BAA2B;IAavC,YAA6B,OAAgD;QAAhD,YAAO,GAAP,OAAO,CAAyC;QAC5E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI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
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
2
|
+
"name": "@nestlab/google-recaptcha",
|
|
3
|
+
"version": "3.1.5",
|
|
4
|
+
"description": "Google recaptcha module for NestJS.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nestjs",
|
|
7
|
+
"recaptcha",
|
|
8
|
+
"google recaptcha",
|
|
9
|
+
"nestjs recaptcha"
|
|
10
|
+
],
|
|
11
|
+
"private": false,
|
|
12
|
+
"main": "index.js",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rimraf dist && tsc && cp package.json dist && cp README.md dist && cp LICENSE dist && cp CONTRIBUTING.md dist",
|
|
15
|
+
"format": "prettier \"**/*.ts\" \"**/*.json\" --ignore-path --write",
|
|
16
|
+
"lint:fix": "eslint . --fix",
|
|
17
|
+
"lint:check": "eslint . --max-warnings=0",
|
|
18
|
+
"test": "jest --silent=false",
|
|
19
|
+
"test:cov": "jest --coverage",
|
|
20
|
+
"test:coveralls": "jest --runInBand --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/chvarkov/google-recaptcha.git"
|
|
25
|
+
},
|
|
26
|
+
"author": "Alexey Chvarkov",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/chvarkov/google-recaptcha/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/chvarkov/google-recaptcha",
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@nestjs/axios": ">=0.0.1 <1.0.0",
|
|
34
|
+
"@nestjs/common": ">=8.0.0 <10.0.0",
|
|
35
|
+
"@nestjs/core": ">=8.0.0 <10.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"@nestjs/graphql": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@nestjs/apollo": "^10.0.22",
|
|
44
|
+
"@nestjs/axios": "^0.1.0",
|
|
45
|
+
"@nestjs/common": "^9.0.11",
|
|
46
|
+
"@nestjs/core": "^9.0.11",
|
|
47
|
+
"@nestjs/graphql": "^10.0.22",
|
|
48
|
+
"@nestjs/platform-express": "^9.0.11",
|
|
49
|
+
"@nestjs/testing": "^9.0.11",
|
|
50
|
+
"@types/express": "^4.17.13",
|
|
51
|
+
"@types/jest": "^29.0.0",
|
|
52
|
+
"@types/node": "^18.7.14",
|
|
53
|
+
"@types/supertest": "^2.0.12",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
|
55
|
+
"@typescript-eslint/parser": "^5.36.1",
|
|
56
|
+
"apollo-server-express": "^3.10.2",
|
|
57
|
+
"coveralls": "^3.1.1",
|
|
58
|
+
"eslint": "^8.23.0",
|
|
59
|
+
"graphql": "^16.6.0",
|
|
60
|
+
"jest": "^28.1.3",
|
|
61
|
+
"prettier": "^2.7.1",
|
|
62
|
+
"reflect-metadata": "^0.1.13",
|
|
63
|
+
"rxjs": "^7.5.6",
|
|
64
|
+
"supertest": "^6.2.4",
|
|
65
|
+
"ts-jest": "^28.0.8",
|
|
66
|
+
"ts-loader": "^9.3.1",
|
|
67
|
+
"ts-node": "^10.9.1",
|
|
68
|
+
"typescript": "^4.8.2"
|
|
69
|
+
},
|
|
70
|
+
"jest": {
|
|
71
|
+
"moduleFileExtensions": [
|
|
72
|
+
"js",
|
|
73
|
+
"json",
|
|
74
|
+
"ts"
|
|
75
|
+
],
|
|
76
|
+
"rootDir": ".",
|
|
77
|
+
"roots": [
|
|
78
|
+
"<rootDir>/test"
|
|
79
|
+
],
|
|
80
|
+
"testRegex": ".spec.ts$",
|
|
81
|
+
"transform": {
|
|
82
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
83
|
+
},
|
|
84
|
+
"coverageDirectory": "./coverage",
|
|
85
|
+
"testEnvironment": "node",
|
|
86
|
+
"collectCoverageFrom": [
|
|
87
|
+
"src/**/*.ts"
|
|
88
|
+
]
|
|
89
|
+
}
|
|
91
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enterprise-reason.transformer.js","sourceRoot":"","sources":["../../src/services/enterprise-reason.transformer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,oGAA8F;AAC9F,oDAAgD;
|
|
1
|
+
{"version":3,"file":"enterprise-reason.transformer.js","sourceRoot":"","sources":["../../src/services/enterprise-reason.transformer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,oGAA8F;AAC9F,oDAAgD;AAGzC,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IACvC,SAAS,CAAC,OAAwC;QACjD,QAAQ,OAAO,EAAE;YAChB,KAAK,oEAA+B,CAAC,YAAY;gBAChD,OAAO,sBAAS,CAAC,YAAY,CAAC;YAE/B,KAAK,oEAA+B,CAAC,oBAAoB;gBACxD,OAAO,sBAAS,CAAC,YAAY,CAAC;YAE/B,KAAK,oEAA+B,CAAC,YAAY;gBAChD,OAAO,sBAAS,CAAC,YAAY,CAAC;YAE/B,KAAK,oEAA+B,CAAC,OAAO,CAAC;YAC7C,KAAK,oEAA+B,CAAC,IAAI;gBACxC,OAAO,sBAAS,CAAC,kBAAkB,CAAC;YAErC,KAAK,oEAA+B,CAAC,SAAS;gBAC7C,OAAO,sBAAS,CAAC,oBAAoB,CAAC;YAEvC,KAAK,oEAA+B,CAAC,OAAO;gBAC3C,OAAO,sBAAS,CAAC,oBAAoB,CAAC;YAEvC,KAAK,oEAA+B,CAAC,wBAAwB;gBAC5D,OAAO,sBAAS,CAAC,YAAY,CAAC;YAE/B;gBACC,OAAO,sBAAS,CAAC,YAAY,CAAC;SAC/B;IACF,CAAC;CACD,CAAA;AA7BY,2BAA2B;IADvC,IAAA,mBAAU,GAAE;GACA,2BAA2B,CA6BvC;AA7BY,kEAA2B"}
|
|
@@ -17,10 +17,7 @@ let RecaptchaRequestResolver = class RecaptchaRequestResolver {
|
|
|
17
17
|
case 'http':
|
|
18
18
|
return context.switchToHttp().getRequest();
|
|
19
19
|
case 'graphql':
|
|
20
|
-
return (_c = (_b = (_a = (0, load_module_1.loadModule)('@nestjs/graphql', true)
|
|
21
|
-
.GqlExecutionContext
|
|
22
|
-
.create(context)
|
|
23
|
-
.getContext().req) === null || _a === void 0 ? void 0 : _a.socket) === null || _b === void 0 ? void 0 : _b._httpMessage) === null || _c === void 0 ? void 0 : _c.req;
|
|
20
|
+
return (_c = (_b = (_a = (0, load_module_1.loadModule)('@nestjs/graphql', true).GqlExecutionContext.create(context).getContext().req) === null || _a === void 0 ? void 0 : _a.socket) === null || _b === void 0 ? void 0 : _b._httpMessage) === null || _c === void 0 ? void 0 : _c.req;
|
|
24
21
|
default:
|
|
25
22
|
throw new Error(`Unsupported request type '${contextType}'.`);
|
|
26
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recaptcha-request.resolver.js","sourceRoot":"","sources":["../../src/services/recaptcha-request.resolver.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA8D;AAC9D,wDAAoD;
|
|
1
|
+
{"version":3,"file":"recaptcha-request.resolver.js","sourceRoot":"","sources":["../../src/services/recaptcha-request.resolver.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA8D;AAC9D,wDAAoD;AAI7C,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACpC,OAAO,CAAI,OAAyB;;QACnC,MAAM,WAAW,GAAyB,OAAO,CAAC,OAAO,EAAE,CAAC;QAE5D,QAAQ,WAAW,EAAE;YACpB,KAAK,MAAM;gBACV,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;YAE5C,KAAK,SAAS;gBACb,OAAO,MAAA,MAAA,MAAA,IAAA,wBAAU,EAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC,GAAG,0CAAE,MAAM,0CAAE,YAAY,0CAAE,GAAG,CAAC;YAC5H;gBACC,MAAM,IAAI,KAAK,CAAC,6BAA6B,WAAW,IAAI,CAAC,CAAC;SAC/D;IACF,CAAC;CACD,CAAA;AAdY,wBAAwB;IADpC,IAAA,mBAAU,GAAE;GACA,wBAAwB,CAcpC;AAdY,4DAAwB"}
|
|
@@ -24,11 +24,10 @@ let RecaptchaValidatorResolver = class RecaptchaValidatorResolver {
|
|
|
24
24
|
this.googleRecaptchaEnterpriseValidator = googleRecaptchaEnterpriseValidator;
|
|
25
25
|
}
|
|
26
26
|
resolve() {
|
|
27
|
-
var _a;
|
|
28
27
|
if (this.options.secretKey) {
|
|
29
28
|
return this.googleRecaptchaValidator;
|
|
30
29
|
}
|
|
31
|
-
if (
|
|
30
|
+
if (Object.keys(this.options.enterprise || {}).length) {
|
|
32
31
|
return this.googleRecaptchaEnterpriseValidator;
|
|
33
32
|
}
|
|
34
33
|
throw new Error('Cannot resolve google recaptcha validator');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recaptcha-validator.resolver.js","sourceRoot":"","sources":["../../src/services/recaptcha-validator.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AAEpD,oEAA6D;AAE7D,wFAAmF;AACnF,8GAAwG;
|
|
1
|
+
{"version":3,"file":"recaptcha-validator.resolver.js","sourceRoot":"","sources":["../../src/services/recaptcha-validator.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AAEpD,oEAA6D;AAE7D,wFAAmF;AACnF,8GAAwG;AAGjG,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IACtC,YAC6C,OAAqC,EAC9D,wBAAkD,EAClD,kCAAsE;QAF7C,YAAO,GAAP,OAAO,CAA8B;QAC9D,6BAAwB,GAAxB,wBAAwB,CAA0B;QAClD,uCAAkC,GAAlC,kCAAkC,CAAoC;IACvF,CAAC;IAEJ,OAAO;QACN,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YAC3B,OAAO,IAAI,CAAC,wBAAwB,CAAC;SACrC;QAED,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;YACtD,OAAO,IAAI,CAAC,kCAAkC,CAAC;SAC/C;QAED,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC9D,CAAC;CACD,CAAA;AAlBY,0BAA0B;IADtC,IAAA,mBAAU,GAAE;IAGV,WAAA,IAAA,eAAM,EAAC,yCAAiB,CAAC,CAAA;6CACmB,qDAAwB;QACd,0EAAkC;GAJ9E,0BAA0B,CAkBtC;AAlBY,gEAA0B"}
|
|
@@ -9,9 +9,7 @@ class AbstractGoogleRecaptchaValidator {
|
|
|
9
9
|
if (options.action) {
|
|
10
10
|
return options.action === action;
|
|
11
11
|
}
|
|
12
|
-
return this.options.actions
|
|
13
|
-
? this.options.actions.includes(action)
|
|
14
|
-
: true;
|
|
12
|
+
return this.options.actions ? this.options.actions.includes(action) : true;
|
|
15
13
|
}
|
|
16
14
|
isValidScore(score, validator) {
|
|
17
15
|
const finalValidator = validator || this.options.score;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-google-recaptcha-validator.js","sourceRoot":"","sources":["../../../src/services/validators/abstract-google-recaptcha-validator.ts"],"names":[],"mappings":";;;AAKA,MAAsB,gCAAgC;
|
|
1
|
+
{"version":3,"file":"abstract-google-recaptcha-validator.js","sourceRoot":"","sources":["../../../src/services/validators/abstract-google-recaptcha-validator.ts"],"names":[],"mappings":";;;AAKA,MAAsB,gCAAgC;IACrD,YAAyC,OAAqC;QAArC,YAAO,GAAP,OAAO,CAA8B;IAAG,CAAC;IAIxE,aAAa,CAAC,MAAc,EAAE,OAA+B;QACtE,IAAI,OAAO,CAAC,MAAM,EAAE;YACnB,OAAO,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC;SACjC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC5E,CAAC;IAES,YAAY,CAAC,KAAa,EAAE,SAA0B;QAC/D,MAAM,cAAc,GAAG,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QAEvD,IAAI,cAAc,EAAE;YACnB,IAAI,OAAO,cAAc,KAAK,UAAU,EAAE;gBACzC,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;aAC7B;YAED,OAAO,KAAK,IAAI,cAAc,CAAC;SAC/B;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AA1BD,4EA0BC"}
|
|
@@ -23,6 +23,7 @@ const google_recaptcha_network_exception_1 = require("../../exceptions/google-re
|
|
|
23
23
|
const google_recaptcha_context_1 = require("../../enums/google-recaptcha-context");
|
|
24
24
|
const enterprise_reason_transformer_1 = require("../enterprise-reason.transformer");
|
|
25
25
|
const rxjs_1 = require("rxjs");
|
|
26
|
+
const get_error_info_1 = require("../../helpers/get-error-info");
|
|
26
27
|
let GoogleRecaptchaEnterpriseValidator = class GoogleRecaptchaEnterpriseValidator extends abstract_google_recaptcha_validator_1.AbstractGoogleRecaptchaValidator {
|
|
27
28
|
constructor(http, logger, options, enterpriseReasonTransformer) {
|
|
28
29
|
super(options);
|
|
@@ -35,14 +36,14 @@ let GoogleRecaptchaEnterpriseValidator = class GoogleRecaptchaEnterpriseValidato
|
|
|
35
36
|
var _a, _b, _c;
|
|
36
37
|
const [result, errorDetails] = await this.verifyResponse(options.response, options.action);
|
|
37
38
|
const errors = [];
|
|
38
|
-
let success = result.tokenProperties.valid;
|
|
39
|
-
if (result.tokenProperties.invalidReason) {
|
|
40
|
-
errors.push(this.enterpriseReasonTransformer.transform(result.tokenProperties.invalidReason));
|
|
41
|
-
}
|
|
39
|
+
let success = (result === null || result === void 0 ? void 0 : result.tokenProperties.valid) || false;
|
|
42
40
|
if (errorDetails) {
|
|
43
41
|
errors.push(error_code_1.ErrorCode.UnknownError);
|
|
44
42
|
}
|
|
45
|
-
if (
|
|
43
|
+
if (result) {
|
|
44
|
+
if (result.tokenProperties.invalidReason) {
|
|
45
|
+
errors.push(this.enterpriseReasonTransformer.transform(result.tokenProperties.invalidReason));
|
|
46
|
+
}
|
|
46
47
|
if (!this.isValidAction(result.tokenProperties.action, options)) {
|
|
47
48
|
success = false;
|
|
48
49
|
errors.push(error_code_1.ErrorCode.ForbiddenAction);
|
|
@@ -81,7 +82,7 @@ let GoogleRecaptchaEnterpriseValidator = class GoogleRecaptchaEnterpriseValidato
|
|
|
81
82
|
this.logger.debug({ body }, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptchaEnterprise}.request`);
|
|
82
83
|
}
|
|
83
84
|
return (0, rxjs_1.firstValueFrom)(this.http.post(url, body, config))
|
|
84
|
-
.then(res => res.data)
|
|
85
|
+
.then((res) => res.data)
|
|
85
86
|
.then((data) => {
|
|
86
87
|
if (this.options.debug) {
|
|
87
88
|
this.logger.debug(data, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptchaEnterprise}.response`);
|
|
@@ -89,15 +90,17 @@ let GoogleRecaptchaEnterpriseValidator = class GoogleRecaptchaEnterpriseValidato
|
|
|
89
90
|
return [data, null];
|
|
90
91
|
})
|
|
91
92
|
.catch((err) => {
|
|
92
|
-
var _a, _b;
|
|
93
93
|
if (this.options.debug) {
|
|
94
|
-
this.logger.debug((
|
|
94
|
+
this.logger.debug((0, get_error_info_1.getErrorInfo)(err), `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptchaEnterprise}.error`);
|
|
95
95
|
}
|
|
96
96
|
const networkErrorCode = err.isAxiosError && err.code;
|
|
97
97
|
if (networkErrorCode) {
|
|
98
98
|
throw new google_recaptcha_network_exception_1.GoogleRecaptchaNetworkException(networkErrorCode);
|
|
99
99
|
}
|
|
100
|
-
const errData =
|
|
100
|
+
const errData = {
|
|
101
|
+
status: err.response.status,
|
|
102
|
+
data: err.response.data,
|
|
103
|
+
};
|
|
101
104
|
return [null, errData];
|
|
102
105
|
});
|
|
103
106
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-recaptcha-enterprise.validator.js","sourceRoot":"","sources":["../../../src/services/validators/google-recaptcha-enterprise.validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,uEAA0G;AAC1G,yCAA4C;AAG5C,+FAAyF;AACzF,8FAAyF;AACzF,uDAAmD;AAEnD,4GAAsG;AACtG,mFAA8E;AAE9E,oFAA+E;AAC/E,+BAAsC;
|
|
1
|
+
{"version":3,"file":"google-recaptcha-enterprise.validator.js","sourceRoot":"","sources":["../../../src/services/validators/google-recaptcha-enterprise.validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,uEAA0G;AAC1G,yCAA4C;AAG5C,+FAAyF;AACzF,8FAAyF;AACzF,uDAAmD;AAEnD,4GAAsG;AACtG,mFAA8E;AAE9E,oFAA+E;AAC/E,+BAAsC;AACtC,iEAA4D;AAKrD,IAAM,kCAAkC,GAAxC,MAAM,kCAAmC,SAAQ,sEAA0D;IAGjH,YACkD,IAAiB,EACvB,MAAc,EAC9B,OAAqC,EAC/C,2BAAwD;QAEzE,KAAK,CAAC,OAAO,CAAC,CAAC;QALkC,SAAI,GAAJ,IAAI,CAAa;QACvB,WAAM,GAAN,MAAM,CAAQ;QAExC,gCAA2B,GAA3B,2BAA2B,CAA6B;QANzD,YAAO,G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YAED,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACrB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAqB,EAAkB,EAAE;YAChD,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;gBACvB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAA,6BAAY,EAAC,GAAG,CAAC,EAAE,GAAG,iDAAsB,CAAC,yBAAyB,QAAQ,CAAC,CAAC;aAClG;YAED,MAAM,gBAAgB,GAAG,GAAG,CAAC,YAAY,IAAI,GAAG,CAAC,IAAI,CAAC;YAEtD,IAAI,gBAAgB,EAAE;gBACrB,MAAM,IAAI,oEAA+B,CAAC,gBAAgB,CAAC,CAAC;aAC5D;YAED,MAAM,OAAO,GAAkB;gBAC9B,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM;gBAC3B,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,IAAI;aACvB,CAAC;YAEF,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC;CACD,CAAA;AAnGY,kCAAkC;IAD9C,IAAA,mBAAU,GAAE;IAKV,WAAA,IAAA,eAAM,EAAC,8CAAsB,CAAC,CAAA;IAC9B,WAAA,IAAA,eAAM,EAAC,wCAAgB,CAAC,CAAA;IACxB,WAAA,IAAA,eAAM,EAAC,yCAAiB,CAAC,CAAA;qCAF6B,mBAAW;QACf,eAAM,UAEX,2DAA2B;GAP9D,kCAAkC,CAmG9C;AAnGY,gFAAkC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Logger } from '@nestjs/common';
|
|
2
2
|
import { VerifyResponseOptions } from '../../interfaces/verify-response-decorator-options';
|
|
3
3
|
import { VerifyResponseV3 } from '../../interfaces/verify-response';
|
|
4
|
-
import { HttpService } from
|
|
4
|
+
import { HttpService } from '@nestjs/axios';
|
|
5
5
|
import { GoogleRecaptchaModuleOptions } from '../../interfaces/google-recaptcha-module-options';
|
|
6
6
|
import { AbstractGoogleRecaptchaValidator } from './abstract-google-recaptcha-validator';
|
|
7
7
|
import { RecaptchaVerificationResult } from '../../models/recaptcha-verification-result';
|
|
@@ -23,6 +23,8 @@ const axios_1 = require("@nestjs/axios");
|
|
|
23
23
|
const abstract_google_recaptcha_validator_1 = require("./abstract-google-recaptcha-validator");
|
|
24
24
|
const recaptcha_verification_result_1 = require("../../models/recaptcha-verification-result");
|
|
25
25
|
const google_recaptcha_context_1 = require("../../enums/google-recaptcha-context");
|
|
26
|
+
const rxjs_1 = require("rxjs");
|
|
27
|
+
const get_error_info_1 = require("../../helpers/get-error-info");
|
|
26
28
|
let GoogleRecaptchaValidator = class GoogleRecaptchaValidator extends abstract_google_recaptcha_validator_1.AbstractGoogleRecaptchaValidator {
|
|
27
29
|
constructor(http, logger, options) {
|
|
28
30
|
super(options);
|
|
@@ -37,9 +39,16 @@ let GoogleRecaptchaValidator = class GoogleRecaptchaValidator extends abstract_g
|
|
|
37
39
|
*/
|
|
38
40
|
async validate(options) {
|
|
39
41
|
const result = await this.verifyResponse(options.response);
|
|
40
|
-
const nativeResponse = Object.assign({}, result);
|
|
41
42
|
if (!this.isUseV3(result)) {
|
|
42
|
-
|
|
43
|
+
const resV2 = result;
|
|
44
|
+
return new recaptcha_verification_result_1.RecaptchaVerificationResult({
|
|
45
|
+
nativeResponse: resV2,
|
|
46
|
+
score: undefined,
|
|
47
|
+
action: undefined,
|
|
48
|
+
errors: resV2.errors,
|
|
49
|
+
success: resV2.success,
|
|
50
|
+
hostname: resV2.hostname,
|
|
51
|
+
});
|
|
43
52
|
}
|
|
44
53
|
if (!this.isValidAction(result.action, options)) {
|
|
45
54
|
result.success = false;
|
|
@@ -49,6 +58,7 @@ let GoogleRecaptchaValidator = class GoogleRecaptchaValidator extends abstract_g
|
|
|
49
58
|
result.success = false;
|
|
50
59
|
result.errors.push(error_code_1.ErrorCode.LowScore);
|
|
51
60
|
}
|
|
61
|
+
const nativeResponse = Object.assign({}, result);
|
|
52
62
|
return new recaptcha_verification_result_1.RecaptchaVerificationResult({
|
|
53
63
|
nativeResponse: nativeResponse,
|
|
54
64
|
score: result.score,
|
|
@@ -67,24 +77,22 @@ let GoogleRecaptchaValidator = class GoogleRecaptchaValidator extends abstract_g
|
|
|
67
77
|
if (this.options.debug) {
|
|
68
78
|
this.logger.debug({ body }, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptcha}.request`);
|
|
69
79
|
}
|
|
70
|
-
return this.http.post(url, body, config)
|
|
71
|
-
.
|
|
72
|
-
.then(
|
|
73
|
-
.then(data => {
|
|
80
|
+
return (0, rxjs_1.firstValueFrom)(this.http.post(url, body, config))
|
|
81
|
+
.then((res) => res.data)
|
|
82
|
+
.then((data) => {
|
|
74
83
|
if (this.options.debug) {
|
|
75
84
|
this.logger.debug(data, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptcha}.response`);
|
|
76
85
|
}
|
|
77
86
|
return data;
|
|
78
87
|
})
|
|
79
|
-
.then(result => (Object.assign(Object.assign({}, result), { errors: result['error-codes'] || [] })))
|
|
80
|
-
.then(result => {
|
|
88
|
+
.then((result) => (Object.assign(Object.assign({}, result), { errors: result['error-codes'] || [] })))
|
|
89
|
+
.then((result) => {
|
|
81
90
|
delete result['error-codes'];
|
|
82
91
|
return result;
|
|
83
92
|
})
|
|
84
93
|
.catch((err) => {
|
|
85
|
-
var _a;
|
|
86
94
|
if (this.options.debug) {
|
|
87
|
-
this.logger.debug((
|
|
95
|
+
this.logger.debug((0, get_error_info_1.getErrorInfo)(err), `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptcha}.error`);
|
|
88
96
|
}
|
|
89
97
|
const networkErrorCode = err.isAxiosError && err.code;
|
|
90
98
|
if (networkErrorCode) {
|
|
@@ -97,8 +105,7 @@ let GoogleRecaptchaValidator = class GoogleRecaptchaValidator extends abstract_g
|
|
|
97
105
|
});
|
|
98
106
|
}
|
|
99
107
|
isUseV3(v) {
|
|
100
|
-
return
|
|
101
|
-
('action' in v && typeof v['action'] === 'string');
|
|
108
|
+
return 'score' in v && typeof v['score'] === 'number' && 'action' in v && typeof v['action'] === 'string';
|
|
102
109
|
}
|
|
103
110
|
};
|
|
104
111
|
GoogleRecaptchaValidator = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-recaptcha.validator.js","sourceRoot":"","sources":["../../../src/services/validators/google-recaptcha.validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,uEAA0G;AAC1G,kCAAkC;AAElC,mFAA8E;AAG9E,uDAAmD;AACnD,4GAAsG;AACtG,yCAA4C;AAE5C,+FAAyF;AACzF,8FAAyF;AACzF,mFAA8E;
|
|
1
|
+
{"version":3,"file":"google-recaptcha.validator.js","sourceRoot":"","sources":["../../../src/services/validators/google-recaptcha.validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,uEAA0G;AAC1G,kCAAkC;AAElC,mFAA8E;AAG9E,uDAAmD;AACnD,4GAAsG;AACtG,yCAA4C;AAE5C,+FAAyF;AACzF,8FAAyF;AACzF,mFAA8E;AAC9E,+BAAsC;AACtC,iEAA4D;AAGrD,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,sEAAkD;IAK/F,YACkD,IAAiB,EACvB,MAAc,EAC9B,OAAqC;QAEhE,KAAK,CAAC,OAAO,CAAC,CAAC;QAJkC,SAAI,GAAJ,IAAI,CAAa;QACvB,WAAM,GAAN,MAAM,CAAQ;QANzC,mBAAc,GAAG,iDAAsB,CAAC,MAAM,CAAC;QAE/C,YAAO,GAAG,EAAE,cAAc,EAAE,mCAAmC,EAAE,CAAC;IAQnF,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ,CAAC,OAA8B;QAC5C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAmB,OAAO,CAAC,QAAQ,CAAC,CAAC;QAE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