iobroker.admin 7.1.1 → 7.1.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.
Files changed (71) hide show
  1. package/README.md +5 -8
  2. package/adminWww/asset-manifest.json +33 -33
  3. package/adminWww/index.html +1 -1
  4. package/adminWww/static/css/3210.f6c8a5fc.chunk.css.map +1 -1
  5. package/adminWww/static/js/2534.d8fd195b.chunk.js +2 -0
  6. package/adminWww/static/js/2534.d8fd195b.chunk.js.map +1 -0
  7. package/adminWww/static/js/2544.047df092.chunk.js +2 -0
  8. package/adminWww/static/js/2544.047df092.chunk.js.map +1 -0
  9. package/adminWww/static/js/2816.f7bf6ba0.chunk.js +2 -0
  10. package/adminWww/static/js/2816.f7bf6ba0.chunk.js.map +1 -0
  11. package/adminWww/static/js/3210.1be726e7.chunk.js +2 -0
  12. package/adminWww/static/js/3210.1be726e7.chunk.js.map +1 -0
  13. package/adminWww/static/js/4112.9b241792.chunk.js +2 -0
  14. package/adminWww/static/js/4112.9b241792.chunk.js.map +1 -0
  15. package/adminWww/static/js/4579.014de1f1.chunk.js +2 -0
  16. package/adminWww/static/js/4579.014de1f1.chunk.js.map +1 -0
  17. package/adminWww/static/js/{5174.60f22386.chunk.js → 5174.f5aa1074.chunk.js} +2 -2
  18. package/adminWww/static/js/5174.f5aa1074.chunk.js.map +1 -0
  19. package/adminWww/static/js/530.cb8dbcf9.chunk.js +2 -0
  20. package/adminWww/static/js/530.cb8dbcf9.chunk.js.map +1 -0
  21. package/adminWww/static/js/6552.0a447e18.chunk.js +2 -0
  22. package/adminWww/static/js/6552.0a447e18.chunk.js.map +1 -0
  23. package/adminWww/static/js/6938.af058182.chunk.js +2 -0
  24. package/adminWww/static/js/6938.af058182.chunk.js.map +1 -0
  25. package/adminWww/static/js/{8038.cacab580.chunk.js → 8038.ae8b7862.chunk.js} +2 -2
  26. package/adminWww/static/js/8038.ae8b7862.chunk.js.map +1 -0
  27. package/adminWww/static/js/858.f34ea2c6.chunk.js +2 -0
  28. package/adminWww/static/js/858.f34ea2c6.chunk.js.map +1 -0
  29. package/adminWww/static/js/9399.5852b7e7.chunk.js +2 -0
  30. package/adminWww/static/js/9399.5852b7e7.chunk.js.map +1 -0
  31. package/adminWww/static/js/9534.2af54084.chunk.js +2 -0
  32. package/adminWww/static/js/9534.2af54084.chunk.js.map +1 -0
  33. package/adminWww/static/js/9917.3662a807.chunk.js +2 -0
  34. package/adminWww/static/js/9917.3662a807.chunk.js.map +1 -0
  35. package/adminWww/static/js/{main.c1384a82.js → main.423e60b6.js} +2 -2
  36. package/adminWww/static/js/main.423e60b6.js.map +1 -0
  37. package/build-backend/lib/passportSocket.js +8 -10
  38. package/build-backend/lib/translations.js +0 -1
  39. package/build-backend/lib/web.js +101 -81
  40. package/build-backend/main.js +173 -184
  41. package/io-package.json +14 -14
  42. package/package.json +97 -96
  43. package/adminWww/static/js/2534.0bc9912f.chunk.js +0 -2
  44. package/adminWww/static/js/2534.0bc9912f.chunk.js.map +0 -1
  45. package/adminWww/static/js/2544.4fa1eef5.chunk.js +0 -2
  46. package/adminWww/static/js/2544.4fa1eef5.chunk.js.map +0 -1
  47. package/adminWww/static/js/2816.cfab0128.chunk.js +0 -2
  48. package/adminWww/static/js/2816.cfab0128.chunk.js.map +0 -1
  49. package/adminWww/static/js/3210.4c1ccdc2.chunk.js +0 -2
  50. package/adminWww/static/js/3210.4c1ccdc2.chunk.js.map +0 -1
  51. package/adminWww/static/js/4112.8c6e6dae.chunk.js +0 -2
  52. package/adminWww/static/js/4112.8c6e6dae.chunk.js.map +0 -1
  53. package/adminWww/static/js/4579.cd86a1cb.chunk.js +0 -2
  54. package/adminWww/static/js/4579.cd86a1cb.chunk.js.map +0 -1
  55. package/adminWww/static/js/5174.60f22386.chunk.js.map +0 -1
  56. package/adminWww/static/js/530.8eed62a7.chunk.js +0 -2
  57. package/adminWww/static/js/530.8eed62a7.chunk.js.map +0 -1
  58. package/adminWww/static/js/6552.29112fa0.chunk.js +0 -2
  59. package/adminWww/static/js/6552.29112fa0.chunk.js.map +0 -1
  60. package/adminWww/static/js/6938.f4331126.chunk.js +0 -2
  61. package/adminWww/static/js/6938.f4331126.chunk.js.map +0 -1
  62. package/adminWww/static/js/8038.cacab580.chunk.js.map +0 -1
  63. package/adminWww/static/js/858.3a130f69.chunk.js +0 -2
  64. package/adminWww/static/js/858.3a130f69.chunk.js.map +0 -1
  65. package/adminWww/static/js/9399.c959c5de.chunk.js +0 -2
  66. package/adminWww/static/js/9399.c959c5de.chunk.js.map +0 -1
  67. package/adminWww/static/js/9534.68ac37f7.chunk.js +0 -2
  68. package/adminWww/static/js/9534.68ac37f7.chunk.js.map +0 -1
  69. package/adminWww/static/js/9917.28c0dbc2.chunk.js +0 -2
  70. package/adminWww/static/js/9917.28c0dbc2.chunk.js.map +0 -1
  71. package/adminWww/static/js/main.c1384a82.js.map +0 -1
