@infrab4a/connect 4.9.0 → 4.9.1-beta.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 (67) hide show
  1. package/index.cjs.js +1048 -335
  2. package/index.esm.js +1000 -315
  3. package/package.json +1 -1
  4. package/src/domain/general/index.d.ts +2 -0
  5. package/src/domain/general/models/index.d.ts +1 -0
  6. package/src/domain/general/models/sequences.d.ts +9 -0
  7. package/src/domain/general/repositories/index.d.ts +1 -0
  8. package/src/domain/general/repositories/sequences.repository.d.ts +4 -0
  9. package/src/domain/shopping/enums/antifraud-providers.enum.d.ts +6 -0
  10. package/src/domain/shopping/enums/index.d.ts +3 -0
  11. package/src/domain/shopping/enums/payment-methods.enum.d.ts +6 -0
  12. package/src/domain/shopping/enums/payment-providers.enum.d.ts +5 -0
  13. package/src/domain/shopping/factories/adyen-payment-method.factory.d.ts +8 -0
  14. package/src/domain/shopping/factories/antifraud-provider.factory.d.ts +15 -0
  15. package/src/domain/shopping/factories/base-payment-method.factory.d.ts +7 -0
  16. package/src/domain/shopping/factories/glampoints-payment-method.factory.d.ts +8 -0
  17. package/src/domain/shopping/factories/index.d.ts +5 -0
  18. package/src/domain/shopping/factories/pagarme-payment-method.factory.d.ts +10 -0
  19. package/src/domain/shopping/factories/payment-provider.factory.d.ts +15 -0
  20. package/src/domain/shopping/index.d.ts +5 -0
  21. package/src/domain/shopping/interfaces/antifraud-method-factory.interface.d.ts +11 -0
  22. package/src/domain/shopping/interfaces/antifraud-provider.interface.d.ts +5 -0
  23. package/src/domain/shopping/interfaces/index.d.ts +7 -0
  24. package/src/domain/shopping/interfaces/payment-method-factory.interface.d.ts +14 -0
  25. package/src/domain/shopping/interfaces/payment-provider-bank-slip.interface.d.ts +5 -0
  26. package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +7 -0
  27. package/src/domain/shopping/interfaces/payment-provider-glampoints.interface.d.ts +5 -0
  28. package/src/domain/shopping/interfaces/payment-provider-pix.interface.d.ts +5 -0
  29. package/src/domain/shopping/models/index.d.ts +2 -0
  30. package/src/domain/shopping/models/order-blocked.d.ts +26 -0
  31. package/src/domain/shopping/models/order.d.ts +2 -2
  32. package/src/domain/shopping/models/payment-transaction.d.ts +66 -0
  33. package/src/domain/shopping/models/payment.d.ts +10 -63
  34. package/src/domain/shopping/models/types/index.d.ts +4 -4
  35. package/src/domain/shopping/repositories/index.d.ts +1 -0
  36. package/src/domain/shopping/repositories/order-blocked.repository.d.ts +6 -0
  37. package/src/domain/shopping/services/adyen-card-payment.service.d.ts +13 -0
  38. package/src/domain/shopping/services/antifraud-bankslip.service.d.ts +9 -0
  39. package/src/domain/shopping/services/antifraud-card.service.d.ts +18 -0
  40. package/src/domain/shopping/services/antifraud-glampoints.service.d.ts +6 -0
  41. package/src/domain/shopping/services/antifraud-pix.service.d.ts +6 -0
  42. package/src/domain/shopping/services/glampoints-payment.service.d.ts +8 -0
  43. package/src/domain/shopping/services/index.d.ts +9 -0
  44. package/src/domain/shopping/services/pagarme-bank-slip-payment.service.d.ts +11 -0
  45. package/src/domain/shopping/services/pagarme-card-payment.service.d.ts +13 -0
  46. package/src/domain/shopping/services/pagarme-pix-payment.service.d.ts +11 -0
  47. package/src/domain/shopping/types/adyen-credentials.type.d.ts +6 -0
  48. package/src/domain/shopping/types/antifraud-provider.type.d.ts +2 -0
  49. package/src/domain/shopping/types/index.d.ts +6 -0
  50. package/src/domain/shopping/types/pagarme-credentials.type.d.ts +5 -0
  51. package/src/domain/shopping/types/payment-card-info.type.d.ts +4 -0
  52. package/src/domain/shopping/types/payment-method.type.d.ts +2 -0
  53. package/src/domain/shopping/types/payment-provider.type.d.ts +2 -0
  54. package/src/errors/business.error.d.ts +7 -0
  55. package/src/errors/fraud-validation.error.d.ts +7 -0
  56. package/src/errors/index.d.ts +7 -2
  57. package/src/errors/payment.error.d.ts +7 -0
  58. package/src/errors/stock-limit.error.d.ts +5 -0
  59. package/src/errors/stock-out.error.d.ts +5 -0
  60. package/src/errors/types/checkout-additional-data-erro.type.d.ts +5 -0
  61. package/src/errors/types/index.d.ts +1 -0
  62. package/src/infra/firebase/firestore/repositories/general/index.d.ts +1 -0
  63. package/src/infra/firebase/firestore/repositories/general/sequences-firestore.repository.d.ts +7 -0
  64. package/src/infra/firebase/firestore/repositories/index.d.ts +3 -2
  65. package/src/infra/firebase/firestore/repositories/shopping/index.d.ts +1 -0
  66. package/src/infra/firebase/firestore/repositories/shopping/order-blocked-firestore.repository.d.ts +9 -0
  67. package/src/utils/index.d.ts +2 -2
package/index.esm.js CHANGED
@@ -2,8 +2,8 @@ import 'reflect-metadata';
2
2
  import * as tslib_1 from 'tslib';
3
3
  import { __decorate, __metadata, __rest } from 'tslib';
4
4
  import { plainToInstance, instanceToPlain, Type, Expose } from 'class-transformer';
5
- import { parseISO } from 'date-fns';
6
- export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub } from 'date-fns';
5
+ import { parseISO, format, startOfDay, endOfDay, subDays, addDays } from 'date-fns';
6
+ export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub, subDays } from 'date-fns';
7
7
  import { isNil, isArray as isArray$1, first, last, flatten, compact, get, isString, each, unset, isObject as isObject$1, set, isNumber, chunk, isEmpty, isDate, isBoolean, isInteger, isNaN as isNaN$1, sortBy, omit } from 'lodash';
8
8
  export { chunk, each, get, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil, isNumber, isObject, isString, now, omit, pick, set, sortBy, unset } from 'lodash';
9
9
  import { debug } from 'debug';
