request-iframe 0.0.1
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/QUICKSTART.CN.md +269 -0
- package/QUICKSTART.md +269 -0
- package/README.CN.md +1369 -0
- package/README.md +1016 -0
- package/library/__tests__/interceptors.test.ts +124 -0
- package/library/__tests__/requestIframe.test.ts +2216 -0
- package/library/__tests__/stream.test.ts +650 -0
- package/library/__tests__/utils.test.ts +433 -0
- package/library/api/client.d.ts +16 -0
- package/library/api/client.d.ts.map +1 -0
- package/library/api/client.js +72 -0
- package/library/api/server.d.ts +16 -0
- package/library/api/server.d.ts.map +1 -0
- package/library/api/server.js +44 -0
- package/library/constants/index.d.ts +209 -0
- package/library/constants/index.d.ts.map +1 -0
- package/library/constants/index.js +260 -0
- package/library/constants/messages.d.ts +80 -0
- package/library/constants/messages.d.ts.map +1 -0
- package/library/constants/messages.js +123 -0
- package/library/core/client.d.ts +99 -0
- package/library/core/client.d.ts.map +1 -0
- package/library/core/client.js +440 -0
- package/library/core/message-handler.d.ts +110 -0
- package/library/core/message-handler.d.ts.map +1 -0
- package/library/core/message-handler.js +320 -0
- package/library/core/request-response.d.ts +59 -0
- package/library/core/request-response.d.ts.map +1 -0
- package/library/core/request-response.js +337 -0
- package/library/core/request.d.ts +17 -0
- package/library/core/request.d.ts.map +1 -0
- package/library/core/request.js +34 -0
- package/library/core/response.d.ts +51 -0
- package/library/core/response.d.ts.map +1 -0
- package/library/core/response.js +323 -0
- package/library/core/server-base.d.ts +86 -0
- package/library/core/server-base.d.ts.map +1 -0
- package/library/core/server-base.js +257 -0
- package/library/core/server-client.d.ts +99 -0
- package/library/core/server-client.d.ts.map +1 -0
- package/library/core/server-client.js +256 -0
- package/library/core/server.d.ts +82 -0
- package/library/core/server.d.ts.map +1 -0
- package/library/core/server.js +338 -0
- package/library/index.d.ts +16 -0
- package/library/index.d.ts.map +1 -0
- package/library/index.js +211 -0
- package/library/interceptors/index.d.ts +41 -0
- package/library/interceptors/index.d.ts.map +1 -0
- package/library/interceptors/index.js +126 -0
- package/library/message/channel.d.ts +107 -0
- package/library/message/channel.d.ts.map +1 -0
- package/library/message/channel.js +184 -0
- package/library/message/dispatcher.d.ts +119 -0
- package/library/message/dispatcher.d.ts.map +1 -0
- package/library/message/dispatcher.js +249 -0
- package/library/message/index.d.ts +5 -0
- package/library/message/index.d.ts.map +1 -0
- package/library/message/index.js +25 -0
- package/library/stream/file-stream.d.ts +48 -0
- package/library/stream/file-stream.d.ts.map +1 -0
- package/library/stream/file-stream.js +240 -0
- package/library/stream/index.d.ts +15 -0
- package/library/stream/index.d.ts.map +1 -0
- package/library/stream/index.js +83 -0
- package/library/stream/readable-stream.d.ts +83 -0
- package/library/stream/readable-stream.d.ts.map +1 -0
- package/library/stream/readable-stream.js +249 -0
- package/library/stream/types.d.ts +165 -0
- package/library/stream/types.d.ts.map +1 -0
- package/library/stream/types.js +5 -0
- package/library/stream/writable-stream.d.ts +60 -0
- package/library/stream/writable-stream.d.ts.map +1 -0
- package/library/stream/writable-stream.js +348 -0
- package/library/types/index.d.ts +408 -0
- package/library/types/index.d.ts.map +1 -0
- package/library/types/index.js +5 -0
- package/library/utils/cache.d.ts +19 -0
- package/library/utils/cache.d.ts.map +1 -0
- package/library/utils/cache.js +83 -0
- package/library/utils/cookie.d.ts +117 -0
- package/library/utils/cookie.d.ts.map +1 -0
- package/library/utils/cookie.js +365 -0
- package/library/utils/debug.d.ts +11 -0
- package/library/utils/debug.d.ts.map +1 -0
- package/library/utils/debug.js +162 -0
- package/library/utils/index.d.ts +13 -0
- package/library/utils/index.d.ts.map +1 -0
- package/library/utils/index.js +132 -0
- package/library/utils/path-match.d.ts +17 -0
- package/library/utils/path-match.d.ts.map +1 -0
- package/library/utils/path-match.js +90 -0
- package/library/utils/protocol.d.ts +61 -0
- package/library/utils/protocol.d.ts.map +1 -0
- package/library/utils/protocol.js +169 -0
- package/package.json +58 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.RequestIframeServerImpl = void 0;
|
|
8
|
+
require("core-js/modules/es.array.iterator.js");
|
|
9
|
+
require("core-js/modules/es.map.js");
|
|
10
|
+
require("core-js/modules/es.object.entries.js");
|
|
11
|
+
require("core-js/modules/es.promise.js");
|
|
12
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
13
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
var _utils = require("../utils");
|
|
16
|
+
var _pathMatch = require("../utils/path-match");
|
|
17
|
+
var _request = require("./request");
|
|
18
|
+
var _response = require("./response");
|
|
19
|
+
var _message = require("../message");
|
|
20
|
+
var _cache = require("../utils/cache");
|
|
21
|
+
var _constants = require("../constants");
|
|
22
|
+
/**
|
|
23
|
+
* Middleware item (contains path matcher and middleware function)
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Pending acknowledgment
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Server configuration options
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* RequestIframeServer implementation
|
|
36
|
+
* Uses shared MessageDispatcher (backed by MessageChannel) to listen for and send messages
|
|
37
|
+
*/
|
|
38
|
+
class RequestIframeServerImpl {
|
|
39
|
+
constructor(options) {
|
|
40
|
+
var _options$ackTimeout, _options$versionValid;
|
|
41
|
+
(0, _defineProperty2.default)(this, "handlers", new Map());
|
|
42
|
+
(0, _defineProperty2.default)(this, "middlewares", []);
|
|
43
|
+
/** Responses waiting for client acknowledgment */
|
|
44
|
+
(0, _defineProperty2.default)(this, "pendingAcks", new Map());
|
|
45
|
+
/** List of functions to unregister handlers */
|
|
46
|
+
(0, _defineProperty2.default)(this, "unregisterFns", []);
|
|
47
|
+
/** Whether it is open */
|
|
48
|
+
(0, _defineProperty2.default)(this, "_isOpen", false);
|
|
49
|
+
this.ackTimeout = (_options$ackTimeout = options === null || options === void 0 ? void 0 : options.ackTimeout) !== null && _options$ackTimeout !== void 0 ? _options$ackTimeout : _constants.DefaultTimeout.SERVER_ACK;
|
|
50
|
+
this.versionValidator = (_options$versionValid = options === null || options === void 0 ? void 0 : options.versionValidator) !== null && _options$versionValid !== void 0 ? _options$versionValid : _utils.isCompatibleVersion;
|
|
51
|
+
|
|
52
|
+
// Get or create shared channel and create dispatcher
|
|
53
|
+
var channel = (0, _cache.getOrCreateMessageChannel)(options === null || options === void 0 ? void 0 : options.secretKey);
|
|
54
|
+
this.dispatcher = new _message.MessageDispatcher(channel);
|
|
55
|
+
|
|
56
|
+
// Auto-open by default
|
|
57
|
+
this.open();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Open message processing (register message handlers)
|
|
62
|
+
*/
|
|
63
|
+
open() {
|
|
64
|
+
if (this._isOpen) return;
|
|
65
|
+
this._isOpen = true;
|
|
66
|
+
this.registerHandlers();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Close message processing (unregister message handlers, but don't release channel)
|
|
71
|
+
*/
|
|
72
|
+
close() {
|
|
73
|
+
if (!this._isOpen) return;
|
|
74
|
+
this._isOpen = false;
|
|
75
|
+
|
|
76
|
+
// Unregister all handlers
|
|
77
|
+
this.unregisterFns.forEach(fn => fn());
|
|
78
|
+
this.unregisterFns.length = 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Whether it is open
|
|
83
|
+
*/
|
|
84
|
+
get isOpen() {
|
|
85
|
+
return this._isOpen;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Register message handlers
|
|
90
|
+
*/
|
|
91
|
+
registerHandlers() {
|
|
92
|
+
var handlerOptions = {
|
|
93
|
+
versionValidator: this.versionValidator,
|
|
94
|
+
onVersionError: this.handleVersionError.bind(this)
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Handle REQUEST messages
|
|
98
|
+
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.REQUEST, (data, context) => this.handleRequest(data, context), handlerOptions));
|
|
99
|
+
|
|
100
|
+
// Handle PING messages
|
|
101
|
+
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.PING, (data, context) => this.handlePing(data, context), handlerOptions));
|
|
102
|
+
|
|
103
|
+
// Handle RECEIVED messages (for confirming response delivery)
|
|
104
|
+
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.RECEIVED, data => this.handleReceived(data), handlerOptions));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Handle protocol version error
|
|
109
|
+
*/
|
|
110
|
+
handleVersionError(data, context, version) {
|
|
111
|
+
if (!context.source) return;
|
|
112
|
+
|
|
113
|
+
// Send protocol version incompatibility error
|
|
114
|
+
this.dispatcher.sendMessage(context.source, context.origin, _constants.MessageType.ERROR, data.requestId, {
|
|
115
|
+
path: data.path,
|
|
116
|
+
status: _constants.HttpStatus.BAD_REQUEST,
|
|
117
|
+
statusText: _constants.Messages.PROTOCOL_VERSION_UNSUPPORTED,
|
|
118
|
+
error: {
|
|
119
|
+
message: (0, _constants.formatMessage)(_constants.Messages.PROTOCOL_VERSION_TOO_LOW, version, _constants.ProtocolVersion.MIN_SUPPORTED),
|
|
120
|
+
code: _constants.ErrorCode.PROTOCOL_UNSUPPORTED
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Handle ping message
|
|
127
|
+
*/
|
|
128
|
+
handlePing(data, context) {
|
|
129
|
+
if (!context.source) return;
|
|
130
|
+
this.dispatcher.sendMessage(context.source, context.origin, _constants.MessageType.PONG, data.requestId);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Handle received acknowledgment
|
|
135
|
+
*/
|
|
136
|
+
handleReceived(data) {
|
|
137
|
+
var pending = this.pendingAcks.get(data.requestId);
|
|
138
|
+
if (pending) {
|
|
139
|
+
clearTimeout(pending.timeoutId);
|
|
140
|
+
this.pendingAcks.delete(data.requestId);
|
|
141
|
+
pending.resolve(true);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Get secretKey */
|
|
146
|
+
get secretKey() {
|
|
147
|
+
return this.dispatcher.secretKey;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Get the underlying MessageDispatcher */
|
|
151
|
+
get messageDispatcher() {
|
|
152
|
+
return this.dispatcher;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Handle request
|
|
157
|
+
*/
|
|
158
|
+
handleRequest(data, context) {
|
|
159
|
+
if (!data.path) return;
|
|
160
|
+
if (!context.source) return;
|
|
161
|
+
var targetWindow = context.source;
|
|
162
|
+
var targetOrigin = context.origin;
|
|
163
|
+
|
|
164
|
+
// Send ACK immediately via dispatcher
|
|
165
|
+
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ACK, data.requestId, {
|
|
166
|
+
path: data.path
|
|
167
|
+
});
|
|
168
|
+
var handlerFn = this.handlers.get(data.path);
|
|
169
|
+
if (!handlerFn) {
|
|
170
|
+
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ERROR, data.requestId, {
|
|
171
|
+
path: data.path,
|
|
172
|
+
error: {
|
|
173
|
+
message: _constants.Messages.METHOD_NOT_FOUND,
|
|
174
|
+
code: _constants.ErrorCode.METHOD_NOT_FOUND
|
|
175
|
+
},
|
|
176
|
+
status: _constants.HttpStatus.NOT_FOUND,
|
|
177
|
+
statusText: _constants.HttpStatusText[_constants.HttpStatus.NOT_FOUND]
|
|
178
|
+
});
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Create response object with channel reference
|
|
183
|
+
var res = new _response.ServerResponseImpl(data.requestId, data.path || '', data.secretKey, targetWindow, targetOrigin, this.dispatcher.getChannel());
|
|
184
|
+
|
|
185
|
+
// Register callback waiting for client acknowledgment
|
|
186
|
+
this.registerPendingAck(data.requestId, received => {
|
|
187
|
+
res._triggerAck(received);
|
|
188
|
+
}, () => {
|
|
189
|
+
res._triggerAck(false);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Create request object
|
|
193
|
+
var req = new _request.ServerRequestImpl(data, context, res);
|
|
194
|
+
|
|
195
|
+
// Execute middleware chain
|
|
196
|
+
this.runMiddlewares(req, res, () => {
|
|
197
|
+
var result = handlerFn(req, res);
|
|
198
|
+
if (result instanceof Promise) {
|
|
199
|
+
// Async task
|
|
200
|
+
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ASYNC, data.requestId, {
|
|
201
|
+
path: data.path
|
|
202
|
+
});
|
|
203
|
+
result.then(value => {
|
|
204
|
+
if (!res._sent && value !== undefined) {
|
|
205
|
+
res.send(value);
|
|
206
|
+
} else if (!res._sent) {
|
|
207
|
+
this.dispatcher.sendMessage(targetWindow, targetOrigin, _constants.MessageType.ERROR, data.requestId, {
|
|
208
|
+
path: data.path,
|
|
209
|
+
error: {
|
|
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);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Register pending acknowledgment response
|
|
243
|
+
*/
|
|
244
|
+
registerPendingAck(requestId, resolve, reject) {
|
|
245
|
+
var timeoutId = setTimeout(() => {
|
|
246
|
+
this.pendingAcks.delete(requestId);
|
|
247
|
+
resolve(false);
|
|
248
|
+
}, this.ackTimeout);
|
|
249
|
+
this.pendingAcks.set(requestId, {
|
|
250
|
+
resolve,
|
|
251
|
+
reject,
|
|
252
|
+
timeoutId
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
use(pathOrMiddleware, middleware) {
|
|
256
|
+
if (typeof pathOrMiddleware === 'function') {
|
|
257
|
+
this.middlewares.push({
|
|
258
|
+
matcher: null,
|
|
259
|
+
middleware: pathOrMiddleware
|
|
260
|
+
});
|
|
261
|
+
} else if (middleware) {
|
|
262
|
+
this.middlewares.push({
|
|
263
|
+
matcher: pathOrMiddleware,
|
|
264
|
+
middleware
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
on(path, handler) {
|
|
269
|
+
this.handlers.set(this.dispatcher.prefixPath(path), handler);
|
|
270
|
+
}
|
|
271
|
+
runMiddlewares(req, res, finalHandler) {
|
|
272
|
+
var path = req.path;
|
|
273
|
+
var index = 0;
|
|
274
|
+
var next = () => {
|
|
275
|
+
if (res._sent) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
while (index < this.middlewares.length) {
|
|
279
|
+
var item = this.middlewares[index++];
|
|
280
|
+
if (item.matcher === null || (0, _pathMatch.matchPath)(path, item.matcher)) {
|
|
281
|
+
try {
|
|
282
|
+
var result = item.middleware(req, res, next);
|
|
283
|
+
if (result instanceof Promise) {
|
|
284
|
+
result.catch(err => {
|
|
285
|
+
if (!res._sent) {
|
|
286
|
+
res.status(_constants.HttpStatus.INTERNAL_SERVER_ERROR).send({
|
|
287
|
+
error: err.message || _constants.Messages.MIDDLEWARE_ERROR
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return;
|
|
293
|
+
} catch (err) {
|
|
294
|
+
if (!res._sent) {
|
|
295
|
+
res.status(_constants.HttpStatus.INTERNAL_SERVER_ERROR).send({
|
|
296
|
+
error: (err === null || err === void 0 ? void 0 : err.message) || _constants.Messages.MIDDLEWARE_ERROR
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (index >= this.middlewares.length) {
|
|
304
|
+
finalHandler();
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
next();
|
|
308
|
+
}
|
|
309
|
+
off(path) {
|
|
310
|
+
this.handlers.delete(this.dispatcher.prefixPath(path));
|
|
311
|
+
}
|
|
312
|
+
map(handlers) {
|
|
313
|
+
Object.entries(handlers).forEach(([path, h]) => {
|
|
314
|
+
this.on(path, h);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Destroy (close and release channel reference)
|
|
320
|
+
*/
|
|
321
|
+
destroy() {
|
|
322
|
+
// Close first
|
|
323
|
+
this.close();
|
|
324
|
+
|
|
325
|
+
// Clean up pending
|
|
326
|
+
this.pendingAcks.forEach(pending => clearTimeout(pending.timeoutId));
|
|
327
|
+
this.pendingAcks.clear();
|
|
328
|
+
|
|
329
|
+
// Clean up handlers
|
|
330
|
+
this.handlers.clear();
|
|
331
|
+
this.middlewares.length = 0;
|
|
332
|
+
|
|
333
|
+
// Destroy dispatcher and release channel reference
|
|
334
|
+
this.dispatcher.destroy();
|
|
335
|
+
(0, _cache.releaseMessageChannel)(this.dispatcher.getChannel());
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
exports.RequestIframeServerImpl = RequestIframeServerImpl;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { requestIframeClient, clearRequestIframeClientCache } from './api/client';
|
|
2
|
+
export { requestIframeServer, clearRequestIframeServerCache } from './api/server';
|
|
3
|
+
export { RequestIframeClientImpl } from './core/client';
|
|
4
|
+
export { RequestIframeServerImpl } from './core/server';
|
|
5
|
+
export { RequestIframeClientServer } from './core/server-client';
|
|
6
|
+
export { MessageChannel, ChannelType, MessageDispatcher } from './message';
|
|
7
|
+
export type { MessageContext, MessageHandlerFn, MessageTypeMatcher, VersionValidator, HandlerOptions, ChannelType as ChannelTypeValue } from './message';
|
|
8
|
+
export { getOrCreateMessageChannel, releaseMessageChannel, clearMessageChannelCache, } from './utils/cache';
|
|
9
|
+
export { ServerRequestImpl } from './core/request';
|
|
10
|
+
export { ServerResponseImpl } from './core/response';
|
|
11
|
+
export { IframeWritableStream, IframeReadableStream, IframeFileWritableStream, IframeFileReadableStream, isIframeReadableStream, isIframeFileStream } from './stream';
|
|
12
|
+
export type { StreamType, StreamState, StreamChunk, WritableStreamOptions, ReadableStreamOptions, FileWritableStreamOptions, FileReadableStreamOptions, StreamBindContext, IIframeWritableStream, IIframeReadableStream, IIframeFileReadableStream, StreamMessageData } from './stream';
|
|
13
|
+
export * from './types';
|
|
14
|
+
export { InterceptorManager, RequestInterceptorManager, ResponseInterceptorManager } from './interceptors';
|
|
15
|
+
export * from './constants';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAElF,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC3E,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,WAAW,IAAI,gBAAgB,EAChC,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,wBAAwB,EACxB,sBAAsB,EACtB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,EACzB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAE3G,cAAc,aAAa,CAAC"}
|
package/library/index.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
var _exportNames = {
|
|
8
|
+
requestIframeClient: true,
|
|
9
|
+
clearRequestIframeClientCache: true,
|
|
10
|
+
requestIframeServer: true,
|
|
11
|
+
clearRequestIframeServerCache: true,
|
|
12
|
+
RequestIframeClientImpl: true,
|
|
13
|
+
RequestIframeServerImpl: true,
|
|
14
|
+
RequestIframeClientServer: true,
|
|
15
|
+
MessageChannel: true,
|
|
16
|
+
ChannelType: true,
|
|
17
|
+
MessageDispatcher: true,
|
|
18
|
+
getOrCreateMessageChannel: true,
|
|
19
|
+
releaseMessageChannel: true,
|
|
20
|
+
clearMessageChannelCache: true,
|
|
21
|
+
ServerRequestImpl: true,
|
|
22
|
+
ServerResponseImpl: true,
|
|
23
|
+
IframeWritableStream: true,
|
|
24
|
+
IframeReadableStream: true,
|
|
25
|
+
IframeFileWritableStream: true,
|
|
26
|
+
IframeFileReadableStream: true,
|
|
27
|
+
isIframeReadableStream: true,
|
|
28
|
+
isIframeFileStream: true,
|
|
29
|
+
InterceptorManager: true,
|
|
30
|
+
RequestInterceptorManager: true,
|
|
31
|
+
ResponseInterceptorManager: true
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "ChannelType", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function get() {
|
|
36
|
+
return _message.ChannelType;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "IframeFileReadableStream", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function get() {
|
|
42
|
+
return _stream.IframeFileReadableStream;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "IframeFileWritableStream", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function get() {
|
|
48
|
+
return _stream.IframeFileWritableStream;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "IframeReadableStream", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function get() {
|
|
54
|
+
return _stream.IframeReadableStream;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, "IframeWritableStream", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function get() {
|
|
60
|
+
return _stream.IframeWritableStream;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(exports, "InterceptorManager", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function get() {
|
|
66
|
+
return _interceptors.InterceptorManager;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(exports, "MessageChannel", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function get() {
|
|
72
|
+
return _message.MessageChannel;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(exports, "MessageDispatcher", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function get() {
|
|
78
|
+
return _message.MessageDispatcher;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(exports, "RequestIframeClientImpl", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function get() {
|
|
84
|
+
return _client2.RequestIframeClientImpl;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(exports, "RequestIframeClientServer", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function get() {
|
|
90
|
+
return _serverClient.RequestIframeClientServer;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(exports, "RequestIframeServerImpl", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function get() {
|
|
96
|
+
return _server2.RequestIframeServerImpl;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(exports, "RequestInterceptorManager", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
get: function get() {
|
|
102
|
+
return _interceptors.RequestInterceptorManager;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(exports, "ResponseInterceptorManager", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function get() {
|
|
108
|
+
return _interceptors.ResponseInterceptorManager;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
Object.defineProperty(exports, "ServerRequestImpl", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
get: function get() {
|
|
114
|
+
return _request.ServerRequestImpl;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(exports, "ServerResponseImpl", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
get: function get() {
|
|
120
|
+
return _response.ServerResponseImpl;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
Object.defineProperty(exports, "clearMessageChannelCache", {
|
|
124
|
+
enumerable: true,
|
|
125
|
+
get: function get() {
|
|
126
|
+
return _cache.clearMessageChannelCache;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
Object.defineProperty(exports, "clearRequestIframeClientCache", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function get() {
|
|
132
|
+
return _client.clearRequestIframeClientCache;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(exports, "clearRequestIframeServerCache", {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
get: function get() {
|
|
138
|
+
return _server.clearRequestIframeServerCache;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
Object.defineProperty(exports, "getOrCreateMessageChannel", {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: function get() {
|
|
144
|
+
return _cache.getOrCreateMessageChannel;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(exports, "isIframeFileStream", {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function get() {
|
|
150
|
+
return _stream.isIframeFileStream;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
Object.defineProperty(exports, "isIframeReadableStream", {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: function get() {
|
|
156
|
+
return _stream.isIframeReadableStream;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
Object.defineProperty(exports, "releaseMessageChannel", {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
get: function get() {
|
|
162
|
+
return _cache.releaseMessageChannel;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
Object.defineProperty(exports, "requestIframeClient", {
|
|
166
|
+
enumerable: true,
|
|
167
|
+
get: function get() {
|
|
168
|
+
return _client.requestIframeClient;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
Object.defineProperty(exports, "requestIframeServer", {
|
|
172
|
+
enumerable: true,
|
|
173
|
+
get: function get() {
|
|
174
|
+
return _server.requestIframeServer;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
var _client = require("./api/client");
|
|
178
|
+
var _server = require("./api/server");
|
|
179
|
+
var _client2 = require("./core/client");
|
|
180
|
+
var _server2 = require("./core/server");
|
|
181
|
+
var _serverClient = require("./core/server-client");
|
|
182
|
+
var _message = require("./message");
|
|
183
|
+
var _cache = require("./utils/cache");
|
|
184
|
+
var _request = require("./core/request");
|
|
185
|
+
var _response = require("./core/response");
|
|
186
|
+
var _stream = require("./stream");
|
|
187
|
+
var _types = require("./types");
|
|
188
|
+
Object.keys(_types).forEach(function (key) {
|
|
189
|
+
if (key === "default" || key === "__esModule") return;
|
|
190
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
191
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
192
|
+
Object.defineProperty(exports, key, {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
get: function get() {
|
|
195
|
+
return _types[key];
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
var _interceptors = require("./interceptors");
|
|
200
|
+
var _constants = require("./constants");
|
|
201
|
+
Object.keys(_constants).forEach(function (key) {
|
|
202
|
+
if (key === "default" || key === "__esModule") return;
|
|
203
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
204
|
+
if (key in exports && exports[key] === _constants[key]) return;
|
|
205
|
+
Object.defineProperty(exports, key, {
|
|
206
|
+
enumerable: true,
|
|
207
|
+
get: function get() {
|
|
208
|
+
return _constants[key];
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RequestConfig, Response, InterceptorFunction } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Interceptor manager
|
|
4
|
+
*/
|
|
5
|
+
export declare class InterceptorManager<T> {
|
|
6
|
+
private handlers;
|
|
7
|
+
/**
|
|
8
|
+
* Add interceptor
|
|
9
|
+
*/
|
|
10
|
+
use(fulfilled: InterceptorFunction<T>, rejected?: (error: any) => any): number;
|
|
11
|
+
/**
|
|
12
|
+
* Remove interceptor
|
|
13
|
+
*/
|
|
14
|
+
eject(id: number): void;
|
|
15
|
+
/**
|
|
16
|
+
* Iterate over all interceptors
|
|
17
|
+
*/
|
|
18
|
+
forEach(fn: (handler: {
|
|
19
|
+
fulfilled: InterceptorFunction<T>;
|
|
20
|
+
rejected?: (error: any) => any;
|
|
21
|
+
}) => void): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Request interceptor manager
|
|
25
|
+
*/
|
|
26
|
+
export declare class RequestInterceptorManager extends InterceptorManager<RequestConfig> {
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Response interceptor manager
|
|
30
|
+
*/
|
|
31
|
+
export declare class ResponseInterceptorManager extends InterceptorManager<Response> {
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Execute request interceptor chain
|
|
35
|
+
*/
|
|
36
|
+
export declare function runRequestInterceptors(interceptors: RequestInterceptorManager, config: RequestConfig): Promise<RequestConfig>;
|
|
37
|
+
/**
|
|
38
|
+
* Execute response interceptor chain
|
|
39
|
+
*/
|
|
40
|
+
export declare function runResponseInterceptors(interceptors: ResponseInterceptorManager, response: Response): Promise<Response>;
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAA;KAAE,KAAK,IAAI,GAAG,IAAI;CAO5G;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,kBAAkB,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"}
|