Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/domains/domains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Resend } from '../resend';
import {
CreateDomainOptions,
CreateDomainRequestOptions,
CreateDomainResponse,
} from './interfaces';

export class Domains {
constructor(private readonly resend: Resend) {}

async create(
payload: CreateDomainOptions,
options: CreateDomainRequestOptions = {},
): Promise<CreateDomainResponse> {
const { data } = await this.resend.post('/domains', payload, options);
return data;
}

async remove(id: string) {
await this.resend.delete(`/domains/${id}`);
}

async verify(id: string) {
await this.resend.post(`/domains/${id}/verify`);
}
}
61 changes: 61 additions & 0 deletions src/domains/interfaces/create-domain-options.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { PostOptions } from '../../common/interfaces';

export type DomainRegion = 'us-east-1' | 'eu-west-1' | 'sa-east-1';

export interface CreateDomainOptions {
domain: string;
region?: DomainRegion;
}

export interface CreateDomainRequestOptions extends PostOptions {}

export type DomainNameservers =
| 'Amazon Route 53'
| 'Cloudflare'
| 'Digital Ocean'
| 'GoDaddy'
| 'Google Domains'
| 'Namecheap'
| 'Unidentified'
| 'Vercel';

export type DomainStatus =
| 'pending'
| 'verified'
| 'failed'
| 'temporary_failure'
| 'not_started';

export interface DomainSpfRecord {
record: 'SPF';
name: string;
value: string;
type: 'MX' | 'TXT';
ttl: string;
status: DomainStatus;
routingPolicy?: string;
priority?: number;
proxStatus?: 'enable' | 'disable';
}

export interface DomainDkimRecord {
record: 'DKIM';
name: string;
value: string;
type: 'CNAME';
ttl: string;
status: DomainStatus;
routingPolicy?: string;
priority?: number;
proxStatus?: 'enable' | 'disable';
}

export type CreateDomainResponse = {
name: string;
id: string;
dnsProvider: DomainNameservers;
status: DomainStatus;
createdAt: string;
records: (DomainSpfRecord | DomainDkimRecord)[];
region: DomainRegion;
};
1 change: 1 addition & 0 deletions src/domains/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './create-domain-options.interface';
2 changes: 2 additions & 0 deletions src/resend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import {
import { version } from '../package.json';
import { GetOptions, PostOptions, PutOptions } from './common/interfaces';
import { ApiKeys } from './api-keys/api-keys';
import { Domains } from './domains/domains';

export class Resend {
readonly baseUrl: string;
private readonly headers: HeadersInit;
private readonly request: AxiosInstance;

readonly apiKeys = new ApiKeys(this);
readonly domains = new Domains(this);

constructor(readonly key?: string) {
if (!key) {
Expand Down