@myapihq/cli 1.0.16 → 1.0.18
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 +1 -0
- package/dist/commands/email.js +90 -88
- package/dist/commands/funnel.js +43 -52
- package/dist/commands/image.d.ts +2 -0
- package/dist/commands/image.js +61 -22
- package/dist/commands/keys.js +22 -60
- package/dist/commands/org.js +37 -44
- package/dist/commands/pixel.d.ts +3 -0
- package/dist/commands/pixel.js +64 -0
- package/dist/commands/setup.js +13 -49
- package/dist/commands/storage.d.ts +1 -0
- package/dist/commands/storage.js +50 -31
- 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 +2 -0
- package/dist/commands/workflow.js +93 -43
- package/dist/config.d.ts +1 -0
- package/dist/config.js +19 -49
- package/dist/index.js +75 -56
- package/dist/output.js +5 -12
- package/dist/utils.js +2 -6
- package/package.json +7 -2
- package/src/commands/email.ts +14 -4
- package/src/commands/image.ts +47 -7
- package/src/commands/pixel.ts +62 -0
- package/src/commands/storage.ts +37 -13
- package/src/commands/url.ts +28 -0
- package/src/commands/webhook.ts +50 -9
- package/src/commands/workflow.ts +67 -19
- package/src/config.ts +17 -5
- package/src/index.ts +59 -1
package/dist/commands/email.js
CHANGED
|
@@ -1,73 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.inbox = inbox;
|
|
8
|
-
exports.outbox = outbox;
|
|
9
|
-
exports.listTemplates = listTemplates;
|
|
10
|
-
exports.generateTemplate = generateTemplate;
|
|
11
|
-
exports.listCampaigns = listCampaigns;
|
|
12
|
-
exports.campaignStats = campaignStats;
|
|
13
|
-
exports.run = run;
|
|
14
|
-
const sdk_1 = require("@myapihq/sdk");
|
|
15
|
-
const config_js_1 = require("../config.js");
|
|
16
|
-
const output_js_1 = require("../output.js");
|
|
17
|
-
const utils_js_1 = require("../utils.js");
|
|
18
|
-
async function createMailbox(flags) {
|
|
19
|
-
const config = (0, config_js_1.requireConfig)();
|
|
1
|
+
import { email as sdkEmail } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable, printJson, info } from '../output.js';
|
|
4
|
+
import { sleep } from '../utils.js';
|
|
5
|
+
export async function createMailbox(flags) {
|
|
6
|
+
const config = requireConfig();
|
|
20
7
|
const orgId = flags.org || config.default_org;
|
|
21
8
|
const domain = flags.domain || config.default_domain;
|
|
22
9
|
if (!orgId || !domain || !flags.username) {
|
|
23
|
-
|
|
10
|
+
error("Missing required arguments.\nUsage: myapi email create-mailbox --org <id> --domain <domain> --username <user>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
|
|
24
11
|
}
|
|
25
|
-
const address = await
|
|
26
|
-
|
|
12
|
+
const address = await sdkEmail.createMailbox(config.api_key, orgId, domain, flags.username);
|
|
13
|
+
success(`Mailbox created: ${address.address}`);
|
|
27
14
|
}
|
|
28
|
-
async function listMailboxes(flags) {
|
|
29
|
-
const config =
|
|
15
|
+
export async function listMailboxes(flags) {
|
|
16
|
+
const config = requireConfig();
|
|
30
17
|
const orgId = flags.org || config.default_org;
|
|
31
18
|
if (!orgId)
|
|
32
|
-
|
|
19
|
+
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>)");
|
|
33
20
|
if (!flags.domain && flags.filter !== 'unassigned')
|
|
34
|
-
|
|
35
|
-
const mailboxes = await
|
|
21
|
+
error("Must provide either --domain <domain> or --filter unassigned");
|
|
22
|
+
const mailboxes = await sdkEmail.listMailboxes(config.api_key, orgId, {
|
|
36
23
|
domain: flags.domain,
|
|
37
24
|
filter: flags.filter === 'unassigned' ? 'unassigned' : undefined
|
|
38
25
|
});
|
|
39
|
-
|
|
26
|
+
printTable(mailboxes);
|
|
40
27
|
}
|
|
41
|
-
async function sent(flags) {
|
|
42
|
-
const config =
|
|
28
|
+
export async function sent(flags) {
|
|
29
|
+
const config = requireConfig();
|
|
43
30
|
const orgId = flags.org || config.default_org;
|
|
44
31
|
if (!orgId)
|
|
45
|
-
|
|
32
|
+
error("Missing required arguments.\nUsage: myapi email sent --org <id> [--limit <num>] [--offset <num>]\n(Or set defaults via: myapi config set-org <id>)");
|
|
46
33
|
const limit = parseInt(flags.limit) || 50;
|
|
47
34
|
const offset = parseInt(flags.offset) || 0;
|
|
48
|
-
const emails = await
|
|
49
|
-
|
|
35
|
+
const emails = await sdkEmail.getSentEmails(config.api_key, orgId, limit, offset);
|
|
36
|
+
printTable(emails);
|
|
50
37
|
}
|
|
51
|
-
async function send(flags) {
|
|
52
|
-
const config =
|
|
38
|
+
export async function send(flags) {
|
|
39
|
+
const config = requireConfig();
|
|
53
40
|
const orgId = flags.org || config.default_org;
|
|
54
41
|
if (!orgId || !flags.from || !flags.to || !flags.subject) {
|
|
55
|
-
|
|
42
|
+
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>]]");
|
|
56
43
|
}
|
|
57
44
|
if (!flags.body && !flags['template-id'])
|
|
58
|
-
|
|
45
|
+
error("Must provide either --body or --template-id");
|
|
59
46
|
if (flags.body && flags['template-id'])
|
|
60
|
-
|
|
47
|
+
error("Cannot provide both --body and --template-id");
|
|
61
48
|
let templateVars;
|
|
62
49
|
if (flags['template-vars']) {
|
|
63
50
|
try {
|
|
64
51
|
templateVars = JSON.parse(flags['template-vars']);
|
|
65
52
|
}
|
|
66
53
|
catch (e) {
|
|
67
|
-
|
|
54
|
+
error("--template-vars must be a valid JSON string");
|
|
68
55
|
}
|
|
69
56
|
}
|
|
70
|
-
const res = await
|
|
57
|
+
const res = await sdkEmail.sendEmail(config.api_key, orgId, {
|
|
71
58
|
from: flags.from,
|
|
72
59
|
to: [flags.to],
|
|
73
60
|
subject: flags.subject,
|
|
@@ -75,39 +62,50 @@ async function send(flags) {
|
|
|
75
62
|
template_id: flags['template-id'],
|
|
76
63
|
template_vars: templateVars
|
|
77
64
|
});
|
|
78
|
-
|
|
65
|
+
success(`Email sent! Message ID: ${res.message_id}`);
|
|
79
66
|
}
|
|
80
|
-
async function inbox(address, flags) {
|
|
81
|
-
const config =
|
|
67
|
+
export async function inbox(address, flags) {
|
|
68
|
+
const config = requireConfig();
|
|
82
69
|
const orgId = flags.org || config.default_org;
|
|
83
70
|
if (!orgId || !address)
|
|
84
|
-
|
|
85
|
-
const messages = await
|
|
86
|
-
|
|
71
|
+
error("Missing required arguments.\nUsage: myapi email inbox <address> --org <id>");
|
|
72
|
+
const messages = await sdkEmail.getInbox(config.api_key, orgId, address);
|
|
73
|
+
printTable(messages);
|
|
87
74
|
}
|
|
88
|
-
async function outbox(address, flags) {
|
|
89
|
-
const config =
|
|
75
|
+
export async function outbox(address, flags) {
|
|
76
|
+
const config = requireConfig();
|
|
90
77
|
const orgId = flags.org || config.default_org;
|
|
91
78
|
if (!orgId || !address)
|
|
92
|
-
|
|
93
|
-
const messages = await
|
|
94
|
-
|
|
79
|
+
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);
|
|
95
82
|
}
|
|
96
|
-
async function listTemplates(flags) {
|
|
97
|
-
const config =
|
|
83
|
+
export async function listTemplates(flags) {
|
|
84
|
+
const config = requireConfig();
|
|
98
85
|
const orgId = flags.org || config.default_org;
|
|
99
86
|
if (!orgId)
|
|
100
|
-
|
|
101
|
-
const templates = await
|
|
102
|
-
(
|
|
87
|
+
error("Missing required arguments.\nUsage: myapi email list-templates --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
88
|
+
const templates = await sdkEmail.listTemplates(config.api_key, orgId);
|
|
89
|
+
if (flags.json)
|
|
90
|
+
printJson(templates);
|
|
91
|
+
else
|
|
92
|
+
printTable(templates);
|
|
93
|
+
}
|
|
94
|
+
export async function deleteTemplate(id, flags) {
|
|
95
|
+
const config = requireConfig();
|
|
96
|
+
const orgId = flags.org || config.default_org;
|
|
97
|
+
if (!orgId || !id)
|
|
98
|
+
error("Missing required arguments.\nUsage: myapi email delete-template <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
99
|
+
await sdkEmail.deleteTemplate(config.api_key, orgId, id);
|
|
100
|
+
success(`Deleted template ${id}`);
|
|
103
101
|
}
|
|
104
|
-
async function generateTemplate(flags) {
|
|
105
|
-
const config =
|
|
102
|
+
export async function generateTemplate(flags) {
|
|
103
|
+
const config = requireConfig();
|
|
106
104
|
const orgId = flags.org || config.default_org;
|
|
107
105
|
if (!orgId || !flags.prompt || !flags.name) {
|
|
108
|
-
|
|
106
|
+
error("Missing required arguments.\nUsage: myapi email generate-template --org <id> --prompt <str> --name <str>");
|
|
109
107
|
}
|
|
110
|
-
const job = await
|
|
108
|
+
const job = await sdkEmail.generateTemplate(config.api_key, orgId, {
|
|
111
109
|
prompt: flags.prompt,
|
|
112
110
|
name: flags.name
|
|
113
111
|
});
|
|
@@ -116,65 +114,67 @@ async function generateTemplate(flags) {
|
|
|
116
114
|
let i = 0;
|
|
117
115
|
let elapsed = 0;
|
|
118
116
|
while (elapsed < 90000) {
|
|
119
|
-
const status = await
|
|
117
|
+
const status = await sdkEmail.getTemplateJobStatus(config.api_key, orgId, job.job_id);
|
|
120
118
|
if (status.status === 'completed') {
|
|
121
119
|
process.stdout.write('\r\x1b[K');
|
|
122
|
-
|
|
120
|
+
success(`Template generated! ID: ${status.template_id}\nPreview: ${status.result?.preview_url}`);
|
|
123
121
|
return;
|
|
124
122
|
}
|
|
125
123
|
if (status.status === 'failed') {
|
|
126
124
|
process.stdout.write('\r\x1b[K');
|
|
127
|
-
|
|
125
|
+
error("Template generation failed");
|
|
128
126
|
}
|
|
129
127
|
process.stdout.write(`\rGenerating template ${chars[i++ % chars.length]}`);
|
|
130
|
-
await
|
|
128
|
+
await sleep(3000);
|
|
131
129
|
elapsed += 3000;
|
|
132
130
|
}
|
|
133
131
|
process.stdout.write('\r\x1b[K');
|
|
134
|
-
|
|
132
|
+
error("Template generation timed out");
|
|
135
133
|
}
|
|
136
|
-
async function listCampaigns(flags) {
|
|
137
|
-
const config =
|
|
134
|
+
export async function listCampaigns(flags) {
|
|
135
|
+
const config = requireConfig();
|
|
138
136
|
const orgId = flags.org || config.default_org;
|
|
139
137
|
if (!orgId)
|
|
140
|
-
|
|
141
|
-
const campaigns = await
|
|
142
|
-
|
|
138
|
+
error("Missing required arguments.\nUsage: myapi email list-campaigns --org <id>\n(Or set a default org via: myapi config set-org <id>)");
|
|
139
|
+
const campaigns = await sdkEmail.listCampaigns(config.api_key, orgId);
|
|
140
|
+
printTable(campaigns);
|
|
143
141
|
}
|
|
144
|
-
async function campaignStats(id, flags) {
|
|
145
|
-
const config =
|
|
142
|
+
export async function campaignStats(id, flags) {
|
|
143
|
+
const config = requireConfig();
|
|
146
144
|
const orgId = flags.org || config.default_org;
|
|
147
145
|
if (!orgId || !id)
|
|
148
|
-
|
|
149
|
-
const stats = await
|
|
150
|
-
|
|
146
|
+
error("Missing required arguments.\nUsage: myapi email campaign-stats <id> --org <id>");
|
|
147
|
+
const stats = await sdkEmail.getCampaignStats(config.api_key, orgId, id);
|
|
148
|
+
printJson(stats);
|
|
151
149
|
}
|
|
152
|
-
async function run(subcommand, args, flags) {
|
|
150
|
+
export async function run(subcommand, args, flags) {
|
|
153
151
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
154
|
-
|
|
152
|
+
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 delete-template Delete a template\n list-campaigns List campaigns\n campaign-stats Get campaign stats\n\nNote: All email commands require the --org <id> flag.');
|
|
155
153
|
return;
|
|
156
154
|
}
|
|
157
155
|
if (flags.help) {
|
|
158
156
|
if (subcommand === 'create-mailbox')
|
|
159
|
-
|
|
157
|
+
info('Usage: myapi email create-mailbox --org <id> --domain <domain> --username <user>');
|
|
160
158
|
else if (subcommand === 'list-mailboxes')
|
|
161
|
-
|
|
159
|
+
info('Usage: myapi email list-mailboxes --org <id> [--domain <domain> | --filter unassigned]');
|
|
162
160
|
else if (subcommand === 'send')
|
|
163
|
-
|
|
161
|
+
info('Usage: myapi email send --org <id> --from <email> --to <email> --subject <str> [--body <str> | --template-id <id> [--template-vars <json_str>]]');
|
|
164
162
|
else if (subcommand === 'sent')
|
|
165
|
-
|
|
163
|
+
info('Usage: myapi email sent --org <id> [--limit <num>] [--offset <num>]');
|
|
166
164
|
else if (subcommand === 'inbox')
|
|
167
|
-
|
|
165
|
+
info('Usage: myapi email inbox <address> --org <id>');
|
|
168
166
|
else if (subcommand === 'outbox')
|
|
169
|
-
|
|
167
|
+
info('Usage: myapi email outbox <address> --org <id>');
|
|
170
168
|
else if (subcommand === 'list-templates')
|
|
171
|
-
|
|
169
|
+
info('Usage: myapi email list-templates --org <id>');
|
|
172
170
|
else if (subcommand === 'generate-template')
|
|
173
|
-
|
|
171
|
+
info('Usage: myapi email generate-template --org <id> --prompt <str> --name <str>');
|
|
172
|
+
else if (subcommand === 'delete-template')
|
|
173
|
+
info('Usage: myapi email delete-template <id> --org <id>');
|
|
174
174
|
else if (subcommand === 'list-campaigns')
|
|
175
|
-
|
|
175
|
+
info('Usage: myapi email list-campaigns --org <id>');
|
|
176
176
|
else if (subcommand === 'campaign-stats')
|
|
177
|
-
|
|
177
|
+
info('Usage: myapi email campaign-stats <campaign_id> --org <id>');
|
|
178
178
|
return;
|
|
179
179
|
}
|
|
180
180
|
if (subcommand === 'create-mailbox')
|
|
@@ -193,10 +193,12 @@ async function run(subcommand, args, flags) {
|
|
|
193
193
|
await listTemplates(flags);
|
|
194
194
|
else if (subcommand === 'generate-template')
|
|
195
195
|
await generateTemplate(flags);
|
|
196
|
+
else if (subcommand === 'delete-template')
|
|
197
|
+
await deleteTemplate(args[0], flags);
|
|
196
198
|
else if (subcommand === 'list-campaigns')
|
|
197
199
|
await listCampaigns(flags);
|
|
198
200
|
else if (subcommand === 'campaign-stats')
|
|
199
201
|
await campaignStats(args[0], flags);
|
|
200
202
|
else
|
|
201
|
-
|
|
203
|
+
error(`Unknown subcommand: ${subcommand}. Run "myapi email --help" for a list of valid subcommands.`);
|
|
202
204
|
}
|
package/dist/commands/funnel.js
CHANGED
|
@@ -1,54 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.del = del;
|
|
7
|
-
exports.push = push;
|
|
8
|
-
exports.verify = verify;
|
|
9
|
-
exports.run = run;
|
|
10
|
-
const sdk_1 = require("@myapihq/sdk");
|
|
11
|
-
const config_js_1 = require("../config.js");
|
|
12
|
-
const output_js_1 = require("../output.js");
|
|
13
|
-
async function list(flags) {
|
|
14
|
-
const config = (0, config_js_1.requireConfig)();
|
|
1
|
+
import { funnel as sdkFunnel } 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();
|
|
15
6
|
const orgId = flags.org || config.default_org;
|
|
16
7
|
if (!orgId)
|
|
17
|
-
|
|
18
|
-
const funnels = await
|
|
19
|
-
|
|
8
|
+
error("Missing required arguments.\nUsage: myapi funnel list --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
9
|
+
const funnels = await sdkFunnel.listFunnels(config.api_key, orgId);
|
|
10
|
+
printTable(funnels);
|
|
20
11
|
}
|
|
21
|
-
async function create(flags) {
|
|
22
|
-
const config =
|
|
12
|
+
export async function create(flags) {
|
|
13
|
+
const config = requireConfig();
|
|
23
14
|
const orgId = flags.org || config.default_org;
|
|
24
15
|
const domain = flags.domain || config.default_domain;
|
|
25
16
|
if (!orgId || !domain) {
|
|
26
|
-
|
|
17
|
+
error("Missing required arguments.\nUsage: myapi funnel create --org <id> --domain <domain>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
|
|
27
18
|
}
|
|
28
|
-
const funnel = await
|
|
29
|
-
|
|
19
|
+
const funnel = await sdkFunnel.createFunnel(config.api_key, orgId, domain);
|
|
20
|
+
success(`Funnel created! ID: ${funnel.id}`);
|
|
30
21
|
}
|
|
31
|
-
async function get(id, flags) {
|
|
32
|
-
const config =
|
|
22
|
+
export async function get(id, flags) {
|
|
23
|
+
const config = requireConfig();
|
|
33
24
|
const orgId = flags.org || config.default_org;
|
|
34
25
|
if (!orgId || !id)
|
|
35
|
-
|
|
36
|
-
const funnel = await
|
|
37
|
-
|
|
26
|
+
error("Missing required arguments.\nUsage: myapi funnel get <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
27
|
+
const funnel = await sdkFunnel.getFunnel(config.api_key, orgId, id);
|
|
28
|
+
printJson(funnel);
|
|
38
29
|
}
|
|
39
|
-
async function del(id, flags) {
|
|
40
|
-
const config =
|
|
30
|
+
export async function del(id, flags) {
|
|
31
|
+
const config = requireConfig();
|
|
41
32
|
const orgId = flags.org || config.default_org;
|
|
42
33
|
if (!orgId || !id)
|
|
43
|
-
|
|
44
|
-
await
|
|
45
|
-
|
|
34
|
+
error("Missing required arguments.\nUsage: myapi funnel delete <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
35
|
+
await sdkFunnel.deleteFunnel(config.api_key, orgId, id);
|
|
36
|
+
success(`Funnel ${id} deleted`);
|
|
46
37
|
}
|
|
47
|
-
async function push(id, slug, flags) {
|
|
48
|
-
const config =
|
|
38
|
+
export async function push(id, slug, flags) {
|
|
39
|
+
const config = requireConfig();
|
|
49
40
|
const orgId = flags.org || config.default_org;
|
|
50
41
|
if (!orgId || !id || !slug) {
|
|
51
|
-
|
|
42
|
+
error("Missing required arguments.\nUsage: myapi funnel push <funnel_id> <slug> --org <id> < index.html\n(Or set defaults via: myapi config set-org <id>)");
|
|
52
43
|
}
|
|
53
44
|
const html = await new Promise((resolve, reject) => {
|
|
54
45
|
let data = '';
|
|
@@ -58,39 +49,39 @@ async function push(id, slug, flags) {
|
|
|
58
49
|
process.stdin.on('error', reject);
|
|
59
50
|
});
|
|
60
51
|
if (!html)
|
|
61
|
-
|
|
62
|
-
await
|
|
63
|
-
|
|
52
|
+
error("No HTML provided via stdin");
|
|
53
|
+
await sdkFunnel.pushFunnelPage(config.api_key, orgId, id, { slug, html });
|
|
54
|
+
success(`Pushed page to ${slug}`);
|
|
64
55
|
}
|
|
65
|
-
async function verify(id, flags) {
|
|
66
|
-
const config =
|
|
56
|
+
export async function verify(id, flags) {
|
|
57
|
+
const config = requireConfig();
|
|
67
58
|
const orgId = flags.org || config.default_org;
|
|
68
59
|
if (!orgId || !id)
|
|
69
|
-
|
|
60
|
+
error("Missing required arguments.\nUsage: myapi funnel verify <id> --org <id> [--slug <slug>]\n(Or set defaults via: myapi config set-org <id>)");
|
|
70
61
|
const opts = {};
|
|
71
62
|
if (flags.slug)
|
|
72
63
|
opts.slug = flags.slug;
|
|
73
|
-
const v = await
|
|
74
|
-
|
|
64
|
+
const v = await sdkFunnel.verifyFunnel(config.api_key, orgId, id, opts);
|
|
65
|
+
printJson(v);
|
|
75
66
|
}
|
|
76
|
-
async function run(subcommand, args, flags) {
|
|
67
|
+
export async function run(subcommand, args, flags) {
|
|
77
68
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
78
|
-
|
|
69
|
+
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.');
|
|
79
70
|
return;
|
|
80
71
|
}
|
|
81
72
|
if (flags.help) {
|
|
82
73
|
if (subcommand === 'list')
|
|
83
|
-
|
|
74
|
+
info('Usage: myapi funnel list --org <id>');
|
|
84
75
|
else if (subcommand === 'create')
|
|
85
|
-
|
|
76
|
+
info('Usage: myapi funnel create --org <id> --domain <domain>');
|
|
86
77
|
else if (subcommand === 'get')
|
|
87
|
-
|
|
78
|
+
info('Usage: myapi funnel get <id> --org <id>');
|
|
88
79
|
else if (subcommand === 'delete')
|
|
89
|
-
|
|
80
|
+
info('Usage: myapi funnel delete <id> --org <id>');
|
|
90
81
|
else if (subcommand === 'push')
|
|
91
|
-
|
|
82
|
+
info('Usage: myapi funnel push <funnel_id> <slug> --org <id> < index.html\n\nPushes HTML content from stdin to the specified funnel.');
|
|
92
83
|
else if (subcommand === 'verify')
|
|
93
|
-
|
|
84
|
+
info('Usage: myapi funnel verify <id> --org <id> [--slug <slug>]\n\nVerifies syntax and structure before pushing.');
|
|
94
85
|
return;
|
|
95
86
|
}
|
|
96
87
|
if (subcommand === 'list')
|
|
@@ -106,5 +97,5 @@ async function run(subcommand, args, flags) {
|
|
|
106
97
|
else if (subcommand === 'verify')
|
|
107
98
|
await verify(args[0], flags);
|
|
108
99
|
else
|
|
109
|
-
|
|
100
|
+
error(`Unknown subcommand: ${subcommand}. Run "myapi funnel --help" for a list of valid subcommands.`);
|
|
110
101
|
}
|
package/dist/commands/image.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare function generate(flags: Record<string, string | boolean>): Promise<void>;
|
|
2
2
|
export declare function list(flags: Record<string, string | boolean>): Promise<void>;
|
|
3
|
+
export declare function del(id: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
4
|
+
export declare function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>): Promise<void>;
|
package/dist/commands/image.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
(0, output_js_1.error)("Missing --prompt flag");
|
|
12
|
-
const config = (0, config_js_1.requireConfig)();
|
|
1
|
+
import { image as sdkImage } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable, info, printJson } from '../output.js';
|
|
4
|
+
import { sleep } from '../utils.js';
|
|
5
|
+
export async function generate(flags) {
|
|
6
|
+
const config = requireConfig();
|
|
7
|
+
const orgId = flags.org || config.default_org;
|
|
8
|
+
if (!orgId || !flags.prompt) {
|
|
9
|
+
error("Missing required arguments.\nUsage: myapi image generate --prompt <text> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
10
|
+
}
|
|
13
11
|
const payload = { prompt: flags.prompt };
|
|
14
12
|
if (flags.ratio)
|
|
15
13
|
payload.aspect_ratio = flags.ratio;
|
|
@@ -17,31 +15,72 @@ async function generate(flags) {
|
|
|
17
15
|
payload.style = flags.style;
|
|
18
16
|
if (flags.colors)
|
|
19
17
|
payload.colors = flags.colors;
|
|
20
|
-
const res = await
|
|
18
|
+
const res = await sdkImage.generateImage(config.api_key, orgId, payload);
|
|
21
19
|
process.stdout.write("Generating image ");
|
|
22
20
|
const chars = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
23
21
|
let i = 0;
|
|
24
22
|
let elapsed = 0;
|
|
25
23
|
while (elapsed < 60000) {
|
|
26
|
-
const job = await
|
|
24
|
+
const job = await sdkImage.getImageJob(config.api_key, orgId, res.job_id);
|
|
27
25
|
if (job.status === 'completed') {
|
|
28
26
|
process.stdout.write('\r\x1b[K');
|
|
29
|
-
|
|
27
|
+
if (flags.json)
|
|
28
|
+
printJson(job);
|
|
29
|
+
else
|
|
30
|
+
success(`Image generated!\nURL: ${job.url}`);
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
33
|
if (job.status === 'failed') {
|
|
33
34
|
process.stdout.write('\r\x1b[K');
|
|
34
|
-
|
|
35
|
+
error(`Image generation failed: ${job.error || 'Unknown error'}`);
|
|
35
36
|
}
|
|
36
37
|
process.stdout.write(`\rGenerating image ${chars[i++ % chars.length]}`);
|
|
37
|
-
await
|
|
38
|
+
await sleep(3000);
|
|
38
39
|
elapsed += 3000;
|
|
39
40
|
}
|
|
40
41
|
process.stdout.write('\r\x1b[K');
|
|
41
|
-
|
|
42
|
+
error("Image generation timed out");
|
|
43
|
+
}
|
|
44
|
+
export async function list(flags) {
|
|
45
|
+
const config = requireConfig();
|
|
46
|
+
const orgId = flags.org || config.default_org;
|
|
47
|
+
if (!orgId)
|
|
48
|
+
error("Missing required arguments.\nUsage: myapi image list --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
49
|
+
const images = await sdkImage.listImages(config.api_key, orgId);
|
|
50
|
+
if (flags.json)
|
|
51
|
+
printJson(images);
|
|
52
|
+
else
|
|
53
|
+
printTable(images);
|
|
54
|
+
}
|
|
55
|
+
export async function del(id, flags) {
|
|
56
|
+
const config = requireConfig();
|
|
57
|
+
const orgId = flags.org || config.default_org;
|
|
58
|
+
if (!orgId || !id) {
|
|
59
|
+
error("Missing required arguments.\nUsage: myapi image delete <job_id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
60
|
+
}
|
|
61
|
+
await sdkImage.deleteImage(config.api_key, orgId, id);
|
|
62
|
+
success(`Image deleted! (Job ${id} history retained, URL nullified)`);
|
|
42
63
|
}
|
|
43
|
-
async function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
64
|
+
export async function run(subcommand, args, flags) {
|
|
65
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
66
|
+
info('Usage: myapi image <subcommand>\n\nSubcommands:\n list List all your generated images\n generate Generate a new AI image from a prompt\n delete Delete the physical image file for a job\n\nNote: All image commands require the --org <id> flag.');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (flags.help) {
|
|
70
|
+
if (subcommand === 'list')
|
|
71
|
+
info('Usage: myapi image list --org <id> [--json]');
|
|
72
|
+
else if (subcommand === 'generate')
|
|
73
|
+
info('Usage: myapi image generate --prompt "<text>" [--ratio <1:1|16:9>] [--style <style>] [--colors <hex_list>] --org <id>\n\nGenerates an AI image and polls until the public URL is ready. Costs $0.05 per generation.');
|
|
74
|
+
else if (subcommand === 'delete')
|
|
75
|
+
info('Usage: myapi image delete <job_id> --org <id>\n\nDeletes the physical image file from storage. The generation job history is kept, but its URL will become null.');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (subcommand === 'list')
|
|
79
|
+
await list(flags);
|
|
80
|
+
else if (subcommand === 'generate')
|
|
81
|
+
await generate(flags);
|
|
82
|
+
else if (subcommand === 'delete')
|
|
83
|
+
await del(args[0], flags);
|
|
84
|
+
else
|
|
85
|
+
error(`Unknown subcommand: ${subcommand}. Run "myapi image --help" for a list of valid subcommands.`);
|
|
47
86
|
}
|