@getalby/cli 0.4.1 → 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
@@ -32,7 +32,7 @@ program
32
32
  ' $ npx @getalby/cli connect "nostr+walletconnect://..."\n' +
33
33
  " $ npx @getalby/cli get-balance\n" +
34
34
  " $ npx @getalby/cli pay-invoice --invoice lnbc...")
35
- .version("0.4.1")
35
+ .version("0.5.0")
36
36
  .option("-w, --wallet-name <name>", "Use a named wallet's connection secret (~/.alby-cli/connection-secret-<name>.key)")
37
37
  .option("-c, --connection-secret <string>", "NWC connection secret (nostr+walletconnect://...) or path to file containing it (preferred)")
38
38
  .option("-v, --verbose", "Print status messages to stderr")
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.1",
5
+ "version": "0.5.0",
6
6
  "type": "module",
7
7
  "main": "build/index.js",
8
8
  "bin": {