From 3dbb376083d7af86febffd8a503ece996f764a84 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Tue, 8 Oct 2024 12:54:11 +0530 Subject: [PATCH] fix: address comment --- src/v0/destinations/intercom_v2/transform.js | 14 +++++++------- .../destinations/intercom_v2/router/data.ts | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/v0/destinations/intercom_v2/transform.js b/src/v0/destinations/intercom_v2/transform.js index e6bd30e2b8c..8d97e20bde7 100644 --- a/src/v0/destinations/intercom_v2/transform.js +++ b/src/v0/destinations/intercom_v2/transform.js @@ -29,16 +29,16 @@ const transformIdentifyPayload = (event) => { const { message, destination } = event; const category = ConfigCategory.IDENTIFY; const payload = constructPayload(message, MappingConfig[category.name]); + const shouldSendAnonymousId = destination.Config.sendAnonymousId; + if (!payload.external_id && shouldSendAnonymousId) { + payload.external_id = message.anonymousId; + } if (!(payload.external_id || payload.email)) { throw new InstrumentationError('Either email or userId is required for Identify call'); } payload.name = getName(message); payload.custom_attributes = message.traits || message.context.traits || {}; payload.custom_attributes = filterCustomAttributes(payload, 'user', destination); - const shouldSendAnonymousId = destination.Config.sendAnonymousId; - if (!payload.external_id && shouldSendAnonymousId) { - payload.external_id = message.anonymousId; - } return payload; }; @@ -46,9 +46,6 @@ const transformTrackPayload = (event) => { const { message, destination } = event; const category = ConfigCategory.TRACK; let payload = constructPayload(message, MappingConfig[category.name]); - if (!(payload.user_id || payload.email)) { - throw new InstrumentationError('Either email or userId is required for Track call'); - } if (!payload.id) { const integrationsObj = getIntegrationsObj(message, 'INTERCOM'); payload.id = integrationsObj?.id; @@ -57,6 +54,9 @@ const transformTrackPayload = (event) => { if (!payload.user_id && shouldSendAnonymousId) { payload.user_id = message.anonymousId; } + if (!(payload.user_id || payload.email || payload.id)) { + throw new InstrumentationError('Either email or userId or id is required for Track call'); + } payload = addMetadataToPayload(payload); return payload; }; diff --git a/test/integrations/destinations/intercom_v2/router/data.ts b/test/integrations/destinations/intercom_v2/router/data.ts index 3ac03eb99c4..76569140590 100644 --- a/test/integrations/destinations/intercom_v2/router/data.ts +++ b/test/integrations/destinations/intercom_v2/router/data.ts @@ -845,7 +845,7 @@ export const data: RouterTestData[] = [ }, { batched: false, - error: 'Either email or userId is required for Track call', + error: 'Either email or userId or id is required for Track call', statTags: RouterInstrumentationErrorStatTags, destination, metadata: [generateMetadata(2)],