@moonpay/cli 0.6.16 → 0.6.21
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/dist/chunk-KSNMIEQD.js +26 -0
- package/dist/chunk-WLQU5BOQ.js +3 -0
- package/dist/index.js +15 -405
- package/dist/mcp-O43HZ23W.js +2 -0
- package/dist/store-XV77WYWO.js +2 -0
- package/package.json +1 -1
- package/skills/moonpay-buy-crypto/SKILL.md +4 -3
- package/dist/chunk-2GHQM7DN.js +0 -7856
- package/dist/chunk-2GHQM7DN.js.map +0 -1
- package/dist/chunk-ZYYH3VNA.js +0 -511
- package/dist/chunk-ZYYH3VNA.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mcp-YNKRGTQW.js +0 -128
- package/dist/mcp-YNKRGTQW.js.map +0 -1
- package/dist/store-6OIOBMHW.js +0 -22
- package/dist/store-6OIOBMHW.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,410 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
consentCheck,
|
|
7
|
-
resolveBaseUrl,
|
|
8
|
-
schemas_default
|
|
9
|
-
} from "./chunk-2GHQM7DN.js";
|
|
10
|
-
import "./chunk-ZYYH3VNA.js";
|
|
2
|
+
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
3
|
+
import{a as C,b as v,c as j,d as _,e as k}from"./chunk-KSNMIEQD.js";import"./chunk-WLQU5BOQ.js";import{createRequire as V}from"module";import{Command as X}from"commander";var q=!process.env.NO_COLOR&&process.stdout.isTTY===!0;function w(e){return t=>q?`${e}${t}\x1B[0m`:t}var p={bold:w("\x1B[1m"),dim:w("\x1B[2m"),green:w("\x1B[32m"),yellow:w("\x1B[33m"),cyan:w("\x1B[36m"),red:w("\x1B[31m")};function N(e){if(e==null)return!0;let t=typeof e;return t==="string"||t==="number"||t==="boolean"}function $(e){return e==null?"-":String(e)}function S(e,t=0){let n=" ".repeat(t);return N(e)?`${n}${$(e)}`:Array.isArray(e)?e.length===0?`${n}${p.dim("(empty)")}`:e.every(N)?e.map(r=>`${n}- ${$(r)}`).join(`
|
|
4
|
+
`):e.map(r=>{if(typeof r!="object"||r===null)return`${n}- ${$(r)}`;let o=Object.entries(r),a=[],[c,f]=o[0];N(f)?a.push(`${n}- ${p.bold(c)}: ${$(f)}`):(a.push(`${n}- ${p.bold(c)}:`),a.push(S(f,t+2)));for(let[m,y]of o.slice(1))N(y)?a.push(`${n} ${p.bold(m)}: ${$(y)}`):(a.push(`${n} ${p.bold(m)}:`),a.push(S(y,t+2)));return a.join(`
|
|
5
|
+
`)}).join(`
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import {
|
|
7
|
+
`):typeof e=="object"&&e!==null?Object.entries(e).map(([o,a])=>N(a)?`${n}${p.bold(o)}: ${$(a)}`:`${n}${p.bold(o)}:
|
|
8
|
+
${S(a,t+1)}`).join(`
|
|
9
|
+
`):""}function Z(e){if(typeof e!="object"||e===null)return e;let t=e;return"data"in t?t.data:"items"in t&&Array.isArray(t.items)&&Object.keys(t).filter(r=>r!=="items").length===0?t.items:e}function J(e,t){return t==="json"?JSON.stringify(e,null,2):S(Z(e))}import{readFileSync as M,writeFileSync as z,mkdirSync as Y}from"fs";import{join as T}from"path";import{homedir as H}from"os";var F=T(H(),".config","moonpay"),K=T(F,"update-check.json"),B=1440*60*1e3,G=3e3;function W(){try{let e=M(K,"utf-8");return JSON.parse(e)}catch{return null}}function Q(e){try{Y(F,{recursive:!0}),z(K,JSON.stringify(e))}catch{}}function R(e,t){let n=e.split(".").map(Number),r=t.split(".").map(Number);for(let o=0;o<3;o++){if((n[o]??0)>(r[o]??0))return!0;if((n[o]??0)<(r[o]??0))return!1}return!1}function A(e,t){return["",p.yellow(`Update available: ${e} \u2192 ${t}`),p.dim("Run `npm i -g @moonpay/cli` to update."),""].join(`
|
|
10
|
+
`)}function P(e){let t=null,n=W();if(n&&Date.now()-n.checkedAt<B)return R(n.latest,e)&&(t=A(e,n.latest)),()=>t;let r=new AbortController,o=setTimeout(()=>r.abort(),G);return fetch("https://registry.npmjs.org/@moonpay%2fcli/latest",{signal:r.signal}).then(a=>a.json()).then(a=>{let c=a.version;c&&(Q({latest:c,checkedAt:Date.now()}),R(c,e)&&(t=A(e,c)))}).catch(()=>{}).finally(()=>clearTimeout(o)),()=>t}var ee=V(import.meta.url),{version:x}=ee("../package.json"),ne=P(x),h=new X;h.name("moonpay").description(`MoonPay CLI \u2014 the crypto onramp for AI agents
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function ansi(code) {
|
|
19
|
-
return (text) => useColor ? `${code}${text}\x1B[0m` : text;
|
|
20
|
-
}
|
|
21
|
-
var color = {
|
|
22
|
-
bold: ansi("\x1B[1m"),
|
|
23
|
-
dim: ansi("\x1B[2m"),
|
|
24
|
-
green: ansi("\x1B[32m"),
|
|
25
|
-
yellow: ansi("\x1B[33m"),
|
|
26
|
-
cyan: ansi("\x1B[36m"),
|
|
27
|
-
red: ansi("\x1B[31m")
|
|
28
|
-
};
|
|
29
|
-
function isScalar(val) {
|
|
30
|
-
if (val === null || val === void 0) return true;
|
|
31
|
-
const t = typeof val;
|
|
32
|
-
return t === "string" || t === "number" || t === "boolean";
|
|
33
|
-
}
|
|
34
|
-
function scalarString(val) {
|
|
35
|
-
if (val === null || val === void 0) return "-";
|
|
36
|
-
return String(val);
|
|
37
|
-
}
|
|
38
|
-
function renderYaml(data, indent = 0) {
|
|
39
|
-
const pad = " ".repeat(indent);
|
|
40
|
-
if (isScalar(data)) return `${pad}${scalarString(data)}`;
|
|
41
|
-
if (Array.isArray(data)) {
|
|
42
|
-
if (data.length === 0) return `${pad}${color.dim("(empty)")}`;
|
|
43
|
-
if (data.every(isScalar)) {
|
|
44
|
-
return data.map((v) => `${pad}- ${scalarString(v)}`).join("\n");
|
|
45
|
-
}
|
|
46
|
-
return data.map((item) => {
|
|
47
|
-
if (typeof item !== "object" || item === null) {
|
|
48
|
-
return `${pad}- ${scalarString(item)}`;
|
|
49
|
-
}
|
|
50
|
-
const entries = Object.entries(item);
|
|
51
|
-
const lines = [];
|
|
52
|
-
const [firstKey, firstVal] = entries[0];
|
|
53
|
-
if (isScalar(firstVal)) {
|
|
54
|
-
lines.push(`${pad}- ${color.bold(firstKey)}: ${scalarString(firstVal)}`);
|
|
55
|
-
} else {
|
|
56
|
-
lines.push(`${pad}- ${color.bold(firstKey)}:`);
|
|
57
|
-
lines.push(renderYaml(firstVal, indent + 2));
|
|
58
|
-
}
|
|
59
|
-
for (const [k, v] of entries.slice(1)) {
|
|
60
|
-
if (isScalar(v)) {
|
|
61
|
-
lines.push(`${pad} ${color.bold(k)}: ${scalarString(v)}`);
|
|
62
|
-
} else {
|
|
63
|
-
lines.push(`${pad} ${color.bold(k)}:`);
|
|
64
|
-
lines.push(renderYaml(v, indent + 2));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return lines.join("\n");
|
|
68
|
-
}).join("\n\n");
|
|
69
|
-
}
|
|
70
|
-
if (typeof data === "object" && data !== null) {
|
|
71
|
-
const entries = Object.entries(data);
|
|
72
|
-
return entries.map(([k, v]) => {
|
|
73
|
-
if (isScalar(v)) return `${pad}${color.bold(k)}: ${scalarString(v)}`;
|
|
74
|
-
return `${pad}${color.bold(k)}:
|
|
75
|
-
${renderYaml(v, indent + 1)}`;
|
|
76
|
-
}).join("\n");
|
|
77
|
-
}
|
|
78
|
-
return "";
|
|
79
|
-
}
|
|
80
|
-
function unwrap(result) {
|
|
81
|
-
if (typeof result !== "object" || result === null) return result;
|
|
82
|
-
const obj = result;
|
|
83
|
-
if ("data" in obj) return obj.data;
|
|
84
|
-
if ("items" in obj && Array.isArray(obj.items)) {
|
|
85
|
-
const otherKeys = Object.keys(obj).filter((k) => k !== "items");
|
|
86
|
-
if (otherKeys.length === 0) return obj.items;
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
function formatOutput(result, format) {
|
|
91
|
-
if (format === "json") return JSON.stringify(result, null, 2);
|
|
92
|
-
return renderYaml(unwrap(result));
|
|
93
|
-
}
|
|
12
|
+
Your agents need money. MoonPay gives them wallets, funds, and tools
|
|
13
|
+
to buy, swap, bridge, and transact \u2014 all from the command line.
|
|
94
14
|
|
|
95
|
-
|
|
96
|
-
import { readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
97
|
-
import { join } from "path";
|
|
98
|
-
import { homedir } from "os";
|
|
99
|
-
var CACHE_DIR = join(homedir(), ".config", "moonpay");
|
|
100
|
-
var CACHE_FILE = join(CACHE_DIR, "update-check.json");
|
|
101
|
-
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
102
|
-
var FETCH_TIMEOUT_MS = 3e3;
|
|
103
|
-
function readCache() {
|
|
104
|
-
try {
|
|
105
|
-
const raw = readFileSync(CACHE_FILE, "utf-8");
|
|
106
|
-
return JSON.parse(raw);
|
|
107
|
-
} catch {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function writeCache(data) {
|
|
112
|
-
try {
|
|
113
|
-
mkdirSync(CACHE_DIR, { recursive: true });
|
|
114
|
-
writeFileSync(CACHE_FILE, JSON.stringify(data));
|
|
115
|
-
} catch {
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function isNewer(latest, current) {
|
|
119
|
-
const a = latest.split(".").map(Number);
|
|
120
|
-
const b = current.split(".").map(Number);
|
|
121
|
-
for (let i = 0; i < 3; i++) {
|
|
122
|
-
if ((a[i] ?? 0) > (b[i] ?? 0)) return true;
|
|
123
|
-
if ((a[i] ?? 0) < (b[i] ?? 0)) return false;
|
|
124
|
-
}
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
function formatNotice(current, latest) {
|
|
128
|
-
return [
|
|
129
|
-
"",
|
|
130
|
-
color.yellow(`Update available: ${current} \u2192 ${latest}`),
|
|
131
|
-
color.dim("Run `npm i -g @moonpay/cli` to update."),
|
|
132
|
-
""
|
|
133
|
-
].join("\n");
|
|
134
|
-
}
|
|
135
|
-
function startVersionCheck(currentVersion) {
|
|
136
|
-
let notice = null;
|
|
137
|
-
const cache = readCache();
|
|
138
|
-
if (cache && Date.now() - cache.checkedAt < ONE_DAY_MS) {
|
|
139
|
-
if (isNewer(cache.latest, currentVersion)) {
|
|
140
|
-
notice = formatNotice(currentVersion, cache.latest);
|
|
141
|
-
}
|
|
142
|
-
return () => notice;
|
|
143
|
-
}
|
|
144
|
-
const controller = new AbortController();
|
|
145
|
-
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
146
|
-
fetch("https://registry.npmjs.org/@moonpay%2fcli/latest", {
|
|
147
|
-
signal: controller.signal
|
|
148
|
-
}).then((res) => res.json()).then((data) => {
|
|
149
|
-
const latest = data.version;
|
|
150
|
-
if (latest) {
|
|
151
|
-
writeCache({ latest, checkedAt: Date.now() });
|
|
152
|
-
if (isNewer(latest, currentVersion)) {
|
|
153
|
-
notice = formatNotice(currentVersion, latest);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}).catch(() => {
|
|
157
|
-
}).finally(() => clearTimeout(timeout));
|
|
158
|
-
return () => notice;
|
|
159
|
-
}
|
|
15
|
+
Run \`mp skill install\` to install AI skills for Claude Code.
|
|
160
16
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
var program = new Command();
|
|
166
|
-
program.name("moonpay").description(
|
|
167
|
-
"MoonPay CLI \u2014 the crypto onramp for AI agents\n\n Your agents need money. MoonPay gives them wallets, funds, and tools\n to buy, swap, bridge, and transact \u2014 all from the command line.\n\n Run `mp skill install` to install AI skills for Claude Code.\n\n Terms of Service: https://www.moonpay.com/legal/terms_of_use_usa\n Privacy Policy: https://www.moonpay.com/legal/privacy_policy\n Swaps by: https://swaps.xyz/terms"
|
|
168
|
-
).version(version).option("--json", "Output as JSON instead of YAML");
|
|
169
|
-
function getFormat() {
|
|
170
|
-
return program.opts().json ? "json" : "yaml";
|
|
171
|
-
}
|
|
172
|
-
function printResult(result) {
|
|
173
|
-
console.log(formatOutput(result, getFormat()));
|
|
174
|
-
}
|
|
175
|
-
function printUpdateNotice() {
|
|
176
|
-
const notice = getUpdateNotice();
|
|
177
|
-
if (notice) process.stderr.write(notice);
|
|
178
|
-
}
|
|
179
|
-
program.command("mcp").description("Start MCP server over stdio (for Claude Desktop, Claude Code, etc.)").action(async () => {
|
|
180
|
-
const { startMcpServer } = await import("./mcp-YNKRGTQW.js");
|
|
181
|
-
await startMcpServer();
|
|
182
|
-
});
|
|
183
|
-
function getOrCreateGroup(parent, segments) {
|
|
184
|
-
let current = parent;
|
|
185
|
-
for (const segment of segments) {
|
|
186
|
-
let existing = current.commands.find((c) => c.name() === segment);
|
|
187
|
-
if (!existing) {
|
|
188
|
-
existing = current.command(segment);
|
|
189
|
-
}
|
|
190
|
-
current = existing;
|
|
191
|
-
}
|
|
192
|
-
return current;
|
|
193
|
-
}
|
|
194
|
-
function flattenShape(shape, prefix = "") {
|
|
195
|
-
const fields = [];
|
|
196
|
-
for (const [key, field] of Object.entries(shape)) {
|
|
197
|
-
const flatKey = prefix ? `${prefix}-${key}` : key;
|
|
198
|
-
let inner = field;
|
|
199
|
-
while (inner._def.typeName === "ZodEffects") inner = inner._def.schema;
|
|
200
|
-
let unwrapped = inner;
|
|
201
|
-
if (unwrapped._def.typeName === "ZodNullable") unwrapped = unwrapped._def.innerType;
|
|
202
|
-
if (unwrapped._def.typeName === "ZodObject" && unwrapped.shape) {
|
|
203
|
-
fields.push(...flattenShape(unwrapped.shape, flatKey));
|
|
204
|
-
} else {
|
|
205
|
-
fields.push({ flatKey, field, path: flatKey.split("-") });
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return fields;
|
|
209
|
-
}
|
|
210
|
-
function unflattenParams(flat, fields) {
|
|
211
|
-
const result = {};
|
|
212
|
-
for (const { flatKey, path } of fields) {
|
|
213
|
-
const camelKey = flatKey.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
214
|
-
const value = camelKey in flat ? flat[camelKey] : flat[flatKey];
|
|
215
|
-
if (path.length === 1) {
|
|
216
|
-
result[path[0]] = value;
|
|
217
|
-
} else {
|
|
218
|
-
let obj = result;
|
|
219
|
-
for (let i = 0; i < path.length - 1; i++) {
|
|
220
|
-
if (!obj[path[i]] || typeof obj[path[i]] !== "object") {
|
|
221
|
-
obj[path[i]] = {};
|
|
222
|
-
}
|
|
223
|
-
obj = obj[path[i]];
|
|
224
|
-
}
|
|
225
|
-
obj[path[path.length - 1]] = value;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return result;
|
|
229
|
-
}
|
|
230
|
-
function registerLocalTools(parent, tools) {
|
|
231
|
-
for (const tool of tools) {
|
|
232
|
-
const segments = tool.schema.name.split("_");
|
|
233
|
-
const leafName = segments.pop();
|
|
234
|
-
const group = getOrCreateGroup(parent, segments);
|
|
235
|
-
const cmd = group.command(leafName).description(tool.schema.description);
|
|
236
|
-
const shape = tool.schema.input.shape ?? {};
|
|
237
|
-
const flatFields = flattenShape(shape);
|
|
238
|
-
const nullableKeys = [];
|
|
239
|
-
const numberKeys = [];
|
|
240
|
-
const jsonKeys = [];
|
|
241
|
-
for (const { flatKey, field } of flatFields) {
|
|
242
|
-
const desc = field.description ?? flatKey;
|
|
243
|
-
let inner = field;
|
|
244
|
-
while (inner._def.typeName === "ZodEffects") inner = inner._def.schema;
|
|
245
|
-
const typeName = inner._def.typeName;
|
|
246
|
-
let checkInner = inner;
|
|
247
|
-
if (checkInner._def.typeName === "ZodNullable") checkInner = checkInner._def.innerType;
|
|
248
|
-
if (checkInner._def.typeName === "ZodNumber") numberKeys.push(flatKey);
|
|
249
|
-
if (checkInner._def.typeName === "ZodRecord") jsonKeys.push(flatKey);
|
|
250
|
-
if (typeName === "ZodBoolean") {
|
|
251
|
-
cmd.option(`--${flatKey}`, desc, false);
|
|
252
|
-
} else if (typeName === "ZodNullable") {
|
|
253
|
-
cmd.option(`--${flatKey} <${flatKey}>`, desc);
|
|
254
|
-
nullableKeys.push(flatKey);
|
|
255
|
-
} else {
|
|
256
|
-
cmd.requiredOption(`--${flatKey} <${flatKey}>`, desc);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
cmd.action(async (options) => {
|
|
260
|
-
if (!tool.schema.name.startsWith("consent_")) {
|
|
261
|
-
await consentCheck.handler({});
|
|
262
|
-
}
|
|
263
|
-
for (const key of nullableKeys) {
|
|
264
|
-
const camelKey = key.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
265
|
-
if (options[camelKey] === void 0) options[camelKey] = null;
|
|
266
|
-
}
|
|
267
|
-
for (const key of numberKeys) {
|
|
268
|
-
const camelKey = key.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
269
|
-
if (options[camelKey] != null && typeof options[camelKey] === "string") {
|
|
270
|
-
options[camelKey] = Number(options[camelKey]);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
for (const key of jsonKeys) {
|
|
274
|
-
const camelKey = key.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
275
|
-
if (typeof options[camelKey] === "string") {
|
|
276
|
-
try {
|
|
277
|
-
options[camelKey] = JSON.parse(options[camelKey]);
|
|
278
|
-
} catch {
|
|
279
|
-
console.error(`Invalid JSON for --${key}`);
|
|
280
|
-
process.exit(1);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
const params = unflattenParams(options, flatFields);
|
|
285
|
-
try {
|
|
286
|
-
const result = await tool.handler(params);
|
|
287
|
-
printResult(result);
|
|
288
|
-
} catch (error) {
|
|
289
|
-
console.error(error.message);
|
|
290
|
-
process.exit(1);
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
function resolveJsonSchema(inputSchema) {
|
|
296
|
-
if (inputSchema.$ref && inputSchema.definitions) {
|
|
297
|
-
const defName = inputSchema.$ref.replace("#/definitions/", "");
|
|
298
|
-
return inputSchema.definitions[defName];
|
|
299
|
-
}
|
|
300
|
-
return inputSchema;
|
|
301
|
-
}
|
|
302
|
-
function isNullableProperty(prop) {
|
|
303
|
-
if (Array.isArray(prop.type)) return prop.type.includes("null");
|
|
304
|
-
if (prop.anyOf) return prop.anyOf.some((t) => t.type === "null");
|
|
305
|
-
return false;
|
|
306
|
-
}
|
|
307
|
-
function isObjectProperty(prop) {
|
|
308
|
-
if (Array.isArray(prop.type)) return prop.type.includes("object");
|
|
309
|
-
if (prop.anyOf) return prop.anyOf.some((t) => t.type === "object");
|
|
310
|
-
return prop.type === "object";
|
|
311
|
-
}
|
|
312
|
-
function isNumberProperty(prop) {
|
|
313
|
-
if (Array.isArray(prop.type)) return prop.type.some((t) => t === "number" || t === "integer");
|
|
314
|
-
if (prop.anyOf) return prop.anyOf.some((t) => t.type === "number" || t.type === "integer");
|
|
315
|
-
return prop.type === "number" || prop.type === "integer";
|
|
316
|
-
}
|
|
317
|
-
var HIDDEN_TOOLS = /* @__PURE__ */ new Set([
|
|
318
|
-
"swaps_transaction_build",
|
|
319
|
-
"token_transfer",
|
|
320
|
-
"transaction_register"
|
|
321
|
-
]);
|
|
322
|
-
function registerRemoteTools(parent, remoteSchemas) {
|
|
323
|
-
for (const schema of remoteSchemas) {
|
|
324
|
-
if (HIDDEN_TOOLS.has(schema.name)) continue;
|
|
325
|
-
const segments = schema.name.split("_");
|
|
326
|
-
const leafName = segments.pop();
|
|
327
|
-
const group = getOrCreateGroup(parent, segments);
|
|
328
|
-
if (group.commands.find((c) => c.name() === leafName)) continue;
|
|
329
|
-
const cmd = group.command(leafName).description(schema.description);
|
|
330
|
-
const resolved = resolveJsonSchema(schema.inputSchema);
|
|
331
|
-
const props = resolved.properties ?? {};
|
|
332
|
-
const requiredSet = new Set(resolved.required ?? []);
|
|
333
|
-
const nullableKeys = [];
|
|
334
|
-
const numberKeys = [];
|
|
335
|
-
const objectKeys = [];
|
|
336
|
-
for (const [key, prop] of Object.entries(props)) {
|
|
337
|
-
const desc = prop.description ?? key;
|
|
338
|
-
const nullable = isNullableProperty(prop);
|
|
339
|
-
const isObj = isObjectProperty(prop);
|
|
340
|
-
const isNum = isNumberProperty(prop);
|
|
341
|
-
if (isNum) numberKeys.push(key);
|
|
342
|
-
if (isObj) {
|
|
343
|
-
objectKeys.push(key);
|
|
344
|
-
if (requiredSet.has(key) && !nullable) {
|
|
345
|
-
cmd.requiredOption(`--${key} <json>`, `${desc} (as JSON)`);
|
|
346
|
-
} else {
|
|
347
|
-
cmd.option(`--${key} <json>`, `${desc} (as JSON)`);
|
|
348
|
-
nullableKeys.push(key);
|
|
349
|
-
}
|
|
350
|
-
} else if (nullable || !requiredSet.has(key)) {
|
|
351
|
-
cmd.option(`--${key} <${key}>`, desc);
|
|
352
|
-
nullableKeys.push(key);
|
|
353
|
-
} else {
|
|
354
|
-
cmd.requiredOption(`--${key} <${key}>`, desc);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
cmd.action(async (options) => {
|
|
358
|
-
await consentCheck.handler({});
|
|
359
|
-
for (const key of nullableKeys) {
|
|
360
|
-
if (options[key] === void 0) options[key] = null;
|
|
361
|
-
}
|
|
362
|
-
for (const key of numberKeys) {
|
|
363
|
-
if (options[key] != null && typeof options[key] === "string") {
|
|
364
|
-
options[key] = Number(options[key]);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
for (const key of objectKeys) {
|
|
368
|
-
if (typeof options[key] === "string") {
|
|
369
|
-
try {
|
|
370
|
-
options[key] = JSON.parse(options[key]);
|
|
371
|
-
} catch {
|
|
372
|
-
console.error(`Invalid JSON for --${key}`);
|
|
373
|
-
process.exit(1);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
try {
|
|
378
|
-
const baseUrl = resolveBaseUrl();
|
|
379
|
-
const result = await callTool(baseUrl, schema.name, options);
|
|
380
|
-
printResult(result);
|
|
381
|
-
printUpdateNotice();
|
|
382
|
-
} catch (error) {
|
|
383
|
-
console.error(error.message);
|
|
384
|
-
process.exit(1);
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
registerLocalTools(program, LOCAL_TOOLS);
|
|
390
|
-
registerRemoteTools(program, schemas_default);
|
|
391
|
-
program.command("tools").description("List available tools").action(() => {
|
|
392
|
-
const allTools = [
|
|
393
|
-
...LOCAL_TOOLS.map((t) => ({
|
|
394
|
-
name: t.schema.name,
|
|
395
|
-
description: t.schema.description
|
|
396
|
-
})),
|
|
397
|
-
...schemas_default.filter((s) => !LOCAL_TOOLS.some((l) => l.schema.name === s.name) && !HIDDEN_TOOLS.has(s.name)).map((s) => ({ name: s.name, description: s.description }))
|
|
398
|
-
].sort((a, b) => a.name.localeCompare(b.name));
|
|
399
|
-
const lines = [];
|
|
400
|
-
for (const tool of allTools) {
|
|
401
|
-
const cmdName = tool.name.replace(/_/g, " ");
|
|
402
|
-
lines.push(` ${color.green(cmdName.padEnd(28))} ${color.dim(tool.description)}`);
|
|
403
|
-
}
|
|
404
|
-
lines.push("");
|
|
405
|
-
lines.push(color.dim(`${allTools.length} tools`));
|
|
406
|
-
console.log(lines.join("\n"));
|
|
407
|
-
printUpdateNotice();
|
|
408
|
-
});
|
|
409
|
-
program.parse();
|
|
410
|
-
//# sourceMappingURL=index.js.map
|
|
17
|
+
Terms of Service: https://www.moonpay.com/legal/terms_of_use_usa
|
|
18
|
+
Privacy Policy: https://www.moonpay.com/legal/privacy_policy
|
|
19
|
+
Swaps by: https://swaps.xyz/terms`).version(x).option("--json","Output as JSON instead of YAML");function te(){return h.opts().json?"json":"yaml"}function E(e){console.log(J(e,te()))}function D(){let e=ne();e&&process.stderr.write(e)}h.command("mcp").description("Start MCP server over stdio (for Claude Desktop, Claude Code, etc.)").action(async()=>{let{startMcpServer:e}=await import("./mcp-O43HZ23W.js");await e()});function I(e,t){let n=e;for(let r of t){let o=n.commands.find(a=>a.name()===r);o||(o=n.command(r)),n=o}return n}function L(e,t=""){let n=[];for(let[r,o]of Object.entries(e)){let a=t?`${t}-${r}`:r,c=o;for(;c._def.typeName==="ZodEffects";)c=c._def.schema;let f=c;f._def.typeName==="ZodNullable"&&(f=f._def.innerType),f._def.typeName==="ZodObject"&&f.shape?n.push(...L(f.shape,a)):n.push({flatKey:a,field:o,path:a.split("-")})}return n}function re(e,t){let n={};for(let{flatKey:r,path:o}of t){let a=r.replace(/-([a-z])/g,(f,m)=>m.toUpperCase()),c=a in e?e[a]:e[r];if(o.length===1)n[o[0]]=c;else{let f=n;for(let m=0;m<o.length-1;m++)(!f[o[m]]||typeof f[o[m]]!="object")&&(f[o[m]]={}),f=f[o[m]];f[o[o.length-1]]=c}}return n}function oe(e,t){for(let n of t){let r=n.schema.name.split("_"),o=r.pop(),c=I(e,r).command(o).description(n.schema.description),f=n.schema.input.shape??{},m=L(f),y=[],b=[],O=[];for(let{flatKey:u,field:i}of m){let s=i.description??u,l=i;for(;l._def.typeName==="ZodEffects";)l=l._def.schema;let g=l._def.typeName,d=l;d._def.typeName==="ZodNullable"&&(d=d._def.innerType),d._def.typeName==="ZodNumber"&&b.push(u),d._def.typeName==="ZodRecord"&&O.push(u),g==="ZodBoolean"?c.option(`--${u}`,s,!1):g==="ZodNullable"?(c.option(`--${u} <${u}>`,s),y.push(u)):c.requiredOption(`--${u} <${u}>`,s)}c.action(async u=>{n.schema.name.startsWith("consent_")||await _.handler({});for(let s of y){let l=s.replace(/-([a-z])/g,(g,d)=>d.toUpperCase());u[l]===void 0&&(u[l]=null)}for(let s of b){let l=s.replace(/-([a-z])/g,(g,d)=>d.toUpperCase());u[l]!=null&&typeof u[l]=="string"&&(u[l]=Number(u[l]))}for(let s of O){let l=s.replace(/-([a-z])/g,(g,d)=>d.toUpperCase());if(typeof u[l]=="string")try{u[l]=JSON.parse(u[l])}catch{console.error(`Invalid JSON for --${s}`),process.exit(1)}}let i=re(u,m);try{let s=await n.handler(i);E(s)}catch(s){console.error(s.message),process.exit(1)}})}}function se(e){if(e.$ref&&e.definitions){let t=e.$ref.replace("#/definitions/","");return e.definitions[t]}return e}function ie(e){return Array.isArray(e.type)?e.type.includes("null"):e.anyOf?e.anyOf.some(t=>t.type==="null"):!1}function ae(e){return Array.isArray(e.type)?e.type.includes("object"):e.anyOf?e.anyOf.some(t=>t.type==="object"):e.type==="object"}function ce(e){return Array.isArray(e.type)?e.type.some(t=>t==="number"||t==="integer"):e.anyOf?e.anyOf.some(t=>t.type==="number"||t.type==="integer"):e.type==="number"||e.type==="integer"}var U=new Set(["swaps_transaction_build","token_transfer","transaction_register"]);function le(e,t){for(let n of t){if(U.has(n.name))continue;let r=n.name.split("_"),o=r.pop(),a=I(e,r);if(a.commands.find(i=>i.name()===o))continue;let c=a.command(o).description(n.description),f=se(n.inputSchema),m=f.properties??{},y=new Set(f.required??[]),b=[],O=[],u=[];for(let[i,s]of Object.entries(m)){let l=s.description??i,g=ie(s),d=ae(s);ce(s)&&O.push(i),d?(u.push(i),y.has(i)&&!g?c.requiredOption(`--${i} <json>`,`${l} (as JSON)`):(c.option(`--${i} <json>`,`${l} (as JSON)`),b.push(i))):g||!y.has(i)?(c.option(`--${i} <${i}>`,l),b.push(i)):c.requiredOption(`--${i} <${i}>`,l)}c.action(async i=>{await _.handler({});for(let s of b)i[s]===void 0&&(i[s]=null);for(let s of O)i[s]!=null&&typeof i[s]=="string"&&(i[s]=Number(i[s]));for(let s of u)if(typeof i[s]=="string")try{i[s]=JSON.parse(i[s])}catch{console.error(`Invalid JSON for --${s}`),process.exit(1)}try{let s=C(),l=await v(s,n.name,i);E(l),D()}catch(s){console.error(s.message),process.exit(1)}})}}oe(h,k);le(h,j);h.command("tools").description("List available tools").action(()=>{let e=[...k.map(n=>({name:n.schema.name,description:n.schema.description})),...j.filter(n=>!k.some(r=>r.schema.name===n.name)&&!U.has(n.name)).map(n=>({name:n.name,description:n.description}))].sort((n,r)=>n.name.localeCompare(r.name)),t=[];for(let n of e){let r=n.name.replace(/_/g," ");t.push(` ${p.green(r.padEnd(28))} ${p.dim(n.description)}`)}t.push(""),t.push(p.dim(`${e.length} tools`)),console.log(t.join(`
|
|
20
|
+
`)),D()});h.parse();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
2
|
+
import{a as u,b as f,c as d,e as l}from"./chunk-KSNMIEQD.js";import"./chunk-WLQU5BOQ.js";import{Server as R}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as x}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as T,ListToolsRequestSchema as v}from"@modelcontextprotocol/sdk/types.js";import{zodToJsonSchema as N}from"zod-to-json-schema";var y=new Map(l.map(s=>[s.schema.name,s]));function q(s){let n=s.inputSchema;if(n.$ref&&n.definitions){let p=n.$ref.replace("#/definitions/","");return n.definitions[p]??n}return n}async function C(){let s=new R({name:"moonpay",version:"1.0.0"},{capabilities:{tools:{listChanged:!0}}}),n=l.map(e=>({name:e.schema.name,description:e.schema.description,inputSchema:N(e.schema.input)})),p=new Map;for(let e of d){if(y.has(e.name))continue;let t=q(e);p.set(e.name,t.properties??{}),n.push({name:e.name,description:e.description,inputSchema:{type:"object",properties:t.properties??{},...t.required?{required:t.required}:{},...t.additionalProperties!==void 0?{additionalProperties:t.additionalProperties}:{}}})}let h=new Map(n.map(e=>[e.name,e]));s.setRequestHandler(v,async()=>({tools:n.map(e=>({name:e.name,description:e.description,inputSchema:e.inputSchema}))})),s.setRequestHandler(T,async e=>{let{name:t,arguments:o={}}=e.params;if(!h.has(t))return{content:[{type:"text",text:`Unknown tool: ${t}`}],isError:!0};try{let i=y.get(t);if(i){let c=i.schema.input.shape??{};for(let[m,a]of Object.entries(c))o[m]===void 0&&a._def.typeName==="ZodNullable"&&(o[m]=null);let r=await i.handler(o);return{content:[{type:"text",text:JSON.stringify(r,null,2)}]}}let S=p.get(t)??{};for(let[c,r]of Object.entries(S))o[c]===void 0&&(Array.isArray(r.type)?r.type.includes("null"):r.anyOf?.some(O=>O.type==="null"))&&(o[c]=null),(r.type==="number"||r.type==="integer"||Array.isArray(r.type)&&r.type.some(a=>a==="number"||a==="integer")||r.anyOf?.some(a=>a.type==="number"||a.type==="integer"))&&typeof o[c]=="string"&&(o[c]=Number(o[c]));let b=u(),w=await f(b,t,o);return{content:[{type:"text",text:JSON.stringify(w,null,2)}]}}catch(i){return{content:[{type:"text",text:i instanceof Error?i.message:String(i)}],isError:!0}}});let g=new x;await s.connect(g)}export{C as startMcpServer};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
2
|
+
import{l as a,m as b,n as c,o as d,p as e,q as f,r as g,s as h}from"./chunk-WLQU5BOQ.js";export{f as addWallet,d as findWallet,e as findWalletOrThrow,a as loadWallets,c as mutateWallets,g as removeWallet,h as resolveSigningKey,b as saveWallets};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@ Generate a MoonPay checkout URL for buying crypto with a credit card or bank tra
|
|
|
15
15
|
```bash
|
|
16
16
|
mp buy \
|
|
17
17
|
--token <currency-code> \
|
|
18
|
-
--amount <amount> \
|
|
18
|
+
--amount <usd-amount> \
|
|
19
19
|
--wallet <destination-address> \
|
|
20
20
|
--email <buyer-email>
|
|
21
21
|
```
|
|
@@ -26,14 +26,15 @@ mp buy \
|
|
|
26
26
|
|
|
27
27
|
## Example flow
|
|
28
28
|
|
|
29
|
-
1. User: "I want to buy
|
|
30
|
-
2. Run: `mp buy --token sol --amount
|
|
29
|
+
1. User: "I want to buy $50 of SOL with my credit card."
|
|
30
|
+
2. Run: `mp buy --token sol --amount 50 --wallet <address> --email user@example.com`
|
|
31
31
|
3. Open the returned checkout URL in the user's browser so they can complete the purchase.
|
|
32
32
|
|
|
33
33
|
## Notes
|
|
34
34
|
|
|
35
35
|
- This is fiat-to-crypto (credit card / bank), not a token swap.
|
|
36
36
|
- For token-to-token swaps, use the **moonpay-swap-tokens** skill instead.
|
|
37
|
+
- The `--amount` flag is in USD (e.g. `--amount 50` = $50 worth of the token).
|
|
37
38
|
- The `--token` flag uses MoonPay currency codes, not mint addresses.
|
|
38
39
|
- The checkout URL handles KYC and payment processing.
|
|
39
40
|
|