@wiotp/sdk 0.6.1 → 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.
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _util = require("../util");
9
+
10
+ var _BaseClient2 = _interopRequireDefault(require("../BaseClient"));
11
+
12
+ var _DeviceConfig = _interopRequireDefault(require("./DeviceConfig"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+
16
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
17
+
18
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
+
20
+ 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); } }
21
+
22
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
23
+
24
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
25
+
26
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
27
+
28
+ function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
29
+
30
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
31
+
32
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
33
+
34
+ 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
35
+
36
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
37
+
38
+ var WILDCARD_TOPIC = 'iot-2/cmd/+/fmt/+';
39
+ var CMD_RE = /^iot-2\/cmd\/(.+)\/fmt\/(.+)$/;
40
+
41
+ var util = require('util');
42
+
43
+ var DeviceClient =
44
+ /*#__PURE__*/
45
+ function (_BaseClient) {
46
+ _inherits(DeviceClient, _BaseClient);
47
+
48
+ function DeviceClient(config) {
49
+ var _this;
50
+
51
+ _classCallCheck(this, DeviceClient);
52
+
53
+ if (!config instanceof _DeviceConfig["default"]) {
54
+ throw new Error("Config must be an instance of DeviceConfig");
55
+ }
56
+
57
+ _this = _possibleConstructorReturn(this, _getPrototypeOf(DeviceClient).call(this, config));
58
+
59
+ _this.log.debug("[DeviceClient:constructor] DeviceClient initialized for " + config.getClientId());
60
+
61
+ return _this;
62
+ }
63
+
64
+ _createClass(DeviceClient, [{
65
+ key: "_commandSubscriptionCallback",
66
+ value: function _commandSubscriptionCallback(err, granted) {
67
+ if (err == null) {
68
+ for (var index in granted) {
69
+ var grant = granted[index];
70
+ this.log.debug("[DeviceClient:connect] Subscribed to device commands on " + grant.topic + " at QoS " + grant.qos);
71
+ }
72
+ } else {
73
+ this.log.error("[DeviceClient:connect] Unable to establish subscription for device commands: " + err);
74
+ this.emit("error", new Error("Unable to establish subscription for device commands: " + err));
75
+ }
76
+ }
77
+ }, {
78
+ key: "connect",
79
+ value: function connect() {
80
+ var _this2 = this;
81
+
82
+ _get(_getPrototypeOf(DeviceClient.prototype), "connect", this).call(this);
83
+
84
+ this.mqtt.on('connect', function () {
85
+ // On connect establish a subscription for commands sent to this device (but not if connecting to quickstart)
86
+ if (!_this2.config.isQuickstart()) {
87
+ // You need to bind a particular this context to the method before you can use it as a callback
88
+ _this2.mqtt.subscribe(WILDCARD_TOPIC, {
89
+ qos: 1
90
+ }, _this2._commandSubscriptionCallback.bind(_this2));
91
+ }
92
+ });
93
+ this.mqtt.on('message', function (topic, payload) {
94
+ _this2.log.debug("[DeviceClient:onMessage] Message received on topic : " + topic + " with payload : " + payload);
95
+
96
+ var match = CMD_RE.exec(topic);
97
+
98
+ if (match) {
99
+ _this2.emit('command', match[1], match[2], payload, topic);
100
+ }
101
+ });
102
+ }
103
+ }, {
104
+ key: "publishEvent",
105
+ value: function publishEvent(eventId, format, data, qos, callback) {
106
+ qos = qos || 0;
107
+
108
+ if (!(0, _util.isDefined)(eventId) || !(0, _util.isDefined)(format)) {
109
+ this.log.error("[DeviceClient:publishEvent] Required params for publishEvent not present");
110
+ this.emit('error', "[DeviceClient:publishEvent] Required params for publishEvent not present");
111
+ return;
112
+ }
113
+
114
+ var topic = util.format("iot-2/evt/%s/fmt/%s", eventId, format);
115
+
116
+ this._publish(topic, data, qos, callback);
117
+
118
+ return this;
119
+ }
120
+ }]);
121
+
122
+ return DeviceClient;
123
+ }(_BaseClient2["default"]);
124
+
125
+ exports["default"] = DeviceClient;
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _BaseConfig2 = _interopRequireDefault(require("../BaseConfig"));
9
+
10
+ var _loglevel = _interopRequireDefault(require("loglevel"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+
14
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
15
+
16
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
+
18
+ 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); } }
19
+
20
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
21
+
22
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
23
+
24
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
25
+
26
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
27
+
28
+ 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
29
+
30
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
31
+
32
+ var YAML = require('yaml');
33
+
34
+ var fs = require('fs');
35
+
36
+ var DeviceConfig =
37
+ /*#__PURE__*/
38
+ function (_BaseConfig) {
39
+ _inherits(DeviceConfig, _BaseConfig);
40
+
41
+ function DeviceConfig(identity, auth, options) {
42
+ var _this;
43
+
44
+ _classCallCheck(this, DeviceConfig);
45
+
46
+ _this = _possibleConstructorReturn(this, _getPrototypeOf(DeviceConfig).call(this, identity, auth, options)); //Validate the arguments
47
+
48
+ if (_this.identity == null) {
49
+ throw new Error("Missing identity from configuration");
50
+ }
51
+
52
+ if (!("orgId" in _this.identity) || _this.identity.orgId == null) {
53
+ throw new Error("Missing identity.orgId from configuration");
54
+ }
55
+
56
+ if (!("typeId" in _this.identity) || _this.identity.typeId == null) {
57
+ throw new Error("Missing identity.typeId from configuration");
58
+ }
59
+
60
+ if (!("deviceId" in _this.identity) || _this.identity.deviceId == null) {
61
+ throw new Error("Missing identity.deviceId from configuration");
62
+ } // Authentication is not supported for quickstart
63
+
64
+
65
+ if (_this.identity.orgId == "quickstart") {
66
+ if (_this.auth != null) {
67
+ throw new Error("Quickstart service does not support device authentication");
68
+ }
69
+ } else {
70
+ if (_this.auth == null) {
71
+ throw new Error("Missing auth from configuration");
72
+ }
73
+
74
+ if (!("token" in _this.auth) || _this.auth.token == null) {
75
+ throw new Error("Missing auth.token from configuration");
76
+ }
77
+ }
78
+
79
+ return _this;
80
+ }
81
+
82
+ _createClass(DeviceConfig, [{
83
+ key: "getOrgId",
84
+ value: function getOrgId() {
85
+ return this.identity.orgId;
86
+ }
87
+ }, {
88
+ key: "getClientId",
89
+ value: function getClientId() {
90
+ return "d:" + this.identity.orgId + ":" + this.identity.typeId + ":" + this.identity.deviceId;
91
+ }
92
+ }, {
93
+ key: "getMqttUsername",
94
+ value: function getMqttUsername() {
95
+ return "use-token-auth";
96
+ }
97
+ }, {
98
+ key: "getMqttPassword",
99
+ value: function getMqttPassword() {
100
+ return this.auth.token;
101
+ }
102
+ }], [{
103
+ key: "parseEnvVars",
104
+ value: function parseEnvVars() {
105
+ //Identity
106
+ var orgId = process.env.WIOTP_IDENTITY_ORGID || null;
107
+ var typeId = process.env.WIOTP_IDENTITY_TYPEID || null;
108
+ var deviceId = process.env.WIOTP_IDENTITY_DEVICEID || null; // Auth
109
+
110
+ var authToken = process.env.WIOTP_AUTH_TOKEN || null; // Also support WIOTP_API_TOKEN usage
111
+
112
+ if (authToken == null) {
113
+ authToken = process.env.WIOTP_API_TOKEN || null;
114
+ } // Options
115
+
116
+
117
+ var domain = process.env.WIOTP_OPTIONS_DOMAIN || null;
118
+ var logLevel = process.env.WIOTP_OPTIONS_LOGLEVEL || "info";
119
+ var port = process.env.WIOTP_OPTIONS_MQTT_PORT || null;
120
+ var transport = process.env.WIOTP_OPTIONS_MQTT_TRANSPORT || null;
121
+ var caFile = process.env.WIOTP_OPTIONS_MQTT_CAFILE || null;
122
+ var cleanStart = process.env.WIOTP_OPTIONS_MQTT_CLEANSTART || "true";
123
+ var sessionExpiry = process.env.WIOTP_OPTIONS_MQTT_SESSIONEXPIRY || 3600;
124
+ var keepAlive = process.env.WIOTP_OPTIONS_MQTT_KEEPALIVE || 60;
125
+ var sharedSubs = process.env.WIOTP_OPTIONS_MQTT_SHAREDSUBSCRIPTION || "false"; // String to int conversions
126
+
127
+ if (port != null) {
128
+ port = parseInt(port);
129
+ }
130
+
131
+ sessionExpiry = parseInt(sessionExpiry);
132
+ keepAlive = parseInt(keepAlive);
133
+ var identity = {
134
+ orgId: orgId,
135
+ typeId: typeId,
136
+ deviceId: deviceId
137
+ };
138
+ var options = {
139
+ domain: domain,
140
+ logLevel: logLevel,
141
+ mqtt: {
142
+ port: port,
143
+ transport: transport,
144
+ cleanStart: ["True", "true", "1"].includes(cleanStart),
145
+ sessionExpiry: sessionExpiry,
146
+ keepAlive: keepAlive,
147
+ sharedSubscription: ["True", "true", "1"].includes(sharedSubs),
148
+ caFile: caFile
149
+ }
150
+ };
151
+ var auth = null; // Quickstart doesn't support auth, so ensure we only add this if it's defined
152
+
153
+ if (authToken != null) {
154
+ auth = {
155
+ token: authToken
156
+ };
157
+ }
158
+
159
+ return new DeviceConfig(identity, auth, options);
160
+ }
161
+ }, {
162
+ key: "parseConfigFile",
163
+ value: function parseConfigFile(configFilePath) {
164
+ //Example Device Configuration File:
165
+
166
+ /*
167
+ identity:
168
+ orgId: org1id
169
+ typeId: raspberry-pi-3
170
+ deviceId: 00ef08ac05
171
+ auth:
172
+ token: Ab$76s)asj8_s5
173
+ options:
174
+ domain: internetofthings.ibmcloud.com
175
+ logLevel: error|warning|info|debug
176
+ mqtt:
177
+ port: 8883
178
+ transport: tcp
179
+ cleanStart: true
180
+ sessionExpiry: 3600
181
+ keepAlive: 60
182
+ caFile: /path/to/certificateAuthorityFile.pem
183
+ */
184
+ var configFile = fs.readFileSync(configFilePath, 'utf8');
185
+ var data = YAML.parse(configFile);
186
+
187
+ if (!fs.existsSync(configFilePath)) {
188
+ throw new Error("File not found");
189
+ } else {
190
+ try {
191
+ var _configFile = fs.readFileSync(configFilePath, 'utf8');
192
+
193
+ var data = YAML.parse(_configFile);
194
+ } catch (err) {
195
+ throw new Error("Error reading device configuration file: " + err.code);
196
+ }
197
+ }
198
+
199
+ if ("options" in data & "logLevel" in data["options"]) {
200
+ var validLevels = ["error", "warning", "info", "debug"];
201
+
202
+ if (!validLevels.includes(data["options"]["logLevel"])) {
203
+ throw new Error("Optional setting options.logLevel (Currently: " + data["options"]["logLevel"] + ") must be one of error, warning, info, debug");
204
+ }
205
+ } else {
206
+ data["options"]["logLevel"] = _loglevel["default"].GetLogger(data["options"]["logLevel"].toUpperCase());
207
+ }
208
+
209
+ return new DeviceConfig(data['identity'], data['auth'], data['options']);
210
+ }
211
+ }]);
212
+
213
+ return DeviceConfig;
214
+ }(_BaseConfig2["default"]);
215
+
216
+ exports["default"] = DeviceConfig;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "DeviceClient", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _DeviceClient["default"];
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "DeviceConfig", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _DeviceConfig["default"];
16
+ }
17
+ });
18
+
19
+ var _DeviceClient = _interopRequireDefault(require("./DeviceClient"));
20
+
21
+ var _DeviceConfig = _interopRequireDefault(require("./DeviceConfig"));
22
+
23
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _BaseClient2 = _interopRequireDefault(require("../BaseClient"));
9
+
10
+ var _GatewayConfig = _interopRequireDefault(require("./GatewayConfig"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+
14
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
15
+
16
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
+
18
+ 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); } }
19
+
20
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
21
+
22
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
23
+
24
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
25
+
26
+ function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
27
+
28
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
29
+
30
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
31
+
32
+ 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
33
+
34
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
35
+
36
+ var CMD_RE = /^iot-2\/type\/(.+)\/id\/(.+)\/cmd\/(.+)\/fmt\/(.+)$/;
37
+
38
+ var util = require('util');
39
+
40
+ var GatewayClient =
41
+ /*#__PURE__*/
42
+ function (_BaseClient) {
43
+ _inherits(GatewayClient, _BaseClient);
44
+
45
+ function GatewayClient(config) {
46
+ var _this;
47
+
48
+ _classCallCheck(this, GatewayClient);
49
+
50
+ if (!config instanceof _GatewayConfig["default"]) {
51
+ throw new Error("Config must be an instance of GatewayConfig");
52
+ }
53
+
54
+ if (config.isQuickstart()) {
55
+ throw new Error('[GatewayClient:constructor] Quickstart not supported in Gateways');
56
+ }
57
+
58
+ _this = _possibleConstructorReturn(this, _getPrototypeOf(GatewayClient).call(this, config));
59
+
60
+ _this.log.debug("[GatewayClient:constructor] GatewayClient initialized for " + config.getClientId());
61
+
62
+ return _this;
63
+ }
64
+
65
+ _createClass(GatewayClient, [{
66
+ key: "connect",
67
+ value: function connect() {
68
+ var _this2 = this;
69
+
70
+ _get(_getPrototypeOf(GatewayClient.prototype), "connect", this).call(this);
71
+
72
+ this.mqtt.on('connect', function () {// This gateway client implemention does not automatically subscribe to any commands!?
73
+ });
74
+ this.mqtt.on('message', function (topic, payload) {
75
+ _this2.log.debug("[GatewayClient:onMessage] Message received on topic : " + topic + " with payload : " + payload);
76
+
77
+ var match = CMD_RE.exec(topic);
78
+
79
+ if (match) {
80
+ _this2.emit('command', match[1], match[2], match[3], match[4], payload, topic);
81
+ }
82
+ });
83
+ }
84
+ }, {
85
+ key: "publishEvent",
86
+ value: function publishEvent(eventId, format, payload, qos, callback) {
87
+ return this._publishEvent(this.config.identity.typeId, this.config.identity.deviceId, eventId, format, payload, qos, callback);
88
+ }
89
+ }, {
90
+ key: "publishDeviceEvent",
91
+ value: function publishDeviceEvent(typeid, deviceId, eventid, format, payload, qos, callback) {
92
+ return this._publishEvent(typeId, deviceId, eventid, format, payload, qos, callback);
93
+ }
94
+ }, {
95
+ key: "_publishEvent",
96
+ value: function _publishEvent(typeId, deviceId, eventId, format, data, qos, callback) {
97
+ var topic = util.format("iot-2/type/%s/id/%s/evt/%s/fmt/%s", typeId, deviceId, eventId, format);
98
+ qos = qos || 0;
99
+
100
+ this._publish(topic, data, qos, callback);
101
+
102
+ return this;
103
+ }
104
+ }, {
105
+ key: "subscribeToDeviceCommands",
106
+ value: function subscribeToDeviceCommands(typeId, deviceId, commandId, format, qos, callback) {
107
+ typeId = typeId || '+';
108
+ deviceId = deviceId || '+';
109
+ commandId = commandid || '+';
110
+ format = format || '+';
111
+ qos = qos || 0;
112
+ var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/cmd/" + commandId + "/fmt/" + format;
113
+
114
+ this._subscribe(topic, qos, callback);
115
+
116
+ return this;
117
+ }
118
+ }, {
119
+ key: "unsubscribeFromDeviceCommands",
120
+ value: function unsubscribeFromDeviceCommands(typeId, deviceId, commandId, format, callback) {
121
+ typeId = typeId || '+';
122
+ deviceId = deviceId || '+';
123
+ commandId = commandId || '+';
124
+ format = format || '+';
125
+ var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/cmd/" + commandId + "/fmt/" + format;
126
+
127
+ this._unsubscribe(topic, callback);
128
+
129
+ return this;
130
+ }
131
+ }, {
132
+ key: "subscribeToCommands",
133
+ value: function subscribeToCommands(commandId, format, qos, callback) {
134
+ commandId = commandId || '+';
135
+ format = format || '+';
136
+ qos = qos || 0;
137
+ var topic = "iot-2/type/" + this.config.identity.typeId + "/id/" + this.config.identity.deviceId + "/cmd/" + commandId + "/fmt/" + format;
138
+
139
+ this._subscribe(topic, qos, callback);
140
+
141
+ return this;
142
+ }
143
+ }, {
144
+ key: "unsubscribeFromCommands",
145
+ value: function unsubscribeFromCommands(commandId, format, callback) {
146
+ commandId = commandId || '+';
147
+ format = format || '+';
148
+ var topic = "iot-2/type/" + this.config.identity.typeId + "/id/" + this.config.identity.deviceId + "/cmd/" + commandId + "/fmt/" + format;
149
+
150
+ this._unsubscribe(topic, callback);
151
+
152
+ return this;
153
+ }
154
+ }]);
155
+
156
+ return GatewayClient;
157
+ }(_BaseClient2["default"]);
158
+
159
+ exports["default"] = GatewayClient;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _DeviceConfig2 = _interopRequireDefault(require("../device/DeviceConfig"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+
12
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
13
+
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+
16
+ 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); } }
17
+
18
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
19
+
20
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
21
+
22
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
23
+
24
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
25
+
26
+ 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
27
+
28
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
29
+
30
+ var GatewayConfig =
31
+ /*#__PURE__*/
32
+ function (_DeviceConfig) {
33
+ _inherits(GatewayConfig, _DeviceConfig);
34
+
35
+ function GatewayConfig(identity, auth, options) {
36
+ _classCallCheck(this, GatewayConfig);
37
+
38
+ return _possibleConstructorReturn(this, _getPrototypeOf(GatewayConfig).call(this, identity, auth, options));
39
+ }
40
+
41
+ _createClass(GatewayConfig, [{
42
+ key: "getClientId",
43
+ value: function getClientId() {
44
+ return "g:" + this.identity.orgId + ":" + this.identity.typeId + ":" + this.identity.deviceId;
45
+ }
46
+ }]);
47
+
48
+ return GatewayConfig;
49
+ }(_DeviceConfig2["default"]);
50
+
51
+ exports["default"] = GatewayConfig;
52
+ ;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "GatewayClient", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _GatewayClient["default"];
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "GatewayConfig", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _GatewayConfig["default"];
16
+ }
17
+ });
18
+
19
+ var _GatewayClient = _interopRequireDefault(require("./GatewayClient"));
20
+
21
+ var _GatewayConfig = _interopRequireDefault(require("./GatewayConfig"));
22
+
23
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
package/dist/util.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isString = isString;
7
+ exports.isNumber = isNumber;
8
+ exports.isBoolean = isBoolean;
9
+ exports.isDefined = isDefined;
10
+ exports.generateUUID = generateUUID;
11
+ exports.isNode = exports.isBrowser = void 0;
12
+
13
+ /**
14
+ *****************************************************************************
15
+ Copyright (c) 2014, 2019 IBM Corporation and other Contributors.
16
+ All rights reserved. This program and the accompanying materials
17
+ are made available under the terms of the Eclipse Public License v1.0
18
+ which accompanies this distribution, and is available at
19
+ http://www.eclipse.org/legal/epl-v10.html
20
+ *****************************************************************************
21
+ *
22
+ */
23
+ function isString(value) {
24
+ return typeof value === 'string';
25
+ }
26
+
27
+ function isNumber(value) {
28
+ return typeof value === 'number';
29
+ }
30
+
31
+ function isBoolean(value) {
32
+ return typeof value === 'boolean';
33
+ }
34
+
35
+ function isDefined(value) {
36
+ return value !== undefined && value !== null;
37
+ }
38
+
39
+ var isBrowser = new Function("try {return this===window;}catch(e){ return false;}");
40
+ exports.isBrowser = isBrowser;
41
+ var isNode = new Function("try {return this===global;}catch(e){return false;}");
42
+ exports.isNode = isNode;
43
+
44
+ function generateUUID() {
45
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
46
+ var r = Math.random() * 16 | 0,
47
+ v = c == 'x' ? r : r & 0x3 | 0x8;
48
+ return v.toString(16);
49
+ });
50
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@wiotp/sdk",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "SDK for developing device, gateway, and application clients for IBM Watson IoT Platform",
5
5
  "main": "dist/index.js",
6
6
  "files": [
7
+ "dist",
7
8
  "src",
8
- "index.js",
9
9
  "package.json",
10
10
  "README.md",
11
11
  "LICENCE"
@@ -60,6 +60,10 @@
60
60
  "email": "parkerda@uk.ibm.com"
61
61
  },
62
62
  "contributors": [
63
+ {
64
+ "name": "Tom Klapiscak",
65
+ "email": "klapitom@uk.ibm.com"
66
+ },
63
67
  {
64
68
  "name": "Bryan Boyd",
65
69
  "email": "bboyd@us.ibm.com"