@theholocron/cli 5.0.0-alpha.443 → 5.0.0-alpha.445

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
@@ -13276,7 +13276,8 @@ var HoldsNoTokenError = class extends Error {
13276
13276
  *
13277
13277
  * Each token the provider's plugin lists is looked for under its own variable (`HOLOCRON_SENTRY_TOKEN`), then the
13278
13278
  * vendor's (`vendorEnvName`); the first that holds a value is that token's. A token the Environment does not hold is in
13279
- * `missing`, so the caller can report it by name.
13279
+ * `missing`, so the caller can report it by name. The Environment's other visible (not concealed) values come back as
13280
+ * `plain`, for the plugin's own settings (a dataset, an account id); a vault that cannot say which are visible gives none.
13280
13281
  *
13281
13282
  * @throws {Error} When the name is not one of this repo's, no vault that reads an Environment is configured, the plugin
13282
13283
  * lists no token, or the Environment holds none of them.
@@ -13293,15 +13294,35 @@ async function environmentTokens(input) {
13293
13294
  gitExec: input.gitExec
13294
13295
  };
13295
13296
  const environment = await resolveEnvironmentId(input.environment, at);
13297
+ const readEntries = input.vault?.readEnvironmentEntries?.bind(input.vault);
13298
+ const readOne = async (id) => {
13299
+ if (!readEntries) return {
13300
+ values: await read(id),
13301
+ plain: {}
13302
+ };
13303
+ const entries = await readEntries(id);
13304
+ return {
13305
+ values: Object.fromEntries(entries.map((e) => [e.name, e.value])),
13306
+ plain: Object.fromEntries(entries.filter((e) => !e.concealed).map((e) => [e.name, e.value]))
13307
+ };
13308
+ };
13296
13309
  let values;
13310
+ let plain;
13297
13311
  if (input.environment === "local") {
13298
- const dev = await read(await resolveEnvironmentId("dev", at));
13299
- const local = await read(environment).catch(() => ({}));
13312
+ const dev = await readOne(await resolveEnvironmentId("dev", at));
13313
+ const local = await readOne(environment).catch(() => ({
13314
+ values: {},
13315
+ plain: {}
13316
+ }));
13300
13317
  values = {
13301
- ...dev,
13302
- ...local
13318
+ ...dev.values,
13319
+ ...local.values
13320
+ };
13321
+ plain = {
13322
+ ...dev.plain,
13323
+ ...local.plain
13303
13324
  };
13304
- } else values = await read(environment);
13325
+ } else ({values, plain} = await readOne(environment));
13305
13326
  if (input.tokens.length === 0) throw new Error(`the ${input.provider} plugin lists no token to look for`);
13306
13327
  const held = [];
13307
13328
  const missing = [];
@@ -13315,12 +13336,40 @@ async function environmentTokens(input) {
13315
13336
  else missing.push(declared.envName);
13316
13337
  }
13317
13338
  if (held.length === 0) throw new HoldsNoTokenError(`${environment} holds none of ${input.tokens.flatMap((t) => [t.envName, ...t.vendorEnvName ? [t.vendorEnvName] : []]).join(", ")}`);
13339
+ for (const declared of input.tokens) {
13340
+ delete plain[declared.envName];
13341
+ if (declared.vendorEnvName) delete plain[declared.vendorEnvName];
13342
+ }
13318
13343
  return {
13319
13344
  environment,
13320
13345
  held,
13321
- missing
13346
+ missing,
13347
+ plain
13322
13348
  };
13323
13349
  }
13350
+ // src/commands/probe/probe-token/with-environment-values/with-environment-values.ts
13351
+ /**
13352
+ * Runs `run` with `values` set in `process.env`, then puts every name back as it was (set again, or removed), even when
13353
+ * `run` throws. It is how a probe that reads another Environment sees that Environment's plain values ahead of the
13354
+ * machine's own: a plugin reads them through the usual chain, which looks at the process environment first, and the
13355
+ * overlay lives only for the one run. Nothing is written anywhere and the values are never printed.
13356
+ *
13357
+ * @param values - The variables to set for the run; none means `run` is called as it is.
13358
+ * @param run - The work that should see them.
13359
+ * @returns What `run` returns.
13360
+ */
13361
+ async function withEnvironmentValues(values, run) {
13362
+ const names = Object.keys(values ?? {});
13363
+ if (!values || names.length === 0) return run();
13364
+ const before = new Map(names.map((name) => [name, process.env[name]]));
13365
+ for (const name of names) process.env[name] = values[name];
13366
+ try {
13367
+ return await run();
13368
+ } finally {
13369
+ for (const [name, previous] of before) if (previous === void 0) delete process.env[name];
13370
+ else process.env[name] = previous;
13371
+ }
13372
+ }
13324
13373
  // src/commands/probe/scrub.ts
