Skip to content

Commit

Permalink
feat: Add get domain (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
bukinoshita authored Jun 26, 2023
1 parent a9dfb4b commit 1ac7b16
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 0 deletions.
105 changes: 105 additions & 0 deletions src/domains/domains.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from 'axios';
import MockAdapater from 'axios-mock-adapter';
import { Resend } from '../resend';
import { DomainRegion } from './interfaces/domain';
import { GetDomainResponse } from './interfaces';

const mock = new MockAdapater(axios);

Expand Down Expand Up @@ -324,6 +325,110 @@ describe('Domains', () => {
});
});

describe('get', () => {
describe('when domain not found', () => {
it('returns error', async () => {
mock.onGet('/domains/1234').replyOnce(200, {
name: 'not_found',
message: 'Domain not found',
statusCode: 404,
});

const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');

await expect(resend.domains.get('1234')).resolves
.toMatchInlineSnapshot(`
{
"message": "Domain not found",
"name": "not_found",
"statusCode": 404,
}
`);
});
});

it('get domain', async () => {
const domain: GetDomainResponse = {
object: 'domain',
id: 'fd61172c-cafc-40f5-b049-b45947779a29',
name: 'resend.com',
status: 'not_started',
created_at: '2023-06-21T06:10:36.144Z',
region: 'us-east-1',
records: [
{
record: 'SPF',
name: 'bounces.resend.com',
type: 'MX',
ttl: 'Auto',
status: 'not_started',
value: 'feedback-smtp.us-east-1.amazonses.com',
priority: 10,
},
{
record: 'SPF',
name: 'bounces.resend.com',
value: '"v=spf1 include:amazonses.com ~all"',
type: 'TXT',
ttl: 'Auto',
status: 'not_started',
},
{
record: 'DKIM',
name: 'resend._domainkey',
value:
'p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDZDhdsAKs5xdSj7h3v22wjx3WMWWADCHwxfef8U03JUbVM/sNSVuY5mbrdJKUoG6QBdfxsOGzhINmQnT89idjp5GdAUhx/KNpt8hcLXMID4nB0Gbcafn03/z5zEPxPfzVJqQd/UqOtZQcfxN9OrIhLiBsYTbcTBB7EvjCb3wEaBwIDAQAB',
type: 'TXT',
status: 'verified',
ttl: 'Auto',
},
],
};

mock.onGet('/domains/1234').replyOnce(200, domain);

const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');

await expect(resend.domains.get('1234')).resolves.toMatchInlineSnapshot(`
{
"created_at": "2023-06-21T06:10:36.144Z",
"id": "fd61172c-cafc-40f5-b049-b45947779a29",
"name": "resend.com",
"object": "domain",
"records": [
{
"name": "bounces.resend.com",
"priority": 10,
"record": "SPF",
"status": "not_started",
"ttl": "Auto",
"type": "MX",
"value": "feedback-smtp.us-east-1.amazonses.com",
},
{
"name": "bounces.resend.com",
"record": "SPF",
"status": "not_started",
"ttl": "Auto",
"type": "TXT",
"value": ""v=spf1 include:amazonses.com ~all"",
},
{
"name": "resend._domainkey",
"record": "DKIM",
"status": "verified",
"ttl": "Auto",
"type": "TXT",
"value": "p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDZDhdsAKs5xdSj7h3v22wjx3WMWWADCHwxfef8U03JUbVM/sNSVuY5mbrdJKUoG6QBdfxsOGzhINmQnT89idjp5GdAUhx/KNpt8hcLXMID4nB0Gbcafn03/z5zEPxPfzVJqQd/UqOtZQcfxN9OrIhLiBsYTbcTBB7EvjCb3wEaBwIDAQAB",
},
],
"region": "us-east-1",
"status": "not_started",
}
`);
});
});

describe('verify', () => {
it('verifies a domain', async () => {
mock
Expand Down
6 changes: 6 additions & 0 deletions src/domains/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CreateDomainOptions,
CreateDomainRequestOptions,
CreateDomainResponse,
GetDomainResponse,
ListDomainsResponse,
} from './interfaces';

Expand All @@ -27,6 +28,11 @@ export class Domains {
return data;
}

async get(id: string): Promise<GetDomainResponse> {
const data = await this.resend.get<GetDomainResponse>(`/domains/${id}`);
return data;
}

async remove(id: string) {
await this.resend.delete(`/domains/${id}`);
}
Expand Down
26 changes: 26 additions & 0 deletions src/domains/interfaces/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,29 @@ export type DomainStatus =
| 'failed'
| 'temporary_failure'
| 'not_started';

export type DomainRecords = DomainSpfRecord | DomainDkimRecord;

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

export interface DomainDkimRecord {
record: 'DKIM';
name: string;
value: string;
type: 'CNAME' | 'TXT';
ttl: string;
status: DomainStatus;
routing_policy?: string;
priority?: number;
proxy_status?: 'enable' | 'disable';
}
11 changes: 11 additions & 0 deletions src/domains/interfaces/get-domain.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { DomainRecords, DomainRegion, DomainStatus } from './domain';

export type GetDomainResponse = {
object: 'domain';
id: string;
name: string;
created_at: string;
region: DomainRegion;
status: DomainStatus;
records: DomainRecords[];
};
1 change: 1 addition & 0 deletions src/domains/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './create-domain-options.interface';
export * from './list-domains.interface';
export * from './get-domain.interface';

0 comments on commit 1ac7b16

Please sign in to comment.