Skip to content

Commit

Permalink
Added new destination for Accoil Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
accoilmj committed Nov 18, 2024
1 parent 79e5979 commit 5b571a9
Show file tree
Hide file tree
Showing 5 changed files with 962 additions and 0 deletions.
123 changes: 123 additions & 0 deletions src/cdk/v2/destinations/accoil_analytics/procWorkflow.yaml
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": {}
})
33 changes: 33 additions & 0 deletions src/cdk/v2/destinations/accoil_analytics/rtWorkflow.yaml
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]
10 changes: 10 additions & 0 deletions src/cdk/v2/destinations/accoil_analytics/utils.js
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,
};
Loading

0 comments on commit 5b571a9

Please sign in to comment.