@infrab4a/connect 4.11.2-beta.0 → 4.12.0-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 (64) hide show
  1. package/index.cjs.js +1003 -343
  2. package/index.esm.js +980 -346
  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 +4 -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 +1 -0
  30. package/src/domain/shopping/models/order.d.ts +2 -2
  31. package/src/domain/shopping/models/payment-transaction.d.ts +67 -0
  32. package/src/domain/shopping/models/payment.d.ts +10 -63
  33. package/src/domain/shopping/models/types/index.d.ts +4 -4
  34. package/src/domain/shopping/services/adyen-card-payment.service.d.ts +13 -0
  35. package/src/domain/shopping/services/antifraud-bankslip.service.d.ts +9 -0
  36. package/src/domain/shopping/services/antifraud-card.service.d.ts +18 -0
  37. package/src/domain/shopping/services/antifraud-glampoints.service.d.ts +6 -0
  38. package/src/domain/shopping/services/antifraud-pix.service.d.ts +6 -0
  39. package/src/domain/shopping/services/glampoints-payment.service.d.ts +8 -0
  40. package/src/domain/shopping/services/index.d.ts +9 -0
  41. package/src/domain/shopping/services/pagarme-bank-slip-payment.service.d.ts +11 -0
  42. package/src/domain/shopping/services/pagarme-card-payment.service.d.ts +13 -0
  43. package/src/domain/shopping/services/pagarme-pix-payment.service.d.ts +11 -0
  44. package/src/domain/shopping/types/adyen-credentials.type.d.ts +6 -0
  45. package/src/domain/shopping/types/antifraud-provider.type.d.ts +2 -0
  46. package/src/domain/shopping/types/index.d.ts +5 -0
  47. package/src/domain/shopping/types/pagarme-credentials.type.d.ts +5 -0
  48. package/src/domain/shopping/types/payment-method.type.d.ts +2 -0
  49. package/src/domain/shopping/types/payment-provider.type.d.ts +2 -0
  50. package/src/errors/business.error.d.ts +7 -0
  51. package/src/errors/fraud-validation.error.d.ts +7 -0
  52. package/src/errors/index.d.ts +7 -2
  53. package/src/errors/payment.error.d.ts +7 -0
  54. package/src/errors/stock-limit.error.d.ts +5 -0
  55. package/src/errors/stock-out.error.d.ts +5 -0
  56. package/src/errors/types/checkout-additional-data-erro.type.d.ts +5 -0
  57. package/src/errors/types/index.d.ts +1 -0
  58. package/src/infra/elasticsearch/indexes/products-index.d.ts +1 -1
  59. package/src/infra/firebase/firestore/repositories/general/index.d.ts +1 -0
  60. package/src/infra/firebase/firestore/repositories/general/sequences-firestore.repository.d.ts +7 -0
  61. package/src/infra/firebase/firestore/repositories/index.d.ts +3 -2
  62. package/src/infra/firebase/firestore/repositories/shopping/index.d.ts +1 -1
  63. package/src/infra/firebase/firestore/repositories/shopping/order-blocked-firestore.repository.d.ts +9 -0
  64. package/src/utils/index.d.ts +2 -2
package/index.cjs.js CHANGED
@@ -19,6 +19,65 @@ 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
+
22
81
  class BaseModel {
23
82
  get identifier() {
24
83
  const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
@@ -556,175 +615,182 @@ exports.Status = void 0;
556
615
  Status["CANCELLED"] = "Cancelado";
557
616
  })(exports.Status || (exports.Status = {}));
558
617
 
