doover-js 0.1.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/LICENSE +201 -0
- package/README.md +35 -0
- package/dist/apis/agents-api.d.ts +22 -0
- package/dist/apis/agents-api.js +20 -0
- package/dist/apis/aggregates-api.d.ts +15 -0
- package/dist/apis/aggregates-api.js +21 -0
- package/dist/apis/alarms-api.d.ts +12 -0
- package/dist/apis/alarms-api.js +27 -0
- package/dist/apis/channels-api.d.ts +27 -0
- package/dist/apis/channels-api.js +24 -0
- package/dist/apis/connections-api.d.ts +23 -0
- package/dist/apis/connections-api.js +24 -0
- package/dist/apis/messages-api.d.ts +32 -0
- package/dist/apis/messages-api.js +45 -0
- package/dist/apis/notifications-api.d.ts +23 -0
- package/dist/apis/notifications-api.js +54 -0
- package/dist/apis/permissions-api.d.ts +9 -0
- package/dist/apis/permissions-api.js +18 -0
- package/dist/apis/processors-api.d.ts +21 -0
- package/dist/apis/processors-api.js +45 -0
- package/dist/apis/turn-api.d.ts +7 -0
- package/dist/apis/turn-api.js +12 -0
- package/dist/client/doover-client.d.ts +29 -0
- package/dist/client/doover-client.js +34 -0
- package/dist/gateway/gateway-client.d.ts +37 -0
- package/dist/gateway/gateway-client.js +258 -0
- package/dist/gateway/types.d.ts +135 -0
- package/dist/gateway/types.js +2 -0
- package/dist/http/errors.d.ts +19 -0
- package/dist/http/errors.js +28 -0
- package/dist/http/rest-client.d.ts +35 -0
- package/dist/http/rest-client.js +129 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +41 -0
- package/dist/test/apis.test.d.ts +1 -0
- package/dist/test/apis.test.js +248 -0
- package/dist/test/doover-client.test.d.ts +1 -0
- package/dist/test/doover-client.test.js +29 -0
- package/dist/test/doover-data-provider.test.d.ts +1 -0
- package/dist/test/doover-data-provider.test.js +228 -0
- package/dist/test/gateway-client.test.d.ts +1 -0
- package/dist/test/gateway-client.test.js +235 -0
- package/dist/test/helpers.d.ts +32 -0
- package/dist/test/helpers.js +115 -0
- package/dist/test/rest-client.test.d.ts +1 -0
- package/dist/test/rest-client.test.js +115 -0
- package/dist/test/utils.test.d.ts +1 -0
- package/dist/test/utils.test.js +54 -0
- package/dist/types/common.d.ts +130 -0
- package/dist/types/common.js +2 -0
- package/dist/types/openapi.d.ts +144 -0
- package/dist/types/openapi.js +2 -0
- package/dist/types/viewer.d.ts +70 -0
- package/dist/types/viewer.js +2 -0
- package/dist/utils/snowflake.d.ts +13 -0
- package/dist/utils/snowflake.js +26 -0
- package/dist/viewer/doover-data-provider.d.ts +55 -0
- package/dist/viewer/doover-data-provider.js +191 -0
- package/dist/viewer/path-parsing.d.ts +5 -0
- package/dist/viewer/path-parsing.js +38 -0
- package/package.json +46 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RestClient = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
class RestClient {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.config = {
|
|
8
|
+
...config,
|
|
9
|
+
sharing: config.sharing ?? "internal",
|
|
10
|
+
organisationId: config.organisationId ?? null,
|
|
11
|
+
impersonateUserStorageKey: config.impersonateUserStorageKey ?? "impersonate_user_id",
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
async request(options) {
|
|
15
|
+
const method = options.method ?? "GET";
|
|
16
|
+
const url = this.buildUrl(options.baseUrl ?? this.config.dataRestUrl, options.path, options.query);
|
|
17
|
+
const headers = new Headers(options.headers);
|
|
18
|
+
const body = this.normalizeBody(options.body, headers);
|
|
19
|
+
headers.set("X-Doover-Sharing", this.config.sharing);
|
|
20
|
+
if (this.config.organisationId) {
|
|
21
|
+
headers.set("X-Doover-Organisation", this.config.organisationId);
|
|
22
|
+
}
|
|
23
|
+
const impersonated = this.getImpersonatedUserId();
|
|
24
|
+
if (impersonated) {
|
|
25
|
+
headers.set("X-Doover-Assume", impersonated);
|
|
26
|
+
}
|
|
27
|
+
const fetchImpl = this.config.fetchImpl ?? fetch;
|
|
28
|
+
const response = await fetchImpl(url, {
|
|
29
|
+
method,
|
|
30
|
+
headers,
|
|
31
|
+
body,
|
|
32
|
+
credentials: "include",
|
|
33
|
+
});
|
|
34
|
+
const payload = await this.parseResponse(response);
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
throw new errors_1.DooverApiError({
|
|
37
|
+
status: response.status,
|
|
38
|
+
body: payload,
|
|
39
|
+
url,
|
|
40
|
+
method,
|
|
41
|
+
message: typeof payload === "object" &&
|
|
42
|
+
payload !== null &&
|
|
43
|
+
"message" in payload &&
|
|
44
|
+
typeof payload.message === "string"
|
|
45
|
+
? payload.message
|
|
46
|
+
: undefined,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return payload;
|
|
50
|
+
}
|
|
51
|
+
get(path, query, baseUrl) {
|
|
52
|
+
return this.request({ path, query, baseUrl });
|
|
53
|
+
}
|
|
54
|
+
post(path, body, query, baseUrl) {
|
|
55
|
+
return this.request({ path, body, query, method: "POST", baseUrl });
|
|
56
|
+
}
|
|
57
|
+
put(path, body, query, baseUrl) {
|
|
58
|
+
return this.request({ path, body, query, method: "PUT", baseUrl });
|
|
59
|
+
}
|
|
60
|
+
patch(path, body, query, baseUrl) {
|
|
61
|
+
return this.request({ path, body, query, method: "PATCH", baseUrl });
|
|
62
|
+
}
|
|
63
|
+
delete(path, query, baseUrl) {
|
|
64
|
+
return this.request({ path, query, method: "DELETE", baseUrl });
|
|
65
|
+
}
|
|
66
|
+
buildUrl(baseUrl, path, query) {
|
|
67
|
+
const normalizedBase = baseUrl.replace(/\/+$/, "");
|
|
68
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
69
|
+
const finalUrl = new URL(`${normalizedBase}${normalizedPath}`);
|
|
70
|
+
if (query) {
|
|
71
|
+
for (const [key, value] of Object.entries(query)) {
|
|
72
|
+
if (value === undefined || value === null) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(value)) {
|
|
76
|
+
value.forEach((item) => finalUrl.searchParams.append(key, String(item)));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
finalUrl.searchParams.set(key, String(value));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return finalUrl.toString();
|
|
84
|
+
}
|
|
85
|
+
normalizeBody(body, headers) {
|
|
86
|
+
if (body === undefined || body === null) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
if (typeof FormData !== "undefined" &&
|
|
90
|
+
body instanceof FormData) {
|
|
91
|
+
return body;
|
|
92
|
+
}
|
|
93
|
+
if (typeof body === "string" || body instanceof Blob || ArrayBuffer.isView(body)) {
|
|
94
|
+
return body;
|
|
95
|
+
}
|
|
96
|
+
headers.set("Content-Type", "application/json");
|
|
97
|
+
return JSON.stringify(body);
|
|
98
|
+
}
|
|
99
|
+
async parseResponse(response) {
|
|
100
|
+
if (response.status === 204) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
104
|
+
if (contentType.includes("application/json")) {
|
|
105
|
+
return response.json();
|
|
106
|
+
}
|
|
107
|
+
if (contentType.includes("application/octet-stream") ||
|
|
108
|
+
contentType.includes("application/pdf")) {
|
|
109
|
+
return response.blob();
|
|
110
|
+
}
|
|
111
|
+
const text = await response.text();
|
|
112
|
+
if (!text) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
return JSON.parse(text);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return text;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
getImpersonatedUserId() {
|
|
123
|
+
if (typeof sessionStorage === "undefined") {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
return sessionStorage.getItem(this.config.impersonateUserStorageKey);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.RestClient = RestClient;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { DooverClient } from "./client/doover-client";
|
|
2
|
+
export { AgentsApi } from "./apis/agents-api";
|
|
3
|
+
export { AggregatesApi } from "./apis/aggregates-api";
|
|
4
|
+
export { AlarmsApi } from "./apis/alarms-api";
|
|
5
|
+
export { ChannelsApi } from "./apis/channels-api";
|
|
6
|
+
export { ConnectionsApi } from "./apis/connections-api";
|
|
7
|
+
export { MessagesApi } from "./apis/messages-api";
|
|
8
|
+
export { NotificationsApi } from "./apis/notifications-api";
|
|
9
|
+
export { PermissionsApi } from "./apis/permissions-api";
|
|
10
|
+
export { ProcessorsApi } from "./apis/processors-api";
|
|
11
|
+
export { TurnApi } from "./apis/turn-api";
|
|
12
|
+
export { GatewayClient } from "./gateway/gateway-client";
|
|
13
|
+
export type * from "./gateway/types";
|
|
14
|
+
export { RestClient } from "./http/rest-client";
|
|
15
|
+
export type { DooverClientConfig } from "./http/rest-client";
|
|
16
|
+
export { DooverApiError, DooverGatewayError, DooverValidationError, } from "./http/errors";
|
|
17
|
+
export { DooverDataProvider } from "./viewer/doover-data-provider";
|
|
18
|
+
export { getIdentifierFromPath } from "./viewer/path-parsing";
|
|
19
|
+
export type * from "./types/common";
|
|
20
|
+
export type * from "./types/openapi";
|
|
21
|
+
export type * from "./types/viewer";
|
|
22
|
+
export { addTimestampToMessage, extractSnowflakeId, generateSnowflakeIdAtTime, } from "./utils/snowflake";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSnowflakeIdAtTime = exports.extractSnowflakeId = exports.addTimestampToMessage = exports.getIdentifierFromPath = exports.DooverDataProvider = exports.DooverValidationError = exports.DooverGatewayError = exports.DooverApiError = exports.RestClient = exports.GatewayClient = exports.TurnApi = exports.ProcessorsApi = exports.PermissionsApi = exports.NotificationsApi = exports.MessagesApi = exports.ConnectionsApi = exports.ChannelsApi = exports.AlarmsApi = exports.AggregatesApi = exports.AgentsApi = exports.DooverClient = void 0;
|
|
4
|
+
var doover_client_1 = require("./client/doover-client");
|
|
5
|
+
Object.defineProperty(exports, "DooverClient", { enumerable: true, get: function () { return doover_client_1.DooverClient; } });
|
|
6
|
+
var agents_api_1 = require("./apis/agents-api");
|
|
7
|
+
Object.defineProperty(exports, "AgentsApi", { enumerable: true, get: function () { return agents_api_1.AgentsApi; } });
|
|
8
|
+
var aggregates_api_1 = require("./apis/aggregates-api");
|
|
9
|
+
Object.defineProperty(exports, "AggregatesApi", { enumerable: true, get: function () { return aggregates_api_1.AggregatesApi; } });
|
|
10
|
+
var alarms_api_1 = require("./apis/alarms-api");
|
|
11
|
+
Object.defineProperty(exports, "AlarmsApi", { enumerable: true, get: function () { return alarms_api_1.AlarmsApi; } });
|
|
12
|
+
var channels_api_1 = require("./apis/channels-api");
|
|
13
|
+
Object.defineProperty(exports, "ChannelsApi", { enumerable: true, get: function () { return channels_api_1.ChannelsApi; } });
|
|
14
|
+
var connections_api_1 = require("./apis/connections-api");
|
|
15
|
+
Object.defineProperty(exports, "ConnectionsApi", { enumerable: true, get: function () { return connections_api_1.ConnectionsApi; } });
|
|
16
|
+
var messages_api_1 = require("./apis/messages-api");
|
|
17
|
+
Object.defineProperty(exports, "MessagesApi", { enumerable: true, get: function () { return messages_api_1.MessagesApi; } });
|
|
18
|
+
var notifications_api_1 = require("./apis/notifications-api");
|
|
19
|
+
Object.defineProperty(exports, "NotificationsApi", { enumerable: true, get: function () { return notifications_api_1.NotificationsApi; } });
|
|
20
|
+
var permissions_api_1 = require("./apis/permissions-api");
|
|
21
|
+
Object.defineProperty(exports, "PermissionsApi", { enumerable: true, get: function () { return permissions_api_1.PermissionsApi; } });
|
|
22
|
+
var processors_api_1 = require("./apis/processors-api");
|
|
23
|
+
Object.defineProperty(exports, "ProcessorsApi", { enumerable: true, get: function () { return processors_api_1.ProcessorsApi; } });
|
|
24
|
+
var turn_api_1 = require("./apis/turn-api");
|
|
25
|
+
Object.defineProperty(exports, "TurnApi", { enumerable: true, get: function () { return turn_api_1.TurnApi; } });
|
|
26
|
+
var gateway_client_1 = require("./gateway/gateway-client");
|
|
27
|
+
Object.defineProperty(exports, "GatewayClient", { enumerable: true, get: function () { return gateway_client_1.GatewayClient; } });
|
|
28
|
+
var rest_client_1 = require("./http/rest-client");
|
|
29
|
+
Object.defineProperty(exports, "RestClient", { enumerable: true, get: function () { return rest_client_1.RestClient; } });
|
|
30
|
+
var errors_1 = require("./http/errors");
|
|
31
|
+
Object.defineProperty(exports, "DooverApiError", { enumerable: true, get: function () { return errors_1.DooverApiError; } });
|
|
32
|
+
Object.defineProperty(exports, "DooverGatewayError", { enumerable: true, get: function () { return errors_1.DooverGatewayError; } });
|
|
33
|
+
Object.defineProperty(exports, "DooverValidationError", { enumerable: true, get: function () { return errors_1.DooverValidationError; } });
|
|
34
|
+
var doover_data_provider_1 = require("./viewer/doover-data-provider");
|
|
35
|
+
Object.defineProperty(exports, "DooverDataProvider", { enumerable: true, get: function () { return doover_data_provider_1.DooverDataProvider; } });
|
|
36
|
+
var path_parsing_1 = require("./viewer/path-parsing");
|
|
37
|
+
Object.defineProperty(exports, "getIdentifierFromPath", { enumerable: true, get: function () { return path_parsing_1.getIdentifierFromPath; } });
|
|
38
|
+
var snowflake_1 = require("./utils/snowflake");
|
|
39
|
+
Object.defineProperty(exports, "addTimestampToMessage", { enumerable: true, get: function () { return snowflake_1.addTimestampToMessage; } });
|
|
40
|
+
Object.defineProperty(exports, "extractSnowflakeId", { enumerable: true, get: function () { return snowflake_1.extractSnowflakeId; } });
|
|
41
|
+
Object.defineProperty(exports, "generateSnowflakeIdAtTime", { enumerable: true, get: function () { return snowflake_1.generateSnowflakeIdAtTime; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const mocha_1 = require("mocha");
|
|
5
|
+
const agents_api_1 = require("../apis/agents-api");
|
|
6
|
+
const aggregates_api_1 = require("../apis/aggregates-api");
|
|
7
|
+
const alarms_api_1 = require("../apis/alarms-api");
|
|
8
|
+
const channels_api_1 = require("../apis/channels-api");
|
|
9
|
+
const connections_api_1 = require("../apis/connections-api");
|
|
10
|
+
const messages_api_1 = require("../apis/messages-api");
|
|
11
|
+
const notifications_api_1 = require("../apis/notifications-api");
|
|
12
|
+
const permissions_api_1 = require("../apis/permissions-api");
|
|
13
|
+
const processors_api_1 = require("../apis/processors-api");
|
|
14
|
+
const turn_api_1 = require("../apis/turn-api");
|
|
15
|
+
const rest_client_1 = require("../http/rest-client");
|
|
16
|
+
const snowflake_1 = require("../utils/snowflake");
|
|
17
|
+
const helpers_1 = require("./helpers");
|
|
18
|
+
function setupRest(responseFactory) {
|
|
19
|
+
const fetchMock = (0, helpers_1.createFetchMock)(responseFactory);
|
|
20
|
+
const rest = new rest_client_1.RestClient({
|
|
21
|
+
dataRestUrl: "https://api.example.com",
|
|
22
|
+
controlApiUrl: "https://control.example.com",
|
|
23
|
+
dataWssUrl: "wss://ws.example.com",
|
|
24
|
+
fetchImpl: fetchMock,
|
|
25
|
+
});
|
|
26
|
+
return { rest, fetchMock };
|
|
27
|
+
}
|
|
28
|
+
(0, mocha_1.describe)("API clients", () => {
|
|
29
|
+
(0, mocha_1.it)("covers agents batch methods", async () => {
|
|
30
|
+
const id = (0, snowflake_1.generateSnowflakeIdAtTime)(new Date("2026-01-01T00:00:00Z"));
|
|
31
|
+
const { rest, fetchMock } = setupRest((url) => {
|
|
32
|
+
if (url.includes("/messages")) {
|
|
33
|
+
return (0, helpers_1.createJsonResponse)({
|
|
34
|
+
results: [
|
|
35
|
+
{
|
|
36
|
+
id,
|
|
37
|
+
author_id: "u",
|
|
38
|
+
channel: { agent_id: "a1", name: "c1" },
|
|
39
|
+
data: {},
|
|
40
|
+
attachments: [],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
count: 1,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return (0, helpers_1.createJsonResponse)({
|
|
47
|
+
results: [{ agent_id: "a1", data: {}, attachments: [] }],
|
|
48
|
+
count: 1,
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
const api = new agents_api_1.AgentsApi(rest);
|
|
52
|
+
const messages = await api.getMultiAgentMessages("c1", {
|
|
53
|
+
agent_id: ["a1", "a2"],
|
|
54
|
+
limit: 5,
|
|
55
|
+
});
|
|
56
|
+
const aggregates = await api.getMultiAgentAggregates("c1", {
|
|
57
|
+
agent_id: ["a1"],
|
|
58
|
+
});
|
|
59
|
+
(0, chai_1.expect)(messages.results[0].timestamp).to.be.greaterThan(0);
|
|
60
|
+
(0, chai_1.expect)(aggregates.results).to.have.length(1);
|
|
61
|
+
(0, chai_1.expect)(fetchMock.getCall(0).args[0]).to.equal("https://api.example.com/agents/channels/c1/messages?agent_id=a1&agent_id=a2&limit=5");
|
|
62
|
+
(0, chai_1.expect)(fetchMock.getCall(1).args[0]).to.equal("https://api.example.com/agents/channels/c1/aggregates?agent_id=a1");
|
|
63
|
+
});
|
|
64
|
+
(0, mocha_1.it)("covers channels methods", async () => {
|
|
65
|
+
const { rest, fetchMock } = setupRest(() => (0, helpers_1.createJsonResponse)([]));
|
|
66
|
+
const api = new channels_api_1.ChannelsApi(rest);
|
|
67
|
+
await api.listChannels("a1", { include_archived: true });
|
|
68
|
+
await api.getChannel("a1", "c1", { include_aggregate: true });
|
|
69
|
+
await api.createChannel("a1", "c1", { is_private: true });
|
|
70
|
+
await api.putChannel("a1", "c1", { is_private: false });
|
|
71
|
+
await api.listDataSeries("a1", { field_name: ["temp"] });
|
|
72
|
+
(0, chai_1.expect)(fetchMock.getCalls().map((call) => [call.args[0], call.args[1]?.method ?? "GET"])).to.deep.equal([
|
|
73
|
+
["https://api.example.com/agents/a1/channels?include_archived=true", "GET"],
|
|
74
|
+
["https://api.example.com/agents/a1/channels/c1?include_aggregate=true", "GET"],
|
|
75
|
+
["https://api.example.com/agents/a1/channels/c1", "POST"],
|
|
76
|
+
["https://api.example.com/agents/a1/channels/c1", "PUT"],
|
|
77
|
+
["https://api.example.com/agents/a1/data_series?field_name=temp", "GET"],
|
|
78
|
+
]);
|
|
79
|
+
});
|
|
80
|
+
(0, mocha_1.it)("covers messages methods and multipart helper", async () => {
|
|
81
|
+
const id = (0, snowflake_1.generateSnowflakeIdAtTime)(new Date("2026-01-01T00:00:00Z"));
|
|
82
|
+
const { rest, fetchMock } = setupRest((url) => {
|
|
83
|
+
if (url.includes("/attachments/")) {
|
|
84
|
+
return (0, helpers_1.createBlobResponse)("data");
|
|
85
|
+
}
|
|
86
|
+
if (url.includes("/timeseries")) {
|
|
87
|
+
return (0, helpers_1.createJsonResponse)({ count: 1, results: [{ value: 1, message_id: id }] });
|
|
88
|
+
}
|
|
89
|
+
if (url.endsWith(`/messages/${id}`)) {
|
|
90
|
+
return (0, helpers_1.createJsonResponse)({
|
|
91
|
+
id,
|
|
92
|
+
author_id: "u",
|
|
93
|
+
channel: { agent_id: "a1", name: "c1" },
|
|
94
|
+
data: {},
|
|
95
|
+
attachments: [],
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (url.endsWith("/messages")) {
|
|
99
|
+
return (0, helpers_1.createJsonResponse)({
|
|
100
|
+
id,
|
|
101
|
+
author_id: "u",
|
|
102
|
+
channel: { agent_id: "a1", name: "c1" },
|
|
103
|
+
data: {},
|
|
104
|
+
attachments: [],
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return (0, helpers_1.createJsonResponse)([
|
|
108
|
+
{
|
|
109
|
+
id,
|
|
110
|
+
author_id: "u",
|
|
111
|
+
channel: { agent_id: "a1", name: "c1" },
|
|
112
|
+
data: {},
|
|
113
|
+
attachments: [],
|
|
114
|
+
},
|
|
115
|
+
]);
|
|
116
|
+
});
|
|
117
|
+
const api = new messages_api_1.MessagesApi(rest);
|
|
118
|
+
const list = await api.listMessages("a1", "c1", { limit: 2 });
|
|
119
|
+
const posted = await api.postMessage("a1", "c1", { data: { x: 1 } });
|
|
120
|
+
const series = await api.getTimeseries("a1", "c1", { field_name: ["x"] });
|
|
121
|
+
const message = await api.getMessage("a1", "c1", id);
|
|
122
|
+
await api.putMessage("a1", "c1", id, { data: { x: 2 } }, { suppress_response: true });
|
|
123
|
+
await api.patchMessage("a1", "c1", id, { data: { x: 3 } }, { clear_attachments: true });
|
|
124
|
+
await api.deleteMessage("a1", "c1", id);
|
|
125
|
+
const blob = await api.getMessageAttachment("a1", "c1", id, "att-1");
|
|
126
|
+
const formData = api.createMultipartPayload({ data: { x: 1 } }, [new Blob(["a"])]);
|
|
127
|
+
(0, chai_1.expect)(list[0].timestamp).to.be.greaterThan(0);
|
|
128
|
+
(0, chai_1.expect)(posted.timestamp).to.be.greaterThan(0);
|
|
129
|
+
(0, chai_1.expect)(series.count).to.equal(1);
|
|
130
|
+
(0, chai_1.expect)(message.id).to.equal(id);
|
|
131
|
+
(0, chai_1.expect)(await blob.text()).to.equal("data");
|
|
132
|
+
(0, chai_1.expect)(formData.get("json_payload")).to.equal(JSON.stringify({ data: { x: 1 } }));
|
|
133
|
+
(0, chai_1.expect)(formData.get("attachment-0")).to.be.instanceOf(Blob);
|
|
134
|
+
});
|
|
135
|
+
(0, mocha_1.it)("covers aggregates and alarms methods", async () => {
|
|
136
|
+
const { rest, fetchMock } = setupRest((url) => {
|
|
137
|
+
if (url.includes("/attachments/")) {
|
|
138
|
+
return (0, helpers_1.createBlobResponse)("agg");
|
|
139
|
+
}
|
|
140
|
+
if (url.includes("/alarms")) {
|
|
141
|
+
return (0, helpers_1.createJsonResponse)({
|
|
142
|
+
id: "alarm",
|
|
143
|
+
name: "a",
|
|
144
|
+
description: "",
|
|
145
|
+
enabled: true,
|
|
146
|
+
key: "x",
|
|
147
|
+
operator: "gt",
|
|
148
|
+
value: 1,
|
|
149
|
+
state: "OK",
|
|
150
|
+
expiry_mins: null,
|
|
151
|
+
entered_state_ts: 1,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return (0, helpers_1.createJsonResponse)({ data: {}, attachments: [] });
|
|
155
|
+
});
|
|
156
|
+
const aggregates = new aggregates_api_1.AggregatesApi(rest);
|
|
157
|
+
const alarms = new alarms_api_1.AlarmsApi(rest);
|
|
158
|
+
await aggregates.getAggregate("a1", "c1");
|
|
159
|
+
await aggregates.putAggregate("a1", "c1", { data: 1 }, { log_update: true });
|
|
160
|
+
await aggregates.patchAggregate("a1", "c1", { data: 2 }, { clear_attachments: true });
|
|
161
|
+
const aggregateBlob = await aggregates.getAggregateAttachment("a1", "c1", "att-1");
|
|
162
|
+
await alarms.listAlarms("a1", "c1");
|
|
163
|
+
await alarms.createAlarm("a1", "c1", { name: "a", key: "x", operator: "gt", value: 1 });
|
|
164
|
+
await alarms.getAlarm("a1", "c1", "alarm");
|
|
165
|
+
await alarms.putAlarm("a1", "c1", "alarm", { name: "a", key: "x", operator: "gt", value: 1 });
|
|
166
|
+
await alarms.patchAlarm("a1", "c1", "alarm", { enabled: false });
|
|
167
|
+
await alarms.deleteAlarm("a1", "c1", "alarm");
|
|
168
|
+
(0, chai_1.expect)(await aggregateBlob.text()).to.equal("agg");
|
|
169
|
+
(0, chai_1.expect)(fetchMock.callCount).to.equal(10);
|
|
170
|
+
});
|
|
171
|
+
(0, mocha_1.it)("covers connections and notifications methods", async () => {
|
|
172
|
+
const { rest, fetchMock } = setupRest(() => (0, helpers_1.createJsonResponse)({ subscriptions: [], endpoints: [], subscribers: [] }));
|
|
173
|
+
const connections = new connections_api_1.ConnectionsApi(rest);
|
|
174
|
+
const notifications = new notifications_api_1.NotificationsApi(rest);
|
|
175
|
+
await connections.getAgentConnections("a1");
|
|
176
|
+
await connections.getAgentConnectionHistory("a1", { default_connection: true });
|
|
177
|
+
await connections.getAgentSubscriptionHistory("a1", { channel: "{\"agent_id\":\"a1\",\"name\":\"c1\"}" });
|
|
178
|
+
await connections.getConnection("conn");
|
|
179
|
+
await connections.getChannelSubscriptions("a1", "c1");
|
|
180
|
+
await notifications.getAgentNotifications("a1");
|
|
181
|
+
await notifications.getAgentNotificationEndpoints("a1", "browser");
|
|
182
|
+
await notifications.createNotificationEndpoint("a1", {
|
|
183
|
+
name: "browser",
|
|
184
|
+
type: 3,
|
|
185
|
+
extra_data: {},
|
|
186
|
+
default: true,
|
|
187
|
+
});
|
|
188
|
+
await notifications.updateNotificationEndpoint("a1", "e1", { name: "browser-2" });
|
|
189
|
+
await notifications.deleteNotificationEndpoint("a1", "e1");
|
|
190
|
+
await notifications.testNotificationEndpoint("a1", "e1");
|
|
191
|
+
await notifications.getAgentNotificationSubscriptions("a1", "a2");
|
|
192
|
+
await notifications.createNotificationSubscription("a1", {
|
|
193
|
+
subscribe_to: "a2",
|
|
194
|
+
severity: 3,
|
|
195
|
+
topic_filter: ["*"],
|
|
196
|
+
});
|
|
197
|
+
await notifications.getAgentDefaultNotificationSubscriptions("a1", "a2");
|
|
198
|
+
await notifications.deleteDefaultNotificationSubscription("a1", "a2");
|
|
199
|
+
await notifications.updateNotificationSubscription("a1", "s1", { severity: 4 });
|
|
200
|
+
await notifications.deleteNotificationSubscription("a1", "s1");
|
|
201
|
+
await notifications.getAgentNotificationSubscribers("a1");
|
|
202
|
+
await notifications.updateMeWebPushEndpoint({
|
|
203
|
+
old_endpoint: "old",
|
|
204
|
+
endpoint: "new",
|
|
205
|
+
key_p256dh: "p",
|
|
206
|
+
key_auth: "a",
|
|
207
|
+
expires_at: 1,
|
|
208
|
+
});
|
|
209
|
+
await notifications.getWebPushPublicKey();
|
|
210
|
+
(0, chai_1.expect)(fetchMock.callCount).to.equal(20);
|
|
211
|
+
});
|
|
212
|
+
(0, mocha_1.it)("covers permissions, processors, and turn methods", async () => {
|
|
213
|
+
const { rest, fetchMock } = setupRest(() => (0, helpers_1.createJsonResponse)({ db: { agent_id: "a1", is_superuser: false, resources: [] } }));
|
|
214
|
+
const permissions = new permissions_api_1.PermissionsApi(rest);
|
|
215
|
+
const processors = new processors_api_1.ProcessorsApi(rest);
|
|
216
|
+
const turn = new turn_api_1.TurnApi(rest);
|
|
217
|
+
await permissions.getAgentPermission("a1");
|
|
218
|
+
await permissions.getAgentPermissionDebug("a1");
|
|
219
|
+
await permissions.syncPermissions({ agent_permissions: [] });
|
|
220
|
+
await processors.createProcessorSchedule("a1", "sched", {
|
|
221
|
+
app_key: "app",
|
|
222
|
+
permissions: [],
|
|
223
|
+
});
|
|
224
|
+
await processors.deleteProcessorSchedule("a1", "sched");
|
|
225
|
+
await processors.regenerateScheduleToken("a1", "sched");
|
|
226
|
+
await processors.getScheduleInfo("sched");
|
|
227
|
+
await processors.getScheduleInfoAlias("sched");
|
|
228
|
+
await processors.createProcessorSubscription("a1", "sub", {
|
|
229
|
+
subscription_arn: "arn",
|
|
230
|
+
app_key: "app",
|
|
231
|
+
permissions: [],
|
|
232
|
+
});
|
|
233
|
+
await processors.deleteProcessorSubscription("a1", "sub");
|
|
234
|
+
await processors.getProcessorSubscriptionInfo("arn");
|
|
235
|
+
await processors.getProcessorSubscriptionInfoAlias("arn");
|
|
236
|
+
await processors.createIngestionEndpoint("a1", "ing", {
|
|
237
|
+
lambda_arn: "arn",
|
|
238
|
+
cidr_ranges: [],
|
|
239
|
+
throttle_limit: 1,
|
|
240
|
+
app_key: "app",
|
|
241
|
+
permissions: [],
|
|
242
|
+
});
|
|
243
|
+
await processors.deleteIngestionEndpoint("a1", "ing");
|
|
244
|
+
await processors.invokeIngestionEndpoint("a1", "ing", { hello: "world" }, { wait: true });
|
|
245
|
+
await turn.createTurnToken({ role: "client", camera_name: "cam", device_id: "a1" });
|
|
246
|
+
(0, chai_1.expect)(fetchMock.callCount).to.equal(16);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const mocha_1 = require("mocha");
|
|
5
|
+
const doover_client_1 = require("../client/doover-client");
|
|
6
|
+
const helpers_1 = require("./helpers");
|
|
7
|
+
(0, mocha_1.describe)("DooverClient", () => {
|
|
8
|
+
(0, mocha_1.it)("wires all public subclients", () => {
|
|
9
|
+
const client = new doover_client_1.DooverClient({
|
|
10
|
+
dataRestUrl: "https://api.example.com",
|
|
11
|
+
controlApiUrl: "https://control.example.com",
|
|
12
|
+
dataWssUrl: "wss://ws.example.com",
|
|
13
|
+
fetchImpl: (0, helpers_1.createFetchMock)(),
|
|
14
|
+
webSocketImpl: helpers_1.MockWebSocket,
|
|
15
|
+
});
|
|
16
|
+
(0, chai_1.expect)(client.viewer).to.exist;
|
|
17
|
+
(0, chai_1.expect)(client.channels).to.exist;
|
|
18
|
+
(0, chai_1.expect)(client.messages).to.exist;
|
|
19
|
+
(0, chai_1.expect)(client.aggregates).to.exist;
|
|
20
|
+
(0, chai_1.expect)(client.alarms).to.exist;
|
|
21
|
+
(0, chai_1.expect)(client.connections).to.exist;
|
|
22
|
+
(0, chai_1.expect)(client.notifications).to.exist;
|
|
23
|
+
(0, chai_1.expect)(client.permissions).to.exist;
|
|
24
|
+
(0, chai_1.expect)(client.processors).to.exist;
|
|
25
|
+
(0, chai_1.expect)(client.turn).to.exist;
|
|
26
|
+
(0, chai_1.expect)(client.agents).to.exist;
|
|
27
|
+
(0, chai_1.expect)(client.gateway).to.exist;
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|