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

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

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
27 changes: 22 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) => {
manish339k marked this conversation as resolved.
Show resolved Hide resolved
const { dataCenter } = Config;
switch (dataCenter) {
case 'EU':
return BASE_EU_ENDPOINT;
case 'US2':
return BASE_US2_ENDPOINT;

Check warning on line 13 in src/v0/destinations/gainsight_px/config.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/gainsight_px/config.js#L10-L13

Added lines #L10 - L13 were not covered by tests
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,12 @@
];

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,
};
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
Loading