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.
- package/README.md +146 -0
- package/dist/apis/_args.d.ts +16 -0
- package/dist/apis/_args.js +26 -0
- package/dist/apis/agents-api.d.ts +4 -1
- package/dist/apis/agents-api.js +139 -1
- package/dist/apis/aggregates-api.d.ts +23 -3
- package/dist/apis/aggregates-api.js +33 -4
- package/dist/apis/alarms-api.d.ts +30 -0
- package/dist/apis/alarms-api.js +51 -6
- package/dist/apis/channels-api.d.ts +40 -3
- package/dist/apis/channels-api.js +50 -5
- package/dist/apis/connections-api.d.ts +21 -5
- package/dist/apis/connections-api.js +26 -10
- package/dist/apis/messages-api.d.ts +54 -9
- package/dist/apis/messages-api.js +94 -12
- package/dist/apis/notifications-api.d.ts +52 -0
- package/dist/apis/notifications-api.js +99 -13
- package/dist/apis/permissions-api.d.ts +8 -0
- package/dist/apis/permissions-api.js +11 -2
- package/dist/apis/processors-api.d.ts +35 -0
- package/dist/apis/processors-api.js +64 -8
- package/dist/apis/users-api.d.ts +8 -0
- package/dist/apis/users-api.js +13 -0
- package/dist/client/capabilities.d.ts +10 -0
- package/dist/client/capabilities.js +43 -0
- package/dist/client/data-client.d.ts +104 -0
- package/dist/client/data-client.js +2 -0
- package/dist/client/doover-client.d.ts +31 -31
- package/dist/client/doover-client.js +58 -37
- package/dist/client/errors.d.ts +23 -0
- package/dist/client/errors.js +50 -0
- package/dist/client/local-agent-client.d.ts +65 -0
- package/dist/client/local-agent-client.js +222 -0
- package/dist/client/multiplex-client.d.ts +151 -0
- package/dist/client/multiplex-client.js +744 -0
- package/dist/client/multiplex-gateway.d.ts +49 -0
- package/dist/client/multiplex-gateway.js +114 -0
- package/dist/client/multiplex-merge.d.ts +12 -0
- package/dist/client/multiplex-merge.js +42 -0
- package/dist/client/provenance.d.ts +60 -0
- package/dist/client/provenance.js +113 -0
- package/dist/client/stats.d.ts +24 -0
- package/dist/client/stats.js +62 -0
- package/dist/client/status-tracker.d.ts +24 -0
- package/dist/client/status-tracker.js +90 -0
- package/dist/gateway/gateway-client.d.ts +23 -1
- package/dist/gateway/gateway-client.js +75 -6
- package/dist/http/rest-client.d.ts +5 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +22 -7
- package/dist/react/context.d.ts +9 -5
- package/dist/react/context.js +6 -2
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +3 -1
- package/dist/react/useChannelAggregate.d.ts +8 -1
- package/dist/react/useChannelAggregate.js +24 -6
- package/dist/react/useChannelMessage.d.ts +8 -1
- package/dist/react/useChannelMessage.js +17 -6
- package/dist/react/useChannelMessages.d.ts +8 -1
- package/dist/react/useChannelMessages.js +21 -7
- package/dist/react/useChannelSubscription.d.ts +6 -0
- package/dist/react/useChannelSubscription.js +8 -18
- package/dist/react/useClientStatus.d.ts +10 -0
- package/dist/react/useClientStatus.js +22 -0
- package/dist/react/useConnectionState.d.ts +5 -0
- package/dist/react/useConnectionState.js +5 -0
- package/dist/react/useMultiAgentAggregates.d.ts +8 -1
- package/dist/react/useMultiAgentAggregates.js +25 -21
- package/dist/react/useMultiAgentChannelMessages.d.ts +8 -1
- package/dist/react/useMultiAgentChannelMessages.js +23 -18
- package/dist/react/useSendMessage.d.ts +8 -1
- package/dist/react/useSendMessage.js +15 -2
- package/dist/react/useSendRpc.js +4 -1
- package/dist/react/useUpdateAggregate.d.ts +6 -0
- package/dist/react/useUpdateAggregate.js +20 -4
- package/dist/react/useUpdateMessage.d.ts +5 -0
- package/dist/react/useUpdateMessage.js +11 -2
- package/dist/rpc/errors.d.ts +10 -0
- package/dist/rpc/errors.js +23 -0
- package/dist/rpc/rpc-dispatcher.d.ts +28 -0
- package/dist/rpc/rpc-dispatcher.js +129 -0
- package/dist/test/api-args.test.d.ts +1 -0
- package/dist/test/api-args.test.js +48 -0
- package/dist/test/api-overloads.test.d.ts +9 -0
- package/dist/test/api-overloads.test.js +276 -0
- package/dist/test/capabilities.test.d.ts +1 -0
- package/dist/test/capabilities.test.js +27 -0
- package/dist/test/data-client-errors.test.d.ts +1 -0
- package/dist/test/data-client-errors.test.js +24 -0
- package/dist/test/data-client-shape.test.d.ts +1 -0
- package/dist/test/data-client-shape.test.js +28 -0
- package/dist/test/doover-client-dataclient.test.d.ts +1 -0
- package/dist/test/doover-client-dataclient.test.js +58 -0
- package/dist/test/doover-client-provenance.test.d.ts +1 -0
- package/dist/test/doover-client-provenance.test.js +32 -0
- package/dist/test/exports.test.d.ts +1 -0
- package/dist/test/exports.test.js +76 -0
- package/dist/test/gateway-provenance.test.d.ts +1 -0
- package/dist/test/gateway-provenance.test.js +29 -0
- package/dist/test/gateway-subscriptions.test.d.ts +1 -0
- package/dist/test/gateway-subscriptions.test.js +95 -0
- package/dist/test/local-agent-client.test.d.ts +1 -0
- package/dist/test/local-agent-client.test.js +202 -0
- package/dist/test/multiplex-capabilities.test.d.ts +1 -0
- package/dist/test/multiplex-capabilities.test.js +37 -0
- package/dist/test/multiplex-conflicts.test.d.ts +1 -0
- package/dist/test/multiplex-conflicts.test.js +35 -0
- package/dist/test/multiplex-gateway.test.d.ts +1 -0
- package/dist/test/multiplex-gateway.test.js +103 -0
- package/dist/test/multiplex-merge.test.d.ts +1 -0
- package/dist/test/multiplex-merge.test.js +19 -0
- package/dist/test/multiplex-noncore.test.d.ts +1 -0
- package/dist/test/multiplex-noncore.test.js +82 -0
- package/dist/test/multiplex-passthrough.test.d.ts +1 -0
- package/dist/test/multiplex-passthrough.test.js +35 -0
- package/dist/test/multiplex-reads.test.d.ts +1 -0
- package/dist/test/multiplex-reads.test.js +87 -0
- package/dist/test/multiplex-registry.test.d.ts +1 -0
- package/dist/test/multiplex-registry.test.js +81 -0
- package/dist/test/multiplex-routing.test.d.ts +1 -0
- package/dist/test/multiplex-routing.test.js +45 -0
- package/dist/test/multiplex-status.test.d.ts +1 -0
- package/dist/test/multiplex-status.test.js +63 -0
- package/dist/test/multiplex-writes.test.d.ts +1 -0
- package/dist/test/multiplex-writes.test.js +93 -0
- package/dist/test/provenance-regression.test.d.ts +1 -0
- package/dist/test/provenance-regression.test.js +45 -0
- package/dist/test/provenance-stamper.test.d.ts +1 -0
- package/dist/test/provenance-stamper.test.js +41 -0
- package/dist/test/provenance-type.test.d.ts +1 -0
- package/dist/test/provenance-type.test.js +15 -0
- package/dist/test/react-client-status.test.d.ts +1 -0
- package/dist/test/react-client-status.test.js +35 -0
- package/dist/test/react-dataclient.test.d.ts +1 -0
- package/dist/test/react-dataclient.test.js +28 -0
- package/dist/test/react-exports.test.d.ts +1 -0
- package/dist/test/react-exports.test.js +45 -0
- package/dist/test/react-sources-option.test.d.ts +1 -0
- package/dist/test/react-sources-option.test.js +41 -0
- package/dist/test/react.test.js +2 -2
- package/dist/test/rpc-dispatcher.test.d.ts +1 -0
- package/dist/test/rpc-dispatcher.test.js +190 -0
- package/dist/test/stats-rpc.test.d.ts +1 -0
- package/dist/test/stats-rpc.test.js +69 -0
- package/dist/test/status-tracker.test.d.ts +1 -0
- package/dist/test/status-tracker.test.js +85 -0
- package/dist/test/users-api.test.d.ts +1 -0
- package/dist/test/users-api.test.js +19 -0
- package/dist/types/common.d.ts +18 -1
- package/dist/types/openapi.d.ts +1 -0
- package/dist/types/provenance.d.ts +45 -0
- package/dist/types/provenance.js +2 -0
- package/dist/types/viewer.d.ts +3 -0
- package/dist/viewer/doover-data-provider.d.ts +30 -34
- package/dist/viewer/doover-data-provider.js +82 -316
- 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
|
|
13
|
+
const rpc_dispatcher_1 = require("../rpc/rpc-dispatcher");
|
|
13
14
|
const path_parsing_1 = require("./path-parsing");
|
|
14
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
this.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
126
|
-
return this.
|
|
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
|
|
130
|
-
return this.
|
|
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
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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.
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
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
|
-
|
|
180
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
|
211
|
-
return this.messagesApi.deleteMessage(
|
|
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
|
|
215
|
-
return this.messagesApi.postMessage(
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
|
278
|
-
return this.aggregatesApi.patchAggregate(
|
|
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
|
|
282
|
-
return this.aggregatesApi.putAggregate(
|
|
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
|
|
286
|
-
return this.connectionsApi.getChannelSubscriptions(
|
|
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;
|