@zauru-sdk/services 2.0.141 → 2.0.143
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,6 @@
|
|
|
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";
|
|
5
4
|
const redisBaseURL = config.redisBaseURL;
|
|
6
5
|
const headers = {
|
|
7
6
|
Authorization: `Bearer ${config.redisToken}`,
|
|
@@ -13,19 +12,16 @@ const expiresToSeconds = (expires) => {
|
|
|
13
12
|
};
|
|
14
13
|
export async function fetchWithRetries(url, config = {}, retries = 3, backoff = 200) {
|
|
15
14
|
try {
|
|
16
|
-
return await
|
|
17
|
-
url,
|
|
18
|
-
...config,
|
|
19
|
-
});
|
|
15
|
+
return await fetch(url, config);
|
|
20
16
|
}
|
|
21
17
|
catch (error) {
|
|
22
18
|
if (retries > 0) {
|
|
23
|
-
console.warn(`=>
|
|
19
|
+
console.warn(`=> Node Fetch request falló (${url}), reintentando en ${backoff}ms... (${retries} intentos restantes)`, `Error message: ${error instanceof Error ? error.message : String(error)}`);
|
|
24
20
|
await new Promise((resolve) => setTimeout(resolve, backoff));
|
|
25
21
|
return fetchWithRetries(url, config, retries - 1, backoff * 2);
|
|
26
22
|
}
|
|
27
23
|
else {
|
|
28
|
-
console.error(`=>
|
|
24
|
+
console.error(`=> Node Fetch request falló (${url}), no se pudo recuperar.`, `Error message: ${error instanceof Error ? error.message : String(error)}`);
|
|
29
25
|
return null;
|
|
30
26
|
}
|
|
31
27
|
}
|
|
@@ -35,20 +31,20 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
35
31
|
return createSessionStorage({
|
|
36
32
|
cookie,
|
|
37
33
|
async createData(data, expires) {
|
|
38
|
-
const id =
|
|
34
|
+
const id = crypto.randomUUID();
|
|
39
35
|
await fetchWithRetries(`${redisBaseURL}/set/${id}?EX=${expires ? expiresToSeconds(expires) : 60 * 60 * 8}`, {
|
|
40
36
|
method: "post",
|
|
41
|
-
|
|
37
|
+
body: JSON.stringify({ data }),
|
|
42
38
|
headers,
|
|
43
39
|
});
|
|
44
40
|
return id;
|
|
45
41
|
},
|
|
46
42
|
async readData(id) {
|
|
47
|
-
const response = await
|
|
43
|
+
const response = await fetch(`${redisBaseURL}/get/${id}`, {
|
|
48
44
|
headers,
|
|
49
45
|
});
|
|
50
46
|
try {
|
|
51
|
-
const { result } = response
|
|
47
|
+
const { result } = (await response.json());
|
|
52
48
|
return JSON.parse(result)?.data;
|
|
53
49
|
}
|
|
54
50
|
catch (error) {
|
|
@@ -59,7 +55,7 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
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<
|
|
1
|
+
export declare function fetchWithRetries(url: string, config?: {}, retries?: number, backoff?: number): Promise<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.143",
|
|
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": "de97bb773cbc14801c39cec4640a860261a9c5e0"
|
|
35
36
|
}
|