apiblaze 0.8.0 → 0.9.0
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 +41 -93
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -99,7 +99,6 @@ var api_exports = {};
|
|
|
99
99
|
__export(api_exports, {
|
|
100
100
|
agentCall: () => agentCall,
|
|
101
101
|
checkProxyName: () => checkProxyName,
|
|
102
|
-
claimProxy: () => claimProxy,
|
|
103
102
|
claimTeam: () => claimTeam,
|
|
104
103
|
createProxy: () => createProxy,
|
|
105
104
|
createProxyAnonymous: () => createProxyAnonymous,
|
|
@@ -194,16 +193,10 @@ async function createProxy(payload) {
|
|
|
194
193
|
body: JSON.stringify(payload)
|
|
195
194
|
});
|
|
196
195
|
}
|
|
197
|
-
async function
|
|
198
|
-
return apiFetch("/api/cli/claim", {
|
|
199
|
-
method: "POST",
|
|
200
|
-
body: JSON.stringify({ claimCode, team_id: teamId })
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
async function claimTeam(code) {
|
|
196
|
+
async function claimTeam(code, teamId) {
|
|
204
197
|
return apiFetch("/api/cli/claim-team", {
|
|
205
198
|
method: "POST",
|
|
206
|
-
body: JSON.stringify({ code })
|
|
199
|
+
body: JSON.stringify({ code, ...teamId ? { team_id: teamId } : {} })
|
|
207
200
|
});
|
|
208
201
|
}
|
|
209
202
|
async function sidecarInitAnonymous() {
|
|
@@ -312,7 +305,7 @@ var import_commander = require("commander");
|
|
|
312
305
|
var import_chalk30 = __toESM(require("chalk"));
|
|
313
306
|
|
|
314
307
|
// package.json
|
|
315
|
-
var version = "0.
|
|
308
|
+
var version = "0.9.0";
|
|
316
309
|
|
|
317
310
|
// src/index.ts
|
|
318
311
|
init_types();
|
|
@@ -1530,7 +1523,7 @@ async function runAnonymousCreate(opts) {
|
|
|
1530
1523
|
} else {
|
|
1531
1524
|
result = await createProxyAnonymous(body);
|
|
1532
1525
|
if (result.cp_key && result.team_id) {
|
|
1533
|
-
saveAnonCred2(result.cp_key, result.team_id, result.
|
|
1526
|
+
saveAnonCred2(result.cp_key, result.team_id, result.claim_code);
|
|
1534
1527
|
}
|
|
1535
1528
|
}
|
|
1536
1529
|
spinner?.succeed(import_chalk6.default.green("Proxy created!"));
|
|
@@ -1564,13 +1557,13 @@ async function runAnonymousCreate(opts) {
|
|
|
1564
1557
|
console.log(import_chalk6.default.dim("\n Save this now \u2014 send it as the X-API-Key header. It may not be shown again."));
|
|
1565
1558
|
}
|
|
1566
1559
|
if (prodEndpoint) printCurlExample(prodEndpoint, opts.auth || "api_key", apiKey, result.portal);
|
|
1567
|
-
const claimCode = result.
|
|
1560
|
+
const claimCode = result.claim_code || cred?.claim_code;
|
|
1568
1561
|
if (claimCode) {
|
|
1569
1562
|
console.log();
|
|
1570
|
-
console.log(` ${import_chalk6.default.yellow("\u26A0 Anonymous \u2014 claim within 30 days or it expires.")}
|
|
1571
|
-
console.log(`
|
|
1572
|
-
console.log(` ${import_chalk6.default.cyan("apiblaze login")} ${import_chalk6.default.dim("(prompts to claim
|
|
1573
|
-
console.log(import_chalk6.default.dim(` From another machine: apiblaze claim ${claimCode}`));
|
|
1563
|
+
console.log(` ${import_chalk6.default.yellow("\u26A0 Anonymous \u2014 claim within 30 days or it expires.")} Everything you create`);
|
|
1564
|
+
console.log(` with the CP key shares ONE workspace. To keep it all in one shot:`);
|
|
1565
|
+
console.log(` ${import_chalk6.default.cyan("apiblaze login")} ${import_chalk6.default.dim("(prompts to claim your workspace into your account)")}`);
|
|
1566
|
+
console.log(import_chalk6.default.dim(` From another machine: apiblaze claim ${claimCode} (add --team <name> to merge into an existing team)`));
|
|
1574
1567
|
} else if (result.claim_url) {
|
|
1575
1568
|
console.log();
|
|
1576
1569
|
console.log(` ${import_chalk6.default.yellow("\u26A0 Anonymous proxy \u2014 claim it to your account within 30 days or it expires:")}`);
|
|
@@ -1591,100 +1584,55 @@ function fail2(message) {
|
|
|
1591
1584
|
}
|
|
1592
1585
|
async function runClaim(claimCodeArg, opts) {
|
|
1593
1586
|
const creds = loadCredentials();
|
|
1594
|
-
if (!creds)
|
|
1595
|
-
fail2("Not logged in. Run `apiblaze login` first, then claim.");
|
|
1596
|
-
}
|
|
1587
|
+
if (!creds) fail2("Not logged in. Run `apiblaze login` first, then claim.");
|
|
1597
1588
|
let claimCode = (claimCodeArg ?? "").trim();
|
|
1598
|
-
let
|
|
1589
|
+
let fromLocal = false;
|
|
1599
1590
|
if (!claimCode) {
|
|
1600
|
-
const
|
|
1601
|
-
if (
|
|
1602
|
-
claimCode =
|
|
1603
|
-
|
|
1591
|
+
const c = loadAnonCred();
|
|
1592
|
+
if (c?.claim_code) {
|
|
1593
|
+
claimCode = c.claim_code;
|
|
1594
|
+
fromLocal = true;
|
|
1604
1595
|
}
|
|
1605
1596
|
}
|
|
1606
1597
|
if (!claimCode && process.stdin.isTTY) {
|
|
1607
1598
|
const { default: inquirer2 } = await import("inquirer");
|
|
1608
|
-
const { code } = await inquirer2.prompt([{
|
|
1609
|
-
type: "input",
|
|
1610
|
-
name: "code",
|
|
1611
|
-
message: "Claim code (from the create output / claim URL):"
|
|
1612
|
-
}]);
|
|
1599
|
+
const { code } = await inquirer2.prompt([{ type: "input", name: "code", message: "Claim code:" }]);
|
|
1613
1600
|
claimCode = (code ?? "").trim();
|
|
1614
1601
|
}
|
|
1615
|
-
if (!claimCode)
|
|
1616
|
-
|
|
1602
|
+
if (!claimCode) fail2("Nothing to claim on this machine. Run `apiblaze claim <code>`, or `apiblaze create`/`init` first.");
|
|
1603
|
+
let targetTeamId;
|
|
1604
|
+
if (opts.team) {
|
|
1605
|
+
const teams = await getTeams().catch(() => []);
|
|
1606
|
+
const match = teams.find((t) => t.teamId === opts.team || t.name.toLowerCase() === opts.team.toLowerCase());
|
|
1607
|
+
if (!match) fail2(`Team "${opts.team}" not found. Available: ${teams.map((t) => t.name).join(", ") || "(none)"}.`);
|
|
1608
|
+
targetTeamId = match.teamId;
|
|
1617
1609
|
}
|
|
1610
|
+
let res;
|
|
1618
1611
|
try {
|
|
1619
|
-
|
|
1620
|
-
if (fromLocalSession) clearAnonCred();
|
|
1621
|
-
if (opts.json) {
|
|
1622
|
-
console.log(JSON.stringify(t, null, 2));
|
|
1623
|
-
return;
|
|
1624
|
-
}
|
|
1625
|
-
console.log(import_chalk7.default.green(`
|
|
1626
|
-
\u2714 Claimed the whole team into your account.`));
|
|
1627
|
-
console.log(` Team: ${import_chalk7.default.bold(t.team_id)}`);
|
|
1628
|
-
console.log(` Its proxies + keys are now yours. Switch to it with ${import_chalk7.default.cyan(`apiblaze team ${t.team_id}`)}.`);
|
|
1629
|
-
console.log(`
|
|
1630
|
-
Manage it at ${import_chalk7.default.cyan("https://dashboard.apiblaze.com/dashboard")}`);
|
|
1631
|
-
return;
|
|
1612
|
+
res = await claimTeam(claimCode, targetTeamId);
|
|
1632
1613
|
} catch (err) {
|
|
1633
|
-
if (err instanceof ApiError
|
|
1634
|
-
const
|
|
1635
|
-
if (
|
|
1636
|
-
if (
|
|
1637
|
-
if (
|
|
1614
|
+
if (err instanceof ApiError) {
|
|
1615
|
+
const c = typeof err.body === "object" && err.body ? err.body.error : void 0;
|
|
1616
|
+
if (c === "already_claimed") fail2("That claim code has already been used.");
|
|
1617
|
+
if (c === "expired") fail2("That claim code has expired. Create a fresh setup with `apiblaze create`/`init`.");
|
|
1618
|
+
if (c === "not_claimable") fail2("That workspace can no longer be claimed (it already belongs to an account).");
|
|
1619
|
+
if (err.status === 404) fail2("That claim code isn't valid \u2014 check it and try again.");
|
|
1620
|
+
if (err.status === 403) fail2(`You're not a member of team "${opts.team}".`);
|
|
1638
1621
|
fail2(`Could not claim: ${err.message}`);
|
|
1639
1622
|
}
|
|
1640
|
-
}
|
|
1641
|
-
const teams = await getTeams().catch(() => []);
|
|
1642
|
-
if (teams.length === 0) {
|
|
1643
|
-
fail2("No teams found for your account.");
|
|
1644
|
-
}
|
|
1645
|
-
let teamId;
|
|
1646
|
-
if (opts.team) {
|
|
1647
|
-
const match = teams.find(
|
|
1648
|
-
(t) => t.teamId === opts.team || t.name.toLowerCase() === opts.team.toLowerCase()
|
|
1649
|
-
);
|
|
1650
|
-
if (!match) {
|
|
1651
|
-
fail2(`Team "${opts.team}" not found. Available: ${teams.map((t) => t.name).join(", ")}.`);
|
|
1652
|
-
}
|
|
1653
|
-
teamId = match.teamId;
|
|
1654
|
-
} else if (creds.teamId && teams.some((t) => t.teamId === creds.teamId)) {
|
|
1655
|
-
teamId = creds.teamId;
|
|
1656
|
-
} else if (teams.length === 1) {
|
|
1657
|
-
teamId = teams[0].teamId;
|
|
1658
|
-
} else if (process.stdin.isTTY) {
|
|
1659
|
-
const { default: inquirer2 } = await import("inquirer");
|
|
1660
|
-
const { picked } = await inquirer2.prompt([{
|
|
1661
|
-
type: "list",
|
|
1662
|
-
name: "picked",
|
|
1663
|
-
message: "Claim into which team?",
|
|
1664
|
-
choices: teams.map((t) => ({ name: t.name, value: t.teamId }))
|
|
1665
|
-
}]);
|
|
1666
|
-
teamId = picked;
|
|
1667
|
-
} else {
|
|
1668
|
-
fail2(`Specify a team: \`apiblaze claim ${claimCode} --team <name|id>\`. Available: ${teams.map((t) => t.name).join(", ")}.`);
|
|
1669
|
-
}
|
|
1670
|
-
const teamName = teams.find((t) => t.teamId === teamId)?.name ?? teamId;
|
|
1671
|
-
let result;
|
|
1672
|
-
try {
|
|
1673
|
-
result = await claimProxy(claimCode, teamId);
|
|
1674
|
-
} catch (err) {
|
|
1675
|
-
if (err instanceof ApiError) fail2(`That claim code isn't valid \u2014 it may be mistyped, already claimed, or expired.`);
|
|
1676
1623
|
throw err;
|
|
1677
1624
|
}
|
|
1625
|
+
if (fromLocal) clearAnonCred();
|
|
1678
1626
|
if (opts.json) {
|
|
1679
|
-
console.log(JSON.stringify(
|
|
1627
|
+
console.log(JSON.stringify(res, null, 2));
|
|
1680
1628
|
return;
|
|
1681
1629
|
}
|
|
1682
|
-
console.log(import_chalk7.default.green(
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
console.log(
|
|
1687
|
-
|
|
1630
|
+
console.log(import_chalk7.default.green("\n\u2714 Claimed your anonymous workspace into your account."));
|
|
1631
|
+
if (res.merged) {
|
|
1632
|
+
console.log(` Merged ${import_chalk7.default.bold(String(res.proxy_count ?? ""))} prox${res.proxy_count === 1 ? "y" : "ies"} into team ${import_chalk7.default.bold(res.team_id)}.`);
|
|
1633
|
+
} else {
|
|
1634
|
+
console.log(` It's now your team ${import_chalk7.default.bold(res.team_id)}. Switch to it with ${import_chalk7.default.cyan(`apiblaze team ${res.team_id}`)}.`);
|
|
1635
|
+
console.log(import_chalk7.default.dim(` (Tip: re-run with --team <name> to merge into an existing team instead.)`));
|
|
1688
1636
|
}
|
|
1689
1637
|
console.log(`
|
|
1690
1638
|
Manage it at ${import_chalk7.default.cyan("https://dashboard.apiblaze.com/dashboard")}`);
|
|
@@ -3685,7 +3633,7 @@ program.command("whoami").description("Show who you are \u2014 both API Producer
|
|
|
3685
3633
|
process.exit(1);
|
|
3686
3634
|
}
|
|
3687
3635
|
});
|
|
3688
|
-
program.command("claim").description("Claim
|
|
3636
|
+
program.command("claim").description("Claim your anonymous workspace into your account (requires login)").argument("[code]", "Claim code from `create`/`init` output (omit to claim this machine's workspace)").option("--team <id|name>", "Merge into this existing team (default: promote to a new team)").option("--json", "Output machine-readable JSON (non-interactive)").action(async (code, opts) => {
|
|
3689
3637
|
try {
|
|
3690
3638
|
await runClaim(code, opts);
|
|
3691
3639
|
} catch (err) {
|
package/package.json
CHANGED