@visa/cli 1.0.5 → 1.0.7-rc.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 +122 -79
- package/dist/cli.js +31 -31
- package/dist/mcp-server/index.js +21 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @visa/cli
|
|
2
2
|
|
|
3
|
-
AI-powered payments
|
|
3
|
+
AI-powered payments over MCP. Exposes Visa card payment tools as MCP (Model Context Protocol) tools so your AI assistant can pay for image generation, video, music, onchain data queries, and more — charged to a Visa card with Touch ID confirmation at the point of invocation.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -8,26 +8,9 @@ AI-powered payments for Claude Code. Exposes Visa card payment tools as MCP (Mod
|
|
|
8
8
|
npm install -g @visa/cli
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## MCP setup
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
# Start MCP server (used by Claude Code)
|
|
15
|
-
visa-cli mcp
|
|
16
|
-
|
|
17
|
-
# Login with GitHub
|
|
18
|
-
visa-cli login
|
|
19
|
-
|
|
20
|
-
# Add a Visa card
|
|
21
|
-
visa-cli add-card
|
|
22
|
-
|
|
23
|
-
# Check status
|
|
24
|
-
visa-cli status
|
|
25
|
-
|
|
26
|
-
# View transaction history
|
|
27
|
-
visa-cli history
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### Claude Code integration
|
|
13
|
+
Add to your MCP client config:
|
|
31
14
|
|
|
32
15
|
```json
|
|
33
16
|
{
|
|
@@ -40,92 +23,152 @@ visa-cli history
|
|
|
40
23
|
}
|
|
41
24
|
```
|
|
42
25
|
|
|
26
|
+
Once connected, your assistant will have access to all payment tools. The first time you use a paid tool, you'll be prompted to log in and enroll a card.
|
|
27
|
+
|
|
43
28
|
---
|
|
44
29
|
|
|
45
|
-
##
|
|
30
|
+
## CLI commands
|
|
46
31
|
|
|
47
|
-
|
|
32
|
+
```bash
|
|
33
|
+
visa-cli login # GitHub OAuth — opens browser, stores session token
|
|
34
|
+
visa-cli add-card # Enroll a Visa card via VGS secure form
|
|
35
|
+
visa-cli status # Show auth state, enrolled cards, daily spend remaining
|
|
36
|
+
visa-cli history # Recent transactions with amounts and any generated media URLs
|
|
37
|
+
visa-cli mcp # Start the MCP server
|
|
38
|
+
```
|
|
48
39
|
|
|
49
|
-
|
|
50
|
-
|------|-------------|
|
|
51
|
-
| `login` | GitHub OAuth login flow |
|
|
52
|
-
| `add_card` | Enroll a Visa card via VGS tokenization |
|
|
53
|
-
| `reset` | Reset auth state |
|
|
54
|
-
| `pay` | Generic payment endpoint |
|
|
55
|
-
| `get_status` | Auth + card + account status |
|
|
56
|
-
| `get_cards` | List enrolled cards |
|
|
57
|
-
| `transaction_history` | Recent transactions with amounts |
|
|
58
|
-
| `update_spending_controls` | Set daily/per-transaction limits |
|
|
59
|
-
| `send_feedback` | Submit feedback on a tool result |
|
|
60
|
-
| `get_feedback` | Retrieve feedback history |
|
|
61
|
-
| `batch` | Batch multiple tool calls |
|
|
62
|
-
| `discover` | List all available tools with pricing |
|
|
40
|
+
---
|
|
63
41
|
|
|
64
|
-
|
|
42
|
+
## Authentication
|
|
65
43
|
|
|
66
|
-
|
|
44
|
+
Login is GitHub OAuth. Your session token is stored at `~/.visa-mcp/config.json`.
|
|
67
45
|
|
|
68
|
-
|
|
46
|
+
```bash
|
|
47
|
+
visa-cli login # opens github.com/login/oauth/authorize in your browser
|
|
48
|
+
visa-cli status # verify you're logged in
|
|
49
|
+
```
|
|
69
50
|
|
|
70
51
|
---
|
|
71
52
|
|
|
72
|
-
##
|
|
53
|
+
## Card enrollment
|
|
73
54
|
|
|
55
|
+
Cards are tokenized via VGS — your raw card number never touches Visa servers. `add_card` opens a hosted VGS Collect form in your browser.
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
visa-cli add-card
|
|
74
59
|
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
3. Baseline: CATALOG from @visa/tools (compiled-in fallback)
|
|
78
|
-
```
|
|
60
|
+
|
|
61
|
+
Multiple cards can be enrolled. The first becomes the default; you can switch defaults with `set_default_card` from within your assistant. To remove a card: `remove_card` (requires Touch ID).
|
|
79
62
|
|
|
80
63
|
---
|
|
81
64
|
|
|
82
|
-
##
|
|
65
|
+
## Payments & Touch ID
|
|
83
66
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
│ ├── tools.ts Core tool handler implementations
|
|
91
|
-
│ └── suggestions.ts Dynamic catalog polling
|
|
92
|
-
├── touchid.ts macOS Touch ID / Secure Enclave attestation
|
|
93
|
-
├── rc-gate.ts RC version gate (checks RC_CODE_HASH)
|
|
94
|
-
└── config/
|
|
95
|
-
└── manager.ts ~/.visa-mcp/config.json read/write
|
|
67
|
+
Every paid tool call requires Touch ID (or device password on macOS). Your assistant will show you the amount and merchant before prompting. If you cancel Touch ID, the payment is aborted — nothing is charged.
|
|
68
|
+
|
|
69
|
+
You can set hard limits via the `update_spending_controls` tool, or check your current limits any time:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
visa-cli status
|
|
96
73
|
```
|
|
97
74
|
|
|
98
75
|
---
|
|
99
76
|
|
|
100
|
-
##
|
|
77
|
+
## MCP tools
|
|
101
78
|
|
|
102
|
-
|
|
103
|
-
# From monorepo root
|
|
104
|
-
pnpm --filter @visa/cli build
|
|
105
|
-
pnpm --filter @visa/cli test
|
|
106
|
-
pnpm --filter @visa/cli test:unit:coverage
|
|
79
|
+
### Account
|
|
107
80
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
81
|
+
| Tool | Description |
|
|
82
|
+
|------|-------------|
|
|
83
|
+
| `login` | GitHub OAuth login — opens browser |
|
|
84
|
+
| `add_card` | Enroll a card via VGS tokenization |
|
|
85
|
+
| `get_cards` | List enrolled cards (masked) |
|
|
86
|
+
| `remove_card` | Remove an enrolled card (Touch ID required) |
|
|
87
|
+
| `set_default_card` | Change the default card (Touch ID required) |
|
|
88
|
+
| `get_status` | Auth, card, spend limits, and budget summary |
|
|
89
|
+
| `update_spending_controls` | Set daily and per-transaction limits (Touch ID required) |
|
|
90
|
+
| `transaction_history` | Recent transactions with amounts and media URLs |
|
|
91
|
+
| `feedback` | Submit feedback on a tool result |
|
|
92
|
+
| `reset` | Clear auth state and credentials |
|
|
93
|
+
|
|
94
|
+
### Generation
|
|
95
|
+
|
|
96
|
+
| Tool | Price | Description |
|
|
97
|
+
|------|-------|-------------|
|
|
98
|
+
| `generate_image_card` | ~$0.06 | FLUX1.1 Ultra — 2K resolution, ~30s |
|
|
99
|
+
| `generate_image_fast_card` | ~$0.04 | FLUX1.1 Pro — 1K resolution, ~10s |
|
|
100
|
+
| `generate_video` | $0.10–$0.30 | Text-to-video (Wan / MiniMax / Kling) |
|
|
101
|
+
| `generate_music_tempo_card` | ~$0.10 | Suno AI music generation, ~2 min |
|
|
102
|
+
| `check_music_status_tempo_card` | ~$0.01 | Poll Suno task for audio URL |
|
|
103
|
+
| `generate_audio` | ~$0.03–$0.04 | TTS (MetaVoice) or SFX (Stable Audio) |
|
|
104
|
+
| `generate_3d` | ~$0.08 | Text-to-3D mesh (Trellis), returns GLB URL |
|
|
105
|
+
| `upscale_image` | ~$0.03 | Image upscaling (Aura SR) |
|
|
106
|
+
| `transcribe_audio` | ~$0.02 | Speech-to-text (Whisper) |
|
|
107
|
+
|
|
108
|
+
### Data
|
|
109
|
+
|
|
110
|
+
| Tool | Price | Description |
|
|
111
|
+
|------|-------|-------------|
|
|
112
|
+
| `query_onchain_prices_card` | ~$0.02 | Real-time or historical token prices (150+ chains via Allium) |
|
|
113
|
+
| `allium_explorer_card` | ~$0.10 | Natural language → SQL blockchain query (step 1) |
|
|
114
|
+
| `allium_explorer_results_card` | up to $3.00 | Fetch results for a submitted query (step 2) |
|
|
115
|
+
| `run_llm` | $0.01–$0.09 | Run a prompt through GPT-4o Mini, Claude, DeepSeek, Perplexity, or Llama |
|
|
116
|
+
|
|
117
|
+
### Utility
|
|
111
118
|
|
|
112
|
-
|
|
119
|
+
| Tool | Description |
|
|
120
|
+
|------|-------------|
|
|
121
|
+
| `pay` | Generic HTTP 402 payment endpoint |
|
|
122
|
+
| `batch` | Execute multiple paid tools in one Touch ID approval |
|
|
123
|
+
| `discover_tools` | Search the dynamic tool catalog |
|
|
124
|
+
| `execute_tool` | Run a tool from the dynamic catalog by ID |
|
|
113
125
|
|
|
114
|
-
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Dynamic catalog
|
|
129
|
+
|
|
130
|
+
The tool catalog is fetched live from the auth server at startup (5-minute TTL). If the server is unreachable, it falls back to the compiled-in baseline from `@visa/tools`.
|
|
131
|
+
|
|
132
|
+
To see all available tools with current pricing, ask your assistant:
|
|
133
|
+
|
|
134
|
+
> "What tools do you have available?"
|
|
115
135
|
|
|
116
136
|
---
|
|
117
137
|
|
|
118
|
-
##
|
|
138
|
+
## Spending controls
|
|
119
139
|
|
|
120
140
|
```
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
→ CI passes on dev
|
|
124
|
-
→ cli-release-rc.yml (bumps RC version, pushes v*-rc.* tag)
|
|
125
|
-
→ cli-publish.yml (injects hash, builds, publishes @visa/cli@rc)
|
|
126
|
-
|
|
127
|
-
Merge dev → main
|
|
128
|
-
→ CI passes on main
|
|
129
|
-
→ cli-release-stable.yml (exits pre mode, bumps stable, pushes v* tag)
|
|
130
|
-
→ cli-publish.yml (publishes @visa/cli@latest)
|
|
141
|
+
Daily limit — hard cap on total spend per day
|
|
142
|
+
Max per-transaction — hard cap per single tool call
|
|
131
143
|
```
|
|
144
|
+
|
|
145
|
+
Both limits are enforced server-side. Touch ID is always required per payment regardless of limits — this cannot be disabled.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Config & data locations
|
|
150
|
+
|
|
151
|
+
| Path | Contents |
|
|
152
|
+
|------|----------|
|
|
153
|
+
| `~/.visa-mcp/config.json` | Session token, device key |
|
|
154
|
+
| `~/.visa-mcp/catalog-cache.json` | Cached tool catalog (24h TTL) |
|
|
155
|
+
| `~/.visa-mcp/allium-results/` | Large query result CSVs |
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Troubleshooting
|
|
160
|
+
|
|
161
|
+
**Touch ID prompt doesn't appear**
|
|
162
|
+
Make sure `visa-cli mcp` is running as a foreground process that has access to the macOS security framework. Running inside some sandboxed environments may prevent Touch ID.
|
|
163
|
+
|
|
164
|
+
**"Not logged in" after `visa-cli login`**
|
|
165
|
+
Restart the MCP server after logging in — your MCP client needs to reconnect to pick up the new session.
|
|
166
|
+
|
|
167
|
+
**Card not showing in `get_cards`**
|
|
168
|
+
Enrollment is only confirmed after you complete the VGS form in the browser. Call `get_cards` after finishing the form to verify.
|
|
169
|
+
|
|
170
|
+
**Tool returns an error about daily limit**
|
|
171
|
+
Check your remaining budget with `visa-cli status` or ask your assistant: "What's my remaining budget today?"
|
|
172
|
+
|
|
173
|
+
**Catalog shows stale tools**
|
|
174
|
+
Delete `~/.visa-mcp/catalog-cache.json` and restart the MCP server to force a fresh fetch.
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var rt=Object.create;var ge=Object.defineProperty;var st=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var it=Object.getPrototypeOf,at=Object.prototype.hasOwnProperty;var ct=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var lt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ot(e))!at.call(t,s)&&s!==n&&ge(t,s,{get:()=>e[s],enumerable:!(r=st(e,s))||r.enumerable});return t};var g=(t,e,n)=>(n=t!=null?rt(it(t)):{},lt(e||!t||!t.__esModule?ge(n,"default",{value:t,enumerable:!0}):n,t));var ee=ct((Ut,mt)=>{mt.exports={name:"@visa/cli",version:"1.0.7-rc.0",description:"AI-powered payments for Claude Code",bin:{"visa-cli":"./bin/visa-cli.js"},scripts:{build:"tsc --noEmit && node esbuild.config.js",dev:"tsc --watch",start:"node dist/mcp-server/index.js",test:"jest --config jest.config.js","test:unit":"jest --config jest.config.js","test:unit:watch":"jest --config jest.config.js --watch","test:unit:coverage":"jest --config jest.config.js --coverage","test:smoke":"VISA_AUTH_URL=https://auth.visacli.sh jest --config jest.smoke.config.js","test:integration":"jest --config jest.integration.config.js","test:e2e":"jest --config jest.e2e.config.js","test:catalog-e2e":"jest --config jest.catalog-e2e.config.js","test:all":"npm run test:unit && npm run test:integration && npm run test:e2e",prepublishOnly:"npm run build && npm test",lint:"eslint src/**/*.ts",format:'prettier --write "src/**/*.ts"',"format:check":'prettier --check "src/**/*.ts"'},keywords:["visa","checkout","mcp","ai-agent","payments","click-to-pay","usdc","stablecoin"],author:"Visa Crypto Labs",license:"SEE LICENSE IN LICENSE",dependencies:{"@modelcontextprotocol/sdk":"^1.0.0",commander:"^12.1.0",zod:"^3.23.0"},devDependencies:{"@visa-cli/tools":"workspace:*","@changesets/changelog-git":"^0.2.1","@changesets/cli":"^2.30.0","@types/jest":"^30.0.0","@types/node":"^22.10.0","@typescript-eslint/eslint-plugin":"^8.56.1","@typescript-eslint/parser":"^8.56.1","@types/express":"^5.0.0",esbuild:"^0.27.4",express:"^4.21.0",eslint:"^10.0.2","eslint-config-prettier":"^10.1.8",jest:"^29.7.0",prettier:"^3.8.1","ts-jest":"^29.2.0",typescript:"^5.7.0"},engines:{node:">=18.0.0"},files:["bin/visa-cli.js","dist/","native/visa-keychain.m","README.md","LICENSE"]}});var Xe=require("commander"),z=g(require("crypto")),N=g(require("os")),Ze=require("child_process"),Qe=require("util");var ye=require("child_process"),Se=require("util"),E=g(require("fs")),ve=g(require("os")),Z=g(require("path")),P=(0,Se.promisify)(ye.execFile),Q=Z.join(ve.homedir(),".visa-mcp"),U=Z.join(Q,"session-token"),k="visa-cli",V="session-token",K="rc-access";async function fe(){try{let{stdout:t}=await P("security",["find-generic-password","-s",k,"-a",V,"-w"],{timeout:5e3});return t.trim()||null}catch{return null}}async function me(t){try{try{await P("security",["delete-generic-password","-s",k,"-a",V],{timeout:5e3})}catch{}return await P("security",["add-generic-password","-s",k,"-a",V,"-w",t],{timeout:5e3}),!0}catch{return!1}}async function he(){try{await P("security",["delete-generic-password","-s",k,"-a",V],{timeout:5e3})}catch{}}async function ut(){try{let{stdout:t}=await P("security",["find-generic-password","-s",k,"-a",K,"-w"],{timeout:5e3});return t.trim()||null}catch{return null}}async function dt(t){try{try{await P("security",["delete-generic-password","-s",k,"-a",K],{timeout:5e3})}catch{}await P("security",["add-generic-password","-s",k,"-a",K,"-w",t],{timeout:5e3})}catch{}}async function pt(){try{await P("security",["delete-generic-password","-s",k,"-a",K],{timeout:5e3})}catch{}}function gt(t){E.mkdirSync(Q,{recursive:!0,mode:448}),E.writeFileSync(U,t,{mode:384})}function ft(){try{return E.readFileSync(U,"utf-8").trim()||null}catch{return null}}var h=class{static async getSessionToken(){if(process.env.VISA_MOCK_KEYCHAIN==="true")return Promise.resolve("mock-session-token-for-testing");let e=await fe();if(e)return e;let n=ft();return n?(await me(n),n):null}static async saveSessionToken(e){if(process.env.VISA_MOCK_KEYCHAIN==="true")return;if(await me(e)){if(await fe()===e){try{E.unlinkSync(U)}catch{}return}await he()}if(gt(e),await this.getSessionToken()!==e)throw new Error("Failed to persist session token. "+(process.platform==="darwin"?'Check Keychain Access permissions for "visa-cli".':`Ensure ${Q} is writable.`))}static async getRcAccessToken(){return process.env.VISA_MOCK_KEYCHAIN==="true"?"mock-rc-token-for-testing":ut()}static async saveRcAccessToken(e){process.env.VISA_MOCK_KEYCHAIN!=="true"&&await dt(e)}static async deleteSessionToken(){if(process.env.VISA_MOCK_KEYCHAIN!=="true"){await he();try{E.unlinkSync(U)}catch{}}}static async clearAll(){await this.deleteSessionToken(),await pt()}};var D=g(require("crypto")),H=g(require("tty")),F=g(require("fs"));var R="6820f6e91b762e645c9bf020c0d3673bb99d4a25a824880c0d548e10bb9bc7b1";function ht(t){return/-rc\.|-beta\./.test(t)}function te(t){return D.createHash("sha256").update(t.trim()).digest("hex")}function we(t){return R==="SKIP"?!0:D.timingSafeEqual(Buffer.from(te(t)),Buffer.from(R))}function yt(t){return new Promise((e,n)=>{let r=F.openSync("/dev/tty","r+"),s=new H.ReadStream(r),o=new H.WriteStream(r),a=()=>{try{s.destroy()}catch{}try{o.destroy()}catch{}try{F.closeSync(r)}catch{}};o.write(t),s.setRawMode(!0),s.resume(),s.setEncoding("utf8");let i="";s.on("data",c=>{c==="\r"||c===`
|
|
2
2
|
`?(o.write(`
|
|
3
|
-
`),
|
|
4
|
-
`),
|
|
3
|
+
`),a(),e(i)):c===""?(o.write(`
|
|
4
|
+
`),a(),n(new Error("Cancelled"))):c==="\x7F"||c==="\b"?i.length>0&&(i=i.slice(0,-1),o.write("\b \b")):(i+=c,o.write("\u2022"))})})}var St=`
|
|
5
5
|
\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557
|
|
6
6
|
\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557
|
|
7
7
|
\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551
|
|
@@ -10,24 +10,24 @@
|
|
|
10
10
|
\u255A\u2550\u2550\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D
|
|
11
11
|
|
|
12
12
|
This is a Release Candidate build. Access is restricted to Visa employees.
|
|
13
|
-
`;async function
|
|
14
|
-
`),process.exit(1)}let
|
|
13
|
+
`;async function be(t={}){let e=t.version??ee().version;if(!ht(e))return;let n=process.env.VISA_RC_CODE;if(n&&we(n)){await h.saveRcAccessToken(te(n));return}if(t.isMcp??!1){let a=await h.getRcAccessToken();if(a&&(R==="SKIP"||a===R))return;process.stderr.write(`[visa-cli] RC build requires access. Run: visa-cli setup
|
|
14
|
+
`),process.exit(1)}let s=await h.getRcAccessToken();if(s&&(R==="SKIP"||s===R))return;console.log(St);let o=3;for(let a=1;a<=o;a++){let i;try{i=await yt(" Enter RC access code: ")}catch{process.exit(1)}if(we(i)){await h.saveRcAccessToken(te(i)),console.log(`
|
|
15
15
|
Access granted. Welcome.
|
|
16
|
-
`);return}o
|
|
17
|
-
Invalid code. ${
|
|
16
|
+
`);return}a<o&&console.log(`
|
|
17
|
+
Invalid code. ${o-a} attempt(s) remaining.
|
|
18
18
|
`)}console.log(`
|
|
19
19
|
Invalid code. Contact your team lead.
|
|
20
|
-
`),process.exit(1)}
|
|
21
|
-
|
|
20
|
+
`),process.exit(1)}var Ce=require("child_process");function vt(t=process.env,e=process.platform){return t.VISA_CLI_NO_BROWSER==="1"||t.VISA_CLI_NO_BROWSER==="true"?{headless:!0,reason:"VISA_CLI_NO_BROWSER is set"}:t.CI==="true"||t.CI==="1"?{headless:!0,reason:"CI environment detected"}:t.SSH_CONNECTION||t.SSH_TTY?{headless:!0,reason:"SSH session detected"}:e==="linux"&&!t.DISPLAY&&!t.WAYLAND_DISPLAY?{headless:!0,reason:"Linux with no $DISPLAY or $WAYLAND_DISPLAY"}:{headless:!1}}function wt(t){let n=t.length+4;return[`\u250C${"\u2500".repeat(n)}\u2510`,`\u2502${" ".repeat(2)}${t}${" ".repeat(2)}\u2502`,`\u2514${"\u2500".repeat(n)}\u2518`].join(`
|
|
21
|
+
`)}function bt(t,e=process.platform){return e==="darwin"?{cmd:"open",args:[t]}:e==="win32"?{cmd:"cmd",args:["/c","start","",t]}:e==="linux"?{cmd:"xdg-open",args:[t]}:null}async function Ee(t,e={}){let n=e.log??(c=>console.log(c)),r=e.env??process.env,s=e.platform??process.platform,o=e.spawn??((c,l,d)=>{(0,Ce.execFile)(c,l,b=>d(b))});n(""),n(" Sign in to Visa CLI by opening this URL in your browser:"),n("");for(let c of wt(t).split(`
|
|
22
|
+
`))n(` ${c}`);n("");let a=vt(r,s);if(a.headless){n(` (${a.reason} \u2014 skipping browser auto-open.)`),n(" Open the URL above on any device with a browser. The CLI will"),n(" continue waiting for you to complete sign-in."),n("");return}let i=bt(t,s);if(!i){n(` No known browser-open command for platform "${s}".`),n(" Open the URL above manually to continue."),n("");return}await new Promise(c=>{o(i.cmd,i.args,l=>{l?(n(` Could not open browser automatically (${l.message}).`),n(" Open the URL above manually to continue."),n("")):(n(" Opened browser. Waiting for you to sign in..."),n("")),c()})})}async function Pe(t,e){let n=e?.timeoutMs??3e4,r=new AbortController,s=setTimeout(()=>r.abort(),n);try{let{timeoutMs:o,...a}=e??{};return await fetch(t,{...a,signal:r.signal})}finally{clearTimeout(s)}}var Ct=/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;function Re(t,e){let n=ke(t),r=ke(e);if(!n||!r)return!1;for(let s=0;s<3;s++)if(n.main[s]!==r.main[s])return n.main[s]>r.main[s];return n.pre&&!r.pre?!1:!n.pre&&r.pre?!0:!n.pre&&!r.pre?!1:Et(n.pre,r.pre)>0}function ke(t){if(typeof t!="string")return null;let n=t.trim().replace(/^v/,"").match(Ct);return n?{main:[Number(n[1]),Number(n[2]),Number(n[3])],pre:n[4]??null}:null}function Et(t,e){let n=t.split("."),r=e.split("."),s=Math.max(n.length,r.length);for(let o=0;o<s;o++){if(o>=n.length)return-1;if(o>=r.length)return 1;let a=n[o],i=r[o],c=/^\d+$/.test(a),l=/^\d+$/.test(i);if(c&&l){let d=Number(a)-Number(i);if(d!==0)return d}else{if(c)return-1;if(l)return 1;if(a<i)return-1;if(a>i)return 1}}return 0}function q(){return!!($e(process.env.VISA_CLI_NO_UPDATE_CHECK)||$e(process.env.CI)||process.env.NODE_ENV==="test")}function $e(t){if(t===void 0)return!1;let e=t.trim().toLowerCase();return!(e===""||e==="0"||e==="false"||e==="no"||e==="off")}var ne="1.0.7-rc.0",A=class{constructor(e){this.getSessionToken=e;this.baseUrl=process.env.VISA_AUTH_URL||"https://auth.visacli.sh"}getSessionToken;baseUrl;lastSignals={};parseServerSignals(e){if(this.lastSignals={},!q()){let r=e.headers.get("X-Latest-Version"),s=e.headers.get("X-Update-Message");r&&Re(r,ne)&&(this.lastSignals.updateAvailable={version:r,message:s||`Update available: v${r}. Run: npm install -g @visa/cli && visa-cli setup`})}let n=e.headers.get("X-Feedback-Prompt");if(n)try{this.lastSignals.feedbackPrompt=JSON.parse(n)}catch{}}getClientVersion(){return ne}async request(e,n,r,s,o){let a=await this.getSessionToken();if(!a)throw new Error("Not logged in. Sign up at https://visacli.sh or run: visa-cli setup");let i={Authorization:`Bearer ${a}`};o&&(e==="GET"?i["X-User-Context"]=o.replace(/[\r\n\0]/g," ").slice(0,1e3):r={...r||{},user_context:o}),r&&(i["Content-Type"]="application/json");let c;try{c=await Pe(`${this.baseUrl}${n}`,{method:e,headers:{...i,"X-Visa-CLI-Version":ne},body:r?JSON.stringify(r):void 0,timeoutMs:s})}catch(d){throw d.name==="AbortError"||d.message?.includes("aborted")?new Error("The request timed out. The server may be under heavy load. Please try again."):new Error("Cannot reach the Visa CLI server. Check your internet connection and try again.")}if(this.parseServerSignals(c),c.status===401)throw new Error("Your session has expired. Run: visa-cli setup");if(c.status===429){let d=c.headers.get("Retry-After")||"3";throw new Error(`Rate limited \u2014 wait ${d}s. Tip: use the batch tool to combine multiple requests into one.`)}if(c.status===503)throw new Error("Visa CLI is temporarily unavailable. Check https://visacli.sh for status.");let l;try{l=await c.json()}catch{throw c.status===500?new Error(`Server error on ${n}. Try again or check https://visacli.sh for status.`):new Error(`Unexpected response from ${n}. Try again.`)}if(!c.ok)throw c.status===500?new Error(`Server error on ${n}. Try again or check https://visacli.sh for status.`):new Error(l?.error||`Request failed (${c.status}). Try again.`);return l}async pay(e,n){return this.request("POST","/v1/pay",e,void 0,n)}async shortcut(e,n,r,s){return this.request("POST",`/v1/shortcuts/${encodeURIComponent(e)}`,n,r,s)}async batch(e,n,r){return this.request("POST","/v1/batch",e,n,r)}async catalogSearch(e,n){let r=new URLSearchParams;e&&r.set("q",e),n&&r.set("category",n);let s=r.toString();return this.request("GET",`/v1/catalog${s?`?${s}`:""}`)}async catalogTool(e){try{return await this.request("GET",`/v1/catalog/${encodeURIComponent(e)}`)}catch{return null}}async paymentPreview(e,n){return this.request("POST","/v1/payment-preview",e,void 0,n)}async getStatus(e){return this.request("GET","/v1/status",void 0,void 0,e)}async getTransactions(e){return this.request("GET","/v1/transactions",void 0,void 0,e)}async updateSpendingControls(e,n){return this.request("POST","/v1/spending-controls",e,void 0,n)}async removeCard(e,n,r){return this.request("DELETE",`/v1/cards/${encodeURIComponent(String(e))}`,n,void 0,r)}async setDefaultCard(e,n,r){return this.request("POST",`/v1/cards/${encodeURIComponent(String(e))}/default`,n,void 0,r)}async getAttestationChallenge(){return this.request("GET","/v1/attestation-challenge")}async registerAttestationKey(e){return this.request("POST","/v1/attestation-key",{publicKey:e})}async logout(e,n){return this.request("POST","/v1/logout",e,void 0,n)}async feedback(e,n,r){return this.request("POST","/v1/feedback",{message:e,...n&&{transaction_id:n}},void 0,r)}async feedSubmit(e){return this.request("POST","/v1/feed",e)}async feedList(e){let n=new URLSearchParams;e?.tab&&n.set("tab",e.tab),e?.limit&&n.set("limit",String(e.limit)),e?.offset&&n.set("offset",String(e.offset));let r=n.toString();return this.request("GET",`/v1/feed${r?"?"+r:""}`)}async feedVote(e,n){return this.request("POST",`/v1/feed/${encodeURIComponent(e)}/vote`,{direction:n})}async feedApprove(e){return this.request("POST",`/v1/feed/${encodeURIComponent(e)}/approve`)}async feedDelete(e){return this.request("DELETE",`/v1/feed/${encodeURIComponent(e)}`)}async feedPending(){return this.request("GET","/v1/feed/pending")}async submitFeedback(e,n,r){return this.request("POST","/v1/feedback",{message:e,...n&&{transaction_id:n}},void 0,r)}async getFeedback(e,n){let r=new URLSearchParams;e&&r.set("limit",String(e));let s=r.toString();return this.request("GET",`/v1/feedback${s?"?"+s:""}`,void 0,void 0,n)}async submitRatedFeedback(e){return this.request("POST","/v1/feedback",e)}};var ae=require("child_process"),_e=require("util"),je=g(require("crypto")),f=g(require("fs")),Me=g(require("os")),C=g(require("path"));var y=g(require("fs")),oe=g(require("path")),xe=g(require("os")),se=oe.join(xe.homedir(),".visa-mcp"),O=oe.join(se,"mcp-server.log"),Pt=5*1024*1024,re=null;function kt(){y.existsSync(se)||y.mkdirSync(se,{recursive:!0,mode:448})}function Rt(){if(!re){if(kt(),y.existsSync(O)&&y.statSync(O).size>Pt){let e=O+".1";y.existsSync(e)&&y.unlinkSync(e),y.renameSync(O,e)}re=y.createWriteStream(O,{flags:"a"})}return re}function B(t,...e){let n=new Date().toISOString(),r=e.map(o=>typeof o=="string"?o:JSON.stringify(o,null,2)).join(" "),s=`[${n}] [${t}] ${r}
|
|
23
|
+
`;process.stderr.write(s),Rt().write(s)}var Ie={debug:(...t)=>B("DEBUG",...t),info:(...t)=>B("INFO",...t),warn:(...t)=>B("WARN",...t),error:(...t)=>B("ERROR",...t)};var I=(0,_e.promisify)(ae.execFile),Y=C.join(Me.homedir(),".visa-mcp","bin"),$=C.join(Y,"Visa CLI"),$t=C.join(__dirname,"..","native"),Ne="5",Te=C.join(Y,"visa-keychain.version"),Ae=C.join(Y,"visa-keychain.sha256");function Oe(t){let e=f.readFileSync(t);return je.createHash("sha256").update(e).digest("hex")}async function Le(){try{if(f.readFileSync(Te,"utf-8").trim()===Ne&&f.existsSync($)){let r=f.readFileSync(Ae,"utf-8").trim();if(Oe($)!==r)Ie.warn("binary:hash-mismatch",{message:"Binary hash mismatch \u2014 possible tampering detected. Recompiling from source."}),f.unlinkSync($);else return $}}catch{}let t=C.join($t,"visa-keychain.m");if(f.existsSync(t)||(t=C.resolve(__dirname,"..","..","native","visa-keychain.m")),f.existsSync(t)||(t=C.resolve(__dirname,"..","native","visa-keychain.m")),!f.existsSync(t))throw new Error("visa-keychain.m source not found. Reinstall Visa CLI.");f.mkdirSync(Y,{recursive:!0,mode:448});try{await I("clang",["-framework","Security","-framework","LocalAuthentication","-framework","Foundation","-framework","AppKit","-o",$,t],{timeout:3e4})}catch(n){throw n.code==="ENOENT"?new Error("Xcode Command Line Tools required. Install: xcode-select --install"):n}let e=Oe($);return f.writeFileSync(Ae,e,{mode:384}),f.writeFileSync(Te,Ne,{mode:384}),$}async function Ue(t){let e=await Le(),n;try{n=(await I(e,t,{timeout:6e4})).stdout}catch(o){n=o.stdout||"";let a=n.trim();throw a.startsWith("ERROR:")?new Error(a.slice(6)):new Error(o.stderr?.trim()||o.message||"Unknown error")}let r=n.trim();if(r.startsWith("OK:"))return r.slice(3);if(r==="OK")return;let s=r.startsWith("ERROR:")?r.slice(6):"Unknown error";throw new Error(s)}var ie=null;function _(){return process.env.VISA_MOCK_TOUCHID==="true"?!0:process.platform!=="darwin"?!1:ie!==null?ie:(ie=!0,!0)}var G="visa-cli",W="attestation-key";async function xt(t){try{await I("security",["delete-generic-password","-s",G,"-a",W],{timeout:5e3})}catch{}await I("security",["add-generic-password","-s",G,"-a",W,"-w",t],{timeout:5e3})}async function It(){try{let{stdout:t}=await I("security",["find-generic-password","-s",G,"-a",W,"-w"],{timeout:5e3});return t.trim()||null}catch{return null}}async function Ve(){let t=await Ue(["generate-key"]);if(!t)throw new Error("Key generation returned no output");let e=t.indexOf(":");if(e<0)throw new Error("Unexpected generate-key output format");let n=t.slice(0,e),r=t.slice(e+1);return await xt(n),r}async function Ke(t,e){if(process.env.VISA_MOCK_TOUCHID==="true")return Promise.resolve("mock-ecdsa-signature-for-testing");let n=await It();if(!n)throw new Error("Attestation key not found. Run setup to generate a new key.");let r=await Le(),s=["sign",t];return e&&s.push(e),new Promise((o,a)=>{let i=(0,ae.execFile)(r,s,{timeout:6e4},(c,l)=>{let d=(l||"").trim();if(c){d.startsWith("ERROR:")?a(new Error(d.slice(6))):a(new Error(c.stderr?.trim()||c.message||"Unknown error"));return}d.startsWith("OK:")?o(d.slice(3)):a(new Error(d.startsWith("ERROR:")?d.slice(6):"Unknown error"))});i.stdin.write(n),i.stdin.end()})}async function De(){try{await I("security",["delete-generic-password","-s",G,"-a",W],{timeout:5e3})}catch{}try{await Ue(["delete-key"])}catch{}}function He(t,e=process.stderr){if(q()||!t?.updateAvailable)return!1;let{message:n}=t.updateAvailable;return n?(e.write(`
|
|
22
24
|
\x1B[33m\u2191 ${n}\x1B[0m
|
|
23
|
-
`),!0):!1}var S=class extends Error{constructor(e){super(e),this.name="PayValidationError"}},
|
|
24
|
-
`),{installed:!0,configPath:n,message:t.postInstallHint}}function
|
|
25
|
-
`),{removed:!0,configPath:n})}function
|
|
26
|
-
${r}: ${n(t.currentPath)}`}function
|
|
27
|
-
Step 2: Checking authentication...`);let
|
|
28
|
-
|
|
29
|
-
`);let pe=3e4,Qe=300*1e3,et=Date.now()+Qe;for(;Date.now()<et;)try{let A=await globalThis.fetch("https://auth.visacli.sh/v1/auth-status",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({state:P,timeout:pe}),signal:AbortSignal.timeout(pe+5e3)});if(!A.ok)continue;let $=await A.json();if($.status==="pending")continue;if($.status==="expired"){g(new Error("Session expired. Please run setup again."));return}if($.status==="complete"&&$.sessionToken){console.log(` Signed in as ${$.user}.`),l($.sessionToken);return}}catch{}g(new Error("Login timed out after 5 minutes. Please run setup again."))}),await h.saveSessionToken(i),console.log(" Session token saved.")),console.log(`
|
|
30
|
-
Step 3: Setting up authentication...`),!_())console.log(" Not macOS \u2014 skipping biometric setup.");else{try{await $t("clang",["--version"])}catch{console.error(" Xcode Command Line Tools are required for payment authentication."),console.error(" Install them by running: xcode-select --install"),console.error(" Then re-run: visa-cli setup"),process.exit(1)}try{let l=await Le();console.log(" Attestation key generated."),await Z().registerAttestationKey(l),console.log(" Attestation key registered with server.")}catch(l){console.log(` Skipped: ${l.message}`)}}let a="\x1B[1m",c="\x1B[0m";console.log(`
|
|
25
|
+
`),!0):!1}var S=class extends Error{constructor(e){super(e),this.name="PayValidationError"}},Fe=["GET","POST"];function qe(t){let e;try{e=new URL(t)}catch{throw new S(`Invalid URL: ${t}. Expected a fully-qualified http(s) URL.`)}if(e.protocol!=="http:"&&e.protocol!=="https:")throw new S(`Unsupported URL scheme "${e.protocol}". Only http and https are allowed.`);return e}function Be(t){let e=(t??"GET").toUpperCase();if(!Fe.includes(e))throw new S(`Unsupported HTTP method "${t}". Supported: ${Fe.join(", ")}.`);return e}function Ge(t){if(t!==void 0){try{JSON.parse(t)}catch(e){throw new S(`--body is not valid JSON: ${e?.message??"parse error"}`)}return t}}function We(t){if(!t||typeof t!="object")throw new S("Merchant returned no payment preview.");let e=t;if(typeof e.amount!="number"||!Number.isFinite(e.amount)||e.amount<=0)throw new S("Could not determine payment amount from merchant.");if(typeof e.merchantName!="string"||e.merchantName.trim().length===0)throw new S("Merchant returned an empty merchant name.");if(e.merchantName.length>200)throw new S(`Merchant name too long (${e.merchantName.length} chars).`);if(typeof e.currency!="string"||e.currency.trim().length===0)throw new S("Merchant returned an empty currency.");if(e.currency.length>10)throw new S(`Currency code too long (${e.currency.length} chars).`);return{amount:e.amount,currency:e.currency,merchantName:e.merchantName}}var p=g(require("fs")),u=g(require("path")),Ye=g(require("os")),m=Ye.homedir(),v=[{id:"claude",displayName:"Claude Code",globalConfigPath:u.join(m,".claude.json"),configKey:"mcpServers",detectPaths:[u.join(m,".claude.json")],postInstallHint:"Restart Claude Code or run /mcp to connect."},{id:"claude-desktop",displayName:"Claude Desktop",globalConfigPath:u.join(m,"Library","Application Support","Claude","claude_desktop_config.json"),configKey:"mcpServers",detectPaths:[u.join(m,"Library","Application Support","Claude")],postInstallHint:"Restart the Claude desktop app to connect."},{id:"cursor",displayName:"Cursor",globalConfigPath:u.join(m,".cursor","mcp.json"),configKey:"mcpServers",detectPaths:[u.join(m,".cursor")],postInstallHint:"Restart Cursor to connect."},{id:"windsurf",displayName:"Windsurf",globalConfigPath:u.join(m,".codeium","windsurf","mcp_config.json"),configKey:"mcpServers",detectPaths:[u.join(m,".codeium","windsurf")],postInstallHint:"Restart Windsurf to connect."},{id:"cline",displayName:"Cline",globalConfigPath:u.join(m,".vscode","mcp.json"),configKey:"mcpServers",detectPaths:[u.join(m,".vscode","extensions","saoudrizwan.claude-dev-*")],postInstallHint:"Restart VS Code to connect."},{id:"roo-code",displayName:"Roo Code",globalConfigPath:u.join(m,".config","Roo","mcp_settings.json"),configKey:"mcpServers",detectPaths:[u.join(m,".vscode","extensions","RooVeterinaryInc.roo-cline-*")],postInstallHint:"Restart VS Code to connect."},{id:"copilot",displayName:"VS Code Copilot",globalConfigPath:u.join(m,".vscode","mcp.json"),configKey:"servers",detectPaths:[u.join(m,".vscode")],postInstallHint:"Restart VS Code to connect."},{id:"zed",displayName:"Zed",globalConfigPath:u.join(m,".config","zed","settings.json"),configKey:"context_servers",detectPaths:[u.join(m,".config","zed")],postInstallHint:"Restart Zed to connect.",buildEntry:t=>({source:"custom",...t})}];function ce(t){return v.find(e=>e.id===t)}function j(t){return t.detectPaths.some(e=>{if(e.includes("*")){let n=u.dirname(e),r=u.basename(e).replaceAll("*","");if(!p.existsSync(n))return!1;try{return p.readdirSync(n).some(s=>s.startsWith(r))}catch{return!1}}return p.existsSync(e)})}function Je(){return{command:"node",args:[u.resolve(__dirname,"mcp-server/index.js")]}}function M(t,e="global"){let n=e==="project"?u.join(process.cwd(),".mcp.json"):t.globalConfigPath,r=u.dirname(n);p.existsSync(r)||p.mkdirSync(r,{recursive:!0});let s={};if(p.existsSync(n))try{s=JSON.parse(p.readFileSync(n,"utf-8"))}catch{s={}}s[t.configKey]=s[t.configKey]||{};let o=Je();return s[t.configKey]["visa-cli"]=t.buildEntry?t.buildEntry(o):o,p.writeFileSync(n,JSON.stringify(s,null,2)+`
|
|
26
|
+
`),{installed:!0,configPath:n,message:t.postInstallHint}}function le(t,e="global"){let n=e==="project"?u.join(process.cwd(),".mcp.json"):t.globalConfigPath;if(!p.existsSync(n))return{removed:!1,configPath:n};let r;try{r=JSON.parse(p.readFileSync(n,"utf-8"))}catch{return{removed:!1,configPath:n}}let s=r[t.configKey];return!s||!s["visa-cli"]?{removed:!1,configPath:n}:(delete s["visa-cli"],p.writeFileSync(n,JSON.stringify(r,null,2)+`
|
|
27
|
+
`),{removed:!0,configPath:n})}function ze(t,e="global"){let n=e==="project"?u.join(process.cwd(),".mcp.json"):t.globalConfigPath;if(!p.existsSync(n))return!1;try{return!!JSON.parse(p.readFileSync(n,"utf-8"))?.[t.configKey]?.["visa-cli"]}catch{return!1}}function Tt(t){if(!t||typeof t!="object")return;let e=t;if(e.command!=="node"||!Array.isArray(e.args)||e.args.length===0)return;let n=e.args[e.args.length-1];if(!(typeof n!="string"||n.length===0))return n}function At(t,e){if(t===e)return!0;let n=u.resolve(t),r=u.resolve(e);if(n===r)return!0;try{let s=p.realpathSync(n),o=p.realpathSync(r);return s===o}catch{return!1}}function L(){let t=Je(),e=t.args[t.args.length-1],n=[];for(let r of v){let s=r.globalConfigPath;if(!p.existsSync(s))continue;let o;try{o=JSON.parse(p.readFileSync(s,"utf-8"))}catch{continue}let a=o?.[r.configKey]?.["visa-cli"];if(!a)continue;let i=Tt(a);if(!i||At(i,e))continue;let c=p.existsSync(i)?"mismatch":"missing";n.push({client:r,configPath:s,currentPath:i,expectedPath:e,staleReason:c})}return n}function ue(t){return{configPath:M(t.client,"global").configPath}}var Ot=(0,Qe.promisify)(Ze.execFile);function _t(t){let e=N.homedir(),n=s=>s.replace(e,"~"),r=t.staleReason==="missing"?"path missing on disk":"path mismatch";return` \u2022 ${t.client.displayName} (${n(t.configPath)})
|
|
28
|
+
${r}: ${n(t.currentPath)}`}function et(t,e){if(t.length===0){console.log(`${e} \u2713 All MCP client configs are up to date.`);return}console.log(`${e} Found ${t.length} stale MCP config ${t.length===1?"entry":"entries"}:`);for(let n of t)console.log(_t(n))}var w=new Xe.Command,J=null;function X(){return J=new A(()=>h.getSessionToken()),J}w.name("visa-cli").description("Visa CLI - AI payment orchestration").version(ee().version);w.hook("preAction",async()=>{await be()});w.command("setup").description("Register MCP server, authenticate, and generate attestation key").option("--check","Scan MCP client configs for stale visa-cli entries and exit without making changes").action(async t=>{try{if(t.check){let l=L();et(l,"MCP config check:"),l.length>0&&(console.log("\nRun `visa-cli setup` (or `visa-cli install --repair`) to rewrite these entries."),process.exit(1));return}console.log("Step 1: Registering MCP server...");let e=L(),n=new Map(e.map(l=>[l.client.id,l])),r=new Set;for(let l of v)if(j(l)){let d=M(l),b=n.get(l.id),T=b?` \u2014 repaired stale ${b.staleReason} entry`:"";console.log(` \u2713 ${l.displayName} (${d.configPath.replace(N.homedir(),"~")})${T}`),b&&r.add(l.id)}let s=e.filter(l=>!r.has(l.client.id));for(let l of s)ue(l),console.log(` \u2713 ${l.client.displayName} (${l.configPath.replace(N.homedir(),"~")}) \u2014 repaired stale ${l.staleReason} entry`);let o=r.size+s.length;console.log(o===0?" \u2713 MCP config verified \u2014 nothing to repair.":` \u2713 Repaired ${o} stale MCP config ${o===1?"entry":"entries"}.`),console.log(`
|
|
29
|
+
Step 2: Checking authentication...`);let a=await h.getSessionToken();if(a?console.log(" Already authenticated."):(console.log(" No session found. Opening browser for GitHub login..."),a=await new Promise(async(l,d)=>{let b=z.randomBytes(16).toString("hex"),T=`https://auth.visacli.sh/login?state=${b}`;await Ee(T);let de=3e4,tt=300*1e3,nt=Date.now()+tt;for(;Date.now()<nt;)try{let pe=await globalThis.fetch("https://auth.visacli.sh/v1/auth-status",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({state:b,timeout:de}),signal:AbortSignal.timeout(de+5e3)});if(!pe.ok)continue;let x=await pe.json();if(x.status==="pending")continue;if(x.status==="expired"){d(new Error("Session expired. Please run setup again."));return}if(x.status==="complete"&&x.sessionToken){console.log(` Signed in as ${x.user}.`),l(x.sessionToken);return}}catch{}d(new Error("Login timed out after 5 minutes. Please run setup again."))}),await h.saveSessionToken(a),console.log(" Session token saved.")),console.log(`
|
|
30
|
+
Step 3: Setting up authentication...`),!_())console.log(" Not macOS \u2014 skipping biometric setup.");else{try{await Ot("clang",["--version"])}catch{console.error(" Xcode Command Line Tools are required for payment authentication."),console.error(" Install them by running: xcode-select --install"),console.error(" Then re-run: visa-cli setup"),process.exit(1)}try{let l=await Ve();console.log(" Attestation key generated."),await X().registerAttestationKey(l),console.log(" Attestation key registered with server.")}catch(l){console.log(` Skipped: ${l.message}`)}}let i="\x1B[1m",c="\x1B[0m";console.log(`
|
|
31
31
|
\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557
|
|
32
32
|
\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557
|
|
33
33
|
\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551
|
|
@@ -35,26 +35,26 @@ Step 3: Setting up authentication...`),!_())console.log(" Not macOS \u2014 ski
|
|
|
35
35
|
\u255A\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551
|
|
36
36
|
\u255A\u2550\u2550\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u2588 CLI
|
|
37
37
|
|
|
38
|
-
${
|
|
38
|
+
${i}Setup complete.${c} Restart Claude Code or run /mcp to connect.
|
|
39
39
|
|
|
40
|
-
${
|
|
40
|
+
${i}Try it out:${c}
|
|
41
41
|
\u2022 Ask Claude: "Generate an image of a neon cityscape"
|
|
42
42
|
\u2022 Ask Claude: "What's the price of ETH on Base?"
|
|
43
43
|
\u2022 Or run: visa-cli pay <merchant-url>
|
|
44
44
|
|
|
45
|
-
${
|
|
46
|
-
${
|
|
47
|
-
`)}catch(e){console.error("Error:",e.message),process.exit(1)}});
|
|
45
|
+
${i}Verify:${c} visa-cli status
|
|
46
|
+
${i}Docs:${c} https://visacli.sh
|
|
47
|
+
`)}catch(e){console.error("Error:",e.message),process.exit(1)}});w.command("install [client]").description("Register MCP server with an AI client (claude, cursor, windsurf, cline, zed, ...)").option("--all","Install for all detected clients").option("--list","Show supported clients and install status").option("--check","Scan MCP client configs for stale visa-cli entries and exit without making changes").option("--repair","Repair stale MCP client configs without re-running the full setup flow").option("--scope <scope>","Install scope: global or project","global").action(async(t,e)=>{try{if(e.check){let o=L();et(o,"MCP config check:"),o.length>0&&process.exit(1);return}if(e.repair){let o=L();if(o.length===0){console.log("\u2713 MCP config verified \u2014 nothing to repair.");return}for(let a of o)ue(a),console.log(` \u2713 ${a.client.displayName} (${a.configPath.replace(N.homedir(),"~")}) \u2014 repaired stale ${a.staleReason} entry`);console.log(`
|
|
48
48
|
Repaired ${o.length} stale MCP config ${o.length===1?"entry":"entries"}.`);return}if(e.list){console.log(`
|
|
49
49
|
\x1B[1mSupported MCP Clients\x1B[0m
|
|
50
|
-
`),console.log(` ${"Client".padEnd(18)} ${"Detected".padEnd(10)} ${"Installed".padEnd(11)} Config Path`),console.log(` ${"\u2500".repeat(18)} ${"\u2500".repeat(10)} ${"\u2500".repeat(11)} ${"\u2500".repeat(40)}`);for(let
|
|
51
|
-
Supported clients: ${
|
|
52
|
-
Supported clients: ${
|
|
53
|
-
`);let
|
|
54
|
-
Result URLs:`);for(let c of
|
|
50
|
+
`),console.log(` ${"Client".padEnd(18)} ${"Detected".padEnd(10)} ${"Installed".padEnd(11)} Config Path`),console.log(` ${"\u2500".repeat(18)} ${"\u2500".repeat(10)} ${"\u2500".repeat(11)} ${"\u2500".repeat(40)}`);for(let i of v){let c=j(i),l=ze(i),d=c?"Yes":"No",b=l?"Yes":"No",T=i.globalConfigPath.replace(N.homedir(),"~");console.log(` ${i.displayName.padEnd(18)} ${d.padEnd(10)} ${b.padEnd(11)} ${T}`)}console.log("");return}let n=e.scope==="project"?"project":"global";if(e.all){let o=[],a=[];for(let i of v){if(!j(i)){a.push(i.displayName);continue}M(i,n),o.push(i.displayName)}o.length>0&&console.log(`Installed for: ${o.join(", ")}.`),a.length>0&&console.log(`Skipped: ${a.map(i=>`${i} (not detected)`).join(", ")}.`),o.length===0&&a.length===0&&console.log("No supported clients found.");return}t||(console.error("Usage: visa-cli install <client>"),console.error(" visa-cli install --all"),console.error(" visa-cli install --list"),console.error(`
|
|
51
|
+
Supported clients: ${v.map(o=>o.id).join(", ")}`),process.exit(1));let r=ce(t);r||(console.error(`Unknown client: ${t}`),console.error(`Supported clients: ${v.map(o=>o.id).join(", ")}`),process.exit(1)),n==="global"&&!j(r)&&(console.error(`${r.displayName} not detected on this machine.`),console.error(`Expected: ${r.detectPaths.join(", ")}`),process.exit(1));let s=M(r,n);console.log(`Registered visa-cli MCP server in ${s.configPath}`),console.log(s.message)}catch(n){console.error("Error:",n.message),process.exit(1)}});w.command("uninstall [client]").description("Remove MCP server from an AI client").option("--all","Remove from all clients").option("--scope <scope>","Uninstall scope: global or project","global").action(async(t,e)=>{try{let n=e.scope==="project"?"project":"global";if(e.all){let o=[];for(let a of v)le(a,n).removed&&o.push(a.displayName);o.length>0?console.log(`Removed visa-cli from: ${o.join(", ")}.`):console.log("visa-cli was not installed in any client.");return}t||(console.error("Usage: visa-cli uninstall <client>"),console.error(" visa-cli uninstall --all"),console.error(`
|
|
52
|
+
Supported clients: ${v.map(o=>o.id).join(", ")}`),process.exit(1));let r=ce(t);r||(console.error(`Unknown client: ${t}`),console.error(`Supported clients: ${v.map(o=>o.id).join(", ")}`),process.exit(1));let s=le(r,n);s.removed?console.log(`Removed visa-cli from ${s.configPath}`):console.log(`visa-cli was not installed for ${r.displayName}.`)}catch(n){console.error("Error:",n.message),process.exit(1)}});w.command("pay <url>").description("Pay a merchant URL (amount auto-detected from HTTP 402 response)").option("-m, --method <method>","HTTP method (GET or POST)","GET").option("-b, --body <json>","JSON request body for POST endpoints").action(async(t,e)=>{try{qe(t);let n=Be(e.method),r=Ge(e.body),s=new A(()=>h.getSessionToken());console.log(`Checking payment for ${t}...`);let o=We(await s.paymentPreview({url:t}));console.log(` Merchant: ${o.merchantName}`),console.log(` Amount: $${o.amount.toFixed(2)} ${o.currency}`),console.log(` Rail: auto-detected
|
|
53
|
+
`);let a;if(_())try{let{nonce:c}=await s.getAttestationChallenge(),l=Buffer.from(JSON.stringify({nonce:c,amount:o.amount,merchant:o.merchantName,context:t})).toString("base64");a={signature:await Ke(l,`pay $${o.amount.toFixed(2)} to ${o.merchantName}`),nonce:c,amount:o.amount,merchant:o.merchantName}}catch(c){console.error(`Touch ID confirmation failed: ${c?.message||"user cancelled or biometric error"}`),process.exit(1)}else console.warn("Warning: Touch ID unavailable on this system \u2014 payment will proceed without biometric attestation.");let i=await s.pay({url:t,method:n,body:r,attestation:a,idempotencyKey:z.randomUUID()});if(i.success){if(console.log(`Payment complete: $${(i.amount??o.amount).toFixed(2)} \u2192 ${i.merchantName??o.merchantName}`),i.receipt?.urls?.length){console.log(`
|
|
54
|
+
Result URLs:`);for(let c of i.receipt.urls)console.log(` ${c}`)}}else console.error(`Payment failed: ${i.message||"Unknown error"}`),process.exit(1)}catch(n){n instanceof S?console.error(`Error: ${n.message}`):console.error("Error:",n.message),process.exit(1)}});w.command("status").description("Check enrollment, cards, wallet, and spending controls").action(async()=>{try{let e=await X().getStatus();if(console.log(`Visa CLI Status
|
|
55
55
|
`),console.log("Enrollment:"),console.log(` Enrolled: ${e.enrolled?"Yes":"No"}`),e.githubUser&&console.log(` GitHub: ${e.githubUser}`),console.log(` Cards: ${e.cardCount??0}`),e.cards&&e.cards.length>0){console.log(`
|
|
56
|
-
Cards:`);for(let n of e.cards){let r=n.isDefault?" (default)":"";console.log(` ${n.brand?.toUpperCase()||"CARD"} ****${n.last4}${r}`)}}if(e.spendingControls){let n=e.spendingControls;console.log(`
|
|
56
|
+
Cards:`);for(let n of e.cards){let r=n.isDefault?" (default)":"",s=Number.isInteger(n.id)?`#${n.id} `:"";console.log(` ${s}${n.brand?.toUpperCase()||"CARD"} ****${n.last4}${r}`)}}if(e.spendingControls){let n=e.spendingControls;console.log(`
|
|
57
57
|
Spending Controls:`),console.log(` Max per transaction: $${n.maxTransactionAmount}`),console.log(` Daily limit: $${n.dailyLimit}`),n.dailySpent!==void 0&&console.log(` Spent today: $${Number(n.dailySpent).toFixed(2)} / $${n.dailyLimit}`)}console.log(`
|
|
58
|
-
Touch ID:`),console.log(` Available: ${_()?"Yes":"No"}`)}catch(t){console.error("Error:",t.message),process.exit(1)}});
|
|
59
|
-
`);try{await
|
|
60
|
-
Reset complete.`)}catch(t){console.error("Error:",t.message),process.exit(1)}});
|
|
58
|
+
Touch ID:`),console.log(` Available: ${_()?"Yes":"No"}`)}catch(t){console.error("Error:",t.message),process.exit(1)}});w.command("reset").description("Log out and clear all credentials").action(async()=>{try{console.log(`Resetting Visa CLI...
|
|
59
|
+
`);try{await X().logout(),console.log(" Server session invalidated.")}catch{console.log(" Server logout skipped (no active session).")}if(await h.clearAll(),console.log(" Keychain credentials cleared."),_())try{await De(),console.log(" Secure Enclave key deleted.")}catch{console.log(" No Secure Enclave key to delete.")}console.log(`
|
|
60
|
+
Reset complete.`)}catch(t){console.error("Error:",t.message),process.exit(1)}});w.command("feedback").description("Submit feedback about Visa CLI").argument("[message]","Your feedback message").action(async t=>{(!t||t.trim().length===0)&&(console.log('Usage: visa-cli feedback "your message"'),process.exit(1));try{await h.getSessionToken()||(console.error("Not logged in. Run visa-cli setup first."),process.exit(1)),await X().feedback(t.trim()),console.log("Feedback submitted. Thanks!")}catch(e){console.error("Error:",e.message),process.exit(1)}});w.hook("postAction",()=>{J&&He(J.lastSignals)});w.parse();
|