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

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.
package/index.cjs.js CHANGED
@@ -11,33 +11,14 @@ var debug = require('debug');
11
11
  var tsCustomError = require('ts-custom-error');
12
12
  var axios = require('axios');
13
13
  var auth = require('firebase/auth');
14
- var crypto = require('crypto');
14
+ var tsMd5 = require('ts-md5');
15
15
  var firestore = require('firebase/firestore');
16
16
  var storage = require('firebase/storage');
17
17
  var gqlQueryBuilder = require('gql-query-builder');
18
18
 
19
19
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
20
 
21
- function _interopNamespace(e) {
22
- if (e && e.__esModule) return e;
23
- var n = Object.create(null);
24
- if (e) {
25
- Object.keys(e).forEach(function (k) {
26
- if (k !== 'default') {
27
- var d = Object.getOwnPropertyDescriptor(e, k);
28
- Object.defineProperty(n, k, d.get ? d : {
29
- enumerable: true,
30
- get: function () { return e[k]; }
31
- });
32
- }
33
- });
34
- }
35
- n["default"] = e;
36
- return Object.freeze(n);
37
- }
38
-
39
21
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
40
- var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
41
22
 
42
23
  exports.AntifraudProviders = void 0;
43
24
  (function (AntifraudProviders) {
@@ -3591,46 +3572,28 @@ GraphQLFieldHelper.ConvertNestedFieldsToGraphQLFields = (fieldName, fieldValue)
3591
3572
  };
3592
3573
 
3593
3574
  class MD5GeneratorHelper {
3594
- /**
3595
- * Gera um hash MD5 para um objeto de qualquer estrutura
3596
- * Garante que o mesmo objeto sempre gerará o mesmo hash, independentemente da ordem das chaves
3597
- */
3598
3575
  static generateMD5(data) {
3599
- // Null ou undefined geram um hash fixo
3600
- if (data === null || data === undefined) {
3601
- return crypto__namespace.createHash('md5').update('null').digest('hex');
3602
- }
3576
+ if (data === null || data === undefined)
3577
+ return tsMd5.Md5.hashStr('null');
3603
3578
  const normalizedData = this.normalizeData(data);
3604
3579
  const jsonString = JSON.stringify(normalizedData);
3605
- return crypto__namespace.createHash('md5').update(jsonString).digest('hex');
3580
+ return tsMd5.Md5.hashStr(jsonString);
3606
3581
  }
3607
- /**
3608
- * Normaliza os dados para garantir que a ordem das chaves não afete o resultado
3609
- */
3610
3582
  static normalizeData(data, depth = 0, maxDepth = 100) {
3611
- // Proteção contra recursão infinita
3612
- if (depth > maxDepth) {
3583
+ if (depth > maxDepth)
3613
3584
  return '[MAX_DEPTH_REACHED]';
3614
- }
3615
- // Tipos primitivos retornam diretamente
3616
- if (data === null || data === undefined) {
3585
+ if (data === null || data === undefined)
3617
3586
  return null;
3618
- }
3619
- if (typeof data !== 'object') {
3587
+ if (typeof data !== 'object')
3620
3588
  return data;
3621
- }
3622
- // Arrays são normalizados e ordenados
3623
- if (Array.isArray(data)) {
3589
+ if (Array.isArray(data))
3624
3590
  return data
3625
3591
  .map((item) => this.normalizeData(item, depth + 1, maxDepth))
3626
3592
  .sort((a, b) => {
3627
- // Converte para string para comparação determinística
3628
3593
  const strA = typeof a === 'object' && a !== null ? JSON.stringify(a) : String(a);
3629
3594
  const strB = typeof b === 'object' && b !== null ? JSON.stringify(b) : String(b);
3630
3595
  return strA.localeCompare(strB);
3631
3596
  });
3632
- }
3633
- // Objetos: ordena as chaves
3634
3597
  const sortedObj = {};
3635
3598
  const keys = Object.keys(data).sort();
3636
3599
  keys.forEach((key) => {
@@ -5048,7 +5011,7 @@ const withGetHasuraGraphQL = (MixinBase) => {
5048
5011
  return CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(this.model, identifiers);
5049
5012
  }
5050
5013
  async get(identifiers, options) {
5051
- var _a, _b, _c, _d;
5014
+ var _a, _b, _c, _d, _e;
5052
5015
  this.logger = DebugHelper.from(this, 'get');
5053
5016
  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)) {
5054
5017
  const cacheKey = this.generateCacheKey(identifiers);
@@ -5082,7 +5045,7 @@ const withGetHasuraGraphQL = (MixinBase) => {
5082
5045
  await this.cache.cacheAdapter.set({
5083
5046
  key: cacheKey,
5084
5047
  data: JSON.stringify(resultModel.toPlain()),
5085
- expirationInSeconds: this.cache.ttlDefault,
5048
+ expirationInSeconds: ((_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl) || this.cache.ttlDefault,
5086
5049
  });
5087
5050
  this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5088
5051
  }
@@ -5135,7 +5098,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
5135
5098
  });
5136
5099
  }
5137
5100
  async find(params, options) {
5138
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
5101
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
5139
5102
  this.logger = DebugHelper.from(this, 'find');
5140
5103
  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)) {
5141
5104
  const cacheKey = generateCacheKey(this.model, params);
@@ -5246,7 +5209,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
5246
5209
  await this.cache.cacheAdapter.set({
5247
5210
  key: cacheKey,
5248
5211
  data: JSON.stringify(findResult),
5249
- expirationInSeconds: this.cache.ttlDefault,
5212
+ expirationInSeconds: ((_m = options === null || options === void 0 ? void 0 : options.cache) === null || _m === void 0 ? void 0 : _m.ttl) || this.cache.ttlDefault,
5250
5213
  });
5251
5214
  this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5252
5215
  }
@@ -5568,11 +5531,12 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5568
5531
  },
5569
5532
  } }));
