@myapihq/sdk 1.0.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/src/hq.ts ADDED
@@ -0,0 +1,109 @@
1
+ import { request } from './client';
2
+
3
+ const BASE_URL = 'https://api.myapihq.com';
4
+
5
+ export interface Org {
6
+ id: string;
7
+ name: string;
8
+ tagline?: string;
9
+ description?: string;
10
+ business_sector?: string;
11
+ logo_url?: string;
12
+ favicon_url?: string;
13
+ og_image_url?: string;
14
+ color_palette?: Record<string, string>;
15
+ font_family?: string;
16
+ imagery_style?: string;
17
+ headline?: string;
18
+ subheadline?: string;
19
+ cta_text?: string;
20
+ value_propositions?: string[];
21
+ social_links?: Record<string, string>;
22
+ canonical_url?: string;
23
+ privacy_policy_url?: string;
24
+ cookie_policy_url?: string;
25
+ terms_url?: string;
26
+ gdpr_enabled?: boolean;
27
+ default_language?: string;
28
+ tracking?: Record<string, unknown>;
29
+ created_at: string;
30
+ updated_at: string;
31
+ }
32
+
33
+ export type OrgPayload = Omit<Org, 'id' | 'created_at' | 'updated_at'>;
34
+
35
+ export async function createAgentAccount(): Promise<{ account_id: string; pin: string; token: string }> {
36
+ return request('POST', `${BASE_URL}/hq/account/agent/create`);
37
+ }
38
+
39
+ export async function recoverAgentToken(pin: string): Promise<{ token: string }> {
40
+ return request('POST', `${BASE_URL}/hq/account/agent/token`, undefined, { pin });
41
+ }
42
+
43
+ export async function createApiKey(jwtToken: string, name: string): Promise<{ api_key: string; id: string; prefix: string }> {
44
+ return request('POST', `${BASE_URL}/hq/account/create/key`, jwtToken, { name });
45
+ }
46
+
47
+ export async function listApiKeys(apiKey: string): Promise<{ id: string; name: string; prefix: string; created_at: string }[]> {
48
+ return request('GET', `${BASE_URL}/hq/account/keys`, apiKey);
49
+ }
50
+
51
+ export async function revokeApiKey(apiKey: string, keyId: string): Promise<void> {
52
+ return request('DELETE', `${BASE_URL}/hq/account/delete/key/${encodeURIComponent(keyId)}`, apiKey);
53
+ }
54
+
55
+ export async function linkAgent(apiKey: string, pin: string): Promise<void> {
56
+ return request('POST', `${BASE_URL}/hq/account/link-agent`, apiKey, { pin });
57
+ }
58
+
59
+ export async function listLinkedAgents(apiKey: string): Promise<{ account_id: string; created_at: string }[]> {
60
+ return request('GET', `${BASE_URL}/hq/account/agents`, apiKey);
61
+ }
62
+
63
+ export async function createOrg(apiKey: string, payload: OrgPayload): Promise<Org> {
64
+ return request('POST', `${BASE_URL}/hq/orgs`, apiKey, payload);
65
+ }
66
+
67
+ export async function importOrg(apiKey: string, domain: string, autoAccept?: boolean): Promise<{ job_id: string; status: string }> {
68
+ return request('POST', `${BASE_URL}/hq/org-imports`, apiKey, { domain, auto_accept: autoAccept });
69
+ }
70
+
71
+ export async function getOrgImportStatus(apiKey: string, jobId: string): Promise<{ status: string; brand_preview: unknown }> {
72
+ return request('GET', `${BASE_URL}/hq/org-imports/${encodeURIComponent(jobId)}`, apiKey);
73
+ }
74
+
75
+ export async function confirmOrgImport(apiKey: string, jobId: string, overrides?: Partial<OrgPayload>): Promise<Org> {
76
+ return request('POST', `${BASE_URL}/hq/org-imports/${encodeURIComponent(jobId)}/confirm`, apiKey, overrides);
77
+ }
78
+
79
+ export async function listOrgs(apiKey: string): Promise<Org[]> {
80
+ return request('GET', `${BASE_URL}/hq/orgs`, apiKey);
81
+ }
82
+
83
+ export async function getOrg(apiKey: string, orgId: string): Promise<Org> {
84
+ return request('GET', `${BASE_URL}/hq/orgs/${encodeURIComponent(orgId)}`, apiKey);
85
+ }
86
+
87
+ export async function updateOrg(apiKey: string, orgId: string, payload: Partial<OrgPayload>): Promise<Org> {
88
+ return request('PATCH', `${BASE_URL}/hq/orgs/${encodeURIComponent(orgId)}`, apiKey, payload);
89
+ }
90
+
91
+ export async function deleteOrg(apiKey: string, orgId: string): Promise<void> {
92
+ return request('DELETE', `${BASE_URL}/hq/orgs/${encodeURIComponent(orgId)}`, apiKey);
93
+ }
94
+
95
+ export async function getBalance(apiKey: string): Promise<{ balance_cents: number; balance_display: string; has_payment_method: boolean }> {
96
+ return request('GET', `${BASE_URL}/hq/billing/balance`, apiKey);
97
+ }
98
+
99
+ export async function getBillingHistory(apiKey: string): Promise<{ amount_cents: number; status: string; created_at: string }[]> {
100
+ return request('GET', `${BASE_URL}/hq/billing/history`, apiKey);
101
+ }
102
+
103
+ export async function setupPayment(apiKey: string): Promise<{ url: string }> {
104
+ return request('POST', `${BASE_URL}/hq/billing/setup-payment`, apiKey);
105
+ }
106
+
107
+ export async function topUp(apiKey: string, amountCents: number): Promise<{ new_balance_cents: number; new_balance_display: string }> {
108
+ return request('POST', `${BASE_URL}/hq/billing/topup`, apiKey, { amount_cents: amountCents });
109
+ }
package/src/image.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { request } from './client';
2
+
3
+ const BASE_URL = 'https://api.myimageapi.com';
4
+
5
+ export interface ImageJob {
6
+ job_id: string;
7
+ status: 'pending' | 'processing' | 'completed' | 'failed';
8
+ url?: string;
9
+ error?: string;
10
+ prompt: string;
11
+ aspect_ratio: string;
12
+ created_at: string;
13
+ }
14
+
15
+ export async function generateImage(apiKey: string, payload: {
16
+ prompt: string;
17
+ aspect_ratio?: '1:1' | '16:9' | '9:16' | '4:3' | '3:4';
18
+ style?: string;
19
+ colors?: string;
20
+ has_text?: boolean;
21
+ }): Promise<{ job_id: string; status: string }> {
22
+ return request('POST', `${BASE_URL}/image/generate`, apiKey, payload);
23
+ }
24
+
25
+ export async function getImageJob(apiKey: string, jobId: string): Promise<ImageJob> {
26
+ return request('GET', `${BASE_URL}/image/jobs/${encodeURIComponent(jobId)}`, apiKey);
27
+ }
28
+
29
+ export async function listImages(apiKey: string): Promise<ImageJob[]> {
30
+ return request('GET', `${BASE_URL}/image/list`, apiKey);
31
+ }
package/src/index.ts ADDED
@@ -0,0 +1,11 @@
1
+ export * from './types';
2
+ export * from './client';
3
+ export * as hq from './hq';
4
+ export * as domain from './domain';
5
+ export * as email from './email';
6
+ export * as funnel from './funnel';
7
+ export * as image from './image';
8
+ export * as pixel from './pixel';
9
+ export * as storage from './storage';
10
+ export * as webhook from './webhook';
11
+ export * as workflow from './workflow';
package/src/pixel.ts ADDED
@@ -0,0 +1,61 @@
1
+ import { request } from './client';
2
+
3
+ const BASE_URL = 'https://api.mypixelapi.com';
4
+
5
+ export interface InteractionsResponse {
6
+ interactions: (Visit | PixelEvent)[];
7
+ total_visits: number;
8
+ total_events: number;
9
+ limit: number;
10
+ offset: number;
11
+ }
12
+ export interface Visit { type: 'visit'; pixel_id: string; from_url: string; to_url: string; ts: string }
13
+ export interface PixelEvent { type: 'event'; pixel_id: string; event_type: 'sent' | 'open' | 'click' | 'page_visit'; url?: string; campaign_id?: string; ts: string }
14
+
15
+ export async function getInteractions(apiKey: string, params: {
16
+ website?: string;
17
+ domain?: string;
18
+ campaign_id?: string;
19
+ from?: string;
20
+ to?: string;
21
+ limit?: number;
22
+ offset?: number;
23
+ }): Promise<InteractionsResponse> {
24
+ const qs = new URLSearchParams();
25
+ for (const [key, val] of Object.entries(params)) {
26
+ if (val !== undefined && val !== null) {
27
+ qs.set(key, String(val));
28
+ }
29
+ }
30
+ const queryString = qs.toString();
31
+ const url = `${BASE_URL}/pixel/interactions${queryString ? `?${queryString}` : ''}`;
32
+ return request('GET', url, apiKey);
33
+ }
34
+
35
+ export async function getVisits(apiKey: string, params: { website: string; from?: string; to?: string; limit?: number; offset?: number }): Promise<{ visits: Visit[]; total: number; limit: number; offset: number }> {
36
+ const qs = new URLSearchParams();
37
+ for (const [key, val] of Object.entries(params)) {
38
+ if (val !== undefined && val !== null) {
39
+ qs.set(key, String(val));
40
+ }
41
+ }
42
+ const queryString = qs.toString();
43
+ const url = `${BASE_URL}/pixel/visits${queryString ? `?${queryString}` : ''}`;
44
+ return request('GET', url, apiKey);
45
+ }
46
+
47
+ export async function getEvents(apiKey: string, params: { campaign_id?: string; domain?: string; from?: string; to?: string; limit?: number; offset?: number }): Promise<{ events: PixelEvent[]; total: number; limit: number; offset: number }> {
48
+ const qs = new URLSearchParams();
49
+ for (const [key, val] of Object.entries(params)) {
50
+ if (val !== undefined && val !== null) {
51
+ qs.set(key, String(val));
52
+ }
53
+ }
54
+ const queryString = qs.toString();
55
+ const url = `${BASE_URL}/pixel/events${queryString ? `?${queryString}` : ''}`;
56
+ return request('GET', url, apiKey);
57
+ }
58
+
59
+ export async function getIdentity(apiKey: string, pixelId: string): Promise<{ uuid: string; is_resolved: boolean; nodes: Record<string, { type: string; probability: number }>; latency_ms: number }> {
60
+ return request('GET', `${BASE_URL}/pixel/identity/${encodeURIComponent(pixelId)}`, apiKey);
61
+ }
package/src/storage.ts ADDED
@@ -0,0 +1,55 @@
1
+ import { request, MyApiError } from './client';
2
+ import { ApiResponse } from './types';
3
+
4
+ const BASE_URL = 'https://api.mystorageapi.com';
5
+
6
+ export interface Asset { asset_id: string; url: string; name: string; created_at: string }
7
+
8
+ export async function ingestAsset(apiKey: string, url: string, name?: string): Promise<Asset> {
9
+ return request('POST', `${BASE_URL}/hq/assets/ingest`, apiKey, { url, name });
10
+ }
11
+
12
+ export async function uploadAsset(apiKey: string, file: Blob | Buffer, contentType: 'image/jpeg' | 'image/png', name?: string): Promise<Asset> {
13
+ const headers: Record<string, string> = {
14
+ 'Authorization': `Bearer ${apiKey}`
15
+ };
16
+
17
+ const formData = new FormData();
18
+ formData.append('file', new Blob([file as any], { type: contentType }));
19
+ if (name) {
20
+ formData.append('name', name);
21
+ }
22
+
23
+ const response = await fetch(`${BASE_URL}/hq/assets/upload`, {
24
+ method: 'POST',
25
+ headers,
26
+ body: formData as any
27
+ });
28
+
29
+ let result: any;
30
+ try {
31
+ result = await response.json();
32
+ } catch {
33
+ throw new MyApiError('invalid_json_response', response.status);
34
+ }
35
+
36
+ if (!response.ok) {
37
+ const code = result?.error || 'unknown_error';
38
+ throw new MyApiError(code, response.status);
39
+ }
40
+
41
+ const apiResponse = result as ApiResponse<Asset>;
42
+ if (!apiResponse.success) {
43
+ throw new MyApiError(apiResponse.error || 'unknown_error', response.status);
44
+ }
45
+
46
+ return apiResponse.data as Asset;
47
+ }
48
+
49
+ export async function listAssets(apiKey: string): Promise<Asset[]> {
50
+ return request('GET', `${BASE_URL}/hq/assets`, apiKey);
51
+ }
52
+
53
+ export async function deleteAsset(apiKey: string, assetId: string): Promise<void> {
54
+ return request('DELETE', `${BASE_URL}/hq/assets/${encodeURIComponent(assetId)}`, apiKey);
55
+ }
package/src/types.ts ADDED
@@ -0,0 +1,13 @@
1
+ export interface ApiResponse<T> {
2
+ success: boolean;
3
+ data: T | null;
4
+ error: string | null;
5
+ meta: { request_id: string; latency_ms: number; service: string; version: string };
6
+ }
7
+
8
+ export interface PaginatedResponse<T> {
9
+ data: T[];
10
+ total: number;
11
+ limit: number;
12
+ offset: number;
13
+ }
package/src/webhook.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { request } from './client';
2
+
3
+ const BASE_URL = 'https://api.mywebhookapi.com';
4
+
5
+ export interface WebhookEndpoint { id: string; org_id: string; name: string; slug: string; inbound_url: string; created_at: string }
6
+ export interface Delivery { id: string; endpoint_id: string; payload: unknown; headers: Record<string, string>; status: string; created_at: string }
7
+
8
+ export async function createEndpoint(apiKey: string, orgId: string, name: string, description?: string): Promise<WebhookEndpoint> {
9
+ return request('POST', `${BASE_URL}/webhook/endpoints`, apiKey, { org_id: orgId, name, description });
10
+ }
11
+
12
+ export async function listEndpoints(apiKey: string): Promise<WebhookEndpoint[]> {
13
+ return request('GET', `${BASE_URL}/webhook/endpoints`, apiKey);
14
+ }
15
+
16
+ export async function deleteEndpoint(apiKey: string, endpointId: string): Promise<void> {
17
+ return request('DELETE', `${BASE_URL}/webhook/endpoints/${encodeURIComponent(endpointId)}`, apiKey);
18
+ }
19
+
20
+ export async function getDelivery(apiKey: string, deliveryId: string): Promise<Delivery> {
21
+ return request('GET', `${BASE_URL}/webhook/deliveries/${encodeURIComponent(deliveryId)}`, apiKey);
22
+ }
@@ -0,0 +1,51 @@
1
+ import { request } from './client';
2
+
3
+ const BASE_URL = 'https://api.myworkflowapi.com';
4
+
5
+ export type WorkflowStep =
6
+ | { type: 'send_email'; from: string; to: string; subject: string; template_id?: string; html?: string }
7
+ | { type: 'slack_message'; webhook_url: string; text: string };
8
+
9
+ export interface Workflow { id: string; org_id: string; name: string; status: 'enabled' | 'disabled'; trigger_config: { endpoint_id: string }; steps: WorkflowStep[]; created_at: string }
10
+ export interface WorkflowRun { id: string; workflow_id: string; trigger_payload: unknown; status: 'pending' | 'running' | 'completed' | 'failed'; error?: string; attempt: number; started_at: string; finished_at?: string; created_at: string }
11
+
12
+ export async function createWorkflow(apiKey: string, payload: {
13
+ org_id: string;
14
+ name: string;
15
+ trigger_config: { endpoint_id: string };
16
+ steps: WorkflowStep[];
17
+ }): Promise<Workflow> {
18
+ return request('POST', `${BASE_URL}/workflow/workflows`, apiKey, payload);
19
+ }
20
+
21
+ export async function listWorkflows(apiKey: string): Promise<Workflow[]> {
22
+ return request('GET', `${BASE_URL}/workflow/workflows`, apiKey);
23
+ }
24
+
25
+ export async function getWorkflow(apiKey: string, workflowId: string): Promise<Workflow> {
26
+ return request('GET', `${BASE_URL}/workflow/workflows/${encodeURIComponent(workflowId)}`, apiKey);
27
+ }
28
+
29
+ export async function updateWorkflow(apiKey: string, workflowId: string, payload: { name?: string; trigger_config?: { endpoint_id: string }; steps?: WorkflowStep[] }): Promise<Workflow> {
30
+ return request('PATCH', `${BASE_URL}/workflow/workflows/${encodeURIComponent(workflowId)}`, apiKey, payload);
31
+ }
32
+
33
+ export async function enableWorkflow(apiKey: string, workflowId: string): Promise<void> {
34
+ return request('POST', `${BASE_URL}/workflow/workflows/${encodeURIComponent(workflowId)}/enable`, apiKey);
35
+ }
36
+
37
+ export async function disableWorkflow(apiKey: string, workflowId: string): Promise<void> {
38
+ return request('POST', `${BASE_URL}/workflow/workflows/${encodeURIComponent(workflowId)}/disable`, apiKey);
39
+ }
40
+
41
+ export async function deleteWorkflow(apiKey: string, workflowId: string): Promise<void> {
42
+ return request('DELETE', `${BASE_URL}/workflow/workflows/${encodeURIComponent(workflowId)}`, apiKey);
43
+ }
44
+
45
+ export async function listWorkflowRuns(apiKey: string, workflowId: string): Promise<WorkflowRun[]> {
46
+ return request('GET', `${BASE_URL}/workflow/workflows/${encodeURIComponent(workflowId)}/runs`, apiKey);
47
+ }
48
+
49
+ export async function getWorkflowRun(apiKey: string, runId: string): Promise<WorkflowRun> {
50
+ return request('GET', `${BASE_URL}/workflow/runs/${encodeURIComponent(runId)}`, apiKey);
51
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "declaration": true,
7
+ "outDir": "./dist",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true
12
+ },
13
+ "include": ["src/**/*"]
14
+ }