@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.cjs.js CHANGED
@@ -38,6 +38,65 @@ function _interopNamespace(e) {
38
38
  var tslib_1__namespace = /*#__PURE__*/_interopNamespace(tslib_1);
39
39
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
40
40
 
41
+ exports.antifraudProviders = void 0;
42
+ (function (antifraudProviders) {
43
+ antifraudProviders["BANKSLIP"] = "bankSlip";
44
+ antifraudProviders["CARD"] = "card";
45
+ antifraudProviders["PIX"] = "pix";
46
+ antifraudProviders["POINTS"] = "glampoints";
47
+ })(exports.antifraudProviders || (exports.antifraudProviders = {}));
48
+
49
+ exports.paymentMethods = void 0;
50
+ (function (paymentMethods) {
51
+ paymentMethods["CARD"] = "card";
52
+ paymentMethods["BANKSLIP"] = "bankSlip";
53
+ paymentMethods["PIX"] = "pix";
54
+ paymentMethods["POINTS"] = "glampoints";
55
+ })(exports.paymentMethods || (exports.paymentMethods = {}));
56
+
57
+ exports.paymentProviders = void 0;
58
+ (function (paymentProviders) {
59
+ paymentProviders["PAGARME"] = "pagarMe";
60
+ paymentProviders["ADYEN"] = "adyen";
61
+ paymentProviders["GLAMPOINTS"] = "glampoints";
62
+ })(exports.paymentProviders || (exports.paymentProviders = {}));
63
+
64
+ class BasePaymentMethodFactory {
65
+ constructor(methods) {
66
+ this.methods = methods;
67
+ }
68
+ build(method) {
69
+ return this.methods[method];
70
+ }
71
+ }
72
+
73
+ class AdyenPaymentMethodFactory extends BasePaymentMethodFactory {
74
+ }
75
+
76
+ class AntifraudProviderFactory {
77
+ constructor(antifraudProviders) {
78
+ this.antifraudProviders = antifraudProviders;
79
+ }
80
+ build(provider) {
81
+ return this.antifraudProviders[provider];
82
+ }
83
+ }
84
+
85
+ class GlampointsPaymentMethodFactory extends BasePaymentMethodFactory {
86
+ }
87
+
88
+ class PagarmePaymentMethodFactory extends BasePaymentMethodFactory {
89
+ }
90
+
91
+ class PaymentProviderFactory {
92
+ constructor(paymentProviders) {
93
+ this.paymentProviders = paymentProviders;
94
+ }
95
+ build(provider) {
96
+ return this.paymentProviders[provider];
97
+ }
98
+ }
99
+
41
100
  class BaseModel {
42
101
  get identifier() {
43
102
  const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
@@ -520,175 +579,178 @@ exports.Status = void 0;
520
579
  Status["CANCELLED"] = "Cancelado";
521
580
  })(exports.Status || (exports.Status = {}));
522
581
 
523
- class Payment extends BaseModel {
524
- static get identifiersFields() {
525
- return ['id'];
526
- }
582
+ class PaymentTransaction extends BaseModel {
527
583
  }
528
584
  tslib_1.__decorate([
529
585
  classTransformer.Expose({ name: 'refuse_reason' }),
530
586
  tslib_1.__metadata("design:type", String)
531
- ], Payment.prototype, "refuseReason", void 0);
587
+ ], PaymentTransaction.prototype, "refuseReason", void 0);
532
588
  tslib_1.__decorate([
533
589
  classTransformer.Expose({ name: 'status_reason' }),
534
590
  tslib_1.__metadata("design:type", String)
535
- ], Payment.prototype, "statusReason", void 0);
591
+ ], PaymentTransaction.prototype, "statusReason", void 0);
536
592
  tslib_1.__decorate([
537
593
  classTransformer.Expose({ name: 'acquirer_response_code' }),
538
594
  tslib_1.__metadata("design:type", String)
539
- ], Payment.prototype, "acquirerResponseCode", void 0);
595
+ ], PaymentTransaction.prototype, "acquirerResponseCode", void 0);
540
596
  tslib_1.__decorate([
541
597
  classTransformer.Expose({ name: 'acquirer_name' }),
542
598
  tslib_1.__metadata("design:type", String)
543
- ], Payment.prototype, "acquirerName", void 0);
599
+ ], PaymentTransaction.prototype, "acquirerName", void 0);
544
600
  tslib_1.__decorate([
545
601
  classTransformer.Expose({ name: 'acquirer_id' }),
546
602
  tslib_1.__metadata("design:type", String)
547
- ], Payment.prototype, "acquirerId", void 0);
603
+ ], PaymentTransaction.prototype, "acquirerId", void 0);
548
604
  tslib_1.__decorate([
549
605
  classTransformer.Expose({ name: 'authorization_code' }),
550
606
  tslib_1.__metadata("design:type", String)
551
- ], Payment.prototype, "authorizationCode", void 0);
607
+ ], PaymentTransaction.prototype, "authorizationCode", void 0);
552
608
  tslib_1.__decorate([
553
609
  classTransformer.Expose({ name: 'soft_descriptor' }),
554
610
  tslib_1.__metadata("design:type", String)
555
- ], Payment.prototype, "softDescriptor", void 0);
611
+ ], PaymentTransaction.prototype, "softDescriptor", void 0);
556
612
  tslib_1.__decorate([
557
613
  classTransformer.Expose({ name: 'date_created' }),
558
614
  tslib_1.__metadata("design:type", String)
559
- ], Payment.prototype, "dateCreated", void 0);
615
+ ], PaymentTransaction.prototype, "dateCreated", void 0);
560
616
  tslib_1.__decorate([
561
617
  classTransformer.Expose({ name: 'date_updated' }),
562
618
  tslib_1.__metadata("design:type", String)
563
- ], Payment.prototype, "dateUpdated", void 0);
619
+ ], PaymentTransaction.prototype, "dateUpdated", void 0);
564
620
  tslib_1.__decorate([
565
621
  classTransformer.Expose({ name: 'authorized_amount' }),
566
622
  tslib_1.__metadata("design:type", Number)
567
- ], Payment.prototype, "authorizedAmount", void 0);
623
+ ], PaymentTransaction.prototype, "authorizedAmount", void 0);
568
624
  tslib_1.__decorate([
569
625
  classTransformer.Expose({ name: 'paid_amount' }),
570
626
  tslib_1.__metadata("design:type", Number)
571
- ], Payment.prototype, "paidAmount", void 0);
572
- tslib_1.__decorate([
573
- classTransformer.Expose({ name: 'paid_at' }),
574
- tslib_1.__metadata("design:type", String)
575
- ], Payment.prototype, "paidAt", void 0);
627
+ ], PaymentTransaction.prototype, "paidAmount", void 0);
576
628
  tslib_1.__decorate([
577
629
  classTransformer.Expose({ name: 'refunded_amount' }),
578
630
  tslib_1.__metadata("design:type", Number)
579
- ], Payment.prototype, "refundedAmount", void 0);
631
+ ], PaymentTransaction.prototype, "refundedAmount", void 0);
580
632
  tslib_1.__decorate([
581
633
  classTransformer.Expose({ name: 'card_holder_name' }),
582
634
  tslib_1.__metadata("design:type", String)
583
- ], Payment.prototype, "cardHolderName", void 0);
635
+ ], PaymentTransaction.prototype, "cardHolderName", void 0);
584
636
  tslib_1.__decorate([
585
637
  classTransformer.Expose({ name: 'card_last_digits' }),
586
638
  tslib_1.__metadata("design:type", String)
587
- ], Payment.prototype, "cardLastDigits", void 0);
639
+ ], PaymentTransaction.prototype, "cardLastDigits", void 0);
588
640
  tslib_1.__decorate([
589
641
  classTransformer.Expose({ name: 'card_first_digits' }),
590
642
  tslib_1.__metadata("design:type", String)
591
- ], Payment.prototype, "cardFirstDigits", void 0);
643
+ ], PaymentTransaction.prototype, "cardFirstDigits", void 0);
592
644
  tslib_1.__decorate([
593
645
  classTransformer.Expose({ name: 'card_brand' }),
594
646
  tslib_1.__metadata("design:type", String)
595
- ], Payment.prototype, "cardBrand", void 0);
647
+ ], PaymentTransaction.prototype, "cardBrand", void 0);
596
648
  tslib_1.__decorate([
597
649
  classTransformer.Expose({ name: 'card_pin_mode' }),
598
650
  tslib_1.__metadata("design:type", String)
599
- ], Payment.prototype, "cardPinMode", void 0);
651
+ ], PaymentTransaction.prototype, "cardPinMode", void 0);
600
652
  tslib_1.__decorate([
601
653
  classTransformer.Expose({ name: 'card_magstripe_fallback' }),
602
654
  tslib_1.__metadata("design:type", Boolean)
603
- ], Payment.prototype, "cardMagstripeFallback", void 0);
655
+ ], PaymentTransaction.prototype, "cardMagstripeFallback", void 0);
604
656
  tslib_1.__decorate([
605
657
  classTransformer.Expose({ name: 'cvm_pin' }),
606
658
  tslib_1.__metadata("design:type", Boolean)
607
- ], Payment.prototype, "cvmPin", void 0);
659
+ ], PaymentTransaction.prototype, "cvmPin", void 0);
608
660
  tslib_1.__decorate([
609
661
  classTransformer.Expose({ name: 'postback_url' }),
610
662
  tslib_1.__metadata("design:type", String)
611
- ], Payment.prototype, "postbackUrl", void 0);
663
+ ], PaymentTransaction.prototype, "postbackUrl", void 0);
612
664
  tslib_1.__decorate([
613
665
  classTransformer.Expose({ name: 'payment_method' }),
614
666
  tslib_1.__metadata("design:type", String)
615
- ], Payment.prototype, "paymentMethod", void 0);
667
+ ], PaymentTransaction.prototype, "paymentMethod", void 0);
616
668
  tslib_1.__decorate([
617
669
  classTransformer.Expose({ name: 'capture_method' }),
618
670
  tslib_1.__metadata("design:type", String)
619
- ], Payment.prototype, "captureMethod", void 0);
671
+ ], PaymentTransaction.prototype, "captureMethod", void 0);
620
672
  tslib_1.__decorate([
621
673
  classTransformer.Expose({ name: 'antifraud_score' }),
622
674
  tslib_1.__metadata("design:type", String)
623
- ], Payment.prototype, "antifraudScore", void 0);
675
+ ], PaymentTransaction.prototype, "antifraudScore", void 0);
624
676
  tslib_1.__decorate([
625
677
  classTransformer.Expose({ name: 'boleto_url' }),
626
678
  tslib_1.__metadata("design:type", String)
627
- ], Payment.prototype, "boletoUrl", void 0);
679
+ ], PaymentTransaction.prototype, "boletoUrl", void 0);
628
680
  tslib_1.__decorate([
629
681
  classTransformer.Expose({ name: 'boleto_barcode' }),
630
682
  tslib_1.__metadata("design:type", String)
631
- ], Payment.prototype, "boletoBarcode", void 0);
683
+ ], PaymentTransaction.prototype, "boletoBarcode", void 0);
632
684
  tslib_1.__decorate([
633
685
  classTransformer.Expose({ name: 'boleto_expiration_date' }),
634
686
  tslib_1.__metadata("design:type", String)
635
- ], Payment.prototype, "boletoExpirationDate", void 0);
687
+ ], PaymentTransaction.prototype, "boletoExpirationDate", void 0);
636
688
  tslib_1.__decorate([
637
689
  classTransformer.Expose({ name: 'subscription_id' }),
638
690
  tslib_1.__metadata("design:type", String)
639
- ], Payment.prototype, "subscriptionId", void 0);
691
+ ], PaymentTransaction.prototype, "subscriptionId", void 0);
640
692
  tslib_1.__decorate([
641
693
  classTransformer.Expose({ name: 'split_rules' }),
642
694
  tslib_1.__metadata("design:type", String)
643
- ], Payment.prototype, "splitRules", void 0);
695
+ ], PaymentTransaction.prototype, "splitRules", void 0);
644
696
  tslib_1.__decorate([
645
697
  classTransformer.Expose({ name: 'antifraud_metadata' }),
646
698
  tslib_1.__metadata("design:type", Object)
647
- ], Payment.prototype, "antifraudMetadata", void 0);
699
+ ], PaymentTransaction.prototype, "antifraudMetadata", void 0);
648
700
  tslib_1.__decorate([
649
701
  classTransformer.Expose({ name: 'reference_key' }),
650
702
  tslib_1.__metadata("design:type", String)
651
- ], Payment.prototype, "referenceKey", void 0);
703
+ ], PaymentTransaction.prototype, "referenceKey", void 0);
652
704
  tslib_1.__decorate([
653
705
  classTransformer.Expose({ name: 'local_transaction_id' }),
654
706
  tslib_1.__metadata("design:type", String)
655
- ], Payment.prototype, "localTransactionId", void 0);
707
+ ], PaymentTransaction.prototype, "localTransactionId", void 0);
656
708
  tslib_1.__decorate([
657
709
  classTransformer.Expose({ name: 'local_time' }),
658
710
  tslib_1.__metadata("design:type", String)
659
- ], Payment.prototype, "localTime", void 0);
711
+ ], PaymentTransaction.prototype, "localTime", void 0);
660
712
  tslib_1.__decorate([
661
713
  classTransformer.Expose({ name: 'fraud_covered' }),
662
714
  tslib_1.__metadata("design:type", Boolean)
663
- ], Payment.prototype, "fraudCovered", void 0);
715
+ ], PaymentTransaction.prototype, "fraudCovered", void 0);
664
716
  tslib_1.__decorate([
665
717
  classTransformer.Expose({ name: 'fraud_reimbursed' }),
666
718
  tslib_1.__metadata("design:type", String)
667
- ], Payment.prototype, "fraudReimbursed", void 0);
719
+ ], PaymentTransaction.prototype, "fraudReimbursed", void 0);
668
720
  tslib_1.__decorate([
669
721
  classTransformer.Expose({ name: 'order_id' }),
670
722
  tslib_1.__metadata("design:type", String)
671
- ], Payment.prototype, "orderId", void 0);
723
+ ], PaymentTransaction.prototype, "orderId", void 0);
672
724
  tslib_1.__decorate([
673
725
  classTransformer.Expose({ name: 'risk_level' }),
674
726
  tslib_1.__metadata("design:type", String)
675
- ], Payment.prototype, "riskLevel", void 0);
727
+ ], PaymentTransaction.prototype, "riskLevel", void 0);
676
728
  tslib_1.__decorate([
677
729
  classTransformer.Expose({ name: 'receipt_url' }),
678
730
  tslib_1.__metadata("design:type", String)
679
- ], Payment.prototype, "receiptUrl", void 0);
731
+ ], PaymentTransaction.prototype, "receiptUrl", void 0);
680
732
  tslib_1.__decorate([
681
733
  classTransformer.Expose({ name: 'private_label' }),
682
734
  tslib_1.__metadata("design:type", String)
683
- ], Payment.prototype, "privateLabel", void 0);
735
+ ], PaymentTransaction.prototype, "privateLabel", void 0);
684
736
  tslib_1.__decorate([
685
737
  classTransformer.Expose({ name: 'pix_qr_code' }),
686
738
  tslib_1.__metadata("design:type", String)
687
- ], Payment.prototype, "pixQrCode", void 0);
739
+ ], PaymentTransaction.prototype, "pixQrCode", void 0);
688
740
  tslib_1.__decorate([
689
741
  classTransformer.Expose({ name: 'pix_expiration_date' }),
690
742
  tslib_1.__metadata("design:type", String)
691
- ], Payment.prototype, "pixExpirationDate", void 0);
743
+ ], PaymentTransaction.prototype, "pixExpirationDate", void 0);
744
+
745
+ class Payment extends BaseModel {
746
+ static get identifiersFields() {
747
+ return ['id'];
748
+ }
749
+ }
750
+ tslib_1.__decorate([
751
+ classTransformer.Type(() => PaymentTransaction),
752
+ tslib_1.__metadata("design:type", PaymentTransaction)
753
+ ], Payment.prototype, "transaction", void 0);
692
754
 
