@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,505 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _axios = _interopRequireDefault(require("axios"));
8
- var _bluebird = _interopRequireDefault(require("bluebird"));
9
- var _btoa = _interopRequireDefault(require("btoa"));
10
- var _formData = _interopRequireDefault(require("form-data"));
11
- var _loglevel = _interopRequireDefault(require("loglevel"));
12
- var _util = require("../util");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
18
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
19
- 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); } }
20
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
21
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : 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 () {
33
- function ApiClient(config) {
34
- _classCallCheck(this, ApiClient);
35
- this.log = _loglevel["default"];
36
- this.log.setDefaultLevel(config.options.logLevel);
37
- this.config = config;
38
- this.useLtpa = this.config.auth && this.config.auth.useLtpa;
39
- this.log.debug("[ApiClient:constructor] ApiClient initialized for " + this.config.getApiBaseUri());
40
- }
41
-
42
- // e.g. [{name: true}, {description: false}] => -name,description
43
- return _createClass(ApiClient, [{
44
- key: "parseSortSpec",
45
- value: function parseSortSpec(sortSpec) {
46
- return sortSpec ? sortSpec.map(function (s) {
47
- var e = Object.entries(s)[0];
48
- return "".concat(e[1] ? '-' : '').concat(e[0]);
49
- }).join(',') : undefined;
50
- }
51
- }, {
52
- key: "callApi",
53
- value: function callApi(method, expectedHttpCode, expectJsonContent, paths, body, params) {
54
- var _this = this;
55
- return new _bluebird["default"](function (resolve, reject) {
56
- var uri = _this.config.getApiBaseUri();
57
- if (Array.isArray(paths)) {
58
- for (var i = 0, l = paths.length; i < l; i++) {
59
- uri += '/' + paths[i];
60
- }
61
- }
62
- var xhrConfig = {
63
- url: uri,
64
- method: method,
65
- headers: {
66
- 'Content-Type': 'application/json'
67
- },
68
- validateStatus: function validateStatus(status) {
69
- if (Array.isArray(expectedHttpCode)) {
70
- return expectedHttpCode.includes(status);
71
- } else {
72
- return status === expectedHttpCode;
73
- }
74
- }
75
- };
76
- if (_this.useLtpa) {
77
- xhrConfig.withCredentials = true;
78
- } else {
79
- xhrConfig.headers['Authorization'] = 'Basic ' + (0, _btoa["default"])(_this.config.auth.key + ':' + _this.config.auth.token);
80
- }
81
- if (body) {
82
- xhrConfig.data = body;
83
- }
84
- if (params) {
85
- xhrConfig.params = params;
86
- }
87
- if (_this.config.getAdditionalHeaders()) {
88
- xhrConfig.headers = _objectSpread(_objectSpread({}, xhrConfig.headers), _this.config.getAdditionalHeaders());
89
- }
90
- function transformResponse(response) {
91
- if (expectJsonContent && !(_typeof(response.data) === 'object')) {
92
- try {
93
- resolve(JSON.parse(response.data));
94
- } catch (e) {
95
- reject(e);
96
- }
97
- } else {
98
- resolve(response.data);
99
- }
100
- }
101
- _this.log.debug("[ApiClient:transformResponse] " + xhrConfig);
102
- (0, _axios["default"])(xhrConfig).then(transformResponse, reject);
103
- });
104
- }
105
- }, {
106
- key: "getOrganizationDetails",
107
- value: function getOrganizationDetails() {
108
- this.log.debug("[ApiClient] getOrganizationDetails()");
109
- return this.callApi('GET', 200, true, null, null);
110
- }
111
- }, {
112
- key: "getServiceStatus",
113
- value: function getServiceStatus() {
114
- this.log.debug("[ApiClient] getServiceStatus()");
115
- return this.callApi('GET', 200, true, ['service-status'], null);
116
- }
117
-
118
- //Usage Management
119
- }, {
120
- key: "getActiveDevices",
121
- value: function getActiveDevices(start, end, detail) {
122
- this.log.debug("[ApiClient] getActiveDevices(" + start + ", " + end + ")");
123
- detail = detail | false;
124
- var params = {
125
- start: start,
126
- end: end,
127
- detail: detail
128
- };
129
- return this.callApi('GET', 200, true, ['usage', 'active-devices'], null, params);
130
- }
131
- }, {
132
- key: "getHistoricalDataUsage",
133
- value: function getHistoricalDataUsage(start, end, detail) {
134
- this.log.debug("[ApiClient] getHistoricalDataUsage(" + start + ", " + end + ")");
135
- detail = detail | false;
136
- var params = {
137
- start: start,
138
- end: end,
139
- detail: detail
140
- };
141
- return this.callApi('GET', 200, true, ['usage', 'historical-data'], null, params);
142
- }
143
- }, {
144
- key: "getDataUsage",
145
- value: function getDataUsage(start, end, detail) {
146
- this.log.debug("[ApiClient] getDataUsage(" + start + ", " + end + ")");
147
- detail = detail | false;
148
- var params = {
149
- start: start,
150
- end: end,
151
- detail: detail
152
- };
153
- return this.callApi('GET', 200, true, ['usage', 'data-traffic'], null, params);
154
- }
155
-
156
- //client connectivity status
157
- }, {
158
- key: "getConnectionStates",
159
- value: function getConnectionStates() {
160
- this.log.debug("[ApiClient] getConnectionStates() - client connectivity");
161
- return this.callApi('GET', 200, true, ["clientconnectionstates"], null);
162
- }
163
- }, {
164
- key: "getConnectionState",
165
- value: function getConnectionState(id) {
166
- this.log.debug("[ApiClient] getConnectionState() - client connectivity");
167
- return this.callApi('GET', 200, true, ["clientconnectionstates/" + id], null);
168
- }
169
- }, {
170
- key: "getConnectedClientsConnectionStates",
171
- value: function getConnectedClientsConnectionStates() {
172
- this.log.debug("[ApiClient] getConnectedClientsConnectionStates() - client connectivity");
173
- return this.callApi('GET', 200, true, ["clientconnectionstates?connectionStatus=connected"], null);
174
- }
175
- }, {
176
- key: "getRecentConnectionStates",
177
- value: function getRecentConnectionStates(date) {
178
- this.log.debug("[ApiClient] getRecentConnectionStates() - client connectivity");
179
- return this.callApi('GET', 200, true, ["clientconnectionstates?connectedAfter=" + date], null);
180
- }
181
- }, {
182
- key: "getCustomConnectionState",
183
- value: function getCustomConnectionState(query) {
184
- this.log.debug("[ApiClient] getCustomConnectionStates() - client connectivity");
185
- return this.callApi('GET', 200, true, ["clientconnectionstates" + query], null);
186
- }
187
-
188
- //bulk apis
189
- }, {
190
- key: "getAllDevices",
191
- value: function getAllDevices(params) {
192
- this.log.debug("[ApiClient] getAllDevices() - BULK");
193
- return this.callApi('GET', 200, true, ["bulk", "devices"], null, params);
194
- }
195
-
196
- /**
197
- * Gateway Access Control (Beta)
198
- * The methods in this section follow the documentation listed under the link:
199
- * https://console.ng.bluemix.net/docs/services/IoT/gateways/gateway-access-control.html#gateway-access-control-beta-
200
- * Involves the following sections from the above mentioned link:
201
- * Assigning a role to a gateway
202
- * Adding devices to and removing devices from a resource group
203
- * Finding a resource group
204
- * Querying a resource group
205
- * Creating and deleting a resource group
206
- * Updating group properties
207
- * Retrieving and updating device properties
208
- *
209
- */
210
-
211
- //getGatewayGroup(gatewayId)
212
- //updateDeviceRoles(deviceId, roles[])
213
- //getAllDevicesInGropu(groupId)
214
- //addDevicesToGroup(groupId, deviceList[])
215
- //removeDevicesFromGroup(groupId, deviceList[])
216
- }, {
217
- key: "getGroupIdsForDevice",
218
- value: function getGroupIdsForDevice(deviceId) {
219
- this.log.debug("[ApiClient] getGroupIdsForDevice(" + deviceId + ")");
220
- return this.callApi('GET', 200, true, ['authorization', 'devices', deviceId], null);
221
- }
222
- }, {
223
- key: "updateDeviceRoles",
224
- value: function updateDeviceRoles(deviceId, roles) {
225
- this.log.debug("[ApiClient] updateDeviceRoles(" + deviceId + "," + roles + ")");
226
- return this.callApi('PUT', 200, false, ['authorization', 'devices', deviceId, 'roles'], roles);
227
- }
228
- }, {
229
- key: "getAllDevicesInGroup",
230
- value: function getAllDevicesInGroup(groupId) {
231
- this.log.debug("[ApiClient] getAllDevicesInGropu(" + groupId + ")");
232
- return this.callApi('GET', 200, true, ['bulk', 'devices', groupId], null);
233
- }
234
- }, {
235
- key: "addDevicesToGroup",
236
- value: function addDevicesToGroup(groupId, deviceList) {
237
- this.log.debug("[ApiClient] addDevicesToGroup(" + groupId + "," + deviceList + ")");
238
- return this.callApi('PUT', 200, false, ['bulk', 'devices', groupId, "add"], deviceList);
239
- }
240
- }, {
241
- key: "removeDevicesFromGroup",
242
- value: function removeDevicesFromGroup(groupId, deviceList) {
243
- this.log.debug("[ApiClient] removeDevicesFromGroup(" + groupId + "," + deviceList + ")");
244
- return this.callApi('PUT', 200, false, ['bulk', 'devices', groupId, "remove"], deviceList);
245
- }
246
-
247
- // https://console.ng.bluemix.net/docs/services/IoT/gateways/gateway-access-control.html
248
-
249
- // Finding a Resource Group
250
- // getGatewayGroups()
251
- // Querying a resource group
252
- // getUniqueDevicesInGroup(groupId)
253
- // getUniqueGatewayGroup(groupId)
254
- // Creating and deleting a resource group
255
- // createGatewayGroup(groupName)
256
- // deleteGatewayGroup(groupId)
257
- // Retrieving and updating device properties
258
- // getGatewayGroupProperties()
259
- // getDeviceRoles(deviceId)
260
- // updateGatewayProperties(gatewayId,control_props)
261
- // updateDeviceControlProperties(deviceId, withroles)
262
-
263
- // Finding a Resource Group
264
- }, {
265
- key: "getAllGroups",
266
- value: function getAllGroups() {
267
- this.log.debug("[ApiClient] getAllGroups()");
268
- return this.callApi('GET', 200, true, ['groups'], null);
269
- }
270
-
271
- // Querying a resource group
272
-
273
- // Get unique identifiers of the members of the resource group
274
- }, {
275
- key: "getAllDeviceIdsInGroup",
276
- value: function getAllDeviceIdsInGroup(groupId) {
277
- this.log.debug("[ApiClient] getAllDeviceIdsInGroup(" + groupId + ")");
278
- return this.callApi('GET', 200, true, ['bulk', 'devices', groupId, "ids"], null);
279
- }
280
-
281
- // properties of the resource group
282
- }, {
283
- key: "getGroup",
284
- value: function getGroup(groupId) {
285
- this.log.debug("[ApiClient] getGroup(" + groupId + ")");
286
- return this.callApi('GET', 200, true, ['groups', groupId], null);
287
- }
288
-
289
- // Creating and deleting a resource group
290
-
291
- // Create a Resource Group
292
- }, {
293
- key: "createGroup",
294
- value: function createGroup(groupInfo) {
295
- this.log.debug("[ApiClient] createGroup()");
296
- return this.callApi('POST', 201, true, ['groups'], groupInfo);
297
- }
298
-
299
- // Delete a Resource Group
300
- }, {
301
- key: "deleteGroup",
302
- value: function deleteGroup(groupId) {
303
- this.log.debug("[ApiClient] deleteGroup(" + groupId + ")");
304
- return this.callApi('DELETE', 200, false, ['groups', groupId], null);
305
- }
306
-
307
- // Retrieving and updating device properties
308
-
309
- // Get the ID of the devices group of a gateway
310
- }, {
311
- key: "getAllDeviceAccessControlProperties",
312
- value: function getAllDeviceAccessControlProperties() {
313
- this.log.debug("[ApiClient] getAllDeviceAccessControlProperties()");
314
- return this.callApi('GET', 200, true, ['authorization', 'devices'], null);
315
- }
316
-
317
- // Get standard role of a gateway
318
- }, {
319
- key: "getDeviceAccessControlProperties",
320
- value: function getDeviceAccessControlProperties(deviceId) {
321
- this.log.debug("[ApiClient] getDeviceAccessControlProperties(" + deviceId + ")");
322
- return this.callApi('GET', 200, true, ['authorization', 'devices', deviceId, 'roles'], null);
323
- }
324
-
325
- // Update device properties without affecting the access control properties
326
- }, {
327
- key: "updateDeviceAccessControlProperties",
328
- value: function updateDeviceAccessControlProperties(deviceId, deviceProps) {
329
- this.log.debug("[ApiClient] updateDeviceAccessControlProperties(" + deviceId + ")");
330
- return this.callApi('PUT', 200, true, ['authorization', 'devices', deviceId], deviceProps);
331
- }
332
-
333
- // Assign a standard role to a gateway
334
- }, {
335
- key: "updateDeviceAccessControlPropertiesWithRoles",
336
- value: function updateDeviceAccessControlPropertiesWithRoles(deviceId, devicePropsWithRoles) {
337
- this.log.debug("[ApiClient] updateDeviceAccessControlPropertiesWithRoles(" + deviceId + "," + devicePropsWithRoles + ")");
338
- return this.callApi('PUT', 200, true, ['authorization', 'devices', deviceId, 'withroles'], devicePropsWithRoles);
339
- }
340
-
341
- // Duplicating updateDeviceRoles(deviceId, roles) for Gateway Roles
342
- }, {
343
- key: "updateGatewayRoles",
344
- value: function updateGatewayRoles(gatewayId, roles) {
345
- this.log.debug("[ApiClient] updateGatewayRoles(" + gatewayId + "," + roles + ")");
346
- return this.callApi('PUT', 200, false, ['authorization', 'devices', gatewayId, 'roles'], roles);
347
- }
348
-
349
- // Extending getAllGroups() to fetch individual Groups
350
- }, {
351
- key: "getGroups",
352
- value: function getGroups(groupId) {
353
- this.log.debug("[ApiClient] getGroups(" + groupId + ")");
354
- return this.callApi('GET', 200, true, ['groups', groupId], null);
355
- }
356
- }, {
357
- key: "callFormDataApi",
358
- value: function callFormDataApi(method, expectedHttpCode, expectJsonContent, paths, body, params) {
359
- var _this2 = this;
360
- return new _bluebird["default"](function (resolve, reject) {
361
- var uri = _this2.config.getApiBaseUri();
362
- if (Array.isArray(paths)) {
363
- for (var i = 0, l = paths.length; i < l; i++) {
364
- uri += '/' + paths[i];
365
- }
366
- }
367
- var xhrConfig = {
368
- url: uri,
369
- method: method,
370
- headers: {
371
- 'Content-Type': 'multipart/form-data'
372
- }
373
- };
374
- if (_this2.useLtpa) {
375
- xhrConfig.withCredentials = true;
376
- } else {
377
- xhrConfig.headers['Authorization'] = 'Basic ' + (0, _btoa["default"])(_this2.apiKey + ':' + _this2.apiToken);
378
- }
379
- if (body) {
380
- xhrConfig.data = body;
381
- if ((0, _util.isBrowser)()) {
382
- xhrConfig.transformRequest = [function (data) {
383
- var formData = new _formData["default"]();
384
- if (xhrConfig.method == "POST") {
385
- if (data.schemaFile) {
386
- var blob = new Blob([data.schemaFile], {
387
- type: "application/json"
388
- });
389
- var schemaFileName = "".concat(data.name || 'schema', ".json");
390
- formData.append('schemaFile', blob, schemaFileName);
391
- }
392
- if (data.name) {
393
- formData.append('name', data.name);
394
- }
395
- if (data.schemaType) {
396
- formData.append('schemaType', 'json-schema');
397
- }
398
- if (data.description) {
399
- formData.append('description', data.description);
400
- }
401
- } else if (xhrConfig.method == "PUT") {
402
- if (data.schemaFile) {
403
- var blob = new Blob([data.schemaFile], {
404
- type: "application/json",
405
- name: data.name
406
- });
407
- var schemaFileName = "".concat(data.name || 'schema', ".json");
408
- formData.append('schemaFile', blob, schemaFileName);
409
- }
410
- }
411
- return formData;
412
- }];
413
- }
414
- }
415
- if (params) {
416
- xhrConfig.params = params;
417
- }
418
- if (_this2.config.getAdditionalHeaders()) {
419
- xhrConfig.headers = _objectSpread(_objectSpread({}, xhrConfig.headers), _this2.config.getAdditionalHeaders());
420
- }
421
- function transformResponse(response) {
422
- if (response.status === expectedHttpCode) {
423
- if (expectJsonContent && !(_typeof(response.data) === 'object')) {
424
- try {
425
- resolve(JSON.parse(response.data));
426
- } catch (e) {
427
- reject(e);
428
- }
429
- } else {
430
- resolve(response.data);
431
- }
432
- } else {
433
- reject(new Error(method + " " + uri + ": Expected HTTP " + expectedHttpCode + " from server but got HTTP " + response.status + ". Error Body: " + JSON.stringify(response.data)));
434
- }
435
- }
436
- _this2.log.debug("[ApiClient:transformResponse] " + xhrConfig);
437
- if ((0, _util.isBrowser)()) {
438
- (0, _axios["default"])(xhrConfig).then(transformResponse, reject);
439
- } else {
440
- var formData = null;
441
- var config = {
442
- url: uri,
443
- method: method,
444
- headers: {
445
- 'Content-Type': 'multipart/form-data'
446
- },
447
- auth: {
448
- user: _this2.apiKey,
449
- pass: _this2.apiToken
450
- },
451
- formData: {},
452
- rejectUnauthorized: false
453
- };
454
- if (xhrConfig.method == "POST") {
455
- formData = {
456
- 'schemaFile': {
457
- 'value': body.schemaFile,
458
- 'options': {
459
- 'contentType': 'application/json',
460
- 'filename': body.name
461
- }
462
- },
463
- 'schemaType': 'json-schema',
464
- 'name': body.name
465
- };
466
- config.formData = formData;
467
- } else if (xhrConfig.method == "PUT") {
468
- formData = {
469
- 'schemaFile': {
470
- 'value': body.schemaFile,
471
- 'options': {
472
- 'contentType': 'application/json',
473
- 'filename': body.name
474
- }
475
- }
476
- };
477
- config.formData = formData;
478
- }
479
- request(config, function optionalCallback(err, response, body) {
480
- if (response.statusCode === expectedHttpCode) {
481
- if (expectJsonContent && !(_typeof(response.data) === 'object')) {
482
- try {
483
- resolve(JSON.parse(body));
484
- } catch (e) {
485
- reject(e);
486
- }
487
- } else {
488
- resolve(body);
489
- }
490
- } else {
491
- reject(new Error(method + " " + uri + ": Expected HTTP " + expectedHttpCode + " from server but got HTTP " + response.statusCode + ". Error Body: " + err));
492
- }
493
- });
494
- }
495
- });
496
- }
497
- }, {
498
- key: "invalidOperation",
499
- value: function invalidOperation(message) {
500
- return new _bluebird["default"](function (resolve, reject) {
501
- resolve(message);
502
- });
503
- }
504
- }]);
505
- }();
@@ -1,75 +0,0 @@
1
- "use strict";
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); }
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.handleError = exports["default"] = exports.WiotpError = exports.ServiceNotFound = exports.InvalidServiceCredentials = exports.DestinationAlreadyExists = void 0;
8
- 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); } }
9
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
10
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : 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); }
12
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
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(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
15
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
16
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
17
- function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
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(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
21
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
22
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
23
- var WiotpError = exports.WiotpError = /*#__PURE__*/function (_Error) {
24
- function WiotpError(message, cause) {
25
- var _this;
26
- _classCallCheck(this, WiotpError);
27
- _this = _callSuper(this, WiotpError, [message]);
28
- _this.cause = cause;
29
- _this.name = _this.constructor.name;
30
- return _this;
31
- }
32
- _inherits(WiotpError, _Error);
33
- return _createClass(WiotpError);
34
- }(/*#__PURE__*/_wrapNativeSuper(Error));
35
- var InvalidServiceCredentials = exports.InvalidServiceCredentials = /*#__PURE__*/function (_WiotpError) {
36
- function InvalidServiceCredentials() {
37
- _classCallCheck(this, InvalidServiceCredentials);
38
- return _callSuper(this, InvalidServiceCredentials, arguments);
39
- }
40
- _inherits(InvalidServiceCredentials, _WiotpError);
41
- return _createClass(InvalidServiceCredentials);
42
- }(WiotpError);
43
- var DestinationAlreadyExists = exports.DestinationAlreadyExists = /*#__PURE__*/function (_WiotpError2) {
44
- function DestinationAlreadyExists() {
45
- _classCallCheck(this, DestinationAlreadyExists);
46
- return _callSuper(this, DestinationAlreadyExists, arguments);
47
- }
48
- _inherits(DestinationAlreadyExists, _WiotpError2);
49
- return _createClass(DestinationAlreadyExists);
50
- }(WiotpError);
51
- var ServiceNotFound = exports.ServiceNotFound = /*#__PURE__*/function (_WiotpError3) {
52
- function ServiceNotFound() {
53
- _classCallCheck(this, ServiceNotFound);
54
- return _callSuper(this, ServiceNotFound, arguments);
55
- }
56
- _inherits(ServiceNotFound, _WiotpError3);
57
- return _createClass(ServiceNotFound);
58
- }(WiotpError);
59
- var handleError = exports.handleError = function handleError(err, errorMappings) {
60
- if (err && err.response && err.response.data && err.response.data.exception && err.response.data.exception.id) {
61
- if (errorMappings && errorMappings[err.response.data.exception.id]) {
62
- throw new errorMappings[err.response.data.exception.id](err.response.data.message, err);
63
- } else {
64
- throw new WiotpError(err.response.data.message, err);
65
- }
66
- } else {
67
- throw err;
68
- }
69
- };
70
- var _default = exports["default"] = {
71
- WiotpError: WiotpError,
72
- InvalidServiceCredentials: InvalidServiceCredentials,
73
- DestinationAlreadyExists: DestinationAlreadyExists,
74
- ServiceNotFound: ServiceNotFound
75
- };