@zauru-sdk/services 2.0.217 → 2.0.219
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/common.js +15 -10
- package/package.json +4 -4
package/dist/esm/common.js
CHANGED
|
@@ -106,15 +106,20 @@ async function getGraphQLToken(session) {
|
|
|
106
106
|
return handlePossibleAxiosErrors(async () => {
|
|
107
107
|
const token = (await session.get("graphqlToken"));
|
|
108
108
|
const headers = (await getHeaders(null, session));
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
109
|
+
// Check if token is missing or within one day of expiration
|
|
110
|
+
const now = Date.now();
|
|
111
|
+
let tokenHasExpired = true;
|
|
112
|
+
if (token && token.expires) {
|
|
113
|
+
const expiresAt = Date.parse(token.expires);
|
|
114
|
+
if (!isNaN(expiresAt)) {
|
|
115
|
+
const oneDayMs = 24 * 60 * 60 * 1000;
|
|
116
|
+
// Refresh if already expired or expires within the next 24 hours
|
|
117
|
+
tokenHasExpired = expiresAt <= now + oneDayMs;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// If there's no valid token or it's expiring soon, fetch a new one
|
|
121
|
+
if (tokenHasExpired) {
|
|
122
|
+
console.log(chalk.yellow(`=============== ⚠️ EL TOKEN GRAPHQL ESTÁ EXPIRADO O NO EXISTE ⚠️ ====================`));
|
|
118
123
|
const responseToken = await httpZauru.get("/apps/graphql.json", {
|
|
119
124
|
headers,
|
|
120
125
|
});
|
|
@@ -127,7 +132,7 @@ async function getGraphQLToken(session) {
|
|
|
127
132
|
console.log(chalk.red(`=============== ❗ NO HAY INFORMACIÓN OBTENIDA DEL REQUEST A ZAURU - GET_TOKEN ❗ ====================`));
|
|
128
133
|
throw new Error("No viene información en la solicitud de getGraphQLToken a Zauru");
|
|
129
134
|
}
|
|
130
|
-
//
|
|
135
|
+
// Return the existing valid token
|
|
131
136
|
return token;
|
|
132
137
|
});
|
|
133
138
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/services",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.219",
|
|
4
4
|
"description": "Servicios de consulta a Zauru",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@remix-run/node": "^2.8.1",
|
|
27
27
|
"@upstash/redis": "^1.34.5",
|
|
28
|
-
"@zauru-sdk/common": "^2.0.
|
|
28
|
+
"@zauru-sdk/common": "^2.0.218",
|
|
29
29
|
"@zauru-sdk/config": "^2.0.100",
|
|
30
30
|
"@zauru-sdk/graphql": "^2.0.216",
|
|
31
|
-
"@zauru-sdk/types": "^2.0.
|
|
31
|
+
"@zauru-sdk/types": "^2.0.218",
|
|
32
32
|
"axios": "^1.6.7",
|
|
33
33
|
"chalk": "5.3.0"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "c17d4fe2185c5db7a4da797db6fe57b67cce3b29"
|
|
36
36
|
}
|