@senticor/hive 1.132.0 → 1.133.0

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.
Files changed (3) hide show
  1. package/README.md +9 -0
  2. package/hive.cjs +81 -17
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -62,6 +62,15 @@ hive health deep --format json
62
62
  `hive auth` is an alias group for `login` / `logout` / `status` (e.g.
63
63
  `hive auth status` shows token validity; `hive logout` clears local tokens).
64
64
 
65
+ **Run another tool as yourself:** `hive auth token` prints a fresh access token
66
+ for your login on stdout, and nothing else. It refreshes the token first when it
67
+ has less than 60 seconds left (or `--min-ttl <seconds>`). When it cannot, stdout
68
+ stays empty and it exits non-zero, so a script never takes an error for a token.
69
+
70
+ ```bash
71
+ HIVE_TOKEN=$(hive auth token) pnpm run mission:provision -- --check
72
+ ```
73
+
65
74
  **Non-interactive (CI, bots, headless):** skip the browser and pass a token
66
75
  directly instead of logging in.
67
76
 
package/hive.cjs CHANGED
@@ -9293,10 +9293,11 @@ async function loginWithBrowser(issuerUrl, opts = {}) {
9293
9293
  prompter?.close();
9294
9294
  }
9295
9295
  }
9296
+ var REFRESH_SKEW_MS = 6e4;
9296
9297
  async function refreshToken(creds) {
9297
- if (!creds || !creds.refresh_token) return false;
9298
+ if (!creds.refresh_token) return { ok: false, failure: { reason: "no_refresh_token", expiresAt: creds.expires_at } };
9298
9299
  const disco = await getDiscovery(creds.issuer);
9299
- if (!disco || !disco.token_endpoint) return false;
9300
+ if (!disco || !disco.token_endpoint) return { ok: false, failure: { reason: "issuer_unreachable", issuer: creds.issuer } };
9300
9301
  const clientId = creds.clientId || CLIENT_ID;
9301
9302
  const tokenEndpoint = rewriteForInternalKeycloak(disco.token_endpoint, creds.issuer);
9302
9303
  const res = await fetchUrlencoded(tokenEndpoint, {
@@ -9304,9 +9305,15 @@ async function refreshToken(creds) {
9304
9305
  client_id: clientId,
9305
9306
  refresh_token: creds.refresh_token
9306
9307
  });
9307
- if (!res.ok) {
9308
+ if (res.status === 400 || res.status === 401) {
9308
9309
  clearCredentials();
9309
- return false;
9310
+ return { ok: false, failure: { reason: "refresh_refused", detail: providerDetail(res.status, res.data) } };
9311
+ }
9312
+ if (!res.ok) {
9313
+ return { ok: false, failure: { reason: "issuer_error", issuer: creds.issuer, detail: providerDetail(res.status, res.data) } };
9314
+ }
9315
+ if (typeof res.data.access_token !== "string" || !res.data.access_token) {
9316
+ return { ok: false, failure: { reason: "issuer_error", issuer: creds.issuer, detail: "the token response held no access token" } };
9310
9317
  }
9311
9318
  const claims2 = parseJwt(res.data.access_token);
9312
9319
  const expiry = Date.now() + (res.data.expires_in || 3600) * 1e3;
@@ -9318,16 +9325,19 @@ async function refreshToken(creds) {
9318
9325
  user: claims2 ? claims2.preferred_username || claims2.sub : creds.user,
9319
9326
  clientId
9320
9327
  });
9321
- return res.data.access_token;
9328
+ return { ok: true, token: res.data.access_token, expiresAt: expiry };
9322
9329
  }
9323
- async function getValidToken() {
9330
+ async function freshToken(minValidityMs = REFRESH_SKEW_MS) {
9324
9331
  const creds = getStoredCredentials();
9325
- if (!creds || !creds.access_token) return null;
9326
- if (creds.expires_at < Date.now() + 6e4) {
9327
- const newAccessToken = await refreshToken(creds);
9328
- return newAccessToken || null;
9332
+ if (!creds || !creds.access_token) return { ok: false, failure: { reason: "not_logged_in" } };
9333
+ if (creds.expires_at >= Date.now() + minValidityMs) {
9334
+ return { ok: true, token: creds.access_token, expiresAt: creds.expires_at };
9329
9335
  }
9330
- return creds.access_token;
9336
+ return refreshToken(creds);
9337
+ }
9338
+ async function getValidToken() {
9339
+ const fresh = await freshToken();
9340
+ return fresh.ok ? fresh.token : null;
9331
9341
  }
9332
9342
 
9333
9343
  // src/lib/exit-codes.ts
@@ -10470,22 +10480,22 @@ var artifactName = injectedString(
10470
10480
  true ? "hive-cli" : void 0
10471
10481
  ) || String(process.env.HIVE_CLI_ARTIFACT_NAME || "hive-cli").trim() || "hive-cli";
10472
10482
  var packageVersion = injectedString(
10473
- true ? "1.132.0" : void 0
10483
+ true ? "1.133.0" : void 0
10474
10484
  ) || String(process.env.HIVE_CLI_PACKAGE_VERSION || "").trim() || readPackageVersion();
10475
10485
  var releaseVersion = injectedString(
10476
- true ? "1.132.0" : void 0
10486
+ true ? "1.133.0" : void 0
10477
10487
  ) || String(process.env.HIVE_CLI_RELEASE_VERSION || "").trim() || packageVersion || "dev";
10478
10488
  var releaseChannel = injectedString(
10479
10489
  true ? "final" : void 0
10480
10490
  ) || String(process.env.HIVE_CLI_RELEASE_CHANNEL || "").trim() || (releaseVersion.includes("-rc.") ? "rc" : releaseVersion === "dev" ? "dev" : "final");
10481
10491
  var buildCommit = injectedString(
10482
- true ? "0df6dc8d14dc4effc5459e082d9eac117d375c28" : void 0
10492
+ true ? "576729e9335e2ae30976eae5618f5839fd06aff3" : void 0
10483
10493
  ) || String(process.env.HIVE_CLI_BUILD_COMMIT || "").trim() || "unknown";
10484
10494
  var buildTimestamp = injectedString(
10485
- true ? "2026-11-10T11:27:57Z" : void 0
10495
+ true ? "2026-11-10T13:06:53Z" : void 0
10486
10496
  ) || String(process.env.HIVE_CLI_BUILD_TIMESTAMP || "").trim() || "unknown";
10487
10497
  var ociRef = injectedString(
10488
- true ? "registry.onstackit.cloud/senticor/hive-cli:1.132.0" : void 0
10498
+ true ? "registry.onstackit.cloud/senticor/hive-cli:1.133.0" : void 0
10489
10499
  ) || String(process.env.HIVE_CLI_OCI_REF || "").trim() || `registry.onstackit.cloud/senticor/${artifactName}:${releaseVersion}`;
10490
10500
  var RELEASE_INFO = Object.freeze({
10491
10501
  packageVersion,
@@ -11638,8 +11648,55 @@ var config = defineCommand({
11638
11648
  })
11639
11649
  }
11640
11650
  });
11651
+ function tokenFailure(message, code) {
11652
+ process.stderr.write(`hive auth token: ${message}
11653
+ `);
11654
+ process.exit(code);
11655
+ }
11656
+ async function printAuthToken(args) {
11657
+ const raw = args.minTtl === void 0 ? "60" : String(args.minTtl).trim();
11658
+ if (!/^\d+$/.test(raw)) tokenFailure(`--min-ttl must be a whole number of seconds, got '${raw}'.`, EXIT_FAILURE);
11659
+ const minTtl = Number(raw);
11660
+ let fresh;
11661
+ try {
11662
+ fresh = await freshToken(minTtl * 1e3);
11663
+ } catch (err) {
11664
+ const issuer = getStoredCredentials()?.issuer ?? "the issuer";
11665
+ tokenFailure(`could not reach ${issuer} to refresh the login: ${err.message}`, EXIT_TRANSPORT_FAILED);
11666
+ }
11667
+ if (!fresh.ok) {
11668
+ const { failure: failure2 } = fresh;
11669
+ switch (failure2.reason) {
11670
+ case "not_logged_in":
11671
+ return tokenFailure("not logged in. Run 'hive login' first.", EXIT_NOT_AUTHORIZED);
11672
+ case "no_refresh_token": {
11673
+ const left2 = Math.round((failure2.expiresAt - Date.now()) / 1e3);
11674
+ const state = left2 > 0 ? `has ${left2} s left, less than --min-ttl ${minTtl},` : "has expired";
11675
+ return tokenFailure(`the stored token ${state} and the login holds no refresh token. Run 'hive login' again.`, EXIT_NOT_AUTHORIZED);
11676
+ }
11677
+ case "refresh_refused":
11678
+ return tokenFailure(`the issuer refused to refresh the login (${failure2.detail}). Run 'hive login' again.`, EXIT_NOT_AUTHORIZED);
11679
+ case "issuer_unreachable":
11680
+ return tokenFailure(`could not reach ${failure2.issuer} to refresh the login. The login is kept; try again.`, EXIT_TRANSPORT_FAILED);
11681
+ case "issuer_error":
11682
+ return tokenFailure(`${failure2.issuer} did not refresh the login: ${failure2.detail}. The login is kept; try again.`, EXIT_REMOTE_FAILED);
11683
+ }
11684
+ }
11685
+ const left = Math.round((fresh.expiresAt - Date.now()) / 1e3);
11686
+ if (left < minTtl) {
11687
+ tokenFailure(
11688
+ `the issuer issues access tokens valid for ${left} s, less than --min-ttl ${minTtl}. Lower --min-ttl.`,
11689
+ EXIT_FAILURE
11690
+ );
11691
+ }
11692
+ if (process.stdout.isTTY) {
11693
+ process.stderr.write("Note: this access token acts as you until it expires. Pass it on as HIVE_TOKEN=$(hive auth token) instead of copying it.\n");
11694
+ }
11695
+ process.stdout.write(`${fresh.token}
11696
+ `);
11697
+ }
11641
11698
  var auth = defineCommand({
11642
- meta: { name: "auth", description: "Authentication aliases (login, logout, status) and the server view of you (me)" },
11699
+ meta: { name: "auth", description: "Authentication aliases (login, logout, status), the server view of you (me) and a fresh token for other tools (token)" },
11643
11700
  args: withArgs(),
11644
11701
  default: "status",
11645
11702
  subCommands: {
@@ -11671,6 +11728,13 @@ var auth = defineCommand({
11671
11728
  hasRefreshToken: Boolean(creds?.refresh_token)
11672
11729
  }, fmt);
11673
11730
  }
11731
+ }),
11732
+ token: defineCommand({
11733
+ meta: { name: "token", description: "Print a fresh access token for the stored login (stdout only)" },
11734
+ args: withArgs({ minTtl: { type: "string", description: "Minimum lifetime in seconds the printed token keeps (default 60)" } }),
11735
+ async run({ args }) {
11736
+ await printAuthToken(args);
11737
+ }
11674
11738
  })
11675
11739
  }
11676
11740
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senticor/hive",
3
- "version": "1.132.0",
3
+ "version": "1.133.0",
4
4
  "description": "Cognitive Hive OS — unified CLI",
5
5
  "type": "commonjs",
6
6
  "bin": {