@infrab4a/connect 4.18.0-beta.0 → 4.18.0-beta.1

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 (69) hide show
  1. package/index.cjs.js +122 -752
  2. package/index.esm.js +125 -729
  3. package/package.json +1 -1
  4. package/src/domain/general/models/index.d.ts +0 -1
  5. package/src/domain/general/repositories/index.d.ts +0 -1
  6. package/src/domain/shopping/index.d.ts +0 -4
  7. package/src/domain/shopping/models/coupons/coupon.d.ts +6 -2
  8. package/src/domain/shopping/models/coupons/enums/coupon-category.enum.d.ts +24 -0
  9. package/src/domain/shopping/models/coupons/enums/coupon-channels.enum.d.ts +10 -0
  10. package/src/domain/shopping/models/coupons/enums/index.d.ts +1 -0
  11. package/src/domain/shopping/models/coupons/types/coupon-category.type.d.ts +2 -0
  12. package/src/domain/shopping/models/coupons/types/coupon-channel.type.d.ts +2 -0
  13. package/src/domain/shopping/models/coupons/types/index.d.ts +2 -0
  14. package/src/domain/shopping/models/index.d.ts +0 -1
  15. package/src/domain/shopping/models/order.d.ts +2 -2
  16. package/src/domain/shopping/models/payment.d.ts +63 -10
  17. package/src/domain/shopping/models/types/index.d.ts +4 -4
  18. package/src/domain/shopping/types/index.d.ts +0 -5
  19. package/src/errors/index.d.ts +2 -7
  20. package/src/infra/firebase/firestore/repositories/general/index.d.ts +0 -1
  21. package/src/infra/firebase/firestore/repositories/shopping/index.d.ts +1 -1
  22. package/src/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +1 -0
  23. package/src/utils/index.d.ts +2 -2
  24. package/src/domain/general/models/sequences.d.ts +0 -9
  25. package/src/domain/general/repositories/sequences.repository.d.ts +0 -4
  26. package/src/domain/shopping/enums/antifraud-providers.enum.d.ts +0 -6
  27. package/src/domain/shopping/enums/index.d.ts +0 -3
  28. package/src/domain/shopping/enums/payment-methods.enum.d.ts +0 -6
  29. package/src/domain/shopping/enums/payment-providers.enum.d.ts +0 -5
  30. package/src/domain/shopping/factories/adyen-payment-method.factory.d.ts +0 -8
  31. package/src/domain/shopping/factories/antifraud-provider.factory.d.ts +0 -15
  32. package/src/domain/shopping/factories/base-payment-method.factory.d.ts +0 -7
  33. package/src/domain/shopping/factories/glampoints-payment-method.factory.d.ts +0 -8
  34. package/src/domain/shopping/factories/index.d.ts +0 -5
  35. package/src/domain/shopping/factories/pagarme-payment-method.factory.d.ts +0 -10
  36. package/src/domain/shopping/factories/payment-provider.factory.d.ts +0 -15
  37. package/src/domain/shopping/interfaces/antifraud-method-factory.interface.d.ts +0 -11
  38. package/src/domain/shopping/interfaces/antifraud-provider.interface.d.ts +0 -5
  39. package/src/domain/shopping/interfaces/index.d.ts +0 -7
  40. package/src/domain/shopping/interfaces/payment-method-factory.interface.d.ts +0 -14
  41. package/src/domain/shopping/interfaces/payment-provider-bank-slip.interface.d.ts +0 -5
  42. package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +0 -7
  43. package/src/domain/shopping/interfaces/payment-provider-glampoints.interface.d.ts +0 -5
  44. package/src/domain/shopping/interfaces/payment-provider-pix.interface.d.ts +0 -5
  45. package/src/domain/shopping/models/payment-transaction.d.ts +0 -67
  46. package/src/domain/shopping/services/adyen-card-payment.service.d.ts +0 -13
  47. package/src/domain/shopping/services/antifraud-bankslip.service.d.ts +0 -9
  48. package/src/domain/shopping/services/antifraud-card.service.d.ts +0 -18
  49. package/src/domain/shopping/services/antifraud-glampoints.service.d.ts +0 -6
  50. package/src/domain/shopping/services/antifraud-pix.service.d.ts +0 -6
  51. package/src/domain/shopping/services/glampoints-payment.service.d.ts +0 -8
  52. package/src/domain/shopping/services/index.d.ts +0 -9
  53. package/src/domain/shopping/services/pagarme-bank-slip-payment.service.d.ts +0 -11
  54. package/src/domain/shopping/services/pagarme-card-payment.service.d.ts +0 -13
  55. package/src/domain/shopping/services/pagarme-pix-payment.service.d.ts +0 -11
  56. package/src/domain/shopping/types/adyen-credentials.type.d.ts +0 -6
  57. package/src/domain/shopping/types/antifraud-provider.type.d.ts +0 -2
  58. package/src/domain/shopping/types/pagarme-credentials.type.d.ts +0 -5
  59. package/src/domain/shopping/types/payment-method.type.d.ts +0 -2
  60. package/src/domain/shopping/types/payment-provider.type.d.ts +0 -2
  61. package/src/errors/business.error.d.ts +0 -7
  62. package/src/errors/fraud-validation.error.d.ts +0 -7
  63. package/src/errors/payment.error.d.ts +0 -7
  64. package/src/errors/stock-limit.error.d.ts +0 -5
  65. package/src/errors/stock-out.error.d.ts +0 -5
  66. package/src/errors/types/checkout-additional-data-erro.type.d.ts +0 -5
  67. package/src/errors/types/index.d.ts +0 -1
  68. package/src/infra/firebase/firestore/repositories/general/sequences-firestore.repository.d.ts +0 -7
  69. package/src/infra/firebase/firestore/repositories/shopping/order-blocked-firestore.repository.d.ts +0 -9
package/index.cjs.js CHANGED
@@ -19,65 +19,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
19
19
 
20
20
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
21
21
 
22
- exports.AntifraudProviders = void 0;
23
- (function (AntifraudProviders) {
24
- AntifraudProviders["BANKSLIP"] = "bankSlip";
25
- AntifraudProviders["CARD"] = "card";
26
- AntifraudProviders["PIX"] = "pix";
27
- AntifraudProviders["POINTS"] = "glampoints";
28
- })(exports.AntifraudProviders || (exports.AntifraudProviders = {}));
29
-
30
- exports.PaymentMethods = void 0;
31
- (function (PaymentMethods) {
32
- PaymentMethods["CARD"] = "card";
33
- PaymentMethods["BANKSLIP"] = "bankSlip";
34
- PaymentMethods["PIX"] = "pix";
35
- PaymentMethods["POINTS"] = "glampoints";
36
- })(exports.PaymentMethods || (exports.PaymentMethods = {}));
37
-
38
- exports.PaymentProviders = void 0;
39
- (function (PaymentProviders) {
40
- PaymentProviders["PAGARME"] = "pagarMe";
41
- PaymentProviders["ADYEN"] = "adyen";
42
- PaymentProviders["GLAMPOINTS"] = "glampoints";
43
- })(exports.PaymentProviders || (exports.PaymentProviders = {}));
44
-
45
- class BasePaymentMethodFactory {
46
- constructor(methods) {
47
- this.methods = methods;
48
- }
49
- build(method) {
50
- return this.methods[method];
51
- }
52
- }
53
-
54
- class AdyenPaymentMethodFactory extends BasePaymentMethodFactory {
55
- }
56
-
57
- class AntifraudProviderFactory {
58
- constructor(antifraudProviders) {
59
- this.antifraudProviders = antifraudProviders;
60
- }
61
- build(provider) {
62
- return this.antifraudProviders[provider];
63
- }
64
- }
65
-
66
- class GlampointsPaymentMethodFactory extends BasePaymentMethodFactory {
67
- }
68
-
69
- class PagarmePaymentMethodFactory extends BasePaymentMethodFactory {
70
- }
71
-
72
- class PaymentProviderFactory {
73
- constructor(paymentProviders) {
74
- this.paymentProviders = paymentProviders;
75
- }
76
- build(provider) {
77
- return this.paymentProviders[provider];
78
- }
79
- }
80
-
81
22
  class BaseModel {
82
23
  get identifier() {
83
24
  const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
@@ -624,182 +565,175 @@ exports.Status = void 0;
624
565
  Status["CANCELLED"] = "Cancelado";
625
566
  })(exports.Status || (exports.Status = {}));
