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 CHANGED
@@ -36,6 +36,7 @@ export declare class TunnelClient {
36
36
  private options;
37
37
  private reconnectTimer;
38
38
  private shouldReconnect;
39
+ private auth401Count;
39
40
  private reconnectAttempts;
40
41
  private maxReconnectAttempts;
41
42
  private pingInterval;
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 is invalid/expired/wrong-server. Stop retrying.
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.shouldReconnect = false;
175
- console.error(` [Tunnel] Authentication failed (401)`);
176
- console.error(chalk.red(` ✗ Your token was rejected by the gateway.`));
177
- console.error(chalk.gray(` This usually means you need to re-login:`));
178
- console.error(chalk.gray(` nstantpage logout && nstantpage login`));
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nstantpage-agent",
3
- "version": "0.5.29",
3
+ "version": "0.5.30",
4
4
  "description": "Local development agent for nstantpage.com — run your projects locally, preview in the cloud. Replaces cloud containers for faster builds.",
5
5
  "type": "module",
6
6
  "bin": {