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.
Files changed (96) hide show
  1. package/QUICKSTART.CN.md +269 -0
  2. package/QUICKSTART.md +269 -0
  3. package/README.CN.md +1369 -0
  4. package/README.md +1016 -0
  5. package/library/__tests__/interceptors.test.ts +124 -0
  6. package/library/__tests__/requestIframe.test.ts +2216 -0
  7. package/library/__tests__/stream.test.ts +650 -0
  8. package/library/__tests__/utils.test.ts +433 -0
  9. package/library/api/client.d.ts +16 -0
  10. package/library/api/client.d.ts.map +1 -0
  11. package/library/api/client.js +72 -0
  12. package/library/api/server.d.ts +16 -0
  13. package/library/api/server.d.ts.map +1 -0
  14. package/library/api/server.js +44 -0
  15. package/library/constants/index.d.ts +209 -0
  16. package/library/constants/index.d.ts.map +1 -0
  17. package/library/constants/index.js +260 -0
  18. package/library/constants/messages.d.ts +80 -0
  19. package/library/constants/messages.d.ts.map +1 -0
  20. package/library/constants/messages.js +123 -0
  21. package/library/core/client.d.ts +99 -0
  22. package/library/core/client.d.ts.map +1 -0
  23. package/library/core/client.js +440 -0
  24. package/library/core/message-handler.d.ts +110 -0
  25. package/library/core/message-handler.d.ts.map +1 -0
  26. package/library/core/message-handler.js +320 -0
  27. package/library/core/request-response.d.ts +59 -0
  28. package/library/core/request-response.d.ts.map +1 -0
  29. package/library/core/request-response.js +337 -0
  30. package/library/core/request.d.ts +17 -0
  31. package/library/core/request.d.ts.map +1 -0
  32. package/library/core/request.js +34 -0
  33. package/library/core/response.d.ts +51 -0
  34. package/library/core/response.d.ts.map +1 -0
  35. package/library/core/response.js +323 -0
  36. package/library/core/server-base.d.ts +86 -0
  37. package/library/core/server-base.d.ts.map +1 -0
  38. package/library/core/server-base.js +257 -0
  39. package/library/core/server-client.d.ts +99 -0
  40. package/library/core/server-client.d.ts.map +1 -0
  41. package/library/core/server-client.js +256 -0
  42. package/library/core/server.d.ts +82 -0
  43. package/library/core/server.d.ts.map +1 -0
  44. package/library/core/server.js +338 -0
  45. package/library/index.d.ts +16 -0
  46. package/library/index.d.ts.map +1 -0
  47. package/library/index.js +211 -0
  48. package/library/interceptors/index.d.ts +41 -0
  49. package/library/interceptors/index.d.ts.map +1 -0
  50. package/library/interceptors/index.js +126 -0
  51. package/library/message/channel.d.ts +107 -0
  52. package/library/message/channel.d.ts.map +1 -0
  53. package/library/message/channel.js +184 -0
  54. package/library/message/dispatcher.d.ts +119 -0
  55. package/library/message/dispatcher.d.ts.map +1 -0
  56. package/library/message/dispatcher.js +249 -0
  57. package/library/message/index.d.ts +5 -0
  58. package/library/message/index.d.ts.map +1 -0
  59. package/library/message/index.js +25 -0
  60. package/library/stream/file-stream.d.ts +48 -0
  61. package/library/stream/file-stream.d.ts.map +1 -0
  62. package/library/stream/file-stream.js +240 -0
  63. package/library/stream/index.d.ts +15 -0
  64. package/library/stream/index.d.ts.map +1 -0
  65. package/library/stream/index.js +83 -0
  66. package/library/stream/readable-stream.d.ts +83 -0
  67. package/library/stream/readable-stream.d.ts.map +1 -0
  68. package/library/stream/readable-stream.js +249 -0
  69. package/library/stream/types.d.ts +165 -0
  70. package/library/stream/types.d.ts.map +1 -0
  71. package/library/stream/types.js +5 -0
  72. package/library/stream/writable-stream.d.ts +60 -0
  73. package/library/stream/writable-stream.d.ts.map +1 -0
  74. package/library/stream/writable-stream.js +348 -0
  75. package/library/types/index.d.ts +408 -0
  76. package/library/types/index.d.ts.map +1 -0
  77. package/library/types/index.js +5 -0
  78. package/library/utils/cache.d.ts +19 -0
  79. package/library/utils/cache.d.ts.map +1 -0
  80. package/library/utils/cache.js +83 -0
  81. package/library/utils/cookie.d.ts +117 -0
  82. package/library/utils/cookie.d.ts.map +1 -0
  83. package/library/utils/cookie.js +365 -0
  84. package/library/utils/debug.d.ts +11 -0
  85. package/library/utils/debug.d.ts.map +1 -0
  86. package/library/utils/debug.js +162 -0
  87. package/library/utils/index.d.ts +13 -0
  88. package/library/utils/index.d.ts.map +1 -0
  89. package/library/utils/index.js +132 -0
  90. package/library/utils/path-match.d.ts +17 -0
  91. package/library/utils/path-match.d.ts.map +1 -0
  92. package/library/utils/path-match.js +90 -0
  93. package/library/utils/protocol.d.ts +61 -0
  94. package/library/utils/protocol.d.ts.map +1 -0
  95. package/library/utils/protocol.js +169 -0
  96. package/package.json +58 -0
