Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: covert toString before toLowercase #2830

Merged
merged 7 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/v0/destinations/active_campaign/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const tags = require('../../util/tags');

const errorHandler = (httpCallError, message) => {
const {response, status} = processAxiosResponse(httpCallError);
const { response, status } = processAxiosResponse(httpCallError);

Check warning on line 9 in src/v0/destinations/active_campaign/util.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/active_campaign/util.js#L9

Added line #L9 was not covered by tests
let msg = message;
if (response) {
msg = `${message} (${httpCallError.response?.statusText},${JSON.stringify(response)})`;
Expand Down
2 changes: 1 addition & 1 deletion src/v0/destinations/adobe_analytics/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ module.exports = {
ECOM_PRODUCT_EVENTS,
commonConfig: MAPPING_CONFIG[CONFIG_CATEGORIES.COMMON.name],
formatDestinationConfig,
DESTINATION: 'ADOBE_ANALYTICS'
DESTINATION: 'ADOBE_ANALYTICS',
};
17 changes: 9 additions & 8 deletions src/v0/destinations/adobe_analytics/networkHandler.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const { proxyRequest, prepareProxyRequest } = require('../../../adapters/network');
const {
processAxiosResponse,
} = require('../../../adapters/utils/networkUtils');
const { processAxiosResponse } = require('../../../adapters/utils/networkUtils');
const { DESTINATION } = require('./config');


/**
* Extract data inside different tags from an xml payload
* @param {*} xml
* @param {*} tagName
* @param {*} xml
* @param {*} tagName
* @returns data inside the tagName
*/
function extractContent(xmlPayload, tagName) {
Expand All @@ -29,9 +26,13 @@ const responseHandler = (destinationResponse, dest) => {
// if the status tag in XML contains FAILURE, we build and throw an explicit error
if (responseStatus === 'FAILURE') {
if (reason) {
throw new InstrumentationError(`[${DESTINATION} Response Handler] Request failed for destination ${dest} : ${reason}` )
throw new InstrumentationError(
`[${DESTINATION} Response Handler] Request failed for destination ${dest} : ${reason}`,
);
} else {
throw new InstrumentationError(`[${DESTINATION} Response Handler] Request failed for destination ${dest} with a general error`)
throw new InstrumentationError(
`[${DESTINATION} Response Handler] Request failed for destination ${dest} with a general error`,
);
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/v0/destinations/braze/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {
getFieldValueFromMessage,
removeUndefinedValues,
isHttpStatusSuccess,
isDefinedAndNotNull,
simpleProcessRouterDestSync,
simpleProcessRouterDest,
isNewStatusCodesAccepted,
Expand Down Expand Up @@ -153,11 +154,16 @@ function getUserAttributesObject(message, mappingJson, destination) {
Object.keys(mappingJson).forEach((destKey) => {
let value = get(traits, mappingJson[destKey]);
if (value || (value === null && reservedKeys.includes(destKey))) {
// if email is not string remove it from attributes
if (destKey === 'email' && typeof value !== 'string') {
throw new InstrumentationError('Invalid email, email must be a valid string');
}

// handle gender special case
if (destKey === 'gender') {
value = formatGender(value);
} else if (destKey === 'email' && value !== null) {
value = value?.toLowerCase();
} else if (destKey === 'email' && isDefinedAndNotNull(value)) {
value = value.toString().toLowerCase();
}
data[destKey] = value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/v0/util/errorTypes/transformerProxyError.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ class TransformerProxyError extends BaseError {
}
}

module.exports = TransformerProxyError;
module.exports = TransformerProxyError;
18 changes: 9 additions & 9 deletions src/v1/destinations/campaign_manager/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ const responseHandler = (destinationResponse) => {
}

throw new TransformerProxyError(
`Campaign Manager: Error transformer proxy v1 during CAMPAIGN_MANAGER response transformation`,
500,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
destinationResponse,
getAuthErrCategoryFromStCode(status),
responseWithIndividualEvents,
);
`Campaign Manager: Error transformer proxy v1 during CAMPAIGN_MANAGER response transformation`,
500,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
},
destinationResponse,
getAuthErrCategoryFromStCode(status),
responseWithIndividualEvents,
);
};

function networkHandler() {
Expand Down
45 changes: 45 additions & 0 deletions test/__tests__/data/braze_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -1910,5 +1910,50 @@
"type": "track",
"userId": ""
}
},
{
"destination": {
"Config": {
"restApiKey": "dummyApiKey",
"prefixProperties": true,
"useNativeSDK": false,
"dataCenter": "us-01"
},
"DestinationDefinition": {
"DisplayName": "Braze",
"ID": "1WhbSZ6uA3H5ChVifHpfL2H6sie",
"Name": "BRAZE"
},
"Enabled": true,
"ID": "1WhcOCGgj9asZu850HvugU2C3Aq",
"Name": "Braze",
"Transformations": []
},
"message": {
"anonymousId": "e6ab2c5e-2cda-44a9-a962-e2f67df78bca",
"channel": "web",
"context": {
"traits": {
"city": "Disney",
"country": "USA",
"email": 123,
"firstname": "Mickey",
"closed_at": null,
"orderTotal": 0
},
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36"
},
"integrations": {
"All": true
},
"messageId": "2536eda4-d638-4c93-8014-8ffe3f083214",
"originalTimestamp": "2020-01-24T06:29:02.362Z",
"receivedAt": "2020-01-24T11:59:02.403+05:30",
"request_ip": "[::1]:53709",
"sentAt": "2020-01-24T06:29:02.363Z",
"timestamp": "2020-01-24T11:59:02.402+05:30",
"type": "identify",
"userId": ""
}
}
]
4 changes: 4 additions & 0 deletions test/__tests__/data/braze_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -1034,5 +1034,9 @@
"type": "REST",
"userId": "e6ab2c5e-2cda-44a9-a962-e2f67df78bca",
"version": "1"
},
{
"statusCode": 400,
"message": "Invalid email, email must be a valid string"
}
]
Loading
Loading