@nestlab/google-recaptcha 2.1.2 → 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.
Files changed (35) hide show
  1. package/README.md +1 -3
  2. package/constants.d.ts +1 -0
  3. package/constants.js +5 -0
  4. package/constants.js.map +1 -0
  5. package/decorators/recaptcha-result.js +2 -2
  6. package/decorators/recaptcha-result.js.map +1 -1
  7. package/decorators/recaptcha.js +1 -1
  8. package/decorators/recaptcha.js.map +1 -1
  9. package/decorators/set-recaptcha-options.js +1 -1
  10. package/decorators/set-recaptcha-options.js.map +1 -1
  11. package/google-recaptcha.module.d.ts +1 -0
  12. package/google-recaptcha.module.js +23 -6
  13. package/google-recaptcha.module.js.map +1 -1
  14. package/guards/google-recaptcha.guard.d.ts +4 -3
  15. package/guards/google-recaptcha.guard.js +14 -8
  16. package/guards/google-recaptcha.guard.js.map +1 -1
  17. package/index.d.ts +0 -1
  18. package/index.js +1 -2
  19. package/index.js.map +1 -1
  20. package/interfaces/google-recaptcha-guard-options.d.ts +0 -5
  21. package/interfaces/google-recaptcha-module-options.d.ts +3 -0
  22. package/interfaces/google-recaptcha-validator-options.d.ts +0 -9
  23. package/package.json +19 -17
  24. package/provider.declarations.d.ts +1 -0
  25. package/provider.declarations.js +2 -1
  26. package/provider.declarations.js.map +1 -1
  27. package/services/google-recaptcha.validator.d.ts +5 -3
  28. package/services/google-recaptcha.validator.js +24 -9
  29. package/services/google-recaptcha.validator.js.map +1 -1
  30. package/services/recaptcha-request.resolver.d.ts +0 -5
  31. package/services/recaptcha-request.resolver.js +3 -19
  32. package/services/recaptcha-request.resolver.js.map +1 -1
  33. package/enums/application-type.d.ts +0 -4
  34. package/enums/application-type.js +0 -9
  35. package/enums/application-type.js.map +0 -1
