@gopherhole/cli 0.1.18 → 0.1.20
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/index.js +31 -7
- package/package.json +1 -1
- package/src/index.ts +32 -7
package/dist/index.js
CHANGED
|
@@ -421,17 +421,36 @@ program
|
|
|
421
421
|
program
|
|
422
422
|
.command('whoami')
|
|
423
423
|
.description('Show current logged in user')
|
|
424
|
-
.action(() => {
|
|
425
|
-
const
|
|
426
|
-
const
|
|
427
|
-
|
|
424
|
+
.action(async () => {
|
|
425
|
+
const sessionId = config.get('sessionId');
|
|
426
|
+
const cachedUser = config.get('user');
|
|
427
|
+
const cachedTenant = config.get('tenant');
|
|
428
|
+
if (!sessionId || !cachedUser) {
|
|
428
429
|
console.log(chalk_1.default.yellow('Not logged in.'));
|
|
429
430
|
console.log(chalk_1.default.gray('\nTo log in: gopherhole login'));
|
|
430
431
|
console.log(chalk_1.default.gray('To sign up: gopherhole signup'));
|
|
431
432
|
process.exit(1);
|
|
432
433
|
}
|
|
433
|
-
|
|
434
|
-
|
|
434
|
+
// Validate session with server
|
|
435
|
+
try {
|
|
436
|
+
const res = await fetch(`${API_URL}/auth/me`, {
|
|
437
|
+
headers: { 'X-Session-ID': sessionId },
|
|
438
|
+
});
|
|
439
|
+
if (!res.ok) {
|
|
440
|
+
const data = await res.json().catch(() => ({}));
|
|
441
|
+
if (data.error === 'Session expired' || res.status === 401) {
|
|
442
|
+
console.log(chalk_1.default.red('Session expired.'));
|
|
443
|
+
console.log(chalk_1.default.gray('\nPlease log in again: gopherhole login'));
|
|
444
|
+
process.exit(1);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
catch {
|
|
449
|
+
// Network error - show cached info with warning
|
|
450
|
+
console.log(chalk_1.default.yellow('⚠ Could not verify session (offline?)\n'));
|
|
451
|
+
}
|
|
452
|
+
console.log(`\n ${chalk_1.default.bold('User:')} ${cachedUser.name} <${cachedUser.email}>`);
|
|
453
|
+
console.log(` ${chalk_1.default.bold('Org:')} ${cachedTenant?.name || 'Personal'}`);
|
|
435
454
|
console.log(` ${chalk_1.default.bold('Config:')} ${config.path}\n`);
|
|
436
455
|
});
|
|
437
456
|
// ========== AGENT COMMANDS ==========
|
|
@@ -1251,6 +1270,7 @@ ${chalk_1.default.bold('Examples:')}
|
|
|
1251
1270
|
.action(async (options) => {
|
|
1252
1271
|
const spinner = (0, ora_1.default)('Searching nearby agents...').start();
|
|
1253
1272
|
try {
|
|
1273
|
+
const sessionId = config.get('sessionId');
|
|
1254
1274
|
const params = new URLSearchParams();
|
|
1255
1275
|
params.set('lat', options.lat);
|
|
1256
1276
|
params.set('lng', options.lng);
|
|
@@ -1261,7 +1281,11 @@ ${chalk_1.default.bold('Examples:')}
|
|
|
1261
1281
|
params.set('category', options.category);
|
|
1262
1282
|
params.set('limit', options.limit);
|
|
1263
1283
|
log('GET /discover/agents/nearby?' + params.toString());
|
|
1264
|
-
const
|
|
1284
|
+
const headers = {};
|
|
1285
|
+
if (sessionId) {
|
|
1286
|
+
headers['X-Session-ID'] = sessionId;
|
|
1287
|
+
}
|
|
1288
|
+
const res = await fetch(`${API_URL}/discover/agents/nearby?${params}`, { headers });
|
|
1265
1289
|
const data = await res.json();
|
|
1266
1290
|
spinner.stop();
|
|
1267
1291
|
if (!data.agents || data.agents.length === 0) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -463,19 +463,39 @@ program
|
|
|
463
463
|
program
|
|
464
464
|
.command('whoami')
|
|
465
465
|
.description('Show current logged in user')
|
|
466
|
-
.action(() => {
|
|
467
|
-
const
|
|
468
|
-
const
|
|
466
|
+
.action(async () => {
|
|
467
|
+
const sessionId = config.get('sessionId') as string | undefined;
|
|
468
|
+
const cachedUser = config.get('user') as { email: string; name: string } | undefined;
|
|
469
|
+
const cachedTenant = config.get('tenant') as { name: string } | undefined;
|
|
469
470
|
|
|
470
|
-
if (!
|
|
471
|
+
if (!sessionId || !cachedUser) {
|
|
471
472
|
console.log(chalk.yellow('Not logged in.'));
|
|
472
473
|
console.log(chalk.gray('\nTo log in: gopherhole login'));
|
|
473
474
|
console.log(chalk.gray('To sign up: gopherhole signup'));
|
|
474
475
|
process.exit(1);
|
|
475
476
|
}
|
|
476
477
|
|
|
477
|
-
|
|
478
|
-
|
|
478
|
+
// Validate session with server
|
|
479
|
+
try {
|
|
480
|
+
const res = await fetch(`${API_URL}/auth/me`, {
|
|
481
|
+
headers: { 'X-Session-ID': sessionId },
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
if (!res.ok) {
|
|
485
|
+
const data = await res.json().catch(() => ({}));
|
|
486
|
+
if (data.error === 'Session expired' || res.status === 401) {
|
|
487
|
+
console.log(chalk.red('Session expired.'));
|
|
488
|
+
console.log(chalk.gray('\nPlease log in again: gopherhole login'));
|
|
489
|
+
process.exit(1);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
} catch {
|
|
493
|
+
// Network error - show cached info with warning
|
|
494
|
+
console.log(chalk.yellow('⚠ Could not verify session (offline?)\n'));
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
console.log(`\n ${chalk.bold('User:')} ${cachedUser.name} <${cachedUser.email}>`);
|
|
498
|
+
console.log(` ${chalk.bold('Org:')} ${cachedTenant?.name || 'Personal'}`);
|
|
479
499
|
console.log(` ${chalk.bold('Config:')} ${config.path}\n`);
|
|
480
500
|
});
|
|
481
501
|
|
|
@@ -1369,6 +1389,7 @@ ${chalk.bold('Examples:')}
|
|
|
1369
1389
|
const spinner = ora('Searching nearby agents...').start();
|
|
1370
1390
|
|
|
1371
1391
|
try {
|
|
1392
|
+
const sessionId = config.get('sessionId') as string;
|
|
1372
1393
|
const params = new URLSearchParams();
|
|
1373
1394
|
params.set('lat', options.lat);
|
|
1374
1395
|
params.set('lng', options.lng);
|
|
@@ -1378,7 +1399,11 @@ ${chalk.bold('Examples:')}
|
|
|
1378
1399
|
params.set('limit', options.limit);
|
|
1379
1400
|
|
|
1380
1401
|
log('GET /discover/agents/nearby?' + params.toString());
|
|
1381
|
-
const
|
|
1402
|
+
const headers: Record<string, string> = {};
|
|
1403
|
+
if (sessionId) {
|
|
1404
|
+
headers['X-Session-ID'] = sessionId;
|
|
1405
|
+
}
|
|
1406
|
+
const res = await fetch(`${API_URL}/discover/agents/nearby?${params}`, { headers });
|
|
1382
1407
|
const data = await res.json();
|
|
1383
1408
|
spinner.stop();
|
|
1384
1409
|
|