559
- class Payment extends BaseModel {
560
- static get identifiersFields() {
561
- return ['id'];
562
- }
618
+ class PaymentTransaction extends BaseModel {
563
619
  }
564
620
  tslib.__decorate([
565
621
  classTransformer.Expose({ name: 'refuse_reason' }),
566
622
  tslib.__metadata("design:type", String)
567
- ], Payment.prototype, "refuseReason", void 0);
623
+ ], PaymentTransaction.prototype, "refuseReason", void 0);
568
624
  tslib.__decorate([
569
625
  classTransformer.Expose({ name: 'status_reason' }),
570
626
  tslib.__metadata("design:type", String)
571
- ], Payment.prototype, "statusReason", void 0);
627
+ ], PaymentTransaction.prototype, "statusReason", void 0);
572
628
  tslib.__decorate([
573
629
  classTransformer.Expose({ name: 'acquirer_response_code' }),
574
630
  tslib.__metadata("design:type", String)
575
- ], Payment.prototype, "acquirerResponseCode", void 0);
631
+ ], PaymentTransaction.prototype, "acquirerResponseCode", void 0);
576
632
  tslib.__decorate([
577
633
  classTransformer.Expose({ name: 'acquirer_name' }),
578
634
  tslib.__metadata("design:type", String)
579
- ], Payment.prototype, "acquirerName", void 0);
635
+ ], PaymentTransaction.prototype, "acquirerName", void 0);
580
636
  tslib.__decorate([
581
637
  classTransformer.Expose({ name: 'acquirer_id' }),
582
638
  tslib.__metadata("design:type", String)
583
- ], Payment.prototype, "acquirerId", void 0);
639
+ ], PaymentTransaction.prototype, "acquirerId", void 0);
584
640
  tslib.__decorate([
585
641
  classTransformer.Expose({ name: 'authorization_code' }),
586
642
  tslib.__metadata("design:type", String)
587
- ], Payment.prototype, "authorizationCode", void 0);
643
+ ], PaymentTransaction.prototype, "authorizationCode", void 0);
588
644
  tslib.__decorate([
589
645
  classTransformer.Expose({ name: 'soft_descriptor' }),
590
646
  tslib.__metadata("design:type", String)
591
- ], Payment.prototype, "softDescriptor", void 0);
647
+ ], PaymentTransaction.prototype, "softDescriptor", void 0);
592
648
  tslib.__decorate([
593
649
  classTransformer.Expose({ name: 'date_created' }),
594
650
  tslib.__metadata("design:type", String)
595
- ], Payment.prototype, "dateCreated", void 0);
651
+ ], PaymentTransaction.prototype, "dateCreated", void 0);
596
652
  tslib.__decorate([
597
653
  classTransformer.Expose({ name: 'date_updated' }),
598
654
  tslib.__metadata("design:type", String)
599
- ], Payment.prototype, "dateUpdated", void 0);
655
+ ], PaymentTransaction.prototype, "dateUpdated", void 0);
600
656
  tslib.__decorate([
601
657
  classTransformer.Expose({ name: 'authorized_amount' }),
602
658
  tslib.__metadata("design:type", Number)
603
- ], Payment.prototype, "authorizedAmount", void 0);
659
+ ], PaymentTransaction.prototype, "authorizedAmount", void 0);
604
660
  tslib.__decorate([
605
661
  classTransformer.Expose({ name: 'paid_amount' }),
606
662
  tslib.__metadata("design:type", Number)
607
- ], Payment.prototype, "paidAmount", void 0);
663
+ ], PaymentTransaction.prototype, "paidAmount", void 0);
608
664
  tslib.__decorate([
609
665
  classTransformer.Expose({ name: 'paid_at' }),
610
666
  tslib.__metadata("design:type", String)
611
- ], Payment.prototype, "paidAt", void 0);
667
+ ], PaymentTransaction.prototype, "paidAt", void 0);
612
668
  tslib.__decorate([
613
669
  classTransformer.Expose({ name: 'refunded_amount' }),
614
670
  tslib.__metadata("design:type", Number)
615
- ], Payment.prototype, "refundedAmount", void 0);
671
+ ], PaymentTransaction.prototype, "refundedAmount", void 0);
616
672
  tslib.__decorate([
617
673
  classTransformer.Expose({ name: 'card_holder_name' }),
618
674
  tslib.__metadata("design:type", String)
619
- ], Payment.prototype, "cardHolderName", void 0);
675
+ ], PaymentTransaction.prototype, "cardHolderName", void 0);
620
676
  tslib.__decorate([
621
677
  classTransformer.Expose({ name: 'card_last_digits' }),
622
678
  tslib.__metadata("design:type", String)
623
- ], Payment.prototype, "cardLastDigits", void 0);
679
+ ], PaymentTransaction.prototype, "cardLastDigits", void 0);
624
680
  tslib.__decorate([
625
681
  classTransformer.Expose({ name: 'card_first_digits' }),
626
682
  tslib.__metadata("design:type", String)
627
- ], Payment.prototype, "cardFirstDigits", void 0);
683
+ ], PaymentTransaction.prototype, "cardFirstDigits", void 0);
628
684
  tslib.__decorate([
629
685
  classTransformer.Expose({ name: 'card_brand' }),
630
686
  tslib.__metadata("design:type", String)
631
- ], Payment.prototype, "cardBrand", void 0);
687
+ ], PaymentTransaction.prototype, "cardBrand", void 0);
632
688
  tslib.__decorate([
633
689
  classTransformer.Expose({ name: 'card_pin_mode' }),
634
690
  tslib.__metadata("design:type", String)
635
- ], Payment.prototype, "cardPinMode", void 0);
691
+ ], PaymentTransaction.prototype, "cardPinMode", void 0);
636
692
  tslib.__decorate([
637
693
  classTransformer.Expose({ name: 'card_magstripe_fallback' }),
638
694
  tslib.__metadata("design:type", Boolean)
639
- ], Payment.prototype, "cardMagstripeFallback", void 0);
695
+ ], PaymentTransaction.prototype, "cardMagstripeFallback", void 0);
640
696
  tslib.__decorate([
641
697
  classTransformer.Expose({ name: 'cvm_pin' }),
642
698
  tslib.__metadata("design:type", Boolean)
643
- ], Payment.prototype, "cvmPin", void 0);
699
+ ], PaymentTransaction.prototype, "cvmPin", void 0);
644
700
  tslib.__decorate([
645
701
  classTransformer.Expose({ name: 'postback_url' }),
646
702
  tslib.__metadata("design:type", String)
647
- ], Payment.prototype, "postbackUrl", void 0);
703
+ ], PaymentTransaction.prototype, "postbackUrl", void 0);
648
704
  tslib.__decorate([
649
705
  classTransformer.Expose({ name: 'payment_method' }),
650
706
  tslib.__metadata("design:type", String)
651
- ], Payment.prototype, "paymentMethod", void 0);
707
+ ], PaymentTransaction.prototype, "paymentMethod", void 0);
652
708
  tslib.__decorate([
653
709
  classTransformer.Expose({ name: 'capture_method' }),
654
710
  tslib.__metadata("design:type", String)
655
- ], Payment.prototype, "captureMethod", void 0);
711
+ ], PaymentTransaction.prototype, "captureMethod", void 0);
656
712
  tslib.__decorate([
657
713
  classTransformer.Expose({ name: 'antifraud_score' }),
658
714
  tslib.__metadata("design:type", String)
659
- ], Payment.prototype, "antifraudScore", void 0);
715
+ ], PaymentTransaction.prototype, "antifraudScore", void 0);
660
716
  tslib.__decorate([
661
717
  classTransformer.Expose({ name: 'boleto_url' }),
662
718
  tslib.__metadata("design:type", String)
663
- ], Payment.prototype, "boletoUrl", void 0);
719
+ ], PaymentTransaction.prototype, "boletoUrl", void 0);
664
720
  tslib.__decorate([
665
721
  classTransformer.Expose({ name: 'boleto_barcode' }),
666
722
  tslib.__metadata("design:type", String)
667
- ], Payment.prototype, "boletoBarcode", void 0);
723
+ ], PaymentTransaction.prototype, "boletoBarcode", void 0);
668
724
  tslib.__decorate([
669
725
  classTransformer.Expose({ name: 'boleto_expiration_date' }),
670
726
  tslib.__metadata("design:type", String)
671
- ], Payment.prototype, "boletoExpirationDate", void 0);
727
+ ], PaymentTransaction.prototype, "boletoExpirationDate", void 0);
672
728
  tslib.__decorate([
673
729
  classTransformer.Expose({ name: 'subscription_id' }),
674
730
  tslib.__metadata("design:type", String)
675
- ], Payment.prototype, "subscriptionId", void 0);
731
+ ], PaymentTransaction.prototype, "subscriptionId", void 0);
676
732
  tslib.__decorate([
677
733
  classTransformer.Expose({ name: 'split_rules' }),
678
734
  tslib.__metadata("design:type", String)
679
- ], Payment.prototype, "splitRules", void 0);
735
+ ], PaymentTransaction.prototype, "splitRules", void 0);
680
736
  tslib.__decorate([
681
737
  classTransformer.Expose({ name: 'antifraud_metadata' }),
682
738
  tslib.__metadata("design:type", Object)
683
- ], Payment.prototype, "antifraudMetadata", void 0);
739
+ ], PaymentTransaction.prototype, "antifraudMetadata", void 0);
684
740
  tslib.__decorate([
685
741
  classTransformer.Expose({ name: 'reference_key' }),
686
742
  tslib.__metadata("design:type", String)
687
- ], Payment.prototype, "referenceKey", void 0);
743
+ ], PaymentTransaction.prototype, "referenceKey", void 0);
688
744
  tslib.__decorate([
689
745
  classTransformer.Expose({ name: 'local_transaction_id' }),
690
746
  tslib.__metadata("design:type", String)
691
- ], Payment.prototype, "localTransactionId", void 0);
747
+ ], PaymentTransaction.prototype, "localTransactionId", void 0);
692
748
  tslib.__decorate([
693
749
  classTransformer.Expose({ name: 'local_time' }),
694
750
  tslib.__metadata("design:type", String)
695
- ], Payment.prototype, "localTime", void 0);
751
+ ], PaymentTransaction.prototype, "localTime", void 0);
696
752
  tslib.__decorate([
697
753
  classTransformer.Expose({ name: 'fraud_covered' }),
698
754
  tslib.__metadata("design:type", Boolean)
699
- ], Payment.prototype, "fraudCovered", void 0);
755
+ ], PaymentTransaction.prototype, "fraudCovered", void 0);
700
756
  tslib.__decorate([
701
757
  classTransformer.Expose({ name: 'fraud_reimbursed' }),
702
758
  tslib.__metadata("design:type", String)
703
- ], Payment.prototype, "fraudReimbursed", void 0);
759
+ ], PaymentTransaction.prototype, "fraudReimbursed", void 0);
704
760
  tslib.__decorate([
705
761
  classTransformer.Expose({ name: 'order_id' }),
706
762
  tslib.__metadata("design:type", String)
707
- ], Payment.prototype, "orderId", void 0);
763
+ ], PaymentTransaction.prototype, "orderId", void 0);
708
764
  tslib.__decorate([
709
765
  classTransformer.Expose({ name: 'risk_level' }),
710
766
  tslib.__metadata("design:type", String)
711
- ], Payment.prototype, "riskLevel", void 0);
767
+ ], PaymentTransaction.prototype, "riskLevel", void 0);
712
768
  tslib.__decorate([
713
769
  classTransformer.Expose({ name: 'receipt_url' }),
714
770
  tslib.__metadata("design:type", String)
715
- ], Payment.prototype, "receiptUrl", void 0);
771
+ ], PaymentTransaction.prototype, "receiptUrl", void 0);
716
772
  tslib.__decorate([
717
773
  classTransformer.Expose({ name: 'private_label' }),
718
774
  tslib.__metadata("design:type", String)
719
- ], Payment.prototype, "privateLabel", void 0);
775
+ ], PaymentTransaction.prototype, "privateLabel", void 0);
720
776
  tslib.__decorate([
721
777
  classTransformer.Expose({ name: 'pix_qr_code' }),
722
778
  tslib.__metadata("design:type", String)
723
- ], Payment.prototype, "pixQrCode", void 0);
779
+ ], PaymentTransaction.prototype, "pixQrCode", void 0);
724
780
  tslib.__decorate([
725
781
  classTransformer.Expose({ name: 'pix_expiration_date' }),
726
782
  tslib.__metadata("design:type", String)
727
- ], Payment.prototype, "pixExpirationDate", void 0);
783
+ ], PaymentTransaction.prototype, "pixExpirationDate", void 0);
784
+
785
+ class Payment extends BaseModel {
786
+ static get identifiersFields() {
787
+ return ['id'];
788
+ }
789
+ }
790
+ tslib.__decorate([
791
+ classTransformer.Type(() => PaymentTransaction),
792
+ tslib.__metadata("design:type", PaymentTransaction)
793
+ ], Payment.prototype, "transaction", void 0);
728
794
 
