@capawesome/cli 0.0.4 → 0.0.5
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 +13 -0
- package/dist/commands/apps/bundles/delete.js +0 -5
- package/dist/commands/apps/channels/create.js +0 -5
- package/dist/commands/apps/channels/delete.js +0 -5
- package/dist/commands/apps/create.js +0 -5
- package/dist/commands/apps/delete.js +0 -5
- package/dist/commands/apps/devices/delete.js +0 -5
- package/dist/commands/login.js +41 -23
- package/dist/commands/logout.js +1 -4
- package/dist/commands/whoami.js +11 -4
- package/dist/services/authorization-service.js +1 -5
- package/dist/services/users.js +36 -0
- package/dist/types/index.js +1 -0
- package/dist/types/user.js +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
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
|
+
## [0.0.5](https://github.com/capawesome-team/cli/compare/v0.0.4...v0.0.5) (2024-05-02)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **login:** add `--token` option ([2cdd649](https://github.com/capawesome-team/cli/commit/2cdd649bec96fbdb8a43e16a08b256b16a98a662))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* allow execution of commands in ci ([4ce7ea6](https://github.com/capawesome-team/cli/commit/4ce7ea6e23c5cb15543df8a215274287134682e8))
|
|
16
|
+
* read user config in ci ([f404989](https://github.com/capawesome-team/cli/commit/f4049890e5ebac15af5491d4ee04e7fcb6e15235))
|
|
17
|
+
|
|
5
18
|
## [0.0.4](https://github.com/capawesome-team/cli/compare/v0.0.3...v0.0.4) (2024-04-30)
|
|
6
19
|
|
|
7
20
|
|
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const citty_1 = require("citty");
|
|
16
16
|
const consola_1 = __importDefault(require("consola"));
|
|
17
17
|
const axios_1 = require("axios");
|
|
18
|
-
const ci_1 = require("../../../utils/ci");
|
|
19
18
|
const apps_1 = __importDefault(require("../../../services/apps"));
|
|
20
19
|
const prompt_1 = require("../../../utils/prompt");
|
|
21
20
|
const app_bundle_1 = __importDefault(require("../../../services/app-bundle"));
|
|
@@ -35,10 +34,6 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
35
34
|
},
|
|
36
35
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
36
|
var _a;
|
|
38
|
-
if ((0, ci_1.isRunningInCi)()) {
|
|
39
|
-
consola_1.default.error('This command is not supported in CI environments.');
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
37
|
let appId = ctx.args.appId;
|
|
43
38
|
if (!appId) {
|
|
44
39
|
const apps = yield apps_1.default.findAll();
|
|
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const citty_1 = require("citty");
|
|
16
|
-
const ci_1 = require("../../../utils/ci");
|
|
17
16
|
const consola_1 = __importDefault(require("consola"));
|
|
18
17
|
const prompt_1 = require("../../../utils/prompt");
|
|
19
18
|
const apps_1 = __importDefault(require("../../../services/apps"));
|
|
@@ -35,10 +34,6 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
35
34
|
},
|
|
36
35
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
36
|
var _a;
|
|
38
|
-
if ((0, ci_1.isRunningInCi)()) {
|
|
39
|
-
consola_1.default.error('This command is not supported in CI environments.');
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
37
|
let appId = ctx.args.appId;
|
|
43
38
|
if (!appId) {
|
|
44
39
|
const apps = yield apps_1.default.findAll();
|
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const citty_1 = require("citty");
|
|
16
16
|
const consola_1 = __importDefault(require("consola"));
|
|
17
17
|
const axios_1 = require("axios");
|
|
18
|
-
const ci_1 = require("../../../utils/ci");
|
|
19
18
|
const apps_1 = __importDefault(require("../../../services/apps"));
|
|
20
19
|
const prompt_1 = require("../../../utils/prompt");
|
|
21
20
|
const app_channel_1 = __importDefault(require("../../../services/app-channel"));
|
|
@@ -35,10 +34,6 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
35
34
|
},
|
|
36
35
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
36
|
var _a;
|
|
38
|
-
if ((0, ci_1.isRunningInCi)()) {
|
|
39
|
-
consola_1.default.error('This command is not supported in CI environments.');
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
37
|
let appId = ctx.args.appId;
|
|
43
38
|
if (!appId) {
|
|
44
39
|
const apps = yield apps_1.default.findAll();
|
|
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const citty_1 = require("citty");
|
|
16
|
-
const ci_1 = require("../../utils/ci");
|
|
17
16
|
const consola_1 = __importDefault(require("consola"));
|
|
18
17
|
const prompt_1 = require("../../utils/prompt");
|
|
19
18
|
const apps_1 = __importDefault(require("../../services/apps"));
|
|
@@ -30,10 +29,6 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
30
29
|
},
|
|
31
30
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
31
|
var _a;
|
|
33
|
-
if ((0, ci_1.isRunningInCi)()) {
|
|
34
|
-
consola_1.default.error('This command is not supported in CI environments.');
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
32
|
let name = ctx.args.name;
|
|
38
33
|
if (!name) {
|
|
39
34
|
name = yield (0, prompt_1.prompt)('Enter the name of the app:', { type: 'text' });
|
|
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const citty_1 = require("citty");
|
|
16
|
-
const ci_1 = require("../../utils/ci");
|
|
17
16
|
const consola_1 = __importDefault(require("consola"));
|
|
18
17
|
const prompt_1 = require("../../utils/prompt");
|
|
19
18
|
const apps_1 = __importDefault(require("../../services/apps"));
|
|
@@ -30,10 +29,6 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
30
29
|
},
|
|
31
30
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
31
|
var _a;
|
|
33
|
-
if ((0, ci_1.isRunningInCi)()) {
|
|
34
|
-
consola_1.default.error('This command is not supported in CI environments.');
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
32
|
let appId = ctx.args.appId;
|
|
38
33
|
if (!appId) {
|
|
39
34
|
const apps = yield apps_1.default.findAll();
|
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const citty_1 = require("citty");
|
|
16
16
|
const consola_1 = __importDefault(require("consola"));
|
|
17
17
|
const axios_1 = require("axios");
|
|
18
|
-
const ci_1 = require("../../../utils/ci");
|
|
19
18
|
const apps_1 = __importDefault(require("../../../services/apps"));
|
|
20
19
|
const prompt_1 = require("../../../utils/prompt");
|
|
21
20
|
const app_device_1 = __importDefault(require("../../../services/app-device"));
|
|
@@ -35,10 +34,6 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
35
34
|
},
|
|
36
35
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
36
|
var _a;
|
|
38
|
-
if ((0, ci_1.isRunningInCi)()) {
|
|
39
|
-
consola_1.default.error('This command is not supported in CI environments.');
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
37
|
let appId = ctx.args.appId;
|
|
43
38
|
if (!appId) {
|
|
44
39
|
const apps = yield apps_1.default.findAll();
|
package/dist/commands/login.js
CHANGED
|
@@ -18,37 +18,55 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
18
18
|
const userConfig_1 = __importDefault(require("../utils/userConfig"));
|
|
19
19
|
const config_1 = require("../config");
|
|
20
20
|
const prompt_1 = require("../utils/prompt");
|
|
21
|
-
const
|
|
21
|
+
const users_1 = __importDefault(require("../services/users"));
|
|
22
22
|
exports.default = (0, citty_1.defineCommand)({
|
|
23
23
|
meta: {
|
|
24
24
|
name: 'login',
|
|
25
25
|
description: 'Sign in to the Capawesome Cloud Console.',
|
|
26
26
|
},
|
|
27
|
+
args: {
|
|
28
|
+
token: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
description: 'Token to use for authentication.',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
27
33
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const email = yield (0, prompt_1.prompt)('Enter your email:', { type: 'text' });
|
|
33
|
-
const password = yield (0, prompt_1.passwordPrompt)('Enter your password:');
|
|
34
|
-
consola_1.default.start('Logging in...');
|
|
35
|
-
let sessionId;
|
|
36
|
-
try {
|
|
37
|
-
const sessionResponse = yield axios_1.default.post(`${config_1.API_URL}/sessions`, {
|
|
38
|
-
email: email,
|
|
39
|
-
password: password,
|
|
34
|
+
let token = ctx.args.token;
|
|
35
|
+
if (token) {
|
|
36
|
+
userConfig_1.default.write({
|
|
37
|
+
token: token,
|
|
40
38
|
});
|
|
41
|
-
|
|
39
|
+
try {
|
|
40
|
+
yield users_1.default.me();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
userConfig_1.default.write({});
|
|
44
|
+
consola_1.default.error('Invalid token.');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
consola_1.default.success(`Successfully signed in.`);
|
|
42
48
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
else {
|
|
50
|
+
const email = yield (0, prompt_1.prompt)('Enter your email:', { type: 'text' });
|
|
51
|
+
const password = yield (0, prompt_1.passwordPrompt)('Enter your password:');
|
|
52
|
+
consola_1.default.start('Logging in...');
|
|
53
|
+
let sessionId;
|
|
54
|
+
try {
|
|
55
|
+
const sessionResponse = yield axios_1.default.post(`${config_1.API_URL}/sessions`, {
|
|
56
|
+
email: email,
|
|
57
|
+
password: password,
|
|
58
|
+
});
|
|
59
|
+
sessionId = sessionResponse.data.id;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
consola_1.default.error('Invalid email or password.');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const tokenResponse = yield axios_1.default.post(`${config_1.API_URL}/tokens`, { name: 'Capawesome CLI' }, { headers: { Authorization: `Bearer ${sessionId}` } });
|
|
66
|
+
userConfig_1.default.write({
|
|
67
|
+
token: tokenResponse.data.token,
|
|
68
|
+
});
|
|
69
|
+
consola_1.default.success(`Successfully signed in.`);
|
|
46
70
|
}
|
|
47
|
-
const tokenResponse = yield axios_1.default.post(`${config_1.API_URL}/tokens`, { name: 'Capawesome CLI' }, { headers: { Authorization: `Bearer ${sessionId}` } });
|
|
48
|
-
userConfig_1.default.write({
|
|
49
|
-
username: email,
|
|
50
|
-
token: tokenResponse.data.token,
|
|
51
|
-
});
|
|
52
|
-
consola_1.default.success(`Successfully signed in.`);
|
|
53
71
|
}),
|
|
54
72
|
});
|
package/dist/commands/logout.js
CHANGED
|
@@ -22,10 +22,7 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
22
22
|
},
|
|
23
23
|
args: {},
|
|
24
24
|
run: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
|
|
26
|
-
delete config.username;
|
|
27
|
-
delete config.token;
|
|
28
|
-
userConfig_1.default.write(config);
|
|
25
|
+
userConfig_1.default.write({});
|
|
29
26
|
consola_1.default.success('Successfully signed out.');
|
|
30
27
|
}),
|
|
31
28
|
});
|
package/dist/commands/whoami.js
CHANGED
|
@@ -15,18 +15,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const citty_1 = require("citty");
|
|
16
16
|
const consola_1 = __importDefault(require("consola"));
|
|
17
17
|
const userConfig_1 = __importDefault(require("../utils/userConfig"));
|
|
18
|
+
const users_1 = __importDefault(require("../services/users"));
|
|
18
19
|
exports.default = (0, citty_1.defineCommand)({
|
|
19
20
|
meta: {
|
|
20
21
|
name: 'whoami',
|
|
21
22
|
description: 'Show current user',
|
|
22
23
|
},
|
|
23
24
|
run: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
const {
|
|
25
|
-
if (
|
|
26
|
-
|
|
25
|
+
const { token } = userConfig_1.default.read();
|
|
26
|
+
if (token) {
|
|
27
|
+
try {
|
|
28
|
+
const user = yield users_1.default.me();
|
|
29
|
+
consola_1.default.info(`Logged in as ${user.email}.`);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
consola_1.default.error('Token is invalid. Please sign in again.');
|
|
33
|
+
}
|
|
27
34
|
}
|
|
28
35
|
else {
|
|
29
|
-
consola_1.default.
|
|
36
|
+
consola_1.default.error('Not logged in.');
|
|
30
37
|
}
|
|
31
38
|
}),
|
|
32
39
|
});
|
|
@@ -3,17 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const ci_1 = require("../utils/ci");
|
|
7
6
|
const userConfig_1 = __importDefault(require("../utils/userConfig"));
|
|
8
7
|
class AuthorizationServiceImpl {
|
|
9
8
|
constructor(userConfig) {
|
|
10
9
|
this.userConfig = userConfig;
|
|
11
10
|
}
|
|
12
11
|
getCurrentAuthorizationToken() {
|
|
13
|
-
|
|
14
|
-
return process.env.CAPAWESOME_TOKEN || null;
|
|
15
|
-
}
|
|
16
|
-
return this.userConfig.read().token || null;
|
|
12
|
+
return this.userConfig.read().token || process.env.CAPAWESOME_TOKEN || null;
|
|
17
13
|
}
|
|
18
14
|
hasAuthorizationToken() {
|
|
19
15
|
return !!this.getCurrentAuthorizationToken();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const http_client_1 = __importDefault(require("../utils/http-client"));
|
|
16
|
+
const authorization_service_1 = __importDefault(require("./authorization-service"));
|
|
17
|
+
class UsersServiceImpl {
|
|
18
|
+
constructor(httpClient) {
|
|
19
|
+
this.httpClient = httpClient;
|
|
20
|
+
}
|
|
21
|
+
me() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const response = yield this.httpClient.get('/users/me', {
|
|
24
|
+
headers: {
|
|
25
|
+
Authorization: `Bearer ${authorization_service_1.default.getCurrentAuthorizationToken()}`,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
if (!response.success) {
|
|
29
|
+
throw response.error;
|
|
30
|
+
}
|
|
31
|
+
return response.data;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const usersService = new UsersServiceImpl(http_client_1.default);
|
|
36
|
+
exports.default = usersService;
|
package/dist/types/index.js
CHANGED