hb-nb-tools 1.1.12 → 2.0.0-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/cli/nb.js CHANGED
@@ -5,9 +5,6 @@
5
5
  // Command line interface to Nuki bridge HTTP API.
6
6
  // Copyright © 2018-2024 Erik Baauw. All rights reserved.
7
7
 
8
- 'use strict'
8
+ import { NbTool } from '../index.js'
9
9
 
10
- const { NbTool } = require('../index')
11
- const pkgJson = require('../package.json')
12
-
13
- new NbTool(pkgJson).main()
10
+ new NbTool(import.meta.dirname).main()
package/index.js CHANGED
@@ -3,36 +3,34 @@
3
3
  // Homebridge NB Tools.
4
4
  // Copyright © 2017-2024 Erik Baauw. All rights reserved.
5
5
 
6
- 'use strict'
7
-
8
6
  /** Homebridge NB Tools.
9
7
  *
10
8
  * @module hbNbTools
11
9
  */
12
- class hbNbTools {
13
- /** Colour conversions.
14
- * <br>See {@link NbClient}.
15
- * @type {Class}
16
- * @memberof module:hbNbTools
17
- */
18
- static get NbClient () { return require('./lib/NbClient') }
19
10
 
20
- /** Parser and validator for command-line arguments.
21
- * <br>See {@link NbDiscovery}.
22
- * @type {Class}
23
- * @memberof module:hbNbTools
24
- */
25
- static get NbDiscovery () { return require('./lib/NbDiscovery') }
11
+ /** Nuki bridge HTTP API client.
12
+ * <br>See {@link NbClient}.
13
+ * @name NbClient
14
+ * @type {Class}
15
+ * @memberof module:hbNbTools
16
+ */
17
+ export { NbClient } from './lib/NbClient.js'
26
18
 
27
- /** Command-line tool.
28
- * <br>See {@link NbListener}.
29
- * @type {Class}
30
- * @memberof module:hbNbTools
31
- */
32
- static get NbListener () { return require('./lib/NbListener') }
19
+ /** Parser and validator for command-line arguments.
20
+ * <br>See {@link NbDiscovery}.
21
+ * @name NbDiscovery
22
+ * @type {Class}
23
+ * @memberof module:hbNbTools
24
+ */
25
+ export { NbDiscovery } from './lib/NbDiscovery.js'
33
26
 
34
- // Command-line tools.
35
- static get NbTool () { return require('./lib/NbTool') }
36
- }
27
+ /** Command-line tool.
28
+ * <br>See {@link NbListener}.
29
+ * @name NbListener
30
+ * @type {Class}
31
+ * @memberof module:hbNbTools
32
+ */
33
+ export { NbListener } from './lib/NbListener.js'
37
34
 
38
- module.exports = hbNbTools
35
+ // Command-line tools.
36
+ export { NbTool } from './lib/NbTool.js'
package/lib/NbClient.js CHANGED
@@ -3,11 +3,12 @@
3
3
  //
4
4
  // Homebridge NB Tools.
5
5
 
6
- 'use strict'
6
+ import { createHash, randomInt } from 'node:crypto'
7
+ import tweetnacl from 'tweetnacl'
7
8
 
8
- const crypto = require('crypto')
9
- const { HttpClient, JsonFormatter, OptionParser, toHexString } = require('hb-lib-tools')
10
- const { secretbox, randomBytes } = require('tweetnacl')
9
+ import { HttpClient, JsonFormatter, OptionParser, toHexString } from 'hb-lib-tools'
10
+
11
+ const { secretbox, randomBytes } = tweetnacl
11
12
 
