@kronos-integration/service-mqtt 1.0.0 → 1.0.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.
@@ -17,11 +17,8 @@ jobs:
17
17
  matrix:
18
18
  os:
19
19
  - ubuntu-latest
20
- - macos-latest
21
- - windows-latest
22
20
  node-version:
23
- - 22.17.0
24
- - 24.3.0
21
+ - 24.4.1
25
22
  steps:
26
23
  - name: checkout
27
24
  uses: actions/checkout@v4.2.2
@@ -58,7 +55,7 @@ jobs:
58
55
  - name: prepare node
59
56
  uses: actions/setup-node@v4.4.0
60
57
  with:
61
- node-version: 22.17.0
58
+ node-version: 22.17.1
62
59
  cache: npm
63
60
  cache-dependency-path: package-lock.json
64
61
  - name: install
@@ -23,7 +23,7 @@ jobs:
23
23
  - name: prepare node
24
24
  uses: actions/setup-node@v4.4.0
25
25
  with:
26
- node-version: 22.17.0
26
+ node-version: 22.17.1
27
27
  cache: npm
28
28
  - name: install
29
29
  run: npm ci
@@ -11,7 +11,7 @@ jobs:
11
11
  strategy:
12
12
  matrix:
13
13
  node-version:
14
- - 22.17.0
14
+ - 22.17.1
15
15
  browser:
16
16
  - chrome
17
17
  steps:
@@ -14,7 +14,7 @@ jobs:
14
14
  - name: prepare node
15
15
  uses: actions/setup-node@v4.4.0
16
16
  with:
17
- node-version: 22.17.0
17
+ node-version: 22.17.1
18
18
  - name: install
19
19
  run: npm ci
20
20
  - name: run docs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kronos-integration/service-mqtt",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -12,7 +12,7 @@
12
12
  "types": "./types/service-mqtt.d.mts"
13
13
  }
14
14
  },
15
- "description": "http server",
15
+ "description": "MQTT service",
16
16
  "keywords": [
17
17
  "mqtt",
18
18
  "kronos-service"
@@ -36,23 +36,23 @@
36
36
  "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib es2024 -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
37
37
  },
38
38
  "dependencies": {
39
- "@kronos-integration/service": "^11.2.8",
40
- "attributes": "^0.1.337",
41
- "mqtt": "^5.13.1"
39
+ "@kronos-integration/service": "^11.2.13",
40
+ "model-attributes": "^4.2.6",
41
+ "mqtt": "^5.13.2"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@kronos-integration/test-interceptor": "^7.0.29",
45
- "@types/node": "^24.0.7",
46
- "ava": "^6.4.0",
45
+ "@types/node": "^24.0.14",
46
+ "ava": "^6.4.1",
47
47
  "c8": "^10.1.3",
48
48
  "documentation": "^14.0.3",
49
49
  "got": "^14.4.7",
50
50
  "network-address": "^1.1.2",
51
- "semantic-release": "^24.2.5",
51
+ "semantic-release": "^24.2.7",
52
52
  "typescript": "^5.8.3"
53
53
  },
54
54
  "engines": {
55
- "node": ">=22.16.0"
55
+ "node": ">=22.17.1"
56
56
  },
