@tchain/tcabci-read-js-client 2.5.0 → 2.5.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.
package/client.js CHANGED
@@ -18,8 +18,9 @@ import {
18
18
  } from './constants.js'
19
19
  import Message from './message.js'
20
20
  import { isJSON, toJSON } from './util.js'
21
- import { DefaultTimeout, Options } from './websocketOptions.js'
21
+ import { Options } from './websocketOptions.js'
22
22
  import { TWebSocket } from './websocket.js'
23
+ import pkg from './package.json' with { type: 'json' }
23
24
 
24
25
  /**
25
26
  * @callback successCallback
@@ -48,7 +49,7 @@ export default class TCaBCIClient {
48
49
  _connected = false
49
50
  _chainName = 'transferchain'
50
51
  _chainVersion = 'v1'
51
- _version = 'v2.3.0'
52
+ _version = `v${pkg.version}`
52
53
  /**
53
54
  * @type {?successCallback}
54
55
  */
@@ -110,13 +111,8 @@ export default class TCaBCIClient {
110
111
  httpClient(uri, req) {
111
112
  req.cache = 'no-cache'
112
113
  req.headers = {
113
- Client: `tcabaci-read-js-client${this._version}`,
114
+ Client: `tcabaci-read-js-client-${this._version}`,
114
115
  }
115
-
116
- if (typeof AbortSignal !== 'undefined') {
117
- req.signal = AbortSignal.timeout(10000)
118
- }
119
-
120
116
  req.priority = 'high'
121
117
 
122
118
  return fetch(this._readNodeAddress + uri, req).then((response) =>
@@ -670,11 +666,12 @@ export default class TCaBCIClient {
670
666
  return { status: message.data }
671
667
  }
672
668
 
673
- this.callListenCallback(!isJSON(message.data) ? message.data : toJSON(message.data))
669
+ this.callListenCallback(
670
+ !isJSON(message.data) ? message.data : toJSON(message.data),
671
+ )
674
672
  })
675
673
 
676
674
  this._ws.addCloseListener((e) => {
677
- console.log('came gggg ', e)
678
675
  this.setConnected(false)
679
676
  this.setSubscribed(false)
680
677
  this.setSubscribeAddresses([], false)
package/client_test.js CHANGED
@@ -5,11 +5,8 @@ import {
5
5
  TRANSACTION_NOT_BROADCAST,
6
6
  TRANSACTION_TYPE_NOT_VALID,
7
7
  } from './errors.js'
8
- import {
9
- READ_NODE_ADDRESS,
10
- READ_NODE_WS_ADDRESS,
11
- TX_TYPE,
12
- } from './constants.js'
8
+ import { READ_NODE_ADDRESS, READ_NODE_WS_ADDRESS } from './constants.js'
9
+ import { TX_TYPE_ADDRESS } from './transaction.js'
13
10
 
14
11
  const waiter = async (timeout = 1000) => {
15
12
  return new Promise((resolve) => setTimeout(resolve, timeout))
@@ -311,7 +308,7 @@ describe('TCaBCIClient', () => {
311
308
  .Broadcast({
312
309
  id: 'dummy id',
313
310
  version: 0,
314
- type: TX_TYPE.TX_TYPE_ADDRESS,
311
+ type: TX_TYPE_ADDRESS,
315
312
  data: btoa(JSON.stringify({ data: '' })),
316
313
  sender_addr:
317
314
  '2mSCzresfg8Gwu7LZ9k9BTWkQAcQEkvYHFUSCZE2ubM4QV89PTeSYwQDqBas3ykq2emHEK6VRvxdgoe1vrhBbQGN',
package/constants.js CHANGED
@@ -4,53 +4,4 @@ export const MESSAGE_TYPE = {
4
4
  },
5
5
  CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
6
6
  READ_NODE_ADDRESS = 'https://read-node-01.transferchain.io',
7
- READ_NODE_WS_ADDRESS = 'wss://read-node-01.transferchain.io/ws',
8
- TX_TYPE = {
9
- TX_TYPE_MASTER: 'initial_storage',
10
- TX_TYPE_ADDRESS: 'interim_storage',
11
- TX_TYPE_ADDRESSES: 'interim_storages',
12
- TX_TYPE_ACCOUNT: 'initial_account',
13
- TX_TYPE_ACCOUNT_INITIAL_TXS: 'initial_account_txs',
14
- TX_TYPE_MESSAGE: 'message',
15
- TX_TYPE_MESSAGE_SENT: 'inherit_message',
16
- TX_TYPE_MESSAGE_THREAD_DELETE: 'inherit_message_recv',
17
- TX_TYPE_TRANSFER: 'transfer',
18
- TX_TYPE_TRANSFER_CANCEL: 'transfer_Cancel',
19
- TX_TYPE_TRANSFER_SENT: 'transfer_sent',
20
- TX_TYPE_TRANSFER_RECEIVE_DELETE: 'transfer_receive_delete',
21
- TX_TYPE_TRANSFER_INFO: 'transfer_info',
22
- TX_TYPE_STORAGE: 'storage',
23
- TX_TYPE_STORAGE_DELETE: 'storage_delete',
24
- TX_TYPE_BACKUP: 'backup',
25
- TX_TYPE_CONTACT: 'interim_message',
26
- TX_TYPE_FILE_VIRTUAL: 'fs_virt',
27
- TX_TYPE_FILE_FS: 'fs_real',
28
- TX_TYPE_RFILE_VIRTUAL: 'fs_rvirt',
29
- TX_TYPE_RFILE_FS: 'fs_rreal',
30
- TX_TYPE_DFILE_VIRTUAL: 'fs_dvirt',
31
- TX_TYPE_DFILE_FS: 'fs_dreal',
32
- TX_TYPE_PFILE_VIRTUAL: 'fs_pvirt',
33
- TX_TYPE_REQUEST: 'request',
34
- TX_TYPE_REQUEST_IN: 'request_in',
35
- TX_TYPE_REQUEST_UPLOAD: 'request_upload',
36
- TX_TYPE_REQUEST_CANCEL: 'request_Cancel',
37
- TX_TYPE_DATA_ROOM: 'data_room',
38
- TX_TYPE_DATA_ROOMF: 'data_roomF',
39
- TX_TYPE_DATA_ROOM_POLICY: 'data_room_policy',
40
- TX_TYPE_DATA_ROOM_DATA: 'data_room_data',
41
- TX_TYPE_DATA_ROOM_DATA_DELETE: 'data_room_data_delete',
42
- TX_TYPE_DATA_ROOM_DATA_POLICY: 'data_room_data_policy',
43
- TX_TYPE_MULTI_DATA_ROOM: 'multi_data_room',
44
- TX_TYPE_MULTI_STORAGE: 'multi_storage',
45
- TX_TYPE_MULTI_TRANSFER: 'multi_transfer',
46
- TX_TYPE_MULTI_TRANSFER_SENT: 'multi_transfer_sent',
47
- TX_TYPE_MULTI_BACKUP: 'multi_backup',
48
- TX_TYPE_MULTI_PASSWD: 'multi_passwd',
49
- TX_TYPE_PASSWD_DATA: 'passwd_data',
50
- TX_TYPE_PASSWD_ROOM: 'passwd_room',
51
- TX_TYPE_PASSWD_ROOMF: 'passwd_roomF',
52
- TX_TYPE_PASSWD_ROOM_POLICY: 'passwd_room_policy',
53
- TX_TYPE_PASSWD_ROOM_DATA: 'passwd_room_data',
54
- TX_TYPE_PASSWD_ROOM_DATA_DELETE: 'passwd_room_data_delete',
55
- TX_TYPE_PASSWD_ROOM_DATA_POLICY: 'passwd_room_data_policy',
56
- }
7
+ READ_NODE_WS_ADDRESS = 'wss://read-node-01.transferchain.io/ws'
package/package.json CHANGED
@@ -1,15 +1,13 @@
1
1
  {
2
2
  "name": "@tchain/tcabci-read-js-client",
3
- "version": "2.5.0",
3
+ "version": "2.5.2",
4
4
  "description": "TransferChain Fastest Read Network WebSocket Client",
5
5
  "main": "client.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "test": "export NODE_ENV=test || SET \"NODE_ENV=test\" && mocha --timeout 5000",
9
- "test:coverage": "export NODE_ENV=test || SET \"NODE_ENV=test\" && nyc --reporter=text mocha --timeout 5000",
10
- "lint": "eslint --ext .js ./",
11
- "lint-fix": "eslint --fix --ext .js ./",
12
- "lint-fix-file": "eslint --fix --ext .js",
8
+ "test": "export NODE_ENV=test || SET \"NODE_ENV=test\" && mocha --require esm --timeout 5000",
9
+ "test:all": "export NODE_ENV=test || SET \"NODE_ENV=test\" && mocha --require esm --timeout 5000 '*_test.js'",
10
+ "test:coverage": "export NODE_ENV=test || SET \"NODE_ENV=test\" && nyc --reporter=text mocha --require esm --timeout 5000",
13
11
  "format": "prettier --write \"**/*.{js,md,json}\" --ignore-path .gitignore"
14
12
  },
15
13
  "repository": {
@@ -23,13 +21,11 @@
23
21
  },
24
22
  "homepage": "https://github.com/TransferChain/tcabci-read-js-client#readme",
25
23
  "devDependencies": {
26
- "chai": "^5.2.1",
27
- "eslint": "^9.15.0",
28
- "eslint-config-prettier": "^9.1.0",
29
- "eslint-plugin-import": "^2.31.0",
30
- "eslint-plugin-node": "^11.1.0",
31
- "eslint-plugin-promise": "^7.1.0",
24
+ "@eslint/js": "^9.34.0",
25
+ "chai": "^6.0.1",
26
+ "esm": "*",
32
27
  "express": "^5.1.0",
28
+ "globals": "^16.3.0",
33
29
  "mocha": "^11.7.1",
34
30
  "nyc": "^17.1.0",
35
31
  "prettier": "^3.6.2",
package/transaction.js CHANGED
@@ -1,10 +1,110 @@
1
1
  import { INVALID_ARGUMENT_WITH_CS } from './errors.js'
2
2
 
3
+ export const TX_TYPE_MASTER = 'initial_storage',
4
+ TX_TYPE_ADDRESS = 'interim_storage',
5
+ TX_TYPE_ADDRESSES = 'interim_storages',
6
+ TX_TYPE_ACCOUNT = 'initial_account',
7
+ TX_TYPE_ACCOUNT_INITIAL_TXS = 'initial_account_txs',
8
+ TX_TYPE_MESSAGE = 'message',
9
+ TX_TYPE_MESSAGE_SENT = 'inherit_message',
10
+ TX_TYPE_MESSAGE_THREAD_DELETE = 'inherit_message_recv',
11
+ TX_TYPE_TRANSFER = 'transfer',
12
+ TX_TYPE_TRANSFER_CANCEL = 'transfer_Cancel',
13
+ TX_TYPE_TRANSFER_SENT = 'transfer_sent',
14
+ TX_TYPE_TRANSFER_RECEIVE_DELETE = 'transfer_receive_delete',
15
+ TX_TYPE_TRANSFER_INFO = 'transfer_info',
16
+ TX_TYPE_STORAGE = 'storage',
17
+ TX_TYPE_STORAGE_DELETE = 'storage_delete',
18
+ TX_TYPE_BACKUP = 'backup',
19
+ TX_TYPE_CONTACT = 'interim_message',
20
+ TX_TYPE_FILE_VIRTUAL = 'fs_virt',
21
+ TX_TYPE_FILE_FS = 'fs_real',
22
+ TX_TYPE_RFILE_VIRTUAL = 'fs_rvirt',
23
+ TX_TYPE_RFILE_FS = 'fs_rreal',
24
+ TX_TYPE_DFILE_VIRTUAL = 'fs_dvirt',
25
+ TX_TYPE_DFILE_FS = 'fs_dreal',
26
+ TX_TYPE_PFILE_VIRTUAL = 'fs_pvirt',
27
+ TX_TYPE_REQUEST = 'request',
28
+ TX_TYPE_REQUEST_IN = 'request_in',
29
+ TX_TYPE_REQUEST_UPLOAD = 'request_upload',
30
+ TX_TYPE_REQUEST_CANCEL = 'request_Cancel',
31
+ TX_TYPE_DATA_ROOM = 'data_room',
32
+ TX_TYPE_DATA_ROOMF = 'data_roomF',
33
+ TX_TYPE_DATA_ROOM_POLICY = 'data_room_policy',
34
+ TX_TYPE_DATA_ROOM_DATA = 'data_room_data',
35
+ TX_TYPE_DATA_ROOM_DATA_DELETE = 'data_room_data_delete',
36
+ TX_TYPE_DATA_ROOM_DATA_POLICY = 'data_room_data_policy',
37
+ TX_TYPE_MULTI_DATA_ROOM = 'multi_data_room',
38
+ TX_TYPE_MULTI_STORAGE = 'multi_storage',
39
+ TX_TYPE_MULTI_TRANSFER = 'multi_transfer',
40
+ TX_TYPE_MULTI_TRANSFER_SENT = 'multi_transfer_sent',
41
+ TX_TYPE_MULTI_BACKUP = 'multi_backup',
42
+ TX_TYPE_MULTI_PASSWD = 'multi_passwd',
43
+ TX_TYPE_PASSWD_DATA = 'passwd_data',
44
+ TX_TYPE_PASSWD_ROOM = 'passwd_room',
45
+ TX_TYPE_PASSWD_ROOMF = 'passwd_roomF',
46
+ TX_TYPE_PASSWD_ROOM_POLICY = 'passwd_room_policy',
47
+ TX_TYPE_PASSWD_ROOM_DATA = 'passwd_room_data',
48
+ TX_TYPE_PASSWD_ROOM_DATA_DELETE = 'passwd_room_data_delete',
49
+ TX_TYPE_PASSWD_ROOM_DATA_POLICY = 'passwd_room_data_policy',
50
+ TX_TYPE_PASSWD_DATAV2 = 'pwdd',
51
+ TX_TYPE_PASSWD_DATAV2_POLICY = 'pwdd_policy',
52
+ TX_TYPE = {
53
+ TX_TYPE_MASTER: TX_TYPE_MASTER,
54
+ TX_TYPE_ADDRESS: TX_TYPE_ADDRESS,
55
+ TX_TYPE_ADDRESSES: TX_TYPE_ADDRESSES,
56
+ TX_TYPE_ACCOUNT: TX_TYPE_ACCOUNT,
57
+ TX_TYPE_ACCOUNT_INITIAL_TXS: TX_TYPE_ACCOUNT_INITIAL_TXS,
58
+ TX_TYPE_MESSAGE: TX_TYPE_MESSAGE,
59
+ TX_TYPE_MESSAGE_SENT: TX_TYPE_MESSAGE_SENT,
60
+ TX_TYPE_MESSAGE_THREAD_DELETE: TX_TYPE_MESSAGE_THREAD_DELETE,
61
+ TX_TYPE_TRANSFER: TX_TYPE_TRANSFER,
62
+ TX_TYPE_TRANSFER_CANCEL: TX_TYPE_TRANSFER_CANCEL,
63
+ TX_TYPE_TRANSFER_SENT: TX_TYPE_TRANSFER_SENT,
64
+ TX_TYPE_TRANSFER_RECEIVE_DELETE: TX_TYPE_TRANSFER_RECEIVE_DELETE,
65
+ TX_TYPE_TRANSFER_INFO: TX_TYPE_TRANSFER_INFO,
66
+ TX_TYPE_STORAGE: TX_TYPE_STORAGE,
67
+ TX_TYPE_STORAGE_DELETE: TX_TYPE_STORAGE_DELETE,
68
+ TX_TYPE_BACKUP: TX_TYPE_BACKUP,
69
+ TX_TYPE_CONTACT: TX_TYPE_CONTACT,
70
+ TX_TYPE_FILE_VIRTUAL: TX_TYPE_FILE_VIRTUAL,
71
+ TX_TYPE_FILE_FS: TX_TYPE_FILE_FS,
72
+ TX_TYPE_RFILE_VIRTUAL: TX_TYPE_RFILE_VIRTUAL,
73
+ TX_TYPE_RFILE_FS: TX_TYPE_RFILE_FS,
74
+ TX_TYPE_DFILE_VIRTUAL: TX_TYPE_DFILE_VIRTUAL,
75
+ TX_TYPE_DFILE_FS: TX_TYPE_DFILE_FS,
76
+ TX_TYPE_PFILE_VIRTUAL: TX_TYPE_PFILE_VIRTUAL,
77
+ TX_TYPE_REQUEST: TX_TYPE_REQUEST,
78
+ TX_TYPE_REQUEST_IN: TX_TYPE_REQUEST_IN,
79
+ TX_TYPE_REQUEST_UPLOAD: TX_TYPE_REQUEST_UPLOAD,
80
+ TX_TYPE_REQUEST_CANCEL: TX_TYPE_REQUEST_CANCEL,
81
+ TX_TYPE_DATA_ROOM: TX_TYPE_DATA_ROOM,
82
+ TX_TYPE_DATA_ROOMF: TX_TYPE_DATA_ROOMF,
83
+ TX_TYPE_DATA_ROOM_POLICY: TX_TYPE_DATA_ROOM_POLICY,
84
+ TX_TYPE_DATA_ROOM_DATA: TX_TYPE_DATA_ROOM_DATA,
85
+ TX_TYPE_DATA_ROOM_DATA_DELETE: TX_TYPE_DATA_ROOM_DATA_DELETE,
86
+ TX_TYPE_DATA_ROOM_DATA_POLICY: TX_TYPE_DATA_ROOM_DATA_POLICY,
87
+ TX_TYPE_MULTI_DATA_ROOM: TX_TYPE_MULTI_DATA_ROOM,
88
+ TX_TYPE_MULTI_STORAGE: TX_TYPE_MULTI_STORAGE,
89
+ TX_TYPE_MULTI_TRANSFER: TX_TYPE_MULTI_TRANSFER,
90
+ TX_TYPE_MULTI_TRANSFER_SENT: TX_TYPE_MULTI_TRANSFER_SENT,
91
+ TX_TYPE_MULTI_BACKUP: TX_TYPE_MULTI_BACKUP,
92
+ TX_TYPE_MULTI_PASSWD: TX_TYPE_MULTI_PASSWD,
93
+ TX_TYPE_PASSWD_DATA: TX_TYPE_PASSWD_DATA,
94
+ TX_TYPE_PASSWD_ROOM: TX_TYPE_PASSWD_ROOM,
95
+ TX_TYPE_PASSWD_ROOMF: TX_TYPE_PASSWD_ROOMF,
96
+ TX_TYPE_PASSWD_ROOM_POLICY: TX_TYPE_PASSWD_ROOM_POLICY,
97
+ TX_TYPE_PASSWD_ROOM_DATA: TX_TYPE_PASSWD_ROOM_DATA,
98
+ TX_TYPE_PASSWD_ROOM_DATA_DELETE: TX_TYPE_PASSWD_ROOM_DATA_DELETE,
99
+ TX_TYPE_PASSWD_ROOM_DATA_POLICY: TX_TYPE_PASSWD_ROOM_DATA_POLICY,
100
+ TX_TYPE_PASSWD_DATAV2: TX_TYPE_PASSWD_DATAV2,
101
+ TX_TYPE_PASSWD_DATAV2_POLICY: TX_TYPE_PASSWD_DATAV2_POLICY,
102
+ },
103
+ TX_TYPE_LIST = Object.keys(TX_TYPE).map((k) => TX_TYPE[k])
104
+
3
105
  export default class Transaction {
4
106
  _id
5
- _block_id
6
107
  _height
7
- _identifier
8
108
  _version
9
109
  _typ
10
110
  _sender_addr
@@ -15,11 +115,23 @@ export default class Transaction {
15
115
  _hash
16
116
  _inserted_at
17
117
 
18
- constructor({
118
+ /**
119
+ * @param {string} id
120
+ * @param {number} height
121
+ * @param {number} version
122
+ * @param {string} typ
123
+ * @param {string} sender_addr
124
+ * @param {string} recipient_addr
125
+ * @param {string} data
126
+ * @param {string} sign
127
+ * @param {number} fee
128
+ * @param {string} hash
129
+ * @param {Date} inserted_at
130
+ * @throws Error
131
+ */
132
+ constructor(
19
133
  id,
20
- block_id,
21
134
  height,
22
- identifier,
23
135
  version,
24
136
  typ,
25
137
  sender_addr,
@@ -29,11 +141,9 @@ export default class Transaction {
29
141
  fee,
30
142
  hash,
31
143
  inserted_at,
32
- }) {
144
+ ) {
33
145
  this._id = id
34
- this._block_id = block_id
35
146
  this._height = height
36
- this._identifier = identifier
37
147
  this._version = version
38
148
  this._typ = typ
39
149
  this._sender_addr = sender_addr
@@ -43,16 +153,20 @@ export default class Transaction {
43
153
  this._fee = fee
44
154
  this._hash = hash
45
155
  this._inserted_at = inserted_at
156
+
157
+ this._validate()
46
158
  }
47
159
 
160
+ /**
161
+ * @return {string}
162
+ * @throws Error
163
+ */
48
164
  ToJSON() {
49
165
  this._validate()
50
166
 
51
167
  return JSON.stringify({
52
168
  id: this._id,
53
- block_id: this._block_id,
54
169
  height: this._height,
55
- identifier: this._identifier,
56
170
  version: this._version,
57
171
  typ: this._typ,
58
172
  sender_addr: this._sender_addr,
@@ -61,46 +175,31 @@ export default class Transaction {
61
175
  sign: this._sign,
62
176
  fee: this._fee,
63
177
  hash: this._hash,
64
- inserted_at: this._inserted_at,
178
+ inserted_at: this._inserted_at.toISOString(),
65
179
  })
66
180
  }
67
181
 
68
182
  _validate() {
69
- if (typeof this._id !== 'number') {
183
+ if (typeof this._id !== 'number')
70
184
  throw new Error(INVALID_ARGUMENT_WITH_CS('id'))
71
- }
72
- if (typeof this._block_id !== 'number') {
73
- throw new Error(INVALID_ARGUMENT_WITH_CS('blockID'))
74
- }
75
- if (typeof this._height !== 'number') {
185
+ if (typeof this._height !== 'number')
76
186
  throw new Error(INVALID_ARGUMENT_WITH_CS('height'))
77
- }
78
- if (typeof this._identifier !== 'string') {
79
- throw new Error(INVALID_ARGUMENT_WITH_CS('identifier'))
80
- }
81
- if (typeof this._version !== 'number') {
187
+ if (typeof this._version !== 'number')
82
188
  throw new Error(INVALID_ARGUMENT_WITH_CS('version'))
83
- }
84
- if (typeof this._typ !== 'string') {
189
+ if (typeof this._typ !== 'string')
85
190
  throw new Error(INVALID_ARGUMENT_WITH_CS('typ'))
86
- }
87
- if (typeof this._sender_addr !== 'string') {
191
+ if (!TX_TYPE[this._typ]) throw new Error(INVALID_ARGUMENT_WITH_CS('typ'))
192
+ if (typeof this._sender_addr !== 'string')
88
193
  throw new Error(INVALID_ARGUMENT_WITH_CS('senderAddr'))
89
- }
90
- if (typeof this._recipient_addr !== 'string') {
194
+ if (typeof this._recipient_addr !== 'string')
91
195
  throw new Error(INVALID_ARGUMENT_WITH_CS('recipientAddr'))
92
- }
93
- if (typeof this._data !== 'object') {
196
+ if (typeof this._data !== 'object')
94
197
  throw new Error(INVALID_ARGUMENT_WITH_CS('data'))
95
- }
96
- if (typeof this._sign !== 'object') {
198
+ if (typeof this._sign !== 'object')
97
199
  throw new Error(INVALID_ARGUMENT_WITH_CS('sign'))
98
- }
99
- if (typeof this._fee !== 'number') {
200
+ if (typeof this._fee !== 'number')
100
201
  throw new Error(INVALID_ARGUMENT_WITH_CS('fee'))
101
- }
102
- if (typeof this._inserted_at !== 'string') {
202
+ if (!(this._inserted_at instanceof Date))
103
203
  throw new Error(INVALID_ARGUMENT_WITH_CS('insertedAt'))
104
- }
105
204
  }
106
205
  }
package/util.js CHANGED
@@ -1,20 +1,3 @@
1
- import { CHARACTERS } from './constants.js'
2
-
3
- export function randomString(length) {
4
- let result = ''
5
-
6
- const charactersLength = CHARACTERS.length
7
-
8
- let counter = 0
9
-
10
- while (counter < length) {
11
- result += CHARACTERS.charAt(Math.floor(Math.random() * charactersLength))
12
- counter += 1
13
- }
14
-
15
- return result
16
- }
17
-
18
1
  export function toJSON(data) {
19
2
  return JSON.parse(data)
20
3
  }
@@ -1,3 +1,5 @@
1
+ import pkg from './package.json' with { type: 'json' }
2
+
1
3
  export const HTTPSPort = 443,
2
4
  HTTPPort = 80
3
5
 
@@ -13,6 +15,7 @@ export class Options {
13
15
  _protocols = []
14
16
  _customWS
15
17
  _endpoints = ['ws', 'longpoll']
18
+ _version = `v${pkg.version}`
16
19
 
17
20
  _maxConnectionDelay = 10000
18
21
  _minReconnectionDelay = 1000 + Math.random() * 4000
@@ -272,6 +275,9 @@ export class Options {
272
275
  maxEnqueuedMessages: this._maxEnqueuedMessages,
273
276
  startClosed: this._startClosed,
274
277
  debug: this._debug,
278
+ headers: {
279
+ Client: `tcabaci-read-js-client/${this._version}`,
280
+ },
275
281
  }
276
282
  }
277
283
  }
@@ -1,6 +1,11 @@
1
1
  import { describe, it } from 'mocha'
2
2
  import { expect } from 'chai'
3
- import { DefaultTimeout, HTTPPort, HTTPSPort, Options } from './websocketOptions.js'
3
+ import {
4
+ DefaultTimeout,
5
+ HTTPPort,
6
+ HTTPSPort,
7
+ Options,
8
+ } from './websocketOptions.js'
4
9
  import WebSocket from 'ws'
5
10
 
6
11
  describe('Options', () => {
package/websocket_test.js CHANGED
@@ -39,9 +39,7 @@ describe('WebSocket', () => {
39
39
  wsTwo = w
40
40
  wsTwo.on('error', console.error)
41
41
 
42
- wsTwo.on('message', function message(data) {
43
-
44
- })
42
+ wsTwo.on('message', function message(data) {})
45
43
  })
46
44
 
47
45
  setTimeout(() => {
@@ -64,6 +62,7 @@ describe('WebSocket', () => {
64
62
  options.setMaxConnectionDelay(100)
65
63
  options.setMinReconnectionDelay(100)
66
64
  options.setCustomWS(WebSocket)
65
+ options.setDebug(true)
67
66
 
68
67
  const twSocket = new TWebSocket(options)
69
68
 
@@ -83,6 +82,7 @@ describe('WebSocket', () => {
83
82
  options.setMaxConnectionDelay(100)
84
83
  options.setMinReconnectionDelay(100)
85
84
  options.setCustomWS(WebSocket)
85
+ options.setDebug(true)
86
86
 
87
87
  const twSocket = new TWebSocket(options)
88
88
 
@@ -101,6 +101,7 @@ describe('WebSocket', () => {
101
101
  options.setMaxConnectionDelay(100)
102
102
  options.setMinReconnectionDelay(100)
103
103
  options.setCustomWS(WebSocket)
104
+ options.setDebug(true)
104
105
 
105
106
  const twSocket = new TWebSocket(options)
106
107
 
@@ -129,6 +130,7 @@ describe('WebSocket', () => {
129
130
  options.setMaxConnectionDelay(100)
130
131
  options.setMinReconnectionDelay(100)
131
132
  options.setCustomWS(WebSocket)
133
+ options.setDebug(true)
132
134
 
133
135
  const twSocket = new TWebSocket(options)
134
136
 
@@ -149,6 +151,7 @@ describe('WebSocket', () => {
149
151
  options.setMaxConnectionDelay(100)
150
152
  options.setMinReconnectionDelay(100)
151
153
  options.setCustomWS(WebSocket)
154
+ options.setDebug(true)
152
155
 
153
156
  const twSocket = new TWebSocket(options)
154
157
 
@@ -169,6 +172,7 @@ describe('WebSocket', () => {
169
172
  options.setMaxConnectionDelay(100)
170
173
  options.setMinReconnectionDelay(100)
171
174
  options.setCustomWS(WebSocket)
175
+ options.setDebug(true)
172
176
 
173
177
  const twSocket = new TWebSocket(options)
174
178
 
@@ -189,6 +193,7 @@ describe('WebSocket', () => {
189
193
  options.setMaxConnectionDelay(100)
190
194
  options.setMinReconnectionDelay(100)
191
195
  options.setCustomWS(WebSocket)
196
+ options.setDebug(true)
192
197
 
193
198
  const twSocket = new TWebSocket(options)
194
199
 
@@ -209,6 +214,7 @@ describe('WebSocket', () => {
209
214
  options.setMaxConnectionDelay(100)
210
215
  options.setMinReconnectionDelay(100)
211
216
  options.setCustomWS(WebSocket)
217
+ options.setDebug(true)
212
218
 
213
219
  const twSocket = new TWebSocket(options)
214
220
 
@@ -232,6 +238,7 @@ describe('WebSocket', () => {
232
238
  options.setMaxConnectionDelay(100)
233
239
  options.setMinReconnectionDelay(100)
234
240
  options.setCustomWS(WebSocket)
241
+ options.setDebug(true)
235
242
 
236
243
  let opened = false,
237
244
  openCb = () => {
@@ -258,6 +265,7 @@ describe('WebSocket', () => {
258
265
  options.setMaxConnectionDelay(100)
259
266
  options.setMinReconnectionDelay(100)
260
267
  options.setCustomWS(WebSocket)
268
+ options.setDebug(true)
261
269
 
262
270
  let opened = false,
263
271
  openCb = () => {
@@ -279,6 +287,7 @@ describe('WebSocket', () => {
279
287
  options.setMaxConnectionDelay(100)
280
288
  options.setMinReconnectionDelay(100)
281
289
  options.setCustomWS(WebSocket)
290
+ options.setDebug(true)
282
291
 
283
292
  let opened = false,
284
293
  openCb = () => {
@@ -302,6 +311,7 @@ describe('WebSocket', () => {
302
311
  options.setMaxConnectionDelay(100)
303
312
  options.setMinReconnectionDelay(100)
304
313
  options.setCustomWS(WebSocket)
314
+ options.setDebug(true)
305
315
 
306
316
  let came = null,
307
317
  messageCb = (msg) => {
@@ -331,6 +341,7 @@ describe('WebSocket', () => {
331
341
  options.setMaxConnectionDelay(100)
332
342
  options.setMinReconnectionDelay(100)
333
343
  options.setCustomWS(WebSocket)
344
+ options.setDebug(true)
334
345
 
335
346
  let came = false,
336
347
  messageCb = () => {
@@ -352,6 +363,7 @@ describe('WebSocket', () => {
352
363
  options.setMaxConnectionDelay(100)
353
364
  options.setMinReconnectionDelay(100)
354
365
  options.setCustomWS(WebSocket)
366
+ options.setDebug(true)
355
367
 
356
368
  let came = false,
357
369
  messageCb = () => {
@@ -375,6 +387,7 @@ describe('WebSocket', () => {
375
387
  options.setMaxConnectionDelay(100)
376
388
  options.setMinReconnectionDelay(100)
377
389
  options.setCustomWS(WebSocket)
390
+ options.setDebug(true)
378
391
 
379
392
  let came = null,
380
393
  errorCb = (e) => {
@@ -407,6 +420,7 @@ describe('WebSocket', () => {
407
420
  options.setMaxConnectionDelay(100)
408
421
  options.setMinReconnectionDelay(100)
409
422
  options.setCustomWS(WebSocket)
423
+ options.setDebug(true)
410
424
 
411
425
  let came = false,
412
426
  errorCb = () => {
@@ -428,6 +442,7 @@ describe('WebSocket', () => {
428
442
  options.setMaxConnectionDelay(100)
429
443
  options.setMinReconnectionDelay(100)
430
444
  options.setCustomWS(WebSocket)
445
+ options.setDebug(true)
431
446
 
432
447
  let came = false,
433
448
  errorCb = () => {
@@ -451,6 +466,7 @@ describe('WebSocket', () => {
451
466
  options.setMaxConnectionDelay(100)
452
467
  options.setMinReconnectionDelay(100)
453
468
  options.setCustomWS(WebSocket)
469
+ options.setDebug(true)
454
470
 
455
471
  let came = null,
456
472
  closeCb = (e) => {
@@ -477,6 +493,7 @@ describe('WebSocket', () => {
477
493
  options.setMaxConnectionDelay(100)
478
494
  options.setMinReconnectionDelay(100)
479
495
  options.setCustomWS(WebSocket)
496
+ options.setDebug(true)
480
497
 
481
498
  let came = false,
482
499
  closeCb = () => {
@@ -498,6 +515,7 @@ describe('WebSocket', () => {
498
515
  options.setMaxConnectionDelay(100)
499
516
  options.setMinReconnectionDelay(100)
500
517
  options.setCustomWS(WebSocket)
518
+ options.setDebug(true)
501
519
 
502
520
  let came = false,
503
521
  closeCb = (e) => {
@@ -514,7 +532,6 @@ describe('WebSocket', () => {
514
532
  expect(twSocket.closeListeners.length).to.be.eq(0)
515
533
  })
516
534
 
517
-
518
535
  it('should error addOpenListener/1 if exceeded maximum listener size', async () => {
519
536
  const options = new Options('localhost', 100, false, 4442)
520
537
 
@@ -522,7 +539,7 @@ describe('WebSocket', () => {
522
539
  options.setMaxConnectionDelay(100)
523
540
  options.setMinReconnectionDelay(100)
524
541
  options.setCustomWS(WebSocket)
525
-
542
+ options.setDebug(true)
526
543
 
527
544
  const twSocket = new TWebSocket(options)
528
545
 
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- /dist
2
- /node_modules
3
- .eslintrc.js
package/.eslintrc.cjs DELETED
@@ -1,85 +0,0 @@
1
- module.exports = {
2
- root: true,
3
-
4
- parserOptions: {
5
- ecmaVersion: 2022, // Allows for the parsing of modern ECMAScript features
6
- },
7
-
8
- env: {
9
- node: true,
10
- browser: true,
11
- jest: true,
12
- },
13
-
14
- // Rules order is important, please avoid shuffling them
15
- extends: [
16
- // Base ESLint recommended rules
17
- 'eslint:recommended',
18
- 'plugin:import/recommended',
19
- 'plugin:import/errors',
20
- 'plugin:import/warnings',
21
- 'prettier',
22
- ],
23
-
24
- plugins: [
25
- 'import',
26
- ],
27
-
28
- globals: {
29
- ga: 'readonly', // Google Analytics
30
- __statics: 'readonly',
31
- process: 'readonly',
32
- chrome: 'readonly',
33
- global: 'readonly',
34
- Promise: 'readonly',
35
- },
36
-
37
- settings: {},
38
-
39
- // add your custom rules here
40
- rules: {
41
- 'import/named': 'error',
42
- 'import/namespace': 'error',
43
- 'import/default': 'error',
44
- 'import/export': 'error',
45
- 'import/extensions': 'off',
46
- 'import/prefer-default-export': 'off',
47
- 'generator-star-spacing': 'off',
48
- 'arrow-parens': 'off',
49
- 'import/first': 'off',
50
- 'import/no-unresolved': 'off',
51
- 'import/no-extraneous-dependencies': 'off',
52
- 'prefer-arrow-callback': ['error', { allowNamedFunctions: true }],
53
- 'no-underscore-dangle': 'off',
54
- 'no-prototype-builtins': 'warn',
55
- 'no-restricted-properties': 'off',
56
- 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
57
- 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
58
- indent: [
59
- 'error',
60
- 2,
61
- {
62
- SwitchCase: 1,
63
- MemberExpression: 1,
64
- ImportDeclaration: 1,
65
- // VariableDeclarator: { var: 2, let: 2, const: 3 },
66
- },
67
- ],
68
- 'brace-style': ['error', '1tbs', { allowSingleLine: true }],
69
- 'padded-blocks': ['error', { blocks: 'never' }],
70
- 'operator-linebreak': 'off',
71
- 'one-var': ['error', { var: 'never' }],
72
- 'lines-around-comment': 'off',
73
- 'padding-line-between-statements': [
74
- 'error',
75
- { blankLine: 'always', prev: 'function', next: 'function' },
76
- { blankLine: 'always', prev: 'function', next: 'block' },
77
- { blankLine: 'always', prev: 'block', next: 'function' },
78
- { blankLine: 'always', prev: 'var', next: '*' },
79
- { blankLine: 'always', prev: 'const', next: '*' },
80
- { blankLine: 'always', prev: 'let', next: '*' },
81
- { blankLine: 'always', prev: '*', next: 'return' },
82
- { blankLine: 'always', prev: '*', next: 'export' },
83
- ],
84
- },
85
- }