Skip to content

Commit

Permalink
chore: propagate metadata in braze
Browse files Browse the repository at this point in the history
  • Loading branch information
Sai Sankeerth committed Jun 19, 2024
1 parent 0c4ce7c commit 6cd9992
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/v0/destinations/braze/braze.util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('dedup utility tests', () => {
};

// Call the function
const users = await BrazeDedupUtility.doApiLookup(identfierChunks, destination);
const users = await BrazeDedupUtility.doApiLookup(identfierChunks, { destination });

// Check the result
expect(users).toEqual([
Expand Down Expand Up @@ -399,7 +399,9 @@ describe('dedup utility tests', () => {
},
}));

const chunkedUserData = await BrazeDedupUtility.doApiLookup(identifierChunks, destination);
const chunkedUserData = await BrazeDedupUtility.doApiLookup(identifierChunks, {
destination,
});
const result = _.flatMap(chunkedUserData);
expect(result).toHaveLength(110);
expect(handleHttpRequest).toHaveBeenCalledTimes(3);
Expand Down Expand Up @@ -455,7 +457,7 @@ describe('dedup utility tests', () => {
},
}));

const users = await BrazeDedupUtility.doApiLookup(chunks, destination);
const users = await BrazeDedupUtility.doApiLookup(chunks, { destination });

expect(handleHttpRequest).toHaveBeenCalledTimes(2);
// Assert that the first chunk was successful and the second failed
Expand Down Expand Up @@ -522,7 +524,7 @@ describe('dedup utility tests', () => {
[{ alias_name: 'alias1', alias_label: 'rudder_id' }],
[{ alias_name: 'alias2', alias_label: 'rudder_id' }],
],
{ Config: { restApiKey: 'xyz' } },
{ destination: { Config: { restApiKey: 'xyz' } } },
);

// restore the original implementation of the mocked functions
Expand Down
5 changes: 3 additions & 2 deletions src/v0/destinations/braze/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function getUserAttributesObject(message, mappingJson, destination) {
* @param {*} message
* @param {*} destination
*/
async function processIdentify(message, destination) {
async function processIdentify({ message, destination, metadata }) {
const identifyPayload = getIdentifyPayload(message);
const identifyEndpoint = getIdentifyEndpoint(getEndpointFromConfig(destination));
const { processedResponse: brazeIdentifyResp } = await handleHttpRequest(
Expand All @@ -223,6 +223,7 @@ async function processIdentify(message, destination) {
requestMethod: 'POST',
module: 'router',
endpointPath: '/users/identify',
metadata,
},
);

Expand Down Expand Up @@ -517,7 +518,7 @@ async function process(event, processParams = { userStore: new Map() }, reqMetad
const brazeExternalID =
getDestinationExternalID(message, 'brazeExternalId') || message.userId;
if (message.anonymousId && brazeExternalID) {
await processIdentify(message, destination);
await processIdentify(event);
} else {
collectStatsForAliasMissConfigurations(destination.ID);
}
Expand Down
7 changes: 4 additions & 3 deletions src/v0/destinations/braze/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const BrazeDedupUtility = {
return identfierChunks;
},

async doApiLookup(identfierChunks, destination) {
async doApiLookup(identfierChunks, { destination, metadata }) {
return Promise.all(
identfierChunks.map(async (ids) => {
const externalIdentifiers = ids.filter((id) => id.external_id);
Expand All @@ -167,6 +167,7 @@ const BrazeDedupUtility = {
requestMethod: 'POST',
module: 'router',
endpointPath: '/users/export/ids',
metadata,
},
);
stats.counter('braze_lookup_failure_count', 1, {
Expand All @@ -189,10 +190,10 @@ const BrazeDedupUtility = {
*/
async doLookup(inputs) {
const lookupStartTime = new Date();
const { destination } = inputs[0];
const { destination, metadata } = inputs[0];
const { externalIdsToQuery, aliasIdsToQuery } = this.prepareInputForDedup(inputs);
const identfierChunks = this.prepareChunksForDedup(externalIdsToQuery, aliasIdsToQuery);
const chunkedUserData = await this.doApiLookup(identfierChunks, destination);
const chunkedUserData = await this.doApiLookup(identfierChunks, { destination, metadata });
stats.timing('braze_lookup_time', lookupStartTime, {
destination_id: destination.Config.destinationId,
});
Expand Down

0 comments on commit 6cd9992

Please sign in to comment.