noibu-react-native 0.2.6 → 0.2.8

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 (114) hide show
  1. package/README.md +15 -15
  2. package/android/build.gradle +1 -1
  3. package/dist/{src/api/clientConfig.d.ts → api/ClientConfig.d.ts} +19 -20
  4. package/dist/api/{clientConfig.js → ClientConfig.js} +82 -63
  5. package/dist/{src/api/helpCode.d.ts → api/HelpCode.d.ts} +3 -10
  6. package/dist/api/{helpCode.js → HelpCode.js} +8 -14
  7. package/dist/api/InputManager.d.ts +39 -0
  8. package/dist/api/InputManager.js +156 -0
  9. package/dist/{src/api/metroplexSocket.d.ts → api/MetroplexSocket.d.ts} +33 -38
  10. package/dist/api/{metroplexSocket.js → MetroplexSocket.js} +190 -178
  11. package/dist/{src/api/storedMetrics.d.ts → api/StoredMetrics.d.ts} +10 -20
  12. package/dist/api/StoredMetrics.js +158 -0
  13. package/dist/{src/api/storedPageVisit.d.ts → api/StoredPageVisit.d.ts} +11 -8
  14. package/dist/api/{storedPageVisit.js → StoredPageVisit.js} +62 -48
  15. package/dist/const_matchers.js +1 -5
  16. package/dist/constants.d.ts +48 -0
  17. package/dist/constants.js +15 -397
  18. package/dist/{src/entry → entry}/index.d.ts +5 -6
  19. package/dist/entry/index.js +3 -4
  20. package/dist/entry/init.d.ts +8 -0
  21. package/dist/entry/init.js +34 -19
  22. package/dist/monitors/AppNavigationMonitor.d.ts +10 -0
  23. package/dist/monitors/AppNavigationMonitor.js +19 -19
  24. package/dist/monitors/AppNavigationMonitor.test.d.ts +1 -0
  25. package/dist/{src/monitors → monitors}/BaseMonitor.d.ts +5 -5
  26. package/dist/monitors/BaseMonitor.js +9 -4
  27. package/dist/monitors/BaseMonitor.test.d.ts +1 -0
  28. package/dist/{src/monitors → monitors}/ClickMonitor.d.ts +10 -13
  29. package/dist/monitors/ClickMonitor.js +72 -76
  30. package/dist/monitors/ClickMonitor.test.d.ts +1 -0
  31. package/dist/{src/monitors → monitors}/ErrorMonitor.d.ts +4 -28
  32. package/dist/monitors/ErrorMonitor.js +45 -55
  33. package/dist/{src/monitors → monitors}/KeyboardInputMonitor.d.ts +1 -3
  34. package/dist/monitors/KeyboardInputMonitor.js +13 -11
  35. package/dist/{src/monitors → monitors}/PageMonitor.d.ts +1 -1
  36. package/dist/monitors/PageMonitor.js +25 -2
  37. package/dist/{src/monitors → monitors}/RequestMonitor.d.ts +9 -29
  38. package/dist/monitors/RequestMonitor.js +46 -57
  39. package/dist/monitors/http-tools/GqlErrorValidator.d.ts +35 -0
  40. package/dist/monitors/http-tools/GqlErrorValidator.js +42 -70
  41. package/dist/{src/monitors → monitors}/http-tools/HTTPDataBundler.d.ts +9 -15
  42. package/dist/monitors/http-tools/HTTPDataBundler.js +74 -67
  43. package/dist/monitors/integrations/ReactNativeNavigationIntegration.d.ts +17 -0
  44. package/dist/monitors/integrations/{react-native-navigation-integration.js → ReactNativeNavigationIntegration.js} +15 -12
  45. package/dist/{src/pageVisit → pageVisit}/EventDebouncer.d.ts +9 -10
  46. package/dist/pageVisit/EventDebouncer.js +43 -74
  47. package/dist/pageVisit/HttpEventManager.d.ts +14 -0
  48. package/dist/pageVisit/HttpEventManager.js +88 -0
  49. package/dist/pageVisit/PageVisitManager.d.ts +31 -0
  50. package/dist/pageVisit/PageVisitManager.js +99 -0
  51. package/dist/pageVisit/pageVisitEventError.d.ts +12 -0
  52. package/dist/pageVisit/pageVisitEventError.js +170 -280
  53. package/dist/{src/react → react}/ErrorBoundary.d.ts +4 -9
  54. package/dist/react/ErrorBoundary.js +3 -6
  55. package/dist/{src/sessionRecorder/sessionRecorder.d.ts → sessionRecorder/SessionRecorder.d.ts} +7 -17
  56. package/dist/sessionRecorder/{sessionRecorder.js → SessionRecorder.js} +60 -71
  57. package/dist/{src/sessionRecorder → sessionRecorder}/nativeSessionRecorderSubscription.d.ts +4 -6
  58. package/dist/sessionRecorder/nativeSessionRecorderSubscription.js +3 -5
  59. package/dist/{src/storage/rnStorageProvider.d.ts → storage/RNStorageProvider.d.ts} +4 -8
  60. package/dist/storage/{rnStorageProvider.js → RNStorageProvider.js} +3 -7
  61. package/dist/{src/storage/storage.d.ts → storage/Storage.d.ts} +8 -18
  62. package/dist/storage/{storage.js → Storage.js} +17 -30
  63. package/dist/{src/storage/storageProvider.d.ts → storage/StorageProvider.d.ts} +5 -8
  64. package/dist/storage/{storageProvider.js → StorageProvider.js} +7 -8
  65. package/dist/types/NavigationIntegration.d.ts +1 -1
  66. package/dist/utils/date.d.ts +7 -0
  67. package/dist/utils/date.js +41 -51
  68. package/dist/utils/eventlistener.js +6 -14
  69. package/dist/{src/utils → utils}/function.d.ts +13 -43
  70. package/dist/utils/function.js +42 -113
  71. package/dist/utils/log.d.ts +4 -0
  72. package/dist/utils/log.js +2 -4
  73. package/dist/{src/utils → utils}/object.d.ts +10 -8
  74. package/dist/utils/object.js +12 -12
  75. package/dist/{src/utils → utils}/performance.d.ts +1 -1
  76. package/dist/utils/piiRedactor.js +31 -3
  77. package/dist/utils/stacktrace-parser.d.ts +8 -0
  78. package/dist/utils/stacktrace-parser.js +29 -21
  79. package/dist/utils/stacktrace-parser.test.d.ts +1 -0
  80. package/package.json +14 -14
  81. package/dist/api/inputManager.js +0 -227
  82. package/dist/api/storedMetrics.js +0 -198
  83. package/dist/pageVisit/pageVisit.js +0 -181
  84. package/dist/pageVisit/pageVisitEventHTTP.js +0 -98
  85. package/dist/pageVisit/userStep.js +0 -20
  86. package/dist/src/api/inputManager.d.ts +0 -87
  87. package/dist/src/constants.d.ts +0 -290
  88. package/dist/src/entry/init.d.ts +0 -5
  89. package/dist/src/monitors/AppNavigationMonitor.d.ts +0 -18
  90. package/dist/src/monitors/http-tools/GqlErrorValidator.d.ts +0 -59
  91. package/dist/src/monitors/integrations/react-native-navigation-integration.d.ts +0 -20
  92. package/dist/src/pageVisit/pageVisit.d.ts +0 -52
  93. package/dist/src/pageVisit/pageVisitEventError.d.ts +0 -15
  94. package/dist/src/pageVisit/pageVisitEventHTTP.d.ts +0 -25
  95. package/dist/src/pageVisit/userStep.d.ts +0 -5
  96. package/dist/src/utils/date.d.ts +0 -6
  97. package/dist/src/utils/log.d.ts +0 -4
  98. package/dist/src/utils/stacktrace-parser.d.ts +0 -7
  99. package/dist/types/Config.d.ts +0 -31
  100. package/dist/types/Metroplex.types.d.ts +0 -73
  101. package/dist/types/PageVisit.types.d.ts +0 -8
  102. package/dist/types/PageVisitErrors.types.d.ts +0 -114
  103. package/dist/types/PageVisitEvents.types.d.ts +0 -91
  104. package/dist/types/PageVisitMetrics.types.d.ts +0 -27
  105. package/dist/types/Storage.d.ts +0 -14
  106. package/dist/types/StoredPageVisit.types.d.ts +0 -11
  107. package/dist/types/WrappedObjects.d.ts +0 -6
  108. /package/dist/{src/api/clientConfig.test.d.ts → api/ClientConfig.test.d.ts} +0 -0
  109. /package/dist/{src/monitors/BaseMonitor.test.d.ts → api/MetroplexSocket.test.d.ts} +0 -0
  110. /package/dist/{src/const_matchers.d.ts → const_matchers.d.ts} +0 -0
  111. /package/dist/{src/sessionRecorder → sessionRecorder}/types.d.ts +0 -0
  112. /package/dist/{src/utils → utils}/eventlistener.d.ts +0 -0
  113. /package/dist/{src/utils → utils}/piiRedactor.d.ts +0 -0
  114. /package/dist/{src/utils → utils}/polyfills.d.ts +0 -0
