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.
Files changed (208) hide show
  1. package/QUICKSTART.CN.md +4 -2
  2. package/QUICKSTART.md +4 -2
  3. package/README.CN.md +129 -33
  4. package/README.md +116 -15
  5. package/cdn/request-iframe-react.umd.js +3354 -0
  6. package/cdn/request-iframe-react.umd.js.map +1 -0
  7. package/cdn/request-iframe-react.umd.min.js +2 -0
  8. package/cdn/request-iframe-react.umd.min.js.map +1 -0
  9. package/cdn/request-iframe.umd.js +19735 -0
  10. package/cdn/request-iframe.umd.js.map +1 -0
  11. package/cdn/request-iframe.umd.min.js +4 -0
  12. package/cdn/request-iframe.umd.min.js.map +1 -0
  13. package/esm/api/client.js +29 -21
  14. package/esm/api/endpoint.js +229 -0
  15. package/esm/api/server.js +16 -8
  16. package/esm/constants/debug.js +17 -0
  17. package/esm/constants/index.js +84 -67
  18. package/esm/constants/log.js +11 -0
  19. package/esm/constants/messages.js +3 -0
  20. package/esm/constants/warn-once.js +15 -0
  21. package/esm/endpoint/facade.js +390 -0
  22. package/esm/endpoint/heartbeat/heartbeat.js +60 -0
  23. package/esm/endpoint/heartbeat/ping.js +20 -0
  24. package/esm/endpoint/index.js +13 -0
  25. package/esm/endpoint/infra/hub.js +316 -0
  26. package/esm/endpoint/infra/inbox.js +232 -0
  27. package/esm/endpoint/infra/outbox.js +408 -0
  28. package/esm/endpoint/stream/dispatcher.js +58 -0
  29. package/esm/endpoint/stream/errors.js +27 -0
  30. package/esm/endpoint/stream/factory.js +76 -0
  31. package/esm/endpoint/stream/file-auto-resolve.js +34 -0
  32. package/esm/endpoint/stream/file-writable.js +105 -0
  33. package/esm/endpoint/stream/handler.js +26 -0
  34. package/esm/{core → impl}/client.js +240 -317
  35. package/esm/{core → impl}/response.js +113 -155
  36. package/esm/impl/server.js +568 -0
  37. package/esm/index.js +13 -6
  38. package/esm/message/ack.js +27 -0
  39. package/esm/message/channel-cache.js +108 -0
  40. package/esm/message/channel.js +90 -4
  41. package/esm/message/dispatcher.js +88 -75
  42. package/esm/stream/error.js +22 -0
  43. package/esm/stream/index.js +3 -1
  44. package/esm/stream/readable-stream.js +45 -9
  45. package/esm/stream/stream-core.js +7 -2
  46. package/esm/stream/writable-stream.js +97 -26
  47. package/esm/utils/blob.js +16 -0
  48. package/esm/utils/cache.js +25 -76
  49. package/esm/utils/content-type.js +81 -0
  50. package/esm/utils/debug.js +156 -179
  51. package/esm/utils/hooks.js +130 -0
  52. package/esm/utils/id.js +14 -0
  53. package/esm/utils/iframe.js +20 -0
  54. package/esm/utils/index.js +11 -163
  55. package/esm/utils/is.js +3 -0
  56. package/esm/utils/logger.js +55 -0
  57. package/esm/utils/promise.js +3 -0
  58. package/esm/utils/window.js +31 -0
  59. package/library/api/client.d.ts.map +1 -1
  60. package/library/api/client.js +30 -22
  61. package/library/api/endpoint.d.ts +23 -0
  62. package/library/api/endpoint.d.ts.map +1 -0
  63. package/library/api/endpoint.js +235 -0
  64. package/library/api/server.d.ts +4 -1
  65. package/library/api/server.d.ts.map +1 -1
  66. package/library/api/server.js +16 -8
  67. package/library/constants/debug.d.ts +18 -0
  68. package/library/constants/debug.d.ts.map +1 -0
  69. package/library/constants/debug.js +23 -0
  70. package/library/constants/index.d.ts +22 -2
  71. package/library/constants/index.d.ts.map +1 -1
  72. package/library/constants/index.js +110 -67
  73. package/library/constants/log.d.ts +12 -0
  74. package/library/constants/log.d.ts.map +1 -0
  75. package/library/constants/log.js +17 -0
  76. package/library/constants/messages.d.ts +3 -0
  77. package/library/constants/messages.d.ts.map +1 -1
  78. package/library/constants/messages.js +3 -0
  79. package/library/constants/warn-once.d.ts +12 -0
  80. package/library/constants/warn-once.d.ts.map +1 -0
  81. package/library/constants/warn-once.js +22 -0
  82. package/library/endpoint/facade.d.ts +238 -0
  83. package/library/endpoint/facade.d.ts.map +1 -0
  84. package/library/endpoint/facade.js +398 -0
  85. package/library/endpoint/heartbeat/heartbeat.d.ts +34 -0
  86. package/library/endpoint/heartbeat/heartbeat.d.ts.map +1 -0
  87. package/library/endpoint/heartbeat/heartbeat.js +67 -0
  88. package/library/endpoint/heartbeat/ping.d.ts +18 -0
  89. package/library/endpoint/heartbeat/ping.d.ts.map +1 -0
  90. package/library/endpoint/heartbeat/ping.js +26 -0
  91. package/library/endpoint/index.d.ts +16 -0
  92. package/library/endpoint/index.d.ts.map +1 -0
  93. package/library/endpoint/index.js +114 -0
  94. package/library/endpoint/infra/hub.d.ts +170 -0
  95. package/library/endpoint/infra/hub.d.ts.map +1 -0
  96. package/library/endpoint/infra/hub.js +323 -0
  97. package/library/endpoint/infra/inbox.d.ts +73 -0
  98. package/library/endpoint/infra/inbox.d.ts.map +1 -0
  99. package/library/endpoint/infra/inbox.js +239 -0
  100. package/library/endpoint/infra/outbox.d.ts +149 -0
  101. package/library/endpoint/infra/outbox.d.ts.map +1 -0
  102. package/library/endpoint/infra/outbox.js +415 -0
  103. package/library/endpoint/stream/dispatcher.d.ts +33 -0
  104. package/library/endpoint/stream/dispatcher.d.ts.map +1 -0
  105. package/library/endpoint/stream/dispatcher.js +66 -0
  106. package/library/endpoint/stream/errors.d.ts +20 -0
  107. package/library/endpoint/stream/errors.d.ts.map +1 -0
  108. package/library/endpoint/stream/errors.js +32 -0
  109. package/library/endpoint/stream/factory.d.ts +44 -0
  110. package/library/endpoint/stream/factory.d.ts.map +1 -0
  111. package/library/endpoint/stream/factory.js +82 -0
  112. package/library/endpoint/stream/file-auto-resolve.d.ts +26 -0
  113. package/library/endpoint/stream/file-auto-resolve.d.ts.map +1 -0
  114. package/library/endpoint/stream/file-auto-resolve.js +41 -0
  115. package/library/endpoint/stream/file-writable.d.ts +33 -0
  116. package/library/endpoint/stream/file-writable.d.ts.map +1 -0
  117. package/library/endpoint/stream/file-writable.js +115 -0
  118. package/library/endpoint/stream/handler.d.ts +20 -0
  119. package/library/endpoint/stream/handler.d.ts.map +1 -0
  120. package/library/endpoint/stream/handler.js +32 -0
  121. package/library/{core → impl}/client.d.ts +16 -13
  122. package/library/impl/client.d.ts.map +1 -0
  123. package/library/{core → impl}/client.js +251 -330
  124. package/library/{core → impl}/request.d.ts.map +1 -1
  125. package/library/{core → impl}/response.d.ts +5 -10
  126. package/library/impl/response.d.ts.map +1 -0
  127. package/library/{core → impl}/response.js +113 -155
  128. package/library/{core → impl}/server.d.ts +22 -55
  129. package/library/impl/server.d.ts.map +1 -0
  130. package/library/impl/server.js +575 -0
  131. package/library/index.d.ts +13 -6
  132. package/library/index.d.ts.map +1 -1
  133. package/library/index.js +16 -16
  134. package/library/message/ack.d.ts +15 -0
  135. package/library/message/ack.d.ts.map +1 -0
  136. package/library/message/ack.js +33 -0
  137. package/library/message/channel-cache.d.ts +26 -0
  138. package/library/message/channel-cache.d.ts.map +1 -0
  139. package/library/message/channel-cache.js +115 -0
  140. package/library/message/channel.d.ts +53 -6
  141. package/library/message/channel.d.ts.map +1 -1
  142. package/library/message/channel.js +94 -8
  143. package/library/message/dispatcher.d.ts +7 -0
  144. package/library/message/dispatcher.d.ts.map +1 -1
  145. package/library/message/dispatcher.js +89 -76
  146. package/library/stream/error.d.ts +24 -0
  147. package/library/stream/error.d.ts.map +1 -0
  148. package/library/stream/error.js +29 -0
  149. package/library/stream/index.d.ts +4 -1
  150. package/library/stream/index.d.ts.map +1 -1
  151. package/library/stream/index.js +7 -4
  152. package/library/stream/readable-stream.d.ts.map +1 -1
  153. package/library/stream/readable-stream.js +46 -10
  154. package/library/stream/stream-core.d.ts.map +1 -1
  155. package/library/stream/stream-core.js +6 -1
  156. package/library/stream/writable-stream.d.ts.map +1 -1
  157. package/library/stream/writable-stream.js +99 -28
  158. package/library/types/index.d.ts +15 -19
  159. package/library/types/index.d.ts.map +1 -1
  160. package/library/utils/blob.d.ts +3 -0
  161. package/library/utils/blob.d.ts.map +1 -0
  162. package/library/utils/blob.js +22 -0
  163. package/library/utils/cache.d.ts +10 -20
  164. package/library/utils/cache.d.ts.map +1 -1
  165. package/library/utils/cache.js +25 -79
  166. package/library/utils/content-type.d.ts +13 -0
  167. package/library/utils/content-type.d.ts.map +1 -0
  168. package/library/utils/content-type.js +87 -0
  169. package/library/utils/debug.d.ts.map +1 -1
  170. package/library/utils/debug.js +155 -177
  171. package/library/utils/hooks.d.ts +30 -0
  172. package/library/utils/hooks.d.ts.map +1 -0
  173. package/library/utils/hooks.js +139 -0
  174. package/library/utils/id.d.ts +9 -0
  175. package/library/utils/id.d.ts.map +1 -0
  176. package/library/utils/id.js +21 -0
  177. package/library/utils/iframe.d.ts +5 -0
  178. package/library/utils/iframe.d.ts.map +1 -0
  179. package/library/utils/iframe.js +25 -0
  180. package/library/utils/index.d.ts +7 -34
  181. package/library/utils/index.d.ts.map +1 -1
  182. package/library/utils/index.js +58 -194
  183. package/library/utils/is.d.ts +2 -0
  184. package/library/utils/is.d.ts.map +1 -0
  185. package/library/utils/is.js +9 -0
  186. package/library/utils/logger.d.ts +13 -0
  187. package/library/utils/logger.d.ts.map +1 -0
  188. package/library/utils/logger.js +63 -0
  189. package/library/utils/promise.d.ts +2 -0
  190. package/library/utils/promise.d.ts.map +1 -0
  191. package/library/utils/promise.js +9 -0
  192. package/library/utils/window.d.ts +2 -0
  193. package/library/utils/window.d.ts.map +1 -0
  194. package/library/utils/window.js +38 -0
  195. package/package.json +49 -2
  196. package/react/package.json +2 -1
  197. package/esm/core/client-server.js +0 -294
  198. package/esm/core/server.js +0 -776
  199. package/library/core/client-server.d.ts +0 -97
  200. package/library/core/client-server.d.ts.map +0 -1
  201. package/library/core/client-server.js +0 -301
  202. package/library/core/client.d.ts.map +0 -1
  203. package/library/core/response.d.ts.map +0 -1
  204. package/library/core/server.d.ts.map +0 -1
  205. package/library/core/server.js +0 -781
  206. /package/esm/{core → impl}/request.js +0 -0
  207. /package/library/{core → impl}/request.d.ts +0 -0
  208. /package/library/{core → impl}/request.js +0 -0
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RequestIframeEndpointHeartbeat = void 0;
7
+ require("core-js/modules/es.array.slice.js");
8
+ require("core-js/modules/es.promise.js");
9
+ require("core-js/modules/es.regexp.to-string.js");
10
+ var _constants = require("../../constants");
11
+ /**
12
+ * RequestIframeEndpointHeartbeat
13
+ *
14
+ * Shared "ping -> wait pong" helper.
15
+ * - Works for both server and client endpoints
16
+ * - Uses core.pending for timeout management
17
+ */
18
+ class RequestIframeEndpointHeartbeat {
19
+ constructor(params) {
20
+ this.hub = params.hub;
21
+ this.pendingBucket = params.pendingBucket;
22
+ this.handledBy = params.handledBy;
23
+ this.isOriginAllowed = params.isOriginAllowed;
24
+ this.warnMissingPendingWhenClosed = params.warnMissingPendingWhenClosed;
25
+ }
26
+
27
+ /**
28
+ * Send PING and resolve true when PONG arrives, false on timeout.
29
+ */
30
+ ping(peer, timeoutMs, targetId) {
31
+ var requestId = `ping_${Date.now()}_${Math.random().toString(36).slice(2)}`;
32
+ return new Promise(resolve => {
33
+ var timeoutId = this.hub.pending.setTimeout(() => {
34
+ this.hub.pending.delete(this.pendingBucket, requestId);
35
+ resolve(false);
36
+ }, timeoutMs);
37
+ this.hub.pending.set(this.pendingBucket, requestId, {
38
+ resolve,
39
+ timeoutId
40
+ });
41
+ peer.sendMessage(_constants.MessageType.PING, requestId, {
42
+ requireAck: true,
43
+ targetId
44
+ });
45
+ });
46
+ }
47
+
48
+ /**
49
+ * Handle incoming PONG for ping() waiter.
50
+ */
51
+ handlePong(data, context) {
52
+ if (this.isOriginAllowed && !this.isOriginAllowed(data, context)) return;
53
+ var pending = this.hub.pending.get(this.pendingBucket, data.requestId);
54
+ if (!pending) {
55
+ if (!this.hub.isOpen) {
56
+ var _this$warnMissingPend;
57
+ (_this$warnMissingPend = this.warnMissingPendingWhenClosed) === null || _this$warnMissingPend === void 0 || _this$warnMissingPend.call(this, data);
58
+ }
59
+ return;
60
+ }
61
+ context.markAcceptedBy(this.handledBy);
62
+ this.hub.pending.clearTimeout(pending.timeoutId);
63
+ this.hub.pending.delete(this.pendingBucket, data.requestId);
64
+ pending.resolve(true);
65
+ }
66
+ }
67
+ exports.RequestIframeEndpointHeartbeat = RequestIframeEndpointHeartbeat;
@@ -0,0 +1,18 @@
1
+ import type { PostMessageData } from '../../types';
2
+ import type { MessageContext } from '../../message';
3
+ import type { RequestIframeEndpointHub } from '../infra/hub';
4
+ /**
5
+ * Create a PING responder handler (reply PONG).
6
+ *
7
+ * This is a shared building block for both client/server endpoints.
8
+ */
9
+ export declare function createPingResponder(params: {
10
+ hub: RequestIframeEndpointHub;
11
+ handledBy: string;
12
+ /**
13
+ * Whether to attach `targetId = data.creatorId` when replying PONG.
14
+ * Useful when multiple instances share a channel.
15
+ */
16
+ includeTargetId?: boolean;
17
+ }): (data: PostMessageData, context: MessageContext) => void;
18
+ //# sourceMappingURL=ping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ping.d.ts","sourceRoot":"","sources":["../../../src/endpoint/heartbeat/ping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAE7D;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,GAAG,EAAE,wBAAwB,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,GAAG,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,KAAK,IAAI,CAe3D"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createPingResponder = createPingResponder;
7
+ var _constants = require("../../constants");
8
+ /**
9
+ * Create a PING responder handler (reply PONG).
10
+ *
11
+ * This is a shared building block for both client/server endpoints.
12
+ */
13
+ function createPingResponder(params) {
14
+ var hub = params.hub,
15
+ handledBy = params.handledBy,
16
+ includeTargetId = params.includeTargetId;
17
+ return (data, context) => {
18
+ if (!context.source) return;
19
+ /** Mark accepted so MessageDispatcher can auto-send ACK when requireAck === true */
20
+ context.markAcceptedBy(handledBy);
21
+ /** Reply PONG */
22
+ hub.messageDispatcher.sendMessage(context.source, context.origin, _constants.MessageType.PONG, data.requestId, includeTargetId ? {
23
+ targetId: data.creatorId
24
+ } : undefined);
25
+ };
26
+ }
@@ -0,0 +1,16 @@
1
+ export { RequestIframeEndpointHub } from './infra/hub';
2
+ export type { RequestIframeEndpointHubOptions } from './infra/hub';
3
+ export { RequestIframeEndpointInbox } from './infra/inbox';
4
+ export { RequestIframeEndpointOutbox } from './infra/outbox';
5
+ export { createPingResponder } from './heartbeat/ping';
6
+ export { buildExpectedAck, isExpectedAckMatch } from '../message/ack';
7
+ export { RequestIframeStreamDispatcher } from './stream/dispatcher';
8
+ export { RequestIframeEndpointHeartbeat } from './heartbeat/heartbeat';
9
+ export { parseStreamStart, createReadableStreamFromStart } from './stream/factory';
10
+ export type { StreamStartInfo } from './stream/factory';
11
+ export { RequestIframeEndpointFacade } from './facade';
12
+ export { createStreamMessageHandler } from './stream/handler';
13
+ export { buildStreamStartTimeoutErrorPayload } from './stream/errors';
14
+ export { autoResolveIframeFileReadableStream, parseFilenameFromContentDisposition } from './stream/file-auto-resolve';
15
+ export { createIframeFileWritableStreamFromContent } from './stream/file-writable';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/endpoint/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,YAAY,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AACnF,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,mCAAmC,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,mCAAmC,EAAE,mCAAmC,EAAE,MAAM,4BAA4B,CAAC;AACtH,OAAO,EAAE,yCAAyC,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "RequestIframeEndpointFacade", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _facade.RequestIframeEndpointFacade;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "RequestIframeEndpointHeartbeat", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _heartbeat.RequestIframeEndpointHeartbeat;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "RequestIframeEndpointHub", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _hub.RequestIframeEndpointHub;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "RequestIframeEndpointInbox", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _inbox.RequestIframeEndpointInbox;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "RequestIframeEndpointOutbox", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _outbox.RequestIframeEndpointOutbox;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "RequestIframeStreamDispatcher", {
37
+ enumerable: true,
38
+ get: function get() {
39
+ return _dispatcher.RequestIframeStreamDispatcher;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "autoResolveIframeFileReadableStream", {
43
+ enumerable: true,
44
+ get: function get() {
45
+ return _fileAutoResolve.autoResolveIframeFileReadableStream;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "buildExpectedAck", {
49
+ enumerable: true,
50
+ get: function get() {
51
+ return _ack.buildExpectedAck;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "buildStreamStartTimeoutErrorPayload", {
55
+ enumerable: true,
56
+ get: function get() {
57
+ return _errors.buildStreamStartTimeoutErrorPayload;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "createIframeFileWritableStreamFromContent", {
61
+ enumerable: true,
62
+ get: function get() {
63
+ return _fileWritable.createIframeFileWritableStreamFromContent;
64
+ }
65
+ });
66
+ Object.defineProperty(exports, "createPingResponder", {
67
+ enumerable: true,
68
+ get: function get() {
69
+ return _ping.createPingResponder;
70
+ }
71
+ });
72
+ Object.defineProperty(exports, "createReadableStreamFromStart", {
73
+ enumerable: true,
74
+ get: function get() {
75
+ return _factory.createReadableStreamFromStart;
76
+ }
77
+ });
78
+ Object.defineProperty(exports, "createStreamMessageHandler", {
79
+ enumerable: true,
80
+ get: function get() {
81
+ return _handler.createStreamMessageHandler;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, "isExpectedAckMatch", {
85
+ enumerable: true,
86
+ get: function get() {
87
+ return _ack.isExpectedAckMatch;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, "parseFilenameFromContentDisposition", {
91
+ enumerable: true,
92
+ get: function get() {
93
+ return _fileAutoResolve.parseFilenameFromContentDisposition;
94
+ }
95
+ });
96
+ Object.defineProperty(exports, "parseStreamStart", {
97
+ enumerable: true,
98
+ get: function get() {
99
+ return _factory.parseStreamStart;
100
+ }
101
+ });
102
+ var _hub = require("./infra/hub");
103
+ var _inbox = require("./infra/inbox");
104
+ var _outbox = require("./infra/outbox");
105
+ var _ping = require("./heartbeat/ping");
106
+ var _ack = require("../message/ack");
107
+ var _dispatcher = require("./stream/dispatcher");
108
+ var _heartbeat = require("./heartbeat/heartbeat");
109
+ var _factory = require("./stream/factory");
110
+ var _facade = require("./facade");
111
+ var _handler = require("./stream/handler");
112
+ var _errors = require("./stream/errors");
113
+ var _fileAutoResolve = require("./stream/file-auto-resolve");
114
+ var _fileWritable = require("./stream/file-writable");
@@ -0,0 +1,170 @@
1
+ import type { HandlerOptions, MessageHandlerFn, MessageTypeMatcher, VersionValidator } from '../../message';
2
+ import { MessageDispatcher } from '../../message';
3
+ import type { PostMessageData } from '../../types';
4
+ import type { MessageContext } from '../../message';
5
+ import type { MessageRoleValue } from '../../constants';
6
+ import { RequestIframeEndpointOutbox } from './outbox';
7
+ import { SyncHook } from '../../utils/hooks';
8
+ /**
9
+ * Pending manager for maps and timers.
10
+ *
11
+ * - Track all pending maps created by hub
12
+ * - Track all timeouts created by hub
13
+ * - Provide a unified cleanup when destroying
14
+ */
15
+ declare class RequestIframePendingManager {
16
+ private readonly maps;
17
+ private readonly timeouts;
18
+ /**
19
+ * Get or create a named pending map that will be auto-cleared on destroy.
20
+ */
21
+ map<K, V>(name: string): Map<K, V>;
22
+ get<K, V>(name: string, key: K): V | undefined;
23
+ set<K, V>(name: string, key: K, value: V): void;
24
+ has<K>(name: string, key: K): boolean;
25
+ delete<K>(name: string, key: K): boolean;
26
+ /**
27
+ * Create a timeout that will be auto-cleared on destroy.
28
+ */
29
+ setTimeout(fn: () => void, ms: number): ReturnType<typeof setTimeout>;
30
+ /**
31
+ * Clear a tracked timeout.
32
+ */
33
+ clearTimeout(id: ReturnType<typeof setTimeout>): void;
34
+ /**
35
+ * Clear all tracked pending maps and timeouts.
36
+ */
37
+ clearAll(): void;
38
+ }
39
+ /**
40
+ * Generic counter/limiter utilities (built on hub.pending maps).
41
+ *
42
+ * This is intended as a shared infrastructure for both client/server:
43
+ * - server can limit max concurrent in-flight requests per client
44
+ * - client can limit max concurrent streams / in-flight sends in future
45
+ */
46
+ declare class RequestIframeLimiter {
47
+ private readonly pending;
48
+ constructor(pending: RequestIframePendingManager);
49
+ get(bucket: string, key: string): number;
50
+ /**
51
+ * Try acquire one permit for the given key.
52
+ * Returns true if acquired, false if limit reached.
53
+ */
54
+ tryAcquire(bucket: string, key: string, limit: number): boolean;
55
+ /**
56
+ * Release one permit for the given key.
57
+ */
58
+ release(bucket: string, key: string): void;
59
+ }
60
+ /**
61
+ * Shared options for endpoint hub.
62
+ */
63
+ export interface RequestIframeEndpointHubOptions {
64
+ /** Message isolation key */
65
+ secretKey?: string;
66
+ /** Protocol version validator (optional, uses built-in validation by default) */
67
+ versionValidator?: VersionValidator;
68
+ /** Whether to automatically open when creating. Default is true. */
69
+ autoOpen?: boolean;
70
+ /** Advanced: auto-ack echo limit for ack.meta length (internal). */
71
+ autoAckMaxMetaLength?: number;
72
+ /** Advanced: auto-ack echo limit for ack.id length (internal). */
73
+ autoAckMaxIdLength?: number;
74
+ }
75
+ /**
76
+ * RequestIframeEndpointHub
77
+ *
78
+ * Endpoint "hub" responsible for:
79
+ * - MessageDispatcher lifecycle
80
+ * - handler registration/unregistration
81
+ * - pending + timeout management
82
+ * - limiter counters
83
+ */
84
+ export declare class RequestIframeEndpointHub {
85
+ readonly hooks: {
86
+ beforeOpen: SyncHook<[]>;
87
+ afterOpen: SyncHook<[]>;
88
+ beforeClose: SyncHook<[]>;
89
+ afterClose: SyncHook<[]>;
90
+ beforeDestroy: SyncHook<[]>;
91
+ afterDestroy: SyncHook<[]>;
92
+ registerHandler: SyncHook<[matcher: MessageTypeMatcher]>;
93
+ unregisterHandler: SyncHook<[]>;
94
+ };
95
+ readonly messageDispatcher: MessageDispatcher;
96
+ readonly versionValidator: VersionValidator;
97
+ readonly pending: RequestIframePendingManager;
98
+ readonly limiter: RequestIframeLimiter;
99
+ readonly instanceId?: string;
100
+ private readonly unregisterFns;
101
+ private registerHandlersFn?;
102
+ private readonly warnOnceKeys;
103
+ private streamCallback?;
104
+ /** Whether it is open */
105
+ private _isOpen;
106
+ constructor(role: MessageRoleValue, instanceId: string | undefined, options?: RequestIframeEndpointHubOptions);
107
+ /**
108
+ * Set registerHandlers callback.
109
+ *
110
+ * This is used by composition-based implementations to define handler bindings.
111
+ */
112
+ setRegisterHandlers(fn: () => void): void;
113
+ /**
114
+ * Register a dispatcher handler and track its unregister function.
115
+ */
116
+ registerHandler(matcher: MessageTypeMatcher, handler: MessageHandlerFn, options?: HandlerOptions | number): () => void;
117
+ /**
118
+ * Create common handler options object.
119
+ */
120
+ createHandlerOptions(onVersionError: HandlerOptions['onVersionError']): HandlerOptions;
121
+ /**
122
+ * Warn once per key.
123
+ */
124
+ warnOnce(key: string, fn: () => void): void;
125
+ /**
126
+ * Set stream callback (used by client-side stream routing).
127
+ */
128
+ setStreamCallback(callback?: (data: PostMessageData, context: MessageContext) => void): void;
129
+ /**
130
+ * Get stream callback (used by handler registration side).
131
+ */
132
+ getStreamCallback(): ((data: PostMessageData, context: MessageContext) => void) | undefined;
133
+ /**
134
+ * Validate origin safely (originValidator wins over origin string).
135
+ */
136
+ isOriginAllowedBy(contextOrigin: string, data: PostMessageData, context: MessageContext, origin?: string, originValidator?: (origin: string, data: PostMessageData, context: MessageContext) => boolean): boolean;
137
+ /**
138
+ * Set a fixed peer (fallback target) for cases where MessageEvent.source is missing.
139
+ *
140
+ * This is useful for "response endpoint" style usage where the peer is already known
141
+ * (e.g. a client bound to an iframe window).
142
+ */
143
+ setFallbackTarget(targetWindow: Window, targetOrigin: string): void;
144
+ /**
145
+ * Create a peer-bound outbox using this hub's dispatcher.
146
+ */
147
+ createOutbox(targetWindow: Window, targetOrigin: string, defaultTargetId?: string): RequestIframeEndpointOutbox;
148
+ /**
149
+ * Open message processing (register message handlers)
150
+ */
151
+ open(): void;
152
+ /**
153
+ * Close message processing (unregister message handlers, but don't release channel)
154
+ */
155
+ close(): void;
156
+ /**
157
+ * Whether it is open
158
+ */
159
+ get isOpen(): boolean;
160
+ /**
161
+ * Get secretKey
162
+ */
163
+ get secretKey(): string | undefined;
164
+ /**
165
+ * Destroy (close and release channel reference)
166
+ */
167
+ destroy(): void;
168
+ }
169
+ export {};
170
+ //# sourceMappingURL=hub.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../../../src/endpoint/infra/hub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC5G,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;;;GAMG;AACH,cAAM,2BAA2B;IAC/B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAoC;IACzD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA4C;IAErE;;OAEG;IACI,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAQlC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAI9C,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI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