noibu-react-native 0.2.1 → 0.2.3

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.
Files changed (79) hide show
  1. package/README.md +1 -1
  2. package/android/src/main/java/com/noibu/sessionreplay/reactnative/NoibuSessionReplayModule.kt +10 -0
  3. package/dist/api/clientConfig.js +225 -217
  4. package/dist/api/metroplexSocket.js +406 -416
  5. package/dist/constants.js +14 -2
  6. package/dist/entry/init.js +58 -56
  7. package/dist/monitors/appNavigationMonitor.js +2 -3
  8. package/dist/monitors/clickMonitor.js +16 -9
  9. package/dist/monitors/errorMonitor.js +30 -8
  10. package/dist/monitors/gqlErrorValidator.js +4 -4
  11. package/dist/monitors/httpDataBundler.js +525 -713
  12. package/dist/monitors/integrations/react-native-navigation-integration.js +4 -2
  13. package/dist/monitors/requestMonitor.js +350 -365
  14. package/dist/pageVisit/eventDebouncer.js +110 -0
  15. package/dist/pageVisit/pageVisitEventError.js +1 -1
  16. package/dist/pageVisit/pageVisitEventHTTP.js +78 -93
  17. package/dist/react/ErrorBoundary.js +18 -15
  18. package/dist/sessionRecorder/nativeSessionRecorderSubscription.js +3 -2
  19. package/dist/sessionRecorder/sessionRecorder.js +151 -150
  20. package/dist/{api → src/api}/clientConfig.d.ts +1 -1
  21. package/dist/{api → src/api}/metroplexSocket.d.ts +25 -25
  22. package/dist/{constants.d.ts → src/constants.d.ts} +44 -0
  23. package/dist/{entry → src/entry}/init.d.ts +1 -1
  24. package/dist/{monitors → src/monitors}/clickMonitor.d.ts +1 -1
  25. package/dist/{monitors → src/monitors}/gqlErrorValidator.d.ts +6 -6
  26. package/dist/src/monitors/httpDataBundler.d.ts +127 -0
  27. package/dist/src/monitors/requestMonitor.d.ts +10 -0
  28. package/dist/src/pageVisit/eventDebouncer.d.ts +31 -0
  29. package/dist/src/pageVisit/pageVisitEventHTTP.d.ts +25 -0
  30. package/dist/{sessionRecorder → src/sessionRecorder}/types.d.ts +1 -1
  31. package/dist/{storage → src/storage}/rnStorageProvider.d.ts +1 -1
  32. package/dist/{storage → src/storage}/storage.d.ts +1 -1
  33. package/dist/{storage → src/storage}/storageProvider.d.ts +3 -3
  34. package/dist/{utils → src/utils}/function.d.ts +25 -4
  35. package/dist/{utils → src/utils}/object.d.ts +9 -4
  36. package/dist/src/utils/piiRedactor.d.ts +11 -0
  37. package/dist/src/utils/polyfills.d.ts +7 -0
  38. package/dist/storage/rnStorageProvider.js +7 -5
  39. package/dist/storage/storage.js +43 -35
  40. package/dist/storage/storageProvider.js +23 -19
  41. package/dist/types/Config.d.ts +24 -20
  42. package/dist/types/PageVisit.types.d.ts +151 -0
  43. package/dist/types/PageVisitMetrics.types.d.ts +27 -0
  44. package/dist/types/RRWeb.d.ts +48 -0
  45. package/dist/types/StoredPageVisit.types.d.ts +2 -4
  46. package/dist/types/WrappedObjects.d.ts +6 -0
  47. package/dist/utils/function.js +110 -76
  48. package/dist/utils/object.js +58 -6
  49. package/dist/utils/piiRedactor.js +98 -0
  50. package/dist/utils/polyfills.js +24 -0
  51. package/package.json +24 -9
  52. package/dist/monitors/httpDataBundler.d.ts +0 -161
  53. package/dist/monitors/requestMonitor.d.ts +0 -10
  54. package/dist/pageVisit/pageVisitEventHTTP.d.ts +0 -18
  55. package/dist/types/PageVisit.d.ts +0 -22
  56. package/dist/types/globals.d.ts +0 -45
  57. /package/dist/{api → src/api}/helpCode.d.ts +0 -0
  58. /package/dist/{api → src/api}/inputManager.d.ts +0 -0
  59. /package/dist/{api → src/api}/storedMetrics.d.ts +0 -0
  60. /package/dist/{api → src/api}/storedPageVisit.d.ts +0 -0
  61. /package/dist/{const_matchers.d.ts → src/const_matchers.d.ts} +0 -0
  62. /package/dist/{entry → src/entry}/index.d.ts +0 -0
  63. /package/dist/{monitors → src/monitors}/appNavigationMonitor.d.ts +0 -0
  64. /package/dist/{monitors → src/monitors}/errorMonitor.d.ts +0 -0
  65. /package/dist/{monitors → src/monitors}/inputMonitor.d.ts +0 -0
  66. /package/dist/{monitors → src/monitors}/integrations/react-native-navigation-integration.d.ts +0 -0
  67. /package/dist/{monitors → src/monitors}/keyboardInputMonitor.d.ts +0 -0
  68. /package/dist/{monitors → src/monitors}/pageMonitor.d.ts +0 -0
  69. /package/dist/{pageVisit → src/pageVisit}/pageVisit.d.ts +0 -0
  70. /package/dist/{pageVisit → src/pageVisit}/pageVisitEventError.d.ts +0 -0
  71. /package/dist/{pageVisit → src/pageVisit}/userStep.d.ts +0 -0
  72. /package/dist/{react → src/react}/ErrorBoundary.d.ts +0 -0
  73. /package/dist/{sessionRecorder → src/sessionRecorder}/nativeSessionRecorderSubscription.d.ts +0 -0
  74. /package/dist/{sessionRecorder → src/sessionRecorder}/sessionRecorder.d.ts +0 -0
  75. /package/dist/{utils → src/utils}/date.d.ts +0 -0
  76. /package/dist/{utils → src/utils}/eventlistener.d.ts +0 -0
  77. /package/dist/{utils → src/utils}/log.d.ts +0 -0
  78. /package/dist/{utils → src/utils}/performance.d.ts +0 -0
  79. /package/dist/{utils → src/utils}/stacktrace-parser.d.ts +0 -0
