@theholocron/cli 5.0.0-alpha.580 → 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
@@ -14052,20 +14100,24 @@ function environmentProblems(declared, have) {
14052
14100
  *
14053
14101
  * Read-only. The environments that must exist are the ones `setup` creates (when an `environments`
14054
14102
  * provider is configured) and every environment `repo.secrets.environments` names, since a secret can only be
14055
- * set on one that exists. An environment that exists but is not expected is never a problem. With no provider and
14103
+ * set on one that exists. An environment that exists but is not expected is never a problem; it is listed as an
14104
+ * information row (`environments-undeclared`) unless `doctor.manualEnvironments` names it. With no provider and
14056
14105
  * nothing named, nothing is declared; with no provider but some named, the row is a skip with the reason.
14057
14106
  */
14058
14107
  const ID$6 = "environments";
14059
14108
  const TITLE$6 = "environments exist";
14109
+ const UNDECLARED_ID = "environments-undeclared";
14110
+ const UNDECLARED_TITLE = "environments nothing declares";
14060
14111
  async function runDoctorEnvironments(input) {
14061
14112
  const print = input.print ?? ((line) => console.log(line));
14062
14113
  const logger = input.logger ?? getLogger();
14063
14114
  const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
14064
14115
  await loader.load();
14065
14116
  assertPluginsResolvable(loader, "doctor environments");
14066
- const row = await checkEnvironments(loader, Object.keys(input.loaded.resolved.repo?.secrets?.environments ?? {}), input.loaded.resolved.repo?.environments ?? []);
14067
- printCheckRows([row], print);
14068
- const summary = summariseChecks([row]);
14117
+ const rows = await checkEnvironments(loader, Object.keys(input.loaded.resolved.repo?.secrets?.environments ?? {}), input.loaded.resolved.repo?.environments ?? [], input.loaded.resolved.doctor?.manualEnvironments ?? []);
14118
+ const row = rows[0];
14119
+ printCheckRows(rows, print);
14120
+ const summary = summariseChecks(rows);
14069
14121
  printCheckSummary(summary, print);
14070
14122
  logger.info({
14071
14123
  ...summary,
@@ -14073,12 +14125,12 @@ async function runDoctorEnvironments(input) {
14073
14125
  }, "doctor environments");
14074
14126
  return {
14075
14127
  status: row.status,
14076
- rows: [row],
14128
+ rows,
14077
14129
  summary,
14078
14130
  ...row.status === "skip" ? { reason: row.detail } : {}
14079
14131
  };
14080
14132
  }
14081
- async function checkEnvironments(loader, named, declared) {
14133
+ async function checkEnvironments(loader, named, declared, manual) {
14082
14134
  const make = (status, detail, problems = []) => ({
14083
14135
  id: ID$6,
14084
14136
  title: TITLE$6,
@@ -14087,18 +14139,36 @@ async function checkEnvironments(loader, named, declared) {
14087
14139
  problems
14088
14140
  });
14089
14141
  const names = [...new Set([...declaredEnvironments(declared).map((env) => env.name), ...named].map((n) => n.toLowerCase()))];
14090
- if (names.length === 0) return make("ok", "none declared");
14091
- if (!loader.has("environments")) return make("skip", whyMissing(loader, "environments", "no `environments` provider to check them with"));
14142
+ const known = /* @__PURE__ */ new Set([...names, ...manual.map((n) => n.toLowerCase())]);
14143
+ const undeclaredRows = (have) => {
14144
+ const undeclared = have.map((env) => env.name).filter((name) => !known.has(name.toLowerCase()));
14145
+ return undeclared.length === 0 ? [] : [{
14146
+ id: UNDECLARED_ID,
14147
+ title: UNDECLARED_TITLE,
14148
+ status: "skip",
14149
+ detail: `${undeclared.length} not declared: ${undeclared.join(", ")}`,
14150
+ problems: []
14151
+ }];
14152
+ };
14153
+ if (names.length === 0) {
14154
+ if (!loader.has("environments")) return [make("ok", "none declared")];
14155
+ try {
14156
+ return [make("ok", "none declared"), ...undeclaredRows(await loader.get("environments").listEnvironments())];
14157
+ } catch {
14158
+ return [make("ok", "none declared")];
14159
+ }
14160
+ }
14161
+ if (!loader.has("environments")) return [make("skip", whyMissing(loader, "environments", "no `environments` provider to check them with"))];
14092
14162
  try {
14093
14163
  const have = await loader.get("environments").listEnvironments();
14094
14164
  const problems = [...declaredVsActual(new Map(names.map((name) => [name, true])), new Map(have.map((env) => [env.name.toLowerCase(), true])), {
14095
14165
  noun: "environment",
14096
14166
  flagExtra: false
14097
14167
  }), ...environmentProblems(declared, have)];
14098
- return problems.length > 0 ? make("fail", `${problems.length} problem(s)`, problems) : make("ok", `${names.length} of ${names.length} exist`);
14168
+ return [problems.length > 0 ? make("fail", `${problems.length} problem(s)`, problems) : make("ok", `${names.length} of ${names.length} exist`), ...undeclaredRows(have)];
14099
14169
  } catch (err) {
14100
14170
  const noToken = missingTokenReason(err);
14101
- return noToken !== void 0 ? make("skip", noToken) : make("fail", errorMessage(err));
14171
+ return [noToken !== void 0 ? make("skip", noToken) : make("fail", errorMessage(err))];
14102
14172
  }
14103
14173
  }
14104
14174
  // src/commands/doctor-environments/doctor-environments.command.ts
@@ -19034,19 +19104,25 @@ function repoChecks(config, repoRoot, statusContexts) {
19034
19104
  checks.push(...viewChecks(repo?.views));
19035
19105
  if (repo?.teams && repo.teams.length > 0) {
19036
19106
  const teams = repo.teams;
19107
+ const manualTeams = config.doctor?.manualTeams ?? [];
19037
19108
  checks.push({
19038
19109
  id: "repo-teams",
19039
19110
  title: "team access matches",
19040
19111
  needs: "listTeamAccess",
19041
19112
  async run(source) {
19042
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(", ")}`] : [];
19043
19122
  return {
19044
- problems: declaredVsActual(new Map(teams.map(teamPermission)), new Map(found.map((t) => [t.slug, t.permission])), {
19045
- noun: "team",
19046
- flagExtra: false,
19047
- show: quote
19048
- }),
19049
- checked: teams.length
19123
+ problems,
19124
+ checked: teams.length,
19125
+ info
19050
19126
  };
19051
19127
  }
19052
19128
  });