@@ -14,6 +14,65 @@ import { deleteField, arrayUnion, arrayRemove, Timestamp, doc, getDoc, updateDoc
14
14
  import { ref, uploadBytes } from 'firebase/storage';
15
15
  import { mutation, query as query$1 } from 'gql-query-builder';
16
16
 
17
+ var antifraudProviders;
18
+ (function (antifraudProviders) {
19
+ antifraudProviders["BANKSLIP"] = "bankSlip";
20
+ antifraudProviders["CARD"] = "card";
21
+ antifraudProviders["PIX"] = "pix";
22
+ antifraudProviders["POINTS"] = "glampoints";
23
+ })(antifraudProviders || (antifraudProviders = {}));
24
+
25
+ var paymentMethods;
26
+ (function (paymentMethods) {
27
+ paymentMethods["CARD"] = "card";
28
+ paymentMethods["BANKSLIP"] = "bankSlip";
29
+ paymentMethods["PIX"] = "pix";
30
+ paymentMethods["POINTS"] = "glampoints";
31
+ })(paymentMethods || (paymentMethods = {}));
32
+
33
+ var paymentProviders;
34
+ (function (paymentProviders) {
35
+ paymentProviders["PAGARME"] = "pagarMe";
36
+ paymentProviders["ADYEN"] = "adyen";
37
+ paymentProviders["GLAMPOINTS"] = "glampoints";
38
+ })(paymentProviders || (paymentProviders = {}));
39
+
40
+ class BasePaymentMethodFactory {
41
+ constructor(methods) {
42
+ this.methods = methods;
43
+ }
44
+ build(method) {
45
+ return this.methods[method];
46
+ }
47
+ }
48
+
49
+ class AdyenPaymentMethodFactory extends BasePaymentMethodFactory {
50
+ }
51
+
52
+ class AntifraudProviderFactory {
53
+ constructor(antifraudProviders) {
54
+ this.antifraudProviders = antifraudProviders;
55
+ }
56
+ build(provider) {
57
+ return this.antifraudProviders[provider];
58
+ }
59
+ }
60
+
61
+ class GlampointsPaymentMethodFactory extends BasePaymentMethodFactory {
62
+ }
63
+
64
+ class PagarmePaymentMethodFactory extends BasePaymentMethodFactory {
65
+ }
66
+
67
+ class PaymentProviderFactory {
68
+ constructor(paymentProviders) {
69
+ this.paymentProviders = paymentProviders;
70
+ }
71
+ build(provider) {
72
+ return this.paymentProviders[provider];
73
+ }
74
+ }
75
+
17
76
  class BaseModel {
18
77
  get identifier() {
19
78
  const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
@@ -496,175 +555,178 @@ var Status;
496
555
  Status["CANCELLED"] = "Cancelado";
497
556
  })(Status || (Status = {}));
498
557
 
499
- class Payment extends BaseModel {
500
- static get identifiersFields() {
501
- return ['id'];
502
- }
558
+ class PaymentTransaction extends BaseModel {
503
559
  }
504
560
  __decorate([
505
561
  Expose({ name: 'refuse_reason' }),
506
562
  __metadata("design:type", String)
507
- ], Payment.prototype, "refuseReason", void 0);
563
+ ], PaymentTransaction.prototype, "refuseReason", void 0);
508
564
  __decorate([
509
565
  Expose({ name: 'status_reason' }),
510
566
  __metadata("design:type", String)
511
- ], Payment.prototype, "statusReason", void 0);
567
+ ], PaymentTransaction.prototype, "statusReason", void 0);
512
568
  __decorate([
513
569
  Expose({ name: 'acquirer_response_code' }),
514
570
  __metadata("design:type", String)
515
- ], Payment.prototype, "acquirerResponseCode", void 0);
571
+ ], PaymentTransaction.prototype, "acquirerResponseCode", void 0);
516
572
  __decorate([
517
573
  Expose({ name: 'acquirer_name' }),
518
574
  __metadata("design:type", String)
519
- ], Payment.prototype, "acquirerName", void 0);
575
+ ], PaymentTransaction.prototype, "acquirerName", void 0);
520
576
  __decorate([
521
577
  Expose({ name: 'acquirer_id' }),
522
578
  __metadata("design:type", String)
523
- ], Payment.prototype, "acquirerId", void 0);
579
+ ], PaymentTransaction.prototype, "acquirerId", void 0);
524
580
  __decorate([
525
581
  Expose({ name: 'authorization_code' }),
526
582
  __metadata("design:type", String)
527
- ], Payment.prototype, "authorizationCode", void 0);
583
+ ], PaymentTransaction.prototype, "authorizationCode", void 0);
528
584
  __decorate([
529
585
  Expose({ name: 'soft_descriptor' }),
530
586
  __metadata("design:type", String)
531
- ], Payment.prototype, "softDescriptor", void 0);
587
+ ], PaymentTransaction.prototype, "softDescriptor", void 0);
532
588
  __decorate([
533
589
  Expose({ name: 'date_created' }),
534
590
  __metadata("design:type", String)
535
- ], Payment.prototype, "dateCreated", void 0);
591
+ ], PaymentTransaction.prototype, "dateCreated", void 0);
536
592
  __decorate([
537
593
  Expose({ name: 'date_updated' }),
538
594
  __metadata("design:type", String)
539
- ], Payment.prototype, "dateUpdated", void 0);
595
+ ], PaymentTransaction.prototype, "dateUpdated", void 0);
540
596
  __decorate([
541
597
  Expose({ name: 'authorized_amount' }),
542
598
  __metadata("design:type", Number)
543
- ], Payment.prototype, "authorizedAmount", void 0);
599
+ ], PaymentTransaction.prototype, "authorizedAmount", void 0);
544
600
  __decorate([
545
601
  Expose({ name: 'paid_amount' }),
546
602
  __metadata("design:type", Number)
547
- ], Payment.prototype, "paidAmount", void 0);
548
- __decorate([
549
- Expose({ name: 'paid_at' }),
550
- __metadata("design:type", String)
551
- ], Payment.prototype, "paidAt", void 0);
603
+ ], PaymentTransaction.prototype, "paidAmount", void 0);
552
604
  __decorate([
553
605
  Expose({ name: 'refunded_amount' }),
554
606
  __metadata("design:type", Number)
555
- ], Payment.prototype, "refundedAmount", void 0);
607
+ ], PaymentTransaction.prototype, "refundedAmount", void 0);
556
608
  __decorate([
557
609
  Expose({ name: 'card_holder_name' }),
558
610
  __metadata("design:type", String)
559
- ], Payment.prototype, "cardHolderName", void 0);
611
+ ], PaymentTransaction.prototype, "cardHolderName", void 0);
560
612
  __decorate([
561
613
  Expose({ name: 'card_last_digits' }),
562
614
  __metadata("design:type", String)
563
- ], Payment.prototype, "cardLastDigits", void 0);
615
+ ], PaymentTransaction.prototype, "cardLastDigits", void 0);
564
616
  __decorate([
565
617
  Expose({ name: 'card_first_digits' }),
566
618
  __metadata("design:type", String)
567
- ], Payment.prototype, "cardFirstDigits", void 0);
619
+ ], PaymentTransaction.prototype, "cardFirstDigits", void 0);
568
620
  __decorate([
569
621
  Expose({ name: 'card_brand' }),
570
622
  __metadata("design:type", String)
571
- ], Payment.prototype, "cardBrand", void 0);
623
+ ], PaymentTransaction.prototype, "cardBrand", void 0);
572
624
  __decorate([
573
625
  Expose({ name: 'card_pin_mode' }),
574
626
  __metadata("design:type", String)
575
- ], Payment.prototype, "cardPinMode", void 0);
627
+ ], PaymentTransaction.prototype, "cardPinMode", void 0);
576
628
  __decorate([
577
629
  Expose({ name: 'card_magstripe_fallback' }),
578
630
  __metadata("design:type", Boolean)
579
- ], Payment.prototype, "cardMagstripeFallback", void 0);
631
+ ], PaymentTransaction.prototype, "cardMagstripeFallback", void 0);
580
632
  __decorate([
581
633
  Expose({ name: 'cvm_pin' }),
582
634
  __metadata("design:type", Boolean)
583
- ], Payment.prototype, "cvmPin", void 0);
635
+ ], PaymentTransaction.prototype, "cvmPin", void 0);
584
636
  __decorate([
585
637
  Expose({ name: 'postback_url' }),
586
638
  __metadata("design:type", String)
587
- ], Payment.prototype, "postbackUrl", void 0);
639
+ ], PaymentTransaction.prototype, "postbackUrl", void 0);
588
640
  __decorate([
589
641
  Expose({ name: 'payment_method' }),
590
642
  __metadata("design:type", String)
591
- ], Payment.prototype, "paymentMethod", void 0);
643
+ ], PaymentTransaction.prototype, "paymentMethod", void 0);
592
644
  __decorate([
593
645
  Expose({ name: 'capture_method' }),
594
646
  __metadata("design:type", String)
595
- ], Payment.prototype, "captureMethod", void 0);
647
+ ], PaymentTransaction.prototype, "captureMethod", void 0);
596
648
  __decorate([
597
649
  Expose({ name: 'antifraud_score' }),
598
650
  __metadata("design:type", String)
599
- ], Payment.prototype, "antifraudScore", void 0);
651
+ ], PaymentTransaction.prototype, "antifraudScore", void 0);
600
652
  __decorate([
601
653
  Expose({ name: 'boleto_url' }),
602
654
  __metadata("design:type", String)
603
- ], Payment.prototype, "boletoUrl", void 0);
655
+ ], PaymentTransaction.prototype, "boletoUrl", void 0);
604
656
  __decorate([
605
657
  Expose({ name: 'boleto_barcode' }),
606
658
  __metadata("design:type", String)
607
- ], Payment.prototype, "boletoBarcode", void 0);
659
+ ], PaymentTransaction.prototype, "boletoBarcode", void 0);
608
660
  __decorate([
609
661
  Expose({ name: 'boleto_expiration_date' }),
610
662
  __metadata("design:type", String)
611
- ], Payment.prototype, "boletoExpirationDate", void 0);
663
+ ], PaymentTransaction.prototype, "boletoExpirationDate", void 0);
612
664
  __decorate([
613
665
  Expose({ name: 'subscription_id' }),
614
666
  __metadata("design:type", String)
615
- ], Payment.prototype, "subscriptionId", void 0);
667
+ ], PaymentTransaction.prototype, "subscriptionId", void 0);
616
668
  __decorate([
617
669
  Expose({ name: 'split_rules' }),
618
670
  __metadata("design:type", String)
619
- ], Payment.prototype, "splitRules", void 0);
671
+ ], PaymentTransaction.prototype, "splitRules", void 0);
620
672
  __decorate([
621
673
  Expose({ name: 'antifraud_metadata' }),
622
674
  __metadata("design:type", Object)
623
- ], Payment.prototype, "antifraudMetadata", void 0);
675
+ ], PaymentTransaction.prototype, "antifraudMetadata", void 0);
624
676
  __decorate([
625
677
  Expose({ name: 'reference_key' }),
626
678
  __metadata("design:type", String)
627
- ], Payment.prototype, "referenceKey", void 0);
679
+ ], PaymentTransaction.prototype, "referenceKey", void 0);
628
680
  __decorate([
629
681
  Expose({ name: 'local_transaction_id' }),
630
682
  __metadata("design:type", String)
631
- ], Payment.prototype, "localTransactionId", void 0);
683
+ ], PaymentTransaction.prototype, "localTransactionId", void 0);
632
684
  __decorate([
633
685
  Expose({ name: 'local_time' }),
634
686
  __metadata("design:type", String)
635
- ], Payment.prototype, "localTime", void 0);
687
+ ], PaymentTransaction.prototype, "localTime", void 0);
636
688
  __decorate([
637
689
  Expose({ name: 'fraud_covered' }),
638
690
  __metadata("design:type", Boolean)
639
- ], Payment.prototype, "fraudCovered", void 0);
691
+ ], PaymentTransaction.prototype, "fraudCovered", void 0);
640
692
  __decorate([
641
693
  Expose({ name: 'fraud_reimbursed' }),
642
694
  __metadata("design:type", String)
643
- ], Payment.prototype, "fraudReimbursed", void 0);
695
+ ], PaymentTransaction.prototype, "fraudReimbursed", void 0);
644
696
  __decorate([
645
697
  Expose({ name: 'order_id' }),
646
698
  __metadata("design:type", String)
647
- ], Payment.prototype, "orderId", void 0);
699
+ ], PaymentTransaction.prototype, "orderId", void 0);
648
700
  __decorate([
649
701
  Expose({ name: 'risk_level' }),
650
702
  __metadata("design:type", String)
651
- ], Payment.prototype, "riskLevel", void 0);
703
+ ], PaymentTransaction.prototype, "riskLevel", void 0);
652
704
  __decorate([
653
705
  Expose({ name: 'receipt_url' }),
654
706
  __metadata("design:type", String)
655
- ], Payment.prototype, "receiptUrl", void 0);
707
+ ], PaymentTransaction.prototype, "receiptUrl", void 0);
656
708
  __decorate([
657
709
  Expose({ name: 'private_label' }),
658
710
  __metadata("design:type", String)
659
- ], Payment.prototype, "privateLabel", void 0);
711
+ ], PaymentTransaction.prototype, "privateLabel", void 0);
660
712
  __decorate([
661
713
  Expose({ name: 'pix_qr_code' }),
662
714
  __metadata("design:type", String)
663
- ], Payment.prototype, "pixQrCode", void 0);
715
+ ], PaymentTransaction.prototype, "pixQrCode", void 0);
664
716
  __decorate([
665
717
  Expose({ name: 'pix_expiration_date' }),
666
718
  __metadata("design:type", String)
667
- ], Payment.prototype, "pixExpirationDate", void 0);
719
+ ], PaymentTransaction.prototype, "pixExpirationDate", void 0);
720
+
721
+ class Payment extends BaseModel {
722
+ static get identifiersFields() {
723
+ return ['id'];
724
+ }
725
+ }
726
+ __decorate([
727
+ Type(() => PaymentTransaction),
728
+ __metadata("design:type", PaymentTransaction)
729
+ ], Payment.prototype, "transaction", void 0);
668
730
 
