apiblaze 0.3.3 → 0.3.5

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 +54 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ var import_commander = require("commander");
28
28
  var import_chalk15 = __toESM(require("chalk"));
29
29
 
30
30
  // package.json
31
- var version = "0.3.3";
31
+ var version = "0.3.5";
32
32
 
33
33
  // src/types.ts
34
34
  var ApiError = class extends Error {
@@ -757,6 +757,32 @@ function startTunnelClient(opts) {
757
757
  }
758
758
 
759
759
  // src/commands/dev.ts
760
+ async function ensureLoggedIn(interactive) {
761
+ const existing = loadCredentials();
762
+ if (existing && Date.now() < existing.expiresAt) return existing;
763
+ console.log(import_chalk4.default.yellow(existing ? "\nYour APIblaze session has expired." : "\nYou're not logged in to APIblaze."));
764
+ if (!interactive) {
765
+ console.error(import_chalk4.default.red("Run `apiblaze login` first."));
766
+ process.exit(1);
767
+ }
768
+ const { doLogin } = await import_inquirer.default.prompt([{
769
+ type: "confirm",
770
+ name: "doLogin",
771
+ message: "Log in now?",
772
+ default: true
773
+ }]);
774
+ if (!doLogin) {
775
+ console.log(import_chalk4.default.dim("Run `apiblaze login` when you're ready."));
776
+ process.exit(0);
777
+ }
778
+ await runLogin();
779
+ const creds = loadCredentials();
780
+ if (!creds) {
781
+ console.error(import_chalk4.default.red("Login did not complete. Run `apiblaze login` and try again."));
782
+ process.exit(1);
783
+ }
784
+ return creds;
785
+ }
760
786
  async function offerAutoCreate(teamId, port) {
761
787
  if (!process.stdin.isTTY) {
762
788
  console.log(import_chalk4.default.yellow("No projects found with an internal target."));
@@ -795,9 +821,6 @@ async function offerAutoCreate(teamId, port) {
795
821
  spinner.fail("Failed to create the dev proxy.");
796
822
  throw err;
797
823
  }
798
- const version2 = result.api_version || "1.0.0";
799
- const endpoint = `https://${name}.apiblaze.com/${version2}/dev`;
800
- console.log(` ${import_chalk4.default.dim("Endpoint:")} ${import_chalk4.default.bold(endpoint)}`);
801
824
  if (auth === "api_key") {
802
825
  const key = result.api_keys?.dev ?? Object.values(result.api_keys ?? {})[0];
803
826
  if (key) {
@@ -813,6 +836,31 @@ async function offerAutoCreate(teamId, port) {
813
836
  }
814
837
  return created;
815
838
  }
839
+ function isInternalTarget(url) {
840
+ if (!url) return false;
841
+ try {
842
+ const h = new URL(url).hostname.toLowerCase();
843
+ return h === "localhost" || h.endsWith(".localhost") || h.endsWith(".local") || h === "0.0.0.0" || /^127\./.test(h) || /^10\./.test(h) || /^192\.168\./.test(h) || /^169\.254\./.test(h) || /^172\.(1[6-9]|2\d|3[01])\./.test(h);
844
+ } catch {
845
+ return false;
846
+ }
847
+ }
848
+ function printTunnelEndpoints(restore, targets) {
849
+ if (restore.length === 0) return;
850
+ console.log(import_chalk4.default.bold("\nYour proxy is live at:"));
851
+ for (const r of restore) {
852
+ const label = targets.find((t) => t.projectId === r.projectId)?.projectName ?? r.projectId;
853
+ console.log(`
854
+ ${import_chalk4.default.bold(label)}`);
855
+ const envs = Object.keys(r.environments ?? {}).filter((e) => isInternalTarget(r.environments[e]?.target));
856
+ for (const env of envs.length ? envs : ["dev"]) {
857
+ console.log(` ${import_chalk4.default.dim("API: ")} ${import_chalk4.default.cyan(`https://${r.projectId}.apiblaze.com/${r.apiVersion}/${env}`)}`);
858
+ }
859
+ if (r.tenant) {
860
+ console.log(` ${import_chalk4.default.dim("Portal:")} ${import_chalk4.default.cyan(`https://${r.tenant}.portal.apiblaze.com/${r.apiVersion}`)}`);
861
+ }
862
+ }
863
+ }
816
864
  async function probeLocalServer(port) {
817
865
  const controller = new AbortController();
818
866
  const timer = setTimeout(() => controller.abort(), 1500);
@@ -828,11 +876,7 @@ async function probeLocalServer(port) {
828
876
  }
829
877
  }
830
878
  async function runDev(options) {
831
- const creds = loadCredentials();
832
- if (!creds) {
833
- console.error(import_chalk4.default.red("Not logged in. Run `apiblaze login` first."));
834
- process.exit(1);
835
- }
879
+ const creds = await ensureLoggedIn(!!process.stdin.isTTY);
836
880
  const linked = await resolveLinkedTeam({ preferredId: creds.teamId, interactive: !!process.stdin.isTTY });
837
881
  if (!linked) {
838
882
  console.error(import_chalk4.default.red("No team available. Run `apiblaze login` to set up your team."));
@@ -922,6 +966,7 @@ Tunneling ${selectedTargets.length} project(s) to localhost:${options.port}
922
966
  throw err;
923
967
  }
924
968
  }
969
+ printTunnelEndpoints(restore, selectedTargets);
925
970
  const clients = connect.projects.map(
926
971
  (projectId) => startTunnelClient({
927
972
  connectUrl: connect.url,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apiblaze",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Dev tunnel CLI for APIblaze — route localhost projects through your APIblaze endpoints",
5
5
  "keywords": [
6
6
  "apiblaze",