@nestlab/google-recaptcha 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants.d.ts +1 -0
- package/constants.js +5 -0
- package/constants.js.map +1 -0
- package/google-recaptcha.module.js +12 -0
- package/google-recaptcha.module.js.map +1 -1
- package/guards/google-recaptcha.guard.d.ts +4 -3
- package/guards/google-recaptcha.guard.js +10 -3
- package/guards/google-recaptcha.guard.js.map +1 -1
- package/index.d.ts +0 -1
- package/index.js +1 -3
- package/index.js.map +1 -1
- package/interfaces/google-recaptcha-module-options.d.ts +3 -0
- package/package.json +1 -1
- package/provider.declarations.d.ts +1 -0
- package/provider.declarations.js +2 -1
- package/provider.declarations.js.map +1 -1
- package/services/google-recaptcha.validator.d.ts +4 -2
- package/services/google-recaptcha.validator.js +22 -5
- package/services/google-recaptcha.validator.js.map +1 -1
- package/enums/application-type.d.ts +0 -4
- package/enums/application-type.js +0 -9
- package/enums/application-type.js.map +0 -1
package/constants.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const RECAPTCHA_LOG_CONTEXT = "GoogleRecaptcha";
|
package/constants.js
ADDED
package/constants.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,iBAAiB,CAAC"}
|
|
@@ -12,6 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.GoogleRecaptchaModule = void 0;
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
15
16
|
const google_recaptcha_guard_1 = require("./guards/google-recaptcha.guard");
|
|
16
17
|
const google_recaptcha_validator_1 = require("./services/google-recaptcha.validator");
|
|
17
18
|
const provider_declarations_1 = require("./provider.declarations");
|
|
@@ -31,6 +32,10 @@ class GoogleRecaptchaModule {
|
|
|
31
32
|
provide: provider_declarations_1.RECAPTCHA_OPTIONS,
|
|
32
33
|
useValue: options,
|
|
33
34
|
},
|
|
35
|
+
{
|
|
36
|
+
provide: provider_declarations_1.RECAPTCHA_LOGGER,
|
|
37
|
+
useFactory: () => options.logger || new common_1.Logger(),
|
|
38
|
+
},
|
|
34
39
|
];
|
|
35
40
|
const httpModule = this.resolveHttpModule();
|
|
36
41
|
const internalProviders = [
|
|
@@ -59,6 +64,13 @@ class GoogleRecaptchaModule {
|
|
|
59
64
|
static forRootAsync(options) {
|
|
60
65
|
const providers = [
|
|
61
66
|
core_1.Reflector,
|
|
67
|
+
{
|
|
68
|
+
provide: provider_declarations_1.RECAPTCHA_LOGGER,
|
|
69
|
+
useFactory: (options) => options.logger || new common_1.Logger(),
|
|
70
|
+
inject: [
|
|
71
|
+
provider_declarations_1.RECAPTCHA_OPTIONS,
|
|
72
|
+
],
|
|
73
|
+
},
|
|
62
74
|
google_recaptcha_guard_1.GoogleRecaptchaGuard,
|
|
63
75
|
google_recaptcha_validator_1.GoogleRecaptchaValidator,
|
|
64
76
|
recaptcha_request_resolver_1.RecaptchaRequestResolver,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-recaptcha.module.js","sourceRoot":"","sources":["../src/google-recaptcha.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"google-recaptcha.module.js","sourceRoot":"","sources":["../src/google-recaptcha.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,2CAAiE;AACjE,4EAAuE;AACvE,sFAAiF;AAKjF,mEAKiC;AACjC,sFAAiF;AACjF,uDAAmD;AACnD,uCAAyC;AACzC,+BAA+B;AAC/B,iCAA8B;AAE9B,MAAa,qBAAqB;IAM9B,MAAM,CAAC,OAAO,CAAC,OAAqC;QAChD,MAAM,SAAS,GAAe;YAC1B,gBAAS;YACT,6CAAoB;YACpB,qDA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O,EAAE,KAAM;IACf,UAAU,EAAE,IAAI,aAAK,CAAC,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC;CAC3C,CAAC"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
1
|
+
import { CanActivate, ExecutionContext, Logger } from '@nestjs/common';
|
|
2
2
|
import { GoogleRecaptchaValidator } from '../services/google-recaptcha.validator';
|
|
3
|
-
import { GoogleRecaptchaGuardOptions } from '../interfaces/google-recaptcha-guard-options';
|
|
4
3
|
import { Reflector } from '@nestjs/core';
|
|
5
4
|
import { RecaptchaRequestResolver } from '../services/recaptcha-request.resolver';
|
|
5
|
+
import { GoogleRecaptchaModuleOptions } from '../interfaces/google-recaptcha-module-options';
|
|
6
6
|
export declare class GoogleRecaptchaGuard implements CanActivate {
|
|
7
7
|
private readonly validator;
|
|
8
8
|
private readonly reflector;
|
|
9
9
|
private readonly requestResolver;
|
|
10
|
+
private readonly logger;
|
|
10
11
|
private readonly options;
|
|
11
|
-
constructor(validator: GoogleRecaptchaValidator, reflector: Reflector, requestResolver: RecaptchaRequestResolver, options:
|
|
12
|
+
constructor(validator: GoogleRecaptchaValidator, reflector: Reflector, requestResolver: RecaptchaRequestResolver, logger: Logger, options: GoogleRecaptchaModuleOptions);
|
|
12
13
|
canActivate(context: ExecutionContext): Promise<true | never>;
|
|
13
14
|
}
|
|
@@ -19,11 +19,13 @@ const provider_declarations_1 = require("../provider.declarations");
|
|
|
19
19
|
const google_recaptcha_exception_1 = require("../exceptions/google-recaptcha.exception");
|
|
20
20
|
const core_1 = require("@nestjs/core");
|
|
21
21
|
const recaptcha_request_resolver_1 = require("../services/recaptcha-request.resolver");
|
|
22
|
+
const constants_1 = require("../constants");
|
|
22
23
|
let GoogleRecaptchaGuard = class GoogleRecaptchaGuard {
|
|
23
|
-
constructor(validator, reflector, requestResolver, options) {
|
|
24
|
+
constructor(validator, reflector, requestResolver, logger, options) {
|
|
24
25
|
this.validator = validator;
|
|
25
26
|
this.reflector = reflector;
|
|
26
27
|
this.requestResolver = requestResolver;
|
|
28
|
+
this.logger = logger;
|
|
27
29
|
this.options = options;
|
|
28
30
|
}
|
|
29
31
|
async canActivate(context) {
|
|
@@ -41,6 +43,9 @@ let GoogleRecaptchaGuard = class GoogleRecaptchaGuard {
|
|
|
41
43
|
const score = (options === null || options === void 0 ? void 0 : options.score) || this.options.score;
|
|
42
44
|
const action = options === null || options === void 0 ? void 0 : options.action;
|
|
43
45
|
request.recaptchaValidationResult = await this.validator.validate({ response, score, action });
|
|
46
|
+
if (this.options.debug) {
|
|
47
|
+
this.logger.debug(request.recaptchaValidationResult, `${constants_1.RECAPTCHA_LOG_CONTEXT}.result`);
|
|
48
|
+
}
|
|
44
49
|
if (request.recaptchaValidationResult.success) {
|
|
45
50
|
return true;
|
|
46
51
|
}
|
|
@@ -49,10 +54,12 @@ let GoogleRecaptchaGuard = class GoogleRecaptchaGuard {
|
|
|
49
54
|
};
|
|
50
55
|
GoogleRecaptchaGuard = __decorate([
|
|
51
56
|
(0, common_1.Injectable)(),
|
|
52
|
-
__param(3, (0, common_1.Inject)(provider_declarations_1.
|
|
57
|
+
__param(3, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_LOGGER)),
|
|
58
|
+
__param(4, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_OPTIONS)),
|
|
53
59
|
__metadata("design:paramtypes", [google_recaptcha_validator_1.GoogleRecaptchaValidator,
|
|
54
60
|
core_1.Reflector,
|
|
55
|
-
recaptcha_request_resolver_1.RecaptchaRequestResolver,
|
|
61
|
+
recaptcha_request_resolver_1.RecaptchaRequestResolver,
|
|
62
|
+
common_1.Logger, Object])
|
|
56
63
|
], GoogleRecaptchaGuard);
|
|
57
64
|
exports.GoogleRecaptchaGuard = GoogleRecaptchaGuard;
|
|
58
65
|
//# sourceMappingURL=google-recaptcha.guard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-recaptcha.guard.js","sourceRoot":"","sources":["../../src/guards/google-recaptcha.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"google-recaptcha.guard.js","sourceRoot":"","sources":["../../src/guards/google-recaptcha.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2F;AAC3F,uFAAkF;AAClF,oEAA6G;AAC7G,yFAAoF;AACpF,uCAAyC;AACzC,uFAAkF;AAElF,4CAAqD;AAIrD,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;IAC7B,YAA6B,SAAmC,EACnC,SAAoB,EACpB,eAAyC,EACf,MAAc,EACb,OAAqC;QAJhE,cAAS,GAAT,SAAS,CAA0B;QACnC,cAAS,GAAT,SAAS,CAAW;QACpB,oBAAe,GAAf,eAAe,CAA0B;QACf,WAAM,GAAN,MAAM,CAAQ;QACb,YAAO,GAAP,OAAO,CAA8B;IAC7F,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAyB;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAEtD,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,UAAU;YAClD,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;YACpC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QAE5B,IAAI,IAAI,EAAE;YACN,OAAO,IAAI,CAAC;SACf;QAED,MAAM,OAAO,GAAmC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,oDAA4B,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QAEvH,MAAM,QAAQ,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ;YAC9B,CAAC,CAAC,MAAM,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;YAClC,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAE3C,MAAM,KAAK,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,KAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QACnD,MAAM,MAAM,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC;QAE/B,OAAO,CAAC,yBAAyB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAC,CAAC,CAAC;QAE7F,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;YACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,yBAAyB,EAAE,GAAG,iCAAqB,SAAS,CAAC,CAAC;SAC3F;QAED,IAAI,OAAO,CAAC,yBAAyB,CAAC,OAAO,EAAE;YAC3C,OAAO,IAAI,CAAC;SACf;QAED,MAAM,IAAI,qDAAwB,CAAC,OAAO,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC;IACjF,CAAC;CACJ,CAAA;AAxCY,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAKI,WAAA,IAAA,eAAM,EAAC,wCAAgB,CAAC,CAAA;IACxB,WAAA,IAAA,eAAM,EAAC,yCAAiB,CAAC,CAAA;qCAJE,qDAAwB;QACxB,gBAAS;QACH,qDAAwB;QACP,eAAM;GAJ5D,oBAAoB,CAwChC;AAxCY,oDAAoB"}
|
package/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export { GoogleRecaptchaGuard } from './guards/google-recaptcha.guard';
|
|
|
5
5
|
export { GoogleRecaptchaModule } from './google-recaptcha.module';
|
|
6
6
|
export { GoogleRecaptchaModuleOptions } from './interfaces/google-recaptcha-module-options';
|
|
7
7
|
export { ErrorCode } from './enums/error-code';
|
|
8
|
-
export { ApplicationType } from './enums/application-type';
|
|
9
8
|
export { GoogleRecaptchaNetwork } from './enums/google-recaptcha-network';
|
|
10
9
|
export { GoogleRecaptchaException } from './exceptions/google-recaptcha.exception';
|
|
11
10
|
export { GoogleRecaptchaNetworkException } from './exceptions/google-recaptcha-network.exception';
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GoogleRecaptchaNetworkException = exports.GoogleRecaptchaException = exports.GoogleRecaptchaNetwork = exports.
|
|
3
|
+
exports.GoogleRecaptchaNetworkException = exports.GoogleRecaptchaException = exports.GoogleRecaptchaNetwork = exports.ErrorCode = exports.GoogleRecaptchaModule = exports.GoogleRecaptchaGuard = exports.RecaptchaResult = exports.SetRecaptchaOptions = exports.Recaptcha = void 0;
|
|
4
4
|
var recaptcha_1 = require("./decorators/recaptcha");
|
|
5
5
|
Object.defineProperty(exports, "Recaptcha", { enumerable: true, get: function () { return recaptcha_1.Recaptcha; } });
|
|
6
6
|
var set_recaptcha_options_1 = require("./decorators/set-recaptcha-options");
|
|
@@ -13,8 +13,6 @@ var google_recaptcha_module_1 = require("./google-recaptcha.module");
|
|
|
13
13
|
Object.defineProperty(exports, "GoogleRecaptchaModule", { enumerable: true, get: function () { return google_recaptcha_module_1.GoogleRecaptchaModule; } });
|
|
14
14
|
var error_code_1 = require("./enums/error-code");
|
|
15
15
|
Object.defineProperty(exports, "ErrorCode", { enumerable: true, get: function () { return error_code_1.ErrorCode; } });
|
|
16
|
-
var application_type_1 = require("./enums/application-type");
|
|
17
|
-
Object.defineProperty(exports, "ApplicationType", { enumerable: true, get: function () { return application_type_1.ApplicationType; } });
|
|
18
16
|
var google_recaptcha_network_1 = require("./enums/google-recaptcha-network");
|
|
19
17
|
Object.defineProperty(exports, "GoogleRecaptchaNetwork", { enumerable: true, get: function () { return google_recaptcha_network_1.GoogleRecaptchaNetwork; } });
|
|
20
18
|
var google_recaptcha_exception_1 = require("./exceptions/google-recaptcha.exception");
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oDAAmD;AAA1C,sGAAA,SAAS,OAAA;AAClB,4EAAyE;AAAhE,4HAAA,mBAAmB,OAAA;AAC5B,kEAAgE;AAAvD,mHAAA,eAAe,OAAA;AACxB,0EAAuE;AAA9D,8HAAA,oBAAoB,OAAA;AAC7B,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA;AAE9B,iDAA+C;AAAtC,uGAAA,SAAS,OAAA;AAClB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oDAAmD;AAA1C,sGAAA,SAAS,OAAA;AAClB,4EAAyE;AAAhE,4HAAA,mBAAmB,OAAA;AAC5B,kEAAgE;AAAvD,mHAAA,eAAe,OAAA;AACxB,0EAAuE;AAA9D,8HAAA,oBAAoB,OAAA;AAC7B,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA;AAE9B,iDAA+C;AAAtC,uGAAA,SAAS,OAAA;AAClB,6EAAyE;AAAhE,kIAAA,sBAAsB,OAAA;AAC/B,sFAAmF;AAA1E,sIAAA,wBAAwB,OAAA;AACjC,sGAAkG;AAAzF,qJAAA,+BAA+B,OAAA"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { GoogleRecaptchaGuardOptions } from './google-recaptcha-guard-options';
|
|
2
2
|
import { GoogleRecaptchaValidatorOptions } from './google-recaptcha-validator-options';
|
|
3
3
|
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
|
|
4
|
+
import { Logger } from '@nestjs/common';
|
|
4
5
|
export interface GoogleRecaptchaModuleOptions extends GoogleRecaptchaValidatorOptions, GoogleRecaptchaGuardOptions {
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
logger?: Logger;
|
|
5
8
|
}
|
|
6
9
|
export interface GoogleRecaptchaOptionsFactory {
|
|
7
10
|
createGoogleRecaptchaOptions(): Promise<GoogleRecaptchaModuleOptions> | GoogleRecaptchaModuleOptions;
|
package/package.json
CHANGED
|
@@ -2,3 +2,4 @@ export declare const RECAPTCHA_OPTIONS: unique symbol;
|
|
|
2
2
|
export declare const RECAPTCHA_VALIDATION_OPTIONS: unique symbol;
|
|
3
3
|
export declare const RECAPTCHA_AXIOS_INSTANCE = "RECAPTCHA_AXIOS_INSTANCE";
|
|
4
4
|
export declare const RECAPTCHA_HTTP_SERVICE = "RECAPTCHA_HTTP_SERVICE";
|
|
5
|
+
export declare const RECAPTCHA_LOGGER = "RECAPTCHA_LOGGER";
|
package/provider.declarations.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RECAPTCHA_HTTP_SERVICE = exports.RECAPTCHA_AXIOS_INSTANCE = exports.RECAPTCHA_VALIDATION_OPTIONS = exports.RECAPTCHA_OPTIONS = void 0;
|
|
3
|
+
exports.RECAPTCHA_LOGGER = exports.RECAPTCHA_HTTP_SERVICE = exports.RECAPTCHA_AXIOS_INSTANCE = exports.RECAPTCHA_VALIDATION_OPTIONS = exports.RECAPTCHA_OPTIONS = void 0;
|
|
4
4
|
exports.RECAPTCHA_OPTIONS = Symbol('RECAPTCHA_OPTIONS');
|
|
5
5
|
exports.RECAPTCHA_VALIDATION_OPTIONS = Symbol('RECAPTCHA_VALIDATION_OPTIONS');
|
|
6
6
|
exports.RECAPTCHA_AXIOS_INSTANCE = 'RECAPTCHA_AXIOS_INSTANCE';
|
|
7
7
|
exports.RECAPTCHA_HTTP_SERVICE = 'RECAPTCHA_HTTP_SERVICE';
|
|
8
|
+
exports.RECAPTCHA_LOGGER = 'RECAPTCHA_LOGGER';
|
|
8
9
|
//# sourceMappingURL=provider.declarations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.declarations.js","sourceRoot":"","sources":["../src/provider.declarations.ts"],"names":[],"mappings":";;;AAAa,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAEhD,QAAA,4BAA4B,GAAG,MAAM,CAAC,8BAA8B,CAAC,CAAC;AAEtE,QAAA,wBAAwB,GAAG,0BAA0B,CAAC;AAEtD,QAAA,sBAAsB,GAAG,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"provider.declarations.js","sourceRoot":"","sources":["../src/provider.declarations.ts"],"names":[],"mappings":";;;AAAa,QAAA,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAEhD,QAAA,4BAA4B,GAAG,MAAM,CAAC,8BAA8B,CAAC,CAAC;AAEtE,QAAA,wBAAwB,GAAG,0BAA0B,CAAC;AAEtD,QAAA,sBAAsB,GAAG,wBAAwB,CAAC;AAElD,QAAA,gBAAgB,GAAG,kBAAkB,CAAC"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
2
2
|
import { GoogleRecaptchaValidationResult } from '../interfaces/google-recaptcha-validation-result';
|
|
3
3
|
import { VerifyResponseOptions } from '../interfaces/verify-response-decorator-options';
|
|
4
4
|
import { HttpService } from "@nestjs/axios";
|
|
5
|
+
import { GoogleRecaptchaModuleOptions } from '../interfaces/google-recaptcha-module-options';
|
|
5
6
|
export declare class GoogleRecaptchaValidator {
|
|
6
7
|
private readonly http;
|
|
8
|
+
private readonly logger;
|
|
7
9
|
private readonly options;
|
|
8
10
|
private readonly defaultNetwork;
|
|
9
11
|
private readonly headers;
|
|
10
|
-
constructor(http: HttpService, options:
|
|
12
|
+
constructor(http: HttpService, logger: Logger, options: GoogleRecaptchaModuleOptions);
|
|
11
13
|
/**
|
|
12
14
|
* @throws GoogleRecaptchaNetworkException
|
|
13
15
|
* @param {VerifyResponseOptions} options
|
|
@@ -20,9 +20,11 @@ const google_recaptcha_network_1 = require("../enums/google-recaptcha-network");
|
|
|
20
20
|
const error_code_1 = require("../enums/error-code");
|
|
21
21
|
const google_recaptcha_network_exception_1 = require("../exceptions/google-recaptcha-network.exception");
|
|
22
22
|
const axios_1 = require("@nestjs/axios");
|
|
23
|
+
const constants_1 = require("../constants");
|
|
23
24
|
let GoogleRecaptchaValidator = class GoogleRecaptchaValidator {
|
|
24
|
-
constructor(http, options) {
|
|
25
|
+
constructor(http, logger, options) {
|
|
25
26
|
this.http = http;
|
|
27
|
+
this.logger = logger;
|
|
26
28
|
this.options = options;
|
|
27
29
|
this.defaultNetwork = google_recaptcha_network_1.GoogleRecaptchaNetwork.Google;
|
|
28
30
|
this.headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
|
|
@@ -47,20 +49,33 @@ let GoogleRecaptchaValidator = class GoogleRecaptchaValidator {
|
|
|
47
49
|
return result;
|
|
48
50
|
}
|
|
49
51
|
verifyResponse(response) {
|
|
50
|
-
const
|
|
52
|
+
const body = qs.stringify({ secret: this.options.secretKey, response });
|
|
51
53
|
const url = this.options.network || this.defaultNetwork;
|
|
52
54
|
const config = {
|
|
53
55
|
headers: this.headers,
|
|
54
56
|
};
|
|
55
|
-
|
|
57
|
+
if (this.options.debug) {
|
|
58
|
+
this.logger.debug({ body }, `${constants_1.RECAPTCHA_LOG_CONTEXT}.request`);
|
|
59
|
+
}
|
|
60
|
+
return this.http.post(url, body, config)
|
|
56
61
|
.toPromise()
|
|
57
62
|
.then(res => res.data)
|
|
63
|
+
.then(data => {
|
|
64
|
+
if (this.options.debug) {
|
|
65
|
+
this.logger.debug(data, `${constants_1.RECAPTCHA_LOG_CONTEXT}.response`);
|
|
66
|
+
}
|
|
67
|
+
return data;
|
|
68
|
+
})
|
|
58
69
|
.then(result => (Object.assign(Object.assign({}, result), { errors: result['error-codes'] || [] })))
|
|
59
70
|
.then(result => {
|
|
60
71
|
delete result['error-codes'];
|
|
61
72
|
return result;
|
|
62
73
|
})
|
|
63
74
|
.catch((err) => {
|
|
75
|
+
var _a;
|
|
76
|
+
if (this.options.debug) {
|
|
77
|
+
this.logger.debug(((_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.data) || err.code || { error: `${err === null || err === void 0 ? void 0 : err.name}: ${err === null || err === void 0 ? void 0 : err.message}`, stack: err === null || err === void 0 ? void 0 : err.stack }, `${constants_1.RECAPTCHA_LOG_CONTEXT}.error`);
|
|
78
|
+
}
|
|
64
79
|
const networkErrorCode = err.isAxiosError && err.code;
|
|
65
80
|
if (networkErrorCode) {
|
|
66
81
|
throw new google_recaptcha_network_exception_1.GoogleRecaptchaNetworkException(networkErrorCode);
|
|
@@ -97,8 +112,10 @@ let GoogleRecaptchaValidator = class GoogleRecaptchaValidator {
|
|
|
97
112
|
GoogleRecaptchaValidator = __decorate([
|
|
98
113
|
(0, common_1.Injectable)(),
|
|
99
114
|
__param(0, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_HTTP_SERVICE)),
|
|
100
|
-
__param(1, (0, common_1.Inject)(provider_declarations_1.
|
|
101
|
-
|
|
115
|
+
__param(1, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_LOGGER)),
|
|
116
|
+
__param(2, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_OPTIONS)),
|
|
117
|
+
__metadata("design:paramtypes", [axios_1.HttpService,
|
|
118
|
+
common_1.Logger, Object])
|
|
102
119
|
], GoogleRecaptchaValidator);
|
|
103
120
|
exports.GoogleRecaptchaValidator = GoogleRecaptchaValidator;
|
|
104
121
|
//# sourceMappingURL=google-recaptcha.validator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-recaptcha.validator.js","sourceRoot":"","sources":["../../src/services/google-recaptcha.validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"google-recaptcha.validator.js","sourceRoot":"","sources":["../../src/services/google-recaptcha.validator.ts"],"names":[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D,CAAC,QAAQ,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,QAAQ,CAAC,CAAC;IAC3D,CAAC;CACJ,CAAA;AAhHY,wBAAwB;IADpC,IAAA,mBAAU,GAAE;IAKI,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;GAL5D,wBAAwB,CAgHpC;AAhHY,4DAAwB"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApplicationType = void 0;
|
|
4
|
-
var ApplicationType;
|
|
5
|
-
(function (ApplicationType) {
|
|
6
|
-
ApplicationType["Rest"] = "REST";
|
|
7
|
-
ApplicationType["GraphQL"] = "GRAPH_QL";
|
|
8
|
-
})(ApplicationType = exports.ApplicationType || (exports.ApplicationType = {}));
|
|
9
|
-
//# sourceMappingURL=application-type.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"application-type.js","sourceRoot":"","sources":["../../src/enums/application-type.ts"],"names":[],"mappings":";;;AAAA,IAAY,eAGX;AAHD,WAAY,eAAe;IACvB,gCAAa,CAAA;IACb,uCAAoB,CAAA;AACxB,CAAC,EAHW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAG1B"}
|