@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.esm.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import 'reflect-metadata';
2
2
  import { __decorate, __metadata, __values, __spreadArray, __read, __extends, __rest } from 'tslib';
3
3
  import { plainToInstance, instanceToPlain, Type, Expose } from 'class-transformer';
4
- import { parseISO } from 'date-fns';
5
- export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub } from 'date-fns';
4
+ import { parseISO, format, startOfDay, endOfDay, subDays, addDays } from 'date-fns';
5
+ export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub, subDays } from 'date-fns';
6
6
  import { isNil, isArray, first, last, flatten, compact, get, isString, each, unset, isObject, set, isNumber, chunk, isEmpty, isDate, isBoolean, isInteger, isNaN as isNaN$1, sortBy, omit } from 'lodash';
7
7
  export { chunk, each, get, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil, isNumber, isObject, isString, now, omit, pick, set, sortBy, unset } from 'lodash';
8
8
  import { debug } from 'debug';
@@ -13,6 +13,65 @@ import { deleteField, arrayUnion, arrayRemove, Timestamp, doc, getDoc, updateDoc
13
13
  import { ref, uploadBytes } from 'firebase/storage';
14
14
  import { mutation, query as query$1 } from 'gql-query-builder';
15
15
 
16
+ var AntifraudProviders;
17
+ (function (AntifraudProviders) {
18
+ AntifraudProviders["BANKSLIP"] = "bankSlip";
19
+ AntifraudProviders["CARD"] = "card";
20
+ AntifraudProviders["PIX"] = "pix";
21
+ AntifraudProviders["POINTS"] = "glampoints";
22
+ })(AntifraudProviders || (AntifraudProviders = {}));
23
+
24
+ var PaymentMethods;
25
+ (function (PaymentMethods) {
26
+ PaymentMethods["CARD"] = "card";
27
+ PaymentMethods["BANKSLIP"] = "bankSlip";
28
+ PaymentMethods["PIX"] = "pix";
29
+ PaymentMethods["POINTS"] = "glampoints";
30
+ })(PaymentMethods || (PaymentMethods = {}));
31
+
32
+ var PaymentProviders;
33
+ (function (PaymentProviders) {
34
+ PaymentProviders["PAGARME"] = "pagarMe";
35
+ PaymentProviders["ADYEN"] = "adyen";
36
+ PaymentProviders["GLAMPOINTS"] = "glampoints";
37
+ })(PaymentProviders || (PaymentProviders = {}));
38
+
39
+ class BasePaymentMethodFactory {
40
+ constructor(methods) {
41
+ this.methods = methods;
42
+ }
43
+ build(method) {
44
+ return this.methods[method];
45
+ }
46
+ }
47
+
48
+ class AdyenPaymentMethodFactory extends BasePaymentMethodFactory {
49
+ }
50
+
51
+ class AntifraudProviderFactory {
52
+ constructor(antifraudProviders) {
53
+ this.antifraudProviders = antifraudProviders;
54
+ }
55
+ build(provider) {
56
+ return this.antifraudProviders[provider];
57
+ }
58
+ }
59
+
60
+ class GlampointsPaymentMethodFactory extends BasePaymentMethodFactory {
61
+ }
62
+
63
+ class PagarmePaymentMethodFactory extends BasePaymentMethodFactory {
64
+ }
65
+
66
+ class PaymentProviderFactory {
67
+ constructor(paymentProviders) {
68
+ this.paymentProviders = paymentProviders;
69
+ }
70
+ build(provider) {
71
+ return this.paymentProviders[provider];
72
+ }
73
+ }
74
+
16
75
  class BaseModel {
17
76
  get identifier() {
18
77
  const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
@@ -550,175 +609,182 @@ var Status;
550
609
  Status["CANCELLED"] = "Cancelado";
551
610
  })(Status || (Status = {}));
552
611
 
553
- class Payment extends BaseModel {
554
- static get identifiersFields() {
555
- return ['id'];
556
- }
612
+ class PaymentTransaction extends BaseModel {
557
613
  }
558
614
  __decorate([
559
615
  Expose({ name: 'refuse_reason' }),
560
616
  __metadata("design:type", String)
561
- ], Payment.prototype, "refuseReason", void 0);
617
+ ], PaymentTransaction.prototype, "refuseReason", void 0);
562
618
  __decorate([
563
619
  Expose({ name: 'status_reason' }),
564
620
  __metadata("design:type", String)
565
- ], Payment.prototype, "statusReason", void 0);
621
+ ], PaymentTransaction.prototype, "statusReason", void 0);
566
622
  __decorate([
567
623
  Expose({ name: 'acquirer_response_code' }),
568
624
  __metadata("design:type", String)
569
- ], Payment.prototype, "acquirerResponseCode", void 0);
625
+ ], PaymentTransaction.prototype, "acquirerResponseCode", void 0);
570
626
  __decorate([
571
627
  Expose({ name: 'acquirer_name' }),
572
628
  __metadata("design:type", String)
573
- ], Payment.prototype, "acquirerName", void 0);
629
+ ], PaymentTransaction.prototype, "acquirerName", void 0);
574
630
  __decorate([
575
631
  Expose({ name: 'acquirer_id' }),
576
632
  __metadata("design:type", String)
577
- ], Payment.prototype, "acquirerId", void 0);
633
+ ], PaymentTransaction.prototype, "acquirerId", void 0);
578
634
  __decorate([
579
635
  Expose({ name: 'authorization_code' }),
580
636
  __metadata("design:type", String)
581
- ], Payment.prototype, "authorizationCode", void 0);
637
+ ], PaymentTransaction.prototype, "authorizationCode", void 0);
582
638
  __decorate([
583
639
  Expose({ name: 'soft_descriptor' }),
584
640
  __metadata("design:type", String)
585
- ], Payment.prototype, "softDescriptor", void 0);
641
+ ], PaymentTransaction.prototype, "softDescriptor", void 0);
586
642
  __decorate([
587
643
  Expose({ name: 'date_created' }),
588
644
  __metadata("design:type", String)
589
- ], Payment.prototype, "dateCreated", void 0);
645
+ ], PaymentTransaction.prototype, "dateCreated", void 0);
590
646
  __decorate([
591
647
  Expose({ name: 'date_updated' }),
592
648
  __metadata("design:type", String)
593
- ], Payment.prototype, "dateUpdated", void 0);
649
+ ], PaymentTransaction.prototype, "dateUpdated", void 0);
594
650
  __decorate([
595
651
  Expose({ name: 'authorized_amount' }),
596
652
  __metadata("design:type", Number)
597
- ], Payment.prototype, "authorizedAmount", void 0);
653
+ ], PaymentTransaction.prototype, "authorizedAmount", void 0);
598
654
  __decorate([
599
655
  Expose({ name: 'paid_amount' }),
600
656
  __metadata("design:type", Number)
601
- ], Payment.prototype, "paidAmount", void 0);
657
+ ], PaymentTransaction.prototype, "paidAmount", void 0);
602
658
  __decorate([
603
659
  Expose({ name: 'paid_at' }),
604
660
  __metadata("design:type", String)
605
- ], Payment.prototype, "paidAt", void 0);
661
+ ], PaymentTransaction.prototype, "paidAt", void 0);
606
662
  __decorate([
607
663
  Expose({ name: 'refunded_amount' }),
608
664
  __metadata("design:type", Number)
609
- ], Payment.prototype, "refundedAmount", void 0);
665
+ ], PaymentTransaction.prototype, "refundedAmount", void 0);
610
666
  __decorate([
611
667
  Expose({ name: 'card_holder_name' }),
612
668
  __metadata("design:type", String)
613
- ], Payment.prototype, "cardHolderName", void 0);
669
+ ], PaymentTransaction.prototype, "cardHolderName", void 0);
614
670
  __decorate([
615
671
  Expose({ name: 'card_last_digits' }),
616
672
  __metadata("design:type", String)
617
- ], Payment.prototype, "cardLastDigits", void 0);
673
+ ], PaymentTransaction.prototype, "cardLastDigits", void 0);
618
674
  __decorate([
619
675
  Expose({ name: 'card_first_digits' }),
620
676
  __metadata("design:type", String)
621
- ], Payment.prototype, "cardFirstDigits", void 0);
677
+ ], PaymentTransaction.prototype, "cardFirstDigits", void 0);
622
678
  __decorate([
623
679
  Expose({ name: 'card_brand' }),
624
680
  __metadata("design:type", String)
625
- ], Payment.prototype, "cardBrand", void 0);
681
+ ], PaymentTransaction.prototype, "cardBrand", void 0);
626
682
  __decorate([
627
683
  Expose({ name: 'card_pin_mode' }),
628
684
  __metadata("design:type", String)
629
- ], Payment.prototype, "cardPinMode", void 0);
685
+ ], PaymentTransaction.prototype, "cardPinMode", void 0);
630
686
  __decorate([
631
687
  Expose({ name: 'card_magstripe_fallback' }),
632
688
  __metadata("design:type", Boolean)
633
- ], Payment.prototype, "cardMagstripeFallback", void 0);
689
+ ], PaymentTransaction.prototype, "cardMagstripeFallback", void 0);
634
690
  __decorate([
635
691
  Expose({ name: 'cvm_pin' }),
636
692
  __metadata("design:type", Boolean)
637
- ], Payment.prototype, "cvmPin", void 0);
693
+ ], PaymentTransaction.prototype, "cvmPin", void 0);
638
694
  __decorate([
639
695
  Expose({ name: 'postback_url' }),
640
696
  __metadata("design:type", String)
641
- ], Payment.prototype, "postbackUrl", void 0);
697
+ ], PaymentTransaction.prototype, "postbackUrl", void 0);
642
698
  __decorate([
643
699
  Expose({ name: 'payment_method' }),
644
700
  __metadata("design:type", String)
645
- ], Payment.prototype, "paymentMethod", void 0);
701
+ ], PaymentTransaction.prototype, "paymentMethod", void 0);
646
702
  __decorate([
647
703
  Expose({ name: 'capture_method' }),
648
704
  __metadata("design:type", String)
649
- ], Payment.prototype, "captureMethod", void 0);
705
+ ], PaymentTransaction.prototype, "captureMethod", void 0);
650
706
  __decorate([
651
707
  Expose({ name: 'antifraud_score' }),
652
708
  __metadata("design:type", String)
653
- ], Payment.prototype, "antifraudScore", void 0);
709
+ ], PaymentTransaction.prototype, "antifraudScore", void 0);
654
710
  __decorate([
655
711
  Expose({ name: 'boleto_url' }),
656
712
  __metadata("design:type", String)
657
- ], Payment.prototype, "boletoUrl", void 0);
713
+ ], PaymentTransaction.prototype, "boletoUrl", void 0);
658
714
  __decorate([
659
715
  Expose({ name: 'boleto_barcode' }),
660
716
  __metadata("design:type", String)
661
- ], Payment.prototype, "boletoBarcode", void 0);
717
+ ], PaymentTransaction.prototype, "boletoBarcode", void 0);
662
718
  __decorate([
663
719
  Expose({ name: 'boleto_expiration_date' }),
664
720
  __metadata("design:type", String)
665
- ], Payment.prototype, "boletoExpirationDate", void 0);
721
+ ], PaymentTransaction.prototype, "boletoExpirationDate", void 0);
666
722
  __decorate([
667
723
  Expose({ name: 'subscription_id' }),
668
724
  __metadata("design:type", String)
669
- ], Payment.prototype, "subscriptionId", void 0);
725
+ ], PaymentTransaction.prototype, "subscriptionId", void 0);
670
726
  __decorate([
671
727
  Expose({ name: 'split_rules' }),
672
728
  __metadata("design:type", String)
673
- ], Payment.prototype, "splitRules", void 0);
729
+ ], PaymentTransaction.prototype, "splitRules", void 0);
674
730
  __decorate([
675
731
  Expose({ name: 'antifraud_metadata' }),
676
732
  __metadata("design:type", Object)
677
- ], Payment.prototype, "antifraudMetadata", void 0);
733
+ ], PaymentTransaction.prototype, "antifraudMetadata", void 0);
678
734
  __decorate([
679
735
  Expose({ name: 'reference_key' }),
680
736
  __metadata("design:type", String)
681
- ], Payment.prototype, "referenceKey", void 0);
737
+ ], PaymentTransaction.prototype, "referenceKey", void 0);
682
738
  __decorate([
683
739
  Expose({ name: 'local_transaction_id' }),
684
740
  __metadata("design:type", String)
685
- ], Payment.prototype, "localTransactionId", void 0);
741
+ ], PaymentTransaction.prototype, "localTransactionId", void 0);
686
742
  __decorate([
687
743
  Expose({ name: 'local_time' }),
688
744
  __metadata("design:type", String)
689
- ], Payment.prototype, "localTime", void 0);
745
+ ], PaymentTransaction.prototype, "localTime", void 0);
690
746
  __decorate([
691
747
  Expose({ name: 'fraud_covered' }),
692
748
  __metadata("design:type", Boolean)
693
- ], Payment.prototype, "fraudCovered", void 0);
749
+ ], PaymentTransaction.prototype, "fraudCovered", void 0);
694
750
  __decorate([
695
751
  Expose({ name: 'fraud_reimbursed' }),
696
752
  __metadata("design:type", String)
697
- ], Payment.prototype, "fraudReimbursed", void 0);
753
+ ], PaymentTransaction.prototype, "fraudReimbursed", void 0);
698
754
  __decorate([
699
755
  Expose({ name: 'order_id' }),
700
756
  __metadata("design:type", String)
701
- ], Payment.prototype, "orderId", void 0);
757
+ ], PaymentTransaction.prototype, "orderId", void 0);
702
758
  __decorate([
703
759
  Expose({ name: 'risk_level' }),
704
760
  __metadata("design:type", String)
705
- ], Payment.prototype, "riskLevel", void 0);
761
+ ], PaymentTransaction.prototype, "riskLevel", void 0);
706
762
  __decorate([
707
763
  Expose({ name: 'receipt_url' }),
708
764
  __metadata("design:type", String)
709
- ], Payment.prototype, "receiptUrl", void 0);
765
+ ], PaymentTransaction.prototype, "receiptUrl", void 0);
710
766
  __decorate([
711
767
  Expose({ name: 'private_label' }),
712
768
  __metadata("design:type", String)
713
- ], Payment.prototype, "privateLabel", void 0);
769
+ ], PaymentTransaction.prototype, "privateLabel", void 0);
714
770
  __decorate([
715
771
  Expose({ name: 'pix_qr_code' }),
716
772
  __metadata("design:type", String)
717
- ], Payment.prototype, "pixQrCode", void 0);
773
+ ], PaymentTransaction.prototype, "pixQrCode", void 0);
718
774
  __decorate([
719
775
  Expose({ name: 'pix_expiration_date' }),
720
776
  __metadata("design:type", String)
721
- ], Payment.prototype, "pixExpirationDate", void 0);
777
+ ], PaymentTransaction.prototype, "pixExpirationDate", void 0);
778
+
779
+ class Payment extends BaseModel {
780
+ static get identifiersFields() {
781
+ return ['id'];
782
+ }
783
+ }
784
+ __decorate([
785
+ Type(() => PaymentTransaction),
786
+ __metadata("design:type", PaymentTransaction)
787
+ ], Payment.prototype, "transaction", void 0);
722
788
 
