@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,777 @@
|
|
|
1
|
+
import { authorized, defaultAuthDeps, signedIn } from "../auth/session.js";
|
|
2
|
+
import { LOGIN_EXPIRED, accepted, 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
|
+
export const DNS_PATH = '/api/v1/dns';
|
|
14
|
+
export const DNS_SITE_DOMAIN = 'deepdynamic.dev';
|
|
15
|
+
const RECORD_TYPES = {
|
|
16
|
+
A: 'IPv4 address', AAAA: 'IPv6 address', CNAME: 'alias target', MX: 'mail server', TXT: 'verification text', CAA: 'allowed certificate authorities',
|
|
17
|
+
NS: 'nameserver delegation', PTR: 'reverse lookup', SRV: 'service location'
|
|
18
|
+
};
|
|
19
|
+
export const DNS_RECORD_TYPES = Object.keys(RECORD_TYPES);
|
|
20
|
+
const TTLS = [['auto', 1, 'auto'], ['300', 300, '5 minutes'], ['3600', 3600, '1 hour'], ['86400', 86400, '1 day']];
|
|
21
|
+
const HOST_TYPES = ['CNAME', 'MX', 'NS', 'PTR'];
|
|
22
|
+
const LABEL = '[a-z0-9_]([a-z0-9_-]*[a-z0-9])?';
|
|
23
|
+
const NAME = new RegExp(`^(@|(\\*\\.)?${LABEL}(\\.${LABEL})*|\\*)$`);
|
|
24
|
+
const HOST = /^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/;
|
|
25
|
+
const RECORD_ID = /^[a-z0-9]([a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
26
|
+
const PRIORITY = /^\d{1,5}$/;
|
|
27
|
+
const RECORD_FLAGS = ['--type', '--name', '--value', '--ttl', '--priority'];
|
|
28
|
+
const RESTORE_FLAGS = ['--project', '--name'];
|
|
29
|
+
const PROPAGATION = 'Once applied, changes usually reach DNS resolvers worldwide within a few minutes, but the previous value can stay cached for up to the TTL.';
|
|
30
|
+
const APPLIED_PROPAGATION = 'Changes usually reach DNS resolvers worldwide within a few minutes, but the previous value can stay cached for up to the TTL.';
|
|
31
|
+
const PENDING = 'DNS is being set up. This usually finishes within a few minutes.';
|
|
32
|
+
const PENDING_APPLY = 'DNS is being set up. The saved records are applied once setup finishes.';
|
|
33
|
+
const NO_PROJECT = 'No connected project';
|
|
34
|
+
const SYNC_EFFECT = 'Makes the DNS servers match the saved records. If the zone is still being set up, tries to create the zone, apply the records and switch the nameservers right now.';
|
|
35
|
+
const SYNC_WARNING = 'Records changed only on the DNS servers are not in the saved records and will be removed.';
|
|
36
|
+
const DNSSEC_STATES = { on: 'on', enabling: 'enabling', disabling: 'disabling (signing stops in 2 days)', off: 'off', unsupported: 'not supported' };
|
|
37
|
+
const DNSSEC_NOTES = {
|
|
38
|
+
on: 'The zone is signed and the DS record is registered at the registrar.',
|
|
39
|
+
enabling: 'Signing the zone and registering the DS record at the registrar. This usually finishes within a few minutes.',
|
|
40
|
+
disabling: 'Removes the DS record at the registrar and stops signing the zone 2 days later, so that cached DS records expire first.',
|
|
41
|
+
off: 'The DNS servers do not sign the zone.',
|
|
42
|
+
unsupported: 'The registrar rejected the DS record for this domain. Its TLD most likely does not support DNSSEC, so DNSSEC cannot be turned on.'
|
|
43
|
+
};
|
|
44
|
+
const DNSSEC_AFTER_ZONE = 'Zone signing and DS record registration at the registrar start once DNS setup finishes.';
|
|
45
|
+
const DNSSEC_ON_EFFECT = 'Signs the zone on the DNS servers and registers a DS record at the registrar. The request waits about 30 seconds for signing and finishes the registration; if signing takes longer, it completes within a few minutes. If DNS is still being set up, this starts once setup finishes.';
|
|
46
|
+
const DNSSEC_SCOPE = 'DNSSEC can be turned on or off only for domains bought through DeepDynamic.';
|
|
47
|
+
const CONFIRM_NEXT = 'Confirm with the user, then run it with --yes.';
|
|
48
|
+
const CHECK_DOMAIN = { stage: 'check_domain', message: 'Checking the domain format.' };
|
|
49
|
+
const CHECK_RECORD_ID = { stage: 'check_record_id', message: 'Checking the record ID format.' };
|
|
50
|
+
const CHECK_RECORD = { stage: 'check_record', message: 'Checking the record type, name and value.' };
|
|
51
|
+
const DESCRIBE_RECORD = { stage: 'describe_record', message: 'Describing how the record will work.' };
|
|
52
|
+
const PREPARE_REQUEST = { stage: 'prepare_request', message: 'Preparing the request.' };
|
|
53
|
+
const plainFailure = (code, message) => ({ code, message, display: message });
|
|
54
|
+
export const DOMAIN_NOT_FOUND = plainFailure('domain_not_found', 'The domain is not among the domains you manage. Check it with deepdynamic dns.');
|
|
55
|
+
const RECORD_NOT_FOUND = plainFailure('record_not_found', 'The domain has no record with that ID. Check it with deepdynamic dns records <domain>.');
|
|
56
|
+
const PROJECT_NOT_FOUND = plainFailure('project_not_found', 'You have no active project with that name. Check it with deepdynamic projects.');
|
|
57
|
+
const NOT_FOUND = { domain_not_found: DOMAIN_NOT_FOUND, record_not_found: RECORD_NOT_FOUND, project_not_found: PROJECT_NOT_FOUND };
|
|
58
|
+
const DNSSEC_FAILURES = {
|
|
59
|
+
external_domain: {
|
|
60
|
+
code: 'external_domain',
|
|
61
|
+
message: 'The domain was bought elsewhere, and DNSSEC can be turned on or off only for domains bought through DeepDynamic. Nothing changed; tell the user DNSSEC is not available for this domain here.',
|
|
62
|
+
display: `The domain was bought elsewhere. ${DNSSEC_SCOPE}`
|
|
63
|
+
},
|
|
64
|
+
dnssec_unsupported: {
|
|
65
|
+
code: 'dnssec_unsupported',
|
|
66
|
+
message: 'The registrar rejected the DS record of this domain, most likely because its TLD does not support DNSSEC, so DNSSEC cannot be turned on. Nothing changed; tell the user and do not retry.',
|
|
67
|
+
display: DNSSEC_NOTES.unsupported
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
export const fail = (pretty, message, display) => ({ error: pretty ? display : message });
|
|
71
|
+
const count = (total, noun) => `${total.toLocaleString('en-US')} ${noun}${total === 1 ? '' : 's'}`;
|
|
72
|
+
const hostName = (name, domain) => name === '@' ? domain : `${name}.${domain}`;
|
|
73
|
+
const ttlLabel = (seconds) => TTLS.find(([, value]) => value === seconds)?.[2] ?? `${seconds.toLocaleString('en-US')} seconds`;
|
|
74
|
+
const recordsUrl = (siteUrl, domain, suffix = '') => new URL(`${DNS_PATH}/${encodeURIComponent(domain)}/records${suffix}`, siteUrl).href;
|
|
75
|
+
const zoneState = (zone) => zone.status === 'pending' ? PENDING : zone.connected ? 'Site connected' : 'Not connected';
|
|
76
|
+
const pendingRows = (zone) => zone.status === 'pending' ? [['Pending', PENDING_APPLY]] : [];
|
|
77
|
+
const analyticsState = (zone) => zone.analytics ? `Google Analytics ${zone.analytics.measurementId} · registered ${zone.analytics.connectedAt.slice(0, 10)}` : 'Google Analytics not registered';
|
|
78
|
+
function dnssecRows(zone, explain = false) {
|
|
79
|
+
if (!zone.dnssec)
|
|
80
|
+
return [];
|
|
81
|
+
const state = ['DNSSEC', DNSSEC_STATES[zone.dnssec]];
|
|
82
|
+
if (!explain)
|
|
83
|
+
return [state];
|
|
84
|
+
return [state, ['Notice', zone.dnssec === 'enabling' && zone.status === 'pending' ? DNSSEC_AFTER_ZONE : DNSSEC_NOTES[zone.dnssec]]];
|
|
85
|
+
}
|
|
86
|
+
function normalizeName(input, domain) {
|
|
87
|
+
const name = input.trim().toLowerCase().replace(/\.$/, '');
|
|
88
|
+
if (!name || name === domain)
|
|
89
|
+
return '@';
|
|
90
|
+
return name.endsWith(`.${domain}`) ? name.slice(0, -domain.length - 1) : name;
|
|
91
|
+
}
|
|
92
|
+
function normalizeValue(type, input) {
|
|
93
|
+
const value = input.trim();
|
|
94
|
+
if (HOST_TYPES.includes(type))
|
|
95
|
+
return value.toLowerCase().replace(/\.$/, '');
|
|
96
|
+
return type === 'A' || type === 'AAAA' ? value.toLowerCase() : value;
|
|
97
|
+
}
|
|
98
|
+
function isIpv4(value) {
|
|
99
|
+
const parts = value.split('.');
|
|
100
|
+
return parts.length === 4 && parts.every((part) => /^(0|[1-9]\d{0,2})$/.test(part) && Number(part) <= 255);
|
|
101
|
+
}
|
|
102
|
+
function isIpv6(value) {
|
|
103
|
+
const halves = value.split('::');
|
|
104
|
+
if (halves.length > 2)
|
|
105
|
+
return false;
|
|
106
|
+
const groups = halves.flatMap((half) => half ? half.split(':') : []);
|
|
107
|
+
if (!groups.every((group) => /^[0-9a-f]{1,4}$/.test(group)))
|
|
108
|
+
return false;
|
|
109
|
+
return halves.length === 2 ? groups.length < 8 : groups.length === 8;
|
|
110
|
+
}
|
|
111
|
+
function describeRecord(record, domain) {
|
|
112
|
+
const host = hostName(record.name, domain);
|
|
113
|
+
if (record.type === 'A' || record.type === 'AAAA')
|
|
114
|
+
return `Points ${host} to the server at ${record.value}.`;
|
|
115
|
+
if (record.type === 'CNAME')
|
|
116
|
+
return `Points ${host} to ${record.value}.`;
|
|
117
|
+
if (record.type === 'MX')
|
|
118
|
+
return `Mail for ${host} is delivered to the server ${record.value}.`;
|
|
119
|
+
if (record.type === 'TXT')
|
|
120
|
+
return `Text for ${host}, used for ownership verification or mail security settings.`;
|
|
121
|
+
return `Sets the ${RECORD_TYPES[record.type]} for ${host}.`;
|
|
122
|
+
}
|
|
123
|
+
function recordRows(record, domain, propagation = PROPAGATION) {
|
|
124
|
+
return [
|
|
125
|
+
['Record', `${record.type} ${hostName(record.name, domain)} → ${record.value}`],
|
|
126
|
+
['TTL', ttlLabel(record.ttl)],
|
|
127
|
+
...(record.priority === undefined ? [] : [['Priority', `${record.priority} (lower values receive mail first)`]]),
|
|
128
|
+
['Description', describeRecord(record, domain)],
|
|
129
|
+
['Propagation', propagation]
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
function readFlags(args, flags) {
|
|
133
|
+
const parsed = parseFlags(args, flags);
|
|
134
|
+
if ('error' in parsed)
|
|
135
|
+
return parsed;
|
|
136
|
+
const values = {};
|
|
137
|
+
for (const [flag, value] of parsed.entries) {
|
|
138
|
+
if (values[flag] !== undefined)
|
|
139
|
+
return { error: `Give ${flag} only once.` };
|
|
140
|
+
values[flag] = value;
|
|
141
|
+
}
|
|
142
|
+
return values;
|
|
143
|
+
}
|
|
144
|
+
export function parseDomain(input, pretty) {
|
|
145
|
+
if (input === undefined || input.startsWith('-'))
|
|
146
|
+
return { error: 'Specify the domain first.' };
|
|
147
|
+
const domain = cleanDomain(input);
|
|
148
|
+
return isDomain(domain) ? domain : { error: `Not a valid domain: ${input}` };
|
|
149
|
+
}
|
|
150
|
+
function parseRecordId(input) {
|
|
151
|
+
if (input === undefined || input.startsWith('-'))
|
|
152
|
+
return { error: 'Specify the record ID after the domain.' };
|
|
153
|
+
return RECORD_ID.test(input)
|
|
154
|
+
? input
|
|
155
|
+
: { error: `Record IDs are 1-64 lowercase letters, digits or hyphens that start and end with a letter or digit, as listed by deepdynamic dns records: ${input}` };
|
|
156
|
+
}
|
|
157
|
+
function parseName(input, domain) {
|
|
158
|
+
const name = normalizeName(input, domain);
|
|
159
|
+
return NAME.test(name)
|
|
160
|
+
? name
|
|
161
|
+
: { error: `--name must be @ for the domain itself or a label such as www made of lowercase letters, digits, hyphens and underscores: ${input}` };
|
|
162
|
+
}
|
|
163
|
+
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
164
|
+
const TARGET = /^(_?[a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/i;
|
|
165
|
+
const CAA = /^(\d{1,3}) (issue|issuewild|iodef|contactemail|contactphone) ("[^"]*")$/;
|
|
166
|
+
const inRange = (token, max) => /^\d{1,5}$/.test(token) && Number(token) <= max;
|
|
167
|
+
const hostOrRoot = (token) => token === '.' || TARGET.test(token);
|
|
168
|
+
const VALUE_CHECKS = {
|
|
169
|
+
A: isIpv4,
|
|
170
|
+
AAAA: isIpv6,
|
|
171
|
+
CNAME: (value) => HOST.test(value),
|
|
172
|
+
MX: (value) => HOST.test(value),
|
|
173
|
+
NS: (value) => HOST.test(value),
|
|
174
|
+
PTR: (value) => HOST.test(value),
|
|
175
|
+
TXT: (value) => value.length <= 4000 && !CONTROL.test(value),
|
|
176
|
+
CAA: (value) => { const match = CAA.exec(value); return !!match && Number(match[1]) <= 255; },
|
|
177
|
+
SRV: (value) => { const parts = value.split(' '); return parts.length === 4 && parts.slice(0, 3).every((part) => inRange(part, 65535)) && hostOrRoot(parts[3]); }
|
|
178
|
+
};
|
|
179
|
+
const HOST_RULE = 'a host name such as mail.example.com';
|
|
180
|
+
const VALUE_RULES = {
|
|
181
|
+
A: 'an IPv4 address such as 198.51.100.24',
|
|
182
|
+
AAAA: 'an IPv6 address such as 2001:db8::1',
|
|
183
|
+
CNAME: HOST_RULE,
|
|
184
|
+
MX: HOST_RULE,
|
|
185
|
+
NS: HOST_RULE,
|
|
186
|
+
PTR: HOST_RULE,
|
|
187
|
+
TXT: '1-4000 characters without control characters',
|
|
188
|
+
CAA: 'flags tag "value" with tag issue, issuewild, iodef, contactemail or contactphone, such as 0 issue "letsencrypt.org"',
|
|
189
|
+
SRV: 'priority weight port target, such as 10 5 5060 sip.example.com'
|
|
190
|
+
};
|
|
191
|
+
function valueError(type, value, pretty) {
|
|
192
|
+
if (VALUE_CHECKS[type](value))
|
|
193
|
+
return null;
|
|
194
|
+
const message = `--value for ${type} records must be ${VALUE_RULES[type]}.`;
|
|
195
|
+
return fail(pretty, message, HOST_TYPES.includes(type) ? `${message} Do not include https://, a path or an IP address.` : message);
|
|
196
|
+
}
|
|
197
|
+
function apexError(type, name) {
|
|
198
|
+
if (name !== '@')
|
|
199
|
+
return null;
|
|
200
|
+
if (type === 'CNAME')
|
|
201
|
+
return { error: 'A CNAME cannot be on the domain itself (@). Use a name such as www.' };
|
|
202
|
+
if (type === 'NS')
|
|
203
|
+
return { error: 'The NS records of the domain itself (@) cannot be changed.' };
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
function parseRecord(args, domain, pretty) {
|
|
207
|
+
const values = readFlags(args, RECORD_FLAGS);
|
|
208
|
+
if ('error' in values)
|
|
209
|
+
return values;
|
|
210
|
+
const { '--type': rawType, '--name': rawName, '--value': rawValue, '--ttl': rawTtl, '--priority': rawPriority } = values;
|
|
211
|
+
if (rawType === undefined || rawName === undefined || rawValue === undefined) {
|
|
212
|
+
const missing = RECORD_FLAGS.find((flag) => values[flag] === undefined);
|
|
213
|
+
return { error: `${missing} is required.` };
|
|
214
|
+
}
|
|
215
|
+
const type = rawType.trim().toUpperCase();
|
|
216
|
+
if (!Object.hasOwn(RECORD_TYPES, type))
|
|
217
|
+
return { error: `--type must be one of ${DNS_RECORD_TYPES.join(', ')}: ${rawType}` };
|
|
218
|
+
const recordType = type;
|
|
219
|
+
const name = parseName(rawName, domain);
|
|
220
|
+
if (typeof name !== 'string')
|
|
221
|
+
return name;
|
|
222
|
+
const apex = apexError(recordType, name);
|
|
223
|
+
if (apex)
|
|
224
|
+
return apex;
|
|
225
|
+
const value = normalizeValue(recordType, rawValue);
|
|
226
|
+
const invalidValue = valueError(recordType, value, pretty);
|
|
227
|
+
if (invalidValue)
|
|
228
|
+
return invalidValue;
|
|
229
|
+
const ttl = rawTtl === undefined ? 1 : TTLS.find(([input]) => input === rawTtl)?.[1];
|
|
230
|
+
if (ttl === undefined)
|
|
231
|
+
return { error: `--ttl must be auto, 300, 3600 or 86400: ${rawTtl}` };
|
|
232
|
+
if (recordType !== 'MX') {
|
|
233
|
+
return rawPriority === undefined
|
|
234
|
+
? { type: recordType, name, value, ttl }
|
|
235
|
+
: { error: '--priority applies only to MX records.' };
|
|
236
|
+
}
|
|
237
|
+
if (rawPriority === undefined)
|
|
238
|
+
return { error: '--priority is required for MX records.' };
|
|
239
|
+
if (!PRIORITY.test(rawPriority) || Number(rawPriority) > 65535)
|
|
240
|
+
return { error: `--priority must be an integer from 0 to 65535: ${rawPriority}` };
|
|
241
|
+
return { type: recordType, name, value, ttl, priority: Number(rawPriority) };
|
|
242
|
+
}
|
|
243
|
+
const getWithToken = (url, token, deps, spinner) => request(url, { method: 'GET', headers: { authorization: `Bearer ${token}` } }, deps, spinner);
|
|
244
|
+
function dnsFailure(result, notFound, conflict, failures = {}, succeeded = accepted) {
|
|
245
|
+
if ('failure' in result)
|
|
246
|
+
return result.failure;
|
|
247
|
+
if (succeeded(result))
|
|
248
|
+
return null;
|
|
249
|
+
const known = result.body?.code;
|
|
250
|
+
if (typeof known === 'string' && Object.hasOwn(failures, known))
|
|
251
|
+
return failures[known];
|
|
252
|
+
if (result.status === 401)
|
|
253
|
+
return LOGIN_EXPIRED;
|
|
254
|
+
if (result.status === 403)
|
|
255
|
+
return plainFailure('login_required', 'The access token is not allowed to do this. Run deepdynamic login again.');
|
|
256
|
+
if (result.status === 404) {
|
|
257
|
+
const code = result.body?.code;
|
|
258
|
+
return typeof code === 'string' && Object.hasOwn(NOT_FOUND, code) ? NOT_FOUND[code] : notFound;
|
|
259
|
+
}
|
|
260
|
+
if (result.status === 400)
|
|
261
|
+
return plainFailure('invalid_arguments', 'The server rejected the request. Check the arguments against the command help.');
|
|
262
|
+
if (result.status === 409)
|
|
263
|
+
return conflict ?? plainFailure('site_unavailable', 'The project name cannot be used as a site address.');
|
|
264
|
+
return httpFailure(result.status);
|
|
265
|
+
}
|
|
266
|
+
async function applied(command, send, pretty, depth, deps) {
|
|
267
|
+
const sent = await authorized(deps, ({ siteUrl, token }) => {
|
|
268
|
+
const url = send.url(siteUrl);
|
|
269
|
+
const spinner = pretty ? send.spinner : null;
|
|
270
|
+
return send.method === 'GET' ? getWithToken(url, token, deps, spinner) : postJson(url, token, send.body ?? {}, deps, spinner);
|
|
271
|
+
});
|
|
272
|
+
if ('login' in sent)
|
|
273
|
+
return sent.login;
|
|
274
|
+
const { session, result } = sent;
|
|
275
|
+
const { siteUrl } = session;
|
|
276
|
+
if (cardRequired(result))
|
|
277
|
+
return requestCard(command, pretty, depth, session, deps);
|
|
278
|
+
const intercepted = 'failure' in result ? null : send.intercept?.(result, siteUrl);
|
|
279
|
+
if (intercepted)
|
|
280
|
+
return intercepted;
|
|
281
|
+
const failure = dnsFailure(result, send.notFound, send.conflict, send.failures, send.succeeded);
|
|
282
|
+
if (failure) {
|
|
283
|
+
return pretty
|
|
284
|
+
? prettyResult(1, depth, command, send.failed, [['Server', siteUrl], ['Reason', failure.display]])
|
|
285
|
+
: agentResult(1, { command, siteUrl, error: sendFailureError(result, failure) });
|
|
286
|
+
}
|
|
287
|
+
return send.done(result.body, siteUrl);
|
|
288
|
+
}
|
|
289
|
+
export async function rehearsed(command, args, pretty, depth, deps, plan, confirm) {
|
|
290
|
+
const { usage } = spec(command);
|
|
291
|
+
const { args: plain, dryRun } = splitDryRun(args);
|
|
292
|
+
const { args: rest, yes } = confirm ? splitYes(plain) : { args: plain, yes: false };
|
|
293
|
+
const planned = plan(rest);
|
|
294
|
+
if ('error' in planned) {
|
|
295
|
+
return pretty
|
|
296
|
+
? prettyResult(2, depth, command, planned.error, [['Usage', usage]])
|
|
297
|
+
: agentResult(2, { command, error: { code: 'invalid_arguments', message: planned.error }, usage });
|
|
298
|
+
}
|
|
299
|
+
if (!dryRun)
|
|
300
|
+
return confirm && !yes ? confirmationRequired(command, planned.confirmArgs ?? plain, pretty, depth, confirm) : applied(command, planned.send, pretty, depth, deps);
|
|
301
|
+
const session = await signedIn(deps);
|
|
302
|
+
if ('login' in session)
|
|
303
|
+
return session.login;
|
|
304
|
+
await rehearse(command, planned.steps, pretty, deps.stream, deps.pause);
|
|
305
|
+
return planned.result(session.siteUrl);
|
|
306
|
+
}
|
|
307
|
+
const zoneOf = (body) => body.zone;
|
|
308
|
+
const savedRecord = (zone, record) => [...zone.records].reverse().find((item) => item.type === record.type && item.name === record.name && item.value === record.value && item.priority === record.priority) ?? null;
|
|
309
|
+
function changed(command, pretty, depth, message, rows, zone, siteUrl, extra) {
|
|
310
|
+
return pretty
|
|
311
|
+
? prettyResult(0, depth, command, message, [['Server', siteUrl], ['Domain', zone.domain], ...rows, ...pendingRows(zone)])
|
|
312
|
+
: agentResult(0, { command, siteUrl, applied: true, domain: zone.domain, ...extra, zone });
|
|
313
|
+
}
|
|
314
|
+
export async function runDnsList(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
315
|
+
const command = 'dns';
|
|
316
|
+
return rehearsed(command, args, pretty, depth, deps, (rest) => {
|
|
317
|
+
const page = parsePage(rest);
|
|
318
|
+
if (typeof page !== 'number')
|
|
319
|
+
return page;
|
|
320
|
+
const listUrl = (siteUrl) => `${new URL(DNS_PATH, siteUrl).href}?page=${page}`;
|
|
321
|
+
return {
|
|
322
|
+
steps: [{ stage: 'prepare_request', message: 'Preparing the request to list managed domains.' }],
|
|
323
|
+
result: (siteUrl) => plannedRequest(command, pretty, depth, siteUrl, listUrl(siteUrl)),
|
|
324
|
+
send: {
|
|
325
|
+
method: 'GET',
|
|
326
|
+
url: listUrl,
|
|
327
|
+
spinner: 'Loading managed domains.',
|
|
328
|
+
failed: 'Could not load managed domains.',
|
|
329
|
+
notFound: httpFailure(404),
|
|
330
|
+
done: (body, siteUrl) => {
|
|
331
|
+
const { zones, ...paged } = body;
|
|
332
|
+
const paging = pagination(paged, command);
|
|
333
|
+
if (!pretty)
|
|
334
|
+
return agentResult(0, { command, siteUrl, ...paging, zones });
|
|
335
|
+
return prettyResult(0, depth, command, zones.length ? `Loaded ${count(zones.length, 'managed domain')}.` : 'You have no managed domains. Once you buy a domain, you can manage its records here.', [
|
|
336
|
+
['Server', siteUrl],
|
|
337
|
+
...zones.map((zone) => [
|
|
338
|
+
zone.domain,
|
|
339
|
+
[zone.project ?? NO_PROJECT, zoneState(zone), ...(zone.dnssec ? [`DNSSEC ${DNSSEC_STATES[zone.dnssec]}`] : []), count(zone.records.length, 'record')].join(' · ')
|
|
340
|
+
]),
|
|
341
|
+
...pageRows(paging)
|
|
342
|
+
]);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
export async function runDnsRecords(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
349
|
+
const command = 'dns records';
|
|
350
|
+
return rehearsed(command, args, pretty, depth, deps, ([input, ...extra]) => {
|
|
351
|
+
const domain = parseDomain(input, pretty);
|
|
352
|
+
if (typeof domain !== 'string')
|
|
353
|
+
return domain;
|
|
354
|
+
if (extra.length)
|
|
355
|
+
return { error: unknownArgument(extra[0]) };
|
|
356
|
+
return {
|
|
357
|
+
steps: [CHECK_DOMAIN, { stage: 'prepare_request', message: 'Preparing the request to list records.' }],
|
|
358
|
+
result: (siteUrl) => plannedRequest(command, pretty, depth, siteUrl, recordsUrl(siteUrl, domain)),
|
|
359
|
+
send: {
|
|
360
|
+
method: 'GET',
|
|
361
|
+
url: (siteUrl) => recordsUrl(siteUrl, domain),
|
|
362
|
+
spinner: 'Loading DNS records.',
|
|
363
|
+
failed: 'Could not load DNS records.',
|
|
364
|
+
notFound: DOMAIN_NOT_FOUND,
|
|
365
|
+
done: (body, siteUrl) => {
|
|
366
|
+
const zone = zoneOf(body);
|
|
367
|
+
if (!pretty)
|
|
368
|
+
return agentResult(0, { command, siteUrl, zone });
|
|
369
|
+
return prettyResult(0, depth, command, zone.records.length ? `Loaded ${count(zone.records.length, 'record')} for ${zone.domain}.` : `${zone.domain} has no records yet.`, [
|
|
370
|
+
['Server', siteUrl],
|
|
371
|
+
['Project', zone.project ?? NO_PROJECT],
|
|
372
|
+
['Status', zoneState(zone)],
|
|
373
|
+
...dnssecRows(zone),
|
|
374
|
+
['Google', zone.searchConsole ? `Search Console registered ${zone.searchConsole.connectedAt.slice(0, 10)}` : 'Search Console not registered'],
|
|
375
|
+
['GA4', analyticsState(zone)],
|
|
376
|
+
...zone.records.map((record) => [
|
|
377
|
+
record.id,
|
|
378
|
+
`${record.type} ${hostName(record.name, zone.domain)} → ${record.value}${record.priority === undefined ? '' : ` (priority ${record.priority})`} · TTL ${ttlLabel(record.ttl)}`
|
|
379
|
+
]),
|
|
380
|
+
...(zone.nameservers ? [['Nameservers', zone.nameservers.join(', ')]] : [])
|
|
381
|
+
]);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
export async function runDnsAdd(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
388
|
+
const command = 'dns add';
|
|
389
|
+
return rehearsed(command, args, pretty, depth, deps, ([input, ...flags]) => {
|
|
390
|
+
const domain = parseDomain(input, pretty);
|
|
391
|
+
if (typeof domain !== 'string')
|
|
392
|
+
return domain;
|
|
393
|
+
const record = parseRecord(flags, domain, pretty);
|
|
394
|
+
if ('error' in record)
|
|
395
|
+
return record;
|
|
396
|
+
const host = hostName(record.name, domain);
|
|
397
|
+
return {
|
|
398
|
+
steps: [CHECK_DOMAIN, CHECK_RECORD, DESCRIBE_RECORD, PREPARE_REQUEST],
|
|
399
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: recordsUrl(siteUrl, domain), body: { ...record } }, 'Checked the DNS record without adding it.', [['Domain', domain], ...recordRows(record, domain)], { domain, host, record }),
|
|
400
|
+
send: {
|
|
401
|
+
method: 'POST',
|
|
402
|
+
url: (siteUrl) => recordsUrl(siteUrl, domain),
|
|
403
|
+
body: { ...record },
|
|
404
|
+
spinner: 'Adding the DNS record.',
|
|
405
|
+
failed: 'Could not add the DNS record.',
|
|
406
|
+
notFound: DOMAIN_NOT_FOUND,
|
|
407
|
+
done: (body, siteUrl) => {
|
|
408
|
+
const zone = zoneOf(body);
|
|
409
|
+
const saved = savedRecord(zone, record);
|
|
410
|
+
return changed(command, pretty, depth, `Added the DNS record for ${host}.`, [...(saved ? [['Record ID', saved.id]] : []), ...recordRows(record, domain, APPLIED_PROPAGATION)], zone, siteUrl, { host, record: saved ?? record });
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
export async function runDnsUpdate(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
417
|
+
const command = 'dns update';
|
|
418
|
+
return rehearsed(command, args, pretty, depth, deps, ([input, id, ...flags]) => {
|
|
419
|
+
const domain = parseDomain(input, pretty);
|
|
420
|
+
if (typeof domain !== 'string')
|
|
421
|
+
return domain;
|
|
422
|
+
const recordId = parseRecordId(id);
|
|
423
|
+
if (typeof recordId !== 'string')
|
|
424
|
+
return recordId;
|
|
425
|
+
const record = parseRecord(flags, domain, pretty);
|
|
426
|
+
if ('error' in record)
|
|
427
|
+
return record;
|
|
428
|
+
const host = hostName(record.name, domain);
|
|
429
|
+
return {
|
|
430
|
+
steps: [CHECK_DOMAIN, CHECK_RECORD_ID, CHECK_RECORD, DESCRIBE_RECORD, PREPARE_REQUEST],
|
|
431
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: recordsUrl(siteUrl, domain, `/${encodeURIComponent(recordId)}`), body: { ...record } }, 'Checked the DNS record without updating it.', [['Domain', domain], ['Record ID', recordId], ...recordRows(record, domain)], { domain, recordId, host, record }),
|
|
432
|
+
send: {
|
|
433
|
+
method: 'POST',
|
|
434
|
+
url: (siteUrl) => recordsUrl(siteUrl, domain, `/${encodeURIComponent(recordId)}`),
|
|
435
|
+
body: { ...record },
|
|
436
|
+
spinner: 'Updating the DNS record.',
|
|
437
|
+
failed: 'Could not update the DNS record.',
|
|
438
|
+
notFound: RECORD_NOT_FOUND,
|
|
439
|
+
done: (body, siteUrl) => changed(command, pretty, depth, `Updated the DNS record for ${host}.`, [['Record ID', recordId], ...recordRows(record, domain, APPLIED_PROPAGATION)], zoneOf(body), siteUrl, { recordId, host, record: { id: recordId, ...record } })
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
export async function runDnsDelete(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
445
|
+
const command = 'dns delete';
|
|
446
|
+
return rehearsed(command, args, pretty, depth, deps, ([input, id, ...extra]) => {
|
|
447
|
+
const domain = parseDomain(input, pretty);
|
|
448
|
+
if (typeof domain !== 'string')
|
|
449
|
+
return domain;
|
|
450
|
+
const recordId = parseRecordId(id);
|
|
451
|
+
if (typeof recordId !== 'string')
|
|
452
|
+
return recordId;
|
|
453
|
+
if (extra.length)
|
|
454
|
+
return { error: unknownArgument(extra[0]) };
|
|
455
|
+
return {
|
|
456
|
+
confirmArgs: [domain, recordId],
|
|
457
|
+
steps: [CHECK_DOMAIN, CHECK_RECORD_ID, { stage: 'review_impact', message: 'Reviewing the impact of the deletion.' }, PREPARE_REQUEST],
|
|
458
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: recordsUrl(siteUrl, domain, `/${encodeURIComponent(recordId)}/delete`), body: {} }, 'Checked the DNS record deletion without deleting it.', [
|
|
459
|
+
['Domain', domain],
|
|
460
|
+
['Record ID', recordId],
|
|
461
|
+
['Impact', 'Once applied, the record is removed and stops routing traffic right away.'],
|
|
462
|
+
['Warning', `If this record connects the site, visitors can no longer reach the site. To restore it, run deepdynamic dns restore ${domain} --project <project>.`],
|
|
463
|
+
['Propagation', PROPAGATION]
|
|
464
|
+
], { domain, recordId }),
|
|
465
|
+
send: {
|
|
466
|
+
method: 'POST',
|
|
467
|
+
url: (siteUrl) => recordsUrl(siteUrl, domain, `/${encodeURIComponent(recordId)}/delete`),
|
|
468
|
+
body: {},
|
|
469
|
+
spinner: 'Deleting the DNS record.',
|
|
470
|
+
failed: 'Could not delete the DNS record.',
|
|
471
|
+
notFound: RECORD_NOT_FOUND,
|
|
472
|
+
done: (body, siteUrl) => {
|
|
473
|
+
const zone = zoneOf(body);
|
|
474
|
+
return changed(command, pretty, depth, 'Deleted the DNS record.', [
|
|
475
|
+
['Record ID', recordId],
|
|
476
|
+
...(zone.target && !zone.connected ? [['Warning', `Visitors cannot reach the site through this domain now. To restore it, run deepdynamic dns restore ${domain} --project <project>.`]] : []),
|
|
477
|
+
['Propagation', APPLIED_PROPAGATION]
|
|
478
|
+
], zone, siteUrl, { recordId });
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
}, {
|
|
483
|
+
message: 'Deleting removes the record from the DNS servers; if it connected the site, visitors can no longer reach it.',
|
|
484
|
+
display: `Deleting removes this record from the DNS servers. ${CONFIRM_NEXT}`
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
export async function runDnsRestore(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
488
|
+
const command = 'dns restore';
|
|
489
|
+
return rehearsed(command, args, pretty, depth, deps, ([input, ...flags]) => {
|
|
490
|
+
const domain = parseDomain(input, pretty);
|
|
491
|
+
if (typeof domain !== 'string')
|
|
492
|
+
return domain;
|
|
493
|
+
const values = readFlags(flags, RESTORE_FLAGS);
|
|
494
|
+
if ('error' in values)
|
|
495
|
+
return values;
|
|
496
|
+
const { '--project': project, '--name': rawName = 'www' } = values;
|
|
497
|
+
if (project === undefined)
|
|
498
|
+
return { error: '--project is required.' };
|
|
499
|
+
if (!PROJECT.test(project))
|
|
500
|
+
return { error: `Project names are 1-63 lowercase letters, digits or hyphens and start and end with a letter or digit: ${project}` };
|
|
501
|
+
const name = parseName(rawName, domain);
|
|
502
|
+
if (typeof name !== 'string')
|
|
503
|
+
return name;
|
|
504
|
+
if (name === '@')
|
|
505
|
+
return { error: '--name cannot be @ because a CNAME cannot be on the domain itself.' };
|
|
506
|
+
const record = { type: 'CNAME', name, value: `${project}.${DNS_SITE_DOMAIN}`, ttl: 1 };
|
|
507
|
+
const host = hostName(name, domain);
|
|
508
|
+
const restoreUrl = (siteUrl) => new URL(`${DNS_PATH}/${encodeURIComponent(domain)}/restore`, siteUrl).href;
|
|
509
|
+
return {
|
|
510
|
+
confirmArgs: [domain, ...flags],
|
|
511
|
+
steps: [
|
|
512
|
+
CHECK_DOMAIN,
|
|
513
|
+
{ stage: 'check_project', message: 'Checking the project name format.' },
|
|
514
|
+
{ stage: 'build_record', message: 'Building the site CNAME record.' },
|
|
515
|
+
{ stage: 'plan_cleanup', message: 'Planning the cleanup of same-name records that conflict with the CNAME.' },
|
|
516
|
+
PREPARE_REQUEST
|
|
517
|
+
],
|
|
518
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: restoreUrl(siteUrl), body: { project, name } }, 'Checked the site connection restore without restoring it.', [
|
|
519
|
+
['Domain', domain],
|
|
520
|
+
['Project', project],
|
|
521
|
+
['Record', `CNAME ${host} → ${record.value}`],
|
|
522
|
+
['TTL', ttlLabel(record.ttl)],
|
|
523
|
+
['Description', describeRecord(record, domain)],
|
|
524
|
+
['Cleanup', `Other records of ${host} cannot coexist with a CNAME and are removed when applied.`],
|
|
525
|
+
['Propagation', PROPAGATION]
|
|
526
|
+
], { domain, host, project, record, replacesSameName: true }),
|
|
527
|
+
send: {
|
|
528
|
+
method: 'POST',
|
|
529
|
+
url: restoreUrl,
|
|
530
|
+
body: { project, name },
|
|
531
|
+
spinner: 'Restoring the site connection.',
|
|
532
|
+
failed: 'Could not restore the site connection.',
|
|
533
|
+
notFound: PROJECT_NOT_FOUND,
|
|
534
|
+
done: (body, siteUrl) => changed(command, pretty, depth, `Restored the site connection for ${host}.`, [
|
|
535
|
+
['Project', project],
|
|
536
|
+
['Record', `CNAME ${host} → ${record.value}`],
|
|
537
|
+
['Cleanup', `Other records of ${host} cannot coexist with a CNAME and were removed.`],
|
|
538
|
+
['Propagation', APPLIED_PROPAGATION]
|
|
539
|
+
], zoneOf(body), siteUrl, { host, project, record })
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
}, {
|
|
543
|
+
message: 'Restoring replaces the other records of the same host and can move the domain to another project.',
|
|
544
|
+
display: `Restoring removes the other records of the same host and can move the domain to another project. ${CONFIRM_NEXT}`
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
export async function runDnsSync(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
548
|
+
const command = 'dns sync';
|
|
549
|
+
return rehearsed(command, args, pretty, depth, deps, ([input, ...extra]) => {
|
|
550
|
+
const domain = parseDomain(input, pretty);
|
|
551
|
+
if (typeof domain !== 'string')
|
|
552
|
+
return domain;
|
|
553
|
+
if (extra.length)
|
|
554
|
+
return { error: unknownArgument(extra[0]) };
|
|
555
|
+
const syncUrl = (siteUrl) => new URL(`${DNS_PATH}/${encodeURIComponent(domain)}/sync`, siteUrl).href;
|
|
556
|
+
return {
|
|
557
|
+
confirmArgs: [domain],
|
|
558
|
+
steps: [CHECK_DOMAIN, { stage: 'review_impact', message: 'Reviewing the impact of the sync.' }, PREPARE_REQUEST],
|
|
559
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: syncUrl(siteUrl), body: {} }, 'Checked the DNS sync without applying it.', [
|
|
560
|
+
['Domain', domain],
|
|
561
|
+
['Effect', SYNC_EFFECT],
|
|
562
|
+
['Warning', SYNC_WARNING],
|
|
563
|
+
['Propagation', PROPAGATION]
|
|
564
|
+
], { domain }),
|
|
565
|
+
send: {
|
|
566
|
+
method: 'POST',
|
|
567
|
+
url: syncUrl,
|
|
568
|
+
body: {},
|
|
569
|
+
spinner: 'Syncing the DNS servers.',
|
|
570
|
+
failed: 'Could not sync the DNS servers.',
|
|
571
|
+
notFound: DOMAIN_NOT_FOUND,
|
|
572
|
+
failures: {
|
|
573
|
+
delegation_pending: {
|
|
574
|
+
code: 'delegation_pending',
|
|
575
|
+
message: `The registrar of this domain bought elsewhere does not point at the DeepDynamic nameservers yet, so the zone stays pending. Ask the user to set the nameservers in zone.nameservers of deepdynamic dns records ${domain} at the registrar where the domain was bought, then run this again a few minutes later.`,
|
|
576
|
+
display: `The registrar where the domain was bought does not use the DeepDynamic nameservers yet. Set the nameservers listed by deepdynamic dns records ${domain} there, then run this again a few minutes later.`
|
|
577
|
+
}
|
|
578
|
+
},
|
|
579
|
+
done: (body, siteUrl) => {
|
|
580
|
+
const zone = zoneOf(body);
|
|
581
|
+
return changed(command, pretty, depth, `Synced the records of ${zone.domain} to the DNS servers.`, [
|
|
582
|
+
['Status', zoneState(zone)],
|
|
583
|
+
...(zone.nameservers ? [['Nameservers', zone.nameservers.join(', ')]] : []),
|
|
584
|
+
['Propagation', APPLIED_PROPAGATION]
|
|
585
|
+
], zone, siteUrl, {});
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
}, {
|
|
590
|
+
message: 'Syncing overwrites the DNS servers with the saved records, so records changed only on the DNS servers are removed.',
|
|
591
|
+
display: `Syncing overwrites the DNS servers with the saved records, so records changed only on the DNS servers are removed. ${CONFIRM_NEXT}`
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
export async function runDnsDnssec(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
595
|
+
const command = 'dns dnssec';
|
|
596
|
+
return rehearsed(command, args, pretty, depth, deps, ([input, state, ...extra]) => {
|
|
597
|
+
const domain = parseDomain(input, pretty);
|
|
598
|
+
if (typeof domain !== 'string')
|
|
599
|
+
return domain;
|
|
600
|
+
if (state === undefined)
|
|
601
|
+
return { error: 'Give on or off after the domain.' };
|
|
602
|
+
if (state.startsWith('-'))
|
|
603
|
+
return { error: unknownArgument(state) };
|
|
604
|
+
if (state !== 'on' && state !== 'off')
|
|
605
|
+
return { error: `Give on or off after the domain: ${state}` };
|
|
606
|
+
if (extra.length)
|
|
607
|
+
return { error: unknownArgument(extra[0]) };
|
|
608
|
+
const enabled = state === 'on';
|
|
609
|
+
const dnssecUrl = (siteUrl) => new URL(`${DNS_PATH}/${encodeURIComponent(domain)}/dnssec`, siteUrl).href;
|
|
610
|
+
return {
|
|
611
|
+
confirmArgs: [domain, state],
|
|
612
|
+
steps: [CHECK_DOMAIN, { stage: 'check_state', message: 'Reviewing the DNSSEC change and its impact.' }, PREPARE_REQUEST],
|
|
613
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: dnssecUrl(siteUrl), body: { enabled } }, 'Checked the DNSSEC change without applying it.', [
|
|
614
|
+
['Domain', domain],
|
|
615
|
+
['Change', enabled ? 'Turn DNSSEC on' : 'Turn DNSSEC off'],
|
|
616
|
+
['Effect', enabled ? DNSSEC_ON_EFFECT : DNSSEC_NOTES.disabling],
|
|
617
|
+
['Target', DNSSEC_SCOPE]
|
|
618
|
+
], { domain, enabled }),
|
|
619
|
+
send: {
|
|
620
|
+
method: 'POST',
|
|
621
|
+
url: dnssecUrl,
|
|
622
|
+
body: { enabled },
|
|
623
|
+
spinner: enabled ? 'Turning DNSSEC on.' : 'Turning DNSSEC off.',
|
|
624
|
+
failed: enabled ? 'Could not turn DNSSEC on.' : 'Could not turn DNSSEC off.',
|
|
625
|
+
notFound: DOMAIN_NOT_FOUND,
|
|
626
|
+
failures: DNSSEC_FAILURES,
|
|
627
|
+
done: (body, siteUrl) => {
|
|
628
|
+
const zone = zoneOf(body);
|
|
629
|
+
return changed(command, pretty, depth, `Turned DNSSEC ${enabled ? 'on' : 'off'} for ${zone.domain}.`, dnssecRows(zone, true), zone, siteUrl, { dnssec: zone.dnssec ?? null });
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
}, {
|
|
634
|
+
message: 'Turning DNSSEC on or off changes the signing of the DNS zone and the DS record at the registrar; turning it off finishes only 2 days later.',
|
|
635
|
+
display: `Turning DNSSEC on or off changes the zone signing on the DNS servers and the DS record at the registrar. Turning it off stops signing 2 days later. ${CONFIRM_NEXT}`
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
const GOOGLE_NEXT = 'Open url in a browser signed in to the same DeepDynamic account within 10 minutes, pick the Google account that should own the Search Console property and allow both permissions. The browser then adds the ownership TXT record, verifies the domain and adds the sc-domain: property, and lands on /projects#dns with the result. Confirm with deepdynamic dns records <domain>: zone.searchConsole.connectedAt is set once it is done.';
|
|
639
|
+
const CONSENT_NOTICE = 'Open it within 10 minutes in a browser signed in to the same DeepDynamic account. When registration finishes, the browser returns to the DNS tab of the My Projects page.';
|
|
640
|
+
export async function runDnsGoogle(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
641
|
+
const command = 'dns google';
|
|
642
|
+
return rehearsed(command, args, pretty, depth, deps, ([input, ...extra]) => {
|
|
643
|
+
const domain = parseDomain(input, pretty);
|
|
644
|
+
if (typeof domain !== 'string')
|
|
645
|
+
return domain;
|
|
646
|
+
if (extra.length)
|
|
647
|
+
return { error: unknownArgument(extra[0]) };
|
|
648
|
+
const googleUrl = (siteUrl) => new URL(`${DNS_PATH}/${encodeURIComponent(domain)}/google`, siteUrl).href;
|
|
649
|
+
return {
|
|
650
|
+
steps: [CHECK_DOMAIN, PREPARE_REQUEST],
|
|
651
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: googleUrl(siteUrl), body: {} }, 'Checked the Google Search Console registration request without sending it.', [
|
|
652
|
+
['Domain', domain],
|
|
653
|
+
['Next', 'Open the returned URL within 10 minutes in a browser signed in to the same DeepDynamic account, pick a Google account and allow both permissions. The ownership TXT record is then added, the domain is verified and the Search Console property is added.']
|
|
654
|
+
], { domain }),
|
|
655
|
+
send: {
|
|
656
|
+
method: 'POST',
|
|
657
|
+
url: googleUrl,
|
|
658
|
+
body: {},
|
|
659
|
+
spinner: 'Creating the Google consent URL.',
|
|
660
|
+
failed: 'Could not create the Google consent URL.',
|
|
661
|
+
notFound: DOMAIN_NOT_FOUND,
|
|
662
|
+
failures: {
|
|
663
|
+
zone_pending: {
|
|
664
|
+
code: 'zone_pending',
|
|
665
|
+
message: `The DNS zone of this domain is still pending, and Google can verify it only after the zone is ready. Check zone.status with deepdynamic dns records ${domain} and run this again once it is ready.`,
|
|
666
|
+
display: `DNS is still being set up. Run this again once deepdynamic dns records ${domain} shows that setup has finished.`
|
|
667
|
+
},
|
|
668
|
+
delegation_propagating: {
|
|
669
|
+
code: 'delegation_propagating',
|
|
670
|
+
message: 'Public DNS still shows the old nameservers for this domain (a freshly bought domain takes about 10 minutes at the registry), so Google could not see the ownership TXT yet. Wait about 10 minutes and run this again.',
|
|
671
|
+
display: 'The nameserver change is still propagating across the internet. Right after buying a domain this takes about 10 minutes, so run this again shortly.'
|
|
672
|
+
}
|
|
673
|
+
},
|
|
674
|
+
done: (body, siteUrl) => {
|
|
675
|
+
const url = body.url;
|
|
676
|
+
return pretty
|
|
677
|
+
? prettyResult(0, depth, command, 'Open the URL below in a browser to finish the Google Search Console registration.', [
|
|
678
|
+
['Server', siteUrl],
|
|
679
|
+
['Domain', domain],
|
|
680
|
+
['URL', url],
|
|
681
|
+
['Notice', CONSENT_NOTICE],
|
|
682
|
+
['Check', `Google row of deepdynamic dns records ${domain}`]
|
|
683
|
+
])
|
|
684
|
+
: agentResult(0, { command, siteUrl, domain, url, next: GOOGLE_NEXT.replace('<domain>', domain) });
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
const ANALYTICS_NEXT = 'Open url in a browser signed in to the same DeepDynamic account within 10 minutes, pick the Google account that should own the GA4 property and allow the Google Analytics edit permission. The browser then creates a new GA4 property named after the domain with a web data stream for https://<siteName>.<domain> under the first Google Analytics account of that Google account, adds the Google tag to the domain and its site host, and lands on /projects#dns with the result. Confirm with deepdynamic dns records <domain>: zone.analytics.measurementId is set once it is done.';
|
|
691
|
+
const ANALYTICS_START = 'Open the returned URL within 10 minutes in a browser signed in to the same DeepDynamic account, pick a Google account and allow the Google Analytics edit permission. A new GA4 property named after the domain and a web stream are then created under the first Google Analytics account of that Google account, and the Google tag is added to the site.';
|
|
692
|
+
const ANALYTICS_OFF_EFFECT = 'Stops adding the Google tag to the HTML of the domain and the site host. The GA4 property stays in Google.';
|
|
693
|
+
const ANALYTICS_OFF_WARNING = 'Registering again creates a new GA4 property that does not continue the visit data collected so far.';
|
|
694
|
+
const ANALYTICS_FAILURES = {
|
|
695
|
+
no_project: {
|
|
696
|
+
code: 'no_project',
|
|
697
|
+
message: 'The domain is not connected to a project, so there is no site to add the Google tag to. Connect one with deepdynamic dns restore <domain> --project <name> --yes, then run this again.',
|
|
698
|
+
display: 'The domain is not connected to a project. Connect one with deepdynamic dns restore first, then run this again.'
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
export async function runDnsAnalytics(args, pretty, depth, deps = defaultAuthDeps(pretty, depth)) {
|
|
702
|
+
const command = 'dns analytics';
|
|
703
|
+
if (args.filter((arg) => !arg.startsWith('-'))[1] === 'off')
|
|
704
|
+
return runDnsAnalyticsOff(args, pretty, depth, deps);
|
|
705
|
+
return rehearsed(command, splitYes(args).args, pretty, depth, deps, ([input, ...extra]) => {
|
|
706
|
+
const domain = parseDomain(input, pretty);
|
|
707
|
+
if (typeof domain !== 'string')
|
|
708
|
+
return domain;
|
|
709
|
+
if (extra.length)
|
|
710
|
+
return { error: extra[0].startsWith('-') ? unknownArgument(extra[0]) : `Only off can follow the domain: ${extra[0]}` };
|
|
711
|
+
const analyticsUrl = (siteUrl) => new URL(`${DNS_PATH}/${encodeURIComponent(domain)}/analytics`, siteUrl).href;
|
|
712
|
+
return {
|
|
713
|
+
steps: [CHECK_DOMAIN, PREPARE_REQUEST],
|
|
714
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: analyticsUrl(siteUrl), body: {} }, 'Checked the Google Analytics registration request without sending it.', [
|
|
715
|
+
['Domain', domain],
|
|
716
|
+
['Next', ANALYTICS_START]
|
|
717
|
+
], { domain }),
|
|
718
|
+
send: {
|
|
719
|
+
method: 'POST',
|
|
720
|
+
url: analyticsUrl,
|
|
721
|
+
body: {},
|
|
722
|
+
spinner: 'Creating the Google consent URL.',
|
|
723
|
+
failed: 'Could not create the Google consent URL.',
|
|
724
|
+
notFound: DOMAIN_NOT_FOUND,
|
|
725
|
+
failures: ANALYTICS_FAILURES,
|
|
726
|
+
done: (body, siteUrl) => {
|
|
727
|
+
const url = body.url;
|
|
728
|
+
return pretty
|
|
729
|
+
? prettyResult(0, depth, command, 'Open the URL below in a browser to finish the Google Analytics registration.', [
|
|
730
|
+
['Server', siteUrl],
|
|
731
|
+
['Domain', domain],
|
|
732
|
+
['URL', url],
|
|
733
|
+
['Notice', CONSENT_NOTICE],
|
|
734
|
+
['Check', `GA4 row of deepdynamic dns records ${domain}`]
|
|
735
|
+
])
|
|
736
|
+
: agentResult(0, { command, siteUrl, domain, url, next: ANALYTICS_NEXT.replaceAll('<domain>', domain) });
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
function runDnsAnalyticsOff(args, pretty, depth, deps) {
|
|
743
|
+
const command = 'dns analytics';
|
|
744
|
+
return rehearsed(command, args, pretty, depth, deps, ([input, , ...extra]) => {
|
|
745
|
+
const domain = parseDomain(input, pretty);
|
|
746
|
+
if (typeof domain !== 'string')
|
|
747
|
+
return domain;
|
|
748
|
+
if (extra.length)
|
|
749
|
+
return { error: unknownArgument(extra[0]) };
|
|
750
|
+
const disconnectUrl = (siteUrl) => new URL(`${DNS_PATH}/${encodeURIComponent(domain)}/analytics/disconnect`, siteUrl).href;
|
|
751
|
+
return {
|
|
752
|
+
confirmArgs: [domain, 'off'],
|
|
753
|
+
steps: [CHECK_DOMAIN, { stage: 'review_impact', message: 'Reviewing the impact of removing Google Analytics.' }, PREPARE_REQUEST],
|
|
754
|
+
result: (siteUrl) => plannedChange(command, pretty, depth, siteUrl, { url: disconnectUrl(siteUrl), body: {} }, 'Checked the Google Analytics removal without applying it.', [
|
|
755
|
+
['Domain', domain],
|
|
756
|
+
['Change', 'Remove the Google tag'],
|
|
757
|
+
['Effect', ANALYTICS_OFF_EFFECT],
|
|
758
|
+
['Warning', ANALYTICS_OFF_WARNING]
|
|
759
|
+
], { domain }),
|
|
760
|
+
send: {
|
|
761
|
+
method: 'POST',
|
|
762
|
+
url: disconnectUrl,
|
|
763
|
+
body: {},
|
|
764
|
+
spinner: 'Removing the Google tag from the site.',
|
|
765
|
+
failed: 'Could not remove Google Analytics.',
|
|
766
|
+
notFound: DOMAIN_NOT_FOUND,
|
|
767
|
+
done: (body, siteUrl) => {
|
|
768
|
+
const zone = zoneOf(body);
|
|
769
|
+
return changed(command, pretty, depth, `Removed the Google tag from the ${zone.domain} site.`, [['GA4', analyticsState(zone)], ['Notice', 'The GA4 property stays in Google. Registering again creates a new property.']], zone, siteUrl, { analytics: zone.analytics ?? null });
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
}, {
|
|
774
|
+
message: 'Removing stops adding the Google tag to the site, so visits are no longer recorded. The GA4 property stays in Google, and registering again creates a new property that does not continue the old data.',
|
|
775
|
+
display: `Removing stops adding the Google tag to the site, so visits are no longer recorded. The GA4 property stays in Google, but registering again creates a new property. ${CONFIRM_NEXT}`
|
|
776
|
+
});
|
|
777
|
+
}
|