doover-js 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/README.md +146 -0
  2. package/dist/apis/_args.d.ts +16 -0
  3. package/dist/apis/_args.js +26 -0
  4. package/dist/apis/agents-api.d.ts +4 -1
  5. package/dist/apis/agents-api.js +139 -1
  6. package/dist/apis/aggregates-api.d.ts +23 -3
  7. package/dist/apis/aggregates-api.js +33 -4
  8. package/dist/apis/alarms-api.d.ts +30 -0
  9. package/dist/apis/alarms-api.js +51 -6
  10. package/dist/apis/channels-api.d.ts +40 -3
  11. package/dist/apis/channels-api.js +50 -5
  12. package/dist/apis/connections-api.d.ts +21 -5
  13. package/dist/apis/connections-api.js +26 -10
  14. package/dist/apis/messages-api.d.ts +54 -9
  15. package/dist/apis/messages-api.js +94 -12
  16. package/dist/apis/notifications-api.d.ts +52 -0
  17. package/dist/apis/notifications-api.js +99 -13
  18. package/dist/apis/permissions-api.d.ts +8 -0
  19. package/dist/apis/permissions-api.js +11 -2
  20. package/dist/apis/processors-api.d.ts +35 -0
  21. package/dist/apis/processors-api.js +64 -8
  22. package/dist/apis/users-api.d.ts +8 -0
  23. package/dist/apis/users-api.js +13 -0
  24. package/dist/client/capabilities.d.ts +10 -0
  25. package/dist/client/capabilities.js +43 -0
  26. package/dist/client/data-client.d.ts +104 -0
  27. package/dist/client/data-client.js +2 -0
  28. package/dist/client/doover-client.d.ts +31 -31
  29. package/dist/client/doover-client.js +58 -37
  30. package/dist/client/errors.d.ts +23 -0
  31. package/dist/client/errors.js +50 -0
  32. package/dist/client/local-agent-client.d.ts +65 -0
  33. package/dist/client/local-agent-client.js +222 -0
  34. package/dist/client/multiplex-client.d.ts +151 -0
  35. package/dist/client/multiplex-client.js +744 -0
  36. package/dist/client/multiplex-gateway.d.ts +49 -0
  37. package/dist/client/multiplex-gateway.js +114 -0
  38. package/dist/client/multiplex-merge.d.ts +12 -0
  39. package/dist/client/multiplex-merge.js +42 -0
  40. package/dist/client/provenance.d.ts +60 -0
  41. package/dist/client/provenance.js +113 -0
  42. package/dist/client/stats.d.ts +24 -0
  43. package/dist/client/stats.js +62 -0
  44. package/dist/client/status-tracker.d.ts +24 -0
  45. package/dist/client/status-tracker.js +90 -0
  46. package/dist/gateway/gateway-client.d.ts +23 -1
  47. package/dist/gateway/gateway-client.js +75 -6
  48. package/dist/http/rest-client.d.ts +5 -0
  49. package/dist/index.d.ts +15 -0
  50. package/dist/index.js +22 -7
  51. package/dist/react/context.d.ts +9 -5
  52. package/dist/react/context.js +6 -2
  53. package/dist/react/index.d.ts +3 -0
  54. package/dist/react/index.js +3 -1
  55. package/dist/react/useChannelAggregate.d.ts +8 -1
  56. package/dist/react/useChannelAggregate.js +24 -6
  57. package/dist/react/useChannelMessage.d.ts +8 -1
  58. package/dist/react/useChannelMessage.js +17 -6
  59. package/dist/react/useChannelMessages.d.ts +8 -1
  60. package/dist/react/useChannelMessages.js +21 -7
  61. package/dist/react/useChannelSubscription.d.ts +6 -0
  62. package/dist/react/useChannelSubscription.js +8 -18
  63. package/dist/react/useClientStatus.d.ts +10 -0
  64. package/dist/react/useClientStatus.js +22 -0
  65. package/dist/react/useConnectionState.d.ts +5 -0
  66. package/dist/react/useConnectionState.js +5 -0
  67. package/dist/react/useMultiAgentAggregates.d.ts +8 -1
  68. package/dist/react/useMultiAgentAggregates.js +25 -21
  69. package/dist/react/useMultiAgentChannelMessages.d.ts +8 -1
  70. package/dist/react/useMultiAgentChannelMessages.js +23 -18
  71. package/dist/react/useSendMessage.d.ts +8 -1
  72. package/dist/react/useSendMessage.js +15 -2
  73. package/dist/react/useSendRpc.js +4 -1
  74. package/dist/react/useUpdateAggregate.d.ts +6 -0
  75. package/dist/react/useUpdateAggregate.js +20 -4
  76. package/dist/react/useUpdateMessage.d.ts +5 -0
  77. package/dist/react/useUpdateMessage.js +11 -2
  78. package/dist/rpc/errors.d.ts +10 -0
  79. package/dist/rpc/errors.js +23 -0
  80. package/dist/rpc/rpc-dispatcher.d.ts +28 -0
  81. package/dist/rpc/rpc-dispatcher.js +129 -0
  82. package/dist/test/api-args.test.d.ts +1 -0
  83. package/dist/test/api-args.test.js +48 -0
  84. package/dist/test/api-overloads.test.d.ts +9 -0
  85. package/dist/test/api-overloads.test.js +276 -0
  86. package/dist/test/capabilities.test.d.ts +1 -0
  87. package/dist/test/capabilities.test.js +27 -0
  88. package/dist/test/data-client-errors.test.d.ts +1 -0
  89. package/dist/test/data-client-errors.test.js +24 -0
  90. package/dist/test/data-client-shape.test.d.ts +1 -0
  91. package/dist/test/data-client-shape.test.js +28 -0
  92. package/dist/test/doover-client-dataclient.test.d.ts +1 -0
  93. package/dist/test/doover-client-dataclient.test.js +58 -0
  94. package/dist/test/doover-client-provenance.test.d.ts +1 -0
  95. package/dist/test/doover-client-provenance.test.js +32 -0
  96. package/dist/test/exports.test.d.ts +1 -0
  97. package/dist/test/exports.test.js +76 -0
  98. package/dist/test/gateway-provenance.test.d.ts +1 -0
  99. package/dist/test/gateway-provenance.test.js +29 -0
  100. package/dist/test/gateway-subscriptions.test.d.ts +1 -0
  101. package/dist/test/gateway-subscriptions.test.js +95 -0
  102. package/dist/test/local-agent-client.test.d.ts +1 -0
  103. package/dist/test/local-agent-client.test.js +202 -0
  104. package/dist/test/multiplex-capabilities.test.d.ts +1 -0
  105. package/dist/test/multiplex-capabilities.test.js +37 -0
  106. package/dist/test/multiplex-conflicts.test.d.ts +1 -0
  107. package/dist/test/multiplex-conflicts.test.js +35 -0
  108. package/dist/test/multiplex-gateway.test.d.ts +1 -0
  109. package/dist/test/multiplex-gateway.test.js +103 -0
  110. package/dist/test/multiplex-merge.test.d.ts +1 -0
  111. package/dist/test/multiplex-merge.test.js +19 -0
  112. package/dist/test/multiplex-noncore.test.d.ts +1 -0
  113. package/dist/test/multiplex-noncore.test.js +82 -0
  114. package/dist/test/multiplex-passthrough.test.d.ts +1 -0
  115. package/dist/test/multiplex-passthrough.test.js +35 -0
  116. package/dist/test/multiplex-reads.test.d.ts +1 -0
  117. package/dist/test/multiplex-reads.test.js +87 -0
  118. package/dist/test/multiplex-registry.test.d.ts +1 -0
  119. package/dist/test/multiplex-registry.test.js +81 -0
  120. package/dist/test/multiplex-routing.test.d.ts +1 -0
  121. package/dist/test/multiplex-routing.test.js +45 -0
  122. package/dist/test/multiplex-status.test.d.ts +1 -0
  123. package/dist/test/multiplex-status.test.js +63 -0
  124. package/dist/test/multiplex-writes.test.d.ts +1 -0
  125. package/dist/test/multiplex-writes.test.js +93 -0
  126. package/dist/test/provenance-regression.test.d.ts +1 -0
  127. package/dist/test/provenance-regression.test.js +45 -0
  128. package/dist/test/provenance-stamper.test.d.ts +1 -0
  129. package/dist/test/provenance-stamper.test.js +41 -0
  130. package/dist/test/provenance-type.test.d.ts +1 -0
  131. package/dist/test/provenance-type.test.js +15 -0
  132. package/dist/test/react-client-status.test.d.ts +1 -0
  133. package/dist/test/react-client-status.test.js +35 -0
  134. package/dist/test/react-dataclient.test.d.ts +1 -0
  135. package/dist/test/react-dataclient.test.js +28 -0
  136. package/dist/test/react-exports.test.d.ts +1 -0
  137. package/dist/test/react-exports.test.js +45 -0
  138. package/dist/test/react-sources-option.test.d.ts +1 -0
  139. package/dist/test/react-sources-option.test.js +41 -0
  140. package/dist/test/react.test.js +2 -2
  141. package/dist/test/rpc-dispatcher.test.d.ts +1 -0
  142. package/dist/test/rpc-dispatcher.test.js +190 -0
  143. package/dist/test/stats-rpc.test.d.ts +1 -0
  144. package/dist/test/stats-rpc.test.js +69 -0
  145. package/dist/test/status-tracker.test.d.ts +1 -0
  146. package/dist/test/status-tracker.test.js +85 -0
  147. package/dist/test/users-api.test.d.ts +1 -0
  148. package/dist/test/users-api.test.js +19 -0
  149. package/dist/types/common.d.ts +18 -1
  150. package/dist/types/openapi.d.ts +1 -0
  151. package/dist/types/provenance.d.ts +45 -0
  152. package/dist/types/provenance.js +2 -0
  153. package/dist/types/viewer.d.ts +3 -0
  154. package/dist/viewer/doover-data-provider.d.ts +30 -34
  155. package/dist/viewer/doover-data-provider.js +82 -316
  156. package/package.json +1 -1
