@theholocron/cli 5.0.0-alpha.476 → 5.0.0-alpha.477

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
@@ -86,6 +86,7 @@ const COMMAND_CONTEXTS = {
86
86
  "new secret": "workspace",
87
87
  "sync secrets": "workspace",
88
88
  "new tunnel": "workspace",
89
+ "new domain": "workspace",
89
90
  "list projects": "workspace",
90
91
  "new project": "workspace",
91
92
  "close project": "workspace",
@@ -792,6 +793,43 @@ const newRepoEntry = {
792
793
  ],
793
794
  supportsDryRun: true
794
795
  };
796
+ // src/commands/new-domain/new-domain.entry.ts
797
+ const newDomainEntry = {
798
+ name: "new domain",
799
+ description: "Make a DNS record through the `dns` provider and keep it in .holocron/dns-records.json",
800
+ positionals: [],
801
+ options: [
802
+ {
803
+ key: "type",
804
+ flag: "--type",
805
+ type: "input",
806
+ message: "Type (CNAME, TXT, A or AAAA):",
807
+ required: true
808
+ },
809
+ {
810
+ key: "name",
811
+ flag: "--name",
812
+ type: "input",
813
+ message: "Hostname (e.g. status.example.dev):",
814
+ required: true
815
+ },
816
+ {
817
+ key: "value",
818
+ flag: "--value",
819
+ type: "input",
820
+ message: "Value, as the vendor shows it:",
821
+ required: true
822
+ },
823
+ {
824
+ key: "note",
825
+ flag: "--note",
826
+ type: "input",
827
+ message: "Note (which vendor serves it):"
828
+ }
829
+ ],
830
+ skipOptions: ["proxied", "yes"],
831
+ supportsDryRun: true
832
+ };
795
833
  // src/commands/notifications-channel-add/notifications-channel-add.entry.ts
796
834
  const notificationsChannelAddEntry = {
797
835
  name: "new channel",
@@ -1567,6 +1605,7 @@ const registry = createCommandRegistry([
1567
1605
  ],
1568
1606
  supportsDryRun: true
1569
1607
  },
1608
+ newDomainEntry,
1570
1609
  projectListEntry,
1571
1610
  projectCreateEntry,
1572
1611
  projectCloseEntry,
@@ -6991,6 +7030,86 @@ const doctorCiCommand = {
6991
7030
  })).status === "fail") process.exitCode = 1;
6992
7031
  }
6993
7032
  };
