@myapihq/cli 1.0.16 → 1.0.17

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.
@@ -1,18 +1,26 @@
1
1
  import { workflow as sdkWorkflow } 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
 
5
5
  export async function list(flags: Record<string, string | boolean>) {
6
6
  const config = requireConfig();
7
- const workflows = await sdkWorkflow.listWorkflows(config.api_key);
8
- printTable(workflows as unknown as Record<string, unknown>[]);
7
+ const orgId = (flags.org as string) || config.default_org;
8
+ if (!orgId) error("Missing required arguments.\nUsage: myapi workflow list --org <id>\n(Or set defaults via: myapi config set-org <id>)");
9
+
10
+ const workflows = await sdkWorkflow.listWorkflows(config.api_key, orgId);
11
+ if (flags.json) printJson(workflows);
12
+ else printTable(workflows as unknown as Record<string, unknown>[]);
9
13
  }
10
14
 
11
15
  export async function create(flags: Record<string, string | boolean>) {
12
- if (!flags['org-id'] || !flags.name || !flags['endpoint-id'] || !flags.steps) {
13
- error("Missing --org-id, --name, --endpoint-id, or --steps flags");
14
- }
15
16
  const config = requireConfig();
17
+ const orgId = (flags.org as string) || config.default_org;
18
+ const name = flags.name as string;
19
+ const endpointId = flags['endpoint-id'] as string;
20
+
21
+ if (!orgId || !name || !endpointId || !flags.steps) {
22
+ 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>)");
23
+ }
16
24
 
17
25
  let steps;