729
795
  class SubscriptionPayment extends BaseModel {
730
796
  static get identifiersFields() {
@@ -2197,8 +2263,8 @@ exports.OrderStatus = void 0;
2197
2263
  class Order extends Checkout {
2198
2264
  }
2199
2265
  tslib.__decorate([
2200
- classTransformer.Type(() => Payment),
2201
- tslib.__metadata("design:type", Payment)
2266
+ classTransformer.Type(() => PaymentTransaction),
2267
+ tslib.__metadata("design:type", PaymentTransaction)
2202
2268
  ], Order.prototype, "payment", void 0);
2203
2269
 
2204
2270
  class OrderBlocked extends BaseModel {
@@ -2229,6 +2295,592 @@ tslib.__decorate([
2229
2295
  tslib.__metadata("design:type", Coupon)
2230
2296
  ], CheckoutSubscription.prototype, "coupon", void 0);
2231
2297
 
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,
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
+
2232
2884
  class RoundProductPricesHelper {
2233
2885
  static roundProductPrices(product) {
2234
2886
  product.price.price = Number(product.price.price.toFixed(2));
@@ -2243,6 +2895,12 @@ class RoundProductPricesHelper {
2243
2895
  }
2244
2896
  }
2245
2897
 
2898
+ class Sequence extends BaseModel {
2899
+ static get identifiersFields() {
2900
+ return ['id'];
2901
+ }
2902
+ }
2903
+
2246
2904
  exports.FilterType = void 0;
2247
2905
  (function (FilterType) {
2248
2906
  FilterType["ACCESSORY_IMPORTANCE"] = "accessoryImportance";
@@ -2381,36 +3039,10 @@ class ShopSettings extends BaseModel {
2381
3039
  }
2382
3040
  }
2383
3041
 
2384
- class InvalidArgumentError extends tsCustomError.CustomError {
2385
- constructor(message) {
2386
- super(message);
2387
- }
2388
- }
2389
-
2390
- class RequiredArgumentError extends tsCustomError.CustomError {
2391
- constructor(args) {
2392
- super(`Required arguments: ${args.join(', ')}`);
2393
- this.args = args;
2394
- this.arguments = args;
2395
- }
2396
- }
2397
-
2398
- class NotFoundError extends tsCustomError.CustomError {
2399
- constructor(message) {
2400
- super(message);
2401
- }
2402
- }
2403
-
2404
- class DuplicatedResultsError extends tsCustomError.CustomError {
2405
- constructor(message) {
2406
- super(message);
2407
- }
2408
- }
2409
-
2410
- class AxiosAdapter {
2411
- constructor(config) {
2412
- this.config = config;
2413
- this.logger = DebugHelper.from(this);
3042
+ class AxiosAdapter {
3043
+ constructor(config) {
3044
+ this.config = config;
3045
+ this.logger = DebugHelper.from(this);
2414
3046
  }
2415
3047
  async get(index, id) {
2416
3048
  const logger = this.logger.with('get');
@@ -2541,7 +3173,8 @@ class ProductsIndex {
2541
3173
  'rate',
2542
3174
  ];
2543
3175
  const filter = [{ term: { published: true } }];
2544
- // if (shop && shop !== Shops.ALL) filter.push({ term: { tags: shop == Shops.GLAMSHOP ? 'feminino' : 'masculino' } })
3176
+ if (shop && shop !== exports.Shops.ALL)
3177
+ filter.push({ term: { tags: shop == exports.Shops.GLAMSHOP ? 'feminino' : 'masculino' } });
2545
3178
  if (size > 9)
2546
3179
  fields.push(...['pricePaid', 'isGift', 'stock', 'weight', 'tags']);
2547
3180
  const query = {
@@ -3109,180 +3742,6 @@ const withCrudFirestore = (MixinBase) => {
3109
3742
  };
3110
3743
  };
3111
3744
 
3112
- class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3113
- constructor({ firestore, interceptors }) {
3114
- super({
3115
- firestore,
3116
- collectionName: 'leads',
3117
- model: Lead,
3118
- interceptors,
3119
- });
3120
- }
3121
- }
3122
-
3123
- class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3124
- constructor({ firestore, interceptors }, parentRepository) {
3125
- super({
3126
- firestore,
3127
- collectionName: 'editions',
3128
- parentIdField: 'subscriptionId',
3129
- model: Edition,
3130
- interceptors,
3131
- });
3132
- this.parentRepository = parentRepository;
3133
- }
3134
- }
3135
-
3136
- class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3137
- constructor({ firestore, interceptors, }) {
3138
- super({
3139
- firestore,
3140
- collectionName: 'subscription',
3141
- model: Subscription,
3142
- interceptors,
3143
- });
3144
- }
3145
- }
3146
-
3147
- class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3148
- constructor({ firestore, interceptors }) {
3149
- super({
3150
- firestore,
3151
- collectionName: 'subscriptionMaterialization',
3152
- model: SubscriptionMaterialization,
3153
- interceptors,
3154
- });
3155
- }
3156
- }
3157
-
3158
- class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3159
- constructor({ firestore, interceptors }, parentRepository) {
3160
- super({
3161
- firestore,
3162
- collectionName: 'payments',
3163
- parentIdField: 'subscriptionId',
3164
- model: SubscriptionPayment,
3165
- interceptors,
3166
- });
3167
- this.parentRepository = parentRepository;
3168
- }
3169
- }
3170
-
3171
- class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3172
- constructor({ firestore, interceptors, }) {
3173
- super({
3174
- firestore,
3175
- collectionName: 'subscriptionSummary',
3176
- model: SubscriptionSummary,
3177
- interceptors,
3178
- });
3179
- }
3180
- }
3181
-
3182
- class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3183
- constructor({ firestore, interceptors }, parentRepository) {
3184
- super({
3185
- firestore,
3186
- collectionName: 'address',
3187
- parentIdField: 'userId',
3188
- model: UserAddress,
3189
- interceptors,
3190
- });
3191
- this.parentRepository = parentRepository;
3192
- }
3193
- }
3194
-
3195
- class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3196
- constructor({ firestore, interceptors }, parentRepository) {
3197
- super({
3198
- firestore,
3199
- collectionName: 'CX',
3200
- parentIdField: 'userId',
3201
- model: BeautyProfile,
3202
- interceptors,
3203
- });
3204
- this.parentRepository = parentRepository;
3205
- }
3206
- }
3207
-
3208
- class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3209
- constructor({ firestore, interceptors }) {
3210
- super({
3211
- firestore,
3212
- collectionName: 'users',
3213
- model: User,
3214
- interceptors,
3215
- });
3216
- }
3217
- async get(identifiers) {
3218
- const user = await super.get({ id: identifiers.id });
3219
- user.beautyProfile = await this.getBeautyProfile(user.id);
3220
- user.isSubscriber = await this.checkIfIsSubscriber(user.id);
3221
- return user;
3222
- }
3223
- async checkIfExistsByField(field, value) {
3224
- const result = await this.find({ filters: { [field]: value } });
3225
- return result.count > 0;
3226
- }
3227
- buildModelInstance() {
3228
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3229
- return {
3230
- toFirestore: (data) => {
3231
- const plain = toFirestore(data);
3232
- delete plain.isSubscriber;
3233
- return plain;
3234
- },
3235
- fromFirestore,
3236
- };
3237
- }
3238
- async getBeautyProfile(userId) {
3239
- const beautyProfile = await this.firestore
3240
- .getCollection(`${this.collectionName}/${userId}/CX`)
3241
- .withConverter(this.buildBeautyProfileModelInstance())
3242
- .getDoc('beautyProfile')
3243
- .get();
3244
- return beautyProfile.data();
3245
- }
3246
- async checkIfIsSubscriber(userId) {
3247
- const docs = await this.collection('subscription')
3248
- .where('user.id', '==', userId)
3249
- .where('status', '==', 'active')
3250
- .getDocs();
3251
- return !!docs && !!docs.size;
3252
- }
3253
- buildBeautyProfileModelInstance() {
3254
- return {
3255
- toFirestore: (data) => data.toPlain(),
3256
- fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
3257
- };
3258
- }
3259
- }
3260
- tslib.__decorate([
3261
- Log(),
3262
- tslib.__metadata("design:type", Function),
3263
- tslib.__metadata("design:paramtypes", [Object]),
3264
- tslib.__metadata("design:returntype", Promise)
3265
- ], UserFirestoreRepository.prototype, "get", null);
3266
- tslib.__decorate([
3267
- Log(),
3268
- tslib.__metadata("design:type", Function),
3269
- tslib.__metadata("design:paramtypes", [String, String]),
3270
- tslib.__metadata("design:returntype", Promise)
3271
- ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
3272
-
3273
- class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3274
- constructor({ firestore, interceptors }, parentRepository) {
3275
- super({
3276
- firestore,
3277
- collectionName: 'payment_method',
3278
- parentIdField: 'userId',
3279
- model: UserPaymentMethod,
3280
- interceptors,
3281
- });
3282
- this.parentRepository = parentRepository;
3283
- }
3284
- }
3285
-
3286
3745
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3287
3746
  constructor({ firestore, interceptors }) {
3288
3747
  super({
@@ -3429,39 +3888,134 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
3429
3888
  async fetchPaginatedReviews() {
3430
3889
  return Promise.resolve([]);
3431
3890
  }
3432
- }
3433
- tslib.__decorate([
3434
- Log(),
3435
- tslib.__metadata("design:type", Function),
3436
- tslib.__metadata("design:paramtypes", [String]),
3437
- tslib.__metadata("design:returntype", Promise)
3438
- ], ProductFirestoreRepository.prototype, "getBySlug", null);
3439
- tslib.__decorate([
3440
- Log(),
3441
- tslib.__metadata("design:type", Function),
3442
- tslib.__metadata("design:paramtypes", [String]),
3443
- tslib.__metadata("design:returntype", Promise)
3444
- ], ProductFirestoreRepository.prototype, "fetchReviews", null);
3891
+ }
3892
+ tslib.__decorate([
3893
+ Log(),
3894
+ tslib.__metadata("design:type", Function),
3895
+ tslib.__metadata("design:paramtypes", [String]),
3896
+ tslib.__metadata("design:returntype", Promise)
3897
+ ], ProductFirestoreRepository.prototype, "getBySlug", null);
3898
+ tslib.__decorate([
3899
+ Log(),
3900
+ tslib.__metadata("design:type", Function),
3901
+ tslib.__metadata("design:paramtypes", [String]),
3902
+ tslib.__metadata("design:returntype", Promise)
3903
+ ], ProductFirestoreRepository.prototype, "fetchReviews", null);
3904
+
3905
+ class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3906
+ constructor({ firestore, interceptors }, parentRepository) {
3907
+ super({
3908
+ firestore,
3909
+ collectionName: 'variants',
3910
+ parentIdField: 'productId',
3911
+ model: Variant,
3912
+ interceptors,
3913
+ });
3914
+ this.parentRepository = parentRepository;
3915
+ }
3916
+ }
3917
+
3918
+ class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3919
+ constructor({ firestore, interceptors }) {
3920
+ super({
3921
+ firestore,
3922
+ collectionName: 'subscriptionProducts',
3923
+ model: Product,
3924
+ interceptors,
3925
+ });
3926
+ }
3927
+ }
3928
+
3929
+ class SequenceFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3930
+ constructor({ firestore, interceptors }) {
3931
+ super({
3932
+ firestore,
3933
+ collectionName: 'sequences',
3934
+ model: Sequence,
3935
+ interceptors,
3936
+ });
3937
+ }
3938
+ }
3939
+
3940
+ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3941
+ constructor({ firestore, interceptors }) {
3942
+ super({
3943
+ firestore,
3944
+ collectionName: 'dms',
3945
+ model: Home,
3946
+ interceptors,
3947
+ });
3948
+ this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
3949
+ var _a, _b, _c;
3950
+ return ({
3951
+ category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
3952
+ ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
3953
+ : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
3954
+ 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)) || [],
3955
+ });
3956
+ };
3957
+ this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
3958
+ var _a;
3959
+ return ({
3960
+ category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
3961
+ products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
3962
+ });
3963
+ };
3964
+ }
3965
+ buildModelInstance() {
3966
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
3967
+ return {
3968
+ toFirestore: (data) => {
3969
+ const modifiedData = this.homeToFirestore(data);
3970
+ return toFirestore(modifiedData);
3971
+ },
3972
+ fromFirestore: (snap) => {
3973
+ const instance = fromFirestore(snap);
3974
+ return this.homeFromFirestore(instance);
3975
+ },
3976
+ };
3977
+ }
3978
+ homeToFirestore(home) {
3979
+ var _a, _b, _c, _d;
3980
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3981
+ home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
3982
+ home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
3983
+ home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
3984
+ }
3985
+ return home;
3986
+ }
3987
+ homeFromFirestore(home) {
3988
+ var _a;
3989
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3990
+ home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
3991
+ home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
3992
+ home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
3993
+ home.data.createdAt =
3994
+ home.data.createdAt instanceof firestore.Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
3995
+ home.data.expiresAt =
3996
+ home.data.expiresAt instanceof firestore.Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
3997
+ }
3998
+ return home;
3999
+ }
4000
+ }
3445
4001
 
