@infrab4a/connect 4.0.0-beta.10 → 4.0.0-beta.12

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 (76) hide show
  1. package/esm2020/infra/firebase/firestore/mixins/with-create-firestore.mixin.mjs +7 -3
  2. package/esm2020/infra/firebase/firestore/mixins/with-crud-firestore.mixin.mjs +1 -1
  3. package/esm2020/infra/firebase/firestore/mixins/with-delete-firestore.mixin.mjs +6 -2
  4. package/esm2020/infra/firebase/firestore/mixins/with-find-firestore.mixin.mjs +6 -4
  5. package/esm2020/infra/firebase/firestore/mixins/with-firestore.mixin.mjs +9 -3
  6. package/esm2020/infra/firebase/firestore/mixins/with-get-firestore.mixin.mjs +6 -3
  7. package/esm2020/infra/firebase/firestore/mixins/with-sub-collection.mixin.mjs +5 -3
  8. package/esm2020/infra/firebase/firestore/mixins/with-update-firestore.mixin.mjs +7 -4
  9. package/esm2020/infra/firebase/firestore/repositories/catalog/category-firestore.repository.mjs +8 -6
  10. package/esm2020/infra/firebase/firestore/repositories/catalog/product-firestore.repository.mjs +8 -6
  11. package/esm2020/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.mjs +10 -8
  12. package/esm2020/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.mjs +8 -6
  13. package/esm2020/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.mjs +8 -6
  14. package/esm2020/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.mjs +8 -6
  15. package/esm2020/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.mjs +8 -6
  16. package/esm2020/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.mjs +8 -6
  17. package/esm2020/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.mjs +8 -6
  18. package/esm2020/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.mjs +8 -6
  19. package/esm2020/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.mjs +6 -4
  20. package/esm2020/infra/firebase/firestore/repositories/shopping/order-firestore.repository.mjs +11 -9
  21. package/esm2020/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.mjs +8 -6
  22. package/esm2020/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.mjs +8 -6
  23. package/esm2020/infra/firebase/firestore/repositories/users/lead-firestore.repository.mjs +8 -6
  24. package/esm2020/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.mjs +10 -9
  25. package/esm2020/infra/firebase/firestore/repositories/users/subscription-firestore.repository.mjs +8 -6
  26. package/esm2020/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.mjs +10 -9
  27. package/esm2020/infra/firebase/firestore/repositories/users/user-address-firestore.repository.mjs +10 -9
  28. package/esm2020/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.mjs +10 -9
  29. package/esm2020/infra/firebase/firestore/repositories/users/user-firestore.repository.mjs +8 -6
  30. package/esm2020/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.mjs +10 -9
  31. package/esm2020/infra/firebase/firestore/types/firestore-interceptors.type.mjs +2 -0
  32. package/esm2020/infra/firebase/firestore/types/firestore.repository.type.mjs +1 -1
  33. package/esm2020/infra/firebase/firestore/types/index.mjs +4 -3
  34. package/esm2020/infra/hasura-graphql/mixins/with-crud-hasura-graphql.mixin.mjs +1 -1
  35. package/esm2020/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.mjs +1 -1
  36. package/esm2020/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.mjs +1 -1
  37. package/esm2020/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.mjs +1 -1
  38. package/esm2020/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.mjs +2 -2
  39. package/fesm2015/infrab4a-connect.mjs +206 -138
  40. package/fesm2015/infrab4a-connect.mjs.map +1 -1
  41. package/fesm2020/infrab4a-connect.mjs +201 -138
  42. package/fesm2020/infrab4a-connect.mjs.map +1 -1
  43. package/infra/firebase/firestore/mixins/with-crud-firestore.mixin.d.ts +2 -1
  44. package/infra/firebase/firestore/mixins/with-firestore.mixin.d.ts +13 -4
  45. package/infra/firebase/firestore/mixins/with-sub-collection.mixin.d.ts +6 -2
  46. package/infra/firebase/firestore/repositories/catalog/category-firestore.repository.d.ts +3 -4
  47. package/infra/firebase/firestore/repositories/catalog/product-firestore.repository.d.ts +3 -4
  48. package/infra/firebase/firestore/repositories/catalog/product-variant-firestore.repository.d.ts +3 -4
  49. package/infra/firebase/firestore/repositories/catalog/subscription-product-firestore.repository.d.ts +3 -4
  50. package/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.d.ts +4 -4
  51. package/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.d.ts +3 -4
  52. package/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.d.ts +3 -4
  53. package/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.d.ts +3 -4
  54. package/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.d.ts +3 -4
  55. package/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.d.ts +4 -4
  56. package/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.d.ts +3 -4
  57. package/infra/firebase/firestore/repositories/shopping/order-firestore.repository.d.ts +4 -4
  58. package/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.d.ts +3 -4
  59. package/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.d.ts +3 -4
  60. package/infra/firebase/firestore/repositories/users/lead-firestore.repository.d.ts +3 -4
  61. package/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.d.ts +3 -6
  62. package/infra/firebase/firestore/repositories/users/subscription-firestore.repository.d.ts +3 -4
  63. package/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.d.ts +3 -6
  64. package/infra/firebase/firestore/repositories/users/user-address-firestore.repository.d.ts +3 -6
  65. package/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.d.ts +3 -6
  66. package/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +4 -4
  67. package/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.d.ts +3 -6
  68. package/infra/firebase/firestore/types/firestore-interceptors.type.d.ts +14 -0
  69. package/infra/firebase/firestore/types/firestore.repository.type.d.ts +2 -0
  70. package/infra/firebase/firestore/types/index.d.ts +3 -2
  71. package/infra/hasura-graphql/mixins/with-crud-hasura-graphql.mixin.d.ts +2 -2
  72. package/infra/hasura-graphql/mixins/with-hasura-graphql.mixin.d.ts +2 -2
  73. package/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +3 -3
  74. package/infra/hasura-graphql/repositories/catalog/product-hasura-graphql.repository.d.ts +3 -3
  75. package/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +3 -3
  76. package/package.json +1 -1
