@myapihq/sdk 1.2.1 → 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 +2 -1
- package/dist/client.js +10 -3
- package/dist/domain.d.ts +49 -0
- package/dist/domain.js +37 -0
- package/package.json +1 -1
- package/src/client.ts +8 -3
- package/src/domain.ts +98 -0
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -59,6 +70,44 @@ export declare function getDomainStatus(apiKey: string, orgId: string, domain: s
|
|
|
59
70
|
export declare function assignDomain(apiKey: string, orgId: string, domain: string): Promise<DomainRecord>;
|
|
60
71
|
export declare function unassignDomain(apiKey: string, orgId: string, domain: string): Promise<DomainRecord>;
|
|
61
72
|
export declare function getDomainSettings(apiKey: string, orgId: string, domain: string): Promise<DomainSettings>;
|
|
73
|
+
export type DnsRecordType = 'A' | 'AAAA' | 'CNAME' | 'MX' | 'TXT';
|
|
74
|
+
export interface DnsRecord {
|
|
75
|
+
id: string;
|
|
76
|
+
type: DnsRecordType;
|
|
77
|
+
name: string;
|
|
78
|
+
content: string;
|
|
79
|
+
ttl: number;
|
|
80
|
+
priority: number | null;
|
|
81
|
+
proxied: boolean | null;
|
|
82
|
+
created_on: string;
|
|
83
|
+
modified_on: string;
|
|
84
|
+
}
|
|
85
|
+
export interface DnsRecordInput {
|
|
86
|
+
type: DnsRecordType;
|
|
87
|
+
name: string;
|
|
88
|
+
content: string;
|
|
89
|
+
ttl?: number;
|
|
90
|
+
priority?: number;
|
|
91
|
+
proxied?: boolean;
|
|
92
|
+
}
|
|
93
|
+
export declare function listDnsRecords(apiKey: string, orgId: string, domain: string, type?: DnsRecordType): Promise<DnsRecord[]>;
|
|
94
|
+
export declare function getDnsRecord(apiKey: string, orgId: string, domain: string, recordId: string): Promise<DnsRecord>;
|
|
95
|
+
export declare function createDnsRecord(apiKey: string, orgId: string, domain: string, input: DnsRecordInput): Promise<DnsRecord>;
|
|
96
|
+
export declare function updateDnsRecord(apiKey: string, orgId: string, domain: string, recordId: string, input: Partial<Omit<DnsRecordInput, 'type'>>): Promise<DnsRecord>;
|
|
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>;
|
|
62
111
|
export declare function updateDomainSettings(apiKey: string, orgId: string, domain: string, payload: {
|
|
63
112
|
security_level?: 'essentially_off' | 'medium' | 'high' | 'under_attack';
|
|
64
113
|
browser_check?: 'on' | 'off';
|
package/dist/domain.js
CHANGED
|
@@ -10,6 +10,13 @@ exports.getDomainStatus = getDomainStatus;
|
|
|
10
10
|
exports.assignDomain = assignDomain;
|
|
11
11
|
exports.unassignDomain = unassignDomain;
|
|
12
12
|
exports.getDomainSettings = getDomainSettings;
|
|
13
|
+
exports.listDnsRecords = listDnsRecords;
|
|
14
|
+
exports.getDnsRecord = getDnsRecord;
|
|
15
|
+
exports.createDnsRecord = createDnsRecord;
|
|
16
|
+
exports.updateDnsRecord = updateDnsRecord;
|
|
17
|
+
exports.deleteDnsRecord = deleteDnsRecord;
|
|
18
|
+
exports.setupEmailInfra = setupEmailInfra;
|
|
19
|
+
exports.retryProvisioning = retryProvisioning;
|
|
13
20
|
exports.updateDomainSettings = updateDomainSettings;
|
|
14
21
|
const client_1 = require("./client");
|
|
15
22
|
const config_1 = require("./config");
|
|
@@ -23,6 +30,13 @@ exports.EXPOSES = [
|
|
|
23
30
|
'GET /domain/orgs/{org_id}/{domain}/settings',
|
|
24
31
|
'POST /domain/orgs/{org_id}/{domain}/settings',
|
|
25
32
|
'GET /domain/orgs/{org_id}/{domain}/status',
|
|
33
|
+
'GET /domain/orgs/{org_id}/{domain}/records',
|
|
34
|
+
'GET /domain/orgs/{org_id}/{domain}/records/{record_id}',
|
|
35
|
+
'POST /domain/orgs/{org_id}/{domain}/records',
|
|
36
|
+
'PATCH /domain/orgs/{org_id}/{domain}/records/{record_id}',
|
|
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',
|
|
26
40
|
];
|
|
27
41
|
async function checkDomain(apiKey, orgId, domain) {
|
|
28
42
|
return (0, client_1.request)('GET', `${config_1.DOMAIN_BASE}/domain/orgs/${encodeURIComponent(orgId)}/check/available/${encodeURIComponent(domain)}`, apiKey);
|
|
@@ -56,6 +70,29 @@ async function unassignDomain(apiKey, orgId, domain) {
|
|
|
56
70
|
async function getDomainSettings(apiKey, orgId, domain) {
|
|
57
71
|
return (0, client_1.request)('GET', `${config_1.DOMAIN_BASE}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/settings`, apiKey);
|
|
58
72
|
}
|
|
73
|
+
async function listDnsRecords(apiKey, orgId, domain, type) {
|
|
74
|
+
const query = type ? `?type=${encodeURIComponent(type)}` : '';
|
|
75
|
+
return (0, client_1.request)('GET', `${config_1.DOMAIN_BASE}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/records${query}`, apiKey);
|
|
76
|
+
}
|
|
77
|
+
async function getDnsRecord(apiKey, orgId, domain, recordId) {
|
|
78
|
+
return (0, client_1.request)('GET', `${config_1.DOMAIN_BASE}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/records/${encodeURIComponent(recordId)}`, apiKey);
|
|
79
|
+
}
|
|
80
|
+
async function createDnsRecord(apiKey, orgId, domain, input) {
|
|
81
|
+
return (0, client_1.request)('POST', `${config_1.DOMAIN_BASE}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/records`, apiKey, input);
|
|
82
|
+
}
|
|
83
|
+
async function updateDnsRecord(apiKey, orgId, domain, recordId, input) {
|
|
84
|
+
return (0, client_1.request)('PATCH', `${config_1.DOMAIN_BASE}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/records/${encodeURIComponent(recordId)}`, apiKey, input);
|
|
85
|
+
}
|
|
86
|
+
async function deleteDnsRecord(apiKey, orgId, domain, recordId) {
|
|
87
|
+
return (0, client_1.request)('DELETE', `${config_1.DOMAIN_BASE}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/records/${encodeURIComponent(recordId)}`, apiKey);
|
|
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
|
+
}
|
|
59
96
|
async function updateDomainSettings(apiKey, orgId, domain, payload) {
|
|
60
97
|
return (0, client_1.request)('POST', `${config_1.DOMAIN_BASE}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/settings`, apiKey, payload);
|
|
61
98
|
}
|
package/package.json
CHANGED
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
@@ -12,6 +12,13 @@ export const EXPOSES: Exposes = [
|
|
|
12
12
|
'GET /domain/orgs/{org_id}/{domain}/settings',
|
|
13
13
|
'POST /domain/orgs/{org_id}/{domain}/settings',
|
|
14
14
|
'GET /domain/orgs/{org_id}/{domain}/status',
|
|
15
|
+
'GET /domain/orgs/{org_id}/{domain}/records',
|
|
16
|
+
'GET /domain/orgs/{org_id}/{domain}/records/{record_id}',
|
|
17
|
+
'POST /domain/orgs/{org_id}/{domain}/records',
|
|
18
|
+
'PATCH /domain/orgs/{org_id}/{domain}/records/{record_id}',
|
|
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',
|
|
15
22
|
];
|
|
16
23
|
|
|
17
24
|
|
|
@@ -22,6 +29,19 @@ export interface DomainRecord {
|
|
|
22
29
|
expires_at?: string;
|
|
23
30
|
days_until_expiry?: number;
|
|
24
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
|
+
};
|
|
25
45
|
org_id?: string | null;
|
|
26
46
|
created_at: string;
|
|
27
47
|
}
|
|
@@ -117,6 +137,84 @@ export async function getDomainSettings(apiKey: string, orgId: string, domain: s
|
|
|
117
137
|
return request('GET', `${BASE_URL}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/settings`, apiKey);
|
|
118
138
|
}
|
|
119
139
|
|
|
140
|
+
// ── DNS records ──────────────────────────────────────────────────────────────
|
|
141
|
+
// Per-zone CRUD on the Cloudflare zone the backend manages for this domain.
|
|
142
|
+
// v1 supports A / AAAA / CNAME / MX / TXT. `priority` is non-null only for MX,
|
|
143
|
+
// `proxied` is non-null only for A/AAAA/CNAME. `ttl: 1` is CF's "automatic"
|
|
144
|
+
// sentinel.
|
|
145
|
+
|
|
146
|
+
export type DnsRecordType = 'A' | 'AAAA' | 'CNAME' | 'MX' | 'TXT';
|
|
147
|
+
|
|
148
|
+
export interface DnsRecord {
|
|
149
|
+
id: string;
|
|
150
|
+
type: DnsRecordType;
|
|
151
|
+
name: string; // FQDN as stored by CF
|
|
152
|
+
content: string;
|
|
153
|
+
ttl: number;
|
|
154
|
+
priority: number | null;
|
|
155
|
+
proxied: boolean | null;
|
|
156
|
+
created_on: string;
|
|
157
|
+
modified_on: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface DnsRecordInput {
|
|
161
|
+
type: DnsRecordType;
|
|
162
|
+
name: string; // Accepts FQDN, host-only, or apex tokens (`@`, `""`).
|
|
163
|
+
content: string;
|
|
164
|
+
ttl?: number; // Default 1 (CF auto). Range [60, 86400] otherwise.
|
|
165
|
+
priority?: number; // Required for MX.
|
|
166
|
+
proxied?: boolean; // A/AAAA/CNAME only. Defaults false.
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export async function listDnsRecords(apiKey: string, orgId: string, domain: string, type?: DnsRecordType): Promise<DnsRecord[]> {
|
|
170
|
+
const query = type ? `?type=${encodeURIComponent(type)}` : '';
|
|
171
|
+
return request('GET', `${BASE_URL}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/records${query}`, apiKey);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export async function getDnsRecord(apiKey: string, orgId: string, domain: string, recordId: string): Promise<DnsRecord> {
|
|
175
|
+
return request('GET', `${BASE_URL}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/records/${encodeURIComponent(recordId)}`, apiKey);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export async function createDnsRecord(apiKey: string, orgId: string, domain: string, input: DnsRecordInput): Promise<DnsRecord> {
|
|
179
|
+
return request('POST', `${BASE_URL}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/records`, apiKey, input);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export async function updateDnsRecord(apiKey: string, orgId: string, domain: string, recordId: string, input: Partial<Omit<DnsRecordInput, 'type'>>): Promise<DnsRecord> {
|
|
183
|
+
return request('PATCH', `${BASE_URL}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/records/${encodeURIComponent(recordId)}`, apiKey, input);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export async function deleteDnsRecord(apiKey: string, orgId: string, domain: string, recordId: string): Promise<void> {
|
|
187
|
+
return request('DELETE', `${BASE_URL}/domain/orgs/${encodeURIComponent(orgId)}/${encodeURIComponent(domain)}/records/${encodeURIComponent(recordId)}`, apiKey);
|
|
188
|
+
}
|
|
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
|
+
|
|
120
218
|
export async function updateDomainSettings(apiKey: string, orgId: string, domain: string, payload: {
|
|
121
219
|
security_level?: 'essentially_off' | 'medium' | 'high' | 'under_attack';
|
|
122
220
|
browser_check?: 'on' | 'off';
|