7033
+ // src/dns-records/disk-io/disk-io.ts
7034
+ /** The file system the list lives on. */
7035
+ const diskIo = {
7036
+ read: (path) => readFile(path, "utf8").catch((err) => {
7037
+ if (err.code === "ENOENT") return null;
7038
+ throw err;
7039
+ }),
7040
+ write: async (path, text) => {
7041
+ await mkdir(dirname(path), { recursive: true });
7042
+ await writeFile(path, text, "utf8");
7043
+ }
7044
+ };
7045
+ // src/dns-records/dns-records.type.ts
7046
+ /** The list's file, relative to the repository root. */
7047
+ const DNS_RECORDS_FILE = ".holocron/dns-records.json";
7048
+ /** The record types `holocron new domain` takes. MX and SRV need a priority the entry does not carry. */
7049
+ const DNS_ENTRY_TYPES = [
7050
+ "CNAME",
7051
+ "TXT",
7052
+ "A",
7053
+ "AAAA"
7054
+ ];
7055
+ // src/dns-records/parse-dns-records/parse-dns-records.ts
7056
+ /** The list in `text`, or a `ConfigError` naming the entry that is wrong. An empty file is an empty list. */
7057
+ function parseDnsRecords(text, file) {
7058
+ if (text.trim() === "") return [];
7059
+ let raw;
7060
+ try {
7061
+ raw = JSON.parse(text);
7062
+ } catch (err) {
7063
+ throw new ConfigError$1(`${file} is not JSON: ${errorMessage(err)}`);
7064
+ }
7065
+ if (!Array.isArray(raw)) throw new ConfigError$1(`${file} must hold an array of records`);
7066
+ return raw.map((item, i) => {
7067
+ const at = `${file} entry ${i + 1}`;
7068
+ if (typeof item !== "object" || item === null) throw new ConfigError$1(`${at} must be an object`);
7069
+ const e = item;
7070
+ const type = DNS_ENTRY_TYPES.find((t) => t === e.type);
7071
+ if (!type) throw new ConfigError$1(`${at}: type must be one of ${DNS_ENTRY_TYPES.join(", ")}`);
7072
+ for (const key of ["name", "value"]) if (typeof e[key] !== "string" || e[key] === "") throw new ConfigError$1(`${at}: ${key} must be a non-empty string`);
7073
+ if (e.note !== void 0 && typeof e.note !== "string") throw new ConfigError$1(`${at}: note must be a string`);
7074
+ if (e.proxied !== void 0 && typeof e.proxied !== "boolean") throw new ConfigError$1(`${at}: proxied must be true or false`);
7075
+ return {
7076
+ type,
7077
+ name: e.name,
7078
+ value: e.value,
7079
+ ...e.note !== void 0 ? { note: e.note } : {},
7080
+ ...e.proxied !== void 0 ? { proxied: e.proxied } : {}
7081
+ };
7082
+ });
7083
+ }
7084
+ // src/dns-records/read-dns-records/read-dns-records.ts
7085
+ /** The records `.holocron/dns-records.json` lists; none when the file is absent. */
7086
+ async function readDnsRecords(repoRoot, io = diskIo) {
7087
+ const text = await io.read(join(repoRoot, DNS_RECORDS_FILE));
7088
+ return text === null ? [] : parseDnsRecords(text, DNS_RECORDS_FILE);
7089
+ }
7090
+ // src/dns-records/upsert-dns-entry/upsert-dns-entry.ts
7091
+ /** An entry's identity: its type and its name, without case or a final dot. */
7092
+ const entryKey = (e) => `${e.type} ${e.name.toLowerCase().replace(/\.$/, "")}`;
7093
+ /**
7094
+ * The list with `entry` in it: a new entry goes last, one with the same type and name takes its place (order kept)
7095
+ * and is returned as `replaced`. The list given is not changed.
7096
+ */
7097
+ function upsertDnsEntry(list, entry) {
7098
+ const at = list.findIndex((e) => entryKey(e) === entryKey(entry));
7099
+ if (at === -1) return {
7100
+ list: [...list, entry],
7101
+ replaced: void 0
7102
+ };
7103
+ return {
7104
+ list: list.map((e, i) => i === at ? entry : e),
7105
+ replaced: list[at]
7106
+ };
7107
+ }
7108
+ // src/dns-records/write-dns-records/write-dns-records.ts
7109
+ /** Write the list the way Prettier lays JSON out, so a rewrite leaves the file formatted. */
7110
+ async function writeDnsRecords(repoRoot, list, io = diskIo) {
7111
+ await io.write(join(repoRoot, DNS_RECORDS_FILE), formatJson(list));
7112
+ }
6994
7113
  // src/commands/missing-token/missing-token.ts
