@marcelo-cheruti/jwtgcp-sdk 1.0.1 → 1.0.2
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/package.json +9 -1
- package/src/authModule.js +8 -6
package/package.json
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marcelo-cheruti/jwtgcp-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/authModule.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"src/authModule.js"
|
|
8
8
|
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "vitest"
|
|
11
|
+
},
|
|
9
12
|
"keywords": [],
|
|
10
13
|
"author": "Marcelo Cheruti Caetano",
|
|
11
14
|
"type": "module",
|
|
12
15
|
"dependencies": {
|
|
13
16
|
"axios": "^1.13.4",
|
|
14
17
|
"axios-retry": "^4.5.0",
|
|
18
|
+
"date-fns": "^4.1.0",
|
|
15
19
|
"dotenv": "^17.2.3",
|
|
16
20
|
"jsonwebtoken": "^9.0.3",
|
|
17
21
|
"uuid": "^13.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"jest": "^30.2.0",
|
|
25
|
+
"vitest": "^4.0.18"
|
|
18
26
|
}
|
|
19
27
|
}
|
package/src/authModule.js
CHANGED
|
@@ -2,7 +2,7 @@ import axios from "axios";
|
|
|
2
2
|
import axiosRetry from "axios-retry";
|
|
3
3
|
import jwt from "jsonwebtoken";
|
|
4
4
|
import { v4 as uuidv4 } from "uuid";
|
|
5
|
-
|
|
5
|
+
import format from "date-fns"
|
|
6
6
|
axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay });
|
|
7
7
|
|
|
8
8
|
let GLOBAL_ACCESS_TOKEN = null;
|
|
@@ -55,7 +55,7 @@ export async function authFlow() {
|
|
|
55
55
|
"Content-Type": "application/json",
|
|
56
56
|
},
|
|
57
57
|
params: {
|
|
58
|
-
key:
|
|
58
|
+
key: _config.apiKey,
|
|
59
59
|
},
|
|
60
60
|
},
|
|
61
61
|
);
|
|
@@ -64,7 +64,7 @@ export async function authFlow() {
|
|
|
64
64
|
|
|
65
65
|
// 2. Chamada para Token passando o 'code'
|
|
66
66
|
const tokenRes = await axios.post(
|
|
67
|
-
|
|
67
|
+
_config.tokenUrl,
|
|
68
68
|
{
|
|
69
69
|
code: code,
|
|
70
70
|
},
|
|
@@ -82,8 +82,8 @@ export async function authFlow() {
|
|
|
82
82
|
},
|
|
83
83
|
);
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
return tokenRes.data.token;
|
|
86
|
+
|
|
87
87
|
} catch (error) {
|
|
88
88
|
console.error(
|
|
89
89
|
"Erro na autenticação:",
|
|
@@ -112,7 +112,9 @@ export async function getToken() {
|
|
|
112
112
|
if (!hasExpValid) {
|
|
113
113
|
console.log("Claims inválidos ou token expirado.");
|
|
114
114
|
GLOBAL_ACCESS_TOKEN = await authFlow();
|
|
115
|
-
console.log(
|
|
115
|
+
console.log(
|
|
116
|
+
`Gerado um novo token as ${format(new Date(), "dd/MM/yyyy HH:mm:ss.SSS")}`,
|
|
117
|
+
);
|
|
116
118
|
return GLOBAL_ACCESS_TOKEN;
|
|
117
119
|
}
|
|
118
120
|
|