@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/index.js
CHANGED
|
@@ -1,51 +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
|
-
|
|
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';
|
|
47
20
|
async function main() {
|
|
48
|
-
|
|
21
|
+
updateNotifier({ pkg }).notify();
|
|
22
|
+
const { args, flags } = parseArgs(process.argv.slice(2));
|
|
49
23
|
if (args.length === 0) {
|
|
50
24
|
printHelp();
|
|
51
25
|
process.exit(0);
|
|
@@ -55,14 +29,14 @@ async function main() {
|
|
|
55
29
|
switch (command) {
|
|
56
30
|
case 'setup':
|
|
57
31
|
if (flags.help) {
|
|
58
|
-
|
|
32
|
+
info('Usage: myapi setup\n\nSetup CLI credentials and view integration instructions');
|
|
59
33
|
break;
|
|
60
34
|
}
|
|
61
35
|
await setupCmd.setup();
|
|
62
36
|
break;
|
|
63
37
|
case 'keys':
|
|
64
38
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
65
|
-
|
|
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>)');
|
|
66
40
|
break;
|
|
67
41
|
}
|
|
68
42
|
if (subcommand === 'create')
|
|
@@ -76,7 +50,7 @@ async function main() {
|
|
|
76
50
|
break;
|
|
77
51
|
case 'org':
|
|
78
52
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
79
|
-
|
|
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');
|
|
80
54
|
break;
|
|
81
55
|
}
|
|
82
56
|
if (subcommand === 'list')
|
|
@@ -94,7 +68,7 @@ async function main() {
|
|
|
94
68
|
break;
|
|
95
69
|
case 'billing':
|
|
96
70
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
97
|
-
|
|
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');
|
|
98
72
|
break;
|
|
99
73
|
}
|
|
100
74
|
if (subcommand === 'balance')
|
|
@@ -114,23 +88,35 @@ async function main() {
|
|
|
114
88
|
case 'domain':
|
|
115
89
|
await domainCmd.run(subcommand, restArgs, flags);
|
|
116
90
|
break;
|
|
91
|
+
case 'funnel':
|
|
92
|
+
await funnelCmd.run(subcommand, restArgs, flags);
|
|
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;
|
|
117
103
|
default:
|
|
118
104
|
printHelp();
|
|
119
105
|
process.exit(0);
|
|
120
106
|
}
|
|
121
107
|
}
|
|
122
108
|
catch (err) {
|
|
123
|
-
if (err instanceof
|
|
109
|
+
if (err instanceof MyApiError) {
|
|
124
110
|
if (err.status === 402)
|
|
125
|
-
|
|
111
|
+
error('Insufficient balance. Run: myapi billing topup <amount>');
|
|
126
112
|
else if (err.status === 401)
|
|
127
|
-
|
|
113
|
+
error('Invalid API key. Run: myapi setup');
|
|
128
114
|
}
|
|
129
|
-
|
|
115
|
+
error(err.message || String(err));
|
|
130
116
|
}
|
|
131
117
|
}
|
|
132
118
|
function printHelp() {
|
|
133
|
-
|
|
119
|
+
info(`myapi - MyAPI command-line interface
|
|
134
120
|
|
|
135
121
|
Usage: myapi <command> [subcommand] [args]
|
|
136
122
|
|
|
@@ -141,7 +127,11 @@ Commands:
|
|
|
141
127
|
setup Setup CLI credentials and view integration instructions
|
|
142
128
|
config Manage CLI defaults like org_id and domain
|
|
143
129
|
domain Manage domain configurations
|
|
130
|
+
funnel Manage headless funnels and pages
|
|
131
|
+
url Shorten URLs and manage links
|
|
132
|
+
webhook Manage inbound webhooks
|
|
133
|
+
workflow Manage workflow automations
|
|
144
134
|
|
|
145
135
|
Run "myapi <command> --help" for subcommand help.`);
|
|
146
136
|
}
|
|
147
|
-
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
|
}
|
package/src/commands/billing.ts
CHANGED
|
@@ -74,7 +74,7 @@ export async function topup(amountStr: string, flags: Record<string, string | bo
|
|
|
74
74
|
|
|
75
75
|
export async function setup(flags: Record<string, string | boolean>) {
|
|
76
76
|
if (flags.help) {
|
|
77
|
-
info('Usage: myapi billing setup\n\nGenerates a secure
|
|
77
|
+
info('Usage: myapi billing setup\n\nGenerates a secure checkout link to add or update your payment method.');
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
80
|
const config = requireConfig();
|
package/src/commands/email.ts
CHANGED
|
@@ -17,22 +17,50 @@ export async function createMailbox(flags: Record<string, string | boolean>) {
|
|
|
17
17
|
export async function listMailboxes(flags: Record<string, string | boolean>) {
|
|
18
18
|
const config = requireConfig();
|
|
19
19
|
const orgId = (flags.org as string) || config.default_org;
|
|
20
|
-
if (!orgId) error("Missing required arguments.\nUsage: myapi email list-mailboxes --org <id
|
|
21
|
-
|
|
20
|
+
if (!orgId) error("Missing required arguments.\nUsage: myapi email list-mailboxes --org <id> [--domain <domain> | --filter unassigned]\n(Or set a default org via: myapi config set-org <id>)");
|
|
21
|
+
if (!flags.domain && flags.filter !== 'unassigned') error("Must provide either --domain <domain> or --filter unassigned");
|
|
22
|
+
const mailboxes = await sdkEmail.listMailboxes(config.api_key, orgId, {
|
|
23
|
+
domain: flags.domain as string | undefined,
|
|
24
|
+
filter: flags.filter === 'unassigned' ? 'unassigned' : undefined
|
|
25
|
+
});
|
|
22
26
|
printTable(mailboxes as unknown as Record<string, unknown>[]);
|
|
23
27
|
}
|
|
24
28
|
|
|
29
|
+
export async function sent(flags: Record<string, string | boolean>) {
|
|
30
|
+
const config = requireConfig();
|
|
31
|
+
const orgId = (flags.org as string) || config.default_org;
|
|
32
|
+
if (!orgId) error("Missing required arguments.\nUsage: myapi email sent --org <id> [--limit <num>] [--offset <num>]\n(Or set defaults via: myapi config set-org <id>)");
|
|
33
|
+
const limit = parseInt(flags.limit as string) || 50;
|
|
34
|
+
const offset = parseInt(flags.offset as string) || 0;
|
|
35
|
+
const emails = await sdkEmail.getSentEmails(config.api_key, orgId, limit, offset);
|
|
36
|
+
printTable(emails as unknown as Record<string, unknown>[]);
|
|
37
|
+
}
|
|
38
|
+
|
|
25
39
|
export async function send(flags: Record<string, string | boolean>) {
|
|
26
40
|
const config = requireConfig();
|
|
27
41
|
const orgId = (flags.org as string) || config.default_org;
|
|
28
|
-
if (!orgId || !flags.from || !flags.to || !flags.subject
|
|
29
|
-
error("Missing required arguments.\nUsage: myapi email send --org <id> --from <email> --to <email> --subject <str> --body <str>");
|
|
42
|
+
if (!orgId || !flags.from || !flags.to || !flags.subject) {
|
|
43
|
+
error("Missing required arguments.\nUsage: myapi email send --org <id> --from <email> --to <email> --subject <str> [--body <str> | --template-id <id> [--template-vars <json_str>]]");
|
|
44
|
+
}
|
|
45
|
+
if (!flags.body && !flags['template-id']) error("Must provide either --body or --template-id");
|
|
46
|
+
if (flags.body && flags['template-id']) error("Cannot provide both --body and --template-id");
|
|
47
|
+
|
|
48
|
+
let templateVars: Record<string, string> | undefined;
|
|
49
|
+
if (flags['template-vars']) {
|
|
50
|
+
try {
|
|
51
|
+
templateVars = JSON.parse(flags['template-vars'] as string);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
error("--template-vars must be a valid JSON string");
|
|
54
|
+
}
|
|
30
55
|
}
|
|
56
|
+
|
|
31
57
|
const res = await sdkEmail.sendEmail(config.api_key, orgId, {
|
|
32
58
|
from: flags.from as string,
|
|
33
59
|
to: [flags.to as string],
|
|
34
60
|
subject: flags.subject as string,
|
|
35
|
-
text: flags.body as string
|
|
61
|
+
text: flags.body as string | undefined,
|
|
62
|
+
template_id: flags['template-id'] as string | undefined,
|
|
63
|
+
template_vars: templateVars
|
|
36
64
|
});
|
|
37
65
|
success(`Email sent! Message ID: ${res.message_id}`);
|
|
38
66
|
}
|
|
@@ -45,6 +73,14 @@ export async function inbox(address: string, flags: Record<string, string | bool
|
|
|
45
73
|
printTable(messages as unknown as Record<string, unknown>[]);
|
|
46
74
|
}
|
|
47
75
|
|
|
76
|
+
export async function outbox(address: string, flags: Record<string, string | boolean>) {
|
|
77
|
+
const config = requireConfig();
|
|
78
|
+
const orgId = (flags.org as string) || config.default_org;
|
|
79
|
+
if (!orgId || !address) error("Missing required arguments.\nUsage: myapi email outbox <address> --org <id>");
|
|
80
|
+
const messages = await sdkEmail.getOutbox(config.api_key, orgId, address);
|
|
81
|
+
printTable(messages as unknown as Record<string, unknown>[]);
|
|
82
|
+
}
|
|
83
|
+
|
|
48
84
|
export async function listTemplates(flags: Record<string, string | boolean>) {
|
|
49
85
|
const config = requireConfig();
|
|
50
86
|
const orgId = (flags.org as string) || config.default_org;
|
|
@@ -107,15 +143,17 @@ export async function campaignStats(id: string, flags: Record<string, string | b
|
|
|
107
143
|
|
|
108
144
|
export async function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>) {
|
|
109
145
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
110
|
-
info('Usage: myapi email <subcommand>\n\nSubcommands:\n create-mailbox Create a new mailbox\n list-mailboxes List mailboxes\n send Send an email\n inbox Read received emails\n list-templates List email templates\n generate-template Generate AI template\n list-campaigns List campaigns\n campaign-stats Get campaign stats\n\nNote: All email commands require the --org <id> flag.');
|
|
146
|
+
info('Usage: myapi email <subcommand>\n\nSubcommands:\n create-mailbox Create a new mailbox\n list-mailboxes List mailboxes\n send Send an email\n sent List sent emails\n inbox Read received emails\n outbox Read sent emails for address\n list-templates List email templates\n generate-template Generate AI template\n list-campaigns List campaigns\n campaign-stats Get campaign stats\n\nNote: All email commands require the --org <id> flag.');
|
|
111
147
|
return;
|
|
112
148
|
}
|
|
113
149
|
|
|
114
150
|
if (flags.help) {
|
|
115
151
|
if (subcommand === 'create-mailbox') info('Usage: myapi email create-mailbox --org <id> --domain <domain> --username <user>');
|
|
116
|
-
else if (subcommand === 'list-mailboxes') info('Usage: myapi email list-mailboxes --org <id>');
|
|
117
|
-
else if (subcommand === 'send') info('Usage: myapi email send --org <id> --from <email> --to <email> --subject <str> --body <str>');
|
|
152
|
+
else if (subcommand === 'list-mailboxes') info('Usage: myapi email list-mailboxes --org <id> [--domain <domain> | --filter unassigned]');
|
|
153
|
+
else if (subcommand === 'send') info('Usage: myapi email send --org <id> --from <email> --to <email> --subject <str> [--body <str> | --template-id <id> [--template-vars <json_str>]]');
|
|
154
|
+
else if (subcommand === 'sent') info('Usage: myapi email sent --org <id> [--limit <num>] [--offset <num>]');
|
|
118
155
|
else if (subcommand === 'inbox') info('Usage: myapi email inbox <address> --org <id>');
|
|
156
|
+
else if (subcommand === 'outbox') info('Usage: myapi email outbox <address> --org <id>');
|
|
119
157
|
else if (subcommand === 'list-templates') info('Usage: myapi email list-templates --org <id>');
|
|
120
158
|
else if (subcommand === 'generate-template') info('Usage: myapi email generate-template --org <id> --prompt <str> --name <str>');
|
|
121
159
|
else if (subcommand === 'list-campaigns') info('Usage: myapi email list-campaigns --org <id>');
|
|
@@ -126,7 +164,9 @@ export async function run(subcommand: string | undefined, args: string[], flags:
|
|
|
126
164
|
if (subcommand === 'create-mailbox') await createMailbox(flags);
|
|
127
165
|
else if (subcommand === 'list-mailboxes') await listMailboxes(flags);
|
|
128
166
|
else if (subcommand === 'send') await send(flags);
|
|
167
|
+
else if (subcommand === 'sent') await sent(flags);
|
|
129
168
|
else if (subcommand === 'inbox') await inbox(args[0], flags);
|
|
169
|
+
else if (subcommand === 'outbox') await outbox(args[0], flags);
|
|
130
170
|
else if (subcommand === 'list-templates') await listTemplates(flags);
|
|
131
171
|
else if (subcommand === 'generate-template') await generateTemplate(flags);
|
|
132
172
|
else if (subcommand === 'list-campaigns') await listCampaigns(flags);
|
package/src/commands/funnel.ts
CHANGED
|
@@ -40,30 +40,6 @@ export async function del(id: string, flags: Record<string, string | boolean>) {
|
|
|
40
40
|
success(`Funnel ${id} deleted`);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export async function preview(id: string, flags: Record<string, string | boolean>) {
|
|
44
|
-
const config = requireConfig();
|
|
45
|
-
const orgId = (flags.org as string) || config.default_org;
|
|
46
|
-
if (!orgId || !id) error("Missing required arguments.\nUsage: myapi funnel preview <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
47
|
-
const p = await sdkFunnel.previewFunnel(config.api_key, orgId, id);
|
|
48
|
-
success(`Preview deployed: ${p.preview_url}`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export async function publish(id: string, flags: Record<string, string | boolean>) {
|
|
52
|
-
const config = requireConfig();
|
|
53
|
-
const orgId = (flags.org as string) || config.default_org;
|
|
54
|
-
if (!orgId || !id) error("Missing required arguments.\nUsage: myapi funnel publish <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
55
|
-
const p = await sdkFunnel.publishFunnel(config.api_key, orgId, id);
|
|
56
|
-
success(`Publish job started. Status: ${p.status}`);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export async function status(id: string, flags: Record<string, string | boolean>) {
|
|
60
|
-
const config = requireConfig();
|
|
61
|
-
const orgId = (flags.org as string) || config.default_org;
|
|
62
|
-
if (!orgId || !id) error("Missing required arguments.\nUsage: myapi funnel status <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
63
|
-
const s = await sdkFunnel.getPublishStatus(config.api_key, orgId, id);
|
|
64
|
-
info(`Publish Status: ${s.status}`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
43
|
export async function push(id: string, slug: string, flags: Record<string, string | boolean>) {
|
|
68
44
|
const config = requireConfig();
|
|
69
45
|
const orgId = (flags.org as string) || config.default_org;
|
|
@@ -82,7 +58,7 @@ export async function push(id: string, slug: string, flags: Record<string, strin
|
|
|
82
58
|
|
|
83
59
|
if (!html) error("No HTML provided via stdin");
|
|
84
60
|
|
|
85
|
-
await sdkFunnel.
|
|
61
|
+
await sdkFunnel.pushFunnelPage(config.api_key, orgId, id, { slug, html });
|
|
86
62
|
success(`Pushed page to ${slug}`);
|
|
87
63
|
}
|
|
88
64
|
|
|
@@ -98,7 +74,7 @@ export async function verify(id: string, flags: Record<string, string | boolean>
|
|
|
98
74
|
|
|
99
75
|
export async function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>) {
|
|
100
76
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
101
|
-
info('Usage: myapi funnel <subcommand>\n\nSubcommands:\n list List funnels\n create Create a funnel\n get Get funnel details\n delete Delete a funnel\n
|
|
77
|
+
info('Usage: myapi funnel <subcommand>\n\nSubcommands:\n list List funnels\n create Create a funnel\n get Get funnel details\n delete Delete a funnel\n push Push a raw HTML page to a slug\n verify Verify links and webhooks\n\nNote: All funnel commands require the --org <id> flag.');
|
|
102
78
|
return;
|
|
103
79
|
}
|
|
104
80
|
|
|
@@ -107,11 +83,8 @@ export async function run(subcommand: string | undefined, args: string[], flags:
|
|
|
107
83
|
else if (subcommand === 'create') info('Usage: myapi funnel create --org <id> --domain <domain>');
|
|
108
84
|
else if (subcommand === 'get') info('Usage: myapi funnel get <id> --org <id>');
|
|
109
85
|
else if (subcommand === 'delete') info('Usage: myapi funnel delete <id> --org <id>');
|
|
110
|
-
else if (subcommand === 'preview') info('Usage: myapi funnel preview <id> --org <id>');
|
|
111
|
-
else if (subcommand === 'publish') info('Usage: myapi funnel publish <id> --org <id>');
|
|
112
|
-
else if (subcommand === 'status') info('Usage: myapi funnel status <id> --org <id>');
|
|
113
86
|
else if (subcommand === 'push') info('Usage: myapi funnel push <funnel_id> <slug> --org <id> < index.html\n\nPushes HTML content from stdin to the specified funnel.');
|
|
114
|
-
else if (subcommand === 'verify') info('Usage: myapi funnel verify <id> --org <id> [--slug <slug>]\n\nVerifies syntax and structure before
|
|
87
|
+
else if (subcommand === 'verify') info('Usage: myapi funnel verify <id> --org <id> [--slug <slug>]\n\nVerifies syntax and structure before pushing.');
|
|
115
88
|
return;
|
|
116
89
|
}
|
|
117
90
|
|
|
@@ -119,9 +92,6 @@ export async function run(subcommand: string | undefined, args: string[], flags:
|
|
|
119
92
|
else if (subcommand === 'create') await create(flags);
|
|
120
93
|
else if (subcommand === 'get') await get(args[0], flags);
|
|
121
94
|
else if (subcommand === 'delete') await del(args[0], flags);
|
|
122
|
-
else if (subcommand === 'preview') await preview(args[0], flags);
|
|
123
|
-
else if (subcommand === 'publish') await publish(args[0], flags);
|
|
124
|
-
else if (subcommand === 'status') await status(args[0], flags);
|
|
125
95
|
else if (subcommand === 'push') await push(args[0], args[1], flags);
|
|
126
96
|
else if (subcommand === 'verify') await verify(args[0], flags);
|
|
127
97
|
else error(`Unknown subcommand: ${subcommand}. Run "myapi funnel --help" for a list of valid subcommands.`);
|
|
@@ -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
|
+
}
|
package/src/commands/workflow.ts
CHANGED
|
@@ -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
|
|
8
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
53
|
-
|
|
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
|
}
|