react-native-gleapsdk 6.4.8 → 7.0.2

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.
@@ -10,6 +10,12 @@ class GleapNetworkIntercepter {
10
10
  _defineProperty(this, "maxRequests", 10);
11
11
 
12
12
  _defineProperty(this, "stopped", false);
13
+
14
+ _defineProperty(this, "updatedCallback", null);
15
+ }
16
+
17
+ setUpdatedCallback(updatedCallback) {
18
+ this.updatedCallback = updatedCallback;
13
19
  }
14
20
 
15
21
  getRequests() {
@@ -34,6 +40,10 @@ class GleapNetworkIntercepter {
34
40
  delete this.requests[keysToRemove[i]];
35
41
  }
36
42
  }
43
+
44
+ if (this.updatedCallback) {
45
+ this.updatedCallback();
46
+ }
37
47
  }
38
48
 
39
49
  calcRequestTime(gleapRequestId) {
@@ -49,13 +59,13 @@ class GleapNetworkIntercepter {
49
59
  }
50
60
  }
51
61
 
52
- contentSizeOk(text) {
62
+ getTextContentSizeOk(text) {
53
63
  if (text && text.length) {
54
64
  const size = text.length * 16;
55
65
  const kiloBytes = size / 1024;
56
66
  const megaBytes = kiloBytes / 1024;
57
67
 
58
- if (megaBytes < 0.5) {
68
+ if (megaBytes < 0.2) {
59
69
  return true;
60
70
  }
61
71
  }
@@ -63,6 +73,33 @@ class GleapNetworkIntercepter {
63
73
  return false;
64
74
  }
65
75
 
76
+ prepareContent(text) {
77
+ if (!this.getTextContentSizeOk(text)) {
78
+ return "<content_too_large>";
79
+ }
80
+
81
+ return text;
82
+ }
83
+
84
+ cleanupPayload(payload) {
85
+ if (payload === undefined || payload === null) {
86
+ return "{}";
87
+ }
88
+
89
+ try {
90
+ if (ArrayBuffer.isView(payload)) {
91
+ return `{ type: "binary", length: ${payload.byteLength} }`;
92
+ }
93
+ } catch (exp) {}
94
+
95
+ return payload;
96
+ }
97
+
98
+ preparePayload(payload) {
99
+ var payloadText = this.cleanupPayload(payload);
100
+ return this.prepareContent(payloadText);
101
+ }
102
+
66
103
  start() {
67
104
  this.setStopped(false);
68
105
  this.interceptNetworkRequests({
@@ -75,7 +112,7 @@ class GleapNetworkIntercepter {
75
112
  var method = params[1].method ? params[1].method : 'GET';
76
113
  this.requests[gleapRequestId] = {
77
114
  request: {
78
- payload: params[1].body,
115
+ payload: this.preparePayload(params[1].body),
79
116
  headers: params[1].headers
80
117
  },
81
118
  type: method,
@@ -114,7 +151,7 @@ class GleapNetworkIntercepter {
114
151
  this.requests[gleapRequestId].response = {
115
152
  status: req.status,
116
153
  statusText: req.statusText,
117
- responseText: this.contentSizeOk(responseText) ? responseText : '<response_too_large>'
154
+ responseText: this.prepareContent(responseText)
118
155
  };
119
156
  this.calcRequestTime(gleapRequestId);
120
157
  this.cleanRequests();
@@ -156,7 +193,7 @@ class GleapNetworkIntercepter {
156
193
 
157
194
  if (request && request.gleapRequestId && this.requests && this.requests[request.gleapRequestId]) {
158
195
  this.requests[request.gleapRequestId].request = {
159
- payload: args.length > 0 ? args[0] : '',
196
+ payload: this.preparePayload(args.length > 0 ? args[0] : ''),
160
197
  headers: request.requestHeaders
161
198
  };
162
199
  }
@@ -192,7 +229,7 @@ class GleapNetworkIntercepter {
192
229
  this.requests[request.gleapRequestId].success = true;
193
230
  this.requests[request.gleapRequestId].response = {
194
231
  status: request.status,
195
- responseText: this.contentSizeOk(responseText) ? responseText : '<response_too_large>'
232
+ responseText: this.prepareContent(responseText)
196
233
  };
197
234
  this.calcRequestTime(request.gleapRequestId);
198
235
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["networklogger.ts"],"names":["GleapNetworkIntercepter","getRequests","Object","values","requests","setMaxRequests","maxRequests","setStopped","stopped","cleanRequests","keys","length","keysToRemove","slice","i","calcRequestTime","gleapRequestId","startDate","date","getTime","isFrozen","duration","Date","toString","contentSizeOk","text","size","kiloBytes","megaBytes","start","interceptNetworkRequests","onFetch","params","method","request","payload","body","headers","type","url","onFetchLoad","req","success","response","status","statusText","responseText","exp","then","catch","_err","onFetchFailed","onOpen","args","onSend","requestHeaders","onError","onLoad","contentType","getResponseHeader","isTextOrJSON","includes","responseType","_response","callback","self","XMLHttpRequest","prototype","open","send","wrappedSetRequestHeader","setRequestHeader","header","value","hasOwnProperty","push","requestId","arguments","addEventListener","apply","global","originalFetch","fetch","clone","data","err"],"mappings":";;AAAA;AACA,MAAMA,uBAAN,CAA8B;AAAA;AAAA,uCAChB,CADgB;;AAAA,sCAEZ,EAFY;;AAAA,yCAGd,EAHc;;AAAA,qCAIlB,KAJkB;AAAA;;AAM5BC,EAAAA,WAAW,GAAG;AACZ,WAAOC,MAAM,CAACC,MAAP,CAAc,KAAKC,QAAnB,CAAP;AACD;;AAEDC,EAAAA,cAAc,CAACC,WAAD,EAAsB;AAClC,SAAKA,WAAL,GAAmBA,WAAnB;AACD;;AAEDC,EAAAA,UAAU,CAACC,OAAD,EAAmB;AAC3B,SAAKA,OAAL,GAAeA,OAAf;AACD;;AAEDC,EAAAA,aAAa,GAAG;AACd,QAAIC,IAAI,GAAGR,MAAM,CAACQ,IAAP,CAAY,KAAKN,QAAjB,CAAX;;AACA,QAAIM,IAAI,CAACC,MAAL,GAAc,KAAKL,WAAvB,EAAoC;AAClC,UAAIM,YAAY,GAAGF,IAAI,CAACG,KAAL,CAAW,CAAX,EAAcH,IAAI,CAACC,MAAL,GAAc,KAAKL,WAAjC,CAAnB;;AACA,WAAK,IAAIQ,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,YAAY,CAACD,MAAjC,EAAyCG,CAAC,EAA1C,EAA8C;AAC5C,eAAO,KAAKV,QAAL,CAAcQ,YAAY,CAACE,CAAD,CAA1B,CAAP;AACD;AACF;AACF;;AAEDC,EAAAA,eAAe,CAACC,cAAD,EAAkC;AAC/C,QAAI,CAAC,KAAKZ,QAAL,CAAcY,cAAd,CAAL,EAAoC;AAClC;AACD;;AAED,QAAIC,SAAS,GAAG,KAAKb,QAAL,CAAcY,cAAd,EAA8BE,IAA9C;;AACA,QACED,SAAS,IACT,OAAOA,SAAS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AACV,MAAT,CAAgB,IAAhB,EAAsBuB,SAAtB,CAAnB,CAD0C,CAE1C;;AACA,aAAOR,IAAI,CAACU,KAAL,CAAW,IAAX,EAAiBF,SAAjB,CAAP;AACD,KAJD,CAhEsC,CAsEtC;;;AACA,QAAIG,MAAJ,EAAY;AACV,OAAC,YAAY;AACX,YAAIC,aAAa,GAAGD,MAAM,CAACE,KAA3B;;AACAF,QAAAA,MAAM,CAACE,KAAP,GAAe,YAAY;AACzB,cAAIlE,cAAc,GAAG,EAAEiD,IAAI,CAACW,SAA5B;AACAZ,UAAAA,QAAQ,CAACjC,OAAT,CAAiB8C,SAAjB,EAA4B7D,cAA5B;AAEA,iBACEiE,aAAa,CACX;AADW,WAEVF,KAFH,CAES,IAFT,EAEeF,SAFf,EAGG7B,IAHH,CAGQ,UAAUL,QAAV,EAAoB;AACxB,gBAAIA,QAAQ,IAAI,OAAOA,QAAQ,CAACwC,KAAhB,KAA0B,UAA1C,EAAsD;AACpD,oBAAMC,IAAI,GAAGzC,QAAQ,CAACwC,KAAT,EAAb;AACAnB,cAAAA,QAAQ,CAACxB,WAAT,CAAqB4C,IAArB,EAA2BpE,cAA3B;AACD;;AAED,mBAAO2B,QAAP;AACD,WAVH,EAWGM,KAXH,CAWUoC,GAAD,IAAS;AACdrB,YAAAA,QAAQ,CAACb,aAAT,CAAuBkC,GAAvB,EAA4BrE,cAA5B;AACA,kBAAMqE,GAAN;AACD,WAdH,CADF;AAiBD,SArBD;AAsBD,OAxBD;AAyBD;;AAED,WAAOrB,QAAP;AACD;;AA7U2B;;AAgV9B,eAAehE,uBAAf","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nclass GleapNetworkIntercepter {\n requestId = 0;\n requests: any = {};\n maxRequests = 10;\n stopped = false;\n\n getRequests() {\n return Object.values(this.requests);\n }\n\n setMaxRequests(maxRequests: number) {\n this.maxRequests = maxRequests;\n }\n\n setStopped(stopped: boolean) {\n this.stopped = stopped;\n }\n\n cleanRequests() {\n var keys = Object.keys(this.requests);\n if (keys.length > this.maxRequests) {\n var keysToRemove = keys.slice(0, keys.length - this.maxRequests);\n for (var i = 0; i < keysToRemove.length; i++) {\n delete this.requests[keysToRemove[i]];\n }\n }\n }\n\n calcRequestTime(gleapRequestId: string | number) {\n if (!this.requests[gleapRequestId]) {\n return;\n }\n\n var startDate = this.requests[gleapRequestId].date;\n if (\n startDate &&\n typeof startDate.getTime === 'function' &&\n !Object.isFrozen(this.requests[gleapRequestId])\n ) {\n this.requests[gleapRequestId].duration =\n new Date().getTime() - startDate.getTime();\n this.requests[gleapRequestId].date =\n this.requests[gleapRequestId].date.toString();\n }\n }\n\n contentSizeOk(text: string) {\n if (text && text.length) {\n const size = text.length * 16;\n const kiloBytes = size / 1024;\n const megaBytes = kiloBytes / 1024;\n if (megaBytes < 0.5) {\n return true;\n }\n }\n return false;\n }\n\n start() {\n this.setStopped(false);\n this.interceptNetworkRequests({\n onFetch: (params: any, gleapRequestId: any) => {\n if (this.stopped) {\n return;\n }\n\n if (params.length >= 2) {\n var method = params[1].method ? params[1].method : 'GET';\n this.requests[gleapRequestId] = {\n request: {\n payload: params[1].body,\n headers: params[1].headers,\n },\n type: method,\n url: params[0],\n date: new Date(),\n };\n } else {\n this.requests[gleapRequestId] = {\n request: {},\n url: params[0],\n type: 'GET',\n date: new Date(),\n };\n }\n\n this.cleanRequests();\n },\n onFetchLoad: (req: any, gleapRequestId: any) => {\n if (\n this.stopped ||\n !gleapRequestId ||\n !this.requests ||\n !this.requests[gleapRequestId]\n ) {\n return;\n }\n\n try {\n this.requests[gleapRequestId].success = true;\n this.requests[gleapRequestId].response = {\n status: req.status,\n statusText: '',\n responseText: '<request_still_open>',\n };\n this.calcRequestTime(gleapRequestId);\n } catch (exp) {}\n\n req\n .text()\n .then((responseText: any) => {\n if (this.requests && this.requests[gleapRequestId]) {\n this.requests[gleapRequestId].success = true;\n this.requests[gleapRequestId].response = {\n status: req.status,\n statusText: req.statusText,\n responseText: this.contentSizeOk(responseText)\n ? responseText\n : '<response_too_large>',\n };\n\n this.calcRequestTime(gleapRequestId);\n this.cleanRequests();\n }\n })\n .catch((_err: any) => {\n if (this) {\n this.cleanRequests();\n }\n });\n },\n onFetchFailed: (_err: any, gleapRequestId: any) => {\n if (this.stopped) {\n return;\n }\n\n this.requests[gleapRequestId].success = false;\n this.calcRequestTime(gleapRequestId);\n this.cleanRequests();\n },\n onOpen: (request: any, args: string | any[]) => {\n if (this.stopped) {\n return;\n }\n\n if (\n request &&\n request.gleapRequestId &&\n args.length >= 2 &&\n this.requests\n ) {\n this.requests[request.gleapRequestId] = {\n type: args[0],\n url: args[1],\n date: new Date(),\n };\n }\n\n this.cleanRequests();\n },\n onSend: (request: any, args: string | any[]) => {\n if (this.stopped) {\n return;\n }\n\n if (\n request &&\n request.gleapRequestId &&\n this.requests &&\n this.requests[request.gleapRequestId]\n ) {\n this.requests[request.gleapRequestId].request = {\n payload: args.length > 0 ? args[0] : '',\n headers: request.requestHeaders,\n };\n }\n\n this.cleanRequests();\n },\n onError: (request: any) => {\n if (\n !this.stopped &&\n this.requests &&\n request &&\n request.gleapRequestId &&\n this.requests[request.gleapRequestId]\n ) {\n this.requests[request.gleapRequestId].success = false;\n this.calcRequestTime(request.gleapRequestId);\n }\n\n this.cleanRequests();\n },\n onLoad: (request: any) => {\n if (this.stopped) {\n return;\n }\n\n if (\n request &&\n request.gleapRequestId &&\n this.requests &&\n this.requests[request.gleapRequestId]\n ) {\n const contentType = request.getResponseHeader('content-type');\n const isTextOrJSON =\n contentType &&\n (contentType.includes('json') || contentType.includes('text'));\n\n var responseText = '<' + contentType + '>';\n if (request.responseType === '' || request.responseType === 'text') {\n responseText = request.responseText;\n }\n if (request._response && isTextOrJSON) {\n responseText = request._response;\n }\n\n this.requests[request.gleapRequestId].success = true;\n this.requests[request.gleapRequestId].response = {\n status: request.status,\n responseText: this.contentSizeOk(responseText)\n ? responseText\n : '<response_too_large>',\n };\n\n this.calcRequestTime(request.gleapRequestId);\n }\n\n this.cleanRequests();\n },\n });\n }\n\n interceptNetworkRequests(callback: any) {\n // eslint-disable-next-line consistent-this\n var self = this;\n\n // @ts-ignore\n if (XMLHttpRequest.prototype['gleapTouched']) {\n return;\n }\n\n // @ts-ignore\n XMLHttpRequest.prototype['gleapTouched'] = true;\n\n // XMLHttpRequest\n const open = XMLHttpRequest.prototype.open;\n const send = XMLHttpRequest.prototype.send;\n\n // @ts-ignore\n XMLHttpRequest.prototype.wrappedSetRequestHeader =\n XMLHttpRequest.prototype.setRequestHeader;\n XMLHttpRequest.prototype.setRequestHeader = function (header, value) {\n // @ts-ignore\n if (!this.requestHeaders) {\n // @ts-ignore\n this.requestHeaders = {};\n }\n\n // @ts-ignore\n if (this.requestHeaders && this.requestHeaders.hasOwnProperty(header)) {\n return;\n }\n\n // @ts-ignore\n if (!this.requestHeaders[header]) {\n // @ts-ignore\n this.requestHeaders[header] = [];\n }\n\n // @ts-ignore\n this.requestHeaders[header].push(value);\n // @ts-ignore\n this.wrappedSetRequestHeader(header, value);\n };\n\n XMLHttpRequest.prototype.open = function () {\n (this as any).gleapRequestId = ++self.requestId;\n callback.onOpen && callback.onOpen(this, arguments);\n\n if (callback.onLoad) {\n this.addEventListener('load', function () {\n // @ts-ignore\n callback.onLoad(this);\n });\n }\n if (callback.onError) {\n this.addEventListener('error', function () {\n // @ts-ignore\n callback.onError(this);\n });\n }\n\n // @ts-ignore\n return open.apply(this, arguments);\n };\n\n XMLHttpRequest.prototype.send = function () {\n callback.onSend && callback.onSend(this, arguments);\n // @ts-ignore\n return send.apply(this, arguments);\n };\n\n // Fetch\n if (global) {\n (function () {\n var originalFetch = global.fetch;\n global.fetch = function () {\n var gleapRequestId = ++self.requestId;\n callback.onFetch(arguments, gleapRequestId);\n\n return (\n originalFetch\n // @ts-ignore\n .apply(this, arguments)\n .then(function (response) {\n if (response && typeof response.clone === 'function') {\n const data = response.clone();\n callback.onFetchLoad(data, gleapRequestId);\n }\n\n return response;\n })\n .catch((err) => {\n callback.onFetchFailed(err, gleapRequestId);\n throw err;\n })\n );\n };\n })();\n }\n\n return callback;\n }\n}\n\nexport default GleapNetworkIntercepter;\n"]}
1
+ {"version":3,"sources":["networklogger.ts"],"names":["GleapNetworkIntercepter","setUpdatedCallback","updatedCallback","getRequests","Object","values","requests","setMaxRequests","maxRequests","setStopped","stopped","cleanRequests","keys","length","keysToRemove","slice","i","calcRequestTime","gleapRequestId","startDate","date","getTime","isFrozen","duration","Date","toString","getTextContentSizeOk","text","size","kiloBytes","megaBytes","prepareContent","cleanupPayload","payload","undefined","ArrayBuffer","isView","byteLength","exp","preparePayload","payloadText","start","interceptNetworkRequests","onFetch","params","method","request","body","headers","type","url","onFetchLoad","req","success","response","status","statusText","responseText","then","catch","_err","onFetchFailed","onOpen","args","onSend","requestHeaders","onError","onLoad","contentType","getResponseHeader","isTextOrJSON","includes","responseType","_response","callback","self","XMLHttpRequest","prototype","open","send","wrappedSetRequestHeader","setRequestHeader","header","value","hasOwnProperty","push","requestId","arguments","addEventListener","apply","global","originalFetch","fetch","clone","data","err"],"mappings":";;AAAA;AACA,MAAMA,uBAAN,CAA8B;AAAA;AAAA,uCAChB,CADgB;;AAAA,sCAEZ,EAFY;;AAAA,yCAGd,EAHc;;AAAA,qCAIlB,KAJkB;;AAAA,6CAKL,IALK;AAAA;;AAO5BC,EAAAA,kBAAkB,CAACC,eAAD,EAAuB;AACvC,SAAKA,eAAL,GAAuBA,eAAvB;AACD;;AAEDC,EAAAA,WAAW,GAAG;AACZ,WAAOC,MAAM,CAACC,MAAP,CAAc,KAAKC,QAAnB,CAAP;AACD;;AAEDC,EAAAA,cAAc,CAACC,WAAD,EAAsB;AAClC,SAAKA,WAAL,GAAmBA,WAAnB;AACD;;AAEDC,EAAAA,UAAU,CAACC,OAAD,EAAmB;AAC3B,SAAKA,OAAL,GAAeA,OAAf;AACD;;AAEDC,EAAAA,aAAa,GAAG;AACd,QAAIC,IAAI,GAAGR,MAAM,CAACQ,IAAP,CAAY,KAA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AAzB,GAAgC,YAAY;AAC1CL,MAAAA,QAAQ,CAACV,MAAT,IAAmBU,QAAQ,CAACV,MAAT,CAAgB,IAAhB,EAAsBuB,SAAtB,CAAnB,CAD0C,CAE1C;;AACA,aAAOR,IAAI,CAACU,KAAL,CAAW,IAAX,EAAiBF,SAAjB,CAAP;AACD,KAJD,CAhEsC,CAsEtC;;;AACA,QAAIG,MAAJ,EAAY;AACV,OAAC,YAAY;AACX,YAAIC,aAAa,GAAGD,MAAM,CAACE,KAA3B;;AACAF,QAAAA,MAAM,CAACE,KAAP,GAAe,YAAY;AACzB,cAAI1E,cAAc,GAAG,EAAEyD,IAAI,CAACW,SAA5B;AACAZ,UAAAA,QAAQ,CAAC/B,OAAT,CAAiB4C,SAAjB,EAA4BrE,cAA5B;AAEA,iBACEyE,aAAa,CACX;AADW,WAEVF,KAFH,CAES,IAFT,EAEeF,SAFf,EAGG7B,IAHH,CAGQ,UAAUJ,QAAV,EAAoB;AACxB,gBAAIA,QAAQ,IAAI,OAAOA,QAAQ,CAACuC,KAAhB,KAA0B,UAA1C,EAAsD;AACpD,oBAAMC,IAAI,GAAGxC,QAAQ,CAACuC,KAAT,EAAb;AACAnB,cAAAA,QAAQ,CAACvB,WAAT,CAAqB2C,IAArB,EAA2B5E,cAA3B;AACD;;AAED,mBAAOoC,QAAP;AACD,WAVH,EAWGK,KAXH,CAWUoC,GAAD,IAAS;AACdrB,YAAAA,QAAQ,CAACb,aAAT,CAAuBkC,GAAvB,EAA4B7E,cAA5B;AACA,kBAAM6E,GAAN;AACD,WAdH,CADF;AAiBD,SArBD;AAsBD,OAxBD;AAyBD;;AAED,WAAOrB,QAAP;AACD;;AA7W2B;;AAgX9B,eAAe1E,uBAAf","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nclass GleapNetworkIntercepter {\n requestId = 0;\n requests: any = {};\n maxRequests = 10;\n stopped = false;\n updatedCallback: any = null;\n\n setUpdatedCallback(updatedCallback: any) {\n this.updatedCallback = updatedCallback; \n }\n\n getRequests() {\n return Object.values(this.requests);\n }\n\n setMaxRequests(maxRequests: number) {\n this.maxRequests = maxRequests;\n }\n\n setStopped(stopped: boolean) {\n this.stopped = stopped;\n }\n\n cleanRequests() {\n var keys = Object.keys(this.requests);\n if (keys.length > this.maxRequests) {\n var keysToRemove = keys.slice(0, keys.length - this.maxRequests);\n for (var i = 0; i < keysToRemove.length; i++) {\n delete this.requests[keysToRemove[i]];\n }\n }\n\n if (this.updatedCallback) {\n this.updatedCallback();\n }\n }\n\n calcRequestTime(gleapRequestId: string | number) {\n if (!this.requests[gleapRequestId]) {\n return;\n }\n\n var startDate = this.requests[gleapRequestId].date;\n if (\n startDate &&\n typeof startDate.getTime === 'function' &&\n !Object.isFrozen(this.requests[gleapRequestId])\n ) {\n this.requests[gleapRequestId].duration =\n new Date().getTime() - startDate.getTime();\n this.requests[gleapRequestId].date =\n this.requests[gleapRequestId].date.toString();\n }\n }\n\n getTextContentSizeOk(text: string) {\n if (text && text.length) {\n const size = text.length * 16;\n const kiloBytes = size / 1024;\n const megaBytes = kiloBytes / 1024;\n if (megaBytes < 0.2) {\n return true;\n }\n }\n return false;\n }\n\n prepareContent(text: string) {\n if (!this.getTextContentSizeOk(text)) {\n return \"<content_too_large>\";\n }\n\n return text;\n }\n\n cleanupPayload(payload: any) {\n if (payload === undefined || payload === null) {\n return \"{}\";\n }\n\n try {\n if (ArrayBuffer.isView(payload)) {\n return `{ type: \"binary\", length: ${payload.byteLength} }`;\n }\n } catch (exp) { }\n\n return payload;\n }\n\n preparePayload(payload: any) {\n var payloadText = this.cleanupPayload(payload);\n return this.prepareContent(payloadText);\n }\n\n start() {\n this.setStopped(false);\n this.interceptNetworkRequests({\n onFetch: (params: any, gleapRequestId: any) => {\n if (this.stopped) {\n return;\n }\n\n if (params.length >= 2) {\n var method = params[1].method ? params[1].method : 'GET';\n this.requests[gleapRequestId] = {\n request: {\n payload: this.preparePayload(params[1].body),\n headers: params[1].headers,\n },\n type: method,\n url: params[0],\n date: new Date(),\n };\n } else {\n this.requests[gleapRequestId] = {\n request: {},\n url: params[0],\n type: 'GET',\n date: new Date(),\n };\n }\n\n this.cleanRequests();\n },\n onFetchLoad: (req: any, gleapRequestId: any) => {\n if (\n this.stopped ||\n !gleapRequestId ||\n !this.requests ||\n !this.requests[gleapRequestId]\n ) {\n return;\n }\n\n try {\n this.requests[gleapRequestId].success = true;\n this.requests[gleapRequestId].response = {\n status: req.status,\n statusText: '',\n responseText: '<request_still_open>',\n };\n this.calcRequestTime(gleapRequestId);\n } catch (exp) {}\n\n req\n .text()\n .then((responseText: any) => {\n if (this.requests && this.requests[gleapRequestId]) {\n this.requests[gleapRequestId].success = true;\n this.requests[gleapRequestId].response = {\n status: req.status,\n statusText: req.statusText,\n responseText: this.prepareContent(responseText),\n };\n\n this.calcRequestTime(gleapRequestId);\n this.cleanRequests();\n }\n })\n .catch((_err: any) => {\n if (this) {\n this.cleanRequests();\n }\n });\n },\n onFetchFailed: (_err: any, gleapRequestId: any) => {\n if (this.stopped) {\n return;\n }\n\n this.requests[gleapRequestId].success = false;\n this.calcRequestTime(gleapRequestId);\n this.cleanRequests();\n },\n onOpen: (request: any, args: string | any[]) => {\n if (this.stopped) {\n return;\n }\n\n if (\n request &&\n request.gleapRequestId &&\n args.length >= 2 &&\n this.requests\n ) {\n this.requests[request.gleapRequestId] = {\n type: args[0],\n url: args[1],\n date: new Date(),\n };\n }\n\n this.cleanRequests();\n },\n onSend: (request: any, args: string | any[]) => {\n if (this.stopped) {\n return;\n }\n\n if (\n request &&\n request.gleapRequestId &&\n this.requests &&\n this.requests[request.gleapRequestId]\n ) {\n this.requests[request.gleapRequestId].request = {\n payload: this.preparePayload(args.length > 0 ? args[0] : ''),\n headers: request.requestHeaders,\n };\n }\n\n this.cleanRequests();\n },\n onError: (request: any) => {\n if (\n !this.stopped &&\n this.requests &&\n request &&\n request.gleapRequestId &&\n this.requests[request.gleapRequestId]\n ) {\n this.requests[request.gleapRequestId].success = false;\n this.calcRequestTime(request.gleapRequestId);\n }\n\n this.cleanRequests();\n },\n onLoad: (request: any) => {\n if (this.stopped) {\n return;\n }\n\n if (\n request &&\n request.gleapRequestId &&\n this.requests &&\n this.requests[request.gleapRequestId]\n ) {\n const contentType = request.getResponseHeader('content-type');\n const isTextOrJSON =\n contentType &&\n (contentType.includes('json') || contentType.includes('text'));\n\n var responseText = '<' + contentType + '>';\n if (request.responseType === '' || request.responseType === 'text') {\n responseText = request.responseText;\n }\n if (request._response && isTextOrJSON) {\n responseText = request._response;\n }\n\n this.requests[request.gleapRequestId].success = true;\n this.requests[request.gleapRequestId].response = {\n status: request.status,\n responseText: this.prepareContent(responseText),\n };\n\n this.calcRequestTime(request.gleapRequestId);\n }\n\n this.cleanRequests();\n },\n });\n }\n\n interceptNetworkRequests(callback: any) {\n // eslint-disable-next-line consistent-this\n var self = this;\n\n // @ts-ignore\n if (XMLHttpRequest.prototype['gleapTouched']) {\n return;\n }\n\n // @ts-ignore\n XMLHttpRequest.prototype['gleapTouched'] = true;\n\n // XMLHttpRequest\n const open = XMLHttpRequest.prototype.open;\n const send = XMLHttpRequest.prototype.send;\n\n // @ts-ignore\n XMLHttpRequest.prototype.wrappedSetRequestHeader =\n XMLHttpRequest.prototype.setRequestHeader;\n XMLHttpRequest.prototype.setRequestHeader = function (header, value) {\n // @ts-ignore\n if (!this.requestHeaders) {\n // @ts-ignore\n this.requestHeaders = {};\n }\n\n // @ts-ignore\n if (this.requestHeaders && this.requestHeaders.hasOwnProperty(header)) {\n return;\n }\n\n // @ts-ignore\n if (!this.requestHeaders[header]) {\n // @ts-ignore\n this.requestHeaders[header] = [];\n }\n\n // @ts-ignore\n this.requestHeaders[header].push(value);\n // @ts-ignore\n this.wrappedSetRequestHeader(header, value);\n };\n\n XMLHttpRequest.prototype.open = function () {\n (this as any).gleapRequestId = ++self.requestId;\n callback.onOpen && callback.onOpen(this, arguments);\n\n if (callback.onLoad) {\n this.addEventListener('load', function () {\n // @ts-ignore\n callback.onLoad(this);\n });\n }\n if (callback.onError) {\n this.addEventListener('error', function () {\n // @ts-ignore\n callback.onError(this);\n });\n }\n\n // @ts-ignore\n return open.apply(this, arguments);\n };\n\n XMLHttpRequest.prototype.send = function () {\n callback.onSend && callback.onSend(this, arguments);\n // @ts-ignore\n return send.apply(this, arguments);\n };\n\n // Fetch\n if (global) {\n (function () {\n var originalFetch = global.fetch;\n global.fetch = function () {\n var gleapRequestId = ++self.requestId;\n callback.onFetch(arguments, gleapRequestId);\n\n return (\n originalFetch\n // @ts-ignore\n .apply(this, arguments)\n .then(function (response) {\n if (response && typeof response.clone === 'function') {\n const data = response.clone();\n callback.onFetchLoad(data, gleapRequestId);\n }\n\n return response;\n })\n .catch((err) => {\n callback.onFetchFailed(err, gleapRequestId);\n throw err;\n })\n );\n };\n })();\n }\n\n return callback;\n }\n}\n\nexport default GleapNetworkIntercepter;\n"]}
@@ -5,30 +5,48 @@ export declare type GleapUserProperty = {
5
5
  declare type GleapActivationMethod = 'SHAKE' | 'SCREENSHOT';
6
6
  declare type GleapSdkType = {
7
7
  initialize(token: string): void;
8
+ startFeedbackFlow(feedbackFlow: string, showBackButton: boolean): void;
9
+ sendSilentCrashReport(description: string, severity: 'LOW' | 'MEDIUM' | 'HIGH'): void;
10
+ sendSilentCrashReportWithExcludeData(description: string, severity: 'LOW' | 'MEDIUM' | 'HIGH', excludeData: {
11
+ customData?: Boolean;
12
+ metaData?: Boolean;
13
+ attachments?: Boolean;
14
+ consoleLog?: Boolean;
15
+ networkLogs?: Boolean;
16
+ customEventLog?: Boolean;
17
+ screenshot?: Boolean;
18
+ replays?: Boolean;
19
+ }): void;
8
20
  open(): void;
9
- startFeedbackFlow(feedbackFlow: string): void;
10
- sendSilentBugReport(description: string, severity: 'LOW' | 'MEDIUM' | 'HIGH'): void;
11
- sendSilentBugReportWithType(description: string, severity: 'LOW' | 'MEDIUM' | 'HIGH', type: string): void;
21
+ close(): void;
22
+ isOpened(): boolean;
12
23
  identify(userId: string, userProperties: GleapUserProperty): void;
24
+ identifyWithUserHash(userId: string, userProperties: GleapUserProperty, userHash: string): void;
13
25
  clearIdentity(): void;
26
+ preFillForm(formData: {
27
+ [key: string]: string;
28
+ }): void;
14
29
  setApiUrl(apiUrl: string): void;
15
- setWidgetUrl(widgetUrl: string): void;
30
+ setFrameUrl(frameUrl: string): void;
16
31
  attachCustomData(customData: any): void;
17
32
  setCustomData(key: string, value: string): void;
18
33
  removeCustomDataForKey(key: string): void;
19
34
  clearCustomData(): void;
20
- registerCustomAction(customActionCallback: (data: {
21
- name: string;
22
- }) => void): void;
23
35
  registerListener(eventType: string, callback: (data?: any) => void): void;
24
36
  setLanguage(language: string): void;
37
+ enableDebugConsoleLog(): void;
38
+ disableConsoleLog(): void;
39
+ log(message: string): void;
40
+ logWithLogLevel(message: string, logLevel: 'INFO' | 'WARNING' | 'ERROR'): void;
25
41
  logEvent(name: string, data: any): void;
26
42
  addAttachment(base64file: string, fileName: string): void;
27
43
  removeAllAttachments(): void;
28
44
  startNetworkLogging(): void;
29
45
  stopNetworkLogging(): void;
30
- enableDebugConsoleLog(): void;
31
46
  setActivationMethods(activationMethods: GleapActivationMethod[]): void;
47
+ registerCustomAction(customActionCallback: (data: {
48
+ name: string;
49
+ }) => void): void;
32
50
  };
33
51
  declare const _default: GleapSdkType;
34
52
  export default _default;
@@ -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.2",
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.3"
20
20
  end
package/src/index.tsx CHANGED
@@ -16,54 +16,93 @@ 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;
57
+ enableDebugConsoleLog(): void;
58
+ disableConsoleLog(): void;
59
+ log(message: string): void;
60
+ logWithLogLevel(message: string, logLevel: 'INFO' | 'WARNING' | 'ERROR'): void;
43
61
  logEvent(name: string, data: any): void;
44
62
  addAttachment(base64file: string, fileName: string): void;
45
63
  removeAllAttachments(): void;
46
64
  startNetworkLogging(): void;
47
65
  stopNetworkLogging(): void;
48
- enableDebugConsoleLog(): void;
49
66
  setActivationMethods(activationMethods: GleapActivationMethod[]): void;
67
+ registerCustomAction(
68
+ customActionCallback: (data: { name: string }) => void
69
+ ): void;
50
70
  };
51
71
 
52
72
  const GleapSdk = NativeModules.Gleapsdk
53
73
  ? NativeModules.Gleapsdk
54
74
  : new Proxy(
55
- {},
56
- {
57
- get() {
58
- throw new Error(LINKING_ERROR);
59
- },
60
- }
61
- );
75
+ {},
76
+ {
77
+ get() {
78
+ throw new Error(LINKING_ERROR);
79
+ },
80
+ }
81
+ );
62
82
 
63
83
  if (GleapSdk && !GleapSdk.touched) {
64
84
  const networkLogger = new GleapNetworkIntercepter();
65
85
 
86
+ // Push the network log to the native SDK.
66
87
  GleapSdk.startNetworkLogging = () => {
88
+ // Set the callback.
89
+ networkLogger.setUpdatedCallback(() => {
90
+ if (!networkLogger) {
91
+ return;
92
+ }
93
+
94
+ const requests = networkLogger.getRequests();
95
+
96
+ if (requests && GleapSdk && typeof GleapSdk.attachNetworkLog !== 'undefined') {
97
+ if (Platform.OS === 'android') {
98
+ GleapSdk.attachNetworkLog(JSON.stringify(requests));
99
+ } else {
100
+ GleapSdk.attachNetworkLog(JSON.parse(JSON.stringify(requests)));
101
+ }
102
+ }
103
+ });
104
+
105
+ // Start the logger.
67
106
  networkLogger.start();
68
107
  };
69
108
 
@@ -103,32 +142,32 @@ if (GleapSdk && !GleapSdk.touched) {
103
142
  GleapSdk.startNetworkLogging();
104
143
  }
105
144
  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');
145
+ } catch (exp) { }
119
146
  });
120
147
 
121
148
  gleapEmitter.addListener('feedbackSent', (data) => {
122
149
  try {
123
150
  const dataJSON = data instanceof Object ? data : JSON.parse(data);
124
151
  notifyCallback('feedbackSent', dataJSON);
125
- } catch (exp) {}
152
+ } catch (exp) { }
153
+ });
154
+
155
+ gleapEmitter.addListener('feedbackFlowStarted', (feedbackAction) => {
156
+ notifyCallback('feedbackFlowStarted', feedbackAction);
126
157
  });
127
158
 
128
159
  gleapEmitter.addListener('feedbackSendingFailed', () => {
129
160
  notifyCallback('feedbackSendingFailed');
130
161
  });
131
162
 
163
+ gleapEmitter.addListener('widgetOpened', () => {
164
+ notifyCallback('widgetOpened');
165
+ });
166
+
167
+ gleapEmitter.addListener('widgetClosed', () => {
168
+ notifyCallback('widgetClosed');
169
+ });
170
+
132
171
  function isJsonString(str: string) {
133
172
  try {
134
173
  JSON.parse(str);
@@ -149,11 +188,10 @@ if (GleapSdk && !GleapSdk.touched) {
149
188
  name,
150
189
  });
151
190
  }
152
- } catch (exp) {}
191
+ } catch (exp) { }
153
192
  });
154
193
 
155
194
  GleapSdk.removeAllAttachments();
156
-
157
195
  GleapSdk.touched = true;
158
196
  }
159
197
 
@@ -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);