669
731
  class SubscriptionPayment extends BaseModel {
670
732
  static get identifiersFields() {
@@ -2275,10 +2337,16 @@ var OrderStatus;
2275
2337
  class Order extends Checkout {
2276
2338
  }
2277
2339
  __decorate([
2278
- Type(() => Payment),
2279
- __metadata("design:type", Payment)
2340
+ Type(() => PaymentTransaction),
2341
+ __metadata("design:type", PaymentTransaction)
2280
2342
  ], Order.prototype, "payment", void 0);
2281
2343
 
2344
+ class OrderBlocked extends BaseModel {
2345
+ static get identifiersFields() {
2346
+ return ['id'];
2347
+ }
2348
+ }
2349
+
2282
2350
  class CheckoutSubscription extends BaseModel {
2283
2351
  static get identifiersFields() {
2284
2352
  return ['id'];
@@ -2301,6 +2369,591 @@ __decorate([
2301
2369
  __metadata("design:type", Coupon)
2302
2370
  ], CheckoutSubscription.prototype, "coupon", void 0);
2303
2371
 
2372
+ class BusinessError extends CustomError {
2373
+ constructor(message, additionalData, type = '') {
2374
+ super(message);
2375
+ this.additionalData = additionalData;
2376
+ this.type = type;
2377
+ }
2378
+ }
2379
+
2380
+ class DuplicatedResultsError extends CustomError {
2381
+ constructor(message) {
2382
+ super(message);
2383
+ }
2384
+ }
2385
+
2386
+ class FraudValidationError extends CustomError {
2387
+ constructor(message, additionalData) {
2388
+ super(message);
2389
+ this.additionalData = additionalData;
2390
+ this.type = 'antifraud';
2391
+ }
2392
+ }
2393
+
2394
+ class InvalidArgumentError extends CustomError {
2395
+ constructor(message) {
2396
+ super(message);
2397
+ }
2398
+ }
2399
+
2400
+ class NotFoundError extends CustomError {
2401
+ constructor(message) {
2402
+ super(message);
2403
+ }
2404
+ }
2405
+
2406
+ class PaymentError extends CustomError {
2407
+ constructor(message, additionalData) {
2408
+ super(message);
2409
+ this.additionalData = additionalData;
2410
+ this.type = 'payment';
2411
+ }
2412
+ }
2413
+
2414
+ class RequiredArgumentError extends CustomError {
2415
+ constructor(args) {
2416
+ super(`Required arguments: ${args.join(', ')}`);
2417
+ this.args = args;
2418
+ this.arguments = args;
2419
+ }
2420
+ }
2421
+
2422
+ class StockLimitError extends BusinessError {
2423
+ constructor(message, additionalData) {
2424
+ super(message, additionalData);
2425
+ this.type = 'stock-limit';
2426
+ }
2427
+ }
2428
+
2429
+ class StockOutError extends BusinessError {
2430
+ constructor(message, additionalData) {
2431
+ super(message, additionalData);
2432
+ this.type = 'stock-out';
2433
+ }
2434
+ }
2435
+
2436
+ class AdyenCardService {
2437
+ constructor(credentials, paymentRepository, orderBlockedRepository) {
2438
+ this.credentials = credentials;
2439
+ this.paymentRepository = paymentRepository;
2440
+ this.orderBlockedRepository = orderBlockedRepository;
2441
+ }
2442
+ async pay(checkout, card) {
2443
+ try {
2444
+ const result = await axios({
2445
+ method: 'POST',
2446
+ url: this.credentials.URL_TRANSACTION,
2447
+ headers: {
2448
+ 'x-api-key': this.credentials.API_KEY,
2449
+ 'content-type': 'application/json',
2450
+ },
2451
+ data: this.createCardPayment(checkout, card),
2452
+ });
2453
+ if (result.data.resultCode !== 'Authorised') {
2454
+ this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
2455
+ return Promise.reject(new PaymentError(`Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito`, {
2456
+ checkoutId: checkout.id,
2457
+ userEmail: checkout.user.email,
2458
+ info: result.data,
2459
+ }));
2460
+ }
2461
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2462
+ createdAt: new Date(),
2463
+ updatedAt: new Date(),
2464
+ userId: checkout.user.id,
2465
+ checkoutId: checkout.id,
2466
+ totalPrice: checkout.totalPrice,
2467
+ paymentProvider: 'adyen',
2468
+ transaction: Object.assign(Object.assign({}, result.data), { status: 'paid' }),
2469
+ }));
2470
+ return payment;
2471
+ }
2472
+ catch (error) {
2473
+ throw new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', {
2474
+ checkoutId: checkout.id,
2475
+ userEmail: checkout.user.email,
2476
+ info: error.message,
2477
+ });
2478
+ }
2479
+ }
2480
+ createCardPayment(checkout, card) {
2481
+ return {
2482
+ amount: {
2483
+ currency: 'BRL',
2484
+ value: ((checkout === null || checkout === void 0 ? void 0 : checkout.totalPrice) || 0) * 100,
2485
+ },
2486
+ paymentMethod: {
2487
+ type: 'scheme',
2488
+ storedPaymentMethodId: card.cardId,
2489
+ },
2490
+ reference: checkout.id,
2491
+ shopperInteraction: 'Ecommerce',
2492
+ merchantAccount: this.credentials.MERCHANT_ACCOUNT,
2493
+ shopperReference: checkout.user.id,
2494
+ recurringProcessingModel: 'CardOnFile',
2495
+ returnUrl: this.credentials.URL_POSTBACK,
2496
+ installments: {
2497
+ value: card.installments,
2498
+ },
2499
+ };
2500
+ }
2501
+ addCard() {
2502
+ throw new Error('Method not implemented.');
2503
+ }
2504
+ }
2505
+
2506
+ class AntifraudBankSlipService {
2507
+ constructor(orderBlockedRepository) {
2508
+ this.orderBlockedRepository = orderBlockedRepository;
2509
+ this.MAX_ORDER_VALUE = 5000;
2510
+ }
2511
+ async validate(checkout) {
2512
+ var _a, _b;
2513
+ if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber)) {
2514
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Boleto not authorized', 'Boleto', 'day');
2515
+ throw new FraudValidationError('Boleto não autorizado para cliente não assinante', {
2516
+ checkoutId: checkout.id,
2517
+ userEmail: checkout.user.email,
2518
+ info: {
2519
+ isSubscriber: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.isSubscriber,
2520
+ subtotal: checkout.subTotalPrice,
2521
+ total: checkout.totalPrice,
2522
+ },
2523
+ });
2524
+ }
2525
+ return true;
2526
+ }
2527
+ }
2528
+
2529
+ class AntifraudCardService {
2530
+ constructor(orderRepository, orderBlockedRepository) {
2531
+ this.orderRepository = orderRepository;
2532
+ this.orderBlockedRepository = orderBlockedRepository;
2533
+ this.LIMIT_ORDERS_DAY = 2;
2534
+ this.LIMIT_ORDERS_WEEK = 7;
2535
+ this.LIMIT_BLOCKED_ORDERS_DAY = 5;
2536
+ }
2537
+ async validate(checkout, card) {
2538
+ var _a, _b;
2539
+ if (!(await this.verifyBlockedOrderAttempts(checkout, card)))
2540
+ throw new FraudValidationError('Cliente com mais de 5 compras negadas/bloqueadas no dia', {
2541
+ checkoutId: checkout.id,
2542
+ userEmail: checkout.user.email,
2543
+ info: {
2544
+ isSubscriber: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber,
2545
+ subtotal: checkout.subTotalPrice,
2546
+ total: checkout.totalPrice,
2547
+ },
2548
+ });
2549
+ if (!(await this.verifyDayAndWeekOrders(checkout, card)))
2550
+ throw new FraudValidationError('Cliente tentando comprar mais de 2 vezes no dia ou 7 vezes na semana', {
2551
+ checkoutId: checkout.id,
2552
+ userEmail: checkout.user.email,
2553
+ info: {
2554
+ isSubscriber: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.isSubscriber,
2555
+ subtotal: checkout.subTotalPrice,
2556
+ total: checkout.totalPrice,
2557
+ },
2558
+ });
2559
+ return true;
2560
+ }
2561
+ async verifyBlockedOrderAttempts(checkout, card) {
2562
+ var _a, _b, _c, _d;
2563
+ const day = `${format(new Date(), 'YYYY-MM-DD')}T00:00:00`;
2564
+ const endOfDay = `${format(new Date(), 'YYYY-MM-DD')}T23:59:59`;
2565
+ const ordersBlockedWithCpf = await this.orderBlockedRepository
2566
+ .find({
2567
+ filters: {
2568
+ customer: { cpf: { operator: Where.EQUALS, value: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf } },
2569
+ date: [
2570
+ { operator: Where.GTE, value: new Date(day) },
2571
+ { operator: Where.LTE, value: new Date(endOfDay) },
2572
+ ],
2573
+ },
2574
+ })
2575
+ .then((data) => data.data);
2576
+ const ordersBlockedWithEmail = await this.orderBlockedRepository
2577
+ .find({
2578
+ filters: {
2579
+ customer: { email: { operator: Where.EQUALS, value: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email } },
2580
+ date: [
2581
+ { operator: Where.GTE, value: new Date(day) },
2582
+ { operator: Where.LTE, value: new Date(endOfDay) },
2583
+ ],
2584
+ },
2585
+ })
2586
+ .then((data) => data.data);
2587
+ const ordersBlockedWithCep = await this.orderBlockedRepository
2588
+ .find({
2589
+ filters: {
2590
+ customer: { shippingAddress: { zip: { operator: Where.EQUALS, value: (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip } } },
2591
+ date: [
2592
+ { operator: Where.GTE, value: new Date(day) },
2593
+ { operator: Where.LTE, value: new Date(endOfDay) },
2594
+ ],
2595
+ },
2596
+ })
2597
+ .then((data) => data.data);
2598
+ const ordersBlockedWithPhone = await this.orderBlockedRepository
2599
+ .find({
2600
+ filters: {
2601
+ customer: { phoneNumber: { operator: Where.EQUALS, value: (_d = checkout.user) === null || _d === void 0 ? void 0 : _d.phone } },
2602
+ date: [
2603
+ { operator: Where.GTE, value: new Date(day) },
2604
+ { operator: Where.LTE, value: new Date(endOfDay) },
2605
+ ],
2606
+ },
2607
+ })
2608
+ .then((data) => data.data);
2609
+ const blockedUniqueEmails = ordersBlockedWithEmail.filter((e) => {
2610
+ var _a;
2611
+ return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf);
2612
+ });
2613
+ const blockedUniqueCeps = ordersBlockedWithCep.filter((e) => {
2614
+ var _a, _b;
2615
+ return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf) && e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email);
2616
+ });
2617
+ const blockedUniquePhone = ordersBlockedWithPhone.filter((e) => {
2618
+ var _a, _b, _c, _d, _e, _f;
2619
+ return (e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf) &&
2620
+ e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email) &&
2621
+ ((_d = (_c = e.customer.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip) === null || _d === void 0 ? void 0 : _d.toString()) !== ((_f = (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.zip) === null || _f === void 0 ? void 0 : _f.toString()));
2622
+ });
2623
+ const blockedAttempts = ordersBlockedWithCpf
2624
+ .concat(blockedUniqueEmails)
2625
+ .concat(blockedUniqueCeps)
2626
+ .concat(blockedUniquePhone);
2627
+ if (blockedAttempts.length >= this.LIMIT_BLOCKED_ORDERS_DAY) {
2628
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'More than 5 attempts have failed', 'Failed attempts', 'day', card || null);
2629
+ return false;
2630
+ }
2631
+ return true;
2632
+ }
2633
+ async verifyDayAndWeekOrders(checkout, card) {
2634
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2635
+ const ordersPerDay = await this.validateOrdersByRange((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf, (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email, (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.phone, (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.zip, card, this.getDateRange('day'));
2636
+ for (const key in ordersPerDay) {
2637
+ if (ordersPerDay[key] > this.LIMIT_ORDERS_DAY) {
2638
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'day');
2639
+ return false;
2640
+ }
2641
+ }
2642
+ const ordersPerWeek = await this.validateOrdersByRange((_e = checkout.user) === null || _e === void 0 ? void 0 : _e.cpf, (_f = checkout.user) === null || _f === void 0 ? void 0 : _f.email, (_g = checkout.user) === null || _g === void 0 ? void 0 : _g.phone, (_h = checkout.shippingAddress) === null || _h === void 0 ? void 0 : _h.zip, card, this.getDateRange('week'));
2643
+ for (const key in ordersPerWeek) {
2644
+ if (ordersPerDay[key] > this.LIMIT_ORDERS_WEEK) {
2645
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'week');
2646
+ return false;
2647
+ }
2648
+ }
2649
+ return true;
2650
+ }
2651
+ async validateOrdersByRange(cpf, email, phone, zip, card, range) {
2652
+ const ordersCpf = await this.countOrdersByField('user', 'cpf', cpf, range);
2653
+ const ordersByEmail = await this.countOrdersByField('user', 'email', email, range);
2654
+ const ordersByPhone = await this.countOrdersByField('user', 'phone', phone, range);
2655
+ const ordersByZip = await this.countOrdersByField('shippingAddress', 'zip', zip, range);
2656
+ return {
2657
+ cpf: ordersCpf,
2658
+ email: ordersByEmail,
2659
+ phone: ordersByPhone,
2660
+ zip: ordersByZip,
2661
+ };
2662
+ }
2663
+ async countOrdersByField(property, field, value, range) {
2664
+ const filters = {
2665
+ [property]: {
2666
+ [field]: value,
2667
+ },
2668
+ ['createdAt']: [
2669
+ { operator: Where.GTE, value: range.firstDate },
2670
+ { operator: Where.LTE, value: range.lastDate },
2671
+ ],
2672
+ };
2673
+ const docs = await (await this.orderRepository.find({ filters })).count;
2674
+ return docs;
2675
+ }
2676
+ getDateRange(range = 'day') {
2677
+ switch (range) {
2678
+ case 'day':
2679
+ return {
2680
+ firstDate: startOfDay(new Date()).getTime(),
2681
+ lastDate: endOfDay(new Date()).getTime(),
2682
+ };
2683
+ case 'week':
2684
+ return {
2685
+ firstDate: startOfDay(subDays(new Date(), 7)).getTime(),
2686
+ lastDate: endOfDay(new Date()).getTime(),
2687
+ };
2688
+ default:
2689
+ return {
2690
+ firstDate: startOfDay(new Date()).getTime(),
2691
+ lastDate: endOfDay(new Date()).getTime(),
2692
+ };
2693
+ }
2694
+ }
2695
+ }
2696
+
2697
+ class AntifraudGlampointsService {
2698
+ constructor() { }
2699
+ async validate(checkout) {
2700
+ return true;
2701
+ }
2702
+ }
2703
+
2704
+ class AntifraudPixService {
2705
+ constructor() { }
2706
+ async validate(checkout) {
2707
+ return true;
2708
+ }
2709
+ }
2710
+
2711
+ class GlampointsPaymentService {
2712
+ constructor(paymentRepository) {
2713
+ this.paymentRepository = paymentRepository;
2714
+ }
2715
+ async pay(checkout) {
2716
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2717
+ createdAt: new Date(),
2718
+ updatedAt: new Date(),
2719
+ userId: checkout.user.id,
2720
+ checkoutId: checkout.id,
2721
+ totalPrice: checkout.totalPrice,
2722
+ paymentProvider: 'glampoints',
2723
+ transaction: {
2724
+ amount: 0,
2725
+ acquirerResponseCode: '0000',
2726
+ acquirerName: 'glampoints',
2727
+ authorizedAmount: 0,
2728
+ captureMethod: 'ecommerce',
2729
+ installments: 1,
2730
+ cost: 0,
2731
+ paidAmount: 0,
2732
+ paymentMethod: 'glampoints',
2733
+ referer: 'api_key',
2734
+ refundedAmount: 0,
2735
+ status: 'paid',
2736
+ statusReason: 'acquirer',
2737
+ },
2738
+ }));
2739
+ return payment;
2740
+ }
2741
+ }
2742
+
2743
+ class PagarmeBankSlipService {
2744
+ constructor(credentials, paymentRepository) {
2745
+ this.credentials = credentials;
2746
+ this.paymentRepository = paymentRepository;
2747
+ }
2748
+ async pay(checkout) {
2749
+ try {
2750
+ const result = await axios({
2751
+ method: 'POST',
2752
+ url: this.credentials.URL_TRANSACTION,
2753
+ data: this.createBoletoPayment(checkout),
2754
+ });
2755
+ if (result.data.status !== 'processing') {
2756
+ return Promise.reject(new PaymentError(`Houve uma falha ao gerar o boleto. Tente novamente`, {
2757
+ checkoutId: checkout.id,
2758
+ userEmail: checkout.user.email,
2759
+ info: result.data,
2760
+ }));
2761
+ }
2762
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2763
+ createdAt: new Date(),
2764
+ updatedAt: new Date(),
2765
+ userId: checkout.user.id,
2766
+ checkoutId: checkout.id,
2767
+ totalPrice: checkout.totalPrice,
2768
+ paymentProvider: 'pagarMe',
2769
+ transaction: result.data,
2770
+ }));
2771
+ return payment;
2772
+ }
2773
+ catch (error) {
2774
+ throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
2775
+ checkoutId: checkout.id,
2776
+ userEmail: checkout.user.email,
2777
+ info: error.response.data,
2778
+ });
2779
+ }
2780
+ }
2781
+ createBoletoPayment(checkout) {
2782
+ return {
2783
+ api_key: this.credentials.API_KEY,
2784
+ amount: Math.floor(checkout.totalPrice * 100),
2785
+ boleto_rules: ['strict_expiration_date'],
2786
+ boleto_instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
2787
+ boleto_expiration_date: format(addDays(new Date(), 3), 'yyyy-MM-dd'),
2788
+ payment_method: 'boleto',
2789
+ postback_url: this.credentials.URL_POSTBACK,
2790
+ customer: {
2791
+ external_id: checkout.user.id,
2792
+ type: 'individual',
2793
+ country: 'br',
2794
+ name: checkout.user.displayName,
2795
+ documents: [
2796
+ {
2797
+ type: 'cpf',
2798
+ number: checkout.user.cpf,
2799
+ },
2800
+ ],
2801
+ },
2802
+ };
2803
+ }
2804
+ }
2805
+
2806
+ class PagarmeCardService {
2807
+ constructor(credentials, paymentRepository, orderBlockedRepository) {
2808
+ this.credentials = credentials;
2809
+ this.paymentRepository = paymentRepository;
2810
+ this.orderBlockedRepository = orderBlockedRepository;
2811
+ }
2812
+ async pay(checkout, card) {
2813
+ var _a;
2814
+ try {
2815
+ const result = await axios({
2816
+ method: 'POST',
2817
+ url: this.credentials.URL_TRANSACTION,
2818
+ data: this.createCardPayment(checkout, card),
2819
+ });
2820
+ if (result.data.status !== 'paid') {
2821
+ this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
2822
+ return Promise.reject(new PaymentError(`Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito`, {
2823
+ checkoutId: checkout.id,
2824
+ userEmail: checkout.user.email,
2825
+ info: result.data,
2826
+ }));
2827
+ }
2828
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2829
+ createdAt: new Date(),
2830
+ updatedAt: new Date(),
2831
+ userId: checkout.user.id,
2832
+ checkoutId: checkout.id,
2833
+ totalPrice: checkout.totalPrice,
2834
+ paymentProvider: 'pagarMe',
2835
+ transaction: result.data,
2836
+ }));
2837
+ return payment;
2838
+ }
2839
+ catch (error) {
2840
+ throw new PaymentError('Seu pagamento com cartão não foi autorizado. Para não perder seus produtos, pague com PIX ou outro cartão de crédito', {
2841
+ checkoutId: checkout.id,
2842
+ userEmail: checkout.user.email,
2843
+ info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
2844
+ });
2845
+ }
2846
+ }
2847
+ addCard() {
2848
+ throw new Error('Method not implemented.');
2849
+ }
2850
+ createCardPayment(checkout, card) {
2851
+ var _a, _b, _c, _d, _e, _f;
2852
+ return {
2853
+ api_key: this.credentials.API_KEY,
2854
+ amount: Math.floor(checkout.totalPrice * 100),
2855
+ card_id: card.cardId,
2856
+ payment_method: 'credit_card',
2857
+ installments: card.installments,
2858
+ soft_descriptor: checkout.shop,
2859
+ customer: {
2860
+ external_id: checkout.user.id,
2861
+ name: checkout.user.displayName,
2862
+ type: 'individual',
2863
+ country: 'br',
2864
+ email: checkout.user.email,
2865
+ phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
2866
+ documents: [
2867
+ {
2868
+ type: 'cpf',
2869
+ number: checkout.user.cpf,
2870
+ },
2871
+ ],
2872
+ },
2873
+ billing: {
2874
+ name: checkout.user.displayName,
2875
+ address: {
2876
+ country: 'br',
2877
+ state: checkout.billingAddress ? checkout.billingAddress.state : (_a = checkout.shippingAddress) === null || _a === void 0 ? void 0 : _a.state,
2878
+ city: checkout.billingAddress ? checkout.billingAddress.city : (_b = checkout.shippingAddress) === null || _b === void 0 ? void 0 : _b.city,
2879
+ neighborhood: checkout.billingAddress ? checkout.billingAddress.district : (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.district,
2880
+ street: checkout.billingAddress ? checkout.billingAddress.street : (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.street,
2881
+ street_number: checkout.billingAddress ? checkout.billingAddress.number : (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.number,
2882
+ zipcode: checkout.billingAddress
2883
+ ? checkout.billingAddress.zip.replace('-', '')
2884
+ : (_f = checkout.shippingAddress) === null || _f === void 0 ? void 0 : _f.zip.replace('-', ''),
2885
+ },
2886
+ },
2887
+ items: checkout.lineItems.map((item) => {
2888
+ return {
2889
+ id: item.id,
2890
+ title: checkout.user.isSubscriber ? `${item.name} - ASSINANTE` : item.name,
2891
+ unit_price: Math.floor(item.pricePaid * 100),
2892
+ quantity: item.quantity,
2893
+ tangible: true,
2894
+ };
2895
+ }),
2896
+ };
2897
+ }
2898
+ }
2899
+
2900
+ class PagarmePixService {
2901
+ constructor(credentials, paymentRepository) {
2902
+ this.credentials = credentials;
2903
+ this.paymentRepository = paymentRepository;
2904
+ }
2905
+ async pay(checkout) {
2906
+ var _a;
2907
+ try {
2908
+ const result = await axios({
2909
+ method: 'POST',
2910
+ url: this.credentials.URL_TRANSACTION,
2911
+ data: this.createPixPayment(checkout),
2912
+ });
2913
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2914
+ createdAt: new Date(),
2915
+ updatedAt: new Date(),
2916
+ userId: checkout.user.id,
2917
+ checkoutId: checkout.id,
2918
+ totalPrice: checkout.totalPrice,
2919
+ paymentProvider: 'pagarMe',
2920
+ transaction: result.data,
2921
+ }));
2922
+ return payment;
2923
+ }
2924
+ catch (error) {
2925
+ throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
2926
+ checkoutId: checkout.id,
2927
+ userEmail: checkout.user.email,
2928
+ info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
2929
+ });
2930
+ }
2931
+ }
2932
+ createPixPayment(checkout) {
2933
+ return {
2934
+ payment_method: 'pix',
2935
+ amount: Math.floor(checkout.totalPrice * 100),
2936
+ api_key: this.credentials.API_KEY,
2937
+ postback_url: this.credentials.URL_POSTBACK,
2938
+ pix_expiration_date: format(addDays(new Date(), 1), 'yyyy-MM-dd'),
2939
+ customer: {
2940
+ external_id: checkout.user.id,
2941
+ type: 'individual',
2942
+ country: 'br',
2943
+ name: checkout.user.displayName,
2944
+ email: checkout.user.email.trim(),
2945
+ phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
2946
+ documents: [
2947
+ {
2948
+ type: 'cpf',
2949
+ number: checkout.user.cpf,
2950
+ },
2951
+ ],
2952
+ },
2953
+ };
2954
+ }
2955
+ }
2956
+
2304
2957
  class RoundProductPricesHelper {
2305
2958
  static roundProductPrices(product) {
2306
2959
  product.price.price = Number(product.price.price.toFixed(2));
@@ -2315,6 +2968,12 @@ class RoundProductPricesHelper {
2315
2968
  }
2316
2969
  }
2317
2970
 
2971
+ class Sequence extends BaseModel {
2972
+ static get identifiersFields() {
2973
+ return ['id'];
2974
+ }
2975
+ }
2976
+
2318
2977
  var FilterType;
2319
2978
  (function (FilterType) {
2320
2979
  FilterType["ACCESSORY_IMPORTANCE"] = "accessoryImportance";
@@ -2453,36 +3112,10 @@ class ShopSettings extends BaseModel {
2453
3112
  }
2454
3113
  }
2455
3114
 
2456
- class InvalidArgumentError extends CustomError {
2457
- constructor(message) {
2458
- super(message);
2459
- }
2460
- }
2461
-
2462
- class RequiredArgumentError extends CustomError {
2463
- constructor(args) {
2464
- super(`Required arguments: ${args.join(', ')}`);
2465
- this.args = args;
2466
- this.arguments = args;
2467
- }
2468
- }
2469
-
2470
- class NotFoundError extends CustomError {
2471
- constructor(message) {
2472
- super(message);
2473
- }
2474
- }
2475
-
2476
- class DuplicatedResultsError extends CustomError {
2477
- constructor(message) {
2478
- super(message);
2479
- }
2480
- }
2481
-
2482
- class AxiosAdapter {
2483
- constructor(config) {
2484
- this.config = config;
2485
- this.logger = DebugHelper.from(this);
3115
+ class AxiosAdapter {
3116
+ constructor(config) {
3117
+ this.config = config;
3118
+ this.logger = DebugHelper.from(this);
2486
3119
  }
2487
3120
  async get(index, id) {
2488
3121
  const logger = this.logger.with('get');
@@ -3171,180 +3804,6 @@ const withCrudFirestore = (MixinBase) => {
3171
3804
  };
3172
3805
  };
3173
3806
 
3174
- class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3175
- constructor({ firestore, interceptors }) {
3176
- super({
3177
- firestore,
3178
- collectionName: 'leads',
3179
- model: Lead,
3180
- interceptors,
3181
- });
3182
- }
3183
- }
3184
-
3185
- class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3186
- constructor({ firestore, interceptors }, parentRepository) {
3187
- super({
3188
- firestore,
3189
- collectionName: 'editions',
3190
- parentIdField: 'subscriptionId',
3191
- model: Edition,
3192
- interceptors,
3193
- });
3194
- this.parentRepository = parentRepository;
3195
- }
3196
- }
3197
-
3198
- class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3199
- constructor({ firestore, interceptors, }) {
3200
- super({
3201
- firestore,
3202
- collectionName: 'subscription',
3203
- model: Subscription,
3204
- interceptors,
3205
- });
3206
- }
3207
- }
3208
-
3209
- class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3210
- constructor({ firestore, interceptors }) {
3211
- super({
3212
- firestore,
3213
- collectionName: 'subscriptionMaterialization',
3214
- model: SubscriptionMaterialization,
3215
- interceptors,
3216
- });
3217
- }
3218
- }
3219
-
3220
- class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3221
- constructor({ firestore, interceptors }, parentRepository) {
3222
- super({
3223
- firestore,
3224
- collectionName: 'payments',
3225
- parentIdField: 'subscriptionId',
3226
- model: SubscriptionPayment,
3227
- interceptors,
3228
- });
3229
- this.parentRepository = parentRepository;
3230
- }
3231
- }
3232
-
3233
- class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3234
- constructor({ firestore, interceptors, }) {
3235
- super({
3236
- firestore,
3237
- collectionName: 'subscriptionSummary',
3238
- model: SubscriptionSummary,
3239
- interceptors,
3240
- });
3241
- }
3242
- }
3243
-
3244
- class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3245
- constructor({ firestore, interceptors }, parentRepository) {
3246
- super({
3247
- firestore,
3248
- collectionName: 'address',
3249
- parentIdField: 'userId',
3250
- model: UserAddress,
3251
- interceptors,
3252
- });
3253
- this.parentRepository = parentRepository;
3254
- }
3255
- }
3256
-
3257
- class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3258
- constructor({ firestore, interceptors }, parentRepository) {
3259
- super({
3260
- firestore,
3261
- collectionName: 'CX',
3262
- parentIdField: 'userId',
3263
- model: BeautyProfile,
3264
- interceptors,
3265
- });
3266
- this.parentRepository = parentRepository;
3267
- }
3268
- }
3269
-
3270
- class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3271
- constructor({ firestore, interceptors }) {
3272
- super({
3273
- firestore,
3274
- collectionName: 'users',
3275
- model: User,
3276
- interceptors,
3277
- });
3278
- }
3279
- async get(identifiers) {
3280
- const user = await super.get({ id: identifiers.id });
3281
- user.beautyProfile = await this.getBeautyProfile(user.id);
3282
- user.isSubscriber = await this.checkIfIsSubscriber(user.id);
3283
- return user;
3284
- }
3285
- async checkIfExistsByField(field, value) {
3286
- const result = await this.find({ filters: { [field]: value } });
3287
- return result.count > 0;
3288
- }
3289
- buildModelInstance() {
3290
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3291
- return {
3292
- toFirestore: (data) => {
3293
- const plain = toFirestore(data);
3294
- delete plain.isSubscriber;
3295
- return plain;
3296
- },
3297
- fromFirestore,
3298
- };
3299
- }
3300
- async getBeautyProfile(userId) {
3301
- const beautyProfile = await this.firestore
3302
- .getCollection(`${this.collectionName}/${userId}/CX`)
3303
- .withConverter(this.buildBeautyProfileModelInstance())
3304
- .getDoc('beautyProfile')
3305
- .get();
3306
- return beautyProfile.data();
3307
- }
3308
- async checkIfIsSubscriber(userId) {
3309
- const docs = await this.collection('subscription')
3310
- .where('user.id', '==', userId)
3311
- .where('status', '==', 'active')
3312
- .getDocs();
3313
- return !!docs && !!docs.size;
3314
- }
3315
- buildBeautyProfileModelInstance() {
3316
- return {
3317
- toFirestore: (data) => data.toPlain(),
3318
- fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
3319
- };
3320
- }
3321
- }
3322
- __decorate([
3323
- Log(),
3324
- __metadata("design:type", Function),
3325
- __metadata("design:paramtypes", [Object]),
3326
- __metadata("design:returntype", Promise)
3327
- ], UserFirestoreRepository.prototype, "get", null);
3328
- __decorate([
3329
- Log(),
3330
- __metadata("design:type", Function),
3331
- __metadata("design:paramtypes", [String, String]),
3332
- __metadata("design:returntype", Promise)
3333
- ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
3334
-
3335
- class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3336
- constructor({ firestore, interceptors }, parentRepository) {
3337
- super({
3338
- firestore,
3339
- collectionName: 'payment_method',
3340
- parentIdField: 'userId',
3341
- model: UserPaymentMethod,
3342
- interceptors,
3343
- });
3344
- this.parentRepository = parentRepository;
3345
- }
3346
- }
3347
-
3348
3807
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3349
3808
  constructor({ firestore, interceptors }) {
3350
3809
  super({
@@ -3529,6 +3988,101 @@ class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpe
3529
3988
  }
3530
3989
  }
3531
3990
 
3991
+ class SequenceFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3992
+ constructor({ firestore, interceptors }) {
3993
+ super({
3994
+ firestore,
3995
+ collectionName: 'sequences',
3996
+ model: Sequence,
3997
+ interceptors,
3998
+ });
3999
+ }
4000
+ }
4001
+
4002
+ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4003
+ constructor({ firestore, interceptors }) {
4004
+ super({
4005
+ firestore,
4006
+ collectionName: 'dms',
4007
+ model: Home,
4008
+ interceptors,
4009
+ });
4010
+ this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
4011
+ var _a, _b, _c;
4012
+ return ({
4013
+ category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
4014
+ ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
4015
+ : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
4016
+ products: ((_c = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.products) === null || _c === void 0 ? void 0 : _c.map((product) => ((product === null || product === void 0 ? void 0 : product.toPlain) ? product === null || product === void 0 ? void 0 : product.toPlain() : product)).filter(Boolean)) || [],
4017
+ });
4018
+ };
4019
+ this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
4020
+ var _a;
4021
+ return ({
4022
+ category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
4023
+ products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
4024
+ });
4025
+ };
4026
+ }
4027
+ buildModelInstance() {
4028
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
4029
+ return {
4030
+ toFirestore: (data) => {
4031
+ const modifiedData = this.homeToFirestore(data);
4032
+ return toFirestore(modifiedData);
4033
+ },
4034
+ fromFirestore: (snap) => {
4035
+ const instance = fromFirestore(snap);
4036
+ return this.homeFromFirestore(instance);
4037
+ },
4038
+ };
4039
+ }
4040
+ homeToFirestore(home) {
4041
+ var _a, _b, _c, _d;
4042
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
4043
+ home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
4044
+ home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
4045
+ home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
4046
+ }
4047
+ return home;
4048
+ }
4049
+ homeFromFirestore(home) {
4050
+ var _a;
4051
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
4052
+ home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
4053
+ home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
4054
+ home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
4055
+ home.data.createdAt =
4056
+ home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
4057
+ home.data.expiresAt =
4058
+ home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
4059
+ }
4060
+ return home;
4061
+ }
4062
+ }
4063
+
4064
+ class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4065
+ constructor({ firestore, interceptors }) {
4066
+ super({
4067
+ firestore,
4068
+ collectionName: 'shopMenus',
4069
+ model: ShopMenu,
4070
+ interceptors,
4071
+ });
4072
+ }
4073
+ }
4074
+
4075
+ class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4076
+ constructor({ firestore, interceptors, }) {
4077
+ super({
4078
+ firestore,
4079
+ collectionName: 'shopSettings',
4080
+ model: ShopSettings,
4081
+ interceptors,
4082
+ });
4083
+ }
4084
+ }
4085
+
3532
4086
  class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3533
