@mparticle/web-sdk 2.80.0 → 2.81.0
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 +75 -488
- package/dist/mparticle.esm.js +75 -488
- package/dist/mparticle.js +244 -673
- package/dist/types/src/configAPIClient.d.ts +1 -0
- package/dist/types/src/ecommerce.d.ts +3 -53
- package/dist/types/src/ecommerce.interfaces.d.ts +11 -12
- package/dist/types/src/events.interfaces.d.ts +1 -1
- package/dist/types/src/forwarders.d.ts +4 -26
- package/dist/types/src/forwarders.interfaces.d.ts +41 -10
- package/dist/types/src/identity-utils.d.ts +3 -3
- package/dist/types/src/identity.d.ts +3 -0
- package/dist/types/src/identity.interfaces.d.ts +45 -11
- package/dist/types/src/identityApiClient.d.ts +5 -4
- package/dist/types/src/mp-instance.d.ts +2 -2
- package/dist/types/src/persistence.interfaces.d.ts +2 -3
- package/dist/types/src/roktManager.d.ts +18 -0
- package/dist/types/src/sdkRuntimeModels.d.ts +2 -2
- package/dist/types/src/store.d.ts +4 -3
- package/package.json +1 -1
- package/src/configAPIClient.ts +1 -0
- package/src/ecommerce.interfaces.ts +12 -21
- package/src/{ecommerce.js → ecommerce.ts} +144 -73
- package/src/events.interfaces.ts +1 -1
- package/src/events.ts +1 -1
- package/src/forwarders.interfaces.ts +73 -10
- package/src/{forwarders.js → forwarders.ts} +214 -176
- package/src/helpers.ts +7 -3
- package/src/identity-utils.ts +2 -2
- package/src/identity.interfaces.ts +58 -14
- package/src/{identity.js → identity.ts} +237 -192
- package/src/identityApiClient.ts +9 -9
- package/src/mp-instance.ts +2 -2
- package/src/persistence.interfaces.ts +2 -3
- package/src/roktManager.ts +37 -0
- package/src/sdkRuntimeModels.ts +2 -1
- package/src/store.ts +4 -3
|
@@ -1,19 +1,79 @@
|
|
|
1
1
|
import filteredMparticleUser from './filteredMparticleUser';
|
|
2
|
-
import { isEmpty, extend } from './utils';
|
|
2
|
+
import { isEmpty, extend, Dictionary } from './utils';
|
|
3
3
|
import KitFilterHelper from './kitFilterHelper';
|
|
4
4
|
import Constants from './constants';
|
|
5
|
-
import APIClient from './apiClient';
|
|
5
|
+
import APIClient, { IForwardingStatsData } from './apiClient';
|
|
6
6
|
import {
|
|
7
7
|
isBlockedByForwardingRule,
|
|
8
8
|
isBlockedByEventFilter,
|
|
9
9
|
filterEventAttributes,
|
|
10
10
|
filterUserIdentities,
|
|
11
11
|
} from './forwarder-utils';
|
|
12
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
13
|
+
import KitBlocker from './kitBlocking';
|
|
14
|
+
import {
|
|
15
|
+
ConfiguredKit,
|
|
16
|
+
IForwarders,
|
|
17
|
+
RegisteredKit,
|
|
18
|
+
forwardingStatsCallback,
|
|
19
|
+
} from './forwarders.interfaces';
|
|
20
|
+
import { SDKEvent, SDKInitConfig } from './sdkRuntimeModels';
|
|
21
|
+
import {
|
|
22
|
+
IKitConfigs,
|
|
23
|
+
IFilteringUserAttributeValue,
|
|
24
|
+
} from './configAPIClient';
|
|
25
|
+
import { UserIdentities } from '@mparticle/web-sdk';
|
|
26
|
+
import { IMParticleUser } from './identity-user-interfaces';
|
|
27
|
+
import { IPixelConfiguration } from './cookieSyncManager';
|
|
12
28
|
|
|
13
29
|
const { Modify, Identify, Login, Logout } = Constants.IdentityMethods;
|
|
14
30
|
|
|
15
|
-
|
|
16
|
-
|
|
31
|
+
// Maps an identity method to the kit callback that reports its completion.
|
|
32
|
+
const identityCompleteKitMethods: Dictionary<
|
|
33
|
+
| 'onIdentifyComplete'
|
|
34
|
+
| 'onLoginComplete'
|
|
35
|
+
| 'onLogoutComplete'
|
|
36
|
+
| 'onModifyComplete'
|
|
37
|
+
> = {
|
|
38
|
+
[Identify]: 'onIdentifyComplete',
|
|
39
|
+
[Login]: 'onLoginComplete',
|
|
40
|
+
[Logout]: 'onLogoutComplete',
|
|
41
|
+
[Modify]: 'onModifyComplete',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function userAttributesMatchFilter(
|
|
45
|
+
userAttributes: Dictionary,
|
|
46
|
+
filterObject: Partial<IFilteringUserAttributeValue>
|
|
47
|
+
): boolean {
|
|
48
|
+
for (const attrName in userAttributes) {
|
|
49
|
+
if (!userAttributes.hasOwnProperty(attrName)) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const attrHash = KitFilterHelper.hashAttributeConditionalForwarding(
|
|
54
|
+
attrName
|
|
55
|
+
);
|
|
56
|
+
const valueHash = KitFilterHelper.hashAttributeConditionalForwarding(
|
|
57
|
+
userAttributes[attrName]
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
if (
|
|
61
|
+
attrHash === filterObject.userAttributeName &&
|
|
62
|
+
valueHash === filterObject.userAttributeValue
|
|
63
|
+
) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default function Forwarders(
|
|
72
|
+
this: IForwarders,
|
|
73
|
+
mpInstance: IMParticleWebSDKInstance,
|
|
74
|
+
kitBlocker: KitBlocker
|
|
75
|
+
): void {
|
|
76
|
+
const self = this;
|
|
17
77
|
this.forwarderStatsUploader = new APIClient(
|
|
18
78
|
mpInstance,
|
|
19
79
|
kitBlocker
|
|
@@ -24,8 +84,11 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
24
84
|
removeUserAttribute: 'removeUserAttribute',
|
|
25
85
|
};
|
|
26
86
|
|
|
27
|
-
this.initForwarders = function(
|
|
28
|
-
|
|
87
|
+
this.initForwarders = function(
|
|
88
|
+
userIdentities: UserIdentities,
|
|
89
|
+
forwardingStatsCallback: forwardingStatsCallback
|
|
90
|
+
): void {
|
|
91
|
+
const user = mpInstance.Identity.getCurrentUser();
|
|
29
92
|
if (
|
|
30
93
|
!mpInstance._Store.webviewBridgeEnabled &&
|
|
31
94
|
mpInstance._Store.configuredForwarders
|
|
@@ -66,7 +129,7 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
66
129
|
return false;
|
|
67
130
|
}
|
|
68
131
|
|
|
69
|
-
|
|
132
|
+
const filteredUserIdentities = mpInstance._Helpers.filterUserIdentities(
|
|
70
133
|
userIdentities,
|
|
71
134
|
forwarder.userIdentityFilters
|
|
72
135
|
);
|
|
@@ -97,7 +160,10 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
97
160
|
}
|
|
98
161
|
};
|
|
99
162
|
|
|
100
|
-
this.isEnabledForUserAttributes = function(
|
|
163
|
+
this.isEnabledForUserAttributes = function(
|
|
164
|
+
filterObject: Partial<IFilteringUserAttributeValue>,
|
|
165
|
+
user: IMParticleUser
|
|
166
|
+
): boolean {
|
|
101
167
|
if (
|
|
102
168
|
!filterObject ||
|
|
103
169
|
!mpInstance._Helpers.isObject(filterObject) ||
|
|
@@ -106,54 +172,33 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
106
172
|
return true;
|
|
107
173
|
}
|
|
108
174
|
|
|
109
|
-
var attrHash, valueHash, userAttributes;
|
|
110
|
-
|
|
111
175
|
if (!user) {
|
|
112
176
|
return false;
|
|
113
|
-
} else {
|
|
114
|
-
userAttributes = user.getAllUserAttributes();
|
|
115
177
|
}
|
|
116
178
|
|
|
117
|
-
|
|
179
|
+
const userAttributes = user.getAllUserAttributes();
|
|
118
180
|
|
|
119
181
|
try {
|
|
120
|
-
|
|
182
|
+
const hasUserAttributes =
|
|
121
183
|
userAttributes &&
|
|
122
184
|
mpInstance._Helpers.isObject(userAttributes) &&
|
|
123
|
-
Object.keys(userAttributes).length
|
|
124
|
-
) {
|
|
125
|
-
for (var attrName in userAttributes) {
|
|
126
|
-
if (userAttributes.hasOwnProperty(attrName)) {
|
|
127
|
-
attrHash = KitFilterHelper.hashAttributeConditionalForwarding(
|
|
128
|
-
attrName
|
|
129
|
-
);
|
|
130
|
-
valueHash = KitFilterHelper.hashAttributeConditionalForwarding(
|
|
131
|
-
userAttributes[attrName]
|
|
132
|
-
);
|
|
185
|
+
Object.keys(userAttributes).length > 0;
|
|
133
186
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
) {
|
|
138
|
-
isMatch = true;
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
187
|
+
const isMatch = hasUserAttributes
|
|
188
|
+
? userAttributesMatchFilter(userAttributes, filterObject)
|
|
189
|
+
: false;
|
|
144
190
|
|
|
145
|
-
|
|
146
|
-
return filterObject.includeOnMatch === isMatch;
|
|
147
|
-
} else {
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
191
|
+
return filterObject.includeOnMatch === isMatch;
|
|
150
192
|
} catch (e) {
|
|
151
193
|
// in any error scenario, err on side of returning true and forwarding event
|
|
152
194
|
return true;
|
|
153
195
|
}
|
|
154
196
|
};
|
|
155
197
|
|
|
156
|
-
this.isEnabledForUnknownUser = function(
|
|
198
|
+
this.isEnabledForUnknownUser = function(
|
|
199
|
+
excludeAnonymousUserBoolean: boolean,
|
|
200
|
+
user: IMParticleUser
|
|
201
|
+
): boolean {
|
|
157
202
|
if (!user || !user.isLoggedIn()) {
|
|
158
203
|
if (excludeAnonymousUserBoolean) {
|
|
159
204
|
return false;
|
|
@@ -162,108 +207,111 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
162
207
|
return true;
|
|
163
208
|
};
|
|
164
209
|
|
|
165
|
-
this.applyToForwarders = function(functionName, functionArgs) {
|
|
210
|
+
this.applyToForwarders = function(functionName: string, functionArgs: unknown): void {
|
|
166
211
|
if (mpInstance._Store.activeForwarders.length) {
|
|
167
212
|
mpInstance._Store.activeForwarders.forEach(function(forwarder) {
|
|
168
|
-
|
|
213
|
+
const forwarderFunction = (forwarder as any)[functionName];
|
|
169
214
|
if (forwarderFunction) {
|
|
170
215
|
try {
|
|
171
|
-
|
|
216
|
+
const result = (forwarder as any)[functionName](functionArgs);
|
|
172
217
|
|
|
173
218
|
if (result) {
|
|
174
219
|
mpInstance.Logger.verbose(result);
|
|
175
220
|
}
|
|
176
221
|
} catch (e) {
|
|
177
|
-
mpInstance.Logger.verbose(e);
|
|
222
|
+
mpInstance.Logger.verbose(e as any);
|
|
178
223
|
}
|
|
179
224
|
}
|
|
180
225
|
});
|
|
181
226
|
}
|
|
182
227
|
};
|
|
183
228
|
|
|
184
|
-
this.sendEventToForwarders = function(event) {
|
|
185
|
-
let clonedEvent;
|
|
186
|
-
let hashedEventName;
|
|
187
|
-
let hashedEventType;
|
|
188
|
-
|
|
229
|
+
this.sendEventToForwarders = function(event: SDKEvent): void {
|
|
189
230
|
if (
|
|
190
|
-
|
|
191
|
-
mpInstance._Store.activeForwarders
|
|
231
|
+
mpInstance._Store.webviewBridgeEnabled ||
|
|
232
|
+
!mpInstance._Store.activeForwarders
|
|
192
233
|
) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
event.EventCategory
|
|
196
|
-
);
|
|
197
|
-
hashedEventType = KitFilterHelper.hashEventType(
|
|
198
|
-
event.EventCategory
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
for (
|
|
202
|
-
let i = 0;
|
|
203
|
-
i < mpInstance._Store.activeForwarders.length;
|
|
204
|
-
i++
|
|
205
|
-
) {
|
|
206
|
-
const forwarder = mpInstance._Store.activeForwarders[i];
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
207
236
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
237
|
+
const hashedEventName = KitFilterHelper.hashEventName(
|
|
238
|
+
event.EventName,
|
|
239
|
+
event.EventCategory as any
|
|
240
|
+
);
|
|
241
|
+
const hashedEventType = KitFilterHelper.hashEventType(
|
|
242
|
+
event.EventCategory as any
|
|
243
|
+
);
|
|
217
244
|
|
|
218
|
-
|
|
219
|
-
|
|
245
|
+
const forwardEvent = function(forwarder: ConfiguredKit): void {
|
|
246
|
+
if (
|
|
247
|
+
isBlockedByForwardingRule(
|
|
248
|
+
event.EventDataType,
|
|
249
|
+
event.EventAttributes,
|
|
250
|
+
forwarder
|
|
251
|
+
)
|
|
252
|
+
) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
220
255
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
event.EventDataType,
|
|
224
|
-
hashedEventName,
|
|
225
|
-
hashedEventType,
|
|
226
|
-
forwarder
|
|
227
|
-
)
|
|
228
|
-
) {
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
256
|
+
// Clone the event object, as we could be sending different attributes to each forwarder
|
|
257
|
+
const clonedEvent = extend(true, {}, event);
|
|
231
258
|
|
|
232
|
-
|
|
259
|
+
if (
|
|
260
|
+
isBlockedByEventFilter(
|
|
233
261
|
event.EventDataType,
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
clonedEvent.EventAttributes,
|
|
262
|
+
hashedEventName,
|
|
263
|
+
hashedEventType,
|
|
237
264
|
forwarder
|
|
238
|
-
)
|
|
265
|
+
)
|
|
266
|
+
) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
239
269
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
270
|
+
clonedEvent.EventAttributes = filterEventAttributes(
|
|
271
|
+
event.EventDataType,
|
|
272
|
+
event.EventCategory,
|
|
273
|
+
event.EventName,
|
|
274
|
+
clonedEvent.EventAttributes,
|
|
275
|
+
forwarder
|
|
276
|
+
);
|
|
245
277
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
278
|
+
// Check user identity filtering rules
|
|
279
|
+
clonedEvent.UserIdentities = filterUserIdentities(
|
|
280
|
+
clonedEvent.UserIdentities,
|
|
281
|
+
forwarder.userIdentityFilters
|
|
282
|
+
);
|
|
251
283
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
284
|
+
// Check user attribute filtering rules
|
|
285
|
+
clonedEvent.UserAttributes = KitFilterHelper.filterUserAttributes(
|
|
286
|
+
clonedEvent.UserAttributes,
|
|
287
|
+
forwarder.userAttributeFilters
|
|
288
|
+
);
|
|
257
289
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
}
|
|
290
|
+
if (!forwarder.process) {
|
|
291
|
+
return;
|
|
262
292
|
}
|
|
263
|
-
|
|
293
|
+
|
|
294
|
+
mpInstance.Logger.verbose(
|
|
295
|
+
'Sending message to forwarder: ' + forwarder.name
|
|
296
|
+
);
|
|
297
|
+
const result = forwarder.process(clonedEvent);
|
|
298
|
+
|
|
299
|
+
if (result) {
|
|
300
|
+
mpInstance.Logger.verbose(result);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
// Not for...of: the downleveled loop is miscompiled in cjs/esm builds.
|
|
305
|
+
mpInstance._Store.activeForwarders.forEach(function(forwarder) {
|
|
306
|
+
forwardEvent(forwarder);
|
|
307
|
+
});
|
|
264
308
|
};
|
|
265
309
|
|
|
266
|
-
this.handleForwarderUserAttributes = function(
|
|
310
|
+
this.handleForwarderUserAttributes = function(
|
|
311
|
+
functionNameKey: string,
|
|
312
|
+
key: string,
|
|
313
|
+
value: string
|
|
314
|
+
): void {
|
|
267
315
|
if (
|
|
268
316
|
(kitBlocker && kitBlocker.isAttributeKeyBlocked(key)) ||
|
|
269
317
|
!mpInstance._Store.activeForwarders.length
|
|
@@ -272,7 +320,7 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
272
320
|
}
|
|
273
321
|
|
|
274
322
|
mpInstance._Store.activeForwarders.forEach(function(forwarder) {
|
|
275
|
-
const forwarderFunction = forwarder[functionNameKey];
|
|
323
|
+
const forwarderFunction = (forwarder as any)[functionNameKey];
|
|
276
324
|
if (
|
|
277
325
|
!forwarderFunction ||
|
|
278
326
|
KitFilterHelper.isFilteredUserAttribute(
|
|
@@ -301,21 +349,21 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
301
349
|
mpInstance.Logger.verbose(result);
|
|
302
350
|
}
|
|
303
351
|
} catch (e) {
|
|
304
|
-
mpInstance.Logger.error(e);
|
|
352
|
+
mpInstance.Logger.error(e as any);
|
|
305
353
|
}
|
|
306
354
|
});
|
|
307
355
|
};
|
|
308
356
|
|
|
309
357
|
// TODO: https://go.mparticle.com/work/SQDSDKS-6036
|
|
310
|
-
this.setForwarderUserIdentities = function(userIdentities) {
|
|
358
|
+
this.setForwarderUserIdentities = function(userIdentities: UserIdentities): void {
|
|
311
359
|
mpInstance._Store.activeForwarders.forEach(function(forwarder) {
|
|
312
|
-
|
|
360
|
+
const filteredUserIdentities = mpInstance._Helpers.filterUserIdentities(
|
|
313
361
|
userIdentities,
|
|
314
362
|
forwarder.userIdentityFilters
|
|
315
363
|
);
|
|
316
364
|
if (forwarder.setUserIdentity) {
|
|
317
365
|
filteredUserIdentities.forEach(function(identity) {
|
|
318
|
-
|
|
366
|
+
const result = forwarder.setUserIdentity(
|
|
319
367
|
identity.Identity,
|
|
320
368
|
identity.Type
|
|
321
369
|
);
|
|
@@ -327,16 +375,16 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
327
375
|
});
|
|
328
376
|
};
|
|
329
377
|
|
|
330
|
-
this.setForwarderOnUserIdentified = function(user) {
|
|
378
|
+
this.setForwarderOnUserIdentified = function(user: IMParticleUser): void {
|
|
331
379
|
mpInstance._Store.activeForwarders.forEach(function(forwarder) {
|
|
332
|
-
|
|
380
|
+
let filteredUser = filteredMparticleUser(
|
|
333
381
|
user.getMPID(),
|
|
334
382
|
forwarder,
|
|
335
383
|
mpInstance,
|
|
336
384
|
kitBlocker
|
|
337
385
|
);
|
|
338
386
|
if (forwarder.onUserIdentified) {
|
|
339
|
-
|
|
387
|
+
let result = forwarder.onUserIdentified(filteredUser);
|
|
340
388
|
if (result) {
|
|
341
389
|
mpInstance.Logger.verbose(result);
|
|
342
390
|
}
|
|
@@ -344,69 +392,48 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
344
392
|
});
|
|
345
393
|
};
|
|
346
394
|
|
|
347
|
-
this.setForwarderOnIdentityComplete = function(
|
|
348
|
-
|
|
395
|
+
this.setForwarderOnIdentityComplete = function(
|
|
396
|
+
user: IMParticleUser,
|
|
397
|
+
identityMethod: string
|
|
398
|
+
): void {
|
|
399
|
+
const kitMethodName = identityCompleteKitMethods[identityMethod];
|
|
400
|
+
|
|
401
|
+
if (!kitMethodName) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
349
404
|
|
|
350
405
|
mpInstance._Store.activeForwarders.forEach(function(forwarder) {
|
|
351
|
-
|
|
406
|
+
const onIdentityComplete = forwarder[kitMethodName];
|
|
407
|
+
|
|
408
|
+
if (!onIdentityComplete) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const filteredUser = filteredMparticleUser(
|
|
352
413
|
user.getMPID(),
|
|
353
414
|
forwarder,
|
|
354
415
|
mpInstance,
|
|
355
416
|
kitBlocker
|
|
356
417
|
);
|
|
357
418
|
|
|
358
|
-
const
|
|
419
|
+
const result = onIdentityComplete.call(
|
|
420
|
+
forwarder,
|
|
421
|
+
filteredUser,
|
|
422
|
+
filteredUser.getUserIdentities()
|
|
423
|
+
);
|
|
359
424
|
|
|
360
|
-
if (
|
|
361
|
-
|
|
362
|
-
result = forwarder.onIdentifyComplete(
|
|
363
|
-
filteredUser,
|
|
364
|
-
filteredUserIdentities
|
|
365
|
-
);
|
|
366
|
-
if (result) {
|
|
367
|
-
mpInstance.Logger.verbose(result);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
} else if (identityMethod === Login) {
|
|
371
|
-
if (forwarder.onLoginComplete) {
|
|
372
|
-
result = forwarder.onLoginComplete(
|
|
373
|
-
filteredUser,
|
|
374
|
-
filteredUserIdentities
|
|
375
|
-
);
|
|
376
|
-
if (result) {
|
|
377
|
-
mpInstance.Logger.verbose(result);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
} else if (identityMethod === Logout) {
|
|
381
|
-
if (forwarder.onLogoutComplete) {
|
|
382
|
-
result = forwarder.onLogoutComplete(
|
|
383
|
-
filteredUser,
|
|
384
|
-
filteredUserIdentities
|
|
385
|
-
);
|
|
386
|
-
if (result) {
|
|
387
|
-
mpInstance.Logger.verbose(result);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
} else if (identityMethod === Modify) {
|
|
391
|
-
if (forwarder.onModifyComplete) {
|
|
392
|
-
result = forwarder.onModifyComplete(
|
|
393
|
-
filteredUser,
|
|
394
|
-
filteredUserIdentities
|
|
395
|
-
);
|
|
396
|
-
if (result) {
|
|
397
|
-
mpInstance.Logger.verbose(result);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
425
|
+
if (result) {
|
|
426
|
+
mpInstance.Logger.verbose(result);
|
|
400
427
|
}
|
|
401
428
|
});
|
|
402
429
|
};
|
|
403
430
|
|
|
404
|
-
this.getForwarderStatsQueue = function() {
|
|
431
|
+
this.getForwarderStatsQueue = function(): IForwardingStatsData[] {
|
|
405
432
|
return mpInstance._Persistence.forwardingStatsBatches
|
|
406
433
|
.forwardingStatsEventQueue;
|
|
407
434
|
};
|
|
408
435
|
|
|
409
|
-
this.setForwarderStatsQueue = function(queue) {
|
|
436
|
+
this.setForwarderStatsQueue = function(queue: IForwardingStatsData[]): void {
|
|
410
437
|
mpInstance._Persistence.forwardingStatsBatches.forwardingStatsEventQueue = queue;
|
|
411
438
|
};
|
|
412
439
|
|
|
@@ -416,7 +443,10 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
416
443
|
// There are 2 types of kits:
|
|
417
444
|
// 1. UI-enabled kits
|
|
418
445
|
// 2. Sideloaded kits.
|
|
419
|
-
this.processForwarders = function(
|
|
446
|
+
this.processForwarders = function(
|
|
447
|
+
config: SDKInitConfig,
|
|
448
|
+
forwardingStatsCallback: forwardingStatsCallback
|
|
449
|
+
): void {
|
|
420
450
|
if (!config) {
|
|
421
451
|
mpInstance.Logger.warning(
|
|
422
452
|
'No config was passed. Cannot process forwarders'
|
|
@@ -438,7 +468,7 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
438
468
|
// The kit configuration will be compared with the kit constructors to determine
|
|
439
469
|
// if there is a match before being initialized.
|
|
440
470
|
// Only kits that are configured properly can be active and used for kit forwarding.
|
|
441
|
-
this.processUIEnabledKits = function(config) {
|
|
471
|
+
this.processUIEnabledKits = function(config: SDKInitConfig): void {
|
|
442
472
|
let kits = this.returnKitConstructors();
|
|
443
473
|
|
|
444
474
|
try {
|
|
@@ -455,7 +485,7 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
455
485
|
}
|
|
456
486
|
};
|
|
457
487
|
|
|
458
|
-
this.returnKitConstructors = function() {
|
|
488
|
+
this.returnKitConstructors = function(): Dictionary<RegisteredKit> {
|
|
459
489
|
let kits = {};
|
|
460
490
|
// If there are kits inside of mpInstance._Store.SDKConfig.kits, then mParticle is self hosted
|
|
461
491
|
if (!isEmpty(mpInstance._Store.SDKConfig.kits)) {
|
|
@@ -483,7 +513,10 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
483
513
|
return kits;
|
|
484
514
|
};
|
|
485
515
|
|
|
486
|
-
this.configureUIEnabledKit = function(
|
|
516
|
+
this.configureUIEnabledKit = function(
|
|
517
|
+
configuration: IKitConfigs,
|
|
518
|
+
kits: Dictionary<RegisteredKit>
|
|
519
|
+
): void {
|
|
487
520
|
let newKit = null;
|
|
488
521
|
const config = configuration;
|
|
489
522
|
|
|
@@ -518,7 +551,7 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
518
551
|
// In the future, when all kits are moved to the mpConfig rather than
|
|
519
552
|
// there being a separate process for MP configured kits and
|
|
520
553
|
// sideloaded kits, this will need to be refactored.
|
|
521
|
-
this.processSideloadedKits = function(mpConfig) {
|
|
554
|
+
this.processSideloadedKits = function(mpConfig: SDKInitConfig): void {
|
|
522
555
|
try {
|
|
523
556
|
if (Array.isArray(mpConfig.sideloadedKits)) {
|
|
524
557
|
const registeredSideloadedKits = { kits: {} };
|
|
@@ -566,13 +599,16 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
566
599
|
};
|
|
567
600
|
|
|
568
601
|
// kits can be included via mParticle UI, or via sideloaded kit config API
|
|
569
|
-
this.configureSideloadedKit = function(kitConstructor) {
|
|
602
|
+
this.configureSideloadedKit = function(kitConstructor: RegisteredKit): void {
|
|
570
603
|
mpInstance._Store.configuredForwarders.push(
|
|
571
604
|
this.returnConfiguredKit(kitConstructor, kitConstructor.filters)
|
|
572
605
|
);
|
|
573
606
|
};
|
|
574
607
|
|
|
575
|
-
this.returnConfiguredKit = function(
|
|
608
|
+
this.returnConfiguredKit = function(
|
|
609
|
+
forwarder: RegisteredKit,
|
|
610
|
+
config: Partial<IKitConfigs> = {}
|
|
611
|
+
): ConfiguredKit {
|
|
576
612
|
const newForwarder = new forwarder.constructor();
|
|
577
613
|
newForwarder.id = config.moduleId;
|
|
578
614
|
|
|
@@ -608,7 +644,7 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
608
644
|
return newForwarder;
|
|
609
645
|
};
|
|
610
646
|
|
|
611
|
-
this.configurePixel = function(settings) {
|
|
647
|
+
this.configurePixel = function(settings: IPixelConfiguration): void {
|
|
612
648
|
if (
|
|
613
649
|
settings.isDebug ===
|
|
614
650
|
mpInstance._Store.SDKConfig.isDevelopmentMode ||
|
|
@@ -619,7 +655,7 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
619
655
|
}
|
|
620
656
|
};
|
|
621
657
|
|
|
622
|
-
this.processPixelConfigs = function(config) {
|
|
658
|
+
this.processPixelConfigs = function(config: SDKInitConfig): void {
|
|
623
659
|
try {
|
|
624
660
|
if (!isEmpty(config.pixelConfigs)) {
|
|
625
661
|
config.pixelConfigs.forEach(function(pixelConfig) {
|
|
@@ -634,7 +670,9 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
634
670
|
}
|
|
635
671
|
};
|
|
636
672
|
|
|
637
|
-
this.sendSingleForwardingStatsToServer = async
|
|
673
|
+
this.sendSingleForwardingStatsToServer = async (
|
|
674
|
+
forwardingStatsData: IForwardingStatsData
|
|
675
|
+
): Promise<void> => {
|
|
638
676
|
// https://go.mparticle.com/work/SQDSDKS-6568
|
|
639
677
|
const fetchPayload = {
|
|
640
678
|
method: 'post',
|
package/src/helpers.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { IMParticleWebSDKInstance } from './mp-instance';
|
|
|
8
8
|
import { SDKHelpersApi } from './sdkRuntimeModels';
|
|
9
9
|
import { IMParticleUser, IdentityCallback, IdentityResult, ISDKUserIdentity } from './identity-user-interfaces';
|
|
10
10
|
import { IAliasResult } from './identity.interfaces';
|
|
11
|
-
import { AliasUsersCallback, MPID } from '@mparticle/web-sdk';
|
|
11
|
+
import { AliasUsersCallback, MPID, UserIdentities } from '@mparticle/web-sdk';
|
|
12
12
|
|
|
13
13
|
const StorageNames = Constants.StorageNames;
|
|
14
14
|
|
|
@@ -25,7 +25,11 @@ function appendFilteredUserIdentity(
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function buildFilteredUserIdentities(
|
|
28
|
-
userIdentitiesObject:
|
|
28
|
+
userIdentitiesObject:
|
|
29
|
+
| UserIdentities
|
|
30
|
+
| utils.Dictionary<string>
|
|
31
|
+
| null
|
|
32
|
+
| undefined,
|
|
29
33
|
filterList: number[],
|
|
30
34
|
inArray: (items: any[], value: any) => boolean
|
|
31
35
|
): ISDKUserIdentity[] {
|
|
@@ -211,7 +215,7 @@ export default function Helpers(
|
|
|
211
215
|
};
|
|
212
216
|
|
|
213
217
|
this.filterUserIdentities = function(
|
|
214
|
-
userIdentitiesObject: Dictionary<string>,
|
|
218
|
+
userIdentitiesObject: UserIdentities | Dictionary<string>,
|
|
215
219
|
filterList: number[]
|
|
216
220
|
): ISDKUserIdentity[] {
|
|
217
221
|
return buildFilteredUserIdentities(
|
package/src/identity-utils.ts
CHANGED
|
@@ -5,10 +5,10 @@ import Types from './types';
|
|
|
5
5
|
import {
|
|
6
6
|
IdentityApiData,
|
|
7
7
|
UserIdentities,
|
|
8
|
-
IdentityCallback,
|
|
9
8
|
} from '@mparticle/web-sdk';
|
|
10
9
|
import { IdentityAPIMethod, IIdentityRequest } from './identity.interfaces';
|
|
11
10
|
import {
|
|
11
|
+
IdentityCallback,
|
|
12
12
|
IdentityResultBody,
|
|
13
13
|
IIdentityResponse,
|
|
14
14
|
IMParticleUser,
|
|
@@ -33,7 +33,7 @@ export type IParseCachedIdentityResponse = (
|
|
|
33
33
|
mpid: string,
|
|
34
34
|
callback: IdentityCallback,
|
|
35
35
|
identityApiData: IdentityApiData,
|
|
36
|
-
identityMethod:
|
|
36
|
+
identityMethod: IdentityAPIMethod,
|
|
37
37
|
knownIdentities: IKnownIdentities,
|
|
38
38
|
fromCachedIdentity: boolean
|
|
39
39
|
) => void;
|