693
755
  class SubscriptionPayment extends BaseModel {
694
756
  static get identifiersFields() {
@@ -2299,10 +2361,16 @@ exports.OrderStatus = void 0;
2299
2361
  class Order extends Checkout {
2300
2362
  }
2301
2363
  tslib_1.__decorate([
2302
- classTransformer.Type(() => Payment),
2303
- tslib_1.__metadata("design:type", Payment)
2364
+ classTransformer.Type(() => PaymentTransaction),
2365
+ tslib_1.__metadata("design:type", PaymentTransaction)
2304
2366
  ], Order.prototype, "payment", void 0);
2305
2367
 
2368
+ class OrderBlocked extends BaseModel {
2369
+ static get identifiersFields() {
2370
+ return ['id'];
2371
+ }
2372
+ }
2373
+
2306
2374
  class CheckoutSubscription extends BaseModel {
2307
2375
  static get identifiersFields() {
2308
2376
  return ['id'];
@@ -2325,6 +2393,591 @@ tslib_1.__decorate([
2325
2393
  tslib_1.__metadata("design:type", Coupon)
2326
2394
  ], CheckoutSubscription.prototype, "coupon", void 0);
2327
2395
 
2396
+ class BusinessError extends tsCustomError.CustomError {
2397
+ constructor(message, additionalData, type = '') {
2398
+ super(message);
2399
+ this.additionalData = additionalData;
2400
+ this.type = type;
2401
+ }
2402
+ }
2403
+
2404
+ class DuplicatedResultsError extends tsCustomError.CustomError {
2405
+ constructor(message) {
2406
+ super(message);
2407
+ }
2408
+ }
2409
+
2410
+ class FraudValidationError extends tsCustomError.CustomError {
2411
+ constructor(message, additionalData) {
2412
+ super(message);
2413
+ this.additionalData = additionalData;
2414
+ this.type = 'antifraud';
2415
+ }
2416
+ }
2417
+
2418
+ class InvalidArgumentError extends tsCustomError.CustomError {
2419
+ constructor(message) {
2420
+ super(message);
2421
+ }
2422
+ }
2423
+
2424
+ class NotFoundError extends tsCustomError.CustomError {
2425
+ constructor(message) {
2426
+ super(message);
2427
+ }
2428
+ }
2429
+
2430
+ class PaymentError extends tsCustomError.CustomError {
2431
+ constructor(message, additionalData) {
2432
+ super(message);
2433
+ this.additionalData = additionalData;
2434
+ this.type = 'payment';
2435
+ }
2436
+ }
2437
+
2438
+ class RequiredArgumentError extends tsCustomError.CustomError {
2439
+ constructor(args) {
2440
+ super(`Required arguments: ${args.join(', ')}`);
2441
+ this.args = args;
2442
+ this.arguments = args;
2443
+ }
2444
+ }
2445
+
2446
+ class StockLimitError extends BusinessError {
2447
+ constructor(message, additionalData) {
2448
+ super(message, additionalData);
2449
+ this.type = 'stock-limit';
2450
+ }
2451
+ }
2452
+
2453
+ class StockOutError extends BusinessError {
2454
+ constructor(message, additionalData) {
2455
+ super(message, additionalData);
2456
+ this.type = 'stock-out';
2457
+ }
2458
+ }
2459
+
2460
+ class AdyenCardService {
2461
+ constructor(credentials, paymentRepository, orderBlockedRepository) {
2462
+ this.credentials = credentials;
2463
+ this.paymentRepository = paymentRepository;
2464
+ this.orderBlockedRepository = orderBlockedRepository;
2465
+ }
2466
+ async pay(checkout, card) {
2467
+ try {
2468
+ const result = await axios__default["default"]({
2469
+ method: 'POST',
2470
+ url: this.credentials.URL_TRANSACTION,
2471
+ headers: {
2472
+ 'x-api-key': this.credentials.API_KEY,
2473
+ 'content-type': 'application/json',
2474
+ },
2475
+ data: this.createCardPayment(checkout, card),
2476
+ });
2477
+ if (result.data.resultCode !== 'Authorised') {
2478
+ this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
2479
+ 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`, {
2480
+ checkoutId: checkout.id,
2481
+ userEmail: checkout.user.email,
2482
+ info: result.data,
2483
+ }));
2484
+ }
2485
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2486
+ createdAt: new Date(),
2487
+ updatedAt: new Date(),
2488
+ userId: checkout.user.id,
2489
+ checkoutId: checkout.id,
2490
+ totalPrice: checkout.totalPrice,
2491
+ paymentProvider: 'adyen',
2492
+ transaction: Object.assign(Object.assign({}, result.data), { status: 'paid' }),
2493
+ }));
2494
+ return payment;
2495
+ }
2496
+ catch (error) {
2497
+ 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', {
2498
+ checkoutId: checkout.id,
2499
+ userEmail: checkout.user.email,
2500
+ info: error.message,
2501
+ });
2502
+ }
2503
+ }
2504
+ createCardPayment(checkout, card) {
2505
+ return {
2506
+ amount: {
2507
+ currency: 'BRL',
2508
+ value: ((checkout === null || checkout === void 0 ? void 0 : checkout.totalPrice) || 0) * 100,
2509
+ },
2510
+ paymentMethod: {
2511
+ type: 'scheme',
2512
+ storedPaymentMethodId: card.cardId,
2513
+ },
2514
+ reference: checkout.id,
2515
+ shopperInteraction: 'Ecommerce',
2516
+ merchantAccount: this.credentials.MERCHANT_ACCOUNT,
2517
+ shopperReference: checkout.user.id,
2518
+ recurringProcessingModel: 'CardOnFile',
2519
+ returnUrl: this.credentials.URL_POSTBACK,
2520
+ installments: {
2521
+ value: card.installments,
2522
+ },
2523
+ };
2524
+ }
2525
+ addCard() {
2526
+ throw new Error('Method not implemented.');
2527
+ }
2528
+ }
2529
+
2530
+ class AntifraudBankSlipService {
2531
+ constructor(orderBlockedRepository) {
2532
+ this.orderBlockedRepository = orderBlockedRepository;
2533
+ this.MAX_ORDER_VALUE = 5000;
2534
+ }
2535
+ async validate(checkout) {
2536
+ var _a, _b;
2537
+ if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber)) {
2538
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Boleto not authorized', 'Boleto', 'day');
2539
+ throw new FraudValidationError('Boleto não autorizado para cliente não assinante', {
2540
+ checkoutId: checkout.id,
2541
+ userEmail: checkout.user.email,
2542
+ info: {
2543
+ isSubscriber: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.isSubscriber,
2544
+ subtotal: checkout.subTotalPrice,
2545
+ total: checkout.totalPrice,
2546
+ },
2547
+ });
2548
+ }
2549
+ return true;
2550
+ }
2551
+ }
2552
+
2553
+ class AntifraudCardService {
2554
+ constructor(orderRepository, orderBlockedRepository) {
2555
+ this.orderRepository = orderRepository;
2556
+ this.orderBlockedRepository = orderBlockedRepository;
2557
+ this.LIMIT_ORDERS_DAY = 2;
2558
+ this.LIMIT_ORDERS_WEEK = 7;
2559
+ this.LIMIT_BLOCKED_ORDERS_DAY = 5;
2560
+ }
2561
+ async validate(checkout, card) {
2562
+ var _a, _b;
2563
+ if (!(await this.verifyBlockedOrderAttempts(checkout, card)))
2564
+ throw new FraudValidationError('Cliente com mais de 5 compras negadas/bloqueadas no dia', {
2565
+ checkoutId: checkout.id,
2566
+ userEmail: checkout.user.email,
2567
+ info: {
2568
+ isSubscriber: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber,
2569
+ subtotal: checkout.subTotalPrice,
2570
+ total: checkout.totalPrice,
2571
+ },
2572
+ });
2573
+ if (!(await this.verifyDayAndWeekOrders(checkout, card)))
2574
+ throw new FraudValidationError('Cliente tentando comprar mais de 2 vezes no dia ou 7 vezes na semana', {
2575
+ checkoutId: checkout.id,
2576
+ userEmail: checkout.user.email,
2577
+ info: {
2578
+ isSubscriber: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.isSubscriber,
2579
+ subtotal: checkout.subTotalPrice,
2580
+ total: checkout.totalPrice,
2581
+ },
2582
+ });
2583
+ return true;
2584
+ }
2585
+ async verifyBlockedOrderAttempts(checkout, card) {
2586
+ var _a, _b, _c, _d;
2587
+ const day = `${dateFns.format(new Date(), 'YYYY-MM-DD')}T00:00:00`;
2588
+ const endOfDay = `${dateFns.format(new Date(), 'YYYY-MM-DD')}T23:59:59`;
2589
+ const ordersBlockedWithCpf = await this.orderBlockedRepository
2590
+ .find({
2591
+ filters: {
2592
+ customer: { cpf: { operator: exports.Where.EQUALS, value: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf } },
2593
+ date: [
2594
+ { operator: exports.Where.GTE, value: new Date(day) },
2595
+ { operator: exports.Where.LTE, value: new Date(endOfDay) },
2596
+ ],
2597
+ },
2598
+ })
2599
+ .then((data) => data.data);
2600
+ const ordersBlockedWithEmail = await this.orderBlockedRepository
2601
+ .find({
2602
+ filters: {
2603
+ customer: { email: { operator: exports.Where.EQUALS, value: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email } },
2604
+ date: [
2605
+ { operator: exports.Where.GTE, value: new Date(day) },
2606
+ { operator: exports.Where.LTE, value: new Date(endOfDay) },
2607
+ ],
2608
+ },
2609
+ })
2610
+ .then((data) => data.data);
2611
+ const ordersBlockedWithCep = await this.orderBlockedRepository
2612
+ .find({
2613
+ filters: {
2614
+ customer: { shippingAddress: { zip: { operator: exports.Where.EQUALS, value: (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip } } },
2615
+ date: [
2616
+ { operator: exports.Where.GTE, value: new Date(day) },
2617
+ { operator: exports.Where.LTE, value: new Date(endOfDay) },
2618
+ ],
2619
+ },
2620
+ })
2621
+ .then((data) => data.data);
2622
+ const ordersBlockedWithPhone = await this.orderBlockedRepository
2623
+ .find({
2624
+ filters: {
2625
+ customer: { phoneNumber: { operator: exports.Where.EQUALS, value: (_d = checkout.user) === null || _d === void 0 ? void 0 : _d.phone } },
2626
+ date: [
2627
+ { operator: exports.Where.GTE, value: new Date(day) },
2628
+ { operator: exports.Where.LTE, value: new Date(endOfDay) },
2629
+ ],
2630
+ },
2631
+ })
2632
+ .then((data) => data.data);
2633
+ const blockedUniqueEmails = ordersBlockedWithEmail.filter((e) => {
2634
+ var _a;
2635
+ return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf);
2636
+ });
2637
+ const blockedUniqueCeps = ordersBlockedWithCep.filter((e) => {
2638
+ var _a, _b;
2639
+ 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);
2640
+ });
2641
+ const blockedUniquePhone = ordersBlockedWithPhone.filter((e) => {
2642
+ var _a, _b, _c, _d, _e, _f;
2643
+ return (e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf) &&
2644
+ e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email) &&
2645
+ ((_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()));
2646
+ });
2647
+ const blockedAttempts = ordersBlockedWithCpf
2648
+ .concat(blockedUniqueEmails)
2649
+ .concat(blockedUniqueCeps)
2650
+ .concat(blockedUniquePhone);
2651
+ if (blockedAttempts.length >= this.LIMIT_BLOCKED_ORDERS_DAY) {
2652
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'More than 5 attempts have failed', 'Failed attempts', 'day', card || null);
2653
+ return false;
2654
+ }
2655
+ return true;
2656
+ }
2657
+ async verifyDayAndWeekOrders(checkout, card) {
2658
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2659
+ 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'));
2660
+ for (const key in ordersPerDay) {
2661
+ if (ordersPerDay[key] > this.LIMIT_ORDERS_DAY) {
2662
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'day');
2663
+ return false;
2664
+ }
2665
+ }
2666
+ 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'));
2667
+ for (const key in ordersPerWeek) {
2668
+ if (ordersPerDay[key] > this.LIMIT_ORDERS_WEEK) {
2669
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'week');
2670
+ return false;
2671
+ }
2672
+ }
2673
+ return true;
2674
+ }
2675
+ async validateOrdersByRange(cpf, email, phone, zip, card, range) {
2676
+ const ordersCpf = await this.countOrdersByField('user', 'cpf', cpf, range);
2677
+ const ordersByEmail = await this.countOrdersByField('user', 'email', email, range);
2678
+ const ordersByPhone = await this.countOrdersByField('user', 'phone', phone, range);
2679
+ const ordersByZip = await this.countOrdersByField('shippingAddress', 'zip', zip, range);
2680
+ return {
2681
+ cpf: ordersCpf,
2682
+ email: ordersByEmail,
2683
+ phone: ordersByPhone,
2684
+ zip: ordersByZip,
2685
+ };
2686
+ }
2687
+ async countOrdersByField(property, field, value, range) {
2688
+ const filters = {
2689
+ [property]: {
2690
+ [field]: value,
2691
+ },
2692
+ ['createdAt']: [
2693
+ { operator: exports.Where.GTE, value: range.firstDate },
2694
+ { operator: exports.Where.LTE, value: range.lastDate },
2695
+ ],
2696
+ };
2697
+ const docs = await (await this.orderRepository.find({ filters })).count;
2698
+ return docs;
2699
+ }
2700
+ getDateRange(range = 'day') {
2701
+ switch (range) {
2702
+ case 'day':
2703
+ return {
2704
+ firstDate: dateFns.startOfDay(new Date()).getTime(),
2705
+ lastDate: dateFns.endOfDay(new Date()).getTime(),
2706
+ };
2707
+ case 'week':
2708
+ return {
2709
+ firstDate: dateFns.startOfDay(dateFns.subDays(new Date(), 7)).getTime(),
2710
+ lastDate: dateFns.endOfDay(new Date()).getTime(),
2711
+ };
2712
+ default:
2713
+ return {
2714
+ firstDate: dateFns.startOfDay(new Date()).getTime(),
2715
+ lastDate: dateFns.endOfDay(new Date()).getTime(),
2716
+ };
2717
+ }
2718
+ }
2719
+ }
2720
+
2721
+ class AntifraudGlampointsService {
2722
+ constructor() { }
2723
+ async validate(checkout) {
2724
+ return true;
2725
+ }
2726
+ }
2727
+
2728
+ class AntifraudPixService {
2729
+ constructor() { }
2730
+ async validate(checkout) {
2731
+ return true;
2732
+ }
2733
+ }
2734
+
2735
+ class GlampointsPaymentService {
2736
+ constructor(paymentRepository) {
2737
+ this.paymentRepository = paymentRepository;
2738
+ }
2739
+ async pay(checkout) {
2740
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2741
+ createdAt: new Date(),
2742
+ updatedAt: new Date(),
2743
+ userId: checkout.user.id,
2744
+ checkoutId: checkout.id,
2745
+ totalPrice: checkout.totalPrice,
2746
+ paymentProvider: 'glampoints',
2747
+ transaction: {
2748
+ amount: 0,
2749
+ acquirerResponseCode: '0000',
2750
+ acquirerName: 'glampoints',
2751
+ authorizedAmount: 0,
2752
+ captureMethod: 'ecommerce',
2753
+ installments: 1,
2754
+ cost: 0,
2755
+ paidAmount: 0,
2756
+ paymentMethod: 'glampoints',
2757
+ referer: 'api_key',
2758
+ refundedAmount: 0,
2759
+ status: 'paid',
2760
+ statusReason: 'acquirer',
2761
+ },
2762
+ }));
2763
+ return payment;
2764
+ }
2765
+ }
2766
+
2767
+ class PagarmeBankSlipService {
2768
+ constructor(credentials, paymentRepository) {
2769
+ this.credentials = credentials;
2770
+ this.paymentRepository = paymentRepository;
2771
+ }
2772
+ async pay(checkout) {
2773
+ try {
2774
+ const result = await axios__default["default"]({
2775
+ method: 'POST',
2776
+ url: this.credentials.URL_TRANSACTION,
2777
+ data: this.createBoletoPayment(checkout),
2778
+ });
2779
+ if (result.data.status !== 'processing') {
2780
+ return Promise.reject(new PaymentError(`Houve uma falha ao gerar o boleto. Tente novamente`, {
2781
+ checkoutId: checkout.id,
2782
+ userEmail: checkout.user.email,
2783
+ info: result.data,
2784
+ }));
2785
+ }
2786
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2787
+ createdAt: new Date(),
2788
+ updatedAt: new Date(),
2789
+ userId: checkout.user.id,
2790
+ checkoutId: checkout.id,
2791
+ totalPrice: checkout.totalPrice,
2792
+ paymentProvider: 'pagarMe',
2793
+ transaction: result.data,
2794
+ }));
2795
+ return payment;
2796
+ }
2797
+ catch (error) {
2798
+ throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
2799
+ checkoutId: checkout.id,
2800
+ userEmail: checkout.user.email,
2801
+ info: error.response.data,
2802
+ });
2803
+ }
2804
+ }
2805
+ createBoletoPayment(checkout) {
2806
+ return {
2807
+ api_key: this.credentials.API_KEY,
2808
+ amount: Math.floor(checkout.totalPrice * 100),
2809
+ boleto_rules: ['strict_expiration_date'],
2810
+ boleto_instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
2811
+ boleto_expiration_date: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd'),
2812
+ payment_method: 'boleto',
2813
+ postback_url: this.credentials.URL_POSTBACK,
2814
+ customer: {
2815
+ external_id: checkout.user.id,
2816
+ type: 'individual',
2817
+ country: 'br',
2818
+ name: checkout.user.displayName,
2819
+ documents: [
2820
+ {
2821
+ type: 'cpf',
2822
+ number: checkout.user.cpf,
2823
+ },
2824
+ ],
2825
+ },
2826
+ };
2827
+ }
2828
+ }
2829
+
2830
+ class PagarmeCardService {
2831
+ constructor(credentials, paymentRepository, orderBlockedRepository) {
2832
+ this.credentials = credentials;
2833
+ this.paymentRepository = paymentRepository;
2834
+ this.orderBlockedRepository = orderBlockedRepository;
2835
+ }
2836
+ async pay(checkout, card) {
2837
+ var _a;
2838
+ try {
2839
+ const result = await axios__default["default"]({
2840
+ method: 'POST',
2841
+ url: this.credentials.URL_TRANSACTION,
2842
+ data: this.createCardPayment(checkout, card),
2843
+ });
2844
+ if (result.data.status !== 'paid') {
2845
+ this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
2846
+ 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`, {
2847
+ checkoutId: checkout.id,
2848
+ userEmail: checkout.user.email,
2849
+ info: result.data,
2850
+ }));
2851
+ }
2852
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2853
+ createdAt: new Date(),
2854
+ updatedAt: new Date(),
2855
+ userId: checkout.user.id,
2856
+ checkoutId: checkout.id,
2857
+ totalPrice: checkout.totalPrice,
2858
+ paymentProvider: 'pagarMe',
2859
+ transaction: result.data,
2860
+ }));
2861
+ return payment;
2862
+ }
2863
+ catch (error) {
2864
+ 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', {
2865
+ checkoutId: checkout.id,
2866
+ userEmail: checkout.user.email,
2867
+ info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
2868
+ });
2869
+ }
2870
+ }
2871
+ addCard() {
2872
+ throw new Error('Method not implemented.');
2873
+ }
2874
+ createCardPayment(checkout, card) {
2875
+ var _a, _b, _c, _d, _e, _f;
2876
+ return {
2877
+ api_key: this.credentials.API_KEY,
2878
+ amount: Math.floor(checkout.totalPrice * 100),
2879
+ card_id: card.cardId,
2880
+ payment_method: 'credit_card',
2881
+ installments: card.installments,
2882
+ soft_descriptor: checkout.shop,
2883
+ customer: {
2884
+ external_id: checkout.user.id,
2885
+ name: checkout.user.displayName,
2886
+ type: 'individual',
2887
+ country: 'br',
2888
+ email: checkout.user.email,
2889
+ phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
2890
+ documents: [
2891
+ {
2892
+ type: 'cpf',
2893
+ number: checkout.user.cpf,
2894
+ },
2895
+ ],
2896
+ },
2897
+ billing: {
2898
+ name: checkout.user.displayName,
2899
+ address: {
2900
+ country: 'br',
2901
+ state: checkout.billingAddress ? checkout.billingAddress.state : (_a = checkout.shippingAddress) === null || _a === void 0 ? void 0 : _a.state,
2902
+ city: checkout.billingAddress ? checkout.billingAddress.city : (_b = checkout.shippingAddress) === null || _b === void 0 ? void 0 : _b.city,
2903
+ neighborhood: checkout.billingAddress ? checkout.billingAddress.district : (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.district,
2904
+ street: checkout.billingAddress ? checkout.billingAddress.street : (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.street,
2905
+ street_number: checkout.billingAddress ? checkout.billingAddress.number : (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.number,
2906
+ zipcode: checkout.billingAddress
2907
+ ? checkout.billingAddress.zip.replace('-', '')
2908
+ : (_f = checkout.shippingAddress) === null || _f === void 0 ? void 0 : _f.zip.replace('-', ''),
2909
+ },
2910
+ },
2911
+ items: checkout.lineItems.map((item) => {
2912
+ return {
2913
+ id: item.id,
2914
+ title: checkout.user.isSubscriber ? `${item.name} - ASSINANTE` : item.name,
2915
+ unit_price: Math.floor(item.pricePaid * 100),
2916
+ quantity: item.quantity,
2917
+ tangible: true,
2918
+ };
2919
+ }),
2920
+ };
2921
+ }
2922
+ }
2923
+
2924
+ class PagarmePixService {
2925
+ constructor(credentials, paymentRepository) {
2926
+ this.credentials = credentials;
2927
+ this.paymentRepository = paymentRepository;
2928
+ }
2929
+ async pay(checkout) {
2930
+ var _a;
2931
+ try {
2932
+ const result = await axios__default["default"]({
2933
+ method: 'POST',
2934
+ url: this.credentials.URL_TRANSACTION,
2935
+ data: this.createPixPayment(checkout),
2936
+ });
2937
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2938
+ createdAt: new Date(),
2939
+ updatedAt: new Date(),
2940
+ userId: checkout.user.id,
2941
+ checkoutId: checkout.id,
2942
+ totalPrice: checkout.totalPrice,
2943
+ paymentProvider: 'pagarMe',
2944
+ transaction: result.data,
2945
+ }));
2946
+ return payment;
2947
+ }
2948
+ catch (error) {
2949
+ throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
2950
+ checkoutId: checkout.id,
2951
+ userEmail: checkout.user.email,
2952
+ info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
2953
+ });
2954
+ }
2955
+ }
2956
+ createPixPayment(checkout) {
2957
+ return {
2958
+ payment_method: 'pix',
2959
+ amount: Math.floor(checkout.totalPrice * 100),
2960
+ api_key: this.credentials.API_KEY,
2961
+ postback_url: this.credentials.URL_POSTBACK,
2962
+ pix_expiration_date: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd'),
2963
+ customer: {
2964
+ external_id: checkout.user.id,
2965
+ type: 'individual',
2966
+ country: 'br',
2967
+ name: checkout.user.displayName,
2968
+ email: checkout.user.email.trim(),
2969
+ phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
2970
+ documents: [
2971
+ {
2972
+ type: 'cpf',
2973
+ number: checkout.user.cpf,
2974
+ },
2975
+ ],
2976
+ },
2977
+ };
2978
+ }
2979
+ }
2980
+
2328
2981
  class RoundProductPricesHelper {
2329
2982
  static roundProductPrices(product) {
2330
2983
  product.price.price = Number(product.price.price.toFixed(2));
@@ -2339,6 +2992,12 @@ class RoundProductPricesHelper {
2339
2992
  }
2340
2993
  }
2341
2994
 
2995
+ class Sequence extends BaseModel {
2996
+ static get identifiersFields() {
2997
+ return ['id'];
2998
+ }
2999
+ }
3000
+
2342
3001
  exports.FilterType = void 0;
2343
3002
  (function (FilterType) {
2344
3003
  FilterType["ACCESSORY_IMPORTANCE"] = "accessoryImportance";
@@ -2477,36 +3136,10 @@ class ShopSettings extends BaseModel {
2477
3136
  }
2478
3137
  }
2479
3138
 
2480
- class InvalidArgumentError extends tsCustomError.CustomError {
2481
- constructor(message) {
2482
- super(message);
2483
- }
2484
- }
2485
-
2486
- class RequiredArgumentError extends tsCustomError.CustomError {
2487
- constructor(args) {
2488
- super(`Required arguments: ${args.join(', ')}`);
2489
- this.args = args;
2490
- this.arguments = args;
2491
- }
2492
- }
2493
-
2494
- class NotFoundError extends tsCustomError.CustomError {
2495
- constructor(message) {
2496
- super(message);
2497
- }
2498
- }
2499
-
2500
- class DuplicatedResultsError extends tsCustomError.CustomError {
2501
- constructor(message) {
2502
- super(message);
2503
- }
2504
- }
2505
-
2506
- class AxiosAdapter {
2507
- constructor(config) {
2508
- this.config = config;
2509
- this.logger = DebugHelper.from(this);
3139
+ class AxiosAdapter {
3140
+ constructor(config) {
3141
+ this.config = config;
3142
+ this.logger = DebugHelper.from(this);
2510
3143
  }
2511
3144
  async get(index, id) {
2512
3145
  const logger = this.logger.with('get');
@@ -3195,180 +3828,6 @@ const withCrudFirestore = (MixinBase) => {
3195
3828
  };
3196
3829
  };
3197
3830
 
3198
- class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3199
- constructor({ firestore, interceptors }) {
3200
- super({
3201
- firestore,
3202
- collectionName: 'leads',
3203
- model: Lead,
3204
- interceptors,
3205
- });
3206
- }
3207
- }
3208
-
3209
- class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3210
- constructor({ firestore, interceptors }, parentRepository) {
3211
- super({
3212
- firestore,
3213
- collectionName: 'editions',
3214
- parentIdField: 'subscriptionId',
3215
- model: Edition,
3216
- interceptors,
3217
- });
3218
- this.parentRepository = parentRepository;
3219
- }
3220
- }
3221
-
3222
- class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3223
- constructor({ firestore, interceptors, }) {
3224
- super({
3225
- firestore,
3226
- collectionName: 'subscription',
3227
- model: Subscription,
3228
- interceptors,
3229
- });
3230
- }
3231
- }
3232
-
3233
- class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3234
- constructor({ firestore, interceptors }) {
3235
- super({
3236
- firestore,
3237
- collectionName: 'subscriptionMaterialization',
3238
- model: SubscriptionMaterialization,
3239
- interceptors,
3240
- });
3241
- }
3242
- }
3243
-
3244
- class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3245
- constructor({ firestore, interceptors }, parentRepository) {
3246
- super({
3247
- firestore,
3248
- collectionName: 'payments',
3249
- parentIdField: 'subscriptionId',
3250
- model: SubscriptionPayment,
3251
- interceptors,
3252
- });
3253
- this.parentRepository = parentRepository;
3254
- }
3255
- }
3256
-
3257
- class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3258
- constructor({ firestore, interceptors, }) {
3259
- super({
3260
- firestore,
3261
- collectionName: 'subscriptionSummary',
3262
- model: SubscriptionSummary,
3263
- interceptors,
3264
- });
3265
- }
3266
- }
3267
-
3268
- class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3269
- constructor({ firestore, interceptors }, parentRepository) {
3270
- super({
3271
- firestore,
3272
- collectionName: 'address',
3273
- parentIdField: 'userId',
3274
- model: UserAddress,
3275
- interceptors,
3276
- });
3277
- this.parentRepository = parentRepository;
3278
- }
3279
- }
3280
-
3281
- class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3282
- constructor({ firestore, interceptors }, parentRepository) {
3283
- super({
3284
- firestore,
3285
- collectionName: 'CX',
3286
- parentIdField: 'userId',
3287
- model: BeautyProfile,
3288
- interceptors,
3289
- });
3290
- this.parentRepository = parentRepository;
3291
- }
3292
- }
3293
-
3294
- class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3295
- constructor({ firestore, interceptors }) {
3296
- super({
3297
- firestore,
3298
- collectionName: 'users',
3299
- model: User,
3300
- interceptors,
3301
- });
3302
- }
3303
- async get(identifiers) {
3304
- const user = await super.get({ id: identifiers.id });
3305
- user.beautyProfile = await this.getBeautyProfile(user.id);
3306
- user.isSubscriber = await this.checkIfIsSubscriber(user.id);
3307
- return user;
3308
- }
3309
- async checkIfExistsByField(field, value) {
3310
- const result = await this.find({ filters: { [field]: value } });
3311
- return result.count > 0;
3312
- }
3313
- buildModelInstance() {
3314
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3315
- return {
3316
- toFirestore: (data) => {
3317
- const plain = toFirestore(data);
3318
- delete plain.isSubscriber;
3319
- return plain;
3320
- },
3321
- fromFirestore,
3322
- };
3323
- }
3324
- async getBeautyProfile(userId) {
3325
- const beautyProfile = await this.firestore
3326
- .getCollection(`${this.collectionName}/${userId}/CX`)
3327
- .withConverter(this.buildBeautyProfileModelInstance())
3328
- .getDoc('beautyProfile')
3329
- .get();
3330
- return beautyProfile.data();
3331
- }
3332
- async checkIfIsSubscriber(userId) {
3333
- const docs = await this.collection('subscription')
3334
- .where('user.id', '==', userId)
3335
- .where('status', '==', 'active')
3336
- .getDocs();
3337
- return !!docs && !!docs.size;
3338
- }
3339
- buildBeautyProfileModelInstance() {
3340
- return {
3341
- toFirestore: (data) => data.toPlain(),
3342
- fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
3343
- };
3344
- }
3345
- }
3346
- tslib_1.__decorate([
3347
- Log(),
3348
- tslib_1.__metadata("design:type", Function),
3349
- tslib_1.__metadata("design:paramtypes", [Object]),
3350
- tslib_1.__metadata("design:returntype", Promise)
3351
- ], UserFirestoreRepository.prototype, "get", null);
3352
- tslib_1.__decorate([
3353
- Log(),
3354
- tslib_1.__metadata("design:type", Function),
3355
- tslib_1.__metadata("design:paramtypes", [String, String]),
3356
- tslib_1.__metadata("design:returntype", Promise)
3357
- ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
3358
-
3359
- class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3360
- constructor({ firestore, interceptors }, parentRepository) {
3361
- super({
3362
- firestore,
3363
- collectionName: 'payment_method',
3364
- parentIdField: 'userId',
3365
- model: UserPaymentMethod,
3366
- interceptors,
3367
- });
3368
- this.parentRepository = parentRepository;
3369
- }
3370
- }
3371
-
3372
3831
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3373
3832
  constructor({ firestore, interceptors }) {
3374
3833
  super({
@@ -3515,39 +3974,134 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
3515
3974
  async fetchPaginatedReviews() {
3516
3975
  return Promise.resolve([]);
3517
3976
  }
3518
- }
3519
- tslib_1.__decorate([
3520
- Log(),
3521
- tslib_1.__metadata("design:type", Function),
3522
- tslib_1.__metadata("design:paramtypes", [String]),
3523
- tslib_1.__metadata("design:returntype", Promise)
3524
- ], ProductFirestoreRepository.prototype, "getBySlug", null);
3525
- tslib_1.__decorate([
3526
- Log(),
3527
- tslib_1.__metadata("design:type", Function),
3528
- tslib_1.__metadata("design:paramtypes", [String]),
3529
- tslib_1.__metadata("design:returntype", Promise)
3530
- ], ProductFirestoreRepository.prototype, "fetchReviews", null);
3977
+ }
3978
+ tslib_1.__decorate([
3979
+ Log(),
3980
+ tslib_1.__metadata("design:type", Function),
3981
+ tslib_1.__metadata("design:paramtypes", [String]),
3982
+ tslib_1.__metadata("design:returntype", Promise)
3983
+ ], ProductFirestoreRepository.prototype, "getBySlug", null);
3984
+ tslib_1.__decorate([
3985
+ Log(),
3986
+ tslib_1.__metadata("design:type", Function),
3987
+ tslib_1.__metadata("design:paramtypes", [String]),
3988
+ tslib_1.__metadata("design:returntype", Promise)
3989
+ ], ProductFirestoreRepository.prototype, "fetchReviews", null);
3990
+
3991
+ class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3992
+ constructor({ firestore, interceptors }, parentRepository) {
3993
+ super({
3994
+ firestore,
3995
+ collectionName: 'variants',
3996
+ parentIdField: 'productId',
3997
+ model: Variant,
3998
+ interceptors,
3999
+ });
4000
+ this.parentRepository = parentRepository;
4001
+ }
4002
+ }
4003
+
4004
+ class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4005
+ constructor({ firestore, interceptors }) {
4006
+ super({
4007
+ firestore,
4008
+ collectionName: 'subscriptionProducts',
4009
+ model: Product,
4010
+ interceptors,
4011
+ });
4012
+ }
4013
+ }
4014
+
4015
+ class SequenceFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4016
+ constructor({ firestore, interceptors }) {
4017
+ super({
4018
+ firestore,
4019
+ collectionName: 'sequences',
4020
+ model: Sequence,
4021
+ interceptors,
4022
+ });
4023
+ }
4024
+ }
4025
+
4026
+ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4027
+ constructor({ firestore, interceptors }) {
4028
+ super({
4029
+ firestore,
4030
+ collectionName: 'dms',
4031
+ model: Home,
4032
+ interceptors,
4033
+ });
4034
+ this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
4035
+ var _a, _b, _c;
4036
+ return ({
4037
+ category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
4038
+ ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
4039
+ : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
4040
+ 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)) || [],
4041
+ });
4042
+ };
4043
+ this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
4044
+ var _a;
4045
+ return ({
4046
+ category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
4047
+ products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
4048
+ });
4049
+ };
4050
+ }
4051
+ buildModelInstance() {
4052
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
4053
+ return {
4054
+ toFirestore: (data) => {
4055
+ const modifiedData = this.homeToFirestore(data);
4056
+ return toFirestore(modifiedData);
4057
+ },
4058
+ fromFirestore: (snap) => {
4059
+ const instance = fromFirestore(snap);
4060
+ return this.homeFromFirestore(instance);
4061
+ },
4062
+ };
4063
+ }
4064
+ homeToFirestore(home) {
4065
+ var _a, _b, _c, _d;
4066
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
4067
+ home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
4068
+ home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
4069
+ home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
4070
+ }
4071
+ return home;
4072
+ }
4073
+ homeFromFirestore(home) {
4074
+ var _a;
4075
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
4076
+ home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
4077
+ home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
4078
+ home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
4079
+ home.data.createdAt =
4080
+ home.data.createdAt instanceof firestore.Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
4081
+ home.data.expiresAt =
4082
+ home.data.expiresAt instanceof firestore.Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
4083
+ }
4084
+ return home;
4085
+ }
4086
+ }
3531
4087
 
