Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
accoilmj committed Nov 14, 2024
1 parent c51cfbb commit 0d0570f
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
Empty file.
129 changes: 129 additions & 0 deletions src/cdk/v2/destinations/accoil_analytics/procWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
bindings:
- name: EventType
path: ../../../../constants
- path: ../../bindings/jsontemplate
exportAll: true
- name: removeUndefinedAndNullValues
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");
- name: prepareContext
template: |
$.context.messageType = .message.type.toLowerCase();
$.context.payload = {
"type": $.context.messageType
};
$.context.finalHeaders = {
"authorization": "Basic " + .destination.Config.apiKey,
"content-type": "application/json"
};
$.context.endpoint = $.endpointUrl(.destination.Config.apiKey);
- name: trackPayload
condition: $.context.messageType == "track"
template: |
$.context.payload.event = .message.event;
$.context.payload.userId = .message.userId;
$.context.payload.timestamp = .message.timestamp;
- name: pagePayload
condition: $.context.messageType == "page"
template: |
$.context.payload.userId = .message.userId;
$.context.payload.name = .message.event;
$.context.payload.timestamp = .message.timestamp;
- name: screenPayload
condition: $.context.messageType == "screen"
template: |
$.context.payload.userId = .message.userId;
$.context.payload.name = .message.event;
$.context.payload.timestamp = .message.timestamp;
- name: identifyPayload
condition: $.context.messageType == "identify"
template: |
$.context.payload.userId = .message.userId;
$.context.payload.traits = .message.traits ?? .message.context.traits;
# $.context.payload.traits.email = .message.traits.email;
# $.context.payload.traits.name = .message.traits.name;
# $.context.payload.traits.role = .message.traits.role;
# $.context.payload.traits.createdAt = .message.traits.createdAt;
# $.context.payload.traits.accountStatus = .message.traits.accountStatus;

- name: groupPayload
condition: $.context.messageType == "group"
template: |
$.context.payload.anonymousId = .message.anonymousId;
$.context.payload.userId = .message.userId;
$.context.payload.groupId = .message.groupId;
$.context.payload.name = .message.event;
$.context.payload.timestamp = .message.timestamp;
$.context.payload.traits = .message.traits ?? .message.context.traits;
# $.context.payload.traits.name = .message.traits.name;
# $.context.payload.traits.createdAt = .message.traits.createdAt;
# $.context.payload.traits.status = .message.traits.status;
# $.context.payload.traits.plan = .message.traits.plan;
# $.context.payload.traits.mrr = .message.traits.mrr;

- name: validateTimestamp
template: |
$.assert($.context.payload.timestamp, "timestamp is required for all calls")
- name: validateTrackPayload
condition: $.context.messageType == "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 == "page"
template: |
$.assert($.context.payload.userId, "userId is required for page call")
- name: validateScreenPayload
condition: $.context.messageType == "screen"
template: |
$.assert($.context.payload.userId, "userId is required for screen call")
$.assert($.context.payload.timestamp, "timestamp is required for screen call")
- name: validateIdentifyPayload
condition: $.context.messageType == "identify"
template: |
$.assert($.context.payload.userId, "userId is required for track call")
$.assert($.context.payload.timestamp, "timestamp is required for screen call")
- name: validateGroupyPayload
condition: $.context.messageType == "group"
template: |
$.assert($.context.payload.userId, "userId is required for track call")
$.assert($.context.payload.timestamp, "timestamp is required for screen 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": {}
})
Empty file.
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,
};

0 comments on commit 0d0570f

Please sign in to comment.