apiblaze 0.1.19 → 0.1.20

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 +58 -16
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -199,10 +199,10 @@ var init_api = __esm({
199
199
 
200
200
  // src/index.ts
201
201
  var import_commander = require("commander");
202
- var import_chalk9 = __toESM(require("chalk"));
202
+ var import_chalk10 = __toESM(require("chalk"));
203
203
 
204
204
  // package.json
205
- var version = "0.1.19";
205
+ var version = "0.1.20";
206
206
 
207
207
  // src/index.ts
208
208
  init_types();
@@ -1064,12 +1064,50 @@ async function runLogout() {
1064
1064
  console.log(import_chalk7.default.green(`\u2714 Logged out${who ? ` (${who})` : ""}.`));
1065
1065
  }
1066
1066
 
1067
- // src/commands/team.ts
1067
+ // src/commands/whoami.ts
1068
1068
  var import_chalk8 = __toESM(require("chalk"));
1069
1069
  init_auth();
1070
+ async function runWhoami(opts = {}) {
1071
+ const creds = loadCredentials();
1072
+ if (!creds) {
1073
+ if (opts.json) {
1074
+ console.log(JSON.stringify({ loggedIn: false }, null, 2));
1075
+ } else {
1076
+ console.log(import_chalk8.default.yellow("Not logged in. Run `apiblaze login` first."));
1077
+ }
1078
+ return;
1079
+ }
1080
+ const expired = Date.now() >= creds.expiresAt;
1081
+ if (opts.json) {
1082
+ console.log(JSON.stringify({
1083
+ loggedIn: true,
1084
+ expired,
1085
+ apiblazeUserId: creds.apiblazeUserId ?? null,
1086
+ githubHandle: creds.githubHandle ?? null,
1087
+ email: creds.email ?? null,
1088
+ teamId: creds.teamId ?? null,
1089
+ teamName: creds.teamName ?? null
1090
+ }, null, 2));
1091
+ return;
1092
+ }
1093
+ const who = creds.githubHandle ?? creds.email ?? creds.apiblazeUserId ?? "unknown";
1094
+ console.log(`${import_chalk8.default.cyan("Signed in as")} ${import_chalk8.default.bold(who)}`);
1095
+ if (creds.email && creds.email !== who) console.log(` Email: ${creds.email}`);
1096
+ if (creds.apiblazeUserId) console.log(` User ID: ${creds.apiblazeUserId}`);
1097
+ if (creds.teamName || creds.teamId) {
1098
+ console.log(` Team: ${import_chalk8.default.bold(creds.teamName ?? creds.teamId)}${creds.teamName && creds.teamId ? import_chalk8.default.gray(` (${creds.teamId})`) : ""}`);
1099
+ }
1100
+ if (expired) {
1101
+ console.log(import_chalk8.default.yellow("\n\u26A0 Session expired. Run `apiblaze login` to re-authenticate."));
1102
+ }
1103
+ }
1104
+
1105
+ // src/commands/team.ts
1106
+ var import_chalk9 = __toESM(require("chalk"));
1107
+ init_auth();
1070
1108
  init_api();
1071
1109
  function fail3(message) {
1072
- console.error(import_chalk8.default.red(`Error: ${message}`));
1110
+ console.error(import_chalk9.default.red(`Error: ${message}`));
1073
1111
  process.exit(1);
1074
1112
  }
1075
1113
  async function runTeam(arg) {
@@ -1091,7 +1129,7 @@ async function runTeam(arg) {
1091
1129
  }
1092
1130
  } else if (teams.length === 1) {
1093
1131
  chosen = teams[0];
1094
- console.log(`${import_chalk8.default.cyan("\u2192")} You only have one team: ${import_chalk8.default.bold(chosen.name)}`);
1132
+ console.log(`${import_chalk9.default.cyan("\u2192")} You only have one team: ${import_chalk9.default.bold(chosen.name)}`);
1095
1133
  } else if (process.stdin.isTTY) {
1096
1134
  const { default: inquirer2 } = await import("inquirer");
1097
1135
  const { picked } = await inquirer2.prompt([{
@@ -1106,8 +1144,8 @@ async function runTeam(arg) {
1106
1144
  fail3(`Specify a team: \`apiblaze team <name|id>\`. Available: ${teams.map((t) => t.name).join(", ")}.`);
1107
1145
  }
1108
1146
  saveCredentials({ ...creds, teamId: chosen.teamId, teamName: chosen.name });
1109
- console.log(import_chalk8.default.green(`
1110
- \u2714 Active team: ${import_chalk8.default.bold(chosen.name)}`));
1147
+ console.log(import_chalk9.default.green(`
1148
+ \u2714 Active team: ${import_chalk9.default.bold(chosen.name)}`));
1111
1149
  }
1112
1150
 
1113
1151
  // src/index.ts
@@ -1137,6 +1175,14 @@ program.command("logout").description("Sign out \u2014 remove stored credentials
1137
1175
  process.exit(1);
1138
1176
  }
1139
1177
  });
1178
+ program.command("whoami").description("Show the signed-in identity and active team").option("--json", "Output machine-readable JSON").action(async (opts) => {
1179
+ try {
1180
+ await runWhoami(opts);
1181
+ } catch (err) {
1182
+ printError(err);
1183
+ process.exit(1);
1184
+ }
1185
+ });
1140
1186
  program.command("claim").description("Claim an anonymously-created proxy into one of your teams (requires login)").argument("[code]", "Claim code from `create` output / claim URL (prompted if omitted)").option("--team <id|name>", "Team to claim into (defaults to your active team)").option("--json", "Output machine-readable JSON (non-interactive)").action(async (code, opts) => {
1141
1187
  try {
1142
1188
  await runClaim(code, opts);
@@ -1165,7 +1211,7 @@ program.command("dev").description("Start a dev tunnel for your localhost projec
1165
1211
  try {
1166
1212
  const resolved = parseInt(port ?? opts.port, 10);
1167
1213
  if (Number.isNaN(resolved)) {
1168
- console.error(import_chalk9.default.red(`Invalid port: ${port ?? opts.port}`));
1214
+ console.error(import_chalk10.default.red(`Invalid port: ${port ?? opts.port}`));
1169
1215
  process.exit(1);
1170
1216
  }
1171
1217
  await runDev({ port: resolved });
@@ -1184,16 +1230,12 @@ Examples:
1184
1230
  # Non-interactive (CI / scripts):
1185
1231
  $ npx apiblaze create --target https://api.example.com --name myapi --json
1186
1232
 
1187
- # Claim that anonymous proxy into your team (after signing in):
1188
- $ npx apiblaze login
1189
- $ npx apiblaze claim G7QN-62JB-VN3D-RQNR-F6EZ
1190
- $ npx apiblaze claim G7QN-62JB-VN3D-RQNR-F6EZ --team my-team
1191
-
1192
1233
  # Sign in, then create under your team:
1193
1234
  $ npx apiblaze login
1194
1235
  $ npx apiblaze create --name myapi --target https://api.example.com --auth api_key
1195
1236
 
1196
1237
  # Manage:
1238
+ $ npx apiblaze whoami
1197
1239
  $ npx apiblaze projects
1198
1240
  $ npx apiblaze team
1199
1241
  $ npx apiblaze dev 3000
@@ -1202,13 +1244,13 @@ Examples:
1202
1244
  );
1203
1245
  function printError(err) {
1204
1246
  if (err instanceof ApiError) {
1205
- console.error(import_chalk9.default.red(`
1247
+ console.error(import_chalk10.default.red(`
1206
1248
  API error (${err.status}): ${err.message}`));
1207
1249
  } else if (err instanceof Error) {
1208
- console.error(import_chalk9.default.red(`
1250
+ console.error(import_chalk10.default.red(`
1209
1251
  Error: ${err.message}`));
1210
1252
  } else {
1211
- console.error(import_chalk9.default.red("\nUnknown error"));
1253
+ console.error(import_chalk10.default.red("\nUnknown error"));
1212
1254
  }
1213
1255
  }
1214
1256
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apiblaze",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "Dev tunnel CLI for APIblaze — route localhost projects through your APIblaze endpoints",
5
5
  "keywords": [
6
6
  "apiblaze",