@myapihq/cli 1.0.16 → 1.0.17
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/billing.js +26 -32
- package/dist/commands/config.js +20 -26
- package/dist/commands/domain.js +56 -67
- package/dist/commands/email.js +75 -88
- package/dist/commands/funnel.js +43 -52
- package/dist/commands/image.js +17 -21
- package/dist/commands/keys.js +22 -60
- package/dist/commands/org.js +37 -44
- package/dist/commands/setup.js +13 -49
- package/dist/commands/storage.js +18 -23
- package/dist/commands/url.d.ts +2 -0
- package/dist/commands/url.js +29 -0
- package/dist/commands/webhook.d.ts +2 -0
- package/dist/commands/webhook.js +64 -24
- package/dist/commands/workflow.d.ts +1 -0
- package/dist/commands/workflow.js +81 -43
- package/dist/config.js +6 -44
- package/dist/index.js +41 -56
- package/dist/output.js +5 -12
- package/dist/utils.js +2 -6
- package/package.json +5 -2
- package/src/commands/url.ts +28 -0
- package/src/commands/webhook.ts +50 -9
- package/src/commands/workflow.ts +55 -18
- package/src/index.ts +23 -0
package/dist/commands/billing.js
CHANGED
|
@@ -1,33 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.topup = topup;
|
|
6
|
-
exports.setup = setup;
|
|
7
|
-
const sdk_1 = require("@myapihq/sdk");
|
|
8
|
-
const config_js_1 = require("../config.js");
|
|
9
|
-
const output_js_1 = require("../output.js");
|
|
10
|
-
async function balance(flags) {
|
|
1
|
+
import { hq } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable, info, printJson } from '../output.js';
|
|
4
|
+
export async function balance(flags) {
|
|
11
5
|
if (flags.help) {
|
|
12
|
-
|
|
6
|
+
info('Usage: myapi billing balance\n\nShows your current account balance, credits, and payment method status.');
|
|
13
7
|
return;
|
|
14
8
|
}
|
|
15
|
-
const config =
|
|
16
|
-
const result = await
|
|
9
|
+
const config = requireConfig();
|
|
10
|
+
const result = await hq.getBalance(config.api_key);
|
|
17
11
|
const bal = result.balance_display || `$${(result.balance_cents / 100).toFixed(2)}`;
|
|
18
12
|
const cred = result.credits_display || `$${((result.credits_cents || 0) / 100).toFixed(2)}`;
|
|
19
13
|
const pm = result.has_payment_method ? 'yes' : 'no';
|
|
20
|
-
|
|
14
|
+
info(`Balance: ${bal} | Credits: ${cred} | Payment method: ${pm}`);
|
|
21
15
|
}
|
|
22
|
-
async function history(flags) {
|
|
16
|
+
export async function history(flags) {
|
|
23
17
|
if (flags.help) {
|
|
24
|
-
|
|
18
|
+
info('Usage: myapi billing history [--json]\n\nShows your recent billing transactions and top-ups.');
|
|
25
19
|
return;
|
|
26
20
|
}
|
|
27
|
-
const config =
|
|
28
|
-
const items = await
|
|
21
|
+
const config = requireConfig();
|
|
22
|
+
const items = await hq.getBillingHistory(config.api_key);
|
|
29
23
|
if (flags.json) {
|
|
30
|
-
|
|
24
|
+
printJson(items);
|
|
31
25
|
return;
|
|
32
26
|
}
|
|
33
27
|
const formattedItems = items.map(item => {
|
|
@@ -46,32 +40,32 @@ async function history(flags) {
|
|
|
46
40
|
Date: dateStr
|
|
47
41
|
};
|
|
48
42
|
});
|
|
49
|
-
|
|
43
|
+
printTable(formattedItems);
|
|
50
44
|
}
|
|
51
|
-
async function topup(amountStr, flags) {
|
|
45
|
+
export async function topup(amountStr, flags) {
|
|
52
46
|
if (flags.help) {
|
|
53
|
-
|
|
47
|
+
info('Usage: myapi billing topup <amount_in_dollars>\n\nAdds funds to your account balance using your saved payment method.\nExample: myapi billing topup 10.00');
|
|
54
48
|
return;
|
|
55
49
|
}
|
|
56
50
|
if (!amountStr) {
|
|
57
|
-
|
|
51
|
+
error("Missing amount. Usage: myapi billing topup <amount_in_dollars>");
|
|
58
52
|
return;
|
|
59
53
|
}
|
|
60
54
|
const amount = parseFloat(amountStr);
|
|
61
55
|
if (isNaN(amount)) {
|
|
62
|
-
|
|
56
|
+
error("Invalid amount. Must be a number in dollars (e.g., 10.00)");
|
|
63
57
|
return;
|
|
64
58
|
}
|
|
65
|
-
const config =
|
|
66
|
-
const result = await
|
|
67
|
-
|
|
59
|
+
const config = requireConfig();
|
|
60
|
+
const result = await hq.topUp(config.api_key, Math.round(amount * 100));
|
|
61
|
+
success(`Top up successful! New balance: $${(result.new_balance_cents / 100).toFixed(2)}`);
|
|
68
62
|
}
|
|
69
|
-
async function setup(flags) {
|
|
63
|
+
export async function setup(flags) {
|
|
70
64
|
if (flags.help) {
|
|
71
|
-
|
|
65
|
+
info('Usage: myapi billing setup\n\nGenerates a secure checkout link to add or update your payment method.');
|
|
72
66
|
return;
|
|
73
67
|
}
|
|
74
|
-
const config =
|
|
75
|
-
const result = await
|
|
76
|
-
|
|
68
|
+
const config = requireConfig();
|
|
69
|
+
const result = await hq.setupPayment(config.api_key);
|
|
70
|
+
success(`Open this URL in your browser to set up payment:\n${result.url}`);
|
|
77
71
|
}
|
package/dist/commands/config.js
CHANGED
|
@@ -1,43 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.setDomain = setDomain;
|
|
5
|
-
exports.view = view;
|
|
6
|
-
exports.run = run;
|
|
7
|
-
const config_js_1 = require("../config.js");
|
|
8
|
-
const output_js_1 = require("../output.js");
|
|
9
|
-
async function setOrg(id, flags) {
|
|
1
|
+
import { requireConfig, saveConfig } from '../config.js';
|
|
2
|
+
import { success, error, info } from '../output.js';
|
|
3
|
+
export async function setOrg(id, flags) {
|
|
10
4
|
if (!id || flags.help) {
|
|
11
|
-
|
|
5
|
+
info("Usage: myapi config set-org <id>\n\nSets a default organization ID for subsequent commands.");
|
|
12
6
|
return;
|
|
13
7
|
}
|
|
14
|
-
const config =
|
|
8
|
+
const config = requireConfig();
|
|
15
9
|
config.default_org = id;
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
saveConfig(config);
|
|
11
|
+
success(`Default organization set to: ${id}`);
|
|
18
12
|
}
|
|
19
|
-
async function setDomain(domain, flags) {
|
|
13
|
+
export async function setDomain(domain, flags) {
|
|
20
14
|
if (!domain || flags.help) {
|
|
21
|
-
|
|
15
|
+
info("Usage: myapi config set-domain <domain>\n\nSets a default domain for subsequent commands.");
|
|
22
16
|
return;
|
|
23
17
|
}
|
|
24
|
-
const config =
|
|
18
|
+
const config = requireConfig();
|
|
25
19
|
config.default_domain = domain;
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
saveConfig(config);
|
|
21
|
+
success(`Default domain set to: ${domain}`);
|
|
28
22
|
}
|
|
29
|
-
async function view(flags) {
|
|
23
|
+
export async function view(flags) {
|
|
30
24
|
if (flags.help) {
|
|
31
|
-
|
|
25
|
+
info("Usage: myapi config view\n\nViews current config settings.");
|
|
32
26
|
return;
|
|
33
27
|
}
|
|
34
|
-
const config =
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
const config = requireConfig();
|
|
29
|
+
info(`Default Org: ${config.default_org || 'Not set'}`);
|
|
30
|
+
info(`Default Domain: ${config.default_domain || 'Not set'}`);
|
|
37
31
|
}
|
|
38
|
-
async function run(subcommand, args, flags) {
|
|
32
|
+
export async function run(subcommand, args, flags) {
|
|
39
33
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
40
|
-
|
|
34
|
+
info('Usage: myapi config <subcommand>\n\nSubcommands:\n view View current config\n set-org Set default organization\n set-domain Set default domain');
|
|
41
35
|
return;
|
|
42
36
|
}
|
|
43
37
|
if (subcommand === 'view')
|
|
@@ -47,5 +41,5 @@ async function run(subcommand, args, flags) {
|
|
|
47
41
|
else if (subcommand === 'set-domain')
|
|
48
42
|
await setDomain(args[0], flags);
|
|
49
43
|
else
|
|
50
|
-
|
|
44
|
+
error(`Unknown subcommand: ${subcommand}. Run "myapi config --help" for a list of valid subcommands.`);
|
|
51
45
|
}
|
package/dist/commands/domain.js
CHANGED
|
@@ -1,100 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.list = list;
|
|
7
|
-
exports.assign = assign;
|
|
8
|
-
exports.unassign = unassign;
|
|
9
|
-
exports.settings = settings;
|
|
10
|
-
exports.updateSettings = updateSettings;
|
|
11
|
-
exports.run = run;
|
|
12
|
-
const sdk_1 = require("@myapihq/sdk");
|
|
13
|
-
const config_js_1 = require("../config.js");
|
|
14
|
-
const output_js_1 = require("../output.js");
|
|
15
|
-
async function check(domainArg, flags) {
|
|
16
|
-
const config = (0, config_js_1.requireConfig)();
|
|
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
|
+
export async function check(domainArg, flags) {
|
|
5
|
+
const config = requireConfig();
|
|
17
6
|
const orgId = flags.org || config.default_org;
|
|
18
7
|
const domain = domainArg || config.default_domain;
|
|
19
8
|
if (!orgId || !domain)
|
|
20
|
-
|
|
21
|
-
const res = await
|
|
9
|
+
error("Missing required arguments.\nUsage: myapi domain check <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
|
|
10
|
+
const res = await sdkDomain.checkDomain(config.api_key, orgId, domain);
|
|
22
11
|
if (res.available) {
|
|
23
|
-
|
|
12
|
+
info(`${domain} — Available ✓ Price: $${(res.price_cents / 100).toFixed(2)}/yr`);
|
|
24
13
|
}
|
|
25
14
|
else {
|
|
26
|
-
|
|
15
|
+
info(`Not available ✗`);
|
|
27
16
|
}
|
|
28
17
|
}
|
|
29
|
-
async function register(domainArg, flags) {
|
|
30
|
-
const config =
|
|
18
|
+
export async function register(domainArg, flags) {
|
|
19
|
+
const config = requireConfig();
|
|
31
20
|
const orgId = flags.org || config.default_org;
|
|
32
21
|
const domain = domainArg || config.default_domain;
|
|
33
22
|
if (!orgId || !domain)
|
|
34
|
-
|
|
23
|
+
error("Missing required arguments.\nUsage: myapi domain register <domain> --org <id> [--years <num>]\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
|
|
35
24
|
const years = parseInt(flags.years) || 1;
|
|
36
|
-
const res = await
|
|
37
|
-
|
|
25
|
+
const res = await sdkDomain.registerDomain(config.api_key, orgId, domain, years);
|
|
26
|
+
success(`Registered ${domain}!\n${JSON.stringify(res, null, 2)}`);
|
|
38
27
|
}
|
|
39
|
-
async function importDomain(domainArg, flags) {
|
|
40
|
-
const config =
|
|
28
|
+
export async function importDomain(domainArg, flags) {
|
|
29
|
+
const config = requireConfig();
|
|
41
30
|
const orgId = flags.org || config.default_org;
|
|
42
31
|
const domain = domainArg || config.default_domain;
|
|
43
32
|
if (!orgId || !domain)
|
|
44
|
-
|
|
33
|
+
error("Missing required arguments.\nUsage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
|
|
45
34
|
if (!flags['namecheap-user'] || !flags['namecheap-key']) {
|
|
46
|
-
|
|
35
|
+
error("Missing required arguments.\nUsage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>");
|
|
47
36
|
}
|
|
48
|
-
await
|
|
37
|
+
await sdkDomain.importDomain(config.api_key, orgId, {
|
|
49
38
|
domain,
|
|
50
39
|
namecheap_api_user: flags['namecheap-user'],
|
|
51
40
|
namecheap_api_key: flags['namecheap-key']
|
|
52
41
|
});
|
|
53
|
-
|
|
42
|
+
success(`Imported ${domain}`);
|
|
54
43
|
}
|
|
55
|
-
async function list(flags) {
|
|
56
|
-
const config =
|
|
44
|
+
export async function list(flags) {
|
|
45
|
+
const config = requireConfig();
|
|
57
46
|
const orgId = flags.org || config.default_org;
|
|
58
47
|
if (!orgId)
|
|
59
|
-
|
|
48
|
+
error("Missing required arguments.\nUsage: myapi domain list --org <id> [--filter=all|unassigned|org]\n(Or set a default org via: myapi config set-org <id>)");
|
|
60
49
|
const filter = flags.filter;
|
|
61
|
-
const domains = await
|
|
62
|
-
|
|
50
|
+
const domains = await sdkDomain.listDomains(config.api_key, orgId, filter);
|
|
51
|
+
printTable(domains);
|
|
63
52
|
}
|
|
64
|
-
async function assign(domainArg, flags) {
|
|
65
|
-
const config =
|
|
53
|
+
export async function assign(domainArg, flags) {
|
|
54
|
+
const config = requireConfig();
|
|
66
55
|
const orgId = flags.org || config.default_org;
|
|
67
56
|
const domain = domainArg || config.default_domain;
|
|
68
57
|
const targetOrgId = flags.target;
|
|
69
58
|
if (!orgId || !domain || !targetOrgId)
|
|
70
|
-
|
|
71
|
-
const res = await
|
|
72
|
-
|
|
59
|
+
error("Missing required arguments.\nUsage: myapi domain assign <domain> --org <id> --target <target_org_id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
|
|
60
|
+
const res = await sdkDomain.assignDomain(config.api_key, orgId, domain, targetOrgId);
|
|
61
|
+
success(`Assigned ${domain} to org ${targetOrgId}`);
|
|
73
62
|
}
|
|
74
|
-
async function unassign(domainArg, flags) {
|
|
75
|
-
const config =
|
|
63
|
+
export async function unassign(domainArg, flags) {
|
|
64
|
+
const config = requireConfig();
|
|
76
65
|
const orgId = flags.org || config.default_org;
|
|
77
66
|
const domain = domainArg || config.default_domain;
|
|
78
67
|
if (!orgId || !domain)
|
|
79
|
-
|
|
80
|
-
const res = await
|
|
81
|
-
|
|
68
|
+
error("Missing required arguments.\nUsage: myapi domain unassign <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
|
|
69
|
+
const res = await sdkDomain.unassignDomain(config.api_key, orgId, domain);
|
|
70
|
+
success(`Unassigned ${domain} from org ${orgId}`);
|
|
82
71
|
}
|
|
83
|
-
async function settings(domainArg, flags) {
|
|
84
|
-
const config =
|
|
72
|
+
export async function settings(domainArg, flags) {
|
|
73
|
+
const config = requireConfig();
|
|
85
74
|
const orgId = flags.org || config.default_org;
|
|
86
75
|
const domain = domainArg || config.default_domain;
|
|
87
76
|
if (!orgId || !domain)
|
|
88
|
-
|
|
89
|
-
const res = await
|
|
90
|
-
|
|
77
|
+
error("Missing required arguments.\nUsage: myapi domain settings <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
|
|
78
|
+
const res = await sdkDomain.getDomainSettings(config.api_key, orgId, domain);
|
|
79
|
+
printJson(res);
|
|
91
80
|
}
|
|
92
|
-
async function updateSettings(domainArg, flags) {
|
|
93
|
-
const config =
|
|
81
|
+
export async function updateSettings(domainArg, flags) {
|
|
82
|
+
const config = requireConfig();
|
|
94
83
|
const orgId = flags.org || config.default_org;
|
|
95
84
|
const domain = domainArg || config.default_domain;
|
|
96
85
|
if (!orgId || !domain)
|
|
97
|
-
|
|
86
|
+
error("Missing required arguments.\nUsage: myapi domain update-settings <domain> --org <id> [--security=...] [--browser-check=...] [--purge-cache]\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
|
|
98
87
|
const payload = {};
|
|
99
88
|
if (flags.security)
|
|
100
89
|
payload.security_level = flags.security;
|
|
@@ -102,31 +91,31 @@ async function updateSettings(domainArg, flags) {
|
|
|
102
91
|
payload.browser_check = flags['browser-check'];
|
|
103
92
|
if (flags['purge-cache'])
|
|
104
93
|
payload.purge_cache = true;
|
|
105
|
-
const res = await
|
|
106
|
-
|
|
94
|
+
const res = await sdkDomain.updateDomainSettings(config.api_key, orgId, domain, payload);
|
|
95
|
+
success(`Updated settings for ${domain}!\n${JSON.stringify(res, null, 2)}`);
|
|
107
96
|
}
|
|
108
|
-
async function run(subcommand, args, flags) {
|
|
97
|
+
export async function run(subcommand, args, flags) {
|
|
109
98
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
110
|
-
|
|
99
|
+
info('Usage: myapi domain <subcommand>\n\nSubcommands:\n list List domains\n check Check domain availability\n register Register a domain\n import Import an existing domain\n assign Assign domain to org\n unassign Unassign domain from its current org\n settings Get domain settings\n update-settings Update domain settings\n\nNote: All domain commands require the --org <id> flag.');
|
|
111
100
|
return;
|
|
112
101
|
}
|
|
113
102
|
if (flags.help) {
|
|
114
103
|
if (subcommand === 'list')
|
|
115
|
-
|
|
104
|
+
info('Usage: myapi domain list --org <id> [--filter=all|unassigned|org]\n\nLists all registered domains in your account.\n --filter=all Lists all domains owned by the account.\n --filter=unassigned Lists domains not assigned to an org.\n --filter=org (Default) Lists domains assigned to the current org.');
|
|
116
105
|
else if (subcommand === 'check')
|
|
117
|
-
|
|
106
|
+
info('Usage: myapi domain check <domain> --org <id>\n\nChecks if a domain name is available for registration.');
|
|
118
107
|
else if (subcommand === 'register')
|
|
119
|
-
|
|
108
|
+
info('Usage: myapi domain register <domain> --org <id> [--years <num>]\n\nRegisters a new domain name.');
|
|
120
109
|
else if (subcommand === 'import')
|
|
121
|
-
|
|
110
|
+
info('Usage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>\n\nImports an existing domain from Namecheap.');
|
|
122
111
|
else if (subcommand === 'assign')
|
|
123
|
-
|
|
112
|
+
info('Usage: myapi domain assign <domain> --org <id> --target <target_org_id>\n\nAssigns a domain to a different organization.');
|
|
124
113
|
else if (subcommand === 'unassign')
|
|
125
|
-
|
|
114
|
+
info('Usage: myapi domain unassign <domain> --org <id>\n\nUnassigns a domain from its current organization.');
|
|
126
115
|
else if (subcommand === 'settings')
|
|
127
|
-
|
|
116
|
+
info('Usage: myapi domain settings <domain> --org <id>\n\nGets the DNS settings and configuration for a domain.');
|
|
128
117
|
else if (subcommand === 'update-settings')
|
|
129
|
-
|
|
118
|
+
info('Usage: myapi domain update-settings <domain> --org <id> [--security=essentially_off|medium|high|under_attack] [--browser-check=on|off] [--purge-cache]\n\nUpdates edge settings for a domain.');
|
|
130
119
|
return;
|
|
131
120
|
}
|
|
132
121
|
if (subcommand === 'list')
|
|
@@ -146,5 +135,5 @@ async function run(subcommand, args, flags) {
|
|
|
146
135
|
else if (subcommand === 'update-settings')
|
|
147
136
|
await updateSettings(args[0], flags);
|
|
148
137
|
else
|
|
149
|
-
|
|
138
|
+
error(`Unknown subcommand: ${subcommand}. Run "myapi domain --help" for a list of valid subcommands.`);
|
|
150
139
|
}
|
package/dist/commands/email.js
CHANGED
|
@@ -1,73 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.inbox = inbox;
|
|
8
|
-
exports.outbox = outbox;
|
|
9
|
-
exports.listTemplates = listTemplates;
|
|
10
|
-
exports.generateTemplate = generateTemplate;
|
|
11
|
-
exports.listCampaigns = listCampaigns;
|
|
12
|
-
exports.campaignStats = campaignStats;
|
|
13
|
-
exports.run = run;
|
|
14
|
-
const sdk_1 = require("@myapihq/sdk");
|
|
15
|
-
const config_js_1 = require("../config.js");
|
|
16
|
-
const output_js_1 = require("../output.js");
|
|
17
|
-
const utils_js_1 = require("../utils.js");
|
|
18
|
-
async function createMailbox(flags) {
|
|
19
|
-
const config = (0, config_js_1.requireConfig)();
|
|
1
|
+
import { email as sdkEmail } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable, printJson, info } from '../output.js';
|
|
4
|
+
import { sleep } from '../utils.js';
|
|
5
|
+
export async function createMailbox(flags) {
|
|
6
|
+
const config = requireConfig();
|
|
20
7
|
const orgId = flags.org || config.default_org;
|
|
21
8
|
const domain = flags.domain || config.default_domain;
|
|
22
9
|
if (!orgId || !domain || !flags.username) {
|
|
23
|
-
|
|
10
|
+
error("Missing required arguments.\nUsage: myapi email create-mailbox --org <id> --domain <domain> --username <user>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
|
|
24
11
|
}
|
|
25
|
-
const address = await
|
|
26
|
-
|
|
12
|
+
const address = await sdkEmail.createMailbox(config.api_key, orgId, domain, flags.username);
|
|
13
|
+
success(`Mailbox created: ${address.address}`);
|
|
27
14
|
}
|
|
28
|
-
async function listMailboxes(flags) {
|
|
29
|
-
const config =
|
|
15
|
+
export async function listMailboxes(flags) {
|
|
16
|
+
const config = requireConfig();
|
|
30
17
|
const orgId = flags.org || config.default_org;
|
|
31
18
|
if (!orgId)
|
|
32
|
-
|
|
19
|
+
error("Missing required arguments.\nUsage: myapi email list-mailboxes --org <id> [--domain <domain> | --filter unassigned]\n(Or set a default org via: myapi config set-org <id>)");
|
|
33
20
|
if (!flags.domain && flags.filter !== 'unassigned')
|
|
34
|
-
|
|
35
|
-
const mailboxes = await
|
|
21
|
+
error("Must provide either --domain <domain> or --filter unassigned");
|
|
22
|
+
const mailboxes = await sdkEmail.listMailboxes(config.api_key, orgId, {
|
|
36
23
|
domain: flags.domain,
|
|
37
24
|
filter: flags.filter === 'unassigned' ? 'unassigned' : undefined
|
|
38
25
|
});
|
|
39
|
-
|
|
26
|
+
printTable(mailboxes);
|
|
40
27
|
}
|
|
41
|
-
async function sent(flags) {
|
|
42
|
-
const config =
|
|
28
|
+
export async function sent(flags) {
|
|
29
|
+
const config = requireConfig();
|
|
43
30
|
const orgId = flags.org || config.default_org;
|
|
44
31
|
if (!orgId)
|
|
45
|
-
|
|
32
|
+
error("Missing required arguments.\nUsage: myapi email sent --org <id> [--limit <num>] [--offset <num>]\n(Or set defaults via: myapi config set-org <id>)");
|
|
46
33
|
const limit = parseInt(flags.limit) || 50;
|
|
47
34
|
const offset = parseInt(flags.offset) || 0;
|
|
48
|
-
const emails = await
|
|
49
|
-
|
|
35
|
+
const emails = await sdkEmail.getSentEmails(config.api_key, orgId, limit, offset);
|
|
36
|
+
printTable(emails);
|
|
50
37
|
}
|
|
51
|
-
async function send(flags) {
|
|
52
|
-
const config =
|
|
38
|
+
export async function send(flags) {
|
|
39
|
+
const config = requireConfig();
|
|
53
40
|
const orgId = flags.org || config.default_org;
|
|
54
41
|
if (!orgId || !flags.from || !flags.to || !flags.subject) {
|
|
55
|
-
|
|
42
|
+
error("Missing required arguments.\nUsage: myapi email send --org <id> --from <email> --to <email> --subject <str> [--body <str> | --template-id <id> [--template-vars <json_str>]]");
|
|
56
43
|
}
|
|
57
44
|
if (!flags.body && !flags['template-id'])
|
|
58
|
-
|
|
45
|
+
error("Must provide either --body or --template-id");
|
|
59
46
|
if (flags.body && flags['template-id'])
|
|
60
|
-
|
|
47
|
+
error("Cannot provide both --body and --template-id");
|
|
61
48
|
let templateVars;
|
|
62
49
|
if (flags['template-vars']) {
|
|
63
50
|
try {
|
|
64
51
|
templateVars = JSON.parse(flags['template-vars']);
|
|
65
52
|
}
|
|
66
53
|
catch (e) {
|
|
67
|
-
|
|
54
|
+
error("--template-vars must be a valid JSON string");
|
|
68
55
|
}
|
|
69
56
|
}
|
|
70
|
-
const res = await
|
|
57
|
+
const res = await sdkEmail.sendEmail(config.api_key, orgId, {
|
|
71
58
|
from: flags.from,
|
|
72
59
|
to: [flags.to],
|
|
73
60
|
subject: flags.subject,
|
|
@@ -75,39 +62,39 @@ async function send(flags) {
|
|
|
75
62
|
template_id: flags['template-id'],
|
|
76
63
|
template_vars: templateVars
|
|
77
64
|
});
|
|
78
|
-
|
|
65
|
+
success(`Email sent! Message ID: ${res.message_id}`);
|
|
79
66
|
}
|
|
80
|
-
async function inbox(address, flags) {
|
|
81
|
-
const config =
|
|
67
|
+
export async function inbox(address, flags) {
|
|
68
|
+
const config = requireConfig();
|
|
82
69
|
const orgId = flags.org || config.default_org;
|
|
83
70
|
if (!orgId || !address)
|
|
84
|
-
|
|
85
|
-
const messages = await
|
|
86
|
-
|
|
71
|
+
error("Missing required arguments.\nUsage: myapi email inbox <address> --org <id>");
|
|
72
|
+
const messages = await sdkEmail.getInbox(config.api_key, orgId, address);
|
|
73
|
+
printTable(messages);
|
|
87
74
|
}
|
|
88
|
-
async function outbox(address, flags) {
|
|
89
|
-
const config =
|
|
75
|
+
export async function outbox(address, flags) {
|
|
76
|
+
const config = requireConfig();
|
|
90
77
|
const orgId = flags.org || config.default_org;
|
|
91
78
|
if (!orgId || !address)
|
|
92
|
-
|
|
93
|
-
const messages = await
|
|
94
|
-
|
|
79
|
+
error("Missing required arguments.\nUsage: myapi email outbox <address> --org <id>");
|
|
80
|
+
const messages = await sdkEmail.getOutbox(config.api_key, orgId, address);
|
|
81
|
+
printTable(messages);
|
|
95
82
|
}
|
|
96
|
-
async function listTemplates(flags) {
|
|
97
|
-
const config =
|
|
83
|
+
export async function listTemplates(flags) {
|
|
84
|
+
const config = requireConfig();
|
|
98
85
|
const orgId = flags.org || config.default_org;
|
|
99
86
|
if (!orgId)
|
|
100
|
-
|
|
101
|
-
const templates = await
|
|
102
|
-
|
|
87
|
+
error("Missing required arguments.\nUsage: myapi email list-templates --org <id>\n(Or set a default org via: myapi config set-org <id>)");
|
|
88
|
+
const templates = await sdkEmail.listTemplates(config.api_key, orgId);
|
|
89
|
+
printTable(templates);
|
|
103
90
|
}
|
|
104
|
-
async function generateTemplate(flags) {
|
|
105
|
-
const config =
|
|
91
|
+
export async function generateTemplate(flags) {
|
|
92
|
+
const config = requireConfig();
|
|
106
93
|
const orgId = flags.org || config.default_org;
|
|
107
94
|
if (!orgId || !flags.prompt || !flags.name) {
|
|
108
|
-
|
|
95
|
+
error("Missing required arguments.\nUsage: myapi email generate-template --org <id> --prompt <str> --name <str>");
|
|
109
96
|
}
|
|
110
|
-
const job = await
|
|
97
|
+
const job = await sdkEmail.generateTemplate(config.api_key, orgId, {
|
|
111
98
|
prompt: flags.prompt,
|
|
112
99
|
name: flags.name
|
|
113
100
|
});
|
|
@@ -116,65 +103,65 @@ async function generateTemplate(flags) {
|
|
|
116
103
|
let i = 0;
|
|
117
104
|
let elapsed = 0;
|
|
118
105
|
while (elapsed < 90000) {
|
|
119
|
-
const status = await
|
|
106
|
+
const status = await sdkEmail.getTemplateJobStatus(config.api_key, orgId, job.job_id);
|
|
120
107
|
if (status.status === 'completed') {
|
|
121
108
|
process.stdout.write('\r\x1b[K');
|
|
122
|
-
|
|
109
|
+
success(`Template generated! ID: ${status.template_id}\nPreview: ${status.result?.preview_url}`);
|
|
123
110
|
return;
|
|
124
111
|
}
|
|
125
112
|
if (status.status === 'failed') {
|
|
126
113
|
process.stdout.write('\r\x1b[K');
|
|
127
|
-
|
|
114
|
+
error("Template generation failed");
|
|
128
115
|
}
|
|
129
116
|
process.stdout.write(`\rGenerating template ${chars[i++ % chars.length]}`);
|
|
130
|
-
await
|
|
117
|
+
await sleep(3000);
|
|
131
118
|
elapsed += 3000;
|
|
132
119
|
}
|
|
133
120
|
process.stdout.write('\r\x1b[K');
|
|
134
|
-
|
|
121
|
+
error("Template generation timed out");
|
|
135
122
|
}
|
|
136
|
-
async function listCampaigns(flags) {
|
|
137
|
-
const config =
|
|
123
|
+
export async function listCampaigns(flags) {
|
|
124
|
+
const config = requireConfig();
|
|
138
125
|
const orgId = flags.org || config.default_org;
|
|
139
126
|
if (!orgId)
|
|
140
|
-
|
|
141
|
-
const campaigns = await
|
|
142
|
-
|
|
127
|
+
error("Missing required arguments.\nUsage: myapi email list-campaigns --org <id>\n(Or set a default org via: myapi config set-org <id>)");
|
|
128
|
+
const campaigns = await sdkEmail.listCampaigns(config.api_key, orgId);
|
|
129
|
+
printTable(campaigns);
|
|
143
130
|
}
|
|
144
|
-
async function campaignStats(id, flags) {
|
|
145
|
-
const config =
|
|
131
|
+
export async function campaignStats(id, flags) {
|
|
132
|
+
const config = requireConfig();
|
|
146
133
|
const orgId = flags.org || config.default_org;
|
|
147
134
|
if (!orgId || !id)
|
|
148
|
-
|
|
149
|
-
const stats = await
|
|
150
|
-
|
|
135
|
+
error("Missing required arguments.\nUsage: myapi email campaign-stats <id> --org <id>");
|
|
136
|
+
const stats = await sdkEmail.getCampaignStats(config.api_key, orgId, id);
|
|
137
|
+
printJson(stats);
|
|
151
138
|
}
|
|
152
|
-
async function run(subcommand, args, flags) {
|
|
139
|
+
export async function run(subcommand, args, flags) {
|
|
153
140
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
154
|
-
|
|
141
|
+
info('Usage: myapi email <subcommand>\n\nSubcommands:\n create-mailbox Create a new mailbox\n list-mailboxes List mailboxes\n send Send an email\n sent List sent emails\n inbox Read received emails\n outbox Read sent emails for address\n list-templates List email templates\n generate-template Generate AI template\n list-campaigns List campaigns\n campaign-stats Get campaign stats\n\nNote: All email commands require the --org <id> flag.');
|
|
155
142
|
return;
|
|
156
143
|
}
|
|
157
144
|
if (flags.help) {
|
|
158
145
|
if (subcommand === 'create-mailbox')
|
|
159
|
-
|
|
146
|
+
info('Usage: myapi email create-mailbox --org <id> --domain <domain> --username <user>');
|
|
160
147
|
else if (subcommand === 'list-mailboxes')
|
|
161
|
-
|
|
148
|
+
info('Usage: myapi email list-mailboxes --org <id> [--domain <domain> | --filter unassigned]');
|
|
162
149
|
else if (subcommand === 'send')
|
|
163
|
-
|
|
150
|
+
info('Usage: myapi email send --org <id> --from <email> --to <email> --subject <str> [--body <str> | --template-id <id> [--template-vars <json_str>]]');
|
|
164
151
|
else if (subcommand === 'sent')
|
|
165
|
-
|
|
152
|
+
info('Usage: myapi email sent --org <id> [--limit <num>] [--offset <num>]');
|
|
166
153
|
else if (subcommand === 'inbox')
|
|
167
|
-
|
|
154
|
+
info('Usage: myapi email inbox <address> --org <id>');
|
|
168
155
|
else if (subcommand === 'outbox')
|
|
169
|
-
|
|
156
|
+
info('Usage: myapi email outbox <address> --org <id>');
|
|
170
157
|
else if (subcommand === 'list-templates')
|
|
171
|
-
|
|
158
|
+
info('Usage: myapi email list-templates --org <id>');
|
|
172
159
|
else if (subcommand === 'generate-template')
|
|
173
|
-
|
|
160
|
+
info('Usage: myapi email generate-template --org <id> --prompt <str> --name <str>');
|
|
174
161
|
else if (subcommand === 'list-campaigns')
|
|
175
|
-
|
|
162
|
+
info('Usage: myapi email list-campaigns --org <id>');
|
|
176
163
|
else if (subcommand === 'campaign-stats')
|
|
177
|
-
|
|
164
|
+
info('Usage: myapi email campaign-stats <campaign_id> --org <id>');
|
|
178
165
|
return;
|
|
179
166
|
}
|
|
180
167
|
if (subcommand === 'create-mailbox')
|
|
@@ -198,5 +185,5 @@ async function run(subcommand, args, flags) {
|
|
|
198
185
|
else if (subcommand === 'campaign-stats')
|
|
199
186
|
await campaignStats(args[0], flags);
|
|
200
187
|
else
|
|
201
|
-
|
|
188
|
+
error(`Unknown subcommand: ${subcommand}. Run "myapi email --help" for a list of valid subcommands.`);
|
|
202
189
|
}
|