@infrab4a/connect 4.25.0-beta.7 → 4.25.0-beta.9

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 (40) hide show
  1. package/index.cjs.js +157 -68
  2. package/index.esm.js +157 -68
  3. package/package.json +1 -1
  4. package/src/infra/firebase/firestore/mixins/helpers/cache-key-generator.helper.d.ts +9 -0
  5. package/src/infra/firebase/firestore/mixins/helpers/index.d.ts +1 -0
  6. package/src/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +1 -1
  7. package/src/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.d.ts +1 -1
  8. package/src/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.d.ts +1 -1
  9. package/src/infra/firebase/firestore/repositories/shop-settings/shop-settings-firestore.repository.d.ts +1 -1
  10. package/src/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.d.ts +1 -1
  11. package/src/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.d.ts +1 -1
  12. package/src/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.d.ts +1 -1
  13. package/src/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.d.ts +1 -1
  14. package/src/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.d.ts +1 -1
  15. package/src/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.d.ts +1 -1
  16. package/src/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.d.ts +1 -1
  17. package/src/infra/firebase/firestore/repositories/shopping/order-blocked-firestore.repository.d.ts +1 -1
  18. package/src/infra/firebase/firestore/repositories/shopping/order-firestore.repository.d.ts +1 -1
  19. package/src/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.d.ts +1 -1
  20. package/src/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.d.ts +1 -1
  21. package/src/infra/firebase/firestore/repositories/users/lead-firestore.repository.d.ts +1 -1
  22. package/src/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.d.ts +1 -1
  23. package/src/infra/firebase/firestore/repositories/users/subscription-firestore.repository.d.ts +1 -1
  24. package/src/infra/firebase/firestore/repositories/users/subscription-materialization-firestore.repository.d.ts +1 -1
  25. package/src/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.d.ts +1 -1
  26. package/src/infra/firebase/firestore/repositories/users/subscription-summary-firestore.repository.d.ts +1 -1
  27. package/src/infra/firebase/firestore/repositories/users/user-address-firestore.repository.d.ts +1 -1
  28. package/src/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.d.ts +1 -1
  29. package/src/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +1 -1
  30. package/src/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.d.ts +1 -1
  31. package/src/infra/hasura-graphql/repositories/catalog/category-collection-children-hasura-graphql.repository.d.ts +1 -1
  32. package/src/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.d.ts +1 -1
  33. package/src/infra/hasura-graphql/repositories/catalog/category-product-hasura-graphql.repository.d.ts +1 -1
  34. package/src/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.d.ts +1 -1
  35. package/src/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.d.ts +1 -1
  36. package/src/infra/hasura-graphql/repositories/catalog/product-errors-hasura-graphql.repository.d.ts +1 -1
  37. package/src/infra/hasura-graphql/repositories/catalog/product-review-hasura-graphql.repository.d.ts +1 -1
  38. package/src/infra/hasura-graphql/repositories/catalog/product-stock-notification-hasura-graphql.repository.d.ts +1 -1
  39. package/src/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +1 -1
  40. package/src/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.d.ts +1 -1
package/index.cjs.js CHANGED
@@ -3604,24 +3604,39 @@ class MD5GeneratorHelper {
3604
3604
  }
3605
3605
  }
3606
3606
 
