@nestlab/google-recaptcha 3.0.1 → 3.1.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 (64) hide show
  1. package/README.md +62 -2
  2. package/enums/classification-reason.d.ts +8 -0
  3. package/enums/classification-reason.js +13 -0
  4. package/enums/classification-reason.js.map +1 -0
  5. package/enums/error-code.d.ts +3 -1
  6. package/enums/error-code.js +3 -0
  7. package/enums/error-code.js.map +1 -1
  8. package/enums/google-recaptcha-context.d.ts +4 -0
  9. package/enums/google-recaptcha-context.js +9 -0
  10. package/enums/google-recaptcha-context.js.map +1 -0
  11. package/enums/google-recaptcha-enterprise-reason.d.ts +10 -0
  12. package/enums/google-recaptcha-enterprise-reason.js +15 -0
  13. package/enums/google-recaptcha-enterprise-reason.js.map +1 -0
  14. package/exceptions/google-recaptcha.exception.js +4 -0
  15. package/exceptions/google-recaptcha.exception.js.map +1 -1
  16. package/google-recaptcha.module.d.ts +1 -0
  17. package/google-recaptcha.module.js +31 -1
  18. package/google-recaptcha.module.js.map +1 -1
  19. package/guards/google-recaptcha.guard.d.ts +7 -5
  20. package/guards/google-recaptcha.guard.js +23 -8
  21. package/guards/google-recaptcha.guard.js.map +1 -1
  22. package/helpers/xor.d.ts +1 -0
  23. package/helpers/xor.js +8 -0
  24. package/helpers/xor.js.map +1 -0
  25. package/index.d.ts +4 -1
  26. package/index.js +9 -3
  27. package/index.js.map +1 -1
  28. package/interfaces/google-recaptcha-enterprise-options.d.ts +5 -0
  29. package/interfaces/google-recaptcha-enterprise-options.js +3 -0
  30. package/interfaces/google-recaptcha-enterprise-options.js.map +1 -0
  31. package/interfaces/google-recaptcha-module-options.d.ts +3 -0
  32. package/interfaces/google-recaptcha-validator-options.d.ts +3 -1
  33. package/interfaces/verify-response-enterprise.d.ts +29 -0
  34. package/interfaces/{google-recaptcha-validation-result.js → verify-response-enterprise.js} +1 -1
  35. package/interfaces/verify-response-enterprise.js.map +1 -0
  36. package/models/recaptcha-verification-result.d.ts +20 -5
  37. package/models/recaptcha-verification-result.js +17 -4
  38. package/models/recaptcha-verification-result.js.map +1 -1
  39. package/package.json +1 -1
  40. package/provider.declarations.d.ts +1 -0
  41. package/provider.declarations.js +2 -1
  42. package/provider.declarations.js.map +1 -1
  43. package/services/enterprise-reason.transformer.d.ts +5 -0
  44. package/services/enterprise-reason.transformer.js +40 -0
  45. package/services/enterprise-reason.transformer.js.map +1 -0
  46. package/services/recaptcha-validator.resolver.d.ts +11 -0
  47. package/services/recaptcha-validator.resolver.js +44 -0
  48. package/services/recaptcha-validator.resolver.js.map +1 -0
  49. package/services/validators/abstract-google-recaptcha-validator.d.ts +11 -0
  50. package/services/validators/abstract-google-recaptcha-validator.js +28 -0
  51. package/services/validators/abstract-google-recaptcha-validator.js.map +1 -0
  52. package/services/validators/google-recaptcha-enterprise.validator.d.ts +16 -0
  53. package/services/validators/google-recaptcha-enterprise.validator.js +114 -0
  54. package/services/validators/google-recaptcha-enterprise.validator.js.map +1 -0
  55. package/services/validators/google-recaptcha.validator.d.ts +21 -0
  56. package/services/{google-recaptcha.validator.js → validators/google-recaptcha.validator.js} +39 -30
  57. package/services/validators/google-recaptcha.validator.js.map +1 -0
  58. package/enums/application-type.d.ts +0 -4
  59. package/enums/application-type.js +0 -9
  60. package/enums/application-type.js.map +0 -1
  61. package/interfaces/google-recaptcha-validation-result.d.ts +0 -9
  62. package/interfaces/google-recaptcha-validation-result.js.map +0 -1
  63. package/services/google-recaptcha.validator.d.ts +0 -20
  64. package/services/google-recaptcha.validator.js.map +0 -1
