Skip to content

feat: add ContactImports class for managing contact imports#963

Open
vcapretz wants to merge 4 commits into
canaryfrom
preview-imports
Open

feat: add ContactImports class for managing contact imports#963
vcapretz wants to merge 4 commits into
canaryfrom
preview-imports

Conversation

@vcapretz
Copy link
Copy Markdown
Contributor

@vcapretz vcapretz commented May 18, 2026

Summary by cubic

Adds ContactImports under resend.contacts.imports to create, list, and get contact import jobs with multipart CSV uploads, pagination, and status filters. Also updates the client to send FormData correctly, exports the new interfaces, and bumps resend to 6.13.0-preview-imports.0.

  • New Features

    • Added contacts.imports (create, list, get) via /contacts/imports; create supports multipart uploads (file) with columnMap, onConflict, onError, segments, and topics; list supports pagination and status (queued, in_progress, completed, failed).
    • Exposed on Contacts as imports; exported interfaces via index.
  • Bug Fixes

    • Resend.post now detects FormData, removes Content-Type, and sends the form body as-is to support multipart uploads.

Written for commit bf926f2. Summary will update on new commits.

Review in cubic

@vcapretz vcapretz self-assigned this May 18, 2026
@vcapretz vcapretz changed the title feat(contacts): add ContactImports class and related interfaces for m… feat: add ContactImports class for managing contact imports May 18, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 18, 2026

Open in StackBlitz

npm i https://pkg.pr.new/resend@963

commit: bf926f2

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 6 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: This PR adds a new ContactImports class with a list method, following the established pattern of similar sub-resources like ContactTopics and ContactSegments, includes passing tests, and only touches new files and minimal additions to existing files, making the blast radius very low.

Re-trigger cubic

Copy link
Copy Markdown
Contributor

@lucasfcosta lucasfcosta left a comment

Choose a reason for hiding this comment

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

Nice!

vcapretz and others added 2 commits June 2, 2026 10:08
@vcapretz
Copy link
Copy Markdown
Contributor Author

vcapretz commented Jun 2, 2026

example script to create a new import:

#!/usr/bin/env node

import { openAsBlob } from 'node:fs';
import { access } from 'node:fs/promises';
import path from 'node:path';
import { Resend } from '../dist/index.mjs';

const apiKey = process.env.RESEND_API_KEY;

if (!apiKey) {
  console.error('Missing RESEND_API_KEY environment variable.');
  process.exit(1);
}

const csvPath = path.resolve(process.cwd(), 'contacts.csv');

try {
  await access(csvPath);
} catch {
  console.error(`CSV file not found: ${csvPath}`);
  process.exit(1);
}

const file = await openAsBlob(csvPath, { type: 'text/csv' });
const resend = new Resend(apiKey);

const result = await resend.contacts.imports.create({
  file,
  fileName: path.basename(csvPath),
  columnMap: { email: 'Email', firstName: 'Name', lastName: 'Last Name' },
  onConflict: 'skip',
  onError: 'continue',
});

console.log(JSON.stringify(result, null, 2));

if (result.error) {
  process.exitCode = 1;
}

Copy link
Copy Markdown
Contributor

@lucasfcosta lucasfcosta left a comment

Choose a reason for hiding this comment

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

No blockers, but I think the fileName comment is worth looking at. Same for other cleanups.

Comment thread src/contacts/imports/interfaces/create-contact-import.interface.ts Outdated
Comment thread src/contacts/imports/contact-imports.ts Outdated
Comment thread src/contacts/imports/contact-imports.ts Outdated
Comment thread src/contacts/imports/contact-imports.ts Outdated
Comment thread src/resend.ts
) {
const headers = new Headers(this.headers);
const isFormData =
typeof FormData !== 'undefined' && entity instanceof FormData;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FormData is not supported on Node 16 and below, which I think it's fine as it's out of LTS and was released in 2021 and LTS ended in 2023, but just noting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh yeah, at this point i wouldn't say we support Node versions older than 20 (maybe even 22)

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread src/contacts/imports/contact-imports.ts
@vcapretz vcapretz marked this pull request as ready for review June 3, 2026 15:50
@vcapretz vcapretz requested a review from a team as a code owner June 3, 2026 15:50
@vcapretz vcapretz requested a review from CarolinaMoraes June 3, 2026 15:50
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Auto-approved: This PR adds a new contact imports feature with multipart CSV uploads, including comprehensive tests and a targeted FormData handler in the HTTP client, all isolated to new functionality with minimal risk to existing code.

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants