@myapihq/cli 1.0.12 → 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.
@@ -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>;
@@ -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
- if (!flags.domain || !flags.username)
17
- (0, output_js_1.error)("Missing --domain or --username flags");
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
- if (!flags.from || !flags.to || !flags.subject || !flags.body) {
29
- (0, output_js_1.error)("Missing --from, --to, --subject, or --body flags");
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
- if (!address)
42
- (0, output_js_1.error)("Missing address");
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
- if (!flags['org-id'] || !flags.prompt || !flags.name) {
54
- (0, output_js_1.error)("Missing --org-id, --prompt, or --name flags");
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
- if (!id)
91
- (0, output_js_1.error)("Missing campaign id");
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/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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myapihq/cli",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "MyAPI command-line interface",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -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
- if (!flags.domain || !flags.username) error("Missing --domain or --username flags");
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
- if (!flags.from || !flags.to || !flags.subject || !flags.body) {
21
- error("Missing --from, --to, --subject, or --body flags");
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
- if (!address) error("Missing address");
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
- if (!flags['org-id'] || !flags.prompt || !flags.name) {
48
- error("Missing --org-id, --prompt, or --name flags");
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
- if (!id) error("Missing campaign id");
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/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
  }