mqtt 5.10.2 → 5.10.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.
Files changed (53) hide show
  1. package/README.md +11 -1
  2. package/build/bin/mqtt.js.map +1 -1
  3. package/build/bin/pub.js +1 -1
  4. package/build/bin/pub.js.map +1 -1
  5. package/build/bin/sub.js +1 -1
  6. package/build/bin/sub.js.map +1 -1
  7. package/build/index.js +17 -7
  8. package/build/index.js.map +1 -1
  9. package/build/lib/BufferedDuplex.js +3 -3
  10. package/build/lib/BufferedDuplex.js.map +1 -1
  11. package/build/lib/KeepaliveManager.js.map +1 -1
  12. package/build/lib/client.d.ts +1 -2
  13. package/build/lib/client.js +17 -7
  14. package/build/lib/client.js.map +1 -1
  15. package/build/lib/connect/ali.js.map +1 -1
  16. package/build/lib/connect/index.js +6 -7
  17. package/build/lib/connect/index.js.map +1 -1
  18. package/build/lib/connect/tls.js.map +1 -1
  19. package/build/lib/connect/ws.js +4 -3
  20. package/build/lib/connect/ws.js.map +1 -1
  21. package/build/lib/connect/wx.js.map +1 -1
  22. package/build/lib/default-message-id-provider.js.map +1 -1
  23. package/build/lib/get-timer.js +17 -7
  24. package/build/lib/get-timer.js.map +1 -1
  25. package/build/lib/handlers/ack.js.map +1 -1
  26. package/build/lib/handlers/auth.js.map +1 -1
  27. package/build/lib/handlers/connack.js +3 -0
  28. package/build/lib/handlers/connack.js.map +1 -1
  29. package/build/lib/handlers/index.js.map +1 -1
  30. package/build/lib/handlers/publish.js.map +1 -1
  31. package/build/lib/handlers/pubrel.js.map +1 -1
  32. package/build/lib/is-browser.js.map +1 -1
  33. package/build/lib/shared.d.ts +0 -1
  34. package/build/lib/shared.js +2 -2
  35. package/build/lib/shared.js.map +1 -1
  36. package/build/lib/store.js.map +1 -1
  37. package/build/lib/topic-alias-recv.js.map +1 -1
  38. package/build/lib/topic-alias-send.js.map +1 -1
  39. package/build/lib/validations.js +2 -3
  40. package/build/lib/validations.js.map +1 -1
  41. package/build/mqtt.js +17 -7
  42. package/build/mqtt.js.map +1 -1
  43. package/build/tsconfig.build.tsbuildinfo +1 -1
  44. package/dist/mqtt.esm.js +8 -5
  45. package/dist/mqtt.js +4474 -5381
  46. package/dist/mqtt.min.js +8 -5
  47. package/package.json +34 -35
  48. package/src/lib/BufferedDuplex.ts +1 -1
  49. package/src/lib/client.ts +7 -1
  50. package/src/lib/connect/index.ts +2 -5
  51. package/src/lib/connect/ws.ts +4 -3
  52. package/src/lib/handlers/connack.ts +3 -0
  53. package/src/lib/shared.ts +1 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mqtt",
3
3
  "description": "A library for the MQTT protocol",
4
- "version": "5.10.2",
4
+ "version": "5.10.4",
5
5
  "contributors": [
6
6
  "Adam Rudd <adamvrr@gmail.com>",
7
7
  "Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
@@ -63,9 +63,9 @@
63
63
  "build:browser": "node esbuild.js",
64
64
  "build": "npm run build:ts && npm run build:browser",
65
65
  "prepare": "npm run build",
66
- "unit-test:node": "node_modules/.bin/nyc node -r esbuild-register test/runTests.ts",
66
+ "unit-test:node": "node -r esbuild-register --test-concurrency 4 --test-reporter=junit --test-reporter-destination=junit.xml --test-reporter=spec --test-reporter-destination=stdout --test test/node/*.ts ",
67
67
  "unit-test:browser": "wtr",
68
- "test:node": "npm run unit-test:node && codecov",
68
+ "test:node": "node_modules/.bin/nyc npm run unit-test:node",
69
69
  "test:browser": "npm run build && npm run unit-test:browser",
70
70
  "test": "npm run test:node",
71
71
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
@@ -111,49 +111,48 @@
111
111
  "net": false
112
112
  },
