@mparticle/web-sdk 2.73.0 → 2.74.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.
@@ -10,6 +10,7 @@ import {
10
10
  AttributeValue,
11
11
  isEmpty,
12
12
  obfuscateDevData,
13
+ getErrorMessage,
13
14
  } from "./utils";
14
15
  import { SDKIdentityApi } from "./identity.interfaces";
15
16
  import { SDKLoggerApi } from "./sdkRuntimeModels";
@@ -338,8 +339,10 @@ export default class RoktManager {
338
339
  }
339
340
  );
340
341
  } catch (error) {
341
- const errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
342
- this.logger.error('Background identify threw an error: ' + errorMessage);
342
+ this.logger.error(
343
+ 'Background identify threw an error: ' +
344
+ getErrorMessage(error)
345
+ );
343
346
  }
344
347
  }
345
348
 
@@ -437,8 +440,9 @@ export default class RoktManager {
437
440
  return hashedAttributes;
438
441
 
439
442
  } catch (error) {
440
- const errorMessage = error instanceof Error ? error.message : String(error);
441
- this.logger.error(`Failed to hashAttributes, returning an empty object: ${errorMessage}`);
443
+ this.logger.error(
444
+ `Failed to hashAttributes, returning an empty object: ${getErrorMessage(error)}`
445
+ );
442
446
  return {};
443
447
  }
444
448
  }
@@ -452,8 +456,9 @@ export default class RoktManager {
452
456
  try {
453
457
  this.kit.setExtensionData<T>(extensionData);
454
458
  } catch (error) {
455
- const errorMessage = error instanceof Error ? error.message : String(error);
456
- throw new Error('Error setting extension data: ' + errorMessage);
459
+ throw new Error(
460
+ 'Error setting extension data: ' + getErrorMessage(error)
461
+ );
457
462
  }
458
463
  }
459
464
 
@@ -478,8 +483,9 @@ export default class RoktManager {
478
483
  try {
479
484
  this.kit.onShoppableAdsReady(callback);
480
485
  } catch (error) {
481
- const errorMessage = error instanceof Error ? error.message : String(error);
482
- this.logger.error(`Failed to register onShoppableAdsReady callback: ${errorMessage}`);
486
+ this.logger.error(
487
+ `Failed to register onShoppableAdsReady callback: ${getErrorMessage(error)}`
488
+ );
483
489
  }
484
490
  }
485
491
 
@@ -517,8 +523,9 @@ export default class RoktManager {
517
523
  const normalizedValue = String(attribute).trim().toLocaleLowerCase();
518
524
  return await this.sha256Hex(normalizedValue);
519
525
  } catch (error) {
520
- const errorMessage = error instanceof Error ? error.message : String(error);
521
- this.logger.error(`Failed to hashSha256, returning undefined: ${errorMessage}`);
526
+ this.logger.error(
527
+ `Failed to hashSha256, returning undefined: ${getErrorMessage(error)}`
528
+ );
522
529
  return undefined;
523
530
  }
524
531
  }
@@ -607,8 +614,9 @@ export default class RoktManager {
607
614
  const reject = message.reject;
608
615
 
609
616
  const handleError = (error: unknown) => {
610
- const errorMessage = error instanceof Error ? error.message : String(error);
611
- this.logger?.error(`RoktManager: Error processing message '${message.methodName}': ${errorMessage}`);
617
+ this.logger?.error(
618
+ `RoktManager: Error processing message '${message.methodName}': ${getErrorMessage(error)}`
619
+ );
612
620
  if (reject) {
613
621
  reject(error);
614
622
  }
package/src/store.ts CHANGED
@@ -151,6 +151,7 @@ export interface IFeatureFlags {
151
151
  captureIntegrationSpecificIds?: boolean;
152
152
  'captureIntegrationSpecificIds.V2'?: string;
153
153
  astBackgroundEvents?: boolean;
154
+ autoLogPageView?: boolean;
154
155
  }
155
156
 
156
157
  // Temporary Interface until Store can be refactored as a class
@@ -766,7 +767,8 @@ export function processFlags(config: SDKInitConfig): IFeatureFlags {
766
767
  AudienceAPI,
767
768
  CaptureIntegrationSpecificIds,
768
769
  CaptureIntegrationSpecificIdsV2,
769
- AstBackgroundEvents
770
+ AstBackgroundEvents,
771
+ AutoLogPageView
770
772
  } = Constants.FeatureFlags;
771
773
 
772
774
  if (!config.flags) {
@@ -787,6 +789,7 @@ export function processFlags(config: SDKInitConfig): IFeatureFlags {
787
789
  flags[CaptureIntegrationSpecificIds] = config.flags[CaptureIntegrationSpecificIds] === 'True';
788
790
  flags[CaptureIntegrationSpecificIdsV2] = (config.flags[CaptureIntegrationSpecificIdsV2] || 'none');
789
791
  flags[AstBackgroundEvents] = config.flags[AstBackgroundEvents] === 'True';
792
+ flags[AutoLogPageView] = config.flags[AutoLogPageView] === 'True';
790
793
  return flags;
791
794
  }
792
795
 
package/src/utils.ts CHANGED
@@ -625,6 +625,27 @@ function extend(...args: any[]): any {
625
625
  return target;
626
626
  }
627
627
 
628
+ const getErrorMessage = (
629
+ e: unknown,
630
+ fallback = 'unknown error'
631
+ ): string => {
632
+ if (e instanceof Error) {
633
+ return e.message;
634
+ }
635
+ if (typeof e === 'string') {
636
+ return e;
637
+ }
638
+ // fetch-mock and some network libs reject with { message } rather than Error
639
+ if (
640
+ e &&
641
+ typeof e === 'object' &&
642
+ typeof (e as { message?: unknown }).message === 'string'
643
+ ) {
644
+ return (e as { message: string }).message;
645
+ }
646
+ return fallback;
647
+ };
648
+
628
649
  export {
629
650
  createCookieString,
630
651
  revertCookieString,
@@ -639,6 +660,7 @@ export {
639
660
  generateDeprecationMessage,
640
661
  generateHash,
641
662
  generateUniqueId,
663
+ getErrorMessage,
642
664
  getRampNumber,
643
665
  inArray,
644
666
  isObject,