723
789
  class SubscriptionPayment extends BaseModel {
724
790
  static get identifiersFields() {
@@ -2191,8 +2257,8 @@ var OrderStatus;
2191
2257
  class Order extends Checkout {
2192
2258
  }
2193
2259
  __decorate([
2194
- Type(() => Payment),
2195
- __metadata("design:type", Payment)
2260
+ Type(() => PaymentTransaction),
2261
+ __metadata("design:type", PaymentTransaction)
2196
2262
  ], Order.prototype, "payment", void 0);
2197
2263
 
2198
2264
  class OrderBlocked extends BaseModel {
@@ -2223,6 +2289,592 @@ __decorate([
2223
2289
  __metadata("design:type", Coupon)
2224
2290
  ], CheckoutSubscription.prototype, "coupon", void 0);
2225
2291
 
2292
+ class BusinessError extends CustomError {
2293
+ constructor(message, additionalData, type = '') {
2294
+ super(message);
2295
+ this.additionalData = additionalData;
2296
+ this.type = type;
2297
+ }
2298
+ }
2299
+
2300
+ class DuplicatedResultsError extends CustomError {
2301
+ constructor(message) {
2302
+ super(message);
2303
+ }
2304
+ }
2305
+
2306
+ class FraudValidationError extends CustomError {
2307
+ constructor(message, additionalData) {
2308
+ super(message);
2309
+ this.additionalData = additionalData;
2310
+ this.type = 'antifraud';
2311
+ }
2312
+ }
2313
+
2314
+ class InvalidArgumentError extends CustomError {
2315
+ constructor(message) {
2316
+ super(message);
2317
+ }
2318
+ }
2319
+
2320
+ class NotFoundError extends CustomError {
2321
+ constructor(message) {
2322
+ super(message);
2323
+ }
2324
+ }
2325
+
2326
+ class PaymentError extends CustomError {
2327
+ constructor(message, additionalData) {
2328
+ super(message);
2329
+ this.additionalData = additionalData;
2330
+ this.type = 'payment';
2331
+ }
2332
+ }
2333
+
2334
+ class RequiredArgumentError extends CustomError {
2335
+ constructor(args) {
2336
+ super(`Required arguments: ${args.join(', ')}`);
2337
+ this.args = args;
2338
+ this.arguments = args;
2339
+ }
2340
+ }
2341
+
2342
+ class StockLimitError extends BusinessError {
2343
+ constructor(message, additionalData) {
2344
+ super(message, additionalData);
2345
+ this.type = 'stock-limit';
2346
+ }
2347
+ }
2348
+
2349
+ class StockOutError extends BusinessError {
2350
+ constructor(message, additionalData) {
2351
+ super(message, additionalData);
2352
+ this.type = 'stock-out';
2353
+ }
2354
+ }
2355
+
2356
+ class AdyenCardService {
2357
+ constructor(credentials, paymentRepository, orderBlockedRepository) {
2358
+ this.credentials = credentials;
2359
+ this.paymentRepository = paymentRepository;
2360
+ this.orderBlockedRepository = orderBlockedRepository;
2361
+ }
2362
+ async pay(checkout, card) {
2363
+ try {
2364
+ const result = await axios({
2365
+ method: 'POST',
2366
+ url: this.credentials.URL_TRANSACTION,
2367
+ headers: {
2368
+ 'x-api-key': this.credentials.API_KEY,
2369
+ 'content-type': 'application/json',
2370
+ },
2371
+ data: this.createCardPayment(checkout, card),
2372
+ });
2373
+ if (result.data.resultCode !== 'Authorised') {
2374
+ this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
2375
+ 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`, {
2376
+ checkoutId: checkout.id,
2377
+ userEmail: checkout.user.email,
2378
+ info: result.data,
2379
+ }));
2380
+ }
2381
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2382
+ createdAt: new Date(),
2383
+ updatedAt: new Date(),
2384
+ userId: checkout.user.id,
2385
+ checkoutId: checkout.id,
2386
+ totalPrice: checkout.totalPrice,
2387
+ paymentProvider: 'adyen',
2388
+ transaction: Object.assign(Object.assign({}, result.data), { status: 'paid' }),
2389
+ }));
2390
+ return payment;
2391
+ }
2392
+ catch (error) {
2393
+ 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', {
2394
+ checkoutId: checkout.id,
2395
+ userEmail: checkout.user.email,
2396
+ info: error.message,
2397
+ });
2398
+ }
2399
+ }
2400
+ createCardPayment(checkout, card) {
2401
+ return {
2402
+ amount: {
2403
+ currency: 'BRL',
2404
+ value: ((checkout === null || checkout === void 0 ? void 0 : checkout.totalPrice) || 0) * 100,
2405
+ },
2406
+ paymentMethod: {
2407
+ type: 'scheme',
2408
+ storedPaymentMethodId: card.cardId,
2409
+ },
2410
+ reference: checkout.id,
2411
+ shopperInteraction: 'Ecommerce',
2412
+ merchantAccount: this.credentials.MERCHANT_ACCOUNT,
2413
+ shopperReference: checkout.user.id,
2414
+ recurringProcessingModel: 'CardOnFile',
2415
+ returnUrl: this.credentials.URL_POSTBACK,
2416
+ installments: {
2417
+ value: card.installments,
2418
+ },
2419
+ };
2420
+ }
2421
+ addCard() {
2422
+ throw new Error('Method not implemented.');
2423
+ }
2424
+ }
2425
+
2426
+ class AntifraudBankSlipService {
2427
+ constructor(orderBlockedRepository) {
2428
+ this.orderBlockedRepository = orderBlockedRepository;
2429
+ this.MAX_ORDER_VALUE = 5000;
2430
+ }
2431
+ async validate(checkout) {
2432
+ var _a, _b;
2433
+ if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber)) {
2434
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Boleto not authorized', 'Boleto', 'day');
2435
+ throw new FraudValidationError('Boleto não autorizado para cliente não assinante', {
2436
+ checkoutId: checkout.id,
2437
+ userEmail: checkout.user.email,
2438
+ info: {
2439
+ isSubscriber: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.isSubscriber,
2440
+ subtotal: checkout.subTotalPrice,
2441
+ total: checkout.totalPrice,
2442
+ },
2443
+ });
2444
+ }
2445
+ return true;
2446
+ }
2447
+ }
2448
+
2449
+ class AntifraudCardService {
2450
+ constructor(orderRepository, orderBlockedRepository) {
2451
+ this.orderRepository = orderRepository;
2452
+ this.orderBlockedRepository = orderBlockedRepository;
2453
+ this.LIMIT_ORDERS_DAY = 2;
2454
+ this.LIMIT_ORDERS_WEEK = 7;
2455
+ this.LIMIT_BLOCKED_ORDERS_DAY = 5;
2456
+ }
2457
+ async validate(checkout, card) {
2458
+ var _a, _b;
2459
+ if (!(await this.verifyBlockedOrderAttempts(checkout, card)))
2460
+ throw new FraudValidationError('Cliente com mais de 5 compras negadas/bloqueadas no dia', {
2461
+ checkoutId: checkout.id,
2462
+ userEmail: checkout.user.email,
2463
+ info: {
2464
+ isSubscriber: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber,
2465
+ subtotal: checkout.subTotalPrice,
2466
+ total: checkout.totalPrice,
2467
+ },
2468
+ });
2469
+ if (!(await this.verifyDayAndWeekOrders(checkout, card)))
2470
+ throw new FraudValidationError('Cliente tentando comprar mais de 2 vezes no dia ou 7 vezes na semana', {
2471
+ checkoutId: checkout.id,
2472
+ userEmail: checkout.user.email,
2473
+ info: {
2474
+ isSubscriber: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.isSubscriber,
2475
+ subtotal: checkout.subTotalPrice,
2476
+ total: checkout.totalPrice,
2477
+ },
2478
+ });
2479
+ return true;
2480
+ }
2481
+ async verifyBlockedOrderAttempts(checkout, card) {
2482
+ var _a, _b, _c, _d;
2483
+ const day = `${format(new Date(), 'YYYY-MM-DD')}T00:00:00`;
2484
+ const endOfDay = `${format(new Date(), 'YYYY-MM-DD')}T23:59:59`;
2485
+ const ordersBlockedWithCpf = await this.orderBlockedRepository
2486
+ .find({
2487
+ filters: {
2488
+ customer: { cpf: { operator: Where.EQUALS, value: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf } },
2489
+ date: [
2490
+ { operator: Where.GTE, value: new Date(day) },
2491
+ { operator: Where.LTE, value: new Date(endOfDay) },
2492
+ ],
2493
+ },
2494
+ })
2495
+ .then((data) => data.data);
2496
+ const ordersBlockedWithEmail = await this.orderBlockedRepository
2497
+ .find({
2498
+ filters: {
2499
+ customer: { email: { operator: Where.EQUALS, value: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email } },
2500
+ date: [
2501
+ { operator: Where.GTE, value: new Date(day) },
2502
+ { operator: Where.LTE, value: new Date(endOfDay) },
2503
+ ],
2504
+ },
2505
+ })
2506
+ .then((data) => data.data);
2507
+ const ordersBlockedWithCep = await this.orderBlockedRepository
2508
+ .find({
2509
+ filters: {
2510
+ customer: { shippingAddress: { zip: { operator: Where.EQUALS, value: (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip } } },
2511
+ date: [
2512
+ { operator: Where.GTE, value: new Date(day) },
2513
+ { operator: Where.LTE, value: new Date(endOfDay) },
2514
+ ],
2515
+ },
2516
+ })
2517
+ .then((data) => data.data);
2518
+ const ordersBlockedWithPhone = await this.orderBlockedRepository
2519
+ .find({
2520
+ filters: {
2521
+ customer: { phoneNumber: { operator: Where.EQUALS, value: (_d = checkout.user) === null || _d === void 0 ? void 0 : _d.phone } },
2522
+ date: [
2523
+ { operator: Where.GTE, value: new Date(day) },
2524
+ { operator: Where.LTE, value: new Date(endOfDay) },
2525
+ ],
2526
+ },
2527
+ })
2528
+ .then((data) => data.data);
2529
+ const blockedUniqueEmails = ordersBlockedWithEmail.filter((e) => {
2530
+ var _a;
2531
+ return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf);
2532
+ });
2533
+ const blockedUniqueCeps = ordersBlockedWithCep.filter((e) => {
2534
+ var _a, _b;
2535
+ 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);
2536
+ });
2537
+ const blockedUniquePhone = ordersBlockedWithPhone.filter((e) => {
2538
+ var _a, _b, _c, _d, _e, _f;
2539
+ return (e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf) &&
2540
+ e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email) &&
2541
+ ((_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()));
2542
+ });
2543
+ const blockedAttempts = ordersBlockedWithCpf
2544
+ .concat(blockedUniqueEmails)
2545
+ .concat(blockedUniqueCeps)
2546
+ .concat(blockedUniquePhone);
2547
+ if (blockedAttempts.length >= this.LIMIT_BLOCKED_ORDERS_DAY) {
2548
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'More than 5 attempts have failed', 'Failed attempts', 'day', card || null);
2549
+ return false;
2550
+ }
2551
+ return true;
2552
+ }
2553
+ async verifyDayAndWeekOrders(checkout, card) {
2554
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2555
+ 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'));
2556
+ for (const key in ordersPerDay) {
2557
+ if (ordersPerDay[key] > this.LIMIT_ORDERS_DAY) {
2558
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'day');
2559
+ return false;
2560
+ }
2561
+ }
2562
+ 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'));
2563
+ for (const key in ordersPerWeek) {
2564
+ if (ordersPerDay[key] > this.LIMIT_ORDERS_WEEK) {
2565
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'week');
2566
+ return false;
2567
+ }
2568
+ }
2569
+ return true;
2570
+ }
2571
+ async validateOrdersByRange(cpf, email, phone, zip, card, range) {
2572
+ const ordersCpf = await this.countOrdersByField('user', 'cpf', cpf, range);
2573
+ const ordersByEmail = await this.countOrdersByField('user', 'email', email, range);
2574
+ const ordersByPhone = await this.countOrdersByField('user', 'phone', phone, range);
2575
+ const ordersByZip = await this.countOrdersByField('shippingAddress', 'zip', zip, range);
2576
+ return {
2577
+ cpf: ordersCpf,
2578
+ email: ordersByEmail,
2579
+ phone: ordersByPhone,
2580
+ zip: ordersByZip,
2581
+ };
2582
+ }
2583
+ async countOrdersByField(property, field, value, range) {
2584
+ const filters = {
2585
+ [property]: {
2586
+ [field]: value,
2587
+ },
2588
+ ['createdAt']: [
2589
+ { operator: Where.GTE, value: range.firstDate },
2590
+ { operator: Where.LTE, value: range.lastDate },
2591
+ ],
2592
+ };
2593
+ const docs = await (await this.orderRepository.find({ filters })).count;
2594
+ return docs;
2595
+ }
2596
+ getDateRange(range = 'day') {
2597
+ switch (range) {
2598
+ case 'day':
2599
+ return {
2600
+ firstDate: startOfDay(new Date()).getTime(),
2601
+ lastDate: endOfDay(new Date()).getTime(),
2602
+ };
2603
+ case 'week':
2604
+ return {
2605
+ firstDate: startOfDay(subDays(new Date(), 7)).getTime(),
2606
+ lastDate: endOfDay(new Date()).getTime(),
2607
+ };
2608
+ default:
2609
+ return {
2610
+ firstDate: startOfDay(new Date()).getTime(),
2611
+ lastDate: endOfDay(new Date()).getTime(),
2612
+ };
2613
+ }
2614
+ }
2615
+ }
2616
+
2617
+ class AntifraudGlampointsService {
2618
+ constructor() { }
2619
+ async validate(checkout) {
2620
+ return true;
2621
+ }
2622
+ }
2623
+
2624
+ class AntifraudPixService {
2625
+ constructor() { }
2626
+ async validate(checkout) {
2627
+ return true;
2628
+ }
2629
+ }
2630
+
2631
+ class GlampointsPaymentService {
2632
+ constructor(paymentRepository) {
2633
+ this.paymentRepository = paymentRepository;
2634
+ }
2635
+ async pay(checkout) {
2636
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2637
+ createdAt: new Date(),
2638
+ updatedAt: new Date(),
2639
+ userId: checkout.user.id,
2640
+ checkoutId: checkout.id,
2641
+ totalPrice: checkout.totalPrice,
2642
+ paymentProvider: 'glampoints',
2643
+ transaction: {
2644
+ amount: 0,
2645
+ acquirerResponseCode: '0000',
2646
+ acquirerName: 'glampoints',
2647
+ authorizedAmount: 0,
2648
+ captureMethod: 'ecommerce',
2649
+ installments: 1,
2650
+ cost: 0,
2651
+ paidAmount: 0,
2652
+ paidAt: new Date().toISOString(),
2653
+ paymentMethod: 'glampoints',
2654
+ referer: 'api_key',
2655
+ refundedAmount: 0,
2656
+ status: 'paid',
2657
+ statusReason: 'acquirer',
2658
+ },
2659
+ }));
2660
+ return payment;
2661
+ }
2662
+ }
2663
+
2664
+ class PagarmeBankSlipService {
2665
+ constructor(credentials, paymentRepository) {
2666
+ this.credentials = credentials;
2667
+ this.paymentRepository = paymentRepository;
2668
+ }
2669
+ async pay(checkout) {
2670
+ try {
2671
+ const result = await axios({
2672
+ method: 'POST',
2673
+ url: this.credentials.URL_TRANSACTION,
2674
+ data: this.createBoletoPayment(checkout),
2675
+ });
2676
+ if (result.data.status !== 'processing') {
2677
+ return Promise.reject(new PaymentError(`Houve uma falha ao gerar o boleto. Tente novamente`, {
2678
+ checkoutId: checkout.id,
2679
+ userEmail: checkout.user.email,
2680
+ info: result.data,
2681
+ }));
2682
+ }
2683
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2684
+ createdAt: new Date(),
2685
+ updatedAt: new Date(),
2686
+ userId: checkout.user.id,
2687
+ checkoutId: checkout.id,
2688
+ totalPrice: checkout.totalPrice,
2689
+ paymentProvider: 'pagarMe',
2690
+ transaction: result.data,
2691
+ }));
2692
+ return payment;
2693
+ }
2694
+ catch (error) {
2695
+ throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
2696
+ checkoutId: checkout.id,
2697
+ userEmail: checkout.user.email,
2698
+ info: error.response.data,
2699
+ });
2700
+ }
2701
+ }
2702
+ createBoletoPayment(checkout) {
2703
+ return {
2704
+ api_key: this.credentials.API_KEY,
2705
+ amount: Math.floor(checkout.totalPrice * 100),
2706
+ boleto_rules: ['strict_expiration_date'],
2707
+ boleto_instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
2708
+ boleto_expiration_date: format(addDays(new Date(), 3), 'yyyy-MM-dd'),
2709
+ payment_method: 'boleto',
2710
+ postback_url: this.credentials.URL_POSTBACK,
2711
+ customer: {
2712
+ external_id: checkout.user.id,
2713
+ type: 'individual',
2714
+ country: 'br',
2715
+ name: checkout.user.displayName,
2716
+ documents: [
2717
+ {
2718
+ type: 'cpf',
2719
+ number: checkout.user.cpf,
2720
+ },
2721
+ ],
2722
+ },
2723
+ };
2724
+ }
2725
+ }
2726
+
2727
+ class PagarmeCardService {
2728
+ constructor(credentials, paymentRepository, orderBlockedRepository) {
2729
+ this.credentials = credentials;
2730
+ this.paymentRepository = paymentRepository;
2731
+ this.orderBlockedRepository = orderBlockedRepository;
2732
+ }
2733
+ async pay(checkout, card) {
2734
+ var _a;
2735
+ try {
2736
+ const result = await axios({
2737
+ method: 'POST',
2738
+ url: this.credentials.URL_TRANSACTION,
2739
+ data: this.createCardPayment(checkout, card),
2740
+ });
2741
+ if (result.data.status !== 'paid') {
2742
+ await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
2743
+ 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`, {
2744
+ checkoutId: checkout.id,
2745
+ userEmail: checkout.user.email,
2746
+ info: result.data,
2747
+ }));
2748
+ }
2749
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2750
+ createdAt: new Date(),
2751
+ updatedAt: new Date(),
2752
+ userId: checkout.user.id,
2753
+ checkoutId: checkout.id,
2754
+ totalPrice: checkout.totalPrice,
2755
+ paymentProvider: PaymentProviders.PAGARME,
2756
+ transaction: Object.assign(Object.assign({}, result.data), { paidAt: new Date() }),
2757
+ }));
2758
+ return payment;
2759
+ }
2760
+ catch (error) {
2761
+ 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', {
2762
+ checkoutId: checkout.id,
2763
+ userEmail: checkout.user.email,
2764
+ info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
2765
+ });
2766
+ }
2767
+ }
2768
+ addCard() {
2769
+ throw new Error('Method not implemented.');
2770
+ }
2771
+ createCardPayment(checkout, card) {
2772
+ var _a, _b, _c, _d, _e, _f;
2773
+ return {
2774
+ api_key: this.credentials.API_KEY,
2775
+ amount: Math.floor(checkout.totalPrice * 100),
2776
+ card_id: card.cardId,
2777
+ payment_method: 'credit_card',
2778
+ installments: card.installments,
2779
+ soft_descriptor: checkout.shop,
2780
+ customer: {
2781
+ external_id: checkout.user.id,
2782
+ name: checkout.user.displayName,
2783
+ type: 'individual',
2784
+ country: 'br',
2785
+ email: checkout.user.email,
2786
+ phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
2787
+ documents: [
2788
+ {
2789
+ type: 'cpf',
2790
+ number: checkout.user.cpf,
2791
+ },
2792
+ ],
2793
+ },
2794
+ billing: {
2795
+ name: checkout.user.displayName,
2796
+ address: {
2797
+ country: 'br',
2798
+ state: checkout.billingAddress ? checkout.billingAddress.state : (_a = checkout.shippingAddress) === null || _a === void 0 ? void 0 : _a.state,
2799
+ city: checkout.billingAddress ? checkout.billingAddress.city : (_b = checkout.shippingAddress) === null || _b === void 0 ? void 0 : _b.city,
2800
+ neighborhood: checkout.billingAddress ? checkout.billingAddress.district : (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.district,
2801
+ street: checkout.billingAddress ? checkout.billingAddress.street : (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.street,
2802
+ street_number: checkout.billingAddress ? checkout.billingAddress.number : (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.number,
2803
+ zipcode: checkout.billingAddress
2804
+ ? checkout.billingAddress.zip.replace('-', '')
2805
+ : (_f = checkout.shippingAddress) === null || _f === void 0 ? void 0 : _f.zip.replace('-', ''),
2806
+ },
2807
+ },
2808
+ items: checkout.lineItems.map((item) => {
2809
+ return {
2810
+ id: item.id,
2811
+ title: checkout.user.isSubscriber ? `${item.name} - ASSINANTE` : item.name,
2812
+ unit_price: Math.floor(item.pricePaid * 100),
2813
+ quantity: item.quantity,
2814
+ tangible: true,
2815
+ };
2816
+ }),
2817
+ };
2818
+ }
2819
+ }
2820
+
2821
+ class PagarmePixService {
2822
+ constructor(credentials, paymentRepository) {
2823
+ this.credentials = credentials;
2824
+ this.paymentRepository = paymentRepository;
2825
+ }
2826
+ async pay(checkout) {
2827
+ var _a;
2828
+ try {
2829
+ const result = await axios({
2830
+ method: 'POST',
2831
+ url: this.credentials.URL_TRANSACTION,
2832
+ data: this.createPixPayment(checkout),
2833
+ });
2834
+ const payment = await this.paymentRepository.create(Payment.toInstance({
2835
+ createdAt: new Date(),
2836
+ updatedAt: new Date(),
2837
+ userId: checkout.user.id,
2838
+ checkoutId: checkout.id,
2839
+ totalPrice: checkout.totalPrice,
2840
+ paymentProvider: 'pagarMe',
2841
+ transaction: Object.assign(Object.assign({}, result.data), { paidAt: new Date() }),
2842
+ }));
2843
+ return payment;
2844
+ }
2845
+ catch (error) {
2846
+ throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
2847
+ checkoutId: checkout.id,
2848
+ userEmail: checkout.user.email,
2849
+ info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
2850
+ });
2851
+ }
2852
+ }
2853
+ createPixPayment(checkout) {
2854
+ return {
2855
+ payment_method: 'pix',
2856
+ amount: Math.floor(checkout.totalPrice * 100),
2857
+ api_key: this.credentials.API_KEY,
2858
+ postback_url: this.credentials.URL_POSTBACK,
2859
+ pix_expiration_date: format(addDays(new Date(), 1), 'yyyy-MM-dd'),
2860
+ customer: {
2861
+ external_id: checkout.user.id,
2862
+ type: 'individual',
2863
+ country: 'br',
2864
+ name: checkout.user.displayName,
2865
+ email: checkout.user.email.trim(),
2866
+ phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
2867
+ documents: [
2868
+ {
2869
+ type: 'cpf',
2870
+ number: checkout.user.cpf,
2871
+ },
2872
+ ],
2873
+ },
2874
+ };
2875
+ }
2876
+ }
2877
+
2226
2878
  class RoundProductPricesHelper {
2227
2879
  static roundProductPrices(product) {
2228
2880
  product.price.price = Number(product.price.price.toFixed(2));
@@ -2237,6 +2889,12 @@ class RoundProductPricesHelper {
2237
2889
  }
2238
2890
  }
2239
2891
 
2892
+ class Sequence extends BaseModel {
2893
+ static get identifiersFields() {
2894
+ return ['id'];
2895
+ }
2896
+ }
2897
+
2240
2898
  var FilterType;
2241
2899
  (function (FilterType) {
2242
2900
  FilterType["ACCESSORY_IMPORTANCE"] = "accessoryImportance";
@@ -2375,36 +3033,10 @@ class ShopSettings extends BaseModel {
2375
3033
  }
2376
3034
  }
2377
3035
 
2378
- class InvalidArgumentError extends CustomError {
2379
- constructor(message) {
2380
- super(message);
2381
- }
2382
- }
2383
-
2384
- class RequiredArgumentError extends CustomError {
2385
- constructor(args) {
2386
- super(`Required arguments: ${args.join(', ')}`);
2387
- this.args = args;
2388
- this.arguments = args;
2389
- }
2390
- }
2391
-
2392
- class NotFoundError extends CustomError {
2393
- constructor(message) {
2394
- super(message);
2395
- }
2396
- }
2397
-
2398
- class DuplicatedResultsError extends CustomError {
2399
- constructor(message) {
2400
- super(message);
2401
- }
2402
- }
2403
-
2404
- class AxiosAdapter {
2405
- constructor(config) {
2406
- this.config = config;
2407
- this.logger = DebugHelper.from(this);
3036
+ class AxiosAdapter {
3037
+ constructor(config) {
3038
+ this.config = config;
3039
+ this.logger = DebugHelper.from(this);
2408
3040
  }
2409
3041
  async get(index, id) {
2410
3042
  const logger = this.logger.with('get');
@@ -2535,7 +3167,8 @@ class ProductsIndex {
2535
3167
  'rate',
2536
3168
  ];
2537
3169
  const filter = [{ term: { published: true } }];
2538
- // if (shop && shop !== Shops.ALL) filter.push({ term: { tags: shop == Shops.GLAMSHOP ? 'feminino' : 'masculino' } })
3170
+ if (shop && shop !== Shops.ALL)
3171
+ filter.push({ term: { tags: shop == Shops.GLAMSHOP ? 'feminino' : 'masculino' } });
2539
3172
  if (size > 9)
2540
3173
  fields.push(...['pricePaid', 'isGift', 'stock', 'weight', 'tags']);
2541
3174
  const query = {
@@ -3103,180 +3736,6 @@ const withCrudFirestore = (MixinBase) => {
3103
3736
  };
3104
3737
  };
3105
3738
 
3106
- class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3107
- constructor({ firestore, interceptors }) {
3108
- super({
3109
- firestore,
3110
- collectionName: 'leads',
3111
- model: Lead,
3112
- interceptors,
3113
- });
3114
- }
3115
- }
3116
-
3117
- class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3118
- constructor({ firestore, interceptors }, parentRepository) {
3119
- super({
3120
- firestore,
3121
- collectionName: 'editions',
3122
- parentIdField: 'subscriptionId',
3123
- model: Edition,
3124
- interceptors,
3125
- });
3126
- this.parentRepository = parentRepository;
3127
- }
3128
- }
3129
-
3130
- class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3131
- constructor({ firestore, interceptors, }) {
3132
- super({
3133
- firestore,
3134
- collectionName: 'subscription',
3135
- model: Subscription,
3136
- interceptors,
3137
- });
3138
- }
3139
- }
3140
-
3141
- class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3142
- constructor({ firestore, interceptors }) {
3143
- super({
3144
- firestore,
3145
- collectionName: 'subscriptionMaterialization',
3146
- model: SubscriptionMaterialization,
3147
- interceptors,
3148
- });
3149
- }
3150
- }
3151
-
3152
- class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3153
- constructor({ firestore, interceptors }, parentRepository) {
3154
- super({
3155
- firestore,
3156
- collectionName: 'payments',
3157
- parentIdField: 'subscriptionId',
3158
- model: SubscriptionPayment,
3159
- interceptors,
3160
- });
3161
- this.parentRepository = parentRepository;
3162
- }
3163
- }
3164
-
3165
- class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3166
- constructor({ firestore, interceptors, }) {
3167
- super({
3168
- firestore,
3169
- collectionName: 'subscriptionSummary',
3170
- model: SubscriptionSummary,
3171
- interceptors,
3172
- });
3173
- }
3174
- }
3175
-
3176
- class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3177
- constructor({ firestore, interceptors }, parentRepository) {
3178
- super({
3179
- firestore,
3180
- collectionName: 'address',
3181
- parentIdField: 'userId',
3182
- model: UserAddress,
3183
- interceptors,
3184
- });
3185
- this.parentRepository = parentRepository;
3186
- }
3187
- }
3188
-
3189
- class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3190
- constructor({ firestore, interceptors }, parentRepository) {
3191
- super({
3192
- firestore,
3193
- collectionName: 'CX',
3194
- parentIdField: 'userId',
3195
- model: BeautyProfile,
3196
- interceptors,
3197
- });
3198
- this.parentRepository = parentRepository;
3199
- }
3200
- }
3201
-
3202
- class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3203
- constructor({ firestore, interceptors }) {
3204
- super({
3205
- firestore,
3206
- collectionName: 'users',
3207
- model: User,
3208
- interceptors,
3209
- });
3210
- }
3211
- async get(identifiers) {
3212
- const user = await super.get({ id: identifiers.id });
3213
- user.beautyProfile = await this.getBeautyProfile(user.id);
3214
- user.isSubscriber = await this.checkIfIsSubscriber(user.id);
3215
- return user;
3216
- }
3217
- async checkIfExistsByField(field, value) {
3218
- const result = await this.find({ filters: { [field]: value } });
3219
- return result.count > 0;
3220
- }
3221
- buildModelInstance() {
3222
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3223
- return {
3224
- toFirestore: (data) => {
3225
- const plain = toFirestore(data);
3226
- delete plain.isSubscriber;
3227
- return plain;
3228
- },
3229
- fromFirestore,
3230
- };
3231
- }
3232
- async getBeautyProfile(userId) {
3233
- const beautyProfile = await this.firestore
3234
- .getCollection(`${this.collectionName}/${userId}/CX`)
3235
- .withConverter(this.buildBeautyProfileModelInstance())
3236
- .getDoc('beautyProfile')
3237
- .get();
3238
- return beautyProfile.data();
3239
- }
3240
- async checkIfIsSubscriber(userId) {
3241
- const docs = await this.collection('subscription')
3242
- .where('user.id', '==', userId)
3243
- .where('status', '==', 'active')
3244
- .getDocs();
3245
- return !!docs && !!docs.size;
3246
- }
3247
- buildBeautyProfileModelInstance() {
3248
- return {
3249
- toFirestore: (data) => data.toPlain(),
3250
- fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
3251
- };
3252
- }
3253
- }
3254
- __decorate([
3255
- Log(),
3256
- __metadata("design:type", Function),
3257
- __metadata("design:paramtypes", [Object]),
3258
- __metadata("design:returntype", Promise)
3259
- ], UserFirestoreRepository.prototype, "get", null);
3260
- __decorate([
3261
- Log(),
3262
- __metadata("design:type", Function),
3263
- __metadata("design:paramtypes", [String, String]),
3264
- __metadata("design:returntype", Promise)
3265
- ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
3266
-
3267
- class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3268
- constructor({ firestore, interceptors }, parentRepository) {
3269
- super({
3270
- firestore,
3271
- collectionName: 'payment_method',
3272
- parentIdField: 'userId',
3273
- model: UserPaymentMethod,
3274
- interceptors,
3275
- });
3276
- this.parentRepository = parentRepository;
3277
- }
3278
- }
3279
-
3280
3739
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3281
3740
  constructor({ firestore, interceptors }) {
3282
3741
  super({
@@ -3423,39 +3882,134 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
3423
3882
  async fetchPaginatedReviews() {
3424
3883
  return Promise.resolve([]);
3425
3884
  }
3426
- }
3427
- __decorate([
3428
- Log(),
3429
- __metadata("design:type", Function),
3430
- __metadata("design:paramtypes", [String]),
3431
- __metadata("design:returntype", Promise)
3432
- ], ProductFirestoreRepository.prototype, "getBySlug", null);
3433
- __decorate([
3434
- Log(),
3435
- __metadata("design:type", Function),
3436
- __metadata("design:paramtypes", [String]),
3437
- __metadata("design:returntype", Promise)
3438
- ], ProductFirestoreRepository.prototype, "fetchReviews", null);
3885
+ }
3886
+ __decorate([
3887
+ Log(),
3888
+ __metadata("design:type", Function),
3889
+ __metadata("design:paramtypes", [String]),
3890
+ __metadata("design:returntype", Promise)
3891
+ ], ProductFirestoreRepository.prototype, "getBySlug", null);
3892
+ __decorate([
3893
+ Log(),
3894
+ __metadata("design:type", Function),
3895
+ __metadata("design:paramtypes", [String]),
3896
+ __metadata("design:returntype", Promise)
3897
+ ], ProductFirestoreRepository.prototype, "fetchReviews", null);
3898
+
3899
+ class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3900
+ constructor({ firestore, interceptors }, parentRepository) {
3901
+ super({
3902
+ firestore,
3903
+ collectionName: 'variants',
3904
+ parentIdField: 'productId',
3905
+ model: Variant,
3906
+ interceptors,
3907
+ });
3908
+ this.parentRepository = parentRepository;
3909
+ }
3910
+ }
3911
+
3912
+ class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3913
+ constructor({ firestore, interceptors }) {
3914
+ super({
3915
+ firestore,
3916
+ collectionName: 'subscriptionProducts',
3917
+ model: Product,
3918
+ interceptors,
3919
+ });
3920
+ }
3921
+ }
3922
+
3923
+ class SequenceFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3924
+ constructor({ firestore, interceptors }) {
3925
+ super({
3926
+ firestore,
3927
+ collectionName: 'sequences',
3928
+ model: Sequence,
3929
+ interceptors,
3930
+ });
3931
+ }
3932
+ }
3933
+
3934
+ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3935
+ constructor({ firestore, interceptors }) {
3936
+ super({
3937
+ firestore,
3938
+ collectionName: 'dms',
3939
+ model: Home,
3940
+ interceptors,
3941
+ });
3942
+ this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
3943
+ var _a, _b, _c;
3944
+ return ({
3945
+ category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
3946
+ ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
3947
+ : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
3948
+ 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)) || [],
3949
+ });
3950
+ };
3951
+ this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
3952
+ var _a;
3953
+ return ({
3954
+ category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
3955
+ products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
3956
+ });
3957
+ };
3958
+ }
3959
+ buildModelInstance() {
3960
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
3961
+ return {
3962
+ toFirestore: (data) => {
3963
+ const modifiedData = this.homeToFirestore(data);
3964
+ return toFirestore(modifiedData);
3965
+ },
3966
+ fromFirestore: (snap) => {
3967
+ const instance = fromFirestore(snap);
3968
+ return this.homeFromFirestore(instance);
3969
+ },
3970
+ };
3971
+ }
3972
+ homeToFirestore(home) {
3973
+ var _a, _b, _c, _d;
3974
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3975
+ home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
3976
+ home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
3977
+ home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
3978
+ }
3979
+ return home;
3980
+ }
3981
+ homeFromFirestore(home) {
3982
+ var _a;
3983
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3984
+ home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
3985
+ home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
3986
+ home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
3987
+ home.data.createdAt =
3988
+ home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
3989
+ home.data.expiresAt =
3990
+ home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
3991
+ }
3992
+ return home;
3993
+ }
3994
+ }
3439
3995
 
