@deepdynamic/cli 0.0.0-stage → 0.1.1
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 +190 -0
- package/dist/agents/refresh.js +20 -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 +60 -0
- package/dist/commands/dns.js +777 -0
- package/dist/commands/domains.js +639 -0
- package/dist/commands/emails.js +74 -0
- package/dist/commands/env.js +194 -0
- package/dist/commands/help.js +148 -0
- package/dist/commands/keys.js +263 -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 +133 -0
- package/dist/commands/plan.js +355 -0
- package/dist/commands/projects.js +838 -0
- package/dist/commands/reference.js +2187 -0
- package/dist/commands/search.js +86 -0
- package/dist/commands/server.js +301 -0
- package/dist/commands/sessions.js +114 -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 +100 -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 +37 -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/refresh-skills.js +5 -0
- package/dist/registry.js +688 -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 +55 -0
- package/dist/runtime/error-hints.js +26 -0
- package/dist/runtime/flags.js +48 -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 +28 -0
- package/dist/runtime/spinner.js +17 -0
- package/dist/runtime/suggest.js +22 -0
- package/dist/runtime/support.js +13 -0
- package/dist/runtime/text-file.js +20 -0
- package/dist/runtime/timeout.js +22 -0
- package/dist/runtime/update-check.js +158 -0
- package/dist/runtime/update-install.js +80 -0
- package/dist/runtime/usage-error.js +9 -0
- package/dist/setup-agents.js +15 -0
- package/dist/site.js +1 -0
- package/dist/update-refresh.js +5 -0
- package/package.json +46 -3
|
@@ -0,0 +1,639 @@
|
|
|
1
|
+
import { authorized, defaultAuthDeps, loginSiteUrl, signedIn } from "../auth/session.js";
|
|
2
|
+
import { LOGIN_EXPIRED, UNEXPECTED, httpFailure, postJson, request, sendFailureError } from "../http/request.js";
|
|
3
|
+
import { agentResult } from "../output.js";
|
|
4
|
+
import { prettyResult } from "../pretty.js";
|
|
5
|
+
import { cardRequired, requestCard } from "../runtime/card-request.js";
|
|
6
|
+
import { cleanDomain, isDomain } from "../runtime/domain-name.js";
|
|
7
|
+
import { spec } from "../registry.js";
|
|
8
|
+
import { confirmationRequired, splitYes } from "../runtime/confirm.js";
|
|
9
|
+
import { pageRows, pagination, parsePage } from "../runtime/page.js";
|
|
10
|
+
import { plannedChange, plannedRequest, rehearse, splitDryRun } from "../runtime/dry-run.js";
|
|
11
|
+
import { parseFlags, unknownArgument } from "../runtime/flags.js";
|
|
12
|
+
import { PROJECT } from "../runtime/project-name.js";
|
|
13
|
+
import { supportFailure } from "../runtime/support.js";
|
|
14
|
+
export const DOMAINS_PATH = '/api/v1/domains';
|
|
15
|
+
export const DOMAIN_MIN_YEARS = { ai: 2 };
|
|
16
|
+
export const DOMAIN_SEARCH_MAX_TLDS = 25;
|
|
17
|
+
const LABEL = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
18
|
+
const TLDS_VALUE = /^[a-z]+(\.[a-z]+)*(,[a-z]+(\.[a-z]+)*)*$/;
|
|
19
|
+
const TLDS_HELP = 'deepdynamic domains tlds';
|
|
20
|
+
const YEARS = /^[123]$/;
|
|
21
|
+
const TOTAL = /^[1-9]\d{0,9}$/;
|
|
22
|
+
const NO_AUTO_RENEW = '--no-auto-renew';
|
|
23
|
+
const YES = '--yes';
|
|
24
|
+
const SEOUL_OFFSET_MS = 9 * 3_600_000;
|
|
25
|
+
const EXPIRY_WARNING = 'The domain expires after its expiry date. Someone else can then register it first, and its site connection is cut as well.';
|
|
26
|
+
const NO_PROJECT = 'No project';
|
|
27
|
+
const DNS_ONLY = 'None (DNS only; connect a site later with deepdynamic dns restore)';
|
|
28
|
+
const REMOVE_EFFECT = 'A registration still waiting for the ownership check is only deleted. For a connected domain, its DNS zone, the records in it and its HTTPS certificate are deleted, and the site stops opening on the domain.';
|
|
29
|
+
const REMOVE_WARNING = 'If you changed the nameservers to DeepDynamic, change them back at your registrar so that mail and other records answer again. If you connected with CNAME, delete the 2 CNAME records you added.';
|
|
30
|
+
const DNS_LABELS = { ns: 'Nameservers', cname: 'CNAME records' };
|
|
31
|
+
const VERIFIED = {
|
|
32
|
+
ns: { pending: 'Verified ownership. Waiting for the nameserver change.', ready: 'Verified ownership. The nameservers are connected.' },
|
|
33
|
+
cname: { pending: 'Verified ownership. Waiting for the CNAME records.', ready: 'Verified ownership. The CNAME records are connected.' }
|
|
34
|
+
};
|
|
35
|
+
const failureOf = (code, message, display = message) => ({ code, message, display });
|
|
36
|
+
const PROJECT_NOT_FOUND = failureOf('project_not_found', 'You have no project with that name. Check the name with deepdynamic projects.');
|
|
37
|
+
const DOMAIN_NOT_FOUND = failureOf('domain_not_found', 'The domain is not in your domain list. Check it with deepdynamic domains.');
|
|
38
|
+
const DOMAIN_PURCHASED = failureOf('domain_purchased', 'The domain was bought through DeepDynamic and is already managed with deepdynamic domains and deepdynamic dns, so it cannot be registered as a domain bought elsewhere.', 'The domain was bought through DeepDynamic. Manage it directly with deepdynamic domains and deepdynamic dns.');
|
|
39
|
+
const DNS_LOOKUP_FAILED = supportFailure('dns_lookup_failed', { note: 'Nothing was changed.' });
|
|
40
|
+
const CLAIM_NOT_FOUND = failureOf('claim_not_found', 'The domain is neither waiting for an ownership check nor connected to your account. Register it first with deepdynamic domains register <domain> [--project <project>]; a registration that is not verified within 7 days expires.', 'The domain is not waiting for an ownership check. Register it first with deepdynamic domains register.');
|
|
41
|
+
const REGISTER_FAILURES = {
|
|
42
|
+
project_not_found: PROJECT_NOT_FOUND,
|
|
43
|
+
domain_purchased: DOMAIN_PURCHASED,
|
|
44
|
+
already_registered: failureOf('already_registered', 'The domain is already connected to your account. Check it with deepdynamic domains. To change its project or mode, disconnect it with deepdynamic domains remove <domain> --yes and register it again.', 'The domain is already connected. To change its project or DNS mode, disconnect it with deepdynamic domains remove and register it again.'),
|
|
45
|
+
limit_reached: failureOf('limit_reached', 'The account already has 10 domains bought elsewhere, counting the ones still waiting for the ownership check. Disconnect one with deepdynamic domains remove <domain> --yes first.', 'An account can connect up to 10 domains bought elsewhere, including the ones waiting for the ownership check.'),
|
|
46
|
+
site_unavailable: failureOf('site_unavailable', 'The project name cannot be used as a site address. Rename the project with deepdynamic projects rename.'),
|
|
47
|
+
dns_lookup_failed: DNS_LOOKUP_FAILED
|
|
48
|
+
};
|
|
49
|
+
const VERIFY_FAILURES = {
|
|
50
|
+
claim_not_found: CLAIM_NOT_FOUND,
|
|
51
|
+
txt_not_found: failureOf('txt_not_found', 'The ownership TXT record was not found. Show the user error.record and ask them to add it at the DNS provider where the domain was bought (name error.record.name, value error.record.value), then run deepdynamic domains verify <domain> again a few minutes later.', 'The ownership TXT record was not found. If you added it, run the command again in a few minutes.'),
|
|
52
|
+
domain_purchased: DOMAIN_PURCHASED,
|
|
53
|
+
dns_lookup_failed: DNS_LOOKUP_FAILED
|
|
54
|
+
};
|
|
55
|
+
const REMOVE_FAILURES = {
|
|
56
|
+
not_found: DOMAIN_NOT_FOUND,
|
|
57
|
+
domain_purchased: failureOf('domain_purchased', 'The domain was bought through DeepDynamic, and only domains bought elsewhere can be disconnected.', 'Domains bought through DeepDynamic cannot be disconnected.')
|
|
58
|
+
};
|
|
59
|
+
const AUTO_RENEW_FAILURES = {
|
|
60
|
+
external_domain: failureOf('external_domain', 'The domain was bought elsewhere, so it renews at the registrar where it was bought. Tell the user to change auto-renew there.', 'The domain was bought elsewhere. Change auto-renew at the registrar where you bought it.')
|
|
61
|
+
};
|
|
62
|
+
const target = (name) => {
|
|
63
|
+
const { usage } = spec(name);
|
|
64
|
+
return { command: name, usage };
|
|
65
|
+
};
|
|
66
|
+
const LIST = target('domains');
|
|
67
|
+
const SEARCH = target('domains search');
|
|
68
|
+
const TLDS = target('domains tlds');
|
|
69
|
+
const BUY = target('domains buy');
|
|
70
|
+
const REGISTER = target('domains register');
|
|
71
|
+
const VERIFY = target('domains verify');
|
|
72
|
+
const REMOVE = target('domains remove');
|
|
73
|
+
const AUTO_RENEW = target('domains auto-renew');
|
|
74
|
+
const PAYMENT_FAILURES = {
|
|
75
|
+
payment_declined: failureOf('payment_declined', 'The card company declined the payment, so nothing was charged or bought. reason holds its answer when it gave one. Ask the user to check the card or register another one, then run the same command again.', 'The card company declined the payment, so nothing was charged. Check the card or register another one, then try again.'),
|
|
76
|
+
payment_unavailable: supportFailure('payment_unavailable', { note: 'Nothing was charged or bought.' })
|
|
77
|
+
};
|
|
78
|
+
const krw = (amount) => `${amount.toLocaleString('en-US')} KRW`;
|
|
79
|
+
const counted = (count, noun) => `${count.toLocaleString('en-US')} ${noun}${count === 1 ? '' : 's'}`;
|
|
80
|
+
const seoulToday = (now) => new Date(now.getTime() + SEOUL_OFFSET_MS).toISOString().slice(0, 10);
|
|
81
|
+
const domainUrl = (siteUrl, domain, action) => new URL(`${DOMAINS_PATH}/${encodeURIComponent(domain)}/${action}`, siteUrl).href;
|
|
82
|
+
const getWithToken = (url, token, deps, spinner) => request(url, { method: 'GET', headers: { authorization: `Bearer ${token}` } }, deps, spinner);
|
|
83
|
+
function addYears(date, years) {
|
|
84
|
+
const [year, month, day] = date.split('-');
|
|
85
|
+
return `${Number(year) + years}-${month}-${month === '02' && day === '29' ? '28' : day}`;
|
|
86
|
+
}
|
|
87
|
+
const dateLabel = (date) => date.slice(0, 10);
|
|
88
|
+
const seoulDateLabel = (iso) => seoulToday(new Date(iso));
|
|
89
|
+
const recordRows = ({ name, value }) => [['TXT name', name], ['TXT value', value]];
|
|
90
|
+
const cnameRows = (connect) => (connect ?? []).map(({ name, value }) => ['CNAME', `${name} → ${value}`]);
|
|
91
|
+
const connectionLabel = ({ dns, status }) => status === 'ready' ? 'connected' : dns === 'ns' ? 'awaiting nameserver change' : 'awaiting CNAME records';
|
|
92
|
+
function domainLabel(item) {
|
|
93
|
+
const project = item.project ?? NO_PROJECT;
|
|
94
|
+
if (item.expiresAt)
|
|
95
|
+
return `${project} · until ${dateLabel(item.expiresAt)} · auto-renew ${item.autoRenew ? 'on' : 'off'}`;
|
|
96
|
+
if (item.verification)
|
|
97
|
+
return `${project} · external · awaiting ownership check · verify by ${seoulDateLabel(item.verification.expiresAt)}`;
|
|
98
|
+
return `${project} · external · ${connectionLabel(item)}`;
|
|
99
|
+
}
|
|
100
|
+
const txtRecordOf = (result) => ('failure' in result ? undefined : result.body?.record);
|
|
101
|
+
function parseDomain(input) {
|
|
102
|
+
if (input === undefined || input.startsWith('-'))
|
|
103
|
+
return { error: 'Specify the domain, such as example.com.' };
|
|
104
|
+
const domain = cleanDomain(input);
|
|
105
|
+
return isDomain(domain) ? domain : { error: 'Write the domain in a form such as example.com.' };
|
|
106
|
+
}
|
|
107
|
+
function parseProject(value) {
|
|
108
|
+
if (value === undefined)
|
|
109
|
+
return null;
|
|
110
|
+
if (PROJECT.test(value))
|
|
111
|
+
return value;
|
|
112
|
+
return { error: '--project must be a project name of 1-63 lowercase letters, digits or hyphens that starts and ends with a letter or digit.' };
|
|
113
|
+
}
|
|
114
|
+
function flagValues(args, flags) {
|
|
115
|
+
const parsed = parseFlags(args, flags);
|
|
116
|
+
if ('error' in parsed)
|
|
117
|
+
return parsed;
|
|
118
|
+
const repeated = flags.find((flag) => parsed.entries.filter(([name]) => name === flag).length > 1);
|
|
119
|
+
if (repeated)
|
|
120
|
+
return { error: `Give ${repeated} once.` };
|
|
121
|
+
return { values: Object.fromEntries(parsed.entries) };
|
|
122
|
+
}
|
|
123
|
+
function invalid({ command, usage }, error, pretty, depth) {
|
|
124
|
+
return pretty
|
|
125
|
+
? prettyResult(2, depth, command, error, [['Usage', usage]])
|
|
126
|
+
: agentResult(2, { command, error: { code: 'invalid_arguments', message: error }, usage });
|
|
127
|
+
}
|
|
128
|
+
async function planned(target, prepared, pretty, deps) {
|
|
129
|
+
const session = await signedIn(deps);
|
|
130
|
+
if ('login' in session)
|
|
131
|
+
return session.login;
|
|
132
|
+
await rehearse(target.command, prepared.steps, pretty, deps.stream, deps.pause);
|
|
133
|
+
return prepared.finish(session.siteUrl);
|
|
134
|
+
}
|
|
135
|
+
function domainFailure(result, notFound, known = {}) {
|
|
136
|
+
if ('failure' in result)
|
|
137
|
+
return result.failure;
|
|
138
|
+
if (result.status === 200 && result.body?.ok === true)
|
|
139
|
+
return null;
|
|
140
|
+
const code = result.body?.code;
|
|
141
|
+
if (typeof code === 'string' && Object.hasOwn(known, code))
|
|
142
|
+
return known[code];
|
|
143
|
+
if (result.status === 401)
|
|
144
|
+
return LOGIN_EXPIRED;
|
|
145
|
+
if (result.status === 403)
|
|
146
|
+
return failureOf('login_required', 'The access token is not allowed to do this. Run deepdynamic login again.');
|
|
147
|
+
if (result.status === 404)
|
|
148
|
+
return notFound;
|
|
149
|
+
if (result.status === 400) {
|
|
150
|
+
return result.body?.unsupportedTld === true
|
|
151
|
+
? { ...failureOf('unsupported_tld', `The TLD is not supported. List supported TLDs with ${TLDS_HELP}.`), retryable: false }
|
|
152
|
+
: failureOf('invalid_arguments', 'The server rejected the request. Check the arguments against the command help.');
|
|
153
|
+
}
|
|
154
|
+
if (result.status === 409) {
|
|
155
|
+
return result.body?.total
|
|
156
|
+
? failureOf('price_changed', 'The price changed. Check the new total and run again with it.')
|
|
157
|
+
: failureOf('domain_unavailable', 'The domain cannot be bought.');
|
|
158
|
+
}
|
|
159
|
+
if (result.status === 422)
|
|
160
|
+
return supportFailure('registration_rejected');
|
|
161
|
+
if (result.status === 429)
|
|
162
|
+
return failureOf('rate_limited', 'Too many requests. Try again in a minute.');
|
|
163
|
+
return httpFailure(result.status);
|
|
164
|
+
}
|
|
165
|
+
function errorBody(result, failure) {
|
|
166
|
+
const error = sendFailureError(result, failure);
|
|
167
|
+
if (failure.code === 'unsupported_tld')
|
|
168
|
+
return { ...error, next: TLDS_HELP };
|
|
169
|
+
if (failure.code === 'dns_lookup_failed')
|
|
170
|
+
return { ...error, retryable: true };
|
|
171
|
+
if (failure.code === 'txt_not_found')
|
|
172
|
+
return { ...error, record: txtRecordOf(result) };
|
|
173
|
+
return error;
|
|
174
|
+
}
|
|
175
|
+
function failed(target, result, failure, pretty, depth, siteUrl, message, extra = {}, rows = []) {
|
|
176
|
+
return pretty
|
|
177
|
+
? prettyResult(1, depth, target.command, message, [['Server', siteUrl], ['Reason', failure.display], ...rows])
|
|
178
|
+
: agentResult(1, { command: target.command, siteUrl, ...extra, error: errorBody(result, failure) });
|
|
179
|
+
}
|
|
180
|
+
export async function runDomainsList(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
181
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
182
|
+
const page = parsePage(rest);
|
|
183
|
+
if (typeof page !== 'number')
|
|
184
|
+
return invalid(LIST, page.error, pretty, depth);
|
|
185
|
+
const listUrl = (siteUrl) => `${new URL(DOMAINS_PATH, siteUrl).href}?page=${page}`;
|
|
186
|
+
if (dryRun) {
|
|
187
|
+
return planned(LIST, {
|
|
188
|
+
steps: [{ stage: 'prepare_request', message: 'Preparing the domain list request.' }],
|
|
189
|
+
finish: (siteUrl) => plannedRequest(LIST.command, pretty, depth, siteUrl, listUrl(siteUrl))
|
|
190
|
+
}, pretty, deps);
|
|
191
|
+
}
|
|
192
|
+
const sent = await authorized(deps, ({ siteUrl, token }) => getWithToken(listUrl(siteUrl), token, deps, pretty ? 'Loading domains.' : null));
|
|
193
|
+
if ('login' in sent)
|
|
194
|
+
return sent.login;
|
|
195
|
+
const { session: { siteUrl }, result } = sent;
|
|
196
|
+
const failure = domainFailure(result, httpFailure(404));
|
|
197
|
+
if (failure)
|
|
198
|
+
return failed(LIST, result, failure, pretty, depth, siteUrl, 'Could not load the domain list.');
|
|
199
|
+
const { domains, ...paged } = result.body;
|
|
200
|
+
const paging = pagination(paged, LIST.command);
|
|
201
|
+
if (!pretty)
|
|
202
|
+
return agentResult(0, { command: LIST.command, siteUrl, ...paging, domains });
|
|
203
|
+
return prettyResult(0, depth, LIST.command, domains.length ? `Loaded ${counted(domains.length, 'domain')}.` : 'You have no bought or connected domains.', [
|
|
204
|
+
['Server', siteUrl],
|
|
205
|
+
...domains.map((item) => [item.domain, domainLabel(item)]),
|
|
206
|
+
...pageRows(paging)
|
|
207
|
+
]);
|
|
208
|
+
}
|
|
209
|
+
function searchName(input) {
|
|
210
|
+
if (input === undefined || input.startsWith('-'))
|
|
211
|
+
return { error: 'Specify the name to search, such as my-brand.' };
|
|
212
|
+
const name = cleanDomain(input);
|
|
213
|
+
if (!LABEL.test(name.split('.')[0])) {
|
|
214
|
+
return { error: 'The name must be up to 63 lowercase letters, digits or hyphens and cannot start or end with a hyphen. A suffix such as .com may follow.' };
|
|
215
|
+
}
|
|
216
|
+
return name;
|
|
217
|
+
}
|
|
218
|
+
function searchTlds(name, value) {
|
|
219
|
+
if (value === undefined)
|
|
220
|
+
return null;
|
|
221
|
+
if (name.includes('.'))
|
|
222
|
+
return { error: 'Do not give --tlds when the name already has a TLD.' };
|
|
223
|
+
const tlds = value.trim().toLowerCase();
|
|
224
|
+
if (TLDS_VALUE.test(tlds) && new Set(tlds.split(',')).size <= DOMAIN_SEARCH_MAX_TLDS)
|
|
225
|
+
return tlds;
|
|
226
|
+
return { error: `--tlds must be up to ${DOMAIN_SEARCH_MAX_TLDS} comma-separated TLDs, such as site,online.` };
|
|
227
|
+
}
|
|
228
|
+
function priceLabel(price, renewalPrice, minYears) {
|
|
229
|
+
const term = minYears > 1 ? ` / ${counted(minYears, 'year')} · ${minYears}-year minimum` : ' / 1 year';
|
|
230
|
+
const renewal = renewalPrice && renewalPrice.amount !== price.amount ? ` · renewal ${krw(renewalPrice.amount)}` : '';
|
|
231
|
+
return `${krw(price.amount)}${term}${renewal}`;
|
|
232
|
+
}
|
|
233
|
+
function searchLabel({ available, premium, price, renewalPrice, minYears }) {
|
|
234
|
+
if (!available)
|
|
235
|
+
return 'taken';
|
|
236
|
+
return `${premium ? 'premium' : 'available'}${price ? ` · ${priceLabel(price, renewalPrice, minYears)}` : ''}`;
|
|
237
|
+
}
|
|
238
|
+
export async function runDomainsSearch(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
239
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
240
|
+
const [input, ...options] = rest;
|
|
241
|
+
const name = searchName(input);
|
|
242
|
+
if (typeof name !== 'string')
|
|
243
|
+
return invalid(SEARCH, name.error, pretty, depth);
|
|
244
|
+
const flags = flagValues(options, ['--tlds']);
|
|
245
|
+
if ('error' in flags)
|
|
246
|
+
return invalid(SEARCH, flags.error, pretty, depth);
|
|
247
|
+
const tlds = searchTlds(name, flags.values['--tlds']);
|
|
248
|
+
if (tlds !== null && typeof tlds !== 'string')
|
|
249
|
+
return invalid(SEARCH, tlds.error, pretty, depth);
|
|
250
|
+
const searchUrl = (siteUrl) => {
|
|
251
|
+
const url = new URL(`${DOMAINS_PATH}/search`, siteUrl);
|
|
252
|
+
url.searchParams.set('name', name);
|
|
253
|
+
if (tlds)
|
|
254
|
+
url.searchParams.set('tlds', tlds);
|
|
255
|
+
return url.href;
|
|
256
|
+
};
|
|
257
|
+
const siteUrl = await loginSiteUrl();
|
|
258
|
+
if (dryRun) {
|
|
259
|
+
await rehearse(SEARCH.command, [
|
|
260
|
+
{ stage: 'validate_name', message: 'Checking the domain name format.' },
|
|
261
|
+
{ stage: 'prepare_request', message: 'Preparing the search request.' }
|
|
262
|
+
], pretty, deps.stream, deps.pause);
|
|
263
|
+
return plannedRequest(SEARCH.command, pretty, depth, siteUrl, searchUrl(siteUrl));
|
|
264
|
+
}
|
|
265
|
+
const result = await request(searchUrl(siteUrl), { method: 'GET' }, deps, pretty ? 'Checking availability.' : null);
|
|
266
|
+
const failure = domainFailure(result, httpFailure(404));
|
|
267
|
+
if (failure)
|
|
268
|
+
return failed(SEARCH, result, failure, pretty, depth, siteUrl, 'Could not check availability.', { name });
|
|
269
|
+
const results = result.body.results;
|
|
270
|
+
if (!pretty)
|
|
271
|
+
return agentResult(0, { command: SEARCH.command, siteUrl, name, results });
|
|
272
|
+
return prettyResult(0, depth, SEARCH.command, results.length ? 'Checked availability.' : 'No results came back. Search again in a moment.', [
|
|
273
|
+
['Server', siteUrl],
|
|
274
|
+
...results.map((item) => [item.domain, searchLabel(item)]),
|
|
275
|
+
...(results.some(({ available }) => available) ? [['Buy', 'deepdynamic domains buy <domain> [--project <project>]']] : [])
|
|
276
|
+
]);
|
|
277
|
+
}
|
|
278
|
+
export async function runDomainsTlds(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
279
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
280
|
+
if (rest.length)
|
|
281
|
+
return invalid(TLDS, unknownArgument(rest[0]), pretty, depth);
|
|
282
|
+
const siteUrl = await loginSiteUrl();
|
|
283
|
+
const url = new URL(`${DOMAINS_PATH}/tlds`, siteUrl).href;
|
|
284
|
+
if (dryRun) {
|
|
285
|
+
await rehearse(TLDS.command, [{ stage: 'prepare_request', message: 'Preparing the supported TLD list request.' }], pretty, deps.stream, deps.pause);
|
|
286
|
+
return plannedRequest(TLDS.command, pretty, depth, siteUrl, url);
|
|
287
|
+
}
|
|
288
|
+
const result = await request(url, { method: 'GET' }, deps, pretty ? 'Loading supported TLDs.' : null);
|
|
289
|
+
const failure = domainFailure(result, httpFailure(404));
|
|
290
|
+
if (failure)
|
|
291
|
+
return failed(TLDS, result, failure, pretty, depth, siteUrl, 'Could not load the supported TLDs.');
|
|
292
|
+
const tlds = result.body.tlds;
|
|
293
|
+
if (!pretty)
|
|
294
|
+
return agentResult(0, { command: TLDS.command, siteUrl, tlds });
|
|
295
|
+
return prettyResult(0, depth, TLDS.command, `Loaded ${counted(tlds.length, 'supported TLD')}.`, [
|
|
296
|
+
['Server', siteUrl],
|
|
297
|
+
...tlds.map(({ tld, recommended, price, renewalPrice, minYears }) => [
|
|
298
|
+
`.${tld}`,
|
|
299
|
+
`${priceLabel(price, renewalPrice, minYears)}${recommended ? ' · recommended' : ''}`
|
|
300
|
+
])
|
|
301
|
+
]);
|
|
302
|
+
}
|
|
303
|
+
function parseBuy(rest) {
|
|
304
|
+
const autoRenew = !rest.includes(NO_AUTO_RENEW);
|
|
305
|
+
const consented = rest.includes(YES);
|
|
306
|
+
const [input, ...options] = rest.filter((arg) => arg !== NO_AUTO_RENEW && arg !== YES);
|
|
307
|
+
const domain = parseDomain(input);
|
|
308
|
+
if (typeof domain !== 'string')
|
|
309
|
+
return domain;
|
|
310
|
+
const tld = domain.slice(domain.indexOf('.') + 1);
|
|
311
|
+
const flags = flagValues(options, ['--project', '--years', '--total']);
|
|
312
|
+
if ('error' in flags)
|
|
313
|
+
return flags;
|
|
314
|
+
const project = parseProject(flags.values['--project']);
|
|
315
|
+
if (project !== null && typeof project !== 'string')
|
|
316
|
+
return project;
|
|
317
|
+
const minYears = DOMAIN_MIN_YEARS[tld] ?? 1;
|
|
318
|
+
const term = flags.values['--years'] ?? String(minYears);
|
|
319
|
+
if (!YEARS.test(term))
|
|
320
|
+
return { error: '--years must be 1, 2 or 3.' };
|
|
321
|
+
if (Number(term) < minYears)
|
|
322
|
+
return { error: `.${tld} domains need a term of at least ${minYears} years. Give --years ${minYears} or more.` };
|
|
323
|
+
const total = flags.values['--total'];
|
|
324
|
+
if (total !== undefined && !TOTAL.test(total))
|
|
325
|
+
return { error: '--total must be the total in won, such as 17900.' };
|
|
326
|
+
if (consented && total === undefined)
|
|
327
|
+
return { error: 'Give --total with the amount you confirmed together with --yes.' };
|
|
328
|
+
return { domain, project, years: Number(term), autoRenew, consented, total: total === undefined ? null : Number(total) };
|
|
329
|
+
}
|
|
330
|
+
function quoteRows(quote, until) {
|
|
331
|
+
return [
|
|
332
|
+
['Domain', quote.domain],
|
|
333
|
+
['Project', quote.project ?? DNS_ONLY],
|
|
334
|
+
['Term', counted(quote.years, 'year')],
|
|
335
|
+
['Valid until', dateLabel(until)],
|
|
336
|
+
['Auto-renew', quote.autoRenew ? `on (renews on ${dateLabel(until)})` : `off (expires on ${dateLabel(until)})`],
|
|
337
|
+
['Total', krw(quote.total.amount)],
|
|
338
|
+
...(quote.premium ? [['Price', 'Premium price set by the registry.']] : [])
|
|
339
|
+
];
|
|
340
|
+
}
|
|
341
|
+
function echoesRequest(parsed, body) {
|
|
342
|
+
const quote = body;
|
|
343
|
+
return quote?.domain === parsed.domain && quote.project === parsed.project && quote.years === parsed.years && quote.autoRenew === parsed.autoRenew
|
|
344
|
+
&& typeof quote.total?.amount === 'number' && TOTAL.test(String(quote.total.amount));
|
|
345
|
+
}
|
|
346
|
+
export async function runDomainsBuy(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
347
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
348
|
+
const parsed = parseBuy(rest);
|
|
349
|
+
if ('error' in parsed)
|
|
350
|
+
return invalid(BUY, parsed.error, pretty, depth);
|
|
351
|
+
const purchase = !dryRun && parsed.consented;
|
|
352
|
+
const payload = {
|
|
353
|
+
domain: parsed.domain,
|
|
354
|
+
...(parsed.project === null ? {} : { project: parsed.project }),
|
|
355
|
+
years: parsed.years,
|
|
356
|
+
autoRenew: parsed.autoRenew,
|
|
357
|
+
...(purchase ? { total: parsed.total } : { dryRun: true })
|
|
358
|
+
};
|
|
359
|
+
const sent = await authorized(deps, ({ siteUrl, token }) => postJson(new URL(`${DOMAINS_PATH}/purchase`, siteUrl).href, token, payload, deps, pretty ? (purchase ? 'Buying the domain.' : 'Checking the total.') : null));
|
|
360
|
+
if ('login' in sent)
|
|
361
|
+
return sent.login;
|
|
362
|
+
const { session, result } = sent;
|
|
363
|
+
const { siteUrl } = session;
|
|
364
|
+
if (cardRequired(result))
|
|
365
|
+
return requestCard(BUY.command, pretty, depth, session, deps, { domain: parsed.domain });
|
|
366
|
+
const failure = domainFailure(result, failureOf('project_not_found', 'You have no project with that name. Create it with deepdynamic projects create <name>.'), PAYMENT_FAILURES) ?? (purchase || echoesRequest(parsed, result.body) ? null : UNEXPECTED);
|
|
367
|
+
if (failure) {
|
|
368
|
+
const answer = 'failure' in result || failure === UNEXPECTED ? null : result.body;
|
|
369
|
+
const total = answer?.total;
|
|
370
|
+
const reason = failure.code === 'payment_declined' && typeof answer?.reason === 'string' ? answer.reason : null;
|
|
371
|
+
return pretty
|
|
372
|
+
? prettyResult(1, depth, BUY.command, purchase ? 'Could not buy the domain.' : 'Could not check the total.', [
|
|
373
|
+
['Server', siteUrl],
|
|
374
|
+
['Reason', failure.display],
|
|
375
|
+
...(reason ? [['Card response', reason]] : []),
|
|
376
|
+
...(total ? [['New total', krw(total.amount)]] : [])
|
|
377
|
+
])
|
|
378
|
+
: agentResult(1, { command: BUY.command, siteUrl, domain: parsed.domain, ...(total ? { total } : {}), ...(reason ? { reason } : {}), error: errorBody(result, failure) });
|
|
379
|
+
}
|
|
380
|
+
const { domain, project, years, autoRenew, premium, total, expiresAt } = result.body;
|
|
381
|
+
const quote = { domain, project, years, autoRenew, premium, total };
|
|
382
|
+
const until = expiresAt ?? addYears(seoulToday(deps.now?.() ?? new Date()), years);
|
|
383
|
+
const retry = `deepdynamic domains buy ${quote.domain}${quote.project === null ? '' : ` --project ${quote.project}`} --years ${quote.years}${quote.autoRenew ? '' : ' --no-auto-renew'} --yes --total ${quote.total.amount}`;
|
|
384
|
+
if (purchase) {
|
|
385
|
+
return pretty
|
|
386
|
+
? prettyResult(0, depth, BUY.command, `Bought ${quote.domain}.`, [['Server', siteUrl], ...quoteRows(quote, until)])
|
|
387
|
+
: agentResult(0, { command: BUY.command, siteUrl, ...quote, expiresAt: until });
|
|
388
|
+
}
|
|
389
|
+
if (dryRun) {
|
|
390
|
+
return pretty
|
|
391
|
+
? prettyResult(0, depth, BUY.command, 'Checked the total. Nothing was bought.', [['Server', siteUrl], ...quoteRows(quote, until), ['Run', retry]])
|
|
392
|
+
: agentResult(0, { command: BUY.command, siteUrl, dryRun: true, applied: false, ...quote, expiresAt: until, next: retry });
|
|
393
|
+
}
|
|
394
|
+
return pretty
|
|
395
|
+
? prettyResult(3, depth, BUY.command, 'Payment consent is required. Check the total, then run the command below.', [['Server', siteUrl], ...quoteRows(quote, until), ['Run', retry]])
|
|
396
|
+
: agentResult(3, {
|
|
397
|
+
command: BUY.command,
|
|
398
|
+
siteUrl,
|
|
399
|
+
...quote,
|
|
400
|
+
expiresAt: until,
|
|
401
|
+
error: { code: 'confirmation_required', message: `Show the user the total, and after they agree run: ${retry}`, next: retry, retryable: false }
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
function parseRegister(rest) {
|
|
405
|
+
const [input, ...options] = rest;
|
|
406
|
+
const domain = parseDomain(input);
|
|
407
|
+
if (typeof domain !== 'string')
|
|
408
|
+
return domain;
|
|
409
|
+
const flags = flagValues(options, ['--project', '--dns', '--site']);
|
|
410
|
+
if ('error' in flags)
|
|
411
|
+
return flags;
|
|
412
|
+
const project = parseProject(flags.values['--project']);
|
|
413
|
+
if (project !== null && typeof project !== 'string')
|
|
414
|
+
return project;
|
|
415
|
+
const dns = flags.values['--dns'] ?? 'ns';
|
|
416
|
+
if (dns !== 'ns' && dns !== 'cname')
|
|
417
|
+
return { error: '--dns must be ns or cname.' };
|
|
418
|
+
if (dns === 'cname' && project === null)
|
|
419
|
+
return { error: '--dns cname needs --project. Use --dns ns to connect without a project.' };
|
|
420
|
+
const site = flags.values['--site'];
|
|
421
|
+
if (site === '@' && dns !== 'cname')
|
|
422
|
+
return { error: '--site @ works only with --dns cname.' };
|
|
423
|
+
if (site !== undefined && site !== '@' && !LABEL.test(site)) {
|
|
424
|
+
return { error: '--site must be a label of 1-63 lowercase letters, digits or hyphens such as www, or @ with --dns cname.' };
|
|
425
|
+
}
|
|
426
|
+
return { domain, project, dns, site: site ?? null };
|
|
427
|
+
}
|
|
428
|
+
function plannedHost({ domain, dns, site }) {
|
|
429
|
+
if (site === '@')
|
|
430
|
+
return domain;
|
|
431
|
+
if (site)
|
|
432
|
+
return `${site}.${domain}`;
|
|
433
|
+
return dns === 'ns' ? `www.${domain}` : `www.${domain} or ${domain} (www is added to an apex domain; a subdomain is used as is)`;
|
|
434
|
+
}
|
|
435
|
+
export async function runDomainsRegister(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
436
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
437
|
+
const parsed = parseRegister(rest);
|
|
438
|
+
if ('error' in parsed)
|
|
439
|
+
return invalid(REGISTER, parsed.error, pretty, depth);
|
|
440
|
+
const { domain, project, dns, site } = parsed;
|
|
441
|
+
const payload = { domain, ...(project === null ? {} : { project }), dns, ...(site === null ? {} : { site }) };
|
|
442
|
+
const next = `deepdynamic domains verify ${domain}`;
|
|
443
|
+
if (dryRun) {
|
|
444
|
+
return planned(REGISTER, {
|
|
445
|
+
steps: [
|
|
446
|
+
{ stage: 'validate_domain', message: 'Checking the domain format.' },
|
|
447
|
+
{ stage: 'validate_project', message: 'Checking the project name.' },
|
|
448
|
+
{ stage: 'validate_dns', message: 'Checking the DNS mode and site name.' },
|
|
449
|
+
{ stage: 'prepare_request', message: 'Preparing the registration request.' }
|
|
450
|
+
],
|
|
451
|
+
finish: (siteUrl) => plannedChange(REGISTER.command, pretty, depth, siteUrl, { url: new URL(DOMAINS_PATH, siteUrl).href, body: payload }, 'Checked the registration. Nothing was registered.', [
|
|
452
|
+
['Domain', domain],
|
|
453
|
+
['Project', project ?? DNS_ONLY],
|
|
454
|
+
['DNS mode', DNS_LABELS[dns]],
|
|
455
|
+
['Site URL', plannedHost(parsed)],
|
|
456
|
+
['Notice', `Registering makes the server create an ownership TXT record and return it. Add that record in the DNS settings at your registrar, then verify ownership with ${next}.`]
|
|
457
|
+
], { domain, project, dns, site })
|
|
458
|
+
}, pretty, deps);
|
|
459
|
+
}
|
|
460
|
+
const sent = await authorized(deps, ({ siteUrl, token }) => postJson(new URL(DOMAINS_PATH, siteUrl).href, token, payload, deps, pretty ? 'Registering the domain.' : null));
|
|
461
|
+
if ('login' in sent)
|
|
462
|
+
return sent.login;
|
|
463
|
+
const { session: { siteUrl }, result } = sent;
|
|
464
|
+
const failure = domainFailure(result, PROJECT_NOT_FOUND, REGISTER_FAILURES);
|
|
465
|
+
if (failure)
|
|
466
|
+
return failed(REGISTER, result, failure, pretty, depth, siteUrl, 'Could not register the domain.', { domain });
|
|
467
|
+
const registered = result.body;
|
|
468
|
+
const view = {
|
|
469
|
+
domain: registered.domain,
|
|
470
|
+
project: registered.project,
|
|
471
|
+
dns: registered.dns,
|
|
472
|
+
siteHost: registered.siteHost,
|
|
473
|
+
record: registered.record,
|
|
474
|
+
expiresAt: registered.expiresAt,
|
|
475
|
+
connect: registered.connect
|
|
476
|
+
};
|
|
477
|
+
if (!pretty)
|
|
478
|
+
return agentResult(0, { command: REGISTER.command, siteUrl, ...view, next });
|
|
479
|
+
return prettyResult(0, depth, REGISTER.command, `Registered ${view.domain}. Add the ownership TXT record.`, [
|
|
480
|
+
['Server', siteUrl],
|
|
481
|
+
['Domain', view.domain],
|
|
482
|
+
['Project', view.project ?? DNS_ONLY],
|
|
483
|
+
['DNS mode', DNS_LABELS[view.dns]],
|
|
484
|
+
['Site URL', view.siteHost],
|
|
485
|
+
...recordRows(view.record),
|
|
486
|
+
['Verify by', seoulDateLabel(view.expiresAt)],
|
|
487
|
+
view.dns === 'ns'
|
|
488
|
+
? ['After verification', 'Change the nameservers at your registrar to connect the domain. The nameservers to use are shown when ownership is verified.']
|
|
489
|
+
: ['After verification', 'Also add the 2 CNAME records below in the DNS settings at your registrar to connect the domain.'],
|
|
490
|
+
...cnameRows(view.connect),
|
|
491
|
+
['Next', `Add the TXT record in the DNS settings at your registrar, then verify ownership with ${next}.`]
|
|
492
|
+
]);
|
|
493
|
+
}
|
|
494
|
+
function connectionRows({ domain, dns, status, nameservers, connect, imported }) {
|
|
495
|
+
if (status === 'ready')
|
|
496
|
+
return [];
|
|
497
|
+
if (dns === 'cname') {
|
|
498
|
+
return [...cnameRows(connect), ['Next', `Add the 2 CNAME records above in the DNS settings at your registrar. They are checked automatically every 5 minutes, or run deepdynamic domains verify ${domain} to check now.`]];
|
|
499
|
+
}
|
|
500
|
+
return [
|
|
501
|
+
...(nameservers
|
|
502
|
+
? nameservers.map((nameserver) => ['Nameservers', nameserver])
|
|
503
|
+
: [['Nameservers', `Not created yet. Run deepdynamic domains verify ${domain} again in a few minutes.`]]),
|
|
504
|
+
...(imported > 0 ? [['Imported', counted(imported, 'record')]] : []),
|
|
505
|
+
['Warning', `Before changing the nameservers, check the imported records with deepdynamic dns records ${domain} and add any missing ones (mail, subdomains and so on) with deepdynamic dns add. Once the nameservers change, the records at the old DNS provider stop answering.`],
|
|
506
|
+
['Next', `Change the nameservers at your registrar to the ones above. They are checked automatically every 5 minutes, or run deepdynamic domains verify ${domain} to check now.`]
|
|
507
|
+
];
|
|
508
|
+
}
|
|
509
|
+
export async function runDomainsVerify(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
510
|
+
const { args: rest, dryRun } = splitDryRun(args);
|
|
511
|
+
const [input, ...extra] = rest;
|
|
512
|
+
const domain = parseDomain(input);
|
|
513
|
+
if (typeof domain !== 'string')
|
|
514
|
+
return invalid(VERIFY, domain.error, pretty, depth);
|
|
515
|
+
if (extra.length)
|
|
516
|
+
return invalid(VERIFY, unknownArgument(extra[0]), pretty, depth);
|
|
517
|
+
if (dryRun) {
|
|
518
|
+
return planned(VERIFY, {
|
|
519
|
+
steps: [
|
|
520
|
+
{ stage: 'validate_domain', message: 'Checking the domain format.' },
|
|
521
|
+
{ stage: 'prepare_request', message: 'Preparing the ownership check request.' }
|
|
522
|
+
],
|
|
523
|
+
finish: (siteUrl) => plannedChange(VERIFY.command, pretty, depth, siteUrl, { url: domainUrl(siteUrl, domain, 'verify'), body: {} }, 'Checked the ownership check request. Nothing was sent.', [
|
|
524
|
+
['Domain', domain],
|
|
525
|
+
['Impact', `Verifies ownership with the _deepdynamic.${domain} TXT record and connects the domain. For a domain that is already connected, only the nameservers or CNAME records are checked again.`]
|
|
526
|
+
], { domain })
|
|
527
|
+
}, pretty, deps);
|
|
528
|
+
}
|
|
529
|
+
const sent = await authorized(deps, ({ siteUrl, token }) => postJson(domainUrl(siteUrl, domain, 'verify'), token, {}, deps, pretty ? 'Checking ownership and connection.' : null));
|
|
530
|
+
if ('login' in sent)
|
|
531
|
+
return sent.login;
|
|
532
|
+
const { session: { siteUrl }, result } = sent;
|
|
533
|
+
const failure = domainFailure(result, CLAIM_NOT_FOUND, VERIFY_FAILURES);
|
|
534
|
+
if (failure) {
|
|
535
|
+
const record = failure.code === 'txt_not_found' ? txtRecordOf(result) : undefined;
|
|
536
|
+
return failed(VERIFY, result, failure, pretty, depth, siteUrl, 'Could not verify ownership.', { domain }, record ? recordRows(record) : []);
|
|
537
|
+
}
|
|
538
|
+
const body = result.body;
|
|
539
|
+
const view = {
|
|
540
|
+
domain: body.domain,
|
|
541
|
+
project: body.project,
|
|
542
|
+
dns: body.dns,
|
|
543
|
+
siteHost: body.siteHost,
|
|
544
|
+
status: body.status,
|
|
545
|
+
nameservers: body.nameservers,
|
|
546
|
+
connect: body.connect,
|
|
547
|
+
imported: body.imported
|
|
548
|
+
};
|
|
549
|
+
if (!pretty)
|
|
550
|
+
return agentResult(0, { command: VERIFY.command, siteUrl, ...view });
|
|
551
|
+
return prettyResult(0, depth, VERIFY.command, VERIFIED[view.dns][view.status], [
|
|
552
|
+
['Server', siteUrl],
|
|
553
|
+
['Domain', view.domain],
|
|
554
|
+
['Project', view.project ?? NO_PROJECT],
|
|
555
|
+
['DNS mode', DNS_LABELS[view.dns]],
|
|
556
|
+
['Site URL', view.siteHost],
|
|
557
|
+
['Status', connectionLabel(view)],
|
|
558
|
+
...connectionRows(view)
|
|
559
|
+
]);
|
|
560
|
+
}
|
|
561
|
+
export async function runDomainsRemove(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
562
|
+
const { args: plain, dryRun } = splitDryRun(args);
|
|
563
|
+
const { args: rest, yes } = splitYes(plain);
|
|
564
|
+
const [input, ...extra] = rest;
|
|
565
|
+
const domain = parseDomain(input);
|
|
566
|
+
if (typeof domain !== 'string')
|
|
567
|
+
return invalid(REMOVE, domain.error, pretty, depth);
|
|
568
|
+
if (extra.length)
|
|
569
|
+
return invalid(REMOVE, unknownArgument(extra[0]), pretty, depth);
|
|
570
|
+
if (dryRun) {
|
|
571
|
+
return planned(REMOVE, {
|
|
572
|
+
steps: [
|
|
573
|
+
{ stage: 'validate_domain', message: 'Checking the domain format.' },
|
|
574
|
+
{ stage: 'review_impact', message: 'Reviewing what disconnecting changes.' },
|
|
575
|
+
{ stage: 'prepare_request', message: 'Preparing the disconnect request.' }
|
|
576
|
+
],
|
|
577
|
+
finish: (siteUrl) => plannedChange(REMOVE.command, pretty, depth, siteUrl, { url: domainUrl(siteUrl, domain, 'remove'), body: {} }, 'Checked the disconnect. Nothing was disconnected.', [['Domain', domain], ['Impact', REMOVE_EFFECT], ['Warning', REMOVE_WARNING]], { domain })
|
|
578
|
+
}, pretty, deps);
|
|
579
|
+
}
|
|
580
|
+
if (!yes) {
|
|
581
|
+
return confirmationRequired(REMOVE.command, [domain], pretty, depth, {
|
|
582
|
+
message: 'Removing deletes the DNS zone, its records and the HTTPS certificate of the domain, and the site stops opening on it.',
|
|
583
|
+
display: 'Disconnecting deletes the DNS zone, its records and the HTTPS certificate of this domain, and the site stops opening on it. Confirm with the user, then run it again with --yes.'
|
|
584
|
+
}, { domain });
|
|
585
|
+
}
|
|
586
|
+
const sent = await authorized(deps, ({ siteUrl, token }) => postJson(domainUrl(siteUrl, domain, 'remove'), token, {}, deps, pretty ? 'Disconnecting the domain.' : null));
|
|
587
|
+
if ('login' in sent)
|
|
588
|
+
return sent.login;
|
|
589
|
+
const { session: { siteUrl }, result } = sent;
|
|
590
|
+
const failure = domainFailure(result, DOMAIN_NOT_FOUND, REMOVE_FAILURES);
|
|
591
|
+
if (failure)
|
|
592
|
+
return failed(REMOVE, result, failure, pretty, depth, siteUrl, 'Could not disconnect the domain.', { domain });
|
|
593
|
+
return pretty
|
|
594
|
+
? prettyResult(0, depth, REMOVE.command, `Disconnected ${domain}.`, [['Server', siteUrl], ['Domain', domain], ['Warning', REMOVE_WARNING]])
|
|
595
|
+
: agentResult(0, { command: REMOVE.command, siteUrl, domain, removed: true });
|
|
596
|
+
}
|
|
597
|
+
export async function runDomainsAutoRenew(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
598
|
+
const { args: plain, dryRun } = splitDryRun(args);
|
|
599
|
+
const { args: rest, yes } = splitYes(plain);
|
|
600
|
+
const [input, state, ...extra] = rest;
|
|
601
|
+
const domain = parseDomain(input);
|
|
602
|
+
if (typeof domain !== 'string')
|
|
603
|
+
return invalid(AUTO_RENEW, domain.error, pretty, depth);
|
|
604
|
+
if (state !== 'on' && state !== 'off')
|
|
605
|
+
return invalid(AUTO_RENEW, 'Give on or off after the domain.', pretty, depth);
|
|
606
|
+
if (extra.length)
|
|
607
|
+
return invalid(AUTO_RENEW, unknownArgument(extra[0]), pretty, depth);
|
|
608
|
+
const enabled = state === 'on';
|
|
609
|
+
const effect = enabled ? [] : [['Warning', EXPIRY_WARNING]];
|
|
610
|
+
if (dryRun) {
|
|
611
|
+
return planned(AUTO_RENEW, {
|
|
612
|
+
steps: [
|
|
613
|
+
{ stage: 'validate_domain', message: 'Checking the domain format.' },
|
|
614
|
+
{ stage: 'plan_renewal', message: 'Reviewing the expiry impact.' },
|
|
615
|
+
{ stage: 'prepare_request', message: 'Preparing the auto-renew change request.' }
|
|
616
|
+
],
|
|
617
|
+
finish: (siteUrl) => plannedChange(AUTO_RENEW.command, pretty, depth, siteUrl, { url: domainUrl(siteUrl, domain, 'auto-renew'), body: { enabled } }, 'Checked the auto-renew change. Nothing was changed.', [['Domain', domain], ['Change', enabled ? 'Turn auto-renew on' : 'Turn auto-renew off'], ...effect], { domain, autoRenew: enabled })
|
|
618
|
+
}, pretty, deps);
|
|
619
|
+
}
|
|
620
|
+
if (!enabled && !yes) {
|
|
621
|
+
return confirmationRequired(AUTO_RENEW.command, [domain, state], pretty, depth, {
|
|
622
|
+
message: 'Turning auto-renew off lets the domain expire at the end of its term.',
|
|
623
|
+
display: 'Turning auto-renew off lets the domain expire at the end of its term. Confirm with the user, then run it again with --yes.'
|
|
624
|
+
}, { domain });
|
|
625
|
+
}
|
|
626
|
+
const sent = await authorized(deps, ({ siteUrl, token }) => postJson(domainUrl(siteUrl, domain, 'auto-renew'), token, { enabled }, deps, pretty ? 'Changing auto-renew.' : null));
|
|
627
|
+
if ('login' in sent)
|
|
628
|
+
return sent.login;
|
|
629
|
+
const { session, result } = sent;
|
|
630
|
+
const { siteUrl } = session;
|
|
631
|
+
if (cardRequired(result))
|
|
632
|
+
return requestCard(AUTO_RENEW.command, pretty, depth, session, deps, { domain });
|
|
633
|
+
const failure = domainFailure(result, DOMAIN_NOT_FOUND, AUTO_RENEW_FAILURES);
|
|
634
|
+
if (failure)
|
|
635
|
+
return failed(AUTO_RENEW, result, failure, pretty, depth, siteUrl, 'Could not change auto-renew.', { domain });
|
|
636
|
+
return pretty
|
|
637
|
+
? prettyResult(0, depth, AUTO_RENEW.command, enabled ? 'Turned auto-renew on.' : 'Turned auto-renew off.', [['Server', siteUrl], ['Domain', domain], ...effect])
|
|
638
|
+
: agentResult(0, { command: AUTO_RENEW.command, siteUrl, domain, autoRenew: enabled });
|
|
639
|
+
}
|