Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mparticle/web-sdk

Package Overview
Dependencies
Maintainers
7
Versions
115
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.9.11-rc.1 to 2.9.12-rc.1

src/batchUploader.ts

5

CHANGELOG.md
## Releases
--
#### 2.9.12 - 2019-10-02
* Support event batching and beacon API; provide new Events API v3 endpoint which supports batching
* Implement Typescript and Babel compilation
* Feat - Enable configuration of config endpoint
#### 2.9.11 - 2019-09-26

@@ -5,0 +10,0 @@ * Feat - Add Base Event functionality to core for future child SDK use

29

package.json
{
"name": "@mparticle/web-sdk",
"version": "2.9.11-rc.1",
"version": "2.9.12-rc.1",
"description": "mParticle core SDK for web applications",

@@ -16,3 +16,3 @@ "license": "Apache-2.0",

"main": "dist/mparticle.common.js",
"module": "src/main.js",
"module": "src/dist/mparticle.esm.js",
"repository": "https://github.com/mParticle/mparticle-web-sdk",

@@ -30,2 +30,3 @@ "scripts": {

"build:webpack:module": "webpack --config test/integrations/module/webpack/webpack.config.js && npm run test:karma:webpack:module",
"build:ts": "tsc -p .",
"test": "npm run build && npm run build:tests:prod && DEBUG=false karma start test/karma.config.js",

@@ -47,3 +48,5 @@ "test:debug": "DEBUG=true karma start test/karma.config.js",

"watch:tests": "ENVIRONMENT=dev rollup --config rollup.test.config.js -w",
"lint": "eslint src/ test/src/"
"lint": "eslint src/ test/src/",
"gts:check": "gts check",
"gts:fix": "gts fix"
},

@@ -54,2 +57,12 @@ "pre-commit": [

"devDependencies": {
"@babel/core": "^7.6.0",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
"@babel/plugin-transform-runtime": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"@babel/preset-typescript": "^7.6.0",
"@types/chai": "^4.2.3",
"@types/mocha": "^5.2.7",
"@types/node": "^10.0.3",
"babel-preset-minify": "^0.5.1",
"browser-sync": "^2.26.3",

@@ -59,2 +72,3 @@ "browserify": "^16.3.0",

"eslint": "^6.4.0",
"gts": "^1.1.0",
"karma": "^4.0.1",

@@ -73,7 +87,11 @@ "karma-chai": "^0.1.0",

"rollup": "^1.19.4",
"rollup-plugin-commonjs": "^10.0.2",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-typescript": "^1.0.1",
"shelljs": "^0.7.8",
"should": "^7.1.0",
"sinon": "^7.4.1",
"tslib": "^1.10.0",
"typescript": "^3.6.2",
"uglify-js": "^3.4.9",

@@ -83,3 +101,6 @@ "webpack": "^4.39.1",

"yuidocjs": "^0.10.2"
},
"dependencies": {
"@babel/runtime": "^7.6.0"
}
}

213

src/apiClient.js

@@ -6,7 +6,31 @@ import Helpers from './helpers';

import Types from './types';
import { BatchUploader } from './batchUploader';
import Persistence from './persistence';
import Forwarders from './forwarders';
var HTTPCodes = Constants.HTTPCodes,
Messages = Constants.Messages;
Messages = Constants.Messages,
uploader = null;
function sendEventToServer(event, sendEventToForwarders, parseEventResponse) {
function queueEventForBatchUpload(event) {
if (!uploader){
var millis = Helpers.getFeatureFlag(Constants.FeatureFlags.EventBatchingIntervalMillis);
uploader = new BatchUploader(mParticle, millis);
}
uploader.queueEvent(event);
}
function shouldEnableBatching() {
if (!window.fetch) {
return false;
}
var eventsV3Percentage = Helpers.getFeatureFlag(Constants.FeatureFlags.EventsV3);
if (!eventsV3Percentage || !Helpers.Validators.isNumber(eventsV3Percentage)) {
return false;
}
var rampNumber = Helpers.getRampNumber(mParticle.Store.deviceId);
return eventsV3Percentage >= rampNumber;
}
function processQueuedEvents() {
var mpid,

@@ -17,62 +41,130 @@ currentUser = mParticle.Identity.getCurrentUser();

}
if (mParticle.Store.eventQueue.length && mpid) {
var localQueueCopy = mParticle.Store.eventQueue;
mParticle.Store.eventQueue = [];
appendUserInfoToEvents(currentUser, localQueueCopy);
localQueueCopy.forEach(function(event) {
sendEventToServer(event);
});
}
}
function appendUserInfoToEvents(user, events) {
events.forEach(function(event) {
if (!event.MPID) {
ServerModel.appendUserInfo(user, event);
}
});
}
function sendEventToServer(event) {
if (mParticle.Store.webviewBridgeEnabled) {
NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.LogEvent, JSON.stringify(event));
} else {
var xhr,
xhrCallback = function() {
if (xhr.readyState === 4) {
mParticle.Logger.verbose('Received ' + xhr.statusText + ' from server');
return;
}
var mpid,
currentUser = mParticle.Identity.getCurrentUser();
if (currentUser) {
mpid = currentUser.getMPID();
}
mParticle.Store.requireDelay = Helpers.isDelayedByIntegration(mParticle.preInit.integrationDelays, mParticle.Store.integrationDelayTimeoutStart, Date.now());
// We queue events if there is no MPID (MPID is null, or === 0), or there are integrations that that require this to stall because integration attributes
// need to be set, or if we are still fetching the config (self hosted only), and so require delaying events
if (!mpid || mParticle.Store.requireDelay || !mParticle.Store.configurationLoaded) {
mParticle.Logger.verbose('Event was added to eventQueue. eventQueue will be processed once a valid MPID is returned or there is no more integration imposed delay.');
mParticle.Store.eventQueue.push(event);
return;
}
parseEventResponse(xhr.responseText);
}
};
processQueuedEvents();
mParticle.Logger.verbose(Messages.InformationMessages.SendBegin);
if (shouldEnableBatching()) {
queueEventForBatchUpload(event);
} else {
sendSingleEventToServer(event);
}
var validUserIdentities = [];
if (event && event.EventName !== Types.MessageType.AppStateTransition) {
Forwarders.sendEventToForwarders(event);
}
}
// convert userIdentities which are objects with key of IdentityType (number) and value ID to an array of Identity objects for DTO and event forwarding
if (Helpers.isObject(event.UserIdentities) && Object.keys(event.UserIdentities).length) {
for (var key in event.UserIdentities) {
var userIdentity = {};
userIdentity.Identity = event.UserIdentities[key];
userIdentity.Type = Helpers.parseNumber(key);
validUserIdentities.push(userIdentity);
function sendSingleEventToServer(event) {
if (event.EventDataType === Types.MessageType.Media) {
return;
}
var xhr,
xhrCallback = function() {
if (xhr.readyState === 4) {
mParticle.Logger.verbose('Received ' + xhr.statusText + ' from server');
parseEventResponse(xhr.responseText);
}
event.UserIdentities = validUserIdentities;
} else {
event.UserIdentities = [];
};
if (!event) {
mParticle.Logger.error(Messages.ErrorMessages.EventEmpty);
return;
}
mParticle.Logger.verbose(Messages.InformationMessages.SendHttp);
xhr = Helpers.createXHR(xhrCallback);
if (xhr) {
try {
xhr.open('post', Helpers.createServiceUrl(mParticle.Store.SDKConfig.v2SecureServiceUrl, mParticle.Store.devToken) + '/Events');
xhr.send(JSON.stringify(ServerModel.convertEventToDTO(event, mParticle.Store.isFirstRun)));
}
catch (e) {
mParticle.Logger.error('Error sending event to mParticle servers. ' + e);
}
}
}
mParticle.Store.requireDelay = Helpers.isDelayedByIntegration(mParticle.preInit.integrationDelays, mParticle.Store.integrationDelayTimeoutStart, Date.now());
// We queue events if there is no MPID (MPID is null, or === 0), or there are integrations that that require this to stall because integration attributes
// need to be set, or if we are still fetching the config (self hosted only), and so require delaying events
if (!mpid || mParticle.Store.requireDelay || !mParticle.Store.configurationLoaded) {
mParticle.Logger.verbose('Event was added to eventQueue. eventQueue will be processed once a valid MPID is returned or there is no more integration imposed delay.');
mParticle.Store.eventQueue.push(event);
} else {
Helpers.processQueuedEvents(mParticle.Store.eventQueue, mpid, !mParticle.Store.requiredDelay, sendEventToServer, sendEventToForwarders, parseEventResponse);
if (!event) {
mParticle.Logger.error(Messages.ErrorMessages.EventEmpty);
return;
function parseEventResponse(responseText) {
var now = new Date(),
settings,
prop,
fullProp;
if (!responseText) {
return;
}
try {
mParticle.Logger.verbose('Parsing response from server');
settings = JSON.parse(responseText);
if (settings && settings.Store) {
mParticle.Logger.verbose('Parsed store from response, updating local settings');
if (!mParticle.Store.serverSettings) {
mParticle.Store.serverSettings = {};
}
mParticle.Logger.verbose(Messages.InformationMessages.SendHttp);
for (prop in settings.Store) {
if (!settings.Store.hasOwnProperty(prop)) {
continue;
}
xhr = Helpers.createXHR(xhrCallback);
fullProp = settings.Store[prop];
if (xhr) {
try {
xhr.open('post', Helpers.createServiceUrl(mParticle.Store.SDKConfig.v2SecureServiceUrl, mParticle.Store.devToken) + '/Events');
xhr.send(JSON.stringify(ServerModel.convertEventToDTO(event, mParticle.Store.isFirstRun, mParticle.Store.currencyCode, mParticle.Store.integrationAttributes)));
if (event.EventName !== Types.MessageType.AppStateTransition) {
sendEventToForwarders(event);
if (!fullProp.Value || new Date(fullProp.Expires) < now) {
// This setting should be deleted from the local store if it exists
if (mParticle.Store.serverSettings.hasOwnProperty(prop)) {
delete mParticle.Store.serverSettings[prop];
}
}
catch (e) {
mParticle.Logger.error('Error sending event to mParticle servers. ' + e);
else {
// This is a valid setting
mParticle.Store.serverSettings[prop] = fullProp;
}
}
Persistence.update();
}
}
catch (e) {
mParticle.Logger.error('Error parsing JSON response from server: ' + e.name);
}
}

@@ -220,3 +312,3 @@

var xhr = Helpers.createXHR(xhrCallback);
url = 'https://' + Constants.DefaultUrls.configUrl + apiKey + '/config?env=';
url = 'https://' + mParticle.Store.SDKConfig.configUrl + apiKey + '/config?env=';
if (config.isDevelopmentMode) {

@@ -239,2 +331,29 @@ url = url + '1';

function prepareForwardingStats(forwarder, event) {
var forwardingStatsData,
queue = Forwarders.getForwarderStatsQueue();
if (forwarder && forwarder.isVisible) {
forwardingStatsData = {
mid: forwarder.id,
esid: forwarder.eventSubscriptionId,
n: event.EventName,
attrs: event.EventAttributes,
sdk: event.SDKVersion,
dt: event.EventDataType,
et: event.EventCategory,
dbg: event.Debug,
ct: event.Timestamp,
eec: event.ExpandedEventCount
};
if (Helpers.getFeatureFlag(Constants.FeatureFlags.ReportBatching)) {
queue.push(forwardingStatsData);
Forwarders.setForwarderStatsQueue(queue);
} else {
sendSingleForwardingStatsToServer(forwardingStatsData);
}
}
}
export default {

@@ -246,3 +365,7 @@ sendEventToServer: sendEventToServer,

sendAliasRequest: sendAliasRequest,
getSDKConfiguration: getSDKConfiguration
getSDKConfiguration: getSDKConfiguration,
prepareForwardingStats: prepareForwardingStats,
processQueuedEvents: processQueuedEvents,
appendUserInfoToEvents: appendUserInfoToEvents,
shouldEnableBatching: shouldEnableBatching
};
var Constants = {
sdkVersion: '2.9.11',
sdkVersion: '2.9.12',
sdkVendor: 'mparticle',

@@ -106,3 +106,4 @@ platform: 'web',

maxCookieSize: 3000, // Number of bytes for cookie size to not exceed
aliasMaxWindow: 90 // Max age of Alias request startTime, in days
aliasMaxWindow: 90, // Max age of Alias request startTime, in days
uploadInterval: 0 // Maximum milliseconds in between batch uploads, below 500 will mean immediate upload
},

@@ -112,2 +113,3 @@ DefaultUrls: {

v2SecureServiceUrl: 'jssdks.mparticle.com/v2/JS/',
v3SecureServiceUrl: 'jssdks.mparticle.com/v3/JS/',
configUrl: 'jssdkcdns.mparticle.com/JS/v2/',

@@ -143,4 +145,6 @@ identityUrl: 'identity.mparticle.com/v1/',

},
Features: {
Batching: 'batching'
FeatureFlags: {
ReportBatching: 'reportBatching',
EventsV3: 'eventsV3',
EventBatchingIntervalMillis: 'eventBatchingIntervalMillis'
}

@@ -147,0 +151,0 @@ };

@@ -231,2 +231,7 @@ import Types from './types';

if (position && !Validators.isNumber(position)) {
mParticle.Logger.error('Position must be a number, it will be set to null.');
position = null;
}
if (!quantity) {

@@ -233,0 +238,0 @@ quantity = 1;

@@ -8,7 +8,5 @@ import Types from './types';

import ApiClient from './apiClient';
import Forwarders from './forwarders';
var Messages = Constants.Messages,
sendEventToServer = ApiClient.sendEventToServer,
sendEventToForwarders = Forwarders.sendEventToForwarders;
sendEventToServer = ApiClient.sendEventToServer;

@@ -23,9 +21,3 @@

var uploadObject = ServerModel.createEventObject(event);
// TODO: Disabled for the time being until we can define an HTTP Request for BaseEvents
if (event.messageType === Types.MessageType.Media) {
sendEventToForwarders(uploadObject);
} else {
sendEventToServer(uploadObject, sendEventToForwarders, parseEventResponse);
}
sendEventToServer(uploadObject);
Persistence.update();

@@ -38,51 +30,2 @@ }

function parseEventResponse(responseText) {
var now = new Date(),
settings,
prop,
fullProp;
if (!responseText) {
return;
}
try {
mParticle.Logger.verbose('Parsing response from server');
settings = JSON.parse(responseText);
if (settings && settings.Store) {
mParticle.Logger.verbose('Parsed store from response, updating local settings');
if (!mParticle.Store.serverSettings) {
mParticle.Store.serverSettings = {};
}
for (prop in settings.Store) {
if (!settings.Store.hasOwnProperty(prop)) {
continue;
}
fullProp = settings.Store[prop];
if (!fullProp.Value || new Date(fullProp.Expires) < now) {
// This setting should be deleted from the local store if it exists
if (mParticle.Store.serverSettings.hasOwnProperty(prop)) {
delete mParticle.Store.serverSettings[prop];
}
}
else {
// This is a valid setting
mParticle.Store.serverSettings[prop] = fullProp;
}
}
Persistence.update();
}
}
catch (e) {
mParticle.Logger.error('Error parsing JSON response from server: ' + e.name);
}
}
function startTracking(callback) {

@@ -154,3 +97,3 @@ if (!mParticle.Store.isTracking) {

});
sendEventToServer(event, sendEventToForwarders, parseEventResponse);
sendEventToServer(event);
}

@@ -287,3 +230,3 @@

sendEventToServer(commerceEvent, sendEventToForwarders, parseEventResponse);
sendEventToServer(commerceEvent);
Persistence.update();

@@ -385,4 +328,3 @@ }

logAST: logAST,
parseEventResponse: parseEventResponse,
addEventHandler: addEventHandler
};
import Helpers from './helpers';
import Types from './types';
import Constants from './constants';
import getFilteredMparticleUser from './mParticleUser';
import ApiClient from './apiClient';
import Persistence from './persistence';
function initForwarders(userIdentities) {
function initForwarders(userIdentities, forwardingStatsCallback) {
var user = mParticle.Identity.getCurrentUser();

@@ -34,3 +32,3 @@ if (!mParticle.Store.webviewBridgeEnabled && mParticle.Store.configuredForwarders) {

forwarder.init(forwarder.settings,
prepareForwardingStats,
forwardingStatsCallback,
false,

@@ -392,29 +390,2 @@ null,

function prepareForwardingStats(forwarder, event) {
var forwardingStatsData,
queue = getForwarderStatsQueue();
if (forwarder && forwarder.isVisible) {
forwardingStatsData = {
mid: forwarder.id,
esid: forwarder.eventSubscriptionId,
n: event.EventName,
attrs: event.EventAttributes,
sdk: event.SDKVersion,
dt: event.EventDataType,
et: event.EventCategory,
dbg: event.Debug,
ct: event.Timestamp,
eec: event.ExpandedEventCount
};
if (Helpers.hasFeatureFlag(Constants.Features.Batching)) {
queue.push(forwardingStatsData);
setForwarderStatsQueue(queue);
} else {
ApiClient.sendSingleForwardingStatsToServer(forwardingStatsData);
}
}
}
function getForwarderStatsQueue() {

@@ -484,3 +455,3 @@ return Persistence.forwardingStatsBatches.forwardingStatsEventQueue;

function processForwarders(config) {
function processForwarders(config, forwardingStatsCallback) {
if (!config) {

@@ -501,3 +472,3 @@ mParticle.Logger.warning('No config was passed. Cannot process forwarders');

}
initForwarders(mParticle.Store.SDKConfig.identifyRequest.userIdentities);
initForwarders(mParticle.Store.SDKConfig.identifyRequest.userIdentities, forwardingStatsCallback);
} catch (e) {

@@ -504,0 +475,0 @@ mParticle.Logger.error('Config was not parsed propertly. Forwarders may not be initialized.');

@@ -22,8 +22,20 @@ import Types from './types';

function hasFeatureFlag(feature) {
if (mParticle.preInit.featureFlags) {
return mParticle.preInit.featureFlags[feature];
function getFeatureFlag(feature) {
if (mParticle.Store.SDKConfig.flags.hasOwnProperty(feature)) {
return mParticle.Store.SDKConfig.flags[feature];
}
return null;
}
/**
* Returns a value between 1-100 inclusive.
*/
function getRampNumber(deviceId) {
if (!deviceId) {
return 100;
}
var hash = generateHash(deviceId);
return Math.abs(hash % 100) + 1;
}
function invokeCallback(callback, code, body, mParticleUser, previousMpid) {

@@ -453,2 +465,6 @@ if (!callback) {

isNumber: function(value) {
return (typeof value === 'number');
},
isFunction: function(fn) {

@@ -547,15 +563,2 @@ return typeof fn === 'function';

// events exist in the eventQueue because they were triggered when the identityAPI request was in flight
// once API request returns and there is an MPID, eventQueue items are reassigned with the returned MPID and flushed
function processQueuedEvents(eventQueue, mpid, requireDelay, sendEventToServer, sendEventToForwarders, parseEventResponse) {
if (eventQueue.length && mpid && requireDelay) {
var localQueueCopy = eventQueue;
mParticle.Store.eventQueue = [];
localQueueCopy.forEach(function(event) {
event.MPID = mpid;
sendEventToServer(event, sendEventToForwarders, parseEventResponse);
});
}
}
function createMainStorageName(workspaceToken) {

@@ -599,8 +602,8 @@ if (workspaceToken) {

invokeAliasCallback: invokeAliasCallback,
hasFeatureFlag: hasFeatureFlag,
getFeatureFlag: getFeatureFlag,
isDelayedByIntegration: isDelayedByIntegration,
processQueuedEvents: processQueuedEvents,
createMainStorageName: createMainStorageName,
createProductStorageName: createProductStorageName,
Validators: Validators
Validators: Validators,
getRampNumber: getRampNumber
};

@@ -15,3 +15,2 @@ import Helpers from './helpers';

HTTPCodes = Constants.HTTPCodes,
sendEventToForwarders = Forwarders.sendEventToForwarders,
sendIdentityRequest = ApiClient.sendIdentityRequest;

@@ -583,3 +582,3 @@

Forwarders.initForwarders(IdentityAPI.getCurrentUser().getUserIdentities());
Forwarders.initForwarders(IdentityAPI.getCurrentUser().getUserIdentities(), ApiClient.prepareForwardingStats);
Forwarders.callSetUserAttributeOnForwarders(key, value);

@@ -642,3 +641,3 @@ }

Forwarders.initForwarders(IdentityAPI.getCurrentUser().getUserIdentities());
Forwarders.initForwarders(IdentityAPI.getCurrentUser().getUserIdentities(), ApiClient.prepareForwardingStats);
Forwarders.applyToForwarders('removeUserAttribute', key);

@@ -689,3 +688,3 @@ }

Forwarders.initForwarders(IdentityAPI.getCurrentUser().getUserIdentities());
Forwarders.initForwarders(IdentityAPI.getCurrentUser().getUserIdentities(), ApiClient.prepareForwardingStats);
Forwarders.callSetUserAttributeOnForwarders(key, arrayCopy);

@@ -710,3 +709,3 @@ }

Forwarders.initForwarders(IdentityAPI.getCurrentUser().getUserIdentities());
Forwarders.initForwarders(IdentityAPI.getCurrentUser().getUserIdentities()), ApiClient.prepareForwardingStats;
if (userAttributes) {

@@ -792,3 +791,3 @@ for (var prop in userAttributes) {

Persistence.saveUserConsentStateToCookies(mpid, state);
Forwarders.initForwarders(this.getUserIdentities().userIdentities);
Forwarders.initForwarders(this.getUserIdentities().userIdentities), ApiClient.prepareForwardingStats;
},

@@ -1035,3 +1034,3 @@ isLoggedIn: function() {

if (!prevUser || newUser.getMPID() !== prevUser.getMPID() || prevUser.isLoggedIn() !== newUser.isLoggedIn()) {
Forwarders.initForwarders(newUser.getUserIdentities().userIdentities);
Forwarders.initForwarders(newUser.getUserIdentities().userIdentities, ApiClient.prepareForwardingStats);
}

@@ -1043,3 +1042,3 @@ Forwarders.setForwarderUserIdentities(newUser.getUserIdentities().userIdentities);

Helpers.processQueuedEvents(mParticle.Store.eventQueue, identityApiResult.mpid, !mParticle.Store.requireDelay, ApiClient.sendEventToServer, sendEventToForwarders, Events.parseEventResponse);
ApiClient.processQueuedEvents();
}

@@ -1046,0 +1045,0 @@

@@ -140,3 +140,2 @@ //

integrationDelays: {},
featureFlags: {},
forwarderConstructors: [],

@@ -774,9 +773,2 @@ isDevelopmentMode: false

},
_configureFeatures: function(featureFlags) {
for (var key in featureFlags) {
if (mParticle.Store && mParticle.preInit.featureFlags) {
mParticle.preInit.featureFlags[key] = featureFlags[key];
}
}
},
_setIntegrationDelay: function(module, boolean) {

@@ -825,7 +817,7 @@ mParticle.preInit.integrationDelays[module] = boolean;

if (Helpers.hasFeatureFlag(Constants.Features.Batching)) {
if (Helpers.getFeatureFlag(Constants.FeatureFlags.ReportBatching)) {
startForwardingStatsTimer();
}
Forwarders.processForwarders(config);
Forwarders.processForwarders(config, ApiClient.prepareForwardingStats);

@@ -922,3 +914,2 @@ // Call mParticle.Store.SDKConfig.identityCallback when identify was not called due to a reload or a sessionId already existing

readyQueue: [],
featureFlags: {},
integrationDelays: {},

@@ -925,0 +916,0 @@ forwarderConstructors: []

@@ -39,2 +39,43 @@ import Types from './types';

function appendUserInfo(user, event) {
if (!event) {
return;
}
if (!user) {
event.MPID = null;
event.ConsentState = null;
event.UserAttributes = null;
event.UserIdentities = null;
return;
}
if (event.MPID && event.MPID === user.getMPID()) {
return;
}
event.MPID = user.getMPID();
event.ConsentState = user.getConsentState();
event.UserAttributes = user.getAllUserAttributes();
var userIdentities = user.getUserIdentities().userIdentities;
var dtoUserIdentities = {};
for (var identityKey in userIdentities) {
var identityType = Types.IdentityType.getIdentityType(identityKey);
if (identityType !== false) {
dtoUserIdentities[identityType] = userIdentities[identityKey];
}
}
var validUserIdentities = [];
if (Helpers.isObject(dtoUserIdentities)) {
if (Object.keys(dtoUserIdentities).length) {
for (var key in dtoUserIdentities) {
var userIdentity = {};
userIdentity.Identity = dtoUserIdentities[key];
userIdentity.Type = Helpers.parseNumber(key);
validUserIdentities.push(userIdentity);
}
}
}
event.UserIdentities = validUserIdentities;
}
function convertProductListToDTO(productList) {

@@ -104,16 +145,5 @@ if (!productList) {

var eventObject = {};
var dtoUserIdentities = {};
var currentUser = mParticle.Identity.getCurrentUser();
var userIdentities = currentUser ? currentUser.getUserIdentities().userIdentities : {};
var optOut = (event.messageType === Types.MessageType.OptOut ? !mParticle.Store.isEnabled : null);
if (mParticle.Store.sessionId || event.messageType == Types.MessageType.OptOut || mParticle.Store.webviewBridgeEnabled) {
for (var identityKey in userIdentities) {
dtoUserIdentities[Types.IdentityType.getIdentityType(identityKey)] = userIdentities[identityKey];
}
if (event.messageType !== Types.MessageType.SessionEnd) {
mParticle.Store.dateLastEventSent = new Date();
}
if (event.hasOwnProperty('toEventAPIObject')) {

@@ -131,5 +161,7 @@ eventObject = event.toEventAPIObject();

if (event.messageType !== Types.MessageType.SessionEnd) {
mParticle.Store.dateLastEventSent = new Date();
}
uploadObject = {
UserAttributes: currentUser ? currentUser.getAllUserAttributes() : {},
UserIdentities: dtoUserIdentities,
Store: mParticle.Store.serverSettings,

@@ -146,7 +178,10 @@ SDKVersion: Constants.sdkVersion,

DeviceId: mParticle.Store.deviceId,
MPID: currentUser ? currentUser.getMPID() : null,
ConsentState: currentUser ? currentUser.getConsentState() : null,
IntegrationAttributes: mParticle.Store.integrationAttributes
IntegrationAttributes: mParticle.Store.integrationAttributes,
CurrencyCode: mParticle.Store.currencyCode
};
eventObject.CurrencyCode = mParticle.Store.currencyCode;
var currentUser = mParticle.Identity.getCurrentUser();
appendUserInfo(currentUser, eventObject);
if (event.messageType === Types.MessageType.SessionEnd) {

@@ -169,3 +204,3 @@ eventObject.SessionLength = mParticle.Store.dateLastEventSent.getTime() - mParticle.Store.sessionStartDate.getTime();

function convertEventToDTO(event, isFirstRun, currencyCode) {
function convertEventToDTO(event, isFirstRun) {
var dto = {

@@ -214,3 +249,3 @@ n: event.EventName,

if (event.EventDataType === MessageType.Commerce) {
dto.cu = currencyCode;
dto.cu = event.CurrencyCode;

@@ -269,3 +304,4 @@ if (event.ShoppingCart) {

convertEventToDTO: convertEventToDTO,
convertToConsentStateDTO: convertToConsentStateDTO
convertToConsentStateDTO: convertToConsentStateDTO,
appendUserInfo: appendUserInfo
};

@@ -218,3 +218,16 @@ import Constants from './constants';

}
if (!config.hasOwnProperty('flags')) {
this.SDKConfig.flags = {};
}
if (!this.SDKConfig.flags.hasOwnProperty(Constants.FeatureFlags.EventsV3)) {
this.SDKConfig.flags[Constants.FeatureFlags.EventsV3] = 0;
}
if (!this.SDKConfig.flags.hasOwnProperty(Constants.FeatureFlags.EventBatchingIntervalMillis)) {
this.SDKConfig.flags[Constants.FeatureFlags.EventBatchingIntervalMillis] = Constants.DefaultConfig.uploadInterval;
}
if (!this.SDKConfig.flags.hasOwnProperty(Constants.FeatureFlags.ReportBatching)) {
this.SDKConfig.flags[Constants.FeatureFlags.ReportBatching] = false;
}
}
}

@@ -161,4 +161,2 @@ var MessageType = {

return IdentityType.FacebookCustomAudienceId;
case 'other1':
return IdentityType.Other1;
case 'other2':

@@ -195,4 +193,2 @@ return IdentityType.Other2;

return 'facebookcustomaudienceid';
case IdentityType.Other1:
return 'other1';
case IdentityType.Other2:

@@ -199,0 +195,0 @@ return 'other2';

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