3607
+ class FirestoreCacheKeyGeneratorHelper {
3608
+ static generateGetCacheKey(model, identifiers) {
3609
+ const sortedEntries = Object.entries(identifiers).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
3610
+ const keyParts = [];
3611
+ for (const [key, value] of sortedEntries) {
3612
+ keyParts.push(`${key}:${value}`);
3613
+ }
3614
+ return `${model.name.toLowerCase()}:get:${keyParts.join(':')}`;
3615
+ }
3616
+ static generateFindCacheKey(model, findParams) {
3617
+ const md5 = MD5GeneratorHelper.generateMD5(findParams);
3618
+ return `${model.name.toLowerCase()}:find:${md5}`;
3619
+ }
3620
+ }
3621
+
3607
3622
  const withGetFirestore = (MixinBase) => {
3608
3623
  return class GetFirestore extends MixinBase {
3609
- async get(identifiers) {
3610
- var _a, _b, _c, _d, _e, _f;
3624
+ async get(identifiers, options) {
3625
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
3611
3626
  const logger = this.logger.with('get');
3612
3627
  const collectionName = this.buildCollectionPathForGet(identifiers);
3613
3628
  const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
3614
3629
  const req = { collection: collectionName, data: identifiers };
3615
- if ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) {
3616
- const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(this.model, identifiers);
3630
+ if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled) !== false) {
3631
+ const cacheKey = FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(this.model, identifiers);
3617
3632
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
3618
3633
  if (cachedData) {
3619
3634
  logger.log({ req, res: 'Dados recuperados do cache', cacheKey });
3620
- return this.model.toInstance(cachedData);
3635
+ return this.model.toInstance(JSON.parse(cachedData));
3621
3636
  }
3622
3637
  }
3623
3638
  try {
3624
- const intercepted = await ((_c = (_b = this.interceptors) === null || _b === void 0 ? void 0 : _b.request) === null || _c === void 0 ? void 0 : _c.call(_b, { instance }));
3639
+ const intercepted = await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.request) === null || _d === void 0 ? void 0 : _d.call(_c, { instance }));
3625
3640
  const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
3626
3641
  const docRef = await this.collection(collectionName)
3627
3642
  .getDoc(Object.values(builded.identifier).shift().toString())
@@ -3629,14 +3644,14 @@ const withGetFirestore = (MixinBase) => {
3629
3644
  const data = docRef.data();
3630
3645
  if (lodash.isNil(data))
3631
3646
  throw new NotFoundError(`Document '${collectionName}/${Object.values(identifiers).shift()}' not found`);
3632
- const res = ((_e = (_d = this.interceptors) === null || _d === void 0 ? void 0 : _d.response) === null || _e === void 0 ? void 0 : _e.call(_d, data, intercepted)) || data;
3647
+ const res = (await ((_f = (_e = this.interceptors) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.call(_e, data, intercepted))) || data;
3633
3648
  logger.log({ req, res });
3634
- if ((_f = this.cache) === null || _f === void 0 ? void 0 : _f.cacheAdapter) {
3635
- const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(this.model, identifiers);
3649
+ if (((_g = this.cache) === null || _g === void 0 ? void 0 : _g.cacheAdapter) && ((_h = options === null || options === void 0 ? void 0 : options.cache) === null || _h === void 0 ? void 0 : _h.enabled) !== false) {
3650
+ const cacheKey = FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(this.model, identifiers);
3636
3651
  await this.cache.cacheAdapter.set({
3637
3652
  key: cacheKey,
3638
- data: res,
3639
- expirationInSeconds: this.cache.ttlDefault,
3653
+ data: JSON.stringify((res === null || res === void 0 ? void 0 : res.toPlain()) || res),
3654
+ expirationInSeconds: ((_j = options === null || options === void 0 ? void 0 : options.cache) === null || _j === void 0 ? void 0 : _j.ttl) || this.cache.ttlDefault,
3640
3655
  });
3641
3656
  logger.log({ req, message: 'Dados salvos no cache', cacheKey });
3642
3657
  }
@@ -3729,15 +3744,26 @@ const withFindFirestore = (MixinBase) => {
3729
3744
  ]);
3730
3745
  };
3731
3746
  }
3732
- async find(find = {}) {
3733
- var _a, _b, _c, _d, _e, _f;
3747
+ generateCacheKey(findParams) {
3748
+ return FirestoreCacheKeyGeneratorHelper.generateFindCacheKey(this.model, findParams);
3749
+ }
3750
+ async find(find = {}, options) {
3751
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
3734
3752
  const logger = this.logger.with('find');
3753
+ if (((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) && ((_b = options === null || options === void 0 ? void 0 : options.cache) === null || _b === void 0 ? void 0 : _b.enabled) !== false) {
3754
+ const cacheKey = this.generateCacheKey(find);
3755
+ const cachedData = await this.cache.cacheAdapter.get(cacheKey);
3756
+ if (cachedData) {
3757
+ logger.log(`Dados recuperados do cache: ${cacheKey}`);
3758
+ return JSON.parse(cachedData);
3759
+ }
3760
+ }
3735
3761
  const collectionName = this.buildCollectionPathForFind(find.filters);
3736
3762
  const collection = this.collection(collectionName);
3737
- const enableCount = (_b = (_a = find === null || find === void 0 ? void 0 : find.options) === null || _a === void 0 ? void 0 : _a.enableCount) !== null && _b !== void 0 ? _b : true;
3763
+ const enableCount = (_d = (_c = find === null || find === void 0 ? void 0 : find.options) === null || _c === void 0 ? void 0 : _c.enableCount) !== null && _d !== void 0 ? _d : true;
3738
3764
  const req = { collection: collectionName, data: find };
3739
3765
  try {
3740
- const intercepted = await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.request) === null || _d === void 0 ? void 0 : _d.call(_c, { find }));
3766
+ const intercepted = await ((_f = (_e = this.interceptors) === null || _e === void 0 ? void 0 : _e.request) === null || _f === void 0 ? void 0 : _f.call(_e, { find }));
3741
3767
  const { fields, filters, limits, orderBy } = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.find) || find;
3742
3768
  const queries = this.makeFirestoreWhere(filters || {});
3743
3769
  const ordination = this.makeFirestoreOrderBy(filters, orderBy);
@@ -3747,10 +3773,19 @@ const withFindFirestore = (MixinBase) => {
3747
3773
  .getDocs();
3748
3774
  const data = docs.docs.map((doc) => doc.data());
3749
3775
  const res = {
3750
- data: (await ((_f = (_e = this.interceptors) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.call(_e, data, intercepted))) || data,
3776
+ data: (await ((_h = (_g = this.interceptors) === null || _g === void 0 ? void 0 : _g.response) === null || _h === void 0 ? void 0 : _h.call(_g, data, intercepted))) || data,
3751
3777
  count: enableCount ? this.calculateCount(data, limits) : Infinity,
3752
3778
  };
3753
3779
  logger.log({ req, queries, ordination, offsets, res });
3780
+ if (((_j = this.cache) === null || _j === void 0 ? void 0 : _j.cacheAdapter) && ((_k = options === null || options === void 0 ? void 0 : options.cache) === null || _k === void 0 ? void 0 : _k.enabled) !== false) {
3781
+ const cacheKey = this.generateCacheKey(find);
3782
+ await this.cache.cacheAdapter.set({
3783
+ key: cacheKey,
3784
+ data: JSON.stringify(res),
3785
+ expirationInSeconds: ((_l = options === null || options === void 0 ? void 0 : options.cache) === null || _l === void 0 ? void 0 : _l.ttl) || this.cache.ttlDefault,
3786
+ });
3787
+ logger.log(`Dados salvos no cache: ${cacheKey}`);
3788
+ }
3754
3789
  return res;
3755
3790
  }
3756
3791
  catch (error) {
@@ -3854,24 +3889,41 @@ const withUpdateFirestore = (MixinBase) => {
3854
3889
  return options === null || options === void 0 ? void 0 : options.value;
3855
3890
  };
3856
3891
  return class UpdateFirestore extends MixinBase {
3892
+ getIdentifiersFromData(data) {
3893
+ const identifiers = {};
3894
+ const model = new this.model();
3895
+ const keyField = model.identifiersFields.shift();
3896
+ const identifierValue = getValueFromParams(data, keyField);
3897
+ identifiers[keyField] = identifierValue;
3898
+ return identifiers;
3899
+ }
3900
+ generateCacheKey(identifiers) {
3901
+ return FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(this.model, identifiers);
3902
+ }
3857
3903
  async update(data) {
3858
- var _a, _b, _c, _d;
3904
+ var _a, _b, _c, _d, _e;
3859
3905
  const logger = this.logger.with('update');
3860
3906
  const collectionName = this.buildCollectionPathForUpdate(data);
3861
3907
  const model = new this.model();
3862
3908
  const keyField = model.identifiersFields.shift();
3863
3909
  const req = { collection: collectionName, data };
3910
+ if ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) {
3911
+ const identifiers = this.getIdentifiersFromData(data);
3912
+ const cacheKey = this.generateCacheKey(identifiers);
3913
+ await this.cache.cacheAdapter.remove(cacheKey);
3914
+ logger.log(`Cache removido: ${cacheKey}`);
3915
+ }
3864
3916
  try {
3865
3917
  const identifiers = getValueFromParams(data, keyField);
3866
3918
  const docRef = this.collection(collectionName).getDoc(identifiers.toString());
3867
3919
  if (!(await docRef.get()).data())
3868
3920
  throw new NotFoundError(`Document '${collectionName}/${Object.values(identifiers.toString())}' not found`);
3869
3921
  const plainFromData = this.model.toInstance(this.paramsToPlain(data));
3870
- const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance: plainFromData }));
3922
+ const intercepted = await ((_c = (_b = this.interceptors) === null || _b === void 0 ? void 0 : _b.request) === null || _c === void 0 ? void 0 : _c.call(_b, { instance: plainFromData }));
3871
3923
  const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || plainFromData;
3872
3924
  await docRef.save(builded.toPlain());
3873
3925
  const docData = await docRef.get();
3874
- const res = ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, docData.data(), intercepted)) || docData.data();
3926
+ const res = ((_e = (_d = this.interceptors) === null || _d === void 0 ? void 0 : _d.response) === null || _e === void 0 ? void 0 : _e.call(_d, docData.data(), intercepted)) || docData.data();
3875
3927
  logger.log({ req, res, identifiers });
3876
3928
  return res;
3877
3929
  }
