Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Types #296

Merged
merged 2 commits into from
Jan 16, 2024
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
6 changes: 5 additions & 1 deletion src/api-keys/api-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import {
CreateApiKeyRequestOptions,
CreateApiKeyResponse,
CreateApiKeyResponseSuccess,
} from './interfaces/create-api-key-options.interface';
import {
ListApiKeysResponse,
ListApiKeysResponseSuccess,
} from './interfaces/list-api-keys.interface';
import {
RemoveApiKeyResponse,
RemoveApiKeyResponseSuccess,
} from './interfaces';
} from './interfaces/remove-api-keys.interface';

export class ApiKeys {
constructor(private readonly resend: Resend) {}
Expand Down
3 changes: 0 additions & 3 deletions src/api-keys/interfaces/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/audiences/audiences.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { enableFetchMocks } from 'jest-fetch-mock';
import { Resend } from '../resend';
import { GetAudienceResponseSuccess } from './interfaces';
import { ErrorResponse } from '../interfaces';
import { GetAudienceResponseSuccess } from './interfaces/get-audience.interface';

enableFetchMocks();

Expand Down
8 changes: 7 additions & 1 deletion src/audiences/audiences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import {
CreateAudienceRequestOptions,
CreateAudienceResponse,
CreateAudienceResponseSuccess,
} from './interfaces/create-audience-options.interface';
import {
GetAudienceResponse,
GetAudienceResponseSuccess,
} from './interfaces/get-audience.interface';
import {
ListAudiencesResponse,
ListAudiencesResponseSuccess,
} from './interfaces/list-audiences.interface';
import {
RemoveAudiencesResponse,
RemoveAudiencesResponseSuccess,
} from './interfaces';
} from './interfaces/remove-audience.interface';

export class Audiences {
constructor(private readonly resend: Resend) {}
Expand Down
4 changes: 0 additions & 4 deletions src/audiences/interfaces/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/batch/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
CreateBatchRequestOptions,
CreateBatchResponse,
CreateBatchSuccessResponse,
} from './interfaces';
} from './interfaces/create-batch-options.interface';

