@teamvibe/poller 0.1.15 → 0.1.16
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/auth-provider.js +25 -0
- package/dist/brain-manager.d.ts +0 -1
- package/dist/types.d.ts +0 -1
- package/package.json +1 -1
package/dist/auth-provider.js
CHANGED
|
@@ -2,7 +2,25 @@ import { logger } from './logger.js';
|
|
|
2
2
|
let currentCredentials = null;
|
|
3
3
|
let currentConfig = null;
|
|
4
4
|
let refreshTimer = null;
|
|
5
|
+
let heartbeatTimer = null;
|
|
5
6
|
const REFRESH_INTERVAL_MS = 50 * 60 * 1000; // 50 minutes (before 1hr expiry)
|
|
7
|
+
const HEARTBEAT_INTERVAL_MS = 60 * 1000; // 1 minute
|
|
8
|
+
async function sendHeartbeat(apiUrl, token) {
|
|
9
|
+
try {
|
|
10
|
+
const response = await fetch(`${apiUrl}/heartbeat`, {
|
|
11
|
+
method: 'POST',
|
|
12
|
+
headers: {
|
|
13
|
+
Authorization: `Bearer ${token}`,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
logger.warn(`Heartbeat failed (${response.status})`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
logger.warn(`Heartbeat error: ${error instanceof Error ? error.message : error}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
6
24
|
async function fetchCredentials(apiUrl, token) {
|
|
7
25
|
const response = await fetch(`${apiUrl}/auth`, {
|
|
8
26
|
method: 'POST',
|
|
@@ -25,6 +43,9 @@ export async function initAuth(apiUrl, token) {
|
|
|
25
43
|
logger.info(`Authenticated successfully. Region: ${auth.config.region}`);
|
|
26
44
|
logger.info(` SQS Queue: ${auth.config.sqsQueueUrl}`);
|
|
27
45
|
logger.info(` Sessions Table: ${auth.config.sessionsTable}`);
|
|
46
|
+
// Send initial heartbeat and schedule periodic heartbeats
|
|
47
|
+
sendHeartbeat(apiUrl, token);
|
|
48
|
+
heartbeatTimer = setInterval(() => sendHeartbeat(apiUrl, token), HEARTBEAT_INTERVAL_MS);
|
|
28
49
|
// Schedule credential refresh
|
|
29
50
|
refreshTimer = setInterval(async () => {
|
|
30
51
|
try {
|
|
@@ -59,4 +80,8 @@ export function stopRefresh() {
|
|
|
59
80
|
clearInterval(refreshTimer);
|
|
60
81
|
refreshTimer = null;
|
|
61
82
|
}
|
|
83
|
+
if (heartbeatTimer) {
|
|
84
|
+
clearInterval(heartbeatTimer);
|
|
85
|
+
heartbeatTimer = null;
|
|
86
|
+
}
|
|
62
87
|
}
|
package/dist/brain-manager.d.ts
CHANGED
package/dist/types.d.ts
CHANGED