@wiotp/sdk 0.7.8 → 0.8.0

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.
@@ -4,31 +4,36 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  var _loglevel = _interopRequireDefault(require("loglevel"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
-
9
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
12
10
  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 StateClient = /*#__PURE__*/function () {
11
+ 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); } }
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
14
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
15
+ *****************************************************************************
16
+ Copyright (c) 2014, 2019 IBM Corporation and other Contributors.
17
+ All rights reserved. This program and the accompanying materials
18
+ are made available under the terms of the Eclipse Public License v1.0
19
+ which accompanies this distribution, and is available at
20
+ http://www.eclipse.org/legal/epl-v10.html
21
+ *****************************************************************************
22
+ *
23
+ */
24
+ var StateClient = exports["default"] = /*#__PURE__*/function () {
19
25
  function StateClient(apiClient) {
20
26
  _classCallCheck(this, StateClient);
21
-
22
27
  this.log = _loglevel["default"];
23
28
  this.apiClient = apiClient;
24
- this.draftMode = true; // Create an alias to the apiClient's methods that we use
29
+ this.draftMode = true;
25
30
 
31
+ // Create an alias to the apiClient's methods that we use
26
32
  this.callApi = this.apiClient.callApi.bind(this.apiClient);
27
33
  this.parseSortSpec = this.apiClient.parseSortSpec.bind(this.apiClient);
28
34
  this.callFormDataApi = this.apiClient.callFormDataApi.bind(this.apiClient);
29
35
  this.invalidOperation = this.apiClient.invalidOperation.bind(this.apiClient);
30
36
  }
31
-
32
37
  _createClass(StateClient, [{
33
38
  key: "workWithActive",
34
39
  value: function workWithActive() {
@@ -38,8 +43,9 @@ var StateClient = /*#__PURE__*/function () {
38
43
  key: "workWithDraft",
39
44
  value: function workWithDraft() {
40
45
  this.draftMode = true;
41
- } // IM Device state API
46
+ }
42
47
 
48
+ // IM Device state API
43
49
  }, {
44
50
  key: "createSchema",
45
51
  value: function createSchema(schemaContents, name, description) {
@@ -48,11 +54,9 @@ var StateClient = /*#__PURE__*/function () {
48
54
  'schemaType': 'json-schema',
49
55
  'name': name
50
56
  };
51
-
52
57
  if (description) {
53
58
  body.description = description;
54
59
  }
55
-
56
60
  var base = this.draftMode ? ["draft", "schemas"] : ["schemas"];
57
61
  return this.callFormDataApi('POST', 201, true, base, body, null);
58
62
  }
@@ -251,11 +255,9 @@ var StateClient = /*#__PURE__*/function () {
251
255
  'description': description,
252
256
  'schemaId': schemaId
253
257
  };
254
-
255
258
  if (alias !== undefined) {
256
259
  body.alias = alias;
257
260
  }
258
-
259
261
  var base = this.draftMode ? ["draft", "logicalinterfaces"] : ["applicationinterfaces"];
260
262
  return this.callApi('POST', 201, true, base, body);
261
263
  }
@@ -285,11 +287,9 @@ var StateClient = /*#__PURE__*/function () {
285
287
  "description": description,
286
288
  "schemaId": schemaId
287
289
  };
288
-
289
290
  if (alias !== undefined) {
290
291
  body.alias = alias;
291
292
  }
292
-
293
293
  var base = this.draftMode ? ["draft", "logicalinterfaces", logicalInterfaceId] : ["applicationinterfaces", logicalInterfaceId];
294
294
  return this.callApi('PUT', 200, true, base, body);
295
295
  }
@@ -297,9 +297,7 @@ var StateClient = /*#__PURE__*/function () {
297
297
  key: "getLogicalInterfaces",
298
298
  value: function getLogicalInterfaces(bookmark, limit, sort, name) {
299
299
  var base = this.draftMode ? ["draft", "logicalinterfaces"] : ["logicalinterfaces"];
300
-
301
300
  var _sort = this.parseSortSpec(sort);
302
-
303
301
  return this.callApi('GET', 200, true, base, undefined, {
304
302
  _bookmark: bookmark,
305
303
  _limit: limit,
@@ -311,86 +309,108 @@ var StateClient = /*#__PURE__*/function () {
311
309
  key: "getActiveLogicalInterfaces",
312
310
  value: function getActiveLogicalInterfaces() {
313
311
  return this.callApi('GET', 200, true, ["logicalinterfaces"]);
314
- } // Application interface patch operation on draft version
315
- // Acceptable operation id - validate-configuration, activate-configuration, list-differences
312
+ }
316
313
 
314
+ // Application interface patch operation on draft version
315
+ // Acceptable operation id - validate-configuration, activate-configuration, list-differences
317
316
  }, {
318
317
  key: "patchOperationLogicalInterface",
319
318
  value: function patchOperationLogicalInterface(logicalInterfaceId, operationId) {
320
319
  var body = {
321
320
  "operation": operationId
322
321
  };
323
-
324
322
  if (this.draftMode) {
325
323
  switch (operationId) {
326
324
  case 'validate-configuration':
327
325
  return this.callApi('PATCH', 200, true, ["draft", "logicalinterfaces", logicalInterfaceId], body);
328
-
329
326
  case 'activate-configuration':
330
327
  return this.callApi('PATCH', 202, true, ["draft", "logicalinterfaces", logicalInterfaceId], body);
331
-
332
328
  case 'deactivate-configuration':
333
329
  return this.callApi('PATCH', 202, true, ["draft", "logicalinterfaces", logicalInterfaceId], body);
334
-
335
330
  case 'list-differences':
336
331
  return this.callApi('PATCH', 200, true, ["draft", "logicalinterfaces", logicalInterfaceId], body);
337
-
338
332
  default:
339
333
  return this.callApi('PATCH', 200, true, ["draft", "logicalinterfaces", logicalInterfaceId], body);
340
334
  }
341
335
  } else {
342
336
  return this.invalidOperation("PATCH operation not allowed on active logical interface");
343
337
  }
344
- } // Application interface patch operation on active version
345
- // Acceptable operation id - deactivate-configuration
338
+ }
346
339
 
340
+ // Application interface patch operation on active version
341
+ // Acceptable operation id - deactivate-configuration
347
342
  }, {
348
343
  key: "patchOperationActiveLogicalInterface",
349
344
  value: function patchOperationActiveLogicalInterface(logicalInterfaceId, operationId) {
350
345
  var body = {
351
346
  "operation": operationId
352
347
  };
353
-
354
348
  if (this.draftMode) {
355
349
  return this.callApi('PATCH', 202, true, ["logicalinterfaces", logicalInterfaceId], body);
356
350
  } else {
357
351
  return this.invalidOperation("PATCH operation 'deactivate-configuration' not allowed on logical interface");
358
352
  }
359
- } // Application interface patch operation on draft version
360
- // Acceptable operation id - validate-configuration, activate-configuration, list-differences
353
+ }
361
354
 
355
+ // Application interface patch operation on draft version
356
+ // Acceptable operation id - validate-configuration, activate-configuration, list-differences
362
357
  }, {
363
358
  key: "patchOperationDeviceType",
364
- value: function patchOperationDeviceType(deviceTypeId, operationId) {
359
+ value:
360
+ // Device Type patch operation on draft version
361
+ // Acceptable operation id - validate-configuration, activate-configuration, list-differences
362
+ function patchOperationDeviceType(typeId, operationId) {
363
+ if (!operationId) {
364
+ return invalidOperation("PATCH operation is not allowed. Operation id is expected");
365
+ }
365
366
  var body = {
366
367
  "operation": operationId
367
368
  };
368
-
369
+ var base = this.draftMode ? ['draft', 'device', 'types', typeId] : ['device', 'types', typeId];
369
370
  if (this.draftMode) {
370
371
  switch (operationId) {
371
372
  case 'validate-configuration':
372
- return this.callApi('PATCH', 200, true, ["draft", "device", "types", deviceTypeId], body);
373
-
373
+ return this.callApi('PATCH', 200, true, base, body);
374
+ break;
374
375
  case 'activate-configuration':
375
- return this.callApi('PATCH', 202, true, ["draft", "device", "types", deviceTypeId], body);
376
-
376
+ return this.callApi('PATCH', 202, true, base, body);
377
+ break;
377
378
  case 'deactivate-configuration':
378
- return this.callApi('PATCH', 202, true, ["draft", "device", "types", deviceTypeId], body);
379
-
379
+ return this.callApi('PATCH', 202, true, base, body);
380
+ break;
380
381
  case 'list-differences':
381
- return this.callApi('PATCH', 200, true, ["draft", "device", "types", deviceTypeId], body);
382
-
382
+ return this.callApi('PATCH', 200, true, base, body);
383
+ break;
383
384
  default:
384
- return this.callApi('PATCH', 200, true, ["draft", "device", "types", deviceTypeId], body);
385
+ return this.invalidOperation("PATCH operation is not allowed. Invalid operation id");
385
386
  }
386
387
  } else {
387
- return this.invalidOperation("this method cannot be called when draftMode=false");
388
+ switch (operationId) {
389
+ case 'validate-configuration':
390
+ return this.callApi('PATCH', 200, true, base, body);
391
+ break;
392
+ case 'deploy-configuration':
393
+ return this.callApi('PATCH', 202, true, base, body);
394
+ break;
395
+ case 'remove-deployed-configuration':
396
+ return this.callApi('PATCH', 202, true, base, body);
397
+ break;
398
+ case 'list-differences':
399
+ return this.invalidOperation("PATCH operation 'list-differences' is not allowed");
400
+ break;
401
+ default:
402
+ return this.invalidOperation("PATCH operation is not allowed. Invalid operation id");
403
+ }
388
404
  }
389
- } // Create device type with physical Interface Id
405
+ }
390
406
 
407
+ // Device Type patch operation on active version
408
+ // Acceptable operation id - deactivate-configuration
391
409
  }, {
392
410
  key: "createDeviceType",
393
- value: function createDeviceType(typeId, description, deviceInfo, metadata, classId, physicalInterfaceId) {
411
+ value:
412
+ // Create device type with physical Interface Id
413
+ function createDeviceType(typeId, description, deviceInfo, metadata, classId, physicalInterfaceId) {
394
414
  this.log.debug("[ApiClient] registerDeviceType(" + typeId + ", " + description + ", " + deviceInfo + ", " + metadata + ", " + classId + ", " + physicalInterfaceId + ")");
395
415
  classId = classId || "Device";
396
416
  var body = {
@@ -408,7 +428,6 @@ var StateClient = /*#__PURE__*/function () {
408
428
  value: function getDeviceTypesByLogicalInterfaceId(logicalInterfaceId) {
409
429
  var bookmark = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
410
430
  var limit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
411
-
412
431
  if (this.draftMode) {
413
432
  return this.callApi('GET', 200, true, ['draft', 'device', 'types'], null, {
414
433
  logicalInterfaceId: logicalInterfaceId,
@@ -428,7 +447,6 @@ var StateClient = /*#__PURE__*/function () {
428
447
  var body = {
429
448
  id: physicalInterfaceId
430
449
  };
431
-
432
450
  if (this.draftMode) {
433
451
  return this.callApi('POST', 201, true, ['draft', 'device', 'types', typeId, 'physicalinterface'], JSON.stringify(body));
434
452
  } else {
@@ -484,19 +502,16 @@ var StateClient = /*#__PURE__*/function () {
484
502
  key: "createDeviceTypeLogicalInterfacePropertyMappings",
485
503
  value: function createDeviceTypeLogicalInterfacePropertyMappings(typeId, logicalInterfaceId, mappings, notificationStrategy) {
486
504
  var body = null,
487
- base = null;
488
-
505
+ base = null;
489
506
  if (this.draftMode) {
490
507
  body = {
491
508
  "logicalInterfaceId": logicalInterfaceId,
492
509
  "propertyMappings": mappings,
493
510
  "notificationStrategy": "never"
494
511
  };
495
-
496
512
  if (notificationStrategy) {
497
513
  body.notificationStrategy = notificationStrategy;
498
514
  }
499
-
500
515
  base = ['draft', 'device', 'types', typeId, 'mappings'];
501
516
  } else {
502
517
  body = {
@@ -505,7 +520,6 @@ var StateClient = /*#__PURE__*/function () {
505
520
  };
506
521
  base = ['device', 'types', typeId, 'mappings'];
507
522
  }
508
-
509
523
  return this.callApi('POST', 201, true, base, body);
510
524
  }
511
525
  }, {
@@ -534,19 +548,16 @@ var StateClient = /*#__PURE__*/function () {
534
548
  key: "updateDeviceTypeLogicalInterfacePropertyMappings",
535
549
  value: function updateDeviceTypeLogicalInterfacePropertyMappings(typeId, logicalInterfaceId, mappings, notificationStrategy) {
536
550
  var body = null,
537
- base = null;
538
-
551
+ base = null;
539
552
  if (this.draftMode) {
540
553
  body = {
541
554
  "logicalInterfaceId": logicalInterfaceId,
542
555
  "propertyMappings": mappings,
543
556
  "notificationStrategy": "never"
544
557
  };
545
-
546
558
  if (notificationStrategy) {
547
559
  body.notificationStrategy = notificationStrategy;
548
560
  }
549
-
550
561
  base = ['draft', 'device', 'types', typeId, 'mappings', logicalInterfaceId];
551
562
  } else {
552
563
  body = {
@@ -555,7 +566,6 @@ var StateClient = /*#__PURE__*/function () {
555
566
  };
556
567
  base = ['device', 'types', typeId, 'mappings', logicalInterfaceId];
557
568
  }
558
-
559
569
  return this.callApi('PUT', 200, false, base, body);
560
570
  }
561
571
  }, {
@@ -569,74 +579,13 @@ var StateClient = /*#__PURE__*/function () {
569
579
  value: function deleteDeviceTypeLogicalInterfaceAssociation(typeId, logicalInterfaceId) {
570
580
  var base = this.draftMode ? ['draft', 'device', 'types', typeId, 'logicalinterfaces', logicalInterfaceId] : ['device', 'types', typeId, 'applicationinterfaces', logicalInterfaceId];
571
581
  return this.callApi('DELETE', 204, false, base);
572
- } // Device Type patch operation on draft version
573
- // Acceptable operation id - validate-configuration, activate-configuration, list-differences
574
-
575
- }, {
576
- key: "patchOperationDeviceType",
577
- value: function patchOperationDeviceType(typeId, operationId) {
578
- if (!operationId) {
579
- return invalidOperation("PATCH operation is not allowed. Operation id is expected");
580
- }
581
-
582
- var body = {
583
- "operation": operationId
584
- };
585
- var base = this.draftMode ? ['draft', 'device', 'types', typeId] : ['device', 'types', typeId];
586
-
587
- if (this.draftMode) {
588
- switch (operationId) {
589
- case 'validate-configuration':
590
- return this.callApi('PATCH', 200, true, base, body);
591
- break;
592
-
593
- case 'activate-configuration':
594
- return this.callApi('PATCH', 202, true, base, body);
595
- break;
596
-
597
- case 'deactivate-configuration':
598
- return this.callApi('PATCH', 202, true, base, body);
599
- break;
600
-
601
- case 'list-differences':
602
- return this.callApi('PATCH', 200, true, base, body);
603
- break;
604
-
605
- default:
606
- return this.invalidOperation("PATCH operation is not allowed. Invalid operation id");
607
- }
608
- } else {
609
- switch (operationId) {
610
- case 'validate-configuration':
611
- return this.callApi('PATCH', 200, true, base, body);
612
- break;
613
-
614
- case 'deploy-configuration':
615
- return this.callApi('PATCH', 202, true, base, body);
616
- break;
617
-
618
- case 'remove-deployed-configuration':
619
- return this.callApi('PATCH', 202, true, base, body);
620
- break;
621
-
622
- case 'list-differences':
623
- return this.invalidOperation("PATCH operation 'list-differences' is not allowed");
624
- break;
625
-
626
- default:
627
- return this.invalidOperation("PATCH operation is not allowed. Invalid operation id");
628
- }
629
- }
630
- } // Device Type patch operation on active version
631
- // Acceptable operation id - deactivate-configuration
632
-
582
+ }
633
583
  }, {
634
584
  key: "patchOperationActiveDeviceType",
635
585
  value: function patchOperationActiveDeviceType(typeId, operationId) {
636
586
  var body = {
637
587
  "operation": operationId
638
588
  };
639
-
640
589
  if (this.draftMode) {
641
590
  return this.callApi('PATCH', 202, true, ['device', 'types', typeId], body);
642
591
  } else {
@@ -661,7 +610,6 @@ var StateClient = /*#__PURE__*/function () {
661
610
  key: "createSchemaAndEventType",
662
611
  value: function createSchemaAndEventType(schemaContents, schemaFileName, eventTypeName, eventDescription) {
663
612
  var _this = this;
664
-
665
613
  var body = {
666
614
  'schemaFile': schemaContents,
667
615
  'schemaType': 'json-schema',
@@ -669,7 +617,6 @@ var StateClient = /*#__PURE__*/function () {
669
617
  };
670
618
  var createSchema = new Promise(function (resolve, reject) {
671
619
  var base = _this.draftMode ? ["draft", "schemas"] : ["schemas"];
672
-
673
620
  _this.callFormDataApi('POST', 201, true, base, body, null).then(function (result) {
674
621
  resolve(result);
675
622
  }, function (error) {
@@ -685,7 +632,6 @@ var StateClient = /*#__PURE__*/function () {
685
632
  key: "createSchemaAndLogicalInterface",
686
633
  value: function createSchemaAndLogicalInterface(schemaContents, schemaFileName, appInterfaceName, appInterfaceDescription, appInterfaceAlias) {
687
634
  var _this2 = this;
688
-
689
635
  var body = {
690
636
  'schemaFile': schemaContents,
691
637
  'schemaType': 'json-schema',
@@ -693,7 +639,6 @@ var StateClient = /*#__PURE__*/function () {
693
639
  };
694
640
  var createSchema = new Promise(function (resolve, reject) {
695
641
  var base = _this2.draftMode ? ["draft", "schemas"] : ["schemas"];
696
-
697
642
  _this2.callFormDataApi('POST', 201, true, base, body, null).then(function (result) {
698
643
  resolve(result);
699
644
  }, function (error) {
@@ -709,7 +654,6 @@ var StateClient = /*#__PURE__*/function () {
709
654
  key: "createPhysicalInterfaceWithEventMapping",
710
655
  value: function createPhysicalInterfaceWithEventMapping(physicalInterfaceName, description, eventId, eventTypeId) {
711
656
  var _this3 = this;
712
-
713
657
  var createPhysicalInterface = new Promise(function (resolve, reject) {
714
658
  _this3.createPhysicalInterface(physicalInterfaceName, description).then(function (result) {
715
659
  resolve(result);
@@ -735,7 +679,6 @@ var StateClient = /*#__PURE__*/function () {
735
679
  key: "createDeviceTypeLogicalInterfaceEventMapping",
736
680
  value: function createDeviceTypeLogicalInterfaceEventMapping(deviceTypeName, description, logicalInterfaceId, eventMapping, notificationStrategy) {
737
681
  var _this4 = this;
738
-
739
682
  var createDeviceType = new Promise(function (resolve, reject) {
740
683
  _this4.createDeviceType(deviceTypeName, description).then(function (result) {
741
684
  resolve(result);
@@ -757,11 +700,9 @@ var StateClient = /*#__PURE__*/function () {
757
700
  deviceTypeLogicalInterface = result;
758
701
  var deviceTypeLogicalInterfacePropertyMappings = new Promise(function (resolve, reject) {
759
702
  var notificationstrategy = "never";
760
-
761
703
  if (notificationStrategy) {
762
704
  notificationstrategy = notificationStrategy;
763
705
  }
764
-
765
706
  _this4.createDeviceTypeLogicalInterfacePropertyMappings(deviceObject.id, logicalInterfaceId, eventMapping, notificationstrategy).then(function (result) {
766
707
  var arr = [deviceObject, deviceTypeLogicalInterface, result];
767
708
  resolve(arr);
@@ -776,9 +717,6 @@ var StateClient = /*#__PURE__*/function () {
776
717
  });
777
718
  }
778
719
  }]);
779
-
780
720
  return StateClient;
781
721
  }();
782
-
783
- exports["default"] = StateClient;
784
722
  ;