Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: salesforce refactor #3824

Open
wants to merge 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3aea42f
fix: initial commit
shrouti1507 Oct 1, 2024
99c8efa
fix: test cases fixed
shrouti1507 Oct 3, 2024
6648747
fix: review comments addressed
shrouti1507 Oct 3, 2024
1565e3a
Merge branch 'develop' into salesforcev2-refactor
shrouti1507 Oct 3, 2024
2494754
Merge branch 'develop' into salesforcev2-refactor
shrouti1507 Oct 21, 2024
0c6a729
fix: conflict resolve
shrouti1507 Oct 21, 2024
17081a0
fix: test case correction
shrouti1507 Oct 21, 2024
9b93202
Merge branch 'develop' into salesforcev2-refactor
shrouti1507 Oct 21, 2024
629aec3
fix: apply suggestions from code review
shrouti1507 Oct 22, 2024
fe921c8
fix: code review change
shrouti1507 Oct 22, 2024
76bee1e
Merge branch 'develop' into salesforcev2-refactor
shrouti1507 Oct 22, 2024
bd3f6d2
fix: code review changes
shrouti1507 Oct 22, 2024
1edb8d0
fix: code review changes
shrouti1507 Oct 22, 2024
80bea09
fix: fix test cases
shrouti1507 Oct 22, 2024
829951e
chore: salesforce refactor
Oct 22, 2024
99cc9ae
fix: update ttl with correct import
Oct 22, 2024
410a512
chore: move from enums to dest def
Oct 22, 2024
b899624
Merge remote-tracking branch 'origin/develop' into chore.sf-refactor
Oct 29, 2024
8e4754a
fix: update factory to registry
Oct 29, 2024
d4aacf1
chore: remove redundant util file
Oct 29, 2024
21b65d0
chore: adding test cases
shrouti1507 Nov 5, 2024
d7bab66
Merge remote-tracking branch 'origin/develop' into chore.sf-refactor
Nov 5, 2024
622d2d0
fix: making server unavailable issue throttled
shrouti1507 Nov 8, 2024
d9caa7e
Merge branch 'develop' into chore.sf-refactor
shrouti1507 Nov 8, 2024
5f2c8c6
fix: success scenario converting to abort
Nov 8, 2024
e7c29fd
chore: remove commented line
Nov 8, 2024
2e072f0
fix: adding more proxy test coverage
shrouti1507 Nov 11, 2024
d320784
fix: correcting mock
shrouti1507 Nov 11, 2024
1abe194
chore: resolve conflict
shrouti1507 Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/v0/destinations/salesforce/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const DESTINATION = 'Salesforce';
const SALESFORCE_OAUTH_SANDBOX = 'salesforce_oauth_sandbox';
const OAUTH = 'oauth';
const LEGACY = 'legacy';
const SALESFORCE_OAUTH = 'salesforce_oauth';
const SALESFORCE = 'salesforce';

const mappingConfig = getMappingConfig(ConfigCategory, __dirname);

Expand All @@ -42,5 +44,7 @@ module.exports = {
DESTINATION,
OAUTH,
LEGACY,
SALESFORCE_OAUTH,
SALESFORCE_OAUTH_SANDBOX,
SALESFORCE,
};
19 changes: 11 additions & 8 deletions src/v0/destinations/salesforce/networkHandler.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
const { proxyRequest, prepareProxyRequest } = require('../../../adapters/network');
const { processAxiosResponse } = require('../../../adapters/utils/networkUtils');
const { LEGACY } = require('./config');
const { salesforceResponseHandler } = require('./utils');
const { isHttpStatusSuccess } = require('../../util');
const { SALESFORCE } = require('./config');
const { default: salesforceRegistry } = require('../../util/salesforce/registry');

const responseHandler = (responseParams) => {
const { destinationResponse, destType, rudderJobMetadata } = responseParams;
const message = `Request for destination: ${destType} Processed Successfully`;
const { status } = destinationResponse;

salesforceResponseHandler(
destinationResponse,
'during Salesforce Response Handling',
rudderJobMetadata?.destInfo?.authKey,
LEGACY,
);
if (!isHttpStatusSuccess(status) && status >= 400) {
salesforceRegistry[SALESFORCE].errorResponseHandler(
destinationResponse,
'during Salesforce Response Handling',
rudderJobMetadata?.destInfo?.authKey,
);
}

// else successfully return status as 200, message and original destination response
return {
Expand Down
18 changes: 8 additions & 10 deletions src/v0/destinations/salesforce/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
generateErrorObject,
isHttpStatusSuccess,
} = require('../../util');
const { salesforceResponseHandler, collectAuthorizationInfo, getAuthHeader } = require('./utils');
const { handleHttpRequest } = require('../../../adapters/network');
const { JSON_MIME_TYPE } = require('../../util/constant');
const { default: salesforceRegistry } = require('../../util/salesforce/registry');

// Basic response builder
// We pass the parameterMap with any processing-specific key-value pre-populated
Expand Down Expand Up @@ -92,7 +92,7 @@
response.method = defaultPostRequestConfig.requestMethod;
response.headers = {
'Content-Type': JSON_MIME_TYPE,
...getAuthHeader({ authorizationFlow, authorizationData }),
...salesforceRegistry[authorizationFlow].getAuthHeader(authorizationData),
};
response.body.JSON = removeUndefinedValues(rawPayload);
response.endpoint = targetEndpoint;
Expand All @@ -114,7 +114,7 @@
'get',
objSearchUrl,
{
headers: getAuthHeader({ authorizationFlow, authorizationData }),
headers: salesforceRegistry[authorizationFlow].getAuthHeader(authorizationData),
},
{
metadata,
Expand All @@ -126,11 +126,10 @@
},
);
if (!isHttpStatusSuccess(processedsfSearchResponse.status)) {
salesforceResponseHandler(
salesforceRegistry[authorizationFlow].errorResponseHandler(

Check warning on line 129 in src/v0/destinations/salesforce/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/salesforce/transform.js#L129

Added line #L129 was not covered by tests
processedsfSearchResponse,
`:- SALESFORCE SEARCH BY ID`,
destination.ID,
authorizationFlow,
);
}
const searchRecord = processedsfSearchResponse.response?.searchRecords?.find(
Expand Down Expand Up @@ -234,7 +233,7 @@
'get',
leadQueryUrl,
{
headers: getAuthHeader({ authorizationFlow, authorizationData }),
headers: salesforceRegistry[authorizationFlow].getAuthHeader(authorizationData),
},
{
metadata,
Expand All @@ -247,11 +246,10 @@
);

if (!isHttpStatusSuccess(processedLeadQueryResponse.status)) {
salesforceResponseHandler(
salesforceRegistry[authorizationFlow].errorResponseHandler(

Check warning on line 249 in src/v0/destinations/salesforce/transform.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/salesforce/transform.js#L249

Added line #L249 was not covered by tests
processedLeadQueryResponse,
`:- during Lead Query`,
destination.ID,
authorizationFlow,
);
}

Expand Down Expand Up @@ -359,7 +357,7 @@
}

async function process(event) {
const authInfo = await collectAuthorizationInfo(event);
const authInfo = await salesforceRegistry.getAuthInfo(event);
const response = await processSingleMessage(
event,
authInfo.authorizationData,
Expand All @@ -371,7 +369,7 @@
const processRouterDest = async (inputs, reqMetadata) => {
let authInfo;
try {
authInfo = await collectAuthorizationInfo(inputs[0]);
authInfo = await salesforceRegistry.getAuthInfo(inputs[0]);
} catch (error) {
const errObj = generateErrorObject(error);
const respEvents = getErrorRespEvents(
Expand Down
208 changes: 0 additions & 208 deletions src/v0/destinations/salesforce/utils.js

This file was deleted.

22 changes: 12 additions & 10 deletions src/v0/destinations/salesforce_oauth/networkHandler.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
const { proxyRequest, prepareProxyRequest } = require('../../../adapters/network');
const { processAxiosResponse } = require('../../../adapters/utils/networkUtils');
const { OAUTH } = require('../salesforce/config');
const { salesforceResponseHandler } = require('../salesforce/utils');
const { isHttpStatusSuccess } = require('../../util');
const { SALESFORCE_OAUTH } = require('../salesforce/config');
const { default: salesforceRegistry } = require('../../util/salesforce/registry');

const responseHandler = (responseParams) => {
const { destinationResponse, destType, rudderJobMetadata } = responseParams;
const message = `Request for destination: ${destType} Processed Successfully`;
const { destinationResponse } = responseParams;
const message = `Request for destination: ${SALESFORCE_OAUTH} Processed Successfully`;
const { status } = destinationResponse;

salesforceResponseHandler(
destinationResponse,
'during Salesforce Response Handling',
rudderJobMetadata?.destInfo?.authKey,
OAUTH,
);
if (!isHttpStatusSuccess(status) && status >= 400) {
salesforceRegistry[SALESFORCE_OAUTH].errorResponseHandler(
destinationResponse,
`during ${SALESFORCE_OAUTH} Response Handling`,
);
}

// else successfully return status as 200, message and original destination response
return {
Expand Down
22 changes: 12 additions & 10 deletions src/v0/destinations/salesforce_oauth_sandbox/networkHandler.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
const { proxyRequest, prepareProxyRequest } = require('../../../adapters/network');
const { processAxiosResponse } = require('../../../adapters/utils/networkUtils');
const { OAUTH } = require('../salesforce/config');
const { salesforceResponseHandler } = require('../salesforce/utils');
const { SALESFORCE_OAUTH_SANDBOX } = require('../salesforce/config');
const { default: salesforceRegistry } = require('../../util/salesforce/registry');
const { isHttpStatusSuccess } = require('../../util');

const responseHandler = (responseParams) => {
const { destinationResponse, destType, rudderJobMetadata } = responseParams;
const message = `Request for destination: ${destType} Processed Successfully`;
const { destinationResponse } = responseParams;
const message = `Request for destination: ${SALESFORCE_OAUTH_SANDBOX} Processed Successfully`;
const { status } = destinationResponse;

salesforceResponseHandler(
destinationResponse,
'during Salesforce Response Handling',
rudderJobMetadata?.destInfo?.authKey,
OAUTH,
);
if (!isHttpStatusSuccess(status) && status >= 400) {
salesforceRegistry[SALESFORCE_OAUTH_SANDBOX].errorResponseHandler(
destinationResponse,
`during ${SALESFORCE_OAUTH_SANDBOX} Response Handling`,
);
}

// else successfully return status as 200, message and original destination response
return {
Expand Down
Loading
Loading