request-iframe 0.0.1 → 0.0.3
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 +271 -12
- package/README.md +268 -11
- package/library/__tests__/channel.test.ts +420 -0
- package/library/__tests__/debug.test.ts +588 -0
- package/library/__tests__/dispatcher.test.ts +481 -0
- package/library/__tests__/interceptors.test.ts +22 -0
- package/library/__tests__/requestIframe.test.ts +2317 -99
- package/library/__tests__/server.test.ts +738 -0
- package/library/api/client.d.js +5 -0
- package/library/api/client.d.ts.map +1 -1
- package/library/api/client.js +11 -6
- package/library/api/server.d.js +5 -0
- package/library/api/server.d.ts +4 -3
- package/library/api/server.d.ts.map +1 -1
- package/library/api/server.js +25 -7
- package/library/constants/index.d.js +36 -0
- package/library/constants/index.d.ts +14 -4
- package/library/constants/index.d.ts.map +1 -1
- package/library/constants/index.js +15 -7
- package/library/constants/messages.d.js +5 -0
- package/library/constants/messages.d.ts +35 -0
- package/library/constants/messages.d.ts.map +1 -1
- package/library/constants/messages.js +36 -1
- package/library/core/client-server.d.ts +101 -0
- package/library/core/client-server.d.ts.map +1 -0
- package/library/core/client-server.js +266 -0
- package/library/core/client.d.js +5 -0
- package/library/core/client.d.ts +38 -6
- package/library/core/client.d.ts.map +1 -1
- package/library/core/client.js +198 -24
- package/library/core/request.d.js +5 -0
- package/library/core/response.d.js +5 -0
- package/library/core/response.d.ts +5 -1
- package/library/core/response.d.ts.map +1 -1
- package/library/core/response.js +85 -70
- package/library/core/server-client.d.js +5 -0
- package/library/core/server-client.d.ts +3 -1
- package/library/core/server-client.d.ts.map +1 -1
- package/library/core/server-client.js +19 -9
- package/library/core/server.d.js +5 -0
- package/library/core/server.d.ts +11 -3
- package/library/core/server.d.ts.map +1 -1
- package/library/core/server.js +112 -54
- package/library/index.d.ts +1 -1
- package/library/index.js +2 -2
- package/library/interceptors/index.d.js +5 -0
- package/library/interceptors/index.d.ts +4 -0
- package/library/interceptors/index.d.ts.map +1 -1
- package/library/interceptors/index.js +7 -0
- package/library/message/channel.d.js +5 -0
- package/library/message/channel.d.ts +3 -1
- package/library/message/channel.d.ts.map +1 -1
- package/library/message/dispatcher.d.js +5 -0
- package/library/message/dispatcher.d.ts +7 -2
- package/library/message/dispatcher.d.ts.map +1 -1
- package/library/message/dispatcher.js +47 -2
- package/library/message/index.d.js +25 -0
- package/library/stream/file-stream.d.js +4 -0
- package/library/stream/file-stream.d.ts +5 -0
- package/library/stream/file-stream.d.ts.map +1 -1
- package/library/stream/file-stream.js +41 -12
- package/library/stream/index.d.js +58 -0
- package/library/stream/readable-stream.d.js +5 -0
- package/library/stream/readable-stream.d.ts.map +1 -1
- package/library/stream/readable-stream.js +32 -30
- package/library/stream/types.d.js +5 -0
- package/library/stream/types.d.ts +18 -0
- package/library/stream/types.d.ts.map +1 -1
- package/library/stream/writable-stream.d.js +5 -0
- package/library/stream/writable-stream.d.ts +1 -0
- package/library/stream/writable-stream.d.ts.map +1 -1
- package/library/stream/writable-stream.js +7 -2
- package/library/types/index.d.js +5 -0
- package/library/types/index.d.ts +79 -19
- package/library/types/index.d.ts.map +1 -1
- package/library/utils/cache.d.js +5 -0
- package/library/utils/cache.d.ts +24 -0
- package/library/utils/cache.d.ts.map +1 -1
- package/library/utils/cache.js +76 -0
- package/library/utils/cookie.d.js +5 -0
- package/library/utils/debug.d.js +5 -0
- package/library/utils/debug.d.ts.map +1 -1
- package/library/utils/debug.js +382 -20
- package/library/utils/index.d.js +94 -0
- package/library/utils/index.d.ts +5 -0
- package/library/utils/index.d.ts.map +1 -1
- package/library/utils/index.js +14 -1
- package/library/utils/path-match.d.js +5 -0
- package/library/utils/protocol.d.js +5 -0
- package/package.json +16 -2
- package/react/library/__tests__/index.test.d.ts +2 -0
- package/react/library/__tests__/index.test.d.ts.map +1 -0
- package/react/library/__tests__/index.test.tsx +770 -0
- package/react/library/index.d.ts +118 -0
- package/react/library/index.d.ts.map +1 -0
- package/react/library/index.js +232 -0
package/library/core/server.js
CHANGED
|
@@ -38,6 +38,7 @@ var _constants = require("../constants");
|
|
|
38
38
|
class RequestIframeServerImpl {
|
|
39
39
|
constructor(options) {
|
|
40
40
|
var _options$ackTimeout, _options$versionValid;
|
|
41
|
+
/** Unique instance ID */
|
|
41
42
|
(0, _defineProperty2.default)(this, "handlers", new Map());
|
|
42
43
|
(0, _defineProperty2.default)(this, "middlewares", []);
|
|
43
44
|
/** Responses waiting for client acknowledgment */
|
|
@@ -46,15 +47,19 @@ class RequestIframeServerImpl {
|
|
|
46
47
|
(0, _defineProperty2.default)(this, "unregisterFns", []);
|
|
47
48
|
/** Whether it is open */
|
|
48
49
|
(0, _defineProperty2.default)(this, "_isOpen", false);
|
|
49
|
-
|
|
50
|
+
// Use custom id if provided, otherwise generate one
|
|
51
|
+
this.id = (options === null || options === void 0 ? void 0 : options.id) || (0, _utils.generateInstanceId)();
|
|
52
|
+
this.ackTimeout = (_options$ackTimeout = options === null || options === void 0 ? void 0 : options.ackTimeout) !== null && _options$ackTimeout !== void 0 ? _options$ackTimeout : _constants.DefaultTimeout.ACK;
|
|
50
53
|
this.versionValidator = (_options$versionValid = options === null || options === void 0 ? void 0 : options.versionValidator) !== null && _options$versionValid !== void 0 ? _options$versionValid : _utils.isCompatibleVersion;
|
|
51
54
|
|
|
52
55
|
// Get or create shared channel and create dispatcher
|
|
53
56
|
var channel = (0, _cache.getOrCreateMessageChannel)(options === null || options === void 0 ? void 0 : options.secretKey);
|
|
54
|
-
this.dispatcher = new _message.MessageDispatcher(channel);
|
|
57
|
+
this.dispatcher = new _message.MessageDispatcher(channel, _constants.MessageRole.SERVER, this.id);
|
|
55
58
|
|
|
56
|
-
// Auto-open by default
|
|
57
|
-
|
|
59
|
+
// Auto-open by default (unless explicitly set to false)
|
|
60
|
+
if ((options === null || options === void 0 ? void 0 : options.autoOpen) !== false) {
|
|
61
|
+
this.open();
|
|
62
|
+
}
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
/**
|
|
@@ -151,22 +156,69 @@ class RequestIframeServerImpl {
|
|
|
151
156
|
get messageDispatcher() {
|
|
152
157
|
return this.dispatcher;
|
|
153
158
|
}
|
|
159
|
+
handleRequestError(res, targetWindow, targetOrigin, data, err) {
|
|
160
|
+
if (!res._sent) {
|
|
161
|
+
/**
|
|
162
|
+
* Use INTERNAL_SERVER_ERROR (500) for handler errors unless a different error status code was explicitly set.
|
|
163
|
+
* If statusCode is still the default OK (200), override it to INTERNAL_SERVER_ERROR.
|
|
164
|
+
*/
|
|
165
|
+
var errorStatus = res.statusCode === _constants.HttpStatus.OK ? _constants.HttpStatus.INTERNAL_SERVER_ERROR : res.statusCode;
|
|
166
|
+
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ERROR, data.requestId, {
|
|
167
|
+
path: data.path,
|
|
168
|
+
error: {
|
|
169
|
+
message: err && err.message || _constants.Messages.REQUEST_FAILED,
|
|
170
|
+
code: err && err.code || _constants.ErrorCode.REQUEST_ERROR
|
|
171
|
+
},
|
|
172
|
+
status: errorStatus,
|
|
173
|
+
statusText: _constants.HttpStatusText[errorStatus] || _constants.HttpStatusText[_constants.HttpStatus.INTERNAL_SERVER_ERROR],
|
|
174
|
+
headers: res.headers,
|
|
175
|
+
targetId: data.creatorId
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
handleRequestResult(res, targetWindow, targetOrigin, data, result) {
|
|
180
|
+
if (!res._sent && result !== undefined) {
|
|
181
|
+
res.send(result);
|
|
182
|
+
} else if (!res._sent) {
|
|
183
|
+
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ERROR, data.requestId, {
|
|
184
|
+
path: data.path,
|
|
185
|
+
error: {
|
|
186
|
+
message: _constants.Messages.NO_RESPONSE_SENT,
|
|
187
|
+
code: _constants.ErrorCode.NO_RESPONSE
|
|
188
|
+
},
|
|
189
|
+
status: _constants.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
190
|
+
statusText: _constants.HttpStatusText[_constants.HttpStatus.INTERNAL_SERVER_ERROR],
|
|
191
|
+
headers: res.headers
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
154
195
|
|
|
155
196
|
/**
|
|
156
197
|
* Handle request
|
|
157
198
|
*/
|
|
158
199
|
handleRequest(data, context) {
|
|
159
|
-
if
|
|
200
|
+
// If targetId is specified, only process if it matches this server's id
|
|
201
|
+
if (!data.path || data.targetId && data.targetId !== this.id) return;
|
|
160
202
|
if (!context.source) return;
|
|
203
|
+
|
|
204
|
+
// If message has already been handled by another server instance, skip processing
|
|
205
|
+
if (context.handledBy) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
161
208
|
var targetWindow = context.source;
|
|
162
209
|
var targetOrigin = context.origin;
|
|
163
210
|
|
|
164
|
-
//
|
|
165
|
-
this.dispatcher.
|
|
166
|
-
|
|
167
|
-
});
|
|
168
|
-
var handlerFn = this.handlers.get(data.path);
|
|
211
|
+
// Use prefixed path to match registered handlers
|
|
212
|
+
var prefixedPath = this.dispatcher.prefixPath(data.path);
|
|
213
|
+
var handlerFn = this.handlers.get(prefixedPath);
|
|
169
214
|
if (!handlerFn) {
|
|
215
|
+
// No handler found in this instance
|
|
216
|
+
// Mark as handled by this instance (using special marker) to prevent other instances from processing
|
|
217
|
+
// This ensures only one instance sends the error response
|
|
218
|
+
context.handledBy = this.id;
|
|
219
|
+
|
|
220
|
+
// Send METHOD_NOT_FOUND error
|
|
221
|
+
// Use request's creatorId as targetId to route back to the correct client
|
|
170
222
|
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ERROR, data.requestId, {
|
|
171
223
|
path: data.path,
|
|
172
224
|
error: {
|
|
@@ -174,13 +226,25 @@ class RequestIframeServerImpl {
|
|
|
174
226
|
code: _constants.ErrorCode.METHOD_NOT_FOUND
|
|
175
227
|
},
|
|
176
228
|
status: _constants.HttpStatus.NOT_FOUND,
|
|
177
|
-
statusText: _constants.HttpStatusText[_constants.HttpStatus.NOT_FOUND]
|
|
229
|
+
statusText: _constants.HttpStatusText[_constants.HttpStatus.NOT_FOUND],
|
|
230
|
+
targetId: data.creatorId
|
|
178
231
|
});
|
|
179
232
|
return;
|
|
180
233
|
}
|
|
181
234
|
|
|
235
|
+
// Mark message as handled by this server instance to prevent other server instances from processing it
|
|
236
|
+
context.handledBy = this.id;
|
|
237
|
+
|
|
238
|
+
// Send ACK immediately via dispatcher
|
|
239
|
+
// Use request's creatorId as targetId to route back to the correct client
|
|
240
|
+
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ACK, data.requestId, {
|
|
241
|
+
path: data.path,
|
|
242
|
+
targetId: data.creatorId
|
|
243
|
+
});
|
|
244
|
+
|
|
182
245
|
// Create response object with channel reference
|
|
183
|
-
|
|
246
|
+
// Pass request's creatorId as targetId so responses are routed back to the correct client
|
|
247
|
+
var res = new _response.ServerResponseImpl(data.requestId, data.path || '', data.secretKey, targetWindow, targetOrigin, this.dispatcher.getChannel(), this.id, data.creatorId);
|
|
184
248
|
|
|
185
249
|
// Register callback waiting for client acknowledgment
|
|
186
250
|
this.registerPendingAck(data.requestId, received => {
|
|
@@ -194,46 +258,22 @@ class RequestIframeServerImpl {
|
|
|
194
258
|
|
|
195
259
|
// Execute middleware chain
|
|
196
260
|
this.runMiddlewares(req, res, () => {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
message: _constants.Messages.NO_RESPONSE_SENT,
|
|
211
|
-
code: _constants.ErrorCode.NO_RESPONSE
|
|
212
|
-
},
|
|
213
|
-
status: _constants.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
214
|
-
statusText: _constants.HttpStatusText[_constants.HttpStatus.INTERNAL_SERVER_ERROR],
|
|
215
|
-
headers: res.headers
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
}).catch(err => {
|
|
219
|
-
if (!res._sent) {
|
|
220
|
-
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ERROR, data.requestId, {
|
|
221
|
-
path: data.path,
|
|
222
|
-
error: {
|
|
223
|
-
message: err && err.message || _constants.Messages.REQUEST_FAILED,
|
|
224
|
-
code: err && err.code || _constants.ErrorCode.REQUEST_ERROR
|
|
225
|
-
},
|
|
226
|
-
status: res.statusCode || _constants.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
227
|
-
statusText: _constants.HttpStatusText[_constants.HttpStatus.INTERNAL_SERVER_ERROR],
|
|
228
|
-
headers: res.headers
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
} else {
|
|
233
|
-
// Synchronous processing
|
|
234
|
-
if (!res._sent && result !== undefined) {
|
|
235
|
-
res.send(result);
|
|
261
|
+
try {
|
|
262
|
+
var result = handlerFn(req, res);
|
|
263
|
+
if ((0, _utils.isPromise)(result)) {
|
|
264
|
+
// Async task
|
|
265
|
+
// Use request's creatorId as targetId to route back to the correct client
|
|
266
|
+
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ASYNC, data.requestId, {
|
|
267
|
+
path: data.path,
|
|
268
|
+
targetId: data.creatorId
|
|
269
|
+
});
|
|
270
|
+
result.then(this.handleRequestResult.bind(this, res, targetWindow, targetOrigin, data)).catch(this.handleRequestError.bind(this, res, targetWindow, targetOrigin, data));
|
|
271
|
+
} else {
|
|
272
|
+
// Synchronous processing
|
|
273
|
+
this.handleRequestResult(res, targetWindow, targetOrigin, data, result);
|
|
236
274
|
}
|
|
275
|
+
} catch (error) {
|
|
276
|
+
this.handleRequestError(res, targetWindow, targetOrigin, data, error);
|
|
237
277
|
}
|
|
238
278
|
});
|
|
239
279
|
}
|
|
@@ -266,7 +306,13 @@ class RequestIframeServerImpl {
|
|
|
266
306
|
}
|
|
267
307
|
}
|
|
268
308
|
on(path, handler) {
|
|
269
|
-
this.
|
|
309
|
+
var prefixedPath = this.dispatcher.prefixPath(path);
|
|
310
|
+
this.handlers.set(prefixedPath, handler);
|
|
311
|
+
|
|
312
|
+
// Return unregister function
|
|
313
|
+
return () => {
|
|
314
|
+
this.handlers.delete(prefixedPath);
|
|
315
|
+
};
|
|
270
316
|
}
|
|
271
317
|
runMiddlewares(req, res, finalHandler) {
|
|
272
318
|
var path = req.path;
|
|
@@ -307,12 +353,24 @@ class RequestIframeServerImpl {
|
|
|
307
353
|
next();
|
|
308
354
|
}
|
|
309
355
|
off(path) {
|
|
310
|
-
|
|
356
|
+
if (Array.isArray(path)) {
|
|
357
|
+
// Batch unregister
|
|
358
|
+
path.forEach(p => {
|
|
359
|
+
this.handlers.delete(this.dispatcher.prefixPath(p));
|
|
360
|
+
});
|
|
361
|
+
} else {
|
|
362
|
+
// Single unregister
|
|
363
|
+
this.handlers.delete(this.dispatcher.prefixPath(path));
|
|
364
|
+
}
|
|
311
365
|
}
|
|
312
366
|
map(handlers) {
|
|
367
|
+
var unregisterFns = [];
|
|
313
368
|
Object.entries(handlers).forEach(([path, h]) => {
|
|
314
|
-
this.on(path, h);
|
|
369
|
+
unregisterFns.push(this.on(path, h));
|
|
315
370
|
});
|
|
371
|
+
return () => {
|
|
372
|
+
unregisterFns.forEach(fn => fn());
|
|
373
|
+
};
|
|
316
374
|
}
|
|
317
375
|
|
|
318
376
|
/**
|
package/library/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { requestIframeClient, clearRequestIframeClientCache } from './api/client
|
|
|
2
2
|
export { requestIframeServer, clearRequestIframeServerCache } from './api/server';
|
|
3
3
|
export { RequestIframeClientImpl } from './core/client';
|
|
4
4
|
export { RequestIframeServerImpl } from './core/server';
|
|
5
|
-
export { RequestIframeClientServer } from './core/server
|
|
5
|
+
export { RequestIframeClientServer } from './core/client-server';
|
|
6
6
|
export { MessageChannel, ChannelType, MessageDispatcher } from './message';
|
|
7
7
|
export type { MessageContext, MessageHandlerFn, MessageTypeMatcher, VersionValidator, HandlerOptions, ChannelType as ChannelTypeValue } from './message';
|
|
8
8
|
export { getOrCreateMessageChannel, releaseMessageChannel, clearMessageChannelCache, } from './utils/cache';
|
package/library/index.js
CHANGED
|
@@ -87,7 +87,7 @@ Object.defineProperty(exports, "RequestIframeClientImpl", {
|
|
|
87
87
|
Object.defineProperty(exports, "RequestIframeClientServer", {
|
|
88
88
|
enumerable: true,
|
|
89
89
|
get: function get() {
|
|
90
|
-
return
|
|
90
|
+
return _clientServer.RequestIframeClientServer;
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
93
|
Object.defineProperty(exports, "RequestIframeServerImpl", {
|
|
@@ -178,7 +178,7 @@ var _client = require("./api/client");
|
|
|
178
178
|
var _server = require("./api/server");
|
|
179
179
|
var _client2 = require("./core/client");
|
|
180
180
|
var _server2 = require("./core/server");
|
|
181
|
-
var
|
|
181
|
+
var _clientServer = require("./core/client-server");
|
|
182
182
|
var _message = require("./message");
|
|
183
183
|
var _cache = require("./utils/cache");
|
|
184
184
|
var _request = require("./core/request");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interceptors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,QAAQ,EACR,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,qBAAa,kBAAkB,CAAC,CAAC;IAC/B,OAAO,CAAC,QAAQ,CAGR;IAER;;OAEG;IACH,GAAG,CACD,SAAS,EAAE,mBAAmB,CAAC,CAAC,CAAC,EACjC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,GAC7B,MAAM;IAKT;;OAEG;IACH,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAMvB;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE;QAAE,SAAS,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC;QAAC,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B,CAAC,aAAa,CAAC;CAAG;AAEnF;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,kBAAkB,CAAC,QAAQ,CAAC;CAAG;AAE/E;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,yBAAyB,EACvC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC,CAgBxB;AAED;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,YAAY,EAAE,0BAA0B,EACxC,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,QAAQ,CAAC,CAgBnB"}
|
|
@@ -7,6 +7,8 @@ export interface MessageContext {
|
|
|
7
7
|
source?: Window;
|
|
8
8
|
/** Origin of the message */
|
|
9
9
|
origin: string;
|
|
10
|
+
/** ID of the instance that handled this message (if handled) */
|
|
11
|
+
handledBy?: string;
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* Message receiver callback
|
|
@@ -94,7 +96,7 @@ export declare class MessageChannel {
|
|
|
94
96
|
* @param requestId request ID
|
|
95
97
|
* @param data additional data
|
|
96
98
|
*/
|
|
97
|
-
sendMessage(target: Window, targetOrigin: string, type: PostMessageData['type'], requestId: string, data?: Partial<Omit<PostMessageData, '__requestIframe__' | 'type' | 'requestId' | 'timestamp'>>): void;
|
|
99
|
+
sendMessage(target: Window, targetOrigin: string, type: PostMessageData['type'], requestId: string, data?: Partial<Omit<PostMessageData, '__requestIframe__' | 'type' | 'requestId' | 'timestamp' | 'role'>>): void;
|
|
98
100
|
/**
|
|
99
101
|
* Add path prefix (for secretKey isolation)
|
|
100
102
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/message/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAChB,MAAM,UAAU,CAAC;AAGlB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4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;OAGG;IACH,OAAO,CAAC,cAAc;IAOtB;;OAEG;IACH,OAAO,CAAC,SAAS;IA4BjB;;;;;OAKG;IACI,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,YAAY,GAAE,MAAY,GAAG,IAAI;IAIvF;;;;;;;OAOG;IACI,WAAW,CAChB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,EAC7B,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,mBAAmB,GAAG,MAAM,GAAG,WAAW,GAAG,WAAW,GAAG,MAAM,CAAC,CAAC,GACvG,IAAI;IAQP;;OAEG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIvC;;OAEG;IACI,OAAO,IAAI,IAAI;CAIvB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MessageRoleValue } from '../constants';
|
|
1
2
|
import { PostMessageData } from '../types';
|
|
2
3
|
import { MessageChannel, type MessageContext } from './channel';
|
|
3
4
|
/**
|
|
@@ -45,6 +46,10 @@ export declare class MessageDispatcher {
|
|
|
45
46
|
readonly secretKey?: string;
|
|
46
47
|
/** Channel type */
|
|
47
48
|
readonly type: MessageChannel['type'];
|
|
49
|
+
/** Role of this dispatcher ('client' or 'server') */
|
|
50
|
+
private readonly role;
|
|
51
|
+
/** Instance ID of the client/server that owns this dispatcher */
|
|
52
|
+
private readonly instanceId?;
|
|
48
53
|
/** Underlying message channel */
|
|
49
54
|
private readonly channel;
|
|
50
55
|
/** Message handler list */
|
|
@@ -53,7 +58,7 @@ export declare class MessageDispatcher {
|
|
|
53
58
|
private readonly boundReceiver;
|
|
54
59
|
/** Reference count (for determining if can be destroyed when cached) */
|
|
55
60
|
private refCount;
|
|
56
|
-
constructor(channel: MessageChannel);
|
|
61
|
+
constructor(channel: MessageChannel, role: MessageRoleValue, instanceId?: string);
|
|
57
62
|
/**
|
|
58
63
|
* Increment reference count
|
|
59
64
|
*/
|
|
@@ -102,7 +107,7 @@ export declare class MessageDispatcher {
|
|
|
102
107
|
* @param requestId request ID
|
|
103
108
|
* @param data additional data
|
|
104
109
|
*/
|
|
105
|
-
sendMessage(target: Window, targetOrigin: string, type: PostMessageData['type'], requestId: string, data?: Partial<Omit<PostMessageData, '__requestIframe__' | 'type' | 'requestId' | 'timestamp'>>): void;
|
|
110
|
+
sendMessage(target: Window, targetOrigin: string, type: PostMessageData['type'], requestId: string, data?: Partial<Omit<PostMessageData, '__requestIframe__' | 'type' | 'requestId' | 'timestamp' | 'role' | 'creatorId'>>): void;
|
|
106
111
|
/**
|
|
107
112
|
* Add path prefix
|
|
108
113
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/message/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAChB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;AAExF;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;AAE/E;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,4DAA4D;IAC5D,cAAc,CAAC,EAAE,CAAC,IAAI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AAe,EAAE,YAAY,GAAE,MAAY,GAAG,IAAI;IAWvF;;;;;;;OAOG;IACI,WAAW,CAChB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,EAC7B,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,mBAAmB,GAAG,MAAM,GAAG,WAAW,GAAG,WAAW,GAAG,MAAM,GAAG,WAAW,CAAC,CAAC,GACrH,IAAI;IAaP;;OAEG;IACI,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIvC;;OAEG;IACI,UAAU,IAAI,cAAc;IAInC;;OAEG;IACI,OAAO,IAAI,IAAI;CAIvB"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
require("core-js/modules/es.symbol.description.js");
|
|
4
|
+
require("core-js/modules/es.array.filter.js");
|
|
4
5
|
require("core-js/modules/es.array.from.js");
|
|
5
6
|
require("core-js/modules/es.array.iterator.js");
|
|
6
7
|
require("core-js/modules/es.array.slice.js");
|
|
8
|
+
require("core-js/modules/es.object.get-own-property-descriptors.js");
|
|
9
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
7
10
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
8
11
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
9
12
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -17,7 +20,10 @@ require("core-js/modules/es.regexp.constructor.js");
|
|
|
17
20
|
require("core-js/modules/es.regexp.exec.js");
|
|
18
21
|
require("core-js/modules/es.regexp.to-string.js");
|
|
19
22
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
+
var _constants = require("../constants");
|
|
20
24
|
var _utils = require("../utils");
|
|
25
|
+
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; }
|
|
26
|
+
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) { (0, _defineProperty2.default)(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; }
|
|
21
27
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
22
28
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
23
29
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
@@ -59,9 +65,11 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
59
65
|
* It works with transport-agnostic MessageContext instead of transport-specific MessageEvent.
|
|
60
66
|
*/
|
|
61
67
|
class MessageDispatcher {
|
|
62
|
-
constructor(channel) {
|
|
68
|
+
constructor(channel, role, instanceId) {
|
|
63
69
|
/** Secret key for message isolation */
|
|
64
70
|
/** Channel type */
|
|
71
|
+
/** Role of this dispatcher ('client' or 'server') */
|
|
72
|
+
/** Instance ID of the client/server that owns this dispatcher */
|
|
65
73
|
/** Underlying message channel */
|
|
66
74
|
/** Message handler list */
|
|
67
75
|
(0, _defineProperty2.default)(this, "handlers", []);
|
|
@@ -70,6 +78,8 @@ class MessageDispatcher {
|
|
|
70
78
|
this.channel = channel;
|
|
71
79
|
this.secretKey = channel.secretKey;
|
|
72
80
|
this.type = channel.type;
|
|
81
|
+
this.role = role;
|
|
82
|
+
this.instanceId = instanceId;
|
|
73
83
|
|
|
74
84
|
// Create bound receiver callback
|
|
75
85
|
this.boundReceiver = (data, context) => {
|
|
@@ -150,6 +160,21 @@ class MessageDispatcher {
|
|
|
150
160
|
* Dispatch message to matching handlers
|
|
151
161
|
*/
|
|
152
162
|
dispatchMessage(data, context) {
|
|
163
|
+
// If message has already been handled by another dispatcher, skip processing
|
|
164
|
+
if (context.handledBy) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Role-based message filtering: only process messages from the opposite role
|
|
169
|
+
// - Server only processes messages from client (role === 'client')
|
|
170
|
+
// - Client only processes messages from server (role === 'server')
|
|
171
|
+
if (data.role !== undefined) {
|
|
172
|
+
var expectedRole = this.role === _constants.MessageRole.CLIENT ? _constants.MessageRole.SERVER : _constants.MessageRole.CLIENT;
|
|
173
|
+
if (data.role !== expectedRole) {
|
|
174
|
+
// Message is from the same role, ignore it to prevent routing confusion
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
153
178
|
var type = data.type;
|
|
154
179
|
var version = (0, _utils.getProtocolVersion)(data);
|
|
155
180
|
var _iterator = _createForOfIteratorHelper(this.handlers),
|
|
@@ -158,6 +183,11 @@ class MessageDispatcher {
|
|
|
158
183
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
159
184
|
var entry = _step.value;
|
|
160
185
|
if (this.matchType(type, entry.matcher)) {
|
|
186
|
+
// If message has been handled by a previous handler, stop processing
|
|
187
|
+
if (context.handledBy) {
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
|
|
161
191
|
// If handler specified version validation
|
|
162
192
|
if (entry.versionValidator && version !== undefined) {
|
|
163
193
|
if (!entry.versionValidator(version)) {
|
|
@@ -169,6 +199,8 @@ class MessageDispatcher {
|
|
|
169
199
|
}
|
|
170
200
|
try {
|
|
171
201
|
entry.handler(data, context);
|
|
202
|
+
// After handler execution, check if it marked the message as handled
|
|
203
|
+
// If context.handledBy is set by the handler, subsequent handlers will be skipped
|
|
172
204
|
} catch (e) {
|
|
173
205
|
// Ignore handler exception, continue executing other handlers
|
|
174
206
|
console.error('[request-iframe] Handler error:', e);
|
|
@@ -207,6 +239,13 @@ class MessageDispatcher {
|
|
|
207
239
|
* @param targetOrigin target origin (defaults to '*')
|
|
208
240
|
*/
|
|
209
241
|
send(target, message, targetOrigin = '*') {
|
|
242
|
+
// Automatically set role and creatorId if not already set (for backward compatibility)
|
|
243
|
+
if (message.role === undefined) {
|
|
244
|
+
message.role = this.role;
|
|
245
|
+
}
|
|
246
|
+
if (message.creatorId === undefined && this.instanceId) {
|
|
247
|
+
message.creatorId = this.instanceId;
|
|
248
|
+
}
|
|
210
249
|
this.channel.send(target, message, targetOrigin);
|
|
211
250
|
}
|
|
212
251
|
|
|
@@ -219,7 +258,13 @@ class MessageDispatcher {
|
|
|
219
258
|
* @param data additional data
|
|
220
259
|
*/
|
|
221
260
|
sendMessage(target, targetOrigin, type, requestId, data) {
|
|
222
|
-
|
|
261
|
+
// Automatically set role and creatorId based on dispatcher's role and instanceId
|
|
262
|
+
// Create message with role and creatorId using createPostMessage directly
|
|
263
|
+
var message = (0, _utils.createPostMessage)(type, requestId, _objectSpread(_objectSpread({}, data), {}, {
|
|
264
|
+
role: this.role,
|
|
265
|
+
creatorId: this.instanceId
|
|
266
|
+
}));
|
|
267
|
+
this.channel.send(target, message, targetOrigin);
|
|
223
268
|
}
|
|
224
269
|
|
|
225
270
|
// ==================== Utilities ====================
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ChannelType", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _channel.ChannelType;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "MessageChannel", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _channel.MessageChannel;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "MessageDispatcher", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _dispatcher.MessageDispatcher;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _channel = require("./channel");
|
|
25
|
+
var _dispatcher = require("./dispatcher");
|
|
@@ -36,6 +36,11 @@ export declare class IframeFileReadableStream extends IframeReadableStream<Uint8
|
|
|
36
36
|
* Read as Blob
|
|
37
37
|
*/
|
|
38
38
|
readAsBlob(): Promise<Blob>;
|
|
39
|
+
/**
|
|
40
|
+
* Read as File
|
|
41
|
+
* @param fileName Optional file name (if not provided, uses stream's filename)
|
|
42
|
+
*/
|
|
43
|
+
readAsFile(fileName?: string): Promise<File>;
|
|
39
44
|
/**
|
|
40
45
|
* Read as ArrayBuffer
|
|
41
46
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-stream.d.ts","sourceRoot":"","sources":["../../src/stream/file-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AA0BjB;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,oBAAoB;IAChE,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;gBAEX,OAAO,EAAE,yBAAyB;IAiBrD;;OAEG;IACH,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM;CAcxC;AAED;;;GAGG;AACH,qBAAa,wBACX,SAAQ,oBAAoB,CAAC,UAAU,CACvC,YAAW,yBAAyB;IAEpC,SAAgB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClC,SAAgB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClC,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;gBAG5B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,oBAAoB,EACpC,OAAO,GAAE,yBAA8B;IAYzC;;OAEG;IACH,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,UAAU;IAa3C;;OAEG;IACH,SAAS,CAAC,WAAW,IAAI,UAAU;IAuBnC;;OAEG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOxC;;OAEG;IACU,iBAAiB,IAAI,OAAO,CAAC,WAAW,CAAC;IAQtD;;OAEG;IACU,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAK9C"}
|
|
1
|
+
{"version":3,"file":"file-stream.d.ts","sourceRoot":"","sources":["../../src/stream/file-stream.ts"],"names":[],"mappings":"A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