113
113
  "dependencies": {
114
- "@types/readable-stream": "^4.0.5",
115
- "@types/ws": "^8.5.9",
114
+ "@types/readable-stream": "^4.0.18",
115
+ "@types/ws": "^8.5.14",
116
116
  "commist": "^3.2.0",
117
117
  "concat-stream": "^2.0.0",
118
- "debug": "^4.3.4",
118
+ "debug": "^4.4.0",
119
119
  "help-me": "^5.0.0",
120
- "lru-cache": "^10.0.1",
120
+ "lru-cache": "^10.4.3",
121
121
  "minimist": "^1.2.8",
122
122
  "mqtt-packet": "^9.0.1",
123
123
  "number-allocator": "^1.0.14",
124
- "readable-stream": "^4.4.2",
124
+ "readable-stream": "^4.7.0",
125
125
  "reinterval": "^1.1.0",
126
- "rfdc": "^1.3.0",
126
+ "rfdc": "^1.4.1",
127
127
  "split2": "^4.2.0",
128
- "worker-timers": "^7.1.4",
129
- "ws": "^8.17.1"
128
+ "worker-timers": "^7.1.8",
129
+ "ws": "^8.18.0"
130
130
  },
131
131
  "devDependencies": {
132
- "@esm-bundle/chai": "^4.3.4-fix.0",
132
+ "@esm-bundle/chai": "^4.3.4",
133
133
  "@release-it/conventional-changelog": "^7.0.2",
134
- "@types/chai": "^4.3.10",
135
- "@types/node": "^20.9.0",
136
- "@types/sinon": "^17.0.1",
137
- "@types/tape": "^5.6.4",
138
- "@typescript-eslint/eslint-plugin": "^6.10.0",
139
- "@typescript-eslint/parser": "^6.10.0",
140
- "@web/test-runner": "^0.18.0",
134
+ "@types/chai": "^4.3.20",
135
+ "@types/node": "^20.17.16",
136
+ "@types/sinon": "^17.0.3",
137
+ "@types/tape": "^5.8.1",
138
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
139
+ "@typescript-eslint/parser": "^6.21.0",
140
+ "@web/test-runner": "^0.19.0",
141
141
  "@web/test-runner-playwright": "^0.11.0",
142
142
  "aedes-cli": "^0.8.0",
143
- "chai": "^4.3.10",
144
- "chokidar": "^3.5.3",
145
- "codecov": "^3.8.2",
143
+ "chai": "^4.5.0",
144
+ "chokidar": "^3.6.0",
146
145
  "conventional-changelog-cli": "^4.1.0",
147
146
  "end-of-stream": "^1.4.4",
148
- "esbuild": "^0.19.5",
147
+ "esbuild": "^0.24.2",
149
148
  "esbuild-plugin-polyfill-node": "^0.3.0",
150
- "esbuild-register": "^3.5.0",
151
- "eslint": "^8.53.0",
149
+ "esbuild-register": "^3.6.0",
150
+ "eslint": "^8.57.1",
152
151
  "eslint-config-airbnb-base": "^15.0.0",
153
152
  "eslint-config-airbnb-typescript": "^17.1.0",
154
- "eslint-config-prettier": "^9.0.0",
155
- "eslint-plugin-import": "^2.29.0",
156
- "eslint-plugin-prettier": "^5.0.1",
153
+ "eslint-config-prettier": "^9.1.0",
154
+ "eslint-plugin-import": "^2.31.0",
155
+ "eslint-plugin-prettier": "^5.2.3",
157
156
  "global": "^4.4.0",
158
157
  "leaked-handles": "^5.2.0",
159
158
  "mkdirp": "^3.0.1",
@@ -161,14 +160,14 @@
161
160
  "mqtt-level-store": "^3.1.0",
162
161
  "nyc": "^15.1.0",
163
162
  "pre-commit": "^1.2.2",
164
- "prettier": "^3.0.3",
165
- "release-it": "^16.2.1",
166
- "rimraf": "^5.0.5",
163
+ "prettier": "^3.4.2",
164
+ "release-it": "^16.3.0",
165
+ "rimraf": "^5.0.10",
167
166
  "should": "^13.2.3",
168
- "sinon": "^17.0.1",
167
+ "sinon": "^17.0.2",
169
168
  "snazzy": "^9.0.0",
170
- "tape": "^5.7.2",
171
- "ts-node": "^10.9.1",
172
- "typescript": "^5.2.2"
169
+ "tape": "^5.9.0",
170
+ "ts-node": "^10.9.2",
171
+ "typescript": "^5.7.3"
173
172
  }
