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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/index.cjs.js +1074 -317
  2. package/index.esm.js +1050 -323
  3. package/package.json +1 -1
  4. package/src/domain/catalog/models/index.d.ts +1 -0
  5. package/src/domain/catalog/models/product-stock-notification.d.ts +12 -0
  6. package/src/domain/catalog/repositories/index.d.ts +1 -0
  7. package/src/domain/catalog/repositories/product-stock-notification.repository.d.ts +5 -0
  8. package/src/domain/general/index.d.ts +2 -0
  9. package/src/domain/general/models/index.d.ts +1 -0
  10. package/src/domain/general/models/sequences.d.ts +9 -0
  11. package/src/domain/general/repositories/index.d.ts +1 -0
  12. package/src/domain/general/repositories/sequences.repository.d.ts +4 -0
  13. package/src/domain/shopping/enums/antifraud-providers.enum.d.ts +6 -0
  14. package/src/domain/shopping/enums/index.d.ts +3 -0
  15. package/src/domain/shopping/enums/payment-methods.enum.d.ts +6 -0
  16. package/src/domain/shopping/enums/payment-providers.enum.d.ts +5 -0
  17. package/src/domain/shopping/factories/adyen-payment-method.factory.d.ts +8 -0
  18. package/src/domain/shopping/factories/antifraud-provider.factory.d.ts +15 -0
  19. package/src/domain/shopping/factories/base-payment-method.factory.d.ts +7 -0
  20. package/src/domain/shopping/factories/glampoints-payment-method.factory.d.ts +8 -0
  21. package/src/domain/shopping/factories/index.d.ts +5 -0
  22. package/src/domain/shopping/factories/pagarme-payment-method.factory.d.ts +10 -0
  23. package/src/domain/shopping/factories/payment-provider.factory.d.ts +15 -0
  24. package/src/domain/shopping/index.d.ts +5 -0
  25. package/src/domain/shopping/interfaces/antifraud-method-factory.interface.d.ts +11 -0
  26. package/src/domain/shopping/interfaces/antifraud-provider.interface.d.ts +5 -0
  27. package/src/domain/shopping/interfaces/index.d.ts +7 -0
  28. package/src/domain/shopping/interfaces/payment-method-factory.interface.d.ts +14 -0
  29. package/src/domain/shopping/interfaces/payment-provider-bank-slip.interface.d.ts +5 -0
  30. package/src/domain/shopping/interfaces/payment-provider-card.interface.d.ts +7 -0
  31. package/src/domain/shopping/interfaces/payment-provider-glampoints.interface.d.ts +5 -0
  32. package/src/domain/shopping/interfaces/payment-provider-pix.interface.d.ts +5 -0
  33. package/src/domain/shopping/models/index.d.ts +2 -0
  34. package/src/domain/shopping/models/order-blocked.d.ts +26 -0
  35. package/src/domain/shopping/models/order.d.ts +2 -2
  36. package/src/domain/shopping/models/payment-transaction.d.ts +66 -0
  37. package/src/domain/shopping/models/payment.d.ts +10 -63
  38. package/src/domain/shopping/models/types/index.d.ts +4 -4
  39. package/src/domain/shopping/repositories/index.d.ts +1 -0
  40. package/src/domain/shopping/repositories/order-blocked.repository.d.ts +6 -0
  41. package/src/domain/shopping/services/adyen-card-payment.service.d.ts +13 -0
  42. package/src/domain/shopping/services/antifraud-bankslip.service.d.ts +9 -0
  43. package/src/domain/shopping/services/antifraud-card.service.d.ts +18 -0
  44. package/src/domain/shopping/services/antifraud-glampoints.service.d.ts +6 -0
  45. package/src/domain/shopping/services/antifraud-pix.service.d.ts +6 -0
  46. package/src/domain/shopping/services/glampoints-payment.service.d.ts +8 -0
  47. package/src/domain/shopping/services/index.d.ts +9 -0
  48. package/src/domain/shopping/services/pagarme-bank-slip-payment.service.d.ts +11 -0
  49. package/src/domain/shopping/services/pagarme-card-payment.service.d.ts +13 -0
  50. package/src/domain/shopping/services/pagarme-pix-payment.service.d.ts +11 -0
  51. package/src/domain/shopping/types/adyen-credentials.type.d.ts +6 -0
  52. package/src/domain/shopping/types/antifraud-provider.type.d.ts +2 -0
  53. package/src/domain/shopping/types/index.d.ts +6 -0
  54. package/src/domain/shopping/types/pagarme-credentials.type.d.ts +5 -0
  55. package/src/domain/shopping/types/payment-card-info.type.d.ts +4 -0
  56. package/src/domain/shopping/types/payment-method.type.d.ts +2 -0
  57. package/src/domain/shopping/types/payment-provider.type.d.ts +2 -0
  58. package/src/errors/business.error.d.ts +7 -0
  59. package/src/errors/fraud-validation.error.d.ts +7 -0
  60. package/src/errors/index.d.ts +7 -2
  61. package/src/errors/payment.error.d.ts +7 -0
  62. package/src/errors/stock-limit.error.d.ts +5 -0
  63. package/src/errors/stock-out.error.d.ts +5 -0
  64. package/src/errors/types/checkout-additional-data-erro.type.d.ts +5 -0
  65. package/src/errors/types/index.d.ts +1 -0
  66. package/src/infra/firebase/firestore/repositories/general/index.d.ts +1 -0
  67. package/src/infra/firebase/firestore/repositories/general/sequences-firestore.repository.d.ts +7 -0
  68. package/src/infra/firebase/firestore/repositories/index.d.ts +3 -2
  69. package/src/infra/firebase/firestore/repositories/shopping/index.d.ts +1 -0
  70. package/src/infra/firebase/firestore/repositories/shopping/order-blocked-firestore.repository.d.ts +9 -0
  71. package/src/infra/hasura-graphql/repositories/catalog/index.d.ts +1 -0
  72. package/src/infra/hasura-graphql/repositories/catalog/product-stock-notification-hasura-graphql.repository.d.ts +11 -0
  73. package/src/utils/index.d.ts +2 -2
