Socket
Socket
Sign inDemoInstall

@mparticle/web-sdk

Package Overview
Dependencies
Maintainers
10
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mparticle/web-sdk - npm Package Compare versions

Comparing version 2.11.16 to 2.12.0

src/configAPIClient.js

5

CHANGELOG.md

@@ -5,2 +5,7 @@ ## Releases

#### 2.12.0 - 2020-10-29
- Feat - Implement client side kit blocking
You can now use Data Master to block unplanned events and attributes from being sent to client side forwarders.
#### 2.11.16 - 2020-10-26

@@ -7,0 +12,0 @@

4

package.json
{
"name": "@mparticle/web-sdk",
"version": "2.11.16",
"version": "2.12.0",
"description": "mParticle core SDK for web applications",

@@ -67,3 +67,5 @@ "license": "Apache-2.0",

"@babel/preset-typescript": "^7.6.0",
"@mparticle/data-planning-models": "^0.1.0",
"@mparticle/event-models": "^1.1.2",
"@rollup/plugin-json": "^4.1.0",
"@types/chai": "^4.2.3",

@@ -70,0 +72,0 @@ "@types/mocha": "^5.2.7",

@@ -5,6 +5,5 @@ import Constants from './constants';

var HTTPCodes = Constants.HTTPCodes,
Messages = Constants.Messages;
var Messages = Constants.Messages;
export default function APIClient(mpInstance) {
export default function APIClient(mpInstance, kitBlocker) {
this.uploader = null;

@@ -106,3 +105,8 @@ var self = this;

if (event && event.EventName !== Types.MessageType.AppStateTransition) {
mpInstance._Forwarders.sendEventToForwarders(event);
if (kitBlocker && kitBlocker.kitBlockingEnabled) {
event = kitBlocker.createBlockedEvent(event);
}
if (event) {
mpInstance._Forwarders.sendEventToForwarders(event);
}
}

@@ -156,148 +160,2 @@ };

this.sendAliasRequest = function(aliasRequest, callback) {
var xhr,
xhrCallback = function() {
if (xhr.readyState === 4) {
mpInstance.Logger.verbose(
'Received ' + xhr.statusText + ' from server'
);
//only parse error messages from failing requests
if (xhr.status !== 200 && xhr.status !== 202) {
if (xhr.responseText) {
var response = JSON.parse(xhr.responseText);
if (response.hasOwnProperty('message')) {
var errorMessage = response.message;
mpInstance._Helpers.invokeAliasCallback(
callback,
xhr.status,
errorMessage
);
return;
}
}
}
mpInstance._Helpers.invokeAliasCallback(
callback,
xhr.status
);
}
};
mpInstance.Logger.verbose(Messages.InformationMessages.SendAliasHttp);
xhr = mpInstance._Helpers.createXHR(xhrCallback);
if (xhr) {
try {
xhr.open(
'post',
mpInstance._Helpers.createServiceUrl(
mpInstance._Store.SDKConfig.aliasUrl,
mpInstance._Store.devToken
) + '/Alias'
);
xhr.send(JSON.stringify(aliasRequest));
} catch (e) {
mpInstance._Helpers.invokeAliasCallback(
callback,
HTTPCodes.noHttpCoverage,
e
);
mpInstance.Logger.error(
'Error sending alias request to mParticle servers. ' + e
);
}
}
};
this.sendIdentityRequest = function(
identityApiRequest,
method,
callback,
originalIdentityApiData,
parseIdentityResponse,
mpid
) {
var xhr,
previousMPID,
xhrCallback = function() {
if (xhr.readyState === 4) {
mpInstance.Logger.verbose(
'Received ' + xhr.statusText + ' from server'
);
parseIdentityResponse(
xhr,
previousMPID,
callback,
originalIdentityApiData,
method
);
}
};
mpInstance.Logger.verbose(
Messages.InformationMessages.SendIdentityBegin
);
if (!identityApiRequest) {
mpInstance.Logger.error(Messages.ErrorMessages.APIRequestEmpty);
return;
}
mpInstance.Logger.verbose(
Messages.InformationMessages.SendIdentityHttp
);
xhr = mpInstance._Helpers.createXHR(xhrCallback);
if (xhr) {
try {
if (mpInstance._Store.identityCallInFlight) {
mpInstance._Helpers.invokeCallback(
callback,
HTTPCodes.activeIdentityRequest,
'There is currently an Identity request processing. Please wait for this to return before requesting again'
);
} else {
previousMPID = mpid || null;
if (method === 'modify') {
xhr.open(
'post',
mpInstance._Helpers.createServiceUrl(
mpInstance._Store.SDKConfig.identityUrl
) +
mpid +
'/' +
method
);
} else {
xhr.open(
'post',
mpInstance._Helpers.createServiceUrl(
mpInstance._Store.SDKConfig.identityUrl
) + method
);
}
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader(
'x-mp-key',
mpInstance._Store.devToken
);
mpInstance._Store.identityCallInFlight = true;
xhr.send(JSON.stringify(identityApiRequest));
}
} catch (e) {
mpInstance._Store.identityCallInFlight = false;
mpInstance._Helpers.invokeCallback(
callback,
HTTPCodes.noHttpCoverage,
e
);
mpInstance.Logger.error(
'Error sending identity request to servers with status code ' +
xhr.status +
' - ' +
e
);
}
}
};
this.sendBatchForwardingStatsToServer = function(forwardingStatsData, xhr) {

@@ -358,58 +216,2 @@ var url, data;

this.getSDKConfiguration = function(
apiKey,
config,
completeSDKInitialization,
mpInstance
) {
var url;
try {
var xhrCallback = function() {
if (xhr.readyState === 4) {
// when a 200 returns, merge current config with what comes back from config, prioritizing user inputted config
if (xhr.status === 200) {
config = mpInstance._Helpers.extend(
{},
config,
JSON.parse(xhr.responseText)
);
completeSDKInitialization(apiKey, config, mpInstance);
mpInstance.Logger.verbose(
'Successfully received configuration from server'
);
} else {
// if for some reason a 200 doesn't return, then we initialize with the just the passed through config
completeSDKInitialization(apiKey, config, mpInstance);
mpInstance.Logger.verbose(
'Issue with receiving configuration from server, received HTTP Code of ' +
xhr.status
);
}
}
};
var xhr = mpInstance._Helpers.createXHR(xhrCallback);
url =
'https://' +
mpInstance._Store.SDKConfig.configUrl +
apiKey +
'/config?env=';
if (config.isDevelopmentMode) {
url = url + '1';
} else {
url = url + '0';
}
if (xhr) {
xhr.open('get', url);
xhr.send(null);
}
} catch (e) {
completeSDKInitialization(apiKey, config, mpInstance);
mpInstance.Logger.error(
'Error getting forwarder configuration from mParticle servers.'
);
}
};
this.prepareForwardingStats = function(forwarder, event) {

@@ -416,0 +218,0 @@ var forwardingStatsData,

var Constants = {
sdkVersion: '2.11.15',
sdkVersion: '2.12.0',
sdkVendor: 'mparticle',

@@ -4,0 +4,0 @@ platform: 'web',

import Types from './types';
export default function filteredMparticleUser(mpid, forwarder, mpInstance) {
export default function filteredMparticleUser(
mpid,
forwarder,
mpInstance,
kitBlocker
) {
var self = this;

@@ -12,7 +17,13 @@ return {

if (identities.hasOwnProperty(identityType)) {
currentUserIdentities[
Types.IdentityType.getIdentityName(
mpInstance._Helpers.parseNumber(identityType)
)
] = identities[identityType];
var identityName = Types.IdentityType.getIdentityName(
mpInstance._Helpers.parseNumber(identityType)
);
if (
!kitBlocker ||
(kitBlocker &&
!kitBlocker.isIdentityBlocked(identityName))
)
//if identity type is not blocked
currentUserIdentities[identityName] =
identities[identityType];
}

@@ -43,3 +54,8 @@ }

) {
userAttributesLists[key] = userAttributes[key].slice();
if (
!kitBlocker ||
(kitBlocker && !kitBlocker.isAttributeKeyBlocked(key))
) {
userAttributesLists[key] = userAttributes[key].slice();
}
}

@@ -64,8 +80,14 @@ }

if (userAttributes.hasOwnProperty(prop)) {
if (Array.isArray(userAttributes[prop])) {
userAttributesCopy[prop] = userAttributes[
prop
].slice();
} else {
userAttributesCopy[prop] = userAttributes[prop];
if (
!kitBlocker ||
(kitBlocker &&
!kitBlocker.isAttributeKeyBlocked(prop))
) {
if (Array.isArray(userAttributes[prop])) {
userAttributesCopy[prop] = userAttributes[
prop
].slice();
} else {
userAttributesCopy[prop] = userAttributes[prop];
}
}

@@ -72,0 +94,0 @@ }

import Types from './types';
import filteredMparticleUser from './filteredMparticleUser';
export default function Forwarders(mpInstance) {
export default function Forwarders(mpInstance, kitBlocker) {
var self = this;

@@ -450,2 +450,6 @@ this.initForwarders = function(userIdentities, forwardingStatsCallback) {

this.callSetUserAttributeOnForwarders = function(key, value) {
if (kitBlocker && kitBlocker.isAttributeKeyBlocked(key)) {
return;
}
if (mpInstance._Store.activeForwarders.length) {

@@ -500,3 +504,4 @@ mpInstance._Store.activeForwarders.forEach(function(forwarder) {

forwarder,
mpInstance
mpInstance,
kitBlocker
);

@@ -519,3 +524,4 @@ if (forwarder.onUserIdentified) {

forwarder,
mpInstance
mpInstance,
kitBlocker
);

@@ -522,0 +528,0 @@ if (identityMethod === 'identify') {

@@ -37,2 +37,5 @@ //

import Consent from './consent';
import KitBlocker from './kitBlocking';
import ConfigAPIClient from './configAPIClient';
import IdentityAPIClient from './identityApiClient';

@@ -64,4 +67,2 @@ var Messages = Constants.Messages,

this._Helpers = new Helpers(this);
this._Forwarders = new Forwarders(this);
this._APIClient = new APIClient(this);
this._Events = new Events(this);

@@ -73,2 +74,3 @@ this._CookieSyncManager = new CookieSyncManager(this);

this._Consent = new Consent(this);
this._IdentityAPIClient = new IdentityAPIClient(this);
this._preInit = {

@@ -115,3 +117,3 @@ readyQueue: [],

) {
self._APIClient.getSDKConfiguration(
new ConfigAPIClient().getSDKConfiguration(
apiKey,

@@ -1124,4 +1126,8 @@ config,

// Some (server) config settings need to be returned before they are set on SDKConfig in a self hosted environment
function completeSDKInitialization(apiKey, config, mpInstance) {
// Some (server) config settings need to be returned before they are set on SDKConfig in a self hosted environment
var kitBlocker = createKitBlocker(config, mpInstance);
mpInstance._APIClient = new APIClient(mpInstance, kitBlocker);
mpInstance._Forwarders = new Forwarders(mpInstance, kitBlocker);
if (config.flags) {

@@ -1314,2 +1320,63 @@ if (config.flags.hasOwnProperty(Constants.FeatureFlags.EventsV3)) {

function createKitBlocker(config, mpInstance) {
var kitBlocker, dataPlanForKitBlocker, kitBlockError, kitBlockOptions;
/* There are three ways a data plan object for blocking can be passed to the SDK:
1. Manually via config.dataPlanOptions (this takes priority)
If not passed in manually, we user the server provided via either
2. Snippet via /mparticle.js endpoint (config.dataPlan.document)
3. Self hosting via /config endpoint (config.dataPlanResult)
*/
if (config.dataPlanOptions) {
mpInstance.Logger.verbose('Customer provided data plan found');
kitBlockOptions = config.dataPlanOptions;
dataPlanForKitBlocker = {
document: {
dtpn: {
vers: kitBlockOptions.dataPlanVersion,
blok: {
ev: kitBlockOptions.blockEvents,
ea: kitBlockOptions.blockEventAttributes,
ua: kitBlockOptions.blockUserAttributes,
id: kitBlockOptions.blockUserIdentities,
},
},
},
};
}
if (!dataPlanForKitBlocker) {
// config.dataPlan.document returns on /mparticle.js endpoint
if (config.dataPlan && config.dataPlan.document) {
if (config.dataPlan.document.error_message) {
kitBlockError = config.dataPlan.document.error_message;
} else {
mpInstance.Logger.verbose('Data plan found from mParticle.js');
dataPlanForKitBlocker = config.dataPlan;
}
}
// config.dataPlanResult returns on /config endpoint
else if (config.dataPlanResult) {
if (config.dataPlanResult.error_message) {
kitBlockError = config.dataPlanResult.error_message;
} else {
mpInstance.Logger.verbose('Data plan found from /config');
dataPlanForKitBlocker = { document: config.dataPlanResult };
}
}
}
if (kitBlockError) {
mpInstance.Logger.error(kitBlockError);
}
if (dataPlanForKitBlocker) {
kitBlocker = new KitBlocker(dataPlanForKitBlocker, mpInstance);
}
return kitBlocker;
}
function runPreConfigFetchInitialization(mpInstance, apiKey, config) {

@@ -1316,0 +1383,0 @@ mpInstance.Logger = new Logger(config);

import * as EventsApi from '@mparticle/event-models';
import { DataPlanVersion } from '@mparticle/data-planning-models';

@@ -115,2 +116,3 @@ export interface SDKEvent {

export interface MParticleWebSDK {
addForwarder(mockForwarder: any);
Identity: SDKIdentityApi;

@@ -127,6 +129,7 @@ Logger: SDKLoggerApi;

setPosition(lat: number | string, lng: number | string): void;
logEvent(eventName: string): void;
logEvent(eventName: string, eventType?: number, attrs?: { [key: string]: string }): void;
eCommerce: any;
logLevel: string;
ProductActionType: SDKProductActionType;
generateHash(value: string);
}

@@ -136,4 +139,11 @@

isDevelopmentMode?: boolean;
logger: {
error?(msg);
warning?(msg)
verbose?(msg)
};
dataPlan: DataPlanConfig;
appVersion?: string;
flags?: { [key: string]: string | number };
kitConfigs: any;
appName?: string;

@@ -148,7 +158,20 @@ logLevel?: string;

isIOS?: boolean;
identifyRequest: { [key: string]: {[key: string]: string} };
requestConfig: boolean;
dataPlanOptions: KitBlockerOptions
}
export interface DataPlanConfig {
planId?: string;
planVersion?: number;
document?: any
}
export interface SDKIdentityApi {
getCurrentUser();
IdentityAPI;
identify;
login;
logout;
modify;
}

@@ -158,3 +181,5 @@

createServiceUrl(arg0: string, arg1: string): void;
parseNumber(value: number)
generateUniqueId();
isObject(item: any)
}

@@ -165,2 +190,3 @@

verbose(arg0: string): void;
warning(arg0: string): void;
}

@@ -231,1 +257,9 @@

}
export interface KitBlockerOptions {
dataPlanVersion: any;
blockUserAttributes: boolean;
blockEventAttributes: boolean;
blockEvents: boolean;
blockUserIdentities: boolean;
}

@@ -249,2 +249,16 @@ import Constants from './constants';

if (config.hasOwnProperty('dataPlanOptions')) {
if (
!config.dataPlanOptions.hasOwnProperty('dataPlanVersion') ||
!config.dataPlanOptions.hasOwnProperty('blockUserAttributes') ||
!config.dataPlanOptions.hasOwnProperty('blockEventAttribute') ||
!config.dataPlanOptions.hasOwnProperty('blockEvents') ||
!config.dataPlanOptions.hasOwnProperty('blockIdentities')
) {
mpInstance.Logger.error(
'Ensure your config.dataPlanOptions object has the following keys: a "dataPlanVersion" object, and "blockUserAttributes", "blockEventAttribute", "blockEvents", "blockIdentities" booleans'
);
}
}
if (!config.hasOwnProperty('flags')) {

@@ -251,0 +265,0 @@ this.SDKConfig.flags = {};

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc