Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:rudderlabs/rudder-transformer in…
Browse files Browse the repository at this point in the history
…to feat.oauth-access-denied-handling
  • Loading branch information
Sai Sankeerth committed Sep 15, 2023
2 parents 9f2b08e + 0f3b39e commit 6c7bc49
Show file tree
Hide file tree
Showing 12 changed files with 1,556 additions and 305 deletions.
104 changes: 104 additions & 0 deletions src/cdk/v2/destinations/fullstory/procWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
bindings:
- name: EventType
path: ../../../../constants
- path: ../../bindings/jsontemplate
exportAll: true
- name: removeUndefinedAndNullValues
path: ../../../../v0/util

steps:
- name: validateInput
template: |
$.assert(.message.type, "message Type is not present. Aborting message.");
$.assert(.message.type in {{$.EventType.([.TRACK, .IDENTIFY])}},
"message type " + .message.type + " is not supported");
- name: prepareContext
template: |
$.context.messageType = .message.type.toLowerCase();
$.context.payload = {};
$.context.finalHeaders = {
"authorization": "Basic " + .destination.Config.apiKey,
"content-type": "application/json"
};
- name: identifyPayload
condition: $.context.messageType == "identify"
template: |
$.context.endpoint = "https://api.fullstory.com/v2/users";
$.context.payload.properties = .message.traits ?? .message.context.traits;
$.context.payload.uid = .message.userId;
$.context.payload.email = .message.context.traits.email;
$.context.payload.display_name = .message.context.traits.name;
- name: trackPayload
condition: $.context.messageType == "track"
template: |
$.context.endpoint = "https://api.fullstory.com/v2/events";
$.context.payload.name = .message.event;
$.context.payload.properties = .message.properties;
$.context.payload.timestamp = .message.originalTimestamp;
$.context.payload.context = {};
- name: validateEventName
condition: $.context.messageType == "track"
template: |
$.assert(.message.event, "event is required for track call")
- name: mapContextFieldsForTrack
condition: $.context.messageType == "track"
template: |
$.context.payload.context.browser = {
"url": .message.context.page.url,
"user_agent": .message.context.userAgent,
"initial_referrer": .message.context.page.initial_referrer,
};
$.context.payload.context.mobile = {
"app_name": .message.context.app.name,
"app_version": .message.context.app.version,
};
$.context.payload.context.device = {
"manufacturer": .message.context.device.manufacturer,
"model": .message.context.device.model,
};
$.context.payload.context.location = {
"ip_address": .message.context.ip,
"latitude": .message.properties.latitude,
"longitude": .message.properties.longitude,
"city": .message.properties.city,
"region": .message.properties.region,
"country": .message.properties.country,
};
- name: mapIdsForTrack
condition: $.context.messageType == "track"
template: |
$.context.payload.session = {
"id": .message.properties.sessionId,
"use_most_recent": .message.properties.useMostRecent,
};
$.context.payload.user = {
"id": .message.properties.userId ?? .message.userId,
}
- 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": {}
})
77 changes: 33 additions & 44 deletions src/v0/destinations/marketo/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const tags = require('../../util/tags');
* https://developers.marketo.com/rest-api/error-codes/
*/

const ERROR_CODE_TO_PASS = ['1015'];

const MARKETO_RETRYABLE_CODES = ['601', '602', '604', '611'];
const MARKETO_ABORTABLE_CODES = [
'600',
Expand All @@ -36,28 +34,29 @@ const MARKETO_ABORTABLE_CODES = [
];
const MARKETO_THROTTLED_CODES = ['502', '606', '607', '608', '615'];

// Keeping here for reference const RECORD_LEVEL_ABORTBALE_ERRORS = [
// '1001',
// '1002',
// '1003',
// '1004',
// '1005',
// '1006',
// '1007',
// '1008',
// '1011',
// '1013',
// '1014',
// '1016',
// '1017',
// '1018',
// '1021',
// '1026',
// '1027',
// '1028',
// '1036',
// '1049',
// ];
const RECORD_LEVEL_ABORTBALE_ERRORS = [
'1001',
'1002',
'1003',
'1004',
'1005',
'1006',
'1007',
'1008',
'1011',
'1013',
'1014',
'1015',
'1016',
'1017',
'1018',
'1021',
'1026',
'1027',
'1028',
'1036',
'1049',
];

const { DESTINATION } = require('./config');
const logger = require('../../../logger');
Expand Down Expand Up @@ -87,7 +86,7 @@ const marketoApplicationErrorHandler = (marketoResponse, sourceMessage, destinat
};
/**
* this function checks the status of individual responses and throws error if any
* response status does not match the expected status
* response ststus does not match the expected status
* doc1: https://developers.marketo.com/rest-api/lead-database/custom-objects/#create_and_update
* doc2: https://developers.marketo.com/rest-api/lead-database/#create_and_update
* Structure of marketoResponse: {
Expand Down Expand Up @@ -123,27 +122,17 @@ const marketoApplicationErrorHandler = (marketoResponse, sourceMessage, destinat
const nestedResponseHandler = (marketoResponse, sourceMessage) => {
const checkStatus = (res) => {
const { status } = res;
const allowedStatus = ['updated', 'added', 'removed', 'created'];
if (
status &&
!allowedStatus.includes(status)
// we need to check the case where the id are not in list
) {
if (status && status !== 'updated' && status !== 'created' && status !== 'added') {
const { reasons } = res;
let statusCode = 400;
if (reasons) {
const errorCodesFromDest = reasons.map((reason) => reason.code);
const filteredErrorCode = errorCodesFromDest.find(
(errorCode) => !ERROR_CODE_TO_PASS.includes(errorCode),
);
if (!filteredErrorCode) {
return;
}
if (MARKETO_THROTTLED_CODES.includes(filteredErrorCode.code)) {
statusCode = 429;
} else if (MARKETO_RETRYABLE_CODES.includes(filteredErrorCode.code)) {
statusCode = 500;
}
if (reasons && RECORD_LEVEL_ABORTBALE_ERRORS.includes(reasons[0].code)) {
statusCode = 400;
} else if (reasons && MARKETO_ABORTABLE_CODES.includes(reasons[0].code)) {
statusCode = 400;
} else if (reasons && MARKETO_THROTTLED_CODES.includes(reasons[0].code)) {
statusCode = 429;
} else if (reasons && MARKETO_RETRYABLE_CODES.includes(reasons[0].code)) {
statusCode = 500;
}
throw new InstrumentationError(
`Request failed during: ${sourceMessage}, error: ${JSON.stringify(reasons)}`,
Expand Down
Loading

0 comments on commit 6c7bc49

Please sign in to comment.