request-iframe 0.0.6 → 0.1.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.
- package/README.CN.md +53 -6
- package/README.md +63 -10
- package/esm/api/client.js +79 -0
- package/esm/api/server.js +59 -0
- package/esm/constants/index.js +257 -0
- package/esm/constants/messages.js +155 -0
- package/esm/core/client-server.js +329 -0
- package/esm/core/client.js +873 -0
- package/esm/core/request.js +27 -0
- package/esm/core/response.js +451 -0
- package/esm/core/server.js +767 -0
- package/esm/index.js +21 -0
- package/esm/interceptors/index.js +122 -0
- package/esm/message/channel.js +181 -0
- package/esm/message/dispatcher.js +380 -0
- package/esm/message/index.js +2 -0
- package/esm/stream/file-stream.js +289 -0
- package/esm/stream/index.js +44 -0
- package/esm/stream/readable-stream.js +500 -0
- package/esm/stream/stream-core.js +91 -0
- package/esm/stream/types.js +1 -0
- package/esm/stream/writable-stream.js +582 -0
- package/esm/types/index.js +1 -0
- package/esm/utils/ack-meta.js +53 -0
- package/esm/utils/cache.js +147 -0
- package/esm/utils/cookie.js +352 -0
- package/esm/utils/debug.js +521 -0
- package/esm/utils/error.js +27 -0
- package/esm/utils/index.js +178 -0
- package/esm/utils/origin.js +28 -0
- package/esm/utils/path-match.js +148 -0
- package/esm/utils/protocol.js +157 -0
- package/library/api/client.d.ts.map +1 -1
- package/library/api/client.js +8 -1
- package/library/api/server.d.ts.map +1 -1
- package/library/api/server.js +4 -1
- package/library/constants/index.d.ts +25 -1
- package/library/constants/index.d.ts.map +1 -1
- package/library/constants/index.js +30 -5
- package/library/constants/messages.d.ts +5 -0
- package/library/constants/messages.d.ts.map +1 -1
- package/library/constants/messages.js +5 -0
- package/library/core/client-server.d.ts +3 -2
- package/library/core/client-server.d.ts.map +1 -1
- package/library/core/client-server.js +51 -4
- package/library/core/client.d.ts +4 -1
- package/library/core/client.d.ts.map +1 -1
- package/library/core/client.js +74 -31
- package/library/core/response.d.ts +21 -3
- package/library/core/response.d.ts.map +1 -1
- package/library/core/response.js +46 -6
- package/library/core/server.d.ts +28 -1
- package/library/core/server.d.ts.map +1 -1
- package/library/core/server.js +180 -19
- package/library/message/channel.d.ts +6 -0
- package/library/message/channel.d.ts.map +1 -1
- package/library/message/dispatcher.d.ts +22 -0
- package/library/message/dispatcher.d.ts.map +1 -1
- package/library/message/dispatcher.js +92 -0
- package/library/stream/file-stream.d.ts +4 -0
- package/library/stream/file-stream.d.ts.map +1 -1
- package/library/stream/file-stream.js +61 -33
- package/library/stream/index.d.ts.map +1 -1
- package/library/stream/index.js +2 -0
- package/library/stream/readable-stream.d.ts +30 -11
- package/library/stream/readable-stream.d.ts.map +1 -1
- package/library/stream/readable-stream.js +329 -73
- package/library/stream/stream-core.d.ts +44 -0
- package/library/stream/stream-core.d.ts.map +1 -0
- package/library/stream/stream-core.js +98 -0
- package/library/stream/types.d.ts +90 -3
- package/library/stream/types.d.ts.map +1 -1
- package/library/stream/writable-stream.d.ts +40 -12
- package/library/stream/writable-stream.d.ts.map +1 -1
- package/library/stream/writable-stream.js +391 -195
- package/library/types/index.d.ts +70 -3
- package/library/types/index.d.ts.map +1 -1
- package/library/utils/ack-meta.d.ts +2 -0
- package/library/utils/ack-meta.d.ts.map +1 -0
- package/library/utils/ack-meta.js +59 -0
- package/library/utils/index.d.ts +1 -0
- package/library/utils/index.d.ts.map +1 -1
- package/library/utils/index.js +16 -0
- package/library/utils/origin.d.ts +14 -0
- package/library/utils/origin.d.ts.map +1 -0
- package/library/utils/origin.js +34 -0
- package/package.json +30 -7
- package/react/README.md +16 -0
- package/react/esm/index.js +284 -0
- package/react/library/index.d.ts +1 -1
- package/react/library/index.d.ts.map +1 -1
- package/react/library/index.js +3 -3
- package/react/package.json +24 -2
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import "core-js/modules/es.array.filter.js";
|
|
2
|
+
import "core-js/modules/es.object.get-own-property-descriptors.js";
|
|
3
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
4
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
6
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
|
+
import "core-js/modules/es.array.iterator.js";
|
|
8
|
+
import "core-js/modules/es.map.js";
|
|
9
|
+
import "core-js/modules/es.promise.js";
|
|
10
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
11
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
+
import { MessageType, getStatusText, Messages } from '../constants';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Debug log prefix
|
|
17
|
+
*/
|
|
18
|
+
var DEBUG_PREFIX = '[request-iframe]';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Format log output
|
|
22
|
+
* - Prefix: bold
|
|
23
|
+
* - info: message text in blue
|
|
24
|
+
*/
|
|
25
|
+
function log(level, message, data) {
|
|
26
|
+
var timestamp = new Date().toISOString();
|
|
27
|
+
var prefix = `${DEBUG_PREFIX} [${timestamp}] [${level.toUpperCase()}]`;
|
|
28
|
+
var prefixStyle = 'font-weight:bold';
|
|
29
|
+
var messageStyle = level === 'info' ? 'color: #1976d2' : '';
|
|
30
|
+
if (data !== undefined) {
|
|
31
|
+
console[level](`%c${prefix}%c ${message}`, prefixStyle, messageStyle, data);
|
|
32
|
+
} else {
|
|
33
|
+
console[level](`%c${prefix}%c ${message}`, prefixStyle, messageStyle);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Format message data for logging (remove sensitive data if needed)
|
|
39
|
+
*/
|
|
40
|
+
function formatMessageData(data) {
|
|
41
|
+
if (!data) return data;
|
|
42
|
+
var formatted = _objectSpread({}, data);
|
|
43
|
+
|
|
44
|
+
// Limit body size in logs
|
|
45
|
+
if (formatted.body && typeof formatted.body === 'object') {
|
|
46
|
+
var bodyStr = JSON.stringify(formatted.body);
|
|
47
|
+
if (bodyStr.length > 500) {
|
|
48
|
+
formatted.body = bodyStr.substring(0, 500) + '... (truncated)';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Limit data size in logs
|
|
53
|
+
if (formatted.data && typeof formatted.data === 'object') {
|
|
54
|
+
var dataStr = JSON.stringify(formatted.data);
|
|
55
|
+
if (dataStr.length > 500) {
|
|
56
|
+
formatted.data = dataStr.substring(0, 500) + '... (truncated)';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return formatted;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Register debug interceptors for client
|
|
64
|
+
*/
|
|
65
|
+
export function setupClientDebugInterceptors(client) {
|
|
66
|
+
// Request interceptor: log request start
|
|
67
|
+
client.interceptors.request.use(config => {
|
|
68
|
+
log('info', Messages.DEBUG_CLIENT_REQUEST_START, formatMessageData({
|
|
69
|
+
path: config.path,
|
|
70
|
+
body: config.body,
|
|
71
|
+
headers: config.headers,
|
|
72
|
+
cookies: config.cookies,
|
|
73
|
+
ackTimeout: config.ackTimeout,
|
|
74
|
+
timeout: config.timeout,
|
|
75
|
+
asyncTimeout: config.asyncTimeout,
|
|
76
|
+
requestId: config.requestId
|
|
77
|
+
}));
|
|
78
|
+
return config;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Response interceptor: log response success
|
|
82
|
+
client.interceptors.response.use(response => {
|
|
83
|
+
var logData = {
|
|
84
|
+
requestId: response.requestId,
|
|
85
|
+
status: response.status,
|
|
86
|
+
statusText: response.statusText,
|
|
87
|
+
headers: response.headers
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Check if response.data is a File or Blob
|
|
91
|
+
if (response.data instanceof File || response.data instanceof Blob) {
|
|
92
|
+
var file = response.data;
|
|
93
|
+
var fileName = file instanceof File ? file.name : undefined;
|
|
94
|
+
var mimeType = file.type || undefined;
|
|
95
|
+
var contentLength = file.size;
|
|
96
|
+
logData.fileData = {
|
|
97
|
+
fileName,
|
|
98
|
+
mimeType,
|
|
99
|
+
contentLength
|
|
100
|
+
};
|
|
101
|
+
log('info', Messages.DEBUG_CLIENT_REQUEST_SUCCESS_FILE, formatMessageData(logData));
|
|
102
|
+
} else if (response.stream) {
|
|
103
|
+
logData.stream = {
|
|
104
|
+
streamId: response.stream.streamId,
|
|
105
|
+
type: response.stream.type
|
|
106
|
+
};
|
|
107
|
+
log('info', Messages.DEBUG_CLIENT_REQUEST_SUCCESS_STREAM, formatMessageData(logData));
|
|
108
|
+
} else {
|
|
109
|
+
logData.data = response.data;
|
|
110
|
+
log('info', Messages.DEBUG_CLIENT_REQUEST_SUCCESS, formatMessageData(logData));
|
|
111
|
+
}
|
|
112
|
+
return response;
|
|
113
|
+
}, error => {
|
|
114
|
+
log('error', Messages.DEBUG_CLIENT_REQUEST_FAILED, formatMessageData({
|
|
115
|
+
requestId: error.requestId,
|
|
116
|
+
code: error.code,
|
|
117
|
+
message: error.message,
|
|
118
|
+
config: error.config,
|
|
119
|
+
response: error.response
|
|
120
|
+
}));
|
|
121
|
+
return Promise.reject(error);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Hook into client's internal message handling via server's message dispatcher
|
|
125
|
+
// This requires accessing internal properties, so we use type assertion
|
|
126
|
+
var clientImpl = client;
|
|
127
|
+
if (clientImpl.server && clientImpl.server.messageDispatcher) {
|
|
128
|
+
setupClientMessageDebugging(clientImpl);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Setup message-level debugging for client
|
|
134
|
+
*/
|
|
135
|
+
function setupClientMessageDebugging(clientImpl) {
|
|
136
|
+
var _server$_registerPend, _server$messageDispat;
|
|
137
|
+
var server = clientImpl.server;
|
|
138
|
+
|
|
139
|
+
// Store original _registerPendingRequest
|
|
140
|
+
var originalRegister = (_server$_registerPend = server._registerPendingRequest) === null || _server$_registerPend === void 0 ? void 0 : _server$_registerPend.bind(server);
|
|
141
|
+
if (originalRegister) {
|
|
142
|
+
server._registerPendingRequest = function (requestId, resolve, reject, origin) {
|
|
143
|
+
// Wrap resolve to log incoming messages
|
|
144
|
+
var wrappedResolve = data => {
|
|
145
|
+
if (data.type === MessageType.ACK) {
|
|
146
|
+
log('info', Messages.DEBUG_CLIENT_RECEIVED_ACK, formatMessageData({
|
|
147
|
+
requestId: data.requestId,
|
|
148
|
+
path: data.path
|
|
149
|
+
}));
|
|
150
|
+
} else if (data.type === MessageType.ASYNC) {
|
|
151
|
+
log('info', Messages.DEBUG_CLIENT_RECEIVED_ASYNC, formatMessageData({
|
|
152
|
+
requestId: data.requestId,
|
|
153
|
+
path: data.path
|
|
154
|
+
}));
|
|
155
|
+
} else if (data.type === MessageType.STREAM_START) {
|
|
156
|
+
var streamBody = data.body;
|
|
157
|
+
log('info', Messages.DEBUG_CLIENT_RECEIVED_STREAM_START, formatMessageData({
|
|
158
|
+
requestId: data.requestId,
|
|
159
|
+
streamId: streamBody === null || streamBody === void 0 ? void 0 : streamBody.streamId,
|
|
160
|
+
streamType: streamBody === null || streamBody === void 0 ? void 0 : streamBody.type,
|
|
161
|
+
chunked: streamBody === null || streamBody === void 0 ? void 0 : streamBody.chunked,
|
|
162
|
+
autoResolve: streamBody === null || streamBody === void 0 ? void 0 : streamBody.autoResolve,
|
|
163
|
+
metadata: streamBody === null || streamBody === void 0 ? void 0 : streamBody.metadata
|
|
164
|
+
}));
|
|
165
|
+
} else if (data.type === MessageType.STREAM_DATA) {
|
|
166
|
+
var _streamBody$data;
|
|
167
|
+
var _streamBody = data.body;
|
|
168
|
+
log('info', Messages.DEBUG_CLIENT_RECEIVED_STREAM_DATA, formatMessageData({
|
|
169
|
+
requestId: data.requestId,
|
|
170
|
+
streamId: _streamBody === null || _streamBody === void 0 ? void 0 : _streamBody.streamId,
|
|
171
|
+
done: _streamBody === null || _streamBody === void 0 ? void 0 : _streamBody.done,
|
|
172
|
+
dataLength: (_streamBody === null || _streamBody === void 0 || (_streamBody$data = _streamBody.data) === null || _streamBody$data === void 0 ? void 0 : _streamBody$data.length) || 0
|
|
173
|
+
}));
|
|
174
|
+
} else if (data.type === MessageType.STREAM_END) {
|
|
175
|
+
var _streamBody2 = data.body;
|
|
176
|
+
log('info', Messages.DEBUG_CLIENT_RECEIVED_STREAM_END, formatMessageData({
|
|
177
|
+
requestId: data.requestId,
|
|
178
|
+
streamId: _streamBody2 === null || _streamBody2 === void 0 ? void 0 : _streamBody2.streamId
|
|
179
|
+
}));
|
|
180
|
+
} else if (data.type === MessageType.RESPONSE) {
|
|
181
|
+
log('info', Messages.DEBUG_CLIENT_RECEIVED_RESPONSE, formatMessageData({
|
|
182
|
+
requestId: data.requestId,
|
|
183
|
+
status: data.status,
|
|
184
|
+
statusText: data.statusText,
|
|
185
|
+
requireAck: data.requireAck
|
|
186
|
+
}));
|
|
187
|
+
} else if (data.type === MessageType.ERROR) {
|
|
188
|
+
log('error', Messages.DEBUG_CLIENT_RECEIVED_ERROR, formatMessageData({
|
|
189
|
+
requestId: data.requestId,
|
|
190
|
+
status: data.status,
|
|
191
|
+
statusText: data.statusText,
|
|
192
|
+
error: data.error
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
resolve(data);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// Wrap reject to log timeouts
|
|
199
|
+
var wrappedReject = () => {
|
|
200
|
+
log('warn', Messages.DEBUG_CLIENT_REQUEST_TIMEOUT, {
|
|
201
|
+
requestId,
|
|
202
|
+
origin
|
|
203
|
+
});
|
|
204
|
+
reject();
|
|
205
|
+
};
|
|
206
|
+
return originalRegister(requestId, wrappedResolve, wrappedReject, origin);
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Log when messages are sent
|
|
211
|
+
var originalSendMessage = (_server$messageDispat = server.messageDispatcher) === null || _server$messageDispat === void 0 || (_server$messageDispat = _server$messageDispat.sendMessage) === null || _server$messageDispat === void 0 ? void 0 : _server$messageDispat.bind(server.messageDispatcher);
|
|
212
|
+
if (originalSendMessage) {
|
|
213
|
+
server.messageDispatcher.sendMessage = function (target, targetOrigin, type, requestId, data) {
|
|
214
|
+
if (type === MessageType.REQUEST) {
|
|
215
|
+
log('info', Messages.DEBUG_CLIENT_SENDING_REQUEST, formatMessageData({
|
|
216
|
+
requestId,
|
|
217
|
+
path: data === null || data === void 0 ? void 0 : data.path,
|
|
218
|
+
body: data === null || data === void 0 ? void 0 : data.body,
|
|
219
|
+
headers: data === null || data === void 0 ? void 0 : data.headers
|
|
220
|
+
}));
|
|
221
|
+
} else if (type === MessageType.PING) {
|
|
222
|
+
log('info', Messages.DEBUG_CLIENT_SENDING_PING, {
|
|
223
|
+
requestId
|
|
224
|
+
});
|
|
225
|
+
} else if (type === MessageType.RECEIVED) {
|
|
226
|
+
log('info', Messages.DEBUG_CLIENT_SENDING_RECEIVED_ACK, {
|
|
227
|
+
requestId
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return originalSendMessage(target, targetOrigin, type, requestId, data);
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Register debug listeners for server
|
|
237
|
+
* Use middleware to log requests and responses
|
|
238
|
+
*/
|
|
239
|
+
export function setupServerDebugListeners(server) {
|
|
240
|
+
var serverImpl = server;
|
|
241
|
+
var startTimes = new Map();
|
|
242
|
+
|
|
243
|
+
// Use global middleware to log requests
|
|
244
|
+
server.use((req, res, next) => {
|
|
245
|
+
var _res$sendStream;
|
|
246
|
+
var startTime = Date.now();
|
|
247
|
+
startTimes.set(req.requestId, startTime);
|
|
248
|
+
log('info', Messages.DEBUG_SERVER_RECEIVED_REQUEST, formatMessageData({
|
|
249
|
+
requestId: req.requestId,
|
|
250
|
+
path: req.path,
|
|
251
|
+
body: req.body,
|
|
252
|
+
origin: req.origin,
|
|
253
|
+
headers: req.headers,
|
|
254
|
+
cookies: req.cookies,
|
|
255
|
+
method: 'POST' // iframe requests are always POST-like
|
|
256
|
+
}));
|
|
257
|
+
|
|
258
|
+
// Store original send methods
|
|
259
|
+
var originalSend = res.send.bind(res);
|
|
260
|
+
var originalJson = res.json.bind(res);
|
|
261
|
+
var originalSendFile = res.sendFile.bind(res);
|
|
262
|
+
var originalSendStream = (_res$sendStream = res.sendStream) === null || _res$sendStream === void 0 ? void 0 : _res$sendStream.bind(res);
|
|
263
|
+
var originalStatus = res.status.bind(res);
|
|
264
|
+
var originalSetHeader = res.setHeader.bind(res);
|
|
265
|
+
|
|
266
|
+
// Track status code changes
|
|
267
|
+
res.status = function (code) {
|
|
268
|
+
log('info', Messages.DEBUG_SERVER_SETTING_STATUS_CODE, {
|
|
269
|
+
requestId: req.requestId,
|
|
270
|
+
path: req.path,
|
|
271
|
+
statusCode: code
|
|
272
|
+
});
|
|
273
|
+
return originalStatus(code);
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// Track header changes
|
|
277
|
+
res.setHeader = function (name, value) {
|
|
278
|
+
log('info', Messages.DEBUG_SERVER_SETTING_HEADER, {
|
|
279
|
+
requestId: req.requestId,
|
|
280
|
+
path: req.path,
|
|
281
|
+
header: name,
|
|
282
|
+
value: Array.isArray(value) ? value.join(', ') : String(value)
|
|
283
|
+
});
|
|
284
|
+
return originalSetHeader(name, value);
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// Override send method
|
|
288
|
+
res.send = /*#__PURE__*/function () {
|
|
289
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(data, options) {
|
|
290
|
+
var duration;
|
|
291
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
292
|
+
while (1) switch (_context.prev = _context.next) {
|
|
293
|
+
case 0:
|
|
294
|
+
duration = Date.now() - (startTimes.get(req.requestId) || startTime);
|
|
295
|
+
startTimes.delete(req.requestId);
|
|
296
|
+
log('info', Messages.DEBUG_SERVER_SENDING_RESPONSE, formatMessageData({
|
|
297
|
+
requestId: req.requestId,
|
|
298
|
+
path: req.path,
|
|
299
|
+
status: res.statusCode,
|
|
300
|
+
statusText: getStatusText(res.statusCode),
|
|
301
|
+
requireAck: options === null || options === void 0 ? void 0 : options.requireAck,
|
|
302
|
+
headers: res.headers,
|
|
303
|
+
data,
|
|
304
|
+
duration: `${duration}ms`
|
|
305
|
+
}));
|
|
306
|
+
return _context.abrupt("return", originalSend(data, options));
|
|
307
|
+
case 1:
|
|
308
|
+
case "end":
|
|
309
|
+
return _context.stop();
|
|
310
|
+
}
|
|
311
|
+
}, _callee);
|
|
312
|
+
}));
|
|
313
|
+
return function (_x, _x2) {
|
|
314
|
+
return _ref.apply(this, arguments);
|
|
315
|
+
};
|
|
316
|
+
}();
|
|
317
|
+
|
|
318
|
+
// Override json method
|
|
319
|
+
res.json = /*#__PURE__*/function () {
|
|
320
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(data, options) {
|
|
321
|
+
var duration;
|
|
322
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
323
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
324
|
+
case 0:
|
|
325
|
+
duration = Date.now() - (startTimes.get(req.requestId) || startTime);
|
|
326
|
+
startTimes.delete(req.requestId);
|
|
327
|
+
log('info', Messages.DEBUG_SERVER_SENDING_JSON_RESPONSE, formatMessageData({
|
|
328
|
+
requestId: req.requestId,
|
|
329
|
+
path: req.path,
|
|
330
|
+
status: res.statusCode,
|
|
331
|
+
statusText: getStatusText(res.statusCode),
|
|
332
|
+
requireAck: options === null || options === void 0 ? void 0 : options.requireAck,
|
|
333
|
+
headers: res.headers,
|
|
334
|
+
data,
|
|
335
|
+
duration: `${duration}ms`
|
|
336
|
+
}));
|
|
337
|
+
return _context2.abrupt("return", originalJson(data, options));
|
|
338
|
+
case 1:
|
|
339
|
+
case "end":
|
|
340
|
+
return _context2.stop();
|
|
341
|
+
}
|
|
342
|
+
}, _callee2);
|
|
343
|
+
}));
|
|
344
|
+
return function (_x3, _x4) {
|
|
345
|
+
return _ref2.apply(this, arguments);
|
|
346
|
+
};
|
|
347
|
+
}();
|
|
348
|
+
|
|
349
|
+
// Override sendFile method
|
|
350
|
+
res.sendFile = /*#__PURE__*/function () {
|
|
351
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(content, options) {
|
|
352
|
+
var duration;
|
|
353
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
354
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
355
|
+
case 0:
|
|
356
|
+
duration = Date.now() - (startTimes.get(req.requestId) || startTime);
|
|
357
|
+
startTimes.delete(req.requestId);
|
|
358
|
+
log('info', Messages.DEBUG_SERVER_SENDING_FILE, formatMessageData({
|
|
359
|
+
requestId: req.requestId,
|
|
360
|
+
path: req.path,
|
|
361
|
+
status: res.statusCode,
|
|
362
|
+
statusText: getStatusText(res.statusCode),
|
|
363
|
+
fileName: options === null || options === void 0 ? void 0 : options.fileName,
|
|
364
|
+
mimeType: options === null || options === void 0 ? void 0 : options.mimeType,
|
|
365
|
+
contentLength: typeof content === 'string' ? content.length : (content === null || content === void 0 ? void 0 : content.size) || 0,
|
|
366
|
+
duration: `${duration}ms`
|
|
367
|
+
}));
|
|
368
|
+
return _context3.abrupt("return", originalSendFile(content, options));
|
|
369
|
+
case 1:
|
|
370
|
+
case "end":
|
|
371
|
+
return _context3.stop();
|
|
372
|
+
}
|
|
373
|
+
}, _callee3);
|
|
374
|
+
}));
|
|
375
|
+
return function (_x5, _x6) {
|
|
376
|
+
return _ref3.apply(this, arguments);
|
|
377
|
+
};
|
|
378
|
+
}();
|
|
379
|
+
|
|
380
|
+
// Override sendStream method if exists
|
|
381
|
+
if (originalSendStream) {
|
|
382
|
+
res.sendStream = /*#__PURE__*/function () {
|
|
383
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(stream) {
|
|
384
|
+
var duration;
|
|
385
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
386
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
387
|
+
case 0:
|
|
388
|
+
duration = Date.now() - (startTimes.get(req.requestId) || startTime);
|
|
389
|
+
startTimes.delete(req.requestId);
|
|
390
|
+
log('info', Messages.DEBUG_SERVER_SENDING_STREAM, formatMessageData({
|
|
391
|
+
requestId: req.requestId,
|
|
392
|
+
path: req.path,
|
|
393
|
+
status: res.statusCode,
|
|
394
|
+
statusText: getStatusText(res.statusCode),
|
|
395
|
+
streamId: stream === null || stream === void 0 ? void 0 : stream.streamId,
|
|
396
|
+
duration: `${duration}ms`
|
|
397
|
+
}));
|
|
398
|
+
return _context4.abrupt("return", originalSendStream(stream));
|
|
399
|
+
case 1:
|
|
400
|
+
case "end":
|
|
401
|
+
return _context4.stop();
|
|
402
|
+
}
|
|
403
|
+
}, _callee4);
|
|
404
|
+
}));
|
|
405
|
+
return function (_x7) {
|
|
406
|
+
return _ref4.apply(this, arguments);
|
|
407
|
+
};
|
|
408
|
+
}();
|
|
409
|
+
}
|
|
410
|
+
next();
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// Hook into server's message dispatcher for more detailed logging
|
|
414
|
+
if (serverImpl.messageDispatcher) {
|
|
415
|
+
setupServerMessageDebugging(serverImpl);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Setup message-level debugging for server
|
|
421
|
+
*/
|
|
422
|
+
function setupServerMessageDebugging(serverImpl) {
|
|
423
|
+
var _dispatcher$sendMessa, _serverImpl$handleReq, _serverImpl$runMiddle;
|
|
424
|
+
var dispatcher = serverImpl.messageDispatcher;
|
|
425
|
+
|
|
426
|
+
// Log when messages are sent
|
|
427
|
+
var originalSendMessage = (_dispatcher$sendMessa = dispatcher.sendMessage) === null || _dispatcher$sendMessa === void 0 ? void 0 : _dispatcher$sendMessa.bind(dispatcher);
|
|
428
|
+
if (originalSendMessage) {
|
|
429
|
+
dispatcher.sendMessage = function (target, targetOrigin, type, requestId, data) {
|
|
430
|
+
if (type === MessageType.ACK) {
|
|
431
|
+
log('info', Messages.DEBUG_SERVER_SENDING_ACK, formatMessageData({
|
|
432
|
+
requestId,
|
|
433
|
+
path: data === null || data === void 0 ? void 0 : data.path
|
|
434
|
+
}));
|
|
435
|
+
} else if (type === MessageType.ASYNC) {
|
|
436
|
+
log('info', Messages.DEBUG_SERVER_SENDING_ASYNC, formatMessageData({
|
|
437
|
+
requestId,
|
|
438
|
+
path: data === null || data === void 0 ? void 0 : data.path
|
|
439
|
+
}));
|
|
440
|
+
} else if (type === MessageType.STREAM_START) {
|
|
441
|
+
var streamBody = (data === null || data === void 0 ? void 0 : data.body) || {};
|
|
442
|
+
log('info', Messages.DEBUG_SERVER_SENDING_STREAM_START, formatMessageData({
|
|
443
|
+
requestId,
|
|
444
|
+
streamId: streamBody.streamId,
|
|
445
|
+
streamType: streamBody.type,
|
|
446
|
+
chunked: streamBody.chunked,
|
|
447
|
+
autoResolve: streamBody.autoResolve,
|
|
448
|
+
metadata: streamBody.metadata
|
|
449
|
+
}));
|
|
450
|
+
} else if (type === MessageType.STREAM_DATA) {
|
|
451
|
+
var _streamBody3$data;
|
|
452
|
+
var _streamBody3 = (data === null || data === void 0 ? void 0 : data.body) || {};
|
|
453
|
+
log('info', Messages.DEBUG_SERVER_SENDING_STREAM_DATA, formatMessageData({
|
|
454
|
+
requestId,
|
|
455
|
+
streamId: _streamBody3.streamId,
|
|
456
|
+
done: _streamBody3.done,
|
|
457
|
+
dataLength: ((_streamBody3$data = _streamBody3.data) === null || _streamBody3$data === void 0 ? void 0 : _streamBody3$data.length) || 0
|
|
458
|
+
}));
|
|
459
|
+
} else if (type === MessageType.STREAM_END) {
|
|
460
|
+
var _streamBody4 = (data === null || data === void 0 ? void 0 : data.body) || {};
|
|
461
|
+
log('info', Messages.DEBUG_SERVER_SENDING_STREAM_END, formatMessageData({
|
|
462
|
+
requestId,
|
|
463
|
+
streamId: _streamBody4.streamId
|
|
464
|
+
}));
|
|
465
|
+
} else if (type === MessageType.ERROR) {
|
|
466
|
+
log('error', Messages.DEBUG_SERVER_SENDING_ERROR, formatMessageData({
|
|
467
|
+
requestId,
|
|
468
|
+
status: data === null || data === void 0 ? void 0 : data.status,
|
|
469
|
+
statusText: data === null || data === void 0 ? void 0 : data.statusText,
|
|
470
|
+
error: data === null || data === void 0 ? void 0 : data.error,
|
|
471
|
+
path: data === null || data === void 0 ? void 0 : data.path
|
|
472
|
+
}));
|
|
473
|
+
} else if (type === MessageType.RESPONSE) {
|
|
474
|
+
log('info', Messages.DEBUG_SERVER_SENDING_RESPONSE_VIA_DISPATCHER, formatMessageData({
|
|
475
|
+
requestId,
|
|
476
|
+
status: data === null || data === void 0 ? void 0 : data.status,
|
|
477
|
+
statusText: data === null || data === void 0 ? void 0 : data.statusText,
|
|
478
|
+
requireAck: data === null || data === void 0 ? void 0 : data.requireAck,
|
|
479
|
+
path: data === null || data === void 0 ? void 0 : data.path
|
|
480
|
+
}));
|
|
481
|
+
}
|
|
482
|
+
return originalSendMessage(target, targetOrigin, type, requestId, data);
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Log when requests are received (before handler)
|
|
487
|
+
var originalHandleRequest = (_serverImpl$handleReq = serverImpl.handleRequest) === null || _serverImpl$handleReq === void 0 ? void 0 : _serverImpl$handleReq.bind(serverImpl);
|
|
488
|
+
if (originalHandleRequest) {
|
|
489
|
+
serverImpl.handleRequest = function (data, context) {
|
|
490
|
+
log('info', Messages.DEBUG_SERVER_HANDLING_REQUEST, formatMessageData({
|
|
491
|
+
requestId: data.requestId,
|
|
492
|
+
path: data.path,
|
|
493
|
+
origin: context === null || context === void 0 ? void 0 : context.origin,
|
|
494
|
+
role: data.role,
|
|
495
|
+
creatorId: data.creatorId
|
|
496
|
+
}));
|
|
497
|
+
return originalHandleRequest(data, context);
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// Log handler execution
|
|
502
|
+
var originalRunMiddlewares = (_serverImpl$runMiddle = serverImpl.runMiddlewares) === null || _serverImpl$runMiddle === void 0 ? void 0 : _serverImpl$runMiddle.bind(serverImpl);
|
|
503
|
+
if (originalRunMiddlewares) {
|
|
504
|
+
serverImpl.runMiddlewares = function (req, res, callback) {
|
|
505
|
+
var handlerStartTime = Date.now();
|
|
506
|
+
log('info', Messages.DEBUG_SERVER_EXECUTING_MIDDLEWARE_CHAIN, {
|
|
507
|
+
requestId: req.requestId,
|
|
508
|
+
path: req.path
|
|
509
|
+
});
|
|
510
|
+
return originalRunMiddlewares(req, res, () => {
|
|
511
|
+
var handlerDuration = Date.now() - handlerStartTime;
|
|
512
|
+
log('info', Messages.DEBUG_SERVER_MIDDLEWARE_CHAIN_COMPLETED, {
|
|
513
|
+
requestId: req.requestId,
|
|
514
|
+
path: req.path,
|
|
515
|
+
duration: `${handlerDuration}ms`
|
|
516
|
+
});
|
|
517
|
+
callback();
|
|
518
|
+
});
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Error class for request-iframe errors
|
|
3
|
+
* Extends native Error with additional error response fields
|
|
4
|
+
*/
|
|
5
|
+
export class RequestIframeError extends Error {
|
|
6
|
+
/** Error code */
|
|
7
|
+
|
|
8
|
+
/** Request configuration */
|
|
9
|
+
|
|
10
|
+
/** Response data (if available) */
|
|
11
|
+
|
|
12
|
+
/** Request ID */
|
|
13
|
+
|
|
14
|
+
constructor(error) {
|
|
15
|
+
super(error.message);
|
|
16
|
+
this.name = 'RequestIframeError';
|
|
17
|
+
this.code = error.code;
|
|
18
|
+
this.config = error.config;
|
|
19
|
+
this.response = error.response;
|
|
20
|
+
this.requestId = error.requestId;
|
|
21
|
+
|
|
22
|
+
// Maintain proper stack trace for where our error was thrown (only available on V8)
|
|
23
|
+
if (Error.captureStackTrace) {
|
|
24
|
+
Error.captureStackTrace(this, RequestIframeError);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|