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
@@ -1,14 +1,10 @@
1
+ import { Singleton } from '../monitors/BaseMonitor';
1
2
  /**
2
3
  * This class holds the final page visit and video frag metrics. It flushes
3
4
  * them to storage and then finally sends them to Metroplex via the post
4
5
  * route when the next page is loaded
5
6
  */
6
- export default class StoredMetrics {
7
- /**
8
- * gets the singleton instance
9
- * @returns {StoredMetrics}
10
- */
11
- static getInstance(): StoredMetrics;
7
+ export default class StoredMetrics extends Singleton {
12
8
  expectedVideoLength: number;
13
9
  expectedVfSeq: number;
14
10
  httpSequenceNumber: number;
@@ -23,17 +19,13 @@ export default class StoredMetrics {
23
19
  httpCount: number;
24
20
  didCutPv: boolean;
25
21
  didCutVideo: boolean;
26
- writeTimeout: any;
27
22
  didStartVideo: boolean;
28
- /** Add video frag payload data to the stored metrics
29
- * @param {} expectedVfSeq
30
- * @param {} expectedVideoLength
31
- */
32
- addVideoFragData(expectedVfSeq: any, expectedVideoLength: any): void;
33
- /** Set the amount of page visit parts
34
- * @param {} expectedPvPart
35
- */
36
- setPvPart(expectedPvPart: any): void;
23
+ /** Creates a new StoredMetrics instance */
24
+ constructor();
25
+ /** Add video frag payload data to the stored metrics */
26
+ addVideoFragData(expectedVfSeq: number, expectedVideoLength: number): void;
27
+ /** Set the amount of page visit parts */
28
+ setPvPart(expectedPvPart: number): void;
37
29
  /** Increase the amount of video clicks seen in the session */
38
30
  addVideoClick(): void;
39
31
  /** Increase the amount of page visit clicks */
@@ -63,10 +55,8 @@ export default class StoredMetrics {
63
55
  * our metrics to localstorage
64
56
  */
65
57
  _setupListeners(): void;
66
- /** posts the metrics to metroplex if client is active
67
- * @param {} eventName
68
- */
69
- _postMetricsIfActive(eventName: any): void;
58
+ /** posts the metrics to metroplex if client is active */
59
+ private postMetricsIfActive;
70
60
  /** posts the metrics to metroplex using the beacon API
71
61
  */
72
62
  postMetrics(): Promise<void>;
@@ -0,0 +1,158 @@
1
+ import { __awaiter } from 'tslib';
2
+ import { CURRENT_NOIBUJS_VERSION, GET_METROPLEX_METRICS_URL } from '../constants.js';
3
+ import ClientConfig from './ClientConfig.js';
4
+ import { getUserAgent, stringifyJSON } from '../utils/function.js';
5
+ import { addSafeEventListener } from '../utils/eventlistener.js';
6
+ import { unwrapNoibuWrapped } from '../utils/object.js';
7
+ import { Singleton } from '../monitors/BaseMonitor.js';
8
+
9
+ // current metrics version to be sent from front end services.
10
+ const CURRENT_METRICS_VERSION = 1;
11
+ /**
12
+ * This class holds the final page visit and video frag metrics. It flushes
13
+ * them to storage and then finally sends them to Metroplex via the post
14
+ * route when the next page is loaded
15
+ */
16
+ class StoredMetrics extends Singleton {
17
+ /** Creates a new StoredMetrics instance */
18
+ constructor() {
19
+ super();
20
+ this.expectedVideoLength = 0;
21
+ this.expectedVfSeq = 0;
22
+ this.httpSequenceNumber = 0;
23
+ this.httpOverLimitCount = 0;
24
+ this.httpDroppedPayloadByTypeCount = 0;
25
+ this.httpDroppedPayloadByLengthCount = 0;
26
+ this.httpPayloadCount = 0;
27
+ this.expectedPvPart = 0;
28
+ this.videoClicks = 0;
29
+ this.pvClicks = 0;
30
+ this.errCount = 0;
31
+ this.httpCount = 0;
32
+ this.didCutPv = false;
33
+ this.didCutVideo = false;
34
+ this.didStartVideo = false;
35
+ this._setupListeners();
36
+ }
37
+ /** Add video frag payload data to the stored metrics */
38
+ addVideoFragData(expectedVfSeq, expectedVideoLength) {
39
+ this.expectedVfSeq = expectedVfSeq;
40
+ this.expectedVideoLength = expectedVideoLength;
41
+ }
42
+ /** Set the amount of page visit parts */
43
+ setPvPart(expectedPvPart) {
44
+ this.expectedPvPart = expectedPvPart;
45
+ }
46
+ /** Increase the amount of video clicks seen in the session */
47
+ addVideoClick() {
48
+ this.videoClicks += 1;
49
+ }
50
+ /** Increase the amount of page visit clicks */
51
+ addPvClick() {
52
+ this.pvClicks += 1;
53
+ }
54
+ /** Increments the error count by 1 */
55
+ addError() {
56
+ this.errCount += 1;
57
+ }
58
+ /** Increments the http count by 1 */
59
+ addHttpEvent() {
60
+ this.httpCount += 1;
61
+ }
62
+ /** Increments the http data sequence count by 1 */
63
+ addHttpData() {
64
+ this.httpSequenceNumber += 1;
65
+ }
66
+ /** Increments the http data over limit count by 1 */
67
+ addHttpDataOverLimit() {
68
+ this.httpOverLimitCount += 1;
69
+ }
70
+ /** Increments the http data drop count by content type */
71
+ addHttpDataDropByType() {
72
+ this.httpDroppedPayloadByTypeCount += 1;
73
+ }
74
+ /** Increments the http data drop count by content length */
75
+ addHttpDataDropByLength() {
76
+ this.httpDroppedPayloadByLengthCount += 1;
77
+ }
78
+ /** Increments the http data payload collected count */
79
+ addHttpDataPayloadCount() {
80
+ this.httpPayloadCount += 1;
81
+ }
82
+ /** Set that the video was cut/blocked due to size constraints */
83
+ setDidCutVideo() {
84
+ this.didCutVideo = true;
85
+ }
86
+ /** Set that the video was started */
87
+ setDidStartVideo() {
88
+ this.didStartVideo = true;
89
+ }
90
+ /** Set that the page visit was cut/blocked due to size constraints */
91
+ setDidCutPv() {
92
+ this.didCutPv = true;
93
+ }
94
+ /**
95
+ * Sets up all the listeners that noibujs should listen to before storing
96
+ * our metrics to localstorage
97
+ */
98
+ _setupListeners() {
99
+ // Add the window event handlers to post the data to the metrics endpoint
100
+ const evt = 'pagehide';
101
+ addSafeEventListener(window, evt, () => this.postMetricsIfActive());
102
+ }
103
+ /** posts the metrics to metroplex if client is active */
104
+ postMetricsIfActive() {
105
+ if (ClientConfig.getInstance().isClientDisabled) {
106
+ return;
107
+ }
108
+ // Don't send the metrics if the session has become inactive
109
+ // already sent when went inactive
110
+ if (ClientConfig.getInstance().isInactive()) {
111
+ return;
112
+ }
113
+ return this.postMetrics();
114
+ }
115
+ /** posts the metrics to metroplex using the beacon API
116
+ */
117
+ postMetrics() {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ // Create a new object to write to local storage that doesnt have the timeout and flush members.
120
+ const lsMetrics = {
121
+ // metadata
122
+ br_id: ClientConfig.getInstance().browserId,
123
+ pv_id: ClientConfig.getInstance().pageVisitId,
124
+ cv: CURRENT_NOIBUJS_VERSION,
125
+ v: CURRENT_METRICS_VERSION,
126
+ // metrics
127
+ exp_vid_len: this.expectedVideoLength,
128
+ exp_vf_seq: this.expectedVfSeq,
129
+ exp_pc_seq: this.expectedPvPart,
130
+ exp_http_seq: this.httpSequenceNumber,
131
+ http_payloads: this.httpPayloadCount,
132
+ http_drop_oversize: this.httpDroppedPayloadByLengthCount,
133
+ http_drop_type: this.httpDroppedPayloadByTypeCount,
134
+ http_over_limit: this.httpOverLimitCount,
135
+ vid_clicks: this.videoClicks,
136
+ pv_clicks: this.pvClicks,
137
+ did_cut_pv: this.didCutPv,
138
+ did_cut_vid: this.didCutVideo,
139
+ did_start_vid: this.didStartVideo,
140
+ exp_http: this.httpCount,
141
+ exp_err: this.errCount,
142
+ on_url: ClientConfig.getInstance().globalUrl,
143
+ };
144
+ unwrapNoibuWrapped(fetch)(GET_METROPLEX_METRICS_URL(), {
145
+ method: 'POST',
146
+ headers: {
147
+ 'content-type': 'application/json',
148
+ 'User-Agent': yield getUserAgent(),
149
+ },
150
+ body: stringifyJSON(lsMetrics),
151
+ // keep alive outlives the current page, its the same as beacon
152
+ keepalive: true,
153
+ });
154
+ });
155
+ }
156
+ }
157
+
158
+ export { StoredMetrics as default };
@@ -1,30 +1,33 @@
1
- import { CompletePageVisit, PageVisitFrag, PageVisitInfo, SlidingMessage } from '../../types/Metroplex.types';
2
1
  import { Singleton } from '../monitors/BaseMonitor';
2
+ import { RetryQueueWSMessage } from '../types/Metroplex';
3
+ import { CompletePageVisitPart, PageInformation, PageVisitPart } from '@noibu/metroplex-ts-bindings';
3
4
  /**
4
5
  * This class holds the final page visit. It flushes it to storage and then
5
6
  * finally sends it to Metroplex via the post route when the next page is loaded
6
7
  */
7
8
  export default class StoredPageVisit extends Singleton {
8
- /**
9
- * Creates a new instance of StoredPageVisit
10
- */
9
+ /** Creates a new instance of StoredPageVisit */
11
10
  constructor();
12
11
  /**
13
12
  * Check if the events contain a click or location change. If they do then write the retry
14
13
  * queue (which contains the metroplex msg sent above) to storage
15
14
  */
16
- checkAndStoreRetryQueue(retryMessageQueue: SlidingMessage[], pvInfo: PageVisitInfo): void;
15
+ checkAndStoreRetryQueue(retryMessageQueue: RetryQueueWSMessage[], pvInfo: PageInformation): void;
17
16
  /** Writes the page visit frags in the retry queue to storage
18
17
  */
19
- writePageVisitsFromRetryQueue(retryMessageQueue: SlidingMessage[], pvInfo: PageVisitInfo): void;
18
+ writePageVisitsFromRetryQueue(retryMessageQueue: RetryQueueWSMessage[], pvInfo: PageInformation): void;
20
19
  /** Write the given page visit frags to storage
21
20
  */
22
- _writePageVisitFrags(pageVisitFrags: PageVisitFrag[], pvInfo: PageVisitInfo): Promise<void>;
21
+ _writePageVisitFrags(pageVisitFrags: PageVisitPart[], pvInfo: PageInformation): Promise<void>;
22
+ /**
23
+ * Handles any issues that may appear when trying to get the stored page visit data
24
+ */
25
+ static handleGetPostDataError(data: string, error: Error): Promise<null>;
23
26
  /**
24
27
  * Read the stored page visit from storage, create a complete page visit object
25
28
  * and then post that to Metroplex
26
29
  */
27
- _getPostData(): Promise<CompletePageVisit>;
30
+ _getPostData(): Promise<CompletePageVisitPart | null>;
28
31
  /**
29
32
  * Creates and tries to resolve a promise that posts the previous page visit
30
33
  * to Metroplex from storage
@@ -1,18 +1,22 @@
1
1
  import { __awaiter } from 'tslib';
2
- import { PV_METROPLEX_TYPE, PAGE_VISIT_PART_ATT_NAME, PV_EVENTS_ATT_NAME, TYPE_ATT_NAME, USERSTEP_EVENT_TYPE, ERROR_EVENT_TYPE, NOIBU_STORED_PAGE_VISIT, SEVERITY, MAX_METROPLEX_SOCKET_INNACTIVE_TIME, PAGE_VISIT_INFORMATION_ATT_NAME, PAGE_VISIT_VID_FRAG_ATT_NAME, IS_LAST_ATT_NAME, GET_METROPLEX_POST_URL } from '../constants.js';
3
- import ClientConfig from './clientConfig.js';
4
- import { stringifyJSON, makeRequest } from '../utils/function.js';
5
- import Storage from '../storage/storage.js';
2
+ import { MAX_METROPLEX_SOCKET_INNACTIVE_TIME, GET_METROPLEX_POST_URL } from '../constants.js';
3
+ import ClientConfig from './ClientConfig.js';
4
+ import { stringifyJSON, postRequest } from '../utils/function.js';
5
+ import Storage from '../storage/Storage.js';
6
6
  import { Singleton } from '../monitors/BaseMonitor.js';
7
+ import '../node_modules/@noibu/metroplex-ts-bindings/dist/index.js';
8
+ import { WebsocketMessageType } from '../node_modules/@noibu/metroplex-ts-bindings/dist/WebsocketMessageType.js';
9
+ import { EventType } from '../node_modules/@noibu/metroplex-ts-bindings/dist/EventType.js';
10
+ import { Severity } from '../node_modules/@noibu/metroplex-ts-bindings/dist/Severity.js';
7
11
 
12
+ // The local storage key used to store the last page visit
13
+ const NOIBU_STORED_PAGE_VISIT = 'n_stored_page_visit';
8
14
  /**
9
15
  * This class holds the final page visit. It flushes it to storage and then
10
16
  * finally sends it to Metroplex via the post route when the next page is loaded
11
17
  */
12
18
  class StoredPageVisit extends Singleton {
13
- /**
14
- * Creates a new instance of StoredPageVisit
15
- */
19
+ /** Creates a new instance of StoredPageVisit */
16
20
  constructor() {
17
21
  super();
18
22
  const storage = Storage.getInstance();
@@ -29,18 +33,15 @@ class StoredPageVisit extends Singleton {
29
33
  // Get the events from the last message
30
34
  const { type, payload } = retryMessageQueue[retryMessageQueue.length - 1];
31
35
  // Only store page visit payloads
32
- if (type !== PV_METROPLEX_TYPE || !payload[PAGE_VISIT_PART_ATT_NAME]) {
36
+ if (type !== WebsocketMessageType.PageVisitPart || !payload) {
33
37
  return;
34
38
  }
35
- const events = payload[PAGE_VISIT_PART_ATT_NAME][PV_EVENTS_ATT_NAME]
36
- ? payload[PAGE_VISIT_PART_ATT_NAME][PV_EVENTS_ATT_NAME]
37
- : [];
39
+ const events = payload.events ? payload.events : [];
38
40
  const filteredEvents = events.filter(event =>
39
- // Return true if the event is a userstep, error, or location event
41
+ // Return true if the event is an userstep, error, or location event
40
42
  // Any userstep is used rather than just mouse clicks because we shouldn't
41
43
  // assume mouse clicks are the only way for any activity to happen
42
- event[TYPE_ATT_NAME] === USERSTEP_EVENT_TYPE ||
43
- event[TYPE_ATT_NAME] === ERROR_EVENT_TYPE);
44
+ event.type === EventType.UserStep || event.type === EventType.Error);
44
45
  // Only write the retry queue if it contains a user step or location change
45
46
  if (filteredEvents.length > 0) {
46
47
  this.writePageVisitsFromRetryQueue(retryMessageQueue, pvInfo);
@@ -52,9 +53,8 @@ class StoredPageVisit extends Singleton {
52
53
  const pageVisitFrags = [];
53
54
  for (let i = 0; i < retryMessageQueue.length; i += 1) {
54
55
  const { type, payload } = retryMessageQueue[i];
55
- if (type === PV_METROPLEX_TYPE) {
56
- const frag = payload[PAGE_VISIT_PART_ATT_NAME];
57
- pageVisitFrags.push(frag);
56
+ if (type === WebsocketMessageType.PageVisitPart) {
57
+ pageVisitFrags.push(payload);
58
58
  }
59
59
  }
60
60
  this._writePageVisitFrags(pageVisitFrags, pvInfo);
@@ -74,16 +74,35 @@ class StoredPageVisit extends Singleton {
74
74
  try {
75
75
  yield storage.save(NOIBU_STORED_PAGE_VISIT, json);
76
76
  }
77
- catch (err) {
77
+ catch (error) {
78
78
  yield storage.remove(NOIBU_STORED_PAGE_VISIT);
79
79
  // Calculate current storage size
80
80
  const size = yield storage.calculateUsedSize();
81
- ClientConfig.getInstance().postNoibuErrorAndOptionallyDisableClient(`Error writing pv to storage: ${err}, ` +
82
- `json size: ${json.length}, storage size: ${size}, ` +
83
- `${yield storage.getDiagnoseInfo()}`, false, SEVERITY.error);
81
+ ClientConfig.getInstance().postInternalError({
82
+ msg: `Error writing pv to storage`,
83
+ error,
84
+ jsonSize: json.length,
85
+ storageSize: size,
86
+ diagnosis: yield storage.getDiagnoseInfo(),
87
+ }, false, Severity.ERROR);
84
88
  }
85
89
  });
86
90
  }
91
+ /**
92
+ * Handles any issues that may appear when trying to get the stored page visit data
93
+ */
94
+ static handleGetPostDataError(data, error) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ // Remove the item since there is something corrupted
97
+ yield Storage.getInstance().remove(NOIBU_STORED_PAGE_VISIT);
98
+ ClientConfig.getInstance().postInternalError({
99
+ msg: `Error parsing page visit string`,
100
+ data,
101
+ error,
102
+ }, false, Severity.ERROR);
103
+ return null;
104
+ });
105
+ }
87
106
  /**
88
107
  * Read the stored page visit from storage, create a complete page visit object
89
108
  * and then post that to Metroplex
@@ -99,12 +118,17 @@ class StoredPageVisit extends Singleton {
99
118
  let storedPageVisit = {};
100
119
  try {
101
120
  storedPageVisit = JSON.parse(data);
121
+ if (!storedPageVisit.pageVisitInfo) {
122
+ return StoredPageVisit.handleGetPostDataError(data, new TypeError('Page visit info is missing'));
123
+ }
124
+ if (!storedPageVisit.pageVisitFrags) {
125
+ return StoredPageVisit.handleGetPostDataError(data, new TypeError('Page visit frags is missing'));
126
+ }
127
+ // Set is last to be true on the page visit information
128
+ storedPageVisit.pageVisitInfo.last = true;
102
129
  }
103
130
  catch (e) {
104
- // Remove the item since there is something corrupted
105
- yield storage.remove(NOIBU_STORED_PAGE_VISIT);
106
- ClientConfig.getInstance().postNoibuErrorAndOptionallyDisableClient(`Error parsing page visit string '${data}': ${e}`, false, SEVERITY.error);
107
- return null;
131
+ return StoredPageVisit.handleGetPostDataError(data, e);
108
132
  }
109
133
  // making sure we have the timestamp attribute since we added this logic after initially
110
134
  // releasing the storedPageVisit
@@ -120,16 +144,10 @@ class StoredPageVisit extends Singleton {
120
144
  }
121
145
  // Copy the page visit information from storage into a new complete PV
122
146
  const completePv = {
123
- [PAGE_VISIT_INFORMATION_ATT_NAME]: storedPageVisit.pageVisitInfo,
124
- [PAGE_VISIT_PART_ATT_NAME]: [],
125
- [PAGE_VISIT_VID_FRAG_ATT_NAME]: [],
147
+ pvi: storedPageVisit.pageVisitInfo,
148
+ pvp: storedPageVisit.pageVisitFrags,
149
+ pvvf: [],
126
150
  };
127
- // Set is last to be true on the page visit information
128
- completePv[PAGE_VISIT_INFORMATION_ATT_NAME][IS_LAST_ATT_NAME] = true;
129
- // Add the page visit frags to the complete PV
130
- for (let i = 0; i < storedPageVisit.pageVisitFrags.length; i += 1) {
131
- completePv[PAGE_VISIT_PART_ATT_NAME].push(storedPageVisit.pageVisitFrags[i]);
132
- }
133
151
  return completePv;
134
152
  });
135
153
  }
@@ -152,20 +170,16 @@ class StoredPageVisit extends Singleton {
152
170
  }
153
171
  /** Returns a promise that resolves to post the page visit in storage to Metroplex */
154
172
  _getPostPageVisitPromise() {
155
- return new Promise((resolve, reject) => {
156
- this._getPostData().then(data => {
157
- if (!data) {
158
- resolve();
159
- return;
160
- }
161
- const headers = {
162
- 'content-type': 'application/json',
163
- };
164
- makeRequest('POST', GET_METROPLEX_POST_URL(), data, headers, 2000, true)
165
- .then(resolve)
166
- .catch(e => {
167
- reject(new Error('Page visit post request rejected due to: ', e));
168
- });
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ const postData = yield this._getPostData();
175
+ if (!postData) {
176
+ return;
177
+ }
178
+ const headers = {
179
+ 'content-type': 'application/json',
180
+ };
181
+ return postRequest(GET_METROPLEX_POST_URL(), postData, headers, true, 2000).catch(cause => {
182
+ Promise.reject(new Error('Page visit post request rejected due to: ', { cause }));
169
183
  });
170
184
  });
171
185
  }
@@ -1,4 +1,3 @@
1
- /* eslint-disable require-jsdoc */
2
1
  // This file is generated by wsmatchers. Don't directly edit this file
3
2
  const addToCartTextRegexArray = [
4
3
  '\\b(view|add|my)\\b.*\\b(cart|bag|basket|bucket|box)\\b',
@@ -251,10 +250,7 @@ const checkoutPlaceOrderRegexArray = [
251
250
  ];
252
251
 
253
252
  function WHITELIST_TEXT_REGEX_STRING() {
254
- return addToCartTextRegexArray
255
- .concat(checkoutStartedTextRegexArray)
256
- .concat(checkoutPlaceOrderRegexArray)
257
- .join('|');
253
+ return addToCartTextRegexArray.concat(checkoutStartedTextRegexArray).concat(checkoutPlaceOrderRegexArray).join('|');
258
254
  }
259
255
 
260
256
  export { WHITELIST_TEXT_REGEX_STRING };
@@ -0,0 +1,48 @@
1
+ /** @module Constants */
2
+ export declare const CURRENT_NOIBUJS_VERSION = 2;
3
+ export declare const MAX_STRING_LENGTH = 1024;
4
+ export declare const MAX_TIME_FOR_UNSENT_DATA_MILLIS = 500;
5
+ export declare const PII_EMAIL_PATTERN: RegExp;
6
+ export declare const PII_REDACTION_REPLACEMENT_STRING = "******";
7
+ export declare const SEVERITY: {
8
+ error: string;
9
+ warn: string;
10
+ info: string;
11
+ debug: string;
12
+ };
13
+ export declare const MAX_METROPLEX_SOCKET_INNACTIVE_TIME: number;
14
+ export declare const MAX_BEACON_PAYLOAD_SIZE = 59000;
15
+ export declare const CONTENT_TYPE = "content-type";
16
+ /**
17
+ * Gets the script id from the cookie object, returns default if cannot be found
18
+ */
19
+ export declare function GET_SCRIPT_ID(): string;
20
+ /**
21
+ * Gets the max metro recon number
22
+ */
23
+ export declare function GET_MAX_METROPLEX_RECONNECTION_NUMBER(): number;
24
+ /**
25
+ * Returns the amount of time in milliseconds to delay a new connection by
26
+ * if we have exceeded the max consecutive connection count
27
+ */
28
+ export declare function GET_METROPLEX_CONSECUTIVE_CONNECTION_DELAY(): number;
29
+ /**
30
+ * gets the base url for metroplex's websocket connection
31
+ */
32
+ export declare function GET_METROPLEX_BASE_SOCKET_URL(): string;
33
+ /**
34
+ * gets the base url for metroplex's HTTP requests
35
+ */
36
+ export declare function GET_METROPLEX_BASE_HTTP_URL(): string;
37
+ /**
38
+ * Returns the URL that accepts http post requests
39
+ */
40
+ export declare function GET_METROPLEX_POST_URL(): string;
41
+ /**
42
+ * Returns the URL for posting metrics data to Metroplex
43
+ */
44
+ export declare function GET_METROPLEX_METRICS_URL(): string;
45
+ /**
46
+ * gets the current env
47
+ */
48
+ export declare function GET_DEVICE_ENV(): string;