@theholocron/cli 5.0.0-alpha.581 → 5.0.0-alpha.582

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/dist/cli.mjs CHANGED
@@ -13826,13 +13826,40 @@ function expectedDnsRecords(config, sources) {
13826
13826
  });
13827
13827
  return expected;
13828
13828
  }
13829
+ // src/commands/doctor-dns/undeclared-dns-row.ts
13830
+ /** A record's name without its case or final dot. */
13831
+ const bare$1 = (name) => name.toLowerCase().replace(/\.$/, "");
13832
+ /**
13833
+ * The information row for the records a zone holds that nothing declares: not a record the config makes `setup`
13834
+ * write, one `.holocron/dns-records.json` lists, a deployment domain's, or one `doctor.manualDnsRecords` names
13835
+ * (`"<TYPE> <name>"` for one type, a bare name for every record of that name). It is a skip, so it never fails
13836
+ * the run, and there is no row when nothing is left over.
13837
+ *
13838
+ * @param zone - The zone the records were read from.
13839
+ * @param have - Every record the provider lists for the zone.
13840
+ * @param declared - Whether a record is one the config accounts for.
13841
+ * @param manual - `doctor.manualDnsRecords`.
13842
+ */
13843
+ function undeclaredDnsRow(zone, have, declared, manual) {
13844
+ const allowed = new Set(manual.map((entry) => entry.trim().toLowerCase().replace(/\.$/, "")));
13845
+ const left = have.filter((r) => !declared(r) && !allowed.has(bare$1(r.name)) && !allowed.has(`${r.type.toLowerCase()} ${bare$1(r.name)}`));
13846
+ if (left.length === 0) return [];
13847
+ return [{
13848
+ id: `dns-undeclared-${zone}`,
13849
+ title: `${zone} records nothing declares`,
13850
+ status: "skip",
13851
+ detail: `${left.length} not declared: ${left.map((r) => `${r.type} ${r.name}`).join(", ")}`,
13852
+ problems: []
13853
+ }];
13854
+ }
13829
13855
  // src/commands/doctor-dns/doctor-dns.ts
13830
13856
  /**
13831
13857
  * `holocron doctor dns` — do the DNS records the config makes setup write exist, pointing where they should?
13832
13858
  *
13833
13859
  * Read-only. One row per zone, each record looked up by type and name (case-insensitively) in what the `dns`
13834
13860
  * provider lists for the zone. A record that is missing, points elsewhere, or is not proxied where it must be is a
13835
- * problem; a record in the zone that is not expected never is. With no `dns` provider and records expected, the
13861
+ * problem; a record in the zone that is not expected never is, and is listed in an information row
13862
+ * (`dns-undeclared-<zone>`, a skip) unless `doctor.manualDnsRecords` names it. With no `dns` provider and records expected, the
13836
13863
  * rows are skips with the reason; a provider with no token for the read skips its zone.
13837
13864
  *
13838
13865
  * A custom domain on the `deployment` provider (Sentinel's `sentinel.theholocron.dev` on Vercel) gets a row of its
@@ -13915,8 +13942,25 @@ async function runDoctorDns(input) {
13915
13942
  for (const { hostname } of domains) rows.push(domainRow(hostname, "skip", why));
13916
13943
  } else {
13917
13944
  const dns = loader.get("dns");
13918
- for (const zone of zones) rows.push(await checkZone(dns, zone, expected.filter((e) => e.zone === zone).map((e) => e.record)));
13919
- for (const { project, hostname } of domains) rows.push(await checkDomain(dns, deploy, project, hostname));
13945
+ const manual = input.loaded.resolved.doctor?.manualDnsRecords ?? [];
13946
+ const domainChecks = [];
13947
+ for (const { project, hostname } of domains) domainChecks.push(await checkDomain(dns, deploy, project, hostname));
13948
+ const declared = /* @__PURE__ */ new Set([...expected.map((e) => keyOf(e.record)), ...domainChecks.flatMap((c) => c.wanted ? [keyOf(c.wanted)] : [])]);
13949
+ const listedLeftovers = /* @__PURE__ */ new Set();
13950
+ for (const zone of zones) {
13951
+ const wanted = expected.filter((e) => e.zone === zone).map((e) => e.record);
13952
+ for (const r of await checkZone(dns, zone, wanted, {
13953
+ declared,
13954
+ manual
13955
+ })) {
13956
+ if (r.id.startsWith("dns-undeclared-")) {
13957
+ if (listedLeftovers.has(r.detail)) continue;
13958
+ listedLeftovers.add(r.detail);
13959
+ }
13960
+ rows.push(r);
13961
+ }
13962
+ }
13963
+ rows.push(...domainChecks.map((c) => c.row));
13920
13964
  }
13921
13965
  printCheckRows(rows, print);
13922
13966
  const summary = summariseChecks(rows);