4087
  constructor({ firestore, interceptors }) {
3534
4088
  super({
@@ -3659,6 +4213,47 @@ class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
3659
4213
  }
3660
4214
  }
3661
4215
 
4216
+ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4217
+ constructor({ firestore, interceptors, }) {
4218
+ super({
4219
+ firestore,
4220
+ collectionName: 'paymentBlockedAttempts',
4221
+ model: OrderBlocked,
4222
+ interceptors,
4223
+ });
4224
+ }
4225
+ async createBlockedOrderOrPayment(checkout, blockType, type, limiteRange, card = null) {
4226
+ var _a, _b, _c, _d, _e, _f, _g, _h;
4227
+ return this.create(OrderBlocked.toInstance({
4228
+ customer: {
4229
+ name: ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.displayName) || '',
4230
+ cpf: ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.cpf) || '',
4231
+ id: (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.id,
4232
+ email: ((_d = checkout.user) === null || _d === void 0 ? void 0 : _d.email) || '',
4233
+ phoneNumber: '+55' + ((_e = checkout.user) === null || _e === void 0 ? void 0 : _e.phone),
4234
+ isSubscriber: (_f = checkout.user) === null || _f === void 0 ? void 0 : _f.isSubscriber,
4235
+ subscriptionPlan: ((_g = checkout.user) === null || _g === void 0 ? void 0 : _g.subscriptionPlan) || '',
4236
+ shippingAddress: Object.assign(Object.assign({}, checkout.shippingAddress), { zip: this.formatZip((_h = checkout.shippingAddress) === null || _h === void 0 ? void 0 : _h.zip) }),
4237
+ },
4238
+ blockType,
4239
+ limiteRange,
4240
+ type,
4241
+ card,
4242
+ checkout: {
4243
+ id: checkout.id,
4244
+ shop: checkout.shop,
4245
+ total: checkout.totalPrice,
4246
+ },
4247
+ date: new Date(),
4248
+ }));
4249
+ }
4250
+ formatZip(zip) {
4251
+ if (zip.length === 8)
4252
+ return zip.substring(0, 5) + '-' + zip.substring(5, 8);
4253
+ return zip;
4254
+ }
4255
+ }
4256
+
3662
4257
  class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3663
