Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: marketo: migrate config fields and fix test cases #2789

Merged
merged 21 commits into from
Dec 2, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update utils.js
anantjain45823 authored Dec 1, 2023
commit ed3bc9261ca05a0d9cc50f50574c36936aee620c
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 = [
@@ -32,6 +35,7 @@ const getEndpoint = (destination) => {
return `https://${domain}/api/v1/customer-profiles`;
};


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

const formatFieldForRETl = (message, fieldName) => {
const identifierType = get(message, identifierTypeKey);
@@ -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;
}
@@ -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,
@@ -170,5 +171,5 @@ module.exports = {
formatFieldForRETl,
getCustomAttributes,
getExternalCustomerId,
formatFieldForEventStream,
formatFieldForEventStream
};