@myapihq/cli 1.0.84 → 1.1.0-wip.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/commands/auth.d.ts +8 -3
  2. package/dist/commands/auth.js +11 -29
  3. package/dist/commands/billing.d.ts +8 -4
  4. package/dist/commands/billing.js +43 -22
  5. package/dist/commands/config.d.ts +8 -5
  6. package/dist/commands/config.js +52 -27
  7. package/dist/commands/domain.d.ts +12 -9
  8. package/dist/commands/domain.js +117 -86
  9. package/dist/commands/email.d.ts +4 -12
  10. package/dist/commands/email.js +490 -128
  11. package/dist/commands/funnel.d.ts +10 -7
  12. package/dist/commands/funnel.js +75 -55
  13. package/dist/commands/image.js +25 -15
  14. package/dist/commands/keys.d.ts +8 -3
  15. package/dist/commands/keys.js +67 -28
  16. package/dist/commands/org.d.ts +9 -5
  17. package/dist/commands/org.js +99 -46
  18. package/dist/commands/pixel.js +23 -11
  19. package/dist/commands/setup.d.ts +3 -2
  20. package/dist/commands/setup.js +44 -77
  21. package/dist/commands/storage.js +25 -15
  22. package/dist/commands/update.d.ts +2 -1
  23. package/dist/commands/url.js +19 -7
  24. package/dist/commands/webhook.d.ts +8 -5
  25. package/dist/commands/webhook.js +52 -36
  26. package/dist/commands/workflow.d.ts +13 -7
  27. package/dist/commands/workflow.js +158 -56
  28. package/dist/flags.d.ts +8 -0
  29. package/dist/flags.js +88 -0
  30. package/dist/flags.test.d.ts +1 -0
  31. package/dist/flags.test.js +73 -0
  32. package/dist/helpers.d.ts +6 -0
  33. package/dist/helpers.js +29 -0
  34. package/dist/index.js +93 -107
  35. package/dist/output.d.ts +10 -1
  36. package/dist/output.js +4 -6
  37. package/dist/skills/my-email-api/README.md +45 -0
  38. package/dist/skills/my-email-api/SKILL.md +106 -0
  39. package/dist/skills/my-email-api/claude/.claude-plugin/plugin.json +6 -0
  40. package/dist/skills/my-email-api/make/.gitkeep +0 -0
  41. package/dist/skills/my-email-api/n8n/.gitkeep +0 -0
  42. package/dist/skills/my-email-api/openapi/.gitkeep +0 -0
  43. package/dist/skills/my-webhook-api/README.md +40 -0
  44. package/dist/skills/my-webhook-api/SKILL.md +65 -0
  45. package/dist/skills/my-webhook-api/claude/.claude-plugin/plugin.json +6 -0
  46. package/dist/skills/my-webhook-api/make/.gitkeep +0 -0
  47. package/dist/skills/my-webhook-api/n8n/.gitkeep +0 -0
  48. package/dist/skills/my-webhook-api/openapi/.gitkeep +0 -0
  49. package/dist/skills/my-workflow-api/README.md +37 -0
  50. package/dist/skills/my-workflow-api/SKILL.md +98 -0
  51. package/dist/skills/my-workflow-api/claude/.claude-plugin/plugin.json +6 -0
  52. package/dist/skills/my-workflow-api/make/.gitkeep +0 -0
  53. package/dist/skills/my-workflow-api/n8n/.gitkeep +0 -0
  54. package/dist/skills/my-workflow-api/openapi/.gitkeep +0 -0
  55. package/dist/utils.d.ts +0 -4
  56. package/dist/utils.js +0 -33
  57. package/dist/utils.test.d.ts +1 -0
  58. package/dist/utils.test.js +48 -0
  59. package/package.json +9 -4
  60. package/dist/commands/account.d.ts +0 -4
  61. package/dist/commands/account.js +0 -80
