@wiotp/sdk 0.7.8 → 0.7.9-beta.1
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/dist/BaseClient.js +36 -82
- package/dist/BaseConfig.js +24 -36
- package/dist/api/ApiClient.js +60 -76
- package/dist/api/ApiErrors.js +29 -74
- package/dist/api/DscClient.js +77 -77
- package/dist/api/LecClient.js +17 -15
- package/dist/api/MgmtClient.js +17 -15
- package/dist/api/RegistryClient.js +12 -18
- package/dist/api/RulesClient.js +17 -15
- package/dist/api/StateClient.js +70 -132
- package/dist/application/ApplicationClient.js +53 -137
- package/dist/application/ApplicationConfig.js +43 -64
- package/dist/application/index.js +0 -3
- package/dist/bundled/wiotp-bundle.js +39030 -34326
- package/dist/bundled/wiotp-bundle.min.js +7 -6
- package/dist/device/DeviceClient.js +25 -54
- package/dist/device/DeviceConfig.js +37 -59
- package/dist/device/index.js +0 -3
- package/dist/gateway/GatewayClient.js +27 -61
- package/dist/gateway/GatewayConfig.js +22 -33
- package/dist/gateway/index.js +0 -3
- package/dist/index.js +14 -28
- package/dist/util.js +9 -15
- package/package.json +24 -24
- package/src/BaseClient.js +1 -1
- package/src/application/ApplicationConfig.js +1 -1
package/dist/api/ApiClient.js
CHANGED
|
@@ -4,47 +4,42 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _axios = _interopRequireDefault(require("axios"));
|
|
9
|
-
|
|
10
8
|
var _bluebird = _interopRequireDefault(require("bluebird"));
|
|
11
|
-
|
|
12
9
|
var _btoa = _interopRequireDefault(require("btoa"));
|
|
13
|
-
|
|
14
10
|
var _formData = _interopRequireDefault(require("form-data"));
|
|
15
|
-
|
|
16
11
|
var _loglevel = _interopRequireDefault(require("loglevel"));
|
|
17
|
-
|
|
18
12
|
var _util = require("../util");
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
21
|
-
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
27
|
-
|
|
28
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
29
|
-
|
|
14
|
+
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); }
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
30
18
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
31
|
-
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
20
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
21
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
22
|
+
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); } /**
|
|
23
|
+
*****************************************************************************
|
|
24
|
+
Copyright (c) 2014, 2019 IBM Corporation and other Contributors.
|
|
25
|
+
All rights reserved. This program and the accompanying materials
|
|
26
|
+
are made available under the terms of the Eclipse Public License v1.0
|
|
27
|
+
which accompanies this distribution, and is available at
|
|
28
|
+
http://www.eclipse.org/legal/epl-v10.html
|
|
29
|
+
*****************************************************************************
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
var ApiClient = exports["default"] = /*#__PURE__*/function () {
|
|
37
33
|
function ApiClient(config) {
|
|
38
34
|
_classCallCheck(this, ApiClient);
|
|
39
|
-
|
|
40
35
|
this.log = _loglevel["default"];
|
|
41
36
|
this.log.setDefaultLevel(config.options.logLevel);
|
|
42
37
|
this.config = config;
|
|
43
38
|
this.useLtpa = this.config.auth && this.config.auth.useLtpa;
|
|
44
39
|
this.log.debug("[ApiClient:constructor] ApiClient initialized for " + this.config.getApiBaseUri());
|
|
45
|
-
}
|
|
46
|
-
|
|
40
|
+
}
|
|
47
41
|
|
|
42
|
+
// e.g. [{name: true}, {description: false}] => -name,description
|
|
48
43
|
_createClass(ApiClient, [{
|
|
49
44
|
key: "parseSortSpec",
|
|
50
45
|
value: function parseSortSpec(sortSpec) {
|
|
@@ -57,16 +52,13 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
57
52
|
key: "callApi",
|
|
58
53
|
value: function callApi(method, expectedHttpCode, expectJsonContent, paths, body, params) {
|
|
59
54
|
var _this = this;
|
|
60
|
-
|
|
61
55
|
return new _bluebird["default"](function (resolve, reject) {
|
|
62
56
|
var uri = _this.config.getApiBaseUri();
|
|
63
|
-
|
|
64
57
|
if (Array.isArray(paths)) {
|
|
65
58
|
for (var i = 0, l = paths.length; i < l; i++) {
|
|
66
59
|
uri += '/' + paths[i];
|
|
67
60
|
}
|
|
68
61
|
}
|
|
69
|
-
|
|
70
62
|
var xhrConfig = {
|
|
71
63
|
url: uri,
|
|
72
64
|
method: method,
|
|
@@ -81,25 +73,20 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
81
73
|
}
|
|
82
74
|
}
|
|
83
75
|
};
|
|
84
|
-
|
|
85
76
|
if (_this.useLtpa) {
|
|
86
77
|
xhrConfig.withCredentials = true;
|
|
87
78
|
} else {
|
|
88
79
|
xhrConfig.headers['Authorization'] = 'Basic ' + (0, _btoa["default"])(_this.config.auth.key + ':' + _this.config.auth.token);
|
|
89
80
|
}
|
|
90
|
-
|
|
91
81
|
if (body) {
|
|
92
82
|
xhrConfig.data = body;
|
|
93
83
|
}
|
|
94
|
-
|
|
95
84
|
if (params) {
|
|
96
85
|
xhrConfig.params = params;
|
|
97
86
|
}
|
|
98
|
-
|
|
99
87
|
if (_this.config.getAdditionalHeaders()) {
|
|
100
88
|
xhrConfig.headers = _objectSpread(_objectSpread({}, xhrConfig.headers), _this.config.getAdditionalHeaders());
|
|
101
89
|
}
|
|
102
|
-
|
|
103
90
|
function transformResponse(response) {
|
|
104
91
|
if (expectJsonContent && !(_typeof(response.data) === 'object')) {
|
|
105
92
|
try {
|
|
@@ -111,9 +98,7 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
111
98
|
resolve(response.data);
|
|
112
99
|
}
|
|
113
100
|
}
|
|
114
|
-
|
|
115
101
|
_this.log.debug("[ApiClient:transformResponse] " + xhrConfig);
|
|
116
|
-
|
|
117
102
|
(0, _axios["default"])(xhrConfig).then(transformResponse, reject);
|
|
118
103
|
});
|
|
119
104
|
}
|
|
@@ -128,8 +113,9 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
128
113
|
value: function getServiceStatus() {
|
|
129
114
|
this.log.debug("[ApiClient] getServiceStatus()");
|
|
130
115
|
return this.callApi('GET', 200, true, ['service-status'], null);
|
|
131
|
-
}
|
|
116
|
+
}
|
|
132
117
|
|
|
118
|
+
//Usage Management
|
|
133
119
|
}, {
|
|
134
120
|
key: "getActiveDevices",
|
|
135
121
|
value: function getActiveDevices(start, end, detail) {
|
|
@@ -165,8 +151,9 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
165
151
|
detail: detail
|
|
166
152
|
};
|
|
167
153
|
return this.callApi('GET', 200, true, ['usage', 'data-traffic'], null, params);
|
|
168
|
-
}
|
|
154
|
+
}
|
|
169
155
|
|
|
156
|
+
//client connectivity status
|
|
170
157
|
}, {
|
|
171
158
|
key: "getConnectionStates",
|
|
172
159
|
value: function getConnectionStates() {
|
|
@@ -196,14 +183,16 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
196
183
|
value: function getCustomConnectionState(query) {
|
|
197
184
|
this.log.debug("[ApiClient] getCustomConnectionStates() - client connectivity");
|
|
198
185
|
return this.callApi('GET', 200, true, ["clientconnectionstates" + query], null);
|
|
199
|
-
}
|
|
186
|
+
}
|
|
200
187
|
|
|
188
|
+
//bulk apis
|
|
201
189
|
}, {
|
|
202
190
|
key: "getAllDevices",
|
|
203
191
|
value: function getAllDevices(params) {
|
|
204
192
|
this.log.debug("[ApiClient] getAllDevices() - BULK");
|
|
205
193
|
return this.callApi('GET', 200, true, ["bulk", "devices"], null, params);
|
|
206
194
|
}
|
|
195
|
+
|
|
207
196
|
/**
|
|
208
197
|
* Gateway Access Control (Beta)
|
|
209
198
|
* The methods in this section follow the documentation listed under the link:
|
|
@@ -218,12 +207,12 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
218
207
|
* Retrieving and updating device properties
|
|
219
208
|
*
|
|
220
209
|
*/
|
|
210
|
+
|
|
221
211
|
//getGatewayGroup(gatewayId)
|
|
222
212
|
//updateDeviceRoles(deviceId, roles[])
|
|
223
213
|
//getAllDevicesInGropu(groupId)
|
|
224
214
|
//addDevicesToGroup(groupId, deviceList[])
|
|
225
215
|
//removeDevicesFromGroup(groupId, deviceList[])
|
|
226
|
-
|
|
227
216
|
}, {
|
|
228
217
|
key: "getGroupIdsForDevice",
|
|
229
218
|
value: function getGroupIdsForDevice(deviceId) {
|
|
@@ -253,7 +242,10 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
253
242
|
value: function removeDevicesFromGroup(groupId, deviceList) {
|
|
254
243
|
this.log.debug("[ApiClient] removeDevicesFromGroup(" + groupId + "," + deviceList + ")");
|
|
255
244
|
return this.callApi('PUT', 200, false, ['bulk', 'devices', groupId, "remove"], deviceList);
|
|
256
|
-
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// https://console.ng.bluemix.net/docs/services/IoT/gateways/gateway-access-control.html
|
|
248
|
+
|
|
257
249
|
// Finding a Resource Group
|
|
258
250
|
// getGatewayGroups()
|
|
259
251
|
// Querying a resource group
|
|
@@ -267,81 +259,94 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
267
259
|
// getDeviceRoles(deviceId)
|
|
268
260
|
// updateGatewayProperties(gatewayId,control_props)
|
|
269
261
|
// updateDeviceControlProperties(deviceId, withroles)
|
|
270
|
-
// Finding a Resource Group
|
|
271
262
|
|
|
263
|
+
// Finding a Resource Group
|
|
272
264
|
}, {
|
|
273
265
|
key: "getAllGroups",
|
|
274
266
|
value: function getAllGroups() {
|
|
275
267
|
this.log.debug("[ApiClient] getAllGroups()");
|
|
276
268
|
return this.callApi('GET', 200, true, ['groups'], null);
|
|
277
|
-
}
|
|
278
|
-
// Get unique identifiers of the members of the resource group
|
|
269
|
+
}
|
|
279
270
|
|
|
271
|
+
// Querying a resource group
|
|
272
|
+
|
|
273
|
+
// Get unique identifiers of the members of the resource group
|
|
280
274
|
}, {
|
|
281
275
|
key: "getAllDeviceIdsInGroup",
|
|
282
276
|
value: function getAllDeviceIdsInGroup(groupId) {
|
|
283
277
|
this.log.debug("[ApiClient] getAllDeviceIdsInGroup(" + groupId + ")");
|
|
284
278
|
return this.callApi('GET', 200, true, ['bulk', 'devices', groupId, "ids"], null);
|
|
285
|
-
}
|
|
279
|
+
}
|
|
286
280
|
|
|
281
|
+
// properties of the resource group
|
|
287
282
|
}, {
|
|
288
283
|
key: "getGroup",
|
|
289
284
|
value: function getGroup(groupId) {
|
|
290
285
|
this.log.debug("[ApiClient] getGroup(" + groupId + ")");
|
|
291
286
|
return this.callApi('GET', 200, true, ['groups', groupId], null);
|
|
292
|
-
}
|
|
293
|
-
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Creating and deleting a resource group
|
|
294
290
|
|
|
291
|
+
// Create a Resource Group
|
|
295
292
|
}, {
|
|
296
293
|
key: "createGroup",
|
|
297
294
|
value: function createGroup(groupInfo) {
|
|
298
295
|
this.log.debug("[ApiClient] createGroup()");
|
|
299
296
|
return this.callApi('POST', 201, true, ['groups'], groupInfo);
|
|
300
|
-
}
|
|
297
|
+
}
|
|
301
298
|
|
|
299
|
+
// Delete a Resource Group
|
|
302
300
|
}, {
|
|
303
301
|
key: "deleteGroup",
|
|
304
302
|
value: function deleteGroup(groupId) {
|
|
305
303
|
this.log.debug("[ApiClient] deleteGroup(" + groupId + ")");
|
|
306
304
|
return this.callApi('DELETE', 200, false, ['groups', groupId], null);
|
|
307
|
-
}
|
|
308
|
-
// Get the ID of the devices group of a gateway
|
|
305
|
+
}
|
|
309
306
|
|
|
307
|
+
// Retrieving and updating device properties
|
|
308
|
+
|
|
309
|
+
// Get the ID of the devices group of a gateway
|
|
310
310
|
}, {
|
|
311
311
|
key: "getAllDeviceAccessControlProperties",
|
|
312
312
|
value: function getAllDeviceAccessControlProperties() {
|
|
313
313
|
this.log.debug("[ApiClient] getAllDeviceAccessControlProperties()");
|
|
314
314
|
return this.callApi('GET', 200, true, ['authorization', 'devices'], null);
|
|
315
|
-
}
|
|
315
|
+
}
|
|
316
316
|
|
|
317
|
+
// Get standard role of a gateway
|
|
317
318
|
}, {
|
|
318
319
|
key: "getDeviceAccessControlProperties",
|
|
319
320
|
value: function getDeviceAccessControlProperties(deviceId) {
|
|
320
321
|
this.log.debug("[ApiClient] getDeviceAccessControlProperties(" + deviceId + ")");
|
|
321
322
|
return this.callApi('GET', 200, true, ['authorization', 'devices', deviceId, 'roles'], null);
|
|
322
|
-
}
|
|
323
|
+
}
|
|
323
324
|
|
|
325
|
+
// Update device properties without affecting the access control properties
|
|
324
326
|
}, {
|
|
325
327
|
key: "updateDeviceAccessControlProperties",
|
|
326
328
|
value: function updateDeviceAccessControlProperties(deviceId, deviceProps) {
|
|
327
329
|
this.log.debug("[ApiClient] updateDeviceAccessControlProperties(" + deviceId + ")");
|
|
328
330
|
return this.callApi('PUT', 200, true, ['authorization', 'devices', deviceId], deviceProps);
|
|
329
|
-
}
|
|
331
|
+
}
|
|
330
332
|
|
|
333
|
+
// Assign a standard role to a gateway
|
|
331
334
|
}, {
|
|
332
335
|
key: "updateDeviceAccessControlPropertiesWithRoles",
|
|
333
336
|
value: function updateDeviceAccessControlPropertiesWithRoles(deviceId, devicePropsWithRoles) {
|
|
334
337
|
this.log.debug("[ApiClient] updateDeviceAccessControlPropertiesWithRoles(" + deviceId + "," + devicePropsWithRoles + ")");
|
|
335
338
|
return this.callApi('PUT', 200, true, ['authorization', 'devices', deviceId, 'withroles'], devicePropsWithRoles);
|
|
336
|
-
}
|
|
339
|
+
}
|
|
337
340
|
|
|
341
|
+
// Duplicating updateDeviceRoles(deviceId, roles) for Gateway Roles
|
|
338
342
|
}, {
|
|
339
343
|
key: "updateGatewayRoles",
|
|
340
344
|
value: function updateGatewayRoles(gatewayId, roles) {
|
|
341
345
|
this.log.debug("[ApiClient] updateGatewayRoles(" + gatewayId + "," + roles + ")");
|
|
342
346
|
return this.callApi('PUT', 200, false, ['authorization', 'devices', gatewayId, 'roles'], roles);
|
|
343
|
-
}
|
|
347
|
+
}
|
|
344
348
|
|
|
349
|
+
// Extending getAllGroups() to fetch individual Groups
|
|
345
350
|
}, {
|
|
346
351
|
key: "getGroups",
|
|
347
352
|
value: function getGroups(groupId) {
|
|
@@ -352,16 +357,13 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
352
357
|
key: "callFormDataApi",
|
|
353
358
|
value: function callFormDataApi(method, expectedHttpCode, expectJsonContent, paths, body, params) {
|
|
354
359
|
var _this2 = this;
|
|
355
|
-
|
|
356
360
|
return new _bluebird["default"](function (resolve, reject) {
|
|
357
361
|
var uri = _this2.config.getApiBaseUri();
|
|
358
|
-
|
|
359
362
|
if (Array.isArray(paths)) {
|
|
360
363
|
for (var i = 0, l = paths.length; i < l; i++) {
|
|
361
364
|
uri += '/' + paths[i];
|
|
362
365
|
}
|
|
363
366
|
}
|
|
364
|
-
|
|
365
367
|
var xhrConfig = {
|
|
366
368
|
url: uri,
|
|
367
369
|
method: method,
|
|
@@ -369,20 +371,16 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
369
371
|
'Content-Type': 'multipart/form-data'
|
|
370
372
|
}
|
|
371
373
|
};
|
|
372
|
-
|
|
373
374
|
if (_this2.useLtpa) {
|
|
374
375
|
xhrConfig.withCredentials = true;
|
|
375
376
|
} else {
|
|
376
377
|
xhrConfig.headers['Authorization'] = 'Basic ' + (0, _btoa["default"])(_this2.apiKey + ':' + _this2.apiToken);
|
|
377
378
|
}
|
|
378
|
-
|
|
379
379
|
if (body) {
|
|
380
380
|
xhrConfig.data = body;
|
|
381
|
-
|
|
382
381
|
if ((0, _util.isBrowser)()) {
|
|
383
382
|
xhrConfig.transformRequest = [function (data) {
|
|
384
383
|
var formData = new _formData["default"]();
|
|
385
|
-
|
|
386
384
|
if (xhrConfig.method == "POST") {
|
|
387
385
|
if (data.schemaFile) {
|
|
388
386
|
var blob = new Blob([data.schemaFile], {
|
|
@@ -391,15 +389,12 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
391
389
|
var schemaFileName = "".concat(data.name || 'schema', ".json");
|
|
392
390
|
formData.append('schemaFile', blob, schemaFileName);
|
|
393
391
|
}
|
|
394
|
-
|
|
395
392
|
if (data.name) {
|
|
396
393
|
formData.append('name', data.name);
|
|
397
394
|
}
|
|
398
|
-
|
|
399
395
|
if (data.schemaType) {
|
|
400
396
|
formData.append('schemaType', 'json-schema');
|
|
401
397
|
}
|
|
402
|
-
|
|
403
398
|
if (data.description) {
|
|
404
399
|
formData.append('description', data.description);
|
|
405
400
|
}
|
|
@@ -413,20 +408,16 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
413
408
|
formData.append('schemaFile', blob, schemaFileName);
|
|
414
409
|
}
|
|
415
410
|
}
|
|
416
|
-
|
|
417
411
|
return formData;
|
|
418
412
|
}];
|
|
419
413
|
}
|
|
420
414
|
}
|
|
421
|
-
|
|
422
415
|
if (params) {
|
|
423
416
|
xhrConfig.params = params;
|
|
424
417
|
}
|
|
425
|
-
|
|
426
418
|
if (_this2.config.getAdditionalHeaders()) {
|
|
427
419
|
xhrConfig.headers = _objectSpread(_objectSpread({}, xhrConfig.headers), _this2.config.getAdditionalHeaders());
|
|
428
420
|
}
|
|
429
|
-
|
|
430
421
|
function transformResponse(response) {
|
|
431
422
|
if (response.status === expectedHttpCode) {
|
|
432
423
|
if (expectJsonContent && !(_typeof(response.data) === 'object')) {
|
|
@@ -442,9 +433,7 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
442
433
|
reject(new Error(method + " " + uri + ": Expected HTTP " + expectedHttpCode + " from server but got HTTP " + response.status + ". Error Body: " + JSON.stringify(response.data)));
|
|
443
434
|
}
|
|
444
435
|
}
|
|
445
|
-
|
|
446
436
|
_this2.log.debug("[ApiClient:transformResponse] " + xhrConfig);
|
|
447
|
-
|
|
448
437
|
if ((0, _util.isBrowser)()) {
|
|
449
438
|
(0, _axios["default"])(xhrConfig).then(transformResponse, reject);
|
|
450
439
|
} else {
|
|
@@ -462,7 +451,6 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
462
451
|
formData: {},
|
|
463
452
|
rejectUnauthorized: false
|
|
464
453
|
};
|
|
465
|
-
|
|
466
454
|
if (xhrConfig.method == "POST") {
|
|
467
455
|
formData = {
|
|
468
456
|
'schemaFile': {
|
|
@@ -488,7 +476,6 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
488
476
|
};
|
|
489
477
|
config.formData = formData;
|
|
490
478
|
}
|
|
491
|
-
|
|
492
479
|
request(config, function optionalCallback(err, response, body) {
|
|
493
480
|
if (response.statusCode === expectedHttpCode) {
|
|
494
481
|
if (expectJsonContent && !(_typeof(response.data) === 'object')) {
|
|
@@ -515,8 +502,5 @@ var ApiClient = /*#__PURE__*/function () {
|
|
|
515
502
|
});
|
|
516
503
|
}
|
|
517
504
|
}]);
|
|
518
|
-
|
|
519
505
|
return ApiClient;
|
|
520
|
-
}();
|
|
521
|
-
|
|
522
|
-
exports["default"] = ApiClient;
|
|
506
|
+
}();
|
package/dist/api/ApiErrors.js
CHANGED
|
@@ -1,104 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
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); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports["default"] = exports.
|
|
7
|
-
|
|
8
|
-
function
|
|
9
|
-
|
|
7
|
+
exports.handleError = exports["default"] = exports.WiotpError = exports.ServiceNotFound = exports.InvalidServiceCredentials = exports.DestinationAlreadyExists = void 0;
|
|
8
|
+
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
11
|
+
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); }
|
|
10
12
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
15
|
-
|
|
16
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
17
|
-
|
|
13
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
14
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
18
15
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
19
|
-
|
|
16
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
20
17
|
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
21
|
-
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
29
|
-
|
|
30
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
31
|
-
|
|
32
|
-
var WiotpError = /*#__PURE__*/function (_Error) {
|
|
18
|
+
function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
|
|
19
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
20
|
+
function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } }
|
|
21
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
22
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
23
|
+
var WiotpError = exports.WiotpError = /*#__PURE__*/function (_Error) {
|
|
33
24
|
_inherits(WiotpError, _Error);
|
|
34
|
-
|
|
35
|
-
var _super = _createSuper(WiotpError);
|
|
36
|
-
|
|
37
25
|
function WiotpError(message, cause) {
|
|
38
26
|
var _this;
|
|
39
|
-
|
|
40
27
|
_classCallCheck(this, WiotpError);
|
|
41
|
-
|
|
42
|
-
_this = _super.call(this, message);
|
|
28
|
+
_this = _callSuper(this, WiotpError, [message]);
|
|
43
29
|
_this.cause = cause;
|
|
44
30
|
_this.name = _this.constructor.name;
|
|
45
31
|
return _this;
|
|
46
32
|
}
|
|
47
|
-
|
|
48
|
-
return WiotpError;
|
|
33
|
+
return _createClass(WiotpError);
|
|
49
34
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
50
|
-
|
|
51
|
-
exports.WiotpError = WiotpError;
|
|
52
|
-
|
|
53
|
-
var InvalidServiceCredentials = /*#__PURE__*/function (_WiotpError) {
|
|
35
|
+
var InvalidServiceCredentials = exports.InvalidServiceCredentials = /*#__PURE__*/function (_WiotpError) {
|
|
54
36
|
_inherits(InvalidServiceCredentials, _WiotpError);
|
|
55
|
-
|
|
56
|
-
var _super2 = _createSuper(InvalidServiceCredentials);
|
|
57
|
-
|
|
58
37
|
function InvalidServiceCredentials() {
|
|
59
38
|
_classCallCheck(this, InvalidServiceCredentials);
|
|
60
|
-
|
|
61
|
-
return _super2.apply(this, arguments);
|
|
39
|
+
return _callSuper(this, InvalidServiceCredentials, arguments);
|
|
62
40
|
}
|
|
63
|
-
|
|
64
|
-
return InvalidServiceCredentials;
|
|
41
|
+
return _createClass(InvalidServiceCredentials);
|
|
65
42
|
}(WiotpError);
|
|
66
|
-
|
|
67
|
-
exports.InvalidServiceCredentials = InvalidServiceCredentials;
|
|
68
|
-
|
|
69
|
-
var DestinationAlreadyExists = /*#__PURE__*/function (_WiotpError2) {
|
|
43
|
+
var DestinationAlreadyExists = exports.DestinationAlreadyExists = /*#__PURE__*/function (_WiotpError2) {
|
|
70
44
|
_inherits(DestinationAlreadyExists, _WiotpError2);
|
|
71
|
-
|
|
72
|
-
var _super3 = _createSuper(DestinationAlreadyExists);
|
|
73
|
-
|
|
74
45
|
function DestinationAlreadyExists() {
|
|
75
46
|
_classCallCheck(this, DestinationAlreadyExists);
|
|
76
|
-
|
|
77
|
-
return _super3.apply(this, arguments);
|
|
47
|
+
return _callSuper(this, DestinationAlreadyExists, arguments);
|
|
78
48
|
}
|
|
79
|
-
|
|
80
|
-
return DestinationAlreadyExists;
|
|
49
|
+
return _createClass(DestinationAlreadyExists);
|
|
81
50
|
}(WiotpError);
|
|
82
|
-
|
|
83
|
-
exports.DestinationAlreadyExists = DestinationAlreadyExists;
|
|
84
|
-
|
|
85
|
-
var ServiceNotFound = /*#__PURE__*/function (_WiotpError3) {
|
|
51
|
+
var ServiceNotFound = exports.ServiceNotFound = /*#__PURE__*/function (_WiotpError3) {
|
|
86
52
|
_inherits(ServiceNotFound, _WiotpError3);
|
|
87
|
-
|
|
88
|
-
var _super4 = _createSuper(ServiceNotFound);
|
|
89
|
-
|
|
90
53
|
function ServiceNotFound() {
|
|
91
54
|
_classCallCheck(this, ServiceNotFound);
|
|
92
|
-
|
|
93
|
-
return _super4.apply(this, arguments);
|
|
55
|
+
return _callSuper(this, ServiceNotFound, arguments);
|
|
94
56
|
}
|
|
95
|
-
|
|
96
|
-
return ServiceNotFound;
|
|
57
|
+
return _createClass(ServiceNotFound);
|
|
97
58
|
}(WiotpError);
|
|
98
|
-
|
|
99
|
-
exports.ServiceNotFound = ServiceNotFound;
|
|
100
|
-
|
|
101
|
-
var handleError = function handleError(err, errorMappings) {
|
|
59
|
+
var handleError = exports.handleError = function handleError(err, errorMappings) {
|
|
102
60
|
if (err && err.response && err.response.data && err.response.data.exception && err.response.data.exception.id) {
|
|
103
61
|
if (errorMappings && errorMappings[err.response.data.exception.id]) {
|
|
104
62
|
throw new errorMappings[err.response.data.exception.id](err.response.data.message, err);
|
|
@@ -109,12 +67,9 @@ var handleError = function handleError(err, errorMappings) {
|
|
|
109
67
|
throw err;
|
|
110
68
|
}
|
|
111
69
|
};
|
|
112
|
-
|
|
113
|
-
exports.handleError = handleError;
|
|
114
|
-
var _default = {
|
|
70
|
+
var _default = exports["default"] = {
|
|
115
71
|
WiotpError: WiotpError,
|
|
116
72
|
InvalidServiceCredentials: InvalidServiceCredentials,
|
|
117
73
|
DestinationAlreadyExists: DestinationAlreadyExists,
|
|
118
74
|
ServiceNotFound: ServiceNotFound
|
|
119
|
-
};
|
|
120
|
-
exports["default"] = _default;
|
|
75
|
+
};
|