Skip to content

Commit

Permalink
fix: addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishmalik committed Dec 6, 2023
1 parent a676fc9 commit edadb6e
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 121 deletions.
38 changes: 19 additions & 19 deletions src/v0/destinations/drip/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,28 @@ const userExists = async (Config, id) => {
};

const createUpdateUser = async (finalpayload, Config, basicAuth) => {
const { processedResponse: processedResponseDrip } = await handleHttpRequest(
'post',
`${ENDPOINT}/v2/${Config.accountId}/subscribers`,
finalpayload,
{
headers: {
Authorization: `Basic ${basicAuth}`,
'Content-Type': JSON_MIME_TYPE,
},
const { processedResponse: processedResponseDrip } = await handleHttpRequest(
'post',
`${ENDPOINT}/v2/${Config.accountId}/subscribers`,
finalpayload,
{
headers: {
Authorization: `Basic ${basicAuth}`,
'Content-Type': JSON_MIME_TYPE,
},
{ destType: 'drip', feature: 'transformation' },
);
},
{ destType: 'drip', feature: 'transformation' },
);

if (processedResponseDrip) {
return processedResponseDrip.status === 200 || processedResponseDrip.status === 201;
}
if (processedResponseDrip) {
return processedResponseDrip.status === 200 || processedResponseDrip.status === 201;
}

let errMsg = '';
if (processedResponseDrip.response) {
errMsg = JSON.stringify(processedResponseDrip.response);
}
throw new AbortedError(`Error occurred while creating or updating user : ${errMsg}`);
let errMsg = '';

Check warning on line 84 in src/v0/destinations/drip/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/drip/util.js#L84

Added line #L84 was not covered by tests
if (processedResponseDrip?.response) {
errMsg = JSON.stringify(processedResponseDrip.response);

Check warning on line 86 in src/v0/destinations/drip/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/drip/util.js#L86

Added line #L86 was not covered by tests
}
throw new AbortedError(`Error occurred while creating or updating user : ${errMsg}`);

Check warning on line 88 in src/v0/destinations/drip/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/drip/util.js#L88

Added line #L88 was not covered by tests
};

const createList = (productList) => {
Expand Down
190 changes: 116 additions & 74 deletions src/v0/destinations/gainsight/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,112 +12,154 @@ const { handleHttpRequest } = require('../../../adapters/network');
const { isHttpStatusSuccess } = require('../../util');

const searchGroup = async (groupName, Config) => {
const { processedResponse: processedResponseGs } = await handleHttpRequest(
'post',
`${ENDPOINTS.groupSearchEndpoint(Config.domain)}`,
getLookupPayload(groupName),
{
headers: {
Accesskey: Config.accessKey,
'Content-Type': JSON_MIME_TYPE,
},
const { processedResponse: processedResponseGs } = await handleHttpRequest(
'post',
`${ENDPOINTS.groupSearchEndpoint(Config.domain)}`,
getLookupPayload(groupName),
{
headers: {
Accesskey: Config.accessKey,
'Content-Type': JSON_MIME_TYPE,
},
{ destType: 'gainsight', feature: 'transformation' },
);
},
{ destType: 'gainsight', feature: 'transformation' },
);

if (!isHttpStatusSuccess(processedResponseGs.status) && processedResponseGs >= 400 && processedResponseGs < 500) {
let errMessage = '';
let errorStatus = 500;
if (processedResponseGs.response) {
errMessage = processedResponseGs.response.errorDesc;
errorStatus = processedResponseGs.status;
}
throw new NetworkError(`failed to search group ${errMessage}`, errorStatus, {
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(errorStatus),
}, processedResponseGs.response);
if (
!isHttpStatusSuccess(processedResponseGs.status) &&
processedResponseGs.status >= 400 &&
processedResponseGs.status < 500

Check warning on line 31 in src/v0/destinations/gainsight/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight/util.js#L30-L31

Added lines #L30 - L31 were not covered by tests
) {
let errMessage = '';
let errorStatus = 500;
if (processedResponseGs.response) {
errMessage = processedResponseGs.response.errorDesc;
errorStatus = processedResponseGs.status;

Check warning on line 37 in src/v0/destinations/gainsight/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight/util.js#L36-L37

Added lines #L36 - L37 were not covered by tests
}
throw new NetworkError(

Check warning on line 39 in src/v0/destinations/gainsight/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight/util.js#L39

Added line #L39 was not covered by tests
`failed to search group ${errMessage}`,
errorStatus,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(errorStatus),
},
processedResponseGs.response,
);
}

if (processedResponseGs.status !== 200) {
throw new RetryableError('failed to search group', processedResponseGs.status, {
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(processedResponseGs.status),
}, processedResponseGs.response);
throw new RetryableError(

Check warning on line 50 in src/v0/destinations/gainsight/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight/util.js#L50

Added line #L50 was not covered by tests
'failed to search group',
processedResponseGs.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(processedResponseGs.status),
},
processedResponseGs.response,
);
}
return processedResponseGs.response;
};

const createGroup = async (payload, Config) => {
const { processedResponse: processedResponseGs } = await handleHttpRequest(
'post',
`${ENDPOINTS.groupCreateEndpoint(Config.domain)}`,
{
records: [payload],
const { processedResponse: processedResponseGs } = await handleHttpRequest(
'post',
`${ENDPOINTS.groupCreateEndpoint(Config.domain)}`,
{
records: [payload],
},
{
headers: {
Accesskey: Config.accessKey,
'Content-Type': JSON_MIME_TYPE,
},
{
headers: {
Accesskey: Config.accessKey,
'Content-Type': JSON_MIME_TYPE,
},
},
{ destType: 'gainsight', feature: 'transformation' },
);
},
{ destType: 'gainsight', feature: 'transformation' },
);

if (!isHttpStatusSuccess(processedResponseGs.status) && processedResponseGs >= 400 && processedResponseGs < 500) {
if (
!isHttpStatusSuccess(processedResponseGs.status) &&
processedResponseGs.status >= 400 &&
processedResponseGs.status < 500

Check warning on line 81 in src/v0/destinations/gainsight/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight/util.js#L80-L81

Added lines #L80 - L81 were not covered by tests
) {
let errMessage = '';
let errorStatus = 500;
if (processedResponseGs.response) {
errMessage = processedResponseGs.response.errorDesc;
errorStatus = processedResponseGs.status;

Check warning on line 87 in src/v0/destinations/gainsight/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight/util.js#L86-L87

Added lines #L86 - L87 were not covered by tests
}
throw new NetworkError(`failed to create group ${errMessage}`, errorStatus, {
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(errorStatus),
}, processedResponseGs.response);
throw new NetworkError(

Check warning on line 89 in src/v0/destinations/gainsight/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight/util.js#L89

Added line #L89 was not covered by tests
`failed to create group ${errMessage}`,
errorStatus,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(errorStatus),
},
processedResponseGs.response,
);
}

if (processedResponseGs.status !== 200) {
throw new RetryableError('failed to create group', processedResponseGs.status, {
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(processedResponseGs.status),
}, processedResponseGs.response);
throw new RetryableError(

Check warning on line 100 in src/v0/destinations/gainsight/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight/util.js#L100

Added line #L100 was not covered by tests
'failed to create group',
processedResponseGs.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(processedResponseGs.status),
},
processedResponseGs.response,
);
}
return processedResponseGs.response?.data?.records[0].Gsid;
};

const updateGroup = async (payload, Config) => {
const { processedResponse: processedResponseGs } = await handleHttpRequest(
'put',
`${ENDPOINTS.groupUpdateEndpoint(Config.domain)}`,
{
records: [payload],
const { processedResponse: processedResponseGs } = await handleHttpRequest(
'put',
`${ENDPOINTS.groupUpdateEndpoint(Config.domain)}`,
{
records: [payload],
},
{
headers: {
Accesskey: Config.accessKey,
'Content-Type': JSON_MIME_TYPE,
},
params: {
keys: 'Name',
},
},
{ destType: 'gainsight', feature: 'transformation' },
);

if (
!isHttpStatusSuccess(processedResponseGs.status) &&
processedResponseGs.status >= 400 &&
processedResponseGs.status < 500

Check warning on line 134 in src/v0/destinations/gainsight/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight/util.js#L133-L134

Added lines #L133 - L134 were not covered by tests
) {
let errMessage = '';
let errorStatus = 500;
if (processedResponseGs.response) {
errMessage = processedResponseGs.response.errorDesc;
errorStatus = processedResponseGs.status;

Check warning on line 140 in src/v0/destinations/gainsight/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight/util.js#L139-L140

Added lines #L139 - L140 were not covered by tests
}
throw new NetworkError(

Check warning on line 142 in src/v0/destinations/gainsight/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight/util.js#L142

Added line #L142 was not covered by tests
`failed to update group ${errMessage}`,
errorStatus,
{
headers: {
Accesskey: Config.accessKey,
'Content-Type': JSON_MIME_TYPE,
},
params: {
keys: 'Name',
},
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(errorStatus),
},
{ destType: 'gainsight', feature: 'transformation' },
processedResponseGs.response,
);
}

if (!isHttpStatusSuccess(processedResponseGs.status) && processedResponseGs >= 400 && processedResponseGs < 500) {
let errMessage = '';
let errorStatus = 500;
if (processedResponseGs.response) {
errMessage = processedResponseGs.response.errorDesc;
errorStatus = processedResponseGs.status;
}
throw new NetworkError(`failed to create group ${errMessage}`, errorStatus, {
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(errorStatus),
}, processedResponseGs.response);
}

if (processedResponseGs.status !== 200) {
throw new RetryableError('failed to create group', processedResponseGs.status, {
if (processedResponseGs.status !== 200) {
throw new RetryableError(

Check warning on line 153 in src/v0/destinations/gainsight/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight/util.js#L153

Added line #L153 was not covered by tests
'failed to update group',
processedResponseGs.status,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(processedResponseGs.status),
}, processedResponseGs.response);
}
return processedResponseGs.response?.data?.records[0].Gsid;
},
processedResponseGs.response,
);
}
return processedResponseGs.response?.data?.records[0].Gsid;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/v0/destinations/gainsight_px/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const updateAccount = async (accountId, payload, Config) => {
return { success: false, err: null };

Check warning on line 105 in src/v0/destinations/gainsight_px/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight_px/util.js#L105

Added line #L105 was not covered by tests
}

return handleErrorResponse(processedResponseGs.response, `error while updating account`, 400);
return handleErrorResponse(processedResponseGs, `error while updating account`, 400);

Check warning on line 108 in src/v0/destinations/gainsight_px/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight_px/util.js#L108

Added line #L108 was not covered by tests
};

/**
Expand Down
15 changes: 4 additions & 11 deletions src/v0/destinations/kustomer/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
const lodash = require('lodash');
const set = require('set-value');
const get = require('get-value');
const { NetworkError, AbortedError } = require('@rudderstack/integrations-lib');
const { NetworkError } = require('@rudderstack/integrations-lib');
const { DEFAULT_BASE_ENDPOINT } = require('./config');
const { getType, isDefinedAndNotNull, isObject, isHttpStatusSuccess } = require('../../util');
const { getType, isDefinedAndNotNull, isObject } = require('../../util');
const { getDynamicErrorType } = require('../../../adapters/utils/networkUtils');
const tags = require('../../util/tags');
const { handleHttpRequest } = require('../../../adapters/network');
Expand Down Expand Up @@ -101,7 +101,7 @@ const handleResponse = (response, status) => {
const { data } = response;
switch (status) {
case 200:
if (data.id) {
if (data?.id) {
return {
userExists: true,
targetUrl: `${DEFAULT_BASE_ENDPOINT}/v1/customers/${data.id}?replace=false`,
Expand Down Expand Up @@ -141,14 +141,7 @@ const fetchKustomer = async (url, destination) => {
{ destType: 'kustomer', feature: 'transformation' },
);

if (isHttpStatusSuccess(processedResponseGs.status)) {
return handleResponse(processedResponseGs.response, processedResponseGs.status);
}

if (!isHttpStatusSuccess(processedResponseGs.status)) {
return handleResponse(processedResponseGs.response, processedResponseGs.status);
}
throw new AbortedError(processedResponseGs);
return handleResponse(processedResponseGs.response, processedResponseGs.status);
};

module.exports = {
Expand Down
33 changes: 17 additions & 16 deletions src/v0/destinations/mailchimp/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const tags = require('../../util/tags');
const { JSON_MIME_TYPE } = require('../../util/constant');
const { handleHttpRequest } = require('../../../adapters/network');


const ADDRESS_MANDATORY_FIELDS = ['addr1', 'city', 'state', 'zip'];

const MAILCHIMP_IDENTIFY_EXCLUSION = [
Expand All @@ -44,8 +43,6 @@ const MAILCHIMP_IDENTIFY_EXCLUSION = [
'birthday',
];



/**
* Returns common endpoint for mailchimp
* @param {*} datacenterId <-- from webapp config
Expand Down Expand Up @@ -190,23 +187,27 @@ const checkIfMailExists = async (apiKey, datacenterId, audienceId, email) => {
const checkIfDoubleOptIn = async (apiKey, datacenterId, audienceId) => {
const url = `${getMailChimpBaseEndpoint(datacenterId, audienceId)}`;
const basicAuth = Buffer.from(`apiKey:${apiKey}`).toString('base64');
const { processedResponse: processedResponseMailChip } = await handleHttpRequest(
'get',
url,
const { processedResponse: processedResponseMailChip } = await handleHttpRequest(
'get',
url,
{
headers: {
Authorization: `Basic ${basicAuth}`,
},
},
{ destType: 'mailchimp', feature: 'transformation' },
);

if (!isHttpStatusSuccess(processedResponseMailChip.status)) {
throw new NetworkError(
'User does not have access to the requested operation',
processedResponseMailChip.status,
{
headers: {
Authorization: `Basic ${basicAuth}`,
},
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(processedResponseMailChip.status),
},
{ destType: 'mailchimp', feature: 'transformation' },
);
}

if (!isHttpStatusSuccess(processedResponseMailChip.status)) {
throw new NetworkError('User does not have access to the requested operation', processedResponseMailChip.status, {
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(processedResponseMailChip.status),
});
}

return !!processedResponseMailChip.response.double_optin;
};

Expand Down

0 comments on commit edadb6e

Please sign in to comment.