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 19, 2023
1 parent 4ac4234 commit 9f6ae10
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 = '';
if (processedResponseDrip?.response) {
errMsg = JSON.stringify(processedResponseDrip.response);
}
throw new AbortedError(`Error occurred while creating or updating user : ${errMsg}`);
};

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
) {
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 (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(
'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
) {
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);
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, {
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(processedResponseGs.status),
}, processedResponseGs.response);
throw new RetryableError(
'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
) {
let errMessage = '';
let errorStatus = 500;
if (processedResponseGs.response) {
errMessage = processedResponseGs.response.errorDesc;
errorStatus = processedResponseGs.status;
}
throw new NetworkError(
`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(
'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 };
}

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

/**
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 9f6ae10

Please sign in to comment.