package/README.md CHANGED
@@ -166,7 +166,7 @@ NoibuJS.addJsSdkError(new Error('My Error'), 'myModule.js');
166
166
 
167
167
  ## License
168
168
 
169
- Copyright 2023 Noibu.com
169
+ Copyright 2024 Noibu.com
170
170
 
171
171
  Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
172
172
 
@@ -100,6 +100,16 @@ class NoibuSessionReplayModule(reactContext: ReactApplicationContext) :
100
100
  return ret
101
101
  }
102
102
 
103
+ @ReactMethod
104
+ fun addListener(eventName: String) {
105
+ // Set up any upstream listeners or background tasks as necessary
106
+ }
107
+
108
+ @ReactMethod
109
+ fun removeListeners(count: Int) {
110
+ // Remove upstream listeners, stop unnecessary background tasks
111
+ }
112
+
103
113
  companion object {
104
114
  const val NAME = "NativeSessionRecorder"
105
115
  private var reactContext: ReactApplicationContext? = null
@@ -1,3 +1,4 @@
1
+ import { __awaiter } from 'tslib';
1
2
  import uuid from 'react-native-uuid';
2
3
  import { MAX_METROPLEX_SOCKET_INNACTIVE_TIME, SEVERITY, NOIBU_BROWSER_ID_KYWRD, PV_SEQ_NUM_RESET_TIME_MINUTES, JS_ENV, MAX_PAGEVISIT_VISITED, CLIENT_LOCK_TIME_MINUTES, GET_SCRIPT_ID, GET_DEVICE_ENV, MAX_COLLECT_ERROR_LOG } from '../constants.js';
3
4
  import { stringifyJSON, getMaxSubstringAllowed, getUserAgent, makeRequest } from '../utils/function.js';
@@ -5,7 +6,6 @@ import Storage from '../storage/storage.js';
5
6
  import { noibuLog } from '../utils/log.js';
6
7
  import { unwrapNoibuWrapped } from '../utils/object.js';
7
8
 
8
- /** @module ClientConfig */
9
9
  /**
10
10
  * Singleton class to manage the client configuration
11
11
  * this class will be responsible for controlling the disabled
@@ -13,25 +13,11 @@ import { unwrapNoibuWrapped } from '../utils/object.js';
13
13
  * storing and retrieval.
14
14
  */
15
15
  class ClientConfig {
16
- pageVisitId;
17
- browserId;
18
- pageVisitSeq;
19
- lastActiveTime;
20
- noibuErrorURL;
21
- cltErrorPostCounter;
22
- maxSocketInactiveTime;
23
- locationBreadcrumbs = [];
24
- static instance;
25
- static noibuErrorURL;
26
- customerDomain;
27
- isClientDisabled;
28
- listOfUrlsToCollectHttpDataFrom;
29
- enableHttpDataCollection;
30
- blockedElements;
31
16
  /**
32
17
  * Creates a ClientConfig singleton instance
33
18
  */
34
19
  constructor(noibuErrorURL, customerConfig) {
20
+ this.locationBreadcrumbs = [];
35
21
  // sets up this.browserId, this.disabledStatus
36
22
  this.pageVisitId = uuid.v4();
37
23
  // variables stored in storage
@@ -56,13 +42,15 @@ class ClientConfig {
56
42
  this.blockedElements = customerConfig.blockedElements;
57
43
  }
58
44
  /** Configures the singleton instance */
59
- static async configureInstance({ noibuErrorURL, customerConfig, }) {
60
- if (!this.instance) {
61
- ClientConfig.noibuErrorURL = noibuErrorURL;
62
- this.instance = new ClientConfig(noibuErrorURL, customerConfig);
63
- // sets up this.browserId, this.isClientDisabled, this.pageVisitSeq
64
- await this.instance._setupStorageVars();
65
- }
45
+ static configureInstance(_a) {
46
+ return __awaiter(this, arguments, void 0, function* ({ noibuErrorURL, customerConfig, }) {
47
+ if (!this.instance) {
48
+ ClientConfig.noibuErrorURL = noibuErrorURL;
49
+ this.instance = new ClientConfig(noibuErrorURL, customerConfig);
50
+ // sets up this.browserId, this.isClientDisabled, this.pageVisitSeq
51
+ yield this.instance._setupStorageVars();
52
+ }
53
+ });
66
54
  }
67
55
  /**
68
56
  * gets the singleton instance
@@ -75,38 +63,44 @@ class ClientConfig {
75
63
  }
76
64
  /** lockClient will disable the client script for a single pagevisit for
77
65
  * duration given in minuntes */
78
- async lockClient(duration, msg) {
79
- const expiryTime = new Date();
80
- expiryTime.setMinutes(expiryTime.getMinutes() + duration);
81
- const noibuLSObject = await this._getClientState();
82
- noibuLSObject.DisabledStatus = true;
83
- noibuLSObject.ClientUnlockTime = expiryTime;
84
- await this._storeBrowserData(noibuLSObject);
85
- await this.postNoibuErrorAndOptionallyDisableClient(msg, true, SEVERITY.warn);
66
+ lockClient(duration, msg) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const expiryTime = new Date();
69
+ expiryTime.setMinutes(expiryTime.getMinutes() + duration);
70
+ const noibuLSObject = yield this._getClientState();
71
+ noibuLSObject.DisabledStatus = true;
72
+ noibuLSObject.ClientUnlockTime = expiryTime;
73
+ yield this._storeBrowserData(noibuLSObject);
74
+ yield this.postNoibuErrorAndOptionallyDisableClient(msg, true, SEVERITY.warn);
75
+ });
86
76
  }
87
77
  /** Locks the client until the next page loads */
88
78
  lockClientUntilNextPage(msg) {
89
79
  return this.postNoibuErrorAndOptionallyDisableClient(msg, true, SEVERITY.warn);
90
80
  }
91
81
  /** Updates the config object to store the given last active time */
92
- async updateLastActiveTime(lastActiveTime) {
93
- this.lastActiveTime = lastActiveTime;
94
- const newConfigData = await this._getLsObject();
95
- newConfigData.LastActive = lastActiveTime;
96
- await this._storeBrowserData(newConfigData);
82
+ updateLastActiveTime(lastActiveTime) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ this.lastActiveTime = lastActiveTime;
85
+ const newConfigData = yield this._getLsObject();
86
+ newConfigData.LastActive = lastActiveTime;
87
+ yield this._storeBrowserData(newConfigData);
88
+ });
97
89
  }
