request-iframe 0.0.6 → 0.1.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.
Files changed (95) hide show
  1. package/README.CN.md +220 -21
  2. package/README.md +221 -24
  3. package/esm/api/client.js +80 -0
  4. package/esm/api/server.js +61 -0
  5. package/esm/constants/index.js +289 -0
  6. package/esm/constants/messages.js +157 -0
  7. package/esm/core/client-server.js +294 -0
  8. package/esm/core/client.js +873 -0
  9. package/esm/core/request.js +27 -0
  10. package/esm/core/response.js +459 -0
  11. package/esm/core/server.js +776 -0
  12. package/esm/index.js +21 -0
  13. package/esm/interceptors/index.js +122 -0
  14. package/esm/message/channel.js +182 -0
  15. package/esm/message/dispatcher.js +418 -0
  16. package/esm/message/index.js +2 -0
  17. package/esm/stream/file-stream.js +289 -0
  18. package/esm/stream/index.js +44 -0
  19. package/esm/stream/readable-stream.js +539 -0
  20. package/esm/stream/stream-core.js +204 -0
  21. package/esm/stream/types.js +1 -0
  22. package/esm/stream/writable-stream.js +836 -0
  23. package/esm/types/index.js +1 -0
  24. package/esm/utils/ack.js +36 -0
  25. package/esm/utils/cache.js +147 -0
  26. package/esm/utils/cookie.js +352 -0
  27. package/esm/utils/debug.js +521 -0
  28. package/esm/utils/error.js +27 -0
  29. package/esm/utils/index.js +180 -0
  30. package/esm/utils/origin.js +30 -0
  31. package/esm/utils/path-match.js +148 -0
  32. package/esm/utils/protocol.js +157 -0
  33. package/library/api/client.d.ts.map +1 -1
  34. package/library/api/client.js +13 -5
  35. package/library/api/server.d.ts.map +1 -1
  36. package/library/api/server.js +6 -1
  37. package/library/constants/index.d.ts +59 -4
  38. package/library/constants/index.d.ts.map +1 -1
  39. package/library/constants/index.js +67 -9
  40. package/library/constants/messages.d.ts +8 -1
  41. package/library/constants/messages.d.ts.map +1 -1
  42. package/library/constants/messages.js +8 -1
  43. package/library/core/client-server.d.ts +7 -15
  44. package/library/core/client-server.d.ts.map +1 -1
  45. package/library/core/client-server.js +56 -44
  46. package/library/core/client.d.ts +4 -1
  47. package/library/core/client.d.ts.map +1 -1
  48. package/library/core/client.js +74 -31
  49. package/library/core/response.d.ts +21 -3
  50. package/library/core/response.d.ts.map +1 -1
  51. package/library/core/response.js +55 -7
  52. package/library/core/server.d.ts +34 -3
  53. package/library/core/server.d.ts.map +1 -1
  54. package/library/core/server.js +191 -21
  55. package/library/message/channel.d.ts +6 -0
  56. package/library/message/channel.d.ts.map +1 -1
  57. package/library/message/channel.js +2 -1
  58. package/library/message/dispatcher.d.ts +32 -0
  59. package/library/message/dispatcher.d.ts.map +1 -1
  60. package/library/message/dispatcher.js +131 -1
  61. package/library/stream/file-stream.d.ts +4 -0
  62. package/library/stream/file-stream.d.ts.map +1 -1
  63. package/library/stream/file-stream.js +61 -33
  64. package/library/stream/index.d.ts.map +1 -1
  65. package/library/stream/index.js +2 -0
  66. package/library/stream/readable-stream.d.ts +30 -11
  67. package/library/stream/readable-stream.d.ts.map +1 -1
  68. package/library/stream/readable-stream.js +368 -73
  69. package/library/stream/stream-core.d.ts +65 -0
  70. package/library/stream/stream-core.d.ts.map +1 -0
  71. package/library/stream/stream-core.js +211 -0
  72. package/library/stream/types.d.ts +203 -3
  73. package/library/stream/types.d.ts.map +1 -1
  74. package/library/stream/writable-stream.d.ts +59 -13
  75. package/library/stream/writable-stream.d.ts.map +1 -1
  76. package/library/stream/writable-stream.js +647 -197
  77. package/library/types/index.d.ts +70 -4
  78. package/library/types/index.d.ts.map +1 -1
  79. package/library/utils/ack.d.ts +2 -0
  80. package/library/utils/ack.d.ts.map +1 -0
  81. package/library/utils/ack.js +44 -0
  82. package/library/utils/debug.js +1 -1
  83. package/library/utils/index.d.ts +1 -0
  84. package/library/utils/index.d.ts.map +1 -1
  85. package/library/utils/index.js +19 -2
  86. package/library/utils/origin.d.ts +14 -0
  87. package/library/utils/origin.d.ts.map +1 -0
  88. package/library/utils/origin.js +35 -0
  89. package/package.json +30 -7
  90. package/react/README.md +16 -0
  91. package/react/esm/index.js +284 -0
  92. package/react/library/index.d.ts +1 -1
  93. package/react/library/index.d.ts.map +1 -1
  94. package/react/library/index.js +3 -3
  95. package/react/package.json +24 -2