@@ -0,0 +1,365 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.symbol.description.js");
4
+ require("core-js/modules/es.array.filter.js");
5
+ require("core-js/modules/es.array.from.js");
6
+ require("core-js/modules/es.object.get-own-property-descriptors.js");
7
+ require("core-js/modules/es.regexp.exec.js");
8
+ require("core-js/modules/es.regexp.to-string.js");
9
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
10
+ Object.defineProperty(exports, "__esModule", {
11
+ value: true
12
+ });
13
+ exports.CookieStore = void 0;
14
+ exports.createClearCookie = createClearCookie;
15
+ exports.createSetCookie = createSetCookie;
16
+ exports.matchCookiePath = matchCookiePath;
17
+ exports.parseSetCookie = parseSetCookie;
18
+ exports.serializeSetCookie = serializeSetCookie;
19
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
+ require("core-js/modules/es.array.index-of.js");
21
+ require("core-js/modules/es.array.iterator.js");
22
+ require("core-js/modules/es.array.map.js");
23
+ require("core-js/modules/es.array.slice.js");
24
+ require("core-js/modules/es.map.js");
25
+ require("core-js/modules/es.string.ends-with.js");
26
+ require("core-js/modules/es.string.starts-with.js");
27
+ require("core-js/modules/es.string.trim.js");
28
+ require("core-js/modules/web.dom-collections.for-each.js");
29
+ require("core-js/modules/web.dom-collections.iterator.js");
30
+ 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; }
31
+ 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) { (0, _defineProperty2.default)(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; }
32
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
33
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
34
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
35
+ /**
36
+ * Cookie management utilities
37
+ * Implements browser-like Cookie mechanism
38
+ */
39
+
40
+ /**
41
+ * Cookie storage item
42
+ */
43
+
44
+ /**
45
+ * Cookie options (for res.cookie)
46
+ */
47
+
48
+ /**
49
+ * Parse Set-Cookie string to CookieItem
50
+ * @param setCookieStr Set-Cookie string, e.g., "token=abc; Path=/; HttpOnly"
51
+ */
52
+ function parseSetCookie(setCookieStr) {
53
+ if (!setCookieStr) return null;
54
+ var parts = setCookieStr.split(';').map(p => p.trim());
55
+ if (parts.length === 0) return null;
56
+
57
+ // First part is name=value
58
+ var firstPart = parts[0];
59
+ var eqIndex = firstPart.indexOf('=');
60
+ if (eqIndex === -1) return null;
61
+ var name = firstPart.substring(0, eqIndex).trim();
62
+ var value = firstPart.substring(eqIndex + 1).trim();
63
+ if (!name) return null;
64
+ var cookie = {
65
+ name,
66
+ value,
67
+ path: '/' // Default path
68
+ };
69
+
70
+ // Parse other attributes
71
+ for (var i = 1; i < parts.length; i++) {
72
+ var part = parts[i];
73
+ var attrEqIndex = part.indexOf('=');
74
+ if (attrEqIndex === -1) {
75
+ // Attribute without value
76
+ var attrName = part.toLowerCase();
77
+ if (attrName === 'httponly') {
78
+ cookie.httpOnly = true;
79
+ } else if (attrName === 'secure') {
80
+ cookie.secure = true;
81
+ }
82
+ } else {
83
+ // Attribute with value
84
+ var _attrName = part.substring(0, attrEqIndex).trim().toLowerCase();
85
+ var attrValue = part.substring(attrEqIndex + 1).trim();
86
+ if (_attrName === 'path') {
87
+ cookie.path = attrValue || '/';
88
+ } else if (_attrName === 'expires') {
89
+ var date = new Date(attrValue);
90
+ if (!isNaN(date.getTime())) {
91
+ cookie.expires = date.getTime();
92
+ }
93
+ } else if (_attrName === 'max-age') {
94
+ var maxAge = parseInt(attrValue, 10);
95
+ if (!isNaN(maxAge)) {
96
+ cookie.expires = Date.now() + maxAge * 1000;
97
+ }
98
+ } else if (_attrName === 'samesite') {
99
+ var sameSite = attrValue.charAt(0).toUpperCase() + attrValue.slice(1).toLowerCase();
100
+ if (sameSite === 'Strict' || sameSite === 'Lax' || sameSite === 'None') {
101
+ cookie.sameSite = sameSite;
102
+ }
103
+ }
104
+ }
105
+ }
106
+ return cookie;
107
+ }
108
+
109
+ /**
110
+ * Serialize CookieItem to Set-Cookie string
111
+ */
112
+ function serializeSetCookie(cookie) {
113
+ var str = `${cookie.name}=${cookie.value}`;
114
+ if (cookie.path) {
115
+ str += `; Path=${cookie.path}`;
116
+ }
117
+ if (cookie.expires !== undefined) {
118
+ str += `; Expires=${new Date(cookie.expires).toUTCString()}`;
119
+ }
120
+ if (cookie.httpOnly) {
121
+ str += '; HttpOnly';
122
+ }
123
+ if (cookie.secure) {
124
+ str += '; Secure';
125
+ }
126
+ if (cookie.sameSite) {
127
+ str += `; SameSite=${cookie.sameSite}`;
128
+ }
129
+ return str;
130
+ }
131
+
132
+ /**
133
+ * Create Set-Cookie string from CookieOptions
134
+ */
135
+ function createSetCookie(name, value, options) {
136
+ var _options$path;
137
+ var str = `${name}=${value}`;
138
+ var path = (_options$path = options === null || options === void 0 ? void 0 : options.path) !== null && _options$path !== void 0 ? _options$path : '/';
139
+ str += `; Path=${path}`;
140
+ if (options !== null && options !== void 0 && options.expires) {
141
+ str += `; Expires=${options.expires.toUTCString()}`;
142
+ } else if ((options === null || options === void 0 ? void 0 : options.maxAge) !== undefined) {
143
+ var expires = new Date(Date.now() + options.maxAge * 1000);
144
+ str += `; Expires=${expires.toUTCString()}`;
145
+ str += `; Max-Age=${options.maxAge}`;
146
+ }
147
+ if (options !== null && options !== void 0 && options.httpOnly) {
148
+ str += '; HttpOnly';
149
+ }
150
+ if (options !== null && options !== void 0 && options.secure) {
151
+ str += '; Secure';
152
+ }
153
+ if (options !== null && options !== void 0 && options.sameSite) {
154
+ str += `; SameSite=${options.sameSite}`;
155
+ }
156
+ return str;
157
+ }
158
+
159
+ /**
160
+ * Create Set-Cookie string to delete Cookie
161
+ */
162
+ function createClearCookie(name, options) {
163
+ var _options$path2;
164
+ var path = (_options$path2 = options === null || options === void 0 ? void 0 : options.path) !== null && _options$path2 !== void 0 ? _options$path2 : '/';
165
+ // Set expiration time to past to delete cookie
166
+ return `${name}=; Path=${path}; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0`;
167
+ }
168
+
169
+ /**
170
+ * Check if request path matches Cookie's path attribute
171
+ * Implements RFC 6265 path matching algorithm
172
+ * @param requestPath request path, e.g., "/api/users"
173
+ * @param cookiePath Cookie's path attribute, e.g., "/api"
174
+ */
175
+ function matchCookiePath(requestPath, cookiePath) {
176
+ // Normalize paths
177
+ var reqPath = normalizePath(requestPath);
178
+ var cPath = normalizePath(cookiePath);
179
+
180
+ // Exact match
181
+ if (reqPath === cPath) {
182
+ return true;
183
+ }
184
+
185
+ // Cookie path is prefix of request path
186
+ if (reqPath.startsWith(cPath)) {
187
+ // Cookie path ends with / or request path has / after cookie path
188
+ if (cPath.endsWith('/') || reqPath.charAt(cPath.length) === '/') {
189
+ return true;
190
+ }
191
+ }
192
+ return false;
193
+ }
194
+
195
+ /**
196
+ * Normalize path
197
+ */
198
+ function normalizePath(path) {
199
+ if (!path || path === '') return '/';
200
+ // Ensure starts with /
201
+ if (!path.startsWith('/')) {
202
+ path = '/' + path;
203
+ }
204
+ // Remove trailing / (unless root path)
205
+ if (path.length > 1 && path.endsWith('/')) {
206
+ path = path.slice(0, -1);
207
+ }
208
+ return path;
209
+ }
210
+
211
+ /**
212
+ * Cookie storage manager
213
+ */
214
+ class CookieStore {
215
+ constructor() {
216
+ (0, _defineProperty2.default)(this, "cookies", new Map());
217
+ }
218
+ /**
219
+ * Generate unique key for Cookie
220
+ */
221
+ getKey(name, path) {
222
+ return `${name}|${path}`;
223
+ }
224
+
225
+ /**
226
+ * Set Cookie
227
+ */
228
+ set(cookie) {
229
+ var key = this.getKey(cookie.name, cookie.path);
230
+ this.cookies.set(key, cookie);
231
+ }
232
+
233
+ /**
234
+ * Set Cookie from Set-Cookie string
235
+ */
236
+ setFromSetCookie(setCookieStr) {
237
+ var cookie = parseSetCookie(setCookieStr);
238
+ if (cookie) {
239
+ // Check if this is a delete operation (expiration in the past)
240
+ if (cookie.expires !== undefined && cookie.expires <= Date.now()) {
241
+ this.remove(cookie.name, cookie.path);
242
+ } else {
243
+ this.set(cookie);
244
+ }
245
+ }
246
+ }
247
+
248
+ /**
249
+ * Remove Cookie
250
+ */
251
+ remove(name, path = '/') {
252
+ var key = this.getKey(name, path);
253
+ this.cookies.delete(key);
254
+ }
255
+
256
+ /**
257
+ * Get all Cookies matching specified path
258
+ * @param requestPath request path
259
+ * @returns matching cookies, format: Record<string, string>
260
+ */
261
+ getForPath(requestPath) {
262
+ var result = {};
263
+ var now = Date.now();
264
+ this.cookies.forEach(cookie => {
265
+ // Check if expired
266
+ if (cookie.expires !== undefined && cookie.expires <= now) {
267
+ return;
268
+ }
269
+
270
+ // Check if path matches
271
+ if (matchCookiePath(requestPath, cookie.path)) {
272
+ // If same-name cookie already exists, use the one with longer (more specific) path
273
+ if (result[cookie.name] === undefined) {
274
+ result[cookie.name] = cookie.value;
275
+ }
276
+ }
277
+ });
278
+ return result;
279
+ }
280
+
281
+ /**
282
+ * Get Cookie value by name
283
+ * @param name Cookie name
284
+ * @param path path (optional, returns first match if not specified)
285
+ */
286
+ get(name, path) {
287
+ if (path) {
288
+ var key = this.getKey(name, path);
289
+ var cookie = this.cookies.get(key);
290
+ if (cookie && (!cookie.expires || cookie.expires > Date.now())) {
291
+ return cookie.value;
292
+ }
293
+ return undefined;
294
+ }
295
+
296
+ // If path not specified, find all cookies with same name
297
+ var _iterator = _createForOfIteratorHelper(this.cookies.values()),
298
+ _step;
299
+ try {
300
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
301
+ var _cookie = _step.value;
302
+ if (_cookie.name === name) {
303
+ if (!_cookie.expires || _cookie.expires > Date.now()) {
304
+ return _cookie.value;
305
+ }
306
+ }
307
+ }
308
+ } catch (err) {
309
+ _iterator.e(err);
310
+ } finally {
311
+ _iterator.f();
312
+ }
313
+ return undefined;
314
+ }
315
+
316
+ /**
317
+ * Get all Cookies (with full info)
318
+ */
319
+ getAll() {
320
+ var now = Date.now();
321
+ var result = [];
322
+ this.cookies.forEach(cookie => {
323
+ if (!cookie.expires || cookie.expires > now) {
324
+ result.push(_objectSpread({}, cookie));
325
+ }
326
+ });
327
+ return result;
328
+ }
329
+
330
+ /**
331
+ * Get all Cookies (simple format)
332
+ */
333
+ getAllSimple() {
334
+ var result = {};
335
+ var now = Date.now();
336
+ this.cookies.forEach(cookie => {
337
+ if (!cookie.expires || cookie.expires > now) {
338
+ result[cookie.name] = cookie.value;
339
+ }
340
+ });
341
+ return result;
342
+ }
343
+
344
+ /**
345
+ * Clear all Cookies
346
+ */
347
+ clear() {
348
+ this.cookies.clear();
349
+ }
350
+
351
+ /**
352
+ * Cleanup expired Cookies
353
+ */
354
+ cleanup() {
355
+ var now = Date.now();
356
+ var keysToDelete = [];
357
+ this.cookies.forEach((cookie, key) => {
358
+ if (cookie.expires !== undefined && cookie.expires <= now) {
359
+ keysToDelete.push(key);
360
+ }
361
+ });
362
+ keysToDelete.forEach(key => this.cookies.delete(key));
363
+ }
364
+ }
365
+ exports.CookieStore = CookieStore;
@@ -0,0 +1,11 @@
1
+ import { RequestIframeClient, RequestIframeServer } from '../types';
2
+ /**
3
+ * Register debug interceptors for client
4
+ */
5
+ export declare function setupClientDebugInterceptors(client: RequestIframeClient): void;
6
+ /**
7
+ * Register debug listeners for server
8
+ * Use middleware to log requests and responses
9
+ */
10
+ export declare function setupServerDebugListeners(server: RequestIframeServer): void;
11
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/utils/debug.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAqBpE;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAmC9E;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAqD3E"}
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.setupClientDebugInterceptors = setupClientDebugInterceptors;
8
+ exports.setupServerDebugListeners = setupServerDebugListeners;
9
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
+ require("core-js/modules/es.promise.js");
12
+ /**
13
+ * Debug log prefix
14
+ */
15
+ var DEBUG_PREFIX = '[request-iframe]';
16
+
17
+ /**
18
+ * Format log output
19
+ */
20
+ function log(level, message, data) {
21
+ var timestamp = new Date().toISOString();
22
+ var prefix = `${DEBUG_PREFIX} [${timestamp}] [${level.toUpperCase()}]`;
23
+ if (data !== undefined) {
24
+ console[level](`${prefix} ${message}`, data);
25
+ } else {
26
+ console[level](`${prefix} ${message}`);
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Register debug interceptors for client
32
+ */
33
+ function setupClientDebugInterceptors(client) {
34
+ // Request interceptor: log request start
35
+ client.interceptors.request.use(config => {
36
+ log('info', '📤 Request Start', {
37
+ path: config.path,
38
+ body: config.body,
39
+ ackTimeout: config.ackTimeout,
40
+ timeout: config.timeout,
41
+ asyncTimeout: config.asyncTimeout,
42
+ requestId: config.requestId
43
+ });
44
+ return config;
45
+ });
46
+
47
+ // Response interceptor: log response success
48
+ client.interceptors.response.use(response => {
49
+ log('info', '✅ Request Success', {
50
+ requestId: response.requestId,
51
+ status: response.status,
52
+ statusText: response.statusText,
53
+ data: response.data
54
+ });
55
+ return response;
56
+ }, error => {
57
+ log('error', '❌ Request Failed', {
58
+ requestId: error.requestId,
59
+ code: error.code,
60
+ message: error.message,
61
+ response: error.response
62
+ });
63
+ return Promise.reject(error);
64
+ });
65
+ }
66
+
67
+ /**
68
+ * Register debug listeners for server
69
+ * Use middleware to log requests and responses
70
+ */
71
+ function setupServerDebugListeners(server) {
72
+ // Use global middleware to log requests
73
+ server.use((req, res, next) => {
74
+ log('info', '📥 Server Received Request', {
75
+ requestId: req.requestId,
76
+ path: req.path,
77
+ body: req.body,
78
+ origin: req.origin,
79
+ headers: req.headers,
80
+ cookies: req.cookies
81
+ });
82
+
83
+ // Store original send methods
84
+ var originalSend = res.send.bind(res);
85
+ var originalJson = res.json.bind(res);
86
+ var originalSendFile = res.sendFile.bind(res);
87
+
88
+ // Override send method
89
+ res.send = /*#__PURE__*/function () {
90
+ var _ref = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(data, options) {
91
+ return _regenerator.default.wrap(function (_context) {
92
+ while (1) switch (_context.prev = _context.next) {
93
+ case 0:
94
+ log('info', '📤 Server Sending Response', {
95
+ requestId: req.requestId,
96
+ path: req.path,
97
+ status: res.statusCode,
98
+ data
99
+ });
100
+ return _context.abrupt("return", originalSend(data, options));
101
+ case 1:
102
+ case "end":
103
+ return _context.stop();
104
+ }
105
+ }, _callee);
106
+ }));
107
+ return function (_x, _x2) {
108
+ return _ref.apply(this, arguments);
109
+ };
110
+ }();
111
+
112
+ // Override json method
113
+ res.json = /*#__PURE__*/function () {
114
+ var _ref2 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2(data, options) {
115
+ return _regenerator.default.wrap(function (_context2) {
116
+ while (1) switch (_context2.prev = _context2.next) {
117
+ case 0:
118
+ log('info', '📤 Server Sending JSON Response', {
119
+ requestId: req.requestId,
120
+ path: req.path,
121
+ status: res.statusCode,
122
+ data
123
+ });
124
+ return _context2.abrupt("return", originalJson(data, options));
125
+ case 1:
126
+ case "end":
127
+ return _context2.stop();
128
+ }
129
+ }, _callee2);
130
+ }));
131
+ return function (_x3, _x4) {
132
+ return _ref2.apply(this, arguments);
133
+ };
134
+ }();
135
+
136
+ // Override sendFile method
137
+ res.sendFile = /*#__PURE__*/function () {
138
+ var _ref3 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3(content, options) {
139
+ return _regenerator.default.wrap(function (_context3) {
140
+ while (1) switch (_context3.prev = _context3.next) {
141
+ case 0:
142
+ log('info', '📤 Server Sending File', {
143
+ requestId: req.requestId,
144
+ path: req.path,
145
+ status: res.statusCode,
146
+ fileName: options === null || options === void 0 ? void 0 : options.fileName,
147
+ mimeType: options === null || options === void 0 ? void 0 : options.mimeType
148
+ });
149
+ return _context3.abrupt("return", originalSendFile(content, options));
150
+ case 1:
151
+ case "end":
152
+ return _context3.stop();
153
+ }
154
+ }, _callee3);
155
+ }));
156
+ return function (_x5, _x6) {
157
+ return _ref3.apply(this, arguments);
158
+ };
159
+ }();
160
+ next();
161
+ });
162
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Generate unique request ID
3
+ */
4
+ export declare function generateRequestId(): string;
5
+ /**
6
+ * Derive targetOrigin from iframe.src
7
+ */
8
+ export declare function getIframeTargetOrigin(iframe: HTMLIFrameElement): string;
9
+ export { createPostMessage, isValidPostMessage, validatePostMessage, validateProtocolVersion, isRequestIframeMessage, getProtocolVersion, isCompatibleVersion } from './protocol';
10
+ export * from './cache';
11
+ export * from './path-match';
12
+ export * from './cookie';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CASvE;AAGD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAGpB,cAAc,SAAS,CAAC;AAGxB,cAAc,cAAc,CAAC;AAG7B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/web.dom-collections.for-each.js");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ var _exportNames = {
8
+ generateRequestId: true,
9
+ getIframeTargetOrigin: true,
10
+ createPostMessage: true,
11
+ isValidPostMessage: true,
12
+ validatePostMessage: true,
13
+ validateProtocolVersion: true,
14
+ isRequestIframeMessage: true,
15
+ getProtocolVersion: true,
16
+ isCompatibleVersion: true
17
+ };
18
+ Object.defineProperty(exports, "createPostMessage", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _protocol.createPostMessage;
22
+ }
23
+ });
24
+ exports.generateRequestId = generateRequestId;
25
+ exports.getIframeTargetOrigin = getIframeTargetOrigin;
26
+ Object.defineProperty(exports, "getProtocolVersion", {
27
+ enumerable: true,
28
+ get: function get() {
29
+ return _protocol.getProtocolVersion;
30
+ }
31
+ });
32
+ Object.defineProperty(exports, "isCompatibleVersion", {
33
+ enumerable: true,
34
+ get: function get() {
35
+ return _protocol.isCompatibleVersion;
36
+ }
37
+ });
38
+ Object.defineProperty(exports, "isRequestIframeMessage", {
39
+ enumerable: true,
40
+ get: function get() {
41
+ return _protocol.isRequestIframeMessage;
42
+ }
43
+ });
44
+ Object.defineProperty(exports, "isValidPostMessage", {
45
+ enumerable: true,
46
+ get: function get() {
47
+ return _protocol.isValidPostMessage;
48
+ }
49
+ });
50
+ Object.defineProperty(exports, "validatePostMessage", {
51
+ enumerable: true,
52
+ get: function get() {
53
+ return _protocol.validatePostMessage;
54
+ }
55
+ });
56
+ Object.defineProperty(exports, "validateProtocolVersion", {
57
+ enumerable: true,
58
+ get: function get() {
59
+ return _protocol.validateProtocolVersion;
60
+ }
61
+ });
62
+ require("core-js/modules/es.array.iterator.js");
63
+ require("core-js/modules/es.regexp.to-string.js");
64
+ require("core-js/modules/web.dom-collections.iterator.js");
65
+ require("core-js/modules/web.url.js");
66
+ require("core-js/modules/web.url.to-json.js");
67
+ require("core-js/modules/web.url-search-params.js");
68
+ var _protocol = require("./protocol");
69
+ var _cache = require("./cache");
70
+ Object.keys(_cache).forEach(function (key) {
71
+ if (key === "default" || key === "__esModule") return;
72
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
73
+ if (key in exports && exports[key] === _cache[key]) return;
74
+ Object.defineProperty(exports, key, {
75
+ enumerable: true,
76
+ get: function get() {
77
+ return _cache[key];
78
+ }
79
+ });
80
+ });
81
+ var _pathMatch = require("./path-match");
82
+ Object.keys(_pathMatch).forEach(function (key) {
83
+ if (key === "default" || key === "__esModule") return;
84
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
85
+ if (key in exports && exports[key] === _pathMatch[key]) return;
86
+ Object.defineProperty(exports, key, {
87
+ enumerable: true,
88
+ get: function get() {
89
+ return _pathMatch[key];
90
+ }
91
+ });
92
+ });
93
+ var _cookie = require("./cookie");
94
+ Object.keys(_cookie).forEach(function (key) {
95
+ if (key === "default" || key === "__esModule") return;
96
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
97
+ if (key in exports && exports[key] === _cookie[key]) return;
98
+ Object.defineProperty(exports, key, {
99
+ enumerable: true,
100
+ get: function get() {
101
+ return _cookie[key];
102
+ }
103
+ });
104
+ });
105
+ /**
106
+ * Generate unique request ID
107
+ */
108
+ function generateRequestId() {
109
+ return `req_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
110
+ }
111
+
112
+ /**
113
+ * Derive targetOrigin from iframe.src
114
+ */
115
+ function getIframeTargetOrigin(iframe) {
116
+ if (!iframe.src) {
117
+ return '*';
118
+ }
119
+ try {
120
+ return new URL(iframe.src).origin;
121
+ } catch (e) {
122
+ return '*';
123
+ }
124
+ }
125
+
126
+ // Export protocol-related functions
127
+
128
+ // Export cache-related functions
129
+
130
+ // Export path matching functions
131
+
132
+ // Export Cookie-related functions