626
567
 
627
- class PaymentTransaction extends BaseModel {
568
+ class Payment extends BaseModel {
569
+ static get identifiersFields() {
570
+ return ['id'];
571
+ }
628
572
  }
629
573
  tslib.__decorate([
630
574
  classTransformer.Expose({ name: 'refuse_reason' }),
631
575
  tslib.__metadata("design:type", String)
632
- ], PaymentTransaction.prototype, "refuseReason", void 0);
576
+ ], Payment.prototype, "refuseReason", void 0);
633
577
  tslib.__decorate([
634
578
  classTransformer.Expose({ name: 'status_reason' }),
635
579
  tslib.__metadata("design:type", String)
636
- ], PaymentTransaction.prototype, "statusReason", void 0);
580
+ ], Payment.prototype, "statusReason", void 0);
637
581
  tslib.__decorate([
638
582
  classTransformer.Expose({ name: 'acquirer_response_code' }),
639
583
  tslib.__metadata("design:type", String)
640
- ], PaymentTransaction.prototype, "acquirerResponseCode", void 0);
584
+ ], Payment.prototype, "acquirerResponseCode", void 0);
641
585
  tslib.__decorate([
642
586
  classTransformer.Expose({ name: 'acquirer_name' }),
643
587
  tslib.__metadata("design:type", String)
644
- ], PaymentTransaction.prototype, "acquirerName", void 0);
588
+ ], Payment.prototype, "acquirerName", void 0);
645
589
  tslib.__decorate([
646
590
  classTransformer.Expose({ name: 'acquirer_id' }),
647
591
  tslib.__metadata("design:type", String)
648
- ], PaymentTransaction.prototype, "acquirerId", void 0);
592
+ ], Payment.prototype, "acquirerId", void 0);
649
593
  tslib.__decorate([
650
594
  classTransformer.Expose({ name: 'authorization_code' }),
651
595
  tslib.__metadata("design:type", String)
652
- ], PaymentTransaction.prototype, "authorizationCode", void 0);
596
+ ], Payment.prototype, "authorizationCode", void 0);
653
597
  tslib.__decorate([
654
598
  classTransformer.Expose({ name: 'soft_descriptor' }),
655
599
  tslib.__metadata("design:type", String)
656
- ], PaymentTransaction.prototype, "softDescriptor", void 0);
600
+ ], Payment.prototype, "softDescriptor", void 0);
657
601
  tslib.__decorate([
658
602
  classTransformer.Expose({ name: 'date_created' }),
659
603
  tslib.__metadata("design:type", String)
660
- ], PaymentTransaction.prototype, "dateCreated", void 0);
604
+ ], Payment.prototype, "dateCreated", void 0);
661
605
  tslib.__decorate([
662
606
  classTransformer.Expose({ name: 'date_updated' }),
663
607
  tslib.__metadata("design:type", String)
664
- ], PaymentTransaction.prototype, "dateUpdated", void 0);
608
+ ], Payment.prototype, "dateUpdated", void 0);
665
609
  tslib.__decorate([
666
610
  classTransformer.Expose({ name: 'authorized_amount' }),
667
611
  tslib.__metadata("design:type", Number)
668
- ], PaymentTransaction.prototype, "authorizedAmount", void 0);
612
+ ], Payment.prototype, "authorizedAmount", void 0);
669
613
  tslib.__decorate([
670
614
  classTransformer.Expose({ name: 'paid_amount' }),
671
615
  tslib.__metadata("design:type", Number)
672
- ], PaymentTransaction.prototype, "paidAmount", void 0);
616
+ ], Payment.prototype, "paidAmount", void 0);
673
617
  tslib.__decorate([
674
618
  classTransformer.Expose({ name: 'paid_at' }),
675
619
  tslib.__metadata("design:type", String)
676
- ], PaymentTransaction.prototype, "paidAt", void 0);
620
+ ], Payment.prototype, "paidAt", void 0);
677
621
  tslib.__decorate([
678
622
  classTransformer.Expose({ name: 'refunded_amount' }),
679
623
  tslib.__metadata("design:type", Number)
680
- ], PaymentTransaction.prototype, "refundedAmount", void 0);
624
+ ], Payment.prototype, "refundedAmount", void 0);
681
625
  tslib.__decorate([
682
626
  classTransformer.Expose({ name: 'card_holder_name' }),
683
627
  tslib.__metadata("design:type", String)
684
- ], PaymentTransaction.prototype, "cardHolderName", void 0);
628
+ ], Payment.prototype, "cardHolderName", void 0);
685
629
  tslib.__decorate([
686
630
  classTransformer.Expose({ name: 'card_last_digits' }),
687
631
  tslib.__metadata("design:type", String)
688
- ], PaymentTransaction.prototype, "cardLastDigits", void 0);
632
+ ], Payment.prototype, "cardLastDigits", void 0);
689
633
  tslib.__decorate([
690
634
  classTransformer.Expose({ name: 'card_first_digits' }),
691
635
  tslib.__metadata("design:type", String)
692
- ], PaymentTransaction.prototype, "cardFirstDigits", void 0);
636
+ ], Payment.prototype, "cardFirstDigits", void 0);
693
637
  tslib.__decorate([
694
638
  classTransformer.Expose({ name: 'card_brand' }),
695
639
  tslib.__metadata("design:type", String)
696
- ], PaymentTransaction.prototype, "cardBrand", void 0);
640
+ ], Payment.prototype, "cardBrand", void 0);
697
641
  tslib.__decorate([
698
642
  classTransformer.Expose({ name: 'card_pin_mode' }),
699
643
  tslib.__metadata("design:type", String)
700
- ], PaymentTransaction.prototype, "cardPinMode", void 0);
644
+ ], Payment.prototype, "cardPinMode", void 0);
701
645
  tslib.__decorate([
702
646
  classTransformer.Expose({ name: 'card_magstripe_fallback' }),
703
647
  tslib.__metadata("design:type", Boolean)
704
- ], PaymentTransaction.prototype, "cardMagstripeFallback", void 0);
648
+ ], Payment.prototype, "cardMagstripeFallback", void 0);
705
649
  tslib.__decorate([
706
650
  classTransformer.Expose({ name: 'cvm_pin' }),
707
651
  tslib.__metadata("design:type", Boolean)
708
- ], PaymentTransaction.prototype, "cvmPin", void 0);
652
+ ], Payment.prototype, "cvmPin", void 0);
709
653
  tslib.__decorate([
710
654
  classTransformer.Expose({ name: 'postback_url' }),
711
655
  tslib.__metadata("design:type", String)
712
- ], PaymentTransaction.prototype, "postbackUrl", void 0);
656
+ ], Payment.prototype, "postbackUrl", void 0);
713
657
  tslib.__decorate([
714
658
  classTransformer.Expose({ name: 'payment_method' }),
715
659
  tslib.__metadata("design:type", String)
716
- ], PaymentTransaction.prototype, "paymentMethod", void 0);
660
+ ], Payment.prototype, "paymentMethod", void 0);
717
661
  tslib.__decorate([
718
662
  classTransformer.Expose({ name: 'capture_method' }),
719
663
  tslib.__metadata("design:type", String)
720
- ], PaymentTransaction.prototype, "captureMethod", void 0);
664
+ ], Payment.prototype, "captureMethod", void 0);
721
665
  tslib.__decorate([
722
666
  classTransformer.Expose({ name: 'antifraud_score' }),
723
667
  tslib.__metadata("design:type", String)
724
- ], PaymentTransaction.prototype, "antifraudScore", void 0);
668
+ ], Payment.prototype, "antifraudScore", void 0);
725
669
  tslib.__decorate([
726
670
  classTransformer.Expose({ name: 'boleto_url' }),
727
671
  tslib.__metadata("design:type", String)
728
- ], PaymentTransaction.prototype, "boletoUrl", void 0);
672
+ ], Payment.prototype, "boletoUrl", void 0);
729
673
  tslib.__decorate([
730
674
  classTransformer.Expose({ name: 'boleto_barcode' }),
731
675
  tslib.__metadata("design:type", String)
732
- ], PaymentTransaction.prototype, "boletoBarcode", void 0);
676
+ ], Payment.prototype, "boletoBarcode", void 0);
733
677
  tslib.__decorate([
734
678
  classTransformer.Expose({ name: 'boleto_expiration_date' }),
735
679
  tslib.__metadata("design:type", String)
736
- ], PaymentTransaction.prototype, "boletoExpirationDate", void 0);
680
+ ], Payment.prototype, "boletoExpirationDate", void 0);
737
681
  tslib.__decorate([
738
682
  classTransformer.Expose({ name: 'subscription_id' }),
739
683
  tslib.__metadata("design:type", String)
740
- ], PaymentTransaction.prototype, "subscriptionId", void 0);
684
+ ], Payment.prototype, "subscriptionId", void 0);
741
685
  tslib.__decorate([
742
686
  classTransformer.Expose({ name: 'split_rules' }),
743
687
  tslib.__metadata("design:type", String)
744
- ], PaymentTransaction.prototype, "splitRules", void 0);
688
+ ], Payment.prototype, "splitRules", void 0);
745
689
  tslib.__decorate([
746
690
  classTransformer.Expose({ name: 'antifraud_metadata' }),
747
691
  tslib.__metadata("design:type", Object)
748
- ], PaymentTransaction.prototype, "antifraudMetadata", void 0);
692
+ ], Payment.prototype, "antifraudMetadata", void 0);
749
693
  tslib.__decorate([
750
694
  classTransformer.Expose({ name: 'reference_key' }),
751
695
  tslib.__metadata("design:type", String)
752
- ], PaymentTransaction.prototype, "referenceKey", void 0);
696
+ ], Payment.prototype, "referenceKey", void 0);
753
697
  tslib.__decorate([
754
698
  classTransformer.Expose({ name: 'local_transaction_id' }),
755
699
  tslib.__metadata("design:type", String)
756
- ], PaymentTransaction.prototype, "localTransactionId", void 0);
700
+ ], Payment.prototype, "localTransactionId", void 0);
757
701
  tslib.__decorate([
758
702
  classTransformer.Expose({ name: 'local_time' }),
759
703
  tslib.__metadata("design:type", String)
760
- ], PaymentTransaction.prototype, "localTime", void 0);
704
+ ], Payment.prototype, "localTime", void 0);
761
705
  tslib.__decorate([
762
706
  classTransformer.Expose({ name: 'fraud_covered' }),
763
707
  tslib.__metadata("design:type", Boolean)
764
- ], PaymentTransaction.prototype, "fraudCovered", void 0);
708
+ ], Payment.prototype, "fraudCovered", void 0);
765
709
  tslib.__decorate([
766
710
  classTransformer.Expose({ name: 'fraud_reimbursed' }),
767
711
  tslib.__metadata("design:type", String)
768
- ], PaymentTransaction.prototype, "fraudReimbursed", void 0);
712
+ ], Payment.prototype, "fraudReimbursed", void 0);
769
713
  tslib.__decorate([
770
714
  classTransformer.Expose({ name: 'order_id' }),
771
715
  tslib.__metadata("design:type", String)
772
- ], PaymentTransaction.prototype, "orderId", void 0);
716
+ ], Payment.prototype, "orderId", void 0);
773
717
  tslib.__decorate([
774
718
  classTransformer.Expose({ name: 'risk_level' }),
775
719
  tslib.__metadata("design:type", String)
776
- ], PaymentTransaction.prototype, "riskLevel", void 0);
720
+ ], Payment.prototype, "riskLevel", void 0);
777
721
  tslib.__decorate([
778
722
  classTransformer.Expose({ name: 'receipt_url' }),
779
723
  tslib.__metadata("design:type", String)
780
- ], PaymentTransaction.prototype, "receiptUrl", void 0);
724
+ ], Payment.prototype, "receiptUrl", void 0);
781
725
  tslib.__decorate([
782
726
  classTransformer.Expose({ name: 'private_label' }),
783
727
  tslib.__metadata("design:type", String)
784
- ], PaymentTransaction.prototype, "privateLabel", void 0);
728
+ ], Payment.prototype, "privateLabel", void 0);
785
729
  tslib.__decorate([
786
730
  classTransformer.Expose({ name: 'pix_qr_code' }),
787
731
  tslib.__metadata("design:type", String)
788
- ], PaymentTransaction.prototype, "pixQrCode", void 0);
732
+ ], Payment.prototype, "pixQrCode", void 0);
789
733
  tslib.__decorate([
790
734
  classTransformer.Expose({ name: 'pix_expiration_date' }),
791
735
  tslib.__metadata("design:type", String)
792
- ], PaymentTransaction.prototype, "pixExpirationDate", void 0);
793
-
794
- class Payment extends BaseModel {
795
- static get identifiersFields() {
796
- return ['id'];
797
- }
798
- }
799
- tslib.__decorate([
800
- classTransformer.Type(() => PaymentTransaction),
801
- tslib.__metadata("design:type", PaymentTransaction)
802
- ], Payment.prototype, "transaction", void 0);
736
+ ], Payment.prototype, "pixExpirationDate", void 0);
803
737
 
