Skip to content

Commit

Permalink
chore: temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Feb 26, 2024
1 parent 3ce5ca6 commit e741e31
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 119 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const { getMappingConfig } = require('../../../../v0/util');
import { getMappingConfig } from '../../../../v0/util';

const ConfigCategories = {
interface ConfigCategory {
type: string;
name: string;
}

const ConfigCategories: { [key: string]: ConfigCategory } = {
GENERAL: {
type: 'general',
name: 'generalPayloadMapping',
Expand All @@ -22,8 +27,10 @@ const ConfigCategories = {
name: 'pageMapping',
},
};

const MAX_BATCH_SIZE = 200; // Maximum number of events to send in a single batch
const mappingConfig = getMappingConfig(ConfigCategories, __dirname);
const batchEndpoint =
'https://experience.ninetailed.co/v2/organizations/{{organisationId}}/environments/{{environment}}/events';
module.exports = { ConfigCategories, mappingConfig, batchEndpoint, MAX_BATCH_SIZE };

export default { ConfigCategories, mappingConfig, batchEndpoint, MAX_BATCH_SIZE };
7 changes: 4 additions & 3 deletions src/cdk/v2/destinations/ninetailed/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ bindings:
path: ../../../../v0/util
- name: removeUndefinedAndNullValues
path: ../../../../v0/util
- path: ./utils
- name: util
path: ./utils

steps:
- name: messageType
Expand All @@ -21,13 +22,13 @@ steps:
$.assertConfig(.destination.Config.environment, "Environment is not present. Aborting");
- name: preparePayload
template: |
const payload = $.constructFullPayload(.message);
const payload = util.constructFullPayload(.message);
$.context.payload = $.removeUndefinedAndNullValues(payload);
- name: buildResponse
template: |
const response = $.defaultRequestConfig();
response.body.JSON.events = [$.context.payload];
response.endpoint = $.getEndpoint(.destination.Config);
response.endpoint = util.getEndpoint(.destination.Config);
response.method = "POST";
response
4 changes: 1 addition & 3 deletions src/cdk/v2/destinations/ninetailed/rtWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
bindings:
- path: ./config
- name: handleRtTfSingleEventError
path: ../../../../v0/util/index
- path: ./utils
exportAll: true
steps:
- name: validateInput
template: |
console.log('router input: ', ^)
$.assert(Array.isArray(^) && ^.length > 0, "Invalid event array")
- name: transform
Expand All @@ -29,7 +28,6 @@ steps:
- name: batchSuccessfulEvents
description: Batches the successfulEvents
template: |
console.log('successBatch: ', $.outputs.successfulEvents)
let batches = $.chunk($.outputs.successfulEvents, $.MAX_BATCH_SIZE);
batches@batch.({
"batchedRequest": {
Expand Down
35 changes: 26 additions & 9 deletions src/cdk/v2/destinations/ninetailed/utils.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
const { mappingConfig, ConfigCategories, batchEndpoint } = require('./config');
// eslint-disable-next-line import/no-import-module-exports
import config from './config';

const { constructPayload } = require('../../../../v0/util');

/**
* This fucntion constructs payloads based upon mappingConfig for all calls
* This fucntion constructs payloads based upon config.mappingConfig for all calls
* We build context as it has some specific payloads with default values so just breaking them down
* @param {*} message
* @returns
*/
const constructFullPayload = (message) => {
const context = constructPayload(message, mappingConfig[ConfigCategories.CONTEXT.name]);
let payload = constructPayload(message, mappingConfig[ConfigCategories.GENERAL.name]);
const context = constructPayload(
message?.context,
config.mappingConfig[config.ConfigCategories.CONTEXT.name],
);
const payload = constructPayload(
message,
config.mappingConfig[config.ConfigCategories.GENERAL.name],
);
let typeSpecifcPayload;
switch (message.type) {
case 'track':
typeSpecifcPayload = constructPayload(message, mappingConfig[ConfigCategories.TRACK.name]);
typeSpecifcPayload = constructPayload(
message,
config.mappingConfig[config.ConfigCategories.TRACK.name],
);
break;
case 'identify':
typeSpecifcPayload = constructPayload(message, mappingConfig[ConfigCategories.IDENTIFY.name]);
typeSpecifcPayload = constructPayload(
message,
config.mappingConfig[config.ConfigCategories.IDENTIFY.name],
);
break;
case 'page':
typeSpecifcPayload = constructPayload(message, mappingConfig[ConfigCategories.PAGE.name]);
typeSpecifcPayload = constructPayload(
message,
config.mappingConfig[config.ConfigCategories.PAGE.name],
);
break;
default:
break;
}
payload.context = context ;
payload.context = context;
return { ...payload, ...typeSpecifcPayload }; // merge base and type-specific payloads;
};

const getEndpoint = (Config) => {
const { organisationId, environment } = Config;
return batchEndpoint
return config.batchEndpoint
.replace('{{organisationId}}', organisationId)
.replace('{{environment}}', environment);
};
Expand Down
13 changes: 11 additions & 2 deletions test/integrations/destinations/ninetailed/commonConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,20 @@ export const commonOutput = {

export const endpoint =
'https://experience.ninetailed.co/v2/organizations/dummyOrganisationId/environments/main/events';
export const instrumentationErrorStatTags = {
export const routerInstrumentationErrorStatTags = {
destType: 'NINETAILED',
errorCategory: 'dataValidation',
errorType: 'instrumentation',
feature: 'router',
implementation: 'cdkV2',
module: 'destination',
}
};
export const processInstrumentationErrorStatTags = {
destType: 'NINETAILED',
errorCategory: 'dataValidation',
errorType: 'instrumentation',
feature: 'processor',
implementation: 'cdkV2',
module: 'destination',
destinationId: 'dummyDestId',
};
2 changes: 1 addition & 1 deletion test/integrations/destinations/ninetailed/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from '../../../../src/cdk/v2/destinations/ninetailed/config';

export const defaultMockFns = () => {
jest.replaceProperty(config, 'MAX_BATCH_SIZE', 2);
config.MAX_BATCH_SIZE = 20;
};
24 changes: 8 additions & 16 deletions test/integrations/destinations/ninetailed/processor/identify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { destination, traits, context, metadata, instrumentationErrorStatTags } from '../commonConfig';
import { destination, traits, commonInput, metadata, processInstrumentationErrorStatTags } from '../commonConfig';
import { transformResultBuilder } from '../../../testUtils';
export const identify = [
{
Expand All @@ -17,12 +17,9 @@ export const identify = [
destination,
message: {
type: 'identify',
context,
...commonInput,
userId: 'sajal12',
channel: 'mobile',
messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce',
traits: traits,
anonymousId: '9c6bd77ea9da3e68',
integrations: {
All: true,
},
Expand Down Expand Up @@ -88,11 +85,11 @@ export const identify = [
},
},
type: 'identify',
channel: 'mobile',
channel: 'web',
userId: 'sajal12',
messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce',
messageId: 'dummy_msg_id',
traits: traits,
anonymousId: '9c6bd77ea9da3e68',
anonymousId: 'anon_123',
originalTimestamp: '2021-01-25T15:32:56.409Z',
},
],
Expand Down Expand Up @@ -121,16 +118,11 @@ export const identify = [
{
destination,
message: {
context,
...commonInput,
type: 'identify',
channel: 'mobile',
messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce',
messageId: 'dummy_msg_id',
traits: traits,
anonymousId: '9c6bd77ea9da3e68',
integrations: {
All: true,
},
originalTimestamp: '2021-01-25T15:32:56.409Z',
},
metadata,
},
Expand All @@ -147,7 +139,7 @@ export const identify = [
metadata: {
destinationId: 'dummyDestId',
},
statTags: instrumentationErrorStatTags,
statTags: processInstrumentationErrorStatTags,
statusCode: 400,
},
],
Expand Down
10 changes: 5 additions & 5 deletions test/integrations/destinations/ninetailed/processor/page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { destination, context, commonProperties, metadata } from './commonConfig';
import { destination, context, commonProperties, metadata } from '../commonConfig';
import { transformResultBuilder } from '../../../testUtils';
export const page = [
{
Expand All @@ -21,9 +21,9 @@ export const page = [
event: 'product purchased',
userId: 'sajal12',
channel: 'mobile',
messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce',
messageId: 'dummy_msg_id',
properties: commonProperties,
anonymousId: '9c6bd77ea9da3e68',
anonymousId: 'anon_123',
integrations: {
All: true,
},
Expand Down Expand Up @@ -90,9 +90,9 @@ export const page = [
},
type: 'page',
channel: 'mobile',
messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce',
messageId: 'dummy_msg_id',
properties: commonProperties,
anonymousId: '9c6bd77ea9da3e68',
anonymousId: 'anon_123',
originalTimestamp: '2021-01-25T15:32:56.409Z',
},
],
Expand Down
14 changes: 7 additions & 7 deletions test/integrations/destinations/ninetailed/processor/track.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { destination, context, commonProperties, metadata } from './commonConfig';
import { destination, context, commonProperties, metadata } from '../commonConfig';
import { transformResultBuilder } from '../../../testUtils';
export const track = [
{
Expand Down Expand Up @@ -59,9 +59,9 @@ export const track = [
event: 'product purchased',
userId: 'sajal12',
channel: 'mobile',
messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce',
messageId: 'dummy_msg_id',
properties: commonProperties,
anonymousId: '9c6bd77ea9da3e68',
anonymousId: 'anon_123',
integrations: {
All: true,
},
Expand Down Expand Up @@ -129,9 +129,9 @@ export const track = [
type: 'track',
event: 'product purchased',
channel: 'mobile',
messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce',
messageId: 'dummy_msg_id',
properties: commonProperties,
anonymousId: '9c6bd77ea9da3e68',
anonymousId: 'anon_123',
originalTimestamp: '2021-01-25T15:32:56.409Z',
},
],
Expand Down Expand Up @@ -163,9 +163,9 @@ export const track = [
context,
type: 'track',
channel: 'mobile',
messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce',
messageId: 'dummy_msg_id',
properties: commonProperties,
anonymousId: '9c6bd77ea9da3e68',
anonymousId: 'anon_123',
integrations: {
All: true,
},
Expand Down
Loading

0 comments on commit e741e31

Please sign in to comment.