@mparticle/web-sdk 2.19.3 → 2.20.1
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 +77 -37
- package/dist/mparticle.esm.js +77 -37
- package/dist/mparticle.js +747 -2389
- package/package.json +5 -5
- package/src/apiClient.ts +2 -4
- package/src/configAPIClient.ts +19 -2
- package/src/forwarders.interfaces.ts +61 -0
- package/src/forwarders.js +141 -72
- package/src/helpers.js +4 -75
- package/src/mockBatchCreator.ts +1 -0
- package/src/mp-instance.js +2 -0
- package/src/persistence.interfaces.ts +138 -0
- package/src/persistence.js +3 -0
- package/src/sdkRuntimeModels.ts +3 -2
- package/src/store.ts +9 -3
- package/src/utils.ts +79 -4
package/src/persistence.js
CHANGED
|
@@ -959,6 +959,9 @@ export default function _Persistence(mpInstance) {
|
|
|
959
959
|
if (userAttributes) {
|
|
960
960
|
if (persistence) {
|
|
961
961
|
if (persistence[mpid]) {
|
|
962
|
+
// TODO: Investigate why setting this to UI still shows up as UA
|
|
963
|
+
// when running `mParticle.getInstance()._Persistence.getLocalStorage()`
|
|
964
|
+
// https://go.mparticle.com/work/SQDSDKS-5195
|
|
962
965
|
persistence[mpid].ui = userAttributes;
|
|
963
966
|
} else {
|
|
964
967
|
persistence[mpid] = {
|
package/src/sdkRuntimeModels.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { Dictionary } from './utils';
|
|
|
7
7
|
import { IServerModel } from './serverModel';
|
|
8
8
|
import { IKitConfigs } from './configAPIClient';
|
|
9
9
|
import { SDKConsentApi, SDKConsentState } from './consent';
|
|
10
|
+
import { IPersistence } from './persistence.interfaces';
|
|
10
11
|
|
|
11
12
|
// TODO: Resolve this with version in @mparticle/web-sdk
|
|
12
13
|
export type SDKEventCustomFlags = Dictionary<any>;
|
|
@@ -139,7 +140,7 @@ export interface MParticleWebSDK {
|
|
|
139
140
|
_Consent: SDKConsentApi;
|
|
140
141
|
Consent: SDKConsentApi;
|
|
141
142
|
_NativeSdkHelpers: any; // TODO: Set up API
|
|
142
|
-
_Persistence:
|
|
143
|
+
_Persistence: IPersistence;
|
|
143
144
|
_preInit: any; // TODO: Set up API
|
|
144
145
|
_resetForTests(MPConfig?: SDKInitConfig): void;
|
|
145
146
|
init(apiKey: string, config: SDKInitConfig, instanceName?: string): void;
|
|
@@ -186,6 +187,7 @@ export interface SDKInitConfig
|
|
|
186
187
|
|
|
187
188
|
kitConfigs?: IKitConfigs[];
|
|
188
189
|
kits?: Dictionary<Kit>;
|
|
190
|
+
sideloadedKits?: MPForwarder[];
|
|
189
191
|
dataPlanOptions?: KitBlockerOptions;
|
|
190
192
|
flags?: Dictionary;
|
|
191
193
|
|
|
@@ -230,7 +232,6 @@ export interface SDKHelpersApi {
|
|
|
230
232
|
generateUniqueId();
|
|
231
233
|
generateHash?(value: string): string;
|
|
232
234
|
getFeatureFlag?(feature: string); // TODO: Feature Constants should be converted to enum
|
|
233
|
-
getRampNumber?(deviceId: string): number;
|
|
234
235
|
isDelayedByIntegration?(
|
|
235
236
|
delayedIntegrations: Dictionary<boolean>,
|
|
236
237
|
timeoutStart: number,
|
package/src/store.ts
CHANGED
|
@@ -54,7 +54,7 @@ export interface SDKConfig {
|
|
|
54
54
|
identifyRequest: IdentifyRequest;
|
|
55
55
|
identityCallback: IdentityCallback;
|
|
56
56
|
integrationDelayTimeout: number;
|
|
57
|
-
|
|
57
|
+
sideloadedKits: MPForwarder[];
|
|
58
58
|
aliasMaxWindow: number;
|
|
59
59
|
deviceId?: string;
|
|
60
60
|
forceHttps?: boolean;
|
|
@@ -101,6 +101,8 @@ function createSDKConfig(config: SDKInitConfig): SDKConfig {
|
|
|
101
101
|
export type PixelConfiguration = Dictionary;
|
|
102
102
|
export type MigrationData = Dictionary;
|
|
103
103
|
export type ServerSettings = Dictionary;
|
|
104
|
+
export type SessionAttributes = Dictionary;
|
|
105
|
+
export type IntegrationAttributes = Dictionary<Dictionary<string>>;
|
|
104
106
|
|
|
105
107
|
type WrapperSDKTypes = 'flutter' | 'none';
|
|
106
108
|
interface WrapperSDKInfo {
|
|
@@ -112,7 +114,7 @@ interface WrapperSDKInfo {
|
|
|
112
114
|
// Temporary Interface until Store can be refactored as a class
|
|
113
115
|
export interface IStore {
|
|
114
116
|
isEnabled: boolean;
|
|
115
|
-
sessionAttributes:
|
|
117
|
+
sessionAttributes: SessionAttributes;
|
|
116
118
|
currentSessionMPIDs: MPID[];
|
|
117
119
|
consentState: SDKConsentState | null;
|
|
118
120
|
sessionId: string | null;
|
|
@@ -140,13 +142,14 @@ export interface IStore {
|
|
|
140
142
|
identifyCalled: boolean;
|
|
141
143
|
isLoggedIn: boolean;
|
|
142
144
|
cookieSyncDates: Dictionary<number>;
|
|
143
|
-
integrationAttributes:
|
|
145
|
+
integrationAttributes: IntegrationAttributes;
|
|
144
146
|
requireDelay: boolean;
|
|
145
147
|
isLocalStorageAvailable: boolean | null;
|
|
146
148
|
storageName: string | null;
|
|
147
149
|
prodStorageName: string | null;
|
|
148
150
|
activeForwarders: MPForwarder[];
|
|
149
151
|
kits: Dictionary<MPForwarder>;
|
|
152
|
+
sideloadedKits: MPForwarder[];
|
|
150
153
|
configuredForwarders: MPForwarder[];
|
|
151
154
|
pixelConfigurations: PixelConfiguration[];
|
|
152
155
|
integrationDelayTimeoutStart: number; // UNIX Timestamp
|
|
@@ -197,6 +200,7 @@ export default function Store(
|
|
|
197
200
|
prodStorageName: null,
|
|
198
201
|
activeForwarders: [],
|
|
199
202
|
kits: {},
|
|
203
|
+
sideloadedKits: [],
|
|
200
204
|
configuredForwarders: [],
|
|
201
205
|
pixelConfigurations: [],
|
|
202
206
|
wrapperSDKInfo: {
|
|
@@ -259,6 +263,8 @@ export default function Store(
|
|
|
259
263
|
|
|
260
264
|
this.SDKConfig.kits = config.kits || {};
|
|
261
265
|
|
|
266
|
+
this.SDKConfig.sideloadedKits = config.sideloadedKits || [];
|
|
267
|
+
|
|
262
268
|
if (config.hasOwnProperty('isIOS')) {
|
|
263
269
|
this.SDKConfig.isIOS = config.isIOS;
|
|
264
270
|
} else {
|
package/src/utils.ts
CHANGED
|
@@ -36,6 +36,81 @@ 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
|
+
|
|
39
114
|
const isObject = (value: any): boolean => {
|
|
40
115
|
var objType = Object.prototype.toString.call(value);
|
|
41
116
|
return objType === '[object Object]' || objType === '[object Error]';
|
|
@@ -76,10 +151,7 @@ const decoded = (s: string): string =>
|
|
|
76
151
|
|
|
77
152
|
const converted = (s: string): string => {
|
|
78
153
|
if (s.indexOf('"') === 0) {
|
|
79
|
-
s = s
|
|
80
|
-
.slice(1, -1)
|
|
81
|
-
.replace(/\\"/g, '"')
|
|
82
|
-
.replace(/\\\\/g, '\\');
|
|
154
|
+
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
|
|
83
155
|
}
|
|
84
156
|
|
|
85
157
|
return s;
|
|
@@ -104,6 +176,9 @@ export {
|
|
|
104
176
|
converted,
|
|
105
177
|
decoded,
|
|
106
178
|
findKeyInObject,
|
|
179
|
+
generateHash,
|
|
180
|
+
generateUniqueId,
|
|
181
|
+
getRampNumber,
|
|
107
182
|
inArray,
|
|
108
183
|
isObject,
|
|
109
184
|
isStringOrNumber,
|