@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.
Files changed (48) hide show
  1. package/LICENSE +203 -203
  2. package/README.md +68 -68
  3. package/dist/BaseClient.js +259 -0
  4. package/dist/BaseConfig.js +194 -0
  5. package/dist/api/ApiClient.js +508 -0
  6. package/dist/api/ApiErrors.js +118 -0
  7. package/dist/api/DscClient.js +332 -0
  8. package/dist/api/LecClient.js +48 -0
  9. package/dist/api/MgmtClient.js +77 -0
  10. package/dist/api/RegistryClient.js +234 -0
  11. package/dist/api/RulesClient.js +105 -0
  12. package/dist/api/StateClient.js +738 -0
  13. package/dist/application/ApplicationClient.js +436 -0
  14. package/dist/application/ApplicationConfig.js +233 -0
  15. package/dist/application/index.js +23 -0
  16. package/dist/bundled/wiotp-bundle.js +35592 -0
  17. package/dist/bundled/wiotp-bundle.min.js +47 -0
  18. package/dist/device/DeviceClient.js +125 -0
  19. package/dist/device/DeviceConfig.js +216 -0
  20. package/dist/device/index.js +23 -0
  21. package/dist/gateway/GatewayClient.js +159 -0
  22. package/dist/gateway/GatewayConfig.js +52 -0
  23. package/dist/gateway/index.js +23 -0
  24. package/dist/index.js +55 -0
  25. package/dist/util.js +50 -0
  26. package/package.json +92 -84
  27. package/src/BaseClient.js +215 -215
  28. package/src/BaseConfig.js +157 -157
  29. package/src/api/ApiClient.js +454 -454
  30. package/src/api/ApiErrors.js +33 -33
  31. package/src/api/DscClient.js +164 -145
  32. package/src/api/LecClient.js +32 -32
  33. package/src/api/MgmtClient.js +57 -57
  34. package/src/api/RegistryClient.js +194 -194
  35. package/src/api/RulesClient.js +84 -84
  36. package/src/api/StateClient.js +650 -650
  37. package/src/application/ApplicationClient.js +348 -348
  38. package/src/application/ApplicationConfig.js +191 -191
  39. package/src/application/index.js +12 -12
  40. package/src/device/DeviceClient.js +78 -78
  41. package/src/device/DeviceConfig.js +175 -175
  42. package/src/device/index.js +14 -14
  43. package/src/gateway/GatewayClient.js +114 -114
  44. package/src/gateway/GatewayConfig.js +21 -21
  45. package/src/gateway/index.js +13 -13
  46. package/{index.js → src/index.js} +19 -19
  47. package/src/util.js +38 -38
  48. package/src/util/IoTFoundation.pem +0 -82
