@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
|
@@ -4,10 +4,11 @@ import {
|
|
|
4
4
|
cacheOrClearIdCache,
|
|
5
5
|
createKnownIdentities,
|
|
6
6
|
executeSearchRequest,
|
|
7
|
+
IKnownIdentities,
|
|
7
8
|
normalizeUserIdentityKeys,
|
|
8
9
|
tryCacheIdentity,
|
|
9
10
|
} from './identity-utils';
|
|
10
|
-
import AudienceManager from './audienceManager';
|
|
11
|
+
import AudienceManager, { IAudienceMemberships } from './audienceManager';
|
|
11
12
|
const { Messages, HTTPCodes, FeatureFlags, IdentityMethods } = Constants;
|
|
12
13
|
const { ErrorMessages } = Messages;
|
|
13
14
|
const { CacheIdentity } = FeatureFlags;
|
|
@@ -21,17 +22,44 @@ import {
|
|
|
21
22
|
import { hasMPIDAndUserLoginChanged, hasMPIDChanged } from './user-utils';
|
|
22
23
|
import { processReadyQueue } from './pre-init-utils';
|
|
23
24
|
import { logDeprecatedMethodUsage } from './reporting/deprecatedMethodLogger';
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
import { IErrorReportingService } from './reporting/types';
|
|
26
|
+
import {
|
|
27
|
+
IdentityCallback,
|
|
28
|
+
IIdentityResponse,
|
|
29
|
+
IMParticleUser,
|
|
30
|
+
mParticleUserCart,
|
|
31
|
+
} from './identity-user-interfaces';
|
|
32
|
+
import {
|
|
33
|
+
IIdentity,
|
|
34
|
+
IIdentityAPIRequestData,
|
|
35
|
+
IdentityAPIMethod,
|
|
36
|
+
IAliasRequest,
|
|
37
|
+
IAliasCallback,
|
|
38
|
+
IAliasNetworkRequest,
|
|
39
|
+
IAliasNativeRequest,
|
|
40
|
+
IIdentityNativeRequest,
|
|
41
|
+
AliasRequestScope,
|
|
42
|
+
SDKIdentityTypeEnum,
|
|
43
|
+
UserAttributeChangeValue,
|
|
44
|
+
} from './identity.interfaces';
|
|
45
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
46
|
+
import { IdentityApiData, UserIdentities, MPID, ConsentState, UserAttributesValue } from '@mparticle/web-sdk';
|
|
47
|
+
import { BaseEvent, SDKEvent, SDKLoggerApi } from './sdkRuntimeModels';
|
|
48
|
+
import { IdentitySearchCallback } from './identity/search';
|
|
49
|
+
|
|
50
|
+
export default function Identity(
|
|
51
|
+
this: IIdentity,
|
|
52
|
+
mpInstance: IMParticleWebSDKInstance
|
|
53
|
+
) {
|
|
26
54
|
const { getFeatureFlag, extend } = mpInstance._Helpers;
|
|
27
55
|
|
|
28
|
-
|
|
56
|
+
const self: IIdentity = this;
|
|
29
57
|
this.idCache = null;
|
|
30
58
|
this.audienceManager = null;
|
|
31
59
|
|
|
32
60
|
// https://go.mparticle.com/work/SQDSDKS-6353
|
|
33
61
|
this.IdentityRequest = {
|
|
34
|
-
preProcessIdentityRequest: function(identityApiData, callback, method) {
|
|
62
|
+
preProcessIdentityRequest: function(identityApiData: IdentityApiData, callback: IdentityCallback, method: IdentityAPIMethod) {
|
|
35
63
|
mpInstance.Logger.verbose(
|
|
36
64
|
Messages.InformationMessages.StartingLogEvent + ': ' + method
|
|
37
65
|
);
|
|
@@ -52,7 +80,7 @@ export default function Identity(mpInstance) {
|
|
|
52
80
|
}
|
|
53
81
|
: removedFalsyIdentityData;
|
|
54
82
|
|
|
55
|
-
|
|
83
|
+
const identityValidationResult = mpInstance._Helpers.Validators.validateIdentities(
|
|
56
84
|
cleanedIdentityApiData,
|
|
57
85
|
method
|
|
58
86
|
);
|
|
@@ -71,7 +99,7 @@ export default function Identity(mpInstance) {
|
|
|
71
99
|
callback &&
|
|
72
100
|
!mpInstance._Helpers.Validators.isFunction(callback)
|
|
73
101
|
) {
|
|
74
|
-
|
|
102
|
+
const error =
|
|
75
103
|
'The optional callback must be a function. You tried entering a(n) ' +
|
|
76
104
|
typeof callback;
|
|
77
105
|
mpInstance.Logger.error(error);
|
|
@@ -88,24 +116,24 @@ export default function Identity(mpInstance) {
|
|
|
88
116
|
},
|
|
89
117
|
|
|
90
118
|
createIdentityRequest: function(
|
|
91
|
-
identityApiData,
|
|
92
|
-
platform,
|
|
93
|
-
sdkVendor,
|
|
94
|
-
sdkVersion,
|
|
95
|
-
deviceId,
|
|
96
|
-
context,
|
|
97
|
-
mpid
|
|
119
|
+
identityApiData: IdentityApiData,
|
|
120
|
+
platform: string,
|
|
121
|
+
sdkVendor: string,
|
|
122
|
+
sdkVersion: string,
|
|
123
|
+
deviceId: string,
|
|
124
|
+
context: string | null,
|
|
125
|
+
mpid: MPID
|
|
98
126
|
) {
|
|
99
|
-
|
|
127
|
+
const APIRequest: IIdentityAPIRequestData = {
|
|
100
128
|
client_sdk: {
|
|
101
129
|
platform: platform,
|
|
102
130
|
sdk_vendor: sdkVendor,
|
|
103
131
|
sdk_version: sdkVersion,
|
|
104
132
|
},
|
|
105
133
|
context: context,
|
|
106
|
-
environment: mpInstance._Store.SDKConfig.isDevelopmentMode
|
|
134
|
+
environment: (mpInstance._Store.SDKConfig.isDevelopmentMode
|
|
107
135
|
? 'development'
|
|
108
|
-
: 'production',
|
|
136
|
+
: 'production'),
|
|
109
137
|
request_id: mpInstance._Helpers.generateUniqueId(),
|
|
110
138
|
request_timestamp_ms: new Date().getTime(),
|
|
111
139
|
previous_mpid: mpid || null,
|
|
@@ -119,12 +147,12 @@ export default function Identity(mpInstance) {
|
|
|
119
147
|
},
|
|
120
148
|
|
|
121
149
|
createModifyIdentityRequest: function(
|
|
122
|
-
currentUserIdentities,
|
|
123
|
-
newUserIdentities,
|
|
124
|
-
platform,
|
|
125
|
-
sdkVendor,
|
|
126
|
-
sdkVersion,
|
|
127
|
-
context
|
|
150
|
+
currentUserIdentities: UserIdentities,
|
|
151
|
+
newUserIdentities: UserIdentities,
|
|
152
|
+
platform: string,
|
|
153
|
+
sdkVendor: string,
|
|
154
|
+
sdkVersion: string,
|
|
155
|
+
context: string | null
|
|
128
156
|
) {
|
|
129
157
|
return {
|
|
130
158
|
client_sdk: {
|
|
@@ -133,9 +161,9 @@ export default function Identity(mpInstance) {
|
|
|
133
161
|
sdk_version: sdkVersion,
|
|
134
162
|
},
|
|
135
163
|
context: context,
|
|
136
|
-
environment: mpInstance._Store.SDKConfig.isDevelopmentMode
|
|
164
|
+
environment: (mpInstance._Store.SDKConfig.isDevelopmentMode
|
|
137
165
|
? 'development'
|
|
138
|
-
: 'production',
|
|
166
|
+
: 'production'),
|
|
139
167
|
request_id: mpInstance._Helpers.generateUniqueId(),
|
|
140
168
|
request_timestamp_ms: new Date().getTime(),
|
|
141
169
|
identity_changes: this.createIdentityChanges(
|
|
@@ -145,16 +173,15 @@ export default function Identity(mpInstance) {
|
|
|
145
173
|
};
|
|
146
174
|
},
|
|
147
175
|
|
|
148
|
-
createIdentityChanges: function(previousIdentities, newIdentities) {
|
|
149
|
-
|
|
150
|
-
var key;
|
|
176
|
+
createIdentityChanges: function(previousIdentities: UserIdentities, newIdentities: UserIdentities) {
|
|
177
|
+
const identityChanges = [];
|
|
151
178
|
if (
|
|
152
179
|
newIdentities &&
|
|
153
180
|
isObject(newIdentities) &&
|
|
154
181
|
previousIdentities &&
|
|
155
182
|
isObject(previousIdentities)
|
|
156
183
|
) {
|
|
157
|
-
for (key in newIdentities) {
|
|
184
|
+
for (const key in newIdentities) {
|
|
158
185
|
identityChanges.push({
|
|
159
186
|
old_value: previousIdentities[key] || null,
|
|
160
187
|
new_value: newIdentities[key],
|
|
@@ -167,12 +194,12 @@ export default function Identity(mpInstance) {
|
|
|
167
194
|
},
|
|
168
195
|
|
|
169
196
|
// takes 2 UI objects keyed by name, combines them, returns them keyed by type
|
|
170
|
-
combineUserIdentities: function(previousUIByName, newUIByName) {
|
|
171
|
-
|
|
172
|
-
|
|
197
|
+
combineUserIdentities: function(previousUIByName: UserIdentities, newUIByName: UserIdentities) {
|
|
198
|
+
const combinedUIByType = {};
|
|
199
|
+
const combinedUIByName = extend({}, previousUIByName, newUIByName);
|
|
173
200
|
|
|
174
|
-
for (
|
|
175
|
-
|
|
201
|
+
for (const key in combinedUIByName) {
|
|
202
|
+
const type = Types.IdentityType.getIdentityType(key);
|
|
176
203
|
// this check removes anything that is not whitelisted as an identity type
|
|
177
204
|
if (type !== false && type >= 0) {
|
|
178
205
|
combinedUIByType[Types.IdentityType.getIdentityType(key)] =
|
|
@@ -183,7 +210,7 @@ export default function Identity(mpInstance) {
|
|
|
183
210
|
return combinedUIByType;
|
|
184
211
|
},
|
|
185
212
|
|
|
186
|
-
createAliasNetworkRequest: function(aliasRequest) {
|
|
213
|
+
createAliasNetworkRequest: function(aliasRequest: IAliasRequest): IAliasNetworkRequest {
|
|
187
214
|
return {
|
|
188
215
|
request_id: mpInstance._Helpers.generateUniqueId(),
|
|
189
216
|
request_type: 'alias',
|
|
@@ -202,7 +229,7 @@ export default function Identity(mpInstance) {
|
|
|
202
229
|
};
|
|
203
230
|
},
|
|
204
231
|
|
|
205
|
-
convertAliasToNative: function(aliasRequest) {
|
|
232
|
+
convertAliasToNative: function(aliasRequest: IAliasRequest): IAliasNativeRequest {
|
|
206
233
|
return {
|
|
207
234
|
DestinationMpid: aliasRequest.destinationMpid,
|
|
208
235
|
SourceMpid: aliasRequest.sourceMpid,
|
|
@@ -212,10 +239,10 @@ export default function Identity(mpInstance) {
|
|
|
212
239
|
};
|
|
213
240
|
},
|
|
214
241
|
|
|
215
|
-
convertToNative: function(identityApiData) {
|
|
216
|
-
|
|
217
|
-
if (identityApiData
|
|
218
|
-
for (
|
|
242
|
+
convertToNative: function(identityApiData: IdentityApiData): IIdentityNativeRequest | undefined {
|
|
243
|
+
const nativeIdentityRequest = [];
|
|
244
|
+
if (identityApiData?.userIdentities) {
|
|
245
|
+
for (const key in identityApiData.userIdentities) {
|
|
219
246
|
if (identityApiData.userIdentities.hasOwnProperty(key)) {
|
|
220
247
|
nativeIdentityRequest.push({
|
|
221
248
|
Type: Types.IdentityType.getIdentityType(key),
|
|
@@ -228,6 +255,7 @@ export default function Identity(mpInstance) {
|
|
|
228
255
|
UserIdentities: nativeIdentityRequest,
|
|
229
256
|
};
|
|
230
257
|
}
|
|
258
|
+
return undefined;
|
|
231
259
|
},
|
|
232
260
|
};
|
|
233
261
|
/**
|
|
@@ -243,21 +271,21 @@ export default function Identity(mpInstance) {
|
|
|
243
271
|
* @param {Object} identityApiData The identityApiData object as indicated [here](https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/README.md#1-customize-the-sdk)
|
|
244
272
|
* @param {Function} [callback] A callback function that is called when the identify request completes
|
|
245
273
|
*/
|
|
246
|
-
identify: function(identityApiData, callback) {
|
|
274
|
+
identify: function(identityApiData: IdentityApiData, callback: IdentityCallback) {
|
|
247
275
|
// https://go.mparticle.com/work/SQDSDKS-6337
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
276
|
+
let mpid;
|
|
277
|
+
const currentUser = mpInstance.Identity.getCurrentUser();
|
|
278
|
+
const preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
|
|
279
|
+
identityApiData,
|
|
280
|
+
callback,
|
|
281
|
+
Identify
|
|
282
|
+
);
|
|
255
283
|
if (currentUser) {
|
|
256
284
|
mpid = currentUser.getMPID();
|
|
257
285
|
}
|
|
258
286
|
|
|
259
287
|
if (preProcessResult.valid) {
|
|
260
|
-
|
|
288
|
+
const identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
261
289
|
preProcessResult.cleanedIdentities,
|
|
262
290
|
Constants.platform,
|
|
263
291
|
Constants.sdkVendor,
|
|
@@ -328,7 +356,9 @@ export default function Identity(mpInstance) {
|
|
|
328
356
|
HTTPCodes.validationIssue,
|
|
329
357
|
preProcessResult.error
|
|
330
358
|
);
|
|
331
|
-
mpInstance.Logger.verbose(
|
|
359
|
+
mpInstance.Logger.verbose(
|
|
360
|
+
preProcessResult as unknown as string
|
|
361
|
+
);
|
|
332
362
|
}
|
|
333
363
|
},
|
|
334
364
|
/**
|
|
@@ -337,22 +367,22 @@ export default function Identity(mpInstance) {
|
|
|
337
367
|
* @param {Object} identityApiData The identityApiData object as indicated [here](https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/README.md#1-customize-the-sdk)
|
|
338
368
|
* @param {Function} [callback] A callback function that is called when the logout request completes
|
|
339
369
|
*/
|
|
340
|
-
logout: function(identityApiData, callback) {
|
|
370
|
+
logout: function(identityApiData: IdentityApiData, callback: IdentityCallback) {
|
|
341
371
|
// https://go.mparticle.com/work/SQDSDKS-6337
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
372
|
+
let mpid;
|
|
373
|
+
const currentUser = mpInstance.Identity.getCurrentUser();
|
|
374
|
+
const preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
|
|
375
|
+
identityApiData,
|
|
376
|
+
callback,
|
|
377
|
+
Logout
|
|
378
|
+
);
|
|
349
379
|
if (currentUser) {
|
|
350
380
|
mpid = currentUser.getMPID();
|
|
351
381
|
}
|
|
352
382
|
|
|
353
383
|
if (preProcessResult.valid) {
|
|
354
|
-
|
|
355
|
-
|
|
384
|
+
let evt;
|
|
385
|
+
const identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
356
386
|
preProcessResult.cleanedIdentities,
|
|
357
387
|
Constants.platform,
|
|
358
388
|
Constants.sdkVendor,
|
|
@@ -396,8 +426,11 @@ export default function Identity(mpInstance) {
|
|
|
396
426
|
mpInstance._Store.activeForwarders.forEach(function(
|
|
397
427
|
forwarder
|
|
398
428
|
) {
|
|
399
|
-
|
|
400
|
-
|
|
429
|
+
const kit = forwarder as {
|
|
430
|
+
logOut?: (event: SDKEvent) => void;
|
|
431
|
+
};
|
|
432
|
+
if (kit.logOut) {
|
|
433
|
+
kit.logOut(evt);
|
|
401
434
|
}
|
|
402
435
|
});
|
|
403
436
|
}
|
|
@@ -418,7 +451,9 @@ export default function Identity(mpInstance) {
|
|
|
418
451
|
HTTPCodes.validationIssue,
|
|
419
452
|
preProcessResult.error
|
|
420
453
|
);
|
|
421
|
-
mpInstance.Logger.verbose(
|
|
454
|
+
mpInstance.Logger.verbose(
|
|
455
|
+
preProcessResult as unknown as string
|
|
456
|
+
);
|
|
422
457
|
}
|
|
423
458
|
},
|
|
424
459
|
/**
|
|
@@ -427,22 +462,22 @@ export default function Identity(mpInstance) {
|
|
|
427
462
|
* @param {Object} identityApiData The identityApiData object as indicated [here](https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/README.md#1-customize-the-sdk)
|
|
428
463
|
* @param {Function} [callback] A callback function that is called when the login request completes
|
|
429
464
|
*/
|
|
430
|
-
login: function(identityApiData, callback) {
|
|
465
|
+
login: function(identityApiData: IdentityApiData, callback: IdentityCallback) {
|
|
431
466
|
// https://go.mparticle.com/work/SQDSDKS-6337
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
467
|
+
let mpid;
|
|
468
|
+
const currentUser = mpInstance.Identity.getCurrentUser();
|
|
469
|
+
const preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
|
|
470
|
+
identityApiData,
|
|
471
|
+
callback,
|
|
472
|
+
Login
|
|
473
|
+
);
|
|
439
474
|
|
|
440
475
|
if (currentUser) {
|
|
441
476
|
mpid = currentUser.getMPID();
|
|
442
477
|
}
|
|
443
478
|
|
|
444
479
|
if (preProcessResult.valid) {
|
|
445
|
-
|
|
480
|
+
const identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
446
481
|
preProcessResult.cleanedIdentities,
|
|
447
482
|
Constants.platform,
|
|
448
483
|
Constants.sdkVendor,
|
|
@@ -514,7 +549,9 @@ export default function Identity(mpInstance) {
|
|
|
514
549
|
HTTPCodes.validationIssue,
|
|
515
550
|
preProcessResult.error
|
|
516
551
|
);
|
|
517
|
-
mpInstance.Logger.verbose(
|
|
552
|
+
mpInstance.Logger.verbose(
|
|
553
|
+
preProcessResult as unknown as string
|
|
554
|
+
);
|
|
518
555
|
}
|
|
519
556
|
},
|
|
520
557
|
/**
|
|
@@ -523,24 +560,23 @@ export default function Identity(mpInstance) {
|
|
|
523
560
|
* @param {Object} identityApiData The identityApiData object as indicated [here](https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/README.md#1-customize-the-sdk)
|
|
524
561
|
* @param {Function} [callback] A callback function that is called when the modify request completes
|
|
525
562
|
*/
|
|
526
|
-
modify: function(identityApiData, callback) {
|
|
563
|
+
modify: function(identityApiData: IdentityApiData, callback: IdentityCallback) {
|
|
527
564
|
// https://go.mparticle.com/work/SQDSDKS-6337
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
565
|
+
let mpid;
|
|
566
|
+
const currentUser = mpInstance.Identity.getCurrentUser();
|
|
567
|
+
const preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
|
|
568
|
+
identityApiData,
|
|
569
|
+
callback,
|
|
570
|
+
Modify
|
|
571
|
+
);
|
|
535
572
|
if (currentUser) {
|
|
536
573
|
mpid = currentUser.getMPID();
|
|
537
574
|
}
|
|
538
575
|
if (preProcessResult.valid) {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
var identityApiRequest = mpInstance._Identity.IdentityRequest.createModifyIdentityRequest(
|
|
576
|
+
const newUserIdentities = identityApiData?.userIdentities
|
|
577
|
+
? preProcessResult.cleanedIdentities.userIdentities
|
|
578
|
+
: {};
|
|
579
|
+
const identityApiRequest = mpInstance._Identity.IdentityRequest.createModifyIdentityRequest(
|
|
544
580
|
currentUser
|
|
545
581
|
? currentUser.getUserIdentities().userIdentities
|
|
546
582
|
: {},
|
|
@@ -573,8 +609,7 @@ export default function Identity(mpInstance) {
|
|
|
573
609
|
callback,
|
|
574
610
|
identityApiData,
|
|
575
611
|
self.parseIdentityResponse,
|
|
576
|
-
mpid
|
|
577
|
-
identityApiRequest.known_identities
|
|
612
|
+
mpid
|
|
578
613
|
);
|
|
579
614
|
}
|
|
580
615
|
} else {
|
|
@@ -593,7 +628,9 @@ export default function Identity(mpInstance) {
|
|
|
593
628
|
HTTPCodes.validationIssue,
|
|
594
629
|
preProcessResult.error
|
|
595
630
|
);
|
|
596
|
-
mpInstance.Logger.verbose(
|
|
631
|
+
mpInstance.Logger.verbose(
|
|
632
|
+
preProcessResult as unknown as string
|
|
633
|
+
);
|
|
597
634
|
}
|
|
598
635
|
},
|
|
599
636
|
/**
|
|
@@ -602,7 +639,7 @@ export default function Identity(mpInstance) {
|
|
|
602
639
|
* @return {Object} the current user object
|
|
603
640
|
*/
|
|
604
641
|
getCurrentUser: function() {
|
|
605
|
-
|
|
642
|
+
let mpid;
|
|
606
643
|
if (mpInstance._Store) {
|
|
607
644
|
mpid = mpInstance._Store.mpid;
|
|
608
645
|
if (mpid) {
|
|
@@ -628,8 +665,8 @@ export default function Identity(mpInstance) {
|
|
|
628
665
|
* @param {String} mpid of the desired user
|
|
629
666
|
* @return {Object} the user for mpid
|
|
630
667
|
*/
|
|
631
|
-
getUser: function(mpid) {
|
|
632
|
-
|
|
668
|
+
getUser: function(mpid: MPID) {
|
|
669
|
+
const persistence = mpInstance._Persistence.getPersistence();
|
|
633
670
|
if (persistence) {
|
|
634
671
|
if (
|
|
635
672
|
persistence[mpid] &&
|
|
@@ -650,18 +687,18 @@ export default function Identity(mpInstance) {
|
|
|
650
687
|
* @return {Array} array of users
|
|
651
688
|
*/
|
|
652
689
|
getUsers: function() {
|
|
653
|
-
|
|
654
|
-
|
|
690
|
+
const persistence = mpInstance._Persistence.getPersistence();
|
|
691
|
+
const users = [];
|
|
655
692
|
if (persistence) {
|
|
656
|
-
for (
|
|
693
|
+
for (const key in persistence) {
|
|
657
694
|
if (!Constants.SDKv2NonMPIDCookieKeys.hasOwnProperty(key)) {
|
|
658
695
|
users.push(self.mParticleUser(key));
|
|
659
696
|
}
|
|
660
697
|
}
|
|
661
698
|
}
|
|
662
699
|
users.sort(function(a, b) {
|
|
663
|
-
|
|
664
|
-
|
|
700
|
+
const aLastSeen = a.getLastSeenTime() || 0;
|
|
701
|
+
const bLastSeen = b.getLastSeenTime() || 0;
|
|
665
702
|
if (aLastSeen > bLastSeen) {
|
|
666
703
|
return -1;
|
|
667
704
|
} else {
|
|
@@ -677,8 +714,8 @@ export default function Identity(mpInstance) {
|
|
|
677
714
|
* @param {Object} aliasRequest object representing an AliasRequest
|
|
678
715
|
* @param {Function} [callback] A callback function that is called when the aliasUsers request completes
|
|
679
716
|
*/
|
|
680
|
-
aliasUsers: function(aliasRequest, callback) {
|
|
681
|
-
|
|
717
|
+
aliasUsers: function(aliasRequest: IAliasRequest, callback: IAliasCallback) {
|
|
718
|
+
let message;
|
|
682
719
|
if (!aliasRequest.destinationMpid || !aliasRequest.sourceMpid) {
|
|
683
720
|
message = Messages.ValidationMessages.AliasMissingMpid;
|
|
684
721
|
}
|
|
@@ -723,7 +760,7 @@ export default function Identity(mpInstance) {
|
|
|
723
760
|
' -> ' +
|
|
724
761
|
aliasRequest.destinationMpid
|
|
725
762
|
);
|
|
726
|
-
|
|
763
|
+
const aliasRequestMessage = mpInstance._Identity.IdentityRequest.createAliasNetworkRequest(
|
|
727
764
|
aliasRequest
|
|
728
765
|
);
|
|
729
766
|
mpInstance._IdentityAPIClient.sendAliasRequest(
|
|
@@ -760,7 +797,7 @@ export default function Identity(mpInstance) {
|
|
|
760
797
|
* @param {Object} knownIdentities A `UserIdentities` map.
|
|
761
798
|
* @param {Function} callback Invoked with the `IIdentitySearchResult`.
|
|
762
799
|
*/
|
|
763
|
-
search: function(workspaceApiKey, knownIdentities, callback) {
|
|
800
|
+
search: function(workspaceApiKey: string, knownIdentities: UserIdentities, callback: IdentitySearchCallback) {
|
|
764
801
|
executeSearchRequest(
|
|
765
802
|
mpInstance,
|
|
766
803
|
workspaceApiKey,
|
|
@@ -784,7 +821,7 @@ export default function Identity(mpInstance) {
|
|
|
784
821
|
after applying this adjustment it will be impossible to create an aliasRequest passes the aliasUsers()
|
|
785
822
|
validation that the startTime must be less than the endTime
|
|
786
823
|
*/
|
|
787
|
-
createAliasRequest: function(sourceUser, destinationUser, scope) {
|
|
824
|
+
createAliasRequest: function(sourceUser: IMParticleUser, destinationUser: IMParticleUser, scope: AliasRequestScope) {
|
|
788
825
|
try {
|
|
789
826
|
if (!destinationUser || !sourceUser) {
|
|
790
827
|
mpInstance.Logger.error(
|
|
@@ -792,7 +829,7 @@ export default function Identity(mpInstance) {
|
|
|
792
829
|
);
|
|
793
830
|
return null;
|
|
794
831
|
}
|
|
795
|
-
|
|
832
|
+
let startTime = sourceUser.getFirstSeenTime();
|
|
796
833
|
if (!startTime) {
|
|
797
834
|
mpInstance.Identity.getUsers().forEach(function(user) {
|
|
798
835
|
if (
|
|
@@ -803,14 +840,14 @@ export default function Identity(mpInstance) {
|
|
|
803
840
|
}
|
|
804
841
|
});
|
|
805
842
|
}
|
|
806
|
-
|
|
843
|
+
const minFirstSeenTimeMs =
|
|
807
844
|
new Date().getTime() -
|
|
808
845
|
mpInstance._Store.SDKConfig.aliasMaxWindow *
|
|
809
846
|
24 *
|
|
810
847
|
60 *
|
|
811
848
|
60 *
|
|
812
849
|
1000;
|
|
813
|
-
|
|
850
|
+
const endTime =
|
|
814
851
|
sourceUser.getLastSeenTime() || new Date().getTime();
|
|
815
852
|
//if the startTime is greater than $maxAliasWindow ago, adjust the startTime to the earliest allowed
|
|
816
853
|
if (startTime < minFirstSeenTimeMs) {
|
|
@@ -845,8 +882,7 @@ export default function Identity(mpInstance) {
|
|
|
845
882
|
* Example: mParticle.Identity.getCurrentUser().getAllUserAttributes()
|
|
846
883
|
* @class mParticle.Identity.getCurrentUser()
|
|
847
884
|
*/
|
|
848
|
-
this.mParticleUser = function(mpid, isLoggedIn) {
|
|
849
|
-
var self = this;
|
|
885
|
+
this.mParticleUser = function(mpid?: MPID, isLoggedIn?: boolean): IMParticleUser {
|
|
850
886
|
return {
|
|
851
887
|
/**
|
|
852
888
|
* Get user identities for current user
|
|
@@ -857,7 +893,7 @@ export default function Identity(mpInstance) {
|
|
|
857
893
|
const currentUserIdentities = {};
|
|
858
894
|
const identities = mpInstance._Store.getUserIdentities(mpid);
|
|
859
895
|
|
|
860
|
-
for (
|
|
896
|
+
for (const identityType in identities) {
|
|
861
897
|
if (identities.hasOwnProperty(identityType)) {
|
|
862
898
|
currentUserIdentities[
|
|
863
899
|
Types.IdentityType.getIdentityName(
|
|
@@ -884,7 +920,7 @@ export default function Identity(mpInstance) {
|
|
|
884
920
|
* @method setUserTag
|
|
885
921
|
* @param {String} tagName
|
|
886
922
|
*/
|
|
887
|
-
setUserTag: function(tagName) {
|
|
923
|
+
setUserTag: function(tagName: string) {
|
|
888
924
|
if (!mpInstance._Helpers.Validators.isValidKeyValue(tagName)) {
|
|
889
925
|
mpInstance.Logger.error(Messages.ErrorMessages.BadKey);
|
|
890
926
|
return;
|
|
@@ -897,7 +933,7 @@ export default function Identity(mpInstance) {
|
|
|
897
933
|
* @method removeUserTag
|
|
898
934
|
* @param {String} tagName
|
|
899
935
|
*/
|
|
900
|
-
removeUserTag: function(tagName) {
|
|
936
|
+
removeUserTag: function(tagName: string) {
|
|
901
937
|
if (!mpInstance._Helpers.Validators.isValidKeyValue(tagName)) {
|
|
902
938
|
mpInstance.Logger.error(Messages.ErrorMessages.BadKey);
|
|
903
939
|
return;
|
|
@@ -913,7 +949,7 @@ export default function Identity(mpInstance) {
|
|
|
913
949
|
*/
|
|
914
950
|
// https://go.mparticle.com/work/SQDSDKS-4576
|
|
915
951
|
// https://go.mparticle.com/work/SQDSDKS-6373
|
|
916
|
-
setUserAttribute: function(key, newValue) {
|
|
952
|
+
setUserAttribute: function(key: string, newValue: string) {
|
|
917
953
|
mpInstance._SessionManager.resetSessionTimer();
|
|
918
954
|
|
|
919
955
|
if (mpInstance._Helpers.canLog()) {
|
|
@@ -989,11 +1025,11 @@ export default function Identity(mpInstance) {
|
|
|
989
1025
|
* @param {Object} user attribute object with keys of the attribute type, and value of the attribute value
|
|
990
1026
|
*/
|
|
991
1027
|
// https://go.mparticle.com/work/SQDSDKS-6373
|
|
992
|
-
setUserAttributes: function(userAttributes) {
|
|
1028
|
+
setUserAttributes: function(userAttributes: Record<string, unknown>) {
|
|
993
1029
|
mpInstance._SessionManager.resetSessionTimer();
|
|
994
1030
|
if (isObject(userAttributes)) {
|
|
995
1031
|
if (mpInstance._Helpers.canLog()) {
|
|
996
|
-
for (
|
|
1032
|
+
for (const key in userAttributes) {
|
|
997
1033
|
if (userAttributes.hasOwnProperty(key)) {
|
|
998
1034
|
this.setUserAttribute(key, userAttributes[key]);
|
|
999
1035
|
}
|
|
@@ -1011,8 +1047,9 @@ export default function Identity(mpInstance) {
|
|
|
1011
1047
|
* @method removeUserAttribute
|
|
1012
1048
|
* @param {String} key
|
|
1013
1049
|
*/
|
|
1014
|
-
removeUserAttribute: function(key) {
|
|
1015
|
-
|
|
1050
|
+
removeUserAttribute: function(key: string) {
|
|
1051
|
+
let cookies;
|
|
1052
|
+
let userAttributes;
|
|
1016
1053
|
mpInstance._SessionManager.resetSessionTimer();
|
|
1017
1054
|
|
|
1018
1055
|
if (!mpInstance._Helpers.Validators.isValidKeyValue(key)) {
|
|
@@ -1030,7 +1067,7 @@ export default function Identity(mpInstance) {
|
|
|
1030
1067
|
|
|
1031
1068
|
userAttributes = this.getAllUserAttributes();
|
|
1032
1069
|
|
|
1033
|
-
|
|
1070
|
+
const existingProp = mpInstance._Helpers.findKeyInObject(
|
|
1034
1071
|
userAttributes,
|
|
1035
1072
|
key
|
|
1036
1073
|
);
|
|
@@ -1039,7 +1076,7 @@ export default function Identity(mpInstance) {
|
|
|
1039
1076
|
key = existingProp;
|
|
1040
1077
|
}
|
|
1041
1078
|
|
|
1042
|
-
|
|
1079
|
+
const deletedUAKeyCopy = userAttributes[key]
|
|
1043
1080
|
? userAttributes[key].toString()
|
|
1044
1081
|
: null;
|
|
1045
1082
|
|
|
@@ -1047,7 +1084,7 @@ export default function Identity(mpInstance) {
|
|
|
1047
1084
|
|
|
1048
1085
|
if (cookies && cookies[mpid]) {
|
|
1049
1086
|
cookies[mpid].ua = userAttributes;
|
|
1050
|
-
mpInstance._Persistence.savePersistence(cookies
|
|
1087
|
+
mpInstance._Persistence.savePersistence(cookies);
|
|
1051
1088
|
}
|
|
1052
1089
|
|
|
1053
1090
|
self.sendUserAttributeChangeEvent(
|
|
@@ -1077,7 +1114,7 @@ export default function Identity(mpInstance) {
|
|
|
1077
1114
|
* @param {Array} value an array of values
|
|
1078
1115
|
*/
|
|
1079
1116
|
// https://go.mparticle.com/work/SQDSDKS-6373
|
|
1080
|
-
setUserAttributeList: function(key, newValue) {
|
|
1117
|
+
setUserAttributeList: function(key: string, newValue: UserAttributesValue[]) {
|
|
1081
1118
|
mpInstance._SessionManager.resetSessionTimer();
|
|
1082
1119
|
|
|
1083
1120
|
if (!mpInstance._Helpers.Validators.isValidKeyValue(key)) {
|
|
@@ -1088,7 +1125,7 @@ export default function Identity(mpInstance) {
|
|
|
1088
1125
|
if (!Array.isArray(newValue)) {
|
|
1089
1126
|
mpInstance.Logger.error(
|
|
1090
1127
|
'The value you passed in to setUserAttributeList must be an array. You passed in a ' +
|
|
1091
|
-
typeof
|
|
1128
|
+
typeof newValue
|
|
1092
1129
|
);
|
|
1093
1130
|
return;
|
|
1094
1131
|
}
|
|
@@ -1136,7 +1173,7 @@ export default function Identity(mpInstance) {
|
|
|
1136
1173
|
) {
|
|
1137
1174
|
userAttributeChange = true;
|
|
1138
1175
|
} else {
|
|
1139
|
-
for (
|
|
1176
|
+
for (let i = 0; i < newValue.length; i++) {
|
|
1140
1177
|
if (previousUserAttributeValue[i] !== newValue[i]) {
|
|
1141
1178
|
userAttributeChange = true;
|
|
1142
1179
|
break;
|
|
@@ -1147,7 +1184,7 @@ export default function Identity(mpInstance) {
|
|
|
1147
1184
|
if (userAttributeChange) {
|
|
1148
1185
|
self.sendUserAttributeChangeEvent(
|
|
1149
1186
|
key,
|
|
1150
|
-
newValue,
|
|
1187
|
+
newValue as unknown as string[],
|
|
1151
1188
|
previousUserAttributeValue,
|
|
1152
1189
|
isNewAttribute,
|
|
1153
1190
|
false,
|
|
@@ -1171,7 +1208,7 @@ export default function Identity(mpInstance) {
|
|
|
1171
1208
|
* @method removeAllUserAttributes
|
|
1172
1209
|
*/
|
|
1173
1210
|
removeAllUserAttributes: function() {
|
|
1174
|
-
|
|
1211
|
+
let userAttributes;
|
|
1175
1212
|
|
|
1176
1213
|
mpInstance._SessionManager.resetSessionTimer();
|
|
1177
1214
|
|
|
@@ -1187,7 +1224,7 @@ export default function Identity(mpInstance) {
|
|
|
1187
1224
|
mpInstance._APIClient.prepareForwardingStats
|
|
1188
1225
|
);
|
|
1189
1226
|
if (userAttributes) {
|
|
1190
|
-
for (
|
|
1227
|
+
for (const prop in userAttributes) {
|
|
1191
1228
|
if (userAttributes.hasOwnProperty(prop)) {
|
|
1192
1229
|
mpInstance._Forwarders.handleForwarderUserAttributes(
|
|
1193
1230
|
'removeUserAttribute',
|
|
@@ -1206,11 +1243,11 @@ export default function Identity(mpInstance) {
|
|
|
1206
1243
|
* @return {Object} an object of only keys with array values. Example: { attr1: [1, 2, 3], attr2: ['a', 'b', 'c'] }
|
|
1207
1244
|
*/
|
|
1208
1245
|
getUserAttributesLists: function() {
|
|
1209
|
-
|
|
1210
|
-
|
|
1246
|
+
let userAttributes;
|
|
1247
|
+
const userAttributesLists = {};
|
|
1211
1248
|
|
|
1212
1249
|
userAttributes = this.getAllUserAttributes();
|
|
1213
|
-
for (
|
|
1250
|
+
for (const key in userAttributes) {
|
|
1214
1251
|
if (
|
|
1215
1252
|
userAttributes.hasOwnProperty(key) &&
|
|
1216
1253
|
Array.isArray(userAttributes[key])
|
|
@@ -1234,12 +1271,11 @@ export default function Identity(mpInstance) {
|
|
|
1234
1271
|
if (userAttributes) {
|
|
1235
1272
|
for (const prop in userAttributes) {
|
|
1236
1273
|
if (userAttributes.hasOwnProperty(prop)) {
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
].slice();
|
|
1274
|
+
const attrValue = userAttributes[prop];
|
|
1275
|
+
if (Array.isArray(attrValue)) {
|
|
1276
|
+
userAttributesCopy[prop] = attrValue.slice();
|
|
1241
1277
|
} else {
|
|
1242
|
-
userAttributesCopy[prop] =
|
|
1278
|
+
userAttributesCopy[prop] = attrValue;
|
|
1243
1279
|
}
|
|
1244
1280
|
}
|
|
1245
1281
|
}
|
|
@@ -1278,7 +1314,7 @@ export default function Identity(mpInstance) {
|
|
|
1278
1314
|
* @method setConsentState
|
|
1279
1315
|
* @param {Object} consent state
|
|
1280
1316
|
*/
|
|
1281
|
-
setConsentState: function(state) {
|
|
1317
|
+
setConsentState: function(state: ConsentState) {
|
|
1282
1318
|
mpInstance._Store.setConsentState(mpid, state);
|
|
1283
1319
|
mpInstance._Forwarders.initForwarders(
|
|
1284
1320
|
this.getUserIdentities().userIdentities,
|
|
@@ -1301,7 +1337,7 @@ export default function Identity(mpInstance) {
|
|
|
1301
1337
|
* @param {Function} [callback] A callback function that is invoked when the user audience request completes
|
|
1302
1338
|
*/
|
|
1303
1339
|
// https://go.mparticle.com/work/SQDSDKS-6436
|
|
1304
|
-
getUserAudiences: function(callback) {
|
|
1340
|
+
getUserAudiences: function(callback: IdentityCallback) {
|
|
1305
1341
|
// user audience API is feature flagged
|
|
1306
1342
|
if (
|
|
1307
1343
|
!mpInstance._Helpers.getFeatureFlag(
|
|
@@ -1317,12 +1353,14 @@ export default function Identity(mpInstance) {
|
|
|
1317
1353
|
self.audienceManager = new AudienceManager(
|
|
1318
1354
|
mpInstance._Store.SDKConfig.userAudienceUrl,
|
|
1319
1355
|
mpInstance._Store.devToken,
|
|
1320
|
-
mpInstance.Logger
|
|
1321
|
-
mpid
|
|
1356
|
+
mpInstance.Logger
|
|
1322
1357
|
);
|
|
1323
1358
|
}
|
|
1324
1359
|
|
|
1325
|
-
self.audienceManager.sendGetUserAudienceRequest(
|
|
1360
|
+
self.audienceManager.sendGetUserAudienceRequest(
|
|
1361
|
+
mpid,
|
|
1362
|
+
callback as unknown as (userAudiences: IAudienceMemberships) => void
|
|
1363
|
+
);
|
|
1326
1364
|
},
|
|
1327
1365
|
};
|
|
1328
1366
|
};
|
|
@@ -1333,7 +1371,7 @@ export default function Identity(mpInstance) {
|
|
|
1333
1371
|
* @class mParticle.Identity.getCurrentUser().getCart()
|
|
1334
1372
|
* @deprecated
|
|
1335
1373
|
*/
|
|
1336
|
-
this.mParticleUserCart = function() {
|
|
1374
|
+
this.mParticleUserCart = function(): mParticleUserCart {
|
|
1337
1375
|
return {
|
|
1338
1376
|
/**
|
|
1339
1377
|
* Adds a cart product to the user cart
|
|
@@ -1425,14 +1463,14 @@ export default function Identity(mpInstance) {
|
|
|
1425
1463
|
|
|
1426
1464
|
// https://go.mparticle.com/work/SQDSDKS-6355
|
|
1427
1465
|
this.parseIdentityResponse = function(
|
|
1428
|
-
identityResponse,
|
|
1429
|
-
previousMPID,
|
|
1430
|
-
callback,
|
|
1431
|
-
identityApiData,
|
|
1432
|
-
method,
|
|
1433
|
-
knownIdentities,
|
|
1434
|
-
parsingCachedResponse
|
|
1435
|
-
) {
|
|
1466
|
+
identityResponse: IIdentityResponse,
|
|
1467
|
+
previousMPID: MPID,
|
|
1468
|
+
callback: IdentityCallback,
|
|
1469
|
+
identityApiData: IdentityApiData,
|
|
1470
|
+
method: IdentityAPIMethod,
|
|
1471
|
+
knownIdentities: IKnownIdentities,
|
|
1472
|
+
parsingCachedResponse: boolean
|
|
1473
|
+
): void {
|
|
1436
1474
|
const prevUser = mpInstance.Identity.getUser(previousMPID);
|
|
1437
1475
|
const prevUserMPID = prevUser ? prevUser.getMPID() : null;
|
|
1438
1476
|
const previousUIByName = prevUser
|
|
@@ -1666,11 +1704,11 @@ export default function Identity(mpInstance) {
|
|
|
1666
1704
|
// compare what identities exist vs what is previously was for the specific user if they were in memory before.
|
|
1667
1705
|
// if it's the first time the user is logging in, send a user identity change request with
|
|
1668
1706
|
this.sendUserIdentityChangeEvent = function(
|
|
1669
|
-
newUserIdentities,
|
|
1670
|
-
method,
|
|
1671
|
-
mpid,
|
|
1672
|
-
prevUserIdentities
|
|
1673
|
-
) {
|
|
1707
|
+
newUserIdentities: UserIdentities,
|
|
1708
|
+
method: IdentityAPIMethod,
|
|
1709
|
+
mpid: MPID,
|
|
1710
|
+
prevUserIdentities: UserIdentities
|
|
1711
|
+
): void {
|
|
1674
1712
|
if (!mpid) {
|
|
1675
1713
|
// https://go.mparticle.com/work/SQDSDKS-6501
|
|
1676
1714
|
if (method !== Modify) {
|
|
@@ -1681,38 +1719,40 @@ export default function Identity(mpInstance) {
|
|
|
1681
1719
|
// https://go.mparticle.com/work/SQDSDKS-6354
|
|
1682
1720
|
const currentUserInMemory = this.IdentityAPI.getUser(mpid);
|
|
1683
1721
|
|
|
1684
|
-
for (
|
|
1722
|
+
for (const identityType in newUserIdentities) {
|
|
1685
1723
|
// Verifies a change actually happened
|
|
1686
1724
|
if (
|
|
1687
|
-
prevUserIdentities[identityType] !==
|
|
1688
|
-
newUserIdentities[identityType]
|
|
1725
|
+
prevUserIdentities[identityType as keyof UserIdentities] !==
|
|
1726
|
+
newUserIdentities[identityType as keyof UserIdentities]
|
|
1689
1727
|
) {
|
|
1690
1728
|
// If a new identity type was introduced when the identity changes
|
|
1691
1729
|
// we need to notify the server so that the user profile is updated in
|
|
1692
1730
|
// the mParticle UI.
|
|
1693
|
-
const isNewUserIdentityType = !prevUserIdentities[
|
|
1731
|
+
const isNewUserIdentityType = !prevUserIdentities[
|
|
1732
|
+
identityType as keyof UserIdentities
|
|
1733
|
+
];
|
|
1694
1734
|
const userIdentityChangeEvent = self.createUserIdentityChange(
|
|
1695
|
-
identityType,
|
|
1696
|
-
newUserIdentities[identityType],
|
|
1697
|
-
prevUserIdentities[identityType],
|
|
1735
|
+
identityType as SDKIdentityTypeEnum,
|
|
1736
|
+
newUserIdentities[identityType as keyof UserIdentities],
|
|
1737
|
+
prevUserIdentities[identityType as keyof UserIdentities],
|
|
1698
1738
|
isNewUserIdentityType,
|
|
1699
1739
|
currentUserInMemory
|
|
1700
1740
|
);
|
|
1701
1741
|
mpInstance._APIClient?.sendEventToServer(
|
|
1702
|
-
userIdentityChangeEvent
|
|
1742
|
+
userIdentityChangeEvent as unknown as SDKEvent
|
|
1703
1743
|
);
|
|
1704
1744
|
}
|
|
1705
1745
|
}
|
|
1706
1746
|
};
|
|
1707
1747
|
|
|
1708
1748
|
this.createUserIdentityChange = function(
|
|
1709
|
-
identityType,
|
|
1710
|
-
newIdentity,
|
|
1711
|
-
oldIdentity,
|
|
1712
|
-
isIdentityTypeNewToBatch,
|
|
1713
|
-
userInMemory
|
|
1749
|
+
identityType: SDKIdentityTypeEnum,
|
|
1750
|
+
newIdentity: string,
|
|
1751
|
+
oldIdentity: string,
|
|
1752
|
+
isIdentityTypeNewToBatch: boolean,
|
|
1753
|
+
userInMemory: IMParticleUser
|
|
1714
1754
|
) {
|
|
1715
|
-
|
|
1755
|
+
let userIdentityChangeEvent;
|
|
1716
1756
|
|
|
1717
1757
|
// https://go.mparticle.com/work/SQDSDKS-6439
|
|
1718
1758
|
userIdentityChangeEvent = mpInstance._ServerModel.createEventObject({
|
|
@@ -1730,20 +1770,20 @@ export default function Identity(mpInstance) {
|
|
|
1730
1770
|
},
|
|
1731
1771
|
},
|
|
1732
1772
|
userInMemory,
|
|
1733
|
-
});
|
|
1773
|
+
} as BaseEvent);
|
|
1734
1774
|
|
|
1735
1775
|
return userIdentityChangeEvent;
|
|
1736
1776
|
};
|
|
1737
1777
|
|
|
1738
1778
|
this.sendUserAttributeChangeEvent = function(
|
|
1739
|
-
attributeKey,
|
|
1740
|
-
newUserAttributeValue,
|
|
1741
|
-
previousUserAttributeValue,
|
|
1742
|
-
isNewAttribute,
|
|
1743
|
-
deleted,
|
|
1744
|
-
user
|
|
1745
|
-
) {
|
|
1746
|
-
|
|
1779
|
+
attributeKey: string,
|
|
1780
|
+
newUserAttributeValue: UserAttributeChangeValue,
|
|
1781
|
+
previousUserAttributeValue: UserAttributeChangeValue,
|
|
1782
|
+
isNewAttribute: boolean,
|
|
1783
|
+
deleted: boolean,
|
|
1784
|
+
user: IMParticleUser
|
|
1785
|
+
): void {
|
|
1786
|
+
const userAttributeChangeEvent = self.createUserAttributeChange(
|
|
1747
1787
|
attributeKey,
|
|
1748
1788
|
newUserAttributeValue,
|
|
1749
1789
|
previousUserAttributeValue,
|
|
@@ -1752,22 +1792,22 @@ export default function Identity(mpInstance) {
|
|
|
1752
1792
|
user
|
|
1753
1793
|
);
|
|
1754
1794
|
if (userAttributeChangeEvent) {
|
|
1755
|
-
mpInstance._APIClient?.sendEventToServer(userAttributeChangeEvent);
|
|
1795
|
+
mpInstance._APIClient?.sendEventToServer(userAttributeChangeEvent as unknown as SDKEvent);
|
|
1756
1796
|
}
|
|
1757
1797
|
};
|
|
1758
1798
|
|
|
1759
1799
|
this.createUserAttributeChange = function(
|
|
1760
|
-
key,
|
|
1761
|
-
newValue,
|
|
1762
|
-
previousUserAttributeValue,
|
|
1763
|
-
isNewAttribute,
|
|
1764
|
-
deleted,
|
|
1765
|
-
user
|
|
1800
|
+
key: string,
|
|
1801
|
+
newValue: UserAttributeChangeValue,
|
|
1802
|
+
previousUserAttributeValue: UserAttributeChangeValue,
|
|
1803
|
+
isNewAttribute: boolean,
|
|
1804
|
+
deleted: boolean,
|
|
1805
|
+
user: IMParticleUser
|
|
1766
1806
|
) {
|
|
1767
1807
|
if (typeof previousUserAttributeValue === 'undefined') {
|
|
1768
1808
|
previousUserAttributeValue = null;
|
|
1769
1809
|
}
|
|
1770
|
-
|
|
1810
|
+
let userAttributeChangeEvent;
|
|
1771
1811
|
if (newValue !== previousUserAttributeValue) {
|
|
1772
1812
|
// https://go.mparticle.com/work/SQDSDKS-6439
|
|
1773
1813
|
userAttributeChangeEvent = mpInstance._ServerModel.createEventObject(
|
|
@@ -1775,8 +1815,8 @@ export default function Identity(mpInstance) {
|
|
|
1775
1815
|
messageType: Types.MessageType.UserAttributeChange,
|
|
1776
1816
|
userAttributeChanges: {
|
|
1777
1817
|
UserAttributeName: key,
|
|
1778
|
-
New: newValue,
|
|
1779
|
-
Old: previousUserAttributeValue,
|
|
1818
|
+
New: newValue as string,
|
|
1819
|
+
Old: previousUserAttributeValue as string,
|
|
1780
1820
|
Deleted: deleted,
|
|
1781
1821
|
IsNewAttribute: isNewAttribute,
|
|
1782
1822
|
},
|
|
@@ -1787,7 +1827,7 @@ export default function Identity(mpInstance) {
|
|
|
1787
1827
|
return userAttributeChangeEvent;
|
|
1788
1828
|
};
|
|
1789
1829
|
|
|
1790
|
-
this.reinitForwardersOnUserChange = function(prevUser, newUser) {
|
|
1830
|
+
this.reinitForwardersOnUserChange = function(prevUser: IMParticleUser, newUser: IMParticleUser): void {
|
|
1791
1831
|
if (hasMPIDAndUserLoginChanged(prevUser, newUser)) {
|
|
1792
1832
|
mpInstance._Forwarders?.initForwarders(
|
|
1793
1833
|
newUser.getUserIdentities().userIdentities,
|
|
@@ -1796,7 +1836,7 @@ export default function Identity(mpInstance) {
|
|
|
1796
1836
|
}
|
|
1797
1837
|
};
|
|
1798
1838
|
|
|
1799
|
-
this.setForwarderCallbacks = function(user, method) {
|
|
1839
|
+
this.setForwarderCallbacks = function(user: IMParticleUser, method: IdentityAPIMethod): void {
|
|
1800
1840
|
// https://go.mparticle.com/work/SQDSDKS-6036
|
|
1801
1841
|
mpInstance._Forwarders?.setForwarderUserIdentities(
|
|
1802
1842
|
user.getUserIdentities().userIdentities
|
|
@@ -1806,14 +1846,19 @@ export default function Identity(mpInstance) {
|
|
|
1806
1846
|
};
|
|
1807
1847
|
}
|
|
1808
1848
|
|
|
1849
|
+
interface IdentityApiDataWithAlias extends IdentityApiData {
|
|
1850
|
+
/** @deprecated */
|
|
1851
|
+
onUserAlias?: (previousUser: IMParticleUser, newUser: IMParticleUser) => void;
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1809
1854
|
// https://go.mparticle.com/work/SQDSDKS-6359
|
|
1810
1855
|
function tryOnUserAlias(
|
|
1811
|
-
previousUser,
|
|
1812
|
-
newUser,
|
|
1813
|
-
identityApiData,
|
|
1814
|
-
logger,
|
|
1815
|
-
errorReporter
|
|
1816
|
-
) {
|
|
1856
|
+
previousUser: IMParticleUser,
|
|
1857
|
+
newUser: IMParticleUser,
|
|
1858
|
+
identityApiData: IdentityApiDataWithAlias,
|
|
1859
|
+
logger: SDKLoggerApi,
|
|
1860
|
+
errorReporter: IErrorReportingService | undefined
|
|
1861
|
+
): void {
|
|
1817
1862
|
if (
|
|
1818
1863
|
identityApiData &&
|
|
1819
1864
|
identityApiData.onUserAlias &&
|