react-native-gleapsdk 6.4.8 → 7.0.0

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.
@@ -3,12 +3,17 @@ declare class GleapNetworkIntercepter {
3
3
  requests: any;
4
4
  maxRequests: number;
5
5
  stopped: boolean;
6
+ updatedCallback: any;
7
+ setUpdatedCallback(updatedCallback: any): void;
6
8
  getRequests(): unknown[];
7
9
  setMaxRequests(maxRequests: number): void;
8
10
  setStopped(stopped: boolean): void;
9
11
  cleanRequests(): void;
10
12
  calcRequestTime(gleapRequestId: string | number): void;
11
- contentSizeOk(text: string): boolean;
13
+ getTextContentSizeOk(text: string): boolean;
14
+ prepareContent(text: string): string;
15
+ cleanupPayload(payload: any): any;
16
+ preparePayload(payload: any): string;
12
17
  start(): void;
13
18
  interceptNetworkRequests(callback: any): any;
14
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gleapsdk",
3
- "version": "6.4.8",
3
+ "version": "7.0.0",
4
4
  "description": "Know exactly why and how a bug happened. Get reports with screenshots, live action replays and all of the important metadata every time.",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -16,5 +16,5 @@ Pod::Spec.new do |s|
16
16
  s.source_files = "ios/**/*.{h,m,mm}"
17
17
 
18
18
  s.dependency "React-Core"
19
- s.dependency "Gleap", "6.4.8"
19
+ s.dependency "Gleap", "7.0.2"
20
20
  end
package/src/index.tsx CHANGED
@@ -16,28 +16,42 @@ type GleapActivationMethod = 'SHAKE' | 'SCREENSHOT';
16
16
 
17
17
  type GleapSdkType = {
18
18
  initialize(token: string): void;
19
- open(): void;
20
- startFeedbackFlow(feedbackFlow: string): void;
21
- sendSilentBugReport(
19
+ startFeedbackFlow(feedbackFlow: string, showBackButton: boolean): void;
20
+ sendSilentCrashReport(
22
21
  description: string,
23
22
  severity: 'LOW' | 'MEDIUM' | 'HIGH'
24
23
  ): void;
25
- sendSilentBugReportWithType(
24
+ sendSilentCrashReportWithExcludeData(
26
25
  description: string,
27
26
  severity: 'LOW' | 'MEDIUM' | 'HIGH',
28
- type: string
27
+ excludeData: {
28
+ customData?: Boolean;
29
+ metaData?: Boolean;
30
+ attachments?: Boolean;
31
+ consoleLog?: Boolean;
32
+ networkLogs?: Boolean;
33
+ customEventLog?: Boolean;
34
+ screenshot?: Boolean;
35
+ replays?: Boolean;
36
+ }
29
37
  ): void;
38
+ open(): void;
39
+ close(): void;
40
+ isOpened(): boolean;
30
41
  identify(userId: string, userProperties: GleapUserProperty): void;
42
+ identifyWithUserHash(
43
+ userId: string,
44
+ userProperties: GleapUserProperty,
45
+ userHash: string
46
+ ): void;
31
47
  clearIdentity(): void;
48
+ preFillForm(formData: { [key: string]: string }): void;
32
49
  setApiUrl(apiUrl: string): void;
33
- setWidgetUrl(widgetUrl: string): void;
50
+ setFrameUrl(frameUrl: string): void;
34
51
  attachCustomData(customData: any): void;
35
52
  setCustomData(key: string, value: string): void;
36
53
  removeCustomDataForKey(key: string): void;
37
54
  clearCustomData(): void;
38
- registerCustomAction(
39
- customActionCallback: (data: { name: string }) => void
40
- ): void;
41
55
  registerListener(eventType: string, callback: (data?: any) => void): void;
42
56
  setLanguage(language: string): void;
43
57
  logEvent(name: string, data: any): void;
@@ -47,23 +61,45 @@ type GleapSdkType = {
47
61
  stopNetworkLogging(): void;
48
62
  enableDebugConsoleLog(): void;
49
63
  setActivationMethods(activationMethods: GleapActivationMethod[]): void;
64
+ registerCustomAction(
65
+ customActionCallback: (data: { name: string }) => void
66
+ ): void;
50
67
  };
51
68
 
52
69
  const GleapSdk = NativeModules.Gleapsdk
53
70
  ? NativeModules.Gleapsdk
54
71
  : new Proxy(
55
- {},
56
- {
57
- get() {
58
- throw new Error(LINKING_ERROR);
59
- },
60
- }
61
- );
72
+ {},
73
+ {
74
+ get() {
75
+ throw new Error(LINKING_ERROR);
76
+ },
77
+ }
78
+ );
62
79
 
63
80
  if (GleapSdk && !GleapSdk.touched) {
64
81
  const networkLogger = new GleapNetworkIntercepter();
65
82
 
83
+ // Push the network log to the native SDK.
66
84
  GleapSdk.startNetworkLogging = () => {
85
+ // Set the callback.
86
+ networkLogger.setUpdatedCallback(() => {
87
+ if (!networkLogger) {
88
+ return;
89
+ }
90
+
91
+ const requests = networkLogger.getRequests();
92
+
93
+ if (requests && GleapSdk && typeof GleapSdk.attachNetworkLog !== 'undefined') {
94
+ if (Platform.OS === 'android') {
95
+ GleapSdk.attachNetworkLog(JSON.stringify(requests));
96
+ } else {
97
+ GleapSdk.attachNetworkLog(JSON.parse(JSON.stringify(requests)));
98
+ }
99
+ }
100
+ });
101
+
102
+ // Start the logger.
67
103
  networkLogger.start();
68
104
  };
69
105
 
@@ -103,32 +139,32 @@ if (GleapSdk && !GleapSdk.touched) {
103
139
  GleapSdk.startNetworkLogging();
104
140
  }
105
141
  notifyCallback('configLoaded', configJSON);
106
- } catch (exp) {}
107
- });
108
-
109
- gleapEmitter.addListener('feedbackWillBeSent', () => {
110
- // Push the network log to the native SDK.
111
- const requests = networkLogger.getRequests();
112
- if (Platform.OS === 'android') {
113
- GleapSdk.attachNetworkLog(JSON.stringify(requests));
114
- } else {
115
- GleapSdk.attachNetworkLog(JSON.parse(JSON.stringify(requests)));
116
- }
117
-
118
- notifyCallback('feedbackWillBeSent');
142
+ } catch (exp) { }
119
143
  });
