@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.
- package/LICENSE +21 -0
- package/README.md +34 -2
- package/dist/agents/bundled.d.ts +5 -0
- package/dist/agents/bundled.js +6 -0
- package/dist/agents/destinations.d.ts +13 -0
- package/dist/agents/destinations.js +16 -0
- package/dist/api-internal.d.ts +62 -0
- package/dist/api-internal.js +348 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +4 -0
- package/dist/command.d.ts +119 -0
- package/dist/command.js +195 -0
- package/dist/commands/api/command.d.ts +15 -0
- package/dist/commands/api/command.js +38 -0
- package/dist/commands/api/run.d.ts +4 -0
- package/dist/commands/api/run.js +24 -0
- package/dist/commands/apps/command.d.ts +19 -0
- package/dist/commands/apps/command.js +29 -0
- package/dist/commands/apps/list.d.ts +8 -0
- package/dist/commands/apps/list.js +10 -0
- package/dist/commands/connect/command.d.ts +34 -0
- package/dist/commands/connect/command.js +70 -0
- package/dist/commands/connect/run.d.ts +10 -0
- package/dist/commands/connect/run.js +71 -0
- package/dist/commands/doctor/command.d.ts +29 -0
- package/dist/commands/doctor/command.js +36 -0
- package/dist/commands/doctor/run.d.ts +13 -0
- package/dist/commands/doctor/run.js +12 -0
- package/dist/commands/env/command.d.ts +5 -0
- package/dist/commands/env/command.js +19 -0
- package/dist/commands/env/pull.d.ts +6 -0
- package/dist/commands/env/pull.js +6 -0
- package/dist/commands/environments/command.d.ts +121 -0
- package/dist/commands/environments/command.js +170 -0
- package/dist/commands/environments/create.d.ts +9 -0
- package/dist/commands/environments/create.js +42 -0
- package/dist/commands/environments/delete.d.ts +7 -0
- package/dist/commands/environments/delete.js +48 -0
- package/dist/commands/environments/get.d.ts +39 -0
- package/dist/commands/environments/get.js +5 -0
- package/dist/commands/environments/list.d.ts +41 -0
- package/dist/commands/environments/list.js +18 -0
- package/dist/commands/environments/wait.d.ts +39 -0
- package/dist/commands/environments/wait.js +21 -0
- package/dist/commands/init/command.d.ts +68 -0
- package/dist/commands/init/command.js +90 -0
- package/dist/commands/init/run.d.ts +8 -0
- package/dist/commands/init/run.js +422 -0
- package/dist/commands/link/command.d.ts +13 -0
- package/dist/commands/link/command.js +32 -0
- package/dist/commands/link/run.d.ts +12 -0
- package/dist/commands/link/run.js +7 -0
- package/dist/commands/login/command.d.ts +1 -0
- package/dist/commands/login/command.js +43 -0
- package/dist/commands/login/run.d.ts +30 -0
- package/dist/commands/login/run.js +43 -0
- package/dist/commands/login/schema.d.ts +33 -0
- package/dist/commands/login/schema.js +33 -0
- package/dist/commands/logout/command.d.ts +1 -0
- package/dist/commands/logout/command.js +24 -0
- package/dist/commands/logout/run.d.ts +10 -0
- package/dist/commands/logout/run.js +19 -0
- package/dist/commands/logout/schema.d.ts +10 -0
- package/dist/commands/logout/schema.js +10 -0
- package/dist/commands/profiles/command.d.ts +2 -0
- package/dist/commands/profiles/command.js +29 -0
- package/dist/commands/profiles/list.d.ts +20 -0
- package/dist/commands/profiles/list.js +10 -0
- package/dist/commands/profiles/schema.d.ts +24 -0
- package/dist/commands/profiles/schema.js +19 -0
- package/dist/commands/profiles/use.d.ts +7 -0
- package/dist/commands/profiles/use.js +7 -0
- package/dist/commands/requests/command.d.ts +39 -0
- package/dist/commands/requests/command.js +65 -0
- package/dist/commands/requests/get.d.ts +32 -0
- package/dist/commands/requests/get.js +15 -0
- package/dist/commands/requests/list.d.ts +27 -0
- package/dist/commands/requests/list.js +25 -0
- package/dist/commands/snapshots/command.d.ts +48 -0
- package/dist/commands/snapshots/command.js +80 -0
- package/dist/commands/snapshots/create.d.ts +7 -0
- package/dist/commands/snapshots/create.js +26 -0
- package/dist/commands/snapshots/delete.d.ts +34 -0
- package/dist/commands/snapshots/delete.js +8 -0
- package/dist/commands/snapshots/get.d.ts +35 -0
- package/dist/commands/snapshots/get.js +5 -0
- package/dist/commands/snapshots/list.d.ts +37 -0
- package/dist/commands/snapshots/list.js +10 -0
- package/dist/commands/unlink/command.d.ts +1 -0
- package/dist/commands/unlink/command.js +15 -0
- package/dist/commands/unlink/run.d.ts +7 -0
- package/dist/commands/unlink/run.js +8 -0
- package/dist/commands/whoami/command.d.ts +28 -0
- package/dist/commands/whoami/command.js +44 -0
- package/dist/commands/whoami/run.d.ts +5 -0
- package/dist/commands/whoami/run.js +39 -0
- package/dist/commands/workspaces/command.d.ts +33 -0
- package/dist/commands/workspaces/command.js +73 -0
- package/dist/commands/workspaces/list.d.ts +5 -0
- package/dist/commands/workspaces/list.js +42 -0
- package/dist/commands/workspaces/use.d.ts +5 -0
- package/dist/commands/workspaces/use.js +18 -0
- package/dist/config/project.d.ts +21 -0
- package/dist/config/project.js +105 -0
- package/dist/config/schema.d.ts +616 -0
- package/dist/config/schema.js +282 -0
- package/dist/context-types.d.ts +89 -0
- package/dist/context-types.js +56 -0
- package/dist/context.d.ts +13 -0
- package/dist/context.js +290 -0
- package/dist/credentials/sealing.d.ts +10 -0
- package/dist/credentials/sealing.js +72 -0
- package/dist/credentials/store.d.ts +17 -0
- package/dist/credentials/store.js +156 -0
- package/dist/doctor.d.ts +4 -0
- package/dist/doctor.js +239 -0
- package/dist/env-file.d.ts +10 -0
- package/dist/env-file.js +254 -0
- package/dist/errors.d.ts +784 -0
- package/dist/errors.js +459 -0
- package/dist/flags.d.ts +22 -0
- package/dist/flags.js +56 -0
- package/dist/generated/internal.d.ts +138 -0
- package/dist/generated/internal.js +2627 -0
- package/dist/generated/retry.d.ts +1 -0
- package/dist/generated/retry.js +11 -0
- package/dist/help.d.ts +408 -0
- package/dist/help.js +220 -0
- package/dist/io-types.d.ts +127 -0
- package/dist/io-types.js +1 -0
- package/dist/io.d.ts +13 -0
- package/dist/io.js +1017 -0
- package/dist/keys.d.ts +50 -0
- package/dist/keys.js +691 -0
- package/dist/link.d.ts +6 -0
- package/dist/link.js +58 -0
- package/dist/login.d.ts +92 -0
- package/dist/login.js +965 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +126 -0
- package/dist/native-helper.d.ts +1 -0
- package/dist/native-helper.js +2 -0
- package/dist/output.d.ts +8 -0
- package/dist/output.js +135 -0
- package/dist/parser.d.ts +28 -0
- package/dist/parser.js +250 -0
- package/dist/program-types.d.ts +67 -0
- package/dist/program-types.js +14 -0
- package/dist/programs.d.ts +2 -0
- package/dist/programs.js +44 -0
- package/dist/project-roots.d.ts +3 -0
- package/dist/project-roots.js +26 -0
- package/dist/prompt.d.ts +3 -0
- package/dist/prompt.js +61 -0
- package/dist/registry.d.ts +2 -0
- package/dist/registry.js +44 -0
- package/dist/resources/create.d.ts +9 -0
- package/dist/resources/create.js +55 -0
- package/dist/resources/read.d.ts +15 -0
- package/dist/resources/read.js +69 -0
- package/dist/resources/schema.d.ts +177 -0
- package/dist/resources/schema.js +158 -0
- package/dist/text.d.ts +3 -0
- package/dist/text.js +19 -0
- package/dist/update.d.ts +22 -0
- package/dist/update.js +126 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +52 -3
package/dist/programs.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { productionOrigin } from './context-types.js';
|
|
2
|
+
import { CliError } from './errors.js';
|
|
3
|
+
export function createPrograms(options) {
|
|
4
|
+
const { io, credential } = options;
|
|
5
|
+
const effects = (supplied) => supplied ?? { signal: io.signal, deadline: null };
|
|
6
|
+
return {
|
|
7
|
+
async run(input, supplied) {
|
|
8
|
+
const effect = effects(supplied);
|
|
9
|
+
const consume = async (key) => {
|
|
10
|
+
const environment = Object.fromEntries(Object.entries(io.host.environment).filter((entry) => entry[1] !== undefined));
|
|
11
|
+
environment.STATEMACHINES_API_KEY = key;
|
|
12
|
+
if (options.origin === productionOrigin) {
|
|
13
|
+
delete environment.STATEMACHINES_BASE_URL;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
environment.STATEMACHINES_BASE_URL = options.origin;
|
|
17
|
+
}
|
|
18
|
+
return io.child.run({
|
|
19
|
+
...input,
|
|
20
|
+
environment,
|
|
21
|
+
cwd: io.host.cwd,
|
|
22
|
+
stdin: 'inherit',
|
|
23
|
+
output: 'inherit',
|
|
24
|
+
options: effect,
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
return credential.kind === 'workspace-key'
|
|
28
|
+
? consume(credential.key)
|
|
29
|
+
: credential.keys.withRunKey({
|
|
30
|
+
account: credential.account,
|
|
31
|
+
workspace: options.workspace,
|
|
32
|
+
consume,
|
|
33
|
+
}, effect);
|
|
34
|
+
},
|
|
35
|
+
async pullEnvironment(file, supplied) {
|
|
36
|
+
if (credential.kind === 'workspace-key') {
|
|
37
|
+
throw new CliError('cli.env_requires_login');
|
|
38
|
+
}
|
|
39
|
+
const effect = effects(supplied);
|
|
40
|
+
const target = await options.files.prepare(file, effect);
|
|
41
|
+
return credential.keys.pullEnvironment({ account: credential.account, workspace: options.workspace, target }, effect);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { EffectOptions, Io } from './io-types.js';
|
|
2
|
+
export declare function findPackageRoot(io: Io, from: string, stopAt: string | null, options: EffectOptions): Promise<string | null>;
|
|
3
|
+
export declare function findProjectRoot(io: Io, options: EffectOptions): Promise<string | null>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
2
|
+
export async function findPackageRoot(io, from, stopAt, options) {
|
|
3
|
+
let directory = resolve(from);
|
|
4
|
+
for (;;) {
|
|
5
|
+
if ((await io.files.inspect(join(directory, 'package.json'), options))
|
|
6
|
+
.kind !== 'missing') {
|
|
7
|
+
return directory;
|
|
8
|
+
}
|
|
9
|
+
const parent = dirname(directory);
|
|
10
|
+
if (directory === stopAt || parent === directory) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
directory = parent;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export async function findProjectRoot(io, options) {
|
|
17
|
+
const home = resolve(io.host.home);
|
|
18
|
+
const belowHome = (root) => {
|
|
19
|
+
const up = root === null ? '' : relative(root, home);
|
|
20
|
+
return up === '..' || up.startsWith(`..${sep}`) || isAbsolute(up)
|
|
21
|
+
? root
|
|
22
|
+
: null;
|
|
23
|
+
};
|
|
24
|
+
return (belowHome(await io.files.findRepositoryRoot(io.host.cwd, options)) ??
|
|
25
|
+
belowHome(await findPackageRoot(io, io.host.cwd, home, options)));
|
|
26
|
+
}
|
package/dist/prompt.d.ts
ADDED
package/dist/prompt.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { confirm, isCancel, multiselect, select } from '@clack/prompts';
|
|
2
|
+
import { CliError } from './errors.js';
|
|
3
|
+
import { untrustedText } from './text.js';
|
|
4
|
+
export function createPrompter(input, output) {
|
|
5
|
+
return {
|
|
6
|
+
async confirm(question, options) {
|
|
7
|
+
const result = await confirm({
|
|
8
|
+
message: untrustedText(question),
|
|
9
|
+
input,
|
|
10
|
+
output,
|
|
11
|
+
signal: options.signal,
|
|
12
|
+
});
|
|
13
|
+
if (isCancel(result)) {
|
|
14
|
+
throw new CliError('cli.cancelled');
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
},
|
|
18
|
+
async multiselect(question, choices, initialValues, options) {
|
|
19
|
+
const result = await multiselect({
|
|
20
|
+
message: untrustedText(question),
|
|
21
|
+
options: choices.map((choice) => ({
|
|
22
|
+
value: choice.value,
|
|
23
|
+
label: untrustedText(choice.label),
|
|
24
|
+
})),
|
|
25
|
+
initialValues: [...initialValues],
|
|
26
|
+
required: false,
|
|
27
|
+
input,
|
|
28
|
+
output,
|
|
29
|
+
signal: options.signal,
|
|
30
|
+
});
|
|
31
|
+
if (isCancel(result)) {
|
|
32
|
+
throw new CliError('cli.cancelled');
|
|
33
|
+
}
|
|
34
|
+
const selected = choices.filter((choice) => result.includes(choice.value));
|
|
35
|
+
if (selected.length !== result.length) {
|
|
36
|
+
throw new CliError('cli.internal');
|
|
37
|
+
}
|
|
38
|
+
return selected.map((choice) => choice.value);
|
|
39
|
+
},
|
|
40
|
+
async select(question, choices, options) {
|
|
41
|
+
const result = await select({
|
|
42
|
+
message: untrustedText(question),
|
|
43
|
+
options: choices.map((choice) => ({
|
|
44
|
+
value: choice.value,
|
|
45
|
+
label: untrustedText(choice.label),
|
|
46
|
+
})),
|
|
47
|
+
input,
|
|
48
|
+
output,
|
|
49
|
+
signal: options.signal,
|
|
50
|
+
});
|
|
51
|
+
if (isCancel(result)) {
|
|
52
|
+
throw new CliError('cli.cancelled');
|
|
53
|
+
}
|
|
54
|
+
const choice = choices.find((choice) => choice.value === result);
|
|
55
|
+
if (!choice) {
|
|
56
|
+
throw new CliError('cli.internal');
|
|
57
|
+
}
|
|
58
|
+
return choice.value;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { apiCommand } from './commands/api/command.js';
|
|
2
|
+
import { appsListCommand } from './commands/apps/command.js';
|
|
3
|
+
import { connectCommand } from './commands/connect/command.js';
|
|
4
|
+
import { doctorCommand } from './commands/doctor/command.js';
|
|
5
|
+
import { envPullCommand } from './commands/env/command.js';
|
|
6
|
+
import { environmentsCreateCommand, environmentsDeleteCommand, environmentsGetCommand, environmentsListCommand, environmentsWaitCommand, } from './commands/environments/command.js';
|
|
7
|
+
import { initCommand } from './commands/init/command.js';
|
|
8
|
+
import { linkCommand } from './commands/link/command.js';
|
|
9
|
+
import { loginCommand } from './commands/login/command.js';
|
|
10
|
+
import { logoutCommand } from './commands/logout/command.js';
|
|
11
|
+
import { profilesListCommand, profilesUseCommand, } from './commands/profiles/command.js';
|
|
12
|
+
import { requestsGetCommand, requestsListCommand, } from './commands/requests/command.js';
|
|
13
|
+
import { snapshotsCreateCommand, snapshotsDeleteCommand, snapshotsGetCommand, snapshotsListCommand, } from './commands/snapshots/command.js';
|
|
14
|
+
import { unlinkCommand } from './commands/unlink/command.js';
|
|
15
|
+
import { whoamiCommand } from './commands/whoami/command.js';
|
|
16
|
+
import { workspacesListCommand, workspacesUseCommand, } from './commands/workspaces/command.js';
|
|
17
|
+
export const commands = [
|
|
18
|
+
appsListCommand,
|
|
19
|
+
environmentsCreateCommand,
|
|
20
|
+
environmentsListCommand,
|
|
21
|
+
environmentsGetCommand,
|
|
22
|
+
environmentsWaitCommand,
|
|
23
|
+
environmentsDeleteCommand,
|
|
24
|
+
connectCommand,
|
|
25
|
+
snapshotsCreateCommand,
|
|
26
|
+
snapshotsListCommand,
|
|
27
|
+
snapshotsGetCommand,
|
|
28
|
+
snapshotsDeleteCommand,
|
|
29
|
+
requestsListCommand,
|
|
30
|
+
requestsGetCommand,
|
|
31
|
+
envPullCommand,
|
|
32
|
+
loginCommand,
|
|
33
|
+
logoutCommand,
|
|
34
|
+
whoamiCommand,
|
|
35
|
+
profilesListCommand,
|
|
36
|
+
profilesUseCommand,
|
|
37
|
+
workspacesListCommand,
|
|
38
|
+
workspacesUseCommand,
|
|
39
|
+
linkCommand,
|
|
40
|
+
initCommand,
|
|
41
|
+
unlinkCommand,
|
|
42
|
+
doctorCommand,
|
|
43
|
+
apiCommand,
|
|
44
|
+
];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WorkspaceContext } from '../context-types.js';
|
|
2
|
+
import { ApiError, CliError } from '../errors.js';
|
|
3
|
+
export declare function labels(values: readonly string[]): Record<string, string>;
|
|
4
|
+
export declare function createKey(provided: string | undefined, context: WorkspaceContext): string;
|
|
5
|
+
export declare function resourceError(cause: unknown, context: WorkspaceContext, details: {
|
|
6
|
+
resource: 'environment' | 'snapshot';
|
|
7
|
+
id?: string;
|
|
8
|
+
idempotencyKey?: string;
|
|
9
|
+
}): Promise<ApiError | CliError>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ApiError, CliError, withErrorDetails } from '../errors.js';
|
|
2
|
+
import { parseEnvironmentLabels } from '../generated/internal.js';
|
|
3
|
+
import { commandError } from '../output.js';
|
|
4
|
+
export function labels(values) {
|
|
5
|
+
try {
|
|
6
|
+
return parseEnvironmentLabels(Object.fromEntries(values.map((value) => {
|
|
7
|
+
const separator = value.indexOf('=');
|
|
8
|
+
return [value.slice(0, separator), value.slice(separator + 1)];
|
|
9
|
+
})));
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
throw new CliError('cli.invalid_arguments', {
|
|
13
|
+
message: 'Use valid, non-reserved key=value labels.',
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function createKey(provided, context) {
|
|
18
|
+
return (provided ?? `cli_${Buffer.from(context.io.randomBytes(32)).toString('hex')}`);
|
|
19
|
+
}
|
|
20
|
+
function commandArgument(value) {
|
|
21
|
+
return /^[A-Za-z0-9_-]+$/.test(value)
|
|
22
|
+
? value
|
|
23
|
+
: `'${value.replaceAll("'", "'\\''")}'`;
|
|
24
|
+
}
|
|
25
|
+
export async function resourceError(cause, context, details) {
|
|
26
|
+
const metadata = {
|
|
27
|
+
resource: details.resource,
|
|
28
|
+
id: details.id ?? null,
|
|
29
|
+
idempotencyKey: details.idempotencyKey ?? null,
|
|
30
|
+
};
|
|
31
|
+
if (context.io.signal.aborted && details.id !== undefined) {
|
|
32
|
+
const id = commandArgument(details.id);
|
|
33
|
+
const workspace = commandArgument(context.workspace.id);
|
|
34
|
+
return new CliError('cli.cancelled', {
|
|
35
|
+
message: `Stopped waiting for ${details.resource} ${details.id}.`,
|
|
36
|
+
details: metadata,
|
|
37
|
+
next: [
|
|
38
|
+
{
|
|
39
|
+
command: `statemachines ${details.resource}s delete ${id} --workspace ${workspace} --yes`,
|
|
40
|
+
reason: `Delete the ${details.resource} when it is no longer needed.`,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const error = await commandError(cause, context.io.signal);
|
|
46
|
+
const previous = error.document.error.details;
|
|
47
|
+
const retained = error instanceof ApiError
|
|
48
|
+
? { fields: previous }
|
|
49
|
+
: previous !== null &&
|
|
50
|
+
typeof previous === 'object' &&
|
|
51
|
+
!Array.isArray(previous)
|
|
52
|
+
? previous
|
|
53
|
+
: {};
|
|
54
|
+
return withErrorDetails(error, { ...retained, ...metadata });
|
|
55
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Environment, Page, PageQuery, Request, Snapshot } from '@usestatemachines/sdk';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { WorkspaceContext } from '../context-types.js';
|
|
4
|
+
import type { environmentResultSchema, pageInput, requestResultSchema, snapshotResultSchema } from './schema.js';
|
|
5
|
+
export declare function environment(context: WorkspaceContext, id: string): Promise<Environment>;
|
|
6
|
+
export declare function snapshot(context: WorkspaceContext, id: string): Promise<Snapshot>;
|
|
7
|
+
export declare function pages<T>(input: z.infer<z.ZodObject<typeof pageInput>>, read: (query: PageQuery) => Promise<Page<T>>): Promise<Page<T>>;
|
|
8
|
+
export declare function environmentResult(value: Environment): z.infer<typeof environmentResultSchema>;
|
|
9
|
+
export declare function snapshotResult(value: Snapshot): z.infer<typeof snapshotResultSchema>;
|
|
10
|
+
export declare function requestResult(value: Request): z.infer<typeof requestResultSchema>;
|
|
11
|
+
export declare function resourceText(value: {
|
|
12
|
+
id: string;
|
|
13
|
+
status: string;
|
|
14
|
+
name: string | null;
|
|
15
|
+
}): string;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { CliError } from '../errors.js';
|
|
2
|
+
export async function environment(context, id) {
|
|
3
|
+
const resource = await context.sdk.environments.get(id);
|
|
4
|
+
context.workspace.assertMember(resource.workspaceId);
|
|
5
|
+
return resource;
|
|
6
|
+
}
|
|
7
|
+
export async function snapshot(context, id) {
|
|
8
|
+
const resource = await context.sdk.snapshots.get(id);
|
|
9
|
+
context.workspace.assertMember(resource.workspaceId);
|
|
10
|
+
return resource;
|
|
11
|
+
}
|
|
12
|
+
export async function pages(input, read) {
|
|
13
|
+
const data = [];
|
|
14
|
+
let cursor = input.cursor;
|
|
15
|
+
const seen = new Set(cursor === undefined ? [] : [cursor]);
|
|
16
|
+
for (;;) {
|
|
17
|
+
const page = await read({
|
|
18
|
+
...(input.limit === undefined ? {} : { limit: Number(input.limit) }),
|
|
19
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
20
|
+
});
|
|
21
|
+
data.push(...page.data);
|
|
22
|
+
if (!input.all || page.nextCursor === null) {
|
|
23
|
+
return { data, nextCursor: page.nextCursor };
|
|
24
|
+
}
|
|
25
|
+
if (seen.has(page.nextCursor)) {
|
|
26
|
+
throw new CliError('cli.invalid_response');
|
|
27
|
+
}
|
|
28
|
+
seen.add(page.nextCursor);
|
|
29
|
+
cursor = page.nextCursor;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function environmentResult(value) {
|
|
33
|
+
return {
|
|
34
|
+
id: value.id,
|
|
35
|
+
workspaceId: value.workspaceId,
|
|
36
|
+
name: value.name,
|
|
37
|
+
labels: value.labels,
|
|
38
|
+
status: value.status,
|
|
39
|
+
reason: value.reason,
|
|
40
|
+
failure: value.failure,
|
|
41
|
+
timeLimitMinutes: value.timeLimitMinutes,
|
|
42
|
+
tokenInUrl: value.tokenInUrl,
|
|
43
|
+
snapshotId: value.snapshotId,
|
|
44
|
+
apps: value.apps,
|
|
45
|
+
createdBy: value.createdBy,
|
|
46
|
+
createdAt: value.createdAt.toISOString(),
|
|
47
|
+
startedAt: value.startedAt?.toISOString() ?? null,
|
|
48
|
+
deletedAt: value.deletedAt?.toISOString() ?? null,
|
|
49
|
+
expiresAt: value.expiresAt?.toISOString() ?? null,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export function snapshotResult(value) {
|
|
53
|
+
return {
|
|
54
|
+
...value,
|
|
55
|
+
createdAt: value.createdAt.toISOString(),
|
|
56
|
+
readyAt: value.readyAt?.toISOString() ?? null,
|
|
57
|
+
deletedAt: value.deletedAt?.toISOString() ?? null,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export function requestResult(value) {
|
|
61
|
+
return {
|
|
62
|
+
...value,
|
|
63
|
+
receivedAt: value.receivedAt.toISOString(),
|
|
64
|
+
completedAt: value.completedAt.toISOString(),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function resourceText(value) {
|
|
68
|
+
return `${value.id}\t${value.status}${value.name === null ? '' : `\t${value.name}`}\n`;
|
|
69
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const pageInput: {
|
|
3
|
+
limit: z.ZodOptional<z.ZodString>;
|
|
4
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
5
|
+
all: z.ZodDefault<z.ZodBoolean>;
|
|
6
|
+
};
|
|
7
|
+
export declare const pageFlags: ({
|
|
8
|
+
negatedName?: undefined;
|
|
9
|
+
name: string;
|
|
10
|
+
key: string;
|
|
11
|
+
type: "string";
|
|
12
|
+
description: string;
|
|
13
|
+
} | {
|
|
14
|
+
name: string;
|
|
15
|
+
key: string;
|
|
16
|
+
type: "boolean";
|
|
17
|
+
negatedName: null;
|
|
18
|
+
description: string;
|
|
19
|
+
})[];
|
|
20
|
+
export declare const idArgument: {
|
|
21
|
+
name: string;
|
|
22
|
+
key: string;
|
|
23
|
+
required: boolean;
|
|
24
|
+
many: boolean;
|
|
25
|
+
};
|
|
26
|
+
export declare const idInputSchema: z.ZodObject<{
|
|
27
|
+
id: z.ZodString;
|
|
28
|
+
}, z.core.$strict>;
|
|
29
|
+
export declare const idempotencyKeySchema: z.ZodOptional<z.ZodString>;
|
|
30
|
+
export declare const labelInputSchema: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
31
|
+
export declare const labelFlag: {
|
|
32
|
+
name: string;
|
|
33
|
+
key: string;
|
|
34
|
+
type: "string[]";
|
|
35
|
+
description: string;
|
|
36
|
+
};
|
|
37
|
+
export declare const environmentStatusSchema: z.ZodEnum<{
|
|
38
|
+
deleted: "deleted";
|
|
39
|
+
failed: "failed";
|
|
40
|
+
running: "running";
|
|
41
|
+
starting: "starting";
|
|
42
|
+
}>;
|
|
43
|
+
export declare const waitFlag: {
|
|
44
|
+
name: string;
|
|
45
|
+
key: string;
|
|
46
|
+
type: "boolean";
|
|
47
|
+
negatedName: string;
|
|
48
|
+
description: string;
|
|
49
|
+
};
|
|
50
|
+
export declare const acceptedSchema: z.ZodObject<{
|
|
51
|
+
event: z.ZodLiteral<"accepted">;
|
|
52
|
+
id: z.ZodString;
|
|
53
|
+
}, z.core.$strict>;
|
|
54
|
+
export declare const environmentResultSchema: z.ZodObject<{
|
|
55
|
+
id: z.ZodString;
|
|
56
|
+
workspaceId: z.ZodString;
|
|
57
|
+
name: z.ZodNullable<z.ZodString>;
|
|
58
|
+
labels: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
59
|
+
status: z.ZodString;
|
|
60
|
+
reason: z.ZodNullable<z.ZodString>;
|
|
61
|
+
failure: z.ZodNullable<z.ZodObject<{
|
|
62
|
+
appName: z.ZodString;
|
|
63
|
+
code: z.ZodString;
|
|
64
|
+
message: z.ZodString;
|
|
65
|
+
}, z.core.$strict>>;
|
|
66
|
+
timeLimitMinutes: z.ZodNumber;
|
|
67
|
+
tokenInUrl: z.ZodBoolean;
|
|
68
|
+
snapshotId: z.ZodNullable<z.ZodString>;
|
|
69
|
+
apps: z.ZodArray<z.ZodObject<{
|
|
70
|
+
appId: z.ZodString;
|
|
71
|
+
name: z.ZodString;
|
|
72
|
+
version: z.ZodString;
|
|
73
|
+
versionId: z.ZodString;
|
|
74
|
+
setup: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
75
|
+
services: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
76
|
+
url: z.ZodString;
|
|
77
|
+
}, z.core.$strict>>;
|
|
78
|
+
createdBy: z.ZodObject<{
|
|
79
|
+
id: z.ZodNullable<z.ZodString>;
|
|
80
|
+
name: z.ZodNullable<z.ZodString>;
|
|
81
|
+
type: z.ZodString;
|
|
82
|
+
}, z.core.$strict>;
|
|
83
|
+
createdAt: z.ZodString;
|
|
84
|
+
startedAt: z.ZodNullable<z.ZodString>;
|
|
85
|
+
deletedAt: z.ZodNullable<z.ZodString>;
|
|
86
|
+
expiresAt: z.ZodNullable<z.ZodString>;
|
|
87
|
+
}, z.core.$strict>;
|
|
88
|
+
export declare const snapshotResultSchema: z.ZodObject<{
|
|
89
|
+
id: z.ZodString;
|
|
90
|
+
workspaceId: z.ZodString;
|
|
91
|
+
environmentId: z.ZodString;
|
|
92
|
+
environmentName: z.ZodNullable<z.ZodString>;
|
|
93
|
+
name: z.ZodNullable<z.ZodString>;
|
|
94
|
+
status: z.ZodString;
|
|
95
|
+
failure: z.ZodNullable<z.ZodObject<{
|
|
96
|
+
code: z.ZodString;
|
|
97
|
+
message: z.ZodString;
|
|
98
|
+
}, z.core.$strict>>;
|
|
99
|
+
sizeBytes: z.ZodNullable<z.ZodNumber>;
|
|
100
|
+
apps: z.ZodArray<z.ZodObject<{
|
|
101
|
+
appId: z.ZodString;
|
|
102
|
+
name: z.ZodString;
|
|
103
|
+
version: z.ZodString;
|
|
104
|
+
versionId: z.ZodString;
|
|
105
|
+
setup: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
106
|
+
services: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
107
|
+
sizeBytes: z.ZodNullable<z.ZodNumber>;
|
|
108
|
+
}, z.core.$strict>>;
|
|
109
|
+
createdBy: z.ZodObject<{
|
|
110
|
+
id: z.ZodNullable<z.ZodString>;
|
|
111
|
+
name: z.ZodNullable<z.ZodString>;
|
|
112
|
+
type: z.ZodString;
|
|
113
|
+
}, z.core.$strict>;
|
|
114
|
+
createdAt: z.ZodString;
|
|
115
|
+
readyAt: z.ZodNullable<z.ZodString>;
|
|
116
|
+
deletedAt: z.ZodNullable<z.ZodString>;
|
|
117
|
+
}, z.core.$strict>;
|
|
118
|
+
export declare const requestResultSchema: z.ZodObject<{
|
|
119
|
+
id: z.ZodString;
|
|
120
|
+
environmentId: z.ZodString;
|
|
121
|
+
appName: z.ZodString;
|
|
122
|
+
method: z.ZodString;
|
|
123
|
+
path: z.ZodString;
|
|
124
|
+
query: z.ZodString;
|
|
125
|
+
service: z.ZodNullable<z.ZodString>;
|
|
126
|
+
mcpServer: z.ZodNullable<z.ZodString>;
|
|
127
|
+
tool: z.ZodNullable<z.ZodString>;
|
|
128
|
+
operation: z.ZodNullable<z.ZodString>;
|
|
129
|
+
responseStatus: z.ZodNumber;
|
|
130
|
+
respondedBy: z.ZodString;
|
|
131
|
+
errorCode: z.ZodNullable<z.ZodString>;
|
|
132
|
+
durationMs: z.ZodNumber;
|
|
133
|
+
requestBytes: z.ZodNullable<z.ZodNumber>;
|
|
134
|
+
responseBytes: z.ZodNullable<z.ZodNumber>;
|
|
135
|
+
receivedAt: z.ZodString;
|
|
136
|
+
completedAt: z.ZodString;
|
|
137
|
+
}, z.core.$strict>;
|
|
138
|
+
export declare const requestDetailResultSchema: z.ZodObject<{
|
|
139
|
+
id: z.ZodString;
|
|
140
|
+
environmentId: z.ZodString;
|
|
141
|
+
appName: z.ZodString;
|
|
142
|
+
method: z.ZodString;
|
|
143
|
+
path: z.ZodString;
|
|
144
|
+
query: z.ZodString;
|
|
145
|
+
service: z.ZodNullable<z.ZodString>;
|
|
146
|
+
mcpServer: z.ZodNullable<z.ZodString>;
|
|
147
|
+
tool: z.ZodNullable<z.ZodString>;
|
|
148
|
+
operation: z.ZodNullable<z.ZodString>;
|
|
149
|
+
responseStatus: z.ZodNumber;
|
|
150
|
+
respondedBy: z.ZodString;
|
|
151
|
+
errorCode: z.ZodNullable<z.ZodString>;
|
|
152
|
+
durationMs: z.ZodNumber;
|
|
153
|
+
requestBytes: z.ZodNullable<z.ZodNumber>;
|
|
154
|
+
responseBytes: z.ZodNullable<z.ZodNumber>;
|
|
155
|
+
receivedAt: z.ZodString;
|
|
156
|
+
completedAt: z.ZodString;
|
|
157
|
+
requestBody: z.ZodObject<{
|
|
158
|
+
bytes: z.ZodNullable<z.ZodNumber>;
|
|
159
|
+
contentType: z.ZodNullable<z.ZodString>;
|
|
160
|
+
coverage: z.ZodString;
|
|
161
|
+
encoding: z.ZodString;
|
|
162
|
+
preview: z.ZodNullable<z.ZodString>;
|
|
163
|
+
previewTruncated: z.ZodBoolean;
|
|
164
|
+
reason: z.ZodNullable<z.ZodString>;
|
|
165
|
+
}, z.core.$strict>;
|
|
166
|
+
requestHeaders: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
167
|
+
responseBody: z.ZodObject<{
|
|
168
|
+
bytes: z.ZodNullable<z.ZodNumber>;
|
|
169
|
+
contentType: z.ZodNullable<z.ZodString>;
|
|
170
|
+
coverage: z.ZodString;
|
|
171
|
+
encoding: z.ZodString;
|
|
172
|
+
preview: z.ZodNullable<z.ZodString>;
|
|
173
|
+
previewTruncated: z.ZodBoolean;
|
|
174
|
+
reason: z.ZodNullable<z.ZodString>;
|
|
175
|
+
}, z.core.$strict>;
|
|
176
|
+
responseHeaders: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
177
|
+
}, z.core.$strict>;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const pageInput = {
|
|
3
|
+
limit: z
|
|
4
|
+
.string()
|
|
5
|
+
.regex(/^[1-9]\d*$/)
|
|
6
|
+
.refine((value) => Number(value) <= 100)
|
|
7
|
+
.optional(),
|
|
8
|
+
cursor: z.string().min(1).max(2048).optional(),
|
|
9
|
+
all: z.boolean().default(false),
|
|
10
|
+
};
|
|
11
|
+
export const pageFlags = [
|
|
12
|
+
{
|
|
13
|
+
name: 'limit',
|
|
14
|
+
key: 'limit',
|
|
15
|
+
type: 'string',
|
|
16
|
+
description: 'Maximum results per page, from 1 to 100.',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'cursor',
|
|
20
|
+
key: 'cursor',
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: 'Continue from this cursor.',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'all',
|
|
26
|
+
key: 'all',
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
negatedName: null,
|
|
29
|
+
description: 'Read every page.',
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
export const idArgument = {
|
|
33
|
+
name: 'id',
|
|
34
|
+
key: 'id',
|
|
35
|
+
required: true,
|
|
36
|
+
many: false,
|
|
37
|
+
};
|
|
38
|
+
export const idInputSchema = z.strictObject({ id: z.string().min(1) });
|
|
39
|
+
export const idempotencyKeySchema = z
|
|
40
|
+
.string()
|
|
41
|
+
.min(8)
|
|
42
|
+
.max(128)
|
|
43
|
+
.regex(/^[A-Za-z0-9._:-]+$/)
|
|
44
|
+
.optional();
|
|
45
|
+
export const labelInputSchema = z
|
|
46
|
+
.array(z.string().regex(/^[^=]+=.*$/))
|
|
47
|
+
.max(32)
|
|
48
|
+
.default([]);
|
|
49
|
+
export const labelFlag = {
|
|
50
|
+
name: 'label',
|
|
51
|
+
key: 'label',
|
|
52
|
+
type: 'string[]',
|
|
53
|
+
description: 'Match or set a key=value label. Repeat for more labels.',
|
|
54
|
+
};
|
|
55
|
+
export const environmentStatusSchema = z.enum([
|
|
56
|
+
'starting',
|
|
57
|
+
'running',
|
|
58
|
+
'failed',
|
|
59
|
+
'deleted',
|
|
60
|
+
]);
|
|
61
|
+
export const waitFlag = {
|
|
62
|
+
name: 'wait',
|
|
63
|
+
key: 'wait',
|
|
64
|
+
type: 'boolean',
|
|
65
|
+
negatedName: 'no-wait',
|
|
66
|
+
description: 'Wait until the resource is ready.',
|
|
67
|
+
};
|
|
68
|
+
export const acceptedSchema = z.strictObject({
|
|
69
|
+
event: z.literal('accepted'),
|
|
70
|
+
id: z.string(),
|
|
71
|
+
});
|
|
72
|
+
const principalSchema = z.strictObject({
|
|
73
|
+
id: z.string().nullable(),
|
|
74
|
+
name: z.string().nullable(),
|
|
75
|
+
type: z.string(),
|
|
76
|
+
});
|
|
77
|
+
const appVersionSchema = z.strictObject({
|
|
78
|
+
appId: z.string(),
|
|
79
|
+
name: z.string(),
|
|
80
|
+
version: z.string(),
|
|
81
|
+
versionId: z.string(),
|
|
82
|
+
setup: z.record(z.string(), z.json()),
|
|
83
|
+
services: z.record(z.string(), z.json()),
|
|
84
|
+
});
|
|
85
|
+
export const environmentResultSchema = z.strictObject({
|
|
86
|
+
id: z.string(),
|
|
87
|
+
workspaceId: z.string(),
|
|
88
|
+
name: z.string().nullable(),
|
|
89
|
+
labels: z.record(z.string(), z.string()),
|
|
90
|
+
status: z.string(),
|
|
91
|
+
reason: z.string().nullable(),
|
|
92
|
+
failure: z
|
|
93
|
+
.strictObject({
|
|
94
|
+
appName: z.string(),
|
|
95
|
+
code: z.string(),
|
|
96
|
+
message: z.string(),
|
|
97
|
+
})
|
|
98
|
+
.nullable(),
|
|
99
|
+
timeLimitMinutes: z.number(),
|
|
100
|
+
tokenInUrl: z.boolean(),
|
|
101
|
+
snapshotId: z.string().nullable(),
|
|
102
|
+
apps: z.array(appVersionSchema.extend({ url: z.string() })),
|
|
103
|
+
createdBy: principalSchema,
|
|
104
|
+
createdAt: z.string(),
|
|
105
|
+
startedAt: z.string().nullable(),
|
|
106
|
+
deletedAt: z.string().nullable(),
|
|
107
|
+
expiresAt: z.string().nullable(),
|
|
108
|
+
});
|
|
109
|
+
export const snapshotResultSchema = z.strictObject({
|
|
110
|
+
id: z.string(),
|
|
111
|
+
workspaceId: z.string(),
|
|
112
|
+
environmentId: z.string(),
|
|
113
|
+
environmentName: z.string().nullable(),
|
|
114
|
+
name: z.string().nullable(),
|
|
115
|
+
status: z.string(),
|
|
116
|
+
failure: z.strictObject({ code: z.string(), message: z.string() }).nullable(),
|
|
117
|
+
sizeBytes: z.number().nullable(),
|
|
118
|
+
apps: z.array(appVersionSchema.extend({ sizeBytes: z.number().nullable() })),
|
|
119
|
+
createdBy: principalSchema,
|
|
120
|
+
createdAt: z.string(),
|
|
121
|
+
readyAt: z.string().nullable(),
|
|
122
|
+
deletedAt: z.string().nullable(),
|
|
123
|
+
});
|
|
124
|
+
export const requestResultSchema = z.strictObject({
|
|
125
|
+
id: z.string(),
|
|
126
|
+
environmentId: z.string(),
|
|
127
|
+
appName: z.string(),
|
|
128
|
+
method: z.string(),
|
|
129
|
+
path: z.string(),
|
|
130
|
+
query: z.string(),
|
|
131
|
+
service: z.string().nullable(),
|
|
132
|
+
mcpServer: z.string().nullable(),
|
|
133
|
+
tool: z.string().nullable(),
|
|
134
|
+
operation: z.string().nullable(),
|
|
135
|
+
responseStatus: z.number(),
|
|
136
|
+
respondedBy: z.string(),
|
|
137
|
+
errorCode: z.string().nullable(),
|
|
138
|
+
durationMs: z.number(),
|
|
139
|
+
requestBytes: z.number().nullable(),
|
|
140
|
+
responseBytes: z.number().nullable(),
|
|
141
|
+
receivedAt: z.string(),
|
|
142
|
+
completedAt: z.string(),
|
|
143
|
+
});
|
|
144
|
+
const bodyPreviewSchema = z.strictObject({
|
|
145
|
+
bytes: z.number().nullable(),
|
|
146
|
+
contentType: z.string().nullable(),
|
|
147
|
+
coverage: z.string(),
|
|
148
|
+
encoding: z.string(),
|
|
149
|
+
preview: z.string().nullable(),
|
|
150
|
+
previewTruncated: z.boolean(),
|
|
151
|
+
reason: z.string().nullable(),
|
|
152
|
+
});
|
|
153
|
+
export const requestDetailResultSchema = requestResultSchema.extend({
|
|
154
|
+
requestBody: bodyPreviewSchema,
|
|
155
|
+
requestHeaders: z.record(z.string(), z.string()),
|
|
156
|
+
responseBody: bodyPreviewSchema,
|
|
157
|
+
responseHeaders: z.record(z.string(), z.string()),
|
|
158
|
+
});
|
package/dist/text.d.ts
ADDED