package/index.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 } from 'date-fns';
6
- export { add, addBusinessDays, addDays, addMonths, addYears, endOfDay, format, formatISO9075, parseISO, startOfDay, sub } from 'date-fns';
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';
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,6 +14,65 @@ 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
+
17
76
  class BaseModel {
18
77
  get identifier() {
19
78
  const fields = this.constructor.identifiersFields.filter((field) => field !== 'identifier');
@@ -196,6 +255,12 @@ class ProductReviews extends BaseModel {
196
255
  }
197
256
  }
198
257
 
258
+ class ProductStockNotification extends BaseModel {
259
+ static get identifiersFields() {
260
+ return ['id'];
261
+ }
262
+ }
263
+
199
264
  class Variant extends BaseModel {
200
265
  static get identifiersFields() {
201
266
  return ['id', 'productId'];
@@ -490,175 +555,178 @@ var Status;
490
555
  Status["CANCELLED"] = "Cancelado";
491
556
  })(Status || (Status = {}));
492
557
 
493
- class Payment extends BaseModel {
494
- static get identifiersFields() {
495
- return ['id'];
496
- }
558
+ class PaymentTransaction extends BaseModel {
497
559
  }
498
560
  __decorate([
499
561
  Expose({ name: 'refuse_reason' }),
500
562
  __metadata("design:type", String)
501
- ], Payment.prototype, "refuseReason", void 0);
563
+ ], PaymentTransaction.prototype, "refuseReason", void 0);
502
564
  __decorate([
503
565
  Expose({ name: 'status_reason' }),
504
566
  __metadata("design:type", String)
505
- ], Payment.prototype, "statusReason", void 0);
567
+ ], PaymentTransaction.prototype, "statusReason", void 0);
506
568
  __decorate([
507
569
  Expose({ name: 'acquirer_response_code' }),
508
570
  __metadata("design:type", String)
509
- ], Payment.prototype, "acquirerResponseCode", void 0);
571
+ ], PaymentTransaction.prototype, "acquirerResponseCode", void 0);
510
572
  __decorate([
511
573
  Expose({ name: 'acquirer_name' }),
512
574
  __metadata("design:type", String)
513
- ], Payment.prototype, "acquirerName", void 0);
575
+ ], PaymentTransaction.prototype, "acquirerName", void 0);
514
576
  __decorate([
515
577
  Expose({ name: 'acquirer_id' }),
516
578
  __metadata("design:type", String)
517
- ], Payment.prototype, "acquirerId", void 0);
579
+ ], PaymentTransaction.prototype, "acquirerId", void 0);
518
580
  __decorate([
519
581
  Expose({ name: 'authorization_code' }),
520
582
  __metadata("design:type", String)
521
- ], Payment.prototype, "authorizationCode", void 0);
583
+ ], PaymentTransaction.prototype, "authorizationCode", void 0);
522
584
  __decorate([
523
585
  Expose({ name: 'soft_descriptor' }),
524
586
  __metadata("design:type", String)
525
- ], Payment.prototype, "softDescriptor", void 0);
587
+ ], PaymentTransaction.prototype, "softDescriptor", void 0);
526
588
  __decorate([
527
589
  Expose({ name: 'date_created' }),
528
590
  __metadata("design:type", String)
529
- ], Payment.prototype, "dateCreated", void 0);
591
+ ], PaymentTransaction.prototype, "dateCreated", void 0);
530
592
  __decorate([
531
593
  Expose({ name: 'date_updated' }),
532
594
  __metadata("design:type", String)
533
- ], Payment.prototype, "dateUpdated", void 0);
595
+ ], PaymentTransaction.prototype, "dateUpdated", void 0);
534
596
  __decorate([
535
597
  Expose({ name: 'authorized_amount' }),
536
598
  __metadata("design:type", Number)
537
- ], Payment.prototype, "authorizedAmount", void 0);
599
+ ], PaymentTransaction.prototype, "authorizedAmount", void 0);
538
600
  __decorate([
539
601
  Expose({ name: 'paid_amount' }),
540
602
  __metadata("design:type", Number)
541
- ], Payment.prototype, "paidAmount", void 0);
542
- __decorate([
543
- Expose({ name: 'paid_at' }),
544
- __metadata("design:type", String)
545
- ], Payment.prototype, "paidAt", void 0);
603
+ ], PaymentTransaction.prototype, "paidAmount", void 0);
546
604
  __decorate([
547
605
  Expose({ name: 'refunded_amount' }),
548
606
  __metadata("design:type", Number)
549
- ], Payment.prototype, "refundedAmount", void 0);
607
+ ], PaymentTransaction.prototype, "refundedAmount", void 0);
550
608
  __decorate([
551
609
  Expose({ name: 'card_holder_name' }),
552
610
  __metadata("design:type", String)
553
- ], Payment.prototype, "cardHolderName", void 0);
611
+ ], PaymentTransaction.prototype, "cardHolderName", void 0);
554
612
  __decorate([
555
613
  Expose({ name: 'card_last_digits' }),
556
614
  __metadata("design:type", String)
557
- ], Payment.prototype, "cardLastDigits", void 0);
615
+ ], PaymentTransaction.prototype, "cardLastDigits", void 0);
558
616
  __decorate([
559
617
  Expose({ name: 'card_first_digits' }),
560
618
  __metadata("design:type", String)
561
- ], Payment.prototype, "cardFirstDigits", void 0);
619
+ ], PaymentTransaction.prototype, "cardFirstDigits", void 0);
562
620
  __decorate([
563
621
  Expose({ name: 'card_brand' }),
564
622
  __metadata("design:type", String)
565
- ], Payment.prototype, "cardBrand", void 0);
623
+ ], PaymentTransaction.prototype, "cardBrand", void 0);
566
624
  __decorate([
567
625
  Expose({ name: 'card_pin_mode' }),
568
626
  __metadata("design:type", String)
569
- ], Payment.prototype, "cardPinMode", void 0);
627
+ ], PaymentTransaction.prototype, "cardPinMode", void 0);
570
628
  __decorate([
571
629
  Expose({ name: 'card_magstripe_fallback' }),
572
630
  __metadata("design:type", Boolean)
573
- ], Payment.prototype, "cardMagstripeFallback", void 0);
631
+ ], PaymentTransaction.prototype, "cardMagstripeFallback", void 0);
574
632
  __decorate([
575
633
  Expose({ name: 'cvm_pin' }),
576
634
  __metadata("design:type", Boolean)
577
- ], Payment.prototype, "cvmPin", void 0);
635
+ ], PaymentTransaction.prototype, "cvmPin", void 0);
578
636
  __decorate([
579
637
  Expose({ name: 'postback_url' }),
580
638
  __metadata("design:type", String)
581
- ], Payment.prototype, "postbackUrl", void 0);
639
+ ], PaymentTransaction.prototype, "postbackUrl", void 0);
582
640
  __decorate([
583
641
  Expose({ name: 'payment_method' }),
584
642
  __metadata("design:type", String)
585
- ], Payment.prototype, "paymentMethod", void 0);
643
+ ], PaymentTransaction.prototype, "paymentMethod", void 0);
586
644
  __decorate([
587
645
  Expose({ name: 'capture_method' }),
588
646
  __metadata("design:type", String)
589
- ], Payment.prototype, "captureMethod", void 0);
647
+ ], PaymentTransaction.prototype, "captureMethod", void 0);
590
648
  __decorate([
591
649
  Expose({ name: 'antifraud_score' }),
592
650
  __metadata("design:type", String)
593
- ], Payment.prototype, "antifraudScore", void 0);
651
+ ], PaymentTransaction.prototype, "antifraudScore", void 0);
594
652
  __decorate([
595
653
  Expose({ name: 'boleto_url' }),
596
654
  __metadata("design:type", String)
597
- ], Payment.prototype, "boletoUrl", void 0);
655
+ ], PaymentTransaction.prototype, "boletoUrl", void 0);
598
656
  __decorate([
599
657
  Expose({ name: 'boleto_barcode' }),
600
658
  __metadata("design:type", String)
601
- ], Payment.prototype, "boletoBarcode", void 0);
659
+ ], PaymentTransaction.prototype, "boletoBarcode", void 0);
602
660
  __decorate([
603
661
  Expose({ name: 'boleto_expiration_date' }),
604
662
  __metadata("design:type", String)
605
- ], Payment.prototype, "boletoExpirationDate", void 0);
663
+ ], PaymentTransaction.prototype, "boletoExpirationDate", void 0);
606
664
  __decorate([
607
665
  Expose({ name: 'subscription_id' }),
608
666
  __metadata("design:type", String)
609
- ], Payment.prototype, "subscriptionId", void 0);
667
+ ], PaymentTransaction.prototype, "subscriptionId", void 0);
610
668
  __decorate([
611
669
  Expose({ name: 'split_rules' }),
612
670
  __metadata("design:type", String)
613
- ], Payment.prototype, "splitRules", void 0);
671
+ ], PaymentTransaction.prototype, "splitRules", void 0);
614
672
  __decorate([
615
673
  Expose({ name: 'antifraud_metadata' }),
616
674
  __metadata("design:type", Object)
617
- ], Payment.prototype, "antifraudMetadata", void 0);
675
+ ], PaymentTransaction.prototype, "antifraudMetadata", void 0);
618
676
  __decorate([
619
677
  Expose({ name: 'reference_key' }),
620
678
  __metadata("design:type", String)
621
- ], Payment.prototype, "referenceKey", void 0);
679
+ ], PaymentTransaction.prototype, "referenceKey", void 0);
622
680
  __decorate([
623
681
  Expose({ name: 'local_transaction_id' }),
624
682
  __metadata("design:type", String)
625
- ], Payment.prototype, "localTransactionId", void 0);
683
+ ], PaymentTransaction.prototype, "localTransactionId", void 0);
626
684
  __decorate([
627
685
  Expose({ name: 'local_time' }),
628
686
  __metadata("design:type", String)
629
- ], Payment.prototype, "localTime", void 0);
687
+ ], PaymentTransaction.prototype, "localTime", void 0);
630
688
  __decorate([
631
689
  Expose({ name: 'fraud_covered' }),
632
690
  __metadata("design:type", Boolean)
633
- ], Payment.prototype, "fraudCovered", void 0);
691
+ ], PaymentTransaction.prototype, "fraudCovered", void 0);
634
692
  __decorate([
635
693
  Expose({ name: 'fraud_reimbursed' }),
636
694
  __metadata("design:type", String)
637
- ], Payment.prototype, "fraudReimbursed", void 0);
695
+ ], PaymentTransaction.prototype, "fraudReimbursed", void 0);
638
696
  __decorate([
639
697
  Expose({ name: 'order_id' }),
640
698
  __metadata("design:type", String)
641
- ], Payment.prototype, "orderId", void 0);
699
+ ], PaymentTransaction.prototype, "orderId", void 0);
642
700
  __decorate([
643
701
  Expose({ name: 'risk_level' }),
644
702
  __metadata("design:type", String)
645
- ], Payment.prototype, "riskLevel", void 0);
703
+ ], PaymentTransaction.prototype, "riskLevel", void 0);
646
704
  __decorate([
647
705
  Expose({ name: 'receipt_url' }),
648
706
  __metadata("design:type", String)
649
- ], Payment.prototype, "receiptUrl", void 0);
707
+ ], PaymentTransaction.prototype, "receiptUrl", void 0);
650
708
  __decorate([
651
709
  Expose({ name: 'private_label' }),
652
710
  __metadata("design:type", String)
653
- ], Payment.prototype, "privateLabel", void 0);
711
+ ], PaymentTransaction.prototype, "privateLabel", void 0);
654
712
  __decorate([
655
713
  Expose({ name: 'pix_qr_code' }),
656
714
  __metadata("design:type", String)
657
- ], Payment.prototype, "pixQrCode", void 0);
715
+ ], PaymentTransaction.prototype, "pixQrCode", void 0);
658
716
  __decorate([
659
717
  Expose({ name: 'pix_expiration_date' }),
660
718
  __metadata("design:type", String)
661
- ], Payment.prototype, "pixExpirationDate", void 0);
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);
662
730
 
