@proxylayer/cli 0.1.0 → 0.1.1
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/README.md +9 -9
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +263 -43
- package/dist/client.d.ts +3 -1
- package/dist/client.js +5 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -22,21 +22,21 @@ When an AI agent calls `auth_request_otp` and `auth_verify_otp`, the local `@pro
|
|
|
22
22
|
## CLI Usage
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
# Public catalog & pricing quote
|
|
26
|
-
npx @proxylayer/cli catalog
|
|
27
|
-
npx @proxylayer/cli quote
|
|
25
|
+
# Public catalog & pricing quote (install globally for `pl` shorthand: npm i -g @proxylayer/cli)
|
|
26
|
+
npx @proxylayer/cli catalog residential
|
|
27
|
+
npx @proxylayer/cli quote residential 10gb
|
|
28
|
+
npx @proxylayer/cli quote isp US 2 30d
|
|
28
29
|
|
|
29
|
-
# Email OTP sign-up / login (
|
|
30
|
-
npx @proxylayer/cli login
|
|
31
|
-
npx @proxylayer/cli login --email user@example.com --code 123456
|
|
30
|
+
# Email OTP sign-up / login (prompts step-by-step for Email and 6-digit code; or pass email directly if known)
|
|
31
|
+
npx @proxylayer/cli login
|
|
32
32
|
|
|
33
33
|
# Create checkout (stripe hosted link, crypto invoice, or prepaid balance)
|
|
34
|
-
npx @proxylayer/cli buy
|
|
35
|
-
npx @proxylayer/cli buy
|
|
34
|
+
npx @proxylayer/cli buy residential 10gb --method stripe
|
|
35
|
+
npx @proxylayer/cli buy isp US 1 30d --method balance
|
|
36
36
|
|
|
37
37
|
# Poll checkout status & output ready-to-use proxy strings
|
|
38
38
|
npx @proxylayer/cli checkout <checkoutSessionId>
|
|
39
|
-
npx @proxylayer/cli proxies
|
|
39
|
+
npx @proxylayer/cli proxies isp --raw
|
|
40
40
|
npx @proxylayer/cli residential --country us --session sticky --qty 5 --raw
|
|
41
41
|
```
|
|
42
42
|
|
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { realpathSync } from "node:fs";
|
|
3
|
-
import readline from "node:readline
|
|
3
|
+
import readline from "node:readline";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { ProxyLayer, ProxyLayerError, } from "./client.js";
|
|
6
6
|
import { clearConfig } from "./config.js";
|
|
7
7
|
import { runStdioMcpServer } from "./mcp.js";
|
|
8
|
-
const CLI_VERSION = "0.1.
|
|
8
|
+
const CLI_VERSION = "0.1.1";
|
|
9
9
|
const HELP_TEXT = `ProxyLayer CLI (${CLI_VERSION})
|
|
10
10
|
|
|
11
11
|
Usage:
|
|
12
|
-
proxylayer <command> [options]
|
|
12
|
+
proxylayer <command> [options] (or \`pl\` when installed globally)
|
|
13
13
|
|
|
14
14
|
Commands:
|
|
15
15
|
mcp Start local stdio MCP server (auto-saves API key on OTP verify)
|
|
16
|
-
login
|
|
16
|
+
login [email] Sign in or register via Email OTP and save API key locally
|
|
17
17
|
[--code <6-digits>] [--key-name <name>] [--access full|read]
|
|
18
18
|
whoami Show stored config path, email, baseUrl, and masked API key
|
|
19
19
|
logout Remove saved local credentials
|
|
20
|
-
catalog
|
|
21
|
-
quote
|
|
20
|
+
catalog [product] List products, durations, countries, and USD prices
|
|
21
|
+
quote <product> ... Calculate USD price (e.g. quote residential 10gb | quote isp US 2 30d)
|
|
22
22
|
balance Show prepaid USD wallet balance
|
|
23
|
-
buy
|
|
23
|
+
buy <product> ... Create checkout (e.g. buy residential 10gb [--method stripe|crypto|balance])
|
|
24
24
|
checkout <session-id> Poll checkout payment and provisioning status
|
|
25
25
|
orders [--limit 20] List order and top-up history
|
|
26
|
-
proxies [
|
|
26
|
+
proxies [product] List static proxies (isp|datacenter|mobile, --raw prints host:port:user:pass)
|
|
27
27
|
residential [options] Generate residential proxy strings (--country us --qty 1 --raw)
|
|
28
28
|
|
|
29
29
|
Global options:
|
|
@@ -103,29 +103,200 @@ function maskKey(key) {
|
|
|
103
103
|
function formatUsd(cents) {
|
|
104
104
|
return `$${(cents / 100).toFixed(2)}`;
|
|
105
105
|
}
|
|
106
|
-
function
|
|
107
|
-
const
|
|
106
|
+
function validateEmailInput(value) {
|
|
107
|
+
const email = (value ?? "").trim().toLowerCase();
|
|
108
|
+
if (!email)
|
|
109
|
+
return { email, error: "Enter your email address." };
|
|
110
|
+
if (email.length > 320 || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
|
111
|
+
return { email, error: "Enter a valid email address." };
|
|
112
|
+
}
|
|
113
|
+
return { email };
|
|
114
|
+
}
|
|
115
|
+
function normalizeOtpCode(raw) {
|
|
116
|
+
const normalized = raw.replace(/[\s-]+/g, "");
|
|
117
|
+
return /^\d{6}$/.test(normalized) ? normalized : null;
|
|
118
|
+
}
|
|
119
|
+
function isCancelCommand(raw) {
|
|
120
|
+
const lower = raw.trim().toLowerCase();
|
|
121
|
+
return lower === "q" || lower === "quit" || lower === "exit";
|
|
122
|
+
}
|
|
123
|
+
async function runInteractiveLogin(options) {
|
|
124
|
+
const { client, keyName, access, stdin, stdout, errOut } = options;
|
|
125
|
+
const terminal = Boolean(stdin.isTTY);
|
|
126
|
+
const rl = readline.createInterface({ input: stdin, output: stdout, terminal });
|
|
127
|
+
const bufferedLines = [];
|
|
128
|
+
let waitingResolver = null;
|
|
129
|
+
let cancelled = false;
|
|
130
|
+
let closed = false;
|
|
131
|
+
const closePrompt = () => {
|
|
132
|
+
closed = true;
|
|
133
|
+
if (waitingResolver) {
|
|
134
|
+
const resolve = waitingResolver;
|
|
135
|
+
waitingResolver = null;
|
|
136
|
+
resolve(null);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
rl.on("line", (line) => {
|
|
140
|
+
if (waitingResolver) {
|
|
141
|
+
const resolve = waitingResolver;
|
|
142
|
+
waitingResolver = null;
|
|
143
|
+
resolve(line);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
bufferedLines.push(line);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
rl.on("SIGINT", () => {
|
|
150
|
+
cancelled = true;
|
|
151
|
+
rl.close();
|
|
152
|
+
});
|
|
153
|
+
rl.on("close", closePrompt);
|
|
154
|
+
const ask = (prompt) => {
|
|
155
|
+
if (bufferedLines.length > 0) {
|
|
156
|
+
stdout.write(prompt);
|
|
157
|
+
return Promise.resolve(bufferedLines.shift());
|
|
158
|
+
}
|
|
159
|
+
if (cancelled || closed)
|
|
160
|
+
return Promise.resolve(null);
|
|
161
|
+
if (terminal) {
|
|
162
|
+
rl.setPrompt(prompt);
|
|
163
|
+
rl.prompt();
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
stdout.write(prompt);
|
|
167
|
+
}
|
|
168
|
+
return new Promise((resolve) => {
|
|
169
|
+
waitingResolver = resolve;
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
const promptForEmail = async (seed) => {
|
|
173
|
+
if (seed !== undefined) {
|
|
174
|
+
const checked = validateEmailInput(seed);
|
|
175
|
+
if (!checked.error)
|
|
176
|
+
return checked.email;
|
|
177
|
+
errOut(checked.error);
|
|
178
|
+
}
|
|
179
|
+
while (true) {
|
|
180
|
+
const answer = await ask('Email (or "q" to cancel): ');
|
|
181
|
+
if (answer === null || isCancelCommand(answer))
|
|
182
|
+
return null;
|
|
183
|
+
const checked = validateEmailInput(answer);
|
|
184
|
+
if (!checked.error)
|
|
185
|
+
return checked.email;
|
|
186
|
+
errOut(checked.error);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
try {
|
|
190
|
+
let email = await promptForEmail(options.initialEmail);
|
|
191
|
+
if (!email)
|
|
192
|
+
return null;
|
|
193
|
+
const requested = await client.requestOtp(email);
|
|
194
|
+
email = requested.email;
|
|
195
|
+
errOut(`Sent a 6-digit verification code to ${email}.`);
|
|
196
|
+
errOut('Type "r" to resend, "e" to change email, or press Ctrl+C to cancel.');
|
|
197
|
+
while (true) {
|
|
198
|
+
const rawAnswer = await ask("6-digit code: ");
|
|
199
|
+
if (rawAnswer === null || isCancelCommand(rawAnswer))
|
|
200
|
+
return null;
|
|
201
|
+
const trimmed = rawAnswer.trim();
|
|
202
|
+
const lower = trimmed.toLowerCase();
|
|
203
|
+
if (lower === "r" || lower === "resend") {
|
|
204
|
+
try {
|
|
205
|
+
await client.requestOtp(email);
|
|
206
|
+
errOut(`Sent a new 6-digit code to ${email}.`);
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
if (err instanceof ProxyLayerError) {
|
|
210
|
+
errOut(err.message);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
throw err;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (lower === "e" || lower === "email") {
|
|
219
|
+
const nextEmail = await promptForEmail();
|
|
220
|
+
if (!nextEmail)
|
|
221
|
+
return null;
|
|
222
|
+
try {
|
|
223
|
+
const nextReq = await client.requestOtp(nextEmail);
|
|
224
|
+
email = nextReq.email;
|
|
225
|
+
errOut(`Sent a 6-digit verification code to ${email}.`);
|
|
226
|
+
}
|
|
227
|
+
catch (err) {
|
|
228
|
+
if (err instanceof ProxyLayerError) {
|
|
229
|
+
errOut(err.message);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
throw err;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (!trimmed) {
|
|
238
|
+
errOut("Enter the 6-digit code from your email.");
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
const normalized = normalizeOtpCode(trimmed);
|
|
242
|
+
if (!normalized) {
|
|
243
|
+
errOut("Enter a 6-digit numeric code (for example: 123456).");
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
return await client.verifyOtp({ email, code: normalized, keyName, access, save: true });
|
|
248
|
+
}
|
|
249
|
+
catch (err) {
|
|
250
|
+
if (err instanceof ProxyLayerError && err.code === "INVALID_OTP") {
|
|
251
|
+
errOut('Incorrect code. Try again, or type "r" to resend a new code.');
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (err instanceof ProxyLayerError && err.code === "OTP_EXPIRED") {
|
|
255
|
+
errOut('That code has expired. Type "r" to send a new code.');
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
throw err;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
rl.close();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function parseSuffixedInt(raw, unitRegex, label) {
|
|
267
|
+
const cleaned = raw.trim().replace(unitRegex, "");
|
|
268
|
+
const parsed = Number(cleaned);
|
|
269
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
270
|
+
throw new Error(`${label} must be a positive integer (got "${raw}")`);
|
|
271
|
+
}
|
|
272
|
+
return parsed;
|
|
273
|
+
}
|
|
274
|
+
function buildPurchase(flags, positionals, allowTopUp) {
|
|
275
|
+
const supported = allowTopUp ? "isp | datacenter | mobile | residential | balance-topup" : "isp | datacenter | mobile | residential";
|
|
276
|
+
const product = strFlag(flags, "product") ?? positionals[1];
|
|
108
277
|
if (!product) {
|
|
109
|
-
throw new Error(
|
|
278
|
+
throw new Error(`Specify a product (${supported}), for example: residential 10gb`);
|
|
110
279
|
}
|
|
111
280
|
if (product === "residential") {
|
|
112
|
-
const trafficGb = intFlag(flags, "gb");
|
|
113
|
-
if (!trafficGb || trafficGb <= 0)
|
|
114
|
-
throw new Error("
|
|
281
|
+
const trafficGb = intFlag(flags, "gb") ?? (positionals[2] ? parseSuffixedInt(positionals[2], /gb$/i, "Traffic GB") : undefined);
|
|
282
|
+
if (!trafficGb || trafficGb <= 0) {
|
|
283
|
+
throw new Error("Traffic in GB is required (for example: residential 10gb or --gb 10)");
|
|
284
|
+
}
|
|
115
285
|
return { productSlug: "residential", trafficGb };
|
|
116
286
|
}
|
|
117
287
|
if (product === "balance-topup") {
|
|
118
288
|
if (!allowTopUp)
|
|
119
289
|
throw new Error("balance-topup cannot be quoted with quote; pass amount to buy");
|
|
120
|
-
const amountCents = intFlag(flags, "amount-cents");
|
|
121
|
-
if (!amountCents || amountCents <= 0)
|
|
122
|
-
throw new Error("
|
|
290
|
+
const amountCents = intFlag(flags, "amount-cents") ?? (positionals[2] ? parseSuffixedInt(positionals[2], /^$/, "Amount cents") : undefined);
|
|
291
|
+
if (!amountCents || amountCents <= 0) {
|
|
292
|
+
throw new Error("Amount in USD cents is required for balance-topup (for example: balance-topup 2500)");
|
|
293
|
+
}
|
|
123
294
|
return { productSlug: "balance-topup", amountCents };
|
|
124
295
|
}
|
|
125
296
|
if (product === "isp" || product === "datacenter" || product === "mobile") {
|
|
126
|
-
const
|
|
127
|
-
const quantity = intFlag(flags, "qty", 1);
|
|
128
|
-
const
|
|
297
|
+
const countryCode = (strFlag(flags, "country") ?? positionals[2] ?? "US").toUpperCase();
|
|
298
|
+
const quantity = intFlag(flags, "qty") ?? (positionals[3] ? parseSuffixedInt(positionals[3], /^$/, "Quantity") : 1);
|
|
299
|
+
const durationDays = intFlag(flags, "days") ?? (positionals[4] ? parseSuffixedInt(positionals[4], /d$/i, "Duration days") : 30);
|
|
129
300
|
const targetIdsRaw = strFlag(flags, "target-proxy-ids");
|
|
130
301
|
const targetProxyIds = targetIdsRaw
|
|
131
302
|
? targetIdsRaw.split(",").map((id) => id.trim()).filter(Boolean)
|
|
@@ -136,7 +307,7 @@ function buildPurchase(flags, allowTopUp) {
|
|
|
136
307
|
items: [{ countryCode, quantity, ...(targetProxyIds?.length ? { targetProxyIds } : {}) }],
|
|
137
308
|
};
|
|
138
309
|
}
|
|
139
|
-
throw new Error(`Unsupported product "${product}"`);
|
|
310
|
+
throw new Error(`Unsupported product "${product}". Choose: ${supported} (for example: residential 10gb)`);
|
|
140
311
|
}
|
|
141
312
|
export async function runCli(argv, deps) {
|
|
142
313
|
const stdout = deps?.stdout ?? process.stdout;
|
|
@@ -165,6 +336,19 @@ export async function runCli(argv, deps) {
|
|
|
165
336
|
return 0;
|
|
166
337
|
}
|
|
167
338
|
const client = new ProxyLayer({ apiKey, baseUrl, configPath, fetch: deps?.fetch });
|
|
339
|
+
const isTty = deps?.isTTY ?? Boolean(stdin.isTTY);
|
|
340
|
+
const ensureInteractiveAuth = async () => {
|
|
341
|
+
if (client.getResolvedConfig().apiKey || !isTty || asJson || asRaw)
|
|
342
|
+
return true;
|
|
343
|
+
errOut("Sign in to ProxyLayer to continue:");
|
|
344
|
+
const interactive = await runInteractiveLogin({ client, stdin, stdout, errOut });
|
|
345
|
+
if (!interactive) {
|
|
346
|
+
errOut("Login cancelled.");
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
errOut(`Signed in as ${interactive.user.email} (${interactive.keyPrefix}...)`);
|
|
350
|
+
return true;
|
|
351
|
+
};
|
|
168
352
|
if (command === "whoami") {
|
|
169
353
|
const resolved = client.getResolvedConfig();
|
|
170
354
|
const payload = {
|
|
@@ -194,19 +378,37 @@ export async function runCli(argv, deps) {
|
|
|
194
378
|
return 0;
|
|
195
379
|
}
|
|
196
380
|
if (command === "login") {
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
throw new Error("--email <address> is required");
|
|
200
|
-
let code = strFlag(flags, "code");
|
|
381
|
+
const rawEmail = strFlag(flags, "email") ?? positionals[1] ?? (flags.has("email") ? "" : undefined);
|
|
382
|
+
const rawCode = strFlag(flags, "code");
|
|
201
383
|
const keyName = strFlag(flags, "key-name");
|
|
202
384
|
const access = strFlag(flags, "access");
|
|
203
385
|
if (access && access !== "read" && access !== "full") {
|
|
204
386
|
throw new Error("--access must be 'read' or 'full'");
|
|
205
387
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
388
|
+
let verified;
|
|
389
|
+
if (!rawCode && isTty && !asJson) {
|
|
390
|
+
const interactive = await runInteractiveLogin({
|
|
391
|
+
client,
|
|
392
|
+
initialEmail: rawEmail,
|
|
393
|
+
keyName,
|
|
394
|
+
access,
|
|
395
|
+
stdin,
|
|
396
|
+
stdout,
|
|
397
|
+
errOut,
|
|
398
|
+
});
|
|
399
|
+
if (!interactive) {
|
|
400
|
+
errOut("Login cancelled.");
|
|
401
|
+
return 130;
|
|
402
|
+
}
|
|
403
|
+
verified = interactive;
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
const checkedEmail = validateEmailInput(rawEmail);
|
|
407
|
+
if (checkedEmail.error)
|
|
408
|
+
throw new Error(checkedEmail.error);
|
|
409
|
+
const email = checkedEmail.email;
|
|
410
|
+
if (!rawCode) {
|
|
411
|
+
const requested = await client.requestOtp(email);
|
|
210
412
|
if (asJson) {
|
|
211
413
|
out(JSON.stringify(requested, null, 2));
|
|
212
414
|
}
|
|
@@ -216,16 +418,11 @@ export async function runCli(argv, deps) {
|
|
|
216
418
|
}
|
|
217
419
|
return 0;
|
|
218
420
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
finally {
|
|
225
|
-
rl.close();
|
|
226
|
-
}
|
|
421
|
+
const code = normalizeOtpCode(rawCode);
|
|
422
|
+
if (!code)
|
|
423
|
+
throw new Error("Enter a 6-digit numeric code.");
|
|
424
|
+
verified = await client.verifyOtp({ email, code, keyName, access, save: true });
|
|
227
425
|
}
|
|
228
|
-
const verified = await client.verifyOtp({ email, code, keyName, access, save: true });
|
|
229
426
|
const resolved = client.getResolvedConfig();
|
|
230
427
|
if (asJson) {
|
|
231
428
|
out(JSON.stringify({
|
|
@@ -244,7 +441,11 @@ export async function runCli(argv, deps) {
|
|
|
244
441
|
return 0;
|
|
245
442
|
}
|
|
246
443
|
if (command === "catalog") {
|
|
247
|
-
const
|
|
444
|
+
const productFilter = strFlag(flags, "product") ?? positionals[1];
|
|
445
|
+
if (productFilter && productFilter !== "isp" && productFilter !== "datacenter" && productFilter !== "mobile" && productFilter !== "residential") {
|
|
446
|
+
throw new Error("--product must be 'isp', 'datacenter', 'mobile', or 'residential'");
|
|
447
|
+
}
|
|
448
|
+
const catalog = await client.getCatalog(productFilter ? { product: productFilter } : undefined);
|
|
248
449
|
if (asJson) {
|
|
249
450
|
out(JSON.stringify(catalog, null, 2));
|
|
250
451
|
}
|
|
@@ -257,7 +458,7 @@ export async function runCli(argv, deps) {
|
|
|
257
458
|
return 0;
|
|
258
459
|
}
|
|
259
460
|
if (command === "quote") {
|
|
260
|
-
const quote = await client.quote(buildPurchase(flags, false));
|
|
461
|
+
const quote = await client.quote(buildPurchase(flags, positionals, false));
|
|
261
462
|
if (asJson) {
|
|
262
463
|
out(JSON.stringify(quote, null, 2));
|
|
263
464
|
}
|
|
@@ -267,6 +468,8 @@ export async function runCli(argv, deps) {
|
|
|
267
468
|
return 0;
|
|
268
469
|
}
|
|
269
470
|
if (command === "balance") {
|
|
471
|
+
if (!(await ensureInteractiveAuth()))
|
|
472
|
+
return 130;
|
|
270
473
|
const summary = await client.getBalance();
|
|
271
474
|
if (asJson) {
|
|
272
475
|
out(JSON.stringify(summary, null, 2));
|
|
@@ -281,8 +484,11 @@ export async function runCli(argv, deps) {
|
|
|
281
484
|
if (paymentMethod !== "stripe" && paymentMethod !== "crypto" && paymentMethod !== "balance") {
|
|
282
485
|
throw new Error("--method must be 'stripe', 'crypto', or 'balance'");
|
|
283
486
|
}
|
|
487
|
+
const purchase = buildPurchase(flags, positionals, true);
|
|
488
|
+
if (!(await ensureInteractiveAuth()))
|
|
489
|
+
return 130;
|
|
284
490
|
const checkout = await client.createCheckout({
|
|
285
|
-
purchase
|
|
491
|
+
purchase,
|
|
286
492
|
paymentMethod,
|
|
287
493
|
cryptoCurrency: strFlag(flags, "crypto-currency"),
|
|
288
494
|
cryptoNetwork: strFlag(flags, "crypto-network"),
|
|
@@ -307,6 +513,8 @@ export async function runCli(argv, deps) {
|
|
|
307
513
|
const sessionId = positionals[1] ?? strFlag(flags, "id");
|
|
308
514
|
if (!sessionId)
|
|
309
515
|
throw new Error("checkout <checkoutSessionId> is required");
|
|
516
|
+
if (!(await ensureInteractiveAuth()))
|
|
517
|
+
return 130;
|
|
310
518
|
const status = await client.getCheckoutStatus(sessionId);
|
|
311
519
|
if (asJson) {
|
|
312
520
|
out(JSON.stringify(status, null, 2));
|
|
@@ -319,6 +527,8 @@ export async function runCli(argv, deps) {
|
|
|
319
527
|
return 0;
|
|
320
528
|
}
|
|
321
529
|
if (command === "orders") {
|
|
530
|
+
if (!(await ensureInteractiveAuth()))
|
|
531
|
+
return 130;
|
|
322
532
|
const orders = await client.listOrders({
|
|
323
533
|
limit: intFlag(flags, "limit"),
|
|
324
534
|
cursor: strFlag(flags, "cursor"),
|
|
@@ -334,10 +544,12 @@ export async function runCli(argv, deps) {
|
|
|
334
544
|
return 0;
|
|
335
545
|
}
|
|
336
546
|
if (command === "proxies") {
|
|
337
|
-
const product = (strFlag(flags, "product")
|
|
547
|
+
const product = (strFlag(flags, "product") ?? positionals[1] ?? "isp");
|
|
338
548
|
if (product !== "isp" && product !== "datacenter" && product !== "mobile") {
|
|
339
549
|
throw new Error("--product must be 'isp', 'datacenter', or 'mobile'");
|
|
340
550
|
}
|
|
551
|
+
if (!(await ensureInteractiveAuth()))
|
|
552
|
+
return 130;
|
|
341
553
|
const res = await client.listStaticProxies({
|
|
342
554
|
product,
|
|
343
555
|
checkoutSessionId: strFlag(flags, "checkout-session-id"),
|
|
@@ -366,6 +578,8 @@ export async function runCli(argv, deps) {
|
|
|
366
578
|
if (session && session !== "sticky" && session !== "rotating") {
|
|
367
579
|
throw new Error("--session must be 'sticky' or 'rotating'");
|
|
368
580
|
}
|
|
581
|
+
if (!(await ensureInteractiveAuth()))
|
|
582
|
+
return 130;
|
|
369
583
|
const res = await client.getResidentialProxies({
|
|
370
584
|
country: strFlag(flags, "country"),
|
|
371
585
|
city: strFlag(flags, "city"),
|
|
@@ -396,7 +610,13 @@ export async function runCli(argv, deps) {
|
|
|
396
610
|
}
|
|
397
611
|
catch (error) {
|
|
398
612
|
if (error instanceof ProxyLayerError) {
|
|
399
|
-
|
|
613
|
+
const firstIssue = error.issues?.[0];
|
|
614
|
+
const detail = error.message === "Invalid request payload" && typeof firstIssue?.message === "string"
|
|
615
|
+
? firstIssue.message
|
|
616
|
+
: error.message;
|
|
617
|
+
errOut(error.code === "VALIDATION_ERROR"
|
|
618
|
+
? `Error: ${detail}`
|
|
619
|
+
: `Error: ${detail} (${error.code}, HTTP ${error.status})`);
|
|
400
620
|
}
|
|
401
621
|
else {
|
|
402
622
|
errOut(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
package/dist/client.d.ts
CHANGED
|
@@ -220,7 +220,9 @@ export declare class ProxyLayer {
|
|
|
220
220
|
get baseUrl(): string;
|
|
221
221
|
getResolvedConfig(): import("./config.js").ResolvedConfig;
|
|
222
222
|
private request;
|
|
223
|
-
getCatalog(
|
|
223
|
+
getCatalog(params?: {
|
|
224
|
+
product?: ProductSlug;
|
|
225
|
+
}): Promise<CatalogResponse>;
|
|
224
226
|
quote(purchase: QuotePurchaseInput): Promise<QuoteResponse>;
|
|
225
227
|
requestOtp(email: string): Promise<OtpRequestResponse>;
|
|
226
228
|
verifyOtp(input: {
|
package/dist/client.js
CHANGED
|
@@ -85,8 +85,11 @@ export class ProxyLayer {
|
|
|
85
85
|
}
|
|
86
86
|
return parsed;
|
|
87
87
|
}
|
|
88
|
-
getCatalog() {
|
|
89
|
-
return this.request("GET", "/api/v1/catalog", {
|
|
88
|
+
getCatalog(params) {
|
|
89
|
+
return this.request("GET", "/api/v1/catalog", {
|
|
90
|
+
auth: "none",
|
|
91
|
+
query: { product: params?.product },
|
|
92
|
+
});
|
|
90
93
|
}
|
|
91
94
|
quote(purchase) {
|
|
92
95
|
return this.request("POST", "/api/v1/quotes", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proxylayer/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Zero-dependency ProxyLayer CLI, local stdio MCP server, and TypeScript/JavaScript SDK.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"node": ">=20.0.0"
|
|
9
9
|
},
|
|
10
10
|
"bin": {
|
|
11
|
-
"proxylayer": "./dist/cli.js"
|
|
11
|
+
"proxylayer": "./dist/cli.js",
|
|
12
|
+
"pl": "./dist/cli.js"
|
|
12
13
|
},
|
|
13
14
|
"main": "./dist/index.js",
|
|
14
15
|
"types": "./dist/index.d.ts",
|