@zauru-sdk/services 2.0.126 → 2.0.127
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/esm/sessions/upstash.js +23 -4
- package/package.json +2 -2
|
@@ -8,6 +8,25 @@ const headers = {
|
|
|
8
8
|
Accept: "application/json",
|
|
9
9
|
"Content-Type": "application/json",
|
|
10
10
|
};
|
|
11
|
+
async function fetchWithRetries(url, options = {}, retries = 3, backoff = 200) {
|
|
12
|
+
try {
|
|
13
|
+
const res = await fetch(url, options);
|
|
14
|
+
if (!res.ok) {
|
|
15
|
+
throw new Error(`HTTP error! status: ${res.status}`);
|
|
16
|
+
}
|
|
17
|
+
return res;
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
if (retries > 0) {
|
|
21
|
+
console.warn(`Fetch falló, reintentando en ${backoff}ms... (${retries} intentos restantes)`);
|
|
22
|
+
await new Promise((resolve) => setTimeout(resolve, backoff));
|
|
23
|
+
return fetchWithRetries(url, options, retries - 1, backoff * 2);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
11
30
|
// For more info check https://remix.run/docs/en/v1/api/remix#createsessionstorage
|
|
12
31
|
export function createUpstashSessionStorage({ cookie }) {
|
|
13
32
|
return createSessionStorage({
|
|
@@ -15,7 +34,7 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
15
34
|
async createData(data, expires) {
|
|
16
35
|
try {
|
|
17
36
|
const id = crypto.randomUUID();
|
|
18
|
-
await
|
|
37
|
+
await fetchWithRetries(`${redisBaseURL}/set/${id}?EX=${MAX_AGE_SESSION_COOKIE}`, {
|
|
19
38
|
method: "post",
|
|
20
39
|
body: JSON.stringify({ data }),
|
|
21
40
|
headers,
|
|
@@ -29,7 +48,7 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
29
48
|
},
|
|
30
49
|
async readData(id) {
|
|
31
50
|
try {
|
|
32
|
-
const response = await
|
|
51
|
+
const response = await fetchWithRetries(`${redisBaseURL}/get/${id}`, {
|
|
33
52
|
headers,
|
|
34
53
|
});
|
|
35
54
|
const { result } = (await response.json());
|
|
@@ -42,7 +61,7 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
42
61
|
},
|
|
43
62
|
async updateData(id, data, expires) {
|
|
44
63
|
try {
|
|
45
|
-
await
|
|
64
|
+
await fetchWithRetries(`${redisBaseURL}/set/${id}?EX=${MAX_AGE_SESSION_COOKIE}`, {
|
|
46
65
|
method: "post",
|
|
47
66
|
body: JSON.stringify({ data }),
|
|
48
67
|
headers,
|
|
@@ -54,7 +73,7 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
54
73
|
},
|
|
55
74
|
async deleteData(id) {
|
|
56
75
|
try {
|
|
57
|
-
await
|
|
76
|
+
await fetchWithRetries(`${redisBaseURL}/del/${id}`, {
|
|
58
77
|
method: "post",
|
|
59
78
|
headers,
|
|
60
79
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/services",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.127",
|
|
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": "1a5c809b81d6d1c5a44be706cd98f840e45c9dd0"
|
|
35
35
|
}
|