@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.
Files changed (56) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +3 -3
  3. package/dist/commands/apps/bundles/create.js +206 -232
  4. package/dist/commands/apps/bundles/delete.js +42 -47
  5. package/dist/commands/apps/bundles/update.js +69 -72
  6. package/dist/commands/apps/channels/create.js +47 -70
  7. package/dist/commands/apps/channels/delete.js +53 -56
  8. package/dist/commands/apps/channels/get.js +27 -61
  9. package/dist/commands/apps/channels/list.js +26 -63
  10. package/dist/commands/apps/channels/update.js +48 -67
  11. package/dist/commands/apps/create.js +38 -38
  12. package/dist/commands/apps/delete.js +39 -40
  13. package/dist/commands/apps/devices/delete.js +42 -47
  14. package/dist/commands/doctor.js +12 -29
  15. package/dist/commands/login.js +48 -69
  16. package/dist/commands/logout.js +13 -31
  17. package/dist/commands/manifests/generate.js +20 -38
  18. package/dist/commands/whoami.js +13 -30
  19. package/dist/config/consts.js +2 -5
  20. package/dist/config/index.js +1 -17
  21. package/dist/index.js +50 -80
  22. package/dist/services/app-bundle-files.js +117 -136
  23. package/dist/services/app-bundles.js +22 -41
  24. package/dist/services/app-channels.js +54 -77
  25. package/dist/services/app-devices.js +10 -25
  26. package/dist/services/apps.js +24 -41
  27. package/dist/services/authorization-service.js +4 -8
  28. package/dist/services/config.js +14 -28
  29. package/dist/services/organizations.js +18 -0
  30. package/dist/services/session-code.js +7 -22
  31. package/dist/services/sessions.js +13 -30
  32. package/dist/services/update.js +17 -55
  33. package/dist/services/users.js +11 -26
  34. package/dist/types/app-bundle-file.js +1 -2
  35. package/dist/types/app-bundle.js +1 -2
  36. package/dist/types/app-channel.js +1 -2
  37. package/dist/types/app-device.js +1 -2
  38. package/dist/types/app.js +1 -2
  39. package/dist/types/index.js +8 -23
  40. package/dist/types/npm-package.js +1 -2
  41. package/dist/types/organization.js +1 -0
  42. package/dist/types/session-code.js +1 -2
  43. package/dist/types/session.js +1 -2
  44. package/dist/types/user.js +1 -2
  45. package/dist/utils/buffer.js +6 -43
  46. package/dist/utils/error.js +24 -14
  47. package/dist/utils/file.js +22 -41
  48. package/dist/utils/hash.js +3 -39
  49. package/dist/utils/http-client.js +27 -53
  50. package/dist/utils/manifest.js +11 -24
  51. package/dist/utils/prompt.js +9 -26
  52. package/dist/utils/signature.js +3 -39
  53. package/dist/utils/userConfig.js +5 -9
  54. package/dist/utils/zip.js +11 -27
  55. package/package.json +15 -8
  56. package/dist/utils/ci.js +0 -7
@@ -1,82 +1,48 @@
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 app_channels_1 = __importDefault(require("../../../services/app-channels"));
18
- const authorization_service_1 = __importDefault(require("../../../services/authorization-service"));
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
- consola_1.default.error('You must provide an app ID.');
22
+ consola.error('You must provide an app ID.');
57
23
  process.exit(1);
58
24
  }