@@ -0,0 +1,289 @@
1
+ /**
2
+ * Protocol version constants
3
+ * Used to identify the protocol version of messages, for compatibility handling in future version upgrades
4
+ *
5
+ * Version compatibility strategy:
6
+ * - Only check minimum supported version, reject deprecated old versions
7
+ * - Don't check maximum version, as new versions usually maintain backward compatibility with old message formats
8
+ * - This way new version servers can be compatible with old version clients, without forcing client upgrades
9
+ */
10
+ export var ProtocolVersion = {
11
+ /** Current protocol version */
12
+ CURRENT: 2,
13
+ /** Minimum supported protocol version (messages below this version will be rejected) */
14
+ MIN_SUPPORTED: 1
15
+ };
16
+
17
+ /**
18
+ * Special origin values
19
+ */
20
+ export var OriginConstant = {
21
+ /** Wildcard origin (postMessage targetOrigin = '*') */
22
+ ANY: '*'
23
+ };
24
+
25
+ /**
26
+ * Auto-ack (ACK-only) limits.
27
+ */
28
+ export var AutoAckConstant = {
29
+ /** Max length of ack.id to be echoed back in auto-ack */
30
+ MAX_ID_LENGTH: 1024,
31
+ /** Max length of ack.meta to be echoed back in auto-ack */
32
+ MAX_META_LENGTH: 5120
33
+ };
34
+
35
+ /**
36
+ * Protocol version type
37
+ */
38
+
39
+ /**
40
+ * Protocol validation result
41
+ */
42
+
43
+ /**
44
+ * HTTP status code constants
45
+ */
46
+ export var HttpStatus = {
47
+ OK: 200,
48
+ CREATED: 201,
49
+ NO_CONTENT: 204,
50
+ BAD_REQUEST: 400,
51
+ UNAUTHORIZED: 401,
52
+ FORBIDDEN: 403,
53
+ NOT_FOUND: 404,
54
+ REQUEST_TIMEOUT: 408,
55
+ TOO_MANY_REQUESTS: 429,
56
+ INTERNAL_SERVER_ERROR: 500,
57
+ BAD_GATEWAY: 502,
58
+ SERVICE_UNAVAILABLE: 503
59
+ };
60
+
61
+ /**
62
+ * HTTP status text constants
63
+ */
64
+ export var HttpStatusText = {
65
+ [HttpStatus.OK]: 'OK',
66
+ [HttpStatus.CREATED]: 'Created',
67
+ [HttpStatus.NO_CONTENT]: 'No Content',
68
+ [HttpStatus.BAD_REQUEST]: 'Bad Request',
69
+ [HttpStatus.UNAUTHORIZED]: 'Unauthorized',
70
+ [HttpStatus.FORBIDDEN]: 'Forbidden',
71
+ [HttpStatus.NOT_FOUND]: 'Not Found',
72
+ [HttpStatus.REQUEST_TIMEOUT]: 'Request Timeout',
73
+ [HttpStatus.TOO_MANY_REQUESTS]: 'Too Many Requests',
74
+ [HttpStatus.INTERNAL_SERVER_ERROR]: 'Internal Server Error',
75
+ [HttpStatus.BAD_GATEWAY]: 'Bad Gateway',
76
+ [HttpStatus.SERVICE_UNAVAILABLE]: 'Service Unavailable'
77
+ };
78
+
79
+ /**
80
+ * Get status text
81
+ */
82
+ export function getStatusText(code) {
83
+ return HttpStatusText[code] || 'Unknown';
84
+ }
85
+
86
+ /**
87
+ * Error code constants
88
+ */
89
+ export var ErrorCode = {
90
+ /** ACK confirmation timeout */
91
+ ACK_TIMEOUT: 'ACK_TIMEOUT',
92
+ /** Request timeout (synchronous) */
93
+ TIMEOUT: 'TIMEOUT',
94
+ /** Async request timeout */
95
+ ASYNC_TIMEOUT: 'ASYNC_TIMEOUT',
96
+ /** Request error */
97
+ REQUEST_ERROR: 'REQUEST_ERROR',
98
+ /** Method not found */
99
+ METHOD_NOT_FOUND: 'METHOD_NOT_FOUND',
100
+ /** No response */
101
+ NO_RESPONSE: 'NO_RESPONSE',
102
+ /** Protocol version not supported */
103
+ PROTOCOL_UNSUPPORTED: 'PROTOCOL_UNSUPPORTED',
104
+ /** iframe not ready */
105
+ IFRAME_NOT_READY: 'IFRAME_NOT_READY',
106
+ /** Stream error */
107
+ STREAM_ERROR: 'STREAM_ERROR',
108
+ /** Stream cancelled */
109
+ STREAM_CANCELLED: 'STREAM_CANCELLED',
110
+ /** Stream not bound */
111
+ STREAM_NOT_BOUND: 'STREAM_NOT_BOUND',
112
+ /** Target window closed */
113
+ TARGET_WINDOW_CLOSED: 'TARGET_WINDOW_CLOSED',
114
+ /** Too many concurrent requests (rate limiting) */
115
+ TOO_MANY_REQUESTS: 'TOO_MANY_REQUESTS',
116
+ /** Stream start not received in time */
117
+ STREAM_START_TIMEOUT: 'STREAM_START_TIMEOUT'
118
+ };
119
+
120
+ /**
121
+ * Message type constants
122
+ */
123
+ export var MessageType = {
124
+ /** Request message */
125
+ REQUEST: 'request',
126
+ /** Acknowledge request received */
127
+ ACK: 'ack',
128
+ /** Async task notification */
129
+ ASYNC: 'async',
130
+ /** Response message */
131
+ RESPONSE: 'response',
132
+ /** Error message */
133
+ ERROR: 'error',
134
+ /** Ping message (for connection detection) */
135
+ PING: 'ping',
136
+ /** Pong message (for connection detection) */
137
+ PONG: 'pong',
138
+ /** Stream start */
139
+ STREAM_START: 'stream_start',
140
+ /** Stream data chunk */
141
+ STREAM_DATA: 'stream_data',
142
+ /** Stream end */
143
+ STREAM_END: 'stream_end',
144
+ /** Stream error */
145
+ STREAM_ERROR: 'stream_error',
146
+ /** Stream cancel */
147
+ STREAM_CANCEL: 'stream_cancel',
148
+ /** Stream pull (receiver requests next chunks) */
149
+ STREAM_PULL: 'stream_pull',
150
+ /** Stream ack (receiver acknowledges a chunk) */
151
+ STREAM_ACK: 'stream_ack'
152
+ };
153
+ export var MessageRole = {
154
+ /** Server role */
155
+ SERVER: 'server',
156
+ /** Client role */
157
+ CLIENT: 'client'
158
+ };
159
+ /**
160
+ * Default timeout configuration (milliseconds)
161
+ */
162
+ export var DefaultTimeout = {
163
+ /**
164
+ * ACK confirmation timeout: 1000ms (1s)
165
+ * Used for requireAck confirmation (ACK-only).
166
+ * Increased from 500ms to accommodate slower environments or busy browsers where postMessage
167
+ * serialization/deserialization may take longer.
168
+ */
169
+ ACK: 1000,
170
+ /** Request timeout: 5s */
171
+ REQUEST: 5000,
172
+ /** Async request timeout: 120s */
173
+ ASYNC: 120000
174
+ };
175
+
176
+ /**
177
+ * HTTP Header name constants
178
+ */
179
+ export var HttpHeader = {
180
+ /** Set-Cookie (server sets cookie) */
181
+ SET_COOKIE: 'Set-Cookie',
182
+ /** Content-Type */
183
+ CONTENT_TYPE: 'Content-Type',
184
+ /** Content-Disposition (for file downloads) */
185
+ CONTENT_DISPOSITION: 'Content-Disposition',
186
+ /** Authorization */
187
+ AUTHORIZATION: 'Authorization',
188
+ /** Cookie (cookies carried in request) */
189
+ COOKIE: 'Cookie'
190
+ };
191
+
192
+ /**
193
+ * HTTP Header name type
194
+ */
195
+
196
+ /**
197
+ * Message type union type
198
+ */
199
+
200
+ /**
201
+ * Error code union type
202
+ */
203
+
204
+ /**
205
+ * Stream type constants
206
+ */
207
+ export var StreamType = {
208
+ /** Normal data stream */
209
+ DATA: 'data',
210
+ /** File stream */
211
+ FILE: 'file'
212
+ };
213
+
214
+ /**
215
+ * Stream mode constants
216
+ * - PULL: receiver pulls next chunks (backpressure)
217
+ * - PUSH: producer pushes via write()
218
+ */
219
+ export var StreamMode = {
220
+ PULL: 'pull',
221
+ PUSH: 'push'
222
+ };
223
+ /**
224
+ * Stream internal message type constants (for stream internal message handling)
225
+ * Note: These are MessageType.STREAM_* values with the stream_ prefix removed
226
+ */
227
+ export var StreamInternalMessageType = {
228
+ /** Data message */
229
+ DATA: 'data',
230
+ /** End message */
231
+ END: 'end',
232
+ /** Error message */
233
+ ERROR: 'error',
234
+ /** Cancel message */
235
+ CANCEL: 'cancel',
236
+ /** Pull message */
237
+ PULL: 'pull'
238
+ };
239
+
240
+ /**
241
+ * Stream internal message type value type
242
+ */
243
+
244
+ /**
245
+ * Stream type value type
246
+ */
247
+
248
+ /**
249
+ * Stream state constants
250
+ */
251
+ export var StreamState = {
252
+ /** Pending */
253
+ PENDING: 'pending',
254
+ /** Streaming */
255
+ STREAMING: 'streaming',
256
+ /** Ended */
257
+ ENDED: 'ended',
258
+ /** Error */
259
+ ERROR: 'error',
260
+ /** Cancelled */
261
+ CANCELLED: 'cancelled'
262
+ };
263
+
264
+ /**
265
+ * Stream state value type
266
+ */
267
+
268
+ /**
269
+ * Stream event name constants (for stream.on / observability)
270
+ */
271
+ export var StreamEvent = {
272
+ START: 'start',
273
+ DATA: 'data',
274
+ READ: 'read',
275
+ WRITE: 'write',
276
+ SEND: 'send',
277
+ PULL: 'pull',
278
+ ACK: 'ack',
279
+ END: 'end',
280
+ CANCEL: 'cancel',
281
+ ERROR: 'error',
282
+ TIMEOUT: 'timeout',
283
+ EXPIRED: 'expired',
284
+ STATE: 'state'
285
+ };
286
+ /**
287
+ * Message constants (for multi-language support)
288
+ */
289
+ export { Messages, formatMessage, setMessages, resetMessages, getMessages } from './messages';
@@ -0,0 +1,157 @@
1
+ import "core-js/modules/es.array.filter.js";
2
+ import "core-js/modules/es.object.get-own-property-descriptors.js";
3
+ import "core-js/modules/web.dom-collections.for-each.js";
4
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
+ import "core-js/modules/es.regexp.exec.js";
6
+ import "core-js/modules/es.string.replace.js";
7
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
+ /**
10
+ * Message constants (for multi-language support)
11
+ *
12
+ * Usage:
13
+ * 1. Direct use: Messages.REQUEST_FAILED
14
+ * 2. Messages with parameters: Messages.formatMessage(Messages.CONNECT_TIMEOUT, timeout)
15
+ *
16
+ * Multi-language extension:
17
+ * You can use the setMessages() method to replace message content for multi-language support
18
+ */
19
+
20
+ /**
21
+ * Default message definitions
22
+ */
23
+ var defaultMessages = {
24
+ /** Protocol related errors */
25
+ INVALID_PROTOCOL_VERSION_FORMAT: 'Invalid protocol version format',
26
+ PROTOCOL_VERSION_TOO_LOW: 'Protocol version {0} is too low, minimum supported version is {1}',
27
+ PROTOCOL_VERSION_UNSUPPORTED: 'Protocol Version Unsupported',
28
+ /** Message format errors */
29
+ INVALID_MESSAGE_FORMAT_NOT_OBJECT: 'Invalid message format: not an object',
30
+ INVALID_MESSAGE_FORMAT_MISSING_PROTOCOL: 'Invalid message format: missing __requestIframe__ field',
31
+ INVALID_MESSAGE_FORMAT_MISSING_TYPE: 'Invalid message format: missing or invalid type field',
32
+ INVALID_MESSAGE_FORMAT_MISSING_REQUEST_ID: 'Invalid message format: missing or invalid requestId field',
33
+ /** Timeout errors */
34
+ ACK_TIMEOUT: 'ACK timeout after {0}ms',
35
+ REQUEST_TIMEOUT: 'Request timeout after {0}ms',
36
+ ASYNC_REQUEST_TIMEOUT: 'Async request timeout after {0}ms',
37
+ /** Request/response errors */
38
+ REQUEST_FAILED: 'Request failed',
39
+ METHOD_NOT_FOUND: 'Method not found',
40
+ NO_RESPONSE_SENT: 'Handler completed but no response sent',
41
+ MIDDLEWARE_ERROR: 'Middleware error',
42
+ ERROR: 'Error',
43
+ TOO_MANY_REQUESTS: 'Too many concurrent requests (limit: {0})',
44
+ /** Client errors */
45
+ IFRAME_NOT_READY: 'iframe.contentWindow is not available',
46
+ TARGET_WINDOW_CLOSED: 'Target window is closed or no longer available',
47
+ /** ClientServer warnings */
48
+ CLIENT_SERVER_IGNORED_MESSAGE_WHEN_CLOSED: 'Ignored message because client server is closed/destroyed (type: {0}, requestId: {1})',
49
+ /** Stream related messages */
50
+ STREAM_NOT_BOUND: 'Stream is not bound to a request context',
51
+ STREAM_ALREADY_STARTED: 'Stream has already started',
52
+ STREAM_CANCELLED: 'Stream was cancelled: {0}',
53
+ STREAM_ERROR: 'Stream error: {0}',
54
+ STREAM_TIMEOUT: 'Stream idle timeout after {0}ms',
55
+ STREAM_EXPIRED: 'Stream expired after {0}ms',
56
+ STREAM_START_TIMEOUT: 'Stream start timeout after {0}ms',
57
+ STREAM_ENDED: 'Stream has ended',
58
+ STREAM_READ_ERROR: 'Failed to read stream data',
59
+ STREAM_WRITE_ONLY_IN_PUSH_MODE: 'Stream write() is only available when mode is "push"',
60
+ STREAM_PENDING_QUEUE_OVERFLOW: 'Stream pending queue overflow (limit: {0})',
61
+ STREAM_PENDING_BYTES_OVERFLOW: 'Stream pending bytes overflow (limit: {0})',
62
+ /** Debug messages - Client */
63
+ DEBUG_CLIENT_REQUEST_START: '📤 [Client] Request Start',
64
+ DEBUG_CLIENT_REQUEST_SUCCESS: '✅ [Client] Request Success',
65
+ DEBUG_CLIENT_REQUEST_SUCCESS_FILE: '✅ [Client] Request Success (File)',
66
+ DEBUG_CLIENT_REQUEST_SUCCESS_STREAM: '✅ [Client] Request Success (Stream)',
67
+ DEBUG_CLIENT_REQUEST_FAILED: '❌ [Client] Request Failed',
68
+ DEBUG_CLIENT_RECEIVED_ACK: '📥 [Client] Received ACK',
69
+ DEBUG_CLIENT_RECEIVED_ASYNC: '⏳ [Client] Received ASYNC Notification',
70
+ DEBUG_CLIENT_RECEIVED_STREAM_START: '🌊 [Client] Received Stream Start',
71
+ DEBUG_CLIENT_RECEIVED_STREAM_DATA: '🌊 [Client] Received Stream Data',
72
+ DEBUG_CLIENT_RECEIVED_STREAM_END: '🌊 [Client] Received Stream End',
73
+ DEBUG_CLIENT_RECEIVED_RESPONSE: '📥 [Client] Received Response',
74
+ DEBUG_CLIENT_RECEIVED_ERROR: '📥 [Client] Received Error',
75
+ DEBUG_CLIENT_REQUEST_TIMEOUT: '⏱️ [Client] Request Timeout',
76
+ DEBUG_CLIENT_SENDING_REQUEST: '📤 [Client] Sending Request',
77
+ DEBUG_CLIENT_SENDING_PING: '📤 [Client] Sending Ping',
78
+ DEBUG_CLIENT_SENDING_RECEIVED_ACK: '📤 [Client] Sending ACK',
79
+ /** Debug messages - Server */
80
+ DEBUG_SERVER_RECEIVED_REQUEST: '📥 [Server] Received Request',
81
+ DEBUG_SERVER_SETTING_STATUS_CODE: '📝 [Server] Setting Status Code',
82
+ DEBUG_SERVER_SETTING_HEADER: '📝 [Server] Setting Header',
83
+ DEBUG_SERVER_SENDING_RESPONSE: '📤 [Server] Sending Response',
84
+ DEBUG_SERVER_SENDING_JSON_RESPONSE: '📤 [Server] Sending JSON Response',
85
+ DEBUG_SERVER_SENDING_FILE: '📤 [Server] Sending File',
86
+ DEBUG_SERVER_SENDING_STREAM: '📤 [Server] Sending Stream',
87
+ DEBUG_SERVER_SENDING_ACK: '📤 [Server] Sending ACK',
88
+ DEBUG_SERVER_SENDING_ASYNC: '📤 [Server] Sending ASYNC Notification',
89
+ DEBUG_SERVER_SENDING_STREAM_START: '🌊 [Server] Sending Stream Start',
90
+ DEBUG_SERVER_SENDING_STREAM_DATA: '🌊 [Server] Sending Stream Data',
91
+ DEBUG_SERVER_SENDING_STREAM_END: '🌊 [Server] Sending Stream End',
92
+ DEBUG_SERVER_SENDING_ERROR: '📤 [Server] Sending Error',
93
+ DEBUG_SERVER_SENDING_RESPONSE_VIA_DISPATCHER: '📤 [Server] Sending Response (via dispatcher)',
94
+ DEBUG_SERVER_HANDLING_REQUEST: '📥 [Server] Handling Request',
95
+ DEBUG_SERVER_EXECUTING_MIDDLEWARE_CHAIN: '⚙️ [Server] Executing Middleware Chain',
96
+ DEBUG_SERVER_MIDDLEWARE_CHAIN_COMPLETED: '✅ [Server] Middleware Chain Completed'
97
+ };
98
+
99
+ /**
100
+ * Message type
101
+ */
102
+
103
+ /**
104
+ * Current message configuration
105
+ */
106
+ var currentMessages = _objectSpread({}, defaultMessages);
107
+
108
+ /**
109
+ * Message constants object
110
+ */
111
+ export var Messages = new Proxy(currentMessages, {
112
+ get(target, prop) {
113
+ return target[prop] || prop;
114
+ }
115
+ });
116
+
117
+ /**
118
+ * Set message content (for multi-language support)
119
+ * @param messages Custom message content (partial or full)
120
+ */
121
+ export function setMessages(messages) {
122
+ currentMessages = _objectSpread(_objectSpread({}, defaultMessages), messages);
123
+ }
124
+
125
+ /**
126
+ * Reset to default messages
127
+ */
128
+ export function resetMessages() {
129
+ currentMessages = _objectSpread({}, defaultMessages);
130
+ }
131
+
132
+ /**
133
+ * Format message (replace placeholders)
134
+ * @param template Message template, using {0}, {1}, etc. as placeholders
135
+ * @param args Replacement parameters
136
+ * @returns Formatted message
137
+ *
138
+ * @example
139
+ * formatMessage('Connect timeout after {0}ms', 5000)
140
+ * // => 'Connect timeout after 5000ms'
141
+ *
142
+ * formatMessage('Protocol version {0} is too low, minimum supported version is {1}', 0, 1)
143
+ * // => 'Protocol version 0 is too low, minimum supported version is 1'
144
+ */
145
+ export function formatMessage(template, ...args) {
146
+ return template.replace(/\{(\d+)\}/g, (match, index) => {
147
+ var argIndex = parseInt(index, 10);
148
+ return argIndex < args.length ? String(args[argIndex]) : match;
149
+ });
150
+ }
151
+
152
+ /**
153
+ * Get current message configuration
154
+ */
155
+ export function getMessages() {
156
+ return _objectSpread({}, currentMessages);
157
+ }