4258
  constructor({ firestore, interceptors }) {
3664
4259
  super({
@@ -3681,87 +4276,177 @@ class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(
3681
4276
  }
3682
4277
  }
3683
4278
 
3684
- class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4279
+ class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3685
4280
  constructor({ firestore, interceptors }) {
3686
4281
  super({
3687
4282
  firestore,
3688
- collectionName: 'dms',
3689
- model: Home,
4283
+ collectionName: 'leads',
4284
+ model: Lead,
3690
4285
  interceptors,
3691
4286
  });
3692
- this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
3693
- var _a, _b, _c;
3694
- return ({
3695
- category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
3696
- ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
3697
- : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
3698
- products: ((_c = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.products) === null || _c === void 0 ? void 0 : _c.map((product) => ((product === null || product === void 0 ? void 0 : product.toPlain) ? product === null || product === void 0 ? void 0 : product.toPlain() : product)).filter(Boolean)) || [],
3699
- });
3700
- };
3701
- this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
3702
- var _a;
3703
- return ({
3704
- category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
3705
- products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
3706
- });
3707
- };
3708
- }
3709
- buildModelInstance() {
3710
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3711
- return {
3712
- toFirestore: (data) => {
3713
- const modifiedData = this.homeToFirestore(data);
3714
- return toFirestore(modifiedData);
3715
- },
3716
- fromFirestore: (snap) => {
3717
- const instance = fromFirestore(snap);
3718
- return this.homeFromFirestore(instance);
3719
- },
3720
- };
3721
4287
  }