3440
- class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3441
- constructor({ firestore, interceptors }, parentRepository) {
3996
+ class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3997
+ constructor({ firestore, interceptors }) {
3442
3998
  super({
3443
3999
  firestore,
3444
- collectionName: 'variants',
3445
- parentIdField: 'productId',
3446
- model: Variant,
4000
+ collectionName: 'shopMenus',
4001
+ model: ShopMenu,
3447
4002
  interceptors,
3448
4003
  });
3449
- this.parentRepository = parentRepository;
3450
4004
  }
3451
4005
  }
3452
4006
 
3453
- class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3454
- constructor({ firestore, interceptors }) {
4007
+ class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4008
+ constructor({ firestore, interceptors, }) {
3455
4009
  super({
3456
4010
  firestore,
3457
- collectionName: 'subscriptionProducts',
3458
- model: Product,
4011
+ collectionName: 'shopSettings',
4012
+ model: ShopSettings,
3459
4013
  interceptors,
3460
4014
  });
3461
4015
  }
@@ -3654,87 +4208,177 @@ class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(
3654
4208
  }
3655
4209
  }
3656
4210
 
3657
- class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4211
+ class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3658
4212
  constructor({ firestore, interceptors }) {
3659
4213
  super({
3660
4214
  firestore,
3661
- collectionName: 'dms',
3662
- model: Home,
4215
+ collectionName: 'leads',
4216
+ model: Lead,
3663
4217
  interceptors,
3664
4218
  });
3665
- this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
3666
- var _a, _b, _c;
3667
- return ({
3668
- category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
3669
- ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
3670
- : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
3671
- 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)) || [],
3672
- });
3673
- };
3674
- this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
3675
- var _a;
3676
- return ({
3677
- category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
3678
- products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
3679
- });
3680
- };
3681
- }
3682
- buildModelInstance() {
3683
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3684
- return {
3685
- toFirestore: (data) => {
3686
- const modifiedData = this.homeToFirestore(data);
3687
- return toFirestore(modifiedData);
3688
- },
3689
- fromFirestore: (snap) => {
3690
- const instance = fromFirestore(snap);
3691
- return this.homeFromFirestore(instance);
3692
- },
3693
- };
3694
4219
  }
