@usestatemachines/cli 0.0.0-stage → 0.1.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 (169) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +34 -2
  3. package/dist/agents/bundled.d.ts +5 -0
  4. package/dist/agents/bundled.js +6 -0
  5. package/dist/agents/destinations.d.ts +13 -0
  6. package/dist/agents/destinations.js +16 -0
  7. package/dist/api-internal.d.ts +62 -0
  8. package/dist/api-internal.js +348 -0
  9. package/dist/bin.d.ts +2 -0
  10. package/dist/bin.js +4 -0
  11. package/dist/command.d.ts +119 -0
  12. package/dist/command.js +195 -0
  13. package/dist/commands/api/command.d.ts +15 -0
  14. package/dist/commands/api/command.js +38 -0
  15. package/dist/commands/api/run.d.ts +4 -0
  16. package/dist/commands/api/run.js +24 -0
  17. package/dist/commands/apps/command.d.ts +19 -0
  18. package/dist/commands/apps/command.js +29 -0
  19. package/dist/commands/apps/list.d.ts +8 -0
  20. package/dist/commands/apps/list.js +10 -0
  21. package/dist/commands/connect/command.d.ts +34 -0
  22. package/dist/commands/connect/command.js +70 -0
  23. package/dist/commands/connect/run.d.ts +10 -0
  24. package/dist/commands/connect/run.js +71 -0
  25. package/dist/commands/doctor/command.d.ts +29 -0
  26. package/dist/commands/doctor/command.js +36 -0
  27. package/dist/commands/doctor/run.d.ts +13 -0
  28. package/dist/commands/doctor/run.js +12 -0
  29. package/dist/commands/env/command.d.ts +5 -0
  30. package/dist/commands/env/command.js +19 -0
  31. package/dist/commands/env/pull.d.ts +6 -0
  32. package/dist/commands/env/pull.js +6 -0
  33. package/dist/commands/environments/command.d.ts +121 -0
  34. package/dist/commands/environments/command.js +170 -0
  35. package/dist/commands/environments/create.d.ts +9 -0
  36. package/dist/commands/environments/create.js +42 -0
  37. package/dist/commands/environments/delete.d.ts +7 -0
  38. package/dist/commands/environments/delete.js +48 -0
  39. package/dist/commands/environments/get.d.ts +39 -0
  40. package/dist/commands/environments/get.js +5 -0
  41. package/dist/commands/environments/list.d.ts +41 -0
  42. package/dist/commands/environments/list.js +18 -0
  43. package/dist/commands/environments/wait.d.ts +39 -0
  44. package/dist/commands/environments/wait.js +21 -0
  45. package/dist/commands/init/command.d.ts +68 -0
  46. package/dist/commands/init/command.js +90 -0
  47. package/dist/commands/init/run.d.ts +8 -0
  48. package/dist/commands/init/run.js +422 -0
  49. package/dist/commands/link/command.d.ts +13 -0
  50. package/dist/commands/link/command.js +32 -0
  51. package/dist/commands/link/run.d.ts +12 -0
  52. package/dist/commands/link/run.js +7 -0
  53. package/dist/commands/login/command.d.ts +1 -0
  54. package/dist/commands/login/command.js +43 -0
  55. package/dist/commands/login/run.d.ts +30 -0
  56. package/dist/commands/login/run.js +43 -0
  57. package/dist/commands/login/schema.d.ts +33 -0
  58. package/dist/commands/login/schema.js +33 -0
  59. package/dist/commands/logout/command.d.ts +1 -0
  60. package/dist/commands/logout/command.js +24 -0
  61. package/dist/commands/logout/run.d.ts +10 -0
  62. package/dist/commands/logout/run.js +19 -0
  63. package/dist/commands/logout/schema.d.ts +10 -0
  64. package/dist/commands/logout/schema.js +10 -0
  65. package/dist/commands/profiles/command.d.ts +2 -0
  66. package/dist/commands/profiles/command.js +29 -0
  67. package/dist/commands/profiles/list.d.ts +20 -0
  68. package/dist/commands/profiles/list.js +10 -0
  69. package/dist/commands/profiles/schema.d.ts +24 -0
  70. package/dist/commands/profiles/schema.js +19 -0
  71. package/dist/commands/profiles/use.d.ts +7 -0
  72. package/dist/commands/profiles/use.js +7 -0
  73. package/dist/commands/requests/command.d.ts +39 -0
  74. package/dist/commands/requests/command.js +65 -0
  75. package/dist/commands/requests/get.d.ts +32 -0
  76. package/dist/commands/requests/get.js +15 -0
  77. package/dist/commands/requests/list.d.ts +27 -0
  78. package/dist/commands/requests/list.js +25 -0
  79. package/dist/commands/snapshots/command.d.ts +48 -0
  80. package/dist/commands/snapshots/command.js +80 -0
  81. package/dist/commands/snapshots/create.d.ts +7 -0
  82. package/dist/commands/snapshots/create.js +26 -0
  83. package/dist/commands/snapshots/delete.d.ts +34 -0
  84. package/dist/commands/snapshots/delete.js +8 -0
  85. package/dist/commands/snapshots/get.d.ts +35 -0
  86. package/dist/commands/snapshots/get.js +5 -0
  87. package/dist/commands/snapshots/list.d.ts +37 -0
  88. package/dist/commands/snapshots/list.js +10 -0
  89. package/dist/commands/unlink/command.d.ts +1 -0
  90. package/dist/commands/unlink/command.js +15 -0
  91. package/dist/commands/unlink/run.d.ts +7 -0
  92. package/dist/commands/unlink/run.js +8 -0
  93. package/dist/commands/whoami/command.d.ts +28 -0
  94. package/dist/commands/whoami/command.js +44 -0
  95. package/dist/commands/whoami/run.d.ts +5 -0
  96. package/dist/commands/whoami/run.js +39 -0
  97. package/dist/commands/workspaces/command.d.ts +33 -0
  98. package/dist/commands/workspaces/command.js +73 -0
  99. package/dist/commands/workspaces/list.d.ts +5 -0
  100. package/dist/commands/workspaces/list.js +42 -0
  101. package/dist/commands/workspaces/use.d.ts +5 -0
  102. package/dist/commands/workspaces/use.js +18 -0
  103. package/dist/config/project.d.ts +21 -0
  104. package/dist/config/project.js +105 -0
  105. package/dist/config/schema.d.ts +616 -0
  106. package/dist/config/schema.js +282 -0
  107. package/dist/context-types.d.ts +89 -0
  108. package/dist/context-types.js +56 -0
  109. package/dist/context.d.ts +13 -0
  110. package/dist/context.js +290 -0
  111. package/dist/credentials/sealing.d.ts +10 -0
  112. package/dist/credentials/sealing.js +72 -0
  113. package/dist/credentials/store.d.ts +17 -0
  114. package/dist/credentials/store.js +156 -0
  115. package/dist/doctor.d.ts +4 -0
  116. package/dist/doctor.js +239 -0
  117. package/dist/env-file.d.ts +10 -0
  118. package/dist/env-file.js +254 -0
  119. package/dist/errors.d.ts +784 -0
  120. package/dist/errors.js +459 -0
  121. package/dist/flags.d.ts +22 -0
  122. package/dist/flags.js +56 -0
  123. package/dist/generated/internal.d.ts +138 -0
  124. package/dist/generated/internal.js +2627 -0
  125. package/dist/generated/retry.d.ts +1 -0
  126. package/dist/generated/retry.js +11 -0
  127. package/dist/help.d.ts +408 -0
  128. package/dist/help.js +220 -0
  129. package/dist/io-types.d.ts +127 -0
  130. package/dist/io-types.js +1 -0
  131. package/dist/io.d.ts +13 -0
  132. package/dist/io.js +1017 -0
  133. package/dist/keys.d.ts +50 -0
  134. package/dist/keys.js +691 -0
  135. package/dist/link.d.ts +6 -0
  136. package/dist/link.js +58 -0
  137. package/dist/login.d.ts +92 -0
  138. package/dist/login.js +965 -0
  139. package/dist/main.d.ts +2 -0
  140. package/dist/main.js +126 -0
  141. package/dist/native-helper.d.ts +1 -0
  142. package/dist/native-helper.js +2 -0
  143. package/dist/output.d.ts +8 -0
  144. package/dist/output.js +135 -0
  145. package/dist/parser.d.ts +28 -0
  146. package/dist/parser.js +250 -0
  147. package/dist/program-types.d.ts +67 -0
  148. package/dist/program-types.js +14 -0
  149. package/dist/programs.d.ts +2 -0
  150. package/dist/programs.js +44 -0
  151. package/dist/project-roots.d.ts +3 -0
  152. package/dist/project-roots.js +26 -0
  153. package/dist/prompt.d.ts +3 -0
  154. package/dist/prompt.js +61 -0
  155. package/dist/registry.d.ts +2 -0
  156. package/dist/registry.js +44 -0
  157. package/dist/resources/create.d.ts +9 -0
  158. package/dist/resources/create.js +55 -0
  159. package/dist/resources/read.d.ts +15 -0
  160. package/dist/resources/read.js +69 -0
  161. package/dist/resources/schema.d.ts +177 -0
  162. package/dist/resources/schema.js +158 -0
  163. package/dist/text.d.ts +3 -0
  164. package/dist/text.js +19 -0
  165. package/dist/update.d.ts +22 -0
  166. package/dist/update.js +126 -0
  167. package/dist/version.d.ts +2 -0
  168. package/dist/version.js +2 -0
  169. package/package.json +52 -3
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+ export declare const doctorInputSchema: z.ZodObject<{
3
+ offline: z.ZodDefault<z.ZodBoolean>;
4
+ }, z.core.$strict>;
5
+ export declare const doctorCheckSchema: z.ZodObject<{
6
+ name: z.ZodString;
7
+ status: z.ZodEnum<{
8
+ failed: "failed";
9
+ ok: "ok";
10
+ skipped: "skipped";
11
+ warning: "warning";
12
+ }>;
13
+ message: z.ZodString;
14
+ fix: z.ZodNullable<z.ZodString>;
15
+ }, z.core.$strict>;
16
+ export declare const doctorResultSchema: z.ZodObject<{
17
+ checks: z.ZodArray<z.ZodObject<{
18
+ name: z.ZodString;
19
+ status: z.ZodEnum<{
20
+ failed: "failed";
21
+ ok: "ok";
22
+ skipped: "skipped";
23
+ warning: "warning";
24
+ }>;
25
+ message: z.ZodString;
26
+ fix: z.ZodNullable<z.ZodString>;
27
+ }, z.core.$strict>>;
28
+ }, z.core.$strict>;
29
+ export declare const doctorCommand: import("../../command.js").RegisteredCommand;
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod';
2
+ import { defineCommand } from '../../command.js';
3
+ export const doctorInputSchema = z.strictObject({
4
+ offline: z.boolean().default(false),
5
+ });
6
+ export const doctorCheckSchema = z.strictObject({
7
+ name: z.string(),
8
+ status: z.enum(['ok', 'warning', 'failed', 'skipped']),
9
+ message: z.string(),
10
+ fix: z.string().nullable(),
11
+ });
12
+ export const doctorResultSchema = z.strictObject({
13
+ checks: z.array(doctorCheckSchema),
14
+ });
15
+ export const doctorCommand = defineCommand({
16
+ name: ['doctor'],
17
+ summary: 'Check credentials, workspace access, and local configuration.',
18
+ need: 'public',
19
+ workspace: true,
20
+ destructive: false,
21
+ streams: false,
22
+ arguments: [],
23
+ flags: [
24
+ {
25
+ name: 'offline',
26
+ key: 'offline',
27
+ type: 'boolean',
28
+ negatedName: null,
29
+ description: 'Skip checks that need a network connection.',
30
+ },
31
+ ],
32
+ input: doctorInputSchema,
33
+ result: doctorResultSchema,
34
+ progress: z.never(),
35
+ load: () => import('./run.js'),
36
+ });
@@ -0,0 +1,13 @@
1
+ import type { z } from 'zod';
2
+ import type { PublicContext } from '../../context-types.js';
3
+ import type { doctorInputSchema, doctorResultSchema } from './command.js';
4
+ export declare function run(input: z.infer<typeof doctorInputSchema>, context: PublicContext): Promise<{
5
+ checks: {
6
+ name: string;
7
+ status: "failed" | "ok" | "skipped" | "warning";
8
+ message: string;
9
+ fix: string | null;
10
+ }[];
11
+ }>;
12
+ export declare function text(result: z.infer<typeof doctorResultSchema>): string;
13
+ export declare function exitCode(result: z.infer<typeof doctorResultSchema>): 0 | 1;
@@ -0,0 +1,12 @@
1
+ import { runDoctor } from '../../doctor.js';
2
+ export function run(input, context) {
3
+ return runDoctor(context, input);
4
+ }
5
+ export function text(result) {
6
+ return `${result.checks
7
+ .map((check) => `${check.status}: ${check.name}: ${check.message}${check.fix === null ? '' : ` ${check.fix}`}`)
8
+ .join('\n')}\n`;
9
+ }
10
+ export function exitCode(result) {
11
+ return result.checks.some((check) => check.status === 'failed') ? 1 : 0;
12
+ }
@@ -0,0 +1,5 @@
1
+ import { z } from 'zod';
2
+ export declare const envPullInputSchema: z.ZodObject<{
3
+ file: z.ZodDefault<z.ZodString>;
4
+ }, z.core.$strict>;
5
+ export declare const envPullCommand: import("../../command.js").RegisteredCommand;
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ import { defineCommand } from '../../command.js';
3
+ import { envPullResultSchema } from '../../program-types.js';
4
+ export const envPullInputSchema = z.strictObject({
5
+ file: z.string().min(1).default('.env.local'),
6
+ });
7
+ export const envPullCommand = defineCommand({
8
+ name: ['env', 'pull'],
9
+ summary: 'Write a workspace key to a dotenv file. Replaces the previous key for this repository and workspace, even when the file changes.',
10
+ need: 'workspace',
11
+ destructive: false,
12
+ streams: false,
13
+ arguments: [{ name: 'file', key: 'file', required: false, many: false }],
14
+ flags: [],
15
+ input: envPullInputSchema,
16
+ result: envPullResultSchema,
17
+ progress: z.never(),
18
+ load: () => import('./pull.js'),
19
+ });
@@ -0,0 +1,6 @@
1
+ import type { z } from 'zod';
2
+ import type { WorkspaceContext } from '../../context-types.js';
3
+ import type { EnvPullResult } from '../../program-types.js';
4
+ import type { envPullInputSchema } from './command.js';
5
+ export declare function run(input: z.infer<typeof envPullInputSchema>, context: WorkspaceContext): Promise<EnvPullResult>;
6
+ export declare function text(result: EnvPullResult): string;
@@ -0,0 +1,6 @@
1
+ export async function run(input, context) {
2
+ return context.programs.pullEnvironment(input.file);
3
+ }
4
+ export function text(result) {
5
+ return `Wrote workspace key to ${result.path}. Expires ${result.expiresAt}.${result.pendingRevocation ? ' Previous key revocation is pending.' : ''}\n`;
6
+ }
@@ -0,0 +1,121 @@
1
+ import { z } from 'zod';
2
+ export declare const createInputSchema: z.ZodObject<{
3
+ app: z.ZodOptional<z.ZodArray<z.ZodString>>;
4
+ snapshot: z.ZodOptional<z.ZodString>;
5
+ name: z.ZodOptional<z.ZodString>;
6
+ label: z.ZodDefault<z.ZodArray<z.ZodString>>;
7
+ timeLimit: z.ZodOptional<z.ZodString>;
8
+ idempotencyKey: z.ZodOptional<z.ZodString>;
9
+ wait: z.ZodOptional<z.ZodBoolean>;
10
+ }, z.core.$strict>;
11
+ export declare const environmentsCreateCommand: import("../../command.js").RegisteredCommand;
12
+ export declare const listInputSchema: z.ZodObject<{
13
+ limit: z.ZodOptional<z.ZodString>;
14
+ cursor: z.ZodOptional<z.ZodString>;
15
+ all: z.ZodDefault<z.ZodBoolean>;
16
+ status: z.ZodOptional<z.ZodArray<z.ZodEnum<{
17
+ deleted: "deleted";
18
+ failed: "failed";
19
+ running: "running";
20
+ starting: "starting";
21
+ }>>>;
22
+ label: z.ZodDefault<z.ZodArray<z.ZodString>>;
23
+ }, z.core.$strict>;
24
+ export declare const listResultSchema: z.ZodObject<{
25
+ data: z.ZodArray<z.ZodObject<{
26
+ id: z.ZodString;
27
+ workspaceId: z.ZodString;
28
+ name: z.ZodNullable<z.ZodString>;
29
+ labels: z.ZodRecord<z.ZodString, z.ZodString>;
30
+ status: z.ZodString;
31
+ reason: z.ZodNullable<z.ZodString>;
32
+ failure: z.ZodNullable<z.ZodObject<{
33
+ appName: z.ZodString;
34
+ code: z.ZodString;
35
+ message: z.ZodString;
36
+ }, z.core.$strict>>;
37
+ timeLimitMinutes: z.ZodNumber;
38
+ tokenInUrl: z.ZodBoolean;
39
+ snapshotId: z.ZodNullable<z.ZodString>;
40
+ apps: z.ZodArray<z.ZodObject<{
41
+ appId: z.ZodString;
42
+ name: z.ZodString;
43
+ version: z.ZodString;
44
+ versionId: z.ZodString;
45
+ setup: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
46
+ services: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
47
+ url: z.ZodString;
48
+ }, z.core.$strict>>;
49
+ createdBy: z.ZodObject<{
50
+ id: z.ZodNullable<z.ZodString>;
51
+ name: z.ZodNullable<z.ZodString>;
52
+ type: z.ZodString;
53
+ }, z.core.$strict>;
54
+ createdAt: z.ZodString;
55
+ startedAt: z.ZodNullable<z.ZodString>;
56
+ deletedAt: z.ZodNullable<z.ZodString>;
57
+ expiresAt: z.ZodNullable<z.ZodString>;
58
+ }, z.core.$strict>>;
59
+ nextCursor: z.ZodNullable<z.ZodString>;
60
+ }, z.core.$strict>;
61
+ export declare const environmentsListCommand: import("../../command.js").RegisteredCommand;
62
+ export declare const environmentsGetCommand: import("../../command.js").RegisteredCommand;
63
+ export declare const waitInputSchema: z.ZodObject<{
64
+ id: z.ZodString;
65
+ status: z.ZodDefault<z.ZodEnum<{
66
+ deleted: "deleted";
67
+ failed: "failed";
68
+ running: "running";
69
+ starting: "starting";
70
+ }>>;
71
+ timeout: z.ZodOptional<z.ZodString>;
72
+ }, z.core.$strict>;
73
+ export declare const environmentsWaitCommand: import("../../command.js").RegisteredCommand;
74
+ export declare const deleteInputSchema: z.ZodObject<{
75
+ id: z.ZodOptional<z.ZodString>;
76
+ label: z.ZodDefault<z.ZodArray<z.ZodString>>;
77
+ }, z.core.$strict>;
78
+ export declare const deleteResultSchema: z.ZodObject<{
79
+ data: z.ZodArray<z.ZodObject<{
80
+ id: z.ZodString;
81
+ workspaceId: z.ZodString;
82
+ name: z.ZodNullable<z.ZodString>;
83
+ labels: z.ZodRecord<z.ZodString, z.ZodString>;
84
+ status: z.ZodString;
85
+ reason: z.ZodNullable<z.ZodString>;
86
+ failure: z.ZodNullable<z.ZodObject<{
87
+ appName: z.ZodString;
88
+ code: z.ZodString;
89
+ message: z.ZodString;
90
+ }, z.core.$strict>>;
91
+ timeLimitMinutes: z.ZodNumber;
92
+ tokenInUrl: z.ZodBoolean;
93
+ snapshotId: z.ZodNullable<z.ZodString>;
94
+ apps: z.ZodArray<z.ZodObject<{
95
+ appId: z.ZodString;
96
+ name: z.ZodString;
97
+ version: z.ZodString;
98
+ versionId: z.ZodString;
99
+ setup: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
100
+ services: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
101
+ url: z.ZodString;
102
+ }, z.core.$strict>>;
103
+ createdBy: z.ZodObject<{
104
+ id: z.ZodNullable<z.ZodString>;
105
+ name: z.ZodNullable<z.ZodString>;
106
+ type: z.ZodString;
107
+ }, z.core.$strict>;
108
+ createdAt: z.ZodString;
109
+ startedAt: z.ZodNullable<z.ZodString>;
110
+ deletedAt: z.ZodNullable<z.ZodString>;
111
+ expiresAt: z.ZodNullable<z.ZodString>;
112
+ }, z.core.$strict>>;
113
+ }, z.core.$strict>;
114
+ export declare const deleteProgressSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
115
+ event: z.ZodLiteral<"matches">;
116
+ ids: z.ZodArray<z.ZodString>;
117
+ }, z.core.$strict>, z.ZodObject<{
118
+ event: z.ZodLiteral<"deleted">;
119
+ id: z.ZodString;
120
+ }, z.core.$strict>], "event">;
121
+ export declare const environmentsDeleteCommand: import("../../command.js").RegisteredCommand;
@@ -0,0 +1,170 @@
1
+ import { z } from 'zod';
2
+ import { defineCommand } from '../../command.js';
3
+ import { acceptedSchema, environmentResultSchema, environmentStatusSchema, idArgument, idempotencyKeySchema, idInputSchema, labelFlag, labelInputSchema, pageFlags, pageInput, waitFlag, } from '../../resources/schema.js';
4
+ export const createInputSchema = z
5
+ .strictObject({
6
+ app: z
7
+ .array(z.string().regex(/^[a-z][a-z0-9-]{1,39}$/))
8
+ .min(1)
9
+ .max(10)
10
+ .optional(),
11
+ snapshot: z.string().min(1).optional(),
12
+ name: z.string().trim().min(1).max(120).optional(),
13
+ label: labelInputSchema,
14
+ timeLimit: z
15
+ .string()
16
+ .regex(/^[1-9]\d*$/)
17
+ .refine((value) => Number(value) <= 1440)
18
+ .optional(),
19
+ idempotencyKey: idempotencyKeySchema,
20
+ wait: z.boolean().optional(),
21
+ })
22
+ .refine((input) => (input.app === undefined) !== (input.snapshot === undefined));
23
+ export const environmentsCreateCommand = defineCommand({
24
+ name: ['environments', 'create'],
25
+ summary: 'Create an environment.',
26
+ need: 'workspace',
27
+ destructive: false,
28
+ streams: true,
29
+ arguments: [],
30
+ flags: [
31
+ {
32
+ name: 'app',
33
+ key: 'app',
34
+ type: 'string[]',
35
+ description: 'Include an app. Repeat for more apps.',
36
+ },
37
+ {
38
+ name: 'snapshot',
39
+ key: 'snapshot',
40
+ type: 'string',
41
+ description: 'Restore a snapshot instead of choosing apps.',
42
+ },
43
+ {
44
+ name: 'name',
45
+ key: 'name',
46
+ type: 'string',
47
+ description: 'Name the environment.',
48
+ },
49
+ labelFlag,
50
+ {
51
+ name: 'time-limit',
52
+ key: 'timeLimit',
53
+ type: 'string',
54
+ description: 'Delete the environment after this many minutes.',
55
+ },
56
+ {
57
+ name: 'idempotency-key',
58
+ key: 'idempotencyKey',
59
+ type: 'string',
60
+ description: 'Reuse a key to retry the same create.',
61
+ },
62
+ waitFlag,
63
+ ],
64
+ input: createInputSchema,
65
+ result: environmentResultSchema,
66
+ progress: acceptedSchema,
67
+ load: () => import('./create.js'),
68
+ });
69
+ export const listInputSchema = z.strictObject({
70
+ ...pageInput,
71
+ status: z.array(environmentStatusSchema).max(5).optional(),
72
+ label: labelInputSchema,
73
+ });
74
+ export const listResultSchema = z.strictObject({
75
+ data: z.array(environmentResultSchema),
76
+ nextCursor: z.string().nullable(),
77
+ });
78
+ export const environmentsListCommand = defineCommand({
79
+ name: ['environments', 'list'],
80
+ summary: 'List environments in the workspace.',
81
+ need: 'workspace',
82
+ destructive: false,
83
+ streams: false,
84
+ arguments: [],
85
+ flags: [
86
+ ...pageFlags,
87
+ {
88
+ name: 'status',
89
+ key: 'status',
90
+ type: 'string[]',
91
+ description: 'Match a status. Repeat for more statuses.',
92
+ },
93
+ labelFlag,
94
+ ],
95
+ input: listInputSchema,
96
+ result: listResultSchema,
97
+ progress: z.never(),
98
+ load: () => import('./list.js'),
99
+ });
100
+ export const environmentsGetCommand = defineCommand({
101
+ name: ['environments', 'get'],
102
+ summary: 'Show an environment.',
103
+ need: 'workspace',
104
+ destructive: false,
105
+ streams: false,
106
+ arguments: [idArgument],
107
+ flags: [],
108
+ input: idInputSchema,
109
+ result: environmentResultSchema,
110
+ progress: z.never(),
111
+ load: () => import('./get.js'),
112
+ });
113
+ export const waitInputSchema = idInputSchema.extend({
114
+ status: environmentStatusSchema.default('running'),
115
+ timeout: z
116
+ .string()
117
+ .regex(/^[1-9]\d*$/)
118
+ .refine((value) => Number.isSafeInteger(Number(value) * 1000))
119
+ .optional(),
120
+ });
121
+ export const environmentsWaitCommand = defineCommand({
122
+ name: ['environments', 'wait'],
123
+ summary: 'Wait for an environment status.',
124
+ need: 'workspace',
125
+ destructive: false,
126
+ streams: false,
127
+ arguments: [idArgument],
128
+ flags: [
129
+ {
130
+ name: 'status',
131
+ key: 'status',
132
+ type: 'string',
133
+ description: 'Wait for this status. Defaults to running.',
134
+ },
135
+ {
136
+ name: 'timeout',
137
+ key: 'timeout',
138
+ type: 'string',
139
+ description: 'Stop waiting after this many seconds.',
140
+ },
141
+ ],
142
+ input: waitInputSchema,
143
+ result: environmentResultSchema,
144
+ progress: z.never(),
145
+ load: () => import('./wait.js'),
146
+ });
147
+ export const deleteInputSchema = z
148
+ .strictObject({ id: z.string().min(1).optional(), label: labelInputSchema })
149
+ .refine((input) => (input.id !== undefined) !== input.label.length > 0);
150
+ export const deleteResultSchema = z.strictObject({
151
+ data: z.array(environmentResultSchema),
152
+ });
153
+ export const deleteProgressSchema = z.discriminatedUnion('event', [
154
+ z.strictObject({ event: z.literal('matches'), ids: z.array(z.string()) }),
155
+ z.strictObject({ event: z.literal('deleted'), id: z.string() }),
156
+ ]);
157
+ export const environmentsDeleteCommand = defineCommand({
158
+ name: ['environments', 'delete'],
159
+ summary: 'Delete an environment or every environment with matching labels.',
160
+ need: 'workspace',
161
+ destructive: true,
162
+ confirmation: 'handler',
163
+ streams: false,
164
+ arguments: [{ ...idArgument, required: false }],
165
+ flags: [labelFlag],
166
+ input: deleteInputSchema,
167
+ result: deleteResultSchema,
168
+ progress: deleteProgressSchema,
169
+ load: () => import('./delete.js'),
170
+ });
@@ -0,0 +1,9 @@
1
+ import type { z } from 'zod';
2
+ import type { CommandEvent } from '../../command.js';
3
+ import type { WorkspaceContext } from '../../context-types.js';
4
+ import { resourceText } from '../../resources/read.js';
5
+ import type { acceptedSchema, environmentResultSchema } from '../../resources/schema.js';
6
+ import type { createInputSchema } from './command.js';
7
+ export declare function run(input: z.infer<typeof createInputSchema>, context: WorkspaceContext): AsyncIterable<CommandEvent<z.infer<typeof environmentResultSchema>, z.infer<typeof acceptedSchema>>>;
8
+ export declare const text: typeof resourceText;
9
+ export declare function progressText(progress: z.infer<typeof acceptedSchema>): string;
@@ -0,0 +1,42 @@
1
+ import { createKey, labels, resourceError } from '../../resources/create.js';
2
+ import { environmentResult, resourceText, snapshot, } from '../../resources/read.js';
3
+ export async function* run(input, context) {
4
+ const parsedLabels = labels(input.label);
5
+ if (input.snapshot !== undefined) {
6
+ await snapshot(context, input.snapshot);
7
+ }
8
+ const idempotencyKey = createKey(input.idempotencyKey, context);
9
+ let id;
10
+ try {
11
+ const created = await context.sdk.environments.create({
12
+ workspaceId: context.workspace.id,
13
+ ...(input.app === undefined ? {} : { apps: input.app }),
14
+ ...(input.snapshot === undefined ? {} : { snapshotId: input.snapshot }),
15
+ ...(input.name === undefined ? {} : { name: input.name }),
16
+ labels: parsedLabels,
17
+ ...(input.timeLimit === undefined
18
+ ? {}
19
+ : { timeLimitMinutes: Number(input.timeLimit) }),
20
+ }, { wait: false, idempotencyKey, signal: context.io.signal });
21
+ id = created.id;
22
+ yield { kind: 'progress', value: { event: 'accepted', id } };
23
+ const result = (input.wait ?? context.presentation.mode === 'interactive')
24
+ ? await context.sdk.environments.wait(id, {
25
+ status: 'running',
26
+ signal: context.io.signal,
27
+ })
28
+ : created;
29
+ yield { kind: 'result', value: environmentResult(result) };
30
+ }
31
+ catch (cause) {
32
+ throw await resourceError(cause, context, {
33
+ resource: 'environment',
34
+ idempotencyKey,
35
+ ...(id === undefined ? {} : { id }),
36
+ });
37
+ }
38
+ }
39
+ export const text = resourceText;
40
+ export function progressText(progress) {
41
+ return `Environment accepted: ${progress.id}`;
42
+ }
@@ -0,0 +1,7 @@
1
+ import type { z } from 'zod';
2
+ import type { CommandEvent } from '../../command.js';
3
+ import type { WorkspaceContext } from '../../context-types.js';
4
+ import type { deleteInputSchema, deleteProgressSchema, deleteResultSchema } from './command.js';
5
+ export declare function run(input: z.infer<typeof deleteInputSchema>, context: WorkspaceContext): AsyncIterable<CommandEvent<z.infer<typeof deleteResultSchema>, z.infer<typeof deleteProgressSchema>>>;
6
+ export declare function text(result: z.infer<typeof deleteResultSchema>): string;
7
+ export declare function progressText(progress: z.infer<typeof deleteProgressSchema>): string;
@@ -0,0 +1,48 @@
1
+ import { CliError } from '../../errors.js';
2
+ import { environment, environmentResult, pages } from '../../resources/read.js';
3
+ export async function* run(input, context) {
4
+ const matches = input.id === undefined
5
+ ? (await pages({ all: true }, (query) => context.sdk.environments.list({
6
+ ...query,
7
+ workspaceId: context.workspace.id,
8
+ label: input.label,
9
+ }))).data.filter((value) => value.status !== 'deleted')
10
+ : [await environment(context, input.id)];
11
+ for (const value of matches) {
12
+ context.workspace.assertMember(value.workspaceId);
13
+ }
14
+ yield {
15
+ kind: 'progress',
16
+ value: { event: 'matches', ids: matches.map((value) => value.id) },
17
+ };
18
+ if (matches.length > 0 && !context.globals.yes) {
19
+ if (context.presentation.mode !== 'interactive') {
20
+ throw new CliError('cli.input_required', {
21
+ message: 'Use --yes to confirm deletion.',
22
+ });
23
+ }
24
+ if (!(await context.io.prompt.confirm(`Delete ${matches.length} environment${matches.length === 1 ? '' : 's'}?`, { signal: context.io.signal, deadline: null }))) {
25
+ throw new CliError('cli.cancelled');
26
+ }
27
+ }
28
+ const data = [];
29
+ for (const value of matches) {
30
+ data.push(environmentResult(await context.sdk.environments.delete(value.id, {
31
+ signal: context.io.signal,
32
+ })));
33
+ yield { kind: 'progress', value: { event: 'deleted', id: value.id } };
34
+ }
35
+ yield { kind: 'result', value: { data } };
36
+ }
37
+ export function text(result) {
38
+ return result.data.length === 0
39
+ ? 'No matching environments.\n'
40
+ : `${result.data.map((value) => `Deleted ${value.id}`).join('\n')}\n`;
41
+ }
42
+ export function progressText(progress) {
43
+ return progress.event === 'matches'
44
+ ? progress.ids.length === 0
45
+ ? 'No matching environments.'
46
+ : `Environments to delete:\n${progress.ids.join('\n')}`
47
+ : `Deleted ${progress.id}`;
48
+ }
@@ -0,0 +1,39 @@
1
+ import type { z } from 'zod';
2
+ import type { WorkspaceContext } from '../../context-types.js';
3
+ import { resourceText } from '../../resources/read.js';
4
+ import type { idInputSchema } from '../../resources/schema.js';
5
+ export declare function run(input: z.infer<typeof idInputSchema>, context: WorkspaceContext): Promise<{
6
+ id: string;
7
+ workspaceId: string;
8
+ name: string | null;
9
+ labels: Record<string, string>;
10
+ status: string;
11
+ reason: string | null;
12
+ failure: {
13
+ appName: string;
14
+ code: string;
15
+ message: string;
16
+ } | null;
17
+ timeLimitMinutes: number;
18
+ tokenInUrl: boolean;
19
+ snapshotId: string | null;
20
+ apps: {
21
+ appId: string;
22
+ name: string;
23
+ version: string;
24
+ versionId: string;
25
+ setup: Record<string, z.JSONType>;
26
+ services: Record<string, z.JSONType>;
27
+ url: string;
28
+ }[];
29
+ createdBy: {
30
+ id: string | null;
31
+ name: string | null;
32
+ type: string;
33
+ };
34
+ createdAt: string;
35
+ startedAt: string | null;
36
+ deletedAt: string | null;
37
+ expiresAt: string | null;
38
+ }>;
39
+ export declare const text: typeof resourceText;
@@ -0,0 +1,5 @@
1
+ import { environment, environmentResult, resourceText, } from '../../resources/read.js';
2
+ export async function run(input, context) {
3
+ return environmentResult(await environment(context, input.id));
4
+ }
5
+ export const text = resourceText;
@@ -0,0 +1,41 @@
1
+ import type { z } from 'zod';
2
+ import type { WorkspaceContext } from '../../context-types.js';
3
+ import type { listInputSchema, listResultSchema } from './command.js';
4
+ export declare function run(input: z.infer<typeof listInputSchema>, context: WorkspaceContext): Promise<{
5
+ data: {
6
+ id: string;
7
+ workspaceId: string;
8
+ name: string | null;
9
+ labels: Record<string, string>;
10
+ status: string;
11
+ reason: string | null;
12
+ failure: {
13
+ appName: string;
14
+ code: string;
15
+ message: string;
16
+ } | null;
17
+ timeLimitMinutes: number;
18
+ tokenInUrl: boolean;
19
+ snapshotId: string | null;
20
+ apps: {
21
+ appId: string;
22
+ name: string;
23
+ version: string;
24
+ versionId: string;
25
+ setup: Record<string, z.JSONType>;
26
+ services: Record<string, z.JSONType>;
27
+ url: string;
28
+ }[];
29
+ createdBy: {
30
+ id: string | null;
31
+ name: string | null;
32
+ type: string;
33
+ };
34
+ createdAt: string;
35
+ startedAt: string | null;
36
+ deletedAt: string | null;
37
+ expiresAt: string | null;
38
+ }[];
39
+ nextCursor: string | null;
40
+ }>;
41
+ export declare function text(result: z.infer<typeof listResultSchema>): string;
@@ -0,0 +1,18 @@
1
+ import { environmentResult, pages, resourceText, } from '../../resources/read.js';
2
+ export async function run(input, context) {
3
+ const page = await pages(input, (query) => context.sdk.environments.list({
4
+ ...query,
5
+ workspaceId: context.workspace.id,
6
+ ...(input.status === undefined ? {} : { status: input.status }),
7
+ ...(input.label.length === 0 ? {} : { label: input.label }),
8
+ }));
9
+ return {
10
+ data: page.data.map(environmentResult),
11
+ nextCursor: page.nextCursor,
12
+ };
13
+ }
14
+ export function text(result) {
15
+ return result.data.length === 0
16
+ ? 'No environments.\n'
17
+ : result.data.map(resourceText).join('');
18
+ }