59
25
  if (!channelId && !name) {
60
- consola_1.default.error('You must provide a channel ID or name.');
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 = yield app_channels_1.default.findOneById({
32
+ channel = await appChannelsService.findOneById({
67
33
  appId,
68
34
  id: channelId,
69
35
  });
70
36
  }
71
37
  else if (name) {
72
- const foundChannels = yield app_channels_1.default.findAll({
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
- consola_1.default.error('Channel not found.');
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
- consola_1.default.success('Channel retrieved successfully.');
63
+ consola.success('Channel retrieved successfully.');
98
64
  }
99
65
  }
100
66
  catch (error) {
101
- const message = (0, error_1.getMessageFromUnknownError)(error);
102
- consola_1.default.error(message);
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
- "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 app_channels_1 = __importDefault(require("../../../services/app-channels"));
18
- const authorization_service_1 = __importDefault(require("../../../services/authorization-service"));
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
- consola_1.default.error('You must provide an app ID.');
22
+ consola.error('You must provide an app ID.');
60
23
  process.exit(1);
61
24
  }
62
25
  try {
63
- const foundChannels = yield app_channels_1.default.findAll({
26
+ const foundChannels = await appChannelsService.findAll({
64
27
  appId,
65
- limit: limitAsNumber,
66
- offset: offsetAsNumber,
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
- consola_1.default.success('Channels retrieved successfully.');
44
+ consola.success('Channels retrieved successfully.');
82
45
  }
83
46
  }
84
47
  catch (error) {
85
- const message = (0, error_1.getMessageFromUnknownError)(error);
86
- consola_1.default.error(message);
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
- "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 app_channels_1 = __importDefault(require("../../../services/app-channels"));
18
- const apps_1 = __importDefault(require("../../../services/apps"));
19
- const authorization_service_1 = __importDefault(require("../../../services/authorization-service"));
20
- const error_1 = require("../../../utils/error");
21
- const prompt_1 = require("../../../utils/prompt");
22
- exports.default = (0, citty_1.defineCommand)({
23
- meta: {
24
- description: 'Update an existing app channel.',
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
- let appId = ctx.args.appId;
50
- let bundleLimitAsString = ctx.args.bundleLimit;
51
- let channelId = ctx.args.channelId;
52
- let name = ctx.args.name;
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
- if (!appId) {
63
- const apps = yield apps_1.default.findAll();
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
- consola_1.default.error('You must create an app before updating a channel.');
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 = yield (0, prompt_1.prompt)('Which app do you want to update the channel for?', {
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 = yield (0, prompt_1.prompt)('Enter the channel ID:', {
56
+ channelId = await prompt('Enter the channel ID:', {
76
57
  type: 'text',
77
58
  });
78
59
  }
79
60
  // Update channel
80
61
  try {
81
- yield app_channels_1.default.update({
62
+ await appChannelsService.update({
82
63
  appId,
83
64
  appChannelId: channelId,
84
65
  name,
85
66
  totalAppBundleLimit: bundleLimit,
86
67
  });
87
- consola_1.default.success('Channel updated successfully.');
68
+ consola.success('Channel updated successfully.');
88
69
  }
89
70
  catch (error) {
90
- const message = (0, error_1.getMessageFromUnknownError)(error);
91
- consola_1.default.error(message);
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
- "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 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: 'Create a new app.',
23
- },
24
- args: {
25
- name: {
26
- type: 'string',
27
- description: 'Name of the app.',
28
- },
29
- },
30
- run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
31
- let name = ctx.args.name;
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 = yield (0, prompt_1.prompt)('Enter the name of the app:', { type: 'text' });
33
+ name = await prompt('Enter the name of the app:', { type: 'text' });
34
34
  }
35
35
  try {
36
- const response = yield apps_1.default.create({ name });
37
- consola_1.default.success('App created successfully.');
38
- consola_1.default.info(`App ID: ${response.id}`);
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 = (0, error_1.getMessageFromUnknownError)(error);
42
- consola_1.default.error(message);
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
- "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 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 apps = yield apps_1.default.findAll();
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
- consola_1.default.error('You must create an app before deleting it.');
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 = yield (0, prompt_1.prompt)('Which app do you want to delete?', {
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 = yield (0, prompt_1.prompt)('Are you sure you want to delete this app?', {
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
- yield apps_1.default.delete({ id: appId });
52
- consola_1.default.success('App deleted successfully.');
50
+ await appsService.delete({ id: appId });
51
+ consola.success('App deleted successfully.');
53
52
  }
54
53
  catch (error) {
55
- const message = (0, error_1.getMessageFromUnknownError)(error);
56
- consola_1.default.error(message);
54
+ const message = getMessageFromUnknownError(error);
55
+ consola.error(message);
57
56
  process.exit(1);
58
57
  }
59
- }),
58
+ },
60
59
  });