noibu-react-native 0.0.4 → 0.0.6

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.
@@ -1,4 +1,4 @@
1
- import { MAX_FRAMES_IN_ARRAY, MAX_STRING_LENGTH, JS_STACK_LINE_ATT_NAME, JS_STACK_COL_ATT_NAME, JS_STACK_FILE_ATT_NAME, JS_STACK_METHOD_ATT_NAME } from '../constants.js';
1
+ import { MAX_FRAMES_IN_ARRAY, MAX_STRING_LENGTH } from '../constants.js';
2
2
 
3
3
  /* eslint-disable require-jsdoc,prefer-destructuring,camelcase */
4
4
  // This is a loose copy of ravenjs code
@@ -56,14 +56,14 @@ const extractSafariExtensionDetails = (func, filename) => {
56
56
  };
57
57
  function createFrame(filename, func, lineno, colno) {
58
58
  const frame = {
59
- [JS_STACK_FILE_ATT_NAME]: filename,
60
- [JS_STACK_METHOD_ATT_NAME]: func,
59
+ file: filename,
60
+ mname: func,
61
61
  };
62
62
  if (lineno !== undefined) {
63
- frame[JS_STACK_LINE_ATT_NAME] = lineno;
63
+ frame.line = lineno;
64
64
  }
65
65
  if (colno !== undefined) {
66
- frame[JS_STACK_COL_ATT_NAME] = colno;
66
+ frame.column = colno;
67
67
  }
68
68
  return frame;
69
69
  }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "noibu-react-native",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
+ "targetNjsVersion": "1.0.104",
4
5
  "description": "React-Native SDK for NoibuJS to collect errors in React-Native applications",
5
6
  "main": "dist/entry/index.js",
6
7
  "types": "dist/entry/index.d.ts",
