@invizi/cli 0.1.1 → 0.1.3
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/auth.js +13 -23
- package/dist/invizi.js +6 -24
- package/package.json +1 -1
package/dist/auth.js
CHANGED
|
@@ -3,14 +3,17 @@ const DEFAULT_SCOPE = 'openid profile email offline_access';
|
|
|
3
3
|
function sleep(ms) {
|
|
4
4
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
5
5
|
}
|
|
6
|
+
// Defaults — public client-side values, not secrets
|
|
7
|
+
const AUTH0_DEFAULTS = {
|
|
8
|
+
domain: 'dev-u1fgwppsg73adwpc.us.auth0.com',
|
|
9
|
+
audience: 'https://api-dev.invizi.co',
|
|
10
|
+
clientId: 'RK5mtxCZygkrBkQr9n2CkgSkjFFsYSsI',
|
|
11
|
+
};
|
|
6
12
|
function getAuth0Config(config = loadConfig()) {
|
|
7
13
|
const auth = config.auth;
|
|
8
|
-
const domain = process.env.AUTH0_DOMAIN || config.auth0Domain || auth?.domain;
|
|
9
|
-
const audience = process.env.AUTH0_AUDIENCE || config.auth0Audience || auth?.audience;
|
|
10
|
-
const clientId = process.env.AUTH0_CLIENT_ID || config.auth0ClientId || auth?.clientId;
|
|
11
|
-
if (!domain || !audience || !clientId) {
|
|
12
|
-
throw new Error('Missing AUTH0_DOMAIN, AUTH0_AUDIENCE, or AUTH0_CLIENT_ID. Set env vars or save them in config.');
|
|
13
|
-
}
|
|
14
|
+
const domain = process.env.AUTH0_DOMAIN || config.auth0Domain || auth?.domain || AUTH0_DEFAULTS.domain;
|
|
15
|
+
const audience = process.env.AUTH0_AUDIENCE || config.auth0Audience || auth?.audience || AUTH0_DEFAULTS.audience;
|
|
16
|
+
const clientId = process.env.AUTH0_CLIENT_ID || config.auth0ClientId || auth?.clientId || AUTH0_DEFAULTS.clientId;
|
|
14
17
|
return { domain, audience, clientId };
|
|
15
18
|
}
|
|
16
19
|
function getStoredAuth() {
|
|
@@ -165,23 +168,9 @@ async function login() {
|
|
|
165
168
|
throw new Error('Login timed out before authorization completed.');
|
|
166
169
|
}
|
|
167
170
|
async function status() {
|
|
168
|
-
const auth = getStoredAuth();
|
|
169
|
-
if (!auth) {
|
|
170
|
-
if (process.env.INVIZI_API_KEY) {
|
|
171
|
-
console.log('No Auth0 token stored. Using INVIZI_API_KEY fallback.');
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
console.log('Not logged in. Run: invizi auth login');
|
|
175
|
-
return 1;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
const ttlSec = Math.max(0, Math.floor((auth.expiresAt - Date.now()) / 1000));
|
|
180
|
-
console.log(`Token: present (expires in ~${ttlSec}s)`);
|
|
181
|
-
}
|
|
182
171
|
const header = await getAuthorizationHeader();
|
|
183
172
|
if (!header) {
|
|
184
|
-
console.log('
|
|
173
|
+
console.log('Not logged in. Run: invizi auth login');
|
|
185
174
|
return 1;
|
|
186
175
|
}
|
|
187
176
|
// Use v1 protocol (auth.me) instead of /api/me (not exposed via nginx)
|
|
@@ -202,8 +191,9 @@ async function status() {
|
|
|
202
191
|
const me = response.result;
|
|
203
192
|
console.log(`User: ${me.id} (${me.role}) via ${me.authProvider}`);
|
|
204
193
|
let email = me.email || null;
|
|
205
|
-
|
|
206
|
-
|
|
194
|
+
const storedAuth = getStoredAuth();
|
|
195
|
+
if (!email && storedAuth?.accessToken && storedAuth?.domain) {
|
|
196
|
+
const profile = await fetchAuth0UserProfile(storedAuth.accessToken, storedAuth.domain);
|
|
207
197
|
email = inferEmail(profile);
|
|
208
198
|
}
|
|
209
199
|
if (email) {
|
package/dist/invizi.js
CHANGED
|
@@ -96,34 +96,16 @@ async function executeRemote(args, options = {}) {
|
|
|
96
96
|
export async function main(rawArgs = process.argv.slice(2)) {
|
|
97
97
|
const args = rawArgs;
|
|
98
98
|
const command = args[0];
|
|
99
|
-
if (!command) {
|
|
99
|
+
if (!command || command === '--help' || command === '-h') {
|
|
100
100
|
showLocalHelp();
|
|
101
|
-
return 0;
|
|
102
|
-
}
|
|
103
|
-
if (command === '--help' || command === '-h') {
|
|
104
101
|
const header = await getAuthorizationHeader();
|
|
105
|
-
if (
|
|
106
|
-
showLocalHelp();
|
|
107
|
-
return 0;
|
|
108
|
-
}
|
|
109
|
-
try {
|
|
110
|
-
await showRemoteHelp(header);
|
|
111
|
-
return 0;
|
|
112
|
-
}
|
|
113
|
-
catch {
|
|
102
|
+
if (header) {
|
|
114
103
|
try {
|
|
115
|
-
|
|
116
|
-
if (code !== 0) {
|
|
117
|
-
showLocalHelp();
|
|
118
|
-
return 0;
|
|
119
|
-
}
|
|
120
|
-
return code;
|
|
121
|
-
}
|
|
122
|
-
catch {
|
|
123
|
-
showLocalHelp();
|
|
124
|
-
return 0;
|
|
104
|
+
await showRemoteHelp(header);
|
|
125
105
|
}
|
|
106
|
+
catch { /* server unreachable — just show local */ }
|
|
126
107
|
}
|
|
108
|
+
return 0;
|
|
127
109
|
}
|
|
128
110
|
if (command === 'auth')
|
|
129
111
|
return auth(args.slice(1));
|
|
@@ -136,7 +118,7 @@ export async function main(rawArgs = process.argv.slice(2)) {
|
|
|
136
118
|
console.log(`\nConfig path: ${getConfigPath()}`);
|
|
137
119
|
return 0;
|
|
138
120
|
}
|
|
139
|
-
if (command === 'version') {
|
|
121
|
+
if (command === 'version' || command === '--version' || command === '-v') {
|
|
140
122
|
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
|
|
141
123
|
console.log(`invizi-cli v${pkg.version || 'unknown'}`);
|
|
142
124
|
return 0;
|