noibu-react-native 0.0.1
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 +155 -0
- package/dist/api/clientConfig.js +416 -0
- package/dist/api/helpCode.js +106 -0
- package/dist/api/inputManager.js +233 -0
- package/dist/api/metroplexSocket.js +882 -0
- package/dist/api/storedMetrics.js +201 -0
- package/dist/api/storedPageVisit.js +235 -0
- package/dist/const_matchers.js +260 -0
- package/dist/constants.d.ts +264 -0
- package/dist/constants.js +528 -0
- package/dist/entry/index.d.ts +8 -0
- package/dist/entry/index.js +15 -0
- package/dist/entry/init.js +91 -0
- package/dist/monitors/clickMonitor.js +284 -0
- package/dist/monitors/elementMonitor.js +174 -0
- package/dist/monitors/errorMonitor.js +295 -0
- package/dist/monitors/gqlErrorValidator.js +306 -0
- package/dist/monitors/httpDataBundler.js +665 -0
- package/dist/monitors/inputMonitor.js +130 -0
- package/dist/monitors/keyboardInputMonitor.js +67 -0
- package/dist/monitors/locationChangeMonitor.js +30 -0
- package/dist/monitors/pageMonitor.js +119 -0
- package/dist/monitors/requestMonitor.js +679 -0
- package/dist/pageVisit/pageVisit.js +172 -0
- package/dist/pageVisit/pageVisitEventError/pageVisitEventError.js +313 -0
- package/dist/pageVisit/pageVisitEventHTTP/pageVisitEventHTTP.js +115 -0
- package/dist/pageVisit/userStep/userStep.js +20 -0
- package/dist/react/ErrorBoundary.d.ts +72 -0
- package/dist/react/ErrorBoundary.js +102 -0
- package/dist/storage/localStorageProvider.js +23 -0
- package/dist/storage/rnStorageProvider.js +62 -0
- package/dist/storage/sessionStorageProvider.js +23 -0
- package/dist/storage/storage.js +119 -0
- package/dist/storage/storageProvider.js +83 -0
- package/dist/utils/date.js +62 -0
- package/dist/utils/eventlistener.js +67 -0
- package/dist/utils/function.js +398 -0
- package/dist/utils/object.js +144 -0
- package/dist/utils/performance.js +21 -0
- package/package.json +57 -0
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
/** @module Constants */
|
|
2
|
+
// current collect version to be sent to front end services
|
|
3
|
+
// The Collect version should only change if we change the protocol between
|
|
4
|
+
// metroplex and collect as a different collect version than the one
|
|
5
|
+
// expected will result in noibujs locking himself for 45 minutes.
|
|
6
|
+
const CURRENT_NOIBUJS_VERSION = 2;
|
|
7
|
+
const MAX_FRAMES_IN_ARRAY = 50;
|
|
8
|
+
const MAX_STRING_LENGTH = 1024;
|
|
9
|
+
// the maximum size of http data payload that will be captured, otherwise it is dropped
|
|
10
|
+
const MAX_HTTP_DATA_PAYLOAD_LENGTH = 50000;
|
|
11
|
+
// number of errors that collect can send to metroplex before shutting himself off.
|
|
12
|
+
const MAX_COLLECT_ERROR_LOG = 50;
|
|
13
|
+
const MAX_PAGEVISIT_PARTS = 10000;
|
|
14
|
+
// maximum number of HTTP data events to collect per page visit
|
|
15
|
+
const MAX_HTTP_DATA_EVENT_COUNT = 100;
|
|
16
|
+
// The max number of milliseconds the front end should wait before sending
|
|
17
|
+
// data to Metroplex
|
|
18
|
+
const MAX_TIME_FOR_UNSENT_DATA_MILLIS = 500;
|
|
19
|
+
const NOIBU_BROWSER_ID_KYWRD = 'n_browser_data';
|
|
20
|
+
// The local storage key used to store the last page visit
|
|
21
|
+
const NOIBU_STORED_PAGE_VISIT = 'n_stored_page_visit';
|
|
22
|
+
// The local storage key used to test whether writing to local storage is supported
|
|
23
|
+
const NOIBU_LOCAL_STORAGE_TEST_KEY = 'n_key';
|
|
24
|
+
// The amount of time to lock the client for if they have exceeded things
|
|
25
|
+
// like the maximum number of pagevisits
|
|
26
|
+
const CLIENT_LOCK_TIME_MINUTES = 45;
|
|
27
|
+
// The amount of inactive time required for us to reset the page visit sequence numbers
|
|
28
|
+
const PV_SEQ_NUM_RESET_TIME_MINUTES = 45;
|
|
29
|
+
// urls needed to communicate with our fe components
|
|
30
|
+
const REQUIRED_DATA_PROCESSING_URLS = [
|
|
31
|
+
'metroplexSocketBase',
|
|
32
|
+
'metroplexHTTPBase',
|
|
33
|
+
];
|
|
34
|
+
const HTTP_BODY_DROPPED_TYPE_MSG = 'Dropped due to unsupported type.';
|
|
35
|
+
const HTTP_BODY_DROPPED_LENGTH_MSG = 'Dropped due to length.';
|
|
36
|
+
const HTTP_BODY_NULL_STRING = 'null';
|
|
37
|
+
// HTTP request/response header keys to be blocked - these must be lowercase.
|
|
38
|
+
const BLOCKED_HTTP_HEADER_KEYS = [
|
|
39
|
+
// Auth token
|
|
40
|
+
'authorization',
|
|
41
|
+
// Email address
|
|
42
|
+
'from',
|
|
43
|
+
// Auth token
|
|
44
|
+
'proxy-authorization',
|
|
45
|
+
// MD5 hash of body could leak PII, obsolete so this shouldn't be a regular issue.
|
|
46
|
+
'content-md5',
|
|
47
|
+
// Cookies could include PII.
|
|
48
|
+
'cookie',
|
|
49
|
+
// IP address
|
|
50
|
+
'x-forwarded-for',
|
|
51
|
+
// IP address
|
|
52
|
+
'x-real-ip',
|
|
53
|
+
// Uniquely-identifiable device ID
|
|
54
|
+
'x-device-id',
|
|
55
|
+
// Uniquely-identifiable request ID
|
|
56
|
+
'x-request-id',
|
|
57
|
+
// Auth token
|
|
58
|
+
'x-auth-token',
|
|
59
|
+
// Uniquely-identifiable user ID
|
|
60
|
+
'x-user-id',
|
|
61
|
+
// Could contain IP address
|
|
62
|
+
'x-forwarded-for',
|
|
63
|
+
// Verizon injects this into requests on their network, contains PII
|
|
64
|
+
'x-uidh',
|
|
65
|
+
// Cookies
|
|
66
|
+
'set-cookie',
|
|
67
|
+
// IP addres
|
|
68
|
+
'forwarded',
|
|
69
|
+
];
|
|
70
|
+
const PII_DIGIT_PATTERN = /[0-9]+/g;
|
|
71
|
+
// eslint-disable-next-line max-len
|
|
72
|
+
const PII_EMAIL_PATTERN = /\b[a-z0-9!#$%&'*+/=?^_‘{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_‘{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\b/g;
|
|
73
|
+
// Regex patterns for a best-effort attempt at blocking PII in HTTP requests
|
|
74
|
+
const HTTP_PII_BLOCKING_PATTERNS = [
|
|
75
|
+
// Match credit cards [https://www.regular-expressions.info/creditcard.html]
|
|
76
|
+
// Visa
|
|
77
|
+
/\b4\d{12}(?:\d{3})?\b/g,
|
|
78
|
+
// MasterCard
|
|
79
|
+
/\b(?:5[1-5]\d{2}|222[1-9]|22[3-9]\d|2[3-6]\d{2}|27[01]\d|2720)\d{12}\b/g,
|
|
80
|
+
// Amex
|
|
81
|
+
/\b3[47]\d{13}\b/g,
|
|
82
|
+
// Diners Club
|
|
83
|
+
/\b3(?:0[0-5]|[68]\d)\d{11}\b/g,
|
|
84
|
+
// Discover
|
|
85
|
+
/\b6(?:011|5\d{2})\d{12}\b/g,
|
|
86
|
+
// JCB
|
|
87
|
+
/\b(?:2131|1800|35\d{3})\d{11}\b/g,
|
|
88
|
+
// Emails [https://www.regular-expressions.info/email.html]
|
|
89
|
+
PII_EMAIL_PATTERN,
|
|
90
|
+
// US SSN with or without dashes
|
|
91
|
+
// [https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s12.html]
|
|
92
|
+
/\b(?!000|666)[0-8]\d{2}[-.● ]?(?!00)\d{2}[-.● ]?(?!0000)\d{4}\b/g,
|
|
93
|
+
// Canadian SIN with or without dashes [https://regexpattern.com/social-insurance-number-ca]
|
|
94
|
+
/\b(\d{3}[-.● ]?\d{3}[-.● ]?\d{3})\b/g,
|
|
95
|
+
// International phone numbers
|
|
96
|
+
// [https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s03.html]
|
|
97
|
+
/\+(?:\d●?){6,14}\d\b/g,
|
|
98
|
+
// US/Canada phone numbers
|
|
99
|
+
// [https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s02.html]
|
|
100
|
+
/(\b|\+)?(1[-.● ]?)?\(?(\d{3})\)?[-.● ]?(\d{3})[-.● ]?(\d{4})\b/g,
|
|
101
|
+
];
|
|
102
|
+
const DEFAULT_WEBSITE_SUBDOMAIN_PATTERN = /^www\d{0,2}$/;
|
|
103
|
+
const PII_REDACTION_REPLACEMENT_STRING = '******';
|
|
104
|
+
// default string for stack frame fields
|
|
105
|
+
const DEFAULT_STACK_FRAME_FIELD_VALUE = '_';
|
|
106
|
+
// Disabled collect status keyword for local storage
|
|
107
|
+
const DISABLED_STATUS_KEY = 'DisabledStatus';
|
|
108
|
+
// Disabled collect status keyword for local storage
|
|
109
|
+
const CLIENT_UNLOCK_TIME_KEY = 'ClientUnlockTime';
|
|
110
|
+
// browser id keyword for local storage
|
|
111
|
+
const BROWSER_ID_KEY = 'BrowserId';
|
|
112
|
+
// current page visit count keyword for local storage
|
|
113
|
+
const CURRENT_PAGE_VISIT_COUNT_KEY = 'CurrentPageVisitCount';
|
|
114
|
+
// pv_id key for local storage
|
|
115
|
+
const PAGE_VISIT_ID_KEY = 'pvId';
|
|
116
|
+
// The local storage key for when a page was last active used to determine when to
|
|
117
|
+
// reset sequence numbers
|
|
118
|
+
const LAST_ACTIVE_TIME_KEY = 'LastActive';
|
|
119
|
+
// current PageVisit version to be sent from front end services
|
|
120
|
+
const CURRENT_PV_VERSION = 5;
|
|
121
|
+
// current metrics version to be sent from front end services.
|
|
122
|
+
const CURRENT_METRICS_VERSION = 1;
|
|
123
|
+
// severity levels for the collect error log
|
|
124
|
+
const SEVERITY_ERROR = 'error';
|
|
125
|
+
const SEVERITY_WARN = 'warn';
|
|
126
|
+
// maximum seconds that we can spend without sending anything
|
|
127
|
+
// to our backend. This needs to be less than Silverbolt's session innactivity
|
|
128
|
+
// time so that PVs don't become part of a separate web session.
|
|
129
|
+
const MAX_METROPLEX_SOCKET_INNACTIVE_TIME = 60 * 35;
|
|
130
|
+
// maximum number of page visits assigned to a single browser id
|
|
131
|
+
const MAX_PAGEVISIT_VISITED = 300;
|
|
132
|
+
const MAX_PAGEVISIT_EVENTS = 200;
|
|
133
|
+
// maximum ids that a user can add to a pagevisit
|
|
134
|
+
const MAX_CUSTOM_IDS_PER_PAGEVISIT = 10;
|
|
135
|
+
const MAX_CUSTOM_ERRORS_PER_PAGEVISIT = 500;
|
|
136
|
+
const NOIBUJS_SDK_REQUEST_HELP_CODE = 'requestHelpCode';
|
|
137
|
+
const NOIBUJS_SDK_ADD_ID_FUNCTION = 'addCustomAttribute';
|
|
138
|
+
const NOIBUJS_SDK_ADD_ERROR_FUNCTION = 'addError';
|
|
139
|
+
const NOIBUJS_SDK_ADD_ERROR_FROM_JS_FMW_FUNCTION = 'addJsSdkError';
|
|
140
|
+
// event targets that we overide to wrap erors
|
|
141
|
+
const EVENT_TARGETS = [
|
|
142
|
+
'Image',
|
|
143
|
+
'EventTarget',
|
|
144
|
+
'Window',
|
|
145
|
+
'Node',
|
|
146
|
+
'ApplicationCache',
|
|
147
|
+
'AudioTrackList',
|
|
148
|
+
'ChannelMergerNode',
|
|
149
|
+
'CryptoOperation',
|
|
150
|
+
'EventSource',
|
|
151
|
+
'FileReader',
|
|
152
|
+
'HTMLUnknownElement',
|
|
153
|
+
'IDBDatabase',
|
|
154
|
+
'IDBRequest',
|
|
155
|
+
'IDBTransaction',
|
|
156
|
+
'KeyOperation',
|
|
157
|
+
'MediaController',
|
|
158
|
+
'MessagePort',
|
|
159
|
+
'ModalWindow',
|
|
160
|
+
'Notification',
|
|
161
|
+
'SVGElementInstance',
|
|
162
|
+
'Screen',
|
|
163
|
+
'TextTrack',
|
|
164
|
+
'TextTrackCue',
|
|
165
|
+
'TextTrackList',
|
|
166
|
+
'WebSocket',
|
|
167
|
+
'WebSocketWorker',
|
|
168
|
+
'Worker',
|
|
169
|
+
'XMLHttpRequest',
|
|
170
|
+
'XMLHttpRequestEventTarget',
|
|
171
|
+
'XMLHttpRequestUpload',
|
|
172
|
+
];
|
|
173
|
+
// will return a regex that will match
|
|
174
|
+
// any keywords that may indicate that users are moving
|
|
175
|
+
// forward in the sales funnel. It will match add to cart, checkout,
|
|
176
|
+
// and any other relevant text.
|
|
177
|
+
// INFO: WHEN ARCEE CHANGES THE REGEX PATTERN, THIS NEEDS TO CHANGE TOO
|
|
178
|
+
// will return a regex that will match
|
|
179
|
+
// any keywords that may indicate that users are moving
|
|
180
|
+
// forward in the sales funnel. It will match add to cart, checkout,
|
|
181
|
+
// and any other relevant text.
|
|
182
|
+
// INFO: WHEN ARCEE CHANGES THE REGEX PATERN, THIS NEEDS TO CHANGE TOO
|
|
183
|
+
// text that have this id will not be masked, change arcee/src/models/websessions/pv_event.rs
|
|
184
|
+
const WHITELIST_HTML_ID_TEXT_REGEX = 'method|finance|sagepay|cart|bag|coupon|affirm|karna|sezzle|button';
|
|
185
|
+
// regex of human readable content based on content-type header
|
|
186
|
+
const HUMAN_READABLE_CONTENT_TYPE_REGEX = 'text|json|xml|html|graphql|x-www-form-urlencoded|form-data';
|
|
187
|
+
// the following constants are the data types that metroplex expexcts
|
|
188
|
+
const PV_METROPLEX_TYPE = 'p';
|
|
189
|
+
const VIDEO_METROPLEX_TYPE = 'v';
|
|
190
|
+
const META_DATA_METROPLEX_TYPE = 'm';
|
|
191
|
+
const HTTP_DATA_METROPLEX_TYPE = 'h';
|
|
192
|
+
// type for custom id metadata type
|
|
193
|
+
const CUSTOM_ID_NAME_TYPE = 'id_name';
|
|
194
|
+
const CUSTOM_ID_VALUE_TYPE = 'id_val';
|
|
195
|
+
// the following constants are attribute names that metroplex expects
|
|
196
|
+
// TODO: write functions that will create the necessary objects to be
|
|
197
|
+
// used as data input for metroplex instead of creating those objects them in the
|
|
198
|
+
// js files
|
|
199
|
+
const BROWSER_ID_ATT_NAME = 'br_id';
|
|
200
|
+
const PV_ID_ATT_NAME = 'pv_id';
|
|
201
|
+
const VER_ATT_NAME = 'v';
|
|
202
|
+
const PV_SEQ_ATT_NAME = 'seq';
|
|
203
|
+
const ON_URL_ATT_NAME = 'on_url';
|
|
204
|
+
const URL_ATT_NAME = 'url';
|
|
205
|
+
const REF_URL_ATT_NAME = 'ref_url';
|
|
206
|
+
const STARTED_AT_ATT_NAME = 'start_at';
|
|
207
|
+
const PV_EVENTS_ATT_NAME = 'events';
|
|
208
|
+
const PV_PART_COUNTER_ATT_NAME = 'pc';
|
|
209
|
+
const CONN_COUNT_ATT_NAME = 'conc';
|
|
210
|
+
const COLLECT_VER_ATT_NAME = 'cv';
|
|
211
|
+
const END_AT_ATT_NAME = 'end_at';
|
|
212
|
+
const IS_LAST_ATT_NAME = 'last';
|
|
213
|
+
const TYPE_ATT_NAME = 'type';
|
|
214
|
+
const OCCURRED_AT_ATT_NAME = 'occ_at';
|
|
215
|
+
const HTTP_CODE_ATT_NAME = 'h_code';
|
|
216
|
+
const JS_ERROR_ATT_NAME = 'j_err';
|
|
217
|
+
const GQL_ERROR_ATT_NAME = 'gql_err';
|
|
218
|
+
const TAGNAME_ATT_NAME = 'tag';
|
|
219
|
+
const SOURCE_ATT_NAME = 'src';
|
|
220
|
+
const TEXT_ATT_NAME = 'txt';
|
|
221
|
+
const HTMLID_ATT_NAME = 'hid';
|
|
222
|
+
const HTTP_METHOD_ATT_NAME = 'mtd';
|
|
223
|
+
const HTTP_RESP_CODE_ATT_NAME = 'code';
|
|
224
|
+
const HTTP_RESP_TIME_ATT_NAME = 'r_time';
|
|
225
|
+
const HTTP_RESP_LENGTH_ATT_NAME = 'resp_len';
|
|
226
|
+
const HTTP_DATA_PAYLOAD_ATT_NAME = 'rqp';
|
|
227
|
+
const HTTP_DATA_RESP_PAYLOAD_ATT_NAME = 'rsp';
|
|
228
|
+
const HTTP_DATA_REQ_HEADERS_ATT_NAME = 'rqh';
|
|
229
|
+
const HTTP_DATA_RESP_HEADERS_ATT_NAME = 'rsh';
|
|
230
|
+
const JS_STACK_LINE_ATT_NAME = 'line';
|
|
231
|
+
const JS_STACK_COL_ATT_NAME = 'column';
|
|
232
|
+
const JS_STACK_METHOD_ATT_NAME = 'mname';
|
|
233
|
+
const JS_STACK_FILE_ATT_NAME = 'file';
|
|
234
|
+
const JS_STACK_FRAMES_ATT_NAME = 'frames';
|
|
235
|
+
const JS_STACK_MESSAGE_ATT_NAME = 'msg';
|
|
236
|
+
const ERROR_SOURCE_ATT_NAME = 'err_src';
|
|
237
|
+
const CSS_CLASS_ATT_NAME = 'class';
|
|
238
|
+
const SEQ_NUM_ATT_NAME = 'seq_num';
|
|
239
|
+
const HELP_CODE_ATT_NAME = 'hc';
|
|
240
|
+
const WORK_REQUEST_ATT_NAME = 'wr';
|
|
241
|
+
const LANG_ATT_NAME = 'lang';
|
|
242
|
+
const SCRIPT_ID_ATT_NAME = 'script_id';
|
|
243
|
+
const SCRIPT_INSTANCE_ID_ATT_NAME = 'script_inst_id';
|
|
244
|
+
const METROPLEX_SOCKET_INSTANCE_ID_ATT_NAME = 'mp_sock_inst_id';
|
|
245
|
+
const SOCKET_INSTANCE_ID_ATT_NAME = 'sock_inst_id';
|
|
246
|
+
// The following are page visit metrics attributes
|
|
247
|
+
const EXP_VIDEO_LENGTH_ATT_NAME = 'exp_vid_len';
|
|
248
|
+
const PV_EXP_VF_SEQ_ATT_NAME = 'exp_vf_seq';
|
|
249
|
+
const PV_EXP_PART_COUNTER_ATT_NAME = 'exp_pc_seq';
|
|
250
|
+
const VIDEO_CLICKS_ATT_NAME = 'vid_clicks';
|
|
251
|
+
const PV_CLICKS_ATT_NAME = 'pv_clicks';
|
|
252
|
+
const DID_CUT_PV_ATT_NAME = 'did_cut_pv';
|
|
253
|
+
const DID_CUT_VID_ATT_NAME = 'did_cut_vid';
|
|
254
|
+
const DID_START_VID_ATT_NAME = 'did_start_vid';
|
|
255
|
+
const HTTP_COUNT_EXPECTED_ATT_NAME = 'exp_http';
|
|
256
|
+
const ERR_COUNT_EXPECTED_ATT_NAME = 'exp_err';
|
|
257
|
+
// http data metrics
|
|
258
|
+
const PV_EXP_HTTP_DATA_SEQ_ATT_NAME = 'exp_http_seq';
|
|
259
|
+
const PV_HTTP_PAYLOADS_COLLECTED_ATT_NAME = 'http_payloads';
|
|
260
|
+
const PV_HTTP_PAYLOADS_DROPPED_OVERSIZE_ATT_NAME = 'http_drop_oversize';
|
|
261
|
+
const PV_HTTP_PAYLOADS_DROPPED_TYPE_ATT_NAME = 'http_drop_type';
|
|
262
|
+
const PV_HTTP_REQUESTS_DROPPED_OVER_LIMIT = 'http_over_limit';
|
|
263
|
+
// the following are event types
|
|
264
|
+
const HTTP_EVENT_TYPE = 'http';
|
|
265
|
+
const JS_EVENT_TYPE = 'js';
|
|
266
|
+
const GQL_EVENT_TYPE = 'gql';
|
|
267
|
+
const USERSTEP_EVENT_TYPE = 'userstep';
|
|
268
|
+
const CLICK_EVENT_TYPE = 'click';
|
|
269
|
+
const KEYBOARD_EVENT_TYPE = 'kbd';
|
|
270
|
+
const LOCATION_EVENT_TYPE = 'loc';
|
|
271
|
+
const ERROR_EVENT_TYPE = 'err';
|
|
272
|
+
const PAGE_EVENT_TYPE = 'page';
|
|
273
|
+
// complete page visit attributes
|
|
274
|
+
const PAGE_VISIT_INFORMATION_ATT_NAME = 'pvi';
|
|
275
|
+
const PAGE_VISIT_PART_ATT_NAME = 'pvp';
|
|
276
|
+
const PAGE_VISIT_VID_FRAG_ATT_NAME = 'pvvf';
|
|
277
|
+
const PAGE_VISIT_META_DATA_ATT_NAME = 'pvm';
|
|
278
|
+
const PAGE_VISIT_HTTP_DATA_ATT_NAME = 'pvh';
|
|
279
|
+
const VIDEO_PART_COUNT_ATT_NAME = 'vpnum';
|
|
280
|
+
// window attributes
|
|
281
|
+
// global window config object name
|
|
282
|
+
const NOIBU_CONFIG_WIN_ATT_NAME = 'NOIBUJS_CONFIG';
|
|
283
|
+
// blocked selectors att name
|
|
284
|
+
const WIN_BLOCKED_SELECTOR_ATT_NAME = 'sel';
|
|
285
|
+
// script id, attribute set by blackout
|
|
286
|
+
const WIN_SCRIPT_ID_ATT_NAME = 'scriptID';
|
|
287
|
+
// njs version, attribute set by blackout
|
|
288
|
+
const WIN_NJS_VERSION_ATT_NAME = 'njs_version';
|
|
289
|
+
// attribute selector set by customers
|
|
290
|
+
const ATTRIBUTE_SELECTORS_ATT_NAME = 'att_sel';
|
|
291
|
+
// http data collection flag
|
|
292
|
+
const HTTP_DATA_COLLECTION_FLAG_NAME = 'http_data_collection';
|
|
293
|
+
// http data payload allowed list
|
|
294
|
+
const HTTP_DATA_PAYLOAD_URL_REGEXES_FLAG_NAME = 'http_re';
|
|
295
|
+
/**
|
|
296
|
+
*
|
|
297
|
+
* grabs the noibujs config from the config and returns it as an object
|
|
298
|
+
*/
|
|
299
|
+
function NOIBUJS_CONFIG() {
|
|
300
|
+
if (window[NOIBU_CONFIG_WIN_ATT_NAME]) {
|
|
301
|
+
return window[NOIBU_CONFIG_WIN_ATT_NAME];
|
|
302
|
+
}
|
|
303
|
+
return {};
|
|
304
|
+
}
|
|
305
|
+
// max size that can be sent from a beacon
|
|
306
|
+
// set to be 59kb right now
|
|
307
|
+
const MAX_BEACON_PAYLOAD_SIZE = 59000;
|
|
308
|
+
// maximum number of connection a single page visit can reach
|
|
309
|
+
const MAX_METROPLEX_CONNECTION_COUNT = 100;
|
|
310
|
+
// All urls that NoibuJS may talk to
|
|
311
|
+
const NOIBU_INPUT_URLS = [
|
|
312
|
+
'i.noibu',
|
|
313
|
+
'i.staging.noibu',
|
|
314
|
+
'input.staging.noibu',
|
|
315
|
+
'input.b.noibu',
|
|
316
|
+
'input.noibu',
|
|
317
|
+
'vf.staging.noibu',
|
|
318
|
+
'vf.noibu',
|
|
319
|
+
];
|
|
320
|
+
// the following are the routes declared in our backend systems
|
|
321
|
+
const METROPLEX_FRAG_ROUTE = 'pv_part';
|
|
322
|
+
const METROPLEX_ERROR_ROUTE = 'collect_error';
|
|
323
|
+
const METROPLEX_METRICS_ROUTE = 'metrics';
|
|
324
|
+
const METROPLEX_FULL_PV_ROUTE = 'pv';
|
|
325
|
+
// this message will be received from the socket if the client has to stop
|
|
326
|
+
// sending video messages
|
|
327
|
+
const STOP_STORING_VID_SOCKET_MESSAGE = 'vid_block';
|
|
328
|
+
// his message will be sent to the client if the client has to stop
|
|
329
|
+
// sending pv messages
|
|
330
|
+
const STOP_STORING_PV_SOCKET_MESSAGE = 'pv_block';
|
|
331
|
+
// this message will be received from the socket if the client has to stop
|
|
332
|
+
// execution and lock itself
|
|
333
|
+
const BLOCK_SOCKET_MESSAGE = 'full_block';
|
|
334
|
+
// message received when the connection needs to be closed for the session
|
|
335
|
+
const CLOSE_CONNECTION_FORCEFULLY = 'close_conn';
|
|
336
|
+
// this message will be received from the socket occasionnaly to indicate
|
|
337
|
+
// that the socket is healthy
|
|
338
|
+
const OK_SOCKET_MESSAGE = 'ok';
|
|
339
|
+
// types of error events
|
|
340
|
+
const XML_HTTP_REQUEST_ERROR_TYPE = 'XMLHttpRequest';
|
|
341
|
+
const ERROR_EVENT_ERROR_TYPE = 'ErrorEvent';
|
|
342
|
+
const ERROR_EVENT_UNHANDLED_REJECTION_TYPE = 'UnhandledRejectionError';
|
|
343
|
+
const EVENT_ERROR_TYPE = 'Event';
|
|
344
|
+
const RESPONSE_ERROR_TYPE = 'Response';
|
|
345
|
+
const GQL_ERROR_TYPE = 'GQLError';
|
|
346
|
+
const WRAPPED_EXCEPTION_ERROR_TYPE = 'WrappedException';
|
|
347
|
+
const FETCH_EXCEPTION_ERROR_TYPE = 'FetchException';
|
|
348
|
+
const ERROR_LOG_EVENT_ERROR_TYPE = 'ErrorLogEvent';
|
|
349
|
+
const CUSTOM_ERROR_EVENT_TYPE = 'CustomError';
|
|
350
|
+
const REACT_ERROR_EVENT_TYPE = 'ReactError';
|
|
351
|
+
const VUE_ERROR_EVENT_TYPE = 'VueError';
|
|
352
|
+
// console functions that we override to capture errors
|
|
353
|
+
const CONSOLE_FUNCTION_OVERRIDES = ['error', 'warn', 'log'];
|
|
354
|
+
// page events we track in the session
|
|
355
|
+
// don't include beforeunload, it will affect bfcache
|
|
356
|
+
const PAGE_EVENTS_WINDOW = [
|
|
357
|
+
'pagehide',
|
|
358
|
+
'pageshow',
|
|
359
|
+
'focus',
|
|
360
|
+
'blur',
|
|
361
|
+
// 'storage', // Disabled until compression is supported NOI-3998
|
|
362
|
+
'popstate',
|
|
363
|
+
'online',
|
|
364
|
+
'offline',
|
|
365
|
+
'messageerror',
|
|
366
|
+
// 'message', // Disabled until compression is supported NOI-3998
|
|
367
|
+
'languagechange',
|
|
368
|
+
'hashchange',
|
|
369
|
+
'beforeprint',
|
|
370
|
+
'afterprint',
|
|
371
|
+
'load',
|
|
372
|
+
'resize',
|
|
373
|
+
];
|
|
374
|
+
const PAGE_EVENTS_DOCUMENT = [
|
|
375
|
+
'visibilitychange',
|
|
376
|
+
'resume',
|
|
377
|
+
'freeze',
|
|
378
|
+
'readystatechange',
|
|
379
|
+
'cut',
|
|
380
|
+
'copy',
|
|
381
|
+
'paste',
|
|
382
|
+
];
|
|
383
|
+
// headers
|
|
384
|
+
const CONTENT_TYPE = 'content-type';
|
|
385
|
+
const CONTENT_LENGTH = 'content-length';
|
|
386
|
+
/**
|
|
387
|
+
*
|
|
388
|
+
* Gets the script id from the cookie object, returns default if cannot be found
|
|
389
|
+
*/
|
|
390
|
+
function GET_SCRIPT_ID() {
|
|
391
|
+
const noibuConfig = NOIBUJS_CONFIG();
|
|
392
|
+
if (noibuConfig[WIN_SCRIPT_ID_ATT_NAME]) {
|
|
393
|
+
return noibuConfig[WIN_SCRIPT_ID_ATT_NAME];
|
|
394
|
+
}
|
|
395
|
+
return 'default';
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
*
|
|
399
|
+
* Checks if the script version is beta
|
|
400
|
+
*/
|
|
401
|
+
function IS_NJS_VERSION_BETA() {
|
|
402
|
+
const noibuConfig = NOIBUJS_CONFIG();
|
|
403
|
+
if (noibuConfig[WIN_NJS_VERSION_ATT_NAME]) {
|
|
404
|
+
return noibuConfig[WIN_NJS_VERSION_ATT_NAME] === 'beta';
|
|
405
|
+
}
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
*
|
|
410
|
+
* Gets the max metro recon number
|
|
411
|
+
*/
|
|
412
|
+
function GET_MAX_METROPLEX_RECONNECTION_NUMBER() {
|
|
413
|
+
try {
|
|
414
|
+
// webpack variable
|
|
415
|
+
// eslint-disable-next-line no-undef
|
|
416
|
+
const maxConnNum = "20";
|
|
417
|
+
return maxConnNum;
|
|
418
|
+
}
|
|
419
|
+
catch (err) {
|
|
420
|
+
// during testing we only try to connect twice before abandoning
|
|
421
|
+
return 2;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
*
|
|
426
|
+
* Returns the amount of time in milliseconds to delay a new connection by
|
|
427
|
+
* if we have exceeded the max consecutive connection count
|
|
428
|
+
*/
|
|
429
|
+
function GET_METROPLEX_CONSECUTIVE_CONNECTION_DELAY() {
|
|
430
|
+
try {
|
|
431
|
+
// webpack variable
|
|
432
|
+
// eslint-disable-next-line no-undef
|
|
433
|
+
const consecConnDelay = "1000";
|
|
434
|
+
return consecConnDelay;
|
|
435
|
+
}
|
|
436
|
+
catch (err) {
|
|
437
|
+
// during testing we only delay by 1 second
|
|
438
|
+
return 1000;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
*
|
|
443
|
+
* gets the attribute selectors set by the customers to match an attribute
|
|
444
|
+
*/
|
|
445
|
+
function GET_ATTRIBUTE_SELECTORS() {
|
|
446
|
+
const noibuConfig = NOIBUJS_CONFIG();
|
|
447
|
+
if (noibuConfig[ATTRIBUTE_SELECTORS_ATT_NAME]) {
|
|
448
|
+
return noibuConfig[ATTRIBUTE_SELECTORS_ATT_NAME];
|
|
449
|
+
}
|
|
450
|
+
return {};
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
*
|
|
454
|
+
* gets the base url for metroplex's websocket connection
|
|
455
|
+
*/
|
|
456
|
+
function GET_METROPLEX_BASE_SOCKET_URL() {
|
|
457
|
+
try {
|
|
458
|
+
// webpack variables
|
|
459
|
+
const metroplexBaseURL = IS_NJS_VERSION_BETA()
|
|
460
|
+
? // eslint-disable-next-line no-undef
|
|
461
|
+
BETA_METROPLEX_BASE_SOCKET_URL
|
|
462
|
+
: // eslint-disable-next-line no-undef
|
|
463
|
+
"wss://input.noibu.com";
|
|
464
|
+
// removing the leading / if any
|
|
465
|
+
if (metroplexBaseURL.endsWith('/')) {
|
|
466
|
+
return metroplexBaseURL.slice(0, -1);
|
|
467
|
+
}
|
|
468
|
+
return metroplexBaseURL;
|
|
469
|
+
}
|
|
470
|
+
catch (err) {
|
|
471
|
+
return 'ws://localhost:3000';
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* gets the base url for metroplex's HTTP requests
|
|
476
|
+
*/
|
|
477
|
+
function GET_METROPLEX_BASE_HTTP_URL() {
|
|
478
|
+
try {
|
|
479
|
+
// webpack variable
|
|
480
|
+
const metroplexBaseURL = IS_NJS_VERSION_BETA()
|
|
481
|
+
? // eslint-disable-next-line no-undef
|
|
482
|
+
BETA_METROPLEX_BASE_HTTP_URL
|
|
483
|
+
: // eslint-disable-next-line no-undef
|
|
484
|
+
"https://input.noibu.com";
|
|
485
|
+
// removing the leading / if any
|
|
486
|
+
if (metroplexBaseURL.endsWith('/')) {
|
|
487
|
+
return metroplexBaseURL.slice(0, -1);
|
|
488
|
+
}
|
|
489
|
+
return metroplexBaseURL;
|
|
490
|
+
}
|
|
491
|
+
catch (err) {
|
|
492
|
+
return 'http://localhost:3000';
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
*
|
|
497
|
+
* Returns the URL that accepts http post requests
|
|
498
|
+
*/
|
|
499
|
+
function GET_METROPLEX_POST_URL() {
|
|
500
|
+
const httpBase = GET_METROPLEX_BASE_HTTP_URL();
|
|
501
|
+
return `${httpBase}/${METROPLEX_FULL_PV_ROUTE}`;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
*
|
|
505
|
+
* Returns the URL for posting metrics data to Metroplex
|
|
506
|
+
*/
|
|
507
|
+
function GET_METROPLEX_METRICS_URL() {
|
|
508
|
+
return `${GET_METROPLEX_BASE_HTTP_URL()}/${METROPLEX_METRICS_ROUTE}`;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
*
|
|
512
|
+
* gets the current env
|
|
513
|
+
*/
|
|
514
|
+
function JS_ENV() {
|
|
515
|
+
try {
|
|
516
|
+
// webpack variable
|
|
517
|
+
// eslint-disable-next-line no-undef
|
|
518
|
+
const currEnv = CURR_ENV;
|
|
519
|
+
return currEnv;
|
|
520
|
+
}
|
|
521
|
+
catch (err) {
|
|
522
|
+
return 'test';
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
// gets the frequency at which the client resends the message that were not confirmed by metroplex
|
|
526
|
+
const METROPLEX_RETRY_FREQUENCY = 30000;
|
|
527
|
+
|
|
528
|
+
export { ATTRIBUTE_SELECTORS_ATT_NAME, BLOCKED_HTTP_HEADER_KEYS, BLOCK_SOCKET_MESSAGE, BROWSER_ID_ATT_NAME, BROWSER_ID_KEY, CLICK_EVENT_TYPE, CLIENT_LOCK_TIME_MINUTES, CLIENT_UNLOCK_TIME_KEY, CLOSE_CONNECTION_FORCEFULLY, COLLECT_VER_ATT_NAME, CONN_COUNT_ATT_NAME, CONSOLE_FUNCTION_OVERRIDES, CONTENT_LENGTH, CONTENT_TYPE, CSS_CLASS_ATT_NAME, CURRENT_METRICS_VERSION, CURRENT_NOIBUJS_VERSION, CURRENT_PAGE_VISIT_COUNT_KEY, CURRENT_PV_VERSION, CUSTOM_ERROR_EVENT_TYPE, CUSTOM_ID_NAME_TYPE, CUSTOM_ID_VALUE_TYPE, DEFAULT_STACK_FRAME_FIELD_VALUE, DEFAULT_WEBSITE_SUBDOMAIN_PATTERN, DID_CUT_PV_ATT_NAME, DID_CUT_VID_ATT_NAME, DID_START_VID_ATT_NAME, DISABLED_STATUS_KEY, END_AT_ATT_NAME, ERROR_EVENT_ERROR_TYPE, ERROR_EVENT_TYPE, ERROR_EVENT_UNHANDLED_REJECTION_TYPE, ERROR_LOG_EVENT_ERROR_TYPE, ERROR_SOURCE_ATT_NAME, ERR_COUNT_EXPECTED_ATT_NAME, EVENT_ERROR_TYPE, EVENT_TARGETS, EXP_VIDEO_LENGTH_ATT_NAME, FETCH_EXCEPTION_ERROR_TYPE, GET_ATTRIBUTE_SELECTORS, GET_MAX_METROPLEX_RECONNECTION_NUMBER, GET_METROPLEX_BASE_HTTP_URL, GET_METROPLEX_BASE_SOCKET_URL, GET_METROPLEX_CONSECUTIVE_CONNECTION_DELAY, GET_METROPLEX_METRICS_URL, GET_METROPLEX_POST_URL, GET_SCRIPT_ID, GQL_ERROR_ATT_NAME, GQL_ERROR_TYPE, GQL_EVENT_TYPE, HELP_CODE_ATT_NAME, HTMLID_ATT_NAME, HTTP_BODY_DROPPED_LENGTH_MSG, HTTP_BODY_DROPPED_TYPE_MSG, HTTP_BODY_NULL_STRING, HTTP_CODE_ATT_NAME, HTTP_COUNT_EXPECTED_ATT_NAME, HTTP_DATA_COLLECTION_FLAG_NAME, HTTP_DATA_METROPLEX_TYPE, HTTP_DATA_PAYLOAD_ATT_NAME, HTTP_DATA_PAYLOAD_URL_REGEXES_FLAG_NAME, HTTP_DATA_REQ_HEADERS_ATT_NAME, HTTP_DATA_RESP_HEADERS_ATT_NAME, HTTP_DATA_RESP_PAYLOAD_ATT_NAME, HTTP_EVENT_TYPE, HTTP_METHOD_ATT_NAME, HTTP_PII_BLOCKING_PATTERNS, HTTP_RESP_CODE_ATT_NAME, HTTP_RESP_LENGTH_ATT_NAME, HTTP_RESP_TIME_ATT_NAME, HUMAN_READABLE_CONTENT_TYPE_REGEX, IS_LAST_ATT_NAME, IS_NJS_VERSION_BETA, JS_ENV, JS_ERROR_ATT_NAME, JS_EVENT_TYPE, JS_STACK_COL_ATT_NAME, JS_STACK_FILE_ATT_NAME, JS_STACK_FRAMES_ATT_NAME, JS_STACK_LINE_ATT_NAME, JS_STACK_MESSAGE_ATT_NAME, JS_STACK_METHOD_ATT_NAME, KEYBOARD_EVENT_TYPE, LANG_ATT_NAME, LAST_ACTIVE_TIME_KEY, LOCATION_EVENT_TYPE, MAX_BEACON_PAYLOAD_SIZE, MAX_COLLECT_ERROR_LOG, MAX_CUSTOM_ERRORS_PER_PAGEVISIT, MAX_CUSTOM_IDS_PER_PAGEVISIT, MAX_FRAMES_IN_ARRAY, MAX_HTTP_DATA_EVENT_COUNT, MAX_HTTP_DATA_PAYLOAD_LENGTH, MAX_METROPLEX_CONNECTION_COUNT, MAX_METROPLEX_SOCKET_INNACTIVE_TIME, MAX_PAGEVISIT_EVENTS, MAX_PAGEVISIT_PARTS, MAX_PAGEVISIT_VISITED, MAX_STRING_LENGTH, MAX_TIME_FOR_UNSENT_DATA_MILLIS, META_DATA_METROPLEX_TYPE, METROPLEX_ERROR_ROUTE, METROPLEX_FRAG_ROUTE, METROPLEX_FULL_PV_ROUTE, METROPLEX_METRICS_ROUTE, METROPLEX_RETRY_FREQUENCY, METROPLEX_SOCKET_INSTANCE_ID_ATT_NAME, NOIBUJS_CONFIG, NOIBUJS_SDK_ADD_ERROR_FROM_JS_FMW_FUNCTION, NOIBUJS_SDK_ADD_ERROR_FUNCTION, NOIBUJS_SDK_ADD_ID_FUNCTION, NOIBUJS_SDK_REQUEST_HELP_CODE, NOIBU_BROWSER_ID_KYWRD, NOIBU_CONFIG_WIN_ATT_NAME, NOIBU_INPUT_URLS, NOIBU_LOCAL_STORAGE_TEST_KEY, NOIBU_STORED_PAGE_VISIT, OCCURRED_AT_ATT_NAME, OK_SOCKET_MESSAGE, ON_URL_ATT_NAME, PAGE_EVENTS_DOCUMENT, PAGE_EVENTS_WINDOW, PAGE_EVENT_TYPE, PAGE_VISIT_HTTP_DATA_ATT_NAME, PAGE_VISIT_ID_KEY, PAGE_VISIT_INFORMATION_ATT_NAME, PAGE_VISIT_META_DATA_ATT_NAME, PAGE_VISIT_PART_ATT_NAME, PAGE_VISIT_VID_FRAG_ATT_NAME, PII_DIGIT_PATTERN, PII_EMAIL_PATTERN, PII_REDACTION_REPLACEMENT_STRING, PV_CLICKS_ATT_NAME, PV_EVENTS_ATT_NAME, PV_EXP_HTTP_DATA_SEQ_ATT_NAME, PV_EXP_PART_COUNTER_ATT_NAME, PV_EXP_VF_SEQ_ATT_NAME, PV_HTTP_PAYLOADS_COLLECTED_ATT_NAME, PV_HTTP_PAYLOADS_DROPPED_OVERSIZE_ATT_NAME, PV_HTTP_PAYLOADS_DROPPED_TYPE_ATT_NAME, PV_HTTP_REQUESTS_DROPPED_OVER_LIMIT, PV_ID_ATT_NAME, PV_METROPLEX_TYPE, PV_PART_COUNTER_ATT_NAME, PV_SEQ_ATT_NAME, PV_SEQ_NUM_RESET_TIME_MINUTES, REACT_ERROR_EVENT_TYPE, REF_URL_ATT_NAME, REQUIRED_DATA_PROCESSING_URLS, RESPONSE_ERROR_TYPE, SCRIPT_ID_ATT_NAME, SCRIPT_INSTANCE_ID_ATT_NAME, SEQ_NUM_ATT_NAME, SEVERITY_ERROR, SEVERITY_WARN, SOCKET_INSTANCE_ID_ATT_NAME, SOURCE_ATT_NAME, STARTED_AT_ATT_NAME, STOP_STORING_PV_SOCKET_MESSAGE, STOP_STORING_VID_SOCKET_MESSAGE, TAGNAME_ATT_NAME, TEXT_ATT_NAME, TYPE_ATT_NAME, URL_ATT_NAME, USERSTEP_EVENT_TYPE, VER_ATT_NAME, VIDEO_CLICKS_ATT_NAME, VIDEO_METROPLEX_TYPE, VIDEO_PART_COUNT_ATT_NAME, VUE_ERROR_EVENT_TYPE, WHITELIST_HTML_ID_TEXT_REGEX, WIN_BLOCKED_SELECTOR_ATT_NAME, WIN_NJS_VERSION_ATT_NAME, WIN_SCRIPT_ID_ATT_NAME, WORK_REQUEST_ATT_NAME, WRAPPED_EXCEPTION_ERROR_TYPE, XML_HTTP_REQUEST_ERROR_TYPE };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ErrorBoundary as _ErrorBoundary } from '../react/ErrorBoundary';
|
|
2
|
+
export declare const NoibuJS: {
|
|
3
|
+
requestHelpCode: (alert?: boolean | undefined) => Promise<string>;
|
|
4
|
+
addCustomAttribute: (name: string, value: string) => string;
|
|
5
|
+
addError: (customError: Error) => string;
|
|
6
|
+
addJsSdkError: (customError: string, errorSource: string) => string;
|
|
7
|
+
};
|
|
8
|
+
export declare const ErrorBoundary: typeof _ErrorBoundary;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GET_METROPLEX_BASE_SOCKET_URL, GET_METROPLEX_BASE_HTTP_URL } from '../constants.js';
|
|
2
|
+
import globalInit from './init.js';
|
|
3
|
+
import { ErrorBoundary as ErrorBoundary$1 } from '../react/ErrorBoundary.js';
|
|
4
|
+
import InputManager from '../api/inputManager.js';
|
|
5
|
+
|
|
6
|
+
// these are set via webbpack
|
|
7
|
+
const urlConfig = {
|
|
8
|
+
metroplexSocketBase: GET_METROPLEX_BASE_SOCKET_URL(),
|
|
9
|
+
metroplexHTTPBase: GET_METROPLEX_BASE_HTTP_URL(),
|
|
10
|
+
};
|
|
11
|
+
globalInit(urlConfig);
|
|
12
|
+
const NoibuJS = InputManager.getInstance().exposeFunctions();
|
|
13
|
+
const ErrorBoundary = ErrorBoundary$1;
|
|
14
|
+
|
|
15
|
+
export { ErrorBoundary, NoibuJS };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { setupURLPolyfill } from 'react-native-url-polyfill';
|
|
2
|
+
import uuid from 'react-native-uuid';
|
|
3
|
+
import { monitorErrors } from '../monitors/errorMonitor.js';
|
|
4
|
+
import { monitorRequests } from '../monitors/requestMonitor.js';
|
|
5
|
+
import { ClickMonitor } from '../monitors/clickMonitor.js';
|
|
6
|
+
import { KeyboardInputMonitor } from '../monitors/keyboardInputMonitor.js';
|
|
7
|
+
import { monitorLocation } from '../monitors/locationChangeMonitor.js';
|
|
8
|
+
import { PageVisit } from '../pageVisit/pageVisit.js';
|
|
9
|
+
import { METROPLEX_ERROR_ROUTE, SEVERITY_ERROR } from '../constants.js';
|
|
10
|
+
import ClientConfig from '../api/clientConfig.js';
|
|
11
|
+
import { PageMonitor } from '../monitors/pageMonitor.js';
|
|
12
|
+
import { HTTPDataBundler } from '../monitors/httpDataBundler.js';
|
|
13
|
+
import { ElementMonitor } from '../monitors/elementMonitor.js';
|
|
14
|
+
import { isInvalidURLConfig, isNoibuJSAlreadyLoaded } from '../utils/function.js';
|
|
15
|
+
import MetroplexSocket from '../api/metroplexSocket.js';
|
|
16
|
+
import StoredPageVisit from '../api/storedPageVisit.js';
|
|
17
|
+
import HelpCode from '../api/helpCode.js';
|
|
18
|
+
|
|
19
|
+
/** @module Init */
|
|
20
|
+
/**
|
|
21
|
+
* initilializes the script to start executing all of NJS features
|
|
22
|
+
* @param {} urlConfig
|
|
23
|
+
*/
|
|
24
|
+
function globalInit(urlConfig) {
|
|
25
|
+
setupURLPolyfill();
|
|
26
|
+
|
|
27
|
+
// if the config url is invalid we block collect from executing
|
|
28
|
+
if (isInvalidURLConfig(urlConfig)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ensure only one copy of NoibuJS is running at a time
|
|
33
|
+
if (isNoibuJSAlreadyLoaded()) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const clterrEndpoint = `${urlConfig.metroplexHTTPBase}/${METROPLEX_ERROR_ROUTE}`;
|
|
37
|
+
ClientConfig.configureInstance(clterrEndpoint);
|
|
38
|
+
|
|
39
|
+
// catch any errors that happened during initialization and send collect error
|
|
40
|
+
try {
|
|
41
|
+
// create an instance ID for this script
|
|
42
|
+
const instanceId = uuid.v4();
|
|
43
|
+
|
|
44
|
+
// verifying if collect was disabled by other microservices
|
|
45
|
+
if (ClientConfig.getInstance().isClientDisabled) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
HelpCode.getInstance();
|
|
50
|
+
|
|
51
|
+
// Call MetroplexSocket getInstance to have it setup the socket before anything
|
|
52
|
+
// else accesses it
|
|
53
|
+
const metroplexSocket = MetroplexSocket.getInstance(instanceId);
|
|
54
|
+
PageVisit.configureInstance();
|
|
55
|
+
// Call the stored page visit get instance, so we post the previous page visit right away
|
|
56
|
+
StoredPageVisit.getInstance();
|
|
57
|
+
|
|
58
|
+
// singleton monitors
|
|
59
|
+
const keyboardInputMonitor = new KeyboardInputMonitor();
|
|
60
|
+
const clickMonitor = ClickMonitor.getInstance();
|
|
61
|
+
const pageMonitor = PageMonitor.getInstance();
|
|
62
|
+
const elementMonitor = ElementMonitor.getInstance();
|
|
63
|
+
HTTPDataBundler.getInstance();
|
|
64
|
+
// monitoring calls
|
|
65
|
+
monitorErrors();
|
|
66
|
+
monitorRequests();
|
|
67
|
+
clickMonitor.monitorClicks();
|
|
68
|
+
monitorLocation();
|
|
69
|
+
keyboardInputMonitor.monitor();
|
|
70
|
+
pageMonitor.monitor();
|
|
71
|
+
elementMonitor.monitor();
|
|
72
|
+
// session recorder, only ran after the window has loaded to not add burden on the
|
|
73
|
+
// initial page load time.
|
|
74
|
+
// Also wait until metroplex has acknowledged, in case video is blocked
|
|
75
|
+
metroplexSocket.connectionPromise.catch(e =>
|
|
76
|
+
ClientConfig.getInstance().postNoibuErrorAndOptionallyDisableClient(
|
|
77
|
+
`Error during metroplexSocket initial connection: ${e}`,
|
|
78
|
+
false,
|
|
79
|
+
SEVERITY_ERROR,
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
ClientConfig.getInstance().postNoibuErrorAndOptionallyDisableClient(
|
|
84
|
+
`Error during globalInit: ${err}`,
|
|
85
|
+
true,
|
|
86
|
+
SEVERITY_ERROR,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { globalInit as default };
|