@@ -1,177 +0,0 @@
1
- import { GET_ATTRIBUTE_SELECTORS } from '../constants.js';
2
- import InputManager from '../api/inputManager.js';
3
-
4
- /** @module ElementMonitor */
5
-
6
- /** Monitors the elements matching query selectors and passes them to the InputManager */
7
- class ElementMonitor {
8
- /**
9
- * gets the singleton instance
10
- * @returns {ElementMonitor}
11
- */
12
- static getInstance() {
13
- if (!this.instance) {
14
- this.instance = new ElementMonitor();
15
- }
16
-
17
- return this.instance;
18
- }
19
-
20
- /**
21
- * Safely calls `querySelectorAll` on the given node and returns an array of
22
- * matching child elements. If `querySelectorAll` returns a falsy value,
23
- * an empty array is returned.
24
- *
25
- * @private
26
- * @param {Node} node - The node on which to call `querySelectorAll`.
27
- * @param {string} selector - The CSS selector used to match child elements.
28
- * @returns {Array<Element>} An array of matching child elements.
29
- */
30
- _safeQueryAll(node, selector) {
31
- const matchingChildElements = node.querySelectorAll(selector);
32
- if (!matchingChildElements) {
33
- return [];
34
- }
35
-
36
- return Array.from(matchingChildElements);
37
- }
38
-
39
- /**
40
- * Processes the given elements by adding their custom attributes to the InputManager.
41
- *
42
- * @private
43
- * @param {NodeList|Array} elements - The list of elements to be processed.
44
- * @param {string} selector - The selector corresponding to the elements being processed.
45
- */
46
- _processMatchingElements(elements, selector) {
47
- elements.forEach(element => {
48
- if (!element) {
49
- return;
50
- }
51
-
52
- const selectorText = element.textContent;
53
-
54
- if (!selectorText) {
55
- return;
56
- }
57
-
58
- InputManager.getInstance()._addCustomAttribute(selector, selectorText);
59
- });
60
- }
61
-
62
- /**
63
- * Finds and processes matching elements within the added nodes by checking if
64
- * they match any of the attribute selectors from GET_ATTRIBUTE_SELECTORS().
65
- * If a node or any of its descendants match, their custom attributes are added
66
- * to the InputManager.
67
- *
68
- * @private
69
- * @param {NodeList|Array} addedNodes - The list of nodes that were added or
70
- * modified in the DOM. Each node in the list will be checked against the
71
- * attribute selectors, and their matching descendants will also be processed.
72
- */
73
- _findAndAddMatchingElementsInNodes(addedNodes) {
74
- const attributeSelectorNames = Object.keys(GET_ATTRIBUTE_SELECTORS());
75
- attributeSelectorNames.forEach(name => {
76
- const selector = GET_ATTRIBUTE_SELECTORS()[name];
77
- if (!selector) {
78
- return;
79
- }
80
-
81
- addedNodes.forEach(node => {
82
- // move to the next node its not an element node
83
- if (node.nodeType !== Node.ELEMENT_NODE) {
84
- return;
85
- }
86
-
87
- let matchingElements = [];
88
-
89
- if (node.matches(selector)) {
90
- matchingElements.push(node);
91
- }
92
-
93
- const matchingChildElements = this._safeQueryAll(node, selector);
94
- matchingElements = matchingElements.concat(matchingChildElements);
95
-
96
- this._processMatchingElements(matchingElements, name);
97
- });
98
- });
99
- }
100
-
101
- /** Sets up a MutationObserver to monitor added elements and attribute changes */
102
- _setupMutationObserver() {
103
- const observer = new MutationObserver(mutations => {
104
- mutations.forEach(mutation => {
105
- // Handle childList mutations
106
- if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
107
- this._findAndAddMatchingElementsInNodes(mutation.addedNodes);
108
- }
109
-
110
- // Handle attribute mutations
111
- if (mutation.type === 'attributes') {
112
- const targetNode = mutation.target;
113
- if (targetNode.nodeType === Node.ELEMENT_NODE) {
114
- this._findAndAddMatchingElementsInNodes([targetNode]);
115
- }
116
- }
117
- });
118
- });
119
-
120
- // the observer will get called when children are added and changed
121
- const observerConfig = { childList: true, subtree: true, attributes: true };
122
- observer.observe(document.documentElement, observerConfig);
123
- this.observer = observer;
124
- }
125
-
126
- /** Finds and adds matching elements to the InputManager */
127
- _findAndAddMatchingElements() {
128
- const attributeSelectorNames = Object.keys(GET_ATTRIBUTE_SELECTORS());
129
- attributeSelectorNames.forEach(name => {
130
- const selector = GET_ATTRIBUTE_SELECTORS()[name];
131
- if (!selector) {
132
- return;
133
- }
134
- const elements = this._safeQueryAll(document, selector);
135
- this._processMatchingElements(elements, name);
136
- });
137
- }
138
-
139
- /** Starts monitoring elements matching query selectors */
140
- monitor() {
141
- const attributeNames = Object.keys(GET_ATTRIBUTE_SELECTORS());
142
- // if we have no attributes to look for, do not setup the listeners
143
- if (attributeNames.length === 0) {
144
- return;
145
- }
146
- this._findAndAddMatchingElements();
147
- if (typeof MutationObserver !== 'undefined') {
148
- this._setupMutationObserver();
149
- } else {
150
- // Fallback using setInterval if MutationObserver is not supported
151
- this.interval = setInterval(() => {
152
- this._findAndAddMatchingElements();
153
- }, 5000); // Check for changes every N seconds
154
- }
155
- }
156
-
157
- /**
158
- * Disconnects the MutationObserver instance, if it exists and has a valid disconnect method.
159
- * This is needed for testing since we want to properly tear down mutation listeners
160
- * @private
161
- */
162
- _disconnectObserver() {
163
- if (
164
- this.observer &&
165
- this.observer.disconnect &&
166
- typeof this.observer.disconnect === 'function'
167
- ) {
168
- this.observer.disconnect();
169
- }
170
-
171
- if (this.interval) {
172
- clearInterval(this.interval);
173
- }
174
- }
175
- }
176
-
177
- export { ElementMonitor };