@testsprite/testsprite-cli 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 +201 -0
- package/README.md +190 -0
- package/dist/assets/agent-skill/testsprite-verify.codex.md +119 -0
- package/dist/assets/agent-skill/testsprite-verify.skill.md +423 -0
- package/dist/commands/agent.d.ts +51 -0
- package/dist/commands/agent.js +552 -0
- package/dist/commands/auth.d.ts +38 -0
- package/dist/commands/auth.js +247 -0
- package/dist/commands/init.d.ts +63 -0
- package/dist/commands/init.js +350 -0
- package/dist/commands/project.d.ts +72 -0
- package/dist/commands/project.js +400 -0
- package/dist/commands/test.d.ts +1245 -0
- package/dist/commands/test.js +6214 -0
- package/dist/commands/usage.d.ts +63 -0
- package/dist/commands/usage.js +156 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +146 -0
- package/dist/lib/agent-targets.d.ts +50 -0
- package/dist/lib/agent-targets.js +99 -0
- package/dist/lib/bundle.d.ts +178 -0
- package/dist/lib/bundle.js +600 -0
- package/dist/lib/client-factory.d.ts +72 -0
- package/dist/lib/client-factory.js +120 -0
- package/dist/lib/config.d.ts +24 -0
- package/dist/lib/config.js +30 -0
- package/dist/lib/credentials.d.ts +17 -0
- package/dist/lib/credentials.js +122 -0
- package/dist/lib/dry-run/fetch.d.ts +18 -0
- package/dist/lib/dry-run/fetch.js +52 -0
- package/dist/lib/dry-run/samples.d.ts +50 -0
- package/dist/lib/dry-run/samples.js +676 -0
- package/dist/lib/errors.d.ts +118 -0
- package/dist/lib/errors.js +388 -0
- package/dist/lib/facade.d.ts +48 -0
- package/dist/lib/facade.js +104 -0
- package/dist/lib/failing-fe-resolver.d.ts +60 -0
- package/dist/lib/failing-fe-resolver.js +103 -0
- package/dist/lib/http.d.ts +255 -0
- package/dist/lib/http.js +608 -0
- package/dist/lib/output.d.ts +55 -0
- package/dist/lib/output.js +70 -0
- package/dist/lib/pagination.d.ts +56 -0
- package/dist/lib/pagination.js +81 -0
- package/dist/lib/poll.d.ts +88 -0
- package/dist/lib/poll.js +221 -0
- package/dist/lib/prompt.d.ts +8 -0
- package/dist/lib/prompt.js +97 -0
- package/dist/lib/rate-throttle.d.ts +49 -0
- package/dist/lib/rate-throttle.js +75 -0
- package/dist/lib/render-error.d.ts +15 -0
- package/dist/lib/render-error.js +44 -0
- package/dist/lib/runs.types.d.ts +344 -0
- package/dist/lib/runs.types.js +25 -0
- package/dist/lib/target-url.d.ts +25 -0
- package/dist/lib/target-url.js +127 -0
- package/dist/lib/ticker.d.ts +37 -0
- package/dist/lib/ticker.js +63 -0
- package/dist/lib/validate.d.ts +82 -0
- package/dist/lib/validate.js +165 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +2 -0
- package/package.json +65 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { type CommonOptions as FactoryCommonOptions } from '../lib/client-factory.js';
|
|
3
|
+
import type { FetchImpl } from '../lib/http.js';
|
|
4
|
+
import { type Page } from '../lib/pagination.js';
|
|
5
|
+
export interface CliProject {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
type: 'frontend' | 'backend';
|
|
9
|
+
createdFrom: 'portal' | 'mcp' | 'cli';
|
|
10
|
+
createdAt: string;
|
|
11
|
+
updatedAt: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ProjectDeps {
|
|
14
|
+
env?: NodeJS.ProcessEnv;
|
|
15
|
+
credentialsPath?: string;
|
|
16
|
+
fetchImpl?: FetchImpl;
|
|
17
|
+
stdout?: (line: string) => void;
|
|
18
|
+
stderr?: (line: string) => void;
|
|
19
|
+
}
|
|
20
|
+
type CommonOptions = FactoryCommonOptions;
|
|
21
|
+
interface ListOptions extends CommonOptions {
|
|
22
|
+
pageSize?: number;
|
|
23
|
+
startingToken?: string;
|
|
24
|
+
maxItems?: number;
|
|
25
|
+
}
|
|
26
|
+
export declare function runList(opts: ListOptions, deps?: ProjectDeps): Promise<Page<CliProject>>;
|
|
27
|
+
interface GetOptions extends CommonOptions {
|
|
28
|
+
projectId: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function runGet(opts: GetOptions, deps?: ProjectDeps): Promise<CliProject>;
|
|
31
|
+
export interface CliCreateProjectRequest {
|
|
32
|
+
type: 'frontend' | 'backend';
|
|
33
|
+
name: string;
|
|
34
|
+
targetUrl?: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
username?: string;
|
|
37
|
+
password?: string;
|
|
38
|
+
instruction?: string;
|
|
39
|
+
}
|
|
40
|
+
export type CliCreateProjectResponse = CliProject;
|
|
41
|
+
interface CreateOptions extends CommonOptions {
|
|
42
|
+
type: 'frontend' | 'backend';
|
|
43
|
+
name: string;
|
|
44
|
+
targetUrl?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
username?: string;
|
|
47
|
+
password?: string;
|
|
48
|
+
passwordFile?: string;
|
|
49
|
+
instruction?: string;
|
|
50
|
+
idempotencyKey?: string;
|
|
51
|
+
}
|
|
52
|
+
export declare function runCreate(opts: CreateOptions, deps?: ProjectDeps): Promise<CliCreateProjectResponse>;
|
|
53
|
+
export interface CliUpdateProjectResponse {
|
|
54
|
+
id: string;
|
|
55
|
+
/** Backend may omit this field; treat absence as no specific fields reported. */
|
|
56
|
+
updatedFields?: string[];
|
|
57
|
+
updatedAt: string;
|
|
58
|
+
}
|
|
59
|
+
interface UpdateOptions extends CommonOptions {
|
|
60
|
+
projectId: string;
|
|
61
|
+
name?: string;
|
|
62
|
+
targetUrl?: string;
|
|
63
|
+
username?: string;
|
|
64
|
+
password?: string;
|
|
65
|
+
passwordFile?: string;
|
|
66
|
+
description?: string;
|
|
67
|
+
instruction?: string;
|
|
68
|
+
idempotencyKey?: string;
|
|
69
|
+
}
|
|
70
|
+
export declare function runUpdate(opts: UpdateOptions, deps?: ProjectDeps): Promise<CliUpdateProjectResponse>;
|
|
71
|
+
export declare function createProjectCommand(deps?: ProjectDeps): Command;
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import { makeHttpClient, } from '../lib/client-factory.js';
|
|
5
|
+
import { ApiError } from '../lib/errors.js';
|
|
6
|
+
import { GLOBAL_OPTS_HINT, Output } from '../lib/output.js';
|
|
7
|
+
import { assertNotLocal } from '../lib/target-url.js';
|
|
8
|
+
import { assertIdempotencyKey } from '../lib/validate.js';
|
|
9
|
+
import { fetchSinglePage, paginate, validatePaginationFlags, } from '../lib/pagination.js';
|
|
10
|
+
export async function runList(opts, deps = {}) {
|
|
11
|
+
const out = makeOutput(opts.output, deps);
|
|
12
|
+
const client = makeClient(opts, deps);
|
|
13
|
+
const paginationFlags = validatePaginationFlags({
|
|
14
|
+
pageSize: opts.pageSize,
|
|
15
|
+
startingToken: opts.startingToken,
|
|
16
|
+
maxItems: opts.maxItems,
|
|
17
|
+
});
|
|
18
|
+
// When the user explicitly passed a page-size flag and did NOT ask
|
|
19
|
+
// for --max-items, treat that as a "give me one page and the cursor"
|
|
20
|
+
// request — same shape AWS CLI ships. Otherwise auto-page.
|
|
21
|
+
const useSinglePage = opts.pageSize !== undefined && opts.maxItems === undefined;
|
|
22
|
+
let page;
|
|
23
|
+
if (useSinglePage) {
|
|
24
|
+
page = await fetchSinglePage(client, '/projects', paginationFlags.pageSize, opts.startingToken);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
page = await paginate(async ({ pageSize, cursor }) => client.get('/projects', {
|
|
28
|
+
query: { pageSize, cursor },
|
|
29
|
+
}), paginationFlags);
|
|
30
|
+
}
|
|
31
|
+
out.print(page, data => {
|
|
32
|
+
const p = data;
|
|
33
|
+
return renderProjectListText(p);
|
|
34
|
+
});
|
|
35
|
+
return page;
|
|
36
|
+
}
|
|
37
|
+
export async function runGet(opts, deps = {}) {
|
|
38
|
+
const out = makeOutput(opts.output, deps);
|
|
39
|
+
const client = makeClient(opts, deps);
|
|
40
|
+
const project = await client.get(`/projects/${encodeURIComponent(opts.projectId)}`);
|
|
41
|
+
out.print(project, data => renderProjectText(data));
|
|
42
|
+
return project;
|
|
43
|
+
}
|
|
44
|
+
export async function runCreate(opts, deps = {}) {
|
|
45
|
+
const out = makeOutput(opts.output, deps);
|
|
46
|
+
const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
47
|
+
// P1-2: validate idempotency key before sending as an HTTP header.
|
|
48
|
+
// Non-ASCII chars cause a ByteString TypeError at the transport layer
|
|
49
|
+
// (exit 10 UNAVAILABLE) — fail fast with a clear exit 5 instead.
|
|
50
|
+
assertIdempotencyKey(opts.idempotencyKey);
|
|
51
|
+
// P1-3: client-side length checks matching server limits.
|
|
52
|
+
if (opts.name !== undefined && opts.name.length > 200) {
|
|
53
|
+
throw localValidationError('--name must be at most 200 characters');
|
|
54
|
+
}
|
|
55
|
+
if (opts.description !== undefined && opts.description.length > 2000) {
|
|
56
|
+
throw localValidationError('--description must be at most 2000 characters');
|
|
57
|
+
}
|
|
58
|
+
// P2-7: guard --url against localhost/RFC1918/non-http(s) (same rules as
|
|
59
|
+
// `test create --target-url`). Applies to both FE (required) and BE (optional).
|
|
60
|
+
if (opts.targetUrl !== undefined) {
|
|
61
|
+
assertNotLocal(opts.targetUrl);
|
|
62
|
+
}
|
|
63
|
+
if (opts.type === 'frontend' && !opts.targetUrl) {
|
|
64
|
+
throw localValidationError('--url is required for --type frontend');
|
|
65
|
+
}
|
|
66
|
+
if (opts.dryRun) {
|
|
67
|
+
const idempotencyKey = opts.idempotencyKey ?? `cli-proj-create-${randomUUID()}`;
|
|
68
|
+
// P2-6: gate idempotency-key output behind --verbose/--debug/json (matches
|
|
69
|
+
// test create convention). Suppress in plain text interactive mode to reduce
|
|
70
|
+
// noise; still available for automation and retry flows.
|
|
71
|
+
if (opts.idempotencyKey === undefined &&
|
|
72
|
+
(opts.output === 'json' || opts.verbose || opts.debug)) {
|
|
73
|
+
stderr(`idempotency-key: ${idempotencyKey}`);
|
|
74
|
+
}
|
|
75
|
+
const sample = {
|
|
76
|
+
id: 'p_dryrun_2026',
|
|
77
|
+
type: opts.type,
|
|
78
|
+
name: opts.name,
|
|
79
|
+
targetUrl: opts.targetUrl ?? '',
|
|
80
|
+
createdFrom: 'cli',
|
|
81
|
+
createdAt: '2026-05-16T00:00:00.000Z',
|
|
82
|
+
updatedAt: '2026-05-16T00:00:00.000Z',
|
|
83
|
+
};
|
|
84
|
+
out.print(sample, data => renderProjectText(data));
|
|
85
|
+
return sample;
|
|
86
|
+
}
|
|
87
|
+
// Resolve password: flag > file > none
|
|
88
|
+
let password = opts.password;
|
|
89
|
+
if (password === undefined && opts.passwordFile !== undefined) {
|
|
90
|
+
password = readFileSync(opts.passwordFile, 'utf8').trim();
|
|
91
|
+
}
|
|
92
|
+
const idempotencyKey = opts.idempotencyKey ?? `cli-proj-create-${randomUUID()}`;
|
|
93
|
+
if (opts.idempotencyKey === undefined && (opts.output === 'json' || opts.verbose || opts.debug)) {
|
|
94
|
+
stderr(`idempotency-key: ${idempotencyKey}`);
|
|
95
|
+
}
|
|
96
|
+
const body = {
|
|
97
|
+
type: opts.type,
|
|
98
|
+
name: opts.name,
|
|
99
|
+
...(opts.targetUrl !== undefined ? { targetUrl: opts.targetUrl } : {}),
|
|
100
|
+
...(opts.description !== undefined ? { description: opts.description } : {}),
|
|
101
|
+
...(opts.username !== undefined ? { username: opts.username } : {}),
|
|
102
|
+
...(password !== undefined ? { password } : {}),
|
|
103
|
+
...(opts.instruction !== undefined ? { instruction: opts.instruction } : {}),
|
|
104
|
+
};
|
|
105
|
+
const client = makeClient(opts, deps);
|
|
106
|
+
const created = await client.post('/projects', {
|
|
107
|
+
body,
|
|
108
|
+
headers: { 'idempotency-key': idempotencyKey },
|
|
109
|
+
});
|
|
110
|
+
out.print(created, data => renderProjectText(data));
|
|
111
|
+
return created;
|
|
112
|
+
}
|
|
113
|
+
export async function runUpdate(opts, deps = {}) {
|
|
114
|
+
const out = makeOutput(opts.output, deps);
|
|
115
|
+
const stderr = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
|
|
116
|
+
// P1-2: validate idempotency key before sending as an HTTP header.
|
|
117
|
+
assertIdempotencyKey(opts.idempotencyKey);
|
|
118
|
+
// P1-3: client-side length checks matching server limits.
|
|
119
|
+
if (opts.name !== undefined && opts.name.length > 200) {
|
|
120
|
+
throw localValidationError('--name must be at most 200 characters');
|
|
121
|
+
}
|
|
122
|
+
if (opts.description !== undefined && opts.description.length > 2000) {
|
|
123
|
+
throw localValidationError('--description must be at most 2000 characters');
|
|
124
|
+
}
|
|
125
|
+
// Resolve password
|
|
126
|
+
let password = opts.password;
|
|
127
|
+
if (password === undefined && opts.passwordFile !== undefined) {
|
|
128
|
+
password = readFileSync(opts.passwordFile, 'utf8').trim();
|
|
129
|
+
}
|
|
130
|
+
// P2-7: guard --url against localhost/RFC1918/non-http(s).
|
|
131
|
+
if (opts.targetUrl !== undefined) {
|
|
132
|
+
assertNotLocal(opts.targetUrl);
|
|
133
|
+
}
|
|
134
|
+
const mutableFields = {
|
|
135
|
+
name: opts.name,
|
|
136
|
+
targetUrl: opts.targetUrl,
|
|
137
|
+
username: opts.username,
|
|
138
|
+
password,
|
|
139
|
+
description: opts.description,
|
|
140
|
+
instruction: opts.instruction,
|
|
141
|
+
};
|
|
142
|
+
const presentFields = Object.entries(mutableFields).filter(([, v]) => v !== undefined);
|
|
143
|
+
if (presentFields.length === 0) {
|
|
144
|
+
throw localValidationError('At least one mutable flag is required: --name, --url, --username, --password/--password-file, --description, or --instruction.');
|
|
145
|
+
}
|
|
146
|
+
if (opts.dryRun) {
|
|
147
|
+
const idempotencyKey = opts.idempotencyKey ?? `cli-proj-update-${randomUUID()}`;
|
|
148
|
+
if (opts.idempotencyKey === undefined &&
|
|
149
|
+
(opts.output === 'json' || opts.verbose || opts.debug)) {
|
|
150
|
+
stderr(`idempotency-key: ${idempotencyKey}`);
|
|
151
|
+
}
|
|
152
|
+
const sample = {
|
|
153
|
+
id: opts.projectId,
|
|
154
|
+
updatedFields: presentFields.map(([k]) => k),
|
|
155
|
+
updatedAt: '2026-05-16T00:00:00.000Z',
|
|
156
|
+
};
|
|
157
|
+
out.print(sample, data => renderUpdateText(data));
|
|
158
|
+
return sample;
|
|
159
|
+
}
|
|
160
|
+
const idempotencyKey = opts.idempotencyKey ?? `cli-proj-update-${randomUUID()}`;
|
|
161
|
+
if (opts.idempotencyKey === undefined && (opts.output === 'json' || opts.verbose || opts.debug)) {
|
|
162
|
+
stderr(`idempotency-key: ${idempotencyKey}`);
|
|
163
|
+
}
|
|
164
|
+
const body = Object.fromEntries(presentFields);
|
|
165
|
+
const client = makeClient(opts, deps);
|
|
166
|
+
const updated = await client.patch(`/projects/${encodeURIComponent(opts.projectId)}`, {
|
|
167
|
+
body,
|
|
168
|
+
headers: { 'idempotency-key': idempotencyKey },
|
|
169
|
+
});
|
|
170
|
+
out.print(updated, data => renderUpdateText(data));
|
|
171
|
+
return updated;
|
|
172
|
+
}
|
|
173
|
+
export function createProjectCommand(deps = {}) {
|
|
174
|
+
const project = new Command('project').description('Manage TestSprite projects');
|
|
175
|
+
project
|
|
176
|
+
.command('list')
|
|
177
|
+
.description('List projects visible to the API key\n' +
|
|
178
|
+
'\nExit codes:\n' +
|
|
179
|
+
' 0 success\n' +
|
|
180
|
+
' 3 auth error\n' +
|
|
181
|
+
' 5 validation error (e.g., bad --page-size)\n' +
|
|
182
|
+
' 10 transport/network failure (UNAVAILABLE) — retry the command')
|
|
183
|
+
.option('--page-size <n>', 'service page-size hint (1-100, default 25)')
|
|
184
|
+
.option('--starting-token <token>', 'opaque cursor from a previous list response')
|
|
185
|
+
.option('--max-items <n>', 'stop after this many items across auto-paged pages')
|
|
186
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
187
|
+
.action(async (cmdOpts, command) => {
|
|
188
|
+
// Don't parse numeric flags via Commander — its parser throws a
|
|
189
|
+
// plain `Error`, which `index.ts` maps to exit code 1. Local
|
|
190
|
+
// validation lives in `runList → validatePaginationFlags`, which
|
|
191
|
+
// raises a typed `ApiError(VALIDATION_ERROR)` and surfaces with
|
|
192
|
+
// the contract-mandated exit code 5.
|
|
193
|
+
await runList({
|
|
194
|
+
...resolveCommonOptions(command),
|
|
195
|
+
pageSize: parseFlag(cmdOpts.pageSize, 'page-size'),
|
|
196
|
+
startingToken: cmdOpts.startingToken,
|
|
197
|
+
maxItems: parseFlag(cmdOpts.maxItems, 'max-items'),
|
|
198
|
+
}, deps);
|
|
199
|
+
});
|
|
200
|
+
project
|
|
201
|
+
.command('get <project-id>')
|
|
202
|
+
.description('Get a project by id')
|
|
203
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
204
|
+
.action(async (projectId, _cmdOpts, command) => {
|
|
205
|
+
await runGet({ ...resolveCommonOptions(command), projectId }, deps);
|
|
206
|
+
});
|
|
207
|
+
project
|
|
208
|
+
.command('create')
|
|
209
|
+
.description('Create a new project')
|
|
210
|
+
.option('--type <frontend|backend>', 'project type (required)')
|
|
211
|
+
.option('--name <name>', 'project name (required)')
|
|
212
|
+
.option('--url <url>', 'target URL (required for frontend)')
|
|
213
|
+
.option('--description <text>', 'optional human description')
|
|
214
|
+
.option('--username <user>', 'optional auth username')
|
|
215
|
+
.option('--password <pw>', 'optional auth password (use --password-file for non-interactive)')
|
|
216
|
+
.option('--password-file <path>', 'read password from file instead of inline flag')
|
|
217
|
+
.option('--instruction <text>', 'optional FE plan-gen instruction hint')
|
|
218
|
+
.option('--idempotency-key <token>', 'opaque idempotency token. Defaults to a UUIDv4 minted per invocation.')
|
|
219
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
220
|
+
.action(async (cmdOpts, command) => {
|
|
221
|
+
if (!cmdOpts.type)
|
|
222
|
+
throw localValidationError('--type is required (frontend|backend)');
|
|
223
|
+
if (!cmdOpts.name)
|
|
224
|
+
throw localValidationError('--name is required');
|
|
225
|
+
const type = cmdOpts.type;
|
|
226
|
+
if (type !== 'frontend' && type !== 'backend') {
|
|
227
|
+
throw localValidationError('--type must be frontend or backend');
|
|
228
|
+
}
|
|
229
|
+
if (type === 'frontend' && !cmdOpts.url) {
|
|
230
|
+
throw localValidationError('--url is required for --type frontend');
|
|
231
|
+
}
|
|
232
|
+
await runCreate({
|
|
233
|
+
...resolveCommonOptions(command),
|
|
234
|
+
type,
|
|
235
|
+
name: cmdOpts.name,
|
|
236
|
+
targetUrl: cmdOpts.url,
|
|
237
|
+
description: cmdOpts.description,
|
|
238
|
+
username: cmdOpts.username,
|
|
239
|
+
password: cmdOpts.password,
|
|
240
|
+
passwordFile: cmdOpts.passwordFile,
|
|
241
|
+
instruction: cmdOpts.instruction,
|
|
242
|
+
idempotencyKey: cmdOpts.idempotencyKey,
|
|
243
|
+
}, deps);
|
|
244
|
+
});
|
|
245
|
+
project
|
|
246
|
+
.command('update <project-id>')
|
|
247
|
+
.description('Update project metadata')
|
|
248
|
+
.option('--name <name>', 'new project name')
|
|
249
|
+
.option('--url <url>', 'new target URL')
|
|
250
|
+
.option('--username <user>', 'new auth username')
|
|
251
|
+
.option('--password <pw>', 'new auth password')
|
|
252
|
+
.option('--password-file <path>', 'read new password from file')
|
|
253
|
+
.option('--description <text>', 'new description')
|
|
254
|
+
.option('--instruction <text>', 'new FE plan-gen instruction hint')
|
|
255
|
+
.option('--idempotency-key <token>', 'opaque idempotency token. Defaults to a UUIDv4 minted per invocation.')
|
|
256
|
+
.addHelpText('after', GLOBAL_OPTS_HINT)
|
|
257
|
+
.action(async (projectId, cmdOpts, command) => {
|
|
258
|
+
await runUpdate({
|
|
259
|
+
...resolveCommonOptions(command),
|
|
260
|
+
projectId,
|
|
261
|
+
name: cmdOpts.name,
|
|
262
|
+
targetUrl: cmdOpts.url,
|
|
263
|
+
username: cmdOpts.username,
|
|
264
|
+
password: cmdOpts.password,
|
|
265
|
+
passwordFile: cmdOpts.passwordFile,
|
|
266
|
+
description: cmdOpts.description,
|
|
267
|
+
instruction: cmdOpts.instruction,
|
|
268
|
+
idempotencyKey: cmdOpts.idempotencyKey,
|
|
269
|
+
}, deps);
|
|
270
|
+
});
|
|
271
|
+
return project;
|
|
272
|
+
}
|
|
273
|
+
function parseFlag(raw, flagName) {
|
|
274
|
+
if (raw === undefined)
|
|
275
|
+
return undefined;
|
|
276
|
+
const n = Number(raw);
|
|
277
|
+
if (!Number.isFinite(n)) {
|
|
278
|
+
throw ApiError.fromEnvelope({
|
|
279
|
+
error: {
|
|
280
|
+
code: 'VALIDATION_ERROR',
|
|
281
|
+
message: 'Invalid request.',
|
|
282
|
+
nextAction: `Flag \`--${flagName}\` is invalid: must be an integer.`,
|
|
283
|
+
requestId: 'local',
|
|
284
|
+
details: { field: flagName, reason: 'must be an integer' },
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return n;
|
|
289
|
+
}
|
|
290
|
+
function resolveCommonOptions(command) {
|
|
291
|
+
const globals = command.optsWithGlobals();
|
|
292
|
+
// P2-8: validate --output before allowing silent fallback to 'text'.
|
|
293
|
+
const rawOutput = globals.output;
|
|
294
|
+
if (rawOutput !== undefined && rawOutput !== 'json' && rawOutput !== 'text') {
|
|
295
|
+
throw localValidationError('--output must be one of: json, text');
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
profile: globals.profile ?? 'default',
|
|
299
|
+
output: globals.output ?? 'text',
|
|
300
|
+
endpointUrl: globals.endpointUrl,
|
|
301
|
+
debug: globals.debug ?? false,
|
|
302
|
+
verbose: globals.verbose ?? false,
|
|
303
|
+
dryRun: globals.dryRun ?? false,
|
|
304
|
+
requestTimeoutMs: parseRequestTimeoutFlag(globals.requestTimeout),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Parse the `--request-timeout <seconds>` flag value into milliseconds.
|
|
309
|
+
* Returns `undefined` when the flag was not supplied (factory falls back to
|
|
310
|
+
* the env var / default). Silently clamps out-of-range values.
|
|
311
|
+
*/
|
|
312
|
+
function parseRequestTimeoutFlag(raw) {
|
|
313
|
+
if (raw === undefined)
|
|
314
|
+
return undefined;
|
|
315
|
+
const n = Number(raw);
|
|
316
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
317
|
+
return undefined;
|
|
318
|
+
return Math.round(n * 1000); // seconds → milliseconds
|
|
319
|
+
}
|
|
320
|
+
function makeClient(opts, deps) {
|
|
321
|
+
return makeHttpClient(opts, {
|
|
322
|
+
env: deps.env,
|
|
323
|
+
credentialsPath: deps.credentialsPath,
|
|
324
|
+
fetchImpl: deps.fetchImpl,
|
|
325
|
+
stderr: deps.stderr,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
function makeOutput(mode, deps) {
|
|
329
|
+
return new Output(mode, { stdout: deps.stdout, stderr: deps.stderr });
|
|
330
|
+
}
|
|
331
|
+
function renderProjectListText(page) {
|
|
332
|
+
if (page.items.length === 0) {
|
|
333
|
+
return page.nextToken
|
|
334
|
+
? `No projects on this page.\nnextToken: ${page.nextToken}`
|
|
335
|
+
: 'No projects.';
|
|
336
|
+
}
|
|
337
|
+
// Compact, AWS-CLI-grade columnar output. Column widths are computed
|
|
338
|
+
// per-call so a single absurdly long project name doesn't push the
|
|
339
|
+
// whole table off-screen.
|
|
340
|
+
const idWidth = Math.max(2, ...page.items.map(p => p.id.length));
|
|
341
|
+
const nameWidth = Math.max(4, ...page.items.map(p => p.name.length));
|
|
342
|
+
const typeWidth = 8;
|
|
343
|
+
const fromWidth = 6;
|
|
344
|
+
const header = pad('ID', idWidth) +
|
|
345
|
+
' ' +
|
|
346
|
+
pad('NAME', nameWidth) +
|
|
347
|
+
' ' +
|
|
348
|
+
pad('TYPE', typeWidth) +
|
|
349
|
+
' ' +
|
|
350
|
+
pad('FROM', fromWidth) +
|
|
351
|
+
' ' +
|
|
352
|
+
'CREATED';
|
|
353
|
+
const rows = page.items.map(p => pad(p.id, idWidth) +
|
|
354
|
+
' ' +
|
|
355
|
+
pad(p.name, nameWidth) +
|
|
356
|
+
' ' +
|
|
357
|
+
pad(p.type, typeWidth) +
|
|
358
|
+
' ' +
|
|
359
|
+
pad(p.createdFrom, fromWidth) +
|
|
360
|
+
' ' +
|
|
361
|
+
p.createdAt);
|
|
362
|
+
const lines = [header, ...rows];
|
|
363
|
+
if (page.nextToken)
|
|
364
|
+
lines.push('', `nextToken: ${page.nextToken}`);
|
|
365
|
+
return lines.join('\n');
|
|
366
|
+
}
|
|
367
|
+
function renderProjectText(p) {
|
|
368
|
+
return [
|
|
369
|
+
`id: ${p.id}`,
|
|
370
|
+
`name: ${p.name}`,
|
|
371
|
+
`type: ${p.type}`,
|
|
372
|
+
`createdFrom: ${p.createdFrom}`,
|
|
373
|
+
`createdAt: ${p.createdAt}`,
|
|
374
|
+
`updatedAt: ${p.updatedAt}`,
|
|
375
|
+
].join('\n');
|
|
376
|
+
}
|
|
377
|
+
function pad(s, width) {
|
|
378
|
+
if (s.length >= width)
|
|
379
|
+
return s;
|
|
380
|
+
return s + ' '.repeat(width - s.length);
|
|
381
|
+
}
|
|
382
|
+
function renderUpdateText(r) {
|
|
383
|
+
return [
|
|
384
|
+
`id: ${r.id}`,
|
|
385
|
+
`updatedFields: ${r.updatedFields?.join(', ') ?? '(none)'}`,
|
|
386
|
+
`updatedAt: ${r.updatedAt}`,
|
|
387
|
+
].join('\n');
|
|
388
|
+
}
|
|
389
|
+
function localValidationError(message) {
|
|
390
|
+
return ApiError.fromEnvelope({
|
|
391
|
+
error: {
|
|
392
|
+
code: 'VALIDATION_ERROR',
|
|
393
|
+
message: 'Invalid request.',
|
|
394
|
+
nextAction: message,
|
|
395
|
+
requestId: 'local',
|
|
396
|
+
details: { reason: 'missing_required_flag' },
|
|
397
|
+
},
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
//# sourceMappingURL=project.js.map
|