@@ -1,7 +1,10 @@
1
- export declare function list(flags: Record<string, string | boolean>): Promise<void>;
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>;
5
- export declare function push(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>;
1
+ import type { FlagSchema } from '../flags.js';
2
+ import { type Flags } from '../helpers.js';
3
+ export declare const SCHEMA: FlagSchema;
4
+ export declare function list(flags: Flags): Promise<void>;
5
+ export declare function create(flags: Flags): Promise<void>;
6
+ export declare function get(id: string, flags: Flags): Promise<void>;
7
+ export declare function del(id: string, flags: Flags): Promise<void>;
8
+ export declare function push(slug: string, flags: Flags): Promise<void>;
9
+ export declare function verify(id: string, flags: Flags): Promise<void>;
10
+ export declare function run(subcommand: string | undefined, args: string[], flags: Flags): Promise<void>;
@@ -1,12 +1,16 @@
1
1
  import { funnel as sdkFunnel, hq } from '@myapihq/sdk';
2
- import { requireConfig, saveConfig } from '../config.js';
2
+ import { requireConfig } from '../config.js';
3
3
  import { success, error, printTable, info, printJson } from '../output.js';
4
4
  import { formatDate } from '../utils.js';
5
+ import { requireOrg } from '../helpers.js';
6
+ export const SCHEMA = {
7
+ org: 'string',
8
+ funnel: 'string',
9
+ slug: 'string',
10
+ };
5
11
  export async function list(flags) {
6
12
  const config = requireConfig();
7
- const orgId = flags.org || config.default_org;
8
- if (!orgId)
9
- error("Missing required arguments.\nUsage: myapi funnel list --org <id>\n(Or set defaults via: myapi config set-org <id>)");
13
+ const orgId = requireOrg(flags, config, 'myapi funnel list [--org <id>]');
10
14
  const funnels = await sdkFunnel.listFunnels(config.api_key, orgId);
11
15
  if (flags.json) {
12
16
  printJson(funnels);
@@ -18,18 +22,14 @@ export async function list(flags) {
18
22
  created_at: formatDate(f.created_at),
19
23
  updated_at: formatDate(f.updated_at),
20
24
  }));
21
- if (rows.length === 0) {
22
- info('No funnels found. Create one with: myapi funnel create');
23
- return;
24
- }
25
- printTable(rows);
25
+ printTable(rows, {
26
+ flags,
27
+ empty: 'No funnels found. Create one with: myapi funnel create',
28
+ });
26
29
  }
