Skip to content

Commit

Permalink
feat: added support to eu/us2 datacenter for gainsight px destination (
Browse files Browse the repository at this point in the history
…#3871)

* feat: added support to eu/us2 datacenter for gainsight px destination

* fix: added unit test
  • Loading branch information
manish339k authored Nov 15, 2024
1 parent c51cfbb commit 12ac3de
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 16 deletions.
31 changes: 26 additions & 5 deletions src/v0/destinations/gainsight_px/config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
const { getMappingConfig } = require('../../util');

const BASE_ENDPOINT = 'https://api.aptrinsic.com/v1';
const ENDPOINTS = {
USERS_ENDPOINT: `${BASE_ENDPOINT}/users`,
CUSTOM_EVENTS_ENDPOINT: `${BASE_ENDPOINT}/events/custom`,
ACCOUNTS_ENDPOINT: `${BASE_ENDPOINT}/accounts`,
const BASE_EU_ENDPOINT = 'https://api-eu.aptrinsic.com/v1';
const BASE_US2_ENDPOINT = 'https://api-us2.aptrinsic.com/v1';

const getBaseEndpoint = (Config) => {
const { dataCenter } = Config;
switch (dataCenter) {
case 'EU':
return BASE_EU_ENDPOINT;
case 'US2':
return BASE_US2_ENDPOINT;
default:
return BASE_ENDPOINT;
}
};

const getUsersEndpoint = (Config) => `${getBaseEndpoint(Config)}/users`;

const getCustomEventsEndpoint = (Config) => `${getBaseEndpoint(Config)}/events/custom`;

const getAccountsEndpoint = (Config) => `${getBaseEndpoint(Config)}/accounts`;

const CONFIG_CATEGORIES = {
IDENTIFY: { type: 'identify', name: 'GainsightPX_Identify' },
TRACK: { type: 'track', name: 'GainsightPX_Track' },
Expand Down Expand Up @@ -79,10 +94,16 @@ const ACCOUNT_EXCLUSION_FIELDS = [
];

module.exports = {
ENDPOINTS,
USER_EXCLUSION_FIELDS,
ACCOUNT_EXCLUSION_FIELDS,
identifyMapping: MAPPING_CONFIG[CONFIG_CATEGORIES.IDENTIFY.name],
trackMapping: MAPPING_CONFIG[CONFIG_CATEGORIES.TRACK.name],
groupMapping: MAPPING_CONFIG[CONFIG_CATEGORIES.GROUP.name],
getUsersEndpoint,
getCustomEventsEndpoint,
getAccountsEndpoint,
BASE_ENDPOINT,
BASE_EU_ENDPOINT,
BASE_US2_ENDPOINT,
getBaseEndpoint,
};
27 changes: 27 additions & 0 deletions src/v0/destinations/gainsight_px/config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { BASE_ENDPOINT, BASE_EU_ENDPOINT, BASE_US2_ENDPOINT, getBaseEndpoint } = require('./config');

describe('getBaseEndpoint method test', () => {
it('Should return BASE_ENDPOINT when destination.Config.dataCenter is not "EU" or "US2"', () => {
const Config = {
dataCenter: 'US',
};
const result = getBaseEndpoint(Config);
expect(result).toBe(BASE_ENDPOINT);
});

it('Should return BASE_EU_ENDPOINT when destination.Config.dataCenter is "EU"', () => {
const Config = {
dataCenter: 'EU',
};
const result = getBaseEndpoint(Config);
expect(result).toBe(BASE_EU_ENDPOINT);
});

it('Should return BASE_US2_ENDPOINT when destination.Config.dataCenter is "US2"', () => {
const Config = {
dataCenter: 'US2',
};
const result = getBaseEndpoint(Config);
expect(result).toBe(BASE_US2_ENDPOINT);
});
});
13 changes: 7 additions & 6 deletions src/v0/destinations/gainsight_px/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ const {
formatEventProps,
} = require('./util');
const {
ENDPOINTS,
USER_EXCLUSION_FIELDS,
ACCOUNT_EXCLUSION_FIELDS,
trackMapping,
groupMapping,
identifyMapping,
getUsersEndpoint,
getCustomEventsEndpoint,
} = require('./config');
const { JSON_MIME_TYPE } = require('../../util/constant');

Expand Down Expand Up @@ -92,15 +93,15 @@ const identifyResponseBuilder = async (message, { Config }, metadata) => {
if (isUserPresent) {
// update user
response.method = defaultPutRequestConfig.requestMethod;
response.endpoint = `${ENDPOINTS.USERS_ENDPOINT}/${userId}`;
response.endpoint = `${getUsersEndpoint(Config)}/${userId}`;
response.body.JSON = removeUndefinedAndNullValues(payload);
return response;
}

// create new user
payload.identifyId = userId;
response.method = defaultPostRequestConfig.requestMethod;
response.endpoint = ENDPOINTS.USERS_ENDPOINT;
response.endpoint = getUsersEndpoint(Config);
response.body.JSON = removeUndefinedAndNullValues(payload);
return response;
};
Expand Down Expand Up @@ -162,7 +163,7 @@ const newGroupResponseBuilder = async (message, { Config }, metadata) => {
'X-APTRINSIC-API-KEY': Config.apiKey,
'Content-Type': JSON_MIME_TYPE,
};
response.endpoint = `${ENDPOINTS.USERS_ENDPOINT}/${userId}`;
response.endpoint = `${getUsersEndpoint(Config)}/${userId}`;
response.body.JSON = {
accountId: groupId,
};
Expand Down Expand Up @@ -230,7 +231,7 @@ const groupResponseBuilder = async (message, { Config }, metadata) => {
'X-APTRINSIC-API-KEY': Config.apiKey,
'Content-Type': JSON_MIME_TYPE,
};
response.endpoint = `${ENDPOINTS.USERS_ENDPOINT}/${userId}`;
response.endpoint = `${getUsersEndpoint(Config)}/${userId}`;
response.body.JSON = {
accountId: groupId,
};
Expand Down Expand Up @@ -271,7 +272,7 @@ const trackResponseBuilder = (message, { Config }) => {
'X-APTRINSIC-API-KEY': Config.apiKey,
'Content-Type': JSON_MIME_TYPE,
};
response.endpoint = ENDPOINTS.CUSTOM_EVENTS_ENDPOINT;
response.endpoint = getCustomEventsEndpoint(Config);
return response;
};

Expand Down
10 changes: 5 additions & 5 deletions src/v0/destinations/gainsight_px/util.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { NetworkError } = require('@rudderstack/integrations-lib');
const { ENDPOINTS } = require('./config');
const tags = require('../../util/tags');
const { getDynamicErrorType } = require('../../../adapters/utils/networkUtils');
const { JSON_MIME_TYPE } = require('../../util/constant');
const { handleHttpRequest } = require('../../../adapters/network');
const { getUsersEndpoint, getAccountsEndpoint } = require('./config');

const handleErrorResponse = (error, customErrMessage, expectedErrStatus, defaultStatus = 400) => {
let destResp;
Expand Down Expand Up @@ -38,10 +38,10 @@ const handleErrorResponse = (error, customErrMessage, expectedErrStatus, default
* @returns
*/
const objectExists = async (id, Config, objectType, metadata) => {
let url = `${ENDPOINTS.USERS_ENDPOINT}/${id}`;
let url = `${getUsersEndpoint(Config)}/${id}`;

if (objectType === 'account') {
url = `${ENDPOINTS.ACCOUNTS_ENDPOINT}/${id}`;
url = `${getAccountsEndpoint(Config)}/${id}`;
}
const { httpResponse: res } = await handleHttpRequest(
'get',
Expand Down Expand Up @@ -70,7 +70,7 @@ const objectExists = async (id, Config, objectType, metadata) => {
const createAccount = async (payload, Config, metadata) => {
const { httpResponse: res } = await handleHttpRequest(
'post',
ENDPOINTS.ACCOUNTS_ENDPOINT,
getAccountsEndpoint(Config),
payload,
{
headers: {
Expand All @@ -96,7 +96,7 @@ const createAccount = async (payload, Config, metadata) => {
const updateAccount = async (accountId, payload, Config, metadata) => {
const { httpResponse: res } = await handleHttpRequest(
'put',
`${ENDPOINTS.ACCOUNTS_ENDPOINT}/${accountId}`,
`${getAccountsEndpoint(Config)}/${accountId}`,
payload,
{
headers: {
Expand Down

0 comments on commit 12ac3de

Please sign in to comment.