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,408 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request default configuration
|
|
3
|
+
* Can be set when creating requestIframeClient, and can be overridden on each request
|
|
4
|
+
*/
|
|
5
|
+
export interface RequestDefaults {
|
|
6
|
+
/** ACK confirmation timeout (milliseconds), timeout for waiting for the other party to acknowledge the message, default 500 */
|
|
7
|
+
ackTimeout?: number;
|
|
8
|
+
/** Request timeout (milliseconds), timeout for waiting for the server to return the result, default 5000 */
|
|
9
|
+
timeout?: number;
|
|
10
|
+
/** Async request timeout (milliseconds), timeout after the server indicates it's an async task, default 120000 */
|
|
11
|
+
asyncTimeout?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* sender.send configuration options
|
|
15
|
+
*/
|
|
16
|
+
export interface RequestOptions extends RequestDefaults {
|
|
17
|
+
/** Custom request ID */
|
|
18
|
+
requestId?: string;
|
|
19
|
+
/** Request headers */
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
/** Request cookies */
|
|
22
|
+
cookies?: Record<string, string>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* sender.send request configuration (internal use)
|
|
26
|
+
*/
|
|
27
|
+
export interface RequestConfig extends RequestOptions {
|
|
28
|
+
/** Interaction event ID (equivalent to path) */
|
|
29
|
+
path: string;
|
|
30
|
+
/** Request body */
|
|
31
|
+
body?: Record<string, any>;
|
|
32
|
+
/** Request headers */
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
/** Request cookies */
|
|
35
|
+
cookies?: Record<string, string>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Response data
|
|
39
|
+
*/
|
|
40
|
+
export interface Response<T = any> {
|
|
41
|
+
/** Response data */
|
|
42
|
+
data: T;
|
|
43
|
+
/** Status code */
|
|
44
|
+
status: number;
|
|
45
|
+
/** Status text */
|
|
46
|
+
statusText: string;
|
|
47
|
+
/** Request ID */
|
|
48
|
+
requestId: string;
|
|
49
|
+
/** Response headers (Set-Cookie is a string array) */
|
|
50
|
+
headers?: Record<string, string | string[]>;
|
|
51
|
+
/** File data (if response is a file) */
|
|
52
|
+
fileData?: {
|
|
53
|
+
content: string;
|
|
54
|
+
mimeType?: string;
|
|
55
|
+
fileName?: string;
|
|
56
|
+
};
|
|
57
|
+
/** Stream data (if response is a stream) */
|
|
58
|
+
stream?: import('../stream').IIframeReadableStream<T>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Error response
|
|
62
|
+
*/
|
|
63
|
+
export interface ErrorResponse {
|
|
64
|
+
/** Error message */
|
|
65
|
+
message: string;
|
|
66
|
+
/** Error code */
|
|
67
|
+
code?: string;
|
|
68
|
+
/** Request configuration */
|
|
69
|
+
config?: RequestConfig;
|
|
70
|
+
/** Response data (if available) */
|
|
71
|
+
response?: {
|
|
72
|
+
data: any;
|
|
73
|
+
status: number;
|
|
74
|
+
statusText: string;
|
|
75
|
+
};
|
|
76
|
+
/** Request ID */
|
|
77
|
+
requestId?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Interceptor function type
|
|
81
|
+
*/
|
|
82
|
+
export type InterceptorFunction<T> = (value: T) => T | Promise<T>;
|
|
83
|
+
/**
|
|
84
|
+
* Request interceptor
|
|
85
|
+
*/
|
|
86
|
+
export interface RequestInterceptor {
|
|
87
|
+
fulfilled: InterceptorFunction<RequestConfig>;
|
|
88
|
+
rejected?: (error: any) => any;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Response interceptor
|
|
92
|
+
*/
|
|
93
|
+
export interface ResponseInterceptor {
|
|
94
|
+
fulfilled: InterceptorFunction<Response>;
|
|
95
|
+
rejected?: (error: ErrorResponse) => any;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* PostMessage message format
|
|
99
|
+
*
|
|
100
|
+
* @description
|
|
101
|
+
* The __requestIframe__ field is the protocol version identifier, used to:
|
|
102
|
+
* - Distinguish request-iframe framework messages from other messages
|
|
103
|
+
* - Support compatibility handling for future version upgrades
|
|
104
|
+
*
|
|
105
|
+
* Version evolution rules:
|
|
106
|
+
* - Minor updates (e.g., adding optional fields): keep version number unchanged
|
|
107
|
+
* - Major updates (e.g., changing core field structure): increment version number
|
|
108
|
+
*/
|
|
109
|
+
export interface PostMessageData {
|
|
110
|
+
/**
|
|
111
|
+
* Protocol version identifier
|
|
112
|
+
* - Used to identify request-iframe framework messages
|
|
113
|
+
* - The value represents the protocol version number, current version is 1
|
|
114
|
+
* - Future version upgrades can use this field for compatibility handling
|
|
115
|
+
*/
|
|
116
|
+
__requestIframe__: number;
|
|
117
|
+
/**
|
|
118
|
+
* Message creation timestamp (milliseconds)
|
|
119
|
+
* - Used for debugging and analyzing message latency
|
|
120
|
+
* - Automatically added when each message is sent
|
|
121
|
+
*/
|
|
122
|
+
timestamp: number;
|
|
123
|
+
/** Message isolation key (used to isolate different businesses/instances) */
|
|
124
|
+
secretKey?: string;
|
|
125
|
+
/** Message type */
|
|
126
|
+
type: 'request' | 'ack' | 'async' | 'response' | 'error' | 'received' | 'ping' | 'pong' | 'stream_start' | 'stream_data' | 'stream_end' | 'stream_error' | 'stream_cancel';
|
|
127
|
+
/** Request ID */
|
|
128
|
+
requestId: string;
|
|
129
|
+
/** Request path */
|
|
130
|
+
path?: string;
|
|
131
|
+
/** Request body */
|
|
132
|
+
body?: any;
|
|
133
|
+
/**
|
|
134
|
+
* Headers
|
|
135
|
+
* - On request: request headers
|
|
136
|
+
* - On response: response headers (Set-Cookie is a string array)
|
|
137
|
+
*/
|
|
138
|
+
headers?: Record<string, string | string[]>;
|
|
139
|
+
/**
|
|
140
|
+
* Cookies (only used for requests)
|
|
141
|
+
* - On request: request cookies (auto-carried by client + manually passed by user)
|
|
142
|
+
* - On response: no longer used, use headers['Set-Cookie'] instead
|
|
143
|
+
*/
|
|
144
|
+
cookies?: Record<string, string>;
|
|
145
|
+
/** Response data */
|
|
146
|
+
data?: any;
|
|
147
|
+
/** File data (base64 encoded, used for sendFile) */
|
|
148
|
+
fileData?: {
|
|
149
|
+
content: string;
|
|
150
|
+
mimeType?: string;
|
|
151
|
+
fileName?: string;
|
|
152
|
+
};
|
|
153
|
+
/** Error information */
|
|
154
|
+
error?: {
|
|
155
|
+
message: string;
|
|
156
|
+
code?: string;
|
|
157
|
+
};
|
|
158
|
+
/** Status code */
|
|
159
|
+
status?: number;
|
|
160
|
+
/** Status text */
|
|
161
|
+
statusText?: string;
|
|
162
|
+
/** Whether client confirmation of receipt is required (for response/error messages) */
|
|
163
|
+
requireAck?: boolean;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Server Request object (similar to express)
|
|
167
|
+
*/
|
|
168
|
+
export interface ServerRequest {
|
|
169
|
+
/** Request body */
|
|
170
|
+
body: any;
|
|
171
|
+
/** Request headers */
|
|
172
|
+
headers: Record<string, string>;
|
|
173
|
+
/** Request cookies */
|
|
174
|
+
cookies: Record<string, string>;
|
|
175
|
+
/** Request path */
|
|
176
|
+
path: string;
|
|
177
|
+
/** Request ID */
|
|
178
|
+
requestId: string;
|
|
179
|
+
/** Sender origin */
|
|
180
|
+
origin: string;
|
|
181
|
+
/** Sender window reference */
|
|
182
|
+
source: Window;
|
|
183
|
+
/** Response object reference (consistent with Express) */
|
|
184
|
+
res: ServerResponse;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Send response options
|
|
188
|
+
*/
|
|
189
|
+
export interface SendOptions {
|
|
190
|
+
/**
|
|
191
|
+
* Whether client confirmation of receipt is required
|
|
192
|
+
* - If true, the Promise returned by send/json/sendFile will resolve after the client confirms receipt
|
|
193
|
+
* - If false (default), resolves immediately without waiting for client confirmation
|
|
194
|
+
*/
|
|
195
|
+
requireAck?: boolean;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Send file options
|
|
199
|
+
*/
|
|
200
|
+
export interface SendFileOptions extends SendOptions {
|
|
201
|
+
/** File MIME type */
|
|
202
|
+
mimeType?: string;
|
|
203
|
+
/** File name */
|
|
204
|
+
fileName?: string;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Cookie options (consistent with Express)
|
|
208
|
+
*/
|
|
209
|
+
export interface CookieOptions {
|
|
210
|
+
/** Cookie expiration time */
|
|
211
|
+
expires?: Date;
|
|
212
|
+
/** Cookie maximum age (seconds) */
|
|
213
|
+
maxAge?: number;
|
|
214
|
+
/** Cookie domain */
|
|
215
|
+
domain?: string;
|
|
216
|
+
/** Cookie path */
|
|
217
|
+
path?: string;
|
|
218
|
+
/** Whether to send only over HTTPS connections */
|
|
219
|
+
secure?: boolean;
|
|
220
|
+
/** Whether to forbid JavaScript access */
|
|
221
|
+
httpOnly?: boolean;
|
|
222
|
+
/** Cookie SameSite attribute */
|
|
223
|
+
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Server Response object (similar to express)
|
|
227
|
+
*/
|
|
228
|
+
export interface ServerResponse {
|
|
229
|
+
/**
|
|
230
|
+
* Send response data
|
|
231
|
+
* @param data Response data
|
|
232
|
+
* @param options Send options
|
|
233
|
+
* @returns Promise<boolean> - If requireAck is true, resolves after client confirms receipt; otherwise resolves immediately
|
|
234
|
+
*/
|
|
235
|
+
send(data: any, options?: SendOptions): Promise<boolean>;
|
|
236
|
+
/**
|
|
237
|
+
* Send JSON response
|
|
238
|
+
* @param data JSON data
|
|
239
|
+
* @param options Send options
|
|
240
|
+
* @returns Promise<boolean> - If requireAck is true, resolves after client confirms receipt; otherwise resolves immediately
|
|
241
|
+
*/
|
|
242
|
+
json(data: any, options?: SendOptions): Promise<boolean>;
|
|
243
|
+
/**
|
|
244
|
+
* Send file (base64 encoded)
|
|
245
|
+
* @param content File content
|
|
246
|
+
* @param options Send options (includes mimeType, fileName, requireAck)
|
|
247
|
+
* @returns Promise<boolean> - If requireAck is true, resolves after client confirms receipt; otherwise resolves immediately
|
|
248
|
+
*/
|
|
249
|
+
sendFile(content: string | Blob | File, options?: SendFileOptions): Promise<boolean>;
|
|
250
|
+
/**
|
|
251
|
+
* Send stream response
|
|
252
|
+
* @param stream Writable stream object
|
|
253
|
+
* @returns Promise<void> - Resolves after stream transfer completes
|
|
254
|
+
*/
|
|
255
|
+
sendStream(stream: import('../stream').IframeWritableStream): Promise<void>;
|
|
256
|
+
/** Set response status code (chainable) */
|
|
257
|
+
status(code: number): ServerResponse;
|
|
258
|
+
/** Set response header (consistent with Express, returns void) */
|
|
259
|
+
setHeader(name: string, value: string | number | string[]): void;
|
|
260
|
+
/** Set response header (chainable version, compatible with Express res.set) */
|
|
261
|
+
set(name: string, value: string | number | string[]): ServerResponse;
|
|
262
|
+
/** Set response cookie (consistent with Express, uses cookie method) */
|
|
263
|
+
cookie(name: string, value: string, options?: CookieOptions): ServerResponse;
|
|
264
|
+
/** Clear cookie (consistent with Express) */
|
|
265
|
+
clearCookie(name: string, options?: CookieOptions): ServerResponse;
|
|
266
|
+
/** Current status code */
|
|
267
|
+
statusCode: number;
|
|
268
|
+
/** Response headers (Set-Cookie is a string array) */
|
|
269
|
+
headers: Record<string, string | string[]>;
|
|
270
|
+
/** Internal property: whether response has been sent */
|
|
271
|
+
_sent?: boolean;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Path matcher type (supports string, RegExp, PathPattern, Array)
|
|
275
|
+
*/
|
|
276
|
+
export type PathMatcher = string | RegExp | Array<string | RegExp>;
|
|
277
|
+
/**
|
|
278
|
+
* Middleware function type
|
|
279
|
+
*/
|
|
280
|
+
export type Middleware = (req: ServerRequest, res: ServerResponse, next: () => void | Promise<void>) => void | Promise<void>;
|
|
281
|
+
/**
|
|
282
|
+
* Server handler function (similar to express)
|
|
283
|
+
*/
|
|
284
|
+
export type ServerHandler = (req: ServerRequest, res: ServerResponse) => any | Promise<any>;
|
|
285
|
+
/**
|
|
286
|
+
* server.on/off event names (low-level)
|
|
287
|
+
*/
|
|
288
|
+
export type ServerEventName = 'request' | 'ack' | 'async' | 'response' | 'error' | 'received' | 'ping' | 'pong';
|
|
289
|
+
/**
|
|
290
|
+
* Client interface
|
|
291
|
+
*/
|
|
292
|
+
export interface RequestIframeClient {
|
|
293
|
+
/** Interceptors (only effective for send) */
|
|
294
|
+
interceptors: {
|
|
295
|
+
request: import('../interceptors').RequestInterceptorManager;
|
|
296
|
+
response: import('../interceptors').ResponseInterceptorManager;
|
|
297
|
+
};
|
|
298
|
+
/** Send request */
|
|
299
|
+
send<T = any>(path: string, body?: Record<string, any>, options?: RequestOptions): Promise<Response<T>>;
|
|
300
|
+
/** Check if server is reachable */
|
|
301
|
+
isConnect(): Promise<boolean>;
|
|
302
|
+
/**
|
|
303
|
+
* Get all cookies matching the specified path
|
|
304
|
+
* @param path Request path, returns all cookies if not provided
|
|
305
|
+
*/
|
|
306
|
+
getCookies(path?: string): Record<string, string>;
|
|
307
|
+
/**
|
|
308
|
+
* Get specified cookie
|
|
309
|
+
* @param name Cookie name
|
|
310
|
+
* @param path Path (optional)
|
|
311
|
+
*/
|
|
312
|
+
getCookie(name: string, path?: string): string | undefined;
|
|
313
|
+
/**
|
|
314
|
+
* Set cookie
|
|
315
|
+
* @param name Cookie name
|
|
316
|
+
* @param value Cookie value
|
|
317
|
+
* @param options Cookie options (path, etc.)
|
|
318
|
+
*/
|
|
319
|
+
setCookie(name: string, value: string, options?: {
|
|
320
|
+
path?: string;
|
|
321
|
+
expires?: Date;
|
|
322
|
+
maxAge?: number;
|
|
323
|
+
}): void;
|
|
324
|
+
/**
|
|
325
|
+
* Delete specified cookie
|
|
326
|
+
* @param name Cookie name
|
|
327
|
+
* @param path Path (optional, defaults to '/')
|
|
328
|
+
*/
|
|
329
|
+
removeCookie(name: string, path?: string): void;
|
|
330
|
+
/**
|
|
331
|
+
* Clear all cookies
|
|
332
|
+
*/
|
|
333
|
+
clearCookies(): void;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Client server interface (used on client side, handles responses only)
|
|
337
|
+
*/
|
|
338
|
+
export interface RequestIframeClientServer {
|
|
339
|
+
/** Destroy server (remove message listener) */
|
|
340
|
+
destroy(): void;
|
|
341
|
+
/** Internal method: listen to low-level events */
|
|
342
|
+
_on(event: ServerEventName, fn: (payload: any) => void): void;
|
|
343
|
+
/** Internal method: unsubscribe from low-level events */
|
|
344
|
+
_off(event: ServerEventName, fn?: (payload: any) => void): void;
|
|
345
|
+
/** Internal method: for client to register pending Promise for response */
|
|
346
|
+
_registerPendingRequest(requestId: string, resolve: (data: PostMessageData) => void, reject: (error: Error) => void, origin?: string): void;
|
|
347
|
+
/** Internal method: for client to cancel waiting */
|
|
348
|
+
_unregisterPendingRequest(requestId: string): void;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Server interface (used on server side, handles requests and responses)
|
|
352
|
+
*/
|
|
353
|
+
export interface RequestIframeServer {
|
|
354
|
+
/** Message isolation key (read-only) */
|
|
355
|
+
readonly secretKey?: string;
|
|
356
|
+
/** Whether message handling is enabled */
|
|
357
|
+
readonly isOpen: boolean;
|
|
358
|
+
/** Enable message handling (register message handler) */
|
|
359
|
+
open(): void;
|
|
360
|
+
/** Disable message handling (unregister message handler, but don't release resources) */
|
|
361
|
+
close(): void;
|
|
362
|
+
/**
|
|
363
|
+
* Register middleware
|
|
364
|
+
* - use(middleware): Register global middleware (executed before all routes)
|
|
365
|
+
* - use(path, middleware): Register path-matching middleware (path supports string, RegExp, PathPattern, Array)
|
|
366
|
+
*/
|
|
367
|
+
use(middleware: Middleware): void;
|
|
368
|
+
use(path: PathMatcher, middleware: Middleware): void;
|
|
369
|
+
/** Register route handler */
|
|
370
|
+
on(path: string, handler: ServerHandler): void;
|
|
371
|
+
/** Unregister route handler */
|
|
372
|
+
off(path: string): void;
|
|
373
|
+
/** Batch register route handlers (via key: value object) */
|
|
374
|
+
map(handlers: Record<string, ServerHandler>): void;
|
|
375
|
+
/** Destroy server (close and release resources) */
|
|
376
|
+
destroy(): void;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* requestIframeClient entry options
|
|
380
|
+
*/
|
|
381
|
+
export interface RequestIframeClientOptions extends RequestDefaults {
|
|
382
|
+
/**
|
|
383
|
+
* Message isolation key.
|
|
384
|
+
* If configured, automatically adds a unified prefix to the path of all messages (to avoid conflicts between different businesses), and only processes framework messages with the same secretKey.
|
|
385
|
+
*/
|
|
386
|
+
secretKey?: string;
|
|
387
|
+
/**
|
|
388
|
+
* Whether to enable trace mode.
|
|
389
|
+
* If true, logs will be printed at various points such as before and after requests.
|
|
390
|
+
*/
|
|
391
|
+
trace?: boolean;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* requestIframeServer entry options
|
|
395
|
+
*/
|
|
396
|
+
export interface RequestIframeServerOptions extends Pick<RequestDefaults, 'ackTimeout'> {
|
|
397
|
+
/**
|
|
398
|
+
* Message isolation key.
|
|
399
|
+
* If configured, automatically adds a unified prefix to the path of all messages (to avoid conflicts between different businesses), and only processes framework messages with the same secretKey.
|
|
400
|
+
*/
|
|
401
|
+
secretKey?: string;
|
|
402
|
+
/**
|
|
403
|
+
* Whether to enable trace mode.
|
|
404
|
+
* If true, logs will be printed at various points such as before and after requests, server receive/respond, etc.
|
|
405
|
+
*/
|
|
406
|
+
trace?: boolean;
|
|
407
|
+
}
|
|
408
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,+HAA+H;IAC/H,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4GAA4G;IAC5G,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kHAAkH;IAClH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,wBAAwB;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,OAAO,CAAC,EAAE,M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G;AACH,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC;IACrF;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MessageChannel, ChannelType } from '../message';
|
|
2
|
+
/**
|
|
3
|
+
* Get or create MessageChannel instance
|
|
4
|
+
* - Within the same window, only one channel is created per type + secretKey combination
|
|
5
|
+
* - Uses reference counting to manage lifecycle
|
|
6
|
+
* @param secretKey secret key for message isolation
|
|
7
|
+
* @param type channel type (defaults to postMessage)
|
|
8
|
+
*/
|
|
9
|
+
export declare function getOrCreateMessageChannel(secretKey?: string, type?: ChannelType): MessageChannel;
|
|
10
|
+
/**
|
|
11
|
+
* Release MessageChannel reference
|
|
12
|
+
* - When reference count reaches 0, destroy channel and remove from cache
|
|
13
|
+
*/
|
|
14
|
+
export declare function releaseMessageChannel(channel: MessageChannel): void;
|
|
15
|
+
/**
|
|
16
|
+
* Clear all MessageChannel cache (mainly for testing)
|
|
17
|
+
*/
|
|
18
|
+
export declare function clearMessageChannelCache(): void;
|
|
19
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/utils/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA2BzD;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,CAAC,EAAE,MAAM,EAClB,IAAI,GAAE,WAAsC,GAC3C,cAAc,CAYhB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAYnE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAM/C"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.clearMessageChannelCache = clearMessageChannelCache;
|
|
7
|
+
exports.getOrCreateMessageChannel = getOrCreateMessageChannel;
|
|
8
|
+
exports.releaseMessageChannel = releaseMessageChannel;
|
|
9
|
+
require("core-js/modules/es.array.iterator.js");
|
|
10
|
+
require("core-js/modules/es.map.js");
|
|
11
|
+
require("core-js/modules/web.dom-collections.for-each.js");
|
|
12
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
13
|
+
var _message = require("../message");
|
|
14
|
+
/**
|
|
15
|
+
* Global cache Symbol (used to store MessageChannel instance cache on window)
|
|
16
|
+
* Using Symbol.for() ensures multiple library copies share the same cache, avoiding multiple instance creation
|
|
17
|
+
*/
|
|
18
|
+
var MESSAGE_CHANNEL_CACHE_SYMBOL = Symbol.for('__requestIframeMessageChannelCache__');
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get the MessageChannel cache from window
|
|
22
|
+
*/
|
|
23
|
+
function getChannelCacheForWindow(win) {
|
|
24
|
+
if (!(MESSAGE_CHANNEL_CACHE_SYMBOL in win)) {
|
|
25
|
+
win[MESSAGE_CHANNEL_CACHE_SYMBOL] = new Map();
|
|
26
|
+
}
|
|
27
|
+
return win[MESSAGE_CHANNEL_CACHE_SYMBOL];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Generate cache key
|
|
32
|
+
* Cache key format: "type:secretKey" or "type:" when no secretKey
|
|
33
|
+
* Different channel types use separate cache entries
|
|
34
|
+
*/
|
|
35
|
+
function getCacheKey(type, secretKey) {
|
|
36
|
+
return `${type}:${secretKey !== null && secretKey !== void 0 ? secretKey : ''}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get or create MessageChannel instance
|
|
41
|
+
* - Within the same window, only one channel is created per type + secretKey combination
|
|
42
|
+
* - Uses reference counting to manage lifecycle
|
|
43
|
+
* @param secretKey secret key for message isolation
|
|
44
|
+
* @param type channel type (defaults to postMessage)
|
|
45
|
+
*/
|
|
46
|
+
function getOrCreateMessageChannel(secretKey, type = _message.ChannelType.POST_MESSAGE) {
|
|
47
|
+
var cache = getChannelCacheForWindow(window);
|
|
48
|
+
var key = getCacheKey(type, secretKey);
|
|
49
|
+
var channel = cache.get(key);
|
|
50
|
+
if (!channel) {
|
|
51
|
+
channel = new _message.MessageChannel(secretKey, type);
|
|
52
|
+
cache.set(key, channel);
|
|
53
|
+
}
|
|
54
|
+
channel.addRef();
|
|
55
|
+
return channel;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Release MessageChannel reference
|
|
60
|
+
* - When reference count reaches 0, destroy channel and remove from cache
|
|
61
|
+
*/
|
|
62
|
+
function releaseMessageChannel(channel) {
|
|
63
|
+
var refCount = channel.release();
|
|
64
|
+
if (refCount <= 0) {
|
|
65
|
+
var cache = getChannelCacheForWindow(window);
|
|
66
|
+
var key = getCacheKey(channel.type, channel.secretKey);
|
|
67
|
+
if (cache.get(key) === channel) {
|
|
68
|
+
cache.delete(key);
|
|
69
|
+
channel.destroy();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Clear all MessageChannel cache (mainly for testing)
|
|
76
|
+
*/
|
|
77
|
+
function clearMessageChannelCache() {
|
|
78
|
+
var cache = getChannelCacheForWindow(window);
|
|
79
|
+
cache.forEach(channel => {
|
|
80
|
+
channel.destroy();
|
|
81
|
+
});
|
|
82
|
+
cache.clear();
|
|
83
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cookie management utilities
|
|
3
|
+
* Implements browser-like Cookie mechanism
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Cookie storage item
|
|
7
|
+
*/
|
|
8
|
+
export interface CookieItem {
|
|
9
|
+
/** Cookie name */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Cookie value */
|
|
12
|
+
value: string;
|
|
13
|
+
/** Path, defaults to '/' */
|
|
14
|
+
path: string;
|
|
15
|
+
/** Expiration time (timestamp) */
|
|
16
|
+
expires?: number;
|
|
17
|
+
/** HttpOnly flag (marker only, no actual effect in postMessage) */
|
|
18
|
+
httpOnly?: boolean;
|
|
19
|
+
/** Secure flag (marker only) */
|
|
20
|
+
secure?: boolean;
|
|
21
|
+
/** SameSite attribute (marker only) */
|
|
22
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Cookie options (for res.cookie)
|
|
26
|
+
*/
|
|
27
|
+
export interface CookieOptions {
|
|
28
|
+
/** Path, defaults to '/' */
|
|
29
|
+
path?: string;
|
|
30
|
+
/** Expiration date */
|
|
31
|
+
expires?: Date;
|
|
32
|
+
/** Max-Age (seconds) */
|
|
33
|
+
maxAge?: number;
|
|
34
|
+
/** HttpOnly flag */
|
|
35
|
+
httpOnly?: boolean;
|
|
36
|
+
/** Secure flag */
|
|
37
|
+
secure?: boolean;
|
|
38
|
+
/** SameSite attribute */
|
|
39
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parse Set-Cookie string to CookieItem
|
|
43
|
+
* @param setCookieStr Set-Cookie string, e.g., "token=abc; Path=/; HttpOnly"
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseSetCookie(setCookieStr: string): CookieItem | null;
|
|
46
|
+
/**
|
|
47
|
+
* Serialize CookieItem to Set-Cookie string
|
|
48
|
+
*/
|
|
49
|
+
export declare function serializeSetCookie(cookie: CookieItem): string;
|
|
50
|
+
/**
|
|
51
|
+
* Create Set-Cookie string from CookieOptions
|
|
52
|
+
*/
|
|
53
|
+
export declare function createSetCookie(name: string, value: string, options?: CookieOptions): string;
|
|
54
|
+
/**
|
|
55
|
+
* Create Set-Cookie string to delete Cookie
|
|
56
|
+
*/
|
|
57
|
+
export declare function createClearCookie(name: string, options?: {
|
|
58
|
+
path?: string;
|
|
59
|
+
}): string;
|
|
60
|
+
/**
|
|
61
|
+
* Check if request path matches Cookie's path attribute
|
|
62
|
+
* Implements RFC 6265 path matching algorithm
|
|
63
|
+
* @param requestPath request path, e.g., "/api/users"
|
|
64
|
+
* @param cookiePath Cookie's path attribute, e.g., "/api"
|
|
65
|
+
*/
|
|
66
|
+
export declare function matchCookiePath(requestPath: string, cookiePath: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Cookie storage manager
|
|
69
|
+
*/
|
|
70
|
+
export declare class CookieStore {
|
|
71
|
+
private cookies;
|
|
72
|
+
/**
|
|
73
|
+
* Generate unique key for Cookie
|
|
74
|
+
*/
|
|
75
|
+
private getKey;
|
|
76
|
+
/**
|
|
77
|
+
* Set Cookie
|
|
78
|
+
*/
|
|
79
|
+
set(cookie: CookieItem): void;
|
|
80
|
+
/**
|
|
81
|
+
* Set Cookie from Set-Cookie string
|
|
82
|
+
*/
|
|
83
|
+
setFromSetCookie(setCookieStr: string): void;
|
|
84
|
+
/**
|
|
85
|
+
* Remove Cookie
|
|
86
|
+
*/
|
|
87
|
+
remove(name: string, path?: string): void;
|
|
88
|
+
/**
|
|
89
|
+
* Get all Cookies matching specified path
|
|
90
|
+
* @param requestPath request path
|
|
91
|
+
* @returns matching cookies, format: Record<string, string>
|
|
92
|
+
*/
|
|
93
|
+
getForPath(requestPath: string): Record<string, string>;
|
|
94
|
+
/**
|
|
95
|
+
* Get Cookie value by name
|
|
96
|
+
* @param name Cookie name
|
|
97
|
+
* @param path path (optional, returns first match if not specified)
|
|
98
|
+
*/
|
|
99
|
+
get(name: string, path?: string): string | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Get all Cookies (with full info)
|
|
102
|
+
*/
|
|
103
|
+
getAll(): CookieItem[];
|
|
104
|
+
/**
|
|
105
|
+
* Get all Cookies (simple format)
|
|
106
|
+
*/
|
|
107
|
+
getAllSimple(): Record<string, string>;
|
|
108
|
+
/**
|
|
109
|
+
* Clear all Cookies
|
|
110
|
+
*/
|
|
111
|
+
clear(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Cleanup expired Cookies
|
|
114
|
+
*/
|
|
115
|
+
cleanup(): void;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=cookie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../src/utils/cookie.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,mBAAmB;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gCAAgC;IAChC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,uCAAuC;IACvC,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,4BAA4B;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,sBAAsB;IACtB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,wBAAwB;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oBAAoB;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kBAAkB;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,yBAAyB;IACzB,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;CACtC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM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