@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,65 @@
|
|
|
1
|
+
import { authorized, defaultAuthDeps } from "../auth/session.js";
|
|
2
|
+
import { LOGIN_EXPIRED, accepted, httpFailure, postJson, sendFailureError } from "../http/request.js";
|
|
3
|
+
import { agentResult } from "../output.js";
|
|
4
|
+
import { prettyResult } from "../pretty.js";
|
|
5
|
+
import { spec } from "../registry.js";
|
|
6
|
+
import { splitDryRun } from "../runtime/dry-run.js";
|
|
7
|
+
import { parseFlags } from "../runtime/flags.js";
|
|
8
|
+
import { readText } from "../runtime/text-file.js";
|
|
9
|
+
export const SMS_PATH = '/api/v1/sms';
|
|
10
|
+
const { name: command, usage, prettyUsage } = spec('sms send');
|
|
11
|
+
const FLAGS = ['--to', '--body', '--body-file'];
|
|
12
|
+
async function parseSendArgs(args, pretty) {
|
|
13
|
+
const parsed = parseFlags(args, FLAGS, pretty);
|
|
14
|
+
if ('error' in parsed)
|
|
15
|
+
return parsed;
|
|
16
|
+
const values = Object.fromEntries(parsed.entries);
|
|
17
|
+
const { '--to': to, '--body': body, '--body-file': bodyFile } = values;
|
|
18
|
+
if (to === undefined) {
|
|
19
|
+
return { error: pretty ? '--to 를 지정하세요.' : '--to is required.' };
|
|
20
|
+
}
|
|
21
|
+
const content = await readText('--body', body, bodyFile, pretty);
|
|
22
|
+
return 'error' in content ? content : { to, body: content.text };
|
|
23
|
+
}
|
|
24
|
+
export async function runSmsSend(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
25
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
26
|
+
const parsed = await parseSendArgs(rest, pretty);
|
|
27
|
+
if ('error' in parsed) {
|
|
28
|
+
return pretty
|
|
29
|
+
? prettyResult(2, depth, command, parsed.error, [['사용법', prettyUsage]])
|
|
30
|
+
: agentResult(2, { command, error: { code: 'invalid_arguments', message: parsed.error }, usage });
|
|
31
|
+
}
|
|
32
|
+
const sent = await authorized(deps, ({ siteUrl, token }) => postJson(new URL(SMS_PATH, siteUrl).href, token, dryRun ? { ...parsed, dryRun } : parsed, deps, pretty ? (dryRun ? '문자를 검증하고 있습니다.' : '문자를 보내고 있습니다.') : null));
|
|
33
|
+
if ('login' in sent)
|
|
34
|
+
return sent.login;
|
|
35
|
+
const { session: { siteUrl }, result } = sent;
|
|
36
|
+
let failure = null;
|
|
37
|
+
let rejected = false;
|
|
38
|
+
if ('failure' in result) {
|
|
39
|
+
failure = result.failure;
|
|
40
|
+
}
|
|
41
|
+
else if (result.status === 401) {
|
|
42
|
+
failure = LOGIN_EXPIRED;
|
|
43
|
+
}
|
|
44
|
+
else if (!accepted(result)) {
|
|
45
|
+
rejected = result.status === 400 && result.body?.rejected === true;
|
|
46
|
+
failure = rejected
|
|
47
|
+
? { code: 'spam_rejected', message: 'The server rejected the message as advertising or spam. The account may be blocked if this continues.', display: '광고·스팸으로 보이는 내용이라 거절되었습니다.' }
|
|
48
|
+
: result.status === 400
|
|
49
|
+
? { code: 'rejected', message: 'The server rejected the message. Check the recipient and body.', display: '받는 사람·본문을 확인하세요.' }
|
|
50
|
+
: httpFailure(result.status);
|
|
51
|
+
}
|
|
52
|
+
if (failure) {
|
|
53
|
+
return pretty
|
|
54
|
+
? prettyResult(1, depth, command, rejected ? '문자가 거절되었습니다.' : dryRun ? '문자를 검증하지 못했습니다.' : '문자를 보내지 못했습니다.', [['서버', siteUrl], ['원인', failure.display]])
|
|
55
|
+
: agentResult(1, { command, siteUrl, delivered: false, ...(rejected ? { rejected } : {}), error: sendFailureError(result, failure) });
|
|
56
|
+
}
|
|
57
|
+
const { dryRun: checked, delivered, id, to } = result.body;
|
|
58
|
+
if (!pretty) {
|
|
59
|
+
return agentResult(0, { command, siteUrl, ...(checked === true ? { dryRun: true } : {}), delivered, rejected, id, to });
|
|
60
|
+
}
|
|
61
|
+
return prettyResult(0, depth, command, checked === true ? '문자를 검증했습니다. 보내지 않았습니다.' : '문자를 보냈습니다.', [
|
|
62
|
+
['서버', siteUrl],
|
|
63
|
+
['받는 사람', to]
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { readLoginSiteUrl } from "../auth/credentials.js";
|
|
2
|
+
import { call } from "../http/call.js";
|
|
3
|
+
import { UNEXPECTED, failureError, 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 { plannedRequest, splitDryRun } from "../runtime/dry-run.js";
|
|
9
|
+
import { parseServerArgs } from "../runtime/server-options.js";
|
|
10
|
+
import { startSpinner } from "../runtime/spinner.js";
|
|
11
|
+
import { supportFailure } from "../runtime/support.js";
|
|
12
|
+
const { name: command, usage, prettyUsage } = spec('system status');
|
|
13
|
+
const BACKEND_UNAVAILABLE = supportFailure('backend_unavailable');
|
|
14
|
+
async function checkBackend(siteUrl, signal, fetcher) {
|
|
15
|
+
try {
|
|
16
|
+
const response = await call(new URL('/api/v1/status/backend', siteUrl).href, { method: 'GET', redirect: 'manual', signal }, fetcher);
|
|
17
|
+
const body = await response.json().catch(() => null);
|
|
18
|
+
return response.status === 200 && body?.status === 'ok' ? 'ok' : 'unavailable';
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return 'unavailable';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export async function runStatus(args, pretty, depth, deps = { fetch, stream: process.stderr, timeoutMs: 10_000 }) {
|
|
25
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
26
|
+
const options = parseServerArgs(rest, pretty);
|
|
27
|
+
if ('error' in options) {
|
|
28
|
+
return pretty
|
|
29
|
+
? prettyResult(2, depth, command, options.error, [['사용법', prettyUsage]])
|
|
30
|
+
: agentResult(2, {
|
|
31
|
+
command,
|
|
32
|
+
error: { code: 'invalid_arguments', message: options.error },
|
|
33
|
+
usage
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const siteUrl = options.siteUrl ?? await readLoginSiteUrl() ?? SITE_URL;
|
|
37
|
+
if (dryRun)
|
|
38
|
+
return plannedRequest(command, pretty, depth, siteUrl, new URL('/api/v1/status', siteUrl).href);
|
|
39
|
+
const stop = pretty ? startSpinner('배포 서버에 연결하고 있습니다.', deps.stream) : () => { };
|
|
40
|
+
const controller = new AbortController();
|
|
41
|
+
const timer = setTimeout(() => controller.abort(), deps.timeoutMs);
|
|
42
|
+
let httpStatus = null;
|
|
43
|
+
let backend = null;
|
|
44
|
+
let failure = null;
|
|
45
|
+
try {
|
|
46
|
+
const response = await call(new URL('/api/v1/status', siteUrl).href, {
|
|
47
|
+
method: 'GET',
|
|
48
|
+
redirect: 'manual',
|
|
49
|
+
signal: controller.signal
|
|
50
|
+
}, deps.fetch);
|
|
51
|
+
httpStatus = response.status;
|
|
52
|
+
if (response.status !== 200) {
|
|
53
|
+
await response.body?.cancel();
|
|
54
|
+
failure = httpFailure(response.status);
|
|
55
|
+
}
|
|
56
|
+
else if (await response.text() !== 'OK') {
|
|
57
|
+
failure = UNEXPECTED;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
backend = await checkBackend(siteUrl, controller.signal, deps.fetch);
|
|
61
|
+
if (backend === 'unavailable')
|
|
62
|
+
failure = BACKEND_UNAVAILABLE;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
failure = controller.signal.aborted
|
|
67
|
+
? { code: 'connection_timeout', message: 'The connection timed out.', display: '서버 응답 대기 시간이 초과되었습니다.' }
|
|
68
|
+
: { code: 'connection_failed', message: 'Could not connect to the deployment server.', display: '서버 주소와 네트워크 연결을 확인하세요.' };
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
stop();
|
|
73
|
+
}
|
|
74
|
+
if (!pretty) {
|
|
75
|
+
return agentResult(failure ? 1 : 0, {
|
|
76
|
+
command,
|
|
77
|
+
siteUrl,
|
|
78
|
+
httpStatus,
|
|
79
|
+
backend,
|
|
80
|
+
...(failure ? { error: failureError(failure) } : {})
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (!failure)
|
|
84
|
+
return prettyResult(0, depth, command, '배포 서버에 연결 성공했습니다.', [['서버', siteUrl], ['서비스', '정상']]);
|
|
85
|
+
const target = backend === 'unavailable' ? '서비스' : '배포 서버';
|
|
86
|
+
return prettyResult(1, depth, command, `${target}에 연결 실패했습니다.`, [['서버', siteUrl], ['원인', failure.display]]);
|
|
87
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { readAccountEmail, readLoginSiteUrl } from "../auth/credentials.js";
|
|
2
|
+
import { authorized, defaultAuthDeps } from "../auth/session.js";
|
|
3
|
+
import { LOGIN_EXPIRED, UNEXPECTED, accepted, defaultDeps, failureError, httpFailure, postJson, request, sendFailureError } 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 { parseFlags } from "../runtime/flags.js";
|
|
8
|
+
import { spec } from "../registry.js";
|
|
9
|
+
import { plannedRequest, splitDryRun } from "../runtime/dry-run.js";
|
|
10
|
+
import { readText } from "../runtime/text-file.js";
|
|
11
|
+
import { parseServerArgs } from "../runtime/server-options.js";
|
|
12
|
+
export const CONTACT_PATH = '/api/v1/ai/contact';
|
|
13
|
+
const QA = spec('support qa');
|
|
14
|
+
const CONTACT = spec('support contact');
|
|
15
|
+
const CONTACT_FLAGS = ['--message', '--message-file', '--team'];
|
|
16
|
+
function isGuide(body) {
|
|
17
|
+
return typeof body === 'object' && body !== null && Array.isArray(body.faq);
|
|
18
|
+
}
|
|
19
|
+
export async function runQa(args, pretty, depth, deps = defaultDeps()) {
|
|
20
|
+
const command = QA.name;
|
|
21
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
22
|
+
const options = parseServerArgs(rest, pretty);
|
|
23
|
+
if ('error' in options) {
|
|
24
|
+
return pretty
|
|
25
|
+
? prettyResult(2, depth, command, options.error, [['사용법', QA.prettyUsage]])
|
|
26
|
+
: agentResult(2, { command, error: { code: 'invalid_arguments', message: options.error }, usage: QA.usage });
|
|
27
|
+
}
|
|
28
|
+
const siteUrl = options.siteUrl ?? await readLoginSiteUrl() ?? SITE_URL;
|
|
29
|
+
if (dryRun)
|
|
30
|
+
return plannedRequest(command, pretty, depth, siteUrl, new URL(CONTACT_PATH, siteUrl).href);
|
|
31
|
+
const result = await request(new URL(CONTACT_PATH, siteUrl).href, { method: 'GET' }, deps, pretty ? '자주 묻는 질문을 불러오고 있습니다.' : null);
|
|
32
|
+
if ('failure' in result || result.status !== 200 || !isGuide(result.body)) {
|
|
33
|
+
const failure = 'failure' in result
|
|
34
|
+
? result.failure
|
|
35
|
+
: result.status !== 200
|
|
36
|
+
? httpFailure(result.status)
|
|
37
|
+
: UNEXPECTED;
|
|
38
|
+
return pretty
|
|
39
|
+
? prettyResult(1, depth, command, '자주 묻는 질문을 불러오지 못했습니다.', [['서버', siteUrl], ['원인', failure.display]])
|
|
40
|
+
: agentResult(1, { command, siteUrl, error: failureError(failure) });
|
|
41
|
+
}
|
|
42
|
+
const guide = result.body;
|
|
43
|
+
if (!pretty) {
|
|
44
|
+
return agentResult(0, { command, siteUrl, ...guide, send: CONTACT.usage });
|
|
45
|
+
}
|
|
46
|
+
return prettyResult(0, depth, command, '자주 묻는 질문을 불러왔습니다.', [
|
|
47
|
+
...guide.faq.flatMap(({ question, answer }, index) => [
|
|
48
|
+
[`Q${index + 1}`, question.ko],
|
|
49
|
+
['', answer.ko]
|
|
50
|
+
]),
|
|
51
|
+
['문의', 'deepdynamic support contact --message <내용>']
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
async function parseContactArgs(args, pretty) {
|
|
55
|
+
const parsed = parseFlags(args, CONTACT_FLAGS, pretty);
|
|
56
|
+
if ('error' in parsed)
|
|
57
|
+
return parsed;
|
|
58
|
+
let message;
|
|
59
|
+
let messageFile;
|
|
60
|
+
const teamEmails = [];
|
|
61
|
+
for (const [flag, value] of parsed.entries) {
|
|
62
|
+
if (flag === '--message')
|
|
63
|
+
message = value;
|
|
64
|
+
else if (flag === '--message-file')
|
|
65
|
+
messageFile = value;
|
|
66
|
+
else
|
|
67
|
+
teamEmails.push(value);
|
|
68
|
+
}
|
|
69
|
+
const content = await readText('--message', message, messageFile, pretty);
|
|
70
|
+
return 'error' in content ? content : { message: content.text, teamEmails };
|
|
71
|
+
}
|
|
72
|
+
export async function runContact(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
73
|
+
const command = CONTACT.name;
|
|
74
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
75
|
+
const parsed = await parseContactArgs(rest, pretty);
|
|
76
|
+
if ('error' in parsed) {
|
|
77
|
+
return pretty
|
|
78
|
+
? prettyResult(2, depth, command, parsed.error, [['사용법', CONTACT.prettyUsage]])
|
|
79
|
+
: agentResult(2, { command, error: { code: 'invalid_arguments', message: parsed.error }, usage: CONTACT.usage });
|
|
80
|
+
}
|
|
81
|
+
const sent = await authorized(deps, ({ siteUrl, token }) => postJson(new URL(CONTACT_PATH, siteUrl).href, token, { message: parsed.message, ...(parsed.teamEmails.length ? { teamEmails: parsed.teamEmails } : {}), ...(dryRun ? { dryRun } : {}) }, deps, pretty ? (dryRun ? '문의 내용을 검증하고 있습니다.' : '문의를 보내고 있습니다.') : null));
|
|
82
|
+
if ('login' in sent)
|
|
83
|
+
return sent.login;
|
|
84
|
+
const { session: { siteUrl }, result } = sent;
|
|
85
|
+
let failure = null;
|
|
86
|
+
if ('failure' in result) {
|
|
87
|
+
failure = result.failure;
|
|
88
|
+
}
|
|
89
|
+
else if (result.status === 401) {
|
|
90
|
+
failure = LOGIN_EXPIRED;
|
|
91
|
+
}
|
|
92
|
+
else if (!accepted(result)) {
|
|
93
|
+
failure = result.status === 429
|
|
94
|
+
? { code: 'rate_limited', message: 'Too many inquiries. Try again later.', display: '요청이 너무 많습니다.' }
|
|
95
|
+
: result.status === 400
|
|
96
|
+
? { code: 'rejected', message: 'The server rejected the inquiry. Check the message and team emails.', display: '문의 내용을 확인하세요.' }
|
|
97
|
+
: httpFailure(result.status);
|
|
98
|
+
}
|
|
99
|
+
if (failure) {
|
|
100
|
+
return pretty
|
|
101
|
+
? prettyResult(1, depth, command, dryRun ? '문의 내용을 검증하지 못했습니다.' : '문의를 보내지 못했습니다.', [['서버', siteUrl], ['원인', failure.display]])
|
|
102
|
+
: agentResult(1, { command, siteUrl, error: sendFailureError(result, failure) });
|
|
103
|
+
}
|
|
104
|
+
const { id, dryRun: checked } = result.body;
|
|
105
|
+
const email = await readAccountEmail();
|
|
106
|
+
if (checked === true) {
|
|
107
|
+
return pretty
|
|
108
|
+
? prettyResult(0, depth, command, '문의 내용을 검증했습니다. 보내지 않았습니다.', [['서버', siteUrl]])
|
|
109
|
+
: agentResult(0, { command, siteUrl, dryRun: true, replyTo: email });
|
|
110
|
+
}
|
|
111
|
+
if (!pretty) {
|
|
112
|
+
return agentResult(0, { command, siteUrl, id: typeof id === 'string' ? id : null, replyTo: email });
|
|
113
|
+
}
|
|
114
|
+
return prettyResult(0, depth, command, '문의를 보냈습니다. 답변은 계정 이메일로 받습니다.', [['서버', siteUrl], ['답변 메일', email ?? '로그인 계정']]);
|
|
115
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { defaultDeps, failureError, request } from "../http/request.js";
|
|
2
|
+
import { agentResult } from "../output.js";
|
|
3
|
+
import { prettyResult } from "../pretty.js";
|
|
4
|
+
import { confirmationRequired, splitYes } from "../runtime/confirm.js";
|
|
5
|
+
import { splitDryRun } from "../runtime/dry-run.js";
|
|
6
|
+
import { unknownArgument } from "../runtime/flags.js";
|
|
7
|
+
import { startSpinner } from "../runtime/spinner.js";
|
|
8
|
+
import { REGISTRY_URL, isNewer, latestOf, saveUpdateCache, updateCachePath, updateLockPath, withUpdateLock } from "../runtime/update-check.js";
|
|
9
|
+
import { PACKAGE_DIR, findPackageManager, installArgs, packageManagerOf, runProgram } from "../runtime/update-install.js";
|
|
10
|
+
import { usageError } from "../runtime/usage-error.js";
|
|
11
|
+
const command = 'update';
|
|
12
|
+
export const defaultUpdateCommandDeps = () => ({
|
|
13
|
+
...defaultDeps(),
|
|
14
|
+
cachePath: updateCachePath(),
|
|
15
|
+
now: Date.now,
|
|
16
|
+
packageManager: packageManagerOf(PACKAGE_DIR),
|
|
17
|
+
find: findPackageManager,
|
|
18
|
+
install: runProgram
|
|
19
|
+
});
|
|
20
|
+
const registryFailure = (status) => ({
|
|
21
|
+
code: 'http_error',
|
|
22
|
+
message: 'The npm registry answered with an error.',
|
|
23
|
+
display: 'npm 레지스트리가 오류로 응답했습니다. 잠시 뒤 다시 시도하세요.',
|
|
24
|
+
retryable: status >= 500 || status === 429
|
|
25
|
+
});
|
|
26
|
+
const REGISTRY_UNEXPECTED = {
|
|
27
|
+
code: 'unexpected_response',
|
|
28
|
+
message: 'The npm registry did not return the latest version.',
|
|
29
|
+
display: 'npm 레지스트리에서 최신 버전을 읽지 못했습니다.'
|
|
30
|
+
};
|
|
31
|
+
const UPDATE_IN_PROGRESS = {
|
|
32
|
+
code: 'update_in_progress',
|
|
33
|
+
message: 'An automatic update is running in the background. Retry in a minute.',
|
|
34
|
+
display: '백그라운드에서 자동 업데이트가 진행 중입니다. 잠시 뒤 다시 실행하세요.',
|
|
35
|
+
retryable: true
|
|
36
|
+
};
|
|
37
|
+
function failed(failure, pretty, depth, data, rows = [], detail) {
|
|
38
|
+
return pretty
|
|
39
|
+
? prettyResult(1, depth, command, failure.display, rows)
|
|
40
|
+
: agentResult(1, { command, ...data, error: { ...failureError(failure), ...(detail === undefined ? {} : { detail }) } });
|
|
41
|
+
}
|
|
42
|
+
export async function runUpdate(args, current, pretty, depth, deps = defaultUpdateCommandDeps()) {
|
|
43
|
+
const { args: withoutYes, yes } = splitYes(args);
|
|
44
|
+
const { args: rest, dryRun } = splitDryRun(withoutYes);
|
|
45
|
+
if (rest.length)
|
|
46
|
+
return usageError(command, unknownArgument(rest[0], pretty), pretty, depth);
|
|
47
|
+
const manager = deps.packageManager;
|
|
48
|
+
if (dryRun) {
|
|
49
|
+
return pretty
|
|
50
|
+
? prettyResult(0, depth, command, '요청을 보내거나 설치하지 않고 확인만 했습니다.', [['현재', current], ['요청', `GET ${REGISTRY_URL}`], ['설치', `${manager} ${installArgs(manager, '<최신 버전>').join(' ')}`]])
|
|
51
|
+
: agentResult(0, { command, current, packageManager: manager, dryRun: true, request: { method: 'GET', url: REGISTRY_URL } });
|
|
52
|
+
}
|
|
53
|
+
const response = await request(REGISTRY_URL, { method: 'GET' }, deps, pretty ? '최신 버전을 확인하고 있습니다.' : null);
|
|
54
|
+
const latest = 'failure' in response || response.status !== 200 ? null : latestOf(response.body);
|
|
55
|
+
if (!latest) {
|
|
56
|
+
const failure = 'failure' in response ? response.failure : response.status !== 200 ? registryFailure(response.status) : REGISTRY_UNEXPECTED;
|
|
57
|
+
return failed(failure, pretty, depth, { current }, [['현재', current]]);
|
|
58
|
+
}
|
|
59
|
+
await saveUpdateCache(deps.cachePath, { checkedAt: deps.now(), latest }).catch(() => { });
|
|
60
|
+
if (!isNewer(latest, current)) {
|
|
61
|
+
return pretty
|
|
62
|
+
? prettyResult(0, depth, command, '최신 버전을 쓰고 있습니다.', [['현재', current], ['최신', latest]])
|
|
63
|
+
: agentResult(0, { command, current, latest, packageManager: manager, updated: false });
|
|
64
|
+
}
|
|
65
|
+
const argv = installArgs(manager, latest);
|
|
66
|
+
const install = `${manager} ${argv.join(' ')}`;
|
|
67
|
+
const data = { current, latest, packageManager: manager, install };
|
|
68
|
+
const rows = [['현재', current], ['최신', latest], ['설치', install]];
|
|
69
|
+
if (!yes) {
|
|
70
|
+
return confirmationRequired(command, args, pretty, depth, {
|
|
71
|
+
message: `DeepDynamic CLI ${latest} is available (current ${current}). The update runs: ${install}.`,
|
|
72
|
+
display: `새 버전이 나왔습니다(현재 ${current}, 최신 ${latest}). ${install} 을 실행합니다.`
|
|
73
|
+
}, data);
|
|
74
|
+
}
|
|
75
|
+
const path = await deps.find(manager);
|
|
76
|
+
if (!path) {
|
|
77
|
+
return failed({
|
|
78
|
+
code: 'package_manager_not_found',
|
|
79
|
+
message: `${manager} was not found on PATH. Update the CLI with the package manager that installed it, for example: ${install}`,
|
|
80
|
+
display: `PATH 에서 ${manager} 을 찾지 못했습니다. CLI 를 설치한 패키지 관리자로 업데이트하세요.`
|
|
81
|
+
}, pretty, depth, data, rows);
|
|
82
|
+
}
|
|
83
|
+
const stop = pretty ? startSpinner(`최신 버전(${latest})을 설치하고 있습니다.`, deps.stream) : () => { };
|
|
84
|
+
const installed = await withUpdateLock(updateLockPath(deps.cachePath), () => deps.install(path, argv), deps.now);
|
|
85
|
+
stop();
|
|
86
|
+
if (!installed)
|
|
87
|
+
return failed(UPDATE_IN_PROGRESS, pretty, depth, data, rows);
|
|
88
|
+
if (installed.status !== 0) {
|
|
89
|
+
return failed({
|
|
90
|
+
code: 'update_failed',
|
|
91
|
+
message: `${install} failed. Read error.detail, fix the cause (for example permissions of the global folder) or run the command yourself.`,
|
|
92
|
+
display: `${manager} 설치가 실패했습니다. 아래 출력을 확인하거나 설치 명령을 직접 실행하세요.`
|
|
93
|
+
}, pretty, depth, data, [...rows, [manager, installed.output]], installed.output);
|
|
94
|
+
}
|
|
95
|
+
return pretty
|
|
96
|
+
? prettyResult(0, depth, command, `업데이트했습니다(${current} → ${latest}).`, [['이전', current], ['현재', latest]])
|
|
97
|
+
: agentResult(0, { command, current, latest, packageManager: manager, updated: true });
|
|
98
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { unknownArgument } from "../runtime/flags.js";
|
|
7
|
+
import { spec } from "../registry.js";
|
|
8
|
+
import { supportFailure } from "../runtime/support.js";
|
|
9
|
+
import { rehearsed } from "./dns.js";
|
|
10
|
+
export const USAGE_PATH = '/api/v1/usage';
|
|
11
|
+
const { name: command } = spec('usage');
|
|
12
|
+
const UNAVAILABLE = supportFailure('unavailable');
|
|
13
|
+
const STEPS = [
|
|
14
|
+
{ stage: 'check_options', message: '조회 옵션을 확인하고 있습니다.' },
|
|
15
|
+
{ stage: 'prepare_request', message: '사용량 조회 요청을 준비하고 있습니다.' }
|
|
16
|
+
];
|
|
17
|
+
const count = (value) => `${value.toLocaleString('ko-KR')}건`;
|
|
18
|
+
const channelText = ({ limit, used, remaining }) => `${count(used)} / ${count(limit)} · ${count(remaining)} 남음`;
|
|
19
|
+
function shown(pretty, depth, body, siteUrl) {
|
|
20
|
+
const { plan, period, resetsAt, sms, email, daily } = body;
|
|
21
|
+
if (!pretty)
|
|
22
|
+
return agentResult(0, { command, siteUrl, plan, period, resetsAt, sms, email, daily });
|
|
23
|
+
return prettyResult(0, depth, command, `${period} 발송 사용량을 불러왔습니다.`, [
|
|
24
|
+
['서버', siteUrl],
|
|
25
|
+
['요금제', plan],
|
|
26
|
+
['SMS', channelText(sms)],
|
|
27
|
+
['이메일', channelText(email)],
|
|
28
|
+
['초기화', `${resetsAt.slice(0, 10)} 00:00 KST`]
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
export async function runUsage(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
32
|
+
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
33
|
+
if (rest.length)
|
|
34
|
+
return { error: unknownArgument(rest[0], pretty) };
|
|
35
|
+
const url = (siteUrl) => new URL(USAGE_PATH, siteUrl).href;
|
|
36
|
+
return {
|
|
37
|
+
steps: STEPS,
|
|
38
|
+
result: (siteUrl) => plannedRequest(command, pretty, depth, siteUrl, url(siteUrl)),
|
|
39
|
+
send: {
|
|
40
|
+
method: 'GET',
|
|
41
|
+
url,
|
|
42
|
+
spinner: '사용량을 불러오고 있습니다.',
|
|
43
|
+
failed: '사용량을 불러오지 못했습니다.',
|
|
44
|
+
notFound: httpFailure(404),
|
|
45
|
+
failures: { unavailable: UNAVAILABLE },
|
|
46
|
+
succeeded: ({ status }) => status === 200,
|
|
47
|
+
done: (body, siteUrl) => shown(pretty, depth, body, siteUrl)
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { readLoginSiteUrl } from "../auth/credentials.js";
|
|
4
|
+
import { call } from "../http/call.js";
|
|
5
|
+
import { UNEXPECTED, failureError, httpFailure } from "../http/request.js";
|
|
6
|
+
import { SITE_URL } from "../metadata.js";
|
|
7
|
+
import { agentResult } from "../output.js";
|
|
8
|
+
import { prettyResult } from "../pretty.js";
|
|
9
|
+
import { spec } from "../registry.js";
|
|
10
|
+
import { plannedRequest, splitDryRun } from "../runtime/dry-run.js";
|
|
11
|
+
import { parseServerArgs } from "../runtime/server-options.js";
|
|
12
|
+
import { startSpinner } from "../runtime/spinner.js";
|
|
13
|
+
import { supportFailure } from "../runtime/support.js";
|
|
14
|
+
export const FILE_OPTION = '--file';
|
|
15
|
+
export const SAVE_OPTION = '--save';
|
|
16
|
+
export const MANIFEST_PATH = '/api/v1/sdk/manifest';
|
|
17
|
+
const { name: command, usage, prettyUsage } = spec('verify');
|
|
18
|
+
const MISMATCH = supportFailure('integrity_mismatch', { note: { en: 'Nothing was saved.', ko: '저장하지 않았습니다.' } });
|
|
19
|
+
export const integrityOf = (bytes) => `sha384-${createHash('sha384').update(bytes).digest('base64')}`;
|
|
20
|
+
function splitPaths(args) {
|
|
21
|
+
const rest = [];
|
|
22
|
+
const paths = { [FILE_OPTION]: null, [SAVE_OPTION]: null };
|
|
23
|
+
for (let index = 0; index < args.length; index++) {
|
|
24
|
+
const arg = args[index];
|
|
25
|
+
const option = [FILE_OPTION, SAVE_OPTION].find((name) => arg === name || arg.startsWith(`${name}=`));
|
|
26
|
+
if (!option) {
|
|
27
|
+
rest.push(arg);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const value = arg === option ? args[++index] : arg.slice(option.length + 1);
|
|
31
|
+
if (!value?.trim())
|
|
32
|
+
return { error: `${option} requires a path.` };
|
|
33
|
+
paths[option] = value;
|
|
34
|
+
}
|
|
35
|
+
return { args: rest, file: paths[FILE_OPTION], save: paths[SAVE_OPTION] };
|
|
36
|
+
}
|
|
37
|
+
function readScript(body, siteUrl) {
|
|
38
|
+
const script = body?.scripts?.[0];
|
|
39
|
+
if (!script)
|
|
40
|
+
return null;
|
|
41
|
+
const { client, src, integrity, download } = script;
|
|
42
|
+
if ([client, src, integrity, download].some((value) => typeof value !== 'string'))
|
|
43
|
+
return null;
|
|
44
|
+
const served = URL.canParse(download) ? new URL(download) : null;
|
|
45
|
+
const site = new URL(siteUrl);
|
|
46
|
+
if (served?.protocol !== site.protocol || served.origin !== site.origin)
|
|
47
|
+
return null;
|
|
48
|
+
return { client, src, integrity, download };
|
|
49
|
+
}
|
|
50
|
+
export async function runVerify(args, pretty, depth, deps = { fetch, stream: process.stderr, timeoutMs: 10_000, readFile: (path) => readFile(path), writeFile: (path, bytes) => writeFile(path, bytes) }) {
|
|
51
|
+
const { args: withoutDryRun, dryRun } = splitDryRun(args);
|
|
52
|
+
const split = splitPaths(withoutDryRun);
|
|
53
|
+
const options = 'error' in split ? split : parseServerArgs(split.args, pretty);
|
|
54
|
+
if ('error' in options) {
|
|
55
|
+
return pretty
|
|
56
|
+
? prettyResult(2, depth, command, options.error, [['사용법', prettyUsage]])
|
|
57
|
+
: agentResult(2, { command, error: { code: 'invalid_arguments', message: options.error }, usage });
|
|
58
|
+
}
|
|
59
|
+
const file = 'file' in split ? split.file : null;
|
|
60
|
+
const save = 'save' in split ? split.save : null;
|
|
61
|
+
const siteUrl = options.siteUrl ?? await readLoginSiteUrl() ?? SITE_URL;
|
|
62
|
+
const manifestUrl = new URL(MANIFEST_PATH, siteUrl).href;
|
|
63
|
+
if (dryRun)
|
|
64
|
+
return plannedRequest(command, pretty, depth, siteUrl, manifestUrl);
|
|
65
|
+
const stop = pretty ? startSpinner('스크립트 매니페스트를 확인하고 있습니다.', deps.stream) : () => { };
|
|
66
|
+
const controller = new AbortController();
|
|
67
|
+
const timer = setTimeout(() => controller.abort(), deps.timeoutMs);
|
|
68
|
+
let script = null;
|
|
69
|
+
let served = null;
|
|
70
|
+
let local = null;
|
|
71
|
+
let saved = null;
|
|
72
|
+
let failure = null;
|
|
73
|
+
try {
|
|
74
|
+
const response = await call(manifestUrl, { method: 'GET', redirect: 'manual', signal: controller.signal }, deps.fetch);
|
|
75
|
+
if (response.status !== 200) {
|
|
76
|
+
await response.body?.cancel();
|
|
77
|
+
failure = httpFailure(response.status);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
script = readScript(await response.json().catch(() => null), siteUrl);
|
|
81
|
+
if (!script)
|
|
82
|
+
failure = UNEXPECTED;
|
|
83
|
+
}
|
|
84
|
+
if (script) {
|
|
85
|
+
const download = await call(script.download, { method: 'GET', redirect: 'manual', signal: controller.signal }, deps.fetch);
|
|
86
|
+
if (download.status !== 200) {
|
|
87
|
+
await download.body?.cancel();
|
|
88
|
+
failure = httpFailure(download.status);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const bytes = new Uint8Array(await download.arrayBuffer());
|
|
92
|
+
const integrity = integrityOf(bytes);
|
|
93
|
+
served = { integrity, matches: integrity === script.integrity };
|
|
94
|
+
if (save !== null && served.matches) {
|
|
95
|
+
try {
|
|
96
|
+
await deps.writeFile(save, bytes);
|
|
97
|
+
saved = { path: save, bytes: bytes.byteLength };
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
failure = { code: 'save_failed', message: `Could not write ${save}.`, display: `파일을 저장할 수 없습니다: ${save}` };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (script && file !== null) {
|
|
106
|
+
try {
|
|
107
|
+
const integrity = integrityOf(await deps.readFile(file));
|
|
108
|
+
local = { path: file, integrity, matches: integrity === script.integrity };
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
failure = { code: 'file_unreadable', message: `Could not read ${file}.`, display: `파일을 읽을 수 없습니다: ${file}` };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!failure && (served?.matches === false || local?.matches === false))
|
|
115
|
+
failure = MISMATCH;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
failure = controller.signal.aborted
|
|
119
|
+
? { code: 'connection_timeout', message: 'The connection timed out.', display: '서버 응답 대기 시간이 초과되었습니다.' }
|
|
120
|
+
: { code: 'connection_failed', message: 'Could not connect to the deployment server.', display: '서버 주소와 네트워크 연결을 확인하세요.' };
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
clearTimeout(timer);
|
|
124
|
+
stop();
|
|
125
|
+
}
|
|
126
|
+
if (!pretty) {
|
|
127
|
+
return agentResult(failure ? 1 : 0, {
|
|
128
|
+
command,
|
|
129
|
+
siteUrl,
|
|
130
|
+
script,
|
|
131
|
+
served,
|
|
132
|
+
...(local ? { file: local } : {}),
|
|
133
|
+
...(saved ? { saved } : {}),
|
|
134
|
+
...(failure ? { error: failureError(failure) } : {})
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const rows = [['서버', siteUrl]];
|
|
138
|
+
if (script)
|
|
139
|
+
rows.push(['스크립트', script.src], ['무결성', script.integrity], ['다운로드', script.download]);
|
|
140
|
+
if (served)
|
|
141
|
+
rows.push(['서빙 파일', served.matches ? '일치' : `불일치 (${served.integrity})`]);
|
|
142
|
+
if (local)
|
|
143
|
+
rows.push(['로컬 파일', local.matches ? `일치 (${local.path})` : `불일치 (${local.integrity})`]);
|
|
144
|
+
if (saved)
|
|
145
|
+
rows.push(['저장', `${saved.path} (${saved.bytes} bytes)`]);
|
|
146
|
+
if (!failure)
|
|
147
|
+
return prettyResult(0, depth, command, '스크립트 해시가 매니페스트와 일치합니다.', rows);
|
|
148
|
+
return prettyResult(1, depth, command, failure.code === 'integrity_mismatch' ? failure.display : '스크립트를 확인하지 못했습니다.', [...rows, ['원인', failure.display]]);
|
|
149
|
+
}
|