@mparticle/web-sdk 2.58.0 → 2.60.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 +110 -86
- package/dist/mparticle.esm.js +110 -86
- package/dist/mparticle.js +467 -276
- package/package.json +1 -1
- package/src/apiClient.ts +42 -4
- package/src/batchUploader.ts +23 -26
- package/src/cookieSyncManager.ts +6 -0
- package/src/foregroundTimeTracker.ts +5 -3
- package/src/identity-utils.ts +24 -1
- package/src/identityApiClient.ts +15 -5
- package/src/logger.ts +4 -0
- package/src/mp-instance.ts +65 -23
- package/src/persistence.js +15 -0
- package/src/roktManager.ts +12 -4
- package/src/sdkRuntimeModels.ts +2 -0
- package/src/sessionManager.ts +11 -2
- package/src/store.ts +2 -1
- package/src/utils.ts +63 -2
- package/src/vault.ts +28 -35
package/src/utils.ts
CHANGED
|
@@ -426,12 +426,71 @@ const filterDictionaryWithHash = <T>(
|
|
|
426
426
|
}
|
|
427
427
|
|
|
428
428
|
const parseConfig = (config: SDKInitConfig, moduleName: string, moduleId: number): IKitConfigs | null => {
|
|
429
|
-
return config.kitConfigs?.find((kitConfig: IKitConfigs) =>
|
|
430
|
-
kitConfig.name === moduleName &&
|
|
429
|
+
return config.kitConfigs?.find((kitConfig: IKitConfigs) =>
|
|
430
|
+
kitConfig.name === moduleName &&
|
|
431
431
|
kitConfig.moduleId === moduleId
|
|
432
432
|
) || null;
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
+
/**
|
|
436
|
+
* Obfuscates an object by replacing all primitive values with their type names,
|
|
437
|
+
* while preserving the structure of nested objects and arrays.
|
|
438
|
+
* This is useful for logging data structures without exposing PII.
|
|
439
|
+
*
|
|
440
|
+
* @param value - The value to obfuscate
|
|
441
|
+
* @returns The obfuscated value with types instead of actual values
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* obfuscateData({ email: 'user@email.com', age: 30 })
|
|
445
|
+
* // Returns: { email: 'string', age: 'number' }
|
|
446
|
+
*
|
|
447
|
+
* obfuscateData({ tags: ['premium', 'verified'] })
|
|
448
|
+
* // Returns: { tags: ['string', 'string'] }
|
|
449
|
+
*/
|
|
450
|
+
const obfuscateData = (value: any): any => {
|
|
451
|
+
// Preserve null and undefined
|
|
452
|
+
if (value === null || value === undefined) {
|
|
453
|
+
return value;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// Handle arrays - recursively obfuscate each element
|
|
457
|
+
if (Array.isArray(value)) {
|
|
458
|
+
return value.map(item => obfuscateData(item));
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// Handle objects - recursively obfuscate each property
|
|
462
|
+
if (isObject(value)) {
|
|
463
|
+
const obfuscated: Dictionary<any> = {};
|
|
464
|
+
for (const key in value) {
|
|
465
|
+
if (value.hasOwnProperty(key)) {
|
|
466
|
+
obfuscated[key] = obfuscateData(value[key]);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return obfuscated;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// For primitives and other types, return the type as a string
|
|
473
|
+
return typeof value;
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* For verbose logging: returns raw data when isDevelopmentMode is true, else obfuscated data.
|
|
478
|
+
* Used when logging payloads so PII is not exposed in production.
|
|
479
|
+
*
|
|
480
|
+
* @param data - The value to log
|
|
481
|
+
* @param isDevelopmentMode - When true, returns data unchanged, when false or undefined, returns obfuscated data
|
|
482
|
+
* @returns Raw data when isDevelopmentMode is true, otherwise obfuscated structure
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* obfuscateDevData({ email: 'user@email.com' }, true)
|
|
486
|
+
* // Returns: { email: 'user@email.com' }
|
|
487
|
+
*
|
|
488
|
+
* obfuscateDevData({ email: 'user@email.com' }, false)
|
|
489
|
+
* // Returns: { email: 'string' }
|
|
490
|
+
*/
|
|
491
|
+
const obfuscateDevData = (data: any, isDevelopmentMode?: boolean): any =>
|
|
492
|
+
isDevelopmentMode ? data : obfuscateData(data);
|
|
493
|
+
|
|
435
494
|
export {
|
|
436
495
|
createCookieString,
|
|
437
496
|
revertCookieString,
|
|
@@ -440,6 +499,7 @@ export {
|
|
|
440
499
|
AttributeValue,
|
|
441
500
|
converted,
|
|
442
501
|
decoded,
|
|
502
|
+
obfuscateDevData,
|
|
443
503
|
filterDictionaryWithHash,
|
|
444
504
|
findKeyInObject,
|
|
445
505
|
generateDeprecationMessage,
|
|
@@ -449,6 +509,7 @@ export {
|
|
|
449
509
|
inArray,
|
|
450
510
|
isObject,
|
|
451
511
|
isStringOrNumber,
|
|
512
|
+
obfuscateData,
|
|
452
513
|
parseConfig,
|
|
453
514
|
parseNumber,
|
|
454
515
|
parseSettingsString,
|
package/src/vault.ts
CHANGED
|
@@ -1,38 +1,22 @@
|
|
|
1
|
-
import { Logger } from '@mparticle/web-sdk';
|
|
2
1
|
import { isEmpty, isNumber } from './utils';
|
|
3
2
|
|
|
4
|
-
export interface IVaultOptions {
|
|
5
|
-
logger?: Logger;
|
|
6
|
-
offlineStorageEnabled?: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
3
|
export abstract class BaseVault<StorableItem> {
|
|
10
4
|
public contents: StorableItem;
|
|
11
5
|
protected readonly _storageKey: string;
|
|
12
|
-
protected logger?: Logger;
|
|
13
6
|
protected storageObject: Storage;
|
|
14
7
|
|
|
15
8
|
/**
|
|
16
9
|
*
|
|
17
10
|
* @param {string} storageKey the local storage key string
|
|
18
|
-
* @param {Storage} Web API Storage object that is being used
|
|
19
|
-
* @param {IVaultOptions} options A Dictionary of IVaultOptions
|
|
11
|
+
* @param {Storage} storageObject Web API Storage object that is being used
|
|
20
12
|
*/
|
|
21
13
|
constructor(
|
|
22
14
|
storageKey: string,
|
|
23
|
-
storageObject: Storage
|
|
24
|
-
options?: IVaultOptions
|
|
15
|
+
storageObject: Storage
|
|
25
16
|
) {
|
|
26
17
|
this._storageKey = storageKey;
|
|
27
18
|
this.storageObject = storageObject;
|
|
28
19
|
|
|
29
|
-
// Add a fake logger in case one is not provided or needed
|
|
30
|
-
this.logger = options?.logger || {
|
|
31
|
-
verbose: () => {},
|
|
32
|
-
warning: () => {},
|
|
33
|
-
error: () => {},
|
|
34
|
-
};
|
|
35
|
-
|
|
36
20
|
this.contents = this.retrieve();
|
|
37
21
|
}
|
|
38
22
|
|
|
@@ -51,16 +35,7 @@ export abstract class BaseVault<StorableItem> {
|
|
|
51
35
|
stringifiedItem = '';
|
|
52
36
|
}
|
|
53
37
|
|
|
54
|
-
|
|
55
|
-
this.storageObject.setItem(this._storageKey, stringifiedItem);
|
|
56
|
-
|
|
57
|
-
this.logger.verbose(`Saving item to Storage: ${stringifiedItem}`);
|
|
58
|
-
} catch (error) {
|
|
59
|
-
this.logger.error(
|
|
60
|
-
`Cannot Save items to Storage: ${stringifiedItem}`
|
|
61
|
-
);
|
|
62
|
-
this.logger.error(error as string);
|
|
63
|
-
}
|
|
38
|
+
this.storageObject.setItem(this._storageKey, stringifiedItem);
|
|
64
39
|
}
|
|
65
40
|
|
|
66
41
|
/**
|
|
@@ -75,8 +50,6 @@ export abstract class BaseVault<StorableItem> {
|
|
|
75
50
|
|
|
76
51
|
this.contents = item ? JSON.parse(item) : null;
|
|
77
52
|
|
|
78
|
-
this.logger.verbose(`Retrieving item from Storage: ${item}`);
|
|
79
|
-
|
|
80
53
|
return this.contents;
|
|
81
54
|
}
|
|
82
55
|
|
|
@@ -86,20 +59,40 @@ export abstract class BaseVault<StorableItem> {
|
|
|
86
59
|
* @method purge
|
|
87
60
|
*/
|
|
88
61
|
public purge(): void {
|
|
89
|
-
this.logger.verbose('Purging Storage');
|
|
90
62
|
this.contents = null;
|
|
91
63
|
this.storageObject.removeItem(this._storageKey);
|
|
92
64
|
}
|
|
93
65
|
}
|
|
94
66
|
|
|
95
67
|
export class LocalStorageVault<StorableItem> extends BaseVault<StorableItem> {
|
|
96
|
-
constructor(storageKey: string
|
|
97
|
-
super(storageKey, window.localStorage
|
|
68
|
+
constructor(storageKey: string) {
|
|
69
|
+
super(storageKey, window.localStorage);
|
|
98
70
|
}
|
|
99
71
|
}
|
|
100
72
|
|
|
101
73
|
export class SessionStorageVault<StorableItem> extends BaseVault<StorableItem> {
|
|
102
|
-
constructor(storageKey: string
|
|
103
|
-
super(storageKey, window.sessionStorage
|
|
74
|
+
constructor(storageKey: string) {
|
|
75
|
+
super(storageKey, window.sessionStorage);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// DisabledVault is used when persistence is disabled by privacy flags.
|
|
80
|
+
export class DisabledVault<StorableItem> extends BaseVault<StorableItem> {
|
|
81
|
+
constructor(storageKey: string) {
|
|
82
|
+
super(storageKey, window.localStorage);
|
|
83
|
+
this.contents = null;
|
|
84
|
+
this.storageObject.removeItem(this._storageKey);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public store(_item: StorableItem): void {
|
|
88
|
+
this.contents = null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public retrieve(): StorableItem | null {
|
|
92
|
+
return this.contents;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public purge(): void {
|
|
96
|
+
this.contents = null;
|
|
104
97
|
}
|
|
105
98
|
}
|