nstantpage-agent 0.5.29 → 0.5.30
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/tunnel.d.ts +1 -0
- package/dist/tunnel.js +15 -6
- package/package.json +1 -1
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