Skip to content

Commit

Permalink
refactor: moved transform.js code logic to rtWorkflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia committed Feb 1, 2024
1 parent 6e12754 commit 13fd161
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 60 deletions.
39 changes: 35 additions & 4 deletions src/cdk/v2/destinations/the_trade_desk/rtWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
bindings:
- name: processRouterDest
path: ./transform
- name: EventType
path: ../../../../constants
- name: processRecordInputs
path: ./transformRecord
- name: processConversionInputs
path: ./transformConversion
- name: handleRtTfSingleEventError
path: ../../../../v0/util/index
- name: InstrumentationError
path: '@rudderstack/integrations-lib'

steps:
- name: validateConfig
Expand All @@ -11,7 +19,30 @@ steps:
$.assertConfig(config.trackerId, "Tracking Tag ID is not present. Aborting")
config.ttlInDays ? $.assertConfig(config.ttlInDays >=0 && config.ttlInDays <= 180, "TTL is out of range. Allowed values are 0 to 180 days")
- name: processRouterDest
- name: validateInput
template: |
$.assert(Array.isArray(^) && ^.length > 0, "Invalid event array")
$.processRouterDest(^)
- name: processRecordEvents
template: |
$.processRecordInputs(^.{.message.type === $.EventType.RECORD}[], ^[0].destination)
- name: processConversionEvents
template: |
$.processConversionInputs(^.{.message.type === $.EventType.TRACK}[])
- name: failOtherEvents
template: |
const otherEvents = ^.{.message.type !== $.EventType.TRACK && .message.type !== $.EventType.RECORD}[]
let failedEvents = otherEvents.map(
function(event) {
const error = new $.InstrumentationError("Event type " + event.message.type + " is not supported");
$.handleRtTfSingleEventError(event, error, {})
}
)
failedEvents ?? []
- name: finalPayload
template: |
[...$.outputs.processRecordEvents, ...$.outputs.processConversionEvents, ...$.outputs.failOtherEvents]
41 changes: 0 additions & 41 deletions src/cdk/v2/destinations/the_trade_desk/transform.js

This file was deleted.

3 changes: 3 additions & 0 deletions src/cdk/v2/destinations/the_trade_desk/transformConversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ const processEvent = (message, destination) => {
const process = (event) => processEvent(event.message, event.destination);

const processConversionInputs = async (inputs, reqMetadata) => {
if (!inputs || inputs.length === 0) {
return [];
}
const respList = await simpleProcessRouterDest(inputs, process, reqMetadata);
return respList;
};
Expand Down
4 changes: 4 additions & 0 deletions src/cdk/v2/destinations/the_trade_desk/transformRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ const processRecordInputs = (inputs, destination) => {
const successMetadata = [];
const errorResponseList = [];

if (!inputs || inputs.length === 0) {
return [];
}

if (!Config.audienceId) {
const segmentNameError = new ConfigurationError(
'Segment name/Audience ID is not present. Aborting',
Expand Down
30 changes: 15 additions & 15 deletions test/integrations/destinations/the_trade_desk/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1750,21 +1750,6 @@ export const data = [
statusCode: 200,
destination: sampleDestination,
},
{
batched: false,
metadata: [{ jobId: 3 }],
statusCode: 400,
error: 'Event type "identify" is not supported',
statTags: {
errorCategory: 'dataValidation',
errorType: 'instrumentation',
destType: 'THE_TRADE_DESK',
module: 'destination',
implementation: 'cdkV2',
feature: 'router',
},
destination: sampleDestination,
},
{
batchedRequest: {
version: '1',
Expand Down Expand Up @@ -1803,6 +1788,21 @@ export const data = [
statusCode: 200,
destination: sampleDestination,
},
{
batched: false,
metadata: [{ jobId: 3 }],
statusCode: 400,
error: 'Event type identify is not supported',
statTags: {
errorCategory: 'dataValidation',
errorType: 'instrumentation',
destType: 'THE_TRADE_DESK',
module: 'destination',
implementation: 'cdkV2',
feature: 'router',
},
destination: sampleDestination,
},
],
},
},
Expand Down

0 comments on commit 13fd161

Please sign in to comment.