@zauru-sdk/services 2.0.190 → 2.0.192
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/index.js +1 -0
- package/dist/esm/redis/redisQueue.js +26 -0
- package/dist/esm/sessions/sessions.js +16 -10
- package/dist/index.d.ts +1 -0
- package/dist/redis/redisQueue.d.ts +2 -0
- package/package.json +3 -2
package/dist/esm/index.js
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Redis } from "@upstash/redis";
|
|
2
|
+
import { config } from "@zauru-sdk/config";
|
|
3
|
+
const redis = new Redis({
|
|
4
|
+
url: config.redisBaseURL,
|
|
5
|
+
token: config.redisToken,
|
|
6
|
+
});
|
|
7
|
+
// Función para intentar adquirir el lock
|
|
8
|
+
export async function acquireLock(key, lockValue, expiration) {
|
|
9
|
+
// Usamos SET con NX (solo si no existe) y PX para expirar el lock en milisegundos
|
|
10
|
+
const result = await redis.set(key, lockValue, {
|
|
11
|
+
nx: true,
|
|
12
|
+
pxat: Date.now() + expiration,
|
|
13
|
+
});
|
|
14
|
+
return result === "OK";
|
|
15
|
+
}
|
|
16
|
+
// Función para liberar el lock de forma segura usando un script Lua
|
|
17
|
+
export async function releaseLock(key, lockValue) {
|
|
18
|
+
const script = `
|
|
19
|
+
if redis.call("get", KEYS[1]) == ARGV[1] then
|
|
20
|
+
return redis.call("del", KEYS[1])
|
|
21
|
+
else
|
|
22
|
+
return 0
|
|
23
|
+
end
|
|
24
|
+
`;
|
|
25
|
+
await redis.eval(script, [key], [lockValue]);
|
|
26
|
+
}
|
|
@@ -11,17 +11,23 @@ const sessionCookie = createCookie("_rj_session", {
|
|
|
11
11
|
});
|
|
12
12
|
const { getSession, commitSession, destroySession } = createUpstashSessionStorage({ cookie: sessionCookie });
|
|
13
13
|
const getRefreshSession = async (request, session) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
try {
|
|
15
|
+
const cookie = request.headers.get("Cookie");
|
|
16
|
+
const currentSession = await getSession(cookie);
|
|
17
|
+
if (!currentSession) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return await commitSession(session, {
|
|
21
|
+
maxAge: 60 * 60 * 24,
|
|
22
|
+
path: "/",
|
|
23
|
+
sameSite: process.env.NODE_ENV === "production" ? "none" : "lax",
|
|
24
|
+
httpOnly: true,
|
|
25
|
+
secure: process.env.NODE_ENV === "production",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error("Ocurrio un error al refrescar la session", error);
|
|
17
30
|
return null;
|
|
18
31
|
}
|
|
19
|
-
return await commitSession(session, {
|
|
20
|
-
maxAge: 60 * 60 * 24,
|
|
21
|
-
path: "/",
|
|
22
|
-
sameSite: process.env.NODE_ENV === "production" ? "none" : "lax",
|
|
23
|
-
httpOnly: true,
|
|
24
|
-
secure: process.env.NODE_ENV === "production",
|
|
25
|
-
});
|
|
26
32
|
};
|
|
27
33
|
export { getSession, commitSession, destroySession, getRefreshSession };
|
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/services",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.192",
|
|
4
4
|
"description": "Servicios de consulta a Zauru",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@remix-run/node": "^2.8.1",
|
|
27
|
+
"@upstash/redis": "^1.34.5",
|
|
27
28
|
"@zauru-sdk/common": "^2.0.187",
|
|
28
29
|
"@zauru-sdk/config": "^2.0.100",
|
|
29
30
|
"@zauru-sdk/graphql": "^2.0.187",
|
|
@@ -31,5 +32,5 @@
|
|
|
31
32
|
"axios": "^1.6.7",
|
|
32
33
|
"chalk": "5.3.0"
|
|
33
34
|
},
|
|
34
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "f6269687436623477fdcb6e69011ee9560fcd905"
|
|
35
36
|
}
|