3695
- homeToFirestore(home) {
3696
- var _a, _b, _c, _d;
3697
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3698
- home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
3699
- home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
3700
- home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
3701
- }
3702
- return home;
4220
+ }
4221
+
4222
+ class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4223
+ constructor({ firestore, interceptors }, parentRepository) {
4224
+ super({
4225
+ firestore,
4226
+ collectionName: 'editions',
4227
+ parentIdField: 'subscriptionId',
4228
+ model: Edition,
4229
+ interceptors,
4230
+ });
4231
+ this.parentRepository = parentRepository;
3703
4232
  }
3704
- homeFromFirestore(home) {
3705
- var _a;
3706
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3707
- home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
3708
- home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
3709
- home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
3710
- home.data.createdAt =
3711
- home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
3712
- home.data.expiresAt =
3713
- home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
3714
- }
3715
- return home;
4233
+ }
4234
+
4235
+ class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4236
+ constructor({ firestore, interceptors, }) {
4237
+ super({
4238
+ firestore,
4239
+ collectionName: 'subscription',
4240
+ model: Subscription,
4241
+ interceptors,
4242
+ });
3716
4243
  }
3717
4244
  }
3718
4245
 
3719
- class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4246
+ class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3720
4247
  constructor({ firestore, interceptors }) {
3721
4248
  super({
3722
4249
  firestore,
3723
- collectionName: 'shopMenus',
3724
- model: ShopMenu,
4250
+ collectionName: 'subscriptionMaterialization',
4251
+ model: SubscriptionMaterialization,
3725
4252
  interceptors,
3726
4253
  });
3727
4254
  }