@@ -13955,14 +13999,18 @@ function domainRow(hostname, status, detail, problems = []) {
13955
13999
  async function checkDomain(dns, deploy, project, hostname) {
13956
14000
  try {
13957
14001
  const request = await deploy.expectedDomainRecord(project, hostname);
13958
- if (!request) return domainRow(hostname, "skip", `${deploy.providerName} recommends no record for it`);
13959
- return await checkZone(dns, request.zone, [request.record], domainRow.bind(void 0, hostname));
14002
+ if (!request) return { row: domainRow(hostname, "skip", `${deploy.providerName} recommends no record for it`) };
14003
+ const [row] = await checkZone(dns, request.zone, [request.record], void 0, domainRow.bind(void 0, hostname));
14004
+ return {
14005
+ row,
14006
+ wanted: request.record
14007
+ };
13960
14008
  } catch (err) {
13961
14009
  const noToken = missingTokenReason(err);
13962
- return noToken !== void 0 ? domainRow(hostname, "skip", noToken) : domainRow(hostname, "fail", errorMessage(err));
14010
+ return { row: noToken !== void 0 ? domainRow(hostname, "skip", noToken) : domainRow(hostname, "fail", errorMessage(err)) };
13963
14011
  }
13964
14012
  }
13965
- async function checkZone(dns, zone, wanted, rowOf = (...args) => row$29(zone, ...args)) {
14013
+ async function checkZone(dns, zone, wanted, undeclared, rowOf = (...args) => row$29(zone, ...args)) {
13966
14014
  try {
13967
14015
  const have = await dns.listRecords(zone);
13968
14016
  const problems = declaredVsActual(new Map(wanted.map((w) => [keyOf(w), w])), new Map(have.map((h) => [keyOf(h), h])), {
@@ -13971,10 +14019,10 @@ async function checkZone(dns, zone, wanted, rowOf = (...args) => row$29(zone, ..
13971
14019
  equal: (want, found) => sameContent(want.content, found.content) && (want.proxied === void 0 || found.proxied === true === want.proxied),
13972
14020
  show: (r) => `${r.content}${r.proxied ? " (proxied)" : ""}`
13973
14021
  });
13974
- return problems.length > 0 ? rowOf("fail", `${problems.length} problem(s)`, problems) : rowOf("ok", `${wanted.length} of ${wanted.length} exist`);
14022
+ return [problems.length > 0 ? rowOf("fail", `${problems.length} problem(s)`, problems) : rowOf("ok", `${wanted.length} of ${wanted.length} exist`), ...undeclared ? undeclaredDnsRow(zone, have, (r) => undeclared.declared.has(keyOf(r)), undeclared.manual) : []];
13975
14023
  } catch (err) {
13976
14024
  const noToken = missingTokenReason(err);
13977
- return noToken !== void 0 ? rowOf("skip", noToken) : rowOf("fail", errorMessage(err));
14025
+ return [noToken !== void 0 ? rowOf("skip", noToken) : rowOf("fail", errorMessage(err))];
13978
14026
  }
13979
14027
  }
13980
14028
  // src/commands/doctor-dns/doctor-dns.command.ts
@@ -19056,19 +19104,25 @@ function repoChecks(config, repoRoot, statusContexts) {
19056
19104
  checks.push(...viewChecks(repo?.views));
19057
19105
  if (repo?.teams && repo.teams.length > 0) {
19058
19106
  const teams = repo.teams;
19107
+ const manualTeams = config.doctor?.manualTeams ?? [];
19059
19108
  checks.push({
19060
19109
  id: "repo-teams",
19061
19110
  title: "team access matches",
19062
19111
  needs: "listTeamAccess",
19063
19112
  async run(source) {
19064
19113
  const found = await source.listTeamAccess();
19114
+ const problems = declaredVsActual(new Map(teams.map(teamPermission)), new Map(found.map((t) => [t.slug, t.permission])), {
19115
+ noun: "team",
19116
+ flagExtra: false,
19117
+ show: quote
19118
+ });
19119
+ const known = new Set([...teams.map((t) => teamPermission(t)[0]), ...manualTeams].map((s) => s.toLowerCase()));
19120
+ const undeclared = found.map((t) => t.slug).filter((slug) => !known.has(slug.toLowerCase()));
19121
+ const info = undeclared.length > 0 ? [`${undeclared.length} team(s) with access not in \`repo.teams\`: ${undeclared.join(", ")}`] : [];
19065
19122
  return {
19066
- problems: declaredVsActual(new Map(teams.map(teamPermission)), new Map(found.map((t) => [t.slug, t.permission])), {
19067
- noun: "team",
19068
- flagExtra: false,
19069
- show: quote
19070
- }),
19071
- checked: teams.length
19123
+ problems,
19124
+ checked: teams.length,
19125
+ info
19072
19126
  };
19073
19127
  }
19074
19128
  });