@capawesome/cli 4.13.0 → 4.14.0
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/CHANGELOG.md +10 -0
- package/README.md +12 -0
- package/dist/commands/login.js +10 -5
- package/dist/commands/login.test.js +35 -12
- package/dist/commands/logout.js +5 -1
- package/dist/commands/logout.test.js +16 -5
- package/dist/commands/whoami.js +2 -2
- package/dist/commands/whoami.test.js +5 -5
- package/dist/index.js +19 -0
- package/dist/services/authorization-service.js +6 -6
- package/dist/services/telemetry.js +31 -0
- package/dist/services/telemetry.test.js +67 -0
- package/dist/utils/credential-store.js +84 -0
- package/dist/utils/credential-store.test.js +84 -0
- package/dist/utils/job-failure-summary.js +1 -0
- package/package.json +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [4.14.0](https://github.com/capawesome-team/cli/compare/v4.13.0...v4.14.0) (2026-06-22)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* hint that failure summary can take up to a minute ([9e75e4f](https://github.com/capawesome-team/cli/commit/9e75e4f211aedae075a9509059a8fd2c7fb5c1f5))
|
|
11
|
+
* store authentication token in OS secure storage ([#175](https://github.com/capawesome-team/cli/issues/175)) ([337213d](https://github.com/capawesome-team/cli/commit/337213d4de900fef6ac52b9c0ae0166cdeded630))
|
|
12
|
+
* **telemetry:** add crash report notice and opt-out ([#173](https://github.com/capawesome-team/cli/issues/173)) ([0027ff2](https://github.com/capawesome-team/cli/commit/0027ff258ef18a293646330fd3d46b29e7b0c324))
|
|
13
|
+
* **telemetry:** attach user ID to crash reports ([#174](https://github.com/capawesome-team/cli/issues/174)) ([eeef34a](https://github.com/capawesome-team/cli/commit/eeef34a1aadbdd2a9b8f013e765155cdb1ea9b44))
|
|
14
|
+
|
|
5
15
|
## [4.13.0](https://github.com/capawesome-team/cli/compare/v4.12.0...v4.13.0) (2026-06-09)
|
|
6
16
|
|
|
7
17
|
|
package/README.md
CHANGED
|
@@ -32,6 +32,18 @@ The Capawesome Cloud CLI ships with command documentation that is accessible wit
|
|
|
32
32
|
npx @capawesome/cli --help
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
## Telemetry
|
|
36
|
+
|
|
37
|
+
The Capawesome Cloud CLI sends crash reports to help us identify and fix bugs. No usage analytics are collected.
|
|
38
|
+
|
|
39
|
+
To opt out, set the following environment variable:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
export CAPAWESOME_TELEMETRY_DISABLED=1
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Learn more in the [Telemetry documentation](https://capawesome.io/docs/cloud/cli/telemetry/).
|
|
46
|
+
|
|
35
47
|
## Development
|
|
36
48
|
|
|
37
49
|
### Getting Started
|
package/dist/commands/login.js
CHANGED
|
@@ -4,6 +4,7 @@ import sessionsService from '../services/sessions.js';
|
|
|
4
4
|
import usersService from '../services/users.js';
|
|
5
5
|
import { isInteractive } from '../utils/environment.js';
|
|
6
6
|
import { prompt } from '../utils/prompt.js';
|
|
7
|
+
import credentialStore from '../utils/credential-store.js';
|
|
7
8
|
import userConfig from '../utils/user-config.js';
|
|
8
9
|
import { defineCommand, defineOptions } from '@robingenz/zli';
|
|
9
10
|
import { AxiosError } from 'axios';
|
|
@@ -81,15 +82,19 @@ export default defineCommand({
|
|
|
81
82
|
}
|
|
82
83
|
// Sign in with the provided token
|
|
83
84
|
consola.start('Signing in...');
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
});
|
|
85
|
+
// Drop the previous user ID but keep other flags,
|
|
86
|
+
// so a crash during sign-in isn't attributed to the previous account
|
|
87
|
+
const { token: _previousToken, userId: _previousUserId, ...persistentConfig } = userConfig.read();
|
|
88
|
+
userConfig.write(persistentConfig);
|
|
89
|
+
credentialStore.setToken(sessionIdOrToken);
|
|
87
90
|
try {
|
|
88
|
-
await usersService.me();
|
|
91
|
+
const user = await usersService.me();
|
|
92
|
+
userConfig.write({ ...persistentConfig, userId: user.id });
|
|
89
93
|
consola.success(`Successfully signed in.`);
|
|
90
94
|
}
|
|
91
95
|
catch (error) {
|
|
92
|
-
|
|
96
|
+
// Clear the credentials on failure while preserving the other flags
|
|
97
|
+
credentialStore.deleteToken();
|
|
93
98
|
if (error instanceof AxiosError && error.response?.status === 401) {
|
|
94
99
|
consola.error(`Invalid token. Please provide a valid token. You can create a token at ${consoleBaseUrl}/settings/tokens.`);
|
|
95
100
|
process.exit(1);
|
|
@@ -2,6 +2,7 @@ import { DEFAULT_API_BASE_URL, DEFAULT_CONSOLE_BASE_URL } from '../config/consts
|
|
|
2
2
|
import configService from '../services/config.js';
|
|
3
3
|
import sessionCodesService from '../services/session-code.js';
|
|
4
4
|
import sessionsService from '../services/sessions.js';
|
|
5
|
+
import credentialStore from '../utils/credential-store.js';
|
|
5
6
|
import { prompt } from '../utils/prompt.js';
|
|
6
7
|
import userConfig from '../utils/user-config.js';
|
|
7
8
|
import consola from 'consola';
|
|
@@ -11,6 +12,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
11
12
|
import loginCommand from './login.js';
|
|
12
13
|
// Mock dependencies
|
|
13
14
|
vi.mock('@/utils/user-config.js');
|
|
15
|
+
vi.mock('@/utils/credential-store.js');
|
|
14
16
|
vi.mock('@/services/session-code.js');
|
|
15
17
|
vi.mock('@/services/sessions.js');
|
|
16
18
|
vi.mock('@/services/config.js');
|
|
@@ -20,11 +22,9 @@ vi.mock('@/utils/prompt.js');
|
|
|
20
22
|
vi.mock('@/utils/environment.js', () => ({
|
|
21
23
|
isInteractive: () => true,
|
|
22
24
|
}));
|
|
23
|
-
vi.mock('@/utils/environment.js', () => ({
|
|
24
|
-
isInteractive: () => true,
|
|
25
|
-
}));
|
|
26
25
|
describe('login', () => {
|
|
27
26
|
const mockUserConfig = vi.mocked(userConfig);
|
|
27
|
+
const mockCredentialStore = vi.mocked(credentialStore);
|
|
28
28
|
const mockSessionCodesService = vi.mocked(sessionCodesService);
|
|
29
29
|
const mockSessionsService = vi.mocked(sessionsService);
|
|
30
30
|
const mockConfigService = vi.mocked(configService);
|
|
@@ -35,6 +35,9 @@ describe('login', () => {
|
|
|
35
35
|
vi.clearAllMocks();
|
|
36
36
|
mockUserConfig.write.mockImplementation(() => { });
|
|
37
37
|
mockUserConfig.read.mockReturnValue({});
|
|
38
|
+
mockCredentialStore.setToken.mockImplementation(() => { });
|
|
39
|
+
mockCredentialStore.deleteToken.mockImplementation(() => { });
|
|
40
|
+
mockCredentialStore.getToken.mockReturnValue(null);
|
|
38
41
|
// Mock config service to return consistent URLs
|
|
39
42
|
mockConfigService.getValueForKey.mockImplementation((key) => {
|
|
40
43
|
if (key === 'CONSOLE_BASE_URL')
|
|
@@ -54,18 +57,38 @@ describe('login', () => {
|
|
|
54
57
|
it('should use the provided token for authentication', async () => {
|
|
55
58
|
const testToken = 'valid-token-123';
|
|
56
59
|
const options = { token: testToken };
|
|
57
|
-
// Mock
|
|
58
|
-
|
|
60
|
+
// Mock credentialStore.getToken to return our test token after it's written
|
|
61
|
+
mockCredentialStore.getToken.mockReturnValue(testToken);
|
|
59
62
|
// Set up nock to intercept the /v1/users/me request
|
|
60
63
|
const scope = nock(DEFAULT_API_BASE_URL)
|
|
61
64
|
.get('/v1/users/me')
|
|
62
65
|
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
63
66
|
.reply(200, { id: 'user-123', email: 'test@example.com' });
|
|
64
67
|
await loginCommand.action(options, undefined);
|
|
65
|
-
expect(
|
|
68
|
+
expect(mockCredentialStore.setToken).toHaveBeenCalledWith(testToken);
|
|
66
69
|
expect(scope.isDone()).toBe(true);
|
|
67
70
|
expect(mockConsola.success).toHaveBeenCalledWith('Successfully signed in.');
|
|
68
71
|
});
|
|
72
|
+
it('should preserve other config flags and replace the previous user ID', async () => {
|
|
73
|
+
const testToken = 'valid-token-123';
|
|
74
|
+
const options = { token: testToken };
|
|
75
|
+
mockCredentialStore.getToken.mockReturnValue(testToken);
|
|
76
|
+
mockUserConfig.read.mockReturnValue({
|
|
77
|
+
token: 'previous-token',
|
|
78
|
+
userId: 'previous-user',
|
|
79
|
+
telemetryNoticeShown: true,
|
|
80
|
+
});
|
|
81
|
+
const scope = nock(DEFAULT_API_BASE_URL)
|
|
82
|
+
.get('/v1/users/me')
|
|
83
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
84
|
+
.reply(200, { id: 'user-123', email: 'test@example.com' });
|
|
85
|
+
await loginCommand.action(options, undefined);
|
|
86
|
+
// The previous user ID is dropped before the new account is confirmed.
|
|
87
|
+
expect(mockUserConfig.write).toHaveBeenNthCalledWith(1, { telemetryNoticeShown: true });
|
|
88
|
+
// The new user ID is stored while other flags are preserved.
|
|
89
|
+
expect(mockUserConfig.write).toHaveBeenNthCalledWith(2, { telemetryNoticeShown: true, userId: 'user-123' });
|
|
90
|
+
expect(scope.isDone()).toBe(true);
|
|
91
|
+
});
|
|
69
92
|
it('should open the browser', async () => {
|
|
70
93
|
const options = {};
|
|
71
94
|
mockPrompt
|
|
@@ -76,8 +99,8 @@ describe('login', () => {
|
|
|
76
99
|
code: 'ABCD1234',
|
|
77
100
|
});
|
|
78
101
|
mockSessionsService.create.mockResolvedValue({ id: 'session-123' });
|
|
79
|
-
// Mock
|
|
80
|
-
|
|
102
|
+
// Mock credentialStore.getToken to return the session token
|
|
103
|
+
mockCredentialStore.getToken.mockReturnValue('session-123');
|
|
81
104
|
// Set up nock to intercept the /v1/users/me request
|
|
82
105
|
const scope = nock(DEFAULT_API_BASE_URL)
|
|
83
106
|
.get('/v1/users/me')
|
|
@@ -106,16 +129,16 @@ describe('login', () => {
|
|
|
106
129
|
it('should throw an error because the provided token is invalid', async () => {
|
|
107
130
|
const invalidToken = 'invalid-token';
|
|
108
131
|
const options = { token: invalidToken };
|
|
109
|
-
// Mock
|
|
110
|
-
|
|
132
|
+
// Mock credentialStore.getToken to return our invalid token after it's written
|
|
133
|
+
mockCredentialStore.getToken.mockReturnValue(invalidToken);
|
|
111
134
|
// Set up nock to intercept the /v1/users/me request and return 401
|
|
112
135
|
const scope = nock(DEFAULT_API_BASE_URL)
|
|
113
136
|
.get('/v1/users/me')
|
|
114
137
|
.matchHeader('Authorization', `Bearer ${invalidToken}`)
|
|
115
138
|
.reply(401, { message: 'Unauthorized' });
|
|
116
139
|
await expect(loginCommand.action(options, undefined)).rejects.toThrow('Process exited with code 1');
|
|
117
|
-
expect(
|
|
118
|
-
expect(
|
|
140
|
+
expect(mockCredentialStore.setToken).toHaveBeenCalledWith(invalidToken);
|
|
141
|
+
expect(mockCredentialStore.deleteToken).toHaveBeenCalled(); // Clears token on error
|
|
119
142
|
expect(scope.isDone()).toBe(true);
|
|
120
143
|
expect(mockConsola.error).toHaveBeenCalledWith(`Invalid token. Please provide a valid token. You can create a token at ${DEFAULT_CONSOLE_BASE_URL}/settings/tokens.`);
|
|
121
144
|
});
|
package/dist/commands/logout.js
CHANGED
|
@@ -2,6 +2,7 @@ import { defineCommand } from '@robingenz/zli';
|
|
|
2
2
|
import consola from 'consola';
|
|
3
3
|
import authorizationService from '../services/authorization-service.js';
|
|
4
4
|
import sessionsService from '../services/sessions.js';
|
|
5
|
+
import credentialStore from '../utils/credential-store.js';
|
|
5
6
|
import userConfig from '../utils/user-config.js';
|
|
6
7
|
export default defineCommand({
|
|
7
8
|
description: 'Sign out from the Capawesome Cloud Console.',
|
|
@@ -10,7 +11,10 @@ export default defineCommand({
|
|
|
10
11
|
if (token && !token.startsWith('ca_')) {
|
|
11
12
|
await sessionsService.delete({ id: token }).catch(() => { });
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
credentialStore.deleteToken();
|
|
15
|
+
// Clear the user ID but keep other flags (e.g. the telemetry notice).
|
|
16
|
+
const { token: _token, userId: _userId, ...persistentConfig } = userConfig.read();
|
|
17
|
+
userConfig.write(persistentConfig);
|
|
14
18
|
consola.success('Successfully signed out.');
|
|
15
19
|
},
|
|
16
20
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_API_BASE_URL } from '../config/consts.js';
|
|
2
2
|
import authorizationService from '../services/authorization-service.js';
|
|
3
|
+
import credentialStore from '../utils/credential-store.js';
|
|
3
4
|
import userConfig from '../utils/user-config.js';
|
|
4
5
|
import consola from 'consola';
|
|
5
6
|
import nock from 'nock';
|
|
@@ -7,41 +8,51 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
7
8
|
import logoutCommand from './logout.js';
|
|
8
9
|
// Mock dependencies
|
|
9
10
|
vi.mock('@/services/authorization-service.js');
|
|
11
|
+
vi.mock('@/utils/credential-store.js');
|
|
10
12
|
vi.mock('@/utils/user-config.js');
|
|
11
13
|
vi.mock('consola');
|
|
12
14
|
describe('logout', () => {
|
|
13
15
|
const mockAuthorizationService = vi.mocked(authorizationService);
|
|
16
|
+
const mockCredentialStore = vi.mocked(credentialStore);
|
|
14
17
|
const mockUserConfig = vi.mocked(userConfig);
|
|
15
18
|
const mockConsola = vi.mocked(consola);
|
|
16
19
|
beforeEach(() => {
|
|
17
20
|
vi.clearAllMocks();
|
|
21
|
+
mockCredentialStore.deleteToken.mockImplementation(() => { });
|
|
18
22
|
mockUserConfig.write.mockImplementation(() => { });
|
|
23
|
+
mockUserConfig.read.mockReturnValue({});
|
|
19
24
|
});
|
|
20
25
|
afterEach(() => {
|
|
21
26
|
nock.cleanAll();
|
|
22
27
|
vi.restoreAllMocks();
|
|
23
28
|
});
|
|
24
|
-
it('should delete session and clear
|
|
29
|
+
it('should delete session and clear credentials with session token', async () => {
|
|
25
30
|
const sessionToken = 'session-123';
|
|
26
31
|
mockAuthorizationService.getCurrentAuthorizationToken.mockReturnValue(sessionToken);
|
|
27
32
|
// Set up nock to intercept the DELETE request
|
|
28
33
|
const scope = nock(DEFAULT_API_BASE_URL).delete('/v1/sessions/session-123').reply(200);
|
|
29
34
|
await logoutCommand.action({}, undefined);
|
|
30
35
|
expect(scope.isDone()).toBe(true);
|
|
31
|
-
expect(
|
|
36
|
+
expect(mockCredentialStore.deleteToken).toHaveBeenCalled();
|
|
32
37
|
expect(mockConsola.success).toHaveBeenCalledWith('Successfully signed out.');
|
|
33
38
|
});
|
|
34
|
-
it('should only clear
|
|
39
|
+
it('should only clear credentials with API token', async () => {
|
|
35
40
|
const apiToken = 'ca_abc123';
|
|
36
41
|
mockAuthorizationService.getCurrentAuthorizationToken.mockReturnValue(apiToken);
|
|
37
42
|
await logoutCommand.action({}, undefined);
|
|
38
|
-
expect(
|
|
43
|
+
expect(mockCredentialStore.deleteToken).toHaveBeenCalled();
|
|
39
44
|
expect(mockConsola.success).toHaveBeenCalledWith('Successfully signed out.');
|
|
40
45
|
});
|
|
46
|
+
it('should clear the user ID but preserve other flags', async () => {
|
|
47
|
+
mockAuthorizationService.getCurrentAuthorizationToken.mockReturnValue('ca_abc123');
|
|
48
|
+
mockUserConfig.read.mockReturnValue({ token: 'ca_abc123', userId: 'user-1', telemetryNoticeShown: true });
|
|
49
|
+
await logoutCommand.action({}, undefined);
|
|
50
|
+
expect(mockUserConfig.write).toHaveBeenCalledWith({ telemetryNoticeShown: true });
|
|
51
|
+
});
|
|
41
52
|
it('should handle no token gracefully', async () => {
|
|
42
53
|
mockAuthorizationService.getCurrentAuthorizationToken.mockReturnValue(null);
|
|
43
54
|
await logoutCommand.action({}, undefined);
|
|
44
|
-
expect(
|
|
55
|
+
expect(mockCredentialStore.deleteToken).toHaveBeenCalled();
|
|
45
56
|
expect(mockConsola.success).toHaveBeenCalledWith('Successfully signed out.');
|
|
46
57
|
});
|
|
47
58
|
});
|
package/dist/commands/whoami.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import authorizationService from '../services/authorization-service.js';
|
|
1
2
|
import usersService from '../services/users.js';
|
|
2
|
-
import userConfig from '../utils/user-config.js';
|
|
3
3
|
import { defineCommand } from '@robingenz/zli';
|
|
4
4
|
import { AxiosError } from 'axios';
|
|
5
5
|
import consola from 'consola';
|
|
6
6
|
export default defineCommand({
|
|
7
7
|
description: 'Show current user',
|
|
8
8
|
action: async (options, args) => {
|
|
9
|
-
const
|
|
9
|
+
const token = authorizationService.getCurrentAuthorizationToken();
|
|
10
10
|
if (token) {
|
|
11
11
|
try {
|
|
12
12
|
const user = await usersService.me();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { DEFAULT_API_BASE_URL } from '../config/consts.js';
|
|
2
|
-
import
|
|
2
|
+
import authorizationService from '../services/authorization-service.js';
|
|
3
3
|
import nock from 'nock';
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
import whoamiCommand from './whoami.js';
|
|
6
6
|
// Mock only the dependencies we need to control
|
|
7
|
-
vi.mock('@/
|
|
7
|
+
vi.mock('@/services/authorization-service.js');
|
|
8
8
|
describe('whoami', () => {
|
|
9
|
-
const
|
|
9
|
+
const mockAuthorizationService = vi.mocked(authorizationService);
|
|
10
10
|
beforeEach(() => {
|
|
11
11
|
vi.clearAllMocks();
|
|
12
12
|
vi.spyOn(process, 'exit').mockImplementation(() => undefined);
|
|
@@ -17,8 +17,8 @@ describe('whoami', () => {
|
|
|
17
17
|
});
|
|
18
18
|
it('should send Bearer token in Authorization header when checking current user', async () => {
|
|
19
19
|
const testToken = 'user-token-456';
|
|
20
|
-
// Mock
|
|
21
|
-
|
|
20
|
+
// Mock the authorization service to return our test token
|
|
21
|
+
mockAuthorizationService.getCurrentAuthorizationToken.mockReturnValue(testToken);
|
|
22
22
|
// Set up nock to intercept the /v1/users/me request
|
|
23
23
|
const scope = nock(DEFAULT_API_BASE_URL)
|
|
24
24
|
.get('/v1/users/me')
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import configService from './services/config.js';
|
|
3
|
+
import telemetryService from './services/telemetry.js';
|
|
3
4
|
import updateService from './services/update.js';
|
|
4
5
|
import { getMessageFromUnknownError, UserError } from './utils/error.js';
|
|
6
|
+
import userConfig from './utils/user-config.js';
|
|
5
7
|
import { defineConfig, processConfig, ZliError } from '@robingenz/zli';
|
|
6
8
|
import * as Sentry from '@sentry/node';
|
|
7
9
|
import { AxiosError } from 'axios';
|
|
@@ -103,6 +105,10 @@ const captureException = async (error) => {
|
|
|
103
105
|
if (error instanceof ZodError) {
|
|
104
106
|
return;
|
|
105
107
|
}
|
|
108
|
+
// Respect telemetry opt-out
|
|
109
|
+
if (!telemetryService.isEnabled()) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
106
112
|
const environment = await configService.getValueForKey('ENVIRONMENT');
|
|
107
113
|
if (environment !== 'production') {
|
|
108
114
|
return;
|
|
@@ -111,6 +117,15 @@ const captureException = async (error) => {
|
|
|
111
117
|
dsn: 'https://19f30f2ec4b91899abc33818568ceb42@o4507446340747264.ingest.de.sentry.io/4508506426966096',
|
|
112
118
|
release: `capawesome-team-cli@${pkg.version}`,
|
|
113
119
|
});
|
|
120
|
+
try {
|
|
121
|
+
const { userId } = userConfig.read();
|
|
122
|
+
if (userId) {
|
|
123
|
+
Sentry.setUser({ id: userId });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// Still report the crash even if the user ID can't be read.
|
|
128
|
+
}
|
|
114
129
|
if (process.argv.slice(2).length > 0) {
|
|
115
130
|
Sentry.setTag('cli_command', process.argv.slice(2)[0]);
|
|
116
131
|
}
|
|
@@ -134,6 +149,8 @@ catch (error) {
|
|
|
134
149
|
// Suggest opening an issue
|
|
135
150
|
consola.log('If you think this is a bug, please open an issue at:');
|
|
136
151
|
consola.log(' https://github.com/capawesome-team/cli/issues/new/choose');
|
|
152
|
+
// Show the telemetry notice
|
|
153
|
+
telemetryService.showNoticeIfNeeded();
|
|
137
154
|
// Check for updates
|
|
138
155
|
await updateService.checkForUpdate();
|
|
139
156
|
// Exit with a non-zero code
|
|
@@ -141,6 +158,8 @@ catch (error) {
|
|
|
141
158
|
}
|
|
142
159
|
}
|
|
143
160
|
finally {
|
|
161
|
+
// Show the telemetry notice
|
|
162
|
+
telemetryService.showNoticeIfNeeded();
|
|
144
163
|
// Check for updates
|
|
145
164
|
await updateService.checkForUpdate();
|
|
146
165
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import credentialStore from '../utils/credential-store.js';
|
|
2
2
|
class AuthorizationServiceImpl {
|
|
3
|
-
|
|
4
|
-
constructor(
|
|
5
|
-
this.
|
|
3
|
+
credentialStore;
|
|
4
|
+
constructor(credentialStore) {
|
|
5
|
+
this.credentialStore = credentialStore;
|
|
6
6
|
}
|
|
7
7
|
getCurrentAuthorizationToken() {
|
|
8
|
-
const token = this.
|
|
8
|
+
const token = this.credentialStore.getToken() || process.env.CAPAWESOME_CLOUD_TOKEN || process.env.CAPAWESOME_TOKEN || null;
|
|
9
9
|
// Trim to remove newline characters that may be included when pasting a token,
|
|
10
10
|
// which would cause an invalid character error in the Authorization header.
|
|
11
11
|
const trimmedToken = token?.trim();
|
|
@@ -15,5 +15,5 @@ class AuthorizationServiceImpl {
|
|
|
15
15
|
return !!this.getCurrentAuthorizationToken();
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
const authorizationService = new AuthorizationServiceImpl(
|
|
18
|
+
const authorizationService = new AuthorizationServiceImpl(credentialStore);
|
|
19
19
|
export default authorizationService;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isInteractive } from '../utils/environment.js';
|
|
2
|
+
import userConfig from '../utils/user-config.js';
|
|
3
|
+
import consola from 'consola';
|
|
4
|
+
const TELEMETRY_DISABLED_VALUES = ['1', 'true'];
|
|
5
|
+
class TelemetryServiceImpl {
|
|
6
|
+
isEnabled() {
|
|
7
|
+
const value = process.env.CAPAWESOME_TELEMETRY_DISABLED?.toLowerCase();
|
|
8
|
+
return !value || !TELEMETRY_DISABLED_VALUES.includes(value);
|
|
9
|
+
}
|
|
10
|
+
showNoticeIfNeeded() {
|
|
11
|
+
if (!this.isEnabled() || !isInteractive()) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const config = userConfig.read();
|
|
16
|
+
if (config.telemetryNoticeShown) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
console.log(''); // Add an empty line for better readability
|
|
20
|
+
consola.info('Capawesome CLI sends crash reports to help us fix bugs.\n' +
|
|
21
|
+
'To opt out: export CAPAWESOME_TELEMETRY_DISABLED=1\n' +
|
|
22
|
+
'Learn more: https://capawesome.io/docs/cloud/cli/telemetry/');
|
|
23
|
+
userConfig.write({ ...config, telemetryNoticeShown: true });
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Never let the telemetry notice break the CLI.
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const telemetryService = new TelemetryServiceImpl();
|
|
31
|
+
export default telemetryService;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import consola from 'consola';
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { isInteractive } from '../utils/environment.js';
|
|
4
|
+
import userConfig from '../utils/user-config.js';
|
|
5
|
+
import telemetryService from './telemetry.js';
|
|
6
|
+
vi.mock('@/utils/environment.js');
|
|
7
|
+
vi.mock('@/utils/user-config.js');
|
|
8
|
+
vi.mock('consola');
|
|
9
|
+
describe('telemetryService', () => {
|
|
10
|
+
const mockIsInteractive = vi.mocked(isInteractive);
|
|
11
|
+
const mockRead = vi.mocked(userConfig.read);
|
|
12
|
+
const mockWrite = vi.mocked(userConfig.write);
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
vi.clearAllMocks();
|
|
15
|
+
delete process.env.CAPAWESOME_TELEMETRY_DISABLED;
|
|
16
|
+
mockIsInteractive.mockReturnValue(true);
|
|
17
|
+
mockRead.mockReturnValue({});
|
|
18
|
+
});
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
delete process.env.CAPAWESOME_TELEMETRY_DISABLED;
|
|
21
|
+
});
|
|
22
|
+
describe('isEnabled', () => {
|
|
23
|
+
it('should be enabled by default', () => {
|
|
24
|
+
expect(telemetryService.isEnabled()).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
it.each(['1', 'true', 'TRUE'])('should be disabled when CAPAWESOME_TELEMETRY_DISABLED is "%s"', (value) => {
|
|
27
|
+
process.env.CAPAWESOME_TELEMETRY_DISABLED = value;
|
|
28
|
+
expect(telemetryService.isEnabled()).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
it('should stay enabled for other values', () => {
|
|
31
|
+
process.env.CAPAWESOME_TELEMETRY_DISABLED = '0';
|
|
32
|
+
expect(telemetryService.isEnabled()).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('showNoticeIfNeeded', () => {
|
|
36
|
+
it('should show the notice once and persist the flag', () => {
|
|
37
|
+
mockRead.mockReturnValue({ token: 'abc' });
|
|
38
|
+
telemetryService.showNoticeIfNeeded();
|
|
39
|
+
expect(consola.info).toHaveBeenCalledOnce();
|
|
40
|
+
expect(mockWrite).toHaveBeenCalledWith({ token: 'abc', telemetryNoticeShown: true });
|
|
41
|
+
});
|
|
42
|
+
it('should not show the notice when it was already shown', () => {
|
|
43
|
+
mockRead.mockReturnValue({ telemetryNoticeShown: true });
|
|
44
|
+
telemetryService.showNoticeIfNeeded();
|
|
45
|
+
expect(consola.info).not.toHaveBeenCalled();
|
|
46
|
+
expect(mockWrite).not.toHaveBeenCalled();
|
|
47
|
+
});
|
|
48
|
+
it('should not show the notice when telemetry is disabled', () => {
|
|
49
|
+
process.env.CAPAWESOME_TELEMETRY_DISABLED = '1';
|
|
50
|
+
telemetryService.showNoticeIfNeeded();
|
|
51
|
+
expect(consola.info).not.toHaveBeenCalled();
|
|
52
|
+
expect(mockWrite).not.toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
it('should not show the notice in non-interactive environments', () => {
|
|
55
|
+
mockIsInteractive.mockReturnValue(false);
|
|
56
|
+
telemetryService.showNoticeIfNeeded();
|
|
57
|
+
expect(consola.info).not.toHaveBeenCalled();
|
|
58
|
+
expect(mockWrite).not.toHaveBeenCalled();
|
|
59
|
+
});
|
|
60
|
+
it('should not throw when reading or writing the config fails', () => {
|
|
61
|
+
mockRead.mockImplementation(() => {
|
|
62
|
+
throw new Error('read failed');
|
|
63
|
+
});
|
|
64
|
+
expect(() => telemetryService.showNoticeIfNeeded()).not.toThrow();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import userConfig from '../utils/user-config.js';
|
|
2
|
+
import { Entry } from '@napi-rs/keyring';
|
|
3
|
+
const SERVICE_NAME = 'capawesome-cli';
|
|
4
|
+
const ACCOUNT_NAME = 'token';
|
|
5
|
+
/**
|
|
6
|
+
* Stores the authentication token in the operating system's secure storage
|
|
7
|
+
* (macOS Keychain, Windows Credential Manager, Linux Secret Service) when
|
|
8
|
+
* available and falls back to the plaintext user config file otherwise
|
|
9
|
+
* (e.g. headless CI environments without a keyring backend).
|
|
10
|
+
*/
|
|
11
|
+
class CredentialStoreImpl {
|
|
12
|
+
keyringAvailable = null;
|
|
13
|
+
getToken() {
|
|
14
|
+
if (!this.isKeyringAvailable()) {
|
|
15
|
+
return userConfig.read().token ?? null;
|
|
16
|
+
}
|
|
17
|
+
const token = this.createEntry().getPassword();
|
|
18
|
+
if (token) {
|
|
19
|
+
return token;
|
|
20
|
+
}
|
|
21
|
+
return this.migrateFileToken();
|
|
22
|
+
}
|
|
23
|
+
setToken(token) {
|
|
24
|
+
if (!this.isKeyringAvailable()) {
|
|
25
|
+
this.writeFileToken(token);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.createEntry().setPassword(token);
|
|
29
|
+
this.clearFileToken();
|
|
30
|
+
}
|
|
31
|
+
deleteToken() {
|
|
32
|
+
if (this.isKeyringAvailable()) {
|
|
33
|
+
try {
|
|
34
|
+
this.createEntry().deletePassword();
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Ignore errors when there is no credential to delete.
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
this.clearFileToken();
|
|
41
|
+
}
|
|
42
|
+
createEntry() {
|
|
43
|
+
return new Entry(SERVICE_NAME, ACCOUNT_NAME);
|
|
44
|
+
}
|
|
45
|
+
isKeyringAvailable() {
|
|
46
|
+
if (this.keyringAvailable === null) {
|
|
47
|
+
try {
|
|
48
|
+
// Probe the backend with a read. This throws if no keyring backend is
|
|
49
|
+
// available, but returns null for a missing credential.
|
|
50
|
+
this.createEntry().getPassword();
|
|
51
|
+
this.keyringAvailable = true;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
this.keyringAvailable = false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return this.keyringAvailable;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Moves a token stored in the plaintext config file into the keyring and
|
|
61
|
+
* removes the plaintext copy. Returns the migrated token or null.
|
|
62
|
+
*/
|
|
63
|
+
migrateFileToken() {
|
|
64
|
+
const fileToken = userConfig.read().token;
|
|
65
|
+
if (!fileToken) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
this.setToken(fileToken);
|
|
69
|
+
return fileToken;
|
|
70
|
+
}
|
|
71
|
+
writeFileToken(token) {
|
|
72
|
+
const config = userConfig.read();
|
|
73
|
+
userConfig.write({ ...config, token });
|
|
74
|
+
}
|
|
75
|
+
clearFileToken() {
|
|
76
|
+
const { token, ...rest } = userConfig.read();
|
|
77
|
+
if (token === undefined) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
userConfig.write(rest);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const credentialStore = new CredentialStoreImpl();
|
|
84
|
+
export default credentialStore;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
const { mockGetPassword, mockSetPassword, mockDeletePassword, mockRead, mockWrite } = vi.hoisted(() => ({
|
|
3
|
+
mockGetPassword: vi.fn(),
|
|
4
|
+
mockSetPassword: vi.fn(),
|
|
5
|
+
mockDeletePassword: vi.fn(),
|
|
6
|
+
mockRead: vi.fn(),
|
|
7
|
+
mockWrite: vi.fn(),
|
|
8
|
+
}));
|
|
9
|
+
vi.mock('@napi-rs/keyring', () => ({
|
|
10
|
+
Entry: vi.fn(function () {
|
|
11
|
+
return {
|
|
12
|
+
getPassword: mockGetPassword,
|
|
13
|
+
setPassword: mockSetPassword,
|
|
14
|
+
deletePassword: mockDeletePassword,
|
|
15
|
+
};
|
|
16
|
+
}),
|
|
17
|
+
}));
|
|
18
|
+
vi.mock('@/utils/user-config.js', () => ({
|
|
19
|
+
default: { read: mockRead, write: mockWrite },
|
|
20
|
+
}));
|
|
21
|
+
const loadCredentialStore = async () => {
|
|
22
|
+
const module = await import('./credential-store.js');
|
|
23
|
+
return module.default;
|
|
24
|
+
};
|
|
25
|
+
describe('credentialStore', () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
vi.clearAllMocks();
|
|
28
|
+
vi.resetModules();
|
|
29
|
+
mockRead.mockReturnValue({});
|
|
30
|
+
});
|
|
31
|
+
describe('when the keyring is available', () => {
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
mockGetPassword.mockReturnValue(null);
|
|
34
|
+
});
|
|
35
|
+
it('should return the token from the keyring', async () => {
|
|
36
|
+
mockGetPassword.mockReturnValue('keyring-token');
|
|
37
|
+
const credentialStore = await loadCredentialStore();
|
|
38
|
+
expect(credentialStore.getToken()).toBe('keyring-token');
|
|
39
|
+
});
|
|
40
|
+
it('should return null when no token is stored', async () => {
|
|
41
|
+
const credentialStore = await loadCredentialStore();
|
|
42
|
+
expect(credentialStore.getToken()).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
it('should migrate a plaintext token from the config file into the keyring', async () => {
|
|
45
|
+
mockRead.mockReturnValue({ token: 'file-token', userId: 'user-1' });
|
|
46
|
+
const credentialStore = await loadCredentialStore();
|
|
47
|
+
expect(credentialStore.getToken()).toBe('file-token');
|
|
48
|
+
expect(mockSetPassword).toHaveBeenCalledWith('file-token');
|
|
49
|
+
expect(mockWrite).toHaveBeenCalledWith({ userId: 'user-1' });
|
|
50
|
+
});
|
|
51
|
+
it('should store the token in the keyring and strip the plaintext copy', async () => {
|
|
52
|
+
mockRead.mockReturnValue({ token: 'old-token', userId: 'user-1' });
|
|
53
|
+
const credentialStore = await loadCredentialStore();
|
|
54
|
+
credentialStore.setToken('new-token');
|
|
55
|
+
expect(mockSetPassword).toHaveBeenCalledWith('new-token');
|
|
56
|
+
expect(mockWrite).toHaveBeenCalledWith({ userId: 'user-1' });
|
|
57
|
+
});
|
|
58
|
+
it('should delete the token from the keyring', async () => {
|
|
59
|
+
const credentialStore = await loadCredentialStore();
|
|
60
|
+
credentialStore.deleteToken();
|
|
61
|
+
expect(mockDeletePassword).toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe('when the keyring is unavailable', () => {
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
mockGetPassword.mockImplementation(() => {
|
|
67
|
+
throw new Error('no keyring backend');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
it('should return the token from the config file', async () => {
|
|
71
|
+
mockRead.mockReturnValue({ token: 'file-token' });
|
|
72
|
+
const credentialStore = await loadCredentialStore();
|
|
73
|
+
expect(credentialStore.getToken()).toBe('file-token');
|
|
74
|
+
expect(mockSetPassword).not.toHaveBeenCalled();
|
|
75
|
+
});
|
|
76
|
+
it('should store the token in the config file while preserving other fields', async () => {
|
|
77
|
+
mockRead.mockReturnValue({ userId: 'user-1' });
|
|
78
|
+
const credentialStore = await loadCredentialStore();
|
|
79
|
+
credentialStore.setToken('file-token');
|
|
80
|
+
expect(mockWrite).toHaveBeenCalledWith({ userId: 'user-1', token: 'file-token' });
|
|
81
|
+
expect(mockSetPassword).not.toHaveBeenCalled();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -10,6 +10,7 @@ import consola from 'consola';
|
|
|
10
10
|
*/
|
|
11
11
|
export const printJobFailureSummary = async (options) => {
|
|
12
12
|
const { jobId } = options;
|
|
13
|
+
consola.info('Hang tight, this can take up to a minute.');
|
|
13
14
|
consola.start('Generating failure summary with Capawesome Cloud Assist...');
|
|
14
15
|
const { summary } = await jobsService.generateFailureSummary({ jobId });
|
|
15
16
|
consola.success('Failure summary generated by Capawesome Cloud Assist:');
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capawesome/cli",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.14.0",
|
|
4
4
|
"description": "The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "rimraf ./dist && tsc && tsc-alias",
|
|
8
8
|
"start": "npm run build && node ./dist/index.js",
|
|
9
9
|
"test": "vitest run",
|
|
10
|
+
"test:coverage": "vitest run --coverage",
|
|
10
11
|
"test:watch": "vitest --watch",
|
|
11
12
|
"test:ui": "vitest --ui",
|
|
12
13
|
"lint": "npm run prettier -- --check",
|
|
@@ -53,14 +54,15 @@
|
|
|
53
54
|
],
|
|
54
55
|
"dependencies": {
|
|
55
56
|
"@clack/prompts": "0.7.0",
|
|
57
|
+
"@napi-rs/keyring": "1.3.0",
|
|
56
58
|
"@robingenz/zli": "0.2.0",
|
|
57
|
-
"@sentry/node": "
|
|
59
|
+
"@sentry/node": "10.58.0",
|
|
58
60
|
"adm-zip": "0.5.16",
|
|
59
61
|
"axios": "1.16.0",
|
|
60
62
|
"axios-retry": "4.5.0",
|
|
61
63
|
"c12": "3.3.3",
|
|
62
64
|
"consola": "3.3.0",
|
|
63
|
-
"form-data": "4.0.
|
|
65
|
+
"form-data": "4.0.6",
|
|
64
66
|
"globby": "16.1.1",
|
|
65
67
|
"http-proxy-agent": "7.0.2",
|
|
66
68
|
"https-proxy-agent": "7.0.6",
|
|
@@ -78,6 +80,7 @@
|
|
|
78
80
|
"@types/mime": "3.0.4",
|
|
79
81
|
"@types/node": "24.2.1",
|
|
80
82
|
"@types/semver": "7.5.8",
|
|
83
|
+
"@vitest/coverage-v8": "4.1.7",
|
|
81
84
|
"@vitest/ui": "4.1.7",
|
|
82
85
|
"commit-and-tag-version": "12.6.1",
|
|
83
86
|
"nock": "14.0.10",
|