@mparticle/web-sdk 2.52.0 → 2.53.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 +25 -10
- package/dist/mparticle.esm.js +25 -10
- package/dist/mparticle.js +128 -74
- package/package.json +1 -1
- package/src/batchUploader.ts +3 -3
- package/src/cookieConsentManager.ts +64 -0
- package/src/cookieSyncManager.ts +6 -0
- package/src/identityApiClient.ts +11 -12
- package/src/logger.ts +66 -0
- package/src/mp-instance.ts +8 -1
- package/src/roktManager.ts +19 -17
- package/src/sdkRuntimeModels.ts +9 -1
- package/src/logger.js +0 -61
package/src/mp-instance.ts
CHANGED
|
@@ -25,7 +25,7 @@ import CookieSyncManager, { ICookieSyncManager } from './cookieSyncManager';
|
|
|
25
25
|
import SessionManager, { ISessionManager } from './sessionManager';
|
|
26
26
|
import Ecommerce from './ecommerce';
|
|
27
27
|
import Store, { IStore } from './store';
|
|
28
|
-
import Logger from './logger';
|
|
28
|
+
import { Logger } from './logger';
|
|
29
29
|
import Persistence from './persistence';
|
|
30
30
|
import Events from './events';
|
|
31
31
|
import Forwarders from './forwarders';
|
|
@@ -51,6 +51,7 @@ import { IPersistence } from './persistence.interfaces';
|
|
|
51
51
|
import ForegroundTimer from './foregroundTimeTracker';
|
|
52
52
|
import RoktManager, { IRoktOptions } from './roktManager';
|
|
53
53
|
import filteredMparticleUser from './filteredMparticleUser';
|
|
54
|
+
import CookieConsentManager, { ICookieConsentManager } from './cookieConsentManager';
|
|
54
55
|
|
|
55
56
|
export interface IErrorLogMessage {
|
|
56
57
|
message?: string;
|
|
@@ -82,6 +83,7 @@ export interface IMParticleWebSDKInstance extends MParticleWebSDK {
|
|
|
82
83
|
_IntegrationCapture: IntegrationCapture;
|
|
83
84
|
_NativeSdkHelpers: INativeSdkHelpers;
|
|
84
85
|
_Persistence: IPersistence;
|
|
86
|
+
_CookieConsentManager: ICookieConsentManager;
|
|
85
87
|
_RoktManager: RoktManager;
|
|
86
88
|
_SessionManager: ISessionManager;
|
|
87
89
|
_ServerModel: IServerModel;
|
|
@@ -227,6 +229,7 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
|
|
|
227
229
|
if (instance._Store) {
|
|
228
230
|
delete instance._Store;
|
|
229
231
|
}
|
|
232
|
+
instance.Logger = new Logger(config);
|
|
230
233
|
instance._Store = new Store(config, instance);
|
|
231
234
|
instance._Store.isLocalStorageAvailable = instance._Persistence.determineLocalStorageAvailability(
|
|
232
235
|
window.localStorage
|
|
@@ -1554,6 +1557,10 @@ function runPreConfigFetchInitialization(mpInstance, apiKey, config) {
|
|
|
1554
1557
|
window.mParticle.Store = mpInstance._Store;
|
|
1555
1558
|
mpInstance.Logger.verbose(StartingInitialization);
|
|
1556
1559
|
|
|
1560
|
+
// Initialize CookieConsentManager with privacy flags from launcherOptions
|
|
1561
|
+
const { noFunctional, noTargeting } = config?.launcherOptions ?? {};
|
|
1562
|
+
mpInstance._CookieConsentManager = new CookieConsentManager({ noFunctional, noTargeting });
|
|
1563
|
+
|
|
1557
1564
|
// Check to see if localStorage is available before main configuration runs
|
|
1558
1565
|
// since we will need this for the current implementation of user persistence
|
|
1559
1566
|
// TODO: Refactor this when we refactor User Identity Persistence
|
package/src/roktManager.ts
CHANGED
|
@@ -17,9 +17,10 @@ import { UserIdentities } from "@mparticle/web-sdk";
|
|
|
17
17
|
import { IdentityType } from "./types";
|
|
18
18
|
|
|
19
19
|
// https://docs.rokt.com/developers/integration-guides/web/library/attributes
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
export type RoktAttributeValueArray = Array<string | number | boolean>;
|
|
21
|
+
export type RoktAttributeValueType = string | number | boolean | undefined | null;
|
|
22
|
+
export type RoktAttributeValue = RoktAttributeValueType | RoktAttributeValueArray;
|
|
23
|
+
export type RoktAttributes = Record<string, RoktAttributeValue>;
|
|
23
24
|
|
|
24
25
|
export interface IRoktPartnerExtensionData<T> {
|
|
25
26
|
[extensionName: string]: T;
|
|
@@ -27,7 +28,7 @@ export interface IRoktPartnerExtensionData<T> {
|
|
|
27
28
|
|
|
28
29
|
// https://docs.rokt.com/developers/integration-guides/web/library/select-placements-options
|
|
29
30
|
export interface IRoktSelectPlacementsOptions {
|
|
30
|
-
attributes:
|
|
31
|
+
attributes: RoktAttributes;
|
|
31
32
|
identifier?: string;
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -40,7 +41,7 @@ export interface IRoktSelection {
|
|
|
40
41
|
|
|
41
42
|
export interface IRoktLauncher {
|
|
42
43
|
selectPlacements: (options: IRoktSelectPlacementsOptions) => Promise<IRoktSelection>;
|
|
43
|
-
hashAttributes: (attributes:
|
|
44
|
+
hashAttributes: (attributes: RoktAttributes) => Promise<Record<string, string>>;
|
|
44
45
|
use: <T>(name: string) => Promise<T>;
|
|
45
46
|
}
|
|
46
47
|
|
|
@@ -63,7 +64,7 @@ export interface IRoktKit {
|
|
|
63
64
|
filteredUser: IMParticleUser | null;
|
|
64
65
|
launcher: IRoktLauncher | null;
|
|
65
66
|
userAttributes: Dictionary<string>;
|
|
66
|
-
hashAttributes: (attributes:
|
|
67
|
+
hashAttributes: (attributes: RoktAttributes) => Promise<RoktAttributes>;
|
|
67
68
|
selectPlacements: (options: IRoktSelectPlacementsOptions) => Promise<IRoktSelection>;
|
|
68
69
|
setExtensionData<T>(extensionData: IRoktPartnerExtensionData<T>): void;
|
|
69
70
|
use: <T>(name: string) => Promise<T>;
|
|
@@ -99,7 +100,7 @@ export default class RoktManager {
|
|
|
99
100
|
private launcherOptions?: IRoktLauncherOptions;
|
|
100
101
|
private logger: SDKLoggerApi;
|
|
101
102
|
private domain?: string;
|
|
102
|
-
private mappedEmailShaIdentityType?: string
|
|
103
|
+
private mappedEmailShaIdentityType?: string | null;
|
|
103
104
|
/**
|
|
104
105
|
* Initializes the RoktManager with configuration settings and user data.
|
|
105
106
|
*
|
|
@@ -257,11 +258,11 @@ export default class RoktManager {
|
|
|
257
258
|
* with Rokt-compatible key names (like emailsha256, mobilesha256)
|
|
258
259
|
*
|
|
259
260
|
*
|
|
260
|
-
* @param {
|
|
261
|
-
* @returns {Promise<
|
|
261
|
+
* @param {RoktAttributes} attributes - Attributes to hash
|
|
262
|
+
* @returns {Promise<RoktAttributes>} Object with both original and hashed attributes
|
|
262
263
|
*
|
|
263
264
|
*/
|
|
264
|
-
public async hashAttributes(attributes:
|
|
265
|
+
public async hashAttributes(attributes: RoktAttributes): Promise<RoktAttributes> {
|
|
265
266
|
try {
|
|
266
267
|
if (!attributes || typeof attributes !== 'object') {
|
|
267
268
|
return {};
|
|
@@ -276,7 +277,7 @@ export default class RoktManager {
|
|
|
276
277
|
|
|
277
278
|
// Hash all attributes in parallel
|
|
278
279
|
const hashPromises = keys.map(async (key) => {
|
|
279
|
-
const attributeValue = attributes[key];
|
|
280
|
+
const attributeValue = attributes[key] as RoktAttributeValueType;
|
|
280
281
|
const hashedValue = await this.hashSha256(attributeValue);
|
|
281
282
|
return { key, attributeValue, hashedValue };
|
|
282
283
|
});
|
|
@@ -284,7 +285,7 @@ export default class RoktManager {
|
|
|
284
285
|
const results = await Promise.all(hashPromises);
|
|
285
286
|
|
|
286
287
|
// Build the result object
|
|
287
|
-
const hashedAttributes:
|
|
288
|
+
const hashedAttributes: RoktAttributes = {};
|
|
288
289
|
for (const { key, attributeValue, hashedValue } of results) {
|
|
289
290
|
hashedAttributes[key] = attributeValue;
|
|
290
291
|
if (hashedValue) {
|
|
@@ -333,7 +334,7 @@ export default class RoktManager {
|
|
|
333
334
|
* @returns {Promise<string | undefined | null>} SHA-256 hashed value or undefined/null
|
|
334
335
|
*
|
|
335
336
|
*/
|
|
336
|
-
public async hashSha256(attribute:
|
|
337
|
+
public async hashSha256(attribute: RoktAttributeValueType): Promise<string | undefined | null> {
|
|
337
338
|
if (attribute === null || attribute === undefined) {
|
|
338
339
|
this.logger.warning(`hashSha256 received null/undefined as input`);
|
|
339
340
|
return attribute as null | undefined;
|
|
@@ -362,13 +363,14 @@ export default class RoktManager {
|
|
|
362
363
|
return Boolean(this.kit && this.kit.launcher);
|
|
363
364
|
}
|
|
364
365
|
|
|
365
|
-
private setUserAttributes(attributes:
|
|
366
|
+
private setUserAttributes(attributes: RoktAttributes): void {
|
|
366
367
|
const reservedAttributes = ['sandbox'];
|
|
367
368
|
const filteredAttributes = {};
|
|
368
369
|
|
|
369
370
|
for (const key in attributes) {
|
|
370
371
|
if (attributes.hasOwnProperty(key) && reservedAttributes.indexOf(key) === -1) {
|
|
371
|
-
|
|
372
|
+
const value = attributes[key];
|
|
373
|
+
filteredAttributes[key] = Array.isArray(value) ? JSON.stringify(value) : value;
|
|
372
374
|
}
|
|
373
375
|
}
|
|
374
376
|
|
|
@@ -379,13 +381,13 @@ export default class RoktManager {
|
|
|
379
381
|
}
|
|
380
382
|
}
|
|
381
383
|
|
|
382
|
-
private mapPlacementAttributes(attributes:
|
|
384
|
+
private mapPlacementAttributes(attributes: RoktAttributes, placementAttributesMapping: Dictionary<string>[]): RoktAttributes {
|
|
383
385
|
const mappingLookup: { [key: string]: string } = {};
|
|
384
386
|
for (const mapping of placementAttributesMapping) {
|
|
385
387
|
mappingLookup[mapping.map] = mapping.value;
|
|
386
388
|
}
|
|
387
389
|
|
|
388
|
-
const mappedAttributes:
|
|
390
|
+
const mappedAttributes: RoktAttributes = {};
|
|
389
391
|
for (const key in attributes) {
|
|
390
392
|
if (attributes.hasOwnProperty(key)) {
|
|
391
393
|
const newKey = mappingLookup[key] || key;
|
package/src/sdkRuntimeModels.ts
CHANGED
|
@@ -40,6 +40,7 @@ import { SDKECommerceAPI } from './ecommerce.interfaces';
|
|
|
40
40
|
import { IErrorLogMessage, IMParticleWebSDKInstance, IntegrationDelays } from './mp-instance';
|
|
41
41
|
import Constants from './constants';
|
|
42
42
|
import RoktManager, { IRoktLauncherOptions } from './roktManager';
|
|
43
|
+
import { IConsoleLogger } from './logger';
|
|
43
44
|
|
|
44
45
|
// TODO: Resolve this with version in @mparticle/web-sdk
|
|
45
46
|
export type SDKEventCustomFlags = Dictionary<any>;
|
|
@@ -259,7 +260,13 @@ export interface IMParticleInstanceManager extends MParticleWebSDK {
|
|
|
259
260
|
export type BooleanStringLowerCase = 'false' | 'true';
|
|
260
261
|
export type BooleanStringTitleCase = 'False' | 'True';
|
|
261
262
|
|
|
262
|
-
export type LogLevelType =
|
|
263
|
+
export type LogLevelType = (typeof LogLevelType)[keyof typeof LogLevelType];
|
|
264
|
+
export const LogLevelType = {
|
|
265
|
+
None: 'none',
|
|
266
|
+
Verbose: 'verbose',
|
|
267
|
+
Warning: 'warning',
|
|
268
|
+
Error: 'error',
|
|
269
|
+
} as const;
|
|
263
270
|
|
|
264
271
|
// TODO: This should eventually be moved into wherever init logic lives
|
|
265
272
|
// TODO: Replace/Merge this with MPConfiguration in @types/mparticle__web-sdk
|
|
@@ -306,6 +313,7 @@ export interface SDKInitConfig
|
|
|
306
313
|
launcherOptions?: IRoktLauncherOptions;
|
|
307
314
|
|
|
308
315
|
rq?: Function[] | any[];
|
|
316
|
+
logger?: IConsoleLogger;
|
|
309
317
|
}
|
|
310
318
|
|
|
311
319
|
export interface DataPlanConfig {
|
package/src/logger.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
function Logger(config) {
|
|
2
|
-
var self = this;
|
|
3
|
-
var logLevel = config.logLevel || 'warning';
|
|
4
|
-
if (config.hasOwnProperty('logger')) {
|
|
5
|
-
this.logger = config.logger;
|
|
6
|
-
} else {
|
|
7
|
-
this.logger = new ConsoleLogger();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
this.verbose = function(msg) {
|
|
11
|
-
if (logLevel !== 'none') {
|
|
12
|
-
if (self.logger.verbose && logLevel === 'verbose') {
|
|
13
|
-
self.logger.verbose(msg);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
this.warning = function(msg) {
|
|
19
|
-
if (logLevel !== 'none') {
|
|
20
|
-
if (
|
|
21
|
-
self.logger.warning &&
|
|
22
|
-
(logLevel === 'verbose' || logLevel === 'warning')
|
|
23
|
-
) {
|
|
24
|
-
self.logger.warning(msg);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
this.error = function(msg) {
|
|
30
|
-
if (logLevel !== 'none') {
|
|
31
|
-
if (self.logger.error) {
|
|
32
|
-
self.logger.error(msg);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
this.setLogLevel = function(newLogLevel) {
|
|
38
|
-
logLevel = newLogLevel;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function ConsoleLogger() {
|
|
43
|
-
this.verbose = function(msg) {
|
|
44
|
-
if (console && console.info) {
|
|
45
|
-
console.info(msg);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
this.error = function(msg) {
|
|
50
|
-
if (console && console.error) {
|
|
51
|
-
console.error(msg);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
this.warning = function(msg) {
|
|
55
|
-
if (console && console.warn) {
|
|
56
|
-
console.warn(msg);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export default Logger;
|