@theholocron/cli 5.0.0-alpha.366 → 5.0.0-alpha.368

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
@@ -3,7 +3,7 @@ import { createRequire } from "node:module";
3
3
  import { copyFileSync, existsSync, fstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
4
4
  import { homedir, tmpdir } from "node:os";
5
5
  import path, { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
6
- import { createEnvLookup, firstEnv, withEnvPrefix } from "@theholocron/env-utils/lookup";
6
+ import { PREFIX, createEnvLookup, firstEnv, holocronEnv } from "@theholocron/env-utils/lookup";
7
7
  import { ProviderApiError, ProviderApiError as ProviderApiError$1, createRestClient, onRetry } from "@theholocron/http-client";
8
8
  import { addGlobalOptions, groupMenu, tokenContext } from "@theholocron/kyber/flags";
9
9
  import { checkForUpdates } from "@theholocron/kyber/notifier";
@@ -803,15 +803,12 @@ function commandsInContext(context) {
803
803
  * traces, errors, structured context that routes to Axiom. It runs in
804
804
  * parallel to `print` (user-facing UX output) and does not replace it.
805
805
  */
806
- const env$9 = createEnvLookup();
807
- /** The one definition of the CLI's variable prefix: `HOLOCRON_<NAME>` is tried before the bare `<NAME>`. */
808
- const PREFIX$1 = "HOLOCRON";
809
- const holocronEnv$1 = withEnvPrefix(env$9, PREFIX$1);
806
+ const env$10 = createEnvLookup();
807
+ const holocron = holocronEnv();
810
808
  /**
811
809
  * The CLI's Axiom dataset (`holocron`; each service has its own): the process environment (`HOLOCRON_AXIOM_DATASET`, then the unprefixed `AXIOM_DATASET`,
812
810
  * through the prefix lookup), then the repo's `log.axiom.dataset`, then the credential chain, which is asked for the
813
- * same pair of names. `resolveValue` takes a plain list of names, so the pair is built from {@link PREFIX} instead of
814
- * adding a prefix option to kyber for one caller.
811
+ * same pair of names through `resolveValue`'s `prefix` option.
815
812
  *
816
813
  * A service's environments ship to the same dataset and are told apart by the `env` field on each line (ADR-0019). The
817
814
  * config dataset is only a per-repo override, so a `global`-context command (`clone`, `auth set`, `upgrade node`, ...,
@@ -819,7 +816,7 @@ const holocronEnv$1 = withEnvPrefix(env$9, PREFIX$1);
819
816
  * lines go.
820
817
  */
821
818
  function resolveCliDataset(opts, isGlobal) {
822
- return holocronEnv$1.get("AXIOM_DATASET") ?? (isGlobal ? void 0 : opts.configAxiomDataset) ?? resolveValue$2([`${PREFIX$1}_AXIOM_DATASET`, "AXIOM_DATASET"]);
819
+ return holocron.get("AXIOM_DATASET") ?? (isGlobal ? void 0 : opts.configAxiomDataset) ?? resolveValue$2(["AXIOM_DATASET"], void 0, { prefix: PREFIX });
823
820
  }
824
821
  /**
825
822
  * Resolve Axiom credentials for the CLI.
@@ -834,15 +831,15 @@ function resolveCliAxiom(opts, ctx) {
834
831
  if (fromEnv) return fromEnv;
835
832
  const dataset = resolveCliDataset(opts, contextForCommand(ctx.command ?? "") === "global");
836
833
  if (!dataset) return void 0;
837
- const org = opts.org ?? env$9.get(`${PREFIX$1}_ORG`);
838
- const token = holocronEnv$1.get("AXIOM_TOKEN") || (org ? keyring.get(`axiom.${org}`) : null) || keyring.get("axiom");
834
+ const org = opts.org ?? env$10.get(`${PREFIX}_ORG`);
835
+ const token = holocron.get("AXIOM_TOKEN") || (org ? keyring.get(`axiom.${org}`) : null) || keyring.get("axiom");
839
836
  return token ? {
840
837
  dataset,
841
838
  token
842
839
  } : void 0;
843
840
  }
844
841
  const logger = createCliLogger({
845
- envPrefix: PREFIX$1,
842
+ envPrefix: PREFIX,
846
843
  resolveAxiom: resolveCliAxiom
847
844
  });
848
845
  /**
@@ -860,7 +857,7 @@ const getRunId = logger.getRunId;
860
857
  logger.resetCliLogger;
861
858
  logger.resolveLogLevel;
862
859
  // src/observability/resolve-telemetry/resolve-telemetry.ts
863
- const holocronEnv = withEnvPrefix(createEnvLookup(), "HOLOCRON");
860
+ const env$9 = holocronEnv();
864
861
  /**
865
862
  * Holocron-specific credential resolution for the telemetry sinks — the env
866
863
  * chain plus Holocron's own shipped fallbacks. This is **CLI policy**, not part
@@ -884,15 +881,15 @@ const FALLBACK_POSTHOG_PROJECT_TOKEN = "phc_AC4vFCvYzwnzmG7Vg5nEc3PZKZztoPyfKp4L
884
881
  const DEFAULT_POSTHOG_HOST = "https://us.i.posthog.com";
885
882
  /** Resolve the Sentry DSN. `""` → error telemetry disabled. */
886
883
  function resolveDsn() {
887
- return holocronEnv.get("SENTRY_DSN") ?? FALLBACK_DSN;
884
+ return env$9.get("SENTRY_DSN") ?? FALLBACK_DSN;
888
885
  }
889
886
  /** Resolve the PostHog project key. `""` → usage analytics disabled. */
890
887
  function resolvePostHogKey() {
891
- return holocronEnv.get("POSTHOG_PROJECT_TOKEN") ?? FALLBACK_POSTHOG_PROJECT_TOKEN;
888
+ return env$9.get("POSTHOG_PROJECT_TOKEN") ?? FALLBACK_POSTHOG_PROJECT_TOKEN;
892
889
  }
893
890
  /** Resolve the PostHog ingest host. */
894
891
  function resolvePostHogHost() {
895
- return holocronEnv.get("POSTHOG_HOST") ?? DEFAULT_POSTHOG_HOST;
892
+ return env$9.get("POSTHOG_HOST") ?? DEFAULT_POSTHOG_HOST;
896
893
  }
897
894
  // src/observability/telemetry/telemetry.ts
898
895
  /**
@@ -906,7 +903,7 @@ function resolvePostHogHost() {
906
903
  * `NO_HOLOCRON_TELEMETRY`); see ADR-0007 / ADR-0008.
907
904
  */
908
905
  const telemetry = createCliTelemetry({
909
- envPrefix: "HOLOCRON",
906
+ envPrefix: PREFIX,
910
907
  dsn: resolveDsn,
911
908
  posthogKey: resolvePostHogKey,
912
909
  posthogHost: resolvePostHogHost,
@@ -1158,7 +1155,7 @@ const defaultImporter = (pkg) => createDefaultImporter()(pkg);
1158
1155
  * pulling FROM it would just re-store the same value.
1159
1156
  */
1160
1157
  function resolveAuthSetToken(input) {
1161
- const e = withEnvPrefix(createEnvLookup(input.env), "HOLOCRON");
1158
+ const e = holocronEnv(input.env);
1162
1159
  return input.positional || e.get(`${input.provider.toUpperCase()}_TOKEN`) || null;
1163
1160
  }
1164
1161
  /**
@@ -2700,7 +2697,7 @@ const getEntry = registry.getEntry;
2700
2697
  */
2701
2698
  const menu = createMenu({
2702
2699
  bin: "holocron",
2703
- envPrefix: "HOLOCRON"
2700
+ envPrefix: PREFIX
2704
2701
  });
2705
2702
  const launchMenu = menu.launchMenu;
2706
2703
  /** The env var a Holocron dry-run preview child gets (`HOLOCRON_DRY_RUN_PREVIEW`). */
@@ -4365,7 +4362,7 @@ const CALLER_IDS = [
4365
4362
  "ci"
4366
4363
  ];
4367
4364
  /** The `ci.` a hosting repo puts before its callers' file names (`ci.yml` is the reusable itself, not a prefixed caller). */
4368
- const PREFIX = "ci.";
4365
+ const PREFIX$1 = "ci.";
4369
4366
  /**
4370
4367
  * What is wrong with the names of the generated callers, one line each. A caller is named for its task id in three
4371
4368
  * places: the file (`workflowFile(id)`, `ci.` first in the repo that hosts the reusables), the workflow `name:` and each
@@ -4376,7 +4373,7 @@ const PREFIX = "ci.";
4376
4373
  function callerProblems(callers) {
4377
4374
  return callers.flatMap(({ file, name, jobs }) => {
4378
4375
  const base = file.replace(/\.yml$/, "");
4379
- const prefix = base.startsWith(PREFIX) ? PREFIX : "";
4376
+ const prefix = base.startsWith(PREFIX$1) ? PREFIX$1 : "";
4380
4377
  const stem = base.slice(prefix.length);
4381
4378
  if (Object.hasOwn(LEGACY_NAMES, stem)) return [`${file}: an old caller name; the flat name is ${workflowKeys(stem).map((id) => `${prefix}${workflowFile(id)}`).join(", ")}`];
4382
4379
  const id = CALLER_IDS.find((candidate) => workflowFile(candidate).replace(/\.yml$/, "") === stem);
@@ -19185,7 +19182,7 @@ async function runSetup(input) {
19185
19182
  const logs = loader.get("logs");
19186
19183
  print(style.step("logs"));
19187
19184
  if (logs.ensureDataset) {
19188
- const dataset = withEnvPrefix(createEnvLookup(), "HOLOCRON").get("AXIOM_DATASET");
19185
+ const dataset = holocronEnv().get("AXIOM_DATASET");
19189
19186
  if (dataset) steps.push(await runStep("logs", `ensureDataset ${dataset}`, dryRun, async () => {
19190
19187
  const result = await logs.ensureDataset(dataset);
19191
19188
  return `${dataset} ${result.alreadyExists ? "exists" : "created"}`;
@@ -21498,6 +21495,22 @@ function secretRoutes(entries, environmentId) {
21498
21495
  ...entry.keys ? { keys: entry.keys } : {}
21499
21496
  }));
21500
21497
  }
21498
+ // src/commands/secrets-sync/github-name/github-name.ts
21499
+ /**
21500
+ * Why GitHub would refuse `name` as an Actions secret or variable name, or `undefined` when it would accept it.
21501
+ *
21502
+ * GitHub's rules (the same for repository, environment and organization secrets and variables): letters, digits and
21503
+ * underscores only, no spaces, not starting with a digit, and not starting with `GITHUB_` (reserved, in any case).
21504
+ * A name that breaks one gets a bare 422 from the API, which no retry can fix, so the sync checks first.
21505
+ *
21506
+ * @param name - The secret or variable name.
21507
+ */
21508
+ function githubNameProblem(name) {
21509
+ if (name === "") return "GitHub names cannot be empty";
21510
+ if (!/^[A-Za-z0-9_]+$/.test(name)) return "GitHub names may only contain letters, digits and underscores";
21511
+ if (/^[0-9]/.test(name)) return "GitHub names cannot start with a number";
21512
+ if (/^GITHUB_/i.test(name)) return "GitHub reserves names starting with GITHUB_";
21513
+ }
21501
21514
  // src/commands/secrets-sync/restore-pem/restore-pem.ts
21502
21515
  /** A PEM block written on one line: the begin marker, the body, the end marker, with spaces between them. */
21503
21516
  const COLLAPSED = /^(-----BEGIN [A-Z0-9 ]+-----) ([\s\S]+?) (-----END [A-Z0-9 ]+-----)$/;
@@ -21619,7 +21632,7 @@ async function runSecretsSync(input) {
21619
21632
  for (const key of route.keys ?? keys) {
21620
21633
  rows.push(await pushRow(`secrets:${secrets.providerName}`, scopeLabel(route.scope), key, envVars, dryRun, async (value) => {
21621
21634
  await secrets.setSecret(route.scope, key, value);
21622
- }));
21635
+ }, nameCheck(secrets.providerName)));
21623
21636
  print(formatRow(rows[rows.length - 1]));
21624
21637
  }
21625
21638
  }
@@ -21652,7 +21665,7 @@ async function runSecretsSync(input) {
21652
21665
  value,
21653
21666
  visibility: route.visibility ?? "all"
21654
21667
  } }, { prune: false });
