apiblaze 0.19.21 → 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 +26 -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.21";
935
+ var version = "0.19.22";
936
936
 
937
937
  // src/index.ts
938
938
  init_types();
@@ -6516,7 +6516,7 @@ 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(teamId, projectId, apiVersion) {
6519
+ async function fetchProxyDoor(teamId, projectId, apiVersion) {
6520
6520
  try {
6521
6521
  const listing = await admin({
6522
6522
  method: "GET",
@@ -6525,11 +6525,15 @@ async function fetchAcceptedMethods(teamId, projectId, apiVersion) {
6525
6525
  });
6526
6526
  const rows = listing?.projects ?? [];
6527
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.teamId, project.projectId, project.apiVersion);
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,
@@ -6674,19 +6678,28 @@ async function noArgsMenu(opts) {
6674
6678
  }
6675
6679
  let savedKey = a.dpKey;
6676
6680
  let savedConsumerAuth = a.consumerAuth;
6681
+ let savedTenant = a.tenant;
6677
6682
  const resumeTeamId = a.teamId ?? creds?.teamId;
6678
6683
  if (!a.anon && resumeTeamId) {
6679
- const methods = await fetchAcceptedMethods(resumeTeamId, a.projectId, a.version);
6680
- const acceptsApiKey = methods === null || methods.includes("api_key");
6684
+ const door = await fetchProxyDoor(resumeTeamId, a.projectId, a.version);
6685
+ const acceptsApiKey = door.methods === null || door.methods.includes("api_key");
6681
6686
  if (!acceptsApiKey) {
6682
6687
  savedConsumerAuth = true;
6683
6688
  savedKey = void 0;
6684
- await ensureConsumerLogin(resumeTeamId, a.tenant ?? a.projectId);
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);
6685
6698
  } else if (savedConsumerAuth && !savedKey) {
6686
6699
  savedConsumerAuth = false;
6687
6700
  }
6688
- if (savedConsumerAuth !== a.consumerAuth || savedKey !== a.dpKey) {
6689
- upsertApichat({ ...a, teamId: resumeTeamId, dpKey: savedKey, consumerAuth: savedConsumerAuth });
6701
+ if (savedConsumerAuth !== a.consumerAuth || savedKey !== a.dpKey || savedTenant !== a.tenant) {
6702
+ upsertApichat({ ...a, teamId: resumeTeamId, tenant: savedTenant, dpKey: savedKey, consumerAuth: savedConsumerAuth });
6690
6703
  }
6691
6704
  }
6692
6705
  const p = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apiblaze",
3
- "version": "0.19.21",
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",