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: Added validation for constructor #568

Merged
merged 3 commits into from
Jul 21, 2022
Merged
Changes from 2 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
27 changes: 24 additions & 3 deletions analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,28 @@ class Analytics {
this.readyCallbacks.forEach((callback) => callback());
}

/**
* A function to validate integration SDK is available in window
* and integration constructor is not undefined
* @param {string} pluginName
* @param {string} modName
* @returns boolean
*/
integrationSDKLoaded(pluginName, modName) {
try {
if (
window.hasOwnProperty(pluginName) &&
typeof window[pluginName][modName].prototype.constructor !== 'undefined'
) {
return true;
}
return false;
MoumitaM marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
handleError(e);
return false;
}
}

/**
* Process the response from control plane and
* call initialize for integrations
Expand Down Expand Up @@ -254,7 +276,7 @@ class Analytics {

const self = this;
const interval = setInterval(function () {
if (window.hasOwnProperty(pluginName)) {
if (self.integrationSDKLoaded(pluginName, modName)) {
const intMod = window[pluginName];
clearInterval(interval);

Expand Down Expand Up @@ -654,7 +676,7 @@ class Analytics {
checkReservedKeywords(rudderElement.message, type);

// if not specified at event level, All: true is default
const clientSuppliedIntegrations = rudderElement.message.integrations || { 'All' : true };
const clientSuppliedIntegrations = rudderElement.message.integrations || { All: true };

// structure user supplied integrations object to rudder format
transformToRudderNames(clientSuppliedIntegrations);
Expand All @@ -667,7 +689,6 @@ class Analytics {
// new event processing after analytics initialized but integrations not fetched from BE
this.toBeProcessedByIntegrationArray.push([type, rudderElement]);
} else {

// get intersection between config plane native enabled destinations
// (which were able to successfully load on the page) vs user supplied integrations
const succesfulLoadedIntersectClientSuppliedIntegrations = findAllEnabledDestinations(
Expand Down