27
30
  export async function create(flags) {
28
31
  const config = requireConfig();
29
- const orgId = flags.org || config.default_org;
30
- if (!orgId) {
31
- error("Missing required arguments.\nUsage: myapi funnel create --org <id>\n(Or set defaults via: myapi config set-org <id>)");
32
- }
32
+ const orgId = requireOrg(flags, config, 'myapi funnel create [--org <id>]');
33
33
  const result = await sdkFunnel.createFunnel(config.api_key, orgId);
34
34
  success(`Funnel created! ID: ${result.funnel.id}`);
35
35
  if (result.domain_url)
@@ -39,9 +39,9 @@ export async function create(flags) {
39
39
  }
40
40
  export async function get(id, flags) {
41
41
  const config = requireConfig();
42
- const orgId = flags.org || config.default_org;
43
- if (!orgId || !id)
44
- error("Missing required arguments.\nUsage: myapi funnel get <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
42
+ const orgId = requireOrg(flags, config, 'myapi funnel get <id> [--org <id>]');
43
+ if (!id)
44
+ error('Missing required arguments.\nUsage: myapi funnel get <id> [--org <id>]');
45
45
  const raw = await sdkFunnel.getFunnel(config.api_key, orgId, id);
46
46
  const funnel = raw.funnel ?? raw;
47
47
  const subdomain_url = raw.subdomain_url ?? funnel.subdomain_url;
@@ -64,27 +64,28 @@ export async function get(id, flags) {
64
64
  }
65
65
  export async function del(id, flags) {
66
66
  const config = requireConfig();
67
- const orgId = flags.org || config.default_org;
68
- if (!orgId || !id)
69
- error("Missing required arguments.\nUsage: myapi funnel delete <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
67
+ const orgId = requireOrg(flags, config, 'myapi funnel delete <id> [--org <id>]');
68
+ if (!id)
69
+ error('Missing required arguments.\nUsage: myapi funnel delete <id> [--org <id>]');
70
70
  await sdkFunnel.deleteFunnel(config.api_key, orgId, id);
71
71
  success(`Funnel ${id} deleted`);
72
72
  }
73
73
  export async function push(slug, flags) {
74
74
  const config = requireConfig();
75
- const orgId = flags.org || config.default_org;
76
- if (!orgId)
77
- error("Missing org. Set a default with: myapi config set-org <id>");
75
+ const orgId = requireOrg(flags, config, 'myapi funnel push [slug] [--funnel <id>] [--org <id>]');
78
76
  const rawSlug = slug || flags.slug || '/';
79
77
  const finalSlug = rawSlug.startsWith('/') ? rawSlug : `/${rawSlug}`;
80
78
  let funnelId = flags.funnel || config.default_funnel;
79
+ let resolvedFromOrg = false;
81
80
  if (!funnelId) {
82
81
  const existing = await sdkFunnel.listFunnels(config.api_key, orgId);
83
82
  if (existing.length === 0)
84
- error("No funnel found for this org. Try: myapi auth config set-org <id>");
83
+ error('No funnel found for this org. Create one with: myapi funnel create');
84
+ if (existing.length > 1) {
85
+ error(`Multiple funnels exist for this org and no default is set.\nPick one with --funnel <id>, or set a default:\n myapi config set-funnel <id>\n\nFunnels:\n${existing.map(f => ` ${f.id}`).join('\n')}`);
86
+ }
85
87
  funnelId = existing[0].id;
86
- config.default_funnel = funnelId;
87
- saveConfig(config);
88
+ resolvedFromOrg = true;
88
89
  }
89
90
  if (process.stdin.isTTY) {
90
91
  error("No content provided via stdin. Use a pipe or file:\n echo '<h1>Hello</h1>' | myapi funnel push /\n cat page.html | myapi funnel push /about");
@@ -100,6 +101,9 @@ export async function push(slug, flags) {
100
101
  error("No content provided via stdin. Usage: echo '<h1>Hello</h1>' | myapi funnel push [slug]");
101
102
  const result = await sdkFunnel.pushFunnelPage(config.api_key, orgId, funnelId, { slug: finalSlug, html });
102
103
  success(`Pushed page to ${finalSlug}`);
104
+ if (resolvedFromOrg) {
105
+ info(`(Used the org's only funnel: ${funnelId}. Set a default with: myapi config set-funnel ${funnelId})`);
106
+ }
103
107
  if (result?.url) {
104
108
  info(`Preview: ${result.url}`);
105
109
  }
@@ -112,47 +116,63 @@ export async function push(slug, flags) {
112
116
  }
113
117
  export async function verify(id, flags) {
114
118
  const config = requireConfig();
115
- const orgId = flags.org || config.default_org;
116
- if (!orgId || !id)
117
- error("Missing required arguments.\nUsage: myapi funnel verify <id> --org <id> [--slug <slug>]\n(Or set defaults via: myapi config set-org <id>)");
119
+ const orgId = requireOrg(flags, config, 'myapi funnel verify <id> [--slug <slug>] [--org <id>]');
120
+ if (!id)
121
+ error('Missing required arguments.\nUsage: myapi funnel verify <id> [--slug <slug>] [--org <id>]');
118
122
  const opts = {};
119
123
  if (flags.slug)
120
124
  opts.slug = flags.slug;
121
125
  const v = await sdkFunnel.verifyFunnel(config.api_key, orgId, id, opts);
122
126
  printJson(v);
123
127
  }
128
+ // ── Dispatcher ───────────────────────────────────────────────────────────────
129
+ const SUBCOMMAND_USAGE = {
130
+ 'list': 'myapi funnel list [--org <id>] [--json]',
131
+ 'create': 'myapi funnel create [--org <id>]',
132
+ 'get': 'myapi funnel get <id> [--org <id>] [--json]',
133
+ 'delete': 'myapi funnel delete <id> [--org <id>]',
134
+ 'push': `myapi funnel push [slug] [--funnel <id>] [--slug <path>] [--org <id>] < page.html
135
+
136
+ Reads HTML from stdin and publishes to <slug> on your funnel. Funnel is resolved
137
+ from --funnel, the default funnel, or (only if the org has exactly one) auto-picked.
138
+
139
+ Examples:
140
+ echo '<h1>Hello</h1>' | myapi funnel push /
141
+ cat about.html | myapi funnel push /about
142
+ myapi funnel push < index.html
143
+ cat p.html | myapi funnel push /pricing --funnel <uuid>`,
144
+ 'verify': 'myapi funnel verify <id> [--slug <slug>] [--org <id>]',
145
+ };
124
146
  export async function run(subcommand, args, flags) {
125
147
  if (!subcommand || (flags.help && !subcommand)) {
126
- 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\nNote: Most funnel commands require the --org <id> flag (or set a default via myapi auth config set-org <id>).');
148
+ info(`Usage: myapi funnel <subcommand>
149
+
150
+ Subcommands:
151
+ list List funnels
152
+ create Create a funnel
153
+ get <id> Get funnel details
154
+ delete Delete a funnel
155
+ push Push a raw HTML page from stdin to a slug
156
+ verify Verify a published page is reachable
157
+
158
+ All commands accept --org <id> (or set default: myapi config set-org <id>).`);
127
159
  return;
128
160
  }
129
161
  if (flags.help) {
130
- if (subcommand === 'list')
131
- info('Usage: myapi funnel list --org <id> [--json]\n\nLists all funnels (websites) in the organization.\n\nFlags:\n --org <id> Organization ID (or set default via myapi auth config set-org)\n --json Output raw JSON');
132
- else if (subcommand === 'create')
133
- info('Usage: myapi funnel create --org <id>\n\nCreates a new funnel in the organization.\n\nFlags:\n --org <id> Organization ID (or set default via myapi auth config set-org)');
134
- else if (subcommand === 'get')
135
- info('Usage: myapi funnel get <id> --org <id>\n\nFetches details of a specific funnel including its pages and settings.\n\nFlags:\n --org <id> Organization ID (or set default via myapi auth config set-org)');
136
- else if (subcommand === 'delete')
137
- info('Usage: myapi funnel delete <id> --org <id>\n\nDeletes a funnel permanently.\n\nFlags:\n --org <id> Organization ID (or set default via myapi auth config set-org)');
138
- else if (subcommand === 'push')
139
- info('Usage: myapi funnel push [slug] < page.html\n\nPublishes an HTML page from stdin to a path within your funnel (website).\nThe funnel is always resolved from your default or --funnel flag.\n\nFlags:\n --org <id> Organization ID (or set default via myapi config set-org)\n --funnel <id> Funnel ID (or set default via myapi config set-funnel)\n --slug <path> Alternative way to specify the slug\n\nExamples:\n echo \'<h1>Hello</h1>\' | myapi funnel push / # push to /\n cat about.html | myapi funnel push /about # push to /about\n myapi funnel push < index.html # push to / on default funnel\n cat p.html | myapi funnel push /pricing --funnel <uuid>');
140
- else if (subcommand === 'pull')
141
- info('Usage: myapi funnel pull [funnel_id] [slug]\n\nFetches the HTML content of a funnel page.');
162
+ const usage = SUBCOMMAND_USAGE[subcommand];
163
+ if (usage)
164
+ info(`Usage: ${usage}`);
165
+ else
166
+ info(`Unknown subcommand: ${subcommand}. Run "myapi funnel --help" for the list.`);
142
167
  return;
143
168
  }
144
- if (subcommand === 'list')
145
- await list(flags);
146
- else if (subcommand === 'create')
147
- await create(flags);
148
- else if (subcommand === 'get')
149
- await get(args[0], flags);
150
- else if (subcommand === 'delete')
151
- await del(args[0], flags);
152
- else if (subcommand === 'push')
153
- await push(args[0], flags);
154
- else if (subcommand === 'verify')
155
- await verify(args[0], flags);
156
- else
157
- error(`Unknown subcommand: ${subcommand}. Run "myapi funnel --help" for a list of valid subcommands.`);
169
+ switch (subcommand) {
170
+ case 'list': return list(flags);
171
+ case 'create': return create(flags);
172
+ case 'get': return get(args[0], flags);
173
+ case 'delete': return del(args[0], flags);
174
+ case 'push': return push(args[0], flags);
175
+ case 'verify': return verify(args[0], flags);
176
+ default: error(`Unknown subcommand: ${subcommand}. Run "myapi funnel --help" for a list of valid subcommands.`);
177
+ }
158
178
  }
@@ -61,26 +61,36 @@ export async function del(id, flags) {
61
61
  await sdkImage.deleteImage(config.api_key, orgId, id);
62
62
  success(`Image deleted! (Job ${id} history retained, URL nullified)`);
63
63
  }
64
+ // ── Dispatcher ───────────────────────────────────────────────────────────────
65
+ const SUBCOMMAND_USAGE = {
66
+ 'list': 'myapi image list [--org <id>] [--json]',
67
+ 'generate': 'myapi image generate --prompt "<text>" [--ratio <1:1|16:9>] [--style <style>] [--colors <hex_list>] [--org <id>]',
68
+ 'delete': 'myapi image delete <job_id> [--org <id>]',
69
+ };
64
70
  export async function run(subcommand, args, flags) {
65
71
  if (!subcommand || (flags.help && !subcommand)) {
66
- info('Usage: myapi image <subcommand>\n\nSubcommands:\n list List all your generated images\n generate Generate a new AI image from a prompt\n delete Delete the physical image file for a job\n\nNote: All image commands require the --org <id> flag.');
72
+ info(`Usage: myapi image <subcommand>
73
+
74
+ Subcommands:
75
+ list List all your generated images
76
+ generate Generate a new AI image from a prompt ($0.05 per generation)
77
+ delete Delete the physical image file for a job (history retained, URL nullified)
78
+
79
+ All commands accept --org <id> (or set default: myapi config set-org <id>).`);
67
80
  return;
68
81
  }
69
82
  if (flags.help) {
70
- if (subcommand === 'list')
71
- info('Usage: myapi image list --org <id> [--json]');
72
- else if (subcommand === 'generate')
73
- info('Usage: myapi image generate --prompt "<text>" [--ratio <1:1|16:9>] [--style <style>] [--colors <hex_list>] --org <id>\n\nGenerates an AI image and polls until the public URL is ready. Costs $0.05 per generation.');
74
- else if (subcommand === 'delete')
75
- info('Usage: myapi image delete <job_id> --org <id>\n\nDeletes the physical image file from storage. The generation job history is kept, but its URL will become null.');
83
+ const usage = SUBCOMMAND_USAGE[subcommand];
84
+ if (usage)
85
+ info(`Usage: ${usage}`);
86
+ else
87
+ info(`Unknown subcommand: ${subcommand}. Run "myapi image --help" for the list.`);
76
88
  return;
77
89
  }
78
- if (subcommand === 'list')
79
- await list(flags);
80
- else if (subcommand === 'generate')
81
- await generate(flags);
82
- else if (subcommand === 'delete')
83
- await del(args[0], flags);
84
- else
85
- error(`Unknown subcommand: ${subcommand}. Run "myapi image --help" for a list of valid subcommands.`);
90
+ switch (subcommand) {
91
+ case 'list': return list(flags);
92
+ case 'generate': return generate(flags);
93
+ case 'delete': return del(args[0], flags);
94
+ default: error(`Unknown subcommand: ${subcommand}. Run "myapi image --help" for a list of valid subcommands.`);
95
+ }
86
96
  }
@@ -1,3 +1,8 @@
1
- export declare function createNew(flags: Record<string, string | boolean>): Promise<void>;
2
- export declare function list(flags: Record<string, string | boolean>): Promise<void>;
3
- export declare function revoke(id: string, flags: Record<string, string | boolean>): Promise<void>;
1
+ import type { FlagSchema } from '../flags.js';
2
+ import type { Flags } from '../helpers.js';
3
+ export declare const SCHEMA: FlagSchema;
4
+ export declare function run(subcommand: string | undefined, args: string[], flags: Flags): Promise<void>;
5
+ export declare function runApiKeys(subcommand: string | undefined, args: string[], flags: Flags): Promise<void>;
6
+ export declare function createNew(flags: Flags): Promise<void>;
7
+ export declare function list(flags: Flags): Promise<void>;
8
+ export declare function revoke(id: string, flags: Flags): Promise<void>;
@@ -3,11 +3,63 @@ import { requireConfig } from '../config.js';
3
3
  import { success, error, printTable, info, printJson } from '../output.js';
4
4
  import { formatDate } from '../utils.js';
5
5
  import * as readline from 'readline';
6
- export async function createNew(flags) {
6
+ export const SCHEMA = {
7
+ name: 'string',
8
+ };
9
+ const KEYS_HEADER = `Usage: myapi keys <subcommand>
10
+
11
+ Manage programmatic API keys for your account.
12
+
13
+ Subcommands:
14
+ list List all API keys with IDs and creation dates
15
+ create Create a new API key (the key value is shown once)
16
+ revoke <id> Permanently revoke an API key by ID
17
+
18
+ Alias for: myapi auth api-keys`;
19
+ const API_KEYS_HEADER = `Usage: myapi auth api-keys <subcommand>
20
+
21
+ Manage programmatic API keys for your account.
22
+
23
+ Subcommands:
24
+ list List all API keys with IDs and creation dates
25
+ create Create a new API key (the key value is shown once)
26
+ revoke <id> Permanently revoke an API key by ID
27
+
28
+ Alias: myapi keys <subcommand>`;
29
+ function subcommandUsage(prefix) {
30
+ return {
31
+ 'list': `myapi ${prefix} list [--json]`,
32
+ 'create': `myapi ${prefix} create [--name <name>]\n\nCreates a new API key. If --name is omitted you will be prompted.`,
33
+ 'revoke': `myapi ${prefix} revoke <id>\n\nPermanently revokes an API key by ID. The key stops working immediately and the action cannot be undone.`,
34
+ };
35
+ }
36
+ async function dispatch(prefix, subcommand, args, flags) {
37
+ if (!subcommand || (flags.help && !subcommand)) {
38
+ info(prefix === 'keys' ? KEYS_HEADER : API_KEYS_HEADER);
39
+ return;
40
+ }
7
41
  if (flags.help) {
8
- info('Usage: myapi auth api-keys create [--name <name>]\n\nCreates a new API key.\n\nFlags:\n --name <name> Key name (skips prompt)');
42
+ const usage = subcommandUsage(prefix)[subcommand];
43
+ if (usage)
44
+ info(`Usage: ${usage}`);
45
+ else
46
+ info(`Unknown subcommand: ${subcommand}. Run "myapi ${prefix} --help" for the list.`);
9
47
  return;
10
48
  }
49
+ switch (subcommand) {
50
+ case 'create': return createNew(flags);
51
+ case 'list': return list(flags);
52
+ case 'revoke': return revoke(args[0], flags);
53
+ default: error(`Unknown subcommand: ${subcommand}. Run "myapi ${prefix} --help" for available subcommands.`);
54
+ }
55
+ }
56
+ export async function run(subcommand, args, flags) {
57
+ return dispatch('keys', subcommand, args, flags);
58
+ }
59
+ export async function runApiKeys(subcommand, args, flags) {
60
+ return dispatch('auth api-keys', subcommand, args, flags);
61
+ }
62
+ export async function createNew(flags) {
11
63
  const config = requireConfig();
12
64
  let name = flags.name || '';
13
65
  if (!name) {
@@ -15,46 +67,33 @@ export async function createNew(flags) {
15
67
  name = await new Promise(resolve => rl.question('Enter a name for the new key: ', resolve));
16
68
  rl.close();
17
69
  }
18
- if (!name.trim()) {
70
+ if (!name.trim())
19
71
  error('Key name cannot be empty. Use --name <name>');
20
- return;
21
- }
22
72
  const keyInfo = await hq.createApiKey(config.api_key, name.trim());
23
73
  success(`New API key created!\n\nName: ${keyInfo.prefix}...\nKey: ${keyInfo.api_key}\n\nMake sure to copy your new API key now. You won't be able to see it again!`);
24
74
  }
25
75
  export async function list(flags) {
26
- if (flags.help) {
27
- info('Usage: myapi auth api-keys list [--json]\n\nLists all API keys associated with your account.\n\nAlias: myapi keys list\n\nFlags:\n --json Output raw JSON');
28
- return;
29
- }
30
76
  const config = requireConfig();
31
77
  const keysList = await hq.listApiKeys(config.api_key);
32
78
  if (flags.json) {
33
79
  printJson(keysList);
34
80
  return;
35
81
  }
36
- const formattedKeys = keysList.map(k => {
37
- const createdStr = formatDate(k.created_at);
38
- const lastUsedStr = k.last_used_at ? formatDate(k.last_used_at) : 'Never';
39
- return {
40
- Name: k.name || 'Unnamed',
41
- Prefix: k.prefix,
42
- ID: k.id,
43
- 'Created At': createdStr,
44
- 'Last Used': lastUsedStr
45
- };
82
+ const formattedKeys = keysList.map(k => ({
83
+ Name: k.name || 'Unnamed',
84
+ Prefix: k.prefix,
85
+ ID: k.id,
86
+ 'Created At': formatDate(k.created_at),
87
+ 'Last Used': k.last_used_at ? formatDate(k.last_used_at) : 'Never',
88
+ }));
89
+ printTable(formattedKeys, {
90
+ flags,
91
+ empty: 'No API keys yet. Create one with: myapi keys create',
46
92
  });
47
- printTable(formattedKeys);
48
93
  }
49
94
  export async function revoke(id, flags) {
50
- if (flags.help) {
51
- info('Usage: myapi auth api-keys revoke <id>\n\nPermanently revokes an API key by ID. This action cannot be undone.\nThe key stops working immediately.\n\nAlias: myapi keys revoke <id>');
52
- return;
53
- }
54
- if (!id) {
55
- error("Missing key ID. Usage: myapi keys revoke <id>");
56
- return;
57
- }
95
+ if (!id)
96
+ error('Missing key ID. Usage: myapi keys revoke <id>');
58
97
  const config = requireConfig();
59
98
  await hq.revokeApiKey(config.api_key, id);
60
99
  success(`Key ${id} revoked successfully.`);
@@ -1,5 +1,9 @@
1
- export declare function create(restArgs: string[], flags: Record<string, string | boolean>): Promise<void>;
2
- export declare function list(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>;
5
- export declare function importOrg(args: string[], flags: Record<string, string | boolean>): Promise<void>;
1
+ import type { FlagSchema } from '../flags.js';
2
+ import { type Flags } from '../helpers.js';
3
+ export declare const SCHEMA: FlagSchema;
4
+ export declare function create(restArgs: string[], flags: Flags): Promise<void>;
5
+ export declare function list(flags: Flags): Promise<void>;
6
+ export declare function get(id: string, flags: Flags): Promise<void>;
7
+ export declare function del(id: string, _flags: Flags): Promise<void>;
8
+ export declare function importOrg(args: string[], flags: Flags): Promise<void>;
9
+ export declare function run(subcommand: string | undefined, args: string[], flags: Flags): Promise<void>;
@@ -3,16 +3,20 @@ import { hq, funnel as sdkFunnel } from '@myapihq/sdk';
3
3
  import { requireConfig, saveConfig } from '../config.js';
4
4
  import { success, error, printTable, printJson, info } from '../output.js';
5
5
  import { sleep, formatDate } from '../utils.js';
6
+ import { requireOrg } from '../helpers.js';
7
+ export const SCHEMA = {
8
+ name: 'string',
9
+ tagline: 'string',
10
+ description: 'string',
11
+ 'business-sector': 'string',
12
+ 'logo-url': 'string',
13
+ org: 'string',
14
+ };
15
+ const SYNC_BRAND_TIMEOUT_MS = 5 * 60 * 1000;
6
16
  export async function create(restArgs, flags) {
7
- if (flags.help) {
8
- info('Usage: myapi org create <name> [options]\n myapi org create --name <name> [options]\n\nCreates a new organization. A funnel (website) is automatically created alongside it.\n\nOptions:\n --name Organization name (alternative to positional argument)\n --tagline Short tagline\n --description Detailed description\n --business-sector Sector (e.g. Technology)\n --logo-url URL to logo image\n --yes Skip the "set as default?" prompt (useful in CI / agent workflows)\n --json Output raw JSON (non-interactive, skips prompts)\n\nExamples:\n myapi org create "Acme Inc"\n myapi org create "Acme Inc" --yes\n myapi org create --name "Acme Inc" --yes');
9
- return;
10
- }
11
17
  const name = flags.name || restArgs[0];
12
- if (!name) {
13
- error("Missing org name. Usage: myapi org create \"My Company\" [--yes]");
14
- return;
15
- }
18
+ if (!name)
19
+ error('Missing org name. Usage: myapi org create "My Company" [--yes]');
16
20
  const config = requireConfig();
17
21
  const payload = { name };
18
22
  if (flags.tagline)
@@ -32,7 +36,7 @@ export async function create(restArgs, flags) {
32
36
  }
33
37
  const setDefault = flags.yes || await new Promise(resolve => {
34
38
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
35
- rl.question(`› Set as default org and funnel? (Y/n) `, ans => {
39
+ rl.question('› Set as default org and funnel? (Y/n) ', ans => {
36
40
  rl.close();
37
41
  resolve(ans.trim().toLowerCase() !== 'n');
38
42
  });
@@ -59,10 +63,6 @@ export async function create(restArgs, flags) {
59
63
  }
60
64
  }
61
65
  export async function list(flags) {
62
- if (flags.help) {
63
- info('Usage: myapi org list [--json]\n\nLists all organizations in your account.\n\nFlags:\n --json Output raw JSON');
64
- return;
65
- }
66
66
  const config = requireConfig();
67
67
  const orgs = await hq.listOrgs(config.api_key);
68
68
  if (flags.json) {
@@ -83,19 +83,16 @@ export async function list(flags) {
83
83
  name: o.id === config.default_org ? `${o.name} *` : o.name,
84
84
  created_at: o.created_at ? formatDate(o.created_at) : '',
85
85
  }));
86
- printTable(rows);
86
+ printTable(rows, {
87
+ flags,
88
+ empty: 'No organizations found. Create one with: myapi org create "My Company"',
89
+ });
87
90
  }
88
91
  export async function get(id, flags) {
89
- if (flags.help) {
90
- info('Usage: myapi org get <id> [--json]\n\nFetches details of a specific organization.\n\nFlags:\n --json Output raw JSON');
91
- return;
92
- }
93
92
  const config = requireConfig();
94
93
  const resolvedId = id || config.default_org;
95
- if (!resolvedId) {
96
- error("Missing org id. Usage: myapi org get <id>\n(Or set a default: myapi config set-org <id>)");
97
- return;
98
- }
94
+ if (!resolvedId)
95
+ error('Missing org id. Usage: myapi org get <id>\n(Or set a default: myapi config set-org <id>)');
99
96
  const org = await hq.getOrg(config.api_key, resolvedId);
100
97
  if (flags.json) {
101
98
  printJson(org);
@@ -110,49 +107,105 @@ export async function get(id, flags) {
110
107
  if (org.preview_subdomain)
111
108
  info(`Preview: https://${org.preview_subdomain}.makeautonomous.com`);
112
109
  }
113
- export async function del(id, flags) {
114
- if (flags.help) {
115
- info('Usage: myapi org delete <id>\n\nPermanently deletes an organization and its associated funnels.\nNote: any registered domains assigned to this org must be unassigned first.\n\nNo confirmation prompt is shown — this action is immediate.');
116
- return;
117
- }
118
- if (!id) {
119
- error("Missing org id. Usage: myapi org delete <id>");
120
- return;
121
- }
110
+ export async function del(id, _flags) {
111
+ if (!id)
112
+ error('Missing org id. Usage: myapi org delete <id>');
122
113
  const config = requireConfig();
123
114
  await hq.deleteOrg(config.api_key, id);
124
115
  success(`Org ${id} deleted`);
125
116
  }
126
117
  export async function importOrg(args, flags) {
127
- if (flags.help) {
128
- info('Usage: myapi org sync-brand <domain> --org <id>\n\nFetches an existing website and extracts brand signals (name, logo, description,\nbusiness sector) to enrich your organization profile automatically.\n\nThis does NOT register or transfer the domain — it only reads from the site.\nThe org must already exist before running this command.\n\nPrerequisite:\n myapi org create --name "My Brand" --yes\n\nExample:\n myapi org sync-brand example.com --org <id>');
129
- return;
130
- }
131
118
  const config = requireConfig();
132
119
  const domain = args[0] || config.default_domain;
133
- const orgId = flags.org || config.default_org;
134
- if (!domain || !orgId) {
135
- error("Missing required arguments.\nUsage: myapi org import <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
136
- return;
137
- }
120
+ const orgId = requireOrg(flags, config, 'myapi org sync-brand <domain> [--org <id>]');
121
+ if (!domain)
122
+ error('Missing required arguments.\nUsage: myapi org sync-brand <domain> [--org <id>]\n(Or set default: myapi config set-domain <domain>)');
138
123
  const result = await hq.importOrg(config.api_key, orgId, domain);
139
124
  const importId = result.job_id;
140
- process.stdout.write("Importing ");
125
+ process.stdout.write('Importing ');
141
126
  const chars = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
142
127
  let i = 0;
143
- while (true) {
128
+ let elapsed = 0;
129
+ while (elapsed < SYNC_BRAND_TIMEOUT_MS) {
144
130
  const status = await hq.getOrgImportStatus(config.api_key, importId);
145
131
  if (status.status === 'awaiting_confirm') {
146
132
  process.stdout.write('\r\x1b[K');
147
- break;
133
+ const org = await hq.confirmOrgImport(config.api_key, importId);
134
+ success(`Import complete! Org ID: ${org.id}`);
135
+ return;
148
136
  }
149
137
  if (status.status === 'failed') {
150
138
  process.stdout.write('\r\x1b[K');
151
- error("Import failed");
139
+ error('Import failed');
152
140
  }
153
141
  process.stdout.write(`\rImporting ${chars[i++ % chars.length]}`);
154
142
  await sleep(3000);
143
+ elapsed += 3000;
144
+ }
145
+ process.stdout.write('\r\x1b[K');
146
+ error(`Import timed out after ${SYNC_BRAND_TIMEOUT_MS / 1000}s. The job may still complete in the background — re-run "myapi org sync-brand" to retry.`);
147
+ }
148
+ // ── Dispatcher ───────────────────────────────────────────────────────────────
149
+ const SUBCOMMAND_USAGE = {
150
+ 'list': 'myapi org list [--json]',
151
+ 'create': `myapi org create <name> [--tagline <str>] [--description <str>] [--business-sector <str>] [--logo-url <url>] [--yes] [--json]
152
+ myapi org create --name <name> [...]
153
+
154
+ Creates a new organization. A funnel (website) is automatically created alongside it.
155
+ Pass --yes to skip the "set as default?" prompt (useful in CI / agent workflows).
156
+
157
+ Examples:
158
+ myapi org create "Acme Inc"
159
+ myapi org create "Acme Inc" --yes
160
+ myapi org create --name "Acme Inc" --yes`,
161
+ 'get': 'myapi org get <id> [--json]',
162
+ 'delete': `myapi org delete <id>
163
+
164
+ Permanently deletes an organization and its associated funnels.
165
+ Any registered domains assigned to this org must be unassigned first.
166
+ No confirmation prompt — the action is immediate.`,
167
+ 'sync-brand': `myapi org sync-brand <domain> [--org <id>]
168
+
169
+ Fetches an existing website and extracts brand signals (name, logo, description,
170
+ business sector) to enrich your organization profile.
171
+
172
+ Does NOT register or transfer the domain — it only reads from the site.
173
+ The org must already exist. Polls for up to 5 minutes.
174
+
175
+ Example:
176
+ myapi org create --name "My Brand" --yes
177
+ myapi org sync-brand example.com --org <id>`,
178
+ };
179
+ export async function run(subcommand, args, flags) {
180
+ if (!subcommand || (flags.help && !subcommand)) {
181
+ info(`Usage: myapi org <subcommand>
182
+
183
+ Subcommands:
184
+ list List organizations
185
+ create Create an organization (e.g. myapi org create "Name" --yes)
186
+ get Get details of an organization
187
+ delete Delete an organization
188
+ sync-brand Sync brand info (name, logo, description) from an existing website`);
189
+ return;
190
+ }
191
+ if (flags.help) {
192
+ const lookup = subcommand === 'import' ? 'sync-brand' : subcommand;
193
+ const usage = SUBCOMMAND_USAGE[lookup];
194
+ if (usage)
195
+ info(`Usage: ${usage}`);
196
+ else
197
+ info(`Unknown subcommand: ${subcommand}. Run "myapi org --help" for the list.`);
198
+ return;
199
+ }
200
+ switch (subcommand) {
201
+ case 'list': return list(flags);
202
+ case 'create': return create(args, flags);
203
+ case 'get': return get(args[0], flags);
204
+ case 'delete': return del(args[0], flags);
205
+ case 'sync-brand': return importOrg(args, flags);
206
+ case 'import':
207
+ process.stderr.write('› Note: "org import" is deprecated — use "org sync-brand" instead.\n');
208
+ return importOrg(args, flags);
209
+ default: error(`Unknown subcommand: ${subcommand}. Run "myapi org --help" for available subcommands.`);
155
210
  }
156
- const org = await hq.confirmOrgImport(config.api_key, importId);
157
- success(`Import complete! Org ID: ${org.id}`);
158
211
  }