804
738
  class SubscriptionPayment extends BaseModel {
805
739
  static get identifiersFields() {
@@ -2216,7 +2150,45 @@ exports.CouponCategory = void 0;
2216
2150
  CouponCategory["CRM"] = "CRM";
2217
2151
  CouponCategory["LOJAUNICO"] = "Loja \u00FAnico";
2218
2152
  CouponCategory["Outros"] = "Outros";
2219
- })(exports.CouponCategory || (exports.CouponCategory = {}));
2153
+ })(exports.CouponCategory || (exports.CouponCategory = {}));
2154
+ exports.CouponOldCategories = void 0;
2155
+ (function (CouponOldCategories) {
2156
+ CouponOldCategories["Reembolso"] = "Reembolso";
2157
+ CouponOldCategories["Desculpas"] = "Desculpas";
2158
+ CouponOldCategories["BFlu"] = "BFlu";
2159
+ CouponOldCategories["ROYAL"] = "Royal";
2160
+ CouponOldCategories["Glamqueen"] = "Glamqueen";
2161
+ CouponOldCategories["Glampartner"] = "Glampartner";
2162
+ CouponOldCategories["Glamgirl"] = "Glamgirl";
2163
+ CouponOldCategories["Glamdiva"] = "Glamdiva";
2164
+ CouponOldCategories["Impulsionamento"] = "Impulsionamento";
2165
+ CouponOldCategories["PaidMedia"] = "Paid Media";
2166
+ CouponOldCategories["Organic"] = "Organic";
2167
+ CouponOldCategories["Direct"] = "Direct";
2168
+ CouponOldCategories["CRM"] = "CRM";
2169
+ CouponOldCategories["LOJAUNICO"] = "Loja \u00FAnico";
2170
+ CouponOldCategories["Outros"] = "Outros";
2171
+ })(exports.CouponOldCategories || (exports.CouponOldCategories = {}));
2172
+ exports.CouponCategories = void 0;
2173
+ (function (CouponCategories) {
2174
+ CouponCategories["API_LOJAUNICA"] = "API_LOJAUNICA";
2175
+ CouponCategories["COMPRE_E_GANHE"] = "COMPRE_E_GANHE";
2176
+ CouponCategories["DESCONTO"] = "DESCONTO";
2177
+ CouponCategories["REEMBOLSO"] = "REEMBOLSO";
2178
+ CouponCategories["DESCULPAS"] = "DESCULPAS";
2179
+ })(exports.CouponCategories || (exports.CouponCategories = {}));
2180
+
2181
+ exports.CouponChannels = void 0;
2182
+ (function (CouponChannels) {
2183
+ CouponChannels["BANNER"] = "7";
2184
+ CouponChannels["BFLUENCE"] = "3";
2185
+ CouponChannels["CRM"] = "2";
2186
+ CouponChannels["GLAMGIRL"] = "0";
2187
+ CouponChannels["PAID"] = "4";
2188
+ CouponChannels["ROYAL"] = "1";
2189
+ CouponChannels["SAC"] = "8";
2190
+ CouponChannels["SOCIAL"] = "5";
2191
+ })(exports.CouponChannels || (exports.CouponChannels = {}));
2220
2192
 
2221
2193
  exports.CouponSubtypes = void 0;
2222
2194
  (function (CouponSubtypes) {
@@ -2263,8 +2235,8 @@ exports.OrderStatus = void 0;
2263
2235
  class Order extends Checkout {
2264
2236
  }
2265
2237
  tslib.__decorate([
2266
- classTransformer.Type(() => PaymentTransaction),
2267
- tslib.__metadata("design:type", PaymentTransaction)
2238
+ classTransformer.Type(() => Payment),
2239
+ tslib.__metadata("design:type", Payment)
2268
2240
  ], Order.prototype, "payment", void 0);
2269
2241
 
2270
2242
  class OrderBlocked extends BaseModel {
@@ -2295,592 +2267,6 @@ tslib.__decorate([
2295
2267
  tslib.__metadata("design:type", Coupon)
2296
2268
  ], CheckoutSubscription.prototype, "coupon", void 0);
2297
2269
 
2298
- class BusinessError extends tsCustomError.CustomError {
2299
- constructor(message, additionalData, type = '') {
2300
- super(message);
2301
- this.additionalData = additionalData;
2302
- this.type = type;
2303
- }
2304
- }
2305
-
2306
- class DuplicatedResultsError extends tsCustomError.CustomError {
2307
- constructor(message) {
2308
- super(message);
2309
- }
2310
- }
2311
-
2312
- class FraudValidationError extends tsCustomError.CustomError {
2313
- constructor(message, additionalData) {
2314
- super(message);
2315
- this.additionalData = additionalData;
2316
- this.type = 'antifraud';
2317
- }
2318
- }
2319
-
2320
- class InvalidArgumentError extends tsCustomError.CustomError {
2321
- constructor(message) {
2322
- super(message);
2323
- }
2324
- }
2325
-
2326
- class NotFoundError extends tsCustomError.CustomError {
2327
- constructor(message) {
2328
- super(message);
2329
- }
2330
- }
2331
-
2332
- class PaymentError extends tsCustomError.CustomError {
2333
- constructor(message, additionalData) {
2334
- super(message);
2335
- this.additionalData = additionalData;
2336
- this.type = 'payment';
2337
- }
2338
- }
2339
-
2340
- class RequiredArgumentError extends tsCustomError.CustomError {
2341
- constructor(args) {
2342
- super(`Required arguments: ${args.join(', ')}`);
2343
- this.args = args;
2344
- this.arguments = args;
2345
- }
2346
- }
2347
-
2348
- class StockLimitError extends BusinessError {
2349
- constructor(message, additionalData) {
2350
- super(message, additionalData);
2351
- this.type = 'stock-limit';
2352
- }
2353
- }
2354
-
2355
- class StockOutError extends BusinessError {
2356
- constructor(message, additionalData) {
2357
- super(message, additionalData);
2358
- this.type = 'stock-out';
2359
- }
2360
- }
2361
-
2362
- class AdyenCardService {
2363
- constructor(credentials, paymentRepository, orderBlockedRepository) {
2364
- this.credentials = credentials;
2365
- this.paymentRepository = paymentRepository;
2366
- this.orderBlockedRepository = orderBlockedRepository;
2367
- }
2368
- async pay(checkout, card) {
2369
- try {
2370
- const result = await axios__default["default"]({
2371
- method: 'POST',
2372
- url: this.credentials.URL_TRANSACTION,
2373
- headers: {
2374
- 'x-api-key': this.credentials.API_KEY,
2375
- 'content-type': 'application/json',
2376
- },
2377
- data: this.createCardPayment(checkout, card),
2378
- });
2379
- if (result.data.resultCode !== 'Authorised') {
2380
- this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
2381
- 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`, {
2382
- checkoutId: checkout.id,
2383
- userEmail: checkout.user.email,
2384
- info: result.data,
2385
- }));
2386
- }
2387
- const payment = await this.paymentRepository.create(Payment.toInstance({
2388
- createdAt: new Date(),
2389
- updatedAt: new Date(),
2390
- userId: checkout.user.id,
2391
- checkoutId: checkout.id,
2392
- totalPrice: checkout.totalPrice,
2393
- paymentProvider: 'adyen',
2394
- transaction: Object.assign(Object.assign({}, result.data), { status: 'paid' }),
2395
- }));
2396
- return payment;
2397
- }
2398
- catch (error) {
2399
- 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', {
2400
- checkoutId: checkout.id,
2401
- userEmail: checkout.user.email,
2402
- info: error.message,
2403
- });
2404
- }
2405
- }
2406
- createCardPayment(checkout, card) {
2407
- return {
2408
- amount: {
2409
- currency: 'BRL',
2410
- value: ((checkout === null || checkout === void 0 ? void 0 : checkout.totalPrice) || 0) * 100,
2411
- },
2412
- paymentMethod: {
2413
- type: 'scheme',
2414
- storedPaymentMethodId: card.cardId,
2415
- },
2416
- reference: checkout.id,
2417
- shopperInteraction: 'Ecommerce',
2418
- merchantAccount: this.credentials.MERCHANT_ACCOUNT,
2419
- shopperReference: checkout.user.id,
2420
- recurringProcessingModel: 'CardOnFile',
2421
- returnUrl: this.credentials.URL_POSTBACK,
2422
- installments: {
2423
- value: card.installments,
2424
- },
2425
- };
2426
- }
2427
- addCard() {
2428
- throw new Error('Method not implemented.');
2429
- }
2430
- }
2431
-
2432
- class AntifraudBankSlipService {
2433
- constructor(orderBlockedRepository) {
2434
- this.orderBlockedRepository = orderBlockedRepository;
2435
- this.MAX_ORDER_VALUE = 5000;
2436
- }
2437
- async validate(checkout) {
2438
- var _a, _b;
2439
- if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber)) {
2440
- await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Boleto not authorized', 'Boleto', 'day');
2441
- throw new FraudValidationError('Boleto não autorizado para cliente não assinante', {
2442
- checkoutId: checkout.id,
2443
- userEmail: checkout.user.email,
2444
- info: {
2445
- isSubscriber: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.isSubscriber,
2446
- subtotal: checkout.subTotalPrice,
2447
- total: checkout.totalPrice,
2448
- },
2449
- });
2450
- }
2451
- return true;
2452
- }
2453
- }
2454
-
2455
- class AntifraudCardService {
2456
- constructor(orderRepository, orderBlockedRepository) {
2457
- this.orderRepository = orderRepository;
2458
- this.orderBlockedRepository = orderBlockedRepository;
2459
- this.LIMIT_ORDERS_DAY = 2;
2460
- this.LIMIT_ORDERS_WEEK = 7;
2461
- this.LIMIT_BLOCKED_ORDERS_DAY = 5;
2462
- }
2463
- async validate(checkout, card) {
2464
- var _a, _b;
2465
- if (!(await this.verifyBlockedOrderAttempts(checkout, card)))
2466
- throw new FraudValidationError('Cliente com mais de 5 compras negadas/bloqueadas no dia', {
2467
- checkoutId: checkout.id,
2468
- userEmail: checkout.user.email,
2469
- info: {
2470
- isSubscriber: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber,
2471
- subtotal: checkout.subTotalPrice,
2472
- total: checkout.totalPrice,
2473
- },
2474
- });
2475
- if (!(await this.verifyDayAndWeekOrders(checkout, card)))
2476
- throw new FraudValidationError('Cliente tentando comprar mais de 2 vezes no dia ou 7 vezes na semana', {
2477
- checkoutId: checkout.id,
2478
- userEmail: checkout.user.email,
2479
- info: {
2480
- isSubscriber: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.isSubscriber,
2481
- subtotal: checkout.subTotalPrice,
2482
- total: checkout.totalPrice,
2483
- },
2484
- });
2485
- return true;
2486
- }
2487
- async verifyBlockedOrderAttempts(checkout, card) {
2488
- var _a, _b, _c, _d;
2489
- const day = `${dateFns.format(new Date(), 'YYYY-MM-DD')}T00:00:00`;
2490
- const endOfDay = `${dateFns.format(new Date(), 'YYYY-MM-DD')}T23:59:59`;
2491
- const ordersBlockedWithCpf = await this.orderBlockedRepository
2492
- .find({
2493
- filters: {
2494
- customer: { cpf: { operator: exports.Where.EQUALS, value: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf } },
2495
- date: [
2496
- { operator: exports.Where.GTE, value: new Date(day) },
2497
- { operator: exports.Where.LTE, value: new Date(endOfDay) },
2498
- ],
2499
- },
2500
- })
2501
- .then((data) => data.data);
2502
- const ordersBlockedWithEmail = await this.orderBlockedRepository
2503
- .find({
2504
- filters: {
2505
- customer: { email: { operator: exports.Where.EQUALS, value: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email } },
2506
- date: [
2507
- { operator: exports.Where.GTE, value: new Date(day) },
2508
- { operator: exports.Where.LTE, value: new Date(endOfDay) },
2509
- ],
2510
- },
2511
- })
2512
- .then((data) => data.data);
2513
- const ordersBlockedWithCep = await this.orderBlockedRepository
2514
- .find({
2515
- filters: {
2516
- customer: { shippingAddress: { zip: { operator: exports.Where.EQUALS, value: (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip } } },
2517
- date: [
2518
- { operator: exports.Where.GTE, value: new Date(day) },
2519
- { operator: exports.Where.LTE, value: new Date(endOfDay) },
2520
- ],
2521
- },
2522
- })
2523
- .then((data) => data.data);
2524
- const ordersBlockedWithPhone = await this.orderBlockedRepository
2525
- .find({
2526
- filters: {
2527
- customer: { phoneNumber: { operator: exports.Where.EQUALS, value: (_d = checkout.user) === null || _d === void 0 ? void 0 : _d.phone } },
2528
- date: [
2529
- { operator: exports.Where.GTE, value: new Date(day) },
2530
- { operator: exports.Where.LTE, value: new Date(endOfDay) },
2531
- ],
2532
- },
2533
- })
2534
- .then((data) => data.data);
2535
- const blockedUniqueEmails = ordersBlockedWithEmail.filter((e) => {
2536
- var _a;
2537
- return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf);
2538
- });
2539
- const blockedUniqueCeps = ordersBlockedWithCep.filter((e) => {
2540
- var _a, _b;
2541
- 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);
2542
- });
2543
- const blockedUniquePhone = ordersBlockedWithPhone.filter((e) => {
2544
- var _a, _b, _c, _d, _e, _f;
2545
- return (e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf) &&
2546
- e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email) &&
2547
- ((_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()));
2548
- });
2549
- const blockedAttempts = ordersBlockedWithCpf
2550
- .concat(blockedUniqueEmails)
2551
- .concat(blockedUniqueCeps)
2552
- .concat(blockedUniquePhone);
2553
- if (blockedAttempts.length >= this.LIMIT_BLOCKED_ORDERS_DAY) {
2554
- await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'More than 5 attempts have failed', 'Failed attempts', 'day', card || null);
2555
- return false;
2556
- }
2557
- return true;
2558
- }
2559
- async verifyDayAndWeekOrders(checkout, card) {
2560
- var _a, _b, _c, _d, _e, _f, _g, _h;
2561
- 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'));
2562
- for (const key in ordersPerDay) {
2563
- if (ordersPerDay[key] > this.LIMIT_ORDERS_DAY) {
2564
- await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'day');
2565
- return false;
2566
- }
2567
- }
2568
- 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'));
2569
- for (const key in ordersPerWeek) {
2570
- if (ordersPerDay[key] > this.LIMIT_ORDERS_WEEK) {
2571
- await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'week');
2572
- return false;
2573
- }
2574
- }
2575
- return true;
2576
- }
2577
- async validateOrdersByRange(cpf, email, phone, zip, card, range) {
2578
- const ordersCpf = await this.countOrdersByField('user', 'cpf', cpf, range);
2579
- const ordersByEmail = await this.countOrdersByField('user', 'email', email, range);
2580
- const ordersByPhone = await this.countOrdersByField('user', 'phone', phone, range);
2581
- const ordersByZip = await this.countOrdersByField('shippingAddress', 'zip', zip, range);
2582
- return {
2583
- cpf: ordersCpf,
2584
- email: ordersByEmail,
2585
- phone: ordersByPhone,
2586
- zip: ordersByZip,
2587
- };
2588
- }
2589
- async countOrdersByField(property, field, value, range) {
2590
- const filters = {
2591
- [property]: {
2592
- [field]: value,
2593
- },
2594
- ['createdAt']: [
2595
- { operator: exports.Where.GTE, value: range.firstDate },
2596
- { operator: exports.Where.LTE, value: range.lastDate },
2597
- ],
2598
- };
2599
- const docs = await (await this.orderRepository.find({ filters })).count;
2600
- return docs;
2601
- }
2602
- getDateRange(range = 'day') {
2603
- switch (range) {
2604
- case 'day':
2605
- return {
2606
- firstDate: dateFns.startOfDay(new Date()).getTime(),
2607
- lastDate: dateFns.endOfDay(new Date()).getTime(),
2608
- };
2609
- case 'week':
2610
- return {
2611
- firstDate: dateFns.startOfDay(dateFns.subDays(new Date(), 7)).getTime(),
2612
- lastDate: dateFns.endOfDay(new Date()).getTime(),
2613
- };
2614
- default:
2615
- return {
2616
- firstDate: dateFns.startOfDay(new Date()).getTime(),
2617
- lastDate: dateFns.endOfDay(new Date()).getTime(),
2618
- };
2619
- }
2620
- }
2621
- }
2622
-
2623
- class AntifraudGlampointsService {
2624
- constructor() { }
2625
- async validate(checkout) {
2626
- return true;
2627
- }
2628
- }
2629
-
2630
- class AntifraudPixService {
2631
- constructor() { }
2632
- async validate(checkout) {
2633
- return true;
2634
- }
2635
- }
2636
-
2637
- class GlampointsPaymentService {
2638
- constructor(paymentRepository) {
2639
- this.paymentRepository = paymentRepository;
2640
- }
2641
- async pay(checkout) {
2642
- const payment = await this.paymentRepository.create(Payment.toInstance({
2643
- createdAt: new Date(),
2644
- updatedAt: new Date(),
2645
- userId: checkout.user.id,
2646
- checkoutId: checkout.id,
2647
- totalPrice: checkout.totalPrice,
2648
- paymentProvider: 'glampoints',
2649
- transaction: {
2650
- amount: 0,
2651
- acquirerResponseCode: '0000',
2652
- acquirerName: 'glampoints',
2653
- authorizedAmount: 0,
2654
- captureMethod: 'ecommerce',
2655
- installments: 1,
2656
- cost: 0,
2657
- paidAmount: 0,
2658
- paidAt: new Date().toISOString(),
2659
- paymentMethod: 'glampoints',
2660
- referer: 'api_key',
2661
- refundedAmount: 0,
2662
- status: 'paid',
2663
- statusReason: 'acquirer',
2664
- },
2665
- }));
2666
- return payment;
2667
- }
2668
- }
2669
-
2670
- class PagarmeBankSlipService {
2671
- constructor(credentials, paymentRepository) {
2672
- this.credentials = credentials;
2673
- this.paymentRepository = paymentRepository;
2674
- }
2675
- async pay(checkout) {
2676
- try {
2677
- const result = await axios__default["default"]({
2678
- method: 'POST',
2679
- url: this.credentials.URL_TRANSACTION,
2680
- data: this.createBoletoPayment(checkout),
2681
- });
2682
- if (result.data.status !== 'processing') {
2683
- return Promise.reject(new PaymentError(`Houve uma falha ao gerar o boleto. Tente novamente`, {
2684
- checkoutId: checkout.id,
2685
- userEmail: checkout.user.email,
2686
- info: result.data,
2687
- }));
2688
- }
2689
- const payment = await this.paymentRepository.create(Payment.toInstance({
2690
- createdAt: new Date(),
2691
- updatedAt: new Date(),
2692
- userId: checkout.user.id,
2693
- checkoutId: checkout.id,
2694
- totalPrice: checkout.totalPrice,
2695
- paymentProvider: 'pagarMe',
2696
- transaction: result.data,
2697
- }));
2698
- return payment;
2699
- }
2700
- catch (error) {
2701
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
2702
- checkoutId: checkout.id,
2703
- userEmail: checkout.user.email,
2704
- info: error.response.data,
2705
- });
2706
- }
2707
- }
2708
- createBoletoPayment(checkout) {
2709
- return {
2710
- api_key: this.credentials.API_KEY,
2711
- amount: Math.floor(checkout.totalPrice * 100),
2712
- boleto_rules: ['strict_expiration_date'],
2713
- boleto_instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
2714
- boleto_expiration_date: dateFns.format(dateFns.addDays(new Date(), 3), 'yyyy-MM-dd'),
2715
- payment_method: 'boleto',
2716
- postback_url: this.credentials.URL_POSTBACK,
2717
- customer: {
2718
- external_id: checkout.user.id,
2719
- type: 'individual',
2720
- country: 'br',
2721
- name: checkout.user.displayName,
2722
- documents: [
2723
- {
2724
- type: 'cpf',
2725
- number: checkout.user.cpf,
2726
- },
2727
- ],
2728
- },
2729
- };
2730
- }
2731
- }
2732
-
2733
- class PagarmeCardService {
2734
- constructor(credentials, paymentRepository, orderBlockedRepository) {
2735
- this.credentials = credentials;
2736
- this.paymentRepository = paymentRepository;
2737
- this.orderBlockedRepository = orderBlockedRepository;
2738
- }
2739
- async pay(checkout, card) {
2740
- var _a;
2741
- try {
2742
- const result = await axios__default["default"]({
2743
- method: 'POST',
2744
- url: this.credentials.URL_TRANSACTION,
2745
- data: this.createCardPayment(checkout, card),
2746
- });
2747
- if (result.data.status !== 'paid') {
2748
- await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
2749
- 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`, {
2750
- checkoutId: checkout.id,
2751
- userEmail: checkout.user.email,
2752
- info: result.data,
2753
- }));
2754
- }
2755
- const payment = await this.paymentRepository.create(Payment.toInstance({
2756
- createdAt: new Date(),
2757
- updatedAt: new Date(),
2758
- userId: checkout.user.id,
2759
- checkoutId: checkout.id,
2760
- totalPrice: checkout.totalPrice,
2761
- paymentProvider: exports.PaymentProviders.PAGARME,
2762
- transaction: Object.assign(Object.assign({}, result.data), { paidAt: new Date() }),
2763
- }));
2764
- return payment;
2765
- }
2766
- catch (error) {
2767
- 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', {
2768
- checkoutId: checkout.id,
2769
- userEmail: checkout.user.email,
2770
- info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
2771
- });
2772
- }
2773
- }
2774
- addCard() {
2775
- throw new Error('Method not implemented.');
2776
- }
2777
- createCardPayment(checkout, card) {
2778
- var _a, _b, _c, _d, _e, _f;
2779
- return {
2780
- api_key: this.credentials.API_KEY,
2781
- amount: Math.floor(checkout.totalPrice * 100),
2782
- card_id: card.cardId,
2783
- payment_method: 'credit_card',
2784
- installments: card.installments,
2785
- soft_descriptor: checkout.shop === exports.Shops.GLAMSHOP ? 'Glam' : "Men's Market",
2786
- customer: {
2787
- external_id: checkout.user.id,
2788
- name: checkout.user.displayName,
2789
- type: 'individual',
2790
- country: 'br',
2791
- email: checkout.user.email,
2792
- phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
2793
- documents: [
2794
- {
2795
- type: 'cpf',
2796
- number: checkout.user.cpf,
2797
- },
2798
- ],
2799
- },
2800
- billing: {
2801
- name: checkout.user.displayName,
2802
- address: {
2803
- country: 'br',
2804
- state: checkout.billingAddress ? checkout.billingAddress.state : (_a = checkout.shippingAddress) === null || _a === void 0 ? void 0 : _a.state,
2805
- city: checkout.billingAddress ? checkout.billingAddress.city : (_b = checkout.shippingAddress) === null || _b === void 0 ? void 0 : _b.city,
2806
- neighborhood: checkout.billingAddress ? checkout.billingAddress.district : (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.district,
2807
- street: checkout.billingAddress ? checkout.billingAddress.street : (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.street,
2808
- street_number: checkout.billingAddress ? checkout.billingAddress.number : (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.number,
2809
- zipcode: checkout.billingAddress
2810
- ? checkout.billingAddress.zip.replace('-', '')
2811
- : (_f = checkout.shippingAddress) === null || _f === void 0 ? void 0 : _f.zip.replace('-', ''),
2812
- },
2813
- },
2814
- items: checkout.lineItems.map((item) => {
2815
- return {
2816
- id: item.id,
2817
- title: checkout.user.isSubscriber ? `${item.name} - ASSINANTE` : item.name,
2818
- unit_price: Math.floor(item.pricePaid * 100),
2819
- quantity: item.quantity,
2820
- tangible: true,
2821
- };
2822
- }),
2823
- };
2824
- }
2825
- }
2826
-
2827
- class PagarmePixService {
2828
- constructor(credentials, paymentRepository) {
2829
- this.credentials = credentials;
2830
- this.paymentRepository = paymentRepository;
2831
- }
2832
- async pay(checkout) {
2833
- var _a;
2834
- try {
2835
- const result = await axios__default["default"]({
2836
- method: 'POST',
2837
- url: this.credentials.URL_TRANSACTION,
2838
- data: this.createPixPayment(checkout),
2839
- });
2840
- const payment = await this.paymentRepository.create(Payment.toInstance({
2841
- createdAt: new Date(),
2842
- updatedAt: new Date(),
2843
- userId: checkout.user.id,
2844
- checkoutId: checkout.id,
2845
- totalPrice: checkout.totalPrice,
2846
- paymentProvider: 'pagarMe',
2847
- transaction: Object.assign(Object.assign({}, result.data), { paidAt: new Date() }),
2848
- }));
2849
- return payment;
2850
- }
2851
- catch (error) {
2852
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
2853
- checkoutId: checkout.id,
2854
- userEmail: checkout.user.email,
2855
- info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
2856
- });
2857
- }
2858
- }
2859
- createPixPayment(checkout) {
2860
- return {
2861
- payment_method: 'pix',
2862
- amount: Math.floor(checkout.totalPrice * 100),
2863
- api_key: this.credentials.API_KEY,
2864
- postback_url: this.credentials.URL_POSTBACK,
2865
- pix_expiration_date: dateFns.format(dateFns.addDays(new Date(), 1), 'yyyy-MM-dd'),
2866
- customer: {
2867
- external_id: checkout.user.id,
2868
- type: 'individual',
2869
- country: 'br',
2870
- name: checkout.user.displayName,
2871
- email: checkout.user.email.trim(),
2872
- phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
2873
- documents: [
2874
- {
2875
- type: 'cpf',
2876
- number: checkout.user.cpf,
2877
- },
2878
- ],
2879
- },
2880
- };
2881
- }
2882
- }
2883
-
2884
2270
  class RoundProductPricesHelper {
2885
2271
  static roundProductPrices(product) {
2886
2272
  product.price.price = Number(product.price.price.toFixed(2));
@@ -2901,12 +2287,6 @@ class LogDocument extends BaseModel {
2901
2287
  }
2902
2288
  }
2903
2289
 
2904
- class Sequence extends BaseModel {
2905
- static get identifiersFields() {
2906
- return ['id'];
2907
- }
2908
- }
2909
-
2910
2290
  exports.FilterType = void 0;
2911
2291
  (function (FilterType) {
2912
2292
  FilterType["ACCESSORY_IMPORTANCE"] = "accessoryImportance";
@@ -3045,6 +2425,32 @@ class ShopSettings extends BaseModel {
3045
2425
  }
3046
2426
  }
3047
2427
 
2428
+ class InvalidArgumentError extends tsCustomError.CustomError {
2429
+ constructor(message) {
2430
+ super(message);
2431
+ }
2432
+ }
2433
+
2434
+ class RequiredArgumentError extends tsCustomError.CustomError {
2435
+ constructor(args) {
2436
+ super(`Required arguments: ${args.join(', ')}`);
2437
+ this.args = args;
2438
+ this.arguments = args;
2439
+ }
2440
+ }
2441
+
2442
+ class NotFoundError extends tsCustomError.CustomError {
2443
+ constructor(message) {
2444
+ super(message);
2445
+ }
2446
+ }
2447
+
2448
+ class DuplicatedResultsError extends tsCustomError.CustomError {
2449
+ constructor(message) {
2450
+ super(message);
2451
+ }
2452
+ }
2453
+
3048
2454
  class AxiosAdapter {
3049
2455
  constructor(config) {
3050
2456
  this.config = config;
@@ -3943,17 +3349,6 @@ class LogFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore
3943
3349
  }
3944
3350
  }
3945
3351
 
3946
- class SequenceFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3947
- constructor({ firestore, interceptors }) {
3948
- super({
3949
- firestore,
3950
- collectionName: 'sequences',
3951
- model: Sequence,
3952
- interceptors,
3953
- });
3954
- }
3955
- }
3956
-
3957
3352
  class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3958
3353
  constructor({ firestore, interceptors }) {
3959
3354
  super({
@@ -5095,6 +4490,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
5095
4490
  return class FindHasuraGraphQLMixin extends MixinBase {
5096
4491
  constructor() {
5097
4492
  super(...arguments);
4493
+ this.lastDistinct = {};
5098
4494
  this.bindOrderByAttributes = (orderBy, fields) => Object.keys(orderBy).reduce((acc, current) => [
5099
4495
  ...acc,
5100
4496
  {
@@ -5130,9 +4526,10 @@ const withFindHasuraGraphQL = (MixinBase) => {
5130
4526
  });
5131
4527
  }
5132
4528
  async find(params) {
5133
- var _a, _b, _c, _d, _e, _f, _g, _h;
4529
+ var _a, _b, _c, _d, _e, _f, _g;
5134
4530
  this.logger = DebugHelper.from(this, 'find');
5135
4531
  const { filters, limits, orderBy, options } = params || {};
4532
+ const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
5136
4533
  const enableCount = (_a = options === null || options === void 0 ? void 0 : options.enableCount) !== null && _a !== void 0 ? _a : true;
5137
4534
  const variablesFilters = lodash.isNil(filters)
5138
4535
  ? {}
@@ -5183,8 +4580,8 @@ const withFindHasuraGraphQL = (MixinBase) => {
5183
4580
  },
5184
4581
  ]
5185
4582
  : []),
5186
- ...((!((_b = params.limits) === null || _b === void 0 ? void 0 : _b.offset) &&
5187
- ((_d = (_c = params.options) === null || _c === void 0 ? void 0 : _c.distinct) === null || _d === void 0 ? void 0 : _d.map((distinct) => {
4583
+ ...((!this.lastDistinct[tableFiltersNamed] &&
4584
+ ((_c = (_b = params.options) === null || _b === void 0 ? void 0 : _b.distinct) === null || _c === void 0 ? void 0 : _c.map((distinct) => {
5188
4585
  var _a, _b;
5189
4586
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
5190
4587
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
@@ -5205,28 +4602,27 @@ const withFindHasuraGraphQL = (MixinBase) => {
5205
4602
  []),
5206
4603
  ]);
5207
4604
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
5208
- return Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_e = options === null || options === void 0 ? void 0 : options.minimal) === null || _e === void 0 ? void 0 : _e.length)
4605
+ return Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_d = options === null || options === void 0 ? void 0 : options.minimal) === null || _d === void 0 ? void 0 : _d.length)
5209
4606
  ? {
5210
4607
  minimal: options.minimal.reduce((minimals, current) => {
5211
4608
  var _a;
5212
4609
  return (Object.assign(Object.assign({}, minimals), lodash.set(minimals, current, result[`${this.tableName}_aggregate`].aggregate.min[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
5213
4610
  }, {}),
5214
4611
  }
5215
- : {})), (((_f = options === null || options === void 0 ? void 0 : options.maximum) === null || _f === void 0 ? void 0 : _f.length)
4612
+ : {})), (((_e = options === null || options === void 0 ? void 0 : options.maximum) === null || _e === void 0 ? void 0 : _e.length)
5216
4613
  ? {
5217
4614
  maximum: options.maximum.reduce((maximums, current) => {
5218
4615
  var _a;
5219
4616
  return (Object.assign(Object.assign({}, maximums), lodash.set(maximums, current, result[`${this.tableName}_aggregate`].aggregate.max[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
5220
4617
  }, {}),
5221
4618
  }
5222
- : {})), (!((_g = params.limits) === null || _g === void 0 ? void 0 : _g.offset) &&
5223
- ((_h = options === null || options === void 0 ? void 0 : options.distinct) === null || _h === void 0 ? void 0 : _h.length) && {
5224
- distinct: options === null || options === void 0 ? void 0 : options.distinct.reduce((distinct, current) => {
4619
+ : {})), (((_f = options === null || options === void 0 ? void 0 : options.distinct) === null || _f === void 0 ? void 0 : _f.length) && {
4620
+ distinct: (_g = this.lastDistinct[tableFiltersNamed]) !== null && _g !== void 0 ? _g : (this.lastDistinct[tableFiltersNamed] = options === null || options === void 0 ? void 0 : options.distinct.reduce((distinct, current) => {
5225
4621
  var _a, _b;
5226
4622
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
5227
4623
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
5228
4624
  return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
5229
- }, {}),
4625
+ }, {})),
5230
4626
  }));
5231
4627
  }
5232
4628
  };
@@ -7293,10 +6689,6 @@ Object.defineProperty(exports, 'sub', {
7293
6689
  enumerable: true,
7294
6690
  get: function () { return dateFns.sub; }
7295
6691
  });
7296
- Object.defineProperty(exports, 'subDays', {
7297
- enumerable: true,
7298
- get: function () { return dateFns.subDays; }
7299
- });
7300
6692
  Object.defineProperty(exports, 'chunk', {
7301
6693
  enumerable: true,
7302
6694
  get: function () { return lodash.chunk; }
@@ -7370,13 +6762,6 @@ Object.defineProperty(exports, 'unset', {
7370
6762
  get: function () { return lodash.unset; }
7371
6763
  });
7372
6764
  exports.Address = Address;
7373
- exports.AdyenCardService = AdyenCardService;
7374
- exports.AdyenPaymentMethodFactory = AdyenPaymentMethodFactory;
7375
- exports.AntifraudBankSlipService = AntifraudBankSlipService;
7376
- exports.AntifraudCardService = AntifraudCardService;
7377
- exports.AntifraudGlampointsService = AntifraudGlampointsService;
7378
- exports.AntifraudPixService = AntifraudPixService;
7379
- exports.AntifraudProviderFactory = AntifraudProviderFactory;
7380
6765
  exports.Authentication = Authentication;
7381
6766
  exports.AuthenticationFirebaseAuthService = AuthenticationFirebaseAuthService;
7382
6767
  exports.AxiosAdapter = AxiosAdapter;
@@ -7384,7 +6769,6 @@ exports.Base = Base;
7384
6769
  exports.BaseModel = BaseModel;
7385
6770
  exports.BeautyProfile = BeautyProfile;
7386
6771
  exports.BeautyQuestionsHelper = BeautyQuestionsHelper;
7387
- exports.BusinessError = BusinessError;
7388
6772
  exports.Buy2Win = Buy2Win;
7389
6773
  exports.Buy2WinFirestoreRepository = Buy2WinFirestoreRepository;
7390
6774
  exports.Campaign = Campaign;
@@ -7422,9 +6806,6 @@ exports.FilterHasuraGraphQLRepository = FilterHasuraGraphQLRepository;
7422
6806
  exports.FilterOption = FilterOption;
7423
6807
  exports.FilterOptionHasuraGraphQLRepository = FilterOptionHasuraGraphQLRepository;
7424
6808
  exports.FirebaseFileUploaderService = FirebaseFileUploaderService;
7425
- exports.FraudValidationError = FraudValidationError;
7426
- exports.GlampointsPaymentMethodFactory = GlampointsPaymentMethodFactory;
7427
- exports.GlampointsPaymentService = GlampointsPaymentService;
7428
6809
  exports.Home = Home;
7429
6810
  exports.HomeFirestoreRepository = HomeFirestoreRepository;
7430
6811
  exports.InvalidArgumentError = InvalidArgumentError;
@@ -7443,15 +6824,8 @@ exports.Order = Order;
7443
6824
  exports.OrderBlocked = OrderBlocked;
7444
6825
  exports.OrderBlockedFirestoreRepository = OrderBlockedFirestoreRepository;
7445
6826
  exports.OrderFirestoreRepository = OrderFirestoreRepository;
7446
- exports.PagarmeBankSlipService = PagarmeBankSlipService;
7447
- exports.PagarmeCardService = PagarmeCardService;
7448
- exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
7449
- exports.PagarmePixService = PagarmePixService;
7450
6827
  exports.Payment = Payment;
7451
- exports.PaymentError = PaymentError;
7452
6828
  exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
7453
- exports.PaymentProviderFactory = PaymentProviderFactory;
7454
- exports.PaymentTransaction = PaymentTransaction;
7455
6829
  exports.Product = Product;
7456
6830
  exports.ProductFirestoreRepository = ProductFirestoreRepository;
7457
6831
  exports.ProductHasuraGraphQL = ProductHasuraGraphQL;
@@ -7469,16 +6843,12 @@ exports.Register = Register;
7469
6843
  exports.RegisterFirebaseAuthService = RegisterFirebaseAuthService;
7470
6844
  exports.RequiredArgumentError = RequiredArgumentError;
7471
6845
  exports.RoundProductPricesHelper = RoundProductPricesHelper;
7472
- exports.Sequence = Sequence;
7473
- exports.SequenceFirestoreRepository = SequenceFirestoreRepository;
7474
6846
  exports.ShippingMethod = ShippingMethod;
7475
6847
  exports.ShopMenu = ShopMenu;
7476
6848
  exports.ShopMenuFirestoreRepository = ShopMenuFirestoreRepository;
7477
6849
  exports.ShopSettings = ShopSettings;
7478
6850
  exports.ShopSettingsFirestoreRepository = ShopSettingsFirestoreRepository;
7479
6851
  exports.SignOut = SignOut;
7480
- exports.StockLimitError = StockLimitError;
7481
- exports.StockOutError = StockOutError;
7482
6852
  exports.Subscription = Subscription;
7483
6853
  exports.SubscriptionEditionFirestoreRepository = SubscriptionEditionFirestoreRepository;
7484
6854
  exports.SubscriptionFirestoreRepository = SubscriptionFirestoreRepository;