@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,60 +1,55 @@
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_bundles_1 = __importDefault(require("../../../services/app-bundles"));
18
- const apps_1 = __importDefault(require("../../../services/apps"));
19
- const error_1 = require("../../../utils/error");
20
- const prompt_1 = require("../../../utils/prompt");
21
- exports.default = (0, citty_1.defineCommand)({
22
- meta: {
23
- description: 'Delete an app bundle.',
24
- },
25
- args: {
26
- appId: {
27
- type: 'string',
28
- description: 'ID of the app.',
29
- },
30
- bundleId: {
31
- type: 'string',
32
- description: 'ID of the bundle.',
33
- },
34
- },
35
- run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
1
+ import { defineCommand, defineOptions } from '@robingenz/zli';
2
+ import consola from 'consola';
3
+ import { z } from 'zod';
4
+ import appBundlesService from '../../../services/app-bundles.js';
5
+ import appsService from '../../../services/apps.js';
6
+ import organizationsService from '../../../services/organizations.js';
7
+ import { getMessageFromUnknownError } from '../../../utils/error.js';
8
+ import { prompt } from '../../../utils/prompt.js';
9
+ export default defineCommand({
10
+ description: 'Delete an app bundle.',
11
+ options: defineOptions(z.object({
12
+ appId: z.string().optional().describe('ID of the app.'),
13
+ bundleId: z.string().optional().describe('ID of the bundle.'),
14
+ })),
15
+ action: async (options, args) => {
16
+ let { appId, bundleId } = options;
36
17
  // Prompt for missing arguments
37
- let appId = ctx.args.appId;
38
- let bundleId = ctx.args.bundleId;
39
18
  if (!appId) {
40
- const apps = yield apps_1.default.findAll();
19
+ const organizations = await organizationsService.findAll();
20
+ if (organizations.length === 0) {
21
+ consola.error('You must create an organization before deleting a bundle.');
22
+ process.exit(1);
23
+ }
24
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
25
+ const organizationId = await prompt('Select the organization of the app from which you want to delete a bundle.', {
26
+ type: 'select',
27
+ options: organizations.map((organization) => ({ label: organization.name, value: organization.id })),
28
+ });
29
+ if (!organizationId) {
30
+ consola.error('You must select the organization of an app from which you want to delete a bundle.');
31
+ process.exit(1);
32
+ }
33
+ const apps = await appsService.findAll({
34
+ organizationId,
35
+ });
41
36
  if (!apps.length) {
42
- consola_1.default.error('You must create an app before deleting a bundle.');
37
+ consola.error('You must create an app before deleting a bundle.');
43
38
  process.exit(1);
44
39
  }
45
40
  // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
46
- appId = yield (0, prompt_1.prompt)('Which app do you want to delete the bundle from?', {
41
+ appId = await prompt('Which app do you want to delete the bundle from?', {
47
42
  type: 'select',
48
43
  options: apps.map((app) => ({ label: app.name, value: app.id })),
49
44
  });
50
45
  }
51
46
  if (!bundleId) {
52
- bundleId = yield (0, prompt_1.prompt)('Enter the bundle ID:', {
47
+ bundleId = await prompt('Enter the bundle ID:', {
53
48
  type: 'text',
54
49
  });
55
50
  }
56
51
  // Confirm deletion
57
- const confirmed = yield (0, prompt_1.prompt)('Are you sure you want to delete this bundle?', {
52
+ const confirmed = await prompt('Are you sure you want to delete this bundle?', {
58
53
  type: 'confirm',
59
54
  });
60
55
  if (!confirmed) {
@@ -62,16 +57,16 @@ exports.default = (0, citty_1.defineCommand)({
62
57
  }
63
58
  // Delete bundle
64
59
  try {
65
- yield app_bundles_1.default.delete({
60
+ await appBundlesService.delete({
66
61
  appId,
67
62
  appBundleId: bundleId,
68
63
  });
69
- consola_1.default.success('Bundle deleted successfully.');
64
+ consola.success('Bundle deleted successfully.');
70
65
  }
71
66
  catch (error) {
72
- const message = (0, error_1.getMessageFromUnknownError)(error);
73
- consola_1.default.error(message);
67
+ const message = getMessageFromUnknownError(error);
68
+ consola.error(message);
74
69
  process.exit(1);
75
70
  }
76
- }),
71
+ },
77
72
  });
@@ -1,102 +1,99 @@
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_bundles_1 = __importDefault(require("../../../services/app-bundles"));
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 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.');
1
+ import { defineCommand, defineOptions } from '@robingenz/zli';
2
+ import consola from 'consola';
3
+ import { z } from 'zod';
4
+ import appBundlesService from '../../../services/app-bundles.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 app bundle.',
12
+ options: defineOptions(z.object({
13
+ androidMax: z
14
+ .string()
15
+ .optional()
16
+ .describe('The maximum Android version code (`versionCode`) that the bundle supports.'),
17
+ androidMin: z
18
+ .string()
19
+ .optional()
20
+ .describe('The minimum Android version code (`versionCode`) that the bundle supports.'),
21
+ appId: z.string().optional().describe('ID of the app.'),
22
+ bundleId: z.string().optional().describe('ID of the bundle.'),
23
+ rollout: z.coerce
24
+ .number()
25
+ .min(0)
26
+ .max(1, {
27
+ message: 'Rollout percentage must be a number between 0 and 1 (e.g. 0.5).',
28
+ })
29
+ .optional()
30
+ .describe('The percentage of devices to deploy the bundle to. Must be a number between 0 and 1 (e.g. 0.5).'),
31
+ iosMax: z
32
+ .string()
33
+ .optional()
34
+ .describe('The maximum iOS bundle version (`CFBundleVersion`) that the bundle supports.'),
35
+ iosMin: z
36
+ .string()
37
+ .optional()
38
+ .describe('The minimum iOS bundle version (`CFBundleVersion`) that the bundle supports.'),
39
+ })),
40
+ action: async (options, args) => {
41
+ let { androidMax, androidMin, appId, bundleId, rollout, iosMax, iosMin } = options;
42
+ if (!authorizationService.hasAuthorizationToken()) {
43
+ consola.error('You must be logged in to run this command.');
59
44
  process.exit(1);
60
45
  }
61
46
  // 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
47
  if (!appId) {
66
- const apps = yield apps_1.default.findAll();
48
+ const organizations = await organizationsService.findAll();
49
+ if (organizations.length === 0) {
50
+ consola.error('You must create an organization before updating a bundle.');
51
+ process.exit(1);
52
+ }
53
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
54
+ const organizationId = await prompt('Select the organization of the app for which you want to update a bundle.', {
55
+ type: 'select',
56
+ options: organizations.map((organization) => ({ label: organization.name, value: organization.id })),
57
+ });
58
+ if (!organizationId) {
59
+ consola.error('You must select the organization of an app for which you want to update a bundle.');
60
+ process.exit(1);
61
+ }
62
+ const apps = await appsService.findAll({
63
+ organizationId,
64
+ });
67
65
  if (!apps.length) {
68
- consola_1.default.error('You must create an app before updating a bundle.');
66
+ consola.error('You must create an app before updating a bundle.');
69
67
  process.exit(1);
70
68
  }
71
69
  // @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?', {
70
+ appId = await prompt('Which app do you want to update the bundle for?', {
73
71
  type: 'select',
74
72
  options: apps.map((app) => ({ label: app.name, value: app.id })),
75
73
  });
76
74
  }
77
75
  if (!bundleId) {
78
- bundleId = yield (0, prompt_1.prompt)('Enter the bundle ID:', {
76
+ bundleId = await prompt('Enter the bundle ID:', {
79
77
  type: 'text',
80
78
  });
81
79
  }
82
80
  // Update bundle
83
81
  try {
84
- const rolloutAsNumber = parseFloat(rollout);
85
- yield app_bundles_1.default.update({
82
+ await appBundlesService.update({
86
83
  appId,
87
84
  appBundleId: bundleId,
88
85
  maxAndroidAppVersionCode: androidMax,
89
86
  maxIosAppVersionCode: iosMax,
90
87
  minAndroidAppVersionCode: androidMin,
91
88
  minIosAppVersionCode: iosMin,
92
- rolloutPercentage: rolloutAsNumber,
89
+ rolloutPercentage: rollout,
93
90
  });
94
- consola_1.default.success('Bundle updated successfully.');
91
+ consola.success('Bundle updated successfully.');
95
92
  }
96
93
  catch (error) {
97
- const message = (0, error_1.getMessageFromUnknownError)(error);
98
- consola_1.default.error(message);
94
+ const message = getMessageFromUnknownError(error);
95
+ consola.error(message);
99
96
  process.exit(1);
100
97
  }
101
- }),
98
+ },
102
99
  });
@@ -1,93 +1,70 @@
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 error_1 = require("../../../utils/error");
20
- const prompt_1 = require("../../../utils/prompt");
21
- exports.default = (0, citty_1.defineCommand)({
22
- meta: {
23
- description: 'Create a new app channel.',
24
- },
25
- args: {
26
- appId: {
27
- type: 'string',
28
- description: 'ID of the app.',
29
- },
30
- bundleLimit: {
31
- type: 'string',
32
- description: 'Maximum number of bundles that can be assigned to the channel. If more bundles are assigned, the oldest bundles will be automatically deleted.',
33
- },
34
- ignoreErrors: {
35
- type: 'boolean',
36
- description: 'Whether to ignore errors or not.',
37
- },
38
- name: {
39
- type: 'string',
40
- description: 'Name of the channel.',
41
- },
42
- },
43
- run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
44
- let appId = ctx.args.appId;
45
- let bundleLimitAsString = ctx.args.bundleLimit;
46
- let ignoreErrors = ctx.args.ignoreErrors;
47
- let name = ctx.args.name;
48
- // Convert ignoreErrors to boolean
49
- if (typeof ignoreErrors === 'string') {
50
- ignoreErrors = ignoreErrors.toLowerCase() === 'true';
51
- }
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 organizationsService from '../../../services/organizations.js';
7
+ import { getMessageFromUnknownError } from '../../../utils/error.js';
8
+ import { prompt } from '../../../utils/prompt.js';
9
+ export default defineCommand({
10
+ description: 'Create a new app channel.',
11
+ options: defineOptions(z.object({
12
+ appId: z.string().optional().describe('ID of the app.'),
13
+ bundleLimit: z.coerce
14
+ .number()
15
+ .optional()
16
+ .describe('Maximum number of bundles that can be assigned to the channel. If more bundles are assigned, the oldest bundles will be automatically deleted.'),
17
+ ignoreErrors: z.boolean().optional().describe('Whether to ignore errors or not.'),
18
+ name: z.string().optional().describe('Name of the channel.'),
19
+ })),
20
+ action: async (options, args) => {
21
+ let { appId, bundleLimit, ignoreErrors, name } = options;
52
22
  // Validate the app ID
53
23
  if (!appId) {
54
- const apps = yield apps_1.default.findAll();
55
- if (!apps.length) {
56
- consola_1.default.error('You must create an app before creating a channel.');
24
+ const organizations = await organizationsService.findAll();
25
+ if (organizations.length === 0) {
26
+ consola.error('You must create an organization before creating a channel.');
57
27
  process.exit(1);
58
28
  }
59
29
  // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
60
- appId = yield (0, prompt_1.prompt)('Which app do you want to create the channel for?', {
30
+ const organizationId = await prompt('Select the organization of the app for which you want to create a channel.', {
61
31
  type: 'select',
62
- options: apps.map((app) => ({ label: app.name, value: app.id })),
32
+ options: organizations.map((organization) => ({ label: organization.name, value: organization.id })),
63
33
  });
64
- }
65
- // Validate the bundle limit
66
- let bundleLimit;
67
- if (bundleLimitAsString) {
68
- bundleLimit = parseInt(bundleLimitAsString, 10);
69
- if (isNaN(bundleLimit)) {
70
- consola_1.default.error('The bundle limit must be a number.');
34
+ if (!organizationId) {
35
+ consola.error('You must select the organization of an app for which you want to create a channel.');
71
36
  process.exit(1);
72
37
  }
38
+ const apps = await appsService.findAll({
39
+ organizationId,
40
+ });
41
+ if (!apps.length) {
42
+ consola.error('You must create an app before creating a channel.');
43
+ process.exit(1);
44
+ }
45
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
46
+ appId = await prompt('Which app do you want to create the channel for?', {
47
+ type: 'select',
48
+ options: apps.map((app) => ({ label: app.name, value: app.id })),
49
+ });
73
50
  }
74
51
  // Validate the channel name
75
52
  if (!name) {
76
- name = yield (0, prompt_1.prompt)('Enter the name of the channel:', { type: 'text' });
53
+ name = await prompt('Enter the name of the channel:', { type: 'text' });
77
54
  }
78
55
  try {
79
- const response = yield app_channels_1.default.create({
56
+ const response = await appChannelsService.create({
80
57
  appId,
81
58
  name,
82
59
  totalAppBundleLimit: bundleLimit,
83
60
  });
84
- consola_1.default.success('Channel created successfully.');
85
- consola_1.default.info(`Channel ID: ${response.id}`);
61
+ consola.success('Channel created successfully.');
62
+ consola.info(`Channel ID: ${response.id}`);
86
63
  }
87
64
  catch (error) {
88
- const message = (0, error_1.getMessageFromUnknownError)(error);
89
- consola_1.default.error(message);
65
+ const message = getMessageFromUnknownError(error);
66
+ consola.error(message);
90
67
  process.exit(ignoreErrors ? 0 : 1);
91
68
  }
92
- }),
69
+ },
93
70
  });
@@ -1,65 +1,62 @@
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 ci_1 = require("../../../utils/ci");
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: 'Delete an 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. Either the ID or name of the channel must be provided.',
34
- },
35
- name: {
36
- type: 'string',
37
- description: 'Name of the channel. Either the ID or name of the channel must be provided.',
38
- },
39
- },
40
- run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
41
- let appId = ctx.args.appId;
42
- let channelId = ctx.args.channelId;
43
- let channelName = ctx.args.name;
1
+ import { defineCommand, defineOptions } from '@robingenz/zli';
2
+ import consola from 'consola';
3
+ import { isCI } from 'std-env';
4
+ import { z } from 'zod';
5
+ import appChannelsService from '../../../services/app-channels.js';
6
+ import appsService from '../../../services/apps.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: 'Delete an app channel.',
12
+ options: defineOptions(z.object({
13
+ appId: z.string().optional().describe('ID of the app.'),
14
+ channelId: z
15
+ .string()
16
+ .optional()
17
+ .describe('ID of the channel. Either the ID or name of the channel must be provided.'),
18
+ name: z
19
+ .string()
20
+ .optional()
21
+ .describe('Name of the channel. Either the ID or name of the channel must be provided.'),
22
+ })),
23
+ action: async (options, args) => {
24
+ let { appId, channelId, name } = options;
44
25
  if (!appId) {
45
- const apps = yield apps_1.default.findAll();
26
+ const organizations = await organizationsService.findAll();
27
+ if (organizations.length === 0) {
28
+ consola.error('You must create an organization before deleting a channel.');
29
+ process.exit(1);
30
+ }
31
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
32
+ const organizationId = await prompt('Select the organization of the app from which you want to delete a channel.', {
33
+ type: 'select',
34
+ options: organizations.map((organization) => ({ label: organization.name, value: organization.id })),
35
+ });
36
+ if (!organizationId) {
37
+ consola.error('You must select the organization of an app from which you want to delete a channel.');
38
+ process.exit(1);
39
+ }
40
+ const apps = await appsService.findAll({
41
+ organizationId,
42
+ });
46
43
  if (!apps.length) {
47
- consola_1.default.error('You must create an app before deleting a channel.');
44
+ consola.error('You must create an app before deleting a channel.');
48
45
  process.exit(1);
49
46
  }
50
47
  // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
51
- appId = yield (0, prompt_1.prompt)('Which app do you want to delete the channel from?', {
48
+ appId = await prompt('Which app do you want to delete the channel from?', {
52
49
  type: 'select',
53
50
  options: apps.map((app) => ({ label: app.name, value: app.id })),
54
51
  });
55
52
  }
56
- if (!channelId && !channelName) {
57
- channelName = yield (0, prompt_1.prompt)('Enter the channel name:', {
53
+ if (!channelId && !name) {
54
+ name = await prompt('Enter the channel name:', {
58
55
  type: 'text',
59
56
  });
60
57
  }
61
- if (!(0, ci_1.isRunningInCi)()) {
62
- const confirmed = yield (0, prompt_1.prompt)('Are you sure you want to delete this channel?', {
58
+ if (!isCI) {
59
+ const confirmed = await prompt('Are you sure you want to delete this channel?', {
63
60
  type: 'confirm',
64
61
  });
65
62
  if (!confirmed) {
@@ -67,17 +64,17 @@ exports.default = (0, citty_1.defineCommand)({
67
64
  }
68
65
  }
69
66
  try {
70
- yield app_channels_1.default.delete({
67
+ await appChannelsService.delete({
71
68
  appId,
72
69
  id: channelId,
73
- name: channelName,
70
+ name,
74
71
  });
75
- consola_1.default.success('Channel deleted successfully.');
72
+ consola.success('Channel deleted successfully.');
76
73
  }
77
74
  catch (error) {
78
- const message = (0, error_1.getMessageFromUnknownError)(error);
79
- consola_1.default.error(message);
75
+ const message = getMessageFromUnknownError(error);
76
+ consola.error(message);
80
77
  process.exit(1);
81
78
  }
82
- }),
79
+ },
83
80
  });