request-iframe 0.0.3 → 0.0.4
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 +35 -8
- package/QUICKSTART.md +35 -8
- package/README.CN.md +170 -24
- package/README.md +230 -19
- package/library/__tests__/coverage-branches.test.ts +356 -0
- package/library/__tests__/requestIframe.test.ts +1008 -58
- package/library/__tests__/stream.test.ts +46 -15
- package/library/api/client.d.ts.map +1 -1
- package/library/api/client.js +1 -0
- package/library/constants/messages.d.ts +2 -0
- package/library/constants/messages.d.ts.map +1 -1
- package/library/constants/messages.js +2 -0
- package/library/core/client-server.d.ts +4 -0
- package/library/core/client-server.d.ts.map +1 -1
- package/library/core/client-server.js +45 -22
- package/library/core/client.d.ts +31 -4
- package/library/core/client.d.ts.map +1 -1
- package/library/core/client.js +471 -284
- package/library/core/request.d.ts +3 -1
- package/library/core/request.d.ts.map +1 -1
- package/library/core/request.js +2 -1
- package/library/core/response.d.ts +26 -4
- package/library/core/response.d.ts.map +1 -1
- package/library/core/response.js +142 -81
- package/library/core/server.d.ts +13 -0
- package/library/core/server.d.ts.map +1 -1
- package/library/core/server.js +211 -6
- package/library/index.d.ts +2 -1
- package/library/index.d.ts.map +1 -1
- package/library/index.js +32 -3
- package/library/message/dispatcher.d.ts.map +1 -1
- package/library/message/dispatcher.js +4 -3
- package/library/stream/index.d.ts +11 -1
- package/library/stream/index.d.ts.map +1 -1
- package/library/stream/index.js +21 -3
- package/library/stream/types.d.ts +2 -2
- package/library/stream/types.d.ts.map +1 -1
- package/library/stream/writable-stream.d.ts +1 -1
- package/library/stream/writable-stream.d.ts.map +1 -1
- package/library/stream/writable-stream.js +8 -10
- package/library/types/index.d.ts +26 -4
- package/library/types/index.d.ts.map +1 -1
- package/library/utils/index.d.ts +14 -0
- package/library/utils/index.d.ts.map +1 -1
- package/library/utils/index.js +99 -1
- package/library/utils/path-match.d.ts +16 -0
- package/library/utils/path-match.d.ts.map +1 -1
- package/library/utils/path-match.js +65 -0
- package/package.json +2 -1
- package/react/library/__tests__/index.test.tsx +44 -22
- package/react/library/index.d.ts.map +1 -1
- package/react/library/index.js +81 -23
- package/react/package.json +7 -0
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Stream functionality tests
|
|
3
3
|
*/
|
|
4
|
+
import type { MessageChannel } from '../message';
|
|
4
5
|
import {
|
|
5
6
|
IframeWritableStream,
|
|
6
7
|
IframeReadableStream,
|
|
7
8
|
IframeFileWritableStream,
|
|
8
9
|
IframeFileReadableStream,
|
|
9
10
|
isIframeReadableStream,
|
|
10
|
-
|
|
11
|
+
isIframeFileReadableStream,
|
|
12
|
+
isIframeFileWritableStream,
|
|
11
13
|
StreamMessageHandler
|
|
12
14
|
} from '../stream';
|
|
13
15
|
|
|
@@ -15,12 +17,17 @@ describe('Stream', () => {
|
|
|
15
17
|
describe('IframeWritableStream', () => {
|
|
16
18
|
let mockTargetWindow: Window;
|
|
17
19
|
let mockPostMessage: jest.Mock;
|
|
20
|
+
/** Mock channel: only send() is used by WritableStream */
|
|
21
|
+
let mockChannel: MessageChannel;
|
|
18
22
|
|
|
19
23
|
beforeEach(() => {
|
|
20
24
|
mockPostMessage = jest.fn();
|
|
21
25
|
mockTargetWindow = {
|
|
22
26
|
postMessage: mockPostMessage
|
|
23
27
|
} as any;
|
|
28
|
+
mockChannel = {
|
|
29
|
+
send: (target: Window, message: any, origin: string) => target.postMessage(message, origin)
|
|
30
|
+
} as unknown as MessageChannel;
|
|
24
31
|
});
|
|
25
32
|
|
|
26
33
|
it('should create stream with default options', () => {
|
|
@@ -69,7 +76,8 @@ describe('Stream', () => {
|
|
|
69
76
|
requestId: 'req-123',
|
|
70
77
|
targetWindow: mockTargetWindow,
|
|
71
78
|
targetOrigin: 'https://example.com',
|
|
72
|
-
secretKey: 'test'
|
|
79
|
+
secretKey: 'test',
|
|
80
|
+
channel: mockChannel
|
|
73
81
|
});
|
|
74
82
|
|
|
75
83
|
await stream.start();
|
|
@@ -98,7 +106,8 @@ describe('Stream', () => {
|
|
|
98
106
|
requestId: 'req-123',
|
|
99
107
|
targetWindow: mockTargetWindow,
|
|
100
108
|
targetOrigin: 'https://example.com',
|
|
101
|
-
secretKey: 'test'
|
|
109
|
+
secretKey: 'test',
|
|
110
|
+
channel: mockChannel
|
|
102
111
|
});
|
|
103
112
|
|
|
104
113
|
await stream.start();
|
|
@@ -115,7 +124,8 @@ describe('Stream', () => {
|
|
|
115
124
|
requestId: 'req-123',
|
|
116
125
|
targetWindow: mockTargetWindow,
|
|
117
126
|
targetOrigin: 'https://example.com',
|
|
118
|
-
secretKey: 'test'
|
|
127
|
+
secretKey: 'test',
|
|
128
|
+
channel: mockChannel
|
|
119
129
|
});
|
|
120
130
|
|
|
121
131
|
await stream.start();
|
|
@@ -136,7 +146,8 @@ describe('Stream', () => {
|
|
|
136
146
|
requestId: 'req-123',
|
|
137
147
|
targetWindow: mockTargetWindow,
|
|
138
148
|
targetOrigin: 'https://example.com',
|
|
139
|
-
secretKey: 'test'
|
|
149
|
+
secretKey: 'test',
|
|
150
|
+
channel: mockChannel
|
|
140
151
|
});
|
|
141
152
|
|
|
142
153
|
await stream.start();
|
|
@@ -159,7 +170,8 @@ describe('Stream', () => {
|
|
|
159
170
|
requestId: 'req-123',
|
|
160
171
|
targetWindow: mockTargetWindow,
|
|
161
172
|
targetOrigin: 'https://example.com',
|
|
162
|
-
secretKey: 'test'
|
|
173
|
+
secretKey: 'test',
|
|
174
|
+
channel: mockChannel
|
|
163
175
|
});
|
|
164
176
|
|
|
165
177
|
await stream.start();
|
|
@@ -174,7 +186,8 @@ describe('Stream', () => {
|
|
|
174
186
|
requestId: 'req-123',
|
|
175
187
|
targetWindow: mockTargetWindow,
|
|
176
188
|
targetOrigin: 'https://example.com',
|
|
177
|
-
secretKey: 'test'
|
|
189
|
+
secretKey: 'test',
|
|
190
|
+
channel: mockChannel
|
|
178
191
|
});
|
|
179
192
|
|
|
180
193
|
stream.cancel('User cancelled');
|
|
@@ -192,7 +205,8 @@ describe('Stream', () => {
|
|
|
192
205
|
requestId: 'req-123',
|
|
193
206
|
targetWindow: mockTargetWindow,
|
|
194
207
|
targetOrigin: 'https://example.com',
|
|
195
|
-
secretKey: 'test'
|
|
208
|
+
secretKey: 'test',
|
|
209
|
+
channel: mockChannel
|
|
196
210
|
});
|
|
197
211
|
|
|
198
212
|
// Manually set state to ended (simulating already ended)
|
|
@@ -237,7 +251,8 @@ describe('Stream', () => {
|
|
|
237
251
|
requestId: 'req-123',
|
|
238
252
|
targetWindow: mockTargetWindow,
|
|
239
253
|
targetOrigin: 'https://example.com',
|
|
240
|
-
secretKey: 'test'
|
|
254
|
+
secretKey: 'test',
|
|
255
|
+
channel: mockChannel
|
|
241
256
|
});
|
|
242
257
|
|
|
243
258
|
stream.cancel('User cancelled');
|
|
@@ -261,7 +276,8 @@ describe('Stream', () => {
|
|
|
261
276
|
requestId: 'req-123',
|
|
262
277
|
targetWindow: mockTargetWindow,
|
|
263
278
|
targetOrigin: 'https://example.com',
|
|
264
|
-
secretKey: 'test'
|
|
279
|
+
secretKey: 'test',
|
|
280
|
+
channel: mockChannel
|
|
265
281
|
});
|
|
266
282
|
|
|
267
283
|
await stream.start();
|
|
@@ -284,7 +300,8 @@ describe('Stream', () => {
|
|
|
284
300
|
requestId: 'req-123',
|
|
285
301
|
targetWindow: mockTargetWindow,
|
|
286
302
|
targetOrigin: 'https://example.com',
|
|
287
|
-
secretKey: 'test'
|
|
303
|
+
secretKey: 'test',
|
|
304
|
+
channel: mockChannel
|
|
288
305
|
});
|
|
289
306
|
|
|
290
307
|
const startPromise = stream.start();
|
|
@@ -637,14 +654,28 @@ describe('Stream', () => {
|
|
|
637
654
|
expect(isIframeReadableStream('string')).toBe(false);
|
|
638
655
|
});
|
|
639
656
|
|
|
640
|
-
it('
|
|
657
|
+
it('isIframeFileReadableStream should return true for IframeFileReadableStream', () => {
|
|
641
658
|
const stream = new IframeFileReadableStream('id', 'reqId', mockHandler);
|
|
642
|
-
expect(
|
|
659
|
+
expect(isIframeFileReadableStream(stream)).toBe(true);
|
|
643
660
|
});
|
|
644
661
|
|
|
645
|
-
it('
|
|
662
|
+
it('isIframeFileReadableStream should return false for regular IframeReadableStream', () => {
|
|
646
663
|
const stream = new IframeReadableStream('id', 'reqId', mockHandler);
|
|
647
|
-
expect(
|
|
664
|
+
expect(isIframeFileReadableStream(stream)).toBe(false);
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
it('isIframeFileWritableStream should return true for IframeFileWritableStream', () => {
|
|
668
|
+
const stream = new IframeFileWritableStream({
|
|
669
|
+
filename: 'test.txt',
|
|
670
|
+
mimeType: 'text/plain',
|
|
671
|
+
next: async () => ({ data: btoa('test'), done: true })
|
|
672
|
+
});
|
|
673
|
+
expect(isIframeFileWritableStream(stream)).toBe(true);
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
it('isIframeFileWritableStream should return false for regular IframeWritableStream', () => {
|
|
677
|
+
const stream = new IframeWritableStream();
|
|
678
|
+
expect(isIframeFileWritableStream(stream)).toBe(false);
|
|
648
679
|
});
|
|
649
680
|
});
|
|
650
681
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAO1F;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,iBAAiB,GAAG,MAAM,EAClC,OAAO,CAAC,EAAE,0BAA0B,GACnC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAO1F;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,iBAAiB,GAAG,MAAM,EAClC,OAAO,CAAC,EAAE,0BAA0B,GACnC,mBAAmB,CAgDrB;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAKtE"}
|
package/library/api/client.js
CHANGED
|
@@ -55,6 +55,7 @@ function requestIframeClient(target, options) {
|
|
|
55
55
|
ackTimeout: options === null || options === void 0 ? void 0 : options.ackTimeout,
|
|
56
56
|
timeout: options === null || options === void 0 ? void 0 : options.timeout,
|
|
57
57
|
asyncTimeout: options === null || options === void 0 ? void 0 : options.asyncTimeout,
|
|
58
|
+
returnData: options === null || options === void 0 ? void 0 : options.returnData,
|
|
58
59
|
headers: options === null || options === void 0 ? void 0 : options.headers
|
|
59
60
|
}, instanceId);
|
|
60
61
|
|
|
@@ -33,6 +33,8 @@ declare const defaultMessages: {
|
|
|
33
33
|
readonly ERROR: "Error";
|
|
34
34
|
/** Client errors */
|
|
35
35
|
readonly IFRAME_NOT_READY: "iframe.contentWindow is not available";
|
|
36
|
+
/** ClientServer warnings */
|
|
37
|
+
readonly CLIENT_SERVER_IGNORED_MESSAGE_WHEN_CLOSED: "Ignored message because client server is closed/destroyed (type: {0}, requestId: {1})";
|
|
36
38
|
/** Stream related messages */
|
|
37
39
|
readonly STREAM_NOT_BOUND: "Stream is not bound to a request context";
|
|
38
40
|
readonly STREAM_ALREADY_STARTED: "Stream has already started";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/constants/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;GAEG;AACH,QAAA,MAAM,eAAe;IACnB,8BAA8B;;;;IAK9B,4BAA4B;;;;;IAM5B,qBAAqB;;;;IAKrB,8BAA8B;;;;;;IAO9B,oBAAoB;;IAGpB,8BAA8B;;;;;;;IAQ9B,8BAA8B;;;;;;;;;;;;;;;;;IAkB9B,8BAA8B;;;;;;;;;;;;;;;;;;CA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,MAAM,CAAC,CAAC,GAAG,IAAI,CAE/E;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAEpC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,MAAM,CAKpF;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAElE"}
|
|
@@ -53,6 +53,8 @@ var defaultMessages = {
|
|
|
53
53
|
ERROR: 'Error',
|
|
54
54
|
/** Client errors */
|
|
55
55
|
IFRAME_NOT_READY: 'iframe.contentWindow is not available',
|
|
56
|
+
/** ClientServer warnings */
|
|
57
|
+
CLIENT_SERVER_IGNORED_MESSAGE_WHEN_CLOSED: 'Ignored message because client server is closed/destroyed (type: {0}, requestId: {1})',
|
|
56
58
|
/** Stream related messages */
|
|
57
59
|
STREAM_NOT_BOUND: 'Stream is not bound to a request context',
|
|
58
60
|
STREAM_ALREADY_STARTED: 'Stream has already started',
|
|
@@ -30,6 +30,10 @@ export declare class RequestIframeClientServer {
|
|
|
30
30
|
private readonly pendingAcks;
|
|
31
31
|
/** Pending requests awaiting response */
|
|
32
32
|
private readonly pendingRequests;
|
|
33
|
+
/**
|
|
34
|
+
* Avoid spamming logs for the same requestId when closed/destroyed
|
|
35
|
+
*/
|
|
36
|
+
private readonly warnedMissingPendingWhenClosed;
|
|
33
37
|
/** Stream message callback */
|
|
34
38
|
private streamCallback?;
|
|
35
39
|
/** List of unregister handler functions */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-server.d.ts","sourceRoot":"","sources":["../../src/core/client-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MA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AEG;IACH,OAAO,CAAC,cAAc;IAStB;;OAEG;IACH,OAAO,CAAC,UAAU;IAWlB;;OAEG;IACI,iBAAiB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI;IAI/D,oBAAoB;IACpB,IAAW,SAAS,IAAI,MAAM,GAAG,SAAS,CAEzC;IAED,2CAA2C;IAC3C,IAAW,iBAAiB,IAAI,iBAAiB,CAEhD;IAED;;OAEG;IACI,mBAAmB,CACxB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,EACpC,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAC7B,IAAI;IASP;;OAEG;IACI,uBAAuB,CAC5B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,EACxC,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,EAC9B,MAAM,CAAC,EAAE,MAAM,GACd,IAAI;IAIP;;OAEG;IACI,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAIzD;;OAEG;IACI,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAIpF;;OAEG;IACI,OAAO,IAAI,IAAI;CAcvB"}
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.RequestIframeClientServer = void 0;
|
|
8
8
|
require("core-js/modules/es.array.iterator.js");
|
|
9
9
|
require("core-js/modules/es.map.js");
|
|
10
|
+
require("core-js/modules/es.set.js");
|
|
10
11
|
require("core-js/modules/es.string.starts-with.js");
|
|
11
12
|
require("core-js/modules/web.dom-collections.for-each.js");
|
|
12
13
|
require("core-js/modules/web.dom-collections.iterator.js");
|
|
@@ -43,6 +44,10 @@ class RequestIframeClientServer {
|
|
|
43
44
|
(0, _defineProperty2.default)(this, "pendingAcks", new Map());
|
|
44
45
|
/** Pending requests awaiting response */
|
|
45
46
|
(0, _defineProperty2.default)(this, "pendingRequests", new Map());
|
|
47
|
+
/**
|
|
48
|
+
* Avoid spamming logs for the same requestId when closed/destroyed
|
|
49
|
+
*/
|
|
50
|
+
(0, _defineProperty2.default)(this, "warnedMissingPendingWhenClosed", new Set());
|
|
46
51
|
/** List of unregister handler functions */
|
|
47
52
|
(0, _defineProperty2.default)(this, "unregisterFns", []);
|
|
48
53
|
/** Whether opened */
|
|
@@ -97,31 +102,30 @@ class RequestIframeClientServer {
|
|
|
97
102
|
onVersionError: this.handleVersionError.bind(this)
|
|
98
103
|
};
|
|
99
104
|
|
|
105
|
+
// Bind handleClientResponse to ensure correct 'this' context
|
|
106
|
+
var boundHandleClientResponse = this.handleClientResponse.bind(this);
|
|
107
|
+
|
|
100
108
|
// Handle ACK messages
|
|
101
|
-
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.ACK,
|
|
109
|
+
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.ACK, boundHandleClientResponse, handlerOptions));
|
|
102
110
|
|
|
103
111
|
// Handle ASYNC messages
|
|
104
|
-
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.ASYNC,
|
|
112
|
+
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.ASYNC, boundHandleClientResponse, handlerOptions));
|
|
105
113
|
|
|
106
114
|
// Handle RESPONSE messages
|
|
107
|
-
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.RESPONSE,
|
|
115
|
+
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.RESPONSE, boundHandleClientResponse, handlerOptions));
|
|
108
116
|
|
|
109
117
|
// Handle ERROR messages
|
|
110
|
-
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.ERROR,
|
|
118
|
+
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.ERROR, boundHandleClientResponse, handlerOptions));
|
|
111
119
|
|
|
112
120
|
// Handle RECEIVED messages
|
|
113
|
-
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.RECEIVED,
|
|
121
|
+
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.RECEIVED, this.handleReceived.bind(this), handlerOptions));
|
|
114
122
|
|
|
115
123
|
// Handle PONG messages
|
|
116
|
-
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.PONG,
|
|
124
|
+
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.PONG, this.handlePong.bind(this), handlerOptions));
|
|
117
125
|
|
|
118
126
|
// Handle stream_start messages (route to handleClientResponse so it reaches send callback)
|
|
119
127
|
// Note: stream_start is handled in send callback, not through streamCallback
|
|
120
|
-
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.STREAM_START,
|
|
121
|
-
// Route to handleClientResponse so it reaches send callback
|
|
122
|
-
this.handleClientResponse(data, context);
|
|
123
|
-
// Don't call streamCallback here - stream_start is handled in send callback
|
|
124
|
-
}, handlerOptions));
|
|
128
|
+
this.unregisterFns.push(this.dispatcher.registerHandler(_constants.MessageType.STREAM_START, boundHandleClientResponse, handlerOptions));
|
|
125
129
|
|
|
126
130
|
// Handle other stream messages (stream_data, stream_end, etc.)
|
|
127
131
|
this.unregisterFns.push(this.dispatcher.registerHandler(type => type.startsWith('stream_') && type !== _constants.MessageType.STREAM_START, (data, context) => {
|
|
@@ -147,20 +151,38 @@ class RequestIframeClientServer {
|
|
|
147
151
|
*/
|
|
148
152
|
handleClientResponse(data, context) {
|
|
149
153
|
var pending = this.pendingRequests.get(data.requestId);
|
|
150
|
-
if (pending) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
154
|
+
if (!pending) {
|
|
155
|
+
/**
|
|
156
|
+
* Pending request not found - ignore by default.
|
|
157
|
+
*
|
|
158
|
+
* If client server is already closed/destroyed, emit a warning to help debugging:
|
|
159
|
+
* this usually means the client was recreated/unmounted before the response arrived.
|
|
160
|
+
*/
|
|
161
|
+
if (!this._isOpen) {
|
|
162
|
+
var key = data.requestId;
|
|
163
|
+
if (!this.warnedMissingPendingWhenClosed.has(key)) {
|
|
164
|
+
this.warnedMissingPendingWhenClosed.add(key);
|
|
165
|
+
// eslint-disable-next-line no-console
|
|
166
|
+
console.warn((0, _constants.formatMessage)(_constants.Messages.CLIENT_SERVER_IGNORED_MESSAGE_WHEN_CLOSED, data.type, data.requestId));
|
|
167
|
+
}
|
|
159
168
|
}
|
|
160
|
-
|
|
161
|
-
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Validate origin
|
|
173
|
+
if (pending.origin && pending.origin !== '*' && context.origin !== pending.origin) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ack, async, and stream_start don't delete pending (stream_start needs to keep pending for stream_data/stream_end)
|
|
178
|
+
if (data.type === _constants.MessageType.ACK || data.type === _constants.MessageType.ASYNC || data.type === _constants.MessageType.STREAM_START) {
|
|
162
179
|
pending.resolve(data);
|
|
180
|
+
return;
|
|
163
181
|
}
|
|
182
|
+
|
|
183
|
+
// response and error delete pending
|
|
184
|
+
this.pendingRequests.delete(data.requestId);
|
|
185
|
+
pending.resolve(data);
|
|
164
186
|
}
|
|
165
187
|
|
|
166
188
|
/**
|
|
@@ -257,6 +279,7 @@ class RequestIframeClientServer {
|
|
|
257
279
|
this.pendingRequests.clear();
|
|
258
280
|
this.pendingAcks.forEach(pending => clearTimeout(pending.timeoutId));
|
|
259
281
|
this.pendingAcks.clear();
|
|
282
|
+
this.warnedMissingPendingWhenClosed.clear();
|
|
260
283
|
|
|
261
284
|
// Destroy dispatcher and release channel reference
|
|
262
285
|
this.dispatcher.destroy();
|
package/library/core/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RequestOptions, Response, RequestIframeClient, RequestDefaults, HeadersConfig } from '../types';
|
|
2
2
|
import { RequestInterceptorManager, ResponseInterceptorManager } from '../interceptors';
|
|
3
3
|
import { RequestIframeClientServer } from './client-server';
|
|
4
|
-
import { StreamMessageHandler, StreamMessageData } from '../stream';
|
|
4
|
+
import { IframeWritableStream, StreamMessageHandler, StreamMessageData } from '../stream';
|
|
5
5
|
/**
|
|
6
6
|
* Client configuration options
|
|
7
7
|
*/
|
|
@@ -19,7 +19,7 @@ export declare class RequestIframeClientImpl implements RequestIframeClient, Str
|
|
|
19
19
|
request: RequestInterceptorManager;
|
|
20
20
|
response: ResponseInterceptorManager;
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
readonly targetWindow: Window;
|
|
23
23
|
private readonly targetOrigin;
|
|
24
24
|
private readonly server;
|
|
25
25
|
private readonly secretKey?;
|
|
@@ -27,6 +27,8 @@ export declare class RequestIframeClientImpl implements RequestIframeClient, Str
|
|
|
27
27
|
private readonly defaultAckTimeout;
|
|
28
28
|
private readonly defaultTimeout;
|
|
29
29
|
private readonly defaultAsyncTimeout;
|
|
30
|
+
/** Default returnData configuration */
|
|
31
|
+
private readonly defaultReturnData;
|
|
30
32
|
/** Initial headers configuration */
|
|
31
33
|
private readonly initialHeaders?;
|
|
32
34
|
/**
|
|
@@ -64,17 +66,42 @@ export declare class RequestIframeClientImpl implements RequestIframeClient, Str
|
|
|
64
66
|
* Resolve header value (handle function type headers)
|
|
65
67
|
*/
|
|
66
68
|
private resolveHeaderValue;
|
|
69
|
+
/**
|
|
70
|
+
* Detect Content-Type for request body
|
|
71
|
+
*/
|
|
72
|
+
private detectContentTypeForBody;
|
|
73
|
+
/**
|
|
74
|
+
* Check if header exists (case-insensitive)
|
|
75
|
+
*/
|
|
76
|
+
private hasHeader;
|
|
67
77
|
/**
|
|
68
78
|
* Merge and resolve headers (initial headers + request headers)
|
|
69
79
|
* Request headers take precedence over initial headers
|
|
80
|
+
* Also auto-detects and sets Content-Type if not already set
|
|
70
81
|
*/
|
|
71
82
|
private mergeHeaders;
|
|
72
83
|
/**
|
|
73
84
|
* Check if server is reachable
|
|
74
85
|
*/
|
|
75
86
|
isConnect(): Promise<boolean>;
|
|
76
|
-
send<T = any>(path: string, body?:
|
|
77
|
-
|
|
87
|
+
send<T = any>(path: string, body?: any, options?: RequestOptions): Promise<Response<T> | T>;
|
|
88
|
+
/**
|
|
89
|
+
* Send file as request body (stream only; server receives stream or auto-resolved File/Blob via autoResolve).
|
|
90
|
+
*/
|
|
91
|
+
sendFile<T = any>(path: string, content: string | Blob | File, options?: RequestOptions & {
|
|
92
|
+
mimeType?: string;
|
|
93
|
+
fileName?: string;
|
|
94
|
+
autoResolve?: boolean;
|
|
95
|
+
}): Promise<Response<T> | T>;
|
|
96
|
+
/**
|
|
97
|
+
* Send stream as request body (server receives readable stream).
|
|
98
|
+
* Sends REQUEST with streamId and stream: true, then starts the writable stream.
|
|
99
|
+
*/
|
|
100
|
+
sendStream<T = any>(path: string, stream: IframeWritableStream, options?: RequestOptions): Promise<Response<T> | T>;
|
|
101
|
+
/**
|
|
102
|
+
* Internal: send REQUEST and wait for response (used by send, sendFile, sendStream).
|
|
103
|
+
*/
|
|
104
|
+
private _sendRequest;
|
|
78
105
|
/**
|
|
79
106
|
* Get internal server instance (for debugging)
|
|
80
107
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,QAAQ,EAGR,mBAAmB,EACnB,eAAe,EACf,aAAa,EAEd,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,QAAQ,EAGR,mBAAmB,EACnB,eAAe,EACf,aAAa,EAEd,MAAM,UAAU,CAAC;AAOlB,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAG3B,MAAM,iB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