xapi-to 0.1.10 → 0.1.11
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 +3 -3
- package/package.json +1 -1
- package/src/codegen.ts +12 -12
- package/src/commands/balance.ts +3 -3
- package/src/config.ts +3 -3
- package/src/index.ts +7 -6
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ xapi register
|
|
|
25
25
|
xapi config set apiKey=sk-xxx
|
|
26
26
|
|
|
27
27
|
# 3. Or via env var
|
|
28
|
-
export
|
|
28
|
+
export XAPI_KEY=sk-xxx
|
|
29
29
|
|
|
30
30
|
# 4. Verify connectivity
|
|
31
31
|
xapi config health
|
|
@@ -76,7 +76,7 @@ xapi oauth providers # list available providers
|
|
|
76
76
|
|
|
77
77
|
```bash
|
|
78
78
|
xapi register # create account, saves apiKey automatically
|
|
79
|
-
xapi balance # show
|
|
79
|
+
xapi balance # show USD balance
|
|
80
80
|
xapi topup # generate payment URL
|
|
81
81
|
xapi topup --method stripe --amount 10 # stripe, $10
|
|
82
82
|
xapi topup --method x402 # x402 (USDC on Base)
|
|
@@ -119,7 +119,7 @@ xapi list --format table # human-readable table
|
|
|
119
119
|
|
|
120
120
|
| Variable | Description |
|
|
121
121
|
|---|---|
|
|
122
|
-
| `
|
|
122
|
+
| `XAPI_KEY` | API key (overrides config file) |
|
|
123
123
|
| `XAPI_ACTION_HOST` | Action service host (default: `action.xapi.to`) |
|
|
124
124
|
| `XAPI_OUTPUT` | Default output format (`json`\|`pretty`\|`table`) |
|
|
125
125
|
|
package/package.json
CHANGED
package/src/codegen.ts
CHANGED
|
@@ -129,10 +129,10 @@ function genCurl(params: CodegenParams): string {
|
|
|
129
129
|
const url = baseUrl(params.actionHost);
|
|
130
130
|
const body = jsonBody(params.actionId, params.input);
|
|
131
131
|
return [
|
|
132
|
-
'# Set
|
|
132
|
+
'# Set XAPI_KEY env var or replace with your key',
|
|
133
133
|
`curl -X POST '${shellEscape(url)}' \\`,
|
|
134
134
|
` -H 'Content-Type: application/json' \\`,
|
|
135
|
-
` -H "XAPI-Key: \${
|
|
135
|
+
` -H "XAPI-Key: \${XAPI_KEY}" \\`,
|
|
136
136
|
` -d '${shellEscape(body)}'`,
|
|
137
137
|
].join('\n');
|
|
138
138
|
}
|
|
@@ -142,7 +142,7 @@ function genPython(lib: 'requests' | 'httpx', params: CodegenParams): string {
|
|
|
142
142
|
const payload = { action_id: params.actionId, input: params.input };
|
|
143
143
|
return [
|
|
144
144
|
`# pip install ${lib}`,
|
|
145
|
-
'# Set
|
|
145
|
+
'# Set XAPI_KEY env var or replace with your key',
|
|
146
146
|
'import os',
|
|
147
147
|
`import ${lib}`,
|
|
148
148
|
'',
|
|
@@ -150,7 +150,7 @@ function genPython(lib: 'requests' | 'httpx', params: CodegenParams): string {
|
|
|
150
150
|
` "${url}",`,
|
|
151
151
|
` headers={`,
|
|
152
152
|
` "Content-Type": "application/json",`,
|
|
153
|
-
` "XAPI-Key": os.environ["
|
|
153
|
+
` "XAPI-Key": os.environ["XAPI_KEY"],`,
|
|
154
154
|
` },`,
|
|
155
155
|
` json=${indent(pythonDict(payload), 4)},`,
|
|
156
156
|
`)`,
|
|
@@ -162,12 +162,12 @@ function genJavaScriptFetch(params: CodegenParams): string {
|
|
|
162
162
|
const url = baseUrl(params.actionHost);
|
|
163
163
|
const body = jsonBody(params.actionId, params.input);
|
|
164
164
|
return [
|
|
165
|
-
'// Set
|
|
165
|
+
'// Set XAPI_KEY env var or replace with your key',
|
|
166
166
|
`const resp = await fetch("${url}", {`,
|
|
167
167
|
` method: "POST",`,
|
|
168
168
|
` headers: {`,
|
|
169
169
|
` "Content-Type": "application/json",`,
|
|
170
|
-
` "XAPI-Key": process.env.
|
|
170
|
+
` "XAPI-Key": process.env.XAPI_KEY,`,
|
|
171
171
|
` },`,
|
|
172
172
|
` body: JSON.stringify(${indent(body, 2)}),`,
|
|
173
173
|
`});`,
|
|
@@ -180,7 +180,7 @@ function genJavaScriptAxios(params: CodegenParams): string {
|
|
|
180
180
|
const body = jsonBody(params.actionId, params.input);
|
|
181
181
|
return [
|
|
182
182
|
'// npm install axios',
|
|
183
|
-
'// Set
|
|
183
|
+
'// Set XAPI_KEY env var or replace with your key',
|
|
184
184
|
'import axios from "axios";',
|
|
185
185
|
'',
|
|
186
186
|
`const resp = await axios.post(`,
|
|
@@ -189,7 +189,7 @@ function genJavaScriptAxios(params: CodegenParams): string {
|
|
|
189
189
|
` {`,
|
|
190
190
|
` headers: {`,
|
|
191
191
|
` "Content-Type": "application/json",`,
|
|
192
|
-
` "XAPI-Key": process.env.
|
|
192
|
+
` "XAPI-Key": process.env.XAPI_KEY,`,
|
|
193
193
|
` },`,
|
|
194
194
|
` },`,
|
|
195
195
|
`);`,
|
|
@@ -201,12 +201,12 @@ function genTypescriptFetch(params: CodegenParams): string {
|
|
|
201
201
|
const url = baseUrl(params.actionHost);
|
|
202
202
|
const body = jsonBody(params.actionId, params.input);
|
|
203
203
|
return [
|
|
204
|
-
'// Set
|
|
204
|
+
'// Set XAPI_KEY env var or replace with your key',
|
|
205
205
|
`const resp: Response = await fetch("${url}", {`,
|
|
206
206
|
` method: "POST",`,
|
|
207
207
|
` headers: {`,
|
|
208
208
|
` "Content-Type": "application/json",`,
|
|
209
|
-
` "XAPI-Key": process.env.
|
|
209
|
+
` "XAPI-Key": process.env.XAPI_KEY!,`,
|
|
210
210
|
` },`,
|
|
211
211
|
` body: JSON.stringify(${indent(body, 2)}),`,
|
|
212
212
|
`});`,
|
|
@@ -220,7 +220,7 @@ function genGo(params: CodegenParams): string {
|
|
|
220
220
|
const body = jsonBody(params.actionId, params.input);
|
|
221
221
|
const escaped = body.replace(/`/g, '` + "`" + `');
|
|
222
222
|
return [
|
|
223
|
-
'// Set
|
|
223
|
+
'// Set XAPI_KEY env var or replace with your key',
|
|
224
224
|
'package main',
|
|
225
225
|
'',
|
|
226
226
|
'import (',
|
|
@@ -238,7 +238,7 @@ function genGo(params: CodegenParams): string {
|
|
|
238
238
|
'\t\tpanic(err)',
|
|
239
239
|
'\t}',
|
|
240
240
|
'\treq.Header.Set("Content-Type", "application/json")',
|
|
241
|
-
'\treq.Header.Set("XAPI-Key", os.Getenv("
|
|
241
|
+
'\treq.Header.Set("XAPI-Key", os.Getenv("XAPI_KEY"))',
|
|
242
242
|
'',
|
|
243
243
|
'\tresp, err := http.DefaultClient.Do(req)',
|
|
244
244
|
'\tif err != nil {',
|
package/src/commands/balance.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* balance command
|
|
3
|
-
* Fetches
|
|
3
|
+
* Fetches balance from GET /auth/me
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { getConfig, requireApiKey, XAPI_API_HOST, scheme } from '../config.ts';
|
|
@@ -20,12 +20,12 @@ export async function balance(args: string[], flags: Record<string, string>) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
try {
|
|
23
|
-
const me = await request<{
|
|
23
|
+
const me = await request<{ balance: string; accountType: string; tier: string }>(
|
|
24
24
|
`${scheme(XAPI_API_HOST)}://${XAPI_API_HOST}/api/auth/me`,
|
|
25
25
|
{ method: 'GET', headers: { Authorization: `Bearer ${token!}` } },
|
|
26
26
|
);
|
|
27
27
|
output({
|
|
28
|
-
balance: me.
|
|
28
|
+
balance: me.balance,
|
|
29
29
|
accountType: me.accountType,
|
|
30
30
|
tier: me.tier,
|
|
31
31
|
}, flags.format as any);
|
package/src/config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Config management
|
|
3
3
|
* Only apiKey is user-configurable. Host is built-in.
|
|
4
|
-
* Reads from env var
|
|
4
|
+
* Reads from env var XAPI_KEY or ~/.xapi/config.json
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { existsSync, readFileSync, writeFileSync, mkdirSync, chmodSync } from 'fs';
|
|
@@ -38,7 +38,7 @@ export function getConfig(): XapiConfig {
|
|
|
38
38
|
const file = loadFileConfig();
|
|
39
39
|
return {
|
|
40
40
|
actionHost: XAPI_ACTION_HOST,
|
|
41
|
-
apiKey: process.env.XAPI_API_KEY || file.apiKey,
|
|
41
|
+
apiKey: process.env.XAPI_KEY || process.env.XAPI_API_KEY || file.apiKey,
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -62,7 +62,7 @@ export function showConfig(): void {
|
|
|
62
62
|
actionHost: cfg.actionHost,
|
|
63
63
|
apiKey: cfg.apiKey ? `${cfg.apiKey.slice(0, 8)}...` : undefined,
|
|
64
64
|
source: {
|
|
65
|
-
apiKey: process.env.XAPI_API_KEY ? 'env' : file.apiKey ? 'file' : 'none',
|
|
65
|
+
apiKey: (process.env.XAPI_KEY || process.env.XAPI_API_KEY) ? 'env' : file.apiKey ? 'file' : 'none',
|
|
66
66
|
},
|
|
67
67
|
configFile: CONFIG_FILE,
|
|
68
68
|
}, null, 2));
|
package/src/index.ts
CHANGED
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
*
|
|
13
13
|
* xapi config show
|
|
14
14
|
* xapi config set apiKey=<key>
|
|
15
|
-
* xapi
|
|
15
|
+
* xapi health
|
|
16
16
|
*
|
|
17
17
|
* Global flags:
|
|
18
18
|
* --format json|pretty|table output format (default: json)
|
|
19
19
|
* --help show help
|
|
20
20
|
*
|
|
21
21
|
* Env vars:
|
|
22
|
-
*
|
|
22
|
+
* XAPI_KEY API key
|
|
23
23
|
* XAPI_ACTION_HOST Action service host (default: action.xapi.to)
|
|
24
24
|
* XAPI_OUTPUT default output format (json|pretty|table)
|
|
25
25
|
*/
|
|
@@ -100,16 +100,17 @@ COMMANDS
|
|
|
100
100
|
balance Show current account balance
|
|
101
101
|
topup [--amount <usd>] [--method stripe|x402] Generate payment URL
|
|
102
102
|
|
|
103
|
+
health Check backend connectivity
|
|
104
|
+
|
|
103
105
|
config show Show current config
|
|
104
106
|
config set apiKey=<key> Save API key to ~/.xapi/config.json
|
|
105
|
-
config health Check backend connectivity
|
|
106
107
|
|
|
107
108
|
GLOBAL FLAGS
|
|
108
109
|
--format json|pretty|table Output format (default: json)
|
|
109
110
|
--help Show help (use with a command for details, e.g. xapi get --help)
|
|
110
111
|
|
|
111
112
|
ENV VARS
|
|
112
|
-
|
|
113
|
+
XAPI_KEY API key (header: XAPI-Key)
|
|
113
114
|
XAPI_ACTION_HOST Action service host (default: action.xapi.to)
|
|
114
115
|
XAPI_OUTPUT Default output format
|
|
115
116
|
|
|
@@ -126,7 +127,7 @@ EXAMPLES
|
|
|
126
127
|
xapi categories
|
|
127
128
|
xapi services --format table
|
|
128
129
|
xapi config set apiKey=xapi_abc123
|
|
129
|
-
xapi
|
|
130
|
+
xapi health
|
|
130
131
|
`;
|
|
131
132
|
|
|
132
133
|
// ── Router ────────────────────────────────────────────────────────────────────
|
|
@@ -176,6 +177,7 @@ async function main() {
|
|
|
176
177
|
case 'register': return regCmds.register(rest, flags);
|
|
177
178
|
case 'balance': return balanceCmds.balance(rest, flags);
|
|
178
179
|
case 'topup': return topupCmds.topup(rest, flags);
|
|
180
|
+
case 'health': return cfgCmds.configHealth(rest, flags);
|
|
179
181
|
|
|
180
182
|
// ── Config commands ──
|
|
181
183
|
case 'config': {
|
|
@@ -183,7 +185,6 @@ async function main() {
|
|
|
183
185
|
switch (subCmd) {
|
|
184
186
|
case 'show': return cfgCmds.configShow(subRest, flags);
|
|
185
187
|
case 'set': return cfgCmds.configSet(subRest, flags);
|
|
186
|
-
case 'health': return cfgCmds.configHealth(subRest, flags);
|
|
187
188
|
default:
|
|
188
189
|
console.error(JSON.stringify({ error: `unknown config command: ${subCmd}` }));
|
|
189
190
|
process.exit(1);
|