@zauru-sdk/services 2.0.141 → 2.0.142
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,7 +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
|
|
4
|
+
import fetch from "node-fetch";
|
|
5
5
|
const redisBaseURL = config.redisBaseURL;
|
|
6
6
|
const headers = {
|
|
7
7
|
Authorization: `Bearer ${config.redisToken}`,
|
|
@@ -13,19 +13,16 @@ const expiresToSeconds = (expires) => {
|
|
|
13
13
|
};
|
|
14
14
|
export async function fetchWithRetries(url, config = {}, retries = 3, backoff = 200) {
|
|
15
15
|
try {
|
|
16
|
-
return await
|
|
17
|
-
url,
|
|
18
|
-
...config,
|
|
19
|
-
});
|
|
16
|
+
return await fetch(url, config);
|
|
20
17
|
}
|
|
21
18
|
catch (error) {
|
|
22
19
|
if (retries > 0) {
|
|
23
|
-
console.warn(`=>
|
|
20
|
+
console.warn(`=> Node Fetch request falló (${url}), reintentando en ${backoff}ms... (${retries} intentos restantes)`, `Error message: ${error instanceof Error ? error.message : String(error)}`);
|
|
24
21
|
await new Promise((resolve) => setTimeout(resolve, backoff));
|
|
25
22
|
return fetchWithRetries(url, config, retries - 1, backoff * 2);
|
|
26
23
|
}
|
|
27
24
|
else {
|
|
28
|
-
console.error(`=>
|
|
25
|
+
console.error(`=> Node Fetch request falló (${url}), no se pudo recuperar.`, `Error message: ${error instanceof Error ? error.message : String(error)}`);
|
|
29
26
|
return null;
|
|
30
27
|
}
|
|
31
28
|
}
|
|
@@ -35,31 +32,30 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
35
32
|
return createSessionStorage({
|
|
36
33
|
cookie,
|
|
37
34
|
async createData(data, expires) {
|
|
38
|
-
const id =
|
|
35
|
+
const id = crypto.randomUUID();
|
|
39
36
|
await fetchWithRetries(`${redisBaseURL}/set/${id}?EX=${expires ? expiresToSeconds(expires) : 60 * 60 * 8}`, {
|
|
40
37
|
method: "post",
|
|
41
|
-
|
|
38
|
+
body: JSON.stringify({ data }),
|
|
42
39
|
headers,
|
|
43
40
|
});
|
|
44
41
|
return id;
|
|
45
42
|
},
|
|
46
43
|
async readData(id) {
|
|
47
|
-
const response = await
|
|
44
|
+
const response = await fetch(`${redisBaseURL}/get/${id}`, {
|
|
48
45
|
headers,
|
|
49
46
|
});
|
|
50
47
|
try {
|
|
51
|
-
const { result } = response
|
|
52
|
-
return JSON.parse(result)
|
|
48
|
+
const { result } = (await response.json());
|
|
49
|
+
return JSON.parse(result).data;
|
|
53
50
|
}
|
|
54
51
|
catch (error) {
|
|
55
|
-
|
|
56
|
-
return {};
|
|
52
|
+
return null;
|
|
57
53
|
}
|
|
58
54
|
},
|
|
59
55
|
async updateData(id, data, expires) {
|
|
60
56
|
await fetchWithRetries(`${redisBaseURL}/set/${id}?EX=${expires ? expiresToSeconds(expires) : 60 * 60 * 8}`, {
|
|
61
57
|
method: "post",
|
|
62
|
-
|
|
58
|
+
body: JSON.stringify({ data }),
|
|
63
59
|
headers,
|
|
64
60
|
});
|
|
65
61
|
},
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function fetchWithRetries(url: string, config?: {}, retries?: number, backoff?: number): Promise<import("
|
|
1
|
+
export declare function fetchWithRetries(url: string, config?: {}, retries?: number, backoff?: number): Promise<import("node-fetch").Response | null>;
|
|
2
2
|
export declare function createUpstashSessionStorage({ cookie }: any): import("@remix-run/node").SessionStorage<import("@remix-run/node").SessionData, import("@remix-run/node").SessionData>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/services",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.142",
|
|
4
4
|
"description": "Servicios de consulta a Zauru",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"@zauru-sdk/graphql": "^2.0.119",
|
|
30
30
|
"@zauru-sdk/types": "^2.0.109",
|
|
31
31
|
"axios": "^1.6.7",
|
|
32
|
-
"chalk": "5.3.0"
|
|
32
|
+
"chalk": "5.3.0",
|
|
33
|
+
"node-fetch": "^3.3.2"
|
|
33
34
|
},
|
|
34
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "ba2c550a25f3195e12cd3e317df6d28696a46ff6"
|
|
35
36
|
}
|