5570
5533
  }
5571
- async get(identifiers) {
5534
+ async get(identifiers, optionsCache) {
5572
5535
  var _a;
5573
5536
  return Number.isNaN(+identifiers.id)
5574
- ? (_a = (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } })).data) === null || _a === void 0 ? void 0 : _a[0]
5575
- : super.get(identifiers);
5537
+ ? (_a = (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, optionsCache))
5538
+ .data) === null || _a === void 0 ? void 0 : _a[0]
5539
+ : super.get(identifiers, optionsCache);
5576
5540
  }
5577
5541
  async update(params) {
5578
5542
  const { products, id: checkId, metadatas, filters } = params, data = tslib.__rest(params, ["products", "id", "metadatas", "filters"]);
@@ -5584,7 +5548,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5584
5548
  category.filters = filters && (await this.updateFilters(+id, { filters }));
5585
5549
  return category;
5586
5550
  }
5587
- async getCategoryBySlug(slug, shop) {
5551
+ async getCategoryBySlug(slug, shop, optionsCache) {
5588
5552
  if (!slug)
5589
5553
  return null;
5590
5554
  const { data } = await this.find({
@@ -5596,14 +5560,14 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5596
5560
  options: {
5597
5561
  enableCount: false,
5598
5562
  },
5599
- });
5563
+ }, optionsCache);
5600
5564
  if (!data.length)
5601
5565
  throw new NotFoundError(`Category with slug ${slug} not found`);
5602
5566
  if (data.length > 1)
5603
5567
  throw new DuplicatedResultsError('Query returned duplicated values');
5604
5568
  return data.shift();
5605
5569
  }
5606
- async getCategoryByShop(shop) {
5570
+ async getCategoryByShop(shop, optionsCache) {
5607
5571
  if (!shop)
5608
5572
  return;
5609
5573
  const { data } = await this.find({
@@ -5615,10 +5579,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5615
5579
  options: {
5616
5580
  enableCount: false,
5617
5581
  },
5618
- });
5582
+ }, optionsCache);
5619
5583
  return data;
5620
5584
  }
5621
- async getCategoriesForHome(categoryIds, shop, limit = 4) {
5585
+ async getCategoriesForHome(categoryIds, shop, limit = 4, optionsCache) {
5622
5586
  if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
5623
5587
  return [];
5624
5588
  const categoriesFirestore = categoryIds.filter((categoryId) => Number.isNaN(+categoryId));
@@ -5626,24 +5590,27 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5626
5590
  const categories = [];
5627
5591
  if (categoriesFirestore.length)
5628
5592
  categories.push(...(await this.find({
5629
- filters: { firestoreId: { operator: exports.Where.IN, value: categoriesFirestore.filter(Boolean) }, published: true },
5630
- }).then(({ data }) => data)));
5593
+ filters: {
5594
+ firestoreId: { operator: exports.Where.IN, value: categoriesFirestore.filter(Boolean) },
5595
+ published: true,
5596
+ },
5597
+ }, optionsCache).then(({ data }) => data)));
5631
5598
  if (categoriesHasura.length)