3446
- class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3447
- constructor({ firestore, interceptors }, parentRepository) {
4002
+ class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4003
+ constructor({ firestore, interceptors }) {
3448
4004
  super({
3449
4005
  firestore,
3450
- collectionName: 'variants',
3451
- parentIdField: 'productId',
3452
- model: Variant,
4006
+ collectionName: 'shopMenus',
4007
+ model: ShopMenu,
3453
4008
  interceptors,
3454
4009
  });
3455
- this.parentRepository = parentRepository;
3456
4010
  }
3457
4011
  }
3458
4012
 
3459
- class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3460
- constructor({ firestore, interceptors }) {
4013
+ class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4014
+ constructor({ firestore, interceptors, }) {
3461
4015
  super({
3462
4016
  firestore,
3463
- collectionName: 'subscriptionProducts',
3464
- model: Product,
4017
+ collectionName: 'shopSettings',
4018
+ model: ShopSettings,
3465
4019
  interceptors,
3466
4020
  });
3467
4021
  }
@@ -3660,87 +4214,177 @@ class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(
3660
4214
  }
3661
4215
  }
3662
4216
 
3663
- class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4217
+ class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3664
4218
  constructor({ firestore, interceptors }) {
3665
4219
  super({
3666
4220
  firestore,
3667
- collectionName: 'dms',
3668
- model: Home,
4221
+ collectionName: 'leads',
4222
+ model: Lead,
3669
4223
  interceptors,
3670
4224
  });
3671
- this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
3672
- var _a, _b, _c;
3673
- return ({
3674
- category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
3675
- ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
3676
- : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
3677
- 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)) || [],
3678
- });
3679
- };
3680
- this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
3681
- var _a;
3682
- return ({
3683
- category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
3684
- products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
3685
- });
3686
- };
3687
- }
3688
- buildModelInstance() {
3689
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3690
- return {
3691
- toFirestore: (data) => {
3692
- const modifiedData = this.homeToFirestore(data);
3693
- return toFirestore(modifiedData);
3694
- },
3695
- fromFirestore: (snap) => {
3696
- const instance = fromFirestore(snap);
3697
- return this.homeFromFirestore(instance);
3698
- },
3699
- };
3700
4225
  }
