From 932ee945665ced6ce9da2c21528de603c2b91626 Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Mon, 13 Nov 2023 12:22:41 +0530 Subject: [PATCH] fix: review comments addressed --- src/v0/destinations/salesforce/transform.js | 13 ++----------- src/v0/destinations/salesforce/utils.js | 2 +- .../salesforce/dataDelivery/data.ts | 18 +++++++++++++----- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/v0/destinations/salesforce/transform.js b/src/v0/destinations/salesforce/transform.js index 123798cb2c..5ada9dfaa0 100644 --- a/src/v0/destinations/salesforce/transform.js +++ b/src/v0/destinations/salesforce/transform.js @@ -11,7 +11,6 @@ const { identifyContactMappingJson, ignoredLeadTraits, ignoredContactTraits, - OAUTH, } = require('./config'); const { removeUndefinedValues, @@ -112,15 +111,11 @@ async function getSaleforceIdForRecord( authorizationFlow, ) { const objSearchUrl = `${authorizationData.instanceUrl}/services/data/v${SF_API_VERSION}/parameterizedSearch/?q=${identifierValue}&sobject=${objectType}&in=${identifierType}&${objectType}.fields=id,${identifierType}`; - const finalHeader = - authorizationFlow === OAUTH - ? { Authorization: `Bearer ${authorizationData.token}` } - : { Authorization: authorizationData.token }; const { processedResponse: processedsfSearchResponse } = await handleHttpRequest( 'get', objSearchUrl, { - headers: finalHeader, + headers: getAuthHeader({ authorizationFlow, authorizationData }), }, { destType: 'salesforce', @@ -227,17 +222,13 @@ async function getSalesforceIdFromPayload( throw new InstrumentationError('Invalid Email address for Lead Objet'); } const leadQueryUrl = `${authorizationData.instanceUrl}/services/data/v${SF_API_VERSION}/parameterizedSearch/?q=${email}&sobject=Lead&Lead.fields=id,IsConverted,ConvertedContactId,IsDeleted`; - const finalHeader = - authorizationFlow === OAUTH - ? { Authorization: `Bearer ${authorizationData.token}` } - : { Authorization: authorizationData.token }; // request configuration will be conditional const { processedResponse: processedLeadQueryResponse } = await handleHttpRequest( 'get', leadQueryUrl, { - headers: finalHeader, + headers: getAuthHeader({ authorizationFlow, authorizationData }), }, { destType: 'salesforce', diff --git a/src/v0/destinations/salesforce/utils.js b/src/v0/destinations/salesforce/utils.js index aacc737842..c725ec3b20 100644 --- a/src/v0/destinations/salesforce/utils.js +++ b/src/v0/destinations/salesforce/utils.js @@ -41,7 +41,7 @@ const salesforceResponseHandler = (destResponse, sourceMessage, authKey, authori throw new RetryableError( `${DESTINATION} Request Failed - due to "INVALID_SESSION_ID", (Retryable) ${sourceMessage}`, 500, - response, + destResponse, authorizationFlow === LEGACY ? '' : getAuthErrCategoryFromStCode(status), ); } else if (status === 403 && matchErrorCode('REQUEST_LIMIT_EXCEEDED')) { diff --git a/test/integrations/destinations/salesforce/dataDelivery/data.ts b/test/integrations/destinations/salesforce/dataDelivery/data.ts index 5016e8fa73..c53ce58f9e 100644 --- a/test/integrations/destinations/salesforce/dataDelivery/data.ts +++ b/test/integrations/destinations/salesforce/dataDelivery/data.ts @@ -122,12 +122,20 @@ export const data = [ authErrorCategory: 'REFRESH_TOKEN', message: 'Salesforce Request Failed - due to "INVALID_SESSION_ID", (Retryable) during Salesforce Response Handling', - destinationResponse: [ - { - message: 'Session expired or invalid', - errorCode: 'INVALID_SESSION_ID', + destinationResponse: { + response: [ + { + message: 'Session expired or invalid', + errorCode: 'INVALID_SESSION_ID', + }, + ], + rudderJobMetadata: { + destInfo: { + authKey: '2HezPl1w11opbFSxnLDEgZ7kWTf', + }, }, - ], + status: 401, + }, statTags: { destType: 'SALESFORCE', errorCategory: 'network',