@robotbas/robotcloud-client 0.2.21 → 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-DmP793IB.d.mts → index-BsViQoY8.d.mts} +287 -99
- package/dist/{index-DmP793IB.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.mjs
CHANGED
|
@@ -76,74 +76,243 @@ __export(robotCloudToken_exports, {
|
|
|
76
76
|
renewToken: () => renewToken,
|
|
77
77
|
validateToken: () => validateToken
|
|
78
78
|
});
|
|
79
|
+
import axios3 from "axios";
|
|
80
|
+
|
|
81
|
+
// src/client/login.ts
|
|
79
82
|
import axios2 from "axios";
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
var LoginClientImpl = class {
|
|
84
|
+
constructor(robotcloudApi2) {
|
|
85
|
+
this.logger = useLogger("AlertsClientImpl");
|
|
86
|
+
this.robotcloudApi = robotcloudApi2;
|
|
84
87
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
async login(username, password, apiKey) {
|
|
89
|
+
try {
|
|
90
|
+
const encoded = btoa(`${username}:${password}`);
|
|
91
|
+
const basicString = `Basic ${encoded}`;
|
|
92
|
+
const cloudUrl = this.robotcloudApi.defaults.baseURL;
|
|
93
|
+
return await axios2.get(cloudUrl + "login", {
|
|
94
|
+
headers: {
|
|
95
|
+
Authorization: basicString,
|
|
96
|
+
"x-api-key": apiKey
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
} catch (error) {
|
|
100
|
+
this.logger.error("Error logging in", error);
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
91
103
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const expirationDate = new Date(payload.exp * 1e3);
|
|
104
|
-
const currentDate = /* @__PURE__ */ new Date();
|
|
105
|
-
return currentDate >= expirationDate;
|
|
106
|
-
};
|
|
107
|
-
var renewToken = async (renew_token) => {
|
|
108
|
-
logger2.debug("Renewing token ...");
|
|
109
|
-
const cloudUrl = robotCloudApi_default.defaults.baseURL;
|
|
110
|
-
const { data } = await axios2.get(cloudUrl + "login/renew", {
|
|
111
|
-
headers: {
|
|
112
|
-
Authorization: `Bearer ${renew_token}`
|
|
104
|
+
async renewToken(token) {
|
|
105
|
+
try {
|
|
106
|
+
const cloudUrl = this.robotcloudApi.defaults.baseURL;
|
|
107
|
+
return await axios2.get(cloudUrl + "login/renew", {
|
|
108
|
+
headers: {
|
|
109
|
+
Authorization: `Bearer ${token}`
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
} catch (error) {
|
|
113
|
+
this.logger.error("Error renewing token", error);
|
|
114
|
+
throw error;
|
|
113
115
|
}
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
renewed: true,
|
|
117
|
-
access: data["access"]["token"],
|
|
118
|
-
renew: data["renew"]["token"]
|
|
119
|
-
};
|
|
116
|
+
}
|
|
120
117
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
118
|
+
|
|
119
|
+
// src/client/alerts.ts
|
|
120
|
+
var ALERTS_BY_SERVICE_TYPE = {
|
|
121
|
+
"RoomBLEPairing_1": [],
|
|
122
|
+
"RoomClime_1": [
|
|
123
|
+
"high_temperature",
|
|
124
|
+
"low_temperature",
|
|
125
|
+
"high_humidity",
|
|
126
|
+
"fancoil_on_overtime"
|
|
127
|
+
],
|
|
128
|
+
"RoomConsumes_1": [
|
|
129
|
+
"high_daily_energy_electric",
|
|
130
|
+
"high_daily_energy_thermal",
|
|
131
|
+
"high_daily_hot_water",
|
|
132
|
+
"high_daily_cold_water"
|
|
133
|
+
],
|
|
134
|
+
"RoomDiagnostics_1": [
|
|
135
|
+
"low_peripheral_num"
|
|
136
|
+
],
|
|
137
|
+
"RoomGrouping_1": [],
|
|
138
|
+
"RoomGuestStatus_1": [
|
|
139
|
+
"door_open_overtime",
|
|
140
|
+
"window_open_overtime",
|
|
141
|
+
"medical_alarm"
|
|
142
|
+
]
|
|
143
|
+
};
|
|
144
|
+
var AlertsClientImpl = class {
|
|
145
|
+
constructor(robotcloudApi2) {
|
|
146
|
+
this.logger = useLogger("AlertsClientImpl");
|
|
147
|
+
this.robotcloudApi = robotcloudApi2;
|
|
127
148
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
149
|
+
getProjectStats(projectId, params) {
|
|
150
|
+
return this.robotcloudApi.get(
|
|
151
|
+
`projects/${projectId}/alerts/stats`,
|
|
152
|
+
{ params: params != null ? params : {} }
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
getProjectLog(projectId, params) {
|
|
156
|
+
return this.robotcloudApi.get(
|
|
157
|
+
`projects/${projectId}/alerts/log`,
|
|
132
158
|
{
|
|
133
|
-
|
|
134
|
-
Authorization: `Bearer ${access_token}`
|
|
135
|
-
}
|
|
159
|
+
params
|
|
136
160
|
}
|
|
137
161
|
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
162
|
+
}
|
|
163
|
+
acknowledge(projectId, data) {
|
|
164
|
+
this.logger.debug("Sending put data: ", data);
|
|
165
|
+
return this.robotcloudApi.put(
|
|
166
|
+
`projects/${projectId}/alerts/log`,
|
|
167
|
+
data
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
getAggregatedLogs(projectId, params) {
|
|
171
|
+
return this.robotcloudApi.get(
|
|
172
|
+
`projects/${projectId}/alerts/aggregate`,
|
|
173
|
+
{ params }
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
async getAvailableAlerts(projectId, params) {
|
|
177
|
+
const { data } = await this.robotcloudApi.get(
|
|
178
|
+
`projects/${projectId}/services`,
|
|
179
|
+
{ params: params != null ? params : {} }
|
|
180
|
+
);
|
|
181
|
+
let alerts = [];
|
|
182
|
+
for (const service of data) {
|
|
183
|
+
if (!(service.name in ALERTS_BY_SERVICE_TYPE)) {
|
|
184
|
+
this.logger.warn(`Service ${service.name} not found in ALERTS_BY_SERVICE_TYPE`);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
alerts.push(...ALERTS_BY_SERVICE_TYPE[service.name]);
|
|
143
188
|
}
|
|
144
|
-
return
|
|
189
|
+
return {
|
|
190
|
+
data: alerts
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
getServiceTypeAlertKeys(serviceType) {
|
|
194
|
+
return ALERTS_BY_SERVICE_TYPE[serviceType];
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// src/client/organizations.ts
|
|
199
|
+
var OrganizationsClient = class {
|
|
200
|
+
constructor(robotcloudApi2) {
|
|
201
|
+
this.logger = useLogger("OrganizationsClient");
|
|
202
|
+
this.getOrganizations = () => {
|
|
203
|
+
return this.robotcloudApi.get(`organizations`);
|
|
204
|
+
};
|
|
205
|
+
this.postOrganizations = () => {
|
|
206
|
+
return this.robotcloudApi.post(`organizations`);
|
|
207
|
+
};
|
|
208
|
+
this.getOrganization = (organizationId) => {
|
|
209
|
+
return this.robotcloudApi.get(
|
|
210
|
+
`organizations/${organizationId}`
|
|
211
|
+
);
|
|
212
|
+
};
|
|
213
|
+
this.putOrganization = (organizationId) => {
|
|
214
|
+
return this.robotcloudApi.put(
|
|
215
|
+
`organizations/${organizationId}`
|
|
216
|
+
);
|
|
217
|
+
};
|
|
218
|
+
this.deleteOrganization = (organizationId) => {
|
|
219
|
+
return this.robotcloudApi.delete(
|
|
220
|
+
`organizations/${organizationId}`
|
|
221
|
+
);
|
|
222
|
+
};
|
|
223
|
+
this.getOrganizationProjects = (organizationId) => {
|
|
224
|
+
return this.robotcloudApi.get(
|
|
225
|
+
`organizations/${organizationId}/projects`
|
|
226
|
+
);
|
|
227
|
+
};
|
|
228
|
+
this.postOrganizationProjects = (organizationId) => {
|
|
229
|
+
return this.robotcloudApi.post(
|
|
230
|
+
`organizations/${organizationId}/projects`
|
|
231
|
+
);
|
|
232
|
+
};
|
|
233
|
+
this.getOrganizationUsers = (organizationId) => {
|
|
234
|
+
return this.robotcloudApi.get(
|
|
235
|
+
`organizations/${organizationId}/users`
|
|
236
|
+
);
|
|
237
|
+
};
|
|
238
|
+
this.postOrganizationUsers = (organizationId) => {
|
|
239
|
+
return this.robotcloudApi.post(
|
|
240
|
+
`organizations/${organizationId}/users`
|
|
241
|
+
);
|
|
242
|
+
};
|
|
243
|
+
this.robotcloudApi = robotcloudApi2;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// src/client/users.ts
|
|
248
|
+
var UsersClient = class {
|
|
249
|
+
constructor(robotcloudApi2) {
|
|
250
|
+
this.logger = useLogger("UsersClient");
|
|
251
|
+
this.getUsers = () => {
|
|
252
|
+
return this.robotcloudApi.get(`users`);
|
|
253
|
+
};
|
|
254
|
+
this.getUser = (username) => {
|
|
255
|
+
return this.robotcloudApi.get(`users/${username}`);
|
|
256
|
+
};
|
|
257
|
+
this.putUser = (username) => {
|
|
258
|
+
return this.robotcloudApi.put(`users/${username}`);
|
|
259
|
+
};
|
|
260
|
+
this.deleteUser = (username) => {
|
|
261
|
+
return this.robotcloudApi.delete(`users/${username}`);
|
|
262
|
+
};
|
|
263
|
+
this.getUserOrganizations = (username) => {
|
|
264
|
+
return this.robotcloudApi.get(`users/${username}`);
|
|
265
|
+
};
|
|
266
|
+
this.getUserProjects = (username) => {
|
|
267
|
+
return this.robotcloudApi.get(
|
|
268
|
+
`users/${username}/projects`
|
|
269
|
+
);
|
|
270
|
+
};
|
|
271
|
+
this.postUserProjects = (username) => {
|
|
272
|
+
return this.robotcloudApi.post(
|
|
273
|
+
`users/${username}/projects`
|
|
274
|
+
);
|
|
275
|
+
};
|
|
276
|
+
this.getProjectToUser = (username, projectId) => {
|
|
277
|
+
return this.robotcloudApi.get(
|
|
278
|
+
`users/${username}/projects/${projectId}`
|
|
279
|
+
);
|
|
280
|
+
};
|
|
281
|
+
this.putProjectToUser = (username, projectId) => {
|
|
282
|
+
return this.robotcloudApi.put(
|
|
283
|
+
`users/${username}/projects/${projectId}`
|
|
284
|
+
);
|
|
285
|
+
};
|
|
286
|
+
this.deleteProjectToUser = (username, projectId) => {
|
|
287
|
+
return this.robotcloudApi.delete(
|
|
288
|
+
`users/${username}/projects/${projectId}`
|
|
289
|
+
);
|
|
290
|
+
};
|
|
291
|
+
this.robotcloudApi = robotcloudApi2;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// src/client/applications.ts
|
|
296
|
+
var ApplicationsClient = class {
|
|
297
|
+
constructor(robotcloudApi2) {
|
|
298
|
+
this.logger = useLogger("ApplicationsClient");
|
|
299
|
+
this.getApplications = () => {
|
|
300
|
+
return this.robotcloudApi.get(`application/register`);
|
|
301
|
+
};
|
|
302
|
+
this.postOrganizations = () => {
|
|
303
|
+
return this.robotcloudApi.post(`application/register`);
|
|
304
|
+
};
|
|
305
|
+
this.getApplication = (applicationId) => {
|
|
306
|
+
return this.robotcloudApi.get(`application/register/${applicationId}`);
|
|
307
|
+
};
|
|
308
|
+
this.putApplication = (applicationId) => {
|
|
309
|
+
return this.robotcloudApi.get(`application/register/${applicationId}`);
|
|
310
|
+
};
|
|
311
|
+
this.deleteApplication = (applicationId) => {
|
|
312
|
+
return this.robotcloudApi.get(`application/register/${applicationId}`);
|
|
313
|
+
};
|
|
314
|
+
this.robotcloudApi = robotcloudApi2;
|
|
145
315
|
}
|
|
146
|
-
return true;
|
|
147
316
|
};
|
|
148
317
|
|
|
149
318
|
// src/client/services/generics.ts
|
|
@@ -436,32 +605,68 @@ var RoomConsumesClient = class {
|
|
|
436
605
|
var roomConsumesClient = new RoomConsumesClient();
|
|
437
606
|
|
|
438
607
|
// src/client/projects/classifiers.ts
|
|
439
|
-
var
|
|
608
|
+
var logger2 = useLogger("classifiers-client");
|
|
440
609
|
var ClassifiersClient = class {
|
|
441
610
|
constructor() {
|
|
442
611
|
this.getProjectClassifiers = (prjId, params) => {
|
|
443
|
-
|
|
612
|
+
logger2.info(`Get project ${prjId} classifiers`);
|
|
444
613
|
return robotCloudApi_default.get(`projects/${prjId}/classifiers`, {
|
|
445
614
|
params
|
|
446
615
|
});
|
|
447
616
|
};
|
|
448
617
|
this.getClassifier = (classifierId) => {
|
|
449
|
-
return robotCloudApi_default.get(
|
|
618
|
+
return robotCloudApi_default.get(
|
|
619
|
+
`classifiers/${classifierId}`,
|
|
620
|
+
{}
|
|
621
|
+
);
|
|
622
|
+
};
|
|
623
|
+
this.putClassifier = (classifierId) => {
|
|
624
|
+
return robotCloudApi_default.put(
|
|
625
|
+
`classifiers/${classifierId}`,
|
|
626
|
+
{}
|
|
627
|
+
);
|
|
628
|
+
};
|
|
629
|
+
this.postClassifier = (classifierId) => {
|
|
630
|
+
return robotCloudApi_default.post(
|
|
631
|
+
`classifiers/${classifierId}`,
|
|
632
|
+
{}
|
|
633
|
+
);
|
|
634
|
+
};
|
|
635
|
+
this.deleteClassifier = (classifierId) => {
|
|
636
|
+
return robotCloudApi_default.delete(
|
|
637
|
+
`classifiers/${classifierId}`,
|
|
638
|
+
{}
|
|
639
|
+
);
|
|
450
640
|
};
|
|
451
641
|
}
|
|
452
642
|
};
|
|
453
643
|
var classifiersClient = new ClassifiersClient();
|
|
454
644
|
|
|
455
645
|
// src/client/projects/devices.ts
|
|
456
|
-
var
|
|
646
|
+
var logger3 = useLogger("devices-client");
|
|
457
647
|
var DevicesClient = class {
|
|
458
648
|
constructor() {
|
|
459
649
|
this.getProjectDevices = (projectId) => {
|
|
460
650
|
return robotCloudApi_default.get(`projects/${projectId}/devices`);
|
|
461
651
|
};
|
|
652
|
+
this.getProjectDevicesLocation = (locationId) => {
|
|
653
|
+
return robotCloudApi_default.get(`locations/${locationId}/devices`);
|
|
654
|
+
};
|
|
655
|
+
this.postProjectDeviceLocation = (locationId) => {
|
|
656
|
+
return robotCloudApi_default.post(`locations/${locationId}/devices`);
|
|
657
|
+
};
|
|
462
658
|
this.getDeviceDetails = (deviceId) => {
|
|
463
659
|
return robotCloudApi_default.get(`devices/${deviceId}`);
|
|
464
660
|
};
|
|
661
|
+
this.putDeviceDetails = (deviceId) => {
|
|
662
|
+
return robotCloudApi_default.put(`devices/${deviceId}`);
|
|
663
|
+
};
|
|
664
|
+
this.deleteDevice = (deviceId) => {
|
|
665
|
+
return robotCloudApi_default.delete(`devices/${deviceId}`);
|
|
666
|
+
};
|
|
667
|
+
this.getDeviceConfiguration = (deviceId) => {
|
|
668
|
+
return robotCloudApi_default.get(`devices/${deviceId}/compatibleconfigurationtypes`);
|
|
669
|
+
};
|
|
465
670
|
}
|
|
466
671
|
};
|
|
467
672
|
var devicesClient = new DevicesClient();
|
|
@@ -477,6 +682,14 @@ var LocationsClient = class {
|
|
|
477
682
|
}
|
|
478
683
|
);
|
|
479
684
|
};
|
|
685
|
+
this.postLocationServiceInstances = (prjId, locId, service_type, params) => {
|
|
686
|
+
return robotCloudApi_default.post(
|
|
687
|
+
`projects/${prjId}/locations/${locId}/services/${service_type}/instances`,
|
|
688
|
+
{
|
|
689
|
+
params
|
|
690
|
+
}
|
|
691
|
+
);
|
|
692
|
+
};
|
|
480
693
|
this.getLocations = (prjId, params) => {
|
|
481
694
|
return robotCloudApi_default.get(
|
|
482
695
|
`projects/${prjId}/locations`,
|
|
@@ -485,12 +698,32 @@ var LocationsClient = class {
|
|
|
485
698
|
}
|
|
486
699
|
);
|
|
487
700
|
};
|
|
701
|
+
this.postLocations = (prjId, params) => {
|
|
702
|
+
return robotCloudApi_default.post(
|
|
703
|
+
`projects/${prjId}/locations`,
|
|
704
|
+
{
|
|
705
|
+
params
|
|
706
|
+
}
|
|
707
|
+
);
|
|
708
|
+
};
|
|
488
709
|
this.getLocation = (locationId) => {
|
|
489
710
|
return robotCloudApi_default.get(
|
|
490
711
|
`locations/${locationId}`,
|
|
491
712
|
{}
|
|
492
713
|
);
|
|
493
714
|
};
|
|
715
|
+
this.putLocation = (locationId) => {
|
|
716
|
+
return robotCloudApi_default.put(
|
|
717
|
+
`locations/${locationId}`,
|
|
718
|
+
{}
|
|
719
|
+
);
|
|
720
|
+
};
|
|
721
|
+
this.deleteLocation = (locationId) => {
|
|
722
|
+
return robotCloudApi_default.delete(
|
|
723
|
+
`locations/${locationId}`,
|
|
724
|
+
{}
|
|
725
|
+
);
|
|
726
|
+
};
|
|
494
727
|
}
|
|
495
728
|
};
|
|
496
729
|
var locationsClient = new LocationsClient();
|
|
@@ -508,6 +741,29 @@ var ProjectsClient = class {
|
|
|
508
741
|
params
|
|
509
742
|
});
|
|
510
743
|
};
|
|
744
|
+
this.putProjectDetails = (prjId, params) => {
|
|
745
|
+
return robotCloudApi_default.put(`projects/${prjId}`, {
|
|
746
|
+
params
|
|
747
|
+
});
|
|
748
|
+
};
|
|
749
|
+
this.deleteProject = (prjId, params) => {
|
|
750
|
+
return robotCloudApi_default.delete(`projects/${prjId}`, {
|
|
751
|
+
params
|
|
752
|
+
});
|
|
753
|
+
};
|
|
754
|
+
this.getProjectUsers = (prjId, params) => {
|
|
755
|
+
return robotCloudApi_default.get(`projects/${prjId}/users`, {
|
|
756
|
+
params
|
|
757
|
+
});
|
|
758
|
+
};
|
|
759
|
+
this.getProjectInstances = (prjId, params) => {
|
|
760
|
+
return robotCloudApi_default.get(
|
|
761
|
+
`projects/${prjId}/instances`,
|
|
762
|
+
{
|
|
763
|
+
params
|
|
764
|
+
}
|
|
765
|
+
);
|
|
766
|
+
};
|
|
511
767
|
this.getProjectServiceTypes = (prjId, params) => {
|
|
512
768
|
return robotCloudApi_default.get(
|
|
513
769
|
`projects/${prjId}/services`,
|
|
@@ -516,12 +772,29 @@ var ProjectsClient = class {
|
|
|
516
772
|
}
|
|
517
773
|
);
|
|
518
774
|
};
|
|
775
|
+
this.getProjectApplications = (prjId, params) => {
|
|
776
|
+
return robotCloudApi_default.get(`projects/${prjId}/applications`, {
|
|
777
|
+
params
|
|
778
|
+
});
|
|
779
|
+
};
|
|
780
|
+
this.getProjectApplication = (prjId, appId) => {
|
|
781
|
+
return robotCloudApi_default.get(
|
|
782
|
+
`projects/${prjId}/applications/${appId}`,
|
|
783
|
+
{}
|
|
784
|
+
);
|
|
785
|
+
};
|
|
786
|
+
this.putProjectApplication = (prjId, appId) => {
|
|
787
|
+
return robotCloudApi_default.put(
|
|
788
|
+
`projects/${prjId}/applications/${appId}`,
|
|
789
|
+
{}
|
|
790
|
+
);
|
|
791
|
+
};
|
|
519
792
|
}
|
|
520
793
|
};
|
|
521
794
|
var projectsClient = new ProjectsClient();
|
|
522
795
|
|
|
523
796
|
// src/client/projects/service-instances.ts
|
|
524
|
-
var
|
|
797
|
+
var logger4 = useLogger("service-instances-client");
|
|
525
798
|
var ServiceInstancesClient = class {
|
|
526
799
|
constructor() {
|
|
527
800
|
this.getAll = (prjId, params) => {
|
|
@@ -561,18 +834,43 @@ var ServiceInstancesClient = class {
|
|
|
561
834
|
var serviceInstancesClient = new ServiceInstancesClient();
|
|
562
835
|
|
|
563
836
|
// src/client/projects/subsystems.ts
|
|
837
|
+
var logger5 = useLogger("service-instances-client");
|
|
564
838
|
var SubsystemsClient = class {
|
|
565
839
|
constructor() {
|
|
566
840
|
this.getProjectSubsystems = (prjId) => {
|
|
841
|
+
logger5.info(`Get project ${prjId} subsystems`);
|
|
567
842
|
return robotCloudApi_default.get(
|
|
568
843
|
`projects/${prjId}/subsystems`
|
|
569
844
|
);
|
|
570
845
|
};
|
|
571
846
|
this.getProjectSubsystem = (prjId, subsysId) => {
|
|
847
|
+
logger5.info(`Get subsystem ${subsysId} from project ${prjId}`);
|
|
572
848
|
return robotCloudApi_default.get(
|
|
573
849
|
`projects/${prjId}/subsystems/${subsysId}`
|
|
574
850
|
);
|
|
575
851
|
};
|
|
852
|
+
this.postProjectSubsystem = (prjId) => {
|
|
853
|
+
logger5.info(`Create subsystem in project ${prjId}`);
|
|
854
|
+
return robotCloudApi_default.post(
|
|
855
|
+
`projects/${prjId}/subsystems`
|
|
856
|
+
);
|
|
857
|
+
};
|
|
858
|
+
this.putProjectSubsystem = (prjId, subsysId) => {
|
|
859
|
+
logger5.info(`Update subsystem ${subsysId} in project ${prjId}`);
|
|
860
|
+
return robotCloudApi_default.put(
|
|
861
|
+
`projects/${prjId}/subsystems/${subsysId}`
|
|
862
|
+
);
|
|
863
|
+
};
|
|
864
|
+
this.deleteSubsystem = (prjId, subsysId) => {
|
|
865
|
+
logger5.info(`Delete subsystem ${subsysId} in project ${prjId}`);
|
|
866
|
+
return robotCloudApi_default.delete(`projects/${prjId}/subsystems/${subsysId}`);
|
|
867
|
+
};
|
|
868
|
+
this.getProjectSubsystemLocations = (prjId, subsysId) => {
|
|
869
|
+
logger5.info(`Get subsystems locations ${subsysId} in project ${prjId}`);
|
|
870
|
+
return robotCloudApi_default.get(
|
|
871
|
+
`projects/${prjId}/subsystems/${subsysId}/locations`
|
|
872
|
+
);
|
|
873
|
+
};
|
|
576
874
|
}
|
|
577
875
|
};
|
|
578
876
|
var subsystemsClient = new SubsystemsClient();
|
|
@@ -591,125 +889,100 @@ var TagsClient = class {
|
|
|
591
889
|
logger6.info(`Get project ${prjId} tag ${tagId}`);
|
|
592
890
|
return robotCloudApi_default.get(`tags/${tagId}`);
|
|
593
891
|
};
|
|
892
|
+
this.postTag = (prjId) => {
|
|
893
|
+
logger6.info(`Create tag for project ${prjId}`);
|
|
894
|
+
return robotCloudApi_default.post(`projects/${prjId}/tags`);
|
|
895
|
+
};
|
|
896
|
+
this.putTag = (prjId, tagId) => {
|
|
897
|
+
logger6.info(`Modify project ${prjId} tag ${tagId}`);
|
|
898
|
+
return robotCloudApi_default.put(`tags/${tagId}`);
|
|
899
|
+
};
|
|
900
|
+
this.deleteTag = (prjId, tagId) => {
|
|
901
|
+
logger6.info(`Delete project ${prjId} tag ${tagId}`);
|
|
902
|
+
return robotCloudApi_default.delete(`tags/${tagId}`);
|
|
903
|
+
};
|
|
594
904
|
}
|
|
595
905
|
};
|
|
596
906
|
var tagsClient = new TagsClient();
|
|
597
907
|
|
|
598
|
-
// src/client/
|
|
599
|
-
var
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
"high_daily_hot_water",
|
|
611
|
-
"high_daily_cold_water"
|
|
612
|
-
],
|
|
613
|
-
"RoomDiagnostics_1": [
|
|
614
|
-
"low_peripheral_num"
|
|
615
|
-
],
|
|
616
|
-
"RoomGrouping_1": [],
|
|
617
|
-
"RoomGuestStatus_1": [
|
|
618
|
-
"door_open_overtime",
|
|
619
|
-
"window_open_overtime",
|
|
620
|
-
"medical_alarm"
|
|
621
|
-
]
|
|
622
|
-
};
|
|
623
|
-
var AlertsClientImpl = class {
|
|
624
|
-
constructor(robotcloudApi2) {
|
|
625
|
-
this.logger = useLogger("AlertsClientImpl");
|
|
626
|
-
this.robotcloudApi = robotcloudApi2;
|
|
908
|
+
// src/client/index.ts
|
|
909
|
+
var applicationsClient = new ApplicationsClient(robotCloudApi_default);
|
|
910
|
+
var loginClient = new LoginClientImpl(robotCloudApi_default);
|
|
911
|
+
var alertsClient = new AlertsClientImpl(robotCloudApi_default);
|
|
912
|
+
var organizationsClient = new OrganizationsClient(robotCloudApi_default);
|
|
913
|
+
var usersClient = new UsersClient(robotCloudApi_default);
|
|
914
|
+
|
|
915
|
+
// src/helpers/robotCloudToken.ts
|
|
916
|
+
var logger7 = useLogger("robotcloud-token");
|
|
917
|
+
function parseJwt(token) {
|
|
918
|
+
if (!token) {
|
|
919
|
+
return;
|
|
627
920
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
921
|
+
return JSON.parse(atob(token.split(".")[1]));
|
|
922
|
+
}
|
|
923
|
+
var decodeToken = (token) => {
|
|
924
|
+
const payload = parseJwt(token);
|
|
925
|
+
if (!payload) {
|
|
926
|
+
return void 0;
|
|
633
927
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
928
|
+
return payload;
|
|
929
|
+
};
|
|
930
|
+
var needRenew = (payload) => {
|
|
931
|
+
const expirationDate = new Date(payload.exp * 1e3);
|
|
932
|
+
expirationDate.setMinutes(
|
|
933
|
+
expirationDate.getMinutes() - config_default.tokenMinutesBeforeExpirationRenew
|
|
934
|
+
);
|
|
935
|
+
const currentDate = /* @__PURE__ */ new Date();
|
|
936
|
+
return currentDate >= expirationDate;
|
|
937
|
+
};
|
|
938
|
+
var isExpired = (payload) => {
|
|
939
|
+
const expirationDate = new Date(payload.exp * 1e3);
|
|
940
|
+
const currentDate = /* @__PURE__ */ new Date();
|
|
941
|
+
return currentDate >= expirationDate;
|
|
942
|
+
};
|
|
943
|
+
var renewToken = async (renew_token) => {
|
|
944
|
+
logger7.debug("Renewing token ...");
|
|
945
|
+
const { data } = await loginClient.renewToken(renew_token);
|
|
946
|
+
return {
|
|
947
|
+
renewed: true,
|
|
948
|
+
access: data["access"]["token"],
|
|
949
|
+
renew: data["renew"]["token"]
|
|
950
|
+
};
|
|
951
|
+
};
|
|
952
|
+
var validateToken = async (access_token) => {
|
|
953
|
+
var _a, _b, _c;
|
|
954
|
+
logger7.debug("Validate token ...");
|
|
955
|
+
const payload = decodeToken(access_token);
|
|
956
|
+
if (!payload) {
|
|
957
|
+
return false;
|
|
958
|
+
}
|
|
959
|
+
const cloudUrl = robotCloudApi_default.defaults.baseURL;
|
|
960
|
+
try {
|
|
961
|
+
const { data } = await axios3.get(
|
|
962
|
+
cloudUrl + `users/${payload.sub}`,
|
|
637
963
|
{
|
|
638
|
-
|
|
964
|
+
headers: {
|
|
965
|
+
Authorization: `Bearer ${access_token}`
|
|
966
|
+
}
|
|
639
967
|
}
|
|
640
968
|
);
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
data
|
|
647
|
-
);
|
|
648
|
-
}
|
|
649
|
-
getAggregatedLogs(projectId, params) {
|
|
650
|
-
return this.robotcloudApi.get(
|
|
651
|
-
`projects/${projectId}/alerts/aggregate`,
|
|
652
|
-
{ params }
|
|
653
|
-
);
|
|
654
|
-
}
|
|
655
|
-
async getAvailableAlerts(projectId, params) {
|
|
656
|
-
const { data } = await this.robotcloudApi.get(
|
|
657
|
-
`projects/${projectId}/services`,
|
|
658
|
-
{ params: params != null ? params : {} }
|
|
659
|
-
);
|
|
660
|
-
let alerts = [];
|
|
661
|
-
for (const service of data) {
|
|
662
|
-
if (!(service.name in ALERTS_BY_SERVICE_TYPE)) {
|
|
663
|
-
this.logger.warn(`Service ${service.name} not found in ALERTS_BY_SERVICE_TYPE`);
|
|
664
|
-
continue;
|
|
665
|
-
}
|
|
666
|
-
alerts.push(...ALERTS_BY_SERVICE_TYPE[service.name]);
|
|
969
|
+
} catch (error) {
|
|
970
|
+
if (axios3.isAxiosError(error)) {
|
|
971
|
+
logger7.warn(`${error.message}: ${(_c = (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) != null ? _c : ""}`);
|
|
972
|
+
} else {
|
|
973
|
+
logger7.warn(error);
|
|
667
974
|
}
|
|
668
|
-
return
|
|
669
|
-
data: alerts
|
|
670
|
-
};
|
|
671
|
-
}
|
|
672
|
-
};
|
|
673
|
-
var alertsClient = new AlertsClientImpl(robotCloudApi_default);
|
|
674
|
-
|
|
675
|
-
// src/client/organizations.ts
|
|
676
|
-
var OrganizationsClient = class {
|
|
677
|
-
constructor() {
|
|
678
|
-
this.getOrganization = (organizationId) => {
|
|
679
|
-
return robotCloudApi_default.get(
|
|
680
|
-
`organizations/${organizationId}`
|
|
681
|
-
);
|
|
682
|
-
};
|
|
683
|
-
this.getOrganizationProjects = (organizationId) => {
|
|
684
|
-
return robotCloudApi_default.get(
|
|
685
|
-
`organizations/${organizationId}/projects`
|
|
686
|
-
);
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
|
-
};
|
|
690
|
-
var organizationsClient = new OrganizationsClient();
|
|
691
|
-
|
|
692
|
-
// src/client/users.ts
|
|
693
|
-
var UsersClient = class {
|
|
694
|
-
constructor() {
|
|
695
|
-
this.getUser = (username) => {
|
|
696
|
-
return robotCloudApi_default.get(`users/${username}`);
|
|
697
|
-
};
|
|
698
|
-
this.getUserProjects = (username) => {
|
|
699
|
-
return robotCloudApi_default.get(
|
|
700
|
-
`users/${username}/projects`
|
|
701
|
-
);
|
|
702
|
-
};
|
|
975
|
+
return false;
|
|
703
976
|
}
|
|
977
|
+
return true;
|
|
704
978
|
};
|
|
705
|
-
var usersClient = new UsersClient();
|
|
706
979
|
|
|
707
980
|
// src/helpers/tags.ts
|
|
708
|
-
var
|
|
981
|
+
var logger8 = useLogger("tags-helper");
|
|
709
982
|
var TagsHelper = class {
|
|
710
983
|
constructor(tagsClient2) {
|
|
711
984
|
this.getTagsTree = async (prjId, maxDepth = 2, params) => {
|
|
712
|
-
|
|
985
|
+
logger8.info(`Get project ${prjId} tags tree`);
|
|
713
986
|
if (!params) {
|
|
714
987
|
params = {};
|
|
715
988
|
}
|
|
@@ -724,7 +997,7 @@ var TagsHelper = class {
|
|
|
724
997
|
return { root: tags };
|
|
725
998
|
};
|
|
726
999
|
this.getTagsChildren = async (prjId, level = 0, parent_id, params, maxDepth) => {
|
|
727
|
-
|
|
1000
|
+
logger8.debug(`Get project ${prjId} tags children: ${parent_id}`);
|
|
728
1001
|
if (!params) {
|
|
729
1002
|
params = {};
|
|
730
1003
|
}
|
|
@@ -803,14 +1076,19 @@ var robotCloudPermissionsHelper = new RobotCloudPermissionsHelperImpl();
|
|
|
803
1076
|
// src/helpers/index.ts
|
|
804
1077
|
var tagsHelper = new TagsHelper(tagsClient);
|
|
805
1078
|
export {
|
|
1079
|
+
ApplicationsClient,
|
|
1080
|
+
OrganizationsClient,
|
|
806
1081
|
RobotCloudClientConfig,
|
|
807
1082
|
RoomClimeClient,
|
|
1083
|
+
UsersClient,
|
|
808
1084
|
airQualityClient,
|
|
809
1085
|
alertsClient,
|
|
1086
|
+
applicationsClient,
|
|
810
1087
|
classifiersClient,
|
|
811
1088
|
config_default as clientConfig,
|
|
812
1089
|
devicesClient,
|
|
813
1090
|
locationsClient,
|
|
1091
|
+
loginClient,
|
|
814
1092
|
organizationsClient,
|
|
815
1093
|
projectsClient,
|
|
816
1094
|
robotCloudPermissionsHelper,
|