Skip to content

Commit

Permalink
feat: moved userSchema to connection config in GARL vdmv2
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepdsvs committed Nov 11, 2024
1 parent 5426d6c commit e57370f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const processRecordEventArray = (
developerToken,
audienceId,
typeOfList,
userSchema,
isHashRequired,
operationType,
) => {
Expand All @@ -38,8 +39,8 @@ const processRecordEventArray = (

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

Expand Down Expand Up @@ -91,7 +92,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 +111,7 @@ function preparepayload(events, config) {
developerToken,
audienceId,
typeOfList,
userSchema,
isHashRequired,
'remove',
);
Expand All @@ -124,6 +126,7 @@ function preparepayload(events, config) {
developerToken,
audienceId,
typeOfList,
userSchema,
isHashRequired,
'add',
);
Expand All @@ -138,6 +141,7 @@ function preparepayload(events, config) {
developerToken,
audienceId,
typeOfList,
userSchema,
isHashRequired,
'add',
);
Expand All @@ -161,19 +165,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];

Check warning on line 179 in src/v0/destinations/google_adwords_remarketing_lists/recordTransform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/google_adwords_remarketing_lists/recordTransform.js#L179

Added line #L179 was not covered by tests
const { audienceId, typeOfList, isHashRequired } = connection.config.destination;

const identifiers = message?.identifiers;

Check warning on line 182 in src/v0/destinations/google_adwords_remarketing_lists/recordTransform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/google_adwords_remarketing_lists/recordTransform.js#L182

Added line #L182 was not covered by tests
let userSchema;
if (identifiers) {
userSchema = Object.keys(identifiers);

Check warning on line 185 in src/v0/destinations/google_adwords_remarketing_lists/recordTransform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/google_adwords_remarketing_lists/recordTransform.js#L185

Added line #L185 was not covered by tests
}

const events = groupedRecordInputs.map((record) => ({
...record,
message: {
Expand All @@ -185,6 +196,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
5 changes: 2 additions & 3 deletions src/v0/destinations/google_adwords_remarketing_lists/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,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
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

0 comments on commit e57370f

Please sign in to comment.