noibu-react-native 0.2.2 → 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.
- package/README.md +1 -1
- package/dist/api/clientConfig.js +225 -217
- package/dist/api/metroplexSocket.js +406 -416
- package/dist/constants.js +14 -2
- package/dist/entry/init.js +58 -56
- package/dist/monitors/appNavigationMonitor.js +2 -3
- package/dist/monitors/clickMonitor.js +16 -9
- package/dist/monitors/errorMonitor.js +30 -8
- package/dist/monitors/gqlErrorValidator.js +4 -4
- package/dist/monitors/httpDataBundler.js +525 -713
- package/dist/monitors/integrations/react-native-navigation-integration.js +4 -2
- package/dist/monitors/requestMonitor.js +350 -365
- package/dist/pageVisit/eventDebouncer.js +110 -0
- package/dist/pageVisit/pageVisitEventError.js +1 -1
- package/dist/pageVisit/pageVisitEventHTTP.js +78 -93
- package/dist/react/ErrorBoundary.js +18 -15
- package/dist/sessionRecorder/nativeSessionRecorderSubscription.js +3 -2
- package/dist/sessionRecorder/sessionRecorder.js +151 -150
- package/dist/{api → src/api}/clientConfig.d.ts +1 -1
- package/dist/{api → src/api}/metroplexSocket.d.ts +25 -25
- package/dist/{constants.d.ts → src/constants.d.ts} +44 -0
- package/dist/{entry → src/entry}/init.d.ts +1 -1
- package/dist/{monitors → src/monitors}/clickMonitor.d.ts +1 -1
- package/dist/{monitors → src/monitors}/gqlErrorValidator.d.ts +6 -6
- package/dist/src/monitors/httpDataBundler.d.ts +127 -0
- package/dist/src/monitors/requestMonitor.d.ts +10 -0
- package/dist/src/pageVisit/eventDebouncer.d.ts +31 -0
- package/dist/src/pageVisit/pageVisitEventHTTP.d.ts +25 -0
- package/dist/{sessionRecorder → src/sessionRecorder}/types.d.ts +1 -1
- package/dist/{storage → src/storage}/storage.d.ts +1 -1
- package/dist/{storage → src/storage}/storageProvider.d.ts +1 -1
- package/dist/{utils → src/utils}/function.d.ts +25 -4
- package/dist/{utils → src/utils}/object.d.ts +9 -4
- package/dist/src/utils/piiRedactor.d.ts +11 -0
- package/dist/src/utils/polyfills.d.ts +7 -0
- package/dist/storage/rnStorageProvider.js +7 -4
- package/dist/storage/storage.js +43 -35
- package/dist/storage/storageProvider.js +23 -19
- package/dist/types/Config.d.ts +24 -20
- package/dist/types/PageVisit.types.d.ts +151 -0
- package/dist/types/PageVisitMetrics.types.d.ts +27 -0
- package/dist/types/RRWeb.d.ts +48 -0
- package/dist/types/StoredPageVisit.types.d.ts +2 -4
- package/dist/types/WrappedObjects.d.ts +6 -0
- package/dist/utils/function.js +110 -76
- package/dist/utils/object.js +58 -6
- package/dist/utils/piiRedactor.js +98 -0
- package/dist/utils/polyfills.js +24 -0
- package/package.json +5 -6
- package/dist/monitors/httpDataBundler.d.ts +0 -161
- package/dist/monitors/requestMonitor.d.ts +0 -10
- package/dist/pageVisit/pageVisitEventHTTP.d.ts +0 -18
- package/dist/types/PageVisit.d.ts +0 -22
- package/dist/types/globals.d.ts +0 -45
- /package/dist/{api → src/api}/helpCode.d.ts +0 -0
- /package/dist/{api → src/api}/inputManager.d.ts +0 -0
- /package/dist/{api → src/api}/storedMetrics.d.ts +0 -0
- /package/dist/{api → src/api}/storedPageVisit.d.ts +0 -0
- /package/dist/{const_matchers.d.ts → src/const_matchers.d.ts} +0 -0
- /package/dist/{entry → src/entry}/index.d.ts +0 -0
- /package/dist/{monitors → src/monitors}/appNavigationMonitor.d.ts +0 -0
- /package/dist/{monitors → src/monitors}/errorMonitor.d.ts +0 -0
- /package/dist/{monitors → src/monitors}/inputMonitor.d.ts +0 -0
- /package/dist/{monitors → src/monitors}/integrations/react-native-navigation-integration.d.ts +0 -0
- /package/dist/{monitors → src/monitors}/keyboardInputMonitor.d.ts +0 -0
- /package/dist/{monitors → src/monitors}/pageMonitor.d.ts +0 -0
- /package/dist/{pageVisit → src/pageVisit}/pageVisit.d.ts +0 -0
- /package/dist/{pageVisit → src/pageVisit}/pageVisitEventError.d.ts +0 -0
- /package/dist/{pageVisit → src/pageVisit}/userStep.d.ts +0 -0
- /package/dist/{react → src/react}/ErrorBoundary.d.ts +0 -0
- /package/dist/{sessionRecorder → src/sessionRecorder}/nativeSessionRecorderSubscription.d.ts +0 -0
- /package/dist/{sessionRecorder → src/sessionRecorder}/sessionRecorder.d.ts +0 -0
- /package/dist/{storage → src/storage}/rnStorageProvider.d.ts +0 -0
- /package/dist/{utils → src/utils}/date.d.ts +0 -0
- /package/dist/{utils → src/utils}/eventlistener.d.ts +0 -0
- /package/dist/{utils → src/utils}/log.d.ts +0 -0
- /package/dist/{utils → src/utils}/performance.d.ts +0 -0
- /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
|
|
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
|
|
package/dist/api/clientConfig.js
CHANGED
|
@@ -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
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
93
|
-
this
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
236
|
-
return
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|