Skip to content

Commit 364ac25

Browse files
fix: add email validation in HS
1 parent 57fc4fe commit 364ac25

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

package-lock.json

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"unset-value": "^2.0.1",
121121
"uuid": "^9.0.1",
122122
"valid-url": "^1.0.9",
123+
"validator": "^13.12.0",
123124
"zod": "^3.22.4"
124125
},
125126
"devDependencies": {

src/v0/destinations/hs/HSTransform-v2.js

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
ConfigurationError,
66
InstrumentationError,
77
} = require('@rudderstack/integrations-lib');
8+
const validator = require('validator');
89
const { MappedToDestinationKey, GENERIC_TRUE_VALUES } = require('../../../constants');
910
const {
1011
defaultPostRequestConfig,
@@ -72,6 +73,11 @@ const addHsAuthentication = (response, Config) => {
7273
const processIdentify = async ({ message, destination, metadata }, propertyMap) => {
7374
const { Config } = destination;
7475
let traits = getFieldValueFromMessage(message, 'traits');
76+
// since hubspot does not allow imvalid emails, we need to
77+
// validate the email before sending it to hubspot
78+
if (traits?.email && !validator.isEmail(traits.email)) {
79+
throw new InstrumentationError(`Email ${traits.email} is invalid`);
80+
}
7581
const mappedToDestination = get(message, MappedToDestinationKey);
7682
const operation = get(message, 'context.hubspotOperation');
7783
const externalIdObj = getDestinationExternalIDObjectForRetl(message, 'HS');

test/integrations/destinations/hs/processor/data.ts

+82
Original file line numberDiff line numberDiff line change
@@ -5425,4 +5425,86 @@ export const data = [
54255425
},
54265426
},
54275427
},
5428+
{
5429+
name: 'hs',
5430+
description:
5431+
'[HS] (New API v3) - throw error if invalid email is provided in traits for identify call',
5432+
feature: 'processor',
5433+
module: 'destination',
5434+
version: 'v0',
5435+
input: {
5436+
request: {
5437+
body: [
5438+
{
5439+
description:
5440+
'[HS] (New API v3) - throw error if invalid email is provided in traits for identify call',
5441+
message: {
5442+
channel: 'web',
5443+
context: {
5444+
traits: {
5445+
email: 'incorrect-email',
5446+
firstname: 'Test Hubspot',
5447+
},
5448+
library: {
5449+
name: 'RudderLabs JavaScript SDK',
5450+
version: '1.0.0',
5451+
},
5452+
},
5453+
type: 'identify',
5454+
messageId: 'e8585d9a-7137-4223-b295-68ab1b17dad7',
5455+
originalTimestamp: '2025-01-01T09:35:31.289Z',
5456+
anonymousId: '00000000000000000000000000',
5457+
userId: '12345',
5458+
properties: '',
5459+
integrations: {
5460+
All: true,
5461+
},
5462+
sentAt: '2019-10-14T11:15:53.296Z',
5463+
},
5464+
destination: {
5465+
Config: {
5466+
authorizationType: 'newPrivateAppApi',
5467+
hubID: '',
5468+
apiKey: '',
5469+
accessToken: 'dummy-access-token',
5470+
apiVersion: 'newApi',
5471+
lookupField: 'lookupField',
5472+
eventFilteringOption: 'disable',
5473+
blacklistedEvents: [
5474+
{
5475+
eventName: '',
5476+
},
5477+
],
5478+
whitelistedEvents: [
5479+
{
5480+
eventName: '',
5481+
},
5482+
],
5483+
},
5484+
Enabled: true,
5485+
},
5486+
},
5487+
],
5488+
},
5489+
},
5490+
output: {
5491+
response: {
5492+
status: 200,
5493+
body: [
5494+
{
5495+
error: 'Email incorrect-email is invalid',
5496+
statTags: {
5497+
destType: 'HS',
5498+
errorCategory: 'dataValidation',
5499+
errorType: 'instrumentation',
5500+
feature: 'processor',
5501+
implementation: 'native',
5502+
module: 'destination',
5503+
},
5504+
statusCode: 400,
5505+
},
5506+
],
5507+
},
5508+
},
5509+
},
54285510
];

0 commit comments

Comments
 (0)