3728
4255
  }
3729
4256
 
3730
- class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4257
+ class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4258
+ constructor({ firestore, interceptors }, parentRepository) {
4259
+ super({
4260
+ firestore,
4261
+ collectionName: 'payments',
4262
+ parentIdField: 'subscriptionId',
4263
+ model: SubscriptionPayment,
4264
+ interceptors,
4265
+ });
4266
+ this.parentRepository = parentRepository;
4267
+ }
4268
+ }
4269
+
4270
+ class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3731
4271
  constructor({ firestore, interceptors, }) {
3732
4272
  super({
3733
4273
  firestore,
3734
- collectionName: 'shopSettings',
3735
- model: ShopSettings,
4274
+ collectionName: 'subscriptionSummary',
4275
+ model: SubscriptionSummary,
4276
+ interceptors,
4277
+ });
4278
+ }
4279
+ }
4280
+
4281
+ class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4282
+ constructor({ firestore, interceptors }, parentRepository) {
4283
+ super({
4284
+ firestore,
4285
+ collectionName: 'address',
4286
+ parentIdField: 'userId',
4287
+ model: UserAddress,
4288
+ interceptors,
4289
+ });
4290
+ this.parentRepository = parentRepository;
4291
+ }
4292
+ }
4293
+
4294
+ class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4295
+ constructor({ firestore, interceptors }, parentRepository) {
4296
+ super({
4297
+ firestore,
4298
+ collectionName: 'CX',
4299
+ parentIdField: 'userId',
4300
+ model: BeautyProfile,
4301
+ interceptors,
4302
+ });
4303
+ this.parentRepository = parentRepository;
4304
+ }
4305
+ }
4306
+
4307
+ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4308
+ constructor({ firestore, interceptors }) {
4309
+ super({
4310
+ firestore,
4311
+ collectionName: 'users',
4312
+ model: User,
4313
+ interceptors,
4314
+ });
4315
+ }
4316
+ async get(identifiers) {
4317
+ const user = await super.get({ id: identifiers.id });
4318
+ user.beautyProfile = await this.getBeautyProfile(user.id);
4319
+ user.isSubscriber = await this.checkIfIsSubscriber(user.id);
4320
+ return user;
4321
+ }
4322
+ async checkIfExistsByField(field, value) {
4323
+ const result = await this.find({ filters: { [field]: value } });
4324
+ return result.count > 0;
4325
+ }
4326
+ buildModelInstance() {
4327
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
4328
+ return {
4329
+ toFirestore: (data) => {
4330
+ const plain = toFirestore(data);
4331
+ delete plain.isSubscriber;
4332
+ return plain;
4333
+ },
4334
+ fromFirestore,
4335
+ };
4336
+ }
4337
+ async getBeautyProfile(userId) {
4338
+ const beautyProfile = await this.firestore
4339
+ .getCollection(`${this.collectionName}/${userId}/CX`)
4340
+ .withConverter(this.buildBeautyProfileModelInstance())
4341
+ .getDoc('beautyProfile')
4342
+ .get();
4343
+ return beautyProfile.data();
4344
+ }
4345
+ async checkIfIsSubscriber(userId) {
4346
+ const docs = await this.collection('subscription')
4347
+ .where('user.id', '==', userId)
4348
+ .where('status', '==', 'active')
4349
+ .getDocs();
4350
+ return !!docs && !!docs.size;
4351
+ }
4352
+ buildBeautyProfileModelInstance() {
4353
+ return {
4354
+ toFirestore: (data) => data.toPlain(),
4355
+ fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
4356
+ };
4357
+ }
4358
+ }
4359
+ __decorate([
4360
+ Log(),
4361
+ __metadata("design:type", Function),
4362
+ __metadata("design:paramtypes", [Object]),
4363
+ __metadata("design:returntype", Promise)
4364
+ ], UserFirestoreRepository.prototype, "get", null);
4365
+ __decorate([
4366
+ Log(),
4367
+ __metadata("design:type", Function),
4368
+ __metadata("design:paramtypes", [String, String]),
4369
+ __metadata("design:returntype", Promise)
4370
+ ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
4371
+
4372
+ class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4373
+ constructor({ firestore, interceptors }, parentRepository) {
4374
+ super({
4375
+ firestore,
4376
+ collectionName: 'payment_method',
4377
+ parentIdField: 'userId',
4378
+ model: UserPaymentMethod,
3736
4379
  interceptors,
3737
4380
  });
4381
+ this.parentRepository = parentRepository;
3738
4382
  }
3739
4383
  }
3740
4384
 
@@ -6136,15 +6780,6 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6136
6780
  }),