3722
- homeToFirestore(home) {
3723
- var _a, _b, _c, _d;
3724
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3725
- home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
3726
- home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
3727
- home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
3728
- }
3729
- return home;
4288
+ }
4289
+
4290
+ class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4291
+ constructor({ firestore, interceptors }, parentRepository) {
4292
+ super({
4293
+ firestore,
4294
+ collectionName: 'editions',
4295
+ parentIdField: 'subscriptionId',
4296
+ model: Edition,
4297
+ interceptors,
4298
+ });
4299
+ this.parentRepository = parentRepository;
3730
4300
  }
3731
- homeFromFirestore(home) {
3732
- var _a;
3733
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3734
- home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
3735
- home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
3736
- home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
3737
- home.data.createdAt =
3738
- home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
3739
- home.data.expiresAt =
3740
- home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
3741
- }
3742
- return home;
4301
+ }
4302
+
4303
+ class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4304
+ constructor({ firestore, interceptors, }) {
4305
+ super({
4306
+ firestore,
4307
+ collectionName: 'subscription',
4308
+ model: Subscription,
4309
+ interceptors,
4310
+ });
3743
4311
  }
3744
4312
  }
3745
4313
 
3746
- class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4314
+ class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3747
4315
  constructor({ firestore, interceptors }) {
3748
4316
  super({
3749
4317
  firestore,
3750
- collectionName: 'shopMenus',
3751
- model: ShopMenu,
4318
+ collectionName: 'subscriptionMaterialization',
4319
+ model: SubscriptionMaterialization,
3752
4320
  interceptors,
3753
4321
  });
3754
4322
  }