57
57
  "repository": {
58
58
  "type": "git",
@@ -23,16 +23,29 @@ export class ServiceMQTT extends Service {
23
23
  static get configurationAttributes() {
24
24
  return mergeAttributes(
25
25
  createAttributes({
26
- "url": {
27
- description: "server listen definition",
28
-
29
- attributes: {
30
- url: {
31
- description: "url of the mqtt server",
32
- needsRestart: true,
33
- type: "url"
34
- }
35
- }
26
+ url: {
27
+ description: "url of the mqtt server",
28
+ needsRestart: true,
29
+ type: "url"
30
+ },
31
+ clean: {
32
+ type: "boolean"
33
+ },
34
+ clientId: {
35
+ type: "string"
36
+ },
37
+ connectTimeout: {
38
+ type: "integer"
39
+ },
40
+ reconnectPeriod: {
41
+ type: "integer"
42
+ },
43
+ username: {
44
+ type: "string"
45
+ },
46
+ password: {
47
+ type: "string",
48
+ private: true
36
49
  }
37
50
  }),
38
51
  Service.configurationAttributes
@@ -46,6 +59,27 @@ export class ServiceMQTT extends Service {
46
59
  return `${this.name}(${this.url})`;
47
60
  }
48
61
 
62
+ get options() {
63
+ return Object.fromEntries(
64
+ [
65
+ "username",
66
+ "password",
67
+ "clean",
68
+ "clientId",
69
+ "connectTimeout",
70
+ "reconnectPeriod"
71
+ ]
72
+ .filter(key => this[key] !== undefined)
73
+ .map(key => [key, this[key]])
74
+ );
75
+
76
+ //return { username: this.username, password: this.password };
77
+ }
78
+
79
+ get topics() {
80
+ return Object.keys(this.endpoints).filter(e => e.topic);
81
+ }
82
+
49
83
  /**
50
84
  * On demand create TopicEndpoint.
51
85
  * @param {string} name
@@ -53,13 +87,7 @@ export class ServiceMQTT extends Service {
53
87
  * @return {Class} TopicEndpoint if path is present of name starts with '/'
54
88
  */
55
89
  endpointFactoryFromConfig(name, definition, ic) {
56
-
57
- if (
58
- definition.method ||
59
- definition.path ||
60
- name[0] === "/" ||
61
- name.match(/^\w+:\//)
62
- ) {
90
+ if (definition.topic) {
63
91
  return TopicEndpoint;
64
92
  }
65
93
 
@@ -69,7 +97,25 @@ export class ServiceMQTT extends Service {
69
97
  async _start() {
70
98
  await super._start();
71
99
 
72
- this.client = connect(this.url);
100
+ console.log(this.options);
101
+ const client = connect(this.url, this.options);
102
+
103
+ this.client = client;
104
+
105
+ client.on("connect", err => {
106
+ client.subscribe(this.topics, (err, granted) => {
107
+ if (err) {
108
+ this.error(err);
109
+ }
110
+ });
111
+ });
112
+
113
+ client.on("message", (topic, message) => {
114
+ const ep = this.endpoints[topic];
115
+ if (ep) {
116
+ ep.receive(message);
117
+ }
118
+ });
73
119
  }
74
120
 
75
121
  async _stop() {
@@ -1,6 +1,16 @@
1
-
2
1
  import { SendReceiveEndpoint } from "@kronos-integration/endpoint";
3
2
  import { Service } from "@kronos-integration/service";
4
3
 
5
4
  export class TopicEndpoint extends SendReceiveEndpoint {
6
- }
5
+ constructor(name, owner, options) {
6
+ super(name, owner, options);
7
+
8
+ if (options.topic) {
9
+ this._topic = options.topic;
10
+ }
11
+ }
12
+
13
+ get topic() {
14
+ return this._topic || this.name;
15
+ }
16
+ }
@@ -1,13 +1,8 @@
1
1
  import test from "ava";
2
2
 
3
3
  import { ReceiveEndpoint } from "@kronos-integration/endpoint";
4
- import {
5
- StandaloneServiceProvider,
6
- } from "@kronos-integration/service";
7
- import {
8
- ServiceMQTT, TopicEndpoint
9
- } from "@kronos-integration/service-mqtt";
10
-
4
+ import { StandaloneServiceProvider } from "@kronos-integration/service";
5
+ import { ServiceMQTT, TopicEndpoint } from "@kronos-integration/service-mqtt";
11
6
 
12
7
  test("endpoint factory", async t => {
13
8
  const sp = new StandaloneServiceProvider();
@@ -17,14 +12,13 @@ test("endpoint factory", async t => {
17
12
 
18
13
  const mqtt = await sp.declareService({
19
14
  type: ServiceMQTT,
20
- listen: {
21
- socket: 1241
22
- },
23
15
  endpoints: {
24
- "/s1": { connected: r1,}
16
+ s1: { topic: "s1", connected: r1 }
25
17
  }
26
18
  });
27
19
 
28
- t.is(mqtt.endpoints["/s1"].name, "/s1");
29
- t.true(mqtt.endpoints["/s1"] instanceof TopicEndpoint);
20
+ t.is(mqtt.endpoints["s1"].name, "s1");
21
+ t.true(mqtt.endpoints["s1"] instanceof TopicEndpoint);
22
+
23
+ // t.deepEqual(mqtt.topics, ["s1"]);
30
24
  });
@@ -3,6 +3,10 @@ export { TopicEndpoint };
3
3
  * MQTT client.
4
4
  */
5
5
  export class ServiceMQTT extends Service {
6
+ get options(): {
7
+ [k: string]: any;
8
+ };
9
+ get topics(): string[];
6
10
  /**
7
11
  * On demand create TopicEndpoint.
8
12
  * @param {string} name
@@ -1,3 +1,6 @@
1
1
  export class TopicEndpoint extends SendReceiveEndpoint {
2
+ constructor(name: any, owner: any, options: any);
3
+ _topic: any;
4
+ get topic(): any;
2
5
  }
3
6
  import { SendReceiveEndpoint } from "@kronos-integration/endpoint";