@@ -0,0 +1,332 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _loglevel = _interopRequireDefault(require("loglevel"));
11
+
12
+ var errors = _interopRequireWildcard(require("./ApiErrors"));
13
+
14
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
15
+
16
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
+
20
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
+
22
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
23
+
24
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
25
+
26
+ var DscClient =
27
+ /*#__PURE__*/
28
+ function () {
29
+ function DscClient(apiClient) {
30
+ _classCallCheck(this, DscClient);
31
+
32
+ this.log = _loglevel["default"]; // callApi(method, expectedHttpCode, expectJsonContent, paths, body, params) {
33
+
34
+ this.apiClient = apiClient;
35
+ }
36
+ /**************************************
37
+ ** Services
38
+ **************************************/
39
+ // {name, description, type, credentials}
40
+
41
+
42
+ _createClass(DscClient, [{
43
+ key: "createService",
44
+ value: function createService(service) {
45
+ return this.apiClient.callApi('POST', 201, true, ['s2s', 'services'], service)["catch"](function (err) {
46
+ return errors.handleError(err, {
47
+ CUDSS0026E: errors.InvalidServiceCredentials
48
+ });
49
+ });
50
+ }
51
+ }, {
52
+ key: "createCloudantService",
53
+ value: function createCloudantService(_ref) {
54
+ var name = _ref.name,
55
+ description = _ref.description,
56
+ username = _ref.username,
57
+ password = _ref.password,
58
+ _ref$host = _ref.host,
59
+ host = _ref$host === void 0 ? "".concat(username, ".cloudant.com") : _ref$host,
60
+ _ref$port = _ref.port,
61
+ port = _ref$port === void 0 ? 443 : _ref$port,
62
+ _ref$url = _ref.url,
63
+ url = _ref$url === void 0 ? "https://".concat(username, ":").concat(password, "@").concat(host) : _ref$url,
64
+ apikey = _ref.apikey,
65
+ iam_apikey_name = _ref.iam_apikey_name,
66
+ iam_apikey_description = _ref.iam_apikey_description,
67
+ iam_role_crn = _ref.iam_role_crn,
68
+ iam_serviceid_crn = _ref.iam_serviceid_crn;
69
+ return this.createService({
70
+ name: name,
71
+ description: description,
72
+ type: 'cloudant',
73
+ credentials: {
74
+ username: username,
75
+ password: password,
76
+ host: host,
77
+ port: port,
78
+ url: url,
79
+ apikey: apikey,
80
+ iam_apikey_name: iam_apikey_name,
81
+ iam_apikey_description: iam_apikey_description,
82
+ iam_role_crn: iam_role_crn,
83
+ iam_serviceid_crn: iam_serviceid_crn
84
+ }
85
+ });
86
+ }
87
+ }, {
88
+ key: "createEventstreamsService",
89
+ value: function createEventstreamsService(_ref2) {
90
+ var name = _ref2.name,
91
+ description = _ref2.description,
92
+ api_key = _ref2.api_key,
93
+ kafka_admin_url = _ref2.kafka_admin_url,
94
+ kafka_brokers_sasl = _ref2.kafka_brokers_sasl,
95
+ user = _ref2.user,
96
+ password = _ref2.password,
97
+ apikey = _ref2.apikey,
98
+ iam_apikey_name = _ref2.iam_apikey_name,
99
+ iam_apikey_description = _ref2.iam_apikey_description,
100
+ iam_role_crn = _ref2.iam_role_crn,
101
+ iam_serviceid_crn = _ref2.iam_serviceid_crn;
102
+ return this.createService({
103
+ name: name,
104
+ description: description,
105
+ type: 'eventstreams',
106
+ credentials: {
107
+ api_key: api_key,
108
+ kafka_admin_url: kafka_admin_url,
109
+ kafka_brokers_sasl: kafka_brokers_sasl,
110
+ user: user,
111
+ password: password,
112
+ apikey: apikey,
113
+ iam_apikey_name: iam_apikey_name,
114
+ iam_apikey_description: iam_apikey_description,
115
+ iam_role_crn: iam_role_crn,
116
+ iam_serviceid_crn: iam_serviceid_crn
117
+ }
118
+ });
119
+ }
120
+ }, {
121
+ key: "getService",
122
+ value: function getService(serviceId) {
123
+ return this.apiClient.callApi('GET', 200, true, ['s2s', 'services', serviceId])["catch"](function (err) {
124
+ return errors.handleError(err, {
125
+ CUDSS0019E: errors.ServiceNotFound
126
+ });
127
+ });
128
+ }
129
+ }, {
130
+ key: "getServices",
131
+ value: function getServices(serviceType) {
132
+ return this.apiClient.callApi('GET', 200, true, ['s2s', 'services'], null, {
133
+ bindingMode: 'manual',
134
+ serviceType: serviceType
135
+ })["catch"](function (err) {
136
+ return errors.handleError(err, {});
137
+ });
138
+ }
139
+ }, {
140
+ key: "deleteService",
141
+ value: function deleteService(serviceId) {
142
+ return this.apiClient.callApi('DELETE', 204, false, ['s2s', 'services', serviceId])["catch"](function (err) {
143
+ return errors.handleError(err, {});
144
+ });
145
+ }
146
+ /**************************************
147
+ ** Historian Connectors
148
+ **************************************/
149
+ // {name, description, serviceId, timezone, enabled}
150
+
151
+ }, {
152
+ key: "createConnector",
153
+ value: function createConnector(_ref3) {
154
+ var name = _ref3.name,
155
+ type = _ref3.type,
156
+ _ref3$description = _ref3.description,
157
+ description = _ref3$description === void 0 ? undefined : _ref3$description,
158
+ serviceId = _ref3.serviceId,
159
+ _ref3$timezone = _ref3.timezone,
160
+ timezone = _ref3$timezone === void 0 ? 'UTC' : _ref3$timezone,
161
+ _ref3$enabled = _ref3.enabled,
162
+ enabled = _ref3$enabled === void 0 ? true : _ref3$enabled;
163
+ return this.apiClient.callApi('POST', 201, true, ['historianconnectors'], {
164
+ name: name,
165
+ description: description,
166
+ type: type,
167
+ serviceId: serviceId,
168
+ timezone: timezone,
169
+ enabled: enabled
170
+ })["catch"](function (err) {
171
+ return errors.handleError(err, {});
172
+ });
173
+ }
174
+ }, {
175
+ key: "updateConnector",
176
+ value: function updateConnector(_ref4) {
177
+ var id = _ref4.id,
178
+ name = _ref4.name,
179
+ description = _ref4.description,
180
+ serviceId = _ref4.serviceId,
181
+ type = _ref4.type,
182
+ enabled = _ref4.enabled,
183
+ timezone = _ref4.timezone;
184
+ return this.apiClient.callApi('PUT', 200, true, ['historianconnectors', id], {
185
+ id: id,
186
+ name: name,
187
+ description: description,
188
+ serviceId: serviceId,
189
+ type: type,
190
+ enabled: enabled,
191
+ timezone: timezone
192
+ })["catch"](function (err) {
193
+ return errors.handleError(err, {});
194
+ });
195
+ }
196
+ }, {
197
+ key: "getConnectors",
198
+ value: function getConnectors(_ref5) {
199
+ var name = _ref5.name,
200
+ serviceType = _ref5.serviceType,
201
+ enabled = _ref5.enabled,
202
+ serviceId = _ref5.serviceId;
203
+ return this.apiClient.callApi('GET', 200, true, ['historianconnectors'], null, {
204
+ name: name ? name : undefined,
205
+ type: serviceType ? serviceType : undefined,
206
+ enabled: enabled === undefined ? undefined : enabled,
207
+ serviceId: serviceId ? serviceId : undefined
208
+ })["catch"](function (err) {
209
+ return errors.handleError(err, {});
210
+ });
211
+ }
212
+ }, {
213
+ key: "deleteConnector",
214
+ value: function deleteConnector(connectorId) {
215
+ return this.apiClient.callApi('DELETE', 204, false, ['historianconnectors', connectorId])["catch"](function (err) {
216
+ return errors.handleError(err, {});
217
+ });
218
+ }
219
+ /**************************************
220
+ ** Destinations
221
+ **************************************/
222
+ // {name, type, configuration}
223
+
224
+ }, {
225
+ key: "createDestination",
226
+ value: function createDestination(connectorId, destination) {
227
+ return this.apiClient.callApi('POST', 201, true, ['historianconnectors', connectorId, 'destinations'], destination)["catch"](function (err) {
228
+ return errors.handleError(err, {
229
+ CUDDSC0103E: errors.DestinationAlreadyExists
230
+ });
231
+ });
232
+ }
233
+ }, {
234
+ key: "createCloudantDestination",
235
+ value: function createCloudantDestination(connectorId, _ref6) {
236
+ var name = _ref6.name,
237
+ bucketInterval = _ref6.bucketInterval;
238
+ return this.createDestination(connectorId, {
239
+ name: name,
240
+ type: 'cloudant',
241
+ configuration: {
242
+ bucketInterval: bucketInterval
243
+ }
244
+ });
245
+ }
246
+ }, {
247
+ key: "createEventstreamsDestination",
248
+ value: function createEventstreamsDestination(connectorId, _ref7) {
249
+ var name = _ref7.name,
250
+ _ref7$partitions = _ref7.partitions,
251
+ partitions = _ref7$partitions === void 0 ? 1 : _ref7$partitions;
252
+ return this.createDestination(connectorId, {
253
+ name: name,
254
+ type: 'eventstreams',
255
+ configuration: {
256
+ partitions: partitions
257
+ }
258
+ });
259
+ }
260
+ }, {
261
+ key: "getDestinations",
262
+ value: function getDestinations(connectorId) {
263
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
264
+ name: undefined
265
+ };
266
+ var name = params.name;
267
+ return this.apiClient.callApi('GET', 200, true, ['historianconnectors', connectorId, 'destinations'], null, {
268
+ name: name ? name : undefined
269
+ })["catch"](function (err) {
270
+ return errors.handleError(err, {});
271
+ });
272
+ }
273
+ }, {
274
+ key: "deleteDestination",
275
+ value: function deleteDestination(connectorId, destinationName) {
276
+ return this.apiClient.callApi('DELETE', [200, 204], false, ['historianconnectors', connectorId, 'destinations', destinationName])["catch"](function (err) {
277
+ return errors.handleError(err, {});
278
+ });
279
+ }
280
+ /**************************************
281
+ ** Forwarding Rules
282
+ **************************************/
283
+ // {name, destinationName, type:event, selector: {deviceType, eventId}}
284
+ // {name, destinationName, type:state, selector: {logicalInterfaceId}}
285
+
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
+
329
+ return DscClient;
330
+ }();
331
+
332
+ exports["default"] = DscClient;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _loglevel = _interopRequireDefault(require("loglevel"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+
12
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
+
14
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
15
+
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
17
+
18
+ var LecClient =
19
+ /*#__PURE__*/
20
+ function () {
21
+ function LecClient(apiClient) {
22
+ _classCallCheck(this, LecClient);
23
+
24
+ this.log = _loglevel["default"];
25
+ this.apiClient = apiClient; // Create an alias to the apiClient's callApi
26
+
27
+ this.callApi = this.apiClient.callApi.bind(this.apiClient);
28
+ }
29
+
30
+ _createClass(LecClient, [{
31
+ key: "getLastEvents",
32
+ value: function getLastEvents(type, id) {
33
+ this.log.debug("[ApiClient] getLastEvents() - event cache");
34
+ return this.callApi('GET', 200, true, ["device", "types", type, "devices", id, "events"], null);
35
+ }
36
+ }, {
37
+ key: "getLastEventsByEventType",
38
+ value: function getLastEventsByEventType(type, id, eventType) {
39
+ this.log.debug("[ApiClient] getLastEventsByEventType() - event cache");
40
+ return this.callApi('GET', 200, true, ["device", "types", type, "devices", id, "events", eventType], null);
41
+ }
42
+ }]);
43
+
44
+ return LecClient;
45
+ }();
46
+
47
+ exports["default"] = LecClient;
48
+ ;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _loglevel = _interopRequireDefault(require("loglevel"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+
12
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
+
14
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
15
+
16
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
17
+
18
+ var MgmtClient =
19
+ /*#__PURE__*/
20
+ function () {
21
+ function MgmtClient(apiClient) {
22
+ _classCallCheck(this, MgmtClient);
23
+
24
+ this.log = _loglevel["default"];
25
+ this.apiClient = apiClient; // Create an alias to the apiClient's callApi
26
+
27
+ this.callApi = this.apiClient.callApi.bind(this.apiClient);
28
+ }
29
+
30
+ _createClass(MgmtClient, [{
31
+ key: "getAllDeviceManagementRequests",
32
+ value: function getAllDeviceManagementRequests() {
33
+ this.log.debug("[ApiClient] getAllDeviceManagementRequests()");
34
+ return this.callApi('GET', 200, true, ['mgmt', 'requests'], null);
35
+ }
36
+ }, {
37
+ key: "initiateDeviceManagementRequest",
38
+ value: function initiateDeviceManagementRequest(action, parameters, devices) {
39
+ this.log.debug("[ApiClient] initiateDeviceManagementRequest(" + action + ", " + parameters + ", " + devices + ")");
40
+ var body = {
41
+ action: action,
42
+ parameters: parameters,
43
+ devices: devices
44
+ };
45
+ return this.callApi('POST', 202, true, ['mgmt', 'requests'], JSON.stringify(body));
46
+ }
47
+ }, {
48
+ key: "getDeviceManagementRequest",
49
+ value: function getDeviceManagementRequest(requestId) {
50
+ this.log.debug("[ApiClient] getDeviceManagementRequest(" + requestId + ")");
51
+ return this.callApi('GET', 200, true, ['mgmt', 'requests', requestId], null);
52
+ }
53
+ }, {
54
+ key: "deleteDeviceManagementRequest",
55
+ value: function deleteDeviceManagementRequest(requestId) {
56
+ this.log.debug("[ApiClient] deleteDeviceManagementRequest(" + requestId + ")");
57
+ return this.callApi('DELETE', 204, false, ['mgmt', 'requests', requestId], null);
58
+ }
59
+ }, {
60
+ key: "getDeviceManagementRequestStatus",
61
+ value: function getDeviceManagementRequestStatus(requestId) {
62
+ this.log.debug("[ApiClient] getDeviceManagementRequestStatus(" + requestId + ")");
63
+ return this.callApi('GET', 200, true, ['mgmt', 'requests', requestId, 'deviceStatus'], null);
64
+ }
65
+ }, {
66
+ key: "getDeviceManagementRequestStatusByDevice",
67
+ value: function getDeviceManagementRequestStatusByDevice(requestId, typeId, deviceId) {
68
+ this.log.debug("[ApiClient] getDeviceManagementRequestStatusByDevice(" + requestId + ", " + typeId + ", " + deviceId + ")");
69
+ return this.callApi('GET', 200, true, ['mgmt', 'requests', requestId, 'deviceStatus', typeId, deviceId], null);
70
+ }
71
+ }]);
72
+
73
+ return MgmtClient;
74
+ }();
75
+
76
+ exports["default"] = MgmtClient;
77
+ ;