@infrab4a/connect 4.9.1-beta.0 → 4.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/index.cjs.js +344 -1057
  2. package/index.esm.js +338 -1023
  3. package/package.json +2 -2
  4. package/src/domain/general/index.d.ts +0 -2
  5. package/src/domain/shopping/index.d.ts +0 -5
  6. package/src/domain/shopping/models/index.d.ts +0 -2
  7. package/src/domain/shopping/models/order.d.ts +2 -2
  8. package/src/domain/shopping/models/payment.d.ts +63 -10
  9. package/src/domain/shopping/models/types/index.d.ts +4 -4
  10. package/src/domain/shopping/repositories/index.d.ts +0 -1
  11. package/src/errors/index.d.ts +2 -7
  12. package/src/infra/firebase/firestore/repositories/index.d.ts +2 -3
  13. package/src/infra/firebase/firestore/repositories/shopping/index.d.ts +0 -1
  14. package/src/utils/index.d.ts +2 -2
  15. package/src/domain/general/models/index.d.ts +0 -1
  16. package/src/domain/general/models/sequences.d.ts +0 -9
  17. package/src/domain/general/repositories/index.d.ts +0 -1
  18. package/src/domain/general/repositories/sequences.repository.d.ts +0 -4
  19. package/src/domain/shopping/enums/antifraud-providers.enum.d.ts +0 -6
  20. package/src/domain/shopping/enums/index.d.ts +0 -3
  21. package/src/domain/shopping/enums/payment-methods.enum.d.ts +0 -6
  22. package/src/domain/shopping/enums/payment-providers.enum.d.ts +0 -5
  23. package/src/domain/shopping/factories/adyen-payment-method.factory.d.ts +0 -8
  24. package/src/domain/shopping/factories/antifraud-provider.factory.d.ts +0 -15
  25. package/src/domain/shopping/factories/base-payment-method.factory.d.ts +0 -7
  26. package/src/domain/shopping/factories/glampoints-payment-method.factory.d.ts +0 -8
  27. package/src/domain/shopping/factories/index.d.ts +0 -5
  28. package/src/domain/shopping/factories/pagarme-payment-method.factory.d.ts +0 -10
  29. package/src/domain/shopping/factories/payment-provider.factory.d.ts +0 -15
  30. package/src/domain/shopping/interfaces/antifraud-method-factory.interface.d.ts +0 -11
  31. package/src/domain/shopping/interfaces/antifraud-provider.interface.d.ts +0 -5
  32. package/src/domain/shopping/interfaces/index.d.ts +0 -7
  33. package/src/domain/shopping/interfaces/payment-method-factory.interface.d.ts +0 -14
  34. package/src/domain/shopping/interfaces/payment-provider-bank-slip.interface.d.ts +0 -5
  35. package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +0 -7
  36. package/src/domain/shopping/interfaces/payment-provider-glampoints.interface.d.ts +0 -5
  37. package/src/domain/shopping/interfaces/payment-provider-pix.interface.d.ts +0 -5
  38. package/src/domain/shopping/models/order-blocked.d.ts +0 -26
  39. package/src/domain/shopping/models/payment-transaction.d.ts +0 -66
  40. package/src/domain/shopping/repositories/order-blocked.repository.d.ts +0 -6
  41. package/src/domain/shopping/services/adyen-card-payment.service.d.ts +0 -13
  42. package/src/domain/shopping/services/antifraud-bankslip.service.d.ts +0 -9
  43. package/src/domain/shopping/services/antifraud-card.service.d.ts +0 -18
  44. package/src/domain/shopping/services/antifraud-glampoints.service.d.ts +0 -6
  45. package/src/domain/shopping/services/antifraud-pix.service.d.ts +0 -6
  46. package/src/domain/shopping/services/glampoints-payment.service.d.ts +0 -8
  47. package/src/domain/shopping/services/index.d.ts +0 -9
  48. package/src/domain/shopping/services/pagarme-bank-slip-payment.service.d.ts +0 -11
  49. package/src/domain/shopping/services/pagarme-card-payment.service.d.ts +0 -13
  50. package/src/domain/shopping/services/pagarme-pix-payment.service.d.ts +0 -11
  51. package/src/domain/shopping/types/adyen-credentials.type.d.ts +0 -6
  52. package/src/domain/shopping/types/antifraud-provider.type.d.ts +0 -2
  53. package/src/domain/shopping/types/index.d.ts +0 -6
  54. package/src/domain/shopping/types/pagarme-credentials.type.d.ts +0 -5
  55. package/src/domain/shopping/types/payment-card-info.type.d.ts +0 -4
  56. package/src/domain/shopping/types/payment-method.type.d.ts +0 -2
  57. package/src/domain/shopping/types/payment-provider.type.d.ts +0 -2
  58. package/src/errors/business.error.d.ts +0 -7
  59. package/src/errors/fraud-validation.error.d.ts +0 -7
  60. package/src/errors/payment.error.d.ts +0 -7
  61. package/src/errors/stock-limit.error.d.ts +0 -5
  62. package/src/errors/stock-out.error.d.ts +0 -5
  63. package/src/errors/types/checkout-additional-data-erro.type.d.ts +0 -5
  64. package/src/errors/types/index.d.ts +0 -1
  65. package/src/infra/firebase/firestore/repositories/general/index.d.ts +0 -1
  66. package/src/infra/firebase/firestore/repositories/general/sequences-firestore.repository.d.ts +0 -7
  67. package/src/infra/firebase/firestore/repositories/shopping/order-blocked-firestore.repository.d.ts +0 -9
package/index.esm.js CHANGED
@@ -2,8 +2,8 @@ import 'reflect-metadata';
2
2
  import * as tslib_1 from 'tslib';
3
3
  import { __decorate, __metadata, __rest } from 'tslib';
4
4
  import { plainToInstance, instanceToPlain, Type, Expose } from 'class-transformer';
5
- import { parseISO, format, startOfDay, endOfDay, subDays, addDays } from 'date-fns';
6
- export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub, subDays } from 'date-fns';
5
+ import { parseISO } from 'date-fns';
6
+ export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub } from 'date-fns';
7
7
  import { isNil, isArray as isArray$1, first, last, flatten, compact, get, isString, each, unset, isObject as isObject$1, set, isNumber, chunk, isEmpty, isDate, isBoolean, isInteger, isNaN as isNaN$1, sortBy, omit } from 'lodash';
8
8
  export { chunk, each, get, isBoolean, isDate, isEmpty, isInteger, isNaN, isNil, isNumber, isObject, isString, now, omit, pick, set, sortBy, unset } from 'lodash';
9
9
  import { debug } from 'debug';
