@mondart/nestjs-common-module 2.8.1 → 2.9.0

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 (88) hide show
  1. package/dist/lib/google-recaptcha/decorators/recaptcha-result.d.ts +1 -0
  2. package/dist/lib/google-recaptcha/decorators/recaptcha-result.js +16 -0
  3. package/dist/lib/google-recaptcha/decorators/recaptcha.d.ts +2 -0
  4. package/dist/lib/google-recaptcha/decorators/recaptcha.js +9 -0
  5. package/dist/lib/google-recaptcha/decorators/set-recaptcha-options.d.ts +2 -0
  6. package/dist/lib/google-recaptcha/decorators/set-recaptcha-options.js +8 -0
  7. package/dist/lib/google-recaptcha/enums/classification-reason.d.ts +8 -0
  8. package/dist/lib/google-recaptcha/enums/classification-reason.js +12 -0
  9. package/dist/lib/google-recaptcha/enums/error-code.d.ts +16 -0
  10. package/dist/lib/google-recaptcha/enums/error-code.js +20 -0
  11. package/dist/lib/google-recaptcha/enums/google-recaptcha-context.d.ts +4 -0
  12. package/dist/lib/google-recaptcha/enums/google-recaptcha-context.js +8 -0
  13. package/dist/lib/google-recaptcha/enums/google-recaptcha-enterprise-reason.d.ts +10 -0
  14. package/dist/lib/google-recaptcha/enums/google-recaptcha-enterprise-reason.js +14 -0
  15. package/dist/lib/google-recaptcha/enums/google-recaptcha-network.d.ts +4 -0
  16. package/dist/lib/google-recaptcha/enums/google-recaptcha-network.js +8 -0
  17. package/dist/lib/google-recaptcha/exceptions/google-recaptcha-network.exception.d.ts +5 -0
  18. package/dist/lib/google-recaptcha/exceptions/google-recaptcha-network.exception.js +14 -0
  19. package/dist/lib/google-recaptcha/exceptions/google-recaptcha.exception.d.ts +8 -0
  20. package/dist/lib/google-recaptcha/exceptions/google-recaptcha.exception.js +54 -0
  21. package/dist/lib/google-recaptcha/google-recaptcha.module.d.ts +12 -0
  22. package/dist/lib/google-recaptcha/google-recaptcha.module.js +159 -0
  23. package/dist/lib/google-recaptcha/guards/google-recaptcha.guard.d.ts +15 -0
  24. package/dist/lib/google-recaptcha/guards/google-recaptcha.guard.js +89 -0
  25. package/dist/lib/google-recaptcha/helpers/get-error-info.d.ts +4 -0
  26. package/dist/lib/google-recaptcha/helpers/get-error-info.js +13 -0
  27. package/dist/lib/google-recaptcha/helpers/load-module.d.ts +2 -0
  28. package/dist/lib/google-recaptcha/helpers/load-module.js +15 -0
  29. package/dist/lib/google-recaptcha/helpers/xor.d.ts +1 -0
  30. package/dist/lib/google-recaptcha/helpers/xor.js +6 -0
  31. package/dist/lib/google-recaptcha/index.d.ts +15 -0
  32. package/dist/lib/google-recaptcha/index.js +31 -0
  33. package/dist/lib/google-recaptcha/interfaces/google-recaptcha-enterprise-options.d.ts +5 -0
  34. package/dist/lib/google-recaptcha/interfaces/google-recaptcha-enterprise-options.js +2 -0
  35. package/dist/lib/google-recaptcha/interfaces/google-recaptcha-guard-options.d.ts +7 -0
  36. package/dist/lib/google-recaptcha/interfaces/google-recaptcha-guard-options.js +2 -0
  37. package/dist/lib/google-recaptcha/interfaces/google-recaptcha-module-options.d.ts +21 -0
  38. package/dist/lib/google-recaptcha/interfaces/google-recaptcha-module-options.js +2 -0
  39. package/dist/lib/google-recaptcha/interfaces/google-recaptcha-validator-options.d.ts +12 -0
  40. package/dist/lib/google-recaptcha/interfaces/google-recaptcha-validator-options.js +2 -0
  41. package/dist/lib/google-recaptcha/interfaces/literal-object.d.ts +3 -0
  42. package/dist/lib/google-recaptcha/interfaces/literal-object.js +2 -0
  43. package/dist/lib/google-recaptcha/interfaces/verify-response-decorator-options.d.ts +13 -0
  44. package/dist/lib/google-recaptcha/interfaces/verify-response-decorator-options.js +2 -0
  45. package/dist/lib/google-recaptcha/interfaces/verify-response-enterprise.d.ts +30 -0
  46. package/dist/lib/google-recaptcha/interfaces/verify-response-enterprise.js +2 -0
  47. package/dist/lib/google-recaptcha/interfaces/verify-response.d.ts +11 -0
  48. package/dist/lib/google-recaptcha/interfaces/verify-response.js +2 -0
  49. package/dist/lib/google-recaptcha/models/recaptcha-config-ref.d.ts +12 -0
  50. package/dist/lib/google-recaptcha/models/recaptcha-config-ref.js +30 -0
  51. package/dist/lib/google-recaptcha/models/recaptcha-verification-result.d.ts +26 -0
  52. package/dist/lib/google-recaptcha/models/recaptcha-verification-result.js +34 -0
  53. package/dist/lib/google-recaptcha/provider.declarations.d.ts +4 -0
  54. package/dist/lib/google-recaptcha/provider.declarations.js +7 -0
  55. package/dist/lib/google-recaptcha/services/enterprise-reason.transformer.d.ts +5 -0
  56. package/dist/lib/google-recaptcha/services/enterprise-reason.transformer.js +38 -0
  57. package/dist/lib/google-recaptcha/services/recaptcha-request.resolver.d.ts +4 -0
  58. package/dist/lib/google-recaptcha/services/recaptcha-request.resolver.js +32 -0
  59. package/dist/lib/google-recaptcha/services/recaptcha-validator.resolver.d.ts +11 -0
  60. package/dist/lib/google-recaptcha/services/recaptcha-validator.resolver.js +40 -0
  61. package/dist/lib/google-recaptcha/services/validators/abstract-google-recaptcha-validator.d.ts +11 -0
  62. package/dist/lib/google-recaptcha/services/validators/abstract-google-recaptcha-validator.js +27 -0
  63. package/dist/lib/google-recaptcha/services/validators/google-recaptcha-enterprise.validator.d.ts +17 -0
  64. package/dist/lib/google-recaptcha/services/validators/google-recaptcha-enterprise.validator.js +126 -0
  65. package/dist/lib/google-recaptcha/services/validators/google-recaptcha.validator.d.ts +17 -0
  66. package/dist/lib/google-recaptcha/services/validators/google-recaptcha.validator.js +128 -0
  67. package/dist/lib/google-recaptcha/types.d.ts +6 -0
  68. package/dist/lib/google-recaptcha/types.js +2 -0
  69. package/dist/lib/index.d.ts +1 -1
  70. package/dist/lib/index.js +1 -1
  71. package/dist/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +1 -1
  73. package/dist/lib/captcha/captcha.decorator.d.ts +0 -4
  74. package/dist/lib/captcha/captcha.decorator.js +0 -7
  75. package/dist/lib/captcha/captcha.exception.d.ts +0 -4
  76. package/dist/lib/captcha/captcha.exception.js +0 -11
  77. package/dist/lib/captcha/captcha.guard.d.ts +0 -16
  78. package/dist/lib/captcha/captcha.guard.js +0 -86
  79. package/dist/lib/captcha/captcha.interface.d.ts +0 -26
  80. package/dist/lib/captcha/captcha.interface.js +0 -4
  81. package/dist/lib/captcha/captcha.module.d.ts +0 -8
  82. package/dist/lib/captcha/captcha.module.js +0 -97
  83. package/dist/lib/captcha/enums/captcha-decorators.enum.d.ts +0 -3
  84. package/dist/lib/captcha/enums/captcha-decorators.enum.js +0 -7
  85. package/dist/lib/captcha/enums/captcha-messages.enum.d.ts +0 -3
  86. package/dist/lib/captcha/enums/captcha-messages.enum.js +0 -7
  87. package/dist/lib/captcha/index.d.ts +0 -5
  88. package/dist/lib/captcha/index.js +0 -9
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ 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;
4
+ var recaptcha_1 = require("./decorators/recaptcha");
5
+ Object.defineProperty(exports, "Recaptcha", { enumerable: true, get: function () { return recaptcha_1.Recaptcha; } });
6
+ var set_recaptcha_options_1 = require("./decorators/set-recaptcha-options");
7
+ Object.defineProperty(exports, "SetRecaptchaOptions", { enumerable: true, get: function () { return set_recaptcha_options_1.SetRecaptchaOptions; } });
8
+ var recaptcha_result_1 = require("./decorators/recaptcha-result");
9
+ Object.defineProperty(exports, "RecaptchaResult", { enumerable: true, get: function () { return recaptcha_result_1.RecaptchaResult; } });
10
+ var google_recaptcha_guard_1 = require("./guards/google-recaptcha.guard");
11
+ Object.defineProperty(exports, "GoogleRecaptchaGuard", { enumerable: true, get: function () { return google_recaptcha_guard_1.GoogleRecaptchaGuard; } });
12
+ var google_recaptcha_module_1 = require("./google-recaptcha.module");
13
+ Object.defineProperty(exports, "GoogleRecaptchaModule", { enumerable: true, get: function () { return google_recaptcha_module_1.GoogleRecaptchaModule; } });
14
+ var error_code_1 = require("./enums/error-code");
15
+ Object.defineProperty(exports, "ErrorCode", { enumerable: true, get: function () { return error_code_1.ErrorCode; } });
16
+ var google_recaptcha_network_1 = require("./enums/google-recaptcha-network");
17
+ Object.defineProperty(exports, "GoogleRecaptchaNetwork", { enumerable: true, get: function () { return google_recaptcha_network_1.GoogleRecaptchaNetwork; } });
18
+ var google_recaptcha_exception_1 = require("./exceptions/google-recaptcha.exception");
19
+ Object.defineProperty(exports, "GoogleRecaptchaException", { enumerable: true, get: function () { return google_recaptcha_exception_1.GoogleRecaptchaException; } });
20
+ var google_recaptcha_network_exception_1 = require("./exceptions/google-recaptcha-network.exception");
21
+ Object.defineProperty(exports, "GoogleRecaptchaNetworkException", { enumerable: true, get: function () { return google_recaptcha_network_exception_1.GoogleRecaptchaNetworkException; } });
22
+ var google_recaptcha_validator_1 = require("./services/validators/google-recaptcha.validator");
23
+ Object.defineProperty(exports, "GoogleRecaptchaValidator", { enumerable: true, get: function () { return google_recaptcha_validator_1.GoogleRecaptchaValidator; } });
24
+ var google_recaptcha_enterprise_validator_1 = require("./services/validators/google-recaptcha-enterprise.validator");
25
+ Object.defineProperty(exports, "GoogleRecaptchaEnterpriseValidator", { enumerable: true, get: function () { return google_recaptcha_enterprise_validator_1.GoogleRecaptchaEnterpriseValidator; } });
26
+ var recaptcha_verification_result_1 = require("./models/recaptcha-verification-result");
27
+ Object.defineProperty(exports, "RecaptchaVerificationResult", { enumerable: true, get: function () { return recaptcha_verification_result_1.RecaptchaVerificationResult; } });
28
+ var classification_reason_1 = require("./enums/classification-reason");
29
+ Object.defineProperty(exports, "ClassificationReason", { enumerable: true, get: function () { return classification_reason_1.ClassificationReason; } });
30
+ var recaptcha_config_ref_1 = require("./models/recaptcha-config-ref");
31
+ Object.defineProperty(exports, "RecaptchaConfigRef", { enumerable: true, get: function () { return recaptcha_config_ref_1.RecaptchaConfigRef; } });
@@ -0,0 +1,5 @@
1
+ export interface GoogleRecaptchaEnterpriseOptions {
2
+ projectId: string;
3
+ siteKey: string;
4
+ apiKey: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import { RecaptchaRemoteIpProvider, RecaptchaResponseProvider, ScoreValidator, SkipIfValue } from '../types';
2
+ export interface GoogleRecaptchaGuardOptions {
3
+ response: RecaptchaResponseProvider;
4
+ remoteIp?: RecaptchaRemoteIpProvider;
5
+ skipIf?: SkipIfValue;
6
+ score?: ScoreValidator;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ import { GoogleRecaptchaGuardOptions } from './google-recaptcha-guard-options';
2
+ import { GoogleRecaptchaValidatorOptions } from './google-recaptcha-validator-options';
3
+ import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
4
+ import { Logger } from '@nestjs/common';
5
+ import { Abstract } from '@nestjs/common/interfaces/abstract.interface';
6
+ export interface GoogleRecaptchaModuleOptions extends GoogleRecaptchaValidatorOptions, GoogleRecaptchaGuardOptions {
7
+ disable?: boolean;
8
+ debug?: boolean;
9
+ logger?: Logger;
10
+ global?: boolean;
11
+ }
12
+ export interface GoogleRecaptchaOptionsFactory {
13
+ createGoogleRecaptchaOptions(): Promise<GoogleRecaptchaModuleOptions> | GoogleRecaptchaModuleOptions;
14
+ }
15
+ export interface GoogleRecaptchaModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
16
+ inject?: Array<string | symbol | Type | Abstract<any> | Function>;
17
+ useClass?: Type<GoogleRecaptchaOptionsFactory>;
18
+ useExisting?: Type<GoogleRecaptchaOptionsFactory>;
19
+ useFactory?: (...args: any[]) => Promise<Omit<GoogleRecaptchaModuleOptions, 'global'>> | Omit<GoogleRecaptchaModuleOptions, 'global'>;
20
+ global?: boolean;
21
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import { GoogleRecaptchaNetwork } from '../enums/google-recaptcha-network';
2
+ import { ScoreValidator } from '../types';
3
+ import { AxiosRequestConfig } from 'axios';
4
+ import { GoogleRecaptchaEnterpriseOptions } from './google-recaptcha-enterprise-options';
5
+ export interface GoogleRecaptchaValidatorOptions {
6
+ secretKey?: string;
7
+ actions?: string[];
8
+ score?: ScoreValidator;
9
+ network?: GoogleRecaptchaNetwork | string;
10
+ axiosConfig?: AxiosRequestConfig;
11
+ enterprise?: GoogleRecaptchaEnterpriseOptions;
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export interface LiteralObject {
2
+ [key: string]: any;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ import { RecaptchaRemoteIpProvider, RecaptchaResponseProvider, ScoreValidator } from '../types';
2
+ export interface VerifyResponseDecoratorOptions {
3
+ response?: RecaptchaResponseProvider;
4
+ remoteIp?: RecaptchaRemoteIpProvider;
5
+ score?: ScoreValidator;
6
+ action?: string;
7
+ }
8
+ export interface VerifyResponseOptions {
9
+ response: string;
10
+ remoteIp?: string;
11
+ score?: ScoreValidator;
12
+ action?: string;
13
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,30 @@
1
+ import { GoogleRecaptchaEnterpriseReason } from '../enums/google-recaptcha-enterprise-reason';
2
+ import { ClassificationReason } from '../enums/classification-reason';
3
+ export interface VerifyResponseEnterprise {
4
+ tokenProperties?: VerifyResponseEnterpriseTokenProperties;
5
+ riskAnalysis?: VerifyResponseEnterpriseRiskAnalysis;
6
+ event: VerifyTokenEnterpriseResponseEvent;
7
+ name: string;
8
+ }
9
+ export interface VerifyTokenEnterpriseEvent {
10
+ token: string;
11
+ siteKey: string;
12
+ expectedAction: string;
13
+ userIpAddress?: string;
14
+ }
15
+ export interface VerifyTokenEnterpriseResponseEvent extends VerifyTokenEnterpriseEvent {
16
+ userAgent: string;
17
+ userIpAddress: string;
18
+ hashedAccountId: string;
19
+ }
20
+ export interface VerifyResponseEnterpriseTokenProperties {
21
+ valid: boolean;
22
+ invalidReason?: GoogleRecaptchaEnterpriseReason;
23
+ hostname: string;
24
+ action: string;
25
+ createTime: string;
26
+ }
27
+ export interface VerifyResponseEnterpriseRiskAnalysis {
28
+ score: number;
29
+ reasons: ClassificationReason[];
30
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import { ErrorCode } from '../enums/error-code';
2
+ export interface VerifyResponseV2 {
3
+ success: boolean;
4
+ challenge_ts: string;
5
+ hostname: string;
6
+ errors: ErrorCode[];
7
+ }
8
+ export interface VerifyResponseV3 extends VerifyResponseV2 {
9
+ score: number;
10
+ action: string;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import { GoogleRecaptchaModuleOptions } from '../interfaces/google-recaptcha-module-options';
2
+ import { GoogleRecaptchaEnterpriseOptions } from '../interfaces/google-recaptcha-enterprise-options';
3
+ import { ScoreValidator, SkipIfValue } from '../types';
4
+ export declare class RecaptchaConfigRef {
5
+ private readonly value;
6
+ get valueOf(): GoogleRecaptchaModuleOptions;
7
+ constructor(value: GoogleRecaptchaModuleOptions);
8
+ setSecretKey(secretKey: string): this;
9
+ setEnterpriseOptions(options: GoogleRecaptchaEnterpriseOptions): this;
10
+ setScore(score: ScoreValidator): this;
11
+ setSkipIf(skipIf: SkipIfValue): this;
12
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecaptchaConfigRef = void 0;
4
+ class RecaptchaConfigRef {
5
+ get valueOf() {
6
+ return this.value;
7
+ }
8
+ constructor(value) {
9
+ this.value = value;
10
+ }
11
+ setSecretKey(secretKey) {
12
+ this.value.secretKey = secretKey;
13
+ this.value.enterprise = undefined;
14
+ return this;
15
+ }
16
+ setEnterpriseOptions(options) {
17
+ this.value.secretKey = undefined;
18
+ this.value.enterprise = options;
19
+ return this;
20
+ }
21
+ setScore(score) {
22
+ this.value.score = score;
23
+ return this;
24
+ }
25
+ setSkipIf(skipIf) {
26
+ this.value.skipIf = skipIf;
27
+ return this;
28
+ }
29
+ }
30
+ exports.RecaptchaConfigRef = RecaptchaConfigRef;
@@ -0,0 +1,26 @@
1
+ import { ErrorCode } from '../enums/error-code';
2
+ import { VerifyResponseEnterpriseRiskAnalysis } from '../interfaces/verify-response-enterprise';
3
+ import { LiteralObject } from '../interfaces/literal-object';
4
+ export interface RecaptchaVerificationResultOptions<Res> {
5
+ success: boolean;
6
+ nativeResponse: Res;
7
+ hostname: string;
8
+ action?: string;
9
+ score?: number;
10
+ remoteIp?: string;
11
+ errors: ErrorCode[];
12
+ }
13
+ export declare class RecaptchaVerificationResult<Res = LiteralObject> {
14
+ private readonly options;
15
+ readonly success: boolean;
16
+ readonly hostname: string;
17
+ readonly remoteIp: string | undefined;
18
+ readonly action: string | undefined;
19
+ readonly score: number | undefined;
20
+ readonly nativeResponse: Res;
21
+ readonly errors: ErrorCode[];
22
+ constructor(options: RecaptchaVerificationResultOptions<Res>);
23
+ toObject(): LiteralObject;
24
+ getResponse(): Res;
25
+ getEnterpriseRiskAnalytics(): VerifyResponseEnterpriseRiskAnalysis | null;
26
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecaptchaVerificationResult = void 0;
4
+ class RecaptchaVerificationResult {
5
+ constructor(options) {
6
+ this.options = options;
7
+ this.success = options.success;
8
+ this.hostname = options.hostname;
9
+ this.action = options.action;
10
+ this.remoteIp = options.remoteIp;
11
+ this.score = options.score;
12
+ this.errors = options.errors;
13
+ this.nativeResponse = options.nativeResponse;
14
+ }
15
+ toObject() {
16
+ return {
17
+ success: this.success,
18
+ hostname: this.hostname,
19
+ action: this.action,
20
+ score: this.score,
21
+ remoteIp: this.remoteIp,
22
+ errors: this.errors,
23
+ nativeResponse: this.nativeResponse,
24
+ };
25
+ }
26
+ getResponse() {
27
+ return this.nativeResponse;
28
+ }
29
+ getEnterpriseRiskAnalytics() {
30
+ const res = this.getResponse();
31
+ return res['riskAnalysis'] || null;
32
+ }
33
+ }
34
+ exports.RecaptchaVerificationResult = RecaptchaVerificationResult;
@@ -0,0 +1,4 @@
1
+ export declare const RECAPTCHA_OPTIONS: unique symbol;
2
+ export declare const RECAPTCHA_VALIDATION_OPTIONS: unique symbol;
3
+ export declare const RECAPTCHA_AXIOS_INSTANCE = "RECAPTCHA_AXIOS_INSTANCE";
4
+ export declare const RECAPTCHA_LOGGER = "RECAPTCHA_LOGGER";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RECAPTCHA_LOGGER = exports.RECAPTCHA_AXIOS_INSTANCE = exports.RECAPTCHA_VALIDATION_OPTIONS = exports.RECAPTCHA_OPTIONS = void 0;
4
+ exports.RECAPTCHA_OPTIONS = Symbol('RECAPTCHA_OPTIONS');
5
+ exports.RECAPTCHA_VALIDATION_OPTIONS = Symbol('RECAPTCHA_VALIDATION_OPTIONS');
6
+ exports.RECAPTCHA_AXIOS_INSTANCE = 'RECAPTCHA_AXIOS_INSTANCE';
7
+ exports.RECAPTCHA_LOGGER = 'RECAPTCHA_LOGGER';
@@ -0,0 +1,5 @@
1
+ import { GoogleRecaptchaEnterpriseReason } from '../enums/google-recaptcha-enterprise-reason';
2
+ import { ErrorCode } from '../enums/error-code';
3
+ export declare class EnterpriseReasonTransformer {
4
+ transform(errCode: GoogleRecaptchaEnterpriseReason): ErrorCode | null;
5
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.EnterpriseReasonTransformer = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const google_recaptcha_enterprise_reason_1 = require("../enums/google-recaptcha-enterprise-reason");
12
+ const error_code_1 = require("../enums/error-code");
13
+ let EnterpriseReasonTransformer = class EnterpriseReasonTransformer {
14
+ transform(errCode) {
15
+ switch (errCode) {
16
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.BrowserError:
17
+ return error_code_1.ErrorCode.BrowserError;
18
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.SiteMismatch:
19
+ return error_code_1.ErrorCode.SiteMismatch;
20
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.Expired:
21
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.Dupe:
22
+ return error_code_1.ErrorCode.TimeoutOrDuplicate;
23
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.UnknownInvalidReason:
24
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.Malformed:
25
+ return error_code_1.ErrorCode.InvalidInputResponse;
26
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.Missing:
27
+ return error_code_1.ErrorCode.MissingInputResponse;
28
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.InvalidReasonUnspecified:
29
+ return null;
30
+ default:
31
+ return error_code_1.ErrorCode.UnknownError;
32
+ }
33
+ }
34
+ };
35
+ exports.EnterpriseReasonTransformer = EnterpriseReasonTransformer;
36
+ exports.EnterpriseReasonTransformer = EnterpriseReasonTransformer = __decorate([
37
+ (0, common_1.Injectable)()
38
+ ], EnterpriseReasonTransformer);
@@ -0,0 +1,4 @@
1
+ import { ExecutionContext } from '@nestjs/common';
2
+ export declare class RecaptchaRequestResolver {
3
+ resolve<T>(context: ExecutionContext): T;
4
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.RecaptchaRequestResolver = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const load_module_1 = require("../helpers/load-module");
12
+ let RecaptchaRequestResolver = class RecaptchaRequestResolver {
13
+ resolve(context) {
14
+ const contextType = context.getType();
15
+ switch (contextType) {
16
+ case 'http':
17
+ return context.switchToHttp().getRequest();
18
+ case 'graphql':
19
+ return (0, load_module_1.loadModule)('@nestjs/graphql', true)
20
+ .GqlExecutionContext.create(context)
21
+ .getContext().req?.socket?._httpMessage?.req;
22
+ case 'ws':
23
+ return context.switchToWs().getClient().handshake;
24
+ default:
25
+ throw new Error(`Unsupported request type '${contextType}'.`);
26
+ }
27
+ }
28
+ };
29
+ exports.RecaptchaRequestResolver = RecaptchaRequestResolver;
30
+ exports.RecaptchaRequestResolver = RecaptchaRequestResolver = __decorate([
31
+ (0, common_1.Injectable)()
32
+ ], RecaptchaRequestResolver);
@@ -0,0 +1,11 @@
1
+ import { AbstractGoogleRecaptchaValidator } from './validators/abstract-google-recaptcha-validator';
2
+ import { GoogleRecaptchaValidator } from './validators/google-recaptcha.validator';
3
+ import { GoogleRecaptchaEnterpriseValidator } from './validators/google-recaptcha-enterprise.validator';
4
+ import { RecaptchaConfigRef } from '../models/recaptcha-config-ref';
5
+ export declare class RecaptchaValidatorResolver {
6
+ private readonly configRef;
7
+ protected readonly googleRecaptchaValidator: GoogleRecaptchaValidator;
8
+ protected readonly googleRecaptchaEnterpriseValidator: GoogleRecaptchaEnterpriseValidator;
9
+ constructor(configRef: RecaptchaConfigRef, googleRecaptchaValidator: GoogleRecaptchaValidator, googleRecaptchaEnterpriseValidator: GoogleRecaptchaEnterpriseValidator);
10
+ resolve(): AbstractGoogleRecaptchaValidator<unknown>;
11
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RecaptchaValidatorResolver = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const google_recaptcha_validator_1 = require("./validators/google-recaptcha.validator");
15
+ const google_recaptcha_enterprise_validator_1 = require("./validators/google-recaptcha-enterprise.validator");
16
+ const recaptcha_config_ref_1 = require("../models/recaptcha-config-ref");
17
+ let RecaptchaValidatorResolver = class RecaptchaValidatorResolver {
18
+ constructor(configRef, googleRecaptchaValidator, googleRecaptchaEnterpriseValidator) {
19
+ this.configRef = configRef;
20
+ this.googleRecaptchaValidator = googleRecaptchaValidator;
21
+ this.googleRecaptchaEnterpriseValidator = googleRecaptchaEnterpriseValidator;
22
+ }
23
+ resolve() {
24
+ const configValue = this.configRef.valueOf;
25
+ if (configValue.secretKey) {
26
+ return this.googleRecaptchaValidator;
27
+ }
28
+ if (Object.keys(configValue.enterprise || {}).length) {
29
+ return this.googleRecaptchaEnterpriseValidator;
30
+ }
31
+ throw new Error('Cannot resolve google recaptcha validator');
32
+ }
33
+ };
34
+ exports.RecaptchaValidatorResolver = RecaptchaValidatorResolver;
35
+ exports.RecaptchaValidatorResolver = RecaptchaValidatorResolver = __decorate([
36
+ (0, common_1.Injectable)(),
37
+ __metadata("design:paramtypes", [recaptcha_config_ref_1.RecaptchaConfigRef,
38
+ google_recaptcha_validator_1.GoogleRecaptchaValidator,
39
+ google_recaptcha_enterprise_validator_1.GoogleRecaptchaEnterpriseValidator])
40
+ ], RecaptchaValidatorResolver);
@@ -0,0 +1,11 @@
1
+ import { VerifyResponseOptions } from '../../interfaces/verify-response-decorator-options';
2
+ import { ScoreValidator } from '../../types';
3
+ import { RecaptchaVerificationResult } from '../../models/recaptcha-verification-result';
4
+ import { RecaptchaConfigRef } from '../../models/recaptcha-config-ref';
5
+ export declare abstract class AbstractGoogleRecaptchaValidator<Res> {
6
+ protected readonly options: RecaptchaConfigRef;
7
+ protected constructor(options: RecaptchaConfigRef);
8
+ abstract validate(options: VerifyResponseOptions): Promise<RecaptchaVerificationResult<Res>>;
9
+ protected isValidAction(action: string, options?: VerifyResponseOptions): boolean;
10
+ protected isValidScore(score: number, validator?: ScoreValidator): boolean;
11
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractGoogleRecaptchaValidator = void 0;
4
+ class AbstractGoogleRecaptchaValidator {
5
+ constructor(options) {
6
+ this.options = options;
7
+ }
8
+ isValidAction(action, options) {
9
+ if (options.action) {
10
+ return options.action === action;
11
+ }
12
+ return this.options.valueOf.actions
13
+ ? this.options.valueOf.actions.includes(action)
14
+ : true;
15
+ }
16
+ isValidScore(score, validator) {
17
+ const finalValidator = validator || this.options.valueOf.score;
18
+ if (finalValidator) {
19
+ if (typeof finalValidator === 'function') {
20
+ return finalValidator(score);
21
+ }
22
+ return score >= finalValidator;
23
+ }
24
+ return true;
25
+ }
26
+ }
27
+ exports.AbstractGoogleRecaptchaValidator = AbstractGoogleRecaptchaValidator;
@@ -0,0 +1,17 @@
1
+ import { Logger } from '@nestjs/common';
2
+ import { VerifyResponseOptions } from '../../interfaces/verify-response-decorator-options';
3
+ import { AbstractGoogleRecaptchaValidator } from './abstract-google-recaptcha-validator';
4
+ import { RecaptchaVerificationResult } from '../../models/recaptcha-verification-result';
5
+ import { VerifyResponseEnterprise } from '../../interfaces/verify-response-enterprise';
6
+ import { EnterpriseReasonTransformer } from '../enterprise-reason.transformer';
7
+ import { AxiosInstance } from 'axios';
8
+ import { RecaptchaConfigRef } from '../../models/recaptcha-config-ref';
9
+ export declare class GoogleRecaptchaEnterpriseValidator extends AbstractGoogleRecaptchaValidator<VerifyResponseEnterprise> {
10
+ private readonly axios;
11
+ private readonly logger;
12
+ private readonly enterpriseReasonTransformer;
13
+ private readonly headers;
14
+ constructor(axios: AxiosInstance, logger: Logger, configRef: RecaptchaConfigRef, enterpriseReasonTransformer: EnterpriseReasonTransformer);
15
+ validate(options: VerifyResponseOptions): Promise<RecaptchaVerificationResult<VerifyResponseEnterprise>>;
16
+ private verifyResponse;
17
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.GoogleRecaptchaEnterpriseValidator = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const provider_declarations_1 = require("../../provider.declarations");
18
+ const abstract_google_recaptcha_validator_1 = require("./abstract-google-recaptcha-validator");
19
+ const recaptcha_verification_result_1 = require("../../models/recaptcha-verification-result");
20
+ const error_code_1 = require("../../enums/error-code");
21
+ const google_recaptcha_network_exception_1 = require("../../exceptions/google-recaptcha-network.exception");
22
+ const google_recaptcha_context_1 = require("../../enums/google-recaptcha-context");
23
+ const enterprise_reason_transformer_1 = require("../enterprise-reason.transformer");
24
+ const get_error_info_1 = require("../../helpers/get-error-info");
25
+ const recaptcha_config_ref_1 = require("../../models/recaptcha-config-ref");
26
+ let GoogleRecaptchaEnterpriseValidator = class GoogleRecaptchaEnterpriseValidator extends abstract_google_recaptcha_validator_1.AbstractGoogleRecaptchaValidator {
27
+ constructor(axios, logger, configRef, enterpriseReasonTransformer) {
28
+ super(configRef);
29
+ this.axios = axios;
30
+ this.logger = logger;
31
+ this.enterpriseReasonTransformer = enterpriseReasonTransformer;
32
+ this.headers = { 'Content-Type': 'application/json' };
33
+ }
34
+ async validate(options) {
35
+ const [result, errorDetails] = await this.verifyResponse(options.response, options.action, options.remoteIp);
36
+ const errors = [];
37
+ let success = result?.tokenProperties?.valid || false;
38
+ if (!errorDetails) {
39
+ if (result.tokenProperties) {
40
+ if (result.tokenProperties.invalidReason) {
41
+ const invalidReasonCode = this.enterpriseReasonTransformer.transform(result.tokenProperties.invalidReason);
42
+ if (invalidReasonCode) {
43
+ errors.push(invalidReasonCode);
44
+ }
45
+ }
46
+ if (success &&
47
+ !this.isValidAction(result.tokenProperties.action, options)) {
48
+ success = false;
49
+ errors.push(error_code_1.ErrorCode.ForbiddenAction);
50
+ }
51
+ }
52
+ if (result.riskAnalysis &&
53
+ !this.isValidScore(result.riskAnalysis.score, options.score)) {
54
+ success = false;
55
+ errors.push(error_code_1.ErrorCode.LowScore);
56
+ }
57
+ }
58
+ if (!success && !errors.length) {
59
+ errorDetails
60
+ ? errors.push(error_code_1.ErrorCode.UnknownError)
61
+ : errors.push(error_code_1.ErrorCode.InvalidInputResponse);
62
+ }
63
+ return new recaptcha_verification_result_1.RecaptchaVerificationResult({
64
+ success,
65
+ errors,
66
+ nativeResponse: result,
67
+ remoteIp: options.remoteIp,
68
+ score: result?.riskAnalysis?.score,
69
+ action: result?.tokenProperties?.action,
70
+ hostname: result?.tokenProperties?.hostname || '',
71
+ });
72
+ }
73
+ verifyResponse(response, expectedAction, remoteIp) {
74
+ const projectId = this.options.valueOf.enterprise.projectId;
75
+ const body = {
76
+ event: {
77
+ expectedAction,
78
+ siteKey: this.options.valueOf.enterprise.siteKey,
79
+ token: response,
80
+ userIpAddress: remoteIp,
81
+ },
82
+ };
83
+ const url = `https://recaptchaenterprise.googleapis.com/v1/projects/${projectId}/assessments`;
84
+ const config = {
85
+ headers: this.headers,
86
+ params: {
87
+ key: this.options.valueOf.enterprise.apiKey,
88
+ },
89
+ };
90
+ if (this.options.valueOf.debug) {
91
+ this.logger.debug({ body }, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptchaEnterprise}.request`);
92
+ }
93
+ return this.axios
94
+ .post(url, body, config)
95
+ .then((res) => res.data)
96
+ .then((data) => {
97
+ if (this.options.valueOf.debug) {
98
+ this.logger.debug(data, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptchaEnterprise}.response`);
99
+ }
100
+ return [data, null];
101
+ })
102
+ .catch((err) => {
103
+ if (this.options.valueOf.debug) {
104
+ this.logger.debug((0, get_error_info_1.getErrorInfo)(err), `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptchaEnterprise}.error`);
105
+ }
106
+ const networkErrorCode = err.isAxiosError && !err.response && err.code;
107
+ if (networkErrorCode) {
108
+ throw new google_recaptcha_network_exception_1.GoogleRecaptchaNetworkException(networkErrorCode);
109
+ }
110
+ const errData = {
111
+ status: err.response.status,
112
+ data: err.response.data,
113
+ };
114
+ return [null, errData];
115
+ });
116
+ }
117
+ };
118
+ exports.GoogleRecaptchaEnterpriseValidator = GoogleRecaptchaEnterpriseValidator;
119
+ exports.GoogleRecaptchaEnterpriseValidator = GoogleRecaptchaEnterpriseValidator = __decorate([
120
+ (0, common_1.Injectable)(),
121
+ __param(0, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_AXIOS_INSTANCE)),
122
+ __param(1, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_LOGGER)),
123
+ __metadata("design:paramtypes", [Function, common_1.Logger,
124
+ recaptcha_config_ref_1.RecaptchaConfigRef,
125
+ enterprise_reason_transformer_1.EnterpriseReasonTransformer])
126
+ ], GoogleRecaptchaEnterpriseValidator);