@getalby/cli 0.4.0 → 0.5.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/README.md CHANGED
@@ -123,13 +123,13 @@ npx @getalby/cli get-budget
123
123
  npx @getalby/cli sign-message --message "Hello, World!"
124
124
 
125
125
  # Fetch a payment-protected resource (auto-detects L402, X402, MPP)
126
- npx @getalby/cli fetch --url "https://example.com/api"
126
+ npx @getalby/cli fetch "https://example.com/api"
127
127
 
128
128
  # Fetch with custom method, headers, and body
129
- npx @getalby/cli fetch --url "https://example.com/api" --method POST --body '{"query":"hello"}' --headers '{"Accept":"application/json"}'
129
+ npx @getalby/cli fetch "https://example.com/api" --method POST --body '{"query":"hello"}' --headers '{"Accept":"application/json"}'
130
130
 
131
131
  # Fetch with a custom max amount (default: 5000 sats, 0 = no limit)
132
- npx @getalby/cli fetch --url "https://example.com/api" --max-amount 1000
132
+ npx @getalby/cli fetch "https://example.com/api" --max-amount 1000
133
133
 
134
134
  # Wait for a payment notification
135
135
  npx @getalby/cli wait-for-payment --payment-hash "abc123..."
@@ -4,16 +4,16 @@ export function registerFetch402Command(program) {
4
4
  program
5
5
  .command("fetch")
6
6
  .description("Fetch a payment-protected resource (auto-detects L402, X402, MPP)")
7
- .requiredOption("-u, --url <url>", "URL to fetch")
7
+ .argument("<url>", "URL to fetch")
8
8
  .option("-m, --method <method>", "HTTP method (GET, POST, etc.)")
9
9
  .option("-b, --body <json>", "Request body (JSON string)")
10
10
  .option("-H, --headers <json>", "Additional headers (JSON string)")
11
11
  .option("--max-amount <sats>", "Maximum amount in sats to pay per request. Aborts if the endpoint requests more. (default: 5000, 0 = no limit)", parseInt)
12
- .action(async (options) => {
12
+ .action(async (url, options) => {
13
13
  await handleError(async () => {
14
14
  const client = await getClient(program);
15
15
  const result = await fetch402(client, {
16
- url: options.url,
16
+ url: url,
17
17
  method: options.method,
18
18
  body: options.body,
19
19
  headers: options.headers ? JSON.parse(options.headers) : undefined,
package/build/index.js CHANGED
@@ -25,14 +25,16 @@ import { registerAuthCommand } from "./commands/auth.js";
25
25
  const program = new Command();
26
26
  program
27
27
  .name("@getalby/cli")
28
- .description("CLI for Nostr Wallet Connect (NIP-47) with lightning tools\n\n" +
28
+ .description("CLI for Nostr Wallet Connect (NIP-47) with lightning tools\n" +
29
+ " Run 'auth' or 'connect' first to set up a wallet connection.\n\n" +
29
30
  " Examples:\n" +
31
+ " $ npx @getalby/cli auth https://my.albyhub.com --app-name OpenClaw\n" +
30
32
  ' $ npx @getalby/cli connect "nostr+walletconnect://..."\n' +
31
33
  " $ npx @getalby/cli get-balance\n" +
32
34
  " $ npx @getalby/cli pay-invoice --invoice lnbc...")
33
- .version("0.4.0")
34
- .option("-c, --connection-secret <string>", "NWC connection secret (nostr+walletconnect://...) or path to file containing it (preferred)")
35
+ .version("0.5.0")
35
36
  .option("-w, --wallet-name <name>", "Use a named wallet's connection secret (~/.alby-cli/connection-secret-<name>.key)")
37
+ .option("-c, --connection-secret <string>", "NWC connection secret (nostr+walletconnect://...) or path to file containing it (preferred)")
36
38
  .option("-v, --verbose", "Print status messages to stderr")
37
39
  .addHelpText("after", `
38
40
  Connection Secret Resolution (in order of priority):
@@ -48,7 +50,7 @@ Security:
48
50
  - NEVER share any part of a connection secret (pubkey, secret, relay etc.) with anyone
49
51
  as this can be used to gain access to your wallet or reduce your wallet's privacy.`);
50
52
  // Register common wallet commands
51
- program.commandsGroup("Wallet Commands (require --connection-secret):");
53
+ program.commandsGroup("Wallet Commands (requires wallet connection):");
52
54
  registerGetBalanceCommand(program);
53
55
  registerGetBudgetCommand(program);
54
56
  registerGetInfoCommand(program);
@@ -57,7 +59,7 @@ registerPayInvoiceCommand(program);
57
59
  registerLookupInvoiceCommand(program);
58
60
  registerListTransactionsCommand(program);
59
61
  // Register advanced wallet commands
60
- program.commandsGroup("Advanced Wallet Commands (require --connection-secret):");
62
+ program.commandsGroup("Advanced Wallet Commands (requires wallet connection):");
61
63
  registerPayKeysendCommand(program);
62
64
  registerGetWalletServiceInfoCommand(program);
63
65
  registerWaitForPaymentCommand(program);
@@ -66,14 +68,14 @@ registerMakeHoldInvoiceCommand(program);
66
68
  registerSettleHoldInvoiceCommand(program);
67
69
  registerCancelHoldInvoiceCommand(program);
68
70
  // Register lightning tool commands
69
- program.commandsGroup("Lightning Tools (no --connection-secret required):");
71
+ program.commandsGroup("Lightning Tools (no wallet connection required):");
70
72
  registerFiatToSatsCommand(program);
71
73
  registerSatsToFiatCommand(program);
72
74
  registerParseInvoiceCommand(program);
73
75
  registerVerifyPreimageCommand(program);
74
76
  registerRequestInvoiceFromLightningAddressCommand(program);
75
77
  // Register fetch command for payment-protected resources
76
- program.commandsGroup("HTTP 402 Payments (require --connection-secret):");
78
+ program.commandsGroup("HTTP 402 Payments (requires wallet connection):");
77
79
  registerFetch402Command(program);
78
80
  // Register setup commands
79
81
  program.commandsGroup("Setup:");
package/build/utils.js CHANGED
@@ -95,6 +95,17 @@ export async function getClient(program) {
95
95
  if (!connectionSecret && !walletName) {
96
96
  connectionSecret = process.env.NWC_URL;
97
97
  }
98
+ // Check for pending connections BEFORE reading the existing connection file.
99
+ // When `auth --force` is used, the old connection-secret.key still exists.
100
+ // If we read it first, we'd skip the pending connection and silently use
101
+ // the old connection instead of completing the new one.
102
+ if (!connectionSecret && existsSync(pendingPath)) {
103
+ if (opts.verbose) {
104
+ console.error("Pending connection found. Waiting for wallet approval...");
105
+ }
106
+ const pendingRelayPath = getPendingConnectionRelayPath(walletName);
107
+ return await completePendingConnection(pendingPath, connectionPath, undefined, opts.verbose, pendingRelayPath);
108
+ }
98
109
  if (!connectionSecret) {
99
110
  try {
100
111
  connectionSecret = readFileSync(connectionPath, "utf-8").trim();
@@ -105,13 +116,6 @@ export async function getClient(program) {
105
116
  throw err;
106
117
  }
107
118
  }
108
- if (!connectionSecret && existsSync(pendingPath)) {
109
- if (opts.verbose) {
110
- console.error("Pending connection found. Waiting for wallet approval...");
111
- }
112
- const pendingRelayPath = getPendingConnectionRelayPath(walletName);
113
- return await completePendingConnection(pendingPath, connectionPath, undefined, opts.verbose, pendingRelayPath);
114
- }
115
119
  if (!connectionSecret) {
116
120
  throw new Error("No connection secret provided. Pass -c <secret or file path>, set NWC_URL, use --wallet-name <name>, or create ~/.alby-cli/connection-secret.key");
117
121
  }
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.4.0",
5
+ "version": "0.5.0",
6
6
  "type": "module",
7
7
  "main": "build/index.js",
8
8
  "bin": {