@@ -3897,17 +3949,25 @@ const withUpdateFirestore = (MixinBase) => {
3897
3949
 
3898
3950
  const withDeleteFirestore = (MixinBase) => {
3899
3951
  return class DeleteFirestore extends MixinBase {
3952
+ generateCacheKey(identifiers) {
3953
+ return FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(this.model, identifiers);
3954
+ }
3900
3955
  async delete(identifiers) {
3901
- var _a, _b, _c, _d;
3956
+ var _a, _b, _c, _d, _e;
3902
3957
  const logger = this.logger.with('delete');
3903
3958
  const collectionName = this.buildCollectionPathForRemove(identifiers);
3904
3959
  const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
3905
3960
  const req = { collection: collectionName, data: identifiers };
3961
+ if ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) {
3962
+ const cacheKey = this.generateCacheKey(identifiers);
3963
+ await this.cache.cacheAdapter.remove(cacheKey);
3964
+ logger.log(`Cache removido: ${cacheKey}`);
3965
+ }
3906
3966
  try {
3907
- const intercepted = await ((_b = (_a = this.interceptors) === null || _a === void 0 ? void 0 : _a.request) === null || _b === void 0 ? void 0 : _b.call(_a, { instance }));
3967
+ const intercepted = await ((_c = (_b = this.interceptors) === null || _b === void 0 ? void 0 : _b.request) === null || _c === void 0 ? void 0 : _c.call(_b, { instance }));
3908
3968
  const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
3909
3969
  await this.collection(collectionName).getDoc(Object.values(builded.identifier).shift().toString()).delete();
3910
- await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, instance, intercepted));
3970
+ await ((_e = (_d = this.interceptors) === null || _d === void 0 ? void 0 : _d.response) === null || _e === void 0 ? void 0 : _e.call(_d, instance, intercepted));
3911
3971
  logger.log({ req, res: undefined });
3912
3972
  }
3913
3973
  catch (error) {
@@ -4152,12 +4212,13 @@ class SequenceFirestoreRepository extends withCrudFirestore(withHelpers(withFire
4152
4212
  }
4153
4213
 
4154
4214
  class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4155
- constructor({ firestore, interceptors }) {
4215
+ constructor({ firestore, interceptors, cache, }) {
4156
4216
  super({
4157
4217
  firestore,
4158
4218
  collectionName: 'dms',
4159
4219
  model: Home,
4160
4220
  interceptors,
4221
+ cache,
4161
4222
  });
4162
4223
  this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
4163
4224
  var _a, _b, _c;
@@ -4214,89 +4275,97 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
4214
4275
  }
4215
4276
 
4216
4277
  class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4217
- constructor({ firestore, interceptors }) {
4278
+ constructor({ firestore, interceptors, cache, }) {
4218
4279
  super({
4219
4280
  firestore,
4220
4281
  collectionName: 'shopMenus',
4221
4282
  model: ShopMenu,
4222
4283
  interceptors,
4284
+ cache,
4223
4285
  });
4224
4286
  }
4225
4287
  }
4226
4288
 
4227
4289
  class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4228
- constructor({ firestore, interceptors, }) {
4290
+ constructor({ firestore, interceptors, cache, }) {
4229
4291
  super({
4230
4292
  firestore,
4231
4293
  collectionName: 'shopSettings',
4232
4294
  model: ShopSettings,
4233
4295
  interceptors,
4296
+ cache,
4234
4297
  });
4235
4298
  }
4236
4299
  }
4237
4300
 
4238
4301
  class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4239
- constructor({ firestore, interceptors }) {
4302
+ constructor({ firestore, interceptors, cache, }) {
4240
4303
  super({
4241
4304
  firestore,
4242
4305
  collectionName: 'buy2win',
4243
4306
  model: Buy2Win,
4244
4307
  interceptors,
4308
+ cache,
4245
4309
  });
4246
4310
  }
4247
4311
  }
4248
4312
 
4249
4313
  class CampaignDashboardFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4250
- constructor({ firestore, interceptors, }) {
4314
+ constructor({ firestore, interceptors, cache, }) {
4251
4315
  super({
4252
4316
  firestore,
4253
4317
  collectionName: 'dashboardCampaignsAuto',
4254
4318
  model: CampaignDashboard,
4255
4319
  interceptors,
4320
+ cache,
4256
4321
  });
4257
4322
  }
4258
4323
  }
4259
4324
 
4260
4325
  class CampaignHashtagFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4261
- constructor({ firestore, interceptors, }) {
4326
+ constructor({ firestore, interceptors, cache, }) {
4262
4327
  super({
4263
4328
  firestore,
4264
4329
  collectionName: 'hashtagCampaignsAuto',
4265
4330
  model: CampaignHashtag,
4266
4331
  interceptors,
4332
+ cache,
4267
4333
  });
4268
4334
  }
4269
4335
  }
4270
4336
 
4271
4337
  class CheckoutFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4272
- constructor({ firestore, interceptors }) {
4338
+ constructor({ firestore, interceptors, cache, }) {
4273
4339
  super({
4274
4340
  firestore,
4275
4341
  collectionName: 'checkouts',
4276
4342
  model: Checkout,
4277
4343
  interceptors,
4344
+ cache,
4278
4345
  });
4279
4346
  }
4280
4347
  }
4281
4348
 
4282
4349
  class CheckoutSubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4283
- constructor({ firestore, interceptors, }) {
4350
+ constructor({ firestore, interceptors, cache, }) {
4284
4351
  super({
4285
4352
  firestore,
4286
4353
  collectionName: 'checkoutsSubscription',
4287
4354
  model: CheckoutSubscription,
4288
4355
  interceptors,
4356
+ cache,
4289
4357
  });
4290
4358
  }
4291
4359
  }
4292
4360
 
4293
4361
  class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4294
- constructor({ firestore, interceptors }) {
4362
+ constructor({ firestore, interceptors, cache, }) {
4295
4363
  super({
4296
4364
  firestore,
4297
4365
  collectionName: 'coupons',
4298
4366
  model: Coupon,
4299
4367
  interceptors,
4368
+ cache,
4300
4369
  });
4301
4370
  }
4302
4371
  buildModelInstance() {
@@ -4319,12 +4388,13 @@ class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirest
4319
4388
  }
4320
4389
 
4321
4390
  class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4322
- constructor({ firestore, interceptors }) {
4391
+ constructor({ firestore, interceptors, cache, }) {
4323
4392
  super({
4324
4393
  firestore,
4325
4394
  collectionName: 'orders',
4326
4395
  model: Order,
4327
4396
  interceptors,
4397
+ cache,
4328
4398
  fields: {
4329
4399
  status: FirestoreFieldType.String,
4330
4400
  },
@@ -4356,22 +4426,24 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
4356
4426
  }
4357
4427
 
4358
4428
  class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
4359
- constructor({ firestore, interceptors }) {
4429
+ constructor({ firestore, interceptors, cache, }) {
4360
4430
  super({
4361
4431
  firestore,
4362
4432
  interceptors,
4433
+ cache,
4363
4434
  });
4364
4435
  this.collectionName = 'legacyOrders';
4365
4436
  }
4366
4437
  }
4367
4438
 
4368
4439
  class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4369
- constructor({ firestore, interceptors, }) {
4440
+ constructor({ firestore, interceptors, cache, }) {
4370
4441
  super({
4371
4442
  firestore,
4372
4443
  collectionName: 'paymentBlockedAttempts',
4373
4444
  model: OrderBlocked,
4374
4445
  interceptors,
4446
+ cache,
4375
4447
  });
4376
4448
  }
4377
4449
  async createBlockedOrderOrPayment(checkout, blockType, type, limiteRange, card = null) {
@@ -4403,130 +4475,141 @@ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(with
4403
4475
  }
4404
4476
 
4405
4477
  class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4406
- constructor({ firestore, interceptors }) {
4478
+ constructor({ firestore, interceptors, cache, }) {
4407
4479
  super({
4408
4480
  firestore,
4409
4481
  collectionName: 'payments',
4410
4482
  model: Payment,
4411
4483
  interceptors,
4484
+ cache,
4412
4485
  });
4413
4486
  }
4414
4487
  }
4415
4488
 
4416
4489
  class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4417
- constructor({ firestore, interceptors, }) {
4490
+ constructor({ firestore, interceptors, cache, }) {
4418
4491
  super({
4419
4492
  firestore,
4420
4493
  collectionName: 'subscriptionPlans',
4421
4494
  model: SubscriptionPlan,
4422
4495
  interceptors,
4496
+ cache,
4423
4497
  });
4424
4498
  }
4425
4499
  }
4426
4500
 
4427
4501
  class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4428
- constructor({ firestore, interceptors }) {
4502
+ constructor({ firestore, interceptors, cache, }) {
4429
4503
  super({
4430
4504
  firestore,
4431
4505
  collectionName: 'leads',
4432
4506
  model: Lead,
4433
4507
  interceptors,
4508
+ cache,
4434
4509
  });
4435
4510
  }
4436
4511
  }
4437
4512
 
4438
4513
  class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4439
- constructor({ firestore, interceptors }, parentRepository) {
4514
+ constructor({ firestore, interceptors, cache, }, parentRepository) {
4440
4515
  super({
4441
4516
  firestore,
4442
4517
  collectionName: 'editions',
4443
4518
  parentIdField: 'subscriptionId',
4444
4519
  model: Edition,
4445
4520
  interceptors,
4521
+ cache,
4446
4522
  });
4447
4523
  this.parentRepository = parentRepository;
4448
4524
  }
4449
4525
  }
4450
4526
 
4451
4527
  class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4452
- constructor({ firestore, interceptors, }) {
4528
+ constructor({ firestore, interceptors, cache, }) {
4453
4529
  super({
4454
4530
  firestore,
4455
4531
  collectionName: 'subscription',
4456
4532
  model: Subscription,
4457
4533
  interceptors,
4534
+ cache,
4458
4535
  });
4459
4536
  }
4460
4537
  }
4461
4538
 
4462
4539
  class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4463
- constructor({ firestore, interceptors }) {
4540
+ constructor({ firestore, interceptors, cache, }) {
4464
4541
  super({
4465
4542
  firestore,
4466
4543
  collectionName: 'subscriptionMaterialization',
4467
4544
  model: SubscriptionMaterialization,
4468
4545
  interceptors,
4546
+ cache,
4469
4547
  });
4470
4548
  }
4471
4549
  }
4472
4550
 
4473
4551
  class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4474
- constructor({ firestore, interceptors }, parentRepository) {
4552
+ constructor({ firestore, interceptors, cache, }, parentRepository) {
4475
4553
  super({
4476
4554
  firestore,
4477
4555
  collectionName: 'payments',
4478
4556
  parentIdField: 'subscriptionId',
4479
4557
  model: SubscriptionPayment,
4480
4558
  interceptors,
4559
+ cache,
4481
4560
  });
4482
4561
  this.parentRepository = parentRepository;
4483
4562
  }
4484
4563
  }
4485
4564
 
4486
4565
  class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4487
- constructor({ firestore, interceptors, }) {
4566
+ constructor({ firestore, interceptors, cache, }) {
4488
4567
  super({
4489
4568
  firestore,
4490
4569
  collectionName: 'subscriptionSummary',
4491
4570
  model: SubscriptionSummary,
4492
4571
  interceptors,
4572
+ cache,
4493
4573
  });
4494
4574
  }
4495
4575
  }
4496
4576
 
4497
4577
  class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4498
- constructor({ firestore, interceptors }, parentRepository) {
4578
+ constructor({ firestore, interceptors, cache, }, parentRepository) {
4499
4579
  super({
4500
4580
  firestore,
4501
4581
  collectionName: 'address',
4502
4582
  parentIdField: 'userId',
4503
4583
  model: UserAddress,
4504
4584
  interceptors,
4585
+ cache,
4505
4586
  });
4506
4587
  this.parentRepository = parentRepository;
4507
4588
  }
4508
4589
  }
4509
4590
 
4510
4591
  class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4511
- constructor({ firestore, interceptors }, parentRepository) {
4592
+ constructor({ firestore, interceptors, cache, }, parentRepository) {
4512
4593
  super({
4513
4594
  firestore,
4514
4595
  collectionName: 'CX',
4515
4596
  parentIdField: 'userId',
4516
4597
  model: BeautyProfile,
4517
4598
  interceptors,
4599
+ cache,
4518
4600
  });
4519
4601
  this.parentRepository = parentRepository;
4520
4602
  }
4521
4603
  }
4522
4604
 
4523
4605
  class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4524
- constructor({ firestore, interceptors }) {
4606
+ constructor({ firestore, interceptors, cache, }) {
4525
4607
  super({
4526
4608
  firestore,
4527
4609
  collectionName: 'users',
4528
4610
  model: User,
4529
4611
  interceptors,
4612
+ cache,
4530
4613
  });
4531
4614
  }
4532
4615
  async get(identifiers) {
@@ -4586,13 +4669,14 @@ tslib.__decorate([
4586
4669
  ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
4587
4670
 
4588
4671
  class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4589
- constructor({ firestore, interceptors }, parentRepository) {
4672
+ constructor({ firestore, interceptors, cache, }, parentRepository) {
4590
4673
  super({
4591
4674
  firestore,
4592
4675
  collectionName: 'payment_method',
4593
4676
  parentIdField: 'userId',
4594
4677
  model: UserPaymentMethod,
4595
4678
  interceptors,
4679
+ cache,
4596
4680
  });
4597
4681
  this.parentRepository = parentRepository;
4598
4682
  }
@@ -5259,7 +5343,7 @@ tslib.__decorate([
5259
5343
  ], ProductErrorsHasuraGraphQL.prototype, "product", void 0);
5260
5344
 
5261
5345
  class CategoryCollectionChildrenHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5262
- constructor({ endpoint, authOptions, interceptors, }) {
5346
+ constructor({ endpoint, authOptions, interceptors, cache, }) {
5263
5347
  super({
5264
5348
  tableName: 'category_collection_children',
5265
5349
  model: CategoryCollectionChildren,
@@ -5290,12 +5374,13 @@ class CategoryCollectionChildrenHasuraGraphQLRepository extends withCrudHasuraGr
5290
5374
  },
5291
5375
  },
5292
5376
  ],
5377
+ cache,
5293
5378
  });
5294
5379
  }
5295
5380
  }
5296
5381
 
5297
5382
  class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5298
- constructor({ endpoint, authOptions, interceptors, }) {
5383
+ constructor({ endpoint, authOptions, interceptors, cache, }) {
5299
5384
  super({
5300
5385
  tableName: 'category_filter',
5301
5386
  model: CategoryFilter,
@@ -5377,6 +5462,7 @@ class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
5377
5462
  },
5378
5463
  },
5379
5464
  ],
5465
+ cache,
5380
5466
  });
5381
5467
  }
5382
5468
  deleteByCategory(categoryId) {
@@ -5621,12 +5707,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5621
5707
  const mostRelevants = category.getMostRelevantByShop(shop);
5622
5708
  const mostRelevantProductsIds = [...new Set(mostRelevants.concat(category.products))];
5623
5709
  const products = [];
5624
- const { data: productsData } = await this.productRepository.findCatalog({
5625
- filters: {
5626
- id: { operator: exports.Where.IN, value: mostRelevantProductsIds },
5627
- published: true,
5628
- },
5629
- fields: [
5710
+ const { data: productsData } = await this.productRepository.findCatalog(Object.assign(Object.assign({ filters: Object.assign({ id: {
5711
+ operator: exports.Where.IN,
5712
+ value: mostRelevantProductsIds,
5713
+ }, published: true }, (options.hasStock ? { stock: { quantity: { operator: exports.Where.GT, value: 0 } } } : {})) }, (options.limit ? { limit: options.limit } : {})), { fields: [
5630
5714
  'id',
5631
5715
  'name',
5632
5716
  'slug',
@@ -5652,15 +5736,12 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5652
5736
  'shoppingCount',
5653
5737
  'gender',
5654
5738
  'createdAt',
5655
- ],
5656
- options: { enableCount: false },
5657
- orderBy: {
5739
+ ], options: { enableCount: false }, orderBy: {
5740
+ stock: 'desc',
5658
5741
  shoppingCount: 'desc',
5659
5742
  rate: 'desc',
5660
- stock: 'desc',
5661
5743
  name: 'asc',
5662
- },
5663
- }, shop === exports.Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5744
+ } }), shop === exports.Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5664
5745
  const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
5665
5746
  const firstProducts = productsData
5666
5747
  .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
@@ -5846,7 +5927,7 @@ tslib.__decorate([
5846
5927
  ], CategoryHasuraGraphQLRepository.prototype, "isChild", null);
5847
5928
 
5848
5929
  class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5849
- constructor({ endpoint, authOptions, interceptors, }) {
5930
+ constructor({ endpoint, authOptions, interceptors, cache, }) {
5850
5931
  super({
5851
5932
  tableName: 'category_product',
5852
5933
  model: CategoryProduct,
@@ -5854,6 +5935,7 @@ class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withH
5854
5935
  authOptions,
5855
5936
  interceptors,
5856
5937
  fields: [{ productId: { columnName: 'product_id' } }, { categoryId: { columnName: 'category_id' } }, 'order'],
5938
+ cache,
5857
5939
  });
5858
5940
  }
5859
5941
  async removeProductFromCategory(categoryId, productId) {
@@ -5880,7 +5962,7 @@ class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withH
5880
5962
  }
5881
5963
 
5882
5964
  class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5883
- constructor({ endpoint, authOptions, interceptors, }, filterOptionRepository, categoryFilterRepository) {
5965
+ constructor({ endpoint, authOptions, interceptors, cache, }, filterOptionRepository, categoryFilterRepository) {
5884
5966
  super({
5885
5967
  tableName: 'filter',
5886
5968
  model: Filter,
@@ -5920,6 +6002,7 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
5920
6002
  },
5921
6003
  },
5922
6004
  ],
6005
+ cache,
5923
6006
  });
5924
6007
  this.filterOptionRepository = filterOptionRepository;
5925
6008
  this.categoryFilterRepository = categoryFilterRepository;
@@ -6006,7 +6089,7 @@ tslib.__decorate([
6006
6089
  ], FilterHasuraGraphQLRepository.prototype, "deleteOptions", null);
6007
6090
 
6008
6091
  class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6009
- constructor({ endpoint, authOptions, interceptors, }) {
6092
+ constructor({ endpoint, authOptions, interceptors, cache, }) {
6010
6093
  super({
6011
6094
  tableName: 'filter_option',
6012
6095
  model: FilterOption,
@@ -6020,18 +6103,20 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
6020
6103
  { createdAt: { columnName: 'created_at' } },
6021
6104
  { updatedAt: { columnName: 'updated_at' } },
6022
6105
  ],
6106
+ cache,
6023
6107
  });
6024
6108
  }
6025
6109
  }
6026
6110
 
6027
6111
  class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6028
- constructor({ endpoint, authOptions, interceptors, }, productRepository) {
6112
+ constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
6029
6113
  super({
6030
6114
  tableName: 'product_errors',
6031
6115
  model: ProductErrorsHasuraGraphQL,
6032
6116
  endpoint,
6033
6117
  authOptions,
6034
6118
  interceptors,
6119
+ cache,
6035
6120
  fields: [
6036
6121
  {
6037
6122
  productId: {
@@ -6745,7 +6830,7 @@ tslib.__decorate([
6745
6830
  ], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
6746
6831
 
6747
6832
  class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6748
- constructor({ endpoint, authOptions, interceptors, }) {
6833
+ constructor({ endpoint, authOptions, interceptors, cache, }) {
6749
6834
  super({
6750
6835
  tableName: 'product_review',
6751
6836
  model: ProductReview,
@@ -6769,6 +6854,7 @@ class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
6769
6854
  { createdAt: { columnName: 'created_at' } },
6770
6855
  { updatedAt: { columnName: 'updated_at' } },
6771
6856
  ],
6857
+ cache,
6772
6858
  });
6773
6859
  }
6774
6860
  async updateManyStatus(reviews) {
@@ -6810,13 +6896,14 @@ tslib.__decorate([
6810
6896
  ], ProductReviewHasuraGraphQLRepository.prototype, "disaproveReview", null);
6811
6897
 
6812
6898
  class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6813
- constructor({ endpoint, authOptions, interceptors, }) {
6899
+ constructor({ endpoint, authOptions, interceptors, cache, }) {
6814
6900
  super({
6815
6901
  tableName: 'product_stock_notification',
6816
6902
  model: ProductStockNotification,
6817
6903
  endpoint,
6818
6904
  authOptions,
6819
6905
  interceptors,
6906
+ cache,
6820
6907
  fields: [
6821
6908
  'id',
6822
6909
  { productId: { columnName: 'product_id' } },
@@ -6871,13 +6958,14 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
6871
6958
  }
6872
6959
 
6873
6960
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6874
- constructor({ endpoint, authOptions, interceptors, }) {
6961
+ constructor({ endpoint, authOptions, interceptors, cache, }) {
6875
6962
  super({
6876
6963
  tableName: 'product',
6877
6964
  model: VariantHasuraGraphQL,
6878
6965
  endpoint,
6879
6966
  authOptions,
6880
6967
  interceptors,
6968
+ cache,
6881
6969
  fields: [
6882
6970
  { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
6883
6971
  { firestoreId: { columnName: 'firestore_id' } },
@@ -6984,13 +7072,14 @@ class WishlistHasuraGraphQL extends Wishlist {
6984
7072
  }
6985
7073
 
6986
7074
  class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6987
- constructor({ endpoint, authOptions, interceptors, }, categoryProductRepository) {
7075
+ constructor({ endpoint, authOptions, interceptors, cache, }, categoryProductRepository) {
6988
7076
  super({
6989
7077
  tableName: 'category',
6990
7078
  model: WishlistHasuraGraphQL,
6991
7079
  endpoint,
6992
7080
  authOptions,
6993
7081
  interceptors,
7082
+ cache,
6994
7083
  fields: [
6995
7084
  { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
6996
7085
  { firestoreId: { columnName: 'firestore_id' } },