@myapihq/cli 1.0.14 → 1.0.16

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.
@@ -68,7 +68,7 @@ async function topup(amountStr, flags) {
68
68
  }
69
69
  async function setup(flags) {
70
70
  if (flags.help) {
71
- (0, output_js_1.info)('Usage: myapi billing setup\n\nGenerates a secure Stripe Checkout link to add or update your payment method.');
71
+ (0, output_js_1.info)('Usage: myapi billing setup\n\nGenerates a secure checkout link to add or update your payment method.');
72
72
  return;
73
73
  }
74
74
  const config = (0, config_js_1.requireConfig)();
@@ -1,7 +1,9 @@
1
1
  export declare function createMailbox(flags: Record<string, string | boolean>): Promise<void>;
2
2
  export declare function listMailboxes(flags: Record<string, string | boolean>): Promise<void>;
3
+ export declare function sent(flags: Record<string, string | boolean>): Promise<void>;
3
4
  export declare function send(flags: Record<string, string | boolean>): Promise<void>;
4
5
  export declare function inbox(address: string, flags: Record<string, string | boolean>): Promise<void>;
6
+ export declare function outbox(address: string, flags: Record<string, string | boolean>): Promise<void>;
5
7
  export declare function listTemplates(flags: Record<string, string | boolean>): Promise<void>;
6
8
  export declare function generateTemplate(flags: Record<string, string | boolean>): Promise<void>;
7
9
  export declare function listCampaigns(flags: Record<string, string | boolean>): Promise<void>;
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createMailbox = createMailbox;
4
4
  exports.listMailboxes = listMailboxes;
5
+ exports.sent = sent;
5
6
  exports.send = send;
6
7
  exports.inbox = inbox;
8
+ exports.outbox = outbox;
7
9
  exports.listTemplates = listTemplates;
8
10
  exports.generateTemplate = generateTemplate;
9
11
  exports.listCampaigns = listCampaigns;
@@ -27,21 +29,51 @@ async function listMailboxes(flags) {
27
29
  const config = (0, config_js_1.requireConfig)();
28
30
  const orgId = flags.org || config.default_org;
29
31
  if (!orgId)
30
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email list-mailboxes --org <id>\n(Or set a default org via: myapi config set-org <id>)");
31
- const mailboxes = await sdk_1.email.listMailboxes(config.api_key, orgId);
32
+ (0, output_js_1.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
+ if (!flags.domain && flags.filter !== 'unassigned')
34
+ (0, output_js_1.error)("Must provide either --domain <domain> or --filter unassigned");
35
+ const mailboxes = await sdk_1.email.listMailboxes(config.api_key, orgId, {
36
+ domain: flags.domain,
37
+ filter: flags.filter === 'unassigned' ? 'unassigned' : undefined
38
+ });
32
39
  (0, output_js_1.printTable)(mailboxes);
33
40
  }
41
+ async function sent(flags) {
42
+ const config = (0, config_js_1.requireConfig)();
43
+ const orgId = flags.org || config.default_org;
44
+ if (!orgId)
45
+ (0, output_js_1.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
+ const limit = parseInt(flags.limit) || 50;
47
+ const offset = parseInt(flags.offset) || 0;
48
+ const emails = await sdk_1.email.getSentEmails(config.api_key, orgId, limit, offset);
49
+ (0, output_js_1.printTable)(emails);
50
+ }
34
51
  async function send(flags) {
35
52
  const config = (0, config_js_1.requireConfig)();
36
53
  const orgId = flags.org || config.default_org;
37
- if (!orgId || !flags.from || !flags.to || !flags.subject || !flags.body) {
38
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email send --org <id> --from <email> --to <email> --subject <str> --body <str>");
54
+ if (!orgId || !flags.from || !flags.to || !flags.subject) {
55
+ (0, output_js_1.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
+ }
57
+ if (!flags.body && !flags['template-id'])
58
+ (0, output_js_1.error)("Must provide either --body or --template-id");
59
+ if (flags.body && flags['template-id'])
60
+ (0, output_js_1.error)("Cannot provide both --body and --template-id");
61
+ let templateVars;
62
+ if (flags['template-vars']) {
63
+ try {
64
+ templateVars = JSON.parse(flags['template-vars']);
65
+ }
66
+ catch (e) {
67
+ (0, output_js_1.error)("--template-vars must be a valid JSON string");
68
+ }
39
69
  }
40
70
  const res = await sdk_1.email.sendEmail(config.api_key, orgId, {
41
71
  from: flags.from,
42
72
  to: [flags.to],
43
73
  subject: flags.subject,
44
- text: flags.body
74
+ text: flags.body,
75
+ template_id: flags['template-id'],
76
+ template_vars: templateVars
45
77
  });
46
78
  (0, output_js_1.success)(`Email sent! Message ID: ${res.message_id}`);
47
79
  }
@@ -53,6 +85,14 @@ async function inbox(address, flags) {
53
85
  const messages = await sdk_1.email.getInbox(config.api_key, orgId, address);
54
86
  (0, output_js_1.printTable)(messages);
55
87
  }
88
+ async function outbox(address, flags) {
89
+ const config = (0, config_js_1.requireConfig)();
90
+ const orgId = flags.org || config.default_org;
91
+ if (!orgId || !address)
92
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email outbox <address> --org <id>");
93
+ const messages = await sdk_1.email.getOutbox(config.api_key, orgId, address);
94
+ (0, output_js_1.printTable)(messages);
95
+ }
56
96
  async function listTemplates(flags) {
57
97
  const config = (0, config_js_1.requireConfig)();
58
98
  const orgId = flags.org || config.default_org;
@@ -111,18 +151,22 @@ async function campaignStats(id, flags) {
111
151
  }
112
152
  async function run(subcommand, args, flags) {
113
153
  if (!subcommand || (flags.help && !subcommand)) {
114
- (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.');
154
+ (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 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.');
115
155
  return;
116
156
  }
117
157
  if (flags.help) {
118
158
  if (subcommand === 'create-mailbox')
119
159
  (0, output_js_1.info)('Usage: myapi email create-mailbox --org <id> --domain <domain> --username <user>');
120
160
  else if (subcommand === 'list-mailboxes')
121
- (0, output_js_1.info)('Usage: myapi email list-mailboxes --org <id>');
161
+ (0, output_js_1.info)('Usage: myapi email list-mailboxes --org <id> [--domain <domain> | --filter unassigned]');
122
162
  else if (subcommand === 'send')
123
- (0, output_js_1.info)('Usage: myapi email send --org <id> --from <email> --to <email> --subject <str> --body <str>');
163
+ (0, output_js_1.info)('Usage: myapi email send --org <id> --from <email> --to <email> --subject <str> [--body <str> | --template-id <id> [--template-vars <json_str>]]');
164
+ else if (subcommand === 'sent')
165
+ (0, output_js_1.info)('Usage: myapi email sent --org <id> [--limit <num>] [--offset <num>]');
124
166
  else if (subcommand === 'inbox')
125
167
  (0, output_js_1.info)('Usage: myapi email inbox <address> --org <id>');
168
+ else if (subcommand === 'outbox')
169
+ (0, output_js_1.info)('Usage: myapi email outbox <address> --org <id>');
126
170
  else if (subcommand === 'list-templates')
127
171
  (0, output_js_1.info)('Usage: myapi email list-templates --org <id>');
128
172
  else if (subcommand === 'generate-template')
@@ -139,8 +183,12 @@ async function run(subcommand, args, flags) {
139
183
  await listMailboxes(flags);
140
184
  else if (subcommand === 'send')
141
185
  await send(flags);
186
+ else if (subcommand === 'sent')
187
+ await sent(flags);
142
188
  else if (subcommand === 'inbox')
143
189
  await inbox(args[0], flags);
190
+ else if (subcommand === 'outbox')
191
+ await outbox(args[0], flags);
144
192
  else if (subcommand === 'list-templates')
145
193
  await listTemplates(flags);
146
194
  else if (subcommand === 'generate-template')
@@ -1,3 +1,7 @@
1
1
  export declare function list(flags: Record<string, string | boolean>): Promise<void>;
2
2
  export declare function create(flags: Record<string, string | boolean>): Promise<void>;
3
+ export declare function get(id: string, flags: Record<string, string | boolean>): Promise<void>;
4
+ export declare function del(id: string, flags: Record<string, string | boolean>): Promise<void>;
3
5
  export declare function push(id: string, slug: string, flags: Record<string, string | boolean>): Promise<void>;
6
+ export declare function verify(id: string, flags: Record<string, string | boolean>): Promise<void>;
7
+ export declare function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>): Promise<void>;
@@ -2,27 +2,54 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.list = list;
4
4
  exports.create = create;
5
+ exports.get = get;
6
+ exports.del = del;
5
7
  exports.push = push;
8
+ exports.verify = verify;
9
+ exports.run = run;
6
10
  const sdk_1 = require("@myapihq/sdk");
7
11
  const config_js_1 = require("../config.js");
8
12
  const output_js_1 = require("../output.js");
9
13
  async function list(flags) {
10
14
  const config = (0, config_js_1.requireConfig)();
11
- const funnels = await sdk_1.funnel.listFunnels(config.api_key);
15
+ const orgId = flags.org || config.default_org;
16
+ if (!orgId)
17
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi funnel list --org <id>\n(Or set defaults via: myapi config set-org <id>)");
18
+ const funnels = await sdk_1.funnel.listFunnels(config.api_key, orgId);
12
19
  (0, output_js_1.printTable)(funnels);
13
20
  }
14
21
  async function create(flags) {
15
- if (!flags['org-id'] || !flags.domain) {
16
- (0, output_js_1.error)("Missing --org-id or --domain flags");
17
- }
18
22
  const config = (0, config_js_1.requireConfig)();
19
- const funnel = await sdk_1.funnel.createFunnel(config.api_key, flags['org-id'], flags.domain);
23
+ const orgId = flags.org || config.default_org;
24
+ const domain = flags.domain || config.default_domain;
25
+ if (!orgId || !domain) {
26
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi funnel create --org <id> --domain <domain>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
27
+ }
28
+ const funnel = await sdk_1.funnel.createFunnel(config.api_key, orgId, domain);
20
29
  (0, output_js_1.success)(`Funnel created! ID: ${funnel.id}`);
21
30
  }
31
+ async function get(id, flags) {
32
+ const config = (0, config_js_1.requireConfig)();
33
+ const orgId = flags.org || config.default_org;
34
+ if (!orgId || !id)
35
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi funnel get <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
36
+ const funnel = await sdk_1.funnel.getFunnel(config.api_key, orgId, id);
37
+ (0, output_js_1.printJson)(funnel);
38
+ }
39
+ async function del(id, flags) {
40
+ const config = (0, config_js_1.requireConfig)();
41
+ const orgId = flags.org || config.default_org;
42
+ if (!orgId || !id)
43
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi funnel delete <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
44
+ await sdk_1.funnel.deleteFunnel(config.api_key, orgId, id);
45
+ (0, output_js_1.success)(`Funnel ${id} deleted`);
46
+ }
22
47
  async function push(id, slug, flags) {
23
- if (!id || !slug)
24
- (0, output_js_1.error)("Missing id or slug");
25
48
  const config = (0, config_js_1.requireConfig)();
49
+ const orgId = flags.org || config.default_org;
50
+ if (!orgId || !id || !slug) {
51
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi funnel push <funnel_id> <slug> --org <id> < index.html\n(Or set defaults via: myapi config set-org <id>)");
52
+ }
26
53
  const html = await new Promise((resolve, reject) => {
27
54
  let data = '';
28
55
  process.stdin.setEncoding('utf-8');
@@ -32,6 +59,52 @@ async function push(id, slug, flags) {
32
59
  });
33
60
  if (!html)
34
61
  (0, output_js_1.error)("No HTML provided via stdin");
35
- await sdk_1.funnel.pushPage(config.api_key, id, slug, html);
62
+ await sdk_1.funnel.pushFunnelPage(config.api_key, orgId, id, { slug, html });
36
63
  (0, output_js_1.success)(`Pushed page to ${slug}`);
37
64
  }
65
+ async function verify(id, flags) {
66
+ const config = (0, config_js_1.requireConfig)();
67
+ const orgId = flags.org || config.default_org;
68
+ if (!orgId || !id)
69
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi funnel verify <id> --org <id> [--slug <slug>]\n(Or set defaults via: myapi config set-org <id>)");
70
+ const opts = {};
71
+ if (flags.slug)
72
+ opts.slug = flags.slug;
73
+ const v = await sdk_1.funnel.verifyFunnel(config.api_key, orgId, id, opts);
74
+ (0, output_js_1.printJson)(v);
75
+ }
76
+ async function run(subcommand, args, flags) {
77
+ if (!subcommand || (flags.help && !subcommand)) {
78
+ (0, output_js_1.info)('Usage: myapi funnel <subcommand>\n\nSubcommands:\n list List funnels\n create Create a funnel\n get Get funnel details\n delete Delete a funnel\n push Push a raw HTML page to a slug\n verify Verify links and webhooks\n\nNote: All funnel commands require the --org <id> flag.');
79
+ return;
80
+ }
81
+ if (flags.help) {
82
+ if (subcommand === 'list')
83
+ (0, output_js_1.info)('Usage: myapi funnel list --org <id>');
84
+ else if (subcommand === 'create')
85
+ (0, output_js_1.info)('Usage: myapi funnel create --org <id> --domain <domain>');
86
+ else if (subcommand === 'get')
87
+ (0, output_js_1.info)('Usage: myapi funnel get <id> --org <id>');
88
+ else if (subcommand === 'delete')
89
+ (0, output_js_1.info)('Usage: myapi funnel delete <id> --org <id>');
90
+ else if (subcommand === 'push')
91
+ (0, output_js_1.info)('Usage: myapi funnel push <funnel_id> <slug> --org <id> < index.html\n\nPushes HTML content from stdin to the specified funnel.');
92
+ else if (subcommand === 'verify')
93
+ (0, output_js_1.info)('Usage: myapi funnel verify <id> --org <id> [--slug <slug>]\n\nVerifies syntax and structure before pushing.');
94
+ return;
95
+ }
96
+ if (subcommand === 'list')
97
+ await list(flags);
98
+ else if (subcommand === 'create')
99
+ await create(flags);
100
+ else if (subcommand === 'get')
101
+ await get(args[0], flags);
102
+ else if (subcommand === 'delete')
103
+ await del(args[0], flags);
104
+ else if (subcommand === 'push')
105
+ await push(args[0], args[1], flags);
106
+ else if (subcommand === 'verify')
107
+ await verify(args[0], flags);
108
+ else
109
+ (0, output_js_1.error)(`Unknown subcommand: ${subcommand}. Run "myapi funnel --help" for a list of valid subcommands.`);
110
+ }
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ const orgCmd = __importStar(require("./commands/org.js"));
44
44
  const setupCmd = __importStar(require("./commands/setup.js"));
45
45
  const configCmd = __importStar(require("./commands/config.js"));
46
46
  const domainCmd = __importStar(require("./commands/domain.js"));
47
- const emailCmd = __importStar(require("./commands/email.js"));
47
+ const funnelCmd = __importStar(require("./commands/funnel.js"));
48
48
  async function main() {
49
49
  const { args, flags } = (0, utils_js_1.parseArgs)(process.argv.slice(2));
50
50
  if (args.length === 0) {
@@ -115,8 +115,8 @@ async function main() {
115
115
  case 'domain':
116
116
  await domainCmd.run(subcommand, restArgs, flags);
117
117
  break;
118
- case 'email':
119
- await emailCmd.run(subcommand, restArgs, flags);
118
+ case 'funnel':
119
+ await funnelCmd.run(subcommand, restArgs, flags);
120
120
  break;
121
121
  default:
122
122
  printHelp();
@@ -145,7 +145,7 @@ Commands:
145
145
  setup Setup CLI credentials and view integration instructions
146
146
  config Manage CLI defaults like org_id and domain
147
147
  domain Manage domain configurations
148
- email Send emails and manage templates
148
+ funnel Manage headless funnels and pages
149
149
 
150
150
  Run "myapi <command> --help" for subcommand help.`);
151
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myapihq/cli",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "MyAPI command-line interface",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -74,7 +74,7 @@ export async function topup(amountStr: string, flags: Record<string, string | bo
74
74
 
75
75
  export async function setup(flags: Record<string, string | boolean>) {
76
76
  if (flags.help) {
77
- info('Usage: myapi billing setup\n\nGenerates a secure Stripe Checkout link to add or update your payment method.');
77
+ info('Usage: myapi billing setup\n\nGenerates a secure checkout link to add or update your payment method.');
78
78
  return;
79
79
  }
80
80
  const config = requireConfig();
@@ -17,22 +17,50 @@ export async function createMailbox(flags: Record<string, string | boolean>) {
17
17
  export async function listMailboxes(flags: Record<string, string | boolean>) {
18
18
  const config = requireConfig();
19
19
  const orgId = (flags.org as string) || config.default_org;
20
- if (!orgId) error("Missing required arguments.\nUsage: myapi email list-mailboxes --org <id>\n(Or set a default org via: myapi config set-org <id>)");
21
- const mailboxes = await sdkEmail.listMailboxes(config.api_key, orgId);
20
+ if (!orgId) 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>)");
21
+ if (!flags.domain && flags.filter !== 'unassigned') error("Must provide either --domain <domain> or --filter unassigned");
22
+ const mailboxes = await sdkEmail.listMailboxes(config.api_key, orgId, {
23
+ domain: flags.domain as string | undefined,
24
+ filter: flags.filter === 'unassigned' ? 'unassigned' : undefined
25
+ });
22
26
  printTable(mailboxes as unknown as Record<string, unknown>[]);
23
27
  }
24
28
 
29
+ export async function sent(flags: Record<string, string | boolean>) {
30
+ const config = requireConfig();
31
+ const orgId = (flags.org as string) || config.default_org;
32
+ if (!orgId) error("Missing required arguments.\nUsage: myapi email sent --org <id> [--limit <num>] [--offset <num>]\n(Or set defaults via: myapi config set-org <id>)");
33
+ const limit = parseInt(flags.limit as string) || 50;
34
+ const offset = parseInt(flags.offset as string) || 0;
35
+ const emails = await sdkEmail.getSentEmails(config.api_key, orgId, limit, offset);
36
+ printTable(emails as unknown as Record<string, unknown>[]);
37
+ }
38
+
25
39
  export async function send(flags: Record<string, string | boolean>) {
26
40
  const config = requireConfig();
27
41
  const orgId = (flags.org as string) || config.default_org;
28
- if (!orgId || !flags.from || !flags.to || !flags.subject || !flags.body) {
29
- error("Missing required arguments.\nUsage: myapi email send --org <id> --from <email> --to <email> --subject <str> --body <str>");
42
+ if (!orgId || !flags.from || !flags.to || !flags.subject) {
43
+ 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>]]");
44
+ }
45
+ if (!flags.body && !flags['template-id']) error("Must provide either --body or --template-id");
46
+ if (flags.body && flags['template-id']) error("Cannot provide both --body and --template-id");
47
+
48
+ let templateVars: Record<string, string> | undefined;
49
+ if (flags['template-vars']) {
50
+ try {
51
+ templateVars = JSON.parse(flags['template-vars'] as string);
52
+ } catch (e) {
53
+ error("--template-vars must be a valid JSON string");
54
+ }
30
55
  }
56
+
31
57
  const res = await sdkEmail.sendEmail(config.api_key, orgId, {
32
58
  from: flags.from as string,
33
59
  to: [flags.to as string],
34
60
  subject: flags.subject as string,
35
- text: flags.body as string
61
+ text: flags.body as string | undefined,
62
+ template_id: flags['template-id'] as string | undefined,
63
+ template_vars: templateVars
36
64
  });
37
65
  success(`Email sent! Message ID: ${res.message_id}`);
38
66
  }
@@ -45,6 +73,14 @@ export async function inbox(address: string, flags: Record<string, string | bool
45
73
  printTable(messages as unknown as Record<string, unknown>[]);
46
74
  }
47
75
 
76
+ export async function outbox(address: string, flags: Record<string, string | boolean>) {
77
+ const config = requireConfig();
78
+ const orgId = (flags.org as string) || config.default_org;
79
+ if (!orgId || !address) 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 as unknown as Record<string, unknown>[]);
82
+ }
83
+
48
84
  export async function listTemplates(flags: Record<string, string | boolean>) {
49
85
  const config = requireConfig();
50
86
  const orgId = (flags.org as string) || config.default_org;
@@ -107,15 +143,17 @@ export async function campaignStats(id: string, flags: Record<string, string | b
107
143
 
108
144
  export async function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>) {
109
145
  if (!subcommand || (flags.help && !subcommand)) {
110
- 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.');
146
+ 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.');
111
147
  return;
112
148
  }
113
149
 
114
150
  if (flags.help) {
115
151
  if (subcommand === 'create-mailbox') info('Usage: myapi email create-mailbox --org <id> --domain <domain> --username <user>');
116
- else if (subcommand === 'list-mailboxes') info('Usage: myapi email list-mailboxes --org <id>');
117
- else if (subcommand === 'send') info('Usage: myapi email send --org <id> --from <email> --to <email> --subject <str> --body <str>');
152
+ else if (subcommand === 'list-mailboxes') info('Usage: myapi email list-mailboxes --org <id> [--domain <domain> | --filter unassigned]');
153
+ else if (subcommand === 'send') info('Usage: myapi email send --org <id> --from <email> --to <email> --subject <str> [--body <str> | --template-id <id> [--template-vars <json_str>]]');
154
+ else if (subcommand === 'sent') info('Usage: myapi email sent --org <id> [--limit <num>] [--offset <num>]');
118
155
  else if (subcommand === 'inbox') info('Usage: myapi email inbox <address> --org <id>');
156
+ else if (subcommand === 'outbox') info('Usage: myapi email outbox <address> --org <id>');
119
157
  else if (subcommand === 'list-templates') info('Usage: myapi email list-templates --org <id>');
120
158
  else if (subcommand === 'generate-template') info('Usage: myapi email generate-template --org <id> --prompt <str> --name <str>');
121
159
  else if (subcommand === 'list-campaigns') info('Usage: myapi email list-campaigns --org <id>');
@@ -126,7 +164,9 @@ export async function run(subcommand: string | undefined, args: string[], flags:
126
164
  if (subcommand === 'create-mailbox') await createMailbox(flags);
127
165
  else if (subcommand === 'list-mailboxes') await listMailboxes(flags);
128
166
  else if (subcommand === 'send') await send(flags);
167
+ else if (subcommand === 'sent') await sent(flags);
129
168
  else if (subcommand === 'inbox') await inbox(args[0], flags);
169
+ else if (subcommand === 'outbox') await outbox(args[0], flags);
130
170
  else if (subcommand === 'list-templates') await listTemplates(flags);
131
171
  else if (subcommand === 'generate-template') await generateTemplate(flags);
132
172
  else if (subcommand === 'list-campaigns') await listCampaigns(flags);
@@ -1,26 +1,52 @@
1
1
  import { funnel as sdkFunnel } from '@myapihq/sdk';
2
2
  import { requireConfig } from '../config.js';
3
- import { success, error, printTable } from '../output.js';
3
+ import { success, error, printTable, info, printJson } from '../output.js';
4
4
  import * as fs from 'fs';
5
5
 
6
6
  export async function list(flags: Record<string, string | boolean>) {
7
7
  const config = requireConfig();
8
- const funnels = await sdkFunnel.listFunnels(config.api_key);
8
+ const orgId = (flags.org as string) || config.default_org;
9
+ if (!orgId) error("Missing required arguments.\nUsage: myapi funnel list --org <id>\n(Or set defaults via: myapi config set-org <id>)");
10
+ const funnels = await sdkFunnel.listFunnels(config.api_key, orgId);
9
11
  printTable(funnels as unknown as Record<string, unknown>[]);
10
12
  }
11
13
 
12
14
  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
15
  const config = requireConfig();
17
- const funnel = await sdkFunnel.createFunnel(config.api_key, flags['org-id'] as string, flags.domain as string);
16
+ const orgId = (flags.org as string) || config.default_org;
17
+ const domain = (flags.domain as string) || config.default_domain;
18
+
19
+ if (!orgId || !domain) {
20
+ error("Missing required arguments.\nUsage: myapi funnel create --org <id> --domain <domain>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
21
+ }
22
+
23
+ const funnel = await sdkFunnel.createFunnel(config.api_key, orgId, domain);
18
24
  success(`Funnel created! ID: ${funnel.id}`);
19
25
  }
20
26
 
27
+ export async function get(id: string, flags: Record<string, string | boolean>) {
28
+ const config = requireConfig();
29
+ const orgId = (flags.org as string) || config.default_org;
30
+ if (!orgId || !id) error("Missing required arguments.\nUsage: myapi funnel get <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
31
+ const funnel = await sdkFunnel.getFunnel(config.api_key, orgId, id);
32
+ printJson(funnel);
33
+ }
34
+
35
+ export async function del(id: string, flags: Record<string, string | boolean>) {
36
+ const config = requireConfig();
37
+ const orgId = (flags.org as string) || config.default_org;
38
+ if (!orgId || !id) error("Missing required arguments.\nUsage: myapi funnel delete <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
39
+ await sdkFunnel.deleteFunnel(config.api_key, orgId, id);
40
+ success(`Funnel ${id} deleted`);
41
+ }
42
+
21
43
  export async function push(id: string, slug: string, flags: Record<string, string | boolean>) {
22
- if (!id || !slug) error("Missing id or slug");
23
44
  const config = requireConfig();
45
+ const orgId = (flags.org as string) || config.default_org;
46
+
47
+ if (!orgId || !id || !slug) {
48
+ error("Missing required arguments.\nUsage: myapi funnel push <funnel_id> <slug> --org <id> < index.html\n(Or set defaults via: myapi config set-org <id>)");
49
+ }
24
50
 
25
51
  const html = await new Promise<string>((resolve, reject) => {
26
52
  let data = '';
@@ -32,6 +58,41 @@ export async function push(id: string, slug: string, flags: Record<string, strin
32
58
 
33
59
  if (!html) error("No HTML provided via stdin");
34
60
 
35
- await sdkFunnel.pushPage(config.api_key, id, slug, html);
61
+ await sdkFunnel.pushFunnelPage(config.api_key, orgId, id, { slug, html });
36
62
  success(`Pushed page to ${slug}`);
37
63
  }
64
+
65
+ export async function verify(id: string, flags: Record<string, string | boolean>) {
66
+ const config = requireConfig();
67
+ const orgId = (flags.org as string) || config.default_org;
68
+ if (!orgId || !id) error("Missing required arguments.\nUsage: myapi funnel verify <id> --org <id> [--slug <slug>]\n(Or set defaults via: myapi config set-org <id>)");
69
+ const opts: any = {};
70
+ if (flags.slug) opts.slug = flags.slug as string;
71
+ const v = await sdkFunnel.verifyFunnel(config.api_key, orgId, id, opts);
72
+ printJson(v);
73
+ }
74
+
75
+ export async function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>) {
76
+ if (!subcommand || (flags.help && !subcommand)) {
77
+ info('Usage: myapi funnel <subcommand>\n\nSubcommands:\n list List funnels\n create Create a funnel\n get Get funnel details\n delete Delete a funnel\n push Push a raw HTML page to a slug\n verify Verify links and webhooks\n\nNote: All funnel commands require the --org <id> flag.');
78
+ return;
79
+ }
80
+
81
+ if (flags.help) {
82
+ if (subcommand === 'list') info('Usage: myapi funnel list --org <id>');
83
+ else if (subcommand === 'create') info('Usage: myapi funnel create --org <id> --domain <domain>');
84
+ else if (subcommand === 'get') info('Usage: myapi funnel get <id> --org <id>');
85
+ else if (subcommand === 'delete') info('Usage: myapi funnel delete <id> --org <id>');
86
+ else if (subcommand === 'push') info('Usage: myapi funnel push <funnel_id> <slug> --org <id> < index.html\n\nPushes HTML content from stdin to the specified funnel.');
87
+ else if (subcommand === 'verify') info('Usage: myapi funnel verify <id> --org <id> [--slug <slug>]\n\nVerifies syntax and structure before pushing.');
88
+ return;
89
+ }
90
+
91
+ if (subcommand === 'list') await list(flags);
92
+ else if (subcommand === 'create') await create(flags);
93
+ else if (subcommand === 'get') await get(args[0], flags);
94
+ else if (subcommand === 'delete') await del(args[0], flags);
95
+ else if (subcommand === 'push') await push(args[0], args[1], flags);
96
+ else if (subcommand === 'verify') await verify(args[0], flags);
97
+ else error(`Unknown subcommand: ${subcommand}. Run "myapi funnel --help" for a list of valid subcommands.`);
98
+ }
package/src/index.ts CHANGED
@@ -9,7 +9,7 @@ import * as orgCmd from './commands/org.js';
9
9
  import * as setupCmd from './commands/setup.js';
10
10
  import * as configCmd from './commands/config.js';
11
11
  import * as domainCmd from './commands/domain.js';
12
- import * as emailCmd from './commands/email.js';
12
+ import * as funnelCmd from './commands/funnel.js';
13
13
 
14
14
  async function main() {
15
15
  const { args, flags } = parseArgs(process.argv.slice(2));
@@ -63,8 +63,8 @@ async function main() {
63
63
  case 'domain':
64
64
  await domainCmd.run(subcommand, restArgs, flags);
65
65
  break;
66
- case 'email':
67
- await emailCmd.run(subcommand, restArgs, flags);
66
+ case 'funnel':
67
+ await funnelCmd.run(subcommand, restArgs, flags);
68
68
  break;
69
69
  default:
70
70
  printHelp();
@@ -91,7 +91,7 @@ Commands:
91
91
  setup Setup CLI credentials and view integration instructions
92
92
  config Manage CLI defaults like org_id and domain
93
93
  domain Manage domain configurations
94
- email Send emails and manage templates
94
+ funnel Manage headless funnels and pages
95
95
 
96
96
  Run "myapi <command> --help" for subcommand help.`);
97
97
  }