5632
5599
  categories.push(...(await this.find({
5633
5600
  filters: {
5634
5601
  id: { operator: exports.Where.IN, value: categoriesHasura.filter(Boolean) },
5635
5602
  published: true,
5636
5603
  },
5637
- }).then(({ data }) => data)));
5604
+ }, optionsCache).then(({ data }) => data)));
5638
5605
  if (!categories.length)
5639
5606
  return [];
5640
5607
  const homeSections = await Promise.all(categories.map(async (category) => ({
5641
5608
  category,
5642
- products: await this.mountCategory(category, shop, { limit, hasStock: true }),
5609
+ products: await this.mountCategory(category, shop, { limit, hasStock: true }, optionsCache),
5643
5610
  })));
5644
5611
  return homeSections;
5645
5612
  }
5646
- async mountCategory(category, shop, options) {
5613
+ async mountCategory(category, shop, options, optionsCache) {
5647
5614
  var _a;
5648
5615
  if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
5649
5616
  return [];
@@ -5689,7 +5656,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5689
5656
  stock: 'desc',
5690
5657
  name: 'asc',
5691
5658
  },
5692
- }, shop === exports.Shops.MENSMARKET ? 'male' : 'female');
5659
+ }, shop === exports.Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5693
5660
  const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
5694
5661
  const firstProducts = productsData
5695
5662
  .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
@@ -5702,7 +5669,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5702
5669
  products.push(...resultFinal);
5703
5670
  return products;
5704
5671
  }
