@nestlab/google-recaptcha
Advanced tools
Comparing version 1.1.2 to 1.1.3
import { DynamicModule } from '@nestjs/common'; | ||
import { GoogleRecaptchaModuleOptions } from './interfaces/google-recaptcha-module-options'; | ||
import { GoogleRecaptchaModuleAsyncOptions, GoogleRecaptchaModuleOptions } from './interfaces/google-recaptcha-module-options'; | ||
export declare class GoogleRecaptchaModule { | ||
static forRoot(options: GoogleRecaptchaModuleOptions): DynamicModule; | ||
static forRootAsync(options: GoogleRecaptchaModuleAsyncOptions): DynamicModule; | ||
private static createAsyncProviders; | ||
private static createAsyncOptionsProvider; | ||
private static isGoogleRecaptchaFactory; | ||
} |
@@ -28,8 +28,56 @@ "use strict"; | ||
imports: [ | ||
common_1.HttpModule | ||
], | ||
providers: providers, | ||
exports: providers, | ||
}; | ||
} | ||
static forRootAsync(options) { | ||
const providers = [ | ||
google_recaptcha_guard_1.GoogleRecaptchaGuard, | ||
google_recaptcha_validator_1.GoogleRecaptchaValidator, | ||
...this.createAsyncProviders(options) | ||
]; | ||
return { | ||
module: GoogleRecaptchaModule_1, | ||
imports: [ | ||
common_1.HttpModule, | ||
...options.imports || [] | ||
], | ||
providers, | ||
providers: providers, | ||
exports: providers, | ||
}; | ||
} | ||
static createAsyncProviders(options) { | ||
const providers = [this.createAsyncOptionsProvider(options)]; | ||
if (options.useClass) { | ||
providers.push({ | ||
provide: options.useClass, | ||
useClass: options.useClass, | ||
}); | ||
} | ||
return providers; | ||
} | ||
static createAsyncOptionsProvider(options) { | ||
if (options.useFactory) { | ||
return { | ||
provide: provider_declarations_1.RECAPTCHA_OPTIONS, | ||
useFactory: options.useFactory, | ||
inject: options.inject || [], | ||
}; | ||
} | ||
return { | ||
provide: provider_declarations_1.RECAPTCHA_OPTIONS, | ||
useFactory: (optionsFactory) => { | ||
if (!this.isGoogleRecaptchaFactory(optionsFactory)) { | ||
throw new Error('Factory must be implement \'GoogleRecaptchaOptionsFactory\' interface.'); | ||
} | ||
return optionsFactory.createGoogleRecaptchaOptions(); | ||
}, | ||
inject: [options.useExisting || options.useClass], | ||
}; | ||
} | ||
static isGoogleRecaptchaFactory(object) { | ||
return !!object && typeof object.createGoogleRecaptchaOptions === 'function'; | ||
} | ||
}; | ||
@@ -36,0 +84,0 @@ GoogleRecaptchaModule = GoogleRecaptchaModule_1 = __decorate([ |
import { GoogleRecaptchaGuardOptions } from './google-recaptcha-guard-options'; | ||
import { GoogleRecaptchaValidatorOptions } from './google-recaptcha-validator-options'; | ||
import { ModuleMetadata, Type } from '@nestjs/common/interfaces'; | ||
export interface GoogleRecaptchaModuleOptions extends GoogleRecaptchaValidatorOptions, GoogleRecaptchaGuardOptions { | ||
} | ||
export interface GoogleRecaptchaOptionsFactory { | ||
createGoogleRecaptchaOptions(): Promise<GoogleRecaptchaModuleOptions> | GoogleRecaptchaModuleOptions; | ||
} | ||
export interface GoogleRecaptchaModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> { | ||
inject?: any[]; | ||
useClass?: Type<GoogleRecaptchaOptionsFactory>; | ||
useExisting?: Type<GoogleRecaptchaOptionsFactory>; | ||
useFactory?: (...args: any[]) => Promise<GoogleRecaptchaModuleOptions> | GoogleRecaptchaModuleOptions; | ||
} |
{ | ||
"name": "@nestlab/google-recaptcha", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Google recaptcha module for NestJS.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -35,2 +35,18 @@ # Google recaptcha module | ||
If you want import configs from your [ConfigService](https://docs.nestjs.com/techniques/configuration#getting-started) via [custom getter function](https://docs.nestjs.com/techniques/configuration#custom-getter-functions) that will return `GoogleRecaptchaModuleOptions` object. | ||
```typescript | ||
@Module({ | ||
imports: [ | ||
GoogleRecaptchaModule.forRootAsync({ | ||
imports: [ConfigModule], | ||
useFactory: (configService: ConfigService) => configService.googleRecaptchaOptions, | ||
inject: [ConfigService], | ||
}) | ||
], | ||
}) | ||
export class AppModule { | ||
} | ||
``` | ||
### Usage <a name="Usage"></a> | ||
@@ -37,0 +53,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30307
355
136