@theholocron/cli 5.0.0-alpha.273 โ 5.0.0-alpha.274
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 +2 -1
- package/dist/cli.mjs +263 -91
- package/dist/cli.mjs.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -550,6 +550,7 @@ commands and the config are provider-neutral; Discord is the first provider.
|
|
|
550
550
|
| `holocron doctor notifications [--built-only] [--deliver]` | Step by step: does the server match the layout, do the secrets exist, and does a person (not the bot) own it. A full run also leaves one `๐งช test:` post in the layout's `testChannel`; `--built-only` posts nothing; `--deliver` posts to every channel and removes each post |
|
|
551
551
|
| `holocron doctor variables` | Do the Actions variables `repo.variables` declares exist, with those values (and, for the organization's, that visibility)? One row for the repository and one for the organization, each only when declared. Read-only. An undeclared variable counts only with `prune`; a scope that cannot be read (no provider, no org token) is a skip, not a failure |
|
|
552
552
|
| `holocron doctor environments` | Do the deployment environments exist? The ones `repo setup` creates (`staging`, `production`, when an `environments` provider is configured) plus every environment `repo.secrets.environments` names. One row. A missing one fails; an extra one is never a problem; no provider with some named is a skip |
|
|
553
|
+
| `holocron doctor dns` | Do the DNS records the config makes setup write exist, pointing where they should? The preview domain's apex and wildcard CNAMEs (Cloudflare), the docs host a wiki provider asks for, and the relay Worker's proxied placeholder; one row per zone. A missing record, another target or a missing proxy fails; an extra record never does. A record `ensureCustomDomain()` returns is not checked, because asking for it creates the domain |
|
|
553
554
|
| `holocron doctor monitoring` | Do the checks the `monitoring` provider declares exist in its account, matched by name, with the URL, method and (when stated) frequency, locations, activated, should-fail, body and assertions the config sets? One row. A check in the account that is not declared is never a problem. A provider that cannot list its checks, failed to load or has no token is a skip |
|
|
554
555
|
| `holocron doctor secrets` | Do the secrets the config says must exist (`repo.secrets`, plus the notification layout's webhook and role secrets and the Chromatic token) exist? One row for the repository, the organization and each environment, each only when something is expected there. Names only; an undeclared secret is never a problem. A scope that cannot be read is a skip |
|
|
555
556
|
| `holocron doctor tokens` | For every token a configured plugin lists (every plugin that resolves one: GitHub's nine, Discord's three, Sentry's two, ...), looked up as the plugin does (its env var, the vendor's, then keyring) and verified with its `verifyToken`: set and accepted is ok (with how long is left, when the token expires), set and rejected fails, a token with 7 days or fewer left fails with `expires in N days: renew it`, not set is a skip. No token is printed. What a token may do is not checked, because GitHub does not return a fine-grained token's permissions |
|
|
@@ -775,7 +776,7 @@ the local override exists to exempt.
|
|
|
775
776
|
`package bump-versions`, `sync github`, `repo upgrade node`,
|
|
776
777
|
`repo upgrade deps`, `new plugin`, `auth`, `notifications setup`,
|
|
777
778
|
`notifications channel add`, `notifications link`,
|
|
778
|
-
`notifications sync-roles`, `doctor environments`, `doctor monitoring`, `doctor notifications`, `doctor secrets`, `doctor tokens`, `doctor variables`
|
|
779
|
+
`notifications sync-roles`, `doctor dns`, `doctor environments`, `doctor monitoring`, `doctor notifications`, `doctor secrets`, `doctor tokens`, `doctor variables`
|
|
779
780
|
- `src/commands/doctor-checks/` and `src/commands/deep-checks/` โ the shared row
|
|
780
781
|
renderer and `declaredVsActual` helper, and `DEEP_CHECKS`, the registry every
|
|
781
782
|
`doctor <capability>` is listed in
|
package/dist/cli.mjs
CHANGED
|
@@ -221,6 +221,7 @@ const COMMAND_CONTEXTS = {
|
|
|
221
221
|
"doctor all": "workspace",
|
|
222
222
|
"doctor notifications": "workspace",
|
|
223
223
|
"doctor environments": "workspace",
|
|
224
|
+
"doctor dns": "workspace",
|
|
224
225
|
"doctor secrets": "workspace",
|
|
225
226
|
"doctor tokens": "workspace",
|
|
226
227
|
"doctor monitoring": "workspace",
|
|
@@ -1423,6 +1424,13 @@ const doctorAllEntry = {
|
|
|
1423
1424
|
supportsDryRun: false,
|
|
1424
1425
|
spawnArgs: ["doctor", "--all"]
|
|
1425
1426
|
};
|
|
1427
|
+
// src/commands/doctor-dns/doctor-dns.entry.ts
|
|
1428
|
+
const doctorDnsEntry = {
|
|
1429
|
+
name: "doctor dns",
|
|
1430
|
+
description: "Check that the DNS records the config makes setup write exist and point where they should (read-only)",
|
|
1431
|
+
positionals: [],
|
|
1432
|
+
supportsDryRun: false
|
|
1433
|
+
};
|
|
1426
1434
|
// src/commands/doctor-environments/doctor-environments.entry.ts
|
|
1427
1435
|
const doctorEnvironmentsEntry = {
|
|
1428
1436
|
name: "doctor environments",
|
|
@@ -1678,6 +1686,7 @@ const COMMAND_REGISTRY = [
|
|
|
1678
1686
|
doctorMonitoringEntry,
|
|
1679
1687
|
doctorNotificationsEntry,
|
|
1680
1688
|
doctorEnvironmentsEntry,
|
|
1689
|
+
doctorDnsEntry,
|
|
1681
1690
|
doctorSecretsEntry,
|
|
1682
1691
|
doctorTokensEntry,
|
|
1683
1692
|
doctorVariablesEntry,
|
|
@@ -4437,6 +4446,246 @@ function layoutSecretNames(layout) {
|
|
|
4437
4446
|
const fromRoles = (layout.roles ?? []).flatMap((role) => role.secret ? [role.secret] : []);
|
|
4438
4447
|
return [...fromChannels, ...fromRoles];
|
|
4439
4448
|
}
|
|
4449
|
+
// src/commands/notifications-setup/avatar-problem.ts
|
|
4450
|
+
/** The first reason a feed's `avatar` cannot work, or undefined. `feed` names the key for the message (`monitoring`, `errors`). */
|
|
4451
|
+
function avatarProblem(channel, feed, picture) {
|
|
4452
|
+
if (typeof picture !== "object") return void 0;
|
|
4453
|
+
if (!picture.url && !picture.image) return `channel \`${channel}\`: \`feeds.${feed}.avatar\` needs a \`url\`, an \`image\`, or both`;
|
|
4454
|
+
if (picture.url && !/^https:\/\//i.test(picture.url)) return `channel \`${channel}\`: \`feeds.${feed}.avatar.url\` must be an https:// URL`;
|
|
4455
|
+
if (picture.image && /^https?:\/\//i.test(picture.image)) return `channel \`${channel}\`: \`feeds.${feed}.avatar.image\` must be a file in the repo, not a URL`;
|
|
4456
|
+
}
|
|
4457
|
+
/** The webhook name a channel's error feed uses: its own, else the provider's name, capitalised (`Sentry`). */
|
|
4458
|
+
function errorsFeedWebhook(feed, errors) {
|
|
4459
|
+
return (typeof feed === "object" ? feed.webhook : void 0) ?? capitalised(errors.providerName);
|
|
4460
|
+
}
|
|
4461
|
+
const capitalised = (name) => name.charAt(0).toUpperCase() + name.slice(1);
|
|
4462
|
+
/** The Worker binding that holds the webhook URL for a source (the contract `apps/comlink` reads). */
|
|
4463
|
+
const relayWebhookBinding = (source) => `COMLINK_${source.toUpperCase()}_WEBHOOK`;
|
|
4464
|
+
/** The Worker binding that holds a source's signing secret (the contract `apps/comlink` reads). */
|
|
4465
|
+
const relaySecretBinding = (source) => `COMLINK_${source.toUpperCase()}_SECRET`;
|
|
4466
|
+
/** Whether any channel in the layout is fed by the error tracker. */
|
|
4467
|
+
function wantsRelay(layout) {
|
|
4468
|
+
return (layout.categories ?? []).some((c) => (c.channels ?? []).some((ch) => ch.feeds?.errors));
|
|
4469
|
+
}
|
|
4470
|
+
/**
|
|
4471
|
+
* The first reason the relay cannot be deployed, or undefined. One source has one webhook, so only one channel can be
|
|
4472
|
+
* fed by it; and the Worker needs somewhere to answer.
|
|
4473
|
+
*/
|
|
4474
|
+
function relayProblem(layout, errors, monitoring) {
|
|
4475
|
+
const fed = (layout.categories ?? []).flatMap((c) => c.channels ?? []).filter((ch) => ch.feeds?.errors);
|
|
4476
|
+
if (fed.length === 0) return void 0;
|
|
4477
|
+
if (!layout.relay?.host) return `channel \`${fed[0].name}\` is fed by the error tracker, which needs \`relay.host\` โ where the relay Worker answers`;
|
|
4478
|
+
if (fed.length > 1) return `channels ${fed.map((c) => `\`${c.name}\``).join(" and ")} are all fed by the error tracker, but its relay posts to one channel โ feed one`;
|
|
4479
|
+
const channel = fed[0];
|
|
4480
|
+
const errorsFeed = channel.feeds.errors;
|
|
4481
|
+
const picture = typeof errorsFeed === "object" ? errorsFeed.avatar : void 0;
|
|
4482
|
+
const pictureProblem = avatarProblem(channel.name, "errors", picture);
|
|
4483
|
+
if (pictureProblem) return pictureProblem;
|
|
4484
|
+
if (errors) {
|
|
4485
|
+
const feed = errorsFeedWebhook(errorsFeed, errors).toLowerCase();
|
|
4486
|
+
const own = (typeof channel.webhook === "object" ? channel.webhook.name : void 0) ?? channel.name;
|
|
4487
|
+
if (channel.webhook && feed === own.toLowerCase()) return `channel \`${channel.name}\`: the relay webhook and the channel's own webhook are both named ${own} โ rename one`;
|
|
4488
|
+
const monitoringFeed = channel.feeds.monitoring;
|
|
4489
|
+
if (monitoring && monitoringFeed) {
|
|
4490
|
+
const other = (typeof monitoringFeed === "object" ? monitoringFeed.webhook : void 0) ?? capitalised(monitoring.providerName);
|
|
4491
|
+
if (feed === other.toLowerCase()) return `channel \`${channel.name}\`: the relay webhook and the monitoring webhook are both named ${other} โ rename one`;
|
|
4492
|
+
}
|
|
4493
|
+
}
|
|
4494
|
+
}
|
|
4495
|
+
/**
|
|
4496
|
+
* What to hand the `dns` capability as the zone: the layout's, else the host itself. The provider looks a name up from
|
|
4497
|
+
* the full name towards the apex until it finds a zone it holds, so this is right for any suffix (`example.co.uk`).
|
|
4498
|
+
*/
|
|
4499
|
+
const relayZone = (relay) => relay.zone ?? relay.host;
|
|
4500
|
+
/**
|
|
4501
|
+
* Deploy the Worker with its webhook secret and its route, then point the host at it with a proxied placeholder record
|
|
4502
|
+
* (the Worker answers before any origin is asked). The built file is read first and the DNS record comes last, so a
|
|
4503
|
+
* missing build or a failed deploy leaves the host untouched.
|
|
4504
|
+
*/
|
|
4505
|
+
async function deployRelay(input) {
|
|
4506
|
+
const { relay, workers, dns } = input;
|
|
4507
|
+
const path = join(input.repoRoot, relay.code ?? "apps/comlink/dist/worker.js");
|
|
4508
|
+
let code;
|
|
4509
|
+
try {
|
|
4510
|
+
code = await (input.readCode ?? ((p) => readFile(p, "utf8")))(path);
|
|
4511
|
+
} catch {
|
|
4512
|
+
throw new Error(`the relay Worker is not built (${relay.code ?? "apps/comlink/dist/worker.js"}) โ run \`pnpm --filter @theholocron/comlink run delivery.build\``);
|
|
4513
|
+
}
|
|
4514
|
+
const script = relay.script ?? "comlink";
|
|
4515
|
+
await workers.deployScript(script, {
|
|
4516
|
+
code,
|
|
4517
|
+
secrets: {
|
|
4518
|
+
[relayWebhookBinding(input.source)]: input.webhook,
|
|
4519
|
+
...input.signingSecret ? { [relaySecretBinding(input.source)]: input.signingSecret } : {}
|
|
4520
|
+
},
|
|
4521
|
+
routes: [`${relay.host}/*`]
|
|
4522
|
+
});
|
|
4523
|
+
await dns.upsertRecord(relayZone(relay), {
|
|
4524
|
+
type: "AAAA",
|
|
4525
|
+
name: relay.host,
|
|
4526
|
+
content: "100::",
|
|
4527
|
+
ttl: 1,
|
|
4528
|
+
proxied: true
|
|
4529
|
+
});
|
|
4530
|
+
return {
|
|
4531
|
+
host: relay.host,
|
|
4532
|
+
script
|
|
4533
|
+
};
|
|
4534
|
+
}
|
|
4535
|
+
// src/commands/setup/preview-config-of.ts
|
|
4536
|
+
/**
|
|
4537
|
+
* The preview configuration (the Pages project and the preview domain) that drives project and DNS provisioning.
|
|
4538
|
+
* `delivery.deploy`, `knowledge.docs` and `knowledge.components` all share the same combined production and preview
|
|
4539
|
+
* mechanism, so any one of them can carry it. `null` when none does.
|
|
4540
|
+
*/
|
|
4541
|
+
function previewConfigOf(config) {
|
|
4542
|
+
const entry = (config.tasks ?? []).map((e) => typeof e === "string" ? { name: e } : e).find((e) => e.name === "delivery.deploy" || e.name === "knowledge.docs" || e.name === "knowledge.components");
|
|
4543
|
+
return entry?.with ? extractPreviewConfig(entry.with, {
|
|
4544
|
+
org: config.org,
|
|
4545
|
+
domain: config.domain
|
|
4546
|
+
}) : null;
|
|
4547
|
+
}
|
|
4548
|
+
// src/commands/doctor-dns/expected-dns-records.ts
|
|
4549
|
+
/**
|
|
4550
|
+
* The DNS records the config makes `holocron repo setup` and `notifications setup` write, as far as they can be
|
|
4551
|
+
* known without writing anything: the preview domain's apex and wildcard CNAMEs (on a Cloudflare deployment), the
|
|
4552
|
+
* docs host a wiki provider asks for, and the relay Worker's proxied placeholder. A record that
|
|
4553
|
+
* `Deployment.ensureCustomDomain()` returns is left out, since asking for it creates the domain.
|
|
4554
|
+
*/
|
|
4555
|
+
function expectedDnsRecords(config, sources) {
|
|
4556
|
+
const expected = [];
|
|
4557
|
+
const preview = previewConfigOf(config);
|
|
4558
|
+
if (preview?.domain && sources.deployment?.providerName === "cloudflare") {
|
|
4559
|
+
const content = `${preview.project}.pages.dev`;
|
|
4560
|
+
for (const name of [preview.domain, `*.${preview.domain}`]) expected.push({
|
|
4561
|
+
zone: preview.domain,
|
|
4562
|
+
record: {
|
|
4563
|
+
type: "CNAME",
|
|
4564
|
+
name,
|
|
4565
|
+
content
|
|
4566
|
+
}
|
|
4567
|
+
});
|
|
4568
|
+
}
|
|
4569
|
+
const docs = sources.wiki?.dnsRecord?.();
|
|
4570
|
+
if (docs) {
|
|
4571
|
+
const { type, name, content } = docs.record;
|
|
4572
|
+
expected.push({
|
|
4573
|
+
zone: docs.zone,
|
|
4574
|
+
record: {
|
|
4575
|
+
type,
|
|
4576
|
+
name,
|
|
4577
|
+
content,
|
|
4578
|
+
...sources.wiki?.proxyConfig?.() ? { proxied: true } : {}
|
|
4579
|
+
}
|
|
4580
|
+
});
|
|
4581
|
+
}
|
|
4582
|
+
for (const { relay } of sources.layouts) if (relay) expected.push({
|
|
4583
|
+
zone: relayZone(relay),
|
|
4584
|
+
record: {
|
|
4585
|
+
type: "AAAA",
|
|
4586
|
+
name: relay.host,
|
|
4587
|
+
content: "100::",
|
|
4588
|
+
proxied: true
|
|
4589
|
+
}
|
|
4590
|
+
});
|
|
4591
|
+
return expected;
|
|
4592
|
+
}
|
|
4593
|
+
// src/commands/doctor-dns/doctor-dns.ts
|
|
4594
|
+
/**
|
|
4595
|
+
* `holocron doctor dns` โ do the DNS records the config makes setup write exist, pointing where they should?
|
|
4596
|
+
*
|
|
4597
|
+
* Read-only. One row per zone, each record looked up by type and name (case-insensitively) in what the `dns`
|
|
4598
|
+
* provider lists for the zone. A record that is missing, points elsewhere, or is not proxied where it must be is a
|
|
4599
|
+
* problem; a record in the zone that is not expected never is. With no `dns` provider and records expected, the
|
|
4600
|
+
* rows are skips with the reason; a provider with no token for the read skips its zone.
|
|
4601
|
+
*/
|
|
4602
|
+
/** `CNAME *.example.com`: a record is its type and its name, however the provider spells the case or the final dot. */
|
|
4603
|
+
const keyOf = (record) => `${record.type} ${record.name.toLowerCase().replace(/\.$/, "")}`;
|
|
4604
|
+
const sameContent = (a, b) => a.toLowerCase().replace(/\.$/, "") === b.toLowerCase().replace(/\.$/, "");
|
|
4605
|
+
async function runDoctorDns(input) {
|
|
4606
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
4607
|
+
const logger = input.logger ?? getLogger();
|
|
4608
|
+
const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
|
|
4609
|
+
await loader.load();
|
|
4610
|
+
assertPluginsResolvable(loader, "doctor dns");
|
|
4611
|
+
const expected = expectedDnsRecords(input.loaded.resolved, {
|
|
4612
|
+
...loader.has("deployment") ? { deployment: loader.get("deployment") } : {},
|
|
4613
|
+
...loader.has("wiki") ? { wiki: loader.get("wiki") } : {},
|
|
4614
|
+
layouts: (loader.has("notifications") ? loader.get("notifications") : []).flatMap((p) => p.layout ? [p.layout] : [])
|
|
4615
|
+
});
|
|
4616
|
+
const zones = [...new Set(expected.map((e) => e.zone))];
|
|
4617
|
+
const rows = [];
|
|
4618
|
+
if (zones.length === 0) rows.push({
|
|
4619
|
+
id: "dns",
|
|
4620
|
+
title: "dns",
|
|
4621
|
+
status: "ok",
|
|
4622
|
+
detail: "none declared",
|
|
4623
|
+
problems: []
|
|
4624
|
+
});
|
|
4625
|
+
else if (!loader.has("dns")) {
|
|
4626
|
+
const why = whyMissing(loader, "dns", "no `dns` provider to check them with");
|
|
4627
|
+
for (const zone of zones) rows.push(row$2(zone, "skip", why));
|
|
4628
|
+
} else {
|
|
4629
|
+
const dns = loader.get("dns");
|
|
4630
|
+
for (const zone of zones) rows.push(await checkZone(dns, zone, expected.filter((e) => e.zone === zone).map((e) => e.record)));
|
|
4631
|
+
}
|
|
4632
|
+
printCheckRows(rows, print);
|
|
4633
|
+
const summary = summariseChecks(rows);
|
|
4634
|
+
printCheckSummary(summary, print);
|
|
4635
|
+
const status = summary.fail > 0 ? "fail" : summary.ok === 0 ? "skip" : "ok";
|
|
4636
|
+
logger.info({
|
|
4637
|
+
...summary,
|
|
4638
|
+
status
|
|
4639
|
+
}, "doctor dns");
|
|
4640
|
+
return {
|
|
4641
|
+
status,
|
|
4642
|
+
rows,
|
|
4643
|
+
summary,
|
|
4644
|
+
...status === "skip" ? { reason: [...new Set(rows.map((r) => r.detail))].join("; ") } : {}
|
|
4645
|
+
};
|
|
4646
|
+
}
|
|
4647
|
+
function row$2(zone, status, detail, problems = []) {
|
|
4648
|
+
return {
|
|
4649
|
+
id: `dns-${zone}`,
|
|
4650
|
+
title: `${zone} records exist`,
|
|
4651
|
+
status,
|
|
4652
|
+
detail,
|
|
4653
|
+
problems
|
|
4654
|
+
};
|
|
4655
|
+
}
|
|
4656
|
+
async function checkZone(dns, zone, wanted) {
|
|
4657
|
+
try {
|
|
4658
|
+
const have = await dns.listRecords(zone);
|
|
4659
|
+
const problems = declaredVsActual(new Map(wanted.map((w) => [keyOf(w), w])), new Map(have.map((h) => [keyOf(h), h])), {
|
|
4660
|
+
noun: "record",
|
|
4661
|
+
flagExtra: false,
|
|
4662
|
+
equal: (want, found) => sameContent(want.content, found.content) && (want.proxied !== true || found.proxied === true),
|
|
4663
|
+
show: (r) => `${r.content}${r.proxied ? " (proxied)" : ""}`
|
|
4664
|
+
});
|
|
4665
|
+
return problems.length > 0 ? row$2(zone, "fail", `${problems.length} problem(s)`, problems) : row$2(zone, "ok", `${wanted.length} of ${wanted.length} exist`);
|
|
4666
|
+
} catch (err) {
|
|
4667
|
+
return err instanceof MissingTokenError ? row$2(zone, "skip", err.message) : row$2(zone, "fail", errorMessage(err));
|
|
4668
|
+
}
|
|
4669
|
+
}
|
|
4670
|
+
// src/commands/doctor-dns/doctor-dns.command.ts
|
|
4671
|
+
const doctorDnsCommand = {
|
|
4672
|
+
command: "dns",
|
|
4673
|
+
describe: "Check that the DNS records the config makes setup write exist and point where they should (read-only)",
|
|
4674
|
+
handler: async (argv) => {
|
|
4675
|
+
const tokens = tokenContext(argv.token);
|
|
4676
|
+
if (!tokens) return;
|
|
4677
|
+
const loaded = await loadConfig(argv.cwd);
|
|
4678
|
+
applyResolvedConfig(argv, loaded.resolved);
|
|
4679
|
+
if ((await runDoctorDns({
|
|
4680
|
+
loaded,
|
|
4681
|
+
context: {
|
|
4682
|
+
repoRoot: argv.cwd,
|
|
4683
|
+
...tokens,
|
|
4684
|
+
org: resolveOrg(argv, loaded.resolved)
|
|
4685
|
+
}
|
|
4686
|
+
})).status === "fail") process.exitCode = 1;
|
|
4687
|
+
}
|
|
4688
|
+
};
|
|
4440
4689
|
// src/commands/setup/setup-environments.ts
|
|
4441
4690
|
/** The deployment environments `holocron repo setup` creates when an `environments` provider is configured. */
|
|
4442
4691
|
const SETUP_ENVIRONMENTS = ["staging", "production"];
|
|
@@ -6384,6 +6633,19 @@ const DEEP_CHECKS = [
|
|
|
6384
6633
|
};
|
|
6385
6634
|
}
|
|
6386
6635
|
},
|
|
6636
|
+
{
|
|
6637
|
+
name: "dns",
|
|
6638
|
+
capability: "dns",
|
|
6639
|
+
command: doctorDnsCommand,
|
|
6640
|
+
async run(input) {
|
|
6641
|
+
const report = await runDoctorDns(input);
|
|
6642
|
+
return {
|
|
6643
|
+
status: report.status,
|
|
6644
|
+
summary: report.summary,
|
|
6645
|
+
...report.reason ? { reason: report.reason } : {}
|
|
6646
|
+
};
|
|
6647
|
+
}
|
|
6648
|
+
},
|
|
6387
6649
|
{
|
|
6388
6650
|
name: "secrets",
|
|
6389
6651
|
capability: "secrets",
|
|
@@ -8987,92 +9249,6 @@ async function lockConfig(filepath) {
|
|
|
8987
9249
|
release: () => unlink(path).catch(() => void 0)
|
|
8988
9250
|
};
|
|
8989
9251
|
}
|
|
8990
|
-
// src/commands/notifications-setup/avatar-problem.ts
|
|
8991
|
-
/** The first reason a feed's `avatar` cannot work, or undefined. `feed` names the key for the message (`monitoring`, `errors`). */
|
|
8992
|
-
function avatarProblem(channel, feed, picture) {
|
|
8993
|
-
if (typeof picture !== "object") return void 0;
|
|
8994
|
-
if (!picture.url && !picture.image) return `channel \`${channel}\`: \`feeds.${feed}.avatar\` needs a \`url\`, an \`image\`, or both`;
|
|
8995
|
-
if (picture.url && !/^https:\/\//i.test(picture.url)) return `channel \`${channel}\`: \`feeds.${feed}.avatar.url\` must be an https:// URL`;
|
|
8996
|
-
if (picture.image && /^https?:\/\//i.test(picture.image)) return `channel \`${channel}\`: \`feeds.${feed}.avatar.image\` must be a file in the repo, not a URL`;
|
|
8997
|
-
}
|
|
8998
|
-
/** The webhook name a channel's error feed uses: its own, else the provider's name, capitalised (`Sentry`). */
|
|
8999
|
-
function errorsFeedWebhook(feed, errors) {
|
|
9000
|
-
return (typeof feed === "object" ? feed.webhook : void 0) ?? capitalised(errors.providerName);
|
|
9001
|
-
}
|
|
9002
|
-
const capitalised = (name) => name.charAt(0).toUpperCase() + name.slice(1);
|
|
9003
|
-
/** The Worker binding that holds the webhook URL for a source (the contract `apps/comlink` reads). */
|
|
9004
|
-
const relayWebhookBinding = (source) => `COMLINK_${source.toUpperCase()}_WEBHOOK`;
|
|
9005
|
-
/** The Worker binding that holds a source's signing secret (the contract `apps/comlink` reads). */
|
|
9006
|
-
const relaySecretBinding = (source) => `COMLINK_${source.toUpperCase()}_SECRET`;
|
|
9007
|
-
/** Whether any channel in the layout is fed by the error tracker. */
|
|
9008
|
-
function wantsRelay(layout) {
|
|
9009
|
-
return (layout.categories ?? []).some((c) => (c.channels ?? []).some((ch) => ch.feeds?.errors));
|
|
9010
|
-
}
|
|
9011
|
-
/**
|
|
9012
|
-
* The first reason the relay cannot be deployed, or undefined. One source has one webhook, so only one channel can be
|
|
9013
|
-
* fed by it; and the Worker needs somewhere to answer.
|
|
9014
|
-
*/
|
|
9015
|
-
function relayProblem(layout, errors, monitoring) {
|
|
9016
|
-
const fed = (layout.categories ?? []).flatMap((c) => c.channels ?? []).filter((ch) => ch.feeds?.errors);
|
|
9017
|
-
if (fed.length === 0) return void 0;
|
|
9018
|
-
if (!layout.relay?.host) return `channel \`${fed[0].name}\` is fed by the error tracker, which needs \`relay.host\` โ where the relay Worker answers`;
|
|
9019
|
-
if (fed.length > 1) return `channels ${fed.map((c) => `\`${c.name}\``).join(" and ")} are all fed by the error tracker, but its relay posts to one channel โ feed one`;
|
|
9020
|
-
const channel = fed[0];
|
|
9021
|
-
const errorsFeed = channel.feeds.errors;
|
|
9022
|
-
const picture = typeof errorsFeed === "object" ? errorsFeed.avatar : void 0;
|
|
9023
|
-
const pictureProblem = avatarProblem(channel.name, "errors", picture);
|
|
9024
|
-
if (pictureProblem) return pictureProblem;
|
|
9025
|
-
if (errors) {
|
|
9026
|
-
const feed = errorsFeedWebhook(errorsFeed, errors).toLowerCase();
|
|
9027
|
-
const own = (typeof channel.webhook === "object" ? channel.webhook.name : void 0) ?? channel.name;
|
|
9028
|
-
if (channel.webhook && feed === own.toLowerCase()) return `channel \`${channel.name}\`: the relay webhook and the channel's own webhook are both named ${own} โ rename one`;
|
|
9029
|
-
const monitoringFeed = channel.feeds.monitoring;
|
|
9030
|
-
if (monitoring && monitoringFeed) {
|
|
9031
|
-
const other = (typeof monitoringFeed === "object" ? monitoringFeed.webhook : void 0) ?? capitalised(monitoring.providerName);
|
|
9032
|
-
if (feed === other.toLowerCase()) return `channel \`${channel.name}\`: the relay webhook and the monitoring webhook are both named ${other} โ rename one`;
|
|
9033
|
-
}
|
|
9034
|
-
}
|
|
9035
|
-
}
|
|
9036
|
-
/**
|
|
9037
|
-
* What to hand the `dns` capability as the zone: the layout's, else the host itself. The provider looks a name up from
|
|
9038
|
-
* the full name towards the apex until it finds a zone it holds, so this is right for any suffix (`example.co.uk`).
|
|
9039
|
-
*/
|
|
9040
|
-
const relayZone = (relay) => relay.zone ?? relay.host;
|
|
9041
|
-
/**
|
|
9042
|
-
* Deploy the Worker with its webhook secret and its route, then point the host at it with a proxied placeholder record
|
|
9043
|
-
* (the Worker answers before any origin is asked). The built file is read first and the DNS record comes last, so a
|
|
9044
|
-
* missing build or a failed deploy leaves the host untouched.
|
|
9045
|
-
*/
|
|
9046
|
-
async function deployRelay(input) {
|
|
9047
|
-
const { relay, workers, dns } = input;
|
|
9048
|
-
const path = join(input.repoRoot, relay.code ?? "apps/comlink/dist/worker.js");
|
|
9049
|
-
let code;
|
|
9050
|
-
try {
|
|
9051
|
-
code = await (input.readCode ?? ((p) => readFile(p, "utf8")))(path);
|
|
9052
|
-
} catch {
|
|
9053
|
-
throw new Error(`the relay Worker is not built (${relay.code ?? "apps/comlink/dist/worker.js"}) โ run \`pnpm --filter @theholocron/comlink run delivery.build\``);
|
|
9054
|
-
}
|
|
9055
|
-
const script = relay.script ?? "comlink";
|
|
9056
|
-
await workers.deployScript(script, {
|
|
9057
|
-
code,
|
|
9058
|
-
secrets: {
|
|
9059
|
-
[relayWebhookBinding(input.source)]: input.webhook,
|
|
9060
|
-
...input.signingSecret ? { [relaySecretBinding(input.source)]: input.signingSecret } : {}
|
|
9061
|
-
},
|
|
9062
|
-
routes: [`${relay.host}/*`]
|
|
9063
|
-
});
|
|
9064
|
-
await dns.upsertRecord(relayZone(relay), {
|
|
9065
|
-
type: "AAAA",
|
|
9066
|
-
name: relay.host,
|
|
9067
|
-
content: "100::",
|
|
9068
|
-
ttl: 1,
|
|
9069
|
-
proxied: true
|
|
9070
|
-
});
|
|
9071
|
-
return {
|
|
9072
|
-
host: relay.host,
|
|
9073
|
-
script
|
|
9074
|
-
};
|
|
9075
|
-
}
|
|
9076
9252
|
// src/commands/notifications-setup/with-elevation.ts
|
|
9077
9253
|
/**
|
|
9078
9254
|
* Runs an edit that may need a permission the bot should not keep. When the provider says it does
|
|
@@ -13927,11 +14103,7 @@ async function runSetup(input) {
|
|
|
13927
14103
|
if (loader.has("deployment")) {
|
|
13928
14104
|
const deploy = loader.get("deployment");
|
|
13929
14105
|
print(style.step("deployment"));
|
|
13930
|
-
const
|
|
13931
|
-
const previewCfg = deployEntry?.with ? extractPreviewConfig(deployEntry.with, {
|
|
13932
|
-
org: config.org,
|
|
13933
|
-
domain: config.domain
|
|
13934
|
-
}) : null;
|
|
14106
|
+
const previewCfg = previewConfigOf(config);
|
|
13935
14107
|
const ensureCustomDomain = async (projectId, hostname) => {
|
|
13936
14108
|
if (!deploy.ensureCustomDomain) return;
|
|
13937
14109
|
const customDomainDns = { value: null };
|