3532
- class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3533
- constructor({ firestore, interceptors }, parentRepository) {
4088
+ class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4089
+ constructor({ firestore, interceptors }) {
3534
4090
  super({
3535
4091
  firestore,
3536
- collectionName: 'variants',
3537
- parentIdField: 'productId',
3538
- model: Variant,
4092
+ collectionName: 'shopMenus',
4093
+ model: ShopMenu,
3539
4094
  interceptors,
3540
4095
  });
3541
- this.parentRepository = parentRepository;
3542
4096
  }
3543
4097
  }
3544
4098
 
3545
- class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3546
- constructor({ firestore, interceptors }) {
4099
+ class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4100
+ constructor({ firestore, interceptors, }) {
3547
4101
  super({
3548
4102
  firestore,
3549
- collectionName: 'subscriptionProducts',
3550
- model: Product,
4103
+ collectionName: 'shopSettings',
4104
+ model: ShopSettings,
3551
4105
  interceptors,
3552
4106
  });
3553
4107
  }
@@ -3683,6 +4237,47 @@ class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
3683
4237
  }
3684
4238
  }
3685
4239
 
4240
+ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4241
+ constructor({ firestore, interceptors, }) {
4242
+ super({
4243
+ firestore,
4244
+ collectionName: 'paymentBlockedAttempts',
4245
+ model: OrderBlocked,
4246
+ interceptors,
4247
+ });
4248
+ }
4249
+ async createBlockedOrderOrPayment(checkout, blockType, type, limiteRange, card = null) {
4250
+ var _a, _b, _c, _d, _e, _f, _g, _h;
4251
+ return this.create(OrderBlocked.toInstance({
4252
+ customer: {
4253
+ name: ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.displayName) || '',
4254
+ cpf: ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.cpf) || '',
4255
+ id: (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.id,
4256
+ email: ((_d = checkout.user) === null || _d === void 0 ? void 0 : _d.email) || '',
4257
+ phoneNumber: '+55' + ((_e = checkout.user) === null || _e === void 0 ? void 0 : _e.phone),
4258
+ isSubscriber: (_f = checkout.user) === null || _f === void 0 ? void 0 : _f.isSubscriber,
4259
+ subscriptionPlan: ((_g = checkout.user) === null || _g === void 0 ? void 0 : _g.subscriptionPlan) || '',
4260
+ shippingAddress: Object.assign(Object.assign({}, checkout.shippingAddress), { zip: this.formatZip((_h = checkout.shippingAddress) === null || _h === void 0 ? void 0 : _h.zip) }),
4261
+ },
4262
+ blockType,
4263
+ limiteRange,
4264
+ type,
4265
+ card,
4266
+ checkout: {
4267
+ id: checkout.id,
4268
+ shop: checkout.shop,
4269
+ total: checkout.totalPrice,
4270
+ },
4271
+ date: new Date(),
4272
+ }));
4273
+ }
4274
+ formatZip(zip) {
4275
+ if (zip.length === 8)
4276
+ return zip.substring(0, 5) + '-' + zip.substring(5, 8);
4277
+ return zip;
4278
+ }
4279
+ }
4280
+
3686
4281
  class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3687
