burrow-cli 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +594 -2
  3. package/bin/burrow.js +200 -0
  4. package/examples/acme-shop.tunnel.yml +18 -0
  5. package/package.json +45 -4
  6. package/src/access.js +163 -0
  7. package/src/add.js +106 -0
  8. package/src/cloudflare.js +118 -0
  9. package/src/commands.js +386 -0
  10. package/src/completion.js +127 -0
  11. package/src/config-file.js +31 -0
  12. package/src/config.js +82 -0
  13. package/src/dashboard/auth.js +79 -0
  14. package/src/dashboard/data.js +70 -0
  15. package/src/dashboard/logs.js +95 -0
  16. package/src/dashboard/manage.js +102 -0
  17. package/src/dashboard/panels/README.md +50 -0
  18. package/src/dashboard/panels/access.js +218 -0
  19. package/src/dashboard/panels/alerts.js +244 -0
  20. package/src/dashboard/panels/backup.js +193 -0
  21. package/src/dashboard/panels/bulk.js +246 -0
  22. package/src/dashboard/panels/cleanup.js +237 -0
  23. package/src/dashboard/panels/doctor.js +119 -0
  24. package/src/dashboard/panels/health.js +146 -0
  25. package/src/dashboard/panels/history.js +104 -0
  26. package/src/dashboard/panels/hooks.js +86 -0
  27. package/src/dashboard/panels/live.js +153 -0
  28. package/src/dashboard/panels/project-form.js +463 -0
  29. package/src/dashboard/panels/quick-actions.js +133 -0
  30. package/src/dashboard/panels/sessions.js +267 -0
  31. package/src/dashboard/panels/shares.js +280 -0
  32. package/src/dashboard/panels/stats.js +165 -0
  33. package/src/dashboard/panels/updates.js +156 -0
  34. package/src/dashboard/panels/uptime.js +115 -0
  35. package/src/dashboard/panels.js +53 -0
  36. package/src/dashboard/server.js +390 -0
  37. package/src/dashboard/session-store.js +47 -0
  38. package/src/dashboard/totp.js +103 -0
  39. package/src/dashboard/ui.js +454 -0
  40. package/src/doctor.js +342 -0
  41. package/src/edit.js +135 -0
  42. package/src/health-observer.js +81 -0
  43. package/src/history.js +145 -0
  44. package/src/hooks.js +256 -0
  45. package/src/naming.js +38 -0
  46. package/src/open.js +67 -0
  47. package/src/pending.js +72 -0
  48. package/src/process.js +95 -0
  49. package/src/project-form.js +134 -0
  50. package/src/project.js +114 -0
  51. package/src/prune.js +99 -0
  52. package/src/rename-state.js +39 -0
  53. package/src/restart.js +35 -0
  54. package/src/service.js +173 -0
  55. package/src/share-expiry.js +55 -0
  56. package/src/share.js +275 -0
  57. package/src/shell-words.js +284 -0
  58. package/src/stats.js +180 -0
  59. package/src/transfer.js +124 -0
  60. package/src/update.js +254 -0
  61. package/src/uptime.js +91 -0
  62. package/src/watch.js +263 -0
  63. package/src/zones.js +102 -0
