@zauru-sdk/services 2.0.127 → 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,29 +1,26 @@
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
- async function fetchWithRetries(url, options = {}, retries = 3, backoff = 200) {
11
+ export async function fetchWithRetriesAxios(url, config = {}, retries = 3, backoff = 200) {
12
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;
13
+ const response = await httpUpstash.request({ url, ...config });
14
+ return response.data;
18
15
  }
19
- catch (err) {
16
+ catch (error) {
20
17
  if (retries > 0) {
21
- console.warn(`Fetch falló, reintentando en ${backoff}ms... (${retries} intentos restantes)`);
18
+ console.warn(`Axios request falló, reintentando en ${backoff}ms... (${retries} intentos restantes)`);
22
19
  await new Promise((resolve) => setTimeout(resolve, backoff));
23
- return fetchWithRetries(url, options, retries - 1, backoff * 2);
20
+ return fetchWithRetriesAxios(url, config, retries - 1, backoff * 2);
24
21
  }
25
22
  else {
26
- throw err;
23
+ throw error;
27
24
  }
28
25
  }
29
26
  }
@@ -34,7 +31,7 @@ export function createUpstashSessionStorage({ cookie }) {
34
31
  async createData(data, expires) {
35
32
  try {
36
33
  const id = crypto.randomUUID();
37
- await fetchWithRetries(`${redisBaseURL}/set/${id}?EX=${MAX_AGE_SESSION_COOKIE}`, {
34
+ await fetchWithRetriesAxios(`/set/${id}?EX=${MAX_AGE_SESSION_COOKIE}`, {
38
35
  method: "post",
39
36
  body: JSON.stringify({ data }),
40
37
  headers,
@@ -48,7 +45,7 @@ export function createUpstashSessionStorage({ cookie }) {
48
45
  },
49
46
  async readData(id) {
50
47
  try {
51
- const response = await fetchWithRetries(`${redisBaseURL}/get/${id}`, {
48
+ const response = await fetchWithRetriesAxios(`/get/${id}`, {
52
49
  headers,
53
50
  });
54
51
  const { result } = (await response.json());
@@ -61,7 +58,7 @@ export function createUpstashSessionStorage({ cookie }) {
61
58
  },
62
59
  async updateData(id, data, expires) {
63
60
  try {
64
- await fetchWithRetries(`${redisBaseURL}/set/${id}?EX=${MAX_AGE_SESSION_COOKIE}`, {
61
+ await fetchWithRetriesAxios(`/set/${id}?EX=${MAX_AGE_SESSION_COOKIE}`, {
65
62
  method: "post",
66
63
  body: JSON.stringify({ data }),
67
64
  headers,
@@ -73,7 +70,7 @@ export function createUpstashSessionStorage({ cookie }) {
73
70
  },
74
71
  async deleteData(id) {
75
72
  try {
76
- await fetchWithRetries(`${redisBaseURL}/del/${id}`, {
73
+ await fetchWithRetriesAxios(`/del/${id}`, {
77
74
  method: "post",
78
75
  headers,
79
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.127",
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": "1a5c809b81d6d1c5a44be706cd98f840e45c9dd0"
34
+ "gitHead": "1c1c74c6f25a3cacc53e2d9ee25e6a24f4bfe153"
35
35
  }