@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
package/src/api/ApiErrors.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
export class WiotpError extends Error {
|
|
3
|
-
constructor(message, cause) {
|
|
4
|
-
super(message);
|
|
5
|
-
this.cause = cause;
|
|
6
|
-
this.name = this.constructor.name;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class InvalidServiceCredentials extends WiotpError {}
|
|
11
|
-
|
|
12
|
-
export class DestinationAlreadyExists extends WiotpError {}
|
|
13
|
-
|
|
14
|
-
export class ServiceNotFound extends WiotpError {}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export const handleError = (err, errorMappings) => {
|
|
18
|
-
if(err && err.response && err.response.data && err.response.data.exception && err.response.data.exception.id) {
|
|
19
|
-
if(errorMappings && errorMappings[err.response.data.exception.id]) {
|
|
20
|
-
throw new errorMappings[err.response.data.exception.id](err.response.data.message, err);
|
|
21
|
-
} else {
|
|
22
|
-
throw new WiotpError(err.response.data.message, err);
|
|
23
|
-
}
|
|
24
|
-
} else {
|
|
25
|
-
throw err;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default {
|
|
30
|
-
WiotpError,
|
|
31
|
-
InvalidServiceCredentials,
|
|
32
|
-
DestinationAlreadyExists,
|
|
33
|
-
ServiceNotFound,
|
|
1
|
+
|
|
2
|
+
export class WiotpError extends Error {
|
|
3
|
+
constructor(message, cause) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.cause = cause;
|
|
6
|
+
this.name = this.constructor.name;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class InvalidServiceCredentials extends WiotpError {}
|
|
11
|
+
|
|
12
|
+
export class DestinationAlreadyExists extends WiotpError {}
|
|
13
|
+
|
|
14
|
+
export class ServiceNotFound extends WiotpError {}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export const handleError = (err, errorMappings) => {
|
|
18
|
+
if(err && err.response && err.response.data && err.response.data.exception && err.response.data.exception.id) {
|
|
19
|
+
if(errorMappings && errorMappings[err.response.data.exception.id]) {
|
|
20
|
+
throw new errorMappings[err.response.data.exception.id](err.response.data.message, err);
|
|
21
|
+
} else {
|
|
22
|
+
throw new WiotpError(err.response.data.message, err);
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
throw err;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default {
|
|
30
|
+
WiotpError,
|
|
31
|
+
InvalidServiceCredentials,
|
|
32
|
+
DestinationAlreadyExists,
|
|
33
|
+
ServiceNotFound,
|
|
34
34
|
}
|
package/src/api/DscClient.js
CHANGED
|
@@ -1,146 +1,165 @@
|
|
|
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
|
-
import * as errors from './ApiErrors';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export default class DscClient {
|
|
17
|
-
constructor(apiClient) {
|
|
18
|
-
this.log = log;
|
|
19
|
-
|
|
20
|
-
// callApi(method, expectedHttpCode, expectJsonContent, paths, body, params) {
|
|
21
|
-
this.apiClient = apiClient;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**************************************
|
|
27
|
-
** Services
|
|
28
|
-
**************************************/
|
|
29
|
-
|
|
30
|
-
// {name, description, type, credentials}
|
|
31
|
-
createService(service) {
|
|
32
|
-
return this.apiClient.callApi('POST', 201, true, ['s2s', 'services'], service)
|
|
33
|
-
.catch(err => errors.handleError(err, {CUDSS0026E: errors.InvalidServiceCredentials}));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
createCloudantService({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return this.createService({name, description, type: '
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return this.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return this.apiClient.callApi('
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
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
|
+
import * as errors from './ApiErrors';
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export default class DscClient {
|
|
17
|
+
constructor(apiClient) {
|
|
18
|
+
this.log = log;
|
|
19
|
+
|
|
20
|
+
// callApi(method, expectedHttpCode, expectJsonContent, paths, body, params) {
|
|
21
|
+
this.apiClient = apiClient;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/**************************************
|
|
27
|
+
** Services
|
|
28
|
+
**************************************/
|
|
29
|
+
|
|
30
|
+
// {name, description, type, credentials}
|
|
31
|
+
createService(service) {
|
|
32
|
+
return this.apiClient.callApi('POST', 201, true, ['s2s', 'services'], service)
|
|
33
|
+
.catch(err => errors.handleError(err, {CUDSS0026E: errors.InvalidServiceCredentials}));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
createCloudantService({
|
|
38
|
+
name, description,
|
|
39
|
+
username, password, host=`${username}.cloudant.com`, port=443, url=`https://${username}:${password}@${host}`,
|
|
40
|
+
apikey, iam_apikey_name, iam_apikey_description, iam_role_crn, iam_serviceid_crn
|
|
41
|
+
}) {
|
|
42
|
+
return this.createService({name, description, type: 'cloudant', credentials: {
|
|
43
|
+
username, password, host, port, url,
|
|
44
|
+
apikey, iam_apikey_name, iam_apikey_description, iam_role_crn, iam_serviceid_crn
|
|
45
|
+
}})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
createEventstreamsService({name, description,
|
|
49
|
+
api_key, kafka_admin_url, kafka_brokers_sasl, user, password,
|
|
50
|
+
apikey, iam_apikey_name, iam_apikey_description, iam_role_crn, iam_serviceid_crn
|
|
51
|
+
}) {
|
|
52
|
+
return this.createService({name, description, type: 'eventstreams', credentials: {
|
|
53
|
+
api_key, kafka_admin_url, kafka_brokers_sasl, user, password,
|
|
54
|
+
apikey, iam_apikey_name, iam_apikey_description, iam_role_crn, iam_serviceid_crn
|
|
55
|
+
}})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getService(serviceId) {
|
|
59
|
+
return this.apiClient.callApi('GET', 200, true, ['s2s', 'services', serviceId])
|
|
60
|
+
.catch(err => errors.handleError(err, {CUDSS0019E: errors.ServiceNotFound}));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getServices(serviceType) {
|
|
64
|
+
return this.apiClient.callApi('GET', 200, true, ['s2s', 'services'], null, { bindingMode:'manual', serviceType })
|
|
65
|
+
.catch(err => errors.handleError(err, {}));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
deleteService(serviceId) {
|
|
70
|
+
return this.apiClient.callApi('DELETE', 204, false, ['s2s', 'services', serviceId])
|
|
71
|
+
.catch(err => errors.handleError(err, {}));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/**************************************
|
|
76
|
+
** Historian Connectors
|
|
77
|
+
**************************************/
|
|
78
|
+
|
|
79
|
+
// {name, description, serviceId, timezone, enabled}
|
|
80
|
+
createConnector({name, type, description=undefined, serviceId, timezone='UTC', enabled=true}) {
|
|
81
|
+
return this.apiClient.callApi('POST', 201, true, ['historianconnectors'], {name, description, type, serviceId, timezone, enabled})
|
|
82
|
+
.catch(err => errors.handleError(err, {}));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
updateConnector({id, name, description, serviceId, type, enabled, timezone}) {
|
|
87
|
+
return this.apiClient.callApi('PUT', 200, true, ['historianconnectors', id], {id, name, description, serviceId, type, enabled, timezone})
|
|
88
|
+
.catch(err => errors.handleError(err, {}));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getConnectors({name, serviceType, enabled, serviceId}) {
|
|
92
|
+
return this.apiClient.callApi('GET', 200, true, ['historianconnectors'], null, {
|
|
93
|
+
name: name ? name : undefined,
|
|
94
|
+
type: serviceType ? serviceType : undefined,
|
|
95
|
+
enabled: enabled === undefined ? undefined : enabled,
|
|
96
|
+
serviceId: serviceId ? serviceId : undefined,
|
|
97
|
+
})
|
|
98
|
+
.catch(err => errors.handleError(err, {}));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
deleteConnector(connectorId) {
|
|
102
|
+
return this.apiClient.callApi('DELETE', 204, false, ['historianconnectors', connectorId])
|
|
103
|
+
.catch(err => errors.handleError(err, {}));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
/**************************************
|
|
108
|
+
** Destinations
|
|
109
|
+
**************************************/
|
|
110
|
+
// {name, type, configuration}
|
|
111
|
+
createDestination(connectorId, destination) {
|
|
112
|
+
return this.apiClient.callApi('POST', 201, true, ['historianconnectors', connectorId, 'destinations'], destination)
|
|
113
|
+
.catch(err => errors.handleError(err, {CUDDSC0103E: errors.DestinationAlreadyExists}));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
createCloudantDestination(connectorId, {name, bucketInterval}) {
|
|
117
|
+
return this.createDestination(connectorId, {name, type: 'cloudant', configuration: { bucketInterval }});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
createEventstreamsDestination(connectorId, {name, partitions=1}) {
|
|
121
|
+
return this.createDestination(connectorId, {name, type: 'eventstreams', configuration: { partitions }});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
getDestinations(connectorId, params={name:undefined}) {
|
|
125
|
+
const {name} = params;
|
|
126
|
+
return this.apiClient.callApi('GET', 200, true, ['historianconnectors', connectorId, 'destinations'], null, {
|
|
127
|
+
name: name ? name : undefined,
|
|
128
|
+
})
|
|
129
|
+
.catch(err => errors.handleError(err, {}));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
deleteDestination(connectorId, destinationName) {
|
|
133
|
+
return this.apiClient.callApi('DELETE', [200, 204], false, ['historianconnectors', connectorId, 'destinations', destinationName])
|
|
134
|
+
.catch(err => errors.handleError(err, {}));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
/**************************************
|
|
139
|
+
** Forwarding Rules
|
|
140
|
+
**************************************/
|
|
141
|
+
|
|
142
|
+
// {name, destinationName, type:event, selector: {deviceType, eventId}}
|
|
143
|
+
// {name, destinationName, type:state, selector: {logicalInterfaceId}}
|
|
144
|
+
createForwardingRule(connectorId, forwardingrule) {
|
|
145
|
+
return this.apiClient.callApi('POST', 201, true, ['historianconnectors', connectorId, 'forwardingrules'], forwardingrule)
|
|
146
|
+
.catch(err => errors.handleError(err, {}));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
createEventForwardingRule(connectorId, {name, destinationName, deviceType='*', eventId='*'}) {
|
|
150
|
+
return this.createForwardingRule(connectorId, {name, destinationName, type: 'event', selector: {deviceType, eventId}})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
getForwardingRules(connectorId) {
|
|
154
|
+
// TODO: QS params
|
|
155
|
+
return this.apiClient.callApi('GET', 200, true, ['historianconnectors', connectorId, 'forwardingrules'])
|
|
156
|
+
.catch(err => errors.handleError(err, {}));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
deleteForwardingRule(connectorId, forwardingRuleId) {
|
|
160
|
+
return this.apiClient.callApi('DELETE', 204, false, ['historianconnectors', connectorId, 'forwardingrules', forwardingRuleId])
|
|
161
|
+
.catch(err => errors.handleError(err, {}));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
146
165
|
}
|
package/src/api/LecClient.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
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 LecClient {
|
|
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
|
-
getLastEvents(type, id) {
|
|
24
|
-
this.log.debug("[ApiClient] getLastEvents() - event cache");
|
|
25
|
-
return this.callApi('GET', 200, true, ["device", "types", type, "devices", id, "events"], null);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getLastEventsByEventType(type, id, eventType) {
|
|
29
|
-
this.log.debug("[ApiClient] getLastEventsByEventType() - event cache");
|
|
30
|
-
return this.callApi('GET', 200, true, ["device", "types", type, "devices", id, "events", eventType], null);
|
|
31
|
-
}
|
|
32
|
-
|
|
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 LecClient {
|
|
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
|
+
getLastEvents(type, id) {
|
|
24
|
+
this.log.debug("[ApiClient] getLastEvents() - event cache");
|
|
25
|
+
return this.callApi('GET', 200, true, ["device", "types", type, "devices", id, "events"], null);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getLastEventsByEventType(type, id, eventType) {
|
|
29
|
+
this.log.debug("[ApiClient] getLastEventsByEventType() - event cache");
|
|
30
|
+
return this.callApi('GET', 200, true, ["device", "types", type, "devices", id, "events", eventType], null);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
33
|
};
|
package/src/api/MgmtClient.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
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 MgmtClient {
|
|
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
|
-
getAllDeviceManagementRequests() {
|
|
24
|
-
this.log.debug("[ApiClient] getAllDeviceManagementRequests()");
|
|
25
|
-
return this.callApi('GET', 200, true, ['mgmt', 'requests'], null);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
initiateDeviceManagementRequest(action, parameters, devices) {
|
|
29
|
-
this.log.debug("[ApiClient] initiateDeviceManagementRequest(" + action + ", " + parameters + ", " + devices + ")");
|
|
30
|
-
let body = {
|
|
31
|
-
action: action,
|
|
32
|
-
parameters: parameters,
|
|
33
|
-
devices: devices
|
|
34
|
-
};
|
|
35
|
-
return this.callApi('POST', 202, true, ['mgmt', 'requests'], JSON.stringify(body));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
getDeviceManagementRequest(requestId) {
|
|
39
|
-
this.log.debug("[ApiClient] getDeviceManagementRequest(" + requestId + ")");
|
|
40
|
-
return this.callApi('GET', 200, true, ['mgmt', 'requests', requestId], null);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
deleteDeviceManagementRequest(requestId) {
|
|
44
|
-
this.log.debug("[ApiClient] deleteDeviceManagementRequest(" + requestId + ")");
|
|
45
|
-
return this.callApi('DELETE', 204, false, ['mgmt', 'requests', requestId], null);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
getDeviceManagementRequestStatus(requestId) {
|
|
49
|
-
this.log.debug("[ApiClient] getDeviceManagementRequestStatus(" + requestId + ")");
|
|
50
|
-
return this.callApi('GET', 200, true, ['mgmt', 'requests', requestId, 'deviceStatus'], null);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
getDeviceManagementRequestStatusByDevice(requestId, typeId, deviceId) {
|
|
54
|
-
this.log.debug("[ApiClient] getDeviceManagementRequestStatusByDevice(" + requestId + ", " + typeId + ", " + deviceId + ")");
|
|
55
|
-
return this.callApi('GET', 200, true, ['mgmt', 'requests', requestId, 'deviceStatus', typeId, deviceId], null);
|
|
56
|
-
}
|
|
57
|
-
|
|
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 MgmtClient {
|
|
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
|
+
getAllDeviceManagementRequests() {
|
|
24
|
+
this.log.debug("[ApiClient] getAllDeviceManagementRequests()");
|
|
25
|
+
return this.callApi('GET', 200, true, ['mgmt', 'requests'], null);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
initiateDeviceManagementRequest(action, parameters, devices) {
|
|
29
|
+
this.log.debug("[ApiClient] initiateDeviceManagementRequest(" + action + ", " + parameters + ", " + devices + ")");
|
|
30
|
+
let body = {
|
|
31
|
+
action: action,
|
|
32
|
+
parameters: parameters,
|
|
33
|
+
devices: devices
|
|
34
|
+
};
|
|
35
|
+
return this.callApi('POST', 202, true, ['mgmt', 'requests'], JSON.stringify(body));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getDeviceManagementRequest(requestId) {
|
|
39
|
+
this.log.debug("[ApiClient] getDeviceManagementRequest(" + requestId + ")");
|
|
40
|
+
return this.callApi('GET', 200, true, ['mgmt', 'requests', requestId], null);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
deleteDeviceManagementRequest(requestId) {
|
|
44
|
+
this.log.debug("[ApiClient] deleteDeviceManagementRequest(" + requestId + ")");
|
|
45
|
+
return this.callApi('DELETE', 204, false, ['mgmt', 'requests', requestId], null);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getDeviceManagementRequestStatus(requestId) {
|
|
49
|
+
this.log.debug("[ApiClient] getDeviceManagementRequestStatus(" + requestId + ")");
|
|
50
|
+
return this.callApi('GET', 200, true, ['mgmt', 'requests', requestId, 'deviceStatus'], null);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getDeviceManagementRequestStatusByDevice(requestId, typeId, deviceId) {
|
|
54
|
+
this.log.debug("[ApiClient] getDeviceManagementRequestStatusByDevice(" + requestId + ", " + typeId + ", " + deviceId + ")");
|
|
55
|
+
return this.callApi('GET', 200, true, ['mgmt', 'requests', requestId, 'deviceStatus', typeId, deviceId], null);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
58
|
};
|