Skip to content

feat(klaviyo): add email regex validation to addProfileToList - #3792

Merged
joe-ayoub-segment merged 3 commits into
mainfrom
ankit/klaviyo-email-validation
Aug 11, 2026
Merged

feat(klaviyo): add email regex validation to addProfileToList#3792
joe-ayoub-segment merged 3 commits into
mainfrom
ankit/klaviyo-email-validation

Conversation

@AnkitSegment

Copy link
Copy Markdown
Contributor

Summary

  • Adds email regex validation (/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/) to the Klaviyo addProfileToList action
  • Validates email in both single perform (throws PayloadValidationError) and batch performBatch (returns PAYLOAD_VALIDATION_FAILED in multi-status) paths
  • Invalid emails are filtered out before sending to Klaviyo's bulk import API, preventing unnecessary API calls

Test plan

  • Unit test: invalid email with single-char TLD rejected in single perform path
  • Unit test: batch filters out invalid emails and only sends valid profiles to API
  • Existing tests continue to pass (valid emails, phone numbers, external IDs)

🤖 Generated with Claude Code

Validate email format before sending to Klaviyo API in both single
perform and batch (performBatch) paths, returning PAYLOAD_VALIDATION_FAILED
in multi-status for invalid emails in batch mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@AnkitSegment
AnkitSegment requested a review from a team as a code owner May 14, 2026 05:01
Copilot AI lite review requested due to automatic review settings May 14, 2026 05:01

Copilot AI left a comment

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.

Pull request overview

This PR tightens input validation for the Klaviyo addProfileToList action by adding a stricter email regex check (beyond the existing JSON-schema format: 'email'), and applying that validation consistently in both single-event and batched execution paths to prevent sending obviously invalid emails to Klaviyo.

Changes:

  • Added a shared validateEmail helper and batch-path error mapping for invalid emails.
  • Added single perform validation that throws PayloadValidationError when the email fails the regex.
  • Added unit tests covering single-perform invalid TLD and batch filtering behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/destination-actions/src/destinations/klaviyo/functions.ts Adds email regex + validation helper and integrates it into batch payload validation.
packages/destination-actions/src/destinations/klaviyo/addProfileToList/index.ts Applies email validation in the single perform path and wires in the helper import.
packages/destination-actions/src/destinations/klaviyo/addProfileToList/tests/index.test.ts Adds tests for invalid email rejection and batch filtering.
Comments suppressed due to low confidence (1)

packages/destination-actions/src/destinations/klaviyo/addProfileToList/index.ts:75

  • This PayloadValidationError includes the raw email address in the error message. Emails are PII and may be surfaced in logs or customer-visible error surfaces; consider using a generic message (and ideally reusing the same message as the batch-path INVALID_EMAIL_ERROR) to avoid echoing user data.
    if (!validateEmail(email)) {
      throw new PayloadValidationError(`${email} is not a valid email address.`)
    }

Comment thread packages/destination-actions/src/destinations/klaviyo/addProfileToList/index.ts Outdated
- Use generic error message instead of echoing email value
- Fix "and" -> "or" in identifier required error message

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@joe-ayoub-segment

Copy link
Copy Markdown
Contributor

Hi @AnkitSegment @harsh-joshi99 will this be tested in stage? If so can we remove the "Ready for release" label until this is done please?

@joe-ayoub-segment

Copy link
Copy Markdown
Contributor

Hi @AnkitSegment @harsh-joshi99 will this be tested in stage? If so can we remove the "Ready for release" label until this is done please?

Hi @AnkitSegment cc @harsh-joshi99 will you be doing stage testing on this? or do you need to check if the email regex is broad enough? I'll deploy this if you give me the thumbs up.

@joe-ayoub-segment

Copy link
Copy Markdown
Contributor

Not deploying until email formatting clarified by @AnkitSegment .

Copilot AI review requested due to automatic review settings August 11, 2026 05:39

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (3)

packages/destination-actions/src/destinations/klaviyo/functions.ts:60

  • validateEmail() currently treats an empty string ('') as valid because !email returns true. This can allow payloads with external_id/phone_number to send email: '' to Klaviyo without being filtered/blocked. Consider only treating undefined (and possibly null if applicable in types) as “no email provided”, and otherwise validate (optionally after trimming).
export function validateEmail(email: string | undefined): boolean {
  if (!email) return true
  return EMAIL_REGEX.test(email)
}

packages/destination-actions/src/destinations/klaviyo/addProfileToList/index.ts:75

  • The error message string is duplicated here while functions.ts introduces INVALID_EMAIL_ERROR.errormessage for the batch path. To avoid message drift (and keep single/batch behavior aligned), consider reusing a shared constant (e.g., exporting the message or error object) rather than hardcoding the string again.
    if (!validateEmail(email)) {
      throw new PayloadValidationError('Email must be a valid email address.')
    }

packages/destination-actions/src/destinations/klaviyo/addProfileToList/tests/index.test.ts:373

  • Given validateEmail() currently treats falsy values as “no email”, it would be useful to add a unit test that covers email: '' (and/or whitespace) combined with another identifier (e.g., external_id) to ensure empty/blank emails don’t slip through and get sent to Klaviyo.
  it('should throw an error for email with single character TLD', async () => {
    const event = createTestEvent({
      type: 'track',
      userId: '123',
      properties: {}
    })
    const mapping = {
      list_id: listId,
      email: 'user@domain.c'
    }

@joe-ayoub-segment
joe-ayoub-segment merged commit a10aff2 into main Aug 11, 2026
19 of 20 checks passed
@joe-ayoub-segment
joe-ayoub-segment deleted the ankit/klaviyo-email-validation branch August 11, 2026 13:50
@joe-ayoub-segment

Copy link
Copy Markdown
Contributor

PR deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants