@zauru-sdk/services 2.0.137 → 2.0.139

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 { httpUpstash } from "../zauru/httpUpstash.js";
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 fetchWithRetriesAxios(url, config = {}, retries = 3, backoff = 200) {
11
+ export async function fetchWithRetries(url, config = {}, retries = 3, backoff = 200) {
12
12
  try {
13
- const response = await httpUpstash.request({ url, ...config });
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(`=> Axios request falló (${url}), reintentando en ${backoff}ms... (${retries} intentos restantes)`, `Error message: ${error instanceof Error ? error.message : String(error)}`);
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 fetchWithRetriesAxios(url, config, retries - 1, backoff * 2);
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 fetchWithRetriesAxios(`${config.redisBaseURL}/set/${id}?EX=${MAX_AGE_SESSION_COOKIE}`, {
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,10 +45,11 @@ export function createUpstashSessionStorage({ cookie }) {
45
45
  },
46
46
  async readData(id) {
47
47
  try {
48
- const response = await fetchWithRetriesAxios(`${config.redisBaseURL}/get/${id}`, {
48
+ const response = await fetchWithRetries(`${config.redisBaseURL}/get/${id}`, {
49
49
  headers,
50
50
  });
51
- return response;
51
+ const { result } = (await response.json());
52
+ return JSON.parse(result).data;
52
53
  }
53
54
  catch (error) {
54
55
  console.error("Error al leer la sesión", error);
@@ -57,9 +58,9 @@ export function createUpstashSessionStorage({ cookie }) {
57
58
  },
58
59
  async updateData(id, data, expires) {
59
60
  try {
60
- await fetchWithRetriesAxios(`${config.redisBaseURL}/set/${id}?EX=${MAX_AGE_SESSION_COOKIE}`, {
61
+ await fetchWithRetries(`${config.redisBaseURL}/set/${id}?EX=${MAX_AGE_SESSION_COOKIE}`, {
61
62
  method: "post",
62
- data,
63
+ body: JSON.stringify({ data }),
63
64
  headers,
64
65
  });
65
66
  }
@@ -69,7 +70,7 @@ export function createUpstashSessionStorage({ cookie }) {
69
70
  },
70
71
  async deleteData(id) {
71
72
  try {
72
- await fetchWithRetriesAxios(`${config.redisBaseURL}/del/${id}`, {
73
+ await fetchWithRetries(`${config.redisBaseURL}/del/${id}`, {
73
74
  method: "post",
74
75
  headers,
75
76
  });
@@ -1,3 +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<import("axios").AxiosResponse<any, any>>;
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.137",
3
+ "version": "2.0.139",
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": "1bb7bafd6aa4e93d505f87e7196cc02f9447cd04"
35
+ "gitHead": "551544150cd689596a8db6d7dbbe66c6fa2ca7c3"
35
36
  }