120
144
 
121
145
  gleapEmitter.addListener('feedbackSent', (data) => {
122
146
  try {
123
147
  const dataJSON = data instanceof Object ? data : JSON.parse(data);
124
148
  notifyCallback('feedbackSent', dataJSON);
125
- } catch (exp) {}
149
+ } catch (exp) { }
150
+ });
151
+
152
+ gleapEmitter.addListener('feedbackFlowStarted', (feedbackAction) => {
153
+ notifyCallback('feedbackFlowStarted', feedbackAction);
126
154
  });
127
155
 
128
156
  gleapEmitter.addListener('feedbackSendingFailed', () => {
129
157
  notifyCallback('feedbackSendingFailed');
130
158
  });
131
159
 
160
+ gleapEmitter.addListener('widgetOpened', () => {
161
+ notifyCallback('widgetOpened');
162
+ });
163
+
164
+ gleapEmitter.addListener('widgetClosed', () => {
165
+ notifyCallback('widgetClosed');
166
+ });
167
+
132
168
  function isJsonString(str: string) {
133
169
  try {
134
170
  JSON.parse(str);
@@ -149,11 +185,10 @@ if (GleapSdk && !GleapSdk.touched) {
149
185
  name,
150
186
  });
151
187
  }
152
- } catch (exp) {}
188
+ } catch (exp) { }
153
189
  });
154
190
 
155
191
  GleapSdk.removeAllAttachments();
156
-
157
192
  GleapSdk.touched = true;
158
193
  }
159
194
 
