Skip to content

Commit

Permalink
chore: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSudip committed Nov 7, 2024
1 parent d776d2a commit 47bd9bd
Show file tree
Hide file tree
Showing 17 changed files with 698 additions and 179 deletions.
2 changes: 1 addition & 1 deletion src/controllers/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class MiscController {
}

public static features(ctx: Context) {
ctx.body = MiscService.getFetaures();
ctx.body = MiscService.getFeatures();
ctx.status = 200;
return ctx;
}
Expand Down
106 changes: 0 additions & 106 deletions src/features.json

This file was deleted.

117 changes: 117 additions & 0 deletions src/features.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
interface FeaturesConfig {
routerTransform: Record<string, boolean>;
regulations: string[];
supportSourceTransformV1: boolean;
supportTransformerProxyV1: boolean;
upgradedToSourceTransformV2?: boolean;
}

const defaultFeaturesConfig: FeaturesConfig = {
routerTransform: {
ACTIVE_CAMPAIGN: true,
ALGOLIA: true,
CANDU: true,
DELIGHTED: true,
DRIP: true,
FB_CUSTOM_AUDIENCE: true,
GA: true,
GAINSIGHT: true,
GAINSIGHT_PX: true,
GOOGLESHEETS: true,
GOOGLE_ADWORDS_ENHANCED_CONVERSIONS: true,
GOOGLE_ADWORDS_REMARKETING_LISTS: true,
GOOGLE_ADWORDS_OFFLINE_CONVERSIONS: true,
HS: true,
ITERABLE: true,
KLAVIYO: true,
KUSTOMER: true,
MAILCHIMP: true,
MAILMODO: true,
MARKETO: true,
OMETRIA: true,
PARDOT: true,
PINTEREST_TAG: true,
PROFITWELL: true,
SALESFORCE: true,
SALESFORCE_OAUTH: true,
SALESFORCE_OAUTH_SANDBOX: true,
SFMC: true,
SNAPCHAT_CONVERSION: true,
TIKTOK_ADS: true,
TRENGO: true,
YAHOO_DSP: true,
CANNY: true,
LAMBDA: true,
WOOTRIC: true,
GOOGLE_CLOUD_FUNCTION: true,
BQSTREAM: true,
CLICKUP: true,
FRESHMARKETER: true,
FRESHSALES: true,
MONDAY: true,
CUSTIFY: true,
USER: true,
REFINER: true,
FACEBOOK_OFFLINE_CONVERSIONS: true,
MAILJET: true,
SNAPCHAT_CUSTOM_AUDIENCE: true,
MARKETO_STATIC_LIST: true,
CAMPAIGN_MANAGER: true,
SENDGRID: true,
SENDINBLUE: true,
ZENDESK: true,
MP: true,
TIKTOK_ADS_OFFLINE_EVENTS: true,
CRITEO_AUDIENCE: true,
CUSTOMERIO: true,
BRAZE: true,
OPTIMIZELY_FULLSTACK: true,
TWITTER_ADS: true,
CLEVERTAP: true,
ORTTO: true,
GLADLY: true,
ONE_SIGNAL: true,
TIKTOK_AUDIENCE: true,
REDDIT: true,
THE_TRADE_DESK: true,
INTERCOM: true,
NINETAILED: true,
KOALA: true,
LINKEDIN_ADS: true,
BLOOMREACH: true,
MOVABLE_INK: true,
EMARSYS: true,
KODDI: true,
WUNDERKIND: true,
CLICKSEND: true,
ZOHO: true,
CORDIAL: true,
X_AUDIENCE: true,
BLOOMREACH_CATALOG: true,
SMARTLY: true,
HTTP: true,
AMAZON_AUDIENCE: true,
INTERCOM_V2: true,
LINKEDIN_AUDIENCE: true,
},
regulations: [
'BRAZE',
'AM',
'INTERCOM',
'CLEVERTAP',
'AF',
'MP',
'GA',
'ITERABLE',
'ENGAGE',
'CUSTIFY',
'SENDGRID',
'SPRIG',
'EMARSYS',
],
supportSourceTransformV1: true,
supportTransformerProxyV1: true,
upgradedToSourceTransformV2: process.env.UPGRADED_TO_SOURCE_TRANSFORM_V2 === 'true' || false, // redundant but required to show that the default is false
};

