@infrab4a/connect 4.25.0-beta.12 → 4.25.0-beta.2

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 (44) hide show
  1. package/index.cjs.js +192 -273
  2. package/index.esm.js +173 -273
  3. package/package.json +1 -1
  4. package/src/domain/catalog/repositories/category.repository.d.ts +4 -15
  5. package/src/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +1 -1
  6. package/src/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.d.ts +1 -1
  7. package/src/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.d.ts +1 -1
  8. package/src/infra/firebase/firestore/repositories/shop-settings/shop-settings-firestore.repository.d.ts +1 -1
  9. package/src/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.d.ts +1 -1
  10. package/src/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.d.ts +1 -1
  11. package/src/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.d.ts +1 -1
  12. package/src/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.d.ts +1 -1
  13. package/src/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.d.ts +1 -1
  14. package/src/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.d.ts +1 -1
  15. package/src/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.d.ts +1 -1
  16. package/src/infra/firebase/firestore/repositories/shopping/order-blocked-firestore.repository.d.ts +1 -1
  17. package/src/infra/firebase/firestore/repositories/shopping/order-firestore.repository.d.ts +1 -1
  18. package/src/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.d.ts +1 -1
  19. package/src/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.d.ts +1 -1
  20. package/src/infra/firebase/firestore/repositories/users/lead-firestore.repository.d.ts +1 -1
  21. package/src/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.d.ts +1 -1
  22. package/src/infra/firebase/firestore/repositories/users/subscription-firestore.repository.d.ts +1 -1
  23. package/src/infra/firebase/firestore/repositories/users/subscription-materialization-firestore.repository.d.ts +1 -1
  24. package/src/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.d.ts +1 -1
  25. package/src/infra/firebase/firestore/repositories/users/subscription-summary-firestore.repository.d.ts +1 -1
  26. package/src/infra/firebase/firestore/repositories/users/user-address-firestore.repository.d.ts +1 -1
  27. package/src/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.d.ts +1 -1
  28. package/src/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +1 -1
  29. package/src/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.d.ts +1 -1
  30. package/src/infra/hasura-graphql/mixins/helpers/md5-generator.helper.d.ts +7 -0
  31. package/src/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +0 -16
  32. package/src/infra/hasura-graphql/repositories/catalog/category-collection-children-hasura-graphql.repository.d.ts +1 -1
  33. package/src/infra/hasura-graphql/repositories/catalog/category-filter-hasura-graphql.repository.d.ts +1 -1
  34. package/src/infra/hasura-graphql/repositories/catalog/category-hasura-graphql.repository.d.ts +6 -19
  35. package/src/infra/hasura-graphql/repositories/catalog/category-product-hasura-graphql.repository.d.ts +1 -1
  36. package/src/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.d.ts +1 -1
  37. package/src/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.d.ts +1 -1
  38. package/src/infra/hasura-graphql/repositories/catalog/product-errors-hasura-graphql.repository.d.ts +1 -1
  39. package/src/infra/hasura-graphql/repositories/catalog/product-review-hasura-graphql.repository.d.ts +1 -1
  40. package/src/infra/hasura-graphql/repositories/catalog/product-stock-notification-hasura-graphql.repository.d.ts +1 -1
  41. package/src/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +1 -1
  42. package/src/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.d.ts +1 -1
  43. package/src/infra/firebase/firestore/mixins/helpers/cache-key-generator.helper.d.ts +0 -9
  44. package/src/infra/firebase/firestore/mixins/helpers/index.d.ts +0 -1
package/index.esm.js CHANGED
@@ -9,7 +9,7 @@ import { debug } from 'debug';
9
9
  import { CustomError } from 'ts-custom-error';
10
10
  import axios, { AxiosError } from 'axios';
11
11
  import { signInWithEmailAndPassword, signInWithPopup, GoogleAuthProvider, signInAnonymously, sendPasswordResetEmail, createUserWithEmailAndPassword, sendEmailVerification } from 'firebase/auth';
12
- import { Md5 } from 'ts-md5';
12
+ import * as crypto from 'crypto';
13
13
  import { deleteField, arrayUnion, arrayRemove, Timestamp, doc, getDoc, updateDoc, setDoc, deleteDoc, collection, limit, getDocs, query, where, orderBy, startAfter, addDoc } from 'firebase/firestore';
14
14
  import { ref, uploadBytes } from 'firebase/storage';
15
15
  import { mutation, query as query$1 } from 'gql-query-builder';
@@ -3566,28 +3566,46 @@ GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields = (fieldName, fieldValue)
3566
3566
  };
3567
3567
 
