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: iterable EUDC #3828

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
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
48 changes: 33 additions & 15 deletions src/v0/destinations/iterable/config.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
const { getMappingConfig } = require('../../util');

const BASE_URL = 'https://api.iterable.com/api/';
const BASE_URL = {
USDC: 'https://api.iterable.com/api/',
EUDC: 'https://api.eu.iterable.com/api/',
};

const ConfigCategory = {
IDENTIFY_BROWSER: {
name: 'IterableRegisterBrowserTokenConfig',
action: 'identifyBrowser',
endpoint: `${BASE_URL}users/registerBrowserToken`,
endpoint: `users/registerBrowserToken`,
},
IDENTIFY_DEVICE: {
name: 'IterableRegisterDeviceTokenConfig',
action: 'identifyDevice',
endpoint: `${BASE_URL}users/registerDeviceToken`,
endpoint: `users/registerDeviceToken`,
},
IDENTIFY: {
name: 'IterableIdentifyConfig',
action: 'identify',
endpoint: `${BASE_URL}users/update`,
endpoint: `users/update`,
},
PAGE: {
name: 'IterablePageConfig',
action: 'page',
endpoint: `${BASE_URL}events/track`,
endpoint: `events/track`,
},
SCREEN: {
name: 'IterablePageConfig',
action: 'screen',
endpoint: `${BASE_URL}events/track`,
endpoint: `events/track`,
},
TRACK: {
name: 'IterableTrackConfig',
action: 'track',
endpoint: `${BASE_URL}events/track`,
endpoint: `events/track`,
},
TRACK_PURCHASE: {
name: 'IterableTrackPurchaseConfig',
action: 'trackPurchase',
endpoint: `${BASE_URL}commerce/trackPurchase`,
endpoint: `commerce/trackPurchase`,
},
PRODUCT: {
name: 'IterableProductConfig',
Expand All @@ -46,7 +49,7 @@ const ConfigCategory = {
UPDATE_CART: {
name: 'IterableProductConfig',
action: 'updateCart',
endpoint: `${BASE_URL}commerce/updateCart`,
endpoint: `commerce/updateCart`,
},
DEVICE: {
name: 'IterableDeviceConfig',
Expand All @@ -56,30 +59,45 @@ const ConfigCategory = {
ALIAS: {
name: 'IterableAliasConfig',
action: 'alias',
endpoint: `${BASE_URL}users/updateEmail`,
endpoint: `users/updateEmail`,
},
CATALOG: {
name: 'IterableCatalogConfig',
action: 'catalogs',
endpoint: `${BASE_URL}catalogs`,
endpoint: `catalogs`,
},
};

const mappingConfig = getMappingConfig(ConfigCategory, __dirname);

// Function to construct endpoint based on the selected data center
const constructEndpoint = (dataCenter, category) => {
const baseUrl = BASE_URL[dataCenter] || BASE_URL.USDC; // Default to USDC if not found
return `${baseUrl}${category.endpoint}`;
};

// Function to get the batch endpoints based on the selected data center
const getBatchEndpoints = (dataCenter) => {
const baseUrl = BASE_URL[dataCenter];
const identifyEndpoint = `${baseUrl}users/bulkUpdate`;
const trackEndpoint = `${baseUrl}events/trackBulk`;
aanshi07 marked this conversation as resolved.
Show resolved Hide resolved
return {
IDENTIFY_BATCH_ENDPOINT: identifyEndpoint,
TRACK_BATCH_ENDPOINT: trackEndpoint,
};
};

const IDENTIFY_MAX_BATCH_SIZE = 1000;
const IDENTIFY_MAX_BODY_SIZE_IN_BYTES = 4000000;
const IDENTIFY_BATCH_ENDPOINT = 'https://api.iterable.com/api/users/bulkUpdate';

const TRACK_MAX_BATCH_SIZE = 8000;
const TRACK_BATCH_ENDPOINT = 'https://api.iterable.com/api/events/trackBulk';

module.exports = {
mappingConfig,
ConfigCategory,
TRACK_BATCH_ENDPOINT,
constructEndpoint,
getBatchEndpoints,
TRACK_MAX_BATCH_SIZE,
IDENTIFY_MAX_BATCH_SIZE,
IDENTIFY_BATCH_ENDPOINT,
IDENTIFY_MAX_BODY_SIZE_IN_BYTES,
};
17 changes: 9 additions & 8 deletions src/v0/destinations/iterable/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
filterEventsAndPrepareBatchRequests,
registerDeviceTokenEventPayloadBuilder,
registerBrowserTokenEventPayloadBuilder,
getCategoryWithEndpoint,
} = require('./util');
const {
constructPayload,
Expand Down Expand Up @@ -120,7 +121,7 @@ const responseBuilderForRegisterDeviceOrBrowserTokenEvents = (message, destinati
* @param {*} message
* @returns
*/
const getCategory = (messageType, message) => {
const getCategory = (messageType, message, dataCenter) => {
const eventType = messageType.toLowerCase();
aanshi07 marked this conversation as resolved.
Show resolved Hide resolved

switch (eventType) {
Expand All @@ -129,17 +130,17 @@ const getCategory = (messageType, message) => {
get(message, MappedToDestinationKey) &&
getDestinationExternalIDInfoForRetl(message, 'ITERABLE').objectType !== 'users'
) {
return ConfigCategory.CATALOG;
return getCategoryWithEndpoint(ConfigCategory.CATALOG, dataCenter);
}
return ConfigCategory.IDENTIFY;
return getCategoryWithEndpoint(ConfigCategory.IDENTIFY, dataCenter);
case EventType.PAGE:
return ConfigCategory.PAGE;
return getCategoryWithEndpoint(ConfigCategory.PAGE, dataCenter);
case EventType.SCREEN:
return ConfigCategory.SCREEN;
return getCategoryWithEndpoint(ConfigCategory.SCREEN, dataCenter);
case EventType.TRACK:
return getCategoryUsingEventName(message);
return getCategoryUsingEventName(message, dataCenter);
case EventType.ALIAS:
return ConfigCategory.ALIAS;
return getCategoryWithEndpoint(ConfigCategory.ALIAS, dataCenter);
default:
throw new InstrumentationError(`Message type ${eventType} not supported`);
}
Expand All @@ -151,7 +152,7 @@ const process = (event) => {
throw new InstrumentationError('Event type is required');
}
const messageType = message.type.toLowerCase();
const category = getCategory(messageType, message);
const category = getCategory(messageType, message, destination.Config.dataCenter);
const response = responseBuilder(message, category, destination);

if (hasMultipleResponses(message, category, destination.Config)) {
Expand Down
27 changes: 17 additions & 10 deletions src/v0/destinations/iterable/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
ConfigCategory,
mappingConfig,
TRACK_MAX_BATCH_SIZE,
TRACK_BATCH_ENDPOINT,
IDENTIFY_MAX_BATCH_SIZE,
IDENTIFY_BATCH_ENDPOINT,
IDENTIFY_MAX_BODY_SIZE_IN_BYTES,
constructEndpoint,
getBatchEndpoints,
} = require('./config');
const { JSON_MIME_TYPE } = require('../../util/constant');
const { EventType, MappedToDestinationKey } = require('../../../constants');
Expand Down Expand Up @@ -88,25 +88,31 @@
return isIdentifyEvent && isIdentifyCategory && hasToken && hasRegisterDeviceOrBrowserKey;
};

const getCategoryWithEndpoint = (categoryConfig, dataCenter) => {
const category = { ...categoryConfig }; // Create a copy of the category
category.endpoint = constructEndpoint(dataCenter, category); // Set the correct endpoint
return category; // Return the updated category
};
aanshi07 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns category value
* @param {*} message
* @returns
*/
const getCategoryUsingEventName = (message) => {
const getCategoryUsingEventName = (message, dataCenter) => {
let { event } = message;
if (typeof event === 'string') {
event = event.toLowerCase();
}

switch (event) {
case 'order completed':
return ConfigCategory.TRACK_PURCHASE;
return getCategoryWithEndpoint(ConfigCategory.TRACK_PURCHASE, dataCenter);
case 'product added':
case 'product removed':
return ConfigCategory.UPDATE_CART;
return getCategoryWithEndpoint(ConfigCategory.UPDATE_CART, dataCenter);
default:
return ConfigCategory.TRACK;
return getCategoryWithEndpoint(ConfigCategory.TRACK, dataCenter);
}
};

Expand Down Expand Up @@ -444,8 +450,8 @@
batchEventResponse.batchedRequest.body.JSON = { users: batch.users };

const { destination, metadata, nonBatchedRequests } = batch;
const { apiKey } = destination.Config;

const { apiKey, dataCenter } = destination.Config;
const { IDENTIFY_BATCH_ENDPOINT } = getBatchEndpoints(dataCenter);

Check warning on line 454 in src/v0/destinations/iterable/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/iterable/util.js#L453-L454

Added lines #L453 - L454 were not covered by tests
const batchedResponse = combineBatchedAndNonBatchedEvents(
apiKey,
metadata,
Expand Down Expand Up @@ -552,8 +558,8 @@
const metadata = [];

const { destination } = chunk[0];
const { apiKey } = destination.Config;

const { apiKey, dataCenter } = destination.Config;
const { TRACK_BATCH_ENDPOINT } = getBatchEndpoints(dataCenter);
chunk.forEach((event) => {
metadata.push(event.metadata);
events.push(get(event, `${MESSAGE_JSON_PATH}`));
Expand Down Expand Up @@ -753,4 +759,5 @@
filterEventsAndPrepareBatchRequests,
registerDeviceTokenEventPayloadBuilder,
registerBrowserTokenEventPayloadBuilder,
getCategoryWithEndpoint,
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { generateMetadata, transformResultBuilder } from './../../../testUtils';
import {
generateMetadata,
overrideDestination,
transformResultBuilder,
} from './../../../testUtils';
import { Destination } from '../../../../../src/types';
import { ProcessorTestData } from '../../../testTypes';

Expand All @@ -15,6 +19,7 @@ const destination: Destination = {
Transformations: [],
Config: {
apiKey: 'testApiKey',
dataCenter: 'USDC',
preferUserId: false,
trackAllPages: true,
trackNamedPages: false,
Expand Down Expand Up @@ -94,4 +99,56 @@ export const aliasTestData: ProcessorTestData[] = [
},
},
},
{
id: 'iterable-alias-test-1',
name: 'iterable',
description: 'Alias call with dataCenter as EUDC',
scenario: 'Business',
successCriteria:
'Response should contain status code 200 and it should contain update email payload',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
destination: overrideDestination(destination, { dataCenter: 'EUDC' }),
message: {
anonymousId: 'anonId',
userId: '[email protected]',
previousId: '[email protected]',
name: 'ApplicationLoaded',
context: {},
properties,
type: 'alias',
sentAt,
originalTimestamp,
},
metadata: generateMetadata(1),
},
],
},
},
output: {
response: {
status: 200,
body: [
{
output: transformResultBuilder({
userId: '',
headers,
endpoint: 'https://api.eu.iterable.com/api/users/updateEmail',
JSON: {
currentEmail: '[email protected]',
newEmail: '[email protected]',
},
}),
statusCode: 200,
metadata: generateMetadata(1),
},
],
},
},
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
generateMetadata,
transformResultBuilder,
generateIndentifyPayload,
overrideDestination,
} from './../../../testUtils';
import { Destination } from '../../../../../src/types';
import { ProcessorTestData } from '../../../testTypes';
Expand All @@ -19,6 +20,7 @@ const destination: Destination = {
Transformations: [],
Config: {
apiKey: 'testApiKey',
dataCenter: 'USDC',
preferUserId: false,
trackAllPages: true,
trackNamedPages: false,
Expand Down Expand Up @@ -55,6 +57,7 @@ const sentAt = '2020-08-28T16:26:16.473Z';
const originalTimestamp = '2020-08-28T16:26:06.468Z';

const updateUserEndpoint = 'https://api.iterable.com/api/users/update';
const updateUserEndpointEUDC = 'https://api.eu.iterable.com/api/users/update';

export const identifyTestData: ProcessorTestData[] = [
{
Expand Down Expand Up @@ -404,4 +407,58 @@ export const identifyTestData: ProcessorTestData[] = [
},
},
},
{
id: 'iterable-identify-test-7',
name: 'iterable',
description: 'Indentify call to update user in iterable with EUDC dataCenter',
scenario: 'Business',
successCriteria:
'Response should contain status code 200 and it should contain update user payload with all user traits and updateUserEndpointEUDC',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
destination: overrideDestination(destination, { dataCenter: 'EUDC' }),
message: {
anonymousId,
context: {
traits: user1Traits,
},
traits: user1Traits,
type: 'identify',
sentAt,
originalTimestamp,
},
metadata: generateMetadata(1),
},
],
},
},
output: {
response: {
status: 200,
body: [
{
output: transformResultBuilder({
userId: '',
headers,
endpoint: updateUserEndpointEUDC,
JSON: {
email: user1Traits.email,
userId: anonymousId,
dataFields: user1Traits,
preferUserId: false,
mergeNestedObjects: true,
},
}),
statusCode: 200,
metadata: generateMetadata(1),
},
],
},
},
},
];
Loading
Loading