@clawcard/cli 0.1.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.
Files changed (2) hide show
  1. package/bin/setup.mjs +223 -0
  2. package/package.json +13 -0
package/bin/setup.mjs ADDED
@@ -0,0 +1,223 @@
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 CONFIG_PATH = join(OPENCLAW_DIR, "openclaw.json");
10
+ const SKILL_PATH = join(SKILLS_DIR, "SKILL.md");
11
+
12
+ const DEFAULT_BASE_URL = "https://clawcard.sh";
13
+
14
+ const SKILL_MD = `---
15
+ name: clawcard
16
+ description: Email, SMS, virtual cards, and credential vault for autonomous agents
17
+ metadata: {"openclaw":{"primaryEnv":"CLAWCARD_API_KEY","emoji":"\\ud83d\\udd11"}}
18
+ ---
19
+
20
+ You have access to ClawCard — a platform that gives you a real email address, phone number, virtual debit cards, and an encrypted credential vault.
21
+
22
+ **Authentication:** All requests use your API key as a Bearer token.
23
+
24
+ ## Getting Started
25
+
26
+ Base URL: $CLAWCARD_BASE_URL (default: https://clawcard.sh)
27
+ Auth header: Authorization: Bearer $CLAWCARD_API_KEY
28
+
29
+ **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.
30
+
31
+ curl -H "Authorization: Bearer $CLAWCARD_API_KEY" $CLAWCARD_BASE_URL/api/me
32
+
33
+ Response: { "keyId": "agt_...", "name": "...", "email": "...", "phone": "...", "spendLimitCents": ... }
34
+
35
+ ## Endpoints
36
+
37
+ Use the keyId from /api/me as KEY_ID in all endpoints below.
38
+
39
+ ### Identity
40
+
41
+ **Get full identity details:**
42
+
43
+ curl -H "Authorization: Bearer $CLAWCARD_API_KEY" $CLAWCARD_BASE_URL/api/agents/KEY_ID
44
+
45
+ ### Email
46
+
47
+ **Read inbox:**
48
+
49
+ curl -H "Authorization: Bearer $CLAWCARD_API_KEY" "$CLAWCARD_BASE_URL/api/agents/KEY_ID/emails?limit=20"
50
+
51
+ **Send email:**
52
+
53
+ curl -X POST -H "Authorization: Bearer $CLAWCARD_API_KEY" -H "Content-Type: application/json" \\
54
+ -d '{"to":"recipient@example.com","subject":"Hello","body":"Message text"}' \\
55
+ $CLAWCARD_BASE_URL/api/agents/KEY_ID/emails/send
56
+
57
+ ### SMS
58
+
59
+ **Read messages:**
60
+
61
+ curl -H "Authorization: Bearer $CLAWCARD_API_KEY" "$CLAWCARD_BASE_URL/api/agents/KEY_ID/sms?limit=20"
62
+
63
+ **Send SMS:**
64
+
65
+ curl -X POST -H "Authorization: Bearer $CLAWCARD_API_KEY" -H "Content-Type: application/json" \\
66
+ -d '{"to":"+15551234567","body":"Message text"}' \\
67
+ $CLAWCARD_BASE_URL/api/agents/KEY_ID/sms/send
68
+
69
+ ### Virtual Cards
70
+
71
+ **List cards:**
72
+
73
+ curl -H "Authorization: Bearer $CLAWCARD_API_KEY" $CLAWCARD_BASE_URL/api/agents/KEY_ID/cards
74
+
75
+ **Create a card (returns PAN, CVV, expiry):**
76
+
77
+ curl -X POST -H "Authorization: Bearer $CLAWCARD_API_KEY" -H "Content-Type: application/json" \\
78
+ -d '{"amountCents":1000,"memo":"Hosting payment","type":"single_use"}' \\
79
+ $CLAWCARD_BASE_URL/api/agents/KEY_ID/cards
80
+
81
+ Card types: single_use (closes after one txn), merchant_locked (locks to first merchant).
82
+
83
+ **Get card details (PAN, CVV):**
84
+
85
+ curl -H "Authorization: Bearer $CLAWCARD_API_KEY" $CLAWCARD_BASE_URL/api/agents/KEY_ID/cards/CARD_ID
86
+
87
+ **Close a card:**
88
+
89
+ curl -X PATCH -H "Authorization: Bearer $CLAWCARD_API_KEY" -H "Content-Type: application/json" \\
90
+ -d '{"action":"close"}' \\
91
+ $CLAWCARD_BASE_URL/api/agents/KEY_ID/cards/CARD_ID
92
+
93
+ ### Credentials Vault
94
+
95
+ **Store a credential:**
96
+
97
+ curl -X POST -H "Authorization: Bearer $CLAWCARD_API_KEY" -H "Content-Type: application/json" \\
98
+ -d '{"service":"aws","key":"access_key","value":"AKIA..."}' \\
99
+ $CLAWCARD_BASE_URL/api/agents/KEY_ID/credentials
100
+
101
+ **Retrieve a credential:**
102
+
103
+ curl -H "Authorization: Bearer $CLAWCARD_API_KEY" $CLAWCARD_BASE_URL/api/agents/KEY_ID/credentials/SERVICE/KEY
104
+
105
+ ### Budget
106
+
107
+ **Check remaining budget:**
108
+
109
+ curl -H "Authorization: Bearer $CLAWCARD_API_KEY" $CLAWCARD_BASE_URL/api/agents/KEY_ID/budget
110
+
111
+ **Allocate budget (moves funds from account balance to this key):**
112
+
113
+ curl -X POST -H "Authorization: Bearer $CLAWCARD_API_KEY" -H "Content-Type: application/json" \\
114
+ -d '{"amountCents":1000}' \\
115
+ $CLAWCARD_BASE_URL/api/agents/KEY_ID/budget
116
+ `;
117
+
118
+ // ── Helpers ──────────────────────────────────────────────────────
119
+
120
+ function log(msg) {
121
+ console.log(` ${msg}`);
122
+ }
123
+
124
+ function success(msg) {
125
+ console.log(` \x1b[32m✓\x1b[0m ${msg}`);
126
+ }
127
+
128
+ function warn(msg) {
129
+ console.log(` \x1b[33m!\x1b[0m ${msg}`);
130
+ }
131
+
132
+ function error(msg) {
133
+ console.error(` \x1b[31m✗\x1b[0m ${msg}`);
134
+ }
135
+
136
+ function readJson(path) {
137
+ try {
138
+ return JSON.parse(readFileSync(path, "utf-8"));
139
+ } catch {
140
+ return null;
141
+ }
142
+ }
143
+
144
+ function writeJson(path, data) {
145
+ writeFileSync(path, JSON.stringify(data, null, 2) + "\n");
146
+ }
147
+
148
+ // ── Main ─────────────────────────────────────────────────────────
149
+
150
+ const args = process.argv.slice(2);
151
+ const apiKey = args[0];
152
+ const baseUrl = args[1] || DEFAULT_BASE_URL;
153
+
154
+ console.log();
155
+ console.log(" \x1b[1m🦞 ClawCard Setup\x1b[0m");
156
+ console.log();
157
+
158
+ if (!apiKey || apiKey.startsWith("-")) {
159
+ log("Usage: npx clawcard <API_KEY> [BASE_URL]");
160
+ log("");
161
+ log("Example:");
162
+ log(" npx clawcard ak_live_abc123...");
163
+ log(" npx clawcard ak_live_abc123... http://localhost:3000");
164
+ console.log();
165
+ process.exit(1);
166
+ }
167
+
168
+ if (!apiKey.startsWith("ak_live_")) {
169
+ warn("API key doesn't start with 'ak_live_' — are you sure this is correct?");
170
+ }
171
+
172
+ // Check OpenClaw is installed
173
+ if (!existsSync(OPENCLAW_DIR)) {
174
+ error("OpenClaw directory not found at ~/.openclaw");
175
+ log("Install OpenClaw first: https://openclaw.dev");
176
+ console.log();
177
+ process.exit(1);
178
+ }
179
+
180
+ // 1. Write skill file
181
+ mkdirSync(SKILLS_DIR, { recursive: true });
182
+ writeFileSync(SKILL_PATH, SKILL_MD);
183
+ success(`Skill written to ${SKILL_PATH}`);
184
+
185
+ // 2. Update openclaw.json with env vars
186
+ const config = readJson(CONFIG_PATH);
187
+ if (!config) {
188
+ error(`Could not read ${CONFIG_PATH}`);
189
+ process.exit(1);
190
+ }
191
+
192
+ // Ensure skills.entries.clawcard.env exists
193
+ if (!config.skills) config.skills = {};
194
+ if (!config.skills.entries) config.skills.entries = {};
195
+
196
+ const existing = config.skills.entries.clawcard;
197
+ if (existing?.env?.CLAWCARD_API_KEY && existing.env.CLAWCARD_API_KEY !== "YOUR_API_KEY_HERE") {
198
+ warn("Existing ClawCard config found — updating API key");
199
+ }
200
+
201
+ config.skills.entries.clawcard = {
202
+ ...existing,
203
+ env: {
204
+ ...(existing?.env || {}),
205
+ CLAWCARD_API_KEY: apiKey,
206
+ CLAWCARD_BASE_URL: baseUrl,
207
+ },
208
+ };
209
+
210
+ writeJson(CONFIG_PATH, config);
211
+ success(`Config updated in ${CONFIG_PATH}`);
212
+
213
+ // 3. Done
214
+ console.log();
215
+ log("\x1b[1mSetup complete!\x1b[0m Your agent now has access to:");
216
+ log(" 📧 Email inbox");
217
+ log(" 📱 Phone number & SMS");
218
+ log(" 💳 Virtual debit cards");
219
+ log(" 🔐 Encrypted credential vault");
220
+ console.log();
221
+ log("Tell your agent to \x1b[1m\"refresh skills\"\x1b[0m or restart the gateway.");
222
+ log("Then try: \x1b[36m\"Use ClawCard to check your identity\"\x1b[0m");
223
+ console.log();
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@clawcard/cli",
3
+ "version": "0.1.0",
4
+ "description": "Set up ClawCard for your OpenClaw agent in one command",
5
+ "bin": {
6
+ "clawcard": "./bin/setup.mjs"
7
+ },
8
+ "type": "module",
9
+ "license": "MIT",
10
+ "files": [
11
+ "bin/"
12
+ ]
13
+ }