@clawcard/cli 0.2.0 → 1.0.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/bin/clawcard.mjs +2 -0
- package/package.json +13 -5
- package/src/api.js +55 -0
- package/src/auth-guard.js +9 -0
- package/src/auth-server.js +63 -0
- package/src/commands/billing.js +169 -0
- package/src/commands/help.js +49 -0
- package/src/commands/keys.js +230 -0
- package/src/commands/login.js +39 -0
- package/src/commands/logout.js +12 -0
- package/src/commands/referral.js +37 -0
- package/src/commands/setup.js +291 -0
- package/src/commands/signup.js +47 -0
- package/src/commands/whoami.js +31 -0
- package/src/config.js +68 -0
- package/src/index.js +209 -0
- package/src/splash.js +11 -0
- package/bin/setup.mjs +0 -218
package/bin/setup.mjs
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
|
|
4
|
-
import { join } from "path";
|
|
5
|
-
import { homedir } from "os";
|
|
6
|
-
|
|
7
|
-
const OPENCLAW_DIR = join(homedir(), ".openclaw");
|
|
8
|
-
const SKILLS_DIR = join(OPENCLAW_DIR, "skills", "clawcard");
|
|
9
|
-
const SKILL_PATH = join(SKILLS_DIR, "SKILL.md");
|
|
10
|
-
|
|
11
|
-
const DEFAULT_BASE_URL = "https://www.clawcard.sh";
|
|
12
|
-
|
|
13
|
-
const SKILL_MD = `---
|
|
14
|
-
name: clawcard
|
|
15
|
-
description: Email, SMS, virtual cards, and credential vault for autonomous agents
|
|
16
|
-
metadata: {"openclaw":{"primaryEnv":"CLAWCARD_API_KEY","emoji":"\\ud83d\\udd11"}}
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
You have access to ClawCard — a platform that gives you a real email address, phone number, virtual debit cards, and an encrypted credential vault.
|
|
20
|
-
|
|
21
|
-
**Authentication:** All requests use your API key as a Bearer token.
|
|
22
|
-
|
|
23
|
-
## Getting Started
|
|
24
|
-
|
|
25
|
-
Base URL: $CLAWCARD_BASE_URL (default: https://www.clawcard.sh)
|
|
26
|
-
Auth header: Authorization: Bearer $CLAWCARD_API_KEY
|
|
27
|
-
|
|
28
|
-
**Step 1: Discover your identity.** Call GET /api/me first — it returns your keyId, email, phone, and budget. Use the keyId for all other endpoints.
|
|
29
|
-
|
|
30
|
-
curl -H "Authorization: Bearer $CLAWCARD_API_KEY" $CLAWCARD_BASE_URL/api/me
|
|
31
|
-
|
|
32
|
-
Response: { "keyId": "agt_...", "name": "...", "email": "...", "phone": "...", "spendLimitCents": ... }
|
|
33
|
-
|
|
34
|
-
## Endpoints
|
|
35
|
-
|
|
36
|
-
Use the keyId from /api/me as KEY_ID in all endpoints below.
|
|
37
|
-
|
|
38
|
-
### Identity
|
|
39
|
-
|
|
40
|
-
**Get full identity details:**
|
|
41
|
-
|
|
42
|
-
curl -H "Authorization: Bearer $CLAWCARD_API_KEY" $CLAWCARD_BASE_URL/api/agents/KEY_ID
|
|
43
|
-
|
|
44
|
-
### Email
|
|
45
|
-
|
|
46
|
-
**Read inbox:**
|
|
47
|
-
|
|
48
|
-
curl -H "Authorization: Bearer $CLAWCARD_API_KEY" "$CLAWCARD_BASE_URL/api/agents/KEY_ID/emails?limit=20"
|
|
49
|
-
|
|
50
|
-
**Send email:**
|
|
51
|
-
|
|
52
|
-
curl -X POST -H "Authorization: Bearer $CLAWCARD_API_KEY" -H "Content-Type: application/json" \\
|
|
53
|
-
-d '{"to":"recipient@example.com","subject":"Hello","body":"Message text"}' \\
|
|
54
|
-
$CLAWCARD_BASE_URL/api/agents/KEY_ID/emails/send
|
|
55
|
-
|
|
56
|
-
### SMS (inbound only)
|
|
57
|
-
|
|
58
|
-
Each key gets a dedicated phone number for receiving SMS (e.g. verification codes). Outbound SMS is not currently supported.
|
|
59
|
-
|
|
60
|
-
**Read received messages:**
|
|
61
|
-
|
|
62
|
-
curl -H "Authorization: Bearer $CLAWCARD_API_KEY" "$CLAWCARD_BASE_URL/api/agents/KEY_ID/sms?limit=20"
|
|
63
|
-
|
|
64
|
-
### Virtual Cards
|
|
65
|
-
|
|
66
|
-
**IMPORTANT: Before creating a card, always ask the user which card type they want.** Explain the two options:
|
|
67
|
-
|
|
68
|
-
1. **single_use** — Closes automatically after one successful transaction. Use for one-time purchases (buying a domain, paying an invoice, a single checkout).
|
|
69
|
-
2. **merchant_locked** — Locks to the first merchant that charges it and allows multiple charges from that merchant. Use for subscriptions or recurring payments (hosting, SaaS tools, any service paid monthly).
|
|
70
|
-
|
|
71
|
-
**Tip:** Merchant-locked cards are more efficient for recurring services since they only use one card from the monthly limit. Single-use cards are safer for one-off purchases since they can't be charged again.
|
|
72
|
-
|
|
73
|
-
**List cards (check for existing open cards before creating new ones):**
|
|
74
|
-
|
|
75
|
-
curl -H "Authorization: Bearer $CLAWCARD_API_KEY" $CLAWCARD_BASE_URL/api/agents/KEY_ID/cards
|
|
76
|
-
|
|
77
|
-
Response includes all cards with their type, status, and spend limit. Look for cards with status "open" — especially merchant_locked cards which can be reused for the same merchant.
|
|
78
|
-
|
|
79
|
-
**IMPORTANT:** Before creating a new card, always check if there's an existing open merchant_locked card for the same merchant. Reusing a merchant-locked card doesn't count against the monthly card limit.
|
|
80
|
-
|
|
81
|
-
**Create a card (returns PAN, CVV, expiry):**
|
|
82
|
-
|
|
83
|
-
curl -X POST -H "Authorization: Bearer $CLAWCARD_API_KEY" -H "Content-Type: application/json" \\
|
|
84
|
-
-d '{"amountCents":1000,"memo":"Hosting payment","type":"single_use"}' \\
|
|
85
|
-
$CLAWCARD_BASE_URL/api/agents/KEY_ID/cards
|
|
86
|
-
|
|
87
|
-
The "type" field is required. Must be "single_use" or "merchant_locked".
|
|
88
|
-
|
|
89
|
-
**Get card details (PAN, CVV, expiry — use this for existing open cards too):**
|
|
90
|
-
|
|
91
|
-
curl -H "Authorization: Bearer $CLAWCARD_API_KEY" $CLAWCARD_BASE_URL/api/agents/KEY_ID/cards/CARD_ID
|
|
92
|
-
|
|
93
|
-
Use this to retrieve the full card number, CVV, and expiry of any open card. This is how you reuse a merchant_locked card for repeat purchases at the same merchant.
|
|
94
|
-
|
|
95
|
-
**Close a card:**
|
|
96
|
-
|
|
97
|
-
curl -X PATCH -H "Authorization: Bearer $CLAWCARD_API_KEY" -H "Content-Type: application/json" \\
|
|
98
|
-
-d '{"action":"close"}' \\
|
|
99
|
-
$CLAWCARD_BASE_URL/api/agents/KEY_ID/cards/CARD_ID
|
|
100
|
-
|
|
101
|
-
### Credentials Vault
|
|
102
|
-
|
|
103
|
-
**Store a credential:**
|
|
104
|
-
|
|
105
|
-
curl -X POST -H "Authorization: Bearer $CLAWCARD_API_KEY" -H "Content-Type: application/json" \\
|
|
106
|
-
-d '{"service":"aws","key":"access_key","value":"AKIA..."}' \\
|
|
107
|
-
$CLAWCARD_BASE_URL/api/agents/KEY_ID/credentials
|
|
108
|
-
|
|
109
|
-
**Retrieve a credential:**
|
|
110
|
-
|
|
111
|
-
curl -H "Authorization: Bearer $CLAWCARD_API_KEY" $CLAWCARD_BASE_URL/api/agents/KEY_ID/credentials/SERVICE/KEY
|
|
112
|
-
|
|
113
|
-
### Budget
|
|
114
|
-
|
|
115
|
-
**Check remaining budget:**
|
|
116
|
-
|
|
117
|
-
curl -H "Authorization: Bearer $CLAWCARD_API_KEY" $CLAWCARD_BASE_URL/api/agents/KEY_ID/budget
|
|
118
|
-
|
|
119
|
-
**Allocate budget (moves funds from account balance to this key):**
|
|
120
|
-
|
|
121
|
-
curl -X POST -H "Authorization: Bearer $CLAWCARD_API_KEY" -H "Content-Type: application/json" \\
|
|
122
|
-
-d '{"amountCents":1000}' \\
|
|
123
|
-
$CLAWCARD_BASE_URL/api/agents/KEY_ID/budget
|
|
124
|
-
`;
|
|
125
|
-
|
|
126
|
-
// ── Helpers ──────────────────────────────────────────────────────
|
|
127
|
-
|
|
128
|
-
function log(msg) {
|
|
129
|
-
console.log(` ${msg}`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function success(msg) {
|
|
133
|
-
console.log(` \x1b[32m✓\x1b[0m ${msg}`);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function warn(msg) {
|
|
137
|
-
console.log(` \x1b[33m!\x1b[0m ${msg}`);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function error(msg) {
|
|
141
|
-
console.error(` \x1b[31m✗\x1b[0m ${msg}`);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// ── Main ─────────────────────────────────────────────────────────
|
|
145
|
-
|
|
146
|
-
const args = process.argv.slice(2);
|
|
147
|
-
const apiKey = args[0];
|
|
148
|
-
const baseUrl = args[1] || DEFAULT_BASE_URL;
|
|
149
|
-
|
|
150
|
-
console.log();
|
|
151
|
-
console.log(" \x1b[1m🦞 ClawCard Setup\x1b[0m");
|
|
152
|
-
console.log();
|
|
153
|
-
|
|
154
|
-
if (!apiKey || apiKey.startsWith("-")) {
|
|
155
|
-
log("Usage: npx clawcard <API_KEY> [BASE_URL]");
|
|
156
|
-
log("");
|
|
157
|
-
log("Example:");
|
|
158
|
-
log(" npx clawcard ak_live_abc123...");
|
|
159
|
-
log(" npx clawcard ak_live_abc123... http://localhost:3000");
|
|
160
|
-
console.log();
|
|
161
|
-
process.exit(1);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (!apiKey.startsWith("ak_live_")) {
|
|
165
|
-
warn("API key doesn't start with 'ak_live_' — are you sure this is correct?");
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Check OpenClaw is installed
|
|
169
|
-
if (!existsSync(OPENCLAW_DIR)) {
|
|
170
|
-
error("OpenClaw directory not found at ~/.openclaw");
|
|
171
|
-
log("Install OpenClaw first: https://openclaw.dev");
|
|
172
|
-
console.log();
|
|
173
|
-
process.exit(1);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// 1. Write skill file
|
|
177
|
-
mkdirSync(SKILLS_DIR, { recursive: true });
|
|
178
|
-
writeFileSync(SKILL_PATH, SKILL_MD);
|
|
179
|
-
success(`Skill written to ${SKILL_PATH}`);
|
|
180
|
-
|
|
181
|
-
// 2. Write env vars to ~/.openclaw/.env
|
|
182
|
-
const ENV_PATH = join(OPENCLAW_DIR, ".env");
|
|
183
|
-
let envContent = "";
|
|
184
|
-
try {
|
|
185
|
-
envContent = readFileSync(ENV_PATH, "utf-8");
|
|
186
|
-
} catch {
|
|
187
|
-
// .env doesn't exist yet, that's fine
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Update or append each var
|
|
191
|
-
const envVars = {
|
|
192
|
-
CLAWCARD_API_KEY: apiKey,
|
|
193
|
-
CLAWCARD_BASE_URL: baseUrl,
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
for (const [key, value] of Object.entries(envVars)) {
|
|
197
|
-
const regex = new RegExp(`^${key}=.*$`, "m");
|
|
198
|
-
if (regex.test(envContent)) {
|
|
199
|
-
envContent = envContent.replace(regex, `${key}=${value}`);
|
|
200
|
-
} else {
|
|
201
|
-
envContent = envContent.trimEnd() + `\n${key}=${value}\n`;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
writeFileSync(ENV_PATH, envContent);
|
|
206
|
-
success(`Credentials written to ${ENV_PATH}`);
|
|
207
|
-
|
|
208
|
-
// 3. Done
|
|
209
|
-
console.log();
|
|
210
|
-
log("\x1b[1mSetup complete!\x1b[0m Your agent now has access to:");
|
|
211
|
-
log(" 📧 Email inbox");
|
|
212
|
-
log(" 📱 Phone number & SMS");
|
|
213
|
-
log(" 💳 Virtual debit cards");
|
|
214
|
-
log(" 🔐 Encrypted credential vault");
|
|
215
|
-
console.log();
|
|
216
|
-
log("Tell your agent to \x1b[1m\"refresh skills\"\x1b[0m or restart the gateway.");
|
|
217
|
-
log("Then try: \x1b[36m\"Use ClawCard to check your identity\"\x1b[0m");
|
|
218
|
-
console.log();
|