Skip to content

Commit

Permalink
Merge branch 'develop' into feat.sources-v2-spec-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayteki95 authored Nov 12, 2024
2 parents 70ab9c8 + 640a11e commit 839281b
Show file tree
Hide file tree
Showing 7 changed files with 405 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const CONFIG_CATEGORIES = {
AUDIENCE_LIST: { type: 'audienceList', name: 'offlineDataJobs' },
ADDRESSINFO: { type: 'addressInfo', name: 'addressInfo' },
};
const ADDRESS_INFO_ATTRIBUTES = ['firstName', 'lastName', 'country', 'postalCode'];
const attributeMapping = {
email: 'hashedEmail',
phone: 'hashedPhoneNumber',
Expand All @@ -31,6 +32,7 @@ module.exports = {
hashAttributes,
offlineDataJobsMapping: MAPPING_CONFIG[CONFIG_CATEGORIES.AUDIENCE_LIST.name],
addressInfoMapping: MAPPING_CONFIG[CONFIG_CATEGORIES.ADDRESSINFO.name],
ADDRESS_INFO_ATTRIBUTES,
consentConfigMap,
destType: 'google_adwords_remarketing_lists',
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ const {
isEventSentByVDMV2Flow,
} = require('../../util');
const { populateConsentFromConfig } = require('../../util/googleUtils');
const { populateIdentifiers, responseBuilder, getOperationAudienceId } = require('./util');
const {
populateIdentifiersForRecordEvent,
responseBuilder,
getOperationAudienceId,
} = require('./util');
const { getErrorResponse, createFinalResponse } = require('../../util/recordUtils');
const { offlineDataJobsMapping, consentConfigMap } = require('./config');

Expand All @@ -23,6 +27,7 @@ const processRecordEventArray = (
developerToken,
audienceId,
typeOfList,
userSchema,
isHashRequired,
operationType,
) => {
Expand All @@ -36,10 +41,10 @@ const processRecordEventArray = (
metadata.push(record.metadata);
});

const userIdentifiersList = populateIdentifiers(
const userIdentifiersList = populateIdentifiersForRecordEvent(
fieldsArray,
destination,
typeOfList,
userSchema,
isHashRequired,
);

Expand Down Expand Up @@ -91,7 +96,7 @@ function preparepayload(events, config) {
const { destination, message, metadata } = events[0];
const accessToken = getAccessToken(metadata, 'access_token');
const developerToken = getValueFromMessage(metadata, 'secret.developer_token');
const { audienceId, typeOfList, isHashRequired } = config;
const { audienceId, typeOfList, isHashRequired, userSchema } = config;

const groupedRecordsByAction = lodash.groupBy(events, (record) =>
record.message.action?.toLowerCase(),
Expand All @@ -110,6 +115,7 @@ function preparepayload(events, config) {
developerToken,
audienceId,
typeOfList,
userSchema,
isHashRequired,
'remove',
);
Expand All @@ -124,6 +130,7 @@ function preparepayload(events, config) {
developerToken,
audienceId,
typeOfList,
userSchema,
isHashRequired,
'add',
);
Expand All @@ -138,6 +145,7 @@ function preparepayload(events, config) {
developerToken,
audienceId,
typeOfList,
userSchema,
isHashRequired,
'add',
);
Expand All @@ -161,19 +169,26 @@ function preparepayload(events, config) {

function processRecordInputsV0(groupedRecordInputs) {
const { destination, message } = groupedRecordInputs[0];
const { audienceId, typeOfList, isHashRequired } = destination.Config;
const { audienceId, typeOfList, isHashRequired, userSchema } = destination.Config;

return preparepayload(groupedRecordInputs, {
audienceId: getOperationAudienceId(audienceId, message),
typeOfList,
userSchema,
isHashRequired,
});
}

function processRecordInputsV1(groupedRecordInputs) {
const { connection } = groupedRecordInputs[0];
const { connection, message } = groupedRecordInputs[0];
const { audienceId, typeOfList, isHashRequired } = connection.config.destination;

const identifiers = message?.identifiers;
let userSchema;
if (identifiers) {
userSchema = Object.keys(identifiers);
}

const events = groupedRecordInputs.map((record) => ({
...record,
message: {
Expand All @@ -185,6 +200,7 @@ function processRecordInputsV1(groupedRecordInputs) {
return preparepayload(events, {
audienceId,
typeOfList,
userSchema,
isHashRequired,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ function extraKeysPresent(dictionary, keyList) {
const createPayload = (message, destination) => {
const { listData } = message.properties;
const properties = ['add', 'remove'];
const { typeOfList, isHashRequired } = destination.Config;
const { typeOfList, userSchema, isHashRequired } = destination.Config;

let outputPayloads = {};
const typeOfOperation = Object.keys(listData);
typeOfOperation.forEach((key) => {
if (properties.includes(key)) {
const userIdentifiersList = populateIdentifiers(
listData[key],
destination,
typeOfList,
userSchema,
isHashRequired,
);
if (userIdentifiersList.length === 0) {
Expand Down
41 changes: 38 additions & 3 deletions src/v0/destinations/google_adwords_remarketing_lists/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
TYPEOFLIST,
BASE_ENDPOINT,
hashAttributes,
ADDRESS_INFO_ATTRIBUTES,
} = require('./config');

const hashEncrypt = (object) => {
Expand Down Expand Up @@ -68,14 +69,13 @@ const responseBuilder = (
* Logics: Here we are creating an array with all the attributes provided in the add/remove array
* inside listData.
* @param {Array} attributeArray rudder event message properties listData add
* @param {object} Config rudder event destination
* @param {string} typeOfList
* @param {Array<string>} userSchema
* @param {boolean} isHashRequired
* @returns
*/
const populateIdentifiers = (attributeArray, { Config }, typeOfList, isHashRequired) => {
const populateIdentifiers = (attributeArray, typeOfList, userSchema, isHashRequired) => {
const userIdentifier = [];
const { userSchema } = Config;
let attribute;
if (TYPEOFLIST[typeOfList]) {
attribute = TYPEOFLIST[typeOfList];
Expand Down Expand Up @@ -115,6 +115,40 @@ const populateIdentifiers = (attributeArray, { Config }, typeOfList, isHashRequi
return userIdentifier;
};

const populateIdentifiersForRecordEvent = (
identifiersArray,
typeOfList,
userSchema,
isHashRequired,
) => {
const userIdentifiers = [];

if (isDefinedAndNotNullAndNotEmpty(identifiersArray)) {
// traversing through every element in the add array
identifiersArray.forEach((identifiers) => {
if (isHashRequired) {
hashEncrypt(identifiers);
}
if (TYPEOFLIST[typeOfList] && identifiers[TYPEOFLIST[typeOfList]]) {
userIdentifiers.push({ [TYPEOFLIST[typeOfList]]: identifiers[TYPEOFLIST[typeOfList]] });
} else {
Object.entries(attributeMapping).forEach(([key, mappedKey]) => {
if (identifiers[key] && userSchema.includes(key))
userIdentifiers.push({ [mappedKey]: identifiers[key] });
});
const addressInfo = constructPayload(identifiers, addressInfoMapping);
if (
isDefinedAndNotNullAndNotEmpty(addressInfo) &&
(userSchema.includes('addressInfo') ||
userSchema.some((schema) => ADDRESS_INFO_ATTRIBUTES.includes(schema)))
)
userIdentifiers.push({ addressInfo });
}
});
}
return userIdentifiers;
};

const getOperationAudienceId = (audienceId, message) => {
let operationAudienceId = audienceId;
const mappedToDestination = get(message, MappedToDestinationKey);
Expand All @@ -132,4 +166,5 @@ module.exports = {
populateIdentifiers,
responseBuilder,
getOperationAudienceId,
populateIdentifiersForRecordEvent,
};
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ describe('GARL utils test', () => {
const { typeOfList, isHashRequired } = baseDestination.Config;
const identifier = populateIdentifiers(
attributeArray,
baseDestination,
typeOfList,
baseDestination.Config.userSchema,
isHashRequired,
);
expect(identifier).toEqual(hashedArray);
Expand Down
Loading

0 comments on commit 839281b

Please sign in to comment.