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 12, 2024
1 parent e57370f commit 180cdd3
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 4 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 @@ -37,7 +41,7 @@ const processRecordEventArray = (
metadata.push(record.metadata);
});

const userIdentifiersList = populateIdentifiers(
const userIdentifiersList = populateIdentifiersForRecordEvent(
fieldsArray,
typeOfList,
userSchema,
Expand Down
36 changes: 36 additions & 0 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 @@ -114,6 +115,40 @@ const populateIdentifiers = (attributeArray, typeOfList, userSchema, 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]] });

Check warning on line 133 in src/v0/destinations/google_adwords_remarketing_lists/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/google_adwords_remarketing_lists/util.js#L133

Added line #L133 was not covered by tests
} 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 @@ -131,4 +166,5 @@ module.exports = {
populateIdentifiers,
responseBuilder,
getOperationAudienceId,
populateIdentifiersForRecordEvent,
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { rETLAudienceRouterRequest } from './audience';
import { rETLRecordRouterRequest } from './record';
import { rETLRecordRouterRequest, rETLRecordRouterRequestVDMv2 } from './record';
import { API_VERSION } from '../../../../../src/v0/destinations/google_adwords_remarketing_lists/config';

export const data = [
Expand Down Expand Up @@ -732,4 +732,120 @@ export const data = [
},
},
},
{
name: 'google_adwords_remarketing_lists record event tests VDMv2',
description: 'Test 1',
feature: 'router',
module: 'destination',
version: 'v0',
input: {
request: {
body: rETLRecordRouterRequestVDMv2,
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: [
{
batchedRequest: [
{
version: '1',
type: 'REST',
method: 'POST',
endpoint: `https://googleads.googleapis.com/${API_VERSION}/customers/7693729833/offlineUserDataJobs`,
headers: {
Authorization: 'Bearer default-accessToken',

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "Bearer default-accessToken" is used as
authorization header
.
'Content-Type': 'application/json',
},
params: {
listId: '7090784486',
customerId: '7693729833',
consent: {
adPersonalization: 'UNSPECIFIED',
adUserData: 'UNSPECIFIED',
},
},
body: {
JSON: {
operations: [
{
create: {
userIdentifiers: [
{
hashedEmail:
'd3142c8f9c9129484daf28df80cc5c955791efed5e69afabb603bc8cb9ffd419',
},
{
hashedPhoneNumber:
'8846dcb6ab2d73a0e67dbd569fa17cec2d9d391e5b05d1dd42919bc21ae82c45',
},
{
addressInfo: {
hashedFirstName:
'9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08',
hashedLastName:
'dcf000c2386fb76d22cefc0d118a8511bb75999019cd373df52044bccd1bd251',
countryCode: 'US',
postalCode: '1245',
},
},
],
},
},
],
},
JSON_ARRAY: {},
XML: {},
FORM: {},
},
files: {},
},
],
metadata: [
{
attemptNum: 1,
destinationId: 'default-destinationId',
dontBatch: false,
secret: {
access_token: 'default-accessToken',
},
sourceId: 'default-sourceId',
userId: 'default-userId',
workspaceId: 'default-workspaceId',
jobId: 1,
},
],
batched: true,
statusCode: 200,
destination: {
Config: {
rudderAccountId: '258Yea7usSKNpbkIaesL9oJ9iYw',
audienceId: '7090784486',
customerId: '7693729833',
loginCustomerId: '',
subAccount: false,
},
DestinationDefinition: {
Config: {},
DisplayName: 'GOOGLE_ADWORDS_REMARKETING_LISTS',
ID: '1aIXqM806xAVm92nx07YwKbRrO9',
Name: 'GOOGLE_ADWORDS_REMARKETING_LISTS',
},
Enabled: true,
ID: '1mMy5cqbtfuaKZv1IhVQKnBdVwe',
IsConnectionEnabled: true,
IsProcessorEnabled: true,
Name: 'GOOGLE_ADWORDS_REMARKETING_LISTS',
Transformations: [],
WorkspaceID: '1TSN08muJTZwH8iCDmnnRt1pmLd',
},
},
],
},
},
},
},
];
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Destination, RouterTransformationRequest } from '../../../../../src/types';
import { Connection, Destination, RouterTransformationRequest } from '../../../../../src/types';
import { VDM_V2_SCHEMA_VERSION } from '../../../../../src/v0/util/constant';
import { generateGoogleOAuthMetadata } from '../../../testUtils';

const destination: Destination = {
Expand Down Expand Up @@ -27,6 +28,43 @@ const destination: Destination = {
IsProcessorEnabled: true,
};

const destination2: Destination = {
Config: {
rudderAccountId: '258Yea7usSKNpbkIaesL9oJ9iYw',
audienceId: '7090784486',
customerId: '7693729833',
loginCustomerId: '',
subAccount: false,
},
ID: '1mMy5cqbtfuaKZv1IhVQKnBdVwe',
Name: 'GOOGLE_ADWORDS_REMARKETING_LISTS',
Enabled: true,
WorkspaceID: '1TSN08muJTZwH8iCDmnnRt1pmLd',
DestinationDefinition: {
ID: '1aIXqM806xAVm92nx07YwKbRrO9',
Name: 'GOOGLE_ADWORDS_REMARKETING_LISTS',
DisplayName: 'GOOGLE_ADWORDS_REMARKETING_LISTS',
Config: {},
},
Transformations: [],
IsConnectionEnabled: true,
IsProcessorEnabled: true,
};

const connection: Connection = {
sourceId: '2MUWghI7u85n91dd1qzGyswpZan',
destinationId: '1mMy5cqbtfuaKZv1IhVQKnBdVwe',
enabled: true,
config: {
destination: {
schemaVersion: VDM_V2_SCHEMA_VERSION,
isHashRequired: true,
typeOfList: 'General',
audienceId: '7090784486',
},
},
};

export const rETLRecordRouterRequest: RouterTransformationRequest = {
input: [
{
Expand Down Expand Up @@ -153,6 +191,38 @@ export const rETLRecordRouterRequest: RouterTransformationRequest = {
destType: 'google_adwords_remarketing_lists',
};

export const rETLRecordRouterRequestVDMv2: RouterTransformationRequest = {
input: [
{
destination: destination2,
connection: connection,
message: {
action: 'insert',
context: {
ip: '14.5.67.21',
library: {
name: 'http',
},
},
recordId: '2',
rudderId: '2',
identifiers: {
email: '[email protected]',
phone: '@09876543210',
firstName: 'test',
lastName: 'rudderlabs',
country: 'US',
postalCode: '1245',
},
type: 'record',
},
metadata: generateGoogleOAuthMetadata(1),
},
],
destType: 'google_adwords_remarketing_lists',
};

module.exports = {
rETLRecordRouterRequest,
rETLRecordRouterRequestVDMv2,
};

0 comments on commit 180cdd3

Please sign in to comment.