typeferry 0.6.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 (392) hide show
  1. package/README.md +88 -0
  2. package/dist/auth/client/cross-tab-sync.d.ts +21 -0
  3. package/dist/auth/client/cross-tab-sync.js +56 -0
  4. package/dist/auth/client/cross-tab-sync.js.map +1 -0
  5. package/dist/auth/client/index.d.ts +2 -0
  6. package/dist/auth/client/index.js +3 -0
  7. package/dist/auth/client/index.js.map +1 -0
  8. package/dist/auth/client/oauth/google-provider.d.ts +11 -0
  9. package/dist/auth/client/oauth/google-provider.js +11 -0
  10. package/dist/auth/client/oauth/google-provider.js.map +1 -0
  11. package/dist/auth/client/oauth/index.d.ts +4 -0
  12. package/dist/auth/client/oauth/index.js +3 -0
  13. package/dist/auth/client/oauth/index.js.map +1 -0
  14. package/dist/auth/client/oauth/use-google-login.d.ts +39 -0
  15. package/dist/auth/client/oauth/use-google-login.js +55 -0
  16. package/dist/auth/client/oauth/use-google-login.js.map +1 -0
  17. package/dist/auth/client/token-refresh.d.ts +21 -0
  18. package/dist/auth/client/token-refresh.js +212 -0
  19. package/dist/auth/client/token-refresh.js.map +1 -0
  20. package/dist/auth/index.d.ts +7 -0
  21. package/dist/auth/index.js +9 -0
  22. package/dist/auth/index.js.map +1 -0
  23. package/dist/auth/server/cookie-utils.d.ts +42 -0
  24. package/dist/auth/server/cookie-utils.js +91 -0
  25. package/dist/auth/server/cookie-utils.js.map +1 -0
  26. package/dist/auth/server/device-info.d.ts +23 -0
  27. package/dist/auth/server/device-info.js +52 -0
  28. package/dist/auth/server/device-info.js.map +1 -0
  29. package/dist/auth/server/index.d.ts +4 -0
  30. package/dist/auth/server/index.js +5 -0
  31. package/dist/auth/server/index.js.map +1 -0
  32. package/dist/auth/server/jwt-utils.d.ts +29 -0
  33. package/dist/auth/server/jwt-utils.js +53 -0
  34. package/dist/auth/server/jwt-utils.js.map +1 -0
  35. package/dist/auth/server/oauth/google.d.ts +31 -0
  36. package/dist/auth/server/oauth/google.js +40 -0
  37. package/dist/auth/server/oauth/google.js.map +1 -0
  38. package/dist/auth/server/oauth/index.d.ts +3 -0
  39. package/dist/auth/server/oauth/index.js +2 -0
  40. package/dist/auth/server/oauth/index.js.map +1 -0
  41. package/dist/auth/server/oauth/types.d.ts +37 -0
  42. package/dist/auth/server/oauth/types.js +2 -0
  43. package/dist/auth/server/oauth/types.js.map +1 -0
  44. package/dist/auth/server/session-manager.d.ts +46 -0
  45. package/dist/auth/server/session-manager.js +167 -0
  46. package/dist/auth/server/session-manager.js.map +1 -0
  47. package/dist/auth/types.d.ts +197 -0
  48. package/dist/auth/types.js +2 -0
  49. package/dist/auth/types.js.map +1 -0
  50. package/dist/client/call-method-proxy.d.ts +2 -0
  51. package/dist/client/call-method-proxy.js +22 -0
  52. package/dist/client/call-method-proxy.js.map +1 -0
  53. package/dist/client/client-channel.d.ts +43 -0
  54. package/dist/client/client-channel.js +148 -0
  55. package/dist/client/client-channel.js.map +1 -0
  56. package/dist/client/client-http.d.ts +27 -0
  57. package/dist/client/client-http.js +106 -0
  58. package/dist/client/client-http.js.map +1 -0
  59. package/dist/client/client-socket.d.ts +85 -0
  60. package/dist/client/client-socket.js +317 -0
  61. package/dist/client/client-socket.js.map +1 -0
  62. package/dist/client/client.d.ts +149 -0
  63. package/dist/client/client.js +401 -0
  64. package/dist/client/client.js.map +1 -0
  65. package/dist/client/context-manager.d.ts +54 -0
  66. package/dist/client/context-manager.js +89 -0
  67. package/dist/client/context-manager.js.map +1 -0
  68. package/dist/client/idle-timer.d.ts +35 -0
  69. package/dist/client/idle-timer.js +101 -0
  70. package/dist/client/idle-timer.js.map +1 -0
  71. package/dist/client/index.d.ts +6 -0
  72. package/dist/client/index.js +7 -0
  73. package/dist/client/index.js.map +1 -0
  74. package/dist/client/logger.d.ts +76 -0
  75. package/dist/client/logger.js +129 -0
  76. package/dist/client/logger.js.map +1 -0
  77. package/dist/client/visibility-manager.d.ts +62 -0
  78. package/dist/client/visibility-manager.js +177 -0
  79. package/dist/client/visibility-manager.js.map +1 -0
  80. package/dist/ejson/adjust-types-from-json-value.d.ts +1 -0
  81. package/dist/ejson/adjust-types-from-json-value.js +35 -0
  82. package/dist/ejson/adjust-types-from-json-value.js.map +1 -0
  83. package/dist/ejson/base64.d.ts +11 -0
  84. package/dist/ejson/base64.js +87 -0
  85. package/dist/ejson/base64.js.map +1 -0
  86. package/dist/ejson/built-in-converters.d.ts +1 -0
  87. package/dist/ejson/built-in-converters.js +137 -0
  88. package/dist/ejson/built-in-converters.js.map +1 -0
  89. package/dist/ejson/clone.d.ts +1 -0
  90. package/dist/ejson/clone.js +80 -0
  91. package/dist/ejson/clone.js.map +1 -0
  92. package/dist/ejson/custom-models.d.ts +38 -0
  93. package/dist/ejson/custom-models.js +76 -0
  94. package/dist/ejson/custom-models.js.map +1 -0
  95. package/dist/ejson/custom-types.d.ts +1 -0
  96. package/dist/ejson/custom-types.js +2 -0
  97. package/dist/ejson/custom-types.js.map +1 -0
  98. package/dist/ejson/equals.d.ts +1 -0
  99. package/dist/ejson/equals.js +117 -0
  100. package/dist/ejson/equals.js.map +1 -0
  101. package/dist/ejson/from-json-value.d.ts +1 -0
  102. package/dist/ejson/from-json-value.js +13 -0
  103. package/dist/ejson/from-json-value.js.map +1 -0
  104. package/dist/ejson/helpers/adjust-types-to-json-value.d.ts +1 -0
  105. package/dist/ejson/helpers/adjust-types-to-json-value.js +36 -0
  106. package/dist/ejson/helpers/adjust-types-to-json-value.js.map +1 -0
  107. package/dist/ejson/helpers/from-json-value-helper.d.ts +1 -0
  108. package/dist/ejson/helpers/from-json-value-helper.js +24 -0
  109. package/dist/ejson/helpers/from-json-value-helper.js.map +1 -0
  110. package/dist/ejson/helpers/to-json-value-helper.d.ts +1 -0
  111. package/dist/ejson/helpers/to-json-value-helper.js +15 -0
  112. package/dist/ejson/helpers/to-json-value-helper.js.map +1 -0
  113. package/dist/ejson/index.d.ts +27 -0
  114. package/dist/ejson/index.js +54 -0
  115. package/dist/ejson/index.js.map +1 -0
  116. package/dist/ejson/is-binary.d.ts +2 -0
  117. package/dist/ejson/is-binary.js +5 -0
  118. package/dist/ejson/is-binary.js.map +1 -0
  119. package/dist/ejson/parse.d.ts +6 -0
  120. package/dist/ejson/parse.js +12 -0
  121. package/dist/ejson/parse.js.map +1 -0
  122. package/dist/ejson/stable-stringify.d.ts +10 -0
  123. package/dist/ejson/stable-stringify.js +25 -0
  124. package/dist/ejson/stable-stringify.js.map +1 -0
  125. package/dist/ejson/stringify.d.ts +5 -0
  126. package/dist/ejson/stringify.js +15 -0
  127. package/dist/ejson/stringify.js.map +1 -0
  128. package/dist/ejson/to-json-value.d.ts +1 -0
  129. package/dist/ejson/to-json-value.js +17 -0
  130. package/dist/ejson/to-json-value.js.map +1 -0
  131. package/dist/ejson/utils.d.ts +18 -0
  132. package/dist/ejson/utils.js +43 -0
  133. package/dist/ejson/utils.js.map +1 -0
  134. package/dist/mongodb/change-streams.d.ts +31 -0
  135. package/dist/mongodb/change-streams.js +142 -0
  136. package/dist/mongodb/change-streams.js.map +1 -0
  137. package/dist/mongodb/client.d.ts +13 -0
  138. package/dist/mongodb/client.js +30 -0
  139. package/dist/mongodb/client.js.map +1 -0
  140. package/dist/mongodb/decorators/collection.d.ts +9 -0
  141. package/dist/mongodb/decorators/collection.js +26 -0
  142. package/dist/mongodb/decorators/collection.js.map +1 -0
  143. package/dist/mongodb/decorators/index.d.ts +4 -0
  144. package/dist/mongodb/decorators/index.js +5 -0
  145. package/dist/mongodb/decorators/index.js.map +1 -0
  146. package/dist/mongodb/decorators/metadata.d.ts +21 -0
  147. package/dist/mongodb/decorators/metadata.js +29 -0
  148. package/dist/mongodb/decorators/metadata.js.map +1 -0
  149. package/dist/mongodb/decorators/register.d.ts +3 -0
  150. package/dist/mongodb/decorators/register.js +10 -0
  151. package/dist/mongodb/decorators/register.js.map +1 -0
  152. package/dist/mongodb/decorators/watch.d.ts +4 -0
  153. package/dist/mongodb/decorators/watch.js +10 -0
  154. package/dist/mongodb/decorators/watch.js.map +1 -0
  155. package/dist/mongodb/filters.d.ts +20 -0
  156. package/dist/mongodb/filters.js +40 -0
  157. package/dist/mongodb/filters.js.map +1 -0
  158. package/dist/mongodb/find-one-or-create.d.ts +4 -0
  159. package/dist/mongodb/find-one-or-create.js +16 -0
  160. package/dist/mongodb/find-one-or-create.js.map +1 -0
  161. package/dist/mongodb/index.d.ts +10 -0
  162. package/dist/mongodb/index.js +11 -0
  163. package/dist/mongodb/index.js.map +1 -0
  164. package/dist/mongodb/live/client.d.ts +52 -0
  165. package/dist/mongodb/live/client.js +266 -0
  166. package/dist/mongodb/live/client.js.map +1 -0
  167. package/dist/mongodb/live/engine.d.ts +55 -0
  168. package/dist/mongodb/live/engine.js +440 -0
  169. package/dist/mongodb/live/engine.js.map +1 -0
  170. package/dist/mongodb/live/index.d.ts +5 -0
  171. package/dist/mongodb/live/index.js +6 -0
  172. package/dist/mongodb/live/index.js.map +1 -0
  173. package/dist/mongodb/live/observer.d.ts +58 -0
  174. package/dist/mongodb/live/observer.js +246 -0
  175. package/dist/mongodb/live/observer.js.map +1 -0
  176. package/dist/mongodb/live/publication.d.ts +4 -0
  177. package/dist/mongodb/live/publication.js +30 -0
  178. package/dist/mongodb/live/publication.js.map +1 -0
  179. package/dist/mongodb/live/source.d.ts +55 -0
  180. package/dist/mongodb/live/source.js +197 -0
  181. package/dist/mongodb/live/source.js.map +1 -0
  182. package/dist/mongodb/live/types.d.ts +266 -0
  183. package/dist/mongodb/live/types.js +29 -0
  184. package/dist/mongodb/live/types.js.map +1 -0
  185. package/dist/mongodb/live/window.d.ts +7 -0
  186. package/dist/mongodb/live/window.js +93 -0
  187. package/dist/mongodb/live/window.js.map +1 -0
  188. package/dist/mongodb/registry.d.ts +35 -0
  189. package/dist/mongodb/registry.js +129 -0
  190. package/dist/mongodb/registry.js.map +1 -0
  191. package/dist/mongodb/schema.d.ts +16 -0
  192. package/dist/mongodb/schema.js +43 -0
  193. package/dist/mongodb/schema.js.map +1 -0
  194. package/dist/mongodb/timestamps.d.ts +17 -0
  195. package/dist/mongodb/timestamps.js +27 -0
  196. package/dist/mongodb/timestamps.js.map +1 -0
  197. package/dist/mongodb/types.d.ts +120 -0
  198. package/dist/mongodb/types.js +10 -0
  199. package/dist/mongodb/types.js.map +1 -0
  200. package/dist/react/components/client-provider.d.ts +8 -0
  201. package/dist/react/components/client-provider.js +23 -0
  202. package/dist/react/components/client-provider.js.map +1 -0
  203. package/dist/react/components/index.d.ts +1 -0
  204. package/dist/react/components/index.js +2 -0
  205. package/dist/react/components/index.js.map +1 -0
  206. package/dist/react/hooks/index.d.ts +13 -0
  207. package/dist/react/hooks/index.js +14 -0
  208. package/dist/react/hooks/index.js.map +1 -0
  209. package/dist/react/hooks/use-auth.d.ts +4 -0
  210. package/dist/react/hooks/use-auth.js +35 -0
  211. package/dist/react/hooks/use-auth.js.map +1 -0
  212. package/dist/react/hooks/use-caller.d.ts +5 -0
  213. package/dist/react/hooks/use-caller.js +13 -0
  214. package/dist/react/hooks/use-caller.js.map +1 -0
  215. package/dist/react/hooks/use-channel.d.ts +1 -0
  216. package/dist/react/hooks/use-channel.js +7 -0
  217. package/dist/react/hooks/use-channel.js.map +1 -0
  218. package/dist/react/hooks/use-circuit-breaker.d.ts +6 -0
  219. package/dist/react/hooks/use-circuit-breaker.js +16 -0
  220. package/dist/react/hooks/use-circuit-breaker.js.map +1 -0
  221. package/dist/react/hooks/use-client.d.ts +3 -0
  222. package/dist/react/hooks/use-client.js +13 -0
  223. package/dist/react/hooks/use-client.js.map +1 -0
  224. package/dist/react/hooks/use-connection-state.d.ts +13 -0
  225. package/dist/react/hooks/use-connection-state.js +55 -0
  226. package/dist/react/hooks/use-connection-state.js.map +1 -0
  227. package/dist/react/hooks/use-creation.d.ts +5 -0
  228. package/dist/react/hooks/use-creation.js +17 -0
  229. package/dist/react/hooks/use-creation.js.map +1 -0
  230. package/dist/react/hooks/use-deps-change.d.ts +1 -0
  231. package/dist/react/hooks/use-deps-change.js +11 -0
  232. package/dist/react/hooks/use-deps-change.js.map +1 -0
  233. package/dist/react/hooks/use-local-event.d.ts +13 -0
  234. package/dist/react/hooks/use-local-event.js +32 -0
  235. package/dist/react/hooks/use-local-event.js.map +1 -0
  236. package/dist/react/hooks/use-method-refresh.d.ts +15 -0
  237. package/dist/react/hooks/use-method-refresh.js +48 -0
  238. package/dist/react/hooks/use-method-refresh.js.map +1 -0
  239. package/dist/react/hooks/use-method.d.ts +26 -0
  240. package/dist/react/hooks/use-method.js +161 -0
  241. package/dist/react/hooks/use-method.js.map +1 -0
  242. package/dist/react/hooks/use-mongodb-live-publication.d.ts +13 -0
  243. package/dist/react/hooks/use-mongodb-live-publication.js +26 -0
  244. package/dist/react/hooks/use-mongodb-live-publication.js.map +1 -0
  245. package/dist/react/hooks/use-object.d.ts +2 -0
  246. package/dist/react/hooks/use-object.js +22 -0
  247. package/dist/react/hooks/use-object.js.map +1 -0
  248. package/dist/react/hooks/use-subscribe.d.ts +8 -0
  249. package/dist/react/hooks/use-subscribe.js +49 -0
  250. package/dist/react/hooks/use-subscribe.js.map +1 -0
  251. package/dist/react/hooks/use-throttled-events.d.ts +7 -0
  252. package/dist/react/hooks/use-throttled-events.js +11 -0
  253. package/dist/react/hooks/use-throttled-events.js.map +1 -0
  254. package/dist/react/hooks/use-token-refresh.d.ts +13 -0
  255. package/dist/react/hooks/use-token-refresh.js +40 -0
  256. package/dist/react/hooks/use-token-refresh.js.map +1 -0
  257. package/dist/react/index.d.ts +2 -0
  258. package/dist/react/index.js +3 -0
  259. package/dist/react/index.js.map +1 -0
  260. package/dist/server/client-node.d.ts +76 -0
  261. package/dist/server/client-node.js +159 -0
  262. package/dist/server/client-node.js.map +1 -0
  263. package/dist/server/create-method-proxy.d.ts +2 -0
  264. package/dist/server/create-method-proxy.js +16 -0
  265. package/dist/server/create-method-proxy.js.map +1 -0
  266. package/dist/server/decorators/cached.d.ts +37 -0
  267. package/dist/server/decorators/cached.js +65 -0
  268. package/dist/server/decorators/cached.js.map +1 -0
  269. package/dist/server/decorators/index.d.ts +14 -0
  270. package/dist/server/decorators/index.js +13 -0
  271. package/dist/server/decorators/index.js.map +1 -0
  272. package/dist/server/decorators/infer.d.ts +78 -0
  273. package/dist/server/decorators/infer.js +11 -0
  274. package/dist/server/decorators/infer.js.map +1 -0
  275. package/dist/server/decorators/metadata.d.ts +60 -0
  276. package/dist/server/decorators/metadata.js +77 -0
  277. package/dist/server/decorators/metadata.js.map +1 -0
  278. package/dist/server/decorators/method.d.ts +14 -0
  279. package/dist/server/decorators/method.js +25 -0
  280. package/dist/server/decorators/method.js.map +1 -0
  281. package/dist/server/decorators/namespace.d.ts +25 -0
  282. package/dist/server/decorators/namespace.js +34 -0
  283. package/dist/server/decorators/namespace.js.map +1 -0
  284. package/dist/server/decorators/protected.d.ts +36 -0
  285. package/dist/server/decorators/protected.js +61 -0
  286. package/dist/server/decorators/protected.js.map +1 -0
  287. package/dist/server/decorators/register.d.ts +25 -0
  288. package/dist/server/decorators/register.js +72 -0
  289. package/dist/server/decorators/register.js.map +1 -0
  290. package/dist/server/decorators/schema.d.ts +17 -0
  291. package/dist/server/decorators/schema.js +27 -0
  292. package/dist/server/decorators/schema.js.map +1 -0
  293. package/dist/server/decorators/use.d.ts +22 -0
  294. package/dist/server/decorators/use.js +32 -0
  295. package/dist/server/decorators/use.js.map +1 -0
  296. package/dist/server/default-methods.d.ts +8 -0
  297. package/dist/server/default-methods.js +8 -0
  298. package/dist/server/default-methods.js.map +1 -0
  299. package/dist/server/event.d.ts +42 -0
  300. package/dist/server/event.js +53 -0
  301. package/dist/server/event.js.map +1 -0
  302. package/dist/server/index.d.ts +10 -0
  303. package/dist/server/index.js +11 -0
  304. package/dist/server/index.js.map +1 -0
  305. package/dist/server/method.d.ts +95 -0
  306. package/dist/server/method.js +113 -0
  307. package/dist/server/method.js.map +1 -0
  308. package/dist/server/methods.d.ts +11 -0
  309. package/dist/server/methods.js +74 -0
  310. package/dist/server/methods.js.map +1 -0
  311. package/dist/server/request-types.d.ts +20 -0
  312. package/dist/server/request-types.js +8 -0
  313. package/dist/server/request-types.js.map +1 -0
  314. package/dist/server/room-registry.d.ts +28 -0
  315. package/dist/server/room-registry.js +83 -0
  316. package/dist/server/room-registry.js.map +1 -0
  317. package/dist/server/server-channel.d.ts +32 -0
  318. package/dist/server/server-channel.js +104 -0
  319. package/dist/server/server-channel.js.map +1 -0
  320. package/dist/server/server.d.ts +124 -0
  321. package/dist/server/server.js +243 -0
  322. package/dist/server/server.js.map +1 -0
  323. package/dist/server/transports/hono-rate-limit.d.ts +15 -0
  324. package/dist/server/transports/hono-rate-limit.js +36 -0
  325. package/dist/server/transports/hono-rate-limit.js.map +1 -0
  326. package/dist/server/transports/index.d.ts +4 -0
  327. package/dist/server/transports/index.js +5 -0
  328. package/dist/server/transports/index.js.map +1 -0
  329. package/dist/server/transports/node-hono-transport-contract.d.ts +16 -0
  330. package/dist/server/transports/node-hono-transport-contract.js +18 -0
  331. package/dist/server/transports/node-hono-transport-contract.js.map +1 -0
  332. package/dist/server/transports/node-hono-transport.d.ts +47 -0
  333. package/dist/server/transports/node-hono-transport.js +327 -0
  334. package/dist/server/transports/node-hono-transport.js.map +1 -0
  335. package/dist/server/transports/redis-transport.d.ts +34 -0
  336. package/dist/server/transports/redis-transport.js +84 -0
  337. package/dist/server/transports/redis-transport.js.map +1 -0
  338. package/dist/server/transports/websocket-transport.d.ts +42 -0
  339. package/dist/server/transports/websocket-transport.js +174 -0
  340. package/dist/server/transports/websocket-transport.js.map +1 -0
  341. package/dist/server/transports/ws-shared.d.ts +37 -0
  342. package/dist/server/transports/ws-shared.js +188 -0
  343. package/dist/server/transports/ws-shared.js.map +1 -0
  344. package/dist/server/typeferry-async-local-storage.d.ts +5 -0
  345. package/dist/server/typeferry-async-local-storage.js +6 -0
  346. package/dist/server/typeferry-async-local-storage.js.map +1 -0
  347. package/dist/server/types.d.ts +27 -0
  348. package/dist/server/types.js +11 -0
  349. package/dist/server/types.js.map +1 -0
  350. package/dist/utils/constants.d.ts +72 -0
  351. package/dist/utils/constants.js +79 -0
  352. package/dist/utils/constants.js.map +1 -0
  353. package/dist/utils/environment.d.ts +8 -0
  354. package/dist/utils/environment.js +17 -0
  355. package/dist/utils/environment.js.map +1 -0
  356. package/dist/utils/errors.d.ts +26 -0
  357. package/dist/utils/errors.js +35 -0
  358. package/dist/utils/errors.js.map +1 -0
  359. package/dist/utils/event-emitter.d.ts +37 -0
  360. package/dist/utils/event-emitter.js +104 -0
  361. package/dist/utils/event-emitter.js.map +1 -0
  362. package/dist/utils/events.d.ts +7 -0
  363. package/dist/utils/events.js +23 -0
  364. package/dist/utils/events.js.map +1 -0
  365. package/dist/utils/helpers.d.ts +14 -0
  366. package/dist/utils/helpers.js +40 -0
  367. package/dist/utils/helpers.js.map +1 -0
  368. package/dist/utils/index.d.ts +11 -0
  369. package/dist/utils/index.js +12 -0
  370. package/dist/utils/index.js.map +1 -0
  371. package/dist/utils/intercept.d.ts +7 -0
  372. package/dist/utils/intercept.js +21 -0
  373. package/dist/utils/intercept.js.map +1 -0
  374. package/dist/utils/iterator.d.ts +9 -0
  375. package/dist/utils/iterator.js +28 -0
  376. package/dist/utils/iterator.js.map +1 -0
  377. package/dist/utils/lodash.d.ts +33 -0
  378. package/dist/utils/lodash.js +123 -0
  379. package/dist/utils/lodash.js.map +1 -0
  380. package/dist/utils/presentation.d.ts +19 -0
  381. package/dist/utils/presentation.js +25 -0
  382. package/dist/utils/presentation.js.map +1 -0
  383. package/dist/utils/promise.d.ts +6 -0
  384. package/dist/utils/promise.js +17 -0
  385. package/dist/utils/promise.js.map +1 -0
  386. package/dist/utils/protocol.d.ts +110 -0
  387. package/dist/utils/protocol.js +59 -0
  388. package/dist/utils/protocol.js.map +1 -0
  389. package/dist/utils/types.d.ts +23 -0
  390. package/dist/utils/types.js +2 -0
  391. package/dist/utils/types.js.map +1 -0
  392. package/package.json +187 -0
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Device information extracted from HTTP request headers.
3
+ * Used for session tracking and security monitoring.
4
+ */
5
+ export interface DeviceInfo {
6
+ /** Client IP address (from x-forwarded-for or socket) */
7
+ ip?: string;
8
+ /** Raw user agent string */
9
+ userAgent?: string;
10
+ /** Parsed operating system name and version */
11
+ os?: string;
12
+ /** Parsed browser name and version */
13
+ browser?: string;
14
+ /** Device category */
15
+ deviceType?: 'mobile' | 'desktop' | 'tablet' | 'unknown';
16
+ }
17
+ /**
18
+ * Represents a user session with refresh token rotation support.
19
+ * Sessions belong to a token family for theft detection.
20
+ */
21
+ export interface Session {
22
+ /** Unique session identifier */
23
+ id: string;
24
+ /** User who owns this session */
25
+ userId: string;
26
+ /** Token family for rotation tracking and theft detection */
27
+ familyId: string;
28
+ /** Current refresh token value */
29
+ token: string;
30
+ /** Unix timestamp (seconds) when session expires */
31
+ expiration: number;
32
+ /** Device that created this session */
33
+ deviceInfo?: DeviceInfo;
34
+ /** Whether this session has been revoked */
35
+ isRevoked?: boolean;
36
+ /** Token that replaced this one after rotation */
37
+ replacedBy?: string;
38
+ /** Unix timestamp (ms) when token was last used/rotated (for grace period) */
39
+ usedAt?: number;
40
+ }
41
+ /**
42
+ * JWT access token payload structure.
43
+ * @template TClaims - Additional custom claims to include
44
+ */
45
+ export interface AccessTokenPayload<TClaims = Record<string, never>> {
46
+ /** User identifier */
47
+ userId: string;
48
+ /** Session identifier for token binding */
49
+ sessionId: string;
50
+ /** Issued-at time (Unix timestamp in seconds, server clock) */
51
+ iat: number;
52
+ /** Expiration time (Unix timestamp in seconds, server clock) */
53
+ exp: number;
54
+ /** Optional custom claims */
55
+ claims?: TClaims;
56
+ }
57
+ /**
58
+ * Token pair returned after authentication or refresh.
59
+ */
60
+ export interface TokenPair {
61
+ /** Short-lived JWT access token */
62
+ accessToken: string;
63
+ /** Long-lived opaque refresh token */
64
+ refreshToken: string;
65
+ /** Access token expiration (Unix timestamp in seconds) */
66
+ exp: number;
67
+ }
68
+ /**
69
+ * Interface for session storage and management.
70
+ * Implement this for different storage backends (MongoDB, Redis, etc.)
71
+ */
72
+ export interface SessionManager {
73
+ /**
74
+ * Create a new session for a user.
75
+ * @param userId - User identifier
76
+ * @param deviceInfo - Optional device information
77
+ * @returns Token pair for the new session
78
+ */
79
+ createSession(userId: string, deviceInfo?: DeviceInfo): Promise<TokenPair>;
80
+ /**
81
+ * Refresh an existing session, rotating the refresh token.
82
+ * @param refreshToken - Current refresh token
83
+ * @param deviceInfo - Optional updated device information
84
+ * @returns New token pair, or null if refresh token is invalid/expired
85
+ */
86
+ refreshSession(refreshToken: string, deviceInfo?: DeviceInfo): Promise<TokenPair | null>;
87
+ /**
88
+ * Revoke a specific session by ID.
89
+ * @param sessionId - Session to revoke
90
+ * @returns Whether the session was found and revoked
91
+ */
92
+ revokeSession(sessionId: string): Promise<boolean>;
93
+ /**
94
+ * Revoke all sessions in a token family (for theft detection).
95
+ * @param familyId - Token family to revoke
96
+ * @returns Number of sessions revoked
97
+ */
98
+ revokeFamily(familyId: string): Promise<number>;
99
+ /**
100
+ * Get all active sessions for a user.
101
+ * @param userId - User identifier
102
+ * @returns Array of active sessions
103
+ */
104
+ getUserSessions(userId: string): Promise<Session[]>;
105
+ /**
106
+ * Revoke all sessions for a user, optionally keeping one family.
107
+ * @param userId - User identifier
108
+ * @param exceptFamilyId - Optional family to preserve (current session)
109
+ * @returns Number of sessions revoked
110
+ */
111
+ revokeAllUserSessions(userId: string, exceptFamilyId?: string): Promise<number>;
112
+ }
113
+ /**
114
+ * Authentication provider interface.
115
+ * Implement this to support different authentication methods.
116
+ * @template TUser - User type returned in auth context
117
+ */
118
+ export interface AuthProvider<TUser = unknown> {
119
+ /**
120
+ * Authenticate a token and return the auth context.
121
+ * @param token - Token to authenticate
122
+ * @returns Auth context if valid, null otherwise
123
+ */
124
+ authenticate(token: string): Promise<AuthContext<TUser> | null>;
125
+ }
126
+ /**
127
+ * Authentication context stored in cache and attached to client.
128
+ * @template TUser - User type
129
+ */
130
+ export interface AuthContext<TUser = unknown> {
131
+ /** Full user object */
132
+ user: TUser;
133
+ /** User identifier (string representation) */
134
+ userId: string;
135
+ /** Session identifier (if using session-based auth) */
136
+ sessionId?: string;
137
+ }
138
+ /**
139
+ * Configuration for authentication module.
140
+ */
141
+ export interface AuthConfig {
142
+ /** JWT signing secret */
143
+ secret: string;
144
+ /** JWT algorithm (default: 'HS256') */
145
+ algorithm?: 'HS256' | 'HS384' | 'HS512';
146
+ /** Access token expiry in minutes (default: 15) */
147
+ accessTokenExpiryMinutes?: number;
148
+ /** Refresh token expiry in days (default: 14) */
149
+ refreshTokenExpiryDays?: number;
150
+ /** Grace period for concurrent refresh requests in seconds (default: 15) */
151
+ rotationGracePeriodSeconds?: number;
152
+ /** Rate limiting for login endpoint */
153
+ loginRateLimit?: {
154
+ windowMs: number;
155
+ maxAttempts: number;
156
+ };
157
+ /** Rate limiting for refresh endpoint */
158
+ refreshRateLimit?: {
159
+ windowMs: number;
160
+ maxAttempts: number;
161
+ };
162
+ }
163
+ /**
164
+ * Cookie configuration options.
165
+ */
166
+ export interface CookieOptions {
167
+ /** Cookie name */
168
+ name: string;
169
+ /** Cookie max age in days */
170
+ maxAgeDays: number;
171
+ /** Whether to set Secure flag (default: true in production) */
172
+ secure?: boolean;
173
+ /** SameSite attribute (default: 'Strict') */
174
+ sameSite?: 'Strict' | 'Lax' | 'None';
175
+ /** Cookie path (default: '/') */
176
+ path?: string;
177
+ }
178
+ /**
179
+ * Configuration for client-side token refresh.
180
+ */
181
+ export interface TokenRefreshConfig {
182
+ /** Server method to call for refresh (default: 'auth.refresh') */
183
+ refreshMethod: string;
184
+ /** Seconds before expiry to trigger refresh (default: 60) */
185
+ refreshBeforeExpirySec: number;
186
+ /** BroadcastChannel name for cross-tab sync */
187
+ broadcastChannelName?: string;
188
+ }
189
+ /**
190
+ * Configuration for cross-tab token synchronization.
191
+ */
192
+ export interface CrossTabSyncConfig {
193
+ /** BroadcastChannel name */
194
+ channelName: string;
195
+ /** Event to emit when token is received from another tab */
196
+ tokenRefreshedEvent?: string;
197
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import type { Client, ProxyMethodCall } from './client.js';
2
+ export declare function callMethodProxy(client: Client, path?: string): ProxyMethodCall;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Properties that must return primitive-producing functions to prevent
3
+ * "Cannot convert object to primitive value" when the proxy is coerced
4
+ * (e.g. string concatenation, JSON.stringify, devtools inspection).
5
+ */
6
+ const COERCION_PROPS = new Set(['toString', 'valueOf', 'toJSON']);
7
+ export function callMethodProxy(client, path = '') {
8
+ return new Proxy(function () { }, {
9
+ get(_, prop) {
10
+ if (typeof prop === 'symbol')
11
+ return undefined;
12
+ if (COERCION_PROPS.has(prop))
13
+ return () => path;
14
+ const newPath = path ? `${path}.${prop}` : prop;
15
+ return callMethodProxy(client, newPath);
16
+ },
17
+ apply(_, __, args) {
18
+ return client.call(path, ...args);
19
+ },
20
+ });
21
+ }
22
+ //# sourceMappingURL=call-method-proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call-method-proxy.js","sourceRoot":"","sources":["../../src/client/call-method-proxy.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAA;AAEjE,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,IAAI,GAAG,EAAE;IACvD,OAAO,IAAI,KAAK,CAAC,cAAa,CAAoB,EAAE;QAClD,GAAG,CAAC,CAAC,EAAE,IAAI;YACT,IAAI,OAAO,IAAI,KAAK,QAAQ;gBAAE,OAAO,SAAS,CAAA;YAC9C,IAAI,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,OAAO,GAAG,EAAE,CAAC,IAAI,CAAA;YAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;YAC/C,OAAO,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACzC,CAAC;QACD,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI;YACf,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAA;QACnC,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,43 @@
1
+ import EventEmitter2 from '../utils/event-emitter.js';
2
+ import type { AnyFunction } from '../utils/index.js';
3
+ import type { Client } from './client.js';
4
+ export declare class ClientChannel extends EventEmitter2 {
5
+ client: Client;
6
+ name: string;
7
+ events: Set<string>;
8
+ _events?: Record<string, AnyFunction | AnyFunction[]>;
9
+ constructor(name: string);
10
+ setClient(client: Client): void;
11
+ private pendingSubscriptions;
12
+ private subscribeDebounceTimeout?;
13
+ /**
14
+ * Commits batched subscription requests via RPC.
15
+ * Emits `{}` (not null) on failure so downstream `result[event]`
16
+ * lookups don't crash with "Cannot read properties of null".
17
+ */
18
+ commitPendingSubscriptions(): Promise<void>;
19
+ subscribe(event: string | string[]): Promise<any>;
20
+ private pendingUnsubscriptions;
21
+ private unsubscribeDebounceTimeout?;
22
+ commitPendingUnsubscriptions(): Promise<void>;
23
+ unsubscribe(event: string | string[]): Promise<any>;
24
+ resubscribe(): Promise<any>;
25
+ /**
26
+ * Wait for an event to fire asynchronously.
27
+ *
28
+ * Returns true if no params are sent.
29
+ */
30
+ wait(event: string, callback?: (...data: any) => any): Promise<any | any[]>;
31
+ /**
32
+ * Returns true if the event was not fired within a given timeout.
33
+ */
34
+ timeout(event: string, timeoutMs?: number): Promise<unknown>;
35
+ iterator(event: string): {
36
+ [Symbol.asyncIterator](): any;
37
+ next(): Promise<unknown>;
38
+ return(): {
39
+ done: boolean;
40
+ };
41
+ throw(error: unknown): Promise<never>;
42
+ };
43
+ }
@@ -0,0 +1,148 @@
1
+ import { isEmpty } from '../utils/lodash.js';
2
+ import EventEmitter2 from '../utils/event-emitter.js';
3
+ import { TypeFerryEvents, createIterator, Methods } from '../utils/index.js';
4
+ import { LogLevel } from './logger.js';
5
+ export class ClientChannel extends EventEmitter2 {
6
+ client;
7
+ name;
8
+ events = new Set();
9
+ constructor(name) {
10
+ super({
11
+ maxListeners: 512,
12
+ });
13
+ if (typeof name !== 'string' || !name)
14
+ throw new Error('the channel name needs to be a string');
15
+ this.name = name;
16
+ }
17
+ setClient(client) {
18
+ this.client = client;
19
+ }
20
+ pendingSubscriptions = new Set();
21
+ subscribeDebounceTimeout;
22
+ /**
23
+ * Commits batched subscription requests via RPC.
24
+ * Emits `{}` (not null) on failure so downstream `result[event]`
25
+ * lookups don't crash with "Cannot read properties of null".
26
+ */
27
+ async commitPendingSubscriptions() {
28
+ const channel = this.name;
29
+ const allEvents = Array.from(this.pendingSubscriptions);
30
+ this.pendingSubscriptions.clear();
31
+ if (!isEmpty(allEvents)) {
32
+ let result = {};
33
+ try {
34
+ result =
35
+ (await this.client.call(Methods.RPC_ON, {
36
+ events: allEvents,
37
+ channel,
38
+ })) ?? {};
39
+ }
40
+ catch {
41
+ result = {};
42
+ }
43
+ this.emit(TypeFerryEvents.COMMIT_PENDING_SUBSCRIPTIONS, result);
44
+ }
45
+ }
46
+ async subscribe(event) {
47
+ const events = Array.isArray(event) ? event : [event];
48
+ if (isEmpty(events))
49
+ return {};
50
+ for (const event of events) {
51
+ this.events.add(event);
52
+ this.pendingSubscriptions.add(event);
53
+ }
54
+ if (this.subscribeDebounceTimeout) {
55
+ clearTimeout(this.subscribeDebounceTimeout);
56
+ }
57
+ this.subscribeDebounceTimeout = setTimeout(this.commitPendingSubscriptions.bind(this), 100);
58
+ try {
59
+ // Wait longer (15s) during reconnection when network may be slow
60
+ const [result] = await this.waitFor(TypeFerryEvents.COMMIT_PENDING_SUBSCRIPTIONS, 15000);
61
+ return result;
62
+ }
63
+ catch (error) {
64
+ this.client.logger.subscription(LogLevel.ERROR, 'Failed to commit subscriptions', { channel: this.name, events: Array.from(this.events) }, error);
65
+ return {};
66
+ }
67
+ }
68
+ pendingUnsubscriptions = new Set();
69
+ unsubscribeDebounceTimeout;
70
+ async commitPendingUnsubscriptions() {
71
+ const channel = this.name;
72
+ const allEvents = Array.from(this.pendingUnsubscriptions);
73
+ this.pendingUnsubscriptions.clear();
74
+ if (!isEmpty(allEvents)) {
75
+ let result = null;
76
+ try {
77
+ result = await this.client.call(Methods.RPC_OFF, {
78
+ events: allEvents,
79
+ channel,
80
+ });
81
+ }
82
+ catch {
83
+ result = {};
84
+ }
85
+ this.emit(TypeFerryEvents.COMMIT_PENDING_UNSUBSCRIPTIONS, result);
86
+ }
87
+ }
88
+ async unsubscribe(event) {
89
+ const events = Array.isArray(event) ? event : [event];
90
+ if (isEmpty(events))
91
+ return {};
92
+ for (const event of events) {
93
+ this.events.delete(event);
94
+ this.pendingUnsubscriptions.add(event);
95
+ }
96
+ if (this.unsubscribeDebounceTimeout) {
97
+ clearTimeout(this.unsubscribeDebounceTimeout);
98
+ }
99
+ this.unsubscribeDebounceTimeout = setTimeout(this.commitPendingUnsubscriptions.bind(this), 100);
100
+ try {
101
+ // Wait longer (15s) during reconnection when network may be slow
102
+ const [result] = await this.waitFor(TypeFerryEvents.COMMIT_PENDING_UNSUBSCRIPTIONS, 15000);
103
+ return result;
104
+ }
105
+ catch (error) {
106
+ this.client.logger.subscription(LogLevel.ERROR, 'Failed to commit unsubscriptions', { channel: this.name, events: Array.from(this.events) }, error);
107
+ return {};
108
+ }
109
+ }
110
+ async resubscribe() {
111
+ return this.subscribe(Array.from(this.events));
112
+ }
113
+ /**
114
+ * Wait for an event to fire asynchronously.
115
+ *
116
+ * Returns true if no params are sent.
117
+ */
118
+ wait(event, callback) {
119
+ return new Promise(resolve => {
120
+ this.once(event, function (data = true) {
121
+ if (callback) {
122
+ resolve(callback(data));
123
+ }
124
+ else {
125
+ resolve(data);
126
+ }
127
+ });
128
+ });
129
+ }
130
+ /**
131
+ * Returns true if the event was not fired within a given timeout.
132
+ */
133
+ timeout(event, timeoutMs = 1000) {
134
+ return new Promise(resolve => {
135
+ const timeout = setTimeout(() => resolve(true), timeoutMs);
136
+ this.wait(event).then(res => {
137
+ if (timeout) {
138
+ clearTimeout(timeout);
139
+ }
140
+ resolve(false);
141
+ });
142
+ });
143
+ }
144
+ iterator(event) {
145
+ return createIterator(this, event);
146
+ }
147
+ }
148
+ //# sourceMappingURL=client-channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-channel.js","sourceRoot":"","sources":["../../src/client/client-channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,aAAa,MAAM,wBAAwB,CAAA;AAGlD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAEnE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,MAAM,OAAO,aAAc,SAAQ,aAAa;IAC9C,MAAM,CAAQ;IACd,IAAI,CAAQ;IACZ,MAAM,GAAgB,IAAI,GAAG,EAAE,CAAA;IAK/B,YAAY,IAAY;QACtB,KAAK,CAAC;YACJ,YAAY,EAAE,GAAG;SAClB,CAAC,CAAA;QAEF,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI;YACnC,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAA;QAE1D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,SAAS,CAAC,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IACO,oBAAoB,GAAgB,IAAI,GAAG,EAAE,CAAA;IAC7C,wBAAwB,CAAiB;IAEjD;;;;OAIG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;;OAIG;IACH,IAAI,CAAC,KAAa,EAAE,QAAgC;QAClD,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;YAC3B,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,IAAI,GAAG,IAAI;gBACpC,IAAI,QAAQ,EAAE,CAAC;oBACb,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;gBACzB,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,IAAI,CAAC,CAAA;gBACf,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,KAAa,EAAE,SAAS,GAAG,IAAI;QACrC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;YAC3B,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,CAAA;YAE1D,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;gBAC1B,IAAI,OAAO,EAAE,CAAC;oBACZ,YAAY,CAAC,OAAO,CAAC,CAAA;gBACvB,CAAC;gBACD,OAAO,CAAC,KAAK,CAAC,CAAA;YAChB,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,QAAQ,CAAC,KAAa;QACpB,OAAO,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IACpC,CAAC;CACF"}
@@ -0,0 +1,27 @@
1
+ import type { Client } from './client.js';
2
+ type Resolve<T = unknown> = (value: T) => void;
3
+ type Reject = (reason?: unknown) => void;
4
+ /**
5
+ * Preserves an unsuccessful HTTP response status across the RPC boundary.
6
+ */
7
+ export declare class ClientHttpResponseError extends Error {
8
+ readonly status: number;
9
+ /**
10
+ * Creates a transport error without discarding the response status.
11
+ */
12
+ constructor(status: number, statusText: string, responseBody: string);
13
+ }
14
+ /**
15
+ * Owns cookie-bearing HTTP RPC requests for one TypeFerry client.
16
+ */
17
+ export declare class ClientHttp {
18
+ client: Client;
19
+ protocol: string;
20
+ host: string;
21
+ uri: string;
22
+ constructor(client: Client);
23
+ /** Strip sensitive keys (refresh tokens) from context before sending over the wire. */
24
+ private stripSensitiveKeys;
25
+ request(payload: Record<string, any>, resolve: Resolve, reject: Reject): Promise<void>;
26
+ }
27
+ export {};
@@ -0,0 +1,106 @@
1
+ import { EJSON } from '../ejson/index.js';
2
+ import { CLIENT_ID_HEADER_KEY, ClientEvents, PayloadType, Presentation, TOKEN_HEADER_KEY, } from '../utils/index.js';
3
+ import { LogLevel } from './logger.js';
4
+ /**
5
+ * Preserves an unsuccessful HTTP response status across the RPC boundary.
6
+ */
7
+ export class ClientHttpResponseError extends Error {
8
+ status;
9
+ /**
10
+ * Creates a transport error without discarding the response status.
11
+ */
12
+ constructor(status, statusText, responseBody) {
13
+ super(`${status} ${statusText}: ${JSON.stringify(responseBody)}`);
14
+ this.name = 'ClientHttpResponseError';
15
+ this.status = status;
16
+ }
17
+ }
18
+ /**
19
+ * Owns cookie-bearing HTTP RPC requests for one TypeFerry client.
20
+ */
21
+ export class ClientHttp {
22
+ client;
23
+ protocol;
24
+ host;
25
+ uri;
26
+ constructor(client) {
27
+ this.client = client;
28
+ this.protocol = this.client.options.secure ? `https://` : `http://`;
29
+ /**
30
+ * HTTP port for cookie-bearing requests (login, refresh).
31
+ *
32
+ * When `httpPort` is explicitly present in options (even if undefined),
33
+ * use the page's own origin so cookies stay same-origin. In dev this
34
+ * routes through Vite's proxy which forwards to the TypeFerry server.
35
+ */
36
+ const hasHttpPort = 'httpPort' in this.client.options;
37
+ if (hasHttpPort && !this.client.options.httpPort) {
38
+ // Use page origin (same-origin cookies via Vite proxy in dev)
39
+ this.host =
40
+ typeof window !== 'undefined'
41
+ ? window.location.origin
42
+ : `${this.protocol}${this.client.options.host}`;
43
+ }
44
+ else {
45
+ const port = this.client.options.httpPort ?? this.client.options.port;
46
+ this.host = port
47
+ ? `${this.protocol}${this.client.options.host}:${port}`
48
+ : `${this.protocol}${this.client.options.host}`;
49
+ }
50
+ this.uri = `${this.host}/__h`;
51
+ }
52
+ /** Strip sensitive keys (refresh tokens) from context before sending over the wire. */
53
+ stripSensitiveKeys(context) {
54
+ const { refreshToken: _, ...safe } = context;
55
+ return safe;
56
+ }
57
+ async request(payload, resolve, reject) {
58
+ try {
59
+ // @ts-ignore
60
+ const data = await fetch(this.uri, {
61
+ method: 'POST',
62
+ headers: {
63
+ [CLIENT_ID_HEADER_KEY]: this.client.uuid,
64
+ Accept: 'text/plain, */*',
65
+ 'Content-Type': 'text/plain',
66
+ ...(this.client.context.token
67
+ ? { [TOKEN_HEADER_KEY]: this.client.context.token }
68
+ : {}),
69
+ },
70
+ credentials: 'include',
71
+ body: EJSON.stringify({
72
+ context: this.stripSensitiveKeys(this.client.context),
73
+ payload,
74
+ }),
75
+ });
76
+ if (data.status !== 200) {
77
+ const errorText = await data.text();
78
+ const error = new ClientHttpResponseError(data.status, data.statusText, errorText);
79
+ this.client.logger.method(LogLevel.ERROR, 'HTTP request failed', {
80
+ status: data.status,
81
+ statusText: data.statusText,
82
+ method: payload.method,
83
+ uri: this.uri,
84
+ }, error);
85
+ return reject(error);
86
+ }
87
+ if (!resolve) {
88
+ return;
89
+ }
90
+ const response = await data.text();
91
+ const decoded = Presentation.decode(response);
92
+ this.client.emit(ClientEvents.INBOUND_MESSAGE, decoded);
93
+ if (decoded.type === PayloadType.ERROR)
94
+ return reject(decoded);
95
+ resolve(decoded.result);
96
+ }
97
+ catch (error) {
98
+ this.client.logger.method(LogLevel.ERROR, 'HTTP request error', {
99
+ method: payload.method,
100
+ uri: this.uri,
101
+ }, error);
102
+ return reject(error);
103
+ }
104
+ }
105
+ }
106
+ //# sourceMappingURL=client-http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-http.js","sourceRoot":"","sources":["../../src/client/client-http.ts"],"names":[],"mappings":"AAAA,OA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O,CAAC,MAAM;gBACtB,GAAG,EAAE,IAAI,CAAC,GAAG;aACd,EACD,KAAc,CACf,CAAA;YAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;QACtB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,85 @@
1
+ import EventEmitter2 from '../utils/event-emitter.js';
2
+ import type { Client, WebSocketOptions } from './client.js';
3
+ /**
4
+ * Native WebSocket transport for the TypeFerry client.
5
+ *
6
+ * Replaces Socket.IO with the browser's built-in WebSocket API. RPC calls
7
+ * are correlated via UUID — the client generates an `id` per call and the
8
+ * server echoes it back in the response.
9
+ *
10
+ * Reconnection uses exponential backoff (500ms → 10s, 10 attempts, 0.5
11
+ * jitter) matching the previous Socket.IO configuration.
12
+ */
13
+ export declare class ClientSocket extends EventEmitter2 {
14
+ client: Client;
15
+ socket: WebSocket | undefined;
16
+ protocol: string;
17
+ uri: string;
18
+ stopped: boolean;
19
+ connecting: boolean;
20
+ options: WebSocketOptions;
21
+ /** UUID-keyed map of in-flight RPC calls awaiting responses. */
22
+ private pending;
23
+ private reconnectAttempt;
24
+ private reconnectTimer;
25
+ /** Prevents infinite loop between scheduleReconnect and VisibilityManager. */
26
+ private exhaustedReconnect;
27
+ get ready(): boolean;
28
+ constructor(client: Client, options?: WebSocketOptions);
29
+ /**
30
+ * Opens a socket immediately and supersedes any scheduled backoff attempt.
31
+ */
32
+ connect(): void;
33
+ /**
34
+ * Builds the WebSocket URL with auth data as query parameters and opens
35
+ * a new connection. Query params mirror the old `socket.handshake.auth`.
36
+ */
37
+ private createSocket;
38
+ close(): Promise<void>;
39
+ /**
40
+ * Sends a fire-and-forget RPC message (void call).
41
+ * @param data - Object containing `method` and optional `params`
42
+ */
43
+ send(_event: string, data: {
44
+ method: string;
45
+ params?: unknown;
46
+ }): void;
47
+ /**
48
+ * Sends an RPC call and returns a promise that resolves when the server
49
+ * responds with a correlated `{ t: "rpc:res", id }` message.
50
+ *
51
+ * Uses UUID-based request correlation instead of Socket.IO acknowledgments.
52
+ */
53
+ emitWithAck<T>(_event: string, data: {
54
+ method: string;
55
+ params?: unknown;
56
+ }, timeout?: number): Promise<T>;
57
+ private handleMessage;
58
+ /**
59
+ * Resolves or rejects the pending RPC call matching the response `id`.
60
+ */
61
+ private handleRpcResponse;
62
+ /** Handles subscription events from the server. */
63
+ private handleTypedEvent;
64
+ /** Handles authentication result from the server. */
65
+ private handleTypedAuth;
66
+ private handleOpen;
67
+ private handleClose;
68
+ private handleSocketError;
69
+ /**
70
+ * Schedules a reconnection attempt with exponential backoff and jitter.
71
+ * After exhausting all attempts, delegates to VisibilityManager for a
72
+ * full reconnect (token refresh + new socket). Stops after one
73
+ * VisibilityManager cycle to prevent infinite loops when the server
74
+ * is unreachable.
75
+ */
76
+ private scheduleReconnect;
77
+ clearReconnectTimer(): void;
78
+ /** Rejects all in-flight RPC calls on unexpected disconnect. */
79
+ private rejectAllPending;
80
+ /**
81
+ * Clears all in-flight RPC calls without rejecting during intentional close.
82
+ * Prevents unhandled rejections when callers don't `.catch()` abandoned calls.
83
+ */
84
+ private clearAllPending;
85
+ }