@@ -14,65 +14,6 @@ import { deleteField, arrayUnion, arrayRemove, Timestamp, doc, getDoc, updateDoc
14
14
  import { ref, uploadBytes } from 'firebase/storage';
15
15
  import { mutation, query as query$1 } from 'gql-query-builder';
16
16
 
17
- var antifraudProviders;
18
- (function (antifraudProviders) {
19
- antifraudProviders["BANKSLIP"] = "bankSlip";
20
- antifraudProviders["CARD"] = "card";
21
- antifraudProviders["PIX"] = "pix";
22
- antifraudProviders["POINTS"] = "glampoints";
23
- })(antifraudProviders || (antifraudProviders = {}));
24
-
25
- var paymentMethods;
26
- (function (paymentMethods) {
27
- paymentMethods["CARD"] = "card";
28
- paymentMethods["BANKSLIP"] = "bankSlip";
29
- paymentMethods["PIX"] = "pix";
30
- paymentMethods["POINTS"] = "glampoints";
31
- })(paymentMethods || (paymentMethods = {}));
32
-
33
- var paymentProviders;
34
- (function (paymentProviders) {
35
- paymentProviders["PAGARME"] = "pagarMe";
36
- paymentProviders["ADYEN"] = "adyen";
37
- paymentProviders["GLAMPOINTS"] = "glampoints";
38
- })(paymentProviders || (paymentProviders = {}));
39
-
40
- class BasePaymentMethodFactory {
41
- constructor(methods) {
42
- this.methods = methods;
43
- }
44
- build(method) {
45
- return this.methods[method];
46
- }
47
- }
48
-
49
- class AdyenPaymentMethodFactory extends BasePaymentMethodFactory {
50
- }
51
-
52
- class AntifraudProviderFactory {
53
- constructor(antifraudProviders) {
54
- this.antifraudProviders = antifraudProviders;
55
- }
56
- build(provider) {
57
- return this.antifraudProviders[provider];
58
- }
59
- }
60
-
61
- class GlampointsPaymentMethodFactory extends BasePaymentMethodFactory {
62
- }
63
-
64
- class PagarmePaymentMethodFactory extends BasePaymentMethodFactory {
65
- }
66
-
67
- class PaymentProviderFactory {
68
- constructor(paymentProviders) {
69
- this.paymentProviders = paymentProviders;
70
- }
71
- build(provider) {
72
- return this.paymentProviders[provider];
73
- }
74
- }
75
-
76
17
  class BaseModel {
77
18
  get identifier() {
78
19
  const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
@@ -555,178 +496,175 @@ var Status;
555
496
  Status["CANCELLED"] = "Cancelado";
556
497
  })(Status || (Status = {}));
557
498
 
558
- class PaymentTransaction extends BaseModel {
499
+ class Payment extends BaseModel {
500
+ static get identifiersFields() {
501
+ return ['id'];
502
+ }
559
503
  }
560
504
  __decorate([
561
505
  Expose({ name: 'refuse_reason' }),
562
506
  __metadata("design:type", String)
563
- ], PaymentTransaction.prototype, "refuseReason", void 0);
507
+ ], Payment.prototype, "refuseReason", void 0);
564
508
  __decorate([
565
509
  Expose({ name: 'status_reason' }),
566
510
  __metadata("design:type", String)
567
- ], PaymentTransaction.prototype, "statusReason", void 0);
511
+ ], Payment.prototype, "statusReason", void 0);
568
512
  __decorate([
569
513
  Expose({ name: 'acquirer_response_code' }),
570
514
  __metadata("design:type", String)
571
- ], PaymentTransaction.prototype, "acquirerResponseCode", void 0);
515
+ ], Payment.prototype, "acquirerResponseCode", void 0);
572
516
  __decorate([
573
517
  Expose({ name: 'acquirer_name' }),
574
518
  __metadata("design:type", String)
575
- ], PaymentTransaction.prototype, "acquirerName", void 0);
519
+ ], Payment.prototype, "acquirerName", void 0);
576
520
  __decorate([
577
521
  Expose({ name: 'acquirer_id' }),
578
522
  __metadata("design:type", String)
579
- ], PaymentTransaction.prototype, "acquirerId", void 0);
523
+ ], Payment.prototype, "acquirerId", void 0);
580
524
  __decorate([
581
525
  Expose({ name: 'authorization_code' }),
582
526
  __metadata("design:type", String)
583
- ], PaymentTransaction.prototype, "authorizationCode", void 0);
527
+ ], Payment.prototype, "authorizationCode", void 0);
584
528
  __decorate([
585
529
  Expose({ name: 'soft_descriptor' }),
586
530
  __metadata("design:type", String)
587
- ], PaymentTransaction.prototype, "softDescriptor", void 0);
531
+ ], Payment.prototype, "softDescriptor", void 0);
588
532
  __decorate([
589
533
  Expose({ name: 'date_created' }),
590
534
  __metadata("design:type", String)
591
- ], PaymentTransaction.prototype, "dateCreated", void 0);
535
+ ], Payment.prototype, "dateCreated", void 0);
592
536
  __decorate([
593
537
  Expose({ name: 'date_updated' }),
594
538
  __metadata("design:type", String)
595
- ], PaymentTransaction.prototype, "dateUpdated", void 0);
539
+ ], Payment.prototype, "dateUpdated", void 0);
596
540
  __decorate([
597
541
  Expose({ name: 'authorized_amount' }),
598
542
  __metadata("design:type", Number)
599
- ], PaymentTransaction.prototype, "authorizedAmount", void 0);
543
+ ], Payment.prototype, "authorizedAmount", void 0);
600
544
  __decorate([
601
545
  Expose({ name: 'paid_amount' }),
602
546
  __metadata("design:type", Number)
603
- ], PaymentTransaction.prototype, "paidAmount", void 0);
547
+ ], Payment.prototype, "paidAmount", void 0);
548
+ __decorate([
549
+ Expose({ name: 'paid_at' }),
550
+ __metadata("design:type", String)
551
+ ], Payment.prototype, "paidAt", void 0);
604
552
  __decorate([
605
553
  Expose({ name: 'refunded_amount' }),
606
554
  __metadata("design:type", Number)
607
- ], PaymentTransaction.prototype, "refundedAmount", void 0);
555
+ ], Payment.prototype, "refundedAmount", void 0);
608
556
  __decorate([
609
557
  Expose({ name: 'card_holder_name' }),
610
558
  __metadata("design:type", String)
611
- ], PaymentTransaction.prototype, "cardHolderName", void 0);
559
+ ], Payment.prototype, "cardHolderName", void 0);
612
560
  __decorate([
613
561
  Expose({ name: 'card_last_digits' }),
614
562
  __metadata("design:type", String)
615
- ], PaymentTransaction.prototype, "cardLastDigits", void 0);
563
+ ], Payment.prototype, "cardLastDigits", void 0);
616
564
  __decorate([
617
565
  Expose({ name: 'card_first_digits' }),
618
566
  __metadata("design:type", String)
619
- ], PaymentTransaction.prototype, "cardFirstDigits", void 0);
567
+ ], Payment.prototype, "cardFirstDigits", void 0);
620
568
  __decorate([
621
569
  Expose({ name: 'card_brand' }),
622
570
  __metadata("design:type", String)
623
- ], PaymentTransaction.prototype, "cardBrand", void 0);
571
+ ], Payment.prototype, "cardBrand", void 0);
624
572
  __decorate([
625
573
  Expose({ name: 'card_pin_mode' }),
626
574
  __metadata("design:type", String)
627
- ], PaymentTransaction.prototype, "cardPinMode", void 0);
575
+ ], Payment.prototype, "cardPinMode", void 0);
628
576
  __decorate([
629
577
  Expose({ name: 'card_magstripe_fallback' }),
630
578
  __metadata("design:type", Boolean)
631
- ], PaymentTransaction.prototype, "cardMagstripeFallback", void 0);
579
+ ], Payment.prototype, "cardMagstripeFallback", void 0);
632
580
  __decorate([
633
581
  Expose({ name: 'cvm_pin' }),
634
582
  __metadata("design:type", Boolean)
635
- ], PaymentTransaction.prototype, "cvmPin", void 0);
583
+ ], Payment.prototype, "cvmPin", void 0);
636
584
  __decorate([
637
585
  Expose({ name: 'postback_url' }),
638
586
  __metadata("design:type", String)
639
- ], PaymentTransaction.prototype, "postbackUrl", void 0);
587
+ ], Payment.prototype, "postbackUrl", void 0);
640
588
  __decorate([
641
589
  Expose({ name: 'payment_method' }),
642
590
  __metadata("design:type", String)
643
- ], PaymentTransaction.prototype, "paymentMethod", void 0);
591
+ ], Payment.prototype, "paymentMethod", void 0);
644
592
  __decorate([
645
593
  Expose({ name: 'capture_method' }),
646
594
  __metadata("design:type", String)
647
- ], PaymentTransaction.prototype, "captureMethod", void 0);
595
+ ], Payment.prototype, "captureMethod", void 0);
648
596
  __decorate([
649
597
  Expose({ name: 'antifraud_score' }),
650
598
  __metadata("design:type", String)
651
- ], PaymentTransaction.prototype, "antifraudScore", void 0);
599
+ ], Payment.prototype, "antifraudScore", void 0);
652
600
  __decorate([
653
601
  Expose({ name: 'boleto_url' }),
654
602
  __metadata("design:type", String)
655
- ], PaymentTransaction.prototype, "boletoUrl", void 0);
603
+ ], Payment.prototype, "boletoUrl", void 0);
656
604
  __decorate([
657
605
  Expose({ name: 'boleto_barcode' }),
658
606
  __metadata("design:type", String)
659
- ], PaymentTransaction.prototype, "boletoBarcode", void 0);
607
+ ], Payment.prototype, "boletoBarcode", void 0);
660
608
  __decorate([
661
609
  Expose({ name: 'boleto_expiration_date' }),
662
610
  __metadata("design:type", String)
663
- ], PaymentTransaction.prototype, "boletoExpirationDate", void 0);
611
+ ], Payment.prototype, "boletoExpirationDate", void 0);
664
612
  __decorate([
665
613
  Expose({ name: 'subscription_id' }),
666
614
  __metadata("design:type", String)
667
- ], PaymentTransaction.prototype, "subscriptionId", void 0);
615
+ ], Payment.prototype, "subscriptionId", void 0);
668
616
  __decorate([
669
617
  Expose({ name: 'split_rules' }),
670
618
  __metadata("design:type", String)
671
- ], PaymentTransaction.prototype, "splitRules", void 0);
619
+ ], Payment.prototype, "splitRules", void 0);
672
620
  __decorate([
673
621
  Expose({ name: 'antifraud_metadata' }),
674
622
  __metadata("design:type", Object)
675
- ], PaymentTransaction.prototype, "antifraudMetadata", void 0);
623
+ ], Payment.prototype, "antifraudMetadata", void 0);
676
624
  __decorate([
677
625
  Expose({ name: 'reference_key' }),
678
626
  __metadata("design:type", String)
679
- ], PaymentTransaction.prototype, "referenceKey", void 0);
627
+ ], Payment.prototype, "referenceKey", void 0);
680
628
  __decorate([
681
629
  Expose({ name: 'local_transaction_id' }),
682
630
  __metadata("design:type", String)
683
- ], PaymentTransaction.prototype, "localTransactionId", void 0);
631
+ ], Payment.prototype, "localTransactionId", void 0);
684
632
  __decorate([
685
633
  Expose({ name: 'local_time' }),
686
634
  __metadata("design:type", String)
687
- ], PaymentTransaction.prototype, "localTime", void 0);
635
+ ], Payment.prototype, "localTime", void 0);
688
636
  __decorate([
689
637
  Expose({ name: 'fraud_covered' }),
690
638
  __metadata("design:type", Boolean)
691
- ], PaymentTransaction.prototype, "fraudCovered", void 0);
639
+ ], Payment.prototype, "fraudCovered", void 0);
692
640
  __decorate([
693
641
  Expose({ name: 'fraud_reimbursed' }),
694
642
  __metadata("design:type", String)
695
- ], PaymentTransaction.prototype, "fraudReimbursed", void 0);
643
+ ], Payment.prototype, "fraudReimbursed", void 0);
696
644
  __decorate([
697
645
  Expose({ name: 'order_id' }),
698
646
  __metadata("design:type", String)
699
- ], PaymentTransaction.prototype, "orderId", void 0);
647
+ ], Payment.prototype, "orderId", void 0);
700
648
  __decorate([
701
649
  Expose({ name: 'risk_level' }),
702
650
  __metadata("design:type", String)
703
- ], PaymentTransaction.prototype, "riskLevel", void 0);
651
+ ], Payment.prototype, "riskLevel", void 0);
704
652
  __decorate([
705
653
  Expose({ name: 'receipt_url' }),
706
654
  __metadata("design:type", String)
707
- ], PaymentTransaction.prototype, "receiptUrl", void 0);
655
+ ], Payment.prototype, "receiptUrl", void 0);
708
656
  __decorate([
709
657
  Expose({ name: 'private_label' }),
710
658
  __metadata("design:type", String)
711
- ], PaymentTransaction.prototype, "privateLabel", void 0);
659
+ ], Payment.prototype, "privateLabel", void 0);
712
660
  __decorate([
713
661
  Expose({ name: 'pix_qr_code' }),
714
662
  __metadata("design:type", String)
715
- ], PaymentTransaction.prototype, "pixQrCode", void 0);
663
+ ], Payment.prototype, "pixQrCode", void 0);
716
664
  __decorate([
717
665
  Expose({ name: 'pix_expiration_date' }),
718
666
  __metadata("design:type", String)
719
- ], PaymentTransaction.prototype, "pixExpirationDate", void 0);
720
-
721
- class Payment extends BaseModel {
722
- static get identifiersFields() {
723
- return ['id'];
724
- }
725
- }
726
- __decorate([
727
- Type(() => PaymentTransaction),
728
- __metadata("design:type", PaymentTransaction)
729
- ], Payment.prototype, "transaction", void 0);
667
+ ], Payment.prototype, "pixExpirationDate", void 0);
730
668
 