98
90
  /** Gets the current page visit sequence number that should be used */
99
- async getPageVisitSeq() {
100
- if (await this._pageVisitSeqNeedsReset()) {
101
- // Reset the page visit sequence number to zero and store the next seq number in storage
102
- this.pageVisitSeq = 0;
103
- const newConfigData = await this._getLsObject();
104
- newConfigData.CurrentPageVisitCount = this.pageVisitSeq + 1;
105
- // Update the last active time since we are actively requesting the seq
106
- newConfigData.LastActive = new Date();
107
- await this._storeBrowserData(newConfigData);
108
- }
109
- return this.pageVisitSeq;
91
+ getPageVisitSeq() {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ if (yield this._pageVisitSeqNeedsReset()) {
94
+ // Reset the page visit sequence number to zero and store the next seq number in storage
95
+ this.pageVisitSeq = 0;
96
+ const newConfigData = yield this._getLsObject();
97
+ newConfigData.CurrentPageVisitCount = this.pageVisitSeq + 1;
98
+ // Update the last active time since we are actively requesting the seq
99
+ newConfigData.LastActive = new Date();
100
+ yield this._storeBrowserData(newConfigData);
101
+ }
102
+ return this.pageVisitSeq;
103
+ });
110
104
  }
111
105
  /**
112
106
  * Returns the client config object from storage or generates a new one
@@ -120,95 +114,101 @@ class ClientConfig {
120
114
  * LastActiveTime: DATE OBJ
121
115
  * }
122
116
  */
