Skip to content

Commit

Permalink
Merge pull request #185 from rudderlabs/production-staging
Browse files Browse the repository at this point in the history
Production <-- staging
  • Loading branch information
sayan-mitra authored Jan 8, 2021
2 parents eacba51 + b09a68f commit 72a6227
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
5 changes: 4 additions & 1 deletion analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
findAllEnabledDestinations,
tranformToRudderNames,
transformToServerNames,
checkReservedKeywords,
} from "./utils/utils";
import {
CONFIG_URL,
Expand Down Expand Up @@ -529,7 +530,6 @@ class Analytics {
} else {
rudderElement.setProperty({});
}

this.trackEvent(rudderElement, options, callback);
}

Expand Down Expand Up @@ -668,6 +668,9 @@ class Analytics {
this.processOptionsParam(rudderElement, options);
logger.debug(JSON.stringify(rudderElement));

// check for reserved keys and log
checkReservedKeywords(rudderElement.message, type);

// structure user supplied integrations object to rudder format
if (Object.keys(rudderElement.message.integrations).length > 0) {
tranformToRudderNames(rudderElement.message.integrations);
Expand Down
12 changes: 12 additions & 0 deletions utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
// Reserved Keywords for properties/triats
const ReservedPropertyKeywords = [
"anonymous_id",
"id",
"sent_at",
"received_at",
"timestamp",
"original_timestamp",
"event_text",
"event",
];
// Message Type enumeration
const MessageType = {
TRACK: "track",
Expand Down Expand Up @@ -79,6 +90,7 @@ const MAX_WAIT_FOR_INTEGRATION_LOAD = 10000;
const INTEGRATION_LOAD_CHECK_INTERVAL = 1000;

export {
ReservedPropertyKeywords,
MessageType,
ECommerceParamNames,
ECommerceEvents,
Expand Down
41 changes: 40 additions & 1 deletion utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parse } from "component-url";
import logger from "./logUtil";
import { commonNames } from "../integrations/integration_cname";
import { clientToServerNames } from "../integrations/client_server_name";
import { CONFIG_URL } from "./constants";
import { CONFIG_URL, ReservedPropertyKeywords } from "./constants";

/**
*
Expand Down Expand Up @@ -419,6 +419,44 @@ function getUserProvidedConfigUrl(configUrl) {
}
return url;
}
/**
* Check if a reserved keyword is present in properties/traits
* @param {*} properties
* @param {*} reservedKeywords
* @param {*} type
*/
function checkReservedKeywords(message, messageType) {
// properties, traits, contextualTraits are either undefined or object
const { properties, traits } = message;
const contextualTraits = message.context.traits;
if (properties) {
Object.keys(properties).forEach((property) => {
if (ReservedPropertyKeywords.indexOf(property.toLowerCase()) >= 0) {
logger.error(
`Warning! : Reserved keyword used in properties--> ${property} with ${messageType} call`
);
}
});
}
if (traits) {
Object.keys(traits).forEach((trait) => {
if (ReservedPropertyKeywords.indexOf(trait.toLowerCase()) >= 0) {
logger.error(
`Warning! : Reserved keyword used in traits--> ${trait} with ${messageType} call`
);
}
});
}
if (contextualTraits) {
Object.keys(contextualTraits).forEach((contextTrait) => {
if (ReservedPropertyKeywords.indexOf(contextTrait.toLowerCase()) >= 0) {
logger.error(
`Warning! : Reserved keyword used in traits --> ${contextTrait} with ${messageType} call`
);
}
});
}
}

/* ------- Start FlattenJson -----------
* This function flatten given json object to single level.
Expand Down Expand Up @@ -469,4 +507,5 @@ export {
rejectArr,
type,
flattenJsonPayload,
checkReservedKeywords,
};

0 comments on commit 72a6227

Please sign in to comment.