feat(klaviyo): add email regex validation to addProfileToList - #3792
Conversation
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>
There was a problem hiding this comment.
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
validateEmailhelper and batch-path error mapping for invalid emails. - Added single
performvalidation that throwsPayloadValidationErrorwhen 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.`)
}
- 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>
|
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. |
|
Not deploying until email formatting clarified by @AnkitSegment . |
There was a problem hiding this comment.
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!emailreturns true. This can allow payloads withexternal_id/phone_numberto sendemail: ''to Klaviyo without being filtered/blocked. Consider only treatingundefined(and possiblynullif 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.tsintroducesINVALID_EMAIL_ERROR.errormessagefor 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 coversemail: ''(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'
}
|
PR deployed |
Summary
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/) to the KlaviyoaddProfileToListactionperform(throwsPayloadValidationError) and batchperformBatch(returnsPAYLOAD_VALIDATION_FAILEDin multi-status) pathsTest plan
🤖 Generated with Claude Code