@myapihq/cli 1.0.16 → 1.0.18

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.
@@ -2,4 +2,6 @@ export declare function list(flags: Record<string, string | boolean>): Promise<v
2
2
  export declare function create(flags: Record<string, string | boolean>): Promise<void>;
3
3
  export declare function enable(id: string, flags: Record<string, string | boolean>): Promise<void>;
4
4
  export declare function disable(id: string, flags: Record<string, string | boolean>): Promise<void>;
5
+ export declare function del(id: string, flags: Record<string, string | boolean>): Promise<void>;
5
6
  export declare function runs(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,57 +1,107 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.list = list;
4
- exports.create = create;
5
- exports.enable = enable;
6
- exports.disable = disable;
7
- exports.runs = runs;
8
- const sdk_1 = require("@myapihq/sdk");
9
- const config_js_1 = require("../config.js");
10
- const output_js_1 = require("../output.js");
11
- async function list(flags) {
12
- const config = (0, config_js_1.requireConfig)();
13
- const workflows = await sdk_1.workflow.listWorkflows(config.api_key);
14
- (0, output_js_1.printTable)(workflows);
1
+ import { workflow as sdkWorkflow } from '@myapihq/sdk';
2
+ import { requireConfig } from '../config.js';
3
+ import { success, error, printTable, info, printJson } from '../output.js';
4
+ export async function list(flags) {
5
+ const config = requireConfig();
6
+ const orgId = flags.org || config.default_org;
7
+ if (!orgId)
8
+ error("Missing required arguments.\nUsage: myapi workflow list --org <id>\n(Or set defaults via: myapi config set-org <id>)");
9
+ const workflows = await sdkWorkflow.listWorkflows(config.api_key, orgId);
10
+ if (flags.json)
11
+ printJson(workflows);
12
+ else
13
+ printTable(workflows);
15
14
  }
16
- async function create(flags) {
17
- if (!flags['org-id'] || !flags.name || !flags['endpoint-id'] || !flags.steps) {
18
- (0, output_js_1.error)("Missing --org-id, --name, --endpoint-id, or --steps flags");
15
+ export async function create(flags) {
16
+ const config = requireConfig();
17
+ const orgId = flags.org || config.default_org;
18
+ const name = flags.name;
19
+ const endpointId = flags['endpoint-id'];
20
+ if (!orgId || !name || !endpointId || !flags.steps) {
21
+ error("Missing required arguments.\nUsage: myapi workflow create --name <name> --endpoint-id <id> --steps <json> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
19
22
  }
20
- const config = (0, config_js_1.requireConfig)();
21
23
  let steps;
22
24
  try {
23
25
  steps = JSON.parse(flags.steps);
24
26
  }
25
27
  catch (err) {
26
- (0, output_js_1.error)("Invalid JSON for --steps");
28
+ error("Invalid JSON for --steps");
27
29
  }
28
- const wf = await sdk_1.workflow.createWorkflow(config.api_key, {
29
- org_id: flags['org-id'],
30
- name: flags.name,
31
- trigger_config: { endpoint_id: flags['endpoint-id'] },
30
+ const wf = await sdkWorkflow.createWorkflow(config.api_key, orgId, {
31
+ name,
32
+ trigger_config: { endpoint_id: endpointId },
32
33
  steps
33
34
  });
34
- await sdk_1.workflow.enableWorkflow(config.api_key, wf.id);
35
- (0, output_js_1.success)(`Workflow created and enabled! ID: ${wf.id}`);
35
+ await sdkWorkflow.enableWorkflow(config.api_key, orgId, wf.id);
36
+ success(`Workflow created and enabled! ID: ${wf.id}`);
36
37
  }
37
- async function enable(id, flags) {
38
- if (!id)
39
- (0, output_js_1.error)("Missing id");
40
- const config = (0, config_js_1.requireConfig)();
41
- await sdk_1.workflow.enableWorkflow(config.api_key, id);
42
- (0, output_js_1.success)(`Workflow ${id} enabled`);
38
+ export async function enable(id, flags) {
39
+ const config = requireConfig();
40
+ const orgId = flags.org || config.default_org;
41
+ if (!orgId || !id)
42
+ error("Missing required arguments.\nUsage: myapi workflow enable <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
43
+ await sdkWorkflow.enableWorkflow(config.api_key, orgId, id);
44
+ success(`Workflow ${id} enabled`);
43
45
  }
44
- async function disable(id, flags) {
45
- if (!id)
46
- (0, output_js_1.error)("Missing id");
47
- const config = (0, config_js_1.requireConfig)();
48
- await sdk_1.workflow.disableWorkflow(config.api_key, id);
49
- (0, output_js_1.success)(`Workflow ${id} disabled`);
46
+ export async function disable(id, flags) {
47
+ const config = requireConfig();
48
+ const orgId = flags.org || config.default_org;
49
+ if (!orgId || !id)
50
+ error("Missing required arguments.\nUsage: myapi workflow disable <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
51
+ await sdkWorkflow.disableWorkflow(config.api_key, orgId, id);
52
+ success(`Disabled workflow ${id}`);
50
53
  }
51
- async function runs(id, flags) {
52
- if (!id)
53
- (0, output_js_1.error)("Missing id");
54
- const config = (0, config_js_1.requireConfig)();
55
- const runs = await sdk_1.workflow.listWorkflowRuns(config.api_key, id);
56
- (0, output_js_1.printTable)(runs);
54
+ export async function del(id, flags) {
55
+ const config = requireConfig();
56
+ const orgId = flags.org || config.default_org;
57
+ if (!orgId || !id)
58
+ error("Missing required arguments.\nUsage: myapi workflow delete <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
59
+ await sdkWorkflow.deleteWorkflow(config.api_key, orgId, id);
60
+ success(`Deleted workflow ${id}`);
61
+ }
62
+ export async function runs(id, flags) {
63
+ const config = requireConfig();
64
+ const orgId = flags.org || config.default_org;
65
+ if (!orgId || !id)
66
+ error("Missing required arguments.\nUsage: myapi workflow runs <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
67
+ const wRuns = await sdkWorkflow.listWorkflowRuns(config.api_key, orgId, id);
68
+ if (flags.json)
69
+ printJson(wRuns);
70
+ else
71
+ printTable(wRuns);
72
+ }
73
+ export async function run(subcommand, args, flags) {
74
+ if (!subcommand || (flags.help && !subcommand)) {
75
+ info('Usage: myapi workflow <subcommand>\n\nSubcommands:\n list List all workflows\n create Create and enable a new workflow\n enable Enable a workflow\n disable Disable a workflow\n delete Delete a workflow\n runs List recent executions (runs) of a workflow\n\nNote: All workflow commands require the --org <id> flag.');
76
+ return;
77
+ }
78
+ if (flags.help) {
79
+ if (subcommand === 'list')
80
+ info('Usage: myapi workflow list --org <id> [--json]\n\nLists all workflows in your organization, showing their ID, name, status, and attached webhook endpoint.');
81
+ else if (subcommand === 'create')
82
+ info('Usage: myapi workflow create --name <name> --endpoint-id <id> --steps <json_array> --org <id>\n\nCreates a new webhook-triggered workflow and immediately enables it.\n\nArguments:\n --name A friendly name for your workflow.\n --endpoint-id The UUID of the my-webhook-api endpoint that will trigger this workflow.\n --steps A raw JSON array defining the actions to take when triggered.\n\nExample Steps Payload:\n \'[{"type": "send_email", "from": "hello@example.com", "to": "{{payload.user.email}}", "subject": "Welcome!", "template_id": "abc-123"}]\n \'[{"type": "slack_message", "webhook_url": "https://hooks.slack.com/...", "text": "New lead: {{payload.name}}"}]\'');
83
+ else if (subcommand === 'enable')
84
+ info('Usage: myapi workflow enable <id> --org <id>\n\nActivates a disabled workflow so it begins listening to its webhook trigger again.');
85
+ else if (subcommand === 'disable')
86
+ info('Usage: myapi workflow disable <id> --org <id>\n\nPauses a workflow. The attached webhook will still accept data, but the workflow steps will not execute.');
87
+ else if (subcommand === 'delete')
88
+ info('Usage: myapi workflow delete <id> --org <id>\n\nDeletes the workflow permanently.');
89
+ else if (subcommand === 'runs')
90
+ info('Usage: myapi workflow runs <workflow_id> --org <id> [--json]\n\nLists the 100 most recent executions of the specified workflow, including completion status and any error messages.');
91
+ return;
92
+ }
93
+ if (subcommand === 'list')
94
+ await list(flags);
95
+ else if (subcommand === 'create')
96
+ await create(flags);
97
+ else if (subcommand === 'enable')
98
+ await enable(args[0], flags);
99
+ else if (subcommand === 'disable')
100
+ await disable(args[0], flags);
101
+ else if (subcommand === 'delete')
102
+ await del(args[0], flags);
103
+ else if (subcommand === 'runs')
104
+ await runs(args[0], flags);
105
+ else
106
+ error(`Unknown subcommand: ${subcommand}. Run "myapi workflow --help" for a list of valid subcommands.`);
57
107
  }
package/dist/config.d.ts CHANGED
@@ -4,6 +4,7 @@ export interface Config {
4
4
  pin: string;
5
5
  default_org?: string;
6
6
  default_domain?: string;
7
+ autocomplete_setup?: boolean;
7
8
  }
8
9
  export declare function loadConfig(): Config | null;
9
10
  export declare function saveConfig(config: Config): void;
package/dist/config.js CHANGED
@@ -1,68 +1,38 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.loadConfig = loadConfig;
37
- exports.saveConfig = saveConfig;
38
- exports.requireConfig = requireConfig;
39
- const fs = __importStar(require("fs"));
40
- const path = __importStar(require("path"));
41
- const os = __importStar(require("os"));
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import * as os from 'os';
42
4
  const CONFIG_DIR = path.join(os.homedir(), '.myapi');
43
5
  const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
44
- function loadConfig() {
6
+ export function loadConfig() {
7
+ let fileConfig = {};
45
8
  try {
46
- if (!fs.existsSync(CONFIG_FILE)) {
47
- return null;
9
+ if (fs.existsSync(CONFIG_FILE)) {
10
+ const data = fs.readFileSync(CONFIG_FILE, 'utf-8');
11
+ fileConfig = JSON.parse(data);
48
12
  }
49
- const data = fs.readFileSync(CONFIG_FILE, 'utf-8');
50
- return JSON.parse(data);
51
13
  }
52
14
  catch (err) {
15
+ // Ignore read errors
16
+ }
17
+ const envKey = process.env.MYAPI_KEY;
18
+ if (envKey) {
19
+ fileConfig.api_key = envKey;
20
+ }
21
+ if (Object.keys(fileConfig).length === 0) {
53
22
  return null;
54
23
  }
24
+ return fileConfig;
55
25
  }
56
- function saveConfig(config) {
26
+ export function saveConfig(config) {
57
27
  if (!fs.existsSync(CONFIG_DIR)) {
58
28
  fs.mkdirSync(CONFIG_DIR, { recursive: true });
59
29
  }
60
30
  fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
61
31
  }
62
- function requireConfig() {
32
+ export function requireConfig() {
63
33
  const config = loadConfig();
64
34
  if (!config || !config.api_key) {
65
- console.error("No API key found. Run: myapi account create");
35
+ console.error("No API key found. Provide MYAPI_KEY env var or run: myapi setup");
66
36
  process.exit(1);
67
37
  }
68
38
  return config;
package/dist/index.js CHANGED
@@ -1,52 +1,46 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
2
  // AUTO-GENERATED by scripts/generate-indexes.js — do not edit manually
38
- const utils_js_1 = require("./utils.js");
39
- const output_js_1 = require("./output.js");
40
- const sdk_1 = require("@myapihq/sdk");
41
- const keysCmd = __importStar(require("./commands/keys.js"));
42
- const billingCmd = __importStar(require("./commands/billing.js"));
43
- const orgCmd = __importStar(require("./commands/org.js"));
44
- const setupCmd = __importStar(require("./commands/setup.js"));
45
- const configCmd = __importStar(require("./commands/config.js"));
46
- const domainCmd = __importStar(require("./commands/domain.js"));
47
- const funnelCmd = __importStar(require("./commands/funnel.js"));
3
+ import { parseArgs } from './utils.js';
4
+ import { error, info, success } from './output.js';
5
+ import { loadConfig, saveConfig } from './config.js';
6
+ import { MyApiError } from '@myapihq/sdk';
7
+ import updateNotifier from 'update-notifier';
8
+ import omelette from 'omelette';
9
+ import * as fs from 'fs';
10
+ const pkgPath = new URL('../package.json', import.meta.url);
11
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
12
+ import * as keysCmd from './commands/keys.js';
13
+ import * as billingCmd from './commands/billing.js';
14
+ import * as orgCmd from './commands/org.js';
15
+ import * as setupCmd from './commands/setup.js';
16
+ import * as configCmd from './commands/config.js';
17
+ import * as domainCmd from './commands/domain.js';
18
+ import * as funnelCmd from './commands/funnel.js';
19
+ import * as imageCmd from './commands/image.js';
20
+ import * as storageCmd from './commands/storage.js';
21
+ import * as urlCmd from './commands/url.js';
22
+ import * as webhookCmd from './commands/webhook.js';
23
+ import * as workflowCmd from './commands/workflow.js';
48
24
  async function main() {
49
- const { args, flags } = (0, utils_js_1.parseArgs)(process.argv.slice(2));
25
+ const completion = omelette('myapi');
26
+ completion.on('myapi', ({ reply }) => {
27
+ reply(['keys', 'billing', 'org', 'setup', 'config', 'domain', 'funnel', 'image', 'storage', 'url', 'webhook', 'workflow', 'autocomplete']);
28
+ });
29
+ completion.init();
30
+ const config = loadConfig();
31
+ if (config && !config.autocomplete_setup) {
32
+ try {
33
+ completion.setupShellInitFile();
34
+ config.autocomplete_setup = true;
35
+ saveConfig(config);
36
+ info('✨ Autocomplete has been auto-configured! Restart your terminal (or run: source ~/.bashrc) to use it.');
37
+ }
38
+ catch (e) {
39
+ // Ignore if we can't write to shell profiles
40
+ }
41
+ }
42
+ updateNotifier({ pkg }).notify();
43
+ const { args, flags } = parseArgs(process.argv.slice(2));
50
44
  if (args.length === 0) {
51
45
  printHelp();
52
46
  process.exit(0);
@@ -54,16 +48,20 @@ async function main() {
54
48
  const [command, subcommand, ...restArgs] = args;
55
49
  try {
56
50
  switch (command) {
51
+ case 'autocomplete':
52
+ completion.setupShellInitFile();
53
+ success('Autocomplete successfully configured! Please restart your terminal or run: source ~/.bashrc (or ~/.zshrc)');
54
+ break;
57
55
  case 'setup':
58
56
  if (flags.help) {
59
- (0, output_js_1.info)('Usage: myapi setup\n\nSetup CLI credentials and view integration instructions');
57
+ info('Usage: myapi setup\n\nSetup CLI credentials and view integration instructions');
60
58
  break;
61
59
  }
62
60
  await setupCmd.setup();
63
61
  break;
64
62
  case 'keys':
65
63
  if (!subcommand || (flags.help && !subcommand)) {
66
- (0, output_js_1.info)('Usage: myapi keys <subcommand>\n\nSubcommands:\n list List your API keys\n create Create a new API key\n revoke Revoke an API key (e.g. myapi keys revoke <id>)');
64
+ info('Usage: myapi keys <subcommand>\n\nSubcommands:\n list List your API keys\n create Create a new API key\n revoke Revoke an API key (e.g. myapi keys revoke <id>)');
67
65
  break;
68
66
  }
69
67
  if (subcommand === 'create')
@@ -77,7 +75,7 @@ async function main() {
77
75
  break;
78
76
  case 'org':
79
77
  if (!subcommand || (flags.help && !subcommand)) {
80
- (0, output_js_1.info)('Usage: myapi org <subcommand>\n\nSubcommands:\n list List organizations\n create Create an organization\n get Get details of an organization\n delete Delete an organization\n import Extract org from domain');
78
+ info('Usage: myapi org <subcommand>\n\nSubcommands:\n list List organizations\n create Create an organization\n get Get details of an organization\n delete Delete an organization\n import Extract org from domain');
81
79
  break;
82
80
  }
83
81
  if (subcommand === 'list')
@@ -95,7 +93,7 @@ async function main() {
95
93
  break;
96
94
  case 'billing':
97
95
  if (!subcommand || (flags.help && !subcommand)) {
98
- (0, output_js_1.info)('Usage: myapi billing <subcommand>\n\nSubcommands:\n balance Check balance\n history View billing history\n topup Top up your balance\n setup Setup a payment method');
96
+ info('Usage: myapi billing <subcommand>\n\nSubcommands:\n balance Check balance\n history View billing history\n topup Top up your balance\n setup Setup a payment method');
99
97
  break;
100
98
  }
101
99
  if (subcommand === 'balance')
@@ -118,27 +116,43 @@ async function main() {
118
116
  case 'funnel':
119
117
  await funnelCmd.run(subcommand, restArgs, flags);
120
118
  break;
119
+ case 'image':
120
+ await imageCmd.run(subcommand, restArgs, flags);
121
+ break;
122
+ case 'storage':
123
+ await storageCmd.run(subcommand, restArgs, flags);
124
+ break;
125
+ case 'url':
126
+ await urlCmd.run(subcommand, restArgs, flags);
127
+ break;
128
+ case 'webhook':
129
+ await webhookCmd.run(subcommand, restArgs, flags);
130
+ break;
131
+ case 'workflow':
132
+ await workflowCmd.run(subcommand, restArgs, flags);
133
+ break;
121
134
  default:
122
135
  printHelp();
123
136
  process.exit(0);
124
137
  }
125
138
  }
126
139
  catch (err) {
127
- if (err instanceof sdk_1.MyApiError) {
140
+ if (err instanceof MyApiError) {
128
141
  if (err.status === 402)
129
- (0, output_js_1.error)('Insufficient balance. Run: myapi billing topup <amount>');
142
+ error('Insufficient balance. Run: myapi billing topup <amount>');
130
143
  else if (err.status === 401)
131
- (0, output_js_1.error)('Invalid API key. Run: myapi setup');
144
+ error('Invalid API key. Run: myapi setup');
132
145
  }
133
- (0, output_js_1.error)(err.message || String(err));
146
+ error(err.message || String(err));
134
147
  }
135
148
  }
136
149
  function printHelp() {
137
- (0, output_js_1.info)(`myapi - MyAPI command-line interface
150
+ info(`myapi - MyAPI command-line interface
138
151
 
139
152
  Usage: myapi <command> [subcommand] [args]
140
153
 
141
154
  Commands:
155
+ autocomplete Autocomplete setup for bash/zsh
142
156
  keys Manage API keys
143
157
  billing Check balance and manage billing
144
158
  org Manage organizations
@@ -146,7 +160,12 @@ Commands:
146
160
  config Manage CLI defaults like org_id and domain
147
161
  domain Manage domain configurations
148
162
  funnel Manage headless funnels and pages
163
+ image Generate AI images
164
+ storage Manage static assets
165
+ url Shorten URLs and manage links
166
+ webhook Manage inbound webhooks
167
+ workflow Manage workflow automations
149
168
 
150
169
  Run "myapi <command> --help" for subcommand help.`);
151
170
  }
152
- main().catch(err => { (0, output_js_1.error)(err.message || String(err)); });
171
+ main().catch(err => { error(err.message || String(err)); });
package/dist/output.js CHANGED
@@ -1,24 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.success = success;
4
- exports.error = error;
5
- exports.info = info;
6
- exports.printJson = printJson;
7
- exports.printTable = printTable;
8
- function success(message) {
1
+ export function success(message) {
9
2
  console.log(`\x1b[32m✓\x1b[0m ${message}`);
10
3
  }
11
- function error(message) {
4
+ export function error(message) {
12
5
  console.error(`\x1b[31m✗\x1b[0m ${message}`);
13
6
  process.exit(1);
14
7
  }
15
- function info(message) {
8
+ export function info(message) {
16
9
  console.log(message);
17
10
  }
18
- function printJson(data) {
11
+ export function printJson(data) {
19
12
  console.log(JSON.stringify(data, null, 2));
20
13
  }
21
- function printTable(rows) {
14
+ export function printTable(rows) {
22
15
  if (process.argv.includes('--json')) {
23
16
  printJson(rows);
24
17
  return;
package/dist/utils.js CHANGED
@@ -1,8 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseArgs = parseArgs;
4
- exports.sleep = sleep;
5
- function parseArgs(argv) {
1
+ export function parseArgs(argv) {
6
2
  const args = [];
7
3
  const flags = {};
8
4
  for (let i = 0; i < argv.length; i++) {
@@ -29,6 +25,6 @@ function parseArgs(argv) {
29
25
  }
30
26
  return { args, flags };
31
27
  }
32
- function sleep(ms) {
28
+ export function sleep(ms) {
33
29
  return new Promise(resolve => setTimeout(resolve, ms));
34
30
  }
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@myapihq/cli",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "MyAPI command-line interface",
5
+ "type": "module",
5
6
  "main": "dist/index.js",
6
7
  "bin": {
7
8
  "myapi": "dist/index.js"
@@ -11,10 +12,14 @@
11
12
  "dev": "tsc --watch"
12
13
  },
13
14
  "dependencies": {
14
- "@myapihq/sdk": "*"
15
+ "@myapihq/sdk": "*",
16
+ "omelette": "^0.4.17",
17
+ "update-notifier": "^7.3.1"
15
18
  },
16
19
  "devDependencies": {
17
20
  "@types/node": "^25.6.0",
21
+ "@types/omelette": "^0.4.5",
22
+ "@types/update-notifier": "^6.0.8",
18
23
  "typescript": "^5.4.0"
19
24
  }
20
25
  }
@@ -80,13 +80,21 @@ export async function outbox(address: string, flags: Record<string, string | boo
80
80
  const messages = await sdkEmail.getOutbox(config.api_key, orgId, address);
81
81
  printTable(messages as unknown as Record<string, unknown>[]);
82
82
  }
83
-
84
83
  export async function listTemplates(flags: Record<string, string | boolean>) {
85
84
  const config = requireConfig();
86
85
  const orgId = (flags.org as string) || config.default_org;
87
- if (!orgId) error("Missing required arguments.\nUsage: myapi email list-templates --org <id>\n(Or set a default org via: myapi config set-org <id>)");
86
+ if (!orgId) error("Missing required arguments.\nUsage: myapi email list-templates --org <id>\n(Or set defaults via: myapi config set-org <id>)");
88
87
  const templates = await sdkEmail.listTemplates(config.api_key, orgId);
89
- printTable(templates as unknown as Record<string, unknown>[]);
88
+ if (flags.json) printJson(templates);
89
+ else printTable(templates as unknown as Record<string, unknown>[]);
90
+ }
91
+
92
+ export async function deleteTemplate(id: string, flags: Record<string, string | boolean>) {
93
+ const config = requireConfig();
94
+ const orgId = (flags.org as string) || config.default_org;
95
+ if (!orgId || !id) error("Missing required arguments.\nUsage: myapi email delete-template <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
96
+ await sdkEmail.deleteTemplate(config.api_key, orgId, id);
97
+ success(`Deleted template ${id}`);
90
98
  }
91
99
 
92
100
  export async function generateTemplate(flags: Record<string, string | boolean>) {
@@ -143,7 +151,7 @@ export async function campaignStats(id: string, flags: Record<string, string | b
143
151
 
144
152
  export async function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>) {
145
153
  if (!subcommand || (flags.help && !subcommand)) {
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.');
154
+ 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 delete-template Delete a template\n list-campaigns List campaigns\n campaign-stats Get campaign stats\n\nNote: All email commands require the --org <id> flag.');
147
155
  return;
148
156
  }
149
157
 
@@ -156,6 +164,7 @@ export async function run(subcommand: string | undefined, args: string[], flags:
156
164
  else if (subcommand === 'outbox') info('Usage: myapi email outbox <address> --org <id>');
157
165
  else if (subcommand === 'list-templates') info('Usage: myapi email list-templates --org <id>');
158
166
  else if (subcommand === 'generate-template') info('Usage: myapi email generate-template --org <id> --prompt <str> --name <str>');
167
+ else if (subcommand === 'delete-template') info('Usage: myapi email delete-template <id> --org <id>');
159
168
  else if (subcommand === 'list-campaigns') info('Usage: myapi email list-campaigns --org <id>');
160
169
  else if (subcommand === 'campaign-stats') info('Usage: myapi email campaign-stats <campaign_id> --org <id>');
161
170
  return;
@@ -169,6 +178,7 @@ export async function run(subcommand: string | undefined, args: string[], flags:
169
178
  else if (subcommand === 'outbox') await outbox(args[0], flags);
170
179
  else if (subcommand === 'list-templates') await listTemplates(flags);
171
180
  else if (subcommand === 'generate-template') await generateTemplate(flags);
181
+ else if (subcommand === 'delete-template') await deleteTemplate(args[0], flags);
172
182
  else if (subcommand === 'list-campaigns') await listCampaigns(flags);
173
183
  else if (subcommand === 'campaign-stats') await campaignStats(args[0], flags);
174
184
  else error(`Unknown subcommand: ${subcommand}. Run "myapi email --help" for a list of valid subcommands.`);