mind-client-js 0.20.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.
@@ -0,0 +1,622 @@
1
+ /*###############################################################
2
+ # #
3
+ # Copyright (c) 2026 DnaSoft BV and/or its subsidiaries. #
4
+ # All rights reserved. #
5
+ # #
6
+ # This source code contains the intellectual property #
7
+ # of its copyright holder(s), and is made available #
8
+ # under a license. If you do not know the terms of #
9
+ # the license, please stop and do not read further. #
10
+ # #
11
+ ###############################################################*/
12
+
13
+ const utils = require("../utils");
14
+ const errors = require('../errors.js')
15
+
16
+ class Session {
17
+ stats = function () {
18
+ const that = this
19
+ const RESP3 = that.objRoot.RESP3
20
+
21
+ return new Promise(function (resolve, reject) {
22
+ if (that.connected === false || that.loggedIn === false) {
23
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
24
+
25
+ return
26
+ }
27
+
28
+ // send command
29
+ const opCode = 'session.stats'
30
+ that.writer("*1" + RESP3.CRLF +
31
+ RESP3.build.blob(opCode)
32
+ );
33
+
34
+ that.reader(data => {
35
+ if (data.charAt(0) === '-') {
36
+ reject(new Error(RESP3.parse.simpleError(data)))
37
+
38
+ return
39
+ }
40
+
41
+ if (data.indexOf('+no data') > -1) {
42
+ //reject(new Error('No stats enabled on server'))
43
+ resolve({})
44
+
45
+ return
46
+ }
47
+
48
+ resolve(JSON.parse(RESP3.parse.blob(data)))
49
+ })
50
+ })
51
+ }
52
+
53
+ resetStats = function () {
54
+ const that = this
55
+ const RESP3 = that.objRoot.RESP3
56
+
57
+ return new Promise(function (resolve, reject) {
58
+ if (that.connected === false || that.loggedIn === false) {
59
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
60
+
61
+ return
62
+ }
63
+
64
+ // send command
65
+ const opCode = 'session.resetStats'
66
+ that.writer("*1" + RESP3.CRLF +
67
+ RESP3.build.blob(opCode)
68
+ );
69
+
70
+ that.reader(data => {
71
+ if (data.charAt(0) === '-') {
72
+ reject(new Error(RESP3.parse.simpleError(data)))
73
+
74
+ return
75
+ }
76
+
77
+ resolve()
78
+ })
79
+ })
80
+ }
81
+
82
+ timeSinceConnect = function () {
83
+ const that = this
84
+ const RESP3 = that.objRoot.RESP3
85
+
86
+ return new Promise(function (resolve, reject) {
87
+ if (that.connected === false || that.loggedIn === false) {
88
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
89
+
90
+ return
91
+ }
92
+
93
+ // send command
94
+ const opCode = 'session.timeSinceConnect'
95
+ that.writer("*1" + RESP3.CRLF +
96
+ RESP3.build.blob(opCode)
97
+ );
98
+
99
+ that.reader(data => {
100
+ if (data.charAt(0) === '-') {
101
+ reject(new Error(RESP3.parse.simpleError(data)))
102
+
103
+ return
104
+ }
105
+
106
+ resolve(RESP3.parse.double(data))
107
+ })
108
+ })
109
+ }
110
+
111
+ log = function (logString = '') {
112
+ const that = this
113
+ const RESP3 = that.objRoot.RESP3
114
+
115
+ return new Promise(function (resolve, reject) {
116
+ if (that.connected === false || that.loggedIn === false) {
117
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
118
+
119
+ return
120
+ }
121
+
122
+ if (typeof logString !== 'string') {
123
+ reject(new Error(errors.PARAM_NOT_STRING + 'logString parameter must be a string'))
124
+
125
+ return
126
+ }
127
+
128
+ // send command
129
+ const opCode = 'session.log'
130
+ that.writer("*2" + RESP3.CRLF +
131
+ RESP3.build.blob(opCode) +
132
+ RESP3.build.blob(logString)
133
+ );
134
+
135
+ that.reader(data => {
136
+ if (data.charAt(0) === '-') {
137
+ reject(new Error(RESP3.parse.simpleError(data)))
138
+
139
+ return
140
+ }
141
+
142
+ resolve()
143
+ })
144
+ })
145
+ }
146
+
147
+ getCurrentSettings = function () {
148
+ const that = this
149
+ const RESP3 = that.objRoot.RESP3
150
+
151
+ return new Promise(function (resolve, reject) {
152
+ if (that.connected === false || that.loggedIn === false) {
153
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
154
+
155
+ return
156
+ }
157
+
158
+ // send command
159
+ const opCode = 'session.getCurrentSettings'
160
+ that.writer("*1" + RESP3.CRLF +
161
+ RESP3.build.blob(opCode)
162
+ );
163
+
164
+ that.reader(data => {
165
+ if (data.charAt(0) === '-') {
166
+ reject(new Error(RESP3.parse.simpleError(data)))
167
+
168
+ return
169
+ }
170
+
171
+ if (data.indexOf('+no data') > -1) {
172
+ resolve({})
173
+
174
+ return
175
+ }
176
+
177
+ resolve(JSON.parse(RESP3.parse.blob(data)))
178
+ })
179
+ })
180
+ }
181
+
182
+ setIdleTimeout = function (timeout) {
183
+ const that = this
184
+ const RESP3 = that.objRoot.RESP3
185
+
186
+ return new Promise(function (resolve, reject) {
187
+ if (that.connected === false || that.loggedIn === false) {
188
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
189
+
190
+ return
191
+ }
192
+
193
+ if (typeof (timeout) !== 'number') {
194
+ reject(new Error(errors.PARAM_NOT_NUMBER + 'timeout must be a number greater than -1'))
195
+
196
+ return
197
+ }
198
+
199
+ if (timeout < 0) {
200
+ reject(new Error(errors.PARAM_NOT_ZERO_OR_GREATER + 'timeout must be zero or higher'))
201
+
202
+ return
203
+ }
204
+
205
+ // send command
206
+ const opCode = 'session.setIdleTimeout'
207
+ that.writer("*2" + RESP3.CRLF +
208
+ RESP3.build.blob(opCode) +
209
+ RESP3.build.blob(timeout)
210
+ );
211
+
212
+ that.reader(data => {
213
+ if (data.charAt(0) === '-') {
214
+ reject(new Error(RESP3.parse.simpleError(data)))
215
+
216
+ return
217
+ }
218
+
219
+ if (data.indexOf('+no data') > -1) {
220
+ //reject(new Error('No stats enabled on server'))
221
+ resolve({})
222
+
223
+ return
224
+ }
225
+
226
+ resolve()
227
+ })
228
+ })
229
+ }
230
+
231
+ setErrorDump = function (value) {
232
+ const that = this
233
+ const RESP3 = that.objRoot.RESP3
234
+
235
+ return new Promise(function (resolve, reject) {
236
+ if (that.connected === false || that.loggedIn === false) {
237
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
238
+
239
+ return
240
+ }
241
+
242
+ if (typeof (value) !== 'number') {
243
+ reject(new Error(errors.PARAM_NOT_NUMBER + 'timeout must be a number greater than -1'))
244
+
245
+ return
246
+ }
247
+
248
+ if (value < 0 || value > 2) {
249
+ reject(new Error(errors.PARAM_NOT_ZERO_OR_GREATER + 'timeout must be between 0 and 2'))
250
+
251
+ return
252
+ }
253
+
254
+ // send command
255
+ const opCode = 'session.setErrorDump'
256
+ that.writer("*2" + RESP3.CRLF +
257
+ RESP3.build.blob(opCode) +
258
+ RESP3.build.blob(value)
259
+ );
260
+
261
+ that.reader(data => {
262
+ if (data.charAt(0) === '-') {
263
+ reject(new Error(RESP3.parse.simpleError(data)))
264
+
265
+ return
266
+ }
267
+
268
+ if (data.indexOf('+no data') > -1) {
269
+ //reject(new Error('No stats enabled on server'))
270
+ resolve({})
271
+
272
+ return
273
+ }
274
+
275
+ resolve()
276
+ })
277
+ })
278
+ }
279
+
280
+ setStats = function (value) {
281
+ const that = this
282
+ const RESP3 = that.objRoot.RESP3
283
+
284
+ return new Promise(function (resolve, reject) {
285
+ if (that.connected === false || that.loggedIn === false) {
286
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
287
+
288
+ return
289
+ }
290
+
291
+ if (typeof (value) !== 'number') {
292
+ reject(new Error(errors.PARAM_NOT_NUMBER + 'timeout must be a number greater than -1'))
293
+
294
+ return
295
+ }
296
+
297
+ if (value < 0 || value > 2) {
298
+ reject(new Error(errors.PARAM_NOT_BETWEEN_ZERO_AND_ONE + 'timeout must be between 0 and 2'))
299
+
300
+ return
301
+ }
302
+
303
+ // send command
304
+ const opCode = 'session.setStats'
305
+ that.writer("*2" + RESP3.CRLF +
306
+ RESP3.build.blob(opCode) +
307
+ RESP3.build.blob(value)
308
+ );
309
+
310
+ that.reader(data => {
311
+ if (data.charAt(0) === '-') {
312
+ reject(new Error(RESP3.parse.simpleError(data)))
313
+
314
+ return
315
+ }
316
+
317
+ if (data.indexOf('+no data') > -1) {
318
+ //reject(new Error('No stats enabled on server'))
319
+ resolve({})
320
+
321
+ return
322
+ }
323
+
324
+ resolve()
325
+ })
326
+ })
327
+ }
328
+
329
+ setDumpRequest = function (value) {
330
+ const that = this
331
+ const RESP3 = that.objRoot.RESP3
332
+
333
+ return new Promise(function (resolve, reject) {
334
+ if (that.connected === false || that.loggedIn === false) {
335
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
336
+
337
+ return
338
+ }
339
+
340
+ if (typeof (value) !== 'number') {
341
+ reject(new Error(errors.PARAM_NOT_NUMBER + 'timeout must be a number greater than -1'))
342
+
343
+ return
344
+ }
345
+
346
+ if (value < 0 || value > 1) {
347
+ reject(new Error(errors.PARAM_NOT_ZERO_OR_ONE + 'timeout must be between 0 and 1'))
348
+
349
+ return
350
+ }
351
+
352
+ // send command
353
+ const opCode = 'session.setDumpRequest'
354
+ that.writer("*2" + RESP3.CRLF +
355
+ RESP3.build.blob(opCode) +
356
+ RESP3.build.blob(value)
357
+ );
358
+
359
+ that.reader(data => {
360
+ if (data.charAt(0) === '-') {
361
+ reject(new Error(RESP3.parse.simpleError(data)))
362
+
363
+ return
364
+ }
365
+
366
+ if (data.indexOf('+no data') > -1) {
367
+ //reject(new Error('No stats enabled on server'))
368
+ resolve({})
369
+
370
+ return
371
+ }
372
+
373
+ resolve()
374
+ })
375
+ })
376
+ }
377
+
378
+ setDumpResponse = function (value) {
379
+ const that = this
380
+ const RESP3 = that.objRoot.RESP3
381
+
382
+ return new Promise(function (resolve, reject) {
383
+ if (that.connected === false || that.loggedIn === false) {
384
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
385
+
386
+ return
387
+ }
388
+
389
+ if (typeof (value) !== 'number') {
390
+ reject(new Error(errors.PARAM_NOT_NUMBER + 'timeout must be a number greater than -1'))
391
+
392
+ return
393
+ }
394
+
395
+ if (value < 0 || value > 1) {
396
+ reject(new Error(errors.PARAM_NOT_ZERO_OR_ONE + 'timeout must be between 0 and 1'))
397
+
398
+ return
399
+ }
400
+
401
+ // send command
402
+ const opCode = 'session.setDumpResponse'
403
+ that.writer("*2" + RESP3.CRLF +
404
+ RESP3.build.blob(opCode) +
405
+ RESP3.build.blob(value)
406
+ );
407
+
408
+ that.reader(data => {
409
+ if (data.charAt(0) === '-') {
410
+ reject(new Error(RESP3.parse.simpleError(data)))
411
+
412
+ return
413
+ }
414
+
415
+ if (data.indexOf('+no data') > -1) {
416
+ //reject(new Error('No stats enabled on server'))
417
+ resolve({})
418
+
419
+ return
420
+ }
421
+
422
+ resolve()
423
+ })
424
+ })
425
+ }
426
+
427
+ setLogLevel = function (value) {
428
+ const that = this
429
+ const RESP3 = that.objRoot.RESP3
430
+
431
+ return new Promise(function (resolve, reject) {
432
+ if (that.connected === false || that.loggedIn === false) {
433
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
434
+
435
+ return
436
+ }
437
+
438
+ if (typeof (value) !== 'number') {
439
+ reject(new Error(errors.PARAM_NOT_NUMBER + 'timeout must be a number greater than -1'))
440
+
441
+ return
442
+ }
443
+
444
+ if (value < 0 || value > 3) {
445
+ reject(new Error(errors.PARAM_NOT_BETWEEN_ZERO_AND_THREE + 'timeout must be between 0 and 3'))
446
+
447
+ return
448
+ }
449
+
450
+ // send command
451
+ const opCode = 'session.setLogLevel'
452
+ that.writer("*2" + RESP3.CRLF +
453
+ RESP3.build.blob(opCode) +
454
+ RESP3.build.blob(value)
455
+ );
456
+
457
+ that.reader(data => {
458
+ if (data.charAt(0) === '-') {
459
+ reject(new Error(RESP3.parse.simpleError(data)))
460
+
461
+ return
462
+ }
463
+
464
+ if (data.indexOf('+no data') > -1) {
465
+ //reject(new Error('No stats enabled on server'))
466
+ resolve({})
467
+
468
+ return
469
+ }
470
+
471
+ resolve()
472
+ })
473
+ })
474
+
475
+ }
476
+
477
+ resetSettings = function () {
478
+ const that = this
479
+ const RESP3 = that.objRoot.RESP3
480
+
481
+ return new Promise(function (resolve, reject) {
482
+ if (that.connected === false || that.loggedIn === false) {
483
+ reject(new Error(errors.NOT_LOGGED_IN + 'Not logged in'))
484
+
485
+ return
486
+ }
487
+
488
+ // send command
489
+ const opCode = 'session.resetSettings'
490
+ that.writer("*1" + RESP3.CRLF +
491
+ RESP3.build.blob(opCode)
492
+ );
493
+
494
+ that.reader(data => {
495
+ if (data.charAt(0) === '-') {
496
+ reject(new Error(RESP3.parse.simpleError(data)))
497
+
498
+ return
499
+ }
500
+
501
+ if (data.indexOf('+no data') > -1) {
502
+ //reject(new Error('No stats enabled on server'))
503
+ resolve({})
504
+
505
+ return
506
+ }
507
+
508
+ resolve()
509
+ })
510
+ })
511
+ }
512
+
513
+ _init = function (obj) {
514
+ Object.defineProperties(obj, {
515
+ ERROR_DUMP_NONE: {
516
+ value: 0,
517
+ enumerable: true,
518
+ configurable: true,
519
+ writable: false
520
+ },
521
+
522
+ ERROR_DUMP_BRIEF: {
523
+ value: 1,
524
+ enumerable: true,
525
+ configurable: true,
526
+ writable: false
527
+ },
528
+
529
+ ERROR_DUMP_FULL: {
530
+ value: 2,
531
+ enumerable: true,
532
+ configurable: true,
533
+ writable: false
534
+ },
535
+
536
+ STATS_NONE: {
537
+ value: 0,
538
+ enumerable: true,
539
+ configurable: true,
540
+ writable: false
541
+ },
542
+
543
+ STATS_GRAND_TOTALS: {
544
+ value: 1,
545
+ enumerable: true,
546
+ configurable: true,
547
+ writable: false
548
+ },
549
+
550
+ STATS_DETAILS: {
551
+ value: 2,
552
+ enumerable: true,
553
+ configurable: true,
554
+ writable: false
555
+ },
556
+
557
+ DUMP_REQUEST_OFF: {
558
+ value: 0,
559
+ enumerable: true,
560
+ configurable: true,
561
+ writable: false
562
+ },
563
+
564
+ DUMP_REQUEST_ON: {
565
+ value: 1,
566
+ enumerable: true,
567
+ configurable: true,
568
+ writable: false
569
+ },
570
+
571
+ DUMP_RESPONSE_OFF: {
572
+ value: 0,
573
+ enumerable: true,
574
+ configurable: true,
575
+ writable: false
576
+ },
577
+
578
+ DUMP_RESPONSE_ON: {
579
+ value: 1,
580
+ enumerable: true,
581
+ configurable: true,
582
+ writable: false
583
+ },
584
+
585
+ LOG_LEVEL_NONE: {
586
+ value: 0,
587
+ enumerable: true,
588
+ configurable: true,
589
+ writable: false
590
+ },
591
+
592
+ LOG_LEVEL_SESSIONS: {
593
+ value: 1,
594
+ enumerable: true,
595
+ configurable: true,
596
+ writable: false
597
+ },
598
+
599
+ LOG_LEVEL_COMMANDS: {
600
+ value: 2,
601
+ enumerable: true,
602
+ configurable: true,
603
+ writable: false
604
+ },
605
+
606
+ LOG_LEVEL_TIMINGS: {
607
+ value: 3,
608
+ enumerable: true,
609
+ configurable: true,
610
+ writable: false
611
+ },
612
+ })
613
+ Object.defineProperties(obj, {
614
+ _init: {
615
+ enumerable: false,
616
+ }
617
+
618
+ })
619
+ }
620
+ }
621
+
622
+ module.exports = Session