@mparticle/web-sdk
Advanced tools
Comparing version 2.20.1 to 2.20.2
{ | ||
"name": "@mparticle/web-sdk", | ||
"version": "2.20.1", | ||
"version": "2.20.2", | ||
"description": "mParticle core SDK for web applications", | ||
@@ -81,3 +81,3 @@ "license": "Apache-2.0", | ||
"@rollup/plugin-typescript": "^8.3.3", | ||
"@rollup/plugin-babel": "6.0.3", | ||
"@rollup/plugin-babel": "5.3.1", | ||
"@rollup/plugin-commonjs": "22.0.2", | ||
@@ -97,4 +97,4 @@ "@rollup/plugin-node-resolve": "13.3.0", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.36.0", | ||
"eslint-config-prettier": "8.8.0", | ||
"eslint": "^7.32.0", | ||
"eslint-config-prettier": "8.3.0", | ||
"eslint-plugin-prettier": "3.4.1", | ||
@@ -121,3 +121,3 @@ "fetch-mock": "^7.5.1", | ||
"tslib": "^2.1.0", | ||
"typescript": "^5.0.2", | ||
"typescript": "^4.2.4", | ||
"uglify-js": "^3.4.9", | ||
@@ -124,0 +124,0 @@ "webpack": "^5.36.2", |
@@ -11,3 +11,3 @@ import Constants from './constants'; | ||
import KitBlocker from './kitBlocking'; | ||
import { Dictionary, getRampNumber } from './utils'; | ||
import { Dictionary } from './utils'; | ||
import { IUploadObject } from './serverModel'; | ||
@@ -71,3 +71,5 @@ | ||
const rampNumber = getRampNumber(mpInstance._Store.deviceId); | ||
const rampNumber = mpInstance._Helpers.getRampNumber( | ||
mpInstance._Store.deviceId | ||
); | ||
return eventsV3Percentage >= rampNumber; | ||
@@ -74,0 +76,0 @@ }; |
@@ -32,5 +32,4 @@ import { DataPlanConfig } from '@mparticle/web-sdk'; | ||
attributeFilters: number[]; | ||
filteringEventAttributeValue: IFilteringAttributeValue; | ||
filteringUserAttributeValue: IFilteringAttributeValue; | ||
filteringConsentRuleValues: IFilteringConsentRulesValue; | ||
filteringEventAttributeValue: Dictionary; | ||
filteringConsentRuleValues: Dictionary; | ||
consentRegulationFilters: number[]; | ||
@@ -44,18 +43,2 @@ consentRegulationPurposeFilters: number[]; | ||
export interface IFilteringAttributeValue { | ||
eventAttributeName: string; | ||
eventAttributeValue: string; | ||
includeOnMatch: boolean | ||
} | ||
export interface IFilteringConsentRulesValue { | ||
includeOnMatch: boolean; | ||
values: IConsentRuleValue[]; | ||
} | ||
export interface IConsentRuleValue { | ||
consentPurpose: string; | ||
hasConsented: boolean | ||
} | ||
export interface IPixelConfig { | ||
@@ -62,0 +45,0 @@ name: string; |
@@ -653,3 +653,3 @@ import Types from './types'; | ||
// TODO: isSandbox, hasSandbox is never used in any kit or in core SDK. | ||
// isVisible. Investigate is only used in 1 place. It is always true if | ||
// isVisibleInvestigate is only used in 1 place. It is always true if | ||
// it is sent to JS. Investigate further to determine if these can be removed. | ||
@@ -656,0 +656,0 @@ // https://go.mparticle.com/work/SQDSDKS-5156 |
@@ -29,2 +29,13 @@ import Types from './types'; | ||
/** | ||
* Returns a value between 1-100 inclusive. | ||
*/ | ||
this.getRampNumber = function(deviceId) { | ||
if (!deviceId) { | ||
return 100; | ||
} | ||
var hash = self.generateHash(deviceId); | ||
return Math.abs(hash % 100) + 1; | ||
}; | ||
this.invokeCallback = function( | ||
@@ -277,2 +288,35 @@ callback, | ||
function generateRandomValue(a) { | ||
var randomValue; | ||
if (window.crypto && window.crypto.getRandomValues) { | ||
randomValue = window.crypto.getRandomValues(new Uint8Array(1)); // eslint-disable-line no-undef | ||
} | ||
if (randomValue) { | ||
return (a ^ (randomValue[0] % 16 >> (a / 4))).toString(16); | ||
} | ||
return (a ^ ((Math.random() * 16) >> (a / 4))).toString(16); | ||
} | ||
this.generateUniqueId = function(a) { | ||
// https://gist.github.com/jed/982883 | ||
// Added support for crypto for better random | ||
return a // if the placeholder was passed, return | ||
? generateRandomValue(a) // a random number | ||
: // or otherwise a concatenated string: | ||
( | ||
[1e7] + // 10000000 + | ||
-1e3 + // -1000 + | ||
-4e3 + // -4000 + | ||
-8e3 + // -80000000 + | ||
-1e11 | ||
) // -100000000000, | ||
.replace( | ||
// replacing | ||
/[018]/g, // zeroes, ones, and eights with | ||
self.generateUniqueId // random hex digits | ||
); | ||
}; | ||
this.filterUserIdentities = function(userIdentitiesObject, filterList) { | ||
@@ -364,2 +408,33 @@ var filteredUserIdentities = []; | ||
this.generateHash = function(name) { | ||
var hash = 0, | ||
i = 0, | ||
character; | ||
if (name === undefined || name === null) { | ||
return 0; | ||
} | ||
name = name.toString().toLowerCase(); | ||
if (Array.prototype.reduce) { | ||
return name.split('').reduce(function(a, b) { | ||
a = (a << 5) - a + b.charCodeAt(0); | ||
return a & a; | ||
}, 0); | ||
} | ||
if (name.length === 0) { | ||
return hash; | ||
} | ||
for (i = 0; i < name.length; i++) { | ||
character = name.charCodeAt(i); | ||
hash = (hash << 5) - hash + character; | ||
hash = hash & hash; | ||
} | ||
return hash; | ||
}; | ||
this.sanitizeAttributes = function(attrs, name) { | ||
@@ -432,4 +507,2 @@ if (!attrs || !self.isObject(attrs)) { | ||
// TODO: Refactor SDK to directly use these methods | ||
// https://go.mparticle.com/work/SQDSDKS-5239 | ||
// Utility Functions | ||
@@ -444,4 +517,2 @@ this.converted = utils.converted; | ||
this.parseStringOrNumber = utils.parseStringOrNumber; | ||
this.generateHash = utils.generateHash; | ||
this.generateUniqueId = utils.generateUniqueId; | ||
@@ -448,0 +519,0 @@ // Imported Validators |
@@ -235,2 +235,3 @@ import * as EventsApi from '@mparticle/event-models'; | ||
getFeatureFlag?(feature: string); // TODO: Feature Constants should be converted to enum | ||
getRampNumber?(deviceId: string): number; | ||
isDelayedByIntegration?( | ||
@@ -237,0 +238,0 @@ delayedIntegrations: Dictionary<boolean>, |
@@ -39,77 +39,2 @@ import slugify from 'slugify'; | ||
function generateHash(name: string): number { | ||
let hash: number = 0; | ||
let character: number; | ||
if (name === undefined || name === null) { | ||
return 0; | ||
} | ||
name = name.toString().toLowerCase(); | ||
if (Array.prototype.reduce) { | ||
return name.split('').reduce(function (a: number, b: string) { | ||
a = (a << 5) - a + b.charCodeAt(0); | ||
return a & a; | ||
}, 0); | ||
} | ||
if (name.length === 0) { | ||
return hash; | ||
} | ||
for (let i = 0; i < name.length; i++) { | ||
character = name.charCodeAt(i); | ||
hash = (hash << 5) - hash + character; | ||
hash = hash & hash; | ||
} | ||
return hash; | ||
} | ||
const generateRandomValue = (value?: string): string => { | ||
let randomValue: string; | ||
let a: number; | ||
if (window.crypto && window.crypto.getRandomValues) { | ||
// @ts-ignore | ||
randomValue = window.crypto.getRandomValues(new Uint8Array(1)); // eslint-disable-line no-undef | ||
} | ||
if (randomValue) { | ||
// @ts-ignore | ||
return (a ^ (randomValue[0] % 16 >> (a / 4))).toString(16); | ||
} | ||
return (a ^ ((Math.random() * 16) >> (a / 4))).toString(16); | ||
}; | ||
const generateUniqueId = (a: string = ''): string => | ||
// https://gist.github.com/jed/982883 | ||
// Added support for crypto for better random | ||
a // if the placeholder was passed, return | ||
? generateRandomValue(a) // if the placeholder was passed, return | ||
: // [1e7] -> // 10000000 + | ||
// -1e3 -> // -1000 + | ||
// -4e3 -> // -4000 + | ||
// -8e3 -> // -80000000 + | ||
// -1e11 -> //-100000000000, | ||
`${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`.replace( | ||
/[018]/g, // zeroes, ones, and eights with | ||
generateUniqueId // random hex digits | ||
); | ||
/** | ||
* Returns a value between 1-100 inclusive. | ||
*/ | ||
const getRampNumber = (value?: string): number => { | ||
if (!value) { | ||
return 100; | ||
} | ||
const hash = generateHash(value); | ||
return Math.abs(hash % 100) + 1; | ||
}; | ||
const isObject = (value: any): boolean => { | ||
@@ -155,3 +80,6 @@ var objType = Object.prototype.toString.call(value); | ||
if (s.indexOf('"') === 0) { | ||
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); | ||
s = s | ||
.slice(1, -1) | ||
.replace(/\\"/g, '"') | ||
.replace(/\\\\/g, '\\'); | ||
} | ||
@@ -181,5 +109,2 @@ | ||
findKeyInObject, | ||
generateHash, | ||
generateUniqueId, | ||
getRampNumber, | ||
inArray, | ||
@@ -186,0 +111,0 @@ isObject, |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1464363
40
25925