apiblaze 0.1.7 → 0.1.9

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 +70 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -164,7 +164,7 @@ var init_api = __esm({
164
164
 
165
165
  // src/index.ts
166
166
  var import_commander = require("commander");
167
- var import_chalk6 = __toESM(require("chalk"));
167
+ var import_chalk7 = __toESM(require("chalk"));
168
168
  init_types();
169
169
 
170
170
  // src/commands/login.ts
@@ -189,12 +189,13 @@ async function runLogin() {
189
189
  throw new Error(`Failed to start login: ${codeRes.status}`);
190
190
  }
191
191
  const deviceAuth = await codeRes.json();
192
+ const loginUrl = deviceAuth.verification_uri_complete ?? deviceAuth.verification_uri;
192
193
  console.log(`${import_chalk.default.cyan("\u2192")} Open this URL in your browser to confirm login:`);
193
- console.log(` ${import_chalk.default.bold.underline(deviceAuth.verification_uri)}
194
+ console.log(` ${import_chalk.default.bold.underline(loginUrl)}
194
195
  `);
195
196
  console.log(`${import_chalk.default.cyan("\u2192")} Your code: ${import_chalk.default.bold(deviceAuth.user_code)}
196
197
  `);
197
- openBrowser(deviceAuth.verification_uri_complete ?? deviceAuth.verification_uri);
198
+ openBrowser(loginUrl);
198
199
  const spinner = (0, import_ora.default)("Waiting for authorization in browser...").start();
199
200
  let accessToken;
200
201
  let pollInterval = (deviceAuth.interval ?? 5) * 1e3;
@@ -682,6 +683,18 @@ function isHttpUrl(s) {
682
683
  return false;
683
684
  }
684
685
  }
686
+ function stripTenantFromPortal(devPortal) {
687
+ try {
688
+ const u = new URL(devPortal);
689
+ const dot = u.hostname.indexOf(".");
690
+ if (dot < 0) return devPortal;
691
+ const product = u.hostname.slice(0, dot).split("-")[0];
692
+ u.hostname = `${product}${u.hostname.slice(dot)}`;
693
+ return u.toString();
694
+ } catch {
695
+ return devPortal;
696
+ }
697
+ }
685
698
  async function runCreate() {
686
699
  const creds = loadCredentials();
687
700
  if (!creds) {
@@ -748,18 +761,18 @@ async function runCreate() {
748
761
  }
749
762
  const version = result.api_version || "1.0.0";
750
763
  const keys = result.api_keys ?? {};
751
- const adminKey = keys.prod ?? Object.values(keys)[0];
764
+ const adminKey = keys.dev ?? Object.values(keys)[0];
752
765
  console.log();
753
- console.log(` ${import_chalk5.default.dim("Proxy URL: ")} ${import_chalk5.default.bold(`https://${name}.apiblaze.com/${version}/prod`)}`);
766
+ console.log(` ${import_chalk5.default.dim("Proxy URL: ")} ${import_chalk5.default.bold(`https://${name}.apiblaze.com/${version}/dev`)}`);
754
767
  if (result.devPortal) {
755
- console.log(` ${import_chalk5.default.dim("Dev portal:")} ${import_chalk5.default.bold(result.devPortal)}`);
768
+ console.log(` ${import_chalk5.default.dim("Dev portal:")} ${import_chalk5.default.bold(stripTenantFromPortal(result.devPortal))}`);
756
769
  }
757
770
  if (adminKey) {
758
771
  console.log();
759
- console.log(` ${import_chalk5.default.dim("Consumer admin API key (prod):")}`);
772
+ console.log(` ${import_chalk5.default.dim("Consumer admin API key (dev):")}`);
760
773
  console.log(` ${import_chalk5.default.bold.green(adminKey)}`);
761
774
  console.log(import_chalk5.default.dim("\n Save this now \u2014 send it as the X-API-Key header. It may not be shown again."));
762
- const otherEnvs = Object.keys(keys).filter((e) => e !== "prod");
775
+ const otherEnvs = Object.keys(keys).filter((e) => e !== "dev");
763
776
  if (otherEnvs.length) {
764
777
  console.log(import_chalk5.default.dim(` (Separate keys were also created for: ${otherEnvs.join(", ")}.)`));
765
778
  }
@@ -767,6 +780,44 @@ async function runCreate() {
767
780
  console.log();
768
781
  }
769
782
 
783
+ // src/commands/team.ts
784
+ var import_chalk6 = __toESM(require("chalk"));
785
+ init_auth();
786
+ init_api();
787
+ async function runTeam() {
788
+ const creds = loadCredentials();
789
+ if (!creds) {
790
+ console.error(import_chalk6.default.red("Not logged in. Run `apiblaze login` first."));
791
+ process.exit(1);
792
+ }
793
+ const teams = await getTeams().catch(() => []);
794
+ if (teams.length === 0) {
795
+ console.log(import_chalk6.default.yellow("No teams found for your account."));
796
+ return;
797
+ }
798
+ let teamId;
799
+ let teamName;
800
+ if (teams.length === 1) {
801
+ teamId = teams[0].teamId;
802
+ teamName = teams[0].name;
803
+ console.log(`${import_chalk6.default.cyan("\u2192")} You only have one team: ${import_chalk6.default.bold(teamName)}`);
804
+ } else {
805
+ const { default: inquirer2 } = await import("inquirer");
806
+ const { chosen } = await inquirer2.prompt([{
807
+ type: "list",
808
+ name: "chosen",
809
+ message: "Switch to which team?",
810
+ default: creds.teamId,
811
+ choices: teams.map((t) => ({ name: t.name, value: t.teamId }))
812
+ }]);
813
+ teamId = chosen;
814
+ teamName = teams.find((t) => t.teamId === chosen)?.name;
815
+ }
816
+ saveCredentials({ ...creds, teamId, teamName });
817
+ console.log(import_chalk6.default.green(`
818
+ \u2714 Active team: ${import_chalk6.default.bold(teamName ?? teamId)}`));
819
+ }
820
+
770
821
  // src/index.ts
771
822
  var program = new import_commander.Command();
772
823
  program.name("apiblaze").description("APIblaze dev tunnel CLI").version("0.1.0");
@@ -786,6 +837,14 @@ program.command("create").description("Create a new API proxy").action(async ()
786
837
  process.exit(1);
787
838
  }
788
839
  });
840
+ program.command("team").description("Switch the active team").action(async () => {
841
+ try {
842
+ await runTeam();
843
+ } catch (err) {
844
+ printError(err);
845
+ process.exit(1);
846
+ }
847
+ });
789
848
  program.command("projects").description("List the projects in your team").action(async () => {
790
849
  try {
791
850
  await runProjects();
@@ -804,13 +863,13 @@ program.command("dev").description("Start a dev tunnel for your localhost projec
804
863
  });
805
864
  function printError(err) {
806
865
  if (err instanceof ApiError) {
807
- console.error(import_chalk6.default.red(`
866
+ console.error(import_chalk7.default.red(`
808
867
  API error (${err.status}): ${err.message}`));
809
868
  } else if (err instanceof Error) {
810
- console.error(import_chalk6.default.red(`
869
+ console.error(import_chalk7.default.red(`
811
870
  Error: ${err.message}`));
812
871
  } else {
813
- console.error(import_chalk6.default.red("\nUnknown error"));
872
+ console.error(import_chalk7.default.red("\nUnknown error"));
814
873
  }
815
874
  }
816
875
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apiblaze",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Dev tunnel CLI for APIblaze — route localhost projects through Cloudflare tunnels",
5
5
  "keywords": [
6
6
  "apiblaze",