@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/keys.js
CHANGED
|
@@ -1,70 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createNew = createNew;
|
|
37
|
-
exports.list = list;
|
|
38
|
-
exports.revoke = revoke;
|
|
39
|
-
const sdk_1 = require("@myapihq/sdk");
|
|
40
|
-
const config_js_1 = require("../config.js");
|
|
41
|
-
const output_js_1 = require("../output.js");
|
|
42
|
-
const readline = __importStar(require("readline"));
|
|
43
|
-
async function createNew(flags) {
|
|
1
|
+
import { hq } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable, info, printJson } from '../output.js';
|
|
4
|
+
import * as readline from 'readline';
|
|
5
|
+
export async function createNew(flags) {
|
|
44
6
|
if (flags.help) {
|
|
45
|
-
|
|
7
|
+
info('Usage: myapi keys create\n\nCreates a new API key. You will be prompted to enter a name for the key.');
|
|
46
8
|
return;
|
|
47
9
|
}
|
|
48
|
-
const config =
|
|
10
|
+
const config = requireConfig();
|
|
49
11
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
50
12
|
const name = await new Promise(resolve => rl.question('Enter a name for the new key: ', resolve));
|
|
51
13
|
rl.close();
|
|
52
14
|
if (!name.trim()) {
|
|
53
|
-
|
|
15
|
+
error('Key name cannot be empty.');
|
|
54
16
|
return;
|
|
55
17
|
}
|
|
56
|
-
const keyInfo = await
|
|
57
|
-
|
|
18
|
+
const keyInfo = await hq.createApiKey(config.api_key, name.trim());
|
|
19
|
+
success(`New API key created!\n\nName: ${keyInfo.prefix}...\nKey: ${keyInfo.api_key}\n\nMake sure to copy your new API key now. You won't be able to see it again!`);
|
|
58
20
|
}
|
|
59
|
-
async function list(flags) {
|
|
21
|
+
export async function list(flags) {
|
|
60
22
|
if (flags.help) {
|
|
61
|
-
|
|
23
|
+
info('Usage: myapi keys list [--json]\n\nLists all API keys associated with your account.');
|
|
62
24
|
return;
|
|
63
25
|
}
|
|
64
|
-
const config =
|
|
65
|
-
const keysList = await
|
|
26
|
+
const config = requireConfig();
|
|
27
|
+
const keysList = await hq.listApiKeys(config.api_key);
|
|
66
28
|
if (flags.json) {
|
|
67
|
-
|
|
29
|
+
printJson(keysList);
|
|
68
30
|
return;
|
|
69
31
|
}
|
|
70
32
|
const formattedKeys = keysList.map(k => {
|
|
@@ -85,18 +47,18 @@ async function list(flags) {
|
|
|
85
47
|
'Last Used': lastUsedStr
|
|
86
48
|
};
|
|
87
49
|
});
|
|
88
|
-
|
|
50
|
+
printTable(formattedKeys);
|
|
89
51
|
}
|
|
90
|
-
async function revoke(id, flags) {
|
|
52
|
+
export async function revoke(id, flags) {
|
|
91
53
|
if (flags.help) {
|
|
92
|
-
|
|
54
|
+
info('Usage: myapi keys revoke <id>\n\nRevokes an API key permanently.');
|
|
93
55
|
return;
|
|
94
56
|
}
|
|
95
57
|
if (!id) {
|
|
96
|
-
|
|
58
|
+
error("Missing key ID. Usage: myapi keys revoke <id>");
|
|
97
59
|
return;
|
|
98
60
|
}
|
|
99
|
-
const config =
|
|
100
|
-
await
|
|
101
|
-
|
|
61
|
+
const config = requireConfig();
|
|
62
|
+
await hq.revokeApiKey(config.api_key, id);
|
|
63
|
+
success(`Key ${id} revoked successfully.`);
|
|
102
64
|
}
|
package/dist/commands/org.js
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.del = del;
|
|
7
|
-
exports.importOrg = importOrg;
|
|
8
|
-
const sdk_1 = require("@myapihq/sdk");
|
|
9
|
-
const config_js_1 = require("../config.js");
|
|
10
|
-
const output_js_1 = require("../output.js");
|
|
11
|
-
const utils_js_1 = require("../utils.js");
|
|
12
|
-
async function create(flags) {
|
|
1
|
+
import { hq } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printJson, info } from '../output.js';
|
|
4
|
+
import { sleep } from '../utils.js';
|
|
5
|
+
export async function create(flags) {
|
|
13
6
|
if (flags.help) {
|
|
14
|
-
|
|
7
|
+
info('Usage: myapi org create --name="My Org" [options]\n\nOptions:\n --name Organization name (required)\n --tagline Short tagline\n --description Detailed description\n --business-sector Sector (e.g. Technology)\n --logo-url URL to logo image');
|
|
15
8
|
return;
|
|
16
9
|
}
|
|
17
10
|
if (!flags.name) {
|
|
18
|
-
|
|
11
|
+
error("Missing --name flag. Run 'myapi org create --help' for details.");
|
|
19
12
|
return;
|
|
20
13
|
}
|
|
21
|
-
const config =
|
|
14
|
+
const config = requireConfig();
|
|
22
15
|
const payload = { name: flags.name };
|
|
23
16
|
if (flags.tagline)
|
|
24
17
|
payload.tagline = flags.tagline;
|
|
@@ -28,74 +21,74 @@ async function create(flags) {
|
|
|
28
21
|
payload.business_sector = flags['business-sector'];
|
|
29
22
|
if (flags['logo-url'])
|
|
30
23
|
payload.logo_url = flags['logo-url'];
|
|
31
|
-
const org = await
|
|
32
|
-
|
|
24
|
+
const org = await hq.createOrg(config.api_key, payload);
|
|
25
|
+
success(`Org created! ID: ${org.id}, Name: ${org.name}`);
|
|
33
26
|
}
|
|
34
|
-
async function list(flags) {
|
|
27
|
+
export async function list(flags) {
|
|
35
28
|
if (flags.help) {
|
|
36
|
-
|
|
29
|
+
info('Usage: myapi org list\n\nLists all organizations in your account as JSON.');
|
|
37
30
|
return;
|
|
38
31
|
}
|
|
39
|
-
const config =
|
|
40
|
-
const orgs = await
|
|
41
|
-
|
|
32
|
+
const config = requireConfig();
|
|
33
|
+
const orgs = await hq.listOrgs(config.api_key);
|
|
34
|
+
printJson(orgs);
|
|
42
35
|
}
|
|
43
|
-
async function get(id, flags) {
|
|
36
|
+
export async function get(id, flags) {
|
|
44
37
|
if (flags.help) {
|
|
45
|
-
|
|
38
|
+
info('Usage: myapi org get <id>\n\nFetches details of a specific organization.');
|
|
46
39
|
return;
|
|
47
40
|
}
|
|
48
41
|
if (!id) {
|
|
49
|
-
|
|
42
|
+
error("Missing org id. Usage: myapi org get <id>");
|
|
50
43
|
return;
|
|
51
44
|
}
|
|
52
|
-
const config =
|
|
53
|
-
const org = await
|
|
54
|
-
|
|
45
|
+
const config = requireConfig();
|
|
46
|
+
const org = await hq.getOrg(config.api_key, id);
|
|
47
|
+
printJson(org);
|
|
55
48
|
}
|
|
56
|
-
async function del(id, flags) {
|
|
49
|
+
export async function del(id, flags) {
|
|
57
50
|
if (flags.help) {
|
|
58
|
-
|
|
51
|
+
info('Usage: myapi org delete <id>\n\nDeletes an organization.');
|
|
59
52
|
return;
|
|
60
53
|
}
|
|
61
54
|
if (!id) {
|
|
62
|
-
|
|
55
|
+
error("Missing org id. Usage: myapi org delete <id>");
|
|
63
56
|
return;
|
|
64
57
|
}
|
|
65
|
-
const config =
|
|
66
|
-
await
|
|
67
|
-
|
|
58
|
+
const config = requireConfig();
|
|
59
|
+
await hq.deleteOrg(config.api_key, id);
|
|
60
|
+
success(`Org ${id} deleted`);
|
|
68
61
|
}
|
|
69
|
-
async function importOrg(args, flags) {
|
|
62
|
+
export async function importOrg(args, flags) {
|
|
70
63
|
if (flags.help) {
|
|
71
|
-
|
|
64
|
+
info('Usage: myapi org import <domain> --org <id>\n\nAutomatically extracts brand info from an existing website and updates the organization.\n\nNote: You must create a placeholder organization first using `myapi org create` to get an org_id.');
|
|
72
65
|
return;
|
|
73
66
|
}
|
|
74
|
-
const config =
|
|
67
|
+
const config = requireConfig();
|
|
75
68
|
const domain = args[0] || config.default_domain;
|
|
76
69
|
const orgId = flags.org || config.default_org;
|
|
77
70
|
if (!domain || !orgId) {
|
|
78
|
-
|
|
71
|
+
error("Missing required arguments.\nUsage: myapi org import <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
|
|
79
72
|
return;
|
|
80
73
|
}
|
|
81
|
-
const result = await
|
|
74
|
+
const result = await hq.importOrg(config.api_key, orgId, domain);
|
|
82
75
|
const importId = result.job_id;
|
|
83
76
|
process.stdout.write("Importing ");
|
|
84
77
|
const chars = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
85
78
|
let i = 0;
|
|
86
79
|
while (true) {
|
|
87
|
-
const status = await
|
|
80
|
+
const status = await hq.getOrgImportStatus(config.api_key, importId);
|
|
88
81
|
if (status.status === 'awaiting_confirm') {
|
|
89
82
|
process.stdout.write('\r\x1b[K');
|
|
90
83
|
break;
|
|
91
84
|
}
|
|
92
85
|
if (status.status === 'failed') {
|
|
93
86
|
process.stdout.write('\r\x1b[K');
|
|
94
|
-
|
|
87
|
+
error("Import failed");
|
|
95
88
|
}
|
|
96
89
|
process.stdout.write(`\rImporting ${chars[i++ % chars.length]}`);
|
|
97
|
-
await
|
|
90
|
+
await sleep(3000);
|
|
98
91
|
}
|
|
99
|
-
const org = await
|
|
100
|
-
|
|
92
|
+
const org = await hq.confirmOrgImport(config.api_key, importId);
|
|
93
|
+
success(`Import complete! Org ID: ${org.id}`);
|
|
101
94
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function interactions(flags: Record<string, string | boolean>): Promise<void>;
|
|
2
|
+
export declare function identity(pixelId: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
3
|
+
export declare function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>): Promise<void>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { pixel as sdkPixel } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { error, printTable, info, printJson } from '../output.js';
|
|
4
|
+
export async function interactions(flags) {
|
|
5
|
+
const config = requireConfig();
|
|
6
|
+
const orgId = flags.org || config.default_org;
|
|
7
|
+
if (!orgId) {
|
|
8
|
+
error("Missing required arguments.\nUsage: myapi pixel interactions --org <id> [--website <domain>] [--campaign-id <id>] [--domain <domain>]\n(Or set defaults via: myapi config set-org <id>)");
|
|
9
|
+
}
|
|
10
|
+
const params = {};
|
|
11
|
+
if (flags.website)
|
|
12
|
+
params.website = flags.website;
|
|
13
|
+
if (flags['campaign-id'])
|
|
14
|
+
params.campaign_id = flags['campaign-id'];
|
|
15
|
+
if (flags.domain)
|
|
16
|
+
params.domain = flags.domain;
|
|
17
|
+
if (flags.from)
|
|
18
|
+
params.from = flags.from;
|
|
19
|
+
if (flags.to)
|
|
20
|
+
params.to = flags.to;
|
|
21
|
+
if (flags.limit)
|
|
22
|
+
params.limit = parseInt(flags.limit, 10);
|
|
23
|
+
if (flags.offset)
|
|
24
|
+
params.offset = parseInt(flags.offset, 10);
|
|
25
|
+
if (!params.website && !params.campaign_id && !params.domain) {
|
|
26
|
+
error("You must provide at least one filter: --website, --campaign-id, or --domain");
|
|
27
|
+
}
|
|
28
|
+
const res = await sdkPixel.getInteractions(config.api_key, orgId, params);
|
|
29
|
+
if (flags.json) {
|
|
30
|
+
printJson(res);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
printTable(res.interactions);
|
|
34
|
+
info(`Total Visits: ${res.total_visits} | Total Events: ${res.total_events} | Showing: ${res.limit} | Offset: ${res.offset}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export async function identity(pixelId, flags) {
|
|
38
|
+
const config = requireConfig();
|
|
39
|
+
const orgId = flags.org || config.default_org;
|
|
40
|
+
if (!orgId || !pixelId) {
|
|
41
|
+
error("Missing required arguments.\nUsage: myapi pixel identity <pixel_id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
42
|
+
}
|
|
43
|
+
const res = await sdkPixel.getIdentity(config.api_key, orgId, pixelId);
|
|
44
|
+
printJson(res);
|
|
45
|
+
}
|
|
46
|
+
export async function run(subcommand, args, flags) {
|
|
47
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
48
|
+
info('Usage: myapi pixel <subcommand>\n\nSubcommands:\n interactions Get a unified timeline of visits and events\n identity Resolve the identity graph for a pixel ID\n\nNote: All pixel commands require the --org <id> flag.');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (flags.help) {
|
|
52
|
+
if (subcommand === 'interactions')
|
|
53
|
+
info('Usage: myapi pixel interactions --org <id> [--website <domain>] [--campaign-id <id>] [--domain <domain>] [--from <iso8601>] [--to <iso8601>] [--limit <num>] [--offset <num>] [--json]\n\nRetrieves a merged timeline of web visits and email events. Requires at least one filter (--website, --campaign-id, or --domain).');
|
|
54
|
+
else if (subcommand === 'identity')
|
|
55
|
+
info('Usage: myapi pixel identity <pixel_id> --org <id>\n\nResolves the full identity graph (emails, IPs, profiles) for a specific pixel tracker ID.');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (subcommand === 'interactions')
|
|
59
|
+
await interactions(flags);
|
|
60
|
+
else if (subcommand === 'identity')
|
|
61
|
+
await identity(args[0], flags);
|
|
62
|
+
else
|
|
63
|
+
error(`Unknown subcommand: ${subcommand}. Run "myapi pixel --help" for a list of valid subcommands.`);
|
|
64
|
+
}
|
package/dist/commands/setup.js
CHANGED
|
@@ -1,42 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.setup = setup;
|
|
37
|
-
const config_js_1 = require("../config.js");
|
|
38
|
-
const output_js_1 = require("../output.js");
|
|
39
|
-
const readline = __importStar(require("readline"));
|
|
1
|
+
import { loadConfig, saveConfig } from '../config.js';
|
|
2
|
+
import { success, info } from '../output.js';
|
|
3
|
+
import * as readline from 'readline';
|
|
40
4
|
function ask(rl, q) {
|
|
41
5
|
return new Promise(resolve => rl.question(q, resolve));
|
|
42
6
|
}
|
|
@@ -48,29 +12,29 @@ function yn(answer, defaultYes = true) {
|
|
|
48
12
|
}
|
|
49
13
|
async function getKey(rl) {
|
|
50
14
|
const key = await ask(rl, 'Paste your API key (get it from https://myapihq.com): ');
|
|
51
|
-
|
|
52
|
-
|
|
15
|
+
saveConfig({ api_key: key.trim(), account_id: '', pin: '' });
|
|
16
|
+
success('API key saved to ~/.myapi/config.json');
|
|
53
17
|
return key.trim();
|
|
54
18
|
}
|
|
55
|
-
async function setup() {
|
|
56
|
-
|
|
19
|
+
export async function setup() {
|
|
20
|
+
info('MyAPI Setup\n');
|
|
57
21
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
58
|
-
const existing =
|
|
22
|
+
const existing = loadConfig();
|
|
59
23
|
if (existing?.api_key) {
|
|
60
24
|
const reuse = await ask(rl, `Found existing account (${existing.account_id || existing.api_key.slice(0, 20) + '...'}). Use it? [Y/n]: `);
|
|
61
25
|
if (!yn(reuse, true)) {
|
|
62
26
|
await getKey(rl);
|
|
63
27
|
}
|
|
64
28
|
else {
|
|
65
|
-
|
|
29
|
+
info('Using existing credentials.');
|
|
66
30
|
}
|
|
67
31
|
}
|
|
68
32
|
else {
|
|
69
33
|
await getKey(rl);
|
|
70
34
|
}
|
|
71
35
|
rl.close();
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
36
|
+
info('\nTo integrate MyAPI with AI agents (Claude, Cursor, Copilot, etc.),');
|
|
37
|
+
info('please follow the instructions in our skills repository:');
|
|
38
|
+
info('https://github.com/myapihq/agent-skills\n');
|
|
39
|
+
success('Setup complete! Try: myapi billing balance');
|
|
76
40
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare function list(flags: Record<string, string | boolean>): Promise<void>;
|
|
2
2
|
export declare function ingest(url: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
3
3
|
export declare function del(id: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
4
|
+
export declare function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>): Promise<void>;
|
package/dist/commands/storage.js
CHANGED
|
@@ -1,36 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const config_js_1 = require("../config.js");
|
|
8
|
-
const output_js_1 = require("../output.js");
|
|
9
|
-
function getOrgId(flags, config) {
|
|
10
|
-
const orgId = flags.org || config.org_id;
|
|
1
|
+
import { storage as sdkStorage } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable, info, printJson } from '../output.js';
|
|
4
|
+
export async function list(flags) {
|
|
5
|
+
const config = requireConfig();
|
|
6
|
+
const orgId = flags.org || config.default_org;
|
|
11
7
|
if (!orgId)
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
error("Missing required arguments.\nUsage: myapi storage list --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
9
|
+
const assets = await sdkStorage.listAssets(config.api_key, orgId);
|
|
10
|
+
if (flags.json)
|
|
11
|
+
printJson(assets);
|
|
12
|
+
else
|
|
13
|
+
printTable(assets);
|
|
14
14
|
}
|
|
15
|
-
async function
|
|
16
|
-
const config =
|
|
17
|
-
const orgId =
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
export async function ingest(url, flags) {
|
|
16
|
+
const config = requireConfig();
|
|
17
|
+
const orgId = flags.org || config.default_org;
|
|
18
|
+
if (!orgId || !url) {
|
|
19
|
+
error("Missing required arguments.\nUsage: myapi storage ingest <url> [--name <name>] --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
20
|
+
}
|
|
21
|
+
const res = await sdkStorage.ingestAsset(config.api_key, orgId, url, flags.name);
|
|
22
|
+
success(`Asset ingested! ID: ${res.asset_id}\nHosted URL: ${res.url}`);
|
|
20
23
|
}
|
|
21
|
-
async function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
export async function del(id, flags) {
|
|
25
|
+
const config = requireConfig();
|
|
26
|
+
const orgId = flags.org || config.default_org;
|
|
27
|
+
if (!orgId || !id) {
|
|
28
|
+
error("Missing required arguments.\nUsage: myapi storage delete <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
29
|
+
}
|
|
30
|
+
await sdkStorage.deleteAsset(config.api_key, orgId, id);
|
|
31
|
+
success(`Asset ${id} deleted`);
|
|
28
32
|
}
|
|
29
|
-
async function
|
|
30
|
-
if (!
|
|
31
|
-
(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
export async function run(subcommand, args, flags) {
|
|
34
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
35
|
+
info('Usage: myapi storage <subcommand>\n\nSubcommands:\n list List all your uploaded assets\n ingest Ingest a public image URL into your edge storage\n delete Delete a stored asset\n\nNote: All storage commands require the --org <id> flag.');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (flags.help) {
|
|
39
|
+
if (subcommand === 'list')
|
|
40
|
+
info('Usage: myapi storage list --org <id> [--json]');
|
|
41
|
+
else if (subcommand === 'ingest')
|
|
42
|
+
info('Usage: myapi storage ingest <url> [--name <name>] --org <id>\n\nDownloads a public image (JPEG/PNG) and permanently hosts it on your MyAPI storage. Returns the new URL.');
|
|
43
|
+
else if (subcommand === 'delete')
|
|
44
|
+
info('Usage: myapi storage delete <asset_id> --org <id>');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (subcommand === 'list')
|
|
48
|
+
await list(flags);
|
|
49
|
+
else if (subcommand === 'ingest')
|
|
50
|
+
await ingest(args[0], flags);
|
|
51
|
+
else if (subcommand === 'delete')
|
|
52
|
+
await del(args[0], flags);
|
|
53
|
+
else
|
|
54
|
+
error(`Unknown subcommand: ${subcommand}. Run "myapi storage --help" for a list of valid subcommands.`);
|
|
36
55
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { url as sdkUrl } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, info, printJson } from '../output.js';
|
|
4
|
+
export async function shorten(targetUrl, flags) {
|
|
5
|
+
const config = requireConfig();
|
|
6
|
+
const orgId = flags.org || config.default_org;
|
|
7
|
+
if (!orgId || !targetUrl)
|
|
8
|
+
error("Missing required arguments.\nUsage: myapi url shorten <url> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
9
|
+
const res = await sdkUrl.shortenUrl(config.api_key, orgId, targetUrl);
|
|
10
|
+
if (flags.json)
|
|
11
|
+
printJson(res);
|
|
12
|
+
else
|
|
13
|
+
success(`Shortened URL: ${res.short_url}\nCode: ${res.short_code}`);
|
|
14
|
+
}
|
|
15
|
+
export async function run(subcommand, args, flags) {
|
|
16
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
17
|
+
info('Usage: myapi url <subcommand>\n\nSubcommands:\n shorten Shorten a long URL\n\nNote: All url commands require the --org <id> flag.');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (flags.help) {
|
|
21
|
+
if (subcommand === 'shorten')
|
|
22
|
+
info('Usage: myapi url shorten <url> --org <id> [--json]\n\nShortens a long URL and returns the compact myurlto.com link.');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (subcommand === 'shorten')
|
|
26
|
+
await shorten(args[0], flags);
|
|
27
|
+
else
|
|
28
|
+
error(`Unknown subcommand: ${subcommand}. Run "myapi url --help" for a list of valid subcommands.`);
|
|
29
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare function list(flags: Record<string, string | boolean>): Promise<void>;
|
|
2
2
|
export declare function create(flags: Record<string, string | boolean>): Promise<void>;
|
|
3
3
|
export declare function del(id: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
4
|
+
export declare function delivery(id: string, flags: Record<string, string | boolean>): Promise<void>;
|
|
5
|
+
export declare function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>): Promise<void>;
|
package/dist/commands/webhook.js
CHANGED
|
@@ -1,28 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { webhook as sdkWebhook } from '@myapihq/sdk';
|
|
2
|
+
import { requireConfig } from '../config.js';
|
|
3
|
+
import { success, error, printTable, info, printJson } from '../output.js';
|
|
4
|
+
export async function list(flags) {
|
|
5
|
+
const config = requireConfig();
|
|
6
|
+
const orgId = flags.org || config.default_org;
|
|
7
|
+
if (!orgId)
|
|
8
|
+
error("Missing required arguments.\nUsage: myapi webhook list --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
9
|
+
const endpoints = await sdkWebhook.listEndpoints(config.api_key, orgId);
|
|
10
|
+
if (flags.json)
|
|
11
|
+
printJson(endpoints);
|
|
12
|
+
else
|
|
13
|
+
printTable(endpoints);
|
|
13
14
|
}
|
|
14
|
-
async function create(flags) {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
export async function create(flags) {
|
|
16
|
+
const config = requireConfig();
|
|
17
|
+
const orgId = flags.org || config.default_org;
|
|
18
|
+
const name = flags.name;
|
|
19
|
+
const description = flags.description;
|
|
20
|
+
if (!orgId || !name) {
|
|
21
|
+
error("Missing required arguments.\nUsage: myapi webhook create --name <name> [--description <desc>] --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
17
22
|
}
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
(0, output_js_1.success)(`Webhook created! ID: ${res.id}\nInbound URL: ${res.inbound_url}`);
|
|
23
|
+
const res = await sdkWebhook.createEndpoint(config.api_key, orgId, name, description);
|
|
24
|
+
success(`Webhook created! ID: ${res.id}\nInbound URL: ${res.inbound_url}`);
|
|
21
25
|
}
|
|
22
|
-
async function del(id, flags) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
export async function del(id, flags) {
|
|
27
|
+
const config = requireConfig();
|
|
28
|
+
const orgId = flags.org || config.default_org;
|
|
29
|
+
if (!orgId || !id)
|
|
30
|
+
error("Missing required arguments.\nUsage: myapi webhook delete <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
31
|
+
await sdkWebhook.deleteEndpoint(config.api_key, orgId, id);
|
|
32
|
+
success(`Webhook ${id} deleted`);
|
|
33
|
+
}
|
|
34
|
+
export async function delivery(id, flags) {
|
|
35
|
+
const config = requireConfig();
|
|
36
|
+
const orgId = flags.org || config.default_org;
|
|
37
|
+
if (!orgId || !id)
|
|
38
|
+
error("Missing required arguments.\nUsage: myapi webhook delivery <id> --org <id>\n(Or set defaults via: myapi config set-org <id>)");
|
|
39
|
+
const res = await sdkWebhook.getDelivery(config.api_key, orgId, id);
|
|
40
|
+
printJson(res);
|
|
41
|
+
}
|
|
42
|
+
export async function run(subcommand, args, flags) {
|
|
43
|
+
if (!subcommand || (flags.help && !subcommand)) {
|
|
44
|
+
info('Usage: myapi webhook <subcommand>\n\nSubcommands:\n list List all inbound webhook endpoints\n create Create a new endpoint to receive data (returns an inbound URL)\n delete Delete a webhook endpoint\n delivery Inspect a specific webhook delivery (headers, payload, status)\n\nNote: All webhook commands require the --org <id> flag.');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (flags.help) {
|
|
48
|
+
if (subcommand === 'list')
|
|
49
|
+
info('Usage: myapi webhook list --org <id> [--json]\n\nLists all webhook endpoints for the organization, including their IDs and inbound slugs.');
|
|
50
|
+
else if (subcommand === 'create')
|
|
51
|
+
info('Usage: myapi webhook create --name <name> [--description <desc>] --org <id>\n\nCreates a new inbound webhook endpoint. Returns the unique inbound URL to give to third parties.');
|
|
52
|
+
else if (subcommand === 'delete')
|
|
53
|
+
info('Usage: myapi webhook delete <id> --org <id>\n\nPermanently deletes the specified webhook endpoint.');
|
|
54
|
+
else if (subcommand === 'delivery')
|
|
55
|
+
info('Usage: myapi webhook delivery <delivery_id> --org <id>\n\nRetrieves the exact HTTP headers, JSON payload, and processing status of a specific received webhook. Useful for debugging inbound data.');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (subcommand === 'list')
|
|
59
|
+
await list(flags);
|
|
60
|
+
else if (subcommand === 'create')
|
|
61
|
+
await create(flags);
|
|
62
|
+
else if (subcommand === 'delete')
|
|
63
|
+
await del(args[0], flags);
|
|
64
|
+
else if (subcommand === 'delivery')
|
|
65
|
+
await delivery(args[0], flags);
|
|
66
|
+
else
|
|
67
|
+
error(`Unknown subcommand: ${subcommand}. Run "myapi webhook --help" for a list of valid subcommands.`);
|
|
28
68
|
}
|