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

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) => {
@@ -5135,19 +5098,21 @@ 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, _m;
5101
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
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);
5142
5105
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
5143
5106
  if (cachedData) {
5107
+ const json = JSON.parse(cachedData);
5108
+ const data = (_c = json.data) === null || _c === void 0 ? void 0 : _c.map((item) => this.convertDataFromHasura(item));
5144
5109
  this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
5145
- return JSON.parse(cachedData);
5110
+ return Object.assign(Object.assign({}, json), { data });
5146
5111
  }
5147
5112
  }
5148
5113
  const { filters, limits, orderBy, options: findOptions } = params || {};
5149
5114
  const tableFiltersNamed = `${this.tableName}:${JSON.stringify(filters)}`;
5150
- const enableCount = (_c = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _c !== void 0 ? _c : true;
5115
+ const enableCount = (_d = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _d !== void 0 ? _d : true;
5151
5116
  const variablesFilters = lodash.isNil(filters)
5152
5117
  ? {}
5153
5118
  : {
@@ -5198,7 +5163,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
5198
5163
  ]
5199
5164
  : []),
5200
5165
  ...((!this.lastDistinct[tableFiltersNamed] &&
5201
- ((_e = (_d = params.options) === null || _d === void 0 ? void 0 : _d.distinct) === null || _e === void 0 ? void 0 : _e.map((distinct) => {
5166
+ ((_f = (_e = params.options) === null || _e === void 0 ? void 0 : _e.distinct) === null || _f === void 0 ? void 0 : _f.map((distinct) => {
5202
5167
  var _a, _b;
5203
5168
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
5204
5169
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
@@ -5219,34 +5184,34 @@ const withFindHasuraGraphQL = (MixinBase) => {
5219
5184
  []),
5220
5185
  ]);
5221
5186
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
5222
- 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)
5187
+ const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_g = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _g === void 0 ? void 0 : _g.length)
5223
5188
  ? {
5224
5189
  minimal: findOptions.minimal.reduce((minimals, current) => {
5225
5190
  var _a;
5226
5191
  return (Object.assign(Object.assign({}, minimals), lodash.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])));
5227
5192
  }, {}),
5228
5193
  }
5229
- : {})), (((_g = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _g === void 0 ? void 0 : _g.length)
5194
+ : {})), (((_h = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _h === void 0 ? void 0 : _h.length)
5230
5195
  ? {
5231
5196
  maximum: findOptions.maximum.reduce((maximums, current) => {
5232
5197
  var _a;
5233
5198
  return (Object.assign(Object.assign({}, maximums), lodash.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])));
5234
5199
  }, {}),
5235
5200
  }
5236
- : {})), (((_h = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _h === void 0 ? void 0 : _h.length) && {
5237
- 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) => {
5201
+ : {})), (((_j = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _j === void 0 ? void 0 : _j.length) && {
5202
+ distinct: (_k = this.lastDistinct[tableFiltersNamed]) !== null && _k !== void 0 ? _k : (this.lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
5238
5203
  var _a, _b;
5239
5204
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
5240
5205
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
5241
5206
  return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
5242
5207
  }, {})),
5243
5208
  }));
5244
- 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)) {
5209
+ if (((_l = this.cache) === null || _l === void 0 ? void 0 : _l.cacheAdapter) && ((_m = options === null || options === void 0 ? void 0 : options.cache) === null || _m === void 0 ? void 0 : _m.enabled)) {
5245
5210
  const cacheKey = generateCacheKey(this.model, params);
5246
5211
  await this.cache.cacheAdapter.set({
5247
5212
  key: cacheKey,
5248
5213
  data: JSON.stringify(findResult),
5249
- expirationInSeconds: ((_m = options === null || options === void 0 ? void 0 : options.cache) === null || _m === void 0 ? void 0 : _m.ttl) || this.cache.ttlDefault,
5214
+ expirationInSeconds: ((_o = options === null || options === void 0 ? void 0 : options.cache) === null || _o === void 0 ? void 0 : _o.ttl) || this.cache.ttlDefault,
5250
5215
  });
5251
5216
  this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5252
5217
  }
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) => {
@@ -5110,19 +5092,21 @@ 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, _m;
5095
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
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);
5117
5099
  const cachedData = await this.cache.cacheAdapter.get(cacheKey);
5118
5100
  if (cachedData) {
5101
+ const json = JSON.parse(cachedData);
5102
+ const data = (_c = json.data) === null || _c === void 0 ? void 0 : _c.map((item) => this.convertDataFromHasura(item));
5119
5103
  this.logger.log(`Dados recuperados do cache: ${cacheKey}`);
5120
- return JSON.parse(cachedData);
5104
+ return Object.assign(Object.assign({}, json), { data });
5121
5105
  }