6995
7114
  /**
6996
7115
  * Why a provider call could not be tried for want of a token, or undefined when the error is something else. A plugin
@@ -7231,10 +7350,35 @@ async function runDoctorDns(input) {
7231
7350
  ...loader.has("wiki") ? { wiki: loader.get("wiki") } : {},
7232
7351
  layouts: (loader.has("notifications") ? loader.get("notifications") : []).flatMap((p) => p.layout ? [p.layout] : [])
7233
7352
  });
7353
+ let listFailure;
7354
+ const listed = await readDnsRecords(input.context.repoRoot, input.io).catch((err) => {
7355
+ listFailure = errorMessage(err);
7356
+ return [];
7357
+ });
7358
+ const apex = input.loaded.resolved.domain;
7359
+ for (const e of listed) {
7360
+ const zone = apex && (e.name === apex || e.name.endsWith(`.${apex}`)) ? apex : e.name;
7361
+ expected.push({
7362
+ zone,
7363
+ record: {
7364
+ type: e.type,
7365
+ name: e.name,
7366
+ content: e.value,
7367
+ proxied: e.proxied ?? false
7368
+ }
7369
+ });
7370
+ }
7234
7371
  const zones = [...new Set(expected.map((e) => e.zone))];
7235
7372
  const deploy = loader.has("deployment") ? loader.get("deployment") : void 0;
7236
7373
  const domains = deploy?.expectedDomainRecord ? deploymentDomains(input.loaded.resolved, deploy) : [];
7237
7374
  const rows = [];
7375
+ if (listFailure !== void 0) rows.push({
7376
+ id: "dns-records-file",
7377
+ title: "dns-records.json reads",
7378
+ status: "fail",
7379
+ detail: listFailure,
7380
+ problems: []
7381
+ });
7238
7382
  if (zones.length === 0 && domains.length === 0) rows.push({
7239
7383
  id: "dns",
7240
7384
  title: "dns",
@@ -17007,6 +17151,65 @@ function describeProviderError(err) {
17007
17151
  if (said === void 0 || !(err instanceof Error)) return describeError(err);
17008
17152
  return describeError(Object.assign(new Error(err.message), { details: said }));
17009
17153
  }
17154
+ // src/commands/setup/dns-records-step/dns-records-step.ts
17155
+ /**
17156
+ * `holocron setup`'s step for the records `holocron new domain` keeps in `.holocron/dns-records.json` (spec
17157
+ * `tech-new-domain-command`). Each is made through the `dns` provider, DNS-only unless the entry says `proxied`; an
17158
+ * upsert leaves a record that is already right as it is. With no `dns` provider each is a failing `todo` row that says
17159
+ * what to make. `--dry-run` writes nothing. Never deletes. No list, no steps; a list that cannot be read is one
17160
+ * failing row.
17161
+ */
17162
+ async function dnsRecordsStep(loader, repoRoot, dryRun, io) {
17163
+ let list;
17164
+ try {
17165
+ list = await readDnsRecords(repoRoot, io);
17166
+ } catch (err) {
17167
+ return [{
17168
+ capability: "dns",
17169
+ step: "read dns-records.json",
17170
+ status: "fail",
17171
+ message: errorMessage(err)
17172
+ }];
17173
+ }
17174
+ const steps = [];
17175
+ for (const e of list) {
17176
+ const step = `dns ${e.type} ${e.name}`;
17177
+ if (dryRun) steps.push({
17178
+ capability: "dns",
17179
+ step,
17180
+ status: "dry-run",
17181
+ message: "would make the record"
17182
+ });
17183
+ else if (!loader.has("dns")) steps.push({
17184
+ capability: "dns",
17185
+ step,
17186
+ status: "fail",
17187
+ message: `todo: no \`dns\` provider is configured; make ${e.type} ${e.name} -> ${e.value}`
17188
+ });
17189
+ else try {
17190
+ await loader.get("dns").upsertRecord(e.name, {
17191
+ type: e.type,
17192
+ name: e.name,
17193
+ content: e.value,
17194
+ proxied: e.proxied ?? false
17195
+ });
17196
+ steps.push({
17197
+ capability: "dns",
17198
+ step,
17199
+ status: "ok",
17200
+ message: `made${e.proxied ? "" : " (DNS only)"}${e.note ? `: ${e.note}` : ""}`
17201
+ });
17202
+ } catch (err) {
17203
+ steps.push({
17204
+ capability: "dns",
17205
+ step,
17206
+ status: "fail",
17207
+ message: describeProviderError(err)
17208
+ });
17209
+ }
17210
+ }
17211
+ return steps;
17212
+ }
17010
17213
  // src/commands/setup/engineering.ts
17011
17214
  async function writeIfAbsent(filePath, content) {
17012
17215
  try {
@@ -17910,6 +18113,14 @@ async function runSetup(input) {
17910
18113
  print(formatStep(steps[steps.length - 1]));
17911
18114
  }
17912
18115
  }
18116
+ const dnsSteps = await dnsRecordsStep(loader, input.context.repoRoot, dryRun);
18117
+ if (dnsSteps.length > 0) {
18118
+ print(style.step("dns"));
18119
+ for (const step of dnsSteps) {
18120
+ steps.push(step);
18121
+ print(formatStep(step));
18122
+ }
18123
+ }
17913
18124
  if (loader.has("monitoring")) {
17914
18125
  const monitoring = loader.get("monitoring");
17915
18126
  print(style.step("monitoring"));
@@ -19826,6 +20037,170 @@ const issueCreateCommand = {
19826
20037
  })).status === "fail") process.exitCode = 1;
19827
20038
  }
19828
20039
  };
