apiblaze 0.17.0 → 0.17.2

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 +39 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -351,6 +351,9 @@ async function cpFetch(cpKey, apiPath, opts = {}) {
351
351
  parsed = text;
352
352
  }
353
353
  if (!res.ok) {
354
+ if (res.status === 401 && loadAnonCred()?.cp_key === cpKey) {
355
+ clearAnonCred();
356
+ }
354
357
  const msg = parsed && typeof parsed === "object" && (parsed.details ?? parsed.error) || res.statusText;
355
358
  throw new ApiError(res.status, typeof msg === "string" ? msg : JSON.stringify(msg), parsed);
356
359
  }
@@ -687,7 +690,7 @@ var import_commander = require("commander");
687
690
  var import_chalk35 = __toESM(require("chalk"));
688
691
 
689
692
  // package.json
690
- var version = "0.17.0";
693
+ var version = "0.17.2";
691
694
 
692
695
  // src/index.ts
693
696
  init_types();
@@ -825,6 +828,12 @@ async function offerClaimPendingAnon() {
825
828
  console.log(import_chalk2.default.green(` \u2714 Claimed your anonymous proxies into your account (team ${import_chalk2.default.bold(t.team_id)}).`));
826
829
  } catch (err) {
827
830
  const { ApiError: ApiError2 } = await Promise.resolve().then(() => (init_types(), types_exports));
831
+ const code = err instanceof ApiError2 && typeof err.body === "object" && err.body ? err.body.error : void 0;
832
+ if (code === "already_claimed" || code === "not_claimable") {
833
+ clearAnonCred2();
834
+ console.log(import_chalk2.default.dim(" Those anonymous proxies were already claimed \u2014 nothing to do."));
835
+ return;
836
+ }
828
837
  const why = err instanceof ApiError2 ? err.message : err instanceof Error ? err.message : "error";
829
838
  console.log(import_chalk2.default.yellow(` Couldn't auto-claim (${why}). Run \`apiblaze claim\` to retry.`));
830
839
  }