package/README.md CHANGED
@@ -69,9 +69,7 @@ export class AppModule {
69
69
  | `secretKey` | **Required.**<br> Type: `string`<br> Google recaptcha secret key |
70
70
  | `response` | **Required.**<br> Type: `(request) => string`<br> Function that returns response (recaptcha token) by request |
71
71
  | `skipIf` | Optional.<br> Type: `boolean` \| `(request) => boolean \| Promise<boolean>` <br> Function that returns true if you allow the request to skip the recaptcha verification. Useful for involing other check methods (e.g. custom privileged API key) or for development or testing |
72
- | `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 |
73
- | `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>` |
74
- | `agent` | **Deprecated.** Use `axiosConfig` option <br> Optional.<br> Type: `https.Agent`<br> If you need to use an agent |
72
+ | `network` | Optional.<br> Type: `GoogleRecaptchaNetwork` \| `string`<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 |
75
73
  | `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. |
76
74
  | `actions` | Optional.<br> Type: `string[]`<br> Available action list for reCAPTCHA v3. <br> You can make this check stricter by passing the action property parameter to `@Recaptcha(...)` decorator. |
77
75
  | `axiosConfig` | Optional.<br> Type: `AxiosRequestConfig`<br> Allows to setup proxy, response timeout, https agent etc... |
package/constants.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const RECAPTCHA_LOG_CONTEXT = "GoogleRecaptcha";
package/constants.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RECAPTCHA_LOG_CONTEXT = void 0;
4
+ exports.RECAPTCHA_LOG_CONTEXT = 'GoogleRecaptcha';
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,iBAAiB,CAAC"}
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RecaptchaResult = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const load_module_1 = require("../helpers/load-module");
6
- exports.RecaptchaResult = common_1.createParamDecorator((data, context) => {
6
+ exports.RecaptchaResult = (0, common_1.createParamDecorator)((data, context) => {
7
7
  var _a, _b, _c, _d;
8
8
  switch (context.getType()) {
9
9
  case 'http':
10
10
  return context.switchToHttp().getRequest().recaptchaValidationResult;
11
11
  case 'graphql':
12
- const graphqlModule = load_module_1.loadModule('@nestjs/graphql', true);
12
+ const graphqlModule = (0, load_module_1.loadModule)('@nestjs/graphql', true);
13
13
  return (_d = (_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) === null || _d === void 0 ? void 0 : _d.recaptchaValidationResult;
14
14
  default:
15
15
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"recaptcha-result.js","sourceRoot":"","sources":["../../src/decorators/recaptcha-result.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AACxE,wDAAoD;AAEvC,QAAA,eAAe,GAAG,6BAAoB,CAAC,CAAC,IAAI,EAAE,OAAyB,EAAE,EAAE;;IACpF,QAAQ,OAAO,CAAC,OAAO,EAAsB,EAAE;QAC3C,KAAK,MAAM;YACP,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC,yBAAyB,CAAC;QACzE,KAAK,SAAS;YACV,MAAM,aAAa,GAAG,wBAAU,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;YAC1D,+BAAO,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC,GAAG,0CAAE,UAAU,0CAAE,YAAY,0CAAE,GAAG,0CAAE,yBAAyB,CAAC;QACxI;YACI,OAAO,IAAI,CAAC;KACnB;AACL,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"recaptcha-result.js","sourceRoot":"","sources":["../../src/decorators/recaptcha-result.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AACxE,wDAAoD;AAEvC,QAAA,eAAe,GAAG,IAAA,6BAAoB,EAAC,CAAC,IAAI,EAAE,OAAyB,EAAE,EAAE;;IACpF,QAAQ,OAAO,CAAC,OAAO,EAAsB,EAAE;QAC3C,KAAK,MAAM;YACP,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC,yBAAyB,CAAC;QACzE,KAAK,SAAS;YACV,MAAM,aAAa,GAAG,IAAA,wBAAU,EAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;YAC1D,OAAO,MAAA,MAAA,MAAA,MAAA,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC,GAAG,0CAAE,UAAU,0CAAE,YAAY,0CAAE,GAAG,0CAAE,yBAAyB,CAAC;QACxI;YACI,OAAO,IAAI,CAAC;KACnB;AACL,CAAC,CAAC,CAAC"}
@@ -5,7 +5,7 @@ const common_1 = require("@nestjs/common");
5
5
  const google_recaptcha_guard_1 = require("../guards/google-recaptcha.guard");
6
6
  const set_recaptcha_options_1 = require("./set-recaptcha-options");
7
7
  function Recaptcha(options) {
8
- return common_1.applyDecorators(set_recaptcha_options_1.SetRecaptchaOptions(options), common_1.UseGuards(google_recaptcha_guard_1.GoogleRecaptchaGuard));
8
+ return (0, common_1.applyDecorators)((0, set_recaptcha_options_1.SetRecaptchaOptions)(options), (0, common_1.UseGuards)(google_recaptcha_guard_1.GoogleRecaptchaGuard));
9
9
  }
10
10
  exports.Recaptcha = Recaptcha;
11
11
  //# sourceMappingURL=recaptcha.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"recaptcha.js","sourceRoot":"","sources":["../../src/decorators/recaptcha.ts"],"names":[],"mappings":";;;AAAA,2CAA4D;AAC5D,6EAAwE;AAExE,mEAA8D;AAE9D,SAAgB,SAAS,CAAC,OAAwC;IAC9D,OAAO,wBAAe,CAClB,2CAAmB,CAAC,OAAO,CAAC,EAC5B,kBAAS,CAAC,6CAAoB,CAAC,CAClC,CAAC;AACN,CAAC;AALD,8BAKC"}
1
+ {"version":3,"file":"recaptcha.js","sourceRoot":"","sources":["../../src/decorators/recaptcha.ts"],"names":[],"mappings":";;;AAAA,2CAA4D;AAC5D,6EAAwE;AAExE,mEAA8D;AAE9D,SAAgB,SAAS,CAAC,OAAwC;IAC9D,OAAO,IAAA,wBAAe,EAClB,IAAA,2CAAmB,EAAC,OAAO,CAAC,EAC5B,IAAA,kBAAS,EAAC,6CAAoB,CAAC,CAClC,CAAC;AACN,CAAC;AALD,8BAKC"}
@@ -4,7 +4,7 @@ exports.SetRecaptchaOptions = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const provider_declarations_1 = require("../provider.declarations");
6
6
  function SetRecaptchaOptions(options) {
7
- return common_1.SetMetadata(provider_declarations_1.RECAPTCHA_VALIDATION_OPTIONS, options);
7
+ return (0, common_1.SetMetadata)(provider_declarations_1.RECAPTCHA_VALIDATION_OPTIONS, options);
8
8
  }
9
9
  exports.SetRecaptchaOptions = SetRecaptchaOptions;
10
10
  //# sourceMappingURL=set-recaptcha-options.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"set-recaptcha-options.js","sourceRoot":"","sources":["../../src/decorators/set-recaptcha-options.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,oEAAwE;AAExE,SAAgB,mBAAmB,CAAC,OAAwC;IACxE,OAAO,oBAAW,CAAC,oDAA4B,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC;AAFD,kDAEC"}
1
+ {"version":3,"file":"set-recaptcha-options.js","sourceRoot":"","sources":["../../src/decorators/set-recaptcha-options.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,oEAAwE;AAExE,SAAgB,mBAAmB,CAAC,OAAwC;IACxE,OAAO,IAAA,oBAAW,EAAC,oDAA4B,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC;AAFD,kDAEC"}
@@ -1,6 +1,7 @@
1
1
  import { DynamicModule } from '@nestjs/common';
2
2
  import { GoogleRecaptchaModuleAsyncOptions, GoogleRecaptchaModuleOptions } from './interfaces/google-recaptcha-module-options';
3
3
  export declare class GoogleRecaptchaModule {
4
+ private static axiosDefaultConfig;
4
5
  static forRoot(options: GoogleRecaptchaModuleOptions): DynamicModule;
5
6
  static forRootAsync(options: GoogleRecaptchaModuleAsyncOptions): DynamicModule;
6
7
  private static resolveHttpModule;
@@ -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");
@@ -19,9 +20,11 @@ const recaptcha_request_resolver_1 = require("./services/recaptcha-request.resol
19
20
  const load_module_1 = require("./helpers/load-module");
20
21
  const core_1 = require("@nestjs/core");
21
22
  const axios = require("axios");
23
+ const https_1 = require("https");
22
24
  class GoogleRecaptchaModule {
23
25
  static forRoot(options) {
24
26
  const providers = [
27
+ core_1.Reflector,
25
28
  google_recaptcha_guard_1.GoogleRecaptchaGuard,
26
29
  google_recaptcha_validator_1.GoogleRecaptchaValidator,
27
30
  recaptcha_request_resolver_1.RecaptchaRequestResolver,
@@ -29,10 +32,13 @@ class GoogleRecaptchaModule {
29
32
  provide: provider_declarations_1.RECAPTCHA_OPTIONS,
30
33
  useValue: options,
31
34
  },
35
+ {
36
+ provide: provider_declarations_1.RECAPTCHA_LOGGER,
37
+ useFactory: () => options.logger || new common_1.Logger(),
38
+ },
32
39
  ];
33
40
  const httpModule = this.resolveHttpModule();
34
41
  const internalProviders = [
35
- core_1.Reflector,
36
42
  {
37
43
  provide: provider_declarations_1.RECAPTCHA_HTTP_SERVICE,
38
44
  useFactory: (axiosInstance) => new httpModule.HttpService(axiosInstance),
@@ -42,7 +48,7 @@ class GoogleRecaptchaModule {
42
48
  },
43
49
  {
44
50
  provide: provider_declarations_1.RECAPTCHA_AXIOS_INSTANCE,
45
- useFactory: () => axios.default.create(this.transformAxiosConfig(options.axiosConfig)),
51
+ useFactory: () => axios.default.create(this.transformAxiosConfig(Object.assign(Object.assign(Object.assign({}, this.axiosDefaultConfig), options.axiosConfig), { headers: null }))),
46
52
  },
47
53
  ];
48
54
  return {
@@ -57,6 +63,14 @@ class GoogleRecaptchaModule {
57
63
  }
58
64
  static forRootAsync(options) {
59
65
  const providers = [
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
+ },
60
74
  google_recaptcha_guard_1.GoogleRecaptchaGuard,
61
75
  google_recaptcha_validator_1.GoogleRecaptchaValidator,
62
76
  recaptcha_request_resolver_1.RecaptchaRequestResolver,
@@ -64,7 +78,6 @@ class GoogleRecaptchaModule {
64
78
  ];
65
79
  const httpModule = this.resolveHttpModule();
66
80
  const internalProviders = [
67
- core_1.Reflector,
68
81
  {
69
82
  provide: provider_declarations_1.RECAPTCHA_HTTP_SERVICE,
70
83
  useFactory: (axiosInstance) => new httpModule.HttpService(axiosInstance),
@@ -75,7 +88,7 @@ class GoogleRecaptchaModule {
75
88
  {
76
89
  provide: provider_declarations_1.RECAPTCHA_AXIOS_INSTANCE,
77
90
  useFactory: (options) => {
78
- const transformedAxiosConfig = this.transformAxiosConfig(options.axiosConfig);
91
+ const transformedAxiosConfig = this.transformAxiosConfig(Object.assign(Object.assign(Object.assign({}, this.axiosDefaultConfig), options.axiosConfig), { headers: null }));
79
92
  return axios.default.create(transformedAxiosConfig);
80
93
  },
81
94
  inject: [
@@ -96,10 +109,10 @@ class GoogleRecaptchaModule {
96
109
  }
97
110
  static resolveHttpModule() {
98
111
  try {
99
- return load_module_1.loadModule('@nestjs/axios');
112
+ return (0, load_module_1.loadModule)('@nestjs/axios');
100
113
  }
101
114
  catch (e) {
102
- return load_module_1.loadModule('@nestjs/common');
115
+ return (0, load_module_1.loadModule)('@nestjs/common');
103
116
  }
104
117
  }
105
118
  static transformAxiosConfig(axiosConfig) {
@@ -140,4 +153,8 @@ class GoogleRecaptchaModule {
140
153
  }
141
154
  }
142
155
  exports.GoogleRecaptchaModule = GoogleRecaptchaModule;
156
+ GoogleRecaptchaModule.axiosDefaultConfig = {
157
+ timeout: 60000,
158
+ httpsAgent: new https_1.Agent({ keepAlive: true }),
159
+ };
143
160
  //# sourceMappingURL=google-recaptcha.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"google-recaptcha.module.js","sourceRoot":"","sources":["../src/google-recaptcha.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,4EAAuE;AACvE,sFAAiF;AAKjF,mEAA8G;AAC9G,sFAAiF;AACjF,uDAAmD;AACnD,uCAAyC;AACzC,+BAA+B;AAE/B,MAAa,qBAAqB;IAC9B,MAAM,CAAC,OAAO,CAAC,OAAqC;QAChD,MAAM,SAAS,GAAe;YAC1B,6CAAoB;YACpB,qDAAwB;YACxB,qDAAwB;YACx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AC3C,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: GoogleRecaptchaGuardOptions);
12
+ constructor(validator: GoogleRecaptchaValidator, reflector: Reflector, requestResolver: RecaptchaRequestResolver, logger: Logger, options: GoogleRecaptchaModuleOptions);
12
13
  canActivate(context: ExecutionContext): Promise<true | never>;
13
14
  }
@@ -19,17 +19,17 @@ 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) {
30
- const request = this.options.applicationType
31
- ? this.requestResolver.resolveByApplicationType(context, this.options.applicationType)
32
- : this.requestResolver.resolve(context);
32
+ const request = this.requestResolver.resolve(context);
33
33
  const skip = typeof this.options.skipIf === 'function'
34
34
  ? await this.options.skipIf(request)
35
35
  : !!this.options.skipIf;
@@ -37,11 +37,15 @@ let GoogleRecaptchaGuard = class GoogleRecaptchaGuard {
37
37
  return true;
38
38
  }
39
39
  const options = this.reflector.get(provider_declarations_1.RECAPTCHA_VALIDATION_OPTIONS, context.getHandler());
40
- const response = (options === null || options === void 0 ? void 0 : options.response) ? await (options === null || options === void 0 ? void 0 : options.response(request))
40
+ const response = (options === null || options === void 0 ? void 0 : options.response)
41
+ ? await (options === null || options === void 0 ? void 0 : options.response(request))
41
42
  : await this.options.response(request);
42
43
  const score = (options === null || options === void 0 ? void 0 : options.score) || this.options.score;
43
44
  const action = options === null || options === void 0 ? void 0 : options.action;
44
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
+ }
45
49
  if (request.recaptchaValidationResult.success) {
46
50
  return true;
47
51
  }
@@ -49,11 +53,13 @@ let GoogleRecaptchaGuard = class GoogleRecaptchaGuard {
49
53
  }
50
54
  };
51
55
  GoogleRecaptchaGuard = __decorate([
52
- common_1.Injectable(),
53
- __param(3, common_1.Inject(provider_declarations_1.RECAPTCHA_OPTIONS)),
56
+ (0, common_1.Injectable)(),
57
+ __param(3, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_LOGGER)),
58
+ __param(4, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_OPTIONS)),
54
59
  __metadata("design:paramtypes", [google_recaptcha_validator_1.GoogleRecaptchaValidator,
55
60
  core_1.Reflector,
56
- recaptcha_request_resolver_1.RecaptchaRequestResolver, Object])
61
+ recaptcha_request_resolver_1.RecaptchaRequestResolver,
62
+ common_1.Logger, Object])
57
63
  ], GoogleRecaptchaGuard);
58
64
  exports.GoogleRecaptchaGuard = GoogleRecaptchaGuard;
59
65
  //# sourceMappingURL=google-recaptcha.guard.js.map
@@ -1 +1 @@
1
- {"version":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,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,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GoogleRecaptchaNetworkException = exports.GoogleRecaptchaException = exports.GoogleRecaptchaNetwork = exports.ErrorCode = exports.GoogleRecaptchaModule = exports.GoogleRecaptchaGuard = exports.RecaptchaResult = exports.SetRecaptchaOptions = exports.Recaptcha = void 0;
3
4
  var recaptcha_1 = require("./decorators/recaptcha");
4
5
  Object.defineProperty(exports, "Recaptcha", { enumerable: true, get: function () { return recaptcha_1.Recaptcha; } });
5
6
  var set_recaptcha_options_1 = require("./decorators/set-recaptcha-options");
@@ -12,8 +13,6 @@ var google_recaptcha_module_1 = require("./google-recaptcha.module");
12
13
  Object.defineProperty(exports, "GoogleRecaptchaModule", { enumerable: true, get: function () { return google_recaptcha_module_1.GoogleRecaptchaModule; } });
13
14
  var error_code_1 = require("./enums/error-code");
14
15
  Object.defineProperty(exports, "ErrorCode", { enumerable: true, get: function () { return error_code_1.ErrorCode; } });
15
- var application_type_1 = require("./enums/application-type");
16
- Object.defineProperty(exports, "ApplicationType", { enumerable: true, get: function () { return application_type_1.ApplicationType; } });
17
16
  var google_recaptcha_network_1 = require("./enums/google-recaptcha-network");
18
17
  Object.defineProperty(exports, "GoogleRecaptchaNetwork", { enumerable: true, get: function () { return google_recaptcha_network_1.GoogleRecaptchaNetwork; } });
19
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,6DAA2D;AAAlD,mHAAA,eAAe,OAAA;AACxB,6EAAyE;AAAhE,kIAAA,sBAAsB,OAAA;AAC/B,sFAAmF;AAA1E,sIAAA,wBAAwB,OAAA;AACjC,sGAAkG;AAAzF,qJAAA,+BAA+B,OAAA"}
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,11 +1,6 @@
1
1
  import { RecaptchaResponseProvider, ScoreValidator } from '../types';
2
- import { ApplicationType } from '../enums/application-type';
3
2
  export interface GoogleRecaptchaGuardOptions {
4
3
  response: RecaptchaResponseProvider;
5
- /**
6
- * @deprecated
7
- */
8
- applicationType?: ApplicationType;
9
4
  skipIf?: boolean | ((request: any) => boolean | Promise<boolean>);
10
5
  score?: ScoreValidator;
11
6
  }
@@ -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;
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- import * as https from 'https';
3
1
  import { GoogleRecaptchaNetwork } from '../enums/google-recaptcha-network';
4
2
  import { ScoreValidator } from '../types';
5
3
  import { AxiosRequestConfig } from 'axios';
@@ -14,12 +12,5 @@ export interface GoogleRecaptchaValidatorOptions {
14
12
  * or set any api url
15
13
  */
16
14
  network?: GoogleRecaptchaNetwork | string;
17
- /**
18
- * @deprecated
19
- * Use axiosConfig for setup agent.
20
- * If your server has trouble connecting to https://www.google.com,
21
- * you can use an agent (`proxy-agent` or other NPM modules)
22
- */
23
- agent?: https.Agent;
24
15
  axiosConfig?: AxiosRequestConfig;
25
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestlab/google-recaptcha",
3
- "version": "2.1.2",
3
+ "version": "3.0.2",
4
4
  "description": "Google recaptcha module for NestJS.",
5
5
  "keywords": [
6
6
  "nest",
@@ -33,25 +33,27 @@
33
33
  },
34
34
  "homepage": "https://github.com/chvarkov/google-recaptcha",
35
35
  "peerDependencies": {
36
- "@nestjs/core": ">=6.0.0 <9.0.0",
37
- "@nestjs/common": ">=6.0.0 <9.0.0"
36
+ "@nestjs/axios": ">=0.0.1 <1.0.0",
37
+ "@nestjs/common": ">=8.0.0 <10.0.0",
38
+ "@nestjs/core": ">=8.0.0 <10.0.0"
38
39
  },
39
40
  "devDependencies": {
40
- "@nestjs/common": "^6.0.0",
41
- "@nestjs/core": "^6.0.0",
42
- "@nestjs/graphql": "^7.9.8",
43
- "@nestjs/platform-express": "^6.11.11",
44
- "@nestjs/testing": "^6.11.11",
45
- "@types/express": "^4.17.11",
46
- "@types/jest": "^24.9.1",
47
- "@types/node": "^12.12.14",
48
- "jest": "^24.9.0",
41
+ "@nestjs/axios": "^0.1.0",
42
+ "@nestjs/common": "^9.0.5",
43
+ "@nestjs/core": "^9.0.5",
44
+ "@nestjs/graphql": "^10.0.21",
45
+ "@nestjs/platform-express": "^9.0.5",
46
+ "@nestjs/testing": "^9.0.5",
47
+ "@types/express": "^4.17.13",
48
+ "@types/jest": "^28.1.6",
49
+ "@types/node": "^18.0.6",
50
+ "jest": "^28.1.3",
49
51
  "reflect-metadata": "^0.1.13",
50
- "rxjs": "^6.5.4",
51
- "ts-jest": "^24.2.0",
52
- "ts-loader": "^8.0.0",
53
- "ts-node": "^8.5.2",
54
- "typescript": "^3.7.2"
52
+ "rxjs": "^7.5.6",
53
+ "ts-jest": "^28.0.7",
54
+ "ts-loader": "^9.3.1",
55
+ "ts-node": "^10.9.1",
56
+ "typescript": "^4.7.4"
55
57
  },
56
58
  "jest": {
57
59
  "moduleFileExtensions": [
@@ -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";
@@ -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 { HttpService } from '@nestjs/common';
2
- import { GoogleRecaptchaValidatorOptions } from '../interfaces/google-recaptcha-validator-options';
1
+ import { Logger } from '@nestjs/common';
3
2
  import { GoogleRecaptchaValidationResult } from '../interfaces/google-recaptcha-validation-result';
4
3
  import { VerifyResponseOptions } from '../interfaces/verify-response-decorator-options';
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: GoogleRecaptchaValidatorOptions);
12
+ constructor(http: HttpService, logger: Logger, options: GoogleRecaptchaModuleOptions);
11
13
  /**
12
14
  * @throws GoogleRecaptchaNetworkException
13
15
  * @param {VerifyResponseOptions} options
@@ -19,9 +19,12 @@ const qs = require("querystring");
19
19
  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
+ const axios_1 = require("@nestjs/axios");
23
+ const constants_1 = require("../constants");
22
24
  let GoogleRecaptchaValidator = class GoogleRecaptchaValidator {
23
- constructor(http, options) {
25
+ constructor(http, logger, options) {
24
26
  this.http = http;
27
+ this.logger = logger;
25
28
  this.options = options;
26
29
  this.defaultNetwork = google_recaptcha_network_1.GoogleRecaptchaNetwork.Google;
27
30
  this.headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
@@ -46,23 +49,33 @@ let GoogleRecaptchaValidator = class GoogleRecaptchaValidator {
46
49
  return result;
47
50
  }
48
51
  verifyResponse(response) {
49
- const data = qs.stringify({ secret: this.options.secretKey, response });
52
+ const body = qs.stringify({ secret: this.options.secretKey, response });
50
53
  const url = this.options.network || this.defaultNetwork;
51
54
  const config = {
52
55
  headers: this.headers,
53
56
  };
54
- if (this.options.agent) {
55
- config.httpsAgent = this.options.agent;
57
+ if (this.options.debug) {
58
+ this.logger.debug({ body }, `${constants_1.RECAPTCHA_LOG_CONTEXT}.request`);
56
59
  }
57
- return this.http.post(url, data, config)
60
+ return this.http.post(url, body, config)
58
61
  .toPromise()
59
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
+ })
60
69
  .then(result => (Object.assign(Object.assign({}, result), { errors: result['error-codes'] || [] })))
61
70
  .then(result => {
62
71
  delete result['error-codes'];
63
72
  return result;
64
73
  })
65
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
+ }
66
79
  const networkErrorCode = err.isAxiosError && err.code;
67
80
  if (networkErrorCode) {
68
81
  throw new google_recaptcha_network_exception_1.GoogleRecaptchaNetworkException(networkErrorCode);
@@ -97,10 +110,12 @@ let GoogleRecaptchaValidator = class GoogleRecaptchaValidator {
97
110
  }
98
111
  };
99
112
  GoogleRecaptchaValidator = __decorate([
100
- common_1.Injectable(),
101
- __param(0, common_1.Inject(provider_declarations_1.RECAPTCHA_HTTP_SERVICE)),
102
- __param(1, common_1.Inject(provider_declarations_1.RECAPTCHA_OPTIONS)),
103
- __metadata("design:paramtypes", [common_1.HttpService, Object])
113
+ (0, common_1.Injectable)(),
114
+ __param(0, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_HTTP_SERVICE)),
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])
104
119
  ], GoogleRecaptchaValidator);
105
120
  exports.GoogleRecaptchaValidator = GoogleRecaptchaValidator;
106
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,2CAAiE;AAEjE,oEAAqF;AACrF,kCAAkC;AAGlC,gFAA2E;AAI3E,oDAAgD;AAChD,yGAAmG;AAGnG,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;IAIjC,YAA6D,IAAiB,EACtB,OAAwC;QADnC,SAAI,GAAJ,IAAI,CAAa;QACtB,YAAO,GAAP,OAAO,CAAiC;QAJ/E,mBAAc,GAAG,iDAAsB,CAAC,MAAM,CAAC;QAC/C,YAAO,GAAG,EAAC,cAAc,EAAE,mCAAmC,EAAC,CAAC;IAIjF,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ,CAAC,OAA8B;QACzC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAmB,OAAO,CAAC,QAAQ,CAAC,CAAC;QAE7E,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YAC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YAChB,IAAI,OAAO,cAAc,KAAK,UAAU,EAAE;gBACtC,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;aAChC;YAED,OAAO,KAAK,IAAI,cAAc,CAAC;SAClC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAEO,OAAO,CAAC,CAAmB;QAC/B,OAAO,CAAC,OAAO,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC;YACnD,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 +1,4 @@
1
1
  import { ExecutionContext } from '@nestjs/common';
2
- import { ApplicationType } from '../enums/application-type';
3
2
  export declare class RecaptchaRequestResolver {
4
3
  resolve<T = any>(context: ExecutionContext): T;
5
- /**
6
- * @deprecated
7
- */
8
- resolveByApplicationType<T = any>(context: ExecutionContext, type: ApplicationType): T;
9
4
  }
@@ -8,7 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.RecaptchaRequestResolver = void 0;
10
10
  const common_1 = require("@nestjs/common");
11
- const application_type_1 = require("../enums/application-type");
12
11
  const load_module_1 = require("../helpers/load-module");
13
12
  let RecaptchaRequestResolver = class RecaptchaRequestResolver {
14
13
  resolve(context) {
@@ -18,30 +17,15 @@ let RecaptchaRequestResolver = class RecaptchaRequestResolver {
18
17
  case 'http':
19
18
  return context.switchToHttp().getRequest();
20
19
  case 'graphql':
21
- const graphqlModule = load_module_1.loadModule('@nestjs/graphql', true);
22
- 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;
20
+ const graphqlModule = (0, load_module_1.loadModule)('@nestjs/graphql', true);
21
+ return (_c = (_b = (_a = graphqlModule.GqlExecutionContext.create(context).getContext().req) === null || _a === void 0 ? void 0 : _a.socket) === null || _b === void 0 ? void 0 : _b._httpMessage) === null || _c === void 0 ? void 0 : _c.req;
23
22
  default:
24
23
  throw new Error(`Unsupported request type '${contextType}'.`);
25
24
  }
26
25
  }
27
- /**
28
- * @deprecated
29
- */
30
- resolveByApplicationType(context, type) {
31
- var _a, _b, _c;
32
- switch (type) {
33
- case application_type_1.ApplicationType.Rest:
34
- return context.switchToHttp().getRequest();
35
- case application_type_1.ApplicationType.GraphQL:
36
- const graphqlModule = load_module_1.loadModule('@nestjs/graphql', true);
37
- 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;
38
- default:
39
- throw new Error(`Unsupported request type '${type}'.`);
40
- }
41
- }
42
26
  };
43
27
  RecaptchaRequestResolver = __decorate([
44
- common_1.Injectable()
28
+ (0, common_1.Injectable)()
45
29
  ], RecaptchaRequestResolver);
46
30
  exports.RecaptchaRequestResolver = RecaptchaRequestResolver;
47
31
  //# sourceMappingURL=recaptcha-request.resolver.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"recaptcha-request.resolver.js","sourceRoot":"","sources":["../../src/services/recaptcha-request.resolver.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA8D;AAC9D,gEAA4D;AAC5D,wDAAoD;AAIpD,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;IACjC,OAAO,C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GAArC,MAAa,wBAAwB;IACjC,OAAO,CAAU,OAAyB;;QACtC,MAAM,WAAW,GAAyB,OAAO,CAAC,OAAO,EAAE,CAAC;QAE5D,QAAQ,WAAW,EAAE;YACjB,KAAK,MAAM;gBACP,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;YAE/C,KAAK,SAAS;gBACV,MAAM,aAAa,GAAG,IAAA,wBAAU,EAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;gBAC1D,OAAO,MAAA,MAAA,MAAA,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC,GAAG,0CAAE,MAAM,0CAAE,YAAY,0CAAE,GAAG,CAAC;YACzG;gBACI,MAAM,IAAI,KAAK,CAAC,6BAA6B,WAAW,IAAI,CAAC,CAAC;SACrE;IACL,CAAC;CACJ,CAAA;AAfY,wBAAwB;IADpC,IAAA,mBAAU,GAAE;GACA,wBAAwB,CAepC;AAfY,4DAAwB"}
@@ -1,4 +0,0 @@
1
- export declare enum ApplicationType {
2
- Rest = "REST",
3
- GraphQL = "GRAPH_QL"
4
- }
@@ -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"}