@@ -2,10 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RecaptchaVerificationResult = void 0;
4
4
  class RecaptchaVerificationResult {
5
- constructor(result) {
6
- this.action = result.action;
7
- this.score = result.score;
8
- this.hostname = result.hostname;
5
+ constructor(options) {
6
+ this.options = options;
7
+ this.success = options.success;
8
+ this.hostname = options.hostname;
9
+ this.action = options.action;
10
+ this.score = options.score;
11
+ this.errors = options.errors;
12
+ this.nativeResponse = options.nativeResponse;
13
+ }
14
+ getResponse() {
15
+ return this.nativeResponse;
16
+ }
17
+ getEnterpriseRiskAnalytics() {
18
+ const res = this.getResponse();
19
+ return res.hasOwnProperty('riskAnalysis')
20
+ ? res['riskAnalysis']
21
+ : null;
9
22
  }
10
23
  }
11
24
  exports.RecaptchaVerificationResult = RecaptchaVerificationResult;
@@ -1 +1 @@
1
- {"version":3,"file":"recaptcha-verification-result.js","sourceRoot":"","sources":["../../src/models/recaptcha-verification-result.ts"],"names":[],"mappings":";;;AAEA,MAAa,2BAA2B;IAKpC,YAAY,MAAuC;QAC/C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IACpC,CAAC;CACJ;AAVD,kEAUC"}
1
+ {"version":3,"file":"recaptcha-verification-result.js","sourceRoot":"","sources":["../../src/models/recaptcha-verification-result.ts"],"names":[],"mappings":";;;AAaA,MAAa,2BAA2B;IAQpC,YAA6B,OAA2C;QAA3C,YAAO,GAAP,OAAO,CAAoC;QACpE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IACjD,CAAC;IAED,WAAW;QACP,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAED,0BAA0B;QACtB,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAE/B,OAAO,GAAG,CAAC,cAAc,CAAC,cAAc,CAAC;YACrC,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC;YACrB,CAAC,CAAC,IAAI,CAAC;IACf,CAAC;CACJ;AA5BD,kEA4BC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestlab/google-recaptcha",
3
- "version": "3.0.1",
3
+ "version": "3.1.0",
4
4
  "description": "Google recaptcha module for NestJS.",
5
5
  "keywords": [
6
6
  "nest",
@@ -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"}
@@ -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;
5
+ }
@@ -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
+ 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.UnknownInvalidReason:
19
+ return error_code_1.ErrorCode.UnknownError;
20
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.SiteMismatch:
21
+ return error_code_1.ErrorCode.SiteMismatch;
22
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.Expired:
23
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.Dupe:
24
+ return error_code_1.ErrorCode.TimeoutOrDuplicate;
25
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.Malformed:
26
+ return error_code_1.ErrorCode.InvalidInputResponse;
27
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.Missing:
28
+ return error_code_1.ErrorCode.MissingInputResponse;
29
+ case google_recaptcha_enterprise_reason_1.GoogleRecaptchaEnterpriseReason.InvalidReasonUnspecified:
30
+ return error_code_1.ErrorCode.UnknownError;
31
+ default:
32
+ return error_code_1.ErrorCode.UnknownError;
33
+ }
34
+ }
35
+ };
36
+ EnterpriseReasonTransformer = __decorate([
37
+ (0, common_1.Injectable)()
38
+ ], EnterpriseReasonTransformer);
39
+ exports.EnterpriseReasonTransformer = EnterpriseReasonTransformer;
40
+ //# sourceMappingURL=enterprise-reason.transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enterprise-reason.transformer.js","sourceRoot":"","sources":["../../src/services/enterprise-reason.transformer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,oGAA8F;AAC9F,oDAAgD;AAGhD,IAAa,2BAA2B,GAAxC,MAAa,2BAA2B;IACpC,SAAS,CAAC,OAAwC;QAC9C,QAAQ,OAAO,EAAE;YACb,KAAK,oEAA+B,CAAC,YAAY;gBAC7C,OAAO,sBAAS,CAAC,YAAY,CAAC;YAElC,KAAK,oEAA+B,CAAC,oBAAoB;gBACrD,OAAO,sBAAS,CAAC,YAAY,CAAC;YAElC,KAAK,oEAA+B,CAAC,YAAY;gBAC7C,OAAO,sBAAS,CAAC,YAAY,CAAC;YAElC,KAAK,oEAA+B,CAAC,OAAO,CAAC;YAC7C,KAAK,oEAA+B,CAAC,IAAI;gBACrC,OAAO,sBAAS,CAAC,kBAAkB,CAAC;YAExC,KAAK,oEAA+B,CAAC,SAAS;gBAC1C,OAAO,sBAAS,CAAC,oBAAoB,CAAC;YAE1C,KAAK,oEAA+B,CAAC,OAAO;gBACxC,OAAO,sBAAS,CAAC,oBAAoB,CAAC;YAE1C,KAAK,oEAA+B,CAAC,wBAAwB;gBACzD,OAAO,sBAAS,CAAC,YAAY,CAAC;YAElC;gBACI,OAAO,sBAAS,CAAC,YAAY,CAAC;SACrC;IACL,CAAC;CACJ,CAAA;AA7BY,2BAA2B;IADvC,IAAA,mBAAU,GAAE;GACA,2BAA2B,CA6BvC;AA7BY,kEAA2B"}
@@ -0,0 +1,11 @@
1
+ import { AbstractGoogleRecaptchaValidator } from './validators/abstract-google-recaptcha-validator';
2
+ import { GoogleRecaptchaModuleOptions } from '../interfaces/google-recaptcha-module-options';
3
+ import { GoogleRecaptchaValidator } from './validators/google-recaptcha.validator';
4
+ import { GoogleRecaptchaEnterpriseValidator } from './validators/google-recaptcha-enterprise.validator';
5
+ export declare class RecaptchaValidatorResolver {
6
+ private readonly options;
7
+ protected readonly googleRecaptchaValidator: GoogleRecaptchaValidator;
8
+ protected readonly googleRecaptchaEnterpriseValidator: GoogleRecaptchaEnterpriseValidator;
9
+ constructor(options: GoogleRecaptchaModuleOptions, googleRecaptchaValidator: GoogleRecaptchaValidator, googleRecaptchaEnterpriseValidator: GoogleRecaptchaEnterpriseValidator);
10
+ resolve(): AbstractGoogleRecaptchaValidator;
11
+ }
@@ -0,0 +1,44 @@
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.RecaptchaValidatorResolver = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const provider_declarations_1 = require("../provider.declarations");
18
+ const google_recaptcha_validator_1 = require("./validators/google-recaptcha.validator");
19
+ const google_recaptcha_enterprise_validator_1 = require("./validators/google-recaptcha-enterprise.validator");
20
+ let RecaptchaValidatorResolver = class RecaptchaValidatorResolver {
21
+ constructor(options, googleRecaptchaValidator, googleRecaptchaEnterpriseValidator) {
22
+ this.options = options;
23
+ this.googleRecaptchaValidator = googleRecaptchaValidator;
24
+ this.googleRecaptchaEnterpriseValidator = googleRecaptchaEnterpriseValidator;
25
+ }
26
+ resolve() {
27
+ var _a;
28
+ if (this.options.secretKey) {
29
+ return this.googleRecaptchaValidator;
30
+ }
31
+ if ((_a = Object.keys(this.options.enterprise || {})) === null || _a === void 0 ? void 0 : _a.length) {
32
+ return this.googleRecaptchaEnterpriseValidator;
33
+ }
34
+ throw new Error('Cannot resolve google recaptcha validator');
35
+ }
36
+ };
37
+ RecaptchaValidatorResolver = __decorate([
38
+ (0, common_1.Injectable)(),
39
+ __param(0, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_OPTIONS)),
40
+ __metadata("design:paramtypes", [Object, google_recaptcha_validator_1.GoogleRecaptchaValidator,
41
+ google_recaptcha_enterprise_validator_1.GoogleRecaptchaEnterpriseValidator])
42
+ ], RecaptchaValidatorResolver);
43
+ exports.RecaptchaValidatorResolver = RecaptchaValidatorResolver;
44
+ //# sourceMappingURL=recaptcha-validator.resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recaptcha-validator.resolver.js","sourceRoot":"","sources":["../../src/services/recaptcha-validator.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AAEpD,oEAA6D;AAE7D,wFAAmF;AACnF,8GAAwG;AAGxG,IAAa,0BAA0B,GAAvC,MAAa,0BAA0B;IACnC,YAAwD,OAAqC,EAC9D,wBAAkD,EAClD,kCAAsE;QAF7C,YAAO,GAAP,OAAO,CAA8B;QAC9D,6BAAwB,GAAxB,wBAAwB,CAA0B;QAClD,uCAAkC,GAAlC,kCAAkC,CAAoC;IACrG,CAAC;IAED,OAAO;;QACH,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YACxB,OAAO,IAAI,CAAC,wBAAwB,CAAC;SACxC;QAED,IAAI,MAAA,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,0CAAE,MAAM,EAAE;YACpD,OAAO,IAAI,CAAC,kCAAkC,CAAC;SAClD;QAED,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IACjE,CAAC;CACJ,CAAA;AAjBY,0BAA0B;IADtC,IAAA,mBAAU,GAAE;IAEI,WAAA,IAAA,eAAM,EAAC,yCAAiB,CAAC,CAAA;6CACmB,qDAAwB;QACd,0EAAkC;GAH5F,0BAA0B,CAiBtC;AAjBY,gEAA0B"}
@@ -0,0 +1,11 @@
1
+ import { VerifyResponseOptions } from '../../interfaces/verify-response-decorator-options';
2
+ import { ScoreValidator } from '../../types';
3
+ import { GoogleRecaptchaModuleOptions } from '../../interfaces/google-recaptcha-module-options';
4
+ import { RecaptchaVerificationResult } from '../../models/recaptcha-verification-result';
5
+ export declare abstract class AbstractGoogleRecaptchaValidator<Res = any> {
6
+ protected readonly options: GoogleRecaptchaModuleOptions;
7
+ protected constructor(options: GoogleRecaptchaModuleOptions);
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,28 @@
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.actions
13
+ ? this.options.actions.includes(action)
14
+ : true;
15
+ }
16
+ isValidScore(score, validator) {
17
+ const finalValidator = validator || this.options.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;
28
+ //# sourceMappingURL=abstract-google-recaptcha-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-google-recaptcha-validator.js","sourceRoot":"","sources":["../../../src/services/validators/abstract-google-recaptcha-validator.ts"],"names":[],"mappings":";;;AAKA,MAAsB,gCAAgC;IAClD,YAAyC,OAAqC;QAArC,YAAO,GAAP,OAAO,CAA8B;IAC9E,CAAC;IAIS,aAAa,CAAC,MAAc,EAAE,OAA+B;QACnE,IAAI,OAAO,CAAC,MAAM,EAAE;YAChB,OAAO,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC;SACpC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO;YACvB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;YACvC,CAAC,CAAC,IAAI,CAAC;IACf,CAAC;IAES,YAAY,CAAC,KAAa,EAAE,SAA0B;QAC5D,MAAM,cAAc,GAAG,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QAEvD,IAAI,cAAc,EAAE;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;CACJ;AA7BD,4EA6BC"}
@@ -0,0 +1,16 @@
1
+ import { Logger } from '@nestjs/common';
2
+ import { HttpService } from '@nestjs/axios';
3
+ import { GoogleRecaptchaModuleOptions } from '../../interfaces/google-recaptcha-module-options';
4
+ import { VerifyResponseOptions } from '../../interfaces/verify-response-decorator-options';
5
+ import { AbstractGoogleRecaptchaValidator } from './abstract-google-recaptcha-validator';
6
+ import { RecaptchaVerificationResult } from '../../models/recaptcha-verification-result';
7
+ import { EnterpriseReasonTransformer } from '../enterprise-reason.transformer';
8
+ export declare class GoogleRecaptchaEnterpriseValidator extends AbstractGoogleRecaptchaValidator {
9
+ private readonly http;
10
+ private readonly logger;
11
+ private readonly enterpriseReasonTransformer;
12
+ private readonly headers;
13
+ constructor(http: HttpService, logger: Logger, options: GoogleRecaptchaModuleOptions, enterpriseReasonTransformer: EnterpriseReasonTransformer);
14
+ validate(options: VerifyResponseOptions): Promise<RecaptchaVerificationResult>;
15
+ private verifyResponse;
16
+ }
@@ -0,0 +1,114 @@
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 axios_1 = require("@nestjs/axios");
19
+ const abstract_google_recaptcha_validator_1 = require("./abstract-google-recaptcha-validator");
20
+ const recaptcha_verification_result_1 = require("../../models/recaptcha-verification-result");
21
+ const error_code_1 = require("../../enums/error-code");
22
+ const google_recaptcha_network_exception_1 = require("../../exceptions/google-recaptcha-network.exception");
23
+ const google_recaptcha_context_1 = require("../../enums/google-recaptcha-context");
24
+ const enterprise_reason_transformer_1 = require("../enterprise-reason.transformer");
25
+ let GoogleRecaptchaEnterpriseValidator = class GoogleRecaptchaEnterpriseValidator extends abstract_google_recaptcha_validator_1.AbstractGoogleRecaptchaValidator {
26
+ constructor(http, logger, options, enterpriseReasonTransformer) {
27
+ super(options);
28
+ this.http = http;
29
+ this.logger = logger;
30
+ this.enterpriseReasonTransformer = enterpriseReasonTransformer;
31
+ this.headers = { 'Content-Type': 'application/json' };
32
+ }
33
+ async validate(options) {
34
+ var _a, _b, _c;
35
+ const [result, errorDetails] = await this.verifyResponse(options.response, options.action);
36
+ const errors = [];
37
+ let success = result.tokenProperties.valid;
38
+ if (result.tokenProperties.invalidReason) {
39
+ errors.push(this.enterpriseReasonTransformer.transform(result.tokenProperties.invalidReason));
40
+ }
41
+ if (errorDetails) {
42
+ errors.push(error_code_1.ErrorCode.UnknownError);
43
+ }
44
+ if (!result) {
45
+ if (!this.isValidAction(result.tokenProperties.action, options)) {
46
+ success = false;
47
+ errors.push(error_code_1.ErrorCode.ForbiddenAction);
48
+ }
49
+ if (!this.isValidScore(result.riskAnalysis.score, options.score)) {
50
+ success = false;
51
+ errors.push(error_code_1.ErrorCode.LowScore);
52
+ }
53
+ }
54
+ return new recaptcha_verification_result_1.RecaptchaVerificationResult({
55
+ success,
56
+ errors,
57
+ nativeResponse: result || errorDetails,
58
+ score: (_a = result === null || result === void 0 ? void 0 : result.riskAnalysis) === null || _a === void 0 ? void 0 : _a.score,
59
+ action: (_b = result === null || result === void 0 ? void 0 : result.tokenProperties) === null || _b === void 0 ? void 0 : _b.action,
60
+ hostname: ((_c = result === null || result === void 0 ? void 0 : result.tokenProperties) === null || _c === void 0 ? void 0 : _c.hostname) || '',
61
+ });
62
+ }
63
+ verifyResponse(response, expectedAction) {
64
+ const projectId = this.options.enterprise.projectId;
65
+ const body = {
66
+ event: {
67
+ expectedAction,
68
+ siteKey: this.options.enterprise.siteKey,
69
+ token: response,
70
+ },
71
+ };
72
+ const url = `https://recaptchaenterprise.googleapis.com/v1/projects/${projectId}/assessments`;
73
+ const config = {
74
+ headers: this.headers,
75
+ params: {
76
+ key: this.options.enterprise.apiKey,
77
+ },
78
+ };
79
+ if (this.options.debug) {
80
+ this.logger.debug({ body }, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptchaEnterprise}.request`);
81
+ }
82
+ return this.http.post(url, body, config)
83
+ .toPromise()
84
+ .then(res => res.data)
85
+ .then(data => {
86
+ if (this.options.debug) {
87
+ this.logger.debug(data, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptchaEnterprise}.response`);
88
+ }
89
+ return [data, null];
90
+ })
91
+ .catch((err) => {
92
+ var _a, _b;
93
+ if (this.options.debug) {
94
+ 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 }, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptchaEnterprise}.error`);
95
+ }
96
+ const networkErrorCode = err.isAxiosError && err.code;
97
+ if (networkErrorCode) {
98
+ throw new google_recaptcha_network_exception_1.GoogleRecaptchaNetworkException(networkErrorCode);
99
+ }
100
+ const errData = (_b = err.response) === null || _b === void 0 ? void 0 : _b.data;
101
+ return [null, errData];
102
+ });
103
+ }
104
+ };
105
+ GoogleRecaptchaEnterpriseValidator = __decorate([
106
+ (0, common_1.Injectable)(),
107
+ __param(0, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_HTTP_SERVICE)),
108
+ __param(1, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_LOGGER)),
109
+ __param(2, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_OPTIONS)),
110
+ __metadata("design:paramtypes", [axios_1.HttpService,
111
+ common_1.Logger, Object, enterprise_reason_transformer_1.EnterpriseReasonTransformer])
112
+ ], GoogleRecaptchaEnterpriseValidator);
113
+ exports.GoogleRecaptchaEnterpriseValidator = GoogleRecaptchaEnterpriseValidator;
114
+ //# sourceMappingURL=google-recaptcha-enterprise.validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-recaptcha-enterprise.validator.js","sourceRoot":"","sources":["../../../src/services/validators/google-recaptcha-enterprise.validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,uEAA0G;AAC1G,yC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IAAA,mBAAU,GAAE;IAII,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,UAEX,2DAA2B;GAN5E,kCAAkC,CAkG9C;AAlGY,gFAAkC"}
@@ -0,0 +1,21 @@
1
+ import { Logger } from '@nestjs/common';
2
+ import { VerifyResponseOptions } from '../../interfaces/verify-response-decorator-options';
3
+ import { VerifyResponseV3 } from '../../interfaces/verify-response';
4
+ import { HttpService } from "@nestjs/axios";
5
+ import { GoogleRecaptchaModuleOptions } from '../../interfaces/google-recaptcha-module-options';
6
+ import { AbstractGoogleRecaptchaValidator } from './abstract-google-recaptcha-validator';
7
+ import { RecaptchaVerificationResult } from '../../models/recaptcha-verification-result';
8
+ export declare class GoogleRecaptchaValidator extends AbstractGoogleRecaptchaValidator {
9
+ private readonly http;
10
+ private readonly logger;
11
+ private readonly defaultNetwork;
12
+ private readonly headers;
13
+ constructor(http: HttpService, logger: Logger, options: GoogleRecaptchaModuleOptions);
14
+ /**
15
+ * @throws GoogleRecaptchaNetworkException
16
+ * @param {VerifyResponseOptions} options
17
+ */
18
+ validate(options: VerifyResponseOptions): Promise<RecaptchaVerificationResult<VerifyResponseV3>>;
19
+ private verifyResponse;
20
+ private isUseV3;
21
+ }
@@ -14,16 +14,20 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.GoogleRecaptchaValidator = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
- const provider_declarations_1 = require("../provider.declarations");
17
+ const provider_declarations_1 = require("../../provider.declarations");
18
18
  const qs = require("querystring");
19
- const google_recaptcha_network_1 = require("../enums/google-recaptcha-network");
20
- const error_code_1 = require("../enums/error-code");
21
- const google_recaptcha_network_exception_1 = require("../exceptions/google-recaptcha-network.exception");
19
+ const google_recaptcha_network_1 = require("../../enums/google-recaptcha-network");
20
+ const error_code_1 = require("../../enums/error-code");
21
+ const google_recaptcha_network_exception_1 = require("../../exceptions/google-recaptcha-network.exception");
22
22
  const axios_1 = require("@nestjs/axios");
23
- let GoogleRecaptchaValidator = class GoogleRecaptchaValidator {
24
- constructor(http, options) {
23
+ const abstract_google_recaptcha_validator_1 = require("./abstract-google-recaptcha-validator");
24
+ const recaptcha_verification_result_1 = require("../../models/recaptcha-verification-result");
25
+ const google_recaptcha_context_1 = require("../../enums/google-recaptcha-context");
26
+ let GoogleRecaptchaValidator = class GoogleRecaptchaValidator extends abstract_google_recaptcha_validator_1.AbstractGoogleRecaptchaValidator {
27
+ constructor(http, logger, options) {
28
+ super(options);
25
29
  this.http = http;
26
- this.options = options;
30
+ this.logger = logger;
27
31
  this.defaultNetwork = google_recaptcha_network_1.GoogleRecaptchaNetwork.Google;
28
32
  this.headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
29
33
  }
@@ -33,6 +37,7 @@ let GoogleRecaptchaValidator = class GoogleRecaptchaValidator {
33
37
  */
34
38
  async validate(options) {
35
39
  const result = await this.verifyResponse(options.response);
40
+ const nativeResponse = Object.assign({}, result);
36
41
  if (!this.isUseV3(result)) {
37
42
  return result;
38
43
  }
@@ -44,23 +49,43 @@ let GoogleRecaptchaValidator = class GoogleRecaptchaValidator {
44
49
  result.success = false;
45
50
  result.errors.push(error_code_1.ErrorCode.LowScore);
46
51
  }
47
- return result;
52
+ return new recaptcha_verification_result_1.RecaptchaVerificationResult({
53
+ nativeResponse: nativeResponse,
54
+ score: result.score,
55
+ errors: result.errors,
56
+ success: result.success,
57
+ action: result.action,
58
+ hostname: result.hostname,
59
+ });
48
60
  }
49
61
  verifyResponse(response) {
50
- const data = qs.stringify({ secret: this.options.secretKey, response });
62
+ const body = qs.stringify({ secret: this.options.secretKey, response });
51
63
  const url = this.options.network || this.defaultNetwork;
52
64
  const config = {
53
65
  headers: this.headers,
54
66
  };
55
- return this.http.post(url, data, config)
67
+ if (this.options.debug) {
68
+ this.logger.debug({ body }, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptcha}.request`);
69
+ }
70
+ return this.http.post(url, body, config)
56
71
  .toPromise()