731
669
  class SubscriptionPayment extends BaseModel {
732
670
  static get identifiersFields() {
@@ -2337,16 +2275,10 @@ var OrderStatus;
2337
2275
  class Order extends Checkout {
2338
2276
  }
2339
2277
  __decorate([
2340
- Type(() => PaymentTransaction),
2341
- __metadata("design:type", PaymentTransaction)
2278
+ Type(() => Payment),
2279
+ __metadata("design:type", Payment)
2342
2280
  ], Order.prototype, "payment", void 0);
2343
2281
 
2344
- class OrderBlocked extends BaseModel {
2345
- static get identifiersFields() {
2346
- return ['id'];
2347
- }
2348
- }
2349
-
2350
2282
  class CheckoutSubscription extends BaseModel {
2351
2283
  static get identifiersFields() {
2352
2284
  return ['id'];
@@ -2369,591 +2301,6 @@ __decorate([
2369
2301
  __metadata("design:type", Coupon)
2370
2302
  ], CheckoutSubscription.prototype, "coupon", void 0);
2371
2303
 
2372
- class BusinessError extends CustomError {
2373
- constructor(message, additionalData, type = '') {
2374
- super(message);
2375
- this.additionalData = additionalData;
2376
- this.type = type;
2377
- }
2378
- }
2379
-
2380
- class DuplicatedResultsError extends CustomError {
2381
- constructor(message) {
2382
- super(message);
2383
- }
2384
- }
2385
-
2386
- class FraudValidationError extends CustomError {
2387
- constructor(message, additionalData) {
2388
- super(message);
2389
- this.additionalData = additionalData;
2390
- this.type = 'antifraud';
2391
- }
2392
- }
2393
-
2394
- class InvalidArgumentError extends CustomError {
2395
- constructor(message) {
2396
- super(message);
2397
- }
2398
- }
2399
-
2400
- class NotFoundError extends CustomError {
2401
- constructor(message) {
2402
- super(message);
2403
- }
2404
- }
2405
-
2406
- class PaymentError extends CustomError {
2407
- constructor(message, additionalData) {
2408
- super(message);
2409
- this.additionalData = additionalData;
2410
- this.type = 'payment';
2411
- }
2412
- }
2413
-
2414
- class RequiredArgumentError extends CustomError {
2415
- constructor(args) {
2416
- super(`Required arguments: ${args.join(', ')}`);
2417
- this.args = args;
2418
- this.arguments = args;
2419
- }
2420
- }
2421
-
2422
- class StockLimitError extends BusinessError {
2423
- constructor(message, additionalData) {
2424
- super(message, additionalData);
2425
- this.type = 'stock-limit';
2426
- }
2427
- }
2428
-
2429
- class StockOutError extends BusinessError {
2430
- constructor(message, additionalData) {
2431
- super(message, additionalData);
2432
- this.type = 'stock-out';
2433
- }
2434
- }
2435
-
2436
- class AdyenCardService {
2437
- constructor(credentials, paymentRepository, orderBlockedRepository) {
2438
- this.credentials = credentials;
2439
- this.paymentRepository = paymentRepository;
2440
- this.orderBlockedRepository = orderBlockedRepository;
2441
- }
2442
- async pay(checkout, card) {
2443
- try {
2444
- const result = await axios({
2445
- method: 'POST',
2446
- url: this.credentials.URL_TRANSACTION,
2447
- headers: {
2448
- 'x-api-key': this.credentials.API_KEY,
2449
- 'content-type': 'application/json',
2450
- },
2451
- data: this.createCardPayment(checkout, card),
2452
- });
2453
- if (result.data.resultCode !== 'Authorised') {
2454
- this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
2455
- 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`, {
2456
- checkoutId: checkout.id,
2457
- userEmail: checkout.user.email,
2458
- info: result.data,
2459
- }));
2460
- }
2461
- const payment = await this.paymentRepository.create(Payment.toInstance({
2462
- createdAt: new Date(),
2463
- updatedAt: new Date(),
2464
- userId: checkout.user.id,
2465
- checkoutId: checkout.id,
2466
- totalPrice: checkout.totalPrice,
2467
- paymentProvider: 'adyen',
2468
- transaction: Object.assign(Object.assign({}, result.data), { status: 'paid' }),
2469
- }));
2470
- return payment;
2471
- }
2472
- catch (error) {
2473
- 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', {
2474
- checkoutId: checkout.id,
2475
- userEmail: checkout.user.email,
2476
- info: error.message,
2477
- });
2478
- }
2479
- }
2480
- createCardPayment(checkout, card) {
2481
- return {
2482
- amount: {
2483
- currency: 'BRL',
2484
- value: ((checkout === null || checkout === void 0 ? void 0 : checkout.totalPrice) || 0) * 100,
2485
- },
2486
- paymentMethod: {
2487
- type: 'scheme',
2488
- storedPaymentMethodId: card.cardId,
2489
- },
2490
- reference: checkout.id,
2491
- shopperInteraction: 'Ecommerce',
2492
- merchantAccount: this.credentials.MERCHANT_ACCOUNT,
2493
- shopperReference: checkout.user.id,
2494
- recurringProcessingModel: 'CardOnFile',
2495
- returnUrl: this.credentials.URL_POSTBACK,
2496
- installments: {
2497
- value: card.installments,
2498
- },
2499
- };
2500
- }
2501
- addCard() {
2502
- throw new Error('Method not implemented.');
2503
- }
2504
- }
2505
-
2506
- class AntifraudBankSlipService {
2507
- constructor(orderBlockedRepository) {
2508
- this.orderBlockedRepository = orderBlockedRepository;
2509
- this.MAX_ORDER_VALUE = 5000;
2510
- }
2511
- async validate(checkout) {
2512
- var _a, _b;
2513
- if (checkout.totalPrice && checkout.totalPrice > this.MAX_ORDER_VALUE && !((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber)) {
2514
- await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Boleto not authorized', 'Boleto', 'day');
2515
- throw new FraudValidationError('Boleto não autorizado para cliente não assinante', {
2516
- checkoutId: checkout.id,
2517
- userEmail: checkout.user.email,
2518
- info: {
2519
- isSubscriber: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.isSubscriber,
2520
- subtotal: checkout.subTotalPrice,
2521
- total: checkout.totalPrice,
2522
- },
2523
- });
2524
- }
2525
- return true;
2526
- }
2527
- }
2528
-
2529
- class AntifraudCardService {
2530
- constructor(orderRepository, orderBlockedRepository) {
2531
- this.orderRepository = orderRepository;
2532
- this.orderBlockedRepository = orderBlockedRepository;
2533
- this.LIMIT_ORDERS_DAY = 2;
2534
- this.LIMIT_ORDERS_WEEK = 7;
2535
- this.LIMIT_BLOCKED_ORDERS_DAY = 5;
2536
- }
2537
- async validate(checkout, card) {
2538
- var _a, _b;
2539
- if (!(await this.verifyBlockedOrderAttempts(checkout, card)))
2540
- throw new FraudValidationError('Cliente com mais de 5 compras negadas/bloqueadas no dia', {
2541
- checkoutId: checkout.id,
2542
- userEmail: checkout.user.email,
2543
- info: {
2544
- isSubscriber: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber,
2545
- subtotal: checkout.subTotalPrice,
2546
- total: checkout.totalPrice,
2547
- },
2548
- });
2549
- if (!(await this.verifyDayAndWeekOrders(checkout, card)))
2550
- throw new FraudValidationError('Cliente tentando comprar mais de 2 vezes no dia ou 7 vezes na semana', {
2551
- checkoutId: checkout.id,
2552
- userEmail: checkout.user.email,
2553
- info: {
2554
- isSubscriber: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.isSubscriber,
2555
- subtotal: checkout.subTotalPrice,
2556
- total: checkout.totalPrice,
2557
- },
2558
- });
2559
- return true;
2560
- }
2561
- async verifyBlockedOrderAttempts(checkout, card) {
2562
- var _a, _b, _c, _d;
2563
- const day = `${format(new Date(), 'YYYY-MM-DD')}T00:00:00`;
2564
- const endOfDay = `${format(new Date(), 'YYYY-MM-DD')}T23:59:59`;
2565
- const ordersBlockedWithCpf = await this.orderBlockedRepository
2566
- .find({
2567
- filters: {
2568
- customer: { cpf: { operator: Where.EQUALS, value: (_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf } },
2569
- date: [
2570
- { operator: Where.GTE, value: new Date(day) },
2571
- { operator: Where.LTE, value: new Date(endOfDay) },
2572
- ],
2573
- },
2574
- })
2575
- .then((data) => data.data);
2576
- const ordersBlockedWithEmail = await this.orderBlockedRepository
2577
- .find({
2578
- filters: {
2579
- customer: { email: { operator: Where.EQUALS, value: (_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email } },
2580
- date: [
2581
- { operator: Where.GTE, value: new Date(day) },
2582
- { operator: Where.LTE, value: new Date(endOfDay) },
2583
- ],
2584
- },
2585
- })
2586
- .then((data) => data.data);
2587
- const ordersBlockedWithCep = await this.orderBlockedRepository
2588
- .find({
2589
- filters: {
2590
- customer: { shippingAddress: { zip: { operator: Where.EQUALS, value: (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.zip } } },
2591
- date: [
2592
- { operator: Where.GTE, value: new Date(day) },
2593
- { operator: Where.LTE, value: new Date(endOfDay) },
2594
- ],
2595
- },
2596
- })
2597
- .then((data) => data.data);
2598
- const ordersBlockedWithPhone = await this.orderBlockedRepository
2599
- .find({
2600
- filters: {
2601
- customer: { phoneNumber: { operator: Where.EQUALS, value: (_d = checkout.user) === null || _d === void 0 ? void 0 : _d.phone } },
2602
- date: [
2603
- { operator: Where.GTE, value: new Date(day) },
2604
- { operator: Where.LTE, value: new Date(endOfDay) },
2605
- ],
2606
- },
2607
- })
2608
- .then((data) => data.data);
2609
- const blockedUniqueEmails = ordersBlockedWithEmail.filter((e) => {
2610
- var _a;
2611
- return e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf);
2612
- });
2613
- const blockedUniqueCeps = ordersBlockedWithCep.filter((e) => {
2614
- var _a, _b;
2615
- 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);
2616
- });
2617
- const blockedUniquePhone = ordersBlockedWithPhone.filter((e) => {
2618
- var _a, _b, _c, _d, _e, _f;
2619
- return (e.customer.cpf !== ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.cpf) &&
2620
- e.customer.email !== ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.email) &&
2621
- ((_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()));
2622
- });
2623
- const blockedAttempts = ordersBlockedWithCpf
2624
- .concat(blockedUniqueEmails)
2625
- .concat(blockedUniqueCeps)
2626
- .concat(blockedUniquePhone);
2627
- if (blockedAttempts.length >= this.LIMIT_BLOCKED_ORDERS_DAY) {
2628
- await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'More than 5 attempts have failed', 'Failed attempts', 'day', card || null);
2629
- return false;
2630
- }
2631
- return true;
2632
- }
2633
- async verifyDayAndWeekOrders(checkout, card) {
2634
- var _a, _b, _c, _d, _e, _f, _g, _h;
2635
- 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'));
2636
- for (const key in ordersPerDay) {
2637
- if (ordersPerDay[key] > this.LIMIT_ORDERS_DAY) {
2638
- await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'day');
2639
- return false;
2640
- }
2641
- }
2642
- 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'));
2643
- for (const key in ordersPerWeek) {
2644
- if (ordersPerDay[key] > this.LIMIT_ORDERS_WEEK) {
2645
- await this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Order limit', key, 'week');
2646
- return false;
2647
- }
2648
- }
2649
- return true;
2650
- }
2651
- async validateOrdersByRange(cpf, email, phone, zip, card, range) {
2652
- const ordersCpf = await this.countOrdersByField('user', 'cpf', cpf, range);
2653
- const ordersByEmail = await this.countOrdersByField('user', 'email', email, range);
2654
- const ordersByPhone = await this.countOrdersByField('user', 'phone', phone, range);
2655
- const ordersByZip = await this.countOrdersByField('shippingAddress', 'zip', zip, range);
2656
- return {
2657
- cpf: ordersCpf,
2658
- email: ordersByEmail,
2659
- phone: ordersByPhone,
2660
- zip: ordersByZip,
2661
- };
2662
- }
2663
- async countOrdersByField(property, field, value, range) {
2664
- const filters = {
2665
- [property]: {
2666
- [field]: value,
2667
- },
2668
- ['createdAt']: [
2669
- { operator: Where.GTE, value: range.firstDate },
2670
- { operator: Where.LTE, value: range.lastDate },
2671
- ],
2672
- };
2673
- const docs = await (await this.orderRepository.find({ filters })).count;
2674
- return docs;
2675
- }
2676
- getDateRange(range = 'day') {
2677
- switch (range) {
2678
- case 'day':
2679
- return {
2680
- firstDate: startOfDay(new Date()).getTime(),
2681
- lastDate: endOfDay(new Date()).getTime(),
2682
- };
2683
- case 'week':
2684
- return {
2685
- firstDate: startOfDay(subDays(new Date(), 7)).getTime(),
2686
- lastDate: endOfDay(new Date()).getTime(),
2687
- };
2688
- default:
2689
- return {
2690
- firstDate: startOfDay(new Date()).getTime(),
2691
- lastDate: endOfDay(new Date()).getTime(),
2692
- };
2693
- }
2694
- }
2695
- }
2696
-
2697
- class AntifraudGlampointsService {
2698
- constructor() { }
2699
- async validate(checkout) {
2700
- return true;
2701
- }
2702
- }
2703
-
2704
- class AntifraudPixService {
2705
- constructor() { }
2706
- async validate(checkout) {
2707
- return true;
2708
- }
2709
- }
2710
-
2711
- class GlampointsPaymentService {
2712
- constructor(paymentRepository) {
2713
- this.paymentRepository = paymentRepository;
2714
- }
2715
- async pay(checkout) {
2716
- const payment = await this.paymentRepository.create(Payment.toInstance({
2717
- createdAt: new Date(),
2718
- updatedAt: new Date(),
2719
- userId: checkout.user.id,
2720
- checkoutId: checkout.id,
2721
- totalPrice: checkout.totalPrice,
2722
- paymentProvider: 'glampoints',
2723
- transaction: {
2724
- amount: 0,
2725
- acquirerResponseCode: '0000',
2726
- acquirerName: 'glampoints',
2727
- authorizedAmount: 0,
2728
- captureMethod: 'ecommerce',
2729
- installments: 1,
2730
- cost: 0,
2731
- paidAmount: 0,
2732
- paymentMethod: 'glampoints',
2733
- referer: 'api_key',
2734
- refundedAmount: 0,
2735
- status: 'paid',
2736
- statusReason: 'acquirer',
2737
- },
2738
- }));
2739
- return payment;
2740
- }
2741
- }
2742
-
2743
- class PagarmeBankSlipService {
2744
- constructor(credentials, paymentRepository) {
2745
- this.credentials = credentials;
2746
- this.paymentRepository = paymentRepository;
2747
- }
2748
- async pay(checkout) {
2749
- try {
2750
- const result = await axios({
2751
- method: 'POST',
2752
- url: this.credentials.URL_TRANSACTION,
2753
- data: this.createBoletoPayment(checkout),
2754
- });
2755
- if (result.data.status !== 'processing') {
2756
- return Promise.reject(new PaymentError(`Houve uma falha ao gerar o boleto. Tente novamente`, {
2757
- checkoutId: checkout.id,
2758
- userEmail: checkout.user.email,
2759
- info: result.data,
2760
- }));
2761
- }
2762
- const payment = await this.paymentRepository.create(Payment.toInstance({
2763
- createdAt: new Date(),
2764
- updatedAt: new Date(),
2765
- userId: checkout.user.id,
2766
- checkoutId: checkout.id,
2767
- totalPrice: checkout.totalPrice,
2768
- paymentProvider: 'pagarMe',
2769
- transaction: result.data,
2770
- }));
2771
- return payment;
2772
- }
2773
- catch (error) {
2774
- throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
2775
- checkoutId: checkout.id,
2776
- userEmail: checkout.user.email,
2777
- info: error.response.data,
2778
- });
2779
- }
2780
- }
2781
- createBoletoPayment(checkout) {
2782
- return {
2783
- api_key: this.credentials.API_KEY,
2784
- amount: Math.floor(checkout.totalPrice * 100),
2785
- boleto_rules: ['strict_expiration_date'],
2786
- boleto_instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
2787
- boleto_expiration_date: format(addDays(new Date(), 3), 'yyyy-MM-dd'),
2788
- payment_method: 'boleto',
2789
- postback_url: this.credentials.URL_POSTBACK,
2790
- customer: {
2791
- external_id: checkout.user.id,
2792
- type: 'individual',
2793
- country: 'br',
2794
- name: checkout.user.displayName,
2795
- documents: [
2796
- {
2797
- type: 'cpf',
2798
- number: checkout.user.cpf,
2799
- },
2800
- ],
2801
- },
2802
- };
2803
- }
2804
- }
2805
-
2806
- class PagarmeCardService {
2807
- constructor(credentials, paymentRepository, orderBlockedRepository) {
2808
- this.credentials = credentials;
2809
- this.paymentRepository = paymentRepository;
2810
- this.orderBlockedRepository = orderBlockedRepository;
2811
- }
2812
- async pay(checkout, card) {
2813
- var _a;
2814
- try {
2815
- const result = await axios({
2816
- method: 'POST',
2817
- url: this.credentials.URL_TRANSACTION,
2818
- data: this.createCardPayment(checkout, card),
2819
- });
2820
- if (result.data.status !== 'paid') {
2821
- this.orderBlockedRepository.createBlockedOrderOrPayment(checkout, 'Card not authorized', 'Card', 'day', card);
2822
- 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`, {
2823
- checkoutId: checkout.id,
2824
- userEmail: checkout.user.email,
2825
- info: result.data,
2826
- }));
2827
- }
2828
- const payment = await this.paymentRepository.create(Payment.toInstance({
2829
- createdAt: new Date(),
2830
- updatedAt: new Date(),
2831
- userId: checkout.user.id,
2832
- checkoutId: checkout.id,
2833
- totalPrice: checkout.totalPrice,
2834
- paymentProvider: 'pagarMe',
2835
- transaction: result.data,
2836
- }));
2837
- return payment;
2838
- }
2839
- catch (error) {
2840
- 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', {
2841
- checkoutId: checkout.id,
2842
- userEmail: checkout.user.email,
2843
- info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
2844
- });
2845
- }
2846
- }
2847
- addCard() {
2848
- throw new Error('Method not implemented.');
2849
- }
2850
- createCardPayment(checkout, card) {
2851
- var _a, _b, _c, _d, _e, _f;
2852
- return {
2853
- api_key: this.credentials.API_KEY,
2854
- amount: Math.floor(checkout.totalPrice * 100),
2855
- card_id: card.cardId,
2856
- payment_method: 'credit_card',
2857
- installments: card.installments,
2858
- soft_descriptor: checkout.shop,
2859
- customer: {
2860
- external_id: checkout.user.id,
2861
- name: checkout.user.displayName,
2862
- type: 'individual',
2863
- country: 'br',
2864
- email: checkout.user.email,
2865
- phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
2866
- documents: [
2867
- {
2868
- type: 'cpf',
2869
- number: checkout.user.cpf,
2870
- },
2871
- ],
2872
- },
2873
- billing: {
2874
- name: checkout.user.displayName,
2875
- address: {
2876
- country: 'br',
2877
- state: checkout.billingAddress ? checkout.billingAddress.state : (_a = checkout.shippingAddress) === null || _a === void 0 ? void 0 : _a.state,
2878
- city: checkout.billingAddress ? checkout.billingAddress.city : (_b = checkout.shippingAddress) === null || _b === void 0 ? void 0 : _b.city,
2879
- neighborhood: checkout.billingAddress ? checkout.billingAddress.district : (_c = checkout.shippingAddress) === null || _c === void 0 ? void 0 : _c.district,
2880
- street: checkout.billingAddress ? checkout.billingAddress.street : (_d = checkout.shippingAddress) === null || _d === void 0 ? void 0 : _d.street,
2881
- street_number: checkout.billingAddress ? checkout.billingAddress.number : (_e = checkout.shippingAddress) === null || _e === void 0 ? void 0 : _e.number,
2882
- zipcode: checkout.billingAddress
2883
- ? checkout.billingAddress.zip.replace('-', '')
2884
- : (_f = checkout.shippingAddress) === null || _f === void 0 ? void 0 : _f.zip.replace('-', ''),
2885
- },
2886
- },
2887
- items: checkout.lineItems.map((item) => {
2888
- return {
2889
- id: item.id,
2890
- title: checkout.user.isSubscriber ? `${item.name} - ASSINANTE` : item.name,
2891
- unit_price: Math.floor(item.pricePaid * 100),
2892
- quantity: item.quantity,
2893
- tangible: true,
2894
- };
2895
- }),
2896
- };
2897
- }
2898
- }
2899
-
2900
- class PagarmePixService {
2901
- constructor(credentials, paymentRepository) {
2902
- this.credentials = credentials;
2903
- this.paymentRepository = paymentRepository;
2904
- }
2905
- async pay(checkout) {
2906
- var _a;
2907
- try {
2908
- const result = await axios({
2909
- method: 'POST',
2910
- url: this.credentials.URL_TRANSACTION,
2911
- data: this.createPixPayment(checkout),
2912
- });
2913
- const payment = await this.paymentRepository.create(Payment.toInstance({
2914
- createdAt: new Date(),
2915
- updatedAt: new Date(),
2916
- userId: checkout.user.id,
2917
- checkoutId: checkout.id,
2918
- totalPrice: checkout.totalPrice,
2919
- paymentProvider: 'pagarMe',
2920
- transaction: result.data,
2921
- }));
2922
- return payment;
2923
- }
2924
- catch (error) {
2925
- throw new PaymentError('Houve uma falha ao processar pagamento com pix', {
2926
- checkoutId: checkout.id,
2927
- userEmail: checkout.user.email,
2928
- info: (_a = error.response) === null || _a === void 0 ? void 0 : _a.data,
2929
- });
2930
- }
2931
- }
2932
- createPixPayment(checkout) {
2933
- return {
2934
- payment_method: 'pix',
2935
- amount: Math.floor(checkout.totalPrice * 100),
2936
- api_key: this.credentials.API_KEY,
2937
- postback_url: this.credentials.URL_POSTBACK,
2938
- pix_expiration_date: format(addDays(new Date(), 1), 'yyyy-MM-dd'),
2939
- customer: {
2940
- external_id: checkout.user.id,
2941
- type: 'individual',
2942
- country: 'br',
2943
- name: checkout.user.displayName,
2944
- email: checkout.user.email.trim(),
2945
- phone_numbers: checkout.user.phone ? ['+55' + checkout.user.phone] : '',
2946
- documents: [
2947
- {
2948
- type: 'cpf',
2949
- number: checkout.user.cpf,
2950
- },
2951
- ],
2952
- },
2953
- };
2954
- }
2955
- }
2956
-
2957
2304
  class RoundProductPricesHelper {
2958
2305
  static roundProductPrices(product) {
2959
2306
  product.price.price = Number(product.price.price.toFixed(2));
@@ -2968,12 +2315,6 @@ class RoundProductPricesHelper {
2968
2315
  }
2969
2316
  }
2970
2317
 
2971
- class Sequence extends BaseModel {
2972
- static get identifiersFields() {
2973
- return ['id'];
2974
- }
2975
- }
2976
-
2977
2318
  var FilterType;
2978
2319
  (function (FilterType) {
2979
2320
  FilterType["ACCESSORY_IMPORTANCE"] = "accessoryImportance";
@@ -3112,17 +2453,43 @@ class ShopSettings extends BaseModel {
3112
2453
  }
3113
2454
  }
3114
2455
 
3115
- class AxiosAdapter {
3116
- constructor(config) {
3117
- this.config = config;
3118
- this.logger = DebugHelper.from(this);
2456
+ class InvalidArgumentError extends CustomError {
2457
+ constructor(message) {
2458
+ super(message);
3119
2459
  }
3120
- async get(index, id) {
3121
- const logger = this.logger.with('get');
3122
- const req = {
3123
- url: `${this.config.url}/${index}/_doc/${id}`,
3124
- method: 'GET',
3125
- responseType: 'json',
2460
+ }
2461
+
2462
+ class RequiredArgumentError extends CustomError {
2463
+ constructor(args) {
2464
+ super(`Required arguments: ${args.join(', ')}`);
2465
+ this.args = args;
2466
+ this.arguments = args;
2467
+ }
2468
+ }
2469
+
2470
+ class NotFoundError extends CustomError {
2471
+ constructor(message) {
2472
+ super(message);
2473
+ }
2474
+ }
2475
+
2476
+ class DuplicatedResultsError extends CustomError {
2477
+ constructor(message) {
2478
+ super(message);
2479
+ }
2480
+ }
2481
+
2482
+ class AxiosAdapter {
2483
+ constructor(config) {
2484
+ this.config = config;
2485
+ this.logger = DebugHelper.from(this);
2486
+ }
2487
+ async get(index, id) {
2488
+ const logger = this.logger.with('get');
2489
+ const req = {
2490
+ url: `${this.config.url}/${index}/_doc/${id}`,
2491
+ method: 'GET',
2492
+ responseType: 'json',
3126
2493
  headers: {
3127
2494
  'Content-Type': 'application/json',
3128
2495
  Authorization: `ApiKey ${this.config.credential}`,
@@ -3804,6 +3171,180 @@ const withCrudFirestore = (MixinBase) => {
3804
3171
  };
3805
3172
  };
3806
3173
 
3174
+ class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3175
+ constructor({ firestore, interceptors }) {
3176
+ super({
3177
+ firestore,
3178
+ collectionName: 'leads',
3179
+ model: Lead,
3180
+ interceptors,
3181
+ });
3182
+ }
3183
+ }
3184
+
3185
+ class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3186
+ constructor({ firestore, interceptors }, parentRepository) {
3187
+ super({
3188
+ firestore,
3189
+ collectionName: 'editions',
3190
+ parentIdField: 'subscriptionId',
3191
+ model: Edition,
3192
+ interceptors,
3193
+ });
3194
+ this.parentRepository = parentRepository;
3195
+ }
3196
+ }
3197
+
3198
+ class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3199
+ constructor({ firestore, interceptors, }) {
3200
+ super({
3201
+ firestore,
3202
+ collectionName: 'subscription',
3203
+ model: Subscription,
3204
+ interceptors,
3205
+ });
3206
+ }
3207
+ }
3208
+
3209
+ class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3210
+ constructor({ firestore, interceptors }) {
3211
+ super({
3212
+ firestore,
3213
+ collectionName: 'subscriptionMaterialization',
3214
+ model: SubscriptionMaterialization,
3215
+ interceptors,
3216
+ });
3217
+ }
3218
+ }
3219
+
3220
+ class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3221
+ constructor({ firestore, interceptors }, parentRepository) {
3222
+ super({
3223
+ firestore,
3224
+ collectionName: 'payments',
3225
+ parentIdField: 'subscriptionId',
3226
+ model: SubscriptionPayment,
3227
+ interceptors,
3228
+ });
3229
+ this.parentRepository = parentRepository;
3230
+ }
3231
+ }
3232
+
3233
+ class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3234
+ constructor({ firestore, interceptors, }) {
3235
+ super({
3236
+ firestore,
3237
+ collectionName: 'subscriptionSummary',
3238
+ model: SubscriptionSummary,
3239
+ interceptors,
3240
+ });
3241
+ }
3242
+ }
3243
+
3244
+ class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3245
+ constructor({ firestore, interceptors }, parentRepository) {
3246
+ super({
3247
+ firestore,
3248
+ collectionName: 'address',
3249
+ parentIdField: 'userId',
3250
+ model: UserAddress,
3251
+ interceptors,
3252
+ });
3253
+ this.parentRepository = parentRepository;
3254
+ }
3255
+ }
3256
+
3257
+ class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3258
+ constructor({ firestore, interceptors }, parentRepository) {
3259
+ super({
3260
+ firestore,
3261
+ collectionName: 'CX',
3262
+ parentIdField: 'userId',
3263
+ model: BeautyProfile,
3264
+ interceptors,
3265
+ });
3266
+ this.parentRepository = parentRepository;
3267
+ }
3268
+ }
3269
+
3270
+ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3271
+ constructor({ firestore, interceptors }) {
3272
+ super({
3273
+ firestore,
3274
+ collectionName: 'users',
3275
+ model: User,
3276
+ interceptors,
3277
+ });
3278
+ }
3279
+ async get(identifiers) {
3280
+ const user = await super.get({ id: identifiers.id });
3281
+ user.beautyProfile = await this.getBeautyProfile(user.id);
3282
+ user.isSubscriber = await this.checkIfIsSubscriber(user.id);
3283
+ return user;
3284
+ }
3285
+ async checkIfExistsByField(field, value) {
3286
+ const result = await this.find({ filters: { [field]: value } });
3287
+ return result.count > 0;
3288
+ }
3289
+ buildModelInstance() {
3290
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
3291
+ return {
3292
+ toFirestore: (data) => {
3293
+ const plain = toFirestore(data);
3294
+ delete plain.isSubscriber;
3295
+ return plain;
3296
+ },
3297
+ fromFirestore,
3298
+ };
3299
+ }
3300
+ async getBeautyProfile(userId) {
3301
+ const beautyProfile = await this.firestore
3302
+ .getCollection(`${this.collectionName}/${userId}/CX`)
3303
+ .withConverter(this.buildBeautyProfileModelInstance())
3304
+ .getDoc('beautyProfile')
3305
+ .get();
3306
+ return beautyProfile.data();
3307
+ }
3308
+ async checkIfIsSubscriber(userId) {
3309
+ const docs = await this.collection('subscription')
3310
+ .where('user.id', '==', userId)
3311
+ .where('status', '==', 'active')
3312
+ .getDocs();
3313
+ return !!docs && !!docs.size;
3314
+ }
3315
+ buildBeautyProfileModelInstance() {
3316
+ return {
3317
+ toFirestore: (data) => data.toPlain(),
3318
+ fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
3319
+ };
3320
+ }
3321
+ }
3322
+ __decorate([
3323
+ Log(),
3324
+ __metadata("design:type", Function),
3325
+ __metadata("design:paramtypes", [Object]),
3326
+ __metadata("design:returntype", Promise)
3327
+ ], UserFirestoreRepository.prototype, "get", null);
3328
+ __decorate([
3329
+ Log(),
3330
+ __metadata("design:type", Function),
3331
+ __metadata("design:paramtypes", [String, String]),
3332
+ __metadata("design:returntype", Promise)
3333
+ ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
3334
+
3335
+ class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3336
+ constructor({ firestore, interceptors }, parentRepository) {
3337
+ super({
3338
+ firestore,
3339
+ collectionName: 'payment_method',
3340
+ parentIdField: 'userId',
3341
+ model: UserPaymentMethod,
3342
+ interceptors,
3343
+ });
3344
+ this.parentRepository = parentRepository;
3345
+ }
3346
+ }
3347
+
3807
3348
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3808
3349
  constructor({ firestore, interceptors }) {
3809
3350
  super({
@@ -3988,131 +3529,36 @@ class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpe
3988
3529
  }
3989
3530
  }
3990
3531
 
3991
- class SequenceFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3532
+ class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3992
3533
  constructor({ firestore, interceptors }) {
3993
3534
  super({
3994
3535
  firestore,
3995
- collectionName: 'sequences',
3996
- model: Sequence,
3536
+ collectionName: 'buy2win',
3537
+ model: Buy2Win,
3997
3538
  interceptors,
3998
3539
  });
3999
3540
  }
4000
3541
  }
4001
3542
 
4002
- class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4003
- constructor({ firestore, interceptors }) {
3543
+ class CampaignDashboardFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3544
+ constructor({ firestore, interceptors, }) {
4004
3545
  super({
4005
3546
  firestore,
4006
- collectionName: 'dms',
4007
- model: Home,
3547
+ collectionName: 'dashboardCampaignsAuto',
3548
+ model: CampaignDashboard,
4008
3549
  interceptors,
4009
3550
  });
4010
- this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
4011
- var _a, _b, _c;
4012
- return ({
4013
- category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
4014
- ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
4015
- : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
4016
- 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)) || [],
4017
- });
4018
- };
4019
- this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
4020
- var _a;
4021
- return ({
4022
- category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
4023
- products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
4024
- });
4025
- };
4026
3551
  }
