-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Co-authored-by: mihir-4116 <[email protected]> Co-authored-by: Mihir Bhalala <[email protected]>
- Loading branch information
1 parent
57fee04
commit 9bc0fd8
Showing
7 changed files
with
1,802 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.