663
731
  class SubscriptionPayment extends BaseModel {
664
732
  static get identifiersFields() {
@@ -2269,10 +2337,16 @@ var OrderStatus;
2269
2337
  class Order extends Checkout {
2270
2338
  }
2271
2339
  __decorate([
2272
- Type(() => Payment),
2273
- __metadata("design:type", Payment)
2340
+ Type(() => PaymentTransaction),
2341
+ __metadata("design:type", PaymentTransaction)
2274
2342
  ], Order.prototype, "payment", void 0);
2275
2343
 
2344
+ class OrderBlocked extends BaseModel {
2345
+ static get identifiersFields() {
2346
+ return ['id'];
2347
+ }
2348
+ }
2349
+
2276
2350
  class CheckoutSubscription extends BaseModel {
2277
2351
  static get identifiersFields() {
2278
2352
  return ['id'];
@@ -2295,6 +2369,591 @@ __decorate([
2295
2369
  __metadata("design:type", Coupon)
2296
2370
  ], CheckoutSubscription.prototype, "coupon", void 0);
2297
2371
 
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
+
2298
2957
  class RoundProductPricesHelper {
2299
2958
  static roundProductPrices(product) {
2300
2959
  product.price.price = Number(product.price.price.toFixed(2));
@@ -2309,6 +2968,12 @@ class RoundProductPricesHelper {
2309
2968
  }
2310
2969
  }
2311
2970
 
2971
+ class Sequence extends BaseModel {
2972
+ static get identifiersFields() {
2973
+ return ['id'];
2974
+ }
2975
+ }
2976
+
2312
2977
  var FilterType;
2313
2978
  (function (FilterType) {
2314
2979
  FilterType["ACCESSORY_IMPORTANCE"] = "accessoryImportance";
@@ -2447,36 +3112,10 @@ class ShopSettings extends BaseModel {
2447
3112
  }
2448
3113
  }
2449
3114
 
2450
- class InvalidArgumentError extends CustomError {
2451
- constructor(message) {
2452
- super(message);
2453
- }
2454
- }
2455
-
2456
- class RequiredArgumentError extends CustomError {
2457
- constructor(args) {
2458
- super(`Required arguments: ${args.join(', ')}`);
2459
- this.args = args;
2460
- this.arguments = args;
2461
- }
2462
- }
2463
-
2464
- class NotFoundError extends CustomError {
2465
- constructor(message) {
2466
- super(message);
2467
- }
2468
- }
2469
-
2470
- class DuplicatedResultsError extends CustomError {
2471
- constructor(message) {
2472
- super(message);
2473
- }
2474
- }
2475
-
2476
- class AxiosAdapter {
2477
- constructor(config) {
2478
- this.config = config;
2479
- this.logger = DebugHelper.from(this);
3115
+ class AxiosAdapter {
3116
+ constructor(config) {
3117
+ this.config = config;
3118
+ this.logger = DebugHelper.from(this);
2480
3119
  }
2481
3120
  async get(index, id) {
2482
3121
  const logger = this.logger.with('get');
@@ -3165,180 +3804,6 @@ const withCrudFirestore = (MixinBase) => {
3165
3804
  };
3166
3805
  };
3167
3806
 
3168
- class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3169
- constructor({ firestore, interceptors }) {
3170
- super({
3171
- firestore,
3172
- collectionName: 'leads',
3173
- model: Lead,
3174
- interceptors,
3175
- });
3176
- }
3177
- }
3178
-
3179
- class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3180
- constructor({ firestore, interceptors }, parentRepository) {
3181
- super({
3182
- firestore,
3183
- collectionName: 'editions',
3184
- parentIdField: 'subscriptionId',
3185
- model: Edition,
3186
- interceptors,
3187
- });
3188
- this.parentRepository = parentRepository;
3189
- }
3190
- }
3191
-
3192
- class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3193
- constructor({ firestore, interceptors, }) {
3194
- super({
3195
- firestore,
3196
- collectionName: 'subscription',
3197
- model: Subscription,
3198
- interceptors,
3199
- });
3200
- }
3201
- }
3202
-
3203
- class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3204
- constructor({ firestore, interceptors }) {
3205
- super({
3206
- firestore,
3207
- collectionName: 'subscriptionMaterialization',
3208
- model: SubscriptionMaterialization,
3209
- interceptors,
3210
- });
3211
- }
3212
- }
3213
-
3214
- class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3215
- constructor({ firestore, interceptors }, parentRepository) {
3216
- super({
3217
- firestore,
3218
- collectionName: 'payments',
3219
- parentIdField: 'subscriptionId',
3220
- model: SubscriptionPayment,
3221
- interceptors,
3222
- });
3223
- this.parentRepository = parentRepository;
3224
- }
3225
- }
3226
-
3227
- class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3228
- constructor({ firestore, interceptors, }) {
3229
- super({
3230
- firestore,
3231
- collectionName: 'subscriptionSummary',
3232
- model: SubscriptionSummary,
3233
- interceptors,
3234
- });
3235
- }
3236
- }
3237
-
3238
- class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3239
- constructor({ firestore, interceptors }, parentRepository) {
3240
- super({
3241
- firestore,
3242
- collectionName: 'address',
3243
- parentIdField: 'userId',
3244
- model: UserAddress,
3245
- interceptors,
3246
- });
3247
- this.parentRepository = parentRepository;
3248
- }
3249
- }
3250
-
3251
- class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3252
- constructor({ firestore, interceptors }, parentRepository) {
3253
- super({
3254
- firestore,
3255
- collectionName: 'CX',
3256
- parentIdField: 'userId',
3257
- model: BeautyProfile,
3258
- interceptors,
3259
- });
3260
- this.parentRepository = parentRepository;
3261
- }
3262
- }
3263
-
3264
- class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3265
- constructor({ firestore, interceptors }) {
3266
- super({
3267
- firestore,
3268
- collectionName: 'users',
3269
- model: User,
3270
- interceptors,
3271
- });
3272
- }
3273
- async get(identifiers) {
3274
- const user = await super.get({ id: identifiers.id });
3275
- user.beautyProfile = await this.getBeautyProfile(user.id);
3276
- user.isSubscriber = await this.checkIfIsSubscriber(user.id);
3277
- return user;
3278
- }
3279
- async checkIfExistsByField(field, value) {
3280
- const result = await this.find({ filters: { [field]: value } });
3281
- return result.count > 0;
3282
- }
3283
- buildModelInstance() {
3284
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3285
- return {
3286
- toFirestore: (data) => {
3287
- const plain = toFirestore(data);
3288
- delete plain.isSubscriber;
3289
- return plain;
3290
- },
3291
- fromFirestore,
3292
- };
3293
- }
3294
- async getBeautyProfile(userId) {
3295
- const beautyProfile = await this.firestore
3296
- .getCollection(`${this.collectionName}/${userId}/CX`)
3297
- .withConverter(this.buildBeautyProfileModelInstance())
3298
- .getDoc('beautyProfile')
3299
- .get();
3300
- return beautyProfile.data();
3301
- }
3302
- async checkIfIsSubscriber(userId) {
3303
- const docs = await this.collection('subscription')
3304
- .where('user.id', '==', userId)
3305
- .where('status', '==', 'active')
3306
- .getDocs();
3307
- return !!docs && !!docs.size;
3308
- }
3309
- buildBeautyProfileModelInstance() {
3310
- return {
3311
- toFirestore: (data) => data.toPlain(),
3312
- fromFirestore: (snap) => BeautyProfile.toInstance(snap.data()),
3313
- };
3314
- }
3315
- }
3316
- __decorate([
3317
- Log(),
3318
- __metadata("design:type", Function),
3319
- __metadata("design:paramtypes", [Object]),
3320
- __metadata("design:returntype", Promise)
3321
- ], UserFirestoreRepository.prototype, "get", null);
3322
- __decorate([
3323
- Log(),
3324
- __metadata("design:type", Function),
3325
- __metadata("design:paramtypes", [String, String]),
3326
- __metadata("design:returntype", Promise)
3327
- ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
3328
-
3329
- class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
3330
- constructor({ firestore, interceptors }, parentRepository) {
3331
- super({
3332
- firestore,
3333
- collectionName: 'payment_method',
3334
- parentIdField: 'userId',
3335
- model: UserPaymentMethod,
3336
- interceptors,
3337
- });
3338
- this.parentRepository = parentRepository;
3339
- }
3340
- }
3341
-
3342
3807
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3343
3808
  constructor({ firestore, interceptors }) {
3344
3809
  super({
@@ -3503,21 +3968,116 @@ class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirest
3503
3968
  constructor({ firestore, interceptors }, parentRepository) {
3504
3969
  super({
3505
3970
  firestore,
3506
- collectionName: 'variants',
3507
- parentIdField: 'productId',
3508
- model: Variant,
3971
+ collectionName: 'variants',
3972
+ parentIdField: 'productId',
3973
+ model: Variant,
3974
+ interceptors,
3975
+ });
3976
+ this.parentRepository = parentRepository;
3977
+ }
3978
+ }
3979
+
3980
+ class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3981
+ constructor({ firestore, interceptors }) {
3982
+ super({
3983
+ firestore,
3984
+ collectionName: 'subscriptionProducts',
3985
+ model: Product,
3986
+ interceptors,
3987
+ });
3988
+ }
3989
+ }
3990
+
3991
+ class SequenceFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3992
+ constructor({ firestore, interceptors }) {
3993
+ super({
3994
+ firestore,
3995
+ collectionName: 'sequences',
3996
+ model: Sequence,
3997
+ interceptors,
3998
+ });
3999
+ }
4000
+ }
4001
+
4002
+ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4003
+ constructor({ firestore, interceptors }) {
4004
+ super({
4005
+ firestore,
4006
+ collectionName: 'dms',
4007
+ model: Home,
4008
+ interceptors,
4009
+ });
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
+ }
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,
3509
4070
  interceptors,
3510
4071
  });
