@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.
- package/dist/BaseClient.js +36 -82
- package/dist/BaseConfig.js +24 -36
- package/dist/api/ApiClient.js +60 -76
- package/dist/api/ApiErrors.js +29 -74
- package/dist/api/DscClient.js +77 -77
- package/dist/api/LecClient.js +17 -15
- package/dist/api/MgmtClient.js +17 -15
- package/dist/api/RegistryClient.js +12 -18
- package/dist/api/RulesClient.js +17 -15
- package/dist/api/StateClient.js +70 -132
- package/dist/application/ApplicationClient.js +53 -137
- package/dist/application/ApplicationConfig.js +43 -64
- package/dist/application/index.js +0 -3
- package/dist/bundled/wiotp-bundle.js +45644 -34207
- package/dist/bundled/wiotp-bundle.min.js +7 -6
- package/dist/device/DeviceClient.js +25 -54
- package/dist/device/DeviceConfig.js +37 -59
- package/dist/device/index.js +0 -3
- package/dist/gateway/GatewayClient.js +27 -61
- package/dist/gateway/GatewayConfig.js +22 -33
- package/dist/gateway/index.js +0 -3
- package/dist/index.js +14 -28
- package/dist/util.js +9 -15
- package/package.json +24 -24
- package/src/BaseClient.js +1 -1
- package/src/application/ApplicationConfig.js +1 -1
|
@@ -1,83 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
8
|
var _BaseConfig2 = _interopRequireDefault(require("../BaseConfig"));
|
|
9
|
-
|
|
10
9
|
var _loglevel = _interopRequireDefault(require("loglevel"));
|
|
11
|
-
|
|
12
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
|
|
14
|
-
function _typeof(obj) { "@babel/helpers - typeof"; 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
11
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
25
|
-
|
|
26
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
27
|
-
|
|
28
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
29
|
-
|
|
12
|
+
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); } }
|
|
13
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(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(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
30
18
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
31
|
-
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
function
|
|
35
|
-
|
|
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(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
21
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
22
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } /**
|
|
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
|
+
*/
|
|
36
32
|
var YAML = require('yaml');
|
|
37
|
-
|
|
38
33
|
var fs = require('fs');
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var ApplicationConfig = /*#__PURE__*/function (_BaseConfig) {
|
|
34
|
+
var _require = require('uuid'),
|
|
35
|
+
uuidv4 = _require.v4;
|
|
36
|
+
var ApplicationConfig = exports["default"] = /*#__PURE__*/function (_BaseConfig) {
|
|
43
37
|
_inherits(ApplicationConfig, _BaseConfig);
|
|
44
|
-
|
|
45
|
-
var _super = _createSuper(ApplicationConfig);
|
|
46
|
-
|
|
47
38
|
function ApplicationConfig(identity, auth, options) {
|
|
48
39
|
var _this;
|
|
49
|
-
|
|
50
40
|
_classCallCheck(this, ApplicationConfig);
|
|
41
|
+
_this = _callSuper(this, ApplicationConfig, [identity, auth, options]);
|
|
51
42
|
|
|
52
|
-
|
|
43
|
+
// Authentication is not supported for quickstart
|
|
53
44
|
// and not required when auth.useLtpa is set
|
|
54
|
-
|
|
55
45
|
if (_this.auth != null && !_this.auth.useLtpa) {
|
|
56
46
|
if (!("key" in _this.auth) || _this.auth.key == null) {
|
|
57
47
|
throw new Error("Missing auth.key from configuration");
|
|
58
48
|
}
|
|
59
|
-
|
|
60
49
|
if (!("token" in _this.auth) || _this.auth.token == null) {
|
|
61
50
|
throw new Error("Missing auth.token from configuration");
|
|
62
51
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
52
|
+
}
|
|
65
53
|
|
|
54
|
+
// Set defaults for optional configuration
|
|
66
55
|
if (_this.identity == null) {
|
|
67
56
|
_this.identity = {};
|
|
68
57
|
}
|
|
69
|
-
|
|
70
58
|
if (!("appId" in _this.identity)) {
|
|
71
59
|
_this.identity.appId = uuidv4();
|
|
72
60
|
}
|
|
73
|
-
|
|
74
61
|
if (!("sharedSubscription" in _this.options.mqtt)) {
|
|
75
62
|
_this.options.mqtt.sharedSubscription = false;
|
|
76
63
|
}
|
|
77
|
-
|
|
78
64
|
return _this;
|
|
79
65
|
}
|
|
80
|
-
|
|
81
66
|
_createClass(ApplicationConfig, [{
|
|
82
67
|
key: "getOrgId",
|
|
83
68
|
value: function getOrgId() {
|
|
@@ -88,8 +73,9 @@ var ApplicationConfig = /*#__PURE__*/function (_BaseConfig) {
|
|
|
88
73
|
} else {
|
|
89
74
|
return null;
|
|
90
75
|
}
|
|
91
|
-
}
|
|
76
|
+
}
|
|
92
77
|
|
|
78
|
+
// Returns options.apiRoot if set, 'api/v0002' otherwiss
|
|
93
79
|
}, {
|
|
94
80
|
key: "getApiRoot",
|
|
95
81
|
value: function getApiRoot() {
|
|
@@ -104,11 +90,9 @@ var ApplicationConfig = /*#__PURE__*/function (_BaseConfig) {
|
|
|
104
90
|
key: "getClientId",
|
|
105
91
|
value: function getClientId() {
|
|
106
92
|
var clientIdPrefix = "a";
|
|
107
|
-
|
|
108
93
|
if (this.options.mqtt.sharedSubscription == true) {
|
|
109
94
|
clientIdPrefix = "A";
|
|
110
95
|
}
|
|
111
|
-
|
|
112
96
|
return clientIdPrefix + ":" + this.getOrgId() + ":" + this.identity.appId;
|
|
113
97
|
}
|
|
114
98
|
}, {
|
|
@@ -138,16 +122,18 @@ var ApplicationConfig = /*#__PURE__*/function (_BaseConfig) {
|
|
|
138
122
|
value: function parseEnvVars() {
|
|
139
123
|
// Auth
|
|
140
124
|
var authKey = process.env.WIOTP_AUTH_KEY || null;
|
|
141
|
-
var authToken = process.env.WIOTP_AUTH_TOKEN || null;
|
|
125
|
+
var authToken = process.env.WIOTP_AUTH_TOKEN || null;
|
|
142
126
|
|
|
127
|
+
// Also support WIOTP_API_KEY / WIOTP_API_TOKEN usage
|
|
143
128
|
if (authKey == null && authToken == null) {
|
|
144
129
|
authKey = process.env.WIOTP_API_KEY || null;
|
|
145
130
|
authToken = process.env.WIOTP_API_TOKEN || null;
|
|
146
|
-
}
|
|
147
|
-
|
|
131
|
+
}
|
|
148
132
|
|
|
149
|
-
|
|
133
|
+
// Identity
|
|
134
|
+
var appId = process.env.WIOTP_IDENTITY_APPID || uuidv4();
|
|
150
135
|
|
|
136
|
+
// Options
|
|
151
137
|
var domain = process.env.WIOTP_OPTIONS_DOMAIN || null;
|
|
152
138
|
var apiRoot = process.env.WIOTP_OPTIONS_API_ROOT || null;
|
|
153
139
|
var logLevel = process.env.WIOTP_OPTIONS_LOGLEVEL || "info";
|
|
@@ -158,13 +144,14 @@ var ApplicationConfig = /*#__PURE__*/function (_BaseConfig) {
|
|
|
158
144
|
var sessionExpiry = process.env.WIOTP_OPTIONS_MQTT_SESSIONEXPIRY || 3600;
|
|
159
145
|
var keepAlive = process.env.WIOTP_OPTIONS_MQTT_KEEPALIVE || 60;
|
|
160
146
|
var sharedSubs = process.env.WIOTP_OPTIONS_MQTT_SHAREDSUBSCRIPTION || "false";
|
|
161
|
-
var verifyCert = process.env.WIOTP_OPTIONS_HTTP_VERIFY || "true";
|
|
162
|
-
|
|
147
|
+
var verifyCert = process.env.WIOTP_OPTIONS_HTTP_VERIFY || "true";
|
|
148
|
+
|
|
149
|
+
// TODO: add environment variable parsing for options.http.additionalHeaders
|
|
163
150
|
|
|
151
|
+
// String to int conversions
|
|
164
152
|
if (port != null) {
|
|
165
153
|
port = parseInt(port);
|
|
166
154
|
}
|
|
167
|
-
|
|
168
155
|
sessionExpiry = parseInt(sessionExpiry);
|
|
169
156
|
keepAlive = parseInt(keepAlive);
|
|
170
157
|
var identity = {
|
|
@@ -187,15 +174,14 @@ var ApplicationConfig = /*#__PURE__*/function (_BaseConfig) {
|
|
|
187
174
|
verify: ["True", "true", "1"].includes(verifyCert)
|
|
188
175
|
}
|
|
189
176
|
};
|
|
190
|
-
var auth = null;
|
|
191
|
-
|
|
177
|
+
var auth = null;
|
|
178
|
+
// Quickstart doesn't support auth, so ensure we only add this if it's defined
|
|
192
179
|
if (authToken != null) {
|
|
193
180
|
auth = {
|
|
194
181
|
key: authKey,
|
|
195
182
|
token: authToken
|
|
196
183
|
};
|
|
197
184
|
}
|
|
198
|
-
|
|
199
185
|
return new ApplicationConfig(identity, auth, options);
|
|
200
186
|
}
|
|
201
187
|
}, {
|
|
@@ -227,36 +213,29 @@ var ApplicationConfig = /*#__PURE__*/function (_BaseConfig) {
|
|
|
227
213
|
X-Csrf-Token: sdfsdfsdf
|
|
228
214
|
X-myheader: hello
|
|
229
215
|
*/
|
|
216
|
+
|
|
230
217
|
var configFile = fs.readFileSync(configFilePath, 'utf8');
|
|
231
218
|
var data = YAML.parse(configFile);
|
|
232
|
-
|
|
233
219
|
if (!fs.existsSync(configFilePath)) {
|
|
234
220
|
throw new Error("File not found");
|
|
235
221
|
} else {
|
|
236
222
|
try {
|
|
237
223
|
var _configFile = fs.readFileSync(configFilePath, 'utf8');
|
|
238
|
-
|
|
239
224
|
var data = YAML.parse(_configFile);
|
|
240
225
|
} catch (err) {
|
|
241
226
|
throw new Error("Error reading device configuration file: " + err.code);
|
|
242
227
|
}
|
|
243
228
|
}
|
|
244
|
-
|
|
245
229
|
if ("options" in data & "logLevel" in data["options"]) {
|
|
246
230
|
var validLevels = ["error", "warning", "info", "debug"];
|
|
247
|
-
|
|
248
231
|
if (!validLevels.includes(data["options"]["logLevel"])) {
|
|
249
232
|
throw new Error("Optional setting options.logLevel (Currently: " + data["options"]["logLevel"] + ") must be one of error, warning, info, debug");
|
|
250
233
|
}
|
|
251
234
|
} else {
|
|
252
235
|
data["options"]["logLevel"] = _loglevel["default"].GetLogger(data["options"]["logLevel"].toUpperCase());
|
|
253
236
|
}
|
|
254
|
-
|
|
255
237
|
return new ApplicationConfig(data['identity'], data['auth'], data['options']);
|
|
256
238
|
}
|
|
257
239
|
}]);
|
|
258
|
-
|
|
259
240
|
return ApplicationConfig;
|
|
260
|
-
}(_BaseConfig2["default"]);
|
|
261
|
-
|
|
262
|
-
exports["default"] = ApplicationConfig;
|
|
241
|
+
}(_BaseConfig2["default"]);
|
|
@@ -15,9 +15,6 @@ Object.defineProperty(exports, "ApplicationConfig", {
|
|
|
15
15
|
return _ApplicationConfig["default"];
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
|
|
19
18
|
var _ApplicationClient = _interopRequireDefault(require("./ApplicationClient"));
|
|
20
|
-
|
|
21
19
|
var _ApplicationConfig = _interopRequireDefault(require("./ApplicationConfig"));
|
|
22
|
-
|
|
23
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|