@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.
- package/dist/commands/billing.js +26 -32
- package/dist/commands/config.js +20 -26
- package/dist/commands/domain.js +56 -67
- package/dist/commands/email.js +75 -88
- package/dist/commands/funnel.js +43 -52
- package/dist/commands/image.js +17 -21
- package/dist/commands/keys.js +22 -60
- package/dist/commands/org.js +37 -44
- package/dist/commands/setup.js +13 -49
- package/dist/commands/storage.js +18 -23
- package/dist/commands/url.d.ts +2 -0
- package/dist/commands/url.js +29 -0
- package/dist/commands/webhook.d.ts +2 -0
- package/dist/commands/webhook.js +64 -24
- package/dist/commands/workflow.d.ts +1 -0
- package/dist/commands/workflow.js +81 -43
- package/dist/config.js +6 -44
- package/dist/index.js +41 -56
- package/dist/output.js +5 -12
- package/dist/utils.js +2 -6
- package/package.json +5 -2
- package/src/commands/url.ts +28 -0
- package/src/commands/webhook.ts +50 -9
- package/src/commands/workflow.ts +55 -18
- package/src/index.ts +23 -0
package/dist/commands/webhook.js
CHANGED
|
@@ -1,28 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { webhook as sdkWebhook } 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 webhook list --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
9
|
+
const endpoints = await sdkWebhook.listEndpoints(config.api_key, orgId);
|
|
10
|
+
if (flags.json)
|
|
11
|
+
printJson(endpoints);
|
|
12
|
+
else
|
|
13
|
+
printTable(endpoints);
|
|
13
14
|
}
|
|
14
|
-
async function create(flags) {
|
|
15
|
-
|
|
16
|
-
|
|
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 description = flags.description;
|
|
20
|
+
if (!orgId || !name) {
|
|
21
|
+
error("Missing required arguments.\nUsage: myapi webhook create --name <name> [--description <desc>] --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
17
22
|
}
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
(0, output_js_1.success)(`Webhook created! ID: ${res.id}\nInbound URL: ${res.inbound_url}`);
|
|
23
|
+
const res = await sdkWebhook.createEndpoint(config.api_key, orgId, name, description);
|
|
24
|
+
success(`Webhook created! ID: ${res.id}\nInbound URL: ${res.inbound_url}`);
|
|
21
25
|
}
|
|
22
|
-
async function del(id, flags) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
export async function del(id, flags) {
|
|
27
|
+
const config = requireConfig();
|
|
28
|
+
const orgId = flags.org || config.default_org;
|
|
29
|
+
if (!orgId || !id)
|
|
30
|
+
error("Missing required arguments.\nUsage: myapi webhook delete <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
31
|
+
await sdkWebhook.deleteEndpoint(config.api_key, orgId, id);
|
|
32
|
+
success(`Webhook ${id} deleted`);
|
|
33
|
+
}
|
|
34
|
+
export async function delivery(id, flags) {
|
|
35
|
+
const config = requireConfig();
|
|
36
|
+
const orgId = flags.org || config.default_org;
|
|
37
|
+
if (!orgId || !id)
|
|
38
|
+
error("Missing required arguments.\nUsage: myapi webhook delivery <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
39
|
+
const res = await sdkWebhook.getDelivery(config.api_key, orgId, id);
|
|
40
|
+
printJson(res);
|
|
41
|
+
}
|
|
42
|
+
export async function run(subcommand, args, flags) {
|
|
43
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
44
|
+
info('Usage: myapi webhook <subcommand>\n\nSubcommands:\n list List all inbound webhook endpoints\n create Create a new endpoint to receive data (returns an inbound URL)\n delete Delete a webhook endpoint\n delivery Inspect a specific webhook delivery (headers, payload, status)\n\nNote: All webhook commands require the --org <id> flag.');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (flags.help) {
|
|
48
|
+
if (subcommand === 'list')
|
|
49
|
+
info('Usage: myapi webhook list --org <id> [--json]\n\nLists all webhook endpoints for the organization, including their IDs and inbound slugs.');
|
|
50
|
+
else if (subcommand === 'create')
|
|
51
|
+
info('Usage: myapi webhook create --name <name> [--description <desc>] --org <id>\n\nCreates a new inbound webhook endpoint. Returns the unique inbound URL to give to third parties.');
|
|
52
|
+
else if (subcommand === 'delete')
|
|
53
|
+
info('Usage: myapi webhook delete <id> --org <id>\n\nPermanently deletes the specified webhook endpoint.');
|
|
54
|
+
else if (subcommand === 'delivery')
|
|
55
|
+
info('Usage: myapi webhook delivery <delivery_id> --org <id>\n\nRetrieves the exact HTTP headers, JSON payload, and processing status of a specific received webhook. Useful for debugging inbound data.');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (subcommand === 'list')
|
|
59
|
+
await list(flags);
|
|
60
|
+
else if (subcommand === 'create')
|
|
61
|
+
await create(flags);
|
|
62
|
+
else if (subcommand === 'delete')
|
|
63
|
+
await del(args[0], flags);
|
|
64
|
+
else if (subcommand === 'delivery')
|
|
65
|
+
await delivery(args[0], flags);
|
|
66
|
+
else
|
|
67
|
+
error(`Unknown subcommand: ${subcommand}. Run "myapi webhook --help" for a list of valid subcommands.`);
|
|
28
68
|
}
|
|
@@ -3,3 +3,4 @@ export declare function create(flags: Record<string, string | boolean>): Promise
|
|
|
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
5
|
export declare function runs(id: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
6
|
+
export declare function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>): Promise<void>;
|
|
@@ -1,57 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
18
|
-
|
|
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
|
-
|
|
28
|
+
error("Invalid JSON for --steps");
|
|
27
29
|
}
|
|
28
|
-
const wf = await
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
35
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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(`Workflow ${id} disabled`);
|
|
50
53
|
}
|
|
51
|
-
async function runs(id, flags) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
(
|
|
54
|
+
export async function runs(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 runs <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
59
|
+
const wRuns = await sdkWorkflow.listWorkflowRuns(config.api_key, orgId, id);
|
|
60
|
+
if (flags.json)
|
|
61
|
+
printJson(wRuns);
|
|
62
|
+
else
|
|
63
|
+
printTable(wRuns);
|
|
64
|
+
}
|
|
65
|
+
export async function run(subcommand, args, flags) {
|
|
66
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
67
|
+
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.');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (flags.help) {
|
|
71
|
+
if (subcommand === 'list')
|
|
72
|
+
info('Usage: myapi workflow list --org <id> [--json]\n\nLists all workflows in your organization, showing their ID, name, status, and attached webhook endpoint.');
|
|
73
|
+
else if (subcommand === 'create')
|
|
74
|
+
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}}"}]\'');
|
|
75
|
+
else if (subcommand === 'enable')
|
|
76
|
+
info('Usage: myapi workflow enable <id> --org <id>\n\nActivates a disabled workflow so it begins listening to its webhook trigger again.');
|
|
77
|
+
else if (subcommand === 'disable')
|
|
78
|
+
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.');
|
|
79
|
+
else if (subcommand === 'runs')
|
|
80
|
+
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.');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (subcommand === 'list')
|
|
84
|
+
await list(flags);
|
|
85
|
+
else if (subcommand === 'create')
|
|
86
|
+
await create(flags);
|
|
87
|
+
else if (subcommand === 'enable')
|
|
88
|
+
await enable(args[0], flags);
|
|
89
|
+
else if (subcommand === 'disable')
|
|
90
|
+
await disable(args[0], flags);
|
|
91
|
+
else if (subcommand === 'runs')
|
|
92
|
+
await runs(args[0], flags);
|
|
93
|
+
else
|
|
94
|
+
error(`Unknown subcommand: ${subcommand}. Run "myapi workflow --help" for a list of valid subcommands.`);
|
|
57
95
|
}
|
package/dist/config.js
CHANGED
|
@@ -1,47 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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() {
|
|
45
7
|
try {
|
|
46
8
|
if (!fs.existsSync(CONFIG_FILE)) {
|
|
47
9
|
return null;
|
|
@@ -53,13 +15,13 @@ function loadConfig() {
|
|
|
53
15
|
return null;
|
|
54
16
|
}
|
|
55
17
|
}
|
|
56
|
-
function saveConfig(config) {
|
|
18
|
+
export function saveConfig(config) {
|
|
57
19
|
if (!fs.existsSync(CONFIG_DIR)) {
|
|
58
20
|
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
59
21
|
}
|
|
60
22
|
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
61
23
|
}
|
|
62
|
-
function requireConfig() {
|
|
24
|
+
export function requireConfig() {
|
|
63
25
|
const config = loadConfig();
|
|
64
26
|
if (!config || !config.api_key) {
|
|
65
27
|
console.error("No API key found. Run: myapi account create");
|
package/dist/index.js
CHANGED
|
@@ -1,52 +1,25 @@
|
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
3
|
+
import { parseArgs } from './utils.js';
|
|
4
|
+
import { error, info } from './output.js';
|
|
5
|
+
import { MyApiError } from '@myapihq/sdk';
|
|
6
|
+
import updateNotifier from 'update-notifier';
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
const pkgPath = new URL('../package.json', import.meta.url);
|
|
9
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
10
|
+
import * as keysCmd from './commands/keys.js';
|
|
11
|
+
import * as billingCmd from './commands/billing.js';
|
|
12
|
+
import * as orgCmd from './commands/org.js';
|
|
13
|
+
import * as setupCmd from './commands/setup.js';
|
|
14
|
+
import * as configCmd from './commands/config.js';
|
|
15
|
+
import * as domainCmd from './commands/domain.js';
|
|
16
|
+
import * as funnelCmd from './commands/funnel.js';
|
|
17
|
+
import * as urlCmd from './commands/url.js';
|
|
18
|
+
import * as webhookCmd from './commands/webhook.js';
|
|
19
|
+
import * as workflowCmd from './commands/workflow.js';
|
|
48
20
|
async function main() {
|
|
49
|
-
|
|
21
|
+
updateNotifier({ pkg }).notify();
|
|
22
|
+
const { args, flags } = parseArgs(process.argv.slice(2));
|
|
50
23
|
if (args.length === 0) {
|
|
51
24
|
printHelp();
|
|
52
25
|
process.exit(0);
|
|
@@ -56,14 +29,14 @@ async function main() {
|
|
|
56
29
|
switch (command) {
|
|
57
30
|
case 'setup':
|
|
58
31
|
if (flags.help) {
|
|
59
|
-
|
|
32
|
+
info('Usage: myapi setup\n\nSetup CLI credentials and view integration instructions');
|
|
60
33
|
break;
|
|
61
34
|
}
|
|
62
35
|
await setupCmd.setup();
|
|
63
36
|
break;
|
|
64
37
|
case 'keys':
|
|
65
38
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
66
|
-
|
|
39
|
+
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
40
|
break;
|
|
68
41
|
}
|
|
69
42
|
if (subcommand === 'create')
|
|
@@ -77,7 +50,7 @@ async function main() {
|
|
|
77
50
|
break;
|
|
78
51
|
case 'org':
|
|
79
52
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
80
|
-
|
|
53
|
+
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
54
|
break;
|
|
82
55
|
}
|
|
83
56
|
if (subcommand === 'list')
|
|
@@ -95,7 +68,7 @@ async function main() {
|
|
|
95
68
|
break;
|
|
96
69
|
case 'billing':
|
|
97
70
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
98
|
-
|
|
71
|
+
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
72
|
break;
|
|
100
73
|
}
|
|
101
74
|
if (subcommand === 'balance')
|
|
@@ -118,23 +91,32 @@ async function main() {
|
|
|
118
91
|
case 'funnel':
|
|
119
92
|
await funnelCmd.run(subcommand, restArgs, flags);
|
|
120
93
|
break;
|
|
94
|
+
case 'url':
|
|
95
|
+
await urlCmd.run(subcommand, restArgs, flags);
|
|
96
|
+
break;
|
|
97
|
+
case 'webhook':
|
|
98
|
+
await webhookCmd.run(subcommand, restArgs, flags);
|
|
99
|
+
break;
|
|
100
|
+
case 'workflow':
|
|
101
|
+
await workflowCmd.run(subcommand, restArgs, flags);
|
|
102
|
+
break;
|
|
121
103
|
default:
|
|
122
104
|
printHelp();
|
|
123
105
|
process.exit(0);
|
|
124
106
|
}
|
|
125
107
|
}
|
|
126
108
|
catch (err) {
|
|
127
|
-
if (err instanceof
|
|
109
|
+
if (err instanceof MyApiError) {
|
|
128
110
|
if (err.status === 402)
|
|
129
|
-
|
|
111
|
+
error('Insufficient balance. Run: myapi billing topup <amount>');
|
|
130
112
|
else if (err.status === 401)
|
|
131
|
-
|
|
113
|
+
error('Invalid API key. Run: myapi setup');
|
|
132
114
|
}
|
|
133
|
-
|
|
115
|
+
error(err.message || String(err));
|
|
134
116
|
}
|
|
135
117
|
}
|
|
136
118
|
function printHelp() {
|
|
137
|
-
|
|
119
|
+
info(`myapi - MyAPI command-line interface
|
|
138
120
|
|
|
139
121
|
Usage: myapi <command> [subcommand] [args]
|
|
140
122
|
|
|
@@ -146,7 +128,10 @@ Commands:
|
|
|
146
128
|
config Manage CLI defaults like org_id and domain
|
|
147
129
|
domain Manage domain configurations
|
|
148
130
|
funnel Manage headless funnels and pages
|
|
131
|
+
url Shorten URLs and manage links
|
|
132
|
+
webhook Manage inbound webhooks
|
|
133
|
+
workflow Manage workflow automations
|
|
149
134
|
|
|
150
135
|
Run "myapi <command> --help" for subcommand help.`);
|
|
151
136
|
}
|
|
152
|
-
main().catch(err => {
|
|
137
|
+
main().catch(err => { error(err.message || String(err)); });
|
package/dist/output.js
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "1.0.17",
|
|
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,12 @@
|
|
|
11
12
|
"dev": "tsc --watch"
|
|
12
13
|
},
|
|
13
14
|
"dependencies": {
|
|
14
|
-
"@myapihq/sdk": "*"
|
|
15
|
+
"@myapihq/sdk": "*",
|
|
16
|
+
"update-notifier": "^7.3.1"
|
|
15
17
|
},
|
|
16
18
|
"devDependencies": {
|
|
17
19
|
"@types/node": "^25.6.0",
|
|
20
|
+
"@types/update-notifier": "^6.0.8",
|
|
18
21
|
"typescript": "^5.4.0"
|
|
19
22
|
}
|
|
20
23
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { url as sdkUrl } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, info, printJson } from '../output.js';
|
|
4
|
+
|
|
5
|
+
export async function shorten(targetUrl: string, flags: Record<string, string | boolean>) {
|
|
6
|
+
const config = requireConfig();
|
|
7
|
+
const orgId = (flags.org as string) || config.default_org;
|
|
8
|
+
if (!orgId || !targetUrl) error("Missing required arguments.\nUsage: myapi url shorten <url> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
9
|
+
|
|
10
|
+
const res = await sdkUrl.shortenUrl(config.api_key, orgId, targetUrl);
|
|
11
|
+
if (flags.json) printJson(res);
|
|
12
|
+
else success(`Shortened URL: ${res.short_url}\nCode: ${res.short_code}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>) {
|
|
16
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
17
|
+
info('Usage: myapi url <subcommand>\n\nSubcommands:\n shorten Shorten a long URL\n\nNote: All url commands require the --org <id> flag.');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (flags.help) {
|
|
22
|
+
if (subcommand === 'shorten') info('Usage: myapi url shorten <url> --org <id> [--json]\n\nShortens a long URL and returns the compact myurlto.com link.');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (subcommand === 'shorten') await shorten(args[0], flags);
|
|
27
|
+
else error(`Unknown subcommand: ${subcommand}. Run "myapi url --help" for a list of valid subcommands.`);
|
|
28
|
+
}
|
package/src/commands/webhook.ts
CHANGED
|
@@ -1,25 +1,66 @@
|
|
|
1
1
|
import { webhook as sdkWebhook } 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
|
|
8
|
-
|
|
7
|
+
const orgId = (flags.org as string) || config.default_org;
|
|
8
|
+
if (!orgId) error("Missing required arguments.\nUsage: myapi webhook list --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
9
|
+
|
|
10
|
+
const endpoints = await sdkWebhook.listEndpoints(config.api_key, orgId);
|
|
11
|
+
if (flags.json) printJson(endpoints);
|
|
12
|
+
else printTable(endpoints 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.description) {
|
|
13
|
-
error("Missing --org-id, --name, or --description flags");
|
|
14
|
-
}
|
|
15
16
|
const config = requireConfig();
|
|
16
|
-
const
|
|
17
|
+
const orgId = (flags.org as string) || config.default_org;
|
|
18
|
+
const name = flags.name as string;
|
|
19
|
+
const description = flags.description as string;
|
|
20
|
+
|
|
21
|
+
if (!orgId || !name) {
|
|
22
|
+
error("Missing required arguments.\nUsage: myapi webhook create --name <name> [--description <desc>] --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const res = await sdkWebhook.createEndpoint(config.api_key, orgId, name, description);
|
|
17
26
|
success(`Webhook created! ID: ${res.id}\nInbound URL: ${res.inbound_url}`);
|
|
18
27
|
}
|
|
19
28
|
|
|
20
29
|
export async function del(id: string, flags: Record<string, string | boolean>) {
|
|
21
|
-
if (!id) error("Missing id");
|
|
22
30
|
const config = requireConfig();
|
|
23
|
-
|
|
31
|
+
const orgId = (flags.org as string) || config.default_org;
|
|
32
|
+
if (!orgId || !id) error("Missing required arguments.\nUsage: myapi webhook delete <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
33
|
+
|
|
34
|
+
await sdkWebhook.deleteEndpoint(config.api_key, orgId, id);
|
|
24
35
|
success(`Webhook ${id} deleted`);
|
|
25
36
|
}
|
|
37
|
+
|
|
38
|
+
export async function delivery(id: string, flags: Record<string, string | boolean>) {
|
|
39
|
+
const config = requireConfig();
|
|
40
|
+
const orgId = (flags.org as string) || config.default_org;
|
|
41
|
+
if (!orgId || !id) error("Missing required arguments.\nUsage: myapi webhook delivery <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
42
|
+
|
|
43
|
+
const res = await sdkWebhook.getDelivery(config.api_key, orgId, id);
|
|
44
|
+
printJson(res);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>) {
|
|
48
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
49
|
+
info('Usage: myapi webhook <subcommand>\n\nSubcommands:\n list List all inbound webhook endpoints\n create Create a new endpoint to receive data (returns an inbound URL)\n delete Delete a webhook endpoint\n delivery Inspect a specific webhook delivery (headers, payload, status)\n\nNote: All webhook commands require the --org <id> flag.');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (flags.help) {
|
|
54
|
+
if (subcommand === 'list') info('Usage: myapi webhook list --org <id> [--json]\n\nLists all webhook endpoints for the organization, including their IDs and inbound slugs.');
|
|
55
|
+
else if (subcommand === 'create') info('Usage: myapi webhook create --name <name> [--description <desc>] --org <id>\n\nCreates a new inbound webhook endpoint. Returns the unique inbound URL to give to third parties.');
|
|
56
|
+
else if (subcommand === 'delete') info('Usage: myapi webhook delete <id> --org <id>\n\nPermanently deletes the specified webhook endpoint.');
|
|
57
|
+
else if (subcommand === 'delivery') info('Usage: myapi webhook delivery <delivery_id> --org <id>\n\nRetrieves the exact HTTP headers, JSON payload, and processing status of a specific received webhook. Useful for debugging inbound data.');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (subcommand === 'list') await list(flags);
|
|
62
|
+
else if (subcommand === 'create') await create(flags);
|
|
63
|
+
else if (subcommand === 'delete') await del(args[0], flags);
|
|
64
|
+
else if (subcommand === 'delivery') await delivery(args[0], flags);
|
|
65
|
+
else error(`Unknown subcommand: ${subcommand}. Run "myapi webhook --help" for a list of valid subcommands.`);
|
|
66
|
+
}
|