@theholocron/cli 5.0.0-alpha.425 → 5.0.0-alpha.427
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 +164 -21
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +14 -0
- package/package.json +10 -10
package/dist/cli.mjs
CHANGED
|
@@ -21,7 +21,7 @@ import { readGitRemote, updateGitignore, upsertManagedBlock } from "@theholocron
|
|
|
21
21
|
import { bumpCatalogPins, discoverWorkspacePackages, parseCatalogs, readPackageJson, readPackageJsonSync, resolveWorkspaceGlobs } from "@theholocron/pkg-utils";
|
|
22
22
|
import { createCliLogger, createCliTelemetry } from "@theholocron/kyber/observability";
|
|
23
23
|
import { resolveAxiomFromEnv } from "@theholocron/observability/logger";
|
|
24
|
-
import { Separator, checkbox, confirm, input, select } from "@inquirer/prompts";
|
|
24
|
+
import { Separator, checkbox, confirm, input, password, select } from "@inquirer/prompts";
|
|
25
25
|
import { runCheckAgainstUrl } from "@theholocron/kyber/checks";
|
|
26
26
|
import { access, copyFile, lstat, mkdir, open, readFile, readdir, realpath, rename, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
|
|
27
27
|
import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
|
|
@@ -19749,6 +19749,21 @@ const newCommand = {
|
|
|
19749
19749
|
handler: () => {}
|
|
19750
19750
|
};
|
|
19751
19751
|
// src/commands/probe/probe.args.ts
|
|
19752
|
+
/**
|
|
19753
|
+
* Shown in `holocron probe --help`: how a probe about a token (`cloudflare token`) picks the token it checks, so the
|
|
19754
|
+
* run itself prints only the result.
|
|
19755
|
+
*/
|
|
19756
|
+
const TOKEN_PROBE_HELP = [
|
|
19757
|
+
"Probes about a token (for example `holocron probe cloudflare token`) check one token. The first of these that applies picks it:",
|
|
19758
|
+
[
|
|
19759
|
+
"- --token <provider>=<value>: that token (a bare --token <value> goes to every provider).",
|
|
19760
|
+
"- --environment <layer or name>: the provider's token, read from that vault Environment.",
|
|
19761
|
+
"- On a terminal, with neither: a question, which asks for the configured token, an Environment or a pasted token.",
|
|
19762
|
+
"- Otherwise: the token the provider normally resolves."
|
|
19763
|
+
].join("\n"),
|
|
19764
|
+
"--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.",
|
|
19765
|
+
"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."
|
|
19766
|
+
].join("\n\n");
|
|
19752
19767
|
const probeArgs = (y) => y.positional("provider", {
|
|
19753
19768
|
type: "string",
|
|
19754
19769
|
describe: "Which provider's probes (omit to list them all)"
|
|
@@ -19776,11 +19791,14 @@ const probeArgs = (y) => y.positional("provider", {
|
|
|
19776
19791
|
}).option("copy", {
|
|
19777
19792
|
type: "boolean",
|
|
19778
19793
|
describe: "`1password export-environment`: put the variables on the clipboard instead of a file"
|
|
19794
|
+
}).option("environment", {
|
|
19795
|
+
type: "string",
|
|
19796
|
+
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)"
|
|
19779
19797
|
}).option("yes", {
|
|
19780
19798
|
type: "boolean",
|
|
19781
19799
|
default: false,
|
|
19782
19800
|
describe: "Run a probe that changes things without asking first (required without a terminal)"
|
|
19783
|
-
});
|
|
19801
|
+
}).epilogue(TOKEN_PROBE_HELP);
|
|
19784
19802
|
// src/commands/probe/app-vault.ts
|
|
19785
19803
|
/**
|
|
19786
19804
|
* The vault of an app that carries its own `holocron.config` (`apps/comlink`, `apps/sentinel`): those configs govern where
|
|
@@ -21254,6 +21272,107 @@ function listProbes(groups) {
|
|
|
21254
21272
|
}
|
|
21255
21273
|
return lines;
|
|
21256
21274
|
}
|
|
21275
|
+
// src/commands/probe/probe-token/choose-token.ts
|
|
21276
|
+
/**
|
|
21277
|
+
* Asks which token a probe that accepts one should check: the configured one, one from an Environment, or one typed in
|
|
21278
|
+
* (hidden as it is typed). Only called on a terminal when neither `--token` nor `--environment` was given.
|
|
21279
|
+
*/
|
|
21280
|
+
async function chooseToken(provider) {
|
|
21281
|
+
const how = await select({
|
|
21282
|
+
message: `Which ${provider} token should it check?`,
|
|
21283
|
+
choices: [
|
|
21284
|
+
{
|
|
21285
|
+
name: "The one this repo is configured to use",
|
|
21286
|
+
value: "configured"
|
|
21287
|
+
},
|
|
21288
|
+
{
|
|
21289
|
+
name: "One from a vault Environment (a layer such as ci or dev, or a name)",
|
|
21290
|
+
value: "environment"
|
|
21291
|
+
},
|
|
21292
|
+
{
|
|
21293
|
+
name: "Type or paste a token",
|
|
21294
|
+
value: "paste"
|
|
21295
|
+
}
|
|
21296
|
+
]
|
|
21297
|
+
});
|
|
21298
|
+
if (how === "environment") return { environment: (await input({
|
|
21299
|
+
message: "Environment (layer or name):",
|
|
21300
|
+
default: "ci"
|
|
21301
|
+
})).trim() };
|
|
21302
|
+
if (how === "paste") return { token: (await password({
|
|
21303
|
+
message: `${provider} token:`,
|
|
21304
|
+
mask: "*"
|
|
21305
|
+
})).trim() };
|
|
21306
|
+
}
|
|
21307
|
+
// src/commands/probe/probe-token/default-provider-tokens.ts
|
|
21308
|
+
/**
|
|
21309
|
+
* Reads the tokens a provider's plugin lists (its module-level `tokens`), resolving the plugin package from the
|
|
21310
|
+
* directory of the config that was loaded so a `--cwd` run finds the plugins installed there.
|
|
21311
|
+
*/
|
|
21312
|
+
function defaultProviderTokens(loaded, importer = createDefaultImporter(dirname(loaded.filepath))) {
|
|
21313
|
+
return async (provider) => (await importer(resolvePluginPackage$1(provider))).tokens ?? [];
|
|
21314
|
+
}
|
|
21315
|
+
// src/commands/secrets-sync/resolve-environment-id/resolve-environment-id.ts
|
|
21316
|
+
/**
|
|
21317
|
+
* The vault Environment `holocron sync secrets <environmentId>` reads. A layer word (`local`, `dev`, `ci`, `prod`) is the
|
|
21318
|
+
* Environment of that layer of this repository, `<org/repo> - <layer>`; any other text is a literal Environment name.
|
|
21319
|
+
* A literal name wins only when it is not exactly a layer word, so an Environment that is itself called `prod` cannot be
|
|
21320
|
+
* addressed by that name (spec `tech-environment-layers`, #2069).
|
|
21321
|
+
*
|
|
21322
|
+
* @param id - The positional the user gave.
|
|
21323
|
+
* @param input - Where the repository is (its `origin` remote is read there), and optionally how to read it.
|
|
21324
|
+
* @throws {ConfigError} For a layer word when the remote cannot be read (the message names the `environment` option).
|
|
21325
|
+
*/
|
|
21326
|
+
async function resolveEnvironmentId(id, input) {
|
|
21327
|
+
if (!isEnvironmentLayer(id)) return id;
|
|
21328
|
+
return layerEnvironment(await repoSlug(input.repoRoot, input.gitExec), id);
|
|
21329
|
+
}
|
|
21330
|
+
// src/commands/probe/probe-token/environment-token.ts
|
|
21331
|
+
/**
|
|
21332
|
+
* The provider's API token as held in one vault Environment, read in memory. Only an Environment this repo uses is
|
|
21333
|
+
* read: a layer word (`local`, `dev`, `ci`, `prod`) is this repo's `<org/repo> - <layer>`, and any other text must be a
|
|
21334
|
+
* name the config already names (`configured`), so a probe cannot be pointed at an Environment the repo has nothing to
|
|
21335
|
+
* do with. `local` reads the way the CLI does, `- local` over `- dev`, and `- local` may be absent.
|
|
21336
|
+
*
|
|
21337
|
+
* The variables looked for are the ones the provider's plugin lists (`HOLOCRON_CLOUDFLARE_TOKEN`, then the vendor's own
|
|
21338
|
+
* `CLOUDFLARE_API_TOKEN`); the first that holds a value wins.
|
|
21339
|
+
*
|
|
21340
|
+
* @throws {Error} When the name is not one of this repo's, no vault that reads an Environment is configured, or the
|
|
21341
|
+
* Environment holds none of the variables.
|
|
21342
|
+
*/
|
|
21343
|
+
async function environmentToken(input) {
|
|
21344
|
+
if (!isEnvironmentLayer(input.environment) && !input.configured.includes(input.environment)) {
|
|
21345
|
+
const known = [...ENVIRONMENT_LAYERS, ...input.configured];
|
|
21346
|
+
throw new Error(`${input.environment} is not an Environment this repo's config names; use one of: ${known.join(", ")}`);
|
|
21347
|
+
}
|
|
21348
|
+
const read = input.vault?.readEnvironment?.bind(input.vault);
|
|
21349
|
+
if (!read) throw new Error("--environment needs a vault provider that can read an Environment (1Password); none is configured");
|
|
21350
|
+
const at = {
|
|
21351
|
+
repoRoot: input.repoRoot,
|
|
21352
|
+
gitExec: input.gitExec
|
|
21353
|
+
};
|
|
21354
|
+
const environment = await resolveEnvironmentId(input.environment, at);
|
|
21355
|
+
let values;
|
|
21356
|
+
if (input.environment === "local") {
|
|
21357
|
+
const dev = await read(await resolveEnvironmentId("dev", at));
|
|
21358
|
+
const local = await read(environment).catch(() => ({}));
|
|
21359
|
+
values = {
|
|
21360
|
+
...dev,
|
|
21361
|
+
...local
|
|
21362
|
+
};
|
|
21363
|
+
} else values = await read(environment);
|
|
21364
|
+
const names = input.tokens.flatMap((t) => [t.envName, ...t.vendorEnvName ? [t.vendorEnvName] : []]);
|
|
21365
|
+
if (names.length === 0) throw new Error(`the ${input.provider} plugin lists no token to look for`);
|
|
21366
|
+
for (const variable of names) {
|
|
21367
|
+
const token = values[variable];
|
|
21368
|
+
if (token) return {
|
|
21369
|
+
token,
|
|
21370
|
+
environment,
|
|
21371
|
+
variable
|
|
21372
|
+
};
|
|
21373
|
+
}
|
|
21374
|
+
throw new Error(`${environment} holds none of ${names.join(", ")}`);
|
|
21375
|
+
}
|
|
21257
21376
|
// src/commands/probe/references/clone-org.ts
|
|
21258
21377
|
const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
21259
21378
|
const MAX_FILE_BYTES = 5242880;
|
|
@@ -21843,7 +21962,8 @@ function tasksProbes(io, names = legacyReplacements()) {
|
|
|
21843
21962
|
async function runProbeCommand(input) {
|
|
21844
21963
|
const print = input.print ?? ((line) => console.log(line));
|
|
21845
21964
|
/* v8 ignore next -- the real loader is only built outside tests, which always inject one */
|
|
21846
|
-
const
|
|
21965
|
+
const makeLoader = input.makeLoader ?? ((context) => new PluginLoader(input.loaded.resolved, context));
|
|
21966
|
+
const loader = input.loader ?? makeLoader(input.context);
|
|
21847
21967
|
await loader.load();
|
|
21848
21968
|
const groups = new Map(loader.probes());
|
|
21849
21969
|
const comlink = comlinkProbes({
|
|
@@ -21872,17 +21992,53 @@ async function runProbeCommand(input) {
|
|
|
21872
21992
|
for (const line of listProbes(/* @__PURE__ */ new Map([[input.provider, probes]]))) print(line);
|
|
21873
21993
|
return { status: "listed" };
|
|
21874
21994
|
}
|
|
21875
|
-
|
|
21995
|
+
let probe = probes[input.probe];
|
|
21876
21996
|
if (!probe) {
|
|
21877
21997
|
print(statusRow("fail", [`\`${input.provider}\` has no probe \`${input.probe}\``, `try: ${Object.keys(probes).sort().join(", ")}`]));
|
|
21878
21998
|
return { status: "fail" };
|
|
21879
21999
|
}
|
|
21880
|
-
|
|
22000
|
+
let context = input.context;
|
|
22001
|
+
let layer;
|
|
22002
|
+
if (probe.acceptsToken) {
|
|
22003
|
+
const given = context.cliTokens?.[input.provider] ?? context.cliToken;
|
|
22004
|
+
const chosen = input.environment ? { environment: input.environment } : given === void 0 ? await input.chooseToken?.(input.provider) : void 0;
|
|
22005
|
+
let override;
|
|
22006
|
+
try {
|
|
22007
|
+
if (chosen?.environment) {
|
|
22008
|
+
override = (await environmentToken({
|
|
22009
|
+
provider: input.provider,
|
|
22010
|
+
environment: chosen.environment,
|
|
22011
|
+
repoRoot: context.repoRoot,
|
|
22012
|
+
configured: ownerEnvironments(input.loaded.resolved).names,
|
|
22013
|
+
vault: loader.has("vault") ? loader.get("vault") : void 0,
|
|
22014
|
+
/* v8 ignore next -- the real importer reads installed plugin packages, which tests replace with `providerTokens` */
|
|
22015
|
+
tokens: await (input.providerTokens ?? defaultProviderTokens(input.loaded))(input.provider)
|
|
22016
|
+
})).token;
|
|
22017
|
+
if (isEnvironmentLayer(chosen.environment)) layer = chosen.environment;
|
|
22018
|
+
} else if (chosen?.token) override = chosen.token;
|
|
22019
|
+
} catch (err) {
|
|
22020
|
+
print(statusRow("fail", [`\`${input.provider} ${input.probe}\``, commandFailureMessage(err)]));
|
|
22021
|
+
return { status: "fail" };
|
|
22022
|
+
}
|
|
22023
|
+
if (override !== void 0) {
|
|
22024
|
+
context = {
|
|
22025
|
+
...context,
|
|
22026
|
+
cliTokens: {
|
|
22027
|
+
...context.cliTokens,
|
|
22028
|
+
[input.provider]: override
|
|
22029
|
+
}
|
|
22030
|
+
};
|
|
22031
|
+
const reloaded = makeLoader(context);
|
|
22032
|
+
await reloaded.load();
|
|
22033
|
+
probe = reloaded.probes().get(input.provider)?.[input.probe] ?? probe;
|
|
22034
|
+
}
|
|
22035
|
+
}
|
|
22036
|
+
const tokens = [context.cliToken, ...Object.values(context.cliTokens ?? {})].filter((t) => typeof t === "string");
|
|
21881
22037
|
return { status: (await runProbe({
|
|
21882
22038
|
name: `${input.provider} ${input.probe}`,
|
|
21883
22039
|
provider: input.provider,
|
|
21884
22040
|
probeName: input.probe,
|
|
21885
|
-
args: input.args ?? [],
|
|
22041
|
+
args: [...input.args ?? [], ...layer ? ["--layer", layer] : []],
|
|
21886
22042
|
...input.lcov ? { lcov: input.lcov } : {},
|
|
21887
22043
|
probe,
|
|
21888
22044
|
dryRun: input.dryRun ?? false,
|
|
@@ -21925,6 +22081,8 @@ const probeCommand = {
|
|
|
21925
22081
|
...argv.lcov ? { lcov: argv.lcov } : {},
|
|
21926
22082
|
dryRun: argv.dryRun,
|
|
21927
22083
|
yes: argv.yes,
|
|
22084
|
+
...argv.environment ? { environment: argv.environment } : {},
|
|
22085
|
+
...process.stdin.isTTY ? { chooseToken } : {},
|
|
21928
22086
|
...process.stdin.isTTY ? { pick: (groups) => launchMenu(buildProbeMenuEntries(groups), argv, {
|
|
21929
22087
|
pickMessage: "probe — choose a provider:",
|
|
21930
22088
|
nonInteractiveMessage: "Run `holocron probe` to list the probes.",
|
|
@@ -24106,21 +24264,6 @@ const notificationsSyncRolesCommand = {
|
|
|
24106
24264
|
})).status === "fail") process.exitCode = 1;
|
|
24107
24265
|
}
|
|
24108
24266
|
};
|
|
24109
|
-
// src/commands/secrets-sync/resolve-environment-id/resolve-environment-id.ts
|
|
24110
|
-
/**
|
|
24111
|
-
* The vault Environment `holocron sync secrets <environmentId>` reads. A layer word (`local`, `dev`, `ci`, `prod`) is the
|
|
24112
|
-
* Environment of that layer of this repository, `<org/repo> - <layer>`; any other text is a literal Environment name.
|
|
24113
|
-
* A literal name wins only when it is not exactly a layer word, so an Environment that is itself called `prod` cannot be
|
|
24114
|
-
* addressed by that name (spec `tech-environment-layers`, #2069).
|
|
24115
|
-
*
|
|
24116
|
-
* @param id - The positional the user gave.
|
|
24117
|
-
* @param input - Where the repository is (its `origin` remote is read there), and optionally how to read it.
|
|
24118
|
-
* @throws {ConfigError} For a layer word when the remote cannot be read (the message names the `environment` option).
|
|
24119
|
-
*/
|
|
24120
|
-
async function resolveEnvironmentId(id, input) {
|
|
24121
|
-
if (!isEnvironmentLayer(id)) return id;
|
|
24122
|
-
return layerEnvironment(await repoSlug(input.repoRoot, input.gitExec), id);
|
|
24123
|
-
}
|
|
24124
24267
|
// src/commands/secrets-sync/secret-routes.ts
|
|
24125
24268
|
/**
|
|
24126
24269
|
* The routes into `secrets` that `repo.secrets.sync` declares for one vault environment: every entry naming it gives
|