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