3701
- homeToFirestore(home) {
3702
- var _a, _b, _c, _d;
3703
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3704
- home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
3705
- home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
3706
- home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
3707
- }
3708
- return home;
4226
+ }
4227
+
4228
+ class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4229
+ constructor({ firestore, interceptors }, parentRepository) {
4230
+ super({
4231
+ firestore,
4232
+ collectionName: 'editions',
4233
+ parentIdField: 'subscriptionId',
4234
+ model: Edition,
4235
+ interceptors,
4236
+ });
4237
+ this.parentRepository = parentRepository;
3709
4238
  }
3710
- homeFromFirestore(home) {
3711
- var _a;
3712
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3713
- home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
3714
- home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
3715
- home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
3716
- home.data.createdAt =
3717
- home.data.createdAt instanceof firestore.Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
3718
- home.data.expiresAt =
3719
- home.data.expiresAt instanceof firestore.Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
3720
- }
3721
- return home;
4239
+ }
4240
+
4241
+ class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4242
+ constructor({ firestore, interceptors, }) {
4243
+ super({
4244
+ firestore,
4245
+ collectionName: 'subscription',
4246
+ model: Subscription,
4247
+ interceptors,
4248
+ });
3722
4249
  }
3723
4250
  }
3724
4251
 
3725
- class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4252
+ class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3726
4253
  constructor({ firestore, interceptors }) {
3727
4254
  super({
3728
4255
  firestore,
3729
- collectionName: 'shopMenus',
3730
- model: ShopMenu,
4256
+ collectionName: 'subscriptionMaterialization',
4257
+ model: SubscriptionMaterialization,
3731
4258
  interceptors,
3732
4259
  });
3733
4260
  }
