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 2.0.8 to 2.1.0

19

google-recaptcha.module.js
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __rest = (this && this.__rest) || function (s, e) {

@@ -19,6 +13,4 @@ var t = {};

};
var GoogleRecaptchaModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GoogleRecaptchaModule = void 0;
const common_1 = require("@nestjs/common");
const google_recaptcha_guard_1 = require("./guards/google-recaptcha.guard");

@@ -31,3 +23,3 @@ const google_recaptcha_validator_1 = require("./services/google-recaptcha.validator");

const axios = require("axios");
let GoogleRecaptchaModule = GoogleRecaptchaModule_1 = class GoogleRecaptchaModule {
class GoogleRecaptchaModule {
static forRoot(options) {

@@ -60,3 +52,3 @@ const providers = [

global: true,
module: GoogleRecaptchaModule_1,
module: GoogleRecaptchaModule,
imports: [

@@ -99,3 +91,3 @@ httpModule.HttpModule,

global: true,
module: GoogleRecaptchaModule_1,
module: GoogleRecaptchaModule,
imports: [

@@ -153,7 +145,4 @@ ...options.imports || [],

}
};
GoogleRecaptchaModule = GoogleRecaptchaModule_1 = __decorate([
common_1.Module({})
], GoogleRecaptchaModule);
}
exports.GoogleRecaptchaModule = GoogleRecaptchaModule;
//# sourceMappingURL=google-recaptcha.module.js.map

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

const recaptcha_request_resolver_1 = require("../services/recaptcha-request.resolver");
const application_type_1 = require("../enums/application-type");
let GoogleRecaptchaGuard = class GoogleRecaptchaGuard {

@@ -32,3 +31,5 @@ constructor(validator, reflector, requestResolver, options) {

async canActivate(context) {
const request = this.requestResolver.resolve(context, this.options.applicationType || application_type_1.ApplicationType.Rest);
const request = this.options.applicationType
? this.requestResolver.resolveByApplicationType(context, this.options.applicationType)
: this.requestResolver.resolve(context);
const skip = typeof this.options.skipIf === 'function'

@@ -35,0 +36,0 @@ ? await this.options.skipIf(request)

@@ -5,2 +5,5 @@ import { RecaptchaResponseProvider, ScoreValidator } from '../types';

response: RecaptchaResponseProvider;
/**
* @deprecated
*/
applicationType?: ApplicationType;

@@ -7,0 +10,0 @@ skipIf?: boolean | ((request: any) => boolean | Promise<boolean>);

@@ -10,5 +10,17 @@ /// <reference types="node" />

score?: ScoreValidator;
/**
* If your server has trouble connecting to https://google.com then you can set networks:
* GoogleRecaptchaNetwork.Google = 'https://www.google.com/recaptcha/api/siteverify'
* GoogleRecaptchaNetwork.Recaptcha = 'https://recaptcha.net/recaptcha/api/siteverify'
* or set any api url
*/
network?: GoogleRecaptchaNetwork | string;
/**
* @deprecated
* Use axiosConfig for setup agent.
* If your server has trouble connecting to https://www.google.com,
* you can use an agent (`proxy-agent` or other NPM modules)
*/
agent?: https.Agent;
axiosConfig?: AxiosRequestConfig;
}
{
"name": "@nestlab/google-recaptcha",
"version": "2.0.8",
"version": "2.1.0",
"description": "Google recaptcha module for NestJS.",

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

@@ -5,2 +5,4 @@ # Google recaptcha module

Supported for HTTP and GraphQL nestJS applications
- [Installation](#installation)

@@ -23,7 +25,2 @@ - [Configuration](#configuration)

For using application type GraphQL `ApplicationType.GraphQL` you need to install `@nestjs/graphql`.
```
$ npm i @nestjs/graphql
```
## Configuration

@@ -41,3 +38,2 @@

network: GoogleRecaptchaNetwork.Recaptcha,
agent: null
})

@@ -59,3 +55,2 @@ ],

skipIf: process.env.NODE_ENV !== 'production',
agent: null,
actions: ['SignUp', 'SignIn'],

@@ -70,22 +65,2 @@ score: 0.8,

**Configuration for GraphQL application**
```typescript
@Module({
imports: [
GoogleRecaptchaModule.forRoot({
secretKey: process.env.GOOGLE_RECAPTCHA_SECRET_KEY,
response: (req: IncomingMessage) => (req.headers.recaptcha || '').toString(),
skipIf: process.env.NODE_ENV !== 'production',
network: GoogleRecaptchaNetwork.Recaptcha,
applicationType: ApplicationType.GraphQL,
agent: null
})
],
})
export class AppModule {
}
```
**Tip: header names transforming to lower case.**

@@ -103,3 +78,3 @@

| `network` | Optional.<br> Type: `GoogleRecaptchaNetwork` \| `boolean`<br> Default: `GoogleRecaptchaNetwork.Google` <br> If your server has trouble connecting to https://google.com then you can set networks:<br> `GoogleRecaptchaNetwork.Google` = 'https://www.google.com/recaptcha/api/siteverify'<br>`GoogleRecaptchaNetwork.Recaptcha` = 'https://recaptcha.net/recaptcha/api/siteverify'<br> or set any api url |
| `applicationType` | Optional.<br> Type: `ApplicationType` <br> Default: `ApplicationType.Rest` <br> Application type affect on type of request argument on `response` provider function <br> Request types:<br> `ApplicationType.Rest` - `(req: express.Request \| fastify.Request) => string \| Promise<string>` <br> `ApplicationType.GraphQL` - `(req: http.IncommingMessage) => string \| Promise<string>` |
| `applicationType` | **Deprecated.** Module detects it automatically from execution context. Optional.<br> Type: `ApplicationType` <br> Application type affect on type of request argument on `response` provider function <br> Context types:<br> `http` - `(req: express.Request \| fastify.Request) => string \| Promise<string>` <br> `graphql` - `(req: http.IncommingMessage) => string \| Promise<string>` |
| `agent` | **Deprecated.** Use `axiosConfig` option <br> Optional.<br> Type: `https.Agent`<br> If you need to use an agent |

@@ -106,0 +81,0 @@ | `score` | Optional.<br> Type: `number` \| `(score: number) => boolean`<br> Score validator for reCAPTCHA v3. <br> `number` - minimum available score. <br> `(score: number) => boolean` - function with custom validation rules. |

@@ -11,2 +11,6 @@ import { HttpService } from '@nestjs/common';

constructor(http: HttpService, options: GoogleRecaptchaValidatorOptions);
/**
* @throws GoogleRecaptchaNetworkException
* @param {VerifyResponseOptions} options
*/
validate(options: VerifyResponseOptions): Promise<GoogleRecaptchaValidationResult>;

@@ -13,0 +17,0 @@ private verifyResponse;

@@ -29,2 +29,6 @@ "use strict";

}
/**
* @throws GoogleRecaptchaNetworkException
* @param {VerifyResponseOptions} options
*/
async validate(options) {

@@ -31,0 +35,0 @@ const result = await this.verifyResponse(options.response);

import { ExecutionContext } from '@nestjs/common';
import { ApplicationType } from '../enums/application-type';
export declare class RecaptchaRequestResolver {
resolve<T = any>(context: ExecutionContext, type: ApplicationType): T;
resolve<T = any>(context: ExecutionContext): T;
/**
* @deprecated
*/
resolveByApplicationType<T = any>(context: ExecutionContext, type: ApplicationType): T;
}

@@ -14,4 +14,20 @@ "use strict";

let RecaptchaRequestResolver = class RecaptchaRequestResolver {
resolve(context, type) {
resolve(context) {
var _a, _b, _c;
const contextType = context.getType();
switch (contextType) {
case 'http':
return context.switchToHttp().getRequest();
case 'graphql':
const graphqlModule = load_module_1.loadModule('@nestjs/graphql', true);
return (_c = (_b = (_a = graphqlModule.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;
default:
throw new Error(`Unsupported request type '${contextType}'.`);
}
}
/**
* @deprecated
*/
resolveByApplicationType(context, type) {
var _a, _b, _c;
switch (type) {

@@ -18,0 +34,0 @@ case application_type_1.ApplicationType.Rest:

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

import { ContextType } from '@nestjs/common';
export declare type RecaptchaResponseProvider = (req: any) => string | Promise<string>;
export declare type ScoreValidator = number | ((score: number) => boolean);
export declare type RecaptchaContextType = ContextType | 'graphql';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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