@mparticle/web-sdk 2.57.0 → 2.58.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.
@@ -0,0 +1,32 @@
1
+ import { valueof } from '../utils';
2
+
3
+ export const ErrorCodes = {
4
+ UNKNOWN_ERROR: 'UNKNOWN_ERROR',
5
+ UNHANDLED_EXCEPTION: 'UNHANDLED_EXCEPTION',
6
+ IDENTITY_REQUEST: 'IDENTITY_REQUEST',
7
+ } as const;
8
+
9
+ export type ErrorCodes = valueof<typeof ErrorCodes>;
10
+
11
+ export type ErrorCode = ErrorCodes | string;
12
+
13
+ export const WSDKErrorSeverity = {
14
+ ERROR: 'ERROR',
15
+ INFO: 'INFO',
16
+ WARNING: 'WARNING',
17
+ } as const;
18
+
19
+ export type WSDKErrorSeverity = (typeof WSDKErrorSeverity)[keyof typeof WSDKErrorSeverity];
20
+
21
+ export type ErrorsRequestBody = {
22
+ additionalInformation?: Record<string, string>;
23
+ code: ErrorCode;
24
+ severity: WSDKErrorSeverity;
25
+ stackTrace?: string;
26
+ deviceInfo?: string;
27
+ integration?: string;
28
+ reporter?: string;
29
+ url?: string;
30
+ };
31
+
32
+ export type LogRequestBody = ErrorsRequestBody;
@@ -52,6 +52,7 @@ import ForegroundTimer from './foregroundTimeTracker';
52
52
  import RoktManager, { IRoktOptions } from './roktManager';
53
53
  import filteredMparticleUser from './filteredMparticleUser';
54
54
  import CookieConsentManager, { ICookieConsentManager } from './cookieConsentManager';
55
+ import { ReportingLogger } from './logging/reportingLogger';
55
56
 
56
57
  export interface IErrorLogMessage {
57
58
  message?: string;
@@ -84,14 +85,16 @@ export interface IMParticleWebSDKInstance extends MParticleWebSDK {
84
85
  _NativeSdkHelpers: INativeSdkHelpers;
85
86
  _Persistence: IPersistence;
86
87
  _CookieConsentManager: ICookieConsentManager;
88
+ _ReportingLogger: ReportingLogger;
87
89
  _RoktManager: RoktManager;
88
90
  _SessionManager: ISessionManager;
89
91
  _ServerModel: IServerModel;
90
92
  _Store: IStore;
91
93
  _instanceName: string;
92
94
  _preInit: IPreInit;
93
- _timeOnSiteTimer: ForegroundTimer;
95
+ _timeOnSiteTimer: ForegroundTimer;
94
96
  setLauncherInstanceGuid: () => void;
97
+ getLauncherInstanceGuid: () => string;
95
98
  captureTiming(metricName: string);
96
99
  processQueueOnIdentityFailure?: () => void;
97
100
  }
@@ -245,12 +248,14 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
245
248
  }
246
249
  };
247
250
 
248
- this._resetForTests = function(config, keepPersistence, instance) {
251
+ this._resetForTests = function(config, keepPersistence, instance, reportingLogger?: ReportingLogger) {
249
252
  if (instance._Store) {
250
253
  delete instance._Store;
251
254
  }
252
- instance.Logger = new Logger(config);
255
+ instance.Logger = new Logger(config, reportingLogger);
253
256
  instance._Store = new Store(config, instance);
257
+ // Update ReportingLogger with the new Store reference to avoid stale data
258
+ reportingLogger?.setStore(instance._Store);
254
259
  instance._Store.isLocalStorageAvailable = instance._Persistence.determineLocalStorageAvailability(
255
260
  window.localStorage
256
261
  );
@@ -1372,7 +1377,7 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
1372
1377
  };
1373
1378
  }
1374
1379
  };
1375
-
1380
+
1376
1381
  const launcherInstanceGuidKey = Constants.Rokt.LauncherInstanceGuidKey;
