@hiyve/cli 1.0.7 → 1.0.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.
- package/package.json +1 -1
- package/src/commands/list.js +2 -2
- package/src/commands/login.js +3 -3
- package/src/commands/whoami.js +2 -2
- package/src/config.js +21 -7
- package/src/config.test.js +13 -6
- package/src/index.js +1 -1
package/package.json
CHANGED
package/src/commands/list.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import chalk from 'chalk';
|
|
8
8
|
import ora from 'ora';
|
|
9
|
-
import {
|
|
9
|
+
import { getApiUrl } from '../config.js';
|
|
10
10
|
import { getCurrentConfig } from '../utils/npmrc.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -30,7 +30,7 @@ export async function list() {
|
|
|
30
30
|
const spinner = ora('Fetching packages...').start();
|
|
31
31
|
|
|
32
32
|
try {
|
|
33
|
-
const response = await fetch(`${
|
|
33
|
+
const response = await fetch(`${getApiUrl()}packages`, {
|
|
34
34
|
headers: {
|
|
35
35
|
Authorization: `Bearer ${config.apiKey}`,
|
|
36
36
|
},
|
package/src/commands/login.js
CHANGED
|
@@ -8,7 +8,7 @@ import prompts from 'prompts';
|
|
|
8
8
|
import chalk from 'chalk';
|
|
9
9
|
import ora from 'ora';
|
|
10
10
|
import { configureNpmrc } from '../utils/npmrc.js';
|
|
11
|
-
import { getRegistryUrl } from '../config.js';
|
|
11
|
+
import { getApiUrl, getRegistryUrl } from '../config.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Login to Hiyve and configure npm
|
|
@@ -63,7 +63,7 @@ export async function login(options) {
|
|
|
63
63
|
const spinner = ora('Verifying API key...').start();
|
|
64
64
|
|
|
65
65
|
try {
|
|
66
|
-
const response = await fetch(`${
|
|
66
|
+
const response = await fetch(`${getApiUrl()}verify`, {
|
|
67
67
|
headers: {
|
|
68
68
|
Authorization: `Bearer ${apiKey}`,
|
|
69
69
|
},
|
|
@@ -111,7 +111,7 @@ export async function login(options) {
|
|
|
111
111
|
|
|
112
112
|
// Fetch available packages from registry
|
|
113
113
|
try {
|
|
114
|
-
const packagesResponse = await fetch(`${
|
|
114
|
+
const packagesResponse = await fetch(`${getApiUrl()}packages`, {
|
|
115
115
|
headers: { Authorization: `Bearer ${apiKey}` },
|
|
116
116
|
});
|
|
117
117
|
|
package/src/commands/whoami.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import chalk from 'chalk';
|
|
8
8
|
import ora from 'ora';
|
|
9
9
|
import { getCurrentConfig } from '../utils/npmrc.js';
|
|
10
|
-
import {
|
|
10
|
+
import { getApiUrl } from '../config.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Show current authentication status
|
|
@@ -39,7 +39,7 @@ export async function whoami() {
|
|
|
39
39
|
const spinner = ora('Verifying with server...').start();
|
|
40
40
|
|
|
41
41
|
try {
|
|
42
|
-
const response = await fetch(`${
|
|
42
|
+
const response = await fetch(`${getApiUrl()}verify`, {
|
|
43
43
|
headers: {
|
|
44
44
|
Authorization: `Bearer ${config.apiKey}`,
|
|
45
45
|
},
|
package/src/config.js
CHANGED
|
@@ -1,31 +1,45 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hiyve CLI Configuration
|
|
3
|
+
*
|
|
4
|
+
* Two URLs matter:
|
|
5
|
+
* - API URL: where the CLI talks to (verify, list, packages). Switches with --dev.
|
|
6
|
+
* - Registry URL: what goes into ~/.npmrc for npm to fetch tarballs. Always prod.
|
|
3
7
|
*/
|
|
4
8
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
9
|
+
const PROD_API_URL = 'https://api.hiyve.dev/registry/';
|
|
10
|
+
const DEV_API_URL = 'https://api.muziemedia.com/registry/';
|
|
7
11
|
|
|
8
12
|
let _devMode = false;
|
|
9
13
|
|
|
10
14
|
/**
|
|
11
|
-
* Enable dev mode (
|
|
15
|
+
* Enable dev mode (CLI API calls go to api.muziemedia.com)
|
|
12
16
|
*/
|
|
13
17
|
export function setDevMode(enabled) {
|
|
14
18
|
_devMode = enabled;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
/**
|
|
18
|
-
* Get the
|
|
22
|
+
* Get the API URL for CLI operations (verify, list, packages).
|
|
23
|
+
* Switches between dev and prod based on --dev flag.
|
|
24
|
+
*/
|
|
25
|
+
export function getApiUrl() {
|
|
26
|
+
return _devMode ? DEV_API_URL : PROD_API_URL;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get the registry URL for ~/.npmrc (where npm fetches tarballs).
|
|
31
|
+
* Always prod — there is one S3 bucket, both APIs point to the same packages.
|
|
19
32
|
*/
|
|
20
33
|
export function getRegistryUrl() {
|
|
21
|
-
return
|
|
34
|
+
return PROD_API_URL;
|
|
22
35
|
}
|
|
23
36
|
|
|
24
|
-
// Backwards-compatible named export
|
|
25
|
-
export const REGISTRY_URL =
|
|
37
|
+
// Backwards-compatible named export
|
|
38
|
+
export const REGISTRY_URL = PROD_API_URL;
|
|
26
39
|
|
|
27
40
|
export default {
|
|
28
41
|
REGISTRY_URL,
|
|
42
|
+
getApiUrl,
|
|
29
43
|
getRegistryUrl,
|
|
30
44
|
setDevMode,
|
|
31
45
|
};
|
package/src/config.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import config, { REGISTRY_URL, getRegistryUrl, setDevMode } from './config.js';
|
|
2
|
+
import config, { REGISTRY_URL, getApiUrl, getRegistryUrl, setDevMode } from './config.js';
|
|
3
3
|
|
|
4
4
|
describe('config', () => {
|
|
5
5
|
it('exports REGISTRY_URL as a named export', () => {
|
|
@@ -11,15 +11,22 @@ describe('config', () => {
|
|
|
11
11
|
expect(config.REGISTRY_URL).toBe('https://api.hiyve.dev/registry/');
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
it('
|
|
14
|
+
it('getApiUrl returns prod URL by default', () => {
|
|
15
|
+
setDevMode(false);
|
|
16
|
+
expect(getApiUrl()).toBe('https://api.hiyve.dev/registry/');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('getApiUrl returns dev URL when dev mode is enabled', () => {
|
|
20
|
+
setDevMode(true);
|
|
21
|
+
expect(getApiUrl()).toBe('https://api.muziemedia.com/registry/');
|
|
15
22
|
setDevMode(false);
|
|
16
|
-
expect(getRegistryUrl()).toBe('https://api.hiyve.dev/registry/');
|
|
17
23
|
});
|
|
18
24
|
|
|
19
|
-
it('getRegistryUrl returns
|
|
25
|
+
it('getRegistryUrl always returns prod URL regardless of dev mode', () => {
|
|
26
|
+
setDevMode(false);
|
|
27
|
+
expect(getRegistryUrl()).toBe('https://api.hiyve.dev/registry/');
|
|
20
28
|
setDevMode(true);
|
|
21
|
-
expect(getRegistryUrl()).toBe('https://api.
|
|
22
|
-
// Reset
|
|
29
|
+
expect(getRegistryUrl()).toBe('https://api.hiyve.dev/registry/');
|
|
23
30
|
setDevMode(false);
|
|
24
31
|
});
|
|
25
32
|
});
|
package/src/index.js
CHANGED
|
@@ -9,4 +9,4 @@ export { logout } from './commands/logout.js';
|
|
|
9
9
|
export { whoami } from './commands/whoami.js';
|
|
10
10
|
export { init } from './commands/init.js';
|
|
11
11
|
export { configureNpmrc, removeNpmrc, getCurrentConfig } from './utils/npmrc.js';
|
|
12
|
-
export { REGISTRY_URL, getRegistryUrl, setDevMode } from './config.js';
|
|
12
|
+
export { REGISTRY_URL, getApiUrl, getRegistryUrl, setDevMode } from './config.js';
|