@theholocron/cli 5.0.0-alpha.384 → 5.0.0-alpha.386

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
@@ -4466,6 +4466,7 @@ async function runDev(input) {
4466
4466
  return finish("fail");
4467
4467
  }
4468
4468
  row(true, `vault ${input.environment}`, `${Object.keys(values).length} variables, passed to the application`);
4469
+ const appEnvironment = values[`${PREFIX}_ENVIRONMENT`] ?? values["ENVIRONMENT"] ?? APP_ENVIRONMENT;
4469
4470
  let token;
4470
4471
  try {
4471
4472
  token = await loader.get("tunnels").tunnelToken(tunnel.tunnelId);
@@ -4482,7 +4483,8 @@ async function runDev(input) {
4482
4483
  command: program,
4483
4484
  args,
4484
4485
  env: {
4485
- ENVIRONMENT: APP_ENVIRONMENT,
4486
+ ENVIRONMENT: appEnvironment,
4487
+ [`${PREFIX}_ENVIRONMENT`]: appEnvironment,
4486
4488
  ...values,
4487
4489
  PORT: String(input.port),
4488
4490
  [`${PREFIX}_PORT`]: String(input.port)
@@ -5992,7 +5994,8 @@ function parseManifest(text) {
5992
5994
  *
5993
5995
  * GitHub has no API that changes an existing App's permissions or event subscriptions, so each instance is changed by
5994
5996
  * hand in its settings page and a missed one fails quietly. Read-only: for every entry of `githubApps` it reads the
5995
- * manifest file, reads the instance's `GITHUB_APP_ID` and `GITHUB_APP_PRIVATE_KEY` from its vault environment in
5997
+ * manifest file, reads the instance's `SENTINEL_GITHUB_APP_ID` and `SENTINEL_GITHUB_APP_PRIVATE_KEY` (else the bare `GITHUB_APP_ID` and
5998
+ * `GITHUB_APP_PRIVATE_KEY`) from its vault environment in
5996
5999
  * memory (never printed, never written), signs the App's own JWT and calls `GET /app` and `GET /app/installations`.
5997
6000
  * Rows per instance: reachable; events (every manifest event is subscribed); permissions (each manifest permission is
5998
6001
  * granted at least at its level, `read < write < admin`); installations (none lags the App, which is a pending
@@ -6000,8 +6003,13 @@ function parseManifest(text) {
6000
6003
  * that fails ends with the settings page that fixes it. An instance whose credentials cannot be read is a skip with
6001
6004
  * the reason; an unreadable manifest, a rejected JWT or a gap is a failure.
6002
6005
  */
6003
- const APP_ID = "GITHUB_APP_ID";
6004
- const PRIVATE_KEY = "GITHUB_APP_PRIVATE_KEY";
6006
+ /** The names the App's credentials are kept under, Sentinel's own first and the bare ones an older Environment has (#1864). */
6007
+ const APP_ID = ["SENTINEL_GITHUB_APP_ID", "GITHUB_APP_ID"];
6008
+ const PRIVATE_KEY = ["SENTINEL_GITHUB_APP_PRIVATE_KEY", "GITHUB_APP_PRIVATE_KEY"];
6009
+ /** The first of `names` the environment holds a value for. */
6010
+ function held(values, names) {
6011
+ return names.map((name) => values[name]).find((value) => value?.trim());
6012
+ }
6005
6013
  const defaultApi = {
6006
6014
  getApp,
6007
6015
  listAppInstallations
@@ -6056,11 +6064,16 @@ async function readCredentials(instance, loader) {
6056
6064
  } catch (err) {
6057
6065
  return { reason: `cannot read the "${instance.environment}" environment: ${errorMessage(err)}` };
6058
6066
  }
6059
- const missing = [APP_ID, PRIVATE_KEY].filter((key) => !values[key]?.trim());
6060
- if (missing.length > 0) return { reason: `"${instance.environment}" does not hold ${missing.join(" or ")}` };
6061
- const privateKey = values[PRIVATE_KEY].includes("\n") ? values[PRIVATE_KEY] : values[PRIVATE_KEY].replace(/\\n/g, "\n");
6067
+ const appId = held(values, APP_ID);
6068
+ const key = held(values, PRIVATE_KEY);
6069
+ const missing = [appId ? void 0 : APP_ID, key ? void 0 : PRIVATE_KEY].filter((names) => names !== void 0);
6070
+ if (missing.length > 0) {
6071
+ const named = missing.map(([preferred, older]) => `${preferred} (or ${older})`).join(" or ");
6072
+ return { reason: `"${instance.environment}" does not hold ${named}` };
6073
+ }
6074
+ const privateKey = key.includes("\n") ? key : key.replace(/\\n/g, "\n");
6062
6075
  return { creds: {
6063
- appId: values[APP_ID].trim(),
6076
+ appId: appId.trim(),
6064
6077
  privateKey
6065
6078
  } };
6066
6079
  }
@@ -11064,8 +11077,8 @@ async function runGithubAppCreate(input) {
11064
11077
  let identity;
11065
11078
  try {
11066
11079
  const lines = [
11067
- dotenvLine("GITHUB_APP_ID", String(app.id)),
11068
- dotenvLine("GITHUB_APP_PRIVATE_KEY", app.pem),
11080
+ dotenvLine("SENTINEL_GITHUB_APP_ID", String(app.id)),
11081
+ dotenvLine("SENTINEL_GITHUB_APP_PRIVATE_KEY", app.pem),
11069
11082
  dotenvLine(input.webhookSecretVar || DEFAULT_WEBHOOK_SECRET_VAR, app.webhookSecret)
11070
11083
  ];
11071
11084
  if (lines.includes(null)) throw new Error("a value cannot be written as a dotenv line");
@@ -11091,7 +11104,7 @@ async function runGithubAppCreate(input) {
11091
11104
  identity,
11092
11105
  print,
11093
11106
  holds: "the App's credentials",
11094
- importHint: "import it in the 1Password app: Developer, View Environments, the Environment, Import .env file; it holds GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY and the webhook secret",
11107
+ importHint: "import it in the 1Password app: Developer, View Environments, the Environment, Import .env file; it holds SENTINEL_GITHUB_APP_ID, SENTINEL_GITHUB_APP_PRIVATE_KEY and the webhook secret",
11095
11108
  keep: input.keep,
11096
11109
  interactive: input.interactive,
11097
11110
  shred: input.shred,