@mparticle/web-sdk 2.20.1 → 2.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mparticle.common.js +30 -46
- package/dist/mparticle.esm.js +30 -46
- package/dist/mparticle.js +2367 -651
- package/package.json +5 -5
- package/src/apiClient.ts +4 -2
- package/src/configAPIClient.ts +2 -19
- package/src/forwarders.js +1 -1
- package/src/helpers.js +75 -4
- package/src/sdkRuntimeModels.ts +1 -0
- package/src/utils.ts +4 -79
- package/src/forwarders.interfaces.ts +0 -61
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-sdk",
|
|
3
|
-
"version": "2.20.
|
|
3
|
+
"version": "2.20.2",
|
|
4
4
|
"description": "mParticle core SDK for web applications",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"@mparticle/event-models": "^1.1.6",
|
|
79
79
|
"@rollup/plugin-json": "^4.1.0",
|
|
80
80
|
"@rollup/plugin-typescript": "^8.3.3",
|
|
81
|
-
"@rollup/plugin-babel": "
|
|
81
|
+
"@rollup/plugin-babel": "5.3.1",
|
|
82
82
|
"@rollup/plugin-commonjs": "22.0.2",
|
|
83
83
|
"@rollup/plugin-node-resolve": "13.3.0",
|
|
84
84
|
"@semantic-release/changelog": "^5.0.1",
|
|
@@ -93,8 +93,8 @@
|
|
|
93
93
|
"browserify": "^17.0.0",
|
|
94
94
|
"chai": "^4.2.0",
|
|
95
95
|
"cross-env": "^7.0.3",
|
|
96
|
-
"eslint": "^
|
|
97
|
-
"eslint-config-prettier": "8.
|
|
96
|
+
"eslint": "^7.32.0",
|
|
97
|
+
"eslint-config-prettier": "8.3.0",
|
|
98
98
|
"eslint-plugin-prettier": "3.4.1",
|
|
99
99
|
"fetch-mock": "^7.5.1",
|
|
100
100
|
"gts": "^3.1.0",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"should": "^7.1.0",
|
|
117
117
|
"sinon": "^11.0.0",
|
|
118
118
|
"tslib": "^2.1.0",
|
|
119
|
-
"typescript": "^
|
|
119
|
+
"typescript": "^4.2.4",
|
|
120
120
|
"uglify-js": "^3.4.9",
|
|
121
121
|
"webpack": "^5.36.2",
|
|
122
122
|
"webpack-cli": "^4.6.0"
|
package/src/apiClient.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
SDKEvent,
|
|
9
9
|
} from './sdkRuntimeModels';
|
|
10
10
|
import KitBlocker from './kitBlocking';
|
|
11
|
-
import { Dictionary
|
|
11
|
+
import { Dictionary } from './utils';
|
|
12
12
|
import { IUploadObject } from './serverModel';
|
|
13
13
|
|
|
14
14
|
const Messages = Constants.Messages;
|
|
@@ -67,7 +67,9 @@ export default function APIClient(
|
|
|
67
67
|
return false;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const rampNumber =
|
|
70
|
+
const rampNumber = mpInstance._Helpers.getRampNumber(
|
|
71
|
+
mpInstance._Store.deviceId
|
|
72
|
+
);
|
|
71
73
|
return eventsV3Percentage >= rampNumber;
|
|
72
74
|
};
|
|
73
75
|
|
package/src/configAPIClient.ts
CHANGED
|
@@ -29,9 +29,8 @@ export interface IKitConfigs {
|
|
|
29
29
|
eventNameFilters: number[];
|
|
30
30
|
eventTypeFilters: number[];
|
|
31
31
|
attributeFilters: number[];
|
|
32
|
-
filteringEventAttributeValue:
|
|
33
|
-
|
|
34
|
-
filteringConsentRuleValues: IFilteringConsentRulesValue;
|
|
32
|
+
filteringEventAttributeValue: Dictionary;
|
|
33
|
+
filteringConsentRuleValues: Dictionary;
|
|
35
34
|
consentRegulationFilters: number[];
|
|
36
35
|
consentRegulationPurposeFilters: number[];
|
|
37
36
|
messageTypeFilters: number[];
|
|
@@ -40,22 +39,6 @@ export interface IKitConfigs {
|
|
|
40
39
|
excludeAnonymousUser: boolean;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
export interface IFilteringAttributeValue {
|
|
44
|
-
eventAttributeName: string;
|
|
45
|
-
eventAttributeValue: string;
|
|
46
|
-
includeOnMatch: boolean
|
|
47
|
-
}
|
|
48
|
-
export interface IFilteringConsentRulesValue {
|
|
49
|
-
includeOnMatch: boolean;
|
|
50
|
-
values: IConsentRuleValue[];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface IConsentRuleValue {
|
|
54
|
-
consentPurpose: string;
|
|
55
|
-
hasConsented: boolean
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
42
|
export interface IPixelConfig {
|
|
60
43
|
name: string;
|
|
61
44
|
moduleId: number;
|
package/src/forwarders.js
CHANGED
|
@@ -650,7 +650,7 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
650
650
|
newForwarder.id = config.moduleId;
|
|
651
651
|
|
|
652
652
|
// TODO: isSandbox, hasSandbox is never used in any kit or in core SDK.
|
|
653
|
-
//
|
|
653
|
+
// isVisibleInvestigate is only used in 1 place. It is always true if
|
|
654
654
|
// it is sent to JS. Investigate further to determine if these can be removed.
|
|
655
655
|
// https://go.mparticle.com/work/SQDSDKS-5156
|
|
656
656
|
newForwarder.isSandbox = config.isDebug || config.isSandbox;
|
package/src/helpers.js
CHANGED
|
@@ -26,6 +26,17 @@ export default function Helpers(mpInstance) {
|
|
|
26
26
|
return null;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Returns a value between 1-100 inclusive.
|
|
31
|
+
*/
|
|
32
|
+
this.getRampNumber = function(deviceId) {
|
|
33
|
+
if (!deviceId) {
|
|
34
|
+
return 100;
|
|
35
|
+
}
|
|
36
|
+
var hash = self.generateHash(deviceId);
|
|
37
|
+
return Math.abs(hash % 100) + 1;
|
|
38
|
+
};
|
|
39
|
+
|
|
29
40
|
this.invokeCallback = function(
|
|
30
41
|
callback,
|
|
31
42
|
code,
|
|
@@ -273,6 +284,39 @@ export default function Helpers(mpInstance) {
|
|
|
273
284
|
return xhr;
|
|
274
285
|
};
|
|
275
286
|
|
|
287
|
+
function generateRandomValue(a) {
|
|
288
|
+
var randomValue;
|
|
289
|
+
if (window.crypto && window.crypto.getRandomValues) {
|
|
290
|
+
randomValue = window.crypto.getRandomValues(new Uint8Array(1)); // eslint-disable-line no-undef
|
|
291
|
+
}
|
|
292
|
+
if (randomValue) {
|
|
293
|
+
return (a ^ (randomValue[0] % 16 >> (a / 4))).toString(16);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return (a ^ ((Math.random() * 16) >> (a / 4))).toString(16);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
this.generateUniqueId = function(a) {
|
|
300
|
+
// https://gist.github.com/jed/982883
|
|
301
|
+
// Added support for crypto for better random
|
|
302
|
+
|
|
303
|
+
return a // if the placeholder was passed, return
|
|
304
|
+
? generateRandomValue(a) // a random number
|
|
305
|
+
: // or otherwise a concatenated string:
|
|
306
|
+
(
|
|
307
|
+
[1e7] + // 10000000 +
|
|
308
|
+
-1e3 + // -1000 +
|
|
309
|
+
-4e3 + // -4000 +
|
|
310
|
+
-8e3 + // -80000000 +
|
|
311
|
+
-1e11
|
|
312
|
+
) // -100000000000,
|
|
313
|
+
.replace(
|
|
314
|
+
// replacing
|
|
315
|
+
/[018]/g, // zeroes, ones, and eights with
|
|
316
|
+
self.generateUniqueId // random hex digits
|
|
317
|
+
);
|
|
318
|
+
};
|
|
319
|
+
|
|
276
320
|
this.filterUserIdentities = function(userIdentitiesObject, filterList) {
|
|
277
321
|
var filteredUserIdentities = [];
|
|
278
322
|
|
|
@@ -359,6 +403,37 @@ export default function Helpers(mpInstance) {
|
|
|
359
403
|
return false;
|
|
360
404
|
};
|
|
361
405
|
|
|
406
|
+
this.generateHash = function(name) {
|
|
407
|
+
var hash = 0,
|
|
408
|
+
i = 0,
|
|
409
|
+
character;
|
|
410
|
+
|
|
411
|
+
if (name === undefined || name === null) {
|
|
412
|
+
return 0;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
name = name.toString().toLowerCase();
|
|
416
|
+
|
|
417
|
+
if (Array.prototype.reduce) {
|
|
418
|
+
return name.split('').reduce(function(a, b) {
|
|
419
|
+
a = (a << 5) - a + b.charCodeAt(0);
|
|
420
|
+
return a & a;
|
|
421
|
+
}, 0);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (name.length === 0) {
|
|
425
|
+
return hash;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
for (i = 0; i < name.length; i++) {
|
|
429
|
+
character = name.charCodeAt(i);
|
|
430
|
+
hash = (hash << 5) - hash + character;
|
|
431
|
+
hash = hash & hash;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return hash;
|
|
435
|
+
};
|
|
436
|
+
|
|
362
437
|
this.sanitizeAttributes = function(attrs, name) {
|
|
363
438
|
if (!attrs || !self.isObject(attrs)) {
|
|
364
439
|
return null;
|
|
@@ -426,8 +501,6 @@ export default function Helpers(mpInstance) {
|
|
|
426
501
|
}
|
|
427
502
|
};
|
|
428
503
|
|
|
429
|
-
// TODO: Refactor SDK to directly use these methods
|
|
430
|
-
// https://go.mparticle.com/work/SQDSDKS-5239
|
|
431
504
|
// Utility Functions
|
|
432
505
|
this.converted = utils.converted;
|
|
433
506
|
this.findKeyInObject = utils.findKeyInObject;
|
|
@@ -437,8 +510,6 @@ export default function Helpers(mpInstance) {
|
|
|
437
510
|
this.decoded = utils.decoded;
|
|
438
511
|
this.returnConvertedBoolean = utils.returnConvertedBoolean;
|
|
439
512
|
this.parseStringOrNumber = utils.parseStringOrNumber;
|
|
440
|
-
this.generateHash = utils.generateHash;
|
|
441
|
-
this.generateUniqueId = utils.generateUniqueId;
|
|
442
513
|
|
|
443
514
|
// Imported Validators
|
|
444
515
|
this.Validators = Validators;
|
package/src/sdkRuntimeModels.ts
CHANGED
|
@@ -232,6 +232,7 @@ export interface SDKHelpersApi {
|
|
|
232
232
|
generateUniqueId();
|
|
233
233
|
generateHash?(value: string): string;
|
|
234
234
|
getFeatureFlag?(feature: string); // TODO: Feature Constants should be converted to enum
|
|
235
|
+
getRampNumber?(deviceId: string): number;
|
|
235
236
|
isDelayedByIntegration?(
|
|
236
237
|
delayedIntegrations: Dictionary<boolean>,
|
|
237
238
|
timeoutStart: number,
|
package/src/utils.ts
CHANGED
|
@@ -36,81 +36,6 @@ const findKeyInObject = (obj: any, key: string): string => {
|
|
|
36
36
|
return null;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
function generateHash(name: string): number {
|
|
40
|
-
let hash: number = 0;
|
|
41
|
-
let character: number;
|
|
42
|
-
|
|
43
|
-
if (name === undefined || name === null) {
|
|
44
|
-
return 0;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
name = name.toString().toLowerCase();
|
|
48
|
-
|
|
49
|
-
if (Array.prototype.reduce) {
|
|
50
|
-
return name.split('').reduce(function (a: number, b: string) {
|
|
51
|
-
a = (a << 5) - a + b.charCodeAt(0);
|
|
52
|
-
return a & a;
|
|
53
|
-
}, 0);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (name.length === 0) {
|
|
57
|
-
return hash;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
for (let i = 0; i < name.length; i++) {
|
|
61
|
-
character = name.charCodeAt(i);
|
|
62
|
-
hash = (hash << 5) - hash + character;
|
|
63
|
-
hash = hash & hash;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return hash;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const generateRandomValue = (value?: string): string => {
|
|
70
|
-
let randomValue: string;
|
|
71
|
-
let a: number;
|
|
72
|
-
|
|
73
|
-
if (window.crypto && window.crypto.getRandomValues) {
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
randomValue = window.crypto.getRandomValues(new Uint8Array(1)); // eslint-disable-line no-undef
|
|
76
|
-
}
|
|
77
|
-
if (randomValue) {
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
return (a ^ (randomValue[0] % 16 >> (a / 4))).toString(16);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return (a ^ ((Math.random() * 16) >> (a / 4))).toString(16);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const generateUniqueId = (a: string = ''): string =>
|
|
86
|
-
// https://gist.github.com/jed/982883
|
|
87
|
-
// Added support for crypto for better random
|
|
88
|
-
|
|
89
|
-
a // if the placeholder was passed, return
|
|
90
|
-
? generateRandomValue(a) // if the placeholder was passed, return
|
|
91
|
-
: // [1e7] -> // 10000000 +
|
|
92
|
-
// -1e3 -> // -1000 +
|
|
93
|
-
// -4e3 -> // -4000 +
|
|
94
|
-
// -8e3 -> // -80000000 +
|
|
95
|
-
// -1e11 -> //-100000000000,
|
|
96
|
-
`${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`.replace(
|
|
97
|
-
/[018]/g, // zeroes, ones, and eights with
|
|
98
|
-
generateUniqueId // random hex digits
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Returns a value between 1-100 inclusive.
|
|
103
|
-
*/
|
|
104
|
-
const getRampNumber = (value?: string): number => {
|
|
105
|
-
if (!value) {
|
|
106
|
-
return 100;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const hash = generateHash(value);
|
|
110
|
-
|
|
111
|
-
return Math.abs(hash % 100) + 1;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
39
|
const isObject = (value: any): boolean => {
|
|
115
40
|
var objType = Object.prototype.toString.call(value);
|
|
116
41
|
return objType === '[object Object]' || objType === '[object Error]';
|
|
@@ -151,7 +76,10 @@ const decoded = (s: string): string =>
|
|
|
151
76
|
|
|
152
77
|
const converted = (s: string): string => {
|
|
153
78
|
if (s.indexOf('"') === 0) {
|
|
154
|
-
s = s
|
|
79
|
+
s = s
|
|
80
|
+
.slice(1, -1)
|
|
81
|
+
.replace(/\\"/g, '"')
|
|
82
|
+
.replace(/\\\\/g, '\\');
|
|
155
83
|
}
|
|
156
84
|
|
|
157
85
|
return s;
|
|
@@ -176,9 +104,6 @@ export {
|
|
|
176
104
|
converted,
|
|
177
105
|
decoded,
|
|
178
106
|
findKeyInObject,
|
|
179
|
-
generateHash,
|
|
180
|
-
generateUniqueId,
|
|
181
|
-
getRampNumber,
|
|
182
107
|
inArray,
|
|
183
108
|
isObject,
|
|
184
109
|
isStringOrNumber,
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { MParticleUser, SDKEvent, SDKEventCustomFlags, SDKUserIdentity } from './sdkRuntimeModels';
|
|
2
|
-
import { Dictionary } from './utils';
|
|
3
|
-
import { IKitConfigs } from './configAPIClient';
|
|
4
|
-
import { UserAttributes } from './persistence.interfaces';
|
|
5
|
-
import { IdentityApiData } from '@mparticle/web-sdk';
|
|
6
|
-
|
|
7
|
-
// The state of the kit when accessed via window.KitName via CDN
|
|
8
|
-
// or imported as an NPM package
|
|
9
|
-
export interface UnregisteredKit {
|
|
10
|
-
register(config): void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// The state of the kit after being added to forwarderConstructors in the CDN
|
|
14
|
-
// or after registered to SDKConfig.kits via NPM
|
|
15
|
-
export interface RegisteredKit {
|
|
16
|
-
constructor(): void;
|
|
17
|
-
name: string;
|
|
18
|
-
getId(): number;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// The state of the kit after being configured. This is what the kit looks like when acted on.
|
|
22
|
-
export interface ConfiguredKit
|
|
23
|
-
extends Omit<IKitConfigs, 'isDebugString' | 'hasDebugString'> {
|
|
24
|
-
common: Dictionary<unknown>;
|
|
25
|
-
init(
|
|
26
|
-
settings: Dictionary<unknown>,
|
|
27
|
-
service: forwardingStatsCallback,
|
|
28
|
-
testMode: boolean,
|
|
29
|
-
trackerId: string | null,
|
|
30
|
-
userAttributes: UserAttributes,
|
|
31
|
-
userIdentities: SDKUserIdentity,
|
|
32
|
-
appVersion: string,
|
|
33
|
-
appName: string,
|
|
34
|
-
customFlags: SDKEventCustomFlags,
|
|
35
|
-
clientId: string): string;
|
|
36
|
-
onIdentifyComplete(user: MParticleUser, filteredIdentityRequest: IdentityApiData): string | KitMappedMethodFailure;
|
|
37
|
-
onLoginComplete(user: MParticleUser, filteredIdentityRequest: IdentityApiData): string | KitMappedMethodFailure;
|
|
38
|
-
onLogoutComplete(user: MParticleUser, filteredIdentityRequest: IdentityApiData): string | KitMappedMethodFailure;
|
|
39
|
-
onModifyComplete(user: MParticleUser, filteredIdentityRequest: IdentityApiData): string | KitMappedMethodFailure;
|
|
40
|
-
onUserIdentified(user: MParticleUser): string | KitMappedMethodFailure;
|
|
41
|
-
process(event: SDKEvent): string;
|
|
42
|
-
setOptOut(isOptingOut: boolean): string | KitMappedMethodFailure;
|
|
43
|
-
removeUserAttribute(key: string): string;
|
|
44
|
-
setUserAttribute(key: string, value:string): string;
|
|
45
|
-
|
|
46
|
-
// TODO: Convert type to enum during Identity migration
|
|
47
|
-
// https://go.mparticle.com/work/SQDSDKS-5218
|
|
48
|
-
setUserIdentity(id: UserIdentityId, type: UserIdentityType): void;
|
|
49
|
-
|
|
50
|
-
// TODO: https://go.mparticle.com/work/SQDSDKS-5156
|
|
51
|
-
isSandbox: boolean;
|
|
52
|
-
hasSandbox: boolean;
|
|
53
|
-
}
|
|
54
|
-
export interface KitMappedMethodFailure {
|
|
55
|
-
error: string
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export type UserIdentityId = string;
|
|
59
|
-
export type UserIdentityType = number;
|
|
60
|
-
|
|
61
|
-
export type forwardingStatsCallback = (forwarder: ConfiguredKit, event: SDKEvent) => void;
|