3568
3568
  class MD5GeneratorHelper {
3569
+ /**
3570
+ * Gera um hash MD5 para um objeto de qualquer estrutura
3571
+ * Garante que o mesmo objeto sempre gerará o mesmo hash, independentemente da ordem das chaves
3572
+ */
3569
3573
  static generateMD5(data) {
3570
- if (data === null || data === undefined)
3571
- return Md5.hashStr('null');
3574
+ // Null ou undefined geram um hash fixo
3575
+ if (data === null || data === undefined) {
3576
+ return crypto.createHash('md5').update('null').digest('hex');
3577
+ }
3572
3578
  const normalizedData = this.normalizeData(data);
3573
3579
  const jsonString = JSON.stringify(normalizedData);
3574
- return Md5.hashStr(jsonString);
3580
+ return crypto.createHash('md5').update(jsonString).digest('hex');
3575
3581
  }
3582
+ /**
3583
+ * Normaliza os dados para garantir que a ordem das chaves não afete o resultado
3584
+ */
3576
3585
  static normalizeData(data, depth = 0, maxDepth = 100) {
3577
- if (depth > maxDepth)
3586
+ // Proteção contra recursão infinita
3587
+ if (depth > maxDepth) {
3578
3588
  return '[MAX_DEPTH_REACHED]';
3579
- if (data === null || data === undefined)
3589
+ }
3590
+ // Tipos primitivos retornam diretamente
3591
+ if (data === null || data === undefined) {
3580
3592
  return null;
3581
- if (typeof data !== 'object')
3593
+ }
3594
+ if (typeof data !== 'object') {
3582
3595
  return data;
3583
- if (Array.isArray(data))
3596
+ }
3597
+ // Arrays são normalizados e ordenados
3598
+ if (Array.isArray(data)) {
3584
3599
  return data
3585
3600
  .map((item) => this.normalizeData(item, depth + 1, maxDepth))
3586
3601
  .sort((a, b) => {
3602
+ // Converte para string para comparação determinística
3587
3603
  const strA = typeof a === 'object' && a !== null ? JSON.stringify(a) : String(a);
3588
3604
  const strB = typeof b === 'object' && b !== null ? JSON.stringify(b) : String(b);
3589
3605
  return strA.localeCompare(strB);
3590
3606
  });
3607
+ }
3608
+ // Objetos: ordena as chaves
3591
3609
  const sortedObj = {};
3592
3610
  const keys = Object.keys(data).sort();
3593
3611
  keys.forEach((key) => {
@@ -3598,39 +3616,24 @@ class MD5GeneratorHelper {
3598
3616
  }
3599
3617
  }
3600
3618
 
3601
- class FirestoreCacheKeyGeneratorHelper {
3602
- static generateGetCacheKey(model, identifiers) {
3603
- const sortedEntries = Object.entries(identifiers).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
3604
- const keyParts = [];
3605
- for (const [key, value] of sortedEntries) {
3606
- keyParts.push(`${key}:${value}`);
3607
- }
3608
- return `${model.name.toLowerCase()}:get:${keyParts.join(':')}`;
3609
- }
3610
- static generateFindCacheKey(model, findParams) {
3611
- const md5 = MD5GeneratorHelper.generateMD5(findParams);
3612
- return `${model.name.toLowerCase()}:find:${md5}`;
3613
- }
3614
- }
3615
-
3616
3619
  const withGetFirestore = (MixinBase) => {
3617
3620
  return class GetFirestore extends MixinBase {
3618
- async get(identifiers, options) {
3619
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
3621
+ async get(identifiers) {
3622
+ var _a, _b, _c, _d, _e, _f;
3620
3623
  const logger = this.logger.with('get');
3621
3624
  const collectionName = this.buildCollectionPathForGet(identifiers);
3622
3625
  const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
3623
3626
  const req = { collection: collectionName, data: identifiers };
3624
- 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) {
3625
- const cacheKey = FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(this.model, identifiers);
3627
+ if ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) {
3628
+ const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(this.model, identifiers);
3626
3629
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
3627
3630
  if (cachedData) {
3628
3631
  logger.log({ req, res: 'Dados recuperados do cache', cacheKey });
3629
- return this.model.toInstance(JSON.parse(cachedData));
3632
+ return this.model.toInstance(cachedData);
3630
3633
  }
3631
3634
  }
3632
3635
  try {
3633
- 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 }));
3636
+ 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 }));
3634
3637
  const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
3635
3638
  const docRef = await this.collection(collectionName)
3636
3639
  .getDoc(Object.values(builded.identifier).shift().toString())
@@ -3638,14 +3641,14 @@ const withGetFirestore = (MixinBase) => {
3638
3641
  const data = docRef.data();
3639
3642
  if (isNil(data))
3640
3643
  throw new NotFoundError(`Document '${collectionName}/${Object.values(identifiers).shift()}' not found`);
3641
- 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;
3644
+ 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;
3642
3645
  logger.log({ req, res });
3643
- 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) {
3644
- const cacheKey = FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(this.model, identifiers);
3646
+ if ((_f = this.cache) === null || _f === void 0 ? void 0 : _f.cacheAdapter) {
3647
+ const cacheKey = CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(this.model, identifiers);
3645
3648
  await this.cache.cacheAdapter.set({
3646
3649
  key: cacheKey,
3647
- data: JSON.stringify((res === null || res === void 0 ? void 0 : res.toPlain()) || res),
3648
- expirationInSeconds: ((_j = options === null || options === void 0 ? void 0 : options.cache) === null || _j === void 0 ? void 0 : _j.ttl) || this.cache.ttlDefault,
3650
+ data: res,
3651
+ expirationInSeconds: this.cache.ttlDefault,
3649
3652
  });
3650
3653
  logger.log({ req, message: 'Dados salvos no cache', cacheKey });
3651
3654
  }
@@ -3738,26 +3741,15 @@ const withFindFirestore = (MixinBase) => {
3738
3741
  ]);
3739
3742
  };
3740
3743
  }
3741
- generateCacheKey(findParams) {
3742
- return FirestoreCacheKeyGeneratorHelper.generateFindCacheKey(this.model, findParams);
3743
- }
3744
- async find(find = {}, options) {
3745
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
3744
+ async find(find = {}) {
3745
+ var _a, _b, _c, _d, _e, _f;
3746
3746
  const logger = this.logger.with('find');
3747
- 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) {
3748
- const cacheKey = this.generateCacheKey(find);
3749
- const cachedData = await this.cache.cacheAdapter.get(cacheKey);
3750
- if (cachedData) {
3751
- logger.log(`Dados recuperados do cache: ${cacheKey}`);
3752
- return JSON.parse(cachedData);
3753
- }
3754
- }
3755
3747
  const collectionName = this.buildCollectionPathForFind(find.filters);
3756
3748
  const collection = this.collection(collectionName);
3757
- 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;
3749
+ 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;
3758
3750
  const req = { collection: collectionName, data: find };
3759
3751
  try {
3760
- 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 }));
3752
+ 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 }));
3761
3753
  const { fields, filters, limits, orderBy } = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.find) || find;
3762
3754
  const queries = this.makeFirestoreWhere(filters || {});
3763
3755
  const ordination = this.makeFirestoreOrderBy(filters, orderBy);
@@ -3767,19 +3759,10 @@ const withFindFirestore = (MixinBase) => {
3767
3759
  .getDocs();
3768
3760
  const data = docs.docs.map((doc) => doc.data());
3769
3761
  const res = {
3770
- 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,
3762
+ 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,
3771
3763
  count: enableCount ? this.calculateCount(data, limits) : Infinity,
3772
3764
  };
3773
3765
  logger.log({ req, queries, ordination, offsets, res });
3774
- 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) {
3775
- const cacheKey = this.generateCacheKey(find);
3776
- await this.cache.cacheAdapter.set({
3777
- key: cacheKey,
3778
- data: JSON.stringify(res),
3779
- expirationInSeconds: ((_l = options === null || options === void 0 ? void 0 : options.cache) === null || _l === void 0 ? void 0 : _l.ttl) || this.cache.ttlDefault,
3780
- });
3781
- logger.log(`Dados salvos no cache: ${cacheKey}`);
3782
- }
3783
3766
  return res;
3784
3767
  }
