@infrab4a/connect 4.25.0-beta.13 → 4.25.0-beta.3

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 (43) hide show
  1. package/index.cjs.js +171 -274
  2. package/index.esm.js +152 -274
  3. package/package.json +1 -1
  4. package/src/infra/firebase/firestore/mixins/with-helpers.mixin.d.ts +1 -1
  5. package/src/infra/firebase/firestore/repositories/shop-settings/home-firestore.repository.d.ts +1 -1
  6. package/src/infra/firebase/firestore/repositories/shop-settings/shop-menu-firestore.repository.d.ts +1 -1
  7. package/src/infra/firebase/firestore/repositories/shop-settings/shop-settings-firestore.repository.d.ts +1 -1
  8. package/src/infra/firebase/firestore/repositories/shopping/buy-2-win-firestore.repository.d.ts +1 -1
  9. package/src/infra/firebase/firestore/repositories/shopping/campaign-dashboard-firestore.repository.d.ts +1 -1
  10. package/src/infra/firebase/firestore/repositories/shopping/campaign-hashtag-firestore.repository.d.ts +1 -1
  11. package/src/infra/firebase/firestore/repositories/shopping/checkout-firestore.repository.d.ts +1 -1
  12. package/src/infra/firebase/firestore/repositories/shopping/checkout-subscription-firestore.repository.d.ts +1 -1
  13. package/src/infra/firebase/firestore/repositories/shopping/coupon-firestore.repository.d.ts +1 -1
  14. package/src/infra/firebase/firestore/repositories/shopping/legacy-order-firestore.repository.d.ts +1 -1
  15. package/src/infra/firebase/firestore/repositories/shopping/order-blocked-firestore.repository.d.ts +1 -1
  16. package/src/infra/firebase/firestore/repositories/shopping/order-firestore.repository.d.ts +1 -1
  17. package/src/infra/firebase/firestore/repositories/shopping/payment-firestore.repository.d.ts +1 -1
  18. package/src/infra/firebase/firestore/repositories/shopping/subscription-plan-firestore.repository.d.ts +1 -1
  19. package/src/infra/firebase/firestore/repositories/users/lead-firestore.repository.d.ts +1 -1
  20. package/src/infra/firebase/firestore/repositories/users/subscription-edition-firestore.repository.d.ts +1 -1
  21. package/src/infra/firebase/firestore/repositories/users/subscription-firestore.repository.d.ts +1 -1
  22. package/src/infra/firebase/firestore/repositories/users/subscription-materialization-firestore.repository.d.ts +1 -1
  23. package/src/infra/firebase/firestore/repositories/users/subscription-payment-firestore.repository.d.ts +1 -1
  24. package/src/infra/firebase/firestore/repositories/users/subscription-summary-firestore.repository.d.ts +1 -1
  25. package/src/infra/firebase/firestore/repositories/users/user-address-firestore.repository.d.ts +1 -1
  26. package/src/infra/firebase/firestore/repositories/users/user-beauty-profile-firestore.repository.d.ts +1 -1
  27. package/src/infra/firebase/firestore/repositories/users/user-firestore.repository.d.ts +1 -1
  28. package/src/infra/firebase/firestore/repositories/users/user-payment-method-firestore.repository.d.ts +1 -1
  29. package/src/infra/hasura-graphql/mixins/helpers/md5-generator.helper.d.ts +7 -0
  30. package/src/infra/hasura-graphql/mixins/with-find-hasura-graphql.mixin.d.ts +0 -16
  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-hasura-graphql.repository.d.ts +0 -2
  34. package/src/infra/hasura-graphql/repositories/catalog/category-product-hasura-graphql.repository.d.ts +1 -1
  35. package/src/infra/hasura-graphql/repositories/catalog/filter-hasura-graphql.repository.d.ts +1 -1
  36. package/src/infra/hasura-graphql/repositories/catalog/filter-option-hasura-graphql.repository.d.ts +1 -1
  37. package/src/infra/hasura-graphql/repositories/catalog/product-errors-hasura-graphql.repository.d.ts +1 -1
  38. package/src/infra/hasura-graphql/repositories/catalog/product-review-hasura-graphql.repository.d.ts +1 -1
  39. package/src/infra/hasura-graphql/repositories/catalog/product-stock-notification-hasura-graphql.repository.d.ts +1 -1
  40. package/src/infra/hasura-graphql/repositories/catalog/variant-hasura-graphql.repository.d.ts +1 -1
  41. package/src/infra/hasura-graphql/repositories/catalog/wishlist-hasura-graphql.repository.d.ts +1 -1
  42. package/src/infra/firebase/firestore/mixins/helpers/cache-key-generator.helper.d.ts +0 -9
  43. 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
  }
@@ -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, _m;
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: ((_m = options === null || options === void 0 ? void 0 : options.cache) === null || _m === void 0 ? void 0 : _m.ttl) || 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"]);
@@ -5706,83 +5623,63 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5706
5623
  return homeSections;
5707
5624
  }
5708
5625
  async mountCategory(category, shop, options, optionsCache) {
5709
- var _a, _b, _c, _d, _e, _f, _g;
5626
+ var _a;
5710
5627
  if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
5711
5628
  return [];
5712
- if (((_b = this.cache) === null || _b === void 0 ? void 0 : _b.cacheAdapter) && ((_c = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _c === void 0 ? void 0 : _c.enabled)) {
5713
- const cacheKey = `${this.model.name.toLowerCase()}:mountCategory:${category.id}:${shop}:${MD5GeneratorHelper.generateMD5(options)}`;
5714
- const cachedData = await this.cache.cacheAdapter.get(cacheKey);
5715
- if (cachedData) {
5716
- this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
5717
- return JSON.parse(cachedData);
5718
- }
5719
- }
5720
- const fields = [
5721
- 'id',
5722
- 'name',
5723
- 'slug',
5724
- 'images',
5725
- 'miniatures',
5726
- 'price',
5727
- 'fullPrice',
5728
- 'subscriberDiscountPercentage',
5729
- 'subscriberPrice',
5730
- 'stock',
5731
- 'published',
5732
- 'CEST',
5733
- 'EAN',
5734
- 'NCM',
5735
- 'brand',
5736
- 'costPrice',
5737
- 'hasVariants',
5738
- 'isKit',
5739
- 'sku',
5740
- 'rate',
5741
- 'tags',
5742
- 'type',
5743
- 'shoppingCount',
5744
- 'gender',
5745
- 'createdAt',
5746
- ];
5629
+ const mostRelevants = category.getMostRelevantByShop(shop);
5630
+ const mostRelevantProductsIds = [...new Set(mostRelevants.concat(category.products))];
5747
5631
  const products = [];
5748
- const mostRelevantsIds = category.getMostRelevantByShop(shop);
5749
- if (mostRelevantsIds === null || mostRelevantsIds === void 0 ? void 0 : mostRelevantsIds.length) {
5750
- const { data: mostRelevants } = await this.productRepository.findCatalog({
5751
- filters: Object.assign({ id: {
5752
- operator: Where.IN,
5753
- value: mostRelevantsIds,
5754
- }, published: true }, (options.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})),
5755
- fields,
5756
- options: { enableCount: false },
5757
- orderBy: {
5758
- stock: 'desc',
5759
- shoppingCount: 'desc',
5760
- rate: 'desc',
5761
- name: 'asc',
5762
- },
5763
- }, shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5764
- if (mostRelevants.length >= mostRelevantsIds.length) {
5765
- const result = this.reorganizeMostRelevantsProducts(mostRelevants, mostRelevantsIds, options.limit);
5766
- if (((_d = this.cache) === null || _d === void 0 ? void 0 : _d.cacheAdapter) && ((_e = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _e === void 0 ? void 0 : _e.enabled))
5767
- await this.saveToCache(category, shop, options, optionsCache, result);
5768
- return result;
5769
- }
5770
- products.push(...mostRelevants);
5771
- }
5772
- const productIds = category.products.filter((productId) => !mostRelevantsIds.includes(productId));
5773
- const { data: productsData } = await this.productRepository.findCatalog(Object.assign(Object.assign({ filters: Object.assign({ id: {
5774
- operator: Where.IN,
5775
- value: productIds,
5776
- }, published: true }, (options.hasStock ? { stock: { quantity: { operator: Where.GT, value: 0 } } } : {})) }, (options.limit ? { limits: { limit: options.limit } } : {})), { fields, options: { enableCount: false }, orderBy: {
5777
- stock: 'desc',
5632
+ const { data: productsData } = await this.productRepository.findCatalog({
5633
+ filters: {
5634
+ id: { operator: Where.IN, value: mostRelevantProductsIds },
5635
+ published: true,
5636
+ },
5637
+ fields: [
5638
+ 'id',
5639
+ 'name',
5640
+ 'slug',
5641
+ 'images',
5642
+ 'miniatures',
5643
+ 'price',
5644
+ 'fullPrice',
5645
+ 'subscriberDiscountPercentage',
5646
+ 'subscriberPrice',
5647
+ 'stock',
5648
+ 'published',
5649
+ 'CEST',
5650
+ 'EAN',
5651
+ 'NCM',
5652
+ 'brand',
5653
+ 'costPrice',
5654
+ 'hasVariants',
5655
+ 'isKit',
5656
+ 'sku',
5657
+ 'rate',
5658
+ 'tags',
5659
+ 'type',
5660
+ 'shoppingCount',
5661
+ 'gender',
5662
+ 'createdAt',
5663
+ ],
5664
+ options: { enableCount: false },
5665
+ orderBy: {
5778
5666
  shoppingCount: 'desc',
5779
5667
  rate: 'desc',
5668
+ stock: 'desc',
5780
5669
  name: 'asc',
5781
- } }), shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5782
- const result = this.reorganizeMostRelevantsProducts([...products, ...productsData], mostRelevantsIds, options.limit);
5783
- if (((_f = this.cache) === null || _f === void 0 ? void 0 : _f.cacheAdapter) && ((_g = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _g === void 0 ? void 0 : _g.enabled))
5784
- await this.saveToCache(category, shop, options, optionsCache, result);
5785
- return result;
5670
+ },
5671
+ }, shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5672
+ const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
5673
+ const firstProducts = productsData
5674
+ .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
5675
+ .sort((a, b) => mostRelevants.indexOf(a.id) - mostRelevants.indexOf(b.id));
5676
+ const lastProducts = productsData
5677
+ .filter((product) => !mostRelevants.includes(product.id) && product.stock.quantity > 0)
5678
+ .concat(mostRelevantWithouyStock);
5679
+ const categoryMostRelevants = firstProducts.concat(lastProducts);
5680
+ const resultFinal = categoryMostRelevants.slice(0, options.limit);
5681
+ products.push(...resultFinal);
5682
+ return products;
5786
5683
  }
5787
5684
  async getChildren(parentId, _optionsCache) {
5788
5685
  const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference', 'published', 'shops'], {
@@ -5918,16 +5815,6 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5918
5815
  return filters;
5919
5816
  }
5920
5817
  }
5921
- async saveToCache(category, shop, options, optionsCache, result) {
5922
- var _a;
5923
- const cacheKey = `${this.model.name.toLowerCase()}:mountCategory:${category.id}:${shop}:${MD5GeneratorHelper.generateMD5(options)}`;
5924
- await this.cache.cacheAdapter.set({
5925
- key: cacheKey,
5926
- data: JSON.stringify(result),
5927
- expirationInSeconds: ((_a = optionsCache === null || optionsCache === void 0 ? void 0 : optionsCache.cache) === null || _a === void 0 ? void 0 : _a.ttl) || this.cache.ttlDefault,
5928
- });
5929
- this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5930
- }
5931
5818
  }
5932
5819
  __decorate([
5933
5820
  Log(),
@@ -5948,7 +5835,6 @@ __decorate([
5948
5835
  __metadata("design:returntype", Promise)
5949
5836
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
5950
5837
  __decorate([
5951
- Log(),
5952
5838
  Log(),
5953
5839
  __metadata("design:type", Function),
5954
5840
  __metadata("design:paramtypes", [Category, String, Object, Object]),
@@ -5968,7 +5854,7 @@ __decorate([
5968
5854
  ], CategoryHasuraGraphQLRepository.prototype, "isChild", null);
5969
5855
 
5970
5856
  class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
5971
- constructor({ endpoint, authOptions, interceptors, cache, }) {
5857
+ constructor({ endpoint, authOptions, interceptors, }) {
5972
5858
  super({
5973
5859
  tableName: 'category_product',
5974
5860
  model: CategoryProduct,
@@ -5976,7 +5862,6 @@ class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withH
5976
5862
  authOptions,
5977
5863
  interceptors,
5978
5864
  fields: [{ productId: { columnName: 'product_id' } }, { categoryId: { columnName: 'category_id' } }, 'order'],
5979
- cache,
5980
5865
  });
5981
5866
  }
5982
5867
  async removeProductFromCategory(categoryId, productId) {
@@ -6003,7 +5888,7 @@ class CategoryProductHasuraGraphQLRepository extends withCrudHasuraGraphQL(withH
6003
5888
  }
6004
5889
 
6005
5890
  class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6006
- constructor({ endpoint, authOptions, interceptors, cache, }, filterOptionRepository, categoryFilterRepository) {
5891
+ constructor({ endpoint, authOptions, interceptors, }, filterOptionRepository, categoryFilterRepository) {
6007
5892
  super({
6008
5893
  tableName: 'filter',
6009
5894
  model: Filter,
@@ -6043,7 +5928,6 @@ class FilterHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGrap
6043
5928
  },
6044
5929
  },
6045
5930
  ],
6046
- cache,
6047
5931
  });
6048
5932
  this.filterOptionRepository = filterOptionRepository;
6049
5933
  this.categoryFilterRepository = categoryFilterRepository;
@@ -6130,7 +6014,7 @@ __decorate([
6130
6014
  ], FilterHasuraGraphQLRepository.prototype, "deleteOptions", null);
6131
6015
 
6132
6016
  class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6133
- constructor({ endpoint, authOptions, interceptors, cache, }) {
6017
+ constructor({ endpoint, authOptions, interceptors, }) {
6134
6018
  super({
6135
6019
  tableName: 'filter_option',
6136
6020
  model: FilterOption,
@@ -6144,20 +6028,18 @@ class FilterOptionHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasu
6144
6028
  { createdAt: { columnName: 'created_at' } },
6145
6029
  { updatedAt: { columnName: 'updated_at' } },
6146
6030
  ],
6147
- cache,
6148
6031
  });
6149
6032
  }
6150
6033
  }
6151
6034
 
6152
6035
  class ProductErrorsHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6153
- constructor({ endpoint, authOptions, interceptors, cache, }, productRepository) {
6036
+ constructor({ endpoint, authOptions, interceptors, }, productRepository) {
6154
6037
  super({
6155
6038
  tableName: 'product_errors',
6156
6039
  model: ProductErrorsHasuraGraphQL,
6157
6040
  endpoint,
6158
6041
  authOptions,
6159
6042
  interceptors,
6160
- cache,
6161
6043
  fields: [
6162
6044
  {
6163
6045
  productId: {
@@ -6871,7 +6753,7 @@ __decorate([
6871
6753
  ], ProductHasuraGraphQLRepository.prototype, "findReviewsByProduct", null);
6872
6754
 
6873
6755
  class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6874
- constructor({ endpoint, authOptions, interceptors, cache, }) {
6756
+ constructor({ endpoint, authOptions, interceptors, }) {
6875
6757
  super({
6876
6758
  tableName: 'product_review',
6877
6759
  model: ProductReview,
@@ -6895,7 +6777,6 @@ class ProductReviewHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHas
6895
6777
  { createdAt: { columnName: 'created_at' } },
6896
6778
  { updatedAt: { columnName: 'updated_at' } },
6897
6779
  ],
6898
- cache,
6899
6780
  });
6900
6781
  }
6901
6782
  async updateManyStatus(reviews) {
@@ -6937,14 +6818,13 @@ __decorate([
6937
6818
  ], ProductReviewHasuraGraphQLRepository.prototype, "disaproveReview", null);
6938
6819
 
6939
6820
  class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
6940
- constructor({ endpoint, authOptions, interceptors, cache, }) {
6821
+ constructor({ endpoint, authOptions, interceptors, }) {
6941
6822
  super({
6942
6823
  tableName: 'product_stock_notification',
6943
6824
  model: ProductStockNotification,
6944
6825
  endpoint,
6945
6826
  authOptions,
6946
6827
  interceptors,
6947
- cache,
6948
6828
  fields: [
6949
6829
  'id',
6950
6830
  { productId: { columnName: 'product_id' } },
@@ -6999,14 +6879,13 @@ class ProductStockNotificationHasuraGraphQLRepository extends withCrudHasuraGrap
6999
6879
  }
7000
6880
 
7001
6881
  class VariantHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
7002
- constructor({ endpoint, authOptions, interceptors, cache, }) {
6882
+ constructor({ endpoint, authOptions, interceptors, }) {
7003
6883
  super({
7004
6884
  tableName: 'product',
7005
6885
  model: VariantHasuraGraphQL,
7006
6886
  endpoint,
7007
6887
  authOptions,
7008
6888
  interceptors,
7009
- cache,
7010
6889
  fields: [
7011
6890
  { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
7012
6891
  { firestoreId: { columnName: 'firestore_id' } },
@@ -7113,14 +6992,13 @@ class WishlistHasuraGraphQL extends Wishlist {
7113
6992
  }
7114
6993
 
7115
6994
  class WishlistHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGraphQL(Base)) {
7116
- constructor({ endpoint, authOptions, interceptors, cache, }, categoryProductRepository) {
6995
+ constructor({ endpoint, authOptions, interceptors, }, categoryProductRepository) {
7117
6996
  super({
7118
6997
  tableName: 'category',
7119
6998
  model: WishlistHasuraGraphQL,
7120
6999
  endpoint,
7121
7000
  authOptions,
7122
7001
  interceptors,
7123
- cache,
7124
7002
  fields: [
7125
7003
  { id: { columnName: 'id', to: (value) => +value, from: (value) => value.toString() } },
7126
7004
  { firestoreId: { columnName: 'firestore_id' } },