doover-js 0.11.0 → 0.12.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 (385) hide show
  1. package/README.md +79 -0
  2. package/dist/apis/_args.js +5 -5
  3. package/dist/apis/agents-api.d.ts +4 -4
  4. package/dist/apis/agents-api.js +2 -2
  5. package/dist/apis/aggregates-api.d.ts +4 -4
  6. package/dist/apis/aggregates-api.js +5 -5
  7. package/dist/apis/alarms-api.d.ts +2 -2
  8. package/dist/apis/alarms-api.js +3 -3
  9. package/dist/apis/channels-api.d.ts +3 -3
  10. package/dist/apis/channels-api.js +6 -6
  11. package/dist/apis/connections-api.d.ts +2 -2
  12. package/dist/apis/connections-api.js +6 -6
  13. package/dist/apis/messages-api.d.ts +4 -4
  14. package/dist/apis/messages-api.js +11 -11
  15. package/dist/apis/notifications-api.d.ts +2 -2
  16. package/dist/apis/notifications-api.js +4 -4
  17. package/dist/apis/organisations-api.d.ts +2 -2
  18. package/dist/apis/permissions-api.d.ts +2 -2
  19. package/dist/apis/permissions-api.js +3 -3
  20. package/dist/apis/processors-api.d.ts +2 -2
  21. package/dist/apis/turn-api.d.ts +2 -2
  22. package/dist/apis/users-api.d.ts +2 -2
  23. package/dist/auth/auth-store.d.ts +1 -1
  24. package/dist/auth/build-auth.d.ts +3 -3
  25. package/dist/auth/build-auth.js +8 -8
  26. package/dist/auth/cookie-auth.d.ts +1 -1
  27. package/dist/auth/cookie-auth.js +2 -2
  28. package/dist/auth/doover-auth.d.ts +2 -2
  29. package/dist/auth/doover-token-auth.d.ts +3 -3
  30. package/dist/auth/doover-token-auth.js +13 -13
  31. package/dist/auth/index.d.ts +10 -0
  32. package/dist/auth/index.js +15 -0
  33. package/dist/client/data-client.d.ts +14 -14
  34. package/dist/client/doover-client.d.ts +7 -7
  35. package/dist/client/doover-client.js +42 -42
  36. package/dist/client/errors.d.ts +2 -2
  37. package/dist/client/errors.js +4 -4
  38. package/dist/client/index.d.ts +4 -0
  39. package/dist/client/index.js +9 -0
  40. package/dist/client/local-agent-client.d.ts +3 -3
  41. package/dist/client/local-agent-client.js +19 -19
  42. package/dist/client/multiplex-client.d.ts +5 -5
  43. package/dist/client/multiplex-client.js +25 -25
  44. package/dist/client/multiplex-gateway.d.ts +3 -3
  45. package/dist/client/multiplex-merge.d.ts +1 -1
  46. package/dist/client/offline-cache.d.ts +2 -2
  47. package/dist/client/offline-cache.js +16 -16
  48. package/dist/client/provenance.d.ts +1 -1
  49. package/dist/client/request-options.d.ts +1 -1
  50. package/dist/client/singleton.d.ts +2 -2
  51. package/dist/client/singleton.js +2 -2
  52. package/dist/client/status-tracker.d.ts +1 -1
  53. package/dist/esm/apis/_args.d.ts +16 -0
  54. package/dist/esm/apis/_args.js +27 -0
  55. package/dist/esm/apis/agents-api.d.ts +196 -0
  56. package/dist/esm/apis/agents-api.js +327 -0
  57. package/dist/esm/apis/aggregates-api.d.ts +67 -0
  58. package/dist/esm/apis/aggregates-api.js +64 -0
  59. package/dist/esm/apis/alarms-api.d.ts +48 -0
  60. package/dist/esm/apis/alarms-api.js +75 -0
  61. package/dist/esm/apis/channels-api.d.ts +83 -0
  62. package/dist/esm/apis/channels-api.js +65 -0
  63. package/dist/esm/apis/connections-api.d.ts +45 -0
  64. package/dist/esm/apis/connections-api.js +44 -0
  65. package/dist/esm/apis/messages-api.d.ts +128 -0
  66. package/dist/esm/apis/messages-api.js +179 -0
  67. package/dist/esm/apis/notifications-api.d.ts +94 -0
  68. package/dist/esm/apis/notifications-api.js +153 -0
  69. package/dist/esm/apis/organisations-api.d.ts +26 -0
  70. package/dist/esm/apis/organisations-api.js +41 -0
  71. package/dist/esm/apis/permissions-api.d.ts +17 -0
  72. package/dist/esm/apis/permissions-api.js +23 -0
  73. package/dist/esm/apis/processors-api.d.ts +56 -0
  74. package/dist/esm/apis/processors-api.js +97 -0
  75. package/dist/esm/apis/turn-api.d.ts +7 -0
  76. package/dist/esm/apis/turn-api.js +8 -0
  77. package/dist/esm/apis/users-api.d.ts +8 -0
  78. package/dist/esm/apis/users-api.js +9 -0
  79. package/dist/esm/auth/auth-profile.d.ts +45 -0
  80. package/dist/esm/auth/auth-profile.js +68 -0
  81. package/dist/esm/auth/auth-store.d.ts +14 -0
  82. package/dist/esm/auth/build-auth.d.ts +38 -0
  83. package/dist/esm/auth/build-auth.js +92 -0
  84. package/dist/esm/auth/cookie-auth.d.ts +91 -0
  85. package/dist/esm/auth/cookie-auth.js +196 -0
  86. package/dist/esm/auth/doover-auth.d.ts +52 -0
  87. package/dist/esm/auth/doover-auth.js +28 -0
  88. package/dist/esm/auth/doover-token-auth.d.ts +39 -0
  89. package/dist/esm/auth/doover-token-auth.js +217 -0
  90. package/dist/esm/auth/errors.d.ts +3 -0
  91. package/dist/esm/auth/errors.js +6 -0
  92. package/dist/esm/auth/index.d.ts +10 -0
  93. package/dist/esm/auth/index.js +6 -0
  94. package/dist/esm/auth/jwt.d.ts +6 -0
  95. package/dist/esm/auth/jwt.js +26 -0
  96. package/dist/esm/client/capabilities.d.ts +10 -0
  97. package/dist/esm/client/capabilities.js +42 -0
  98. package/dist/esm/client/data-client.d.ts +104 -0
  99. package/dist/esm/client/doover-client.d.ts +46 -0
  100. package/dist/esm/client/doover-client.js +94 -0
  101. package/dist/esm/client/errors.d.ts +32 -0
  102. package/dist/esm/client/errors.js +64 -0
  103. package/dist/esm/client/index.d.ts +4 -0
  104. package/dist/esm/client/index.js +2 -0
  105. package/dist/esm/client/local-agent-client.d.ts +65 -0
  106. package/dist/esm/client/local-agent-client.js +225 -0
  107. package/dist/esm/client/multiplex-client.d.ts +165 -0
  108. package/dist/esm/client/multiplex-client.js +842 -0
  109. package/dist/esm/client/multiplex-gateway.d.ts +49 -0
  110. package/dist/esm/client/multiplex-gateway.js +110 -0
  111. package/dist/esm/client/multiplex-merge.d.ts +12 -0
  112. package/dist/esm/client/multiplex-merge.js +38 -0
  113. package/dist/esm/client/offline-cache.d.ts +162 -0
  114. package/dist/esm/client/offline-cache.js +757 -0
  115. package/dist/esm/client/provenance.d.ts +60 -0
  116. package/dist/esm/client/provenance.js +108 -0
  117. package/dist/esm/client/request-options.d.ts +23 -0
  118. package/dist/esm/client/request-options.js +23 -0
  119. package/dist/esm/client/singleton.d.ts +26 -0
  120. package/dist/esm/client/singleton.js +54 -0
  121. package/dist/esm/client/stats.d.ts +79 -0
  122. package/dist/esm/client/stats.js +155 -0
  123. package/dist/esm/client/status-tracker.d.ts +24 -0
  124. package/dist/esm/client/status-tracker.js +86 -0
  125. package/dist/esm/gateway/gateway-client.d.ts +86 -0
  126. package/dist/esm/gateway/gateway-client.js +463 -0
  127. package/dist/esm/gateway/index.d.ts +3 -0
  128. package/dist/esm/gateway/index.js +1 -0
  129. package/dist/esm/gateway/types.d.ts +142 -0
  130. package/dist/esm/http/errors.d.ts +19 -0
  131. package/dist/esm/http/errors.js +22 -0
  132. package/dist/esm/http/index.d.ts +3 -0
  133. package/dist/esm/http/index.js +2 -0
  134. package/dist/esm/http/rest-client.d.ts +62 -0
  135. package/dist/esm/http/rest-client.js +181 -0
  136. package/dist/esm/index.d.ts +62 -0
  137. package/dist/esm/index.js +37 -0
  138. package/dist/esm/node/config-manager.d.ts +34 -0
  139. package/dist/esm/node/config-manager.js +140 -0
  140. package/dist/esm/node/index.d.ts +1 -0
  141. package/dist/esm/node/index.js +1 -0
  142. package/dist/esm/package.json +1 -0
  143. package/dist/esm/react/context.d.ts +23 -0
  144. package/dist/esm/react/context.js +28 -0
  145. package/dist/esm/react/index.d.ts +38 -0
  146. package/dist/esm/react/index.js +21 -0
  147. package/dist/esm/react/messageRangeStore.d.ts +93 -0
  148. package/dist/esm/react/messageRangeStore.js +140 -0
  149. package/dist/esm/react/sharedQueryClient.d.ts +21 -0
  150. package/dist/esm/react/sharedQueryClient.js +35 -0
  151. package/dist/esm/react/useAgentChannel.d.ts +8 -0
  152. package/dist/esm/react/useAgentChannel.js +9 -0
  153. package/dist/esm/react/useAgentConnections.d.ts +8 -0
  154. package/dist/esm/react/useAgentConnections.js +20 -0
  155. package/dist/esm/react/useAgentTokenState.d.ts +70 -0
  156. package/dist/esm/react/useAgentTokenState.js +127 -0
  157. package/dist/esm/react/useChannelAggregate.d.ts +64 -0
  158. package/dist/esm/react/useChannelAggregate.js +77 -0
  159. package/dist/esm/react/useChannelMessage.d.ts +45 -0
  160. package/dist/esm/react/useChannelMessage.js +79 -0
  161. package/dist/esm/react/useChannelMessages.d.ts +83 -0
  162. package/dist/esm/react/useChannelMessages.js +214 -0
  163. package/dist/esm/react/useChannelSubscription.d.ts +27 -0
  164. package/dist/esm/react/useChannelSubscription.js +30 -0
  165. package/dist/esm/react/useClientStatus.d.ts +10 -0
  166. package/dist/esm/react/useClientStatus.js +19 -0
  167. package/dist/esm/react/useConnectionState.d.ts +26 -0
  168. package/dist/esm/react/useConnectionState.js +45 -0
  169. package/dist/esm/react/useDeviceMap.d.ts +109 -0
  170. package/dist/esm/react/useDeviceMap.js +59 -0
  171. package/dist/esm/react/useInvocationLogs.d.ts +23 -0
  172. package/dist/esm/react/useInvocationLogs.js +37 -0
  173. package/dist/esm/react/useMultiAgentAggregates.d.ts +38 -0
  174. package/dist/esm/react/useMultiAgentAggregates.js +104 -0
  175. package/dist/esm/react/useMultiAgentChannelMessages.d.ts +79 -0
  176. package/dist/esm/react/useMultiAgentChannelMessages.js +169 -0
  177. package/dist/esm/react/useOfflineStatus.d.ts +8 -0
  178. package/dist/esm/react/useOfflineStatus.js +23 -0
  179. package/dist/esm/react/useSendMessage.d.ts +16 -0
  180. package/dist/esm/react/useSendMessage.js +26 -0
  181. package/dist/esm/react/useSendRpc.d.ts +68 -0
  182. package/dist/esm/react/useSendRpc.js +164 -0
  183. package/dist/esm/react/useTurnCredentials.d.ts +12 -0
  184. package/dist/esm/react/useTurnCredentials.js +22 -0
  185. package/dist/esm/react/useUpdateAggregate.d.ts +27 -0
  186. package/dist/esm/react/useUpdateAggregate.js +39 -0
  187. package/dist/esm/react/useUpdateMessage.d.ts +38 -0
  188. package/dist/esm/react/useUpdateMessage.js +36 -0
  189. package/dist/esm/refine/index.d.ts +72 -0
  190. package/dist/esm/refine/index.js +215 -0
  191. package/dist/esm/rpc/errors.d.ts +10 -0
  192. package/dist/esm/rpc/errors.js +19 -0
  193. package/dist/esm/rpc/index.d.ts +3 -0
  194. package/dist/esm/rpc/index.js +2 -0
  195. package/dist/esm/rpc/rpc-dispatcher.d.ts +41 -0
  196. package/dist/esm/rpc/rpc-dispatcher.js +141 -0
  197. package/dist/esm/types/audit.d.ts +53 -0
  198. package/dist/esm/types/audit.js +11 -0
  199. package/dist/esm/types/batch.d.ts +85 -0
  200. package/dist/esm/types/batch.js +42 -0
  201. package/dist/esm/types/common.d.ts +250 -0
  202. package/dist/esm/types/connection.d.ts +72 -0
  203. package/dist/esm/types/connection.js +7 -0
  204. package/dist/esm/types/index.d.ts +9 -0
  205. package/dist/esm/types/openapi.d.ts +195 -0
  206. package/dist/esm/types/provenance.d.ts +45 -0
  207. package/dist/esm/types/viewer.d.ts +122 -0
  208. package/dist/esm/utils/snowflake.d.ts +21 -0
  209. package/dist/esm/utils/snowflake.js +33 -0
  210. package/dist/esm/viewer/doover-data-provider.d.ts +90 -0
  211. package/dist/esm/viewer/doover-data-provider.js +189 -0
  212. package/dist/esm/viewer/path-parsing.d.ts +5 -0
  213. package/dist/esm/viewer/path-parsing.js +35 -0
  214. package/dist/gateway/gateway-client.d.ts +5 -5
  215. package/dist/gateway/gateway-client.js +5 -5
  216. package/dist/gateway/index.d.ts +3 -0
  217. package/dist/gateway/index.js +5 -0
  218. package/dist/gateway/types.d.ts +1 -1
  219. package/dist/http/index.d.ts +3 -0
  220. package/dist/http/index.js +9 -0
  221. package/dist/http/rest-client.d.ts +3 -3
  222. package/dist/http/rest-client.js +2 -2
  223. package/dist/index.d.ts +62 -62
  224. package/dist/index.js +88 -88
  225. package/dist/node/config-manager.d.ts +2 -2
  226. package/dist/node/config-manager.js +5 -5
  227. package/dist/node/index.d.ts +1 -1
  228. package/dist/node/index.js +2 -2
  229. package/dist/react/context.d.ts +1 -1
  230. package/dist/react/index.d.ts +38 -38
  231. package/dist/react/index.js +59 -59
  232. package/dist/react/messageRangeStore.d.ts +1 -1
  233. package/dist/react/useAgentChannel.d.ts +3 -3
  234. package/dist/react/useAgentChannel.js +2 -2
  235. package/dist/react/useAgentConnections.d.ts +1 -1
  236. package/dist/react/useAgentConnections.js +2 -2
  237. package/dist/react/useAgentTokenState.d.ts +3 -3
  238. package/dist/react/useAgentTokenState.js +8 -8
  239. package/dist/react/useChannelAggregate.d.ts +3 -3
  240. package/dist/react/useChannelAggregate.js +8 -8
  241. package/dist/react/useChannelMessage.d.ts +2 -2
  242. package/dist/react/useChannelMessage.js +4 -4
  243. package/dist/react/useChannelMessages.d.ts +3 -3
  244. package/dist/react/useChannelMessages.js +10 -10
  245. package/dist/react/useChannelSubscription.d.ts +2 -2
  246. package/dist/react/useChannelSubscription.js +2 -2
  247. package/dist/react/useClientStatus.d.ts +1 -1
  248. package/dist/react/useClientStatus.js +2 -2
  249. package/dist/react/useConnectionState.js +2 -2
  250. package/dist/react/useDeviceMap.js +2 -2
  251. package/dist/react/useInvocationLogs.d.ts +1 -1
  252. package/dist/react/useInvocationLogs.js +2 -2
  253. package/dist/react/useMultiAgentAggregates.d.ts +1 -1
  254. package/dist/react/useMultiAgentAggregates.js +5 -5
  255. package/dist/react/useMultiAgentChannelMessages.d.ts +1 -1
  256. package/dist/react/useMultiAgentChannelMessages.js +2 -2
  257. package/dist/react/useOfflineStatus.d.ts +2 -2
  258. package/dist/react/useOfflineStatus.js +2 -2
  259. package/dist/react/useSendMessage.d.ts +2 -2
  260. package/dist/react/useSendMessage.js +2 -2
  261. package/dist/react/useSendRpc.d.ts +2 -2
  262. package/dist/react/useSendRpc.js +2 -2
  263. package/dist/react/useTurnCredentials.d.ts +2 -2
  264. package/dist/react/useTurnCredentials.js +2 -2
  265. package/dist/react/useUpdateAggregate.d.ts +3 -3
  266. package/dist/react/useUpdateAggregate.js +4 -4
  267. package/dist/react/useUpdateMessage.d.ts +2 -2
  268. package/dist/react/useUpdateMessage.js +2 -2
  269. package/dist/refine/index.d.ts +1 -1
  270. package/dist/rpc/errors.d.ts +1 -1
  271. package/dist/rpc/index.d.ts +3 -0
  272. package/dist/rpc/index.js +7 -0
  273. package/dist/rpc/rpc-dispatcher.d.ts +4 -4
  274. package/dist/rpc/rpc-dispatcher.js +2 -2
  275. package/dist/types/common.d.ts +1 -1
  276. package/dist/types/index.d.ts +9 -0
  277. package/dist/types/index.js +2 -0
  278. package/dist/types/openapi.d.ts +1 -1
  279. package/dist/types/viewer.d.ts +2 -2
  280. package/dist/viewer/doover-data-provider.d.ts +10 -10
  281. package/dist/viewer/doover-data-provider.js +25 -25
  282. package/dist/viewer/path-parsing.d.ts +1 -1
  283. package/package.json +795 -8
  284. package/dist/test/api-args.test.js +0 -48
  285. package/dist/test/api-overloads.test.d.ts +0 -9
  286. package/dist/test/api-overloads.test.js +0 -330
  287. package/dist/test/apis.test.js +0 -408
  288. package/dist/test/auth.test.js +0 -708
  289. package/dist/test/batch-apis.test.js +0 -183
  290. package/dist/test/capabilities.test.js +0 -27
  291. package/dist/test/config-manager.test.js +0 -160
  292. package/dist/test/data-client-errors.test.js +0 -24
  293. package/dist/test/data-client-shape.test.js +0 -28
  294. package/dist/test/doover-client-dataclient.test.d.ts +0 -1
  295. package/dist/test/doover-client-dataclient.test.js +0 -58
  296. package/dist/test/doover-client-provenance.test.d.ts +0 -1
  297. package/dist/test/doover-client-provenance.test.js +0 -32
  298. package/dist/test/doover-client.test.d.ts +0 -1
  299. package/dist/test/doover-client.test.js +0 -42
  300. package/dist/test/doover-data-provider.test.d.ts +0 -1
  301. package/dist/test/doover-data-provider.test.js +0 -657
  302. package/dist/test/exports.test.d.ts +0 -1
  303. package/dist/test/exports.test.js +0 -80
  304. package/dist/test/gateway-client.test.d.ts +0 -1
  305. package/dist/test/gateway-client.test.js +0 -474
  306. package/dist/test/gateway-provenance.test.d.ts +0 -1
  307. package/dist/test/gateway-provenance.test.js +0 -29
  308. package/dist/test/gateway-subscriptions.test.d.ts +0 -1
  309. package/dist/test/gateway-subscriptions.test.js +0 -95
  310. package/dist/test/helpers.d.ts +0 -32
  311. package/dist/test/helpers.js +0 -115
  312. package/dist/test/local-agent-client.test.d.ts +0 -1
  313. package/dist/test/local-agent-client.test.js +0 -202
  314. package/dist/test/message-range-store.test.d.ts +0 -1
  315. package/dist/test/message-range-store.test.js +0 -183
  316. package/dist/test/multiplex-capabilities.test.d.ts +0 -1
  317. package/dist/test/multiplex-capabilities.test.js +0 -37
  318. package/dist/test/multiplex-conflicts.test.d.ts +0 -1
  319. package/dist/test/multiplex-conflicts.test.js +0 -35
  320. package/dist/test/multiplex-gateway.test.d.ts +0 -1
  321. package/dist/test/multiplex-gateway.test.js +0 -103
  322. package/dist/test/multiplex-merge.test.d.ts +0 -1
  323. package/dist/test/multiplex-merge.test.js +0 -19
  324. package/dist/test/multiplex-noncore.test.d.ts +0 -1
  325. package/dist/test/multiplex-noncore.test.js +0 -82
  326. package/dist/test/multiplex-passthrough.test.d.ts +0 -1
  327. package/dist/test/multiplex-passthrough.test.js +0 -35
  328. package/dist/test/multiplex-reads.test.d.ts +0 -1
  329. package/dist/test/multiplex-reads.test.js +0 -87
  330. package/dist/test/multiplex-registry.test.d.ts +0 -1
  331. package/dist/test/multiplex-registry.test.js +0 -81
  332. package/dist/test/multiplex-routing.test.d.ts +0 -1
  333. package/dist/test/multiplex-routing.test.js +0 -45
  334. package/dist/test/multiplex-status.test.d.ts +0 -1
  335. package/dist/test/multiplex-status.test.js +0 -63
  336. package/dist/test/multiplex-writes.test.d.ts +0 -1
  337. package/dist/test/multiplex-writes.test.js +0 -93
  338. package/dist/test/offline-cache.test.d.ts +0 -1
  339. package/dist/test/offline-cache.test.js +0 -289
  340. package/dist/test/provenance-regression.test.d.ts +0 -1
  341. package/dist/test/provenance-regression.test.js +0 -45
  342. package/dist/test/provenance-stamper.test.d.ts +0 -1
  343. package/dist/test/provenance-stamper.test.js +0 -41
  344. package/dist/test/provenance-type.test.d.ts +0 -1
  345. package/dist/test/provenance-type.test.js +0 -15
  346. package/dist/test/react-channel-messages-forward.test.d.ts +0 -1
  347. package/dist/test/react-channel-messages-forward.test.js +0 -139
  348. package/dist/test/react-channel-messages-range.test.d.ts +0 -1
  349. package/dist/test/react-channel-messages-range.test.js +0 -109
  350. package/dist/test/react-client-status.test.d.ts +0 -1
  351. package/dist/test/react-client-status.test.js +0 -35
  352. package/dist/test/react-dataclient.test.d.ts +0 -1
  353. package/dist/test/react-dataclient.test.js +0 -28
  354. package/dist/test/react-exports.test.d.ts +0 -1
  355. package/dist/test/react-exports.test.js +0 -46
  356. package/dist/test/react-multiagent-messages.test.d.ts +0 -1
  357. package/dist/test/react-multiagent-messages.test.js +0 -113
  358. package/dist/test/react-sources-option.test.d.ts +0 -1
  359. package/dist/test/react-sources-option.test.js +0 -41
  360. package/dist/test/react.test.d.ts +0 -1
  361. package/dist/test/react.test.js +0 -482
  362. package/dist/test/refine.test.d.ts +0 -1
  363. package/dist/test/refine.test.js +0 -71
  364. package/dist/test/rest-client.test.d.ts +0 -1
  365. package/dist/test/rest-client.test.js +0 -197
  366. package/dist/test/rpc-dispatcher.test.d.ts +0 -1
  367. package/dist/test/rpc-dispatcher.test.js +0 -251
  368. package/dist/test/singleton.test.d.ts +0 -1
  369. package/dist/test/singleton.test.js +0 -62
  370. package/dist/test/stats-rpc.test.d.ts +0 -1
  371. package/dist/test/stats-rpc.test.js +0 -69
  372. package/dist/test/status-tracker.test.d.ts +0 -1
  373. package/dist/test/status-tracker.test.js +0 -85
  374. package/dist/test/users-api.test.d.ts +0 -1
  375. package/dist/test/users-api.test.js +0 -19
  376. package/dist/test/utils.test.d.ts +0 -1
  377. package/dist/test/utils.test.js +0 -64
  378. /package/dist/{test/api-args.test.d.ts → esm/auth/auth-store.js} +0 -0
  379. /package/dist/{test/apis.test.d.ts → esm/client/data-client.js} +0 -0
  380. /package/dist/{test/auth.test.d.ts → esm/gateway/types.js} +0 -0
  381. /package/dist/{test/batch-apis.test.d.ts → esm/types/common.js} +0 -0
  382. /package/dist/{test/capabilities.test.d.ts → esm/types/index.js} +0 -0
  383. /package/dist/{test/config-manager.test.d.ts → esm/types/openapi.js} +0 -0
  384. /package/dist/{test/data-client-errors.test.d.ts → esm/types/provenance.js} +0 -0
  385. /package/dist/{test/data-client-shape.test.d.ts → esm/types/viewer.js} +0 -0