@@ -1199,9 +1199,15 @@ const withFirestore = (MixinBase) => {
1199
1199
  }), {});
1200
1200
  };
1201
1201
  return class extends MixinBase {
1202
- constructor() {
1203
- super(...arguments);
1202
+ constructor(...params) {
1203
+ const options = params[0];
1204
+ super(...params);
1204
1205
  this.collectionName = '';
1206
+ this.firestore = options.firestore;
1207
+ this.collectionName = options.collectionName;
1208
+ this.model = options.model;
1209
+ this.fields = options.fields;
1210
+ this.interceptors = options.interceptors;
1205
1211
  }
1206
1212
  collection(path) {
1207
1213
  return collection(this.firestore, path || this.collectionName).withConverter(this.buildModelInstance());
@@ -1248,11 +1254,14 @@ const withHelpers = (MixinBase) => {
1248
1254
  const withGetFirestore = (MixinBase) => {
1249
1255
  return class GetFirestore extends MixinBase {
1250
1256
  async get(identifiers) {
1251
- const docRef = await getDoc(doc(await this.collection(this.buildCollectionPathForGet(identifiers)), Object.values(identifiers).shift().toString()));
1257
+ const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => ({ ...acc, [field]: identifiers[field] }), {}));
1258
+ const intercepted = await this.interceptors?.request?.({ instance });
1259
+ const builded = intercepted?.instance || instance;
1260
+ const docRef = await getDoc(doc(await this.collection(this.buildCollectionPathForGet(identifiers)), Object.values(builded.identifier).shift().toString()));
1252
1261
  const data = docRef.data();
1253
1262
  if (isNil(data))
1254
1263
  throw new NotFoundError(`Document ${JSON.stringify(identifiers)} not found`);
1255
- return data;
1264
+ return this.interceptors?.response?.(data, intercepted) || data;
1256
1265
  }
1257
1266
  buildCollectionPathForGet(identifiers) {
1258
1267
  return this.isSubCollection(this)
@@ -1333,8 +1342,10 @@ const withFindFirestore = (MixinBase) => {
1333
1342
  return Object.keys(fieldsToOrderBy).map((fieldName) => orderBy(fieldName, fieldsToOrderBy[fieldName]));
1334
1343
  };
1335
1344
  }
1336
- async find({ filters, limits, orderBy, } = {}) {
1337
- const collection = this.collection(this.buildCollectionPathForFind(filters));
1345
+ async find(find = {}) {
1346
+ const collection = this.collection(this.buildCollectionPathForFind(find.filters));
1347
+ const intercepted = await this.interceptors?.request?.({ find });
1348
+ const { filters, limits, orderBy } = intercepted.find || find;
1338
1349
  const queries = this.makeFirestoreWhere(filters || {});
1339
1350
  const ordination = this.makeFirestoreOrderBy(filters, orderBy);
1340
1351
  const offsets = await this.defineLimits(filters, limits);
@@ -1342,7 +1353,7 @@ const withFindFirestore = (MixinBase) => {
1342
1353
  const docs = await getDocs(query(collection, ...queryArgumments));
1343
1354
  const data = docs.docs.map((doc) => doc.data());
1344
1355
  return {
1345
- data,
1356
+ data: (await this.interceptors?.response?.(data, intercepted)) || data,
1346
1357
  count: this.calculateCount(data, limits),
1347
1358
  };
1348
1359
  }
@@ -1378,9 +1389,13 @@ const withFindFirestore = (MixinBase) => {
1378
1389
  const withCreateFirestore = (MixinBase) => {
1379
1390
  return class CreateFirestore extends MixinBase {
1380
1391
  async create(data) {
1381
- const docRef = await this.save(this.model.toInstance(data));
1392
+ const instance = this.model.toInstance(data);
1393
+ const intercepted = await this.interceptors?.request?.({ instance });
1394
+ const builded = intercepted?.instance || instance;
1395
+ const docRef = await this.save(builded);
1382
1396
  const doc = await getDoc(docRef);
1383
- return doc.data();
1397
+ const docBuilded = (await this.interceptors?.response?.(doc.data(), intercepted)) || doc.data();
1398
+ return docBuilded;
1384
1399
  }
1385
1400
  async save(data) {
1386
1401
  const id = data.identifier[data.identifiersFields?.shift()]?.toString();
@@ -1424,9 +1439,12 @@ const withUpdateFirestore = (MixinBase) => {
1424
1439
  const model = new this.model();
1425
1440
  const keyField = model.identifiersFields.shift();
1426
1441
  const docRef = doc(this.collection(this.buildCollectionPathForUpdate(data)), getValueFromParams(data, keyField).toString());
1427
- await setDoc(docRef, this.paramsToPlain(data), { merge: true });
1428
- const docData = await getDoc(docRef);
1429
- return docData.data();
1442
+ const plainFromData = this.model.toInstance(this.paramsToPlain(data));
1443
+ const intercepted = await this.interceptors?.request?.({ instance: plainFromData });
1444
+ const builded = intercepted?.instance || plainFromData;
1445
+ await setDoc(docRef, builded.toPlain(), { merge: true });
1446
+ const docData = await getDoc(docRef).then((doc) => doc.data());
1447
+ return this.interceptors?.response?.(docData, intercepted) || docData;
1430
1448
  }
1431
1449
  buildCollectionPathForUpdate(identifiers) {
1432
1450
  return this.isSubCollection(this)
@@ -1448,7 +1466,11 @@ const withUpdateFirestore = (MixinBase) => {
1448
1466
  const withDeleteFirestore = (MixinBase) => {
1449
1467
  return class DeleteFirestore extends MixinBase {
1450
1468
  async delete(identifiers) {
1451
- await deleteDoc(doc(this.collection(this.buildCollectionPathForRemove(identifiers)), Object.values(identifiers).shift().toString()));
1469
+ const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => ({ ...acc, [field]: identifiers[field] }), {}));
1470
+ const intercepted = await this.interceptors?.request?.({ instance });
1471
+ const builded = intercepted?.instance || instance;
1472
+ await deleteDoc(doc(this.collection(this.buildCollectionPathForRemove(identifiers)), Object.values(builded.identifier).shift().toString()));
1473
+ await this.interceptors?.response?.(instance, intercepted);
1452
1474
  }
1453
1475
  buildCollectionPathForRemove(identifiers) {
1454
1476
  return this.isSubCollection(this)
@@ -1460,8 +1482,10 @@ const withDeleteFirestore = (MixinBase) => {
1460
1482
 
1461
1483
  const withSubCollection = (MixinBase, ParentModel) => {
1462
1484
  return class SubCollectionMix extends MixinBase {
1463
- constructor(...args) {
1464
- super(args);
1485
+ constructor(...params) {
1486
+ const options = params[0];
1487
+ super(...params);
1488
+ this.parentIdField = options.parentIdField;
1465
1489
  }
1466
1490
  collection(path) {
1467
1491
  return super.collection(path);
@@ -1475,73 +1499,83 @@ const withCrudFirestore = (MixinBase) => {
1475
1499
  };
1476
1500
 
1477
1501
  class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1478
- constructor(firestore) {
1479
- super();
1480
- this.firestore = firestore;
1481
- this.collectionName = 'leads';
1482
- this.model = Lead;
1502
+ constructor({ firestore, interceptors }) {
1503
+ super({
1504
+ firestore,
1505
+ collectionName: 'leads',
1506
+ model: Lead,
1507
+ interceptors,
1508
+ });
1483
1509
  }
1484
1510
  }
1485
1511
 
1486
1512
  class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription) {
1487
- constructor(firestore, parentRepository) {
1488
- super();
1489
- this.firestore = firestore;
1490
- this.parentRepository = parentRepository;
1491
- this.collectionName = 'editions';
1492
- this.parentIdField = 'subscriptionId';
1493
- this.model = Edition;
1513
+ constructor({ firestore, interceptors }) {
1514
+ super({
1515
+ firestore,
1516
+ collectionName: 'editions',
1517
+ parentIdField: 'subscriptionId',
1518
+ model: Edition,
1519
+ interceptors,
1520
+ });
1494
1521
  }
1495
1522
  }
1496
1523
 
1497
1524
  class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1498
- constructor(firestore) {
1499
- super();
1500
- this.firestore = firestore;
1501
- this.collectionName = 'subscription';
1502
- this.model = Subscription;
1525
+ constructor({ firestore, interceptors, }) {
1526
+ super({
1527
+ firestore,
1528
+ collectionName: 'subscription',
1529
+ model: Subscription,
1530
+ interceptors,
1531
+ });
1503
1532
  }
1504
1533
  }
1505
1534
 
1506
1535
  class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Subscription) {
1507
- constructor(firestore, parentRepository) {
1508
- super();
1509
- this.firestore = firestore;
1510
- this.parentRepository = parentRepository;
1511
- this.collectionName = 'payments';
1512
- this.parentIdField = 'subscriptionId';
1513
- this.model = SubscriptionPayment;
1536
+ constructor({ firestore, interceptors, }) {
1537
+ super({
1538
+ firestore,
1539
+ collectionName: 'payments',
1540
+ parentIdField: 'subscriptionId',
1541
+ model: SubscriptionPayment,
1542
+ interceptors,
1543
+ });
1514
1544
  }
1515
1545
  }
1516
1546
 
1517
1547
  class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
1518
- constructor(firestore, parentRepository) {
1519
- super();
1520
- this.firestore = firestore;
1521
- this.parentRepository = parentRepository;
1522
- this.collectionName = 'address';
1523
- this.parentIdField = 'userId';
1524
- this.model = UserAddress;
1548
+ constructor({ firestore, interceptors, }) {
1549
+ super({
1550
+ firestore,
1551
+ collectionName: 'address',
1552
+ parentIdField: 'userId',
1553
+ model: UserAddress,
1554
+ interceptors,
1555
+ });
1525
1556
  }
1526
1557
  }
1527
1558
 
1528
1559
  class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
1529
- constructor(firestore, parentRepository) {
1530
- super();
1531
- this.firestore = firestore;
1532
- this.parentRepository = parentRepository;
1533
- this.collectionName = 'CX';
1534
- this.parentIdField = 'userId';
1535
- this.model = BeautyProfile;
1560
+ constructor({ firestore, interceptors, }) {
1561
+ super({
1562
+ firestore,
1563
+ collectionName: 'CX',
1564
+ parentIdField: 'userId',
1565
+ model: BeautyProfile,
1566
+ interceptors,
1567
+ });
1536
1568
  }
1537
1569
  }
1538
1570
 
1539
1571
  class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1540
- constructor(firestore) {
1541
- super();
1542
- this.firestore = firestore;
1543
- this.collectionName = 'users';
1544
- this.model = User;
1572
+ constructor({ firestore, interceptors }) {
1573
+ super({
1574
+ firestore,
1575
+ collectionName: 'users',
1576
+ model: User,
1577
+ interceptors,
1578
+ });
1545
1579
  }
1546
1580
  async get(identifiers) {
1547
1581
  const user = await super.get({ id: identifiers.id });
@@ -1581,22 +1615,25 @@ class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
1581
1615
  }
1582
1616
 
1583
1617
  class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), User) {
1584
- constructor(firestore, parentRepository) {
1585
- super();
1586
- this.firestore = firestore;
1587
- this.parentRepository = parentRepository;
1588
- this.collectionName = 'payment_method';
1589
- this.parentIdField = 'userId';
1590
- this.model = UserPaymentMethod;
1618
+ constructor({ firestore, interceptors, }) {
1619
+ super({
1620
+ firestore,
1621
+ collectionName: 'payment_method',
1622
+ parentIdField: 'userId',
1623
+ model: UserPaymentMethod,
1624
+ interceptors,
1625
+ });
1591
1626
  }
1592
1627
  }
1593
1628
 
1594
1629
  class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1595
- constructor(firestore) {
1596
- super();
1597
- this.firestore = firestore;
1598
- this.collectionName = 'categories';
1599
- this.model = Category;
1630
+ constructor({ firestore, interceptors }) {
1631
+ super({
1632
+ firestore,
1633
+ collectionName: 'categories',
1634
+ model: Category,
1635
+ interceptors,
1636
+ });
1600
1637
  }
1601
1638
  async getCategoryBySlug(slug, shop) {
1602
1639
  const categoryDocs = await getDocs(query(this.collection(this.collectionName), where('slug', '==', slug), where('shop', '==', shop), where('published', '==', true)));
@@ -1641,12 +1678,14 @@ class CategoryFirestoreRepository extends withCrudFirestore(withHelpers(withFire
1641
1678
  }
1642
1679
 
1643
1680
  class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1644
- constructor(firestore) {
1645
- super();
1646
- this.firestore = firestore;
1681
+ constructor({ firestore, interceptors }) {
1682
+ super({
1683
+ firestore,
1684
+ collectionName: 'productsErpVitrine',
1685
+ model: Product,
1686
+ interceptors,
1687
+ });
1647
1688
  this.reviews = {};
1648
- this.collectionName = 'productsErpVitrine';
1649
- this.model = Product;
1650
1689
  }
1651
1690
  async getBySlug(slug) {
1652
1691
  const result = await this.find({
@@ -1684,40 +1723,48 @@ class ProductFirestoreRepository extends withCrudFirestore(withHelpers(withFires
1684
1723
  }
1685
1724
 
1686
1725
  class ProductVariantFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base))), Product) {
1687
- constructor(firestore, parentRepository) {
1688
- super();
1689
- this.firestore = firestore;
1726
+ constructor({ firestore, interceptors }, parentRepository) {
1727
+ super({
1728
+ firestore,
1729
+ collectionName: 'variants',
1730
+ parentIdField: 'productId',
1731
+ model: Variant,
1732
+ interceptors,
1733
+ });
1690
1734
  this.parentRepository = parentRepository;
1691
- this.collectionName = 'variants';
1692
- this.parentIdField = 'productId';
1693
- this.model = Variant;
1694
1735
  }
1695
1736
  }
1696
1737
 
1697
1738
  class SubscriptionProductFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1698
- constructor(firestore) {
1699
- super();
1700
- this.firestore = firestore;
1701
- this.collectionName = 'subscriptionProducts';
1702
- this.model = Product;
1739
+ constructor({ firestore, interceptors }) {
1740
+ super({
1741
+ firestore,
1742
+ collectionName: 'subscriptionProducts',
1743
+ model: Product,
1744
+ interceptors,
1745
+ });
1703
1746
  }
1704
1747
  }
1705
1748
 
1706
1749
  class CheckoutFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1707
- constructor(firestore) {
1708
- super();
1709
- this.firestore = firestore;
1710
- this.collectionName = 'checkouts';
1711
- this.model = Checkout;
1750
+ constructor({ firestore, interceptors }) {
1751
+ super({
1752
+ firestore,
1753
+ collectionName: 'checkouts',
1754
+ model: Checkout,
1755
+ interceptors,
1756
+ });
1712
1757
  }
1713
1758
  }
1714
1759
 
1715
1760
  class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1716
- constructor(firestore) {
1717
- super();
1718
- this.firestore = firestore;
1719
- this.collectionName = 'coupons';
1720
- this.model = Coupon;
1761
+ constructor({ firestore, interceptors }) {
1762
+ super({
1763
+ firestore,
1764
+ collectionName: 'coupons',
1765
+ model: Coupon,
1766
+ interceptors,
1767
+ });
1721
1768
  }
1722
1769
  buildModelInstance() {
1723
1770
  const { fromFirestore, toFirestore } = super.buildModelInstance();
@@ -1739,9 +1786,16 @@ class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirest
1739
1786
  }
1740
1787
 
1741
1788
  class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1742
- constructor(firestore) {
1743
- super();
1744
- this.firestore = firestore;
1789
+ constructor({ firestore, interceptors }) {
1790
+ super({
1791
+ firestore,
1792
+ collectionName: 'orders',
1793
+ model: Order,
1794
+ interceptors,
1795
+ fields: {
1796
+ status: FirestoreFieldType.String,
1797
+ },
1798
+ });
1745
1799
  this.orderFromFirestore = (order) => {
1746
1800
  if (!!order?.lineItems?.length) {
1747
1801
  order.lineItems = order.lineItems.map((lineItem) => {
@@ -1754,11 +1808,6 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
1754
1808
  }
1755
1809
  return order;
1756
1810
  };
1757
- this.collectionName = 'orders';
1758
- this.model = Order;
1759
- this.fields = {
1760
- status: FirestoreFieldType.String,
1761
- };
1762
1811
  }
1763
1812
  buildModelInstance() {
1764
1813
  const { fromFirestore, toFirestore } = super.buildModelInstance();
@@ -1773,53 +1822,67 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
1773
1822
  }
1774
1823
 
1775
1824
  class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1776
- constructor(firestore) {
1777
- super();
1778
- this.firestore = firestore;
1779
- this.collectionName = 'payments';
1780
- this.model = Payment;
1825
+ constructor({ firestore, interceptors }) {
1826
+ super({
1827
+ firestore,
1828
+ collectionName: 'payments',
1829
+ model: Payment,
1830
+ interceptors,
1831
+ });
1781
1832
  }
1782
1833
  }
1783
1834
 
1784
1835
  class CheckoutSubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1785
- constructor(firestore) {
1786
- super();
1787
- this.firestore = firestore;
1788
- this.collectionName = 'checkoutsSubscription';
1789
- this.model = CheckoutSubscription;
1836
+ constructor({ firestore, interceptors, }) {
1837
+ super({
1838
+ firestore,
1839
+ collectionName: 'checkoutsSubscription',
1840
+ model: CheckoutSubscription,
1841
+ interceptors,
1842
+ });
1790
1843
  }
1791
1844
  }
1792
1845
 
1793
1846
  class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1794
- constructor(firestore) {
1795
- super();
1796
- this.firestore = firestore;
1797
- this.collectionName = 'subscriptionPlans';
1798
- this.model = SubscriptionPlan;
1847
+ constructor({ firestore, interceptors, }) {
1848
+ super({
1849
+ firestore,
1850
+ collectionName: 'subscriptionPlans',
1851
+ model: SubscriptionPlan,
1852
+ interceptors,
1853
+ });
1799
1854
  }
1800
1855
  }
1801
1856
 
1802
1857
  class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1803
- constructor(firestore) {
1804
- super();
1805
- this.firestore = firestore;
1806
- this.collectionName = 'buy2win';
1807
- this.model = Buy2Win;
1858
+ constructor({ firestore, interceptors }) {
1859
+ super({
1860
+ firestore,
1861
+ collectionName: 'buy2win',
1862
+ model: Buy2Win,
1863
+ interceptors,
1864
+ });
1808
1865
  }
1809
1866
  }
1810
1867
 
1811
1868
  class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
1812
- constructor(firestore) {
1813
- super(firestore);
1814
- this.firestore = firestore;
1869
+ constructor({ firestore, interceptors }) {
1870
+ super({
1871
+ firestore,
1872
+ interceptors,
1873
+ });
1815
1874
  this.collectionName = 'legacyOrders';
1816
1875
  }
1817
1876
  }
1818
1877
 
1819
1878
  class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1820
- constructor(firestore) {
1821
- super();
1822
- this.firestore = firestore;
1879
+ constructor({ firestore, interceptors }) {
1880
+ super({
1881
+ firestore,
1882
+ collectionName: 'dms',
1883
+ model: Home,
1884
+ interceptors,
1885
+ });
1823
1886
  this.homeToFirestore = (home) => {
1824
1887
  if (home.data?.data) {
1825
1888
  home.data.data.discoverProducts = home.data.data.discoverProducts.map(this.homeCategoryGroupToPlain);
@@ -1848,8 +1911,6 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
1848
1911
  category: Category.toInstance(homeCategoryGroup.category),
1849
1912
  products: homeCategoryGroup.products.map((product) => Product.toInstance(product)),
1850
1913
  });
1851
- this.collectionName = 'dms';
1852
- this.model = Home;
1853
1914
  }
1854
1915
  buildModelInstance() {
1855
1916
  const { fromFirestore, toFirestore } = super.buildModelInstance();
@@ -1867,11 +1928,13 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
1867
1928
  }
1868
1929
 
1869
1930
  class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
1870
- constructor(firestore) {
1871
- super();
1872
- this.firestore = firestore;
1873
- this.collectionName = 'shopMenus';
1874
- this.model = ShopMenu;
1931
+ constructor({ firestore, interceptors }) {
1932
+ super({
1933
+ firestore,
1934
+ collectionName: 'shopMenus',
1935
+ model: ShopMenu,
1936
+ interceptors,
1937
+ });
1875
1938
  }
1876
1939
  }
1877
1940
 
@@ -3234,7 +3297,7 @@ class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGra
3234
3297
  subscriberPrice: data.subscriber_price,
3235
3298
  }),
3236
3299
  bindFindFilter: (sentence) => {
3237
- const filters = Object.values(sentence || {}).shift();
3300
+ const filters = Object.values(sentence).shift();
3238
3301
  return {
3239
3302
  ...((filters?.price || filters?.price === 0) && { price: filters.price }),
3240
3303
  ...((filters.fullPrice || filters.fullPrice === 0) && { full_price: filters.fullPrice }),