feat: expose domain dns records via api (#259)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "usesend"
|
||||
version = "0.2.3"
|
||||
version = "0.2.4"
|
||||
description = "Python SDK for the UseSend API"
|
||||
authors = ["UseSend"]
|
||||
license = "MIT"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Python client for the UseSend API."""
|
||||
|
||||
from .usesend import UseSend, UseSendHTTPError
|
||||
from .domains import Domains # type: ignore
|
||||
from . import types
|
||||
|
||||
__all__ = ["UseSend", "UseSendHTTPError", "types"]
|
||||
__all__ = ["UseSend", "UseSendHTTPError", "types", "Domains"]
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
"""Domain resource client using TypedDict shapes (no Pydantic)."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional, Tuple, List
|
||||
|
||||
from .types import (
|
||||
APIError,
|
||||
Domain,
|
||||
DomainCreate,
|
||||
DomainCreateResponse,
|
||||
DomainVerifyResponse,
|
||||
)
|
||||
|
||||
|
||||
class Domains:
|
||||
"""Client for `/domains` endpoints."""
|
||||
|
||||
def __init__(self, usesend: "UseSend") -> None:
|
||||
self.usesend = usesend
|
||||
|
||||
def list(self) -> Tuple[Optional[List[Domain]], Optional[APIError]]:
|
||||
data, err = self.usesend.get("/domains")
|
||||
return (data, err) # type: ignore[return-value]
|
||||
|
||||
def create(self, payload: DomainCreate) -> Tuple[Optional[DomainCreateResponse], Optional[APIError]]:
|
||||
data, err = self.usesend.post("/domains", payload)
|
||||
return (data, err) # type: ignore[return-value]
|
||||
|
||||
def verify(self, domain_id: int) -> Tuple[Optional[DomainVerifyResponse], Optional[APIError]]:
|
||||
data, err = self.usesend.put(f"/domains/{domain_id}/verify", {})
|
||||
return (data, err) # type: ignore[return-value]
|
||||
|
||||
def get(self, domain_id: int) -> Tuple[Optional[Domain], Optional[APIError]]:
|
||||
data, err = self.usesend.get(f"/domains/{domain_id}")
|
||||
return (data, err) # type: ignore[return-value]
|
||||
|
||||
from .usesend import UseSend # noqa: E402 pylint: disable=wrong-import-position
|
||||
@@ -22,6 +22,21 @@ DomainStatus = Literal[
|
||||
'TEMPORARY_FAILURE',
|
||||
]
|
||||
|
||||
DNSRecordType = Literal['MX', 'TXT']
|
||||
|
||||
|
||||
class DNSRecord(TypedDict, total=False):
|
||||
type: DNSRecordType
|
||||
name: str
|
||||
value: str
|
||||
ttl: str
|
||||
priority: Optional[str]
|
||||
status: DomainStatus
|
||||
recommended: Optional[bool]
|
||||
|
||||
|
||||
DNSRecords = List[DNSRecord]
|
||||
|
||||
|
||||
class Domain(TypedDict, total=False):
|
||||
id: float
|
||||
@@ -40,6 +55,9 @@ class Domain(TypedDict, total=False):
|
||||
isVerifying: bool
|
||||
errorMessage: Optional[str]
|
||||
subdomain: Optional[str]
|
||||
verificationError: Optional[str]
|
||||
lastCheckedTime: Optional[str]
|
||||
dnsRecords: DNSRecords
|
||||
|
||||
|
||||
DomainList = List[Domain]
|
||||
@@ -67,6 +85,9 @@ class DomainCreateResponse(TypedDict, total=False):
|
||||
isVerifying: bool
|
||||
errorMessage: Optional[str]
|
||||
subdomain: Optional[str]
|
||||
verificationError: Optional[str]
|
||||
lastCheckedTime: Optional[str]
|
||||
dnsRecords: DNSRecords
|
||||
|
||||
|
||||
class DomainVerifyResponse(TypedDict):
|
||||
|
||||
@@ -71,6 +71,7 @@ class UseSend:
|
||||
# Lazily initialise resource clients.
|
||||
self.emails = Emails(self)
|
||||
self.contacts = Contacts(self)
|
||||
self.domains = Domains(self)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Internal request helper
|
||||
@@ -123,3 +124,4 @@ class UseSend:
|
||||
# Import here to avoid circular dependency during type checking
|
||||
from .emails import Emails # noqa: E402 pylint: disable=wrong-import-position
|
||||
from .contacts import Contacts # noqa: E402 pylint: disable=wrong-import-position
|
||||
from .domains import Domains # type: ignore # noqa: E402
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "usesend-js",
|
||||
"version": "1.5.2",
|
||||
"version": "1.5.3",
|
||||
"description": "",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
|
||||
@@ -29,6 +29,14 @@ type VerifyDomainResponse = {
|
||||
type VerifyDomainResponseSuccess =
|
||||
paths["/v1/domains/{id}/verify"]["put"]["responses"]["200"]["content"]["application/json"];
|
||||
|
||||
type GetDomainResponse = {
|
||||
data: GetDomainResponseSuccess | null;
|
||||
error: ErrorResponse | null;
|
||||
};
|
||||
|
||||
type GetDomainResponseSuccess =
|
||||
paths["/v1/domains/{id}"]["get"]["responses"]["200"]["content"]["application/json"];
|
||||
|
||||
export class Domains {
|
||||
constructor(private readonly usesend: UseSend) {
|
||||
this.usesend = usesend;
|
||||
@@ -54,4 +62,12 @@ export class Domains {
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
async get(id: number): Promise<GetDomainResponse> {
|
||||
const data = await this.usesend.get<GetDomainResponseSuccess>(
|
||||
`/domains/${id}`
|
||||
);
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ export class Emails {
|
||||
const data = await this.usesend.get<GetEmailResponseSuccess>(
|
||||
`/emails/${id}`
|
||||
);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+245
-6
@@ -20,7 +20,7 @@ export interface paths {
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Retrieve the user */
|
||||
/** @description Retrieve domains accessible by the API key */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
@@ -61,6 +61,40 @@ export interface paths {
|
||||
isVerifying: boolean;
|
||||
errorMessage?: string | null;
|
||||
subdomain?: string | null;
|
||||
verificationError?: string | null;
|
||||
lastCheckedTime?: string | null;
|
||||
dnsRecords: {
|
||||
/**
|
||||
* @description DNS record type
|
||||
* @example TXT
|
||||
* @enum {string}
|
||||
*/
|
||||
type: "MX" | "TXT";
|
||||
/**
|
||||
* @description DNS record name
|
||||
* @example mail
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* @description DNS record value
|
||||
* @example v=spf1 include:amazonses.com ~all
|
||||
*/
|
||||
value: string;
|
||||
/**
|
||||
* @description DNS record TTL
|
||||
* @example Auto
|
||||
*/
|
||||
ttl: string;
|
||||
/**
|
||||
* @description DNS record priority
|
||||
* @example 10
|
||||
*/
|
||||
priority?: string | null;
|
||||
/** @enum {string} */
|
||||
status: "NOT_STARTED" | "PENDING" | "SUCCESS" | "FAILED" | "TEMPORARY_FAILURE";
|
||||
/** @description Whether the record is recommended */
|
||||
recommended?: boolean;
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
};
|
||||
@@ -124,6 +158,40 @@ export interface paths {
|
||||
isVerifying: boolean;
|
||||
errorMessage?: string | null;
|
||||
subdomain?: string | null;
|
||||
verificationError?: string | null;
|
||||
lastCheckedTime?: string | null;
|
||||
dnsRecords: {
|
||||
/**
|
||||
* @description DNS record type
|
||||
* @example TXT
|
||||
* @enum {string}
|
||||
*/
|
||||
type: "MX" | "TXT";
|
||||
/**
|
||||
* @description DNS record name
|
||||
* @example mail
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* @description DNS record value
|
||||
* @example v=spf1 include:amazonses.com ~all
|
||||
*/
|
||||
value: string;
|
||||
/**
|
||||
* @description DNS record TTL
|
||||
* @example Auto
|
||||
*/
|
||||
ttl: string;
|
||||
/**
|
||||
* @description DNS record priority
|
||||
* @example 10
|
||||
*/
|
||||
priority?: string | null;
|
||||
/** @enum {string} */
|
||||
status: "NOT_STARTED" | "PENDING" | "SUCCESS" | "FAILED" | "TEMPORARY_FAILURE";
|
||||
/** @description Whether the record is recommended */
|
||||
recommended?: boolean;
|
||||
}[];
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -154,7 +222,7 @@ export interface paths {
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Create a new domain */
|
||||
/** @description Verify domain */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
@@ -165,6 +233,28 @@ export interface paths {
|
||||
};
|
||||
};
|
||||
};
|
||||
/** @description Forbidden - API key doesn't have access to this domain */
|
||||
403: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": {
|
||||
error: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
/** @description Domain not found */
|
||||
404: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": {
|
||||
error: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
post?: never;
|
||||
@@ -174,6 +264,112 @@ export interface paths {
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/v1/domains/{id}": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
get: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: number | null;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Retrieve the domain */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": {
|
||||
/**
|
||||
* @description The ID of the domain
|
||||
* @example 1
|
||||
*/
|
||||
id: number;
|
||||
/**
|
||||
* @description The name of the domain
|
||||
* @example example.com
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* @description The ID of the team
|
||||
* @example 1
|
||||
*/
|
||||
teamId: number;
|
||||
/** @enum {string} */
|
||||
status: "NOT_STARTED" | "PENDING" | "SUCCESS" | "FAILED" | "TEMPORARY_FAILURE";
|
||||
/** @default us-east-1 */
|
||||
region: string;
|
||||
/** @default false */
|
||||
clickTracking: boolean;
|
||||
/** @default false */
|
||||
openTracking: boolean;
|
||||
publicKey: string;
|
||||
dkimStatus?: string | null;
|
||||
spfDetails?: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
/** @default false */
|
||||
dmarcAdded: boolean;
|
||||
/** @default false */
|
||||
isVerifying: boolean;
|
||||
errorMessage?: string | null;
|
||||
subdomain?: string | null;
|
||||
verificationError?: string | null;
|
||||
lastCheckedTime?: string | null;
|
||||
dnsRecords: {
|
||||
/**
|
||||
* @description DNS record type
|
||||
* @example TXT
|
||||
* @enum {string}
|
||||
*/
|
||||
type: "MX" | "TXT";
|
||||
/**
|
||||
* @description DNS record name
|
||||
* @example mail
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* @description DNS record value
|
||||
* @example v=spf1 include:amazonses.com ~all
|
||||
*/
|
||||
value: string;
|
||||
/**
|
||||
* @description DNS record TTL
|
||||
* @example Auto
|
||||
*/
|
||||
ttl: string;
|
||||
/**
|
||||
* @description DNS record priority
|
||||
* @example 10
|
||||
*/
|
||||
priority?: string | null;
|
||||
/** @enum {string} */
|
||||
status: "NOT_STARTED" | "PENDING" | "SUCCESS" | "FAILED" | "TEMPORARY_FAILURE";
|
||||
/** @description Whether the record is recommended */
|
||||
recommended?: boolean;
|
||||
}[];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/v1/emails/{emailId}": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
@@ -214,7 +410,7 @@ export interface paths {
|
||||
emailEvents: {
|
||||
emailId: string;
|
||||
/** @enum {string} */
|
||||
status: "SCHEDULED" | "QUEUED" | "SENT" | "DELIVERY_DELAYED" | "BOUNCED" | "REJECTED" | "RENDERING_FAILURE" | "DELIVERED" | "OPENED" | "CLICKED" | "COMPLAINED" | "FAILED" | "CANCELLED";
|
||||
status: "SCHEDULED" | "QUEUED" | "SENT" | "DELIVERY_DELAYED" | "BOUNCED" | "REJECTED" | "RENDERING_FAILURE" | "DELIVERED" | "OPENED" | "CLICKED" | "COMPLAINED" | "FAILED" | "CANCELLED" | "SUPPRESSED";
|
||||
createdAt: string;
|
||||
data?: unknown;
|
||||
}[];
|
||||
@@ -268,7 +464,52 @@ export interface paths {
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
get: {
|
||||
parameters: {
|
||||
query?: {
|
||||
page?: string;
|
||||
limit?: string;
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
domainId?: string | string[];
|
||||
};
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Retrieve a list of emails */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": {
|
||||
data: {
|
||||
id: string;
|
||||
to: string | string[];
|
||||
replyTo?: string | string[] | unknown;
|
||||
cc?: string | string[] | unknown;
|
||||
bcc?: string | string[] | unknown;
|
||||
from: string;
|
||||
subject: string;
|
||||
html: string | null;
|
||||
text: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
/** @enum {string|null} */
|
||||
latestStatus: "SCHEDULED" | "QUEUED" | "SENT" | "DELIVERY_DELAYED" | "BOUNCED" | "REJECTED" | "RENDERING_FAILURE" | "DELIVERED" | "OPENED" | "CLICKED" | "COMPLAINED" | "FAILED" | "CANCELLED" | "SUPPRESSED" | null;
|
||||
/** Format: date-time */
|
||||
scheduledAt: string | null;
|
||||
domainId: number | null;
|
||||
}[];
|
||||
count: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
put?: never;
|
||||
post: {
|
||||
parameters: {
|
||||
@@ -281,7 +522,6 @@ export interface paths {
|
||||
content: {
|
||||
"application/json": {
|
||||
to: string | string[];
|
||||
/** Format: email */
|
||||
from: string;
|
||||
/** @description Optional when templateId is provided */
|
||||
subject?: string;
|
||||
@@ -345,7 +585,6 @@ export interface paths {
|
||||
content: {
|
||||
"application/json": {
|
||||
to: string | string[];
|
||||
/** Format: email */
|
||||
from: string;
|
||||
/** @description Optional when templateId is provided */
|
||||
subject?: string;
|
||||
|
||||
Reference in New Issue
Block a user