4282
  constructor({ firestore, interceptors }) {
3688
4283
  super({
@@ -3705,87 +4300,177 @@ class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(
3705
4300
  }
3706
4301
  }
3707
4302
 
3708
- class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4303
+ class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3709
4304
  constructor({ firestore, interceptors }) {
3710
4305
  super({
3711
4306
  firestore,
3712
- collectionName: 'dms',
3713
- model: Home,
4307
+ collectionName: 'leads',
4308
+ model: Lead,
3714
4309
  interceptors,
3715
4310
  });
3716
- this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
3717
- var _a, _b, _c;
3718
- return ({
3719
- category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
3720
- ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
3721
- : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
3722
- 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)) || [],
3723
- });
3724
- };
3725
- this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
3726
- var _a;
3727
- return ({
3728
- category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
3729
- products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
3730
- });
3731
- };
3732
- }
3733
- buildModelInstance() {
3734
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3735
- return {
3736
- toFirestore: (data) => {
3737
- const modifiedData = this.homeToFirestore(data);
3738
- return toFirestore(modifiedData);
3739
- },
3740
- fromFirestore: (snap) => {
3741
- const instance = fromFirestore(snap);
3742
- return this.homeFromFirestore(instance);
3743
- },
3744
- };
3745
4311
  }
3746
- homeToFirestore(home) {
3747
- var _a, _b, _c, _d;
3748
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3749
- home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
3750
- home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
3751
- home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
3752
- }
3753
- return home;
4312
+ }
4313
+
4314
+ class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4315
+ constructor({ firestore, interceptors }, parentRepository) {
4316
+ super({
4317
+ firestore,
4318
+ collectionName: 'editions',
4319
+ parentIdField: 'subscriptionId',
4320
+ model: Edition,
4321
+ interceptors,
4322
+ });
4323
+ this.parentRepository = parentRepository;
3754
4324
  }
