@iobroker/socket-classes 1.0.1 → 1.1.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/README.md CHANGED
@@ -87,6 +87,7 @@ io.close();
87
87
  * [setObject](#setobject_w)
88
88
  * [delObject](#delobject_w)
89
89
  * [getStates](#getstates_w)
90
+ * [getForeignStates](#getforeignstates_w)
90
91
  * [getState](#getstate_w)
91
92
  * [setState](#setstate_w)
92
93
  * [getBinaryState](#getbinarystate_w)
@@ -221,6 +222,11 @@ Read states by pattern
221
222
  * pattern *(string)*: optional pattern, like `system.adapter.*` or array of state IDs
222
223
  * callback *(function)*: `function (error, states)`, where `states` is an object like `{'system.adapter.history.0': {_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}, 'system.adapter.history.1': {...}}}`
223
224
 
225
+ ### <a name="getforeignstates_w"></a>getForeignStates(pattern, callback)
226
+ Read all states (which might not belong to this adapter) which match the given pattern
227
+ * pattern *(string)*: pattern like
228
+ * callback *(function)*: `function (error)`
229
+
224
230
  ### <a name="getstate_w"></a>getState(id, callback)
225
231
  Read one state.
226
232
  * id *(string)*: State ID like, 'system.adapter.admin.0.memRss'
@@ -430,6 +436,7 @@ Read all instances of the given adapter, or all instances of all adapters if ada
430
436
  * [getForeignObjects](#getforeignobjects_a)
431
437
  * [delObjects](#delobjects_a)
432
438
  * [getStates](#getstates_a)
439
+ * [getForeignStates](#getforeignstates_a)
433
440
  * [getState](#getstate_a)
434
441
  * [setState](#setstate_a)
435
442
  * [getBinaryState](#getbinarystate_a)
@@ -438,7 +445,6 @@ Read all instances of the given adapter, or all instances of all adapters if ada
438
445
  * [subscribeStates](#subscribestates_a)
439
446
  * [unsubscribe](#unsubscribe_a)
440
447
  * [unsubscribeStates](#unsubscribestates_a)
441
- * [getForeignStates](#getforeignstates_a)
442
448
  * [readFile](#readfile_a)
443
449
  * [readFile64](#readfile64_a)
444
450
  * [writeFile64](#writefile64_a)
@@ -717,6 +723,11 @@ Read states by pattern
717
723
  * pattern *(string)*: optional pattern, like `system.adapter.*` or array of state IDs
718
724
  * callback *(function)*: `function (error, states)`, where `states` is an object like `{'system.adapter.history.0': {_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}, 'system.adapter.history.1': {...}}}`
719
725
 
726
+ ### <a name="getforeignstates_a"></a>getForeignStates(pattern, callback)
727
+ Read all states (which might not belong to this adapter) which match the given pattern
728
+ * pattern *(string)*: pattern like
729
+ * callback *(function)*: `function (error)`
730
+
720
731
  ### <a name="getstate_a"></a>getState(id, callback)
721
732
  Read one state.
722
733
  * id *(string)*: State ID like, 'system.adapter.admin.0.memRss'
@@ -759,11 +770,6 @@ Unsubscribe from state changes by pattern. Same as `unsubscribe`.
759
770
  * pattern *(string)*: pattern like 'system.adapter.*' or array of states like ['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
760
771
  * callback *(function)*: `function (error)`
761
772
 
762
- ### <a name="getforeignstates_a"></a>getForeignStates(pattern, callback)
763
- Read all states (which might not belong to this adapter) which match the given pattern
764
- * pattern *(string)*: pattern like
765
- * callback *(function)*: `function (error)`
766
-
767
773
  ### <a name="readfile_a"></a>readFile(_adapter, fileName, callback)
768
774
  Read file from ioBroker DB
769
775
  * _adapter *(string)*: instance name, e.g. `vis.0`
@@ -882,6 +888,13 @@ Read all instances of the given adapter, or all instances of all adapters if ada
882
888
  -->
883
889
 
884
890
  ## Changelog
891
+ ### 1.1.0 (2022-12-22)
892
+ * (bluefox) Added user check to many commands
893
+ * (bluefox) Downgrade axios to 0.27.2
894
+
895
+ ### 1.0.2 (2022-11-08)
896
+ * (bluefox) Function `getObjects`for web was extended by devices, channels and enums
897
+
885
898
  ### 1.0.1 (2022-10-10)
886
899
  * (bluefox) Fixed error with delObject
887
900
 
@@ -121,7 +121,7 @@ class SocketCommands {
121
121
  const files = await this.adapter.readDirAsync(_adapter, name, options);
122
122
  if (files && files.length) {
123
123
  for (let f = 0; f < files.length; f++) {
124
- await this._unlink(_adapter, name + '/' + files[f].file);
124
+ await this._unlink(_adapter, `${name}/${files[f].file}`);
125
125
  }
126
126
  }
127
127
  } catch (error) {
@@ -218,7 +218,7 @@ class SocketCommands {
218
218
 
219
219
  publishFile(socket, id, fileName, size) {
220
220
  if (socket && socket.subscribe && socket.subscribe.fileChange && this._updateSession(socket)) {
221
- const key = id + '####' + fileName;
221
+ const key = `${id}####${fileName}`;
222
222
  return !!socket.subscribe.fileChange.find(sub => {
223
223
  if (sub.regex.test(key)) {
224
224
  socket.emit('fileChange', id, fileName, size);
@@ -237,7 +237,7 @@ class SocketCommands {
237
237
  for (let i = 0; i < s.length; i++) {
238
238
  ids.push(s[i].pattern);
239
239
  }
240
- this.adapter.log.debug('Subscribes: ' + ids.join(', '));
240
+ this.adapter.log.debug(`Subscribes: ${ids.join(', ')}`);
241
241
  } else {
242
242
  this.adapter.log.debug('Subscribes: no subscribes');
243
243
  }
@@ -283,16 +283,16 @@ class SocketCommands {
283
283
  if (this.subscribes[type][key] === undefined) {
284
284
  this.subscribes[type][key] = 1;
285
285
  if (type === 'stateChange') {
286
- this.adapter.subscribeForeignStates(pattern);
286
+ this.adapter.subscribeForeignStates(pattern, {user: socket._acl.user});
287
287
  } else if (type === 'objectChange') {
288
- this.adapter.subscribeForeignObjects && this.adapter.subscribeForeignObjects(pattern);
288
+ this.adapter.subscribeForeignObjects && this.adapter.subscribeForeignObjects(pattern, {user: socket._acl.user});
289
289
  } else if (type === 'log') {
290
290
  if (!this.logEnabled && this.adapter.requireLog) {
291
291
  this.logEnabled = true;
292
- this.adapter.requireLog(true);
292
+ this.adapter.requireLog(true); // , {user: socket._acl.user}
293
293
  }
294
294
  } else if (type === 'fileChange') {
295
- this.adapter.subscribeForeignFiles && this.adapter.subscribeForeignFiles(pattern, patternFile);
295
+ this.adapter.subscribeForeignFiles && this.adapter.subscribeForeignFiles(pattern, patternFile, {user: socket._acl.user});
296
296
  }
297
297
  } else {
298
298
  this.subscribes[type][key]++;
@@ -331,19 +331,19 @@ class SocketCommands {
331
331
  if (this.subscribes[type][key] <= 0) {
332
332
  if (type === 'stateChange') {
333
333
  //console.log((socket._name || socket.id) + ' unsubscribeForeignStates ' + pattern);
334
- this.adapter.unsubscribeForeignStates(pattern);
334
+ this.adapter.unsubscribeForeignStates(pattern, {user: socket._acl.user});
335
335
  } else if (type === 'objectChange') {
336
336
  //console.log((socket._name || socket.id) + ' unsubscribeForeignObjects ' + pattern);
337
- this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern);
337
+ this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern, {user: socket._acl.user});
338
338
  } else if (type === 'log') {
339
339
  //console.log((socket._name || socket.id) + ' requireLog false');
340
340
  if (this.logEnabled && this.adapter.requireLog) {
341
341
  this.logEnabled = false;
342
- this.adapter.requireLog(false);
342
+ this.adapter.requireLog(false); // , {user: socket._acl.user}
343
343
  }
344
344
  } else if (type === 'fileChange') {
345
345
  //console.log((socket._name || socket.id) + ' requireLog false');
346
- this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(pattern, patternFile);
346
+ this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(pattern, patternFile, {user: socket._acl.user});
347
347
  }
348
348
  delete this.subscribes[type][pattern];
349
349
  }
@@ -360,16 +360,16 @@ class SocketCommands {
360
360
  this.subscribes[type][key]--;
361
361
  if (this.subscribes[type][key] <= 0) {
362
362
  if (type === 'stateChange') {
363
- this.adapter.unsubscribeForeignStates(pattern);
363
+ this.adapter.unsubscribeForeignStates(pattern, {user: socket._acl.user});
364
364
  } else if (type === 'objectChange') {
365
- this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern);
365
+ this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern, {user: socket._acl.user});
366
366
  } else if (type === 'log') {
367
367
  if (this.adapter.requireLog && this.logEnabled) {
368
368
  this.logEnabled = false;
369
- this.adapter.requireLog(false);
369
+ this.adapter.requireLog(false); // , {user: socket._acl.user}
370
370
  }
371
371
  } else if (type === 'fileChange') {
372
- this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(pattern, patternFile);
372
+ this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(pattern, patternFile, {user: socket._acl.user});
373
373
  }
374
374
  delete this.subscribes[type][key];
375
375
  }
@@ -378,19 +378,19 @@ class SocketCommands {
378
378
  Object.keys(this.subscribes[type]).forEach(pattern => {
379
379
  if (type === 'stateChange') {
380
380
  //console.log((socket._name || socket.id) + ' unsubscribeForeignStates ' + pattern);
381
- this.adapter.unsubscribeForeignStates(pattern);
381
+ this.adapter.unsubscribeForeignStates(pattern, {user: socket._acl.user});
382
382
  } else if (type === 'objectChange') {
383
383
  //console.log((socket._name || socket.id) + ' unsubscribeForeignObjects ' + pattern);
384
- this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern);
384
+ this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern, {user: socket._acl.user});
385
385
  } else if (type === 'log') {
386
386
  //console.log((socket._name || socket.id) + ' requireLog false');
387
387
  if (this.adapter.requireLog && this.logEnabled) {
388
388
  this.logEnabled = false;
389
- this.adapter.requireLog(false);
389
+ this.adapter.requireLog(false); // , {user: socket._acl.user}
390
390
  }
391
391
  } else if (type === 'fileChange') {
392
392
  const [id, fileName] = pattern.split('####');
393
- this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(id, fileName);
393
+ this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(id, fileName, {user: socket._acl.user});
394
394
  }
395
395
  });
396
396
 
@@ -405,7 +405,8 @@ class SocketCommands {
405
405
 
406
406
  if (!type) {
407
407
  // all
408
- return Object.keys(socket.subscribe).forEach(type => this.subscribeSocket(socket, type));
408
+ return Object.keys(socket.subscribe)
409
+ .forEach(type => this.subscribeSocket(socket, type));
409
410
  }
410
411
 
411
412
  if (!socket.subscribe[type]) {
@@ -417,14 +418,17 @@ class SocketCommands {
417
418
  if (this.subscribes[type][pattern] === undefined) {
418
419
  this.subscribes[type][pattern] = 1;
419
420
  if (type === 'stateChange') {
420
- this.adapter.subscribeForeignStates(pattern);
421
+ this.adapter.subscribeForeignStates(pattern, {user: socket._acl.user});
421
422
  } else if (type === 'objectChange') {
422
- this.adapter.subscribeForeignObjects && this.adapter.subscribeForeignObjects(pattern);
423
+ this.adapter.subscribeForeignObjects && this.adapter.subscribeForeignObjects(pattern, {user: socket._acl.user});
423
424
  } else if (type === 'log') {
424
425
  if (this.adapter.requireLog && !this.logEnabled) {
425
426
  this.logEnabled = true;
426
- this.adapter.requireLog(true);
427
+ this.adapter.requireLog(true); // , {user: socket._acl.user}
427
428
  }
429
+ } else if (type === 'fileChange') {
430
+ const [id, fileName] = pattern.split('####');
431
+ this.adapter.subscribeForeignFiles && this.adapter.subscribeForeignFiles(id, fileName, {user: socket._acl.user});
428
432
  }
429
433
  } else {
430
434
  this.subscribes[type][pattern]++;
@@ -439,7 +443,8 @@ class SocketCommands {
439
443
 
440
444
  if (!type) {
441
445
  // all
442
- return Object.keys(socket.subscribe).forEach(type => this.unsubscribeSocket(socket, type));
446
+ return Object.keys(socket.subscribe)
447
+ .forEach(type => this.unsubscribeSocket(socket, type));
443
448
  }
444
449
 
445
450
  if (!socket.subscribe[type]) {
@@ -452,14 +457,17 @@ class SocketCommands {
452
457
  this.subscribes[type][pattern]--;
453
458
  if (this.subscribes[type][pattern] <= 0) {
454
459
  if (type === 'stateChange') {
455
- this.adapter.unsubscribeForeignStates(pattern);
460
+ this.adapter.unsubscribeForeignStates(pattern, {user: socket._acl.user});
456
461
  } else if (type === 'objectChange') {
457
- this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern);
462
+ this.adapter.unsubscribeForeignObjects && this.adapter.unsubscribeForeignObjects(pattern, {user: socket._acl.user});
458
463
  } else if (type === 'log') {
459
464
  if (this.adapter.requireLog && !this.logEnabled) {
460
465
  this.logEnabled = true;
461
- this.adapter.requireLog(true);
466
+ this.adapter.requireLog(true); // , {user: socket._acl.user}
462
467
  }
468
+ } else if (type === 'fileChange') {
469
+ const [id, fileName] = pattern.split('####');
470
+ this.adapter.unsubscribeForeignFiles && this.adapter.unsubscribeForeignFiles(id, fileName, {user: socket._acl.user});
463
471
  }
464
472
  delete this.subscribes[type][pattern];
465
473
  }
@@ -657,7 +665,7 @@ class SocketCommands {
657
665
  // @param {function} callback - `function (error, {status, statusText}, body)`
658
666
  if (this._checkPermissions(socket, 'httpGet', callback, url)) {
659
667
  axios = axios || require('axios');
660
- this.adapter.log.debug('httpGet: ' + url);
668
+ this.adapter.log.debug(`httpGet: ${url}`);
661
669
  try {
662
670
  axios(url, {
663
671
  responseType: 'arraybuffer',
@@ -913,7 +921,7 @@ class SocketCommands {
913
921
  this.adapter.log.debug('writeFile deprecated. Please use writeFile64');
914
922
  // const buffer = Buffer.from(data64, 'base64');
915
923
  try {
916
- this.adapter.writeFile(_adapter, fileName, data, {user: socket._acl.user}, (error, ...args) =>
924
+ this.adapter.writeFile(_adapter, fileName, data, options, (error, ...args) =>
917
925
  SocketCommands._fixCallback(callback, error, ...args));
918
926
  } catch (error) {
919
927
  this.adapter.log.error('[writeFile] ERROR: ' + error.toString());
@@ -933,7 +941,7 @@ class SocketCommands {
933
941
  .then(() => SocketCommands._fixCallback(callback))
934
942
  .catch(error => SocketCommands._fixCallback(callback, error));
935
943
  } catch (error) {
936
- this.adapter.log.error('[unlink] ERROR: ' + error.toString());
944
+ this.adapter.log.error(`[unlink] ERROR: ${error.toString()}`);
937
945
  SocketCommands._fixCallback(callback, error);
938
946
  }
939
947
  }
@@ -1073,7 +1081,7 @@ class SocketCommands {
1073
1081
  this.adapter.chmodFile(_adapter, fileName, options, (error, ...args) =>
1074
1082
  SocketCommands._fixCallback(callback, error, ...args));
1075
1083
  } catch (error) {
1076
- this.adapter.log.error('[chmodFile] ERROR: ' + error.toString());
1084
+ this.adapter.log.error(`[chmodFile] ERROR: ${error.toString()}`);
1077
1085
  SocketCommands._fixCallback(callback, error);
1078
1086
  }
1079
1087
  }
@@ -1092,7 +1100,7 @@ class SocketCommands {
1092
1100
  this.adapter.chownFile(_adapter, fileName, options, (error, ...args) =>
1093
1101
  SocketCommands._fixCallback(callback, error, ...args));
1094
1102
  } catch (error) {
1095
- this.adapter.log.error('[chownFile] ERROR: ' + error.toString());
1103
+ this.adapter.log.error(`[chownFile] ERROR: ${error.toString()}`);
1096
1104
  SocketCommands._fixCallback(callback, error);
1097
1105
  }
1098
1106
  }
@@ -1108,7 +1116,7 @@ class SocketCommands {
1108
1116
  this.adapter.fileExists(_adapter, fileName, {user: socket._acl.user}, (error, ...args) =>
1109
1117
  SocketCommands._fixCallback(callback, error, ...args));
1110
1118
  } catch (error) {
1111
- this.adapter.log.error('[fileExists] ERROR: ' + error.toString());
1119
+ this.adapter.log.error(`[fileExists] ERROR: ${error.toString()}`);
1112
1120
  SocketCommands._fixCallback(callback, error);
1113
1121
  }
1114
1122
  }
@@ -1144,6 +1152,7 @@ class SocketCommands {
1144
1152
  try {
1145
1153
  this.adapter.getObjectView('system', 'instance',
1146
1154
  {startkey: `system.adapter.${_adapterName}`, endkey: `system.adapter.${_adapterName}\u9999`},
1155
+ {user: socket._acl.user},
1147
1156
  (error, doc) => {
1148
1157
  if (error) {
1149
1158
  callback(error);
@@ -1194,6 +1203,25 @@ class SocketCommands {
1194
1203
  }
1195
1204
  };
1196
1205
 
1206
+ this.commands['getForeignStates'] = (socket, pattern, callback) => {
1207
+ // Read all states (which might not belong to this adapter) which match the given pattern
1208
+ // @param {string} pattern - pattern like
1209
+ // @param {function} callback - `function (error)`
1210
+ if (this._checkPermissions(socket, 'getStates', callback)) {
1211
+ if (typeof callback === 'function') {
1212
+ try {
1213
+ this.adapter.getForeignStates(pattern, {user: socket._acl.user}, (error, ...args) =>
1214
+ SocketCommands._fixCallback(callback, error, ...args));
1215
+ } catch (error) {
1216
+ this.adapter.log.error(`[getForeignStates] ERROR: ${error}`);
1217
+ SocketCommands._fixCallback(callback, error);
1218
+ }
1219
+ } else {
1220
+ this.adapter.log.warn('[getForeignStates] Invalid callback')
1221
+ }
1222
+ }
1223
+ };
1224
+
1197
1225
  this.commands['getState'] = (socket, id, callback) => {
1198
1226
  // Read one state.
1199
1227
  // @param {string} id - State ID like, 'system.adapter.admin.0.memRss'
@@ -1250,7 +1278,7 @@ class SocketCommands {
1250
1278
  if (typeof callback === 'function') {
1251
1279
  try {
1252
1280
  if (this.adapter.getForeignBinaryState) {
1253
- this.adapter.getForeignBinaryState(id, (error, data) => {
1281
+ this.adapter.getForeignBinaryState(id, {user: socket._acl.user}, (error, data) => {
1254
1282
  if (data) {
1255
1283
  try {
1256
1284
  data = Buffer.from(data).toString('base64');
@@ -1261,7 +1289,7 @@ class SocketCommands {
1261
1289
  SocketCommands._fixCallback(callback, error, data);
1262
1290
  });
1263
1291
  } else {
1264
- this.adapter.getBinaryState(id, (error, data) => {
1292
+ this.adapter.getBinaryState(id, {user: socket._acl.user}, (error, data) => {
1265
1293
  if (data) {
1266
1294
  try {
1267
1295
  data = Buffer.from(data).toString('base64');
@@ -1273,7 +1301,7 @@ class SocketCommands {
1273
1301
  });
1274
1302
  }
1275
1303
  } catch (error) {
1276
- this.adapter.log.error('[getBinaryState] ERROR: ' + error.toString());
1304
+ this.adapter.log.error(`[getBinaryState] ERROR: ${error.toString()}`);
1277
1305
  SocketCommands._fixCallback(callback, error);
1278
1306
  }
1279
1307
  } else {
@@ -1298,10 +1326,10 @@ class SocketCommands {
1298
1326
 
1299
1327
  try {
1300
1328
  if (this.adapter.setForeignBinaryState) {
1301
- this.adapter.setForeignBinaryState(id, data, (error, ...args) =>
1329
+ this.adapter.setForeignBinaryState(id, data, {user: socket._acl.user}, (error, ...args) =>
1302
1330
  SocketCommands._fixCallback(callback, error, ...args));
1303
1331
  } else {
1304
- this.adapter.setBinaryState(id, data, (error, ...args) =>
1332
+ this.adapter.setBinaryState(id, data, {user: socket._acl.user}, (error, ...args) =>
1305
1333
  SocketCommands._fixCallback(callback, error, ...args));
1306
1334
  }
1307
1335
  } catch (error) {
@@ -1372,18 +1400,28 @@ class SocketCommands {
1372
1400
  // @param {function} callback - `function (error, obj)`
1373
1401
  if (this._checkPermissions(socket, 'getObjects', callback)) {
1374
1402
  try {
1375
- this.adapter.getForeignObjects('*', 'state', 'rooms', {user: socket._acl.user}, (error, objs) => {
1376
- if (typeof callback === 'function') {
1403
+ if (typeof callback === 'function') {
1404
+ this.adapter.getForeignObjects('*', 'state', 'rooms', {user: socket._acl.user}, async (error, objs) => {
1405
+ try {
1406
+ const channels = await this.adapter.getForeignObjectsAsync('*', 'channel', null, {user: socket._acl.user});
1407
+ const devices = await this.adapter.getForeignObjectsAsync('*', 'device', null, {user: socket._acl.user});
1408
+ const enums = await this.adapter.getForeignObjectsAsync('*', 'enum', null, {user: socket._acl.user});
1409
+ const config = await this.adapter.getForeignObjectAsync('system.config', {user: socket._acl.user});
1410
+ Object.assign(objs, channels, devices, enums);
1411
+ objs['system.config'] = config;
1412
+ } catch (e) {
1413
+ this.adapter.log.error('[getObjects] ERROR: ' + e.toString());
1414
+ }
1377
1415
  // overload language
1378
1416
  if (this.adapter._language && objs['system.config'] && objs['system.config'].common) {
1379
1417
  objs['system.config'].common.language = this.adapter._language;
1380
1418
  }
1381
1419
 
1382
1420
  SocketCommands._fixCallback(callback, error, objs);
1383
- } else {
1384
- this.adapter.log.warn('[getObjects] Invalid callback');
1385
- }
1386
- });
1421
+ });
1422
+ } else {
1423
+ this.adapter.log.warn('[getObjects] Invalid callback');
1424
+ }
1387
1425
  } catch (error) {
1388
1426
  this.adapter.log.error('[getObjects] ERROR: ' + error.toString());
1389
1427
  SocketCommands._fixCallback(callback, error);
@@ -1450,7 +1488,7 @@ class SocketCommands {
1450
1488
  try {
1451
1489
  this.adapter.getObjectView(design, search, params, {user: socket._acl.user}, callback);
1452
1490
  } catch (error) {
1453
- this.adapter.log.error('[getObjectView] ERROR: ' + error.toString());
1491
+ this.adapter.log.error(`[getObjectView] ERROR: ${error.toString()}`);
1454
1492
  SocketCommands._fixCallback(callback, error);
1455
1493
  }
1456
1494
  }
@@ -165,7 +165,7 @@ class SocketCommandsAdmin extends SocketCommands {
165
165
  // remove this function when js.controller 4.x will be mainstream
166
166
  _readLicenses(login, password) {
167
167
  const config = {
168
- headers: { Authorization: `Basic ${Buffer.from(login + ':' + password).toString('base64')}` },
168
+ headers: { Authorization: `Basic ${Buffer.from(`${login}:${password}`).toString('base64')}` },
169
169
  timeout: 4000,
170
170
  validateStatus: status => status < 400
171
171
  };
@@ -190,18 +190,18 @@ class SocketCommandsAdmin extends SocketCommands {
190
190
  }
191
191
 
192
192
  // remove this function when js.controller 4.x will be mainstream
193
- _updateLicenses(login, password) {
193
+ _updateLicenses(login, password, options) {
194
194
  // if login and password provided in the message, just try to read without saving it in system.licenses
195
195
  if (login && password) {
196
196
  return this._readLicenses(login, password);
197
197
  } else {
198
198
  // get actual object
199
- return this.adapter.getForeignObjectAsync('system.licenses')
199
+ return this.adapter.getForeignObjectAsync('system.licenses', options)
200
200
  .then(systemLicenses => {
201
201
  // If password and login exist
202
202
  if (systemLicenses && systemLicenses.native && systemLicenses.native.password && systemLicenses.native.login) {
203
203
  // get the secret to decode the password
204
- return this.adapter.getForeignObjectAsync('system.config')
204
+ return this.adapter.getForeignObjectAsync('system.config', options)
205
205
  .then(systemConfig => {
206
206
  // decode the password
207
207
  let password;
@@ -231,7 +231,7 @@ class SocketCommandsAdmin extends SocketCommands {
231
231
  systemLicenses.native.readTime = new Date().toISOString();
232
232
 
233
233
  // save only if object changed
234
- return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses)
234
+ return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses, options)
235
235
  .then(() => licenses);
236
236
  })
237
237
  .catch(error => {
@@ -241,7 +241,7 @@ class SocketCommandsAdmin extends SocketCommands {
241
241
  if (systemLicenses && systemLicenses.native && systemLicenses.native.licenses && systemLicenses.native.licenses.length) {
242
242
  systemLicenses.native.licenses = [];
243
243
  systemLicenses.native.readTime = new Date().toISOString();
244
- return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses)
244
+ return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses, options)
245
245
  .then(() => {
246
246
  throw error;
247
247
  });
@@ -257,7 +257,7 @@ class SocketCommandsAdmin extends SocketCommands {
257
257
  if (systemLicenses && systemLicenses.native && systemLicenses.native.licenses && systemLicenses.native.licenses.length) {
258
258
  systemLicenses.native.licenses = [];
259
259
  systemLicenses.native.readTime = new Date().toISOString();
260
- return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses)
260
+ return this.adapter.setForeignObjectAsync('system.licenses', systemLicenses, options)
261
261
  .then(() => {
262
262
  throw new Error('No password or login');
263
263
  });
@@ -413,7 +413,7 @@ class SocketCommandsAdmin extends SocketCommands {
413
413
  }
414
414
 
415
415
  try {
416
- this.adapter.getForeignObject('system.group.' + group, options, (error, obj) => {
416
+ this.adapter.getForeignObject(`system.group.${group}`, options, (error, obj) => {
417
417
  if (obj) {
418
418
  SocketCommands._fixCallback(callback, 'Group yet exists');
419
419
  } else {
@@ -428,10 +428,10 @@ class SocketCommandsAdmin extends SocketCommands {
428
428
  }
429
429
  };
430
430
  try {
431
- this.adapter.setForeignObject('system.group.' + group, obj, options, error =>
431
+ this.adapter.setForeignObject(`system.group.${group}`, obj, options, error =>
432
432
  SocketCommands._fixCallback(callback, error, obj));
433
433
  } catch (error) {
434
- this.adapter.log.error('[_addGroup] cannot write group: ' + error.toString());
434
+ this.adapter.log.error(`[_addGroup] cannot write group: ${error.toString()}`);
435
435
  SocketCommands._fixCallback(callback, error);
436
436
  }
437
437
  }
@@ -452,11 +452,11 @@ class SocketCommandsAdmin extends SocketCommands {
452
452
  SocketCommands._fixCallback(callback, 'Cannot delete group, while is system group');
453
453
  } else {
454
454
  try {
455
- this.adapter.delForeignObject('system.group.' + group, options, error =>
455
+ this.adapter.delForeignObject(`system.group.${group}`, options, error =>
456
456
  // Remove this group from all users in web client
457
457
  SocketCommands._fixCallback(callback, error));
458
458
  } catch (error) {
459
- this.adapter.log.error('[_delGroup] cannot delete group: ' + error.toString());
459
+ this.adapter.log.error(`[_delGroup] cannot delete group: ${error.toString()}`);
460
460
  SocketCommands._fixCallback(callback, error);
461
461
  }
462
462
  }
@@ -520,7 +520,7 @@ class SocketCommandsAdmin extends SocketCommands {
520
520
  }
521
521
  } else {
522
522
  try {
523
- this.adapter.getObjectList({include_docs: true}, (error, res) => {
523
+ this.adapter.getObjectList({include_docs: true}, {user: socket._acl.user}, (error, res) => {
524
524
  this.adapter.log.info('received all objects');
525
525
  res = res.rows;
526
526
  const objects = {};
@@ -542,7 +542,7 @@ class SocketCommandsAdmin extends SocketCommands {
542
542
  }
543
543
  });
544
544
  } catch (error) {
545
- this.adapter.log.error('[_getAllObjects] ERROR: ' + error.toString());
545
+ this.adapter.log.error(`[_getAllObjects] ERROR: ${error.toString()}`);
546
546
  SocketCommands._fixCallback(callback, error);
547
547
  }
548
548
  }
@@ -705,7 +705,7 @@ class SocketCommandsAdmin extends SocketCommands {
705
705
  for (let f = 0; f < files.length; f++) {
706
706
  try {
707
707
  if (!files[f].endsWith('-audit.json')) {
708
- const stat = fs.lstatSync(fileName + '/' + files[f]);
708
+ const stat = fs.lstatSync(`${fileName}/${files[f]}`);
709
709
  if (!stat.isDirectory()) {
710
710
  result.list.push({
711
711
  fileName: `log/${transport}/${files[f]}`,
@@ -726,7 +726,7 @@ class SocketCommandsAdmin extends SocketCommands {
726
726
  result = {error: 'no file loggers'};
727
727
  }
728
728
  } catch (error) {
729
- this.adapter.log.error('Cannot read logs: ' + error);
729
+ this.adapter.log.error(`Cannot read logs: ${error}`);
730
730
  result = {error};
731
731
  }
732
732
  SocketCommands._fixCallback(callback, result.error, result.list);
@@ -754,7 +754,7 @@ class SocketCommandsAdmin extends SocketCommands {
754
754
  this.adapter.delForeignState(id, {user: socket._acl.user}, (error, ...args) =>
755
755
  SocketCommands._fixCallback(callback, error, ...args));
756
756
  } catch (error) {
757
- this.adapter.log.error('[delState] ERROR: ' + error.toString());
757
+ this.adapter.log.error(`[delState] ERROR: ${error.toString()}`);
758
758
  SocketCommands._fixCallback(callback, error);
759
759
  }
760
760
  }
@@ -776,7 +776,7 @@ class SocketCommandsAdmin extends SocketCommands {
776
776
  this.adapter.sendToHost(host, 'cmdExec', {data: cmd, id});
777
777
  SocketCommands._fixCallback(callback, null);
778
778
  } catch (error) {
779
- this.adapter.log.error('[cmdExec] ERROR: ' + error.toString());
779
+ this.adapter.log.error(`[cmdExec] ERROR: ${error.toString()}`);
780
780
  SocketCommands._fixCallback(callback, error);
781
781
  }
782
782
  }
@@ -825,7 +825,7 @@ class SocketCommandsAdmin extends SocketCommands {
825
825
  SocketCommands._fixCallback(callback, null, this.adapter.decrypt(this.secret, encryptedText));
826
826
  } else {
827
827
  try {
828
- this.adapter.getForeignObject('system.config', (error, obj) => {
828
+ this.adapter.getForeignObject('system.config', {user: socket._acl.user}, (error, obj) => {
829
829
  if (obj && obj.native && obj.native.secret) {
830
830
  this.secret = obj.native.secret;
831
831
  SocketCommands._fixCallback(callback, null, this.adapter.decrypt(this.secret, encryptedText));
@@ -848,7 +848,7 @@ class SocketCommandsAdmin extends SocketCommands {
848
848
  if (this.secret) {
849
849
  SocketCommands._fixCallback(callback, null, this.adapter.encrypt(this.secret, plainText));
850
850
  } else {
851
- this.adapter.getForeignObject('system.config', (error, obj) => {
851
+ this.adapter.getForeignObject('system.config', {user: socket._acl.user}, (error, obj) => {
852
852
  if (obj && obj.native && obj.native.secret) {
853
853
  this.secret = obj.native.secret;
854
854
  try {
@@ -881,7 +881,7 @@ class SocketCommandsAdmin extends SocketCommands {
881
881
  if (this.adapter.config.auth) {
882
882
  user = socket._acl.user;
883
883
  if (!user.startsWith('system.user.')) {
884
- user = 'system.user.' + user;
884
+ user = `system.user.${user}`;
885
885
  }
886
886
  } else {
887
887
  user = this.adapter.config.defaultUser;
@@ -937,6 +937,7 @@ class SocketCommandsAdmin extends SocketCommands {
937
937
  if (typeof callback === 'function' && this._checkPermissions(socket, 'getObject', callback)) {
938
938
  this.adapter.getObjectView('system', 'adapter',
939
939
  {startkey: `system.adapter.${adapterName || ''}`, endkey: `system.adapter.${adapterName || '\u9999'}`},
940
+ {user: socket._acl.user},
940
941
  (error, doc) =>
941
942
  {
942
943
  if (error) {
@@ -981,7 +982,7 @@ class SocketCommandsAdmin extends SocketCommands {
981
982
  });
982
983
  } else {
983
984
  // remove this branch when js-controller 4.x will be mainstream
984
- this._updateLicenses(login, password)
985
+ this._updateLicenses(login, password, {user: socket._acl.user})
985
986
  .then(licenses => SocketCommands._fixCallback(callback, null, licenses))
986
987
  .catch(error => SocketCommands._fixCallback(callback, error));
987
988
  }
@@ -995,6 +996,7 @@ class SocketCommandsAdmin extends SocketCommands {
995
996
  if (this._checkPermissions(socket, 'getObject', callback)) {
996
997
  this.adapter.getObjectView('system', 'instance',
997
998
  {startkey: `system.adapter.`, endkey: `system.adapter.\u9999`},
999
+ {user: socket._acl.user},
998
1000
  (error, doc) => {
999
1001
  if (error) {
1000
1002
  callback(error);
@@ -1026,6 +1028,7 @@ class SocketCommandsAdmin extends SocketCommands {
1026
1028
  if (this._checkPermissions(socket, 'getObject', callback)) {
1027
1029
  this.adapter.getObjectView('system', 'adapter',
1028
1030
  {startkey: `system.adapter.`, endkey: `system.adapter.\u9999`},
1031
+ {user: socket._acl.user},
1029
1032
  (error, doc) => {
1030
1033
  if (error) {
1031
1034
  callback(error);
@@ -1068,7 +1071,7 @@ class SocketCommandsAdmin extends SocketCommands {
1068
1071
  // Read system config in short form to save bandwidth
1069
1072
  // @param {function} callback - `function (error, systemConfig)`, where `systemConfig` is an object like `{common: {...}, native: {secret: 'aaa'}}`
1070
1073
  if (this._checkPermissions(socket, 'getObject', callback)) {
1071
- this.adapter.getForeignObject('system.config', (error, obj) => {
1074
+ this.adapter.getForeignObject('system.config', {user: socket._acl.user}, (error, obj) => {
1072
1075
  obj = obj || {};
1073
1076
  const secret = obj && obj.native && obj.native.secret;
1074
1077
  delete obj.native;
@@ -1084,7 +1087,7 @@ class SocketCommandsAdmin extends SocketCommands {
1084
1087
  // Read repositories from cache in short form to save bandwidth
1085
1088
  // @param {function} callback - `function (error, repositories)`, where `repositories` is an object like `{_id: 'system.repositories', common: {...}, native: {repositories: {default: {json: {_repoInfo: {...}}}}}}`
1086
1089
  if (this._checkPermissions(socket, 'getObject', callback)) {
1087
- this.adapter.getForeignObject('system.repositories', (error, obj) => {
1090
+ this.adapter.getForeignObject('system.repositories', {user: socket._acl.user}, (error, obj) => {
1088
1091
  obj && obj.native && obj.native.repositories && Object.keys(obj.native.repositories).forEach(name => {
1089
1092
  if (obj.native.repositories[name].json) {
1090
1093
  // limit information to _repoInfo
@@ -1119,7 +1122,9 @@ class SocketCommandsAdmin extends SocketCommands {
1119
1122
  // @param {function} callback - `function (error, hosts)`, where `hosts` is an array of objects like `[{_id:'system.host.raspi',common:{name:'raspi',icon:'icon',color:'blue',installedVersion:'2.1.0'},native:{hardware:{networkInterfaces:[...]}}}]`
1120
1123
  if (this._checkPermissions(socket, 'getObject', callback)) {
1121
1124
  this.adapter.getObjectView('system', 'host',
1122
- {startkey: 'system.host.', endkey: 'system.host.\u9999'}, (error, doc) => {
1125
+ {startkey: 'system.host.', endkey: 'system.host.\u9999'},
1126
+ {user: socket._acl.user},
1127
+ (error, doc) => {
1123
1128
  if (error) {
1124
1129
  callback(error);
1125
1130
  } else {
@@ -1158,29 +1163,6 @@ class SocketCommandsAdmin extends SocketCommands {
1158
1163
  this._initCommandsUser();
1159
1164
  }
1160
1165
 
1161
- __initCommandsStates() {
1162
- super.__initCommandsStates();
1163
-
1164
- this.commands['getForeignStates'] = (socket, pattern, callback) => {
1165
- // Read all states (which might not belong to this adapter) which match the given pattern
1166
- // @param {string} pattern - pattern like
1167
- // @param {function} callback - `function (error)`
1168
- if (this._checkPermissions(socket, 'getStates', callback)) {
1169
- if (typeof callback === 'function') {
1170
- try {
1171
- this.adapter.getForeignStates(pattern, (error, ...args) =>
1172
- SocketCommands._fixCallback(callback, error, ...args));
1173
- } catch (error) {
1174
- this.adapter.log.error(`[getForeignStates] ERROR: ${error}`);
1175
- SocketCommands._fixCallback(callback, error);
1176
- }
1177
- } else {
1178
- this.adapter.log.warn('[getForeignStates] Invalid callback')
1179
- }
1180
- }
1181
- };
1182
- }
1183
-
1184
1166
  __initCommandsFiles() {
1185
1167
  super.__initCommandsFiles();
1186
1168
 
@@ -1204,8 +1186,8 @@ class SocketCommandsAdmin extends SocketCommands {
1204
1186
  this.adapter.writeFile(_adapter, fileName, buffer, {user: socket._acl.user}, (error, ...args) =>
1205
1187
  SocketCommands._fixCallback(callback, error, ...args));
1206
1188
  } catch (error) {
1207
- this.adapter.log.error('[writeFile] Cannot convert data: ' + error.toString());
1208
- callback && callback('Cannot convert data: ' + error.toString());
1189
+ this.adapter.log.error(`[writeFile] Cannot convert data: ${error.toString()}`);
1190
+ callback && callback(`Cannot convert data: ${error.toString()}`);
1209
1191
  }
1210
1192
  }
1211
1193
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iobroker/socket-classes",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "ioBroker server-side web sockets",
5
5
  "author": {
6
6
  "name": "bluefox",
@@ -31,8 +31,8 @@
31
31
  "@alcalzone/release-script-plugin-license": "^3.5.9",
32
32
  "iobroker.js-controller": "dev",
33
33
  "gulp": "^4.0.2",
34
- "chai": "^4.3.6",
35
- "mocha": "^10.0.0"
34
+ "chai": "^4.3.7",
35
+ "mocha": "^10.1.0"
36
36
  },
37
37
  "bugs": {
38
38
  "url": "https://github.com/ioBroker/ioBroker.web/issues"