From b60c133f0197f76b17c4dff2356cebb40715c42e Mon Sep 17 00:00:00 2001 From: Bu Kinoshita <6929565+bukinoshita@users.noreply.github.com> Date: Fri, 9 Feb 2024 22:41:14 -0300 Subject: [PATCH] feat: Add patch domain (#320) --- src/domains/domains.spec.ts | 38 ++++++++++++++++++- src/domains/domains.ts | 16 ++++++++ .../interfaces/patch-domain.interface.ts | 17 +++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/domains/interfaces/patch-domain.interface.ts diff --git a/src/domains/domains.spec.ts b/src/domains/domains.spec.ts index ed0e169e..c850a4f0 100644 --- a/src/domains/domains.spec.ts +++ b/src/domains/domains.spec.ts @@ -9,6 +9,7 @@ import { } from './interfaces/create-domain-options.interface'; import { ListDomainsResponseSuccess } from './interfaces/list-domains.interface'; import { RemoveDomainsResponseSuccess } from './interfaces/remove-domain.interface'; +import { PatchDomainsResponseSuccess } from './interfaces/patch-domain.interface'; enableFetchMocks(); @@ -498,6 +499,41 @@ describe('Domains', () => { }); }); + describe('patch', () => { + it('patch domain click tracking', async () => { + const id = '5262504e-8ed7-4fac-bd16-0d4be94bc9f2'; + const response: PatchDomainsResponseSuccess = { + object: 'domain', + id, + }; + + fetchMock.mockOnce(JSON.stringify(response), { + status: 200, + headers: { + 'content-type': 'application/json', + Authorization: 'Bearer re_924b3rjh2387fbewf823', + }, + }); + + const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop'); + + await expect( + resend.domains.patch({ + id, + click_tracking: true, + }), + ).resolves.toMatchInlineSnapshot(` +{ + "data": { + "id": "5262504e-8ed7-4fac-bd16-0d4be94bc9f2", + "object": "domain", + }, + "error": null, +} +`); + }); + }); + describe('verify', () => { it('verifies a domain', async () => { fetchMock.mockOnce(JSON.stringify({}), { @@ -525,7 +561,7 @@ describe('Domains', () => { it('removes a domain', async () => { const id = '5262504e-8ed7-4fac-bd16-0d4be94bc9f2'; const response: RemoveDomainsResponseSuccess = { - id: id, + id, }; fetchMock.mockOnce(JSON.stringify(response), { status: 200, diff --git a/src/domains/domains.ts b/src/domains/domains.ts index c177a517..5a2ec031 100644 --- a/src/domains/domains.ts +++ b/src/domains/domains.ts @@ -13,6 +13,11 @@ import { ListDomainsResponse, ListDomainsResponseSuccess, } from './interfaces/list-domains.interface'; +import { + PatchDomainsOptions, + PatchDomainsResponse, + PatchDomainsResponseSuccess, +} from './interfaces/patch-domain.interface'; import { RemoveDomainsResponse, RemoveDomainsResponseSuccess, @@ -49,6 +54,17 @@ export class Domains { return data; } + async patch(payload: PatchDomainsOptions): Promise { + const data = await this.resend.patch( + `/domains/${payload.id}`, + { + click_tracking: payload.click_tracking, + open_tracking: payload.open_tracking, + }, + ); + return data; + } + async remove(id: string): Promise { const data = await this.resend.delete( `/domains/${id}`, diff --git a/src/domains/interfaces/patch-domain.interface.ts b/src/domains/interfaces/patch-domain.interface.ts new file mode 100644 index 00000000..3f9b2c72 --- /dev/null +++ b/src/domains/interfaces/patch-domain.interface.ts @@ -0,0 +1,17 @@ +import { ErrorResponse } from '../../interfaces'; +import { Domain } from './domain'; + +export interface PatchDomainsOptions { + id: string; + click_tracking?: boolean; + open_tracking?: boolean; +} + +export type PatchDomainsResponseSuccess = Pick & { + object: 'domain'; +}; + +export interface PatchDomainsResponse { + data: PatchDomainsResponseSuccess | null; + error: ErrorResponse | null; +}