@myapihq/cli 1.0.84 → 1.1.0-wip.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/auth.d.ts +8 -3
- package/dist/commands/auth.js +11 -29
- package/dist/commands/billing.d.ts +8 -4
- package/dist/commands/billing.js +43 -22
- package/dist/commands/config.d.ts +8 -5
- package/dist/commands/config.js +52 -27
- package/dist/commands/domain.d.ts +12 -9
- package/dist/commands/domain.js +117 -86
- package/dist/commands/email.d.ts +4 -12
- package/dist/commands/email.js +490 -128
- package/dist/commands/funnel.d.ts +10 -7
- package/dist/commands/funnel.js +75 -55
- package/dist/commands/image.js +25 -15
- package/dist/commands/keys.d.ts +8 -3
- package/dist/commands/keys.js +67 -28
- package/dist/commands/org.d.ts +9 -5
- package/dist/commands/org.js +99 -46
- package/dist/commands/pixel.js +23 -11
- package/dist/commands/setup.d.ts +3 -2
- package/dist/commands/setup.js +44 -77
- package/dist/commands/storage.js +25 -15
- package/dist/commands/update.d.ts +2 -1
- package/dist/commands/url.js +19 -7
- package/dist/commands/webhook.d.ts +8 -5
- package/dist/commands/webhook.js +52 -36
- package/dist/commands/workflow.d.ts +13 -7
- package/dist/commands/workflow.js +158 -56
- package/dist/flags.d.ts +8 -0
- package/dist/flags.js +88 -0
- package/dist/flags.test.d.ts +1 -0
- package/dist/flags.test.js +73 -0
- package/dist/helpers.d.ts +6 -0
- package/dist/helpers.js +29 -0
- package/dist/index.js +93 -107
- package/dist/output.d.ts +10 -1
- package/dist/output.js +4 -6
- package/dist/skills/my-email-api/README.md +45 -0
- package/dist/skills/my-email-api/SKILL.md +106 -0
- package/dist/skills/my-email-api/claude/.claude-plugin/plugin.json +6 -0
- package/dist/skills/my-email-api/make/.gitkeep +0 -0
- package/dist/skills/my-email-api/n8n/.gitkeep +0 -0
- package/dist/skills/my-email-api/openapi/.gitkeep +0 -0
- package/dist/skills/my-webhook-api/README.md +40 -0
- package/dist/skills/my-webhook-api/SKILL.md +65 -0
- package/dist/skills/my-webhook-api/claude/.claude-plugin/plugin.json +6 -0
- package/dist/skills/my-webhook-api/make/.gitkeep +0 -0
- package/dist/skills/my-webhook-api/n8n/.gitkeep +0 -0
- package/dist/skills/my-webhook-api/openapi/.gitkeep +0 -0
- package/dist/skills/my-workflow-api/README.md +37 -0
- package/dist/skills/my-workflow-api/SKILL.md +98 -0
- package/dist/skills/my-workflow-api/claude/.claude-plugin/plugin.json +6 -0
- package/dist/skills/my-workflow-api/make/.gitkeep +0 -0
- package/dist/skills/my-workflow-api/n8n/.gitkeep +0 -0
- package/dist/skills/my-workflow-api/openapi/.gitkeep +0 -0
- package/dist/utils.d.ts +0 -4
- package/dist/utils.js +0 -33
- package/dist/utils.test.d.ts +1 -0
- package/dist/utils.test.js +48 -0
- package/package.json +9 -4
- package/dist/commands/account.d.ts +0 -4
- package/dist/commands/account.js +0 -80
package/dist/commands/pixel.js
CHANGED
|
@@ -43,22 +43,34 @@ export async function identity(pixelId, flags) {
|
|
|
43
43
|
const res = await sdkPixel.getIdentity(config.api_key, orgId, pixelId);
|
|
44
44
|
printJson(res);
|
|
45
45
|
}
|
|
46
|
+
// ── Dispatcher ───────────────────────────────────────────────────────────────
|
|
47
|
+
const SUBCOMMAND_USAGE = {
|
|
48
|
+
'interactions': 'myapi pixel interactions [--website <domain>] [--campaign-id <id>] [--domain <domain>] [--from <iso8601>] [--to <iso8601>] [--limit <num>] [--offset <num>] [--org <id>] [--json]',
|
|
49
|
+
'identity': 'myapi pixel identity <pixel_id> [--org <id>]',
|
|
50
|
+
};
|
|
46
51
|
export async function run(subcommand, args, flags) {
|
|
47
52
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
48
|
-
info(
|
|
53
|
+
info(`Usage: myapi pixel <subcommand>
|
|
54
|
+
|
|
55
|
+
Subcommands:
|
|
56
|
+
interactions Get a unified timeline of visits and events
|
|
57
|
+
(requires at least one filter: --website, --campaign-id, or --domain)
|
|
58
|
+
identity Resolve the identity graph (emails, IPs, profiles) for a pixel ID
|
|
59
|
+
|
|
60
|
+
All commands accept --org <id> (or set default: myapi config set-org <id>).`);
|
|
49
61
|
return;
|
|
50
62
|
}
|
|
51
63
|
if (flags.help) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
const usage = SUBCOMMAND_USAGE[subcommand];
|
|
65
|
+
if (usage)
|
|
66
|
+
info(`Usage: ${usage}`);
|
|
67
|
+
else
|
|
68
|
+
info(`Unknown subcommand: ${subcommand}. Run "myapi pixel --help" for the list.`);
|
|
56
69
|
return;
|
|
57
70
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
error(`Unknown subcommand: ${subcommand}. Run "myapi pixel --help" for a list of valid subcommands.`);
|
|
71
|
+
switch (subcommand) {
|
|
72
|
+
case 'interactions': return interactions(flags);
|
|
73
|
+
case 'identity': return identity(args[0], flags);
|
|
74
|
+
default: error(`Unknown subcommand: ${subcommand}. Run "myapi pixel --help" for a list of valid subcommands.`);
|
|
75
|
+
}
|
|
64
76
|
}
|
package/dist/commands/setup.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Flags } from '../helpers.js';
|
|
1
2
|
export declare function installSkills(): Promise<void>;
|
|
2
|
-
export declare function importKey(apiKey: string, flags:
|
|
3
|
-
export declare function setup(flags?:
|
|
3
|
+
export declare function importKey(apiKey: string, flags: Flags): Promise<void>;
|
|
4
|
+
export declare function setup(flags?: Flags): Promise<void>;
|
package/dist/commands/setup.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as path from 'path';
|
|
|
4
4
|
import * as readline from 'readline';
|
|
5
5
|
import { loadConfig, saveConfig, addAccount, loadFullConfig } from '../config.js';
|
|
6
6
|
import { info, success } from '../output.js';
|
|
7
|
-
|
|
7
|
+
import { hq, funnel as sdkFunnel } from '@myapihq/sdk';
|
|
8
8
|
function ask(rl, q) {
|
|
9
9
|
return new Promise(resolve => rl.question(q, resolve));
|
|
10
10
|
}
|
|
@@ -14,17 +14,6 @@ function yn(answer, defaultYes = true) {
|
|
|
14
14
|
return defaultYes;
|
|
15
15
|
return t === 'y' || t === 'yes';
|
|
16
16
|
}
|
|
17
|
-
async function post(path, body) {
|
|
18
|
-
const res = await fetch(`${API_BASE}${path}`, {
|
|
19
|
-
method: 'POST',
|
|
20
|
-
headers: { 'Content-Type': 'application/json' },
|
|
21
|
-
body: JSON.stringify(body),
|
|
22
|
-
});
|
|
23
|
-
const json = await res.json();
|
|
24
|
-
if (!res.ok)
|
|
25
|
-
throw new Error(json.error ?? `HTTP ${res.status}`);
|
|
26
|
-
return json.data ?? json;
|
|
27
|
-
}
|
|
28
17
|
// ---------------------------------------------------------------------------
|
|
29
18
|
// Skills installation
|
|
30
19
|
// ---------------------------------------------------------------------------
|
|
@@ -55,7 +44,9 @@ export async function installSkills() {
|
|
|
55
44
|
fs.mkdirSync(skillDir, { recursive: true });
|
|
56
45
|
fs.copyFileSync(path.join(BUNDLED_SKILLS_DIR, skill, 'SKILL.md'), path.join(skillDir, 'SKILL.md'));
|
|
57
46
|
}
|
|
58
|
-
// Symlink each skill into agent config directories
|
|
47
|
+
// Symlink each skill into agent config directories. Surface failures so
|
|
48
|
+
// users can fix permission issues — skills that didn't install will not
|
|
49
|
+
// be available to the agent and "skills installed" would otherwise lie.
|
|
59
50
|
for (const [agent, dir] of Object.entries(AGENT_DIRS)) {
|
|
60
51
|
try {
|
|
61
52
|
fs.mkdirSync(dir, { recursive: true });
|
|
@@ -70,8 +61,15 @@ export async function installSkills() {
|
|
|
70
61
|
}
|
|
71
62
|
info(` ✓ ${agent}`);
|
|
72
63
|
}
|
|
73
|
-
catch {
|
|
74
|
-
//
|
|
64
|
+
catch (err) {
|
|
65
|
+
// Skip agents not installed on this machine (ENOENT on parent dir is OK).
|
|
66
|
+
// Surface anything else so the user knows skills aren't fully installed.
|
|
67
|
+
const code = err?.code;
|
|
68
|
+
if (code === 'ENOENT' || code === 'ENOTDIR') {
|
|
69
|
+
// Agent likely not installed — quietly skip.
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
info(` ✗ ${agent}: ${err.message || code} (${dir})`);
|
|
75
73
|
}
|
|
76
74
|
}
|
|
77
75
|
}
|
|
@@ -80,18 +78,14 @@ export async function installSkills() {
|
|
|
80
78
|
// ---------------------------------------------------------------------------
|
|
81
79
|
async function registeredFlow(rl) {
|
|
82
80
|
const email = (await ask(rl, '› Email? ')).trim();
|
|
83
|
-
await
|
|
81
|
+
await hq.sendCode(email);
|
|
84
82
|
info(`› Sent a code to ${email} · paste it below`);
|
|
85
83
|
const code = (await ask(rl, '› Code? ')).trim();
|
|
86
|
-
const data = await
|
|
84
|
+
const data = await hq.verifyCode(email, code);
|
|
87
85
|
return { ...data, email };
|
|
88
86
|
}
|
|
89
|
-
// ---------------------------------------------------------------------------
|
|
90
|
-
// Anonymous flow
|
|
91
|
-
// ---------------------------------------------------------------------------
|
|
92
87
|
async function anonymousFlow() {
|
|
93
|
-
|
|
94
|
-
return data;
|
|
88
|
+
return hq.createAnonymousAccount();
|
|
95
89
|
}
|
|
96
90
|
// ---------------------------------------------------------------------------
|
|
97
91
|
// Main setup command
|
|
@@ -102,37 +96,25 @@ export async function importKey(apiKey, flags) {
|
|
|
102
96
|
info('Usage: myapi auth import-key <api_key> [--install-skills] [--no-skills]\n\nImports an existing API key non-interactively. Use this in CI, Docker, or any\nenvironment where the interactive "myapi auth setup" flow is not practical.\n\nThe key is validated against the API before being saved. Your default org and\nfunnel are auto-detected from the account and written to the local config.\n\nFlags:\n --install-skills Also install the MyAPI skills pack for AI agents after importing\n --no-skills Skip skills installation even if previously installed\n\nExamples:\n myapi auth import-key hq_live_xxxxxxxxxxxxxxxxxxxx\n myapi auth import-key hq_live_xxxxxxxxxxxxxxxxxxxx --install-skills');
|
|
103
97
|
return;
|
|
104
98
|
}
|
|
105
|
-
const auth = { Authorization: `Bearer ${apiKey}` };
|
|
106
99
|
let accountId = '';
|
|
107
100
|
let email;
|
|
108
101
|
let defaultOrg = '';
|
|
109
102
|
let defaultFunnel = '';
|
|
110
103
|
try {
|
|
111
|
-
const
|
|
112
|
-
const meJson = await meRes.json();
|
|
113
|
-
if (!meRes.ok)
|
|
114
|
-
throw new Error(meJson.error ?? `HTTP ${meRes.status}`);
|
|
115
|
-
const me = meJson.data ?? meJson;
|
|
104
|
+
const me = await hq.getAccount(apiKey);
|
|
116
105
|
accountId = me.account_id ?? '';
|
|
117
106
|
email = me.email || undefined;
|
|
118
107
|
}
|
|
119
108
|
catch (e) {
|
|
120
109
|
throw new Error(`Could not verify API key: ${e.message}`);
|
|
121
110
|
}
|
|
122
|
-
// Fetch org/funnel defaults.
|
|
123
111
|
try {
|
|
124
|
-
const
|
|
125
|
-
if (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (fRes.ok) {
|
|
131
|
-
const funnels = ((await fRes.json())?.data ?? []);
|
|
132
|
-
if (funnels.length > 0)
|
|
133
|
-
defaultFunnel = funnels[funnels.length - 1].id;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
112
|
+
const orgs = await hq.listOrgs(apiKey);
|
|
113
|
+
if (orgs.length > 0) {
|
|
114
|
+
defaultOrg = orgs[orgs.length - 1].id;
|
|
115
|
+
const funnels = await sdkFunnel.listFunnels(apiKey, defaultOrg);
|
|
116
|
+
if (funnels.length > 0)
|
|
117
|
+
defaultFunnel = funnels[funnels.length - 1].id;
|
|
136
118
|
}
|
|
137
119
|
}
|
|
138
120
|
catch { /* non-fatal */ }
|
|
@@ -224,42 +206,27 @@ export async function setup(flags = {}) {
|
|
|
224
206
|
}
|
|
225
207
|
// Validate key and ensure org/funnel defaults are correct.
|
|
226
208
|
try {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const funnels = (await fRes.json())?.data ?? [];
|
|
249
|
-
if (funnels.length > 0 && (!resolvedFunnel || !funnels.find((f) => f.id === resolvedFunnel))) {
|
|
250
|
-
resolvedFunnel = funnels[funnels.length - 1].id;
|
|
251
|
-
info(`› Auto-selected funnel: ${resolvedFunnel}`);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
if (resolvedOrg !== defaultOrg || resolvedFunnel !== defaultFunnel) {
|
|
255
|
-
const full = loadFullConfig();
|
|
256
|
-
const idx = full.active;
|
|
257
|
-
full.accounts[idx].default_org = resolvedOrg;
|
|
258
|
-
full.accounts[idx].default_funnel = resolvedFunnel;
|
|
259
|
-
fs.writeFileSync(path.join(os.homedir(), '.myapi', 'config.json'), JSON.stringify(full, null, 2), { mode: 0o600 });
|
|
260
|
-
defaultOrg = resolvedOrg;
|
|
261
|
-
defaultFunnel = resolvedFunnel;
|
|
262
|
-
}
|
|
209
|
+
await hq.getAccount(apiKey);
|
|
210
|
+
let resolvedOrg = defaultOrg;
|
|
211
|
+
let resolvedFunnel = defaultFunnel;
|
|
212
|
+
const orgs = await hq.listOrgs(apiKey);
|
|
213
|
+
if (orgs.length > 0) {
|
|
214
|
+
const latest = orgs[orgs.length - 1];
|
|
215
|
+
if (!resolvedOrg || !orgs.find(o => o.id === resolvedOrg)) {
|
|
216
|
+
resolvedOrg = latest.id;
|
|
217
|
+
info(`› Auto-selected org: ${latest.name} (${resolvedOrg})`);
|
|
218
|
+
}
|
|
219
|
+
const funnels = await sdkFunnel.listFunnels(apiKey, resolvedOrg);
|
|
220
|
+
if (funnels.length > 0 && (!resolvedFunnel || !funnels.find((f) => f.id === resolvedFunnel))) {
|
|
221
|
+
resolvedFunnel = funnels[funnels.length - 1].id;
|
|
222
|
+
info(`› Auto-selected funnel: ${resolvedFunnel}`);
|
|
223
|
+
}
|
|
224
|
+
if (resolvedOrg !== defaultOrg || resolvedFunnel !== defaultFunnel) {
|
|
225
|
+
const current = loadConfig();
|
|
226
|
+
if (current) {
|
|
227
|
+
saveConfig({ ...current, default_org: resolvedOrg, default_funnel: resolvedFunnel });
|
|
228
|
+
defaultOrg = resolvedOrg;
|
|
229
|
+
defaultFunnel = resolvedFunnel;
|
|
263
230
|
}
|
|
264
231
|
}
|
|
265
232
|
}
|
package/dist/commands/storage.js
CHANGED
|
@@ -30,26 +30,36 @@ export async function del(id, flags) {
|
|
|
30
30
|
await sdkStorage.deleteAsset(config.api_key, orgId, id);
|
|
31
31
|
success(`Asset ${id} deleted`);
|
|
32
32
|
}
|
|
33
|
+
// ── Dispatcher ───────────────────────────────────────────────────────────────
|
|
34
|
+
const SUBCOMMAND_USAGE = {
|
|
35
|
+
'list': 'myapi storage list [--org <id>] [--json]',
|
|
36
|
+
'ingest': 'myapi storage ingest <url> [--name <name>] [--org <id>]',
|
|
37
|
+
'delete': 'myapi storage delete <asset_id> [--org <id>]',
|
|
38
|
+
};
|
|
33
39
|
export async function run(subcommand, args, flags) {
|
|
34
40
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
35
|
-
info(
|
|
41
|
+
info(`Usage: myapi storage <subcommand>
|
|
42
|
+
|
|
43
|
+
Subcommands:
|
|
44
|
+
list List all your uploaded assets
|
|
45
|
+
ingest Ingest a public image URL into your edge storage
|
|
46
|
+
delete Delete a stored asset
|
|
47
|
+
|
|
48
|
+
All commands accept --org <id> (or set default: myapi config set-org <id>).`);
|
|
36
49
|
return;
|
|
37
50
|
}
|
|
38
51
|
if (flags.help) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
info('Usage: myapi storage delete <asset_id> --org <id>');
|
|
52
|
+
const usage = SUBCOMMAND_USAGE[subcommand];
|
|
53
|
+
if (usage)
|
|
54
|
+
info(`Usage: ${usage}`);
|
|
55
|
+
else
|
|
56
|
+
info(`Unknown subcommand: ${subcommand}. Run "myapi storage --help" for the list.`);
|
|
45
57
|
return;
|
|
46
58
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
else
|
|
54
|
-
error(`Unknown subcommand: ${subcommand}. Run "myapi storage --help" for a list of valid subcommands.`);
|
|
59
|
+
switch (subcommand) {
|
|
60
|
+
case 'list': return list(flags);
|
|
61
|
+
case 'ingest': return ingest(args[0], flags);
|
|
62
|
+
case 'delete': return del(args[0], flags);
|
|
63
|
+
default: error(`Unknown subcommand: ${subcommand}. Run "myapi storage --help" for a list of valid subcommands.`);
|
|
64
|
+
}
|
|
55
65
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { Flags } from '../helpers.js';
|
|
1
2
|
export declare function checkForUpdate(currentVersion: string): Promise<void>;
|
|
2
|
-
export declare function update(flags?:
|
|
3
|
+
export declare function update(flags?: Flags): Promise<void>;
|
|
3
4
|
export declare function latestVersion(): Promise<string | null>;
|
|
4
5
|
export declare function isNewer(latest: string, current: string): boolean;
|
package/dist/commands/url.js
CHANGED
|
@@ -12,18 +12,30 @@ export async function shorten(targetUrl, flags) {
|
|
|
12
12
|
else
|
|
13
13
|
success(`Shortened URL: ${res.short_url}\nCode: ${res.short_code}`);
|
|
14
14
|
}
|
|
15
|
+
// ── Dispatcher ───────────────────────────────────────────────────────────────
|
|
16
|
+
const SUBCOMMAND_USAGE = {
|
|
17
|
+
'shorten': 'myapi url shorten <url> [--org <id>] [--json]',
|
|
18
|
+
};
|
|
15
19
|
export async function run(subcommand, args, flags) {
|
|
16
20
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
17
|
-
info(
|
|
21
|
+
info(`Usage: myapi url <subcommand>
|
|
22
|
+
|
|
23
|
+
Subcommands:
|
|
24
|
+
shorten Shorten a long URL (returns a myurlto.com link)
|
|
25
|
+
|
|
26
|
+
All commands accept --org <id> (or set default: myapi config set-org <id>).`);
|
|
18
27
|
return;
|
|
19
28
|
}
|
|
20
29
|
if (flags.help) {
|
|
21
|
-
|
|
22
|
-
|
|
30
|
+
const usage = SUBCOMMAND_USAGE[subcommand];
|
|
31
|
+
if (usage)
|
|
32
|
+
info(`Usage: ${usage}`);
|
|
33
|
+
else
|
|
34
|
+
info(`Unknown subcommand: ${subcommand}. Run "myapi url --help" for the list.`);
|
|
23
35
|
return;
|
|
24
36
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
switch (subcommand) {
|
|
38
|
+
case 'shorten': return shorten(args[0], flags);
|
|
39
|
+
default: error(`Unknown subcommand: ${subcommand}. Run "myapi url --help" for a list of valid subcommands.`);
|
|
40
|
+
}
|
|
29
41
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
1
|
+
import type { FlagSchema } from '../flags.js';
|
|
2
|
+
import { type Flags } from '../helpers.js';
|
|
3
|
+
export declare const SCHEMA: FlagSchema;
|
|
4
|
+
export declare function list(flags: Flags): Promise<void>;
|
|
5
|
+
export declare function create(flags: Flags): Promise<void>;
|
|
6
|
+
export declare function del(id: string, flags: Flags): Promise<void>;
|
|
7
|
+
export declare function delivery(id: string, flags: Flags): Promise<void>;
|
|
8
|
+
export declare function run(subcommand: string | undefined, args: string[], flags: Flags): Promise<void>;
|
package/dist/commands/webhook.js
CHANGED
|
@@ -1,68 +1,84 @@
|
|
|
1
1
|
import { webhook as sdkWebhook } from '@myapihq/sdk';
|
|
2
2
|
import { requireConfig } from '../config.js';
|
|
3
3
|
import { success, error, printTable, info, printJson } from '../output.js';
|
|
4
|
+
import { requireOrg } from '../helpers.js';
|
|
5
|
+
export const SCHEMA = {
|
|
6
|
+
org: 'string',
|
|
7
|
+
name: 'string',
|
|
8
|
+
description: 'string',
|
|
9
|
+
};
|
|
4
10
|
export async function list(flags) {
|
|
5
11
|
const config = requireConfig();
|
|
6
|
-
const orgId = flags
|
|
7
|
-
if (!orgId)
|
|
8
|
-
error("Missing required arguments.\nUsage: myapi webhook list --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
12
|
+
const orgId = requireOrg(flags, config, 'myapi webhook list [--org <id>]');
|
|
9
13
|
const endpoints = await sdkWebhook.listEndpoints(config.api_key, orgId);
|
|
10
|
-
if (flags.json)
|
|
14
|
+
if (flags.json) {
|
|
11
15
|
printJson(endpoints);
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
printTable(endpoints, {
|
|
19
|
+
flags,
|
|
20
|
+
empty: 'No webhook endpoints yet. Create one with: myapi webhook create --name <name>',
|
|
21
|
+
});
|
|
14
22
|
}
|
|
15
23
|
export async function create(flags) {
|
|
16
24
|
const config = requireConfig();
|
|
17
|
-
const orgId = flags
|
|
25
|
+
const orgId = requireOrg(flags, config, 'myapi webhook create --name <name> [--description <desc>] [--org <id>]');
|
|
18
26
|
const name = flags.name;
|
|
27
|
+
if (!name)
|
|
28
|
+
error('Missing required arguments.\nUsage: myapi webhook create --name <name> [--description <desc>] [--org <id>]');
|
|
19
29
|
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>)");
|
|
22
|
-
}
|
|
23
30
|
const res = await sdkWebhook.createEndpoint(config.api_key, orgId, name, description);
|
|
24
|
-
success(`Webhook created! ID: ${res.id}\nInbound URL: ${res.
|
|
31
|
+
success(`Webhook created! ID: ${res.id}\nInbound URL: ${res.url}`);
|
|
25
32
|
}
|
|
26
33
|
export async function del(id, flags) {
|
|
27
34
|
const config = requireConfig();
|
|
28
|
-
const orgId = flags
|
|
29
|
-
if (!
|
|
30
|
-
error(
|
|
35
|
+
const orgId = requireOrg(flags, config, 'myapi webhook delete <id> [--org <id>]');
|
|
36
|
+
if (!id)
|
|
37
|
+
error('Missing required arguments.\nUsage: myapi webhook delete <id> [--org <id>]');
|
|
31
38
|
await sdkWebhook.deleteEndpoint(config.api_key, orgId, id);
|
|
32
39
|
success(`Webhook ${id} deleted`);
|
|
33
40
|
}
|
|
34
41
|
export async function delivery(id, flags) {
|
|
35
42
|
const config = requireConfig();
|
|
36
|
-
const orgId = flags
|
|
37
|
-
if (!
|
|
38
|
-
error(
|
|
43
|
+
const orgId = requireOrg(flags, config, 'myapi webhook delivery <id> [--org <id>]');
|
|
44
|
+
if (!id)
|
|
45
|
+
error('Missing required arguments.\nUsage: myapi webhook delivery <id> [--org <id>]');
|
|
39
46
|
const res = await sdkWebhook.getDelivery(config.api_key, orgId, id);
|
|
40
47
|
printJson(res);
|
|
41
48
|
}
|
|
49
|
+
// ── Dispatcher ───────────────────────────────────────────────────────────────
|
|
50
|
+
const SUBCOMMAND_USAGE = {
|
|
51
|
+
'list': 'myapi webhook list [--org <id>] [--json]',
|
|
52
|
+
'create': 'myapi webhook create --name <name> [--description <desc>] [--org <id>]',
|
|
53
|
+
'delete': 'myapi webhook delete <id> [--org <id>]',
|
|
54
|
+
'delivery': 'myapi webhook delivery <delivery_id> [--org <id>]',
|
|
55
|
+
};
|
|
42
56
|
export async function run(subcommand, args, flags) {
|
|
43
57
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
44
|
-
info(
|
|
58
|
+
info(`Usage: myapi webhook <subcommand>
|
|
59
|
+
|
|
60
|
+
Subcommands:
|
|
61
|
+
list List all inbound webhook endpoints
|
|
62
|
+
create Create a new endpoint to receive data (returns an inbound URL)
|
|
63
|
+
delete Delete a webhook endpoint
|
|
64
|
+
delivery Inspect a specific webhook delivery (payload, received_at)
|
|
65
|
+
|
|
66
|
+
All commands accept --org <id> (or set default: myapi config set-org <id>).`);
|
|
45
67
|
return;
|
|
46
68
|
}
|
|
47
69
|
if (flags.help) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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.');
|
|
70
|
+
const usage = SUBCOMMAND_USAGE[subcommand];
|
|
71
|
+
if (usage)
|
|
72
|
+
info(`Usage: ${usage}`);
|
|
73
|
+
else
|
|
74
|
+
info(`Unknown subcommand: ${subcommand}. Run "myapi webhook --help" for the list.`);
|
|
56
75
|
return;
|
|
57
76
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
await delivery(args[0], flags);
|
|
66
|
-
else
|
|
67
|
-
error(`Unknown subcommand: ${subcommand}. Run "myapi webhook --help" for a list of valid subcommands.`);
|
|
77
|
+
switch (subcommand) {
|
|
78
|
+
case 'list': return list(flags);
|
|
79
|
+
case 'create': return create(flags);
|
|
80
|
+
case 'delete': return del(args[0], flags);
|
|
81
|
+
case 'delivery': return delivery(args[0], flags);
|
|
82
|
+
default: error(`Unknown subcommand: ${subcommand}. Run "myapi webhook --help" for a list of valid subcommands.`);
|
|
83
|
+
}
|
|
68
84
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
1
|
+
import type { FlagSchema } from '../flags.js';
|
|
2
|
+
import { type Flags } from '../helpers.js';
|
|
3
|
+
export declare const SCHEMA: FlagSchema;
|
|
4
|
+
export declare function list(flags: Flags): Promise<void>;
|
|
5
|
+
export declare function get(id: string, flags: Flags): Promise<void>;
|
|
6
|
+
export declare function create(flags: Flags): Promise<void>;
|
|
7
|
+
export declare function update(id: string, flags: Flags): Promise<void>;
|
|
8
|
+
export declare function enable(id: string, flags: Flags): Promise<void>;
|
|
9
|
+
export declare function disable(id: string, flags: Flags): Promise<void>;
|
|
10
|
+
export declare function del(id: string, flags: Flags): Promise<void>;
|
|
11
|
+
export declare function runs(id: string, flags: Flags): Promise<void>;
|
|
12
|
+
export declare function getRun(runId: string, flags: Flags): Promise<void>;
|
|
13
|
+
export declare function run(subcommand: string | undefined, args: string[], flags: Flags): Promise<void>;
|