Skip to content
Draft
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
3 changes: 3 additions & 0 deletions src/contacts/contacts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { buildPaginationQuery } from '../common/utils/build-pagination-query';
import type { Resend } from '../resend';
import { ContactImports } from './imports/contact-imports';
import type {
CreateContactOptions,
CreateContactRequestOptions,
Expand Down Expand Up @@ -31,10 +32,12 @@ import { ContactSegments } from './segments/contact-segments';
import { ContactTopics } from './topics/contact-topics';

export class Contacts {
readonly imports: ContactImports;
readonly topics: ContactTopics;
readonly segments: ContactSegments;

constructor(private readonly resend: Resend) {
this.imports = new ContactImports(this.resend);
this.topics = new ContactTopics(this.resend);
this.segments = new ContactSegments(this.resend);
}
Expand Down
98 changes: 98 additions & 0 deletions src/contacts/imports/contact-imports.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import createFetchMock from 'vitest-fetch-mock';
import { Resend } from '../../resend';
import { mockSuccessResponse } from '../../test-utils/mock-fetch';
import type {
ListContactImportsOptions,
ListContactImportsResponseSuccess,
} from './interfaces/list-contact-imports.interface';

const fetchMocker = createFetchMock(vi);
fetchMocker.enableMocks();

describe('ContactImports', () => {
afterEach(() => fetchMock.resetMocks());
afterAll(() => fetchMocker.disableMocks());

describe('list', () => {
it('lists contact imports', async () => {
const response: ListContactImportsResponseSuccess = {
object: 'list',
has_more: false,
data: [
{
object: 'contact_import',
id: '479e3145-dd38-476b-932c-529ceb705947',
status: 'completed',
created_at: '2026-05-15T18:32:37.823Z',
completed_at: '2026-05-15T18:33:42.916Z',
counts: {
total: 1200,
created: 800,
updated: 300,
skipped: 75,
failed: 25,
},
},
],
};

mockSuccessResponse(response, {});

const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
await expect(
resend.contacts.imports.list(),
).resolves.toMatchInlineSnapshot(`
{
"data": {
"data": [
{
"completed_at": "2026-05-15T18:33:42.916Z",
"counts": {
"created": 800,
"failed": 25,
"skipped": 75,
"total": 1200,
"updated": 300,
},
"created_at": "2026-05-15T18:32:37.823Z",
"id": "479e3145-dd38-476b-932c-529ceb705947",
"object": "contact_import",
"status": "completed",
},
],
"has_more": false,
"object": "list",
},
"error": null,
"headers": {
"content-type": "application/json",
},
}
`);
expect(fetchMock.mock.calls[0][0]).toBe(
'https://api.resend.com/contacts/imports',
);
});

it('lists contact imports with pagination and status', async () => {
const options: ListContactImportsOptions = {
limit: 10,
status: 'completed',
};
const response: ListContactImportsResponseSuccess = {
object: 'list',
has_more: false,
data: [],
};

mockSuccessResponse(response, {});

const resend = new Resend('re_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop');
await resend.contacts.imports.list(options);

expect(fetchMock.mock.calls[0][0]).toBe(
'https://api.resend.com/contacts/imports?limit=10&status=completed',
);
});
});
});
28 changes: 28 additions & 0 deletions src/contacts/imports/contact-imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { buildPaginationQuery } from '../../common/utils/build-pagination-query';
import type { Resend } from '../../resend';
import type {
ListContactImportsOptions,
ListContactImportsResponse,
ListContactImportsResponseSuccess,
} from './interfaces/list-contact-imports.interface';

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

async list(
options: ListContactImportsOptions = {},
): Promise<ListContactImportsResponse> {
const searchParams = new URLSearchParams(buildPaginationQuery(options));

if (options.status !== undefined) {
searchParams.set('status', options.status);
}

const queryString = searchParams.toString();
const url = queryString
? `/contacts/imports?${queryString}`
: '/contacts/imports';

return this.resend.get<ListContactImportsResponseSuccess>(url);
}
}
1 change: 1 addition & 0 deletions src/contacts/imports/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './list-contact-imports.interface';
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type {
PaginatedData,
PaginationOptions,
} from '../../../common/interfaces/pagination-options.interface';
import type { Response } from '../../../interfaces';

export type ContactImportStatus =
| 'queued'
| 'in_progress'
| 'completed'
| 'failed';

export type ListContactImportsOptions = PaginationOptions & {
status?: ContactImportStatus;
};

export interface ContactImportCounts {
total: number;
created: number;
updated: number;
skipped: number;
failed: number;
}

export interface ContactImport {
object: 'contact_import';
id: string;
status: ContactImportStatus;
created_at: string;
completed_at: string | null;
counts: ContactImportCounts;
}

export type ListContactImportsResponseSuccess = PaginatedData<ContactImport[]>;

export type ListContactImportsResponse =
Response<ListContactImportsResponseSuccess>;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './batch/interfaces';
export * from './broadcasts/interfaces';
export * from './common/interfaces';
export * from './contact-properties/interfaces';
export * from './contacts/imports/interfaces';
export * from './contacts/interfaces';
export * from './contacts/segments/interfaces';
export * from './contacts/topics/interfaces';
Expand Down
Loading