@wiotp/sdk 0.4.2 → 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.
Files changed (48) hide show
  1. package/LICENSE +203 -203
  2. package/README.md +68 -68
  3. package/dist/BaseClient.js +259 -0
  4. package/dist/BaseConfig.js +194 -0
  5. package/dist/api/ApiClient.js +508 -0
  6. package/dist/api/ApiErrors.js +118 -0
  7. package/dist/api/DscClient.js +332 -0
  8. package/dist/api/LecClient.js +48 -0
  9. package/dist/api/MgmtClient.js +77 -0
  10. package/dist/api/RegistryClient.js +234 -0
  11. package/dist/api/RulesClient.js +105 -0
  12. package/dist/api/StateClient.js +738 -0
  13. package/dist/application/ApplicationClient.js +436 -0
  14. package/dist/application/ApplicationConfig.js +233 -0
  15. package/dist/application/index.js +23 -0
  16. package/dist/bundled/wiotp-bundle.js +35592 -0
  17. package/dist/bundled/wiotp-bundle.min.js +47 -0
  18. package/dist/device/DeviceClient.js +125 -0
  19. package/dist/device/DeviceConfig.js +216 -0
  20. package/dist/device/index.js +23 -0
  21. package/dist/gateway/GatewayClient.js +159 -0
  22. package/dist/gateway/GatewayConfig.js +52 -0
  23. package/dist/gateway/index.js +23 -0
  24. package/dist/index.js +55 -0
  25. package/dist/util.js +50 -0
  26. package/package.json +92 -84
  27. package/src/BaseClient.js +215 -215
  28. package/src/BaseConfig.js +157 -157
  29. package/src/api/ApiClient.js +454 -454
  30. package/src/api/ApiErrors.js +33 -33
  31. package/src/api/DscClient.js +164 -145
  32. package/src/api/LecClient.js +32 -32
  33. package/src/api/MgmtClient.js +57 -57
  34. package/src/api/RegistryClient.js +194 -194
  35. package/src/api/RulesClient.js +84 -84
  36. package/src/api/StateClient.js +650 -650
  37. package/src/application/ApplicationClient.js +348 -348
  38. package/src/application/ApplicationConfig.js +191 -191
  39. package/src/application/index.js +12 -12
  40. package/src/device/DeviceClient.js +78 -78
  41. package/src/device/DeviceConfig.js +175 -175
  42. package/src/device/index.js +14 -14
  43. package/src/gateway/GatewayClient.js +114 -114
  44. package/src/gateway/GatewayConfig.js +21 -21
  45. package/src/gateway/index.js +13 -13
  46. package/{index.js → src/index.js} +19 -19
  47. package/src/util.js +38 -38
  48. package/src/util/IoTFoundation.pem +0 -82
