@myapihq/cli 1.0.11 → 1.0.13
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/domain.d.ts +3 -0
- package/dist/commands/domain.js +58 -19
- package/dist/commands/email.d.ts +1 -0
- package/dist/commands/email.js +78 -20
- package/dist/commands/org.js +1 -1
- package/dist/index.js +5 -0
- package/package.json +1 -1
- package/src/commands/domain.ts +43 -11
- package/src/commands/email.ts +59 -18
- package/src/commands/org.ts +1 -1
- package/src/index.ts +5 -0
|
@@ -2,5 +2,8 @@ export declare function check(domain: string, flags: Record<string, string | boo
|
|
|
2
2
|
export declare function register(domain: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
3
3
|
export declare function importDomain(domain: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
4
4
|
export declare function list(flags: Record<string, string | boolean>): Promise<void>;
|
|
5
|
+
export declare function assign(domain: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
6
|
+
export declare function unassign(domain: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
5
7
|
export declare function settings(domain: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
8
|
+
export declare function updateSettings(domain: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
6
9
|
export declare function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>): Promise<void>;
|
package/dist/commands/domain.js
CHANGED
|
@@ -4,17 +4,18 @@ exports.check = check;
|
|
|
4
4
|
exports.register = register;
|
|
5
5
|
exports.importDomain = importDomain;
|
|
6
6
|
exports.list = list;
|
|
7
|
+
exports.assign = assign;
|
|
8
|
+
exports.unassign = unassign;
|
|
7
9
|
exports.settings = settings;
|
|
10
|
+
exports.updateSettings = updateSettings;
|
|
8
11
|
exports.run = run;
|
|
9
12
|
const sdk_1 = require("@myapihq/sdk");
|
|
10
13
|
const config_js_1 = require("../config.js");
|
|
11
14
|
const output_js_1 = require("../output.js");
|
|
12
15
|
async function check(domain, flags) {
|
|
13
16
|
const orgId = flags.org;
|
|
14
|
-
if (!orgId)
|
|
15
|
-
(0, output_js_1.error)("Missing --org <id>
|
|
16
|
-
if (!domain)
|
|
17
|
-
(0, output_js_1.error)("Missing domain");
|
|
17
|
+
if (!orgId || !domain)
|
|
18
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain check <domain> --org <id>");
|
|
18
19
|
const config = (0, config_js_1.requireConfig)();
|
|
19
20
|
const res = await sdk_1.domain.checkDomain(config.api_key, orgId, domain);
|
|
20
21
|
if (res.available) {
|
|
@@ -26,10 +27,8 @@ async function check(domain, flags) {
|
|
|
26
27
|
}
|
|
27
28
|
async function register(domain, flags) {
|
|
28
29
|
const orgId = flags.org;
|
|
29
|
-
if (!orgId)
|
|
30
|
-
(0, output_js_1.error)("Missing --org <id>
|
|
31
|
-
if (!domain)
|
|
32
|
-
(0, output_js_1.error)("Missing domain");
|
|
30
|
+
if (!orgId || !domain)
|
|
31
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain register <domain> --org <id> [--years <num>]");
|
|
33
32
|
const years = parseInt(flags.years) || 1;
|
|
34
33
|
const config = (0, config_js_1.requireConfig)();
|
|
35
34
|
const res = await sdk_1.domain.registerDomain(config.api_key, orgId, domain, years);
|
|
@@ -37,12 +36,10 @@ async function register(domain, flags) {
|
|
|
37
36
|
}
|
|
38
37
|
async function importDomain(domain, flags) {
|
|
39
38
|
const orgId = flags.org;
|
|
40
|
-
if (!orgId)
|
|
41
|
-
(0, output_js_1.error)("Missing --org <id>
|
|
42
|
-
if (!domain)
|
|
43
|
-
(0, output_js_1.error)("Missing domain");
|
|
39
|
+
if (!orgId || !domain)
|
|
40
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>");
|
|
44
41
|
if (!flags['namecheap-user'] || !flags['namecheap-key']) {
|
|
45
|
-
(0, output_js_1.error)("Missing --namecheap-user
|
|
42
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>");
|
|
46
43
|
}
|
|
47
44
|
const config = (0, config_js_1.requireConfig)();
|
|
48
45
|
await sdk_1.domain.importDomain(config.api_key, orgId, {
|
|
@@ -55,25 +52,55 @@ async function importDomain(domain, flags) {
|
|
|
55
52
|
async function list(flags) {
|
|
56
53
|
const orgId = flags.org;
|
|
57
54
|
if (!orgId)
|
|
58
|
-
(0, output_js_1.error)("Missing --org <id>
|
|
55
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain list --org <id> [--filter=all|unassigned|org]");
|
|
59
56
|
const config = (0, config_js_1.requireConfig)();
|
|
60
57
|
const filter = flags.filter;
|
|
61
58
|
const domains = await sdk_1.domain.listDomains(config.api_key, orgId, filter);
|
|
62
59
|
(0, output_js_1.printTable)(domains);
|
|
63
60
|
}
|
|
61
|
+
async function assign(domain, flags) {
|
|
62
|
+
const orgId = flags.org;
|
|
63
|
+
const targetOrgId = flags.target;
|
|
64
|
+
if (!orgId || !domain || !targetOrgId)
|
|
65
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain assign <domain> --org <id> --target <target_org_id>");
|
|
66
|
+
const config = (0, config_js_1.requireConfig)();
|
|
67
|
+
const res = await sdk_1.domain.assignDomain(config.api_key, orgId, domain, targetOrgId);
|
|
68
|
+
(0, output_js_1.success)(`Assigned ${domain} to org ${targetOrgId}`);
|
|
69
|
+
}
|
|
70
|
+
async function unassign(domain, flags) {
|
|
71
|
+
const orgId = flags.org;
|
|
72
|
+
if (!orgId || !domain)
|
|
73
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain unassign <domain> --org <id>");
|
|
74
|
+
const config = (0, config_js_1.requireConfig)();
|
|
75
|
+
const res = await sdk_1.domain.unassignDomain(config.api_key, orgId, domain);
|
|
76
|
+
(0, output_js_1.success)(`Unassigned ${domain} from org ${orgId}`);
|
|
77
|
+
}
|
|
64
78
|
async function settings(domain, flags) {
|
|
65
79
|
const orgId = flags.org;
|
|
66
|
-
if (!orgId)
|
|
67
|
-
(0, output_js_1.error)("Missing --org <id>
|
|
68
|
-
if (!domain)
|
|
69
|
-
(0, output_js_1.error)("Missing domain");
|
|
80
|
+
if (!orgId || !domain)
|
|
81
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain settings <domain> --org <id>");
|
|
70
82
|
const config = (0, config_js_1.requireConfig)();
|
|
71
83
|
const res = await sdk_1.domain.getDomainSettings(config.api_key, orgId, domain);
|
|
72
84
|
(0, output_js_1.printJson)(res);
|
|
73
85
|
}
|
|
86
|
+
async function updateSettings(domain, flags) {
|
|
87
|
+
const orgId = flags.org;
|
|
88
|
+
if (!orgId || !domain)
|
|
89
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain update-settings <domain> --org <id> [--security=...] [--browser-check=...] [--purge-cache]");
|
|
90
|
+
const config = (0, config_js_1.requireConfig)();
|
|
91
|
+
const payload = {};
|
|
92
|
+
if (flags.security)
|
|
93
|
+
payload.security_level = flags.security;
|
|
94
|
+
if (flags['browser-check'])
|
|
95
|
+
payload.browser_check = flags['browser-check'];
|
|
96
|
+
if (flags['purge-cache'])
|
|
97
|
+
payload.purge_cache = true;
|
|
98
|
+
const res = await sdk_1.domain.updateDomainSettings(config.api_key, orgId, domain, payload);
|
|
99
|
+
(0, output_js_1.success)(`Updated settings for ${domain}!\n${JSON.stringify(res, null, 2)}`);
|
|
100
|
+
}
|
|
74
101
|
async function run(subcommand, args, flags) {
|
|
75
102
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
76
|
-
(0, output_js_1.info)('Usage: myapi domain <subcommand>\n\nSubcommands:\n list
|
|
103
|
+
(0, output_js_1.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.');
|
|
77
104
|
return;
|
|
78
105
|
}
|
|
79
106
|
if (flags.help) {
|
|
@@ -85,8 +112,14 @@ async function run(subcommand, args, flags) {
|
|
|
85
112
|
(0, output_js_1.info)('Usage: myapi domain register <domain> --org <id> [--years <num>]\n\nRegisters a new domain name.');
|
|
86
113
|
else if (subcommand === 'import')
|
|
87
114
|
(0, output_js_1.info)('Usage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>\n\nImports an existing domain from Namecheap.');
|
|
115
|
+
else if (subcommand === 'assign')
|
|
116
|
+
(0, output_js_1.info)('Usage: myapi domain assign <domain> --org <id> --target <target_org_id>\n\nAssigns a domain to a different organization.');
|
|
117
|
+
else if (subcommand === 'unassign')
|
|
118
|
+
(0, output_js_1.info)('Usage: myapi domain unassign <domain> --org <id>\n\nUnassigns a domain from its current organization.');
|
|
88
119
|
else if (subcommand === 'settings')
|
|
89
120
|
(0, output_js_1.info)('Usage: myapi domain settings <domain> --org <id>\n\nGets the DNS settings and configuration for a domain.');
|
|
121
|
+
else if (subcommand === 'update-settings')
|
|
122
|
+
(0, output_js_1.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.');
|
|
90
123
|
return;
|
|
91
124
|
}
|
|
92
125
|
if (subcommand === 'list')
|
|
@@ -97,8 +130,14 @@ async function run(subcommand, args, flags) {
|
|
|
97
130
|
await register(args[0], flags);
|
|
98
131
|
else if (subcommand === 'import')
|
|
99
132
|
await importDomain(args[0], flags);
|
|
133
|
+
else if (subcommand === 'assign')
|
|
134
|
+
await assign(args[0], flags);
|
|
135
|
+
else if (subcommand === 'unassign')
|
|
136
|
+
await unassign(args[0], flags);
|
|
100
137
|
else if (subcommand === 'settings')
|
|
101
138
|
await settings(args[0], flags);
|
|
139
|
+
else if (subcommand === 'update-settings')
|
|
140
|
+
await updateSettings(args[0], flags);
|
|
102
141
|
else
|
|
103
142
|
(0, output_js_1.error)(`Unknown subcommand: ${subcommand}. Run "myapi domain --help" for a list of valid subcommands.`);
|
|
104
143
|
}
|
package/dist/commands/email.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export declare function listTemplates(flags: Record<string, string | boolean>):
|
|
|
6
6
|
export declare function generateTemplate(flags: Record<string, string | boolean>): Promise<void>;
|
|
7
7
|
export declare function listCampaigns(flags: Record<string, string | boolean>): Promise<void>;
|
|
8
8
|
export declare function campaignStats(id: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
9
|
+
export declare function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>): Promise<void>;
|
package/dist/commands/email.js
CHANGED
|
@@ -8,28 +8,35 @@ exports.listTemplates = listTemplates;
|
|
|
8
8
|
exports.generateTemplate = generateTemplate;
|
|
9
9
|
exports.listCampaigns = listCampaigns;
|
|
10
10
|
exports.campaignStats = campaignStats;
|
|
11
|
+
exports.run = run;
|
|
11
12
|
const sdk_1 = require("@myapihq/sdk");
|
|
12
13
|
const config_js_1 = require("../config.js");
|
|
13
14
|
const output_js_1 = require("../output.js");
|
|
14
15
|
const utils_js_1 = require("../utils.js");
|
|
15
16
|
async function createMailbox(flags) {
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const orgId = flags.org;
|
|
18
|
+
if (!orgId || !flags.domain || !flags.username) {
|
|
19
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi email create-mailbox --org <id> --domain <domain> --username <user>");
|
|
20
|
+
}
|
|
18
21
|
const config = (0, config_js_1.requireConfig)();
|
|
19
|
-
const address = await sdk_1.email.createMailbox(config.api_key, flags.domain, flags.username);
|
|
22
|
+
const address = await sdk_1.email.createMailbox(config.api_key, orgId, flags.domain, flags.username);
|
|
20
23
|
(0, output_js_1.success)(`Mailbox created: ${address.address}`);
|
|
21
24
|
}
|
|
22
25
|
async function listMailboxes(flags) {
|
|
26
|
+
const orgId = flags.org;
|
|
27
|
+
if (!orgId)
|
|
28
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi email list-mailboxes --org <id>");
|
|
23
29
|
const config = (0, config_js_1.requireConfig)();
|
|
24
|
-
const mailboxes = await sdk_1.email.listMailboxes(config.api_key);
|
|
30
|
+
const mailboxes = await sdk_1.email.listMailboxes(config.api_key, orgId);
|
|
25
31
|
(0, output_js_1.printTable)(mailboxes);
|
|
26
32
|
}
|
|
27
33
|
async function send(flags) {
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
const orgId = flags.org;
|
|
35
|
+
if (!orgId || !flags.from || !flags.to || !flags.subject || !flags.body) {
|
|
36
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi email send --org <id> --from <email> --to <email> --subject <str> --body <str>");
|
|
30
37
|
}
|
|
31
38
|
const config = (0, config_js_1.requireConfig)();
|
|
32
|
-
const res = await sdk_1.email.sendEmail(config.api_key, {
|
|
39
|
+
const res = await sdk_1.email.sendEmail(config.api_key, orgId, {
|
|
33
40
|
from: flags.from,
|
|
34
41
|
to: [flags.to],
|
|
35
42
|
subject: flags.subject,
|
|
@@ -38,24 +45,28 @@ async function send(flags) {
|
|
|
38
45
|
(0, output_js_1.success)(`Email sent! Message ID: ${res.message_id}`);
|
|
39
46
|
}
|
|
40
47
|
async function inbox(address, flags) {
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
const orgId = flags.org;
|
|
49
|
+
if (!orgId || !address)
|
|
50
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi email inbox <address> --org <id>");
|
|
43
51
|
const config = (0, config_js_1.requireConfig)();
|
|
44
|
-
const messages = await sdk_1.email.getInbox(config.api_key, address);
|
|
52
|
+
const messages = await sdk_1.email.getInbox(config.api_key, orgId, address);
|
|
45
53
|
(0, output_js_1.printTable)(messages);
|
|
46
54
|
}
|
|
47
55
|
async function listTemplates(flags) {
|
|
56
|
+
const orgId = flags.org;
|
|
57
|
+
if (!orgId)
|
|
58
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi email list-templates --org <id>");
|
|
48
59
|
const config = (0, config_js_1.requireConfig)();
|
|
49
|
-
const templates = await sdk_1.email.listTemplates(config.api_key);
|
|
60
|
+
const templates = await sdk_1.email.listTemplates(config.api_key, orgId);
|
|
50
61
|
(0, output_js_1.printTable)(templates);
|
|
51
62
|
}
|
|
52
63
|
async function generateTemplate(flags) {
|
|
53
|
-
|
|
54
|
-
|
|
64
|
+
const orgId = flags.org;
|
|
65
|
+
if (!orgId || !flags.prompt || !flags.name) {
|
|
66
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi email generate-template --org <id> --prompt <str> --name <str>");
|
|
55
67
|
}
|
|
56
68
|
const config = (0, config_js_1.requireConfig)();
|
|
57
|
-
const job = await sdk_1.email.generateTemplate(config.api_key, {
|
|
58
|
-
org_id: flags['org-id'],
|
|
69
|
+
const job = await sdk_1.email.generateTemplate(config.api_key, orgId, {
|
|
59
70
|
prompt: flags.prompt,
|
|
60
71
|
name: flags.name
|
|
61
72
|
});
|
|
@@ -64,7 +75,7 @@ async function generateTemplate(flags) {
|
|
|
64
75
|
let i = 0;
|
|
65
76
|
let elapsed = 0;
|
|
66
77
|
while (elapsed < 90000) {
|
|
67
|
-
const status = await sdk_1.email.getTemplateJobStatus(config.api_key, job.job_id);
|
|
78
|
+
const status = await sdk_1.email.getTemplateJobStatus(config.api_key, orgId, job.job_id);
|
|
68
79
|
if (status.status === 'completed') {
|
|
69
80
|
process.stdout.write('\r\x1b[K');
|
|
70
81
|
(0, output_js_1.success)(`Template generated! ID: ${status.template_id}\nPreview: ${status.result?.preview_url}`);
|
|
@@ -82,14 +93,61 @@ async function generateTemplate(flags) {
|
|
|
82
93
|
(0, output_js_1.error)("Template generation timed out");
|
|
83
94
|
}
|
|
84
95
|
async function listCampaigns(flags) {
|
|
96
|
+
const orgId = flags.org;
|
|
97
|
+
if (!orgId)
|
|
98
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi email list-campaigns --org <id>");
|
|
85
99
|
const config = (0, config_js_1.requireConfig)();
|
|
86
|
-
const campaigns = await sdk_1.email.listCampaigns(config.api_key);
|
|
100
|
+
const campaigns = await sdk_1.email.listCampaigns(config.api_key, orgId);
|
|
87
101
|
(0, output_js_1.printTable)(campaigns);
|
|
88
102
|
}
|
|
89
103
|
async function campaignStats(id, flags) {
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
const orgId = flags.org;
|
|
105
|
+
if (!orgId || !id)
|
|
106
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi email campaign-stats <id> --org <id>");
|
|
92
107
|
const config = (0, config_js_1.requireConfig)();
|
|
93
|
-
const stats = await sdk_1.email.getCampaignStats(config.api_key, id);
|
|
108
|
+
const stats = await sdk_1.email.getCampaignStats(config.api_key, orgId, id);
|
|
94
109
|
(0, output_js_1.printJson)(stats);
|
|
95
110
|
}
|
|
111
|
+
async function run(subcommand, args, flags) {
|
|
112
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
113
|
+
(0, output_js_1.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 inbox Read received emails\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.');
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (flags.help) {
|
|
117
|
+
if (subcommand === 'create-mailbox')
|
|
118
|
+
(0, output_js_1.info)('Usage: myapi email create-mailbox --org <id> --domain <domain> --username <user>');
|
|
119
|
+
else if (subcommand === 'list-mailboxes')
|
|
120
|
+
(0, output_js_1.info)('Usage: myapi email list-mailboxes --org <id>');
|
|
121
|
+
else if (subcommand === 'send')
|
|
122
|
+
(0, output_js_1.info)('Usage: myapi email send --org <id> --from <email> --to <email> --subject <str> --body <str>');
|
|
123
|
+
else if (subcommand === 'inbox')
|
|
124
|
+
(0, output_js_1.info)('Usage: myapi email inbox <address> --org <id>');
|
|
125
|
+
else if (subcommand === 'list-templates')
|
|
126
|
+
(0, output_js_1.info)('Usage: myapi email list-templates --org <id>');
|
|
127
|
+
else if (subcommand === 'generate-template')
|
|
128
|
+
(0, output_js_1.info)('Usage: myapi email generate-template --org <id> --prompt <str> --name <str>');
|
|
129
|
+
else if (subcommand === 'list-campaigns')
|
|
130
|
+
(0, output_js_1.info)('Usage: myapi email list-campaigns --org <id>');
|
|
131
|
+
else if (subcommand === 'campaign-stats')
|
|
132
|
+
(0, output_js_1.info)('Usage: myapi email campaign-stats <campaign_id> --org <id>');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (subcommand === 'create-mailbox')
|
|
136
|
+
await createMailbox(flags);
|
|
137
|
+
else if (subcommand === 'list-mailboxes')
|
|
138
|
+
await listMailboxes(flags);
|
|
139
|
+
else if (subcommand === 'send')
|
|
140
|
+
await send(flags);
|
|
141
|
+
else if (subcommand === 'inbox')
|
|
142
|
+
await inbox(args[0], flags);
|
|
143
|
+
else if (subcommand === 'list-templates')
|
|
144
|
+
await listTemplates(flags);
|
|
145
|
+
else if (subcommand === 'generate-template')
|
|
146
|
+
await generateTemplate(flags);
|
|
147
|
+
else if (subcommand === 'list-campaigns')
|
|
148
|
+
await listCampaigns(flags);
|
|
149
|
+
else if (subcommand === 'campaign-stats')
|
|
150
|
+
await campaignStats(args[0], flags);
|
|
151
|
+
else
|
|
152
|
+
(0, output_js_1.error)(`Unknown subcommand: ${subcommand}. Run "myapi email --help" for a list of valid subcommands.`);
|
|
153
|
+
}
|
package/dist/commands/org.js
CHANGED
|
@@ -74,7 +74,7 @@ async function importOrg(args, flags) {
|
|
|
74
74
|
const domain = args[0];
|
|
75
75
|
const orgId = flags.org;
|
|
76
76
|
if (!domain || !orgId) {
|
|
77
|
-
(0, output_js_1.error)("Missing
|
|
77
|
+
(0, output_js_1.error)("Missing required arguments.\nUsage: myapi org import <domain> --org <id>");
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
80
|
const config = (0, config_js_1.requireConfig)();
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ 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"));
|
|
45
45
|
const domainCmd = __importStar(require("./commands/domain.js"));
|
|
46
|
+
const emailCmd = __importStar(require("./commands/email.js"));
|
|
46
47
|
async function main() {
|
|
47
48
|
const { args, flags } = (0, utils_js_1.parseArgs)(process.argv.slice(2));
|
|
48
49
|
if (args.length === 0) {
|
|
@@ -110,6 +111,9 @@ async function main() {
|
|
|
110
111
|
case 'domain':
|
|
111
112
|
await domainCmd.run(subcommand, restArgs, flags);
|
|
112
113
|
break;
|
|
114
|
+
case 'email':
|
|
115
|
+
await emailCmd.run(subcommand, restArgs, flags);
|
|
116
|
+
break;
|
|
113
117
|
default:
|
|
114
118
|
printHelp();
|
|
115
119
|
process.exit(0);
|
|
@@ -136,6 +140,7 @@ Commands:
|
|
|
136
140
|
org Manage organizations
|
|
137
141
|
setup Setup CLI credentials and view integration instructions
|
|
138
142
|
domain Manage domain configurations
|
|
143
|
+
email Send emails and manage templates
|
|
139
144
|
|
|
140
145
|
Run "myapi <command> --help" for subcommand help.`);
|
|
141
146
|
}
|
package/package.json
CHANGED
package/src/commands/domain.ts
CHANGED
|
@@ -4,8 +4,7 @@ import { success, error, info, printTable, printJson } from '../output.js';
|
|
|
4
4
|
|
|
5
5
|
export async function check(domain: string, flags: Record<string, string | boolean>) {
|
|
6
6
|
const orgId = flags.org as string;
|
|
7
|
-
if (!orgId) error("Missing --org <id>
|
|
8
|
-
if (!domain) error("Missing domain");
|
|
7
|
+
if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain check <domain> --org <id>");
|
|
9
8
|
const config = requireConfig();
|
|
10
9
|
const res = await sdkDomain.checkDomain(config.api_key, orgId, domain);
|
|
11
10
|
if (res.available) {
|
|
@@ -17,8 +16,7 @@ export async function check(domain: string, flags: Record<string, string | boole
|
|
|
17
16
|
|
|
18
17
|
export async function register(domain: string, flags: Record<string, string | boolean>) {
|
|
19
18
|
const orgId = flags.org as string;
|
|
20
|
-
if (!orgId) error("Missing --org <id>
|
|
21
|
-
if (!domain) error("Missing domain");
|
|
19
|
+
if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain register <domain> --org <id> [--years <num>]");
|
|
22
20
|
const years = parseInt(flags.years as string) || 1;
|
|
23
21
|
const config = requireConfig();
|
|
24
22
|
const res = await sdkDomain.registerDomain(config.api_key, orgId, domain, years);
|
|
@@ -27,10 +25,9 @@ export async function register(domain: string, flags: Record<string, string | bo
|
|
|
27
25
|
|
|
28
26
|
export async function importDomain(domain: string, flags: Record<string, string | boolean>) {
|
|
29
27
|
const orgId = flags.org as string;
|
|
30
|
-
if (!orgId) error("Missing --org <id>
|
|
31
|
-
if (!domain) error("Missing domain");
|
|
28
|
+
if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>");
|
|
32
29
|
if (!flags['namecheap-user'] || !flags['namecheap-key']) {
|
|
33
|
-
error("Missing --namecheap-user
|
|
30
|
+
error("Missing required arguments.\nUsage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>");
|
|
34
31
|
}
|
|
35
32
|
const config = requireConfig();
|
|
36
33
|
await sdkDomain.importDomain(config.api_key, orgId, {
|
|
@@ -43,25 +40,54 @@ export async function importDomain(domain: string, flags: Record<string, string
|
|
|
43
40
|
|
|
44
41
|
export async function list(flags: Record<string, string | boolean>) {
|
|
45
42
|
const orgId = flags.org as string;
|
|
46
|
-
if (!orgId) error("Missing --org <id>
|
|
43
|
+
if (!orgId) error("Missing required arguments.\nUsage: myapi domain list --org <id> [--filter=all|unassigned|org]");
|
|
47
44
|
const config = requireConfig();
|
|
48
45
|
const filter = flags.filter as 'all' | 'unassigned' | 'org' | undefined;
|
|
49
46
|
const domains = await sdkDomain.listDomains(config.api_key, orgId, filter);
|
|
50
47
|
printTable(domains as unknown as Record<string, unknown>[]);
|
|
51
48
|
}
|
|
52
49
|
|
|
50
|
+
export async function assign(domain: string, flags: Record<string, string | boolean>) {
|
|
51
|
+
const orgId = flags.org as string;
|
|
52
|
+
const targetOrgId = flags.target as string;
|
|
53
|
+
if (!orgId || !domain || !targetOrgId) error("Missing required arguments.\nUsage: myapi domain assign <domain> --org <id> --target <target_org_id>");
|
|
54
|
+
const config = requireConfig();
|
|
55
|
+
const res = await sdkDomain.assignDomain(config.api_key, orgId, domain, targetOrgId);
|
|
56
|
+
success(`Assigned ${domain} to org ${targetOrgId}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function unassign(domain: string, flags: Record<string, string | boolean>) {
|
|
60
|
+
const orgId = flags.org as string;
|
|
61
|
+
if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain unassign <domain> --org <id>");
|
|
62
|
+
const config = requireConfig();
|
|
63
|
+
const res = await sdkDomain.unassignDomain(config.api_key, orgId, domain);
|
|
64
|
+
success(`Unassigned ${domain} from org ${orgId}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
53
67
|
export async function settings(domain: string, flags: Record<string, string | boolean>) {
|
|
54
68
|
const orgId = flags.org as string;
|
|
55
|
-
if (!orgId) error("Missing --org <id>
|
|
56
|
-
if (!domain) error("Missing domain");
|
|
69
|
+
if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain settings <domain> --org <id>");
|
|
57
70
|
const config = requireConfig();
|
|
58
71
|
const res = await sdkDomain.getDomainSettings(config.api_key, orgId, domain);
|
|
59
72
|
printJson(res);
|
|
60
73
|
}
|
|
61
74
|
|
|
75
|
+
export async function updateSettings(domain: string, flags: Record<string, string | boolean>) {
|
|
76
|
+
const orgId = flags.org as string;
|
|
77
|
+
if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain update-settings <domain> --org <id> [--security=...] [--browser-check=...] [--purge-cache]");
|
|
78
|
+
const config = requireConfig();
|
|
79
|
+
const payload: any = {};
|
|
80
|
+
if (flags.security) payload.security_level = flags.security as string;
|
|
81
|
+
if (flags['browser-check']) payload.browser_check = flags['browser-check'] as string;
|
|
82
|
+
if (flags['purge-cache']) payload.purge_cache = true;
|
|
83
|
+
|
|
84
|
+
const res = await sdkDomain.updateDomainSettings(config.api_key, orgId, domain, payload);
|
|
85
|
+
success(`Updated settings for ${domain}!\n${JSON.stringify(res, null, 2)}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
62
88
|
export async function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>) {
|
|
63
89
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
64
|
-
info('Usage: myapi domain <subcommand>\n\nSubcommands:\n list
|
|
90
|
+
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.');
|
|
65
91
|
return;
|
|
66
92
|
}
|
|
67
93
|
|
|
@@ -70,7 +96,10 @@ export async function run(subcommand: string | undefined, args: string[], flags:
|
|
|
70
96
|
else if (subcommand === 'check') info('Usage: myapi domain check <domain> --org <id>\n\nChecks if a domain name is available for registration.');
|
|
71
97
|
else if (subcommand === 'register') info('Usage: myapi domain register <domain> --org <id> [--years <num>]\n\nRegisters a new domain name.');
|
|
72
98
|
else if (subcommand === 'import') info('Usage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>\n\nImports an existing domain from Namecheap.');
|
|
99
|
+
else if (subcommand === 'assign') info('Usage: myapi domain assign <domain> --org <id> --target <target_org_id>\n\nAssigns a domain to a different organization.');
|
|
100
|
+
else if (subcommand === 'unassign') info('Usage: myapi domain unassign <domain> --org <id>\n\nUnassigns a domain from its current organization.');
|
|
73
101
|
else if (subcommand === 'settings') info('Usage: myapi domain settings <domain> --org <id>\n\nGets the DNS settings and configuration for a domain.');
|
|
102
|
+
else if (subcommand === 'update-settings') 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.');
|
|
74
103
|
return;
|
|
75
104
|
}
|
|
76
105
|
|
|
@@ -78,6 +107,9 @@ export async function run(subcommand: string | undefined, args: string[], flags:
|
|
|
78
107
|
else if (subcommand === 'check') await check(args[0], flags);
|
|
79
108
|
else if (subcommand === 'register') await register(args[0], flags);
|
|
80
109
|
else if (subcommand === 'import') await importDomain(args[0], flags);
|
|
110
|
+
else if (subcommand === 'assign') await assign(args[0], flags);
|
|
111
|
+
else if (subcommand === 'unassign') await unassign(args[0], flags);
|
|
81
112
|
else if (subcommand === 'settings') await settings(args[0], flags);
|
|
113
|
+
else if (subcommand === 'update-settings') await updateSettings(args[0], flags);
|
|
82
114
|
else error(`Unknown subcommand: ${subcommand}. Run "myapi domain --help" for a list of valid subcommands.`);
|
|
83
115
|
}
|
package/src/commands/email.ts
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
import { email as sdkEmail } from '@myapihq/sdk';
|
|
2
2
|
import { requireConfig } from '../config.js';
|
|
3
|
-
import { success, error, printTable, printJson } from '../output.js';
|
|
3
|
+
import { success, error, printTable, printJson, info } from '../output.js';
|
|
4
4
|
import { sleep } from '../utils.js';
|
|
5
5
|
|
|
6
6
|
export async function createMailbox(flags: Record<string, string | boolean>) {
|
|
7
|
-
|
|
7
|
+
const orgId = flags.org as string;
|
|
8
|
+
if (!orgId || !flags.domain || !flags.username) {
|
|
9
|
+
error("Missing required arguments.\nUsage: myapi email create-mailbox --org <id> --domain <domain> --username <user>");
|
|
10
|
+
}
|
|
8
11
|
const config = requireConfig();
|
|
9
|
-
const address = await sdkEmail.createMailbox(config.api_key, flags.domain as string, flags.username as string);
|
|
12
|
+
const address = await sdkEmail.createMailbox(config.api_key, orgId, flags.domain as string, flags.username as string);
|
|
10
13
|
success(`Mailbox created: ${address.address}`);
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
export async function listMailboxes(flags: Record<string, string | boolean>) {
|
|
17
|
+
const orgId = flags.org as string;
|
|
18
|
+
if (!orgId) error("Missing required arguments.\nUsage: myapi email list-mailboxes --org <id>");
|
|
14
19
|
const config = requireConfig();
|
|
15
|
-
const mailboxes = await sdkEmail.listMailboxes(config.api_key);
|
|
20
|
+
const mailboxes = await sdkEmail.listMailboxes(config.api_key, orgId);
|
|
16
21
|
printTable(mailboxes as unknown as Record<string, unknown>[]);
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
export async function send(flags: Record<string, string | boolean>) {
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
const orgId = flags.org as string;
|
|
26
|
+
if (!orgId || !flags.from || !flags.to || !flags.subject || !flags.body) {
|
|
27
|
+
error("Missing required arguments.\nUsage: myapi email send --org <id> --from <email> --to <email> --subject <str> --body <str>");
|
|
22
28
|
}
|
|
23
29
|
const config = requireConfig();
|
|
24
|
-
const res = await sdkEmail.sendEmail(config.api_key, {
|
|
30
|
+
const res = await sdkEmail.sendEmail(config.api_key, orgId, {
|
|
25
31
|
from: flags.from as string,
|
|
26
32
|
to: [flags.to as string],
|
|
27
33
|
subject: flags.subject as string,
|
|
@@ -31,26 +37,29 @@ export async function send(flags: Record<string, string | boolean>) {
|
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
export async function inbox(address: string, flags: Record<string, string | boolean>) {
|
|
34
|
-
|
|
40
|
+
const orgId = flags.org as string;
|
|
41
|
+
if (!orgId || !address) error("Missing required arguments.\nUsage: myapi email inbox <address> --org <id>");
|
|
35
42
|
const config = requireConfig();
|
|
36
|
-
const messages = await sdkEmail.getInbox(config.api_key, address);
|
|
43
|
+
const messages = await sdkEmail.getInbox(config.api_key, orgId, address);
|
|
37
44
|
printTable(messages as unknown as Record<string, unknown>[]);
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
export async function listTemplates(flags: Record<string, string | boolean>) {
|
|
48
|
+
const orgId = flags.org as string;
|
|
49
|
+
if (!orgId) error("Missing required arguments.\nUsage: myapi email list-templates --org <id>");
|
|
41
50
|
const config = requireConfig();
|
|
42
|
-
const templates = await sdkEmail.listTemplates(config.api_key);
|
|
51
|
+
const templates = await sdkEmail.listTemplates(config.api_key, orgId);
|
|
43
52
|
printTable(templates as unknown as Record<string, unknown>[]);
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
export async function generateTemplate(flags: Record<string, string | boolean>) {
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
const orgId = flags.org as string;
|
|
57
|
+
if (!orgId || !flags.prompt || !flags.name) {
|
|
58
|
+
error("Missing required arguments.\nUsage: myapi email generate-template --org <id> --prompt <str> --name <str>");
|
|
49
59
|
}
|
|
50
60
|
const config = requireConfig();
|
|
51
61
|
|
|
52
|
-
const job = await sdkEmail.generateTemplate(config.api_key, {
|
|
53
|
-
org_id: flags['org-id'] as string,
|
|
62
|
+
const job = await sdkEmail.generateTemplate(config.api_key, orgId, {
|
|
54
63
|
prompt: flags.prompt as string,
|
|
55
64
|
name: flags.name as string
|
|
56
65
|
});
|
|
@@ -61,7 +70,7 @@ export async function generateTemplate(flags: Record<string, string | boolean>)
|
|
|
61
70
|
let elapsed = 0;
|
|
62
71
|
|
|
63
72
|
while (elapsed < 90000) {
|
|
64
|
-
const status = await sdkEmail.getTemplateJobStatus(config.api_key, job.job_id);
|
|
73
|
+
const status = await sdkEmail.getTemplateJobStatus(config.api_key, orgId, job.job_id);
|
|
65
74
|
if (status.status === 'completed') {
|
|
66
75
|
process.stdout.write('\r\x1b[K');
|
|
67
76
|
success(`Template generated! ID: ${status.template_id}\nPreview: ${status.result?.preview_url}`);
|
|
@@ -80,14 +89,46 @@ export async function generateTemplate(flags: Record<string, string | boolean>)
|
|
|
80
89
|
}
|
|
81
90
|
|
|
82
91
|
export async function listCampaigns(flags: Record<string, string | boolean>) {
|
|
92
|
+
const orgId = flags.org as string;
|
|
93
|
+
if (!orgId) error("Missing required arguments.\nUsage: myapi email list-campaigns --org <id>");
|
|
83
94
|
const config = requireConfig();
|
|
84
|
-
const campaigns = await sdkEmail.listCampaigns(config.api_key);
|
|
95
|
+
const campaigns = await sdkEmail.listCampaigns(config.api_key, orgId);
|
|
85
96
|
printTable(campaigns as unknown as Record<string, unknown>[]);
|
|
86
97
|
}
|
|
87
98
|
|
|
88
99
|
export async function campaignStats(id: string, flags: Record<string, string | boolean>) {
|
|
89
|
-
|
|
100
|
+
const orgId = flags.org as string;
|
|
101
|
+
if (!orgId || !id) error("Missing required arguments.\nUsage: myapi email campaign-stats <id> --org <id>");
|
|
90
102
|
const config = requireConfig();
|
|
91
|
-
const stats = await sdkEmail.getCampaignStats(config.api_key, id);
|
|
103
|
+
const stats = await sdkEmail.getCampaignStats(config.api_key, orgId, id);
|
|
92
104
|
printJson(stats);
|
|
93
105
|
}
|
|
106
|
+
|
|
107
|
+
export async function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>) {
|
|
108
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
109
|
+
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 inbox Read received emails\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.');
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (flags.help) {
|
|
114
|
+
if (subcommand === 'create-mailbox') info('Usage: myapi email create-mailbox --org <id> --domain <domain> --username <user>');
|
|
115
|
+
else if (subcommand === 'list-mailboxes') info('Usage: myapi email list-mailboxes --org <id>');
|
|
116
|
+
else if (subcommand === 'send') info('Usage: myapi email send --org <id> --from <email> --to <email> --subject <str> --body <str>');
|
|
117
|
+
else if (subcommand === 'inbox') info('Usage: myapi email inbox <address> --org <id>');
|
|
118
|
+
else if (subcommand === 'list-templates') info('Usage: myapi email list-templates --org <id>');
|
|
119
|
+
else if (subcommand === 'generate-template') info('Usage: myapi email generate-template --org <id> --prompt <str> --name <str>');
|
|
120
|
+
else if (subcommand === 'list-campaigns') info('Usage: myapi email list-campaigns --org <id>');
|
|
121
|
+
else if (subcommand === 'campaign-stats') info('Usage: myapi email campaign-stats <campaign_id> --org <id>');
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (subcommand === 'create-mailbox') await createMailbox(flags);
|
|
126
|
+
else if (subcommand === 'list-mailboxes') await listMailboxes(flags);
|
|
127
|
+
else if (subcommand === 'send') await send(flags);
|
|
128
|
+
else if (subcommand === 'inbox') await inbox(args[0], flags);
|
|
129
|
+
else if (subcommand === 'list-templates') await listTemplates(flags);
|
|
130
|
+
else if (subcommand === 'generate-template') await generateTemplate(flags);
|
|
131
|
+
else if (subcommand === 'list-campaigns') await listCampaigns(flags);
|
|
132
|
+
else if (subcommand === 'campaign-stats') await campaignStats(args[0], flags);
|
|
133
|
+
else error(`Unknown subcommand: ${subcommand}. Run "myapi email --help" for a list of valid subcommands.`);
|
|
134
|
+
}
|
package/src/commands/org.ts
CHANGED
|
@@ -70,7 +70,7 @@ export async function importOrg(args: string[], flags: Record<string, string | b
|
|
|
70
70
|
const orgId = flags.org as string;
|
|
71
71
|
|
|
72
72
|
if (!domain || !orgId) {
|
|
73
|
-
error("Missing
|
|
73
|
+
error("Missing required arguments.\nUsage: myapi org import <domain> --org <id>");
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
76
|
const config = requireConfig();
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import * as billingCmd from './commands/billing.js';
|
|
|
8
8
|
import * as orgCmd from './commands/org.js';
|
|
9
9
|
import * as setupCmd from './commands/setup.js';
|
|
10
10
|
import * as domainCmd from './commands/domain.js';
|
|
11
|
+
import * as emailCmd from './commands/email.js';
|
|
11
12
|
|
|
12
13
|
async function main() {
|
|
13
14
|
const { args, flags } = parseArgs(process.argv.slice(2));
|
|
@@ -58,6 +59,9 @@ async function main() {
|
|
|
58
59
|
case 'domain':
|
|
59
60
|
await domainCmd.run(subcommand, restArgs, flags);
|
|
60
61
|
break;
|
|
62
|
+
case 'email':
|
|
63
|
+
await emailCmd.run(subcommand, restArgs, flags);
|
|
64
|
+
break;
|
|
61
65
|
default:
|
|
62
66
|
printHelp();
|
|
63
67
|
process.exit(0);
|
|
@@ -82,6 +86,7 @@ Commands:
|
|
|
82
86
|
org Manage organizations
|
|
83
87
|
setup Setup CLI credentials and view integration instructions
|
|
84
88
|
domain Manage domain configurations
|
|
89
|
+
email Send emails and manage templates
|
|
85
90
|
|
|
86
91
|
Run "myapi <command> --help" for subcommand help.`);
|
|
87
92
|
}
|