57
72
  .then(res => res.data)
73
+ .then(data => {
74
+ if (this.options.debug) {
75
+ this.logger.debug(data, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptcha}.response`);
76
+ }
77
+ return data;
78
+ })
58
79
  .then(result => (Object.assign(Object.assign({}, result), { errors: result['error-codes'] || [] })))
59
80
  .then(result => {
60
81
  delete result['error-codes'];
61
82
  return result;
62
83
  })
63
84
  .catch((err) => {
85
+ var _a;
86
+ if (this.options.debug) {
87
+ 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 }, `${google_recaptcha_context_1.GoogleRecaptchaContext.GoogleRecaptcha}.error`);
88
+ }
64
89
  const networkErrorCode = err.isAxiosError && err.code;
65
90
  if (networkErrorCode) {
66
91
  throw new google_recaptcha_network_exception_1.GoogleRecaptchaNetworkException(networkErrorCode);
@@ -71,24 +96,6 @@ let GoogleRecaptchaValidator = class GoogleRecaptchaValidator {
71
96
  };
72
97
  });
73
98
  }
74
- isValidAction(action, options) {
75
- if (options.action) {
76
- return options.action === action;
77
- }
78
- return this.options.actions
79
- ? this.options.actions.includes(action)
80
- : true;
81
- }
82
- isValidScore(score, validator) {
83
- const finalValidator = validator || this.options.score;
84
- if (finalValidator) {
85
- if (typeof finalValidator === 'function') {
86
- return finalValidator(score);
87
- }
88
- return score >= finalValidator;
89
- }
90
- return true;
91
- }
92
99
  isUseV3(v) {
93
100
  return ('score' in v && typeof v['score'] === 'number') &&
94
101
  ('action' in v && typeof v['action'] === 'string');
@@ -97,8 +104,10 @@ let GoogleRecaptchaValidator = class GoogleRecaptchaValidator {
97
104
  GoogleRecaptchaValidator = __decorate([
98
105
  (0, common_1.Injectable)(),
99
106
  __param(0, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_HTTP_SERVICE)),
100
- __param(1, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_OPTIONS)),
101
- __metadata("design:paramtypes", [axios_1.HttpService, Object])
107
+ __param(1, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_LOGGER)),
108
+ __param(2, (0, common_1.Inject)(provider_declarations_1.RECAPTCHA_OPTIONS)),
109
+ __metadata("design:paramtypes", [axios_1.HttpService,
110
+ common_1.Logger, Object])
102
111
  ], GoogleRecaptchaValidator);
103
112
  exports.GoogleRecaptchaValidator = GoogleRecaptchaValidator;
104
113
  //# sourceMappingURL=google-recaptcha.validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-recaptcha.validator.js","sourceRoot":"","sources":["../../../src/services/validators/google-recaptcha.validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,uEAA0G;AAC1G,kCAAkC;AAElC,mFAA8E;AAG9E,uDAAmD;AACnD,4GAAsG;AACtG,yCAA4C;AAE5C,+FAAyF;AACzF,8FAAyF;AACzF,mFAA8E;AAG9E,IAAa,wBAAwB,GAArC,MAAa,wBAAyB,SAAQ,sEAAgC;IAI1E,YAA6D,IAAiB,EACvB,MAAc,EAC9B,OAAqC;QACxE,KAAK,CAAC,OAAO,CAAC,CAAC;QAH0C,SAAI,GAAJ,IAAI,CAAa;QACvB,WAAM,GAAN,MAAM,CAAQ;QAJpD,mBAAc,GAAG,iDAAsB,CAAC,MAAM,CAAC;QAC/C,YAAO,GAAG,EAAC,cAAc,EAAE,mCAAmC,EAAC,CAAC;IAMjF,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ,CAAC,OAA8B;QACzC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAmB,OAAO,CAAC,QAA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GAAG,CAAC,YAAY,IAAI,GAAG,CAAC,IAAI,CAAC;YAEtD,IAAI,gBAAgB,EAAE;gBAClB,MAAM,IAAI,oEAA+B,CAAC,gBAAgB,CAAC,CAAC;aAC/D;YAED,OAAO;gBACH,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,CAAC,sBAAS,CAAC,YAAY,CAAC;aACnC,CAAA;QACL,CAAC,CAAC,CAAC;IACX,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;AAlGY,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,CAkGpC;AAlGY,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"}
@@ -1,9 +0,0 @@
1
- import { ErrorCode } from '../enums/error-code';
2
- import { VerifyResponseV2 } from './verify-response';
3
- export interface GoogleRecaptchaValidationResult extends VerifyResponseV2 {
4
- success: boolean;
5
- hostname: string;
6
- action?: string;
7
- score?: number;
8
- errors: ErrorCode[];
9
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"google-recaptcha-validation-result.js","sourceRoot":"","sources":["../../src/interfaces/google-recaptcha-validation-result.ts"],"names":[],"mappings":""}
@@ -1,20 +0,0 @@
1
- import { GoogleRecaptchaValidatorOptions } from '../interfaces/google-recaptcha-validator-options';
2
- import { GoogleRecaptchaValidationResult } from '../interfaces/google-recaptcha-validation-result';
3
- import { VerifyResponseOptions } from '../interfaces/verify-response-decorator-options';
4
- import { HttpService } from "@nestjs/axios";
5
- export declare class GoogleRecaptchaValidator {
6
- private readonly http;
7
- private readonly options;
8
- private readonly defaultNetwork;
9
- private readonly headers;
10
- constructor(http: HttpService, options: GoogleRecaptchaValidatorOptions);
11
- /**
12
- * @throws GoogleRecaptchaNetworkException
13
- * @param {VerifyResponseOptions} options
14
- */
15
- validate(options: VerifyResponseOptions): Promise<GoogleRecaptchaValidationResult>;
16
- private verifyResponse;
17
- private isValidAction;
18
- private isValidScore;
19
- private isUseV3;
20
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"google-recaptcha.validator.js","sourceRoot":"","sources":["../../src/services/google-recaptcha.validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AAEpD,oEAAqF;AACrF,kCAAkC;AAGlC,gFAA2E;AAI3E,oDAAgD;AAChD,yGAAmG;AACnG,yCAA4C;AAG5C,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;IAIjC,YAA6D,IAAiB,EACtB,OAAwC;QADnC,SAAI,GAAJ,IAAI,CAAa;QACtB,YAAO,GAA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