4027
- buildModelInstance() {
4028
- const { fromFirestore, toFirestore } = super.buildModelInstance();
4029
- return {
4030
- toFirestore: (data) => {
4031
- const modifiedData = this.homeToFirestore(data);
4032
- return toFirestore(modifiedData);
4033
- },
4034
- fromFirestore: (snap) => {
4035
- const instance = fromFirestore(snap);
4036
- return this.homeFromFirestore(instance);
4037
- },
4038
- };
4039
- }
4040
- homeToFirestore(home) {
4041
- var _a, _b, _c, _d;
4042
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
4043
- home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
4044
- home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
4045
- home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
4046
- }
4047
- return home;
4048
- }
4049
- homeFromFirestore(home) {
4050
- var _a;
4051
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
4052
- home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
4053
- home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
4054
- home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
4055
- home.data.createdAt =
4056
- home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
4057
- home.data.expiresAt =
4058
- home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
4059
- }
4060
- return home;
4061
- }
4062
- }
4063
-
4064
- class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4065
- constructor({ firestore, interceptors }) {
4066
- super({
4067
- firestore,
4068
- collectionName: 'shopMenus',
4069
- model: ShopMenu,
4070
- interceptors,
4071
- });
4072
- }
4073
- }
4074
-
4075
- class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4076
- constructor({ firestore, interceptors, }) {
4077
- super({
4078
- firestore,
4079
- collectionName: 'shopSettings',
4080
- model: ShopSettings,
4081
- interceptors,
4082
- });
4083
- }
4084
- }
4085
-
4086
- class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4087
- constructor({ firestore, interceptors }) {
4088
- super({
4089
- firestore,
4090
- collectionName: 'buy2win',
4091
- model: Buy2Win,
4092
- interceptors,
4093
- });
4094
- }
4095
- }
4096
-
4097
- class CampaignDashboardFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4098
- constructor({ firestore, interceptors, }) {
4099
- super({
4100
- firestore,
4101
- collectionName: 'dashboardCampaignsAuto',
4102
- model: CampaignDashboard,
4103
- interceptors,
4104
- });
4105
- }
4106
- }
4107
-
4108
- class CampaignHashtagFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4109
- constructor({ firestore, interceptors, }) {
4110
- super({
4111
- firestore,
4112
- collectionName: 'hashtagCampaignsAuto',
4113
- model: CampaignHashtag,
4114
- interceptors,
4115
- });
3552
+ }
3553
+
3554
+ class CampaignHashtagFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3555
+ constructor({ firestore, interceptors, }) {
3556
+ super({
3557
+ firestore,
3558
+ collectionName: 'hashtagCampaignsAuto',
3559
+ model: CampaignHashtag,
3560
+ interceptors,
3561
+ });
4116
3562
  }
