delete-domain route added (#267)

This commit is contained in:
Kuntal Majee
2025-10-11 00:26:45 +05:30
committed by GitHub
parent 3388426929
commit 3f6a02ac56
8 changed files with 408 additions and 7 deletions
+4
View File
@@ -34,4 +34,8 @@ class Domains:
data, err = self.usesend.get(f"/domains/{domain_id}")
return (data, err) # type: ignore[return-value]
def delete(self, domain_id: int) -> Tuple[Optional[Domain], Optional[APIError]]:
data, err = self.usesend.delete(f"/domains/{domain_id}")
return (data, err) # type: ignore[return-value]
from .usesend import UseSend # noqa: E402 pylint: disable=wrong-import-position
+19 -3
View File
@@ -37,6 +37,14 @@ type GetDomainResponse = {
type GetDomainResponseSuccess =
paths["/v1/domains/{id}"]["get"]["responses"]["200"]["content"]["application/json"];
type DeleteDomainResponse = {
data: DeleteDomainResponseSuccess | null;
error: ErrorResponse | null;
};
type DeleteDomainResponseSuccess =
paths["/v1/domains/{id}"]["delete"]["responses"]["200"]["content"]["application/json"];
export class Domains {
constructor(private readonly usesend: UseSend) {
this.usesend = usesend;
@@ -50,7 +58,7 @@ export class Domains {
async create(payload: CreateDomainPayload): Promise<CreateDomainResponse> {
const data = await this.usesend.post<CreateDomainResponseSuccess>(
"/domains",
payload
payload,
);
return data;
}
@@ -58,14 +66,22 @@ export class Domains {
async verify(id: number): Promise<VerifyDomainResponse> {
const data = await this.usesend.put<VerifyDomainResponseSuccess>(
`/domains/${id}/verify`,
{}
{},
);
return data;
}
async get(id: number): Promise<GetDomainResponse> {
const data = await this.usesend.get<GetDomainResponseSuccess>(
`/domains/${id}`
`/domains/${id}`,
);
return data;
}
async delete(id: number): Promise<DeleteDomainResponse> {
const data = await this.usesend.delete<DeleteDomainResponseSuccess>(
`/domains/${id}`,
);
return data;
+5 -3
View File
@@ -1,6 +1,7 @@
import { ErrorResponse } from "../types";
import { Contacts } from "./contact";
import { Emails } from "./email";
import { Domains } from "./domain";
const defaultBaseUrl = "https://app.usesend.com";
// eslint-disable-next-line turbo/no-undeclared-env-vars
@@ -15,12 +16,13 @@ export class UseSend {
// readonly domains = new Domains(this);
readonly emails = new Emails(this);
readonly domains = new Domains(this);
readonly contacts = new Contacts(this);
url = baseUrl;
constructor(
readonly key?: string,
url?: string
url?: string,
) {
if (!key) {
if (typeof process !== "undefined" && process.env) {
@@ -29,7 +31,7 @@ export class UseSend {
if (!this.key) {
throw new Error(
'Missing API key. Pass it to the constructor `new UseSend("us_123")`'
'Missing API key. Pass it to the constructor `new UseSend("us_123")`',
);
}
}
@@ -46,7 +48,7 @@ export class UseSend {
async fetchRequest<T>(
path: string,
options = {}
options = {},
): Promise<{ data: T | null; error: ErrorResponse | null }> {
const response = await fetch(`${this.url}${path}`, options);
const defaultError = {
+113 -1
View File
@@ -364,7 +364,119 @@ export interface paths {
};
put?: never;
post?: never;
delete?: never;
delete: {
parameters: {
query?: never;
header?: never;
path: {
id: number;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description Domain deleted successfully */
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;
}[];
};
};
};
/** @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;
};
};
};
};
};
options?: never;
head?: never;
patch?: never;