3734
4261
  }
3735
4262
 
3736
- class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4263
+ class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4264
+ constructor({ firestore, interceptors }, parentRepository) {
4265
+ super({
4266
+ firestore,
4267
+ collectionName: 'payments',
4268
+ parentIdField: 'subscriptionId',
4269
+ model: SubscriptionPayment,
4270
+ interceptors,
4271
+ });
4272
+ this.parentRepository = parentRepository;
4273
+ }
4274
+ }
4275
+
4276
+ class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3737
4277
  constructor({ firestore, interceptors, }) {
3738
4278
  super({
3739
4279
  firestore,
3740
- collectionName: 'shopSettings',
3741
- model: ShopSettings,
4280
+ collectionName: 'subscriptionSummary',
4281
+ model: SubscriptionSummary,
4282
+ interceptors,
4283
+ });
4284
+ }
4285
+ }
4286
+
4287
+ class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4288
+ constructor({ firestore, interceptors }, parentRepository) {
4289
+ super({
4290
+ firestore,
4291
+ collectionName: 'address',
4292
+ parentIdField: 'userId',
4293
+ model: UserAddress,
4294
+ interceptors,
4295
+ });
4296
+ this.parentRepository = parentRepository;
4297
+ }
4298
+ }
4299
+
4300
+ class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4301
+ constructor({ firestore, interceptors }, parentRepository) {
4302
+ super({
4303
+ firestore,
4304
+ collectionName: 'CX',
4305
+ parentIdField: 'userId',
4306
+ model: BeautyProfile,
4307
+ interceptors,
4308
+ });
4309
+ this.parentRepository = parentRepository;
4310
+ }
4311
+ }
4312
+
4313
+ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4314
+ constructor({ firestore, interceptors }) {
4315
+ super({
4316
+ firestore,
4317
+ collectionName: 'users',
4318
+ model: User,
4319
+ interceptors,
4320
+ });
4321
+ }
4322
+ async get(identifiers) {
4323
+ const user = await super.get({ id: identifiers.id });
4324
+ user.beautyProfile = await this.getBeautyProfile(user.id);
4325
+ user.isSubscriber = await this.checkIfIsSubscriber(user.id);
4326
+ return user;
4327
+ }
4328
+ async checkIfExistsByField(field, value) {
4329
+ const result = await this.find({ filters: { [field]: value } });
4330
+ return result.count > 0;
4331
+ }
4332
+ buildModelInstance() {
4333
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
4334
+ return {
4335
+ toFirestore: (data) => {
4336
+ const plain = toFirestore(data);
4337
+ delete plain.isSubscriber;
4338
+ return plain;
4339
+ },
4340
+ fromFirestore,
4341
+ };
4342
+ }
4343
+ async getBeautyProfile(userId) {
4344
+ const beautyProfile = await this.firestore
4345
+ .getCollection(`${this.collectionName}/${userId}/CX`)
4346
+ .withConverter(this.buildBeautyProfileModelInstance())
4347
+ .getDoc('beautyProfile')
4348
+ .get();
4349
+ return beautyProfile.data();
4350
+ }
4351
+ async checkIfIsSubscriber(userId) {
4352
+ const docs = await this.collection('subscription')
4353
+ .where('user.id', '==', userId)
4354
+ .where('status', '==', 'active')
4355
+ .getDocs();
4356
+ return !!docs && !!docs.size;
4357
+ }
4358
+ buildBeautyProfileModelInstance() {
4359
+ return {
4360
+ toFirestore: (data) => data.toPlain(),
4361
+ fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
4362
+ };
4363
+ }
4364
+ }
4365
+ tslib.__decorate([
4366
+ Log(),
4367
+ tslib.__metadata("design:type", Function),
4368
+ tslib.__metadata("design:paramtypes", [Object]),
4369
+ tslib.__metadata("design:returntype", Promise)
4370
+ ], UserFirestoreRepository.prototype, "get", null);
4371
+ tslib.__decorate([
4372
+ Log(),
4373
+ tslib.__metadata("design:type", Function),
4374
+ tslib.__metadata("design:paramtypes", [String, String]),
4375
+ tslib.__metadata("design:returntype", Promise)
4376
+ ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
4377
+
4378
+ class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4379
+ constructor({ firestore, interceptors }, parentRepository) {
4380
+ super({
4381
+ firestore,
4382
+ collectionName: 'payment_method',
4383
+ parentIdField: 'userId',
4384
+ model: UserPaymentMethod,
3742
4385
  interceptors,
3743
4386
  });
4387
+ this.parentRepository = parentRepository;
3744
4388
  }
3745
4389
  }
3746
4390
 
@@ -6142,15 +6786,6 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6142
6786
  }),