4117
3563
  }
4118
3564
 
@@ -4213,47 +3659,6 @@ class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
4213
3659
  }
4214
3660
  }
4215
3661
 
4216
- class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4217
- constructor({ firestore, interceptors, }) {
4218
- super({
4219
- firestore,
4220
- collectionName: 'paymentBlockedAttempts',
4221
- model: OrderBlocked,
4222
- interceptors,
4223
- });
4224
- }
4225
- async createBlockedOrderOrPayment(checkout, blockType, type, limiteRange, card = null) {
4226
- var _a, _b, _c, _d, _e, _f, _g, _h;
4227
- return this.create(OrderBlocked.toInstance({
4228
- customer: {
4229
- name: ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.displayName) || '',
4230
- cpf: ((_b = checkout.user) === null || _b === void 0 ? void 0 : _b.cpf) || '',
4231
- id: (_c = checkout.user) === null || _c === void 0 ? void 0 : _c.id,
4232
- email: ((_d = checkout.user) === null || _d === void 0 ? void 0 : _d.email) || '',
4233
- phoneNumber: '+55' + ((_e = checkout.user) === null || _e === void 0 ? void 0 : _e.phone),
4234
- isSubscriber: (_f = checkout.user) === null || _f === void 0 ? void 0 : _f.isSubscriber,
4235
- subscriptionPlan: ((_g = checkout.user) === null || _g === void 0 ? void 0 : _g.subscriptionPlan) || '',
4236
- shippingAddress: Object.assign(Object.assign({}, checkout.shippingAddress), { zip: this.formatZip((_h = checkout.shippingAddress) === null || _h === void 0 ? void 0 : _h.zip) }),
4237
- },
4238
- blockType,
4239
- limiteRange,
4240
- type,
4241
- card,
4242
- checkout: {
4243
- id: checkout.id,
4244
- shop: checkout.shop,
4245
- total: checkout.totalPrice,
4246
- },
4247
- date: new Date(),
4248
- }));
4249
- }
4250
- formatZip(zip) {
4251
- if (zip.length === 8)
4252
- return zip.substring(0, 5) + '-' + zip.substring(5, 8);
4253
- return zip;
4254
- }
4255
- }
4256
-
4257
3662
  class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4258