1377
1382
  this.setLauncherInstanceGuid = function() {
1378
1383
  if (!window[launcherInstanceGuidKey]
@@ -1381,6 +1386,10 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
1381
1386
  }
1382
1387
  };
1383
1388
 
1389
+ this.getLauncherInstanceGuid = function() {
1390
+ return window[launcherInstanceGuidKey];
1391
+ };
1392
+
1384
1393
  this.captureTiming = function(metricsName) {
1385
1394
  if (typeof window !== 'undefined' && window.performance?.mark) {
1386
1395
  window.performance.mark(metricsName);
@@ -1446,6 +1455,8 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
1446
1455
  // Configure Rokt Manager with user and filtered user
1447
1456
  const roktConfig: IKitConfigs = parseConfig(config, 'Rokt', 181);
1448
1457
  if (roktConfig) {
1458
+ const accountId = roktConfig.settings?.accountId;
1459
+ mpInstance._Store.setRoktAccountId(accountId);
1449
1460
  const { userAttributeFilters } = roktConfig;
1450
1461
  const roktFilteredUser = filteredMparticleUser(
1451
1462
  currentUserMPID,
@@ -1579,9 +1590,16 @@ function createIdentityCache(mpInstance) {
1579
1590
  }
1580
1591
 
1581
1592
  function runPreConfigFetchInitialization(mpInstance, apiKey, config) {
1582
- mpInstance.Logger = new Logger(config);
1593
+ mpInstance._ReportingLogger = new ReportingLogger(
1594
+ config,
1595
+ Constants.sdkVersion,
1596
+ undefined,
1597
+ mpInstance.getLauncherInstanceGuid(),
1598
+ );
1599
+ mpInstance.Logger = new Logger(config, mpInstance._ReportingLogger);
1583
1600
  mpInstance._Store = new Store(config, mpInstance, apiKey);
1584
1601
  window.mParticle.Store = mpInstance._Store;
1602
+ mpInstance._ReportingLogger.setStore(mpInstance._Store);
1585
1603
  mpInstance.Logger.verbose(StartingInitialization);
1586
1604
 
1587
1605
  // Initialize CookieConsentManager with privacy flags from launcherOptions
@@ -59,6 +59,12 @@ export interface RoktKitFilterSettings {
59
59
  filteredUser?: IMParticleUser | null;
60
60
  }
61
61
 
62
+ export interface IRoktKitSettings {
63
+ accountId?: string;
64
+ placementAttributesMapping?: string;
65
+ hashedEmailUserIdentityType?: string;
66
+ }
67
+
62
68
  export interface IRoktKit {
63
69
  filters: RoktKitFilterSettings;
64
70
  filteredUser: IMParticleUser | null;
@@ -69,6 +75,8 @@ export interface IRoktKit {
69
75
  setExtensionData<T>(extensionData: IRoktPartnerExtensionData<T>): void;
70
76
  use: <T>(name: string) => Promise<T>;
71
77
  launcherOptions?: Dictionary<any>;
78
+ settings?: IRoktKitSettings;
79
+ integrationName?: string;
72
80
  }
73
81
 
74
82
  export interface IRoktOptions {
@@ -181,6 +189,15 @@ export default class RoktManager {
181
189
 
182
190
  public attachKit(kit: IRoktKit): void {
183
191
  this.kit = kit;
192
+
193
+ if (kit.settings?.accountId) {
194
+ this.store.setRoktAccountId(kit.settings.accountId);
195
+ }
196
+
197
+ if (kit.integrationName) {
198
+ this.store?.setIntegrationName(kit.integrationName);
199
+ }
200
+
184
201
  this.processMessageQueue();
185
202
 
186
203
  try {
@@ -588,4 +605,4 @@ export default class RoktManager {
588
605
 
589
606
  return false; // Values are the same
590
607
  }
591
- }
608
+ }
@@ -7,18 +7,24 @@ import {
7
7
  SDKEventAttrs,
8
8
  Callback,
9
9
  } from '@mparticle/web-sdk';
10
- import { IntegrationAttribute, IntegrationAttributes, IStore, WrapperSDKTypes } from './store';
10
+ import {
11
+ IntegrationAttribute,
12
+ IntegrationAttributes,
13
+ IStore,
14
+ WrapperSDKTypes,
15
+ } from './store';
11
16
  import Validators from './validators';
12
17
  import { Dictionary, valueof } from './utils';
13
18
  import { IKitConfigs } from './configAPIClient';
14
19
  import { SDKConsentApi, SDKConsentState } from './consent';
15
20
  import MPSideloadedKit from './sideloadedKit';
16
21
  import { ISessionManager } from './sessionManager';
17
- import { ConfiguredKit, MPForwarder, UnregisteredKit } from './forwarders.interfaces';
18
22
  import {
19
- SDKIdentityApi,
20
- IAliasCallback,
21
- } from './identity.interfaces';
23
+ ConfiguredKit,
24
+ MPForwarder,
25
+ UnregisteredKit,
26
+ } from './forwarders.interfaces';
27
+ import { SDKIdentityApi, IAliasCallback } from './identity.interfaces';
22
28
  import {
23
29
  ISDKUserAttributeChangeData,
24
30
  ISDKUserIdentityChanges,
@@ -36,11 +42,16 @@ import {
36
42
  } from './types';
37
43
  import { IPixelConfiguration } from './cookieSyncManager';
38
44
  import _BatchValidator from './mockBatchCreator';
39
- import { SDKECommerceAPI } from './ecommerce.interfaces';
40
- import { IErrorLogMessage, IMParticleWebSDKInstance, IntegrationDelays } from './mp-instance';
45
+ import { SDKECommerceAPI } from './ecommerce.interfaces';
46
+ import {
47
+ IErrorLogMessage,
48
+ IMParticleWebSDKInstance,
49
+ IntegrationDelays,
50
+ } from './mp-instance';
41
51
  import Constants from './constants';
42
52
  import RoktManager, { IRoktLauncherOptions } from './roktManager';
43
53
  import { IConsoleLogger } from './logger';
54
+ import { ErrorCodes } from './logging/types';
44
55
 
45
56
  // TODO: Resolve this with version in @mparticle/web-sdk
46
57
  export type SDKEventCustomFlags = Dictionary<any>;
@@ -178,7 +189,7 @@ export interface MParticleWebSDK {
178
189
  _resetForTests(
179
190
  MPConfig?: SDKInitConfig,
180
191
  keepPersistence?: boolean,
181
- instance?: IMParticleWebSDKInstance,
192
+ instance?: IMParticleWebSDKInstance
182
193
  ): void;
183
194
  configurePixel(config: IPixelConfiguration): void;
184
195
  endSession(): void;
@@ -207,9 +218,24 @@ export interface MParticleWebSDK {
207
218
  ): void;
208
219
  logBaseEvent(event: BaseEvent, eventOptions?: SDKEventOptions): void;
209
220
  logError(error: IErrorLogMessage, attrs?: SDKEventAttrs): void;
210
- logLink(selector: string, eventName: string, eventType: valueof<typeof EventType>, eventInfo: SDKEventAttrs): void;
211
- logForm(selector: string, eventName: string, eventType: valueof<typeof EventType>, eventInfo: SDKEventAttrs): void;
212
- logPageView(eventName?: string, attrs?: SDKEventAttrs, customFlags?: SDKEventCustomFlags, eventOptions?: SDKEventOptions): void;
221
+ logLink(
222
+ selector: string,
223
+ eventName: string,
224
+ eventType: valueof<typeof EventType>,
225
+ eventInfo: SDKEventAttrs
226
+ ): void;
227
+ logForm(
228
+ selector: string,
229
+ eventName: string,
230
+ eventType: valueof<typeof EventType>,
231
+ eventInfo: SDKEventAttrs
232
+ ): void;
233
+ logPageView(
234
+ eventName?: string,
235
+ attrs?: SDKEventAttrs,
236
+ customFlags?: SDKEventCustomFlags,
237
+ eventOptions?: SDKEventOptions
238
+ ): void;
213
239
  setOptOut(isOptingOut: boolean): void;
214
240
  eCommerce: SDKECommerceAPI;
215
241
  isInitialized(): boolean;
@@ -227,7 +253,10 @@ export interface MParticleWebSDK {
227
253
 
228
254
  stopTrackingLocation(): void;
229
255
  generateHash(value: string): string;
230
- setIntegrationAttribute(integrationModuleId: number, attrs: IntegrationAttribute): void;
256
+ setIntegrationAttribute(
257
+ integrationModuleId: number,
258
+ attrs: IntegrationAttribute
259
+ ): void;
231
260
  getIntegrationAttributes(integrationModuleId: number): IntegrationAttribute;
232
261
  captureTiming(metricName: string): void;
233
262
  }
@@ -248,14 +277,13 @@ export interface IMParticleInstanceManager extends MParticleWebSDK {
248
277
  MPSideloadedKit: typeof MPSideloadedKit;
249
278
  Rokt: RoktManager;
250
279
  // https://go.mparticle.com/work/SQDSDKS-7060
251
- sessionManager: Pick<ISessionManager, 'getSession'>;
280
+ sessionManager: Pick<ISessionManager, 'getSession'>;
252
281
  Store: IStore;
253
282
 
254
283
  // Public Methods
255
284
  getInstance(instanceName?: string): IMParticleWebSDKInstance;
256
285
  }
257
286
 
258
-
259
287
  // Used in cases where server requires booleans as strings
260
288
  export type BooleanStringLowerCase = 'false' | 'true';
261
289
  export type BooleanStringTitleCase = 'False' | 'True';
@@ -311,6 +339,7 @@ export interface SDKInitConfig
311
339
  identityCallback?: IdentityCallback;
312
340
 
313
341
  launcherOptions?: IRoktLauncherOptions;
342
+ isLoggingEnabled?: boolean;
314
343
 
315
344
  rq?: Function[] | any[];
316
345
  logger?: IConsoleLogger;
@@ -361,9 +390,9 @@ export interface SDKHelpersApi {
361
390
  }
362
391
 
363
392
  export interface SDKLoggerApi {
364
- error(arg0: string): void;
365
- verbose(arg0: string): void;
366
- warning(arg0: string): void;
393
+ error(msg: string, code?: ErrorCodes): void;
394
+ verbose(msg: string): void;
395
+ warning(msg: string): void;
367
396
  setLogLevel(logLevel: LogLevelType): void;
368
397
  }
369
398
 
package/src/store.ts CHANGED
@@ -96,6 +96,9 @@ export interface SDKConfig {
96
96
  webviewBridgeName?: string;
97
97
  workspaceToken?: string;
98
98
  requiredWebviewBridgeName?: string;
99
+ loggingUrl?: string;
100
+ errorUrl?: string;
101
+ isLoggingEnabled?: boolean;
99
102
  }
100
103
 
101
104
  function createSDKConfig(config: SDKInitConfig): SDKConfig {
@@ -120,6 +123,9 @@ function createSDKConfig(config: SDKInitConfig): SDKConfig {
120
123
  sdkConfig[prop] = Constants.DefaultBaseUrls[prop];
121
124
  }
122
125
 
126
+ // Always initialize flags to at least an empty object to prevent undefined access
127
+ sdkConfig.flags = sdkConfig.flags || {};
128
+
123
129
  return sdkConfig;
124
130
  }
125
131
 
@@ -202,6 +208,8 @@ export interface IStore {
202
208
  integrationDelayTimeoutStart: number; // UNIX Timestamp
203
209
  webviewBridgeEnabled?: boolean;
204
210
  wrapperSDKInfo: WrapperSDKInfo;
211
+ roktAccountId: string | null;
212
+ integrationName: string | null;
205
213
 
206
214
  persistenceData?: IPersistenceMinified;
207
215
 
@@ -223,6 +231,10 @@ export interface IStore {
223
231
  setUserAttributes?(mpid: MPID, attributes: UserAttributes): void;
224
232
  getUserIdentities?(mpid: MPID): UserIdentities;
225
233
  setUserIdentities?(mpid: MPID, userIdentities: UserIdentities): void;
234
+ getRoktAccountId?(): string;
235
+ setRoktAccountId?(accountId: string): void;
236
+ getIntegrationName?(): string;
237
+ setIntegrationName?(integrationName: string): void;
226
238
 
227
239
  addMpidToSessionHistory?(mpid: MPID, previousMpid?: MPID): void;
228
240
  hasInvalidIdentifyRequest?: () => boolean;
@@ -289,6 +301,8 @@ export default function Store(
289
301
  version: null,
290
302
  isInfoSet: false,
291
303
  },
304
+ roktAccountId: null,
305
+ integrationName: null,
292
306
 
293
307
  // Placeholder for in-memory persistence model
294
308
  persistenceData: {
@@ -311,10 +325,6 @@ export default function Store(
311
325
  this.SDKConfig.flags = {};
312
326
  }
313
327
 
314
- // We process the initial config that is passed via the SDK init
315
- // and then we will reprocess the config within the processConfig
316
- // function when the config is updated from the server
317
- // https://go.mparticle.com/work/SQDSDKS-6317
318
328
  this.SDKConfig.flags = processFlags(config);
319
329
 
320
330
  if (config.deviceId) {
@@ -338,10 +348,6 @@ export default function Store(
338
348
  this.SDKConfig[baseUrlKeys] = baseUrls[baseUrlKeys];
339
349
  }
340
350
 
341
- if (config.hasOwnProperty('logLevel')) {
342
- this.SDKConfig.logLevel = config.logLevel;
343
- }
344
-
345
351
  this.SDKConfig.useNativeSdk = !!config.useNativeSdk;
346
352
 
347
353
  this.SDKConfig.kits = config.kits || {};
@@ -667,6 +673,16 @@ export default function Store(
667
673
  this.setUserIdentities = (mpid: MPID, userIdentities: UserIdentities) => {
668
674
  this._setPersistence(mpid, 'ui', userIdentities);
669
675
  };
676
+
677
+ this.getRoktAccountId = () => this.roktAccountId;
678
+ this.setRoktAccountId = (accountId: string) => {
679
+ this.roktAccountId = accountId;
680
+ };
681
+
682
+ this.getIntegrationName = () => this.integrationName;
683
+ this.setIntegrationName = (integrationName: string) => {
684
+ this.integrationName = integrationName;
685
+ };
670
686
 
671
687
  this.addMpidToSessionHistory = (mpid: MPID, previousMPID?: MPID): void => {
672
688
  const indexOfMPID = this.currentSessionMPIDs.indexOf(mpid);
@@ -699,7 +715,10 @@ export default function Store(
699
715
  // We should reprocess the flags and baseUrls in case they have changed when we request an updated config
700
716
  // such as if the SDK is being self-hosted and the flags are different on the server config
701
717
  // https://go.mparticle.com/work/SQDSDKS-6317
702
- this.SDKConfig.flags = processFlags(config);
718
+ // Only update flags if the config actually has flags (don't overwrite with empty object)
719
+ if (config.flags) {
720
+ this.SDKConfig.flags = processFlags(config);
721
+ }
703
722
 
704
723
  const baseUrls: Dictionary<string> = processBaseUrls(
705
724
  config,
@@ -842,7 +861,7 @@ function processDirectBaseUrls(
842
861
  for (let baseUrlKey in defaultBaseUrls) {
843
862
  // Any custom endpoints passed to mpConfig will take priority over direct
844
863
  // mapping to the silo. The most common use case is a customer provided CNAME.
845
- if (baseUrlKey === 'configUrl') {
864
+ if (baseUrlKey === 'configUrl' || baseUrlKey === 'loggingUrl' || baseUrlKey === 'errorUrl') {
846
865
  directBaseUrls[baseUrlKey] =
847
866
  config[baseUrlKey] || defaultBaseUrls[baseUrlKey];
848
867
  continue;
package/src/uploaders.ts CHANGED
@@ -5,6 +5,7 @@ export interface IFetchPayload {
5
5
  headers: {
6
6
  Accept: string;
7
7
  'Content-Type'?: string;
8
+ 'rokt-account-id'?: string;
8
9
  };
9
10
  body?: string;
10
11
  }