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,233 @@
|
|
|
1
|
+
import { NOIBUJS_SDK_REQUEST_HELP_CODE, NOIBUJS_SDK_ADD_ID_FUNCTION, NOIBUJS_SDK_ADD_ERROR_FUNCTION, NOIBUJS_SDK_ADD_ERROR_FROM_JS_FMW_FUNCTION, MAX_CUSTOM_ERRORS_PER_PAGEVISIT, REACT_ERROR_EVENT_TYPE, VUE_ERROR_EVENT_TYPE, MAX_CUSTOM_IDS_PER_PAGEVISIT, META_DATA_METROPLEX_TYPE, PAGE_VISIT_META_DATA_ATT_NAME, CUSTOM_ID_NAME_TYPE, CUSTOM_ID_VALUE_TYPE, CUSTOM_ERROR_EVENT_TYPE } from '../constants.js';
|
|
2
|
+
import MetroplexSocket from './metroplexSocket.js';
|
|
3
|
+
import { saveErrorToPagevisit } from '../pageVisit/pageVisitEventError/pageVisitEventError.js';
|
|
4
|
+
import HelpCode from './helpCode.js';
|
|
5
|
+
|
|
6
|
+
/** @module InputManager */
|
|
7
|
+
|
|
8
|
+
/** this class controls the input that customers can inject into
|
|
9
|
+
* our script via the NoibuJS SDK
|
|
10
|
+
*/
|
|
11
|
+
class InputManager {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new InputManager
|
|
14
|
+
*/
|
|
15
|
+
constructor() {
|
|
16
|
+
this.customIDs = {};
|
|
17
|
+
this.customErrorsCount = 0;
|
|
18
|
+
|
|
19
|
+
this.TOO_MANY_IDS_ADDED_MSG = 'TOO_MANY_IDS_ADDED';
|
|
20
|
+
this.ID_NAME_ALREADY_ADDED_MSG = 'ID_NAME_ALREADY_ADDED';
|
|
21
|
+
this.NAME_TOO_LONG_MSG = 'NAME_TOO_LONG';
|
|
22
|
+
this.VALUE_TOO_LONG_MSG = 'VALUE_TOO_LONG';
|
|
23
|
+
this.INVALID_NAME_TYPE_MSG = 'INVALID_NAME_TYPE';
|
|
24
|
+
this.INVALID_VALUE_TYPE_MSG = 'INVALID_VALUE_TYPE';
|
|
25
|
+
this.NAME_HAS_NO_LENGTH_MSG = 'NAME_HAS_NO_LENGTH';
|
|
26
|
+
this.VALUE_HAS_NO_LENGTH_MSG = 'VALUE_HAS_NO_LENGTH';
|
|
27
|
+
this.SUCCESS_MSG = 'SUCCESS';
|
|
28
|
+
this.ERROR_HAS_NO_MSG_MSG = 'ERROR_HAS_NO_MSG';
|
|
29
|
+
this.ERROR_HAS_NO_STACK_MSG = 'ERROR_HAS_NO_STACK';
|
|
30
|
+
this.NULL_CUSTOM_ERR_MSG = 'NULL_CUSTOM_ERROR';
|
|
31
|
+
this.ERROR_ALREADY_RECEIVED_MSG = 'ERROR_ALREADY_RECEIVED';
|
|
32
|
+
this.INVALID_ERROR_SOURCE_MSG = 'INVALID_ERROR_SOURCE_MSG';
|
|
33
|
+
this.TOO_MANY_ERRORS_RECEIVED_PER_PAGEVISIT_MSG =
|
|
34
|
+
'TOO_MANY_ERRORS_RECEIVED_PER_PAGEVISIT';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** gets the singleton instance */
|
|
38
|
+
static getInstance() {
|
|
39
|
+
if (!this.instance) {
|
|
40
|
+
this.instance = new InputManager();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return this.instance;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** exposes functions to the window of the browser for the clients
|
|
47
|
+
* to interact with on their end
|
|
48
|
+
*/
|
|
49
|
+
exposeFunctions() {
|
|
50
|
+
return this._getSDKWindowObject();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* gets the sdk object that will be assigned to a window variable
|
|
55
|
+
* @returns {{
|
|
56
|
+
* requestHelpCode: (alert?: boolean) => Promise<string>,
|
|
57
|
+
* addCustomAttribute: (name: string, value: string) => string,
|
|
58
|
+
* addError: (customError: Error) => string,
|
|
59
|
+
* addJsSdkError: (customError: string, errorSource: string) => string
|
|
60
|
+
* }}
|
|
61
|
+
*/
|
|
62
|
+
_getSDKWindowObject() {
|
|
63
|
+
return {
|
|
64
|
+
// adding all the functions and binding the current context
|
|
65
|
+
// so that we can use the exposed function as if they are running`
|
|
66
|
+
// in the noibujs script
|
|
67
|
+
[NOIBUJS_SDK_REQUEST_HELP_CODE]: this._requestHelpCode.bind(this),
|
|
68
|
+
[NOIBUJS_SDK_ADD_ID_FUNCTION]: this._addCustomAttribute.bind(this),
|
|
69
|
+
[NOIBUJS_SDK_ADD_ERROR_FUNCTION]: this._addCustomError.bind(this),
|
|
70
|
+
[NOIBUJS_SDK_ADD_ERROR_FROM_JS_FMW_FUNCTION]:
|
|
71
|
+
this._addErrorFromJSSdk.bind(this),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* validates the custom error that was passed
|
|
77
|
+
* @param {} customError
|
|
78
|
+
*/
|
|
79
|
+
_validateCustomError(customError) {
|
|
80
|
+
// customError cannot be null
|
|
81
|
+
if (!customError) {
|
|
82
|
+
return this.NULL_CUSTOM_ERR_MSG;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// making sure we have the message and stack to create an error signature
|
|
86
|
+
if (!customError.message) {
|
|
87
|
+
return this.ERROR_HAS_NO_MSG_MSG;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!customError.stack) {
|
|
91
|
+
return this.ERROR_HAS_NO_STACK_MSG;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return this.SUCCESS_MSG;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Validates and sets the custom error to our internal trackers
|
|
99
|
+
* @param {} customError
|
|
100
|
+
*/
|
|
101
|
+
_validateAndSetCustomError(customError) {
|
|
102
|
+
// we cap the number of errors allowed to be sent
|
|
103
|
+
if (this.customErrorsCount >= MAX_CUSTOM_ERRORS_PER_PAGEVISIT) {
|
|
104
|
+
return this.TOO_MANY_ERRORS_RECEIVED_PER_PAGEVISIT_MSG;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// need to validate first before we start operating with the received
|
|
108
|
+
// data
|
|
109
|
+
const validationResult = this._validateCustomError(customError);
|
|
110
|
+
if (validationResult !== this.SUCCESS_MSG) {
|
|
111
|
+
return validationResult;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this.customErrorsCount += 1;
|
|
115
|
+
return this.SUCCESS_MSG;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* adds an error from a JS Sdk to the session
|
|
120
|
+
* @param {} customError
|
|
121
|
+
*/
|
|
122
|
+
_addErrorFromJSSdk(customError, errorSource) {
|
|
123
|
+
const validationAndSettingResult =
|
|
124
|
+
this._validateAndSetCustomError(customError);
|
|
125
|
+
if (validationAndSettingResult !== this.SUCCESS_MSG) {
|
|
126
|
+
return validationAndSettingResult;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// we only support two sdks today, increase this list as we add more
|
|
130
|
+
if (
|
|
131
|
+
errorSource !== REACT_ERROR_EVENT_TYPE &&
|
|
132
|
+
errorSource !== VUE_ERROR_EVENT_TYPE
|
|
133
|
+
) {
|
|
134
|
+
return this.INVALID_ERROR_SOURCE_MSG;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
saveErrorToPagevisit(errorSource, { error: customError });
|
|
138
|
+
return validationAndSettingResult;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* adds a custom Error to the session
|
|
143
|
+
* @param {} customError
|
|
144
|
+
*/
|
|
145
|
+
_addCustomError(customError) {
|
|
146
|
+
const validationAndSettingResult =
|
|
147
|
+
this._validateAndSetCustomError(customError);
|
|
148
|
+
if (validationAndSettingResult !== this.SUCCESS_MSG) {
|
|
149
|
+
return validationAndSettingResult;
|
|
150
|
+
}
|
|
151
|
+
saveErrorToPagevisit(CUSTOM_ERROR_EVENT_TYPE, { error: customError });
|
|
152
|
+
return validationAndSettingResult;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* adds a custom id to the session
|
|
157
|
+
* @param {} name
|
|
158
|
+
* @param {} value
|
|
159
|
+
*/
|
|
160
|
+
_addCustomAttribute(name, value) {
|
|
161
|
+
// we return if we are over the limit of ids
|
|
162
|
+
if (Object.keys(this.customIDs).length >= MAX_CUSTOM_IDS_PER_PAGEVISIT) {
|
|
163
|
+
return this.TOO_MANY_IDS_ADDED_MSG;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// need to validate first before we start operating with the received
|
|
167
|
+
// data
|
|
168
|
+
const validationResult = this._validateCustomIDInput(name, value);
|
|
169
|
+
if (validationResult !== this.SUCCESS_MSG) {
|
|
170
|
+
return validationResult;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// we do not want to keep sending something that was already sent
|
|
174
|
+
if (name in this.customIDs) {
|
|
175
|
+
return this.ID_NAME_ALREADY_ADDED_MSG;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
this.customIDs[name] = value;
|
|
179
|
+
MetroplexSocket.getInstance().sendMessage(META_DATA_METROPLEX_TYPE, {
|
|
180
|
+
[PAGE_VISIT_META_DATA_ATT_NAME]: {
|
|
181
|
+
[CUSTOM_ID_NAME_TYPE]: name,
|
|
182
|
+
[CUSTOM_ID_VALUE_TYPE]: value,
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return this.SUCCESS_MSG;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* validation function for customer input
|
|
191
|
+
* @param {} name
|
|
192
|
+
* @param {} value
|
|
193
|
+
*/
|
|
194
|
+
_validateCustomIDInput(name, value) {
|
|
195
|
+
// all ids need to be strings and less than 50 chars and more than 0 chars
|
|
196
|
+
if (typeof name !== 'string') {
|
|
197
|
+
return this.INVALID_NAME_TYPE_MSG;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (typeof value !== 'string') {
|
|
201
|
+
return this.INVALID_VALUE_TYPE_MSG;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (value.length > 50) {
|
|
205
|
+
return this.VALUE_TOO_LONG_MSG;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (name.length > 50) {
|
|
209
|
+
return this.NAME_TOO_LONG_MSG;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (value.length === 0) {
|
|
213
|
+
return this.VALUE_HAS_NO_LENGTH_MSG;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (name.length === 0) {
|
|
217
|
+
return this.NAME_HAS_NO_LENGTH_MSG;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return this.SUCCESS_MSG;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Requests a help code from the HelpCode instance.
|
|
225
|
+
* @param {boolean} [alertUser=true] - Whether to alert the user about the help code request.
|
|
226
|
+
* @returns {Promise<string>} A promise that resolves with the requested help code.
|
|
227
|
+
*/
|
|
228
|
+
_requestHelpCode(alertUser = true) {
|
|
229
|
+
return HelpCode.getInstance().requestHelpCode(alertUser);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export { InputManager as default };
|