@@ -0,0 +1,86 @@
1
+ import type { DooverAuth } from "../auth/doover-auth.js";
2
+ import type { DooverStatsCollector } from "../client/stats.js";
3
+ import type { DooverClientConfig } from "../http/rest-client.js";
4
+ import type { GatewayListenerMap, WebSocketSession } from "./types.js";
5
+ import type { Aggregate, ChannelRef, JSONValue, MessageStructure } from "../types/common.js";
6
+ export type GatewayProvenanceHook = <T>(value: T, ctx: {
7
+ event: string;
8
+ sessionId?: string;
9
+ }) => any;
10
+ export interface ChannelHandlers {
11
+ onMessage?: (msg: MessageStructure) => void;
12
+ onMessageUpdate?: (msg: MessageStructure, requestData?: JSONValue) => void;
13
+ onAggregate?: (agg: Aggregate) => void;
14
+ }
15
+ export declare class GatewayClient {
16
+ private readonly config;
17
+ private socket;
18
+ private session;
19
+ private reconnectTimer;
20
+ private reconnectAttempts;
21
+ /** Set when the consumer explicitly disconnects — suppresses reconnect. */
22
+ private explicitlyDisconnected;
23
+ /** Guards against concurrent connect() callers creating duplicate sockets. */
24
+ private opening;
25
+ private listeners;
26
+ private subscriptions;
27
+ private channelRegistry;
28
+ private readonly auth;
29
+ private stats;
30
+ private provenanceHook;
31
+ constructor(config: DooverClientConfig, auth?: DooverAuth);
32
+ /** Attach a stats collector. Call with `null` to detach. */
33
+ setStats(stats: DooverStatsCollector | null): void;
34
+ /** Optional hook that stamps `__source` provenance onto emitted gateway
35
+ * payloads. `DooverClient` / `LocalAgentClient` set this; standalone
36
+ * `GatewayClient` users leave it null and get raw payloads. */
37
+ setProvenanceHook(hook: GatewayProvenanceHook | null): void;
38
+ private stamp;
39
+ connect(): Promise<void>;
40
+ private openSocket;
41
+ disconnect(code?: number, reason?: string): void;
42
+ on<K extends keyof GatewayListenerMap>(eventName: K, listener: GatewayListenerMap[K]): void;
43
+ off<K extends keyof GatewayListenerMap>(eventName: K, listener: GatewayListenerMap[K]): void;
44
+ subscribe(channel: ChannelRef, options?: {
45
+ diff_only?: boolean;
46
+ }): void;
47
+ unsubscribe(channel: ChannelRef): void;
48
+ /**
49
+ * Attach channel-scoped handlers. Returns an idempotent unsubscribe fn.
50
+ * The first handler for a channel triggers a wire-level subscribe; the
51
+ * last detach triggers a wire-level unsubscribe.
52
+ */
53
+ subscribeToChannel(channel: ChannelRef, handlers: ChannelHandlers): () => void;
54
+ syncChannel(channel: ChannelRef): void;
55
+ sendOneShotMessage(channel: ChannelRef, data: JSONValue): void;
56
+ getSession(): WebSocketSession | null;
57
+ isConnected(): boolean;
58
+ /** Number of channels the gateway is currently subscribed to. */
59
+ getSubscriptionCount(): number;
60
+ /** Snapshot of currently subscribed channels (for debug/inspection). */
61
+ getSubscriptions(): ChannelRef[];
62
+ /**
63
+ * Force a fresh connection: close the current socket (without suppressing
64
+ * reconnects) and immediately open a new one. Useful for a manual
65
+ * "reconnect now" control in debug UIs.
66
+ */
67
+ reconnect(): Promise<void>;
68
+ private handleMessage;
69
+ private identifyOrResume;
70
+ private resubscribeAll;
71
+ private send;
72
+ private emit;
73
+ private scheduleReconnect;
74
+ private connectInBackground;
75
+ /** Exponential backoff with full-jitter, capped at RECONNECT_CAP_MS. */
76
+ private computeReconnectDelay;
77
+ private installLifecycleListeners;
78
+ private handleVisibilityChange;
79
+ private handleOnline;
80
+ /**
81
+ * Called by lifecycle hooks when we have a strong signal that the network
82
+ * or tab has come back — skip the backoff schedule and reconnect now.
83
+ */
84
+ private tryImmediateReconnect;
85
+ private channelKey;
86
+ }
@@ -0,0 +1,463 @@
1
+ import { DooverGatewayError } from "../http/errors.js";
2
+ import { addTimestampToMessage } from "../utils/snowflake.js";
3
+ const RECONNECT_BASE_MS = 1000;
4
+ const RECONNECT_CAP_MS = 30000;
5
+ /** Schemes a WebSocket can be opened on — it maps http(s) to ws(s) itself. */
6
+ const ALLOWED_WSS_PROTOCOLS = new Set(["ws:", "wss:", "http:", "https:"]);
7
+ /**
8
+ * Reject a `dataWssUrl` that cannot address a gateway.
9
+ *
10
+ * An empty or relative value is the dangerous case, because nothing rejects it
11
+ * on its own: the WebSocket constructor resolves a relative URL against the
12
+ * document and maps https to wss, so in a browser `new WebSocket("")` silently
13
+ * points the gateway at whatever page is open. That page answers the upgrade
14
+ * with its own HTML and a 200, the browser reports "the server did not accept
15
+ * the WebSocket handshake", and the client retries against it forever — a loop
16
+ * that looks like a server problem and never names the real cause. It reached
17
+ * a kiosk panel that way, from a client built with `dataWssUrl: ""` because the
18
+ * build it was bundled into defined no env for it.
19
+ *
20
+ * Absolute http(s) is allowed as well as ws(s), since the WebSocket
21
+ * constructor maps those itself and existing configs rely on it.
22
+ */
23
+ function assertAbsoluteWssUrl(url) {
24
+ if (typeof url !== "string" || url.trim() === "") {
25
+ throw new Error("dataWssUrl is empty, so a gateway connection would resolve against the " +
26
+ "current page rather than a gateway; set it to an absolute ws(s):// URL");
27
+ }
28
+ let parsed;
29
+ try {
30
+ parsed = new URL(url);
31
+ }
32
+ catch {
33
+ throw new Error(`dataWssUrl must be an absolute ws(s):// URL, not the relative value ${JSON.stringify(url)}`);
34
+ }
35
+ if (!ALLOWED_WSS_PROTOCOLS.has(parsed.protocol)) {
36
+ throw new Error(`dataWssUrl must be ws(s):// or http(s)://, not ${parsed.protocol}//`);
37
+ }
38
+ }
39
+ export class GatewayClient {
40
+ constructor(config, auth) {
41
+ this.config = config;
42
+ this.socket = null;
43
+ this.session = null;
44
+ this.reconnectTimer = null;
45
+ this.reconnectAttempts = 0;
46
+ /** Set when the consumer explicitly disconnects — suppresses reconnect. */
47
+ this.explicitlyDisconnected = false;
48
+ /** Guards against concurrent connect() callers creating duplicate sockets. */
49
+ this.opening = false;
50
+ this.listeners = {
51
+ ready: new Set(),
52
+ channelSync: new Set(),
53
+ messageCreate: new Set(),
54
+ messageUpdate: new Set(),
55
+ aggregateUpdate: new Set(),
56
+ alarmTrigger: new Set(),
57
+ oneShotMessage: new Set(),
58
+ channelSubscription: new Set(),
59
+ channelUnsubscription: new Set(),
60
+ wssError: new Set(),
61
+ sessionCancelled: new Set(),
62
+ open: new Set(),
63
+ close: new Set(),
64
+ };
65
+ this.subscriptions = new Map();
66
+ this.channelRegistry = new Map();
67
+ this.stats = null;
68
+ this.provenanceHook = null;
69
+ this.handleVisibilityChange = () => {
70
+ if (typeof document === "undefined")
71
+ return;
72
+ if (document.visibilityState !== "visible")
73
+ return;
74
+ this.tryImmediateReconnect();
75
+ };
76
+ this.handleOnline = () => {
77
+ this.tryImmediateReconnect();
78
+ };
79
+ this.auth = auth ?? null;
80
+ this.installLifecycleListeners();
81
+ }
82
+ /** Attach a stats collector. Call with `null` to detach. */
83
+ setStats(stats) {
84
+ this.stats = stats;
85
+ }
86
+ /** Optional hook that stamps `__source` provenance onto emitted gateway
87
+ * payloads. `DooverClient` / `LocalAgentClient` set this; standalone
88
+ * `GatewayClient` users leave it null and get raw payloads. */
89
+ setProvenanceHook(hook) {
90
+ this.provenanceHook = hook;
91
+ }
92
+ stamp(value, event) {
93
+ if (!this.provenanceHook)
94
+ return value;
95
+ return this.provenanceHook(value, {
96
+ event,
97
+ ...(this.session?.session_id ? { sessionId: this.session.session_id } : {}),
98
+ });
99
+ }
100
+ async connect() {
101
+ this.explicitlyDisconnected = false;
102
+ if (this.socket && this.socket.readyState <= WebSocket.OPEN) {
103
+ return;
104
+ }
105
+ // De-dupe concurrent callers. Without this, N simultaneous
106
+ // `subscribeToChannel(...)` calls each await auth, then each create
107
+ // their own socket — the last one wins `this.socket`, but the earlier
108
+ // sockets' `onmessage` handlers still fire and try to send() through
109
+ // `this.socket` (a newer, not-yet-open socket → throws). The flag is
110
+ // cleared synchronously as soon as the new socket is assigned in
111
+ // `openSocket`, so reconnects after close still work.
112
+ if (this.opening) {
113
+ return;
114
+ }
115
+ this.opening = true;
116
+ try {
117
+ await this.openSocket();
118
+ }
119
+ finally {
120
+ this.opening = false;
121
+ }
122
+ }
123
+ async openSocket() {
124
+ // Before auth, before any socket: a URL that cannot address a gateway is a
125
+ // configuration fault, and finding out now costs one error instead of an
126
+ // endless handshake failure that reads like a broken server.
127
+ assertAbsoluteWssUrl(this.config.dataWssUrl);
128
+ if (this.auth) {
129
+ await this.auth.ensureReady();
130
+ }
131
+ const hasFactory = !!this.config.webSocketFactory;
132
+ const wsParams = this.auth
133
+ ? await this.auth.prepareWebSocket(this.config.dataWssUrl, hasFactory)
134
+ : { url: this.config.dataWssUrl };
135
+ let socket;
136
+ if (this.config.webSocketFactory) {
137
+ socket = this.config.webSocketFactory({
138
+ url: wsParams.url,
139
+ headers: wsParams.headers,
140
+ });
141
+ }
142
+ else {
143
+ const WebSocketImpl = this.config.webSocketImpl ?? WebSocket;
144
+ socket = new WebSocketImpl(wsParams.url);
145
+ }
146
+ this.socket = socket;
147
+ // Release the concurrency gate synchronously now that the new socket is
148
+ // assigned — any subsequent connect() will see it via `this.socket`.
149
+ this.opening = false;
150
+ socket.onopen = () => this.emit("open");
151
+ socket.onclose = (event) => {
152
+ this.emit("close", event);
153
+ this.scheduleReconnect();
154
+ };
155
+ socket.onerror = () => undefined;
156
+ socket.onmessage = (event) => this.handleMessage(event.data);
157
+ }
158
+ disconnect(code, reason) {
159
+ this.explicitlyDisconnected = true;
160
+ if (this.reconnectTimer) {
161
+ clearTimeout(this.reconnectTimer);
162
+ this.reconnectTimer = null;
163
+ }
164
+ this.reconnectAttempts = 0;
165
+ this.socket?.close(code, reason);
166
+ this.socket = null;
167
+ }
168
+ on(eventName, listener) {
169
+ this.listeners[eventName].add(listener);
170
+ }
171
+ off(eventName, listener) {
172
+ this.listeners[eventName].delete(listener);
173
+ }
174
+ subscribe(channel, options) {
175
+ this.subscriptions.set(this.channelKey(channel), {
176
+ channel,
177
+ diff_only: options?.diff_only ?? false,
178
+ });
179
+ if (!this.isConnected()) {
180
+ this.connectInBackground();
181
+ return;
182
+ }
183
+ this.send({
184
+ op: 12,
185
+ d: {
186
+ channel,
187
+ organisation_id: this.config.organisationId ?? null,
188
+ diff_only: options?.diff_only ?? false,
189
+ },
190
+ });
191
+ }
192
+ unsubscribe(channel) {
193
+ this.subscriptions.delete(this.channelKey(channel));
194
+ if (!this.isConnected()) {
195
+ return;
196
+ }
197
+ this.send({
198
+ op: 13,
199
+ d: {
200
+ channel,
201
+ organisation_id: this.config.organisationId ?? null,
202
+ },
203
+ });
204
+ }
205
+ /**
206
+ * Attach channel-scoped handlers. Returns an idempotent unsubscribe fn.
207
+ * The first handler for a channel triggers a wire-level subscribe; the
208
+ * last detach triggers a wire-level unsubscribe.
209
+ */
210
+ subscribeToChannel(channel, handlers) {
211
+ const key = this.channelKey(channel);
212
+ let entry = this.channelRegistry.get(key);
213
+ if (!entry) {
214
+ entry = { handlers: new Set(), cleanup: [] };
215
+ this.channelRegistry.set(key, entry);
216
+ const matches = (c) => c.agent_id === channel.agent_id && c.name === channel.name;
217
+ const onMsgCreate = (msg) => {
218
+ if (!matches(msg.channel))
219
+ return;
220
+ entry.handlers.forEach((h) => h.onMessage?.(msg));
221
+ };
222
+ const onMsgUpdate = (msg, requestData) => {
223
+ if (!matches(msg.channel))
224
+ return;
225
+ entry.handlers.forEach((h) => h.onMessageUpdate?.(msg, requestData));
226
+ };
227
+ const onAggregate = (event) => {
228
+ if (!matches(event.channel))
229
+ return;
230
+ entry.handlers.forEach((h) => h.onAggregate?.(event.aggregate));
231
+ };
232
+ const onChannelSync = (event) => {
233
+ if (!matches(event.channel))
234
+ return;
235
+ entry.handlers.forEach((h) => h.onAggregate?.(event.aggregate));
236
+ };
237
+ this.on("messageCreate", onMsgCreate);
238
+ this.on("messageUpdate", onMsgUpdate);
239
+ this.on("aggregateUpdate", onAggregate);
240
+ this.on("channelSync", onChannelSync);
241
+ entry.cleanup.push(() => this.off("messageCreate", onMsgCreate), () => this.off("messageUpdate", onMsgUpdate), () => this.off("aggregateUpdate", onAggregate), () => this.off("channelSync", onChannelSync));
242
+ this.subscribe(channel);
243
+ }
244
+ entry.handlers.add(handlers);
245
+ let detached = false;
246
+ return () => {
247
+ if (detached)
248
+ return;
249
+ detached = true;
250
+ entry.handlers.delete(handlers);
251
+ if (entry.handlers.size === 0) {
252
+ entry.cleanup.forEach((fn) => fn());
253
+ this.channelRegistry.delete(key);
254
+ this.unsubscribe(channel);
255
+ }
256
+ };
257
+ }
258
+ syncChannel(channel) {
259
+ if (!this.isConnected()) {
260
+ this.connectInBackground();
261
+ return;
262
+ }
263
+ this.send({
264
+ op: 14,
265
+ d: {
266
+ channel,
267
+ organisation_id: this.config.organisationId ?? null,
268
+ },
269
+ });
270
+ }
271
+ sendOneShotMessage(channel, data) {
272
+ if (!this.isConnected()) {
273
+ this.connectInBackground();
274
+ return;
275
+ }
276
+ this.send({
277
+ op: 15,
278
+ d: {
279
+ channel,
280
+ data,
281
+ },
282
+ });
283
+ }
284
+ getSession() {
285
+ return this.session;
286
+ }
287
+ isConnected() {
288
+ return this.socket?.readyState === WebSocket.OPEN;
289
+ }
290
+ /** Number of channels the gateway is currently subscribed to. */
291
+ getSubscriptionCount() {
292
+ return this.subscriptions.size;
293
+ }
294
+ /** Snapshot of currently subscribed channels (for debug/inspection). */
295
+ getSubscriptions() {
296
+ return [...this.subscriptions.values()].map((s) => s.channel);
297
+ }
298
+ /**
299
+ * Force a fresh connection: close the current socket (without suppressing
300
+ * reconnects) and immediately open a new one. Useful for a manual
301
+ * "reconnect now" control in debug UIs.
302
+ */
303
+ async reconnect() {
304
+ if (this.reconnectTimer) {
305
+ clearTimeout(this.reconnectTimer);
306
+ this.reconnectTimer = null;
307
+ }
308
+ this.reconnectAttempts = 0;
309
+ // Drop the session so the new socket identifies fresh (op 10) rather
310
+ // than attempting to resume a just-closed session (op 11) that the
311
+ // server has already torn down.
312
+ this.session = null;
313
+ if (this.socket) {
314
+ // Suppress the auto-reconnect path so we don't double-schedule.
315
+ const prev = this.socket;
316
+ prev.onclose = null;
317
+ prev.close(1000, "manual reconnect");
318
+ this.socket = null;
319
+ }
320
+ await this.connect();
321
+ }
322
+ handleMessage(raw) {
323
+ this.stats?.recordGatewayReceived();
324
+ const message = JSON.parse(raw);
325
+ if (message.op === 3) {
326
+ this.session = null;
327
+ this.emit("sessionCancelled");
328
+ return;
329
+ }
330
+ if (message.op !== 0 || !message.t) {
331
+ return;
332
+ }
333
+ switch (message.t) {
334
+ case "Hello":
335
+ this.identifyOrResume();
336
+ break;
337
+ case "Ready":
338
+ this.reconnectAttempts = 0;
339
+ this.session = message.d;
340
+ this.emit("ready", message.d);
341
+ this.resubscribeAll();
342
+ break;
343
+ case "ChannelSync":
344
+ this.emit("channelSync", this.stamp(message.d, "channelSync"));
345
+ break;
346
+ case "MessageCreate":
347
+ this.emit("messageCreate", this.stamp(addTimestampToMessage(message.d), "messageCreate"));
348
+ break;
349
+ case "MessageUpdate":
350
+ this.emit("messageUpdate", this.stamp(addTimestampToMessage(message.d.message), "messageUpdate"), message.d.request_data);
351
+ break;
352
+ case "AggregateUpdate":
353
+ this.emit("aggregateUpdate", this.stamp(message.d, "aggregateUpdate"));
354
+ break;
355
+ case "AlarmTrigger":
356
+ this.emit("alarmTrigger", this.stamp(message.d, "alarmTrigger"));
357
+ break;
358
+ case "OneShotMessage":
359
+ this.emit("oneShotMessage", this.stamp(message.d, "oneShotMessage"));
360
+ break;
361
+ case "ChannelSubscription":
362
+ this.emit("channelSubscription", message.d);
363
+ break;
364
+ case "ChannelUnsubscription":
365
+ this.emit("channelUnsubscription", message.d);
366
+ break;
367
+ case "WSSErrorEvent":
368
+ this.emit("wssError", message.d);
369
+ break;
370
+ default:
371
+ break;
372
+ }
373
+ }
374
+ identifyOrResume() {
375
+ if (this.session) {
376
+ this.send({
377
+ op: 11,
378
+ d: {
379
+ session_id: this.session.session_id,
380
+ session_token: this.session.session_token,
381
+ default_connection: false,
382
+ },
383
+ });
384
+ return;
385
+ }
386
+ this.send({
387
+ op: 10,
388
+ d: {
389
+ default_connection: false,
390
+ organisation_id: this.config.organisationId ?? null,
391
+ sharing_mode: this.config.sharing ?? "internal",
392
+ },
393
+ });
394
+ }
395
+ resubscribeAll() {
396
+ for (const entry of this.subscriptions.values()) {
397
+ this.subscribe(entry.channel, { diff_only: entry.diff_only });
398
+ }
399
+ }
400
+ send(payload) {
401
+ if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
402
+ throw new DooverGatewayError("WebSocket is not connected");
403
+ }
404
+ this.socket.send(JSON.stringify(payload));
405
+ this.stats?.recordGatewaySent();
406
+ }
407
+ emit(eventName, ...args) {
408
+ this.listeners[eventName].forEach((listener) => {
409
+ listener(...args);
410
+ });
411
+ }
412
+ scheduleReconnect() {
413
+ if (this.reconnectTimer || this.explicitlyDisconnected) {
414
+ return;
415
+ }
416
+ const delay = this.computeReconnectDelay();
417
+ this.reconnectAttempts += 1;
418
+ this.reconnectTimer = setTimeout(() => {
419
+ this.reconnectTimer = null;
420
+ this.connectInBackground();
421
+ }, delay);
422
+ }
423
+ connectInBackground() {
424
+ void this.connect().catch((err) => {
425
+ this.emit("wssError", {
426
+ message: err instanceof Error ? err.message : String(err),
427
+ });
428
+ });
429
+ }
430
+ /** Exponential backoff with full-jitter, capped at RECONNECT_CAP_MS. */
431
+ computeReconnectDelay() {
432
+ const exp = Math.min(RECONNECT_CAP_MS, RECONNECT_BASE_MS * 2 ** this.reconnectAttempts);
433
+ return Math.floor(Math.random() * exp);
434
+ }
435
+ installLifecycleListeners() {
436
+ if (this.config.disableBrowserLifecycleHooks)
437
+ return;
438
+ if (typeof document !== "undefined" && typeof document.addEventListener === "function") {
439
+ document.addEventListener("visibilitychange", this.handleVisibilityChange);
440
+ }
441
+ if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
442
+ window.addEventListener("online", this.handleOnline);
443
+ }
444
+ }
445
+ /**
446
+ * Called by lifecycle hooks when we have a strong signal that the network
447
+ * or tab has come back — skip the backoff schedule and reconnect now.
448
+ */
449
+ tryImmediateReconnect() {
450
+ if (this.explicitlyDisconnected)
451
+ return;
452
+ if (this.isConnected())
453
+ return;
454
+ if (this.reconnectTimer) {
455
+ clearTimeout(this.reconnectTimer);
456
+ this.reconnectTimer = null;
457
+ }
458
+ this.connectInBackground();
459
+ }
460
+ channelKey(channel) {
461
+ return `${channel.agent_id}/${channel.name}`;
462
+ }
463
+ }
@@ -0,0 +1,3 @@
1
+ export { GatewayClient } from "./gateway-client.js";
2
+ export type { ChannelHandlers } from "./gateway-client.js";
3
+ export type * from "./types.js";
@@ -0,0 +1 @@
1
+ export { GatewayClient } from "./gateway-client.js";
@@ -0,0 +1,142 @@
1
+ import type { Aggregate, Alarm, ChannelRef, JSONValue, MessageStructure } from "../types/common.js";
2
+ export interface WebSocketSubscription {
3
+ channel: ChannelRef;
4
+ organisation_id?: string | null;
5
+ diff_only: boolean;
6
+ }
7
+ export interface WebSocketSession {
8
+ session_id: string;
9
+ session_token: string;
10
+ subscriptions: WebSocketSubscription[];
11
+ }
12
+ export interface GatewayMessageBase {
13
+ op: number;
14
+ d: unknown;
15
+ s?: number | null;
16
+ t?: string;
17
+ }
18
+ export interface GatewayHello extends GatewayMessageBase {
19
+ op: 0;
20
+ t: "Hello";
21
+ d: Record<string, never>;
22
+ }
23
+ export interface GatewayReady extends GatewayMessageBase {
24
+ op: 0;
25
+ t: "Ready";
26
+ d: WebSocketSession;
27
+ }
28
+ export interface GatewayChannelSync extends GatewayMessageBase {
29
+ op: 0;
30
+ t: "ChannelSync";
31
+ d: {
32
+ channel: ChannelRef;
33
+ aggregate: Aggregate;
34
+ };
35
+ }
36
+ export interface GatewayMessageCreate extends GatewayMessageBase {
37
+ op: 0;
38
+ t: "MessageCreate";
39
+ d: Omit<MessageStructure, "timestamp">;
40
+ }
41
+ /**
42
+ * `message` is the full post-update MessageStructure; `request_data` is the
43
+ * diff of just-changed fields. Consumers should read `message` for the
44
+ * current state and only touch `request_data` if they specifically need to
45
+ * know what changed in this update.
46
+ */
47
+ export interface GatewayMessageUpdate extends GatewayMessageBase {
48
+ op: 0;
49
+ t: "MessageUpdate";
50
+ d: {
51
+ channel: ChannelRef;
52
+ author_id: string;
53
+ organisation_id?: string;
54
+ message: Omit<MessageStructure, "timestamp">;
55
+ request_data: JSONValue;
56
+ };
57
+ }
58
+ export interface GatewayAggregateUpdate extends GatewayMessageBase {
59
+ op: 0;
60
+ t: "AggregateUpdate";
61
+ d: {
62
+ author_id: string;
63
+ channel: ChannelRef;
64
+ aggregate: Aggregate;
65
+ request_data: Aggregate;
66
+ organisation_id: string;
67
+ };
68
+ }
69
+ export interface GatewayAlarmTrigger extends GatewayMessageBase {
70
+ op: 0;
71
+ t: "AlarmTrigger";
72
+ d: {
73
+ channel: ChannelRef;
74
+ alarm: Alarm;
75
+ old_state: Alarm["state"];
76
+ new_state: Alarm["state"];
77
+ aggregate: Aggregate;
78
+ request_data: Aggregate;
79
+ organisation_id: string;
80
+ };
81
+ }
82
+ export interface GatewayOneShotMessage extends GatewayMessageBase {
83
+ op: 0;
84
+ t: "OneShotMessage";
85
+ d: {
86
+ id: string | null;
87
+ author_id: string;
88
+ channel: ChannelRef;
89
+ data: JSONValue;
90
+ };
91
+ }
92
+ export interface GatewayChannelSubscription extends GatewayMessageBase {
93
+ op: 0;
94
+ t: "ChannelSubscription";
95
+ d: {
96
+ agent_id: string;
97
+ channel: ChannelRef;
98
+ session_id: string;
99
+ default_session: boolean;
100
+ };
101
+ }
102
+ export interface GatewayChannelUnsubscription extends GatewayMessageBase {
103
+ op: 0;
104
+ t: "ChannelUnsubscription";
105
+ d: {
106
+ agent_id: string;
107
+ channel: ChannelRef;
108
+ session_id: string;
109
+ default_session: boolean;
110
+ };
111
+ }
112
+ export interface GatewayWSSErrorEvent extends GatewayMessageBase {
113
+ op: 0;
114
+ t: "WSSErrorEvent";
115
+ d: {
116
+ message: string;
117
+ };
118
+ }
119
+ export interface GatewayHeartbeatAck extends GatewayMessageBase {
120
+ op: 2;
121
+ d: Record<string, never>;
122
+ }
123
+ export interface GatewaySessionCancelled extends GatewayMessageBase {
124
+ op: 3;
125
+ d: Record<string, never>;
126
+ }
127
+ export type GatewayInboundMessage = GatewayHello | GatewayReady | GatewayChannelSync | GatewayMessageCreate | GatewayMessageUpdate | GatewayAggregateUpdate | GatewayAlarmTrigger | GatewayOneShotMessage | GatewayChannelSubscription | GatewayChannelUnsubscription | GatewayWSSErrorEvent | GatewayHeartbeatAck | GatewaySessionCancelled;
128
+ export interface GatewayListenerMap {
129
+ ready: (event: GatewayReady["d"]) => void;
130
+ channelSync: (event: GatewayChannelSync["d"]) => void;
131
+ messageCreate: (event: MessageStructure) => void;
132
+ messageUpdate: (message: MessageStructure, request_data: JSONValue | undefined) => void;
133
+ aggregateUpdate: (event: GatewayAggregateUpdate["d"]) => void;
134
+ alarmTrigger: (event: GatewayAlarmTrigger["d"]) => void;
135
+ oneShotMessage: (event: GatewayOneShotMessage["d"]) => void;
136
+ channelSubscription: (event: GatewayChannelSubscription["d"]) => void;
137
+ channelUnsubscription: (event: GatewayChannelUnsubscription["d"]) => void;
138
+ wssError: (event: GatewayWSSErrorEvent["d"]) => void;
139
+ sessionCancelled: () => void;
140
+ open: () => void;
141
+ close: (event: CloseEvent) => void;
142
+ }