diff --git a/package-lock.json b/package-lock.json index 0822a9b42b..d988eccb57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@koa/router": "^12.0.0", "@ndhoule/extend": "^2.0.0", "@pyroscope/nodejs": "^0.2.6", - "@rudderstack/workflow-engine": "^0.5.7", + "@rudderstack/workflow-engine": "^0.6.8", "ajv": "^8.12.0", "ajv-draft-04": "^1.0.0", "ajv-formats": "^2.1.1", @@ -6638,42 +6638,80 @@ } }, "node_modules/@rudderstack/json-template-engine": { - "version": "0.5.5", - "license": "MIT" + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@rudderstack/json-template-engine/-/json-template-engine-0.8.1.tgz", + "integrity": "sha512-MR2ArfOXEDh9FEj/N3LVLjIxf134wq+YxUdZN4gTLEONIPdna97QeNk4hnhtlob0QQIrWr13mfPaU9FpvU2Q6Q==" }, "node_modules/@rudderstack/workflow-engine": { - "version": "0.5.7", - "license": "MIT", + "version": "0.6.8", + "resolved": "https://registry.npmjs.org/@rudderstack/workflow-engine/-/workflow-engine-0.6.8.tgz", + "integrity": "sha512-fJRbFmr9sJCmRdANqpoaQJ9NnepZrKDzY7s8jhtezLOBI6jaRovFoBHx4djspqazGTlU33FkXHT96HxNeZ7zuA==", "dependencies": { - "@aws-crypto/sha256-js": "^4.0.0", - "@rudderstack/json-template-engine": "^0.5.5", - "js-yaml": "^4.1.0", + "@aws-crypto/sha256-js": "^5.0.0", + "@rudderstack/json-template-engine": "^0.8.1", "jsonata": "^2.0.3", "lodash": "^4.17.21", - "object-sizeof": "^2.6.3" + "object-sizeof": "^2.6.3", + "yaml": "^2.3.2" } }, "node_modules/@rudderstack/workflow-engine/node_modules/@aws-crypto/sha256-js": { - "version": "4.0.0", - "license": "Apache-2.0", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@aws-crypto/sha256-js/-/sha256-js-5.2.0.tgz", + "integrity": "sha512-FFQQyu7edu4ufvIZ+OadFpHHOt+eSTBaYaki44c+akjg7qZg9oOQeLlk77F6tSYqjDAFClrHJk9tMf0HdVyOvA==", "dependencies": { - "@aws-crypto/util": "^4.0.0", + "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", - "tslib": "^1.11.1" + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" } }, "node_modules/@rudderstack/workflow-engine/node_modules/@aws-crypto/util": { - "version": "4.0.0", - "license": "Apache-2.0", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@aws-crypto/util/-/util-5.2.0.tgz", + "integrity": "sha512-4RkU9EsI6ZpBve5fseQlGNUWKMa1RLPQ1dnjnQoe07ldfIzcsGb5hC5W0Dm7u423KWzawlrpbjXBrXCEv9zazQ==", "dependencies": { "@aws-sdk/types": "^3.222.0", - "@aws-sdk/util-utf8-browser": "^3.0.0", - "tslib": "^1.11.1" + "@smithy/util-utf8": "^2.0.0", + "tslib": "^2.6.2" } }, - "node_modules/@rudderstack/workflow-engine/node_modules/tslib": { - "version": "1.14.1", - "license": "0BSD" + "node_modules/@rudderstack/workflow-engine/node_modules/@smithy/is-array-buffer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-2.0.0.tgz", + "integrity": "sha512-z3PjFjMyZNI98JFRJi/U0nGoLWMSJlDjAW4QUX2WNZLas5C0CmVV6LJ01JI0k90l7FvpmixjWxPFmENSClQ7ug==", + "dependencies": { + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@rudderstack/workflow-engine/node_modules/@smithy/util-buffer-from": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-2.0.0.tgz", + "integrity": "sha512-/YNnLoHsR+4W4Vf2wL5lGv0ksg8Bmk3GEGxn2vEQt52AQaPSCuaO5PM5VM7lP1K9qHRKHwrPGktqVoAHKWHxzw==", + "dependencies": { + "@smithy/is-array-buffer": "^2.0.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@rudderstack/workflow-engine/node_modules/@smithy/util-utf8": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-2.0.0.tgz", + "integrity": "sha512-rctU1VkziY84n5OXe3bPNpKR001ZCME2JCaBBFgtiM2hfKbHFudc/BkMuPab8hRbLd0j3vbnBTTZ1igBf0wgiQ==", + "dependencies": { + "@smithy/util-buffer-from": "^2.0.0", + "tslib": "^2.5.0" + }, + "engines": { + "node": ">=14.0.0" + } }, "node_modules/@sideway/address": { "version": "4.1.4", @@ -19352,8 +19390,9 @@ } }, "node_modules/tslib": { - "version": "2.5.3", - "license": "0BSD" + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" }, "node_modules/tsscmp": { "version": "1.0.6", @@ -19891,9 +19930,9 @@ "license": "ISC" }, "node_modules/yaml": { - "version": "2.3.1", - "dev": true, - "license": "ISC", + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.4.tgz", + "integrity": "sha512-8aAvwVUSHpfEqTQ4w/KMlf3HcRdt50E5ODIQJBw1fQ5RL34xabzxtUlzTXVqc4rkZsPbvrXKWnABCD7kWSmocA==", "engines": { "node": ">= 14" } diff --git a/package.json b/package.json index 46f728664d..1503650123 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "@koa/router": "^12.0.0", "@ndhoule/extend": "^2.0.0", "@pyroscope/nodejs": "^0.2.6", - "@rudderstack/workflow-engine": "^0.5.7", + "@rudderstack/workflow-engine": "^0.6.8", "ajv": "^8.12.0", "ajv-draft-04": "^1.0.0", "ajv-formats": "^2.1.1", diff --git a/src/cdk/v2/destinations/gladly/procWorkflow.yaml b/src/cdk/v2/destinations/gladly/procWorkflow.yaml index 5a4d3c337d..795aac9dac 100644 --- a/src/cdk/v2/destinations/gladly/procWorkflow.yaml +++ b/src/cdk/v2/destinations/gladly/procWorkflow.yaml @@ -3,8 +3,6 @@ bindings: path: ../../../../constants - path: ./utils exportAll: true - - name: isDefinedAndNotNull - path: ../../../../v0/util - name: defaultRequestConfig path: ../../../../v0/util - name: removeUndefinedAndNullValues @@ -45,7 +43,7 @@ steps: image: .message.context.traits.avatar || .message.traits.avatar, address: .message.context.traits.address || .message.traits.address } - $.context.payload.address ? $.context.payload.address = $.context.payload.address.toString() + $.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) @@ -62,6 +60,7 @@ steps: const endpoint = $.getEndpoint(.destination) const rawResponse = await $.httpPOST(endpoint, requestPayload, requestOptions) const processedResponse = $.processAxiosResponse(rawResponse) + processedResponse.status == 400 ? $.assertHttpResp(processedResponse, "Unable to create or update user due to " + JSON.stringify(processedResponse.response)); processedResponse - name: buildResponseForProcessTransformation diff --git a/src/cdk/v2/destinations/gladly/rtWorkflow.yaml b/src/cdk/v2/destinations/gladly/rtWorkflow.yaml index a907403ca4..bf08fd451f 100644 --- a/src/cdk/v2/destinations/gladly/rtWorkflow.yaml +++ b/src/cdk/v2/destinations/gladly/rtWorkflow.yaml @@ -1,6 +1,8 @@ bindings: - name: handleRtTfSingleEventError path: ../../../../v0/util/index + - path: ./utils + exportAll: true steps: - name: validateInput @@ -15,11 +17,11 @@ steps: - name: successfulEvents template: | $.outputs.transform#idx.output.({ - "batchedRequest": ., + "batchedRequest": $.getPayload(.), "batched": false, "destination": ^[idx].destination, "metadata": ^[idx].metadata[], - "statusCode": 200 + "statusCode": $.getStatusCode($.requestMetadata, $.outputs.transform#idx.output.status) })[] - name: failedEvents template: | diff --git a/src/cdk/v2/destinations/gladly/utils.js b/src/cdk/v2/destinations/gladly/utils.js index 17ee55bdc8..7aaf2ee359 100644 --- a/src/cdk/v2/destinations/gladly/utils.js +++ b/src/cdk/v2/destinations/gladly/utils.js @@ -1,6 +1,6 @@ -const { getFieldValueFromMessage, base64Convertor, getDestinationExternalID } = require('../../../../v0/util'); +const { getFieldValueFromMessage, base64Convertor, isNewStatusCodesAccepted } = require('../../../../v0/util'); +const { HTTP_STATUS_CODES } = require('../../../../v0/util/constant'); -const lookUpFields = ['email', 'phone', 'externalCustomerId']; const reservedCustomAttributes = [ 'email', 'phone', @@ -36,31 +36,6 @@ const formatField = (message, fieldName) => { return undefined; }; -const getQueryParams = (message, integrationsObj) => { - let queryParamKey; - let queryParamValue; - if (integrationsObj && integrationsObj.lookup){ - queryParamKey = integrationsObj.lookup; - } - if (!queryParamKey) { - queryParamKey = 'email'; - } - if (!lookUpFields.includes(queryParamKey)) { - queryParamKey = 'email'; - } - - if (queryParamKey === 'email' || queryParamKey === 'phone') { - queryParamValue = getFieldValueFromMessage(message,queryParamKey); - if (!queryParamValue) return undefined; - } else{ - queryParamValue = getDestinationExternalID(message, 'gladlyExternalCustomerId'); - if (!queryParamValue) return undefined; - } - - queryParamKey = queryParamKey === 'phone' ? 'phoneNumber' : queryParamKey; - return { key: queryParamKey, value: queryParamValue }; -}; - const getCustomAttributes = (message) => { const customAttributes = message.context.traits; reservedCustomAttributes.forEach((customAttribute) => { @@ -71,4 +46,17 @@ const getCustomAttributes = (message) => { return customAttributes; }; -module.exports = { formatField, getCustomAttributes, getEndpoint, getQueryParams, getHeaders }; +const getStatusCode = (requestMetadata, statusCode) => { + if(isNewStatusCodesAccepted(requestMetadata) && statusCode === 200){ + return HTTP_STATUS_CODES.SUPPRESS_EVENTS; + } + return statusCode; +} + +const getPayload = (eventPayload) => { + const payload = eventPayload; + delete payload.status; + return payload; +} + +module.exports = { formatField, getCustomAttributes, getEndpoint, getHeaders, getStatusCode, getPayload }; diff --git a/src/cdk/v2/handler.ts b/src/cdk/v2/handler.ts index 4b3868b85b..7dc0f5fd82 100644 --- a/src/cdk/v2/handler.ts +++ b/src/cdk/v2/handler.ts @@ -64,9 +64,9 @@ export function getCachedWorkflowEngine( return workflowEnginePromiseMap[destName][feature]; } -export async function executeWorkflow(workflowEngine: WorkflowEngine, parsedEvent: FixMe) { +export async function executeWorkflow(workflowEngine: WorkflowEngine, parsedEvent: FixMe, requestMetadata: NonNullable){ try { - const result = await workflowEngine.execute(parsedEvent); + const result = await workflowEngine.execute(parsedEvent, {requestMetadata}); // TODO: Handle remaining output scenarios return result.output; } catch (error) { @@ -78,11 +78,12 @@ export async function processCdkV2Workflow( destType: string, parsedEvent: FixMe, feature: string, + requestMetadata: NonNullable = {}, bindings: Record = {}, ) { try { const workflowEngine = await getCachedWorkflowEngine(destType, feature, bindings); - return await executeWorkflow(workflowEngine, parsedEvent); + return await executeWorkflow(workflowEngine, parsedEvent, requestMetadata); } catch (error) { throw getErrorInfo(error, isCdkV2Destination(parsedEvent), defTags); } diff --git a/src/services/destination/cdkV2Integration.ts b/src/services/destination/cdkV2Integration.ts index b4c0a15e87..672fe25245 100644 --- a/src/services/destination/cdkV2Integration.ts +++ b/src/services/destination/cdkV2Integration.ts @@ -52,7 +52,7 @@ export default class CDKV2DestinationService implements IntegrationDestinationSe events: ProcessorTransformationRequest[], destinationType: string, _version: string, - _requestMetadata: NonNullable, + requestMetadata: NonNullable, ): Promise { // TODO: Change the promise type const respList: ProcessorTransformationResponse[][] = await Promise.all( @@ -64,6 +64,7 @@ export default class CDKV2DestinationService implements IntegrationDestinationSe destinationType, event, tags.FEATURES.PROCESSOR, + requestMetadata ); stats.increment('event_transform_success', { @@ -108,7 +109,7 @@ export default class CDKV2DestinationService implements IntegrationDestinationSe events: RouterTransformationRequestData[], destinationType: string, _version: string, - _requestMetadata: NonNullable, + requestMetadata: NonNullable, ): Promise { const allDestEvents: object = groupBy( events, @@ -126,7 +127,7 @@ export default class CDKV2DestinationService implements IntegrationDestinationSe metaTo.metadata = destInputArray[0].metadata; try { const doRouterTransformationResponse: RouterTransformationResponse[] = - await processCdkV2Workflow(destinationType, destInputArray, tags.FEATURES.ROUTER); + await processCdkV2Workflow(destinationType, destInputArray, tags.FEATURES.ROUTER, requestMetadata); return DestinationPostTransformationService.handleRouterTransformSuccessEvents( doRouterTransformationResponse, undefined,