investira.sdk 2.4.26 → 2.4.28

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/CHANGELOG.md CHANGED
@@ -637,3 +637,7 @@ O contrutor para a criação das mensagem foi alterado.
637
637
  # 2.4.23
638
638
 
639
639
  - [dates] scheduleToDate com atributo nextDay
640
+
641
+ # 2.4.28
642
+
643
+ - [responses] serviceDataResponse com parametro de referencia a funcao
@@ -172,13 +172,14 @@ const arrays = {
172
172
  }
173
173
  for (const xItem of xItens) {
174
174
  //Força que valor seja uma string
175
- const xTmp = '' + xItem;
175
+ const xTmp = String(xItem).trim();
176
176
  //Somente incluir itens não vázios
177
177
  if (xTmp.length > 0) {
178
178
  xArray.push(`${pPrefix}${xTmp}${pSuffix}`);
179
179
  }
180
180
  }
181
- return xArray;
181
+ // Remove itens duplicados
182
+ return Array.from(new Set(xArray));
182
183
  },
183
184
  /**
184
185
  * Remove itens duplicados de um array
@@ -191,9 +192,10 @@ const arrays = {
191
192
  * @returns {Array} Novo array contendo apenas valores únicos
192
193
  */
193
194
  removeDuplicated: pArray => {
194
- return pArray.filter((pItem, pIndex) => {
195
- return pArray.indexOf(pItem) === pIndex;
196
- });
195
+ if (!pArray) {
196
+ return [];
197
+ }
198
+ return Array.from(new Set(pArray));
197
199
  },
198
200
  /**
199
201
  * Verifica se dois arrays são iguais
@@ -293,15 +293,18 @@ const formats = {
293
293
  'gmail.com',
294
294
  'outlook.com',
295
295
  'hotmail.com',
296
+ 'live.com',
296
297
  'icloud.com',
297
298
  'me.com',
298
299
  'zaz.com.br',
300
+ 'bol.com.br',
299
301
  'terra.com.br',
300
302
  'ig.com.br',
301
303
  'yahoo.com',
304
+ 'msn.com',
305
+ 'yahoo.com.br',
302
306
  'globo.com',
303
- 'uol.com.br',
304
- 'yahoo.com.br'
307
+ 'uol.com.br'
305
308
  ]);
306
309
 
307
310
  const pvNorm = pStr => (pStr ?? '').toString().normalize('NFKC').trim().toLowerCase();
@@ -1,5 +1,6 @@
1
1
  const { isObject } = require('./validators');
2
2
  const { arrayToObject } = require('./arrays');
3
+ const { i } = require('investira.sdk/lib/utils/invests');
3
4
 
4
5
  const responses = {
5
6
  /**
@@ -140,25 +141,45 @@ const responses = {
140
141
  *
141
142
  * @param {array} pMainResult Result principal
142
143
  * @param {*} [pClauses=null]
143
- * @param {*} [pTotalItensPromise=null] Promise que retorna a quantidade total de itens
144
+ * @param {*} [pReferenciaFuncao=null] Referencia a uma função que retorna uma promise que retorna a quantidade total de itens
144
145
  * @param {object} [pArrayToObjectParams=null] Parametros para a criação da chave dos objetos
145
146
  * - keyPropertyName
146
147
  * - keyFormatFunction
147
148
  * - keyPrefix
148
149
  * @returns {Promise}
149
150
  */
150
- serviceDataResponse: (pMainResult, pClauses = null, pTotalItensPromise = null, pArrayToObjectParams = null) => {
151
+ serviceDataResponse: async (
152
+ pMainResult,
153
+ pClauses = null,
154
+ pReferenciaFuncao = null,
155
+ pArrayToObjectParams = null
156
+ ) => {
151
157
  //Se size, para controle de paginação, foi definido, converte array em objeto e/ou busca quantidade total de registros
152
158
  let xMainResult = pMainResult;
153
- if (pClauses && pClauses.limit && pClauses.limit.size) {
159
+ if (pClauses?.limit?.size) {
154
160
  if (pArrayToObjectParams && pArrayToObjectParams.keyPropertyName) {
155
161
  //Converte array em objeto
156
162
  const { keyPropertyName, keyFormatFunction = null, keyPrefix = '_' } = pArrayToObjectParams;
157
163
  xMainResult = arrayToObject(pMainResult, keyPropertyName, keyFormatFunction, keyPrefix);
158
164
  }
159
- //Pesquisa quantidade total de registros
160
- if (pTotalItensPromise) {
161
- return pTotalItensPromise
165
+ if (pReferenciaFuncao) {
166
+ //Trata a referencia a função ou promise
167
+ //O correto é que seja informado uma referencia a uma função
168
+ //para evitar que ela seja chamada desnecessariamente já na linha de comando
169
+ //Foi mantido o código original para não quebrar funcionalidades existentes
170
+ return Promise.resolve()
171
+ .then(() => {
172
+ //Paremetro é uma referencia a uma função
173
+ if (typeof pReferenciaFuncao === 'function') {
174
+ //Executa a função
175
+ return pReferenciaFuncao();
176
+ //Parametro é uma promise
177
+ } else if (pReferenciaFuncao instanceof Promise) {
178
+ //Executa a promise
179
+ return pReferenciaFuncao;
180
+ }
181
+ return 0;
182
+ })
162
183
  .then(rCount => {
163
184
  return {
164
185
  data: xMainResult,
@@ -177,7 +198,7 @@ const responses = {
177
198
  * Retorna resultado no formado {data, pages, message}
178
199
  *
179
200
  * @param {*} pResult
180
- * @param {boolean} [pVerifyPage=true]
201
+ * @param {boolean} [pMessage=null]
181
202
  * @returns {object}
182
203
  */
183
204
  routeDataResponse: (pResult = {}, pMessage = null) => {
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "investira.sdk",
3
- "version": "2.4.26",
3
+ "version": "2.4.28",
4
4
  "author": "Investira",
5
5
  "description": "Investira SDK",
6
6
  "main": "index.js",
7
7
  "type": "commonjs",
8
8
  "registry": true,
9
- "raw": "investira.sdk@2.4.26",
9
+ "raw": "investira.sdk@2.4.28",
10
10
  "escapedName": "investira.sdk",
11
- "rawSpec": "2.4.26",
11
+ "rawSpec": "2.4.28",
12
12
  "saveSpec": null,
13
- "fetchSpec": "2.4.26",
13
+ "fetchSpec": "2.4.28",
14
14
  "homepage": "https://investira.com.br/",
15
15
  "engines": {
16
16
  "node": ">=11.11.0 <=18.12",