3511
- this.parentRepository = parentRepository;
3512
4072
  }
3513
4073
  }
3514
4074
 
3515
- class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3516
- constructor({ firestore, interceptors }) {
4075
+ class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4076
+ constructor({ firestore, interceptors, }) {
3517
4077
  super({
3518
4078
  firestore,
3519
- collectionName: 'subscriptionProducts',
3520
- model: Product,
4079
+ collectionName: 'shopSettings',
4080
+ model: ShopSettings,
3521
4081
  interceptors,
3522
4082
  });
3523
4083
  }
@@ -3653,6 +4213,47 @@ class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
3653
4213
  }
3654
4214
  }
3655
4215
 
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
+
3656
4257
  class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3657
4258
  constructor({ firestore, interceptors }) {
3658
4259
  super({
@@ -3675,87 +4276,177 @@ class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(
3675
4276
  }
3676
4277
  }
3677
4278
 
3678
- class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4279
+ class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3679
4280
  constructor({ firestore, interceptors }) {
3680
4281
  super({
3681
4282
  firestore,
3682
- collectionName: 'dms',
3683
- model: Home,
4283
+ collectionName: 'leads',
4284
+ model: Lead,
3684
4285
  interceptors,
3685
4286
  });
3686
- this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
3687
- var _a, _b, _c;
3688
- return ({
3689
- category: ((_a = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _a === void 0 ? void 0 : _a.toPlain)
3690
- ? (_b = homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category) === null || _b === void 0 ? void 0 : _b.toPlain()
3691
- : homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category,
3692
- 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)) || [],
3693
- });
3694
- };
3695
- this.plainToHomeCategoryGroup = (homeCategoryGroup) => {
3696
- var _a;
3697
- return ({
3698
- category: Category.toInstance(homeCategoryGroup === null || homeCategoryGroup === void 0 ? void 0 : homeCategoryGroup.category),
3699
- products: (_a = homeCategoryGroup.products) === null || _a === void 0 ? void 0 : _a.map((product) => Product.toInstance(product)),
3700
- });
3701
- };
3702
- }
3703
- buildModelInstance() {
3704
- const { fromFirestore, toFirestore } = super.buildModelInstance();
3705
- return {
3706
- toFirestore: (data) => {
3707
- const modifiedData = this.homeToFirestore(data);
3708
- return toFirestore(modifiedData);
3709
- },
3710
- fromFirestore: (snap) => {
3711
- const instance = fromFirestore(snap);
3712
- return this.homeFromFirestore(instance);
3713
- },
3714
- };
3715
4287
  }
3716
- homeToFirestore(home) {
3717
- var _a, _b, _c, _d;
3718
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3719
- home.data.data.discoverProducts = ((_b = home.data.data.discoverProducts) === null || _b === void 0 ? void 0 : _b.map(this.homeCategoryGroupToPlain)) || [];
3720
- home.data.data.featuredProducts = ((_c = home.data.data.featuredProducts) === null || _c === void 0 ? void 0 : _c.map(this.homeCategoryGroupToPlain)) || [];
3721
- home.data.data.verticalProducts = ((_d = home.data.data.verticalProducts) === null || _d === void 0 ? void 0 : _d.map(this.homeCategoryGroupToPlain)) || [];
3722
- }
3723
- return home;
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;
3724
4300
  }
3725
- homeFromFirestore(home) {
3726
- var _a;
3727
- if ((_a = home.data) === null || _a === void 0 ? void 0 : _a.data) {
3728
- home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.plainToHomeCategoryGroup);
3729
- home.data.data.featuredProducts = home.data.data.featuredProducts.map(this.plainToHomeCategoryGroup);
3730
- home.data.data.verticalProducts = home.data.data.verticalProducts.map(this.plainToHomeCategoryGroup);
3731
- home.data.createdAt =
3732
- home.data.createdAt instanceof Timestamp ? home.data.createdAt.toDate() : home.data.createdAt;
3733
- home.data.expiresAt =
3734
- home.data.expiresAt instanceof Timestamp ? home.data.expiresAt.toDate() : home.data.expiresAt;
3735
- }
3736
- return home;
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
+ });
3737
4311
  }