@@ -4,6 +4,11 @@ class GleapNetworkIntercepter {
4
4
  requests: any = {};
5
5
  maxRequests = 10;
6
6
  stopped = false;
7
+ updatedCallback: any = null;
8
+
9
+ setUpdatedCallback(updatedCallback: any) {
10
+ this.updatedCallback = updatedCallback;
11
+ }
7
12
 
8
13
  getRequests() {
9
14
  return Object.values(this.requests);
@@ -25,6 +30,10 @@ class GleapNetworkIntercepter {
25
30
  delete this.requests[keysToRemove[i]];
26
31
  }
27
32
  }
33
+
34
+ if (this.updatedCallback) {
35
+ this.updatedCallback();
36
+ }
28
37
  }
29
38
 
30
39
  calcRequestTime(gleapRequestId: string | number) {
@@ -45,18 +54,45 @@ class GleapNetworkIntercepter {
45
54
  }
46
55
  }
47
56
 
48
- contentSizeOk(text: string) {
57
+ getTextContentSizeOk(text: string) {
49
58
  if (text && text.length) {
50
59
  const size = text.length * 16;
51
60
  const kiloBytes = size / 1024;
52
61
  const megaBytes = kiloBytes / 1024;
53
- if (megaBytes < 0.5) {
62
+ if (megaBytes < 0.2) {
54
63
  return true;
55
64
  }
56
65
  }
57
66
  return false;
58
67
  }
59
68
 
69
+ prepareContent(text: string) {
70
+ if (!this.getTextContentSizeOk(text)) {
71
+ return "<content_too_large>";
72
+ }
73
+
74
+ return text;
75
+ }
76
+
77
+ cleanupPayload(payload: any) {
78
+ if (payload === undefined || payload === null) {
79
+ return "{}";
80
+ }
81
+
82
+ try {
83
+ if (ArrayBuffer.isView(payload)) {
84
+ return `{ type: "binary", length: ${payload.byteLength} }`;
85
+ }
86
+ } catch (exp) { }
87
+
88
+ return payload;
89
+ }
90
+
91
+ preparePayload(payload: any) {
92
+ var payloadText = this.cleanupPayload(payload);
93
+ return this.prepareContent(payloadText);
94
+ }
95
+
60
96
  start() {
61
97
  this.setStopped(false);
62
98
  this.interceptNetworkRequests({
@@ -69,7 +105,7 @@ class GleapNetworkIntercepter {
69
105
  var method = params[1].method ? params[1].method : 'GET';
70
106
  this.requests[gleapRequestId] = {
71
107
  request: {
72
- payload: params[1].body,
108
+ payload: this.preparePayload(params[1].body),
73
109
  headers: params[1].headers,
74
110
  },
75
111
  type: method,
@@ -115,9 +151,7 @@ class GleapNetworkIntercepter {
115
151
  this.requests[gleapRequestId].response = {
116
152
  status: req.status,
117
153
  statusText: req.statusText,
118
- responseText: this.contentSizeOk(responseText)
119
- ? responseText
120
- : '<response_too_large>',
154
+ responseText: this.prepareContent(responseText),
121
155
  };
122
156
 
123
157
  this.calcRequestTime(gleapRequestId);
@@ -171,7 +205,7 @@ class GleapNetworkIntercepter {
171
205
  this.requests[request.gleapRequestId]
172
206
  ) {
173
207
  this.requests[request.gleapRequestId].request = {
174
- payload: args.length > 0 ? args[0] : '',
208
+ payload: this.preparePayload(args.length > 0 ? args[0] : ''),
175
209
  headers: request.requestHeaders,
176
210
  };
177
211
  }
@@ -219,9 +253,7 @@ class GleapNetworkIntercepter {
219
253
  this.requests[request.gleapRequestId].success = true;
220
254
  this.requests[request.gleapRequestId].response = {
221
255
  status: request.status,
222
- responseText: this.contentSizeOk(responseText)
223
- ? responseText
224
- : '<response_too_large>',
256
+ responseText: this.prepareContent(responseText),
225
257
  };
226
258
 
227
259
  this.calcRequestTime(request.gleapRequestId);