@theholocron/cli 5.0.0-alpha.236 → 5.0.0-alpha.237

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
@@ -24,7 +24,7 @@ import search from "@inquirer/search";
24
24
  import { execFileSync, spawn, spawnSync } from "node:child_process";
25
25
  import ora from "ora";
26
26
  import { findRootSync, isWorkspaceRoot, walkFilesSync } from "@theholocron/fs-utils";
27
- import { access, copyFile, mkdir, open, readFile, readdir, rename, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
27
+ import { access, copyFile, mkdir, open, readFile, readdir, realpath, rename, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
28
28
  import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
29
29
  import { createServer } from "node:http";
30
30
  import { stringifyJson } from "@theholocron/json-utils";
@@ -6967,6 +6967,29 @@ function printNextSteps$1(print, inputs) {
6967
6967
  print(" 7. Commit + push when capability is functionally complete.");
6968
6968
  }
6969
6969
  //#endregion
6970
+ //#region src/commands/probe/app-vault.ts
6971
+ /**
6972
+ * The vault of an app that carries its own `holocron.config` (`apps/comlink`, `apps/sentinel`): those configs govern where
6973
+ * the app's secrets live, apart from the root's. `undefined` when the app has no config of its own (the search for one
6974
+ * would otherwise walk up and find the root's), or its config declares no vault, or that config cannot be read.
6975
+ */
6976
+ async function loadAppVault(appDir, context, importer) {
6977
+ let loaded;
6978
+ try {
6979
+ loaded = await loadConfig(appDir);
6980
+ } catch {
6981
+ return;
6982
+ }
6983
+ const [found, wanted] = await Promise.all([realpath(dirname(loaded.filepath)), realpath(appDir)]);
6984
+ if (found !== wanted) return void 0;
6985
+ const loader = new PluginLoader(loaded.resolved, {
6986
+ ...context,
6987
+ repoRoot: appDir
6988
+ }, importer);
6989
+ await loader.load();
6990
+ return loader.has("vault") ? loader.get("vault") : void 0;
6991
+ }
6992
+ //#endregion
6970
6993
  //#region src/commands/probe/comlink-probes.ts
6971
6994
  /** The group of probes for the Comlink relay Worker (`apps/comlink`). It is an app, not a provider, so they are the CLI's own. */
6972
6995
  const COMLINK_PROVIDER = "comlink";
@@ -6981,6 +7004,7 @@ function relayOf(loader) {
6981
7004
  return {
6982
7005
  host,
6983
7006
  script: layout.relay?.script ?? "comlink",
7007
+ appDir: dirname(dirname(layout.relay?.code ?? "apps/comlink/dist/worker.js")),
6984
7008
  source: errors.providerName.toLowerCase()
6985
7009
  };
6986
7010
  }
@@ -6999,6 +7023,15 @@ const testDelivery = () => JSON.stringify({
6999
7023
  triggered_rule: "holocron probe"
7000
7024
  }
7001
7025
  });
7026
+ /** A secret by name from a vault: the bare name when the vault can take one, else as a reference. `undefined` if it cannot be read. */
7027
+ async function readSecret(vault, name) {
7028
+ if (!vault) return void 0;
7029
+ try {
7030
+ return await (vault.readSecret ? vault.readSecret(name) : vault.read(name)) || void 0;
7031
+ } catch {
7032
+ return;
7033
+ }
7034
+ }
7002
7035
  function comlinkProbes(deps) {
7003
7036
  const http = deps.fetch ?? fetch;
7004
7037
  const env = deps.env ?? process.env;
@@ -7058,7 +7091,7 @@ function comlinkProbes(deps) {
7058
7091
  summary: "Send the relay a correctly signed test alert, so a labelled embed lands in the errors channel. The message stays there.",
7059
7092
  writes: true,
7060
7093
  async run(probe) {
7061
- const { host, source } = relayOf(deps.loader);
7094
+ const { host, source, appDir } = relayOf(deps.loader);
7062
7095
  if (source !== "sentry") throw new Error(`deliver knows how to sign a Sentry delivery, not a ${source} one`);
7063
7096
  const name = relaySecretBinding(source);
7064
7097
  if (probe.dryRun) {
@@ -7069,8 +7102,9 @@ function comlinkProbes(deps) {
7069
7102
  return;
7070
7103
  }
7071
7104
  let secret = env[name];
7072
- if (!secret && deps.loader.has("vault")) secret = await deps.loader.get("vault").read(name).catch(() => void 0);
7073
- if (!secret) throw new Error(`no signing secret: set ${name} in the environment (for example \`doppler run -- holocron probe comlink deliver\`), or run this where the vault holds it`);
7105
+ if (!secret && deps.appVault) secret = await readSecret(await deps.appVault(appDir), name);
7106
+ if (!secret && deps.loader.has("vault")) secret = await readSecret(deps.loader.get("vault"), name);
7107
+ if (!secret) throw new Error(`no signing secret: set ${name} in the environment, or give ${appDir}/holocron.config a vault that holds it`);
7074
7108
  probe.secret(secret);
7075
7109
  const body = testDelivery();
7076
7110
  const status = await probe.write("send a signed test alert to the relay", async () => {
@@ -7340,7 +7374,10 @@ async function runProbeCommand(input) {
7340
7374
  const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
7341
7375
  await loader.load();
7342
7376
  const groups = new Map(loader.probes());
7343
- const comlink = comlinkProbes({ loader });
7377
+ const comlink = comlinkProbes({
7378
+ loader,
7379
+ appVault: (appDir) => loadAppVault(join(input.context.repoRoot, appDir), input.context)
7380
+ });
7344
7381
  groups.set(CORE_PROVIDER, coreProbes(loader, /* @__PURE__ */ new Map([[COMLINK_PROVIDER, comlink]])));
7345
7382
  groups.set(COMLINK_PROVIDER, comlink);
7346
7383
  if (!input.provider) {