123
- async _getLsObject() {
124
- const storage = Storage.getInstance();
125
- const storedConfig = await storage.load(NOIBU_BROWSER_ID_KYWRD);
126
- // first time browsing since noibu was installed
127
- if (!storedConfig) {
128
- return this._generateAndStoreData();
129
- }
130
- let parsedConfig = {};
131
- try {
132
- parsedConfig = JSON.parse(storedConfig);
133
- }
134
- catch (e) {
135
- return this._generateAndStoreData();
136
- }
137
- // checking if it's a valid object. The CLIENT_UNLOCK_TIME_KEY doesn't have to exist
138
- // since it's not written to the storage object when set to null.
139
- if (!(parsedConfig.BrowserId &&
140
- Boolean(parsedConfig.DisabledStatus) === parsedConfig.DisabledStatus &&
141
- parsedConfig.CurrentPageVisitCount &&
142
- parsedConfig.LastActive)) {
143
- return this._generateAndStoreData();
144
- }
145
- return parsedConfig;
117
+ _getLsObject() {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const storage = Storage.getInstance();
120
+ const storedConfig = yield storage.load(NOIBU_BROWSER_ID_KYWRD);
121
+ // first time browsing since noibu was installed
122
+ if (!storedConfig) {
123
+ return this._generateAndStoreData();
124
+ }
125
+ let parsedConfig = {};
126
+ try {
127
+ parsedConfig = JSON.parse(storedConfig);
128
+ }
129
+ catch (e) {
130
+ return this._generateAndStoreData();
131
+ }
132
+ // checking if it's a valid object. The CLIENT_UNLOCK_TIME_KEY doesn't have to exist
133
+ // since it's not written to the storage object when set to null.
134
+ if (!(parsedConfig.BrowserId &&
135
+ Boolean(parsedConfig.DisabledStatus) === parsedConfig.DisabledStatus &&
136
+ parsedConfig.CurrentPageVisitCount &&
137
+ parsedConfig.LastActive)) {
138
+ return this._generateAndStoreData();
139
+ }
140
+ return parsedConfig;
141
+ });
146
142
  }
147
143
  /**
148
144
  * Check if we have surpassed the last active time and the page visit seq number needs resetting
149
145
  */