5122
5106
  }
5123
5107
  const { filters, limits, orderBy, options: findOptions } = params || {};
5124
5108
  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;
5109
+ const enableCount = (_d = findOptions === null || findOptions === void 0 ? void 0 : findOptions.enableCount) !== null && _d !== void 0 ? _d : true;
5126
5110
  const variablesFilters = isNil(filters)
5127
5111
  ? {}
5128
5112
  : {
@@ -5173,7 +5157,7 @@ const withFindHasuraGraphQL = (MixinBase) => {
5173
5157
  ]
5174
5158
  : []),
5175
5159
  ...((!this.lastDistinct[tableFiltersNamed] &&
5176
- ((_e = (_d = params.options) === null || _d === void 0 ? void 0 : _d.distinct) === null || _e === void 0 ? void 0 : _e.map((distinct) => {
5160
+ ((_f = (_e = params.options) === null || _e === void 0 ? void 0 : _e.distinct) === null || _f === void 0 ? void 0 : _f.map((distinct) => {
5177
5161
  var _a, _b;
5178
5162
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === distinct)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === distinct);
5179
5163
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || distinct;
@@ -5194,34 +5178,34 @@ const withFindHasuraGraphQL = (MixinBase) => {
5194
5178
  []),
5195
5179
  ]);
5196
5180
  const data = result[this.tableName].map((row) => this.convertDataFromHasura(row));
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)
5181
+ const findResult = Object.assign(Object.assign(Object.assign({ data, count: enableCount ? result[`${this.tableName}_aggregate`].aggregate.count : Infinity }, (((_g = findOptions === null || findOptions === void 0 ? void 0 : findOptions.minimal) === null || _g === void 0 ? void 0 : _g.length)
5198
5182
  ? {
5199
5183
  minimal: findOptions.minimal.reduce((minimals, current) => {
5200
5184
  var _a;
5201
5185
  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])));
5202
5186
  }, {}),
5203
5187
  }
5204
- : {})), (((_g = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _g === void 0 ? void 0 : _g.length)
5188
+ : {})), (((_h = findOptions === null || findOptions === void 0 ? void 0 : findOptions.maximum) === null || _h === void 0 ? void 0 : _h.length)
5205
5189
  ? {
5206
5190
  maximum: findOptions.maximum.reduce((maximums, current) => {
5207
5191
  var _a;
5208
5192
  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])));
5209
5193
  }, {}),
5210
5194
  }
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) => {
5195
+ : {})), (((_j = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct) === null || _j === void 0 ? void 0 : _j.length) && {
5196
+ distinct: (_k = this.lastDistinct[tableFiltersNamed]) !== null && _k !== void 0 ? _k : (this.lastDistinct[tableFiltersNamed] = findOptions === null || findOptions === void 0 ? void 0 : findOptions.distinct.reduce((distinct, current) => {
5213
5197
  var _a, _b;
5214
5198
  const distinctOption = (_a = this.fields.find((fieldOption) => fieldOption === current)) !== null && _a !== void 0 ? _a : this.fields.find((fieldOption) => Object.keys(fieldOption).shift() === current);
5215
5199
  const fieldName = ((_b = Object.values(distinctOption).shift()) === null || _b === void 0 ? void 0 : _b.columnName) || current;
5216
5200
  return Object.assign(Object.assign({}, distinct), { [current.toString()]: result[`${this.tableName}_${current.toString()}_distinct`].map((obj) => obj[fieldName]) });
5217
5201
  }, {})),
5218
5202
  }));
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)) {
5203
+ if (((_l = this.cache) === null || _l === void 0 ? void 0 : _l.cacheAdapter) && ((_m = options === null || options === void 0 ? void 0 : options.cache) === null || _m === void 0 ? void 0 : _m.enabled)) {
5220
5204
  const cacheKey = generateCacheKey(this.model, params);
5221
5205
  await this.cache.cacheAdapter.set({
5222
5206
  key: cacheKey,
5223
5207
  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,
5208
+ expirationInSeconds: ((_o = options === null || options === void 0 ? void 0 : options.cache) === null || _o === void 0 ? void 0 : _o.ttl) || this.cache.ttlDefault,
5225
5209
  });
5226
5210
  this.logger.log(`Dados salvos no cache: ${cacheKey}`);
5227
5211
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infrab4a/connect",
3
- "version": "4.25.0-beta.3",
3
+ "version": "4.25.0-beta.5",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -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
  }