3785
3768
  catch (error) {
@@ -3883,41 +3866,24 @@ const withUpdateFirestore = (MixinBase) => {
3883
3866
  return options === null || options === void 0 ? void 0 : options.value;
3884
3867
  };
3885
3868
  return class UpdateFirestore extends MixinBase {
3886
- getIdentifiersFromData(data) {
3887
- const identifiers = {};
3888
- const model = new this.model();
3889
- const keyField = model.identifiersFields.shift();
3890
- const identifierValue = getValueFromParams(data, keyField);
3891
- identifiers[keyField] = identifierValue;
3892
- return identifiers;
3893
- }
3894
- generateCacheKey(identifiers) {
3895
- return FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(this.model, identifiers);
3896
- }
3897
3869
  async update(data) {
3898
- var _a, _b, _c, _d, _e;
3870
+ var _a, _b, _c, _d;
3899
3871
  const logger = this.logger.with('update');
3900
3872
  const collectionName = this.buildCollectionPathForUpdate(data);
3901
3873
  const model = new this.model();
3902
3874
  const keyField = model.identifiersFields.shift();
3903
3875
  const req = { collection: collectionName, data };
3904
- if ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) {
3905
- const identifiers = this.getIdentifiersFromData(data);
3906
- const cacheKey = this.generateCacheKey(identifiers);
3907
- await this.cache.cacheAdapter.remove(cacheKey);
3908
- logger.log(`Cache removido: ${cacheKey}`);
3909
- }
3910
3876
  try {
3911
3877
  const identifiers = getValueFromParams(data, keyField);
3912
3878
  const docRef = this.collection(collectionName).getDoc(identifiers.toString());
3913
3879
  if (!(await docRef.get()).data())
3914
3880
  throw new NotFoundError(`Document '${collectionName}/${Object.values(identifiers.toString())}' not found`);
3915
3881
  const plainFromData = this.model.toInstance(this.paramsToPlain(data));
3916
- 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 }));
3882
+ 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 }));
3917
3883
  const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || plainFromData;
3918
3884
  await docRef.save(builded.toPlain());
3919
3885
  const docData = await docRef.get();
3920
- 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();
3886
+ 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();
3921
3887
  logger.log({ req, res, identifiers });
3922
3888
  return res;
3923
3889
  }
@@ -3943,25 +3909,17 @@ const withUpdateFirestore = (MixinBase) => {
3943
3909
 
3944
3910
  const withDeleteFirestore = (MixinBase) => {
3945
3911
  return class DeleteFirestore extends MixinBase {
3946
- generateCacheKey(identifiers) {
3947
- return FirestoreCacheKeyGeneratorHelper.generateGetCacheKey(this.model, identifiers);
3948
- }
3949
3912
  async delete(identifiers) {
3950
- var _a, _b, _c, _d, _e;
3913
+ var _a, _b, _c, _d;
3951
3914
  const logger = this.logger.with('delete');
3952
3915
  const collectionName = this.buildCollectionPathForRemove(identifiers);
3953
3916
  const instance = this.model.toInstance(this.model.identifiersFields.reduce((acc, field) => (Object.assign(Object.assign({}, acc), { [field]: identifiers[field] })), {}));
3954
3917
  const req = { collection: collectionName, data: identifiers };
3955
- if ((_a = this.cache) === null || _a === void 0 ? void 0 : _a.cacheAdapter) {
3956
- const cacheKey = this.generateCacheKey(identifiers);
3957
- await this.cache.cacheAdapter.remove(cacheKey);
3958
- logger.log(`Cache removido: ${cacheKey}`);
3959
- }
3960
3918
  try {
3961
- 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 }));
3919
+ 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 }));
3962
3920
  const builded = (intercepted === null || intercepted === void 0 ? void 0 : intercepted.instance) || instance;
3963
3921
  await this.collection(collectionName).getDoc(Object.values(builded.identifier).shift().toString()).delete();
3964
- await ((_e = (_d = this.interceptors) === null || _d === void 0 ? void 0 : _d.response) === null || _e === void 0 ? void 0 : _e.call(_d, instance, intercepted));
3922
+ await ((_d = (_c = this.interceptors) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.call(_c, instance, intercepted));
3965
3923
  logger.log({ req, res: undefined });
3966
3924
  }