5705
- async getChildren(parentId) {
5672
+ async getChildren(parentId, _optionsCache) {
5706
5673
  const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference', 'published', 'shops'], {
5707
5674
  args: {
5708
5675
  type: 'category_tree_args',
@@ -5840,31 +5807,31 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5840
5807
  tslib.__decorate([
5841
5808
  Log(),
5842
5809
  tslib.__metadata("design:type", Function),
5843
- tslib.__metadata("design:paramtypes", [String, String]),
5810
+ tslib.__metadata("design:paramtypes", [String, String, Object]),
5844
5811
  tslib.__metadata("design:returntype", Promise)
5845
5812
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoryBySlug", null);
5846
5813
  tslib.__decorate([
5847
5814
  Log(),
5848
5815
  tslib.__metadata("design:type", Function),
5849
- tslib.__metadata("design:paramtypes", [String]),
5816
+ tslib.__metadata("design:paramtypes", [String, Object]),
5850
5817
  tslib.__metadata("design:returntype", Promise)
5851
5818
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
5852
5819
  tslib.__decorate([
5853
5820
  Log(),
5854
5821
  tslib.__metadata("design:type", Function),
5855
- tslib.__metadata("design:paramtypes", [Array, String, Object]),
5822
+ tslib.__metadata("design:paramtypes", [Array, String, Object, Object]),
5856
5823
  tslib.__metadata("design:returntype", Promise)
5857
5824
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
5858
5825
  tslib.__decorate([
5859
5826
  Log(),
5860
5827
  tslib.__metadata("design:type", Function),
5861
- tslib.__metadata("design:paramtypes", [Category, String, Object]),
5828
+ tslib.__metadata("design:paramtypes", [Category, String, Object, Object]),
5862
5829
  tslib.__metadata("design:returntype", Promise)
5863
5830
  ], CategoryHasuraGraphQLRepository.prototype, "mountCategory", null);
5864
5831
  tslib.__decorate([
5865
5832
  Log(),
5866
5833
  tslib.__metadata("design:type", Function),
5867
- tslib.__metadata("design:paramtypes", [Number]),
5834
+ tslib.__metadata("design:paramtypes", [Number, Object]),
5868
5835
  tslib.__metadata("design:returntype", Promise)
5869
5836
  ], CategoryHasuraGraphQLRepository.prototype, "getChildren", null);
5870
5837
  tslib.__decorate([
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 * as crypto from 'crypto';
12
+ import { Md5 } from 'ts-md5';
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,46 +3566,28 @@ 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
- */
3573
3569
  static generateMD5(data) {
3574
- // Null ou undefined geram um hash fixo
3575
- if (data === null || data === undefined) {
3576
- return crypto.createHash('md5').update('null').digest('hex');
3577
- }
3570
+ if (data === null || data === undefined)
3571
+ return Md5.hashStr('null');
3578
3572
  const normalizedData = this.normalizeData(data);
3579
3573
  const jsonString = JSON.stringify(normalizedData);
3580
- return crypto.createHash('md5').update(jsonString).digest('hex');
3574
+ return Md5.hashStr(jsonString);
3581
3575
  }
3582
- /**
3583
- * Normaliza os dados para garantir que a ordem das chaves não afete o resultado
3584
- */
3585
3576
  static normalizeData(data, depth = 0, maxDepth = 100) {
3586
- // Proteção contra recursão infinita
3587
- if (depth > maxDepth) {
3577
+ if (depth > maxDepth)
3588
3578
  return '[MAX_DEPTH_REACHED]';
3589
- }
3590
- // Tipos primitivos retornam diretamente
3591
- if (data === null || data === undefined) {
3579
+ if (data === null || data === undefined)
3592
3580
  return null;
3593
- }
3594
- if (typeof data !== 'object') {
3581
+ if (typeof data !== 'object')
3595
3582
  return data;
3596
- }
3597
- // Arrays são normalizados e ordenados
3598
- if (Array.isArray(data)) {
3583
+ if (Array.isArray(data))
3599
3584
  return data
3600
3585
  .map((item) => this.normalizeData(item, depth + 1, maxDepth))
3601
3586
  .sort((a, b) => {
3602
- // Converte para string para comparação determinística
3603
3587
  const strA = typeof a === 'object' && a !== null ? JSON.stringify(a) : String(a);
3604
3588
  const strB = typeof b === 'object' && b !== null ? JSON.stringify(b) : String(b);
3605
3589
  return strA.localeCompare(strB);
3606
3590
  });
3607
- }
3608
- // Objetos: ordena as chaves
3609
3591
  const sortedObj = {};
3610
3592
  const keys = Object.keys(data).sort();
3611
3593
  keys.forEach((key) => {
@@ -5023,7 +5005,7 @@ const withGetHasuraGraphQL = (MixinBase) => {
5023
5005
  return CacheKeyGeneratorHelper.generateCacheKeyFromIdentifiers(this.model, identifiers);
5024
5006
  }
5025
5007
  async get(identifiers, options) {
5026
- var _a, _b, _c, _d;
5008
+ var _a, _b, _c, _d, _e;
5027
5009
  this.logger = DebugHelper.from(this, 'get');
5028
5010
  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)) {
5029
5011
  const cacheKey = this.generateCacheKey(identifiers);
@@ -5057,7 +5039,7 @@ const withGetHasuraGraphQL = (MixinBase) => {
5057
5039
  await this.cache.cacheAdapter.set({
5058
5040
  key: cacheKey,
5059
5041
  data: JSON.stringify(resultModel.toPlain()),
5060
- expirationInSeconds: this.cache.ttlDefault,
5042
+ expirationInSeconds: ((_e = options === null || options === void 0 ? void 0 : options.cache) === null || _e === void 0 ? void 0 : _e.ttl) || this.cache.ttlDefault,
5061
5043
  });
5062
5044
  this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5063
5045
  }
@@ -5110,7 +5092,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
5110
5092
  });
5111
5093
  }
5112
5094
  async find(params, options) {
5113
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
5095
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
5114
5096
  this.logger = DebugHelper.from(this, 'find');
5115
5097
  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)) {
5116
5098
  const cacheKey = generateCacheKey(this.model, params);
@@ -5221,7 +5203,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
5221
5203
  await this.cache.cacheAdapter.set({
5222
5204
  key: cacheKey,
5223
5205
  data: JSON.stringify(findResult),
5224
- expirationInSeconds: this.cache.ttlDefault,
5206
+ expirationInSeconds: ((_m = options === null || options === void 0 ? void 0 : options.cache) === null || _m === void 0 ? void 0 : _m.ttl) || this.cache.ttlDefault,
5225
5207
  });
5226
5208
  this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5227
5209
  }
@@ -5543,11 +5525,12 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5543
5525
  },
5544
5526
  } }));
5545
5527
  }
5546
- async get(identifiers) {
5528
+ async get(identifiers, optionsCache) {
5547
5529
  var _a;
5548
5530
  return Number.isNaN(+identifiers.id)
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);
5531
+ ? (_a = (await this.find({ filters: { firestoreId: identifiers.id }, options: { enableCount: false } }, optionsCache))
5532
+ .data) === null || _a === void 0 ? void 0 : _a[0]
5533
+ : super.get(identifiers, optionsCache);
5551
5534
  }
5552
5535
  async update(params) {
5553
5536
  const { products, id: checkId, metadatas, filters } = params, data = __rest(params, ["products", "id", "metadatas", "filters"]);
@@ -5559,7 +5542,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5559
5542
  category.filters = filters && (await this.updateFilters(+id, { filters }));
5560
5543
  return category;
5561
5544
  }
5562
- async getCategoryBySlug(slug, shop) {
5545
+ async getCategoryBySlug(slug, shop, optionsCache) {
5563
5546
  if (!slug)
5564
5547
  return null;
5565
5548
  const { data } = await this.find({
@@ -5571,14 +5554,14 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5571
5554
  options: {
5572
5555
  enableCount: false,
5573
5556
  },
5574
- });
5557
+ }, optionsCache);
5575
5558
  if (!data.length)
5576
5559
  throw new NotFoundError(`Category with slug ${slug} not found`);
5577
5560
  if (data.length > 1)
5578
5561
  throw new DuplicatedResultsError('Query returned duplicated values');
5579
5562
  return data.shift();
5580
5563
  }
5581
- async getCategoryByShop(shop) {
5564
+ async getCategoryByShop(shop, optionsCache) {
5582
5565
  if (!shop)
5583
5566
  return;
5584
5567
  const { data } = await this.find({
@@ -5590,10 +5573,10 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5590
5573
  options: {
5591
5574
  enableCount: false,
5592
5575
  },
5593
- });
5576
+ }, optionsCache);
5594
5577
  return data;
5595
5578
  }
5596
- async getCategoriesForHome(categoryIds, shop, limit = 4) {
5579
+ async getCategoriesForHome(categoryIds, shop, limit = 4, optionsCache) {
5597
5580
  if (!(categoryIds === null || categoryIds === void 0 ? void 0 : categoryIds.length))
5598
5581
  return [];
5599
5582
  const categoriesFirestore = categoryIds.filter((categoryId) => Number.isNaN(+categoryId));
@@ -5601,24 +5584,27 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5601
5584
  const categories = [];
5602
5585
  if (categoriesFirestore.length)
5603
5586
  categories.push(...(await this.find({
5604
- filters: { firestoreId: { operator: Where.IN, value: categoriesFirestore.filter(Boolean) }, published: true },
5605
- }).then(({ data }) => data)));
5587
+ filters: {
5588
+ firestoreId: { operator: Where.IN, value: categoriesFirestore.filter(Boolean) },
5589
+ published: true,
5590
+ },
5591
+ }, optionsCache).then(({ data }) => data)));
5606
5592
  if (categoriesHasura.length)
