@getalby/cli 0.5.0 → 0.6.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.
@@ -0,0 +1,24 @@
1
+ import { discover } from "../tools/lightning/discover.js";
2
+ import { handleError, output } from "../utils.js";
3
+ export function registerDiscoverCommand(program) {
4
+ program
5
+ .command("discover")
6
+ .description("Search 402index.io for paid API services that accept bitcoin/lightning")
7
+ .option("-q, --query <text>", "Search query")
8
+ .option("-p, --protocol <protocol>", "Filter by protocol (L402, x402, MPP)")
9
+ .option("--health <status>", "Filter by health (healthy, degraded, down, unknown)", "healthy")
10
+ .option("-s, --sort <field>", "Sort by (reliability, latency, price, name)", "reliability")
11
+ .option("-l, --limit <number>", "Number of results", "10")
12
+ .action(async (options) => {
13
+ await handleError(async () => {
14
+ const result = await discover({
15
+ query: options.query,
16
+ protocol: options.protocol,
17
+ health: options.health,
18
+ sort: options.sort,
19
+ limit: parseInt(options.limit, 10),
20
+ });
21
+ output(result);
22
+ });
23
+ });
24
+ }
package/build/index.js CHANGED
@@ -22,6 +22,7 @@ import { registerRequestInvoiceFromLightningAddressCommand } from "./commands/re
22
22
  import { registerFetch402Command } from "./commands/fetch.js";
23
23
  import { registerConnectCommand } from "./commands/connect.js";
24
24
  import { registerAuthCommand } from "./commands/auth.js";
25
+ import { registerDiscoverCommand } from "./commands/discover.js";
25
26
  const program = new Command();
26
27
  program
27
28
  .name("@getalby/cli")
@@ -32,7 +33,7 @@ program
32
33
  ' $ npx @getalby/cli connect "nostr+walletconnect://..."\n' +
33
34
  " $ npx @getalby/cli get-balance\n" +
34
35
  " $ npx @getalby/cli pay-invoice --invoice lnbc...")
35
- .version("0.5.0")
36
+ .version("0.6.0")
36
37
  .option("-w, --wallet-name <name>", "Use a named wallet's connection secret (~/.alby-cli/connection-secret-<name>.key)")
37
38
  .option("-c, --connection-secret <string>", "NWC connection secret (nostr+walletconnect://...) or path to file containing it (preferred)")
38
39
  .option("-v, --verbose", "Print status messages to stderr")
@@ -77,6 +78,9 @@ registerRequestInvoiceFromLightningAddressCommand(program);
77
78
  // Register fetch command for payment-protected resources
78
79
  program.commandsGroup("HTTP 402 Payments (requires wallet connection):");
79
80
  registerFetch402Command(program);
81
+ // Register service discovery
82
+ program.commandsGroup("Service Discovery:");
83
+ registerDiscoverCommand(program);
80
84
  // Register setup commands
81
85
  program.commandsGroup("Setup:");
82
86
  registerAuthCommand(program);
@@ -0,0 +1,51 @@
1
+ export async function discover(params) {
2
+ const url = new URL("https://402index.io/api/v1/services");
3
+ const requestedLimit = params.limit ?? 10;
4
+ if (params.query)
5
+ url.searchParams.set("q", params.query);
6
+ if (params.protocol)
7
+ url.searchParams.set("protocol", params.protocol);
8
+ if (params.health)
9
+ url.searchParams.set("health", params.health);
10
+ if (params.sort)
11
+ url.searchParams.set("sort", params.sort);
12
+ // Filter to BTC (Lightning) services server-side
13
+ url.searchParams.set("payment_asset", "BTC");
14
+ url.searchParams.set("limit", String(requestedLimit));
15
+ const controller = new AbortController();
16
+ const timer = setTimeout(() => controller.abort(), 5000);
17
+ let response;
18
+ try {
19
+ response = await fetch(url.toString(), { signal: controller.signal });
20
+ }
21
+ catch (error) {
22
+ if (error instanceof Error && error.name === "AbortError") {
23
+ throw new Error("Request to 402index.io timed out");
24
+ }
25
+ throw error;
26
+ }
27
+ finally {
28
+ clearTimeout(timer);
29
+ }
30
+ if (!response.ok) {
31
+ throw new Error(`402index.io returned status ${response.status}: ${await response.text()}`);
32
+ }
33
+ const data = (await response.json());
34
+ return {
35
+ services: data.services.map((s) => ({
36
+ name: s.name,
37
+ description: s.description,
38
+ url: s.url,
39
+ protocol: s.protocol,
40
+ price_sats: s.price_sats,
41
+ price_usd: s.price_usd,
42
+ category: s.category,
43
+ provider: s.provider,
44
+ health_status: s.health_status,
45
+ reliability_score: s.reliability_score,
46
+ latency_p50_ms: s.latency_p50_ms,
47
+ http_method: s.http_method,
48
+ })),
49
+ total: data.total,
50
+ };
51
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@getalby/cli",
3
3
  "description": "CLI for Nostr Wallet Connect (NIP-47) with a few additional useful lightning tools",
4
4
  "repository": "https://github.com/getAlby/cli.git",
5
- "version": "0.5.0",
5
+ "version": "0.6.0",
6
6
  "type": "module",
7
7
  "main": "build/index.js",
8
8
  "bin": {