3755
4323
  }
3756
4324
 
3757
- class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4325
+ class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4326
+ constructor({ firestore, interceptors }, parentRepository) {
4327
+ super({
4328
+ firestore,
4329
+ collectionName: 'payments',
4330
+ parentIdField: 'subscriptionId',
4331
+ model: SubscriptionPayment,
4332
+ interceptors,
4333
+ });
4334
+ this.parentRepository = parentRepository;
4335
+ }
4336
+ }
4337
+
4338
+ class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3758
4339
  constructor({ firestore, interceptors, }) {
3759
4340
  super({
3760
4341
  firestore,
3761
- collectionName: 'shopSettings',
3762
- model: ShopSettings,
4342
+ collectionName: 'subscriptionSummary',
4343
+ model: SubscriptionSummary,
4344
+ interceptors,
4345
+ });
4346
+ }
4347
+ }
4348
+
4349
+ class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4350
+ constructor({ firestore, interceptors }, parentRepository) {
4351
+ super({
4352
+ firestore,
4353
+ collectionName: 'address',
4354
+ parentIdField: 'userId',
4355
+ model: UserAddress,
4356
+ interceptors,
4357
+ });
4358
+ this.parentRepository = parentRepository;
4359
+ }
4360
+ }
4361
+
4362
+ class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4363
+ constructor({ firestore, interceptors }, parentRepository) {
4364
+ super({
4365
+ firestore,
4366
+ collectionName: 'CX',
4367
+ parentIdField: 'userId',
4368
+ model: BeautyProfile,
4369
+ interceptors,
4370
+ });
4371
+ this.parentRepository = parentRepository;
4372
+ }
4373
+ }
4374
+
4375
+ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4376
+ constructor({ firestore, interceptors }) {
4377
+ super({
4378
+ firestore,
4379
+ collectionName: 'users',
4380
+ model: User,
4381
+ interceptors,
4382
+ });
4383
+ }
4384
+ async get(identifiers) {
4385
+ const user = await super.get({ id: identifiers.id });
4386
+ user.beautyProfile = await this.getBeautyProfile(user.id);
4387
+ user.isSubscriber = await this.checkIfIsSubscriber(user.id);
4388
+ return user;
4389
+ }
4390
+ async checkIfExistsByField(field, value) {
4391
+ const result = await this.find({ filters: { [field]: value } });
4392
+ return result.count > 0;
4393
+ }
4394
+ buildModelInstance() {
4395
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
4396
+ return {
4397
+ toFirestore: (data) => {
4398
+ const plain = toFirestore(data);
4399
+ delete plain.isSubscriber;
4400
+ return plain;
4401
+ },
4402
+ fromFirestore,
4403
+ };
4404
+ }
4405
+ async getBeautyProfile(userId) {
4406
+ const beautyProfile = await this.firestore
4407
+ .getCollection(`${this.collectionName}/${userId}/CX`)
4408
+ .withConverter(this.buildBeautyProfileModelInstance())
4409
+ .getDoc('beautyProfile')
4410
+ .get();
4411
+ return beautyProfile.data();
4412
+ }
4413
+ async checkIfIsSubscriber(userId) {
4414
+ const docs = await this.collection('subscription')
4415
+ .where('user.id', '==', userId)
4416
+ .where('status', '==', 'active')
4417
+ .getDocs();
4418
+ return !!docs && !!docs.size;
4419
+ }
4420
+ buildBeautyProfileModelInstance() {
4421
+ return {
4422
+ toFirestore: (data) => data.toPlain(),
4423
+ fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
4424
+ };
4425
+ }
4426
+ }
4427
+ __decorate([
4428
+ Log(),
4429
+ __metadata("design:type", Function),
4430
+ __metadata("design:paramtypes", [Object]),
4431
+ __metadata("design:returntype", Promise)
4432
+ ], UserFirestoreRepository.prototype, "get", null);
4433
+ __decorate([
4434
+ Log(),
4435
+ __metadata("design:type", Function),
4436
+ __metadata("design:paramtypes", [String, String]),
4437
+ __metadata("design:returntype", Promise)
4438
+ ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
4439
+
4440
+ class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4441
+ constructor({ firestore, interceptors }, parentRepository) {
4442
+ super({
4443
+ firestore,
4444
+ collectionName: 'payment_method',
4445
+ parentIdField: 'userId',
4446
+ model: UserPaymentMethod,
3763
4447
  interceptors,
3764
4448
  });
4449
+ this.parentRepository = parentRepository;
3765
4450
  }
3766
4451
  }
3767
4452
 
@@ -6256,4 +6941,4 @@ __decorate([
6256
6941
  __metadata("design:returntype", Promise)
6257
6942
  ], WishlistHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
6258
6943
 
6259
- export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, Plans, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductReviews, ProductReviewsHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, is, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
6944
+ export { AccessoryImportances, Address, AdyenCardService, AdyenPaymentMethodFactory, AntifraudBankSlipService, AntifraudCardService, AntifraudGlampointsService, AntifraudPixService, AntifraudProviderFactory, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, BusinessError, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, FraudValidationError, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderFirestoreRepository, OrderStatus, PagarmeBankSlipService, PagarmeCardService, PagarmePaymentMethodFactory, PagarmePixService, Payment, PaymentError, PaymentFirestoreRepository, PaymentProviderFactory, PaymentTransaction, PaymentType, Plans, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductReviews, ProductReviewsHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, StockLimitError, StockOutError, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, antifraudProviders, is, isDebuggable, isUUID, parseDateTime, paymentMethods, paymentProviders, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };