Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nestlab/google-recaptcha

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestlab/google-recaptcha - npm Package Compare versions

Comparing version 3.6.0 to 3.7.0

models/recaptcha-config-ref.d.ts

3

CHANGELOG.md
# Changelog
## v3.7.0
- Added `RecaptchaConfigRef` for dynamic configuration
## v3.6.0

@@ -4,0 +7,0 @@ - Added `remoteIp?: (req) => string` option into:

1

decorators/recaptcha-result.js

@@ -15,2 +15,1 @@ "use strict";

});
//# sourceMappingURL=recaptcha-result.js.map

@@ -11,2 +11,1 @@ "use strict";

exports.Recaptcha = Recaptcha;
//# sourceMappingURL=recaptcha.js.map

@@ -10,2 +10,1 @@ "use strict";

exports.SetRecaptchaOptions = SetRecaptchaOptions;
//# sourceMappingURL=set-recaptcha-options.js.map

@@ -13,2 +13,1 @@ "use strict";

})(ClassificationReason = exports.ClassificationReason || (exports.ClassificationReason = {}));
//# sourceMappingURL=classification-reason.js.map

@@ -22,2 +22,1 @@ "use strict";

})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
//# sourceMappingURL=error-code.js.map

@@ -9,2 +9,1 @@ "use strict";

})(GoogleRecaptchaContext = exports.GoogleRecaptchaContext || (exports.GoogleRecaptchaContext = {}));
//# sourceMappingURL=google-recaptcha-context.js.map

@@ -15,2 +15,1 @@ "use strict";

})(GoogleRecaptchaEnterpriseReason = exports.GoogleRecaptchaEnterpriseReason || (exports.GoogleRecaptchaEnterpriseReason = {}));
//# sourceMappingURL=google-recaptcha-enterprise-reason.js.map

@@ -9,2 +9,1 @@ "use strict";

})(GoogleRecaptchaNetwork = exports.GoogleRecaptchaNetwork || (exports.GoogleRecaptchaNetwork = {}));
//# sourceMappingURL=google-recaptcha-network.js.map

@@ -13,2 +13,1 @@ "use strict";

exports.GoogleRecaptchaNetworkException = GoogleRecaptchaNetworkException;
//# sourceMappingURL=google-recaptcha-network.exception.js.map

@@ -55,2 +55,1 @@ "use strict";

exports.GoogleRecaptchaException = GoogleRecaptchaException;
//# sourceMappingURL=google-recaptcha.exception.js.map

@@ -16,2 +16,3 @@ "use strict";

const xor_1 = require("./helpers/xor");
const recaptcha_config_ref_1 = require("./models/recaptcha-config-ref");
class GoogleRecaptchaModule {

@@ -35,2 +36,6 @@ static forRoot(options) {

},
{
provide: recaptcha_config_ref_1.RecaptchaConfigRef,
useFactory: () => new recaptcha_config_ref_1.RecaptchaConfigRef(options),
},
];

@@ -59,2 +64,7 @@ this.validateOptions(options);

},
{
provide: recaptcha_config_ref_1.RecaptchaConfigRef,
useFactory: (opts) => new recaptcha_config_ref_1.RecaptchaConfigRef(opts),
inject: [provider_declarations_1.RECAPTCHA_OPTIONS],
},
google_recaptcha_guard_1.GoogleRecaptchaGuard,

@@ -145,2 +155,1 @@ google_recaptcha_validator_1.GoogleRecaptchaValidator,

};
//# sourceMappingURL=google-recaptcha.module.js.map
import { CanActivate, ExecutionContext, Logger } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { RecaptchaRequestResolver } from '../services/recaptcha-request.resolver';
import { GoogleRecaptchaModuleOptions } from '../interfaces/google-recaptcha-module-options';
import { RecaptchaValidatorResolver } from '../services/recaptcha-validator.resolver';
import { RecaptchaConfigRef } from '../models/recaptcha-config-ref';
export declare class GoogleRecaptchaGuard implements CanActivate {

@@ -11,6 +11,6 @@ private readonly reflector;

private readonly logger;
private readonly options;
constructor(reflector: Reflector, requestResolver: RecaptchaRequestResolver, validatorResolver: RecaptchaValidatorResolver, logger: Logger, options: GoogleRecaptchaModuleOptions);
private readonly configRef;
constructor(reflector: Reflector, requestResolver: RecaptchaRequestResolver, validatorResolver: RecaptchaValidatorResolver, logger: Logger, configRef: RecaptchaConfigRef);
canActivate(context: ExecutionContext): Promise<true | never>;
private resolveLogContext;
}

@@ -24,4 +24,5 @@ "use strict";

const google_recaptcha_enterprise_validator_1 = require("../services/validators/google-recaptcha-enterprise.validator");
const recaptcha_config_ref_1 = require("../models/recaptcha-config-ref");
let GoogleRecaptchaGuard = class GoogleRecaptchaGuard {
constructor(reflector, requestResolver, validatorResolver, logger, options) {
constructor(reflector, requestResolver, validatorResolver, logger, configRef) {
this.reflector = reflector;

@@ -31,7 +32,8 @@ this.requestResolver = requestResolver;

this.logger = logger;
this.options = options;
this.configRef = configRef;
}
async canActivate(context) {
const request = this.requestResolver.resolve(context);
const skip = typeof this.options.skipIf === 'function' ? await this.options.skipIf(request) : !!this.options.skipIf;
const skipIfValue = this.configRef.valueOf.skipIf;
const skip = typeof skipIfValue === 'function' ? await skipIfValue(request) : !!skipIfValue;
if (skip) {

@@ -42,10 +44,10 @@ return true;

const [response, remoteIp] = await Promise.all([
(options === null || options === void 0 ? void 0 : options.response) ? await options.response(request) : await this.options.response(request),
(options === null || options === void 0 ? void 0 : options.remoteIp) ? await options.remoteIp(request) : await this.options.remoteIp && this.options.remoteIp(request),
(options === null || options === void 0 ? void 0 : options.response) ? await options.response(request) : await this.configRef.valueOf.response(request),
(options === null || options === void 0 ? void 0 : options.remoteIp) ? await options.remoteIp(request) : await this.configRef.valueOf.remoteIp && this.configRef.valueOf.remoteIp(request),
]);
const score = (options === null || options === void 0 ? void 0 : options.score) || this.options.score;
const score = (options === null || options === void 0 ? void 0 : options.score) || this.configRef.valueOf.score;
const action = options === null || options === void 0 ? void 0 : options.action;
const validator = this.validatorResolver.resolve();
request.recaptchaValidationResult = await validator.validate({ response, remoteIp, score, action });
if (this.options.debug) {
if (this.configRef.valueOf.debug) {
const loggerCtx = this.resolveLogContext(validator);

@@ -68,9 +70,8 @@ this.logger.debug(request.recaptchaValidationResult.toObject(), `${loggerCtx}.result`);

__param(3, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_LOGGER)),
__param(4, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_OPTIONS)),
__metadata("design:paramtypes", [core_1.Reflector,
recaptcha_request_resolver_1.RecaptchaRequestResolver,
recaptcha_validator_resolver_1.RecaptchaValidatorResolver,
common_1.Logger, Object])
common_1.Logger,
recaptcha_config_ref_1.RecaptchaConfigRef])
], GoogleRecaptchaGuard);
exports.GoogleRecaptchaGuard = GoogleRecaptchaGuard;
//# sourceMappingURL=google-recaptcha.guard.js.map

@@ -16,2 +16,1 @@ "use strict";

exports.getErrorInfo = getErrorInfo;
//# sourceMappingURL=get-error-info.js.map

@@ -17,2 +17,1 @@ "use strict";

exports.loadModule = loadModule;
//# sourceMappingURL=load-module.js.map

@@ -8,2 +8,1 @@ "use strict";

exports.xor = xor;
//# sourceMappingURL=xor.js.map

@@ -15,1 +15,2 @@ export { Recaptcha } from './decorators/recaptcha';

export { ClassificationReason } from './enums/classification-reason';
export { RecaptchaConfigRef } from './models/recaptcha-config-ref';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClassificationReason = exports.RecaptchaVerificationResult = exports.GoogleRecaptchaEnterpriseValidator = exports.GoogleRecaptchaValidator = exports.GoogleRecaptchaNetworkException = exports.GoogleRecaptchaException = exports.GoogleRecaptchaNetwork = exports.ErrorCode = exports.GoogleRecaptchaModule = exports.GoogleRecaptchaGuard = exports.RecaptchaResult = exports.SetRecaptchaOptions = exports.Recaptcha = void 0;
exports.RecaptchaConfigRef = exports.ClassificationReason = exports.RecaptchaVerificationResult = exports.GoogleRecaptchaEnterpriseValidator = exports.GoogleRecaptchaValidator = exports.GoogleRecaptchaNetworkException = exports.GoogleRecaptchaException = exports.GoogleRecaptchaNetwork = exports.ErrorCode = exports.GoogleRecaptchaModule = exports.GoogleRecaptchaGuard = exports.RecaptchaResult = exports.SetRecaptchaOptions = exports.Recaptcha = void 0;
var recaptcha_1 = require("./decorators/recaptcha");

