From 9bc0fd8efcee44871a190bd6cb9e89c5cf035ff8 Mon Sep 17 00:00:00 2001 From: Sudip Paul <67197965+ItsSudip@users.noreply.github.com> Date: Thu, 2 Nov 2023 19:31:33 +0530 Subject: [PATCH] feat: add new destination tiktok_audience (#2710) * feat: add new destination tiktok_audience * remove log * refactor code * chore: refactor workflows * add test cases * chore: refactore code * refactor code and add negative test case --------- Co-authored-by: Dilip Kola Co-authored-by: mihir-4116 Co-authored-by: Mihir Bhalala <77438541+mihir-4116@users.noreply.github.com> --- src/cdk/v2/bindings/default.js | 6 + .../v2/destinations/tiktok_audience/config.js | 9 + .../tiktok_audience/procWorkflow.yaml | 67 ++ .../tiktok_audience/rtWorkflow.yaml | 32 + src/features.json | 1 + .../tiktok_audience/processor/data.ts | 854 ++++++++++++++++++ .../tiktok_audience/router/data.ts | 833 +++++++++++++++++ 7 files changed, 1802 insertions(+) create mode 100644 src/cdk/v2/destinations/tiktok_audience/config.js create mode 100644 src/cdk/v2/destinations/tiktok_audience/procWorkflow.yaml create mode 100644 src/cdk/v2/destinations/tiktok_audience/rtWorkflow.yaml create mode 100644 test/integrations/destinations/tiktok_audience/processor/data.ts create mode 100644 test/integrations/destinations/tiktok_audience/router/data.ts diff --git a/src/cdk/v2/bindings/default.js b/src/cdk/v2/bindings/default.js index 0bba7210f0..b86b6d2b63 100644 --- a/src/cdk/v2/bindings/default.js +++ b/src/cdk/v2/bindings/default.js @@ -1,3 +1,4 @@ +const crypto = require('crypto'); const { InstrumentationError, ConfigurationError, @@ -47,7 +48,12 @@ function assertHttpResp(processedResponse, message) { } } +function MD5(data) { + return crypto.createHash('md5').update(data).digest('hex'); +} + module.exports = { + MD5, isValidEventType, assert, assertConfig, diff --git a/src/cdk/v2/destinations/tiktok_audience/config.js b/src/cdk/v2/destinations/tiktok_audience/config.js new file mode 100644 index 0000000000..853f372505 --- /dev/null +++ b/src/cdk/v2/destinations/tiktok_audience/config.js @@ -0,0 +1,9 @@ +const ACTION_MAP = { + add: 'add', + remove: 'delete', +}; +const SHA256_TRAITS = ['IDFA_SHA256', 'AAID_SHA256', 'EMAIL_SHA256', 'PHONE_SHA256']; +module.exports = { + ACTION_MAP, + SHA256_TRAITS, +}; diff --git a/src/cdk/v2/destinations/tiktok_audience/procWorkflow.yaml b/src/cdk/v2/destinations/tiktok_audience/procWorkflow.yaml new file mode 100644 index 0000000000..cd84ecbc87 --- /dev/null +++ b/src/cdk/v2/destinations/tiktok_audience/procWorkflow.yaml @@ -0,0 +1,67 @@ + +bindings: + - name: EventType + path: ../../../../constants + - path: ../../bindings/jsontemplate + exportAll: true + - path: ./config + - name: removeUndefinedAndNullValues + path: ../../../../v0/util + - name: defaultRequestConfig + path: ../../../../v0/util + +steps: + - name: validateInput + template: | + let messageType = .message.type; + $.assert(.message.type, "message Type is not present. Aborting message."); + $.assert(.message.type.toLowerCase() ==='audiencelist', "Event type " + .message.type.toLowerCase() + " is not supported. Aborting message."); + $.assert(.message.properties, "Message properties is not present. Aborting message."); + $.assert(.message.properties.listData, "listData is not present inside properties. Aborting message."); + $.assert($.containsAll(Object.keys(.message.properties.listData), ["add", "remove"]), "unsupported action type. Aborting message.") + + - name: prepareIdentifiersList + description: | + Populate list of identifiers to be updated + template: | + const destinationFields = .message.context.destinationFields.split(", ") + const audienceId = .message.context.externalId[0].type.split("-")[1]; + const isHashRequired = .destination.Config.isHashRequired; + const advertiserIds = .metadata.secret.advertiserIds; + const hashTraits = function(traits) { + traits@trait.(destinationFields@destinationField.( + trait[destinationField] ? { + id: isHashRequired ? + destinationField in $.SHA256_TRAITS ? + $.SHA256(trait[destinationField]) : $.MD5(trait[destinationField]) + : trait[destinationField], + audience_ids:[audienceId] + } : {} + )[]) + }; + const listData = .message.properties.listData; + const actions = Object.keys(listData) + actions@action.({ + "batch_data": hashTraits(listData[action]), + "id_schema": destinationFields, + "advertiser_ids": advertiserIds, + "action": $.ACTION_MAP[action], + })[] + + + - name: buildResponseForProcessTransformation + description: build response + template: | + const accessToken = .metadata.secret.accessToken + const anonymousId = .message.anonymousId; + $.outputs.prepareIdentifiersList@body.( + let response = $.defaultRequestConfig(); + response.body.JSON = body; + response.userId = anonymousId; + response.endpoint = "https://business-api.tiktok.com/open_api/v1.3/segment/mapping/"; + response.headers = { + "Access-Token": accessToken, + "Content-Type": "application/json" + }; + response + ) diff --git a/src/cdk/v2/destinations/tiktok_audience/rtWorkflow.yaml b/src/cdk/v2/destinations/tiktok_audience/rtWorkflow.yaml new file mode 100644 index 0000000000..3db4c405ad --- /dev/null +++ b/src/cdk/v2/destinations/tiktok_audience/rtWorkflow.yaml @@ -0,0 +1,32 @@ +bindings: + - name: handleRtTfSingleEventError + path: ../../../../v0/util/index + +steps: + - name: validateInput + template: | + $.assert(Array.isArray(^) && ^.length > 0, "Invalid event array") + + - name: transform + externalWorkflow: + path: ./procWorkflow.yaml + loopOverInput: true + + - name: successfulEvents + debug: true + template: | + $.outputs.transform#idx{"output" in .}.({ + "batchedRequest": .output, + "batched": true, + "destination": ^[idx].destination, + "metadata": ^[idx].metadata[], + "statusCode": 200 + })[] + - name: failedEvents + template: | + $.outputs.transform#idx.error.( + $.handleRtTfSingleEventError(^[idx], .originalError ?? ., {}) + )[] + - name: finalPayload + template: | + [...$.outputs.failedEvents, ...$.outputs.successfulEvents] diff --git a/src/features.json b/src/features.json index 7de214ab39..fb5b0735f0 100644 --- a/src/features.json +++ b/src/features.json @@ -58,6 +58,7 @@ "OPTIMIZELY_FULLSTACK": true, "TWITTER_ADS": true, "CLEVERTAP": true, + "TIKTOK_AUDIENCE": true, "ORTTO": true } } diff --git a/test/integrations/destinations/tiktok_audience/processor/data.ts b/test/integrations/destinations/tiktok_audience/processor/data.ts new file mode 100644 index 0000000000..a715aa2f72 --- /dev/null +++ b/test/integrations/destinations/tiktok_audience/processor/data.ts @@ -0,0 +1,854 @@ +export const data = [ + { + "name": "tiktok_audience", + "description": "Test 1: Containing SHA256 traits only", + "feature": "processor", + "module": "destination", + "version": "v0", + "input": { + "request": { + "body": [ + { + "message": { + "userId": "user 1", + "type": "audiencelist", + "properties": { + "listData": { + "add": [ + { + "EMAIL_SHA256": "alex@email.com" + }, + { + "EMAIL_SHA256": "amy@abc.com" + }, + { + "EMAIL_SHA256": "van@abc.com" + } + ], + "remove": [ + { + "EMAIL_SHA256": "alex@email.com" + }, + { + "EMAIL_SHA256": "amy@abc.com" + }, + { + "EMAIL_SHA256": "van@abc.com" + } + ] + } + }, + "context": { + "ip": "14.5.67.21", + "library": { + "name": "http" + }, + "externalId": [ + { + "type": "TIKTOK_AUDIENCE-23856594064540489", + "identifierType": "EMAIL_SHA256" + } + ], + "destinationFields": "EMAIL_SHA256" + }, + "timestamp": "2020-02-02T00:23:09.544Z" + }, + "metadata": { + "jobId": 1, + "secret": { + "accessToken": "dummyAccessToken", + "advertiserIds": [ + "dummyAdverTiserID" + ] + } + }, + "destination": { + "DestinationDefinition": { + "Config": { + "cdkV2Enabled": true + } + }, + "Config": { + "isHashRequired": true, + "registerDeviceOrBrowserApiKey": true, + "apiKey": "intercomApiKey", + "appId": "9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0", + "collectContext": false + } + } + } + ] + } + }, + "output": { + "response": { + "status": 200, + "body": [ + { + "output": { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://business-api.tiktok.com/open_api/v1.3/segment/mapping/", + "headers": { + "Access-Token": "dummyAccessToken", + "Content-Type": "application/json" + }, + "params": {}, + "body": { + "JSON": { + "batch_data": [ + [ + { + "id": "ac0f1baec38a9ef3cfcb56db981df7d9bab2568c7f53ef3776d1c059ec58e72b", + "audience_ids": [ + "23856594064540489" + ] + } + ], + [ + { + "id": "49eaeca26c878f268ad33af8cfa8194ca5b8b8e448b1c775bf9153a2de734579", + "audience_ids": [ + "23856594064540489" + ] + } + ], + [ + { + "id": "2048acfa84a01121060ca2fc8a673a76d427176dc37224d4408c21973bd90e5c", + "audience_ids": [ + "23856594064540489" + ] + } + ] + ], + "id_schema": [ + "EMAIL_SHA256" + ], + "advertiser_ids": [ + "dummyAdverTiserID" + ], + "action": "add" + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} + }, + "files": {}, + "userId": "" + }, + "metadata": { + "jobId": 1, + "secret": { + "accessToken": "dummyAccessToken", + "advertiserIds": [ + "dummyAdverTiserID" + ] + } + }, + "statusCode": 200 + }, + { + "output": { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://business-api.tiktok.com/open_api/v1.3/segment/mapping/", + "headers": { + "Access-Token": "dummyAccessToken", + "Content-Type": "application/json" + }, + "params": {}, + "body": { + "JSON": { + "batch_data": [ + [ + { + "id": "ac0f1baec38a9ef3cfcb56db981df7d9bab2568c7f53ef3776d1c059ec58e72b", + "audience_ids": [ + "23856594064540489" + ] + } + ], + [ + { + "id": "49eaeca26c878f268ad33af8cfa8194ca5b8b8e448b1c775bf9153a2de734579", + "audience_ids": [ + "23856594064540489" + ] + } + ], + [ + { + "id": "2048acfa84a01121060ca2fc8a673a76d427176dc37224d4408c21973bd90e5c", + "audience_ids": [ + "23856594064540489" + ] + } + ] + ], + "id_schema": [ + "EMAIL_SHA256" + ], + "advertiser_ids": [ + "dummyAdverTiserID" + ], + "action": "delete" + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} + }, + "files": {}, + "userId": "" + }, + "metadata": { + "jobId": 1, + "secret": { + "accessToken": "dummyAccessToken", + "advertiserIds": [ + "dummyAdverTiserID" + ] + } + }, + "statusCode": 200 + } + ] + } + } + }, + { + "name": "tiktok_audience", + "description": "Test 2: Containing SHA256 and MD5 traits", + "feature": "processor", + "module": "destination", + "version": "v0", + "input": { + "request": { + "body": [ + { + "message": { + "userId": "user 1", + "type": "audiencelist", + "properties": { + "listData": { + "add": [ + { + "EMAIL_SHA256": "alex@email.com", + "AAID_MD5": "1234567" + }, + { + "EMAIL_SHA256": "amy@abc.com", + "AAID_MD5": "1234568" + }, + { + "EMAIL_SHA256": "van@abc.com", + "AAID_MD5": "1234569" + } + ], + "remove": [ + { + "EMAIL_SHA256": "alex@email.com", + "AAID_MD5": "1234570" + }, + { + "EMAIL_SHA256": "amy@abc.com", + "AAID_MD5": "1234571" + }, + { + "EMAIL_SHA256": "van@abc.com", + "AAID_MD5": "1234572" + } + ] + } + }, + "context": { + "ip": "14.5.67.21", + "library": { + "name": "http" + }, + "externalId": [ + { + "type": "TIKTOK_AUDIENCE-23856594064540489", + "identifierType": "EMAIL_SHA256" + } + ], + "destinationFields": "EMAIL_SHA256, AAID_MD5" + }, + "timestamp": "2020-02-02T00:23:09.544Z" + }, + "metadata": { + "jobId": 1, + "secret": { + "accessToken": "dummyAccessToken", + "advertiserIds": [ + "dummyAdverTiserID" + ] + } + }, + "destination": { + "DestinationDefinition": { + "Config": { + "cdkV2Enabled": true + } + }, + "Config": { + "isHashRequired": true, + "registerDeviceOrBrowserApiKey": true, + "apiKey": "intercomApiKey", + "appId": "9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0", + "collectContext": false + } + } + } + ] + } + }, + "output": { + "response": { + "status": 200, + "body": [ + { + "output": { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://business-api.tiktok.com/open_api/v1.3/segment/mapping/", + "headers": { + "Access-Token": "dummyAccessToken", + "Content-Type": "application/json" + }, + "params": {}, + "body": { + "JSON": { + "batch_data": [ + [ + { + "id": "ac0f1baec38a9ef3cfcb56db981df7d9bab2568c7f53ef3776d1c059ec58e72b", + "audience_ids": [ + "23856594064540489" + ] + }, + { + "id": "fcea920f7412b5da7be0cf42b8c93759", + "audience_ids": [ + "23856594064540489" + ] + } + ], + [ + { + "id": "49eaeca26c878f268ad33af8cfa8194ca5b8b8e448b1c775bf9153a2de734579", + "audience_ids": [ + "23856594064540489" + ] + }, + { + "id": "fe743d8d97aa7dfc6c93ccdc2e749513", + "audience_ids": [ + "23856594064540489" + ] + } + ], + [ + { + "id": "2048acfa84a01121060ca2fc8a673a76d427176dc37224d4408c21973bd90e5c", + "audience_ids": [ + "23856594064540489" + ] + }, + { + "id": "e36a2f90240e9e84483504fd4a704452", + "audience_ids": [ + "23856594064540489" + ] + } + ] + ], + "id_schema": [ + "EMAIL_SHA256", + "AAID_MD5" + ], + "advertiser_ids": [ + "dummyAdverTiserID" + ], + "action": "add" + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} + }, + "files": {}, + "userId": "" + }, + "metadata": { + "jobId": 1, + "secret": { + "accessToken": "dummyAccessToken", + "advertiserIds": [ + "dummyAdverTiserID" + ] + } + }, + "statusCode": 200 + }, + { + "output": { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://business-api.tiktok.com/open_api/v1.3/segment/mapping/", + "headers": { + "Access-Token": "dummyAccessToken", + "Content-Type": "application/json" + }, + "params": {}, + "body": { + "JSON": { + "batch_data": [ + [ + { + "id": "ac0f1baec38a9ef3cfcb56db981df7d9bab2568c7f53ef3776d1c059ec58e72b", + "audience_ids": [ + "23856594064540489" + ] + }, + { + "id": "c1abd65fea29d573ddef1bce925e3276", + "audience_ids": [ + "23856594064540489" + ] + } + ], + [ + { + "id": "49eaeca26c878f268ad33af8cfa8194ca5b8b8e448b1c775bf9153a2de734579", + "audience_ids": [ + "23856594064540489" + ] + }, + { + "id": "7298110702a080dfc6903f13333eb04a", + "audience_ids": [ + "23856594064540489" + ] + } + ], + [ + { + "id": "2048acfa84a01121060ca2fc8a673a76d427176dc37224d4408c21973bd90e5c", + "audience_ids": [ + "23856594064540489" + ] + }, + { + "id": "d9cb68b1fd3b9d32abc5f4cab8b42b68", + "audience_ids": [ + "23856594064540489" + ] + } + ] + ], + "id_schema": [ + "EMAIL_SHA256", + "AAID_MD5" + ], + "advertiser_ids": [ + "dummyAdverTiserID" + ], + "action": "delete" + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} + }, + "files": {}, + "userId": "" + }, + "metadata": { + "jobId": 1, + "secret": { + "accessToken": "dummyAccessToken", + "advertiserIds": [ + "dummyAdverTiserID" + ] + } + }, + "statusCode": 200 + } + ] + } + } + }, + { + "name": "tiktok_audience", + "description": "Test 3: Containing all possible traits", + "feature": "processor", + "module": "destination", + "version": "v0", + "input": { + "request": { + "body": [ + { + "message": { + "userId": "user 1", + "type": "audiencelist", + "properties": { + "listData": { + "add": [ + { + "EMAIL_SHA256": "alex@email.com", + "PHONE_SHA256": "+129988776655", + "IDFA_SHA256": "1234lkasfjdalj12321", + "AAID_SHA256": "000999OOOQQQQ", + "AAID_MD5": "000999OOOQQQQ", + "IDFA_MD5": "1234lkasfjdalj12321" + }, + { + "EMAIL_SHA256": "amy@abc.com", + "PHONE_SHA256": "+129988776677", + "IDFA_SHA256": "1234lkasfjdalj114455", + "AAID_SHA256": "000999OOOPPPP", + "AAID_MD5": "000999OOOPPPP", + "IDFA_MD5": "1234lkasfjdalj114455" + } + ] + } + }, + "context": { + "ip": "14.5.67.21", + "library": { + "name": "http" + }, + "externalId": [ + { + "type": "TIKTOK_AUDIENCE-23856594064540489", + "identifierType": "EMAIL_SHA256" + } + ], + "destinationFields": "EMAIL_SHA256, PHONE_SHA256, IDFA_SHA256, AAID_SHA256, AAID_MD, IDFA_MD5" + }, + "timestamp": "2020-02-02T00:23:09.544Z" + }, + "metadata": { + "jobId": 1, + "secret": { + "accessToken": "dummyAccessToken", + "advertiserIds": [ + "dummyAdverTiserID" + ] + } + }, + "destination": { + "DestinationDefinition": { + "Config": { + "cdkV2Enabled": true + } + }, + "Config": { + "isHashRequired": true, + "registerDeviceOrBrowserApiKey": true, + "apiKey": "intercomApiKey", + "appId": "9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0", + "collectContext": false + } + } + } + ] + } + }, + "output": { + "response": { + "status": 200, + "body": [ + { + "output": { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://business-api.tiktok.com/open_api/v1.3/segment/mapping/", + "headers": { + "Access-Token": "dummyAccessToken", + "Content-Type": "application/json" + }, + "params": {}, + "body": { + "JSON": { + "batch_data": [ + [ + { + "id": "ac0f1baec38a9ef3cfcb56db981df7d9bab2568c7f53ef3776d1c059ec58e72b", + "audience_ids": [ + "23856594064540489" + ] + }, + { + "id": "31e78a3bf9ce2b43316f64fe883a531d6266938091e94e2f2480272481163dee", + "audience_ids": [ + "23856594064540489" + ] + }, + { + "id": "0259f595f7172c8dd692a5c37b4d296939555f862aae8adb964391bdb65006ab", + "audience_ids": [ + "23856594064540489" + ] + }, + { + "id": "b06fbe7a29f33576a792ba3df3c9bf838cd26ea88cf574285fa60dc0234a8485", + "audience_ids": [ + "23856594064540489" + ] + }, + {}, + { + "id": "32ee3d063320815a13e0058c2498ff76", + "audience_ids": [ + "23856594064540489" + ] + } + ], + [ + { + "id": "49eaeca26c878f268ad33af8cfa8194ca5b8b8e448b1c775bf9153a2de734579", + "audience_ids": [ + "23856594064540489" + ] + }, + { + "id": "fb40adc7debbf40e7b45b0a4a91886785dff1a28809276f95f1c44f7045f9b4d", + "audience_ids": [ + "23856594064540489" + ] + }, + { + "id": "e6bbdf34c5f3472f31b2923a26811560a599233f3dea4c9971595c3bb7b1e8dc", + "audience_ids": [ + "23856594064540489" + ] + }, + { + "id": "661125f7d337811256c5b55996b22c89047804dcec494db72659e4be71e03091", + "audience_ids": [ + "23856594064540489" + ] + }, + {}, + { + "id": "94162773066d6ae88b2658dc58ca2317", + "audience_ids": [ + "23856594064540489" + ] + } + ] + ], + "id_schema": [ + "EMAIL_SHA256", + "PHONE_SHA256", + "IDFA_SHA256", + "AAID_SHA256", + "AAID_MD", + "IDFA_MD5" + ], + "advertiser_ids": [ + "dummyAdverTiserID" + ], + "action": "add" + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} + }, + "files": {}, + "userId": "" + }, + "metadata": { + "jobId": 1, + "secret": { + "accessToken": "dummyAccessToken", + "advertiserIds": [ + "dummyAdverTiserID" + ] + } + }, + "statusCode": 200 + } + ] + } + } + }, + { + "name": "tiktok_audience", + "description": "Test 4: Considering some null values", + "feature": "processor", + "module": "destination", + "version": "v0", + "input": { + "request": { + "body": [ + { + "message": { + "userId": "user 1", + "type": "audiencelist", + "properties": { + "listData": { + "add": [ + { + "EMAIL_SHA256": "alex@email.com", + "PHONE_SHA256": "+129988776655", + "AAID_MD5": "000999OOOQQQQ", + "IDFA_MD5": "1234lkasfjdalj12321" + }, + { + "EMAIL_SHA256": "amy@abc.com", + "AAID_SHA256": "000999OOOPPPP", + "AAID_MD5": "000999OOOPPPP", + "IDFA_MD5": "1234lkasfjdalj114455" + } + ] + } + }, + "context": { + "ip": "14.5.67.21", + "library": { + "name": "http" + }, + "externalId": [ + { + "type": "TIKTOK_AUDIENCE-23856594064540489", + "identifierType": "EMAIL_SHA256" + } + ], + "destinationFields": "EMAIL_SHA256, PHONE_SHA256, IDFA_SHA256, AAID_SHA256, AAID_MD, IDFA_MD5" + }, + "timestamp": "2020-02-02T00:23:09.544Z" + }, + "metadata": { + "jobId": 1, + "secret": { + "accessToken": "dummyAccessToken", + "advertiserIds": [ + "dummyAdverTiserID" + ] + } + }, + "destination": { + "DestinationDefinition": { + "Config": { + "cdkV2Enabled": true + } + }, + "Config": { + "isHashRequired": true, + "registerDeviceOrBrowserApiKey": true, + "apiKey": "intercomApiKey", + "appId": "9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0", + "collectContext": false + } + } + } + ] + } + }, + "output": { + "response": { + "status": 200, + "body": [ + { + "output": { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://business-api.tiktok.com/open_api/v1.3/segment/mapping/", + "headers": { + "Access-Token": "dummyAccessToken", + "Content-Type": "application/json" + }, + "params": {}, + "body": { + "JSON": { + "batch_data": [ + [ + { + "id": "ac0f1baec38a9ef3cfcb56db981df7d9bab2568c7f53ef3776d1c059ec58e72b", + "audience_ids": [ + "23856594064540489" + ] + }, + { + "id": "31e78a3bf9ce2b43316f64fe883a531d6266938091e94e2f2480272481163dee", + "audience_ids": [ + "23856594064540489" + ] + }, + {}, + {}, + {}, + { + "id": "32ee3d063320815a13e0058c2498ff76", + "audience_ids": [ + "23856594064540489" + ] + } + ], + [ + { + "id": "49eaeca26c878f268ad33af8cfa8194ca5b8b8e448b1c775bf9153a2de734579", + "audience_ids": [ + "23856594064540489" + ] + }, + {}, + {}, + { + "id": "661125f7d337811256c5b55996b22c89047804dcec494db72659e4be71e03091", + "audience_ids": [ + "23856594064540489" + ] + }, + {}, + { + "id": "94162773066d6ae88b2658dc58ca2317", + "audience_ids": [ + "23856594064540489" + ] + } + ] + ], + "id_schema": [ + "EMAIL_SHA256", + "PHONE_SHA256", + "IDFA_SHA256", + "AAID_SHA256", + "AAID_MD", + "IDFA_MD5" + ], + "advertiser_ids": [ + "dummyAdverTiserID" + ], + "action": "add" + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} + }, + "files": {}, + "userId": "" + }, + "metadata": { + "jobId": 1, + "secret": { + "accessToken": "dummyAccessToken", + "advertiserIds": [ + "dummyAdverTiserID" + ] + } + }, + "statusCode": 200 + } + ] + } + } + } +] \ No newline at end of file diff --git a/test/integrations/destinations/tiktok_audience/router/data.ts b/test/integrations/destinations/tiktok_audience/router/data.ts new file mode 100644 index 0000000000..c8a8b93d30 --- /dev/null +++ b/test/integrations/destinations/tiktok_audience/router/data.ts @@ -0,0 +1,833 @@ +export const data = [ + { + name: 'tiktok_audience', + description: 'Multiple jobs with different metadata', + feature: 'router', + module: 'destination', + version: 'v0', + input: { + request: { + body: { + input: [ + { + message: { + userId: 'user 1', + type: 'audiencelist', + properties: { + listData: { + add: [ + { + EMAIL_SHA256: 'alex@email.com', + }, + { + EMAIL_SHA256: 'amy@abc.com', + }, + { + EMAIL_SHA256: 'van@abc.com', + }, + ], + remove: [ + { + EMAIL_SHA256: 'alex@email.com', + }, + { + EMAIL_SHA256: 'amy@abc.com', + }, + { + EMAIL_SHA256: 'van@abc.com', + }, + ], + }, + }, + context: { + ip: '14.5.67.21', + library: { + name: 'http', + }, + externalId: [ + { + type: 'TIKTOK_AUDIENCE-23856594064540489', + identifierType: 'EMAIL_SHA256', + }, + ], + destinationFields: 'EMAIL_SHA256', + }, + timestamp: '2020-02-02T00:23:09.544Z', + }, + metadata: { + jobId: 1, + secret: { + accessToken: 'dummyAccessToken', + advertiserIds: ['dummyAdverTiserID'], + }, + }, + destination: { + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + isHashRequired: true, + registerDeviceOrBrowserApiKey: true, + apiKey: 'intercomApiKey', + appId: '9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0', + collectContext: false, + }, + }, + }, + { + message: { + userId: 'user 1', + type: 'audiencelist', + properties: { + listData: { + add: [ + { + EMAIL_SHA256: 'alex@email.com', + AAID_MD5: '1234567', + }, + { + EMAIL_SHA256: 'amy@abc.com', + AAID_MD5: '1234568', + }, + { + EMAIL_SHA256: 'van@abc.com', + AAID_MD5: '1234569', + }, + ], + remove: [ + { + EMAIL_SHA256: 'alex@email.com', + AAID_MD5: '1234570', + }, + { + EMAIL_SHA256: 'amy@abc.com', + AAID_MD5: '1234571', + }, + { + EMAIL_SHA256: 'van@abc.com', + AAID_MD5: '1234572', + }, + ], + }, + }, + context: { + ip: '14.5.67.21', + library: { + name: 'http', + }, + externalId: [ + { + type: 'TIKTOK_AUDIENCE-23856594064540489', + identifierType: 'EMAIL_SHA256', + }, + ], + destinationFields: 'EMAIL_SHA256, AAID_MD5', + }, + timestamp: '2020-02-02T00:23:09.544Z', + }, + metadata: { + jobId: 2, + secret: { + accessToken: 'dummyAccessToken', + advertiserIds: ['dummyAdverTiserID'], + }, + }, + destination: { + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + isHashRequired: true, + registerDeviceOrBrowserApiKey: true, + apiKey: 'intercomApiKey', + appId: '9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0', + collectContext: false, + }, + }, + }, + { + message: { + userId: 'user 1', + type: 'audiencelist', + properties: { + listData: { + add: [ + { + EMAIL_SHA256: 'alex@email.com', + PHONE_SHA256: '+129988776655', + IDFA_SHA256: '1234lkasfjdalj12321', + AAID_SHA256: '000999OOOQQQQ', + AAID_MD5: '000999OOOQQQQ', + IDFA_MD5: '1234lkasfjdalj12321', + }, + { + EMAIL_SHA256: 'amy@abc.com', + PHONE_SHA256: '+129988776677', + IDFA_SHA256: '1234lkasfjdalj114455', + AAID_SHA256: '000999OOOPPPP', + AAID_MD5: '000999OOOPPPP', + IDFA_MD5: '1234lkasfjdalj114455', + }, + ], + }, + }, + context: { + ip: '14.5.67.21', + library: { + name: 'http', + }, + externalId: [ + { + type: 'TIKTOK_AUDIENCE-23856594064540489', + identifierType: 'EMAIL_SHA256', + }, + ], + destinationFields: + 'EMAIL_SHA256, PHONE_SHA256, IDFA_SHA256, AAID_SHA256, AAID_MD, IDFA_MD5', + }, + timestamp: '2020-02-02T00:23:09.544Z', + }, + metadata: { + jobId: 3, + secret: { + accessToken: 'dummyAccessToken', + advertiserIds: ['dummyAdverTiserID'], + }, + }, + destination: { + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + isHashRequired: true, + registerDeviceOrBrowserApiKey: true, + apiKey: 'intercomApiKey', + appId: '9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0', + collectContext: false, + }, + }, + }, + { + message: { + userId: 'user 1', + type: 'audiencelist', + properties: { + listData: { + add: [ + { + EMAIL_SHA256: 'alex@email.com', + PHONE_SHA256: '+129988776655', + AAID_MD5: '000999OOOQQQQ', + IDFA_MD5: '1234lkasfjdalj12321', + }, + { + EMAIL_SHA256: 'amy@abc.com', + AAID_SHA256: '000999OOOPPPP', + AAID_MD5: '000999OOOPPPP', + IDFA_MD5: '1234lkasfjdalj114455', + }, + ], + }, + }, + context: { + ip: '14.5.67.21', + library: { + name: 'http', + }, + externalId: [ + { + type: 'TIKTOK_AUDIENCE-23856594064540489', + identifierType: 'EMAIL_SHA256', + }, + ], + destinationFields: + 'EMAIL_SHA256, PHONE_SHA256, IDFA_SHA256, AAID_SHA256, AAID_MD, IDFA_MD5', + }, + timestamp: '2020-02-02T00:23:09.544Z', + }, + metadata: { + jobId: 4, + secret: { + accessToken: 'dummyAccessToken', + advertiserIds: ['dummyAdverTiserID'], + }, + }, + destination: { + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + isHashRequired: true, + registerDeviceOrBrowserApiKey: true, + apiKey: 'intercomApiKey', + appId: '9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0', + collectContext: false, + }, + }, + }, + { + message: { + userId: 'user 1', + properties: { + listData: { + add: [ + { + EMAIL_SHA256: 'alex@email.com', + PHONE_SHA256: '+129988776655', + AAID_MD5: '000999OOOQQQQ', + IDFA_MD5: '1234lkasfjdalj12321', + }, + { + EMAIL_SHA256: 'amy@abc.com', + AAID_SHA256: '000999OOOPPPP', + AAID_MD5: '000999OOOPPPP', + IDFA_MD5: '1234lkasfjdalj114455', + }, + ], + }, + }, + context: { + ip: '14.5.67.21', + library: { + name: 'http', + }, + externalId: [ + { + type: 'TIKTOK_AUDIENCE-23856594064540489', + identifierType: 'EMAIL_SHA256', + }, + ], + destinationFields: + 'EMAIL_SHA256, PHONE_SHA256, IDFA_SHA256, AAID_SHA256, AAID_MD, IDFA_MD5', + }, + timestamp: '2020-02-02T00:23:09.544Z', + }, + metadata: { + jobId: 1524545, + secret: { + accessToken: 'dummyAccessToken', + advertiserIds: ['dummyAdverTiserID'], + }, + }, + destination: { + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + isHashRequired: true, + registerDeviceOrBrowserApiKey: true, + apiKey: 'intercomApiKey', + appId: '9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0', + collectContext: false, + }, + }, + }, + ], + destType: 'tiktok_audience', + }, + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: [ + { + error: 'message Type is not present. Aborting message.', + batched: false, + destination: { + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + isHashRequired: true, + registerDeviceOrBrowserApiKey: true, + apiKey: 'intercomApiKey', + appId: '9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0', + collectContext: false, + }, + }, + metadata: [ + { + jobId: 1524545, + secret: { + accessToken: 'dummyAccessToken', + advertiserIds: ['dummyAdverTiserID'], + }, + }, + ], + statTags: { + destType: 'TIKTOK_AUDIENCE', + errorCategory: 'dataValidation', + errorType: 'instrumentation', + feature: 'router', + implementation: 'cdkV2', + module: 'destination', + }, + statusCode: 400, + }, + { + batchedRequest: [ + { + version: '1', + type: 'REST', + method: 'POST', + endpoint: 'https://business-api.tiktok.com/open_api/v1.3/segment/mapping/', + headers: { + 'Access-Token': 'dummyAccessToken', + 'Content-Type': 'application/json', + }, + params: {}, + body: { + JSON: { + batch_data: [ + [ + { + id: 'ac0f1baec38a9ef3cfcb56db981df7d9bab2568c7f53ef3776d1c059ec58e72b', + audience_ids: ['23856594064540489'], + }, + ], + [ + { + id: '49eaeca26c878f268ad33af8cfa8194ca5b8b8e448b1c775bf9153a2de734579', + audience_ids: ['23856594064540489'], + }, + ], + [ + { + id: '2048acfa84a01121060ca2fc8a673a76d427176dc37224d4408c21973bd90e5c', + audience_ids: ['23856594064540489'], + }, + ], + ], + id_schema: ['EMAIL_SHA256'], + advertiser_ids: ['dummyAdverTiserID'], + action: 'add', + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + }, + { + version: '1', + type: 'REST', + method: 'POST', + endpoint: 'https://business-api.tiktok.com/open_api/v1.3/segment/mapping/', + headers: { + 'Access-Token': 'dummyAccessToken', + 'Content-Type': 'application/json', + }, + params: {}, + body: { + JSON: { + batch_data: [ + [ + { + id: 'ac0f1baec38a9ef3cfcb56db981df7d9bab2568c7f53ef3776d1c059ec58e72b', + audience_ids: ['23856594064540489'], + }, + ], + [ + { + id: '49eaeca26c878f268ad33af8cfa8194ca5b8b8e448b1c775bf9153a2de734579', + audience_ids: ['23856594064540489'], + }, + ], + [ + { + id: '2048acfa84a01121060ca2fc8a673a76d427176dc37224d4408c21973bd90e5c', + audience_ids: ['23856594064540489'], + }, + ], + ], + id_schema: ['EMAIL_SHA256'], + advertiser_ids: ['dummyAdverTiserID'], + action: 'delete', + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + }, + ], + batched: true, + destination: { + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + isHashRequired: true, + registerDeviceOrBrowserApiKey: true, + apiKey: 'intercomApiKey', + appId: '9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0', + collectContext: false, + }, + }, + metadata: [ + { + jobId: 1, + secret: { + accessToken: 'dummyAccessToken', + advertiserIds: ['dummyAdverTiserID'], + }, + }, + ], + statusCode: 200, + }, + { + batchedRequest: [ + { + version: '1', + type: 'REST', + method: 'POST', + endpoint: 'https://business-api.tiktok.com/open_api/v1.3/segment/mapping/', + headers: { + 'Access-Token': 'dummyAccessToken', + 'Content-Type': 'application/json', + }, + params: {}, + body: { + JSON: { + batch_data: [ + [ + { + id: 'ac0f1baec38a9ef3cfcb56db981df7d9bab2568c7f53ef3776d1c059ec58e72b', + audience_ids: ['23856594064540489'], + }, + { + id: 'fcea920f7412b5da7be0cf42b8c93759', + audience_ids: ['23856594064540489'], + }, + ], + [ + { + id: '49eaeca26c878f268ad33af8cfa8194ca5b8b8e448b1c775bf9153a2de734579', + audience_ids: ['23856594064540489'], + }, + { + id: 'fe743d8d97aa7dfc6c93ccdc2e749513', + audience_ids: ['23856594064540489'], + }, + ], + [ + { + id: '2048acfa84a01121060ca2fc8a673a76d427176dc37224d4408c21973bd90e5c', + audience_ids: ['23856594064540489'], + }, + { + id: 'e36a2f90240e9e84483504fd4a704452', + audience_ids: ['23856594064540489'], + }, + ], + ], + id_schema: ['EMAIL_SHA256', 'AAID_MD5'], + advertiser_ids: ['dummyAdverTiserID'], + action: 'add', + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + }, + { + version: '1', + type: 'REST', + method: 'POST', + endpoint: 'https://business-api.tiktok.com/open_api/v1.3/segment/mapping/', + headers: { + 'Access-Token': 'dummyAccessToken', + 'Content-Type': 'application/json', + }, + params: {}, + body: { + JSON: { + batch_data: [ + [ + { + id: 'ac0f1baec38a9ef3cfcb56db981df7d9bab2568c7f53ef3776d1c059ec58e72b', + audience_ids: ['23856594064540489'], + }, + { + id: 'c1abd65fea29d573ddef1bce925e3276', + audience_ids: ['23856594064540489'], + }, + ], + [ + { + id: '49eaeca26c878f268ad33af8cfa8194ca5b8b8e448b1c775bf9153a2de734579', + audience_ids: ['23856594064540489'], + }, + { + id: '7298110702a080dfc6903f13333eb04a', + audience_ids: ['23856594064540489'], + }, + ], + [ + { + id: '2048acfa84a01121060ca2fc8a673a76d427176dc37224d4408c21973bd90e5c', + audience_ids: ['23856594064540489'], + }, + { + id: 'd9cb68b1fd3b9d32abc5f4cab8b42b68', + audience_ids: ['23856594064540489'], + }, + ], + ], + id_schema: ['EMAIL_SHA256', 'AAID_MD5'], + advertiser_ids: ['dummyAdverTiserID'], + action: 'delete', + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + }, + ], + batched: true, + destination: { + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + isHashRequired: true, + registerDeviceOrBrowserApiKey: true, + apiKey: 'intercomApiKey', + appId: '9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0', + collectContext: false, + }, + }, + metadata: [ + { + jobId: 2, + secret: { + accessToken: 'dummyAccessToken', + advertiserIds: ['dummyAdverTiserID'], + }, + }, + ], + statusCode: 200, + }, + { + batchedRequest: { + version: '1', + type: 'REST', + method: 'POST', + endpoint: 'https://business-api.tiktok.com/open_api/v1.3/segment/mapping/', + headers: { + 'Access-Token': 'dummyAccessToken', + 'Content-Type': 'application/json', + }, + params: {}, + body: { + JSON: { + batch_data: [ + [ + { + id: 'ac0f1baec38a9ef3cfcb56db981df7d9bab2568c7f53ef3776d1c059ec58e72b', + audience_ids: ['23856594064540489'], + }, + { + id: '31e78a3bf9ce2b43316f64fe883a531d6266938091e94e2f2480272481163dee', + audience_ids: ['23856594064540489'], + }, + { + id: '0259f595f7172c8dd692a5c37b4d296939555f862aae8adb964391bdb65006ab', + audience_ids: ['23856594064540489'], + }, + { + id: 'b06fbe7a29f33576a792ba3df3c9bf838cd26ea88cf574285fa60dc0234a8485', + audience_ids: ['23856594064540489'], + }, + {}, + { + id: '32ee3d063320815a13e0058c2498ff76', + audience_ids: ['23856594064540489'], + }, + ], + [ + { + id: '49eaeca26c878f268ad33af8cfa8194ca5b8b8e448b1c775bf9153a2de734579', + audience_ids: ['23856594064540489'], + }, + { + id: 'fb40adc7debbf40e7b45b0a4a91886785dff1a28809276f95f1c44f7045f9b4d', + audience_ids: ['23856594064540489'], + }, + { + id: 'e6bbdf34c5f3472f31b2923a26811560a599233f3dea4c9971595c3bb7b1e8dc', + audience_ids: ['23856594064540489'], + }, + { + id: '661125f7d337811256c5b55996b22c89047804dcec494db72659e4be71e03091', + audience_ids: ['23856594064540489'], + }, + {}, + { + id: '94162773066d6ae88b2658dc58ca2317', + audience_ids: ['23856594064540489'], + }, + ], + ], + id_schema: [ + 'EMAIL_SHA256', + 'PHONE_SHA256', + 'IDFA_SHA256', + 'AAID_SHA256', + 'AAID_MD', + 'IDFA_MD5', + ], + advertiser_ids: ['dummyAdverTiserID'], + action: 'add', + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + }, + batched: true, + destination: { + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + isHashRequired: true, + registerDeviceOrBrowserApiKey: true, + apiKey: 'intercomApiKey', + appId: '9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0', + collectContext: false, + }, + }, + metadata: [ + { + jobId: 3, + secret: { + accessToken: 'dummyAccessToken', + advertiserIds: ['dummyAdverTiserID'], + }, + }, + ], + statusCode: 200, + }, + { + batchedRequest: { + version: '1', + type: 'REST', + method: 'POST', + endpoint: 'https://business-api.tiktok.com/open_api/v1.3/segment/mapping/', + headers: { + 'Access-Token': 'dummyAccessToken', + 'Content-Type': 'application/json', + }, + params: {}, + body: { + JSON: { + batch_data: [ + [ + { + id: 'ac0f1baec38a9ef3cfcb56db981df7d9bab2568c7f53ef3776d1c059ec58e72b', + audience_ids: ['23856594064540489'], + }, + { + id: '31e78a3bf9ce2b43316f64fe883a531d6266938091e94e2f2480272481163dee', + audience_ids: ['23856594064540489'], + }, + {}, + {}, + {}, + { + id: '32ee3d063320815a13e0058c2498ff76', + audience_ids: ['23856594064540489'], + }, + ], + [ + { + id: '49eaeca26c878f268ad33af8cfa8194ca5b8b8e448b1c775bf9153a2de734579', + audience_ids: ['23856594064540489'], + }, + {}, + {}, + { + id: '661125f7d337811256c5b55996b22c89047804dcec494db72659e4be71e03091', + audience_ids: ['23856594064540489'], + }, + {}, + { + id: '94162773066d6ae88b2658dc58ca2317', + audience_ids: ['23856594064540489'], + }, + ], + ], + id_schema: [ + 'EMAIL_SHA256', + 'PHONE_SHA256', + 'IDFA_SHA256', + 'AAID_SHA256', + 'AAID_MD', + 'IDFA_MD5', + ], + advertiser_ids: ['dummyAdverTiserID'], + action: 'add', + }, + JSON_ARRAY: {}, + XML: {}, + FORM: {}, + }, + files: {}, + }, + batched: true, + destination: { + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + isHashRequired: true, + registerDeviceOrBrowserApiKey: true, + apiKey: 'intercomApiKey', + appId: '9e9cdea1-78fa-4829-a9b2-5d7f7e96d1a0', + collectContext: false, + }, + }, + metadata: [ + { + jobId: 4, + secret: { + accessToken: 'dummyAccessToken', + advertiserIds: ['dummyAdverTiserID'], + }, + }, + ], + statusCode: 200, + }, + ], + }, + }, + }, + }, +];