Skip to content

Commit

Permalink
Merge branch 'develop' into chore.node.upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
krishna2020 authored Jan 16, 2025
2 parents a6001c4 + 1c45db8 commit 211813d
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 0 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"unset-value": "^2.0.1",
"uuid": "^9.0.1",
"valid-url": "^1.0.9",
"validator": "^13.12.0",
"zod": "^3.22.4"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions src/v0/destinations/hs/HSTransform-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
ConfigurationError,
InstrumentationError,
} = require('@rudderstack/integrations-lib');
const validator = require('validator');
const { MappedToDestinationKey, GENERIC_TRUE_VALUES } = require('../../../constants');
const {
defaultPostRequestConfig,
Expand Down Expand Up @@ -72,6 +73,11 @@ const addHsAuthentication = (response, Config) => {
const processIdentify = async ({ message, destination, metadata }, propertyMap) => {
const { Config } = destination;
let traits = getFieldValueFromMessage(message, 'traits');
// since hubspot does not allow imvalid emails, we need to
// validate the email before sending it to hubspot
if (traits?.email && !validator.isEmail(traits.email)) {
throw new InstrumentationError(`Email "${traits.email}" is invalid`);
}
const mappedToDestination = get(message, MappedToDestinationKey);
const operation = get(message, 'context.hubspotOperation');
const externalIdObj = getDestinationExternalIDObjectForRetl(message, 'HS');
Expand Down
82 changes: 82 additions & 0 deletions test/integrations/destinations/hs/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5425,4 +5425,86 @@ export const data = [
},
},
},
{
name: 'hs',
description:
'[HS] (New API v3) - throw error if invalid email is provided in traits for identify call',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
description:
'[HS] (New API v3) - throw error if invalid email is provided in traits for identify call',
message: {
channel: 'web',
context: {
traits: {
email: 'incorrect-email',
firstname: 'Test Hubspot',
},
library: {
name: 'RudderLabs JavaScript SDK',
version: '1.0.0',
},
},
type: 'identify',
messageId: 'e8585d9a-7137-4223-b295-68ab1b17dad7',
originalTimestamp: '2025-01-01T09:35:31.289Z',
anonymousId: '00000000000000000000000000',
userId: '12345',
properties: '',
integrations: {
All: true,
},
sentAt: '2019-10-14T11:15:53.296Z',
},
destination: {
Config: {
authorizationType: 'newPrivateAppApi',
hubID: '',
apiKey: '',
accessToken: 'dummy-access-token',
apiVersion: 'newApi',
lookupField: 'lookupField',
eventFilteringOption: 'disable',
blacklistedEvents: [
{
eventName: '',
},
],
whitelistedEvents: [
{
eventName: '',
},
],
},
Enabled: true,
},
},
],
},
},
output: {
response: {
status: 200,
body: [
{
error: 'Email "incorrect-email" is invalid',
statTags: {
destType: 'HS',
errorCategory: 'dataValidation',
errorType: 'instrumentation',
feature: 'processor',
implementation: 'native',
module: 'destination',
},
statusCode: 400,
},
],
},
},
},
];
116 changes: 116 additions & 0 deletions test/integrations/destinations/hs/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3547,4 +3547,120 @@ export const data = [
},
},
},
{
name: 'hs',
description: 'test when email is of wrong format',
feature: 'router',
module: 'destination',
id: 'emailfailsValidation',
version: 'v0',
input: {
request: {
body: {
input: [
{
message: {
channel: 'web',
context: {
traits: {
email: 'incorrect-email',
firstname: 'Test Hubspot',
},
library: {
name: 'RudderLabs JavaScript SDK',
version: '1.0.0',
},
},
type: 'identify',
messageId: 'e8585d9a-7137-4223-b295-68ab1b17dad7',
originalTimestamp: '2025-01-01T09:35:31.289Z',
anonymousId: '00000000000000000000000000',
userId: '12345',
properties: '',
integrations: {
All: true,
},
sentAt: '2019-10-14T11:15:53.296Z',
},
destination: {
Config: {
authorizationType: 'newPrivateAppApi',
hubID: '',
apiKey: '',
accessToken: 'dummy-access-token',
apiVersion: 'newApi',
lookupField: 'lookupField',
eventFilteringOption: 'disable',
blacklistedEvents: [
{
eventName: '',
},
],
whitelistedEvents: [
{
eventName: '',
},
],
},
Enabled: true,
},
metadata: { jobId: 3, userId: 'u1' },
},
],
destType: 'hs',
},
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: [
{
batched: false,
destination: {
Config: {
accessToken: 'dummy-access-token',
apiKey: '',
apiVersion: 'newApi',
authorizationType: 'newPrivateAppApi',
blacklistedEvents: [
{
eventName: '',
},
],
eventFilteringOption: 'disable',
hubID: '',
lookupField: 'lookupField',
whitelistedEvents: [
{
eventName: '',
},
],
},
Enabled: true,
},
error: 'Email "incorrect-email" is invalid',
metadata: [
{
jobId: 3,
userId: 'u1',
},
],
statTags: {
destType: 'HS',
errorCategory: 'dataValidation',
errorType: 'instrumentation',
feature: 'router',
implementation: 'native',
module: 'destination',
},
statusCode: 400,
},
],
},
},
},
},
];

0 comments on commit 211813d

Please sign in to comment.