6143
6787
  },
6144
6788
  },
6145
- {
6146
- metadatas: {
6147
- columnName: 'metadatas',
6148
- fields: ['shop', 'title', 'description'],
6149
- bindPersistData: (value) => ({
6150
- metadatas: { data: value },
6151
- }),
6152
- },
6153
- },
6154
6789
  { isCollection: { columnName: 'is_collection' } },
6155
6790
  { isWishlist: { columnName: 'is_wishlist' } },
6156
6791
  'reference',
@@ -6170,7 +6805,6 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6170
6805
  'theme',
6171
6806
  { bannerUrl: { columnName: 'banner_url' } },
6172
6807
  { personHasPhoto: { columnName: 'person_has_photo' } },
6173
- { mostRelevants: { columnName: 'most_relevants', type: HasuraGraphQLColumnType.Jsonb } },
6174
6808
  ],
6175
6809
  });
6176
6810
  this.categoryFilterRepository = categoryFilterRepository;
@@ -6427,6 +7061,10 @@ Object.defineProperty(exports, 'sub', {
6427
7061
  enumerable: true,
6428
7062
  get: function () { return dateFns.sub; }
6429
7063
  });
7064
+ Object.defineProperty(exports, 'subDays', {
7065
+ enumerable: true,
7066
+ get: function () { return dateFns.subDays; }
7067
+ });
6430
7068
  Object.defineProperty(exports, 'chunk', {
6431
7069
  enumerable: true,
6432
7070
  get: function () { return lodash.chunk; }
@@ -6500,6 +7138,13 @@ Object.defineProperty(exports, 'unset', {
6500
7138
  get: function () { return lodash.unset; }
6501
7139
  });
6502
7140
  exports.Address = Address;
7141
+ exports.AdyenCardService = AdyenCardService;
7142
+ exports.AdyenPaymentMethodFactory = AdyenPaymentMethodFactory;
7143
+ exports.AntifraudBankSlipService = AntifraudBankSlipService;
7144
+ exports.AntifraudCardService = AntifraudCardService;
7145
+ exports.AntifraudGlampointsService = AntifraudGlampointsService;
7146
+ exports.AntifraudPixService = AntifraudPixService;
7147
+ exports.AntifraudProviderFactory = AntifraudProviderFactory;
6503
7148
  exports.Authentication = Authentication;
6504
7149
  exports.AuthenticationFirebaseAuthService = AuthenticationFirebaseAuthService;
6505
7150
  exports.AxiosAdapter = AxiosAdapter;
@@ -6507,6 +7152,7 @@ exports.Base = Base;
6507
7152
  exports.BaseModel = BaseModel;
6508
7153
  exports.BeautyProfile = BeautyProfile;
6509
7154
  exports.BeautyQuestionsHelper = BeautyQuestionsHelper;
7155
+ exports.BusinessError = BusinessError;
6510
7156
  exports.Buy2Win = Buy2Win;
6511
7157
  exports.Buy2WinFirestoreRepository = Buy2WinFirestoreRepository;
6512
7158
  exports.Campaign = Campaign;
@@ -6544,6 +7190,9 @@ exports.FilterHasuraGraphQLRepository = FilterHasuraGraphQLRepository;
6544
7190
  exports.FilterOption = FilterOption;
6545
7191
  exports.FilterOptionHasuraGraphQLRepository = FilterOptionHasuraGraphQLRepository;
6546
7192
  exports.FirebaseFileUploaderService = FirebaseFileUploaderService;
7193
+ exports.FraudValidationError = FraudValidationError;
7194
+ exports.GlampointsPaymentMethodFactory = GlampointsPaymentMethodFactory;
7195
+ exports.GlampointsPaymentService = GlampointsPaymentService;
6547
7196
  exports.Home = Home;
6548
7197
  exports.HomeFirestoreRepository = HomeFirestoreRepository;
6549
7198
  exports.InvalidArgumentError = InvalidArgumentError;
@@ -6560,8 +7209,15 @@ exports.Order = Order;
6560
7209
  exports.OrderBlocked = OrderBlocked;
6561
7210
  exports.OrderBlockedFirestoreRepository = OrderBlockedFirestoreRepository;
6562
7211
  exports.OrderFirestoreRepository = OrderFirestoreRepository;
7212
+ exports.PagarmeBankSlipService = PagarmeBankSlipService;
7213
+ exports.PagarmeCardService = PagarmeCardService;
7214
+ exports.PagarmePaymentMethodFactory = PagarmePaymentMethodFactory;
7215
+ exports.PagarmePixService = PagarmePixService;
6563
7216
  exports.Payment = Payment;
7217
+ exports.PaymentError = PaymentError;
6564
7218
  exports.PaymentFirestoreRepository = PaymentFirestoreRepository;
7219
+ exports.PaymentProviderFactory = PaymentProviderFactory;
7220
+ exports.PaymentTransaction = PaymentTransaction;
6565
7221
  exports.Product = Product;
6566
7222
  exports.ProductFirestoreRepository = ProductFirestoreRepository;
6567
7223
  exports.ProductHasuraGraphQL = ProductHasuraGraphQL;
@@ -6578,12 +7234,16 @@ exports.Register = Register;
6578
7234
  exports.RegisterFirebaseAuthService = RegisterFirebaseAuthService;
6579
7235
  exports.RequiredArgumentError = RequiredArgumentError;
6580
7236
  exports.RoundProductPricesHelper = RoundProductPricesHelper;
7237
+ exports.Sequence = Sequence;
7238
+ exports.SequenceFirestoreRepository = SequenceFirestoreRepository;
6581
7239
  exports.ShippingMethod = ShippingMethod;
6582
7240
  exports.ShopMenu = ShopMenu;
6583
7241
  exports.ShopMenuFirestoreRepository = ShopMenuFirestoreRepository;
6584
7242
  exports.ShopSettings = ShopSettings;
6585
7243
  exports.ShopSettingsFirestoreRepository = ShopSettingsFirestoreRepository;
6586
7244
  exports.SignOut = SignOut;
7245
+ exports.StockLimitError = StockLimitError;
7246
+ exports.StockOutError = StockOutError;
6587
7247
  exports.Subscription = Subscription;
6588
7248
  exports.SubscriptionEditionFirestoreRepository = SubscriptionEditionFirestoreRepository;
6589
7249
  exports.SubscriptionFirestoreRepository = SubscriptionFirestoreRepository;