@mysetup/mqtt 2.0.1 → 2.0.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.
package/README.md CHANGED
@@ -1,82 +1,68 @@
1
- # @mysetup/mqtt-client
1
+ # @mysetup/mqtt
2
2
 
3
- A utility for managing MQTT connections, subscriptions, publishing, and client caching, built on top of the [mqtt](https://www.npmjs.com/package/mqtt) library.
4
-
5
- ## Features
6
-
7
- - Connect to MQTT brokers with custom configuration
8
- - Subscribe and unsubscribe to topics
9
- - Publish messages to topics
10
- - Handle connection events (connect, error, reconnect, close, offline)
11
- - Cache and reuse MQTT clients by `clientId`
12
- - Custom message callbacks
13
- - Integration with a logger and cache system
3
+ MQTT helpers for creating connections, subscribing, publishing, and reusing clients.
14
4
 
15
5
  ## Installation
16
6
 
17
- ```sh
18
- npm install @mysetup/mqtt-client
7
+ ```bash
8
+ pnpm add @mysetup/mqtt
19
9
  ```
20
10
 
11
+ ## Supported libraries and runtimes
12
+
13
+ | Supported | Notes |
14
+ | ---------------------- | ------------------------------- |
15
+ | Node.js | Full support |
16
+ | Next.js server runtime | Supported in backend-only usage |
17
+ | Browser apps | Not supported |
18
+
21
19
  ## Usage
22
20
 
23
- ```sh
24
- import { mqttCreateConnection, mqttSub, mqttPublish, mqttDisconnect } from "@mysetup/mqtt-client";
21
+ ```ts
22
+ import {
23
+ mqttCreateConnection,
24
+ mqttDisconnect,
25
+ mqttPublish,
26
+ mqttSub,
27
+ } from "@mysetup/mqtt";
25
28
 
26
- const clientId = "myClientId";
29
+ const clientId = "app-client";
27
30
  const config = {
28
31
  protocol: "mqtt",
29
32
  host: "localhost",
30
33
  port: 1883,
31
34
  path: "",
32
- username: "user",
33
- password: "pass",
34
35
  };
35
36
 
36
- const topicList = ["my/topic"];
37
-
38
37
  mqttCreateConnection({
39
38
  clientId,
40
39
  config,
41
- topicList,
42
- messageCallback: (topic, message) => {
43
- console.log(`Received on ${topic}: ${message}`);
40
+ topicList: ["updates/topic"],
41
+ messageCallback: (topic, payload) => {
42
+ console.log(topic, payload);
44
43
  },
45
- environment: "development", // Optional: enables verbose logging
46
- });
47
-
48
- // Subscribe to topics
49
- mqttSub(topicList, clientId, (topic, message) => {
50
- console.log(`Received: ${message} on ${topic}`);
44
+ environment: "development",
51
45
  });
52
46
 
53
- // Publish a message
54
- mqttPublish("my/topic", { hello: "world" }, clientId);
55
-
56
- // Disconnect
57
- mqttDisconnect({ clientId, config, topicList }, false);
47
+ mqttSub(["updates/topic"], clientId);
48
+ mqttPublish("updates/topic", { hello: "world" }, clientId);
49
+ mqttDisconnect(
50
+ {
51
+ clientId,
52
+ config,
53
+ topicList: ["updates/topic"],
54
+ messageCallback: () => {},
55
+ },
56
+ false,
57
+ );
58
58
  ```
59
59
 
60
- ## Functions
61
-
62
- - mqttCreateConnection(props: ConnectionProps): MqttClient
63
- Creates or retrieves a cached MQTT client and connects to the broker.
64
-
65
- - mqttSub(topicList, clientId, messageCallback?, environment?)
66
- Subscribes to the given topics for the specified client.
67
-
68
- - mqttUnSub(topicList, clientId, environment?)
69
- Unsubscribes from the given topics for the specified client.
70
-
71
- - mqttPublish(topic, message, clientId, environment?)
72
- Publishes a message to a topic.
73
-
74
- - mqttDisconnect(props, reinit, environment?)
75
- Disconnects the client and optionally reinitializes the connection.
76
-
77
- - getMqttClient(clientId)
78
- Retrieves the cached MQTT client by ID.
79
-
80
- ## License
60
+ ## Exports
81
61
 
82
- MIT
62
+ - `mqttCreateConnection`
63
+ - `mqttSub`
64
+ - `mqttUnSub`
65
+ - `mqttPublish`
66
+ - `mqttDisconnect`
67
+ - `getMqttClient`
68
+ - `removeMqttClient`
package/dist/index.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  export * from "./mqttClient";
2
- //# sourceMappingURL=index.d.ts.map
@@ -25,4 +25,3 @@ declare const getMqttClient: (id: string) => mqtt.MqttClient | null;
25
25
  declare const removeMqttClient: (id: string) => void;
26
26
  export { mqttCreateConnection, mqttSub, mqttUnSub, mqttDisconnect, mqttPublish, getMqttClient, removeMqttClient, };
27
27
  export type { ConnectionProps, MqttConfigProps, MqttClient };
28
- //# sourceMappingURL=mqttClient.d.ts.map
package/package.json CHANGED
@@ -1,45 +1,58 @@
1
1
  {
2
- "name": "@mysetup/mqtt",
3
- "version": "2.0.1",
4
- "license": "MIT",
5
- "main": "dist/index.js",
6
- "files": [
7
- "dist"
8
- ],
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.js"
14
- },
15
- "./package.json": "./package.json"
2
+ "name": "@mysetup/mqtt",
3
+ "version": "2.0.4",
4
+ "description": "MQTT client helpers for Node.js applications.",
5
+ "author": "krishnaraj <krishnaraj.webdev@gmail.com>",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "mqtt",
9
+ "iot",
10
+ "nodejs",
11
+ "typescript",
12
+ "messaging"
13
+ ],
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "main": "dist/index.js",
18
+ "types": "dist/index.d.ts",
19
+ "sideEffects": false,
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "import": "./dist/index.js",
27
+ "require": "./dist/index.js"
16
28
  },
