doover-js 0.11.0 → 0.13.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 (389) hide show
  1. package/README.md +106 -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 +17 -14
  34. package/dist/client/doover-client.d.ts +9 -7
  35. package/dist/client/doover-client.js +44 -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 +6 -0
  39. package/dist/client/index.js +12 -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/network-status.d.ts +17 -0
  47. package/dist/client/network-status.js +70 -0
  48. package/dist/client/offline-cache.d.ts +9 -4
  49. package/dist/client/offline-cache.js +34 -22
  50. package/dist/client/provenance.d.ts +1 -1
  51. package/dist/client/request-options.d.ts +1 -1
  52. package/dist/client/singleton.d.ts +2 -2
  53. package/dist/client/singleton.js +2 -2
  54. package/dist/client/status-tracker.d.ts +1 -1
  55. package/dist/esm/apis/_args.d.ts +16 -0
  56. package/dist/esm/apis/_args.js +27 -0
  57. package/dist/esm/apis/agents-api.d.ts +196 -0
  58. package/dist/esm/apis/agents-api.js +327 -0
  59. package/dist/esm/apis/aggregates-api.d.ts +67 -0
  60. package/dist/esm/apis/aggregates-api.js +64 -0
  61. package/dist/esm/apis/alarms-api.d.ts +48 -0
  62. package/dist/esm/apis/alarms-api.js +75 -0
  63. package/dist/esm/apis/channels-api.d.ts +83 -0
  64. package/dist/esm/apis/channels-api.js +65 -0
  65. package/dist/esm/apis/connections-api.d.ts +45 -0
  66. package/dist/esm/apis/connections-api.js +44 -0
  67. package/dist/esm/apis/messages-api.d.ts +128 -0
  68. package/dist/esm/apis/messages-api.js +179 -0
  69. package/dist/esm/apis/notifications-api.d.ts +94 -0
  70. package/dist/esm/apis/notifications-api.js +153 -0
  71. package/dist/esm/apis/organisations-api.d.ts +26 -0
  72. package/dist/esm/apis/organisations-api.js +41 -0
  73. package/dist/esm/apis/permissions-api.d.ts +17 -0
  74. package/dist/esm/apis/permissions-api.js +23 -0
  75. package/dist/esm/apis/processors-api.d.ts +56 -0
  76. package/dist/esm/apis/processors-api.js +97 -0
  77. package/dist/esm/apis/turn-api.d.ts +7 -0
  78. package/dist/esm/apis/turn-api.js +8 -0
  79. package/dist/esm/apis/users-api.d.ts +8 -0
  80. package/dist/esm/apis/users-api.js +9 -0
  81. package/dist/esm/auth/auth-profile.d.ts +45 -0
  82. package/dist/esm/auth/auth-profile.js +68 -0
  83. package/dist/esm/auth/auth-store.d.ts +14 -0
  84. package/dist/esm/auth/build-auth.d.ts +38 -0
  85. package/dist/esm/auth/build-auth.js +92 -0
  86. package/dist/esm/auth/cookie-auth.d.ts +91 -0
  87. package/dist/esm/auth/cookie-auth.js +196 -0
  88. package/dist/esm/auth/doover-auth.d.ts +52 -0
  89. package/dist/esm/auth/doover-auth.js +28 -0
  90. package/dist/esm/auth/doover-token-auth.d.ts +39 -0
  91. package/dist/esm/auth/doover-token-auth.js +217 -0
  92. package/dist/esm/auth/errors.d.ts +3 -0
  93. package/dist/esm/auth/errors.js +6 -0
  94. package/dist/esm/auth/index.d.ts +10 -0
  95. package/dist/esm/auth/index.js +6 -0
  96. package/dist/esm/auth/jwt.d.ts +6 -0
  97. package/dist/esm/auth/jwt.js +26 -0
  98. package/dist/esm/client/capabilities.d.ts +10 -0
  99. package/dist/esm/client/capabilities.js +42 -0
  100. package/dist/esm/client/data-client.d.ts +107 -0
  101. package/dist/esm/client/doover-client.d.ts +48 -0
  102. package/dist/esm/client/doover-client.js +96 -0
  103. package/dist/esm/client/errors.d.ts +32 -0
  104. package/dist/esm/client/errors.js +64 -0
  105. package/dist/esm/client/index.d.ts +6 -0
  106. package/dist/esm/client/index.js +3 -0
  107. package/dist/esm/client/local-agent-client.d.ts +65 -0
  108. package/dist/esm/client/local-agent-client.js +225 -0
  109. package/dist/esm/client/multiplex-client.d.ts +165 -0
  110. package/dist/esm/client/multiplex-client.js +842 -0
  111. package/dist/esm/client/multiplex-gateway.d.ts +49 -0
  112. package/dist/esm/client/multiplex-gateway.js +110 -0
  113. package/dist/esm/client/multiplex-merge.d.ts +12 -0
  114. package/dist/esm/client/multiplex-merge.js +38 -0
  115. package/dist/esm/client/network-status.d.ts +17 -0
  116. package/dist/esm/client/network-status.js +66 -0
  117. package/dist/esm/client/offline-cache.d.ts +167 -0
  118. package/dist/esm/client/offline-cache.js +769 -0
  119. package/dist/esm/client/provenance.d.ts +60 -0
  120. package/dist/esm/client/provenance.js +108 -0
  121. package/dist/esm/client/request-options.d.ts +23 -0
  122. package/dist/esm/client/request-options.js +23 -0
  123. package/dist/esm/client/singleton.d.ts +26 -0
  124. package/dist/esm/client/singleton.js +54 -0
  125. package/dist/esm/client/stats.d.ts +79 -0
  126. package/dist/esm/client/stats.js +155 -0
  127. package/dist/esm/client/status-tracker.d.ts +24 -0
  128. package/dist/esm/client/status-tracker.js +86 -0
  129. package/dist/esm/gateway/gateway-client.d.ts +86 -0
  130. package/dist/esm/gateway/gateway-client.js +463 -0
  131. package/dist/esm/gateway/index.d.ts +3 -0
  132. package/dist/esm/gateway/index.js +1 -0
  133. package/dist/esm/gateway/types.d.ts +142 -0
  134. package/dist/esm/http/errors.d.ts +19 -0
  135. package/dist/esm/http/errors.js +22 -0
  136. package/dist/esm/http/index.d.ts +3 -0
  137. package/dist/esm/http/index.js +2 -0
  138. package/dist/esm/http/rest-client.d.ts +64 -0
  139. package/dist/esm/http/rest-client.js +181 -0
  140. package/dist/esm/index.d.ts +64 -0
  141. package/dist/esm/index.js +38 -0
  142. package/dist/esm/node/config-manager.d.ts +34 -0
  143. package/dist/esm/node/config-manager.js +140 -0
  144. package/dist/esm/node/index.d.ts +1 -0
  145. package/dist/esm/node/index.js +1 -0
  146. package/dist/esm/package.json +1 -0
  147. package/dist/esm/react/context.d.ts +23 -0
  148. package/dist/esm/react/context.js +28 -0
  149. package/dist/esm/react/index.d.ts +38 -0
  150. package/dist/esm/react/index.js +21 -0
  151. package/dist/esm/react/messageRangeStore.d.ts +93 -0
  152. package/dist/esm/react/messageRangeStore.js +140 -0
  153. package/dist/esm/react/sharedQueryClient.d.ts +21 -0
  154. package/dist/esm/react/sharedQueryClient.js +35 -0
  155. package/dist/esm/react/useAgentChannel.d.ts +8 -0
  156. package/dist/esm/react/useAgentChannel.js +9 -0
  157. package/dist/esm/react/useAgentConnections.d.ts +8 -0
  158. package/dist/esm/react/useAgentConnections.js +20 -0
  159. package/dist/esm/react/useAgentTokenState.d.ts +70 -0
  160. package/dist/esm/react/useAgentTokenState.js +127 -0
  161. package/dist/esm/react/useChannelAggregate.d.ts +64 -0
  162. package/dist/esm/react/useChannelAggregate.js +77 -0
  163. package/dist/esm/react/useChannelMessage.d.ts +45 -0
  164. package/dist/esm/react/useChannelMessage.js +79 -0
  165. package/dist/esm/react/useChannelMessages.d.ts +83 -0
  166. package/dist/esm/react/useChannelMessages.js +214 -0
  167. package/dist/esm/react/useChannelSubscription.d.ts +27 -0
  168. package/dist/esm/react/useChannelSubscription.js +30 -0
  169. package/dist/esm/react/useClientStatus.d.ts +10 -0
  170. package/dist/esm/react/useClientStatus.js +19 -0
  171. package/dist/esm/react/useConnectionState.d.ts +26 -0
  172. package/dist/esm/react/useConnectionState.js +45 -0
  173. package/dist/esm/react/useDeviceMap.d.ts +109 -0
  174. package/dist/esm/react/useDeviceMap.js +59 -0
  175. package/dist/esm/react/useInvocationLogs.d.ts +23 -0
  176. package/dist/esm/react/useInvocationLogs.js +37 -0
  177. package/dist/esm/react/useMultiAgentAggregates.d.ts +38 -0
  178. package/dist/esm/react/useMultiAgentAggregates.js +104 -0
  179. package/dist/esm/react/useMultiAgentChannelMessages.d.ts +79 -0
  180. package/dist/esm/react/useMultiAgentChannelMessages.js +169 -0
  181. package/dist/esm/react/useOfflineStatus.d.ts +8 -0
  182. package/dist/esm/react/useOfflineStatus.js +37 -0
  183. package/dist/esm/react/useSendMessage.d.ts +16 -0
  184. package/dist/esm/react/useSendMessage.js +26 -0
  185. package/dist/esm/react/useSendRpc.d.ts +68 -0
  186. package/dist/esm/react/useSendRpc.js +164 -0
  187. package/dist/esm/react/useTurnCredentials.d.ts +12 -0
  188. package/dist/esm/react/useTurnCredentials.js +22 -0
  189. package/dist/esm/react/useUpdateAggregate.d.ts +27 -0
  190. package/dist/esm/react/useUpdateAggregate.js +39 -0
  191. package/dist/esm/react/useUpdateMessage.d.ts +38 -0
  192. package/dist/esm/react/useUpdateMessage.js +36 -0
  193. package/dist/esm/refine/index.d.ts +72 -0
  194. package/dist/esm/refine/index.js +215 -0
  195. package/dist/esm/rpc/errors.d.ts +10 -0
  196. package/dist/esm/rpc/errors.js +19 -0
  197. package/dist/esm/rpc/index.d.ts +3 -0
  198. package/dist/esm/rpc/index.js +2 -0
  199. package/dist/esm/rpc/rpc-dispatcher.d.ts +41 -0
  200. package/dist/esm/rpc/rpc-dispatcher.js +141 -0
  201. package/dist/esm/types/audit.d.ts +53 -0
  202. package/dist/esm/types/audit.js +11 -0
  203. package/dist/esm/types/batch.d.ts +85 -0
  204. package/dist/esm/types/batch.js +42 -0
  205. package/dist/esm/types/common.d.ts +250 -0
  206. package/dist/esm/types/connection.d.ts +72 -0
  207. package/dist/esm/types/connection.js +7 -0
  208. package/dist/esm/types/index.d.ts +9 -0
  209. package/dist/esm/types/openapi.d.ts +195 -0
  210. package/dist/esm/types/provenance.d.ts +45 -0
  211. package/dist/esm/types/viewer.d.ts +122 -0
  212. package/dist/esm/utils/snowflake.d.ts +21 -0
  213. package/dist/esm/utils/snowflake.js +33 -0
  214. package/dist/esm/viewer/doover-data-provider.d.ts +90 -0
  215. package/dist/esm/viewer/doover-data-provider.js +189 -0
  216. package/dist/esm/viewer/path-parsing.d.ts +5 -0
  217. package/dist/esm/viewer/path-parsing.js +35 -0
  218. package/dist/gateway/gateway-client.d.ts +5 -5
  219. package/dist/gateway/gateway-client.js +5 -5
  220. package/dist/gateway/index.d.ts +3 -0
  221. package/dist/gateway/index.js +5 -0
  222. package/dist/gateway/types.d.ts +1 -1
  223. package/dist/http/index.d.ts +3 -0
  224. package/dist/http/index.js +9 -0
  225. package/dist/http/rest-client.d.ts +5 -3
  226. package/dist/http/rest-client.js +2 -2
  227. package/dist/index.d.ts +64 -62
  228. package/dist/index.js +92 -89
  229. package/dist/node/config-manager.d.ts +2 -2
  230. package/dist/node/config-manager.js +5 -5
  231. package/dist/node/index.d.ts +1 -1
  232. package/dist/node/index.js +2 -2
  233. package/dist/react/context.d.ts +1 -1
  234. package/dist/react/index.d.ts +38 -38
  235. package/dist/react/index.js +59 -59
  236. package/dist/react/messageRangeStore.d.ts +1 -1
  237. package/dist/react/useAgentChannel.d.ts +3 -3
  238. package/dist/react/useAgentChannel.js +2 -2
  239. package/dist/react/useAgentConnections.d.ts +1 -1
  240. package/dist/react/useAgentConnections.js +2 -2
  241. package/dist/react/useAgentTokenState.d.ts +3 -3
  242. package/dist/react/useAgentTokenState.js +8 -8
  243. package/dist/react/useChannelAggregate.d.ts +3 -3
  244. package/dist/react/useChannelAggregate.js +8 -8
  245. package/dist/react/useChannelMessage.d.ts +2 -2
  246. package/dist/react/useChannelMessage.js +4 -4
  247. package/dist/react/useChannelMessages.d.ts +3 -3
  248. package/dist/react/useChannelMessages.js +10 -10
  249. package/dist/react/useChannelSubscription.d.ts +2 -2
  250. package/dist/react/useChannelSubscription.js +2 -2
  251. package/dist/react/useClientStatus.d.ts +1 -1
  252. package/dist/react/useClientStatus.js +2 -2
  253. package/dist/react/useConnectionState.js +2 -2
  254. package/dist/react/useDeviceMap.js +2 -2
  255. package/dist/react/useInvocationLogs.d.ts +1 -1
  256. package/dist/react/useInvocationLogs.js +2 -2
  257. package/dist/react/useMultiAgentAggregates.d.ts +1 -1
  258. package/dist/react/useMultiAgentAggregates.js +5 -5
  259. package/dist/react/useMultiAgentChannelMessages.d.ts +1 -1
  260. package/dist/react/useMultiAgentChannelMessages.js +2 -2
  261. package/dist/react/useOfflineStatus.d.ts +2 -2
  262. package/dist/react/useOfflineStatus.js +31 -17
  263. package/dist/react/useSendMessage.d.ts +2 -2
  264. package/dist/react/useSendMessage.js +2 -2
  265. package/dist/react/useSendRpc.d.ts +2 -2
  266. package/dist/react/useSendRpc.js +2 -2
  267. package/dist/react/useTurnCredentials.d.ts +2 -2
  268. package/dist/react/useTurnCredentials.js +2 -2
  269. package/dist/react/useUpdateAggregate.d.ts +3 -3
  270. package/dist/react/useUpdateAggregate.js +4 -4
  271. package/dist/react/useUpdateMessage.d.ts +2 -2
  272. package/dist/react/useUpdateMessage.js +2 -2
  273. package/dist/refine/index.d.ts +1 -1
  274. package/dist/rpc/errors.d.ts +1 -1
  275. package/dist/rpc/index.d.ts +3 -0
  276. package/dist/rpc/index.js +7 -0
  277. package/dist/rpc/rpc-dispatcher.d.ts +4 -4
  278. package/dist/rpc/rpc-dispatcher.js +2 -2
  279. package/dist/types/common.d.ts +1 -1
  280. package/dist/types/index.d.ts +9 -0
  281. package/dist/types/index.js +2 -0
  282. package/dist/types/openapi.d.ts +1 -1
  283. package/dist/types/viewer.d.ts +2 -2
  284. package/dist/viewer/doover-data-provider.d.ts +10 -10
  285. package/dist/viewer/doover-data-provider.js +25 -25
  286. package/dist/viewer/path-parsing.d.ts +1 -1
  287. package/package.json +795 -8
  288. package/dist/test/api-args.test.js +0 -48
  289. package/dist/test/api-overloads.test.d.ts +0 -9
  290. package/dist/test/api-overloads.test.js +0 -330
  291. package/dist/test/apis.test.js +0 -408
  292. package/dist/test/auth.test.js +0 -708
  293. package/dist/test/batch-apis.test.js +0 -183
  294. package/dist/test/capabilities.test.js +0 -27
  295. package/dist/test/config-manager.test.js +0 -160
  296. package/dist/test/data-client-errors.test.js +0 -24
  297. package/dist/test/data-client-shape.test.js +0 -28
  298. package/dist/test/doover-client-dataclient.test.d.ts +0 -1
  299. package/dist/test/doover-client-dataclient.test.js +0 -58
  300. package/dist/test/doover-client-provenance.test.d.ts +0 -1
  301. package/dist/test/doover-client-provenance.test.js +0 -32
  302. package/dist/test/doover-client.test.d.ts +0 -1
  303. package/dist/test/doover-client.test.js +0 -42
  304. package/dist/test/doover-data-provider.test.d.ts +0 -1
  305. package/dist/test/doover-data-provider.test.js +0 -657
  306. package/dist/test/exports.test.d.ts +0 -1
  307. package/dist/test/exports.test.js +0 -80
  308. package/dist/test/gateway-client.test.d.ts +0 -1
  309. package/dist/test/gateway-client.test.js +0 -474
  310. package/dist/test/gateway-provenance.test.d.ts +0 -1
  311. package/dist/test/gateway-provenance.test.js +0 -29
  312. package/dist/test/gateway-subscriptions.test.d.ts +0 -1
  313. package/dist/test/gateway-subscriptions.test.js +0 -95
  314. package/dist/test/helpers.d.ts +0 -32
  315. package/dist/test/helpers.js +0 -115
  316. package/dist/test/local-agent-client.test.d.ts +0 -1
  317. package/dist/test/local-agent-client.test.js +0 -202
  318. package/dist/test/message-range-store.test.d.ts +0 -1
  319. package/dist/test/message-range-store.test.js +0 -183
  320. package/dist/test/multiplex-capabilities.test.d.ts +0 -1
  321. package/dist/test/multiplex-capabilities.test.js +0 -37
  322. package/dist/test/multiplex-conflicts.test.d.ts +0 -1
  323. package/dist/test/multiplex-conflicts.test.js +0 -35
  324. package/dist/test/multiplex-gateway.test.d.ts +0 -1
  325. package/dist/test/multiplex-gateway.test.js +0 -103
  326. package/dist/test/multiplex-merge.test.d.ts +0 -1
  327. package/dist/test/multiplex-merge.test.js +0 -19
  328. package/dist/test/multiplex-noncore.test.d.ts +0 -1
  329. package/dist/test/multiplex-noncore.test.js +0 -82
  330. package/dist/test/multiplex-passthrough.test.d.ts +0 -1
  331. package/dist/test/multiplex-passthrough.test.js +0 -35
  332. package/dist/test/multiplex-reads.test.d.ts +0 -1
  333. package/dist/test/multiplex-reads.test.js +0 -87
  334. package/dist/test/multiplex-registry.test.d.ts +0 -1
  335. package/dist/test/multiplex-registry.test.js +0 -81
  336. package/dist/test/multiplex-routing.test.d.ts +0 -1
  337. package/dist/test/multiplex-routing.test.js +0 -45
  338. package/dist/test/multiplex-status.test.d.ts +0 -1
  339. package/dist/test/multiplex-status.test.js +0 -63
  340. package/dist/test/multiplex-writes.test.d.ts +0 -1
  341. package/dist/test/multiplex-writes.test.js +0 -93
  342. package/dist/test/offline-cache.test.d.ts +0 -1
  343. package/dist/test/offline-cache.test.js +0 -289
  344. package/dist/test/provenance-regression.test.d.ts +0 -1
  345. package/dist/test/provenance-regression.test.js +0 -45
  346. package/dist/test/provenance-stamper.test.d.ts +0 -1
  347. package/dist/test/provenance-stamper.test.js +0 -41
  348. package/dist/test/provenance-type.test.d.ts +0 -1
  349. package/dist/test/provenance-type.test.js +0 -15
  350. package/dist/test/react-channel-messages-forward.test.d.ts +0 -1
  351. package/dist/test/react-channel-messages-forward.test.js +0 -139
  352. package/dist/test/react-channel-messages-range.test.d.ts +0 -1
  353. package/dist/test/react-channel-messages-range.test.js +0 -109
  354. package/dist/test/react-client-status.test.d.ts +0 -1
  355. package/dist/test/react-client-status.test.js +0 -35
  356. package/dist/test/react-dataclient.test.d.ts +0 -1
  357. package/dist/test/react-dataclient.test.js +0 -28
  358. package/dist/test/react-exports.test.d.ts +0 -1
  359. package/dist/test/react-exports.test.js +0 -46
  360. package/dist/test/react-multiagent-messages.test.d.ts +0 -1
  361. package/dist/test/react-multiagent-messages.test.js +0 -113
  362. package/dist/test/react-sources-option.test.d.ts +0 -1
  363. package/dist/test/react-sources-option.test.js +0 -41
  364. package/dist/test/react.test.d.ts +0 -1
  365. package/dist/test/react.test.js +0 -482
  366. package/dist/test/refine.test.d.ts +0 -1
  367. package/dist/test/refine.test.js +0 -71
  368. package/dist/test/rest-client.test.d.ts +0 -1
  369. package/dist/test/rest-client.test.js +0 -197
  370. package/dist/test/rpc-dispatcher.test.d.ts +0 -1
  371. package/dist/test/rpc-dispatcher.test.js +0 -251
  372. package/dist/test/singleton.test.d.ts +0 -1
  373. package/dist/test/singleton.test.js +0 -62
  374. package/dist/test/stats-rpc.test.d.ts +0 -1
  375. package/dist/test/stats-rpc.test.js +0 -69
  376. package/dist/test/status-tracker.test.d.ts +0 -1
  377. package/dist/test/status-tracker.test.js +0 -85
  378. package/dist/test/users-api.test.d.ts +0 -1
  379. package/dist/test/users-api.test.js +0 -19
  380. package/dist/test/utils.test.d.ts +0 -1
  381. package/dist/test/utils.test.js +0 -64
  382. /package/dist/{test/api-args.test.d.ts → esm/auth/auth-store.js} +0 -0
  383. /package/dist/{test/apis.test.d.ts → esm/client/data-client.js} +0 -0
  384. /package/dist/{test/auth.test.d.ts → esm/gateway/types.js} +0 -0
  385. /package/dist/{test/batch-apis.test.d.ts → esm/types/common.js} +0 -0
  386. /package/dist/{test/capabilities.test.d.ts → esm/types/index.js} +0 -0
  387. /package/dist/{test/config-manager.test.d.ts → esm/types/openapi.js} +0 -0
  388. /package/dist/{test/data-client-errors.test.d.ts → esm/types/provenance.js} +0 -0
  389. /package/dist/{test/data-client-shape.test.d.ts → esm/types/viewer.js} +0 -0