package/README.md CHANGED
@@ -27,7 +27,8 @@ Install using favourite node package manager (npm, yarn, etc.):
27
27
  npm install noibu-react-native --save
28
28
  ```
29
29
 
30
- Additionally, for iOS target do:
30
+ Additionally, for iOS target do:
31
+
31
32
  ```bash
32
33
  npx pod-install
33
34
  ```
@@ -65,22 +66,21 @@ That's it! First time the module is set up, it runs an init and starts listening
65
66
  ## Configuration
66
67
 
67
68
  `setupNoibu(config): void` method accepts following parameters:
68
- - `config` which consists of
69
- - `@property domain {string}` - indicates which Noibu dashboard session recordings should go to ([learn more about domains](https://help.noibu.com/hc/en-us/articles/4846518088845-Domains-Overview))
70
- - `@property [blockedElements] {string[]}` - lets you specify component ids to be ignored by SDK when collecting error information
71
- - `@property [enableHttpDataCollection] {boolean}` - indicates whether SDK should collect HTTP information like headers or body from requests
72
- - `@property [listOfUrlsToCollectHttpDataFrom] {string[]}` - is an allow list of URLs to allow HTTP data collection from, works best with `enableHttpDataCollection` enabled
73
69
 
74
- Example:
70
+ - `config` which consists of
71
+ - `@property domain {string}` - indicates which Noibu dashboard session recordings should go to ([learn more about domains](https://help.noibu.com/hc/en-us/articles/4846518088845-Domains-Overview))
72
+ - `@property [blockedElements] {string[]}` - lets you specify component ids to be ignored by SDK when collecting error information
73
+ - `@property [enableHttpDataCollection] {boolean}` - indicates whether SDK should collect HTTP information like headers or body from requests
74
+ - `@property [listOfUrlsToCollectHttpDataFrom] {string[]}` - is an allow list of URLs to allow HTTP data collection from, works best with `enableHttpDataCollection` enabled
75
+
76
+ Example:
77
+
75
78
  ```js
