Skip to content

Commit

Permalink
feat(INT-305): onboard gladly destination (#2786)
Browse files Browse the repository at this point in the history
* feat: onboard gladly destination

* chore: code review changes

* chore: code review changes

* chore: code review changes

* chore: code review changes

* chore: code review changes

* chore: code review changes

* chore: code review changes

* chore: code review changes

* fix: package.json changes

* chore: added utility tests

* chore: added gladly router and processor tests

* chore: added gladly rETL tests

* fix: sonar code smell

* chore: code review changes
  • Loading branch information
mihir-4116 authored Nov 14, 2023
1 parent 06c6503 commit ff80b88
Show file tree
Hide file tree
Showing 13 changed files with 2,456 additions and 30 deletions.
131 changes: 109 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@ndhoule/extend": "^2.0.0",
"@pyroscope/nodejs": "^0.2.6",
"@rudderstack/integrations-lib": "^0.1.8",
"@rudderstack/workflow-engine": "^0.5.7",
"@rudderstack/workflow-engine": "^0.6.9",
"ajv": "^8.12.0",
"ajv-draft-04": "^1.0.0",
"ajv-formats": "^2.1.1",
Expand Down
88 changes: 88 additions & 0 deletions src/cdk/v2/destinations/gladly/procWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
bindings:
- name: EventType
path: ../../../../constants
- path: ./utils
exportAll: true
- name: defaultRequestConfig
path: ../../../../v0/util
- name: removeUndefinedAndNullValues
path: ../../../../v0/util
- name: getDestinationExternalID
path: ../../../../v0/util
- name: httpGET
path: ../../../../adapters/network
- name: processAxiosResponse
path: ../../../../adapters/utils/networkUtils


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")
$.assert(messageType in {{$.EventType.([.IDENTIFY])}}, "message type " + messageType + " is not supported")
$.assertConfig(.destination.Config.apiToken, "API Token is not present. Aborting")
$.assertConfig(.destination.Config.domain, "Gladly domain is not present. Aborting")
$.assertConfig(.destination.Config.userName, "User Name is not present. Aborting")
- name: preparePayload
template: |
$.context.payload = {
name: .message.traits.name || .message.context.traits.name,
image: .message.traits.avatar || .message.context.traits.avatar,
address: .message.traits.address || .message.context.traits.address
}
$.context.payload.address && typeof $.context.payload.address === "object" ? $.context.payload.address = JSON.stringify($.context.payload.address)
$.context.payload.emails = $.formatField(.message, "email")
$.context.payload.phones = $.formatField(.message, "phone")
$.context.payload.customAttributes = $.getCustomAttributes(.message)
$.context.payload.externalCustomerId = $.getExternalCustomerId(.message)
$.context.payload.id = $.getCustomerId(.message)
$.context.payload = $.removeUndefinedAndNullValues($.context.payload)
- name: validatePayload
template: |
$.validatePayload($.context.payload)
- name: findCustomer
description: Find if customer is exist or not based on email, phone or externalCustomerId
condition: $.getQueryParams($.context.payload) !== undefined
template: |
const requestOptions = {
headers: $.getHeaders(.destination)
}
const endpoint = $.getEndpoint(.destination) + "?" + $.getQueryParams($.context.payload);
const rawResponse = await $.httpGET(endpoint,requestOptions)
const processedResponse = $.processAxiosResponse(rawResponse)
processedResponse
- name: createCustomer
description: Build response for create customer
condition: $.outputs.findCustomer.status === 400 || ($.outputs.findCustomer.status === 200 && $.outputs.findCustomer.response.length === 0) || $.getQueryParams($.context.payload) === undefined
template: |
const response = $.defaultRequestConfig()
response.body.JSON = $.removeUndefinedAndNullValues($.context.payload)
response.endpoint = $.getEndpoint(.destination)
response.method = "POST"
response.headers = $.getHeaders(.destination)
response
else:
name: updateCustomer
description: Build response for update customer
template: |
const response = $.defaultRequestConfig()
response.body.JSON = $.removeUndefinedAndNullValues($.context.payload.{~["id"]})
response.endpoint = $.getEndpoint(.destination) + "/" + $.outputs.findCustomer.response[0].id
response.method = "PATCH"
response.headers = $.getHeaders(.destination)
response
33 changes: 33 additions & 0 deletions src/cdk/v2/destinations/gladly/rtWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
bindings:
- name: handleRtTfSingleEventError
path: ../../../../v0/util/index
- path: ./utils
exportAll: true

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.successfulEvents, ...$.outputs.failedEvents]
Loading

0 comments on commit ff80b88

Please sign in to comment.