Skip to content

Commit

Permalink
feat: gaec migration
Browse files Browse the repository at this point in the history
  • Loading branch information
AASHISH MALIK committed Nov 4, 2024
1 parent ba694a5 commit bbe3849
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 167 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/* eslint-disable no-param-reassign */

const get = require('get-value');
const { cloneDeep, isNumber } = require('lodash');
const { InstrumentationError, ConfigurationError } = require('@rudderstack/integrations-lib');
const isString = require('lodash/isString');
const { cloneDeep } = require('lodash');
const {
InstrumentationError,
ConfigurationError,
isDefinedAndNotNull,
} = require('@rudderstack/integrations-lib');
const {
constructPayload,
defaultRequestConfig,
Expand Down Expand Up @@ -36,18 +39,14 @@ const updateMappingJson = (mapping) => {
const responseBuilder = async (metadata, message, { Config }, payload) => {
const response = defaultRequestConfig();
const { event } = message;
const { subAccount } = Config;
let { customerId, loginCustomerId } = Config;
if (isNumber(customerId)) {
customerId = customerId.toString();
}
if (isNumber(loginCustomerId)) {
loginCustomerId = loginCustomerId.toString();
}
if (!isString(customerId) || !isString(loginCustomerId)) {
throw new InstrumentationError('customerId and loginCustomerId should be a string or number');
if (isDefinedAndNotNull(Config.configData)) {
const configDetails = JSON.parse(Config.configData);
Config.customerId = configDetails.customerId;
if (configDetails.loginCustomerId) {
Config.loginCustomerId = configDetails.loginCustomerId;
}
}
const filteredCustomerId = removeHyphens(customerId);
const filteredCustomerId = removeHyphens(Config.customerId);
response.endpoint = `${BASE_ENDPOINT}/${filteredCustomerId}:uploadConversionAdjustments`;
response.body.JSON = payload;
const accessToken = getAccessToken(metadata, 'access_token');
Expand All @@ -57,12 +56,10 @@ const responseBuilder = async (metadata, message, { Config }, payload) => {
'developer-token': getValueFromMessage(metadata, 'secret.developer_token'),
};
response.params = { event, customerId: filteredCustomerId };
if (subAccount)
if (loginCustomerId) {
const filteredLoginCustomerId = removeHyphens(loginCustomerId);
response.headers['login-customer-id'] = filteredLoginCustomerId;
} else throw new ConfigurationError(`LoginCustomerId is required as subAccount is true.`);

if (Config.loginCustomerId) {
const filteredLoginCustomerId = removeHyphens(Config.loginCustomerId);
response.headers['login-customer-id'] = filteredLoginCustomerId;
}
return response;
};

Expand All @@ -71,8 +68,16 @@ const processTrackEvent = async (metadata, message, destination) => {
const { Config } = destination;
const { event } = message;
const { listOfConversions } = Config;
if (listOfConversions.some((i) => i.conversions === event)) {
flag = 1;
if (listOfConversions && listOfConversions.length > 0) {
if (typeof listOfConversions[0] === 'string') {
if (listOfConversions.some((i) => i === event)) {
flag = 1;
}
} else {
if (listOfConversions.some((i) => i.conversions === event)) {
flag = 1;
}
}
}
if (event === undefined || event === '' || flag === 0) {
throw new ConfigurationError(
Expand Down
Loading

0 comments on commit bbe3849

Please sign in to comment.