@wutiange/log-listener-plugin 1.3.0-alpha.1 → 1.3.0-alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +2 -2
  3. package/console.ts +21 -0
  4. package/dist/src/HTTPInterceptor.d.ts +48 -0
  5. package/dist/src/HTTPInterceptor.js +202 -0
  6. package/dist/src/HTTPInterceptor.js.map +1 -0
  7. package/dist/src/logPlugin.d.ts +19 -20
  8. package/dist/src/logPlugin.js +108 -122
  9. package/dist/src/logPlugin.js.map +1 -1
  10. package/fetch.ts +39 -0
  11. package/index.ts +3 -0
  12. package/package.json +49 -47
  13. package/src/HTTPInterceptor.ts +319 -0
  14. package/src/__tests__/console.test.ts +25 -25
  15. package/src/common.ts +4 -4
  16. package/src/logPlugin.ts +238 -229
  17. package/src/server.ts +66 -66
  18. package/src/utils.ts +47 -47
  19. package/dist/packages/network-logger/Logger.d.ts +0 -28
  20. package/dist/packages/network-logger/Logger.js +0 -192
  21. package/dist/packages/network-logger/Logger.js.map +0 -1
  22. package/dist/packages/network-logger/NetworkRequestInfo.d.ts +0 -37
  23. package/dist/packages/network-logger/NetworkRequestInfo.js +0 -151
  24. package/dist/packages/network-logger/NetworkRequestInfo.js.map +0 -1
  25. package/dist/packages/network-logger/constant.d.ts +0 -2
  26. package/dist/packages/network-logger/constant.js +0 -6
  27. package/dist/packages/network-logger/constant.js.map +0 -1
  28. package/dist/packages/network-logger/types.d.ts +0 -14
  29. package/dist/packages/network-logger/types.js +0 -3
  30. package/dist/packages/network-logger/types.js.map +0 -1
  31. package/dist/packages/network-logger/utils/debounce.d.ts +0 -2
  32. package/dist/packages/network-logger/utils/debounce.js +0 -20
  33. package/dist/packages/network-logger/utils/debounce.js.map +0 -1
  34. package/dist/packages/network-logger/utils/extractHost.d.ts +0 -2
  35. package/dist/packages/network-logger/utils/extractHost.js +0 -9
  36. package/dist/packages/network-logger/utils/extractHost.js.map +0 -1
  37. package/dist/packages/network-logger/utils/fromEntries.d.ts +0 -2
  38. package/dist/packages/network-logger/utils/fromEntries.js +0 -8
  39. package/dist/packages/network-logger/utils/fromEntries.js.map +0 -1
  40. package/dist/packages/network-logger/utils/logger.d.ts +0 -1
  41. package/dist/packages/network-logger/utils/logger.js +0 -6
  42. package/dist/packages/network-logger/utils/logger.js.map +0 -1
  43. package/dist/src/CompatibilityManager.d.ts +0 -27
  44. package/dist/src/CompatibilityManager.js +0 -82
  45. package/dist/src/CompatibilityManager.js.map +0 -1
  46. package/dist/src/console.d.ts +0 -1
  47. package/dist/src/console.js +0 -20
  48. package/dist/src/console.js.map +0 -1
  49. package/dist/src/fetch.d.ts +0 -1
  50. package/dist/src/fetch.js +0 -48
  51. package/dist/src/fetch.js.map +0 -1
  52. package/dist/src/index.d.ts +0 -2
  53. package/dist/src/index.js +0 -8
  54. package/dist/src/index.js.map +0 -1
  55. package/packages/network-logger/Logger.ts +0 -274
  56. package/packages/network-logger/NetworkRequestInfo.ts +0 -161
  57. package/packages/network-logger/constant.ts +0 -3
  58. package/packages/network-logger/types.ts +0 -36
  59. package/packages/network-logger/utils/debounce.ts +0 -21
  60. package/packages/network-logger/utils/extractHost.ts +0 -7
  61. package/packages/network-logger/utils/fromEntries.ts +0 -7
  62. package/packages/network-logger/utils/logger.ts +0 -2
  63. package/src/CompatibilityManager.ts +0 -71
