@myapihq/sdk 1.2.2 → 1.2.4

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/client.d.ts CHANGED
@@ -2,6 +2,7 @@ export declare class MyApiError extends Error {
2
2
  code: string;
3
3
  status: number;
4
4
  detail?: string | undefined;
5
- constructor(code: string, status: number, detail?: string | undefined);
5
+ body?: Record<string, unknown> | undefined;
6
+ constructor(code: string, status: number, detail?: string | undefined, body?: Record<string, unknown> | undefined);
6
7
  }
7
8
  export declare function request<T>(method: string, url: string, apiKey?: string, body?: unknown, extraHeaders?: Record<string, string>): Promise<T>;
package/dist/client.js CHANGED
@@ -6,13 +6,18 @@ class MyApiError extends Error {
6
6
  code;
7
7
  status;
8
8
  detail;
9
- constructor(code, status, detail) {
9
+ body;
10
+ // `body` is the full error object as returned by the backend — preserved so
11
+ // callers can read service-specific fields the SDK doesn't otherwise model
12
+ // (e.g. CF_API_ERROR carries `cf_message` / `cf_status`).
13
+ constructor(code, status, detail, body) {
10
14
  // Surface the detail in the message so console.error / err.message
11
15
  // shows useful info without callers having to look at err.detail.
12
16
  super(detail ? `${code} (${status}): ${detail}` : code);
13
17
  this.code = code;
14
18
  this.status = status;
15
19
  this.detail = detail;
20
+ this.body = body;
16
21
  this.name = 'MyApiError';
17
22
  }
18
23
  }
@@ -59,14 +64,16 @@ async function request(method, url, apiKey, body, extraHeaders) {
59
64
  const err = result?.error;
60
65
  const code = typeof err === 'object' ? (err?.code || 'unknown_error') : (err || 'unknown_error');
61
66
  const detail = typeof err === 'object' ? (err?.message || undefined) : undefined;
62
- throw new MyApiError(code, response.status, detail);
67
+ const body = typeof err === 'object' ? err : undefined;
68
+ throw new MyApiError(code, response.status, detail, body);
63
69
  }
64
70
  const apiResponse = result;
65
71
  if (!apiResponse.success) {
66
72
  const err = apiResponse.error;
67
73
  const code = typeof err === 'object' ? (err?.code || 'unknown_error') : (err || 'unknown_error');
68
74
  const detail = typeof err === 'object' ? (err?.message || undefined) : undefined;
69
- throw new MyApiError(code, response.status, detail);
75
+ const body = typeof err === 'object' ? err : undefined;
76
+ throw new MyApiError(code, response.status, detail, body);
70
77
  }
71
78
  return apiResponse.data;
72
79
  }
package/dist/domain.d.ts CHANGED
@@ -6,6 +6,17 @@ export interface DomainRecord {
6
6
  expires_at?: string;
7
7
  days_until_expiry?: number;
8
8
  email_infra_ready?: boolean;
9
+ email_infra?: 'skipped' | 'pending' | 'ready' | 'error';
10
+ email_subdomain?: string;
11
+ dns_active?: boolean;
12
+ steps_completed?: string[];
13
+ error_detail?: {
14
+ failed_step: string;
15
+ message: string;
16
+ retryable: boolean;
17
+ attempt_count?: number;
18
+ last_attempt_at?: string;
19
+ };
9
20
  org_id?: string | null;
10
21
  created_at: string;
11
22
  }
