@capawesome/cli 0.0.6 → 0.0.8
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 +16 -0
- package/dist/commands/apps/bundles/create.js +22 -17
- package/dist/commands/apps/bundles/delete.js +13 -11
- package/dist/commands/apps/bundles/update.js +101 -0
- package/dist/commands/apps/channels/create.js +9 -10
- package/dist/commands/apps/channels/delete.js +9 -10
- package/dist/commands/apps/create.js +3 -8
- package/dist/commands/apps/delete.js +7 -8
- package/dist/commands/apps/devices/delete.js +9 -10
- package/dist/index.js +1 -0
- package/dist/services/{app-bundle.js → app-bundles.js} +13 -0
- package/dist/utils/error.js +29 -0
- package/dist/utils/http-client.js +19 -0
- package/package.json +1 -1
- /package/dist/services/{app-channel.js → app-channels.js} +0 -0
- /package/dist/services/{app-device.js → app-devices.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
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.8](https://github.com/capawesome-team/cli/compare/v0.0.7...v0.0.8) (2024-06-10)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* improve error handling ([e67e94b](https://github.com/capawesome-team/cli/commit/e67e94b50308fe227275a9ce83097f67423d0fbd))
|
|
11
|
+
* throw error if no app exists ([930857c](https://github.com/capawesome-team/cli/commit/930857cf735e102ebf1be7e8772cc251a3ddc1a2))
|
|
12
|
+
|
|
13
|
+
## [0.0.7](https://github.com/capawesome-team/cli/compare/v0.0.6...v0.0.7) (2024-05-27)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* add `apps:bundles:update` command ([9dbad37](https://github.com/capawesome-team/cli/commit/9dbad377bebf4ea9b2a04194c3cda73aafcae067))
|
|
19
|
+
* add `rollout` argument to `apps:bundles:create` command ([30b892c](https://github.com/capawesome-team/cli/commit/30b892cd3aabfc62178420d516c162abacd1b757))
|
|
20
|
+
|
|
5
21
|
## [0.0.6](https://github.com/capawesome-team/cli/compare/v0.0.5...v0.0.6) (2024-05-04)
|
|
6
22
|
|
|
7
23
|
|
|
@@ -15,13 +15,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const citty_1 = require("citty");
|
|
16
16
|
const consola_1 = __importDefault(require("consola"));
|
|
17
17
|
const prompt_1 = require("../../../utils/prompt");
|
|
18
|
-
const axios_1 = require("axios");
|
|
19
18
|
const zip_1 = __importDefault(require("../../../utils/zip"));
|
|
20
19
|
const form_data_1 = __importDefault(require("form-data"));
|
|
21
20
|
const node_fs_1 = require("node:fs");
|
|
22
21
|
const authorization_service_1 = __importDefault(require("../../../services/authorization-service"));
|
|
23
22
|
const apps_1 = __importDefault(require("../../../services/apps"));
|
|
24
|
-
const
|
|
23
|
+
const app_bundles_1 = __importDefault(require("../../../services/app-bundles"));
|
|
24
|
+
const error_1 = require("../../../utils/error");
|
|
25
25
|
exports.default = (0, citty_1.defineCommand)({
|
|
26
26
|
meta: {
|
|
27
27
|
description: 'Create a new app bundle.',
|
|
@@ -47,6 +47,10 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
47
47
|
type: 'string',
|
|
48
48
|
description: 'Path to the bundle to upload. Must be a folder (e.g. `www` or `dist`) or a zip file.',
|
|
49
49
|
},
|
|
50
|
+
rollout: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
description: 'The percentage of devices to deploy the bundle to. Must be a number between 0 and 1 (e.g. 0.5).',
|
|
53
|
+
},
|
|
50
54
|
iosMax: {
|
|
51
55
|
type: 'string',
|
|
52
56
|
description: 'The maximum iOS bundle version (`CFBundleVersion`) that the bundle supports.',
|
|
@@ -57,12 +61,11 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
57
61
|
},
|
|
58
62
|
},
|
|
59
63
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
-
var _a, _b, _c;
|
|
61
64
|
if (!authorization_service_1.default.hasAuthorizationToken()) {
|
|
62
65
|
consola_1.default.error('You must be logged in to run this command.');
|
|
63
66
|
return;
|
|
64
67
|
}
|
|
65
|
-
const { androidMax, androidMin, iosMax, iosMin } = ctx.args;
|
|
68
|
+
const { androidMax, androidMin, rollout, iosMax, iosMin } = ctx.args;
|
|
66
69
|
let appId = ctx.args.appId;
|
|
67
70
|
let path = ctx.args.path;
|
|
68
71
|
let channelName = ctx.args.channel;
|
|
@@ -73,6 +76,10 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
73
76
|
}
|
|
74
77
|
if (!appId) {
|
|
75
78
|
const apps = yield apps_1.default.findAll();
|
|
79
|
+
if (!apps.length) {
|
|
80
|
+
consola_1.default.error('You must create an app before creating a bundle.');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
76
83
|
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
77
84
|
appId = yield (0, prompt_1.prompt)('Which app do you want to deploy to:', {
|
|
78
85
|
type: 'select',
|
|
@@ -109,6 +116,14 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
109
116
|
if (androidMin) {
|
|
110
117
|
formData.append('minAndroidAppVersionCode', androidMin);
|
|
111
118
|
}
|
|
119
|
+
if (rollout) {
|
|
120
|
+
const rolloutAsNumber = parseFloat(rollout);
|
|
121
|
+
if (isNaN(rolloutAsNumber) || rolloutAsNumber < 0 || rolloutAsNumber > 1) {
|
|
122
|
+
consola_1.default.error('Rollout percentage must be a number between 0 and 1 (e.g. 0.5).');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
formData.append('rolloutPercentage', rolloutAsNumber);
|
|
126
|
+
}
|
|
112
127
|
if (iosMax) {
|
|
113
128
|
formData.append('maxIosAppVersionCode', iosMax);
|
|
114
129
|
}
|
|
@@ -118,23 +133,13 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
118
133
|
consola_1.default.start('Uploading...');
|
|
119
134
|
// Upload the bundle
|
|
120
135
|
try {
|
|
121
|
-
const response = yield
|
|
136
|
+
const response = yield app_bundles_1.default.create({ appId: appId, formData: formData });
|
|
122
137
|
consola_1.default.success('Bundle successfully created.');
|
|
123
138
|
consola_1.default.info(`Bundle ID: ${response.id}`);
|
|
124
139
|
}
|
|
125
140
|
catch (error) {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
129
|
-
consola_1.default.error('Your token is no longer valid. Please sign in again.');
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
consola_1.default.error(((_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || defaultErrorMessage);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
consola_1.default.error(defaultErrorMessage);
|
|
137
|
-
}
|
|
141
|
+
const message = (0, error_1.getMessageFromUnknownError)(error);
|
|
142
|
+
consola_1.default.error(message);
|
|
138
143
|
}
|
|
139
144
|
}),
|
|
140
145
|
});
|
|
@@ -14,10 +14,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const citty_1 = require("citty");
|
|
16
16
|
const consola_1 = __importDefault(require("consola"));
|
|
17
|
-
const axios_1 = require("axios");
|
|
18
17
|
const apps_1 = __importDefault(require("../../../services/apps"));
|
|
19
18
|
const prompt_1 = require("../../../utils/prompt");
|
|
20
|
-
const
|
|
19
|
+
const app_bundles_1 = __importDefault(require("../../../services/app-bundles"));
|
|
20
|
+
const error_1 = require("../../../utils/error");
|
|
21
21
|
exports.default = (0, citty_1.defineCommand)({
|
|
22
22
|
meta: {
|
|
23
23
|
description: 'Delete an app bundle.',
|
|
@@ -33,42 +33,44 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
33
33
|
},
|
|
34
34
|
},
|
|
35
35
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
|
|
36
|
+
// Prompt for missing arguments
|
|
37
37
|
let appId = ctx.args.appId;
|
|
38
|
+
let bundleId = ctx.args.bundleId;
|
|
38
39
|
if (!appId) {
|
|
39
40
|
const apps = yield apps_1.default.findAll();
|
|
41
|
+
if (!apps.length) {
|
|
42
|
+
consola_1.default.error('You must create an app before deleting a bundle.');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
40
45
|
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
41
46
|
appId = yield (0, prompt_1.prompt)('Which app do you want to delete the bundle from?', {
|
|
42
47
|
type: 'select',
|
|
43
48
|
options: apps.map((app) => ({ label: app.name, value: app.id })),
|
|
44
49
|
});
|
|
45
50
|
}
|
|
46
|
-
let bundleId = ctx.args.bundleId;
|
|
47
51
|
if (!bundleId) {
|
|
48
52
|
bundleId = yield (0, prompt_1.prompt)('Enter the bundle ID:', {
|
|
49
53
|
type: 'text',
|
|
50
54
|
});
|
|
51
55
|
}
|
|
56
|
+
// Confirm deletion
|
|
52
57
|
const confirmed = yield (0, prompt_1.prompt)('Are you sure you want to delete this bundle?', {
|
|
53
58
|
type: 'confirm',
|
|
54
59
|
});
|
|
55
60
|
if (!confirmed) {
|
|
56
61
|
return;
|
|
57
62
|
}
|
|
63
|
+
// Delete bundle
|
|
58
64
|
try {
|
|
59
|
-
yield
|
|
65
|
+
yield app_bundles_1.default.delete({
|
|
60
66
|
appId,
|
|
61
67
|
bundleId,
|
|
62
68
|
});
|
|
63
69
|
consola_1.default.success('Bundle deleted successfully.');
|
|
64
70
|
}
|
|
65
71
|
catch (error) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
consola_1.default.error('Failed to delete bundle.');
|
|
71
|
-
}
|
|
72
|
+
const message = (0, error_1.getMessageFromUnknownError)(error);
|
|
73
|
+
consola_1.default.error(message);
|
|
72
74
|
}
|
|
73
75
|
}),
|
|
74
76
|
});
|
|
@@ -0,0 +1,101 @@
|
|
|
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 citty_1 = require("citty");
|
|
16
|
+
const consola_1 = __importDefault(require("consola"));
|
|
17
|
+
const prompt_1 = require("../../../utils/prompt");
|
|
18
|
+
const authorization_service_1 = __importDefault(require("../../../services/authorization-service"));
|
|
19
|
+
const apps_1 = __importDefault(require("../../../services/apps"));
|
|
20
|
+
const app_bundles_1 = __importDefault(require("../../../services/app-bundles"));
|
|
21
|
+
const error_1 = require("../../../utils/error");
|
|
22
|
+
exports.default = (0, citty_1.defineCommand)({
|
|
23
|
+
meta: {
|
|
24
|
+
description: 'Update an app bundle.',
|
|
25
|
+
},
|
|
26
|
+
args: {
|
|
27
|
+
androidMax: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'The maximum Android version code (`versionCode`) that the bundle supports.',
|
|
30
|
+
},
|
|
31
|
+
androidMin: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'The minimum Android version code (`versionCode`) that the bundle supports.',
|
|
34
|
+
},
|
|
35
|
+
appId: {
|
|
36
|
+
type: 'string',
|
|
37
|
+
description: 'ID of the app.',
|
|
38
|
+
},
|
|
39
|
+
bundleId: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
description: 'ID of the bundle.',
|
|
42
|
+
},
|
|
43
|
+
rollout: {
|
|
44
|
+
type: 'string',
|
|
45
|
+
description: 'The percentage of devices to deploy the bundle to. Must be a number between 0 and 1 (e.g. 0.5).',
|
|
46
|
+
},
|
|
47
|
+
iosMax: {
|
|
48
|
+
type: 'string',
|
|
49
|
+
description: 'The maximum iOS bundle version (`CFBundleVersion`) that the bundle supports.',
|
|
50
|
+
},
|
|
51
|
+
iosMin: {
|
|
52
|
+
type: 'string',
|
|
53
|
+
description: 'The minimum iOS bundle version (`CFBundleVersion`) that the bundle supports.',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
if (!authorization_service_1.default.hasAuthorizationToken()) {
|
|
58
|
+
consola_1.default.error('You must be logged in to run this command.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// Prompt for missing arguments
|
|
62
|
+
const { androidMax, androidMin, rollout, iosMax, iosMin } = ctx.args;
|
|
63
|
+
let appId = ctx.args.appId;
|
|
64
|
+
let bundleId = ctx.args.bundleId;
|
|
65
|
+
if (!appId) {
|
|
66
|
+
const apps = yield apps_1.default.findAll();
|
|
67
|
+
if (!apps.length) {
|
|
68
|
+
consola_1.default.error('You must create an app before updating a bundle.');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
72
|
+
appId = yield (0, prompt_1.prompt)('Which app do you want to update the bundle for?', {
|
|
73
|
+
type: 'select',
|
|
74
|
+
options: apps.map((app) => ({ label: app.name, value: app.id })),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (!bundleId) {
|
|
78
|
+
bundleId = yield (0, prompt_1.prompt)('Enter the bundle ID:', {
|
|
79
|
+
type: 'text',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
// Update bundle
|
|
83
|
+
try {
|
|
84
|
+
const rolloutAsNumber = parseFloat(rollout);
|
|
85
|
+
yield app_bundles_1.default.update({
|
|
86
|
+
appId,
|
|
87
|
+
bundleId,
|
|
88
|
+
maxAndroidAppVersionCode: androidMax,
|
|
89
|
+
maxIosAppVersionCode: iosMax,
|
|
90
|
+
minAndroidAppVersionCode: androidMin,
|
|
91
|
+
minIosAppVersionCode: iosMin,
|
|
92
|
+
rolloutPercentage: rolloutAsNumber,
|
|
93
|
+
});
|
|
94
|
+
consola_1.default.success('Bundle updated successfully.');
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const message = (0, error_1.getMessageFromUnknownError)(error);
|
|
98
|
+
consola_1.default.error(message);
|
|
99
|
+
}
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
@@ -16,8 +16,8 @@ const citty_1 = require("citty");
|
|
|
16
16
|
const consola_1 = __importDefault(require("consola"));
|
|
17
17
|
const prompt_1 = require("../../../utils/prompt");
|
|
18
18
|
const apps_1 = __importDefault(require("../../../services/apps"));
|
|
19
|
-
const
|
|
20
|
-
const
|
|
19
|
+
const app_channels_1 = __importDefault(require("../../../services/app-channels"));
|
|
20
|
+
const error_1 = require("../../../utils/error");
|
|
21
21
|
exports.default = (0, citty_1.defineCommand)({
|
|
22
22
|
meta: {
|
|
23
23
|
description: 'Create a new app channel.',
|
|
@@ -33,10 +33,13 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
33
33
|
},
|
|
34
34
|
},
|
|
35
35
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
var _a;
|
|
37
36
|
let appId = ctx.args.appId;
|
|
38
37
|
if (!appId) {
|
|
39
38
|
const apps = yield apps_1.default.findAll();
|
|
39
|
+
if (!apps.length) {
|
|
40
|
+
consola_1.default.error('You must create an app before creating a channel.');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
40
43
|
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
41
44
|
appId = yield (0, prompt_1.prompt)('Which app do you want to delete the channel from?', {
|
|
42
45
|
type: 'select',
|
|
@@ -48,7 +51,7 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
48
51
|
name = yield (0, prompt_1.prompt)('Enter the name of the channel:', { type: 'text' });
|
|
49
52
|
}
|
|
50
53
|
try {
|
|
51
|
-
const response = yield
|
|
54
|
+
const response = yield app_channels_1.default.create({
|
|
52
55
|
appId,
|
|
53
56
|
name,
|
|
54
57
|
});
|
|
@@ -56,12 +59,8 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
56
59
|
consola_1.default.info(`Channel ID: ${response.id}`);
|
|
57
60
|
}
|
|
58
61
|
catch (error) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
consola_1.default.error('Failed to create channel.');
|
|
64
|
-
}
|
|
62
|
+
const message = (0, error_1.getMessageFromUnknownError)(error);
|
|
63
|
+
consola_1.default.error(message);
|
|
65
64
|
}
|
|
66
65
|
}),
|
|
67
66
|
});
|
|
@@ -14,10 +14,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const citty_1 = require("citty");
|
|
16
16
|
const consola_1 = __importDefault(require("consola"));
|
|
17
|
-
const axios_1 = require("axios");
|
|
18
17
|
const apps_1 = __importDefault(require("../../../services/apps"));
|
|
19
18
|
const prompt_1 = require("../../../utils/prompt");
|
|
20
|
-
const
|
|
19
|
+
const app_channels_1 = __importDefault(require("../../../services/app-channels"));
|
|
20
|
+
const error_1 = require("../../../utils/error");
|
|
21
21
|
exports.default = (0, citty_1.defineCommand)({
|
|
22
22
|
meta: {
|
|
23
23
|
description: 'Delete an app channel.',
|
|
@@ -33,10 +33,13 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
33
33
|
},
|
|
34
34
|
},
|
|
35
35
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
var _a;
|
|
37
36
|
let appId = ctx.args.appId;
|
|
38
37
|
if (!appId) {
|
|
39
38
|
const apps = yield apps_1.default.findAll();
|
|
39
|
+
if (!apps.length) {
|
|
40
|
+
consola_1.default.error('You must create an app before deleting a bundle.');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
40
43
|
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
41
44
|
appId = yield (0, prompt_1.prompt)('Which app do you want to delete the channel from?', {
|
|
42
45
|
type: 'select',
|
|
@@ -60,19 +63,15 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
60
63
|
return;
|
|
61
64
|
}
|
|
62
65
|
try {
|
|
63
|
-
yield
|
|
66
|
+
yield app_channels_1.default.delete({
|
|
64
67
|
appId,
|
|
65
68
|
name: channel,
|
|
66
69
|
});
|
|
67
70
|
consola_1.default.success('Channel deleted successfully.');
|
|
68
71
|
}
|
|
69
72
|
catch (error) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
consola_1.default.error('Failed to delete channel.');
|
|
75
|
-
}
|
|
73
|
+
const message = (0, error_1.getMessageFromUnknownError)(error);
|
|
74
|
+
consola_1.default.error(message);
|
|
76
75
|
}
|
|
77
76
|
}),
|
|
78
77
|
});
|
|
@@ -16,7 +16,7 @@ const citty_1 = require("citty");
|
|
|
16
16
|
const consola_1 = __importDefault(require("consola"));
|
|
17
17
|
const prompt_1 = require("../../utils/prompt");
|
|
18
18
|
const apps_1 = __importDefault(require("../../services/apps"));
|
|
19
|
-
const
|
|
19
|
+
const error_1 = require("../../utils/error");
|
|
20
20
|
exports.default = (0, citty_1.defineCommand)({
|
|
21
21
|
meta: {
|
|
22
22
|
description: 'Create a new app.',
|
|
@@ -28,7 +28,6 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
30
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
var _a;
|
|
32
31
|
let name = ctx.args.name;
|
|
33
32
|
if (!name) {
|
|
34
33
|
name = yield (0, prompt_1.prompt)('Enter the name of the app:', { type: 'text' });
|
|
@@ -39,12 +38,8 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
39
38
|
consola_1.default.info(`App ID: ${response.id}`);
|
|
40
39
|
}
|
|
41
40
|
catch (error) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
consola_1.default.error('Failed to create app.');
|
|
47
|
-
}
|
|
41
|
+
const message = (0, error_1.getMessageFromUnknownError)(error);
|
|
42
|
+
consola_1.default.error(message);
|
|
48
43
|
}
|
|
49
44
|
}),
|
|
50
45
|
});
|
|
@@ -16,7 +16,7 @@ const citty_1 = require("citty");
|
|
|
16
16
|
const consola_1 = __importDefault(require("consola"));
|
|
17
17
|
const prompt_1 = require("../../utils/prompt");
|
|
18
18
|
const apps_1 = __importDefault(require("../../services/apps"));
|
|
19
|
-
const
|
|
19
|
+
const error_1 = require("../../utils/error");
|
|
20
20
|
exports.default = (0, citty_1.defineCommand)({
|
|
21
21
|
meta: {
|
|
22
22
|
description: 'Delete an app.',
|
|
@@ -28,10 +28,13 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
30
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
var _a;
|
|
32
31
|
let appId = ctx.args.appId;
|
|
33
32
|
if (!appId) {
|
|
34
33
|
const apps = yield apps_1.default.findAll();
|
|
34
|
+
if (!apps.length) {
|
|
35
|
+
consola_1.default.error('You must create an app before deleting it.');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
35
38
|
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
36
39
|
appId = yield (0, prompt_1.prompt)('Which app do you want to delete?', {
|
|
37
40
|
type: 'select',
|
|
@@ -49,12 +52,8 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
49
52
|
consola_1.default.success('App deleted successfully.');
|
|
50
53
|
}
|
|
51
54
|
catch (error) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
consola_1.default.error('Failed to delete app.');
|
|
57
|
-
}
|
|
55
|
+
const message = (0, error_1.getMessageFromUnknownError)(error);
|
|
56
|
+
consola_1.default.error(message);
|
|
58
57
|
}
|
|
59
58
|
}),
|
|
60
59
|
});
|
|
@@ -14,10 +14,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const citty_1 = require("citty");
|
|
16
16
|
const consola_1 = __importDefault(require("consola"));
|
|
17
|
-
const axios_1 = require("axios");
|
|
18
17
|
const apps_1 = __importDefault(require("../../../services/apps"));
|
|
19
18
|
const prompt_1 = require("../../../utils/prompt");
|
|
20
|
-
const
|
|
19
|
+
const app_devices_1 = __importDefault(require("../../../services/app-devices"));
|
|
20
|
+
const error_1 = require("../../../utils/error");
|
|
21
21
|
exports.default = (0, citty_1.defineCommand)({
|
|
22
22
|
meta: {
|
|
23
23
|
description: 'Delete an app device.',
|
|
@@ -33,10 +33,13 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
33
33
|
},
|
|
34
34
|
},
|
|
35
35
|
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
var _a;
|
|
37
36
|
let appId = ctx.args.appId;
|
|
38
37
|
if (!appId) {
|
|
39
38
|
const apps = yield apps_1.default.findAll();
|
|
39
|
+
if (!apps.length) {
|
|
40
|
+
consola_1.default.error('You must create an app before deleting a device.');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
40
43
|
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
41
44
|
appId = yield (0, prompt_1.prompt)('Which app do you want to delete the device from?', {
|
|
42
45
|
type: 'select',
|
|
@@ -56,19 +59,15 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
56
59
|
return;
|
|
57
60
|
}
|
|
58
61
|
try {
|
|
59
|
-
yield
|
|
62
|
+
yield app_devices_1.default.delete({
|
|
60
63
|
appId,
|
|
61
64
|
deviceId,
|
|
62
65
|
});
|
|
63
66
|
consola_1.default.success('Device deleted successfully.');
|
|
64
67
|
}
|
|
65
68
|
catch (error) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
consola_1.default.error('Failed to delete device.');
|
|
71
|
-
}
|
|
69
|
+
const message = (0, error_1.getMessageFromUnknownError)(error);
|
|
70
|
+
consola_1.default.error(message);
|
|
72
71
|
}
|
|
73
72
|
}),
|
|
74
73
|
});
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ const main = (0, citty_1.defineCommand)({
|
|
|
43
43
|
'apps:delete': Promise.resolve().then(() => __importStar(require('./commands/apps/delete'))).then((mod) => mod.default),
|
|
44
44
|
'apps:bundles:create': Promise.resolve().then(() => __importStar(require('./commands/apps/bundles/create'))).then((mod) => mod.default),
|
|
45
45
|
'apps:bundles:delete': Promise.resolve().then(() => __importStar(require('./commands/apps/bundles/delete'))).then((mod) => mod.default),
|
|
46
|
+
'apps:bundles:update': Promise.resolve().then(() => __importStar(require('./commands/apps/bundles/update'))).then((mod) => mod.default),
|
|
46
47
|
'apps:channels:create': Promise.resolve().then(() => __importStar(require('./commands/apps/channels/create'))).then((mod) => mod.default),
|
|
47
48
|
'apps:channels:delete': Promise.resolve().then(() => __importStar(require('./commands/apps/channels/delete'))).then((mod) => mod.default),
|
|
48
49
|
'apps:devices:delete': Promise.resolve().then(() => __importStar(require('./commands/apps/devices/delete'))).then((mod) => mod.default),
|
|
@@ -29,6 +29,19 @@ class AppBundlesServiceImpl {
|
|
|
29
29
|
return response.data;
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
+
update(data) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const response = yield this.httpClient.patch(`/apps/${data.appId}/bundles/${data.bundleId}`, data, {
|
|
35
|
+
headers: {
|
|
36
|
+
Authorization: `Bearer ${authorization_service_1.default.getCurrentAuthorizationToken()}`,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
if (!response.success) {
|
|
40
|
+
throw response.error;
|
|
41
|
+
}
|
|
42
|
+
return response.data;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
32
45
|
delete(data) {
|
|
33
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
47
|
const response = yield this.httpClient.delete(`/apps/${data.appId}/bundles/${data.bundleId}`, {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMessageFromUnknownError = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const getMessageFromUnknownError = (error) => {
|
|
6
|
+
let message = 'An unknown error has occurred.';
|
|
7
|
+
if (error instanceof axios_1.AxiosError) {
|
|
8
|
+
message = getErrorMessageFromAxiosError(error);
|
|
9
|
+
}
|
|
10
|
+
else if (error instanceof Error) {
|
|
11
|
+
message = error.message;
|
|
12
|
+
}
|
|
13
|
+
return message;
|
|
14
|
+
};
|
|
15
|
+
exports.getMessageFromUnknownError = getMessageFromUnknownError;
|
|
16
|
+
const getErrorMessageFromAxiosError = (error) => {
|
|
17
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
18
|
+
let message = 'An unknown network error has occurred.';
|
|
19
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
20
|
+
message = 'Your token is no longer valid. Please sign in again.';
|
|
21
|
+
}
|
|
22
|
+
else if ((_c = (_b = error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) {
|
|
23
|
+
message = (_e = (_d = error.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.message;
|
|
24
|
+
}
|
|
25
|
+
else if ((_j = (_h = (_g = (_f = error.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.error) === null || _h === void 0 ? void 0 : _h.issues[0]) === null || _j === void 0 ? void 0 : _j.message) {
|
|
26
|
+
message = ((_k = error.response) === null || _k === void 0 ? void 0 : _k.data).error.issues[0].message;
|
|
27
|
+
}
|
|
28
|
+
return message;
|
|
29
|
+
};
|
|
@@ -53,6 +53,25 @@ class HttpClientImpl {
|
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
+
patch(url, data, config) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
try {
|
|
59
|
+
const res = yield axios_1.default.patch(config_1.API_URL + url, data, config);
|
|
60
|
+
return {
|
|
61
|
+
success: true,
|
|
62
|
+
status: res.status,
|
|
63
|
+
data: res.data,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
status: e.response.status,
|
|
70
|
+
error: e,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
56
75
|
post(url, data, config) {
|
|
57
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
77
|
try {
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|