@theholocron/cli 5.0.0-alpha.431 → 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 +151 -85
- package/dist/cli.mjs.map +1 -1
- package/package.json +10 -10
package/dist/cli.mjs
CHANGED
|
@@ -12120,6 +12120,14 @@ async function matrixPlaces(input) {
|
|
|
12120
12120
|
environment
|
|
12121
12121
|
});
|
|
12122
12122
|
}
|
|
12123
|
+
const listedVariables = (environment) => new Set(variableEntries.filter((entry) => resolvedEnvironment(entry) === environment).flatMap((entry) => entry.keys.map((name) => name.toUpperCase())));
|
|
12124
|
+
const ownNames = (kind, environment, present, needed) => {
|
|
12125
|
+
if (!envs.has(`${kind === "secret" ? "variable" : "secret"}:${environment}`)) return present;
|
|
12126
|
+
const variables = listedVariables(environment);
|
|
12127
|
+
if (kind === "variable") return present.filter((name) => variables.has(name.toUpperCase()));
|
|
12128
|
+
const wanted = new Set(needed.map((name) => name.toUpperCase()));
|
|
12129
|
+
return present.filter((name) => !variables.has(name.toUpperCase()) || wanted.has(name.toUpperCase()));
|
|
12130
|
+
};
|
|
12123
12131
|
for (const { kind, env, environment } of envs.values()) {
|
|
12124
12132
|
if (!wants(env)) continue;
|
|
12125
12133
|
const found = await namesOf(environment);
|
|
@@ -12156,7 +12164,7 @@ async function matrixPlaces(input) {
|
|
|
12156
12164
|
kind,
|
|
12157
12165
|
needed,
|
|
12158
12166
|
reasons,
|
|
12159
|
-
...Array.isArray(found) ? { present } : { unread: found.why }
|
|
12167
|
+
...Array.isArray(found) ? { present: ownNames(kind, environment, present, needed) } : { unread: found.why }
|
|
12160
12168
|
});
|
|
12161
12169
|
}
|
|
12162
12170
|
if (wants("prod")) for (const environment of new Set(deployEntries.map(resolvedEnvironment))) {
|
|
@@ -19966,15 +19974,15 @@ const newCommand = {
|
|
|
19966
19974
|
* run itself prints only the result.
|
|
19967
19975
|
*/
|
|
19968
19976
|
const TOKEN_PROBE_HELP = [
|
|
19969
|
-
"Probes about a token (for example `holocron probe cloudflare token`) check
|
|
19977
|
+
"Probes about a token (for example `holocron probe cloudflare token`) check a token. The first of these that applies picks it:",
|
|
19970
19978
|
[
|
|
19971
19979
|
"- --token <provider>=<value>: that token (a bare --token <value> goes to every provider).",
|
|
19972
|
-
"- --environment <layer or name>: the provider
|
|
19980
|
+
"- --environment <layer or name>: every token the provider declares that the vault Environment holds, one after another, each under its variable name.",
|
|
19973
19981
|
"- On a terminal, with neither: a question, which asks for the configured token, an Environment or a pasted token.",
|
|
19974
19982
|
"- Otherwise: the token the provider normally resolves."
|
|
19975
19983
|
].join("\n"),
|
|
19976
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.",
|
|
19977
|
-
"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.
|
|
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."
|
|
19978
19986
|
].join("\n\n");
|
|
19979
19987
|
const probeArgs = (y) => y.positional("provider", {
|
|
19980
19988
|
type: "string",
|
|
@@ -20005,7 +20013,7 @@ const probeArgs = (y) => y.positional("provider", {
|
|
|
20005
20013
|
describe: "`1password export-environment`: put the variables on the clipboard instead of a file"
|
|
20006
20014
|
}).option("environment", {
|
|
20007
20015
|
type: "string",
|
|
20008
|
-
describe: "A probe about a token (`cloudflare token`): check the provider
|
|
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)"
|
|
20009
20017
|
}).option("yes", {
|
|
20010
20018
|
type: "boolean",
|
|
20011
20019
|
default: false,
|
|
@@ -20032,6 +20040,33 @@ function ownerEnvironments(config) {
|
|
|
20032
20040
|
instances
|
|
20033
20041
|
};
|
|
20034
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
|
+
}
|
|
20035
20070
|
// src/commands/probe/app-vault.ts
|
|
20036
20071
|
/**
|
|
20037
20072
|
* The vault of an app that carries its own `holocron.config` (`apps/comlink`, `apps/sentinel`): those configs govern where
|
|
@@ -20815,33 +20850,6 @@ function realDocsPresenceIo(repoRoot) {
|
|
|
20815
20850
|
};
|
|
20816
20851
|
/* v8 ignore stop */
|
|
20817
20852
|
}
|
|
20818
|
-
// src/commands/token-expectations/token-expectations.ts
|
|
20819
|
-
/**
|
|
20820
|
-
* Reads what a plugin's tokens declare (`PluginToken.expect`) as one entry per token and layer that holds it, in the
|
|
20821
|
-
* order of `ENVIRONMENT_LAYERS`. The one reader the token probes, the doctor and the docs check share, so none of them
|
|
20822
|
-
* walks the declaration itself. A token with no `expect` yields nothing; a layer no token holds is never listed.
|
|
20823
|
-
*/
|
|
20824
|
-
function tokenExpectations(tokens, filter = {}) {
|
|
20825
|
-
const found = [];
|
|
20826
|
-
for (const token of tokens) {
|
|
20827
|
-
if (!token.expect || filter.envName !== void 0 && token.envName !== filter.envName) continue;
|
|
20828
|
-
const { layers = [], permissions = {} } = token.expect;
|
|
20829
|
-
for (const layer of ENVIRONMENT_LAYERS) {
|
|
20830
|
-
if (filter.layer !== void 0 && filter.layer !== layer) continue;
|
|
20831
|
-
const rules = permissions[layer];
|
|
20832
|
-
if (!rules && !layers.includes(layer)) continue;
|
|
20833
|
-
const entries = Object.entries(rules ?? {});
|
|
20834
|
-
found.push({
|
|
20835
|
-
envName: token.envName,
|
|
20836
|
-
layer,
|
|
20837
|
-
rules: rules ?? {},
|
|
20838
|
-
required: entries.filter(([, rule]) => rule === "required").map(([name]) => name),
|
|
20839
|
-
absent: entries.filter(([, rule]) => rule === "absent").map(([name]) => name)
|
|
20840
|
-
});
|
|
20841
|
-
}
|
|
20842
|
-
}
|
|
20843
|
-
return found;
|
|
20844
|
-
}
|
|
20845
20853
|
// src/commands/probe/docs-tokens/compare-permissions/compare-permissions.ts
|
|
20846
20854
|
const mentions = (heading, name) => heading.toLowerCase().includes(name.toLowerCase());
|
|
20847
20855
|
/**
|
|
@@ -21755,20 +21763,21 @@ async function resolveEnvironmentId(id, input) {
|
|
|
21755
21763
|
if (!isEnvironmentLayer(id)) return id;
|
|
21756
21764
|
return layerEnvironment(await repoSlug(input.repoRoot, input.gitExec), id);
|
|
21757
21765
|
}
|
|
21758
|
-
// src/commands/probe/probe-token/environment-
|
|
21766
|
+
// src/commands/probe/probe-token/environment-tokens.ts
|
|
21759
21767
|
/**
|
|
21760
|
-
*
|
|
21768
|
+
* Every token the provider declares that one vault Environment holds, read in memory. Only an Environment this repo uses is
|
|
21761
21769
|
* read: a layer word (`local`, `dev`, `ci`, `prod`) is this repo's `<org/repo> - <layer>`, and any other text must be a
|
|
21762
21770
|
* name the config already names (`configured`), so a probe cannot be pointed at an Environment the repo has nothing to
|
|
21763
21771
|
* do with. `local` reads the way the CLI does, `- local` over `- dev`, and `- local` may be absent.
|
|
21764
21772
|
*
|
|
21765
|
-
*
|
|
21766
|
-
* `
|
|
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.
|
|
21767
21776
|
*
|
|
21768
|
-
* @throws {Error} When the name is not one of this repo's, no vault that reads an Environment is configured,
|
|
21769
|
-
* Environment holds none of
|
|
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.
|
|
21770
21779
|
*/
|
|
21771
|
-
async function
|
|
21780
|
+
async function environmentTokens(input) {
|
|
21772
21781
|
if (!isEnvironmentLayer(input.environment) && !input.configured.includes(input.environment)) {
|
|
21773
21782
|
const known = [...ENVIRONMENT_LAYERS, ...input.configured];
|
|
21774
21783
|
throw new Error(`${input.environment} is not an Environment this repo's config names; use one of: ${known.join(", ")}`);
|
|
@@ -21789,17 +21798,27 @@ async function environmentToken(input) {
|
|
|
21789
21798
|
...local
|
|
21790
21799
|
};
|
|
21791
21800
|
} else values = await read(environment);
|
|
21792
|
-
|
|
21793
|
-
|
|
21794
|
-
|
|
21795
|
-
|
|
21796
|
-
|
|
21797
|
-
|
|
21798
|
-
|
|
21799
|
-
variable
|
|
21800
|
-
|
|
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);
|
|
21801
21812
|
}
|
|
21802
|
-
|
|
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(", ")}`);
|
|
21816
|
+
}
|
|
21817
|
+
return {
|
|
21818
|
+
environment,
|
|
21819
|
+
held,
|
|
21820
|
+
missing
|
|
21821
|
+
};
|
|
21803
21822
|
}
|
|
21804
21823
|
// src/commands/probe/references/clone-org.ts
|
|
21805
21824
|
const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
@@ -22031,6 +22050,10 @@ async function runProbe(input) {
|
|
|
22031
22050
|
if (clean.status === "heading") print(`\n ${style.header(clean.label)}`);
|
|
22032
22051
|
else print(statusRow(clean.status === "info" ? "skip" : clean.status, [clean.label, clean.detail ?? ""]));
|
|
22033
22052
|
};
|
|
22053
|
+
if (input.heading) emit({
|
|
22054
|
+
status: "heading",
|
|
22055
|
+
label: input.heading
|
|
22056
|
+
});
|
|
22034
22057
|
if (input.probe.writes && !input.dryRun && !input.yes) {
|
|
22035
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`);
|
|
22036
22059
|
if (!await (input.confirm ?? ((message) => confirm({
|
|
@@ -22420,63 +22443,106 @@ async function runProbeCommand(input) {
|
|
|
22420
22443
|
for (const line of listProbes(/* @__PURE__ */ new Map([[input.provider, probes]]))) print(line);
|
|
22421
22444
|
return { status: "listed" };
|
|
22422
22445
|
}
|
|
22423
|
-
|
|
22446
|
+
const probe = probes[input.probe];
|
|
22424
22447
|
if (!probe) {
|
|
22425
22448
|
print(statusRow("fail", [`\`${input.provider}\` has no probe \`${input.probe}\``, `try: ${Object.keys(probes).sort().join(", ")}`]));
|
|
22426
22449
|
return { status: "fail" };
|
|
22427
22450
|
}
|
|
22428
|
-
let context = input.context;
|
|
22429
22451
|
let layer;
|
|
22452
|
+
const steps = [{
|
|
22453
|
+
context: input.context,
|
|
22454
|
+
args: []
|
|
22455
|
+
}];
|
|
22456
|
+
const notHeld = [];
|
|
22430
22457
|
if (probe.acceptsToken) {
|
|
22431
|
-
const given = context.cliTokens?.[input.provider] ?? context.cliToken;
|
|
22458
|
+
const given = input.context.cliTokens?.[input.provider] ?? input.context.cliToken;
|
|
22432
22459
|
const chosen = input.environment ? { environment: input.environment } : given === void 0 ? await input.chooseToken?.(input.provider) : void 0;
|
|
22433
|
-
let override;
|
|
22434
22460
|
try {
|
|
22435
22461
|
if (chosen?.environment) {
|
|
22436
|
-
|
|
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({
|
|
22437
22465
|
provider: input.provider,
|
|
22438
22466
|
environment: chosen.environment,
|
|
22439
|
-
repoRoot: context.repoRoot,
|
|
22467
|
+
repoRoot: input.context.repoRoot,
|
|
22440
22468
|
configured: ownerEnvironments(input.loaded.resolved).names,
|
|
22441
22469
|
vault: loader.has("vault") ? loader.get("vault") : void 0,
|
|
22442
|
-
|
|
22443
|
-
|
|
22444
|
-
})).token;
|
|
22470
|
+
tokens: declared
|
|
22471
|
+
});
|
|
22445
22472
|
if (isEnvironmentLayer(chosen.environment)) layer = chosen.environment;
|
|
22446
|
-
|
|
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
|
+
};
|
|
22447
22503
|
} catch (err) {
|
|
22448
22504
|
print(statusRow("fail", [`\`${input.provider} ${input.probe}\``, commandFailureMessage(err)]));
|
|
22449
22505
|
return { status: "fail" };
|
|
22450
22506
|
}
|
|
22451
|
-
|
|
22452
|
-
|
|
22453
|
-
|
|
22454
|
-
|
|
22455
|
-
|
|
22456
|
-
|
|
22457
|
-
|
|
22458
|
-
};
|
|
22459
|
-
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);
|
|
22460
22514
|
await reloaded.load();
|
|
22461
|
-
|
|
22515
|
+
stepProbe = reloaded.probes().get(input.provider)?.[input.probe] ?? probe;
|
|
22462
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);
|
|
22463
22539
|
}
|
|
22464
|
-
const
|
|
22465
|
-
|
|
22466
|
-
|
|
22467
|
-
|
|
22468
|
-
|
|
22469
|
-
|
|
22470
|
-
...input.lcov ? { lcov: input.lcov } : {},
|
|
22471
|
-
probe,
|
|
22472
|
-
dryRun: input.dryRun ?? false,
|
|
22473
|
-
yes: input.yes ?? false,
|
|
22474
|
-
secrets: tokens,
|
|
22475
|
-
print: input.print ?? (probe.reportsTo === "stderr" ? (line) => console.error(line) : print),
|
|
22476
|
-
...input.interactive !== void 0 ? { interactive: input.interactive } : {},
|
|
22477
|
-
...input.confirm ? { confirm: input.confirm } : {},
|
|
22478
|
-
...input.onInterrupt ? { onInterrupt: input.onInterrupt } : {}
|
|
22479
|
-
})).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" };
|
|
22480
22546
|
}
|
|
22481
22547
|
// src/commands/probe/probe.command.ts
|
|
22482
22548
|
const probeCommand = {
|