3738
4312
  }
3739
4313
 
3740
- class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4314
+ class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3741
4315
  constructor({ firestore, interceptors }) {
3742
4316
  super({
3743
4317
  firestore,
3744
- collectionName: 'shopMenus',
3745
- model: ShopMenu,
4318
+ collectionName: 'subscriptionMaterialization',
4319
+ model: SubscriptionMaterialization,
3746
4320
  interceptors,
3747
4321
  });
3748
4322
  }
3749
4323
  }
3750
4324
 
3751
- class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4325
+ class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4326
+ constructor({ firestore, interceptors }, parentRepository) {
4327
+ super({
4328
+ firestore,
4329
+ collectionName: 'payments',
4330
+ parentIdField: 'subscriptionId',
4331
+ model: SubscriptionPayment,
4332
+ interceptors,
4333
+ });
4334
+ this.parentRepository = parentRepository;
4335
+ }
4336
+ }
4337
+
4338
+ class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
3752
4339
  constructor({ firestore, interceptors, }) {
3753
4340
  super({
3754
4341
  firestore,
3755
- collectionName: 'shopSettings',
3756
- model: ShopSettings,
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,
3757
4447
  interceptors,
3758
4448
  });
4449
+ this.parentRepository = parentRepository;
3759
4450
  }
