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

fix: allowing traffic type dynamically for split.io #3425

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions src/v0/destinations/splitio/data/EventConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,17 @@
"type": "toFloat"
},
"required": false
},
{
"destKey": "trafficTypeName",
"sourceKeys": [
"traits.trafficTypeName",
"context.traits.trafficTypeName",
"properties.trafficTypeName"
],
Gauravudia marked this conversation as resolved.
Show resolved Hide resolved
"metadata": {
"type": "toString"
},
"required": false
}
]
8 changes: 7 additions & 1 deletion src/v0/destinations/splitio/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function prepareResponse(message, destination, category) {

let outputPayload = {};

// ref: https://docs.split.io/reference/events-overview
outputPayload = constructPayload(message, MAPPING_CONFIG[category.name]);
outputPayload.eventTypeId = outputPayload.eventTypeId.replace(/ /g, '_');
if (EVENT_TYPE_ID_REGEX.test(outputPayload.eventTypeId)) {
Expand Down Expand Up @@ -93,7 +94,12 @@ function prepareResponse(message, destination, category) {
if (isDefinedAndNotNullAndNotEmpty(environment)) {
outputPayload.environmentName = environment;
}
outputPayload.trafficTypeName = trafficType;

// in case traffic type could not be mapped from the input payloads, falls back to the UI configured default traffic type.
if (!isDefinedAndNotNullAndNotEmpty(outputPayload.trafficTypeName)) {
outputPayload.trafficTypeName = trafficType;
}

outputPayload.properties = removeUndefinedNullValuesAndEmptyObjectArray(
flattenJson(bufferProperty),
);
Expand Down
9 changes: 6 additions & 3 deletions test/integrations/destinations/splitio/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const data = [
Config: {
apiKey: 'abcde',
environment: 'staging',
trafficType: 'user',
trafficType: 'anonymous',
},
},
},
Expand Down Expand Up @@ -246,7 +246,7 @@ export const data = [
Config: {
apiKey: 'abcde',
environment: 'production',
trafficType: 'user',
trafficType: 'anonymous',
},
},
},
Expand Down Expand Up @@ -847,6 +847,9 @@ export const data = [
library: {
name: 'http',
},
traits: {
trafficTypeName: 'user',
},
},
type: 'identify',
timestamp: '2020-01-21T00:21:34.208Z',
Expand All @@ -858,7 +861,7 @@ export const data = [
Config: {
apiKey: 'abcde',
environment: 'staging',
trafficType: 'user',
trafficType: 'anonymous',
},
},
},
Expand Down
Loading