@theholocron/cli 5.0.0-alpha.432 → 5.0.0-alpha.433

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
@@ -19974,15 +19974,15 @@ const newCommand = {
19974
19974
  * run itself prints only the result.
19975
19975
  */
19976
19976
  const TOKEN_PROBE_HELP = [
19977
- "Probes about a token (for example `holocron probe cloudflare token`) check one token. The first of these that applies picks it:",
19977
+ "Probes about a token (for example `holocron probe cloudflare token`) check a token. The first of these that applies picks it:",
19978
19978
  [
19979
19979
  "- --token <provider>=<value>: that token (a bare --token <value> goes to every provider).",
19980
- "- --environment <layer or name>: the provider's token, read from that vault Environment.",
19980
+ "- --environment <layer or name>: every token the provider declares that the vault Environment holds, one after another, each under its variable name.",
19981
19981
  "- On a terminal, with neither: a question, which asks for the configured token, an Environment or a pasted token.",
19982
19982
  "- Otherwise: the token the provider normally resolves."
19983
19983
  ].join("\n"),
19984
19984
  "--environment takes a layer (local, dev, ci or prod, which is this repo's `<org/repo> - <layer>`) or an Environment the config already names; anything else is refused. `local` is read over `dev`, as the CLI reads it.",
19985
- "A token read from a layer is checked against what that layer's token should carry (the permission table in the tokens docs): what it should have must be there and what it should not have must not be. Any other token is only described. The token is never printed."
19985
+ "A token read from a layer is checked against what that layer's token should carry (the permission table in the tokens docs): what it should have must be there and what it should not have must not be. A declared token the Environment does not hold is skipped, and fails when that layer is meant to hold it. Any other token is only described. A token is never printed."
19986
19986
  ].join("\n\n");
19987
19987
  const probeArgs = (y) => y.positional("provider", {
19988
19988
  type: "string",
@@ -20013,7 +20013,7 @@ const probeArgs = (y) => y.positional("provider", {
20013
20013
  describe: "`1password export-environment`: put the variables on the clipboard instead of a file"
20014
20014
  }).option("environment", {
20015
20015
  type: "string",
20016
- describe: "A probe about a token (`cloudflare token`): check the provider's token held in this vault Environment (a layer such as `ci` or `dev`, or a name)"
20016
+ describe: "A probe about a token (`cloudflare token`): check every token of the provider held in this vault Environment (a layer such as `ci` or `dev`, or a name)"
20017
20017
  }).option("yes", {
20018
20018
  type: "boolean",
20019
20019
  default: false,
@@ -20040,6 +20040,33 @@ function ownerEnvironments(config) {
20040
20040
  instances
20041
20041
  };
20042
20042
  }
20043
+ // src/commands/token-expectations/token-expectations.ts
20044
+ /**
20045
+ * Reads what a plugin's tokens declare (`PluginToken.expect`) as one entry per token and layer that holds it, in the
20046
+ * order of `ENVIRONMENT_LAYERS`. The one reader the token probes, the doctor and the docs check share, so none of them
20047
+ * walks the declaration itself. A token with no `expect` yields nothing; a layer no token holds is never listed.
20048
+ */
20049
+ function tokenExpectations(tokens, filter = {}) {
20050
+ const found = [];
20051
+ for (const token of tokens) {
20052
+ if (!token.expect || filter.envName !== void 0 && token.envName !== filter.envName) continue;
20053
+ const { layers = [], permissions = {} } = token.expect;
20054
+ for (const layer of ENVIRONMENT_LAYERS) {
20055
+ if (filter.layer !== void 0 && filter.layer !== layer) continue;
20056
+ const rules = permissions[layer];
20057
+ if (!rules && !layers.includes(layer)) continue;
20058
+ const entries = Object.entries(rules ?? {});
20059
+ found.push({
20060
+ envName: token.envName,
20061
+ layer,
20062
+ rules: rules ?? {},
20063
+ required: entries.filter(([, rule]) => rule === "required").map(([name]) => name),
20064
+ absent: entries.filter(([, rule]) => rule === "absent").map(([name]) => name)
20065
+ });
20066
+ }
20067
+ }
20068
+ return found;
20069
+ }
20043
20070
  // src/commands/probe/app-vault.ts
20044
20071
  /**
20045
20072
  * The vault of an app that carries its own `holocron.config` (`apps/comlink`, `apps/sentinel`): those configs govern where
@@ -20823,33 +20850,6 @@ function realDocsPresenceIo(repoRoot) {
20823
20850
  };
20824
20851
  /* v8 ignore stop */
20825
20852
  }
20826
- // src/commands/token-expectations/token-expectations.ts
20827
- /**
20828
- * Reads what a plugin's tokens declare (`PluginToken.expect`) as one entry per token and layer that holds it, in the
20829
- * order of `ENVIRONMENT_LAYERS`. The one reader the token probes, the doctor and the docs check share, so none of them
20830
- * walks the declaration itself. A token with no `expect` yields nothing; a layer no token holds is never listed.
20831
- */
20832
- function tokenExpectations(tokens, filter = {}) {
20833
- const found = [];
20834
- for (const token of tokens) {
20835
- if (!token.expect || filter.envName !== void 0 && token.envName !== filter.envName) continue;
20836
- const { layers = [], permissions = {} } = token.expect;
20837
- for (const layer of ENVIRONMENT_LAYERS) {
20838
- if (filter.layer !== void 0 && filter.layer !== layer) continue;
20839
- const rules = permissions[layer];
20840
- if (!rules && !layers.includes(layer)) continue;
20841
- const entries = Object.entries(rules ?? {});
20842
- found.push({
20843
- envName: token.envName,
20844
- layer,
20845
- rules: rules ?? {},
20846
- required: entries.filter(([, rule]) => rule === "required").map(([name]) => name),
20847
- absent: entries.filter(([, rule]) => rule === "absent").map(([name]) => name)
20848
- });
20849
- }
20850
- }
20851
- return found;
20852
- }
20853
20853
  // src/commands/probe/docs-tokens/compare-permissions/compare-permissions.ts
20854
20854
  const mentions = (heading, name) => heading.toLowerCase().includes(name.toLowerCase());
20855
20855
  /**
@@ -21763,20 +21763,21 @@ async function resolveEnvironmentId(id, input) {
21763
21763
  if (!isEnvironmentLayer(id)) return id;
21764
21764
  return layerEnvironment(await repoSlug(input.repoRoot, input.gitExec), id);
21765
21765
  }
21766
- // src/commands/probe/probe-token/environment-token.ts
21766
+ // src/commands/probe/probe-token/environment-tokens.ts
21767
21767
  /**
21768
- * The provider's API token as held in one vault Environment, read in memory. Only an Environment this repo uses is
21768
+ * Every token the provider declares that one vault Environment holds, read in memory. Only an Environment this repo uses is
21769
21769
  * read: a layer word (`local`, `dev`, `ci`, `prod`) is this repo's `<org/repo> - <layer>`, and any other text must be a
21770
21770
  * name the config already names (`configured`), so a probe cannot be pointed at an Environment the repo has nothing to
21771
21771
  * do with. `local` reads the way the CLI does, `- local` over `- dev`, and `- local` may be absent.
21772
21772
  *
21773
- * The variables looked for are the ones the provider's plugin lists (`HOLOCRON_CLOUDFLARE_TOKEN`, then the vendor's own
21774
- * `CLOUDFLARE_API_TOKEN`); the first that holds a value wins.
21773
+ * Each token the provider's plugin lists is looked for under its own variable (`HOLOCRON_SENTRY_TOKEN`), then the
21774
+ * vendor's (`vendorEnvName`); the first that holds a value is that token's. A token the Environment does not hold is in
21775
+ * `missing`, so the caller can report it by name.
21775
21776
  *
21776
- * @throws {Error} When the name is not one of this repo's, no vault that reads an Environment is configured, or the
21777
- * Environment holds none of the variables.
21777
+ * @throws {Error} When the name is not one of this repo's, no vault that reads an Environment is configured, the plugin
21778
+ * lists no token, or the Environment holds none of them.
21778
21779
  */
21779
- async function environmentToken(input) {
21780
+ async function environmentTokens(input) {
21780
21781
  if (!isEnvironmentLayer(input.environment) && !input.configured.includes(input.environment)) {
21781
21782
  const known = [...ENVIRONMENT_LAYERS, ...input.configured];
21782
21783
  throw new Error(`${input.environment} is not an Environment this repo's config names; use one of: ${known.join(", ")}`);
@@ -21797,17 +21798,27 @@ async function environmentToken(input) {
21797
21798
  ...local
21798
21799
  };
21799
21800
  } else values = await read(environment);
21800
- const names = input.tokens.flatMap((t) => [t.envName, ...t.vendorEnvName ? [t.vendorEnvName] : []]);
21801
- if (names.length === 0) throw new Error(`the ${input.provider} plugin lists no token to look for`);
21802
- for (const variable of names) {
21803
- const token = values[variable];
21804
- if (token) return {
21805
- token,
21806
- environment,
21807
- variable
21808
- };
21801
+ if (input.tokens.length === 0) throw new Error(`the ${input.provider} plugin lists no token to look for`);
21802
+ const held = [];
21803
+ const missing = [];
21804
+ for (const declared of input.tokens) {
21805
+ const variable = [declared.envName, ...declared.vendorEnvName ? [declared.vendorEnvName] : []].find((v) => values[v]);
21806
+ if (variable) held.push({
21807
+ token: values[variable],
21808
+ variable,
21809
+ envName: declared.envName
21810
+ });
21811
+ else missing.push(declared.envName);
21812
+ }
21813
+ if (held.length === 0) {
21814
+ const names = input.tokens.flatMap((t) => [t.envName, ...t.vendorEnvName ? [t.vendorEnvName] : []]);
21815
+ throw new Error(`${environment} holds none of ${names.join(", ")}`);
21809
21816
  }
21810
- throw new Error(`${environment} holds none of ${names.join(", ")}`);
21817
+ return {
21818
+ environment,
21819
+ held,
21820
+ missing
21821
+ };
21811
21822
  }
21812
21823
  // src/commands/probe/references/clone-org.ts
21813
21824
  const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "node_modules"]);
@@ -22039,6 +22050,10 @@ async function runProbe(input) {
22039
22050
  if (clean.status === "heading") print(`\n ${style.header(clean.label)}`);
22040
22051
  else print(statusRow(clean.status === "info" ? "skip" : clean.status, [clean.label, clean.detail ?? ""]));
22041
22052
  };
22053
+ if (input.heading) emit({
22054
+ status: "heading",
22055
+ label: input.heading
22056
+ });
22042
22057
  if (input.probe.writes && !input.dryRun && !input.yes) {
22043
22058
  if (!(input.interactive ?? Boolean(process.stdin.isTTY))) throw new NonInteractiveError(`\`${input.name}\` changes things on ${input.provider} (${input.probe.summary}); pass --yes to run it without asking`);
22044
22059
  if (!await (input.confirm ?? ((message) => confirm({
@@ -22428,63 +22443,106 @@ async function runProbeCommand(input) {
22428
22443
  for (const line of listProbes(/* @__PURE__ */ new Map([[input.provider, probes]]))) print(line);
22429
22444
  return { status: "listed" };
22430
22445
  }
22431
- let probe = probes[input.probe];
22446
+ const probe = probes[input.probe];
22432
22447
  if (!probe) {
22433
22448
  print(statusRow("fail", [`\`${input.provider}\` has no probe \`${input.probe}\``, `try: ${Object.keys(probes).sort().join(", ")}`]));
22434
22449
  return { status: "fail" };
22435
22450
  }
22436
- let context = input.context;
22437
22451
  let layer;
22452
+ const steps = [{
22453
+ context: input.context,
22454
+ args: []
22455
+ }];
22456
+ const notHeld = [];
22438
22457
  if (probe.acceptsToken) {
22439
- const given = context.cliTokens?.[input.provider] ?? context.cliToken;
22458
+ const given = input.context.cliTokens?.[input.provider] ?? input.context.cliToken;
22440
22459
  const chosen = input.environment ? { environment: input.environment } : given === void 0 ? await input.chooseToken?.(input.provider) : void 0;
22441
- let override;
22442
22460
  try {
22443
22461
  if (chosen?.environment) {
22444
- override = (await environmentToken({
22462
+ /* v8 ignore next -- the real importer reads installed plugin packages, which tests replace with `providerTokens` */
22463
+ const declared = await (input.providerTokens ?? defaultProviderTokens(input.loaded))(input.provider);
22464
+ const found = await environmentTokens({
22445
22465
  provider: input.provider,
22446
22466
  environment: chosen.environment,
22447
- repoRoot: context.repoRoot,
22467
+ repoRoot: input.context.repoRoot,
22448
22468
  configured: ownerEnvironments(input.loaded.resolved).names,
22449
22469
  vault: loader.has("vault") ? loader.get("vault") : void 0,
22450
- /* v8 ignore next -- the real importer reads installed plugin packages, which tests replace with `providerTokens` */
22451
- tokens: await (input.providerTokens ?? defaultProviderTokens(input.loaded))(input.provider)
22452
- })).token;
22470
+ tokens: declared
22471
+ });
22453
22472
  if (isEnvironmentLayer(chosen.environment)) layer = chosen.environment;
22454
- } else if (chosen?.token) override = chosen.token;
22473
+ steps.length = 0;
22474
+ for (const held of found.held) steps.push({
22475
+ context: {
22476
+ ...input.context,
22477
+ cliTokens: {
22478
+ ...input.context.cliTokens,
22479
+ [input.provider]: held.token
22480
+ }
22481
+ },
22482
+ heading: held.envName,
22483
+ args: ["--token-name", held.envName]
22484
+ });
22485
+ for (const name of found.missing) notHeld.push({
22486
+ name,
22487
+ fails: layer !== void 0 && tokenExpectations(declared, {
22488
+ layer,
22489
+ envName: name
22490
+ }).length > 0,
22491
+ environment: found.environment
22492
+ });
22493
+ } else if (chosen?.token) steps[0] = {
22494
+ context: {
22495
+ ...input.context,
22496
+ cliTokens: {
22497
+ ...input.context.cliTokens,
22498
+ [input.provider]: chosen.token
22499
+ }
22500
+ },
22501
+ args: []
22502
+ };
22455
22503
  } catch (err) {
22456
22504
  print(statusRow("fail", [`\`${input.provider} ${input.probe}\``, commandFailureMessage(err)]));
22457
22505
  return { status: "fail" };
22458
22506
  }
22459
- if (override !== void 0) {
22460
- context = {
22461
- ...context,
22462
- cliTokens: {
22463
- ...context.cliTokens,
22464
- [input.provider]: override
22465
- }
22466
- };
22467
- const reloaded = makeLoader(context);
22507
+ }
22508
+ const out = input.print ?? (probe.reportsTo === "stderr" ? (line) => console.error(line) : print);
22509
+ const statuses = [];
22510
+ for (const step of steps) {
22511
+ let stepProbe = probe;
22512
+ if (step.context !== input.context) {
22513
+ const reloaded = makeLoader(step.context);
22468
22514
  await reloaded.load();
22469
- probe = reloaded.probes().get(input.provider)?.[input.probe] ?? probe;
22515
+ stepProbe = reloaded.probes().get(input.provider)?.[input.probe] ?? probe;
22470
22516
  }
22517
+ const tokens = [step.context.cliToken, ...Object.values(step.context.cliTokens ?? {})].filter((t) => typeof t === "string");
22518
+ const report = await runProbe({
22519
+ name: `${input.provider} ${input.probe}`,
22520
+ provider: input.provider,
22521
+ probeName: input.probe,
22522
+ args: [
22523
+ ...input.args ?? [],
22524
+ ...layer ? ["--layer", layer] : [],
22525
+ ...step.args
22526
+ ],
22527
+ ...step.heading ? { heading: step.heading } : {},
22528
+ ...input.lcov ? { lcov: input.lcov } : {},
22529
+ probe: stepProbe,
22530
+ dryRun: input.dryRun ?? false,
22531
+ yes: input.yes ?? false,
22532
+ secrets: tokens,
22533
+ print: out,
22534
+ ...input.interactive !== void 0 ? { interactive: input.interactive } : {},
22535
+ ...input.confirm ? { confirm: input.confirm } : {},
22536
+ ...input.onInterrupt ? { onInterrupt: input.onInterrupt } : {}
22537
+ });
22538
+ statuses.push(report.status);
22471
22539
  }
22472
- const tokens = [context.cliToken, ...Object.values(context.cliTokens ?? {})].filter((t) => typeof t === "string");
22473
- return { status: (await runProbe({
22474
- name: `${input.provider} ${input.probe}`,
22475
- provider: input.provider,
22476
- probeName: input.probe,
22477
- args: [...input.args ?? [], ...layer ? ["--layer", layer] : []],
22478
- ...input.lcov ? { lcov: input.lcov } : {},
22479
- probe,
22480
- dryRun: input.dryRun ?? false,
22481
- yes: input.yes ?? false,
22482
- secrets: tokens,
22483
- print: input.print ?? (probe.reportsTo === "stderr" ? (line) => console.error(line) : print),
22484
- ...input.interactive !== void 0 ? { interactive: input.interactive } : {},
22485
- ...input.confirm ? { confirm: input.confirm } : {},
22486
- ...input.onInterrupt ? { onInterrupt: input.onInterrupt } : {}
22487
- })).status };
22540
+ for (const missing of notHeld) {
22541
+ out(`\n ${style.header(missing.name)}`);
22542
+ out(statusRow(missing.fails ? "fail" : "skip", [`not held in ${missing.environment}`]));
22543
+ if (missing.fails) statuses.push("fail");
22544
+ }
22545
+ return { status: ["fail", "cancelled"].find((s) => statuses.includes(s)) ?? "ok" };
22488
22546
  }
22489
22547
  // src/commands/probe/probe.command.ts
22490
22548
  const probeCommand = {