3755
- homeFromFirestore(home) {
3756
- var _a;
3757
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3758
- home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
3759
- home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
3760
- home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
3761
- home.data.createdAt =
3762
- home.data.createdAt instanceof firestore.Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
3763
- home.data.expiresAt =
3764
- home.data.expiresAt instanceof firestore.Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
3765
- }
3766
- return home;
4325
+ }
4326
+
4327
+ class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4328
+ constructor({ firestore, interceptors, }) {
4329
+ super({
4330
+ firestore,
4331
+ collectionName: 'subscription',
4332
+ model: Subscription,
4333
+ interceptors,
4334
+ });
3767
4335
  }
3768
4336
  }
3769
4337
 
3770
- class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4338
+ class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3771
4339
  constructor({ firestore, interceptors }) {
3772
4340
  super({
3773
4341
  firestore,
3774
- collectionName: 'shopMenus',
3775
- model: ShopMenu,
4342
+ collectionName: 'subscriptionMaterialization',
4343
+ model: SubscriptionMaterialization,
3776
4344
  interceptors,
3777
4345
  });
3778
4346
  }
3779
4347
  }
3780
4348
 
3781
- class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4349
+ class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4350
+ constructor({ firestore, interceptors }, parentRepository) {
4351
+ super({
4352
+ firestore,
4353
+ collectionName: 'payments',
4354
+ parentIdField: 'subscriptionId',
4355
+ model: SubscriptionPayment,
4356
+ interceptors,
4357
+ });
4358
+ this.parentRepository = parentRepository;
4359
+ }
4360
+ }
4361
+
4362
+ class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3782
4363
  constructor({ firestore, interceptors, }) {
3783
4364
  super({
3784
4365
  firestore,
3785
- collectionName: 'shopSettings',
3786
- model: ShopSettings,
4366
+ collectionName: 'subscriptionSummary',
4367
+ model: SubscriptionSummary,
4368
+ interceptors,
4369
+ });
4370
+ }
4371
+ }
4372
+
4373
+ class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4374
+ constructor({ firestore, interceptors }, parentRepository) {
4375
+ super({
4376
+ firestore,
4377
+ collectionName: 'address',
4378
+ parentIdField: 'userId',
4379
+ model: UserAddress,
4380
+ interceptors,
4381
+ });
4382
+ this.parentRepository = parentRepository;
4383
+ }
4384
+ }
4385
+
4386
+ class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4387
+ constructor({ firestore, interceptors }, parentRepository) {
4388
+ super({
4389
+ firestore,
4390
+ collectionName: 'CX',
4391
+ parentIdField: 'userId',
4392
+ model: BeautyProfile,
4393
+ interceptors,
4394
+ });
4395
+ this.parentRepository = parentRepository;
4396
+ }
4397
+ }
4398
+
4399
+ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4400
+ constructor({ firestore, interceptors }) {
4401
+ super({
4402
+ firestore,
4403
+ collectionName: 'users',
4404
+ model: User,
4405
+ interceptors,
4406
+ });
4407
+ }
4408
+ async get(identifiers) {
4409
+ const user = await super.get({ id: identifiers.id });
4410
+ user.beautyProfile = await this.getBeautyProfile(user.id);
4411
+ user.isSubscriber = await this.checkIfIsSubscriber(user.id);
4412
+ return user;
4413
+ }
4414
+ async checkIfExistsByField(field, value) {
4415
+ const result = await this.find({ filters: { [field]: value } });
4416
+ return result.count > 0;
4417
+ }
4418
+ buildModelInstance() {
4419
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
4420
+ return {
4421
+ toFirestore: (data) => {
4422
+ const plain = toFirestore(data);
4423
+ delete plain.isSubscriber;
4424
+ return plain;
4425
+ },
4426
+ fromFirestore,
4427
+ };
4428
+ }
4429
+ async getBeautyProfile(userId) {
4430
+ const beautyProfile = await this.firestore
4431
+ .getCollection(`${this.collectionName}/${userId}/CX`)
4432
+ .withConverter(this.buildBeautyProfileModelInstance())
4433
+ .getDoc('beautyProfile')
4434
+ .get();
4435
+ return beautyProfile.data();
4436
+ }
4437
+ async checkIfIsSubscriber(userId) {
4438
+ const docs = await this.collection('subscription')
4439
+ .where('user.id', '==', userId)
4440
+ .where('status', '==', 'active')
4441
+ .getDocs();
4442
+ return !!docs && !!docs.size;
4443
+ }
4444
+ buildBeautyProfileModelInstance() {
4445
+ return {
4446
+ toFirestore: (data) => data.toPlain(),
4447
+ fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
4448
+ };
4449
+ }
4450
+ }
4451
+ tslib_1.__decorate([
4452
+ Log(),
4453
+ tslib_1.__metadata("design:type", Function),
4454
+ tslib_1.__metadata("design:paramtypes", [Object]),
4455
+ tslib_1.__metadata("design:returntype", Promise)
4456
+ ], UserFirestoreRepository.prototype, "get", null);
4457
+ tslib_1.__decorate([
4458
+ Log(),
4459
+ tslib_1.__metadata("design:type", Function),
4460
+ tslib_1.__metadata("design:paramtypes", [String, String]),
4461
+ tslib_1.__metadata("design:returntype", Promise)
4462
+ ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
4463
+
4464
+ class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4465
+ constructor({ firestore, interceptors }, parentRepository) {
4466
+ super({
4467
+ firestore,
4468
+ collectionName: 'payment_method',
4469
+ parentIdField: 'userId',
4470
+ model: UserPaymentMethod,
3787
4471
  interceptors,
3788
4472
  });
4473
+ this.parentRepository = parentRepository;
3789
4474
  }
3790
4475
  }
3791
4476
 
@@ -6324,6 +7009,10 @@ Object.defineProperty(exports, 'sub', {
6324
7009
  enumerable: true,
6325
7010
  get: function () { return dateFns.sub; }
6326
7011
  });
7012
+ Object.defineProperty(exports, 'subDays', {
7013
+ enumerable: true,
7014
+ get: function () { return dateFns.subDays; }
7015
+ });
6327
7016
  Object.defineProperty(exports, 'chunk', {
6328
7017
  enumerable: true,
6329
7018
  get: function () { return lodash.chunk; }
@@ -6397,6 +7086,13 @@ Object.defineProperty(exports, 'unset', {
6397
7086
  get: function () { return lodash.unset; }
6398
7087
  });
6399
7088
  exports.Address = Address;
7089
+ exports.AdyenCardService = AdyenCardService;
7090
+ exports.AdyenPaymentMethodFactory = AdyenPaymentMethodFactory;
7091
+ exports.AntifraudBankSlipService = AntifraudBankSlipService;
7092
+ exports.AntifraudCardService = AntifraudCardService;
7093
+ exports.AntifraudGlampointsService = AntifraudGlampointsService;
7094
+ exports.AntifraudPixService = AntifraudPixService;
7095
+ exports.AntifraudProviderFactory = AntifraudProviderFactory;
6400
7096
  exports.Authentication = Authentication;
6401
7097
  exports.AuthenticationFirebaseAuthService = AuthenticationFirebaseAuthService;
6402
7098
  exports.AxiosAdapter = AxiosAdapter;
@@ -6404,6 +7100,7 @@ exports.Base = Base;
6404
7100
  exports.BaseModel = BaseModel;
6405
7101
  exports.BeautyProfile = BeautyProfile;
6406
7102
  exports.BeautyQuestionsHelper = BeautyQuestionsHelper;
7103
+ exports.BusinessError = BusinessError;
6407
7104
  exports.Buy2Win = Buy2Win;
6408
7105
  exports.Buy2WinFirestoreRepository = Buy2WinFirestoreRepository;
6409
7106
  exports.Campaign = Campaign;
@@ -6441,6 +7138,9 @@ exports.FilterHasuraGraphQLRepository = FilterHasuraGraphQLRepository;
6441
7138
  exports.FilterOption = FilterOption;
6442
7139
  exports.FilterOptionHasuraGraphQLRepository = FilterOptionHasuraGraphQLRepository;
6443
7140
  exports.FirebaseFileUploaderService = FirebaseFileUploaderService;
7141
+ exports.FraudValidationError = FraudValidationError;
7142
+ exports.GlampointsPaymentMethodFactory = GlampointsPaymentMethodFactory;
7143
+ exports.GlampointsPaymentService = GlampointsPaymentService;
6444
7144
  exports.Home = Home;
6445
7145
  exports.HomeFirestoreRepository = HomeFirestoreRepository;
6446
7146
  exports.InvalidArgumentError = InvalidArgumentError;
@@ -6454,9 +7154,18 @@ exports.Log = Log;
6454
7154
  exports.Logger = Logger;
6455
7155
  exports.NotFoundError = NotFoundError;
6456
7156
  exports.Order = Order;
7157
+ exports.OrderBlocked = OrderBlocked;
7158
+ exports.OrderBlockedFirestoreRepository = OrderBlockedFirestoreRepository;
6457
7159
  exports.OrderFirestoreRepository = OrderFirestoreRepository;
7160
+ exports.PagarmeBankSlipService = PagarmeBankSlipService;
7161
+ exports.PagarmeCardService = PagarmeCardService;
7162
+ exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
7163
+ exports.PagarmePixService = PagarmePixService;
6458
7164
  exports.Payment = Payment;
7165
+ exports.PaymentError = PaymentError;
6459
7166
  exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
7167
+ exports.PaymentProviderFactory = PaymentProviderFactory;
7168
+ exports.PaymentTransaction = PaymentTransaction;
6460
7169
  exports.Product = Product;
6461
7170
  exports.ProductFirestoreRepository = ProductFirestoreRepository;
6462
7171
  exports.ProductHasuraGraphQL = ProductHasuraGraphQL;
@@ -6473,12 +7182,16 @@ exports.Register = Register;
6473
7182
  exports.RegisterFirebaseAuthService = RegisterFirebaseAuthService;
6474
7183
  exports.RequiredArgumentError = RequiredArgumentError;
6475
7184
  exports.RoundProductPricesHelper = RoundProductPricesHelper;
7185
+ exports.Sequence = Sequence;
7186
+ exports.SequenceFirestoreRepository = SequenceFirestoreRepository;
6476
7187
  exports.ShippingMethod = ShippingMethod;
6477
7188
  exports.ShopMenu = ShopMenu;
6478
7189
  exports.ShopMenuFirestoreRepository = ShopMenuFirestoreRepository;
6479
7190
  exports.ShopSettings = ShopSettings;
6480
7191
  exports.ShopSettingsFirestoreRepository = ShopSettingsFirestoreRepository;
6481
7192
  exports.SignOut = SignOut;
7193
+ exports.StockLimitError = StockLimitError;
7194
+ exports.StockOutError = StockOutError;
6482
7195
  exports.Subscription = Subscription;
6483
7196
  exports.SubscriptionEditionFirestoreRepository = SubscriptionEditionFirestoreRepository;
6484
7197
  exports.SubscriptionFirestoreRepository = SubscriptionFirestoreRepository;