@zauru-sdk/services 2.0.137 → 2.0.138
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,23 +1,23 @@
|
|
|
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
|
export const MAX_AGE_SESSION_COOKIE = 60 * 60 * 16; //16 hours
|
|
6
6
|
const headers = {
|
|
7
7
|
Authorization: `Bearer ${config.redisToken}`,
|
|
8
8
|
Accept: "application/json",
|
|
9
9
|
"Content-Type": "application/json",
|
|
10
10
|
};
|
|
11
|
-
export async function
|
|
11
|
+
export async function fetchWithRetries(url, config = {}, retries = 3, backoff = 200) {
|
|
12
12
|
try {
|
|
13
|
-
const response = await
|
|
13
|
+
const response = await fetch(url, config);
|
|
14
14
|
return response;
|
|
15
15
|
}
|
|
16
16
|
catch (error) {
|
|
17
17
|
if (retries > 0) {
|
|
18
|
-
console.warn(`=>
|
|
18
|
+
console.warn(`=> Node Fetch request falló (${url}), reintentando en ${backoff}ms... (${retries} intentos restantes)`, `Error message: ${error instanceof Error ? error.message : String(error)}`);
|
|
19
19
|
await new Promise((resolve) => setTimeout(resolve, backoff));
|
|
20
|
-
return
|
|
20
|
+
return fetchWithRetries(url, config, retries - 1, backoff * 2);
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
23
|
throw error;
|
|
@@ -31,9 +31,9 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
31
31
|
async createData(data, expires) {
|
|
32
32
|
try {
|
|
33
33
|
const id = crypto.randomUUID();
|
|
34
|
-
await
|
|
34
|
+
await fetchWithRetries(`${config.redisBaseURL}/set/${id}?EX=${MAX_AGE_SESSION_COOKIE}`, {
|
|
35
35
|
method: "post",
|
|
36
|
-
data,
|
|
36
|
+
body: JSON.stringify({ data }),
|
|
37
37
|
headers,
|
|
38
38
|
});
|
|
39
39
|
return id;
|
|
@@ -45,7 +45,7 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
45
45
|
},
|
|
46
46
|
async readData(id) {
|
|
47
47
|
try {
|
|
48
|
-
const response = await
|
|
48
|
+
const response = await fetchWithRetries(`${config.redisBaseURL}/get/${id}`, {
|
|
49
49
|
headers,
|
|
50
50
|
});
|
|
51
51
|
return response;
|
|
@@ -57,9 +57,9 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
57
57
|
},
|
|
58
58
|
async updateData(id, data, expires) {
|
|
59
59
|
try {
|
|
60
|
-
await
|
|
60
|
+
await fetchWithRetries(`${config.redisBaseURL}/set/${id}?EX=${MAX_AGE_SESSION_COOKIE}`, {
|
|
61
61
|
method: "post",
|
|
62
|
-
data,
|
|
62
|
+
body: JSON.stringify({ data }),
|
|
63
63
|
headers,
|
|
64
64
|
});
|
|
65
65
|
}
|
|
@@ -69,7 +69,7 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
69
69
|
},
|
|
70
70
|
async deleteData(id) {
|
|
71
71
|
try {
|
|
72
|
-
await
|
|
72
|
+
await fetchWithRetries(`${config.redisBaseURL}/del/${id}`, {
|
|
73
73
|
method: "post",
|
|
74
74
|
headers,
|
|
75
75
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const MAX_AGE_SESSION_COOKIE: number;
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function fetchWithRetries(url: string, config?: {}, retries?: number, backoff?: number): Promise<import("node-fetch").Response>;
|
|
3
3
|
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.138",
|
|
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": "6168ec563ca136c0ffcb9bb6bf6d4d021dde6bb5"
|
|
35
36
|
}
|