@zauru-sdk/services 2.0.119 → 2.0.124

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,12 +1,12 @@
1
1
  import { createCookie } from "@remix-run/node";
2
2
  import { createUpstashSessionStorage } from "./upstash.js";
3
+ export const MAX_AGE_SESSION_COOKIE = 60 * 60 * 5; //5 hours
3
4
  const sessionCookie = createCookie("_rj_session", {
4
5
  secrets: ["r3m1xr0ck1"],
5
6
  path: "/",
6
7
  sameSite: process.env.NODE_ENV === "production" ? "none" : "lax",
7
8
  httpOnly: true,
8
- maxAge: 60 * 60 * 24,
9
- //expires,
9
+ maxAge: MAX_AGE_SESSION_COOKIE,
10
10
  secure: process.env.NODE_ENV === "production",
11
11
  });
12
12
  const { getSession, commitSession, destroySession } = createUpstashSessionStorage({ cookie: sessionCookie });
@@ -10,43 +10,61 @@ const headers = {
10
10
  //Le quité la expiración porque era muy corta para recepciones,
11
11
  //antes se definía algo así: await fetch(`${redisBaseURL}/set/${id}?EX=${expiresToSeconds(expires)}`
12
12
  //Estaba en el createData y en el updateData
13
+ //Ahora lo manejo en el maxAge de la cookie <- lo actualizo en cada request
13
14
  // For more info check https://remix.run/docs/en/v1/api/remix#createsessionstorage
14
15
  export function createUpstashSessionStorage({ cookie }) {
15
16
  return createSessionStorage({
16
17
  cookie,
17
18
  async createData(data, expires) {
18
- const id = crypto.randomUUID();
19
- await fetch(`${redisBaseURL}/set/${id}?EX=${259200}`, {
20
- method: "post",
21
- body: JSON.stringify({ data }),
22
- headers,
23
- });
24
- return id;
19
+ try {
20
+ const id = crypto.randomUUID();
21
+ await fetch(`${redisBaseURL}/set/${id}`, {
22
+ method: "post",
23
+ body: JSON.stringify({ data }),
24
+ headers,
25
+ });
26
+ return id;
27
+ }
28
+ catch (error) {
29
+ console.error("Error al crear la sesión", error);
30
+ return "";
31
+ }
25
32
  },
26
33
  async readData(id) {
27
- const response = await fetch(`${redisBaseURL}/get/${id}`, {
28
- headers,
29
- });
30
34
  try {
35
+ const response = await fetch(`${redisBaseURL}/get/${id}`, {
36
+ headers,
37
+ });
31
38
  const { result } = (await response.json());
32
39
  return JSON.parse(result).data;
33
40
  }
34
41
  catch (error) {
42
+ console.error("Error al leer la sesión", error);
35
43
  return null;
36
44
  }
37
45
  },
38
46
  async updateData(id, data, expires) {
39
- await fetch(`${redisBaseURL}/set/${id}?EX=${259200}`, {
40
- method: "post",
41
- body: JSON.stringify({ data }),
42
- headers,
43
- });
47
+ try {
48
+ await fetch(`${redisBaseURL}/set/${id}`, {
49
+ method: "post",
50
+ body: JSON.stringify({ data }),
51
+ headers,
52
+ });
53
+ }
54
+ catch (error) {
55
+ console.error("Error al actualizar la sesión", error);
56
+ }
44
57
  },
45
58
  async deleteData(id) {
46
- await fetch(`${redisBaseURL}/del/${id}`, {
47
- method: "post",
48
- headers,
49
- });
59
+ try {
60
+ await fetch(`${redisBaseURL}/del/${id}`, {
61
+ method: "post",
62
+ headers,
63
+ });
64
+ }
65
+ catch (error) {
66
+ console.error("Error al eliminar la sesión", error);
67
+ }
50
68
  },
51
69
  });
52
70
  }
@@ -1,2 +1,3 @@
1
+ export declare const MAX_AGE_SESSION_COOKIE: number;
1
2
  declare const getSession: (cookieHeader?: string | null, options?: import("cookie").CookieParseOptions) => Promise<import("@remix-run/node").Session<import("@remix-run/node").SessionData, import("@remix-run/node").SessionData>>, commitSession: (session: import("@remix-run/node").Session<import("@remix-run/node").SessionData, import("@remix-run/node").SessionData>, options?: import("cookie").CookieSerializeOptions) => Promise<string>, destroySession: (session: import("@remix-run/node").Session<import("@remix-run/node").SessionData, import("@remix-run/node").SessionData>, options?: import("cookie").CookieSerializeOptions) => Promise<string>;
2
3
  export { getSession, commitSession, destroySession };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/services",
3
- "version": "2.0.119",
3
+ "version": "2.0.124",
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": "56d56910cd5f8e311239d379369fd608dd697aea"
34
+ "gitHead": "d4458053906cd851edfd0c9f69cb6fcf945193de"
35
35
  }