@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,234 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
+
10
+ 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); } }
11
+
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
13
+
14
+ /**
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 RegistryClient =
25
+ /*#__PURE__*/
26
+ function () {
27
+ function RegistryClient(apiClient) {
28
+ _classCallCheck(this, RegistryClient);
29
+
30
+ this.apiClient = apiClient;
31
+ }
32
+
33
+ _createClass(RegistryClient, [{
34
+ key: "listAllDevicesOfType",
35
+ value: function listAllDevicesOfType(type) {
36
+ this.apiClient.log.debug("[ApiClient] listAllDevicesOfType(" + type + ")");
37
+ return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices'], null);
38
+ }
39
+ }, {
40
+ key: "deleteDeviceType",
41
+ value: function deleteDeviceType(type) {
42
+ this.apiClient.log.debug("[ApiClient] deleteDeviceType(" + type + ")");
43
+ return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type], null);
44
+ }
45
+ }, {
46
+ key: "getDeviceType",
47
+ value: function getDeviceType(type) {
48
+ this.apiClient.log.debug("[ApiClient] getDeviceType(" + type + ")");
49
+ return this.apiClient.callApi('GET', 200, true, ['device', 'types', type], null);
50
+ }
51
+ }, {
52
+ key: "getAllDeviceTypes",
53
+ value: function getAllDeviceTypes() {
54
+ this.apiClient.log.debug("[ApiClient] getAllDeviceTypes()");
55
+ return this.apiClient.callApi('GET', 200, true, ['device', 'types'], null);
56
+ }
57
+ }, {
58
+ key: "updateDeviceType",
59
+ value: function updateDeviceType(type, description, deviceInfo, metadata) {
60
+ this.apiClient.log.debug("[ApiClient] updateDeviceType(" + type + ", " + description + ", " + deviceInfo + ", " + metadata + ")");
61
+ var body = {
62
+ deviceInfo: deviceInfo,
63
+ description: description,
64
+ metadata: metadata
65
+ };
66
+ return this.apiClient.callApi('PUT', 200, true, ['device', 'types', type], JSON.stringify(body));
67
+ }
68
+ }, {
69
+ key: "registerDeviceType",
70
+ value: function registerDeviceType(typeId, description, deviceInfo, metadata, classId) {
71
+ this.apiClient.log.debug("[ApiClient] registerDeviceType(" + typeId + ", " + description + ", " + deviceInfo + ", " + metadata + ", " + classId + ")"); // TODO: field validation
72
+
73
+ classId = classId || "Device";
74
+ var body = {
75
+ id: typeId,
76
+ classId: classId,
77
+ deviceInfo: deviceInfo,
78
+ description: description,
79
+ metadata: metadata
80
+ };
81
+ return this.apiClient.callApi('POST', 201, true, ['device', 'types'], JSON.stringify(body));
82
+ }
83
+ }, {
84
+ key: "registerDevice",
85
+ value: function registerDevice(type, deviceId, authToken, deviceInfo, location, metadata) {
86
+ this.apiClient.log.debug("[ApiClient] registerDevice(" + type + ", " + deviceId + ", " + deviceInfo + ", " + location + ", " + metadata + ")"); // TODO: field validation
87
+
88
+ var body = {
89
+ deviceId: deviceId,
90
+ authToken: authToken,
91
+ deviceInfo: deviceInfo,
92
+ location: location,
93
+ metadata: metadata
94
+ };
95
+ return this.apiClient.callApi('POST', 201, true, ['device', 'types', type, 'devices'], JSON.stringify(body));
96
+ }
97
+ }, {
98
+ key: "unregisterDevice",
99
+ value: function unregisterDevice(type, deviceId) {
100
+ this.apiClient.log.debug("[ApiClient] unregisterDevice(" + type + ", " + deviceId + ")");
101
+ return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type, 'devices', deviceId], null);
102
+ }
103
+ }, {
104
+ key: "updateDevice",
105
+ value: function updateDevice(type, deviceId, deviceInfo, status, metadata, extensions) {
106
+ this.apiClient.log.debug("[ApiClient] updateDevice(" + type + ", " + deviceId + ", " + deviceInfo + ", " + status + ", " + metadata + ")");
107
+ var body = {
108
+ deviceInfo: deviceInfo,
109
+ status: status,
110
+ metadata: metadata,
111
+ extensions: extensions
112
+ };
113
+ return this.apiClient.callApi('PUT', 200, true, ['device', 'types', type, 'devices', deviceId], JSON.stringify(body));
114
+ }
115
+ }, {
116
+ key: "getDevice",
117
+ value: function getDevice(type, deviceId) {
118
+ this.apiClient.log.debug("[ApiClient] getDevice(" + type + ", " + deviceId + ")");
119
+ return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId], null);
120
+ }
121
+ /**
122
+ * Register multiple new devices, each request can contain a maximum of 512KB.
123
+ * The response body will contain the generated authentication tokens for all devices.
124
+ * The caller of the method must make sure to record these tokens when processing
125
+ * the response. The IBM Watson IoT Platform will not be able to retrieve lost authentication tokens
126
+ *
127
+ * @param arryOfDevicesToBeAdded Array of JSON devices to be added. Refer to
128
+ * <a href="https://docs.internetofthings.ibmcloud.com/swagger/v0002.html#!/Bulk_Operations/post_bulk_devices_add">link</a>
129
+ * for more information about the schema to be used
130
+ */
131
+
132
+ }, {
133
+ key: "registerMultipleDevices",
134
+ value: function registerMultipleDevices(arryOfDevicesToBeAdded) {
135
+ this.apiClient.log.debug("[ApiClient] arryOfDevicesToBeAdded() - BULK");
136
+ return this.apiClient.callApi('POST', 201, true, ["bulk", "devices", "add"], JSON.stringify(arryOfDevicesToBeAdded));
137
+ }
138
+ /**
139
+ * Delete multiple devices, each request can contain a maximum of 512Kb
140
+ *
141
+ * @param arryOfDevicesToBeDeleted Array of JSON devices to be deleted. Refer to
142
+ * <a href="https://docs.internetofthings.ibmcloud.com/swagger/v0002.html#!/Bulk_Operations/post_bulk_devices_remove">link</a>
143
+ * for more information about the schema to be used.
144
+ */
145
+
146
+ }, {
147
+ key: "deleteMultipleDevices",
148
+ value: function deleteMultipleDevices(arryOfDevicesToBeDeleted) {
149
+ this.apiClient.log.debug("[ApiClient] deleteMultipleDevices() - BULK");
150
+ return this.apiClient.callApi('POST', 201, true, ["bulk", "devices", "remove"], JSON.stringify(arryOfDevicesToBeDeleted));
151
+ }
152
+ }, {
153
+ key: "getDeviceLocation",
154
+ value: function getDeviceLocation(type, deviceId) {
155
+ this.apiClient.log.debug("[ApiClient] getDeviceLocation(" + type + ", " + deviceId + ")");
156
+ return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'location'], null);
157
+ }
158
+ }, {
159
+ key: "updateDeviceLocation",
160
+ value: function updateDeviceLocation(type, deviceId, location) {
161
+ this.apiClient.log.debug("[ApiClient] updateDeviceLocation(" + type + ", " + deviceId + ", " + location + ")");
162
+ return this.apiClient.callApi('PUT', 200, true, ['device', 'types', type, 'devices', deviceId, 'location'], JSON.stringify(location));
163
+ }
164
+ }, {
165
+ key: "getDeviceManagementInformation",
166
+ value: function getDeviceManagementInformation(type, deviceId) {
167
+ this.apiClient.log.debug("[ApiClient] getDeviceManagementInformation(" + type + ", " + deviceId + ")");
168
+ return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'mgmt'], null);
169
+ }
170
+ }, {
171
+ key: "getAllDiagnosticLogs",
172
+ value: function getAllDiagnosticLogs(type, deviceId) {
173
+ this.apiClient.log.debug("[ApiClient] getAllDiagnosticLogs(" + type + ", " + deviceId + ")");
174
+ return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs'], null);
175
+ }
176
+ }, {
177
+ key: "clearAllDiagnosticLogs",
178
+ value: function clearAllDiagnosticLogs(type, deviceId) {
179
+ this.apiClient.log.debug("[ApiClient] clearAllDiagnosticLogs(" + type + ", " + deviceId + ")");
180
+ return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs'], null);
181
+ }
182
+ }, {
183
+ key: "addDeviceDiagLogs",
184
+ value: function addDeviceDiagLogs(type, deviceId, log) {
185
+ this.apiClient.log.debug("[ApiClient] addDeviceDiagLogs(" + type + ", " + deviceId + ", " + log + ")");
186
+ return this.apiClient.callApi('POST', 201, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs'], JSON.stringify(log));
187
+ }
188
+ }, {
189
+ key: "getDiagnosticLog",
190
+ value: function getDiagnosticLog(type, deviceId, logId) {
191
+ this.apiClient.log.debug("[ApiClient] getAllDiagnosticLogs(" + type + ", " + deviceId + ", " + logId + ")");
192
+ return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs', logId], null);
193
+ }
194
+ }, {
195
+ key: "deleteDiagnosticLog",
196
+ value: function deleteDiagnosticLog(type, deviceId, logId) {
197
+ this.apiClient.log.debug("[ApiClient] deleteDiagnosticLog(" + type + ", " + deviceId + ", " + logId + ")");
198
+ return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'logs', logId], null);
199
+ }
200
+ }, {
201
+ key: "getDeviceErrorCodes",
202
+ value: function getDeviceErrorCodes(type, deviceId) {
203
+ this.apiClient.log.debug("[ApiClient] getDeviceErrorCodes(" + type + ", " + deviceId + ")");
204
+ return this.apiClient.callApi('GET', 200, true, ['device', 'types', type, 'devices', deviceId, 'diag', 'errorCodes'], null);
205
+ }
206
+ }, {
207
+ key: "clearDeviceErrorCodes",
208
+ value: function clearDeviceErrorCodes(type, deviceId) {
209
+ this.apiClient.log.debug("[ApiClient] clearDeviceErrorCodes(" + type + ", " + deviceId + ")");
210
+ return this.apiClient.callApi('DELETE', 204, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'errorCodes'], null);
211
+ }
212
+ }, {
213
+ key: "addErrorCode",
214
+ value: function addErrorCode(type, deviceId, log) {
215
+ this.apiClient.log.debug("[ApiClient] addErrorCode(" + type + ", " + deviceId + ", " + log + ")");
216
+ return this.apiClient.callApi('POST', 201, false, ['device', 'types', type, 'devices', deviceId, 'diag', 'errorCodes'], JSON.stringify(log));
217
+ }
218
+ }, {
219
+ key: "getDeviceConnectionLogs",
220
+ value: function getDeviceConnectionLogs(typeId, deviceId) {
221
+ this.apiClient.log.debug("[ApiClient] getDeviceConnectionLogs(" + typeId + ", " + deviceId + ")");
222
+ var params = {
223
+ typeId: typeId,
224
+ deviceId: deviceId
225
+ };
226
+ return this.apiClient.callApi('GET', 200, true, ['logs', 'connection'], null, params);
227
+ }
228
+ }]);
229
+
230
+ return RegistryClient;
231
+ }();
232
+
233
+ exports["default"] = RegistryClient;
234
+ ;
@@ -0,0 +1,105 @@
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 RulesClient =
19
+ /*#__PURE__*/
20
+ function () {
21
+ function RulesClient(apiClient) {
22
+ _classCallCheck(this, RulesClient);
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(RulesClient, [{
31
+ key: "getRulesForLogicalInterface",
32
+ value: function getRulesForLogicalInterface(logicalInterfaceId) {
33
+ if (this.draftMode) {
34
+ return this.getRulesForLogicalInterface(logicalInterfaceId);
35
+ } else {
36
+ return this.getActiveRulesForLogicalInterface(logicalInterfaceId);
37
+ }
38
+ }
39
+ }, {
40
+ key: "getDraftRulesForLogicalInterface",
41
+ value: function getDraftRulesForLogicalInterface(logicalInterfaceId) {
42
+ return this.callApi('GET', 200, true, ['draft', 'logicalinterfaces', logicalInterfaceId, 'rules']);
43
+ }
44
+ }, {
45
+ key: "getActiveRulesForLogicalInterface",
46
+ value: function getActiveRulesForLogicalInterface(logicalInterfaceId) {
47
+ return this.callApi('GET', 200, true, ['logicalinterfaces', logicalInterfaceId, 'rules']);
48
+ }
49
+ }, {
50
+ key: "createRule",
51
+ value: function createRule(logicalInterfaceId, name, condition) {
52
+ var description = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
53
+ var notificationStrategy = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : RulesClient.RuleNotificationStrategy.EVERY_TIME();
54
+ var body = {
55
+ name: name,
56
+ condition: condition,
57
+ notificationStrategy: notificationStrategy
58
+ };
59
+ if (description) body['description'] = description;
60
+ var base = this.draftMode ? ['draft', 'logicalinterfaces', logicalInterfaceId, 'rules'] : ['logicalinterfaces', logicalInterfaceId, 'rules'];
61
+ return this.callApi('POST', 201, true, base, JSON.stringify(body));
62
+ }
63
+ }, {
64
+ key: "updateRule",
65
+ value: function updateRule(rule) {
66
+ var base = this.draftMode ? ['draft', 'logicalinterfaces', rule.logicalInterfaceId, 'rules', rule.id] : ['logicalinterfaces', rule.logicalInterfaceId, 'rules', rule.id];
67
+ return this.callApi('PUT', 200, true, base, JSON.stringify(rule));
68
+ }
69
+ }, {
70
+ key: "deleteRule",
71
+ value: function deleteRule(logicalInterfaceId, ruleId) {
72
+ var base = this.draftMode ? ['draft', 'logicalinterfaces', logicalInterfaceId, 'rules', ruleId] : ['logicalinterfaces', logicalInterfaceId, 'rules', ruleId];
73
+ return this.callApi('DELETE', 204, false, base);
74
+ }
75
+ }]);
76
+
77
+ return RulesClient;
78
+ }();
79
+
80
+ exports["default"] = RulesClient;
81
+ RulesClient.RuleNotificationStrategy = {
82
+ EVERY_TIME: function EVERY_TIME() {
83
+ return {
84
+ when: 'every-time'
85
+ };
86
+ },
87
+ BECOMES_TRUE: function BECOMES_TRUE() {
88
+ return {
89
+ when: 'becomes-true'
90
+ };
91
+ },
92
+ X_IN_Y: function X_IN_Y(count) {
93
+ return {
94
+ when: 'x-in-y',
95
+ count: count
96
+ };
97
+ },
98
+ PERSISTS: function PERSISTS(count, timePeriod) {
99
+ return {
100
+ when: 'persists',
101
+ count: count,
102
+ timePeriod: timePeriod
103
+ };
104
+ }
105
+ };