export default defaultFeaturesConfig;
40 changes: 40 additions & 0 deletions src/services/__tests__/misc.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DestHandlerMap } from '../../constants/destinationCanonicalNames';
import defaultFeaturesConfig from '../../features';
import { MiscService } from '../misc';

describe('Misc tests', () => {
Expand All @@ -24,3 +25,42 @@ describe('Misc tests', () => {
);
});
});

describe('Misc | getFeatures', () => {
const originalEnv = process.env;

beforeEach(() => {
// Reset environment variables and module cache before each test
process.env = { ...originalEnv };
jest.resetModules();
});

afterAll(() => {
// Restore the original environment variables after all tests
process.env = originalEnv;
});

function getMiscService() {
// Re-import config and featuresService after environment variables are set
const { MiscService: miscService } = require('../misc');
return miscService;
}

it('should return the default configuration as a JSON string', () => {
const miscService = getMiscService();
const expectedConfig = JSON.stringify(defaultFeaturesConfig);
const result = miscService.getFeatures();
expect(result).toBe(expectedConfig);
});

it('should return configuration with upgradedToSourceTransformV2 overridden by environment variable', () => {
process.env.UPGRADED_TO_SOURCE_TRANSFORM_V2 = 'true';
const expectedConfig = {
...defaultFeaturesConfig,
upgradedToSourceTransformV2: true,
};
const miscService = getMiscService();
const result = miscService.getFeatures();
expect(result).toBe(JSON.stringify(expectedConfig));
});
});
8 changes: 3 additions & 5 deletions src/services/misc.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable global-require, import/no-dynamic-require */
import fs from 'fs';
import { Context } from 'koa';
import path from 'path';
import { DestHandlerMap } from '../constants/destinationCanonicalNames';
import { getCPUProfile, getHeapProfile } from '../middleware';
import { Metadata } from '../types';
import defaultFeaturesConfig from '../features';

export class MiscService {
public static getDestHandler(dest: string, version: string) {
Expand Down Expand Up @@ -62,9 +61,8 @@ export class MiscService {
return process.env.npm_package_version || 'Version Info not found';
}

public static getFetaures() {
const obj = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../features.json'), 'utf8'));
return JSON.stringify(obj);
public static getFeatures() {
return JSON.stringify(defaultFeaturesConfig);
}

public static async getCPUProfile(seconds: number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

const get = require('get-value');
const { cloneDeep, isNumber } = require('lodash');
const { InstrumentationError, ConfigurationError } = require('@rudderstack/integrations-lib');
const {
InstrumentationError,
ConfigurationError,
isDefinedAndNotNull,
} = require('@rudderstack/integrations-lib');
const isString = require('lodash/isString');
const {
constructPayload,
Expand All @@ -11,6 +15,7 @@ const {
removeHyphens,
simpleProcessRouterDest,
getAccessToken,
isDefined,
} = require('../../util');

const { trackMapping, BASE_ENDPOINT } = require('./config');
Expand Down Expand Up @@ -38,6 +43,16 @@ const responseBuilder = async (metadata, message, { Config }, payload) => {
const { event } = message;
const { subAccount } = Config;
let { customerId, loginCustomerId } = Config;
const { configData } = Config;

if (isDefinedAndNotNull(configData)) {
const configDetails = JSON.parse(configData);
customerId = configDetails.customerId;
if (isDefined(configDetails.loginCustomerId)) {
loginCustomerId = configDetails.loginCustomerId;
}
}

if (isNumber(customerId)) {
customerId = customerId.toString();
}
Expand All @@ -63,6 +78,11 @@ const responseBuilder = async (metadata, message, { Config }, payload) => {
response.headers['login-customer-id'] = filteredLoginCustomerId;
} else throw new ConfigurationError(`LoginCustomerId is required as subAccount is true.`);

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

return response;
};

Expand All @@ -71,8 +91,14 @@ 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.includes(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 47bd9bd

Please sign in to comment.