@seavideo/cli 0.0.0-stage → 0.3.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 +12 -0
- package/README.md +528 -2
- package/dist/bin/seavideo.js +11 -0
- package/dist/src/atomic-write.js +14 -0
- package/dist/src/canvas/api.js +172 -0
- package/dist/src/canvas/browser.js +40 -0
- package/dist/src/canvas/chrome-binary.js +109 -0
- package/dist/src/canvas/daemon.js +264 -0
- package/dist/src/canvas/engine-install.js +46 -0
- package/dist/src/canvas/engine-log.js +9 -0
- package/dist/src/canvas/engine.js +99 -0
- package/dist/src/canvas/entry.js +16 -0
- package/dist/src/canvas/env-lock.js +164 -0
- package/dist/src/canvas/launch.js +97 -0
- package/dist/src/canvas/lifecycle.js +65 -0
- package/dist/src/canvas/names.js +61 -0
- package/dist/src/canvas/params.js +38 -0
- package/dist/src/canvas/puppeteer.js +153 -0
- package/dist/src/canvas/screenshot.js +23 -0
- package/dist/src/canvas/session-record.js +77 -0
- package/dist/src/canvas/team.js +97 -0
- package/dist/src/canvas/tool-args.js +47 -0
- package/dist/src/canvas/tool-session.js +165 -0
- package/dist/src/canvas/tool-specs.js +54 -0
- package/dist/src/canvas/url.js +38 -0
- package/dist/src/cli/args.js +16 -0
- package/dist/src/cli/commands/auth.js +51 -0
- package/dist/src/cli/commands/canvas/common.js +31 -0
- package/dist/src/cli/commands/canvas/engine-choice.js +41 -0
- package/dist/src/cli/commands/canvas/index.js +5 -0
- package/dist/src/cli/commands/canvas/item.js +233 -0
- package/dist/src/cli/commands/canvas/list.js +168 -0
- package/dist/src/cli/commands/canvas/register.js +106 -0
- package/dist/src/cli/commands/canvas/render.js +229 -0
- package/dist/src/cli/commands/canvas/screenshot.js +52 -0
- package/dist/src/cli/commands/canvas/session.js +249 -0
- package/dist/src/cli/commands/canvas/teams.js +142 -0
- package/dist/src/cli/commands/config.js +74 -0
- package/dist/src/cli/commands/doctor.js +261 -0
- package/dist/src/cli/commands/engine.js +96 -0
- package/dist/src/cli/commands/env/create.js +160 -0
- package/dist/src/cli/commands/env/fields.js +26 -0
- package/dist/src/cli/commands/env/index.js +4 -0
- package/dist/src/cli/commands/env/list.js +44 -0
- package/dist/src/cli/commands/env/mutate.js +118 -0
- package/dist/src/cli/commands/login/flow-token.js +41 -0
- package/dist/src/cli/commands/login/index.js +12 -0
- package/dist/src/cli/commands/login/oauth.js +69 -0
- package/dist/src/cli/commands/login/save.js +26 -0
- package/dist/src/cli/commands/logout.js +92 -0
- package/dist/src/cli/commands/skill.js +185 -0
- package/dist/src/cli/commands/tool.js +279 -0
- package/dist/src/cli/commands/update.js +117 -0
- package/dist/src/cli/commands/wallet.js +69 -0
- package/dist/src/cli/commands/whoami.js +147 -0
- package/dist/src/cli/context.js +41 -0
- package/dist/src/cli/credential.js +93 -0
- package/dist/src/cli/elapsed.js +25 -0
- package/dist/src/cli/failure-screenshot.js +24 -0
- package/dist/src/cli/flags.js +1 -0
- package/dist/src/cli/hints.js +7 -0
- package/dist/src/cli/main.js +44 -0
- package/dist/src/cli/output-error.js +23 -0
- package/dist/src/cli/output.js +47 -0
- package/dist/src/cli/program.js +261 -0
- package/dist/src/cli/run.js +11 -0
- package/dist/src/cli/session.js +63 -0
- package/dist/src/config/base-url.js +26 -0
- package/dist/src/config/credential-vault.js +115 -0
- package/dist/src/config/dotenv.js +59 -0
- package/dist/src/config/envname.js +41 -0
- package/dist/src/config/paths.js +22 -0
- package/dist/src/config/preset-schema.js +67 -0
- package/dist/src/config/presets.js +132 -0
- package/dist/src/config/resolve.js +41 -0
- package/dist/src/config/secret-key.js +63 -0
- package/dist/src/config/store-schema.js +143 -0
- package/dist/src/config/store.js +273 -0
- package/dist/src/config/vault-crypto.js +44 -0
- package/dist/src/deps.js +191 -0
- package/dist/src/deps.types.js +1 -0
- package/dist/src/errors.js +24 -0
- package/dist/src/fs-retry.js +34 -0
- package/dist/src/i18n.js +1214 -0
- package/dist/src/loopback.js +134 -0
- package/dist/src/sdk/auth.js +20 -0
- package/dist/src/sdk/credential-expiry.js +67 -0
- package/dist/src/sdk/discovery.js +90 -0
- package/dist/src/sdk/http.js +98 -0
- package/dist/src/sdk/identity.js +17 -0
- package/dist/src/sdk/jwks.js +119 -0
- package/dist/src/sdk/oauth-protocol.js +226 -0
- package/dist/src/sdk/oauth.js +179 -0
- package/dist/src/sdk/provider/cn.js +34 -0
- package/dist/src/sdk/provider/index.js +16 -0
- package/dist/src/sdk/provider/oversea.js +41 -0
- package/dist/src/sdk/provider/types.js +1 -0
- package/dist/src/sdk/refresh.js +66 -0
- package/dist/src/semver.js +89 -0
- package/dist/src/skill/api.js +176 -0
- package/dist/src/text.js +3 -0
- package/dist/src/types.js +1 -0
- package/dist/src/update/check-cache.js +56 -0
- package/dist/src/update/install-layout.js +79 -0
- package/dist/src/update/notify.js +15 -0
- package/dist/src/update/npm-install.js +64 -0
- package/dist/src/update/passive.js +53 -0
- package/dist/src/update/registry.js +59 -0
- package/dist/src/wallet/api.js +107 -0
- package/package.json +67 -4
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { CliError, errorMessage } from "../../../errors.js";
|
|
2
|
+
import { buildCanvasUrl, maskUrlCredential } from "../../../canvas/url.js";
|
|
3
|
+
import { resolveFlowCredential } from "../../credential.js";
|
|
4
|
+
import { collectNames } from "../../../canvas/names.js";
|
|
5
|
+
import { assertCanvasId, normalizeDeleteIds, validateCanvasName } from "../../../canvas/params.js";
|
|
6
|
+
import { closeCanvasSession } from "../../../canvas/lifecycle.js";
|
|
7
|
+
import { withCanvasLock } from "../../../canvas/env-lock.js";
|
|
8
|
+
import { readSessionRecord } from "../../../canvas/session-record.js";
|
|
9
|
+
import { resolveEnvName } from "../../../config/resolve.js";
|
|
10
|
+
import { formatTimestamp } from "../../elapsed.js";
|
|
11
|
+
import { renderTable, style } from "../../output.js";
|
|
12
|
+
import { cmdPrefix } from "../../hints.js";
|
|
13
|
+
import { agoText, nameOf, serializeItem } from "./render.js";
|
|
14
|
+
import { sanitizeText } from "../../../text.js";
|
|
15
|
+
import { loadEnv } from "../../context.js";
|
|
16
|
+
import { t } from "../../../i18n.js";
|
|
17
|
+
import { accountOf, apiOf, assertSpace } from "./common.js";
|
|
18
|
+
import { loadHint, useCanvas } from "./session.js";
|
|
19
|
+
export async function canvasCreateCommand(ctx, name, options) {
|
|
20
|
+
const { deps } = ctx;
|
|
21
|
+
assertSpace(ctx, options.project);
|
|
22
|
+
if (options.project !== undefined && options.folder !== undefined) {
|
|
23
|
+
throw new CliError('usage', t('canvas.projectFolderConflict', {}, deps.env));
|
|
24
|
+
}
|
|
25
|
+
const canvasName = validateCanvasName(name, deps.env);
|
|
26
|
+
const { api } = await apiOf(ctx);
|
|
27
|
+
const created = await api.create({
|
|
28
|
+
name: canvasName,
|
|
29
|
+
projectId: options.project,
|
|
30
|
+
folderId: options.folder,
|
|
31
|
+
});
|
|
32
|
+
let loadWarning = null;
|
|
33
|
+
let loadOutput = [];
|
|
34
|
+
if (options.use === true) {
|
|
35
|
+
const buffered = [];
|
|
36
|
+
const realStdout = deps.stdout;
|
|
37
|
+
deps.stdout = (text) => buffered.push(text);
|
|
38
|
+
try {
|
|
39
|
+
await useCanvas(ctx, created.id);
|
|
40
|
+
loadOutput = buffered;
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
loadWarning =
|
|
44
|
+
`${style.warn('!')} ${t('canvas.createdButNotLoaded', {}, deps.env)}\n` +
|
|
45
|
+
`${style.dim(` ${errorMessage(err)}`)}\n` +
|
|
46
|
+
`${style.dim(` ${loadHint(ctx, created.id, deps.env)}`)}\n`;
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
deps.stdout = realStdout;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
}
|
|
54
|
+
if (options.json === true) {
|
|
55
|
+
deps.stdout(`${JSON.stringify(serializeItem(created), null, 2)}\n`);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
deps.stdout(`${style.ok('✓')} ${t('canvas.created', { id: created.id, name: created.name === '' ? t('canvas.unnamed', {}, deps.env) : sanitizeText(created.name) }, deps.env)}\n`);
|
|
59
|
+
for (const text of loadOutput)
|
|
60
|
+
deps.stdout(text);
|
|
61
|
+
if (options.use !== true) {
|
|
62
|
+
deps.stdout(`${style.dim(` ${t('canvas.nextUse', {}, deps.env)}: ${cmdPrefix(ctx)}canvas use ${created.id}`)}\n`);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (loadWarning !== null)
|
|
68
|
+
deps.stderr(loadWarning);
|
|
69
|
+
else {
|
|
70
|
+
}
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
async function fetchGraphOrGuide(ctx, canvasId) {
|
|
74
|
+
const { api } = await apiOf(ctx);
|
|
75
|
+
try {
|
|
76
|
+
return await api.get(canvasId);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
throw isCanvasNotFound(err) ? canvasNotFoundError(ctx, canvasId, err) : err;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function isCanvasNotFound(err) {
|
|
83
|
+
return err instanceof CliError && err.kind === 'server' && err.message.includes('409');
|
|
84
|
+
}
|
|
85
|
+
function canvasNotFoundError(ctx, canvasId, err) {
|
|
86
|
+
const raw = `\n${t('canvas.notFoundRaw', { raw: err.message }, ctx.deps.env)}`;
|
|
87
|
+
const rid = err.detail === undefined
|
|
88
|
+
? ''
|
|
89
|
+
: `\n${t('canvas.notFoundRid', { rid: err.detail }, ctx.deps.env)}`;
|
|
90
|
+
return new CliError('server', t('canvas.notFound', { id: canvasId }, ctx.deps.env), {
|
|
91
|
+
detail: `${t('canvas.notFoundDetail', {}, ctx.deps.env)}${raw}${rid}`,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
export async function canvasGetCommand(ctx, id, options) {
|
|
95
|
+
const { deps } = ctx;
|
|
96
|
+
const canvasId = assertCanvasId(id, deps.env);
|
|
97
|
+
const { api, config, flowToken } = await apiOf(ctx);
|
|
98
|
+
const graph = await fetchGraphOrGuide(ctx, canvasId);
|
|
99
|
+
let result;
|
|
100
|
+
if (graph.deletedAt !== null) {
|
|
101
|
+
const detail = t('canvas.getDeletedDetail', { at: graph.deletedAt }, deps.env);
|
|
102
|
+
if (options.json === true) {
|
|
103
|
+
deps.stdout(`${JSON.stringify({ ...serializeItem(graph), deleted: true, deletedAt: graph.deletedAt }, null, 2)}\n`);
|
|
104
|
+
deps.stderr(`${style.warn('!')} ${detail}\n`);
|
|
105
|
+
result = 0;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
throw new CliError('server', t('canvas.getDeleted', {}, deps.env), { detail });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const last = await ctx.store.readLastCanvas(config.env);
|
|
113
|
+
const lastUsedAt = last !== null && last.id === graph.id ? last.at : null;
|
|
114
|
+
const lookupResult = await collectNames(deps, config, api, [graph], accountOf(config, flowToken));
|
|
115
|
+
if (lookupResult.error !== null) {
|
|
116
|
+
deps.stderr(`${style.warn('!')} ${t('canvas.namesUnavailable', { error: lookupResult.error }, deps.env)}\n`);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
}
|
|
120
|
+
const { names } = lookupResult;
|
|
121
|
+
const teamName = nameOf(names.teams, graph.teamId);
|
|
122
|
+
const projectName = nameOf(names.projects, graph.projectId);
|
|
123
|
+
const folderName = nameOf(names.folders, graph.folderId);
|
|
124
|
+
if (options.json === true) {
|
|
125
|
+
deps.stdout(`${JSON.stringify({
|
|
126
|
+
...serializeItem(graph),
|
|
127
|
+
teamName,
|
|
128
|
+
projectName,
|
|
129
|
+
folderName,
|
|
130
|
+
...(lastUsedAt === null ? {} : { lastUsedAt }),
|
|
131
|
+
}, null, 2)}\n`);
|
|
132
|
+
result = 0;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
renderCanvasDetail(ctx, graph, { teamName, projectName, folderName }, lastUsedAt);
|
|
136
|
+
result = 0;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
function renderCanvasDetail(ctx, graph, names, lastUsedAt) {
|
|
142
|
+
const { deps } = ctx;
|
|
143
|
+
const dash = style.dim('-');
|
|
144
|
+
const ref = (refId, name) => {
|
|
145
|
+
let refText;
|
|
146
|
+
if (refId === null) {
|
|
147
|
+
refText = dash;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
refText = name === null ? refId : `${sanitizeText(name)} ${style.dim(refId)}`;
|
|
151
|
+
}
|
|
152
|
+
return refText;
|
|
153
|
+
};
|
|
154
|
+
const rows = [
|
|
155
|
+
[t('canvas.field.id', {}, deps.env), graph.id],
|
|
156
|
+
[
|
|
157
|
+
t('canvas.field.name', {}, deps.env),
|
|
158
|
+
graph.name === '' ? style.dim(t('canvas.unnamed', {}, deps.env)) : sanitizeText(graph.name),
|
|
159
|
+
],
|
|
160
|
+
[t('canvas.field.type', {}, deps.env), graph.graphType],
|
|
161
|
+
[t('canvas.field.team', {}, deps.env), ref(graph.teamId, names.teamName)],
|
|
162
|
+
[t('canvas.field.project', {}, deps.env), ref(graph.projectId, names.projectName)],
|
|
163
|
+
[t('canvas.field.folder', {}, deps.env), ref(graph.folderId, names.folderName)],
|
|
164
|
+
[t('canvas.field.created', {}, deps.env), graph.createdAt ?? dash],
|
|
165
|
+
[t('canvas.field.updated', {}, deps.env), graph.updatedAt ?? dash],
|
|
166
|
+
];
|
|
167
|
+
if (lastUsedAt !== null) {
|
|
168
|
+
rows.push([
|
|
169
|
+
t('canvas.field.lastUsed', {}, deps.env),
|
|
170
|
+
`${formatTimestamp(lastUsedAt)} ${style.dim(`(${agoText(lastUsedAt, deps.clock(), deps.env)})`)}`,
|
|
171
|
+
]);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
}
|
|
175
|
+
deps.stdout(`${renderTable(rows)}\n`);
|
|
176
|
+
}
|
|
177
|
+
export async function canvasUrlCommand(ctx, id, options) {
|
|
178
|
+
const { deps } = ctx;
|
|
179
|
+
const canvasId = assertCanvasId(id, deps.env);
|
|
180
|
+
const loaded = await loadEnv(ctx);
|
|
181
|
+
const { config } = await resolveFlowCredential(ctx, loaded);
|
|
182
|
+
const full = buildCanvasUrl(config, ctx.entry, canvasId, deps.env);
|
|
183
|
+
const shown = options.raw === true ? full : maskUrlCredential(full);
|
|
184
|
+
if (options.json === true) {
|
|
185
|
+
deps.stdout(`${JSON.stringify({ id, url: shown }, null, 2)}\n`);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
deps.stdout(`${shown}\n`);
|
|
189
|
+
}
|
|
190
|
+
return 0;
|
|
191
|
+
}
|
|
192
|
+
export async function canvasDeleteCommand(ctx, ids, options) {
|
|
193
|
+
const { deps } = ctx;
|
|
194
|
+
const list = normalizeDeleteIds(ids, deps.env);
|
|
195
|
+
const env = await resolveEnvName(ctx.envFlag, deps, ctx.paths);
|
|
196
|
+
return withCanvasLock(ctx, env, async () => {
|
|
197
|
+
const { api } = await apiOf(ctx);
|
|
198
|
+
if (options.hard === true) {
|
|
199
|
+
await api.remove(list, { hard: false });
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
}
|
|
203
|
+
const result = await api.remove(list, { hard: options.hard === true });
|
|
204
|
+
let exitCode;
|
|
205
|
+
if (options.json === true) {
|
|
206
|
+
deps.stdout(`${JSON.stringify({ ids: list, hard: options.hard === true, ...result }, null, 2)}\n`);
|
|
207
|
+
exitCode = 0;
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
deps.stdout(`${style.ok('✓')} ${options.hard === true
|
|
211
|
+
? t('canvas.hardDeleted', { count: result.changed }, deps.env)
|
|
212
|
+
: t('canvas.softDeleted', { count: result.changed }, deps.env)}\n`);
|
|
213
|
+
await closeIfSessionCanvas(ctx, env, list, deps);
|
|
214
|
+
if (options.hard === true) {
|
|
215
|
+
deps.stdout(`${style.dim(` ${t('canvas.hardDeleteWarning', {}, deps.env)}`)}\n`);
|
|
216
|
+
}
|
|
217
|
+
else if (result.changed > 0) {
|
|
218
|
+
deps.stdout(`${style.dim(` ${t('canvas.softDeleteHint', {}, deps.env)}`)}\n`);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
}
|
|
222
|
+
exitCode = 0;
|
|
223
|
+
}
|
|
224
|
+
return exitCode;
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
async function closeIfSessionCanvas(ctx, env, ids, deps) {
|
|
228
|
+
const record = await readSessionRecord(ctx.paths.canvasSessionFile(env), deps);
|
|
229
|
+
if (record === null || !ids.includes(record.id))
|
|
230
|
+
return;
|
|
231
|
+
await closeCanvasSession(ctx, env);
|
|
232
|
+
deps.stdout(`${style.dim(` ${t('canvas.sessionClosed', { id: record.id }, deps.env)}`)}\n`);
|
|
233
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { CliError, errorMessage } from "../../../errors.js";
|
|
2
|
+
import { createTeamApi } from "../../../canvas/team.js";
|
|
3
|
+
import { collectNames } from "../../../canvas/names.js";
|
|
4
|
+
import { requireSpace } from "../../../canvas/entry.js";
|
|
5
|
+
import { PAGE_SIZE_LIMIT } from "../../../canvas/params.js";
|
|
6
|
+
import { parsePositiveInt } from "../../args.js";
|
|
7
|
+
import { formatTimestamp } from "../../elapsed.js";
|
|
8
|
+
import { renderTable, style } from "../../output.js";
|
|
9
|
+
import { hint } from "../../hints.js";
|
|
10
|
+
import { renderList, renderTeamList } from "./render.js";
|
|
11
|
+
import { sanitizeText } from "../../../text.js";
|
|
12
|
+
import { t } from "../../../i18n.js";
|
|
13
|
+
import { accountOf, apiOf, assertSpace, MAX_ALL_PAGES, requireAccountCredential, } from "./common.js";
|
|
14
|
+
async function teamOverview(ctx, config, flowToken) {
|
|
15
|
+
const credential = config.credential;
|
|
16
|
+
let result;
|
|
17
|
+
if (credential === null) {
|
|
18
|
+
result = {
|
|
19
|
+
teams: [],
|
|
20
|
+
error: t('canvas.teamsNoAccountCredential', { env: config.env }, ctx.deps.env),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
try {
|
|
25
|
+
const teams = await createTeamApi(ctx.deps, config, credential, flowToken).teams();
|
|
26
|
+
result = { teams, error: null };
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
result = { teams: [], error: errorMessage(err) };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
async function listAllPages(api, params) {
|
|
35
|
+
const items = [];
|
|
36
|
+
let total = 0;
|
|
37
|
+
for (let page = 1; page <= MAX_ALL_PAGES; page += 1) {
|
|
38
|
+
const chunk = await api.list({ ...params, page, pageSize: PAGE_SIZE_LIMIT });
|
|
39
|
+
total = chunk.total;
|
|
40
|
+
items.push(...chunk.items);
|
|
41
|
+
if (chunk.items.length < PAGE_SIZE_LIMIT || items.length >= total)
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
return { items, total };
|
|
45
|
+
}
|
|
46
|
+
export async function canvasListCommand(ctx, options) {
|
|
47
|
+
const { deps } = ctx;
|
|
48
|
+
assertSpace(ctx, options.project !== undefined ? options.project : options.team);
|
|
49
|
+
if (options.team !== undefined && options.project !== undefined) {
|
|
50
|
+
throw new CliError('usage', t('canvas.teamWithProject', {}, deps.env));
|
|
51
|
+
}
|
|
52
|
+
const { api, config, flowToken } = await apiOf(ctx);
|
|
53
|
+
const pageSize = options.pageSize === undefined
|
|
54
|
+
? 20
|
|
55
|
+
: parsePositiveInt(options.pageSize, '--page-size', deps.env);
|
|
56
|
+
if (pageSize > PAGE_SIZE_LIMIT) {
|
|
57
|
+
throw new CliError('usage', t('canvas.pageSizeTooLarge', { value: pageSize, limit: PAGE_SIZE_LIMIT }, deps.env));
|
|
58
|
+
}
|
|
59
|
+
let result;
|
|
60
|
+
if (options.team !== undefined) {
|
|
61
|
+
result = await listTeam(ctx, config, flowToken, options, pageSize);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const base = { projectId: options.project, keyword: options.keyword };
|
|
65
|
+
const last = await ctx.store.readLastCanvas(config.env);
|
|
66
|
+
const now = deps.clock();
|
|
67
|
+
const lookup = async (rows) => {
|
|
68
|
+
const names = await collectNames(deps, config, api, rows, accountOf(config, flowToken));
|
|
69
|
+
if (names.error !== null) {
|
|
70
|
+
deps.stderr(`${style.warn('!')} ${t('canvas.namesUnavailable', { error: names.error }, deps.env)}\n`);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
}
|
|
74
|
+
return names.names;
|
|
75
|
+
};
|
|
76
|
+
if (options.all === true) {
|
|
77
|
+
const { items, total } = await listAllPages(api, base);
|
|
78
|
+
result = await renderList(ctx, items, await lookup(items), { total, page: 1, pageSize: Math.max(1, items.length) }, options.json === true, options.project === undefined && options.keyword === undefined
|
|
79
|
+
? await teamOverview(ctx, config, flowToken)
|
|
80
|
+
: null, last, now);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const page = options.page === undefined ? 1 : parsePositiveInt(options.page, '--page', deps.env);
|
|
84
|
+
const pageResult = await api.list({ ...base, page, pageSize });
|
|
85
|
+
const overview = page === 1 && options.project === undefined && options.keyword === undefined
|
|
86
|
+
? await teamOverview(ctx, config, flowToken)
|
|
87
|
+
: null;
|
|
88
|
+
result = await renderList(ctx, pageResult.items, await lookup(pageResult.items), { total: pageResult.total, page, pageSize }, options.json === true, overview, last, now);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
async function listTeam(ctx, config, flowToken, options, pageSize) {
|
|
94
|
+
const { deps } = ctx;
|
|
95
|
+
const credential = requireAccountCredential(config, deps.env);
|
|
96
|
+
const teamApi = createTeamApi(deps, config, credential, flowToken);
|
|
97
|
+
const teamId = options.team;
|
|
98
|
+
const collected = [];
|
|
99
|
+
const projectNames = new Map();
|
|
100
|
+
let projectCount = 0;
|
|
101
|
+
for (let p = 1; p <= MAX_ALL_PAGES; p += 1) {
|
|
102
|
+
const chunk = await teamApi.canvases(teamId, p, PAGE_SIZE_LIMIT);
|
|
103
|
+
collected.push(...chunk.canvases);
|
|
104
|
+
projectCount += chunk.projects.length;
|
|
105
|
+
for (const project of chunk.projects)
|
|
106
|
+
projectNames.set(project.id, project.name);
|
|
107
|
+
if (p >= chunk.pages)
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
const page = options.page === undefined ? 1 : parsePositiveInt(options.page, '--page', deps.env);
|
|
111
|
+
const total = collected.length;
|
|
112
|
+
const pages = Math.max(1, Math.ceil(total / pageSize));
|
|
113
|
+
const visible = options.all === true ? collected : collected.slice((page - 1) * pageSize, page * pageSize);
|
|
114
|
+
let teamName = null;
|
|
115
|
+
try {
|
|
116
|
+
teamName = (await teamApi.teams()).find((x) => x.id === teamId)?.name ?? null;
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
teamName = null;
|
|
120
|
+
}
|
|
121
|
+
return renderTeamList(ctx, visible, {
|
|
122
|
+
total,
|
|
123
|
+
page: options.all === true ? 1 : page,
|
|
124
|
+
pages: options.all === true ? 1 : pages,
|
|
125
|
+
projectCount,
|
|
126
|
+
}, teamId, teamName, options.json === true, options.all === true, await ctx.store.readLastCanvas(config.env), deps.clock());
|
|
127
|
+
}
|
|
128
|
+
export async function canvasFolderListCommand(ctx, options) {
|
|
129
|
+
const { deps } = ctx;
|
|
130
|
+
requireSpace(ctx.entry, 'personal', deps.env);
|
|
131
|
+
const { api } = await apiOf(ctx);
|
|
132
|
+
const folders = await api.folders();
|
|
133
|
+
let result;
|
|
134
|
+
if (options.json === true) {
|
|
135
|
+
deps.stdout(`${JSON.stringify({ total: folders.length, items: folders }, null, 2)}\n`);
|
|
136
|
+
result = 0;
|
|
137
|
+
}
|
|
138
|
+
else if (folders.length === 0) {
|
|
139
|
+
deps.stdout(`${style.dim(t('canvas.folderEmpty', {}, deps.env))}\n`);
|
|
140
|
+
deps.stdout(`${style.dim(` ${t('canvas.folderEmptyHint', {}, deps.env)}`)}\n`);
|
|
141
|
+
result = 0;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const hasCount = folders.some((f) => f.canvasCount !== null);
|
|
145
|
+
const columns = [
|
|
146
|
+
['id', 'canvas.col.id'],
|
|
147
|
+
['name', 'canvas.col.name'],
|
|
148
|
+
['createdAt', 'canvas.col.createdAt'],
|
|
149
|
+
];
|
|
150
|
+
const header = columns.map(([, key]) => t(key, {}, deps.env));
|
|
151
|
+
if (hasCount) {
|
|
152
|
+
header.push(t('canvas.col.canvases', {}, deps.env));
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
}
|
|
156
|
+
const cells = folders.map((f) => [
|
|
157
|
+
f.id,
|
|
158
|
+
f.name === '' ? style.dim(t('canvas.unnamed', {}, deps.env)) : sanitizeText(f.name),
|
|
159
|
+
f.createdAt === null ? '' : formatTimestamp(f.createdAt),
|
|
160
|
+
...(hasCount ? [f.canvasCount === null ? '' : String(f.canvasCount)] : []),
|
|
161
|
+
]);
|
|
162
|
+
deps.stdout(`${style.bold(header.join(' '))}\n`);
|
|
163
|
+
deps.stdout(`${renderTable(cells)}\n`);
|
|
164
|
+
deps.stdout(`${style.dim(` ${t('canvas.folderCount', { count: folders.length }, deps.env)} · ${hint(ctx, 'canvas.folderHint', `canvas create <name> --folder <id>`)}`)}\n`);
|
|
165
|
+
result = 0;
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { t } from "../../../i18n.js";
|
|
2
|
+
import { runCommand } from "../../run.js";
|
|
3
|
+
import { canvasCloseCommand, canvasCreateCommand, canvasDeleteCommand, canvasFolderListCommand, canvasGetCommand, canvasListCommand, canvasProjectListCommand, canvasScreenshotCommand, canvasTeamListCommand, canvasUrlCommand, canvasUseCommand, } from "./index.js";
|
|
4
|
+
export function registerCanvas(program, deps, ctx) {
|
|
5
|
+
const canvas = program.command('canvas').description(t('cmd.canvas'));
|
|
6
|
+
addCanvasBrowse(canvas, deps, ctx);
|
|
7
|
+
addCanvasItem(canvas, deps, ctx);
|
|
8
|
+
}
|
|
9
|
+
function addCanvasBrowse(canvas, deps, ctx) {
|
|
10
|
+
canvas
|
|
11
|
+
.command('list')
|
|
12
|
+
.description(t('cmd.canvas.list'))
|
|
13
|
+
.option('--project <id>', t('opt.projectId'))
|
|
14
|
+
.option('--team <id>', t('opt.teamId'))
|
|
15
|
+
.option('--keyword <text>', t('opt.keyword'))
|
|
16
|
+
.option('--page <n>', t('opt.page'))
|
|
17
|
+
.option('--page-size <n>', t('opt.pageSize'))
|
|
18
|
+
.option('--all', t('opt.allPages'))
|
|
19
|
+
.option('--json', t('opt.json'))
|
|
20
|
+
.action(async (options) => {
|
|
21
|
+
process.exitCode = await runCommand(() => canvasListCommand(ctx(), options), deps);
|
|
22
|
+
});
|
|
23
|
+
const folder = canvas.command('folder').description(t('cmd.canvas.folder'));
|
|
24
|
+
folder
|
|
25
|
+
.command('list')
|
|
26
|
+
.description(t('cmd.canvas.folderList'))
|
|
27
|
+
.option('--json', t('opt.json'))
|
|
28
|
+
.action(async (options) => {
|
|
29
|
+
process.exitCode = await runCommand(() => canvasFolderListCommand(ctx(), options), deps);
|
|
30
|
+
});
|
|
31
|
+
const project = canvas.command('project').description(t('cmd.canvas.project'));
|
|
32
|
+
project
|
|
33
|
+
.command('list')
|
|
34
|
+
.description(t('cmd.canvas.projectList'))
|
|
35
|
+
.option('--team <id>', t('opt.teamId'))
|
|
36
|
+
.option('--json', t('opt.json'))
|
|
37
|
+
.action(async (options) => {
|
|
38
|
+
process.exitCode = await runCommand(() => canvasProjectListCommand(ctx(), options), deps);
|
|
39
|
+
});
|
|
40
|
+
const team = canvas.command('team').description(t('cmd.canvas.team'));
|
|
41
|
+
team
|
|
42
|
+
.command('list')
|
|
43
|
+
.description(t('cmd.canvas.teamList'))
|
|
44
|
+
.option('--json', t('opt.json'))
|
|
45
|
+
.action(async (options) => {
|
|
46
|
+
process.exitCode = await runCommand(() => canvasTeamListCommand(ctx(), options), deps);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function addCanvasItem(canvas, deps, ctx) {
|
|
50
|
+
canvas
|
|
51
|
+
.command('create <name>')
|
|
52
|
+
.description(t('cmd.canvas.create'))
|
|
53
|
+
.option('--project <id>', t('opt.projectId'))
|
|
54
|
+
.option('--folder <id>', t('opt.folderId'))
|
|
55
|
+
.option('--use', t('opt.useCanvas'))
|
|
56
|
+
.option('--json', t('opt.json'))
|
|
57
|
+
.action(async (name, options) => {
|
|
58
|
+
process.exitCode = await runCommand(() => canvasCreateCommand(ctx(), name, options), deps);
|
|
59
|
+
});
|
|
60
|
+
canvas
|
|
61
|
+
.command('get <id>')
|
|
62
|
+
.description(t('cmd.canvas.get'))
|
|
63
|
+
.option('--json', t('opt.json'))
|
|
64
|
+
.action(async (id, options) => {
|
|
65
|
+
process.exitCode = await runCommand(() => canvasGetCommand(ctx(), id, options), deps);
|
|
66
|
+
});
|
|
67
|
+
canvas
|
|
68
|
+
.command('use <id>')
|
|
69
|
+
.description(t('cmd.canvas.use'))
|
|
70
|
+
.option('--show', t('opt.canvasShow'))
|
|
71
|
+
.option('--json', t('opt.json'))
|
|
72
|
+
.action(async (id, options) => {
|
|
73
|
+
process.exitCode = await runCommand(() => canvasUseCommand(ctx(), id, options), deps);
|
|
74
|
+
});
|
|
75
|
+
canvas
|
|
76
|
+
.command('close')
|
|
77
|
+
.description(t('cmd.canvas.close'))
|
|
78
|
+
.option('--json', t('opt.json'))
|
|
79
|
+
.action(async (options) => {
|
|
80
|
+
process.exitCode = await runCommand(() => canvasCloseCommand(ctx(), options), deps);
|
|
81
|
+
});
|
|
82
|
+
canvas
|
|
83
|
+
.command('screenshot')
|
|
84
|
+
.description(t('cmd.canvas.screenshot'))
|
|
85
|
+
.option('--out <path>', t('opt.screenshotOut'))
|
|
86
|
+
.option('--json', t('opt.json'))
|
|
87
|
+
.action(async (options) => {
|
|
88
|
+
process.exitCode = await runCommand(() => canvasScreenshotCommand(ctx(), options), deps);
|
|
89
|
+
});
|
|
90
|
+
canvas
|
|
91
|
+
.command('url <id>')
|
|
92
|
+
.description(t('cmd.canvas.url'))
|
|
93
|
+
.option('--raw', t('opt.raw'))
|
|
94
|
+
.option('--json', t('opt.json'))
|
|
95
|
+
.action(async (id, options) => {
|
|
96
|
+
process.exitCode = await runCommand(() => canvasUrlCommand(ctx(), id, options), deps);
|
|
97
|
+
});
|
|
98
|
+
canvas
|
|
99
|
+
.command('delete <ids...>')
|
|
100
|
+
.description(t('cmd.canvas.delete'))
|
|
101
|
+
.option('--hard', t('opt.hardDelete'))
|
|
102
|
+
.option('--json', t('opt.json'))
|
|
103
|
+
.action(async (ids, options) => {
|
|
104
|
+
process.exitCode = await runCommand(() => canvasDeleteCommand(ctx(), ids, options), deps);
|
|
105
|
+
});
|
|
106
|
+
}
|