18
26
  try {
@@ -21,34 +29,63 @@ export async function create(flags: Record<string, string | boolean>) {
21
29
  error("Invalid JSON for --steps");
22
30
  }
23
31
 
24
- const wf = await sdkWorkflow.createWorkflow(config.api_key, {
25
- org_id: flags['org-id'] as string,
26
- name: flags.name as string,
27
- trigger_config: { endpoint_id: flags['endpoint-id'] as string },
32
+ const wf = await sdkWorkflow.createWorkflow(config.api_key, orgId, {
33
+ name,
34
+ trigger_config: { endpoint_id: endpointId },
28
35
  steps
29
36
  });
30
37
 
31
- await sdkWorkflow.enableWorkflow(config.api_key, wf.id);
38
+ await sdkWorkflow.enableWorkflow(config.api_key, orgId, wf.id);
32
39
  success(`Workflow created and enabled! ID: ${wf.id}`);
33
40
  }
34
41
 
35
42
  export async function enable(id: string, flags: Record<string, string | boolean>) {
36
- if (!id) error("Missing id");
37
43
  const config = requireConfig();
38
- await sdkWorkflow.enableWorkflow(config.api_key, id);
44
+ const orgId = (flags.org as string) || config.default_org;
45
+ if (!orgId || !id) error("Missing required arguments.\nUsage: myapi workflow enable <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
46
+
47
+ await sdkWorkflow.enableWorkflow(config.api_key, orgId, id);
39
48
  success(`Workflow ${id} enabled`);
40
49
  }
41
50
 
42
51
  export async function disable(id: string, flags: Record<string, string | boolean>) {
43
- if (!id) error("Missing id");
44
52
  const config = requireConfig();
45
- await sdkWorkflow.disableWorkflow(config.api_key, id);
53
+ const orgId = (flags.org as string) || config.default_org;
54
+ if (!orgId || !id) error("Missing required arguments.\nUsage: myapi workflow disable <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
55
+
56
+ await sdkWorkflow.disableWorkflow(config.api_key, orgId, id);
46
57
  success(`Workflow ${id} disabled`);
47
58
  }
48
59
 
49
60
  export async function runs(id: string, flags: Record<string, string | boolean>) {
50
- if (!id) error("Missing id");
51
61
  const config = requireConfig();
52
- const runs = await sdkWorkflow.listWorkflowRuns(config.api_key, id);
53
- printTable(runs as unknown as Record<string, unknown>[]);
62
+ const orgId = (flags.org as string) || config.default_org;
63
+ if (!orgId || !id) error("Missing required arguments.\nUsage: myapi workflow runs <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
64
+
65
+ const wRuns = await sdkWorkflow.listWorkflowRuns(config.api_key, orgId, id);
66
+ if (flags.json) printJson(wRuns);
67
+ else printTable(wRuns as unknown as Record<string, unknown>[]);
68
+ }
69
+
70
+ export async function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>) {
71
+ if (!subcommand || (flags.help && !subcommand)) {
72
+ 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 runs List recent executions (runs) of a workflow\n\nNote: All workflow commands require the --org <id> flag.');
73
+ return;
74
+ }
75
+
76
+ if (flags.help) {
77
+ if (subcommand === 'list') info('Usage: myapi workflow list --org <id> [--json]\n\nLists all workflows in your organization, showing their ID, name, status, and attached webhook endpoint.');
78
+ else if (subcommand === 'create') 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}}"}]\'');
79
+ else if (subcommand === 'enable') info('Usage: myapi workflow enable <id> --org <id>\n\nActivates a disabled workflow so it begins listening to its webhook trigger again.');
80
+ else if (subcommand === 'disable') 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.');
81
+ else if (subcommand === 'runs') 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.');
82
+ return;
83
+ }
84
+
85
+ if (subcommand === 'list') await list(flags);
86
+ else if (subcommand === 'create') await create(flags);
87
+ else if (subcommand === 'enable') await enable(args[0], flags);
88
+ else if (subcommand === 'disable') await disable(args[0], flags);
89
+ else if (subcommand === 'runs') await runs(args[0], flags);
90
+ else error(`Unknown subcommand: ${subcommand}. Run "myapi workflow --help" for a list of valid subcommands.`);
54
91
  }
package/src/index.ts CHANGED
@@ -3,6 +3,12 @@
3
3
  import { parseArgs } from './utils.js';
4
4
  import { error, info } from './output.js';
5
5
  import { MyApiError } from '@myapihq/sdk';
6
+ import updateNotifier from 'update-notifier';
7
+ import * as fs from 'fs';
8
+ import * as path from 'path';
9
+
10
+ const pkgPath = new URL('../package.json', import.meta.url);
11
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
6
12
  import * as keysCmd from './commands/keys.js';
7
13
  import * as billingCmd from './commands/billing.js';
8
14
  import * as orgCmd from './commands/org.js';
@@ -10,8 +16,13 @@ import * as setupCmd from './commands/setup.js';
10
16
  import * as configCmd from './commands/config.js';
11
17
  import * as domainCmd from './commands/domain.js';
12
18
  import * as funnelCmd from './commands/funnel.js';
19
+ import * as urlCmd from './commands/url.js';
20
+ import * as webhookCmd from './commands/webhook.js';
21
+ import * as workflowCmd from './commands/workflow.js';
13
22
 
14
23
  async function main() {
24
+ updateNotifier({ pkg }).notify();
25
+
15
26
  const { args, flags } = parseArgs(process.argv.slice(2));
16
27
  if (args.length === 0) { printHelp(); process.exit(0); }
17
28
  const [command, subcommand, ...restArgs] = args;
@@ -66,6 +77,15 @@ async function main() {
66
77
  case 'funnel':
67
78
  await funnelCmd.run(subcommand, restArgs, flags);
68
79
  break;
80
+ case 'url':
81
+ await urlCmd.run(subcommand, restArgs, flags);
82
+ break;
83
+ case 'webhook':
84
+ await webhookCmd.run(subcommand, restArgs, flags);
85
+ break;
86
+ case 'workflow':
87
+ await workflowCmd.run(subcommand, restArgs, flags);
88
+ break;
69
89
  default:
70
90
  printHelp();
71
91
  process.exit(0);
@@ -92,6 +112,9 @@ Commands:
92
112
  config Manage CLI defaults like org_id and domain
93
113
  domain Manage domain configurations
94
114
  funnel Manage headless funnels and pages
115
+ url Shorten URLs and manage links
116
+ webhook Manage inbound webhooks
117
+ workflow Manage workflow automations
95
118
 
96
119
  Run "myapi <command> --help" for subcommand help.`);
97
120
  }