faces-cli 1.5.8 → 1.5.9

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.
@@ -1,24 +1,90 @@
1
1
  import { BaseCommand } from '../../base.js';
2
- import { FacesAPIError } from '../../client.js';
2
+ import { FacesClient, FacesAPIError } from '../../client.js';
3
+ import { resolveBaseUrl, resolveToken, resolveApiKey } from '../../config.js';
3
4
  export default class AuthWhoami extends BaseCommand {
4
- static description = 'Print current user profile';
5
+ static description = 'Print current user profile and auth diagnostic';
5
6
  static flags = {
6
7
  ...BaseCommand.baseFlags,
7
8
  };
8
9
  async run() {
9
10
  const { flags } = await this.parse(AuthWhoami);
10
- const client = this.makeClient(flags);
11
- let data;
11
+ const baseUrl = resolveBaseUrl(flags['base-url']);
12
+ const token = resolveToken(flags.token);
13
+ const apiKey = resolveApiKey(flags['api-key']);
14
+ const json = this.jsonEnabled();
15
+ const diag = {
16
+ base_url: baseUrl,
17
+ jwt_configured: Boolean(token),
18
+ api_key_configured: Boolean(apiKey),
19
+ api_key_prefix: apiKey ? apiKey.slice(0, 12) + '...' : null,
20
+ };
21
+ // Try API key first (priority), then JWT
22
+ const credential = apiKey || token;
23
+ const method = apiKey ? 'api_key' : token ? 'jwt' : null;
24
+ if (!credential) {
25
+ diag.authenticated = false;
26
+ diag.auth_method = null;
27
+ diag.error = 'No credentials configured (no API key, no JWT)';
28
+ if (!json) {
29
+ process.stderr.write('Auth diagnostic:\n');
30
+ process.stderr.write(` base_url: ${baseUrl}\n`);
31
+ process.stderr.write(` jwt: not configured\n`);
32
+ process.stderr.write(` api_key: not configured\n`);
33
+ process.stderr.write(` status: not authenticated\n`);
34
+ }
35
+ return diag;
36
+ }
37
+ const client = new FacesClient(baseUrl, token, apiKey);
12
38
  try {
13
- data = await client.get('/auth/me');
39
+ const data = await client.get('/auth/me');
40
+ const inner = (data.data ?? data);
41
+ diag.authenticated = true;
42
+ diag.auth_method = method;
43
+ diag.user_id = inner.user_id;
44
+ diag.username = inner.username;
45
+ diag.email = inner.email;
46
+ diag.name = inner.name;
47
+ diag.is_admin = inner.is_admin;
48
+ if (!json) {
49
+ process.stderr.write('Auth diagnostic:\n');
50
+ process.stderr.write(` base_url: ${baseUrl}\n`);
51
+ process.stderr.write(` jwt: ${token ? 'configured' : 'not configured'}\n`);
52
+ process.stderr.write(` api_key: ${apiKey ? diag.api_key_prefix : 'not configured'}\n`);
53
+ process.stderr.write(` auth_method: ${method}\n`);
54
+ process.stderr.write(` status: authenticated\n`);
55
+ process.stderr.write('\n');
56
+ process.stderr.write(` user_id: ${inner.user_id}\n`);
57
+ process.stderr.write(` username: ${inner.username}\n`);
58
+ process.stderr.write(` email: ${inner.email}\n`);
59
+ process.stderr.write(` name: ${inner.name}\n`);
60
+ }
61
+ return diag;
14
62
  }
15
63
  catch (err) {
16
- if (err instanceof FacesAPIError)
17
- this.error(`Error (${err.statusCode}): ${err.message}`);
18
- throw err;
64
+ const errMsg = err instanceof FacesAPIError ? `${err.statusCode}: ${err.message}` : String(err);
65
+ diag.authenticated = false;
66
+ diag.auth_method = method;
67
+ diag.error = errMsg;
68
+ // If API key failed, also report JWT state
69
+ if (method === 'api_key' && token) {
70
+ diag.jwt_status = 'configured but not tried (API key takes priority)';
71
+ }
72
+ if (method === 'jwt') {
73
+ diag.jwt_status = 'failed';
74
+ if (apiKey) {
75
+ diag.api_key_status = 'configured but not valid for this endpoint';
76
+ }
77
+ }
78
+ if (!json) {
79
+ process.stderr.write('Auth diagnostic:\n');
80
+ process.stderr.write(` base_url: ${baseUrl}\n`);
81
+ process.stderr.write(` jwt: ${token ? 'configured' : 'not configured'}\n`);
82
+ process.stderr.write(` api_key: ${apiKey ? diag.api_key_prefix : 'not configured'}\n`);
83
+ process.stderr.write(` auth_method: ${method}\n`);
84
+ process.stderr.write(` status: failed\n`);
85
+ process.stderr.write(` error: ${errMsg}\n`);
86
+ }
87
+ return diag;
19
88
  }
20
- if (!this.jsonEnabled())
21
- this.printHuman(data);
22
- return data;
23
89
  }
24
90
  }
@@ -12,6 +12,10 @@ export default class ConfigSet extends BaseCommand {
12
12
  };
13
13
  async run() {
14
14
  const { args } = await this.parse(ConfigSet);
15
+ // Validate api_key prefix
16
+ if (args.key === 'api_key' && args.value && !args.value.startsWith('sk-faces-')) {
17
+ this.error('Faces API keys start with sk-faces-. This does not look like a Faces API key.');
18
+ }
15
19
  setConfigKey(args.key, args.value);
16
20
  this.log(`Set ${args.key}.`);
17
21
  return { key: args.key, status: 'set' };