150
- async _pageVisitSeqNeedsReset() {
151
- const noibuLSObject = await this._getClientState();
152
- const someTimeAgo = new Date();
153
- someTimeAgo.setMinutes(someTimeAgo.getMinutes() - PV_SEQ_NUM_RESET_TIME_MINUTES);
154
- if (!noibuLSObject.LastActive) {
155
- return true;
156
- }
157
- return new Date(noibuLSObject.LastActive) < someTimeAgo;
146
+ _pageVisitSeqNeedsReset() {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ const noibuLSObject = yield this._getClientState();
149
+ const someTimeAgo = new Date();
150
+ someTimeAgo.setMinutes(someTimeAgo.getMinutes() - PV_SEQ_NUM_RESET_TIME_MINUTES);
151
+ if (!noibuLSObject.LastActive) {
152
+ return true;
153
+ }
154
+ return new Date(noibuLSObject.LastActive) < someTimeAgo;
155
+ });
158
156
  }
159
157
  /**
160
158
  * _setupStorageVars will set all class variables that depend
161
159
  * on the storage's value.
162
160
  */
163
- async _setupStorageVars() {
164
- const storage = Storage.getInstance();
165
- if (!(await storage.isAvailable())) {
166
- void this.postNoibuErrorAndOptionallyDisableClient(`Storage is unavailable, disabling client. ${await storage.getDiagnoseInfo()}`, true, SEVERITY.error);
167
- return;
168
- }
169
- // getting the current content of the storage
170
- const noibuLSObject = await this._getClientState();
171
- // Check if we have surpased the last active time and reset the sequence number if so
172
- if (await this._pageVisitSeqNeedsReset()) {
173
- noibuLSObject.CurrentPageVisitCount = 0;
174
- }
175
- this.browserId = noibuLSObject.BrowserId;
176
- noibuLog('ClientConfig - _setupStorageVars', { noibuLSObject });
177
- this.pageVisitSeq = noibuLSObject.CurrentPageVisitCount;
178
- this.isClientDisabled = noibuLSObject.DisabledStatus;
179
- // If the client has been disabled just return.
180
- // Calling _getClientState() above performs the disabled expirey check
181
- if (this.isClientDisabled)
182
- return;
183
- // Update the LS object values before storing it for the next page visit
184
- noibuLSObject.CurrentPageVisitCount += 1;
185
- noibuLSObject.LastActive = new Date();
186
- // Expose page visit ID in storage for use by Trailbreaker video tests
187
- // This will be done for the testvideo and lambdavideo bundles used by Trailbreaker
188
- if (JS_ENV().includes('video')) {
189
- noibuLSObject.pvId = this.pageVisitId;
190
- }
191
- // if we have reached the max page visits for a browser id then
192
- // we disabled collect for 45 minutes
193
- if (noibuLSObject.CurrentPageVisitCount >= MAX_PAGEVISIT_VISITED) {
194
- // if we bust the max pagevisit visited limit we lock the client for 45 minutes
195
- // since its probably a bot.
196
- const expiryTime = new Date();
197
- expiryTime.setMinutes(expiryTime.getMinutes() + CLIENT_LOCK_TIME_MINUTES);
198
- // setting the lock time
199
- noibuLSObject.ClientUnlockTime = expiryTime;
200
- noibuLSObject.DisabledStatus = true;
201
- await this.postNoibuErrorAndOptionallyDisableClient(`Hit max page visits, disabling client for ${CLIENT_LOCK_TIME_MINUTES}mins`, true, SEVERITY.error);
202
- }
203
- // we now check if we successfully saved the data
204
- const savedData = await this._storeBrowserData(noibuLSObject);
205
- // if the browser is null, we cannot access the storage or an
206
- // error happened, thus we disable collect.
207
- if (!savedData.BrowserId) {
208
- // we do not set a lock expiry date here since we cannot store to storage
209
- void this.postNoibuErrorAndOptionallyDisableClient(`Null browser in storage, disabling client`, true, SEVERITY.error);
210
- this.browserId = '';
211
- }
161
+ _setupStorageVars() {
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ const storage = Storage.getInstance();
164
+ if (!(yield storage.isAvailable())) {
165
+ void this.postNoibuErrorAndOptionallyDisableClient(`Storage is unavailable, disabling client. ${yield storage.getDiagnoseInfo()}`, true, SEVERITY.error);
166
+ return;
167
+ }
168
+ // getting the current content of the storage
169
+ const noibuLSObject = yield this._getClientState();
170
+ // Check if we have surpased the last active time and reset the sequence number if so
171
+ if (yield this._pageVisitSeqNeedsReset()) {
172
+ noibuLSObject.CurrentPageVisitCount = 0;
173
+ }
174
+ this.browserId = noibuLSObject.BrowserId;
175
+ noibuLog('ClientConfig - _setupStorageVars', { noibuLSObject });
176
+ this.pageVisitSeq = noibuLSObject.CurrentPageVisitCount;
177
+ this.isClientDisabled = noibuLSObject.DisabledStatus;
178
+ // If the client has been disabled just return.
179
+ // Calling _getClientState() above performs the disabled expirey check
180
+ if (this.isClientDisabled)
181
+ return;
182
+ // Update the LS object values before storing it for the next page visit
183
+ noibuLSObject.CurrentPageVisitCount += 1;
184
+ noibuLSObject.LastActive = new Date();
185
+ // Expose page visit ID in storage for use by Trailbreaker video tests
186
+ // This will be done for the testvideo and lambdavideo bundles used by Trailbreaker
187
+ if (JS_ENV().includes('video')) {
188
+ noibuLSObject.pvId = this.pageVisitId;
189
+ }
190
+ // if we have reached the max page visits for a browser id then
191
+ // we disabled collect for 45 minutes
192
+ if (noibuLSObject.CurrentPageVisitCount >= MAX_PAGEVISIT_VISITED) {
193
+ // if we bust the max pagevisit visited limit we lock the client for 45 minutes
194
+ // since its probably a bot.
195
+ const expiryTime = new Date();
196
+ expiryTime.setMinutes(expiryTime.getMinutes() + CLIENT_LOCK_TIME_MINUTES);
197
+ // setting the lock time
198
+ noibuLSObject.ClientUnlockTime = expiryTime;
199
+ noibuLSObject.DisabledStatus = true;
200
+ yield this.postNoibuErrorAndOptionallyDisableClient(`Hit max page visits, disabling client for ${CLIENT_LOCK_TIME_MINUTES}mins`, true, SEVERITY.error);
201
+ }
202
+ // we now check if we successfully saved the data
203
+ const savedData = yield this._storeBrowserData(noibuLSObject);
204
+ // if the browser is null, we cannot access the storage or an
205
+ // error happened, thus we disable collect.
206
+ if (!savedData.BrowserId) {
207
+ // we do not set a lock expiry date here since we cannot store to storage
208
+ void this.postNoibuErrorAndOptionallyDisableClient(`Null browser in storage, disabling client`, true, SEVERITY.error);
209
+ this.browserId = '';
210
+ }
211
+ });
212
212
  }
