@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/auth.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare
|
|
1
|
+
import type { FlagSchema } from '../flags.js';
|
|
2
|
+
import type { Flags } from '../helpers.js';
|
|
3
|
+
export declare const SCHEMA: FlagSchema;
|
|
4
|
+
export declare const HELP = "Usage: myapi auth <subcommand>\n\nSubcommands:\n setup Configure your account\n import-key Import an existing API key non-interactively\n whoami Show current account \u00B7 supports --json\n link [email] Upgrade anonymous account to registered (or add a second session)\n Use myapi auth setup to create a completely new account\n switch [index] Switch active account by index or email\n config Manage CLI defaults (org, funnel, domain) \u00B7 supports set-org / set-funnel / set-domain\n install-skills Install or update the MyAPI skills pack for AI agents\n api-keys Manage API keys \u00B7 list / create / revoke\n keys Alias for api-keys";
|
|
5
|
+
export declare const INSTALL_SKILLS_HELP = "Usage: myapi auth install-skills\n\nInstalls the MyAPI skills pack for AI coding agents (Claude, Gemini, Cursor).\n\nThis command writes skill definition files to:\n ~/.agents/skills/myapi/\n\nAnd creates symlinks in the appropriate agent config directories:\n ~/.claude/ (Claude)\n ~/.gemini/ (Gemini)\n ~/.cursor/ (Cursor, if detected)\n\nThese files teach agents how to use the MyAPI CLI and API directly.\nRun this command again to update existing skills to the latest version.";
|
|
6
|
+
export declare function link(flags?: Flags, emailArg?: string): Promise<void>;
|
|
7
|
+
export declare function whoami(flags?: Flags): Promise<void>;
|
|
8
|
+
export declare function switchCmd(flags?: Flags, indexArg?: string): Promise<void>;
|
package/dist/commands/auth.js
CHANGED
|
@@ -3,7 +3,14 @@ import { loadConfig, saveConfig, addAccount, switchAccount, listAccounts } from
|
|
|
3
3
|
import { info, success, error, printJson } from '../output.js';
|
|
4
4
|
import { installSkills } from './setup.js';
|
|
5
5
|
import { hq } from '@myapihq/sdk';
|
|
6
|
-
const
|
|
6
|
+
export const SCHEMA = {
|
|
7
|
+
'install-skills': 'boolean',
|
|
8
|
+
'no-skills': 'boolean',
|
|
9
|
+
anonymous: 'boolean',
|
|
10
|
+
anon: 'boolean',
|
|
11
|
+
};
|
|
12
|
+
export const HELP = 'Usage: myapi auth <subcommand>\n\nSubcommands:\n setup Configure your account\n import-key Import an existing API key non-interactively\n whoami Show current account · supports --json\n link [email] Upgrade anonymous account to registered (or add a second session)\n Use myapi auth setup to create a completely new account\n switch [index] Switch active account by index or email\n config Manage CLI defaults (org, funnel, domain) · supports set-org / set-funnel / set-domain\n install-skills Install or update the MyAPI skills pack for AI agents\n api-keys Manage API keys · list / create / revoke\n keys Alias for api-keys';
|
|
13
|
+
export const INSTALL_SKILLS_HELP = 'Usage: myapi auth install-skills\n\nInstalls the MyAPI skills pack for AI coding agents (Claude, Gemini, Cursor).\n\nThis command writes skill definition files to:\n ~/.agents/skills/myapi/\n\nAnd creates symlinks in the appropriate agent config directories:\n ~/.claude/ (Claude)\n ~/.gemini/ (Gemini)\n ~/.cursor/ (Cursor, if detected)\n\nThese files teach agents how to use the MyAPI CLI and API directly.\nRun this command again to update existing skills to the latest version.';
|
|
7
14
|
function ask(rl, q) {
|
|
8
15
|
return new Promise(resolve => rl.question(q, resolve));
|
|
9
16
|
}
|
|
@@ -13,31 +20,6 @@ function yn(answer, defaultYes = true) {
|
|
|
13
20
|
return defaultYes;
|
|
14
21
|
return t === 'y' || t === 'yes';
|
|
15
22
|
}
|
|
16
|
-
async function post(path, body, apiKey) {
|
|
17
|
-
const headers = { 'Content-Type': 'application/json' };
|
|
18
|
-
if (apiKey)
|
|
19
|
-
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
20
|
-
const res = await fetch(`${API_BASE}${path}`, {
|
|
21
|
-
method: 'POST',
|
|
22
|
-
headers,
|
|
23
|
-
body: JSON.stringify(body),
|
|
24
|
-
});
|
|
25
|
-
const json = await res.json();
|
|
26
|
-
if (!res.ok)
|
|
27
|
-
throw new Error(json.error ?? `HTTP ${res.status}`);
|
|
28
|
-
return json.data ?? json;
|
|
29
|
-
}
|
|
30
|
-
async function patch(path, body, apiKey) {
|
|
31
|
-
const res = await fetch(`${API_BASE}${path}`, {
|
|
32
|
-
method: 'PATCH',
|
|
33
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}` },
|
|
34
|
-
body: JSON.stringify(body),
|
|
35
|
-
});
|
|
36
|
-
const json = await res.json();
|
|
37
|
-
if (!res.ok)
|
|
38
|
-
throw new Error(json.error ?? `HTTP ${res.status}`);
|
|
39
|
-
return json.data ?? json;
|
|
40
|
-
}
|
|
41
23
|
// myapi auth link — upgrade anonymous session to registered account.
|
|
42
24
|
export async function link(flags = {}, emailArg) {
|
|
43
25
|
if (flags.help) {
|
|
@@ -56,7 +38,7 @@ export async function link(flags = {}, emailArg) {
|
|
|
56
38
|
error(`Invalid email address: "${email}".`);
|
|
57
39
|
let upgradeOk = true;
|
|
58
40
|
try {
|
|
59
|
-
await
|
|
41
|
+
await hq.upgradeAccount(config.api_key, email);
|
|
60
42
|
}
|
|
61
43
|
catch (err) {
|
|
62
44
|
if (err.message !== 'EMAIL_TAKEN')
|
|
@@ -67,11 +49,11 @@ export async function link(flags = {}, emailArg) {
|
|
|
67
49
|
const ans = (await ask(rl, '› Sign in and add it as a second account? (Y/n) ')).trim();
|
|
68
50
|
if (!yn(ans))
|
|
69
51
|
return;
|
|
70
|
-
await
|
|
52
|
+
await hq.sendCode(email);
|
|
71
53
|
}
|
|
72
54
|
info(`› Sent a code to ${email} · paste it below`);
|
|
73
55
|
const code = (await ask(rl, '› Code? ')).trim();
|
|
74
|
-
const data = await
|
|
56
|
+
const data = await hq.verifyCode(email, code);
|
|
75
57
|
const skillsFromFlag = flags['install-skills'] ? true : flags['no-skills'] ? false : null;
|
|
76
58
|
const wantsSkills = skillsFromFlag !== null ? skillsFromFlag : yn((await ask(rl, '› Install the MyAPI skills pack? (Y/n) ')).trim());
|
|
77
59
|
if (upgradeOk) {
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare
|
|
4
|
-
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 run(subcommand: string | undefined, args: string[], flags: Flags): Promise<void>;
|
|
5
|
+
export declare function balance(flags: Flags): Promise<void>;
|
|
6
|
+
export declare function history(flags: Flags): Promise<void>;
|
|
7
|
+
export declare function topup(amountStr: string, flags: Flags): Promise<void>;
|
|
8
|
+
export declare function setup(_flags: Flags): Promise<void>;
|
package/dist/commands/billing.js
CHANGED
|
@@ -3,11 +3,46 @@ import { hq } from '@myapihq/sdk';
|
|
|
3
3
|
import { requireConfig } from '../config.js';
|
|
4
4
|
import { success, error, printTable, info, printJson } from '../output.js';
|
|
5
5
|
import { formatDate } from '../utils.js';
|
|
6
|
-
export
|
|
6
|
+
export const SCHEMA = {};
|
|
7
|
+
const SUBCOMMAND_USAGE = {
|
|
8
|
+
'balance': 'myapi billing balance [--json]',
|
|
9
|
+
'history': 'myapi billing history [--json]',
|
|
10
|
+
'topup': `myapi billing topup <amount> [--yes]
|
|
11
|
+
|
|
12
|
+
Amount is in whole dollars (e.g. "10" charges $10).
|
|
13
|
+
Confirmation is required for amounts of $50 or more — pass --yes to skip it.
|
|
14
|
+
|
|
15
|
+
Example: myapi billing topup 10`,
|
|
16
|
+
'setup': 'myapi billing setup',
|
|
17
|
+
};
|
|
18
|
+
export async function run(subcommand, args, flags) {
|
|
19
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
20
|
+
info(`Usage: myapi billing <subcommand>
|
|
21
|
+
|
|
22
|
+
Subcommands:
|
|
23
|
+
balance Check balance, credits, and payment method status
|
|
24
|
+
history View recent transactions and top-ups
|
|
25
|
+
topup Top up your balance (whole dollars)
|
|
26
|
+
setup Open a checkout link to add or update payment method`);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
7
29
|
if (flags.help) {
|
|
8
|
-
|
|
30
|
+
const usage = SUBCOMMAND_USAGE[subcommand];
|
|
31
|
+
if (usage)
|
|
32
|
+
info(`Usage: ${usage}`);
|
|
33
|
+
else
|
|
34
|
+
info(`Unknown subcommand: ${subcommand}. Run "myapi billing --help" for the list.`);
|
|
9
35
|
return;
|
|
10
36
|
}
|
|
37
|
+
switch (subcommand) {
|
|
38
|
+
case 'balance': return balance(flags);
|
|
39
|
+
case 'history': return history(flags);
|
|
40
|
+
case 'topup': return topup(args[0], flags);
|
|
41
|
+
case 'setup': return setup(flags);
|
|
42
|
+
default: error(`Unknown subcommand: ${subcommand}. Run "myapi billing --help" for available subcommands.`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export async function balance(flags) {
|
|
11
46
|
const config = requireConfig();
|
|
12
47
|
const result = await hq.getBalance(config.api_key);
|
|
13
48
|
if (flags.json) {
|
|
@@ -24,37 +59,27 @@ export async function balance(flags) {
|
|
|
24
59
|
info(`Balance: ${result.balance_display} | Credits: ${result.credits_display} (not usable for domains) | Payment method: ${pm}`);
|
|
25
60
|
}
|
|
26
61
|
export async function history(flags) {
|
|
27
|
-
if (flags.help) {
|
|
28
|
-
info('Usage: myapi billing history [--json]\n\nShows your recent billing transactions and top-ups.\n\nFlags:\n --json Output raw JSON');
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
62
|
const config = requireConfig();
|
|
32
63
|
const items = await hq.getBillingHistory(config.api_key);
|
|
33
64
|
if (flags.json) {
|
|
34
65
|
printJson(items);
|
|
35
66
|
return;
|
|
36
67
|
}
|
|
37
|
-
if (items.length === 0) {
|
|
38
|
-
info('No transactions yet.');
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
68
|
const formattedItems = items.map(item => ({
|
|
42
69
|
Type: item.type || 'unknown',
|
|
43
70
|
Amount: item.amount_display,
|
|
44
71
|
Status: item.status ? item.status.charAt(0).toUpperCase() + item.status.slice(1) : '',
|
|
45
72
|
Date: formatDate(item.created_at),
|
|
46
73
|
}));
|
|
47
|
-
printTable(formattedItems
|
|
74
|
+
printTable(formattedItems, {
|
|
75
|
+
flags,
|
|
76
|
+
empty: 'No transactions yet.',
|
|
77
|
+
});
|
|
48
78
|
}
|
|
49
79
|
export async function topup(amountStr, flags) {
|
|
50
|
-
if (flags.help) {
|
|
51
|
-
info('Usage: myapi billing topup <amount>\n\nAmount is in whole dollars (e.g. "10" charges $10).\nConfirmation is required for amounts of $50 or more. Use --yes to skip it.\nExample: myapi billing topup 10\n\nFlags:\n --yes Skip confirmation prompt for large amounts');
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
80
|
const amount = Math.round(parseFloat(amountStr));
|
|
55
81
|
if (!amountStr || isNaN(amount) || amount <= 0) {
|
|
56
|
-
error(
|
|
57
|
-
return;
|
|
82
|
+
error('Amount must be a positive whole number of dollars (e.g. myapi billing topup 10)');
|
|
58
83
|
}
|
|
59
84
|
if (!flags.yes && !flags.y && amount >= 50) {
|
|
60
85
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -69,11 +94,7 @@ export async function topup(amountStr, flags) {
|
|
|
69
94
|
const result = await hq.topUp(config.api_key, amount);
|
|
70
95
|
success(`Top up successful! New balance: ${result.new_balance_display}`);
|
|
71
96
|
}
|
|
72
|
-
export async function setup(
|
|
73
|
-
if (flags.help) {
|
|
74
|
-
info('Usage: myapi billing setup\n\nGenerates a secure checkout link to add or update your payment method.');
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
97
|
+
export async function setup(_flags) {
|
|
77
98
|
const config = requireConfig();
|
|
78
99
|
const result = await hq.setupPayment(config.api_key);
|
|
79
100
|
success(`Open this URL in your browser to set up payment:\n${result.url}`);
|
|
@@ -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 setOrg(id: string, _flags: Flags, via?: string): Promise<void>;
|
|
5
|
+
export declare function setFunnel(id: string, _flags: Flags, via?: string): Promise<void>;
|
|
6
|
+
export declare function setDomain(domain: string, _flags: Flags, via?: string): Promise<void>;
|
|
7
|
+
export declare function view(flags: Flags, _via?: string): Promise<void>;
|
|
8
|
+
export declare function run(subcommand: string | undefined, args: string[], flags: Flags): Promise<void>;
|
package/dist/commands/config.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { hq, funnel as sdkFunnel } from '@myapihq/sdk';
|
|
2
2
|
import { requireConfig, saveConfig } from '../config.js';
|
|
3
|
-
import { success, error, info } from '../output.js';
|
|
3
|
+
import { success, error, info, printJson } from '../output.js';
|
|
4
|
+
export const SCHEMA = {
|
|
5
|
+
_via: 'string',
|
|
6
|
+
};
|
|
4
7
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
5
|
-
export async function setOrg(id,
|
|
6
|
-
if (!id
|
|
7
|
-
info(`Usage: myapi ${via} set-org <id
|
|
8
|
+
export async function setOrg(id, _flags, via = 'auth config') {
|
|
9
|
+
if (!id) {
|
|
10
|
+
info(`Usage: myapi ${via} set-org <id>`);
|
|
8
11
|
return;
|
|
9
12
|
}
|
|
10
13
|
if (!UUID_RE.test(id))
|
|
@@ -16,9 +19,9 @@ export async function setOrg(id, flags, via = 'auth config') {
|
|
|
16
19
|
saveConfig(config);
|
|
17
20
|
success(`Default organization set to: ${org.name || org.id}`);
|
|
18
21
|
}
|
|
19
|
-
export async function setFunnel(id,
|
|
20
|
-
if (!id
|
|
21
|
-
info(`Usage: myapi ${via} set-funnel <id
|
|
22
|
+
export async function setFunnel(id, _flags, via = 'auth config') {
|
|
23
|
+
if (!id) {
|
|
24
|
+
info(`Usage: myapi ${via} set-funnel <id>`);
|
|
22
25
|
return;
|
|
23
26
|
}
|
|
24
27
|
if (!UUID_RE.test(id))
|
|
@@ -34,9 +37,9 @@ export async function setFunnel(id, flags, via = 'auth config') {
|
|
|
34
37
|
saveConfig(config);
|
|
35
38
|
success(`Default funnel set to: ${funnelId}`);
|
|
36
39
|
}
|
|
37
|
-
export async function setDomain(domain,
|
|
38
|
-
if (!domain
|
|
39
|
-
info(`Usage: myapi ${via} set-domain <domain
|
|
40
|
+
export async function setDomain(domain, _flags, via = 'auth config') {
|
|
41
|
+
if (!domain) {
|
|
42
|
+
info(`Usage: myapi ${via} set-domain <domain>`);
|
|
40
43
|
return;
|
|
41
44
|
}
|
|
42
45
|
const config = requireConfig();
|
|
@@ -44,14 +47,9 @@ export async function setDomain(domain, flags, via = 'auth config') {
|
|
|
44
47
|
saveConfig(config);
|
|
45
48
|
success(`Default domain set to: ${domain}`);
|
|
46
49
|
}
|
|
47
|
-
export async function view(flags,
|
|
48
|
-
if (flags.help) {
|
|
49
|
-
info(`Usage: myapi ${via} view [--json]\n\nShows the currently configured defaults: default org, funnel, and domain.\n\nFlags:\n --json Output raw JSON`);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
50
|
+
export async function view(flags, _via = 'auth config') {
|
|
52
51
|
const config = requireConfig();
|
|
53
52
|
if (flags.json) {
|
|
54
|
-
const { printJson } = await import('../output.js');
|
|
55
53
|
printJson({
|
|
56
54
|
default_org: config.default_org ?? null,
|
|
57
55
|
default_funnel: config.default_funnel ?? null,
|
|
@@ -63,20 +61,47 @@ export async function view(flags, via = 'auth config') {
|
|
|
63
61
|
info(`Default Funnel: ${config.default_funnel || 'Not set'}`);
|
|
64
62
|
info(`Default Domain: ${config.default_domain || 'Not set'}`);
|
|
65
63
|
}
|
|
64
|
+
// ── Dispatcher ───────────────────────────────────────────────────────────────
|
|
65
|
+
function subcommandUsage(via) {
|
|
66
|
+
return {
|
|
67
|
+
'view': `myapi ${via} view [--json]`,
|
|
68
|
+
'set-org': `myapi ${via} set-org <id>\n\nSets the default organization for all commands that require --org.\nThe ID is validated against the API before saving.`,
|
|
69
|
+
'set-funnel': `myapi ${via} set-funnel <id>\n\nSets the default funnel. Must belong to your current default org.\nThe ID is validated against the API before saving.`,
|
|
70
|
+
'set-domain': `myapi ${via} set-domain <domain>\n\nSets the default domain used by domain commands when the domain arg is omitted.`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
66
73
|
export async function run(subcommand, args, flags) {
|
|
67
74
|
const via = flags._via || 'auth config';
|
|
68
75
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
69
|
-
info(`Usage: myapi ${via} <subcommand
|
|
76
|
+
info(`Usage: myapi ${via} <subcommand>
|
|
77
|
+
|
|
78
|
+
Manages CLI defaults (org, funnel, domain) so you don't have to pass --org / --domain on every command.
|
|
79
|
+
|
|
80
|
+
Subcommands:
|
|
81
|
+
view Show current defaults
|
|
82
|
+
set-org Set default organization (validates access)
|
|
83
|
+
set-funnel Set default funnel (must be owned by default org)
|
|
84
|
+
set-domain Set default domain
|
|
85
|
+
|
|
86
|
+
Examples:
|
|
87
|
+
myapi ${via} set-org <id>
|
|
88
|
+
myapi ${via} set-funnel <id>
|
|
89
|
+
myapi ${via} view`);
|
|
70
90
|
return;
|
|
71
91
|
}
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
92
|
+
if (flags.help) {
|
|
93
|
+
const usage = subcommandUsage(via)[subcommand];
|
|
94
|
+
if (usage)
|
|
95
|
+
info(`Usage: ${usage}`);
|
|
96
|
+
else
|
|
97
|
+
info(`Unknown subcommand: ${subcommand}. Run "myapi ${via} --help" for the list.`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
switch (subcommand) {
|
|
101
|
+
case 'view': return view(flags, via);
|
|
102
|
+
case 'set-org': return setOrg(args[0], flags, via);
|
|
103
|
+
case 'set-funnel': return setFunnel(args[0], flags, via);
|
|
104
|
+
case 'set-domain': return setDomain(args[0], flags, via);
|
|
105
|
+
default: error(`Unknown subcommand: ${subcommand}. Run "myapi ${via} --help" for a list of valid subcommands.`);
|
|
106
|
+
}
|
|
82
107
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
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 check(domainArg: string, flags: Flags): Promise<void>;
|
|
5
|
+
export declare function register(domainArg: string, flags: Flags): Promise<void>;
|
|
6
|
+
export declare function list(flags: Flags): Promise<void>;
|
|
7
|
+
export declare function assign(domainArg: string, flags: Flags): Promise<void>;
|
|
8
|
+
export declare function unassign(domainArg: string, flags: Flags): Promise<void>;
|
|
9
|
+
export declare function status(domainArg: string, flags: Flags): Promise<void>;
|
|
10
|
+
export declare function settings(domainArg: string, flags: Flags): Promise<void>;
|
|
11
|
+
export declare function updateSettings(domainArg: string, flags: Flags): Promise<void>;
|
|
12
|
+
export declare function run(subcommand: string | undefined, args: string[], flags: Flags): Promise<void>;
|
package/dist/commands/domain.js
CHANGED
|
@@ -2,16 +2,20 @@ import { domain as sdkDomain } from '@myapihq/sdk';
|
|
|
2
2
|
import { requireConfig } from '../config.js';
|
|
3
3
|
import { success, error, info, printTable, printJson } from '../output.js';
|
|
4
4
|
import { formatDate } from '../utils.js';
|
|
5
|
+
import { requireOrg, requireDomain } from '../helpers.js';
|
|
6
|
+
export const SCHEMA = {
|
|
7
|
+
org: 'string',
|
|
8
|
+
domain: 'string',
|
|
9
|
+
filter: 'string',
|
|
10
|
+
years: 'number',
|
|
11
|
+
security: 'string',
|
|
12
|
+
'browser-check': 'string',
|
|
13
|
+
'purge-cache': 'boolean',
|
|
14
|
+
};
|
|
5
15
|
export async function check(domainArg, flags) {
|
|
6
16
|
const config = requireConfig();
|
|
7
|
-
const orgId = flags
|
|
8
|
-
const domain = domainArg
|
|
9
|
-
if (!orgId || !domain) {
|
|
10
|
-
const hint = config.default_org
|
|
11
|
-
? `(current default org: ${config.default_org})`
|
|
12
|
-
: '(Set defaults: myapi config set-org <id> / myapi config set-domain <domain>)';
|
|
13
|
-
error(`Missing required arguments.\nUsage: myapi domain check <domain>${config.default_org ? '' : ' --org <id>'}\n${hint}`);
|
|
14
|
-
}
|
|
17
|
+
const orgId = requireOrg(flags, config, 'myapi domain check <domain> [--org <id>]');
|
|
18
|
+
const domain = requireDomain(domainArg, flags, config, 'myapi domain check <domain> [--org <id>]');
|
|
15
19
|
const res = await sdkDomain.checkDomain(config.api_key, orgId, domain);
|
|
16
20
|
if (flags.json) {
|
|
17
21
|
const out = { domain, available: res.available };
|
|
@@ -34,58 +38,50 @@ export async function check(domainArg, flags) {
|
|
|
34
38
|
}
|
|
35
39
|
export async function register(domainArg, flags) {
|
|
36
40
|
const config = requireConfig();
|
|
37
|
-
const orgId = flags
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
info(`
|
|
45
|
-
info(`
|
|
46
|
-
info(`Your funnel will be live on https://${domain} once propagation completes.`);
|
|
41
|
+
const orgId = requireOrg(flags, config, 'myapi domain register <domain> [--years <n>] [--org <id>]');
|
|
42
|
+
if (!domainArg)
|
|
43
|
+
error('Missing required arguments.\nUsage: myapi domain register <domain> [--years <n>] [--org <id>]');
|
|
44
|
+
const years = flags.years || 1;
|
|
45
|
+
await sdkDomain.registerDomain(config.api_key, orgId, domainArg, years);
|
|
46
|
+
success(`Registered ${domainArg}!`);
|
|
47
|
+
info(`Assign it to your org now:\n myapi domain assign ${domainArg} --org ${orgId}`);
|
|
48
|
+
info(`DNS propagation can take a few minutes — track it with: myapi domain status ${domainArg}`);
|
|
49
|
+
info(`Your funnel will be live on https://${domainArg} once propagation completes.`);
|
|
47
50
|
}
|
|
48
51
|
export async function list(flags) {
|
|
49
52
|
const config = requireConfig();
|
|
50
|
-
const orgId = flags
|
|
51
|
-
if (!orgId)
|
|
52
|
-
error("Missing required arguments.\nUsage: myapi domain list --org <id> [--filter=all|unassigned|org]\n(Set default: myapi auth config set-org <id>)");
|
|
53
|
+
const orgId = requireOrg(flags, config, 'myapi domain list [--filter=all|unassigned|org] [--org <id>]');
|
|
53
54
|
const filter = flags.filter;
|
|
54
55
|
const domains = await sdkDomain.listDomains(config.api_key, orgId, filter);
|
|
55
56
|
if (flags.json) {
|
|
56
57
|
printJson(domains);
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
printTable(domains);
|
|
60
|
+
printTable(domains, {
|
|
61
|
+
flags,
|
|
62
|
+
empty: 'No domains found in this organization. Register one with: myapi domain register <name>',
|
|
63
|
+
});
|
|
64
64
|
}
|
|
65
65
|
export async function assign(domainArg, flags) {
|
|
66
66
|
const config = requireConfig();
|
|
67
|
-
const orgId = flags
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
success(`Assigned ${domain} to org ${orgId}`);
|
|
67
|
+
const orgId = requireOrg(flags, config, 'myapi domain assign <domain> [--org <id>]');
|
|
68
|
+
if (!domainArg)
|
|
69
|
+
error('Missing required arguments.\nUsage: myapi domain assign <domain> [--org <id>]');
|
|
70
|
+
await sdkDomain.assignDomain(config.api_key, orgId, domainArg);
|
|
71
|
+
success(`Assigned ${domainArg} to org ${orgId}`);
|
|
73
72
|
}
|
|
74
73
|
export async function unassign(domainArg, flags) {
|
|
75
74
|
const config = requireConfig();
|
|
76
|
-
const orgId = flags
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
success(`Unassigned ${domain} from org ${orgId}`);
|
|
75
|
+
const orgId = requireOrg(flags, config, 'myapi domain unassign <domain> [--org <id>]');
|
|
76
|
+
if (!domainArg)
|
|
77
|
+
error('Missing required arguments.\nUsage: myapi domain unassign <domain> [--org <id>]');
|
|
78
|
+
await sdkDomain.unassignDomain(config.api_key, orgId, domainArg);
|
|
79
|
+
success(`Unassigned ${domainArg} from org ${orgId}`);
|
|
82
80
|
}
|
|
83
81
|
export async function status(domainArg, flags) {
|
|
84
82
|
const config = requireConfig();
|
|
85
|
-
const orgId = flags
|
|
86
|
-
const domain = domainArg
|
|
87
|
-
if (!orgId || !domain)
|
|
88
|
-
error("Missing required arguments.\nUsage: myapi domain status <domain> --org <id>\n(Set defaults: myapi auth config set-org <id> / myapi auth config set-domain <domain>)");
|
|
83
|
+
const orgId = requireOrg(flags, config, 'myapi domain status <domain> [--org <id>]');
|
|
84
|
+
const domain = requireDomain(domainArg, flags, config, 'myapi domain status <domain> [--org <id>]');
|
|
89
85
|
const res = await sdkDomain.getDomainStatus(config.api_key, orgId, domain);
|
|
90
86
|
if (flags.json) {
|
|
91
87
|
printJson(res);
|
|
@@ -96,23 +92,19 @@ export async function status(domainArg, flags) {
|
|
|
96
92
|
if (res.expires_at)
|
|
97
93
|
info(`Expires: ${formatDate(res.expires_at)}`);
|
|
98
94
|
if (res.status === 'active')
|
|
99
|
-
info(
|
|
95
|
+
info('Note: if recently activated, the SSL certificate may still be provisioning — allow a few minutes before the site is reachable over HTTPS.');
|
|
100
96
|
}
|
|
101
97
|
export async function settings(domainArg, flags) {
|
|
102
98
|
const config = requireConfig();
|
|
103
|
-
const orgId = flags
|
|
104
|
-
const domain = domainArg
|
|
105
|
-
if (!orgId || !domain)
|
|
106
|
-
error("Missing required arguments.\nUsage: myapi domain settings <domain> --org <id>\n(Set defaults: myapi auth config set-org <id> / myapi auth config set-domain <domain>)");
|
|
99
|
+
const orgId = requireOrg(flags, config, 'myapi domain settings <domain> [--org <id>]');
|
|
100
|
+
const domain = requireDomain(domainArg, flags, config, 'myapi domain settings <domain> [--org <id>]');
|
|
107
101
|
const res = await sdkDomain.getDomainSettings(config.api_key, orgId, domain);
|
|
108
102
|
printJson(res);
|
|
109
103
|
}
|
|
110
104
|
export async function updateSettings(domainArg, flags) {
|
|
111
105
|
const config = requireConfig();
|
|
112
|
-
const orgId = flags
|
|
113
|
-
const domain = domainArg
|
|
114
|
-
if (!orgId || !domain)
|
|
115
|
-
error("Missing required arguments.\nUsage: myapi domain update-settings <domain> --org <id> [--security=...] [--browser-check=...] [--purge-cache]\n(Set defaults: myapi auth config set-org <id> / myapi auth config set-domain <domain>)");
|
|
106
|
+
const orgId = requireOrg(flags, config, 'myapi domain update-settings <domain> [--org <id>]');
|
|
107
|
+
const domain = requireDomain(domainArg, flags, config, 'myapi domain update-settings <domain> [--org <id>]');
|
|
116
108
|
const payload = {};
|
|
117
109
|
if (flags.security)
|
|
118
110
|
payload.security_level = flags.security;
|
|
@@ -120,49 +112,88 @@ export async function updateSettings(domainArg, flags) {
|
|
|
120
112
|
payload.browser_check = flags['browser-check'];
|
|
121
113
|
if (flags['purge-cache'])
|
|
122
114
|
payload.purge_cache = true;
|
|
115
|
+
if (Object.keys(payload).length === 0) {
|
|
116
|
+
error('Nothing to update. Pass at least one of --security=<level>, --browser-check=<on|off>, --purge-cache.');
|
|
117
|
+
}
|
|
123
118
|
const res = await sdkDomain.updateDomainSettings(config.api_key, orgId, domain, payload);
|
|
124
119
|
success(`Updated settings for ${domain}!\n${JSON.stringify(res, null, 2)}`);
|
|
125
120
|
}
|
|
121
|
+
// ── Dispatcher ───────────────────────────────────────────────────────────────
|
|
122
|
+
const SUBCOMMAND_USAGE = {
|
|
123
|
+
'list': `myapi domain list [--filter=all|unassigned|org] [--org <id>] [--json]
|
|
124
|
+
|
|
125
|
+
--filter=all All domains owned by the account.
|
|
126
|
+
--filter=unassigned Domains not yet assigned to any org.
|
|
127
|
+
--filter=org (Default) Domains assigned to the specified org.
|
|
128
|
+
|
|
129
|
+
Note: --filter=all and --filter=unassigned are account-wide; --org is only used
|
|
130
|
+
to authenticate the request.`,
|
|
131
|
+
'check': 'myapi domain check <domain> [--org <id>] [--json]',
|
|
132
|
+
'register': `myapi domain register <domain> [--years <num>] [--org <id>]
|
|
133
|
+
|
|
134
|
+
--years <num> Number of years to register for (default: 1)
|
|
135
|
+
|
|
136
|
+
Prerequisites:
|
|
137
|
+
- Sufficient balance (myapi billing balance)
|
|
138
|
+
- Domain available (myapi domain check <domain>)
|
|
139
|
+
|
|
140
|
+
After registering: myapi domain assign <domain>
|
|
141
|
+
DNS propagation takes a few minutes — track it with: myapi domain status <domain>`,
|
|
142
|
+
'assign': `myapi domain assign <domain> [--org <id>]
|
|
143
|
+
|
|
144
|
+
Assigns a registered domain to an org. Once assigned, your funnel is served at
|
|
145
|
+
https://<domain> after DNS propagation completes.
|
|
146
|
+
|
|
147
|
+
To transfer to a different org: unassign first, then assign to the new org.`,
|
|
148
|
+
'unassign': 'myapi domain unassign <domain> [--org <id>]',
|
|
149
|
+
'status': 'myapi domain status <domain> [--org <id>] [--json]',
|
|
150
|
+
'settings': `myapi domain settings <domain> [--org <id>]
|
|
151
|
+
|
|
152
|
+
Gets current edge/CDN settings (security level, browser check, cache).
|
|
153
|
+
Use "myapi domain update-settings" to change them.`,
|
|
154
|
+
'update-settings': `myapi domain update-settings <domain> [--security=<level>] [--browser-check=on|off] [--purge-cache] [--org <id>]
|
|
155
|
+
|
|
156
|
+
--security=<level> essentially_off | low | medium | high | under_attack (default: medium)
|
|
157
|
+
--browser-check=<on|off> Browser integrity challenge for suspicious traffic (default: on)
|
|
158
|
+
--purge-cache Immediately clear the CDN cache for this domain
|
|
159
|
+
|
|
160
|
+
Example:
|
|
161
|
+
myapi domain update-settings example.com --security=high --purge-cache`,
|
|
162
|
+
};
|
|
126
163
|
export async function run(subcommand, args, flags) {
|
|
127
164
|
if (!subcommand || (flags.help && !subcommand)) {
|
|
128
|
-
info(
|
|
165
|
+
info(`Usage: myapi domain <subcommand>
|
|
166
|
+
|
|
167
|
+
Subcommands:
|
|
168
|
+
list List domains
|
|
169
|
+
check Check domain availability
|
|
170
|
+
register Register a domain
|
|
171
|
+
assign Assign domain to an org
|
|
172
|
+
unassign Unassign domain from its current org
|
|
173
|
+
status Get domain status
|
|
174
|
+
settings Get edge/CDN settings
|
|
175
|
+
update-settings Update edge/CDN settings
|
|
176
|
+
|
|
177
|
+
Tip: Set defaults with "myapi config set-org <id>" / "set-domain <domain>" to skip flags on every command.`);
|
|
129
178
|
return;
|
|
130
179
|
}
|
|
131
180
|
if (flags.help) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
info('Usage: myapi domain register <domain> --org <id> [--years <num>]\n\nRegisters a new domain name under your account.\n\nFlags:\n --years <num> Number of years to register for (default: 1)\n\nPrerequisites:\n - You must have sufficient balance (myapi billing balance)\n - The domain must be available (myapi domain check <domain>)\n\nAfter registering, assign the domain to your org:\n myapi domain assign <domain> --org <id>\n\nDNS propagation takes a few minutes. Track it with:\n myapi domain status <domain>');
|
|
138
|
-
else if (subcommand === 'assign')
|
|
139
|
-
info('Usage: myapi domain assign <domain> --org <id>\n\nAssigns a registered domain to an organization. The domain must already be\nregistered under your account. Once assigned, your funnel will be served at\nhttps://<domain> after DNS propagation completes.\n\nTo transfer a domain to a different org: unassign it first, then assign to the new org.');
|
|
140
|
-
else if (subcommand === 'unassign')
|
|
141
|
-
info('Usage: myapi domain unassign <domain> --org <id>\n\nUnassigns a domain from its current organization. The domain remains registered\nunder your account and can be reassigned to a different org at any time.');
|
|
142
|
-
else if (subcommand === 'status')
|
|
143
|
-
info('Usage: myapi domain status <domain> --org <id> [--json]\n\nGets the registration status of a domain.\n\nFlags:\n --json Output raw JSON');
|
|
144
|
-
else if (subcommand === 'settings')
|
|
145
|
-
info('Usage: myapi domain settings <domain> --org <id>\n\nGets the current edge/CDN settings for a domain (security level, browser check, cache).\nUse "myapi domain update-settings" to change them.');
|
|
146
|
-
else if (subcommand === 'update-settings')
|
|
147
|
-
info('Usage: myapi domain update-settings <domain> --org <id> [flags]\n\nUpdates edge/CDN settings for a domain.\n\nFlags:\n --security=<level> CDN security level. Controls bot/threat filtering.\n Values: essentially_off | low | medium | high | under_attack\n Default (if unset): medium\n --browser-check=<on|off> Enable or disable browser integrity challenge for suspicious traffic.\n Default: on\n --purge-cache Immediately clears the CDN cache for this domain.\n Use after deploying changes that are not yet visible.\n\nExample:\n myapi domain update-settings example.com --org <id> --security=high --purge-cache');
|
|
181
|
+
const usage = SUBCOMMAND_USAGE[subcommand];
|
|
182
|
+
if (usage)
|
|
183
|
+
info(`Usage: ${usage}`);
|
|
184
|
+
else
|
|
185
|
+
info(`Unknown subcommand: ${subcommand}. Run "myapi domain --help" for the list.`);
|
|
148
186
|
return;
|
|
149
187
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
await status(args[0], flags);
|
|
162
|
-
else if (subcommand === 'settings')
|
|
163
|
-
await settings(args[0], flags);
|
|
164
|
-
else if (subcommand === 'update-settings')
|
|
165
|
-
await updateSettings(args[0], flags);
|
|
166
|
-
else
|
|
167
|
-
error(`Unknown subcommand: ${subcommand}. Run "myapi domain --help" for a list of valid subcommands.`);
|
|
188
|
+
switch (subcommand) {
|
|
189
|
+
case 'list': return list(flags);
|
|
190
|
+
case 'check': return check(args[0], flags);
|
|
191
|
+
case 'register': return register(args[0], flags);
|
|
192
|
+
case 'assign': return assign(args[0], flags);
|
|
193
|
+
case 'unassign': return unassign(args[0], flags);
|
|
194
|
+
case 'status': return status(args[0], flags);
|
|
195
|
+
case 'settings': return settings(args[0], flags);
|
|
196
|
+
case 'update-settings': return updateSettings(args[0], flags);
|
|
197
|
+
default: error(`Unknown subcommand: ${subcommand}. Run "myapi domain --help" for a list of valid subcommands.`);
|
|
198
|
+
}
|
|
168
199
|
}
|