21655
- }));
21668
+ }, nameCheck(source.providerName)));
21656
21669
  print(formatRow(rows[rows.length - 1]));
21657
21670
  }
21658
21671
  }
@@ -21742,7 +21755,15 @@ function summarise(rows, logger, print, dryRun) {
21742
21755
  * for a value still to be found, and pushing it would overwrite a working secret with nothing (which no provider can
21743
21756
  * read back to undo). Everything else goes through {@link runRow}.
21744
21757
  */
21745
- async function pushRow(destination, scope, key, envVars, dryRun, body) {
21758
+ async function pushRow(destination, scope, key, envVars, dryRun, body, nameProblem) {
21759
+ const problem = nameProblem?.(key);
21760
+ if (problem) return {
21761
+ destination,
21762
+ scope,
21763
+ key,
21764
+ status: "skip",
21765
+ message: `invalid name: ${problem}`
21766
+ };
21746
21767
  const value = Object.hasOwn(envVars, key) ? envVars[key] : void 0;
21747
21768
  if (value === void 0) return {
21748
21769
  destination,
@@ -21760,6 +21781,10 @@ async function pushRow(destination, scope, key, envVars, dryRun, body) {
21760
21781
  };
21761
21782
  return runRow(destination, scope, key, dryRun, () => body(restorePem(value)));
21762
21783
  }
21784
+ /** The name check for a destination: GitHub's rules when the provider is `github`, none for any other. */
21785
+ function nameCheck(providerName) {
21786
+ return providerName === "github" ? githubNameProblem : void 0;
21787
+ }
21763
21788
  async function runRow(destination, scope, key, dryRun, body) {
21764
21789
  if (dryRun) return {
21765
21790
  destination,