@capawesome/cli 1.13.2 → 1.14.0-dev.8c382fa.1755584275
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 +7 -0
- package/README.md +3 -3
- package/dist/commands/apps/bundles/create.js +206 -232
- package/dist/commands/apps/bundles/delete.js +42 -47
- package/dist/commands/apps/bundles/update.js +69 -72
- package/dist/commands/apps/channels/create.js +47 -70
- package/dist/commands/apps/channels/delete.js +53 -56
- package/dist/commands/apps/channels/get.js +27 -61
- package/dist/commands/apps/channels/list.js +26 -63
- package/dist/commands/apps/channels/update.js +48 -67
- package/dist/commands/apps/create.js +38 -38
- package/dist/commands/apps/delete.js +39 -40
- package/dist/commands/apps/devices/delete.js +42 -47
- package/dist/commands/doctor.js +12 -29
- package/dist/commands/login.js +48 -69
- package/dist/commands/logout.js +13 -31
- package/dist/commands/manifests/generate.js +20 -38
- package/dist/commands/whoami.js +13 -30
- package/dist/config/consts.js +2 -5
- package/dist/config/index.js +1 -17
- package/dist/index.js +50 -80
- package/dist/services/app-bundle-files.js +117 -136
- package/dist/services/app-bundles.js +22 -41
- package/dist/services/app-channels.js +54 -77
- package/dist/services/app-devices.js +10 -25
- package/dist/services/apps.js +24 -41
- package/dist/services/authorization-service.js +4 -8
- package/dist/services/config.js +14 -28
- package/dist/services/organizations.js +18 -0
- package/dist/services/session-code.js +7 -22
- package/dist/services/sessions.js +13 -30
- package/dist/services/update.js +17 -55
- package/dist/services/users.js +11 -26
- package/dist/types/app-bundle-file.js +1 -2
- package/dist/types/app-bundle.js +1 -2
- package/dist/types/app-channel.js +1 -2
- package/dist/types/app-device.js +1 -2
- package/dist/types/app.js +1 -2
- package/dist/types/index.js +8 -23
- package/dist/types/npm-package.js +1 -2
- package/dist/types/organization.js +1 -0
- package/dist/types/session-code.js +1 -2
- package/dist/types/session.js +1 -2
- package/dist/types/user.js +1 -2
- package/dist/utils/buffer.js +6 -43
- package/dist/utils/error.js +24 -14
- package/dist/utils/file.js +22 -41
- package/dist/utils/hash.js +3 -39
- package/dist/utils/http-client.js +27 -53
- package/dist/utils/manifest.js +11 -24
- package/dist/utils/prompt.js +9 -26
- package/dist/utils/signature.js +3 -39
- package/dist/utils/userConfig.js +5 -9
- package/dist/utils/zip.js +11 -27
- package/package.json +15 -8
- package/dist/utils/ci.js +0 -7
|
@@ -1,82 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const error_1 = require("../../../utils/error");
|
|
20
|
-
exports.default = (0, citty_1.defineCommand)({
|
|
21
|
-
meta: {
|
|
22
|
-
description: 'Get an existing app channel.',
|
|
23
|
-
},
|
|
24
|
-
args: {
|
|
25
|
-
appId: {
|
|
26
|
-
type: 'string',
|
|
27
|
-
description: 'ID of the app.',
|
|
28
|
-
},
|
|
29
|
-
channelId: {
|
|
30
|
-
type: 'string',
|
|
31
|
-
description: 'ID of the channel.',
|
|
32
|
-
},
|
|
33
|
-
json: {
|
|
34
|
-
type: 'boolean',
|
|
35
|
-
description: 'Output in JSON format.',
|
|
36
|
-
},
|
|
37
|
-
name: {
|
|
38
|
-
type: 'string',
|
|
39
|
-
description: 'Name of the channel.',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
if (!authorization_service_1.default.hasAuthorizationToken()) {
|
|
44
|
-
consola_1.default.error('You must be logged in to run this command.');
|
|
1
|
+
import { defineCommand, defineOptions } from '@robingenz/zli';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import appChannelsService from '../../../services/app-channels.js';
|
|
5
|
+
import authorizationService from '../../../services/authorization-service.js';
|
|
6
|
+
import { getMessageFromUnknownError } from '../../../utils/error.js';
|
|
7
|
+
export default defineCommand({
|
|
8
|
+
description: 'Get an existing app channel.',
|
|
9
|
+
options: defineOptions(z.object({
|
|
10
|
+
appId: z.string().optional().describe('ID of the app.'),
|
|
11
|
+
channelId: z.string().optional().describe('ID of the channel.'),
|
|
12
|
+
json: z.boolean().optional().describe('Output in JSON format.'),
|
|
13
|
+
name: z.string().optional().describe('Name of the channel.'),
|
|
14
|
+
})),
|
|
15
|
+
action: async (options, args) => {
|
|
16
|
+
let { appId, channelId, json, name } = options;
|
|
17
|
+
if (!authorizationService.hasAuthorizationToken()) {
|
|
18
|
+
consola.error('You must be logged in to run this command.');
|
|
45
19
|
process.exit(1);
|
|
46
20
|
}
|
|
47
|
-
let appId = ctx.args.appId;
|
|
48
|
-
let channelId = ctx.args.channelId;
|
|
49
|
-
let json = ctx.args.json;
|
|
50
|
-
// Convert json to boolean
|
|
51
|
-
if (typeof json === 'string') {
|
|
52
|
-
json = json.toLowerCase() === 'true';
|
|
53
|
-
}
|
|
54
|
-
let name = ctx.args.name;
|
|
55
21
|
if (!appId) {
|
|
56
|
-
|
|
22
|
+
consola.error('You must provide an app ID.');
|
|
57
23
|
process.exit(1);
|
|
58
24
|
}
|
|
59
25
|
if (!channelId && !name) {
|
|
60
|
-
|
|
26
|
+
consola.error('You must provide a channel ID or name.');
|
|
61
27
|
process.exit(1);
|
|
62
28
|
}
|
|
63
29
|
try {
|
|
64
30
|
let channel;
|
|
65
31
|
if (channelId) {
|
|
66
|
-
channel =
|
|
32
|
+
channel = await appChannelsService.findOneById({
|
|
67
33
|
appId,
|
|
68
34
|
id: channelId,
|
|
69
35
|
});
|
|
70
36
|
}
|
|
71
37
|
else if (name) {
|
|
72
|
-
const foundChannels =
|
|
38
|
+
const foundChannels = await appChannelsService.findAll({
|
|
73
39
|
appId,
|
|
74
40
|
name,
|
|
75
41
|
});
|
|
76
42
|
channel = foundChannels[0];
|
|
77
43
|
}
|
|
78
44
|
if (!channel) {
|
|
79
|
-
|
|
45
|
+
consola.error('Channel not found.');
|
|
80
46
|
process.exit(1);
|
|
81
47
|
}
|
|
82
48
|
if (json) {
|
|
@@ -94,13 +60,13 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
94
60
|
totalAppBundleLimit: channel.totalAppBundleLimit,
|
|
95
61
|
appId: channel.appId,
|
|
96
62
|
});
|
|
97
|
-
|
|
63
|
+
consola.success('Channel retrieved successfully.');
|
|
98
64
|
}
|
|
99
65
|
}
|
|
100
66
|
catch (error) {
|
|
101
|
-
const message =
|
|
102
|
-
|
|
67
|
+
const message = getMessageFromUnknownError(error);
|
|
68
|
+
consola.error(message);
|
|
103
69
|
process.exit(1);
|
|
104
70
|
}
|
|
105
|
-
}
|
|
71
|
+
},
|
|
106
72
|
});
|
|
@@ -1,69 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const error_1 = require("../../../utils/error");
|
|
20
|
-
exports.default = (0, citty_1.defineCommand)({
|
|
21
|
-
meta: {
|
|
22
|
-
description: 'Retrieve a list of existing app channels.',
|
|
23
|
-
},
|
|
24
|
-
args: {
|
|
25
|
-
appId: {
|
|
26
|
-
type: 'string',
|
|
27
|
-
description: 'ID of the app.',
|
|
28
|
-
},
|
|
29
|
-
json: {
|
|
30
|
-
type: 'boolean',
|
|
31
|
-
description: 'Output in JSON format.',
|
|
32
|
-
},
|
|
33
|
-
limit: {
|
|
34
|
-
type: 'string',
|
|
35
|
-
description: 'Limit for pagination.',
|
|
36
|
-
},
|
|
37
|
-
offset: {
|
|
38
|
-
type: 'string',
|
|
39
|
-
description: 'Offset for pagination.',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
if (!authorization_service_1.default.hasAuthorizationToken()) {
|
|
44
|
-
consola_1.default.error('You must be logged in to run this command.');
|
|
1
|
+
import { defineCommand, defineOptions } from '@robingenz/zli';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import appChannelsService from '../../../services/app-channels.js';
|
|
5
|
+
import authorizationService from '../../../services/authorization-service.js';
|
|
6
|
+
import { getMessageFromUnknownError } from '../../../utils/error.js';
|
|
7
|
+
export default defineCommand({
|
|
8
|
+
description: 'Retrieve a list of existing app channels.',
|
|
9
|
+
options: defineOptions(z.object({
|
|
10
|
+
appId: z.string().optional().describe('ID of the app.'),
|
|
11
|
+
json: z.boolean().optional().describe('Output in JSON format.'),
|
|
12
|
+
limit: z.coerce.number().optional().describe('Limit for pagination.'),
|
|
13
|
+
offset: z.coerce.number().optional().describe('Offset for pagination.'),
|
|
14
|
+
})),
|
|
15
|
+
action: async (options, args) => {
|
|
16
|
+
let { appId, json, limit, offset } = options;
|
|
17
|
+
if (!authorizationService.hasAuthorizationToken()) {
|
|
18
|
+
consola.error('You must be logged in to run this command.');
|
|
45
19
|
process.exit(1);
|
|
46
20
|
}
|
|
47
|
-
let appId = ctx.args.appId;
|
|
48
|
-
let json = ctx.args.json;
|
|
49
|
-
const limit = ctx.args.limit;
|
|
50
|
-
const offset = ctx.args.offset;
|
|
51
|
-
// Convert limit and offset to numbers
|
|
52
|
-
const limitAsNumber = limit ? parseInt(limit, 10) : undefined;
|
|
53
|
-
const offsetAsNumber = offset ? parseInt(offset, 10) : undefined;
|
|
54
|
-
// Convert json to boolean
|
|
55
|
-
if (typeof json === 'string') {
|
|
56
|
-
json = json.toLowerCase() === 'true';
|
|
57
|
-
}
|
|
58
21
|
if (!appId) {
|
|
59
|
-
|
|
22
|
+
consola.error('You must provide an app ID.');
|
|
60
23
|
process.exit(1);
|
|
61
24
|
}
|
|
62
25
|
try {
|
|
63
|
-
const foundChannels =
|
|
26
|
+
const foundChannels = await appChannelsService.findAll({
|
|
64
27
|
appId,
|
|
65
|
-
limit
|
|
66
|
-
offset
|
|
28
|
+
limit,
|
|
29
|
+
offset,
|
|
67
30
|
});
|
|
68
31
|
const logData = foundChannels.map((channel) => ({
|
|
69
32
|
id: channel.id,
|
|
@@ -78,13 +41,13 @@ exports.default = (0, citty_1.defineCommand)({
|
|
|
78
41
|
}
|
|
79
42
|
else {
|
|
80
43
|
console.table(logData);
|
|
81
|
-
|
|
44
|
+
consola.success('Channels retrieved successfully.');
|
|
82
45
|
}
|
|
83
46
|
}
|
|
84
47
|
catch (error) {
|
|
85
|
-
const message =
|
|
86
|
-
|
|
48
|
+
const message = getMessageFromUnknownError(error);
|
|
49
|
+
consola.error(message);
|
|
87
50
|
process.exit(1);
|
|
88
51
|
}
|
|
89
|
-
}
|
|
52
|
+
},
|
|
90
53
|
});
|
|
@@ -1,95 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
args: {
|
|
27
|
-
appId: {
|
|
28
|
-
type: 'string',
|
|
29
|
-
description: 'ID of the app.',
|
|
30
|
-
},
|
|
31
|
-
channelId: {
|
|
32
|
-
type: 'string',
|
|
33
|
-
description: 'ID of the channel.',
|
|
34
|
-
},
|
|
35
|
-
bundleLimit: {
|
|
36
|
-
type: 'string',
|
|
37
|
-
description: 'Maximum number of bundles that can be assigned to the channel. If more bundles are assigned, the oldest bundles will be automatically deleted.',
|
|
38
|
-
},
|
|
39
|
-
name: {
|
|
40
|
-
type: 'string',
|
|
41
|
-
description: 'Name of the channel.',
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
if (!authorization_service_1.default.hasAuthorizationToken()) {
|
|
46
|
-
consola_1.default.error('You must be logged in to run this command.');
|
|
1
|
+
import { defineCommand, defineOptions } from '@robingenz/zli';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import appChannelsService from '../../../services/app-channels.js';
|
|
5
|
+
import appsService from '../../../services/apps.js';
|
|
6
|
+
import authorizationService from '../../../services/authorization-service.js';
|
|
7
|
+
import organizationsService from '../../../services/organizations.js';
|
|
8
|
+
import { getMessageFromUnknownError } from '../../../utils/error.js';
|
|
9
|
+
import { prompt } from '../../../utils/prompt.js';
|
|
10
|
+
export default defineCommand({
|
|
11
|
+
description: 'Update an existing app channel.',
|
|
12
|
+
options: defineOptions(z.object({
|
|
13
|
+
appId: z.string().optional().describe('ID of the app.'),
|
|
14
|
+
channelId: z.string().optional().describe('ID of the channel.'),
|
|
15
|
+
bundleLimit: z.coerce
|
|
16
|
+
.number()
|
|
17
|
+
.optional()
|
|
18
|
+
.describe('Maximum number of bundles that can be assigned to the channel. If more bundles are assigned, the oldest bundles will be automatically deleted.'),
|
|
19
|
+
name: z.string().optional().describe('Name of the channel.'),
|
|
20
|
+
})),
|
|
21
|
+
action: async (options, args) => {
|
|
22
|
+
let { appId, channelId, bundleLimit, name } = options;
|
|
23
|
+
if (!authorizationService.hasAuthorizationToken()) {
|
|
24
|
+
consola.error('You must be logged in to run this command.');
|
|
47
25
|
process.exit(1);
|
|
48
26
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// Validate the bundle limit
|
|
54
|
-
let bundleLimit;
|
|
55
|
-
if (bundleLimitAsString) {
|
|
56
|
-
bundleLimit = parseInt(bundleLimitAsString, 10);
|
|
57
|
-
if (isNaN(bundleLimit)) {
|
|
58
|
-
consola_1.default.error('The bundle limit must be a number.');
|
|
27
|
+
if (!appId) {
|
|
28
|
+
const organizations = await organizationsService.findAll();
|
|
29
|
+
if (organizations.length === 0) {
|
|
30
|
+
consola.error('You must create an organization before updating a channel.');
|
|
59
31
|
process.exit(1);
|
|
60
32
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
33
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
34
|
+
const organizationId = await prompt('Select the organization of the app for which you want to update a channel.', {
|
|
35
|
+
type: 'select',
|
|
36
|
+
options: organizations.map((organization) => ({ label: organization.name, value: organization.id })),
|
|
37
|
+
});
|
|
38
|
+
if (!organizationId) {
|
|
39
|
+
consola.error('You must select the organization of an app for which you want to update a channel.');
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
const apps = await appsService.findAll({
|
|
43
|
+
organizationId,
|
|
44
|
+
});
|
|
64
45
|
if (!apps.length) {
|
|
65
|
-
|
|
46
|
+
consola.error('You must create an app before updating a channel.');
|
|
66
47
|
process.exit(1);
|
|
67
48
|
}
|
|
68
49
|
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
69
|
-
appId =
|
|
50
|
+
appId = await prompt('Which app do you want to update the channel for?', {
|
|
70
51
|
type: 'select',
|
|
71
52
|
options: apps.map((app) => ({ label: app.name, value: app.id })),
|
|
72
53
|
});
|
|
73
54
|
}
|
|
74
55
|
if (!channelId) {
|
|
75
|
-
channelId =
|
|
56
|
+
channelId = await prompt('Enter the channel ID:', {
|
|
76
57
|
type: 'text',
|
|
77
58
|
});
|
|
78
59
|
}
|
|
79
60
|
// Update channel
|
|
80
61
|
try {
|
|
81
|
-
|
|
62
|
+
await appChannelsService.update({
|
|
82
63
|
appId,
|
|
83
64
|
appChannelId: channelId,
|
|
84
65
|
name,
|
|
85
66
|
totalAppBundleLimit: bundleLimit,
|
|
86
67
|
});
|
|
87
|
-
|
|
68
|
+
consola.success('Channel updated successfully.');
|
|
88
69
|
}
|
|
89
70
|
catch (error) {
|
|
90
|
-
const message =
|
|
91
|
-
|
|
71
|
+
const message = getMessageFromUnknownError(error);
|
|
72
|
+
consola.error(message);
|
|
92
73
|
process.exit(1);
|
|
93
74
|
}
|
|
94
|
-
}
|
|
75
|
+
},
|
|
95
76
|
});
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
import { defineCommand, defineOptions } from '@robingenz/zli';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import appsService from '../../services/apps.js';
|
|
5
|
+
import organizationsService from '../../services/organizations.js';
|
|
6
|
+
import { getMessageFromUnknownError } from '../../utils/error.js';
|
|
7
|
+
import { prompt } from '../../utils/prompt.js';
|
|
8
|
+
export default defineCommand({
|
|
9
|
+
description: 'Create a new app.',
|
|
10
|
+
options: defineOptions(z.object({
|
|
11
|
+
name: z.string().optional().describe('Name of the app.'),
|
|
12
|
+
organizationId: z.string().optional().describe('ID of the organization to create the app in.'),
|
|
13
|
+
})),
|
|
14
|
+
action: async (options, args) => {
|
|
15
|
+
let { name, organizationId } = options;
|
|
16
|
+
if (!organizationId) {
|
|
17
|
+
const organizations = await organizationsService.findAll();
|
|
18
|
+
if (organizations.length === 0) {
|
|
19
|
+
consola.error('You must create an organization before creating an app.');
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
23
|
+
organizationId = await prompt('Which organization do you want to create the app in?', {
|
|
24
|
+
type: 'select',
|
|
25
|
+
options: organizations.map((organization) => ({ label: organization.name, value: organization.id })),
|
|
26
|
+
});
|
|
27
|
+
if (!organizationId) {
|
|
28
|
+
consola.error('You must select an organization to create the app in.');
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
32
|
if (!name) {
|
|
33
|
-
name =
|
|
33
|
+
name = await prompt('Enter the name of the app:', { type: 'text' });
|
|
34
34
|
}
|
|
35
35
|
try {
|
|
36
|
-
const response =
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
const response = await appsService.create({ name, organizationId });
|
|
37
|
+
consola.success('App created successfully.');
|
|
38
|
+
consola.info(`App ID: ${response.id}`);
|
|
39
39
|
}
|
|
40
40
|
catch (error) {
|
|
41
|
-
const message =
|
|
42
|
-
|
|
41
|
+
const message = getMessageFromUnknownError(error);
|
|
42
|
+
consola.error(message);
|
|
43
43
|
process.exit(1);
|
|
44
44
|
}
|
|
45
|
-
}
|
|
45
|
+
},
|
|
46
46
|
});
|
|
@@ -1,60 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const citty_1 = require("citty");
|
|
16
|
-
const consola_1 = __importDefault(require("consola"));
|
|
17
|
-
const apps_1 = __importDefault(require("../../services/apps"));
|
|
18
|
-
const error_1 = require("../../utils/error");
|
|
19
|
-
const prompt_1 = require("../../utils/prompt");
|
|
20
|
-
exports.default = (0, citty_1.defineCommand)({
|
|
21
|
-
meta: {
|
|
22
|
-
description: 'Delete an app.',
|
|
23
|
-
},
|
|
24
|
-
args: {
|
|
25
|
-
appId: {
|
|
26
|
-
type: 'string',
|
|
27
|
-
description: 'ID of the app.',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
let appId = ctx.args.appId;
|
|
1
|
+
import { defineCommand, defineOptions } from '@robingenz/zli';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import appsService from '../../services/apps.js';
|
|
5
|
+
import organizationsService from '../../services/organizations.js';
|
|
6
|
+
import { getMessageFromUnknownError } from '../../utils/error.js';
|
|
7
|
+
import { prompt } from '../../utils/prompt.js';
|
|
8
|
+
export default defineCommand({
|
|
9
|
+
description: 'Delete an app.',
|
|
10
|
+
options: defineOptions(z.object({
|
|
11
|
+
appId: z.string().optional().describe('ID of the app.'),
|
|
12
|
+
})),
|
|
13
|
+
action: async (options, args) => {
|
|
14
|
+
let { appId } = options;
|
|
32
15
|
if (!appId) {
|
|
33
|
-
const
|
|
16
|
+
const organizations = await organizationsService.findAll();
|
|
17
|
+
if (organizations.length === 0) {
|
|
18
|
+
consola.error('You must create an organization before deleting an app.');
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
22
|
+
const organizationId = await prompt('Which organization do you want to delete the app from?', {
|
|
23
|
+
type: 'select',
|
|
24
|
+
options: organizations.map((organization) => ({ label: organization.name, value: organization.id })),
|
|
25
|
+
});
|
|
26
|
+
if (!organizationId) {
|
|
27
|
+
consola.error('You must select an organization to delete the app from.');
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
const apps = await appsService.findAll({
|
|
31
|
+
organizationId,
|
|
32
|
+
});
|
|
34
33
|
if (!apps.length) {
|
|
35
|
-
|
|
34
|
+
consola.error('You must create an app before deleting it.');
|
|
36
35
|
process.exit(1);
|
|
37
36
|
}
|
|
38
37
|
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
39
|
-
appId =
|
|
38
|
+
appId = await prompt('Which app do you want to delete?', {
|
|
40
39
|
type: 'select',
|
|
41
40
|
options: apps.map((app) => ({ label: app.name, value: app.id })),
|
|
42
41
|
});
|
|
43
42
|
}
|
|
44
|
-
const confirmed =
|
|
43
|
+
const confirmed = await prompt('Are you sure you want to delete this app?', {
|
|
45
44
|
type: 'confirm',
|
|
46
45
|
});
|
|
47
46
|
if (!confirmed) {
|
|
48
47
|
return;
|
|
49
48
|
}
|
|
50
49
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
await appsService.delete({ id: appId });
|
|
51
|
+
consola.success('App deleted successfully.');
|
|
53
52
|
}
|
|
54
53
|
catch (error) {
|
|
55
|
-
const message =
|
|
56
|
-
|
|
54
|
+
const message = getMessageFromUnknownError(error);
|
|
55
|
+
consola.error(message);
|
|
57
56
|
process.exit(1);
|
|
58
57
|
}
|
|
59
|
-
}
|
|
58
|
+
},
|
|
60
59
|
});
|