nstantpage-agent 0.5.29 → 0.5.31
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/commands/start.js +15 -0
- package/dist/tunnel.d.ts +1 -0
- package/dist/tunnel.js +15 -6
- package/package.json +1 -1
package/dist/commands/start.js
CHANGED
|
@@ -194,6 +194,21 @@ export async function startCommand(directory, options) {
|
|
|
194
194
|
if (!token && isLocalGateway) {
|
|
195
195
|
token = 'local-dev';
|
|
196
196
|
}
|
|
197
|
+
// Check token expiry before connecting
|
|
198
|
+
if (token && token !== 'local-dev') {
|
|
199
|
+
try {
|
|
200
|
+
const parts = token.split('.');
|
|
201
|
+
if (parts.length === 3) {
|
|
202
|
+
const payload = JSON.parse(Buffer.from(parts[1], 'base64').toString('utf-8'));
|
|
203
|
+
if (payload.exp && payload.exp < Date.now() / 1000) {
|
|
204
|
+
console.log(chalk.red('✗ Your authentication token has expired.'));
|
|
205
|
+
console.log(chalk.gray(' Run "nstantpage login" to re-authenticate.'));
|
|
206
|
+
process.exit(1);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch { }
|
|
211
|
+
}
|
|
197
212
|
// Determine project ID (optional — without it, agent enters standby mode)
|
|
198
213
|
// Only use explicitly passed --project-id, never fall back to stored value
|
|
199
214
|
let projectId = options.projectId;
|
package/dist/tunnel.d.ts
CHANGED
package/dist/tunnel.js
CHANGED
|
@@ -26,6 +26,7 @@ export class TunnelClient {
|
|
|
26
26
|
options;
|
|
27
27
|
reconnectTimer = null;
|
|
28
28
|
shouldReconnect = true;
|
|
29
|
+
auth401Count = 0;
|
|
29
30
|
reconnectAttempts = 0;
|
|
30
31
|
maxReconnectAttempts = Infinity; // Never give up — service should always reconnect
|
|
31
32
|
pingInterval = null;
|
|
@@ -108,6 +109,7 @@ export class TunnelClient {
|
|
|
108
109
|
this.ws.on('open', () => {
|
|
109
110
|
clearTimeout(connectTimeout);
|
|
110
111
|
this.reconnectAttempts = 0;
|
|
112
|
+
this.auth401Count = 0;
|
|
111
113
|
this.connectedAt = Date.now();
|
|
112
114
|
this.emitStatus('connected');
|
|
113
115
|
// Send enhanced agent info with capabilities and deviceId
|
|
@@ -169,13 +171,20 @@ export class TunnelClient {
|
|
|
169
171
|
this.ws.on('error', (err) => {
|
|
170
172
|
clearTimeout(connectTimeout);
|
|
171
173
|
const msg = err.message || '';
|
|
172
|
-
// Detect 401 — token
|
|
174
|
+
// Detect 401 — token may be invalid/expired, or gateway may be confused
|
|
175
|
+
// after boot (DNS was just resolving). Keep retrying with a longer delay
|
|
176
|
+
// instead of giving up permanently.
|
|
173
177
|
if (msg.includes('401')) {
|
|
174
|
-
this.
|
|
175
|
-
console.error(` [Tunnel] Authentication failed (401)`);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
this.auth401Count = (this.auth401Count || 0) + 1;
|
|
179
|
+
console.error(` [Tunnel] Authentication failed (401) — attempt ${this.auth401Count}`);
|
|
180
|
+
if (this.auth401Count <= 3) {
|
|
181
|
+
console.error(chalk.yellow(` ⚠ Token rejected — will retry (may be transient at boot)`));
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
console.error(chalk.red(` ✗ Persistent 401. Try: nstantpage logout && nstantpage login`));
|
|
185
|
+
}
|
|
186
|
+
// Bump reconnect attempts to get a longer backoff (at least 30s)
|
|
187
|
+
this.reconnectAttempts = Math.max(this.reconnectAttempts, 10);
|
|
179
188
|
if (this.reconnectAttempts === 0) {
|
|
180
189
|
reject(err);
|
|
181
190
|
}
|
package/package.json
CHANGED