@myapihq/cli 1.0.5 → 1.0.7
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/commands/account.js +5 -16
- package/dist/commands/billing.js +28 -5
- package/dist/commands/keys.d.ts +3 -0
- package/dist/commands/keys.js +80 -0
- package/dist/commands/org.js +40 -8
- package/dist/commands/setup.js +10 -99
- package/dist/index.js +33 -13
- package/package.json +1 -1
- package/src/commands/billing.ts +30 -3
- package/src/commands/keys.ts +47 -0
- package/src/commands/org.ts +39 -5
- package/src/commands/setup.ts +10 -109
- package/src/index.ts +29 -11
- package/tsconfig.json +3 -6
- package/dist/cli/src/commands/account.d.ts +0 -4
- package/dist/cli/src/commands/account.js +0 -91
- package/dist/cli/src/commands/billing.d.ts +0 -4
- package/dist/cli/src/commands/billing.js +0 -34
- package/dist/cli/src/commands/domain.d.ts +0 -5
- package/dist/cli/src/commands/domain.js +0 -56
- package/dist/cli/src/commands/email.d.ts +0 -8
- package/dist/cli/src/commands/email.js +0 -95
- package/dist/cli/src/commands/funnel.d.ts +0 -3
- package/dist/cli/src/commands/funnel.js +0 -37
- package/dist/cli/src/commands/image.d.ts +0 -2
- package/dist/cli/src/commands/image.js +0 -47
- package/dist/cli/src/commands/org.d.ts +0 -5
- package/dist/cli/src/commands/org.js +0 -67
- package/dist/cli/src/commands/setup.d.ts +0 -1
- package/dist/cli/src/commands/setup.js +0 -165
- package/dist/cli/src/commands/storage.d.ts +0 -3
- package/dist/cli/src/commands/storage.js +0 -36
- package/dist/cli/src/commands/webhook.d.ts +0 -3
- package/dist/cli/src/commands/webhook.js +0 -28
- package/dist/cli/src/commands/workflow.d.ts +0 -5
- package/dist/cli/src/commands/workflow.js +0 -57
- package/dist/cli/src/config.d.ts +0 -8
- package/dist/cli/src/config.js +0 -69
- package/dist/cli/src/index.d.ts +0 -2
- package/dist/cli/src/index.js +0 -117
- package/dist/cli/src/output.d.ts +0 -5
- package/dist/cli/src/output.js +0 -42
- package/dist/cli/src/utils.d.ts +0 -5
- package/dist/cli/src/utils.js +0 -34
- package/dist/sdk/src/client.d.ts +0 -6
- package/dist/sdk/src/client.js +0 -51
- package/dist/sdk/src/domain.d.ts +0 -32
- package/dist/sdk/src/domain.js +0 -36
- package/dist/sdk/src/email.d.ts +0 -144
- package/dist/sdk/src/email.js +0 -116
- package/dist/sdk/src/funnel.d.ts +0 -31
- package/dist/sdk/src/funnel.js +0 -28
- package/dist/sdk/src/hq.d.ts +0 -84
- package/dist/sdk/src/hq.js +0 -80
- package/dist/sdk/src/image.d.ts +0 -21
- package/dist/sdk/src/image.js +0 -16
- package/dist/sdk/src/index.d.ts +0 -11
- package/dist/sdk/src/index.js +0 -51
- package/dist/sdk/src/pixel.d.ts +0 -65
- package/dist/sdk/src/pixel.js +0 -44
- package/dist/sdk/src/storage.d.ts +0 -10
- package/dist/sdk/src/storage.js +0 -48
- package/dist/sdk/src/types.d.ts +0 -17
- package/dist/sdk/src/types.js +0 -2
- package/dist/sdk/src/webhook.d.ts +0 -20
- package/dist/sdk/src/webhook.js +0 -20
- package/dist/sdk/src/workflow.d.ts +0 -56
- package/dist/sdk/src/workflow.js +0 -40
- package/src/commands/account.ts +0 -63
package/dist/commands/account.js
CHANGED
|
@@ -43,25 +43,14 @@ const output_js_1 = require("../output.js");
|
|
|
43
43
|
const readline = __importStar(require("readline"));
|
|
44
44
|
async function create() {
|
|
45
45
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
46
|
-
const
|
|
47
|
-
const choice = await ask('Do you want to (1) auto-create a new account or (2) paste an existing API key? [1/2]: ');
|
|
46
|
+
const key = await new Promise(resolve => rl.question('Paste your API key (get it from https://myapihq.com): ', resolve));
|
|
48
47
|
rl.close();
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
const key = await new Promise(resolve => rl2.question('Paste your API key: ', resolve));
|
|
52
|
-
rl2.close();
|
|
53
|
-
(0, config_js_1.saveConfig)({ api_key: key.trim(), account_id: '', pin: '' });
|
|
54
|
-
(0, output_js_1.success)(`API key saved to ~/.myapi/config.json`);
|
|
48
|
+
if (!key.trim()) {
|
|
49
|
+
(0, output_js_1.error)('API key cannot be empty.');
|
|
55
50
|
return;
|
|
56
51
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
(0, config_js_1.saveConfig)({
|
|
60
|
-
api_key: keyInfo.api_key,
|
|
61
|
-
account_id: agent.account_id,
|
|
62
|
-
pin: agent.pin
|
|
63
|
-
});
|
|
64
|
-
(0, output_js_1.success)(`Account created!\n\nAPI Key: ${keyInfo.api_key}\nAccount ID: ${agent.account_id}\nPIN: ${agent.pin}\n\nCredentials saved to ~/.myapi/config.json\nKeep your PIN safe — it's the only way to recover your account.`);
|
|
52
|
+
(0, config_js_1.saveConfig)({ api_key: key.trim(), account_id: '', pin: '' });
|
|
53
|
+
(0, output_js_1.success)(`API key saved to ~/.myapi/config.json`);
|
|
65
54
|
}
|
|
66
55
|
async function token(flags) {
|
|
67
56
|
let pin = flags.pin;
|
package/dist/commands/billing.js
CHANGED
|
@@ -8,26 +8,49 @@ const sdk_1 = require("@myapihq/sdk");
|
|
|
8
8
|
const config_js_1 = require("../config.js");
|
|
9
9
|
const output_js_1 = require("../output.js");
|
|
10
10
|
async function balance(flags) {
|
|
11
|
+
if (flags.help) {
|
|
12
|
+
(0, output_js_1.info)('Usage: myapi billing balance\n\nShows your current account balance, credits, and payment method status.');
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
11
15
|
const config = (0, config_js_1.requireConfig)();
|
|
12
16
|
const result = await sdk_1.hq.getBalance(config.api_key);
|
|
13
|
-
|
|
17
|
+
const bal = result.balance_display || `$${(result.balance_cents / 100).toFixed(2)}`;
|
|
18
|
+
const cred = result.credits_display || `$${((result.credits_cents || 0) / 100).toFixed(2)}`;
|
|
19
|
+
const pm = result.has_payment_method ? 'yes' : 'no';
|
|
20
|
+
(0, output_js_1.info)(`Balance: ${bal} | Credits: ${cred} | Payment method: ${pm}`);
|
|
14
21
|
}
|
|
15
22
|
async function history(flags) {
|
|
23
|
+
if (flags.help) {
|
|
24
|
+
(0, output_js_1.info)('Usage: myapi billing history\n\nShows your recent billing transactions and top-ups.');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
16
27
|
const config = (0, config_js_1.requireConfig)();
|
|
17
28
|
const items = await sdk_1.hq.getBillingHistory(config.api_key);
|
|
18
29
|
(0, output_js_1.printTable)(items);
|
|
19
30
|
}
|
|
20
31
|
async function topup(amountStr, flags) {
|
|
21
|
-
if (
|
|
22
|
-
(0, output_js_1.
|
|
32
|
+
if (flags.help) {
|
|
33
|
+
(0, output_js_1.info)('Usage: myapi billing topup <amount>\n\nAdds funds to your account balance using your saved payment method.\nExample: myapi billing topup 10.00');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!amountStr) {
|
|
37
|
+
(0, output_js_1.error)("Missing amount. Usage: myapi billing topup <amount>");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
23
40
|
const amount = parseFloat(amountStr);
|
|
24
|
-
if (isNaN(amount))
|
|
25
|
-
(0, output_js_1.error)("Invalid amount");
|
|
41
|
+
if (isNaN(amount)) {
|
|
42
|
+
(0, output_js_1.error)("Invalid amount. Must be a number (e.g., 10.00)");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
26
45
|
const config = (0, config_js_1.requireConfig)();
|
|
27
46
|
const result = await sdk_1.hq.topUp(config.api_key, Math.round(amount * 100));
|
|
28
47
|
(0, output_js_1.success)(`Top up successful! New balance: $${(result.new_balance_cents / 100).toFixed(2)}`);
|
|
29
48
|
}
|
|
30
49
|
async function setup(flags) {
|
|
50
|
+
if (flags.help) {
|
|
51
|
+
(0, output_js_1.info)('Usage: myapi billing setup\n\nGenerates a secure Stripe Checkout link to add or update your payment method.');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
31
54
|
const config = (0, config_js_1.requireConfig)();
|
|
32
55
|
const result = await sdk_1.hq.setupPayment(config.api_key);
|
|
33
56
|
(0, output_js_1.success)(`Open this URL in your browser to set up payment:\n${result.url}`);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function createNew(flags: Record<string, string | boolean>): Promise<void>;
|
|
2
|
+
export declare function list(flags: Record<string, string | boolean>): Promise<void>;
|
|
3
|
+
export declare function revoke(id: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createNew = createNew;
|
|
37
|
+
exports.list = list;
|
|
38
|
+
exports.revoke = revoke;
|
|
39
|
+
const sdk_1 = require("@myapihq/sdk");
|
|
40
|
+
const config_js_1 = require("../config.js");
|
|
41
|
+
const output_js_1 = require("../output.js");
|
|
42
|
+
const readline = __importStar(require("readline"));
|
|
43
|
+
async function createNew(flags) {
|
|
44
|
+
if (flags.help) {
|
|
45
|
+
(0, output_js_1.info)('Usage: myapi keys create\n\nCreates a new API key. You will be prompted to enter a name for the key.');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const config = (0, config_js_1.requireConfig)();
|
|
49
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
50
|
+
const name = await new Promise(resolve => rl.question('Enter a name for the new key: ', resolve));
|
|
51
|
+
rl.close();
|
|
52
|
+
if (!name.trim()) {
|
|
53
|
+
(0, output_js_1.error)('Key name cannot be empty.');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const keyInfo = await sdk_1.hq.createApiKey(config.api_key, name.trim());
|
|
57
|
+
(0, output_js_1.success)(`New API key created!\n\nName: ${keyInfo.prefix}...\nKey: ${keyInfo.api_key}\n\nMake sure to copy your new API key now. You won't be able to see it again!`);
|
|
58
|
+
}
|
|
59
|
+
async function list(flags) {
|
|
60
|
+
if (flags.help) {
|
|
61
|
+
(0, output_js_1.info)('Usage: myapi keys list\n\nLists all API keys associated with your account.');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const config = (0, config_js_1.requireConfig)();
|
|
65
|
+
const keysList = await sdk_1.hq.listApiKeys(config.api_key);
|
|
66
|
+
(0, output_js_1.printTable)(keysList);
|
|
67
|
+
}
|
|
68
|
+
async function revoke(id, flags) {
|
|
69
|
+
if (flags.help) {
|
|
70
|
+
(0, output_js_1.info)('Usage: myapi keys revoke <id>\n\nRevokes an API key permanently.');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!id) {
|
|
74
|
+
(0, output_js_1.error)("Missing key ID. Usage: myapi keys revoke <id>");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const config = (0, config_js_1.requireConfig)();
|
|
78
|
+
await sdk_1.hq.revokeApiKey(config.api_key, id);
|
|
79
|
+
(0, output_js_1.success)(`Key ${id} revoked successfully.`);
|
|
80
|
+
}
|
package/dist/commands/org.js
CHANGED
|
@@ -10,39 +10,71 @@ const config_js_1 = require("../config.js");
|
|
|
10
10
|
const output_js_1 = require("../output.js");
|
|
11
11
|
const utils_js_1 = require("../utils.js");
|
|
12
12
|
async function create(flags) {
|
|
13
|
-
if (
|
|
14
|
-
(0, output_js_1.
|
|
13
|
+
if (flags.help) {
|
|
14
|
+
(0, output_js_1.info)('Usage: myapi org create --name="My Org" [options]\n\nOptions:\n --name Organization name (required)\n --tagline Short tagline\n --description Detailed description\n --business-sector Sector (e.g. Technology)\n --logo-url URL to logo image');
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!flags.name) {
|
|
18
|
+
(0, output_js_1.error)("Missing --name flag. Run 'myapi org create --help' for details.");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
15
21
|
const config = (0, config_js_1.requireConfig)();
|
|
16
22
|
const payload = { name: flags.name };
|
|
17
23
|
if (flags.tagline)
|
|
18
24
|
payload.tagline = flags.tagline;
|
|
19
25
|
if (flags.description)
|
|
20
26
|
payload.description = flags.description;
|
|
27
|
+
if (flags['business-sector'])
|
|
28
|
+
payload.business_sector = flags['business-sector'];
|
|
29
|
+
if (flags['logo-url'])
|
|
30
|
+
payload.logo_url = flags['logo-url'];
|
|
21
31
|
const org = await sdk_1.hq.createOrg(config.api_key, payload);
|
|
22
32
|
(0, output_js_1.success)(`Org created! ID: ${org.id}, Name: ${org.name}`);
|
|
23
33
|
}
|
|
24
34
|
async function list(flags) {
|
|
35
|
+
if (flags.help) {
|
|
36
|
+
(0, output_js_1.info)('Usage: myapi org list\n\nLists all organizations in your account.');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
25
39
|
const config = (0, config_js_1.requireConfig)();
|
|
26
40
|
const orgs = await sdk_1.hq.listOrgs(config.api_key);
|
|
27
41
|
(0, output_js_1.printTable)(orgs);
|
|
28
42
|
}
|
|
29
43
|
async function get(id, flags) {
|
|
30
|
-
if (
|
|
31
|
-
(0, output_js_1.
|
|
44
|
+
if (flags.help) {
|
|
45
|
+
(0, output_js_1.info)('Usage: myapi org get <id>\n\nFetches details of a specific organization.');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (!id) {
|
|
49
|
+
(0, output_js_1.error)("Missing org id. Usage: myapi org get <id>");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
32
52
|
const config = (0, config_js_1.requireConfig)();
|
|
33
53
|
const org = await sdk_1.hq.getOrg(config.api_key, id);
|
|
34
54
|
(0, output_js_1.printJson)(org);
|
|
35
55
|
}
|
|
36
56
|
async function del(id, flags) {
|
|
37
|
-
if (
|
|
38
|
-
(0, output_js_1.
|
|
57
|
+
if (flags.help) {
|
|
58
|
+
(0, output_js_1.info)('Usage: myapi org delete <id>\n\nDeletes an organization.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!id) {
|
|
62
|
+
(0, output_js_1.error)("Missing org id. Usage: myapi org delete <id>");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
39
65
|
const config = (0, config_js_1.requireConfig)();
|
|
40
66
|
await sdk_1.hq.deleteOrg(config.api_key, id);
|
|
41
67
|
(0, output_js_1.success)(`Org ${id} deleted`);
|
|
42
68
|
}
|
|
43
69
|
async function importOrg(domain, flags) {
|
|
44
|
-
if (
|
|
45
|
-
(0, output_js_1.
|
|
70
|
+
if (flags.help) {
|
|
71
|
+
(0, output_js_1.info)('Usage: myapi org import <domain>\n\nAutomatically extracts brand info from an existing website and creates an organization.');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (!domain) {
|
|
75
|
+
(0, output_js_1.error)("Missing domain. Usage: myapi org import <domain>");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
46
78
|
const config = (0, config_js_1.requireConfig)();
|
|
47
79
|
const result = await sdk_1.hq.importOrg(config.api_key, domain);
|
|
48
80
|
const importId = result.job_id;
|
package/dist/commands/setup.js
CHANGED
|
@@ -34,14 +34,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.setup = setup;
|
|
37
|
-
const sdk_1 = require("@myapihq/sdk");
|
|
38
37
|
const config_js_1 = require("../config.js");
|
|
39
38
|
const output_js_1 = require("../output.js");
|
|
40
39
|
const readline = __importStar(require("readline"));
|
|
41
|
-
const child_process_1 = require("child_process");
|
|
42
|
-
const fs = __importStar(require("fs"));
|
|
43
|
-
const path = __importStar(require("path"));
|
|
44
|
-
const os = __importStar(require("os"));
|
|
45
40
|
function ask(rl, q) {
|
|
46
41
|
return new Promise(resolve => rl.question(q, resolve));
|
|
47
42
|
}
|
|
@@ -51,115 +46,31 @@ function yn(answer, defaultYes = true) {
|
|
|
51
46
|
return defaultYes;
|
|
52
47
|
return t === 'y' || t === 'yes';
|
|
53
48
|
}
|
|
54
|
-
async function
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
(0, output_js_1.success)('API key saved to ~/.myapi/config.json');
|
|
60
|
-
return key.trim();
|
|
61
|
-
}
|
|
62
|
-
(0, output_js_1.info)('Creating account...');
|
|
63
|
-
const agent = await sdk_1.hq.createAgentAccount();
|
|
64
|
-
const keyInfo = await sdk_1.hq.createApiKey(agent.token, 'default');
|
|
65
|
-
(0, config_js_1.saveConfig)({ api_key: keyInfo.api_key, account_id: agent.account_id, pin: agent.pin });
|
|
66
|
-
(0, output_js_1.success)(`Account created!\n\nAPI Key: ${keyInfo.api_key}\nPIN: ${agent.pin}\n\nSave your PIN — it's the only way to recover your account.`);
|
|
67
|
-
return keyInfo.api_key;
|
|
68
|
-
}
|
|
69
|
-
function registerClaudeMcp() {
|
|
70
|
-
try {
|
|
71
|
-
(0, child_process_1.execSync)('claude mcp add myapi -- npx -y @myapihq/mcp', { stdio: 'inherit' });
|
|
72
|
-
(0, output_js_1.success)('Claude Code MCP registered');
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
(0, output_js_1.info)('Could not auto-register. Run manually:\n claude mcp add myapi -- npx -y @myapihq/mcp');
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function registerGeminiMcp() {
|
|
79
|
-
const configPath = path.join(os.homedir(), '.gemini', 'settings.json');
|
|
80
|
-
try {
|
|
81
|
-
let settings = {};
|
|
82
|
-
if (fs.existsSync(configPath)) {
|
|
83
|
-
settings = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
84
|
-
}
|
|
85
|
-
settings.mcpServers = settings.mcpServers ?? {};
|
|
86
|
-
settings.mcpServers.myapi = { command: 'npx', args: ['-y', '@myapihq/mcp'] };
|
|
87
|
-
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
88
|
-
fs.writeFileSync(configPath, JSON.stringify(settings, null, 2));
|
|
89
|
-
(0, output_js_1.success)('Gemini CLI MCP registered (~/.gemini/settings.json)');
|
|
90
|
-
}
|
|
91
|
-
catch {
|
|
92
|
-
(0, output_js_1.info)('Could not auto-configure Gemini CLI. Add manually to ~/.gemini/settings.json:');
|
|
93
|
-
(0, output_js_1.info)(' { "mcpServers": { "myapi": { "command": "npx", "args": ["-y", "@myapihq/mcp"] } } }');
|
|
94
|
-
}
|
|
49
|
+
async function getKey(rl) {
|
|
50
|
+
const key = await ask(rl, 'Paste your API key (get it from https://myapihq.com): ');
|
|
51
|
+
(0, config_js_1.saveConfig)({ api_key: key.trim(), account_id: '', pin: '' });
|
|
52
|
+
(0, output_js_1.success)('API key saved to ~/.myapi/config.json');
|
|
53
|
+
return key.trim();
|
|
95
54
|
}
|
|
96
55
|
async function setup() {
|
|
97
56
|
(0, output_js_1.info)('MyAPI Setup\n');
|
|
98
57
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
99
|
-
// Step 1: credentials
|
|
100
58
|
const existing = (0, config_js_1.loadConfig)();
|
|
101
59
|
if (existing?.api_key) {
|
|
102
60
|
const reuse = await ask(rl, `Found existing account (${existing.account_id || existing.api_key.slice(0, 20) + '...'}). Use it? [Y/n]: `);
|
|
103
61
|
if (!yn(reuse, true)) {
|
|
104
|
-
await
|
|
62
|
+
await getKey(rl);
|
|
105
63
|
}
|
|
106
64
|
else {
|
|
107
65
|
(0, output_js_1.info)('Using existing credentials.');
|
|
108
66
|
}
|
|
109
67
|
}
|
|
110
68
|
else {
|
|
111
|
-
await
|
|
112
|
-
}
|
|
113
|
-
// Step 2: which agents
|
|
114
|
-
(0, output_js_1.info)('\nWhich AI agents do you use?');
|
|
115
|
-
const useClaude = yn(await ask(rl, ' Claude Code? [Y/n]: '), true);
|
|
116
|
-
const useGemini = yn(await ask(rl, ' Gemini CLI? [Y/n]: '), true);
|
|
117
|
-
const useCursor = yn(await ask(rl, ' Cursor? [y/N]: '), false);
|
|
118
|
-
const useWindsurf = yn(await ask(rl, ' Windsurf? [y/N]: '), false);
|
|
119
|
-
const useKiro = yn(await ask(rl, ' Kiro? [y/N]: '), false);
|
|
120
|
-
const useCopilot = yn(await ask(rl, ' GitHub Copilot? [y/N]: '), false);
|
|
121
|
-
const useOther = yn(await ask(rl, ' Other / Codex? [y/N]: '), false);
|
|
122
|
-
// Step 3: Claude — MCP or Skills or both
|
|
123
|
-
let claudeMcp = false;
|
|
124
|
-
let claudeSkills = false;
|
|
125
|
-
if (useClaude) {
|
|
126
|
-
(0, output_js_1.info)('\nFor Claude Code, how do you want to connect?');
|
|
127
|
-
claudeMcp = yn(await ask(rl, ' MCP server — live API calls via tool use? [Y/n]: '), true);
|
|
128
|
-
claudeSkills = yn(await ask(rl, ' Skills plugin — inline docs + prompts? [y/N]: '), false);
|
|
69
|
+
await getKey(rl);
|
|
129
70
|
}
|
|
130
71
|
rl.close();
|
|
131
|
-
|
|
132
|
-
(0, output_js_1.info)('
|
|
133
|
-
|
|
134
|
-
registerClaudeMcp();
|
|
135
|
-
if (useGemini)
|
|
136
|
-
registerGeminiMcp();
|
|
137
|
-
if (claudeSkills) {
|
|
138
|
-
(0, output_js_1.info)('To install the MyAPI skill inside Claude Code, run:');
|
|
139
|
-
(0, output_js_1.info)(' /plugin marketplace add myapihq/claude-skills');
|
|
140
|
-
(0, output_js_1.info)(' /plugin install my-api-hq@myapi-skills');
|
|
141
|
-
}
|
|
142
|
-
const skillsUrl = 'https://github.com/myapihq/agent-skills/blob/main/skills/my-api-hq/SKILL.md';
|
|
143
|
-
if (useCursor) {
|
|
144
|
-
(0, output_js_1.info)('\nCursor — copy the skill into .cursor/rules/:');
|
|
145
|
-
(0, output_js_1.info)(` ${skillsUrl}`);
|
|
146
|
-
}
|
|
147
|
-
if (useWindsurf) {
|
|
148
|
-
(0, output_js_1.info)('\nWindsurf — add the skill to your rules configuration:');
|
|
149
|
-
(0, output_js_1.info)(` ${skillsUrl}`);
|
|
150
|
-
}
|
|
151
|
-
if (useKiro) {
|
|
152
|
-
(0, output_js_1.info)('\nKiro — copy the skill into .kiro/skills/:');
|
|
153
|
-
(0, output_js_1.info)(` ${skillsUrl}`);
|
|
154
|
-
}
|
|
155
|
-
if (useCopilot) {
|
|
156
|
-
(0, output_js_1.info)('\nGitHub Copilot — paste the skill into .github/copilot-instructions.md:');
|
|
157
|
-
(0, output_js_1.info)(` ${skillsUrl}`);
|
|
158
|
-
}
|
|
159
|
-
if (useOther) {
|
|
160
|
-
(0, output_js_1.info)('\nOther agents — copy the skill markdown as a system prompt or instruction file:');
|
|
161
|
-
(0, output_js_1.info)(` ${skillsUrl}`);
|
|
162
|
-
}
|
|
163
|
-
(0, output_js_1.info)('');
|
|
72
|
+
(0, output_js_1.info)('\nTo integrate MyAPI with AI agents (Claude, Cursor, Copilot, etc.),');
|
|
73
|
+
(0, output_js_1.info)('please follow the instructions in our skills repository:');
|
|
74
|
+
(0, output_js_1.info)('https://github.com/myapihq/agent-skills\n');
|
|
164
75
|
(0, output_js_1.success)('Setup complete! Try: myapi billing balance');
|
|
165
76
|
}
|
package/dist/index.js
CHANGED
|
@@ -38,7 +38,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
38
38
|
const utils_js_1 = require("./utils.js");
|
|
39
39
|
const output_js_1 = require("./output.js");
|
|
40
40
|
const sdk_1 = require("@myapihq/sdk");
|
|
41
|
-
const
|
|
41
|
+
const keysCmd = __importStar(require("./commands/keys.js"));
|
|
42
42
|
const billingCmd = __importStar(require("./commands/billing.js"));
|
|
43
43
|
const orgCmd = __importStar(require("./commands/org.js"));
|
|
44
44
|
const setupCmd = __importStar(require("./commands/setup.js"));
|
|
@@ -52,29 +52,49 @@ async function main() {
|
|
|
52
52
|
try {
|
|
53
53
|
switch (command) {
|
|
54
54
|
case 'setup':
|
|
55
|
+
if (flags.help) {
|
|
56
|
+
(0, output_js_1.info)('Usage: myapi setup\n\nSetup CLI credentials and view integration instructions');
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
55
59
|
await setupCmd.setup();
|
|
56
60
|
break;
|
|
57
|
-
case '
|
|
61
|
+
case 'keys':
|
|
62
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
63
|
+
(0, output_js_1.info)('Usage: myapi keys <subcommand>\n\nSubcommands:\n list List your API keys\n create Create a new API key\n revoke Revoke an API key (e.g. myapi keys revoke <id>)');
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
58
66
|
if (subcommand === 'create')
|
|
59
|
-
await
|
|
60
|
-
else if (subcommand === '
|
|
61
|
-
await
|
|
62
|
-
else if (subcommand === 'keys')
|
|
63
|
-
await accountCmd.listKeys(flags);
|
|
67
|
+
await keysCmd.createNew(flags);
|
|
68
|
+
else if (subcommand === 'list')
|
|
69
|
+
await keysCmd.list(flags);
|
|
64
70
|
else if (subcommand === 'revoke')
|
|
65
|
-
await
|
|
71
|
+
await keysCmd.revoke(restArgs[0], flags);
|
|
66
72
|
else
|
|
67
73
|
printHelp();
|
|
68
74
|
break;
|
|
69
75
|
case 'org':
|
|
76
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
77
|
+
(0, output_js_1.info)('Usage: myapi org <subcommand>\n\nSubcommands:\n list List organizations\n create Create an organization\n get Get details of an organization\n delete Delete an organization\n import Extract org from domain');
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
70
80
|
if (subcommand === 'list')
|
|
71
81
|
await orgCmd.list(flags);
|
|
72
82
|
else if (subcommand === 'create')
|
|
73
83
|
await orgCmd.create(flags);
|
|
84
|
+
else if (subcommand === 'get')
|
|
85
|
+
await orgCmd.get(restArgs[0], flags);
|
|
86
|
+
else if (subcommand === 'delete')
|
|
87
|
+
await orgCmd.del(restArgs[0], flags);
|
|
88
|
+
else if (subcommand === 'import')
|
|
89
|
+
await orgCmd.importOrg(restArgs[0], flags);
|
|
74
90
|
else
|
|
75
91
|
printHelp();
|
|
76
92
|
break;
|
|
77
93
|
case 'billing':
|
|
94
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
95
|
+
(0, output_js_1.info)('Usage: myapi billing <subcommand>\n\nSubcommands:\n balance Check balance\n history View billing history\n topup Top up your balance\n setup Setup a payment method');
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
78
98
|
if (subcommand === 'balance')
|
|
79
99
|
await billingCmd.balance(flags);
|
|
80
100
|
else if (subcommand === 'history')
|
|
@@ -107,11 +127,11 @@ function printHelp() {
|
|
|
107
127
|
Usage: myapi <command> [subcommand] [args]
|
|
108
128
|
|
|
109
129
|
Commands:
|
|
110
|
-
|
|
111
|
-
billing
|
|
112
|
-
org
|
|
113
|
-
setup
|
|
130
|
+
keys Manage API keys
|
|
131
|
+
billing Check balance and manage billing
|
|
132
|
+
org Manage organizations
|
|
133
|
+
setup Setup CLI credentials and view integration instructions
|
|
114
134
|
|
|
115
|
-
Run "myapi <command>" for subcommand help.`);
|
|
135
|
+
Run "myapi <command> --help" for subcommand help.`);
|
|
116
136
|
}
|
|
117
137
|
main().catch(err => { (0, output_js_1.error)(err.message || String(err)); });
|
package/package.json
CHANGED
package/src/commands/billing.ts
CHANGED
|
@@ -3,21 +3,44 @@ import { requireConfig } from '../config.js';
|
|
|
3
3
|
import { success, error, printTable, info } from '../output.js';
|
|
4
4
|
|
|
5
5
|
export async function balance(flags: Record<string, string | boolean>) {
|
|
6
|
+
if (flags.help) {
|
|
7
|
+
info('Usage: myapi billing balance\n\nShows your current account balance, credits, and payment method status.');
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
6
10
|
const config = requireConfig();
|
|
7
11
|
const result = await hq.getBalance(config.api_key);
|
|
8
|
-
|
|
12
|
+
|
|
13
|
+
const bal = result.balance_display || `$${(result.balance_cents / 100).toFixed(2)}`;
|
|
14
|
+
const cred = result.credits_display || `$${((result.credits_cents || 0) / 100).toFixed(2)}`;
|
|
15
|
+
const pm = result.has_payment_method ? 'yes' : 'no';
|
|
16
|
+
|
|
17
|
+
info(`Balance: ${bal} | Credits: ${cred} | Payment method: ${pm}`);
|
|
9
18
|
}
|
|
10
19
|
|
|
11
20
|
export async function history(flags: Record<string, string | boolean>) {
|
|
21
|
+
if (flags.help) {
|
|
22
|
+
info('Usage: myapi billing history\n\nShows your recent billing transactions and top-ups.');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
12
25
|
const config = requireConfig();
|
|
13
26
|
const items = await hq.getBillingHistory(config.api_key);
|
|
14
27
|
printTable(items as unknown as Record<string, unknown>[]);
|
|
15
28
|
}
|
|
16
29
|
|
|
17
30
|
export async function topup(amountStr: string, flags: Record<string, string | boolean>) {
|
|
18
|
-
if (
|
|
31
|
+
if (flags.help) {
|
|
32
|
+
info('Usage: myapi billing topup <amount>\n\nAdds funds to your account balance using your saved payment method.\nExample: myapi billing topup 10.00');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!amountStr) {
|
|
36
|
+
error("Missing amount. Usage: myapi billing topup <amount>");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
19
39
|
const amount = parseFloat(amountStr);
|
|
20
|
-
if (isNaN(amount))
|
|
40
|
+
if (isNaN(amount)) {
|
|
41
|
+
error("Invalid amount. Must be a number (e.g., 10.00)");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
21
44
|
|
|
22
45
|
const config = requireConfig();
|
|
23
46
|
const result = await hq.topUp(config.api_key, Math.round(amount * 100));
|
|
@@ -25,6 +48,10 @@ export async function topup(amountStr: string, flags: Record<string, string | bo
|
|
|
25
48
|
}
|
|
26
49
|
|
|
27
50
|
export async function setup(flags: Record<string, string | boolean>) {
|
|
51
|
+
if (flags.help) {
|
|
52
|
+
info('Usage: myapi billing setup\n\nGenerates a secure Stripe Checkout link to add or update your payment method.');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
28
55
|
const config = requireConfig();
|
|
29
56
|
const result = await hq.setupPayment(config.api_key);
|
|
30
57
|
success(`Open this URL in your browser to set up payment:\n${result.url}`);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { hq } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable, info } from '../output.js';
|
|
4
|
+
import * as readline from 'readline';
|
|
5
|
+
|
|
6
|
+
export async function createNew(flags: Record<string, string | boolean>) {
|
|
7
|
+
if (flags.help) {
|
|
8
|
+
info('Usage: myapi keys create\n\nCreates a new API key. You will be prompted to enter a name for the key.');
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const config = requireConfig();
|
|
12
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
13
|
+
const name = await new Promise<string>(resolve => rl.question('Enter a name for the new key: ', resolve));
|
|
14
|
+
rl.close();
|
|
15
|
+
|
|
16
|
+
if (!name.trim()) {
|
|
17
|
+
error('Key name cannot be empty.');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const keyInfo = await hq.createApiKey(config.api_key, name.trim());
|
|
22
|
+
success(`New API key created!\n\nName: ${keyInfo.prefix}...\nKey: ${keyInfo.api_key}\n\nMake sure to copy your new API key now. You won't be able to see it again!`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function list(flags: Record<string, string | boolean>) {
|
|
26
|
+
if (flags.help) {
|
|
27
|
+
info('Usage: myapi keys list\n\nLists all API keys associated with your account.');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const config = requireConfig();
|
|
31
|
+
const keysList = await hq.listApiKeys(config.api_key);
|
|
32
|
+
printTable(keysList as unknown as Record<string, unknown>[]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function revoke(id: string, flags: Record<string, string | boolean>) {
|
|
36
|
+
if (flags.help) {
|
|
37
|
+
info('Usage: myapi keys revoke <id>\n\nRevokes an API key permanently.');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!id) {
|
|
41
|
+
error("Missing key ID. Usage: myapi keys revoke <id>");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const config = requireConfig();
|
|
45
|
+
await hq.revokeApiKey(config.api_key, id);
|
|
46
|
+
success(`Key ${id} revoked successfully.`);
|
|
47
|
+
}
|