@@ -1,708 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const chai_1 = require("chai");
7
- const chai_as_promised_1 = __importDefault(require("chai-as-promised"));
8
- const mocha_1 = require("mocha");
9
- const sinon_1 = __importDefault(require("sinon"));
10
- const auth_profile_1 = require("../auth/auth-profile");
11
- const build_auth_1 = require("../auth/build-auth");
12
- const cookie_auth_1 = require("../auth/cookie-auth");
13
- const doover_token_auth_1 = require("../auth/doover-token-auth");
14
- const errors_1 = require("../auth/errors");
15
- const jwt_1 = require("../auth/jwt");
16
- const doover_client_1 = require("../client/doover-client");
17
- const gateway_client_1 = require("../gateway/gateway-client");
18
- const rest_client_1 = require("../http/rest-client");
19
- const helpers_1 = require("./helpers");
20
- (0, chai_1.use)(chai_as_promised_1.default);
21
- // ---------------------------------------------------------------------------
22
- // Helper: create a minimal JWT with a given `exp` claim
23
- // ---------------------------------------------------------------------------
24
- function makeJwt(exp) {
25
- const header = Buffer.from(JSON.stringify({ alg: "HS256" })).toString("base64url");
26
- const payload = Buffer.from(JSON.stringify({ exp })).toString("base64url");
27
- return `${header}.${payload}.fakesig`;
28
- }
29
- // ---------------------------------------------------------------------------
30
- // Helper: in-memory AuthProfileStore
31
- // ---------------------------------------------------------------------------
32
- class MemoryProfileStore {
33
- constructor() {
34
- this.currentProfile = null;
35
- this.current = null;
36
- this.profiles = new Map();
37
- this.writeCalled = 0;
38
- }
39
- get(name) {
40
- return this.profiles.get(name);
41
- }
42
- create(entry) {
43
- this.profiles.set(entry.profile, entry);
44
- }
45
- delete(name) {
46
- this.profiles.delete(name);
47
- }
48
- write() {
49
- this.writeCalled++;
50
- }
51
- }
52
- // ---------------------------------------------------------------------------
53
- // Helpers: cookie-auth session state
54
- // ---------------------------------------------------------------------------
55
- /** An `app.at_exp` cookie string expiring `secondsFromNow` from now. */
56
- function expiryCookie(secondsFromNow) {
57
- return `app.at_exp=${Math.floor(Date.now() / 1000) + secondsFromNow}`;
58
- }
59
- /** A refresh-capable CookieAuth over a fixed cookie string. */
60
- function cookieAuth(options) {
61
- return new cookie_auth_1.CookieAuth({
62
- authServerUrl: "https://auth.example.com",
63
- fetchImpl: (options.fetchMock ?? (0, helpers_1.createFetchMock)()),
64
- cookieReader: () => options.cookie,
65
- });
66
- }
67
- // ---------------------------------------------------------------------------
68
- // CookieAuth
69
- // ---------------------------------------------------------------------------
70
- (0, mocha_1.describe)("CookieAuth", () => {
71
- (0, mocha_1.it)("sends no auth header and uses credentials: include", async () => {
72
- const auth = new cookie_auth_1.CookieAuth();
73
- (0, chai_1.expect)(await auth.getHttpHeaders()).to.deep.equal({});
74
- (0, chai_1.expect)(auth.getFetchCredentials()).to.equal("include");
75
- });
76
- (0, mocha_1.it)("prepareWebSocket returns the URL unchanged", async () => {
77
- const auth = new cookie_auth_1.CookieAuth();
78
- const result = await auth.prepareWebSocket("wss://example.com/ws", true);
79
- (0, chai_1.expect)(result).to.deep.equal({ url: "wss://example.com/ws" });
80
- });
81
- (0, mocha_1.it)("ensureReady resolves immediately", async () => {
82
- const auth = new cookie_auth_1.CookieAuth();
83
- await auth.ensureReady(); // should not throw
84
- });
85
- (0, mocha_1.it)("does not refresh when no authServerUrl is configured", async () => {
86
- const fetchMock = (0, helpers_1.createFetchMock)();
87
- const auth = new cookie_auth_1.CookieAuth({
88
- fetchImpl: fetchMock,
89
- cookieReader: () => expiryCookie(-60),
90
- });
91
- (0, chai_1.expect)(await auth.handleUnauthorized()).to.equal(false);
92
- await auth.ensureReady();
93
- (0, chai_1.expect)(fetchMock.callCount).to.equal(0);
94
- });
95
- // -- Session inspection ---------------------------------------------------
96
- (0, mocha_1.it)("reads the expiry cookie", () => {
97
- const auth = cookieAuth({ cookie: expiryCookie(3600) });
98
- (0, chai_1.expect)(auth.isAccessTokenValid()).to.equal(true);
99
- (0, chai_1.expect)(auth.isAccessTokenStale()).to.equal(false);
100
- (0, chai_1.expect)(auth.getAccessTokenExpiry()).to.be.instanceOf(Date);
101
- });
102
- (0, mocha_1.it)("treats an expired cookie as invalid but refreshable", () => {
103
- const auth = cookieAuth({ cookie: expiryCookie(-60) });
104
- (0, chai_1.expect)(auth.isAccessTokenValid()).to.equal(false);
105
- (0, chai_1.expect)(auth.isAccessTokenStale()).to.equal(true);
106
- });
107
- (0, mocha_1.it)("reports a near-expiry token as stale while still valid", () => {
108
- const auth = cookieAuth({ cookie: expiryCookie(60) });
109
- (0, chai_1.expect)(auth.isAccessTokenValid()).to.equal(true);
110
- (0, chai_1.expect)(auth.isAccessTokenStale(5 * 60000)).to.equal(true);
111
- });
112
- (0, mocha_1.it)("reports no session when the cookie is absent", () => {
113
- const auth = cookieAuth({ cookie: "other=1" });
114
- (0, chai_1.expect)(auth.getAccessTokenExpiry()).to.equal(null);
115
- (0, chai_1.expect)(auth.isAccessTokenValid()).to.equal(false);
116
- // Nothing to refresh — must not read as "stale".
117
- (0, chai_1.expect)(auth.isAccessTokenStale()).to.equal(false);
118
- });
119
- (0, mocha_1.it)("ignores a non-numeric expiry cookie", () => {
120
- const auth = cookieAuth({ cookie: "app.at_exp=garbage" });
121
- (0, chai_1.expect)(auth.getAccessTokenExpiry()).to.equal(null);
122
- (0, chai_1.expect)(auth.isAccessTokenValid()).to.equal(false);
123
- });
124
- (0, mocha_1.it)("honours a custom expiry cookie name", () => {
125
- const auth = new cookie_auth_1.CookieAuth({
126
- authServerUrl: "https://auth.example.com",
127
- accessTokenExpiryCookieName: "custom.exp",
128
- cookieReader: () => `custom.exp=${Math.floor(Date.now() / 1000) + 3600}`,
129
- });
130
- (0, chai_1.expect)(auth.isAccessTokenValid()).to.equal(true);
131
- });
132
- // -- Refresh behaviour ----------------------------------------------------
133
- (0, mocha_1.it)("refreshes an expired token via the hosted-backend endpoint", async () => {
134
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({}));
135
- const auth = cookieAuth({ cookie: expiryCookie(-60), fetchMock });
136
- (0, chai_1.expect)(await auth.handleUnauthorized()).to.equal(true);
137
- (0, chai_1.expect)(fetchMock.callCount).to.equal(1);
138
- (0, chai_1.expect)(fetchMock.firstCall.args[0]).to.equal("https://auth.example.com/app/refresh/");
139
- const init = fetchMock.firstCall.args[1];
140
- (0, chai_1.expect)(init.method).to.equal("POST");
141
- (0, chai_1.expect)(init.credentials).to.equal("include");
142
- });
143
- (0, mocha_1.it)("honours a custom refresh path", async () => {
144
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({}));
145
- const auth = new cookie_auth_1.CookieAuth({
146
- authServerUrl: "https://auth.example.com",
147
- refreshPath: "/proxy/renew",
148
- fetchImpl: fetchMock,
149
- cookieReader: () => expiryCookie(-60),
150
- });
151
- await auth.refreshAccessToken();
152
- (0, chai_1.expect)(fetchMock.firstCall.args[0]).to.equal("https://auth.example.com/proxy/renew");
153
- });
154
- (0, mocha_1.it)("reports failure when the refresh endpoint rejects", async () => {
155
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({}, { status: 400 }));
156
- const auth = cookieAuth({ cookie: expiryCookie(-60), fetchMock });
157
- (0, chai_1.expect)(await auth.handleUnauthorized()).to.equal(false);
158
- });
159
- (0, mocha_1.it)("reports failure when the refresh request throws", async () => {
160
- const fetchMock = sinon_1.default.stub().rejects(new Error("offline"));
161
- const auth = cookieAuth({ cookie: expiryCookie(-60), fetchMock });
162
- (0, chai_1.expect)(await auth.handleUnauthorized()).to.equal(false);
163
- });
164
- (0, mocha_1.it)("skips the refresh call when there is no session cookie", async () => {
165
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({}));
166
- const auth = cookieAuth({ cookie: "", fetchMock });
167
- (0, chai_1.expect)(await auth.handleUnauthorized()).to.equal(false);
168
- (0, chai_1.expect)(fetchMock.callCount).to.equal(0);
169
- });
170
- (0, mocha_1.it)("collapses concurrent refreshes onto one request", async () => {
171
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({}));
172
- const auth = cookieAuth({ cookie: expiryCookie(-60), fetchMock });
173
- const results = await Promise.all([
174
- auth.handleUnauthorized(),
175
- auth.handleUnauthorized(),
176
- auth.handleUnauthorized(),
177
- ]);
178
- (0, chai_1.expect)(results).to.deep.equal([true, true, true]);
179
- (0, chai_1.expect)(fetchMock.callCount).to.equal(1);
180
- });
181
- (0, mocha_1.it)("reuses a recent failure instead of retrying in a loop", async () => {
182
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({}, { status: 400 }));
183
- const auth = cookieAuth({ cookie: expiryCookie(-60), fetchMock });
184
- (0, chai_1.expect)(await auth.handleUnauthorized()).to.equal(false);
185
- (0, chai_1.expect)(await auth.handleUnauthorized()).to.equal(false);
186
- (0, chai_1.expect)(await auth.handleUnauthorized()).to.equal(false);
187
- (0, chai_1.expect)(fetchMock.callCount).to.equal(1);
188
- });
189
- (0, mocha_1.it)("ensureReady refreshes an expired token before the request goes out", async () => {
190
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({}));
191
- const auth = cookieAuth({ cookie: expiryCookie(-60), fetchMock });
192
- await auth.ensureReady();
193
- (0, chai_1.expect)(fetchMock.callCount).to.equal(1);
194
- });
195
- (0, mocha_1.it)("ensureReady leaves a valid token alone", async () => {
196
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({}));
197
- const auth = cookieAuth({ cookie: expiryCookie(30), fetchMock });
198
- await auth.ensureReady();
199
- (0, chai_1.expect)(fetchMock.callCount).to.equal(0);
200
- });
201
- (0, mocha_1.it)("ensureReady does not reject when the refresh fails", async () => {
202
- const fetchMock = sinon_1.default.stub().rejects(new Error("offline"));
203
- const auth = cookieAuth({ cookie: expiryCookie(-60), fetchMock });
204
- await auth.ensureReady(); // should not throw
205
- });
206
- });
207
- // ---------------------------------------------------------------------------
208
- // DooverTokenAuth
209
- // ---------------------------------------------------------------------------
210
- (0, mocha_1.describe)("DooverTokenAuth", () => {
211
- (0, mocha_1.afterEach)(() => sinon_1.default.restore());
212
- (0, mocha_1.it)("sends bearer header and uses credentials: omit", async () => {
213
- const auth = new doover_token_auth_1.DooverTokenAuth({ token: "tok123" });
214
- (0, chai_1.expect)(await auth.getHttpHeaders()).to.deep.equal({
215
- Authorization: "Bearer tok123",
216
- });
217
- (0, chai_1.expect)(auth.getFetchCredentials()).to.equal("omit");
218
- });
219
- (0, mocha_1.it)("returns empty headers when no token is set", async () => {
220
- const auth = new doover_token_auth_1.DooverTokenAuth({});
221
- (0, chai_1.expect)(await auth.getHttpHeaders()).to.deep.equal({});
222
- });
223
- (0, mocha_1.it)("setToken updates the token", async () => {
224
- const auth = new doover_token_auth_1.DooverTokenAuth({ token: "old" });
225
- auth.setToken("new-token");
226
- (0, chai_1.expect)(await auth.getHttpHeaders()).to.deep.equal({
227
- Authorization: "Bearer new-token",
228
- });
229
- });
230
- (0, mocha_1.it)("setRefreshToken updates the refresh token used by ensureReady", async () => {
231
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({
232
- access_token: "new-access-token",
233
- expires_in: 3600,
234
- }));
235
- const auth = new doover_token_auth_1.DooverTokenAuth({
236
- token: null,
237
- authServerUrl: "https://auth.example.com",
238
- authServerClientId: "client-1",
239
- fetchImpl: fetchMock,
240
- });
241
- auth.setRefreshToken("new-refresh-token");
242
- await auth.ensureReady();
243
- (0, chai_1.expect)(fetchMock.callCount).to.equal(1);
244
- (0, chai_1.expect)(fetchMock.firstCall.args[0]).to.contain("refresh_token=new-refresh-token");
245
- (0, chai_1.expect)(await auth.getHttpHeaders()).to.deep.equal({
246
- Authorization: "Bearer new-access-token",
247
- });
248
- });
249
- // -- Refresh behaviour ----------------------------------------------------
250
- (0, mocha_1.it)("does not refresh when token is clearly valid", async () => {
251
- const farFuture = Date.now() + 3600000;
252
- const fetchMock = (0, helpers_1.createFetchMock)();
253
- const auth = new doover_token_auth_1.DooverTokenAuth({
254
- token: "valid",
255
- tokenExpires: new Date(farFuture),
256
- refreshToken: "rt",
257
- authServerUrl: "https://auth.example.com",
258
- authServerClientId: "client-1",
259
- fetchImpl: fetchMock,
260
- });
261
- await auth.ensureReady();
262
- (0, chai_1.expect)(fetchMock.callCount).to.equal(0);
263
- });
264
- (0, mocha_1.it)("triggers refresh when token is missing", async () => {
265
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({
266
- access_token: "new-tok",
267
- expires_in: 3600,
268
- }));
269
- const auth = new doover_token_auth_1.DooverTokenAuth({
270
- token: null,
271
- refreshToken: "rt",
272
- authServerUrl: "https://auth.example.com",
273
- authServerClientId: "client-1",
274
- fetchImpl: fetchMock,
275
- });
276
- await auth.ensureReady();
277
- (0, chai_1.expect)(fetchMock.callCount).to.equal(1);
278
- (0, chai_1.expect)(await auth.getHttpHeaders()).to.deep.equal({
279
- Authorization: "Bearer new-tok",
280
- });
281
- });
282
- (0, mocha_1.it)("triggers refresh within the 30-second expiry buffer", async () => {
283
- const almostExpired = Date.now() + 15000; // 15 s left
284
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({
285
- access_token: "refreshed-tok",
286
- expires_in: 3600,
287
- }));
288
- const auth = new doover_token_auth_1.DooverTokenAuth({
289
- token: "old-tok",
290
- tokenExpires: new Date(almostExpired),
291
- refreshToken: "rt",
292
- authServerUrl: "https://auth.example.com",
293
- authServerClientId: "client-1",
294
- fetchImpl: fetchMock,
295
- });
296
- await auth.ensureReady();
297
- (0, chai_1.expect)(fetchMock.callCount).to.equal(1);
298
- (0, chai_1.expect)(await auth.getHttpHeaders()).to.deep.equal({
299
- Authorization: "Bearer refreshed-tok",
300
- });
301
- });
302
- (0, mocha_1.it)("throws DooverAuthError when refresh metadata is incomplete", async () => {
303
- const auth = new doover_token_auth_1.DooverTokenAuth({
304
- token: null,
305
- // No refreshToken, authServerUrl, or authServerClientId
306
- });
307
- await (0, chai_1.expect)(auth.ensureReady()).to.be.rejectedWith(errors_1.DooverAuthError, /missing authServerUrl/);
308
- });
309
- (0, mocha_1.it)("throws DooverAuthError when refresh HTTP request fails", async () => {
310
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({ error: "invalid_grant" }, { status: 400 }));
311
- const auth = new doover_token_auth_1.DooverTokenAuth({
312
- token: null,
313
- refreshToken: "rt",
314
- authServerUrl: "https://auth.example.com",
315
- authServerClientId: "client-1",
316
- fetchImpl: fetchMock,
317
- });
318
- await (0, chai_1.expect)(auth.ensureReady()).to.be.rejectedWith(errors_1.DooverAuthError, /status 400/);
319
- });
320
- (0, mocha_1.it)("writes refreshed token back to the attached ConfigManager", async () => {
321
- const store = new MemoryProfileStore();
322
- const profile = new auth_profile_1.AuthProfile({
323
- profile: "test",
324
- refreshToken: "rt",
325
- authServerUrl: "https://auth.example.com",
326
- authServerClientId: "client-1",
327
- });
328
- store.create(profile);
329
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({
330
- access_token: "refreshed",
331
- expires_in: 3600,
332
- refresh_token: "new-rt",
333
- }));
334
- // Construct with no token so refresh is triggered
335
- const auth = new doover_token_auth_1.DooverTokenAuth({
336
- refreshToken: "rt",
337
- authServerUrl: "https://auth.example.com",
338
- authServerClientId: "client-1",
339
- fetchImpl: fetchMock,
340
- });
341
- auth.attachProfile(profile, store);
342
- await auth.ensureReady();
343
- (0, chai_1.expect)(profile.token).to.equal("refreshed");
344
- (0, chai_1.expect)(profile.refreshToken).to.equal("new-rt");
345
- (0, chai_1.expect)(store.writeCalled).to.equal(1);
346
- });
347
- // -- WebSocket auth -------------------------------------------------------
348
- (0, mocha_1.it)("prepareWebSocket uses Authorization header when canUseHeaders is true", async () => {
349
- const auth = new doover_token_auth_1.DooverTokenAuth({ token: "ws-tok" });
350
- const result = await auth.prepareWebSocket("wss://ws.example.com", true);
351
- (0, chai_1.expect)(result.url).to.equal("wss://ws.example.com");
352
- (0, chai_1.expect)(result.headers).to.deep.equal({
353
- Authorization: "Bearer ws-tok",
354
- });
355
- });
356
- (0, mocha_1.it)("prepareWebSocket appends ?token= when canUseHeaders is false", async () => {
357
- const auth = new doover_token_auth_1.DooverTokenAuth({ token: "ws-tok" });
358
- const result = await auth.prepareWebSocket("wss://ws.example.com/path", false);
359
- (0, chai_1.expect)(result.url).to.equal("wss://ws.example.com/path?token=ws-tok");
360
- (0, chai_1.expect)(result.headers).to.be.undefined;
361
- });
362
- });
363
- // ---------------------------------------------------------------------------
364
- // JWT expiry decoding
365
- // ---------------------------------------------------------------------------
366
- (0, mocha_1.describe)("JWT decodeTokenExpiry", () => {
367
- (0, mocha_1.it)("decodes token exp claim", () => {
368
- const exp = Math.floor(Date.now() / 1000) + 3600;
369
- const token = makeJwt(exp);
370
- const result = (0, jwt_1.decodeTokenExpiry)(token);
371
- (0, chai_1.expect)(result).to.be.instanceOf(Date);
372
- (0, chai_1.expect)(result.getTime()).to.equal(exp * 1000);
373
- });
374
- (0, mocha_1.it)("returns null for tokens without exp", () => {
375
- const header = Buffer.from(JSON.stringify({ alg: "HS256" })).toString("base64url");
376
- const payload = Buffer.from(JSON.stringify({ sub: "user" })).toString("base64url");
377
- (0, chai_1.expect)((0, jwt_1.decodeTokenExpiry)(`${header}.${payload}.sig`)).to.equal(null);
378
- });
379
- (0, mocha_1.it)("returns null for malformed tokens", () => {
380
- (0, chai_1.expect)((0, jwt_1.decodeTokenExpiry)("not-a-jwt")).to.equal(null);
381
- (0, chai_1.expect)((0, jwt_1.decodeTokenExpiry)("")).to.equal(null);
382
- });
383
- });
384
- // ---------------------------------------------------------------------------
385
- // AuthProfile parse / dump
386
- // ---------------------------------------------------------------------------
387
- (0, mocha_1.describe)("AuthProfile", () => {
388
- (0, mocha_1.it)("parses reduced-format config lines", () => {
389
- const lines = [
390
- "TOKEN=abc123",
391
- "TOKEN_EXPIRES=2026-01-01T00:00:00.000Z",
392
- "AGENT_ID=agent-1",
393
- "BASE_URL=https://control.example.com",
394
- "BASE_DATA_URL=https://data.example.com",
395
- "REFRESH_TOKEN=rt-xyz",
396
- "REFRESH_TOKEN_ID=rti-1",
397
- "AUTH_SERVER_URL=https://auth.example.com",
398
- "AUTH_SERVER_CLIENT_ID=client-1",
399
- ];
400
- const profile = auth_profile_1.AuthProfile.parse("prod", lines);
401
- (0, chai_1.expect)(profile.profile).to.equal("prod");
402
- (0, chai_1.expect)(profile.token).to.equal("abc123");
403
- (0, chai_1.expect)(profile.tokenExpires).to.equal("2026-01-01T00:00:00.000Z");
404
- (0, chai_1.expect)(profile.agentId).to.equal("agent-1");
405
- (0, chai_1.expect)(profile.controlBaseUrl).to.equal("https://control.example.com");
406
- (0, chai_1.expect)(profile.dataBaseUrl).to.equal("https://data.example.com");
407
- (0, chai_1.expect)(profile.refreshToken).to.equal("rt-xyz");
408
- (0, chai_1.expect)(profile.refreshTokenId).to.equal("rti-1");
409
- (0, chai_1.expect)(profile.authServerUrl).to.equal("https://auth.example.com");
410
- (0, chai_1.expect)(profile.authServerClientId).to.equal("client-1");
411
- });
412
- (0, mocha_1.it)("dumps back to the same reduced format", () => {
413
- const profile = new auth_profile_1.AuthProfile({
414
- profile: "test",
415
- token: "tok",
416
- agentId: "a1",
417
- refreshToken: "rt",
418
- });
419
- const dumped = profile.dump();
420
- (0, chai_1.expect)(dumped).to.include("TOKEN=tok");
421
- (0, chai_1.expect)(dumped).to.include("AGENT_ID=a1");
422
- (0, chai_1.expect)(dumped).to.include("REFRESH_TOKEN=rt");
423
- // Null fields should be absent
424
- (0, chai_1.expect)(dumped).not.to.include("TOKEN_EXPIRES");
425
- (0, chai_1.expect)(dumped).not.to.include("BASE_URL");
426
- });
427
- (0, mocha_1.it)("dumpBlock includes the [profile=...] header", () => {
428
- const profile = new auth_profile_1.AuthProfile({ profile: "dev", token: "t1" });
429
- const block = profile.dumpBlock();
430
- (0, chai_1.expect)(block).to.match(/^\[profile=dev\]/);
431
- (0, chai_1.expect)(block).to.include("TOKEN=t1");
432
- });
433
- });
434
- // ---------------------------------------------------------------------------
435
- // buildAuth
436
- // ---------------------------------------------------------------------------
437
- (0, mocha_1.describe)("buildAuth", () => {
438
- (0, mocha_1.it)("returns provided auth as-is", () => {
439
- const auth = new cookie_auth_1.CookieAuth();
440
- (0, chai_1.expect)((0, build_auth_1.buildAuth)({ auth })).to.equal(auth);
441
- });
442
- (0, mocha_1.it)("throws when auth is combined with raw auth config", () => {
443
- const auth = new cookie_auth_1.CookieAuth();
444
- (0, chai_1.expect)(() => (0, build_auth_1.buildAuth)({ auth, token: "tok" })).to.throw(errors_1.DooverAuthError, /Cannot combine/);
445
- });
446
- (0, mocha_1.it)("builds CookieAuth when no token-related input is present", () => {
447
- (0, chai_1.expect)((0, build_auth_1.buildAuth)({})).to.be.instanceOf(cookie_auth_1.CookieAuth);
448
- });
449
- (0, mocha_1.it)("builds a refresh-capable CookieAuth from authServerUrl alone", async () => {
450
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({}));
451
- const auth = (0, build_auth_1.buildAuth)({
452
- authServerUrl: "https://auth.example.com",
453
- fetchImpl: fetchMock,
454
- });
455
- // authServerUrl says where to refresh; it is not token material, so this
456
- // stays cookie auth rather than becoming a tokenless DooverTokenAuth.
457
- (0, chai_1.expect)(auth).to.be.instanceOf(cookie_auth_1.CookieAuth);
458
- (0, chai_1.expect)(await auth.handleUnauthorized()).to.equal(false); // no session cookie
459
- });
460
- (0, mocha_1.it)("still builds DooverTokenAuth when token material accompanies authServerUrl", () => {
461
- const auth = (0, build_auth_1.buildAuth)({
462
- authServerUrl: "https://auth.example.com",
463
- refreshToken: "rt",
464
- });
465
- (0, chai_1.expect)(auth).to.be.instanceOf(doover_token_auth_1.DooverTokenAuth);
466
- });
467
- (0, mocha_1.it)("builds DooverTokenAuth when token is provided", () => {
468
- const auth = (0, build_auth_1.buildAuth)({ token: "tok" });
469
- (0, chai_1.expect)(auth).to.be.instanceOf(doover_token_auth_1.DooverTokenAuth);
470
- });
471
- (0, mocha_1.it)("builds DooverTokenAuth from an AuthProfile with token", () => {
472
- const profile = new auth_profile_1.AuthProfile({ profile: "test", token: "t1" });
473
- const auth = (0, build_auth_1.buildAuth)({ profile });
474
- (0, chai_1.expect)(auth).to.be.instanceOf(doover_token_auth_1.DooverTokenAuth);
475
- });
476
- (0, mocha_1.it)("explicit raw fields override profile-loaded values", async () => {
477
- const profile = new auth_profile_1.AuthProfile({ profile: "test", token: "profile-tok" });
478
- const auth = (0, build_auth_1.buildAuth)({ profile, token: "override-tok" });
479
- (0, chai_1.expect)(auth).to.be.instanceOf(doover_token_auth_1.DooverTokenAuth);
480
- (0, chai_1.expect)(await auth.getHttpHeaders()).to.deep.equal({
481
- Authorization: "Bearer override-tok",
482
- });
483
- });
484
- (0, mocha_1.it)("resolves a string profile via configManager", () => {
485
- const store = new MemoryProfileStore();
486
- store.create(new auth_profile_1.AuthProfile({ profile: "staging", token: "st" }));
487
- const auth = (0, build_auth_1.buildAuth)({ profile: "staging", configManager: store });
488
- (0, chai_1.expect)(auth).to.be.instanceOf(doover_token_auth_1.DooverTokenAuth);
489
- });
490
- (0, mocha_1.it)("throws when profile is a string without configManager", () => {
491
- (0, chai_1.expect)(() => (0, build_auth_1.buildAuth)({ profile: "staging" })).to.throw(errors_1.DooverAuthError, /configManager/);
492
- });
493
- (0, mocha_1.it)("throws when string profile is not found in configManager", () => {
494
- const store = new MemoryProfileStore();
495
- (0, chai_1.expect)(() => (0, build_auth_1.buildAuth)({ profile: "nope", configManager: store })).to.throw(errors_1.DooverAuthError, /not found/);
496
- });
497
- });
498
- // ---------------------------------------------------------------------------
499
- // DooverClient shared auth instance
500
- // ---------------------------------------------------------------------------
501
- (0, mocha_1.describe)("DooverClient auth sharing", () => {
502
- (0, mocha_1.beforeEach)(() => {
503
- (0, helpers_1.installSessionStorageMock)();
504
- helpers_1.MockWebSocket.reset();
505
- Object.defineProperty(globalThis, "WebSocket", {
506
- value: helpers_1.MockWebSocket,
507
- configurable: true,
508
- writable: true,
509
- });
510
- });
511
- (0, mocha_1.it)("shares one auth instance across REST and gateway", () => {
512
- const client = new doover_client_1.DooverClient({
513
- dataRestUrl: "https://api.example.com",
514
- controlApiUrl: "https://control.example.com",
515
- dataWssUrl: "wss://ws.example.com",
516
- token: "shared-tok",
517
- fetchImpl: (0, helpers_1.createFetchMock)(),
518
- webSocketImpl: helpers_1.MockWebSocket,
519
- });
520
- (0, chai_1.expect)(client.auth).to.be.instanceOf(doover_token_auth_1.DooverTokenAuth);
521
- (0, chai_1.expect)(client.rest.auth).to.equal(client.auth);
522
- // viewer's internal rest and gateway should also share the same auth
523
- (0, chai_1.expect)(client.viewer.rest.auth).to.equal(client.auth);
524
- });
525
- (0, mocha_1.it)("defaults to CookieAuth when no auth inputs are provided", () => {
526
- const client = new doover_client_1.DooverClient({
527
- dataRestUrl: "https://api.example.com",
528
- controlApiUrl: "https://control.example.com",
529
- dataWssUrl: "wss://ws.example.com",
530
- fetchImpl: (0, helpers_1.createFetchMock)(),
531
- webSocketImpl: helpers_1.MockWebSocket,
532
- });
533
- (0, chai_1.expect)(client.auth).to.be.instanceOf(cookie_auth_1.CookieAuth);
534
- });
535
- });
536
- // ---------------------------------------------------------------------------
537
- // GatewayClient auth integration
538
- // ---------------------------------------------------------------------------
539
- (0, mocha_1.describe)("GatewayClient auth integration", () => {
540
- (0, mocha_1.beforeEach)(() => {
541
- helpers_1.MockWebSocket.reset();
542
- Object.defineProperty(globalThis, "WebSocket", {
543
- value: helpers_1.MockWebSocket,
544
- configurable: true,
545
- writable: true,
546
- });
547
- });
548
- (0, mocha_1.afterEach)(() => sinon_1.default.restore());
549
- (0, mocha_1.it)("appends ?token= when using token auth without webSocketFactory", async () => {
550
- const auth = new doover_token_auth_1.DooverTokenAuth({ token: "gw-tok" });
551
- const gw = new gateway_client_1.GatewayClient({
552
- dataRestUrl: "https://api.example.com",
553
- controlApiUrl: "https://control.example.com",
554
- dataWssUrl: "wss://ws.example.com",
555
- webSocketImpl: helpers_1.MockWebSocket,
556
- }, auth);
557
- await gw.connect();
558
- const ws = helpers_1.MockWebSocket.instances[0];
559
- (0, chai_1.expect)(ws.url).to.equal("wss://ws.example.com/?token=gw-tok");
560
- });
561
- (0, mocha_1.it)("uses webSocketFactory with Authorization header for token auth", async () => {
562
- const auth = new doover_token_auth_1.DooverTokenAuth({ token: "factory-tok" });
563
- let capturedHeaders;
564
- const factory = (opts) => {
565
- capturedHeaders = opts.headers;
566
- return new helpers_1.MockWebSocket(opts.url);
567
- };
568
- const gw = new gateway_client_1.GatewayClient({
569
- dataRestUrl: "https://api.example.com",
570
- controlApiUrl: "https://control.example.com",
571
- dataWssUrl: "wss://ws.example.com",
572
- webSocketFactory: factory,
573
- }, auth);
574
- await gw.connect();
575
- (0, chai_1.expect)(capturedHeaders).to.deep.equal({
576
- Authorization: "Bearer factory-tok",
577
- });
578
- // URL should NOT have the token query param
579
- const ws = helpers_1.MockWebSocket.instances[0];
580
- (0, chai_1.expect)(ws.url).to.equal("wss://ws.example.com");
581
- });
582
- (0, mocha_1.it)("cookie auth leaves websocket URL unchanged", async () => {
583
- const auth = new cookie_auth_1.CookieAuth();
584
- const gw = new gateway_client_1.GatewayClient({
585
- dataRestUrl: "https://api.example.com",
586
- controlApiUrl: "https://control.example.com",
587
- dataWssUrl: "wss://ws.example.com",
588
- webSocketImpl: helpers_1.MockWebSocket,
589
- }, auth);
590
- await gw.connect();
591
- const ws = helpers_1.MockWebSocket.instances[0];
592
- (0, chai_1.expect)(ws.url).to.equal("wss://ws.example.com");
593
- });
594
- (0, mocha_1.it)("reconnect uses newly refreshed token", async () => {
595
- let callCount = 0;
596
- const fetchMock = (0, helpers_1.createFetchMock)(() => {
597
- callCount++;
598
- return (0, helpers_1.createJsonResponse)({
599
- access_token: `refreshed-${callCount}`,
600
- expires_in: 3600,
601
- });
602
- });
603
- const auth = new doover_token_auth_1.DooverTokenAuth({
604
- token: null,
605
- refreshToken: "rt",
606
- authServerUrl: "https://auth.example.com",
607
- authServerClientId: "c1",
608
- fetchImpl: fetchMock,
609
- });
610
- const gw = new gateway_client_1.GatewayClient({
611
- dataRestUrl: "https://api.example.com",
612
- controlApiUrl: "https://control.example.com",
613
- dataWssUrl: "wss://ws.example.com",
614
- webSocketImpl: helpers_1.MockWebSocket,
615
- }, auth);
616
- await gw.connect();
617
- const ws1 = helpers_1.MockWebSocket.instances[0];
618
- (0, chai_1.expect)(ws1.url).to.include("token=refreshed-1");
619
- // Simulate disconnect + reconnect
620
- gw.disconnect();
621
- // Clear the token to force a re-refresh
622
- auth.setToken(null);
623
- await gw.connect();
624
- const ws2 = helpers_1.MockWebSocket.instances[1];
625
- (0, chai_1.expect)(ws2.url).to.include("token=refreshed-2");
626
- });
627
- });
628
- // ---------------------------------------------------------------------------
629
- // RestClient auth integration
630
- // ---------------------------------------------------------------------------
631
- (0, mocha_1.describe)("RestClient auth integration", () => {
632
- (0, mocha_1.beforeEach)(() => (0, helpers_1.installSessionStorageMock)());
633
- (0, mocha_1.it)("sends Authorization header with token auth", async () => {
634
- const auth = new doover_token_auth_1.DooverTokenAuth({ token: "rest-tok" });
635
- const fetchMock = (0, helpers_1.createFetchMock)();
636
- const client = new rest_client_1.RestClient({
637
- dataRestUrl: "https://api.example.com",
638
- controlApiUrl: "https://control.example.com",
639
- dataWssUrl: "wss://ws.example.com",
640
- fetchImpl: fetchMock,
641
- }, auth);
642
- await client.get("/items");
643
- const [, init] = fetchMock.getCall(0).args;
644
- const headers = init?.headers;
645
- (0, chai_1.expect)(headers.get("Authorization")).to.equal("Bearer rest-tok");
646
- (0, chai_1.expect)(init?.credentials).to.equal("omit");
647
- });
648
- (0, mocha_1.it)("uses credentials: include with cookie auth", async () => {
649
- const auth = new cookie_auth_1.CookieAuth();
650
- const fetchMock = (0, helpers_1.createFetchMock)();
651
- const client = new rest_client_1.RestClient({
652
- dataRestUrl: "https://api.example.com",
653
- controlApiUrl: "https://control.example.com",
654
- dataWssUrl: "wss://ws.example.com",
655
- fetchImpl: fetchMock,
656
- }, auth);
657
- await client.get("/items");
658
- const [, init] = fetchMock.getCall(0).args;
659
- const headers = init?.headers;
660
- (0, chai_1.expect)(headers.get("Authorization")).to.equal(null);
661
- (0, chai_1.expect)(init?.credentials).to.equal("include");
662
- });
663
- (0, mocha_1.it)("refreshes and replays a 401 with refresh-capable cookie auth", async () => {
664
- let itemsCalls = 0;
665
- const fetchMock = (0, helpers_1.createFetchMock)((url) => {
666
- if (url === "https://auth.example.com/app/refresh/") {
667
- return (0, helpers_1.createJsonResponse)({});
668
- }
669
- itemsCalls += 1;
670
- // First attempt uses the dead cookie; the replay succeeds.
671
- return itemsCalls === 1
672
- ? (0, helpers_1.createJsonResponse)({ detail: "expired" }, { status: 401 })
673
- : (0, helpers_1.createJsonResponse)({ items: [] });
674
- });
675
- const auth = cookieAuth({ cookie: expiryCookie(-60), fetchMock });
676
- const client = new rest_client_1.RestClient({
677
- dataRestUrl: "https://api.example.com",
678
- controlApiUrl: "https://control.example.com",
679
- dataWssUrl: "wss://ws.example.com",
680
- fetchImpl: fetchMock,
681
- }, auth);
682
- const result = await client.get("/items");
683
- (0, chai_1.expect)(result).to.deep.equal({ items: [] });
684
- (0, chai_1.expect)(itemsCalls).to.equal(2);
685
- });
686
- (0, mocha_1.it)("surfaces the 401 when cookie auth cannot refresh", async () => {
687
- const fetchMock = (0, helpers_1.createFetchMock)(() => (0, helpers_1.createJsonResponse)({ detail: "expired" }, { status: 401 }));
688
- const client = new rest_client_1.RestClient({
689
- dataRestUrl: "https://api.example.com",
690
- controlApiUrl: "https://control.example.com",
691
- dataWssUrl: "wss://ws.example.com",
692
- fetchImpl: fetchMock,
693
- }, new cookie_auth_1.CookieAuth());
694
- await (0, chai_1.expect)(client.get("/items")).to.be.rejected;
695
- });
696
- (0, mocha_1.it)("uses credentials: include when no auth is provided (backward compat)", async () => {
697
- const fetchMock = (0, helpers_1.createFetchMock)();
698
- const client = new rest_client_1.RestClient({
699
- dataRestUrl: "https://api.example.com",
700
- controlApiUrl: "https://control.example.com",
701
- dataWssUrl: "wss://ws.example.com",
702
- fetchImpl: fetchMock,
703
- });
704
- await client.get("/items");
705
- const [, init] = fetchMock.getCall(0).args;
706
- (0, chai_1.expect)(init?.credentials).to.equal("include");
707
- });
708
- });