apiblaze 0.19.22 → 0.19.24

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 (2) hide show
  1. package/dist/index.js +22 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -932,7 +932,7 @@ var import_commander = require("commander");
932
932
  var import_chalk44 = __toESM(require("chalk"));
933
933
 
934
934
  // package.json
935
- var version = "0.19.22";
935
+ var version = "0.19.24";
936
936
 
937
937
  // src/index.ts
938
938
  init_types();
@@ -6067,12 +6067,13 @@ async function dataPlaneAuth(p) {
6067
6067
  if (fresh.accessToken !== stored.accessToken) saveConsumer(fresh);
6068
6068
  return { Authorization: `Bearer ${fresh.accessToken}` };
6069
6069
  }
6070
- async function ensureConsumerLogin(teamId, tenant2) {
6070
+ async function ensureConsumerLogin(teamId, tenant2, version2) {
6071
+ const resource = `https://${tenant2}.portal.apiblaze.com/${version2}`;
6071
6072
  const existing = loadConsumer();
6072
- if (existing && existing.tenant === tenant2) {
6073
+ if (existing && existing.tenant === tenant2 && existing.resource === resource) {
6073
6074
  const fresh = await validConsumerToken(existing);
6074
6075
  if (fresh) {
6075
- if (fresh.accessToken !== existing.accessToken) saveConsumer(fresh);
6076
+ if (fresh.accessToken !== existing.accessToken) saveConsumer({ ...fresh, resource });
6076
6077
  console.log(import_chalk39.default.dim(` Using your consumer session on ${import_chalk39.default.bold(tenant2)}${fresh.email ? ` (${fresh.email})` : ""}.`));
6077
6078
  return fresh;
6078
6079
  }
@@ -6099,7 +6100,7 @@ async function ensureConsumerLogin(teamId, tenant2) {
6099
6100
  console.log(` Code: ${import_chalk39.default.bold(userCode)}
6100
6101
  `);
6101
6102
  console.log(import_chalk39.default.dim(" (opening your browser\u2026 waiting for you to finish)"));
6102
- }, `https://${tenant2}.portal.apiblaze.com/1.0.0`);
6103
+ }, resource);
6103
6104
  const claims = result.idToken && decodeJwt2(result.idToken) || (decodeJwt2(result.accessToken) ?? {});
6104
6105
  const creds = {
6105
6106
  tenant: tenant2,
@@ -6110,7 +6111,8 @@ async function ensureConsumerLogin(teamId, tenant2) {
6110
6111
  expiresAt: Date.now() + (result.expiresIn ?? 3600) * 1e3,
6111
6112
  scope: result.scope,
6112
6113
  email: typeof claims.email === "string" ? claims.email : void 0,
6113
- obtainedAt: Date.now()
6114
+ obtainedAt: Date.now(),
6115
+ resource
6114
6116
  };
6115
6117
  saveConsumer(creds);
6116
6118
  console.log(` ${import_chalk39.default.green("\u2714")} Signed in as${creds.email ? ` ${import_chalk39.default.bold(creds.email)}` : " a consumer"} on ${tenant2}.`);
@@ -6413,7 +6415,14 @@ async function replTurn(p, messages, userText) {
6413
6415
  return;
6414
6416
  }
6415
6417
  if (res.status === 401) {
6416
- console.log(import_chalk39.default.red(" The proxy rejected the API key (401). The key may have been revoked; re-run `apiblaze apichat` to re-provision."));
6418
+ const reason = data && (data.error || data.message) || null;
6419
+ const usingKey = !p.consumerAuth;
6420
+ console.log(import_chalk39.default.red(` The proxy rejected the request (401)${reason ? `: ${reason}` : "."}`));
6421
+ console.log(
6422
+ import_chalk39.default.dim(
6423
+ usingKey ? " Sent an API key. If the key was revoked, re-run `apiblaze apichat` to re-provision." : " Sent your consumer OAuth token. Re-run `apiblaze apichat` to sign in again."
6424
+ )
6425
+ );
6417
6426
  return;
6418
6427
  }
6419
6428
  if (!res.ok || !data) {
@@ -6556,7 +6565,7 @@ async function openServerProxy(project) {
6556
6565
  } else {
6557
6566
  consumerAuth = true;
6558
6567
  dpKey = void 0;
6559
- await ensureConsumerLogin(project.teamId, door.tenant ?? tenant2);
6568
+ await ensureConsumerLogin(project.teamId, door.tenant ?? tenant2, version2);
6560
6569
  }
6561
6570
  const p = {
6562
6571
  projectId: project.projectId,
@@ -6575,14 +6584,14 @@ async function openServerProxy(project) {
6575
6584
  const raw = await admin({
6576
6585
  method: "GET",
6577
6586
  path: `/projects/${project.projectId}/${version2}/openapi`,
6578
- summary: "Fetch OpenAPI spec"
6587
+ summary: "Check the proxy has a spec"
6579
6588
  }).catch(() => null);
6580
6589
  const spec2 = raw && (raw.spec ?? raw);
6581
6590
  spinner.stop();
6582
- if (spec2 && (spec2.paths || spec2.openapi)) {
6583
- await publishMcp(p, spec2);
6584
- } else {
6591
+ if (!spec2 || !(spec2.paths || spec2.openapi)) {
6585
6592
  console.log(import_chalk39.default.yellow(" This proxy has no OpenAPI spec yet \u2014 chat will have no tools. Build one with `apiblaze agent openapi`."));
6593
+ } else {
6594
+ console.log(import_chalk39.default.dim(" Using the proxy's existing MCP catalogue (`apiblaze mcp` to rebuild it)."));
6586
6595
  }
6587
6596
  } catch (err) {
6588
6597
  spinner.fail("Could not open the proxy.");
@@ -6694,7 +6703,7 @@ async function noArgsMenu(opts) {
6694
6703
  );
6695
6704
  }
6696
6705
  savedTenant = loginTenant;
6697
- await ensureConsumerLogin(resumeTeamId, loginTenant);
6706
+ await ensureConsumerLogin(resumeTeamId, loginTenant, a.version);
6698
6707
  } else if (savedConsumerAuth && !savedKey) {
6699
6708
  savedConsumerAuth = false;
6700
6709
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apiblaze",
3
- "version": "0.19.22",
3
+ "version": "0.19.24",
4
4
  "description": "APIblaze CLI — Chat with your APIs, Manage your API keys, users and groups with the APIblaze serverless proxy",
5
5
  "keywords": [
6
6
  "apiblaze",