174
173
  }
@@ -56,7 +56,7 @@ export class BufferedDuplex extends Duplex {
56
56
  this.isSocketOpen = false
57
57
 
58
58
  this.proxy.on('data', (chunk) => {
59
- if (!this.destroyed) {
59
+ if (!this.destroyed && this.readable) {
60
60
  this.push(chunk)
61
61
  }
62
62
  })
package/src/lib/client.ts CHANGED
@@ -162,6 +162,12 @@ export interface IClientOptions extends ISecureClientOptions {
162
162
  * 1000 milliseconds, interval between two reconnections
163
163
  */
164
164
  reconnectPeriod?: number
165
+ /**
166
+ * Set to true to enable the reconnect period to apply if the initial
167
+ * connection is denied with an error in the CONNACK packet, such as with an
168
+ * authentication error.
169
+ */
170
+ reconnectOnConnackError?: boolean
165
171
  /**
166
172
  * 30 * 1000 milliseconds, time to wait before a CONNACK is received
167
173
  */
@@ -565,7 +571,7 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
565
571
  ? options.customHandleAcks
566
572
  : (...args) => {
567
573
  args[3](null, 0)
568
- }
574
+ }
569
575
 
570
576
  // Disable pre-generated write cache if requested. Will allocate buffers on-the-fly instead. WARNING: This can affect write performance
571
577
  if (!this.options.writeCache) {
@@ -72,17 +72,14 @@ function connect(
72
72
  parsedOptions.protocol = parsedUrl.protocol as MqttProtocol
73
73
  parsedOptions.path = parsedUrl.path
74
74
 
75
- parsedOptions.protocol = parsedOptions.protocol?.replace(
76
- /:$/,
77
- '',
78
- ) as MqttProtocol
79
-
80
75
  opts = { ...parsedOptions, ...opts }
81
76
 
82
77
  // when parsing an url expect the protocol to be set
83
78
  if (!opts.protocol) {
84
79
  throw new Error('Missing protocol')
85
80
  }
81
+
82
+ opts.protocol = opts.protocol.replace(/:$/, '') as MqttProtocol
86
83
  }
87
84
 
88
85
  opts.unixSocket = opts.unixSocket || opts.protocol?.includes('+unix')
@@ -257,14 +257,15 @@ const browserStreamBuilder: StreamBuilder = (client, opts) => {
257
257
  * https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/message_event
258
258
  */
259
259
  async function onMessage(event: MessageEvent) {
260
+ if (!proxy || proxy.destroyed || !proxy.readable) {
261
+ return
262
+ }
260
263
  let { data } = event
261
264
  if (data instanceof ArrayBuffer) data = Buffer.from(data)
262
265
  else if (data instanceof Blob)
263
266
  data = Buffer.from(await new Response(data).arrayBuffer())
264
267
  else data = Buffer.from(data as string, 'utf8')
265
- if (proxy && !proxy.destroyed) {
266
- proxy.push(data)
267
- }
268
+ proxy.push(data)
268
269
  }
269
270
 
270
271
  function socketWriteBrowser(
@@ -49,6 +49,9 @@ const handleConnack: PacketHandler = (client, packet: IConnackPacket) => {
49
49
  rc,
50
50
  )
51
51
  client.emit('error', err)
52
+ if (client.options.reconnectOnConnackError) {
53
+ client['_cleanUp'](true)
54
+ }
52
55
  }
53
56
  }
54
57
 
package/src/lib/shared.ts CHANGED
@@ -81,7 +81,7 @@ export const nextTick =
81
81
  ? process.nextTick
82
82
  : (callback: () => void) => {
83
83
  setTimeout(callback, 0)
84
- }
84
+ }
85
85
 
86
86
  // eslint-disable-next-line @typescript-eslint/no-var-requires
87
87
  export const MQTTJS_VERSION = require('../../package.json').version