@wiotp/sdk 0.4.2 → 0.6.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/LICENSE +203 -203
- package/README.md +68 -68
- package/dist/BaseClient.js +259 -0
- package/dist/BaseConfig.js +194 -0
- package/dist/api/ApiClient.js +508 -0
- package/dist/api/ApiErrors.js +118 -0
- package/dist/api/DscClient.js +332 -0
- package/dist/api/LecClient.js +48 -0
- package/dist/api/MgmtClient.js +77 -0
- package/dist/api/RegistryClient.js +234 -0
- package/dist/api/RulesClient.js +105 -0
- package/dist/api/StateClient.js +738 -0
- package/dist/application/ApplicationClient.js +436 -0
- package/dist/application/ApplicationConfig.js +233 -0
- package/dist/application/index.js +23 -0
- package/dist/bundled/wiotp-bundle.js +35592 -0
- package/dist/bundled/wiotp-bundle.min.js +47 -0
- package/dist/device/DeviceClient.js +125 -0
- package/dist/device/DeviceConfig.js +216 -0
- package/dist/device/index.js +23 -0
- package/dist/gateway/GatewayClient.js +159 -0
- package/dist/gateway/GatewayConfig.js +52 -0
- package/dist/gateway/index.js +23 -0
- package/dist/index.js +55 -0
- package/dist/util.js +50 -0
- package/package.json +92 -84
- package/src/BaseClient.js +215 -215
- package/src/BaseConfig.js +157 -157
- package/src/api/ApiClient.js +454 -454
- package/src/api/ApiErrors.js +33 -33
- package/src/api/DscClient.js +164 -145
- package/src/api/LecClient.js +32 -32
- package/src/api/MgmtClient.js +57 -57
- package/src/api/RegistryClient.js +194 -194
- package/src/api/RulesClient.js +84 -84
- package/src/api/StateClient.js +650 -650
- package/src/application/ApplicationClient.js +348 -348
- package/src/application/ApplicationConfig.js +191 -191
- package/src/application/index.js +12 -12
- package/src/device/DeviceClient.js +78 -78
- package/src/device/DeviceConfig.js +175 -175
- package/src/device/index.js +14 -14
- package/src/gateway/GatewayClient.js +114 -114
- package/src/gateway/GatewayConfig.js +21 -21
- package/src/gateway/index.js +13 -13
- package/{index.js → src/index.js} +19 -19
- package/src/util.js +38 -38
- package/src/util/IoTFoundation.pem +0 -82
|
@@ -1,195 +1,195 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*****************************************************************************
|
|
3
|
-
Copyright (c) 2014, 2019 IBM Corporation and other Contributors.
|
|
4
|
-
All rights reserved. This program and the accompanying materials
|
|
5
|
-
are made available under the terms of the Eclipse Public License v1.0
|
|
6
|
-
which accompanies this distribution, and is available at
|
|
7
|
-
http://www.eclipse.org/legal/epl-v10.html
|
|
8
|
-
*****************************************************************************
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
export default class RegistryClient {
|
|
13
|
-
constructor(apiClient) {
|
|
14
|
-
this.apiClient = apiClient;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
listAllDevicesOfType(type) {
|
|
18
|
-
this.apiClient.log.debug("[ApiClient] listAllDevicesOfType(" + type + ")");
|
|
19
|
-
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices'], null);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
deleteDeviceType(type) {
|
|
23
|
-
this.apiClient.log.debug("[ApiClient] deleteDeviceType(" + type + ")");
|
|
24
|
-
return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type], null);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getDeviceType(type) {
|
|
28
|
-
this.apiClient.log.debug("[ApiClient] getDeviceType(" + type + ")");
|
|
29
|
-
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type], null);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
getAllDeviceTypes() {
|
|
33
|
-
this.apiClient.log.debug("[ApiClient] getAllDeviceTypes()");
|
|
34
|
-
return this.apiClient.callApi('GET', 200, true, ['device', 'types'], null);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
updateDeviceType(type, description, deviceInfo, metadata) {
|
|
38
|
-
this.apiClient.log.debug("[ApiClient] updateDeviceType(" + type + ", " + description + ", " + deviceInfo + ", " + metadata + ")");
|
|
39
|
-
let body = {
|
|
40
|
-
deviceInfo: deviceInfo,
|
|
41
|
-
description: description,
|
|
42
|
-
metadata: metadata
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return this.apiClient.callApi('PUT', 200, true, ['device', 'types', type], JSON.stringify(body));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
registerDeviceType(typeId, description, deviceInfo, metadata, classId) {
|
|
49
|
-
this.apiClient.log.debug("[ApiClient] registerDeviceType(" + typeId + ", " + description + ", " + deviceInfo + ", " + metadata + ", " + classId + ")");
|
|
50
|
-
// TODO: field validation
|
|
51
|
-
classId = classId || "Device";
|
|
52
|
-
let body = {
|
|
53
|
-
id: typeId,
|
|
54
|
-
classId: classId,
|
|
55
|
-
deviceInfo: deviceInfo,
|
|
56
|
-
description: description,
|
|
57
|
-
metadata: metadata
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
return this.apiClient.callApi('POST', 201, true, ['device', 'types'], JSON.stringify(body));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
registerDevice(type, deviceId, authToken, deviceInfo, location, metadata) {
|
|
64
|
-
this.apiClient.log.debug("[ApiClient] registerDevice(" + type + ", " + deviceId + ", " + deviceInfo + ", " + location + ", " + metadata + ")");
|
|
65
|
-
// TODO: field validation
|
|
66
|
-
let body = {
|
|
67
|
-
deviceId: deviceId,
|
|
68
|
-
authToken: authToken,
|
|
69
|
-
deviceInfo: deviceInfo,
|
|
70
|
-
location: location,
|
|
71
|
-
metadata: metadata
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
return this.apiClient.callApi('POST', 201, true, ['device', 'types', type, 'devices'], JSON.stringify(body));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
unregisterDevice(type, deviceId) {
|
|
78
|
-
this.apiClient.log.debug("[ApiClient] unregisterDevice(" + type + ", " + deviceId + ")");
|
|
79
|
-
return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type, 'devices', deviceId], null);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
updateDevice(type, deviceId, deviceInfo, status, metadata, extensions) {
|
|
83
|
-
this.apiClient.log.debug("[ApiClient] updateDevice(" + type + ", " + deviceId + ", " + deviceInfo + ", " + status + ", " + metadata + ")");
|
|
84
|
-
let body = {
|
|
85
|
-
deviceInfo: deviceInfo,
|
|
86
|
-
status: status,
|
|
87
|
-
metadata: metadata,
|
|
88
|
-
extensions: extensions
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
return this.apiClient.callApi('PUT', 200, true, ['device', 'types', type, 'devices', deviceId], JSON.stringify(body));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
getDevice(type, deviceId) {
|
|
95
|
-
this.apiClient.log.debug("[ApiClient] getDevice(" + type + ", " + deviceId + ")");
|
|
96
|
-
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId], null);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Register multiple new devices, each request can contain a maximum of 512KB.
|
|
102
|
-
* The response body will contain the generated authentication tokens for all devices.
|
|
103
|
-
* The caller of the method must make sure to record these tokens when processing
|
|
104
|
-
* the response. The IBM Watson IoT Platform will not be able to retrieve lost authentication tokens
|
|
105
|
-
*
|
|
106
|
-
* @param arryOfDevicesToBeAdded Array of JSON devices to be added. Refer to
|
|
107
|
-
* <a href="https://docs.internetofthings.ibmcloud.com/swagger/v0002.html#!/Bulk_Operations/post_bulk_devices_add">link</a>
|
|
108
|
-
* for more information about the schema to be used
|
|
109
|
-
*/
|
|
110
|
-
registerMultipleDevices(arryOfDevicesToBeAdded) {
|
|
111
|
-
this.apiClient.log.debug("[ApiClient] arryOfDevicesToBeAdded() - BULK");
|
|
112
|
-
return this.apiClient.callApi('POST', 201, true, ["bulk", "devices", "add"], JSON.stringify(arryOfDevicesToBeAdded));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Delete multiple devices, each request can contain a maximum of 512Kb
|
|
117
|
-
*
|
|
118
|
-
* @param arryOfDevicesToBeDeleted Array of JSON devices to be deleted. Refer to
|
|
119
|
-
* <a href="https://docs.internetofthings.ibmcloud.com/swagger/v0002.html#!/Bulk_Operations/post_bulk_devices_remove">link</a>
|
|
120
|
-
* for more information about the schema to be used.
|
|
121
|
-
*/
|
|
122
|
-
deleteMultipleDevices(arryOfDevicesToBeDeleted) {
|
|
123
|
-
|
|
124
|
-
this.apiClient.log.debug("[ApiClient] deleteMultipleDevices() - BULK");
|
|
125
|
-
return this.apiClient.callApi('POST', 201, true, ["bulk", "devices", "remove"], JSON.stringify(arryOfDevicesToBeDeleted));
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
getDeviceLocation(type, deviceId) {
|
|
129
|
-
this.apiClient.log.debug("[ApiClient] getDeviceLocation(" + type + ", " + deviceId + ")");
|
|
130
|
-
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'location'], null);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
updateDeviceLocation(type, deviceId, location) {
|
|
134
|
-
this.apiClient.log.debug("[ApiClient] updateDeviceLocation(" + type + ", " + deviceId + ", " + location + ")");
|
|
135
|
-
|
|
136
|
-
return this.apiClient.callApi('PUT', 200, true, ['device', 'types', type, 'devices', deviceId, 'location'], JSON.stringify(location));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
getDeviceManagementInformation(type, deviceId) {
|
|
141
|
-
this.apiClient.log.debug("[ApiClient] getDeviceManagementInformation(" + type + ", " + deviceId + ")");
|
|
142
|
-
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'mgmt'], null);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
getAllDiagnosticLogs(type, deviceId) {
|
|
146
|
-
this.apiClient.log.debug("[ApiClient] getAllDiagnosticLogs(" + type + ", " + deviceId + ")");
|
|
147
|
-
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs'], null);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
clearAllDiagnosticLogs(type, deviceId) {
|
|
151
|
-
this.apiClient.log.debug("[ApiClient] clearAllDiagnosticLogs(" + type + ", " + deviceId + ")");
|
|
152
|
-
return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs'], null);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
addDeviceDiagLogs(type, deviceId, log) {
|
|
156
|
-
this.apiClient.log.debug("[ApiClient] addDeviceDiagLogs(" + type + ", " + deviceId + ", " + log + ")");
|
|
157
|
-
return this.apiClient.callApi('POST', 201, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs'], JSON.stringify(log));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
getDiagnosticLog(type, deviceId, logId) {
|
|
161
|
-
this.apiClient.log.debug("[ApiClient] getAllDiagnosticLogs(" + type + ", " + deviceId + ", " + logId + ")");
|
|
162
|
-
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs', logId], null);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
deleteDiagnosticLog(type, deviceId, logId) {
|
|
166
|
-
this.apiClient.log.debug("[ApiClient] deleteDiagnosticLog(" + type + ", " + deviceId + ", " + logId + ")");
|
|
167
|
-
return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs', logId], null);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
getDeviceErrorCodes(type, deviceId) {
|
|
171
|
-
this.apiClient.log.debug("[ApiClient] getDeviceErrorCodes(" + type + ", " + deviceId + ")");
|
|
172
|
-
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'diag', 'errorCodes'], null);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
clearDeviceErrorCodes(type, deviceId) {
|
|
176
|
-
this.apiClient.log.debug("[ApiClient] clearDeviceErrorCodes(" + type + ", " + deviceId + ")");
|
|
177
|
-
return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'errorCodes'], null);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
addErrorCode(type, deviceId, log) {
|
|
181
|
-
this.apiClient.log.debug("[ApiClient] addErrorCode(" + type + ", " + deviceId + ", " + log + ")");
|
|
182
|
-
return this.apiClient.callApi('POST', 201, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'errorCodes'], JSON.stringify(log));
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
getDeviceConnectionLogs(typeId, deviceId) {
|
|
186
|
-
this.apiClient.log.debug("[ApiClient] getDeviceConnectionLogs(" + typeId + ", " + deviceId + ")");
|
|
187
|
-
let params = {
|
|
188
|
-
typeId: typeId,
|
|
189
|
-
deviceId: deviceId
|
|
190
|
-
};
|
|
191
|
-
return this.apiClient.callApi('GET', 200, true, ['logs', 'connection'], null, params);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
1
|
+
/**
|
|
2
|
+
*****************************************************************************
|
|
3
|
+
Copyright (c) 2014, 2019 IBM Corporation and other Contributors.
|
|
4
|
+
All rights reserved. This program and the accompanying materials
|
|
5
|
+
are made available under the terms of the Eclipse Public License v1.0
|
|
6
|
+
which accompanies this distribution, and is available at
|
|
7
|
+
http://www.eclipse.org/legal/epl-v10.html
|
|
8
|
+
*****************************************************************************
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export default class RegistryClient {
|
|
13
|
+
constructor(apiClient) {
|
|
14
|
+
this.apiClient = apiClient;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
listAllDevicesOfType(type) {
|
|
18
|
+
this.apiClient.log.debug("[ApiClient] listAllDevicesOfType(" + type + ")");
|
|
19
|
+
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices'], null);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
deleteDeviceType(type) {
|
|
23
|
+
this.apiClient.log.debug("[ApiClient] deleteDeviceType(" + type + ")");
|
|
24
|
+
return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type], null);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getDeviceType(type) {
|
|
28
|
+
this.apiClient.log.debug("[ApiClient] getDeviceType(" + type + ")");
|
|
29
|
+
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type], null);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getAllDeviceTypes() {
|
|
33
|
+
this.apiClient.log.debug("[ApiClient] getAllDeviceTypes()");
|
|
34
|
+
return this.apiClient.callApi('GET', 200, true, ['device', 'types'], null);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
updateDeviceType(type, description, deviceInfo, metadata) {
|
|
38
|
+
this.apiClient.log.debug("[ApiClient] updateDeviceType(" + type + ", " + description + ", " + deviceInfo + ", " + metadata + ")");
|
|
39
|
+
let body = {
|
|
40
|
+
deviceInfo: deviceInfo,
|
|
41
|
+
description: description,
|
|
42
|
+
metadata: metadata
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return this.apiClient.callApi('PUT', 200, true, ['device', 'types', type], JSON.stringify(body));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
registerDeviceType(typeId, description, deviceInfo, metadata, classId) {
|
|
49
|
+
this.apiClient.log.debug("[ApiClient] registerDeviceType(" + typeId + ", " + description + ", " + deviceInfo + ", " + metadata + ", " + classId + ")");
|
|
50
|
+
// TODO: field validation
|
|
51
|
+
classId = classId || "Device";
|
|
52
|
+
let body = {
|
|
53
|
+
id: typeId,
|
|
54
|
+
classId: classId,
|
|
55
|
+
deviceInfo: deviceInfo,
|
|
56
|
+
description: description,
|
|
57
|
+
metadata: metadata
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return this.apiClient.callApi('POST', 201, true, ['device', 'types'], JSON.stringify(body));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
registerDevice(type, deviceId, authToken, deviceInfo, location, metadata) {
|
|
64
|
+
this.apiClient.log.debug("[ApiClient] registerDevice(" + type + ", " + deviceId + ", " + deviceInfo + ", " + location + ", " + metadata + ")");
|
|
65
|
+
// TODO: field validation
|
|
66
|
+
let body = {
|
|
67
|
+
deviceId: deviceId,
|
|
68
|
+
authToken: authToken,
|
|
69
|
+
deviceInfo: deviceInfo,
|
|
70
|
+
location: location,
|
|
71
|
+
metadata: metadata
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return this.apiClient.callApi('POST', 201, true, ['device', 'types', type, 'devices'], JSON.stringify(body));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
unregisterDevice(type, deviceId) {
|
|
78
|
+
this.apiClient.log.debug("[ApiClient] unregisterDevice(" + type + ", " + deviceId + ")");
|
|
79
|
+
return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type, 'devices', deviceId], null);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
updateDevice(type, deviceId, deviceInfo, status, metadata, extensions) {
|
|
83
|
+
this.apiClient.log.debug("[ApiClient] updateDevice(" + type + ", " + deviceId + ", " + deviceInfo + ", " + status + ", " + metadata + ")");
|
|
84
|
+
let body = {
|
|
85
|
+
deviceInfo: deviceInfo,
|
|
86
|
+
status: status,
|
|
87
|
+
metadata: metadata,
|
|
88
|
+
extensions: extensions
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return this.apiClient.callApi('PUT', 200, true, ['device', 'types', type, 'devices', deviceId], JSON.stringify(body));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getDevice(type, deviceId) {
|
|
95
|
+
this.apiClient.log.debug("[ApiClient] getDevice(" + type + ", " + deviceId + ")");
|
|
96
|
+
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId], null);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Register multiple new devices, each request can contain a maximum of 512KB.
|
|
102
|
+
* The response body will contain the generated authentication tokens for all devices.
|
|
103
|
+
* The caller of the method must make sure to record these tokens when processing
|
|
104
|
+
* the response. The IBM Watson IoT Platform will not be able to retrieve lost authentication tokens
|
|
105
|
+
*
|
|
106
|
+
* @param arryOfDevicesToBeAdded Array of JSON devices to be added. Refer to
|
|
107
|
+
* <a href="https://docs.internetofthings.ibmcloud.com/swagger/v0002.html#!/Bulk_Operations/post_bulk_devices_add">link</a>
|
|
108
|
+
* for more information about the schema to be used
|
|
109
|
+
*/
|
|
110
|
+
registerMultipleDevices(arryOfDevicesToBeAdded) {
|
|
111
|
+
this.apiClient.log.debug("[ApiClient] arryOfDevicesToBeAdded() - BULK");
|
|
112
|
+
return this.apiClient.callApi('POST', 201, true, ["bulk", "devices", "add"], JSON.stringify(arryOfDevicesToBeAdded));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Delete multiple devices, each request can contain a maximum of 512Kb
|
|
117
|
+
*
|
|
118
|
+
* @param arryOfDevicesToBeDeleted Array of JSON devices to be deleted. Refer to
|
|
119
|
+
* <a href="https://docs.internetofthings.ibmcloud.com/swagger/v0002.html#!/Bulk_Operations/post_bulk_devices_remove">link</a>
|
|
120
|
+
* for more information about the schema to be used.
|
|
121
|
+
*/
|
|
122
|
+
deleteMultipleDevices(arryOfDevicesToBeDeleted) {
|
|
123
|
+
|
|
124
|
+
this.apiClient.log.debug("[ApiClient] deleteMultipleDevices() - BULK");
|
|
125
|
+
return this.apiClient.callApi('POST', 201, true, ["bulk", "devices", "remove"], JSON.stringify(arryOfDevicesToBeDeleted));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
getDeviceLocation(type, deviceId) {
|
|
129
|
+
this.apiClient.log.debug("[ApiClient] getDeviceLocation(" + type + ", " + deviceId + ")");
|
|
130
|
+
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'location'], null);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
updateDeviceLocation(type, deviceId, location) {
|
|
134
|
+
this.apiClient.log.debug("[ApiClient] updateDeviceLocation(" + type + ", " + deviceId + ", " + location + ")");
|
|
135
|
+
|
|
136
|
+
return this.apiClient.callApi('PUT', 200, true, ['device', 'types', type, 'devices', deviceId, 'location'], JSON.stringify(location));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
getDeviceManagementInformation(type, deviceId) {
|
|
141
|
+
this.apiClient.log.debug("[ApiClient] getDeviceManagementInformation(" + type + ", " + deviceId + ")");
|
|
142
|
+
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'mgmt'], null);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
getAllDiagnosticLogs(type, deviceId) {
|
|
146
|
+
this.apiClient.log.debug("[ApiClient] getAllDiagnosticLogs(" + type + ", " + deviceId + ")");
|
|
147
|
+
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs'], null);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
clearAllDiagnosticLogs(type, deviceId) {
|
|
151
|
+
this.apiClient.log.debug("[ApiClient] clearAllDiagnosticLogs(" + type + ", " + deviceId + ")");
|
|
152
|
+
return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs'], null);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
addDeviceDiagLogs(type, deviceId, log) {
|
|
156
|
+
this.apiClient.log.debug("[ApiClient] addDeviceDiagLogs(" + type + ", " + deviceId + ", " + log + ")");
|
|
157
|
+
return this.apiClient.callApi('POST', 201, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs'], JSON.stringify(log));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
getDiagnosticLog(type, deviceId, logId) {
|
|
161
|
+
this.apiClient.log.debug("[ApiClient] getAllDiagnosticLogs(" + type + ", " + deviceId + ", " + logId + ")");
|
|
162
|
+
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs', logId], null);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
deleteDiagnosticLog(type, deviceId, logId) {
|
|
166
|
+
this.apiClient.log.debug("[ApiClient] deleteDiagnosticLog(" + type + ", " + deviceId + ", " + logId + ")");
|
|
167
|
+
return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs', logId], null);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
getDeviceErrorCodes(type, deviceId) {
|
|
171
|
+
this.apiClient.log.debug("[ApiClient] getDeviceErrorCodes(" + type + ", " + deviceId + ")");
|
|
172
|
+
return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'diag', 'errorCodes'], null);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
clearDeviceErrorCodes(type, deviceId) {
|
|
176
|
+
this.apiClient.log.debug("[ApiClient] clearDeviceErrorCodes(" + type + ", " + deviceId + ")");
|
|
177
|
+
return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'errorCodes'], null);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
addErrorCode(type, deviceId, log) {
|
|
181
|
+
this.apiClient.log.debug("[ApiClient] addErrorCode(" + type + ", " + deviceId + ", " + log + ")");
|
|
182
|
+
return this.apiClient.callApi('POST', 201, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'errorCodes'], JSON.stringify(log));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
getDeviceConnectionLogs(typeId, deviceId) {
|
|
186
|
+
this.apiClient.log.debug("[ApiClient] getDeviceConnectionLogs(" + typeId + ", " + deviceId + ")");
|
|
187
|
+
let params = {
|
|
188
|
+
typeId: typeId,
|
|
189
|
+
deviceId: deviceId
|
|
190
|
+
};
|
|
191
|
+
return this.apiClient.callApi('GET', 200, true, ['logs', 'connection'], null, params);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
195
|
};
|
package/src/api/RulesClient.js
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*****************************************************************************
|
|
3
|
-
Copyright (c) 2014, 2019 IBM Corporation and other Contributors.
|
|
4
|
-
All rights reserved. This program and the accompanying materials
|
|
5
|
-
are made available under the terms of the Eclipse Public License v1.0
|
|
6
|
-
which accompanies this distribution, and is available at
|
|
7
|
-
http://www.eclipse.org/legal/epl-v10.html
|
|
8
|
-
*****************************************************************************
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
import log from 'loglevel';
|
|
12
|
-
|
|
13
|
-
export default class RulesClient {
|
|
14
|
-
constructor(apiClient) {
|
|
15
|
-
this.log = log;
|
|
16
|
-
|
|
17
|
-
this.apiClient = apiClient;
|
|
18
|
-
|
|
19
|
-
// Create an alias to the apiClient's callApi
|
|
20
|
-
this.callApi = this.apiClient.callApi.bind(this.apiClient);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
getRulesForLogicalInterface(logicalInterfaceId) {
|
|
25
|
-
if (this.draftMode) {
|
|
26
|
-
return this.getRulesForLogicalInterface(logicalInterfaceId);
|
|
27
|
-
} else {
|
|
28
|
-
return this.getActiveRulesForLogicalInterface(logicalInterfaceId);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
getDraftRulesForLogicalInterface(logicalInterfaceId) {
|
|
34
|
-
return this.callApi('GET', 200, true, ['draft', 'logicalinterfaces', logicalInterfaceId, 'rules']);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
getActiveRulesForLogicalInterface(logicalInterfaceId) {
|
|
39
|
-
return this.callApi('GET', 200, true, ['logicalinterfaces', logicalInterfaceId, 'rules']);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
createRule(logicalInterfaceId, name, condition, description=undefined, notificationStrategy=RulesClient.RuleNotificationStrategy.EVERY_TIME()) {
|
|
44
|
-
var body = {
|
|
45
|
-
name,
|
|
46
|
-
condition,
|
|
47
|
-
notificationStrategy
|
|
48
|
-
}
|
|
49
|
-
if (description) body['description'] = description;
|
|
50
|
-
var base = this.draftMode ? ['draft', 'logicalinterfaces', logicalInterfaceId, 'rules'] : ['logicalinterfaces', logicalInterfaceId, 'rules'];
|
|
51
|
-
return this.callApi('POST', 201, true, base, JSON.stringify(body));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
updateRule(rule) {
|
|
56
|
-
var base = this.draftMode ? ['draft', 'logicalinterfaces', rule.logicalInterfaceId, 'rules', rule.id] : ['logicalinterfaces', rule.logicalInterfaceId, 'rules', rule.id];
|
|
57
|
-
return this.callApi('PUT', 200, true, base, JSON.stringify(rule));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
deleteRule(logicalInterfaceId, ruleId) {
|
|
62
|
-
var base = this.draftMode ? ['draft', 'logicalinterfaces', logicalInterfaceId, 'rules', ruleId] : ['logicalinterfaces', logicalInterfaceId, 'rules', ruleId];
|
|
63
|
-
return this.callApi('DELETE', 204, false, base);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
RulesClient.RuleNotificationStrategy = {
|
|
69
|
-
EVERY_TIME: () => ({
|
|
70
|
-
when: 'every-time'
|
|
71
|
-
}),
|
|
72
|
-
BECOMES_TRUE: () => ({
|
|
73
|
-
when: 'becomes-true',
|
|
74
|
-
}),
|
|
75
|
-
X_IN_Y: (count) => ({
|
|
76
|
-
when: 'x-in-y',
|
|
77
|
-
count,
|
|
78
|
-
}),
|
|
79
|
-
PERSISTS: (count, timePeriod) => ({
|
|
80
|
-
when: 'persists',
|
|
81
|
-
count,
|
|
82
|
-
timePeriod
|
|
83
|
-
}),
|
|
84
|
-
|
|
1
|
+
/**
|
|
2
|
+
*****************************************************************************
|
|
3
|
+
Copyright (c) 2014, 2019 IBM Corporation and other Contributors.
|
|
4
|
+
All rights reserved. This program and the accompanying materials
|
|
5
|
+
are made available under the terms of the Eclipse Public License v1.0
|
|
6
|
+
which accompanies this distribution, and is available at
|
|
7
|
+
http://www.eclipse.org/legal/epl-v10.html
|
|
8
|
+
*****************************************************************************
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
import log from 'loglevel';
|
|
12
|
+
|
|
13
|
+
export default class RulesClient {
|
|
14
|
+
constructor(apiClient) {
|
|
15
|
+
this.log = log;
|
|
16
|
+
|
|
17
|
+
this.apiClient = apiClient;
|
|
18
|
+
|
|
19
|
+
// Create an alias to the apiClient's callApi
|
|
20
|
+
this.callApi = this.apiClient.callApi.bind(this.apiClient);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
getRulesForLogicalInterface(logicalInterfaceId) {
|
|
25
|
+
if (this.draftMode) {
|
|
26
|
+
return this.getRulesForLogicalInterface(logicalInterfaceId);
|
|
27
|
+
} else {
|
|
28
|
+
return this.getActiveRulesForLogicalInterface(logicalInterfaceId);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
getDraftRulesForLogicalInterface(logicalInterfaceId) {
|
|
34
|
+
return this.callApi('GET', 200, true, ['draft', 'logicalinterfaces', logicalInterfaceId, 'rules']);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
getActiveRulesForLogicalInterface(logicalInterfaceId) {
|
|
39
|
+
return this.callApi('GET', 200, true, ['logicalinterfaces', logicalInterfaceId, 'rules']);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
createRule(logicalInterfaceId, name, condition, description=undefined, notificationStrategy=RulesClient.RuleNotificationStrategy.EVERY_TIME()) {
|
|
44
|
+
var body = {
|
|
45
|
+
name,
|
|
46
|
+
condition,
|
|
47
|
+
notificationStrategy
|
|
48
|
+
}
|
|
49
|
+
if (description) body['description'] = description;
|
|
50
|
+
var base = this.draftMode ? ['draft', 'logicalinterfaces', logicalInterfaceId, 'rules'] : ['logicalinterfaces', logicalInterfaceId, 'rules'];
|
|
51
|
+
return this.callApi('POST', 201, true, base, JSON.stringify(body));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
updateRule(rule) {
|
|
56
|
+
var base = this.draftMode ? ['draft', 'logicalinterfaces', rule.logicalInterfaceId, 'rules', rule.id] : ['logicalinterfaces', rule.logicalInterfaceId, 'rules', rule.id];
|
|
57
|
+
return this.callApi('PUT', 200, true, base, JSON.stringify(rule));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
deleteRule(logicalInterfaceId, ruleId) {
|
|
62
|
+
var base = this.draftMode ? ['draft', 'logicalinterfaces', logicalInterfaceId, 'rules', ruleId] : ['logicalinterfaces', logicalInterfaceId, 'rules', ruleId];
|
|
63
|
+
return this.callApi('DELETE', 204, false, base);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
RulesClient.RuleNotificationStrategy = {
|
|
69
|
+
EVERY_TIME: () => ({
|
|
70
|
+
when: 'every-time'
|
|
71
|
+
}),
|
|
72
|
+
BECOMES_TRUE: () => ({
|
|
73
|
+
when: 'becomes-true',
|
|
74
|
+
}),
|
|
75
|
+
X_IN_Y: (count) => ({
|
|
76
|
+
when: 'x-in-y',
|
|
77
|
+
count,
|
|
78
|
+
}),
|
|
79
|
+
PERSISTS: (count, timePeriod) => ({
|
|
80
|
+
when: 'persists',
|
|
81
|
+
count,
|
|
82
|
+
timePeriod
|
|
83
|
+
}),
|
|
84
|
+
|
|
85
85
|
};
|