20040
+ // src/commands/new-domain/new-domain.ts
20041
+ /**
20042
+ * `holocron new domain` — take a DNS record, make it through the `dns` provider, keep it in the list
20043
+ * (`.holocron/dns-records.json`) that `setup` re-applies and `doctor dns` checks (spec `tech-new-domain-command`).
20044
+ *
20045
+ * Provider-neutral: it calls the `dns` capability's `upsertRecord`, so it names no vendor. A record is DNS-only unless
20046
+ * `--proxied`, because a vendor reads the record itself to verify the name. It shows what will change, asks first
20047
+ * (unless `--yes` or `--dry-run`) and never deletes.
20048
+ */
20049
+ /** A value as comparable text: no case, no final dot, no quotes around a TXT value. */
20050
+ const normal = (v) => v.trim().replace(/^"(.*)"$/s, "$1").replace(/\.$/, "").toLowerCase();
20051
+ async function runNewDomain(input) {
20052
+ const { print, logger, loader } = input;
20053
+ await loader.load();
20054
+ assertPluginsResolvable(loader, "new domain");
20055
+ if (!loader.has("dns")) throw new Error("`dns` capability is not configured: add a `dns` provider to holocron.config");
20056
+ const need = async (field) => {
20057
+ const given = input[field];
20058
+ if (given !== void 0 && given !== "") return given;
20059
+ if (!input.ask) throw new NonInteractiveError(`--${field} is required without a terminal`);
20060
+ return (await input.ask(field)).trim();
20061
+ };
20062
+ const type = (await need("type")).toUpperCase();
20063
+ const kind = DNS_ENTRY_TYPES.find((t) => t === type);
20064
+ if (!kind) throw new Error(`--type must be one of ${DNS_ENTRY_TYPES.join(", ")} (got ${type})`);
20065
+ const name = (await need("name")).toLowerCase().replace(/\.$/, "");
20066
+ const zone = input.loaded.resolved.domain;
20067
+ if (zone && name !== zone && !name.endsWith(`.${zone}`)) throw new Error(`--name must be ${zone} or a name under it (got ${name})`);
20068
+ const value = await need("value");
20069
+ if (value === "") throw new Error("--value is required");
20070
+ const entry = {
20071
+ type: kind,
20072
+ name,
20073
+ value,
20074
+ ...input.note ? { note: input.note } : {},
20075
+ ...input.proxied ? { proxied: true } : {}
20076
+ };
20077
+ const dryRun = input.context.dryRun === true;
20078
+ const dns = loader.get("dns");
20079
+ const { list, replaced } = upsertDnsEntry(await readDnsRecords(input.context.repoRoot, input.io), entry);
20080
+ print(`Holocron new domain — ${entry.type} ${entry.name}${dryRun ? " (dry-run)" : ""}`);
20081
+ try {
20082
+ const held = (await dns.listRecords(entry.name)).filter((r) => r.type === entry.type && normal(r.name) === normal(entry.name));
20083
+ const same = held.some((r) => normal(r.content) === normal(entry.value) && r.proxied === true === (entry.proxied ?? false));
20084
+ print(held.length === 0 ? ` + ${entry.type} ${entry.name} -> ${entry.value} is new` : same ? ` = ${entry.type} ${entry.name} already holds that value` : ` ~ ${entry.type} ${entry.name} holds ${held[0].content}; it would become ${entry.value}`);
20085
+ if (replaced) print(` ~ the list already has this record (${replaced.value}); its entry is replaced`);
20086
+ if (dryRun) return {
20087
+ status: "dry-run",
20088
+ entry,
20089
+ message: "nothing written"
20090
+ };
20091
+ if (!input.yes) {
20092
+ if (!input.confirm) throw new NonInteractiveError("pass --yes to make the record without a terminal");
20093
+ if (!await input.confirm(`Make ${entry.type} ${entry.name} (DNS ${entry.proxied ? "proxied" : "only"})?`)) {
20094
+ print(" cancelled; nothing written");
20095
+ return {
20096
+ status: "cancelled",
20097
+ entry
20098
+ };
20099
+ }
20100
+ }
20101
+ const record = {
20102
+ type: entry.type,
20103
+ name: entry.name,
20104
+ content: entry.value,
20105
+ proxied: entry.proxied ?? false
20106
+ };
20107
+ await dns.upsertRecord(entry.name, record);
20108
+ await writeDnsRecords(input.context.repoRoot, list, input.io);
20109
+ print(` ✓ made ${entry.type} ${entry.name} via ${dns.providerName}; kept in .holocron/dns-records.json`);
20110
+ logger.info({
20111
+ type: entry.type,
20112
+ name: entry.name,
20113
+ provider: dns.providerName,
20114
+ status: "ok"
20115
+ }, "new domain");
20116
+ return {
20117
+ status: "ok",
20118
+ entry
20119
+ };
20120
+ } catch (err) {
20121
+ if (err instanceof NonInteractiveError) throw err;
20122
+ const message = errorMessage(err);
20123
+ print(` ✗ ${message}`);
20124
+ logger.warn({
20125
+ type: entry.type,
20126
+ name: entry.name,
20127
+ reason: message
20128
+ }, "new domain");
20129
+ return {
20130
+ status: "fail",
20131
+ entry,
20132
+ message
20133
+ };
20134
+ }
20135
+ }
20136
+ // src/commands/new-domain/new-domain.command.ts
20137
+ const newDomainArgs = (y) => y.option("type", {
20138
+ type: "string",
20139
+ describe: `Record type: ${DNS_ENTRY_TYPES.join(", ")} (asked for on a terminal)`
20140
+ }).option("name", {
20141
+ type: "string",
20142
+ describe: "The full hostname, under the org's domain (asked for on a terminal)"
20143
+ }).option("value", {
20144
+ type: "string",
20145
+ describe: "The record's content, as the vendor shows it (asked for on a terminal)"
20146
+ }).option("note", {
20147
+ type: "string",
20148
+ describe: "Why it exists, e.g. which vendor serves the name"
20149
+ }).option("proxied", {
20150
+ type: "boolean",
20151
+ default: false,
20152
+ describe: "Send traffic through the provider's proxy (default: DNS only, which a vendor's verification needs)"
20153
+ }).option("yes", {
20154
+ type: "boolean",
20155
+ default: false,
20156
+ describe: "Make the record without asking first (required without a terminal)"
20157
+ });
20158
+ /** Ask for one field on a terminal. */
20159
+ async function ask(field) {
20160
+ if (field === "type") return select({
20161
+ message: "Record type:",
20162
+ choices: DNS_ENTRY_TYPES.map((t) => ({ value: t }))
20163
+ });
20164
+ return input({ message: field === "name" ? "Hostname:" : "Value, as the vendor shows it:" });
20165
+ }
20166
+ const newDomainCommand = {
20167
+ command: "domain",
20168
+ describe: "Make a DNS record through the `dns` provider and keep it in .holocron/dns-records.json",
20169
+ builder: newDomainArgs,
20170
+ handler: async (argv) => {
20171
+ const tokens = tokenContext(argv.token);
20172
+ if (!tokens) return;
20173
+ const loaded = await loadConfig(argv.cwd);
20174
+ applyResolvedConfig(argv, loaded.resolved);
20175
+ const terminal = process.stdin.isTTY === true;
20176
+ const context = {
20177
+ repoRoot: argv.cwd,
20178
+ dryRun: argv.dryRun,
20179
+ ...tokens,
20180
+ org: resolveOrg(argv, loaded.resolved)
20181
+ };
20182
+ if ((await runNewDomain({
20183
+ loaded,
20184
+ context,
20185
+ loader: new PluginLoader(loaded.resolved, context),
20186
+ print: (line) => console.log(line),
20187
+ logger: getLogger(),
20188
+ ...argv.type ? { type: argv.type } : {},
20189
+ ...argv.name ? { name: argv.name } : {},
20190
+ ...argv.value ? { value: argv.value } : {},
20191
+ ...argv.note ? { note: argv.note } : {},
20192
+ ...argv.proxied ? { proxied: true } : {},
20193
+ ...argv.yes ? { yes: true } : {},
20194
+ ...terminal ? {
20195
+ ask,
20196
+ confirm: (message) => confirm({
20197
+ message,
20198
+ default: false
20199
+ })
20200
+ } : {}
20201
+ })).status === "fail") process.exitCode = 1;
20202
+ }
20203
+ };
19829
20204
  // src/commands/notifications-channel-add/notifications-channel-add.args.ts