@@ -30,2 +30,3 @@ Object.defineProperty(exports, "Recaptcha", { enumerable: true, get: function () { return recaptcha_1.Recaptcha; } });

Object.defineProperty(exports, "ClassificationReason", { enumerable: true, get: function () { return classification_reason_1.ClassificationReason; } });
//# sourceMappingURL=index.js.map
var recaptcha_config_ref_1 = require("./models/recaptcha-config-ref");
Object.defineProperty(exports, "RecaptchaConfigRef", { enumerable: true, get: function () { return recaptcha_config_ref_1.RecaptchaConfigRef; } });
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=google-recaptcha-enterprise-options.js.map

@@ -1,7 +0,7 @@

import { RecaptchaRemoteIpProvider, RecaptchaResponseProvider, ScoreValidator } from "../types";
import { RecaptchaRemoteIpProvider, RecaptchaResponseProvider, ScoreValidator, SkipIfValue } from '../types';
export interface GoogleRecaptchaGuardOptions {
response: RecaptchaResponseProvider;
remoteIp?: RecaptchaRemoteIpProvider;
skipIf?: boolean | (<Req = unknown>(request: Req) => boolean | Promise<boolean>);
skipIf?: SkipIfValue;
score?: ScoreValidator;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=google-recaptcha-guard-options.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=google-recaptcha-module-options.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=google-recaptcha-validator-options.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=literal-object.js.map

@@ -1,2 +0,2 @@

import { RecaptchaRemoteIpProvider, RecaptchaResponseProvider, ScoreValidator } from "../types";
import { RecaptchaRemoteIpProvider, RecaptchaResponseProvider, ScoreValidator } from '../types';
export interface VerifyResponseDecoratorOptions {

@@ -3,0 +3,0 @@ response?: RecaptchaResponseProvider;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=verify-response-decorator-options.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=verify-response-enterprise.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=verify-response.js.map

@@ -35,2 +35,1 @@ "use strict";

exports.RecaptchaVerificationResult = RecaptchaVerificationResult;
//# sourceMappingURL=recaptcha-verification-result.js.map
{
"name": "@nestlab/google-recaptcha",
"version": "3.6.0",
"version": "3.7.0",
"description": "Google recaptcha module for NestJS.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -8,2 +8,1 @@ "use strict";

exports.RECAPTCHA_LOGGER = 'RECAPTCHA_LOGGER';
//# sourceMappingURL=provider.declarations.js.map

@@ -30,2 +30,3 @@ # Google recaptcha module

* [Validate in service (Enterprise)](#validate-in-service-enterprise)
* [Dynamic Recaptcha configuration](#dynamic-recaptcha-configuration)
* [Error handling](#error-handling)

@@ -475,2 +476,53 @@ * [Contribution](#contribution)

### Dynamic Recaptcha configuration
The `RecaptchaConfigRef` class provides a convenient way to modify Recaptcha validation parameters within your application.
This can be particularly useful in scenarios where the administration of Recaptcha is managed dynamically, such as by an administrator.
The class exposes methods that allow the customization of various Recaptcha options.
**RecaptchaConfigRef API:**
```typescript
@Injectable()
class RecaptchaConfigRef {
// Sets the secret key for Recaptcha validation.
setSecretKey(secretKey: string): this;
// Sets enterprise-specific options for Recaptcha validation
setEnterpriseOptions(options: GoogleRecaptchaEnterpriseOptions): this;
// Sets the score threshold for Recaptcha validation.
setScore(score: ScoreValidator): this;
// Sets conditions under which Recaptcha validation should be skipped.
setSkipIf(skipIf: SkipIfValue): this;
}
```
**Usage example:**
```typescript
@Injectable()
export class RecaptchaAdminService implements OnApplicationBootstrap {
constructor(private readonly recaptchaConfigRef: RecaptchaConfigRef) {
}
async onApplicationBootstrap(): Promise<void> {
// TODO: Pull recaptcha configs from your database
this.recaptchaConfigRef
.setSecretKey('SECRET_KEY_VALUE')
.setScore(0.3);
}
async updateSecretKey(secretKey: string): Promise<void> {
// TODO: Save new secret key to your database
this.recaptchaConfigRef.setSecretKey(secretKey);
}
}
```
After call `this.recaptchaConfigRef.setSecretKey(...)` - `@Recaptcha` guard and `GoogleRecaptchaValidator` will use new secret key.
### Error handling

@@ -477,0 +529,0 @@

@@ -39,2 +39,1 @@ "use strict";

exports.EnterpriseReasonTransformer = EnterpriseReasonTransformer;
//# sourceMappingURL=enterprise-reason.transformer.js.map

@@ -30,2 +30,1 @@ "use strict";

exports.RecaptchaRequestResolver = RecaptchaRequestResolver;
//# sourceMappingURL=recaptcha-request.resolver.js.map
import { AbstractGoogleRecaptchaValidator } from './validators/abstract-google-recaptcha-validator';
import { GoogleRecaptchaModuleOptions } from '../interfaces/google-recaptcha-module-options';
import { GoogleRecaptchaValidator } from './validators/google-recaptcha.validator';
import { GoogleRecaptchaEnterpriseValidator } from './validators/google-recaptcha-enterprise.validator';
import { RecaptchaConfigRef } from '../models/recaptcha-config-ref';
export declare class RecaptchaValidatorResolver {
private readonly options;
private readonly configRef;
protected readonly googleRecaptchaValidator: GoogleRecaptchaValidator;
protected readonly googleRecaptchaEnterpriseValidator: GoogleRecaptchaEnterpriseValidator;
constructor(options: GoogleRecaptchaModuleOptions, googleRecaptchaValidator: GoogleRecaptchaValidator, googleRecaptchaEnterpriseValidator: GoogleRecaptchaEnterpriseValidator);
constructor(configRef: RecaptchaConfigRef, googleRecaptchaValidator: GoogleRecaptchaValidator, googleRecaptchaEnterpriseValidator: GoogleRecaptchaEnterpriseValidator);
resolve(): AbstractGoogleRecaptchaValidator<unknown>;
}

@@ -11,14 +11,11 @@ "use strict";

};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RecaptchaValidatorResolver = void 0;
const common_1 = require("@nestjs/common");
const provider_declarations_1 = require("../provider.declarations");
const google_recaptcha_validator_1 = require("./validators/google-recaptcha.validator");
const google_recaptcha_enterprise_validator_1 = require("./validators/google-recaptcha-enterprise.validator");
const recaptcha_config_ref_1 = require("../models/recaptcha-config-ref");
let RecaptchaValidatorResolver = class RecaptchaValidatorResolver {
constructor(options, googleRecaptchaValidator, googleRecaptchaEnterpriseValidator) {
this.options = options;
constructor(configRef, googleRecaptchaValidator, googleRecaptchaEnterpriseValidator) {
this.configRef = configRef;
this.googleRecaptchaValidator = googleRecaptchaValidator;

@@ -28,6 +25,7 @@ this.googleRecaptchaEnterpriseValidator = googleRecaptchaEnterpriseValidator;

resolve() {
if (this.options.secretKey) {
const configValue = this.configRef.valueOf;
if (configValue.secretKey) {
return this.googleRecaptchaValidator;
}
if (Object.keys(this.options.enterprise || {}).length) {
if (Object.keys(configValue.enterprise || {}).length) {
return this.googleRecaptchaEnterpriseValidator;

@@ -40,7 +38,6 @@ }

(0, common_1.Injectable)(),
__param(0, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_OPTIONS)),
__metadata("design:paramtypes", [Object, google_recaptcha_validator_1.GoogleRecaptchaValidator,
__metadata("design:paramtypes", [recaptcha_config_ref_1.RecaptchaConfigRef,
google_recaptcha_validator_1.GoogleRecaptchaValidator,
google_recaptcha_enterprise_validator_1.GoogleRecaptchaEnterpriseValidator])
], RecaptchaValidatorResolver);
exports.RecaptchaValidatorResolver = RecaptchaValidatorResolver;
//# sourceMappingURL=recaptcha-validator.resolver.js.map
import { VerifyResponseOptions } from '../../interfaces/verify-response-decorator-options';
import { ScoreValidator } from '../../types';
import { GoogleRecaptchaModuleOptions } from '../../interfaces/google-recaptcha-module-options';
import { RecaptchaVerificationResult } from '../../models/recaptcha-verification-result';
import { RecaptchaConfigRef } from '../../models/recaptcha-config-ref';
export declare abstract class AbstractGoogleRecaptchaValidator<Res> {
protected readonly options: GoogleRecaptchaModuleOptions;
protected constructor(options: GoogleRecaptchaModuleOptions);
protected readonly options: RecaptchaConfigRef;
protected constructor(options: RecaptchaConfigRef);
abstract validate(options: VerifyResponseOptions): Promise<RecaptchaVerificationResult<Res>>;

@@ -9,0 +9,0 @@ protected isValidAction(action: string, options?: VerifyResponseOptions): boolean;

@@ -12,6 +12,6 @@ "use strict";

}
return this.options.actions ? this.options.actions.includes(action) : true;
return this.options.valueOf.actions ? this.options.valueOf.actions.includes(action) : true;
}
isValidScore(score, validator) {
const finalValidator = validator || this.options.score;
const finalValidator = validator || this.options.valueOf.score;
if (finalValidator) {

@@ -27,2 +27,1 @@ if (typeof finalValidator === 'function') {

exports.AbstractGoogleRecaptchaValidator = AbstractGoogleRecaptchaValidator;
//# sourceMappingURL=abstract-google-recaptcha-validator.js.map
import { Logger } from '@nestjs/common';
import { GoogleRecaptchaModuleOptions } from '../../interfaces/google-recaptcha-module-options';
import { VerifyResponseOptions } from '../../interfaces/verify-response-decorator-options';

@@ -9,2 +8,3 @@ import { AbstractGoogleRecaptchaValidator } from './abstract-google-recaptcha-validator';

import { AxiosInstance } from 'axios';
import { RecaptchaConfigRef } from '../../models/recaptcha-config-ref';
export declare class GoogleRecaptchaEnterpriseValidator extends AbstractGoogleRecaptchaValidator<VerifyResponseEnterprise> {

@@ -15,5 +15,5 @@ private readonly axios;

private readonly headers;
constructor(axios: AxiosInstance, logger: Logger, options: GoogleRecaptchaModuleOptions, enterpriseReasonTransformer: EnterpriseReasonTransformer);
constructor(axios: AxiosInstance, logger: Logger, configRef: RecaptchaConfigRef, enterpriseReasonTransformer: EnterpriseReasonTransformer);
validate(options: VerifyResponseOptions): Promise<RecaptchaVerificationResult<VerifyResponseEnterprise>>;
private verifyResponse;
}

@@ -25,5 +25,6 @@ "use strict";

const get_error_info_1 = require("../../helpers/get-error-info");
const recaptcha_config_ref_1 = require("../../models/recaptcha-config-ref");
let GoogleRecaptchaEnterpriseValidator = class GoogleRecaptchaEnterpriseValidator extends abstract_google_recaptcha_validator_1.AbstractGoogleRecaptchaValidator {
constructor(axios, logger, options, enterpriseReasonTransformer) {
super(options);
constructor(axios, logger, configRef, enterpriseReasonTransformer) {
super(configRef);
this.axios = axios;

@@ -71,7 +72,7 @@ this.logger = logger;

verifyResponse(response, expectedAction, remoteIp) {
const projectId = this.options.enterprise.projectId;
const projectId = this.options.valueOf.enterprise.projectId;
const body = {
event: {
expectedAction,
siteKey: this.options.enterprise.siteKey,
siteKey: this.options.valueOf.enterprise.siteKey,
token: response,

@@ -85,6 +86,6 @@ userIpAddress: remoteIp,

params: {
key: this.options.enterprise.apiKey,
key: this.options.valueOf.enterprise.apiKey,
},
};
if (this.options.debug) {
if (this.options.valueOf.debug) {
this.logger.debug({ body }, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptchaEnterprise}.request`);

@@ -95,3 +96,3 @@ }

.then((data) => {
if (this.options.debug) {
if (this.options.valueOf.debug) {
this.logger.debug(data, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptchaEnterprise}.response`);

@@ -102,3 +103,3 @@ }

.catch((err) => {
if (this.options.debug) {
if (this.options.valueOf.debug) {
this.logger.debug((0, get_error_info_1.getErrorInfo)(err), `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptchaEnterprise}.error`);

@@ -122,6 +123,6 @@ }

__param(1, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_LOGGER)),
__param(2, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_OPTIONS)),
__metadata("design:paramtypes", [Function, common_1.Logger, Object, enterprise_reason_transformer_1.EnterpriseReasonTransformer])
__metadata("design:paramtypes", [Function, common_1.Logger,
recaptcha_config_ref_1.RecaptchaConfigRef,
enterprise_reason_transformer_1.EnterpriseReasonTransformer])
], GoogleRecaptchaEnterpriseValidator);
exports.GoogleRecaptchaEnterpriseValidator = GoogleRecaptchaEnterpriseValidator;
//# sourceMappingURL=google-recaptcha-enterprise.validator.js.map
import { Logger } from '@nestjs/common';
import { VerifyResponseOptions } from '../../interfaces/verify-response-decorator-options';
import { VerifyResponseV3 } from '../../interfaces/verify-response';
import { GoogleRecaptchaModuleOptions } from '../../interfaces/google-recaptcha-module-options';
import { AbstractGoogleRecaptchaValidator } from './abstract-google-recaptcha-validator';
import { RecaptchaVerificationResult } from '../../models/recaptcha-verification-result';
import { AxiosInstance } from 'axios';
import { RecaptchaConfigRef } from "../../models/recaptcha-config-ref";
export declare class GoogleRecaptchaValidator extends AbstractGoogleRecaptchaValidator<VerifyResponseV3> {

@@ -13,3 +13,3 @@ private readonly axios;

private readonly headers;
constructor(axios: AxiosInstance, logger: Logger, options: GoogleRecaptchaModuleOptions);
constructor(axios: AxiosInstance, logger: Logger, configRef: RecaptchaConfigRef);
/**

@@ -16,0 +16,0 @@ * @throws GoogleRecaptchaNetworkException

@@ -26,5 +26,6 @@ "use strict";

const get_error_info_1 = require("../../helpers/get-error-info");
const recaptcha_config_ref_1 = require("../../models/recaptcha-config-ref");
let GoogleRecaptchaValidator = class GoogleRecaptchaValidator extends abstract_google_recaptcha_validator_1.AbstractGoogleRecaptchaValidator {
constructor(axios, logger, options) {
super(options);
constructor(axios, logger, configRef) {
super(configRef);
this.axios = axios;

@@ -73,8 +74,8 @@ this.logger = logger;

verifyResponse(response, remoteIp) {
const body = qs.stringify({ secret: this.options.secretKey, response, remoteip: remoteIp });
const url = this.options.network || this.defaultNetwork;
const body = qs.stringify({ secret: this.options.valueOf.secretKey, response, remoteip: remoteIp });
const url = this.options.valueOf.network || this.defaultNetwork;
const config = {
headers: this.headers,
};
if (this.options.debug) {
if (this.options.valueOf.debug) {
this.logger.debug({ body }, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptcha}.request`);

@@ -85,3 +86,3 @@ }

.then((data) => {
if (this.options.debug) {
if (this.options.valueOf.debug) {
this.logger.debug(data, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptcha}.response`);

@@ -97,3 +98,3 @@ }

.catch((err) => {
if (this.options.debug) {
if (this.options.valueOf.debug) {
this.logger.debug((0, get_error_info_1.getErrorInfo)(err), `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptcha}.error`);

@@ -119,6 +120,5 @@ }

__param(1, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_LOGGER)),
__param(2, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_OPTIONS)),
__metadata("design:paramtypes", [Function, common_1.Logger, Object])
__metadata("design:paramtypes", [Function, common_1.Logger,
recaptcha_config_ref_1.RecaptchaConfigRef])
], GoogleRecaptchaValidator);
exports.GoogleRecaptchaValidator = GoogleRecaptchaValidator;
//# sourceMappingURL=google-recaptcha.validator.js.map

@@ -5,2 +5,3 @@ import { ContextType } from '@nestjs/common';

export declare type ScoreValidator = number | ((score: number) => boolean);
export declare type SkipIfValue = boolean | (<Req = unknown>(request: Req) => boolean | Promise<boolean>);
export declare type RecaptchaContextType = ContextType | 'graphql';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc