request-iframe 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/QUICKSTART.CN.md +4 -2
- package/QUICKSTART.md +4 -2
- package/README.CN.md +129 -33
- package/README.md +116 -15
- package/cdn/request-iframe-react.umd.js +3354 -0
- package/cdn/request-iframe-react.umd.js.map +1 -0
- package/cdn/request-iframe-react.umd.min.js +2 -0
- package/cdn/request-iframe-react.umd.min.js.map +1 -0
- package/cdn/request-iframe.umd.js +19735 -0
- package/cdn/request-iframe.umd.js.map +1 -0
- package/cdn/request-iframe.umd.min.js +4 -0
- package/cdn/request-iframe.umd.min.js.map +1 -0
- package/esm/api/client.js +29 -21
- package/esm/api/endpoint.js +229 -0
- package/esm/api/server.js +16 -8
- package/esm/constants/debug.js +17 -0
- package/esm/constants/index.js +84 -67
- package/esm/constants/log.js +11 -0
- package/esm/constants/messages.js +3 -0
- package/esm/constants/warn-once.js +15 -0
- package/esm/endpoint/facade.js +390 -0
- package/esm/endpoint/heartbeat/heartbeat.js +60 -0
- package/esm/endpoint/heartbeat/ping.js +20 -0
- package/esm/endpoint/index.js +13 -0
- package/esm/endpoint/infra/hub.js +316 -0
- package/esm/endpoint/infra/inbox.js +232 -0
- package/esm/endpoint/infra/outbox.js +408 -0
- package/esm/endpoint/stream/dispatcher.js +58 -0
- package/esm/endpoint/stream/errors.js +27 -0
- package/esm/endpoint/stream/factory.js +76 -0
- package/esm/endpoint/stream/file-auto-resolve.js +34 -0
- package/esm/endpoint/stream/file-writable.js +105 -0
- package/esm/endpoint/stream/handler.js +26 -0
- package/esm/{core → impl}/client.js +240 -317
- package/esm/{core → impl}/response.js +113 -155
- package/esm/impl/server.js +568 -0
- package/esm/index.js +13 -6
- package/esm/message/ack.js +27 -0
- package/esm/message/channel-cache.js +108 -0
- package/esm/message/channel.js +90 -4
- package/esm/message/dispatcher.js +88 -75
- package/esm/stream/error.js +22 -0
- package/esm/stream/index.js +3 -1
- package/esm/stream/readable-stream.js +45 -9
- package/esm/stream/stream-core.js +7 -2
- package/esm/stream/writable-stream.js +97 -26
- package/esm/utils/blob.js +16 -0
- package/esm/utils/cache.js +25 -76
- package/esm/utils/content-type.js +81 -0
- package/esm/utils/debug.js +156 -179
- package/esm/utils/hooks.js +130 -0
- package/esm/utils/id.js +14 -0
- package/esm/utils/iframe.js +20 -0
- package/esm/utils/index.js +11 -163
- package/esm/utils/is.js +3 -0
- package/esm/utils/logger.js +55 -0
- package/esm/utils/promise.js +3 -0
- package/esm/utils/window.js +31 -0
- package/library/api/client.d.ts.map +1 -1
- package/library/api/client.js +30 -22
- package/library/api/endpoint.d.ts +23 -0
- package/library/api/endpoint.d.ts.map +1 -0
- package/library/api/endpoint.js +235 -0
- package/library/api/server.d.ts +4 -1
- package/library/api/server.d.ts.map +1 -1
- package/library/api/server.js +16 -8
- package/library/constants/debug.d.ts +18 -0
- package/library/constants/debug.d.ts.map +1 -0
- package/library/constants/debug.js +23 -0
- package/library/constants/index.d.ts +22 -2
- package/library/constants/index.d.ts.map +1 -1
- package/library/constants/index.js +110 -67
- package/library/constants/log.d.ts +12 -0
- package/library/constants/log.d.ts.map +1 -0
- package/library/constants/log.js +17 -0
- package/library/constants/messages.d.ts +3 -0
- package/library/constants/messages.d.ts.map +1 -1
- package/library/constants/messages.js +3 -0
- package/library/constants/warn-once.d.ts +12 -0
- package/library/constants/warn-once.d.ts.map +1 -0
- package/library/constants/warn-once.js +22 -0
- package/library/endpoint/facade.d.ts +238 -0
- package/library/endpoint/facade.d.ts.map +1 -0
- package/library/endpoint/facade.js +398 -0
- package/library/endpoint/heartbeat/heartbeat.d.ts +34 -0
- package/library/endpoint/heartbeat/heartbeat.d.ts.map +1 -0
- package/library/endpoint/heartbeat/heartbeat.js +67 -0
- package/library/endpoint/heartbeat/ping.d.ts +18 -0
- package/library/endpoint/heartbeat/ping.d.ts.map +1 -0
- package/library/endpoint/heartbeat/ping.js +26 -0
- package/library/endpoint/index.d.ts +16 -0
- package/library/endpoint/index.d.ts.map +1 -0
- package/library/endpoint/index.js +114 -0
- package/library/endpoint/infra/hub.d.ts +170 -0
- package/library/endpoint/infra/hub.d.ts.map +1 -0
- package/library/endpoint/infra/hub.js +323 -0
- package/library/endpoint/infra/inbox.d.ts +73 -0
- package/library/endpoint/infra/inbox.d.ts.map +1 -0
- package/library/endpoint/infra/inbox.js +239 -0
- package/library/endpoint/infra/outbox.d.ts +149 -0
- package/library/endpoint/infra/outbox.d.ts.map +1 -0
- package/library/endpoint/infra/outbox.js +415 -0
- package/library/endpoint/stream/dispatcher.d.ts +33 -0
- package/library/endpoint/stream/dispatcher.d.ts.map +1 -0
- package/library/endpoint/stream/dispatcher.js +66 -0
- package/library/endpoint/stream/errors.d.ts +20 -0
- package/library/endpoint/stream/errors.d.ts.map +1 -0
- package/library/endpoint/stream/errors.js +32 -0
- package/library/endpoint/stream/factory.d.ts +44 -0
- package/library/endpoint/stream/factory.d.ts.map +1 -0
- package/library/endpoint/stream/factory.js +82 -0
- package/library/endpoint/stream/file-auto-resolve.d.ts +26 -0
- package/library/endpoint/stream/file-auto-resolve.d.ts.map +1 -0
- package/library/endpoint/stream/file-auto-resolve.js +41 -0
- package/library/endpoint/stream/file-writable.d.ts +33 -0
- package/library/endpoint/stream/file-writable.d.ts.map +1 -0
- package/library/endpoint/stream/file-writable.js +115 -0
- package/library/endpoint/stream/handler.d.ts +20 -0
- package/library/endpoint/stream/handler.d.ts.map +1 -0
- package/library/endpoint/stream/handler.js +32 -0
- package/library/{core → impl}/client.d.ts +16 -13
- package/library/impl/client.d.ts.map +1 -0
- package/library/{core → impl}/client.js +251 -330
- package/library/{core → impl}/request.d.ts.map +1 -1
- package/library/{core → impl}/response.d.ts +5 -10
- package/library/impl/response.d.ts.map +1 -0
- package/library/{core → impl}/response.js +113 -155
- package/library/{core → impl}/server.d.ts +22 -55
- package/library/impl/server.d.ts.map +1 -0
- package/library/impl/server.js +575 -0
- package/library/index.d.ts +13 -6
- package/library/index.d.ts.map +1 -1
- package/library/index.js +16 -16
- package/library/message/ack.d.ts +15 -0
- package/library/message/ack.d.ts.map +1 -0
- package/library/message/ack.js +33 -0
- package/library/message/channel-cache.d.ts +26 -0
- package/library/message/channel-cache.d.ts.map +1 -0
- package/library/message/channel-cache.js +115 -0
- package/library/message/channel.d.ts +53 -6
- package/library/message/channel.d.ts.map +1 -1
- package/library/message/channel.js +94 -8
- package/library/message/dispatcher.d.ts +7 -0
- package/library/message/dispatcher.d.ts.map +1 -1
- package/library/message/dispatcher.js +89 -76
- package/library/stream/error.d.ts +24 -0
- package/library/stream/error.d.ts.map +1 -0
- package/library/stream/error.js +29 -0
- package/library/stream/index.d.ts +4 -1
- package/library/stream/index.d.ts.map +1 -1
- package/library/stream/index.js +7 -4
- package/library/stream/readable-stream.d.ts.map +1 -1
- package/library/stream/readable-stream.js +46 -10
- package/library/stream/stream-core.d.ts.map +1 -1
- package/library/stream/stream-core.js +6 -1
- package/library/stream/writable-stream.d.ts.map +1 -1
- package/library/stream/writable-stream.js +99 -28
- package/library/types/index.d.ts +15 -19
- package/library/types/index.d.ts.map +1 -1
- package/library/utils/blob.d.ts +3 -0
- package/library/utils/blob.d.ts.map +1 -0
- package/library/utils/blob.js +22 -0
- package/library/utils/cache.d.ts +10 -20
- package/library/utils/cache.d.ts.map +1 -1
- package/library/utils/cache.js +25 -79
- package/library/utils/content-type.d.ts +13 -0
- package/library/utils/content-type.d.ts.map +1 -0
- package/library/utils/content-type.js +87 -0
- package/library/utils/debug.d.ts.map +1 -1
- package/library/utils/debug.js +155 -177
- package/library/utils/hooks.d.ts +30 -0
- package/library/utils/hooks.d.ts.map +1 -0
- package/library/utils/hooks.js +139 -0
- package/library/utils/id.d.ts +9 -0
- package/library/utils/id.d.ts.map +1 -0
- package/library/utils/id.js +21 -0
- package/library/utils/iframe.d.ts +5 -0
- package/library/utils/iframe.d.ts.map +1 -0
- package/library/utils/iframe.js +25 -0
- package/library/utils/index.d.ts +7 -34
- package/library/utils/index.d.ts.map +1 -1
- package/library/utils/index.js +58 -194
- package/library/utils/is.d.ts +2 -0
- package/library/utils/is.d.ts.map +1 -0
- package/library/utils/is.js +9 -0
- package/library/utils/logger.d.ts +13 -0
- package/library/utils/logger.d.ts.map +1 -0
- package/library/utils/logger.js +63 -0
- package/library/utils/promise.d.ts +2 -0
- package/library/utils/promise.d.ts.map +1 -0
- package/library/utils/promise.js +9 -0
- package/library/utils/window.d.ts +2 -0
- package/library/utils/window.d.ts.map +1 -0
- package/library/utils/window.js +38 -0
- package/package.json +49 -2
- package/react/package.json +2 -1
- package/esm/core/client-server.js +0 -294
- package/esm/core/server.js +0 -776
- package/library/core/client-server.d.ts +0 -97
- package/library/core/client-server.d.ts.map +0 -1
- package/library/core/client-server.js +0 -301
- package/library/core/client.d.ts.map +0 -1
- package/library/core/response.d.ts.map +0 -1
- package/library/core/server.d.ts.map +0 -1
- package/library/core/server.js +0 -781
- /package/esm/{core → impl}/request.js +0 -0
- /package/library/{core → impl}/request.d.ts +0 -0
- /package/library/{core → impl}/request.js +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "core-js/modules/es.array.iterator.js";
|
|
2
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
3
|
+
import "core-js/modules/web.url.js";
|
|
4
|
+
import "core-js/modules/web.url.to-json.js";
|
|
5
|
+
import "core-js/modules/web.url-search-params.js";
|
|
6
|
+
import { OriginConstant } from '../constants';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Derive targetOrigin from iframe.src
|
|
10
|
+
*/
|
|
11
|
+
export function getIframeTargetOrigin(iframe) {
|
|
12
|
+
if (!iframe.src) {
|
|
13
|
+
return OriginConstant.ANY;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
return new URL(iframe.src).origin;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
return OriginConstant.ANY;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/esm/utils/index.js
CHANGED
|
@@ -1,78 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import "core-js/modules/web.url.js";
|
|
8
|
-
import "core-js/modules/web.url.to-json.js";
|
|
9
|
-
import "core-js/modules/web.url-search-params.js";
|
|
10
|
-
import { OriginConstant } from '../constants';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Generate unique request ID
|
|
14
|
-
*/
|
|
15
|
-
export function generateRequestId() {
|
|
16
|
-
return `req_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Generate unique instance ID
|
|
21
|
-
*/
|
|
22
|
-
export function generateInstanceId() {
|
|
23
|
-
return `inst_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Derive targetOrigin from iframe.src
|
|
28
|
-
*/
|
|
29
|
-
export function getIframeTargetOrigin(iframe) {
|
|
30
|
-
if (!iframe.src) {
|
|
31
|
-
return OriginConstant.ANY;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
return new URL(iframe.src).origin;
|
|
35
|
-
} catch (e) {
|
|
36
|
-
return OriginConstant.ANY;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export function isPromise(value) {
|
|
40
|
-
return value !== null && typeof value === 'object' && 'then' in value;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Check if target window is still available (not closed/removed)
|
|
45
|
-
* @param targetWindow Target window to check
|
|
46
|
-
* @returns true if window is available, false otherwise
|
|
47
|
-
*/
|
|
48
|
-
export function isWindowAvailable(targetWindow) {
|
|
49
|
-
if (!targetWindow) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
try {
|
|
53
|
-
// Must have postMessage to be a usable target
|
|
54
|
-
if (typeof targetWindow.postMessage !== 'function') {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// For windows opened via window.open(), check closed property
|
|
59
|
-
if ('closed' in targetWindow && targetWindow.closed === true) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Avoid touching cross-origin properties (like document) which may throw.
|
|
64
|
-
// If closed is not true and postMessage exists, treat as available.
|
|
65
|
-
return true;
|
|
66
|
-
} catch (e) {
|
|
67
|
-
// If accessing window properties throws an error, window is likely closed
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
1
|
+
export { generateRequestId, generateInstanceId } from './id';
|
|
2
|
+
export { getIframeTargetOrigin } from './iframe';
|
|
3
|
+
export { isPromise } from './promise';
|
|
4
|
+
export { isFunction } from './is';
|
|
5
|
+
export { isWindowAvailable } from './window';
|
|
6
|
+
export { detectContentType } from './content-type';
|
|
71
7
|
// Export protocol-related functions
|
|
72
8
|
export { createPostMessage, isValidPostMessage, validatePostMessage, validateProtocolVersion, isRequestIframeMessage, getProtocolVersion, isCompatibleVersion } from './protocol';
|
|
73
9
|
|
|
74
|
-
//
|
|
75
|
-
|
|
10
|
+
// NOTE:
|
|
11
|
+
// Cache helpers are intentionally NOT re-exported here.
|
|
12
|
+
// - Server cache is an internal API and should be imported from `./cache` explicitly.
|
|
13
|
+
// - MessageChannel cache lives in `src/message/channel-cache.ts`.
|
|
76
14
|
|
|
77
15
|
// Export path matching functions
|
|
78
16
|
export * from './path-match';
|
|
@@ -87,94 +25,4 @@ export * from './cookie';
|
|
|
87
25
|
|
|
88
26
|
// Export Error class
|
|
89
27
|
export { RequestIframeError } from './error';
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Detect Content-Type based on data type
|
|
93
|
-
* @param data The data to detect Content-Type for
|
|
94
|
-
* @param options Options for detection
|
|
95
|
-
* @param options.checkStream Whether to check for IframeWritableStream (default: false)
|
|
96
|
-
* @param options.isIframeWritableStream Optional function to check if data is a stream (required if checkStream is true)
|
|
97
|
-
* @returns The detected Content-Type, or null if Content-Type should not be auto-set
|
|
98
|
-
*/
|
|
99
|
-
export function detectContentType(data, options) {
|
|
100
|
-
if (data === null || data === undefined) return null;
|
|
101
|
-
var _ref = options || {},
|
|
102
|
-
_ref$checkStream = _ref.checkStream,
|
|
103
|
-
checkStream = _ref$checkStream === void 0 ? false : _ref$checkStream,
|
|
104
|
-
isIframeWritableStream = _ref.isIframeWritableStream;
|
|
105
|
-
|
|
106
|
-
// Stream - handled separately (only for response)
|
|
107
|
-
if (checkStream && isIframeWritableStream) {
|
|
108
|
-
if (isIframeWritableStream(data)) {
|
|
109
|
-
return null; // Stream will be handled by sendStream
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// File
|
|
114
|
-
if (typeof File !== 'undefined' && data instanceof File) {
|
|
115
|
-
return data.type || 'application/octet-stream';
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Blob
|
|
119
|
-
if (typeof Blob !== 'undefined' && data instanceof Blob) {
|
|
120
|
-
return data.type || 'application/octet-stream';
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// ArrayBuffer
|
|
124
|
-
if (typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) {
|
|
125
|
-
return 'application/octet-stream';
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// FormData
|
|
129
|
-
if (typeof FormData !== 'undefined' && data instanceof FormData) {
|
|
130
|
-
// FormData typically doesn't need Content-Type header (browser sets it with boundary)
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// URLSearchParams
|
|
135
|
-
if (typeof URLSearchParams !== 'undefined' && data instanceof URLSearchParams) {
|
|
136
|
-
return 'application/x-www-form-urlencoded';
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// String - check if it's JSON string
|
|
140
|
-
if (typeof data === 'string') {
|
|
141
|
-
// Try to parse as JSON, if successful, treat as JSON
|
|
142
|
-
try {
|
|
143
|
-
JSON.parse(data);
|
|
144
|
-
return 'application/json';
|
|
145
|
-
} catch (_unused) {
|
|
146
|
-
return 'text/plain; charset=utf-8';
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Number, boolean - treat as JSON
|
|
151
|
-
if (typeof data === 'number' || typeof data === 'boolean') {
|
|
152
|
-
return 'application/json';
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Plain object or array - treat as JSON
|
|
156
|
-
if (typeof data === 'object') {
|
|
157
|
-
// Exclude common binary/file types (already checked above, but double-check for safety)
|
|
158
|
-
if (typeof Blob !== 'undefined' && data instanceof Blob) return null;
|
|
159
|
-
if (typeof File !== 'undefined' && data instanceof File) return null;
|
|
160
|
-
if (typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return null;
|
|
161
|
-
if (typeof FormData !== 'undefined' && data instanceof FormData) return null;
|
|
162
|
-
if (typeof URLSearchParams !== 'undefined' && data instanceof URLSearchParams) return null;
|
|
163
|
-
return 'application/json';
|
|
164
|
-
}
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** Convert Blob to base64 string */
|
|
169
|
-
export function blobToBase64(blob) {
|
|
170
|
-
return new Promise((resolve, reject) => {
|
|
171
|
-
var reader = new FileReader();
|
|
172
|
-
reader.onloadend = () => {
|
|
173
|
-
var result = reader.result;
|
|
174
|
-
var base64 = result.includes(',') ? result.split(',')[1] : result;
|
|
175
|
-
resolve(base64);
|
|
176
|
-
};
|
|
177
|
-
reader.onerror = reject;
|
|
178
|
-
reader.readAsDataURL(blob);
|
|
179
|
-
});
|
|
180
|
-
}
|
|
28
|
+
export { blobToBase64 } from './blob';
|
package/esm/utils/is.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { LogLevel } from '../constants';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Built-in leveled logger for request-iframe.
|
|
5
|
+
*
|
|
6
|
+
* - Default level is 'warn' (prints warn/error only)
|
|
7
|
+
* - Trace/debug tools can raise to 'info' or 'trace'
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var DEBUG_PREFIX = '[request-iframe]';
|
|
11
|
+
var levelOrder = {
|
|
12
|
+
[LogLevel.TRACE]: 10,
|
|
13
|
+
[LogLevel.INFO]: 20,
|
|
14
|
+
[LogLevel.WARN]: 30,
|
|
15
|
+
[LogLevel.ERROR]: 40,
|
|
16
|
+
[LogLevel.SILENT]: 100
|
|
17
|
+
};
|
|
18
|
+
var currentLevel = LogLevel.WARN;
|
|
19
|
+
export function getRequestIframeLogLevel() {
|
|
20
|
+
return currentLevel;
|
|
21
|
+
}
|
|
22
|
+
export function setRequestIframeLogLevel(level) {
|
|
23
|
+
currentLevel = level;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Ensure current log level is at least as verbose as `level`.
|
|
28
|
+
* - Example: current 'warn' + ensure 'trace' => becomes 'trace'
|
|
29
|
+
*/
|
|
30
|
+
export function ensureRequestIframeLogLevel(level) {
|
|
31
|
+
if (levelOrder[level] < levelOrder[currentLevel]) {
|
|
32
|
+
currentLevel = level;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function shouldLog(level) {
|
|
36
|
+
return levelOrder[level] >= levelOrder[currentLevel];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Log with level gating + unified prefix.
|
|
41
|
+
*/
|
|
42
|
+
export function requestIframeLog(level, message, data) {
|
|
43
|
+
if (currentLevel === LogLevel.SILENT) return;
|
|
44
|
+
if (!shouldLog(level)) return;
|
|
45
|
+
var timestamp = new Date().toISOString();
|
|
46
|
+
var prefix = `${DEBUG_PREFIX} [${timestamp}] [${level.toUpperCase()}]`;
|
|
47
|
+
var prefixStyle = 'font-weight:bold';
|
|
48
|
+
var messageStyle = level === LogLevel.INFO ? 'color: #1976d2' : '';
|
|
49
|
+
var method = level === LogLevel.TRACE ? 'debug' : level;
|
|
50
|
+
if (data !== undefined) {
|
|
51
|
+
console[method](`%c${prefix}%c ${message}`, prefixStyle, messageStyle, data);
|
|
52
|
+
} else {
|
|
53
|
+
console[method](`%c${prefix}%c ${message}`, prefixStyle, messageStyle);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if target window is still available (not closed/removed)
|
|
3
|
+
* @param targetWindow Target window to check
|
|
4
|
+
* @returns true if window is available, false otherwise
|
|
5
|
+
*/
|
|
6
|
+
import { isFunction } from './is';
|
|
7
|
+
export function isWindowAvailable(targetWindow) {
|
|
8
|
+
if (!targetWindow) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
/** Must have postMessage to be a usable target */
|
|
13
|
+
if (!isFunction(targetWindow.postMessage)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** For windows opened via window.open(), check closed property */
|
|
18
|
+
if ('closed' in targetWindow && targetWindow.closed === true) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Avoid touching cross-origin properties (like document) which may throw.
|
|
24
|
+
* If closed is not true and postMessage exists, treat as available.
|
|
25
|
+
*/
|
|
26
|
+
return true;
|
|
27
|
+
} catch (e) {
|
|
28
|
+
/** If accessing window properties throws an error, window is likely closed */
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -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;
|
|
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;AAS1F;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,iBAAiB,GAAG,MAAM,EAClC,OAAO,CAAC,EAAE,0BAA0B,GACnC,mBAAmB,CA2DrB;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAQtE"}
|
package/library/api/client.js
CHANGED
|
@@ -5,11 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.clearRequestIframeClientCache = clearRequestIframeClientCache;
|
|
7
7
|
exports.requestIframeClient = requestIframeClient;
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var _client = require("../
|
|
8
|
+
var _iframe = require("../utils/iframe");
|
|
9
|
+
var _id = require("../utils/id");
|
|
10
|
+
var _client = require("../impl/client");
|
|
11
11
|
var _debug = require("../utils/debug");
|
|
12
|
+
var _logger = require("../utils/logger");
|
|
12
13
|
var _constants = require("../constants");
|
|
14
|
+
var _channelCache = require("../message/channel-cache");
|
|
13
15
|
/**
|
|
14
16
|
* Create a client (for sending requests)
|
|
15
17
|
*
|
|
@@ -24,7 +26,7 @@ function requestIframeClient(target, options) {
|
|
|
24
26
|
if (target.tagName === 'IFRAME') {
|
|
25
27
|
var iframe = target;
|
|
26
28
|
targetWindow = iframe.contentWindow;
|
|
27
|
-
targetOrigin = (0,
|
|
29
|
+
targetOrigin = (0, _iframe.getIframeTargetOrigin)(iframe);
|
|
28
30
|
if (!targetWindow) {
|
|
29
31
|
throw {
|
|
30
32
|
message: _constants.Messages.IFRAME_NOT_READY,
|
|
@@ -45,18 +47,10 @@ function requestIframeClient(target, options) {
|
|
|
45
47
|
var secretKey = options === null || options === void 0 ? void 0 : options.secretKey;
|
|
46
48
|
|
|
47
49
|
// Generate instance ID first (will be used by both client and server)
|
|
48
|
-
var instanceId = (0,
|
|
50
|
+
var instanceId = (0, _id.generateInstanceId)();
|
|
49
51
|
|
|
50
|
-
// Create
|
|
51
|
-
var
|
|
52
|
-
secretKey,
|
|
53
|
-
autoOpen: options === null || options === void 0 ? void 0 : options.autoOpen,
|
|
54
|
-
autoAckMaxMetaLength: options === null || options === void 0 ? void 0 : options.autoAckMaxMetaLength,
|
|
55
|
-
autoAckMaxIdLength: options === null || options === void 0 ? void 0 : options.autoAckMaxIdLength
|
|
56
|
-
}, instanceId);
|
|
57
|
-
|
|
58
|
-
// Create client instance
|
|
59
|
-
var client = new _client.RequestIframeClientImpl(targetWindow, targetOrigin, server, {
|
|
52
|
+
// Create client instance (internally creates its core message server)
|
|
53
|
+
var client = new _client.RequestIframeClientImpl(targetWindow, targetOrigin, {
|
|
60
54
|
secretKey,
|
|
61
55
|
ackTimeout: options === null || options === void 0 ? void 0 : options.ackTimeout,
|
|
62
56
|
timeout: options === null || options === void 0 ? void 0 : options.timeout,
|
|
@@ -64,12 +58,23 @@ function requestIframeClient(target, options) {
|
|
|
64
58
|
returnData: options === null || options === void 0 ? void 0 : options.returnData,
|
|
65
59
|
headers: options === null || options === void 0 ? void 0 : options.headers,
|
|
66
60
|
allowedOrigins: options === null || options === void 0 ? void 0 : options.allowedOrigins,
|
|
67
|
-
validateOrigin: options === null || options === void 0 ? void 0 : options.validateOrigin
|
|
61
|
+
validateOrigin: options === null || options === void 0 ? void 0 : options.validateOrigin,
|
|
62
|
+
autoOpen: options === null || options === void 0 ? void 0 : options.autoOpen,
|
|
63
|
+
autoAckMaxMetaLength: options === null || options === void 0 ? void 0 : options.autoAckMaxMetaLength,
|
|
64
|
+
autoAckMaxIdLength: options === null || options === void 0 ? void 0 : options.autoAckMaxIdLength
|
|
68
65
|
}, instanceId);
|
|
69
66
|
|
|
70
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Trace/log level:
|
|
69
|
+
* - default: only warn/error will be printed (logger default)
|
|
70
|
+
* - if trace enabled: raise log level and (optionally) enable detailed debug interceptors
|
|
71
|
+
*/
|
|
71
72
|
if (options !== null && options !== void 0 && options.trace) {
|
|
72
|
-
|
|
73
|
+
var level = options.trace === true ? _constants.LogLevel.TRACE : options.trace;
|
|
74
|
+
(0, _logger.setRequestIframeLogLevel)(level);
|
|
75
|
+
if (level === _constants.LogLevel.TRACE || level === _constants.LogLevel.INFO) {
|
|
76
|
+
(0, _debug.setupClientDebugInterceptors)(client);
|
|
77
|
+
}
|
|
73
78
|
}
|
|
74
79
|
return client;
|
|
75
80
|
}
|
|
@@ -79,8 +84,11 @@ function requestIframeClient(target, options) {
|
|
|
79
84
|
* Note: This clears the shared message channel for the specified secretKey
|
|
80
85
|
*/
|
|
81
86
|
function clearRequestIframeClientCache(secretKey) {
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
// Client is not cached; this helper only clears shared MessageChannel cache.
|
|
88
|
+
// If secretKey is provided, only clear channels under that secretKey.
|
|
89
|
+
if (typeof secretKey === 'string') {
|
|
90
|
+
(0, _channelCache.clearMessageChannelCache)(secretKey);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
(0, _channelCache.clearMessageChannelCache)();
|
|
86
94
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RequestIframeClient, RequestIframeServer, RequestIframeClientOptions, RequestIframeServerOptions } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Endpoint facade type (client + server).
|
|
4
|
+
*/
|
|
5
|
+
export type RequestIframeEndpoint = RequestIframeClient & RequestIframeServer;
|
|
6
|
+
/**
|
|
7
|
+
* Endpoint facade options (client + server).
|
|
8
|
+
*
|
|
9
|
+
* - For client-side sending: uses RequestIframeClientOptions fields (targetOrigin, headers, etc.)
|
|
10
|
+
* - For server-side handling: uses RequestIframeServerOptions fields (middlewares, allowedOrigins, etc.)
|
|
11
|
+
*
|
|
12
|
+
* Note: overlapping fields (autoOpen/trace/allowedOrigins/validateOrigin/ackTimeout/autoAckMax*) apply to both sides.
|
|
13
|
+
*/
|
|
14
|
+
export type RequestIframeEndpointOptions = RequestIframeClientOptions & RequestIframeServerOptions;
|
|
15
|
+
/**
|
|
16
|
+
* Create an endpoint facade (client + server) for a peer window/iframe.
|
|
17
|
+
*
|
|
18
|
+
* It can:
|
|
19
|
+
* - send requests to the peer (client)
|
|
20
|
+
* - handle requests from the peer (server)
|
|
21
|
+
*/
|
|
22
|
+
export declare function requestIframeEndpoint(target: HTMLIFrameElement | Window, options?: RequestIframeEndpointOptions): RequestIframeEndpoint;
|
|
23
|
+
//# sourceMappingURL=endpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../src/api/endpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,mBAAmB,EACnB,mBAAmB,EACnB,0BAA0B,EAC1B,0BAA0B,EAC3B,MAAM,UAAU,CAAC;AAUlB;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,mBAAmB,GAAG,mBAAmB,CAAC;AAE9E;;;;;;;GAOG;AACH,MAAM,MAAM,4BAA4B,GAAG,0BAA0B,GAAG,0BAA0B,CAAC;AA8LnG;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,iBAAiB,GAAG,MAAM,EAClC,OAAO,CAAC,EAAE,4BAA4B,GACrC,qBAAqB,CAoCvB"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.requestIframeEndpoint = requestIframeEndpoint;
|
|
8
|
+
require("core-js/modules/es.array.map.js");
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _iframe = require("../utils/iframe");
|
|
11
|
+
var _id = require("../utils/id");
|
|
12
|
+
var _window = require("../utils/window");
|
|
13
|
+
var _client = require("../impl/client");
|
|
14
|
+
var _server = require("../impl/server");
|
|
15
|
+
var _debug = require("../utils/debug");
|
|
16
|
+
var _logger = require("../utils/logger");
|
|
17
|
+
var _constants = require("../constants");
|
|
18
|
+
/**
|
|
19
|
+
* Endpoint facade type (client + server).
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Endpoint facade options (client + server).
|
|
24
|
+
*
|
|
25
|
+
* - For client-side sending: uses RequestIframeClientOptions fields (targetOrigin, headers, etc.)
|
|
26
|
+
* - For server-side handling: uses RequestIframeServerOptions fields (middlewares, allowedOrigins, etc.)
|
|
27
|
+
*
|
|
28
|
+
* Note: overlapping fields (autoOpen/trace/allowedOrigins/validateOrigin/ackTimeout/autoAckMax*) apply to both sides.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
class RequestIframeEndpointApiFacade {
|
|
32
|
+
constructor(params) {
|
|
33
|
+
var _params$options;
|
|
34
|
+
(0, _defineProperty2.default)(this, "desiredOpen_", true);
|
|
35
|
+
/** Client send APIs */
|
|
36
|
+
(0, _defineProperty2.default)(this, "send", (path, body, options) => this.getClient().send(path, body, options));
|
|
37
|
+
(0, _defineProperty2.default)(this, "sendFile", (path, content, options) => this.getClient().sendFile(path, content, options));
|
|
38
|
+
(0, _defineProperty2.default)(this, "sendStream", (path, stream, options) => this.getClient().sendStream(path, stream, options));
|
|
39
|
+
(0, _defineProperty2.default)(this, "isConnect", () => this.getClient().isConnect());
|
|
40
|
+
(0, _defineProperty2.default)(this, "getCookies", path => this.getClient().getCookies(path));
|
|
41
|
+
(0, _defineProperty2.default)(this, "getCookie", (name, path) => this.getClient().getCookie(name, path));
|
|
42
|
+
(0, _defineProperty2.default)(this, "setCookie", (name, value, options) => this.getClient().setCookie(name, value, options));
|
|
43
|
+
(0, _defineProperty2.default)(this, "removeCookie", (name, path) => this.getClient().removeCookie(name, path));
|
|
44
|
+
(0, _defineProperty2.default)(this, "clearCookies", () => this.getClient().clearCookies());
|
|
45
|
+
/** Server routing/middleware APIs */
|
|
46
|
+
(0, _defineProperty2.default)(this, "use", (pathOrMiddleware, middleware) => this.getServer().use(pathOrMiddleware, middleware));
|
|
47
|
+
(0, _defineProperty2.default)(this, "on", (path, handler) => this.getServer().on(path, handler));
|
|
48
|
+
(0, _defineProperty2.default)(this, "off", path => this.getServer().off(path));
|
|
49
|
+
(0, _defineProperty2.default)(this, "map", handlers => this.getServer().map(handlers));
|
|
50
|
+
this.targetWindow_ = params.targetWindow;
|
|
51
|
+
this.targetOrigin_ = params.targetOrigin;
|
|
52
|
+
this.options_ = params.options;
|
|
53
|
+
this.endpointId_ = params.endpointId;
|
|
54
|
+
this.desiredOpen_ = ((_params$options = params.options) === null || _params$options === void 0 ? void 0 : _params$options.autoOpen) !== false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Lazy create client.
|
|
59
|
+
*/
|
|
60
|
+
getClient() {
|
|
61
|
+
if (!this.client_) {
|
|
62
|
+
var options = this.options_;
|
|
63
|
+
var client = new _client.RequestIframeClientImpl(this.targetWindow_, this.targetOrigin_, {
|
|
64
|
+
secretKey: options === null || options === void 0 ? void 0 : options.secretKey,
|
|
65
|
+
ackTimeout: options === null || options === void 0 ? void 0 : options.ackTimeout,
|
|
66
|
+
timeout: options === null || options === void 0 ? void 0 : options.timeout,
|
|
67
|
+
asyncTimeout: options === null || options === void 0 ? void 0 : options.asyncTimeout,
|
|
68
|
+
returnData: options === null || options === void 0 ? void 0 : options.returnData,
|
|
69
|
+
headers: options === null || options === void 0 ? void 0 : options.headers,
|
|
70
|
+
allowedOrigins: options === null || options === void 0 ? void 0 : options.allowedOrigins,
|
|
71
|
+
validateOrigin: options === null || options === void 0 ? void 0 : options.validateOrigin,
|
|
72
|
+
autoOpen: false,
|
|
73
|
+
autoAckMaxMetaLength: options === null || options === void 0 ? void 0 : options.autoAckMaxMetaLength,
|
|
74
|
+
autoAckMaxIdLength: options === null || options === void 0 ? void 0 : options.autoAckMaxIdLength
|
|
75
|
+
}, this.endpointId_);
|
|
76
|
+
if (options !== null && options !== void 0 && options.trace) {
|
|
77
|
+
var level = options.trace === true ? _constants.LogLevel.TRACE : options.trace;
|
|
78
|
+
(0, _logger.setRequestIframeLogLevel)(level);
|
|
79
|
+
if (level === _constants.LogLevel.TRACE || level === _constants.LogLevel.INFO) {
|
|
80
|
+
(0, _debug.setupClientDebugInterceptors)(client);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
this.client_ = client;
|
|
84
|
+
}
|
|
85
|
+
if (this.desiredOpen_ && !this.client_.isOpen) {
|
|
86
|
+
this.client_.open();
|
|
87
|
+
}
|
|
88
|
+
if (!this.desiredOpen_ && this.client_.isOpen) {
|
|
89
|
+
this.client_.close();
|
|
90
|
+
}
|
|
91
|
+
return this.client_;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Lazy create server.
|
|
96
|
+
*/
|
|
97
|
+
getServer() {
|
|
98
|
+
if (!this.server_) {
|
|
99
|
+
var options = this.options_;
|
|
100
|
+
var server = new _server.RequestIframeServerImpl({
|
|
101
|
+
secretKey: options === null || options === void 0 ? void 0 : options.secretKey,
|
|
102
|
+
id: this.endpointId_,
|
|
103
|
+
ackTimeout: options === null || options === void 0 ? void 0 : options.ackTimeout,
|
|
104
|
+
autoOpen: false,
|
|
105
|
+
allowedOrigins: options === null || options === void 0 ? void 0 : options.allowedOrigins,
|
|
106
|
+
validateOrigin: options === null || options === void 0 ? void 0 : options.validateOrigin,
|
|
107
|
+
maxConcurrentRequestsPerClient: options === null || options === void 0 ? void 0 : options.maxConcurrentRequestsPerClient,
|
|
108
|
+
autoAckMaxMetaLength: options === null || options === void 0 ? void 0 : options.autoAckMaxMetaLength,
|
|
109
|
+
autoAckMaxIdLength: options === null || options === void 0 ? void 0 : options.autoAckMaxIdLength
|
|
110
|
+
});
|
|
111
|
+
if (options !== null && options !== void 0 && options.trace) {
|
|
112
|
+
var level = options.trace === true ? _constants.LogLevel.TRACE : options.trace;
|
|
113
|
+
(0, _logger.setRequestIframeLogLevel)(level);
|
|
114
|
+
if (level === _constants.LogLevel.TRACE || level === _constants.LogLevel.INFO) {
|
|
115
|
+
(0, _debug.setupServerDebugListeners)(server);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
this.server_ = server;
|
|
119
|
+
}
|
|
120
|
+
if (this.desiredOpen_ && !this.server_.isOpen) {
|
|
121
|
+
this.server_.open();
|
|
122
|
+
}
|
|
123
|
+
if (!this.desiredOpen_ && this.server_.isOpen) {
|
|
124
|
+
this.server_.close();
|
|
125
|
+
}
|
|
126
|
+
return this.server_;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Optional accessors for debugging.
|
|
131
|
+
* Note: accessing will trigger lazy creation.
|
|
132
|
+
*/
|
|
133
|
+
get client() {
|
|
134
|
+
return this.getClient();
|
|
135
|
+
}
|
|
136
|
+
get server() {
|
|
137
|
+
return this.getServer();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Client fields */
|
|
141
|
+
get targetWindow() {
|
|
142
|
+
return this.targetWindow_;
|
|
143
|
+
}
|
|
144
|
+
get id() {
|
|
145
|
+
return this.endpointId_;
|
|
146
|
+
}
|
|
147
|
+
get isOpen() {
|
|
148
|
+
/**
|
|
149
|
+
* Facade-level open state.
|
|
150
|
+
* - When client/server is lazily created later, it will follow this state.
|
|
151
|
+
*/
|
|
152
|
+
return this.desiredOpen_;
|
|
153
|
+
}
|
|
154
|
+
get interceptors() {
|
|
155
|
+
return this.getClient().interceptors;
|
|
156
|
+
}
|
|
157
|
+
set interceptors(value) {
|
|
158
|
+
this.getClient().interceptors = value;
|
|
159
|
+
}
|
|
160
|
+
isAvailable() {
|
|
161
|
+
return (0, _window.isWindowAvailable)(this.targetWindow_);
|
|
162
|
+
}
|
|
163
|
+
open() {
|
|
164
|
+
var _this$client_, _this$server_;
|
|
165
|
+
this.desiredOpen_ = true;
|
|
166
|
+
(_this$client_ = this.client_) === null || _this$client_ === void 0 || _this$client_.open();
|
|
167
|
+
(_this$server_ = this.server_) === null || _this$server_ === void 0 || _this$server_.open();
|
|
168
|
+
}
|
|
169
|
+
close() {
|
|
170
|
+
var _this$client_2, _this$server_2;
|
|
171
|
+
this.desiredOpen_ = false;
|
|
172
|
+
(_this$client_2 = this.client_) === null || _this$client_2 === void 0 || _this$client_2.close();
|
|
173
|
+
(_this$server_2 = this.server_) === null || _this$server_2 === void 0 || _this$server_2.close();
|
|
174
|
+
}
|
|
175
|
+
destroy() {
|
|
176
|
+
var _this$client_3, _this$server_3;
|
|
177
|
+
/**
|
|
178
|
+
* Destroy created sides only.
|
|
179
|
+
* They share the underlying MessageChannel via cache ref-counting, so partial creation is safe.
|
|
180
|
+
*/
|
|
181
|
+
(_this$client_3 = this.client_) === null || _this$client_3 === void 0 || _this$client_3.destroy();
|
|
182
|
+
(_this$server_3 = this.server_) === null || _this$server_3 === void 0 || _this$server_3.destroy();
|
|
183
|
+
this.client_ = undefined;
|
|
184
|
+
this.server_ = undefined;
|
|
185
|
+
}
|
|
186
|
+
/** Server fields */
|
|
187
|
+
get secretKey() {
|
|
188
|
+
var _this$options_;
|
|
189
|
+
return (_this$options_ = this.options_) === null || _this$options_ === void 0 ? void 0 : _this$options_.secretKey;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Create an endpoint facade (client + server) for a peer window/iframe.
|
|
195
|
+
*
|
|
196
|
+
* It can:
|
|
197
|
+
* - send requests to the peer (client)
|
|
198
|
+
* - handle requests from the peer (server)
|
|
199
|
+
*/
|
|
200
|
+
function requestIframeEndpoint(target, options) {
|
|
201
|
+
var _options$id;
|
|
202
|
+
var targetWindow = null;
|
|
203
|
+
var targetOrigin = _constants.OriginConstant.ANY;
|
|
204
|
+
if (target.tagName === 'IFRAME') {
|
|
205
|
+
var iframe = target;
|
|
206
|
+
targetWindow = iframe.contentWindow;
|
|
207
|
+
targetOrigin = (0, _iframe.getIframeTargetOrigin)(iframe);
|
|
208
|
+
if (!targetWindow) {
|
|
209
|
+
throw {
|
|
210
|
+
message: _constants.Messages.IFRAME_NOT_READY,
|
|
211
|
+
code: _constants.ErrorCode.IFRAME_NOT_READY
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
targetWindow = target;
|
|
216
|
+
targetOrigin = _constants.OriginConstant.ANY;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Allow user to override targetOrigin explicitly */
|
|
220
|
+
if (options !== null && options !== void 0 && options.targetOrigin) {
|
|
221
|
+
targetOrigin = options.targetOrigin;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Endpoint uses ONE shared id by default, so it behaves like a single endpoint.
|
|
226
|
+
* If options.id is provided, it becomes the shared id for both client+server.
|
|
227
|
+
*/
|
|
228
|
+
var endpointId = (_options$id = options === null || options === void 0 ? void 0 : options.id) !== null && _options$id !== void 0 ? _options$id : (0, _id.generateInstanceId)();
|
|
229
|
+
return new RequestIframeEndpointApiFacade({
|
|
230
|
+
targetWindow,
|
|
231
|
+
targetOrigin,
|
|
232
|
+
options,
|
|
233
|
+
endpointId
|
|
234
|
+
});
|
|
235
|
+
}
|
package/library/api/server.d.ts
CHANGED
|
@@ -13,5 +13,8 @@ export declare function requestIframeServer(options?: RequestIframeServerOptions
|
|
|
13
13
|
* Clear server cache (for testing or reset)
|
|
14
14
|
* Note: This clears the cached server instances
|
|
15
15
|
*/
|
|
16
|
-
export declare function clearRequestIframeServerCache(
|
|
16
|
+
export declare function clearRequestIframeServerCache(arg?: string | {
|
|
17
|
+
secretKey?: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
}): void;
|
|
17
20
|
//# sourceMappingURL=server.d.ts.map
|