vigthoria-cli 1.11.45 → 1.11.47
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/auth.js +10 -3
- package/dist/utils/cli-state.d.ts +7 -0
- package/dist/utils/cli-state.js +18 -0
- package/package.json +1 -1
package/dist/commands/auth.js
CHANGED
|
@@ -4,6 +4,7 @@ import { homedir } from 'os';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import readline from 'readline';
|
|
6
6
|
import { Config } from '../utils/config.js';
|
|
7
|
+
import { clearGatewayPreflightCache } from '../utils/cli-state.js';
|
|
7
8
|
const DEFAULT_API_URL = 'https://coder.vigthoria.io';
|
|
8
9
|
const CONFIG_DIR = path.join(homedir(), '.vigthoria');
|
|
9
10
|
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
@@ -62,9 +63,11 @@ function syncSharedConfig(config) {
|
|
|
62
63
|
if (config.user?.email) {
|
|
63
64
|
shared.set('email', String(config.user.email));
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
// Always overwrite (never conditionally skip) so a fresh login can never
|
|
67
|
+
// leave a stale/rotated key behind from a prior session — a falsy value
|
|
68
|
+
// here explicitly clears the cache, forcing ensureV3ServiceKey() to fetch
|
|
69
|
+
// a real one on next use instead of silently trusting stale state.
|
|
70
|
+
shared.set('v3ServiceKey', config.v3ServiceKey || null);
|
|
68
71
|
}
|
|
69
72
|
catch {
|
|
70
73
|
// Keep legacy auth flow working even if shared config write fails.
|
|
@@ -148,12 +151,16 @@ export function saveAuthConfig(config) {
|
|
|
148
151
|
// Best-effort on non-POSIX filesystems.
|
|
149
152
|
}
|
|
150
153
|
syncSharedConfig(config);
|
|
154
|
+
// A fresh login must never be blocked by a stale cached gateway-preflight
|
|
155
|
+
// failure from a prior (invalid) session.
|
|
156
|
+
clearGatewayPreflightCache();
|
|
151
157
|
}
|
|
152
158
|
export function clearAuthConfig() {
|
|
153
159
|
if (existsSync(CONFIG_FILE)) {
|
|
154
160
|
rmSync(CONFIG_FILE, { force: true });
|
|
155
161
|
}
|
|
156
162
|
clearSharedConfigAuth();
|
|
163
|
+
clearGatewayPreflightCache();
|
|
157
164
|
}
|
|
158
165
|
export function getAuthToken() {
|
|
159
166
|
return process.env.VIGTHORIA_TOKEN || loadAuthConfig().token;
|
|
@@ -51,4 +51,11 @@ export declare function readCachedLatestVersion(maxAgeMs?: number): string | nul
|
|
|
51
51
|
export declare function writeCachedLatestVersion(latestVersion: string, notifiedFor?: string): void;
|
|
52
52
|
export declare function readGatewayPreflightCache(maxAgeMs?: number): boolean | null;
|
|
53
53
|
export declare function writeGatewayPreflightCache(valid: boolean): void;
|
|
54
|
+
/**
|
|
55
|
+
* Invalidate any cached gateway-preflight result. Must be called on
|
|
56
|
+
* every login/logout/token change so a stale cached `false` from a
|
|
57
|
+
* prior (invalid) session can never block the very next auth-protected
|
|
58
|
+
* command run right after a fresh, successful login.
|
|
59
|
+
*/
|
|
60
|
+
export declare function clearGatewayPreflightCache(): void;
|
|
54
61
|
export declare function isSafeNpmPackageSpec(spec: string): boolean;
|
package/dist/utils/cli-state.js
CHANGED
|
@@ -163,6 +163,24 @@ export function writeGatewayPreflightCache(valid) {
|
|
|
163
163
|
// Best-effort.
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Invalidate any cached gateway-preflight result. Must be called on
|
|
168
|
+
* every login/logout/token change so a stale cached `false` from a
|
|
169
|
+
* prior (invalid) session can never block the very next auth-protected
|
|
170
|
+
* command run right after a fresh, successful login.
|
|
171
|
+
*/
|
|
172
|
+
export function clearGatewayPreflightCache() {
|
|
173
|
+
try {
|
|
174
|
+
const state = readStateUnchecked();
|
|
175
|
+
if (state.gatewayPreflight) {
|
|
176
|
+
delete state.gatewayPreflight;
|
|
177
|
+
saveCliState(state);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
// Best-effort.
|
|
182
|
+
}
|
|
183
|
+
}
|
|
166
184
|
/**
|
|
167
185
|
* Validate an npm package spec used by `vigthoria update --from <spec>`.
|
|
168
186
|
* Returns `true` when the spec is acceptable. Rejects whitespace and
|