213
213
  /**
214
214
  * Function will get the Noibu Storage Object
@@ -216,24 +216,28 @@ class ClientConfig {
216
216
  * Get it from storage if the expiry date is not in the past
217
217
  * Generate a brand new one if the expiry date is in the past
218
218
  */
219
- async _getClientState() {
220
- const newConfigData = await this._getLsObject();
221
- // if the lock expired, we remove the lock period and enable the client
222
- if (newConfigData.ClientUnlockTime &&
223
- new Date(newConfigData.ClientUnlockTime) <= new Date()) {
224
- newConfigData.ClientUnlockTime = undefined;
225
- newConfigData.DisabledStatus = false;
226
- await this._storeBrowserData(newConfigData);
227
- }
228
- // return the stored browserId
229
- return newConfigData;
219
+ _getClientState() {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ const newConfigData = yield this._getLsObject();
222
+ // if the lock expired, we remove the lock period and enable the client
223
+ if (newConfigData.ClientUnlockTime &&
224
+ new Date(newConfigData.ClientUnlockTime) <= new Date()) {
225
+ newConfigData.ClientUnlockTime = undefined;
226
+ newConfigData.DisabledStatus = false;
227
+ yield this._storeBrowserData(newConfigData);
228
+ }
229
+ // return the stored browserId
230
+ return newConfigData;
231
+ });
230
232
  }