@@ -1,36 +0,0 @@
1
- import NetworkRequestInfo from './NetworkRequestInfo';
2
-
3
- export type Headers = {[header: string]: string};
4
- export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
5
- export type StartNetworkLoggingOptions = {
6
- /**
7
- * Max number of requests to keep before overwriting
8
- * @default 500
9
- */
10
- maxRequests?: number;
11
- /** List of hosts to ignore, e.g. `services.test.com` */
12
- ignoredHosts?: string[];
13
- /** List of urls to ignore, e.g. `https://services.test.com/test` */
14
- ignoredUrls?: string[];
15
- /**
16
- * List of url patterns to ignore, e.g. `/^GET https://test.com\/pages\/.*$/`
17
- *
18
- * Url to match with is in the format: `${method} ${url}`, e.g. `GET https://test.com/pages/123`
19
- */
20
- ignoredPatterns?: RegExp[];
21
- /**
22
- * Force the network logger to start even if another program is using the network interceptor
23
- * e.g. a dev/debuging program
24
- */
25
- forceEnable?: boolean;
26
- /**
27
- * Refresh rate of the logger in milliseconds
28
- * @default 50
29
- */
30
- refreshRate?: number;
31
- };
32
-
33
- export type NetworkRequestInfoRow = Pick<
34
- NetworkRequestInfo,
35
- 'url' | 'gqlOperation' | 'id' | 'method' | 'status' | 'duration' | 'startTime'
36
- >;
@@ -1,21 +0,0 @@
1
- // https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_debounce
2
- function debounce(func: Function, wait: number, immediate: boolean = false) {
3
- let timeout: ReturnType<typeof setTimeout> | undefined;
4
- return function () {
5
- const args = arguments;
6
- clearTimeout(timeout);
7
- // @ts-ignore
8
- if (immediate && !timeout) {
9
- func.apply(this, args);
10
- }
11
- timeout = setTimeout(function () {
12
- timeout = undefined;
13
- // @ts-ignore
14
- if (!immediate) {
15
- func.apply(this, args);
16
- }
17
- }, wait);
18
- };
19
- }
20
-
21
- export default debounce;
@@ -1,7 +0,0 @@
1
- const extractHost = (url: string) => {
2
- const host = url.split('//')[1]?.split(':')[0]?.split('/')[0] || undefined;
3
-
4
- return host;
5
- };
6
-
7
- export default extractHost;
@@ -1,7 +0,0 @@
1
- const fromEntries = (arr: any[]) =>
2
- arr.reduce((acc, [k, v]) => {
3
- acc[k] = v;
4
- return acc;
5
- }, {});
6
-
7
- export default fromEntries;
@@ -1,2 +0,0 @@
1
- export const warn = (message: string) =>
2
- console.warn(`react-native-network-logger: ${message}`);
@@ -1,71 +0,0 @@
1
- import NetworkRequestInfo from "../packages/network-logger/NetworkRequestInfo";
2
-
3
- class CompatibilityManager {
4
- private static requestInfoObj: Record<string, NetworkRequestInfo> = {}
5
- static async interceptionToNetwork(data: NetworkRequestInfo[]) {
6
- const tempWillSendArr: NetworkRequestInfo[] = []
7
- if (Object.keys(CompatibilityManager.requestInfoObj).length === 0) {
8
- CompatibilityManager.requestInfoObj = data.reduce((e, c) => {
9
- if (c.endTime) {
10
- const startReq = c.copy()
11
- startReq.endTime = 0;
12
- tempWillSendArr.push(startReq, c)
13
- return e
14
- }
15
- tempWillSendArr.push(c)
16
- return {...e, [c.id]: c}
17
- }, {})
18
- } else {
19
- data.forEach(e => {
20
- const tempObj = CompatibilityManager.requestInfoObj
21
- if (!(e.id in tempObj)) {
22
- if (!e.endTime) {
23
- tempWillSendArr.push(e)
24
- CompatibilityManager.requestInfoObj[e.id] = e
25
- } else {
26
- const startReq = e.copy()
27
- startReq.endTime = 0;
28
- tempWillSendArr.push(startReq, e)
29
- }
30
- return
31
- }
32
- if (e.id in tempObj && e.endTime) {
33
- tempWillSendArr.push(e)
34
- delete CompatibilityManager.requestInfoObj[e.id]
35
- return
36
- }
37
- })
38
- }
39
-
40
- // 将要发送的数据转换成兼容的数据
41
- return CompatibilityManager.asyncSwapSendArr(tempWillSendArr)
42
- }
43
-
44
- private static async asyncSwapSendArr(data: NetworkRequestInfo[]) {
45
- const asyncTempArr = await Promise.all(data.map(async (e) => {
46
- if (e.endTime) {
47
- return {
48
- headers: e.responseHeaders,
49
- body: await e.getResponseBody(),
50
- requestId: e.id,
51
- statusCode: e.status,
52
- endTime: e.endTime,
53
- };
54
- } else {
55
- return {
56
- url: e.url,
57
- id: e.id,
58
- method: e.method,
59
- headers: e.requestHeaders,
60
- body: e.getRequestBody(),
61
- createTime: e.startTime,
62
- };
63
- }
64
- }));
65
-
66
- return asyncTempArr;
67
- }
68
- }
69
-
70
-
71
- export default CompatibilityManager