@jtandrelevicius/utils-js-library 1.0.2 → 1.0.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 (2) hide show
  1. package/index.js +28 -19
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -20,11 +20,13 @@ class DataQueryService {
20
20
  */
21
21
  static normalizeResponse(rawValue) {
22
22
  try {
23
+ // Tenta parsear se for string, senão usa o valor original
23
24
  const parsedValue = typeof rawValue === 'string' ? JSON.parse(rawValue) : rawValue;
24
25
 
25
26
  if (!parsedValue) return [];
26
27
  if (Array.isArray(parsedValue)) return parsedValue;
27
28
 
29
+ // Lógica de fallback para estruturas aninhadas complexas (ex: respostas SAP/Legacy)
28
30
  let finalData = null;
29
31
 
30
32
  if (typeof parsedValue === 'object') {
@@ -244,7 +246,7 @@ class ExportService {
244
246
  });
245
247
  return row;
246
248
  });
247
-
249
+ // @ts-ignore
248
250
  const worksheet = XLSX.utils.json_to_sheet(formattedData);
249
251
  const workbook = XLSX.utils.book_new();
250
252
  XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
@@ -285,26 +287,33 @@ class ExportService {
285
287
  }
286
288
  }
287
289
 
288
- if (typeof window !== 'undefined') {
289
- window.JSK = DataQueryService;
290
- window.JFSK = FormatUtils;
291
- window.JOSK = SortUtils;
292
- window.JEXSK = ExportService;
290
+ // ==========================================
291
+ // DETECÇÃO DE AMBIENTE (Browser vs Node.js)
292
+ // ==========================================
293
293
 
294
+ const lib = {
295
+ DataQueryService,
296
+ FormatUtils,
297
+ SortUtils,
298
+ ExportService,
299
+ // Aliases para retrocompatibilidade
300
+ JSK: DataQueryService,
301
+ JFSK: FormatUtils,
302
+ JOSK: SortUtils,
303
+ JEXSK: ExportService
304
+ };
305
+
306
+ // Se estiver em ambiente Node.js/CommonJS
307
+ if (typeof module !== 'undefined' && module.exports) {
308
+ module.exports = lib;
309
+ }
310
+ // Se estiver no Browser (janela global)
311
+ else if (typeof window !== 'undefined') {
312
+ Object.assign(window, lib);
313
+
314
+ // Configuração automática se existir a função legado
294
315
  if (typeof window.executeQuery === 'function') {
295
316
  DataQueryService.setExecutor(window.executeQuery);
296
317
  console.log("[DataQueryService] Executor 'executeQuery' detectado e configurado automaticamente.");
297
318
  }
298
- }
299
-
300
- export {
301
- DataQueryService,
302
- FormatUtils,
303
- SortUtils,
304
- ExportService,
305
- // Aliases
306
- DataQueryService as JSK,
307
- FormatUtils as JFSK,
308
- SortUtils as JOSK,
309
- ExportService as JEXSK
310
- };
319
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jtandrelevicius/utils-js-library",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {