@robotbas/robotcloud-client 0.2.22 → 0.3.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/dist/helpers/index.d.mts +1 -1
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/index.js +148 -7
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/index.mjs +148 -7
- package/dist/helpers/index.mjs.map +1 -1
- package/dist/{index-BQ8vrXpV.d.mts → index-BsViQoY8.d.mts} +287 -99
- package/dist/{index-BQ8vrXpV.d.ts → index-BsViQoY8.d.ts} +287 -99
- package/dist/index.d.mts +228 -89
- package/dist/index.d.ts +228 -89
- package/dist/index.js +448 -165
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +443 -165
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/types/ProjectClassifer.d.ts +11 -1
- package/types/ProjectLocation.d.ts +24 -0
- package/types/ProjectSubsystem.d.ts +4 -0
- package/types/ProjectTag.d.ts +8 -1
- package/types/RobotCloudClient.d.ts +187 -9
- package/types/ServiceInstance.d.ts +14 -5
- package/types/Token.d.ts +15 -7
- package/types/alerts.d.ts +88 -0
package/dist/index.js
CHANGED
|
@@ -30,14 +30,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
ApplicationsClient: () => ApplicationsClient,
|
|
34
|
+
OrganizationsClient: () => OrganizationsClient,
|
|
33
35
|
RobotCloudClientConfig: () => RobotCloudClientConfig,
|
|
34
36
|
RoomClimeClient: () => RoomClimeClient,
|
|
37
|
+
UsersClient: () => UsersClient,
|
|
35
38
|
airQualityClient: () => airQualityClient,
|
|
36
39
|
alertsClient: () => alertsClient,
|
|
40
|
+
applicationsClient: () => applicationsClient,
|
|
37
41
|
classifiersClient: () => classifiersClient,
|
|
38
42
|
clientConfig: () => config_default,
|
|
39
43
|
devicesClient: () => devicesClient,
|
|
40
44
|
locationsClient: () => locationsClient,
|
|
45
|
+
loginClient: () => loginClient,
|
|
41
46
|
organizationsClient: () => organizationsClient,
|
|
42
47
|
projectsClient: () => projectsClient,
|
|
43
48
|
robotCloudPermissionsHelper: () => robotCloudPermissionsHelper,
|
|
@@ -126,74 +131,243 @@ __export(robotCloudToken_exports, {
|
|
|
126
131
|
renewToken: () => renewToken,
|
|
127
132
|
validateToken: () => validateToken
|
|
128
133
|
});
|
|
134
|
+
var import_axios3 = __toESM(require("axios"));
|
|
135
|
+
|
|
136
|
+
// src/client/login.ts
|
|
129
137
|
var import_axios2 = __toESM(require("axios"));
|
|
130
|
-
var
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
138
|
+
var LoginClientImpl = class {
|
|
139
|
+
constructor(robotcloudApi2) {
|
|
140
|
+
this.logger = useLogger("AlertsClientImpl");
|
|
141
|
+
this.robotcloudApi = robotcloudApi2;
|
|
134
142
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
async login(username, password, apiKey) {
|
|
144
|
+
try {
|
|
145
|
+
const encoded = btoa(`${username}:${password}`);
|
|
146
|
+
const basicString = `Basic ${encoded}`;
|
|
147
|
+
const cloudUrl = this.robotcloudApi.defaults.baseURL;
|
|
148
|
+
return await import_axios2.default.get(cloudUrl + "login", {
|
|
149
|
+
headers: {
|
|
150
|
+
Authorization: basicString,
|
|
151
|
+
"x-api-key": apiKey
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
} catch (error) {
|
|
155
|
+
this.logger.error("Error logging in", error);
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
141
158
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const expirationDate = new Date(payload.exp * 1e3);
|
|
154
|
-
const currentDate = /* @__PURE__ */ new Date();
|
|
155
|
-
return currentDate >= expirationDate;
|
|
156
|
-
};
|
|
157
|
-
var renewToken = async (renew_token) => {
|
|
158
|
-
logger2.debug("Renewing token ...");
|
|
159
|
-
const cloudUrl = robotCloudApi_default.defaults.baseURL;
|
|
160
|
-
const { data } = await import_axios2.default.get(cloudUrl + "login/renew", {
|
|
161
|
-
headers: {
|
|
162
|
-
Authorization: `Bearer ${renew_token}`
|
|
159
|
+
async renewToken(token) {
|
|
160
|
+
try {
|
|
161
|
+
const cloudUrl = this.robotcloudApi.defaults.baseURL;
|
|
162
|
+
return await import_axios2.default.get(cloudUrl + "login/renew", {
|
|
163
|
+
headers: {
|
|
164
|
+
Authorization: `Bearer ${token}`
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
} catch (error) {
|
|
168
|
+
this.logger.error("Error renewing token", error);
|
|
169
|
+
throw error;
|
|
163
170
|
}
|
|
164
|
-
}
|
|
165
|
-
return {
|
|
166
|
-
renewed: true,
|
|
167
|
-
access: data["access"]["token"],
|
|
168
|
-
renew: data["renew"]["token"]
|
|
169
|
-
};
|
|
171
|
+
}
|
|
170
172
|
};
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
|
|
174
|
+
// src/client/alerts.ts
|
|
175
|
+
var ALERTS_BY_SERVICE_TYPE = {
|
|
176
|
+
"RoomBLEPairing_1": [],
|
|
177
|
+
"RoomClime_1": [
|
|
178
|
+
"high_temperature",
|
|
179
|
+
"low_temperature",
|
|
180
|
+
"high_humidity",
|
|
181
|
+
"fancoil_on_overtime"
|
|
182
|
+
],
|
|
183
|
+
"RoomConsumes_1": [
|
|
184
|
+
"high_daily_energy_electric",
|
|
185
|
+
"high_daily_energy_thermal",
|
|
186
|
+
"high_daily_hot_water",
|
|
187
|
+
"high_daily_cold_water"
|
|
188
|
+
],
|
|
189
|
+
"RoomDiagnostics_1": [
|
|
190
|
+
"low_peripheral_num"
|
|
191
|
+
],
|
|
192
|
+
"RoomGrouping_1": [],
|
|
193
|
+
"RoomGuestStatus_1": [
|
|
194
|
+
"door_open_overtime",
|
|
195
|
+
"window_open_overtime",
|
|
196
|
+
"medical_alarm"
|
|
197
|
+
]
|
|
198
|
+
};
|
|
199
|
+
var AlertsClientImpl = class {
|
|
200
|
+
constructor(robotcloudApi2) {
|
|
201
|
+
this.logger = useLogger("AlertsClientImpl");
|
|
202
|
+
this.robotcloudApi = robotcloudApi2;
|
|
177
203
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
204
|
+
getProjectStats(projectId, params) {
|
|
205
|
+
return this.robotcloudApi.get(
|
|
206
|
+
`projects/${projectId}/alerts/stats`,
|
|
207
|
+
{ params: params != null ? params : {} }
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
getProjectLog(projectId, params) {
|
|
211
|
+
return this.robotcloudApi.get(
|
|
212
|
+
`projects/${projectId}/alerts/log`,
|
|
182
213
|
{
|
|
183
|
-
|
|
184
|
-
Authorization: `Bearer ${access_token}`
|
|
185
|
-
}
|
|
214
|
+
params
|
|
186
215
|
}
|
|
187
216
|
);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
217
|
+
}
|
|
218
|
+
acknowledge(projectId, data) {
|
|
219
|
+
this.logger.debug("Sending put data: ", data);
|
|
220
|
+
return this.robotcloudApi.put(
|
|
221
|
+
`projects/${projectId}/alerts/log`,
|
|
222
|
+
data
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
getAggregatedLogs(projectId, params) {
|
|
226
|
+
return this.robotcloudApi.get(
|
|
227
|
+
`projects/${projectId}/alerts/aggregate`,
|
|
228
|
+
{ params }
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
async getAvailableAlerts(projectId, params) {
|
|
232
|
+
const { data } = await this.robotcloudApi.get(
|
|
233
|
+
`projects/${projectId}/services`,
|
|
234
|
+
{ params: params != null ? params : {} }
|
|
235
|
+
);
|
|
236
|
+
let alerts = [];
|
|
237
|
+
for (const service of data) {
|
|
238
|
+
if (!(service.name in ALERTS_BY_SERVICE_TYPE)) {
|
|
239
|
+
this.logger.warn(`Service ${service.name} not found in ALERTS_BY_SERVICE_TYPE`);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
alerts.push(...ALERTS_BY_SERVICE_TYPE[service.name]);
|
|
193
243
|
}
|
|
194
|
-
return
|
|
244
|
+
return {
|
|
245
|
+
data: alerts
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
getServiceTypeAlertKeys(serviceType) {
|
|
249
|
+
return ALERTS_BY_SERVICE_TYPE[serviceType];
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// src/client/organizations.ts
|
|
254
|
+
var OrganizationsClient = class {
|
|
255
|
+
constructor(robotcloudApi2) {
|
|
256
|
+
this.logger = useLogger("OrganizationsClient");
|
|
257
|
+
this.getOrganizations = () => {
|
|
258
|
+
return this.robotcloudApi.get(`organizations`);
|
|
259
|
+
};
|
|
260
|
+
this.postOrganizations = () => {
|
|
261
|
+
return this.robotcloudApi.post(`organizations`);
|
|
262
|
+
};
|
|
263
|
+
this.getOrganization = (organizationId) => {
|
|
264
|
+
return this.robotcloudApi.get(
|
|
265
|
+
`organizations/${organizationId}`
|
|
266
|
+
);
|
|
267
|
+
};
|
|
268
|
+
this.putOrganization = (organizationId) => {
|
|
269
|
+
return this.robotcloudApi.put(
|
|
270
|
+
`organizations/${organizationId}`
|
|
271
|
+
);
|
|
272
|
+
};
|
|
273
|
+
this.deleteOrganization = (organizationId) => {
|
|
274
|
+
return this.robotcloudApi.delete(
|
|
275
|
+
`organizations/${organizationId}`
|
|
276
|
+
);
|
|
277
|
+
};
|
|
278
|
+
this.getOrganizationProjects = (organizationId) => {
|
|
279
|
+
return this.robotcloudApi.get(
|
|
280
|
+
`organizations/${organizationId}/projects`
|
|
281
|
+
);
|
|
282
|
+
};
|
|
283
|
+
this.postOrganizationProjects = (organizationId) => {
|
|
284
|
+
return this.robotcloudApi.post(
|
|
285
|
+
`organizations/${organizationId}/projects`
|
|
286
|
+
);
|
|
287
|
+
};
|
|
288
|
+
this.getOrganizationUsers = (organizationId) => {
|
|
289
|
+
return this.robotcloudApi.get(
|
|
290
|
+
`organizations/${organizationId}/users`
|
|
291
|
+
);
|
|
292
|
+
};
|
|
293
|
+
this.postOrganizationUsers = (organizationId) => {
|
|
294
|
+
return this.robotcloudApi.post(
|
|
295
|
+
`organizations/${organizationId}/users`
|
|
296
|
+
);
|
|
297
|
+
};
|
|
298
|
+
this.robotcloudApi = robotcloudApi2;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// src/client/users.ts
|
|
303
|
+
var UsersClient = class {
|
|
304
|
+
constructor(robotcloudApi2) {
|
|
305
|
+
this.logger = useLogger("UsersClient");
|
|
306
|
+
this.getUsers = () => {
|
|
307
|
+
return this.robotcloudApi.get(`users`);
|
|
308
|
+
};
|
|
309
|
+
this.getUser = (username) => {
|
|
310
|
+
return this.robotcloudApi.get(`users/${username}`);
|
|
311
|
+
};
|
|
312
|
+
this.putUser = (username) => {
|
|
313
|
+
return this.robotcloudApi.put(`users/${username}`);
|
|
314
|
+
};
|
|
315
|
+
this.deleteUser = (username) => {
|
|
316
|
+
return this.robotcloudApi.delete(`users/${username}`);
|
|
317
|
+
};
|
|
318
|
+
this.getUserOrganizations = (username) => {
|
|
319
|
+
return this.robotcloudApi.get(`users/${username}`);
|
|
320
|
+
};
|
|
321
|
+
this.getUserProjects = (username) => {
|
|
322
|
+
return this.robotcloudApi.get(
|
|
323
|
+
`users/${username}/projects`
|
|
324
|
+
);
|
|
325
|
+
};
|
|
326
|
+
this.postUserProjects = (username) => {
|
|
327
|
+
return this.robotcloudApi.post(
|
|
328
|
+
`users/${username}/projects`
|
|
329
|
+
);
|
|
330
|
+
};
|
|
331
|
+
this.getProjectToUser = (username, projectId) => {
|
|
332
|
+
return this.robotcloudApi.get(
|
|
333
|
+
`users/${username}/projects/${projectId}`
|
|
334
|
+
);
|
|
335
|
+
};
|
|
336
|
+
this.putProjectToUser = (username, projectId) => {
|
|
337
|
+
return this.robotcloudApi.put(
|
|
338
|
+
`users/${username}/projects/${projectId}`
|
|
339
|
+
);
|
|
340
|
+
};
|
|
341
|
+
this.deleteProjectToUser = (username, projectId) => {
|
|
342
|
+
return this.robotcloudApi.delete(
|
|
343
|
+
`users/${username}/projects/${projectId}`
|
|
344
|
+
);
|
|
345
|
+
};
|
|
346
|
+
this.robotcloudApi = robotcloudApi2;
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
// src/client/applications.ts
|
|
351
|
+
var ApplicationsClient = class {
|
|
352
|
+
constructor(robotcloudApi2) {
|
|
353
|
+
this.logger = useLogger("ApplicationsClient");
|
|
354
|
+
this.getApplications = () => {
|
|
355
|
+
return this.robotcloudApi.get(`application/register`);
|
|
356
|
+
};
|
|
357
|
+
this.postOrganizations = () => {
|
|
358
|
+
return this.robotcloudApi.post(`application/register`);
|
|
359
|
+
};
|
|
360
|
+
this.getApplication = (applicationId) => {
|
|
361
|
+
return this.robotcloudApi.get(`application/register/${applicationId}`);
|
|
362
|
+
};
|
|
363
|
+
this.putApplication = (applicationId) => {
|
|
364
|
+
return this.robotcloudApi.get(`application/register/${applicationId}`);
|
|
365
|
+
};
|
|
366
|
+
this.deleteApplication = (applicationId) => {
|
|
367
|
+
return this.robotcloudApi.get(`application/register/${applicationId}`);
|
|
368
|
+
};
|
|
369
|
+
this.robotcloudApi = robotcloudApi2;
|
|
195
370
|
}
|
|
196
|
-
return true;
|
|
197
371
|
};
|
|
198
372
|
|
|
199
373
|
// src/client/services/generics.ts
|
|
@@ -486,32 +660,68 @@ var RoomConsumesClient = class {
|
|
|
486
660
|
var roomConsumesClient = new RoomConsumesClient();
|
|
487
661
|
|
|
488
662
|
// src/client/projects/classifiers.ts
|
|
489
|
-
var
|
|
663
|
+
var logger2 = useLogger("classifiers-client");
|
|
490
664
|
var ClassifiersClient = class {
|
|
491
665
|
constructor() {
|
|
492
666
|
this.getProjectClassifiers = (prjId, params) => {
|
|
493
|
-
|
|
667
|
+
logger2.info(`Get project ${prjId} classifiers`);
|
|
494
668
|
return robotCloudApi_default.get(`projects/${prjId}/classifiers`, {
|
|
495
669
|
params
|
|
496
670
|
});
|
|
497
671
|
};
|
|
498
672
|
this.getClassifier = (classifierId) => {
|
|
499
|
-
return robotCloudApi_default.get(
|
|
673
|
+
return robotCloudApi_default.get(
|
|
674
|
+
`classifiers/${classifierId}`,
|
|
675
|
+
{}
|
|
676
|
+
);
|
|
677
|
+
};
|
|
678
|
+
this.putClassifier = (classifierId) => {
|
|
679
|
+
return robotCloudApi_default.put(
|
|
680
|
+
`classifiers/${classifierId}`,
|
|
681
|
+
{}
|
|
682
|
+
);
|
|
683
|
+
};
|
|
684
|
+
this.postClassifier = (classifierId) => {
|
|
685
|
+
return robotCloudApi_default.post(
|
|
686
|
+
`classifiers/${classifierId}`,
|
|
687
|
+
{}
|
|
688
|
+
);
|
|
689
|
+
};
|
|
690
|
+
this.deleteClassifier = (classifierId) => {
|
|
691
|
+
return robotCloudApi_default.delete(
|
|
692
|
+
`classifiers/${classifierId}`,
|
|
693
|
+
{}
|
|
694
|
+
);
|
|
500
695
|
};
|
|
501
696
|
}
|
|
502
697
|
};
|
|
503
698
|
var classifiersClient = new ClassifiersClient();
|
|
504
699
|
|
|
505
700
|
// src/client/projects/devices.ts
|
|
506
|
-
var
|
|
701
|
+
var logger3 = useLogger("devices-client");
|
|
507
702
|
var DevicesClient = class {
|
|
508
703
|
constructor() {
|
|
509
704
|
this.getProjectDevices = (projectId) => {
|
|
510
705
|
return robotCloudApi_default.get(`projects/${projectId}/devices`);
|
|
511
706
|
};
|
|
707
|
+
this.getProjectDevicesLocation = (locationId) => {
|
|
708
|
+
return robotCloudApi_default.get(`locations/${locationId}/devices`);
|
|
709
|
+
};
|
|
710
|
+
this.postProjectDeviceLocation = (locationId) => {
|
|
711
|
+
return robotCloudApi_default.post(`locations/${locationId}/devices`);
|
|
712
|
+
};
|
|
512
713
|
this.getDeviceDetails = (deviceId) => {
|
|
513
714
|
return robotCloudApi_default.get(`devices/${deviceId}`);
|
|
514
715
|
};
|
|
716
|
+
this.putDeviceDetails = (deviceId) => {
|
|
717
|
+
return robotCloudApi_default.put(`devices/${deviceId}`);
|
|
718
|
+
};
|
|
719
|
+
this.deleteDevice = (deviceId) => {
|
|
720
|
+
return robotCloudApi_default.delete(`devices/${deviceId}`);
|
|
721
|
+
};
|
|
722
|
+
this.getDeviceConfiguration = (deviceId) => {
|
|
723
|
+
return robotCloudApi_default.get(`devices/${deviceId}/compatibleconfigurationtypes`);
|
|
724
|
+
};
|
|
515
725
|
}
|
|
516
726
|
};
|
|
517
727
|
var devicesClient = new DevicesClient();
|
|
@@ -527,6 +737,14 @@ var LocationsClient = class {
|
|
|
527
737
|
}
|
|
528
738
|
);
|
|
529
739
|
};
|
|
740
|
+
this.postLocationServiceInstances = (prjId, locId, service_type, params) => {
|
|
741
|
+
return robotCloudApi_default.post(
|
|
742
|
+
`projects/${prjId}/locations/${locId}/services/${service_type}/instances`,
|
|
743
|
+
{
|
|
744
|
+
params
|
|
745
|
+
}
|
|
746
|
+
);
|
|
747
|
+
};
|
|
530
748
|
this.getLocations = (prjId, params) => {
|
|
531
749
|
return robotCloudApi_default.get(
|
|
532
750
|
`projects/${prjId}/locations`,
|
|
@@ -535,12 +753,32 @@ var LocationsClient = class {
|
|
|
535
753
|
}
|
|
536
754
|
);
|
|
537
755
|
};
|
|
756
|
+
this.postLocations = (prjId, params) => {
|
|
757
|
+
return robotCloudApi_default.post(
|
|
758
|
+
`projects/${prjId}/locations`,
|
|
759
|
+
{
|
|
760
|
+
params
|
|
761
|
+
}
|
|
762
|
+
);
|
|
763
|
+
};
|
|
538
764
|
this.getLocation = (locationId) => {
|
|
539
765
|
return robotCloudApi_default.get(
|
|
540
766
|
`locations/${locationId}`,
|
|
541
767
|
{}
|
|
542
768
|
);
|
|
543
769
|
};
|
|
770
|
+
this.putLocation = (locationId) => {
|
|
771
|
+
return robotCloudApi_default.put(
|
|
772
|
+
`locations/${locationId}`,
|
|
773
|
+
{}
|
|
774
|
+
);
|
|
775
|
+
};
|
|
776
|
+
this.deleteLocation = (locationId) => {
|
|
777
|
+
return robotCloudApi_default.delete(
|
|
778
|
+
`locations/${locationId}`,
|
|
779
|
+
{}
|
|
780
|
+
);
|
|
781
|
+
};
|
|
544
782
|
}
|
|
545
783
|
};
|
|
546
784
|
var locationsClient = new LocationsClient();
|
|
@@ -558,6 +796,29 @@ var ProjectsClient = class {
|
|
|
558
796
|
params
|
|
559
797
|
});
|
|
560
798
|
};
|
|
799
|
+
this.putProjectDetails = (prjId, params) => {
|
|
800
|
+
return robotCloudApi_default.put(`projects/${prjId}`, {
|
|
801
|
+
params
|
|
802
|
+
});
|
|
803
|
+
};
|
|
804
|
+
this.deleteProject = (prjId, params) => {
|
|
805
|
+
return robotCloudApi_default.delete(`projects/${prjId}`, {
|
|
806
|
+
params
|
|
807
|
+
});
|
|
808
|
+
};
|
|
809
|
+
this.getProjectUsers = (prjId, params) => {
|
|
810
|
+
return robotCloudApi_default.get(`projects/${prjId}/users`, {
|
|
811
|
+
params
|
|
812
|
+
});
|
|
813
|
+
};
|
|
814
|
+
this.getProjectInstances = (prjId, params) => {
|
|
815
|
+
return robotCloudApi_default.get(
|
|
816
|
+
`projects/${prjId}/instances`,
|
|
817
|
+
{
|
|
818
|
+
params
|
|
819
|
+
}
|
|
820
|
+
);
|
|
821
|
+
};
|
|
561
822
|
this.getProjectServiceTypes = (prjId, params) => {
|
|
562
823
|
return robotCloudApi_default.get(
|
|
563
824
|
`projects/${prjId}/services`,
|
|
@@ -566,12 +827,29 @@ var ProjectsClient = class {
|
|
|
566
827
|
}
|
|
567
828
|
);
|
|
568
829
|
};
|
|
830
|
+
this.getProjectApplications = (prjId, params) => {
|
|
831
|
+
return robotCloudApi_default.get(`projects/${prjId}/applications`, {
|
|
832
|
+
params
|
|
833
|
+
});
|
|
834
|
+
};
|
|
835
|
+
this.getProjectApplication = (prjId, appId) => {
|
|
836
|
+
return robotCloudApi_default.get(
|
|
837
|
+
`projects/${prjId}/applications/${appId}`,
|
|
838
|
+
{}
|
|
839
|
+
);
|
|
840
|
+
};
|
|
841
|
+
this.putProjectApplication = (prjId, appId) => {
|
|
842
|
+
return robotCloudApi_default.put(
|
|
843
|
+
`projects/${prjId}/applications/${appId}`,
|
|
844
|
+
{}
|
|
845
|
+
);
|
|
846
|
+
};
|
|
569
847
|
}
|
|
570
848
|
};
|
|
571
849
|
var projectsClient = new ProjectsClient();
|
|
572
850
|
|
|
573
851
|
// src/client/projects/service-instances.ts
|
|
574
|
-
var
|
|
852
|
+
var logger4 = useLogger("service-instances-client");
|
|
575
853
|
var ServiceInstancesClient = class {
|
|
576
854
|
constructor() {
|
|
577
855
|
this.getAll = (prjId, params) => {
|
|
@@ -611,18 +889,43 @@ var ServiceInstancesClient = class {
|
|
|
611
889
|
var serviceInstancesClient = new ServiceInstancesClient();
|
|
612
890
|
|
|
613
891
|
// src/client/projects/subsystems.ts
|
|
892
|
+
var logger5 = useLogger("service-instances-client");
|
|
614
893
|
var SubsystemsClient = class {
|
|
615
894
|
constructor() {
|
|
616
895
|
this.getProjectSubsystems = (prjId) => {
|
|
896
|
+
logger5.info(`Get project ${prjId} subsystems`);
|
|
617
897
|
return robotCloudApi_default.get(
|
|
618
898
|
`projects/${prjId}/subsystems`
|
|
619
899
|
);
|
|
620
900
|
};
|
|
621
901
|
this.getProjectSubsystem = (prjId, subsysId) => {
|
|
902
|
+
logger5.info(`Get subsystem ${subsysId} from project ${prjId}`);
|
|
622
903
|
return robotCloudApi_default.get(
|
|
623
904
|
`projects/${prjId}/subsystems/${subsysId}`
|
|
624
905
|
);
|
|
625
906
|
};
|
|
907
|
+
this.postProjectSubsystem = (prjId) => {
|
|
908
|
+
logger5.info(`Create subsystem in project ${prjId}`);
|
|
909
|
+
return robotCloudApi_default.post(
|
|
910
|
+
`projects/${prjId}/subsystems`
|
|
911
|
+
);
|
|
912
|
+
};
|
|
913
|
+
this.putProjectSubsystem = (prjId, subsysId) => {
|
|
914
|
+
logger5.info(`Update subsystem ${subsysId} in project ${prjId}`);
|
|
915
|
+
return robotCloudApi_default.put(
|
|
916
|
+
`projects/${prjId}/subsystems/${subsysId}`
|
|
917
|
+
);
|
|
918
|
+
};
|
|
919
|
+
this.deleteSubsystem = (prjId, subsysId) => {
|
|
920
|
+
logger5.info(`Delete subsystem ${subsysId} in project ${prjId}`);
|
|
921
|
+
return robotCloudApi_default.delete(`projects/${prjId}/subsystems/${subsysId}`);
|
|
922
|
+
};
|
|
923
|
+
this.getProjectSubsystemLocations = (prjId, subsysId) => {
|
|
924
|
+
logger5.info(`Get subsystems locations ${subsysId} in project ${prjId}`);
|
|
925
|
+
return robotCloudApi_default.get(
|
|
926
|
+
`projects/${prjId}/subsystems/${subsysId}/locations`
|
|
927
|
+
);
|
|
928
|
+
};
|
|
626
929
|
}
|
|
627
930
|
};
|
|
628
931
|
var subsystemsClient = new SubsystemsClient();
|
|
@@ -641,125 +944,100 @@ var TagsClient = class {
|
|
|
641
944
|
logger6.info(`Get project ${prjId} tag ${tagId}`);
|
|
642
945
|
return robotCloudApi_default.get(`tags/${tagId}`);
|
|
643
946
|
};
|
|
947
|
+
this.postTag = (prjId) => {
|
|
948
|
+
logger6.info(`Create tag for project ${prjId}`);
|
|
949
|
+
return robotCloudApi_default.post(`projects/${prjId}/tags`);
|
|
950
|
+
};
|
|
951
|
+
this.putTag = (prjId, tagId) => {
|
|
952
|
+
logger6.info(`Modify project ${prjId} tag ${tagId}`);
|
|
953
|
+
return robotCloudApi_default.put(`tags/${tagId}`);
|
|
954
|
+
};
|
|
955
|
+
this.deleteTag = (prjId, tagId) => {
|
|
956
|
+
logger6.info(`Delete project ${prjId} tag ${tagId}`);
|
|
957
|
+
return robotCloudApi_default.delete(`tags/${tagId}`);
|
|
958
|
+
};
|
|
644
959
|
}
|
|
645
960
|
};
|
|
646
961
|
var tagsClient = new TagsClient();
|
|
647
962
|
|
|
648
|
-
// src/client/
|
|
649
|
-
var
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
"high_daily_hot_water",
|
|
661
|
-
"high_daily_cold_water"
|
|
662
|
-
],
|
|
663
|
-
"RoomDiagnostics_1": [
|
|
664
|
-
"low_peripheral_num"
|
|
665
|
-
],
|
|
666
|
-
"RoomGrouping_1": [],
|
|
667
|
-
"RoomGuestStatus_1": [
|
|
668
|
-
"door_open_overtime",
|
|
669
|
-
"window_open_overtime",
|
|
670
|
-
"medical_alarm"
|
|
671
|
-
]
|
|
672
|
-
};
|
|
673
|
-
var AlertsClientImpl = class {
|
|
674
|
-
constructor(robotcloudApi2) {
|
|
675
|
-
this.logger = useLogger("AlertsClientImpl");
|
|
676
|
-
this.robotcloudApi = robotcloudApi2;
|
|
963
|
+
// src/client/index.ts
|
|
964
|
+
var applicationsClient = new ApplicationsClient(robotCloudApi_default);
|
|
965
|
+
var loginClient = new LoginClientImpl(robotCloudApi_default);
|
|
966
|
+
var alertsClient = new AlertsClientImpl(robotCloudApi_default);
|
|
967
|
+
var organizationsClient = new OrganizationsClient(robotCloudApi_default);
|
|
968
|
+
var usersClient = new UsersClient(robotCloudApi_default);
|
|
969
|
+
|
|
970
|
+
// src/helpers/robotCloudToken.ts
|
|
971
|
+
var logger7 = useLogger("robotcloud-token");
|
|
972
|
+
function parseJwt(token) {
|
|
973
|
+
if (!token) {
|
|
974
|
+
return;
|
|
677
975
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
976
|
+
return JSON.parse(atob(token.split(".")[1]));
|
|
977
|
+
}
|
|
978
|
+
var decodeToken = (token) => {
|
|
979
|
+
const payload = parseJwt(token);
|
|
980
|
+
if (!payload) {
|
|
981
|
+
return void 0;
|
|
683
982
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
983
|
+
return payload;
|
|
984
|
+
};
|
|
985
|
+
var needRenew = (payload) => {
|
|
986
|
+
const expirationDate = new Date(payload.exp * 1e3);
|
|
987
|
+
expirationDate.setMinutes(
|
|
988
|
+
expirationDate.getMinutes() - config_default.tokenMinutesBeforeExpirationRenew
|
|
989
|
+
);
|
|
990
|
+
const currentDate = /* @__PURE__ */ new Date();
|
|
991
|
+
return currentDate >= expirationDate;
|
|
992
|
+
};
|
|
993
|
+
var isExpired = (payload) => {
|
|
994
|
+
const expirationDate = new Date(payload.exp * 1e3);
|
|
995
|
+
const currentDate = /* @__PURE__ */ new Date();
|
|
996
|
+
return currentDate >= expirationDate;
|
|
997
|
+
};
|
|
998
|
+
var renewToken = async (renew_token) => {
|
|
999
|
+
logger7.debug("Renewing token ...");
|
|
1000
|
+
const { data } = await loginClient.renewToken(renew_token);
|
|
1001
|
+
return {
|
|
1002
|
+
renewed: true,
|
|
1003
|
+
access: data["access"]["token"],
|
|
1004
|
+
renew: data["renew"]["token"]
|
|
1005
|
+
};
|
|
1006
|
+
};
|
|
1007
|
+
var validateToken = async (access_token) => {
|
|
1008
|
+
var _a, _b, _c;
|
|
1009
|
+
logger7.debug("Validate token ...");
|
|
1010
|
+
const payload = decodeToken(access_token);
|
|
1011
|
+
if (!payload) {
|
|
1012
|
+
return false;
|
|
1013
|
+
}
|
|
1014
|
+
const cloudUrl = robotCloudApi_default.defaults.baseURL;
|
|
1015
|
+
try {
|
|
1016
|
+
const { data } = await import_axios3.default.get(
|
|
1017
|
+
cloudUrl + `users/${payload.sub}`,
|
|
687
1018
|
{
|
|
688
|
-
|
|
1019
|
+
headers: {
|
|
1020
|
+
Authorization: `Bearer ${access_token}`
|
|
1021
|
+
}
|
|
689
1022
|
}
|
|
690
1023
|
);
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
data
|
|
697
|
-
);
|
|
698
|
-
}
|
|
699
|
-
getAggregatedLogs(projectId, params) {
|
|
700
|
-
return this.robotcloudApi.get(
|
|
701
|
-
`projects/${projectId}/alerts/aggregate`,
|
|
702
|
-
{ params }
|
|
703
|
-
);
|
|
704
|
-
}
|
|
705
|
-
async getAvailableAlerts(projectId, params) {
|
|
706
|
-
const { data } = await this.robotcloudApi.get(
|
|
707
|
-
`projects/${projectId}/services`,
|
|
708
|
-
{ params: params != null ? params : {} }
|
|
709
|
-
);
|
|
710
|
-
let alerts = [];
|
|
711
|
-
for (const service of data) {
|
|
712
|
-
if (!(service.name in ALERTS_BY_SERVICE_TYPE)) {
|
|
713
|
-
this.logger.warn(`Service ${service.name} not found in ALERTS_BY_SERVICE_TYPE`);
|
|
714
|
-
continue;
|
|
715
|
-
}
|
|
716
|
-
alerts.push(...ALERTS_BY_SERVICE_TYPE[service.name]);
|
|
1024
|
+
} catch (error) {
|
|
1025
|
+
if (import_axios3.default.isAxiosError(error)) {
|
|
1026
|
+
logger7.warn(`${error.message}: ${(_c = (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) != null ? _c : ""}`);
|
|
1027
|
+
} else {
|
|
1028
|
+
logger7.warn(error);
|
|
717
1029
|
}
|
|
718
|
-
return
|
|
719
|
-
data: alerts
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
};
|
|
723
|
-
var alertsClient = new AlertsClientImpl(robotCloudApi_default);
|
|
724
|
-
|
|
725
|
-
// src/client/organizations.ts
|
|
726
|
-
var OrganizationsClient = class {
|
|
727
|
-
constructor() {
|
|
728
|
-
this.getOrganization = (organizationId) => {
|
|
729
|
-
return robotCloudApi_default.get(
|
|
730
|
-
`organizations/${organizationId}`
|
|
731
|
-
);
|
|
732
|
-
};
|
|
733
|
-
this.getOrganizationProjects = (organizationId) => {
|
|
734
|
-
return robotCloudApi_default.get(
|
|
735
|
-
`organizations/${organizationId}/projects`
|
|
736
|
-
);
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
};
|
|
740
|
-
var organizationsClient = new OrganizationsClient();
|
|
741
|
-
|
|
742
|
-
// src/client/users.ts
|
|
743
|
-
var UsersClient = class {
|
|
744
|
-
constructor() {
|
|
745
|
-
this.getUser = (username) => {
|
|
746
|
-
return robotCloudApi_default.get(`users/${username}`);
|
|
747
|
-
};
|
|
748
|
-
this.getUserProjects = (username) => {
|
|
749
|
-
return robotCloudApi_default.get(
|
|
750
|
-
`users/${username}/projects`
|
|
751
|
-
);
|
|
752
|
-
};
|
|
1030
|
+
return false;
|
|
753
1031
|
}
|
|
1032
|
+
return true;
|
|
754
1033
|
};
|
|
755
|
-
var usersClient = new UsersClient();
|
|
756
1034
|
|
|
757
1035
|
// src/helpers/tags.ts
|
|
758
|
-
var
|
|
1036
|
+
var logger8 = useLogger("tags-helper");
|
|
759
1037
|
var TagsHelper = class {
|
|
760
1038
|
constructor(tagsClient2) {
|
|
761
1039
|
this.getTagsTree = async (prjId, maxDepth = 2, params) => {
|
|
762
|
-
|
|
1040
|
+
logger8.info(`Get project ${prjId} tags tree`);
|
|
763
1041
|
if (!params) {
|
|
764
1042
|
params = {};
|
|
765
1043
|
}
|
|
@@ -774,7 +1052,7 @@ var TagsHelper = class {
|
|
|
774
1052
|
return { root: tags };
|
|
775
1053
|
};
|
|
776
1054
|
this.getTagsChildren = async (prjId, level = 0, parent_id, params, maxDepth) => {
|
|
777
|
-
|
|
1055
|
+
logger8.debug(`Get project ${prjId} tags children: ${parent_id}`);
|
|
778
1056
|
if (!params) {
|
|
779
1057
|
params = {};
|
|
780
1058
|
}
|
|
@@ -854,14 +1132,19 @@ var robotCloudPermissionsHelper = new RobotCloudPermissionsHelperImpl();
|
|
|
854
1132
|
var tagsHelper = new TagsHelper(tagsClient);
|
|
855
1133
|
// Annotate the CommonJS export names for ESM import in node:
|
|
856
1134
|
0 && (module.exports = {
|
|
1135
|
+
ApplicationsClient,
|
|
1136
|
+
OrganizationsClient,
|
|
857
1137
|
RobotCloudClientConfig,
|
|
858
1138
|
RoomClimeClient,
|
|
1139
|
+
UsersClient,
|
|
859
1140
|
airQualityClient,
|
|
860
1141
|
alertsClient,
|
|
1142
|
+
applicationsClient,
|
|
861
1143
|
classifiersClient,
|
|
862
1144
|
clientConfig,
|
|
863
1145
|
devicesClient,
|
|
864
1146
|
locationsClient,
|
|
1147
|
+
loginClient,
|
|
865
1148
|
organizationsClient,
|
|
866
1149
|
projectsClient,
|
|
867
1150
|
robotCloudPermissionsHelper,
|