xapi-to 0.1.13 → 0.1.15
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 +42 -40
- package/dist/index.js +1335 -0
- package/package.json +14 -9
- package/src/client.ts +0 -265
- package/src/codegen.ts +0 -307
- package/src/commands/action.ts +0 -328
- package/src/commands/balance.ts +0 -35
- package/src/commands/config.ts +0 -58
- package/src/commands/oauth.ts +0 -297
- package/src/commands/register.ts +0 -77
- package/src/commands/topup.ts +0 -33
- package/src/config.ts +0 -69
- package/src/format.ts +0 -61
- package/src/index.ts +0 -216
package/src/index.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
/**
|
|
3
|
-
* xapi CLI - agent-friendly command-line interface for xapi
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* xapi list [--source capability|api] [--page N] [--page-size N] [--category X]
|
|
7
|
-
* xapi search <query> [--source capability|api] [--category X] [--page N] [--page-size N]
|
|
8
|
-
* xapi categories [--source capability|api]
|
|
9
|
-
* xapi services [--page N] [--page-size N] [--category X]
|
|
10
|
-
* xapi get <id> [--code curl|py|js|ts|go]
|
|
11
|
-
* xapi call <id> --input '{"k":"v"}' [--code curl|py|js|ts|go]
|
|
12
|
-
*
|
|
13
|
-
* xapi config show
|
|
14
|
-
* xapi config set apiKey=<key>
|
|
15
|
-
* xapi config health
|
|
16
|
-
* xapi health
|
|
17
|
-
*
|
|
18
|
-
* Global flags:
|
|
19
|
-
* --format json|pretty|table output format (default: json)
|
|
20
|
-
* --help show help
|
|
21
|
-
*
|
|
22
|
-
* Env vars:
|
|
23
|
-
* XAPI_KEY API key
|
|
24
|
-
* XAPI_ACTION_HOST Action service host (default: action.xapi.to)
|
|
25
|
-
* XAPI_OUTPUT default output format (json|pretty|table)
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
import * as actionCmds from './commands/action.ts';
|
|
29
|
-
import * as cfgCmds from './commands/config.ts';
|
|
30
|
-
const { CONFIG_HELP } = cfgCmds;
|
|
31
|
-
import * as regCmds from './commands/register.ts';
|
|
32
|
-
import * as topupCmds from './commands/topup.ts';
|
|
33
|
-
import * as balanceCmds from './commands/balance.ts';
|
|
34
|
-
import * as oauthCmds from './commands/oauth.ts';
|
|
35
|
-
const { OAUTH_HELP } = oauthCmds;
|
|
36
|
-
|
|
37
|
-
// ── Argument parser ───────────────────────────────────────────────────────────
|
|
38
|
-
|
|
39
|
-
interface ParsedArgs {
|
|
40
|
-
positional: string[];
|
|
41
|
-
flags: Record<string, string>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function parseArgs(argv: string[]): ParsedArgs {
|
|
45
|
-
const positional: string[] = [];
|
|
46
|
-
const flags: Record<string, string> = {};
|
|
47
|
-
let i = 0;
|
|
48
|
-
while (i < argv.length) {
|
|
49
|
-
const arg = argv[i];
|
|
50
|
-
if (arg.startsWith('--')) {
|
|
51
|
-
const key = arg.slice(2);
|
|
52
|
-
const next = argv[i + 1];
|
|
53
|
-
if (next && !next.startsWith('--')) {
|
|
54
|
-
flags[key] = next;
|
|
55
|
-
i += 2;
|
|
56
|
-
} else {
|
|
57
|
-
flags[key] = 'true';
|
|
58
|
-
i++;
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
positional.push(arg);
|
|
62
|
-
i++;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return { positional, flags };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// ── Help ──────────────────────────────────────────────────────────────────────
|
|
69
|
-
|
|
70
|
-
const HELP = `xapi - agent-friendly CLI for xapi
|
|
71
|
-
|
|
72
|
-
USAGE
|
|
73
|
-
xapi <command> [args] [flags]
|
|
74
|
-
|
|
75
|
-
COMMANDS
|
|
76
|
-
list List all actions
|
|
77
|
-
--source capability|api Filter by source type
|
|
78
|
-
--page N --page-size N Pagination
|
|
79
|
-
--category <name> Filter by category
|
|
80
|
-
--service-id <id> Filter by service
|
|
81
|
-
search <query> Search actions by keyword
|
|
82
|
-
--source capability|api Filter by source type
|
|
83
|
-
--category <name> Filter by category
|
|
84
|
-
--page N --page-size N Pagination
|
|
85
|
-
categories List all action categories
|
|
86
|
-
--source capability|api Filter by source type
|
|
87
|
-
services List all services
|
|
88
|
-
--page N --page-size N Pagination
|
|
89
|
-
--category <name> Filter by category
|
|
90
|
-
get <id> [--method GET|POST|...] Get action schema (filter by HTTP method)
|
|
91
|
-
--code <target> Generate code snippet (curl, py, js, ts, go)
|
|
92
|
-
call <id> --input '{"key":"val"}' Execute an action
|
|
93
|
-
--method GET|POST|... Override HTTP method
|
|
94
|
-
--code <target> Generate code snippet instead of executing
|
|
95
|
-
Variants: python.requests, python.httpx, javascript.fetch, javascript.axios
|
|
96
|
-
|
|
97
|
-
oauth bind [--provider twitter] Bind Twitter OAuth to your API key
|
|
98
|
-
oauth status List current OAuth bindings
|
|
99
|
-
oauth unbind <binding-id> Remove an OAuth binding
|
|
100
|
-
oauth providers List available OAuth providers
|
|
101
|
-
|
|
102
|
-
register [referral-code] Create a new user account (apiKey saved automatically)
|
|
103
|
-
--referral-code <code> Register with an inviter's referral code (also: --referralCode, or as positional arg)
|
|
104
|
-
balance Show current account balance
|
|
105
|
-
topup [--amount <usd>] [--method stripe|x402] Generate payment URL
|
|
106
|
-
|
|
107
|
-
health Check backend connectivity
|
|
108
|
-
|
|
109
|
-
config show Show current config
|
|
110
|
-
config set apiKey=<key> Save API key to ~/.xapi/config.json
|
|
111
|
-
config health Check backend connectivity (alias: xapi health)
|
|
112
|
-
|
|
113
|
-
GLOBAL FLAGS
|
|
114
|
-
--format json|pretty|table Output format (default: json)
|
|
115
|
-
--help Show help (use with a command for details, e.g. xapi get --help)
|
|
116
|
-
|
|
117
|
-
ENV VARS
|
|
118
|
-
XAPI_KEY API key (header: XAPI-Key)
|
|
119
|
-
XAPI_ACTION_HOST Action service host (default: action.xapi.to)
|
|
120
|
-
XAPI_OUTPUT Default output format
|
|
121
|
-
|
|
122
|
-
EXAMPLES
|
|
123
|
-
xapi register
|
|
124
|
-
xapi register --referral-code xapito # register with an inviter's referral code
|
|
125
|
-
xapi register xapito # positional shorthand
|
|
126
|
-
xapi list --format table
|
|
127
|
-
xapi list --source capability
|
|
128
|
-
xapi search twitter --source api
|
|
129
|
-
xapi get twitter.tweet_detail
|
|
130
|
-
xapi get twitter.tweet_detail --code curl
|
|
131
|
-
xapi get twitter.tweet_detail --code py --format pretty
|
|
132
|
-
xapi call twitter.tweet_detail --input '{"tweet_id":"1234567890"}'
|
|
133
|
-
xapi call twitter.tweet_detail --input '{"tweet_id":"1234567890"}' --code python
|
|
134
|
-
xapi categories
|
|
135
|
-
xapi services --format table
|
|
136
|
-
xapi config set apiKey=xapi_abc123
|
|
137
|
-
xapi health
|
|
138
|
-
`;
|
|
139
|
-
|
|
140
|
-
// ── Router ────────────────────────────────────────────────────────────────────
|
|
141
|
-
|
|
142
|
-
async function main() {
|
|
143
|
-
const { positional, flags } = parseArgs(process.argv.slice(2));
|
|
144
|
-
|
|
145
|
-
if (positional.length === 0) {
|
|
146
|
-
console.log(HELP);
|
|
147
|
-
process.exit(0);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// inject format from flag into env so format.ts picks it up
|
|
151
|
-
if (flags.format) process.env.XAPI_OUTPUT = flags.format;
|
|
152
|
-
|
|
153
|
-
const [cmd, ...rest] = positional;
|
|
154
|
-
|
|
155
|
-
switch (cmd) {
|
|
156
|
-
// ── Action commands (top-level) ──
|
|
157
|
-
case 'list': return actionCmds.actionList(rest, flags);
|
|
158
|
-
case 'search': return actionCmds.actionSearch(rest, flags);
|
|
159
|
-
case 'categories': return actionCmds.actionCategories(rest, flags);
|
|
160
|
-
case 'services': return actionCmds.actionServices(rest, flags);
|
|
161
|
-
case 'get': return actionCmds.actionGet(rest, flags);
|
|
162
|
-
case 'call': return actionCmds.actionCall(rest, flags);
|
|
163
|
-
|
|
164
|
-
// ── OAuth commands ──
|
|
165
|
-
case 'oauth': {
|
|
166
|
-
if (flags.help || rest.length === 0) {
|
|
167
|
-
console.log(OAUTH_HELP);
|
|
168
|
-
process.exit(0);
|
|
169
|
-
}
|
|
170
|
-
const [subCmd, ...subRest] = rest;
|
|
171
|
-
switch (subCmd) {
|
|
172
|
-
case 'bind': return oauthCmds.oauthBind(subRest, flags);
|
|
173
|
-
case 'status': return oauthCmds.oauthStatus(subRest, flags);
|
|
174
|
-
case 'unbind': return oauthCmds.oauthUnbind(subRest, flags);
|
|
175
|
-
case 'providers': return oauthCmds.oauthProviders(subRest, flags);
|
|
176
|
-
default:
|
|
177
|
-
console.error(JSON.stringify({ error: `unknown oauth command: ${subCmd}`, hint: 'valid commands: bind, status, unbind, providers' }));
|
|
178
|
-
process.exit(1);
|
|
179
|
-
}
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// ── Account commands ──
|
|
184
|
-
case 'register': return regCmds.register(rest, flags);
|
|
185
|
-
case 'balance': return balanceCmds.balance(rest, flags);
|
|
186
|
-
case 'topup': return topupCmds.topup(rest, flags);
|
|
187
|
-
case 'health': return cfgCmds.configHealth(rest, flags);
|
|
188
|
-
|
|
189
|
-
// ── Config commands ──
|
|
190
|
-
case 'config': {
|
|
191
|
-
if (flags.help || rest.length === 0) {
|
|
192
|
-
console.log(CONFIG_HELP);
|
|
193
|
-
process.exit(0);
|
|
194
|
-
}
|
|
195
|
-
const [subCmd, ...subRest] = rest;
|
|
196
|
-
switch (subCmd) {
|
|
197
|
-
case 'show': return cfgCmds.configShow(subRest, flags);
|
|
198
|
-
case 'set': return cfgCmds.configSet(subRest, flags);
|
|
199
|
-
case 'health': return cfgCmds.configHealth(subRest, flags);
|
|
200
|
-
default:
|
|
201
|
-
console.error(JSON.stringify({ error: `unknown config command: ${subCmd}`, hint: 'valid commands: show, set, health' }));
|
|
202
|
-
process.exit(1);
|
|
203
|
-
}
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
default:
|
|
208
|
-
console.error(JSON.stringify({ error: `unknown command: ${cmd}`, hint: 'run xapi --help' }));
|
|
209
|
-
process.exit(1);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
main().catch(e => {
|
|
214
|
-
console.error(JSON.stringify({ error: 'fatal', message: e.message }));
|
|
215
|
-
process.exit(1);
|
|
216
|
-
});
|