231
233
  /**
232
234
  * _generateAndStoreData generates brand new data and then proceeds to store
233
235
  * it.
234
236
  */
235
- async _generateAndStoreData() {
236
- return this._storeBrowserData(this._generateNewBrowserData());
237
+ _generateAndStoreData() {
238
+ return __awaiter(this, void 0, void 0, function* () {
239
+ return this._storeBrowserData(this._generateNewBrowserData());
240
+ });
237
241
  }
238
242
  /**
239
243
  * _generateNewBrowserData will create new data to be stored in storage
@@ -257,17 +261,19 @@ class ClientConfig {
257
261
  * _storeBrowserData will store the passed object in storage.
258
262
  * @param {} data the data to be stored
259
263
  */
260
- async _storeBrowserData(data) {
261
- const storage = Storage.getInstance();
262
- try {
263
- await storage.save(NOIBU_BROWSER_ID_KYWRD, stringifyJSON(data));
264
- return data;
265
- }
266
- catch (e) {
267
- await this.postNoibuErrorAndOptionallyDisableClient(`Error writing browser data to storage, disabling client: ${e.message}, ${await storage.getDiagnoseInfo()}`, true, SEVERITY.error);
268
- // sending empty fields if we encountered errors while storing in the LS
269
- return this._generateNewBrowserData();
270
- }
264
+ _storeBrowserData(data) {
265
+ return __awaiter(this, void 0, void 0, function* () {
266
+ const storage = Storage.getInstance();
267
+ try {
268
+ yield storage.save(NOIBU_BROWSER_ID_KYWRD, stringifyJSON(data));
269
+ return data;
270
+ }
271
+ catch (e) {
272
+ yield this.postNoibuErrorAndOptionallyDisableClient(`Error writing browser data to storage, disabling client: ${e.message}, ${yield storage.getDiagnoseInfo()}`, true, SEVERITY.error);
273
+ // sending empty fields if we encountered errors while storing in the LS
274
+ return this._generateNewBrowserData();
275
+ }
276
+ });
271
277
  }
272
278
  /** sets current breadcrumbs to be reconstructed into global url */
273
279
  set currentLocationBreadcrumbs(newValue) {
@@ -290,73 +296,75 @@ class ClientConfig {
290
296
  * and disable the client if required
291
297
  * severity expects one of the SEVERITY_x level constants, or else error will be used
292
298
  */
293
- async postNoibuErrorAndOptionallyDisableClient(errorMsg, disableClient, severity, keepAlive = false) {
294
- noibuLog('postNoibuErrorAndOptionallyDisableClient', {
295
- errorMsg,
296
- disableClient,
297
- severity,
298
- keepAlive,
299
- });
300
- if (this.isClientDisabled) {
301
- return;
302
- }
303
- if (disableClient) {
304
- this.isClientDisabled = true;
305
- }
306
- if (severity === SEVERITY.warn) {
307
- // don't log warning messages by default, as a cost savings
308
- return;
309
- }
310
- const collectError = {
311
- browserId: this.browserId || '',
312
- pageVisitId: this.pageVisitId,
313
- scriptId: GET_SCRIPT_ID(),
314
- ua: await getUserAgent(),
315
- deviceEnv: GET_DEVICE_ENV(),
316
- error: stringifyJSON(errorMsg),
317
- };
318
- // if the page visits sends more errors than the
319
- // allowed threshold we disable the client
320
- if (this.cltErrorPostCounter >= MAX_COLLECT_ERROR_LOG) {
321
- // we disable the client for 10 minute if we sent too many logs
322
- // we manually lock the client to not cause an infinite loop
323
- const expiryTime = new Date();
324
- expiryTime.setMinutes(expiryTime.getMinutes() + 10); // 10 minutes lock
325
- const noibuLSObject = await this._getClientState();
326
- noibuLSObject.DisabledStatus = true;
327
- noibuLSObject.ClientUnlockTime = expiryTime;
328
- await this._storeBrowserData(noibuLSObject);
329
- this.isClientDisabled = true;
330
- // end of lock
331
- // overriding the message to be an alert that we are shutting collect off.
332
- collectError.error = `Shutting collect off, we reached the maximum limit of collect errors sent.`;
333
- }
334
- const errorContent = {
335
- url: this.globalUrl,
336
- err_msg: collectError,
337
- sev: severity,
338
- };
339
- const headers = {
340
- 'content-type': 'application/json',
341
- };
342
- if (!keepAlive) {
343
- makeRequest('POST', this.noibuErrorURL, errorContent, headers, 2000, false).catch(() => {
344
- // we do nothing and let this error silently fail
345
- });
346
- }
347
- else {
348
- void unwrapNoibuWrapped(fetch)(this.noibuErrorURL, {
349
- method: 'POST',
350
- headers,
351
- body: stringifyJSON(errorContent),
352
- // keep alive outlives the current page, its the same as beacon
353
- keepalive: true,
299
+ postNoibuErrorAndOptionallyDisableClient(errorMsg_1, disableClient_1, severity_1) {
300
+ return __awaiter(this, arguments, void 0, function* (errorMsg, disableClient, severity, keepAlive = false) {
301
+ noibuLog('postNoibuErrorAndOptionallyDisableClient', {
302
+ errorMsg,
303
+ disableClient,
304
+ severity,
305
+ keepAlive,
354
306
  });
355
- }
356
- // only increment if this was an actual error, not a warning or otherwise
357
- if (severity === SEVERITY.error) {
358
- this.cltErrorPostCounter += 1;
359
- }
307
+ if (this.isClientDisabled) {
308
+ return;
309
+ }
310
+ if (disableClient) {
311
+ this.isClientDisabled = true;
312
+ }
313
+ if (severity === SEVERITY.warn) {
314
+ // don't log warning messages by default, as a cost savings
315
+ return;
316
+ }
317
+ const collectError = {
318
+ browserId: this.browserId || '',
319
+ pageVisitId: this.pageVisitId,
320
+ scriptId: GET_SCRIPT_ID(),
321
+ ua: yield getUserAgent(),
322
+ deviceEnv: GET_DEVICE_ENV(),
323
+ error: stringifyJSON(errorMsg),
324
+ };
325
+ // if the page visits sends more errors than the
326
+ // allowed threshold we disable the client
327
+ if (this.cltErrorPostCounter >= MAX_COLLECT_ERROR_LOG) {
328
+ // we disable the client for 10 minute if we sent too many logs
329
+ // we manually lock the client to not cause an infinite loop
330
+ const expiryTime = new Date();
331
+ expiryTime.setMinutes(expiryTime.getMinutes() + 10); // 10 minutes lock
332
+ const noibuLSObject = yield this._getClientState();
333
+ noibuLSObject.DisabledStatus = true;
334
+ noibuLSObject.ClientUnlockTime = expiryTime;
335
+ yield this._storeBrowserData(noibuLSObject);
336
+ this.isClientDisabled = true;
337
+ // end of lock
338
+ // overriding the message to be an alert that we are shutting collect off.
339
+ collectError.error = `Shutting collect off, we reached the maximum limit of collect errors sent.`;
340
+ }
341
+ const errorContent = {
342
+ url: this.globalUrl,
343
+ err_msg: collectError,
344
+ sev: severity,
345
+ };
346
+ const headers = {
347
+ 'content-type': 'application/json',
348
+ };
349
+ if (!keepAlive) {
350
+ makeRequest('POST', this.noibuErrorURL, errorContent, headers, 2000, false).catch(() => {
351
+ // we do nothing and let this error silently fail
352
+ });
353
+ }
354
+ else {
355
+ void unwrapNoibuWrapped(fetch)(this.noibuErrorURL, {
356
+ method: 'POST',
357
+ headers,
358
+ body: stringifyJSON(errorContent),
359
+ // keep alive outlives the current page, its the same as beacon
360
+ keepalive: true,
361
+ });
362
+ }
363
+ // only increment if this was an actual error, not a warning or otherwise
364
+ if (severity === SEVERITY.error) {
365
+ this.cltErrorPostCounter += 1;
366
+ }
367
+ });
360
368
  }
361
369
  /**
362
370
  * Returns true if the page visit is considered to be inactive