5607
5593
  categories.push(...(await this.find({
5608
5594
  filters: {
5609
5595
  id: { operator: Where.IN, value: categoriesHasura.filter(Boolean) },
5610
5596
  published: true,
5611
5597
  },
5612
- }).then(({ data }) => data)));
5598
+ }, optionsCache).then(({ data }) => data)));
5613
5599
  if (!categories.length)
5614
5600
  return [];
5615
5601
  const homeSections = await Promise.all(categories.map(async (category) => ({
5616
5602
  category,
5617
- products: await this.mountCategory(category, shop, { limit, hasStock: true }),
5603
+ products: await this.mountCategory(category, shop, { limit, hasStock: true }, optionsCache),
5618
5604
  })));
5619
5605
  return homeSections;
5620
5606
  }
5621
- async mountCategory(category, shop, options) {
5607
+ async mountCategory(category, shop, options, optionsCache) {
5622
5608
  var _a;
5623
5609
  if (!((_a = category === null || category === void 0 ? void 0 : category.products) === null || _a === void 0 ? void 0 : _a.length))
5624
5610
  return [];
@@ -5664,7 +5650,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5664
5650
  stock: 'desc',
5665
5651
  name: 'asc',
5666
5652
  },
5667
- }, shop === Shops.MENSMARKET ? 'male' : 'female');
5653
+ }, shop === Shops.MENSMARKET ? 'male' : 'female', optionsCache);
5668
5654
  const mostRelevantWithouyStock = productsData.filter((product) => mostRelevants.includes(product.id) && product.stock.quantity <= 0);