3967
3925
  catch (error) {
@@ -4206,13 +4164,12 @@ class SequenceFirestoreRepository extends withCrudFirestore(withHelpers(withFire
4206
4164
  }
4207
4165
 
4208
4166
  class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4209
- constructor({ firestore, interceptors, cache, }) {
4167
+ constructor({ firestore, interceptors }) {
4210
4168
  super({
4211
4169
  firestore,
4212
4170
  collectionName: 'dms',
4213
4171
  model: Home,
4214
4172
  interceptors,
4215
- cache,
4216
4173
  });
4217
4174
  this.homeCategoryGroupToPlain = (homeCategoryGroup) => {
4218
4175
  var _a, _b, _c;
@@ -4269,97 +4226,89 @@ class HomeFirestoreRepository extends withCrudFirestore(withHelpers(withFirestor
4269
4226
  }
4270
4227
 
4271
4228
  class ShopMenuFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4272
- constructor({ firestore, interceptors, cache, }) {
4229
+ constructor({ firestore, interceptors }) {
4273
4230
  super({
4274
4231
  firestore,
4275
4232
  collectionName: 'shopMenus',
4276
4233
  model: ShopMenu,
4277
4234
  interceptors,
4278
- cache,
4279
4235
  });
4280
4236
  }
4281
4237
  }
4282
4238
 
4283
4239
  class ShopSettingsFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4284
- constructor({ firestore, interceptors, cache, }) {
4240
+ constructor({ firestore, interceptors, }) {
4285
4241
  super({
4286
4242
  firestore,
4287
4243
  collectionName: 'shopSettings',
4288
4244
  model: ShopSettings,
4289
4245
  interceptors,
4290
- cache,
4291
4246
  });
4292
4247
  }
4293
4248
  }
4294
4249
 
4295
4250
  class Buy2WinFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4296
- constructor({ firestore, interceptors, cache, }) {
4251
+ constructor({ firestore, interceptors }) {
4297
4252
  super({
4298
4253
  firestore,
4299
4254
  collectionName: 'buy2win',
4300
4255
  model: Buy2Win,
4301
4256
  interceptors,
4302
- cache,
4303
4257
  });
4304
4258
  }
4305
4259
  }
4306
4260
 
4307
4261
  class CampaignDashboardFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4308
- constructor({ firestore, interceptors, cache, }) {
4262
+ constructor({ firestore, interceptors, }) {
4309
4263
  super({
4310
4264
  firestore,
4311
4265
  collectionName: 'dashboardCampaignsAuto',
4312
4266
  model: CampaignDashboard,
4313
4267
  interceptors,
4314
- cache,
4315
4268
  });
4316
4269
  }
4317
4270
  }
4318
4271
 
4319
4272
  class CampaignHashtagFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4320
- constructor({ firestore, interceptors, cache, }) {
4273
+ constructor({ firestore, interceptors, }) {
4321
4274
  super({
4322
4275
  firestore,
4323
4276
  collectionName: 'hashtagCampaignsAuto',
4324
4277
  model: CampaignHashtag,
4325
4278
  interceptors,
4326
- cache,
4327
4279
  });
4328
4280
  }
4329
4281
  }
4330
4282
 
4331
4283
  class CheckoutFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4332
- constructor({ firestore, interceptors, cache, }) {
4284
+ constructor({ firestore, interceptors }) {
4333
4285
  super({
4334
4286
  firestore,
4335
4287
  collectionName: 'checkouts',
4336
4288
  model: Checkout,
4337
4289
  interceptors,
4338
- cache,
4339
4290
  });
4340
4291
  }
4341
4292
  }
4342
4293
 
4343
4294
  class CheckoutSubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4344
- constructor({ firestore, interceptors, cache, }) {
4295
+ constructor({ firestore, interceptors, }) {
4345
4296
  super({
4346
4297
  firestore,
4347
4298
  collectionName: 'checkoutsSubscription',
4348
4299
  model: CheckoutSubscription,
4349
4300
  interceptors,
4350
- cache,
4351
4301
  });
4352
4302
  }
4353
4303
  }
4354
4304
 
4355
4305
  class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4356
- constructor({ firestore, interceptors, cache, }) {
4306
+ constructor({ firestore, interceptors }) {
4357
4307
  super({
4358
4308
  firestore,
4359
4309
  collectionName: 'coupons',
4360
4310
  model: Coupon,
4361
4311
  interceptors,
4362
- cache,
4363
4312
  });
4364
4313
  }
4365
4314
  buildModelInstance() {
@@ -4382,13 +4331,12 @@ class CouponFirestoreRepository extends withCrudFirestore(withHelpers(withFirest
4382
4331
  }
4383
4332
 
4384
4333
  class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4385
- constructor({ firestore, interceptors, cache, }) {
4334
+ constructor({ firestore, interceptors }) {
4386
4335
  super({
4387
4336
  firestore,
4388
4337
  collectionName: 'orders',
4389
4338
  model: Order,
4390
4339
  interceptors,
4391
- cache,
4392
4340
  fields: {
4393
4341
  status: FirestoreFieldType.String,
4394
4342
  },
@@ -4420,24 +4368,22 @@ class OrderFirestoreRepository extends withCrudFirestore(withHelpers(withFiresto
4420
4368
  }
4421
4369
 
4422
4370
  class LegacyOrderFirestoreRepository extends OrderFirestoreRepository {
4423
- constructor({ firestore, interceptors, cache, }) {
4371
+ constructor({ firestore, interceptors }) {
4424
4372
  super({
4425
4373
  firestore,
4426
4374
  interceptors,
4427
- cache,
4428
4375
  });
4429
4376
  this.collectionName = 'legacyOrders';
4430
4377
  }
4431
4378
  }
4432
4379
 
4433
4380
  class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4434
- constructor({ firestore, interceptors, cache, }) {
4381
+ constructor({ firestore, interceptors, }) {
4435
4382
  super({
4436
4383
  firestore,
4437
4384
  collectionName: 'paymentBlockedAttempts',
4438
4385
  model: OrderBlocked,
4439
4386
  interceptors,
4440
- cache,
4441
4387
  });
4442
4388
  }
4443
4389
  async createBlockedOrderOrPayment(checkout, blockType, type, limiteRange, card = null) {
@@ -4469,141 +4415,130 @@ class OrderBlockedFirestoreRepository extends withCrudFirestore(withHelpers(with
4469
4415
  }
4470
4416
 
4471
4417
  class PaymentFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4472
- constructor({ firestore, interceptors, cache, }) {
4418
+ constructor({ firestore, interceptors }) {
4473
4419
  super({
4474
4420
  firestore,
4475
4421
  collectionName: 'payments',
4476
4422
  model: Payment,
4477
4423
  interceptors,
4478
- cache,
4479
4424
  });
4480
4425
  }
4481
4426
  }
4482
4427
 
4483
4428
  class SubscriptionPlanFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4484
- constructor({ firestore, interceptors, cache, }) {
4429
+ constructor({ firestore, interceptors, }) {
4485
4430
  super({
4486
4431
  firestore,
4487
4432
  collectionName: 'subscriptionPlans',
4488
4433
  model: SubscriptionPlan,
4489
4434
  interceptors,
4490
- cache,
4491
4435
  });
4492
4436
  }
4493
4437
  }
4494
4438
 
4495
4439
  class LeadFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4496
- constructor({ firestore, interceptors, cache, }) {
4440
+ constructor({ firestore, interceptors }) {
4497
4441
  super({
4498
4442
  firestore,
4499
4443
  collectionName: 'leads',
4500
4444
  model: Lead,
4501
4445
  interceptors,
4502
- cache,
4503
4446
  });
4504
4447
  }
4505
4448
  }
4506
4449
 
4507
4450
  class SubscriptionEditionFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4508
- constructor({ firestore, interceptors, cache, }, parentRepository) {
4451
+ constructor({ firestore, interceptors }, parentRepository) {
4509
4452
  super({
4510
4453
  firestore,
4511
4454
  collectionName: 'editions',
4512
4455
  parentIdField: 'subscriptionId',
4513
4456
  model: Edition,
4514
4457
  interceptors,
4515
- cache,
4516
4458
  });
4517
4459
  this.parentRepository = parentRepository;
4518
4460
  }
4519
4461
  }
4520
4462
 
4521
4463
  class SubscriptionFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4522
- constructor({ firestore, interceptors, cache, }) {
4464
+ constructor({ firestore, interceptors, }) {
4523
4465
  super({
4524
4466
  firestore,
4525
4467
  collectionName: 'subscription',
4526
4468
  model: Subscription,
4527
4469
  interceptors,
4528
- cache,
4529
4470
  });
4530
4471
  }
4531
4472
  }
4532
4473
 
4533
4474
  class SubscriptionMaterializationFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4534
- constructor({ firestore, interceptors, cache, }) {
4475
+ constructor({ firestore, interceptors }) {
4535
4476
  super({
4536
4477
  firestore,
4537
4478
  collectionName: 'subscriptionMaterialization',
4538
4479
  model: SubscriptionMaterialization,
4539
4480
  interceptors,
4540
- cache,
4541
4481
  });
4542
4482
  }
4543
4483
  }
4544
4484
 
4545
4485
  class SubscriptionPaymentFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4546
- constructor({ firestore, interceptors, cache, }, parentRepository) {
4486
+ constructor({ firestore, interceptors }, parentRepository) {
4547
4487
  super({
4548
4488
  firestore,
4549
4489
  collectionName: 'payments',
4550
4490
  parentIdField: 'subscriptionId',
4551
4491
  model: SubscriptionPayment,
4552
4492
  interceptors,
4553
- cache,
4554
4493
  });
4555
4494
  this.parentRepository = parentRepository;
4556
4495
  }
4557
4496
  }
4558
4497
 
4559
4498
  class SubscriptionSummaryFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4560
- constructor({ firestore, interceptors, cache, }) {
4499
+ constructor({ firestore, interceptors, }) {
4561
4500
  super({
4562
4501
  firestore,
4563
4502
  collectionName: 'subscriptionSummary',
4564
4503
  model: SubscriptionSummary,
4565
4504
  interceptors,
4566
- cache,
4567
4505
  });
4568
4506
  }
4569
4507
  }
4570
4508
 
4571
4509
  class UserAddressFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4572
- constructor({ firestore, interceptors, cache, }, parentRepository) {
4510
+ constructor({ firestore, interceptors }, parentRepository) {
4573
4511
  super({
4574
4512
  firestore,
4575
4513
  collectionName: 'address',
4576
4514
  parentIdField: 'userId',
4577
4515
  model: UserAddress,
4578
4516
  interceptors,
4579
- cache,
4580
4517
  });
4581
4518
  this.parentRepository = parentRepository;
4582
4519
  }
4583
4520
  }
4584
4521
 
4585
4522
  class UserBeautyProfileFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4586
- constructor({ firestore, interceptors, cache, }, parentRepository) {
4523
+ constructor({ firestore, interceptors }, parentRepository) {
4587
4524
  super({
4588
4525
  firestore,
4589
4526
  collectionName: 'CX',
4590
4527
  parentIdField: 'userId',
4591
4528
  model: BeautyProfile,
4592
4529
  interceptors,
4593
- cache,
4594
4530
  });
4595
4531
  this.parentRepository = parentRepository;
4596
4532
  }
4597
4533
  }
4598
4534
 
4599
4535
  class UserFirestoreRepository extends withCrudFirestore(withHelpers(withFirestore(Base))) {
4600
- constructor({ firestore, interceptors, cache, }) {
4536
+ constructor({ firestore, interceptors }) {
4601
4537
  super({
4602
4538
  firestore,
4603
4539
  collectionName: 'users',
4604
4540
  model: User,
4605
4541
  interceptors,
4606
- cache,
4607
4542
  });
4608
4543
  }
4609
4544
  async get(identifiers) {
@@ -4663,14 +4598,13 @@ __decorate([
4663
4598
  ], UserFirestoreRepository.prototype, "checkIfExistsByField", null);
4664
4599
 
4665
4600
  class UserPaymentMethodFirestoreRepository extends withSubCollection(withCrudFirestore(withHelpers(withFirestore(Base)))) {
4666
- constructor({ firestore, interceptors, cache, }, parentRepository) {
4601
+ constructor({ firestore, interceptors }, parentRepository) {
4667
4602
  super({
4668
4603
  firestore,
4669
4604
  collectionName: 'payment_method',
4670
4605
  parentIdField: 'userId',
4671
4606
  model: UserPaymentMethod,
4672
4607
  interceptors,
4673
- cache,
4674
4608
  });
4675
4609
  this.parentRepository = parentRepository;
4676
4610
  }
@@ -5089,7 +5023,7 @@ const withGetHasuraGraphQL = (MixinBase) => {
5089
5023
  return CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(this.model, identifiers);
5090
5024
  }
5091
5025
  async get(identifiers, options) {
5092
- var _a, _b, _c, _d, _e;
5026
+ var _a, _b, _c, _d;
5093
5027
  this.logger = DebugHelper.from(this, 'get');
5094
5028
  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)) {
5095
5029
  const cacheKey = this.generateCacheKey(identifiers);
@@ -5123,7 +5057,7 @@ const withGetHasuraGraphQL = (MixinBase) => {
5123
5057
  await this.cache.cacheAdapter.set({
5124
5058
  key: cacheKey,
5125
5059
  data: JSON.stringify(resultModel.toPlain()),
5126
- expirationInSeconds: ((_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl) || this.cache.ttlDefault,
5060
+ expirationInSeconds: this.cache.ttlDefault,
5127
5061
  });
5128
5062
  this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5129
5063
  }
@@ -5176,19 +5110,19 @@ const withFindHasuraGraphQL = (MixinBase) => {
5176
5110
  });
5177
5111
  }
5178
5112
  async find(params, options) {
5179
- var _a, _b, _c, _d, _e, _f, _g, _h;
5113
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
5180
5114
  this.logger = DebugHelper.from(this, 'find');
5181
- const { filters, limits, orderBy, options: findOptions } = params || {};
5182
- const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
5183
- const enableCount = (_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _a !== void 0 ? _a : true;
5184
- if (((_b = this.cache) === null || _b === void 0 ? void 0 : _b.cacheAdapter) && ((_c = options === null || options === void 0 ? void 0 : options.cache) === null || _c === void 0 ? void 0 : _c.enabled)) {
5115
+ 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)) {
5185
5116
  const cacheKey = generateCacheKey(this.model, params);
5186
5117
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
5187
5118
  if (cachedData) {
5188
5119
  this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
5189
- return this.bindResult(JSON.parse(cachedData), { enableCount, findOptions, tableFiltersNamed });
5120
+ return JSON.parse(cachedData);
5190
5121
  }
5191
5122
  }
5123
+ const { filters, limits, orderBy, options: findOptions } = params || {};
5124
+ const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
5125
+ const enableCount = (_c = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _c !== void 0 ? _c : true;
5192
5126
  const variablesFilters = isNil(filters)
5193
5127
  ? {}
5194
5128
  : {
@@ -5259,42 +5193,38 @@ const withFindHasuraGraphQL = (MixinBase) => {
5259
5193
  }))) ||
5260
5194
  []),
5261
5195
  ]);
5262
- if (((_f = this.cache) === null || _f === void 0 ? void 0 : _f.cacheAdapter) && ((_g = options === null || options === void 0 ? void 0 : options.cache) === null || _g === void 0 ? void 0 : _g.enabled)) {
5263
- const cacheKey = generateCacheKey(this.model, params);
5264
- await this.cache.cacheAdapter.set({
5265
- key: cacheKey,
5266
- data: JSON.stringify(result),
5267
- expirationInSeconds: ((_h = options === null || options === void 0 ? void 0 : options.cache) === null || _h === void 0 ? void 0 : _h.ttl) || this.cache.ttlDefault,
5268
- });
5269
- this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5270
- }
5271
- return this.bindResult(result, { enableCount, findOptions, tableFiltersNamed });
5272
- }
5273
- bindResult(result, { enableCount, findOptions, tableFiltersNamed, }) {
5274
- var _a, _b, _c, _d;
5275
5196
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
5276
- const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_a = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _a === void 0 ? void 0 : _a.length)
5197
+ const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_f = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _f === void 0 ? void 0 : _f.length)
5277
5198
  ? {
5278
5199
  minimal: findOptions.minimal.reduce((minimals, current) => {
5279
5200
  var _a;
5280
5201
  return (Object.assign(Object.assign({}, minimals), set(minimals, current, result[`${this.tableName}_aggregate`].aggregate.min[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
5281
5202
  }, {}),
5282
5203
  }
5283
- : {})), (((_b = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _b === void 0 ? void 0 : _b.length)
5204
+ : {})), (((_g = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _g === void 0 ? void 0 : _g.length)
5284
5205
  ? {
5285
5206
  maximum: findOptions.maximum.reduce((maximums, current) => {
5286
5207
  var _a;
5287
5208
  return (Object.assign(Object.assign({}, maximums), set(maximums, current, result[`${this.tableName}_aggregate`].aggregate.max[((_a = AttributeOptionHelper.FindByAttribute(current.toString().split('.').pop(), this.fields)) === null || _a === void 0 ? void 0 : _a.columnName) || current])));
5288
5209
  }, {}),
5289
5210
  }
5290
- : {})), (((_c = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _c === void 0 ? void 0 : _c.length) && {
5291
- distinct: (_d = this.lastDistinct[tableFiltersNamed]) !== null && _d !== void 0 ? _d : (this.lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
5211
+ : {})), (((_h = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _h === void 0 ? void 0 : _h.length) && {
5212
+ distinct: (_j = this.lastDistinct[tableFiltersNamed]) !== null && _j !== void 0 ? _j : (this.lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
5292
5213
  var _a, _b;
5293
5214
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
5294
5215
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
5295
5216
  return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
5296
5217
  }, {})),
5297
5218
  }));
5219
+ if (((_k = this.cache) === null || _k === void 0 ? void 0 : _k.cacheAdapter) && ((_l = options === null || options === void 0 ? void 0 : options.cache) === null || _l === void 0 ? void 0 : _l.enabled)) {
5220
+ const cacheKey = generateCacheKey(this.model, params);
5221
+ await this.cache.cacheAdapter.set({
5222
+ key: cacheKey,
5223
+ data: JSON.stringify(findResult),
5224
+ expirationInSeconds: this.cache.ttlDefault,
5225
+ });
5226
+ this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5227
+ }
5298
5228
  return findResult;
5299
5229
  }
5300
5230
  };
@@ -5337,7 +5267,7 @@ __decorate([
5337
5267
  ], ProductErrorsHasuraGraphQL.prototype, "product", void 0);
5338
5268
 
5339
5269
  class CategoryCollectionChildrenHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5340
- constructor({ endpoint, authOptions, interceptors, cache, }) {
5270
+ constructor({ endpoint, authOptions, interceptors, }) {
5341
5271
  super({
5342
5272
  tableName: 'category_collection_children',
5343
5273
  model: CategoryCollectionChildren,
@@ -5368,13 +5298,12 @@ class CategoryCollectionChildrenHasuraGraphQLRepository extends withCrudHasuraGr
5368
5298
  },
5369
5299
  },
5370
5300
  ],
5371
- cache,
5372
5301
  });
5373
5302
  }
5374
5303
  }
5375
5304
 
5376
5305
  class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5377
- constructor({ endpoint, authOptions, interceptors, cache, }) {
5306
+ constructor({ endpoint, authOptions, interceptors, }) {
5378
5307
  super({
5379
5308
  tableName: 'category_filter',
5380
5309
  model: CategoryFilter,
@@ -5456,7 +5385,6 @@ class CategoryFilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHa
5456
5385
  },
5457
5386
  },
5458
5387
  ],
5459
- cache,
5460
5388
  });
5461
5389
  }
5462
5390
  deleteByCategory(categoryId) {
@@ -5596,17 +5524,6 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5596
5524
  });
5597
5525
  this.productRepository = productRepository;
5598
5526
  this.categoryFilterRepository = categoryFilterRepository;
5599
- this.reorganizeMostRelevantsProducts = (products, mostRelevantsIds, limit) => {
5600
- const mostRelevantWithouyStock = products.filter((product) => mostRelevantsIds.includes(product.id) && product.stock.quantity <= 0);
5601
- const firstProducts = products
5602
- .filter((product) => mostRelevantsIds.includes(product.id) && product.stock.quantity > 0)
5603
- .sort((a, b) => mostRelevantsIds.indexOf(a.id) - mostRelevantsIds.indexOf(b.id));
5604
- const lastProducts = products
5605
- .filter((product) => !mostRelevantsIds.includes(product.id) && product.stock.quantity > 0)
5606
- .concat(mostRelevantWithouyStock);
5607
- const categoryMostRelevants = firstProducts.concat(lastProducts);
5608
- return limit ? categoryMostRelevants.slice(0, limit) : categoryMostRelevants;
5609
- };
5610
5527
  }
5611
5528
  async create(params) {
5612
5529
  const { images, mostRelevants, metadatas } = params, data = __rest(params, ["images", "mostRelevants", "metadatas"]);
@@ -5626,12 +5543,11 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5626
5543
  },
5627
5544
  } }));
5628
5545
  }
5629
- async get(identifiers, optionsCache) {
5546
+ async get(identifiers) {
5630
5547
  var _a;
5631
5548
  return Number.isNaN(+identifiers.id)
5632
- ? (_a = (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, optionsCache))
5633
- .data) === null || _a === void 0 ? void 0 : _a[0]
5634
- : super.get(identifiers, optionsCache);
5549
+ ? (_a = (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })).data) === null || _a === void 0 ? void 0 : _a[0]
5550
+ : super.get(identifiers);
5635
5551
  }
5636
5552
  async update(params) {
5637
5553
  const { products, id: checkId, metadatas, filters } = params, data = __rest(params, ["products", "id", "metadatas", "filters"]);
@@ -5643,7 +5559,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5643
5559
  category.filters = filters && (await this.updateFilters(+id, { filters }));
5644
5560
  return category;
5645
5561
  }
5646
- async getCategoryBySlug(slug, shop, optionsCache) {
5562
+ async getCategoryBySlug(slug, shop) {
5647
5563
  if (!slug)
5648
5564
  return null;
5649
5565
  const { data } = await this.find({
@@ -5655,14 +5571,14 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5655
5571
  options: {
5656
5572
  enableCount: false,
5657
5573
  },
5658
- }, optionsCache);
5574
+ });
5659
5575
  if (!data.length)
5660
5576
  throw new NotFoundError(`Category with slug ${slug} not found`);
5661
5577
  if (data.length > 1)
5662
5578
  throw new DuplicatedResultsError('Query returned duplicated values');
5663
5579
  return data.shift();
5664
5580
  }
5665
- async getCategoryByShop(shop, optionsCache) {
5581
+ async getCategoryByShop(shop) {
5666
5582
  if (!shop)
5667
5583
  return;
5668
5584
  const { data } = await this.find({
@@ -5674,10 +5590,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5674
5590
  options: {
5675
5591
  enableCount: false,
5676
5592
  },
5677
- }, optionsCache);
5593
+ });
5678
5594
  return data;
5679
5595
  }
5680
- async getCategoriesForHome(categoryIds, shop, limit = 4, optionsCache) {
5596
+ async getCategoriesForHome(categoryIds, shop, limit = 4) {
5681
5597
  if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
5682
5598
  return [];
5683
5599
  const categoriesFirestore = categoryIds.filter((categoryId) => Number.isNaN(+categoryId));
@@ -5685,91 +5601,83 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5685
5601
  const categories = [];
5686
5602
  if (categoriesFirestore.length)
5687
5603
  categories.push(...(await this.find({
5688
- filters: {
5689
- firestoreId: { operator: Where.IN, value: categoriesFirestore.filter(Boolean) },
5690
- published: true,
5691
- },
5692
- }, optionsCache).then(({ data }) => data)));
5604
+ filters: { firestoreId: { operator: Where.IN, value: categoriesFirestore.filter(Boolean) }, published: true },
5605
+ }).then(({ data }) => data)));
5693
5606
  if (categoriesHasura.length)