3663
  constructor({ firestore, interceptors }) {
4259
3664
  super({
@@ -4276,177 +3681,87 @@ class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(
4276
3681
  }
4277
3682
  }
4278
3683
 
4279
- class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3684
+ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4280
3685
  constructor({ firestore, interceptors }) {
4281
3686
  super({
4282
3687
  firestore,
4283
- collectionName: 'leads',
4284
- model: Lead,
3688
+ collectionName: 'dms',
3689
+ model: Home,
4285
3690
  interceptors,
4286
3691
  });
3692
+ this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
3693
+ var _a, _b, _c;
3694
+ return ({
3695
+ category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
3696
+ ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
3697
+ : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
3698
+ 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)) || [],
3699
+ });
3700
+ };
3701
+ this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
3702
+ var _a;
3703
+ return ({
3704
+ category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
3705
+ products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
3706
+ });
3707
+ };
4287
3708
  }
4288
- }
4289
-
4290
- class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4291
- constructor({ firestore, interceptors }, parentRepository) {
4292
- super({
4293
- firestore,
4294
- collectionName: 'editions',
4295
- parentIdField: 'subscriptionId',
4296
- model: Edition,
4297
- interceptors,
4298
- });
4299
- this.parentRepository = parentRepository;
3709
+ buildModelInstance() {
3710
+ const { fromFirestore, toFirestore } = super.buildModelInstance();
3711
+ return {
3712
+ toFirestore: (data) => {
3713
+ const modifiedData = this.homeToFirestore(data);
3714
+ return toFirestore(modifiedData);
3715
+ },
3716
+ fromFirestore: (snap) => {
3717
+ const instance = fromFirestore(snap);
3718
+ return this.homeFromFirestore(instance);
3719
+ },
3720
+ };
4300
3721
  }
4301
- }
4302
-
4303
- class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4304
- constructor({ firestore, interceptors, }) {
4305
- super({
4306
- firestore,
4307
- collectionName: 'subscription',
4308
- model: Subscription,
4309
- interceptors,
4310
- });
3722
+ homeToFirestore(home) {
3723
+ var _a, _b, _c, _d;
3724
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3725
+ home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
3726
+ home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
3727
+ home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
3728
+ }
3729
+ return home;
4311
3730
  }
