react-native-gleapsdk 6.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.
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+
10
+ class BugBattleNetworkIntercepter {
11
+ constructor() {
12
+ _defineProperty(this, "requestId", 0);
13
+
14
+ _defineProperty(this, "requests", {});
15
+
16
+ _defineProperty(this, "maxRequests", 10);
17
+
18
+ _defineProperty(this, "stopped", false);
19
+ }
20
+
21
+ getRequests() {
22
+ return Object.values(this.requests);
23
+ }
24
+
25
+ setMaxRequests(maxRequests) {
26
+ this.maxRequests = maxRequests;
27
+ }
28
+
29
+ setStopped(stopped) {
30
+ this.stopped = stopped;
31
+ }
32
+
33
+ cleanRequests() {
34
+ var keys = Object.keys(this.requests);
35
+
36
+ if (keys.length > this.maxRequests) {
37
+ var keysToRemove = keys.slice(0, keys.length - this.maxRequests);
38
+
39
+ for (var i = 0; i < keysToRemove.length; i++) {
40
+ delete this.requests[keysToRemove[i]];
41
+ }
42
+ }
43
+ }
44
+
45
+ calcRequestTime(gleapRequestId) {
46
+ if (!this.requests[gleapRequestId]) {
47
+ return;
48
+ }
49
+
50
+ var startDate = this.requests[gleapRequestId].date;
51
+
52
+ if (startDate) {
53
+ this.requests[gleapRequestId].duration = new Date().getTime() - startDate.getTime();
54
+ this.requests[gleapRequestId].date = this.requests[gleapRequestId].date.toString();
55
+ }
56
+ }
57
+
58
+ start() {
59
+ this.setStopped(false);
60
+ this.interceptNetworkRequests({
61
+ onFetch: (params, gleapRequestId) => {
62
+ if (this.stopped) {
63
+ return;
64
+ }
65
+
66
+ if (params.length >= 2) {
67
+ var method = params[1].method ? params[1].method : 'GET';
68
+ this.requests[gleapRequestId] = {
69
+ request: {
70
+ payload: params[1].body,
71
+ headers: params[1].headers
72
+ },
73
+ type: method,
74
+ url: params[0],
75
+ date: new Date()
76
+ };
77
+ } else {
78
+ this.requests[gleapRequestId] = {
79
+ request: {},
80
+ url: params[0],
81
+ type: 'GET',
82
+ date: new Date()
83
+ };
84
+ }
85
+
86
+ this.cleanRequests();
87
+ },
88
+ onFetchLoad: (req, gleapRequestId) => {
89
+ if (this.stopped) {
90
+ return;
91
+ }
92
+
93
+ req.text().then(responseText => {
94
+ this.requests[gleapRequestId].success = true;
95
+ this.requests[gleapRequestId].response = {
96
+ status: req.status,
97
+ statusText: req.statusText,
98
+ responseText: responseText
99
+ };
100
+ this.calcRequestTime(gleapRequestId);
101
+ this.cleanRequests();
102
+ });
103
+ },
104
+ onFetchFailed: (_err, gleapRequestId) => {
105
+ if (this.stopped) {
106
+ return;
107
+ }
108
+
109
+ this.requests[gleapRequestId].success = false;
110
+ this.calcRequestTime(gleapRequestId);
111
+ this.cleanRequests();
112
+ },
113
+ onOpen: (request, args) => {
114
+ if (this.stopped) {
115
+ return;
116
+ }
117
+
118
+ if (request && request.gleapRequestId && args.length >= 2 && this.requests) {
119
+ this.requests[request.gleapRequestId] = {
120
+ type: args[0],
121
+ url: args[1],
122
+ date: new Date()
123
+ };
124
+ }
125
+
126
+ this.cleanRequests();
127
+ },
128
+ onSend: (request, args) => {
129
+ if (this.stopped) {
130
+ return;
131
+ }
132
+
133
+ if (request && request.gleapRequestId && args.length > 0 && this.requests && this.requests[request.gleapRequestId]) {
134
+ this.requests[request.gleapRequestId].request = {
135
+ payload: args[0],
136
+ headers: request.requestHeaders
137
+ };
138
+ }
139
+
140
+ this.cleanRequests();
141
+ },
142
+ onError: request => {
143
+ if (!this.stopped && this.requests && request && request.gleapRequestId && this.requests[request.gleapRequestId]) {
144
+ this.requests[request.gleapRequestId].success = false;
145
+ this.calcRequestTime(request.gleapRequestId);
146
+ }
147
+
148
+ this.cleanRequests();
149
+ },
150
+ onLoad: request => {
151
+ if (this.stopped) {
152
+ return;
153
+ }
154
+
155
+ if (request && request.gleapRequestId && this.requests && this.requests[request.gleapRequestId]) {
156
+ const contentType = request.getResponseHeader('content-type');
157
+ const isTextOrJSON = contentType && (contentType.includes('json') || contentType.includes('text'));
158
+ var responseText = '<' + contentType + '>';
159
+
160
+ if (request.responseType === '' || request.responseType === 'text') {
161
+ responseText = request.responseText;
162
+ }
163
+
164
+ if (request._response && isTextOrJSON) {
165
+ responseText = request._response;
166
+ }
167
+
168
+ this.requests[request.gleapRequestId].success = true;
169
+ this.requests[request.gleapRequestId].response = {
170
+ status: request.status,
171
+ responseText: responseText
172
+ };
173
+ this.calcRequestTime(request.gleapRequestId);
174
+ }
175
+
176
+ this.cleanRequests();
177
+ }
178
+ });
179
+ }
180
+
181
+ interceptNetworkRequests(callback) {
182
+ // eslint-disable-next-line consistent-this
183
+ var self = this; // XMLHttpRequest
184
+
185
+ const open = XMLHttpRequest.prototype.open;
186
+ const send = XMLHttpRequest.prototype.send; // @ts-ignore
187
+
188
+ XMLHttpRequest.prototype.wrappedSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
189
+
190
+ XMLHttpRequest.prototype.setRequestHeader = function (header, value) {
191
+ // @ts-ignore
192
+ this.wrappedSetRequestHeader(header, value); // @ts-ignore
193
+
194
+ if (!this.requestHeaders) {
195
+ // @ts-ignore
196
+ this.requestHeaders = {};
197
+ } // @ts-ignore
198
+
199
+
200
+ if (!this.requestHeaders[header]) {
201
+ // @ts-ignore
202
+ this.requestHeaders[header] = [];
203
+ } // @ts-ignore
204
+
205
+
206
+ this.requestHeaders[header].push(value);
207
+ };
208
+
209
+ XMLHttpRequest.prototype.open = function () {
210
+ this.gleapRequestId = ++self.requestId;
211
+ callback.onOpen && callback.onOpen(this, arguments);
212
+
213
+ if (callback.onLoad) {
214
+ this.addEventListener('load', function () {
215
+ // @ts-ignore
216
+ callback.onLoad(this);
217
+ });
218
+ }
219
+
220
+ if (callback.onError) {
221
+ this.addEventListener('error', function () {
222
+ // @ts-ignore
223
+ callback.onError(this);
224
+ });
225
+ } // @ts-ignore
226
+
227
+
228
+ return open.apply(this, arguments);
229
+ };
230
+
231
+ XMLHttpRequest.prototype.send = function () {
232
+ callback.onSend && callback.onSend(this, arguments); // @ts-ignore
233
+
234
+ return send.apply(this, arguments);
235
+ }; // Fetch
236
+
237
+
238
+ if (global) {
239
+ (function () {
240
+ var originalFetch = global.fetch;
241
+
242
+ global.fetch = function () {
243
+ var gleapRequestId = ++self.requestId;
244
+ callback.onFetch(arguments, gleapRequestId);
245
+ return originalFetch // @ts-ignore
246
+ .apply(this, arguments).then(function (data) {
247
+ return data.text().then(textData => {
248
+ data.text = function () {
249
+ return Promise.resolve(textData);
250
+ };
251
+
252
+ data.json = function () {
253
+ return Promise.resolve(JSON.parse(textData));
254
+ };
255
+
256
+ callback.onFetchLoad(data, gleapRequestId);
257
+ return data;
258
+ });
259
+ }).catch(err => {
260
+ callback.onFetchFailed(err, gleapRequestId);
261
+ throw err;
262
+ });
263
+ };
264
+ })();
265
+ }
266
+
267
+ return callback;
268
+ }
269
+
270
+ }
271
+
272
+ var _default = BugBattleNetworkIntercepter;
273
+ exports.default = _default;
274
+ //# sourceMappingURL=networklogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["networklogger.ts"],"names":["BugBattleNetworkIntercepter","getRequests","Object","values","requests","setMaxRequests","maxRequests","setStopped","stopped","cleanRequests","keys","length","keysToRemove","slice","i","calcRequestTime","gleapRequestId","startDate","date","duration","Date","getTime","toString","start","interceptNetworkRequests","onFetch","params","method","request","payload","body","headers","type","url","onFetchLoad","req","text","then","responseText","success","response","status","statusText","onFetchFailed","_err","onOpen","args","onSend","requestHeaders","onError","onLoad","contentType","getResponseHeader","isTextOrJSON","includes","responseType","_response","callback","self","open","XMLHttpRequest","prototype","send","wrappedSetRequestHeader","setRequestHeader","header","value","push","requestId","arguments","addEventListener","apply","global","originalFetch","fetch","data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Q,CAAChC,OAAT,CAAiB4C,SAAjB,EAA4BrD,cAA5B;AAEA,iBACEyD,aAAa,CACX;AADW,WAEVF,KAFH,CAES,IAFT,EAEeF,SAFf,EAGGhC,IAHH,CAGQ,UAAUsC,IAAV,EAAgB;AACpB,mBAAOA,IAAI,CAACvC,IAAL,GAAYC,IAAZ,CAAkBuC,QAAD,IAAc;AACpCD,cAAAA,IAAI,CAACvC,IAAL,GAAY,YAAY;AACtB,uBAAOyC,OAAO,CAACC,OAAR,CAAgBF,QAAhB,CAAP;AACD,eAFD;;AAIAD,cAAAA,IAAI,CAACI,IAAL,GAAY,YAAY;AACtB,uBAAOF,OAAO,CAACC,OAAR,CAAgBE,IAAI,CAACC,KAAL,CAAWL,QAAX,CAAhB,CAAP;AACD,eAFD;;AAIAnB,cAAAA,QAAQ,CAACvB,WAAT,CAAqByC,IAArB,EAA2B3D,cAA3B;AAEA,qBAAO2D,IAAP;AACD,aAZM,CAAP;AAaD,WAjBH,EAkBGO,KAlBH,CAkBUC,GAAD,IAAS;AACd1B,YAAAA,QAAQ,CAACd,aAAT,CAAuBwC,GAAvB,EAA4BnE,cAA5B;AACA,kBAAMmE,GAAN;AACD,WArBH,CADF;AAwBD,SA5BD;AA6BD,OA/BD;AAgCD;;AAED,WAAO1B,QAAP;AACD;;AAhS+B;;eAmSnBzD,2B","sourcesContent":["class BugBattleNetworkIntercepter {\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 (startDate) {\n this.requests[gleapRequestId].duration =\n new Date().getTime() - startDate.getTime();\n this.requests[gleapRequestId].date = this.requests[\n gleapRequestId\n ].date.toString();\n }\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 (this.stopped) {\n return;\n }\n\n req.text().then((responseText: any) => {\n this.requests[gleapRequestId].success = true;\n this.requests[gleapRequestId].response = {\n status: req.status,\n statusText: req.statusText,\n responseText: responseText,\n };\n\n this.calcRequestTime(gleapRequestId);\n\n this.cleanRequests();\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\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 args.length > 0 &&\n this.requests &&\n this.requests[request.gleapRequestId]\n ) {\n this.requests[request.gleapRequestId].request = {\n payload: 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: 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 // 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 this.wrappedSetRequestHeader(header, value);\n\n // @ts-ignore\n if (!this.requestHeaders) {\n // @ts-ignore\n this.requestHeaders = {};\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 };\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 (data) {\n return data.text().then((textData) => {\n data.text = function () {\n return Promise.resolve(textData);\n };\n\n data.json = function () {\n return Promise.resolve(JSON.parse(textData));\n };\n\n callback.onFetchLoad(data, gleapRequestId);\n\n return data;\n });\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 BugBattleNetworkIntercepter;\n"]}
@@ -0,0 +1,84 @@
1
+ import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
2
+ import GleapNetworkIntercepter from './networklogger';
3
+ const LINKING_ERROR = `The package 'react-native-gleapsdk' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
4
+ ios: "- You have run 'pod install'\n",
5
+ default: ''
6
+ }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo managed workflow\n';
7
+ const GleapSdk = NativeModules.Gleapsdk ? NativeModules.Gleapsdk : new Proxy({}, {
8
+ get() {
9
+ throw new Error(LINKING_ERROR);
10
+ }
11
+
12
+ });
13
+ const networkLogger = new GleapNetworkIntercepter();
14
+
15
+ GleapSdk.startNetworkLogging = () => {
16
+ networkLogger.start();
17
+ };
18
+
19
+ GleapSdk.stopNetworkLogging = () => {
20
+ networkLogger.setStopped(true);
21
+ };
22
+
23
+ if (GleapSdk) {
24
+ var callbacks = [];
25
+
26
+ GleapSdk.registerCustomAction = customActionCallback => {
27
+ callbacks.push(customActionCallback);
28
+ };
29
+
30
+ const gleapEmitter = new NativeEventEmitter(GleapSdk);
31
+ gleapEmitter.addListener('configLoaded', config => {
32
+ try {
33
+ const configJSON = JSON.parse(config);
34
+
35
+ if (configJSON.enableNetworkLogs) {
36
+ GleapSdk.startNetworkLogging();
37
+ }
38
+ } catch (exp) {}
39
+ });
40
+ gleapEmitter.addListener('feedbackWillBeSent', () => {
41
+ // Push the network log to the native SDK.
42
+ const requests = networkLogger.getRequests();
43
+
44
+ if (Platform.OS === 'android') {
45
+ GleapSdk.attachNetworkLog(JSON.stringify(requests));
46
+ } else {
47
+ GleapSdk.attachNetworkLog(requests);
48
+ }
49
+ });
50
+ gleapEmitter.addListener('customActionTriggered', data => {
51
+ try {
52
+ if (isJsonString(data)) {
53
+ data = JSON.parse(data);
54
+ }
55
+
56
+ const {
57
+ name
58
+ } = data;
59
+
60
+ if (name && callbacks.length > 0) {
61
+ for (var i = 0; i < callbacks.length; i++) {
62
+ if (callbacks[i]) {
63
+ callbacks[i]({
64
+ name
65
+ });
66
+ }
67
+ }
68
+ }
69
+ } catch (exp) {}
70
+ });
71
+ }
72
+
73
+ function isJsonString(str) {
74
+ try {
75
+ JSON.parse(str);
76
+ } catch (e) {
77
+ return false;
78
+ }
79
+
80
+ return true;
81
+ }
82
+
83
+ export default GleapSdk;
84
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.tsx"],"names":["NativeModules","NativeEventEmitter","Platform","GleapNetworkIntercepter","LINKING_ERROR","select","ios","default","GleapSdk","Gleapsdk","Proxy","get","Error","networkLogger","startNetworkLogging","start","stopNetworkLogging","setStopped","callbacks","registerCustomAction","customActionCallback","push","gleapEmitter","addListener","config","configJSON","JSON","parse","enableNetworkLogs","exp","requests","getRequests","OS","attachNetworkLog","stringify","data","isJsonString","name","length","i","str","e"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,kBAAxB,EAA4CC,QAA5C,QAA4D,cAA5D;AACA,OAAOC,uBAAP,MAAoC,iBAApC;AAEA,MAAMC,aAAa,GAChB,gFAAD,GACAF,QAAQ,CAACG,MAAT,CAAgB;AAAEC,EAAAA,GAAG,EA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AA,QAAQ,CAACyB,gBAAT,CAA0BP,IAAI,CAACQ,SAAL,CAAeJ,QAAf,CAA1B;AACD,KAFD,MAEO;AACLtB,MAAAA,QAAQ,CAACyB,gBAAT,CAA0BH,QAA1B;AACD;AACF,GARD;AAUAR,EAAAA,YAAY,CAACC,WAAb,CAAyB,uBAAzB,EAAmDY,IAAD,IAAe;AAC/D,QAAI;AACF,UAAIC,YAAY,CAACD,IAAD,CAAhB,EAAwB;AACtBA,QAAAA,IAAI,GAAGT,IAAI,CAACC,KAAL,CAAWQ,IAAX,CAAP;AACD;;AACD,YAAM;AAAEE,QAAAA;AAAF,UAAWF,IAAjB;;AACA,UAAIE,IAAI,IAAInB,SAAS,CAACoB,MAAV,GAAmB,CAA/B,EAAkC;AAChC,aAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGrB,SAAS,CAACoB,MAA9B,EAAsCC,CAAC,EAAvC,EAA2C;AACzC,cAAIrB,SAAS,CAACqB,CAAD,CAAb,EAAkB;AAChBrB,YAAAA,SAAS,CAACqB,CAAD,CAAT,CAAa;AACXF,cAAAA;AADW,aAAb;AAGD;AACF;AACF;AACF,KAdD,CAcE,OAAOR,GAAP,EAAY,CAAE;AACjB,GAhBD;AAiBD;;AAED,SAASO,YAAT,CAAsBI,GAAtB,EAAmC;AACjC,MAAI;AACFd,IAAAA,IAAI,CAACC,KAAL,CAAWa,GAAX;AACD,GAFD,CAEE,OAAOC,CAAP,EAAU;AACV,WAAO,KAAP;AACD;;AACD,SAAO,IAAP;AACD;;AAED,eAAejC,QAAf","sourcesContent":["import { NativeModules, NativeEventEmitter, Platform } from 'react-native';\nimport GleapNetworkIntercepter from './networklogger';\n\nconst LINKING_ERROR =\n `The package 'react-native-gleapsdk' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nexport type GleapUserProperty = {\n email?: string;\n name?: string;\n};\n\ntype GleapSdkType = {\n initialize(token: string): void;\n startFeedbackFlow(): void;\n sendSilentBugReport(\n description: string,\n severity: 'LOW' | 'MEDIUM' | 'HIGH'\n ): void;\n identify(userId: string, userProperties: GleapUserProperty): void;\n clearIdentity(): void;\n setApiUrl(apiUrl: string): void;\n setWidgetUrl(widgetUrl: string): void;\n attachCustomData(customData: any): void;\n setCustomData(key: string, value: string): void;\n removeCustomDataForKey(key: string): void;\n clearCustomData(): void;\n registerCustomAction(\n customActionCallback: (data: { name: string }) => void\n ): void;\n setLanguage(language: string): void;\n logEvent(name: string, data: any): void;\n addAttachment(base64file: string, fileName: string): void;\n removeAllAttachments(): void;\n startNetworkLogging(): void;\n stopNetworkLogging(): void;\n};\n\nconst GleapSdk = NativeModules.Gleapsdk\n ? NativeModules.Gleapsdk\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\nconst networkLogger = new GleapNetworkIntercepter();\n\nGleapSdk.startNetworkLogging = () => {\n networkLogger.start();\n};\n\nGleapSdk.stopNetworkLogging = () => {\n networkLogger.setStopped(true);\n};\n\nif (GleapSdk) {\n var callbacks: any[] = [];\n\n GleapSdk.registerCustomAction = (customActionCallback: any) => {\n callbacks.push(customActionCallback);\n };\n\n const gleapEmitter = new NativeEventEmitter(GleapSdk);\n gleapEmitter.addListener('configLoaded', (config: any) => {\n try {\n const configJSON = JSON.parse(config);\n if (configJSON.enableNetworkLogs) {\n GleapSdk.startNetworkLogging();\n }\n } catch (exp) {}\n });\n gleapEmitter.addListener('feedbackWillBeSent', () => {\n // Push the network log to the native SDK.\n const requests = networkLogger.getRequests();\n if (Platform.OS === 'android') {\n GleapSdk.attachNetworkLog(JSON.stringify(requests));\n } else {\n GleapSdk.attachNetworkLog(requests);\n }\n });\n\n gleapEmitter.addListener('customActionTriggered', (data: any) => {\n try {\n if (isJsonString(data)) {\n data = JSON.parse(data);\n }\n const { name } = data;\n if (name && callbacks.length > 0) {\n for (var i = 0; i < callbacks.length; i++) {\n if (callbacks[i]) {\n callbacks[i]({\n name,\n });\n }\n }\n }\n } catch (exp) {}\n });\n}\n\nfunction isJsonString(str: string) {\n try {\n JSON.parse(str);\n } catch (e) {\n return false;\n }\n return true;\n}\n\nexport default GleapSdk as GleapSdkType;\n"]}
@@ -0,0 +1,266 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ class BugBattleNetworkIntercepter {
4
+ constructor() {
5
+ _defineProperty(this, "requestId", 0);
6
+
7
+ _defineProperty(this, "requests", {});
8
+
9
+ _defineProperty(this, "maxRequests", 10);
10
+
11
+ _defineProperty(this, "stopped", false);
12
+ }
13
+
14
+ getRequests() {
15
+ return Object.values(this.requests);
16
+ }
17
+
18
+ setMaxRequests(maxRequests) {
19
+ this.maxRequests = maxRequests;
20
+ }
21
+
22
+ setStopped(stopped) {
23
+ this.stopped = stopped;
24
+ }
25
+
26
+ cleanRequests() {
27
+ var keys = Object.keys(this.requests);
28
+
29
+ if (keys.length > this.maxRequests) {
30
+ var keysToRemove = keys.slice(0, keys.length - this.maxRequests);
31
+
32
+ for (var i = 0; i < keysToRemove.length; i++) {
33
+ delete this.requests[keysToRemove[i]];
34
+ }
35
+ }
36
+ }
37
+
38
+ calcRequestTime(gleapRequestId) {
39
+ if (!this.requests[gleapRequestId]) {
40
+ return;
41
+ }
42
+
43
+ var startDate = this.requests[gleapRequestId].date;
44
+
45
+ if (startDate) {
46
+ this.requests[gleapRequestId].duration = new Date().getTime() - startDate.getTime();
47
+ this.requests[gleapRequestId].date = this.requests[gleapRequestId].date.toString();
48
+ }
49
+ }
50
+
51
+ start() {
52
+ this.setStopped(false);
53
+ this.interceptNetworkRequests({
54
+ onFetch: (params, gleapRequestId) => {
55
+ if (this.stopped) {
56
+ return;
57
+ }
58
+
59
+ if (params.length >= 2) {
60
+ var method = params[1].method ? params[1].method : 'GET';
61
+ this.requests[gleapRequestId] = {
62
+ request: {
63
+ payload: params[1].body,
64
+ headers: params[1].headers
65
+ },
66
+ type: method,
67
+ url: params[0],
68
+ date: new Date()
69
+ };
70
+ } else {
71
+ this.requests[gleapRequestId] = {
72
+ request: {},
73
+ url: params[0],
74
+ type: 'GET',
75
+ date: new Date()
76
+ };
77
+ }
78
+
79
+ this.cleanRequests();
80
+ },
81
+ onFetchLoad: (req, gleapRequestId) => {
82
+ if (this.stopped) {
83
+ return;
84
+ }
85
+
86
+ req.text().then(responseText => {
87
+ this.requests[gleapRequestId].success = true;
88
+ this.requests[gleapRequestId].response = {
89
+ status: req.status,
90
+ statusText: req.statusText,
91
+ responseText: responseText
92
+ };
93
+ this.calcRequestTime(gleapRequestId);
94
+ this.cleanRequests();
95
+ });
96
+ },
97
+ onFetchFailed: (_err, gleapRequestId) => {
98
+ if (this.stopped) {
99
+ return;
100
+ }
101
+
102
+ this.requests[gleapRequestId].success = false;
103
+ this.calcRequestTime(gleapRequestId);
104
+ this.cleanRequests();
105
+ },
106
+ onOpen: (request, args) => {
107
+ if (this.stopped) {
108
+ return;
109
+ }
110
+
111
+ if (request && request.gleapRequestId && args.length >= 2 && this.requests) {
112
+ this.requests[request.gleapRequestId] = {
113
+ type: args[0],
114
+ url: args[1],
115
+ date: new Date()
116
+ };
117
+ }
118
+
119
+ this.cleanRequests();
120
+ },
121
+ onSend: (request, args) => {
122
+ if (this.stopped) {
123
+ return;
124
+ }
125
+
126
+ if (request && request.gleapRequestId && args.length > 0 && this.requests && this.requests[request.gleapRequestId]) {
127
+ this.requests[request.gleapRequestId].request = {
128
+ payload: args[0],
129
+ headers: request.requestHeaders
130
+ };
131
+ }
132
+
133
+ this.cleanRequests();
134
+ },
135
+ onError: request => {
136
+ if (!this.stopped && this.requests && request && request.gleapRequestId && this.requests[request.gleapRequestId]) {
137
+ this.requests[request.gleapRequestId].success = false;
138
+ this.calcRequestTime(request.gleapRequestId);
139
+ }
140
+
141
+ this.cleanRequests();
142
+ },
143
+ onLoad: request => {
144
+ if (this.stopped) {
145
+ return;
146
+ }
147
+
148
+ if (request && request.gleapRequestId && this.requests && this.requests[request.gleapRequestId]) {
149
+ const contentType = request.getResponseHeader('content-type');
150
+ const isTextOrJSON = contentType && (contentType.includes('json') || contentType.includes('text'));
151
+ var responseText = '<' + contentType + '>';
152
+
153
+ if (request.responseType === '' || request.responseType === 'text') {
154
+ responseText = request.responseText;
155
+ }
156
+
157
+ if (request._response && isTextOrJSON) {
158
+ responseText = request._response;
159
+ }
160
+
161
+ this.requests[request.gleapRequestId].success = true;
162
+ this.requests[request.gleapRequestId].response = {
163
+ status: request.status,
164
+ responseText: responseText
165
+ };
166
+ this.calcRequestTime(request.gleapRequestId);
167
+ }
168
+
169
+ this.cleanRequests();
170
+ }
171
+ });
172
+ }
173
+
174
+ interceptNetworkRequests(callback) {
175
+ // eslint-disable-next-line consistent-this
176
+ var self = this; // XMLHttpRequest
177
+
178
+ const open = XMLHttpRequest.prototype.open;
179
+ const send = XMLHttpRequest.prototype.send; // @ts-ignore
180
+
181
+ XMLHttpRequest.prototype.wrappedSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
182
+
183
+ XMLHttpRequest.prototype.setRequestHeader = function (header, value) {
184
+ // @ts-ignore
185
+ this.wrappedSetRequestHeader(header, value); // @ts-ignore
186
+
187
+ if (!this.requestHeaders) {
188
+ // @ts-ignore
189
+ this.requestHeaders = {};
190
+ } // @ts-ignore
191
+
192
+
193
+ if (!this.requestHeaders[header]) {
194
+ // @ts-ignore
195
+ this.requestHeaders[header] = [];
196
+ } // @ts-ignore
197
+
198
+
199
+ this.requestHeaders[header].push(value);
200
+ };
201
+
202
+ XMLHttpRequest.prototype.open = function () {
203
+ this.gleapRequestId = ++self.requestId;
204
+ callback.onOpen && callback.onOpen(this, arguments);
205
+
206
+ if (callback.onLoad) {
207
+ this.addEventListener('load', function () {
208
+ // @ts-ignore
209
+ callback.onLoad(this);
210
+ });
211
+ }
212
+
213
+ if (callback.onError) {
214
+ this.addEventListener('error', function () {
215
+ // @ts-ignore
216
+ callback.onError(this);
217
+ });
218
+ } // @ts-ignore
219
+
220
+
221
+ return open.apply(this, arguments);
222
+ };
223
+
224
+ XMLHttpRequest.prototype.send = function () {
225
+ callback.onSend && callback.onSend(this, arguments); // @ts-ignore
226
+
227
+ return send.apply(this, arguments);
228
+ }; // Fetch
229
+
230
+
231
+ if (global) {
232
+ (function () {
233
+ var originalFetch = global.fetch;
234
+
235
+ global.fetch = function () {
236
+ var gleapRequestId = ++self.requestId;
237
+ callback.onFetch(arguments, gleapRequestId);
238
+ return originalFetch // @ts-ignore
239
+ .apply(this, arguments).then(function (data) {
240
+ return data.text().then(textData => {
241
+ data.text = function () {
242
+ return Promise.resolve(textData);
243
+ };
244
+
245
+ data.json = function () {
246
+ return Promise.resolve(JSON.parse(textData));
247
+ };
248
+
249
+ callback.onFetchLoad(data, gleapRequestId);
250
+ return data;
251
+ });
252
+ }).catch(err => {
253
+ callback.onFetchFailed(err, gleapRequestId);
254
+ throw err;
255
+ });
256
+ };
257
+ })();
258
+ }
259
+
260
+ return callback;
261
+ }
262
+
263
+ }
264
+
265
+ export default BugBattleNetworkIntercepter;
266
+ //# sourceMappingURL=networklogger.js.map