17
- "scripts": {
18
- "dev": "nodemon",
19
- "lint": "eslint .",
20
- "typecheck": "tsc --noEmit",
21
- "build": "rm -rf ./dist && tsc",
22
- "format": "prettier --write \"**/*.{ts,tsx,md,js}\"",
23
- "checks": "pnpm typecheck && pnpm lint",
24
- "clean": "rm -rf node_modules .swc dist pnpm-lock.yaml && echo \"✅ Successfully removed \""
25
- },
26
- "dependencies": {
27
- "mqtt": "^5.10.3"
28
- },
29
- "devDependencies": {
30
- "@mysetup/cache": "latest",
31
- "@mysetup/eslint-config": "latest",
32
- "@mysetup/logger": "latest",
33
- "@mysetup/prettier-config": "latest",
34
- "@mysetup/tsconfig": "latest",
35
- "@types/node": "^22.16.4",
36
- "nodemon": "3.1.7",
37
- "ts-node": "^10.9.2",
38
- "typescript": "5.5.4"
39
- },
40
- "prettier": "@mysetup/prettier-config",
41
- "engines": {
42
- "node": ">=20.15.1"
43
- },
44
- "packageManager": "pnpm@9.9.0"
45
- }
29
+ "./package.json": "./package.json"
30
+ },
31
+ "dependencies": {
32
+ "mqtt": "^5.10.3",
33
+ "@mysetup/logger": "^2.0.4",
34
+ "@mysetup/cache": "^2.0.4"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^22.16.4",
38
+ "nodemon": "3.1.7",
39
+ "ts-node": "^10.9.2",
40
+ "typescript": "5.5.4",
41
+ "@mysetup/eslint-config": "^2.0.5",
42
+ "@mysetup/tsconfig": "^2.0.4",
43
+ "@mysetup/prettier-config": "^2.0.4"
44
+ },
45
+ "prettier": "@mysetup/prettier-config",
46
+ "engines": {
47
+ "node": ">=20.15.1"
48
+ },
49
+ "scripts": {
50
+ "dev": "nodemon",
51
+ "lint": "node ../scripts/run-eslint.cjs .",
52
+ "typecheck": "tsc --noEmit",
53
+ "build": "node ../scripts/package-fs.cjs remove dist && tsc -p tsconfig.build.json",
54
+ "format": "prettier --write \"**/*.{ts,tsx,md,js}\"",
55
+ "checks": "pnpm typecheck && pnpm lint && pnpm build",
56
+ "clean": "node ../scripts/package-fs.cjs remove node_modules .swc dist pnpm-lock.yaml && echo \"Cleaned\""
57
+ }
58
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"mqttClient.d.ts","sourceRoot":"","sources":["../mqttClient.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGvC,KAAK,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,KAAK,CAAC;AAEp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../test/test-mqtt.ts"],"names":[],"mappings":""}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var logger_1 = require("@mysetup/logger");
4
- var mqttClient_1 = require("../mqttClient");
5
- var _a = process.env, ENVIRONMENT = _a.ENVIRONMENT, MQTT_HOST = _a.MQTT_HOST, MQTT_USERNAME = _a.MQTT_USERNAME, MQTT_PASSWORD = _a.MQTT_PASSWORD, MQTT_PORT = _a.MQTT_PORT;
6
- var CLIENT_ID = "testClient-".concat(Math.random().toString(16).slice(2, 8));
7
- (0, mqttClient_1.mqttCreateConnection)({
8
- clientId: CLIENT_ID,
9
- config: {
10
- host: String(MQTT_HOST),
11
- port: Number(MQTT_PORT),
12
- protocol: "mqtts",
13
- path: "",
14
- username: MQTT_USERNAME,
15
- password: MQTT_PASSWORD,
16
- },
17
- environment: String(ENVIRONMENT),
18
- topicList: ["#"],
19
- messageCallback: function (topic, message) {
20
- logger_1.logger.info("Message received \u2192 topic: ".concat(topic, ", message: ").concat(message.toString()));
21
- },
22
- });