whistler-mcp 1.0.13 → 1.0.14
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/adapters/apiClient.js +20 -2
- package/package.json +1 -1
package/adapters/apiClient.js
CHANGED
|
@@ -6,14 +6,32 @@ import os from 'os';
|
|
|
6
6
|
const API_BASE_URL = process.env.API_URL || 'https://whistler-backend.onrender.com/api';
|
|
7
7
|
export const TOKEN_PATH = path.join(os.homedir(), '.whistler_mcp_token.json');
|
|
8
8
|
|
|
9
|
+
function isTokenExpired(token) {
|
|
10
|
+
try {
|
|
11
|
+
const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString('utf8'));
|
|
12
|
+
return payload.exp && payload.exp < Math.floor(Date.now() / 1000);
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
9
18
|
export function getSavedToken() {
|
|
10
19
|
if (fs.existsSync(TOKEN_PATH)) {
|
|
11
20
|
try {
|
|
12
21
|
const data = JSON.parse(fs.readFileSync(TOKEN_PATH, 'utf8'));
|
|
13
|
-
|
|
22
|
+
if (data.token) {
|
|
23
|
+
if (isTokenExpired(data.token)) {
|
|
24
|
+
// Remove the stale token file so the next call prompts re-login
|
|
25
|
+
fs.unlinkSync(TOKEN_PATH);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return data.token;
|
|
29
|
+
}
|
|
14
30
|
} catch (e) { }
|
|
15
31
|
}
|
|
16
|
-
|
|
32
|
+
const envToken = process.env.WHISTLER_API_TOKEN || null;
|
|
33
|
+
if (envToken && isTokenExpired(envToken)) return null;
|
|
34
|
+
return envToken;
|
|
17
35
|
}
|
|
18
36
|
|
|
19
37
|
export function saveToken(token, user) {
|