apiblaze 0.1.18 → 0.1.19
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 +137 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -51,6 +51,14 @@ function saveCredentials(creds) {
|
|
|
51
51
|
fs.writeFileSync(CREDENTIALS_PATH, JSON.stringify(creds, null, 2), "utf-8");
|
|
52
52
|
fs.chmodSync(CREDENTIALS_PATH, 384);
|
|
53
53
|
}
|
|
54
|
+
function clearCredentials() {
|
|
55
|
+
try {
|
|
56
|
+
fs.unlinkSync(CREDENTIALS_PATH);
|
|
57
|
+
return true;
|
|
58
|
+
} catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
54
62
|
function loadCredentials() {
|
|
55
63
|
try {
|
|
56
64
|
const raw = fs.readFileSync(CREDENTIALS_PATH, "utf-8");
|
|
@@ -85,6 +93,7 @@ var init_auth = __esm({
|
|
|
85
93
|
var api_exports = {};
|
|
86
94
|
__export(api_exports, {
|
|
87
95
|
checkProxyName: () => checkProxyName,
|
|
96
|
+
claimProxy: () => claimProxy,
|
|
88
97
|
createProxy: () => createProxy,
|
|
89
98
|
createProxyAnonymous: () => createProxyAnonymous,
|
|
90
99
|
deleteDevTunnel: () => deleteDevTunnel,
|
|
@@ -159,6 +168,12 @@ async function createProxy(payload) {
|
|
|
159
168
|
body: JSON.stringify(payload)
|
|
160
169
|
});
|
|
161
170
|
}
|
|
171
|
+
async function claimProxy(claimCode, teamId) {
|
|
172
|
+
return apiFetch("/api/cli/claim", {
|
|
173
|
+
method: "POST",
|
|
174
|
+
body: JSON.stringify({ claimCode, team_id: teamId })
|
|
175
|
+
});
|
|
176
|
+
}
|
|
162
177
|
async function putDevTunnel(payload) {
|
|
163
178
|
return apiFetch("/api/cli/dev-tunnel", {
|
|
164
179
|
method: "PUT",
|
|
@@ -184,10 +199,10 @@ var init_api = __esm({
|
|
|
184
199
|
|
|
185
200
|
// src/index.ts
|
|
186
201
|
var import_commander = require("commander");
|
|
187
|
-
var
|
|
202
|
+
var import_chalk9 = __toESM(require("chalk"));
|
|
188
203
|
|
|
189
204
|
// package.json
|
|
190
|
-
var version = "0.1.
|
|
205
|
+
var version = "0.1.19";
|
|
191
206
|
|
|
192
207
|
// src/index.ts
|
|
193
208
|
init_types();
|
|
@@ -963,7 +978,7 @@ async function runAnonymousCreate(opts) {
|
|
|
963
978
|
console.log();
|
|
964
979
|
}
|
|
965
980
|
|
|
966
|
-
// src/commands/
|
|
981
|
+
// src/commands/claim.ts
|
|
967
982
|
var import_chalk6 = __toESM(require("chalk"));
|
|
968
983
|
init_auth();
|
|
969
984
|
init_api();
|
|
@@ -971,26 +986,112 @@ function fail2(message) {
|
|
|
971
986
|
console.error(import_chalk6.default.red(`Error: ${message}`));
|
|
972
987
|
process.exit(1);
|
|
973
988
|
}
|
|
974
|
-
async function
|
|
989
|
+
async function runClaim(claimCodeArg, opts) {
|
|
975
990
|
const creds = loadCredentials();
|
|
976
991
|
if (!creds) {
|
|
977
|
-
fail2("Not logged in. Run `apiblaze login` first.");
|
|
992
|
+
fail2("Not logged in. Run `apiblaze login` first, then claim.");
|
|
993
|
+
}
|
|
994
|
+
let claimCode = (claimCodeArg ?? "").trim();
|
|
995
|
+
if (!claimCode && process.stdin.isTTY) {
|
|
996
|
+
const { default: inquirer2 } = await import("inquirer");
|
|
997
|
+
const { code } = await inquirer2.prompt([{
|
|
998
|
+
type: "input",
|
|
999
|
+
name: "code",
|
|
1000
|
+
message: "Claim code (from the create output / claim URL):"
|
|
1001
|
+
}]);
|
|
1002
|
+
claimCode = (code ?? "").trim();
|
|
1003
|
+
}
|
|
1004
|
+
if (!claimCode) {
|
|
1005
|
+
fail2("A claim code is required: `apiblaze claim <code>`.");
|
|
978
1006
|
}
|
|
979
1007
|
const teams = await getTeams().catch(() => []);
|
|
980
1008
|
if (teams.length === 0) {
|
|
981
1009
|
fail2("No teams found for your account.");
|
|
982
1010
|
}
|
|
1011
|
+
let teamId;
|
|
1012
|
+
if (opts.team) {
|
|
1013
|
+
const match = teams.find(
|
|
1014
|
+
(t) => t.teamId === opts.team || t.name.toLowerCase() === opts.team.toLowerCase()
|
|
1015
|
+
);
|
|
1016
|
+
if (!match) {
|
|
1017
|
+
fail2(`Team "${opts.team}" not found. Available: ${teams.map((t) => t.name).join(", ")}.`);
|
|
1018
|
+
}
|
|
1019
|
+
teamId = match.teamId;
|
|
1020
|
+
} else if (creds.teamId && teams.some((t) => t.teamId === creds.teamId)) {
|
|
1021
|
+
teamId = creds.teamId;
|
|
1022
|
+
} else if (teams.length === 1) {
|
|
1023
|
+
teamId = teams[0].teamId;
|
|
1024
|
+
} else if (process.stdin.isTTY) {
|
|
1025
|
+
const { default: inquirer2 } = await import("inquirer");
|
|
1026
|
+
const { picked } = await inquirer2.prompt([{
|
|
1027
|
+
type: "list",
|
|
1028
|
+
name: "picked",
|
|
1029
|
+
message: "Claim into which team?",
|
|
1030
|
+
choices: teams.map((t) => ({ name: t.name, value: t.teamId }))
|
|
1031
|
+
}]);
|
|
1032
|
+
teamId = picked;
|
|
1033
|
+
} else {
|
|
1034
|
+
fail2(`Specify a team: \`apiblaze claim ${claimCode} --team <name|id>\`. Available: ${teams.map((t) => t.name).join(", ")}.`);
|
|
1035
|
+
}
|
|
1036
|
+
const teamName = teams.find((t) => t.teamId === teamId)?.name ?? teamId;
|
|
1037
|
+
const result = await claimProxy(claimCode, teamId);
|
|
1038
|
+
if (opts.json) {
|
|
1039
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
console.log(import_chalk6.default.green(`
|
|
1043
|
+
\u2714 Claimed into ${import_chalk6.default.bold(teamName)}.`));
|
|
1044
|
+
if (result.project_id) console.log(` Project: ${import_chalk6.default.bold(result.project_id)}`);
|
|
1045
|
+
if (result.endpoints?.length) {
|
|
1046
|
+
console.log(" Endpoints:");
|
|
1047
|
+
for (const e of result.endpoints) console.log(` ${e}`);
|
|
1048
|
+
}
|
|
1049
|
+
console.log(`
|
|
1050
|
+
Manage it at ${import_chalk6.default.cyan("https://dashboard.apiblaze.com/dashboard")}`);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// src/commands/logout.ts
|
|
1054
|
+
var import_chalk7 = __toESM(require("chalk"));
|
|
1055
|
+
init_auth();
|
|
1056
|
+
async function runLogout() {
|
|
1057
|
+
const creds = loadCredentials();
|
|
1058
|
+
const removed = clearCredentials();
|
|
1059
|
+
if (!removed) {
|
|
1060
|
+
console.log(import_chalk7.default.yellow("You were not logged in."));
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
const who = creds?.githubHandle ?? creds?.email;
|
|
1064
|
+
console.log(import_chalk7.default.green(`\u2714 Logged out${who ? ` (${who})` : ""}.`));
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// src/commands/team.ts
|
|
1068
|
+
var import_chalk8 = __toESM(require("chalk"));
|
|
1069
|
+
init_auth();
|
|
1070
|
+
init_api();
|
|
1071
|
+
function fail3(message) {
|
|
1072
|
+
console.error(import_chalk8.default.red(`Error: ${message}`));
|
|
1073
|
+
process.exit(1);
|
|
1074
|
+
}
|
|
1075
|
+
async function runTeam(arg) {
|
|
1076
|
+
const creds = loadCredentials();
|
|
1077
|
+
if (!creds) {
|
|
1078
|
+
fail3("Not logged in. Run `apiblaze login` first.");
|
|
1079
|
+
}
|
|
1080
|
+
const teams = await getTeams().catch(() => []);
|
|
1081
|
+
if (teams.length === 0) {
|
|
1082
|
+
fail3("No teams found for your account.");
|
|
1083
|
+
}
|
|
983
1084
|
let chosen;
|
|
984
1085
|
if (arg) {
|
|
985
1086
|
chosen = teams.find(
|
|
986
1087
|
(t) => t.teamId === arg || t.name.toLowerCase() === arg.toLowerCase()
|
|
987
1088
|
);
|
|
988
1089
|
if (!chosen) {
|
|
989
|
-
|
|
1090
|
+
fail3(`Team "${arg}" not found. Available: ${teams.map((t) => t.name).join(", ")}.`);
|
|
990
1091
|
}
|
|
991
1092
|
} else if (teams.length === 1) {
|
|
992
1093
|
chosen = teams[0];
|
|
993
|
-
console.log(`${
|
|
1094
|
+
console.log(`${import_chalk8.default.cyan("\u2192")} You only have one team: ${import_chalk8.default.bold(chosen.name)}`);
|
|
994
1095
|
} else if (process.stdin.isTTY) {
|
|
995
1096
|
const { default: inquirer2 } = await import("inquirer");
|
|
996
1097
|
const { picked } = await inquirer2.prompt([{
|
|
@@ -1002,11 +1103,11 @@ async function runTeam(arg) {
|
|
|
1002
1103
|
}]);
|
|
1003
1104
|
chosen = teams.find((t) => t.teamId === picked);
|
|
1004
1105
|
} else {
|
|
1005
|
-
|
|
1106
|
+
fail3(`Specify a team: \`apiblaze team <name|id>\`. Available: ${teams.map((t) => t.name).join(", ")}.`);
|
|
1006
1107
|
}
|
|
1007
1108
|
saveCredentials({ ...creds, teamId: chosen.teamId, teamName: chosen.name });
|
|
1008
|
-
console.log(
|
|
1009
|
-
\u2714 Active team: ${
|
|
1109
|
+
console.log(import_chalk8.default.green(`
|
|
1110
|
+
\u2714 Active team: ${import_chalk8.default.bold(chosen.name)}`));
|
|
1010
1111
|
}
|
|
1011
1112
|
|
|
1012
1113
|
// src/index.ts
|
|
@@ -1028,6 +1129,22 @@ program.command("create").description("Create a new API proxy (no login needed \
|
|
|
1028
1129
|
process.exit(1);
|
|
1029
1130
|
}
|
|
1030
1131
|
});
|
|
1132
|
+
program.command("logout").description("Sign out \u2014 remove stored credentials from this machine").action(async () => {
|
|
1133
|
+
try {
|
|
1134
|
+
await runLogout();
|
|
1135
|
+
} catch (err) {
|
|
1136
|
+
printError(err);
|
|
1137
|
+
process.exit(1);
|
|
1138
|
+
}
|
|
1139
|
+
});
|
|
1140
|
+
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
|
+
try {
|
|
1142
|
+
await runClaim(code, opts);
|
|
1143
|
+
} catch (err) {
|
|
1144
|
+
printError(err);
|
|
1145
|
+
process.exit(1);
|
|
1146
|
+
}
|
|
1147
|
+
});
|
|
1031
1148
|
program.command("team").description("Switch the active team").argument("[team]", "Team name or id to switch to (omit to choose interactively)").action(async (team) => {
|
|
1032
1149
|
try {
|
|
1033
1150
|
await runTeam(team);
|
|
@@ -1048,7 +1165,7 @@ program.command("dev").description("Start a dev tunnel for your localhost projec
|
|
|
1048
1165
|
try {
|
|
1049
1166
|
const resolved = parseInt(port ?? opts.port, 10);
|
|
1050
1167
|
if (Number.isNaN(resolved)) {
|
|
1051
|
-
console.error(
|
|
1168
|
+
console.error(import_chalk9.default.red(`Invalid port: ${port ?? opts.port}`));
|
|
1052
1169
|
process.exit(1);
|
|
1053
1170
|
}
|
|
1054
1171
|
await runDev({ port: resolved });
|
|
@@ -1067,6 +1184,11 @@ Examples:
|
|
|
1067
1184
|
# Non-interactive (CI / scripts):
|
|
1068
1185
|
$ npx apiblaze create --target https://api.example.com --name myapi --json
|
|
1069
1186
|
|
|
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
|
+
|
|
1070
1192
|
# Sign in, then create under your team:
|
|
1071
1193
|
$ npx apiblaze login
|
|
1072
1194
|
$ npx apiblaze create --name myapi --target https://api.example.com --auth api_key
|
|
@@ -1075,17 +1197,18 @@ Examples:
|
|
|
1075
1197
|
$ npx apiblaze projects
|
|
1076
1198
|
$ npx apiblaze team
|
|
1077
1199
|
$ npx apiblaze dev 3000
|
|
1200
|
+
$ npx apiblaze logout
|
|
1078
1201
|
`
|
|
1079
1202
|
);
|
|
1080
1203
|
function printError(err) {
|
|
1081
1204
|
if (err instanceof ApiError) {
|
|
1082
|
-
console.error(
|
|
1205
|
+
console.error(import_chalk9.default.red(`
|
|
1083
1206
|
API error (${err.status}): ${err.message}`));
|
|
1084
1207
|
} else if (err instanceof Error) {
|
|
1085
|
-
console.error(
|
|
1208
|
+
console.error(import_chalk9.default.red(`
|
|
1086
1209
|
Error: ${err.message}`));
|
|
1087
1210
|
} else {
|
|
1088
|
-
console.error(
|
|
1211
|
+
console.error(import_chalk9.default.red("\nUnknown error"));
|
|
1089
1212
|
}
|
|
1090
1213
|
}
|
|
1091
1214
|
program.parse(process.argv);
|