@@ -25,7 +25,6 @@ const web_1 = require("./lib/web");
25
25
  const adapterName = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), { encoding: 'utf-8' }))
26
26
  .name.split('.')
27
27
  .pop();
28
- // eslint-disable-next-line @typescript-eslint/no-var-requires
29
28
  const { getInstalledInfo } = utils.commonTools;
30
29
  const ONE_HOUR_MS = 3_600_000;
31
30
  const ERROR_PERMISSION = 'permissionError';
@@ -46,7 +45,6 @@ class Admin extends utils.Adapter {
46
45
  updaterTimeout;
47
46
  ratingTimeout;
48
47
  timerNews;
49
- _running;
50
48
  _tasks;
51
49
  constructor(options = {}) {
52
50
  options = {
@@ -67,8 +65,9 @@ class Admin extends utils.Adapter {
67
65
  }
68
66
  /**
69
67
  * Is called if a subscribed object changes
70
- * @param id
71
- * @param obj
68
+ *
69
+ * @param id object ID that changed
70
+ * @param obj the changed object value
72
71
  */
73
72
  onObjectChange(id, obj) {
74
73
  if (obj) {
@@ -87,7 +86,7 @@ class Admin extends utils.Adapter {
87
86
  }
88
87
  this.updaterTimeout = setTimeout(() => {
89
88
  this.updaterTimeout = null;
90
- this.writeUpdateInfo();
89
+ void this.writeUpdateInfo();
91
90
  }, 5_000);
92
91
  }
93
92
  }
@@ -102,8 +101,9 @@ class Admin extends utils.Adapter {
102
101
  }
103
102
  /**
104
103
  * Is called if a subscribed state was changed
105
- * @param id
106
- * @param state
104
+ *
105
+ * @param id state ID that changed
106
+ * @param state the changed state value
107
107
  */
108
108
  onStateChange(id, state) {
109
109
  if (socket) {
@@ -118,38 +118,38 @@ class Admin extends utils.Adapter {
118
118
  /**
119
119
  * Is called when databases are connected and adapter received configuration.
120
120
  */
121
- onReady() {
122
- this.getForeignObject('system.config', (err, obj) => {
123
- if (!err && obj) {
124
- obj.native = obj.native || {};
125
- if (this.config.language) {
126
- systemLanguage = this.config.language;
127
- }
128
- else if (obj.common?.language) {
129
- systemLanguage = obj.common.language;
130
- }
131
- if (!obj.native.secret) {
132
- crypto.randomBytes(24, (_ex, buf) => {
133
- this.secret = buf.toString('hex');
134
- this.extendForeignObject('system.config', { native: { secret: this.secret } });
135
- this.init();
136
- });
137
- }
138
- else {
139
- this.secret = obj.native.secret;
121
+ async onReady() {
122
+ const systemConfig = await this.getForeignObjectAsync('system.config');
123
+ if (systemConfig) {
124
+ systemConfig.native = systemConfig.native || {};
125
+ if (this.config.language) {
126
+ systemLanguage = this.config.language;
127
+ }
128
+ else if (systemConfig.common?.language) {
129
+ systemLanguage = systemConfig.common.language;
130
+ }
131
+ if (!systemConfig.native.secret) {
132
+ crypto.randomBytes(24, (_ex, buf) => {
133
+ this.secret = buf.toString('hex');
134
+ this.extendForeignObject('system.config', { native: { secret: this.secret } });
140
135
  this.init();
141
- }
136
+ });
142
137
  }
143
138
  else {
144
- this.secret = secret;
145
- this.log.error('Cannot find object system.config');
139
+ this.secret = systemConfig.native.secret;
140
+ this.init();
146
141
  }
147
- });
142
+ }
143
+ else {
144
+ this.secret = secret;
145
+ this.log.error('Cannot find object system.config');
146
+ }
148
147
  }
149
148
  /**
150
149
  * Some message was sent to this instance over the message box. Used by email, pushover, text2speech, ...
151
150
  * Using this method requires "common.messagebox" property to be set to true in io-package.json
152
- * @param obj
151
+ *
152
+ * @param obj the message object
153
153
  */
154
154
  onMessage(obj) {
155
155
  if (!obj) {
@@ -212,7 +212,8 @@ class Admin extends utils.Adapter {
212
212
  }
213
213
  /**
214
214
  * Is called when adapter shuts down - callback has to be called under any circumstances!
215
- * @param callback
215
+ *
216
+ * @param callback Callback after unloading
216
217
  */
217
218
  onUnload(callback) {
218
219
  if (this.timerRepo) {
@@ -248,7 +249,7 @@ class Admin extends utils.Adapter {
248
249
  }
249
250
  async createUpdateInfo() {
250
251
  const promises = [];
251
- // create connected object and state
252
+ // create a connected object and state
252
253
  const updatesNumberObj = objects[`${this.namespace}.info.updatesNumber`];
253
254
  if (!updatesNumberObj || !updatesNumberObj.common || updatesNumberObj.common.type !== 'number') {
254
255
  const obj = {
@@ -276,7 +277,7 @@ class Admin extends utils.Adapter {
276
277
  },
277
278
  native: {},
278
279
  };
279
- this.setObject(obj._id, obj);
280
+ await this.setObject(obj._id, obj);
280
281
  }
281
282
  const updatesListObj = objects[`${this.namespace}.info.updatesList`];
282
283
  if (!updatesListObj || !updatesListObj.common || updatesListObj.common.type !== 'string') {
@@ -305,7 +306,7 @@ class Admin extends utils.Adapter {
305
306
  },
306
307
  native: {},
307
308
  };
308
- this.setObject(obj._id, obj);
309
+ await this.setObject(obj._id, obj);
309
310
  }
310
311
  const newUpdatesObj = objects[`${this.namespace}.info.newUpdates`];
311
312
  if (!newUpdatesObj || !newUpdatesObj.common || newUpdatesObj.common.type !== 'boolean') {
@@ -402,29 +403,30 @@ class Admin extends utils.Adapter {
402
403
  /**
403
404
  * Write the update information to the states
404
405
  */
405
- writeUpdateInfo(
406
+ async writeUpdateInfo(
406
407
  /** current sources, if given */
407
408
  sources) {
408
409
  if (!objects['system.config'] || !objects['system.config'].common) {
409
410
  return this.log.warn('Repository cannot be read. Invalid "system.config" object.');
410
411
  }
411
- const { activeRepo } = objects['system.config'].common;
412
+ const activeRepo = objects['system.config']
413
+ .common?.activeRepo;
412
414
  const systemRepos = objects['system.repositories'];
413
415
  if (!sources) {
414
416
  sources = {};
415
417
  // If multi-repo case
416
418
  if (Array.isArray(activeRepo)) {
417
419
  if (systemRepos?.native?.repositories) {
418
- activeRepo.forEach(repo => {
420
+ for (const repo of activeRepo) {
419
421
  if (systemRepos.native.repositories[repo]?.json) {
420
422
  Object.assign(sources, systemRepos.native.repositories[repo].json);
421
423
  }
422
424
  else {
423
- this.setState('info.updatesNumber', 0, true);
424
- this.setState('info.updatesList', '', true);
425
- this.setState('info.newUpdates', false, true);
426
- this.setState('info.updatesJson', '{}', true);
427
- this.setState('info.lastUpdateCheck', Date.now(), true);
425
+ await this.setState('info.updatesNumber', 0, true);
426
+ await this.setState('info.updatesList', '', true);
427
+ await this.setState('info.newUpdates', false, true);
428
+ await this.setState('info.updatesJson', '{}', true);
429
+ await this.setState('info.lastUpdateCheck', Date.now(), true);
428
430
  if (systemRepos.native.repositories[repo]) {
429
431
  this.log.warn(`Repository cannot be read: Active repo - ${repo}`);
430
432
  }
@@ -432,7 +434,7 @@ class Admin extends utils.Adapter {
432
434
  this.log.warn('No repository source configured');
433
435
  }
434
436
  }
435
- });
437
+ }
436
438
  }
437
439
  }
438
440
  else if (systemRepos?.native?.repositories?.[activeRepo]?.json) {
@@ -440,11 +442,11 @@ class Admin extends utils.Adapter {
440
442
  }
441
443
  }
442
444
  if (!Object.keys(sources).length) {
443
- this.setState('info.updatesNumber', 0, true);
444
- this.setState('info.updatesList', '', true);
445
- this.setState('info.newUpdates', false, true);
446
- this.setState('info.updatesJson', '{}', true);
447
- this.setState('info.lastUpdateCheck', Date.now(), true);
445
+ await this.setState('info.updatesNumber', 0, true);
446
+ await this.setState('info.updatesList', '', true);
447
+ await this.setState('info.newUpdates', false, true);
448
+ await this.setState('info.updatesJson', '{}', true);
449
+ await this.setState('info.lastUpdateCheck', Date.now(), true);
448
450
  if (Array.isArray(activeRepo)) {
449
451
  let found = false;
450
452
  if (systemRepos?.native?.repositories) {
@@ -462,7 +464,7 @@ class Admin extends utils.Adapter {
462
464
  }
463
465
  }
464
466
  else if (systemRepos?.native?.repositories?.[activeRepo]) {
465
- this.log.warn(`Repository cannot be read. Active repo: ${activeRepo}`);
467
+ this.log.warn(`Repository cannot be read. Active repo: "${activeRepo}"`);
466
468
  }
467
469
  else {
468
470
  this.log.warn(`No repository source configured. Possible values: ${systemRepos?.native?.repositories
@@ -475,65 +477,64 @@ class Admin extends utils.Adapter {
475
477
  const list = [];
476
478
  const updatesJson = {};
477
479
  let newUpdateIndicator = false;
478
- this.getState('info.updatesJson', (_err, state) => {
479
- let oldUpdates;
480
- if (typeof state?.val === 'string') {
481
- try {
482
- oldUpdates = JSON.parse(state.val) || {};
483
- }
484
- catch (e) {
485
- oldUpdates = {};
486
- this.log.warn(`Cannot parse info.updatesJson: ${e}`);
487
- }
480
+ const state = await this.getStateAsync('info.updatesJson');
481
+ let oldUpdates;
482
+ if (typeof state?.val === 'string') {
483
+ try {
484
+ oldUpdates = JSON.parse(state.val) || {};
488
485
  }
489
- else {
486
+ catch (e) {
490
487
  oldUpdates = {};
488
+ this.log.warn(`Cannot parse info.updatesJson: ${e}`);
491
489
  }
492
- Object.keys(sources).forEach(name => {
493
- try {
494
- if (installed[name]?.version && sources[name].version) {
495
- if (sources[name].version !== installed[name].version &&
496
- !this.upToDate(sources[name].version, installed[name].version)) {
497
- // Check if updates are new or already known to user
498
- if (!oldUpdates ||
499
- !oldUpdates[name] ||
500
- oldUpdates[name].availableVersion !== sources[name].version) {
501
- newUpdateIndicator = true;
502
- } // endIf
503
- updatesJson[name] = {
504
- availableVersion: sources[name].version,
505
- installedVersion: installed[name].version,
506
- };
507
- // remove first part of the name
508
- const n = name.indexOf('.');
509
- list.push(n === -1 ? name : name.substring(n + 1));
510
- }
490
+ }
491
+ else {
492
+ oldUpdates = {};
493
+ }
494
+ Object.keys(sources).forEach(name => {
495
+ try {
496
+ if (installed[name]?.version && sources[name].version) {
497
+ if (sources[name].version !== installed[name].version &&
498
+ !this.upToDate(sources[name].version, installed[name].version)) {
499
+ // Check if updates are new or already known to user
500
+ if (!oldUpdates ||
501
+ !oldUpdates[name] ||
502
+ oldUpdates[name].availableVersion !== sources[name].version) {
503
+ newUpdateIndicator = true;
504
+ } // endIf
505
+ updatesJson[name] = {
506
+ availableVersion: sources[name].version,
507
+ installedVersion: installed[name].version,
508
+ };
509
+ // remove the first part of the name
510
+ const n = name.indexOf('.');
511
+ list.push(n === -1 ? name : name.substring(n + 1));
511
512
  }
512
513
  }
513
- catch (err) {
514
- this.log.warn(`Error on version check for ${name}: ${err}`);
515
- }
516
- });
517
- this.setState('info.updatesNumber', list.length, true);
518
- this.setState('info.updatesList', list.join(', '), true);
519
- this.setState('info.newUpdates', newUpdateIndicator, true);
520
- this.setState('info.updatesJson', JSON.stringify(updatesJson), true);
521
- this.setState('info.lastUpdateCheck', Date.now(), true);
522
- if (!newUpdateIndicator) {
523
- return;
524
514
  }
525
- const textArr = [];
526
- for (const [adapter, updateInfo] of Object.entries(updatesJson)) {
527
- const text = (0, translations_1.getAdapterUpdateText)({
528
- adapter,
529
- installedVersion: updateInfo.installedVersion,
530
- newVersion: updateInfo.availableVersion,
531
- lang: systemLanguage,
532
- });
533
- textArr.push(text);
515
+ catch (err) {
516
+ this.log.warn(`Error on version check for ${name}: ${err}`);
534
517
  }
535
- this.registerNotification('admin', 'adapterUpdates', textArr.join('\n'));
536
518
  });
519
+ await this.setState('info.updatesNumber', list.length, true);
520
+ await this.setState('info.updatesList', list.join(', '), true);
521
+ await this.setState('info.newUpdates', newUpdateIndicator, true);
522
+ await this.setState('info.updatesJson', JSON.stringify(updatesJson), true);
523
+ await this.setState('info.lastUpdateCheck', Date.now(), true);
524
+ if (!newUpdateIndicator) {
525
+ return;
526
+ }
527
+ const textArr = [];
528
+ for (const [adapter, updateInfo] of Object.entries(updatesJson)) {
529
+ const text = (0, translations_1.getAdapterUpdateText)({
530
+ adapter,
531
+ installedVersion: updateInfo.installedVersion,
532
+ newVersion: updateInfo.availableVersion,
533
+ lang: systemLanguage,
534
+ });
535
+ textArr.push(text);
536
+ }
537
+ await this.registerNotification('admin', 'adapterUpdates', textArr.join('\n'));
537
538
  }
538
539
  initSocket(server, store) {
539
540
  socket = new socket_classes_1.SocketAdmin(this.config, this, objects);
@@ -557,29 +558,11 @@ class Admin extends utils.Adapter {
557
558
  })
558
559
  .catch(error => this.log.error(`Cannot read UUID: ${error}`));
559
560
  }
560
- processTasks() {
561
- if (!this._running && this._tasks.length) {
562
- this._running = true;
563
- const obj = this._tasks.shift();
564
- if (!obj.acl || obj.acl.owner !== this.config.defaultUser) {
565
- obj.acl.owner = this.config.defaultUser;
566
- this.setForeignObject(obj._id, obj, () => setImmediate(() => {
567
- this._running = false;
568
- this.processTasks();
569
- }));
570
- }
571
- else {
572
- setImmediate(() => {
573
- this._running = false;
574
- this.processTasks();
575
- });
576
- }
577
- }
578
- }
579
561
  async applyRightsToObjects(pattern, types) {
562
+ let len = 0;
580
563
  if (typeof types === 'object') {
581
564
  for (const type of types) {
582
- this.applyRightsToObjects(pattern, type);
565
+ len += await this.applyRightsToObjects(pattern, type);
583
566
  }
584
567
  }
585
568
  else {
@@ -590,52 +573,53 @@ class Admin extends utils.Adapter {
590
573
  });
591
574
  this._tasks = this._tasks || [];
592
575
  for (const row of doc.rows) {
593
- this._tasks.push(row.value);
576
+ const obj = row.value;
577
+ if (!obj.acl || obj.acl.owner !== this.config.defaultUser) {
578
+ obj.acl.owner = this.config.defaultUser;
579
+ await this.setForeignObjectAsync(obj._id, obj);
580
+ len++;
581
+ }
594
582
  }
595
- this.processTasks();
596
583
  }
597
584
  catch (e) {
598
585
  this.log.error(`Error applying rights to objects: ${e.message}`);
599
586
  }
600
587
  }
588
+ return len;
601
589
  }
602
- applyRights() {
603
- const promises = [];
590
+ async applyRights() {
604
591
  this.config.accessAllowedConfigs = this.config.accessAllowedConfigs || [];
605
592
  this.config.accessAllowedTabs = this.config.accessAllowedTabs || [];
606
- this.config.accessAllowedConfigs.forEach(id => promises.push(new Promise(resolve => this.getForeignObject(`system.adapter.${id}`, (err, obj) => {
593
+ let len = 0;
594
+ for (const id of this.config.accessAllowedConfigs) {
595
+ const obj = await this.getForeignObjectAsync(`system.adapter.${id}`);
607
596
  if (obj?.acl && obj.acl.owner !== this.config.defaultUser) {
608
597
  obj.acl.owner = this.config.defaultUser;
609
- this.setForeignObject(`system.adapter.${id}`, obj, err => resolve(!err));
598
+ await this.setForeignObjectAsync(`system.adapter.${id}`, obj);
599
+ len++;
610
600
  }
611
- else {
612
- resolve(false);
613
- }
614
- }))));
615
- this.config.accessAllowedTabs.forEach(id => {
601
+ }
602
+ for (const id of this.config.accessAllowedTabs) {
616
603
  if (id.startsWith('devices.')) {
617
- // change rights of all alias.*
618
- this.applyRightsToObjects('alias', ['state', 'channel']);
604
+ // change rights of all `alias.*`
605
+ len += await this.applyRightsToObjects('alias', ['state', 'channel']);
619
606
  }
620
607
  else if (id.startsWith('javascript.')) {
621
608
  // change rights of all script.js.*
622
- this.applyRightsToObjects('javascript', ['script', 'channel']);
609
+ len += await this.applyRightsToObjects('javascript', ['script', 'channel']);
623
610
  }
624
611
  else if (id.startsWith('fullcalendar.')) {
625
612
  // change rights of all fullcalendar.*
626
- this.applyRightsToObjects('fullcalendar', ['schedule']);
613
+ len += await this.applyRightsToObjects('fullcalendar', ['schedule']);
627
614
  }
628
615
  else if (id.startsWith('scenes.')) {
629
616
  // change rights of all scenes.*
630
- this.applyRightsToObjects('scenes', ['state', 'channel']);
631
- }
632
- });
633
- Promise.all(promises).then(results => {
634
- const len = results.filter(r => !!r).length;
635
- if (len) {
636
- this.log.info(`Updated ${len} objects`);
617
+ len += await this.applyRightsToObjects('scenes', ['state', 'channel']);
637
618
  }
638
- });
619
+ }
620
+ if (len) {
621
+ this.log.info(`Updated ${len} objects`);
622
+ }
639
623
  }
640
624
  /**
641
625
  * Read news from server and register them as notifications
@@ -830,8 +814,8 @@ class Admin extends utils.Adapter {
830
814
  /**
831
815
  * Check if adapter is active
832
816
  *
833
- * @param adapterName
834
- * @param instances
817
+ * @param adapterName name of the adapter
818
+ * @param instances list of instances
835
819
  */
836
820
  checkActive(adapterName, instances) {
837
821
  return !!Object.keys(instances)
@@ -841,8 +825,8 @@ class Admin extends utils.Adapter {
841
825
  /**
842
826
  * Check if conditions met
843
827
  *
844
- * @param condition
845
- * @param installedVersion
828
+ * @param condition condition to check
829
+ * @param installedVersion installed version
846
830
  */
847
831
  checkConditions(condition, installedVersion) {
848
832
  if (condition.startsWith('equals')) {
@@ -1161,7 +1145,7 @@ class Admin extends utils.Adapter {
1161
1145
  this.config.tmpPath = tmpPath;
1162
1146
  this.config.tmpPathAllow = true;
1163
1147
  }
1164
- this.createUpdateInfo().then(() => this.writeUpdateInfo());
1148
+ void this.createUpdateInfo().then(() => this.writeUpdateInfo());
1165
1149
  }
1166
1150
  if (callback) {
1167
1151
  callback(this);
@@ -1244,9 +1228,9 @@ class Admin extends utils.Adapter {
1244
1228
  this.timerRepo = null;
1245
1229
  }
1246
1230
  this.log.debug(`Next repo update on ${new Date(Date.now() + this.config.autoUpdate * ONE_HOUR_MS + 1).toLocaleString()}`);
1247
- this.timerRepo = setTimeout(() => {
1231
+ this.timerRepo = setTimeout(async () => {
1248
1232
  this.timerRepo = null;
1249
- this.updateRegister();
1233
+ await this.updateRegister();
1250
1234
  }, this.config.autoUpdate * ONE_HOUR_MS + 1);
1251
1235
  }
1252
1236
  }
@@ -1270,17 +1254,15 @@ class Admin extends utils.Adapter {
1270
1254
  /**
1271
1255
  * Read repository information from active repository
1272
1256
  */
1273
- updateRegister() {
1257
+ async updateRegister() {
1274
1258
  if (lastRepoUpdate && Date.now() - lastRepoUpdate < 3600000) {
1275
1259
  this.log.error('Automatic repository update is not allowed more than once a hour');
1276
1260
  this.restartRepoUpdate();
1277
1261
  return;
1278
1262
  }
1279
1263
  lastRepoUpdate = Date.now();
1280
- this.getForeignObject('system.config', async (err, systemConfig) => {
1281
- if (err) {
1282
- this.log.error('May not read "system.config"');
1283
- }
1264
+ try {
1265
+ const systemConfig = await this.getForeignObjectAsync('system.config');
1284
1266
  if (systemConfig?.common) {
1285
1267
  try {
1286
1268
  const repos = await this.getForeignObjectAsync('system.repositories');
@@ -1294,14 +1276,12 @@ class Admin extends utils.Adapter {
1294
1276
  const active = systemConfig.common.activeRepo;
1295
1277
  // if repo is valid and actual
1296
1278
  if (Array.isArray(active)) {
1297
- if (!err &&
1298
- Date.now() < repos.ts + this.config.autoUpdate * ONE_HOUR_MS &&
1279
+ if (Date.now() < repos.ts + this.config.autoUpdate * ONE_HOUR_MS &&
1299
1280
  !active.find(repo => !repos?.native?.repositories?.[repo]?.json)) {
1300
1281
  exists = true;
1301
1282
  }
1302
1283
  }
1303
- else if (!err &&
1304
- repos?.native?.repositories?.[active]?.json &&
1284
+ else if (repos?.native?.repositories?.[active]?.json &&
1305
1285
  Date.now() < repos.ts + this.config.autoUpdate * ONE_HOUR_MS) {
1306
1286
  exists = true;
1307
1287
  }
@@ -1342,9 +1322,9 @@ class Admin extends utils.Adapter {
1342
1322
  if (this.timerRepo) {
1343
1323
  clearTimeout(this.timerRepo);
1344
1324
  }
1345
- this.timerRepo = setTimeout(() => {
1325
+ this.timerRepo = setTimeout(async () => {
1346
1326
  this.timerRepo = null;
1347
- this.updateRegister();
1327
+ await this.updateRegister();
1348
1328
  }, interval);
1349
1329
  }
1350
1330
  }
@@ -1352,7 +1332,10 @@ class Admin extends utils.Adapter {
1352
1332
  this.log.error(`May not read "system.repositories": ${err}`);
1353
1333
  }
1354
1334
  }
1355
- });
1335
+ }
1336
+ catch {
1337
+ this.log.error('May not read "system.config"');
1338
+ }
1356
1339
  }
1357
1340
  // this function re-check if the common objects like '0_userdata.0' exist
1358
1341
  async checkCommonObjects() {
@@ -1435,13 +1418,13 @@ class Admin extends utils.Adapter {
1435
1418
  if (!this.config.defaultUser.match(/^system\.user\./)) {
1436
1419
  this.config.defaultUser = `system.user.${this.config.defaultUser}`;
1437
1420
  }
1438
- this.checkCommonObjects().catch((e) => this.log.warn(`Cannot check common objects: ${e}`));
1421
+ this.checkCommonObjects().catch((e) => this.log.warn(`Cannot check common objects: ${e?.message}`));
1439
1422
  this.getData(adapter => (webServer = new web_1.default(adapter.config, adapter, this.initSocket.bind(this), { systemLanguage })));
1440
1423
  if (this.config.accessApplyRights &&
1441
1424
  this.config.accessLimit &&
1442
1425
  !this.config.auth &&
1443
1426
  this.config.defaultUser !== 'system.user.admin') {
1444
- this.applyRights();
1427
+ this.applyRights().catch((e) => this.log.warn(`Cannot apply rights: ${e?.message}`));
1445
1428
  }
1446
1429
  // By default, update repository every 24 hours
1447
1430
  if (this.config.autoUpdate === undefined || this.config.autoUpdate === null) {
@@ -1457,7 +1440,7 @@ class Admin extends utils.Adapter {
1457
1440
  this.config.autoUpdate = 590; // max interval is 2147483647 milliseconds
1458
1441
  }
1459
1442
  // check info.connected
1460
- this.getObjectAsync('info.connected').then(obj => {
1443
+ void this.getObjectAsync('info.connected').then(obj => {
1461
1444
  if (!obj) {
1462
1445
  const packageJson = JSON.parse(fs.readFileSync(`${__dirname}/../io-package.json`).toString('utf8'));
1463
1446
  const obj = packageJson.instanceObjects.find((o) => o._id === 'info.connected');
@@ -1467,33 +1450,39 @@ class Admin extends utils.Adapter {
1467
1450
  }
1468
1451
  });
1469
1452
  if (this.config.autoUpdate) {
1470
- this.updateRegister();
1453
+ void this.updateRegister().catch(e => this.log.error(`Cannot update repository: ${e}`));
1471
1454
  }
1472
- this.updateNews();
1455
+ void this.updateNews().catch(e => this.log.error(`Cannot update news: ${e}`));
1473
1456
  this.updateIcons();
1474
- this.validateUserData0();
1457
+ void this.validateUserData0().catch(e => this.log.error(`Cannot validate 0_userdata: ${e}`));
1475
1458
  }
1476
1459
  /**
1477
1460
  * Create 0_userdata if it does not exist
1478
1461
  */
1479
- validateUserData0() {
1480
- this.getForeignObject('0_userdata.0', (err, obj) => {
1481
- if (!obj) {
1482
- try {
1483
- const ioContent = fs.readFileSync(`${utils.controllerDir}/io-package.json`).toString('utf8');
1484
- const io = JSON.parse(ioContent);
1485
- if (io.objects) {
1486
- const userData = io.objects.find((obj) => obj._id === '0_userdata.0');
1487
- if (userData) {
1488
- this.setForeignObject(userData._id, userData, () => this.log.info('Object 0_userdata.0 was re-created'));
1489
- }
1462
+ async validateUserData0() {
1463
+ let obj;
1464
+ try {
1465
+ obj = await this.getForeignObjectAsync('0_userdata.0');
1466
+ }
1467
+ catch {
1468
+ // ignore
1469
+ }
1470
+ if (!obj) {
1471
+ try {
1472
+ const ioContent = fs.readFileSync(`${utils.controllerDir}/io-package.json`).toString('utf8');
1473
+ const io = JSON.parse(ioContent);
1474
+ if (io.objects) {
1475
+ const userData = io.objects.find((obj) => obj._id === '0_userdata.0');
1476
+ if (userData) {
1477
+ await this.setForeignObjectAsync(userData._id, userData);
1478
+ this.log.info('Object 0_userdata.0 was re-created');
1490
1479
  }
1491
1480
  }
1492
- catch (e) {
1493
- this.log.error(`Cannot read ${utils.controllerDir}/io-package.json: ${e}`);
1494
- }
1495
1481
  }
1496
- });
1482
+ catch (e) {
1483
+ this.log.error(`Cannot read ${utils.controllerDir}/io-package.json: ${e}`);
1484
+ }
1485
+ }
1497
1486
  }
1498
1487
  }
1499
1488
  if (require.main !== module) {