package/src/BaseConfig.js CHANGED
@@ -1,158 +1,158 @@
1
- /**
2
- *****************************************************************************
3
- Copyright (c) 2019 IBM Corporation and other Contributors.
4
- All rights reserved. This program and the accompanying materials
5
- are made available under the terms of the Eclipse Public License v1.0
6
- which accompanies this distribution, and is available at
7
- http://www.eclipse.org/legal/epl-v10.html
8
- *****************************************************************************
9
- *
10
- */
11
-
12
- export default class BaseConfig{
13
- constructor(identity, auth, options) {
14
- this.identity = identity;
15
- this.auth = auth;
16
- this.options = options;
17
-
18
- // Validation for options common to all confiugration
19
-
20
- if (this.options != null && "mqtt" in this.options) {
21
- // validate port
22
- if ("port" in this.options.mqtt && this.options.mqtt.port != null) {
23
- if (isNaN(this.options.mqtt.port)) {
24
- throw new Error("Optional setting options.mqtt.port must be a number if provided");
25
- }
26
- }
27
- // Validate cleanStart
28
- if ("cleanStart" in this.options.mqtt && typeof(this.options.mqtt.cleanStart) != "boolean") {
29
- throw new Error("Optional setting options.mqtt.cleanStart must be a boolean if provided");
30
- }
31
- }
32
-
33
- // Set defaults for optional configuration
34
- if (this.options == null) {
35
- this.options = {};
36
- }
37
- if (!("domain" in this.options) || this.options.domain == null) {
38
- this.options.domain = "internetofthings.ibmcloud.com";
39
- }
40
-
41
- if (!("logLevel" in this.options) || this.options.logLevel == null) {
42
- this.options.logLevel = "info";
43
- }
44
-
45
- if (!("mqtt" in this.options)) {
46
- this.options.mqtt = {};
47
- }
48
-
49
- if (!("port" in this.options.mqtt) || this.options.mqtt.port == null) {
50
- this.options.mqtt.port = 8883;
51
- }
52
- if (!("transport" in this.options.mqtt) || this.options.mqtt.transport == null) {
53
- this.options.mqtt.transport = "tcp";
54
- }
55
-
56
- if (!("cleanStart" in this.options.mqtt)) {
57
- this.options.mqtt.cleanStart = true;
58
- }
59
- if (!("sessionExpiry" in this.options.mqtt)) {
60
- this.options.mqtt.sessionExpiry = 3600;
61
- }
62
- if (!("keepAlive" in this.options.mqtt)) {
63
- this.options.mqtt.keepAlive = 60;
64
- }
65
-
66
- if (!("caFile" in this.options.mqtt)) {
67
- this.options.mqtt.caFile = null;
68
- }
69
- }
70
-
71
- getOrgId() {
72
- throw new Error("Sub class must implement getOrgId()");
73
- }
74
-
75
- isQuickstart() {
76
- return this.getOrgId() == "quickstart";
77
- }
78
-
79
- getClientId() {
80
- throw new Error("Sub class must implement getClientId()");
81
- }
82
-
83
- getMqttUsername() {
84
- throw new Error("Sub class must implement getMqttUsername()");
85
- }
86
-
87
- getMqttPassword() {
88
- throw new Error("Sub class must implement getMqttPassowrd()");
89
- }
90
-
91
- getMqttConfig() {
92
- // See: https://www.npmjs.com/package/mqtt#mqttclientstreambuilder-options
93
- let mqttConfig = {
94
- // Identity
95
- clientId: this.getClientId(),
96
-
97
- // Basic Connectivity
98
- keepalive: this.options.mqtt.keepAlive, // in seconds
99
- connectTimeout: 90*1000, // milliseconds, time to wait before a CONNACK is received
100
- reconnectPeriod: 1000, // milliseconds, interval between two reconnections
101
- queueQoSZero: true, // if connection is broken, queue outgoing QoS zero messages
102
- resubscribe: true, // if connection is broken and reconnects, subscribed topics are automatically subscribed again
103
-
104
- clean: this.options.mqtt.cleanStart, // set to false to receive QoS 1 and 2 messages while offline
105
-
106
- // Authentication
107
- username: this.getMqttUsername(),
108
- password: this.getMqttPassword(),
109
-
110
- // Security
111
- // If you are using a self-signed certificate, pass the rejectUnauthorized: false option. Beware
112
- // that you are exposing yourself to man in the middle attacks, so it is a configuration that
113
- // is not recommended for production environments.
114
- rejectUnauthorized: true,
115
-
116
- // MQTTv5 support doesn't work with Watson IoT Platform, so stick to default for now
117
- // protocolId: "MQTT",
118
- // protocolVersion: 5
119
- }
120
- return mqttConfig;
121
- }
122
-
123
- getMqttHost() {
124
- let server = this.getOrgId() + ".messaging." + this.options.domain + ":" + this.options.mqtt.port;
125
-
126
- // For unencrpyted ports
127
- if (this.options.mqtt.port == 80 || this.options.mqtt.port == 1883) {
128
- if (this.options.mqtt.transport == "tcp") {
129
- return "tcp://" + server;
130
- }
131
- if (this.options.mqtt.transport == "websockets") {
132
- return "ws://" + server;
133
- }
134
- }
135
-
136
- // For encrypted ports
137
- if (this.options.mqtt.port == 433 || this.options.mqtt.port == 8883) {
138
- if (this.options.mqtt.transport == "tcp") {
139
- return "ssl://" + server;
140
- }
141
- if (this.options.mqtt.transport == "websockets") {
142
- return "wss://" + server;
143
- }
144
- }
145
-
146
- // Default to something, but really shouldn't hit this scenario unless misconfigured
147
- return "ssl://" + server;
148
- }
149
-
150
- static parseEnvVars() {
151
- throw new Error("Sub class must implement parseEnvVars()");
152
- }
153
-
154
- static parseConfigFile() {
155
- throw new Error("Sub class must implement parseConfigFile()");
156
- }
157
-
1
+ /**
2
+ *****************************************************************************
3
+ Copyright (c) 2019 IBM Corporation and other Contributors.
4
+ All rights reserved. This program and the accompanying materials
5
+ are made available under the terms of the Eclipse Public License v1.0
6
+ which accompanies this distribution, and is available at
7
+ http://www.eclipse.org/legal/epl-v10.html
8
+ *****************************************************************************
9
+ *
10
+ */
11
+
12
+ export default class BaseConfig{
13
+ constructor(identity, auth, options) {
14
+ this.identity = identity;
15
+ this.auth = auth;
16
+ this.options = options;
17
+
18
+ // Validation for options common to all confiugration
19
+
20
+ if (this.options != null && "mqtt" in this.options) {
21
+ // validate port
22
+ if ("port" in this.options.mqtt && this.options.mqtt.port != null) {
23
+ if (isNaN(this.options.mqtt.port)) {
24
+ throw new Error("Optional setting options.mqtt.port must be a number if provided");
25
+ }
26
+ }
27
+ // Validate cleanStart
28
+ if ("cleanStart" in this.options.mqtt && typeof(this.options.mqtt.cleanStart) != "boolean") {
29
+ throw new Error("Optional setting options.mqtt.cleanStart must be a boolean if provided");
30
+ }
31
+ }
32
+
33
+ // Set defaults for optional configuration
34
+ if (this.options == null) {
35
+ this.options = {};
36
+ }
37
+ if (!("domain" in this.options) || this.options.domain == null) {
38
+ this.options.domain = "internetofthings.ibmcloud.com";
39
+ }
40
+
41
+ if (!("logLevel" in this.options) || this.options.logLevel == null) {
42
+ this.options.logLevel = "info";
43
+ }
44
+
45
+ if (!("mqtt" in this.options)) {
46
+ this.options.mqtt = {};
47
+ }
48
+
49
+ if (!("port" in this.options.mqtt) || this.options.mqtt.port == null) {
50
+ this.options.mqtt.port = 8883;
51
+ }
52
+ if (!("transport" in this.options.mqtt) || this.options.mqtt.transport == null) {
53
+ this.options.mqtt.transport = "tcp";
54
+ }
55
+
56
+ if (!("cleanStart" in this.options.mqtt)) {
57
+ this.options.mqtt.cleanStart = true;
58
+ }
59
+ if (!("sessionExpiry" in this.options.mqtt)) {
60
+ this.options.mqtt.sessionExpiry = 3600;
61
+ }
62
+ if (!("keepAlive" in this.options.mqtt)) {
63
+ this.options.mqtt.keepAlive = 60;
64
+ }
65
+
66
+ if (!("caFile" in this.options.mqtt)) {
67
+ this.options.mqtt.caFile = null;
68
+ }
69
+ }
70
+
71
+ getOrgId() {
72
+ throw new Error("Sub class must implement getOrgId()");
73
+ }
74
+
75
+ isQuickstart() {
76
+ return this.getOrgId() == "quickstart";
77
+ }
78
+
79
+ getClientId() {
80
+ throw new Error("Sub class must implement getClientId()");
81
+ }
82
+
83
+ getMqttUsername() {
84
+ throw new Error("Sub class must implement getMqttUsername()");
85
+ }
86
+
87
+ getMqttPassword() {
88
+ throw new Error("Sub class must implement getMqttPassowrd()");
89
+ }
90
+
91
+ getMqttConfig() {
92
+ // See: https://www.npmjs.com/package/mqtt#mqttclientstreambuilder-options
93
+ let mqttConfig = {
94
+ // Identity
95
+ clientId: this.getClientId(),
96
+
97
+ // Basic Connectivity
98
+ keepalive: this.options.mqtt.keepAlive, // in seconds
99
+ connectTimeout: 90*1000, // milliseconds, time to wait before a CONNACK is received
100
+ reconnectPeriod: 1000, // milliseconds, interval between two reconnections
101
+ queueQoSZero: true, // if connection is broken, queue outgoing QoS zero messages
102
+ resubscribe: true, // if connection is broken and reconnects, subscribed topics are automatically subscribed again
103
+
104
+ clean: this.options.mqtt.cleanStart, // set to false to receive QoS 1 and 2 messages while offline
105
+
106
+ // Authentication
107
+ username: this.getMqttUsername(),
108
+ password: this.getMqttPassword(),
109
+
110
+ // Security
111
+ // If you are using a self-signed certificate, pass the rejectUnauthorized: false option. Beware
112
+ // that you are exposing yourself to man in the middle attacks, so it is a configuration that
113
+ // is not recommended for production environments.
114
+ rejectUnauthorized: true,
115
+
116
+ // MQTTv5 support doesn't work with Watson IoT Platform, so stick to default for now
117
+ // protocolId: "MQTT",
118
+ // protocolVersion: 5
119
+ }
120
+ return mqttConfig;
121
+ }
122
+
123
+ getMqttHost() {
124
+ let server = this.getOrgId() + ".messaging." + this.options.domain + ":" + this.options.mqtt.port;
125
+
126
+ // For unencrpyted ports
127
+ if (this.options.mqtt.port == 80 || this.options.mqtt.port == 1883) {
128
+ if (this.options.mqtt.transport == "tcp") {
129
+ return "tcp://" + server;
130
+ }
131
+ if (this.options.mqtt.transport == "websockets") {
132
+ return "ws://" + server;
133
+ }
134
+ }
135
+
136
+ // For encrypted ports
137
+ if (this.options.mqtt.port == 433 || this.options.mqtt.port == 8883) {
138
+ if (this.options.mqtt.transport == "tcp") {
139
+ return "ssl://" + server;
140
+ }
141
+ if (this.options.mqtt.transport == "websockets") {
142
+ return "wss://" + server;
143
+ }
144
+ }
145
+
146
+ // Default to something, but really shouldn't hit this scenario unless misconfigured
147
+ return "ssl://" + server;
148
+ }
149
+
150
+ static parseEnvVars() {
151
+ throw new Error("Sub class must implement parseEnvVars()");
152
+ }
153
+
154
+ static parseConfigFile() {
155
+ throw new Error("Sub class must implement parseConfigFile()");
156
+ }
157
+
158
158
  };