1
1
import { Inject , Injectable , Logger } from '@nestjs/common' ;
2
- import { RECAPTCHA_AXIOS_INSTANCE , RECAPTCHA_LOGGER , RECAPTCHA_OPTIONS } from '../../provider.declarations' ;
3
- import { GoogleRecaptchaModuleOptions } from '../../interfaces/google-recaptcha-module-options' ;
2
+ import { RECAPTCHA_AXIOS_INSTANCE , RECAPTCHA_LOGGER } from '../../provider.declarations' ;
4
3
import { VerifyResponseOptions } from '../../interfaces/verify-response-decorator-options' ;
5
4
import { AbstractGoogleRecaptchaValidator } from './abstract-google-recaptcha-validator' ;
6
5
import { RecaptchaVerificationResult } from '../../models/recaptcha-verification-result' ;
@@ -13,6 +12,7 @@ import { EnterpriseReasonTransformer } from '../enterprise-reason.transformer';
13
12
import { getErrorInfo } from '../../helpers/get-error-info' ;
14
13
import { AxiosInstance } from 'axios' ;
15
14
import { LiteralObject } from '../../interfaces/literal-object' ;
15
+ import { RecaptchaConfigRef } from '../../models/recaptcha-config-ref' ;
16
16
17
17
type VerifyResponse = [ VerifyResponseEnterprise , LiteralObject ] ;
18
18
@@ -23,10 +23,10 @@ export class GoogleRecaptchaEnterpriseValidator extends AbstractGoogleRecaptchaV
23
23
constructor (
24
24
@Inject ( RECAPTCHA_AXIOS_INSTANCE ) private readonly axios : AxiosInstance ,
25
25
@Inject ( RECAPTCHA_LOGGER ) private readonly logger : Logger ,
26
- @ Inject ( RECAPTCHA_OPTIONS ) options : GoogleRecaptchaModuleOptions ,
26
+ configRef : RecaptchaConfigRef ,
27
27
private readonly enterpriseReasonTransformer : EnterpriseReasonTransformer
28
28
) {
29
- super ( options ) ;
29
+ super ( configRef ) ;
30
30
}
31
31
32
32
async validate ( options : VerifyResponseOptions ) : Promise < RecaptchaVerificationResult < VerifyResponseEnterprise > > {
@@ -73,11 +73,11 @@ export class GoogleRecaptchaEnterpriseValidator extends AbstractGoogleRecaptchaV
73
73
}
74
74
75
75
private verifyResponse ( response : string , expectedAction : string , remoteIp : string ) : Promise < VerifyResponse > {
76
- const projectId = this . options . enterprise . projectId ;
76
+ const projectId = this . options . valueOf . enterprise . projectId ;
77
77
const body : { event : VerifyTokenEnterpriseEvent } = {
78
78
event : {
79
79
expectedAction,
80
- siteKey : this . options . enterprise . siteKey ,
80
+ siteKey : this . options . valueOf . enterprise . siteKey ,
81
81
token : response ,
82
82
userIpAddress : remoteIp ,
83
83
} ,
@@ -88,25 +88,25 @@ export class GoogleRecaptchaEnterpriseValidator extends AbstractGoogleRecaptchaV
88
88
const config : axios . AxiosRequestConfig = {
89
89
headers : this . headers ,
90
90
params : {
91
- key : this . options . enterprise . apiKey ,
91
+ key : this . options . valueOf . enterprise . apiKey ,
92
92
} ,
93
93
} ;
94
94
95
- if ( this . options . debug ) {
95
+ if ( this . options . valueOf . debug ) {
96
96
this . logger . debug ( { body } , `${ GoogleRecaptchaContext . GoogleRecaptchaEnterprise } .request` ) ;
97
97
}
98
98
99
99
return this . axios . post < VerifyResponseEnterprise > ( url , body , config )
100
100
. then ( ( res ) => res . data )
101
101
. then ( ( data ) : VerifyResponse => {
102
- if ( this . options . debug ) {
102
+ if ( this . options . valueOf . debug ) {
103
103
this . logger . debug ( data , `${ GoogleRecaptchaContext . GoogleRecaptchaEnterprise } .response` ) ;
104
104
}
105
105
106
106
return [ data , null ] ;
107
107
} )
108
108
. catch ( ( err : axios . AxiosError ) : VerifyResponse => {
109
- if ( this . options . debug ) {
109
+ if ( this . options . valueOf . debug ) {
110
110
this . logger . debug ( getErrorInfo ( err ) , `${ GoogleRecaptchaContext . GoogleRecaptchaEnterprise } .error` ) ;
111
111
}
112
112
0 commit comments