@wutiange/log-listener-plugin 1.3.2 → 2.0.1-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +130 -24
- package/dist/src/HTTPInterceptor.d.ts +1 -0
- package/dist/src/HTTPInterceptor.js +12 -9
- package/dist/src/HTTPInterceptor.js.map +1 -1
- package/dist/src/Server.d.ts +13 -6
- package/dist/src/Server.js +119 -41
- package/dist/src/Server.js.map +1 -1
- package/dist/src/__mocks__/react-native/Libraries/Blob/FileReader.js +0 -1
- package/dist/src/__mocks__/react-native/Libraries/Blob/FileReader.js.map +1 -1
- package/dist/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js +0 -1
- package/dist/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js.map +1 -1
- package/dist/src/__tests__/Server.test.js +89 -114
- package/dist/src/__tests__/Server.test.js.map +1 -1
- package/dist/src/common.d.ts +19 -10
- package/dist/src/common.js +63 -4
- package/dist/src/common.js.map +1 -1
- package/dist/src/logPlugin.d.ts +12 -9
- package/dist/src/logPlugin.js +87 -82
- package/dist/src/logPlugin.js.map +1 -1
- package/dist/src/logger.d.ts +6 -0
- package/dist/src/logger.js +16 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/utils.js +12 -7
- package/dist/src/utils.js.map +1 -1
- package/index.ts +3 -0
- package/package.json +18 -12
- package/src/HTTPInterceptor.ts +339 -0
- package/src/Server.ts +166 -0
- package/src/__mocks__/react-native/Libraries/Blob/FileReader.js +45 -0
- package/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js +39 -0
- package/src/__tests__/HTTPInterceptor.test.ts +322 -0
- package/src/__tests__/Server.test.ts +175 -0
- package/src/__tests__/utils.test.ts +113 -0
- package/src/common.ts +70 -0
- package/src/logPlugin.ts +224 -0
- package/src/logger.ts +15 -0
- package/src/utils.ts +112 -0
- package/tsconfig.json +27 -0
@@ -14,141 +14,116 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
15
|
const Server_1 = __importDefault(require("../Server"));
|
16
16
|
const utils_1 = require("../utils");
|
17
|
-
jest.mock('../utils', () =>
|
18
|
-
|
19
|
-
|
20
|
-
})
|
21
|
-
jest.mock('
|
22
|
-
|
23
|
-
}));
|
24
|
-
class MockResponse {
|
25
|
-
constructor(body) {
|
26
|
-
this.body = body;
|
27
|
-
}
|
28
|
-
text() {
|
29
|
-
return Promise.resolve(this.body);
|
30
|
-
}
|
31
|
-
static [Symbol.hasInstance](instance) {
|
32
|
-
return instance && typeof instance.text === 'function';
|
33
|
-
}
|
34
|
-
}
|
35
|
-
global.Response = MockResponse;
|
17
|
+
jest.mock('../utils', () => {
|
18
|
+
const actual = jest.requireActual('../utils');
|
19
|
+
return Object.assign(Object.assign({}, actual), { sleep: jest.fn() });
|
20
|
+
});
|
21
|
+
jest.mock('react-native-zeroconf', () => undefined, { virtual: true });
|
22
|
+
global.fetch = jest.fn();
|
36
23
|
describe('Server', () => {
|
37
24
|
let server;
|
38
|
-
const mockUrl = 'http://example.com';
|
39
|
-
const mockTimeout = 5000;
|
40
25
|
beforeEach(() => {
|
41
|
-
server = new Server_1.default(mockUrl, mockTimeout);
|
42
26
|
jest.clearAllMocks();
|
27
|
+
global.fetch.mockReset();
|
43
28
|
});
|
44
|
-
describe('
|
45
|
-
it('should initialize with
|
46
|
-
|
47
|
-
expect(server
|
48
|
-
});
|
49
|
-
it('should use default timeout if not provided', () => {
|
50
|
-
const defaultServer = new Server_1.default(mockUrl);
|
51
|
-
expect(defaultServer['timeout']).toBe(3000);
|
29
|
+
describe('Constructor and URL Management', () => {
|
30
|
+
it('should initialize with default values', () => {
|
31
|
+
server = new Server_1.default();
|
32
|
+
expect(server.getUrls()).toEqual([]);
|
52
33
|
});
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
server.updateTimeout(10000);
|
57
|
-
expect(server['timeout']).toBe(10000);
|
34
|
+
it('should initialize with custom URL', () => {
|
35
|
+
server = new Server_1.default('localhost:8080');
|
36
|
+
expect(server.getUrls()).toEqual(['http://localhost:8080']);
|
58
37
|
});
|
59
|
-
it('should
|
60
|
-
server.
|
61
|
-
|
38
|
+
it('should handle URLs with and without http prefix', () => {
|
39
|
+
server = new Server_1.default();
|
40
|
+
server.updateUrl('localhost:8080');
|
41
|
+
expect(server.getUrls()).toEqual(['http://localhost:8080']);
|
42
|
+
server.updateUrl('http://localhost:8080');
|
43
|
+
expect(server.getUrls()).toEqual(['http://localhost:8080']);
|
62
44
|
});
|
63
45
|
});
|
64
|
-
describe('
|
65
|
-
it('should
|
66
|
-
|
67
|
-
|
46
|
+
describe('ZeroConf Handling', () => {
|
47
|
+
it('should handle case when zeroconf is not available', () => {
|
48
|
+
server = new Server_1.default();
|
49
|
+
const mockListener = jest.fn();
|
50
|
+
server.addUrlsListener(mockListener);
|
51
|
+
expect(mockListener).not.toHaveBeenCalled();
|
68
52
|
});
|
69
|
-
it('should
|
70
|
-
|
71
|
-
|
53
|
+
it('should handle case when zeroconf is available', () => {
|
54
|
+
const mockZeroconfInstance = {
|
55
|
+
on: jest.fn(),
|
56
|
+
scan: jest.fn()
|
57
|
+
};
|
58
|
+
jest.doMock('react-native-zeroconf', () => ({
|
59
|
+
__esModule: true,
|
60
|
+
default: jest.fn(() => mockZeroconfInstance)
|
61
|
+
}), { virtual: true });
|
62
|
+
server = new Server_1.default();
|
63
|
+
const mockListener = jest.fn();
|
64
|
+
server.addUrlsListener(mockListener);
|
65
|
+
expect(mockListener).not.toHaveBeenCalled();
|
72
66
|
});
|
73
67
|
});
|
74
|
-
describe('
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
});
|
79
|
-
it('should return correct url without port', () => {
|
80
|
-
utils_1.hasPort.mockReturnValue(true);
|
81
|
-
expect(server.getUrl()).toBe(`${mockUrl}:`);
|
68
|
+
describe('Data Sending', () => {
|
69
|
+
beforeEach(() => {
|
70
|
+
server = new Server_1.default('localhost:8080');
|
71
|
+
global.fetch.mockImplementation(() => Promise.resolve({ ok: true }));
|
82
72
|
});
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
const mockResponse = new MockResponse('success');
|
88
|
-
it('should return null if baseUrl is empty', () => __awaiter(void 0, void 0, void 0, function* () {
|
89
|
-
server.updateUrl('');
|
90
|
-
const result = yield server['send'](mockPath, mockData);
|
91
|
-
expect(result).toBeNull();
|
92
|
-
}));
|
93
|
-
it('should return response text on successful fetch', () => __awaiter(void 0, void 0, void 0, function* () {
|
94
|
-
const common = require('../common');
|
95
|
-
const mockResponseText = 'success';
|
96
|
-
const mockResponseObject = new MockResponse(mockResponseText);
|
97
|
-
common.tempFetch.mockResolvedValue(mockResponseObject);
|
98
|
-
const result = yield server['send'](mockPath, mockData);
|
99
|
-
expect(result).toBe(mockResponseText);
|
100
|
-
expect(common.tempFetch).toHaveBeenCalledWith(`${server.getUrl()}/${mockPath}`, expect.objectContaining({
|
73
|
+
it('should send log data', () => __awaiter(void 0, void 0, void 0, function* () {
|
74
|
+
const testData = { message: 'test log' };
|
75
|
+
yield server.log(testData);
|
76
|
+
expect(global.fetch).toHaveBeenCalledWith('http://localhost:8080/log', expect.objectContaining({
|
101
77
|
method: 'POST',
|
102
|
-
headers: {
|
103
|
-
|
78
|
+
headers: {
|
79
|
+
'Content-Type': 'application/json;charset=utf-8'
|
80
|
+
},
|
81
|
+
body: expect.any(String)
|
104
82
|
}));
|
105
83
|
}));
|
106
|
-
it('should
|
107
|
-
const
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
common.tempFetch.mockResolvedValue(mockResponse);
|
116
|
-
const dataWithError = { error: new Error('Test error') };
|
117
|
-
yield server['send'](mockPath, dataWithError);
|
118
|
-
expect(common.tempFetch).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
|
119
|
-
body: expect.stringContaining('Error: Test error'),
|
84
|
+
it('should send network data', () => __awaiter(void 0, void 0, void 0, function* () {
|
85
|
+
const testData = { url: 'test.com' };
|
86
|
+
yield server.network(testData);
|
87
|
+
expect(global.fetch).toHaveBeenCalledWith('http://localhost:8080/network', expect.objectContaining({
|
88
|
+
method: 'POST',
|
89
|
+
headers: {
|
90
|
+
'Content-Type': 'application/json;charset=utf-8'
|
91
|
+
},
|
92
|
+
body: expect.any(String)
|
120
93
|
}));
|
121
94
|
}));
|
122
|
-
it('should
|
123
|
-
|
124
|
-
|
125
|
-
const
|
126
|
-
|
95
|
+
it('should handle timeout', () => __awaiter(void 0, void 0, void 0, function* () {
|
96
|
+
server.updateTimeout(100);
|
97
|
+
utils_1.sleep.mockImplementation(() => Promise.reject(new Error('Timeout')));
|
98
|
+
const testData = { message: 'test' };
|
99
|
+
yield server.log(testData);
|
100
|
+
expect(global.fetch).toHaveBeenCalled();
|
101
|
+
expect(utils_1.sleep).toHaveBeenCalledWith(100, true);
|
127
102
|
}));
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
expect(sendSpy).toHaveBeenCalledWith('log', logData);
|
142
|
-
expect(result).toBe('log result');
|
103
|
+
it('should handle errors and send error data', () => __awaiter(void 0, void 0, void 0, function* () {
|
104
|
+
global.fetch.mockImplementation(() => Promise.reject(new Error('Network error')));
|
105
|
+
const testData = { message: 'test' };
|
106
|
+
yield server.log(testData);
|
107
|
+
expect(global.fetch).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
|
108
|
+
body: expect.stringContaining('log-plugin-internal-error')
|
109
|
+
}));
|
110
|
+
const lastCall = global.fetch.mock.calls[global.fetch.mock.calls.length - 1];
|
111
|
+
const body = JSON.parse(lastCall[1].body);
|
112
|
+
expect(body).toMatchObject({
|
113
|
+
tag: 'log-plugin-internal-error',
|
114
|
+
level: 'error'
|
115
|
+
});
|
143
116
|
}));
|
144
117
|
});
|
145
|
-
describe('
|
146
|
-
it('should
|
147
|
-
|
148
|
-
const
|
149
|
-
|
150
|
-
|
151
|
-
expect(
|
118
|
+
describe('Base Data Management', () => {
|
119
|
+
it('should update base data', () => __awaiter(void 0, void 0, void 0, function* () {
|
120
|
+
server = new Server_1.default('localhost:8080');
|
121
|
+
const baseData = { userId: '123' };
|
122
|
+
server.updateBaseData(baseData);
|
123
|
+
yield server.log({ message: 'test' });
|
124
|
+
expect(global.fetch).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({
|
125
|
+
body: expect.stringContaining('"userId":"123"')
|
126
|
+
}));
|
152
127
|
}));
|
153
128
|
});
|
154
129
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Server.test.js","sourceRoot":"","sources":["../../../src/__tests__/Server.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAA+B;AAC/B,
|
1
|
+
{"version":3,"file":"Server.test.js","sourceRoot":"","sources":["../../../src/__tests__/Server.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAA+B;AAC/B,oCAAiC;AAGjC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE;IACzB,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAC9C,uCACK,MAAM,KACT,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,IAChB;AACJ,CAAC,CAAC,CAAC;AAIH,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAGvE,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAEzB,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,IAAI,MAAc,CAAC;IAEnB,UAAU,CAAC,GAAG,EAAE;QAEd,IAAI,CAAC,aAAa,EAAE,CAAC;QACpB,MAAM,CAAC,KAAmB,CAAC,SAAS,EAAE,CAAC;IAC1C,CAAC,CAAC,CAAC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,KAAK,CAAC,CAAC,oBAAoB,CACvC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAClB,MAAM,CAAC,gBAAgB,CAAC;gBACtB,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,gBAAgB,CAAC;aAChD,CAAC,CACH,CAAC;QACJ,CAAC,CAAA,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/common.d.ts
CHANGED
@@ -1,11 +1,20 @@
|
|
1
|
-
export declare const log
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
export declare const URLS_KEY = "log-listener-plugin-urls$$key";
|
2
|
+
export declare const DEFAULT_TIMEOUT = 3000;
|
3
|
+
export declare const LOG_KEY = "[@wutiange/log-listener-plugin \u65E5\u5FD7]";
|
4
|
+
export declare enum Level {
|
5
|
+
LOG = "log",
|
6
|
+
WARN = "warn",
|
7
|
+
ERROR = "error"
|
8
|
+
}
|
9
|
+
export declare enum Tag {
|
10
|
+
LOG_PLUGIN_INTERNAL_ERROR = "log-plugin-internal-error",
|
11
|
+
DEFAULT = "default"
|
12
|
+
}
|
13
|
+
export declare const getBaseData: () => Record<string, string>;
|
14
|
+
export declare const getDefaultStorage: () => Storage;
|
15
|
+
export declare const getErrMsg: (error: any) => {
|
16
|
+
message: string[];
|
17
|
+
tag: Tag;
|
18
|
+
level: Level;
|
19
|
+
createTime: number;
|
10
20
|
};
|
11
|
-
export declare const tempFetch: typeof fetch;
|
package/dist/src/common.js
CHANGED
@@ -1,7 +1,66 @@
|
|
1
1
|
"use strict";
|
2
|
-
var
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
3
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.
|
5
|
-
|
6
|
-
exports.
|
6
|
+
exports.getErrMsg = exports.getDefaultStorage = exports.getBaseData = exports.Tag = exports.Level = exports.LOG_KEY = exports.DEFAULT_TIMEOUT = exports.URLS_KEY = void 0;
|
7
|
+
const logger_1 = __importDefault(require("./logger"));
|
8
|
+
exports.URLS_KEY = 'log-listener-plugin-urls$$key';
|
9
|
+
exports.DEFAULT_TIMEOUT = 3000;
|
10
|
+
exports.LOG_KEY = '[@wutiange/log-listener-plugin 日志]';
|
11
|
+
var Level;
|
12
|
+
(function (Level) {
|
13
|
+
Level["LOG"] = "log";
|
14
|
+
Level["WARN"] = "warn";
|
15
|
+
Level["ERROR"] = "error";
|
16
|
+
})(Level || (exports.Level = Level = {}));
|
17
|
+
var Tag;
|
18
|
+
(function (Tag) {
|
19
|
+
Tag["LOG_PLUGIN_INTERNAL_ERROR"] = "log-plugin-internal-error";
|
20
|
+
Tag["DEFAULT"] = "default";
|
21
|
+
})(Tag || (exports.Tag = Tag = {}));
|
22
|
+
const getDefaultDeviceINfo = () => {
|
23
|
+
try {
|
24
|
+
const { Platform } = require('react-native');
|
25
|
+
return Object.assign({ SystemName: Platform.OS, Version: Platform.Version }, Platform.constants);
|
26
|
+
}
|
27
|
+
catch (error) {
|
28
|
+
logger_1.default.warn(exports.LOG_KEY, '这个插件只能在 react-native 中使用');
|
29
|
+
return {};
|
30
|
+
}
|
31
|
+
};
|
32
|
+
const getBaseData = () => {
|
33
|
+
var _a;
|
34
|
+
try {
|
35
|
+
const DeviceInfo = (_a = require("react-native-device-info")) === null || _a === void 0 ? void 0 : _a.default;
|
36
|
+
return Object.assign({ Brand: DeviceInfo.getBrand(), Model: DeviceInfo.getModel(), AppVersion: DeviceInfo.getVersion(), Carrier: DeviceInfo.getCarrierSync(), Manufacturer: DeviceInfo.getManufacturerSync(), SystemName: DeviceInfo.getSystemName() }, getDefaultDeviceINfo());
|
37
|
+
}
|
38
|
+
catch (error) {
|
39
|
+
return getDefaultDeviceINfo();
|
40
|
+
}
|
41
|
+
};
|
42
|
+
exports.getBaseData = getBaseData;
|
43
|
+
const getDefaultStorage = () => {
|
44
|
+
var _a;
|
45
|
+
try {
|
46
|
+
const AsyncStorage = (_a = require("@react-native-async-storage/async-storage")) === null || _a === void 0 ? void 0 : _a.default;
|
47
|
+
return AsyncStorage;
|
48
|
+
}
|
49
|
+
catch (error) {
|
50
|
+
return null;
|
51
|
+
}
|
52
|
+
};
|
53
|
+
exports.getDefaultStorage = getDefaultStorage;
|
54
|
+
const getErrMsg = (error) => {
|
55
|
+
var _a;
|
56
|
+
return {
|
57
|
+
message: [
|
58
|
+
`${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}--->这是@wutiange/log-listener-plugin内部错误,请提issue反馈,issue地址:https://github.com/wutiange/log-listener-plugin/issues`,
|
59
|
+
],
|
60
|
+
tag: Tag.LOG_PLUGIN_INTERNAL_ERROR,
|
61
|
+
level: Level.ERROR,
|
62
|
+
createTime: Date.now(),
|
63
|
+
};
|
64
|
+
};
|
65
|
+
exports.getErrMsg = getErrMsg;
|
7
66
|
//# sourceMappingURL=common.js.map
|
package/dist/src/common.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAEjB,QAAA,QAAQ,GAAG,+BAA+B,CAAA;AAC1C,QAAA,eAAe,GAAG,IAAI,CAAA;AACtB,QAAA,OAAO,GAAG,oCAAoC,CAAA;AAC3D,IAAY,KAIX;AAJD,WAAY,KAAK;IACf,oBAAW,CAAA;IACX,sBAAa,CAAA;IACb,wBAAe,CAAA;AACjB,CAAC,EAJW,KAAK,qBAAL,KAAK,QAIhB;AAED,IAAY,GAGX;AAHD,WAAY,GAAG;IACb,8DAAuD,CAAA;IACvD,0BAAmB,CAAA;AACrB,CAAC,EAHW,GAAG,mBAAH,GAAG,QAGd;AAED,M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SAAS,GAAG,CAAC,KAAU,EAAE,EAAE;;IACtC,OAAO;QACL,OAAO,EAAE;YACP,GACE,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,mCAAI,KACpB,kHAAkH;SACnH;QACD,GAAG,EAAE,GAAG,CAAC,yBAAyB;QAClC,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;KACvB,CAAA;AACH,CAAC,CAAA;AAXY,QAAA,SAAS,aAWrB"}
|
package/dist/src/logPlugin.d.ts
CHANGED
@@ -1,13 +1,23 @@
|
|
1
|
+
type Options = {
|
2
|
+
storage?: Storage;
|
3
|
+
timeout?: number;
|
4
|
+
testUrl?: string;
|
5
|
+
isAuto?: boolean;
|
6
|
+
baseData?: Record<string, any>;
|
7
|
+
};
|
1
8
|
declare class LogPlugin {
|
2
9
|
private server;
|
3
|
-
private baseData;
|
4
10
|
private timeout;
|
5
|
-
private host;
|
6
11
|
private isAuto;
|
12
|
+
private storage;
|
13
|
+
constructor();
|
14
|
+
private init;
|
15
|
+
config: ({ storage, timeout, testUrl, isAuto, baseData }: Options) => void;
|
7
16
|
auto: () => void;
|
8
17
|
unAuto: () => void;
|
9
18
|
startRecordLog: () => void;
|
10
19
|
stopRecordLog: () => void;
|
20
|
+
private handleIgnoredUrls;
|
11
21
|
startRecordNetwork: () => void;
|
12
22
|
setBaseUrl: (url: string) => void;
|
13
23
|
setTimeout: (timeout: number) => void;
|
@@ -18,13 +28,6 @@ declare class LogPlugin {
|
|
18
28
|
log: (...data: any[]) => void;
|
19
29
|
warn: (...data: any[]) => void;
|
20
30
|
error: (...data: any[]) => void;
|
21
|
-
uniqueReq: (uniqueId: string | undefined, input: RequestInfo | URL, init?: RequestInit) => Promise<string>;
|
22
|
-
private _res;
|
23
|
-
resTimeout: (uniqueId: string) => Promise<string>;
|
24
|
-
resResponseError: (uniqueId: string) => Promise<string>;
|
25
|
-
uniqueRes: (uniqueId: string, response?: Response) => Promise<string>;
|
26
|
-
req: (input: RequestInfo | URL, init?: RequestInit) => Promise<string>;
|
27
|
-
res: (id: number, response?: Response) => Promise<string>;
|
28
31
|
}
|
29
32
|
declare const SafeLogPlugin: typeof LogPlugin;
|
30
33
|
declare const logPlugin: LogPlugin;
|