@mparticle/web-sdk 2.60.0 → 2.61.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.
@@ -52,7 +52,9 @@ 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
+ import { ErrorReportingDispatcher } from './reporting/errorReportingDispatcher';
56
+ import { LoggingDispatcher } from './reporting/loggingDispatcher';
57
+ import { IErrorReportingService, ILoggingService } from './reporting/types';
56
58
 
57
59
  export interface IErrorLogMessage {
58
60
  message?: string;
@@ -85,7 +87,8 @@ export interface IMParticleWebSDKInstance extends MParticleWebSDK {
85
87
  _NativeSdkHelpers: INativeSdkHelpers;
86
88
  _Persistence: IPersistence;
87
89
  _CookieConsentManager: ICookieConsentManager;
88
- _ReportingLogger: ReportingLogger;
90
+ _ErrorReportingDispatcher: ErrorReportingDispatcher;
91
+ _LoggingDispatcher: LoggingDispatcher;
89
92
  _RoktManager: RoktManager;
90
93
  _SessionManager: ISessionManager;
91
94
  _ServerModel: IServerModel;
@@ -138,6 +141,9 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
138
141
  forwarderConstructors: [],
139
142
  };
140
143
 
144
+ this._ErrorReportingDispatcher = new ErrorReportingDispatcher();
145
+ this._LoggingDispatcher = new LoggingDispatcher();
146
+
141
147
  this._RoktManager = new RoktManager();
142
148
 
143
149
  this._RoktManager.setOnReadyCallback(() => {
@@ -266,14 +272,16 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
266
272
  }
267
273
  };
268
274
 
269
- this._resetForTests = function(config, keepPersistence, instance, reportingLogger?: ReportingLogger) {
275
+ this._resetForTests = function(config, keepPersistence, instance) {
270
276
  if (instance._Store) {
271
277
  delete instance._Store;
272
278
  }
273
- instance.Logger = new Logger(config, reportingLogger);
279
+ instance._ErrorReportingDispatcher = new ErrorReportingDispatcher();
280
+ instance._LoggingDispatcher = new LoggingDispatcher();
281
+ instance.Logger = new Logger(config);
282
+ instance._ErrorReportingDispatcher.logger = instance.Logger;
283
+ instance._LoggingDispatcher.logger = instance.Logger;
274
284
  instance._Store = new Store(config, instance);
275
- // Update ReportingLogger with the new Store reference to avoid stale data
276
- reportingLogger?.setStore(instance._Store);
277
285
  instance._Store.isLocalStorageAvailable = instance._Persistence.determineLocalStorageAvailability(
278
286
  window.localStorage
279
287
  );
@@ -1406,6 +1414,14 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
1406
1414
  }
1407
1415
  };
1408
1416
 
1417
+ this._registerErrorReportingService = function(service: IErrorReportingService) {
1418
+ self._ErrorReportingDispatcher.register(service);
1419
+ };
1420
+
1421
+ this._registerLoggingService = function(service: ILoggingService) {
1422
+ self._LoggingDispatcher.register(service);
1423
+ };
1424
+
1409
1425
  const launcherInstanceGuidKey = Constants.Rokt.LauncherInstanceGuidKey;
1410
1426
  this.setLauncherInstanceGuid = function() {
1411
1427
  if (!window[launcherInstanceGuidKey]
@@ -1504,7 +1520,9 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
1504
1520
  mpInstance._Store,
1505
1521
  mpInstance.Logger,
1506
1522
  roktOptions,
1507
- mpInstance.captureTiming
1523
+ mpInstance.captureTiming,
1524
+ mpInstance._ErrorReportingDispatcher,
1525
+ mpInstance._LoggingDispatcher
1508
1526
  );
1509
1527
  }
1510
1528
 
@@ -1626,16 +1644,11 @@ function createIdentityCache(mpInstance) {
1626
1644
  }
1627
1645
 
1628
1646
  function runPreConfigFetchInitialization(mpInstance, apiKey, config) {
1629
- mpInstance._ReportingLogger = new ReportingLogger(
1630
- config,
1631
- Constants.sdkVersion,
1632
- undefined,
1633
- mpInstance.getLauncherInstanceGuid(),
1634
- );
1635
- mpInstance.Logger = new Logger(config, mpInstance._ReportingLogger);
1647
+ mpInstance.Logger = new Logger(config);
1648
+ mpInstance._ErrorReportingDispatcher.logger = mpInstance.Logger;
1649
+ mpInstance._LoggingDispatcher.logger = mpInstance.Logger;
1636
1650
  mpInstance._Store = new Store(config, mpInstance, apiKey);
1637
1651
  window.mParticle.Store = mpInstance._Store;
1638
- mpInstance._ReportingLogger.setStore(mpInstance._Store);
1639
1652
  mpInstance.Logger.verbose(StartingInitialization);
1640
1653
 
1641
1654
  // Initialize CookieConsentManager with privacy flags from launcherOptions
@@ -398,7 +398,7 @@ function mParticleInstanceManager(this: IMParticleInstanceManager) {
398
398
 
399
399
  this.sessionManager = {
400
400
  getSession: function() {
401
- return self.getInstance()._SessionManager.getSession();
401
+ return self.getInstance()._SessionManager.getSessionId();
402
402
  },
403
403
  };
404
404
 
@@ -487,6 +487,12 @@ function mParticleInstanceManager(this: IMParticleInstanceManager) {
487
487
  this._setWrapperSDKInfo = function(name, version) {
488
488
  self.getInstance()._setWrapperSDKInfo(name, version);
489
489
  };
490
+ this._registerErrorReportingService = function(service) {
491
+ self.getInstance()._registerErrorReportingService(service);
492
+ };
493
+ this._registerLoggingService = function(service) {
494
+ self.getInstance()._registerLoggingService(service);
495
+ };
490
496
  }
491
497
 
492
498
  const mParticleManager = new mParticleInstanceManager();
@@ -0,0 +1,21 @@
1
+ import { SDKLoggerApi } from '../sdkRuntimeModels';
2
+ import { IErrorReportingService, ISDKError } from './types';
3
+
4
+ export class ErrorReportingDispatcher implements IErrorReportingService {
5
+ private readonly services: IErrorReportingService[] = [];
6
+ public logger?: SDKLoggerApi;
7
+
8
+ public register(service: IErrorReportingService): void {
9
+ this.services.push(service);
10
+ }
11
+
12
+ public report(error: ISDKError): void {
13
+ this.services.forEach(s => {
14
+ try {
15
+ s.report(error);
16
+ } catch (e) {
17
+ this.logger?.error('Error in ErrorReportingService: ' + e);
18
+ }
19
+ });
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import { SDKLoggerApi } from '../sdkRuntimeModels';
2
+ import { ILoggingService, ISDKLogEntry } from './types';
3
+
4
+ export class LoggingDispatcher implements ILoggingService {
5
+ private readonly services: ILoggingService[] = [];
6
+ public logger?: SDKLoggerApi;
7
+
8
+ public register(service: ILoggingService): void {
9
+ this.services.push(service);
10
+ }
11
+
12
+ public log(entry: ISDKLogEntry): void {
13
+ this.services.forEach(s => {
14
+ try {
15
+ s.log(entry);
16
+ } catch (e) {
17
+ this.logger?.error('Error in LoggingService: ' + e);
18
+ }
19
+ });
20
+ }
21
+ }
@@ -0,0 +1,45 @@
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
+ IDENTITY_MISMATCH: 'IDENTITY_MISMATCH',
8
+ ROKT_KIT_ATTACHED: 'ROKT_KIT_ATTACHED',
9
+ } as const;
10
+
11
+ export type ErrorCodes = valueof<typeof ErrorCodes>;
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
+ /** Structured error object for reporting. */
22
+ export interface ISDKError {
23
+ message: string;
24
+ code?: ErrorCodes;
25
+ severity: WSDKErrorSeverity;
26
+ stackTrace?: string;
27
+ additionalInformation?: Record<string, string>;
28
+ }
29
+
30
+ /** Structured log entry for informational logging. */
31
+ export interface ISDKLogEntry {
32
+ message: string;
33
+ code?: ErrorCodes;
34
+ additionalInformation?: Record<string, string>;
35
+ }
36
+
37
+ /** Contract for error/warning reporting services. */
38
+ export interface IErrorReportingService {
39
+ report(error: ISDKError): void;
40
+ }
41
+
42
+ /** Contract for informational logging services. */
43
+ export interface ILoggingService {
44
+ log(entry: ISDKLogEntry): void;
45
+ }
@@ -16,6 +16,7 @@ import { SDKLoggerApi } from "./sdkRuntimeModels";
16
16
  import { IStore, LocalSessionAttributes } from "./store";
17
17
  import { UserIdentities } from "@mparticle/web-sdk";
18
18
  import { IdentityType, PerformanceMarkType } from "./types";
19
+ import { ErrorCodes, IErrorReportingService, ILoggingService, WSDKErrorSeverity } from "./reporting/types";
19
20
 
20
21
  // https://docs.rokt.com/developers/integration-guides/web/library/attributes
21
22
  export type RoktAttributeValueArray = Array<string | number | boolean>;
@@ -108,6 +109,8 @@ export default class RoktManager {
108
109
  private store: IStore;
109
110
  private launcherOptions?: IRoktLauncherOptions;
110
111
  private logger: SDKLoggerApi;
112
+ private errorReporter: IErrorReportingService;
113
+ private loggingService: ILoggingService;
111
114
  private domain?: string;
112
115
  private mappedEmailShaIdentityType?: string | null;
113
116
  private captureTiming?: (metricsName: string) => void;
@@ -130,17 +133,21 @@ export default class RoktManager {
130
133
  * @param {SDKLoggerApi} logger - The mParticle Logger instance
131
134
  * @param {IRoktOptions} options - Options for the RoktManager
132
135
  * @param {Function} captureTiming - Function to capture performance timing marks
133
- *
136
+ * @param {IErrorReportingService} errorReporter - Dispatcher for error/warning reporting
137
+ * @param {ILoggingService} loggingService - Dispatcher for informational logging
138
+ *
134
139
  * @throws Logs error to console if placementAttributesMapping parsing fails
135
140
  */
136
141
  public init(
137
- roktConfig: IKitConfigs,
138
- filteredUser: IMParticleUser,
142
+ roktConfig: IKitConfigs,
143
+ filteredUser: IMParticleUser,
139
144
  identityService: SDKIdentityApi,
140
145
  store: IStore,
141
146
  logger?: SDKLoggerApi,
142
147
  options?: IRoktOptions,
143
- captureTiming?: (metricsName: string) => void
148
+ captureTiming?: (metricsName: string) => void,
149
+ errorReporter?: IErrorReportingService,
150
+ loggingService?: ILoggingService
144
151
  ): void {
145
152
  const { userAttributeFilters, settings } = roktConfig || {};
146
153
  const { placementAttributesMapping, hashedEmailUserIdentityType } = settings || {};
@@ -149,6 +156,8 @@ export default class RoktManager {
149
156
  this.identityService = identityService;
150
157
  this.store = store;
151
158
  this.logger = logger;
159
+ this.errorReporter = errorReporter;
160
+ this.loggingService = loggingService;
152
161
  this.captureTiming = captureTiming;
153
162
 
154
163
  this.captureTiming?.(PerformanceMarkType.JointSdkRoktKitInit);
@@ -199,6 +208,11 @@ export default class RoktManager {
199
208
  this.store?.setIntegrationName(kit.integrationName);
200
209
  }
201
210
 
211
+ this.loggingService?.log({
212
+ message: 'RoktManager: Kit attached, Rokt is ready',
213
+ code: ErrorCodes.ROKT_KIT_ATTACHED,
214
+ });
215
+
202
216
  this.processMessageQueue();
203
217
 
204
218
  try {
@@ -269,13 +283,25 @@ export default class RoktManager {
269
283
  if (emailChanged) {
270
284
  newIdentities.email = newEmail;
271
285
  if (newEmail) {
272
- this.logger.warning(`Email mismatch detected. Current email differs from email passed to selectPlacements call. Proceeding to call identify with email from selectPlacements call. Please verify your implementation.`);
286
+ const msg = 'Email mismatch detected. Current email differs from email passed to selectPlacements call. Proceeding to call identify with email from selectPlacements call. Please verify your implementation.';
287
+ this.logger.warning(msg);
288
+ this.errorReporter?.report({
289
+ message: msg,
290
+ code: ErrorCodes.IDENTITY_MISMATCH,
291
+ severity: WSDKErrorSeverity.WARNING,
292
+ });
273
293
  }
274
294
  }
275
295
 
276
296
  if (hashedEmailChanged) {
277
297
  newIdentities[this.mappedEmailShaIdentityType] = newHashedEmail;
278
- this.logger.warning(`emailsha256 mismatch detected. Current mParticle hashedEmail differs from hashedEmail passed to selectPlacements call. Proceeding to call identify with hashedEmail from selectPlacements call. Please verify your implementation.`);
298
+ const msg = 'emailsha256 mismatch detected. Current mParticle hashedEmail differs from hashedEmail passed to selectPlacements call. Proceeding to call identify with hashedEmail from selectPlacements call. Please verify your implementation.';
299
+ this.logger.warning(msg);
300
+ this.errorReporter?.report({
301
+ message: msg,
302
+ code: ErrorCodes.IDENTITY_MISMATCH,
303
+ severity: WSDKErrorSeverity.WARNING,
304
+ });
279
305
  }
280
306
 
281
307
  if (!isEmpty(newIdentities)) {
@@ -51,7 +51,7 @@ import {
51
51
  import Constants from './constants';
52
52
  import RoktManager, { IRoktLauncherOptions } from './roktManager';
53
53
  import { IConsoleLogger } from './logger';
54
- import { ErrorCodes } from './logging/types';
54
+ import { ErrorCodes, IErrorReportingService, ILoggingService } from './reporting/types';
55
55
 
56
56
  // TODO: Resolve this with version in @mparticle/web-sdk
57
57
  export type SDKEventCustomFlags = Dictionary<any>;
@@ -260,6 +260,8 @@ export interface MParticleWebSDK {
260
260
  ): void;
261
261
  getIntegrationAttributes(integrationModuleId: number): IntegrationAttribute;
262
262
  captureTiming(metricName: string): void;
263
+ _registerErrorReportingService(service: IErrorReportingService): void;
264
+ _registerLoggingService(service: ILoggingService): void;
263
265
  }
264
266
 
265
267
  // https://go.mparticle.com/work/SQDSDKS-4805
@@ -302,7 +302,7 @@ export default function ServerModel(
302
302
  // events do not have names, but are denoted by their `event_type`
303
303
  EventName:
304
304
  event.name ||
305
- ((event.messageType as unknown) as string),
305
+ String(event.messageType),
306
306
  EventCategory: event.eventType,
307
307
  EventAttributes: mpInstance._Helpers.sanitizeAttributes(
308
308
  event.data,
package/src/store.ts CHANGED
@@ -96,8 +96,6 @@ export interface SDKConfig {
96
96
  webviewBridgeName?: string;
97
97
  workspaceToken?: string;
98
98
  requiredWebviewBridgeName?: string;
99
- loggingUrl?: string;
100
- errorUrl?: string;
101
99
  isLoggingEnabled?: boolean;
102
100
  }
103
101
 
@@ -862,7 +860,7 @@ function processDirectBaseUrls(
862
860
  for (let baseUrlKey in defaultBaseUrls) {
863
861
  // Any custom endpoints passed to mpConfig will take priority over direct
864
862
  // mapping to the silo. The most common use case is a customer provided CNAME.
865
- if (baseUrlKey === 'configUrl' || baseUrlKey === 'loggingUrl' || baseUrlKey === 'errorUrl') {
863
+ if (baseUrlKey === 'configUrl') {
866
864
  directBaseUrls[baseUrlKey] =
867
865
  config[baseUrlKey] || defaultBaseUrls[baseUrlKey];
868
866
  continue;
@@ -1,192 +0,0 @@
1
- import { ErrorCodes, LogRequestBody, WSDKErrorSeverity } from "./types";
2
- import { FetchUploader, IFetchPayload } from "../uploaders";
3
- import { IStore, SDKConfig } from "../store";
4
- import { SDKInitConfig } from "../sdkRuntimeModels";
5
- import Constants from "../constants";
6
-
7
- // Header key constants
8
- const HEADER_ACCEPT = 'Accept' as const;
9
- const HEADER_CONTENT_TYPE = 'Content-Type' as const;
10
- const HEADER_ROKT_LAUNCHER_VERSION = 'rokt-launcher-version' as const;
11
- const HEADER_ROKT_LAUNCHER_INSTANCE_GUID = 'rokt-launcher-instance-guid' as const;
12
- const HEADER_ROKT_WSDK_VERSION = 'rokt-wsdk-version' as const;
13
-
14
- interface IReportingLoggerPayload extends IFetchPayload {
15
- headers: IFetchPayload['headers'] & {
16
- [HEADER_ROKT_LAUNCHER_INSTANCE_GUID]?: string;
17
- [HEADER_ROKT_LAUNCHER_VERSION]: string;
18
- [HEADER_ROKT_WSDK_VERSION]: string;
19
- };
20
- body: string;
21
- }
22
-
23
- export class ReportingLogger {
24
- private readonly isEnabled: boolean;
25
- private readonly reporter: string = 'mp-wsdk';
26
- private readonly rateLimiter: IRateLimiter;
27
- private store: IStore | null;
28
- private readonly loggingUrl: string;
29
- private readonly errorUrl: string;
30
- private readonly isLoggingEnabled: boolean;
31
-
32
- constructor(
33
- config: SDKConfig | SDKInitConfig | any,
34
- private readonly sdkVersion: string,
35
- store?: IStore,
36
- private readonly launcherInstanceGuid?: string,
37
- rateLimiter?: IRateLimiter,
38
- ) {
39
- this.loggingUrl = `https://${config.loggingUrl || Constants.DefaultBaseUrls.loggingUrl}`;
40
- this.errorUrl = `https://${config.errorUrl || Constants.DefaultBaseUrls.errorUrl}`;
41
- this.isLoggingEnabled = config.isLoggingEnabled || false;
42
- this.store = store ?? null;
43
- this.isEnabled = this.isReportingEnabled();
44
- this.rateLimiter = rateLimiter ?? new RateLimiter();
45
- }
46
-
47
- public setStore(store: IStore): void {
48
- this.store = store;
49
- }
50
-
51
- public info(msg: string, code?: ErrorCodes) {
52
- this.sendLog(WSDKErrorSeverity.INFO, msg, code);
53
- }
54
-
55
- public error(msg: string, code?: ErrorCodes, stackTrace?: string) {
56
- this.sendError(WSDKErrorSeverity.ERROR, msg, code, stackTrace);
57
- }
58
-
59
- public warning(msg: string, code?: ErrorCodes) {
60
- this.sendError(WSDKErrorSeverity.WARNING, msg, code);
61
- }
62
-
63
- private sendToServer(url: string, severity: WSDKErrorSeverity, msg: string, code?: ErrorCodes, stackTrace?: string): void {
64
- if (!this.canSendLog(severity))
65
- return;
66
-
67
- try {
68
- const logRequest = this.buildLogRequest(severity, msg, code, stackTrace);
69
- const uploader = new FetchUploader(url);
70
- const payload: IReportingLoggerPayload = {
71
- method: 'POST',
72
- headers: this.getHeaders(),
73
- body: JSON.stringify(logRequest),
74
- };
75
- uploader.upload(payload).catch((error) => {
76
- console.error('ReportingLogger: Failed to send log', error);
77
- });
78
- } catch (error) {
79
- console.error('ReportingLogger: Failed to send log', error);
80
- }
81
- }
82
-
83
- private sendLog(severity: WSDKErrorSeverity, msg: string, code?: ErrorCodes, stackTrace?: string): void {
84
- this.sendToServer(this.loggingUrl, severity, msg, code, stackTrace);
85
- }
86
-
87
- private sendError(severity: WSDKErrorSeverity, msg: string, code?: ErrorCodes, stackTrace?: string): void {
88
- this.sendToServer(this.errorUrl, severity, msg, code, stackTrace);
89
- }
90
-
91
- private buildLogRequest(severity: WSDKErrorSeverity, msg: string, code?: ErrorCodes, stackTrace?: string): LogRequestBody {
92
- return {
93
- additionalInformation: {
94
- message: msg,
95
- version: this.getVersion(),
96
- },
97
- severity: severity,
98
- code: code ?? ErrorCodes.UNKNOWN_ERROR,
99
- url: this.getUrl(),
100
- deviceInfo: this.getUserAgent(),
101
- stackTrace: stackTrace,
102
- reporter: this.reporter,
103
- // Integration will be set to integrationName once the kit connects via RoktManager.attachKit()
104
- integration: this.store?.getIntegrationName() ?? 'mp-wsdk'
105
- };
106
- }
107
-
108
- private getVersion(): string {
109
- return this.store?.getIntegrationName?.() ?? `mParticle_wsdkv_${this.sdkVersion}`;
110
- }
111
-
112
- private isReportingEnabled(): boolean {
113
- return this.isDebugModeEnabled() ||
114
- (this.isRoktDomainPresent() && this.isFeatureFlagEnabled());
115
- }
116
-
117
- private isRoktDomainPresent(): boolean {
118
- return typeof window !== 'undefined' && Boolean(window['ROKT_DOMAIN']);
119
- }
120
-
121
- private isFeatureFlagEnabled = (): boolean => this.isLoggingEnabled;
122
-
123
- private isDebugModeEnabled(): boolean {
124
- return (
125
- typeof window !== 'undefined' &&
126
- (window.
127
- location?.
128
- search?.
129
- toLowerCase()?.
130
- includes('mp_enable_logging=true') ?? false)
131
- );
132
- }
133
-
134
- private canSendLog(severity: WSDKErrorSeverity): boolean {
135
- return this.isEnabled && !this.isRateLimited(severity);
136
- }
137
-
138
- private isRateLimited(severity: WSDKErrorSeverity): boolean {
139
- return this.rateLimiter.incrementAndCheck(severity);
140
- }
141
-
142
- private getUrl(): string | undefined {
143
- return typeof window !== 'undefined' ? window.location?.href : undefined;
144
- }
145
-
146
- private getUserAgent(): string | undefined {
147
- return typeof window !== 'undefined' ? window.navigator?.userAgent : undefined;
148
- }
149
-
150
- private getHeaders(): IReportingLoggerPayload['headers'] {
151
- const headers: IReportingLoggerPayload['headers'] = {
152
- [HEADER_ACCEPT]: 'text/plain;charset=UTF-8',
153
- [HEADER_CONTENT_TYPE]: 'application/json',
154
- [HEADER_ROKT_LAUNCHER_VERSION]: this.getVersion(),
155
- [HEADER_ROKT_WSDK_VERSION]: 'joint',
156
- };
157
-
158
- if (this.launcherInstanceGuid) {
159
- headers[HEADER_ROKT_LAUNCHER_INSTANCE_GUID] = this.launcherInstanceGuid;
160
- }
161
-
162
- const accountId = this.store?.getRoktAccountId?.();
163
- if (accountId) {
164
- headers['rokt-account-id'] = accountId;
165
- }
166
-
167
- return headers;
168
- }
169
- }
170
-
171
- export interface IRateLimiter {
172
- incrementAndCheck(severity: WSDKErrorSeverity): boolean;
173
- }
174
-
175
- export class RateLimiter implements IRateLimiter {
176
- private readonly rateLimits: Map<WSDKErrorSeverity, number> = new Map([
177
- [WSDKErrorSeverity.ERROR, 10],
178
- [WSDKErrorSeverity.WARNING, 10],
179
- [WSDKErrorSeverity.INFO, 10],
180
- ]);
181
- private logCount: Map<WSDKErrorSeverity, number> = new Map();
182
-
183
- public incrementAndCheck(severity: WSDKErrorSeverity): boolean {
184
- const count = this.logCount.get(severity) || 0;
185
- const limit = this.rateLimits.get(severity) || 10;
186
-
187
- const newCount = count + 1;
188
- this.logCount.set(severity, newCount);
189
-
190
- return newCount > limit;
191
- }
192
- }
@@ -1,32 +0,0 @@
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;