76
79
  setupNoibu({
77
- domain: 'react-native-app.myshop.com',
78
- enableHttpDataCollection: true,
79
- listOfUrlsToCollectHttpDataFrom: [
80
- 'https://react-native-app.myshop.com/backend',
81
- 'https://example.com/some-path/',
82
- ],
83
- blockedElements: ['sensitive-info']
80
+ domain: 'react-native-app.myshop.com',
81
+ enableHttpDataCollection: true,
82
+ listOfUrlsToCollectHttpDataFrom: ['https://react-native-app.myshop.com/backend', 'https://example.com/some-path/'],
83
+ blockedElements: ['sensitive-info'],
84
84
  });
85
85
  ```
86
86
 
@@ -101,7 +101,7 @@ Requests a help code from the HelpCode instance. To read more about help codes,
101
101
  ```jsx
102
102
  import { NoibuJS } from 'noibu-react-native';
103
103
  import { useCallback, useState } from 'react';
104
- import { Alert, Text, Pressable, View} from 'react-native';
104
+ import { Alert, Text, Pressable, View } from 'react-native';
105
105
 
106
106
  const AlertHelpCode = () => {
107
107
  const triggerHelpCodeAlert = useCallback(async () => {
@@ -67,7 +67,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
67
67
  dependencies {
68
68
  implementation "com.facebook.react:react-native:+"
69
69
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
70
- implementation "com.noibu:sessionreplay-recorder:0.2.0"
70
+ implementation "com.noibu:sessionreplay-recorder:0.2.1"
71
71
  }
72
72
 
73
73
  if (isNewArchitectureEnabled()) {
@@ -1,5 +1,4 @@
1
- import { SEVERITY } from '../constants';
2
- import { CustomerConfig, StoredConfig } from '../../types/Config';
1
+ import { ErrorMessage, Severity } from '@noibu/metroplex-ts-bindings';
3
2
  import { Singleton } from '../monitors/BaseMonitor';
4
3
  /**
5
4
  * Singleton class to manage the client configuration
@@ -11,34 +10,33 @@ export default class ClientConfig extends Singleton {
11
10
  readonly pageVisitId: string;
12
11
  browserId: StoredConfig['BrowserId'];
13
12
  private pageVisitSeq;
14
- lastActiveTime: Date;
13
+ private lastActiveTime;
15
14
  private readonly noibuErrorURL;
16
15
  private cltErrorPostCounter;
17
16
  private readonly maxSocketInactiveTime;
18
17
  private locationBreadcrumbs;
19
- customerDomain: string;
18
+ private readonly customerDomain;
20
19
  isClientDisabled: boolean;
21
20
  configurationPromise: Promise<void>;
22
21
  readonly listOfUrlsToCollectHttpDataFrom: CustomerConfig['listOfUrlsToCollectHttpDataFrom'];
23
22
  readonly enableHttpDataCollection: CustomerConfig['enableHttpDataCollection'];
24
23
  readonly blockedElements: CustomerConfig['blockedElements'];
25
- /**
26
- * Creates a ClientConfig singleton instance
27
- */
24
+ private alreadyPostingError;
25
+ /** Error handling for constructor */
26
+ handleConstructorError(noibuErrorURL?: string, customerConfig?: CustomerConfig): void;
27
+ /** Creates a ClientConfig singleton instance */
28
28
  constructor(noibuErrorURL?: string, customerConfig?: CustomerConfig);
29
- /**
30
- * Convenience method to check correct setup
31
- */
29
+ /** Convenience method to check correct setup */
32
30
  private hasAllNecessaryArgs;
33
31
  /** lockClient will disable the client script for a single pagevisit for
34
32
  * duration given in minuntes */
35
- lockClient(duration: number, msg: string): Promise<void>;
33
+ lockClient(duration: number, msg: ErrorMessage): Promise<void>;
36
34
  /** Locks the client until the next page loads */
37
- lockClientUntilNextPage(msg: string): Promise<void>;
35
+ lockClientUntilNextPage(msg: ErrorMessage): Promise<void>;
38
36
  /** Updates the config object to store the given last active time */
39
37
  updateLastActiveTime(lastActiveTime: Date): Promise<void>;
40
38
  /** Gets the current page visit sequence number that should be used */
41
- getPageVisitSeq(): Promise<number>;
39
+ getPageVisitSeq(): Promise<number | null>;
42
40
  /**
43
41
  * Returns the client config object from storage or generates a new one
44
42
  * What is stored in storage will look like this
@@ -52,9 +50,7 @@ export default class ClientConfig extends Singleton {
52
50
  * }
53
51
  */
54
52
  _getLsObject(): Promise<StoredConfig>;
55
- /**
56
- * Check if we have surpassed the last active time and the page visit seq number needs resetting
57
- */
53
+ /** Check if we have surpassed the last active time and the page visit seq number needs resetting */
58
54
  _pageVisitSeqNeedsReset(): Promise<boolean>;
59
55
  /**
60
56
  * _setupStorageVars will set all class variables that depend
@@ -88,13 +84,16 @@ export default class ClientConfig extends Singleton {
88
84
  /** gets current global url */
89
85
  get globalUrl(): string;
90
86
  /**
91
- * postNoibuErrorAndOptionallyDisableClient will post errors that were thrown by collect
87
+ * postInternalError will post errors that were thrown by collect
92
88
  * and disable the client if required
93
89
  * severity expects one of the SEVERITY_x level constants, or else error will be used
94
90
  */
95
- postNoibuErrorAndOptionallyDisableClient(errorMsg: any, disableClient?: boolean, severity?: (typeof SEVERITY)[keyof typeof SEVERITY], keepAlive?: boolean): Promise<void>;
91
+ postInternalError(errorMsg: ErrorMessage, disableClient?: boolean, severity?: Severity, keepAlive?: boolean): Promise<void>;
92
+ /** Returns true if the page visit is considered to be inactive */
93
+ isInactive(): boolean;
96
94
  /**
97
- * Returns true if the page visit is considered to be inactive
95
+ * Wraps a function in a try catch block and posts the error if one is thrown
96
+ * explanation will be inserted into the error message as 'Error in {explanation}'
98
97
  */
99
- isInactive(): boolean;
98
+ wrapInternal(explanation: string, fun: () => void): void;
100
99
  }
@@ -1,12 +1,24 @@
1
1
  import { __awaiter } from 'tslib';
2
2
  import uuid from 'react-native-uuid';
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';
4
- import { stringifyJSON, getMaxSubstringAllowed, getUserAgent, makeRequest } from '../utils/function.js';
5
- import Storage from '../storage/storage.js';
3
+ import '../node_modules/@noibu/metroplex-ts-bindings/dist/index.js';
4
+ import { MAX_METROPLEX_SOCKET_INNACTIVE_TIME, GET_SCRIPT_ID, GET_DEVICE_ENV } from '../constants.js';
5
+ import { stringifyJSON, getMaxSubstringAllowed, getUserAgent, postRequest } from '../utils/function.js';
6
+ import Storage from '../storage/Storage.js';
6
7
  import { noibuLog } from '../utils/log.js';
7
8
  import { unwrapNoibuWrapped } from '../utils/object.js';
8
9
  import { Singleton } from '../monitors/BaseMonitor.js';
10
+ import { Severity } from '../node_modules/@noibu/metroplex-ts-bindings/dist/Severity.js';
9
11
 
12
+ // maximum number of page visits assigned to a single browser id
13
+ const MAX_PAGEVISIT_VISITED = 300;
14
+ // The amount of time to lock the client for if they have exceeded things
15
+ // like the maximum number of pagevisits
16
+ const CLIENT_LOCK_TIME_MINUTES = 45;
17
+ // The amount of inactive time required for us to reset the page visit sequence numbers
18
+ const PV_SEQ_NUM_RESET_TIME_MINUTES = 45;
19
+ // number of errors that collect can send to metroplex before shutting himself off.
20
+ const MAX_COLLECT_ERROR_LOG = 50;
21
+ const NOIBU_BROWSER_ID_KYWRD = 'n_browser_data';
10
22
  /**
11
23
  * Singleton class to manage the client configuration
12
24
  * this class will be responsible for controlling the disabled
@@ -14,9 +26,18 @@ import { Singleton } from '../monitors/BaseMonitor.js';
14
26
  * storing and retrieval.
15
27
  */
16
28
  class ClientConfig extends Singleton {
17
- /**
18
- * Creates a ClientConfig singleton instance
19
- */
29
+ /** Error handling for constructor */
30
+ handleConstructorError(noibuErrorURL, customerConfig) {
31
+ const reason = {
32
+ msg: 'ClientConfig was not properly configured',
33
+ noibuErrorURL,
34
+ customerConfig,
35
+ globalUrl: this.globalUrl,
36
+ };
37
+ void this.postInternalError(reason, true, Severity.ERROR);
38
+ this.configurationPromise = Promise.reject(reason);
39
+ }
40
+ /** Creates a ClientConfig singleton instance */
20
41
  constructor(noibuErrorURL, customerConfig) {
21
42
  super();
22
43
  this.pageVisitId = uuid.v4();
@@ -33,26 +54,26 @@ class ClientConfig extends Singleton {
33
54
  this.maxSocketInactiveTime = MAX_METROPLEX_SOCKET_INNACTIVE_TIME;
34
55
  this.locationBreadcrumbs = [];
35
56
  this.isClientDisabled = false;
57
+ this.alreadyPostingError = false;
58
+ if (!noibuErrorURL || !customerConfig) {
59
+ this.handleConstructorError(noibuErrorURL, customerConfig);
60
+ return;
61
+ }
36
62
  this.noibuErrorURL = noibuErrorURL;
37
63
  this.customerDomain = customerConfig.domain;
38
- this.listOfUrlsToCollectHttpDataFrom =
39
- customerConfig.listOfUrlsToCollectHttpDataFrom;
40
- this.enableHttpDataCollection = customerConfig.enableHttpDataCollection;
41
- this.blockedElements = customerConfig.blockedElements;
42
- if (!noibuErrorURL || !this.hasAllNecessaryArgs()) {
43
- const reason = Object.assign({ msg: 'ClientConfig was not properly configured' }, customerConfig);
44
- void this.postNoibuErrorAndOptionallyDisableClient(reason, true, SEVERITY.error);
45
- this.configurationPromise = Promise.reject(reason);
64
+ if (!this.hasAllNecessaryArgs(customerConfig)) {
65
+ this.handleConstructorError(noibuErrorURL, customerConfig);
46
66
  return;
47
67
  }
68
+ this.listOfUrlsToCollectHttpDataFrom = customerConfig.listOfUrlsToCollectHttpDataFrom;
69
+ this.enableHttpDataCollection = customerConfig.enableHttpDataCollection;
70
+ this.blockedElements = customerConfig.blockedElements;
48
71
  // sets up this.browserId, this.isClientDisabled, this.pageVisitSeq
49
72
  this.configurationPromise = this._setupStorageVars();
50
73
  }
51
- /**
52
- * Convenience method to check correct setup
53
- */
54
- hasAllNecessaryArgs() {
55
- return (!!this.customerDomain && this.globalUrl.includes(this.customerDomain));
74
+ /** Convenience method to check correct setup */
75
+ hasAllNecessaryArgs(customerConfig) {
76
+ return !!customerConfig.domain && this.globalUrl.includes(customerConfig.domain);
56
77
  }
57
78
  /** lockClient will disable the client script for a single pagevisit for
58
79
  * duration given in minuntes */
@@ -64,12 +85,12 @@ class ClientConfig extends Singleton {
64
85
  noibuLSObject.DisabledStatus = true;
65
86
  noibuLSObject.ClientUnlockTime = expiryTime;
66
87
  yield this._storeBrowserData(noibuLSObject);
67
- yield this.postNoibuErrorAndOptionallyDisableClient(msg, true, SEVERITY.warn);
88
+ yield this.postInternalError(msg, true, Severity.WARN);
68
89
  });
69
90
  }
70
91
  /** Locks the client until the next page loads */
71
92
  lockClientUntilNextPage(msg) {
72
- return this.postNoibuErrorAndOptionallyDisableClient(msg, true, SEVERITY.warn);
93
+ return this.postInternalError(msg, true, Severity.WARN);
73
94
  }
74
95
  /** Updates the config object to store the given last active time */
75
96
  updateLastActiveTime(lastActiveTime) {
@@ -133,9 +154,7 @@ class ClientConfig extends Singleton {
133
154
  return parsedConfig;
134
155
  });
135
156
  }
136
- /**
137
- * Check if we have surpassed the last active time and the page visit seq number needs resetting
138
- */
157
+ /** Check if we have surpassed the last active time and the page visit seq number needs resetting */
139
158
  _pageVisitSeqNeedsReset() {
140
159
  return __awaiter(this, void 0, void 0, function* () {
141
160
  const noibuLSObject = yield this._getClientState();
@@ -155,7 +174,7 @@ class ClientConfig extends Singleton {
155
174
  return __awaiter(this, void 0, void 0, function* () {
156
175
  const storage = Storage.getInstance();
157
176
  if (!(yield storage.isAvailable())) {
158
- void this.postNoibuErrorAndOptionallyDisableClient(`Storage is unavailable, disabling client. ${yield storage.getDiagnoseInfo()}`, true, SEVERITY.error);
177
+ void this.postInternalError({ msg: `Storage is unavailable, disabling client.`, diagnosis: yield storage.getDiagnoseInfo() }, true, Severity.ERROR);
159
178
  return;
160
179
  }
161
180
  // getting the current content of the storage
@@ -175,11 +194,6 @@ class ClientConfig extends Singleton {
175
194
  // Update the LS object values before storing it for the next page visit
176
195
  noibuLSObject.CurrentPageVisitCount += 1;
177
196
  noibuLSObject.LastActive = new Date();
178
- // Expose page visit ID in storage for use by Trailbreaker video tests
179
- // This will be done for the testvideo and lambdavideo bundles used by Trailbreaker
180
- if (JS_ENV().includes('video')) {
181
- noibuLSObject.pvId = this.pageVisitId;
182
- }
183
197
  // if we have reached the max page visits for a browser id then
184
198
  // we disabled collect for 45 minutes
185
199
  if (noibuLSObject.CurrentPageVisitCount >= MAX_PAGEVISIT_VISITED) {
@@ -190,7 +204,7 @@ class ClientConfig extends Singleton {
190
204
  // setting the lock time
191
205
  noibuLSObject.ClientUnlockTime = expiryTime;
192
206
  noibuLSObject.DisabledStatus = true;
193
- yield this.postNoibuErrorAndOptionallyDisableClient(`Hit max page visits, disabling client for ${CLIENT_LOCK_TIME_MINUTES}mins`, true, SEVERITY.error);
207
+ yield this.postInternalError({ msg: `Hit max page visits, disabling client for ${CLIENT_LOCK_TIME_MINUTES}mins` }, true, Severity.ERROR);
194
208
  }
195
209
  // we now check if we successfully saved the data
196
210
  const savedData = yield this._storeBrowserData(noibuLSObject);
@@ -198,7 +212,7 @@ class ClientConfig extends Singleton {
198
212
  // error happened, thus we disable collect.
199
213
  if (!savedData.BrowserId) {
200
214
  // we do not set a lock expiry date here since we cannot store to storage
201
- void this.postNoibuErrorAndOptionallyDisableClient(`Null browser in storage, disabling client`, true, SEVERITY.error);
215
+ void this.postInternalError({ msg: `Null browser in storage, disabling client` }, true, Severity.ERROR);
202
216
  this.browserId = '';
203
217
  }
204
218
  });
@@ -213,8 +227,7 @@ class ClientConfig extends Singleton {
213
227
  return __awaiter(this, void 0, void 0, function* () {
214
228
  const newConfigData = yield this._getLsObject();
215
229
  // if the lock expired, we remove the lock period and enable the client
216
- if (newConfigData.ClientUnlockTime &&
217
- new Date(newConfigData.ClientUnlockTime) <= new Date()) {
230
+ if (newConfigData.ClientUnlockTime && new Date(newConfigData.ClientUnlockTime) <= new Date()) {
218
231
  newConfigData.ClientUnlockTime = undefined;
219
232
  newConfigData.DisabledStatus = false;
220
233
  yield this._storeBrowserData(newConfigData);
@@ -237,18 +250,12 @@ class ClientConfig extends Singleton {
237
250
  * and persisted throughout a session
238
251
  */
239
252
  _generateNewBrowserData() {
240
- const noibuBrowserData = {
253
+ return {
241
254
  DisabledStatus: false,
242
255
  BrowserId: uuid.v4(),
243
256
  CurrentPageVisitCount: 0,
244
257
  LastActive: new Date(),
245
258
  };
246
- // Expose page visit ID in storage for use by Trailbreaker video tests
247
- // This will be done for the testvideo and lambdavideo bundles used by Trailbreaker
248
- if (JS_ENV().includes('video')) {
249
- noibuBrowserData.pvId = this.pageVisitId;
250
- }
251
- return noibuBrowserData;
252
259
  }
253
260
  /**
254
261
  * _storeBrowserData will store the passed object in storage.
@@ -262,7 +269,10 @@ class ClientConfig extends Singleton {
262
269
  return data;
263
270
  }
264
271
  catch (e) {
265
- yield this.postNoibuErrorAndOptionallyDisableClient(`Error writing browser data to storage, disabling client: ${e.message}, ${yield storage.getDiagnoseInfo()}`, true, SEVERITY.error);
272
+ yield this.postInternalError({
273
+ msg: 'Error writing browser data to storage, disabling client: ' + e.message,
274
+ diagnosis: yield storage.getDiagnoseInfo(),
275
+ }, true, Severity.ERROR);
266
276
  // sending empty fields if we encountered errors while storing in the LS
267
277
  return this._generateNewBrowserData();
268
278
  }
@@ -285,35 +295,33 @@ class ClientConfig extends Singleton {
285
295
  return getMaxSubstringAllowed(globalUrl.toString());
286
296
  }
287
297
  /**
288
- * postNoibuErrorAndOptionallyDisableClient will post errors that were thrown by collect
298
+ * postInternalError will post errors that were thrown by collect
289
299
  * and disable the client if required
290
300
  * severity expects one of the SEVERITY_x level constants, or else error will be used
291
301
  */
292
- postNoibuErrorAndOptionallyDisableClient(errorMsg_1) {
293
- return __awaiter(this, arguments, void 0, function* (errorMsg, disableClient = false, severity = SEVERITY.error, keepAlive = false) {
294
- noibuLog('postNoibuErrorAndOptionallyDisableClient', {
295
- errorMsg,
296
- disableClient,
297
- severity,
298
- keepAlive,
299
- });
300
- if (this.isClientDisabled) {
302
+ postInternalError(errorMsg_1) {
303
+ return __awaiter(this, arguments, void 0, function* (errorMsg, disableClient = false, severity = Severity.ERROR, keepAlive = false) {
304
+ if (this.alreadyPostingError || this.isClientDisabled || severity === Severity.WARN) {
301
305
  return;
302
306
  }
303
307
  if (disableClient) {
304
308
  this.isClientDisabled = true;
305
309
  }
306
- if (severity === SEVERITY.warn) {
307
- // don't log warning messages by default, as a cost savings
308
- return;
309
- }
310
+ this.alreadyPostingError = true;
311
+ /** Don't use noibuErr here since we end up in recursion due to RN log intercept in debug mode */
312
+ noibuLog('postInternalError', {
313
+ errorMsg,
314
+ disableClient,
315
+ severity,
316
+ keepAlive,
317
+ });
310
318
  const collectError = {
311
319
  browserId: this.browserId || '',
312
320
  pageVisitId: this.pageVisitId,
313
321
  scriptId: GET_SCRIPT_ID(),
314
322
  ua: yield getUserAgent(),
315
323
  deviceEnv: GET_DEVICE_ENV(),
316
- error: stringifyJSON(errorMsg),
324
+ msg: stringifyJSON(errorMsg),
317
325
  };
318
326
  // if the page visits sends more errors than the
319
327
  // allowed threshold we disable the client
@@ -329,7 +337,7 @@ class ClientConfig extends Singleton {
329
337
  this.isClientDisabled = true;
330
338
  // end of lock
331
339
  // 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.`;
340
+ collectError.msg = `Shutting collect off, we reached the maximum limit of collect errors sent.`;
333
341
  }
334
342
  const errorContent = {
335
343
  url: this.globalUrl,
@@ -340,7 +348,7 @@ class ClientConfig extends Singleton {
340
348
  'content-type': 'application/json',
341
349
  };
342
350
  if (!keepAlive) {
343
- makeRequest('POST', this.noibuErrorURL, errorContent, headers, 2000, false).catch(() => {
351
+ postRequest(this.noibuErrorURL, errorContent, headers, false, 2000).catch(() => {
344
352
  // we do nothing and let this error silently fail
345
353
  });
346
354
  }
@@ -354,19 +362,30 @@ class ClientConfig extends Singleton {
354
362
  });
355
363
  }
356
364
  // only increment if this was an actual error, not a warning or otherwise
357
- if (severity === SEVERITY.error) {
365
+ if (severity === Severity.ERROR) {
358
366
  this.cltErrorPostCounter += 1;
359
367
  }
368
+ this.alreadyPostingError = false;
360
369
  });
361
370
  }
362
- /**
363
- * Returns true if the page visit is considered to be inactive
364
- */
371
+ /** Returns true if the page visit is considered to be inactive */
365
372
  isInactive() {
366
373
  const someTimeAgo = new Date();
367
374
  someTimeAgo.setSeconds(someTimeAgo.getSeconds() - this.maxSocketInactiveTime);
368
375
  return this.lastActiveTime < someTimeAgo;
369
376
  }
377
+ /**
378
+ * Wraps a function in a try catch block and posts the error if one is thrown
379
+ * explanation will be inserted into the error message as 'Error in {explanation}'
380
+ */
381
+ wrapInternal(explanation, fun) {
382
+ try {
383
+ fun();
384
+ }
385
+ catch (error) {
386
+ this.postInternalError({ msg: `Error in ${explanation}`, error }, false, Severity.ERROR);
387
+ }
388
+ }
370
389
  }
371
390
 
372
391
  export { ClientConfig as default };
@@ -4,20 +4,13 @@ import { Singleton } from '../monitors/BaseMonitor';
4
4
  */
5
5
  export default class HelpCode extends Singleton {
6
6
  private requestContext;
7
- /**
8
- * Constructs instance and sets up event listeners
9
- */
7
+ /** Constructs instance and sets up event listeners */
10
8
  constructor();
11
9
  /**
12
10
  * Requests a help code and returns a Promise that resolves when the help code is obtained
13
11
  * or rejects if the noibu connection is unavailable.
14
-
15
- * @returns {Promise<string>} Promise object representing the help code request.
16
- * @throws {string} Throws an error if the noibu connection is unavailable.
17
- */
18
- requestHelpCode(): Promise<unknown>;
19
- /**
20
- * Handles the received help code event.
21
12
  */
13
+ requestHelpCode(): Promise<string | null>;
14
+ /** Handles the received help code event. */
22
15
  receiveHelpCode(event: CustomEvent<string>): void;
23
16
  }
@@ -1,16 +1,15 @@
1
1
  import { __awaiter } from 'tslib';
2
- import MetroplexSocket from './metroplexSocket.js';
3
- import { SEVERITY } from '../constants.js';
4
- import ClientConfig from './clientConfig.js';
2
+ import MetroplexSocket from './MetroplexSocket.js';
3
+ import ClientConfig from './ClientConfig.js';
5
4
  import { Singleton } from '../monitors/BaseMonitor.js';
5
+ import '../node_modules/@noibu/metroplex-ts-bindings/dist/index.js';
6
+ import { Severity } from '../node_modules/@noibu/metroplex-ts-bindings/dist/Severity.js';
6
7
 
7
8
  /**
8
9
  * HelpCode class is responsible for help code feature related functionality
9
10
  */
10
11
  class HelpCode extends Singleton {
11
- /**
12
- * Constructs instance and sets up event listeners
13
- */
12
+ /** Constructs instance and sets up event listeners */
14
13
  constructor() {
15
14
  super();
16
15
  this.requestContext = null;
@@ -19,9 +18,6 @@ class HelpCode extends Singleton {
19
18
  /**
20
19
  * Requests a help code and returns a Promise that resolves when the help code is obtained
21
20
  * or rejects if the noibu connection is unavailable.
22
-
23
- * @returns {Promise<string>} Promise object representing the help code request.
24
- * @throws {string} Throws an error if the noibu connection is unavailable.
25
21
  */
26
22
  requestHelpCode() {
27
23
  return __awaiter(this, void 0, void 0, function* () {
@@ -46,16 +42,14 @@ class HelpCode extends Singleton {
46
42
  return this.requestContext.promise;
47
43
  });
48
44
  }
49
- /**
50
- * Handles the received help code event.
51
- */
45
+ /** Handles the received help code event. */
52
46
  receiveHelpCode(event) {
53
47
  var _a, _b;
54
48
  if (this.requestContext === null) {
55
49
  const { success, data } = event.detail;
56
50
  if (!success) {
57
- const message = `Noibu help code is not available due to ${data}`;
58
- ClientConfig.getInstance().postNoibuErrorAndOptionallyDisableClient(message, false, SEVERITY.error);
51
+ const msg = `Noibu help code is not available due to ${data}`;
52
+ ClientConfig.getInstance().postInternalError({ msg }, false, Severity.ERROR);
59
53
  }
60
54
  return;
61
55
  }
@@ -0,0 +1,39 @@
1
+ import { Singleton } from '../monitors/BaseMonitor';
2
+ declare const NOIBUJS_SDK_REQUEST_HELP_CODE = "requestHelpCode";
3
+ declare const NOIBUJS_SDK_ADD_ID_FUNCTION = "addCustomAttribute";
4
+ declare const NOIBUJS_SDK_ADD_ERROR_FUNCTION = "addError";
5
+ declare const NOIBUJS_SDK_ADD_ERROR_FROM_JS_FMW_FUNCTION = "addJsSdkError";
6
+ /** this class controls the input that customers can inject into
7
+ * our script via the NoibuJS SDK
8
+ */
9
+ export default class InputManager extends Singleton {
10
+ private readonly customIDs;
11
+ private customErrorsCount;
12
+ /** exposes functions to the window of the browser for the clients
13
+ * to interact with on their end
14
+ */
15
+ exposeFunctions(): {
16
+ [NOIBUJS_SDK_REQUEST_HELP_CODE]: () => Promise<string | null>;
17
+ [NOIBUJS_SDK_ADD_ID_FUNCTION]: (name: string, value: string) => Promise<string>;
18
+ [NOIBUJS_SDK_ADD_ERROR_FUNCTION]: (customError: unknown) => string;
19
+ [NOIBUJS_SDK_ADD_ERROR_FROM_JS_FMW_FUNCTION]: (customError: unknown, errorSource: unknown) => string;
20
+ };
21
+ /** validates the custom error that was passed */
22
+ getErrorValidationError(customError: any): "SUCCESS" | "ERROR_HAS_NO_MSG" | "ERROR_HAS_NO_STACK" | "NULL_CUSTOM_ERROR";
23
+ /** Validates and sets the custom error to our internal trackers */
24
+ _validateAndSetCustomError(customError: unknown): "SUCCESS" | "ERROR_HAS_NO_MSG" | "ERROR_HAS_NO_STACK" | "NULL_CUSTOM_ERROR" | "TOO_MANY_ERRORS_RECEIVED_PER_PAGEVISIT";
25
+ /** adds an error from a JS Sdk to the session */
26
+ _addErrorFromJSSdk(customError: unknown, errorSource: unknown): "SUCCESS" | "ERROR_HAS_NO_MSG" | "ERROR_HAS_NO_STACK" | "NULL_CUSTOM_ERROR" | "TOO_MANY_ERRORS_RECEIVED_PER_PAGEVISIT";
27
+ /** adds a custom Error to the session */
28
+ _addCustomError(customError: unknown): "SUCCESS" | "ERROR_HAS_NO_MSG" | "ERROR_HAS_NO_STACK" | "NULL_CUSTOM_ERROR" | "TOO_MANY_ERRORS_RECEIVED_PER_PAGEVISIT";
29
+ /**
30
+ * adds a custom id to the session
31
+ * todo wrong param types, should be unknown
32
+ */
33
+ _addCustomAttribute(name: string, value: string): Promise<"TOO_MANY_IDS_ADDED" | "ID_NAME_ALREADY_ADDED" | "NAME_TOO_LONG" | "VALUE_TOO_LONG" | "INVALID_NAME_TYPE" | "INVALID_VALUE_TYPE" | "NAME_HAS_NO_LENGTH" | "VALUE_HAS_NO_LENGTH" | "SUCCESS">;
34
+ /** validation function for customer input */
35
+ getValidationError(name: unknown, value: unknown): "NAME_TOO_LONG" | "VALUE_TOO_LONG" | "INVALID_NAME_TYPE" | "INVALID_VALUE_TYPE" | "NAME_HAS_NO_LENGTH" | "VALUE_HAS_NO_LENGTH" | "SUCCESS";
36
+ /** Requests a help code from the HelpCode instance. */
37
+ _requestHelpCode(): Promise<string | null>;
38
+ }
39
+ export {};