Skip to content

Commit

Permalink
Update utils.js
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 authored Dec 1, 2023
1 parent 184e474 commit ed3bc92
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/cdk/v2/destinations/gladly/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const get = require('get-value');
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const { base64Convertor, getDestinationExternalID } = require('../../../../v0/util');
const {
base64Convertor,
getDestinationExternalID,
} = require('../../../../v0/util');
const { MappedToDestinationKey } = require('../../../../constants');

const reservedCustomAttributes = [
Expand Down Expand Up @@ -32,6 +35,7 @@ const getEndpoint = (destination) => {
return `https://${domain}/api/v1/customer-profiles`;
};


const getFieldValue = (field) => {
if (field) {
if (Array.isArray(field)) {
Expand All @@ -40,7 +44,7 @@ const getFieldValue = (field) => {
return [{ original: field }];
}
return undefined;
};
}

const formatFieldForRETl = (message, fieldName) => {
const identifierType = get(message, identifierTypeKey);
Expand All @@ -66,16 +70,15 @@ const formatField = (message, fieldName) => {
return formatFieldForRETl(message, fieldName);
}
return formatFieldForEventStream(message, fieldName);

};

const getCustomAttributes = (message) => {
const mappedToDestination = get(message, MappedToDestinationKey);
// for rETL
if (mappedToDestination) {
if (message?.traits?.customAttributes && typeof message.traits.customAttributes === 'object') {
return Object.keys(message.traits.customAttributes).length > 0
? message.traits.customAttributes
: undefined;
return Object.keys(message.traits.customAttributes).length > 0 ? message.traits.customAttributes : undefined;
}
return undefined;
}
Expand Down Expand Up @@ -137,27 +140,25 @@ const getCustomerId = (message) => {

const validatePayload = (payload) => {
if (!(payload?.phones || payload?.emails || payload?.id || payload?.externalCustomerId)) {
throw new InstrumentationError(
'One of phone, email, userId or GladlyCustomerId is required for an identify call',
);
throw new InstrumentationError('One of phone, email, userId or GladlyCustomerId is required for an identify call');
}
};

const getQueryParams = (payload) => {
if (payload.emails && payload.emails.length > 0) {
return `email=${encodeURIComponent(payload.emails[0].original)}`;
return `email=${encodeURIComponent(payload.emails[0].original)}`
}

if (payload.phones && payload.phones.length > 0) {
return `phoneNumber=${encodeURIComponent(payload.phones[0].original)}`;
return `phoneNumber=${encodeURIComponent(payload.phones[0].original)}`
}

if (payload.externalCustomerId) {
return `externalCustomerId=${encodeURIComponent(payload.externalCustomerId)}`;
return `externalCustomerId=${encodeURIComponent(payload.externalCustomerId)}`
}

return undefined;
};
}

module.exports = {
getHeaders,
Expand All @@ -170,5 +171,5 @@ module.exports = {
formatFieldForRETl,
getCustomAttributes,
getExternalCustomerId,
formatFieldForEventStream,
formatFieldForEventStream
};

0 comments on commit ed3bc92

Please sign in to comment.