-
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: new destination for accoil analytics
- Loading branch information
Showing
5 changed files
with
962 additions
and
0 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
src/cdk/v2/destinations/accoil_analytics/procWorkflow.yaml
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,123 @@ | ||
bindings: | ||
- name: EventType | ||
path: ../../../../constants | ||
- path: ../../bindings/jsontemplate | ||
exportAll: true | ||
- name: removeUndefinedAndNullValues | ||
path: ../../../../v0/util | ||
- name: base64Convertor | ||
path: ../../../../v0/util | ||
- path: ./utils | ||
|
||
steps: | ||
- name: validateInput | ||
template: | | ||
$.assert(.message.type, "message type is not present. Aborting message."); | ||
$.assert(.message.type in {{$.EventType.([.TRACK, .PAGE, .SCREEN, .IDENTIFY, .GROUP])}}, | ||
"message type " + .message.type + " is not supported"); | ||
$.assertConfig(.destination.Config.apiKey, "apiKey must be supplied in destination config"); | ||
# Note our auth does not require a password in basic auth just the string "key:" | ||
- name: prepareContext | ||
template: | | ||
$.context.messageType = .message.type.toLowerCase(); | ||
$.context.payload = { | ||
"type": $.context.messageType | ||
}; | ||
$.context.finalHeaders = { | ||
"authorization": "Basic " + $.base64Convertor(.destination.Config.apiKey + ":"), | ||
"content-type": "application/json" | ||
}; | ||
$.context.endpoint = $.endpointUrl(.destination.Config.apiKey); | ||
- name: trackPayload | ||
condition: $.context.messageType == {{$.EventType.TRACK}} | ||
template: | | ||
$.context.payload.event = .message.event; | ||
$.context.payload.userId = .message.().({{{{$.getGenericPaths("userId")}}}}) | ||
$.context.payload.timestamp = .message.().({{{{$.getGenericPaths("timestamp")}}}}) | ||
- name: pagePayload | ||
condition: $.context.messageType == {{$.EventType.PAGE}} | ||
template: | | ||
$.context.payload.userId = .message.().({{{{$.getGenericPaths("userId")}}}}); | ||
$.context.payload.name = .message.name; | ||
$.context.payload.timestamp = .message.().({{{{$.getGenericPaths("timestamp")}}}}); | ||
- name: screenPayload | ||
condition: $.context.messageType == {{$.EventType.SCREEN}} | ||
template: | | ||
$.context.payload.userId = .message.().({{{{$.getGenericPaths("userId")}}}}); | ||
$.context.payload.name = .message.name; | ||
$.context.payload.timestamp = .message.().({{{{$.getGenericPaths("timestamp")}}}}); | ||
- name: identifyPayload | ||
condition: $.context.messageType == {{$.EventType.IDENTIFY}} | ||
template: | | ||
$.context.payload.userId = .message.().({{{{$.getGenericPaths("userId")}}}}); | ||
$.context.payload.traits = .message.traits ?? .message.context.traits; | ||
$.context.payload.timestamp = .message.().({{{{$.getGenericPaths("timestamp")}}}}); | ||
- name: groupPayload | ||
condition: $.context.messageType == {{$.EventType.GROUP}} | ||
template: | | ||
$.context.payload.anonymousId = .message.anonymousId; | ||
$.context.payload.userId = .message.().({{{{$.getGenericPaths("userId")}}}}); | ||
$.context.payload.groupId = .message.groupId; | ||
$.context.payload.timestamp = .message.().({{{{$.getGenericPaths("timestamp")}}}}); | ||
$.context.payload.traits = .message.traits ?? .message.context.traits; | ||
- name: validateTimestamp | ||
template: | | ||
$.assert($.context.payload.timestamp, "timestamp is required for all calls") | ||
- name: validateTrackPayload | ||
condition: $.context.messageType == {{$.EventType.TRACK}} | ||
template: | | ||
$.assert($.context.payload.event, "event is required for track call") | ||
$.assert($.context.payload.userId, "userId is required for track call") | ||
- name: validatePagePayload | ||
condition: $.context.messageType == {{$.EventType.PAGE}} | ||
template: | | ||
$.assert($.context.payload.name, "name is required for page call") | ||
$.assert($.context.payload.userId, "userId is required for page call") | ||
- name: validateScreenPayload | ||
condition: $.context.messageType == {{$.EventType.SCREEN}} | ||
template: | | ||
$.assert($.context.payload.name, "name is required for screen call") | ||
$.assert($.context.payload.userId, "userId is required for screen call") | ||
- name: validateIdentifyPayload | ||
condition: $.context.messageType == {{$.EventType.IDENTIFY}} | ||
template: | | ||
$.assert($.context.payload.userId, "userId is required for identify call") | ||
- name: validateGroupPayload | ||
condition: $.context.messageType == {{$.EventType.GROUP}} | ||
template: | | ||
$.assert($.context.payload.userId, "userId is required for group call") | ||
$.assert($.context.payload.groupId, "groupId is required for group call") | ||
- name: cleanPayload | ||
template: | | ||
$.context.payload = $.removeUndefinedAndNullValues($.context.payload); | ||
- name: buildResponseForProcessTransformation | ||
template: | | ||
$.context.payload.({ | ||
"body": { | ||
"JSON": ., | ||
"JSON_ARRAY": {}, | ||
"XML": {}, | ||
"FORM": {} | ||
}, | ||
"version": "1", | ||
"type": "REST", | ||
"method": "POST", | ||
"endpoint": $.context.endpoint, | ||
"headers": $.context.finalHeaders, | ||
"params": {}, | ||
"files": {} | ||
}) |
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,33 @@ | ||
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 | ||
template: | | ||
$.outputs.transform#idx.output.({ | ||
"batchedRequest": ., | ||
"batched": false, | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const stgRegex = new RegExp(/^stg_/, 'i'); | ||
|
||
const endpointUrl = (apiKey) => { | ||
const staging = stgRegex.test(apiKey); | ||
return staging ? 'https://instaging.accoil.com/segment' : 'https://in.accoil.com/segment'; | ||
}; | ||
|
||
module.exports = { | ||
endpointUrl, | ||
}; |
Oops, something went wrong.