6137
6781
  },
6138
6782
  },
6139
- {
6140
- metadatas: {
6141
- columnName: 'metadatas',
6142
- fields: ['shop', 'title', 'description'],
6143
- bindPersistData: (value) => ({
6144
- metadatas: { data: value },
6145
- }),
6146
- },
6147
- },
6148
6783
  { isCollection: { columnName: 'is_collection' } },
6149
6784
  { isWishlist: { columnName: 'is_wishlist' } },
6150
6785
  'reference',
@@ -6164,7 +6799,6 @@ class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
6164
6799
  'theme',
6165
6800
  { bannerUrl: { columnName: 'banner_url' } },
6166
6801
  { personHasPhoto: { columnName: 'person_has_photo' } },
6167
- { mostRelevants: { columnName: 'most_relevants', type: HasuraGraphQLColumnType.Jsonb } },
6168
6802
  ],
6169
6803
  });
6170
6804
  this.categoryFilterRepository = categoryFilterRepository;
@@ -6377,4 +7011,4 @@ __decorate([
6377
7011
  __metadata("design:returntype", Promise)
6378
7012
  ], WishlistHasuraGraphQLRepository.prototype, "findBfluOrGlamgirlWishlists", null);
6379
7013
 
6380
- export { AccessoryImportances, Address, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, GenderDestination, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, PersonTypes, Plans, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductReviews, ProductReviewsHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, is, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
7014
+ export { AccessoryImportances, Address, AdyenCardService, AdyenPaymentMethodFactory, AntifraudBankSlipService, AntifraudCardService, AntifraudGlampointsService, AntifraudPixService, AntifraudProviderFactory, AntifraudProviders, Area, Authentication, AuthenticationFirebaseAuthService, AxiosAdapter, Base, BaseModel, BeardProblems, BeardSizes, BeautyProductImportances, BeautyProfile, BeautyQuestionsHelper, BillingStatus, BodyProblems, BodyShapes, BodyTattoos, BusinessError, Buy2Win, Buy2WinFirestoreRepository, Campaign, CampaignBanner, CampaignDashboard, CampaignDashboardFirestoreRepository, CampaignHashtag, CampaignHashtagFirestoreRepository, Category, CategoryCollectionChildren, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryFilter, CategoryFilterHasuraGraphQLRepository, CategoryFirestoreRepository, CategoryHasuraGraphQL, CategoryHasuraGraphQLRepository, Checkout, CheckoutFirestoreRepository, CheckoutSubscription, CheckoutSubscriptionFirestoreRepository, CheckoutTypes, ClassNameHelper, ConnectBaseDocumentSnapshot, ConnectCollectionService, ConnectDocumentService, ConnectFirestoreService, Coupon, CouponFirestoreRepository, CouponSubtypes, CouponTypes, Debug, DebugDecoratorHelper, DebugHelper, DebugNamespaces, DuplicatedResultsError, Edition, EditionStatus, Exclusivities, FaceSkinOilinesses, FaceSkinProblems, FaceSkinTones, FamilyIncomes, Filter, FilterHasuraGraphQLRepository, FilterOption, FilterOptionHasuraGraphQLRepository, FilterType, FirebaseFileUploaderService, FragranceImportances, FraudValidationError, GenderDestination, GlampointsPaymentMethodFactory, GlampointsPaymentService, HairColors, HairProblems, HairStrands, HairTypes, Home, HomeFirestoreRepository, InvalidArgumentError, KitProduct, KitProductHasuraGraphQL, Lead, LeadFirestoreRepository, LegacyOrderFirestoreRepository, LineItem, Log, Logger, NotFoundError, OfficePosition, Order, OrderBlocked, OrderBlockedFirestoreRepository, OrderFirestoreRepository, OrderStatus, PagarmeBankSlipService, PagarmeCardService, PagarmePaymentMethodFactory, PagarmePixService, Payment, PaymentError, PaymentFirestoreRepository, PaymentMethods, PaymentProviderFactory, PaymentProviders, PaymentTransaction, PaymentType, PersonTypes, Plans, Product, ProductFirestoreRepository, ProductHasuraGraphQL, ProductHasuraGraphQLRepository, ProductReviews, ProductReviewsHasuraGraphQLRepository, ProductSpents, ProductStockNotification, ProductStockNotificationHasuraGraphQLRepository, ProductVariantFirestoreRepository, ProductsIndex, QuestionsFilters, RecoveryPassword, ReflectHelper, Register, RegisterFirebaseAuthService, RequiredArgumentError, RoundProductPricesHelper, Sequence, SequenceFirestoreRepository, ShippingMethod, ShopMenu, ShopMenuFirestoreRepository, ShopPageName, ShopSettings, ShopSettingsFirestoreRepository, Shops, SignInMethods, SignOut, Status, StockLimitError, StockOutError, Subscription, SubscriptionEditionFirestoreRepository, SubscriptionFirestoreRepository, SubscriptionMaterialization, SubscriptionMaterializationFirestoreRepository, SubscriptionPayment, SubscriptionPaymentFirestoreRepository, SubscriptionPlan, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionSummary, SubscriptionSummaryFirestoreRepository, Trace, UnauthorizedError, UpdateOptionActions, UpdateUserImage, User, UserAddress, UserAddressFirestoreRepository, UserAlreadyRegisteredError, UserBeautyProfileFirestoreRepository, UserFirestoreRepository, UserPaymentMethod, UserPaymentMethodFirestoreRepository, UserType, Variant, VariantHasuraGraphQL, VariantHasuraGraphQLRepository, WeakPasswordError, Where, Wishlist, WishlistHasuraGraphQLRepository, is, isDebuggable, isUUID, parseDateTime, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };