@wiotp/sdk 0.8.3 → 0.8.4

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.
@@ -1,328 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _loglevel = _interopRequireDefault(require("loglevel"));
8
- var errors = _interopRequireWildcard(require("./ApiErrors"));
9
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
12
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
13
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
14
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
15
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
16
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
17
- *****************************************************************************
18
- Copyright (c) 2014, 2019 IBM Corporation and other Contributors.
19
- All rights reserved. This program and the accompanying materials
20
- are made available under the terms of the Eclipse Public License v1.0
21
- which accompanies this distribution, and is available at
22
- http://www.eclipse.org/legal/epl-v10.html
23
- *****************************************************************************
24
- *
25
- */
26
- var DscClient = exports["default"] = /*#__PURE__*/function () {
27
- function DscClient(apiClient) {
28
- _classCallCheck(this, DscClient);
29
- this.log = _loglevel["default"];
30
-
31
- // callApi(method, expectedHttpCode, expectJsonContent, paths, body, params) {
32
- this.apiClient = apiClient;
33
- }
34
-
35
- /**************************************
36
- ** Services
37
- **************************************/
38
-
39
- // {name, description, type, credentials}
40
- return _createClass(DscClient, [{
41
- key: "createService",
42
- value: function createService(service) {
43
- return this.apiClient.callApi('POST', 201, true, ['s2s', 'services'], service)["catch"](function (err) {
44
- return errors.handleError(err, {
45
- CUDSS0026E: errors.InvalidServiceCredentials
46
- });
47
- });
48
- }
49
- }, {
50
- key: "createCloudantService",
51
- value: function createCloudantService(_ref) {
52
- var name = _ref.name,
53
- description = _ref.description,
54
- username = _ref.username,
55
- password = _ref.password,
56
- _ref$host = _ref.host,
57
- host = _ref$host === void 0 ? "".concat(username, ".cloudant.com") : _ref$host,
58
- _ref$port = _ref.port,
59
- port = _ref$port === void 0 ? 443 : _ref$port,
60
- _ref$url = _ref.url,
61
- url = _ref$url === void 0 ? "https://".concat(username, ":").concat(password, "@").concat(host) : _ref$url,
62
- apikey = _ref.apikey,
63
- iam_apikey_name = _ref.iam_apikey_name,
64
- iam_apikey_description = _ref.iam_apikey_description,
65
- iam_role_crn = _ref.iam_role_crn,
66
- iam_serviceid_crn = _ref.iam_serviceid_crn;
67
- return this.createService({
68
- name: name,
69
- description: description,
70
- type: 'cloudant',
71
- credentials: {
72
- username: username,
73
- password: password,
74
- host: host,
75
- port: port,
76
- url: url,
77
- apikey: apikey,
78
- iam_apikey_name: iam_apikey_name,
79
- iam_apikey_description: iam_apikey_description,
80
- iam_role_crn: iam_role_crn,
81
- iam_serviceid_crn: iam_serviceid_crn
82
- }
83
- });
84
- }
85
- }, {
86
- key: "createEventstreamsService",
87
- value: function createEventstreamsService(_ref2) {
88
- var name = _ref2.name,
89
- description = _ref2.description,
90
- api_key = _ref2.api_key,
91
- kafka_admin_url = _ref2.kafka_admin_url,
92
- kafka_brokers_sasl = _ref2.kafka_brokers_sasl,
93
- user = _ref2.user,
94
- password = _ref2.password,
95
- apikey = _ref2.apikey,
96
- iam_apikey_name = _ref2.iam_apikey_name,
97
- iam_apikey_description = _ref2.iam_apikey_description,
98
- iam_role_crn = _ref2.iam_role_crn,
99
- iam_serviceid_crn = _ref2.iam_serviceid_crn;
100
- return this.createService({
101
- name: name,
102
- description: description,
103
- type: 'eventstreams',
104
- credentials: {
105
- api_key: api_key,
106
- kafka_admin_url: kafka_admin_url,
107
- kafka_brokers_sasl: kafka_brokers_sasl,
108
- user: user,
109
- password: password,
110
- apikey: apikey,
111
- iam_apikey_name: iam_apikey_name,
112
- iam_apikey_description: iam_apikey_description,
113
- iam_role_crn: iam_role_crn,
114
- iam_serviceid_crn: iam_serviceid_crn
115
- }
116
- });
117
- }
118
- }, {
119
- key: "getService",
120
- value: function getService(serviceId) {
121
- return this.apiClient.callApi('GET', 200, true, ['s2s', 'services', serviceId])["catch"](function (err) {
122
- return errors.handleError(err, {
123
- CUDSS0019E: errors.ServiceNotFound
124
- });
125
- });
126
- }
127
- }, {
128
- key: "getServices",
129
- value: function getServices(serviceType) {
130
- return this.apiClient.callApi('GET', 200, true, ['s2s', 'services'], null, {
131
- bindingMode: 'manual',
132
- serviceType: serviceType
133
- })["catch"](function (err) {
134
- return errors.handleError(err, {});
135
- });
136
- }
137
- }, {
138
- key: "deleteService",
139
- value: function deleteService(serviceId) {
140
- return this.apiClient.callApi('DELETE', 204, false, ['s2s', 'services', serviceId])["catch"](function (err) {
141
- return errors.handleError(err, {});
142
- });
143
- }
144
-
145
- /**************************************
146
- ** Historian Connectors
147
- **************************************/
148
-
149
- // {name, description, serviceId, timezone, enabled}
150
- }, {
151
- key: "createConnector",
152
- value: function createConnector(_ref3) {
153
- var name = _ref3.name,
154
- type = _ref3.type,
155
- _ref3$description = _ref3.description,
156
- description = _ref3$description === void 0 ? undefined : _ref3$description,
157
- serviceId = _ref3.serviceId,
158
- _ref3$timezone = _ref3.timezone,
159
- timezone = _ref3$timezone === void 0 ? 'UTC' : _ref3$timezone,
160
- _ref3$enabled = _ref3.enabled,
161
- enabled = _ref3$enabled === void 0 ? true : _ref3$enabled;
162
- return this.apiClient.callApi('POST', 201, true, ['historianconnectors'], {
163
- name: name,
164
- description: description,
165
- type: type,
166
- serviceId: serviceId,
167
- timezone: timezone,
168
- enabled: enabled
169
- })["catch"](function (err) {
170
- return errors.handleError(err, {});
171
- });
172
- }
173
- }, {
174
- key: "updateConnector",
175
- value: function updateConnector(_ref4) {
176
- var id = _ref4.id,
177
- name = _ref4.name,
178
- description = _ref4.description,
179
- serviceId = _ref4.serviceId,
180
- type = _ref4.type,
181
- enabled = _ref4.enabled,
182
- timezone = _ref4.timezone;
183
- return this.apiClient.callApi('PUT', 200, true, ['historianconnectors', id], {
184
- id: id,
185
- name: name,
186
- description: description,
187
- serviceId: serviceId,
188
- type: type,
189
- enabled: enabled,
190
- timezone: timezone
191
- })["catch"](function (err) {
192
- return errors.handleError(err, {});
193
- });
194
- }
195
- }, {
196
- key: "getConnectors",
197
- value: function getConnectors(_ref5) {
198
- var name = _ref5.name,
199
- serviceType = _ref5.serviceType,
200
- enabled = _ref5.enabled,
201
- serviceId = _ref5.serviceId;
202
- return this.apiClient.callApi('GET', 200, true, ['historianconnectors'], null, {
203
- name: name ? name : undefined,
204
- type: serviceType ? serviceType : undefined,
205
- enabled: enabled === undefined ? undefined : enabled,
206
- serviceId: serviceId ? serviceId : undefined
207
- })["catch"](function (err) {
208
- return errors.handleError(err, {});
209
- });
210
- }
211
- }, {
212
- key: "deleteConnector",
213
- value: function deleteConnector(connectorId) {
214
- return this.apiClient.callApi('DELETE', 204, false, ['historianconnectors', connectorId])["catch"](function (err) {
215
- return errors.handleError(err, {});
216
- });
217
- }
218
-
219
- /**************************************
220
- ** Destinations
221
- **************************************/
222
- // {name, type, configuration}
223
- }, {
224
- key: "createDestination",
225
- value: function createDestination(connectorId, destination) {
226
- return this.apiClient.callApi('POST', 201, true, ['historianconnectors', connectorId, 'destinations'], destination)["catch"](function (err) {
227
- return errors.handleError(err, {
228
- CUDDSC0103E: errors.DestinationAlreadyExists
229
- });
230
- });
231
- }
232
- }, {
233
- key: "createCloudantDestination",
234
- value: function createCloudantDestination(connectorId, _ref6) {
235
- var name = _ref6.name,
236
- bucketInterval = _ref6.bucketInterval;
237
- return this.createDestination(connectorId, {
238
- name: name,
239
- type: 'cloudant',
240
- configuration: {
241
- bucketInterval: bucketInterval
242
- }
243
- });
244
- }
245
- }, {
246
- key: "createEventstreamsDestination",
247
- value: function createEventstreamsDestination(connectorId, _ref7) {
248
- var name = _ref7.name,
249
- _ref7$partitions = _ref7.partitions,
250
- partitions = _ref7$partitions === void 0 ? 1 : _ref7$partitions;
251
- return this.createDestination(connectorId, {
252
- name: name,
253
- type: 'eventstreams',
254
- configuration: {
255
- partitions: partitions
256
- }
257
- });
258
- }
259
- }, {
260
- key: "getDestinations",
261
- value: function getDestinations(connectorId) {
262
- var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
263
- name: undefined
264
- };
265
- var name = params.name;
266
- return this.apiClient.callApi('GET', 200, true, ['historianconnectors', connectorId, 'destinations'], null, {
267
- name: name ? name : undefined
268
- })["catch"](function (err) {
269
- return errors.handleError(err, {});
270
- });
271
- }
272
- }, {
273
- key: "deleteDestination",
274
- value: function deleteDestination(connectorId, destinationName) {
275
- return this.apiClient.callApi('DELETE', [200, 204], false, ['historianconnectors', connectorId, 'destinations', destinationName])["catch"](function (err) {
276
- return errors.handleError(err, {});
277
- });
278
- }
279
-
280
- /**************************************
281
- ** Forwarding Rules
282
- **************************************/
283
-
284
- // {name, destinationName, type:event, selector: {deviceType, eventId}}
285
- // {name, destinationName, type:state, selector: {logicalInterfaceId}}
286
- }, {
287
- key: "createForwardingRule",
288
- value: function createForwardingRule(connectorId, forwardingrule) {
289
- return this.apiClient.callApi('POST', 201, true, ['historianconnectors', connectorId, 'forwardingrules'], forwardingrule)["catch"](function (err) {
290
- return errors.handleError(err, {});
291
- });
292
- }
293
- }, {
294
- key: "createEventForwardingRule",
295
- value: function createEventForwardingRule(connectorId, _ref8) {
296
- var name = _ref8.name,
297
- destinationName = _ref8.destinationName,
298
- _ref8$deviceType = _ref8.deviceType,
299
- deviceType = _ref8$deviceType === void 0 ? '*' : _ref8$deviceType,
300
- _ref8$eventId = _ref8.eventId,
301
- eventId = _ref8$eventId === void 0 ? '*' : _ref8$eventId;
302
- return this.createForwardingRule(connectorId, {
303
- name: name,
304
- destinationName: destinationName,
305
- type: 'event',
306
- selector: {
307
- deviceType: deviceType,
308
- eventId: eventId
309
- }
310
- });
311
- }
312
- }, {
313
- key: "getForwardingRules",
314
- value: function getForwardingRules(connectorId) {
315
- // TODO: QS params
316
- return this.apiClient.callApi('GET', 200, true, ['historianconnectors', connectorId, 'forwardingrules'])["catch"](function (err) {
317
- return errors.handleError(err, {});
318
- });
319
- }
320
- }, {
321
- key: "deleteForwardingRule",
322
- value: function deleteForwardingRule(connectorId, forwardingRuleId) {
323
- return this.apiClient.callApi('DELETE', 204, false, ['historianconnectors', connectorId, 'forwardingrules', forwardingRuleId])["catch"](function (err) {
324
- return errors.handleError(err, {});
325
- });
326
- }
327
- }]);
328
- }();
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _loglevel = _interopRequireDefault(require("loglevel"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
9
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
11
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
12
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
13
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
14
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
15
- *****************************************************************************
16
- Copyright (c) 2014, 2019 IBM Corporation and other Contributors.
17
- All rights reserved. This program and the accompanying materials
18
- are made available under the terms of the Eclipse Public License v1.0
19
- which accompanies this distribution, and is available at
20
- http://www.eclipse.org/legal/epl-v10.html
21
- *****************************************************************************
22
- *
23
- */
24
- var LecClient = exports["default"] = /*#__PURE__*/function () {
25
- function LecClient(apiClient) {
26
- _classCallCheck(this, LecClient);
27
- this.log = _loglevel["default"];
28
- this.apiClient = apiClient;
29
-
30
- // Create an alias to the apiClient's callApi
31
- this.callApi = this.apiClient.callApi.bind(this.apiClient);
32
- }
33
- return _createClass(LecClient, [{
34
- key: "getLastEvents",
35
- value: function getLastEvents(type, id) {
36
- this.log.debug("[ApiClient] getLastEvents() - event cache");
37
- return this.callApi('GET', 200, true, ["device", "types", type, "devices", id, "events"], null);
38
- }
39
- }, {
40
- key: "getLastEventsByEventType",
41
- value: function getLastEventsByEventType(type, id, eventType) {
42
- this.log.debug("[ApiClient] getLastEventsByEventType() - event cache");
43
- return this.callApi('GET', 200, true, ["device", "types", type, "devices", id, "events", eventType], null);
44
- }
45
- }]);
46
- }();
47
- ;
@@ -1,76 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _loglevel = _interopRequireDefault(require("loglevel"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
9
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
11
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
12
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
13
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
14
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
15
- *****************************************************************************
16
- Copyright (c) 2014, 2019 IBM Corporation and other Contributors.
17
- All rights reserved. This program and the accompanying materials
18
- are made available under the terms of the Eclipse Public License v1.0
19
- which accompanies this distribution, and is available at
20
- http://www.eclipse.org/legal/epl-v10.html
21
- *****************************************************************************
22
- *
23
- */
24
- var MgmtClient = exports["default"] = /*#__PURE__*/function () {
25
- function MgmtClient(apiClient) {
26
- _classCallCheck(this, MgmtClient);
27
- this.log = _loglevel["default"];
28
- this.apiClient = apiClient;
29
-
30
- // Create an alias to the apiClient's callApi
31
- this.callApi = this.apiClient.callApi.bind(this.apiClient);
32
- }
33
- return _createClass(MgmtClient, [{
34
- key: "getAllDeviceManagementRequests",
35
- value: function getAllDeviceManagementRequests() {
36
- this.log.debug("[ApiClient] getAllDeviceManagementRequests()");
37
- return this.callApi('GET', 200, true, ['mgmt', 'requests'], null);
38
- }
39
- }, {
40
- key: "initiateDeviceManagementRequest",
41
- value: function initiateDeviceManagementRequest(action, parameters, devices) {
42
- this.log.debug("[ApiClient] initiateDeviceManagementRequest(" + action + ", " + parameters + ", " + devices + ")");
43
- var body = {
44
- action: action,
45
- parameters: parameters,
46
- devices: devices
47
- };
48
- return this.callApi('POST', 202, true, ['mgmt', 'requests'], JSON.stringify(body));
49
- }
50
- }, {
51
- key: "getDeviceManagementRequest",
52
- value: function getDeviceManagementRequest(requestId) {
53
- this.log.debug("[ApiClient] getDeviceManagementRequest(" + requestId + ")");
54
- return this.callApi('GET', 200, true, ['mgmt', 'requests', requestId], null);
55
- }
56
- }, {
57
- key: "deleteDeviceManagementRequest",
58
- value: function deleteDeviceManagementRequest(requestId) {
59
- this.log.debug("[ApiClient] deleteDeviceManagementRequest(" + requestId + ")");
60
- return this.callApi('DELETE', 204, false, ['mgmt', 'requests', requestId], null);
61
- }
62
- }, {
63
- key: "getDeviceManagementRequestStatus",
64
- value: function getDeviceManagementRequestStatus(requestId) {
65
- this.log.debug("[ApiClient] getDeviceManagementRequestStatus(" + requestId + ")");
66
- return this.callApi('GET', 200, true, ['mgmt', 'requests', requestId, 'deviceStatus'], null);
67
- }
68
- }, {
69
- key: "getDeviceManagementRequestStatusByDevice",
70
- value: function getDeviceManagementRequestStatusByDevice(requestId, typeId, deviceId) {
71
- this.log.debug("[ApiClient] getDeviceManagementRequestStatusByDevice(" + requestId + ", " + typeId + ", " + deviceId + ")");
72
- return this.callApi('GET', 200, true, ['mgmt', 'requests', requestId, 'deviceStatus', typeId, deviceId], null);
73
- }
74
- }]);
75
- }();
76
- ;