13325
13374
  const HIDDEN = "«hidden»";
13326
13375
  /** Shapes that are credentials wherever they appear: a Discord webhook URL, a bearer header, a Sentry token. */
@@ -20784,7 +20833,7 @@ const TOKEN_PROBE_HELP = [
20784
20833
  "- Otherwise: the token the provider normally resolves."
20785
20834
  ].join("\n"),
20786
20835
  "--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.",
20787
- "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."
20836
+ "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. The Environment also supplies the plugin's own visible (not concealed) values for the run, such as a dataset or an account id, ahead of this machine's; what it does not hold comes from the machine as usual. A token or a value is never printed."
20788
20837
  ].join("\n\n");
20789
20838
  const probeArgs = (y) => y.positional("provider", {
20790
20839
  type: "string",
@@ -20815,7 +20864,7 @@ const probeArgs = (y) => y.positional("provider", {
20815
20864
  describe: "`1password export-environment`: put the variables on the clipboard instead of a file"
20816
20865
  }).option("environment", {
20817
20866
  type: "string",
20818
- 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)"
20867
+ 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), with its visible values (a dataset, an account id) used first"
20819
20868
  }).option("yes", {
20820
20869
  type: "boolean",
20821
20870
  default: false,
@@ -22983,7 +23032,8 @@ async function runProbeCommand(input) {
22983
23032
  }
22984
23033
  },
22985
23034
  heading: held.envName,
22986
- args: ["--token-name", held.envName]
23035
+ args: ["--token-name", held.envName],
23036
+ values: found.plain
22987
23037
  });
22988
23038
  for (const name of found.missing) notHeld.push({
22989
23039
  name,
@@ -23010,33 +23060,36 @@ async function runProbeCommand(input) {
23010
23060
  }
23011
23061
  const out = input.print ?? (probe.reportsTo === "stderr" ? (line) => console.error(line) : print);
23012
23062
  const statuses = [];
23063
+ const { provider, probe: probeName } = input;
23013
23064
  for (const step of steps) {
23014
- let stepProbe = probe;
23015
- if (step.context !== input.context) {
23016
- const reloaded = makeLoader(step.context);
23017
- await reloaded.load();
23018
- stepProbe = reloaded.probes().get(input.provider)?.[input.probe] ?? probe;
23019
- }
23020
- const tokens = [step.context.cliToken, ...Object.values(step.context.cliTokens ?? {})].filter((t) => typeof t === "string");
23021
- const report = await runProbe({
23022
- name: `${input.provider} ${input.probe}`,
23023
- provider: input.provider,
23024
- probeName: input.probe,
23025
- args: [
23026
- ...input.args ?? [],
23027
- ...layer ? ["--layer", layer] : [],
23028
- ...step.args
23029
- ],
23030
- ...step.heading ? { heading: step.heading } : {},
23031
- ...input.lcov ? { lcov: input.lcov } : {},
23032
- probe: stepProbe,
23033
- dryRun: input.dryRun ?? false,
23034
- yes: input.yes ?? false,
23035
- secrets: tokens,
23036
- print: out,
23037
- ...input.interactive !== void 0 ? { interactive: input.interactive } : {},
23038
- ...input.confirm ? { confirm: input.confirm } : {},
23039
- ...input.onInterrupt ? { onInterrupt: input.onInterrupt } : {}
23065
+ const report = await withEnvironmentValues(step.values, async () => {
23066
+ let stepProbe = probe;
23067
+ if (step.context !== input.context) {
23068
+ const reloaded = makeLoader(step.context);
23069
+ await reloaded.load();
23070
+ stepProbe = reloaded.probes().get(provider)?.[probeName] ?? probe;
23071
+ }
23072
+ const tokens = [step.context.cliToken, ...Object.values(step.context.cliTokens ?? {})].filter((t) => typeof t === "string");
23073
+ return runProbe({
23074
+ name: `${provider} ${probeName}`,
23075
+ provider,
23076
+ probeName,
23077
+ args: [
23078
+ ...input.args ?? [],
23079
+ ...layer ? ["--layer", layer] : [],
23080
+ ...step.args
23081
+ ],
23082
+ ...step.heading ? { heading: step.heading } : {},
23083
+ ...input.lcov ? { lcov: input.lcov } : {},
23084
+ probe: stepProbe,
23085
+ dryRun: input.dryRun ?? false,
23086
+ yes: input.yes ?? false,
23087
+ secrets: tokens,
23088
+ print: out,
23089
+ ...input.interactive !== void 0 ? { interactive: input.interactive } : {},
23090
+ ...input.confirm ? { confirm: input.confirm } : {},
23091
+ ...input.onInterrupt ? { onInterrupt: input.onInterrupt } : {}
23092
+ });
23040
23093
  });
23041
23094
  statuses.push(report.status);
23042
23095
  }