apiblaze 0.19.20 → 0.19.22

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 +45 -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.20";
935
+ var version = "0.19.22";
936
936
 
937
937
  // src/index.ts
938
938
  init_types();
@@ -6516,20 +6516,24 @@ async function mintDurableProxyKey(teamId, tenant2) {
6516
6516
  if (!out?.key) throw new Error("key mint returned no key");
6517
6517
  return out.key;
6518
6518
  }
6519
- async function fetchAcceptedMethods(project) {
6519
+ async function fetchProxyDoor(teamId, projectId, apiVersion) {
6520
6520
  try {
6521
6521
  const listing = await admin({
6522
6522
  method: "GET",
6523
- path: `/projects?team_id=${encodeURIComponent(project.teamId)}`,
6524
- summary: `Read the access policy for ${project.projectName}`
6523
+ path: `/projects?team_id=${encodeURIComponent(teamId)}`,
6524
+ summary: `Read the access policy for ${projectId}`
6525
6525
  });
6526
6526
  const rows = listing?.projects ?? [];
6527
- const row = rows.find((r) => r.project_id === project.projectId && r.api_version === project.apiVersion) ?? rows.find((r) => r.project_id === project.projectId);
6527
+ const row = rows.find((r) => r.project_id === projectId && r.api_version === apiVersion) ?? rows.find((r) => r.project_id === projectId);
6528
+ const tenant2 = row?.config?.default_tenant ?? row?.config?.tenant ?? (typeof row?.urls?.portal === "string" ? row.urls.portal.replace(/^https?:\/\//, "").split(".")[0] : void 0);
6528
6529
  const policy = row?.config?.requests_policy;
6529
- if (!policy || policy.mode !== "authenticate") return null;
6530
- return Array.isArray(policy.methods) && policy.methods.length ? policy.methods : null;
6530
+ if (!policy || policy.mode !== "authenticate") return { methods: null, tenant: tenant2 };
6531
+ return {
6532
+ methods: Array.isArray(policy.methods) && policy.methods.length ? policy.methods : null,
6533
+ tenant: tenant2
6534
+ };
6531
6535
  } catch {
6532
- return null;
6536
+ return { methods: null };
6533
6537
  }
6534
6538
  }
6535
6539
  async function openServerProxy(project) {
@@ -6539,8 +6543,8 @@ async function openServerProxy(project) {
6539
6543
  const tenant2 = project.tenant || project.projectId;
6540
6544
  const me = loadCredentials()?.apiblazeUserId;
6541
6545
  const prior = loadApichats().find((a) => a.projectId === project.projectId);
6542
- const acceptedMethods = await fetchAcceptedMethods(project);
6543
- const acceptsApiKey = acceptedMethods === null || acceptedMethods.includes("api_key");
6546
+ const door = await fetchProxyDoor(project.teamId, project.projectId, project.apiVersion);
6547
+ const acceptsApiKey = door.methods === null || door.methods.includes("api_key");
6544
6548
  let dpKey = prior?.dpKey;
6545
6549
  let consumerAuth = false;
6546
6550
  if (acceptsApiKey) {
@@ -6552,7 +6556,7 @@ async function openServerProxy(project) {
6552
6556
  } else {
6553
6557
  consumerAuth = true;
6554
6558
  dpKey = void 0;
6555
- await ensureConsumerLogin(project.teamId, tenant2);
6559
+ await ensureConsumerLogin(project.teamId, door.tenant ?? tenant2);
6556
6560
  }
6557
6561
  const p = {
6558
6562
  projectId: project.projectId,
@@ -6591,6 +6595,8 @@ async function openServerProxy(project) {
6591
6595
  version: version2,
6592
6596
  environment,
6593
6597
  mcpHost,
6598
+ teamId: project.teamId,
6599
+ tenant: tenant2,
6594
6600
  dpKey,
6595
6601
  consumerAuth,
6596
6602
  anon: false,
@@ -6670,14 +6676,40 @@ async function noArgsMenu(opts) {
6670
6676
  ]);
6671
6677
  if (mode === "resume") messages = a.messages.slice();
6672
6678
  }
6679
+ let savedKey = a.dpKey;
6680
+ let savedConsumerAuth = a.consumerAuth;
6681
+ let savedTenant = a.tenant;
6682
+ const resumeTeamId = a.teamId ?? creds?.teamId;
6683
+ if (!a.anon && resumeTeamId) {
6684
+ const door = await fetchProxyDoor(resumeTeamId, a.projectId, a.version);
6685
+ const acceptsApiKey = door.methods === null || door.methods.includes("api_key");
6686
+ if (!acceptsApiKey) {
6687
+ savedConsumerAuth = true;
6688
+ savedKey = void 0;
6689
+ const loginTenant = door.tenant ?? a.tenant;
6690
+ if (!loginTenant) {
6691
+ fail4(
6692
+ `Could not work out which tenant signs consumers in for "${a.projectId}".`,
6693
+ 'Re-open it from the "your proxy" list instead of Recent apichats.'
6694
+ );
6695
+ }
6696
+ savedTenant = loginTenant;
6697
+ await ensureConsumerLogin(resumeTeamId, loginTenant);
6698
+ } else if (savedConsumerAuth && !savedKey) {
6699
+ savedConsumerAuth = false;
6700
+ }
6701
+ if (savedConsumerAuth !== a.consumerAuth || savedKey !== a.dpKey || savedTenant !== a.tenant) {
6702
+ upsertApichat({ ...a, teamId: resumeTeamId, tenant: savedTenant, dpKey: savedKey, consumerAuth: savedConsumerAuth });
6703
+ }
6704
+ }
6673
6705
  const p = {
6674
6706
  projectId: a.projectId,
6675
6707
  version: a.version,
6676
6708
  environment: a.environment,
6677
- dpKey: a.dpKey,
6709
+ dpKey: savedKey,
6678
6710
  // Carry the door forward — resuming an OAuth-only chat must not fall back to
6679
6711
  // looking for a key that was never minted.
6680
- consumerAuth: a.consumerAuth,
6712
+ consumerAuth: savedConsumerAuth,
6681
6713
  mcpHost: a.mcpHost,
6682
6714
  proxyUrl: void 0,
6683
6715
  anon: a.anon,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apiblaze",
3
- "version": "0.19.20",
3
+ "version": "0.19.22",
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",