@robotbas/robotcloud-client 0.2.22 → 0.3.1

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/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,
@@ -45,6 +50,7 @@ __export(index_exports, {
45
50
  robotcloudApi: () => robotCloudApi_default,
46
51
  roomClimeClient: () => roomClimeClient,
47
52
  roomConsumesClient: () => roomConsumesClient,
53
+ roomGroupingClient: () => roomGroupingClient,
48
54
  roomGuestStatusClient: () => roomGuestStatusClient,
49
55
  serviceInstancesClient: () => serviceInstancesClient,
50
56
  subsystemsClient: () => subsystemsClient,
@@ -126,74 +132,233 @@ __export(robotCloudToken_exports, {
126
132
  renewToken: () => renewToken,
127
133
  validateToken: () => validateToken
128
134
  });
135
+ var import_axios3 = __toESM(require("axios"));
136
+
137
+ // src/client/login.ts
129
138
  var import_axios2 = __toESM(require("axios"));
130
- var logger2 = useLogger("robotcloud-token");
131
- function parseJwt(token) {
132
- if (!token) {
133
- return;
139
+ var LoginClientImpl = class {
140
+ constructor(robotcloudApi2) {
141
+ this.logger = useLogger("LoginClientImpl");
142
+ this.robotcloudApi = robotcloudApi2;
134
143
  }
135
- return JSON.parse(atob(token.split(".")[1]));
136
- }
137
- var decodeToken = (token) => {
138
- const payload = parseJwt(token);
139
- if (!payload) {
140
- return void 0;
144
+ async login(username, password, apiKey) {
145
+ try {
146
+ const encoded = btoa(`${username}:${password}`);
147
+ const basicString = `Basic ${encoded}`;
148
+ const cloudUrl = this.robotcloudApi.defaults.baseURL;
149
+ return await import_axios2.default.get(cloudUrl + "login", {
150
+ headers: {
151
+ Authorization: basicString,
152
+ "x-api-key": apiKey
153
+ }
154
+ });
155
+ } catch (error) {
156
+ this.logger.error("Error logging in", error);
157
+ throw error;
158
+ }
141
159
  }
142
- return payload;
143
- };
144
- var needRenew = (payload) => {
145
- const expirationDate = new Date(payload.exp * 1e3);
146
- expirationDate.setMinutes(
147
- expirationDate.getMinutes() - config_default.tokenMinutesBeforeExpirationRenew
148
- );
149
- const currentDate = /* @__PURE__ */ new Date();
150
- return currentDate >= expirationDate;
151
- };
152
- var isExpired = (payload) => {
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}`
160
+ async renewToken(token) {
161
+ try {
162
+ const cloudUrl = this.robotcloudApi.defaults.baseURL;
163
+ return await import_axios2.default.get(cloudUrl + "login/renew", {
164
+ headers: {
165
+ Authorization: `Bearer ${token}`
166
+ }
167
+ });
168
+ } catch (error) {
169
+ this.logger.error("Error renewing token", error);
170
+ throw error;
163
171
  }
164
- });
165
- return {
166
- renewed: true,
167
- access: data["access"]["token"],
168
- renew: data["renew"]["token"]
169
- };
172
+ }
170
173
  };
171
- var validateToken = async (access_token) => {
172
- var _a, _b, _c;
173
- logger2.debug("Validate token ...");
174
- const payload = decodeToken(access_token);
175
- if (!payload) {
176
- return false;
174
+
175
+ // src/client/alerts.ts
176
+ var ALERTS_BY_SERVICE_TYPE = {
177
+ "RoomBLEPairing_1": [],
178
+ "RoomClime_1": [
179
+ "high_temperature",
180
+ "low_temperature",
181
+ "high_humidity",
182
+ "fancoil_on_overtime"
183
+ ],
184
+ "RoomConsumes_1": [
185
+ "high_daily_energy_electric",
186
+ "high_daily_energy_thermal",
187
+ "high_daily_hot_water",
188
+ "high_daily_cold_water"
189
+ ],
190
+ "RoomDiagnostics_1": [
191
+ "low_peripheral_num"
192
+ ],
193
+ "RoomGrouping_1": [],
194
+ "RoomGuestStatus_1": [
195
+ "door_open_overtime",
196
+ "window_open_overtime",
197
+ "medical_alarm"
198
+ ]
199
+ };
200
+ var AlertsClientImpl = class {
201
+ constructor(robotcloudApi2) {
202
+ this.logger = useLogger("AlertsClientImpl");
203
+ this.robotcloudApi = robotcloudApi2;
177
204
  }
178
- const cloudUrl = robotCloudApi_default.defaults.baseURL;
179
- try {
180
- const { data } = await import_axios2.default.get(
181
- cloudUrl + `users/${payload.sub}`,
205
+ getProjectStats(projectId, params) {
206
+ return this.robotcloudApi.get(
207
+ `projects/${projectId}/alerts/stats`,
208
+ { params: params != null ? params : {} }
209
+ );
210
+ }
211
+ getProjectLog(projectId, params) {
212
+ return this.robotcloudApi.get(
213
+ `projects/${projectId}/alerts/log`,
182
214
  {
183
- headers: {
184
- Authorization: `Bearer ${access_token}`
185
- }
215
+ params
186
216
  }
187
217
  );
188
- } catch (error) {
189
- if (import_axios2.default.isAxiosError(error)) {
190
- logger2.warn(`${error.message}: ${(_c = (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) != null ? _c : ""}`);
191
- } else {
192
- logger2.warn(error);
218
+ }
219
+ acknowledge(projectId, data) {
220
+ this.logger.debug("Sending put data: ", data);
221
+ return this.robotcloudApi.put(
222
+ `projects/${projectId}/alerts/log`,
223
+ data
224
+ );
225
+ }
226
+ getAggregatedLogs(projectId, params) {
227
+ return this.robotcloudApi.get(
228
+ `projects/${projectId}/alerts/aggregate`,
229
+ { params }
230
+ );
231
+ }
232
+ async getAvailableAlerts(projectId, params) {
233
+ const { data } = await this.robotcloudApi.get(
234
+ `projects/${projectId}/services`,
235
+ { params: params != null ? params : {} }
236
+ );
237
+ let alerts = [];
238
+ for (const service of data) {
239
+ if (!(service.name in ALERTS_BY_SERVICE_TYPE)) {
240
+ this.logger.warn(`Service ${service.name} not found in ALERTS_BY_SERVICE_TYPE`);
241
+ continue;
242
+ }
243
+ alerts.push(...ALERTS_BY_SERVICE_TYPE[service.name]);
193
244
  }
194
- return false;
245
+ return {
246
+ data: alerts
247
+ };
248
+ }
249
+ getServiceTypeAlertKeys(serviceType) {
250
+ return ALERTS_BY_SERVICE_TYPE[serviceType];
251
+ }
252
+ };
253
+
254
+ // src/client/organizations.ts
255
+ var OrganizationsClient = class {
256
+ constructor(robotcloudApi2) {
257
+ this.logger = useLogger("OrganizationsClient");
258
+ this.getOrganizations = () => {
259
+ return this.robotcloudApi.get(`organizations`);
260
+ };
261
+ this.postOrganizations = () => {
262
+ return this.robotcloudApi.post(`organizations`);
263
+ };
264
+ this.getOrganization = (organizationId) => {
265
+ return this.robotcloudApi.get(
266
+ `organizations/${organizationId}`
267
+ );
268
+ };
269
+ this.putOrganization = (organizationId) => {
270
+ return this.robotcloudApi.put(
271
+ `organizations/${organizationId}`
272
+ );
273
+ };
274
+ this.deleteOrganization = (organizationId) => {
275
+ return this.robotcloudApi.delete(
276
+ `organizations/${organizationId}`
277
+ );
278
+ };
279
+ this.robotcloudApi = robotcloudApi2;
280
+ }
281
+ };
282
+
283
+ // src/client/users.ts
284
+ var UsersClient = class {
285
+ constructor(robotcloudApi2) {
286
+ this.logger = useLogger("UsersClient");
287
+ this.getOrganizationUsers = (organizationId) => {
288
+ return this.robotcloudApi.get(
289
+ `organizations/${organizationId}/users`
290
+ );
291
+ };
292
+ this.postOrganizationUsers = (organizationId) => {
293
+ return this.robotcloudApi.post(
294
+ `organizations/${organizationId}/users`
295
+ );
296
+ };
297
+ this.getUsers = () => {
298
+ return this.robotcloudApi.get(`users`);
299
+ };
300
+ this.getUser = (username) => {
301
+ return this.robotcloudApi.get(`users/${username}`);
302
+ };
303
+ this.putUser = (username) => {
304
+ return this.robotcloudApi.put(`users/${username}`);
305
+ };
306
+ this.deleteUser = (username) => {
307
+ return this.robotcloudApi.delete(`users/${username}`);
308
+ };
309
+ this.getUserOrganizations = (username) => {
310
+ return this.robotcloudApi.get(`users/${username}/organizations`);
311
+ };
312
+ this.getUserProjects = (username) => {
313
+ return this.robotcloudApi.get(
314
+ `users/${username}/projects`
315
+ );
316
+ };
317
+ this.postUserProjects = (username) => {
318
+ return this.robotcloudApi.post(
319
+ `users/${username}/projects`
320
+ );
321
+ };
322
+ this.getProjectToUser = (username, projectId) => {
323
+ return this.robotcloudApi.get(
324
+ `users/${username}/projects/${projectId}`
325
+ );
326
+ };
327
+ this.putProjectToUser = (username, projectId) => {
328
+ return this.robotcloudApi.put(
329
+ `users/${username}/projects/${projectId}`
330
+ );
331
+ };
332
+ this.deleteProjectToUser = (username, projectId) => {
333
+ return this.robotcloudApi.delete(
334
+ `users/${username}/projects/${projectId}`
335
+ );
336
+ };
337
+ this.robotcloudApi = robotcloudApi2;
338
+ }
339
+ };
340
+
341
+ // src/client/applications.ts
342
+ var ApplicationsClient = class {
343
+ constructor(robotcloudApi2) {
344
+ this.logger = useLogger("ApplicationsClient");
345
+ this.getApplications = () => {
346
+ return this.robotcloudApi.get(`application/register`);
347
+ };
348
+ this.postOrganizations = () => {
349
+ return this.robotcloudApi.post(`application/register`);
350
+ };
351
+ this.getApplication = (applicationId) => {
352
+ return this.robotcloudApi.get(`application/register/${applicationId}`);
353
+ };
354
+ this.putApplication = (applicationId) => {
355
+ return this.robotcloudApi.put(`application/register/${applicationId}`);
356
+ };
357
+ this.deleteApplication = (applicationId) => {
358
+ return this.robotcloudApi.delete(`application/register/${applicationId}`);
359
+ };
360
+ this.robotcloudApi = robotcloudApi2;
195
361
  }
196
- return true;
197
362
  };
198
363
 
199
364
  // src/client/services/generics.ts
@@ -485,33 +650,113 @@ var RoomConsumesClient = class {
485
650
  };
486
651
  var roomConsumesClient = new RoomConsumesClient();
487
652
 
653
+ // src/client/services/room-grouping-1.ts
654
+ var RoomGroupingConfigClient = class extends GenericInstanceConfigClient {
655
+ constructor() {
656
+ super("RoomGrouping_1");
657
+ }
658
+ };
659
+ var RoomGroupingClient = class {
660
+ constructor() {
661
+ this.getInstanceData = (prjId, instanceId, params) => {
662
+ return robotCloudApi_default.get(
663
+ `/projects/${prjId}/services/RoomConsumes_1/instances/${instanceId}/data`,
664
+ {
665
+ params,
666
+ headers: {
667
+ Accept: "application/json"
668
+ }
669
+ }
670
+ );
671
+ };
672
+ this._configurationClient = new RoomGroupingConfigClient();
673
+ }
674
+ get configuration() {
675
+ return this._configurationClient;
676
+ }
677
+ getAlerts(prjId, params) {
678
+ throw Error("Not implemented method");
679
+ }
680
+ getData(prjId, params) {
681
+ return robotCloudApi_default.get(`/projects/${prjId}/services/RoomGrouping_1/data`, {
682
+ params,
683
+ headers: {
684
+ Accept: "application/json"
685
+ }
686
+ });
687
+ }
688
+ getInstanceHistoric(prjId, instanceId, startTime, endTime, params) {
689
+ throw Error("Not implemented method");
690
+ }
691
+ getInstanceHistoricAggregate(prjId, instanceId, startTime, endTime, aggFunction, periode, params) {
692
+ throw Error("Not implemented method");
693
+ }
694
+ };
695
+ var roomGroupingClient = new RoomGroupingClient();
696
+
488
697
  // src/client/projects/classifiers.ts
489
- var logger3 = useLogger("classifiers-client");
698
+ var logger2 = useLogger("classifiers-client");
490
699
  var ClassifiersClient = class {
491
700
  constructor() {
492
701
  this.getProjectClassifiers = (prjId, params) => {
493
- logger3.info(`Get project ${prjId} classifiers`);
702
+ logger2.info(`Get project ${prjId} classifiers`);
494
703
  return robotCloudApi_default.get(`projects/${prjId}/classifiers`, {
495
704
  params
496
705
  });
497
706
  };
498
707
  this.getClassifier = (classifierId) => {
499
- return robotCloudApi_default.get(`classifiers/${classifierId}`);
708
+ return robotCloudApi_default.get(
709
+ `classifiers/${classifierId}`,
710
+ {}
711
+ );
712
+ };
713
+ this.putClassifier = (classifierId) => {
714
+ return robotCloudApi_default.put(
715
+ `classifiers/${classifierId}`,
716
+ {}
717
+ );
718
+ };
719
+ this.postClassifier = (classifierId) => {
720
+ return robotCloudApi_default.post(
721
+ `classifiers/${classifierId}`,
722
+ {}
723
+ );
724
+ };
725
+ this.deleteClassifier = (classifierId) => {
726
+ return robotCloudApi_default.delete(
727
+ `classifiers/${classifierId}`,
728
+ {}
729
+ );
500
730
  };
501
731
  }
502
732
  };
503
733
  var classifiersClient = new ClassifiersClient();
504
734
 
505
735
  // src/client/projects/devices.ts
506
- var logger4 = useLogger("devices-client");
736
+ var logger3 = useLogger("devices-client");
507
737
  var DevicesClient = class {
508
738
  constructor() {
509
739
  this.getProjectDevices = (projectId) => {
510
740
  return robotCloudApi_default.get(`projects/${projectId}/devices`);
511
741
  };
742
+ this.getProjectDevicesLocation = (locationId) => {
743
+ return robotCloudApi_default.get(`locations/${locationId}/devices`);
744
+ };
745
+ this.postProjectDeviceLocation = (locationId) => {
746
+ return robotCloudApi_default.post(`locations/${locationId}/devices`);
747
+ };
512
748
  this.getDeviceDetails = (deviceId) => {
513
749
  return robotCloudApi_default.get(`devices/${deviceId}`);
514
750
  };
751
+ this.putDeviceDetails = (deviceId) => {
752
+ return robotCloudApi_default.put(`devices/${deviceId}`);
753
+ };
754
+ this.deleteDevice = (deviceId) => {
755
+ return robotCloudApi_default.delete(`devices/${deviceId}`);
756
+ };
757
+ this.getDeviceConfiguration = (deviceId) => {
758
+ return robotCloudApi_default.get(`devices/${deviceId}/compatibleconfigurationtypes`);
759
+ };
515
760
  }
516
761
  };
517
762
  var devicesClient = new DevicesClient();
@@ -519,16 +764,16 @@ var devicesClient = new DevicesClient();
519
764
  // src/client/projects/locations.ts
520
765
  var LocationsClient = class {
521
766
  constructor() {
522
- this.getLocationServiceInstances = (prjId, locId, service_type, params) => {
767
+ this.getLocations = (prjId, params) => {
523
768
  return robotCloudApi_default.get(
524
- `projects/${prjId}/locations/${locId}/services/${service_type}/instances`,
769
+ `projects/${prjId}/locations`,
525
770
  {
526
771
  params
527
772
  }
528
773
  );
529
774
  };
530
- this.getLocations = (prjId, params) => {
531
- return robotCloudApi_default.get(
775
+ this.postLocations = (prjId, params) => {
776
+ return robotCloudApi_default.post(
532
777
  `projects/${prjId}/locations`,
533
778
  {
534
779
  params
@@ -541,6 +786,18 @@ var LocationsClient = class {
541
786
  {}
542
787
  );
543
788
  };
789
+ this.putLocation = (locationId) => {
790
+ return robotCloudApi_default.put(
791
+ `locations/${locationId}`,
792
+ {}
793
+ );
794
+ };
795
+ this.deleteLocation = (locationId) => {
796
+ return robotCloudApi_default.delete(
797
+ `locations/${locationId}`,
798
+ {}
799
+ );
800
+ };
544
801
  }
545
802
  };
546
803
  var locationsClient = new LocationsClient();
@@ -548,6 +805,16 @@ var locationsClient = new LocationsClient();
548
805
  // src/client/projects/projects.ts
549
806
  var ProjectsClient = class {
550
807
  constructor() {
808
+ this.getOrganizationProjects = (organizationId) => {
809
+ return robotCloudApi_default.get(
810
+ `organizations/${organizationId}/projects`
811
+ );
812
+ };
813
+ this.postOrganizationProjects = (organizationId) => {
814
+ return robotCloudApi_default.post(
815
+ `organizations/${organizationId}/projects`
816
+ );
817
+ };
551
818
  this.getProjects = (params) => {
552
819
  return robotCloudApi_default.get("projects", {
553
820
  params
@@ -558,12 +825,36 @@ var ProjectsClient = class {
558
825
  params
559
826
  });
560
827
  };
561
- this.getProjectServiceTypes = (prjId, params) => {
828
+ this.putProjectDetails = (prjId, params) => {
829
+ return robotCloudApi_default.put(`projects/${prjId}`, {
830
+ params
831
+ });
832
+ };
833
+ this.deleteProject = (prjId, params) => {
834
+ return robotCloudApi_default.delete(`projects/${prjId}`, {
835
+ params
836
+ });
837
+ };
838
+ this.getProjectUsers = (prjId, params) => {
839
+ return robotCloudApi_default.get(`projects/${prjId}/users`, {
840
+ params
841
+ });
842
+ };
843
+ this.getProjectApplications = (prjId, params) => {
844
+ return robotCloudApi_default.get(`projects/${prjId}/applications`, {
845
+ params
846
+ });
847
+ };
848
+ this.getProjectApplication = (prjId, appId) => {
562
849
  return robotCloudApi_default.get(
563
- `projects/${prjId}/services`,
564
- {
565
- params
566
- }
850
+ `projects/${prjId}/applications/${appId}`,
851
+ {}
852
+ );
853
+ };
854
+ this.putProjectApplication = (prjId, appId) => {
855
+ return robotCloudApi_default.put(
856
+ `projects/${prjId}/applications/${appId}`,
857
+ {}
567
858
  );
568
859
  };
569
860
  }
@@ -571,7 +862,7 @@ var ProjectsClient = class {
571
862
  var projectsClient = new ProjectsClient();
572
863
 
573
864
  // src/client/projects/service-instances.ts
574
- var logger5 = useLogger("service-instances-client");
865
+ var logger4 = useLogger("service-instances-client");
575
866
  var ServiceInstancesClient = class {
576
867
  constructor() {
577
868
  this.getAll = (prjId, params) => {
@@ -590,39 +881,134 @@ var ServiceInstancesClient = class {
590
881
  }
591
882
  );
592
883
  };
593
- this.getServiceInstance = (prjId, service_type, service_id) => {
884
+ this.getProjectServiceTypes = (prjId, params) => {
885
+ return robotCloudApi_default.get(
886
+ `projects/${prjId}/services`,
887
+ {
888
+ params
889
+ }
890
+ );
891
+ };
892
+ this.getLocationServiceInstances = (prjId, locId, service_type, params) => {
893
+ return robotCloudApi_default.get(
894
+ `projects/${prjId}/locations/${locId}/services/${service_type}/instances`,
895
+ {
896
+ params
897
+ }
898
+ );
899
+ };
900
+ this.postLocationServiceInstances = (prjId, locId, service_type, params) => {
901
+ return robotCloudApi_default.post(
902
+ `projects/${prjId}/locations/${locId}/services/${service_type}/instances`,
903
+ {
904
+ params
905
+ }
906
+ );
907
+ };
908
+ this.getServiceInstance = (prjId, service_type, instance_id) => {
594
909
  return robotCloudApi_default.get(
595
- `projects/${prjId}/services/${service_type}/instances/${service_id}`
910
+ `projects/${prjId}/services/${service_type}/instances/${instance_id}`
911
+ );
912
+ };
913
+ this.putServiceInstance = (prjId, service_type, instance_id) => {
914
+ return robotCloudApi_default.put(
915
+ `projects/${prjId}/services/${service_type}/instances/${instance_id}`
916
+ );
917
+ };
918
+ this.deleteServiceInstance = (prjId, service_type, instance_id) => {
919
+ return robotCloudApi_default.delete(
920
+ `projects/${prjId}/services/${service_type}/instances/${instance_id}`
596
921
  );
597
922
  };
598
- this.getServiceInstanceDevicesInfo = (prjId, service_type, service_id) => {
599
- return robotCloudApi_default.get(`projects/${prjId}/services/${service_type}/instances/${service_id}/deviceconf`);
923
+ this.getServiceInstanceDevicesInfo = (prjId, service_type, instance_id) => {
924
+ return robotCloudApi_default.get(`projects/${prjId}/services/${service_type}/instances/${instance_id}/deviceconf`);
925
+ };
926
+ this.putServiceInstanceDevicesInfo = (prjId, service_type, instance_id) => {
927
+ return robotCloudApi_default.put(`projects/${prjId}/services/${service_type}/instances/${instance_id}/deviceconf`);
600
928
  };
601
929
  }
602
930
  getServiceAllInstancesData(prjId, service_type) {
603
931
  return robotCloudApi_default.get(`projects/${prjId}/services/${service_type}/data`);
604
932
  }
933
+ getServiceInstancesData(prjId, service_type, instance_id) {
934
+ return robotCloudApi_default.get(`projects/${prjId}/services/${service_type}/instances/${instance_id}/data`);
935
+ }
605
936
  getServiceAllInstancesAlerts(prjId, service_type) {
606
937
  return robotCloudApi_default.get(
607
938
  `projects/${prjId}/services/${service_type}/alert`
608
939
  );
609
940
  }
941
+ getServiceInstancesAlerts(prjId, service_type, instance_id) {
942
+ return robotCloudApi_default.get(`projects/${prjId}/services/${service_type}/instances/${instance_id}/alert`);
943
+ }
944
+ getServiceInstancesConfiguration(prjId, service_type, instance_id) {
945
+ return robotCloudApi_default.get(`projects/${prjId}/services/${service_type}/instances/${instance_id}/configuration`);
946
+ }
947
+ putServiceInstancesConfiguration(prjId, service_type, instance_id) {
948
+ return robotCloudApi_default.put(`projects/${prjId}/services/${service_type}/instances/${instance_id}/configuration`);
949
+ }
950
+ getServiceInstancesHistoricData(prjId, service_type, instance_id) {
951
+ return robotCloudApi_default.get(`projects/${prjId}/services/${service_type}/instances/${instance_id}/historic/data`);
952
+ }
953
+ getServiceInstancesHistoricDataAggregate(prjId, service_type, instance_id) {
954
+ return robotCloudApi_default.get(`projects/${prjId}/services/${service_type}/instances/${instance_id}/historic/data/aggregate`);
955
+ }
956
+ getServiceLocation(prjId, locationId) {
957
+ return robotCloudApi_default.get(
958
+ `projects/${prjId}/locations/${locationId}/services`
959
+ );
960
+ }
961
+ getSizeProjectInstances(prjId) {
962
+ return robotCloudApi_default.get(
963
+ `size/projects/${prjId}/instances`
964
+ );
965
+ }
966
+ getSizeProjectServicesInstances(prjId, service_type) {
967
+ return robotCloudApi_default.get(
968
+ `size/projects/${prjId}/services/${service_type}/instances`
969
+ );
970
+ }
610
971
  };
611
972
  var serviceInstancesClient = new ServiceInstancesClient();
612
973
 
613
974
  // src/client/projects/subsystems.ts
975
+ var logger5 = useLogger("service-instances-client");
614
976
  var SubsystemsClient = class {
615
977
  constructor() {
616
978
  this.getProjectSubsystems = (prjId) => {
979
+ logger5.info(`Get project ${prjId} subsystems`);
617
980
  return robotCloudApi_default.get(
618
981
  `projects/${prjId}/subsystems`
619
982
  );
620
983
  };
621
984
  this.getProjectSubsystem = (prjId, subsysId) => {
985
+ logger5.info(`Get subsystem ${subsysId} from project ${prjId}`);
622
986
  return robotCloudApi_default.get(
623
987
  `projects/${prjId}/subsystems/${subsysId}`
624
988
  );
625
989
  };
990
+ this.postProjectSubsystem = (prjId) => {
991
+ logger5.info(`Create subsystem in project ${prjId}`);
992
+ return robotCloudApi_default.post(
993
+ `projects/${prjId}/subsystems`
994
+ );
995
+ };
996
+ this.putProjectSubsystem = (prjId, subsysId) => {
997
+ logger5.info(`Update subsystem ${subsysId} in project ${prjId}`);
998
+ return robotCloudApi_default.put(
999
+ `projects/${prjId}/subsystems/${subsysId}`
1000
+ );
1001
+ };
1002
+ this.deleteSubsystem = (prjId, subsysId) => {
1003
+ logger5.info(`Delete subsystem ${subsysId} in project ${prjId}`);
1004
+ return robotCloudApi_default.delete(`projects/${prjId}/subsystems/${subsysId}`);
1005
+ };
1006
+ this.getProjectSubsystemLocations = (prjId, subsysId) => {
1007
+ logger5.info(`Get subsystems locations ${subsysId} in project ${prjId}`);
1008
+ return robotCloudApi_default.get(
1009
+ `projects/${prjId}/subsystems/${subsysId}/locations`
1010
+ );
1011
+ };
626
1012
  }
627
1013
  };
628
1014
  var subsystemsClient = new SubsystemsClient();
@@ -641,125 +1027,100 @@ var TagsClient = class {
641
1027
  logger6.info(`Get project ${prjId} tag ${tagId}`);
642
1028
  return robotCloudApi_default.get(`tags/${tagId}`);
643
1029
  };
1030
+ this.postTag = (prjId) => {
1031
+ logger6.info(`Create tag for project ${prjId}`);
1032
+ return robotCloudApi_default.post(`projects/${prjId}/tags`);
1033
+ };
1034
+ this.putTag = (prjId, tagId) => {
1035
+ logger6.info(`Modify project ${prjId} tag ${tagId}`);
1036
+ return robotCloudApi_default.put(`tags/${tagId}`);
1037
+ };
1038
+ this.deleteTag = (prjId, tagId) => {
1039
+ logger6.info(`Delete project ${prjId} tag ${tagId}`);
1040
+ return robotCloudApi_default.delete(`tags/${tagId}`);
1041
+ };
644
1042
  }
645
1043
  };
646
1044
  var tagsClient = new TagsClient();
647
1045
 
648
- // src/client/alerts.ts
649
- var ALERTS_BY_SERVICE_TYPE = {
650
- "RoomBLEPairing_1": [],
651
- "RoomClime_1": [
652
- "high_temperature",
653
- "low_temperature",
654
- "high_humidity",
655
- "fancoil_on_overtime"
656
- ],
657
- "RoomConsumes_1": [
658
- "high_daily_energy_electric",
659
- "high_daily_energy_thermal",
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;
1046
+ // src/client/index.ts
1047
+ var applicationsClient = new ApplicationsClient(robotCloudApi_default);
1048
+ var loginClient = new LoginClientImpl(robotCloudApi_default);
1049
+ var alertsClient = new AlertsClientImpl(robotCloudApi_default);
1050
+ var organizationsClient = new OrganizationsClient(robotCloudApi_default);
1051
+ var usersClient = new UsersClient(robotCloudApi_default);
1052
+
1053
+ // src/helpers/robotCloudToken.ts
1054
+ var logger7 = useLogger("robotcloud-token");
1055
+ function parseJwt(token) {
1056
+ if (!token) {
1057
+ return;
677
1058
  }
678
- getProjectStats(projectId, params) {
679
- return this.robotcloudApi.get(
680
- `projects/${projectId}/alerts/stats`,
681
- { params: params != null ? params : {} }
682
- );
1059
+ return JSON.parse(atob(token.split(".")[1]));
1060
+ }
1061
+ var decodeToken = (token) => {
1062
+ const payload = parseJwt(token);
1063
+ if (!payload) {
1064
+ return void 0;
683
1065
  }
684
- getProjectLog(projectId, params) {
685
- return this.robotcloudApi.get(
686
- `projects/${projectId}/alerts/log`,
1066
+ return payload;
1067
+ };
1068
+ var needRenew = (payload) => {
1069
+ const expirationDate = new Date(payload.exp * 1e3);
1070
+ expirationDate.setMinutes(
1071
+ expirationDate.getMinutes() - config_default.tokenMinutesBeforeExpirationRenew
1072
+ );
1073
+ const currentDate = /* @__PURE__ */ new Date();
1074
+ return currentDate >= expirationDate;
1075
+ };
1076
+ var isExpired = (payload) => {
1077
+ const expirationDate = new Date(payload.exp * 1e3);
1078
+ const currentDate = /* @__PURE__ */ new Date();
1079
+ return currentDate >= expirationDate;
1080
+ };
1081
+ var renewToken = async (renew_token) => {
1082
+ logger7.debug("Renewing token ...");
1083
+ const { data } = await loginClient.renewToken(renew_token);
1084
+ return {
1085
+ renewed: true,
1086
+ access: data["access"]["token"],
1087
+ renew: data["renew"]["token"]
1088
+ };
1089
+ };
1090
+ var validateToken = async (access_token) => {
1091
+ var _a, _b, _c;
1092
+ logger7.debug("Validate token ...");
1093
+ const payload = decodeToken(access_token);
1094
+ if (!payload) {
1095
+ return false;
1096
+ }
1097
+ const cloudUrl = robotCloudApi_default.defaults.baseURL;
1098
+ try {
1099
+ const { data } = await import_axios3.default.get(
1100
+ cloudUrl + `users/${payload.sub}`,
687
1101
  {
688
- params
1102
+ headers: {
1103
+ Authorization: `Bearer ${access_token}`
1104
+ }
689
1105
  }
690
1106
  );
691
- }
692
- acknowledge(projectId, data) {
693
- this.logger.debug("Sending put data: ", data);
694
- return this.robotcloudApi.put(
695
- `projects/${projectId}/alerts/log`,
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]);
1107
+ } catch (error) {
1108
+ if (import_axios3.default.isAxiosError(error)) {
1109
+ logger7.warn(`${error.message}: ${(_c = (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) != null ? _c : ""}`);
1110
+ } else {
1111
+ logger7.warn(error);
717
1112
  }
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
- };
1113
+ return false;
753
1114
  }
1115
+ return true;
754
1116
  };
755
- var usersClient = new UsersClient();
756
1117
 
757
1118
  // src/helpers/tags.ts
758
- var logger7 = useLogger("tags-helper");
1119
+ var logger8 = useLogger("tags-helper");
759
1120
  var TagsHelper = class {
760
1121
  constructor(tagsClient2) {
761
1122
  this.getTagsTree = async (prjId, maxDepth = 2, params) => {
762
- logger7.info(`Get project ${prjId} tags tree`);
1123
+ logger8.info(`Get project ${prjId} tags tree`);
763
1124
  if (!params) {
764
1125
  params = {};
765
1126
  }
@@ -774,7 +1135,7 @@ var TagsHelper = class {
774
1135
  return { root: tags };
775
1136
  };
776
1137
  this.getTagsChildren = async (prjId, level = 0, parent_id, params, maxDepth) => {
777
- logger7.debug(`Get project ${prjId} tags children: ${parent_id}`);
1138
+ logger8.debug(`Get project ${prjId} tags children: ${parent_id}`);
778
1139
  if (!params) {
779
1140
  params = {};
780
1141
  }
@@ -854,14 +1215,19 @@ var robotCloudPermissionsHelper = new RobotCloudPermissionsHelperImpl();
854
1215
  var tagsHelper = new TagsHelper(tagsClient);
855
1216
  // Annotate the CommonJS export names for ESM import in node:
856
1217
  0 && (module.exports = {
1218
+ ApplicationsClient,
1219
+ OrganizationsClient,
857
1220
  RobotCloudClientConfig,
858
1221
  RoomClimeClient,
1222
+ UsersClient,
859
1223
  airQualityClient,
860
1224
  alertsClient,
1225
+ applicationsClient,
861
1226
  classifiersClient,
862
1227
  clientConfig,
863
1228
  devicesClient,
864
1229
  locationsClient,
1230
+ loginClient,
865
1231
  organizationsClient,
866
1232
  projectsClient,
867
1233
  robotCloudPermissionsHelper,
@@ -869,6 +1235,7 @@ var tagsHelper = new TagsHelper(tagsClient);
869
1235
  robotcloudApi,
870
1236
  roomClimeClient,
871
1237
  roomConsumesClient,
1238
+ roomGroupingClient,
872
1239
  roomGuestStatusClient,
873
1240
  serviceInstancesClient,
874
1241
  subsystemsClient,