@zauru-sdk/services 2.0.145 → 2.0.147
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createSessionStorage } from "@remix-run/node";
|
|
2
2
|
import crypto from "crypto";
|
|
3
3
|
import { config } from "@zauru-sdk/config";
|
|
4
|
+
import axios from "axios";
|
|
4
5
|
const redisBaseURL = config.redisBaseURL;
|
|
5
6
|
const headers = {
|
|
6
7
|
Authorization: `Bearer ${config.redisToken}`,
|
|
@@ -10,43 +11,60 @@ const headers = {
|
|
|
10
11
|
const expiresToSeconds = (expires) => {
|
|
11
12
|
return Math.floor((expires.getTime() - new Date().getTime()) / 1000);
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
export async function fetchWithRetries(url, config = {}, retries = 3, backoff = 200) {
|
|
15
|
+
try {
|
|
16
|
+
return await axios.request({
|
|
17
|
+
url,
|
|
18
|
+
...config,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (retries > 0) {
|
|
23
|
+
console.warn(`=> Axios request falló (${url}), reintentando en ${backoff}ms... (${retries} intentos restantes)`, `Error message: ${error instanceof Error ? error.message : String(error)}`);
|
|
24
|
+
await new Promise((resolve) => setTimeout(resolve, backoff));
|
|
25
|
+
return fetchWithRetries(url, config, retries - 1, backoff * 2);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.error(`=> Axios request falló (${url}), no se pudo recuperar.`, `Error message: ${error instanceof Error ? error.message : String(error)}`);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
16
33
|
// For more info check https://remix.run/docs/en/v1/api/remix#createsessionstorage
|
|
17
34
|
export function createUpstashSessionStorage({ cookie }) {
|
|
18
35
|
return createSessionStorage({
|
|
19
36
|
cookie,
|
|
20
37
|
async createData(data, expires) {
|
|
21
|
-
const id = crypto.randomUUID()
|
|
22
|
-
await
|
|
38
|
+
const id = `${data?.selectedEntity}-${data?.employee_id}-${crypto.randomUUID()}`;
|
|
39
|
+
await fetchWithRetries(`${redisBaseURL}/set/${id}?EX=${expires ? expiresToSeconds(expires) : 60 * 60 * 8}`, {
|
|
23
40
|
method: "post",
|
|
24
|
-
|
|
41
|
+
data: { data },
|
|
25
42
|
headers,
|
|
26
43
|
});
|
|
27
44
|
return id;
|
|
28
45
|
},
|
|
29
46
|
async readData(id) {
|
|
30
|
-
const response = await
|
|
47
|
+
const response = await fetchWithRetries(`${redisBaseURL}/get/${id}`, {
|
|
31
48
|
headers,
|
|
32
49
|
});
|
|
33
50
|
try {
|
|
34
|
-
const { result } =
|
|
35
|
-
return JSON.parse(result)
|
|
51
|
+
const { result } = response?.data;
|
|
52
|
+
return JSON.parse(result)?.data;
|
|
36
53
|
}
|
|
37
54
|
catch (error) {
|
|
38
|
-
|
|
55
|
+
console.error("Error al leer la sesión: ", error);
|
|
56
|
+
return {};
|
|
39
57
|
}
|
|
40
58
|
},
|
|
41
59
|
async updateData(id, data, expires) {
|
|
42
|
-
await
|
|
60
|
+
await fetchWithRetries(`${redisBaseURL}/set/${id}?EX=${expires ? expiresToSeconds(expires) : 60 * 60 * 8}`, {
|
|
43
61
|
method: "post",
|
|
44
|
-
|
|
62
|
+
data: { data },
|
|
45
63
|
headers,
|
|
46
64
|
});
|
|
47
65
|
},
|
|
48
66
|
async deleteData(id) {
|
|
49
|
-
await
|
|
67
|
+
await fetchWithRetries(`${redisBaseURL}/del/${id}`, {
|
|
50
68
|
method: "post",
|
|
51
69
|
headers,
|
|
52
70
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import http from "node:http";
|
|
3
|
+
import https from "node:https";
|
|
4
|
+
const httpAgent = new http.Agent({ keepAlive: true });
|
|
5
|
+
const httpsAgent = new https.Agent({ keepAlive: true });
|
|
6
|
+
export const httpUpstash = axios.create({
|
|
7
|
+
httpAgent,
|
|
8
|
+
httpsAgent,
|
|
9
|
+
timeout: 5000,
|
|
10
|
+
});
|
|
@@ -1 +1,2 @@
|
|
|
1
|
+
export declare function fetchWithRetries(url: string, config?: {}, retries?: number, backoff?: number): Promise<import("axios").AxiosResponse<any, any> | null>;
|
|
1
2
|
export declare function createUpstashSessionStorage({ cookie }: any): import("@remix-run/node").SessionStorage<import("@remix-run/node").SessionData, import("@remix-run/node").SessionData>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const httpUpstash: import("axios").AxiosInstance;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/services",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.147",
|
|
4
4
|
"description": "Servicios de consulta a Zauru",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"axios": "^1.6.7",
|
|
32
32
|
"chalk": "5.3.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "ffc6b6dd78d0b4ebfdb3be4c50252b752db22d36"
|
|
35
35
|
}
|