Skip to content

Commit

Permalink
Merge branch 'develop' into feat.addFaasCustomPolicies
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayachand authored Nov 2, 2023
2 parents 3090231 + 9bc0fd8 commit f05a1c1
Show file tree
Hide file tree
Showing 18 changed files with 3,026 additions and 423 deletions.
6 changes: 6 additions & 0 deletions src/cdk/v2/bindings/default.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const crypto = require('crypto');
const {
InstrumentationError,
ConfigurationError,
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/cdk/v2/destinations/tiktok_audience/config.js
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,
};
67 changes: 67 additions & 0 deletions src/cdk/v2/destinations/tiktok_audience/procWorkflow.yaml
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
)
32 changes: 32 additions & 0 deletions src/cdk/v2/destinations/tiktok_audience/rtWorkflow.yaml
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]
1 change: 1 addition & 0 deletions src/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"OPTIMIZELY_FULLSTACK": true,
"TWITTER_ADS": true,
"CLEVERTAP": true,
"TIKTOK_AUDIENCE": true,
"ORTTO": true
}
}
5 changes: 4 additions & 1 deletion src/v0/destinations/am/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ events.forEach((event) => {
const DELETE_MAX_BATCH_SIZE = 100;
const DESTINATION = 'amplitude';
const IDENTIFY_AM = '$identify';

const AMBatchSizeLimit = 20 * 1024 * 1024; // 20 MB
const AMBatchEventLimit = 500; // event size limit from sdk is 32KB => 15MB
module.exports = {
DESTINATION,
Event,
Expand All @@ -134,4 +135,6 @@ module.exports = {
DELETE_MAX_BATCH_SIZE,
batchEventsWithUserIdLengthLowerThanFive,
IDENTIFY_AM,
AMBatchSizeLimit,
AMBatchEventLimit
};
Loading

0 comments on commit f05a1c1

Please sign in to comment.