d-drive-cli 1.1.1 → 1.1.2

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.
@@ -26,18 +26,20 @@ async function configCommand(options) {
26
26
  // Accept keys entered with or without the `dd_` prefix, and strip any accidental "Bearer " prefix
27
27
  const rawKey = options.key.replace(/^Bearer\s+/i, '').trim();
28
28
  const normalizedKey = rawKey.startsWith('dd_') ? rawKey : `dd_${rawKey}`;
29
- const response = await axios_1.default.get(`${apiUrl}/auth/me`, {
29
+ // Validate API key by calling a protected endpoint that accepts API keys (authenticate middleware)
30
+ const validateUrl = apiUrl.replace(/\/$/, '') + '/api-keys';
31
+ const response = await axios_1.default.get(validateUrl, {
30
32
  headers: {
31
33
  Authorization: `Bearer ${normalizedKey}`,
32
34
  },
33
35
  timeout: 10000,
34
36
  });
35
- if (response.status === 200 && response.data) {
37
+ if (response.status === 200) {
36
38
  (0, config_1.setConfig)('apiKey', normalizedKey);
37
39
  if (options.url) {
38
40
  (0, config_1.setConfig)('apiUrl', options.url);
39
41
  }
40
- spinner.succeed(chalk_1.default.green(`✓ API key validated and saved! Authenticated as: ${response.data.user?.discordUsername || 'User'}`));
42
+ spinner.succeed(chalk_1.default.green('✓ API key validated and saved!'));
41
43
  }
42
44
  else {
43
45
  spinner.fail(chalk_1.default.red('✗ Invalid API key'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "d-drive-cli",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "D-Drive CLI tool for developers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -31,19 +31,20 @@ export async function configCommand(options: ConfigOptions) {
31
31
  const rawKey = options.key.replace(/^Bearer\s+/i, '').trim();
32
32
  const normalizedKey = rawKey.startsWith('dd_') ? rawKey : `dd_${rawKey}`;
33
33
 
34
- const response = await axios.get(`${apiUrl}/auth/me`, {
34
+ // Validate API key by calling a protected endpoint that accepts API keys (authenticate middleware)
35
+ const validateUrl = apiUrl.replace(/\/$/, '') + '/api-keys';
36
+ const response = await axios.get(validateUrl, {
35
37
  headers: {
36
38
  Authorization: `Bearer ${normalizedKey}`,
37
39
  },
38
40
  timeout: 10000,
39
41
  });
40
-
41
- if (response.status === 200 && response.data) {
42
+ if (response.status === 200) {
42
43
  setConfig('apiKey', normalizedKey);
43
44
  if (options.url) {
44
45
  setConfig('apiUrl', options.url);
45
46
  }
46
- spinner.succeed(chalk.green(`✓ API key validated and saved! Authenticated as: ${response.data.user?.discordUsername || 'User'}`));
47
+ spinner.succeed(chalk.green('✓ API key validated and saved!'));
47
48
  } else {
48
49
  spinner.fail(chalk.red('✗ Invalid API key'));
49
50
  process.exit(1);