diff --git a/src/v0/destinations/monday/transform.js b/src/v0/destinations/monday/transform.js index 152b42f8d0..de34fa0521 100644 --- a/src/v0/destinations/monday/transform.js +++ b/src/v0/destinations/monday/transform.js @@ -38,7 +38,7 @@ const responseBuilder = (payload, endpoint, apiToken) => { * @param {*} param1 * @returns */ -const trackResponseBuilder = async (message, { Config }) => { +const trackResponseBuilder = async ({ message, destination: { Config }, metadata }) => { const { apiToken } = Config; let boardId = getDestinationExternalID(message, 'boardId'); const event = get(message, 'event'); @@ -54,14 +54,14 @@ const trackResponseBuilder = async (message, { Config }) => { } const endpoint = ENDPOINT; - const processedResponse = await getBoardDetails(endpoint, boardId, apiToken); + const processedResponse = await getBoardDetails(endpoint, boardId, apiToken, metadata); const payload = populatePayload(message, Config, processedResponse); return responseBuilder(payload, endpoint, apiToken); }; -const processEvent = async (message, destination) => { +const processEvent = async ({ message, destination, metadata }) => { if (!message.type) { throw new InstrumentationError('Event type is required'); } @@ -71,14 +71,14 @@ const processEvent = async (message, destination) => { const messageType = message.type.toLowerCase(); let response; if (messageType === EventType.TRACK) { - response = await trackResponseBuilder(message, destination); + response = await trackResponseBuilder({ message, destination, metadata }); } else { throw new InstrumentationError(`Event type ${messageType} is not supported`); } return response; }; -const process = async (event) => processEvent(event.message, event.destination); +const process = async (event) => processEvent(event); const processRouterDest = async (inputs, reqMetadata) => { const respList = await simpleProcessRouterDest(inputs, process, reqMetadata); diff --git a/src/v0/destinations/monday/util.js b/src/v0/destinations/monday/util.js index 0694028eb2..07e084c158 100644 --- a/src/v0/destinations/monday/util.js +++ b/src/v0/destinations/monday/util.js @@ -179,7 +179,7 @@ const mapColumnValues = (properties, columnToPropertyMapping, board) => { * @param {*} apiToken * @returns */ -const getBoardDetails = async (url, boardID, apiToken) => { +const getBoardDetails = async (url, boardID, apiToken, metadata) => { const clientResponse = await httpPOST( url, { @@ -197,6 +197,7 @@ const getBoardDetails = async (url, boardID, apiToken) => { endpointPath: '/v2', requestMethod: 'POST', module: 'router', + metadata, }, ); const boardDetailsResponse = processAxiosResponse(clientResponse); diff --git a/src/v0/destinations/profitwell/transform.js b/src/v0/destinations/profitwell/transform.js index 58449fd9c1..e88718771e 100644 --- a/src/v0/destinations/profitwell/transform.js +++ b/src/v0/destinations/profitwell/transform.js @@ -24,18 +24,19 @@ const { getDynamicErrorType } = require('../../../adapters/utils/networkUtils'); const tags = require('../../util/tags'); const { JSON_MIME_TYPE } = require('../../util/constant'); -const identifyResponseBuilder = async (message, { Config }) => { +const identifyResponseBuilder = async ({ message, destination: { Config }, metadata }) => { const { userId, userAlias, subscriptionId, subscriptionAlias } = validatePayloadAndRetunImpIds(message); let finalSubscriptionId = subscriptionId; let finalSubscriptionAlias = subscriptionAlias; - - const targetUrl = `${BASE_ENDPOINT}/v2/users/${userId || userAlias}/`; - const res = await getSubscriptionHistory(targetUrl, { + const options = { headers: { Authorization: Config.privateApiKey, }, - }); + }; + + const targetUrl = `${BASE_ENDPOINT}/v2/users/${userId || userAlias}/`; + const res = await getSubscriptionHistory(targetUrl, options, metadata); let payload; const response = defaultRequestConfig(); @@ -159,7 +160,7 @@ const process = async (event) => { let response; if (messageType === EventType.IDENTIFY) { - response = await identifyResponseBuilder(message, destination); + response = await identifyResponseBuilder(event); } else { throw new InstrumentationError(`Event type ${messageType} is not supported`); } diff --git a/src/v0/destinations/profitwell/utils.js b/src/v0/destinations/profitwell/utils.js index 1b23561721..cdc4f8a47d 100644 --- a/src/v0/destinations/profitwell/utils.js +++ b/src/v0/destinations/profitwell/utils.js @@ -179,7 +179,7 @@ const CURRENCY_CODES = [ 'zwl', ]; -const getSubscriptionHistory = async (endpoint, options) => { +const getSubscriptionHistory = async (endpoint, options, metadata) => { const requestOptions = { method: 'get', ...options, @@ -191,6 +191,7 @@ const getSubscriptionHistory = async (endpoint, options) => { endpointPath: '/users/userId', requestMethod: 'GET', module: 'router', + metadata, }); return res; }; diff --git a/src/v0/destinations/sendgrid/transform.js b/src/v0/destinations/sendgrid/transform.js index c32e34c489..a3516687db 100644 --- a/src/v0/destinations/sendgrid/transform.js +++ b/src/v0/destinations/sendgrid/transform.js @@ -57,15 +57,15 @@ const responseBuilder = (payload, method, endpoint, apiKey) => { throw new TransformationError(ErrorMessage.FailedToConstructPayload); }; -const identifyResponseBuilder = async (message, destination) => { +const identifyResponseBuilder = async ({ message, destination, metadata }) => { validateIdentifyPayload(message); - const builder = await createOrUpdateContactPayloadBuilder(message, destination); + const builder = await createOrUpdateContactPayloadBuilder({ message, destination, metadata }); const { payload, method, endpoint } = builder; const { apiKey } = destination.Config; return responseBuilder(payload, method, endpoint, apiKey); }; -const trackResponseBuilder = async (message, { Config }) => { +const trackResponseBuilder = async ({ message, destination: { Config } }) => { validateTrackPayload(message, Config); let payload = {}; payload = constructPayload(message, MAPPING_CONFIG[CONFIG_CATEGORIES.TRACK.name]); @@ -123,7 +123,8 @@ const trackResponseBuilder = async (message, { Config }) => { return responseBuilder(payload, method, endpoint, apiKey); }; -const processEvent = async (message, destination) => { +const processEvent = async (event) => { + const { message, destination } = event; // Validating if message type is even given or not if (!message.type) { throw new InstrumentationError('Event type is required'); @@ -137,10 +138,10 @@ const processEvent = async (message, destination) => { let response; switch (messageType) { case EventType.IDENTIFY: - response = await identifyResponseBuilder(message, destination); + response = await identifyResponseBuilder(event); break; case EventType.TRACK: - response = await trackResponseBuilder(message, destination); + response = await trackResponseBuilder(event); break; default: throw new InstrumentationError(`Event type ${messageType} is not supported`); @@ -148,7 +149,7 @@ const processEvent = async (message, destination) => { return response; }; -const process = (event) => processEvent(event.message, event.destination); +const process = (event) => processEvent(event); const generateBatchedPaylaodForArray = (events, combination) => { let batchEventResponse = defaultBatchRequestConfig(); diff --git a/src/v0/destinations/sendgrid/util.js b/src/v0/destinations/sendgrid/util.js index 7105c5cda5..1edb480516 100644 --- a/src/v0/destinations/sendgrid/util.js +++ b/src/v0/destinations/sendgrid/util.js @@ -431,7 +431,7 @@ const getContactListIds = (message, destination) => { * @param {*} destination * @returns */ -const fetchCustomFields = async (destination) => { +const fetchCustomFields = async ({ destination, metadata }) => { const { apiKey } = destination.Config; return customFieldsCache.get(destination.ID, async () => { const requestOptions = { @@ -448,6 +448,7 @@ const fetchCustomFields = async (destination) => { endpointPath: '/marketing/field_definitions', requestMethod: 'GET', module: 'router', + metadata, }); const processedResponse = processAxiosResponse(resonse); if (isHttpStatusSuccess(processedResponse.status)) { @@ -475,14 +476,14 @@ const fetchCustomFields = async (destination) => { * @param {*} contactDetails * @returns */ -const getCustomFields = async (message, destination) => { +const getCustomFields = async ({ message, destination, metadata }) => { const customFields = {}; const payload = get(message, 'context.traits'); const { customFieldsMapping } = destination.Config; const fieldsMapping = getHashFromArray(customFieldsMapping, 'from', 'to', false); const fields = Object.keys(fieldsMapping); if (fields.length > 0) { - const destinationCustomFields = await fetchCustomFields(destination); + const destinationCustomFields = await fetchCustomFields({ destination, metadata }); const customFieldNameToIdMapping = {}; const customFieldNamesArray = destinationCustomFields.map((destinationCustomField) => { const { id, name } = destinationCustomField; @@ -511,13 +512,13 @@ const getCustomFields = async (message, destination) => { * @param {*} destination * @returns */ -const createOrUpdateContactPayloadBuilder = async (message, destination) => { +const createOrUpdateContactPayloadBuilder = async ({ message, destination, metadata }) => { const contactDetails = constructPayload(message, MAPPING_CONFIG[CONFIG_CATEGORIES.IDENTIFY.name]); if (contactDetails.address_line_1) { contactDetails.address_line_1 = flattenAddress(contactDetails.address_line_1); } const contactListIds = getContactListIds(message, destination); - contactDetails.custom_fields = await getCustomFields(message, destination); + contactDetails.custom_fields = await getCustomFields({ message, destination, metadata }); const payload = { contactDetails, contactListIds }; const { endpoint } = CONFIG_CATEGORIES.IDENTIFY; const method = defaultPutRequestConfig.requestMethod; diff --git a/src/v0/destinations/sendinblue/transform.js b/src/v0/destinations/sendinblue/transform.js index 7663672f12..178a697f00 100644 --- a/src/v0/destinations/sendinblue/transform.js +++ b/src/v0/destinations/sendinblue/transform.js @@ -176,7 +176,7 @@ const updateDOIContactResponseBuilder = (message, destination, identifier) => { ); }; -const createOrUpdateDOIContactResponseBuilder = async (message, destination) => { +const createOrUpdateDOIContactResponseBuilder = async ({ message, destination, metadata }) => { let email = getFieldValueFromMessage(message, 'emailOnly'); const phone = getFieldValueFromMessage(message, 'phone'); @@ -196,7 +196,7 @@ const createOrUpdateDOIContactResponseBuilder = async (message, destination) => } const { apiKey } = destination.Config; - const contactExists = await checkIfContactExists(identifier, apiKey); + const contactExists = await checkIfContactExists(identifier, apiKey, metadata); if (contactExists) { return updateDOIContactResponseBuilder(message, destination, identifier); @@ -205,7 +205,7 @@ const createOrUpdateDOIContactResponseBuilder = async (message, destination) => return createDOIContactResponseBuilder(message, destination); }; -const identifyResponseBuilder = async (message, destination) => { +const identifyResponseBuilder = async ({ message, destination, metadata }) => { const { doi } = destination.Config; if (!doi) { const unlinkListIds = getListIds(message, 'sendinblueUnlinkListIds'); @@ -215,7 +215,7 @@ const identifyResponseBuilder = async (message, destination) => { return createOrUpdateContactResponseBuilder(message, destination); } - return createOrUpdateDOIContactResponseBuilder(message, destination); + return createOrUpdateDOIContactResponseBuilder({ message, destination, metadata }); }; // ref:- https://tracker-doc.sendinblue.com/reference/trackevent-3 @@ -305,7 +305,8 @@ const pageResponseBuilder = (message, destination) => { return responseBuilder(payload, endpoint, destination, true); }; -const processEvent = async (message, destination) => { +const processEvent = async (event) => { + const { message, destination } = event; if (!message.type) { throw new InstrumentationError('Event type is required'); } @@ -314,7 +315,7 @@ const processEvent = async (message, destination) => { let response; switch (messageType) { case EventType.IDENTIFY: - response = await identifyResponseBuilder(message, destination); + response = await identifyResponseBuilder(event); break; case EventType.TRACK: response = trackResponseBuilder(message, destination); @@ -328,7 +329,7 @@ const processEvent = async (message, destination) => { return response; }; -const process = (event) => processEvent(event.message, event.destination); +const process = (event) => processEvent(event); const processRouterDest = async (inputs) => { const respList = await simpleProcessRouterDest(inputs, process, process); diff --git a/src/v0/destinations/sendinblue/util.js b/src/v0/destinations/sendinblue/util.js index 9fded8e493..083de4ca44 100644 --- a/src/v0/destinations/sendinblue/util.js +++ b/src/v0/destinations/sendinblue/util.js @@ -52,7 +52,7 @@ const validateEmailAndPhone = (email, phone = null) => { */ const prepareEmailFromPhone = (phone) => `${phone.replace('+', '')}${EMAIL_SUFFIX}`; -const checkIfContactExists = async (identifier, apiKey) => { +const checkIfContactExists = async (identifier, apiKey, metadata) => { const endpoint = getContactDetailsEndpoint(identifier); const requestOptions = { headers: prepareHeader(apiKey), @@ -63,6 +63,7 @@ const checkIfContactExists = async (identifier, apiKey) => { endpointPath: '/contacts', requestMethod: 'GET', module: 'router', + metadata, }); const processedContactDetailsResponse = processAxiosResponse(contactDetailsResponse);