3760
4451
  }
3761
4452
 
@@ -5860,6 +6551,42 @@ __decorate([
5860
6551
  __metadata("design:returntype", void 0)
5861
6552
  ], ProductReviewsHasuraGraphQLRepository.prototype, "disaproveReview", null);
5862
6553
 
6554
+ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6555
+ constructor({ endpoint, authOptions, interceptors, }) {
6556
+ super({
6557
+ tableName: 'product_stock_notification',
6558
+ model: ProductStockNotification,
6559
+ endpoint,
6560
+ authOptions,
6561
+ interceptors,
6562
+ fields: [
6563
+ 'id',
6564
+ { productId: { columnName: 'product_id' } },
6565
+ 'name',
6566
+ 'email',
6567
+ 'shop',
6568
+ { createdAt: { columnName: 'created_at' } },
6569
+ { updatedAt: { columnName: 'updated_at' } },
6570
+ ],
6571
+ });
6572
+ }
6573
+ async addCustomerEmail(shop, productId, name, email) {
6574
+ const notification = await this.find({
6575
+ filters: {
6576
+ productId,
6577
+ email,
6578
+ },
6579
+ }).then((data) => data.data.shift());
6580
+ if (!notification)
6581
+ this.create({
6582
+ shop,
6583
+ productId,
6584
+ name,
6585
+ email,
6586
+ });
6587
+ }
6588
+ }
6589
+
5863
6590
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5864
6591
  constructor({ endpoint, authOptions, interceptors, }) {
5865
6592
  super({
@@ -6214,4 +6941,4 @@ __decorate([
6214
6941
  __metadata("design:returntype", Promise)
6215
6942
  ], WishlistHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
6216
6943
 
6217
- 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, 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 };
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 };