5694
5607
  categories.push(...(await this.find({
5695
5608
  filters: {
5696
5609
  id: { operator: Where.IN, value: categoriesHasura.filter(Boolean) },
5697
5610
  published: true,
5698
5611
  },
5699
- }, optionsCache).then(({ data }) => data)));
5612
+ }).then(({ data }) => data)));
5700
5613
  if (!categories.length)
5701
5614
  return [];
5702
5615
  const homeSections = await Promise.all(categories.map(async (category) => ({
5703
5616
  category,
5704
- products: await this.mountCategory(category, shop, { limit, hasStock: true }, optionsCache),
5617
+ products: await this.mountCategory(category, shop, { limit, hasStock: true }),
5705
5618
  })));
5706
5619
  return homeSections;
5707
5620
  }
5708
- async mountCategory(category, shop, options, optionsCache) {
5621
+ async mountCategory(category, shop, options) {
5709
5622
  var _a;
5710
5623
  if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
5711
5624
  return [];
5712
- const fields = [
5713
- 'id',
5714
- 'name',
5715
- 'slug',
5716
- 'images',
5717
- 'miniatures',
5718
- 'price',
5719
- 'fullPrice',
5720
- 'subscriberDiscountPercentage',
5721
- 'subscriberPrice',
5722
- 'stock',
5723
- 'published',
5724
- 'CEST',
5725
- 'EAN',
5726
- 'NCM',
5727
- 'brand',
5728
- 'costPrice',
5729
- 'hasVariants',
5730
- 'isKit',
5731
- 'sku',
5732
- 'rate',
5733
- 'tags',
5734
- 'type',
5735
- 'shoppingCount',
5736
- 'gender',
5737
- 'createdAt',
5738
- ];
5625
+ const mostRelevants = category.getMostRelevantByShop(shop);
5626
+ const mostRelevantProductsIds = [...new Set(mostRelevants.concat(category.products))];
5739
5627
  const products = [];
5740
- const mostRelevantsIds = category.getMostRelevantByShop(shop);
5741
- if (mostRelevantsIds === null || mostRelevantsIds === void 0 ? void 0 : mostRelevantsIds.length) {
5742
- const { data: mostRelevants } = await this.productRepository.findCatalog({
5743
- filters: Object.assign({ id: {
5744
- operator: Where.IN,
5745
- value: mostRelevantsIds,
5746
- }, published: true }, (options.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})),
5747
- fields,
5748
- options: { enableCount: false },
5749
- orderBy: {
5750
- stock: 'desc',
5751
- shoppingCount: 'desc',
5752
- rate: 'desc',
5753
- name: 'asc',
5754
- },
5755
- }, shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5756
- if (mostRelevants.length >= mostRelevantsIds.length)
5757
- return this.reorganizeMostRelevantsProducts(mostRelevants, mostRelevantsIds, options.limit);
5758
- products.push(...mostRelevants);
5759
- }
5760
- const productIds = category.products.filter((productId) => !mostRelevantsIds.includes(productId));
5761
- const { data: productsData } = await this.productRepository.findCatalog(Object.assign(Object.assign({ filters: Object.assign({ id: {
5762
- operator: Where.IN,
5763
- value: productIds,
5764
- }, published: true }, (options.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
5765
- stock: 'desc',
5628
+ const { data: productsData } = await this.productRepository.findCatalog({
5629
+ filters: {
5630
+ id: { operator: Where.IN, value: mostRelevantProductsIds },
5631
+ published: true,
5632
+ },
5633
+ fields: [
5634
+ 'id',
5635
+ 'name',
5636
+ 'slug',
5637
+ 'images',
5638
+ 'miniatures',
5639
+ 'price',
5640
+ 'fullPrice',
5641
+ 'subscriberDiscountPercentage',
5642
+ 'subscriberPrice',
5643
+ 'stock',
5644
+ 'published',
5645
+ 'CEST',
5646
+ 'EAN',
5647
+ 'NCM',
5648
+ 'brand',
5649
+ 'costPrice',
5650
+ 'hasVariants',
5651
+ 'isKit',
5652
+ 'sku',
5653
+ 'rate',
5654
+ 'tags',
5655
+ 'type',
5656
+ 'shoppingCount',
5657
+ 'gender',
5658
+ 'createdAt',
5659
+ ],
5660
+ options: { enableCount: false },
5661
+ orderBy: {
5766
5662
  shoppingCount: 'desc',
5767
5663
  rate: 'desc',
5664
+ stock: 'desc',
5768
5665
  name: 'asc',
5769
- } }), shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5770
- return this.reorganizeMostRelevantsProducts([...products, ...productsData], mostRelevantsIds, options.limit);
5771
- }
5772
- async getChildren(parentId, _optionsCache) {
5666
+ },
5667
+ }, shop === Shops.MENSMARKET ? 'male' : 'female');
5668
+ const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
5669
+ const firstProducts = productsData
5670
+ .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
5671
+ .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
5672
+ const lastProducts = productsData
5673
+ .filter((product) => !mostRelevants.includes(product.id) && product.stock.quantity > 0)
5674
+ .concat(mostRelevantWithouyStock);
5675
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
5676
+ const resultFinal = categoryMostRelevants.slice(0, options.limit);
5677
+ products.push(...resultFinal);
5678
+ return products;
5679
+ }
5680
+ async getChildren(parentId) {
5773
5681
  const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference', 'published', 'shops'], {
5774
5682
  args: {
5775
5683
  type: 'category_tree_args',
@@ -5907,31 +5815,31 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5907
5815
  __decorate([
5908
5816
  Log(),
5909
5817
  __metadata("design:type", Function),
5910
- __metadata("design:paramtypes", [String, String, Object]),
5818
+ __metadata("design:paramtypes", [String, String]),
5911
5819
  __metadata("design:returntype", Promise)
5912
5820
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoryBySlug", null);
5913
5821
  __decorate([
5914
5822
  Log(),
5915
5823
  __metadata("design:type", Function),
5916
- __metadata("design:paramtypes", [String, Object]),
5824
+ __metadata("design:paramtypes", [String]),
5917
5825
  __metadata("design:returntype", Promise)
5918
5826
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
5919
5827
  __decorate([
5920
5828
  Log(),
5921
5829
  __metadata("design:type", Function),
5922
- __metadata("design:paramtypes", [Array, String, Object, Object]),
5830
+ __metadata("design:paramtypes", [Array, String, Object]),
5923
5831
  __metadata("design:returntype", Promise)
5924
5832
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
5925
5833
  __decorate([
5926
5834
  Log(),
5927
5835
  __metadata("design:type", Function),
5928
- __metadata("design:paramtypes", [Category, String, Object, Object]),
5836
+ __metadata("design:paramtypes", [Category, String, Object]),
5929
5837
  __metadata("design:returntype", Promise)
5930
5838
  ], CategoryHasuraGraphQLRepository.prototype, "mountCategory", null);
5931
5839
  __decorate([
5932
5840
  Log(),
5933
5841
  __metadata("design:type", Function),
5934
- __metadata("design:paramtypes", [Number, Object]),
5842
+ __metadata("design:paramtypes", [Number]),
5935
5843
  __metadata("design:returntype", Promise)
5936
5844
  ], CategoryHasuraGraphQLRepository.prototype, "getChildren", null);
5937
5845
  __decorate([
@@ -5942,7 +5850,7 @@ __decorate([
5942
5850
  ], CategoryHasuraGraphQLRepository.prototype, "isChild", null);
5943
5851
 
5944
5852
  class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5945
- constructor({ endpoint, authOptions, interceptors, cache, }) {
5853
+ constructor({ endpoint, authOptions, interceptors, }) {
5946
5854
  super({
5947
5855
  tableName: 'category_product',
5948
5856
  model: CategoryProduct,
@@ -5950,7 +5858,6 @@ class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withH
5950
5858
  authOptions,
5951
5859
  interceptors,
5952
5860
  fields: [{ productId: { columnName: 'product_id' } }, { categoryId: { columnName: 'category_id' } }, 'order'],
5953
- cache,
5954
5861
  });
5955
5862
  }
5956
5863
  async removeProductFromCategory(categoryId, productId) {
@@ -5977,7 +5884,7 @@ class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withH
5977
5884
  }
5978
5885
 
5979
5886
  class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5980
- constructor({ endpoint, authOptions, interceptors, cache, }, filterOptionRepository, categoryFilterRepository) {
5887
+ constructor({ endpoint, authOptions, interceptors, }, filterOptionRepository, categoryFilterRepository) {
5981
5888
  super({
5982
5889
  tableName: 'filter',
5983
5890
  model: Filter,
@@ -6017,7 +5924,6 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
6017
5924
  },
6018
5925
  },
6019
5926
  ],
6020
- cache,
6021
5927
  });
6022
5928
  this.filterOptionRepository = filterOptionRepository;
6023
5929
  this.categoryFilterRepository = categoryFilterRepository;
@@ -6104,7 +6010,7 @@ __decorate([
6104
6010
  ], FilterHasuraGraphQLRepository.prototype, "deleteOptions", null);
6105
6011
 
6106
6012
  class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6107
- constructor({ endpoint, authOptions, interceptors, cache, }) {
6013
+ constructor({ endpoint, authOptions, interceptors, }) {
6108
6014
  super({
6109
6015
  tableName: 'filter_option',
6110
6016
  model: FilterOption,
@@ -6118,20 +6024,18 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
6118
6024
  { createdAt: { columnName: 'created_at' } },
6119
6025
  { updatedAt: { columnName: 'updated_at' } },
6120
6026
  ],
6121
- cache,
6122
6027
  });
6123
6028
  }
6124
6029
  }
6125
6030
 
6126
6031
  class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6127
- constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
6032
+ constructor({ endpoint, authOptions, interceptors, }, productRepository) {
6128
6033
  super({
6129
6034
  tableName: 'product_errors',
6130
6035
  model: ProductErrorsHasuraGraphQL,
6131
6036
  endpoint,
6132
6037
  authOptions,
6133
6038
  interceptors,
6134
- cache,
6135
6039
  fields: [
6136
6040
  {
6137
6041
  productId: {
@@ -6845,7 +6749,7 @@ __decorate([
6845
6749
  ], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
6846
6750
 
6847
6751
  class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6848
- constructor({ endpoint, authOptions, interceptors, cache, }) {
6752
+ constructor({ endpoint, authOptions, interceptors, }) {
6849
6753
  super({
6850
6754
  tableName: 'product_review',
6851
6755
  model: ProductReview,
@@ -6869,7 +6773,6 @@ class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
6869
6773
  { createdAt: { columnName: 'created_at' } },
6870
6774
  { updatedAt: { columnName: 'updated_at' } },
6871
6775
  ],
6872
- cache,
6873
6776
  });
6874
6777
  }
6875
6778
  async updateManyStatus(reviews) {
@@ -6911,14 +6814,13 @@ __decorate([
6911
6814
  ], ProductReviewHasuraGraphQLRepository.prototype, "disaproveReview", null);
6912
6815
 
6913
6816
  class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6914
- constructor({ endpoint, authOptions, interceptors, cache, }) {
6817
+ constructor({ endpoint, authOptions, interceptors, }) {
6915
6818
  super({
6916
6819
  tableName: 'product_stock_notification',
6917
6820
  model: ProductStockNotification,
6918
6821
  endpoint,
6919
6822
  authOptions,
6920
6823
  interceptors,
6921
- cache,
6922
6824
  fields: [
6923
6825
  'id',
6924
6826
  { productId: { columnName: 'product_id' } },
@@ -6973,14 +6875,13 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
6973
6875
  }
6974
6876
 
6975
6877
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6976
- constructor({ endpoint, authOptions, interceptors, cache, }) {
6878
+ constructor({ endpoint, authOptions, interceptors, }) {
6977
6879
  super({
6978
6880
  tableName: 'product',
6979
6881
  model: VariantHasuraGraphQL,
6980
6882
  endpoint,
6981
6883
  authOptions,
6982
6884
  interceptors,
6983
- cache,
6984
6885
  fields: [
6985
6886
  { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
6986
6887
  { firestoreId: { columnName: 'firestore_id' } },
@@ -7087,14 +6988,13 @@ class WishlistHasuraGraphQL extends Wishlist {
7087
6988
  }
7088
6989
 
7089
6990
  class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
7090
- constructor({ endpoint, authOptions, interceptors, cache, }, categoryProductRepository) {
6991
+ constructor({ endpoint, authOptions, interceptors, }, categoryProductRepository) {
7091
6992
  super({
7092
6993
  tableName: 'category',
7093
6994
  model: WishlistHasuraGraphQL,
7094
6995
  endpoint,
7095
6996
  authOptions,
7096
6997
  interceptors,
7097
- cache,
7098
6998
  fields: [
7099
6999
  { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
7100
7000
  { firestoreId: { columnName: 'firestore_id' } },