export class Batch {
constructor(private readonly resend: Resend) {}
Expand Down
1 change: 0 additions & 1 deletion src/batch/interfaces/index.ts

This file was deleted.

20 changes: 10 additions & 10 deletions src/contacts/contacts.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { enableFetchMocks } from 'jest-fetch-mock';
import { Resend } from '../resend';
import { GetContactResponseSuccess } from './interfaces';
import { ErrorResponse } from '../interfaces';
import { GetContactResponseSuccess } from './interfaces/get-contact.interface';

enableFetchMocks();

Expand Down Expand Up @@ -29,7 +29,7 @@ describe('Contacts', () => {
await expect(
resend.contacts.create({
email: '[email protected]',
audience_id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
audienceId: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
}),
).resolves.toMatchInlineSnapshot(`
{
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('Contacts', () => {

const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');

const result = resend.contacts.create({ email: '', audience_id: '' });
const result = resend.contacts.create({ email: '', audienceId: '' });

await expect(result).resolves.toMatchInlineSnapshot(`
{
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('Contacts', () => {

await expect(
resend.contacts.list({
audience_id: 'b6d24b8e-af0b-4c3c-be0c-359bbd97381a',
audienceId: 'b6d24b8e-af0b-4c3c-be0c-359bbd97381a',
}),
).resolves.toMatchInlineSnapshot(`
{
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('Contacts', () => {

const result = resend.contacts.get({
id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87223',
audience_id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
audienceId: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
});

await expect(result).resolves.toMatchInlineSnapshot(`
Expand Down Expand Up @@ -183,7 +183,7 @@ describe('Contacts', () => {
await expect(
resend.contacts.get({
id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87223',
audience_id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
audienceId: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
}),
).resolves.toMatchInlineSnapshot(`
{
Expand Down Expand Up @@ -219,8 +219,8 @@ describe('Contacts', () => {
await expect(
resend.contacts.update({
id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87223',
audience_id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
first_name: 'Bu',
audienceId: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
fistName: 'Bu',
}),
).resolves.toMatchInlineSnapshot(`
{
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('Contacts', () => {
await expect(
resend.contacts.remove({
id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87223',
audience_id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
audienceId: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
}),
).resolves.toMatchInlineSnapshot(`
{
Expand Down Expand Up @@ -291,7 +291,7 @@ describe('Contacts', () => {
await expect(
resend.contacts.remove({
email: '[email protected]',
audience_id: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
audienceId: '3d4a472d-bc6d-4dd2-aa9d-d3d50ce87222',
}),
).resolves.toMatchInlineSnapshot(`
{
Expand Down
46 changes: 26 additions & 20 deletions src/contacts/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ import {
CreateContactRequestOptions,
CreateContactResponse,
CreateContactResponseSuccess,
} from './interfaces/create-contact-options.interface';
import {
GetContactOptions,
GetContactResponse,
GetContactResponseSuccess,
} from './interfaces/get-contact.interface';
import {
ListContactsOptions,
ListContactsResponse,
ListContactsResponseSuccess,
} from './interfaces/list-contacts.interface';
import {
RemoveContactOptions,
RemoveContactsResponse,
RemoveContactsResponseSuccess,
} from './interfaces';
} from './interfaces/remove-contact.interface';
import {
UpdateContactOptions,
UpdateContactResponse,
Expand All @@ -26,48 +34,46 @@ export class Contacts {
options: CreateContactRequestOptions = {},
): Promise<CreateContactResponse> {
const data = await this.resend.post<CreateContactResponseSuccess>(
`/audiences/${payload.audience_id}/contacts`,
payload,
`/audiences/${payload.audienceId}/contacts`,
{
...payload,
first_name: payload.firstName,
last_name: payload.lastName,
},
options,
);
return data;
}

async list({
audience_id,
}: {
audience_id: string;
}): Promise<ListContactsResponse> {
async list(options: ListContactsOptions): Promise<ListContactsResponse> {
const data = await this.resend.get<ListContactsResponseSuccess>(
`/audiences/${audience_id}/contacts`,
`/audiences/${options.audienceId}/contacts`,
);
return data;
}

async get({
audience_id,
id,
}: {
audience_id: string;
id: string;
}): Promise<GetContactResponse> {
async get(options: GetContactOptions): Promise<GetContactResponse> {
const data = await this.resend.get<GetContactResponseSuccess>(
`/audiences/${audience_id}/contacts/${id}`,
`/audiences/${options.audienceId}/contacts/${options.id}`,
);
return data;
}

async update(payload: UpdateContactOptions): Promise<UpdateContactResponse> {
const data = await this.resend.patch<UpdateContactResponseSuccess>(
`/audiences/${payload.audience_id}/contacts/${payload.id}`,
payload,
`/audiences/${payload.audienceId}/contacts/${payload.id}`,
{
...payload,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we destruct audienceId in here? I don't think it's used in the API's body, but the way we have now will send extra keys in the body.

an even better option would be to explicitly send what we want (since we only care about 3 keys)

Suggested change
...payload,
unsubscribed: payload.unsubscribed,

first_name: payload.fistName,
last_name: payload.lastName,
},
);
return data;
}

async remove(payload: RemoveContactOptions): Promise<RemoveContactsResponse> {
const data = await this.resend.delete<RemoveContactsResponseSuccess>(
`/audiences/${payload.audience_id}/contacts/${
`/audiences/${payload.audienceId}/contacts/${
payload?.email ? payload?.email : payload?.id
}`,
);
Expand Down
6 changes: 3 additions & 3 deletions src/contacts/interfaces/create-contact-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { ErrorResponse } from '../../interfaces';
import { Contact } from './contact';

export interface CreateContactOptions {
audience_id: string;
audienceId: string;
email: string;
unsubscribed?: boolean;
first_name?: string;
last_name?: string;
firstName?: string;
lastName?: string;
Comment on lines +6 to +10
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are breaking changes

}

export interface CreateContactRequestOptions extends PostOptions {}
Expand Down
5 changes: 5 additions & 0 deletions src/contacts/interfaces/get-contact.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ErrorResponse } from '../../interfaces';
import { Contact } from './contact';

export interface GetContactOptions {
audienceId: string;
id: string;
}

export interface GetContactResponseSuccess
extends Pick<Contact, 'id' | 'name' | 'created_at'> {
object: 'contact';
Expand Down
4 changes: 0 additions & 4 deletions src/contacts/interfaces/index.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/contacts/interfaces/list-contacts.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ErrorResponse } from '../../interfaces';
import { Contact } from './contact';

export interface ListContactsOptions {
audienceId: string;
}

export type ListContactsResponseSuccess = Contact[];

export interface ListContactsResponse {
Expand Down
2 changes: 1 addition & 1 deletion src/contacts/interfaces/remove-contact.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface RemoveByOptions {
}

export interface RemoveContactOptions extends RemoveByOptions {
audience_id: string;
audienceId: string;
}

export interface RemoveContactsResponse {
Expand Down
6 changes: 3 additions & 3 deletions src/contacts/interfaces/update-contact.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Contact } from './contact';

export interface UpdateContactOptions {
id: string;
audience_id: string;
audienceId: string;
unsubscribed?: boolean;
first_name?: string;
last_name?: string;
fistName?: string;
lastName?: string;
}

export type UpdateContactResponseSuccess = Pick<Contact, 'id'>;
Expand Down
2 changes: 1 addition & 1 deletion src/domains/domains.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { enableFetchMocks } from 'jest-fetch-mock';
import { Resend } from '../resend';
import { DomainRegion } from './interfaces/domain';
import { GetDomainResponseSuccess } from './interfaces';
import { ErrorResponse } from '../interfaces';
import { GetDomainResponseSuccess } from './interfaces/get-domain.interface';

enableFetchMocks();

Expand Down
10 changes: 9 additions & 1 deletion src/domains/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ import {
CreateDomainRequestOptions,
CreateDomainResponse,
CreateDomainResponseSuccess,
} from './interfaces/create-domain-options.interface';
import {
GetDomainResponse,
GetDomainResponseSuccess,
} from './interfaces/get-domain.interface';
import {
ListDomainsResponse,
ListDomainsResponseSuccess,
} from './interfaces/list-domains.interface';
import {
RemoveDomainsResponse,
RemoveDomainsResponseSuccess,
} from './interfaces/remove-domain.interface';
import {
VerifyDomainsResponse,
VerifyDomainsResponseSuccess,
} from './interfaces';
} from './interfaces/verify-domain.interface';

export class Domains {
constructor(private readonly resend: Resend) {}
Expand Down
5 changes: 0 additions & 5 deletions src/domains/interfaces/index.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/emails/emails.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { enableFetchMocks } from 'jest-fetch-mock';
import { Resend } from '../resend';
import { CreateEmailOptions, GetEmailResponseSuccess } from './interfaces';
import { ErrorResponse } from '../interfaces';
import { GetEmailResponseSuccess } from './interfaces/get-email-options.interface';
import { CreateEmailOptions } from './interfaces/create-email-options.interface';

enableFetchMocks();

Expand Down
4 changes: 3 additions & 1 deletion src/emails/emails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
CreateEmailRequestOptions,
CreateEmailResponse,
CreateEmailResponseSuccess,
} from './interfaces/create-email-options.interface';
import {
GetEmailResponse,
GetEmailResponseSuccess,
} from './interfaces';
} from './interfaces/get-email-options.interface';

export class Emails {
constructor(private readonly resend: Resend) {}
Expand Down
2 changes: 0 additions & 2 deletions src/emails/interfaces/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/resend.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Resend } from './resend';
import { enableFetchMocks } from 'jest-fetch-mock';
import { CreateEmailOptions } from './emails/interfaces';
import { ErrorResponse } from './interfaces';
import { CreateEmailOptions } from './emails/interfaces/create-email-options.interface';

enableFetchMocks();

Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5388,11 +5388,11 @@ __metadata:

"typescript@patch:[email protected]#~builtin<compat/typescript>":
version: 5.3.3
resolution: "typescript@patch:typescript@npm%3A5.3.3#~builtin<compat/typescript>::version=5.3.3&hash=29ae49"
resolution: "typescript@patch:typescript@npm%3A5.3.3#~builtin<compat/typescript>::version=5.3.3&hash=e012d7"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: f61375590b3162599f0f0d5b8737877ac0a7bc52761dbb585d67e7b8753a3a4c42d9a554c4cc929f591ffcf3a2b0602f65ae3ce74714fd5652623a816862b610
checksum: 4e604a9e107ce0c23b16a2f8d79d0531d4d8fe9ebbb7a8c395c66998c39892f0e0a071ef0b0d4e66420a8ec2b8d6cfd9cdb29ba24f25b37cba072e9282376df9
languageName: node
linkType: hard

Expand Down