nameslink 1.0.6 → 1.1.17
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/README.md +30 -9
- package/bin/nameslink.mjs +5 -2
- package/package.json +3 -2
- package/skill/nameslink/SKILL.md +22 -8
- package/src/cli.mjs +20 -3
- package/src/client.mjs +29 -0
- package/src/hosted-site.mjs +37 -12
- package/src/i18n.mjs +32 -2
- package/src/oauth.mjs +46 -7
- package/src/startup-telemetry.mjs +98 -0
package/README.md
CHANGED
|
@@ -81,6 +81,20 @@ Running `nameslink` with no arguments in an interactive terminal shows a compact
|
|
|
81
81
|
and the safest starting commands. Piped output, CI, Agent JSON mode, and `nameslink help` remain
|
|
82
82
|
stable and do not receive decorative output.
|
|
83
83
|
|
|
84
|
+
## CLI sign-in authorization
|
|
85
|
+
|
|
86
|
+
During `nameslink login`, choose **Full authorization** to verify your identity once. The same CLI
|
|
87
|
+
sign-in can buy domains, create or update DNS records, and publish a site without another MFA
|
|
88
|
+
challenge. The permission lasts until that sign-in ends, including across access-token renewals.
|
|
89
|
+
Each purchase still requires reviewing and approving the domain and price. Account security changes
|
|
90
|
+
can invalidate the authorization. Domain transfers and access key creation retain their own checks.
|
|
91
|
+
|
|
92
|
+
Choose **On-demand authorization** to finish sign-in without an additional verification. The CLI
|
|
93
|
+
opens the browser when a protected operation requires MFA and continues the original command after
|
|
94
|
+
verification. With `--json`, the command emits `mfa.browser` on stderr while it waits. The browser
|
|
95
|
+
opens locally for the signed-in customer. `nameslink whoami --json` reports `authorizationMode`
|
|
96
|
+
as `FULL` or `ON_DEMAND` for sessions granted with either mode.
|
|
97
|
+
|
|
84
98
|
## Try it safely
|
|
85
99
|
|
|
86
100
|
```bash
|
|
@@ -190,7 +204,9 @@ Update and delete resolve the record ID in the named zone before submitting the
|
|
|
190
204
|
server independently enforces the current account and zone ownership.
|
|
191
205
|
|
|
192
206
|
DNS create/update/delete use the same `EMAIL_FALLBACK` MFA policy as the NamesLink web console.
|
|
193
|
-
|
|
207
|
+
Full authorization covers DNS create/update for the current sign-in. On-demand sessions use browser
|
|
208
|
+
verification when required. For earlier OAuth CLI sessions, DNS verification is reusable for one
|
|
209
|
+
account, endpoint, profile/session and DNS zone
|
|
194
210
|
for **one hour after all factors pass**. It covers record create/update in that zone and cleanup of unchanged records actually created by
|
|
195
211
|
this CLI session. The server create task records the exact returned record ID and content digest.
|
|
196
212
|
Other records or changed content require separate MFA scoped to that ID/snapshot;
|
|
@@ -216,8 +232,8 @@ resume with its returned command, never generate a new challenge to resend a cod
|
|
|
216
232
|
session returns `Account.Mfa.CliSessionRevoked`; run `nameslink login` again.
|
|
217
233
|
This contract requires the matching backend and CLI rollout; source tests do not prove deployment.
|
|
218
234
|
|
|
219
|
-
|
|
220
|
-
factor
|
|
235
|
+
For an earlier session or AK/SK authentication, use the returned command-line challenge and its
|
|
236
|
+
listed factor inputs. By default the CLI follows the
|
|
221
237
|
account-scoped task/batch operation until it succeeds or fails; `--no-wait` deliberately returns
|
|
222
238
|
after acceptance. Task success is not public propagation proof, so use
|
|
223
239
|
`nameslink dns records list <domain>` and an independent resolver to verify the resulting state.
|
|
@@ -575,11 +591,10 @@ title, falling back to the filename. `rename` changes only that label. First pub
|
|
|
575
591
|
reviewed version and destination;
|
|
576
592
|
when DNS or HTTPS is pending, it returns the original operation and next action, without claiming
|
|
577
593
|
publication success. For a NamesLink-managed destination, publish includes bounded automatic DNS
|
|
578
|
-
setup
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
`domain check` on
|
|
582
|
-
formal public verification. Sites bound to external DNS before 2026-10-10 keep updating on their
|
|
594
|
+
setup under the selected CLI authorization mode. The server continues after the CLI exits. Existing
|
|
595
|
+
records are preserved and conflicts require review. `status` reports DNS readiness
|
|
596
|
+
(`domainSetup.status`) independently of site publication (`site.status`). If DNS status is
|
|
597
|
+
`UNKNOWN`, run `domain check` on the original plan. The formal URL appears after public verification. Sites bound to external DNS before 2026-10-10 keep updating on their
|
|
583
598
|
existing binding and still read
|
|
584
599
|
stage-specific records through `domain show`; new bindings to external domains are refused. One site
|
|
585
600
|
binds one single-label subdomain; `www`, `blog`, and other
|
|
@@ -600,7 +615,7 @@ nameslink site hosted stop <site-id> --yes --json
|
|
|
600
615
|
|
|
601
616
|
Retained successful history is restored through a new operation on the same domain, even after its
|
|
602
617
|
old preview expires. Stop retains history and DNS records and requires a fresh ordinary MFA check.
|
|
603
|
-
DNS apply
|
|
618
|
+
DNS apply follows the current CLI authorization mode. AK/SK authentication retains ordinary MFA.
|
|
604
619
|
|
|
605
620
|
For a stopped site, `status --watch` returns `REMOVED` without waiting for it to become live.
|
|
606
621
|
Prepare and review a new candidate on the same site ID, then review the full host in its returned
|
|
@@ -654,3 +669,9 @@ The bootstrap address and operation semantics remain stable; resource locations
|
|
|
654
669
|
Only endpoint-relative URI templates are accepted. Credentials are signed/sent after resolution; redirects remain disabled.
|
|
655
670
|
A missing GET route can refresh discovery once. Writes are never replayed to follow a moved route; recover the original receipt with the original request key.
|
|
656
671
|
The existing domain-portfolio and OAuth login protocols are outside this resource migration.
|
|
672
|
+
|
|
673
|
+
### Startup diagnostics
|
|
674
|
+
|
|
675
|
+
The CLI sends best-effort first-run and sign-in checkpoints to NamesLink. It sends fixed
|
|
676
|
+
event names and random journey IDs, without credentials, verification codes, or command
|
|
677
|
+
arguments. Set `NAMESLINK_TELEMETRY_DISABLED=1` to turn off these client reports.
|
package/bin/nameslink.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { main, provisionSkillQuietly, remindAboutUpdate } from '../src/cli.mjs';
|
|
4
|
+
import { createStartupTelemetry } from '../src/startup-telemetry.mjs';
|
|
4
5
|
import { loadLanguagePreference, saveLanguagePreference } from '../src/config.mjs';
|
|
5
6
|
import { createI18n, formatRecoveryGuidance, languageOptionFromArgv, localizeError } from '../src/i18n.mjs';
|
|
6
7
|
|
|
@@ -66,8 +67,9 @@ if (i18n && requestedLanguage) {
|
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
const startupTelemetry = createStartupTelemetry();
|
|
69
71
|
if (i18n)
|
|
70
|
-
main(argv, { i18n })
|
|
72
|
+
main(argv, { i18n, startupTelemetry })
|
|
71
73
|
// 只在命令成功后提醒,且提醒自身吞掉所有异常:一条已经跑成功的命令的退出码不能被它改写。
|
|
72
74
|
.then(() => remindAboutUpdate(argv, i18n))
|
|
73
75
|
.then(() => provisionSkillQuietly(argv, i18n))
|
|
@@ -79,4 +81,5 @@ if (i18n)
|
|
|
79
81
|
}
|
|
80
82
|
reportError(error, i18n);
|
|
81
83
|
process.exitCode = 1;
|
|
82
|
-
})
|
|
84
|
+
})
|
|
85
|
+
.finally(() => startupTelemetry?.drain());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nameslink",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.17",
|
|
4
4
|
"description": "NamesLink command-line client for domains, DNS, intelligent site building, Security Acceleration and automation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"skill/nameslink/SKILL.md",
|
|
36
36
|
"skill/nameslink/agents/openai.yaml",
|
|
37
37
|
"README.md",
|
|
38
|
-
"scripts/postinstall.mjs"
|
|
38
|
+
"scripts/postinstall.mjs",
|
|
39
|
+
"src/startup-telemetry.mjs"
|
|
39
40
|
],
|
|
40
41
|
"engines": {
|
|
41
42
|
"node": ">=20"
|
package/skill/nameslink/SKILL.md
CHANGED
|
@@ -49,7 +49,11 @@ value. Never choose the last repeated value on the user's behalf.
|
|
|
49
49
|
and on the authorization page choose "Use another account" instead of confirming; that clears the
|
|
50
50
|
browser session and returns to the NamesLink login page, where email or Google both work. Always
|
|
51
51
|
read back the account the page says it is about to authorize and check it against what the user
|
|
52
|
-
asked for before approving.
|
|
52
|
+
asked for before approving. Let the customer choose the authorization mode in the browser.
|
|
53
|
+
Full authorization verifies their identity at sign-in and covers purchases, DNS create/update,
|
|
54
|
+
and site publishing for that CLI sign-in. On-demand authorization verifies protected operations
|
|
55
|
+
in the browser when required. Both modes keep exact purchase approval. Read `authorizationMode`
|
|
56
|
+
from `nameslink whoami --json` to identify the active mode when the server provides it.
|
|
53
57
|
Confirm the reported endpoint and environment before sending credentials or performing a paid
|
|
54
58
|
action. Official remote endpoints require HTTPS; custom HTTPS and loopback HTTP endpoints are
|
|
55
59
|
development-only, require an explicit process-local opt-in, and are never persisted. If
|
|
@@ -108,10 +112,20 @@ After approval, run:
|
|
|
108
112
|
nameslink apply <plan-id> --approve <digest> --watch --json
|
|
109
113
|
```
|
|
110
114
|
|
|
111
|
-
|
|
112
|
-
`
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
When stderr (or the live `--output-file` progress stream) emits `mfa.browser` with
|
|
116
|
+
`status=WAITING_FOR_USER` and `agentAction=NOTIFY_USER_AND_WAIT`, immediately tell the customer
|
|
117
|
+
to complete MFA in the NamesLink browser page. Pause dependent work and keep this same command
|
|
118
|
+
running; do not kill it, start another copy, or claim the operation has succeeded. Use a live or
|
|
119
|
+
background execution handle and read progress while it runs, so the notification reaches the
|
|
120
|
+
customer before the command finishes. If `browserOpened=false`, give the customer the returned
|
|
121
|
+
verification link; otherwise use the browser already opened by the CLI. Never ask for, collect,
|
|
122
|
+
or type the customer's MFA codes in this browser flow. The browser handles every factor.
|
|
123
|
+
Wait for the original command's final result: after verification it automatically resumes the
|
|
124
|
+
same request. If it exits with `Account.Mfa.FlowExpired`, tell the customer verification timed out;
|
|
125
|
+
do not claim success or silently switch to collecting codes in chat.
|
|
126
|
+
|
|
127
|
+
If the command exits with `Cli.Mfa.ChallengePending`, use the command-line challenge's `data`
|
|
128
|
+
envelope. The challenge lives on the server for its stated lifetime. Continue in two steps:
|
|
115
129
|
|
|
116
130
|
1. **Send the code.** The initial challenge sends nothing. For each EMAIL/SMS factor run the exact
|
|
117
131
|
command from `nextAction.sendCodeCommands[]`, for example
|
|
@@ -143,9 +157,9 @@ file, and delete the file as soon as the command returns.
|
|
|
143
157
|
|
|
144
158
|
**Two things an agent must never do**, both of which caused real incidents:
|
|
145
159
|
|
|
146
|
-
- **Do not build an interactive session**: no FIFO, no long-lived background process
|
|
147
|
-
`screen … stuff`, no writing into a still-running CLI.
|
|
148
|
-
|
|
160
|
+
- **Do not build an interactive code entry session**: no FIFO, no long-lived background process
|
|
161
|
+
for code entry, no `screen … stuff`, and no writing codes into a still-running CLI. Use the
|
|
162
|
+
supported browser or command-line flow.
|
|
149
163
|
- **Do not drive the interactive `--mfa-stdin` prompt flow.** Prompting inside one live process is
|
|
150
164
|
for a human at a real TTY. As an agent, always take the two-step path above.
|
|
151
165
|
|
package/src/cli.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
saveSkillCheckMetadata, saveUpdateCheckMetadata, validateEndpoint,
|
|
12
12
|
} from './config.mjs';
|
|
13
13
|
import { createI18n, formatCode, formatContractLabel, formatDisplayLabel, formatRecoveryGuidance, localizeServerMessage } from './i18n.mjs';
|
|
14
|
-
import { browserLogin } from './oauth.mjs';
|
|
14
|
+
import { browserLogin, browserMfa } from './oauth.mjs';
|
|
15
15
|
import { completeProfile } from './profile.mjs';
|
|
16
16
|
import {
|
|
17
17
|
ensureOfficialSkill, inspectOfficialSkillInstallations, installOfficialSkill, planSkillReminder,
|
|
@@ -420,6 +420,7 @@ export async function main(argv, runtime = {}) {
|
|
|
420
420
|
const i18n = runtime.i18n || createI18n(parsed.options.lang);
|
|
421
421
|
const noCommand = parsed.positionals.length === 0;
|
|
422
422
|
const command = parsed.positionals.shift() || 'help';
|
|
423
|
+
const firstRunJourney = await runtime.startupTelemetry?.firstRun(parsed.options.endpoint, 'unknown', cliVersion);
|
|
423
424
|
const interactive = runtime.interactive ?? Boolean(stdout.isTTY && !parsed.options.json);
|
|
424
425
|
if (noCommand && !parsed.options.help && !parsed.options.version && interactive) {
|
|
425
426
|
const write = runtime.write || ((value) => stdout.write(value));
|
|
@@ -504,19 +505,28 @@ export async function main(argv, runtime = {}) {
|
|
|
504
505
|
config.endpointPersistent = endpointSelection.persistent;
|
|
505
506
|
}
|
|
506
507
|
const invocation = prepareJourney(
|
|
507
|
-
config,
|
|
508
|
+
config.journey ? config : { journey: firstRunJourney },
|
|
508
509
|
journeyCommand.replaceAll(' ', ':'),
|
|
509
510
|
cliVersion,
|
|
510
511
|
);
|
|
511
512
|
config.journey = invocation.journey;
|
|
512
513
|
if (command === 'login') {
|
|
514
|
+
const observe = (checkpoint) => runtime.startupTelemetry?.report(config.endpoint, invocation.context, checkpoint);
|
|
515
|
+
observe('LOGIN_STARTED');
|
|
513
516
|
config.credentials = await browserLogin(config.endpoint, i18n, {
|
|
514
517
|
openBrowser: parsed.options['no-browser'] !== true,
|
|
515
518
|
json: parsed.options.json,
|
|
516
519
|
writeProgress: runtime.writeProgress,
|
|
517
520
|
journeyContext: invocation.context,
|
|
521
|
+
observe,
|
|
518
522
|
});
|
|
519
|
-
|
|
523
|
+
try {
|
|
524
|
+
await saveConfig(config);
|
|
525
|
+
} catch (error) {
|
|
526
|
+
observe('CREDENTIAL_SAVE_FAILED');
|
|
527
|
+
throw error;
|
|
528
|
+
}
|
|
529
|
+
observe('CREDENTIAL_SAVED');
|
|
520
530
|
if (parsed.options.json) {
|
|
521
531
|
return print({ loggedIn: true, ...authStatusSummary(config) }, true);
|
|
522
532
|
}
|
|
@@ -556,6 +566,12 @@ export async function main(argv, runtime = {}) {
|
|
|
556
566
|
}
|
|
557
567
|
|
|
558
568
|
const client = new NamesLinkClient(config, i18n, invocation.context);
|
|
569
|
+
if (!parsed.options['mfa-stdin'] && !parsed.options['mfa-code-file'] && !parsed.options['mfa-challenge']) {
|
|
570
|
+
client.mfaBrowser = (url, { expiresAt } = {}) => browserMfa(url, i18n, {
|
|
571
|
+
json: parsed.options.json, expiresAt, openBrowser: parsed.options['no-browser'] !== true,
|
|
572
|
+
writeProgress: runtime.writeProgress,
|
|
573
|
+
});
|
|
574
|
+
}
|
|
559
575
|
const profileRuntime = {
|
|
560
576
|
interactive: runtime.interactive ?? Boolean(stdin.isTTY && !parsed.options.json),
|
|
561
577
|
ask: runtime.ask || prompt,
|
|
@@ -1676,6 +1692,7 @@ function authStatusSummary(config) {
|
|
|
1676
1692
|
method:
|
|
1677
1693
|
credentials?.type === 'ak' ? 'NAMESLINK_AK_SK' : credentials?.type === 'oauth' ? 'NAMESLINK_OAUTH_PKCE' : 'NONE',
|
|
1678
1694
|
accountNo: credentials?.accountNo || null,
|
|
1695
|
+
...(credentials?.authorizationMode ? { authorizationMode: credentials.authorizationMode } : {}),
|
|
1679
1696
|
sessionMode: credentials?.type === 'oauth' ? 'oauth-bearer' : credentials?.type === 'ak' ? 'ak-signature' : 'none',
|
|
1680
1697
|
credentialStorage: config.credentialStorage || 'none',
|
|
1681
1698
|
};
|
package/src/client.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { createRequire } from 'node:module';
|
|
|
3
3
|
import { saveConfig, validateEndpoint } from './config.mjs';
|
|
4
4
|
import { createI18n } from './i18n.mjs';
|
|
5
5
|
import { prepareJourney, requestJourneyHeaders } from './journey.mjs';
|
|
6
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
6
7
|
|
|
7
8
|
const require = createRequire(import.meta.url);
|
|
8
9
|
const { version: packageVersion } = require('../package.json');
|
|
@@ -273,6 +274,12 @@ export class NamesLinkClient {
|
|
|
273
274
|
// high-risk operations cannot accidentally acquire or reuse DNS assurance.
|
|
274
275
|
const sessionSecret = usesMfaSession(method, reference) ? mfaSessionSecret(this.config) : null;
|
|
275
276
|
if (sessionSecret) headers['X-NamesLink-Mfa-Session'] = sessionSecret;
|
|
277
|
+
const browserMfa = this.mfaBrowser && this.config.credentials.type === 'oauth'
|
|
278
|
+
&& this.config.credentials.authorizationMode && !body?.mfaVerification;
|
|
279
|
+
if (browserMfa) {
|
|
280
|
+
headers['X-NamesLink-Mfa-Browser'] = '1';
|
|
281
|
+
if (options.mfaPromptId) headers['X-NamesLink-Mfa-Prompt'] = options.mfaPromptId;
|
|
282
|
+
}
|
|
276
283
|
const response = await fetchOrThrow(this.config, this.endpoint, url, {
|
|
277
284
|
method,
|
|
278
285
|
headers,
|
|
@@ -304,6 +311,10 @@ export class NamesLinkClient {
|
|
|
304
311
|
await this.prefetchCsrf(true);
|
|
305
312
|
return this.request(method, reference, body, { ...options, retry: false });
|
|
306
313
|
}
|
|
314
|
+
if (browserMfa && !options.mfaPromptId && payload?.code === 'Account.Mfa.BrowserRequired') {
|
|
315
|
+
const mfaPromptId = await this.waitForBrowserMfa(payload.data);
|
|
316
|
+
return this.request(method, reference, body, { ...options, mfaPromptId });
|
|
317
|
+
}
|
|
307
318
|
if (payload?.data?.resumeToken) {
|
|
308
319
|
this.config.lastInterruption = {
|
|
309
320
|
resumeToken: payload.data.resumeToken,
|
|
@@ -319,6 +330,24 @@ export class NamesLinkClient {
|
|
|
319
330
|
return payload.data;
|
|
320
331
|
}
|
|
321
332
|
|
|
333
|
+
async waitForBrowserMfa({ ticket, expiresAt } = {}) {
|
|
334
|
+
if (typeof ticket !== 'string' || !/^[a-f0-9-]{36}$/.test(ticket) || !Number.isFinite(expiresAt)) {
|
|
335
|
+
throw new Error('The server returned an invalid browser verification request.');
|
|
336
|
+
}
|
|
337
|
+
const prompt = new URL(`${this.endpoint}/account/oauth/cli/mfa-prompt`);
|
|
338
|
+
prompt.searchParams.set('ticket', ticket);
|
|
339
|
+
prompt.searchParams.set('lang', this.i18n.language);
|
|
340
|
+
const deadline = Math.min(expiresAt, Date.now() + 300_000);
|
|
341
|
+
await this.mfaBrowser(prompt.toString(), { expiresAt: deadline });
|
|
342
|
+
while (Date.now() < deadline) {
|
|
343
|
+
const result = await this.request('GET', `/account/oauth/cli/mfa-prompts/${ticket}`);
|
|
344
|
+
if (result?.status === 'APPROVED') return ticket;
|
|
345
|
+
await delay(2000);
|
|
346
|
+
}
|
|
347
|
+
throw new ApiError({ code: 'Account.Mfa.FlowExpired', message: 'Browser verification expired.' }, 400,
|
|
348
|
+
this.i18n, this.endpoint);
|
|
349
|
+
}
|
|
350
|
+
|
|
322
351
|
async refresh() {
|
|
323
352
|
assertCredentialEndpoint(this.config);
|
|
324
353
|
const response = await fetchOrThrow(this.config, this.endpoint, `${this.endpoint}/account/oauth/cli/refresh`, {
|
package/src/hosted-site.mjs
CHANGED
|
@@ -8,7 +8,9 @@ import { inspectUndeployableSiteSource } from './site-source-guidance.mjs';
|
|
|
8
8
|
import { withHostedJournal } from './hosted-journal.mjs';
|
|
9
9
|
|
|
10
10
|
const SITE_FIELDS = ['hostedSiteId', 'displayName', 'host', 'status', 'generation', 'bindingId',
|
|
11
|
-
'candidateReleaseId', 'lastVerifiedReleaseId', 'pendingReleaseId', 'historyComplete', 'legacy', 'version', 'url', 'problemCode', 'lastPublishedAt', 'previewSiteId'];
|
|
11
|
+
'candidateReleaseId', 'lastVerifiedReleaseId', 'pendingReleaseId', 'historyComplete', 'legacy', 'version', 'url', 'problemCode', 'domainConnectionProblem', 'lastPublishedAt', 'previewSiteId'];
|
|
12
|
+
const INITIAL_PUBLICATION_STATES = ['OWNERSHIP_PENDING', 'SAAS_PENDING', 'SAAS_HOSTNAME_CREATED', 'SAAS_ROUTE_CREATED',
|
|
13
|
+
'DNS_CERT_READY', 'KV_CANDIDATE_READY', 'ACTIVATING'];
|
|
12
14
|
const RELEASE_FIELDS = ['releaseId', 'versionNumber', 'previewSiteId', 'retentionState', 'firstVerifiedAt',
|
|
13
15
|
'lastVerifiedAt', 'recoverable', 'lastVerified', 'candidate'];
|
|
14
16
|
const OP_FIELDS = ['operationId', 'hostedSiteId', 'releaseId', 'bindingId', 'kind', 'generation', 'status', 'nextAction'];
|
|
@@ -85,9 +87,9 @@ export async function hostedSiteCommand(client, positionals, options, i18n, runt
|
|
|
85
87
|
};
|
|
86
88
|
if (options.watch) site = await poll(read, site,
|
|
87
89
|
(item) => ['DRAFT', 'ACTIVE', 'REMOVED', 'UNBOUND', 'UPDATE_UNKNOWN', 'ACTIVATION_UNKNOWN', 'UPDATE_FAILED', 'FAILED'].includes(item.status)
|
|
88
|
-
||
|
|
90
|
+
|| dnsNeedsAttention(dns), runtime);
|
|
89
91
|
return output({ site, complete: Boolean(site.url), ...(dns ? { domainSetup: dns } : {}), nextAction: site.url ? 'VISIT_SITE' :
|
|
90
|
-
publicationNextAction(dns) ||
|
|
92
|
+
publicationNextAction(dns, site) ||
|
|
91
93
|
(site.status === 'REMOVED' ? (site.candidateReleaseId ? 'REVIEW_PREVIEW_THEN_PUBLISH' : 'CREATE_PREVIEW') :
|
|
92
94
|
['UPDATE_UNKNOWN', 'ACTIVATION_UNKNOWN'].includes(site.status) ? 'READ_ORIGINAL_OPERATION' : 'INSPECT_SITE'),
|
|
93
95
|
...activationRecovery(site),
|
|
@@ -224,7 +226,7 @@ async function operationResult(client, siteId, original, operationKey, options,
|
|
|
224
226
|
operation, (item) => item.status === 'SUCCEEDED' || (item.status !== 'RUNNING' && !progressing()), runtime);
|
|
225
227
|
return { operation, site, idempotencyKey: operationKey, complete: operation.status === 'SUCCEEDED',
|
|
226
228
|
...(dns ? { domainSetup: dns } : {}),
|
|
227
|
-
nextAction: publicationNextAction(dns) || operation.nextAction,
|
|
229
|
+
nextAction: operation.status === 'SUCCEEDED' ? operation.nextAction : publicationNextAction(dns, site) || operation.nextAction,
|
|
228
230
|
...(current() ? activationRecovery(site) : {}),
|
|
229
231
|
statusCommand: `nameslink site hosted status ${siteId} --watch --json` };
|
|
230
232
|
}
|
|
@@ -242,19 +244,34 @@ function activationRecovery(site) {
|
|
|
242
244
|
] };
|
|
243
245
|
}
|
|
244
246
|
|
|
245
|
-
/**
|
|
247
|
+
/** Read DNS setup separately from publication, including after the site is live. */
|
|
246
248
|
async function publicationProgress(client, site) {
|
|
247
|
-
if (!site.bindingId ||
|
|
248
|
-
'
|
|
249
|
-
|
|
249
|
+
if (!site.bindingId || site.domainConnectionProblem
|
|
250
|
+
|| ![...INITIAL_PUBLICATION_STATES, 'ACTIVE', 'ACTIVATION_UNKNOWN', 'FAILED'].includes(site.status)) return null;
|
|
251
|
+
let value;
|
|
252
|
+
try {
|
|
253
|
+
value = await get(client, 'sites.publicationDns', { siteId: site.hostedSiteId });
|
|
254
|
+
} catch (error) {
|
|
255
|
+
if (error instanceof ApiError || isUnknown(error) || error.body?.data?.operation === 'sites.publicationDns') {
|
|
256
|
+
return { status: 'UNAVAILABLE' };
|
|
257
|
+
}
|
|
258
|
+
throw error;
|
|
259
|
+
}
|
|
250
260
|
if (value === null) return null;
|
|
251
261
|
if (!value || !['RUNNING', 'SUCCEEDED', 'UNKNOWN', 'CONFLICT', 'EXPIRED', 'REVIEW'].includes(value.status)
|
|
252
|
-
|| !Number.isFinite(Date.parse(value.expiresAt)) || value.planId != null && !/^[A-Za-z0-9_-]{1,128}$/.test(value.planId))
|
|
262
|
+
|| !Number.isFinite(Date.parse(value.expiresAt)) || value.planId != null && !/^[A-Za-z0-9_-]{1,128}$/.test(value.planId)) {
|
|
263
|
+
return { status: 'UNAVAILABLE' };
|
|
264
|
+
}
|
|
253
265
|
return pick(value, ['status', 'planId', 'expiresAt']);
|
|
254
266
|
}
|
|
255
267
|
|
|
256
|
-
function
|
|
257
|
-
|
|
268
|
+
function dnsNeedsAttention(dns) {
|
|
269
|
+
return ['UNKNOWN', 'CONFLICT', 'EXPIRED', 'REVIEW'].includes(dns?.status);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function publicationNextAction(dns, site) {
|
|
273
|
+
if (!dns || dns.status === 'UNAVAILABLE') return null;
|
|
274
|
+
if (dns.status === 'SUCCEEDED') return INITIAL_PUBLICATION_STATES.includes(site.status) ? 'WAIT_FOR_PUBLICATION' : null;
|
|
258
275
|
if (dns.status === 'RUNNING') return 'WAIT_FOR_PUBLICATION';
|
|
259
276
|
if (dns.status === 'UNKNOWN') return 'CHECK_ORIGINAL_DNS_PLAN';
|
|
260
277
|
return 'REVIEW_DOMAIN_SETUP';
|
|
@@ -607,9 +624,17 @@ function output(value, options, runtime) {
|
|
|
607
624
|
const lines = [];
|
|
608
625
|
if (value.site) {
|
|
609
626
|
lines.push(`${value.site.displayName || value.site.hostedSiteId}${value.site.host ? ` · ${value.site.host}` : ''}`);
|
|
610
|
-
|
|
627
|
+
const connectionProblem = value.site.domainConnectionProblem;
|
|
628
|
+
lines.push(connectionProblem
|
|
629
|
+
? i18n?.optional(`hosted.connection.${connectionProblem}`) || connectionProblem
|
|
630
|
+
: i18n?.optional(`hosted.status.${value.site.status}`) || value.site.status);
|
|
611
631
|
if (value.site.url) lines.push(value.site.url);
|
|
612
632
|
}
|
|
633
|
+
if (value.domainSetup) {
|
|
634
|
+
const label = i18n?.optional('hosted.dns.label') || 'Automatic DNS';
|
|
635
|
+
const status = value.domainSetup.status;
|
|
636
|
+
lines.push(`${label}${i18n?.colon || ': '}${i18n?.optional(`hosted.dns.${status}`) || status}`);
|
|
637
|
+
}
|
|
613
638
|
if (value.previewUrl) lines.push(`${i18n?.t('hosted.preview') || 'Preview'}${i18n?.colon || ': '}${value.previewUrl}`);
|
|
614
639
|
if (value.release?.versionNumber) lines.push(`${i18n?.t('hosted.version') || 'Version'}${i18n?.colon || ': '}${value.release.versionNumber}`);
|
|
615
640
|
if (value.nextAction) lines.push(i18n?.optional(`hosted.next.${value.nextAction}`) || value.nextAction);
|
package/src/i18n.mjs
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { absoluteConsoleUrl } from './urls.mjs';
|
|
2
2
|
|
|
3
3
|
const EN_US = {
|
|
4
|
-
'hosted.next.WAIT_FOR_PUBLICATION': 'NamesLink is publishing your site
|
|
4
|
+
'hosted.next.WAIT_FOR_PUBLICATION': 'NamesLink is publishing your site. Follow the status command to check progress.',
|
|
5
|
+
'hosted.dns.label': 'Automatic DNS',
|
|
6
|
+
'hosted.dns.RUNNING': 'Configuring',
|
|
7
|
+
'hosted.dns.SUCCEEDED': 'Ready',
|
|
8
|
+
'hosted.dns.UNKNOWN': 'Checking the original attempt',
|
|
9
|
+
'hosted.dns.CONFLICT': 'Conflicting records',
|
|
10
|
+
'hosted.dns.EXPIRED': 'Setup timed out',
|
|
11
|
+
'hosted.dns.REVIEW': 'Needs review',
|
|
12
|
+
'hosted.dns.UNAVAILABLE': 'Status unavailable',
|
|
13
|
+
'hosted.connection.DNS_HOSTING_MOVED': 'Domain disconnected. DNS hosting has moved.',
|
|
14
|
+
'hosted.connection.DNS_RECORD_CHANGED': 'Domain disconnected. The DNS records no longer point to this site.',
|
|
5
15
|
'hosted.next.CHECK_ORIGINAL_DNS_PLAN': 'Check the original DNS plan shown in domainSetup.planId. Do not start another publication.',
|
|
6
16
|
'hosted.next.REVIEW_DOMAIN_SETUP': 'Automatic setup paused. Review the domain settings and the original plan before continuing.',
|
|
7
17
|
'apiError.Cli.Hosted.DestinationUnavailable': 'We could not check this address. Check the full hostname and try again.',
|
|
@@ -18,6 +28,9 @@ const EN_US = {
|
|
|
18
28
|
'apiError.Drop.Hosted.Dns.INCONSISTENT': 'We could not verify the DNS setup records. Contact support with the original plan ID.',
|
|
19
29
|
'hosted.preview': "Preview",
|
|
20
30
|
'hosted.version': "Version",
|
|
31
|
+
'hosted.status.DNS_CERT_READY': "Preparing publication",
|
|
32
|
+
'hosted.status.KV_CANDIDATE_READY': "Preparing publication",
|
|
33
|
+
'hosted.status.ACTIVATING': "Verifying the site",
|
|
21
34
|
'hosted.status.ACTIVE': "Published",
|
|
22
35
|
'hosted.status.DRAFT': "Not published",
|
|
23
36
|
'hosted.next.REVIEW_PREVIEW_THEN_PUBLISH': "Review the preview, then explicitly publish this version to your domain.",
|
|
@@ -212,6 +225,8 @@ const EN_US = {
|
|
|
212
225
|
'error.walletTopUpTimeout':
|
|
213
226
|
'The top-up has not been credited yet. Do not create or pay another top-up. Check `{balanceCommand}`; after the balance arrives, continue the same reviewed purchase with `{resumeCommand}`.',
|
|
214
227
|
'login.opening': 'Opening NamesLink authorization in your browser…',
|
|
228
|
+
'mfa.browserWaiting': 'Waiting for you to complete MFA in the browser that just opened. Remind the customer and keep this command running; it continues automatically after verification. Do not ask for their verification codes in chat.',
|
|
229
|
+
'mfa.browserManual': 'Open the link below to complete MFA in your browser. Remind the customer and keep this command running; it continues automatically after verification. Do not ask for their verification codes in chat.',
|
|
215
230
|
'login.openingManual': 'Open this NamesLink authorization URL in your browser:',
|
|
216
231
|
'login.browserUnavailable': 'Could not open a browser automatically. Continue with the URL below. A remote shell needs access to this CLI process\'s loopback callback; --no-browser does not provide cross-device login.',
|
|
217
232
|
'login.openingHint':
|
|
@@ -737,7 +752,17 @@ const EN_US = {
|
|
|
737
752
|
};
|
|
738
753
|
|
|
739
754
|
const ZH_CN = {
|
|
740
|
-
'hosted.next.WAIT_FOR_PUBLICATION': 'NamesLink
|
|
755
|
+
'hosted.next.WAIT_FOR_PUBLICATION': 'NamesLink 正在发布网站。可用返回的状态命令查看进度。',
|
|
756
|
+
'hosted.dns.label': '自动 DNS',
|
|
757
|
+
'hosted.dns.RUNNING': '配置中',
|
|
758
|
+
'hosted.dns.SUCCEEDED': '已就绪',
|
|
759
|
+
'hosted.dns.UNKNOWN': '正在核对原操作',
|
|
760
|
+
'hosted.dns.CONFLICT': '记录冲突',
|
|
761
|
+
'hosted.dns.EXPIRED': '配置超时',
|
|
762
|
+
'hosted.dns.REVIEW': '需要检查',
|
|
763
|
+
'hosted.dns.UNAVAILABLE': '暂时无法查询状态',
|
|
764
|
+
'hosted.connection.DNS_HOSTING_MOVED': '域名已断开,DNS 托管已迁移。',
|
|
765
|
+
'hosted.connection.DNS_RECORD_CHANGED': '域名已断开,DNS 记录已不再指向本站。',
|
|
741
766
|
'hosted.next.CHECK_ORIGINAL_DNS_PLAN': '请核对 domainSetup.planId 中的原解析计划,不要重新发布。',
|
|
742
767
|
'hosted.next.REVIEW_DOMAIN_SETUP': '自动配置已暂停。请检查域名设置和原解析计划,再继续。',
|
|
743
768
|
'apiError.Cli.Hosted.DestinationUnavailable': '暂时无法确认这个地址,请检查完整域名后重试。',
|
|
@@ -754,6 +779,9 @@ const ZH_CN = {
|
|
|
754
779
|
'apiError.Drop.Hosted.Dns.INCONSISTENT': '解析配置记录需要核对,请携带原计划编号联系支持。',
|
|
755
780
|
'hosted.preview': "预览地址",
|
|
756
781
|
'hosted.version': "版本",
|
|
782
|
+
'hosted.status.DNS_CERT_READY': "正在准备发布",
|
|
783
|
+
'hosted.status.KV_CANDIDATE_READY': "正在准备发布",
|
|
784
|
+
'hosted.status.ACTIVATING': "正在验证站点",
|
|
757
785
|
'hosted.status.ACTIVE': "已发布",
|
|
758
786
|
'hosted.status.DRAFT': "未发布",
|
|
759
787
|
'hosted.next.REVIEW_PREVIEW_THEN_PUBLISH': "请查看预览效果,再明确发布此版本到自有域名。",
|
|
@@ -945,6 +973,8 @@ const ZH_CN = {
|
|
|
945
973
|
'login.opening': '正在打开 NamesLink 授权页…',
|
|
946
974
|
'login.openingManual': '请在浏览器中打开以下 NamesLink 授权链接:',
|
|
947
975
|
'login.browserUnavailable': '无法自动打开浏览器,请用下方链接继续。远程终端仍需能访问此 CLI 进程的本机回调,--no-browser 不代表支持跨设备登录。',
|
|
976
|
+
'mfa.browserWaiting': '正在等待客户在已打开的浏览器中完成 MFA。请提醒客户完成验证,并保持当前命令运行;验证后会自动继续。不要在对话中索取验证码。',
|
|
977
|
+
'mfa.browserManual': '请打开下方链接,在浏览器中完成 MFA。请提醒客户完成验证,并保持当前命令运行;验证后会自动继续。不要在对话中索取验证码。',
|
|
948
978
|
'login.openingHint': '页面上会写明将要授权哪个账号。同一账号就直接确认;要换账号请点页面上的「换其他账号」——退出 CLI 并不会退出浏览器登录态。',
|
|
949
979
|
'login.success': 'NamesLink 登录成功,账号:{accountNo}。',
|
|
950
980
|
'logout.success':
|
package/src/oauth.mjs
CHANGED
|
@@ -10,6 +10,30 @@ import {
|
|
|
10
10
|
import { createI18n } from './i18n.mjs';
|
|
11
11
|
import { appendJourneyQuery, requestJourneyHeaders } from './journey.mjs';
|
|
12
12
|
|
|
13
|
+
/** Open the customer handoff and notify the calling agent before verification polling starts. */
|
|
14
|
+
export async function browserMfa(url, i18n = createI18n('en-US'), options = {}) {
|
|
15
|
+
let browserOpened = options.openBrowser !== false;
|
|
16
|
+
let launchFailed = false;
|
|
17
|
+
if (browserOpened) {
|
|
18
|
+
try {
|
|
19
|
+
await (options.openBrowserFn || openBrowser)(url);
|
|
20
|
+
} catch {
|
|
21
|
+
browserOpened = false;
|
|
22
|
+
launchFailed = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const message = i18n.t(browserOpened ? 'mfa.browserWaiting' : 'mfa.browserManual');
|
|
26
|
+
const writeProgress = options.writeProgress || ((value) => process.stderr.write(value));
|
|
27
|
+
writeProgress(options.json
|
|
28
|
+
? `${JSON.stringify({ type: 'mfa.browser', status: 'WAITING_FOR_USER',
|
|
29
|
+
agentAction: 'NOTIFY_USER_AND_WAIT',
|
|
30
|
+
nextAction: browserOpened ? 'COMPLETE_BROWSER_MFA' : 'OPEN_VERIFICATION_URL',
|
|
31
|
+
browserOpened, message, url, expiresAt: options.expiresAt,
|
|
32
|
+
...(launchFailed ? { reason: 'BROWSER_UNAVAILABLE' } : {}),
|
|
33
|
+
})}\n`
|
|
34
|
+
: `${message}\n${browserOpened ? '' : `${url}\n`}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
13
37
|
export async function browserLogin(endpoint, i18n = createI18n('en-US'), options = {}) {
|
|
14
38
|
const verifier = randomBytes(32).toString('base64url');
|
|
15
39
|
const challenge = createHash('sha256').update(verifier).digest('base64url');
|
|
@@ -66,6 +90,8 @@ export async function browserLogin(endpoint, i18n = createI18n('en-US'), options
|
|
|
66
90
|
launchFailed = true;
|
|
67
91
|
}
|
|
68
92
|
}
|
|
93
|
+
options.observe?.(browserOpened ? 'BROWSER_LAUNCHED'
|
|
94
|
+
: launchFailed ? 'BROWSER_LAUNCH_FAILED' : 'BROWSER_MANUAL');
|
|
69
95
|
if (options.json) {
|
|
70
96
|
const writeProgress = options.writeProgress || ((value) => process.stderr.write(value));
|
|
71
97
|
writeProgress(`${JSON.stringify({
|
|
@@ -82,16 +108,23 @@ export async function browserLogin(endpoint, i18n = createI18n('en-US'), options
|
|
|
82
108
|
process.stdout.write(`${i18n.t('login.openingHint')}\n`);
|
|
83
109
|
}
|
|
84
110
|
code = await waitForOAuthCallback(callback.promise, 300_000, setTimeout, clearTimeout, i18n);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
options.observe?.('CALLBACK_NOT_COMPLETED');
|
|
113
|
+
throw error;
|
|
85
114
|
} finally {
|
|
86
115
|
await new Promise((resolve) => server.close(resolve));
|
|
87
116
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
options.
|
|
94
|
-
|
|
117
|
+
options.observe?.('CALLBACK_RECEIVED');
|
|
118
|
+
try {
|
|
119
|
+
const credentials = await exchangeOAuthCode(
|
|
120
|
+
endpoint, { code, verifier, redirectUri }, i18n, options.fetchFn || fetch, options.journeyContext,
|
|
121
|
+
);
|
|
122
|
+
options.observe?.('TOKEN_RECEIVED');
|
|
123
|
+
return credentials;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
options.observe?.('TOKEN_NOT_RECEIVED');
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
95
128
|
}
|
|
96
129
|
|
|
97
130
|
export async function exchangeOAuthCode(
|
|
@@ -144,6 +177,10 @@ export async function exchangeOAuthCode(
|
|
|
144
177
|
if (!tokenResponse.ok || payload.code !== '200') {
|
|
145
178
|
throw new ApiError(payload, tokenResponse.status, i18n, endpoint);
|
|
146
179
|
}
|
|
180
|
+
if (typeof payload.data?.accessToken !== 'string' || !payload.data.accessToken
|
|
181
|
+
|| typeof payload.data?.refreshToken !== 'string' || !payload.data.refreshToken) {
|
|
182
|
+
throw new UnexpectedResponseError(endpoint, tokenResponse.status, 'MISSING_TOKENS');
|
|
183
|
+
}
|
|
147
184
|
return {
|
|
148
185
|
type: 'oauth',
|
|
149
186
|
endpoint: endpoint.replace(/\/$/, ''),
|
|
@@ -152,6 +189,8 @@ export async function exchangeOAuthCode(
|
|
|
152
189
|
// A new secure-store nonce separates logins even if the server issues equal JWTs in one second.
|
|
153
190
|
mfaSessionNonce: randomBytes(32).toString('base64url'),
|
|
154
191
|
accountNo: payload.data.accountNo,
|
|
192
|
+
...(['FULL', 'ON_DEMAND'].includes(payload.data.authorizationMode)
|
|
193
|
+
? { authorizationMode: payload.data.authorizationMode } : {}),
|
|
155
194
|
};
|
|
156
195
|
}
|
|
157
196
|
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { configPaths, loadConfig, validateEndpoint } from './config.mjs';
|
|
5
|
+
import { prepareJourney, requestJourneyHeaders } from './journey.mjs';
|
|
6
|
+
|
|
7
|
+
const ENDPOINTS = new Set([
|
|
8
|
+
'nameslink.com', 'www.nameslink.com', 'api.nameslink.com',
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
/** Best-effort usage observations. Only the existing random journey and fixed event names leave the CLI. */
|
|
12
|
+
export function createStartupTelemetry({
|
|
13
|
+
environment = process.env, paths = configPaths(), readPreferences = loadConfig,
|
|
14
|
+
transport = () => fetch,
|
|
15
|
+
} = {}) {
|
|
16
|
+
if (environment.NAMESLINK_TELEMETRY_DISABLED === '1' || environment.NODE_TEST_CONTEXT) return undefined;
|
|
17
|
+
const pending = new Set();
|
|
18
|
+
const transports = new Map();
|
|
19
|
+
|
|
20
|
+
function report(endpoint, context, checkpoint) {
|
|
21
|
+
const delivery = send(endpoint, context, checkpoint);
|
|
22
|
+
pending.add(delivery);
|
|
23
|
+
delivery.then(() => pending.delete(delivery));
|
|
24
|
+
return delivery;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function send(endpoint, context, checkpoint) {
|
|
28
|
+
try {
|
|
29
|
+
if (!context || !isTelemetryEndpoint(endpoint)) return false;
|
|
30
|
+
if (!transports.has(endpoint)) transports.set(endpoint, transport(endpoint));
|
|
31
|
+
const response = await transports.get(endpoint)(`${endpoint}/account/oauth/cli/telemetry/${checkpoint}`, {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
credentials: 'omit',
|
|
34
|
+
redirect: 'error',
|
|
35
|
+
headers: requestJourneyHeaders(context),
|
|
36
|
+
signal: AbortSignal.timeout(2500),
|
|
37
|
+
});
|
|
38
|
+
await response.body?.cancel();
|
|
39
|
+
return response.status === 204;
|
|
40
|
+
} catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function firstRun(endpointOption, command, version) {
|
|
46
|
+
try {
|
|
47
|
+
const preferences = await readPreferences({ readCredentials: false });
|
|
48
|
+
const { endpoint } = validateEndpoint(endpointOption || preferences.endpoint, environment);
|
|
49
|
+
if (!isTelemetryEndpoint(endpoint)) return undefined;
|
|
50
|
+
const key = createHash('sha256').update(endpoint).digest('hex').slice(0, 16);
|
|
51
|
+
const dir = join(paths.dir, 'observability');
|
|
52
|
+
const seed = join(dir, `first-run-${key}.json`);
|
|
53
|
+
const receipt = join(dir, `first-run-${key}.sent`);
|
|
54
|
+
let existing;
|
|
55
|
+
try {
|
|
56
|
+
await readFile(receipt);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (error.code !== 'ENOENT') return undefined;
|
|
59
|
+
existing = await prepareFirstRun(dir, seed, preferences, command, version, environment);
|
|
60
|
+
const delivery = report(endpoint, existing.context, 'FIRST_RUN').then(async (accepted) => {
|
|
61
|
+
if (accepted) await writeFile(receipt, '', { mode: 0o600 }).catch(() => {});
|
|
62
|
+
});
|
|
63
|
+
pending.add(delivery);
|
|
64
|
+
delivery.then(() => pending.delete(delivery));
|
|
65
|
+
return existing.journey;
|
|
66
|
+
}
|
|
67
|
+
// A first invocation may have exited after --help without creating config.json.
|
|
68
|
+
return JSON.parse(await readFile(seed, 'utf8')).journey;
|
|
69
|
+
} catch {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return { firstRun, report, drain: () => Promise.all(pending) };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function prepareFirstRun(dir, seed, preferences, command, version, environment) {
|
|
78
|
+
try {
|
|
79
|
+
return JSON.parse(await readFile(seed, 'utf8'));
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if (error.code !== 'ENOENT') throw error;
|
|
82
|
+
}
|
|
83
|
+
const first = prepareJourney(preferences, command, version, environment);
|
|
84
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
85
|
+
try {
|
|
86
|
+
await writeFile(seed, JSON.stringify(first), { flag: 'wx', mode: 0o600 });
|
|
87
|
+
return first;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (error.code !== 'EEXIST') throw error;
|
|
90
|
+
return JSON.parse(await readFile(seed, 'utf8'));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function isTelemetryEndpoint(endpoint) {
|
|
95
|
+
const url = new URL(endpoint);
|
|
96
|
+
return url.protocol === 'https:' && ENDPOINTS.has(url.hostname) && url.pathname === '/api'
|
|
97
|
+
&& !url.port && !url.username && !url.password && !url.search && !url.hash;
|
|
98
|
+
}
|