@capawesome/cli 3.10.1 → 3.11.0

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 (44) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/commands/apps/builds/cancel.js +3 -3
  3. package/dist/commands/apps/builds/create.js +6 -6
  4. package/dist/commands/apps/builds/download.js +4 -4
  5. package/dist/commands/apps/builds/logs.js +3 -3
  6. package/dist/commands/apps/bundles/create.js +6 -6
  7. package/dist/commands/apps/bundles/delete.js +4 -4
  8. package/dist/commands/apps/bundles/delete.test.js +2 -2
  9. package/dist/commands/apps/bundles/update.js +3 -3
  10. package/dist/commands/apps/bundles/update.test.js +2 -2
  11. package/dist/commands/apps/channels/create.js +3 -3
  12. package/dist/commands/apps/channels/create.test.js +2 -2
  13. package/dist/commands/apps/channels/delete.js +14 -6
  14. package/dist/commands/apps/channels/delete.test.js +24 -9
  15. package/dist/commands/apps/channels/list.js +34 -2
  16. package/dist/commands/apps/channels/list.test.js +1 -1
  17. package/dist/commands/apps/channels/update.js +3 -3
  18. package/dist/commands/apps/channels/update.test.js +2 -2
  19. package/dist/commands/apps/create.js +3 -3
  20. package/dist/commands/apps/create.test.js +2 -2
  21. package/dist/commands/apps/delete.js +3 -3
  22. package/dist/commands/apps/delete.test.js +2 -2
  23. package/dist/commands/apps/deployments/cancel.js +3 -3
  24. package/dist/commands/apps/deployments/create.js +4 -4
  25. package/dist/commands/apps/deployments/logs.js +3 -3
  26. package/dist/commands/apps/devices/delete.js +4 -4
  27. package/dist/commands/apps/devices/delete.test.js +2 -2
  28. package/dist/commands/apps/environments/create.js +68 -0
  29. package/dist/commands/apps/environments/delete.js +87 -0
  30. package/dist/commands/apps/environments/list.js +69 -0
  31. package/dist/commands/apps/environments/set.js +126 -0
  32. package/dist/commands/apps/environments/unset.js +98 -0
  33. package/dist/commands/login.js +2 -2
  34. package/dist/commands/login.test.js +4 -4
  35. package/dist/commands/manifests/generate.js +2 -2
  36. package/dist/commands/manifests/generate.test.js +2 -2
  37. package/dist/commands/organizations/create.js +2 -2
  38. package/dist/commands/organizations/create.test.js +2 -2
  39. package/dist/index.js +5 -0
  40. package/dist/services/app-environments.js +67 -2
  41. package/dist/utils/app-environments.js +34 -0
  42. package/dist/utils/app-environments.ts.test.js +76 -0
  43. package/dist/utils/environment.js +20 -0
  44. package/package.json +2 -3
@@ -6,7 +6,7 @@ import organizationsService from '../../../services/organizations.js';
6
6
  import { prompt } from '../../../utils/prompt.js';
7
7
  import { defineCommand, defineOptions } from '@robingenz/zli';
8
8
  import consola from 'consola';
9
- import { hasTTY } from 'std-env';
9
+ import { isInteractive } from '../../../utils/environment.js';
10
10
  import { z } from 'zod';
11
11
  export default defineCommand({
12
12
  description: 'Cancel an ongoing app deployment.',
@@ -33,7 +33,7 @@ export default defineCommand({
33
33
  }
34
34
  // Prompt for app ID if not provided
35
35
  if (!appId) {
36
- if (!hasTTY) {
36
+ if (!isInteractive()) {
37
37
  consola.error('You must provide an app ID when running in non-interactive environment.');
38
38
  process.exit(1);
39
39
  }
@@ -70,7 +70,7 @@ export default defineCommand({
70
70
  }
71
71
  // Prompt for deployment ID if not provided
72
72
  if (!deploymentId) {
73
- if (!hasTTY) {
73
+ if (!isInteractive()) {
74
74
  consola.error('You must provide a deployment ID when running in non-interactive environment.');
75
75
  process.exit(1);
76
76
  }
@@ -10,7 +10,7 @@ import { prompt } from '../../../utils/prompt.js';
10
10
  import { wait } from '../../../utils/wait.js';
11
11
  import { defineCommand, defineOptions } from '@robingenz/zli';
12
12
  import consola from 'consola';
13
- import { hasTTY } from 'std-env';
13
+ import { isInteractive } from '../../../utils/environment.js';
14
14
  import { z } from 'zod';
15
15
  export default defineCommand({
16
16
  description: 'Create a new app deployment.',
@@ -42,7 +42,7 @@ export default defineCommand({
42
42
  }
43
43
  // Prompt for app ID if not provided
44
44
  if (!appId) {
45
- if (!hasTTY) {
45
+ if (!isInteractive()) {
46
46
  consola.error('You must provide an app ID when running in non-interactive environment.');
47
47
  process.exit(1);
48
48
  }
@@ -79,7 +79,7 @@ export default defineCommand({
79
79
  }
80
80
  // Prompt for build ID if not provided
81
81
  if (!buildId) {
82
- if (!hasTTY) {
82
+ if (!isInteractive()) {
83
83
  consola.error('You must provide a build ID when running in non-interactive environment.');
84
84
  process.exit(1);
85
85
  }
@@ -105,7 +105,7 @@ export default defineCommand({
105
105
  const build = await appBuildsService.findOne({ appId, appBuildId: buildId });
106
106
  // Prompt for destination if not provided
107
107
  if (!destination) {
108
- if (!hasTTY) {
108
+ if (!isInteractive()) {
109
109
  consola.error('You must provide a destination when running in non-interactive environment.');
110
110
  process.exit(1);
111
111
  }
@@ -7,7 +7,7 @@ import { prompt } from '../../../utils/prompt.js';
7
7
  import { wait } from '../../../utils/wait.js';
8
8
  import { defineCommand, defineOptions } from '@robingenz/zli';
9
9
  import consola from 'consola';
10
- import { hasTTY } from 'std-env';
10
+ import { isInteractive } from '../../../utils/environment.js';
11
11
  import { z } from 'zod';
12
12
  export default defineCommand({
13
13
  description: 'View the deployment logs of an app.',
@@ -34,7 +34,7 @@ export default defineCommand({
34
34
  }
35
35
  // Prompt for app ID if not provided
36
36
  if (!appId) {
37
- if (!hasTTY) {
37
+ if (!isInteractive()) {
38
38
  consola.error('You must provide an app ID when running in non-interactive environment.');
39
39
  process.exit(1);
40
40
  }
@@ -71,7 +71,7 @@ export default defineCommand({
71
71
  }
72
72
  // Prompt for deployment ID if not provided
73
73
  if (!deploymentId) {
74
- if (!hasTTY) {
74
+ if (!isInteractive()) {
75
75
  consola.error('You must provide a deployment ID when running in non-interactive environment.');
76
76
  process.exit(1);
77
77
  }
@@ -5,7 +5,7 @@ import organizationsService from '../../../services/organizations.js';
5
5
  import { prompt } from '../../../utils/prompt.js';
6
6
  import { defineCommand, defineOptions } from '@robingenz/zli';
7
7
  import consola from 'consola';
8
- import { hasTTY } from 'std-env';
8
+ import { isInteractive } from '../../../utils/environment.js';
9
9
  import { z } from 'zod';
10
10
  export default defineCommand({
11
11
  description: 'Delete an app device.',
@@ -21,7 +21,7 @@ export default defineCommand({
21
21
  }
22
22
  // Prompt for app ID if not provided
23
23
  if (!appId) {
24
- if (!hasTTY) {
24
+ if (!isInteractive()) {
25
25
  consola.error('You must provide an app ID when running in non-interactive environment.');
26
26
  process.exit(1);
27
27
  }
@@ -54,7 +54,7 @@ export default defineCommand({
54
54
  }
55
55
  // Prompt for device ID if not provided
56
56
  if (!deviceId) {
57
- if (!hasTTY) {
57
+ if (!isInteractive()) {
58
58
  consola.error('You must provide the device ID when running in non-interactive environment.');
59
59
  process.exit(1);
60
60
  }
@@ -63,7 +63,7 @@ export default defineCommand({
63
63
  });
64
64
  }
65
65
  // Confirm deletion
66
- if (hasTTY) {
66
+ if (isInteractive()) {
67
67
  const confirmed = await prompt('Are you sure you want to delete this device?', {
68
68
  type: 'confirm',
69
69
  });
@@ -11,8 +11,8 @@ vi.mock('@/utils/user-config.js');
11
11
  vi.mock('@/utils/prompt.js');
12
12
  vi.mock('@/services/authorization-service.js');
13
13
  vi.mock('consola');
14
- vi.mock('std-env', () => ({
15
- hasTTY: true,
14
+ vi.mock('@/utils/environment.js', () => ({
15
+ isInteractive: () => true,
16
16
  }));
17
17
  describe('apps-devices-delete', () => {
18
18
  const mockUserConfig = vi.mocked(userConfig);
@@ -0,0 +1,68 @@
1
+ import appEnvironmentsService from '../../../services/app-environments.js';
2
+ import appsService from '../../../services/apps.js';
3
+ import authorizationService from '../../../services/authorization-service.js';
4
+ import organizationsService from '../../../services/organizations.js';
5
+ import { isInteractive } from '../../../utils/environment.js';
6
+ import { prompt } from '../../../utils/prompt.js';
7
+ import { defineCommand, defineOptions } from '@robingenz/zli';
8
+ import consola from 'consola';
9
+ import { z } from 'zod';
10
+ export default defineCommand({
11
+ description: 'Create a new environment.',
12
+ options: defineOptions(z.object({
13
+ appId: z.string().optional().describe('ID of the app.'),
14
+ name: z.string().optional().describe('Name of the environment.'),
15
+ })),
16
+ action: async (options, args) => {
17
+ let { appId, name } = options;
18
+ if (!authorizationService.hasAuthorizationToken()) {
19
+ consola.error('You must be logged in to run this command. Please run the `login` command first.');
20
+ process.exit(1);
21
+ }
22
+ if (!appId) {
23
+ if (!isInteractive()) {
24
+ consola.error('You must provide an app ID when running in non-interactive environment.');
25
+ process.exit(1);
26
+ }
27
+ const organizations = await organizationsService.findAll();
28
+ if (organizations.length === 0) {
29
+ consola.error('You must create an organization before creating an environment.');
30
+ process.exit(1);
31
+ }
32
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
33
+ const organizationId = await prompt('Select the organization of the app for which you want to create an environment.', {
34
+ type: 'select',
35
+ options: organizations.map((organization) => ({ label: organization.name, value: organization.id })),
36
+ });
37
+ if (!organizationId) {
38
+ consola.error('You must select the organization of an app for which you want to create an environment.');
39
+ process.exit(1);
40
+ }
41
+ const apps = await appsService.findAll({
42
+ organizationId,
43
+ });
44
+ if (!apps.length) {
45
+ consola.error('You must create an app before creating an environment.');
46
+ process.exit(1);
47
+ }
48
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
49
+ appId = await prompt('Which app do you want to create the environment for?', {
50
+ type: 'select',
51
+ options: apps.map((app) => ({ label: app.name, value: app.id })),
52
+ });
53
+ }
54
+ if (!name) {
55
+ if (!isInteractive()) {
56
+ consola.error('You must provide the environment name when running in non-interactive environment.');
57
+ process.exit(1);
58
+ }
59
+ name = await prompt('Enter the name of the environment:', { type: 'text' });
60
+ }
61
+ const response = await appEnvironmentsService.create({
62
+ appId,
63
+ name,
64
+ });
65
+ consola.success('Environment created successfully.');
66
+ consola.info(`Environment ID: ${response.id}`);
67
+ },
68
+ });
@@ -0,0 +1,87 @@
1
+ import appEnvironmentsService from '../../../services/app-environments.js';
2
+ import appsService from '../../../services/apps.js';
3
+ import authorizationService from '../../../services/authorization-service.js';
4
+ import organizationsService from '../../../services/organizations.js';
5
+ import { isInteractive } from '../../../utils/environment.js';
6
+ import { prompt } from '../../../utils/prompt.js';
7
+ import { defineCommand, defineOptions } from '@robingenz/zli';
8
+ import consola from 'consola';
9
+ import { z } from 'zod';
10
+ export default defineCommand({
11
+ description: 'Delete an environment.',
12
+ options: defineOptions(z.object({
13
+ appId: z.string().optional().describe('ID of the app.'),
14
+ environmentId: z.string().optional().describe('ID of the environment. Either the ID or name must be provided.'),
15
+ name: z.string().optional().describe('Name of the environment. Either the ID or name must be provided.'),
16
+ })),
17
+ action: async (options, args) => {
18
+ let { appId, environmentId, name } = options;
19
+ if (!authorizationService.hasAuthorizationToken()) {
20
+ consola.error('You must be logged in to run this command. Please run the `login` command first.');
21
+ process.exit(1);
22
+ }
23
+ if (!appId) {
24
+ if (!isInteractive()) {
25
+ consola.error('You must provide an app ID when running in non-interactive environment.');
26
+ process.exit(1);
27
+ }
28
+ const organizations = await organizationsService.findAll();
29
+ if (organizations.length === 0) {
30
+ consola.error('You must create an organization before deleting an environment.');
31
+ process.exit(1);
32
+ }
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 from which you want to delete an environment.', {
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 from which you want to delete an environment.');
40
+ process.exit(1);
41
+ }
42
+ const apps = await appsService.findAll({
43
+ organizationId,
44
+ });
45
+ if (!apps.length) {
46
+ consola.error('You must create an app before deleting an environment.');
47
+ process.exit(1);
48
+ }
49
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
50
+ appId = await prompt('Which app do you want to delete the environment from?', {
51
+ type: 'select',
52
+ options: apps.map((app) => ({ label: app.name, value: app.id })),
53
+ });
54
+ }
55
+ if (!environmentId && !name) {
56
+ if (!isInteractive()) {
57
+ consola.error('You must provide either the environment ID or name when running in non-interactive environment.');
58
+ process.exit(1);
59
+ }
60
+ const environments = await appEnvironmentsService.findAll({ appId });
61
+ if (!environments.length) {
62
+ consola.error('No environments found for this app. Create one first.');
63
+ process.exit(1);
64
+ }
65
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
66
+ const selectedEnvironmentId = await prompt('Select the environment to delete:', {
67
+ type: 'select',
68
+ options: environments.map((env) => ({ label: env.name, value: env.id })),
69
+ });
70
+ environmentId = selectedEnvironmentId;
71
+ }
72
+ if (isInteractive()) {
73
+ const confirmed = await prompt('Are you sure you want to delete this environment?', {
74
+ type: 'confirm',
75
+ });
76
+ if (!confirmed) {
77
+ return;
78
+ }
79
+ }
80
+ await appEnvironmentsService.delete({
81
+ appId,
82
+ id: environmentId,
83
+ name,
84
+ });
85
+ consola.success('Environment deleted successfully.');
86
+ },
87
+ });
@@ -0,0 +1,69 @@
1
+ import appEnvironmentsService from '../../../services/app-environments.js';
2
+ import appsService from '../../../services/apps.js';
3
+ import authorizationService from '../../../services/authorization-service.js';
4
+ import organizationsService from '../../../services/organizations.js';
5
+ import { isInteractive } from '../../../utils/environment.js';
6
+ import { prompt } from '../../../utils/prompt.js';
7
+ import { defineCommand, defineOptions } from '@robingenz/zli';
8
+ import consola from 'consola';
9
+ import { z } from 'zod';
10
+ export default defineCommand({
11
+ description: 'List all environments for an app.',
12
+ options: defineOptions(z.object({
13
+ appId: z.string().optional().describe('ID of the app.'),
14
+ json: z.boolean().optional().describe('Output in JSON format.'),
15
+ limit: z.coerce.number().optional().describe('Limit for pagination.'),
16
+ offset: z.coerce.number().optional().describe('Offset for pagination.'),
17
+ })),
18
+ action: async (options, args) => {
19
+ let { appId, json, limit, offset } = options;
20
+ if (!authorizationService.hasAuthorizationToken()) {
21
+ consola.error('You must be logged in to run this command. Please run the `login` command first.');
22
+ process.exit(1);
23
+ }
24
+ if (!appId) {
25
+ if (!isInteractive()) {
26
+ consola.error('You must provide an app ID when running in non-interactive environment.');
27
+ process.exit(1);
28
+ }
29
+ const organizations = await organizationsService.findAll();
30
+ if (organizations.length === 0) {
31
+ consola.error('You must create an organization before listing environments.');
32
+ process.exit(1);
33
+ }
34
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
35
+ const organizationId = await prompt('Select the organization of the app for which you want to list environments.', {
36
+ type: 'select',
37
+ options: organizations.map((organization) => ({ label: organization.name, value: organization.id })),
38
+ });
39
+ if (!organizationId) {
40
+ consola.error('You must select the organization of an app for which you want to list environments.');
41
+ process.exit(1);
42
+ }
43
+ const apps = await appsService.findAll({
44
+ organizationId,
45
+ });
46
+ if (!apps.length) {
47
+ consola.error('You must create an app before listing environments.');
48
+ process.exit(1);
49
+ }
50
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
51
+ appId = await prompt('Which app do you want to list the environments for?', {
52
+ type: 'select',
53
+ options: apps.map((app) => ({ label: app.name, value: app.id })),
54
+ });
55
+ }
56
+ const environments = await appEnvironmentsService.findAll({
57
+ appId,
58
+ limit,
59
+ offset,
60
+ });
61
+ if (json) {
62
+ console.log(JSON.stringify(environments, null, 2));
63
+ }
64
+ else {
65
+ console.table(environments);
66
+ consola.success('Environments retrieved successfully.');
67
+ }
68
+ },
69
+ });
@@ -0,0 +1,126 @@
1
+ import appEnvironmentsService from '../../../services/app-environments.js';
2
+ import appsService from '../../../services/apps.js';
3
+ import authorizationService from '../../../services/authorization-service.js';
4
+ import organizationsService from '../../../services/organizations.js';
5
+ import { parseKeyValuePairs } from '../../../utils/app-environments.js';
6
+ import { isInteractive } from '../../../utils/environment.js';
7
+ import { prompt } from '../../../utils/prompt.js';
8
+ import { defineCommand, defineOptions } from '@robingenz/zli';
9
+ import consola from 'consola';
10
+ import fs from 'fs';
11
+ import { z } from 'zod';
12
+ export default defineCommand({
13
+ description: 'Set environment variables and secrets.',
14
+ options: defineOptions(z.object({
15
+ appId: z.string().optional().describe('ID of the app.'),
16
+ environmentId: z.string().optional().describe('ID of the environment.'),
17
+ variable: z
18
+ .array(z.string())
19
+ .optional()
20
+ .describe('Environment variable in key=value format. Can be specified multiple times.'),
21
+ variableFile: z.string().optional().describe('Path to a file containing environment variables in .env format.'),
22
+ secret: z
23
+ .array(z.string())
24
+ .optional()
25
+ .describe('Environment secret in key=value format. Can be specified multiple times.'),
26
+ secretFile: z.string().optional().describe('Path to a file containing environment secrets in .env format.'),
27
+ })),
28
+ action: async (options, args) => {
29
+ let { appId, environmentId, variable, variableFile, secret, secretFile } = options;
30
+ if (!authorizationService.hasAuthorizationToken()) {
31
+ consola.error('You must be logged in to run this command. Please run the `login` command first.');
32
+ process.exit(1);
33
+ }
34
+ if (!appId) {
35
+ if (!isInteractive()) {
36
+ consola.error('You must provide an app ID when running in non-interactive environment.');
37
+ process.exit(1);
38
+ }
39
+ const organizations = await organizationsService.findAll();
40
+ if (organizations.length === 0) {
41
+ consola.error('You must create an organization before setting environment variables or secrets.');
42
+ process.exit(1);
43
+ }
44
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
45
+ const organizationId = await prompt('Select the organization of the app for which you want to set environment variables or secrets.', {
46
+ type: 'select',
47
+ options: organizations.map((organization) => ({ label: organization.name, value: organization.id })),
48
+ });
49
+ if (!organizationId) {
50
+ consola.error('You must select the organization of an app for which you want to set environment variables or secrets.');
51
+ process.exit(1);
52
+ }
53
+ const apps = await appsService.findAll({
54
+ organizationId,
55
+ });
56
+ if (!apps.length) {
57
+ consola.error('You must create an app before setting environment variables or secrets.');
58
+ process.exit(1);
59
+ }
60
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
61
+ appId = await prompt('Which app do you want to set the environment variables or secrets for?', {
62
+ type: 'select',
63
+ options: apps.map((app) => ({ label: app.name, value: app.id })),
64
+ });
65
+ }
66
+ if (!environmentId) {
67
+ if (!isInteractive()) {
68
+ consola.error('You must provide an environment ID when running in non-interactive environment.');
69
+ process.exit(1);
70
+ }
71
+ const environments = await appEnvironmentsService.findAll({ appId });
72
+ if (!environments.length) {
73
+ consola.error('No environments found for this app. Create one first.');
74
+ process.exit(1);
75
+ }
76
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
77
+ environmentId = await prompt('Select the environment:', {
78
+ type: 'select',
79
+ options: environments.map((env) => ({ label: env.name, value: env.id })),
80
+ });
81
+ }
82
+ // Parse variables from inline and file
83
+ const variablesMap = new Map();
84
+ if (variableFile) {
85
+ const fileContent = await fs.promises.readFile(variableFile, 'utf-8');
86
+ const fileVariables = parseKeyValuePairs(fileContent);
87
+ fileVariables.forEach((v) => variablesMap.set(v.key, v.value));
88
+ }
89
+ if (variable) {
90
+ const inlineVariables = parseKeyValuePairs(variable.join('\n'));
91
+ inlineVariables.forEach((v) => variablesMap.set(v.key, v.value));
92
+ }
93
+ const allVariables = Array.from(variablesMap.entries()).map(([key, value]) => ({ key, value }));
94
+ // Parse secrets from inline and file
95
+ const secretsMap = new Map();
96
+ if (secretFile) {
97
+ const fileContent = await fs.promises.readFile(secretFile, 'utf-8');
98
+ const fileSecrets = parseKeyValuePairs(fileContent);
99
+ fileSecrets.forEach((s) => secretsMap.set(s.key, s.value));
100
+ }
101
+ if (secret) {
102
+ const inlineSecrets = parseKeyValuePairs(secret.join('\n'));
103
+ inlineSecrets.forEach((s) => secretsMap.set(s.key, s.value));
104
+ }
105
+ const allSecrets = Array.from(secretsMap.entries()).map(([key, value]) => ({ key, value }));
106
+ if (!allVariables.length && !allSecrets.length) {
107
+ consola.error('You must provide at least one variable or secret to set.');
108
+ process.exit(1);
109
+ }
110
+ if (allVariables.length) {
111
+ await appEnvironmentsService.setVariables({
112
+ appId,
113
+ environmentId,
114
+ variables: allVariables,
115
+ });
116
+ }
117
+ if (allSecrets.length) {
118
+ await appEnvironmentsService.setSecrets({
119
+ appId,
120
+ environmentId,
121
+ secrets: allSecrets,
122
+ });
123
+ }
124
+ consola.success('Environment variables and secrets set successfully.');
125
+ },
126
+ });
@@ -0,0 +1,98 @@
1
+ import appEnvironmentsService from '../../../services/app-environments.js';
2
+ import appsService from '../../../services/apps.js';
3
+ import authorizationService from '../../../services/authorization-service.js';
4
+ import organizationsService from '../../../services/organizations.js';
5
+ import { isInteractive } from '../../../utils/environment.js';
6
+ import { prompt } from '../../../utils/prompt.js';
7
+ import { defineCommand, defineOptions } from '@robingenz/zli';
8
+ import consola from 'consola';
9
+ import { z } from 'zod';
10
+ export default defineCommand({
11
+ description: 'Unset environment variables and secrets.',
12
+ options: defineOptions(z.object({
13
+ appId: z.string().optional().describe('ID of the app.'),
14
+ environmentId: z.string().optional().describe('ID of the environment.'),
15
+ variable: z
16
+ .array(z.string())
17
+ .optional()
18
+ .describe('Key of the environment variable to unset. Can be specified multiple times.'),
19
+ secret: z
20
+ .array(z.string())
21
+ .optional()
22
+ .describe('Key of the environment secret to unset. Can be specified multiple times.'),
23
+ })),
24
+ action: async (options, args) => {
25
+ let { appId, environmentId, variable: variableKeys, secret: secretKeys } = options;
26
+ if (!authorizationService.hasAuthorizationToken()) {
27
+ consola.error('You must be logged in to run this command. Please run the `login` command first.');
28
+ process.exit(1);
29
+ }
30
+ if (!appId) {
31
+ if (!isInteractive()) {
32
+ consola.error('You must provide an app ID when running in non-interactive environment.');
33
+ process.exit(1);
34
+ }
35
+ const organizations = await organizationsService.findAll();
36
+ if (organizations.length === 0) {
37
+ consola.error('You must create an organization before unsetting environment variables or secrets.');
38
+ process.exit(1);
39
+ }
40
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
41
+ const organizationId = await prompt('Select the organization of the app for which you want to unset environment variables or secrets.', {
42
+ type: 'select',
43
+ options: organizations.map((organization) => ({ label: organization.name, value: organization.id })),
44
+ });
45
+ if (!organizationId) {
46
+ consola.error('You must select the organization of an app for which you want to unset environment variables or secrets.');
47
+ process.exit(1);
48
+ }
49
+ const apps = await appsService.findAll({
50
+ organizationId,
51
+ });
52
+ if (!apps.length) {
53
+ consola.error('You must create an app before unsetting environment variables or secrets.');
54
+ process.exit(1);
55
+ }
56
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
57
+ appId = await prompt('Which app do you want to unset the environment variables or secrets for?', {
58
+ type: 'select',
59
+ options: apps.map((app) => ({ label: app.name, value: app.id })),
60
+ });
61
+ }
62
+ if (!environmentId) {
63
+ if (!isInteractive()) {
64
+ consola.error('You must provide an environment ID when running in non-interactive environment.');
65
+ process.exit(1);
66
+ }
67
+ const environments = await appEnvironmentsService.findAll({ appId });
68
+ if (!environments.length) {
69
+ consola.error('No environments found for this app. Create one first.');
70
+ process.exit(1);
71
+ }
72
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
73
+ environmentId = await prompt('Select the environment:', {
74
+ type: 'select',
75
+ options: environments.map((env) => ({ label: env.name, value: env.id })),
76
+ });
77
+ }
78
+ if (!variableKeys?.length && !secretKeys?.length) {
79
+ consola.error('You must provide at least one variable key or secret key to unset.');
80
+ process.exit(1);
81
+ }
82
+ if (variableKeys?.length) {
83
+ await appEnvironmentsService.unsetVariables({
84
+ appId,
85
+ environmentId,
86
+ keys: variableKeys,
87
+ });
88
+ }
89
+ if (secretKeys?.length) {
90
+ await appEnvironmentsService.unsetSecrets({
91
+ appId,
92
+ environmentId,
93
+ keys: secretKeys,
94
+ });
95
+ }
96
+ consola.success('Environment variables and secrets unset successfully.');
97
+ },
98
+ });
@@ -2,13 +2,13 @@ import configService from '../services/config.js';
2
2
  import sessionCodesService from '../services/session-code.js';
3
3
  import sessionsService from '../services/sessions.js';
4
4
  import usersService from '../services/users.js';
5
+ import { isInteractive } from '../utils/environment.js';
5
6
  import { prompt } from '../utils/prompt.js';
6
7
  import userConfig from '../utils/user-config.js';
7
8
  import { defineCommand, defineOptions } from '@robingenz/zli';
8
9
  import { AxiosError } from 'axios';
9
10
  import consola from 'consola';
10
11
  import open from 'open';
11
- import { hasTTY } from 'std-env';
12
12
  import { z } from 'zod';
13
13
  export default defineCommand({
14
14
  description: 'Sign in to the Capawesome Cloud Console.',
@@ -19,7 +19,7 @@ export default defineCommand({
19
19
  const consoleBaseUrl = await configService.getValueForKey('CONSOLE_BASE_URL');
20
20
  let { token: sessionIdOrToken } = options;
21
21
  if (sessionIdOrToken === undefined) {
22
- if (!hasTTY) {
22
+ if (!isInteractive()) {
23
23
  consola.error('You must provide a token when running in non-interactive environment.');
24
24
  process.exit(1);
25
25
  }
@@ -17,11 +17,11 @@ vi.mock('@/services/config.js');
17
17
  vi.mock('open');
18
18
  vi.mock('consola');
19
19
  vi.mock('@/utils/prompt.js');
20
- vi.mock('std-env', () => ({
21
- hasTTY: true,
20
+ vi.mock('@/utils/environment.js', () => ({
21
+ isInteractive: () => true,
22
22
  }));
23
- vi.mock('std-env', () => ({
24
- hasTTY: true,
23
+ vi.mock('@/utils/environment.js', () => ({
24
+ isInteractive: () => true,
25
25
  }));
26
26
  describe('login', () => {
27
27
  const mockUserConfig = vi.mocked(userConfig);
@@ -3,7 +3,7 @@ import { generateManifestJson } from '../../utils/manifest.js';
3
3
  import { prompt } from '../../utils/prompt.js';
4
4
  import { defineCommand, defineOptions } from '@robingenz/zli';
5
5
  import consola from 'consola';
6
- import { hasTTY } from 'std-env';
6
+ import { isInteractive } from '../../utils/environment.js';
7
7
  import { z } from 'zod';
8
8
  export default defineCommand({
9
9
  description: 'Generate a manifest file.',
@@ -13,7 +13,7 @@ export default defineCommand({
13
13
  action: async (options, args) => {
14
14
  let path = options.path;
15
15
  if (!path) {
16
- if (!hasTTY) {
16
+ if (!isInteractive()) {
17
17
  consola.error('You must provide the path to the web assets folder when running in non-interactive environment.');
18
18
  process.exit(1);
19
19
  }
@@ -9,8 +9,8 @@ vi.mock('@/utils/file.js');
9
9
  vi.mock('@/utils/manifest.js');
10
10
  vi.mock('@/utils/prompt.js');
11
11
  vi.mock('consola');
12
- vi.mock('std-env', () => ({
13
- hasTTY: true,
12
+ vi.mock('@/utils/environment.js', () => ({
13
+ isInteractive: () => true,
14
14
  }));
15
15
  describe('manifests-generate', () => {
16
16
  const mockFileExistsAtPath = vi.mocked(fileExistsAtPath);