@myapihq/cli 1.0.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.
- package/dist/commands/account.d.ts +4 -0
- package/dist/commands/account.js +79 -0
- package/dist/commands/billing.d.ts +4 -0
- package/dist/commands/billing.js +34 -0
- package/dist/commands/domain.d.ts +5 -0
- package/dist/commands/domain.js +56 -0
- package/dist/commands/email.d.ts +8 -0
- package/dist/commands/email.js +95 -0
- package/dist/commands/funnel.d.ts +3 -0
- package/dist/commands/funnel.js +37 -0
- package/dist/commands/image.d.ts +2 -0
- package/dist/commands/image.js +47 -0
- package/dist/commands/org.d.ts +5 -0
- package/dist/commands/org.js +67 -0
- package/dist/commands/storage.d.ts +3 -0
- package/dist/commands/storage.js +27 -0
- package/dist/commands/webhook.d.ts +3 -0
- package/dist/commands/webhook.js +28 -0
- package/dist/commands/workflow.d.ts +5 -0
- package/dist/commands/workflow.js +57 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.js +69 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +105 -0
- package/dist/output.d.ts +5 -0
- package/dist/output.js +42 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +34 -0
- package/package.json +20 -0
- package/src/commands/account.ts +48 -0
- package/src/commands/billing.ts +31 -0
- package/src/commands/domain.ts +49 -0
- package/src/commands/email.ts +93 -0
- package/src/commands/funnel.ts +37 -0
- package/src/commands/image.ts +45 -0
- package/src/commands/org.ts +64 -0
- package/src/commands/storage.ts +23 -0
- package/src/commands/webhook.ts +25 -0
- package/src/commands/workflow.ts +54 -0
- package/src/config.ts +40 -0
- package/src/index.ts +68 -0
- package/src/output.ts +47 -0
- package/src/utils.ts +30 -0
- package/tsconfig.json +14 -0
package/dist/config.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
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.loadConfig = loadConfig;
|
|
37
|
+
exports.saveConfig = saveConfig;
|
|
38
|
+
exports.requireConfig = requireConfig;
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const os = __importStar(require("os"));
|
|
42
|
+
const CONFIG_DIR = path.join(os.homedir(), '.myapi');
|
|
43
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
44
|
+
function loadConfig() {
|
|
45
|
+
try {
|
|
46
|
+
if (!fs.existsSync(CONFIG_FILE)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const data = fs.readFileSync(CONFIG_FILE, 'utf-8');
|
|
50
|
+
return JSON.parse(data);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function saveConfig(config) {
|
|
57
|
+
if (!fs.existsSync(CONFIG_DIR)) {
|
|
58
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
59
|
+
}
|
|
60
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
61
|
+
}
|
|
62
|
+
function requireConfig() {
|
|
63
|
+
const config = loadConfig();
|
|
64
|
+
if (!config || !config.api_key) {
|
|
65
|
+
console.error("No API key found. Run: myapi account create");
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
return config;
|
|
69
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
const utils_js_1 = require("./utils.js");
|
|
38
|
+
const output_js_1 = require("./output.js");
|
|
39
|
+
const sdk_1 = require("@myapihq/sdk");
|
|
40
|
+
const accountCmd = __importStar(require("./commands/account.js"));
|
|
41
|
+
const billingCmd = __importStar(require("./commands/billing.js"));
|
|
42
|
+
async function main() {
|
|
43
|
+
const { args, flags } = (0, utils_js_1.parseArgs)(process.argv.slice(2));
|
|
44
|
+
if (args.length === 0) {
|
|
45
|
+
printHelp();
|
|
46
|
+
process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
const [command, subcommand, ...restArgs] = args;
|
|
49
|
+
try {
|
|
50
|
+
switch (command) {
|
|
51
|
+
case 'account':
|
|
52
|
+
if (subcommand === 'create')
|
|
53
|
+
await accountCmd.create();
|
|
54
|
+
else if (subcommand === 'token')
|
|
55
|
+
await accountCmd.token(flags);
|
|
56
|
+
else if (subcommand === 'keys')
|
|
57
|
+
await accountCmd.listKeys(flags);
|
|
58
|
+
else if (subcommand === 'revoke')
|
|
59
|
+
await accountCmd.revokeKey(restArgs[0], flags);
|
|
60
|
+
else
|
|
61
|
+
printHelp();
|
|
62
|
+
break;
|
|
63
|
+
case 'billing':
|
|
64
|
+
if (subcommand === 'balance')
|
|
65
|
+
await billingCmd.balance(flags);
|
|
66
|
+
else if (subcommand === 'history')
|
|
67
|
+
await billingCmd.history(flags);
|
|
68
|
+
else if (subcommand === 'topup')
|
|
69
|
+
await billingCmd.topup(restArgs[0], flags);
|
|
70
|
+
else if (subcommand === 'setup')
|
|
71
|
+
await billingCmd.setup(flags);
|
|
72
|
+
else
|
|
73
|
+
printHelp();
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
printHelp();
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (err instanceof sdk_1.MyApiError) {
|
|
82
|
+
if (err.status === 402) {
|
|
83
|
+
(0, output_js_1.error)("Insufficient balance. Run: myapi billing topup <amount>");
|
|
84
|
+
}
|
|
85
|
+
else if (err.status === 401) {
|
|
86
|
+
(0, output_js_1.error)("Invalid API key. Run: myapi account create");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
(0, output_js_1.error)(err.message || String(err));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function printHelp() {
|
|
93
|
+
(0, output_js_1.info)(`myapi - MyAPI command-line interface
|
|
94
|
+
|
|
95
|
+
Usage: myapi <command> [subcommand] [args]
|
|
96
|
+
|
|
97
|
+
Commands:
|
|
98
|
+
account Manage your account and API keys
|
|
99
|
+
billing Check balance and top up
|
|
100
|
+
|
|
101
|
+
Run "myapi <command>" for subcommand help.`);
|
|
102
|
+
}
|
|
103
|
+
main().catch(err => {
|
|
104
|
+
(0, output_js_1.error)(err.message || String(err));
|
|
105
|
+
});
|
package/dist/output.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function success(message: string): void;
|
|
2
|
+
export declare function error(message: string): never;
|
|
3
|
+
export declare function info(message: string): void;
|
|
4
|
+
export declare function printJson(data: unknown): void;
|
|
5
|
+
export declare function printTable(rows: Record<string, unknown>[]): void;
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.success = success;
|
|
4
|
+
exports.error = error;
|
|
5
|
+
exports.info = info;
|
|
6
|
+
exports.printJson = printJson;
|
|
7
|
+
exports.printTable = printTable;
|
|
8
|
+
function success(message) {
|
|
9
|
+
console.log(`\x1b[32m✓\x1b[0m ${message}`);
|
|
10
|
+
}
|
|
11
|
+
function error(message) {
|
|
12
|
+
console.error(`\x1b[31m✗\x1b[0m ${message}`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
function info(message) {
|
|
16
|
+
console.log(message);
|
|
17
|
+
}
|
|
18
|
+
function printJson(data) {
|
|
19
|
+
console.log(JSON.stringify(data, null, 2));
|
|
20
|
+
}
|
|
21
|
+
function printTable(rows) {
|
|
22
|
+
if (process.argv.includes('--json')) {
|
|
23
|
+
printJson(rows);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (rows.length === 0) {
|
|
27
|
+
console.log("No data found.");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const columns = Object.keys(rows[0]);
|
|
31
|
+
const colWidths = columns.map(col => {
|
|
32
|
+
return Math.max(col.length, ...rows.map(row => String(row[col] ?? '').length));
|
|
33
|
+
});
|
|
34
|
+
const printRow = (row) => {
|
|
35
|
+
console.log(row.map((cell, i) => cell.padEnd(colWidths[i] + 2)).join(''));
|
|
36
|
+
};
|
|
37
|
+
printRow(columns);
|
|
38
|
+
console.log(colWidths.map(w => '-'.repeat(w + 2)).join(''));
|
|
39
|
+
for (const row of rows) {
|
|
40
|
+
printRow(columns.map(col => String(row[col] ?? '')));
|
|
41
|
+
}
|
|
42
|
+
}
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseArgs = parseArgs;
|
|
4
|
+
exports.sleep = sleep;
|
|
5
|
+
function parseArgs(argv) {
|
|
6
|
+
const args = [];
|
|
7
|
+
const flags = {};
|
|
8
|
+
for (let i = 0; i < argv.length; i++) {
|
|
9
|
+
const arg = argv[i];
|
|
10
|
+
if (arg.startsWith('--')) {
|
|
11
|
+
if (arg.includes('=')) {
|
|
12
|
+
const [key, value] = arg.slice(2).split('=', 2);
|
|
13
|
+
flags[key] = value;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
const next = argv[i + 1];
|
|
17
|
+
if (next && !next.startsWith('--')) {
|
|
18
|
+
flags[arg.slice(2)] = next;
|
|
19
|
+
i++;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
flags[arg.slice(2)] = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
args.push(arg);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { args, flags };
|
|
31
|
+
}
|
|
32
|
+
function sleep(ms) {
|
|
33
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
34
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@myapihq/cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "MyAPI command-line interface",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"myapi": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"dev": "tsc --watch"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@myapihq/sdk": "*"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/node": "^25.6.0",
|
|
18
|
+
"typescript": "^5.4.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { hq } from '@myapihq/sdk';
|
|
2
|
+
import { saveConfig, requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable } from '../output.js';
|
|
4
|
+
import * as readline from 'readline';
|
|
5
|
+
|
|
6
|
+
export async function create() {
|
|
7
|
+
const agent = await hq.createAgentAccount();
|
|
8
|
+
const keyInfo = await hq.createApiKey(agent.token, 'default');
|
|
9
|
+
|
|
10
|
+
saveConfig({
|
|
11
|
+
api_key: keyInfo.api_key,
|
|
12
|
+
account_id: agent.account_id,
|
|
13
|
+
pin: agent.pin
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
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.`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function token(flags: Record<string, string | boolean>) {
|
|
20
|
+
let pin = flags.pin as string;
|
|
21
|
+
if (!pin) {
|
|
22
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
23
|
+
pin = await new Promise<string>(resolve => rl.question('Enter PIN: ', resolve));
|
|
24
|
+
rl.close();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const result = await hq.recoverAgentToken(pin);
|
|
28
|
+
const keyInfo = await hq.createApiKey(result.token, 'recovered');
|
|
29
|
+
|
|
30
|
+
const config = requireConfig();
|
|
31
|
+
config.api_key = keyInfo.api_key;
|
|
32
|
+
saveConfig(config);
|
|
33
|
+
|
|
34
|
+
success(`Token recovered! New API Key: ${keyInfo.api_key}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function listKeys(flags: Record<string, string | boolean>) {
|
|
38
|
+
const config = requireConfig();
|
|
39
|
+
const keys = await hq.listApiKeys(config.api_key);
|
|
40
|
+
printTable(keys as unknown as Record<string, unknown>[]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function revokeKey(id: string, flags: Record<string, string | boolean>) {
|
|
44
|
+
if (!id) error("Missing key id");
|
|
45
|
+
const config = requireConfig();
|
|
46
|
+
await hq.revokeApiKey(config.api_key, id);
|
|
47
|
+
success(`Key ${id} revoked`);
|
|
48
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { hq } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable, info } from '../output.js';
|
|
4
|
+
|
|
5
|
+
export async function balance(flags: Record<string, string | boolean>) {
|
|
6
|
+
const config = requireConfig();
|
|
7
|
+
const result = await hq.getBalance(config.api_key);
|
|
8
|
+
info(`Balance: $${(result.balance_cents / 100).toFixed(2)} | Payment method: ${result.has_payment_method ? 'yes' : 'no'}`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function history(flags: Record<string, string | boolean>) {
|
|
12
|
+
const config = requireConfig();
|
|
13
|
+
const items = await hq.getBillingHistory(config.api_key);
|
|
14
|
+
printTable(items as unknown as Record<string, unknown>[]);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function topup(amountStr: string, flags: Record<string, string | boolean>) {
|
|
18
|
+
if (!amountStr) error("Missing amount");
|
|
19
|
+
const amount = parseFloat(amountStr);
|
|
20
|
+
if (isNaN(amount)) error("Invalid amount");
|
|
21
|
+
|
|
22
|
+
const config = requireConfig();
|
|
23
|
+
const result = await hq.topUp(config.api_key, Math.round(amount * 100));
|
|
24
|
+
success(`Top up successful! New balance: $${(result.new_balance_cents / 100).toFixed(2)}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function setup(flags: Record<string, string | boolean>) {
|
|
28
|
+
const config = requireConfig();
|
|
29
|
+
const result = await hq.setupPayment(config.api_key);
|
|
30
|
+
success(`Open this URL in your browser to set up payment:\n${result.url}`);
|
|
31
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { domain as sdkDomain } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, info, printTable, printJson } from '../output.js';
|
|
4
|
+
|
|
5
|
+
export async function check(domain: string, flags: Record<string, string | boolean>) {
|
|
6
|
+
if (!domain) error("Missing domain");
|
|
7
|
+
const config = requireConfig();
|
|
8
|
+
const res = await sdkDomain.checkDomain(config.api_key, domain);
|
|
9
|
+
if (res.available) {
|
|
10
|
+
info(`${domain} — Available ✓ Price: $${(res.price_cents / 100).toFixed(2)}/yr`);
|
|
11
|
+
} else {
|
|
12
|
+
info(`Not available ✗`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function register(domain: string, flags: Record<string, string | boolean>) {
|
|
17
|
+
if (!domain) error("Missing domain");
|
|
18
|
+
const years = parseInt(flags.years as string) || 1;
|
|
19
|
+
const config = requireConfig();
|
|
20
|
+
const res = await sdkDomain.registerDomain(config.api_key, domain, years);
|
|
21
|
+
success(`Registered ${domain}!\n${JSON.stringify(res, null, 2)}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function importDomain(domain: string, flags: Record<string, string | boolean>) {
|
|
25
|
+
if (!domain) error("Missing domain");
|
|
26
|
+
if (!flags['namecheap-user'] || !flags['namecheap-key']) {
|
|
27
|
+
error("Missing --namecheap-user or --namecheap-key flags");
|
|
28
|
+
}
|
|
29
|
+
const config = requireConfig();
|
|
30
|
+
await sdkDomain.importDomain(config.api_key, {
|
|
31
|
+
domain,
|
|
32
|
+
namecheap_api_user: flags['namecheap-user'] as string,
|
|
33
|
+
namecheap_api_key: flags['namecheap-key'] as string
|
|
34
|
+
});
|
|
35
|
+
success(`Imported ${domain}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function list(flags: Record<string, string | boolean>) {
|
|
39
|
+
const config = requireConfig();
|
|
40
|
+
const domains = await sdkDomain.listDomains(config.api_key);
|
|
41
|
+
printTable(domains as unknown as Record<string, unknown>[]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function settings(domain: string, flags: Record<string, string | boolean>) {
|
|
45
|
+
if (!domain) error("Missing domain");
|
|
46
|
+
const config = requireConfig();
|
|
47
|
+
const res = await sdkDomain.getDomainSettings(config.api_key, domain);
|
|
48
|
+
printJson(res);
|
|
49
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { email as sdkEmail } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable, printJson } from '../output.js';
|
|
4
|
+
import { sleep } from '../utils.js';
|
|
5
|
+
|
|
6
|
+
export async function createMailbox(flags: Record<string, string | boolean>) {
|
|
7
|
+
if (!flags.domain || !flags.username) error("Missing --domain or --username flags");
|
|
8
|
+
const config = requireConfig();
|
|
9
|
+
const address = await sdkEmail.createMailbox(config.api_key, flags.domain as string, flags.username as string);
|
|
10
|
+
success(`Mailbox created: ${address.address}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function listMailboxes(flags: Record<string, string | boolean>) {
|
|
14
|
+
const config = requireConfig();
|
|
15
|
+
const mailboxes = await sdkEmail.listMailboxes(config.api_key);
|
|
16
|
+
printTable(mailboxes as unknown as Record<string, unknown>[]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function send(flags: Record<string, string | boolean>) {
|
|
20
|
+
if (!flags.from || !flags.to || !flags.subject || !flags.body) {
|
|
21
|
+
error("Missing --from, --to, --subject, or --body flags");
|
|
22
|
+
}
|
|
23
|
+
const config = requireConfig();
|
|
24
|
+
const res = await sdkEmail.sendEmail(config.api_key, {
|
|
25
|
+
from: flags.from as string,
|
|
26
|
+
to: [flags.to as string],
|
|
27
|
+
subject: flags.subject as string,
|
|
28
|
+
text: flags.body as string
|
|
29
|
+
});
|
|
30
|
+
success(`Email sent! Message ID: ${res.message_id}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function inbox(address: string, flags: Record<string, string | boolean>) {
|
|
34
|
+
if (!address) error("Missing address");
|
|
35
|
+
const config = requireConfig();
|
|
36
|
+
const messages = await sdkEmail.getInbox(config.api_key, address);
|
|
37
|
+
printTable(messages as unknown as Record<string, unknown>[]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function listTemplates(flags: Record<string, string | boolean>) {
|
|
41
|
+
const config = requireConfig();
|
|
42
|
+
const templates = await sdkEmail.listTemplates(config.api_key);
|
|
43
|
+
printTable(templates as unknown as Record<string, unknown>[]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function generateTemplate(flags: Record<string, string | boolean>) {
|
|
47
|
+
if (!flags['org-id'] || !flags.prompt || !flags.name) {
|
|
48
|
+
error("Missing --org-id, --prompt, or --name flags");
|
|
49
|
+
}
|
|
50
|
+
const config = requireConfig();
|
|
51
|
+
|
|
52
|
+
const job = await sdkEmail.generateTemplate(config.api_key, {
|
|
53
|
+
org_id: flags['org-id'] as string,
|
|
54
|
+
prompt: flags.prompt as string,
|
|
55
|
+
name: flags.name as string
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
process.stdout.write("Generating template ");
|
|
59
|
+
const chars = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
60
|
+
let i = 0;
|
|
61
|
+
let elapsed = 0;
|
|
62
|
+
|
|
63
|
+
while (elapsed < 90000) {
|
|
64
|
+
const status = await sdkEmail.getTemplateJobStatus(config.api_key, job.job_id);
|
|
65
|
+
if (status.status === 'completed') {
|
|
66
|
+
process.stdout.write('\r\x1b[K');
|
|
67
|
+
success(`Template generated! ID: ${status.template_id}\nPreview: ${status.result?.preview_url}`);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (status.status === 'failed') {
|
|
71
|
+
process.stdout.write('\r\x1b[K');
|
|
72
|
+
error("Template generation failed");
|
|
73
|
+
}
|
|
74
|
+
process.stdout.write(`\rGenerating template ${chars[i++ % chars.length]}`);
|
|
75
|
+
await sleep(3000);
|
|
76
|
+
elapsed += 3000;
|
|
77
|
+
}
|
|
78
|
+
process.stdout.write('\r\x1b[K');
|
|
79
|
+
error("Template generation timed out");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function listCampaigns(flags: Record<string, string | boolean>) {
|
|
83
|
+
const config = requireConfig();
|
|
84
|
+
const campaigns = await sdkEmail.listCampaigns(config.api_key);
|
|
85
|
+
printTable(campaigns as unknown as Record<string, unknown>[]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function campaignStats(id: string, flags: Record<string, string | boolean>) {
|
|
89
|
+
if (!id) error("Missing campaign id");
|
|
90
|
+
const config = requireConfig();
|
|
91
|
+
const stats = await sdkEmail.getCampaignStats(config.api_key, id);
|
|
92
|
+
printJson(stats);
|
|
93
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { funnel as sdkFunnel } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable } from '../output.js';
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
|
|
6
|
+
export async function list(flags: Record<string, string | boolean>) {
|
|
7
|
+
const config = requireConfig();
|
|
8
|
+
const funnels = await sdkFunnel.listFunnels(config.api_key);
|
|
9
|
+
printTable(funnels as unknown as Record<string, unknown>[]);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function create(flags: Record<string, string | boolean>) {
|
|
13
|
+
if (!flags['org-id'] || !flags.domain) {
|
|
14
|
+
error("Missing --org-id or --domain flags");
|
|
15
|
+
}
|
|
16
|
+
const config = requireConfig();
|
|
17
|
+
const funnel = await sdkFunnel.createFunnel(config.api_key, flags['org-id'] as string, flags.domain as string);
|
|
18
|
+
success(`Funnel created! ID: ${funnel.id}`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function push(id: string, slug: string, flags: Record<string, string | boolean>) {
|
|
22
|
+
if (!id || !slug) error("Missing id or slug");
|
|
23
|
+
const config = requireConfig();
|
|
24
|
+
|
|
25
|
+
const html = await new Promise<string>((resolve, reject) => {
|
|
26
|
+
let data = '';
|
|
27
|
+
process.stdin.setEncoding('utf-8');
|
|
28
|
+
process.stdin.on('data', chunk => { data += chunk; });
|
|
29
|
+
process.stdin.on('end', () => resolve(data));
|
|
30
|
+
process.stdin.on('error', reject);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (!html) error("No HTML provided via stdin");
|
|
34
|
+
|
|
35
|
+
await sdkFunnel.pushPage(config.api_key, id, slug, html);
|
|
36
|
+
success(`Pushed page to ${slug}`);
|
|
37
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { image as sdkImage } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable } from '../output.js';
|
|
4
|
+
import { sleep } from '../utils.js';
|
|
5
|
+
|
|
6
|
+
export async function generate(flags: Record<string, string | boolean>) {
|
|
7
|
+
if (!flags.prompt) error("Missing --prompt flag");
|
|
8
|
+
const config = requireConfig();
|
|
9
|
+
|
|
10
|
+
const payload: any = { prompt: flags.prompt as string };
|
|
11
|
+
if (flags.ratio) payload.aspect_ratio = flags.ratio as string;
|
|
12
|
+
if (flags.style) payload.style = flags.style as string;
|
|
13
|
+
if (flags.colors) payload.colors = flags.colors as string;
|
|
14
|
+
|
|
15
|
+
const res = await sdkImage.generateImage(config.api_key, payload);
|
|
16
|
+
|
|
17
|
+
process.stdout.write("Generating image ");
|
|
18
|
+
const chars = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
19
|
+
let i = 0;
|
|
20
|
+
let elapsed = 0;
|
|
21
|
+
|
|
22
|
+
while (elapsed < 60000) {
|
|
23
|
+
const job = await sdkImage.getImageJob(config.api_key, res.job_id);
|
|
24
|
+
if (job.status === 'completed') {
|
|
25
|
+
process.stdout.write('\r\x1b[K');
|
|
26
|
+
success(`Image generated!\nURL: ${job.url}`);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (job.status === 'failed') {
|
|
30
|
+
process.stdout.write('\r\x1b[K');
|
|
31
|
+
error(`Image generation failed: ${job.error || 'Unknown error'}`);
|
|
32
|
+
}
|
|
33
|
+
process.stdout.write(`\rGenerating image ${chars[i++ % chars.length]}`);
|
|
34
|
+
await sleep(3000);
|
|
35
|
+
elapsed += 3000;
|
|
36
|
+
}
|
|
37
|
+
process.stdout.write('\r\x1b[K');
|
|
38
|
+
error("Image generation timed out");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function list(flags: Record<string, string | boolean>) {
|
|
42
|
+
const config = requireConfig();
|
|
43
|
+
const images = await sdkImage.listImages(config.api_key);
|
|
44
|
+
printTable(images as unknown as Record<string, unknown>[]);
|
|
45
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { hq } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable, printJson } from '../output.js';
|
|
4
|
+
import { sleep } from '../utils.js';
|
|
5
|
+
|
|
6
|
+
export async function create(flags: Record<string, string | boolean>) {
|
|
7
|
+
if (!flags.name) error("Missing --name flag");
|
|
8
|
+
const config = requireConfig();
|
|
9
|
+
const payload: any = { name: flags.name as string };
|
|
10
|
+
if (flags.tagline) payload.tagline = flags.tagline as string;
|
|
11
|
+
if (flags.description) payload.description = flags.description as string;
|
|
12
|
+
|
|
13
|
+
const org = await hq.createOrg(config.api_key, payload);
|
|
14
|
+
success(`Org created! ID: ${org.id}, Name: ${org.name}`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function list(flags: Record<string, string | boolean>) {
|
|
18
|
+
const config = requireConfig();
|
|
19
|
+
const orgs = await hq.listOrgs(config.api_key);
|
|
20
|
+
printTable(orgs as unknown as Record<string, unknown>[]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function get(id: string, flags: Record<string, string | boolean>) {
|
|
24
|
+
if (!id) error("Missing org id");
|
|
25
|
+
const config = requireConfig();
|
|
26
|
+
const org = await hq.getOrg(config.api_key, id);
|
|
27
|
+
printJson(org);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function del(id: string, flags: Record<string, string | boolean>) {
|
|
31
|
+
if (!id) error("Missing org id");
|
|
32
|
+
const config = requireConfig();
|
|
33
|
+
await hq.deleteOrg(config.api_key, id);
|
|
34
|
+
success(`Org ${id} deleted`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function importOrg(domain: string, flags: Record<string, string | boolean>) {
|
|
38
|
+
if (!domain) error("Missing domain");
|
|
39
|
+
const config = requireConfig();
|
|
40
|
+
|
|
41
|
+
const result = await hq.importOrg(config.api_key, domain);
|
|
42
|
+
const importId = result.job_id;
|
|
43
|
+
|
|
44
|
+
process.stdout.write("Importing ");
|
|
45
|
+
const chars = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
46
|
+
let i = 0;
|
|
47
|
+
|
|
48
|
+
while (true) {
|
|
49
|
+
const status = await hq.getOrgImportStatus(config.api_key, importId);
|
|
50
|
+
if (status.status === 'awaiting_confirm') {
|
|
51
|
+
process.stdout.write('\r\x1b[K');
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
if (status.status === 'failed') {
|
|
55
|
+
process.stdout.write('\r\x1b[K');
|
|
56
|
+
error("Import failed");
|
|
57
|
+
}
|
|
58
|
+
process.stdout.write(`\rImporting ${chars[i++ % chars.length]}`);
|
|
59
|
+
await sleep(3000);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const org = await hq.confirmOrgImport(config.api_key, importId);
|
|
63
|
+
success(`Import complete! Org ID: ${org.id}`);
|
|
64
|
+
}
|