Skip to content

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

Open
AnkitSegment wants to merge 2 commits into
mainfrom
ankit/klaviyo-email-validation
Open

feat(klaviyo): add email regex validation to addProfileToList#3792
AnkitSegment wants to merge 2 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 review requested due to automatic review settings May 14, 2026 05:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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>
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.

4 participants