@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,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getInteractions = getInteractions;
4
+ exports.getVisits = getVisits;
5
+ exports.getEvents = getEvents;
6
+ exports.getIdentity = getIdentity;
7
+ const client_1 = require("./client");
8
+ const BASE_URL = 'https://api.mypixelapi.com';
9
+ async function getInteractions(apiKey, params) {
10
+ const qs = new URLSearchParams();
11
+ for (const [key, val] of Object.entries(params)) {
12
+ if (val !== undefined && val !== null) {
13
+ qs.set(key, String(val));
14
+ }
15
+ }
16
+ const queryString = qs.toString();
17
+ const url = `${BASE_URL}/pixel/interactions${queryString ? `?${queryString}` : ''}`;
18
+ return (0, client_1.request)('GET', url, apiKey);
19
+ }
20
+ async function getVisits(apiKey, params) {
21
+ const qs = new URLSearchParams();
22
+ for (const [key, val] of Object.entries(params)) {
23
+ if (val !== undefined && val !== null) {
24
+ qs.set(key, String(val));
25
+ }
26
+ }
27
+ const queryString = qs.toString();
28
+ const url = `${BASE_URL}/pixel/visits${queryString ? `?${queryString}` : ''}`;
29
+ return (0, client_1.request)('GET', url, apiKey);
30
+ }
31
+ async function getEvents(apiKey, params) {
32
+ const qs = new URLSearchParams();
33
+ for (const [key, val] of Object.entries(params)) {
34
+ if (val !== undefined && val !== null) {
35
+ qs.set(key, String(val));
36
+ }
37
+ }
38
+ const queryString = qs.toString();
39
+ const url = `${BASE_URL}/pixel/events${queryString ? `?${queryString}` : ''}`;
40
+ return (0, client_1.request)('GET', url, apiKey);
41
+ }
42
+ async function getIdentity(apiKey, pixelId) {
43
+ return (0, client_1.request)('GET', `${BASE_URL}/pixel/identity/${encodeURIComponent(pixelId)}`, apiKey);
44
+ }
@@ -0,0 +1,10 @@
1
+ export interface Asset {
2
+ asset_id: string;
3
+ url: string;
4
+ name: string;
5
+ created_at: string;
6
+ }
7
+ export declare function ingestAsset(apiKey: string, orgId: string, url: string, name?: string): Promise<Asset>;
8
+ export declare function uploadAsset(apiKey: string, orgId: string, file: Blob | Buffer, contentType: 'image/jpeg' | 'image/png', name?: string): Promise<Asset>;
9
+ export declare function listAssets(apiKey: string, orgId: string): Promise<Asset[]>;
10
+ export declare function deleteAsset(apiKey: string, orgId: string, assetId: string): Promise<void>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ingestAsset = ingestAsset;
4
+ exports.uploadAsset = uploadAsset;
5
+ exports.listAssets = listAssets;
6
+ exports.deleteAsset = deleteAsset;
7
+ const client_1 = require("./client");
8
+ const BASE_URL = 'https://api.mystorageapi.com';
9
+ async function ingestAsset(apiKey, orgId, url, name) {
10
+ return (0, client_1.request)('POST', `${BASE_URL}/storage/orgs/${encodeURIComponent(orgId)}/assets/ingest`, apiKey, { url, name });
11
+ }
12
+ async function uploadAsset(apiKey, orgId, file, contentType, name) {
13
+ const headers = {
14
+ 'Authorization': `Bearer ${apiKey}`
15
+ };
16
+ const formData = new FormData();
17
+ formData.append('file', new Blob([file], { type: contentType }));
18
+ if (name) {
19
+ formData.append('name', name);
20
+ }
21
+ const response = await fetch(`${BASE_URL}/storage/orgs/${encodeURIComponent(orgId)}/assets/upload`, {
22
+ method: 'POST',
23
+ headers,
24
+ body: formData
25
+ });
26
+ let result;
27
+ try {
28
+ result = await response.json();
29
+ }
30
+ catch {
31
+ throw new client_1.MyApiError('invalid_json_response', response.status);
32
+ }
33
+ if (!response.ok) {
34
+ const code = result?.error || 'unknown_error';
35
+ throw new client_1.MyApiError(code, response.status);
36
+ }
37
+ const apiResponse = result;
38
+ if (!apiResponse.success) {
39
+ throw new client_1.MyApiError(apiResponse.error || 'unknown_error', response.status);
40
+ }
41
+ return apiResponse.data;
42
+ }
43
+ async function listAssets(apiKey, orgId) {
44
+ return (0, client_1.request)('GET', `${BASE_URL}/storage/orgs/${encodeURIComponent(orgId)}/assets`, apiKey);
45
+ }
46
+ async function deleteAsset(apiKey, orgId, assetId) {
47
+ return (0, client_1.request)('DELETE', `${BASE_URL}/storage/orgs/${encodeURIComponent(orgId)}/assets/${encodeURIComponent(assetId)}`, apiKey);
48
+ }
@@ -0,0 +1,17 @@
1
+ export interface ApiResponse<T> {
2
+ success: boolean;
3
+ data: T | null;
4
+ error: string | null;
5
+ meta: {
6
+ request_id: string;
7
+ latency_ms: number;
8
+ service: string;
9
+ version: string;
10
+ };
11
+ }
12
+ export interface PaginatedResponse<T> {
13
+ data: T[];
14
+ total: number;
15
+ limit: number;
16
+ offset: number;
17
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,20 @@
1
+ export interface WebhookEndpoint {
2
+ id: string;
3
+ org_id: string;
4
+ name: string;
5
+ slug: string;
6
+ inbound_url: string;
7
+ created_at: string;
8
+ }
9
+ export interface Delivery {
10
+ id: string;
11
+ endpoint_id: string;
12
+ payload: unknown;
13
+ headers: Record<string, string>;
14
+ status: string;
15
+ created_at: string;
16
+ }
17
+ export declare function createEndpoint(apiKey: string, orgId: string, name: string, description?: string): Promise<WebhookEndpoint>;
18
+ export declare function listEndpoints(apiKey: string): Promise<WebhookEndpoint[]>;
19
+ export declare function deleteEndpoint(apiKey: string, endpointId: string): Promise<void>;
20
+ export declare function getDelivery(apiKey: string, deliveryId: string): Promise<Delivery>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createEndpoint = createEndpoint;
4
+ exports.listEndpoints = listEndpoints;
5
+ exports.deleteEndpoint = deleteEndpoint;
6
+ exports.getDelivery = getDelivery;
7
+ const client_1 = require("./client");
8
+ const BASE_URL = 'https://api.mywebhookapi.com';
9
+ async function createEndpoint(apiKey, orgId, name, description) {
10
+ return (0, client_1.request)('POST', `${BASE_URL}/webhook/endpoints`, apiKey, { org_id: orgId, name, description });
11
+ }
12
+ async function listEndpoints(apiKey) {
13
+ return (0, client_1.request)('GET', `${BASE_URL}/webhook/endpoints`, apiKey);
14
+ }
15
+ async function deleteEndpoint(apiKey, endpointId) {
16
+ return (0, client_1.request)('DELETE', `${BASE_URL}/webhook/endpoints/${encodeURIComponent(endpointId)}`, apiKey);
17
+ }
18
+ async function getDelivery(apiKey, deliveryId) {
19
+ return (0, client_1.request)('GET', `${BASE_URL}/webhook/deliveries/${encodeURIComponent(deliveryId)}`, apiKey);
20
+ }
@@ -0,0 +1,56 @@
1
+ export type WorkflowStep = {
2
+ type: 'send_email';
3
+ from: string;
4
+ to: string;
5
+ subject: string;
6
+ template_id?: string;
7
+ html?: string;
8
+ } | {
9
+ type: 'slack_message';
10
+ webhook_url: string;
11
+ text: string;
12
+ };
13
+ export interface Workflow {
14
+ id: string;
15
+ org_id: string;
16
+ name: string;
17
+ status: 'enabled' | 'disabled';
18
+ trigger_config: {
19
+ endpoint_id: string;
20
+ };
21
+ steps: WorkflowStep[];
22
+ created_at: string;
23
+ }
24
+ export interface WorkflowRun {
25
+ id: string;
26
+ workflow_id: string;
27
+ trigger_payload: unknown;
28
+ status: 'pending' | 'running' | 'completed' | 'failed';
29
+ error?: string;
30
+ attempt: number;
31
+ started_at: string;
32
+ finished_at?: string;
33
+ created_at: string;
34
+ }
35
+ export declare function createWorkflow(apiKey: string, payload: {
36
+ org_id: string;
37
+ name: string;
38
+ trigger_config: {
39
+ endpoint_id: string;
40
+ };
41
+ steps: WorkflowStep[];
42
+ }): Promise<Workflow>;
43
+ export declare function listWorkflows(apiKey: string): Promise<Workflow[]>;
44
+ export declare function getWorkflow(apiKey: string, workflowId: string): Promise<Workflow>;
45
+ export declare function updateWorkflow(apiKey: string, workflowId: string, payload: {
46
+ name?: string;
47
+ trigger_config?: {
48
+ endpoint_id: string;
49
+ };
50
+ steps?: WorkflowStep[];
51
+ }): Promise<Workflow>;
52
+ export declare function enableWorkflow(apiKey: string, workflowId: string): Promise<void>;
53
+ export declare function disableWorkflow(apiKey: string, workflowId: string): Promise<void>;
54
+ export declare function deleteWorkflow(apiKey: string, workflowId: string): Promise<void>;
55
+ export declare function listWorkflowRuns(apiKey: string, workflowId: string): Promise<WorkflowRun[]>;
56
+ export declare function getWorkflowRun(apiKey: string, runId: string): Promise<WorkflowRun>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createWorkflow = createWorkflow;
4
+ exports.listWorkflows = listWorkflows;
5
+ exports.getWorkflow = getWorkflow;
6
+ exports.updateWorkflow = updateWorkflow;
7
+ exports.enableWorkflow = enableWorkflow;
8
+ exports.disableWorkflow = disableWorkflow;
9
+ exports.deleteWorkflow = deleteWorkflow;
10
+ exports.listWorkflowRuns = listWorkflowRuns;
11
+ exports.getWorkflowRun = getWorkflowRun;
12
+ const client_1 = require("./client");
13
+ const BASE_URL = 'https://api.myworkflowapi.com';
14
+ async function createWorkflow(apiKey, payload) {
15
+ return (0, client_1.request)('POST', `${BASE_URL}/workflow/workflows`, apiKey, payload);
16
+ }
17
+ async function listWorkflows(apiKey) {
18
+ return (0, client_1.request)('GET', `${BASE_URL}/workflow/workflows`, apiKey);
19
+ }
20
+ async function getWorkflow(apiKey, workflowId) {
21
+ return (0, client_1.request)('GET', `${BASE_URL}/workflow/workflows/${encodeURIComponent(workflowId)}`, apiKey);
22
+ }
23
+ async function updateWorkflow(apiKey, workflowId, payload) {
24
+ return (0, client_1.request)('PATCH', `${BASE_URL}/workflow/workflows/${encodeURIComponent(workflowId)}`, apiKey, payload);
25
+ }
26
+ async function enableWorkflow(apiKey, workflowId) {
27
+ return (0, client_1.request)('POST', `${BASE_URL}/workflow/workflows/${encodeURIComponent(workflowId)}/enable`, apiKey);
28
+ }
29
+ async function disableWorkflow(apiKey, workflowId) {
30
+ return (0, client_1.request)('POST', `${BASE_URL}/workflow/workflows/${encodeURIComponent(workflowId)}/disable`, apiKey);
31
+ }
32
+ async function deleteWorkflow(apiKey, workflowId) {
33
+ return (0, client_1.request)('DELETE', `${BASE_URL}/workflow/workflows/${encodeURIComponent(workflowId)}`, apiKey);
34
+ }
35
+ async function listWorkflowRuns(apiKey, workflowId) {
36
+ return (0, client_1.request)('GET', `${BASE_URL}/workflow/workflows/${encodeURIComponent(workflowId)}/runs`, apiKey);
37
+ }
38
+ async function getWorkflowRun(apiKey, runId) {
39
+ return (0, client_1.request)('GET', `${BASE_URL}/workflow/runs/${encodeURIComponent(runId)}`, apiKey);
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myapihq/cli",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "MyAPI command-line interface",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -2,22 +2,31 @@ import { storage as sdkStorage } from '@myapihq/sdk';
2
2
  import { requireConfig } from '../config.js';
3
3
  import { success, error, printTable } from '../output.js';
4
4
 
5
+ function getOrgId(flags: Record<string, string | boolean>, config: any): string {
6
+ const orgId = flags.org || config.org_id;
7
+ if (!orgId) error("Missing org-id. Pass --org or set it in config.");
8
+ return orgId as string;
9
+ }
10
+
5
11
  export async function list(flags: Record<string, string | boolean>) {
6
12
  const config = requireConfig();
7
- const assets = await sdkStorage.listAssets(config.api_key);
13
+ const orgId = getOrgId(flags, config);
14
+ const assets = await sdkStorage.listAssets(config.api_key, orgId);
8
15
  printTable(assets as unknown as Record<string, unknown>[]);
9
16
  }
10
17
 
11
18
  export async function ingest(url: string, flags: Record<string, string | boolean>) {
12
19
  if (!url) error("Missing url");
13
20
  const config = requireConfig();
14
- const res = await sdkStorage.ingestAsset(config.api_key, url, flags.name as string);
21
+ const orgId = getOrgId(flags, config);
22
+ const res = await sdkStorage.ingestAsset(config.api_key, orgId, url, flags.name as string);
15
23
  success(`Asset ingested! ID: ${res.asset_id}\nHosted URL: ${res.url}`);
16
24
  }
17
25
 
18
26
  export async function del(id: string, flags: Record<string, string | boolean>) {
19
27
  if (!id) error("Missing id");
20
28
  const config = requireConfig();
21
- await sdkStorage.deleteAsset(config.api_key, id);
29
+ const orgId = getOrgId(flags, config);
30
+ await sdkStorage.deleteAsset(config.api_key, orgId, id);
22
31
  success(`Asset ${id} deleted`);
23
32
  }
package/tsconfig.json CHANGED
@@ -8,7 +8,11 @@
8
8
  "strict": true,
9
9
  "esModuleInterop": true,
10
10
  "skipLibCheck": true,
11
- "forceConsistentCasingInFileNames": true
11
+ "forceConsistentCasingInFileNames": true,
12
+ "paths": {
13
+ "@myapihq/sdk": ["../sdk/src/index.ts"],
14
+ "@myapihq/sdk/*": ["../sdk/src/*"]
15
+ }
12
16
  },
13
17
  "include": ["src/**/*"]
14
18
  }