@zauru-sdk/services 2.0.146 → 2.0.148
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/sessions.js +2 -1
- package/dist/esm/sessions/upstash.js +31 -13
- package/dist/esm/zauru/httpCMS.js +2 -4
- package/dist/esm/zauru/httpGraphQL.js +1 -3
- package/dist/esm/zauru/httpOauth.js +1 -3
- package/dist/esm/zauru/httpUpstash.js +10 -0
- package/dist/esm/zauru/httpZauru.js +2 -4
- package/dist/sessions/upstash.d.ts +1 -0
- package/dist/zauru/httpUpstash.d.ts +1 -0
- package/package.json +2 -2
|
@@ -5,7 +5,8 @@ const sessionCookie = createCookie("_rj_session", {
|
|
|
5
5
|
path: "/",
|
|
6
6
|
sameSite: process.env.NODE_ENV === "production" ? "none" : "lax",
|
|
7
7
|
httpOnly: true,
|
|
8
|
-
maxAge: 60 * 60 *
|
|
8
|
+
maxAge: 60 * 60 * 24,
|
|
9
|
+
//expires,
|
|
9
10
|
secure: process.env.NODE_ENV === "production",
|
|
10
11
|
});
|
|
11
12
|
const { getSession, commitSession, destroySession } = createUpstashSessionStorage({ cookie: sessionCookie });
|
|
@@ -1,6 +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 axios from "axios";
|
|
4
5
|
const redisBaseURL = config.redisBaseURL;
|
|
5
6
|
const headers = {
|
|
6
7
|
Authorization: `Bearer ${config.redisToken}`,
|
|
@@ -10,43 +11,60 @@ const headers = {
|
|
|
10
11
|
const expiresToSeconds = (expires) => {
|
|
11
12
|
return Math.floor((expires.getTime() - new Date().getTime()) / 1000);
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
export async function fetchWithRetries(url, config = {}, retries = 3, backoff = 200) {
|
|
15
|
+
try {
|
|
16
|
+
return await axios.request({
|
|
17
|
+
url,
|
|
18
|
+
...config,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (retries > 0) {
|
|
23
|
+
console.warn(`=> Axios request falló (${url}), reintentando en ${backoff}ms... (${retries} intentos restantes)`, `Error message: ${error instanceof Error ? error.message : String(error)}`);
|
|
24
|
+
await new Promise((resolve) => setTimeout(resolve, backoff));
|
|
25
|
+
return fetchWithRetries(url, config, retries - 1, backoff * 2);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.error(`=> Axios request falló (${url}), no se pudo recuperar.`, `Error message: ${error instanceof Error ? error.message : String(error)}`);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
16
33
|
// For more info check https://remix.run/docs/en/v1/api/remix#createsessionstorage
|
|
17
34
|
export function createUpstashSessionStorage({ cookie }) {
|
|
18
35
|
return createSessionStorage({
|
|
19
36
|
cookie,
|
|
20
37
|
async createData(data, expires) {
|
|
21
|
-
const id = crypto.randomUUID()
|
|
22
|
-
await
|
|
38
|
+
const id = `${data?.selectedEntity}-${data?.employee_id}-${crypto.randomUUID()}`;
|
|
39
|
+
await fetchWithRetries(`${redisBaseURL}/set/${id}?EX=${expires ? expiresToSeconds(expires) : 60 * 60 * 8}`, {
|
|
23
40
|
method: "post",
|
|
24
|
-
|
|
41
|
+
data: { data },
|
|
25
42
|
headers,
|
|
26
43
|
});
|
|
27
44
|
return id;
|
|
28
45
|
},
|
|
29
46
|
async readData(id) {
|
|
30
|
-
const response = await
|
|
47
|
+
const response = await fetchWithRetries(`${redisBaseURL}/get/${id}`, {
|
|
31
48
|
headers,
|
|
32
49
|
});
|
|
33
50
|
try {
|
|
34
|
-
const { result } =
|
|
35
|
-
return JSON.parse(result)
|
|
51
|
+
const { result } = response?.data;
|
|
52
|
+
return JSON.parse(result)?.data;
|
|
36
53
|
}
|
|
37
54
|
catch (error) {
|
|
38
|
-
|
|
55
|
+
console.error("Error al leer la sesión: ", error);
|
|
56
|
+
return {};
|
|
39
57
|
}
|
|
40
58
|
},
|
|
41
59
|
async updateData(id, data, expires) {
|
|
42
|
-
await
|
|
60
|
+
await fetchWithRetries(`${redisBaseURL}/set/${id}?EX=${expires ? expiresToSeconds(expires) : 60 * 60 * 8}`, {
|
|
43
61
|
method: "post",
|
|
44
|
-
|
|
62
|
+
data: { data },
|
|
45
63
|
headers,
|
|
46
64
|
});
|
|
47
65
|
},
|
|
48
66
|
async deleteData(id) {
|
|
49
|
-
await
|
|
67
|
+
await fetchWithRetries(`${redisBaseURL}/del/${id}`, {
|
|
50
68
|
method: "post",
|
|
51
69
|
headers,
|
|
52
70
|
});
|
|
@@ -6,14 +6,13 @@ const axiosInstance = axios.create({
|
|
|
6
6
|
});
|
|
7
7
|
axiosInstance.interceptors.request.use(function (request) {
|
|
8
8
|
// Do something before request is sent
|
|
9
|
-
console.log("---------------- EJECUTANDO REQUEST CMS ----------------");
|
|
10
9
|
const baseName = `${request.baseURL}${request.url}`;
|
|
11
|
-
console.
|
|
10
|
+
console.log(chalk.green(baseName));
|
|
12
11
|
request.timeout = 200000;
|
|
13
12
|
return request;
|
|
14
13
|
}, function (error) {
|
|
15
14
|
console.log(chalk.red("---------------- ERROR CON REQUEST CMS ----------------"));
|
|
16
|
-
console.
|
|
15
|
+
console.error(`${error}`);
|
|
17
16
|
// Do something with request error
|
|
18
17
|
return Promise.reject(error);
|
|
19
18
|
});
|
|
@@ -21,7 +20,6 @@ axiosInstance.interceptors.request.use(function (request) {
|
|
|
21
20
|
axiosInstance.interceptors.response.use(function (response) {
|
|
22
21
|
// Do something with response data
|
|
23
22
|
const baseName = `${response.config.baseURL}${response.config.url}`;
|
|
24
|
-
console.timeEnd(baseName);
|
|
25
23
|
return response;
|
|
26
24
|
}, function (error) {
|
|
27
25
|
console.log(chalk.red("---------------- ERROR CON REQUEST CMS ----------------"));
|
|
@@ -6,9 +6,8 @@ const axiosInstance = axios.create({
|
|
|
6
6
|
});
|
|
7
7
|
axiosInstance.interceptors.request.use(function (request) {
|
|
8
8
|
// Do something before request is sent
|
|
9
|
-
console.log("---------------- EJECUTANDO REQUEST GRAPHQL ----------------");
|
|
10
9
|
const baseName = `${request.baseURL}${request.url}`;
|
|
11
|
-
console.
|
|
10
|
+
console.log(chalk.green(baseName));
|
|
12
11
|
request.timeout = 200000;
|
|
13
12
|
return request;
|
|
14
13
|
}, function (error) {
|
|
@@ -21,7 +20,6 @@ axiosInstance.interceptors.request.use(function (request) {
|
|
|
21
20
|
axiosInstance.interceptors.response.use(function (response) {
|
|
22
21
|
// Do something with response data
|
|
23
22
|
const baseName = `${response.config.baseURL}${response.config.url}`;
|
|
24
|
-
console.timeEnd(baseName);
|
|
25
23
|
return response;
|
|
26
24
|
}, function (error) {
|
|
27
25
|
console.log(chalk.red("---------------- ERROR CON REQUEST GRAPHQL ----------------"));
|
|
@@ -6,9 +6,8 @@ const axiosInstance = axios.create({
|
|
|
6
6
|
});
|
|
7
7
|
axiosInstance.interceptors.request.use(function (request) {
|
|
8
8
|
// Do something before request is sent
|
|
9
|
-
console.log("---------------- EJECUTANDO REQUEST ----------------");
|
|
10
9
|
const baseName = `${request.baseURL}${request.url}`;
|
|
11
|
-
console.
|
|
10
|
+
console.log(chalk.green(baseName));
|
|
12
11
|
request.timeout = 200000;
|
|
13
12
|
return request;
|
|
14
13
|
}, function (error) {
|
|
@@ -21,7 +20,6 @@ axiosInstance.interceptors.request.use(function (request) {
|
|
|
21
20
|
axiosInstance.interceptors.response.use(function (response) {
|
|
22
21
|
// Do something with response data
|
|
23
22
|
const baseName = `${response.config.baseURL}${response.config.url}`;
|
|
24
|
-
console.timeEnd(baseName);
|
|
25
23
|
return response;
|
|
26
24
|
}, function (error) {
|
|
27
25
|
console.log(chalk.red("---------------- ERROR CON REQUEST ----------------"));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import http from "node:http";
|
|
3
|
+
import https from "node:https";
|
|
4
|
+
const httpAgent = new http.Agent({ keepAlive: true });
|
|
5
|
+
const httpsAgent = new https.Agent({ keepAlive: true });
|
|
6
|
+
export const httpUpstash = axios.create({
|
|
7
|
+
httpAgent,
|
|
8
|
+
httpsAgent,
|
|
9
|
+
timeout: 5000,
|
|
10
|
+
});
|
|
@@ -6,9 +6,8 @@ const axiosInstance = axios.create({
|
|
|
6
6
|
});
|
|
7
7
|
axiosInstance.interceptors.request.use(function (request) {
|
|
8
8
|
// Do something before request is sent
|
|
9
|
-
console.log(`---------------- EJECUTANDO REQUEST ----------------`);
|
|
10
9
|
const baseName = `${request.baseURL}${request.url}`;
|
|
11
|
-
console.
|
|
10
|
+
console.log(chalk.green(baseName));
|
|
12
11
|
request.timeout = 200000;
|
|
13
12
|
return request;
|
|
14
13
|
}, function (error) {
|
|
@@ -21,7 +20,6 @@ axiosInstance.interceptors.request.use(function (request) {
|
|
|
21
20
|
axiosInstance.interceptors.response.use(function (response) {
|
|
22
21
|
// Do something with response data
|
|
23
22
|
const baseName = `${response.config.baseURL}${response.config.url}`;
|
|
24
|
-
console.timeEnd(baseName);
|
|
25
23
|
return response;
|
|
26
24
|
}, function (error) {
|
|
27
25
|
console.log(chalk.red("---------------- ERROR CON REQUEST (RESPONSE INTERCEPTOR) ----------------"));
|
|
@@ -30,7 +28,7 @@ axiosInstance.interceptors.response.use(function (response) {
|
|
|
30
28
|
const msgError = response
|
|
31
29
|
? `HTTP ${response.status} ${response.statusText} - URL: ${response?.config?.baseURL}${response?.config?.url} - ${JSON.stringify(response?.data)}`
|
|
32
30
|
: error;
|
|
33
|
-
console.
|
|
31
|
+
console.error(chalk.red(`${msgError}`));
|
|
34
32
|
throw new Error(msgError);
|
|
35
33
|
});
|
|
36
34
|
export const httpZauru = axiosInstance;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
+
export declare function fetchWithRetries(url: string, config?: {}, retries?: number, backoff?: number): Promise<import("axios").AxiosResponse<any, any> | null>;
|
|
1
2
|
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.148",
|
|
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": "b2598726a30e877d4af78777934c69045b7a81a8"
|
|
35
35
|
}
|