@myapihq/cli 1.0.4 → 1.0.5

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.
Files changed (58) hide show
  1. package/dist/cli/src/commands/account.d.ts +4 -0
  2. package/dist/cli/src/commands/account.js +91 -0
  3. package/dist/cli/src/commands/billing.d.ts +4 -0
  4. package/dist/cli/src/commands/billing.js +34 -0
  5. package/dist/cli/src/commands/domain.d.ts +5 -0
  6. package/dist/cli/src/commands/domain.js +56 -0
  7. package/dist/cli/src/commands/email.d.ts +8 -0
  8. package/dist/cli/src/commands/email.js +95 -0
  9. package/dist/cli/src/commands/funnel.d.ts +3 -0
  10. package/dist/cli/src/commands/funnel.js +37 -0
  11. package/dist/cli/src/commands/image.d.ts +2 -0
  12. package/dist/cli/src/commands/image.js +47 -0
  13. package/dist/cli/src/commands/org.d.ts +5 -0
  14. package/dist/cli/src/commands/org.js +67 -0
  15. package/dist/cli/src/commands/setup.d.ts +1 -0
  16. package/dist/cli/src/commands/setup.js +165 -0
  17. package/dist/cli/src/commands/storage.d.ts +3 -0
  18. package/dist/cli/src/commands/storage.js +36 -0
  19. package/dist/cli/src/commands/webhook.d.ts +3 -0
  20. package/dist/cli/src/commands/webhook.js +28 -0
  21. package/dist/cli/src/commands/workflow.d.ts +5 -0
  22. package/dist/cli/src/commands/workflow.js +57 -0
  23. package/dist/cli/src/config.d.ts +8 -0
  24. package/dist/cli/src/config.js +69 -0
  25. package/dist/cli/src/index.d.ts +2 -0
  26. package/dist/cli/src/index.js +117 -0
  27. package/dist/cli/src/output.d.ts +5 -0
  28. package/dist/cli/src/output.js +42 -0
  29. package/dist/cli/src/utils.d.ts +5 -0
  30. package/dist/cli/src/utils.js +34 -0
  31. package/dist/commands/storage.js +12 -3
  32. package/dist/sdk/src/client.d.ts +6 -0
  33. package/dist/sdk/src/client.js +51 -0
  34. package/dist/sdk/src/domain.d.ts +32 -0
  35. package/dist/sdk/src/domain.js +36 -0
  36. package/dist/sdk/src/email.d.ts +144 -0
  37. package/dist/sdk/src/email.js +116 -0
  38. package/dist/sdk/src/funnel.d.ts +31 -0
  39. package/dist/sdk/src/funnel.js +28 -0
  40. package/dist/sdk/src/hq.d.ts +84 -0
  41. package/dist/sdk/src/hq.js +80 -0
  42. package/dist/sdk/src/image.d.ts +21 -0
  43. package/dist/sdk/src/image.js +16 -0
  44. package/dist/sdk/src/index.d.ts +11 -0
  45. package/dist/sdk/src/index.js +51 -0
  46. package/dist/sdk/src/pixel.d.ts +65 -0
  47. package/dist/sdk/src/pixel.js +44 -0
  48. package/dist/sdk/src/storage.d.ts +10 -0
  49. package/dist/sdk/src/storage.js +48 -0
  50. package/dist/sdk/src/types.d.ts +17 -0
  51. package/dist/sdk/src/types.js +2 -0
  52. package/dist/sdk/src/webhook.d.ts +20 -0
  53. package/dist/sdk/src/webhook.js +20 -0
  54. package/dist/sdk/src/workflow.d.ts +56 -0
  55. package/dist/sdk/src/workflow.js +40 -0
  56. package/package.json +1 -1
  57. package/src/commands/storage.ts +12 -3
  58. package/tsconfig.json +5 -1
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.list = list;
4
+ exports.ingest = ingest;
5
+ exports.del = del;
6
+ const sdk_1 = require("@myapihq/sdk");
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;
11
+ if (!orgId)
12
+ (0, output_js_1.error)("Missing org-id. Pass --org or set it in config.");
13
+ return orgId;
14
+ }
15
+ async function list(flags) {
16
+ const config = (0, config_js_1.requireConfig)();
17
+ const orgId = getOrgId(flags, config);
18
+ const assets = await sdk_1.storage.listAssets(config.api_key, orgId);
19
+ (0, output_js_1.printTable)(assets);
20
+ }
21
+ async function ingest(url, flags) {
22
+ if (!url)
23
+ (0, output_js_1.error)("Missing url");
24
+ const config = (0, config_js_1.requireConfig)();
25
+ const orgId = getOrgId(flags, config);
26
+ const res = await sdk_1.storage.ingestAsset(config.api_key, orgId, url, flags.name);
27
+ (0, output_js_1.success)(`Asset ingested! ID: ${res.asset_id}\nHosted URL: ${res.url}`);
28
+ }
29
+ async function del(id, flags) {
30
+ if (!id)
31
+ (0, output_js_1.error)("Missing id");
32
+ const config = (0, config_js_1.requireConfig)();
33
+ const orgId = getOrgId(flags, config);
34
+ await sdk_1.storage.deleteAsset(config.api_key, orgId, id);
35
+ (0, output_js_1.success)(`Asset ${id} deleted`);
36
+ }
@@ -0,0 +1,3 @@
1
+ export declare function list(flags: Record<string, string | boolean>): Promise<void>;
2
+ export declare function create(flags: Record<string, string | boolean>): Promise<void>;
3
+ export declare function del(id: string, flags: Record<string, string | boolean>): Promise<void>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.list = list;
4
+ exports.create = create;
5
+ exports.del = del;
6
+ const sdk_1 = require("@myapihq/sdk");
7
+ const config_js_1 = require("../config.js");
8
+ const output_js_1 = require("../output.js");
9
+ async function list(flags) {
10
+ const config = (0, config_js_1.requireConfig)();
11
+ const endpoints = await sdk_1.webhook.listEndpoints(config.api_key);
12
+ (0, output_js_1.printTable)(endpoints);
13
+ }
14
+ async function create(flags) {
15
+ if (!flags['org-id'] || !flags.name || !flags.description) {
16
+ (0, output_js_1.error)("Missing --org-id, --name, or --description flags");
17
+ }
18
+ const config = (0, config_js_1.requireConfig)();
19
+ const res = await sdk_1.webhook.createEndpoint(config.api_key, flags['org-id'], flags.name, flags.description);
20
+ (0, output_js_1.success)(`Webhook created! ID: ${res.id}\nInbound URL: ${res.inbound_url}`);
21
+ }
22
+ async function del(id, flags) {
23
+ if (!id)
24
+ (0, output_js_1.error)("Missing id");
25
+ const config = (0, config_js_1.requireConfig)();
26
+ await sdk_1.webhook.deleteEndpoint(config.api_key, id);
27
+ (0, output_js_1.success)(`Webhook ${id} deleted`);
28
+ }
@@ -0,0 +1,5 @@
1
+ export declare function list(flags: Record<string, string | boolean>): Promise<void>;
2
+ export declare function create(flags: Record<string, string | boolean>): Promise<void>;
3
+ export declare function enable(id: string, flags: Record<string, string | boolean>): Promise<void>;
4
+ export declare function disable(id: string, flags: Record<string, string | boolean>): Promise<void>;
5
+ export declare function runs(id: string, flags: Record<string, string | boolean>): Promise<void>;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.list = list;
4
+ exports.create = create;
5
+ exports.enable = enable;
6
+ exports.disable = disable;
7
+ exports.runs = runs;
8
+ const sdk_1 = require("@myapihq/sdk");
9
+ const config_js_1 = require("../config.js");
10
+ const output_js_1 = require("../output.js");
11
+ async function list(flags) {
12
+ const config = (0, config_js_1.requireConfig)();
13
+ const workflows = await sdk_1.workflow.listWorkflows(config.api_key);
14
+ (0, output_js_1.printTable)(workflows);
15
+ }
16
+ async function create(flags) {
17
+ if (!flags['org-id'] || !flags.name || !flags['endpoint-id'] || !flags.steps) {
18
+ (0, output_js_1.error)("Missing --org-id, --name, --endpoint-id, or --steps flags");
19
+ }
20
+ const config = (0, config_js_1.requireConfig)();
21
+ let steps;
22
+ try {
23
+ steps = JSON.parse(flags.steps);
24
+ }
25
+ catch (err) {
26
+ (0, output_js_1.error)("Invalid JSON for --steps");
27
+ }
28
+ const wf = await sdk_1.workflow.createWorkflow(config.api_key, {
29
+ org_id: flags['org-id'],
30
+ name: flags.name,
31
+ trigger_config: { endpoint_id: flags['endpoint-id'] },
32
+ steps
33
+ });
34
+ await sdk_1.workflow.enableWorkflow(config.api_key, wf.id);
35
+ (0, output_js_1.success)(`Workflow created and enabled! ID: ${wf.id}`);
36
+ }
37
+ async function enable(id, flags) {
38
+ if (!id)
39
+ (0, output_js_1.error)("Missing id");
40
+ const config = (0, config_js_1.requireConfig)();
41
+ await sdk_1.workflow.enableWorkflow(config.api_key, id);
42
+ (0, output_js_1.success)(`Workflow ${id} enabled`);
43
+ }
44
+ async function disable(id, flags) {
45
+ if (!id)
46
+ (0, output_js_1.error)("Missing id");
47
+ const config = (0, config_js_1.requireConfig)();
48
+ await sdk_1.workflow.disableWorkflow(config.api_key, id);
49
+ (0, output_js_1.success)(`Workflow ${id} disabled`);
50
+ }
51
+ async function runs(id, flags) {
52
+ if (!id)
53
+ (0, output_js_1.error)("Missing id");
54
+ const config = (0, config_js_1.requireConfig)();
55
+ const runs = await sdk_1.workflow.listWorkflowRuns(config.api_key, id);
56
+ (0, output_js_1.printTable)(runs);
57
+ }
@@ -0,0 +1,8 @@
1
+ export interface Config {
2
+ api_key: string;
3
+ account_id: string;
4
+ pin: string;
5
+ }
6
+ export declare function loadConfig(): Config | null;
7
+ export declare function saveConfig(config: Config): void;
8
+ export declare function requireConfig(): Config;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
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.loadConfig = loadConfig;
37
+ exports.saveConfig = saveConfig;
38
+ exports.requireConfig = requireConfig;
39
+ const fs = __importStar(require("fs"));
40
+ const path = __importStar(require("path"));
41
+ const os = __importStar(require("os"));
42
+ const CONFIG_DIR = path.join(os.homedir(), '.myapi');
43
+ const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
44
+ function loadConfig() {
45
+ try {
46
+ if (!fs.existsSync(CONFIG_FILE)) {
47
+ return null;
48
+ }
49
+ const data = fs.readFileSync(CONFIG_FILE, 'utf-8');
50
+ return JSON.parse(data);
51
+ }
52
+ catch (err) {
53
+ return null;
54
+ }
55
+ }
56
+ function saveConfig(config) {
57
+ if (!fs.existsSync(CONFIG_DIR)) {
58
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
59
+ }
60
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), { mode: 0o600 });
61
+ }
62
+ function requireConfig() {
63
+ const config = loadConfig();
64
+ if (!config || !config.api_key) {
65
+ console.error("No API key found. Run: myapi account create");
66
+ process.exit(1);
67
+ }
68
+ return config;
69
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ // AUTO-GENERATED by scripts/generate-indexes.js — do not edit manually
38
+ const utils_js_1 = require("./utils.js");
39
+ const output_js_1 = require("./output.js");
40
+ const sdk_1 = require("@myapihq/sdk");
41
+ const accountCmd = __importStar(require("./commands/account.js"));
42
+ const billingCmd = __importStar(require("./commands/billing.js"));
43
+ const orgCmd = __importStar(require("./commands/org.js"));
44
+ const setupCmd = __importStar(require("./commands/setup.js"));
45
+ async function main() {
46
+ const { args, flags } = (0, utils_js_1.parseArgs)(process.argv.slice(2));
47
+ if (args.length === 0) {
48
+ printHelp();
49
+ process.exit(0);
50
+ }
51
+ const [command, subcommand, ...restArgs] = args;
52
+ try {
53
+ switch (command) {
54
+ case 'setup':
55
+ await setupCmd.setup();
56
+ break;
57
+ case 'account':
58
+ if (subcommand === 'create')
59
+ await accountCmd.create();
60
+ else if (subcommand === 'token')
61
+ await accountCmd.token(flags);
62
+ else if (subcommand === 'keys')
63
+ await accountCmd.listKeys(flags);
64
+ else if (subcommand === 'revoke')
65
+ await accountCmd.revokeKey(restArgs[0], flags);
66
+ else
67
+ printHelp();
68
+ break;
69
+ case 'org':
70
+ if (subcommand === 'list')
71
+ await orgCmd.list(flags);
72
+ else if (subcommand === 'create')
73
+ await orgCmd.create(flags);
74
+ else
75
+ printHelp();
76
+ break;
77
+ case 'billing':
78
+ if (subcommand === 'balance')
79
+ await billingCmd.balance(flags);
80
+ else if (subcommand === 'history')
81
+ await billingCmd.history(flags);
82
+ else if (subcommand === 'topup')
83
+ await billingCmd.topup(restArgs[0], flags);
84
+ else if (subcommand === 'setup')
85
+ await billingCmd.setup(flags);
86
+ else
87
+ printHelp();
88
+ break;
89
+ default:
90
+ printHelp();
91
+ process.exit(0);
92
+ }
93
+ }
94
+ catch (err) {
95
+ if (err instanceof sdk_1.MyApiError) {
96
+ if (err.status === 402)
97
+ (0, output_js_1.error)('Insufficient balance. Run: myapi billing topup <amount>');
98
+ else if (err.status === 401)
99
+ (0, output_js_1.error)('Invalid API key. Run: myapi setup');
100
+ }
101
+ (0, output_js_1.error)(err.message || String(err));
102
+ }
103
+ }
104
+ function printHelp() {
105
+ (0, output_js_1.info)(`myapi - MyAPI command-line interface
106
+
107
+ Usage: myapi <command> [subcommand] [args]
108
+
109
+ Commands:
110
+ account
111
+ billing
112
+ org
113
+ setup
114
+
115
+ Run "myapi <command>" for subcommand help.`);
116
+ }
117
+ main().catch(err => { (0, output_js_1.error)(err.message || String(err)); });
@@ -0,0 +1,5 @@
1
+ export declare function success(message: string): void;
2
+ export declare function error(message: string): never;
3
+ export declare function info(message: string): void;
4
+ export declare function printJson(data: unknown): void;
5
+ export declare function printTable(rows: Record<string, unknown>[]): void;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.success = success;
4
+ exports.error = error;
5
+ exports.info = info;
6
+ exports.printJson = printJson;
7
+ exports.printTable = printTable;
8
+ function success(message) {
9
+ console.log(`\x1b[32m✓\x1b[0m ${message}`);
10
+ }
11
+ function error(message) {
12
+ console.error(`\x1b[31m✗\x1b[0m ${message}`);
13
+ process.exit(1);
14
+ }
15
+ function info(message) {
16
+ console.log(message);
17
+ }
18
+ function printJson(data) {
19
+ console.log(JSON.stringify(data, null, 2));
20
+ }
21
+ function printTable(rows) {
22
+ if (process.argv.includes('--json')) {
23
+ printJson(rows);
24
+ return;
25
+ }
26
+ if (rows.length === 0) {
27
+ console.log("No data found.");
28
+ return;
29
+ }
30
+ const columns = Object.keys(rows[0]);
31
+ const colWidths = columns.map(col => {
32
+ return Math.max(col.length, ...rows.map(row => String(row[col] ?? '').length));
33
+ });
34
+ const printRow = (row) => {
35
+ console.log(row.map((cell, i) => cell.padEnd(colWidths[i] + 2)).join(''));
36
+ };
37
+ printRow(columns);
38
+ console.log(colWidths.map(w => '-'.repeat(w + 2)).join(''));
39
+ for (const row of rows) {
40
+ printRow(columns.map(col => String(row[col] ?? '')));
41
+ }
42
+ }
@@ -0,0 +1,5 @@
1
+ export declare function parseArgs(argv: string[]): {
2
+ args: string[];
3
+ flags: Record<string, string | boolean>;
4
+ };
5
+ export declare function sleep(ms: number): Promise<unknown>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseArgs = parseArgs;
4
+ exports.sleep = sleep;
5
+ function parseArgs(argv) {
6
+ const args = [];
7
+ const flags = {};
8
+ for (let i = 0; i < argv.length; i++) {
9
+ const arg = argv[i];
10
+ if (arg.startsWith('--')) {
11
+ if (arg.includes('=')) {
12
+ const [key, value] = arg.slice(2).split('=', 2);
13
+ flags[key] = value;
14
+ }
15
+ else {
16
+ const next = argv[i + 1];
17
+ if (next && !next.startsWith('--')) {
18
+ flags[arg.slice(2)] = next;
19
+ i++;
20
+ }
21
+ else {
22
+ flags[arg.slice(2)] = true;
23
+ }
24
+ }
25
+ }
26
+ else {
27
+ args.push(arg);
28
+ }
29
+ }
30
+ return { args, flags };
31
+ }
32
+ function sleep(ms) {
33
+ return new Promise(resolve => setTimeout(resolve, ms));
34
+ }
@@ -6,22 +6,31 @@ exports.del = del;
6
6
  const sdk_1 = require("@myapihq/sdk");
7
7
  const config_js_1 = require("../config.js");
8
8
  const output_js_1 = require("../output.js");
9
+ function getOrgId(flags, config) {
10
+ const orgId = flags.org || config.org_id;
11
+ if (!orgId)
12
+ (0, output_js_1.error)("Missing org-id. Pass --org or set it in config.");
13
+ return orgId;
14
+ }
9
15
  async function list(flags) {
10
16
  const config = (0, config_js_1.requireConfig)();
11
- const assets = await sdk_1.storage.listAssets(config.api_key);
17
+ const orgId = getOrgId(flags, config);
18
+ const assets = await sdk_1.storage.listAssets(config.api_key, orgId);
12
19
  (0, output_js_1.printTable)(assets);
13
20
  }
14
21
  async function ingest(url, flags) {
15
22
  if (!url)
16
23
  (0, output_js_1.error)("Missing url");
17
24
  const config = (0, config_js_1.requireConfig)();
18
- const res = await sdk_1.storage.ingestAsset(config.api_key, url, flags.name);
25
+ const orgId = getOrgId(flags, config);
26
+ const res = await sdk_1.storage.ingestAsset(config.api_key, orgId, url, flags.name);
19
27
  (0, output_js_1.success)(`Asset ingested! ID: ${res.asset_id}\nHosted URL: ${res.url}`);
20
28
  }
21
29
  async function del(id, flags) {
22
30
  if (!id)
23
31
  (0, output_js_1.error)("Missing id");
24
32
  const config = (0, config_js_1.requireConfig)();
25
- await sdk_1.storage.deleteAsset(config.api_key, id);
33
+ const orgId = getOrgId(flags, config);
34
+ await sdk_1.storage.deleteAsset(config.api_key, orgId, id);
26
35
  (0, output_js_1.success)(`Asset ${id} deleted`);
27
36
  }
@@ -0,0 +1,6 @@
1
+ export declare class MyApiError extends Error {
2
+ code: string;
3
+ status: number;
4
+ constructor(code: string, status: number);
5
+ }
6
+ export declare function request<T>(method: string, url: string, apiKey?: string, body?: unknown): Promise<T>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MyApiError = void 0;
4
+ exports.request = request;
5
+ class MyApiError extends Error {
6
+ code;
7
+ status;
8
+ constructor(code, status) {
9
+ super(code);
10
+ this.code = code;
11
+ this.status = status;
12
+ this.name = 'MyApiError';
13
+ }
14
+ }
15
+ exports.MyApiError = MyApiError;
16
+ async function request(method, url, apiKey, body) {
17
+ const headers = {};
18
+ if (apiKey) {
19
+ headers['Authorization'] = `Bearer ${apiKey}`;
20
+ }
21
+ if (body !== undefined) {
22
+ headers['Content-Type'] = 'application/json';
23
+ }
24
+ const options = {
25
+ method,
26
+ headers,
27
+ };
28
+ if (body !== undefined) {
29
+ options.body = JSON.stringify(body);
30
+ }
31
+ const response = await fetch(url, options);
32
+ if (response.status === 204) {
33
+ return undefined;
34
+ }
35
+ let result;
36
+ try {
37
+ result = await response.json();
38
+ }
39
+ catch {
40
+ throw new MyApiError('invalid_json_response', response.status);
41
+ }
42
+ if (!response.ok) {
43
+ const code = result?.error || 'unknown_error';
44
+ throw new MyApiError(code, response.status);
45
+ }
46
+ const apiResponse = result;
47
+ if (!apiResponse.success) {
48
+ throw new MyApiError(apiResponse.error || 'unknown_error', response.status);
49
+ }
50
+ return apiResponse.data;
51
+ }
@@ -0,0 +1,32 @@
1
+ export interface DomainRecord {
2
+ domain: string;
3
+ status: string;
4
+ expires_at?: string;
5
+ created_at: string;
6
+ }
7
+ export interface DomainSettings {
8
+ domain: string;
9
+ security_level: string;
10
+ browser_check: string;
11
+ ai_bots_protection: string;
12
+ is_robots_txt_managed: boolean;
13
+ }
14
+ export declare function checkDomain(apiKey: string, domain: string): Promise<{
15
+ available: boolean;
16
+ price_cents: number;
17
+ }>;
18
+ export declare function registerDomain(apiKey: string, domain: string, years?: number): Promise<DomainRecord>;
19
+ export declare function importDomain(apiKey: string, payload: {
20
+ domain: string;
21
+ namecheap_api_user?: string;
22
+ namecheap_api_key?: string;
23
+ }): Promise<DomainRecord>;
24
+ export declare function listDomains(apiKey: string): Promise<DomainRecord[]>;
25
+ export declare function getDomainStatus(apiKey: string, domain: string): Promise<DomainRecord>;
26
+ export declare function renewDomain(apiKey: string, domain: string, years?: number): Promise<DomainRecord>;
27
+ export declare function getDomainSettings(apiKey: string, domain: string): Promise<DomainSettings>;
28
+ export declare function updateDomainSettings(apiKey: string, domain: string, payload: {
29
+ security_level?: 'essentially_off' | 'medium' | 'high' | 'under_attack';
30
+ browser_check?: 'on' | 'off';
31
+ purge_cache?: boolean;
32
+ }): Promise<DomainSettings>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkDomain = checkDomain;
4
+ exports.registerDomain = registerDomain;
5
+ exports.importDomain = importDomain;
6
+ exports.listDomains = listDomains;
7
+ exports.getDomainStatus = getDomainStatus;
8
+ exports.renewDomain = renewDomain;
9
+ exports.getDomainSettings = getDomainSettings;
10
+ exports.updateDomainSettings = updateDomainSettings;
11
+ const client_1 = require("./client");
12
+ const BASE_URL = 'https://api.mydomainapi.com';
13
+ async function checkDomain(apiKey, domain) {
14
+ return (0, client_1.request)('GET', `${BASE_URL}/domain/check/${encodeURIComponent(domain)}`, apiKey);
15
+ }
16
+ async function registerDomain(apiKey, domain, years) {
17
+ return (0, client_1.request)('POST', `${BASE_URL}/domain/register`, apiKey, { domain, years });
18
+ }
19
+ async function importDomain(apiKey, payload) {
20
+ return (0, client_1.request)('POST', `${BASE_URL}/domain/import`, apiKey, payload);
21
+ }
22
+ async function listDomains(apiKey) {
23
+ return (0, client_1.request)('GET', `${BASE_URL}/domain/list/me`, apiKey);
24
+ }
25
+ async function getDomainStatus(apiKey, domain) {
26
+ return (0, client_1.request)('GET', `${BASE_URL}/domain/status/${encodeURIComponent(domain)}`, apiKey);
27
+ }
28
+ async function renewDomain(apiKey, domain, years) {
29
+ return (0, client_1.request)('POST', `${BASE_URL}/domain/renew/${encodeURIComponent(domain)}`, apiKey, { years });
30
+ }
31
+ async function getDomainSettings(apiKey, domain) {
32
+ return (0, client_1.request)('GET', `${BASE_URL}/domain/settings/${encodeURIComponent(domain)}`, apiKey);
33
+ }
34
+ async function updateDomainSettings(apiKey, domain, payload) {
35
+ return (0, client_1.request)('POST', `${BASE_URL}/domain/settings/${encodeURIComponent(domain)}`, apiKey, payload);
36
+ }