@zauru-sdk/services 2.0.126 → 2.0.128
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,13 +1,29 @@
|
|
|
1
1
|
import { createSessionStorage } from "@remix-run/node";
|
|
2
2
|
import crypto from "crypto";
|
|
3
3
|
import { config } from "@zauru-sdk/config";
|
|
4
|
+
import { httpUpstash } from "~/zauru/httpUpstash.js";
|
|
4
5
|
export const MAX_AGE_SESSION_COOKIE = 60 * 60 * 16; //16 hours
|
|
5
|
-
const redisBaseURL = config.redisBaseURL;
|
|
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 fetchWithRetriesAxios(url, config = {}, retries = 3, backoff = 200) {
|
|
12
|
+
try {
|
|
13
|
+
const response = await httpUpstash.request({ url, ...config });
|
|
14
|
+
return response.data;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (retries > 0) {
|
|
18
|
+
console.warn(`Axios request falló, reintentando en ${backoff}ms... (${retries} intentos restantes)`);
|
|
19
|
+
await new Promise((resolve) => setTimeout(resolve, backoff));
|
|
20
|
+
return fetchWithRetriesAxios(url, config, retries - 1, backoff * 2);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
11
27
|
// For more info check https://remix.run/docs/en/v1/api/remix#createsessionstorage
|
|
12
28
|
export function createUpstashSessionStorage({ cookie }) {
|
|
13
29
|
return createSessionStorage({
|
|
@@ -15,7 +31,7 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
15
31
|
async createData(data, expires) {
|
|
16
32
|
try {
|
|
17
33
|
const id = crypto.randomUUID();
|
|
18
|
-
await
|
|
34
|
+
await fetchWithRetriesAxios(`/set/${id}?EX=${MAX_AGE_SESSION_COOKIE}`, {
|
|
19
35
|
method: "post",
|
|
20
36
|
body: JSON.stringify({ data }),
|
|
21
37
|
headers,
|
|
@@ -29,7 +45,7 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
29
45
|
},
|
|
30
46
|
async readData(id) {
|
|
31
47
|
try {
|
|
32
|
-
const response = await
|
|
48
|
+
const response = await fetchWithRetriesAxios(`/get/${id}`, {
|
|
33
49
|
headers,
|
|
34
50
|
});
|
|
35
51
|
const { result } = (await response.json());
|
|
@@ -42,7 +58,7 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
42
58
|
},
|
|
43
59
|
async updateData(id, data, expires) {
|
|
44
60
|
try {
|
|
45
|
-
await
|
|
61
|
+
await fetchWithRetriesAxios(`/set/${id}?EX=${MAX_AGE_SESSION_COOKIE}`, {
|
|
46
62
|
method: "post",
|
|
47
63
|
body: JSON.stringify({ data }),
|
|
48
64
|
headers,
|
|
@@ -54,7 +70,7 @@ export function createUpstashSessionStorage({ cookie }) {
|
|
|
54
70
|
},
|
|
55
71
|
async deleteData(id) {
|
|
56
72
|
try {
|
|
57
|
-
await
|
|
73
|
+
await fetchWithRetriesAxios(`/del/${id}`, {
|
|
58
74
|
method: "post",
|
|
59
75
|
headers,
|
|
60
76
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { config } from "@zauru-sdk/config";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import http from "node:http";
|
|
4
|
+
import https from "node:https";
|
|
5
|
+
const httpAgent = new http.Agent({ keepAlive: true });
|
|
6
|
+
const httpsAgent = new https.Agent({ keepAlive: true });
|
|
7
|
+
export const httpUpstash = axios.create({
|
|
8
|
+
baseURL: `${config.redisBaseURL}`,
|
|
9
|
+
httpAgent,
|
|
10
|
+
httpsAgent,
|
|
11
|
+
timeout: 5000,
|
|
12
|
+
});
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare const MAX_AGE_SESSION_COOKIE: number;
|
|
2
|
+
export declare function fetchWithRetriesAxios(url: string, config?: {}, retries?: number, backoff?: number): Promise<any>;
|
|
2
3
|
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.128",
|
|
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": "1c1c74c6f25a3cacc53e2d9ee25e6a24f4bfe153"
|
|
35
35
|
}
|