@myapihq/cli 1.0.15 → 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.d.ts +2 -0
- package/dist/commands/email.js +107 -72
- package/dist/commands/funnel.d.ts +0 -3
- package/dist/commands/funnel.js +43 -91
- 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 +45 -55
- package/dist/output.js +5 -12
- package/dist/utils.js +2 -6
- package/package.json +5 -2
- package/src/commands/billing.ts +1 -1
- package/src/commands/email.ts +48 -8
- package/src/commands/funnel.ts +3 -33
- 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 +28 -0
package/dist/commands/org.js
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.del = del;
|
|
7
|
-
exports.importOrg = importOrg;
|
|
8
|
-
const sdk_1 = require("@myapihq/sdk");
|
|
9
|
-
const config_js_1 = require("../config.js");
|
|
10
|
-
const output_js_1 = require("../output.js");
|
|
11
|
-
const utils_js_1 = require("../utils.js");
|
|
12
|
-
async function create(flags) {
|
|
1
|
+
import { hq } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printJson, info } from '../output.js';
|
|
4
|
+
import { sleep } from '../utils.js';
|
|
5
|
+
export async function create(flags) {
|
|
13
6
|
if (flags.help) {
|
|
14
|
-
|
|
7
|
+
info('Usage: myapi org create --name="My Org" [options]\n\nOptions:\n --name Organization name (required)\n --tagline Short tagline\n --description Detailed description\n --business-sector Sector (e.g. Technology)\n --logo-url URL to logo image');
|
|
15
8
|
return;
|
|
16
9
|
}
|
|
17
10
|
if (!flags.name) {
|
|
18
|
-
|
|
11
|
+
error("Missing --name flag. Run 'myapi org create --help' for details.");
|
|
19
12
|
return;
|
|
20
13
|
}
|
|
21
|
-
const config =
|
|
14
|
+
const config = requireConfig();
|
|
22
15
|
const payload = { name: flags.name };
|
|
23
16
|
if (flags.tagline)
|
|
24
17
|
payload.tagline = flags.tagline;
|
|
@@ -28,74 +21,74 @@ async function create(flags) {
|
|
|
28
21
|
payload.business_sector = flags['business-sector'];
|
|
29
22
|
if (flags['logo-url'])
|
|
30
23
|
payload.logo_url = flags['logo-url'];
|
|
31
|
-
const org = await
|
|
32
|
-
|
|
24
|
+
const org = await hq.createOrg(config.api_key, payload);
|
|
25
|
+
success(`Org created! ID: ${org.id}, Name: ${org.name}`);
|
|
33
26
|
}
|
|
34
|
-
async function list(flags) {
|
|
27
|
+
export async function list(flags) {
|
|
35
28
|
if (flags.help) {
|
|
36
|
-
|
|
29
|
+
info('Usage: myapi org list\n\nLists all organizations in your account as JSON.');
|
|
37
30
|
return;
|
|
38
31
|
}
|
|
39
|
-
const config =
|
|
40
|
-
const orgs = await
|
|
41
|
-
|
|
32
|
+
const config = requireConfig();
|
|
33
|
+
const orgs = await hq.listOrgs(config.api_key);
|
|
34
|
+
printJson(orgs);
|
|
42
35
|
}
|
|
43
|
-
async function get(id, flags) {
|
|
36
|
+
export async function get(id, flags) {
|
|
44
37
|
if (flags.help) {
|
|
45
|
-
|
|
38
|
+
info('Usage: myapi org get <id>\n\nFetches details of a specific organization.');
|
|
46
39
|
return;
|
|
47
40
|
}
|
|
48
41
|
if (!id) {
|
|
49
|
-
|
|
42
|
+
error("Missing org id. Usage: myapi org get <id>");
|
|
50
43
|
return;
|
|
51
44
|
}
|
|
52
|
-
const config =
|
|
53
|
-
const org = await
|
|
54
|
-
|
|
45
|
+
const config = requireConfig();
|
|
46
|
+
const org = await hq.getOrg(config.api_key, id);
|
|
47
|
+
printJson(org);
|
|
55
48
|
}
|
|
56
|
-
async function del(id, flags) {
|
|
49
|
+
export async function del(id, flags) {
|
|
57
50
|
if (flags.help) {
|
|
58
|
-
|
|
51
|
+
info('Usage: myapi org delete <id>\n\nDeletes an organization.');
|
|
59
52
|
return;
|
|
60
53
|
}
|
|
61
54
|
if (!id) {
|
|
62
|
-
|
|
55
|
+
error("Missing org id. Usage: myapi org delete <id>");
|
|
63
56
|
return;
|
|
64
57
|
}
|
|
65
|
-
const config =
|
|
66
|
-
await
|
|
67
|
-
|
|
58
|
+
const config = requireConfig();
|
|
59
|
+
await hq.deleteOrg(config.api_key, id);
|
|
60
|
+
success(`Org ${id} deleted`);
|
|
68
61
|
}
|
|
69
|
-
async function importOrg(args, flags) {
|
|
62
|
+
export async function importOrg(args, flags) {
|
|
70
63
|
if (flags.help) {
|
|
71
|
-
|
|
64
|
+
info('Usage: myapi org import <domain> --org <id>\n\nAutomatically extracts brand info from an existing website and updates the organization.\n\nNote: You must create a placeholder organization first using `myapi org create` to get an org_id.');
|
|
72
65
|
return;
|
|
73
66
|
}
|
|
74
|
-
const config =
|
|
67
|
+
const config = requireConfig();
|
|
75
68
|
const domain = args[0] || config.default_domain;
|
|
76
69
|
const orgId = flags.org || config.default_org;
|
|
77
70
|
if (!domain || !orgId) {
|
|
78
|
-
|
|
71
|
+
error("Missing required arguments.\nUsage: myapi org import <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
|
|
79
72
|
return;
|
|
80
73
|
}
|
|
81
|
-
const result = await
|
|
74
|
+
const result = await hq.importOrg(config.api_key, orgId, domain);
|
|
82
75
|
const importId = result.job_id;
|
|
83
76
|
process.stdout.write("Importing ");
|
|
84
77
|
const chars = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
85
78
|
let i = 0;
|
|
86
79
|
while (true) {
|
|
87
|
-
const status = await
|
|
80
|
+
const status = await hq.getOrgImportStatus(config.api_key, importId);
|
|
88
81
|
if (status.status === 'awaiting_confirm') {
|
|
89
82
|
process.stdout.write('\r\x1b[K');
|
|
90
83
|
break;
|
|
91
84
|
}
|
|
92
85
|
if (status.status === 'failed') {
|
|
93
86
|
process.stdout.write('\r\x1b[K');
|
|
94
|
-
|
|
87
|
+
error("Import failed");
|
|
95
88
|
}
|
|
96
89
|
process.stdout.write(`\rImporting ${chars[i++ % chars.length]}`);
|
|
97
|
-
await
|
|
90
|
+
await sleep(3000);
|
|
98
91
|
}
|
|
99
|
-
const org = await
|
|
100
|
-
|
|
92
|
+
const org = await hq.confirmOrgImport(config.api_key, importId);
|
|
93
|
+
success(`Import complete! Org ID: ${org.id}`);
|
|
101
94
|
}
|
package/dist/commands/setup.js
CHANGED
|
@@ -1,42 +1,6 @@
|
|
|
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.setup = setup;
|
|
37
|
-
const config_js_1 = require("../config.js");
|
|
38
|
-
const output_js_1 = require("../output.js");
|
|
39
|
-
const readline = __importStar(require("readline"));
|
|
1
|
+
import { loadConfig, saveConfig } from '../config.js';
|
|
2
|
+
import { success, info } from '../output.js';
|
|
3
|
+
import * as readline from 'readline';
|
|
40
4
|
function ask(rl, q) {
|
|
41
5
|
return new Promise(resolve => rl.question(q, resolve));
|
|
42
6
|
}
|
|
@@ -48,29 +12,29 @@ function yn(answer, defaultYes = true) {
|
|
|
48
12
|
}
|
|
49
13
|
async function getKey(rl) {
|
|
50
14
|
const key = await ask(rl, 'Paste your API key (get it from https://myapihq.com): ');
|
|
51
|
-
|
|
52
|
-
|
|
15
|
+
saveConfig({ api_key: key.trim(), account_id: '', pin: '' });
|
|
16
|
+
success('API key saved to ~/.myapi/config.json');
|
|
53
17
|
return key.trim();
|
|
54
18
|
}
|
|
55
|
-
async function setup() {
|
|
56
|
-
|
|
19
|
+
export async function setup() {
|
|
20
|
+
info('MyAPI Setup\n');
|
|
57
21
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
58
|
-
const existing =
|
|
22
|
+
const existing = loadConfig();
|
|
59
23
|
if (existing?.api_key) {
|
|
60
24
|
const reuse = await ask(rl, `Found existing account (${existing.account_id || existing.api_key.slice(0, 20) + '...'}). Use it? [Y/n]: `);
|
|
61
25
|
if (!yn(reuse, true)) {
|
|
62
26
|
await getKey(rl);
|
|
63
27
|
}
|
|
64
28
|
else {
|
|
65
|
-
|
|
29
|
+
info('Using existing credentials.');
|
|
66
30
|
}
|
|
67
31
|
}
|
|
68
32
|
else {
|
|
69
33
|
await getKey(rl);
|
|
70
34
|
}
|
|
71
35
|
rl.close();
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
36
|
+
info('\nTo integrate MyAPI with AI agents (Claude, Cursor, Copilot, etc.),');
|
|
37
|
+
info('please follow the instructions in our skills repository:');
|
|
38
|
+
info('https://github.com/myapihq/agent-skills\n');
|
|
39
|
+
success('Setup complete! Try: myapi billing balance');
|
|
76
40
|
}
|
package/dist/commands/storage.js
CHANGED
|
@@ -1,36 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.ingest = ingest;
|
|
5
|
-
exports.del = del;
|
|
6
|
-
const sdk_1 = require("@myapihq/sdk");
|
|
7
|
-
const config_js_1 = require("../config.js");
|
|
8
|
-
const output_js_1 = require("../output.js");
|
|
1
|
+
import { storage as sdkStorage } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable } from '../output.js';
|
|
9
4
|
function getOrgId(flags, config) {
|
|
10
5
|
const orgId = flags.org || config.org_id;
|
|
11
6
|
if (!orgId)
|
|
12
|
-
|
|
7
|
+
error("Missing org-id. Pass --org or set it in config.");
|
|
13
8
|
return orgId;
|
|
14
9
|
}
|
|
15
|
-
async function list(flags) {
|
|
16
|
-
const config =
|
|
10
|
+
export async function list(flags) {
|
|
11
|
+
const config = requireConfig();
|
|
17
12
|
const orgId = getOrgId(flags, config);
|
|
18
|
-
const assets = await
|
|
19
|
-
|
|
13
|
+
const assets = await sdkStorage.listAssets(config.api_key, orgId);
|
|
14
|
+
printTable(assets);
|
|
20
15
|
}
|
|
21
|
-
async function ingest(url, flags) {
|
|
16
|
+
export async function ingest(url, flags) {
|
|
22
17
|
if (!url)
|
|
23
|
-
|
|
24
|
-
const config =
|
|
18
|
+
error("Missing url");
|
|
19
|
+
const config = requireConfig();
|
|
25
20
|
const orgId = getOrgId(flags, config);
|
|
26
|
-
const res = await
|
|
27
|
-
|
|
21
|
+
const res = await sdkStorage.ingestAsset(config.api_key, orgId, url, flags.name);
|
|
22
|
+
success(`Asset ingested! ID: ${res.asset_id}\nHosted URL: ${res.url}`);
|
|
28
23
|
}
|
|
29
|
-
async function del(id, flags) {
|
|
24
|
+
export async function del(id, flags) {
|
|
30
25
|
if (!id)
|
|
31
|
-
|
|
32
|
-
const config =
|
|
26
|
+
error("Missing id");
|
|
27
|
+
const config = requireConfig();
|
|
33
28
|
const orgId = getOrgId(flags, config);
|
|
34
|
-
await
|
|
35
|
-
|
|
29
|
+
await sdkStorage.deleteAsset(config.api_key, orgId, id);
|
|
30
|
+
success(`Asset ${id} deleted`);
|
|
36
31
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { url as sdkUrl } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, info, printJson } from '../output.js';
|
|
4
|
+
export async function shorten(targetUrl, flags) {
|
|
5
|
+
const config = requireConfig();
|
|
6
|
+
const orgId = flags.org || config.default_org;
|
|
7
|
+
if (!orgId || !targetUrl)
|
|
8
|
+
error("Missing required arguments.\nUsage: myapi url shorten <url> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
9
|
+
const res = await sdkUrl.shortenUrl(config.api_key, orgId, targetUrl);
|
|
10
|
+
if (flags.json)
|
|
11
|
+
printJson(res);
|
|
12
|
+
else
|
|
13
|
+
success(`Shortened URL: ${res.short_url}\nCode: ${res.short_code}`);
|
|
14
|
+
}
|
|
15
|
+
export async function run(subcommand, args, flags) {
|
|
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
|
+
if (flags.help) {
|
|
21
|
+
if (subcommand === 'shorten')
|
|
22
|
+
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
|
+
if (subcommand === 'shorten')
|
|
26
|
+
await shorten(args[0], flags);
|
|
27
|
+
else
|
|
28
|
+
error(`Unknown subcommand: ${subcommand}. Run "myapi url --help" for a list of valid subcommands.`);
|
|
29
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare function list(flags: Record<string, string | boolean>): Promise<void>;
|
|
2
2
|
export declare function create(flags: Record<string, string | boolean>): Promise<void>;
|
|
3
3
|
export declare function del(id: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
4
|
+
export declare function delivery(id: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
5
|
+
export declare function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>): Promise<void>;
|
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");
|