@zauru-sdk/services 6.7.1 → 6.7.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.
- package/dist/common.d.ts +4 -7
- package/dist/esm/common.js +62 -67
- package/package.json +4 -4
package/dist/common.d.ts
CHANGED
|
@@ -52,6 +52,10 @@ export type SessionMessage = {
|
|
|
52
52
|
export declare const saveSessionMessage: (session: Session, info: SessionMessage) => Promise<void>;
|
|
53
53
|
export declare const deleteSessionMessage: (session: Session, id: string) => Promise<boolean>;
|
|
54
54
|
export declare function generateDistinctCode(prefix: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Actualiza las variables en la sesión desde Zauru.
|
|
57
|
+
*/
|
|
58
|
+
export declare function actualizarVariables(headers: any, session: Session): Promise<VariableGraphQL[]>;
|
|
55
59
|
/**
|
|
56
60
|
*
|
|
57
61
|
* @param headers
|
|
@@ -63,10 +67,3 @@ export declare function getVariablesByName(headers: any, session: Session, names
|
|
|
63
67
|
[key: string]: string;
|
|
64
68
|
}>;
|
|
65
69
|
export declare function getVariablesSchemaByName(headers: any, session: Session, names: Array<string>): Promise<VariableGraphQL[]>;
|
|
66
|
-
/**
|
|
67
|
-
* Actualiza las variables en la sesión.
|
|
68
|
-
* @param {any} headers - Headers necesarios para la consulta.
|
|
69
|
-
* @param {Session} session - La sesión actual.
|
|
70
|
-
* @returns {Promise<void>}
|
|
71
|
-
*/
|
|
72
|
-
export declare function actualizarVariables(headers: any, session: Session): Promise<void>;
|
package/dist/esm/common.js
CHANGED
|
@@ -233,6 +233,52 @@ export function generateDistinctCode(prefix) {
|
|
|
233
233
|
const codigoProducto = `${prefix}-${uuid}`;
|
|
234
234
|
return codigoProducto;
|
|
235
235
|
}
|
|
236
|
+
const getCachedSessionVariables = (session) => {
|
|
237
|
+
const tempVars = session.get("variables");
|
|
238
|
+
return Array.isArray(tempVars) && tempVars.length ? tempVars : [];
|
|
239
|
+
};
|
|
240
|
+
const pickVariablesByName = (variables, names) => {
|
|
241
|
+
const returnObject = {};
|
|
242
|
+
for (const variable of variables) {
|
|
243
|
+
if (names.includes(variable.name)) {
|
|
244
|
+
returnObject[variable.name] = variable.value;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return returnObject;
|
|
248
|
+
};
|
|
249
|
+
const missingVariableNames = (names, found) => names.filter((name) => !Object.keys(found).includes(name));
|
|
250
|
+
/**
|
|
251
|
+
* Actualiza las variables en la sesión desde Zauru.
|
|
252
|
+
*/
|
|
253
|
+
export async function actualizarVariables(headers, session) {
|
|
254
|
+
const response = await getVariables(headers);
|
|
255
|
+
if (response.error) {
|
|
256
|
+
throw new Error(`${response.userMsg} - ${response.msg}`);
|
|
257
|
+
}
|
|
258
|
+
const variables = response.data ?? [];
|
|
259
|
+
session.set("variables", variables);
|
|
260
|
+
await commitSession(session);
|
|
261
|
+
console.log("Variables actualizadas y sesión refrescada.");
|
|
262
|
+
return variables;
|
|
263
|
+
}
|
|
264
|
+
const getSessionVariables = async (headers, session, options) => {
|
|
265
|
+
if (!options?.refresh) {
|
|
266
|
+
const cached = getCachedSessionVariables(session);
|
|
267
|
+
if (cached.length) {
|
|
268
|
+
return { variables: cached, refreshed: false };
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
variables: await actualizarVariables(headers, session),
|
|
273
|
+
refreshed: true,
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
const assertRequestedVariablesFound = (names, found) => {
|
|
277
|
+
const noEncontradas = missingVariableNames(names, found);
|
|
278
|
+
if (noEncontradas.length) {
|
|
279
|
+
throw new Error(`No se encontraron las variables: ${noEncontradas.join(",")} pruebe cerrar e iniciar sesión nuevamente para continuar.`);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
236
282
|
/**
|
|
237
283
|
*
|
|
238
284
|
* @param headers
|
|
@@ -241,78 +287,27 @@ export function generateDistinctCode(prefix) {
|
|
|
241
287
|
* @returns
|
|
242
288
|
*/
|
|
243
289
|
export async function getVariablesByName(headers, session, names) {
|
|
244
|
-
|
|
245
|
-
let
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
else {
|
|
253
|
-
//si no están en la sesión, las obtengo de zauru y luego las guardo en la sesión
|
|
254
|
-
//Obtengo mis variables, para tener los tags solicitados
|
|
255
|
-
const response = await getVariables(headers);
|
|
256
|
-
if (response.error) {
|
|
257
|
-
throw new Error(`${response.userMsg} - ${response.msg}`);
|
|
290
|
+
let { variables, refreshed } = await getSessionVariables(headers, session);
|
|
291
|
+
let returnObject = pickVariablesByName(variables, names);
|
|
292
|
+
if (missingVariableNames(names, returnObject).length) {
|
|
293
|
+
if (!refreshed) {
|
|
294
|
+
({ variables } = await getSessionVariables(headers, session, {
|
|
295
|
+
refresh: true,
|
|
296
|
+
}));
|
|
297
|
+
returnObject = pickVariablesByName(variables, names);
|
|
258
298
|
}
|
|
259
|
-
|
|
260
|
-
return { id: x.id, name: x.name, value: x.value };
|
|
261
|
-
}));
|
|
262
|
-
await commitSession(session);
|
|
263
|
-
variables = response.data ?? [];
|
|
264
|
-
}
|
|
265
|
-
const filtrados = variables.filter((value) => names.includes(value.name));
|
|
266
|
-
const returnObject = {};
|
|
267
|
-
filtrados.forEach((variable) => {
|
|
268
|
-
returnObject[`${variable.name}`] = variable.value;
|
|
269
|
-
});
|
|
270
|
-
//Pregunto si todas las variables fueron encontradas o no
|
|
271
|
-
if (!names.every((variable) => Object.keys(returnObject).includes(variable))) {
|
|
272
|
-
const noEncontradas = names
|
|
273
|
-
.filter((variable) => !Object.keys(returnObject).includes(variable))
|
|
274
|
-
.join(",");
|
|
275
|
-
throw new Error(`No se encontraron las variables: ${noEncontradas} pruebe cerrar e iniciar sesión nuevamente para continuar.`);
|
|
299
|
+
assertRequestedVariablesFound(names, returnObject);
|
|
276
300
|
}
|
|
277
301
|
return returnObject;
|
|
278
302
|
}
|
|
279
303
|
export async function getVariablesSchemaByName(headers, session, names) {
|
|
280
|
-
|
|
281
|
-
let
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
//si no están en la sesión, las obtengo de zauru y luego las guardo en la sesión
|
|
290
|
-
//Obtengo mis variables, para tener los tags solicitados
|
|
291
|
-
const response = await getVariables(headers);
|
|
292
|
-
if (response.error) {
|
|
293
|
-
throw new Error(`${response.userMsg} - ${response.msg}`);
|
|
294
|
-
}
|
|
295
|
-
session.set("variables", response.data);
|
|
296
|
-
await commitSession(session);
|
|
297
|
-
variables = response.data ?? [];
|
|
304
|
+
let { variables, refreshed } = await getSessionVariables(headers, session);
|
|
305
|
+
let filtrados = variables.filter((value) => names.includes(value.name));
|
|
306
|
+
if (filtrados.length !== names.length && !refreshed) {
|
|
307
|
+
({ variables } = await getSessionVariables(headers, session, {
|
|
308
|
+
refresh: true,
|
|
309
|
+
}));
|
|
310
|
+
filtrados = variables.filter((value) => names.includes(value.name));
|
|
298
311
|
}
|
|
299
|
-
const filtrados = variables.filter((value) => names.includes(value.name));
|
|
300
312
|
return filtrados;
|
|
301
313
|
}
|
|
302
|
-
/**
|
|
303
|
-
* Actualiza las variables en la sesión.
|
|
304
|
-
* @param {any} headers - Headers necesarios para la consulta.
|
|
305
|
-
* @param {Session} session - La sesión actual.
|
|
306
|
-
* @returns {Promise<void>}
|
|
307
|
-
*/
|
|
308
|
-
export async function actualizarVariables(headers, session) {
|
|
309
|
-
// Intentamos obtener las variables desde el servidor
|
|
310
|
-
const response = await getVariables(headers);
|
|
311
|
-
if (response.error) {
|
|
312
|
-
throw new Error(`${response.userMsg} - ${response.msg}`);
|
|
313
|
-
}
|
|
314
|
-
// Guardamos las variables en la sesión
|
|
315
|
-
session.set("variables", response.data);
|
|
316
|
-
await commitSession(session);
|
|
317
|
-
console.log("Variables actualizadas y sesión refrescada.");
|
|
318
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/services",
|
|
3
|
-
"version": "6.7.
|
|
3
|
+
"version": "6.7.3",
|
|
4
4
|
"description": "Servicios de consulta a Zauru",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@remix-run/node": "^2.8.1",
|
|
28
28
|
"@upstash/redis": "^1.34.5",
|
|
29
|
-
"@zauru-sdk/common": "^6.3.
|
|
29
|
+
"@zauru-sdk/common": "^6.3.4",
|
|
30
30
|
"@zauru-sdk/config": "^6.0.0",
|
|
31
31
|
"@zauru-sdk/graphql": "^6.5.0",
|
|
32
|
-
"@zauru-sdk/types": "^6.
|
|
32
|
+
"@zauru-sdk/types": "^6.12.0",
|
|
33
33
|
"axios": "^1.6.7",
|
|
34
34
|
"chalk": "5.3.0",
|
|
35
35
|
"moment": "^2.30.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "f05db6e411cd5af8104570563e94d800e7b390e3"
|
|
38
38
|
}
|