-
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: onboard emersys destination (#3318)
* feat: emersys initial commit * feat: emersys initial batching commit * feat: emersys initial batching commit 2 * feat: unit test cases with minor edits * fix: emersys unit test cases * fix: adding support for track call * fix: adding network hand;er support * fix: track batch handled * fix: latest changes * refactor: remove cdk v1 imports * fix: identify batching final * fix: all batching final * fix: cide clean up * fix: router test cases finalised * small edit * fix: processor test cases finalised * fix: data delivery test cases * fix: adding user deletion implementation * fix: small edit * fix: edit in network handler * fix: data delivery test cases finalised * fix: editing unit test cases * fix: resolve fake timer clash * fix: add user deletion test cases * fix: doc links added * fix: review comments addressed --------- Co-authored-by: Dilip Kola <[email protected]> Co-authored-by: Shrouti Gangopadhyay <[email protected]>
- Loading branch information
1 parent
a354a62
commit 3f9ed30
Showing
16 changed files
with
4,455 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const ALLOWED_OPT_IN_VALUES = ['1', '2', '']; | ||
const groupedSuccessfulPayload = { | ||
identify: { | ||
method: 'PUT', | ||
batches: [], | ||
}, | ||
group: { | ||
method: 'POST', | ||
batches: [], | ||
}, | ||
track: { | ||
method: 'POST', | ||
batches: [], | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
MAX_BATCH_SIZE: 1000, | ||
EMAIL_FIELD_ID: 3, | ||
OPT_IN_FILED_ID: 31, | ||
ALLOWED_OPT_IN_VALUES, | ||
MAX_BATCH_SIZE_BYTES: 8000000, // 8 MB, | ||
groupedSuccessfulPayload, | ||
}; |
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,88 @@ | ||
bindings: | ||
- name: EventType | ||
path: ../../../../constants | ||
- path: ../../bindings/jsontemplate | ||
exportAll: true | ||
- name: removeUndefinedValues | ||
path: ../../../../v0/util | ||
- name: removeUndefinedAndNullValues | ||
path: ../../../../v0/util | ||
- name: defaultRequestConfig | ||
path: ../../../../v0/util | ||
- name: getIntegrationsObj | ||
path: ../../../../v0/util | ||
- name: getFieldValueFromMessage | ||
path: ../../../../v0/util | ||
- name: CommonUtils | ||
path: ../../../../util/common | ||
- path: ./utils | ||
- path: ./config | ||
- path: lodash | ||
name: cloneDeep | ||
|
||
steps: | ||
- name: checkIfProcessed | ||
condition: .message.statusCode | ||
template: | | ||
$.batchMode ? .message.body.JSON : .message | ||
onComplete: return | ||
- name: messageType | ||
template: | | ||
.message.type.toLowerCase() | ||
- name: validateInput | ||
template: | | ||
let messageType = $.outputs.messageType; | ||
$.assert(messageType, "Message type is not present. Aborting message."); | ||
$.assert(messageType in {{$.EventType.([.TRACK, .IDENTIFY, .GROUP])}}, | ||
"message type " + messageType + " is not supported") | ||
$.assertConfig(.destination.Config.emersysUsername, "Emersys user name is not configured. Aborting"); | ||
$.assertConfig(.destination.Config.emersysUserSecret, "Emersys user secret is not configured. Aborting"); | ||
- name: validateInputForTrack | ||
description: Additional validation for Track events | ||
condition: $.outputs.messageType === {{$.EventType.TRACK}} | ||
template: | | ||
$.assert(.message.event, "event could not be mapped to conversion rule. Aborting.") | ||
- name: preparePayloadForIdentify | ||
description: | | ||
Builds identify payload. ref: https://dev.emarsys.com/docs/core-api-reference/f8ljhut3ac2i1-update-contacts | ||
condition: $.outputs.messageType === {{$.EventType.IDENTIFY}} | ||
template: | | ||
$.context.payload = $.buildIdentifyPayload(.message, .destination.Config,); | ||
- name: preparePayloadForGroup | ||
description: | | ||
Builds group payload. ref: https://dev.emarsys.com/docs/core-api-reference/1m0m70hy3tuov-add-contacts-to-a-contact-list | ||
condition: $.outputs.messageType === {{$.EventType.GROUP}} | ||
template: | | ||
$.context.payload = $.buildGroupPayload(.message, .destination.Config,); | ||
- name: preparePayloadForTrack | ||
description: | | ||
Builds track payload. ref: https://dev.emarsys.com/docs/core-api-reference/fl0xx6rwfbwqb-trigger-an-external-event | ||
condition: $.outputs.messageType === {{$.EventType.TRACK}} | ||
template: | | ||
const properties = ^.message.properties; | ||
const integrationObject = $.getIntegrationsObj(^.message, 'emarsys'); | ||
const emersysIdentifierId = $.deduceCustomIdentifier(integrationObject, ^.destination.Config.emersysCustomIdentifier); | ||
const payload = { | ||
key_id: emersysIdentifierId, | ||
external_id: $.deduceExternalIdValue(^.message,emersysIdentifierId,.destination.Config.fieldMapping), | ||
trigger_id: integrationObject.trigger_id, | ||
data: properties.data, | ||
attachment:$.CommonUtils.toArray(properties.attachment), | ||
event_time: $.getFieldValueFromMessage(^.message, 'timestamp'), | ||
}; | ||
$.context.payload = { | ||
eventType: ^.message.type, | ||
destinationPayload: { | ||
payload: $.removeUndefinedAndNullValues(payload), | ||
eventId: $.deduceEventId(^.message,.destination.Config), | ||
}, | ||
}; | ||
- name: buildResponse | ||
template: | | ||
const response = $.defaultRequestConfig(); | ||
response.body.JSON = $.context.payload; | ||
response.endpoint = $.deduceEndPoint($.context.payload,.destination.Config); | ||
response.method = "POST"; | ||
response.headers = $.buildHeader(.destination.Config) | ||
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,38 @@ | ||
bindings: | ||
- path: ./utils | ||
- name: handleRtTfSingleEventError | ||
path: ../../../../v0/util/index | ||
|
||
steps: | ||
- name: validateInput | ||
template: | | ||
$.assert(Array.isArray(^) && ^.length > 0, "Invalid event array") | ||
- name: transform | ||
externalWorkflow: | ||
path: ./procWorkflow.yaml | ||
bindings: | ||
- name: batchMode | ||
value: true | ||
loopOverInput: true | ||
- name: successfulEvents | ||
template: | | ||
$.outputs.transform#idx.output.({ | ||
"message": .[], | ||
"destination": ^ [idx].destination, | ||
"metadata": ^ [idx].metadata | ||
})[] | ||
- name: failedEvents | ||
template: | | ||
$.outputs.transform#idx.error.( | ||
$.handleRtTfSingleEventError(^[idx], .originalError ?? ., {}) | ||
)[] | ||
- name: batchSuccessfulEvents | ||
description: Batches the successfulEvents | ||
template: | | ||
$.context.batchedPayload = $.batchResponseBuilder($.outputs.successfulEvents); | ||
- name: finalPayload | ||
template: | | ||
[...$.outputs.failedEvents, ...$.context.batchedPayload] |
Oops, something went wrong.