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 @@
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","textData","Promise","resolve","json","JSON","parse","catch","err"],"mappings":";;AAAA,MAAMA,2BAAN,CAAkC;AAAA;AAAA,uCACpB,CADoB;;AAAA,sCAEhB,EAFgB;;AAAA,yCAGlB,EAHkB;;AAAA,qCAItB,KAJsB;AAAA;;AAMhCC,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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E,cAA5B;AACA,kBAAMmE,GAAN;AACD,WArBH,CADF;AAwBD,SA5BD;AA6BD,OA/BD;AAgCD;;AAED,WAAO1B,QAAP;AACD;;AAhS+B;;AAmSlC,eAAezD,2BAAf","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,28 @@
1
+ export declare type GleapUserProperty = {
2
+ email?: string;
3
+ name?: string;
4
+ };
5
+ declare type GleapSdkType = {
6
+ initialize(token: string): void;
7
+ startFeedbackFlow(): void;
8
+ sendSilentBugReport(description: string, severity: 'LOW' | 'MEDIUM' | 'HIGH'): void;
9
+ identify(userId: string, userProperties: GleapUserProperty): void;
10
+ clearIdentity(): void;
11
+ setApiUrl(apiUrl: string): void;
12
+ setWidgetUrl(widgetUrl: string): void;
13
+ attachCustomData(customData: any): void;
14
+ setCustomData(key: string, value: string): void;
15
+ removeCustomDataForKey(key: string): void;
16
+ clearCustomData(): void;
17
+ registerCustomAction(customActionCallback: (data: {
18
+ name: string;
19
+ }) => void): void;
20
+ setLanguage(language: string): void;
21
+ logEvent(name: string, data: any): void;
22
+ addAttachment(base64file: string, fileName: string): void;
23
+ removeAllAttachments(): void;
24
+ startNetworkLogging(): void;
25
+ stopNetworkLogging(): void;
26
+ };
27
+ declare const _default: GleapSdkType;
28
+ export default _default;
@@ -0,0 +1,14 @@
1
+ declare class BugBattleNetworkIntercepter {
2
+ requestId: number;
3
+ requests: any;
4
+ maxRequests: number;
5
+ stopped: boolean;
6
+ getRequests(): unknown[];
7
+ setMaxRequests(maxRequests: number): void;
8
+ setStopped(stopped: boolean): void;
9
+ cleanRequests(): void;
10
+ calcRequestTime(gleapRequestId: string | number): void;
11
+ start(): void;
12
+ interceptNetworkRequests(callback: any): any;
13
+ }
14
+ export default BugBattleNetworkIntercepter;
package/package.json ADDED
@@ -0,0 +1,147 @@
1
+ {
2
+ "name": "react-native-gleapsdk",
3
+ "version": "6.0.0",
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
+ "main": "lib/commonjs/index",
6
+ "module": "lib/module/index",
7
+ "types": "lib/typescript/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "android",
14
+ "ios",
15
+ "cpp",
16
+ "react-native-gleapsdk.podspec",
17
+ "!lib/typescript/example",
18
+ "!android/build",
19
+ "!ios/build",
20
+ "!**/__tests__",
21
+ "!**/__fixtures__",
22
+ "!**/__mocks__"
23
+ ],
24
+ "scripts": {
25
+ "test": "jest",
26
+ "typescript": "tsc --noEmit",
27
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
28
+ "prepare": "bob build",
29
+ "release": "release-it",
30
+ "example": "yarn --cwd example",
31
+ "pods": "cd example && pod-install --quiet",
32
+ "bootstrap": "yarn example && yarn && yarn pods"
33
+ },
34
+ "keywords": [
35
+ "react-native",
36
+ "ios",
37
+ "android"
38
+ ],
39
+ "repository": "https://github.com/GleapSDK/ReactNative-SDK",
40
+ "author": "gleap <hello@gleap.io> (https://github.com/GleapSDK)",
41
+ "license": "MIT",
42
+ "bugs": {
43
+ "url": "https://github.com/GleapSDK/ReactNative-SDK/issues"
44
+ },
45
+ "homepage": "https://github.com/GleapSDK/ReactNative-SDK#readme",
46
+ "publishConfig": {
47
+ "registry": "https://registry.npmjs.org/"
48
+ },
49
+ "devDependencies": {
50
+ "@commitlint/config-conventional": "^11.0.0",
51
+ "@react-native-community/eslint-config": "^2.0.0",
52
+ "@release-it/conventional-changelog": "^2.0.0",
53
+ "@types/jest": "^26.0.0",
54
+ "@types/react": "^16.9.19",
55
+ "@types/react-native": "0.62.13",
56
+ "commitlint": "^11.0.0",
57
+ "eslint": "^7.2.0",
58
+ "eslint-config-prettier": "^7.0.0",
59
+ "eslint-plugin-prettier": "^3.1.3",
60
+ "husky": "^6.0.0",
61
+ "jest": "^26.0.1",
62
+ "pod-install": "^0.1.0",
63
+ "prettier": "^2.0.5",
64
+ "react": "16.13.1",
65
+ "react-native": "0.63.4",
66
+ "react-native-builder-bob": "^0.18.0",
67
+ "release-it": "^14.2.2",
68
+ "typescript": "^4.1.3"
69
+ },
70
+ "peerDependencies": {
71
+ "react": "*",
72
+ "react-native": "*"
73
+ },
74
+ "jest": {
75
+ "preset": "react-native",
76
+ "modulePathIgnorePatterns": [
77
+ "<rootDir>/example/node_modules",
78
+ "<rootDir>/lib/"
79
+ ]
80
+ },
81
+ "commitlint": {
82
+ "extends": [
83
+ "@commitlint/config-conventional"
84
+ ]
85
+ },
86
+ "release-it": {
87
+ "git": {
88
+ "commitMessage": "chore: release ${version}",
89
+ "tagName": "v${version}"
90
+ },
91
+ "npm": {
92
+ "publish": true
93
+ },
94
+ "github": {
95
+ "release": true
96
+ },
97
+ "plugins": {
98
+ "@release-it/conventional-changelog": {
99
+ "preset": "angular"
100
+ }
101
+ }
102
+ },
103
+ "eslintConfig": {
104
+ "root": true,
105
+ "extends": [
106
+ "@react-native-community",
107
+ "prettier"
108
+ ],
109
+ "rules": {
110
+ "prettier/prettier": [
111
+ "error",
112
+ {
113
+ "quoteProps": "consistent",
114
+ "singleQuote": true,
115
+ "tabWidth": 2,
116
+ "trailingComma": "es5",
117
+ "useTabs": false
118
+ }
119
+ ]
120
+ }
121
+ },
122
+ "eslintIgnore": [
123
+ "node_modules/",
124
+ "lib/"
125
+ ],
126
+ "prettier": {
127
+ "quoteProps": "consistent",
128
+ "singleQuote": true,
129
+ "tabWidth": 2,
130
+ "trailingComma": "es5",
131
+ "useTabs": false
132
+ },
133
+ "react-native-builder-bob": {
134
+ "source": "src",
135
+ "output": "lib",
136
+ "targets": [
137
+ "commonjs",
138
+ "module",
139
+ [
140
+ "typescript",
141
+ {
142
+ "project": "tsconfig.build.json"
143
+ }
144
+ ]
145
+ ]
146
+ }
147
+ }
@@ -0,0 +1,20 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "react-native-gleapsdk"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => "10.0" }
14
+ s.source = { :git => "https://github.com/GleapSDK/ReactNative-SDK.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm}"
17
+
18
+ s.dependency "React-Core"
19
+ s.dependency "Gleap", "6.0.10"
20
+ end
package/src/index.tsx ADDED
@@ -0,0 +1,115 @@
1
+ import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
2
+ import GleapNetworkIntercepter from './networklogger';
3
+
4
+ const LINKING_ERROR =
5
+ `The package 'react-native-gleapsdk' doesn't seem to be linked. Make sure: \n\n` +
6
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
7
+ '- You rebuilt the app after installing the package\n' +
8
+ '- You are not using Expo managed workflow\n';
9
+
10
+ export type GleapUserProperty = {
11
+ email?: string;
12
+ name?: string;
13
+ };
14
+
15
+ type GleapSdkType = {
16
+ initialize(token: string): void;
17
+ startFeedbackFlow(): void;
18
+ sendSilentBugReport(
19
+ description: string,
20
+ severity: 'LOW' | 'MEDIUM' | 'HIGH'
21
+ ): void;
22
+ identify(userId: string, userProperties: GleapUserProperty): void;
23
+ clearIdentity(): void;
24
+ setApiUrl(apiUrl: string): void;
25
+ setWidgetUrl(widgetUrl: string): void;
26
+ attachCustomData(customData: any): void;
27
+ setCustomData(key: string, value: string): void;
28
+ removeCustomDataForKey(key: string): void;
29
+ clearCustomData(): void;
30
+ registerCustomAction(
31
+ customActionCallback: (data: { name: string }) => void
32
+ ): void;
33
+ setLanguage(language: string): void;
34
+ logEvent(name: string, data: any): void;
35
+ addAttachment(base64file: string, fileName: string): void;
36
+ removeAllAttachments(): void;
37
+ startNetworkLogging(): void;
38
+ stopNetworkLogging(): void;
39
+ };
40
+
41
+ const GleapSdk = NativeModules.Gleapsdk
42
+ ? NativeModules.Gleapsdk
43
+ : new Proxy(
44
+ {},
45
+ {
46
+ get() {
47
+ throw new Error(LINKING_ERROR);
48
+ },
49
+ }
50
+ );
51
+ const networkLogger = new GleapNetworkIntercepter();
52
+
53
+ GleapSdk.startNetworkLogging = () => {
54
+ networkLogger.start();
55
+ };
56
+
57
+ GleapSdk.stopNetworkLogging = () => {
58
+ networkLogger.setStopped(true);
59
+ };
60
+
61
+ if (GleapSdk) {
62
+ var callbacks: any[] = [];
63
+
64
+ GleapSdk.registerCustomAction = (customActionCallback: any) => {
65
+ callbacks.push(customActionCallback);
66
+ };
67
+
68
+ const gleapEmitter = new NativeEventEmitter(GleapSdk);
69
+ gleapEmitter.addListener('configLoaded', (config: any) => {
70
+ try {
71
+ const configJSON = JSON.parse(config);
72
+ if (configJSON.enableNetworkLogs) {
73
+ GleapSdk.startNetworkLogging();
74
+ }
75
+ } catch (exp) {}
76
+ });
77
+ gleapEmitter.addListener('feedbackWillBeSent', () => {
78
+ // Push the network log to the native SDK.
79
+ const requests = networkLogger.getRequests();
80
+ if (Platform.OS === 'android') {
81
+ GleapSdk.attachNetworkLog(JSON.stringify(requests));
82
+ } else {
83
+ GleapSdk.attachNetworkLog(requests);
84
+ }
85
+ });
86
+
87
+ gleapEmitter.addListener('customActionTriggered', (data: any) => {
88
+ try {
89
+ if (isJsonString(data)) {
90
+ data = JSON.parse(data);
91
+ }
92
+ const { name } = data;
93
+ if (name && callbacks.length > 0) {
94
+ for (var i = 0; i < callbacks.length; i++) {
95
+ if (callbacks[i]) {
96
+ callbacks[i]({
97
+ name,
98
+ });
99
+ }
100
+ }
101
+ }
102
+ } catch (exp) {}
103
+ });
104
+ }
105
+
106
+ function isJsonString(str: string) {
107
+ try {
108
+ JSON.parse(str);
109
+ } catch (e) {
110
+ return false;
111
+ }
112
+ return true;
113
+ }
114
+
115
+ export default GleapSdk as GleapSdkType;
@@ -0,0 +1,292 @@
1
+ class BugBattleNetworkIntercepter {
2
+ requestId = 0;
3
+ requests: any = {};
4
+ maxRequests = 10;
5
+ stopped = false;
6
+
7
+ getRequests() {
8
+ return Object.values(this.requests);
9
+ }
10
+
11
+ setMaxRequests(maxRequests: number) {
12
+ this.maxRequests = maxRequests;
13
+ }
14
+
15
+ setStopped(stopped: boolean) {
16
+ this.stopped = stopped;
17
+ }
18
+
19
+ cleanRequests() {
20
+ var keys = Object.keys(this.requests);
21
+ if (keys.length > this.maxRequests) {
22
+ var keysToRemove = keys.slice(0, keys.length - this.maxRequests);
23
+ for (var i = 0; i < keysToRemove.length; i++) {
24
+ delete this.requests[keysToRemove[i]];
25
+ }
26
+ }
27
+ }
28
+
29
+ calcRequestTime(gleapRequestId: string | number) {
30
+ if (!this.requests[gleapRequestId]) {
31
+ return;
32
+ }
33
+
34
+ var startDate = this.requests[gleapRequestId].date;
35
+ if (startDate) {
36
+ this.requests[gleapRequestId].duration =
37
+ new Date().getTime() - startDate.getTime();
38
+ this.requests[gleapRequestId].date = this.requests[
39
+ gleapRequestId
40
+ ].date.toString();
41
+ }
42
+ }
43
+
44
+ start() {
45
+ this.setStopped(false);
46
+ this.interceptNetworkRequests({
47
+ onFetch: (params: any, gleapRequestId: any) => {
48
+ if (this.stopped) {
49
+ return;
50
+ }
51
+
52
+ if (params.length >= 2) {
53
+ var method = params[1].method ? params[1].method : 'GET';
54
+ this.requests[gleapRequestId] = {
55
+ request: {
56
+ payload: params[1].body,
57
+ headers: params[1].headers,
58
+ },
59
+ type: method,
60
+ url: params[0],
61
+ date: new Date(),
62
+ };
63
+ } else {
64
+ this.requests[gleapRequestId] = {
65
+ request: {},
66
+ url: params[0],
67
+ type: 'GET',
68
+ date: new Date(),
69
+ };
70
+ }
71
+
72
+ this.cleanRequests();
73
+ },
74
+ onFetchLoad: (req: any, gleapRequestId: any) => {
75
+ if (this.stopped) {
76
+ return;
77
+ }
78
+
79
+ req.text().then((responseText: any) => {
80
+ this.requests[gleapRequestId].success = true;
81
+ this.requests[gleapRequestId].response = {
82
+ status: req.status,
83
+ statusText: req.statusText,
84
+ responseText: responseText,
85
+ };
86
+
87
+ this.calcRequestTime(gleapRequestId);
88
+
89
+ this.cleanRequests();
90
+ });
91
+ },
92
+ onFetchFailed: (_err: any, gleapRequestId: any) => {
93
+ if (this.stopped) {
94
+ return;
95
+ }
96
+
97
+ this.requests[gleapRequestId].success = false;
98
+ this.calcRequestTime(gleapRequestId);
99
+
100
+ this.cleanRequests();
101
+ },
102
+ onOpen: (request: any, args: string | any[]) => {
103
+ if (this.stopped) {
104
+ return;
105
+ }
106
+
107
+ if (
108
+ request &&
109
+ request.gleapRequestId &&
110
+ args.length >= 2 &&
111
+ this.requests
112
+ ) {
113
+ this.requests[request.gleapRequestId] = {
114
+ type: args[0],
115
+ url: args[1],
116
+ date: new Date(),
117
+ };
118
+ }
119
+
120
+ this.cleanRequests();
121
+ },
122
+ onSend: (request: any, args: string | any[]) => {
123
+ if (this.stopped) {
124
+ return;
125
+ }
126
+
127
+ if (
128
+ request &&
129
+ request.gleapRequestId &&
130
+ args.length > 0 &&
131
+ this.requests &&
132
+ this.requests[request.gleapRequestId]
133
+ ) {
134
+ this.requests[request.gleapRequestId].request = {
135
+ payload: args[0],
136
+ headers: request.requestHeaders,
137
+ };
138
+ }
139
+
140
+ this.cleanRequests();
141
+ },
142
+ onError: (request: any) => {
143
+ if (
144
+ !this.stopped &&
145
+ this.requests &&
146
+ request &&
147
+ request.gleapRequestId &&
148
+ this.requests[request.gleapRequestId]
149
+ ) {
150
+ this.requests[request.gleapRequestId].success = false;
151
+ this.calcRequestTime(request.gleapRequestId);
152
+ }
153
+
154
+ this.cleanRequests();
155
+ },
156
+ onLoad: (request: any) => {
157
+ if (this.stopped) {
158
+ return;
159
+ }
160
+
161
+ if (
162
+ request &&
163
+ request.gleapRequestId &&
164
+ this.requests &&
165
+ this.requests[request.gleapRequestId]
166
+ ) {
167
+ const contentType = request.getResponseHeader('content-type');
168
+ const isTextOrJSON =
169
+ contentType &&
170
+ (contentType.includes('json') || contentType.includes('text'));
171
+
172
+ var responseText = '<' + contentType + '>';
173
+ if (request.responseType === '' || request.responseType === 'text') {
174
+ responseText = request.responseText;
175
+ }
176
+ if (request._response && isTextOrJSON) {
177
+ responseText = request._response;
178
+ }
179
+
180
+ this.requests[request.gleapRequestId].success = true;
181
+ this.requests[request.gleapRequestId].response = {
182
+ status: request.status,
183
+ responseText: responseText,
184
+ };
185
+
186
+ this.calcRequestTime(request.gleapRequestId);
187
+ }
188
+
189
+ this.cleanRequests();
190
+ },
191
+ });
192
+ }
193
+
194
+ interceptNetworkRequests(callback: any) {
195
+ // eslint-disable-next-line consistent-this
196
+ var self = this;
197
+
198
+ // XMLHttpRequest
199
+ const open = XMLHttpRequest.prototype.open;
200
+ const send = XMLHttpRequest.prototype.send;
201
+
202
+ // @ts-ignore
203
+ XMLHttpRequest.prototype.wrappedSetRequestHeader =
204
+ XMLHttpRequest.prototype.setRequestHeader;
205
+ XMLHttpRequest.prototype.setRequestHeader = function (header, value) {
206
+ // @ts-ignore
207
+ this.wrappedSetRequestHeader(header, value);
208
+
209
+ // @ts-ignore
210
+ if (!this.requestHeaders) {
211
+ // @ts-ignore
212
+ this.requestHeaders = {};
213
+ }
214
+
215
+ // @ts-ignore
216
+ if (!this.requestHeaders[header]) {
217
+ // @ts-ignore
218
+ this.requestHeaders[header] = [];
219
+ }
220
+
221
+ // @ts-ignore
222
+ this.requestHeaders[header].push(value);
223
+ };
224
+
225
+ XMLHttpRequest.prototype.open = function () {
226
+ (this as any).gleapRequestId = ++self.requestId;
227
+ callback.onOpen && callback.onOpen(this, arguments);
228
+
229
+ if (callback.onLoad) {
230
+ this.addEventListener('load', function () {
231
+ // @ts-ignore
232
+ callback.onLoad(this);
233
+ });
234
+ }
235
+ if (callback.onError) {
236
+ this.addEventListener('error', function () {
237
+ // @ts-ignore
238
+ callback.onError(this);
239
+ });
240
+ }
241
+
242
+ // @ts-ignore
243
+ return open.apply(this, arguments);
244
+ };
245
+
246
+ XMLHttpRequest.prototype.send = function () {
247
+ callback.onSend && callback.onSend(this, arguments);
248
+ // @ts-ignore
249
+ return send.apply(this, arguments);
250
+ };
251
+
252
+ // Fetch
253
+ if (global) {
254
+ (function () {
255
+ var originalFetch = global.fetch;
256
+ global.fetch = function () {
257
+ var gleapRequestId = ++self.requestId;
258
+ callback.onFetch(arguments, gleapRequestId);
259
+
260
+ return (
261
+ originalFetch
262
+ // @ts-ignore
263
+ .apply(this, arguments)
264
+ .then(function (data) {
265
+ return data.text().then((textData) => {
266
+ data.text = function () {
267
+ return Promise.resolve(textData);
268
+ };
269
+
270
+ data.json = function () {
271
+ return Promise.resolve(JSON.parse(textData));
272
+ };
273
+
274
+ callback.onFetchLoad(data, gleapRequestId);
275
+
276
+ return data;
277
+ });
278
+ })
279
+ .catch((err) => {
280
+ callback.onFetchFailed(err, gleapRequestId);
281
+ throw err;
282
+ })
283
+ );
284
+ };
285
+ })();
286
+ }
287
+
288
+ return callback;
289
+ }
290
+ }
291
+
292
+ export default BugBattleNetworkIntercepter;