@infrab4a/connect 4.9.0-beta.4 → 4.9.1-beta.0

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