5669
5655
  const firstProducts = productsData
5670
5656
  .filter((product) => mostRelevants.includes(product.id) && product.stock.quantity > 0)
@@ -5677,7 +5663,7 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5677
5663
  products.push(...resultFinal);
5678
5664
  return products;
5679
5665
  }
5680
- async getChildren(parentId) {
5666
+ async getChildren(parentId, _optionsCache) {
5681
5667
  const { category_tree } = await this.query('category_tree', ['id', 'name', 'parent_id', 'slug', 'reference', 'published', 'shops'], {
5682
5668
  args: {
5683
5669
  type: 'category_tree_args',
@@ -5815,31 +5801,31 @@ class CategoryHasuraGraphQLRepository extends withCrudHasuraGraphQL(withHasuraGr
5815
5801
  __decorate([
5816
5802
  Log(),
5817
5803
  __metadata("design:type", Function),
5818
- __metadata("design:paramtypes", [String, String]),
5804
+ __metadata("design:paramtypes", [String, String, Object]),
5819
5805
  __metadata("design:returntype", Promise)
5820
5806
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoryBySlug", null);
5821
5807
  __decorate([
5822
5808
  Log(),
5823
5809
  __metadata("design:type", Function),
5824
- __metadata("design:paramtypes", [String]),
5810
+ __metadata("design:paramtypes", [String, Object]),
5825
5811
  __metadata("design:returntype", Promise)
5826
5812
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoryByShop", null);
5827
5813
  __decorate([
5828
5814
  Log(),
5829
5815
  __metadata("design:type", Function),
5830
- __metadata("design:paramtypes", [Array, String, Object]),
5816
+ __metadata("design:paramtypes", [Array, String, Object, Object]),
5831
5817
  __metadata("design:returntype", Promise)
5832
5818
  ], CategoryHasuraGraphQLRepository.prototype, "getCategoriesForHome", null);
5833
5819
  __decorate([
5834
5820
  Log(),
5835
5821
  __metadata("design:type", Function),
5836
- __metadata("design:paramtypes", [Category, String, Object]),
5822
+ __metadata("design:paramtypes", [Category, String, Object, Object]),
5837
5823
  __metadata("design:returntype", Promise)
5838
5824
  ], CategoryHasuraGraphQLRepository.prototype, "mountCategory", null);
5839
5825
  __decorate([
5840
5826
  Log(),
5841
5827
  __metadata("design:type", Function),
5842
- __metadata("design:paramtypes", [Number]),
5828
+ __metadata("design:paramtypes", [Number, Object]),
5843
5829
  __metadata("design:returntype", Promise)
5844
5830
  ], CategoryHasuraGraphQLRepository.prototype, "getChildren", null);
5845
5831
  __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.25.0-beta.2",
3
+ "version": "4.25.0-beta.4",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -1,18 +1,29 @@
1
1
  import { CrudRepository } from '../../generic/repository/crud.repository';
2
+ import { RepositoryCacheOptions } from '../../generic/repository/types';
2
3
  import { Product } from '../models';
3
4
  import { Category } from '../models/category';
4
5
  import { Shops } from '../models/enums/shops.enum';
5
6
  export interface CategoryRepository<T extends Category = Category> extends CrudRepository<T> {
6
- getCategoryBySlug(slug: string, shop: Shops): Promise<Category>;
7
- getCategoryByShop(shop: string): Promise<Category[]>;
8
- getCategoriesForHome(categoryIds: string[], shop: Shops, limit?: number): Promise<{
7
+ getCategoryBySlug(slug: string, shop: Shops, optionsCache?: {
8
+ cache?: RepositoryCacheOptions;
9
+ }): Promise<Category>;
10
+ getCategoryByShop(shop: string, optionsCache?: {
11
+ cache?: RepositoryCacheOptions;
12
+ }): Promise<Category[]>;
13
+ getCategoriesForHome(categoryIds: string[], shop: Shops, limit?: number, optionsCache?: {
14
+ cache?: RepositoryCacheOptions;
15
+ }): Promise<{
9
16
  category: Category;
10
17
  products: Product[];
11
18
  }[]>;
12
19
  mountCategory(category: Category, shop: Shops, options?: {
13
20
  limit?: number;
14
21
  hasStock?: boolean;
22
+ }, optionsCache?: {
23
+ cache?: RepositoryCacheOptions;
15
24
  }): Promise<Product[]>;
16
- getChildren(parentId: number): Promise<Category[]>;
25
+ getChildren(parentId: number, optionsCache?: {
26
+ cache?: RepositoryCacheOptions;
27
+ }): Promise<Category[]>;
17
28
  isChild(id: number, parentId: number): Promise<boolean>;
18
29
  }
@@ -1,11 +1,4 @@
1
1
  export declare class MD5GeneratorHelper {
2
- /**
3
- * Gera um hash MD5 para um objeto de qualquer estrutura
4
- * Garante que o mesmo objeto sempre gerará o mesmo hash, independentemente da ordem das chaves
5
- */
6
2
  static generateMD5(data: any): string;
7
- /**
8
- * Normaliza os dados para garantir que a ordem das chaves não afete o resultado
9
- */
10
3
  private static normalizeData;
11
4
  }
@@ -1,4 +1,4 @@
1
- import { Category, CategoryRepository, CreateRepositoryParams, GetRepositoryParams, Product, Shops, UpdateRepositoryParams } from '../../../../domain';
1
+ import { Category, CategoryRepository, CreateRepositoryParams, GetRepositoryParams, Product, RepositoryCacheOptions, Shops, UpdateRepositoryParams } from '../../../../domain';
2
2
  import { HasuraConstructorParams } from '../../mixins';
3
3
  import { CategoryHasuraGraphQL } from '../../models';
4
4
  import { CategoryFilterHasuraGraphQLRepository } from './category-filter-hasura-graphql.repository';
@@ -11,11 +11,19 @@ export declare class CategoryHasuraGraphQLRepository extends CategoryHasuraGraph
11
11
  private readonly categoryFilterRepository;
12
12
  constructor({ endpoint, authOptions, interceptors, cache, }: Pick<HasuraConstructorParams<CategoryHasuraGraphQL>, 'endpoint' | 'authOptions' | 'interceptors' | 'cache'>, productRepository: ProductHasuraGraphQLRepository, categoryFilterRepository: CategoryFilterHasuraGraphQLRepository);
13
13
  create(params: CreateRepositoryParams<CategoryHasuraGraphQL>): Promise<CategoryHasuraGraphQL>;
14
- get(identifiers: GetRepositoryParams<CategoryHasuraGraphQL>): Promise<CategoryHasuraGraphQL>;
14
+ get(identifiers: GetRepositoryParams<CategoryHasuraGraphQL>, optionsCache?: {
15
+ cache?: RepositoryCacheOptions;
16
+ }): Promise<CategoryHasuraGraphQL>;
15
17
  update(params: UpdateRepositoryParams<CategoryHasuraGraphQL>): Promise<CategoryHasuraGraphQL>;
16
- getCategoryBySlug(slug: string, shop: Shops): Promise<Category>;
17
- getCategoryByShop(shop: string): Promise<Category[]>;
18
- getCategoriesForHome(categoryIds: string[], shop: Shops, limit?: number): Promise<{
18
+ getCategoryBySlug(slug: string, shop: Shops, optionsCache?: {
19
+ cache?: RepositoryCacheOptions;
20
+ }): Promise<Category>;
21
+ getCategoryByShop(shop: string, optionsCache?: {
22
+ cache?: RepositoryCacheOptions;
23
+ }): Promise<Category[]>;
24
+ getCategoriesForHome(categoryIds: string[], shop: Shops, limit?: number, optionsCache?: {
25
+ cache?: RepositoryCacheOptions;
26
+ }): Promise<{
19
27
  category: Category;
20
28
  products: Product[];
21
29
  }[]>;
@@ -23,8 +31,12 @@ export declare class CategoryHasuraGraphQLRepository extends CategoryHasuraGraph
23
31
  limit?: number;
24
32
  hasStock?: boolean;
25
33
  gender?: string;
34
+ }, optionsCache?: {
35
+ cache?: RepositoryCacheOptions;
26
36
  }): Promise<Product[]>;
27
- getChildren(parentId: number): Promise<Category[]>;
37
+ getChildren(parentId: number, _optionsCache?: {
38
+ cache?: RepositoryCacheOptions;
39
+ }): Promise<Category[]>;
28
40
  isChild(id: number, parentId: number): Promise<boolean>;
29
41
  private getId;
30
42
  private updateProducts;