@@ -84,6 +95,19 @@ export declare function getDnsRecord(apiKey: string, orgId: string, domain: stri
84
95
  export declare function createDnsRecord(apiKey: string, orgId: string, domain: string, input: DnsRecordInput): Promise<DnsRecord>;
85
96
  export declare function updateDnsRecord(apiKey: string, orgId: string, domain: string, recordId: string, input: Partial<Omit<DnsRecordInput, 'type'>>): Promise<DnsRecord>;
86
97
  export declare function deleteDnsRecord(apiKey: string, orgId: string, domain: string, recordId: string): Promise<void>;
98
+ export interface EmailInfraResponse {
99
+ domain: string;
100
+ email_infra: 'pending' | 'ready' | 'error';
101
+ email_subdomain: string;
102
+ next_step?: string;
103
+ }
104
+ export declare function setupEmailInfra(apiKey: string, orgId: string, domain: string, subdomain?: string): Promise<EmailInfraResponse>;
105
+ export interface RetryProvisioningResponse {
106
+ domain: string;
107
+ email_infra?: string;
108
+ next_step?: string;
109
+ }
110
+ export declare function retryProvisioning(apiKey: string, orgId: string, domain: string): Promise<RetryProvisioningResponse>;
87
111
  export declare function updateDomainSettings(apiKey: string, orgId: string, domain: string, payload: {
88
112
  security_level?: 'essentially_off' | 'medium' | 'high' | 'under_attack';
89
113
  browser_check?: 'on' | 'off';
package/dist/domain.js CHANGED
@@ -15,6 +15,8 @@ exports.getDnsRecord = getDnsRecord;
15
15
  exports.createDnsRecord = createDnsRecord;
16
16
  exports.updateDnsRecord = updateDnsRecord;
17
17
  exports.deleteDnsRecord = deleteDnsRecord;
18
+ exports.setupEmailInfra = setupEmailInfra;
19
+ exports.retryProvisioning = retryProvisioning;
18
20
  exports.updateDomainSettings = updateDomainSettings;
19
21
  const client_1 = require("./client");
20
22
  const config_1 = require("./config");
@@ -33,6 +35,8 @@ exports.EXPOSES = [
33
35
  'POST /domain/orgs/{org_id}/{domain}/records',
34
36
  'PATCH /domain/orgs/{org_id}/{domain}/records/{record_id}',
35
37
  'DELETE /domain/orgs/{org_id}/{domain}/records/{record_id}',
38
+ 'POST /domain/orgs/{org_id}/{domain}/email-infra',
39
+ 'POST /domain/orgs/{org_id}/{domain}/retry-provisioning',
36
40
  ];
37
41
  async function checkDomain(apiKey, orgId, domain) {
38
42
  return (0, client_1.request)('GET', `${config_1.DOMAIN_BASE}/domain/orgs/${encodeURIComponent(orgId)}/check/available/${encodeURIComponent(domain)}`, apiKey);
@@ -82,6 +86,13 @@ async function updateDnsRecord(apiKey, orgId, domain, recordId, input) {
82
86
  async function deleteDnsRecord(apiKey, orgId, domain, recordId) {
83
87
  return (0, client_1.request)('DELETE', `${config_1.DOMAIN_BASE}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/records/${encodeURIComponent(recordId)}`, apiKey);
84
88
  }
89
+ async function setupEmailInfra(apiKey, orgId, domain, subdomain) {
90
+ const body = subdomain ? { subdomain } : {};
91
+ return (0, client_1.request)('POST', `${config_1.DOMAIN_BASE}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/email-infra`, apiKey, body);
92
+ }
93
+ async function retryProvisioning(apiKey, orgId, domain) {
94
+ return (0, client_1.request)('POST', `${config_1.DOMAIN_BASE}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/retry-provisioning`, apiKey);
95
+ }
85
96
  async function updateDomainSettings(apiKey, orgId, domain, payload) {
86
97
  return (0, client_1.request)('POST', `${config_1.DOMAIN_BASE}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/settings`, apiKey, payload);
87
98
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@myapihq/sdk",
3
3
  "license": "Apache-2.0",
4
- "version": "1.2.2",
4
+ "version": "1.2.4",
5
5
  "description": "TypeScript SDK for the MyAPI ecosystem",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
package/src/client.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import { ApiResponse } from './types';
2
2
 
3
3
  export class MyApiError extends Error {
4
- constructor(public code: string, public status: number, public detail?: string) {
4
+ // `body` is the full error object as returned by the backend — preserved so
5
+ // callers can read service-specific fields the SDK doesn't otherwise model
6
+ // (e.g. CF_API_ERROR carries `cf_message` / `cf_status`).
7
+ constructor(public code: string, public status: number, public detail?: string, public body?: Record<string, unknown>) {
5
8
  // Surface the detail in the message so console.error / err.message
6
9
  // shows useful info without callers having to look at err.detail.
7
10
  super(detail ? `${code} (${status}): ${detail}` : code);
@@ -69,7 +72,8 @@ export async function request<T>(
69
72
  const err = result?.error;
70
73
  const code = typeof err === 'object' ? (err?.code || 'unknown_error') : (err || 'unknown_error');
71
74
  const detail = typeof err === 'object' ? (err?.message || undefined) : undefined;
72
- throw new MyApiError(code, response.status, detail);
75
+ const body = typeof err === 'object' ? err : undefined;
76
+ throw new MyApiError(code, response.status, detail, body);
73
77
  }
74
78
 
75
79
  const apiResponse = result as ApiResponse<T>;
@@ -77,7 +81,8 @@ export async function request<T>(
77
81
  const err = apiResponse.error as any;
78
82
  const code = typeof err === 'object' ? (err?.code || 'unknown_error') : (err || 'unknown_error');
79
83
  const detail = typeof err === 'object' ? (err?.message || undefined) : undefined;
80
- throw new MyApiError(code, response.status, detail);
84
+ const body = typeof err === 'object' ? err : undefined;
85
+ throw new MyApiError(code, response.status, detail, body);
81
86
  }
82
87
 
83
88
  return apiResponse.data as T;
package/src/domain.ts CHANGED
@@ -17,6 +17,8 @@ export const EXPOSES: Exposes = [
17
17
  'POST /domain/orgs/{org_id}/{domain}/records',
18
18
  'PATCH /domain/orgs/{org_id}/{domain}/records/{record_id}',
19
19
  'DELETE /domain/orgs/{org_id}/{domain}/records/{record_id}',
20
+ 'POST /domain/orgs/{org_id}/{domain}/email-infra',
21
+ 'POST /domain/orgs/{org_id}/{domain}/retry-provisioning',
20
22
  ];
21
23
 
22
24
 
@@ -27,6 +29,19 @@ export interface DomainRecord {
27
29
  expires_at?: string;
28
30
  days_until_expiry?: number;
29
31
  email_infra_ready?: boolean;
32
+ // New status surface (post-2026-05-14 backend). Email infra is opt-in and
33
+ // always lives on a subdomain — apex is never touched.
34
+ email_infra?: 'skipped' | 'pending' | 'ready' | 'error';
35
+ email_subdomain?: string; // Only set when email_infra ∈ {pending, ready, error}.
36
+ dns_active?: boolean;
37
+ steps_completed?: string[];
38
+ error_detail?: {
39
+ failed_step: string;
40
+ message: string;
41
+ retryable: boolean;
42
+ attempt_count?: number;
43
+ last_attempt_at?: string;
44
+ };
30
45
  org_id?: string | null;
31
46
  created_at: string;
32
47
  }
@@ -172,6 +187,34 @@ export async function deleteDnsRecord(apiKey: string, orgId: string, domain: str
172
187
  return request('DELETE', `${BASE_URL}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/records/${encodeURIComponent(recordId)}`, apiKey);
173
188
  }
174
189
 
190
+ // Opt in to MyAPI-managed email on a subdomain. Apex is never touched; the
191
+ // backend provisions an SES identity on <subdomain>.<domain> and writes
192
+ // DKIM/SPF/DMARC records there. Default subdomain is `mail`.
193
+ export interface EmailInfraResponse {
194
+ domain: string;
195
+ email_infra: 'pending' | 'ready' | 'error';
196
+ email_subdomain: string;
197
+ next_step?: string;
198
+ }
199
+
200
+ export async function setupEmailInfra(apiKey: string, orgId: string, domain: string, subdomain?: string): Promise<EmailInfraResponse> {
201
+ const body = subdomain ? { subdomain } : {};
202
+ return request('POST', `${BASE_URL}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/email-infra`, apiKey, body);
203
+ }
204
+
205
+ // Re-run provisioning from the failed step when status=infra_error and the
206
+ // error is retryable. Returns a transient `{ email_infra: 'pending', next_step }`
207
+ // shape; caller polls `getDomainStatus` until status flips off `infra_error`.
208
+ export interface RetryProvisioningResponse {
209
+ domain: string;
210
+ email_infra?: string;
211
+ next_step?: string;
212
+ }
213
+
214
+ export async function retryProvisioning(apiKey: string, orgId: string, domain: string): Promise<RetryProvisioningResponse> {
215
+ return request('POST', `${BASE_URL}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/retry-provisioning`, apiKey);
216
+ }
217
+
175
218
  export async function updateDomainSettings(apiKey: string, orgId: string, domain: string, payload: {
176
219
  security_level?: 'essentially_off' | 'medium' | 'high' | 'under_attack';
177
220
  browser_check?: 'on' | 'off';