vigthoria-cli 1.9.9 → 1.9.10

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/README.md CHANGED
@@ -99,7 +99,7 @@ If you see `ENOTFOUND registry.npmjs.org`, try these solutions:
99
99
  4. **Direct tarball download:**
100
100
  ```bash
101
101
  # Download directly
102
- npm install -g https://coder.vigthoria.io/releases/vigthoria-cli-1.9.9.tgz
102
+ npm install -g https://coder.vigthoria.io/releases/vigthoria-cli-1.9.10.tgz
103
103
  ```
104
104
 
105
105
  5. **Use Git clone method (no npm registry needed):**
package/dist/utils/api.js CHANGED
@@ -467,19 +467,20 @@ class APIClient {
467
467
  async validateToken(options = {}) {
468
468
  const allowNetworkFailOpen = options.allowNetworkFailOpen !== false;
469
469
  const enforceTokenShape = options.enforceTokenShape !== false;
470
+ const explicitEnvToken = Boolean(process.env.VIGTHORIA_TOKEN || process.env.VIGTHORIA_AUTH_TOKEN);
470
471
  const token = this.getAccessToken();
471
472
  if (!token) {
472
473
  return { valid: false, error: 'No auth token configured. Run: vigthoria login' };
473
474
  }
474
- // Fast-fail obviously malformed tokens so invalid-token checks don't get
475
- // masked by unrelated transport outages.
476
- if (enforceTokenShape) {
475
+ // Fast-fail obviously malformed ENV override tokens so invalid-token checks
476
+ // don't get masked by unrelated transport outages. Persisted login tokens may
477
+ // be non-JWT in some deployments and must still be gateway-validated server-side.
478
+ if (enforceTokenShape && explicitEnvToken) {
477
479
  const looksLikeJwt = token.split('.').length === 3;
478
480
  if (!looksLikeJwt || token.length < 40) {
479
481
  return { valid: false, error: 'Auth token expired or invalid. Run: vigthoria login' };
480
482
  }
481
483
  }
482
- const explicitEnvToken = Boolean(process.env.VIGTHORIA_TOKEN || process.env.VIGTHORIA_AUTH_TOKEN);
483
484
  const headers = {
484
485
  Authorization: `Bearer ${token}`,
485
486
  Cookie: `vigthoria-auth-token=${token}`,
@@ -495,16 +496,30 @@ class APIClient {
495
496
  if (r.status === 'fulfilled')
496
497
  return { valid: true };
497
498
  }
498
- for (const r of results) {
499
- if (r.status === 'rejected') {
500
- const err = r.reason;
501
- if (err.response?.status === 401 || err.response?.status === 403) {
502
- return { valid: false, error: 'Auth token expired or invalid. Run: vigthoria login' };
503
- }
504
- if (err instanceof CLIError && err.category === 'auth') {
505
- return { valid: false, error: 'Auth token expired or invalid. Run: vigthoria login' };
499
+ const sawUnauthorized = results.some((r) => r.status === 'rejected' && ((r.reason?.response?.status === 401) || (r.reason?.response?.status === 403) || (r.reason instanceof CLIError && r.reason.category === 'auth')));
500
+ if (sawUnauthorized) {
501
+ // For persisted CLI sessions, attempt one refresh before failing auth.
502
+ if (!explicitEnvToken) {
503
+ const refreshed = await this.refreshToken();
504
+ if (refreshed) {
505
+ const retryToken = this.getAccessToken();
506
+ if (retryToken) {
507
+ const retryHeaders = {
508
+ Authorization: `Bearer ${retryToken}`,
509
+ Cookie: `vigthoria-auth-token=${retryToken}`,
510
+ };
511
+ const retryResults = await Promise.allSettled([
512
+ axios_1.default.get(`${canonicalBaseUrl}/api/user/profile`, { timeout: 5000, headers: retryHeaders, httpsAgent: this._httpsAgent ?? undefined }),
513
+ axios_1.default.get(`${canonicalBaseUrl}/api/user/subscription`, { timeout: 5000, headers: retryHeaders, httpsAgent: this._httpsAgent ?? undefined }),
514
+ ]);
515
+ for (const rr of retryResults) {
516
+ if (rr.status === 'fulfilled')
517
+ return { valid: true };
518
+ }
519
+ }
506
520
  }
507
521
  }
522
+ return { valid: false, error: 'Auth token expired or invalid. Run: vigthoria login' };
508
523
  }
509
524
  if (explicitEnvToken || !allowNetworkFailOpen) {
510
525
  return { valid: false, error: 'Auth token expired or invalid. Run: vigthoria login' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vigthoria-cli",
3
- "version": "1.9.9",
3
+ "version": "1.9.10",
4
4
  "description": "Vigthoria Coder CLI - AI-powered terminal coding assistant",
5
5
  "main": "dist/index.js",
6
6
  "files": [