12
13
  class NbClient extends HttpClient {
13
14
  static get DeviceTypes () {
@@ -191,17 +192,17 @@ class NbClient extends HttpClient {
191
192
  const ts = date.slice(0, 19) + 'Z'
192
193
  if (this._params.encryption === 'encryptedToken') {
193
194
  if (this._key == null) {
194
- const hash = crypto.createHash('sha256')
195
+ const hash = createHash('sha256')
195
196
  hash.update(this._params.token)
196
197
  this._key = hash.digest()
197
198
  }
198
- const rnr = crypto.randomInt(10000)
199
+ const rnr = randomInt(10000)
199
200
  const nonce = Buffer.from(randomBytes(secretbox.nonceLength))
200
201
  const message = Buffer.from([ts, rnr].join(','), 'utf-8')
201
202
  const ctoken = Buffer.from(secretbox(message, nonce, this._key))
202
203
  suffix = separator + 'ctoken=' + ctoken.toString('hex') + '&nonce=' + nonce.toString('hex')
203
204
  } else if (this._params.encryption === 'hashedToken') { // deprecated
204
- const hash = crypto.createHash('sha256')
205
+ const hash = createHash('sha256')
205
206
  const rnr = Number(date[18] + date.slice(20, 23))
206
207
  hash.update([ts, rnr, this._params.token].join(','))
207
208
  suffix = separator + 'ts=' + ts + '&rnr=' + rnr +
@@ -213,4 +214,4 @@ class NbClient extends HttpClient {
213
214
  }
214
215
  }
215
216
 
216
- module.exports = NbClient
217
+ export { NbClient }
@@ -3,10 +3,7 @@
3
3
  //
4
4
  // Homebridge NB Tools.
5
5
 
6
- 'use strict'
7
-
8
- const hbLibTools = require('hb-lib-tools')
9
- const { HttpClient, OptionParser } = hbLibTools
6
+ import { HttpClient, OptionParser } from 'hb-lib-tools'
10
7
 
11
8
  class NbDiscovery extends HttpClient {
12
9
  constructor (params = {}) {
@@ -54,4 +51,4 @@ class NbDiscovery extends HttpClient {
54
51
  }
55
52
  }
56
53
 
57
- module.exports = NbDiscovery
54
+ export { NbDiscovery }
package/lib/NbListener.js CHANGED
@@ -3,20 +3,20 @@
3
3
  //
4
4
  // Homebridge NB Tools.
5
5
 
6
- 'use strict'
6
+ import { EventEmitter } from 'node:events'
7
+ import { createServer } from 'node:http'
7
8
 
8
- const events = require('events')
9
- const http = require('http')
10
- const NbClient = require('./NbClient')
11
- const { OptionParser } = require('hb-lib-tools')
9
+ import { OptionParser } from 'hb-lib-tools'
12
10
 
13
- class NbListener extends events.EventEmitter {
11
+ import { NbClient } from '../index.js'
12
+
13
+ class NbListener extends EventEmitter {
14
14
  constructor (port = 0) {
15
15
  super()
16
16
  this._myPort = port
17
17
  this._clients = {}
18
18
  this._clientsByName = {}
19
- this._server = http.createServer((request, response) => {
19
+ this._server = createServer((request, response) => {
20
20
  let buffer = ''
21
21
  request.on('data', (data) => {
22
22
  buffer += data
@@ -106,4 +106,4 @@ class NbListener extends events.EventEmitter {
106
106
  }
107
107
  }
108
108
 
109
- module.exports = NbListener
109
+ export { NbListener }
package/lib/NbTool.js CHANGED
@@ -3,14 +3,12 @@
3
3
  //
4
4
  // Command line interface to Nuki bridge HTTP API.
5
5
 
6
- 'use strict'
6
+ import {
7
+ CommandLineParser, CommandLineTool, JsonFormatter, OptionParser
8
+ } from 'hb-lib-tools'
7
9
 
8
- const NbClient = require('./NbClient')
9
- const NbDiscovery = require('./NbDiscovery')
10
- const NbListener = require('./NbListener')
11
- const hbLibTools = require('hb-lib-tools')
10
+ import { NbClient, NbDiscovery, NbListener } from '../index.js'
12
11
 
13
- const { CommandLineParser, CommandLineTool, JsonFormatter, OptionParser } = hbLibTools
14
12
  const { b, u } = CommandLineTool
15
13
  const { UsageError } = CommandLineParser
16
14
 
@@ -641,4 +639,4 @@ class NbTool extends CommandLineTool {
641
639
  }
642
640
  }
643
641
 
644
- module.exports = NbTool
642
+ export { NbTool }
package/package.json CHANGED
@@ -3,7 +3,9 @@
3
3
  "description": "Homebridge NB Tools",
4
4
  "author": "Erik Baauw",
5
5
  "license": "Apache-2.0",
6
- "version": "1.1.12",
6
+ "version": "2.0.0-0",
7
+ "type": "module",
8
+ "main": "index.js",
7
9
  "keywords": [
8
10
  "nuki",
9
11
  "smart-lock",
@@ -17,7 +19,7 @@
17
19
  "node": "^20||^18"
18
20
  },
19
21
  "dependencies": {
20
- "hb-lib-tools": "~1.2.3",
22
+ "hb-lib-tools": "~2.0.0-0",
21
23
  "tweetnacl": "~1.0.3"
22
24
  },
23
25
  "scripts": {