4312
- }
4313
-
4314
- class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4315
- constructor({ firestore, interceptors }) {
4316
- super({
4317
- firestore,
4318
- collectionName: 'subscriptionMaterialization',
4319
- model: SubscriptionMaterialization,
4320
- interceptors,
4321
- });
3731
+ homeFromFirestore(home) {
3732
+ var _a;
3733
+ if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3734
+ home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
3735
+ home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
3736
+ home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
3737
+ home.data.createdAt =
3738
+ home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
3739
+ home.data.expiresAt =
3740
+ home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
3741
+ }
3742
+ return home;
4322
3743
  }
4323
3744
  }
4324
3745
 
4325
- class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4326
- constructor({ firestore, interceptors }, parentRepository) {
3746
+ class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3747
+ constructor({ firestore, interceptors }) {
4327
3748
  super({
4328
3749
  firestore,
4329
- collectionName: 'payments',
4330
- parentIdField: 'subscriptionId',
4331
- model: SubscriptionPayment,
3750
+ collectionName: 'shopMenus',
3751
+ model: ShopMenu,
4332
3752
  interceptors,
4333
3753
  });
4334
- this.parentRepository = parentRepository;
4335
3754
  }
4336
3755
  }
4337
3756
 
4338
- class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3757
+ class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4339
3758
  constructor({ firestore, interceptors, }) {
4340
3759
  super({
4341
3760
  firestore,
4342
- collectionName: 'subscriptionSummary',
4343
- model: SubscriptionSummary,
4344
- interceptors,
4345
- });
4346
- }
4347
- }
4348
-
4349
- class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4350
- constructor({ firestore, interceptors }, parentRepository) {
4351
- super({
4352
- firestore,
4353
- collectionName: 'address',
4354
- parentIdField: 'userId',
4355
- model: UserAddress,
4356
- interceptors,
4357
- });
4358
- this.parentRepository = parentRepository;
4359
- }
4360
- }
4361
-
4362
- class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4363
- constructor({ firestore, interceptors }, parentRepository) {
4364
- super({
4365
- firestore,
4366
- collectionName: 'CX',
4367
- parentIdField: 'userId',
4368
- model: BeautyProfile,
4369
- interceptors,
4370
- });
4371
- this.parentRepository = parentRepository;
4372
- }
4373
- }
4374
-
4375
- class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4376
- constructor({ firestore, interceptors }) {
4377
- super({
4378
- firestore,
4379
- collectionName: 'users',
4380
- model: User,
4381
- interceptors,
4382
- });
4383
- }
4384
- async get(identifiers) {
4385
- const user = await super.get({ id: identifiers.id });
4386
- user.beautyProfile = await this.getBeautyProfile(user.id);
4387
- user.isSubscriber = await this.checkIfIsSubscriber(user.id);
4388
- return user;
4389
- }
4390
- async checkIfExistsByField(field, value) {
4391
- const result = await this.find({ filters: { [field]: value } });
4392
- return result.count > 0;
4393
- }
4394
- buildModelInstance() {
4395
- const { fromFirestore, toFirestore } = super.buildModelInstance();
4396
- return {
4397
- toFirestore: (data) => {
4398
- const plain = toFirestore(data);
4399
- delete plain.isSubscriber;
4400
- return plain;
4401
- },
4402
- fromFirestore,
4403
- };
4404
- }
4405
- async getBeautyProfile(userId) {
4406
- const beautyProfile = await this.firestore
4407
- .getCollection(`${this.collectionName}/${userId}/CX`)
4408
- .withConverter(this.buildBeautyProfileModelInstance())
4409
- .getDoc('beautyProfile')
4410
- .get();
4411
- return beautyProfile.data();
4412
- }
4413
- async checkIfIsSubscriber(userId) {
4414
- const docs = await this.collection('subscription')
4415
- .where('user.id', '==', userId)
4416
- .where('status', '==', 'active')
4417
- .getDocs();
4418
- return !!docs && !!docs.size;
4419
- }
4420
- buildBeautyProfileModelInstance() {
4421
- return {
4422
- toFirestore: (data) => data.toPlain(),
4423
- fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
4424
- };
4425
- }
4426
- }
4427
- __decorate([
4428
- Log(),
4429
- __metadata("design:type", Function),
4430
- __metadata("design:paramtypes", [Object]),
4431
- __metadata("design:returntype", Promise)
4432
- ], UserFirestoreRepository.prototype, "get", null);
4433
- __decorate([
4434
- Log(),
4435
- __metadata("design:type", Function),
4436
- __metadata("design:paramtypes", [String, String]),
4437
- __metadata("design:returntype", Promise)
4438
- ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
4439
-
4440
- class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4441
- constructor({ firestore, interceptors }, parentRepository) {
4442
- super({
4443
- firestore,
4444
- collectionName: 'payment_method',
4445
- parentIdField: 'userId',
4446
- model: UserPaymentMethod,
3761
+ collectionName: 'shopSettings',
3762
+ model: ShopSettings,
4447
3763
  interceptors,
4448
3764
  });
4449
- this.parentRepository = parentRepository;
4450
3765
  }
4451
3766
  }
4452
3767
 
@@ -6941,4 +6256,4 @@ __decorate([
6941
6256
  __metadata("design:returntype", Promise)
6942
6257
  ], WishlistHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
6943
6258
 
6944
- export { AccessoryImportances, Address, AdyenCardService, AdyenPaymentMethodFactory, AntifraudBankSlipService, AntifraudCardService, AntifraudGlampointsService, AntifraudPixService, AntifraudProviderFactory, 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, PaymentProviderFactory, PaymentTransaction, PaymentType, 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, antifraudProviders, is, isDebuggable, isUUID, parseDateTime, paymentMethods, paymentProviders, withCreateFirestore, withCreateHasuraGraphQL, withCrudFirestore, withCrudHasuraGraphQL, withDeleteFirestore, withDeleteHasuraGraphQL, withFindFirestore, withFindHasuraGraphQL, withFirestore, withGetFirestore, withGetHasuraGraphQL, withHasuraGraphQL, withHelpers, withSubCollection, withUpdateFirestore, withUpdateHasuraGraphQL };
6259
+ 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, OrderFirestoreRepository, OrderStatus, Payment, PaymentFirestoreRepository, PaymentType, 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 };