@robotbas/robotcloud-client 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/dist/RobotCloudClient.d-L7OLs5ZS.d.mts +180 -0
- package/dist/RobotCloudClient.d-L7OLs5ZS.d.ts +180 -0
- package/dist/helpers/index.d.mts +9 -0
- package/dist/helpers/index.d.ts +9 -0
- package/dist/helpers/index.js +110 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/index.mjs +73 -0
- package/dist/helpers/index.mjs.map +1 -0
- package/dist/index.d.mts +272 -0
- package/dist/index.d.ts +272 -0
- package/dist/index.js +560 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +522 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +49 -0
- package/types/ProjectClassifer.d.ts +5 -0
- package/types/ProjectTag.d.ts +14 -0
- package/types/RobotCloudClient.d.ts +179 -0
- package/types/ServiceInstance.d.ts +12 -0
- package/types/ServiceInstanceRead.d.ts +5 -0
- package/types/Token.d.ts +12 -0
- package/types/helpers.d.ts +5 -0
- package/types/services.d.ts +108 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# TYPESCRIPT ROBOTCLOUD API CLIENT
|
|
2
|
+
|
|
3
|
+
Typescript library to access robotcloud endpoints.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn add @robotbas/robotcloud-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Configure authentication interceptor
|
|
12
|
+
|
|
13
|
+
Example used on a nuxtjs middleware to setup the RobotCloud API token.
|
|
14
|
+
```typescript
|
|
15
|
+
import robotcloudApi, { setCheckTokenFunction } from "robotcloud-client";
|
|
16
|
+
|
|
17
|
+
const appConfigs = useRuntimeConfig().public; // Get aplication global configs
|
|
18
|
+
robotcloudApi.defaults.baseURL = appConfigs.robotCloudUrl
|
|
19
|
+
setCheckTokenFunction(async () => {
|
|
20
|
+
const token = await getAccessToken()
|
|
21
|
+
if (!token) {
|
|
22
|
+
await navigateTo(appConfigs.loginUrl, { external: true })
|
|
23
|
+
return ''
|
|
24
|
+
}
|
|
25
|
+
return token
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
type TemperatureUnit = "CELSIUS" | "FAHRENHEIT"
|
|
2
|
+
type RegimState = "COLD"|"HEAT"|"AUTO"
|
|
3
|
+
|
|
4
|
+
type ProjectAccessLevel = "BLOCKED" | "RESTRICTED" | "BASIC" | "ADVANCED"
|
|
5
|
+
type AppAccessLevel = "BLOCKED" | "STANDARD" | "ADVANCED" | "ADMIN"
|
|
6
|
+
|
|
7
|
+
type RobotCloudServiceType = "RoomClime_1"|"RoomGuestStatus_1"|"AirQuality_1"
|
|
8
|
+
|
|
9
|
+
// Desired fancoil speed (0 = Auto, 1..3 = Manual Speed)
|
|
10
|
+
type FancoilSpeedState = 0|1|2|3;
|
|
11
|
+
|
|
12
|
+
interface ProjectRequestParams {
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface ProjectDetailsRequestParams {
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
interface SubsystemRequestParams {
|
|
20
|
+
subsystem_id?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface PaginableRequestParams {
|
|
24
|
+
startIndex?: number;
|
|
25
|
+
maxSize?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ProjectLocationsRequestParams extends SubsystemRequestParams, PaginableRequestParams {
|
|
29
|
+
tag_id?: string | string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
interface ServiceInstanceDataRequestParams {
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface ProjectTagRequestParams extends PaginableRequestParams {
|
|
38
|
+
parent_tag?: string;
|
|
39
|
+
no_parent?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface ServiceInstancesRequestParams extends SubsystemRequestParams, PaginableRequestParams {
|
|
43
|
+
id?: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
location_id?: string;
|
|
46
|
+
device_id?: string;
|
|
47
|
+
tag_id?: string[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface LocationServiceInstancesRequestParams extends SubsystemRequestParams, PaginableRequestParams {
|
|
51
|
+
tag_id?: string[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface RoomClimeInstanceConfigParams {
|
|
55
|
+
temperature_set_point?: number;
|
|
56
|
+
humidity_set_point?: number;
|
|
57
|
+
regim?: RegimState;
|
|
58
|
+
eco_mode?: "STANDBY" | "ECO" | "VIP";
|
|
59
|
+
fancoil_speed?: 0 | 1 | 2 | 3;
|
|
60
|
+
on?: boolean;
|
|
61
|
+
high_temperature_level?: number;
|
|
62
|
+
low_temperature_level?: number;
|
|
63
|
+
high_humidity_level?: number;
|
|
64
|
+
fancoil_on_time_limit?: number;
|
|
65
|
+
temperature_units?: TemperatureUnit;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
/** RESPONSE **/
|
|
70
|
+
|
|
71
|
+
interface RobotCloudNamedItem {
|
|
72
|
+
id: string;
|
|
73
|
+
name: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface RobotCloudProject {
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
organization: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** USERS */
|
|
83
|
+
interface RobotCloudUserDetails {
|
|
84
|
+
username: string;
|
|
85
|
+
name: string;
|
|
86
|
+
last_name: string;
|
|
87
|
+
email: string;
|
|
88
|
+
org_id: string;
|
|
89
|
+
org_access: number;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
interface RobotCloudProjectDetails extends RobotCloudProject {
|
|
94
|
+
version: number;
|
|
95
|
+
description?: string;
|
|
96
|
+
country?: string;
|
|
97
|
+
timezone?: string;
|
|
98
|
+
image_url?: string;
|
|
99
|
+
longitude?: number;
|
|
100
|
+
latitude?: number;
|
|
101
|
+
application_enabled?: boolean;
|
|
102
|
+
access_level?: ProjectAccessLevel;
|
|
103
|
+
app_access_level?: AppAccessLevel;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface RobotCloudDeviceDetails extends RobotCloudNamedItem {
|
|
107
|
+
description?: string;
|
|
108
|
+
location: string;
|
|
109
|
+
address: {
|
|
110
|
+
domain: number;
|
|
111
|
+
zone: number;
|
|
112
|
+
id: number;
|
|
113
|
+
};
|
|
114
|
+
type: number;
|
|
115
|
+
configuration_type: string;
|
|
116
|
+
tags: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
interface RobotCloudServiceTypeDetails {
|
|
120
|
+
description: string;
|
|
121
|
+
name: RobotCloudServiceType
|
|
122
|
+
}
|
|
123
|
+
/** SERVICE EVENTS VALUES **/
|
|
124
|
+
interface RoomClime1AlertEventValue {
|
|
125
|
+
high_temperature: boolean;
|
|
126
|
+
low_temperature: boolean;
|
|
127
|
+
high_humidity: boolean;
|
|
128
|
+
fancoil_on_overtime: boolean;
|
|
129
|
+
}
|
|
130
|
+
interface RoomClime1EventValue {
|
|
131
|
+
temperature: number;
|
|
132
|
+
humidity: number;
|
|
133
|
+
fancoil_speed: number;
|
|
134
|
+
fancoil_manual: boolean;
|
|
135
|
+
on: boolean;
|
|
136
|
+
temperature_set_point: number;
|
|
137
|
+
humidity_set_point: number;
|
|
138
|
+
regim: RegimState;
|
|
139
|
+
eco_mode: "STANDBY"|"ECO"|"VIP";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
interface RoomConsumes1AlertEventValue {
|
|
143
|
+
high_daily_energy_electric: boolean;
|
|
144
|
+
high_daily_energy_thermal: boolean;
|
|
145
|
+
high_daily_hot_water: boolean;
|
|
146
|
+
high_daily_cold_water: boolean;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
interface RoomGrouping1DataEventValue {
|
|
150
|
+
replica_1_active: boolean;
|
|
151
|
+
replica_2_active: boolean;
|
|
152
|
+
replica_3_active: boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface RoomConsumes1DataEventValue {
|
|
156
|
+
energy_electric: number;
|
|
157
|
+
energy_thermal: number;
|
|
158
|
+
hot_water: number;
|
|
159
|
+
cold_water: number;
|
|
160
|
+
daily_energy_electric: number;
|
|
161
|
+
daily_energy_thermal: number;
|
|
162
|
+
daily_hot_water: number;
|
|
163
|
+
daily_cold_water: number;
|
|
164
|
+
daily_co2_footprint: number;
|
|
165
|
+
daily_tree_equivalent: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** SERVICE INSTANCES DEVICE CONFIG */
|
|
169
|
+
interface ServiceInstanceDeviceConfig {
|
|
170
|
+
device: string;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
interface RoomGrouping1InstanceDeviceConfig {
|
|
174
|
+
Main: ServiceInstanceDeviceConfig;
|
|
175
|
+
Replica_1: ServiceInstanceDeviceConfig;
|
|
176
|
+
Replica_2: ServiceInstanceDeviceConfig;
|
|
177
|
+
Replica_3: ServiceInstanceDeviceConfig;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type { AppAccessLevel as A, FancoilSpeedState as F, LocationServiceInstancesRequestParams as L, ProjectRequestParams as P, RobotCloudNamedItem as R, SubsystemRequestParams as S, TemperatureUnit as T, RobotCloudServiceType as a, RobotCloudUserDetails as b, RobotCloudProject as c, ProjectDetailsRequestParams as d, RobotCloudProjectDetails as e, ProjectLocationsRequestParams as f, ServiceInstancesRequestParams as g, ProjectTagRequestParams as h, RobotCloudDeviceDetails as i, RobotCloudServiceTypeDetails as j, RoomGrouping1DataEventValue as k, ServiceInstanceDataRequestParams as l, RoomConsumes1DataEventValue as m, RoomGrouping1InstanceDeviceConfig as n, RoomClime1AlertEventValue as o, RoomClime1EventValue as p, RoomClimeInstanceConfigParams as q, RoomConsumes1AlertEventValue as r, RegimState as s, ProjectAccessLevel as t, PaginableRequestParams as u, ServiceInstanceDeviceConfig as v };
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
type TemperatureUnit = "CELSIUS" | "FAHRENHEIT"
|
|
2
|
+
type RegimState = "COLD"|"HEAT"|"AUTO"
|
|
3
|
+
|
|
4
|
+
type ProjectAccessLevel = "BLOCKED" | "RESTRICTED" | "BASIC" | "ADVANCED"
|
|
5
|
+
type AppAccessLevel = "BLOCKED" | "STANDARD" | "ADVANCED" | "ADMIN"
|
|
6
|
+
|
|
7
|
+
type RobotCloudServiceType = "RoomClime_1"|"RoomGuestStatus_1"|"AirQuality_1"
|
|
8
|
+
|
|
9
|
+
// Desired fancoil speed (0 = Auto, 1..3 = Manual Speed)
|
|
10
|
+
type FancoilSpeedState = 0|1|2|3;
|
|
11
|
+
|
|
12
|
+
interface ProjectRequestParams {
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface ProjectDetailsRequestParams {
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
interface SubsystemRequestParams {
|
|
20
|
+
subsystem_id?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface PaginableRequestParams {
|
|
24
|
+
startIndex?: number;
|
|
25
|
+
maxSize?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ProjectLocationsRequestParams extends SubsystemRequestParams, PaginableRequestParams {
|
|
29
|
+
tag_id?: string | string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
interface ServiceInstanceDataRequestParams {
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface ProjectTagRequestParams extends PaginableRequestParams {
|
|
38
|
+
parent_tag?: string;
|
|
39
|
+
no_parent?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface ServiceInstancesRequestParams extends SubsystemRequestParams, PaginableRequestParams {
|
|
43
|
+
id?: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
location_id?: string;
|
|
46
|
+
device_id?: string;
|
|
47
|
+
tag_id?: string[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface LocationServiceInstancesRequestParams extends SubsystemRequestParams, PaginableRequestParams {
|
|
51
|
+
tag_id?: string[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface RoomClimeInstanceConfigParams {
|
|
55
|
+
temperature_set_point?: number;
|
|
56
|
+
humidity_set_point?: number;
|
|
57
|
+
regim?: RegimState;
|
|
58
|
+
eco_mode?: "STANDBY" | "ECO" | "VIP";
|
|
59
|
+
fancoil_speed?: 0 | 1 | 2 | 3;
|
|
60
|
+
on?: boolean;
|
|
61
|
+
high_temperature_level?: number;
|
|
62
|
+
low_temperature_level?: number;
|
|
63
|
+
high_humidity_level?: number;
|
|
64
|
+
fancoil_on_time_limit?: number;
|
|
65
|
+
temperature_units?: TemperatureUnit;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
/** RESPONSE **/
|
|
70
|
+
|
|
71
|
+
interface RobotCloudNamedItem {
|
|
72
|
+
id: string;
|
|
73
|
+
name: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface RobotCloudProject {
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
organization: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** USERS */
|
|
83
|
+
interface RobotCloudUserDetails {
|
|
84
|
+
username: string;
|
|
85
|
+
name: string;
|
|
86
|
+
last_name: string;
|
|
87
|
+
email: string;
|
|
88
|
+
org_id: string;
|
|
89
|
+
org_access: number;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
interface RobotCloudProjectDetails extends RobotCloudProject {
|
|
94
|
+
version: number;
|
|
95
|
+
description?: string;
|
|
96
|
+
country?: string;
|
|
97
|
+
timezone?: string;
|
|
98
|
+
image_url?: string;
|
|
99
|
+
longitude?: number;
|
|
100
|
+
latitude?: number;
|
|
101
|
+
application_enabled?: boolean;
|
|
102
|
+
access_level?: ProjectAccessLevel;
|
|
103
|
+
app_access_level?: AppAccessLevel;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface RobotCloudDeviceDetails extends RobotCloudNamedItem {
|
|
107
|
+
description?: string;
|
|
108
|
+
location: string;
|
|
109
|
+
address: {
|
|
110
|
+
domain: number;
|
|
111
|
+
zone: number;
|
|
112
|
+
id: number;
|
|
113
|
+
};
|
|
114
|
+
type: number;
|
|
115
|
+
configuration_type: string;
|
|
116
|
+
tags: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
interface RobotCloudServiceTypeDetails {
|
|
120
|
+
description: string;
|
|
121
|
+
name: RobotCloudServiceType
|
|
122
|
+
}
|
|
123
|
+
/** SERVICE EVENTS VALUES **/
|
|
124
|
+
interface RoomClime1AlertEventValue {
|
|
125
|
+
high_temperature: boolean;
|
|
126
|
+
low_temperature: boolean;
|
|
127
|
+
high_humidity: boolean;
|
|
128
|
+
fancoil_on_overtime: boolean;
|
|
129
|
+
}
|
|
130
|
+
interface RoomClime1EventValue {
|
|
131
|
+
temperature: number;
|
|
132
|
+
humidity: number;
|
|
133
|
+
fancoil_speed: number;
|
|
134
|
+
fancoil_manual: boolean;
|
|
135
|
+
on: boolean;
|
|
136
|
+
temperature_set_point: number;
|
|
137
|
+
humidity_set_point: number;
|
|
138
|
+
regim: RegimState;
|
|
139
|
+
eco_mode: "STANDBY"|"ECO"|"VIP";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
interface RoomConsumes1AlertEventValue {
|
|
143
|
+
high_daily_energy_electric: boolean;
|
|
144
|
+
high_daily_energy_thermal: boolean;
|
|
145
|
+
high_daily_hot_water: boolean;
|
|
146
|
+
high_daily_cold_water: boolean;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
interface RoomGrouping1DataEventValue {
|
|
150
|
+
replica_1_active: boolean;
|
|
151
|
+
replica_2_active: boolean;
|
|
152
|
+
replica_3_active: boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
interface RoomConsumes1DataEventValue {
|
|
156
|
+
energy_electric: number;
|
|
157
|
+
energy_thermal: number;
|
|
158
|
+
hot_water: number;
|
|
159
|
+
cold_water: number;
|
|
160
|
+
daily_energy_electric: number;
|
|
161
|
+
daily_energy_thermal: number;
|
|
162
|
+
daily_hot_water: number;
|
|
163
|
+
daily_cold_water: number;
|
|
164
|
+
daily_co2_footprint: number;
|
|
165
|
+
daily_tree_equivalent: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** SERVICE INSTANCES DEVICE CONFIG */
|
|
169
|
+
interface ServiceInstanceDeviceConfig {
|
|
170
|
+
device: string;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
interface RoomGrouping1InstanceDeviceConfig {
|
|
174
|
+
Main: ServiceInstanceDeviceConfig;
|
|
175
|
+
Replica_1: ServiceInstanceDeviceConfig;
|
|
176
|
+
Replica_2: ServiceInstanceDeviceConfig;
|
|
177
|
+
Replica_3: ServiceInstanceDeviceConfig;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type { AppAccessLevel as A, FancoilSpeedState as F, LocationServiceInstancesRequestParams as L, ProjectRequestParams as P, RobotCloudNamedItem as R, SubsystemRequestParams as S, TemperatureUnit as T, RobotCloudServiceType as a, RobotCloudUserDetails as b, RobotCloudProject as c, ProjectDetailsRequestParams as d, RobotCloudProjectDetails as e, ProjectLocationsRequestParams as f, ServiceInstancesRequestParams as g, ProjectTagRequestParams as h, RobotCloudDeviceDetails as i, RobotCloudServiceTypeDetails as j, RoomGrouping1DataEventValue as k, ServiceInstanceDataRequestParams as l, RoomConsumes1DataEventValue as m, RoomGrouping1InstanceDeviceConfig as n, RoomClime1AlertEventValue as o, RoomClime1EventValue as p, RoomClimeInstanceConfigParams as q, RoomConsumes1AlertEventValue as r, RegimState as s, ProjectAccessLevel as t, PaginableRequestParams as u, ServiceInstanceDeviceConfig as v };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { t as ProjectAccessLevel } from '../RobotCloudClient.d-L7OLs5ZS.mjs';
|
|
2
|
+
|
|
3
|
+
interface RobotCloudPermissionsHelper {
|
|
4
|
+
checkProjectAccess(prjId: string, required_project_access: ProjectAccessLevel): Promise<boolean>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare const robotCloudPermissionsHelper: RobotCloudPermissionsHelper;
|
|
8
|
+
|
|
9
|
+
export { type RobotCloudPermissionsHelper, robotCloudPermissionsHelper };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { t as ProjectAccessLevel } from '../RobotCloudClient.d-L7OLs5ZS.js';
|
|
2
|
+
|
|
3
|
+
interface RobotCloudPermissionsHelper {
|
|
4
|
+
checkProjectAccess(prjId: string, required_project_access: ProjectAccessLevel): Promise<boolean>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare const robotCloudPermissionsHelper: RobotCloudPermissionsHelper;
|
|
8
|
+
|
|
9
|
+
export { type RobotCloudPermissionsHelper, robotCloudPermissionsHelper };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/helpers/index.ts
|
|
31
|
+
var helpers_exports = {};
|
|
32
|
+
__export(helpers_exports, {
|
|
33
|
+
robotCloudPermissionsHelper: () => robotCloudPermissionsHelper
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
36
|
+
|
|
37
|
+
// src/utils/logger.ts
|
|
38
|
+
var import_consola = require("consola");
|
|
39
|
+
function useLogger(tag, options = { level: 1e3 }) {
|
|
40
|
+
return tag ? (0, import_consola.createConsola)(options).withTag(tag) : (0, import_consola.createConsola)(options);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/robotCloudApi.ts
|
|
44
|
+
var import_axios = __toESM(require("axios"));
|
|
45
|
+
var logger = useLogger("robotcloud-api");
|
|
46
|
+
var robotcloudApi = import_axios.default.create();
|
|
47
|
+
var checkTokenPromise = null;
|
|
48
|
+
var clearPromise = () => checkTokenPromise = null;
|
|
49
|
+
async function refreshToken(checkToken2) {
|
|
50
|
+
const access_token = await checkToken2();
|
|
51
|
+
return access_token;
|
|
52
|
+
}
|
|
53
|
+
var checkToken = async () => {
|
|
54
|
+
return "";
|
|
55
|
+
};
|
|
56
|
+
robotcloudApi.interceptors.request.use(
|
|
57
|
+
async (config) => {
|
|
58
|
+
logger.info("robotcloud api interceptor:", config.url);
|
|
59
|
+
if (!checkTokenPromise) {
|
|
60
|
+
checkTokenPromise = refreshToken(checkToken).finally(clearPromise);
|
|
61
|
+
}
|
|
62
|
+
const token = await checkTokenPromise;
|
|
63
|
+
if (!token) {
|
|
64
|
+
return config;
|
|
65
|
+
}
|
|
66
|
+
config.headers.authorization = `Bearer ${token}`;
|
|
67
|
+
return config;
|
|
68
|
+
},
|
|
69
|
+
(error) => {
|
|
70
|
+
logger.error(error);
|
|
71
|
+
Promise.reject(error);
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
var robotCloudApi_default = robotcloudApi;
|
|
75
|
+
|
|
76
|
+
// src/robotCloudClient.ts
|
|
77
|
+
var logger2 = useLogger("robotcloud-client");
|
|
78
|
+
var getProjectDetails = (prjId, params) => {
|
|
79
|
+
return robotCloudApi_default.get(`projects/${prjId}`, {
|
|
80
|
+
params
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/helpers/robotCloudPermissionsHelper.ts
|
|
85
|
+
var RobotCloudPermissionsHelperImpl = class {
|
|
86
|
+
async checkProjectAccess(prjId, required_project_access) {
|
|
87
|
+
const { data: project } = await getProjectDetails(prjId);
|
|
88
|
+
if (project.access_level == required_project_access) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
switch (required_project_access) {
|
|
92
|
+
case "ADVANCED":
|
|
93
|
+
return project.access_level == "ADVANCED";
|
|
94
|
+
case "BASIC":
|
|
95
|
+
return project.access_level == "BASIC" || project.access_level == "ADVANCED";
|
|
96
|
+
case "RESTRICTED":
|
|
97
|
+
return project.access_level == "RESTRICTED" || project.access_level == "BASIC" || project.access_level == "ADVANCED";
|
|
98
|
+
case "BLOCKED":
|
|
99
|
+
return true;
|
|
100
|
+
default:
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var robotCloudPermissionsHelper = new RobotCloudPermissionsHelperImpl();
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
robotCloudPermissionsHelper
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/helpers/index.ts","../../src/utils/logger.ts","../../src/robotCloudApi.ts","../../src/robotCloudClient.ts","../../src/helpers/robotCloudPermissionsHelper.ts"],"sourcesContent":["export { robotCloudPermissionsHelper } from \"helpers/robotCloudPermissionsHelper\";\n\nexport type * from \"../../types/helpers\";","import { createConsola } from \"consola\";\nimport type { ConsolaOptions } from 'consola';\n\nexport function useLogger (tag?: string, options: Partial<ConsolaOptions> = { level: 1000 }) {\n return tag ? createConsola(options).withTag(tag) : createConsola(options)\n}","import axios from \"axios\"\nimport { useLogger } from 'utils/logger';\n\nconst logger = useLogger(\"robotcloud-api\")\n\nconst robotcloudApi = axios.create();\n\nlet checkTokenPromise: Promise<string | undefined> | null = null;\nconst clearPromise = () => checkTokenPromise = null;\n\nasync function refreshToken(checkToken: () => Promise<string | undefined>) {\n const access_token = await checkToken();\n return access_token;\n }\n\n \nlet checkToken = async (): Promise<string> => { return ''}\n\n// Important to add interceptor once, inside a middleware are stacked in each request.\nrobotcloudApi.interceptors.request.use(\n async config => {\n logger.info(\"robotcloud api interceptor:\", config.url)\n if (!checkTokenPromise) {\n checkTokenPromise = refreshToken(checkToken).finally(clearPromise);\n }\n\n // When other request is checking token wait for it\n const token = await checkTokenPromise;\n if (!token) {\n return config\n }\n\n config.headers.authorization = `Bearer ${token}`;\n return config;\n },\n error => {\n logger.error(error)\n Promise.reject(error)\n });\n\nexport const setCheckTokenFunction = (fun: () => Promise<string>) => {\n checkToken = fun\n}\n\nexport default robotcloudApi;\n","import type { AxiosResponse } from \"axios\";\n\nimport { useLogger } from 'utils/logger';\nimport robotcloudApi from \"robotCloudApi\";\nimport { \n LocationServiceInstancesRequestParams, ProjectDetailsRequestParams, ProjectLocationsRequestParams, \n ProjectRequestParams, ProjectTagRequestParams, RobotCloudDeviceDetails, RobotCloudNamedItem, \n RobotCloudProject, RobotCloudProjectDetails, RobotCloudServiceType, RobotCloudServiceTypeDetails, RobotCloudUserDetails, \n RoomConsumes1DataEventValue, RoomGrouping1DataEventValue, \n RoomGrouping1InstanceDeviceConfig, ServiceInstanceDataRequestParams, \n ServiceInstancesRequestParams, \n SubsystemRequestParams\n} from \"../types/RobotCloudClient\";\nimport { RobotCloudServiceInstance, ServiceInstanceDetails } from \"../types/ServiceInstance\";\nimport { ClassifierDetails } from \"../types/ProjectClassifer\";\nimport { ProjectTag, ProjectTagTreeNode, ProjectTagsTree } from \"../types/ProjectTag\";\nimport { ServiceDataMeasurement, ServiceDataRequestParams } from \"../types/services\";\n\n\nconst logger = useLogger(\"robotcloud-client\")\n\n\n\ninterface RobotCloudLocationDetails {\n id: string;\n name: string;\n description: string;\n project: string;\n tags: string[]\n}\n\nexport const getLocationServiceInstances = (\n prjId: string,\n locId: string,\n service_type: RobotCloudServiceType,\n params?: LocationServiceInstancesRequestParams\n): Promise<AxiosResponse<RobotCloudServiceInstance[]>> => {\n return robotcloudApi.get<RobotCloudServiceInstance[]>(`projects/${prjId}/locations/${locId}/services/${service_type}/instances`, {\n params,\n });\n}\n\n\n// USERS ENDPOINTS\nexport const getUser = (\n username: string\n ): Promise<AxiosResponse<RobotCloudUserDetails>> => {\n return robotcloudApi.get<RobotCloudUserDetails>(`users/${username}`);\n };\n\n// PROJECT ENDPOINTS\nexport const getProjects = (\n params?: ProjectRequestParams\n): Promise<AxiosResponse<RobotCloudProject[]>> => {\n return robotcloudApi.get<RobotCloudProject[]>(\"projects\", {\n params\n });\n};\n\nexport const getProjectDetails = (\n prjId: string,\n params?: ProjectDetailsRequestParams\n): Promise<AxiosResponse<RobotCloudProjectDetails>> => {\n return robotcloudApi.get<RobotCloudProjectDetails>(`projects/${prjId}`, {\n params,\n });\n};\n\n// PROJECT SUBSYSTEMS ENDPOINTS\n\nexport const getProjectSubsystem = (\n prjId: string,\n subsysId: string\n) => {\n return robotcloudApi.get<RobotCloudNamedItem>(`projects/${prjId}/subsystems/${subsysId}`);\n}\n\nexport const getLocations = (\n prjId: string,\n params?: ProjectLocationsRequestParams\n): Promise<AxiosResponse<RobotCloudNamedItem[]>> => {\n return robotcloudApi.get<RobotCloudNamedItem[]>(`projects/${prjId}/locations`, {\n params,\n });\n};\n\nexport const getLocation = (\n locationId: string\n): Promise<AxiosResponse<RobotCloudLocationDetails>> => {\n return robotcloudApi.get<RobotCloudLocationDetails>(`locations/${locationId}`, { });\n};\n\nexport const getServiceInstances = (\n prjId: string,\n service_type: string,\n params?: ServiceInstancesRequestParams\n): Promise<AxiosResponse<RobotCloudServiceInstance[]>> => {\n return robotcloudApi.get<RobotCloudServiceInstance[]>(`projects/${prjId}/services/${service_type}/instances`, {\n params,\n });\n}\n\nexport const getServiceInstance = (\n prjId: string,\n service_type: string,\n service_id: string\n) => {\n return robotcloudApi.get<ServiceInstanceDetails>(`projects/${prjId}/services/${service_type}/instances/${service_id}`);\n}\n\nexport const getClassifier = (\n classifierId: string\n) => {\n return robotcloudApi.get<ClassifierDetails>(`classifiers/${classifierId}`);\n}\n\nexport const getTags = (\n prjId: string,\n params?: ProjectTagRequestParams\n): Promise<AxiosResponse<ProjectTag[]>> => {\n logger.info(`Get project ${prjId} tags`)\n return robotcloudApi.get<ProjectTag[]>(`projects/${prjId}/tags`, {\n params,\n });\n};\n\nexport const getTagsTree = async (\n prjId: string,\n maxDepth: number = 2,\n params?: ProjectTagRequestParams\n): Promise<ProjectTagsTree> => {\n logger.info(`Get project ${prjId} tags tree`)\n if (!params) {\n params = {} as ProjectTagRequestParams \n }\n params.no_parent = true;\n\n const tags = await getTagsChildren(prjId, 0, undefined, undefined, maxDepth)\n return {root: tags} as ProjectTagsTree;\n};\n\nexport const getTagsChildren = async (\n prjId: string,\n level: number = 0,\n parent_id?: string,\n params?: ProjectTagRequestParams,\n maxDepth?: number\n): Promise<ProjectTagTreeNode[]> => {\n logger.debug(`Get project ${prjId} tags children: ${parent_id}`)\n if (!params) {\n params = {} as ProjectTagRequestParams \n }\n params.no_parent = !parent_id;\n params.parent_tag = parent_id;\n\n const tags = await getTags(prjId, params)\n if (tags.data.length == 0) {\n return [];\n }\n \n const response: ProjectTagTreeNode[] = []\n const requests: any[] = []\n for (let i = 0; i < tags.data.length; i++) {\n const element = tags.data[i]\n const node = {\n tag: element\n } as ProjectTagTreeNode;\n response.push(node)\n if (maxDepth && level < maxDepth) {\n requests.push(\n getTagsChildren(prjId, level + 1, element.id, params, maxDepth)\n )\n }\n }\n\n const responses = await Promise.all(requests)\n let i = 0;\n responses.forEach(element => {\n response[i].children = element\n i++\n });\n \n return response;\n\n}\n\n/* PROJECT DEVICES ENDPOINTS */\nexport const getDeviceDetails = (\n deviceId: string,\n): Promise<AxiosResponse<RobotCloudDeviceDetails>> => {\n return robotcloudApi.get<RobotCloudDeviceDetails>(`devices/${deviceId}`);\n}\n\n/* SERVICES ENDPOINTS */\nexport const getProjectServiceTypes = (\n prjId: string,\n params?: SubsystemRequestParams\n): Promise<AxiosResponse<RobotCloudServiceTypeDetails[]>> => {\n return robotcloudApi.get<RobotCloudServiceTypeDetails[]>(`projects/${prjId}/services`, {\n params,\n });\n}\n/* SERVICES INSTANCES DATA ENDPOINTS */\n\nexport const getRoomGrouping1ServiceData = (\n prjId: string,\n params?: ServiceDataRequestParams\n): Promise<AxiosResponse<ServiceDataMeasurement<RoomGrouping1DataEventValue>[]>> => {\n return robotcloudApi.get<ServiceDataMeasurement<RoomGrouping1DataEventValue>[]>(\n `/projects/${prjId}/services/RoomGrouping_1/data`,\n { \n params,\n headers: {\n \"Accept\": 'application/json'\n }\n }\n )\n}\n\nexport const getRoomConsumesInstanceServiceData = (\n prjId: string,\n instanceId: string,\n params?: ServiceInstanceDataRequestParams\n): Promise<AxiosResponse<ServiceDataMeasurement<RoomConsumes1DataEventValue>>> => {\n return robotcloudApi.get<ServiceDataMeasurement<RoomConsumes1DataEventValue>>(\n `/projects/${prjId}/services/RoomConsumes_1/instances/${instanceId}/data`,\n { \n params,\n headers: {\n \"Accept\": 'application/json'\n }\n }\n )\n}\n\n\n/* SERVICES INSTANCES DEVICE INGORMATION ENDPOINTS */\n\n\nexport const getRoomGrouping1InstanceDeviceConfig = (\n prjId: string,\n instanceId: string,\n): Promise<AxiosResponse<RoomGrouping1InstanceDeviceConfig>> => {\n return robotcloudApi.put<RoomGrouping1InstanceDeviceConfig>(\n `/projects/${prjId}/services/RoomGrouping_1/instances/${instanceId}/configuration`\n )\n}\n","import * as robotCloudClient from \"robotCloudClient\";\nimport { RobotCloudPermissionsHelper } from \"../../types/helpers\";\nimport { ProjectAccessLevel } from \"../../types/RobotCloudClient\";\n\n\nclass RobotCloudPermissionsHelperImpl implements RobotCloudPermissionsHelper {\n\n async checkProjectAccess(prjId: string, required_project_access: ProjectAccessLevel): Promise<boolean> {\n\n const { data: project} = await robotCloudClient.getProjectDetails(prjId)\n if (project.access_level == required_project_access) {\n return true\n }\n\n switch (required_project_access) {\n case 'ADVANCED':\n return project.access_level == 'ADVANCED'\n case 'BASIC':\n return project.access_level == 'BASIC' || project.access_level == 'ADVANCED'\n case 'RESTRICTED':\n return project.access_level == 'RESTRICTED' || project.access_level == 'BASIC' || \n project.access_level == 'ADVANCED'\n case 'BLOCKED':\n return true \n default:\n return false\n }\n \n }\n}\n\nexport const robotCloudPermissionsHelper: RobotCloudPermissionsHelper = new RobotCloudPermissionsHelperImpl()"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAA8B;AAGvB,SAAS,UAAW,KAAc,UAAmC,EAAE,OAAO,IAAK,GAAG;AACzF,SAAO,UAAM,8BAAc,OAAO,EAAE,QAAQ,GAAG,QAAI,8BAAc,OAAO;AAC5E;;;ACLA,mBAAkB;AAGlB,IAAM,SAAS,UAAU,gBAAgB;AAEzC,IAAM,gBAAgB,aAAAA,QAAM,OAAO;AAEnC,IAAI,oBAAwD;AAC5D,IAAM,eAAe,MAAM,oBAAoB;AAE/C,eAAe,aAAaC,aAA+C;AACvE,QAAM,eAAe,MAAMA,YAAW;AACtC,SAAO;AACT;AAGF,IAAI,aAAa,YAA6B;AAAE,SAAO;AAAE;AAGzD,cAAc,aAAa,QAAQ;AAAA,EAC/B,OAAM,WAAU;AACZ,WAAO,KAAK,+BAA+B,OAAO,GAAG;AACrD,QAAI,CAAC,mBAAmB;AACpB,0BAAoB,aAAa,UAAU,EAAE,QAAQ,YAAY;AAAA,IACrE;AAGA,UAAM,QAAQ,MAAM;AACpB,QAAI,CAAC,OAAO;AACR,aAAO;AAAA,IACX;AAEA,WAAO,QAAQ,gBAAgB,UAAU,KAAK;AAC9C,WAAO;AAAA,EACX;AAAA,EACA,WAAS;AACL,WAAO,MAAM,KAAK;AAClB,YAAQ,OAAO,KAAK;AAAA,EAC1B;AAAC;AAMH,IAAO,wBAAQ;;;ACzBf,IAAMC,UAAS,UAAU,mBAAmB;AAwCrC,IAAM,oBAAoB,CAC/B,OACA,WACqD;AACrD,SAAO,sBAAc,IAA8B,YAAY,KAAK,IAAI;AAAA,IACtE;AAAA,EACF,CAAC;AACH;;;AC7DA,IAAM,kCAAN,MAA6E;AAAA,EAEzE,MAAM,mBAAmB,OAAe,yBAA+D;AAEnG,UAAM,EAAE,MAAM,QAAO,IAAI,MAAuB,kBAAkB,KAAK;AACvE,QAAI,QAAQ,gBAAgB,yBAAyB;AACjD,aAAO;AAAA,IACX;AAEA,YAAQ,yBAAyB;AAAA,MAC7B,KAAK;AACD,eAAO,QAAQ,gBAAgB;AAAA,MACnC,KAAK;AACD,eAAO,QAAQ,gBAAgB,WAAW,QAAQ,gBAAgB;AAAA,MACtE,KAAK;AACD,eAAO,QAAQ,gBAAgB,gBAAgB,QAAQ,gBAAgB,WAC/D,QAAQ,gBAAgB;AAAA,MACpC,KAAK;AACD,eAAO;AAAA,MACX;AACI,eAAO;AAAA,IACf;AAAA,EAEJ;AACJ;AAEO,IAAM,8BAA2D,IAAI,gCAAgC;","names":["axios","checkToken","logger"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/utils/logger.ts
|
|
2
|
+
import { createConsola } from "consola";
|
|
3
|
+
function useLogger(tag, options = { level: 1e3 }) {
|
|
4
|
+
return tag ? createConsola(options).withTag(tag) : createConsola(options);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// src/robotCloudApi.ts
|
|
8
|
+
import axios from "axios";
|
|
9
|
+
var logger = useLogger("robotcloud-api");
|
|
10
|
+
var robotcloudApi = axios.create();
|
|
11
|
+
var checkTokenPromise = null;
|
|
12
|
+
var clearPromise = () => checkTokenPromise = null;
|
|
13
|
+
async function refreshToken(checkToken2) {
|
|
14
|
+
const access_token = await checkToken2();
|
|
15
|
+
return access_token;
|
|
16
|
+
}
|
|
17
|
+
var checkToken = async () => {
|
|
18
|
+
return "";
|
|
19
|
+
};
|
|
20
|
+
robotcloudApi.interceptors.request.use(
|
|
21
|
+
async (config) => {
|
|
22
|
+
logger.info("robotcloud api interceptor:", config.url);
|
|
23
|
+
if (!checkTokenPromise) {
|
|
24
|
+
checkTokenPromise = refreshToken(checkToken).finally(clearPromise);
|
|
25
|
+
}
|
|
26
|
+
const token = await checkTokenPromise;
|
|
27
|
+
if (!token) {
|
|
28
|
+
return config;
|
|
29
|
+
}
|
|
30
|
+
config.headers.authorization = `Bearer ${token}`;
|
|
31
|
+
return config;
|
|
32
|
+
},
|
|
33
|
+
(error) => {
|
|
34
|
+
logger.error(error);
|
|
35
|
+
Promise.reject(error);
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
var robotCloudApi_default = robotcloudApi;
|
|
39
|
+
|
|
40
|
+
// src/robotCloudClient.ts
|
|
41
|
+
var logger2 = useLogger("robotcloud-client");
|
|
42
|
+
var getProjectDetails = (prjId, params) => {
|
|
43
|
+
return robotCloudApi_default.get(`projects/${prjId}`, {
|
|
44
|
+
params
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/helpers/robotCloudPermissionsHelper.ts
|
|
49
|
+
var RobotCloudPermissionsHelperImpl = class {
|
|
50
|
+
async checkProjectAccess(prjId, required_project_access) {
|
|
51
|
+
const { data: project } = await getProjectDetails(prjId);
|
|
52
|
+
if (project.access_level == required_project_access) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
switch (required_project_access) {
|
|
56
|
+
case "ADVANCED":
|
|
57
|
+
return project.access_level == "ADVANCED";
|
|
58
|
+
case "BASIC":
|
|
59
|
+
return project.access_level == "BASIC" || project.access_level == "ADVANCED";
|
|
60
|
+
case "RESTRICTED":
|
|
61
|
+
return project.access_level == "RESTRICTED" || project.access_level == "BASIC" || project.access_level == "ADVANCED";
|
|
62
|
+
case "BLOCKED":
|
|
63
|
+
return true;
|
|
64
|
+
default:
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var robotCloudPermissionsHelper = new RobotCloudPermissionsHelperImpl();
|
|
70
|
+
export {
|
|
71
|
+
robotCloudPermissionsHelper
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/logger.ts","../../src/robotCloudApi.ts","../../src/robotCloudClient.ts","../../src/helpers/robotCloudPermissionsHelper.ts"],"sourcesContent":["import { createConsola } from \"consola\";\nimport type { ConsolaOptions } from 'consola';\n\nexport function useLogger (tag?: string, options: Partial<ConsolaOptions> = { level: 1000 }) {\n return tag ? createConsola(options).withTag(tag) : createConsola(options)\n}","import axios from \"axios\"\nimport { useLogger } from 'utils/logger';\n\nconst logger = useLogger(\"robotcloud-api\")\n\nconst robotcloudApi = axios.create();\n\nlet checkTokenPromise: Promise<string | undefined> | null = null;\nconst clearPromise = () => checkTokenPromise = null;\n\nasync function refreshToken(checkToken: () => Promise<string | undefined>) {\n const access_token = await checkToken();\n return access_token;\n }\n\n \nlet checkToken = async (): Promise<string> => { return ''}\n\n// Important to add interceptor once, inside a middleware are stacked in each request.\nrobotcloudApi.interceptors.request.use(\n async config => {\n logger.info(\"robotcloud api interceptor:\", config.url)\n if (!checkTokenPromise) {\n checkTokenPromise = refreshToken(checkToken).finally(clearPromise);\n }\n\n // When other request is checking token wait for it\n const token = await checkTokenPromise;\n if (!token) {\n return config\n }\n\n config.headers.authorization = `Bearer ${token}`;\n return config;\n },\n error => {\n logger.error(error)\n Promise.reject(error)\n });\n\nexport const setCheckTokenFunction = (fun: () => Promise<string>) => {\n checkToken = fun\n}\n\nexport default robotcloudApi;\n","import type { AxiosResponse } from \"axios\";\n\nimport { useLogger } from 'utils/logger';\nimport robotcloudApi from \"robotCloudApi\";\nimport { \n LocationServiceInstancesRequestParams, ProjectDetailsRequestParams, ProjectLocationsRequestParams, \n ProjectRequestParams, ProjectTagRequestParams, RobotCloudDeviceDetails, RobotCloudNamedItem, \n RobotCloudProject, RobotCloudProjectDetails, RobotCloudServiceType, RobotCloudServiceTypeDetails, RobotCloudUserDetails, \n RoomConsumes1DataEventValue, RoomGrouping1DataEventValue, \n RoomGrouping1InstanceDeviceConfig, ServiceInstanceDataRequestParams, \n ServiceInstancesRequestParams, \n SubsystemRequestParams\n} from \"../types/RobotCloudClient\";\nimport { RobotCloudServiceInstance, ServiceInstanceDetails } from \"../types/ServiceInstance\";\nimport { ClassifierDetails } from \"../types/ProjectClassifer\";\nimport { ProjectTag, ProjectTagTreeNode, ProjectTagsTree } from \"../types/ProjectTag\";\nimport { ServiceDataMeasurement, ServiceDataRequestParams } from \"../types/services\";\n\n\nconst logger = useLogger(\"robotcloud-client\")\n\n\n\ninterface RobotCloudLocationDetails {\n id: string;\n name: string;\n description: string;\n project: string;\n tags: string[]\n}\n\nexport const getLocationServiceInstances = (\n prjId: string,\n locId: string,\n service_type: RobotCloudServiceType,\n params?: LocationServiceInstancesRequestParams\n): Promise<AxiosResponse<RobotCloudServiceInstance[]>> => {\n return robotcloudApi.get<RobotCloudServiceInstance[]>(`projects/${prjId}/locations/${locId}/services/${service_type}/instances`, {\n params,\n });\n}\n\n\n// USERS ENDPOINTS\nexport const getUser = (\n username: string\n ): Promise<AxiosResponse<RobotCloudUserDetails>> => {\n return robotcloudApi.get<RobotCloudUserDetails>(`users/${username}`);\n };\n\n// PROJECT ENDPOINTS\nexport const getProjects = (\n params?: ProjectRequestParams\n): Promise<AxiosResponse<RobotCloudProject[]>> => {\n return robotcloudApi.get<RobotCloudProject[]>(\"projects\", {\n params\n });\n};\n\nexport const getProjectDetails = (\n prjId: string,\n params?: ProjectDetailsRequestParams\n): Promise<AxiosResponse<RobotCloudProjectDetails>> => {\n return robotcloudApi.get<RobotCloudProjectDetails>(`projects/${prjId}`, {\n params,\n });\n};\n\n// PROJECT SUBSYSTEMS ENDPOINTS\n\nexport const getProjectSubsystem = (\n prjId: string,\n subsysId: string\n) => {\n return robotcloudApi.get<RobotCloudNamedItem>(`projects/${prjId}/subsystems/${subsysId}`);\n}\n\nexport const getLocations = (\n prjId: string,\n params?: ProjectLocationsRequestParams\n): Promise<AxiosResponse<RobotCloudNamedItem[]>> => {\n return robotcloudApi.get<RobotCloudNamedItem[]>(`projects/${prjId}/locations`, {\n params,\n });\n};\n\nexport const getLocation = (\n locationId: string\n): Promise<AxiosResponse<RobotCloudLocationDetails>> => {\n return robotcloudApi.get<RobotCloudLocationDetails>(`locations/${locationId}`, { });\n};\n\nexport const getServiceInstances = (\n prjId: string,\n service_type: string,\n params?: ServiceInstancesRequestParams\n): Promise<AxiosResponse<RobotCloudServiceInstance[]>> => {\n return robotcloudApi.get<RobotCloudServiceInstance[]>(`projects/${prjId}/services/${service_type}/instances`, {\n params,\n });\n}\n\nexport const getServiceInstance = (\n prjId: string,\n service_type: string,\n service_id: string\n) => {\n return robotcloudApi.get<ServiceInstanceDetails>(`projects/${prjId}/services/${service_type}/instances/${service_id}`);\n}\n\nexport const getClassifier = (\n classifierId: string\n) => {\n return robotcloudApi.get<ClassifierDetails>(`classifiers/${classifierId}`);\n}\n\nexport const getTags = (\n prjId: string,\n params?: ProjectTagRequestParams\n): Promise<AxiosResponse<ProjectTag[]>> => {\n logger.info(`Get project ${prjId} tags`)\n return robotcloudApi.get<ProjectTag[]>(`projects/${prjId}/tags`, {\n params,\n });\n};\n\nexport const getTagsTree = async (\n prjId: string,\n maxDepth: number = 2,\n params?: ProjectTagRequestParams\n): Promise<ProjectTagsTree> => {\n logger.info(`Get project ${prjId} tags tree`)\n if (!params) {\n params = {} as ProjectTagRequestParams \n }\n params.no_parent = true;\n\n const tags = await getTagsChildren(prjId, 0, undefined, undefined, maxDepth)\n return {root: tags} as ProjectTagsTree;\n};\n\nexport const getTagsChildren = async (\n prjId: string,\n level: number = 0,\n parent_id?: string,\n params?: ProjectTagRequestParams,\n maxDepth?: number\n): Promise<ProjectTagTreeNode[]> => {\n logger.debug(`Get project ${prjId} tags children: ${parent_id}`)\n if (!params) {\n params = {} as ProjectTagRequestParams \n }\n params.no_parent = !parent_id;\n params.parent_tag = parent_id;\n\n const tags = await getTags(prjId, params)\n if (tags.data.length == 0) {\n return [];\n }\n \n const response: ProjectTagTreeNode[] = []\n const requests: any[] = []\n for (let i = 0; i < tags.data.length; i++) {\n const element = tags.data[i]\n const node = {\n tag: element\n } as ProjectTagTreeNode;\n response.push(node)\n if (maxDepth && level < maxDepth) {\n requests.push(\n getTagsChildren(prjId, level + 1, element.id, params, maxDepth)\n )\n }\n }\n\n const responses = await Promise.all(requests)\n let i = 0;\n responses.forEach(element => {\n response[i].children = element\n i++\n });\n \n return response;\n\n}\n\n/* PROJECT DEVICES ENDPOINTS */\nexport const getDeviceDetails = (\n deviceId: string,\n): Promise<AxiosResponse<RobotCloudDeviceDetails>> => {\n return robotcloudApi.get<RobotCloudDeviceDetails>(`devices/${deviceId}`);\n}\n\n/* SERVICES ENDPOINTS */\nexport const getProjectServiceTypes = (\n prjId: string,\n params?: SubsystemRequestParams\n): Promise<AxiosResponse<RobotCloudServiceTypeDetails[]>> => {\n return robotcloudApi.get<RobotCloudServiceTypeDetails[]>(`projects/${prjId}/services`, {\n params,\n });\n}\n/* SERVICES INSTANCES DATA ENDPOINTS */\n\nexport const getRoomGrouping1ServiceData = (\n prjId: string,\n params?: ServiceDataRequestParams\n): Promise<AxiosResponse<ServiceDataMeasurement<RoomGrouping1DataEventValue>[]>> => {\n return robotcloudApi.get<ServiceDataMeasurement<RoomGrouping1DataEventValue>[]>(\n `/projects/${prjId}/services/RoomGrouping_1/data`,\n { \n params,\n headers: {\n \"Accept\": 'application/json'\n }\n }\n )\n}\n\nexport const getRoomConsumesInstanceServiceData = (\n prjId: string,\n instanceId: string,\n params?: ServiceInstanceDataRequestParams\n): Promise<AxiosResponse<ServiceDataMeasurement<RoomConsumes1DataEventValue>>> => {\n return robotcloudApi.get<ServiceDataMeasurement<RoomConsumes1DataEventValue>>(\n `/projects/${prjId}/services/RoomConsumes_1/instances/${instanceId}/data`,\n { \n params,\n headers: {\n \"Accept\": 'application/json'\n }\n }\n )\n}\n\n\n/* SERVICES INSTANCES DEVICE INGORMATION ENDPOINTS */\n\n\nexport const getRoomGrouping1InstanceDeviceConfig = (\n prjId: string,\n instanceId: string,\n): Promise<AxiosResponse<RoomGrouping1InstanceDeviceConfig>> => {\n return robotcloudApi.put<RoomGrouping1InstanceDeviceConfig>(\n `/projects/${prjId}/services/RoomGrouping_1/instances/${instanceId}/configuration`\n )\n}\n","import * as robotCloudClient from \"robotCloudClient\";\nimport { RobotCloudPermissionsHelper } from \"../../types/helpers\";\nimport { ProjectAccessLevel } from \"../../types/RobotCloudClient\";\n\n\nclass RobotCloudPermissionsHelperImpl implements RobotCloudPermissionsHelper {\n\n async checkProjectAccess(prjId: string, required_project_access: ProjectAccessLevel): Promise<boolean> {\n\n const { data: project} = await robotCloudClient.getProjectDetails(prjId)\n if (project.access_level == required_project_access) {\n return true\n }\n\n switch (required_project_access) {\n case 'ADVANCED':\n return project.access_level == 'ADVANCED'\n case 'BASIC':\n return project.access_level == 'BASIC' || project.access_level == 'ADVANCED'\n case 'RESTRICTED':\n return project.access_level == 'RESTRICTED' || project.access_level == 'BASIC' || \n project.access_level == 'ADVANCED'\n case 'BLOCKED':\n return true \n default:\n return false\n }\n \n }\n}\n\nexport const robotCloudPermissionsHelper: RobotCloudPermissionsHelper = new RobotCloudPermissionsHelperImpl()"],"mappings":";AAAA,SAAS,qBAAqB;AAGvB,SAAS,UAAW,KAAc,UAAmC,EAAE,OAAO,IAAK,GAAG;AACzF,SAAO,MAAM,cAAc,OAAO,EAAE,QAAQ,GAAG,IAAI,cAAc,OAAO;AAC5E;;;ACLA,OAAO,WAAW;AAGlB,IAAM,SAAS,UAAU,gBAAgB;AAEzC,IAAM,gBAAgB,MAAM,OAAO;AAEnC,IAAI,oBAAwD;AAC5D,IAAM,eAAe,MAAM,oBAAoB;AAE/C,eAAe,aAAaA,aAA+C;AACvE,QAAM,eAAe,MAAMA,YAAW;AACtC,SAAO;AACT;AAGF,IAAI,aAAa,YAA6B;AAAE,SAAO;AAAE;AAGzD,cAAc,aAAa,QAAQ;AAAA,EAC/B,OAAM,WAAU;AACZ,WAAO,KAAK,+BAA+B,OAAO,GAAG;AACrD,QAAI,CAAC,mBAAmB;AACpB,0BAAoB,aAAa,UAAU,EAAE,QAAQ,YAAY;AAAA,IACrE;AAGA,UAAM,QAAQ,MAAM;AACpB,QAAI,CAAC,OAAO;AACR,aAAO;AAAA,IACX;AAEA,WAAO,QAAQ,gBAAgB,UAAU,KAAK;AAC9C,WAAO;AAAA,EACX;AAAA,EACA,WAAS;AACL,WAAO,MAAM,KAAK;AAClB,YAAQ,OAAO,KAAK;AAAA,EAC1B;AAAC;AAMH,IAAO,wBAAQ;;;ACzBf,IAAMC,UAAS,UAAU,mBAAmB;AAwCrC,IAAM,oBAAoB,CAC/B,OACA,WACqD;AACrD,SAAO,sBAAc,IAA8B,YAAY,KAAK,IAAI;AAAA,IACtE;AAAA,EACF,CAAC;AACH;;;AC7DA,IAAM,kCAAN,MAA6E;AAAA,EAEzE,MAAM,mBAAmB,OAAe,yBAA+D;AAEnG,UAAM,EAAE,MAAM,QAAO,IAAI,MAAuB,kBAAkB,KAAK;AACvE,QAAI,QAAQ,gBAAgB,yBAAyB;AACjD,aAAO;AAAA,IACX;AAEA,YAAQ,yBAAyB;AAAA,MAC7B,KAAK;AACD,eAAO,QAAQ,gBAAgB;AAAA,MACnC,KAAK;AACD,eAAO,QAAQ,gBAAgB,WAAW,QAAQ,gBAAgB;AAAA,MACtE,KAAK;AACD,eAAO,QAAQ,gBAAgB,gBAAgB,QAAQ,gBAAgB,WAC/D,QAAQ,gBAAgB;AAAA,MACpC,KAAK;AACD,eAAO;AAAA,MACX;AACI,eAAO;AAAA,IACf;AAAA,EAEJ;AACJ;AAEO,IAAM,8BAA2D,IAAI,gCAAgC;","names":["checkToken","logger"]}
|