apiblaze 0.17.1 → 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.
- package/dist/index.js +37 -9
- 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.
|
|
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.")}
|
|
1918
|
-
console.log(`
|
|
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"
|
|
1971
|
-
|
|
1972
|
-
|
|
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`."));
|
package/package.json
CHANGED