package/src/watch.js ADDED
@@ -0,0 +1,263 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { createConnection } from 'node:net';
4
+ import { dirname, join } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { configPath, loadConfig, parseEnv, stateDir } from './config.js';
7
+ import { Cloudflare } from './cloudflare.js';
8
+ import { tunnelName } from './naming.js';
9
+ import { DASHBOARD_PROJECT, dashboardProject, loadProjectFile } from './project.js';
10
+ import { localProjects, readMeta, readPid, runningPid } from './process.js';
11
+ import { isShare } from './share.js';
12
+ import { recordEvent } from './history.js';
13
+ import { unitDir } from './service.js';
14
+
15
+ const log = (...a) => console.log(...a);
16
+ const BIN = fileURLToPath(new URL('../bin/burrow.js', import.meta.url));
17
+ export const WATCH_UNIT = 'burrow-watch.service';
18
+ export const watchStateFile = () => join(stateDir(), 'watch', 'state.json');
19
+
20
+ // Alert settings come from the environment or the burrow config file.
21
+ export function settings(env = process.env) {
22
+ let file = {};
23
+ try { if (existsSync(configPath())) file = parseEnv(readFileSync(configPath(), 'utf8')); } catch {}
24
+ const get = (k) => env[k] || file[k] || '';
25
+ return { webhook: get('BURROW_ALERT_WEBHOOK'), ntfy: get('BURROW_ALERT_NTFY'), ntfyToken: get('BURROW_ALERT_NTFY_TOKEN') };
26
+ }
27
+
28
+ // host:port pairs a project's services listen on, from its tunnel.yml.
29
+ export function localTargets(project, cfg = loadConfig()) {
30
+ let proj = null;
31
+ if (project === DASHBOARD_PROJECT) proj = dashboardProject(cfg.dashboardPort);
32
+ else {
33
+ const file = readMeta(project)?.file;
34
+ if (file && existsSync(file)) { try { proj = loadProjectFile(file); } catch {} }
35
+ }
36
+ if (!proj) return [];
37
+ const out = new Map();
38
+ const add = (service, url) => {
39
+ let u;
40
+ try { u = new URL(url); } catch { return; }
41
+ const port = Number(u.port) || { 'http:': 80, 'ws:': 80, 'https:': 443, 'wss:': 443, 'ssh:': 22 }[u.protocol];
42
+ if (!port || !u.hostname) return;
43
+ const host = u.hostname.replace(/^\[|\]$/g, '');
44
+ if (!out.has(`${host}:${port}`)) out.set(`${host}:${port}`, { service, host, port });
45
+ };
46
+ for (const s of proj.services) {
47
+ add(s.name, s.url);
48
+ for (const p of s.paths) add(s.name, p.url);
49
+ }
50
+ return [...out.values()];
51
+ }
52
+
53
+ export function tcpOpen(host, port, timeoutMs = 2000) {
54
+ return new Promise((resolve) => {
55
+ const sock = createConnection({ host, port });
56
+ const done = (ok) => { sock.destroy(); resolve(ok); };
57
+ sock.setTimeout(timeoutMs, () => done(false));
58
+ sock.once('connect', () => done(true));
59
+ sock.once('error', () => done(false));
60
+ });
61
+ }
62
+
63
+ // One project's health: ok | degraded | down, with the reasons.
64
+ export async function checkProject(project, { tunnels, cfg }) {
65
+ const problems = [];
66
+ const pid = runningPid(project);
67
+ if (!pid) problems.push(['down', readPid(project) ? 'cloudflared is not running (it exited or crashed)' : 'cloudflared is not running']);
68
+ if (tunnels) {
69
+ const t = tunnels.find((x) => x.name === tunnelName(project));
70
+ if (!t) problems.push(['down', `tunnel ${tunnelName(project)} not found on Cloudflare`]);
71
+ else if (t.status === 'down' || t.status === 'inactive') problems.push(['down', `tunnel is ${t.status} (no connections)`]);
72
+ else if (t.status === 'degraded') problems.push(['degraded', `tunnel is degraded (${(t.connections || []).length} connection(s))`]);
73
+ }
74
+ for (const t of localTargets(project, cfg)) {
75
+ if (!(await tcpOpen(t.host, t.port))) problems.push(['degraded', `${t.service}: nothing listening on ${t.host}:${t.port}`]);
76
+ }
77
+ const status = problems.some(([l]) => l === 'down') ? 'down' : problems.length ? 'degraded' : 'ok';
78
+ return { project, status, problems: problems.map(([, what]) => what), hostnames: readMeta(project)?.hostnames || [] };
79
+ }
80
+
81
+ // Debounce: a new status has to be seen `debounce` times in a row before it counts.
82
+ // The first observation is compared with "ok", so a project that is already broken alerts.
83
+ export function evaluate(prev, observed, debounce, now = Date.now()) {
84
+ const cur = prev || { status: 'ok', pending: null, count: 0, since: now };
85
+ if (observed === cur.status) return { next: { ...cur, pending: null, count: 0 }, change: null };
86
+ const count = cur.pending === observed ? cur.count + 1 : 1;
87
+ if (count >= debounce) {
88
+ return { next: { status: observed, pending: null, count: 0, since: now }, change: { from: cur.status, to: observed } };
89
+ }
90
+ return { next: { ...cur, pending: observed, count }, change: null };
91
+ }
92
+
93
+ export function alertText(a) {
94
+ if (a.to === 'ok') return `burrow: ${a.project} recovered (was ${a.from})`;
95
+ return `burrow: ${a.project} is ${a.to === 'down' ? 'DOWN' : 'degraded'}: ${a.problems.join('; ')}`;
96
+ }
97
+
98
+ // Slack and Discord want {text} and {content}; anything else gets the full JSON payload.
99
+ export function webhookBody(url, a) {
100
+ const text = alertText(a);
101
+ let host = '';
102
+ try { host = new URL(url).hostname; } catch {}
103
+ if (/(^|\.)discord(app)?\.com$/.test(host)) return { content: text };
104
+ if (host === 'hooks.slack.com') return { text };
105
+ return {
106
+ text, content: text, project: a.project, status: a.to, previous: a.from,
107
+ problems: a.problems, hostnames: a.hostnames, at: new Date(a.at).toISOString(),
108
+ };
109
+ }
110
+
111
+ async function post(url, body, headers) {
112
+ const res = await fetch(url, { method: 'POST', body, headers, signal: AbortSignal.timeout(10000) });
113
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
114
+ }
115
+
116
+ // Never prints the webhook URL or the ntfy token: both are secrets.
117
+ // `report` gets delivery failures (the dashboard shows them); returns how many failed.
118
+ export async function sendAlert(a, s, { dry = false, report = (m) => console.error(m) } = {}) {
119
+ let failed = 0;
120
+ log(`${dry ? '[dry-run] ' : ''}alert: ${alertText(a)}`);
121
+ if (dry) return 0;
122
+ if (s.webhook) {
123
+ try { await post(s.webhook, JSON.stringify(webhookBody(s.webhook, a)), { 'Content-Type': 'application/json' }); } catch (e) {
124
+ failed++;
125
+ report(`burrow: webhook alert failed: ${e.name === 'TimeoutError' ? 'timed out' : e.message}`);
126
+ }
127
+ }
128
+ if (s.ntfy) {
129
+ const url = /^https?:\/\//.test(s.ntfy) ? s.ntfy : `https://ntfy.sh/${encodeURIComponent(s.ntfy)}`;
130
+ const headers = {
131
+ Title: `burrow: ${a.project} ${a.to === 'ok' ? 'recovered' : a.to}`,
132
+ Priority: a.to === 'down' ? 'high' : 'default',
133
+ Tags: a.to === 'ok' ? 'white_check_mark' : a.to === 'down' ? 'rotating_light' : 'warning',
134
+ 'Content-Type': 'text/plain; charset=utf-8',
135
+ };
136
+ if (s.ntfyToken) headers.Authorization = `Bearer ${s.ntfyToken}`;
137
+ const body = [alertText(a), ...a.hostnames.map((h) => `https://${h}`)].join('\n');
138
+ try { await post(url, body, headers); } catch (e) {
139
+ failed++;
140
+ report(`burrow: ntfy alert failed: ${e.name === 'TimeoutError' ? 'timed out' : e.message}`);
141
+ }
142
+ }
143
+ return failed;
144
+ }
145
+
146
+ function readState() { try { return JSON.parse(readFileSync(watchStateFile(), 'utf8')); } catch { return {}; } }
147
+ function writeState(st) {
148
+ mkdirSync(dirname(watchStateFile()), { recursive: true, mode: 0o700 });
149
+ writeFileSync(watchStateFile(), JSON.stringify(st, null, 2) + '\n', { mode: 0o600 });
150
+ }
151
+
152
+ // Projects with a pid file (running, or crashed). `burrow down` removes the pid file,
153
+ // so a project you stopped on purpose is no longer watched.
154
+ function watched(args) {
155
+ return args.length ? args : localProjects().filter((p) => !isShare(p));
156
+ }
157
+
158
+ async function tick(args, { debounce, dry, verbose }) {
159
+ const cfg = loadConfig();
160
+ let tunnels = null;
161
+ if (cfg.token && cfg.accountId) {
162
+ try {
163
+ tunnels = await new Cloudflare({ token: cfg.token, accountId: cfg.accountId }).listTunnels();
164
+ } catch (e) {
165
+ console.error(`burrow: Cloudflare API check skipped: ${e.message}`);
166
+ }
167
+ }
168
+ const s = settings();
169
+ const prev = readState();
170
+ const next = {};
171
+ const projects = watched(args);
172
+ if (!projects.length && verbose) log('No running burrow projects to watch.');
173
+ for (const project of projects) {
174
+ const r = await checkProject(project, { tunnels, cfg });
175
+ const { next: st, change } = evaluate(prev[project], r.status, debounce);
176
+ next[project] = st;
177
+ if (verbose) log(`${project}: ${r.status}${r.problems.length ? ` (${r.problems.join('; ')})` : ''}${st.pending ? ` [${st.pending} ${st.count}/${debounce}]` : ''}`);
178
+ if (change && !dry) {
179
+ // Health transitions go to the event history too (the dashboard's uptime timeline reads them).
180
+ recordEvent({ action: 'health', project, source: 'watch', ok: change.to === 'ok', detail: `${change.to}${r.problems.length ? `: ${r.problems.join('; ')}` : ''} (was ${change.from})` });
181
+ }
182
+ if (change) await sendAlert({ ...change, project, problems: r.problems, hostnames: r.hostnames, at: Date.now() }, s, { dry });
183
+ }
184
+ writeState(next);
185
+ }
186
+
187
+ function renderUnit({ interval, debounce, env = process.env }) {
188
+ const q = (v) => (/^[A-Za-z0-9_@%+=:,./-]+$/.test(v) ? v : `"${String(v).replace(/(["\\])/g, '\\$1')}"`);
189
+ const keep = ['PATH', 'BURROW_CONFIG', 'BURROW_STATE_DIR', 'XDG_CONFIG_HOME', 'XDG_STATE_HOME'];
190
+ const envLines = keep.filter((k) => env[k]).map((k) => `Environment=${q(`${k}=${env[k]}`)}`);
191
+ return `# Generated by "burrow watch --install-service". Remove with "burrow watch --uninstall-service".
192
+ [Unit]
193
+ Description=burrow watch: alerts for Cloudflare Tunnel projects
194
+ Wants=network-online.target
195
+ After=network-online.target
196
+
197
+ [Service]
198
+ Type=simple
199
+ ${envLines.join('\n')}
200
+ ExecStart=${[process.execPath, BIN, 'watch', '--interval', String(interval), '--debounce', String(debounce)].map(q).join(' ')}
201
+ Restart=on-failure
202
+ RestartSec=30
203
+
204
+ [Install]
205
+ WantedBy=default.target
206
+ `;
207
+ }
208
+
209
+ function systemctl(...args) {
210
+ const r = spawnSync(process.env.BURROW_SYSTEMCTL || 'systemctl', ['--user', ...args], { encoding: 'utf8', timeout: 30000, killSignal: 'SIGKILL' });
211
+ return { ok: !r.error && r.status === 0, out: `${r.stdout || ''}${r.stderr || ''}`.trim(), error: r.error };
212
+ }
213
+
214
+ async function serviceAction(opts, interval, debounce) {
215
+ const path = join(unitDir(), WATCH_UNIT);
216
+ if (opts.uninstallService) {
217
+ if (opts.dryRun) { log(`[dry-run] would disable ${WATCH_UNIT} and remove ${path}`); return; }
218
+ systemctl('disable', '--now', WATCH_UNIT);
219
+ rmSync(path, { force: true });
220
+ systemctl('daemon-reload');
221
+ log(`Removed ${WATCH_UNIT}.`);
222
+ return;
223
+ }
224
+ const unit = renderUnit({ interval, debounce });
225
+ if (opts.dryRun) { log(`[dry-run] would write ${path}:\n`); log(unit); return; }
226
+ mkdirSync(unitDir(), { recursive: true });
227
+ writeFileSync(path, unit);
228
+ for (const args of [['daemon-reload'], ['enable', '--now', WATCH_UNIT]]) {
229
+ const r = systemctl(...args);
230
+ if (!r.ok) throw new Error(`systemctl --user ${args.join(' ')} failed: ${r.error?.message || r.out}`);
231
+ }
232
+ log(`Wrote ${path} and started ${WATCH_UNIT} (every ${interval}s, debounce ${debounce}).`);
233
+ const s = settings();
234
+ if (!s.webhook && !s.ntfy) log('No alert channel set yet: add BURROW_ALERT_WEBHOOK or BURROW_ALERT_NTFY to the config.');
235
+ }
236
+
237
+ export async function watch(projectArgs = [], opts = {}) {
238
+ const interval = parseInt(opts.interval ?? '60', 10);
239
+ const debounce = parseInt(opts.debounce ?? '2', 10);
240
+ if (!(interval >= 1)) throw new Error(`Invalid --interval "${opts.interval}" (seconds, at least 1)`);
241
+ if (!(debounce >= 1)) throw new Error(`Invalid --debounce "${opts.debounce}" (at least 1)`);
242
+ if (opts.installService || opts.uninstallService) return serviceAction(opts, interval, debounce);
243
+ const s = settings();
244
+ if (!s.webhook && !s.ntfy && !opts.dryRun) log('No alert channel set (BURROW_ALERT_WEBHOOK or BURROW_ALERT_NTFY); changes are only printed.');
245
+ if (opts.once) { await tick(projectArgs, { debounce, dry: !!opts.dryRun, verbose: true }); return; }
246
+
247
+ log(`Watching ${projectArgs.length ? projectArgs.join(', ') : 'running projects'} every ${interval}s (debounce ${debounce}). Ctrl+C to stop.`);
248
+ let stop = false;
249
+ let wake = () => {};
250
+ const onSignal = () => { stop = true; wake(); };
251
+ process.on('SIGINT', onSignal);
252
+ process.on('SIGTERM', onSignal);
253
+ let first = true;
254
+ while (!stop) {
255
+ try { await tick(projectArgs, { debounce, dry: !!opts.dryRun, verbose: first }); } catch (e) { console.error(`burrow: watch: ${e.message}`); }
256
+ first = false;
257
+ if (stop) break;
258
+ await new Promise((resolve) => { const t = setTimeout(resolve, interval * 1000); wake = () => { clearTimeout(t); resolve(); }; });
259
+ }
260
+ process.off('SIGINT', onSignal);
261
+ process.off('SIGTERM', onSignal);
262
+ log('Stopped watching.');
263
+ }
package/src/zones.js ADDED
@@ -0,0 +1,102 @@
1
+ import { mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { stateDir } from './config.js';
4
+ import { Cloudflare } from './cloudflare.js';
5
+ import { readMeta } from './process.js';
6
+
7
+ // Per-project domains: `domain:` in tunnel.yml overrides BURROW_DOMAIN. Each domain is a
8
+ // Cloudflare zone; its ID is looked up once, checked to be on CF_ACCOUNT_ID, and cached.
9
+ export const zoneCacheFile = () => join(stateDir(), 'cache', 'zones.json');
10
+ const TTL = 7 * 24 * 3600 * 1000;
11
+
12
+ export const projectDomain = (proj, cfg) => proj?.domain || cfg.domain;
13
+ export const inZone = (cf, zoneId) => new Cloudflare({ token: cf.token, accountId: cf.accountId, zoneId });
14
+
15
+ export function readZoneCache() {
16
+ try { return JSON.parse(readFileSync(zoneCacheFile(), 'utf8')); } catch { return {}; }
17
+ }
18
+ function writeZoneCache(cache) {
19
+ mkdirSync(dirname(zoneCacheFile()), { recursive: true, mode: 0o700 });
20
+ writeFileSync(zoneCacheFile(), JSON.stringify(cache, null, 2) + '\n', { mode: 0o600 });
21
+ }
22
+
23
+ // CF_ZONE_ID only ever applies to BURROW_DOMAIN.
24
+ export async function zoneIdFor(cf, cfg, domain, { refresh = false } = {}) {
25
+ if (!domain) throw new Error('No domain: set BURROW_DOMAIN or "domain:" in tunnel.yml.');
26
+ if (domain === cfg.domain && cfg.zoneId) return cfg.zoneId;
27
+ const cache = readZoneCache();
28
+ const hit = cache[domain];
29
+ if (!refresh && hit?.id && hit.accountId === cfg.accountId && Date.now() - hit.checkedAt < TTL) return hit.id;
30
+ const zones = await cf.all('/zones', { name: domain, 'account.id': cfg.accountId });
31
+ const zone = zones.find((z) => z.name === domain && (!z.account?.id || z.account.id === cfg.accountId));
32
+ if (!zone) {
33
+ throw new Error(
34
+ `Zone ${domain} is not on Cloudflare account ${cfg.accountId}, or the token can't see it. ` +
35
+ 'Add the domain to that account and give the token Zone > DNS > Edit and Zone > Zone > Read for it.'
36
+ );
37
+ }
38
+ if (zone.status && zone.status !== 'active') console.error(`burrow: warning: zone ${domain} is ${zone.status}, not active yet.`);
39
+ cache[domain] = { id: zone.id, accountId: cfg.accountId, checkedAt: Date.now() };
40
+ writeZoneCache(cache);
41
+ return zone.id;
42
+ }
43
+
44
+ function metas() {
45
+ let names = [];
46
+ try { names = readdirSync(stateDir()).filter((f) => f.endsWith('.json')).map((f) => f.slice(0, -5)); } catch {}
47
+ return names.map((n) => readMeta(n)).filter(Boolean);
48
+ }
49
+
50
+ // Every zone burrow may have records in: BURROW_DOMAIN's, the cached ones, and the zones
51
+ // remembered for projects. [{ id, domain }], unique by id.
52
+ export async function knownZones(cf, cfg, { onError } = {}) {
53
+ const out = new Map();
54
+ if (cfg.domain) {
55
+ // With onError, a failing lookup of BURROW_DOMAIN's zone is reported (id null) instead of
56
+ // stopping the other zones from being read.
57
+ try { out.set(await zoneIdFor(cf, cfg, cfg.domain), cfg.domain); } catch (e) {
58
+ if (!onError) throw e;
59
+ onError({ id: null, domain: cfg.domain }, e);
60
+ }
61
+ }
62
+ for (const [domain, z] of Object.entries(readZoneCache())) {
63
+ if (z.id && z.accountId === cfg.accountId && !out.has(z.id)) out.set(z.id, domain);
64
+ }
65
+ for (const m of metas()) if (m.zoneId && !out.has(m.zoneId)) out.set(m.zoneId, m.domain || m.zoneId);
66
+ return [...out].map(([id, domain]) => ({ id, domain }));
67
+ }
68
+
69
+ // DNS records matching { comment } or { prefix } in every known zone, each with zoneId.
70
+ // Without onError, one unreadable zone throws; with onError(zone, err), it's skipped.
71
+ export async function recordsEverywhere(cf, cfg, { comment, prefix, onError }) {
72
+ const out = [];
73
+ for (const z of await knownZones(cf, cfg, { onError })) {
74
+ const zc = inZone(cf, z.id);
75
+ let recs;
76
+ try {
77
+ recs = comment ? await zc.recordsByComment(comment) : await zc.recordsByCommentPrefix(prefix);
78
+ } catch (e) {
79
+ if (!onError) throw e;
80
+ onError(z, e);
81
+ continue;
82
+ }
83
+ for (const r of recs) out.push({ ...r, zoneId: z.id, zoneName: z.domain });
84
+ }
85
+ return out;
86
+ }
87
+
88
+ // Zone read errors as [{ zone, zoneId, error }] (the shape `ls --json`, `status --json` and the
89
+ // dashboard report), and which of them hides a project's DNS records: the zone remembered
90
+ // for it by `burrow up` (zoneId / domain), else BURROW_DOMAIN's zone.
91
+ export const zoneErrorCollector = () => {
92
+ const list = [];
93
+ return { list, onError: (z, e) => list.push({ zone: z.domain, zoneId: z.id, error: e.message }) };
94
+ };
95
+ export function zoneErrorFor(project, zoneErrors, cfg) {
96
+ if (!zoneErrors?.length) return null;
97
+ const meta = readMeta(project);
98
+ const hit = meta?.zoneId
99
+ ? zoneErrors.find((z) => z.zoneId === meta.zoneId || (meta.domain && z.zone === meta.domain))
100
+ : zoneErrors.find((z) => z.zone === (meta?.domain || cfg.domain));
101
+ return hit ? { zone: hit.zone, error: hit.error } : null;
102
+ }