19830
20205
  const notificationsChannelAddArgs = (y) => y.positional("name", {
19831
20206
  type: "string",
@@ -22255,8 +22630,8 @@ const newRepoCommand = {
22255
22630
  // src/commands/new/new.command.ts
22256
22631
  const newCommand = {
22257
22632
  command: "new",
22258
- describe: "Create a repo, plugin, channel, server, secret, token, tunnel, GitHub App, project, spec or issue",
22259
- builder: (y) => y.command(newRepoCommand).command(pluginCreateCommand).command(notificationsChannelAddCommand).command(githubAppCreateCommand).command(projectCreateCommand).command(secretSetCommand).command(notificationsCreateServerCommand).command(ideasPromoteCommand).command(issueCreateCommand).command(authSetCommand).command(tunnelUpCommand).command(groupMenu("new")),
22633
+ describe: "Create a repo, plugin, channel, server, secret, token, tunnel, domain record, GitHub App, project, spec or issue",
22634
+ builder: (y) => y.command(newRepoCommand).command(pluginCreateCommand).command(notificationsChannelAddCommand).command(githubAppCreateCommand).command(projectCreateCommand).command(secretSetCommand).command(notificationsCreateServerCommand).command(ideasPromoteCommand).command(issueCreateCommand).command(authSetCommand).command(tunnelUpCommand).command(newDomainCommand).command(groupMenu("new")),
22260
22635
  handler: () => {}
22261
22636
  };
22262
22637
  // src/commands/probe/probe.args.ts