@@ -1914,10 +1923,8 @@ async function runAnonymousCreate(opts) {
1914
1923
  const claimCode = result.claim_code || cred?.claim_code;
1915
1924
  if (claimCode) {
1916
1925
  console.log();
1917
- console.log(` ${import_chalk6.default.yellow("\u26A0 Anonymous \u2014 claim within 30 days or it expires.")} Everything you create`);
1918
- console.log(` with the CP key shares ONE workspace. To keep it all in one shot:`);
1919
- console.log(` ${import_chalk6.default.cyan("apiblaze login")} ${import_chalk6.default.dim("(prompts to claim your workspace into your account)")}`);
1920
- console.log(import_chalk6.default.dim(` From another machine: apiblaze claim ${claimCode} (add --team <name> to merge into an existing team)`));
1926
+ console.log(` ${import_chalk6.default.yellow("\u26A0 Anonymous \u2014 claim within 30 days or it expires.")} To claim these proxies:`);
1927
+ console.log(` ${import_chalk6.default.cyan(`npx apiblaze login && npx apiblaze claim ${claimCode}`)}`);
1921
1928
  } else if (result.claim_url) {
1922
1929
  console.log();
1923
1930
  console.log(` ${import_chalk6.default.yellow("\u26A0 Anonymous proxy \u2014 claim it to your account within 30 days or it expires:")}`);
@@ -1967,9 +1974,17 @@ async function runClaim(claimCodeArg, opts) {
1967
1974
  } catch (err) {
1968
1975
  if (err instanceof ApiError) {
1969
1976
  const c = typeof err.body === "object" && err.body ? err.body.error : void 0;
1970
- if (c === "already_claimed") fail2("That claim code has already been used.");
1971
- if (c === "expired") fail2("That claim code has expired. Create a fresh setup with `apiblaze create`/`init`.");
1972
- if (c === "not_claimable") fail2("That workspace can no longer be claimed (it already belongs to an account).");
1977
+ if (c === "already_claimed" || c === "not_claimable") {
1978
+ if (fromLocal) clearAnonCred();
1979
+ console.log(import_chalk7.default.yellow("\nThis workspace was already claimed (e.g. on dashboard.apiblaze.com)."));
1980
+ if (fromLocal) console.log(import_chalk7.default.dim(" Cleared the local anonymous key."));
1981
+ console.log(import_chalk7.default.dim(" Your proxies are safe under your account \u2014 manage them with `apiblaze login`."));
1982
+ return;
1983
+ }
1984
+ if (c === "expired") {
1985
+ if (fromLocal) clearAnonCred();
1986
+ fail2("That claim code has expired. Create a fresh setup with `apiblaze create`/`init`.");
1987
+ }
1973
1988
  if (err.status === 404) fail2("That claim code isn't valid \u2014 check it and try again.");
1974
1989
  if (err.status === 403) fail2(`You're not a member of team "${opts.team}".`);
1975
1990
  fail2(`Could not claim: ${err.message}`);
@@ -2163,9 +2178,11 @@ async function runLogout(opts = {}) {
2163
2178
  // src/commands/whoami.ts
2164
2179
  var import_chalk9 = __toESM(require("chalk"));
2165
2180
  init_auth();
2181
+ init_anon_cred();
2166
2182
  async function runWhoami(opts = {}) {
2167
2183
  const creds = loadCredentials();
2168
2184
  const consumer2 = loadConsumer();
2185
+ const anon = loadAnonCred();
2169
2186
  if (opts.json) {
2170
2187
  console.log(JSON.stringify({
2171
2188
  producer: creds ? {
@@ -2177,7 +2194,8 @@ async function runWhoami(opts = {}) {
2177
2194
  teamId: creds.teamId ?? null,
2178
2195
  teamName: creds.teamName ?? null
2179
2196
  } : { loggedIn: false },
2180
- consumer: consumer2 ? { loggedIn: true, expired: Date.now() >= consumer2.expiresAt, tenant: consumer2.tenant, email: consumer2.email ?? null } : { loggedIn: false }
2197
+ consumer: consumer2 ? { loggedIn: true, expired: Date.now() >= consumer2.expiresAt, tenant: consumer2.tenant, email: consumer2.email ?? null } : { loggedIn: false },
2198
+ anonymous: anon ? { exists: true, teamId: anon.team_id, claimCode: anon.claim_code ?? null, cpKeyPrefix: anon.cp_key.slice(0, 11) } : { exists: false }
2181
2199
  }, null, 2));
2182
2200
  return;
2183
2201
  }
@@ -2192,6 +2210,16 @@ async function runWhoami(opts = {}) {
2192
2210
  if (creds.activeTenant) console.log(` Tenant scope: ${import_chalk9.default.bold(creds.activeTenant)} ${import_chalk9.default.dim("(clear: `apiblaze tenant use --clear`)")}`);
2193
2211
  if (Date.now() >= creds.expiresAt) console.log(import_chalk9.default.yellow(" \u26A0 Session expired \u2014 run `apiblaze login`."));
2194
2212
  }
2213
+ if (anon) {
2214
+ const masked = `${anon.cp_key.slice(0, 11)}\u2026${anon.cp_key.slice(-4)}`;
2215
+ console.log(import_chalk9.default.bold("\nAnonymous workspace") + import_chalk9.default.dim(" (created without an account \u2014 unclaimed)"));
2216
+ console.log(` Team: ${import_chalk9.default.bold(anon.team_id)}`);
2217
+ console.log(` CP key: ${import_chalk9.default.bold(masked)} ${import_chalk9.default.dim("controls the proxies you created anonymously")}`);
2218
+ console.log(
2219
+ import_chalk9.default.dim(` Keep it: ${import_chalk9.default.cyan("apiblaze login")} then ${import_chalk9.default.cyan("apiblaze claim")}`) + (anon.claim_code ? import_chalk9.default.dim(` \xB7 from another machine: ${import_chalk9.default.cyan(`apiblaze claim ${anon.claim_code}`)}`) : "")
2220
+ );
2221
+ if (creds) console.log(import_chalk9.default.dim(" (you're logged in \u2014 `apiblaze claim` folds this workspace into your account)"));
2222
+ }
2195
2223
  console.log(import_chalk9.default.bold("\nAPI Consumer"));
2196
2224
  if (!consumer2) {
2197
2225
  console.log(import_chalk9.default.dim(" Not logged in. Run `apiblaze consumer login`."));
@@ -4394,15 +4422,13 @@ async function transformsMenu(proj2) {
4394
4422
  { type: "input", name: "destination", message: `Destination field ${fieldHint}:`, validate: (s) => !!s || "required" },
4395
4423
  { type: "confirm", name: "strip", message: "Remove the source field after copying?", default: false }
4396
4424
  ]);
4397
- const source_fns = await buildFns("Transform the value as it is READ (source functions)");
4398
- const dest_fns = await buildFns("Transform the value as it is WRITTEN (destination functions)");
4425
+ const source_fns = await buildFns("Transform the value");
4399
4426
  action2 = {
4400
4427
  type: "copy",
4401
4428
  source: a.source,
4402
4429
  destination: a.destination,
4403
4430
  ...a.strip ? { strip_source: true } : {},
4404
- ...source_fns.length ? { source_fns } : {},
4405
- ...dest_fns.length ? { dest_fns } : {}
4431
+ ...source_fns.length ? { source_fns } : {}
4406
4432
  };
4407
4433
  }
4408
4434
  const condition = await buildCondition(ans.phase);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apiblaze",
3
- "version": "0.17.0",
3
+ "version": "0.17.2",
4
4
  "description": "APIblaze CLI + sidecar — manage API proxies, run dev tunnels, and route a Next.js app's egress through APIblaze with one command",
5
5
  "keywords": [
6
6
  "apiblaze",