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

refactor: deprecate mixpanel /track endpoint #2833

Merged
merged 6 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 0 additions & 2 deletions src/v0/destinations/mp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const MP_IDENTIFY_EXCLUSION_LIST = [
];

const GEO_SOURCE_ALLOWED_VALUES = [null, 'reverse_geocoding'];
const TRACK_MAX_BATCH_SIZE = 50;
const IMPORT_MAX_BATCH_SIZE = 2000;
const ENGAGE_MAX_BATCH_SIZE = 2000;
const GROUPS_MAX_BATCH_SIZE = 200;
Expand All @@ -68,7 +67,6 @@ module.exports = {
MP_IDENTIFY_EXCLUSION_LIST,
getCreateDeletionTaskEndpoint,
DISTINCT_ID_MAX_BATCH_SIZE,
TRACK_MAX_BATCH_SIZE,
IMPORT_MAX_BATCH_SIZE,
ENGAGE_MAX_BATCH_SIZE,
GROUPS_MAX_BATCH_SIZE,
Expand Down
63 changes: 22 additions & 41 deletions src/v0/destinations/mp/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const {
BASE_ENDPOINT,
BASE_ENDPOINT_EU,
IMPORT_MAX_BATCH_SIZE,
TRACK_MAX_BATCH_SIZE,
ENGAGE_MAX_BATCH_SIZE,
GROUPS_MAX_BATCH_SIZE,
} = require('./config');
Expand All @@ -46,21 +45,19 @@ const mPEventPropertiesConfigJson = mappingConfig[ConfigCategory.EVENT_PROPERTIE
const setImportCredentials = (destConfig) => {
const endpoint =
destConfig.dataResidency === 'eu' ? `${BASE_ENDPOINT_EU}/import/` : `${BASE_ENDPOINT}/import/`;
const headers = { 'Content-Type': 'application/json' };
const params = { strict: destConfig.strictMode ? 1 : 0 };
const { apiSecret, serviceAccountUserName, serviceAccountSecret, projectId } = destConfig;
if (apiSecret) {
headers.Authorization = `Basic ${base64Convertor(`${apiSecret}:`)}`;
} else if (serviceAccountUserName && serviceAccountSecret && projectId) {
headers.Authorization = `Basic ${base64Convertor(
`${serviceAccountUserName}:${serviceAccountSecret}`,
)}`;
const { serviceAccountUserName, serviceAccountSecret, projectId, token } = destConfig;
Gauravudia marked this conversation as resolved.
Show resolved Hide resolved
let credentials;
if (serviceAccountUserName && serviceAccountSecret && projectId) {
credentials = `${serviceAccountUserName}:${serviceAccountSecret}`;
params.projectId = projectId;
} else {
throw new InstrumentationError(
'Event timestamp is older than 5 days and no API secret or service account credentials (i.e. username, secret and projectId) are provided in destination configuration',
);
credentials = `${token}:`;
}
const headers = {
'Content-Type': 'application/json',
Authorization: `Basic ${base64Convertor(credentials)}`,
};
return { endpoint, headers, params };
};

Expand All @@ -69,35 +66,25 @@ const responseBuilderSimple = (payload, message, eventType, destConfig) => {
response.method = defaultPostRequestConfig.requestMethod;
response.userId = message.userId || message.anonymousId;
response.body.JSON_ARRAY = { batch: JSON.stringify([removeUndefinedValues(payload)]) };
const { apiSecret, serviceAccountUserName, serviceAccountSecret, projectId, dataResidency } =
destConfig;
const { dataResidency } = destConfig;
const duration = getTimeDifference(message.timestamp);
switch (eventType) {
case EventType.ALIAS:
case EventType.TRACK:
case EventType.SCREEN:
case EventType.PAGE:
if (
!apiSecret &&
!(serviceAccountUserName && serviceAccountSecret && projectId) &&
duration.days <= 5
) {
response.endpoint =
dataResidency === 'eu' ? `${BASE_ENDPOINT_EU}/track/` : `${BASE_ENDPOINT}/track/`;
response.headers = {};
} else if (duration.years > 5) {
case EventType.PAGE: {
krishna2020 marked this conversation as resolved.
Show resolved Hide resolved
if (duration.years > 5) {
throw new InstrumentationError('Event timestamp should be within last 5 years');
} else {
const credentials = setImportCredentials(destConfig);
response.endpoint = credentials.endpoint;
response.headers = credentials.headers;
response.params = {
project_id: credentials.params?.projectId,
strict: credentials.params.strict,
};
break;
}
const credentials = setImportCredentials(destConfig);
response.endpoint = credentials.endpoint;
response.headers = credentials.headers;
response.params = {
project_id: credentials.params?.projectId,
strict: credentials.params.strict,
};
break;
}
case 'merge':
// eslint-disable-next-line no-case-declarations
const credentials = setImportCredentials(destConfig);
Expand Down Expand Up @@ -492,19 +479,13 @@ const processRouterDest = async (inputs, reqMetadata) => {
);

transformedPayloads = lodash.flatMap(transformedPayloads);
const { engageEvents, groupsEvents, trackEvents, importEvents, batchErrorRespList } =
const { engageEvents, groupsEvents, importEvents, batchErrorRespList } =
groupEventsByEndpoint(transformedPayloads);

const engageRespList = batchEvents(engageEvents, ENGAGE_MAX_BATCH_SIZE, reqMetadata);
const groupsRespList = batchEvents(groupsEvents, GROUPS_MAX_BATCH_SIZE, reqMetadata);
const trackRespList = batchEvents(trackEvents, TRACK_MAX_BATCH_SIZE, reqMetadata);
const importRespList = batchEvents(importEvents, IMPORT_MAX_BATCH_SIZE, reqMetadata);
const batchSuccessRespList = [
...engageRespList,
...groupsRespList,
...trackRespList,
...importRespList,
];
const batchSuccessRespList = [...engageRespList, ...groupsRespList, ...importRespList];

return [...batchSuccessRespList, ...batchErrorRespList];
}),
Expand Down
2 changes: 0 additions & 2 deletions src/v0/destinations/mp/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ const groupEventsByEndpoint = (events) => {
const eventMap = {
engage: [],
groups: [],
track: [],
import: [],
};
const batchErrorRespList = [];
Expand All @@ -240,7 +239,6 @@ const groupEventsByEndpoint = (events) => {
return {
engageEvents: eventMap.engage,
groupsEvents: eventMap.groups,
trackEvents: eventMap.track,
importEvents: eventMap.import,
batchErrorRespList,
};
Expand Down
43 changes: 7 additions & 36 deletions src/v0/destinations/mp/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('Mixpanel utils test', () => {
expect(result).toEqual({
engageEvents: [],
groupsEvents: [],
trackEvents: [],
importEvents: [],
batchErrorRespList: [],
});
Expand Down Expand Up @@ -79,7 +78,7 @@ describe('Mixpanel utils test', () => {
},
{
message: {
endpoint: '/track',
endpoint: '/import',
body: {
JSON_ARRAY: {
batch: '[{prop:4}]',
Expand Down Expand Up @@ -140,10 +139,10 @@ describe('Mixpanel utils test', () => {
},
},
],
trackEvents: [
importEvents: [
{
message: {
endpoint: '/track',
endpoint: '/import',
body: {
JSON_ARRAY: {
batch: '[{prop:4}]',
Expand All @@ -152,8 +151,6 @@ describe('Mixpanel utils test', () => {
userId: 'user1',
},
},
],
importEvents: [
{
message: {
endpoint: '/import',
Expand Down Expand Up @@ -268,7 +265,7 @@ describe('Mixpanel utils test', () => {
const input = [
{
batchedRequest: {
endpoint: 'https://api.mixpanel.com/track/',
endpoint: 'https://api.mixpanel.com/import/',
},
metadata: [
{
Expand All @@ -295,19 +292,6 @@ describe('Mixpanel utils test', () => {
statusCode: 200,
destination: destinationMock,
},
{
batchedRequest: {
endpoint: 'https://api.mixpanel.com/track/',
},
metadata: [
{
jobId: 5,
},
],
batched: true,
statusCode: 200,
destination: destinationMock,
},
{
batchedRequest: {
endpoint: 'https://api.mixpanel.com/engage/',
Expand Down Expand Up @@ -343,7 +327,7 @@ describe('Mixpanel utils test', () => {
{
batchedRequest: [
{
endpoint: 'https://api.mixpanel.com/track/',
endpoint: 'https://api.mixpanel.com/import/',
},
{
endpoint: 'https://api.mixpanel.com/engage/',
Expand All @@ -367,19 +351,6 @@ describe('Mixpanel utils test', () => {
statusCode: 200,
destination: destinationMock,
},
{
batchedRequest: {
endpoint: 'https://api.mixpanel.com/track/',
},
metadata: [
{
jobId: 5,
},
],
batched: true,
statusCode: 200,
destination: destinationMock,
},
{
batchedRequest: {
endpoint: 'https://api.mixpanel.com/import/',
Expand All @@ -401,7 +372,7 @@ describe('Mixpanel utils test', () => {
const input = [
{
batchedRequest: {
endpoint: 'https://api.mixpanel.com/track/',
endpoint: 'https://api.mixpanel.com/import/',
},
metadata: [
{
Expand Down Expand Up @@ -446,7 +417,7 @@ describe('Mixpanel utils test', () => {
const expectedOutput = [
{
batchedRequest: {
endpoint: 'https://api.mixpanel.com/track/',
endpoint: 'https://api.mixpanel.com/import/',
},

metadata: [
Expand Down
2 changes: 1 addition & 1 deletion test/integrations/destinations/mp/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const defaultMockFns = () => {
const sampleDestination = {
Config: {
apiKey: 'dummyApiKey',
token: 'dummyApiKey',
token: 'test_api_token',
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved
prefixProperties: true,
useNativeSDK: false,
},
Expand Down
Loading
Loading