@deepdynamic/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 +201 -0
- package/README.md +32 -2
- package/THIRD_PARTY_NOTICES.txt +102 -0
- package/dist/agents/content.js +12 -0
- package/dist/agents/edit.js +140 -0
- package/dist/agents/install.js +180 -0
- package/dist/agents/setup.js +29 -0
- package/dist/agents/targets.js +91 -0
- package/dist/auth/credentials.js +63 -0
- package/dist/auth/session.js +49 -0
- package/dist/cli.js +198 -0
- package/dist/commands/account.js +96 -0
- package/dist/commands/activity.js +80 -0
- package/dist/commands/blocked.js +89 -0
- package/dist/commands/deploy/agents.js +11 -0
- package/dist/commands/deploy/files.js +62 -0
- package/dist/commands/deploy/index.js +95 -0
- package/dist/commands/deploy/manifest.js +24 -0
- package/dist/commands/deploy/minify.js +27 -0
- package/dist/commands/deploy/progress.js +85 -0
- package/dist/commands/deploy/ship.js +117 -0
- package/dist/commands/deploy/upload.js +125 -0
- package/dist/commands/deployments.js +59 -0
- package/dist/commands/dns.js +791 -0
- package/dist/commands/domains.js +711 -0
- package/dist/commands/emails.js +74 -0
- package/dist/commands/env.js +194 -0
- package/dist/commands/help.js +149 -0
- package/dist/commands/keys.js +269 -0
- package/dist/commands/login/flow.js +155 -0
- package/dist/commands/login/index.js +26 -0
- package/dist/commands/logout.js +71 -0
- package/dist/commands/mail.js +241 -0
- package/dist/commands/notifications.js +132 -0
- package/dist/commands/plan.js +371 -0
- package/dist/commands/projects.js +836 -0
- package/dist/commands/reference.js +2180 -0
- package/dist/commands/search.js +75 -0
- package/dist/commands/server.js +314 -0
- package/dist/commands/sessions.js +120 -0
- package/dist/commands/sites.js +102 -0
- package/dist/commands/sms.js +65 -0
- package/dist/commands/status.js +87 -0
- package/dist/commands/support.js +115 -0
- package/dist/commands/update.js +98 -0
- package/dist/commands/usage.js +51 -0
- package/dist/commands/verify.js +149 -0
- package/dist/commands/version.js +6 -0
- package/dist/guide.js +76 -0
- package/dist/http/call.js +6 -0
- package/dist/http/request.js +54 -0
- package/dist/index.js +11 -0
- package/dist/metadata.js +4 -0
- package/dist/output.js +9 -0
- package/dist/pretty.js +70 -0
- package/dist/registry.js +760 -0
- package/dist/runtime/browser.js +15 -0
- package/dist/runtime/card-request.js +55 -0
- package/dist/runtime/confirm.js +21 -0
- package/dist/runtime/development.js +13 -0
- package/dist/runtime/domain-name.js +5 -0
- package/dist/runtime/dry-run.js +28 -0
- package/dist/runtime/env-file.js +58 -0
- package/dist/runtime/error-hints.js +26 -0
- package/dist/runtime/flags.js +50 -0
- package/dist/runtime/login-screen.js +78 -0
- package/dist/runtime/page.js +18 -0
- package/dist/runtime/project-name.js +1 -0
- package/dist/runtime/run-mode.js +7 -0
- package/dist/runtime/server-options.js +32 -0
- package/dist/runtime/spinner.js +15 -0
- package/dist/runtime/suggest.js +22 -0
- package/dist/runtime/support.js +14 -0
- package/dist/runtime/text-file.js +20 -0
- package/dist/runtime/timeout.js +22 -0
- package/dist/runtime/update-check.js +124 -0
- package/dist/runtime/update-install.js +50 -0
- package/dist/runtime/usage-error.js +9 -0
- package/dist/setup-agents.js +8 -0
- package/dist/site.js +1 -0
- package/dist/update-refresh.js +5 -0
- package/package.json +46 -3
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsonLine } from "../output.js";
|
|
2
|
+
import { MCP_URL, NAME } from "./content.js";
|
|
3
|
+
import { installAgentFiles } from "./install.js";
|
|
4
|
+
const COMMAND = 'agents-setup';
|
|
5
|
+
const label = ({ agent, item, code, path, command, detail }) => `- ${agent} ${item}: ${code}${path ? ` (${path})` : command ? ` (${command})` : ''}${detail ? ` ${detail.split('\n')[0]}` : ''}`;
|
|
6
|
+
export async function runAgentSetup(env, commands, uid) {
|
|
7
|
+
if (uid === 0 && env.vars.SUDO_USER) {
|
|
8
|
+
return {
|
|
9
|
+
code: 0,
|
|
10
|
+
stdout: jsonLine({ ok: true, command: COMMAND, agents: [], outcomes: [], warning: { code: 'sudo_skipped', message: 'Run the install script again without sudo to add the agent settings.' } }),
|
|
11
|
+
stderr: '에이전트 설정을 건너뛰었습니다. sudo 로 실행되어 사용자 홈의 설정 파일을 건드리지 않았습니다. sudo 없이 설치 스크립트를 다시 실행하면 넣습니다.\n'
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const outcomes = await installAgentFiles(env, commands);
|
|
15
|
+
const agents = [...new Set(outcomes.map(({ agent }) => agent))];
|
|
16
|
+
const failed = outcomes.filter(({ status }) => status === 'failed');
|
|
17
|
+
const lines = !agents.length
|
|
18
|
+
? ['설정 폴더가 있는 AI 에이전트를 찾지 못해 에이전트 설정은 넣지 않았습니다.']
|
|
19
|
+
: [
|
|
20
|
+
`에이전트 설정을 넣었습니다: ${agents.join(', ')} (스킬 ${NAME}, 전역 지침, MCP ${MCP_URL})`,
|
|
21
|
+
...(failed.length ? ['일부 항목은 넣지 못했습니다. CLI 는 설치되어 그대로 쓸 수 있습니다.', ...failed.map(label)] : []),
|
|
22
|
+
'새 스킬과 MCP 는 에이전트를 다시 시작하면 보입니다.'
|
|
23
|
+
];
|
|
24
|
+
return {
|
|
25
|
+
code: 0,
|
|
26
|
+
stdout: jsonLine({ ok: true, command: COMMAND, agents, outcomes, ...(failed.length ? { warning: { code: 'agent_setup_partial', failed: failed.length } } : {}) }),
|
|
27
|
+
stderr: `${lines.join('\n')}\n`
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { isAbsolute, join } from 'node:path';
|
|
2
|
+
import { MCP_URL, NAME } from "./content.js";
|
|
3
|
+
const absolute = (value) => (value && isAbsolute(value) ? value : undefined);
|
|
4
|
+
const json = (files, path, value, seed) => ({ kind: 'json', files, path, value, ...(seed ? { seed } : {}) });
|
|
5
|
+
const servers = (file, value) => json([file], ['mcpServers', NAME], value);
|
|
6
|
+
export function agentTargets({ home, platform, vars }) {
|
|
7
|
+
const config = absolute(vars.XDG_CONFIG_HOME) ?? join(home, '.config');
|
|
8
|
+
const shared = join(home, '.agents', 'skills');
|
|
9
|
+
const claude = absolute(vars.CLAUDE_CONFIG_DIR) ?? join(home, '.claude');
|
|
10
|
+
const codex = absolute(vars.CODEX_HOME) ?? join(home, '.codex');
|
|
11
|
+
const geminiBase = absolute(vars.GEMINI_CLI_HOME) ?? home;
|
|
12
|
+
const gemini = join(geminiBase, '.gemini');
|
|
13
|
+
const cursor = join(home, '.cursor');
|
|
14
|
+
const copilot = absolute(vars.COPILOT_HOME) ?? join(home, '.copilot');
|
|
15
|
+
const windsurf = join(home, '.codeium', 'windsurf');
|
|
16
|
+
const devin = platform === 'win32' && absolute(vars.APPDATA) ? join(vars.APPDATA, 'devin') : join(config, 'devin');
|
|
17
|
+
const opencode = join(config, 'opencode');
|
|
18
|
+
const crush = absolute(vars.CRUSH_GLOBAL_CONFIG) ?? join(config, 'crush');
|
|
19
|
+
const amp = join(home, '.config', 'amp');
|
|
20
|
+
const kiro = absolute(vars.KIRO_HOME) ?? join(home, '.kiro');
|
|
21
|
+
const gooseRoot = absolute(vars.GOOSE_PATH_ROOT);
|
|
22
|
+
const goose = gooseRoot ? join(gooseRoot, 'config') : platform === 'win32' && absolute(vars.APPDATA) ? join(vars.APPDATA, 'Block', 'goose', 'config') : join(home, '.config', 'goose');
|
|
23
|
+
const qwen = absolute(vars.QWEN_HOME) ?? join(home, '.qwen');
|
|
24
|
+
const command = (name, remove, add, fallback) => ({ kind: 'command', command: name, remove, add, fallback });
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
id: 'claude-code', dir: claude, skills: [join(claude, 'skills')],
|
|
28
|
+
instructions: { kind: 'file', file: join(claude, 'rules', `${NAME}.md`) },
|
|
29
|
+
mcp: command('claude', ['mcp', 'remove', NAME, '--scope', 'user'], ['mcp', 'add', '--transport', 'http', '--scope', 'user', NAME, MCP_URL], null)
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: 'codex', dir: codex, skills: [shared],
|
|
33
|
+
instructions: { kind: 'block', file: join(codex, 'AGENTS.md') },
|
|
34
|
+
mcp: { kind: 'toml', file: join(codex, 'config.toml') }
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: 'gemini-cli', dir: gemini, skills: [join(geminiBase, '.agents', 'skills')],
|
|
38
|
+
instructions: { kind: 'block', file: join(gemini, 'GEMINI.md') },
|
|
39
|
+
mcp: command('gemini', ['mcp', 'remove', '--scope', 'user', NAME], ['mcp', 'add', '--scope', 'user', '--transport', 'http', NAME, MCP_URL], servers(join(gemini, 'settings.json'), { httpUrl: MCP_URL }))
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'cursor', dir: cursor, skills: [shared], instructions: null,
|
|
43
|
+
mcp: servers(join(cursor, 'mcp.json'), { url: MCP_URL })
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 'copilot-cli', dir: copilot, skills: [shared],
|
|
47
|
+
instructions: { kind: 'block', file: join(copilot, 'copilot-instructions.md') },
|
|
48
|
+
mcp: command('copilot', ['mcp', 'remove', NAME], ['mcp', 'add', '--transport', 'http', NAME, MCP_URL], servers(join(copilot, 'mcp-config.json'), { type: 'http', url: MCP_URL, tools: ['*'] }))
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 'windsurf', dir: windsurf, skills: [shared],
|
|
52
|
+
instructions: { kind: 'block', file: join(windsurf, 'memories', 'global_rules.md') },
|
|
53
|
+
mcp: servers(join(windsurf, 'mcp_config.json'), { serverUrl: MCP_URL })
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: 'devin', dir: devin, skills: [shared],
|
|
57
|
+
instructions: { kind: 'block', file: join(devin, 'AGENTS.md') },
|
|
58
|
+
mcp: command('devin', ['mcp', 'remove', NAME], ['mcp', 'add', '-s', 'user', NAME, MCP_URL], servers(join(devin, 'mcp_config.json'), { url: MCP_URL, transport: 'http' }))
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: 'opencode', dir: opencode, skills: [shared],
|
|
62
|
+
instructions: { kind: 'opencode', file: join(opencode, `${NAME}.md`), settings: [join(opencode, 'opencode.json'), join(opencode, 'opencode.jsonc')] },
|
|
63
|
+
mcp: { kind: 'opencode', files: [join(opencode, 'opencode.json'), join(opencode, 'opencode.jsonc')] }
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'crush', dir: crush, skills: [absolute(vars.CRUSH_SKILLS_DIR) ?? shared],
|
|
67
|
+
instructions: { kind: 'block', file: join(crush, 'CRUSH.md') },
|
|
68
|
+
mcp: { kind: 'crush', rc: join(crush, 'crushrc'), settings: json([join(crush, 'crush.json')], ['mcp', NAME], { type: 'http', url: MCP_URL }, '{\n "$schema": "https://charm.land/crush.json"\n}') }
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 'amp', dir: amp, skills: [shared],
|
|
72
|
+
instructions: { kind: 'block', file: join(amp, 'AGENTS.md') },
|
|
73
|
+
mcp: { kind: 'amp', command: 'amp', add: ['mcp', 'add', NAME, MCP_URL], settings: json([join(amp, 'settings.json'), join(amp, 'settings.jsonc')], ['amp.mcpServers', NAME], { url: MCP_URL }) }
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: 'kiro', dir: kiro, skills: [join(kiro, 'skills')],
|
|
77
|
+
instructions: { kind: 'file', file: join(kiro, 'steering', `${NAME}.md`) },
|
|
78
|
+
mcp: servers(join(kiro, 'settings', 'mcp.json'), { url: MCP_URL })
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: 'goose', dir: goose, skills: [shared],
|
|
82
|
+
instructions: { kind: 'block', file: join(goose, '.goosehints') },
|
|
83
|
+
mcp: { kind: 'yaml', file: join(goose, 'config.yaml') }
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: 'qwen-code', dir: qwen, skills: [shared],
|
|
87
|
+
instructions: { kind: 'block', file: join(qwen, 'QWEN.md') },
|
|
88
|
+
mcp: command('qwen', ['mcp', 'remove', NAME], ['mcp', 'add', '--scope', 'user', '--transport', 'http', NAME, MCP_URL], servers(join(qwen, 'settings.json'), { httpUrl: MCP_URL }))
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { chmod, mkdir, readFile, realpath, rm, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { dirname, join, win32 } from 'node:path';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import { allowedServer } from "../runtime/run-mode.js";
|
|
7
|
+
const run = promisify(execFile);
|
|
8
|
+
const system32 = (program) => win32.join(process.env.SystemRoot || 'C:\\Windows', 'System32', program);
|
|
9
|
+
let userSid;
|
|
10
|
+
const currentUserSid = () => userSid ??= run(system32('whoami.exe'), ['/user', '/fo', 'csv', '/nh'], { windowsHide: true })
|
|
11
|
+
.then(({ stdout }) => /"(S-1-[0-9-]+)"\s*$/.exec(stdout.trim())?.[1] ?? null, () => null);
|
|
12
|
+
async function restrictToOwner(directory) {
|
|
13
|
+
if (process.platform !== 'win32')
|
|
14
|
+
return;
|
|
15
|
+
const sid = await currentUserSid();
|
|
16
|
+
if (sid)
|
|
17
|
+
await run(system32('icacls.exe'), [win32.toNamespacedPath(await realpath(directory)), '/inheritance:r', '/grant:r', `*${sid}:(OI)(CI)F`], { windowsHide: true }).catch(() => { });
|
|
18
|
+
}
|
|
19
|
+
export function credentialsPath(env = process.env, home = homedir()) {
|
|
20
|
+
return join(env.XDG_CONFIG_HOME || join(home, '.config'), 'deepdynamic', env.DEEPDYNAMIC_DEVELOPMENT ? 'credentials.local.json' : 'credentials.json');
|
|
21
|
+
}
|
|
22
|
+
export async function readAccountEmail(path = credentialsPath()) {
|
|
23
|
+
try {
|
|
24
|
+
const credentials = JSON.parse(await readFile(path, 'utf8'));
|
|
25
|
+
return typeof credentials?.email === 'string' ? credentials.email : null;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export async function readAccessToken(path = credentialsPath()) {
|
|
32
|
+
try {
|
|
33
|
+
const credentials = JSON.parse(await readFile(path, 'utf8'));
|
|
34
|
+
return typeof credentials?.accessToken === 'string' && credentials.accessToken ? credentials.accessToken : null;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export async function readLoginSiteUrl(path = credentialsPath()) {
|
|
41
|
+
try {
|
|
42
|
+
const credentials = JSON.parse(await readFile(path, 'utf8'));
|
|
43
|
+
const url = typeof credentials?.siteUrl === 'string' ? new URL(credentials.siteUrl) : null;
|
|
44
|
+
return url && (url.protocol === 'http:' || url.protocol === 'https:') && allowedServer(url.origin) ? url.origin : null;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export async function saveCredentials(credentials, path = credentialsPath()) {
|
|
51
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
52
|
+
await restrictToOwner(dirname(path));
|
|
53
|
+
const existing = await stat(path).catch(() => null);
|
|
54
|
+
if (existing?.isFile())
|
|
55
|
+
await chmod(path, existing.mode & 0o600);
|
|
56
|
+
await writeFile(path, `${JSON.stringify(credentials, null, 2)}\n`, { mode: 0o600 });
|
|
57
|
+
await chmod(path, 0o600);
|
|
58
|
+
return path;
|
|
59
|
+
}
|
|
60
|
+
export async function removeCredentials(path = credentialsPath()) {
|
|
61
|
+
await rm(path, { force: true });
|
|
62
|
+
return path;
|
|
63
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { defaultLoginDeps, login } from "../commands/login/flow.js";
|
|
2
|
+
import { defaultDeps, request } from "../http/request.js";
|
|
3
|
+
import { SITE_URL } from "../metadata.js";
|
|
4
|
+
import { LOCAL_SITE_URL } from "../runtime/development.js";
|
|
5
|
+
import { developmentRun } from "../runtime/run-mode.js";
|
|
6
|
+
import { readAccessToken, readLoginSiteUrl } from "./credentials.js";
|
|
7
|
+
export const CAPTAIN_MODE_TIMEOUT_MS = 5_000;
|
|
8
|
+
export const defaultAuthDeps = (pretty, depth, loginDeps) => ({
|
|
9
|
+
...defaultDeps(),
|
|
10
|
+
signIn: (siteUrl) => login({ ...(loginDeps ?? defaultLoginDeps()), siteUrl }, pretty, depth)
|
|
11
|
+
});
|
|
12
|
+
export async function loginSiteUrl() {
|
|
13
|
+
return await readLoginSiteUrl() ?? (developmentRun() ? LOCAL_SITE_URL : SITE_URL);
|
|
14
|
+
}
|
|
15
|
+
export async function fetchCaptainMode(deps = { ...defaultDeps(), timeoutMs: CAPTAIN_MODE_TIMEOUT_MS }) {
|
|
16
|
+
const token = await readAccessToken();
|
|
17
|
+
if (!token)
|
|
18
|
+
return null;
|
|
19
|
+
const result = await request(new URL('/api/v1/me', await loginSiteUrl()).href, {
|
|
20
|
+
method: 'GET',
|
|
21
|
+
headers: { authorization: `Bearer ${token}` }
|
|
22
|
+
}, deps, null);
|
|
23
|
+
if ('failure' in result || result.status !== 200)
|
|
24
|
+
return null;
|
|
25
|
+
const enabled = result.body?.user?.captainMode;
|
|
26
|
+
return typeof enabled === 'boolean' ? enabled : null;
|
|
27
|
+
}
|
|
28
|
+
export async function signedIn(deps, renew = false) {
|
|
29
|
+
const saved = renew ? null : await readAccessToken();
|
|
30
|
+
if (saved)
|
|
31
|
+
return { token: saved, siteUrl: await loginSiteUrl() };
|
|
32
|
+
const result = await deps.signIn(await loginSiteUrl());
|
|
33
|
+
const token = result.code === 0 ? await readAccessToken() : null;
|
|
34
|
+
return token ? { token, siteUrl: await loginSiteUrl() } : { login: result };
|
|
35
|
+
}
|
|
36
|
+
export async function authorized(deps, send) {
|
|
37
|
+
let session = await signedIn(deps);
|
|
38
|
+
if ('login' in session)
|
|
39
|
+
return session;
|
|
40
|
+
let result = await send(session);
|
|
41
|
+
if (!('failure' in result) && result.status === 401) {
|
|
42
|
+
const renewed = await signedIn(deps, true);
|
|
43
|
+
if ('login' in renewed)
|
|
44
|
+
return renewed;
|
|
45
|
+
session = renewed;
|
|
46
|
+
result = await send(session);
|
|
47
|
+
}
|
|
48
|
+
return { session, result };
|
|
49
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { readAccountEmail } from "./auth/credentials.js";
|
|
2
|
+
import { defaultAuthDeps } from "./auth/session.js";
|
|
3
|
+
import { runAccountDelete, runAccountGet } from "./commands/account.js";
|
|
4
|
+
import { runActivity } from "./commands/activity.js";
|
|
5
|
+
import { runBlocked } from "./commands/blocked.js";
|
|
6
|
+
import { runDeploy } from "./commands/deploy/index.js";
|
|
7
|
+
import { restoreDeployment, uploadDeployment } from "./commands/deploy/upload.js";
|
|
8
|
+
import { runDeployments } from "./commands/deployments.js";
|
|
9
|
+
import { runDnsAdd, runDnsAnalytics, runDnsDelete, runDnsDnssec, runDnsGoogle, runDnsList, runDnsRecords, runDnsRestore, runDnsSync, runDnsUpdate } from "./commands/dns.js";
|
|
10
|
+
import { runDomainsAutoRenew, runDomainsBuy, runDomainsList, runDomainsRegister, runDomainsRemove, runDomainsSearch, runDomainsTlds, runDomainsVerify } from "./commands/domains.js";
|
|
11
|
+
import { runEmailSend } from "./commands/emails.js";
|
|
12
|
+
import { runEnvClear, runEnvList, runEnvPush } from "./commands/env.js";
|
|
13
|
+
import { CLI_PRETTY_USAGE, CLI_USAGE, runCommandHelp, runCommands, runHelp } from "./commands/help.js";
|
|
14
|
+
import { runKeysCreate, runKeysIssue, runKeysList, runKeysRevoke } from "./commands/keys.js";
|
|
15
|
+
import { defaultLoginDeps, LOGIN_TIMEOUT_MS } from "./commands/login/flow.js";
|
|
16
|
+
import { runLogin } from "./commands/login/index.js";
|
|
17
|
+
import { runLogout } from "./commands/logout.js";
|
|
18
|
+
import { runMailList, runMailReset, runMailSet, runMailShow } from "./commands/mail.js";
|
|
19
|
+
import { runNotificationsList, runNotificationsRead } from "./commands/notifications.js";
|
|
20
|
+
import { writeFile } from 'node:fs/promises';
|
|
21
|
+
import { runProjectsCreate, runProjectsDelete, runProjectsHistory, runProjectsList, runProjectsMetric, runProjectsPhotocard, runProjectsPwa, runProjectsRename, runProjectsRollback, runProjectsStatus, runProjectsStop } from "./commands/projects.js";
|
|
22
|
+
import { runPlanCancel, runPlanPay, runPlanResume, runPlanShow, runPlanSubscribe } from "./commands/plan.js";
|
|
23
|
+
import { runSearch } from "./commands/search.js";
|
|
24
|
+
import { runServerAutopilot, runServerList, runServerSet } from "./commands/server.js";
|
|
25
|
+
import { runSessionsList, runSessionsRevoke } from "./commands/sessions.js";
|
|
26
|
+
import { runSites } from "./commands/sites.js";
|
|
27
|
+
import { runSmsSend } from "./commands/sms.js";
|
|
28
|
+
import { runStatus } from "./commands/status.js";
|
|
29
|
+
import { runVerify } from "./commands/verify.js";
|
|
30
|
+
import { runContact, runQa } from "./commands/support.js";
|
|
31
|
+
import { runUpdate } from "./commands/update.js";
|
|
32
|
+
import { runUsage } from "./commands/usage.js";
|
|
33
|
+
import { runVersion } from "./commands/version.js";
|
|
34
|
+
import { agentResult } from "./output.js";
|
|
35
|
+
import { prettyResult, renderBanner, renderWordmark } from "./pretty.js";
|
|
36
|
+
import { commands } from "./registry.js";
|
|
37
|
+
import { closest } from "./runtime/suggest.js";
|
|
38
|
+
import { LOGIN_TIMEOUT_OPTION, parseTimeout } from "./runtime/timeout.js";
|
|
39
|
+
import { updateLine } from "./runtime/update-check.js";
|
|
40
|
+
const NAMES = commands.map(({ name }) => name);
|
|
41
|
+
const TOP_COMMANDS = [...new Set(NAMES.map((name) => name.split(' ')[0]))];
|
|
42
|
+
const TOP_OPTIONS = ['-h', '--help', '-v', '--version', '--pretty', LOGIN_TIMEOUT_OPTION];
|
|
43
|
+
const withDeps = (run) => (args, pretty, depth, { deps }) => run(args, pretty, depth, deps);
|
|
44
|
+
const actions = {
|
|
45
|
+
login: (args, pretty, depth, { loginDeps }) => runLogin(args, pretty, depth, loginDeps),
|
|
46
|
+
logout: withDeps(runLogout),
|
|
47
|
+
'account get': (args, pretty, depth) => runAccountGet(args, pretty, depth),
|
|
48
|
+
'account activity': withDeps(runActivity),
|
|
49
|
+
'account notifications': withDeps(runNotificationsList),
|
|
50
|
+
'account notifications read': withDeps(runNotificationsRead),
|
|
51
|
+
'account delete': withDeps(runAccountDelete),
|
|
52
|
+
'system status': (args, pretty, depth) => runStatus(args, pretty, depth),
|
|
53
|
+
verify: (args, pretty, depth) => runVerify(args, pretty, depth),
|
|
54
|
+
help: (args, pretty, depth, { version }) => runHelp(args, version, depth, pretty),
|
|
55
|
+
commands: (args, pretty, depth, { version }) => runCommands(args, version, depth, pretty),
|
|
56
|
+
update: (args, pretty, depth, { version }) => runUpdate(args, version, pretty, depth),
|
|
57
|
+
sites: (args, pretty, depth) => runSites(args, pretty, depth),
|
|
58
|
+
'sites blocked': withDeps(runBlocked),
|
|
59
|
+
search: (args, pretty, depth) => runSearch(args, pretty, depth),
|
|
60
|
+
'support qa': withDeps(runQa),
|
|
61
|
+
'support contact': withDeps(runContact),
|
|
62
|
+
'emails send': withDeps(runEmailSend),
|
|
63
|
+
'sms send': withDeps(runSmsSend),
|
|
64
|
+
projects: withDeps(runProjectsList),
|
|
65
|
+
'projects create': withDeps(runProjectsCreate),
|
|
66
|
+
'projects status': withDeps(runProjectsStatus),
|
|
67
|
+
'projects metric': withDeps(runProjectsMetric),
|
|
68
|
+
'projects photocard': (args, pretty, depth, { deps }) => runProjectsPhotocard(args, pretty, depth, { ...deps, writeFile: (path, bytes) => writeFile(path, bytes) }),
|
|
69
|
+
'projects deploy': (args, pretty, depth, { deps }) => runDeploy(args, pretty, depth, { ...deps, upload: uploadDeployment }),
|
|
70
|
+
'projects env push': withDeps(runEnvPush),
|
|
71
|
+
'projects env list': withDeps(runEnvList),
|
|
72
|
+
'projects env clear': withDeps(runEnvClear),
|
|
73
|
+
deployments: withDeps(runDeployments),
|
|
74
|
+
'projects history': withDeps(runProjectsHistory),
|
|
75
|
+
'projects rollback': (args, pretty, depth, { deps }) => runProjectsRollback(args, pretty, depth, { ...deps, restore: restoreDeployment }),
|
|
76
|
+
'projects rename': withDeps(runProjectsRename),
|
|
77
|
+
'projects pwa': withDeps(runProjectsPwa),
|
|
78
|
+
'projects stop': withDeps(runProjectsStop),
|
|
79
|
+
'projects delete': withDeps(runProjectsDelete),
|
|
80
|
+
domains: withDeps(runDomainsList),
|
|
81
|
+
'domains search': withDeps(runDomainsSearch),
|
|
82
|
+
'domains tlds': withDeps(runDomainsTlds),
|
|
83
|
+
'domains buy': withDeps(runDomainsBuy),
|
|
84
|
+
'domains register': withDeps(runDomainsRegister),
|
|
85
|
+
'domains verify': withDeps(runDomainsVerify),
|
|
86
|
+
'domains remove': withDeps(runDomainsRemove),
|
|
87
|
+
'domains auto-renew': withDeps(runDomainsAutoRenew),
|
|
88
|
+
dns: withDeps(runDnsList),
|
|
89
|
+
'dns records': withDeps(runDnsRecords),
|
|
90
|
+
'dns add': withDeps(runDnsAdd),
|
|
91
|
+
'dns update': withDeps(runDnsUpdate),
|
|
92
|
+
'dns delete': withDeps(runDnsDelete),
|
|
93
|
+
'dns restore': withDeps(runDnsRestore),
|
|
94
|
+
'dns sync': withDeps(runDnsSync),
|
|
95
|
+
'dns dnssec': withDeps(runDnsDnssec),
|
|
96
|
+
'dns google': withDeps(runDnsGoogle),
|
|
97
|
+
'dns analytics': withDeps(runDnsAnalytics),
|
|
98
|
+
server: withDeps(runServerList),
|
|
99
|
+
'server set': withDeps(runServerSet),
|
|
100
|
+
'server autopilot': withDeps(runServerAutopilot),
|
|
101
|
+
plan: withDeps(runPlanShow),
|
|
102
|
+
'plan subscribe': withDeps(runPlanSubscribe),
|
|
103
|
+
'plan cancel': withDeps(runPlanCancel),
|
|
104
|
+
'plan resume': withDeps(runPlanResume),
|
|
105
|
+
'plan pay': withDeps(runPlanPay),
|
|
106
|
+
usage: withDeps(runUsage),
|
|
107
|
+
keys: withDeps(runKeysList),
|
|
108
|
+
'keys issue': withDeps(runKeysIssue),
|
|
109
|
+
'keys create': withDeps(runKeysCreate),
|
|
110
|
+
'keys revoke': withDeps(runKeysRevoke),
|
|
111
|
+
sessions: withDeps(runSessionsList),
|
|
112
|
+
'sessions revoke': withDeps(runSessionsRevoke),
|
|
113
|
+
mail: withDeps(runMailList),
|
|
114
|
+
'mail show': withDeps(runMailShow),
|
|
115
|
+
'mail set': withDeps(runMailSet),
|
|
116
|
+
'mail reset': withDeps(runMailReset)
|
|
117
|
+
};
|
|
118
|
+
const isName = (name) => NAMES.includes(name);
|
|
119
|
+
export async function run(args, version, depth, loginDeps, update = null) {
|
|
120
|
+
const pretty = args.includes('--pretty');
|
|
121
|
+
const commandArgs = args.filter((arg) => arg !== '--pretty');
|
|
122
|
+
const timeout = parseTimeout(commandArgs, LOGIN_TIMEOUT_MS / 1000, pretty, LOGIN_TIMEOUT_OPTION, 1);
|
|
123
|
+
const result = 'error' in timeout
|
|
124
|
+
? pretty
|
|
125
|
+
? prettyResult(2, depth, LOGIN_TIMEOUT_OPTION, timeout.error, [['사용법', CLI_PRETTY_USAGE]])
|
|
126
|
+
: agentResult(2, { error: { code: 'invalid_arguments', message: timeout.error }, usage: CLI_USAGE })
|
|
127
|
+
: await dispatch(timeout.rest, version, depth, pretty, timeout.rest.length < commandArgs.length ? { ...(loginDeps ?? defaultLoginDeps()), timeoutMs: timeout.waitMs } : loginDeps);
|
|
128
|
+
const notice = update?.event === 'update_available' && !('error' in timeout) && timeout.rest[0] === 'update' ? null : update;
|
|
129
|
+
if (!pretty)
|
|
130
|
+
return notice ? { ...result, stderr: result.stderr + updateLine(version, notice) } : result;
|
|
131
|
+
const wordmark = !('error' in timeout) && isHome(timeout.rest) ? renderWordmark(depth) : '';
|
|
132
|
+
return { ...result, stdout: wordmark + renderBanner(version, depth, await readAccountEmail(), notice) + result.stdout };
|
|
133
|
+
}
|
|
134
|
+
function isHome([input, ...rest]) {
|
|
135
|
+
return input === undefined || input === '-h' || input === '--help' || (input === 'help' && rest.length === 0);
|
|
136
|
+
}
|
|
137
|
+
function unknownSubcommand(group, action, pretty, depth) {
|
|
138
|
+
const members = commands.filter(({ name }) => name === group || name.startsWith(`${group} `));
|
|
139
|
+
const subcommands = members.filter(({ name }) => name !== group).map(({ name }) => name.slice(group.length + 1));
|
|
140
|
+
const suggestion = action === undefined ? null : closest(action, subcommands);
|
|
141
|
+
return pretty
|
|
142
|
+
? prettyResult(2, depth, group, action === undefined ? '하위 명령을 지정하세요.' : `알 수 없는 하위 명령입니다: ${action}`, [
|
|
143
|
+
['사용법', members.map(({ prettyUsage }) => prettyUsage).join(' | ')], ...(suggestion ? [['혹시', `deepdynamic ${group} ${suggestion}`]] : [])
|
|
144
|
+
])
|
|
145
|
+
: agentResult(2, {
|
|
146
|
+
command: group,
|
|
147
|
+
error: { code: 'unknown_subcommand', message: action === undefined ? 'A subcommand is required.' : `Unknown subcommand: ${action}` },
|
|
148
|
+
...(suggestion ? { suggestions: [suggestion] } : {}),
|
|
149
|
+
subcommands,
|
|
150
|
+
usage: members.map(({ usage }) => usage).join(' | ')
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async function dispatch(commandArgs, version, depth, pretty, loginDeps) {
|
|
154
|
+
const [input, action, subaction] = commandArgs;
|
|
155
|
+
const context = { deps: defaultAuthDeps(pretty, depth, loginDeps), loginDeps, version };
|
|
156
|
+
if (input === undefined || input === '-h' || input === '--help') {
|
|
157
|
+
return runHelp([], version, depth, pretty);
|
|
158
|
+
}
|
|
159
|
+
const commandHelp = runCommandHelp(commandArgs, pretty, depth);
|
|
160
|
+
if (commandHelp) {
|
|
161
|
+
return commandHelp;
|
|
162
|
+
}
|
|
163
|
+
if (input === '-v' || input === '--version') {
|
|
164
|
+
return runVersion(version, pretty);
|
|
165
|
+
}
|
|
166
|
+
const pair = `${input} ${action}`;
|
|
167
|
+
const triple = `${pair} ${subaction}`;
|
|
168
|
+
if (subaction !== undefined && isName(triple)) {
|
|
169
|
+
return actions[triple](commandArgs.slice(3), pretty, depth, context);
|
|
170
|
+
}
|
|
171
|
+
if (action !== undefined && isName(pair)) {
|
|
172
|
+
return actions[pair](commandArgs.slice(2), pretty, depth, context);
|
|
173
|
+
}
|
|
174
|
+
if (action !== undefined && NAMES.some((name) => name.startsWith(`${pair} `))) {
|
|
175
|
+
return unknownSubcommand(pair, subaction, pretty, depth);
|
|
176
|
+
}
|
|
177
|
+
const grouped = NAMES.some((name) => name.startsWith(`${input} `));
|
|
178
|
+
if (isName(input) && (!grouped || action === undefined || action.startsWith('-'))) {
|
|
179
|
+
return actions[input](commandArgs.slice(1), pretty, depth, context);
|
|
180
|
+
}
|
|
181
|
+
if (grouped) {
|
|
182
|
+
return unknownSubcommand(input, action, pretty, depth);
|
|
183
|
+
}
|
|
184
|
+
const option = input.startsWith('-');
|
|
185
|
+
const suggestion = closest(input, option ? TOP_OPTIONS : TOP_COMMANDS);
|
|
186
|
+
if (!pretty) {
|
|
187
|
+
const kind = option ? 'option' : 'command';
|
|
188
|
+
return agentResult(2, {
|
|
189
|
+
error: { code: `unknown_${kind}`, message: `Unknown ${kind}: ${input}` },
|
|
190
|
+
...(suggestion ? { suggestions: [suggestion] } : {}),
|
|
191
|
+
usage: 'deepdynamic --help'
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return prettyResult(2, depth, input, `알 수 없는 ${option ? '옵션' : '명령'}입니다: ${input}`, [
|
|
195
|
+
['도움말', 'deepdynamic --help'],
|
|
196
|
+
...(suggestion ? [['혹시', option ? suggestion : `deepdynamic ${suggestion}`]] : [])
|
|
197
|
+
]);
|
|
198
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { readAccountEmail } from "../auth/credentials.js";
|
|
2
|
+
import { defaultAuthDeps, fetchCaptainMode, loginSiteUrl } from "../auth/session.js";
|
|
3
|
+
import { httpFailure } from "../http/request.js";
|
|
4
|
+
import { SITE_URL } from "../metadata.js";
|
|
5
|
+
import { agentResult } from "../output.js";
|
|
6
|
+
import { prettyResult } from "../pretty.js";
|
|
7
|
+
import { spec } from "../registry.js";
|
|
8
|
+
import { openBrowser } from "../runtime/browser.js";
|
|
9
|
+
import { unknownArgument } from "../runtime/flags.js";
|
|
10
|
+
import { plannedRequest, splitDryRun } from "../runtime/dry-run.js";
|
|
11
|
+
import { usageError } from "../runtime/usage-error.js";
|
|
12
|
+
import { rehearsed } from "./dns.js";
|
|
13
|
+
const { name: command } = spec('account get');
|
|
14
|
+
const DELETE = spec('account delete');
|
|
15
|
+
export const DELETE_REQUEST_PATH = '/api/v1/me/delete-request';
|
|
16
|
+
export const DELETE_PAGE_PATH = '/projects#account-delete';
|
|
17
|
+
const BLOCKER_TEXT = {
|
|
18
|
+
subscription: '이용 중인 유료 요금제가 있습니다. deepdynamic plan cancel 로 해지하세요.',
|
|
19
|
+
charges: '결제되지 않은 요금이 있습니다. deepdynamic plan pay 로 결제하세요.',
|
|
20
|
+
card: '등록한 결제 카드가 있습니다. 열린 화면의 요금제 영역에서 카드를 삭제하세요.',
|
|
21
|
+
domains: '만료되지 않은 구입 도메인이 있습니다. 자동 갱신을 끄고 만료된 뒤 요청할 수 있습니다.'
|
|
22
|
+
};
|
|
23
|
+
const PROJECTS_PAGE = `${SITE_URL}/projects`;
|
|
24
|
+
const guideNotes = {
|
|
25
|
+
developer: [
|
|
26
|
+
`The user has turned on captain mode (기장 모드) on the My Projects page (${PROJECTS_PAGE}). Assume the user is a developer and explain with technical terms such as commands, commits, build logs and error codes. Do not use airline metaphors.`,
|
|
27
|
+
'For deploy progress, relay percent and forHuman.detail only.'
|
|
28
|
+
],
|
|
29
|
+
non_developer: [
|
|
30
|
+
`The user has not turned on captain mode (기장 모드) on the My Projects page (${PROJECTS_PAGE}). Assume the user is not a developer and explain in plain words.`,
|
|
31
|
+
'Explain with the airline terms of the My Projects page: a project is a flight (항공편), its number such as KR4821 is the flight number (편명), a deploy is a departure (출발), a deploy in progress is 비행 중, a published site is 도착, a failed deploy is 결항, a project not deployed yet is 출발 전, the project server is the aircraft (항공기), CPU is the engine (엔진), RAM is the navigation system (항법장치), the site address is the gate (접속 게이트), the agent that deployed is the origin (출발지) and the deploy region is the destination (도착지).',
|
|
32
|
+
'Do not show the user technical terms such as commit, build, Git, repository, VM, DNS, JSON, exit code or error code, nor commands or logs. Explain them only when the user asks.',
|
|
33
|
+
'For deploy progress, relay percent and forHuman.message only. Do not relay forHuman.detail.',
|
|
34
|
+
'When something fails, tell the user in plain words only what did not work and what happens next, and handle the technical fix yourself. When the error message says to contact support, also give the user its error code and the contact options it lists.',
|
|
35
|
+
'When you need the user to confirm something, such as a project name or a deletion, ask in plain words too.'
|
|
36
|
+
]
|
|
37
|
+
};
|
|
38
|
+
export function guide(captainMode) {
|
|
39
|
+
const audience = captainMode ? 'developer' : 'non_developer';
|
|
40
|
+
return { captainMode, audience, notes: guideNotes[audience] };
|
|
41
|
+
}
|
|
42
|
+
function deletionShown(pretty, depth, body, siteUrl, open) {
|
|
43
|
+
const { requested, requestedAt, blockers, resources } = body;
|
|
44
|
+
const deletePage = new URL(DELETE_PAGE_PATH, siteUrl).href;
|
|
45
|
+
open(deletePage);
|
|
46
|
+
if (!pretty)
|
|
47
|
+
return agentResult(0, { command: DELETE.name, siteUrl, requested, requestedAt, blockers, resources, deletePage });
|
|
48
|
+
const message = requested
|
|
49
|
+
? '계정 삭제 요청이 접수되어 지원팀이 확인하고 있습니다. 열린 화면에서 요청을 취소할 수 있습니다.'
|
|
50
|
+
: blockers.length
|
|
51
|
+
? '계정을 삭제하기 전에 정리해야 할 항목이 있습니다.'
|
|
52
|
+
: '계정 삭제를 요청할 수 있습니다. 열린 화면에서 사용자가 직접 요청하세요.';
|
|
53
|
+
return prettyResult(0, depth, DELETE.name, message, [
|
|
54
|
+
['서버', siteUrl],
|
|
55
|
+
['요청', requestedAt ?? '없음'],
|
|
56
|
+
...blockers.map((blocker) => ['정리할 항목', BLOCKER_TEXT[blocker]]),
|
|
57
|
+
['화면', deletePage]
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
export async function runAccountDelete(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
61
|
+
return rehearsed(DELETE.name, args, pretty, depth, deps, (rest) => {
|
|
62
|
+
if (rest.length)
|
|
63
|
+
return { error: unknownArgument(rest[0], pretty) };
|
|
64
|
+
const url = (siteUrl) => new URL(DELETE_REQUEST_PATH, siteUrl).href;
|
|
65
|
+
return {
|
|
66
|
+
steps: [{ stage: 'prepare_request', message: '계정 삭제 조건 조회 요청을 준비하고 있습니다.' }],
|
|
67
|
+
result: (siteUrl) => plannedRequest(DELETE.name, pretty, depth, siteUrl, url(siteUrl)),
|
|
68
|
+
send: {
|
|
69
|
+
method: 'GET',
|
|
70
|
+
url,
|
|
71
|
+
spinner: '계정 삭제 조건을 확인하고 있습니다.',
|
|
72
|
+
failed: '계정 삭제 조건을 확인하지 못했습니다.',
|
|
73
|
+
notFound: httpFailure(404),
|
|
74
|
+
succeeded: ({ status }) => status === 200,
|
|
75
|
+
done: (body, siteUrl) => deletionShown(pretty, depth, body, siteUrl, deps.openBrowser ?? openBrowser)
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export async function runAccountGet(args, pretty, depth, readCaptainMode = fetchCaptainMode) {
|
|
81
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
82
|
+
if (rest.length)
|
|
83
|
+
return usageError(command, unknownArgument(rest[0], pretty), pretty, depth);
|
|
84
|
+
if (dryRun) {
|
|
85
|
+
const siteUrl = await loginSiteUrl();
|
|
86
|
+
return plannedRequest(command, pretty, depth, siteUrl, new URL('/api/v1/me', siteUrl).href);
|
|
87
|
+
}
|
|
88
|
+
const email = await readAccountEmail();
|
|
89
|
+
const captainMode = await readCaptainMode();
|
|
90
|
+
if (!pretty)
|
|
91
|
+
return agentResult(0, { command, account: email ? { email } : null, guide: guide(captainMode) });
|
|
92
|
+
return prettyResult(0, depth, command, '계정 정보를 표시했습니다.', [
|
|
93
|
+
['계정', email ?? '로그인하지 않음'],
|
|
94
|
+
['기장 모드', captainMode === null ? '확인하지 못함' : captainMode ? '켜짐' : '꺼짐']
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { defaultAuthDeps } from "../auth/session.js";
|
|
2
|
+
import { httpFailure } from "../http/request.js";
|
|
3
|
+
import { agentResult } from "../output.js";
|
|
4
|
+
import { prettyResult } from "../pretty.js";
|
|
5
|
+
import { plannedRequest } from "../runtime/dry-run.js";
|
|
6
|
+
import { parseFlags } from "../runtime/flags.js";
|
|
7
|
+
import { rehearsed } from "./dns.js";
|
|
8
|
+
export const ACTIVITY_PATH = '/api/v1/activity';
|
|
9
|
+
const command = 'account activity';
|
|
10
|
+
const FLAGS = ['--page', '--kind', '--date', '--source'];
|
|
11
|
+
const KINDS = ['login', 'change'];
|
|
12
|
+
const SOURCES = ['web', 'cli'];
|
|
13
|
+
const PAGE_RE = /^[1-9]\d{0,5}$/;
|
|
14
|
+
const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
15
|
+
const STEPS = [
|
|
16
|
+
{ stage: 'validate_filters', message: '조회 조건을 확인하고 있습니다.' },
|
|
17
|
+
{ stage: 'prepare_request', message: '계정 기록 요청을 준비하고 있습니다.' }
|
|
18
|
+
];
|
|
19
|
+
function isCalendarDate(value) {
|
|
20
|
+
const time = DATE_RE.test(value) ? Date.parse(`${value}T00:00:00Z`) : NaN;
|
|
21
|
+
return !Number.isNaN(time) && new Date(time).toISOString().startsWith(value);
|
|
22
|
+
}
|
|
23
|
+
function parseActivityArgs(args, pretty) {
|
|
24
|
+
const parsed = parseFlags(args, FLAGS, pretty);
|
|
25
|
+
if ('error' in parsed)
|
|
26
|
+
return parsed;
|
|
27
|
+
const repeated = FLAGS.find((flag) => parsed.entries.filter(([name]) => name === flag).length > 1);
|
|
28
|
+
if (repeated)
|
|
29
|
+
return { error: pretty ? `${repeated} 는 한 번만 지정하세요.` : `${repeated} can be given only once.` };
|
|
30
|
+
const { '--page': page = '1', '--kind': kind, '--date': date, '--source': source } = Object.fromEntries(parsed.entries);
|
|
31
|
+
if (!PAGE_RE.test(page))
|
|
32
|
+
return { error: pretty ? `--page 에는 1 이상의 정수를 지정하세요: ${page}` : `--page requires a positive integer: ${page}` };
|
|
33
|
+
if (kind !== undefined && !KINDS.includes(kind))
|
|
34
|
+
return { error: pretty ? `--kind 에는 login 또는 change 를 지정하세요: ${kind}` : `--kind must be login or change: ${kind}` };
|
|
35
|
+
if (date !== undefined && !isCalendarDate(date))
|
|
36
|
+
return { error: pretty ? `--date 에는 실제 날짜를 YYYY-MM-DD 형식으로 지정하세요: ${date}` : `--date requires a real calendar date as YYYY-MM-DD: ${date}` };
|
|
37
|
+
if (source !== undefined && !SOURCES.includes(source))
|
|
38
|
+
return { error: pretty ? `--source 에는 web 또는 cli 를 지정하세요: ${source}` : `--source must be web or cli: ${source}` };
|
|
39
|
+
return { page: Number(page), kind: kind ?? null, date: date ?? null, source: source ?? null };
|
|
40
|
+
}
|
|
41
|
+
const seoulTime = (iso) => `${new Date(iso).toLocaleString('sv-SE', { timeZone: 'Asia/Seoul' }).slice(0, 16)} KST`;
|
|
42
|
+
function recordLine(record) {
|
|
43
|
+
const parts = [record.kind, record.source, record.action, ...(record.target ? [record.target] : []), ...(record.ip ? [`IP ${record.ip}`] : [])];
|
|
44
|
+
return [seoulTime(record.at), parts.join(' · ')];
|
|
45
|
+
}
|
|
46
|
+
export async function runActivity(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
47
|
+
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
48
|
+
const options = parseActivityArgs(rest, pretty);
|
|
49
|
+
if ('error' in options)
|
|
50
|
+
return options;
|
|
51
|
+
const url = (siteUrl) => {
|
|
52
|
+
const endpoint = new URL(ACTIVITY_PATH, siteUrl);
|
|
53
|
+
endpoint.searchParams.set('page', String(options.page));
|
|
54
|
+
if (options.kind)
|
|
55
|
+
endpoint.searchParams.set('kind', options.kind);
|
|
56
|
+
if (options.date)
|
|
57
|
+
endpoint.searchParams.set('date', options.date);
|
|
58
|
+
if (options.source)
|
|
59
|
+
endpoint.searchParams.set('source', options.source);
|
|
60
|
+
return endpoint.href;
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
steps: STEPS,
|
|
64
|
+
result: (siteUrl) => plannedRequest(command, pretty, depth, siteUrl, url(siteUrl)),
|
|
65
|
+
send: {
|
|
66
|
+
method: 'GET',
|
|
67
|
+
url,
|
|
68
|
+
spinner: '계정 기록을 불러오고 있습니다.',
|
|
69
|
+
failed: '계정 기록을 불러오지 못했습니다.',
|
|
70
|
+
notFound: httpFailure(404),
|
|
71
|
+
done: (body, siteUrl) => {
|
|
72
|
+
const { page, pageSize, total, date, source, records } = body;
|
|
73
|
+
if (!pretty)
|
|
74
|
+
return agentResult(0, { command, siteUrl, page, pageSize, total, date, source, records });
|
|
75
|
+
return prettyResult(0, depth, command, `계정 기록 ${total}건 중 ${page}페이지를 불러왔습니다.`, [['서버', siteUrl], ...records.map(recordLine)]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
}
|