From 0d0570f1737a274b81f783e7757b60462fb9a734 Mon Sep 17 00:00:00 2001 From: David Meiklejohn Date: Tue, 12 Nov 2024 11:59:03 +1000 Subject: [PATCH] WIP --- .../destinations/accoil_analytics/config.js | 0 .../accoil_analytics/procWorkflow.yaml | 129 ++++++++++++++++++ .../accoil_analytics/rtWorkflow.yaml | 0 .../v2/destinations/accoil_analytics/utils.js | 10 ++ 4 files changed, 139 insertions(+) create mode 100644 src/cdk/v2/destinations/accoil_analytics/config.js create mode 100644 src/cdk/v2/destinations/accoil_analytics/procWorkflow.yaml create mode 100644 src/cdk/v2/destinations/accoil_analytics/rtWorkflow.yaml create mode 100644 src/cdk/v2/destinations/accoil_analytics/utils.js diff --git a/src/cdk/v2/destinations/accoil_analytics/config.js b/src/cdk/v2/destinations/accoil_analytics/config.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/cdk/v2/destinations/accoil_analytics/procWorkflow.yaml b/src/cdk/v2/destinations/accoil_analytics/procWorkflow.yaml new file mode 100644 index 0000000000..fd81f9d7d7 --- /dev/null +++ b/src/cdk/v2/destinations/accoil_analytics/procWorkflow.yaml @@ -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": {} + }) \ No newline at end of file diff --git a/src/cdk/v2/destinations/accoil_analytics/rtWorkflow.yaml b/src/cdk/v2/destinations/accoil_analytics/rtWorkflow.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/cdk/v2/destinations/accoil_analytics/utils.js b/src/cdk/v2/destinations/accoil_analytics/utils.js new file mode 100644 index 0000000000..7a6c63d4ce --- /dev/null +++ b/src/cdk/v2/destinations/accoil_analytics/utils.js @@ -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, +}; \ No newline at end of file