@@ -6,113 +6,50 @@ const aggregates_api_1 = require("../apis/aggregates-api");
6
6
  const channels_api_1 = require("../apis/channels-api");
7
7
  const connections_api_1 = require("../apis/connections-api");
8
8
  const messages_api_1 = require("../apis/messages-api");
9
+ const users_api_1 = require("../apis/users-api");
9
10
  const gateway_client_1 = require("../gateway/gateway-client");
10
11
  const errors_1 = require("../http/errors");
11
12
  const rest_client_1 = require("../http/rest-client");
12
- const snowflake_1 = require("../utils/snowflake");
13
+ const rpc_dispatcher_1 = require("../rpc/rpc-dispatcher");
13
14
  const path_parsing_1 = require("./path-parsing");
14
- function isRpcMessageData(data) {
15
- return (typeof data === "object" &&
16
- data !== null &&
17
- "status" in data &&
18
- "method" in data &&
19
- "request" in data);
20
- }
21
- function isPlainObject(value) {
22
- return (typeof value === "object" &&
23
- value !== null &&
24
- !Array.isArray(value));
25
- }
15
+ /** @deprecated Use DooverClient subclients directly. Removed in 0.6.0. */
26
16
  class DooverDataProvider {
27
- constructor(config, auth) {
28
- this.config = config;
29
- this.subscriptions = new Map();
30
- this.rest = new rest_client_1.RestClient(config, auth);
31
- this.gateway = new gateway_client_1.GatewayClient(config, auth);
32
- this.agentsApi = new agents_api_1.AgentsApi(this.rest);
17
+ // implementation
18
+ constructor(configOrInjected, auth) {
19
+ this.bridges = new Map();
20
+ if ("rest" in configOrInjected && "gateway" in configOrInjected) {
21
+ this.rest = configOrInjected.rest;
22
+ this.gateway = configOrInjected.gateway;
23
+ this.controlApiUrl = configOrInjected.controlApiUrl;
24
+ }
25
+ else {
26
+ this.rest = new rest_client_1.RestClient(configOrInjected, auth);
27
+ this.gateway = new gateway_client_1.GatewayClient(configOrInjected, auth);
28
+ this.controlApiUrl = configOrInjected.controlApiUrl;
29
+ }
30
+ this.agentsApi = new agents_api_1.AgentsApi(this.rest, this.controlApiUrl);
33
31
  this.channelsApi = new channels_api_1.ChannelsApi(this.rest);
34
32
  this.messagesApi = new messages_api_1.MessagesApi(this.rest);
35
33
  this.aggregatesApi = new aggregates_api_1.AggregatesApi(this.rest);
36
34
  this.connectionsApi = new connections_api_1.ConnectionsApi(this.rest);
37
- this.gateway.on("messageCreate", (message) => {
38
- const key = this.channelKey(message.channel.agent_id, message.channel.name);
39
- const identifier = this.toIdentifier(message.channel.agent_id, message.channel.name);
40
- this.subscriptions.get(key)?.forEach((entry) => entry.messageCallback(identifier, message));
41
- });
42
- this.gateway.on("messageUpdate", (message, request_data) => {
43
- const key = this.channelKey(message.channel.agent_id, message.channel.name);
44
- const identifier = this.toIdentifier(message.channel.agent_id, message.channel.name);
45
- this.subscriptions.get(key)?.forEach((entry) => entry.messageUpdateCallback?.(identifier, message, request_data));
46
- });
47
- this.gateway.on("channelSync", (event) => {
48
- const key = this.channelKey(event.channel.agent_id, event.channel.name);
49
- const identifier = this.toIdentifier(event.channel.agent_id, event.channel.name);
50
- this.subscriptions.get(key)?.forEach((entry) => entry.aggregateCallback(identifier, event.aggregate));
51
- });
52
- this.gateway.on("aggregateUpdate", (event) => {
53
- const key = this.channelKey(event.channel.agent_id, event.channel.name);
54
- const identifier = this.toIdentifier(event.channel.agent_id, event.channel.name);
55
- this.subscriptions.get(key)?.forEach((entry) => entry.aggregateCallback(identifier, event.aggregate));
56
- });
57
35
  }
36
+ /** @deprecated Use `client.users.getMe()` instead. Removed in 0.6.0. */
58
37
  getMe() {
59
- return this.rest.get("/users/me", undefined, this.config.controlApiUrl);
38
+ return new users_api_1.UsersApi(this.rest, this.controlApiUrl).getMe();
60
39
  }
40
+ /** @deprecated Use `client.agents.listAgents(opts)` instead. Removed in 0.6.0. */
61
41
  async getAgents(options) {
62
- const query = {};
63
- if (options?.includeArchived) {
64
- query["include-archived"] = true;
65
- }
66
- if (options?.includeOrganisations) {
67
- query["include-organisations"] = true;
68
- }
69
- if (options?.includeUsers) {
70
- query["include-users"] = true;
71
- }
72
- const raw = await this.rest.request({
73
- path: "/agents/",
74
- baseUrl: this.config.controlApiUrl,
75
- omitSharingHeader: true,
76
- query: Object.keys(query).length > 0 ? query : undefined,
77
- });
78
- const rawAgents = Array.isArray(raw.agents) ? raw.agents : [];
79
- const normalizedAgents = rawAgents.map((agent) => this.normalizeAgentEntry(agent));
80
- if (!options?.mergeIncludedAsAgents) {
81
- return {
82
- ...raw,
83
- agents: normalizedAgents,
84
- };
85
- }
86
- const merged = [...normalizedAgents];
87
- if (options.includeOrganisations) {
88
- const rawOrganisations = Array.isArray(raw.organisations)
89
- ? raw.organisations
90
- : [];
91
- for (const org of rawOrganisations) {
92
- merged.push(this.normalizeOrganisationEntry(org));
93
- }
94
- }
95
- if (options.includeUsers) {
96
- const rawUsers = Array.isArray(raw.users) ? raw.users : [];
97
- for (const user of rawUsers) {
98
- merged.push(this.normalizeUserEntry(user));
99
- }
100
- }
101
- return {
102
- ...raw,
103
- agents: merged,
104
- results: merged,
105
- count: merged.length,
106
- };
42
+ return this.agentsApi.listAgents(options);
107
43
  }
44
+ /** @deprecated Use `client.channels.listChannels(id, opts)` instead. Removed in 0.6.0. */
108
45
  async getChannels(identifier, options) {
109
- if (!identifier.agentId) {
46
+ if (!identifier.agentId)
110
47
  return undefined;
111
- }
112
48
  return this.channelsApi.listChannels(identifier.agentId, {
113
49
  include_archived: options?.includeArchived,
114
50
  });
115
51
  }
52
+ /** @deprecated Use `client.channels.putChannel(id, name, body)` instead. Removed in 0.6.0. */
116
53
  createChannel(identifier, channelName, options) {
117
54
  if (!identifier.agentId) {
118
55
  throw new errors_1.DooverValidationError("Identifier must contain agentId");
@@ -121,179 +58,114 @@ class DooverDataProvider {
121
58
  is_private: options?.is_private ?? false,
122
59
  });
123
60
  }
61
+ /** @deprecated Use `client.channels.archiveChannel(id)` instead. Removed in 0.6.0. */
124
62
  archiveChannel(identifier) {
125
- const validated = this.requireChannel(identifier);
126
- return this.rest.post(`/agents/${validated.agentId}/channels/${validated.channelName}/archive`, {});
63
+ const v = this.requireChannel(identifier);
64
+ return this.channelsApi.archiveChannel(v.agentId, v.channelName);
127
65
  }
66
+ /** @deprecated Use `client.channels.unarchiveChannel(id)` instead. Removed in 0.6.0. */
128
67
  unarchiveChannel(identifier) {
129
- const validated = this.requireChannel(identifier);
130
- return this.rest.post(`/agents/${validated.agentId}/channels/${validated.channelName}/unarchive`, {});
68
+ const v = this.requireChannel(identifier);
69
+ return this.channelsApi.unarchiveChannel(v.agentId, v.channelName);
131
70
  }
71
+ /** @deprecated Use `client.channels.getChannel(id)` instead. Removed in 0.6.0. */
132
72
  getChannel(identifier) {
133
73
  if (!identifier.agentId || !identifier.channelName) {
134
74
  return Promise.resolve(undefined);
135
75
  }
136
76
  return this.channelsApi.getChannel(identifier.agentId, identifier.channelName);
137
77
  }
78
+ /** @deprecated Use `client.gateway.subscribeToChannel(channel, handlers)` instead. Removed in 0.6.0. */
138
79
  async subscribeToChannel(identifier, callback, aggregateCallback, messageUpdateCallback) {
139
80
  const validated = this.requireChannel(identifier);
140
- const key = this.channelKey(validated.agentId, validated.channelName);
141
- const entries = this.subscriptions.get(key) ?? [];
142
- entries.push({
143
- messageCallback: callback,
144
- aggregateCallback,
145
- messageUpdateCallback,
81
+ const channel = { agent_id: validated.agentId, name: validated.channelName };
82
+ const off = this.gateway.subscribeToChannel(channel, {
83
+ onMessage: (msg) => callback(identifier, msg),
84
+ onAggregate: (agg) => aggregateCallback(identifier, agg),
85
+ onMessageUpdate: messageUpdateCallback
86
+ ? (msg, rd) => messageUpdateCallback(identifier, msg, rd)
87
+ : undefined,
146
88
  });
147
- this.subscriptions.set(key, entries);
89
+ this.bridges.set(callback, off);
148
90
  await this.gateway.connect();
149
- this.gateway.subscribe({
150
- agent_id: validated.agentId,
151
- name: validated.channelName,
152
- });
153
- return Promise.resolve();
154
91
  }
155
- async unsubscribeFromChannel(identifier, callback) {
156
- const validated = this.requireChannel(identifier);
157
- const key = this.channelKey(validated.agentId, validated.channelName);
158
- const entries = this.subscriptions.get(key);
159
- if (!entries) {
160
- return Promise.reject(new errors_1.DooverValidationError("Not Currently Subscribed to Channel"));
161
- }
162
- const next = entries.filter((entry) => entry.messageCallback !== callback);
163
- if (next.length === 0) {
164
- this.subscriptions.delete(key);
165
- this.gateway.unsubscribe({
166
- agent_id: validated.agentId,
167
- name: validated.channelName,
168
- });
169
- }
170
- else {
171
- this.subscriptions.set(key, next);
92
+ /** @deprecated Call the unsubscribe fn returned by `client.gateway.subscribeToChannel`. Removed in 0.6.0. */
93
+ async unsubscribeFromChannel(_identifier, callback) {
94
+ const off = this.bridges.get(callback);
95
+ if (!off) {
96
+ throw new errors_1.DooverValidationError("Not Currently Subscribed to Channel");
172
97
  }
173
- return Promise.resolve();
98
+ off();
99
+ this.bridges.delete(callback);
174
100
  }
101
+ /** @deprecated Compose `client.channels.getChannel(id).then(c => c.aggregate ?? client.aggregates.getAggregate(id))` instead. Removed in 0.6.0. */
175
102
  async getAggregate(identifier) {
176
- if (!identifier.agentId || !identifier.channelName) {
103
+ if (!identifier.agentId || !identifier.channelName)
177
104
  return undefined;
178
- }
179
- const channel = await this.channelsApi.getChannel(identifier.agentId, identifier.channelName);
180
- if (channel.aggregate) {
181
- return channel.aggregate;
182
- }
105
+ const ch = await this.channelsApi.getChannel(identifier.agentId, identifier.channelName);
106
+ if (ch.aggregate)
107
+ return ch.aggregate;
183
108
  return this.aggregatesApi.getAggregate(identifier.agentId, identifier.channelName);
184
109
  }
185
- /**
186
- * Fetch a page of messages for a channel.
187
- *
188
- * Accepts either a cursor string (legacy — shorthand for `{ before }`)
189
- * or a `ListMessagesParams` options object.
190
- *
191
- * Default limit is 10 for backwards compatibility; pass `limit` explicitly
192
- * for larger pages.
193
- */
110
+ /** @deprecated Use `client.messages.listMessages(id, { ...opts, order: "asc" })` instead. Removed in 0.6.0. */
194
111
  async getMessages(identifier, optionsOrBefore) {
195
- if (!identifier.agentId || !identifier.channelName) {
112
+ if (!identifier.agentId || !identifier.channelName)
196
113
  return undefined;
197
- }
198
- const options = typeof optionsOrBefore === "string"
114
+ const params = typeof optionsOrBefore === "string"
199
115
  ? { before: optionsOrBefore }
200
116
  : (optionsOrBefore ?? {});
201
- const messages = await this.messagesApi.listMessages(identifier.agentId, identifier.channelName, {
202
- before: options.before ?? (0, snowflake_1.generateSnowflakeIdAtTime)(new Date()),
203
- limit: options.limit ?? 10,
204
- ...(options.after !== undefined ? { after: options.after } : {}),
205
- ...(options.field_name !== undefined ? { field_name: options.field_name } : {}),
117
+ return this.messagesApi.listMessages(identifier.agentId, identifier.channelName, {
118
+ ...params,
119
+ order: "asc",
206
120
  });
207
- return messages.reverse();
208
121
  }
122
+ /** @deprecated Use `client.messages.deleteMessage(id, msgId)` instead. Removed in 0.6.0. */
209
123
  deleteMessage(identifier, messageId) {
210
- const validated = this.requireChannel(identifier);
211
- return this.messagesApi.deleteMessage(validated.agentId, validated.channelName, messageId);
124
+ const v = this.requireChannel(identifier);
125
+ return this.messagesApi.deleteMessage(v.agentId, v.channelName, messageId);
212
126
  }
127
+ /** @deprecated Use `client.messages.postMessage(id, { data })` instead. Removed in 0.6.0. */
213
128
  sendMessage(identifier, message) {
214
- const validated = this.requireChannel(identifier);
215
- return this.messagesApi.postMessage(validated.agentId, validated.channelName, {
129
+ const v = this.requireChannel(identifier);
130
+ return this.messagesApi.postMessage(v.agentId, v.channelName, {
216
131
  data: message,
217
132
  });
218
133
  }
219
- /**
220
- * Send a message-based RPC to a channel and await a settled response.
221
- *
222
- * Wire protocol: POST a message with `{ type: "rpc", ...rpcRequest }`; the
223
- * server echoes progress via `MessageUpdate` events keyed by the message id,
224
- * carrying a `status` envelope. Resolves on `success` with the `response`
225
- * payload, rejects on `error` with the status message.
226
- *
227
- * For low-latency ephemeral commands (camera PTZ etc.), use
228
- * `gateway.sendOneShotMessage` directly instead — that path is not persisted
229
- * to the database.
230
- *
231
- * `onStatus` fires on every intermediate status (`sent`, `acknowledged`,
232
- * `deferred`, `pending`) and once more on terminal states.
233
- */
134
+ /** @deprecated Use `client.rpc.send(id, req, opts)` instead. Removed in 0.6.0. */
234
135
  sendRPC(identifier, rpcRequest, options) {
235
- return new Promise((resolve, reject) => {
236
- let rpcMessageId;
237
- let settled = false;
238
- const onUpdate = (_identifier, message) => {
239
- if (settled)
240
- return;
241
- if (rpcMessageId === undefined || message.id !== rpcMessageId)
242
- return;
243
- if (!isRpcMessageData(message.data))
244
- return;
245
- const rpcMessage = message.data;
246
- options?.onStatus?.(rpcMessage.status);
247
- if (rpcMessage.status.code === "success") {
248
- settled = true;
249
- void this.unsubscribeFromChannel(identifier, noopMessageCallback);
250
- resolve(rpcMessage.response);
251
- }
252
- else if (rpcMessage.status.code === "error") {
253
- settled = true;
254
- void this.unsubscribeFromChannel(identifier, noopMessageCallback);
255
- reject(rpcMessage.status.message);
256
- }
257
- };
258
- // noopMessageCallback is used as the identity handle for this
259
- // subscription — subscribe/unsubscribe pair matches by reference.
260
- const noopMessageCallback = () => { };
261
- const noopAggregateCallback = () => { };
262
- this.subscribeToChannel(identifier, noopMessageCallback, noopAggregateCallback, onUpdate)
263
- .then(() => this.sendMessage(identifier, { type: "rpc", ...rpcRequest }))
264
- .then((message) => {
265
- rpcMessageId = message.id;
266
- })
267
- .catch((error) => {
268
- if (settled)
269
- return;
270
- settled = true;
271
- void this.unsubscribeFromChannel(identifier, noopMessageCallback);
272
- reject(error);
273
- });
274
- });
136
+ const v = this.requireChannel(identifier);
137
+ if (!this.dispatcher) {
138
+ this.dispatcher = new rpc_dispatcher_1.RpcDispatcher(this.gateway, this.messagesApi);
139
+ }
140
+ return this.dispatcher.send({ agentId: v.agentId, channelName: v.channelName }, rpcRequest, options);
275
141
  }
142
+ /** @deprecated Use `client.aggregates.patchAggregate(id, data, params)` instead. Removed in 0.6.0. */
276
143
  updateAggregate(identifier, message, params) {
277
- const validated = this.requireChannel(identifier);
278
- return this.aggregatesApi.patchAggregate(validated.agentId, validated.channelName, message, params);
144
+ const v = this.requireChannel(identifier);
145
+ return this.aggregatesApi.patchAggregate(v.agentId, v.channelName, message, params);
279
146
  }
147
+ /** @deprecated Use `client.aggregates.putAggregate(id, data, params)` instead. Removed in 0.6.0. */
280
148
  putAggregate(identifier, message, params) {
281
- const validated = this.requireChannel(identifier);
282
- return this.aggregatesApi.putAggregate(validated.agentId, validated.channelName, message, params);
149
+ const v = this.requireChannel(identifier);
150
+ return this.aggregatesApi.putAggregate(v.agentId, v.channelName, message, params);
283
151
  }
152
+ /** @deprecated Use `client.connections.getChannelSubscriptions(id)` instead. Removed in 0.6.0. */
284
153
  getChannelSubscriptions(identifier) {
285
- const validated = this.requireChannel(identifier);
286
- return this.connectionsApi.getChannelSubscriptions(validated.agentId, validated.channelName);
154
+ const v = this.requireChannel(identifier);
155
+ return this.connectionsApi.getChannelSubscriptions(v.agentId, v.channelName);
287
156
  }
157
+ /** @deprecated Use `client.connections.getAgentConnections(id)` instead. Removed in 0.6.0. */
288
158
  getAgentConnections(identifier) {
289
159
  if (!identifier.agentId) {
290
160
  return Promise.reject(new errors_1.DooverValidationError("Invalid Identifier"));
291
161
  }
292
162
  return this.connectionsApi.getAgentConnections(identifier.agentId);
293
163
  }
164
+ /** @deprecated Use the free function `getIdentifierFromPath(path, search)` instead. Removed in 0.6.0. */
294
165
  getIdentifierFromPath(path, searchParams) {
295
166
  return (0, path_parsing_1.getIdentifierFromPath)(path, searchParams);
296
167
  }
168
+ /** @deprecated No replacement — this was a synthesized stub. Removed in 0.6.0. */
297
169
  getAgentInfo(agentId) {
298
170
  return Promise.resolve({
299
171
  id: agentId,
@@ -308,106 +180,6 @@ class DooverDataProvider {
308
180
  extra_config: {},
309
181
  });
310
182
  }
311
- normalizeAgentEntry(rawAgent) {
312
- const source = isPlainObject(rawAgent)
313
- ? rawAgent
314
- : {};
315
- const fixedLocation = source.fixed_location;
316
- const normalizedFixedLocation = isPlainObject(fixedLocation) &&
317
- typeof fixedLocation.latitude === "number" &&
318
- typeof fixedLocation.longitude === "number"
319
- ? {
320
- latitude: fixedLocation.latitude,
321
- longitude: fixedLocation.longitude,
322
- }
323
- : { latitude: 0, longitude: 0 };
324
- const faIcon = typeof source.fa_icon === "string" && source.fa_icon.length > 0
325
- ? source.fa_icon
326
- : "fa-solid fa-robot";
327
- return {
328
- ...source,
329
- id: typeof source.id === "string" ? source.id : String(source.id ?? ""),
330
- organisation: typeof source.organisation === "string" ? source.organisation : "",
331
- name: typeof source.name === "string" ? source.name : "",
332
- display_name: typeof source.display_name === "string" ? source.display_name : "",
333
- archived: typeof source.archived === "boolean" ? source.archived : false,
334
- group: typeof source.group === "string" ? source.group : "",
335
- fa_icon: faIcon,
336
- type: source.type === "device" ||
337
- source.type === "dashboard" ||
338
- source.type === "organisation" ||
339
- source.type === "user"
340
- ? source.type
341
- : "device",
342
- fixed_location: normalizedFixedLocation,
343
- extra_config: this.coerceExtraConfig(source.extra_config),
344
- };
345
- }
346
- normalizeOrganisationEntry(rawOrganisation) {
347
- const source = isPlainObject(rawOrganisation)
348
- ? rawOrganisation
349
- : {};
350
- const name = typeof source.name === "string" ? source.name : "";
351
- const rootGroup = isPlainObject(source.root_group) ? source.root_group : null;
352
- const groupName = rootGroup && typeof rootGroup.name === "string" ? rootGroup.name : "";
353
- return {
354
- id: typeof source.id === "string" ? source.id : String(source.id ?? ""),
355
- organisation: name,
356
- name,
357
- display_name: name,
358
- archived: typeof source.archived === "boolean" ? source.archived : false,
359
- group: groupName,
360
- fa_icon: "fa-solid fa-building",
361
- type: "organisation",
362
- fixed_location: { latitude: 0, longitude: 0 },
363
- extra_config: this.coerceExtraConfig(source.extra_config),
364
- };
365
- }
366
- normalizeUserEntry(rawUser) {
367
- const source = isPlainObject(rawUser)
368
- ? rawUser
369
- : {};
370
- const id = typeof source.id === "string" ? source.id : String(source.id ?? "");
371
- const username = typeof source.username === "string" ? source.username : "";
372
- const email = typeof source.email === "string" ? source.email : "";
373
- const name = username !== "" ? username : email !== "" ? email : id;
374
- return {
375
- id,
376
- organisation: "",
377
- name,
378
- display_name: this.buildUserDisplayName(source),
379
- archived: false,
380
- group: "",
381
- fa_icon: "fa-solid fa-user",
382
- type: "user",
383
- fixed_location: { latitude: 0, longitude: 0 },
384
- extra_config: this.coerceExtraConfig(source.custom_data),
385
- };
386
- }
387
- buildUserDisplayName(rawUser) {
388
- const source = isPlainObject(rawUser)
389
- ? rawUser
390
- : {};
391
- const firstName = typeof source.first_name === "string" ? source.first_name.trim() : "";
392
- const lastName = typeof source.last_name === "string" ? source.last_name.trim() : "";
393
- const fullName = `${firstName} ${lastName}`.trim();
394
- if (fullName !== "") {
395
- return fullName;
396
- }
397
- if (typeof source.username === "string" && source.username !== "") {
398
- return source.username;
399
- }
400
- if (typeof source.email === "string" && source.email !== "") {
401
- return source.email;
402
- }
403
- if (typeof source.id === "string" && source.id !== "") {
404
- return source.id;
405
- }
406
- return String(source.id ?? "");
407
- }
408
- coerceExtraConfig(value) {
409
- return isPlainObject(value) ? value : {};
410
- }
411
183
  requireChannel(identifier) {
412
184
  if (!identifier.agentId || !identifier.channelName) {
413
185
  throw new errors_1.DooverValidationError("Identifier must contain agentId and channelName");
@@ -417,11 +189,5 @@ class DooverDataProvider {
417
189
  channelName: identifier.channelName,
418
190
  };
419
191
  }
420
- channelKey(agentId, channelName) {
421
- return `${agentId}/${channelName}`;
422
- }
423
- toIdentifier(agentId, channelName) {
424
- return { agentId, channelName };
425
- }
426
192
  }
427
193
  exports.DooverDataProvider = DooverDataProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doover-js",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "description": "TypeScript client for Doover.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",