d-drive-cli 1.1.0 → 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.
package/README.md CHANGED
@@ -4,32 +4,10 @@ Command-line tool for D-Drive cloud storage.
4
4
 
5
5
  ## Installation
6
6
 
7
- ### Option 1: NPM (Coming Soon)
8
7
  ```bash
9
8
  npm install -g d-drive-cli
10
9
  ```
11
10
 
12
- ### Option 2: Local Installation (Current)
13
- ```bash
14
- # Clone the repository
15
- git clone https://github.com/jasonzli-DEV/D-Drive.git
16
- cd D-Drive/cli
17
-
18
- # Build and install globally
19
- npm install
20
- npm run build
21
- npm install -g .
22
-
23
- # Verify installation
24
- d-drive --version
25
- ```
26
-
27
- ### Option 3: Direct from Repository
28
- ```bash
29
- # Install directly from GitHub (once published)
30
- npm install -g jasonzli-DEV/D-Drive/cli
31
- ```
32
-
33
11
  ## Configuration
34
12
 
35
13
  First, configure your API key:
@@ -20,21 +20,26 @@ async function configCommand(options) {
20
20
  if (options.key) {
21
21
  const spinner = (0, ora_1.default)('Validating API key...').start();
22
22
  try {
23
- // Test the API key by calling the /auth/me endpoint
23
+ // Normalize and test the API key by calling the /auth/me endpoint
24
24
  const config = (0, config_1.getConfig)();
25
25
  const apiUrl = options.url || config.apiUrl || 'http://localhost:5000/api';
26
- const response = await axios_1.default.get(`${apiUrl}/auth/me`, {
26
+ // Accept keys entered with or without the `dd_` prefix, and strip any accidental "Bearer " prefix
27
+ const rawKey = options.key.replace(/^Bearer\s+/i, '').trim();
28
+ const normalizedKey = rawKey.startsWith('dd_') ? rawKey : `dd_${rawKey}`;
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, {
27
32
  headers: {
28
- Authorization: `Bearer ${options.key}`,
33
+ Authorization: `Bearer ${normalizedKey}`,
29
34
  },
30
35
  timeout: 10000,
31
36
  });
32
- if (response.status === 200 && response.data) {
33
- (0, config_1.setConfig)('apiKey', options.key);
37
+ if (response.status === 200) {
38
+ (0, config_1.setConfig)('apiKey', normalizedKey);
34
39
  if (options.url) {
35
40
  (0, config_1.setConfig)('apiUrl', options.url);
36
41
  }
37
- 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!'));
38
43
  }
39
44
  else {
40
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.0",
3
+ "version": "1.1.2",
4
4
  "description": "D-Drive CLI tool for developers",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -23,23 +23,28 @@ export async function configCommand(options: ConfigOptions) {
23
23
  const spinner = ora('Validating API key...').start();
24
24
 
25
25
  try {
26
- // Test the API key by calling the /auth/me endpoint
26
+ // Normalize and test the API key by calling the /auth/me endpoint
27
27
  const config = getConfig();
28
28
  const apiUrl = options.url || config.apiUrl || 'http://localhost:5000/api';
29
-
30
- const response = await axios.get(`${apiUrl}/auth/me`, {
29
+
30
+ // Accept keys entered with or without the `dd_` prefix, and strip any accidental "Bearer " prefix
31
+ const rawKey = options.key.replace(/^Bearer\s+/i, '').trim();
32
+ const normalizedKey = rawKey.startsWith('dd_') ? rawKey : `dd_${rawKey}`;
33
+
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, {
31
37
  headers: {
32
- Authorization: `Bearer ${options.key}`,
38
+ Authorization: `Bearer ${normalizedKey}`,
33
39
  },
34
40
  timeout: 10000,
35
41
  });
36
-
37
- if (response.status === 200 && response.data) {
38
- setConfig('apiKey', options.key);
42
+ if (response.status === 200) {
43
+ setConfig('apiKey', normalizedKey);
39
44
  if (options.url) {
40
45
  setConfig('apiUrl', options.url);
41
46
  }
42
- 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!'));
43
48
  } else {
44
49
  spinner.fail(chalk.red('✗ Invalid API key'));
45
50
  process.exit(1);