hb-nb-tools 2.0.23 → 2.0.25

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/lib/NbClient.js CHANGED
@@ -120,17 +120,19 @@ class NbClient extends HttpClient {
120
120
  }
121
121
  const optionParser = new OptionParser(_params)
122
122
  optionParser
123
- .hostKey('host')
124
- .intKey('timeout', 1, 60)
125
- .stringKey('token')
126
123
  .enumKey('encryption')
127
124
  .enumKeyValue('encryption', 'none')
128
125
  .enumKeyValue('encryption', 'hashedToken')
129
126
  .enumKeyValue('encryption', 'encryptedToken')
127
+ .instanceKey('logger')
128
+ .hostKey('host')
129
+ .intKey('timeout', 1, 60)
130
+ .stringKey('token')
130
131
  .parse(params)
131
132
  super({
132
133
  host: _params.hostname + ':' + _params.port,
133
134
  json: true,
135
+ logger: _params.logger,
134
136
  keepAlive: true,
135
137
  maxSockets: 1,
136
138
  timeout: _params.timeout
@@ -140,7 +142,7 @@ class NbClient extends HttpClient {
140
142
  }
141
143
 
142
144
  get id () { return this._params.id }
143
- get name () { return 'Nuki Bridge ' + this._params.id }
145
+ get name () { return this._params.hostname }
144
146
  get encryption () { return this._params.encryption }
145
147
  get firmware () { return this._params.firmware }
146
148
  get token () { return this._params.token }
@@ -25,13 +25,16 @@ class NbDiscovery extends HttpClient {
25
25
  timeout: 5
26
26
  }
27
27
  const optionParser = new OptionParser(config)
28
- optionParser.intKey('timeout', 1, 60)
29
- optionParser.parse(params)
28
+ optionParser
29
+ .instanceKey('logger')
30
+ .intKey('timeout', 1, 60)
31
+ .parse(params)
30
32
  super({
31
33
  https: true,
32
34
  host: 'api.nuki.io',
33
35
  json: true,
34
36
  keepAlive: false,
37
+ logger: params.logger,
35
38
  name: 'nuki server',
36
39
  path: '/discover',
37
40
  timeout: config.timeout
@@ -48,14 +51,11 @@ class NbDiscovery extends HttpClient {
48
51
  for (const bridge of response.body.bridges) {
49
52
  const client = new HttpClient({
50
53
  host: bridge.ip + ':' + bridge.port,
54
+ logger: this.config.logger,
51
55
  path: '',
52
56
  timeout: this.config.timeout,
53
57
  validStatusCodes: [200, 401]
54
58
  })
55
- client
56
- .on('error', (error) => { this.emit('error', error) })
57
- .on('request', (request) => { this.emit('request', request) })
58
- .on('response', (response) => { this.emit('response', response) })
59
59
  try {
60
60
  await client.get('/info')
61
61
  bridges.push(bridge)
package/lib/NbTool.js CHANGED
@@ -316,6 +316,7 @@ class NbTool extends CommandLineTool {
316
316
  const clargs = {
317
317
  options: {
318
318
  host: process.env.NB_HOST,
319
+ logger: this,
319
320
  timeout: 5,
320
321
  token: process.env.NB_TOKEN
321
322
  }
@@ -323,13 +324,7 @@ class NbTool extends CommandLineTool {
323
324
  parser
324
325
  .help('h', 'help', help.nb)
325
326
  .version('V', 'version')
326
- .flag('D', 'debug', () => {
327
- if (this.debugEnabled) {
328
- this.setOptions({ vdebug: true })
329
- } else {
330
- this.setOptions({ debug: true, chalk: true })
331
- }
332
- })
327
+ .debug('D', 'debug', this)
333
328
  .option('H', 'host', (value) => {
334
329
  OptionParser.toHost('host', value, false, true)
335
330
  clargs.options.host = value
@@ -368,38 +363,9 @@ class NbTool extends CommandLineTool {
368
363
  this.jsonFormatter = new JsonFormatter({ sortKeys: true })
369
364
  if (clargs.command === 'discover') {
370
365
  this.nbDiscovery = new NbDiscovery({
366
+ logger: this,
371
367
  timeout: clargs.options.timeout
372
368
  })
373
- this.nbDiscovery
374
- .on('error', (error) => {
375
- this.log(
376
- '%s: request %d: %s %s', error.request.name, error.request.id,
377
- error.request.method, error.request.resource
378
- )
379
- this.warn(
380
- '%s: request %d: error: %s', error.request.name, error.request.id, error
381
- )
382
- })
383
- .on('request', (request) => {
384
- this.debug(
385
- '%s: request %d: %s %s', request.name, request.id,
386
- request.method, request.resource
387
- )
388
- this.vdebug(
389
- '%s: request %d: %s %s', request.name, request.id,
390
- request.method, request.url
391
- )
392
- })
393
- .on('response', (response) => {
394
- this.vdebug(
395
- '%s: request %d: response: %j', response.request.name, response.request.id,
396
- response.body
397
- )
398
- this.debug(
399
- '%s: request %d: %d %s', response.request.name, response.request.id,
400
- response.statusCode, response.statusMessage
401
- )
402
- })
403
369
  } else {
404
370
  if (clargs.options.host == null) {
405
371
  await this.fatal(`Missing host. Set ${b('NB_HOST')} or specify ${b('-H')}.`)
@@ -407,38 +373,7 @@ class NbTool extends CommandLineTool {
407
373
  if (clargs.command === 'auth') {
408
374
  clargs.options.timeout = 60
409
375
  }
410
- const name = clargs.options.host
411
376
  this.client = new NbClient(clargs.options)
412
- this.client
413
- .on('error', (error) => {
414
- this.log(
415
- '%s: request %d: %s %s', name, error.request.id,
416
- error.request.method, error.request.resource
417
- )
418
- this.warn(
419
- '%s: request %d: error: %s', name, error.request.id, error
420
- )
421
- })
422
- .on('request', (request) => {
423
- this.debug(
424
- '%s: request %d: %s %s', name, request.id,
425
- request.method, request.resource
426
- )
427
- this.vdebug(
428
- '%s: request %d: %s %s', name, request.id,
429
- request.method, request.url
430
- )
431
- })
432
- .on('response', (response) => {
433
- this.vdebug(
434
- '%s: request %d: response: %j', name, response.request.id,
435
- response.body
436
- )
437
- this.debug(
438
- '%s: request %d: %d %s', name, response.request.id,
439
- response.statusCode, response.statusMessage
440
- )
441
- })
442
377
  if (clargs.options.token == null && clargs.command !== 'auth') {
443
378
  let args = ''
444
379
  if (clargs.options.host !== process.env.NB_HOST) {
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "ebaauw"
7
7
  ],
8
8
  "license": "Apache-2.0",
9
- "version": "2.0.23",
9
+ "version": "2.0.25",
10
10
  "type": "module",
11
11
  "exports": {
12
12
  "./*": "./lib/*.js"
@@ -26,10 +26,10 @@
26
26
  "nb": "cli/nb.js"
27
27
  },
28
28
  "engines": {
29
- "node": "^24||^22||^20"
29
+ "node": "^24||^22"
30
30
  },
31
31
  "dependencies": {
32
- "hb-lib-tools": "~2.2.17",
32
+ "hb-lib-tools": "~3.0.5",
33
33
  "tweetnacl": "~1.0.3"
34
34
  },
35
35
  "scripts": {