@tchain/tcabci-read-js-client 2.7.7 → 2.7.9
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 +3 -3
- package/block.d.ts +3 -3
- package/block.js +5 -2
- package/breaker.js +19 -17
- package/callback.d.ts +1 -1
- package/client.d.ts +20 -15
- package/client.js +54 -54
- package/constants.d.ts +1 -2
- package/errors.js +1 -1
- package/http.d.ts +1 -1
- package/http.js +6 -4
- package/message.d.ts +7 -5
- package/message.js +5 -2
- package/package.json +21 -22
- package/transaction.d.ts +4 -2
- package/transaction.js +13 -6
- package/util.d.ts +2 -2
- package/util.js +4 -1
- package/websocket.d.ts +1 -1
- package/websocket.js +9 -9
- package/websocketOptions.d.ts +1 -1
- package/websocketOptions.js +7 -4
package/README.md
CHANGED
|
@@ -25,18 +25,18 @@ const client = new TCaBCIClient()
|
|
|
25
25
|
// OR
|
|
26
26
|
const client = new TCaBCIClient([
|
|
27
27
|
'https://read-node-01.transferchain.io',
|
|
28
|
-
'wss://read-node-01.transferchain.io/ws'
|
|
28
|
+
'wss://read-node-01.transferchain.io/ws'
|
|
29
29
|
])
|
|
30
30
|
// OR
|
|
31
31
|
// With addresses and WebSocket library and network name, version
|
|
32
32
|
const client = new TCaBCIClient(
|
|
33
33
|
[
|
|
34
34
|
'https://read-node-01.transferchain.io',
|
|
35
|
-
'wss://read-node-01.transferchain.io/ws'
|
|
35
|
+
'wss://read-node-01.transferchain.io/ws'
|
|
36
36
|
],
|
|
37
37
|
WebSocket,
|
|
38
38
|
'transferchain',
|
|
39
|
-
'v1'
|
|
39
|
+
'v1'
|
|
40
40
|
)
|
|
41
41
|
|
|
42
42
|
client.Start()
|
package/block.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { Transaction } from './transaction'
|
|
|
3
3
|
export declare class Block {
|
|
4
4
|
get Height(): number
|
|
5
5
|
get TXS(): number
|
|
6
|
-
get Hash(): string|null
|
|
6
|
+
get Hash(): string | null
|
|
7
7
|
get Transactions(): Transaction[]
|
|
8
8
|
get ChainName(): string
|
|
9
9
|
get ChainVersion(): string
|
|
10
10
|
|
|
11
|
-
static FromJSON(value: string): { block?: Block
|
|
12
|
-
static FromObject(obj: Record<string, any>): { block?: Block
|
|
11
|
+
static FromJSON(value: string): { block?: Block; error?: Error }
|
|
12
|
+
static FromObject(obj: Record<string, any>): { block?: Block; error?: Error }
|
|
13
13
|
}
|
package/block.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Transaction } from './transaction.js'
|
|
2
|
+
import { Debug } from '@streetbyters/js-debug'
|
|
2
3
|
|
|
3
4
|
export class Block {
|
|
4
5
|
_height
|
|
@@ -55,7 +56,7 @@ export class Block {
|
|
|
55
56
|
if (typeof parsed.transactions !== 'undefined') {
|
|
56
57
|
for (let i = 0; i < parsed.transactions.length; i++) {
|
|
57
58
|
const { transaction, error } = Transaction.FromObject(
|
|
58
|
-
parsed.transactions[i]
|
|
59
|
+
parsed.transactions[i]
|
|
59
60
|
)
|
|
60
61
|
if (error) {
|
|
61
62
|
return { block: null, error: error }
|
|
@@ -67,6 +68,7 @@ export class Block {
|
|
|
67
68
|
|
|
68
69
|
return { block: bl, error: null }
|
|
69
70
|
} catch (e) {
|
|
71
|
+
Debug.error(e)
|
|
70
72
|
return { block: null, error: e }
|
|
71
73
|
}
|
|
72
74
|
}
|
|
@@ -92,7 +94,7 @@ export class Block {
|
|
|
92
94
|
if (typeof obj.transactions !== 'undefined') {
|
|
93
95
|
for (let i = 0; i < obj.transactions.length; i++) {
|
|
94
96
|
const { transaction, error } = Transaction.FromObject(
|
|
95
|
-
obj.transactions[i]
|
|
97
|
+
obj.transactions[i]
|
|
96
98
|
)
|
|
97
99
|
if (error) {
|
|
98
100
|
return { block: null, error: error }
|
|
@@ -104,6 +106,7 @@ export class Block {
|
|
|
104
106
|
|
|
105
107
|
return { block: bl, error: null }
|
|
106
108
|
} catch (e) {
|
|
109
|
+
Debug.error(e)
|
|
107
110
|
return { block: null, error: e }
|
|
108
111
|
}
|
|
109
112
|
}
|
package/breaker.js
CHANGED
|
@@ -4,36 +4,38 @@ import {
|
|
|
4
4
|
retry,
|
|
5
5
|
handleType,
|
|
6
6
|
circuitBreaker,
|
|
7
|
-
wrap
|
|
7
|
+
wrap
|
|
8
8
|
} from 'cockatiel'
|
|
9
9
|
import { FetchError } from './errors.js'
|
|
10
10
|
|
|
11
11
|
export class Breaker {
|
|
12
12
|
_options = {
|
|
13
13
|
halfOpenAfter: 10 * 1000,
|
|
14
|
-
breaker: new ConsecutiveBreaker(10)
|
|
14
|
+
breaker: new ConsecutiveBreaker(10)
|
|
15
15
|
}
|
|
16
16
|
_retryPolicy = retry(
|
|
17
|
-
handleType(FetchError, (err)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
handleType(FetchError, err => [502, 503, 504].includes(err.status)).orType(
|
|
18
|
+
Error,
|
|
19
|
+
err => {
|
|
20
|
+
return err.message.toLowerCase().search('failed to fetch') > -1
|
|
21
|
+
}
|
|
22
|
+
),
|
|
22
23
|
{
|
|
23
24
|
maxAttempts: 10,
|
|
24
25
|
backoff: new ExponentialBackoff({
|
|
25
26
|
initialDelay: 500,
|
|
26
|
-
maxDelay: 15000
|
|
27
|
-
})
|
|
28
|
-
}
|
|
27
|
+
maxDelay: 15000
|
|
28
|
+
})
|
|
29
|
+
}
|
|
29
30
|
)
|
|
30
31
|
_circuitBreakerPolicy = circuitBreaker(
|
|
31
|
-
handleType(FetchError, (err)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
handleType(FetchError, err => [502, 503, 504].includes(err.status)).orType(
|
|
33
|
+
Error,
|
|
34
|
+
err => {
|
|
35
|
+
return err.message.toLowerCase().search('failed to fetch') > -1
|
|
36
|
+
}
|
|
37
|
+
),
|
|
38
|
+
this._options
|
|
37
39
|
)
|
|
38
40
|
_retryWithBreaker = wrap(this._retryPolicy, this._circuitBreakerPolicy)
|
|
39
41
|
constructor() {}
|
|
@@ -43,7 +45,7 @@ export class Breaker {
|
|
|
43
45
|
* @return {Promise<*>}
|
|
44
46
|
*/
|
|
45
47
|
execute(fn) {
|
|
46
|
-
return this._retryWithBreaker.execute(fn).catch(
|
|
48
|
+
return this._retryWithBreaker.execute(fn).catch(err => {
|
|
47
49
|
return Promise.reject(err)
|
|
48
50
|
})
|
|
49
51
|
}
|
package/callback.d.ts
CHANGED
package/client.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { Transaction, TXType } from './transaction'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
SuccessCallback,
|
|
4
|
+
ErrorCallback,
|
|
5
|
+
CloseCallback,
|
|
6
|
+
ListenCallback
|
|
7
|
+
} from './callback'
|
|
3
8
|
|
|
4
9
|
declare class TCaBCIClient {
|
|
5
10
|
constructor(
|
|
6
11
|
readNodeAddresses: string[],
|
|
7
12
|
wsLibrary: WebSocket,
|
|
8
13
|
chainName: string,
|
|
9
|
-
chainVersion: string
|
|
14
|
+
chainVersion: string
|
|
10
15
|
)
|
|
11
16
|
SetDebug(debug: boolean): TCaBCIClient
|
|
12
17
|
SetSuccessCallback(cb: SuccessCallback): TCaBCIClient
|
|
@@ -30,13 +35,13 @@ declare class TCaBCIClient {
|
|
|
30
35
|
Subscribe(
|
|
31
36
|
addresses: string[],
|
|
32
37
|
signedData: Record<string, string>,
|
|
33
|
-
txTypes?: TXType[]
|
|
38
|
+
txTypes?: TXType[]
|
|
34
39
|
): TCaBCIClient
|
|
35
40
|
Unsubscribe(): TCaBCIClient
|
|
36
41
|
LastBlock(
|
|
37
42
|
chainName?: null,
|
|
38
|
-
chainVersion?: null
|
|
39
|
-
): { blocks: Transaction[]; total_count: number }
|
|
43
|
+
chainVersion?: null
|
|
44
|
+
): Promise<{ blocks: Transaction[]; total_count: number }>
|
|
40
45
|
Tx(id: string, signature: string): Promise<{ tx: Transaction }>
|
|
41
46
|
TxSummary({
|
|
42
47
|
recipientAddrs,
|
|
@@ -45,7 +50,7 @@ declare class TCaBCIClient {
|
|
|
45
50
|
typ,
|
|
46
51
|
types,
|
|
47
52
|
chainName,
|
|
48
|
-
chainVersion
|
|
53
|
+
chainVersion
|
|
49
54
|
}: Record<string, any>): Promise<{
|
|
50
55
|
chain_name: string
|
|
51
56
|
chain_version: string
|
|
@@ -71,8 +76,8 @@ declare class TCaBCIClient {
|
|
|
71
76
|
orderField,
|
|
72
77
|
orderBy,
|
|
73
78
|
chainName,
|
|
74
|
-
chainVersion
|
|
75
|
-
}): Promise<{ txs: Transaction[]; total_count: number }>
|
|
79
|
+
chainVersion
|
|
80
|
+
}: Record<string, any>): Promise<{ txs: Transaction[]; total_count: number }>
|
|
76
81
|
BroadcastCommit({
|
|
77
82
|
id,
|
|
78
83
|
version,
|
|
@@ -83,8 +88,8 @@ declare class TCaBCIClient {
|
|
|
83
88
|
sender_addr,
|
|
84
89
|
recipient_addr,
|
|
85
90
|
sign,
|
|
86
|
-
fee
|
|
87
|
-
}): Promise<{ data: Record<string, any> }>
|
|
91
|
+
fee
|
|
92
|
+
}: Record<string, any>): Promise<{ data: Record<string, any> }>
|
|
88
93
|
BroadcastSync({
|
|
89
94
|
id,
|
|
90
95
|
version,
|
|
@@ -95,8 +100,8 @@ declare class TCaBCIClient {
|
|
|
95
100
|
sender_addr,
|
|
96
101
|
recipient_addr,
|
|
97
102
|
sign,
|
|
98
|
-
fee
|
|
99
|
-
}): Promise<{ data: Record<string, any> }>
|
|
103
|
+
fee
|
|
104
|
+
}: Record<string, any>): Promise<{ data: Record<string, any> }>
|
|
100
105
|
Broadcast({
|
|
101
106
|
id,
|
|
102
107
|
version,
|
|
@@ -107,14 +112,14 @@ declare class TCaBCIClient {
|
|
|
107
112
|
sender_addr,
|
|
108
113
|
recipient_addr,
|
|
109
114
|
sign,
|
|
110
|
-
fee
|
|
111
|
-
}): Promise<{ data: Record<string, any> }>
|
|
115
|
+
fee
|
|
116
|
+
}: Record<string, any>): Promise<{ data: Record<string, any> }>
|
|
112
117
|
Bulk(
|
|
113
118
|
addresses: string[],
|
|
114
119
|
signedData: Record<string, any>,
|
|
115
120
|
maxHeight?: number,
|
|
116
121
|
chainName?: string,
|
|
117
|
-
chainVersion?: string
|
|
122
|
+
chainVersion?: string
|
|
118
123
|
): Promise<{ data: Record<string, any> }>
|
|
119
124
|
}
|
|
120
125
|
|
package/client.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
NOT_CONNECTED,
|
|
7
7
|
NOT_SUBSCRIBED,
|
|
8
8
|
TRANSACTION_NOT_BROADCAST,
|
|
9
|
-
TRANSACTION_TYPE_NOT_VALID
|
|
9
|
+
TRANSACTION_TYPE_NOT_VALID
|
|
10
10
|
} from './errors.js'
|
|
11
11
|
import { READ_NODE_ADDRESS, READ_NODE_WS_ADDRESS } from './constants.js'
|
|
12
12
|
import Message, {
|
|
@@ -15,7 +15,7 @@ import Message, {
|
|
|
15
15
|
SUBSCRIBEMessage,
|
|
16
16
|
UNSUBSCRIBEMessage,
|
|
17
17
|
Subscription,
|
|
18
|
-
OK
|
|
18
|
+
OK
|
|
19
19
|
} from './message.js'
|
|
20
20
|
import { Options } from './websocketOptions.js'
|
|
21
21
|
import { TWebSocket } from './websocket.js'
|
|
@@ -57,7 +57,7 @@ export default class TCaBCIClient {
|
|
|
57
57
|
_connected = false
|
|
58
58
|
_chainName = 'transferchain'
|
|
59
59
|
_chainVersion = 'v1'
|
|
60
|
-
_version = `v2.7.
|
|
60
|
+
_version = `v2.7.9`
|
|
61
61
|
/**
|
|
62
62
|
* @type {?SuccessCallback}
|
|
63
63
|
*/
|
|
@@ -97,7 +97,7 @@ export default class TCaBCIClient {
|
|
|
97
97
|
readNodeAddresses = [],
|
|
98
98
|
wsLibrary,
|
|
99
99
|
chainName = null,
|
|
100
|
-
chainVersion = null
|
|
100
|
+
chainVersion = null
|
|
101
101
|
) {
|
|
102
102
|
if (!wsLibrary) throw new Error(INVALID_ARGUMENTS)
|
|
103
103
|
this._wsLibrary = wsLibrary
|
|
@@ -221,7 +221,7 @@ export default class TCaBCIClient {
|
|
|
221
221
|
chain_name: this._chainName,
|
|
222
222
|
chain_version: this._chainVersion,
|
|
223
223
|
connected: this._connected,
|
|
224
|
-
subscribed: this._subscribed
|
|
224
|
+
subscribed: this._subscribed
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
|
|
@@ -275,8 +275,8 @@ export default class TCaBCIClient {
|
|
|
275
275
|
type: SUBSCRIBEMessage,
|
|
276
276
|
addrs: addrs,
|
|
277
277
|
signedData: _signedData,
|
|
278
|
-
txTypes
|
|
279
|
-
}).ToJSON()
|
|
278
|
+
txTypes
|
|
279
|
+
}).ToJSON()
|
|
280
280
|
)
|
|
281
281
|
this._setSubscribeAddresses(addrs, true)._setSubscribeSignedData(signedData)
|
|
282
282
|
|
|
@@ -294,8 +294,8 @@ export default class TCaBCIClient {
|
|
|
294
294
|
new Message({
|
|
295
295
|
isWeb: true,
|
|
296
296
|
type: UNSUBSCRIBEMessage,
|
|
297
|
-
addrs: this.SubscribeAddresses
|
|
298
|
-
}).ToJSON()
|
|
297
|
+
addrs: this.SubscribeAddresses
|
|
298
|
+
}).ToJSON()
|
|
299
299
|
)
|
|
300
300
|
this._setSubscribed(false)
|
|
301
301
|
this._setSubscribeAddresses([])
|
|
@@ -314,10 +314,10 @@ export default class TCaBCIClient {
|
|
|
314
314
|
.request(
|
|
315
315
|
`/v1/blocks?chain_name=${chainName ?? this._chainName}&chain_version=${chainVersion ?? this._chainVersion}&limit=1&offset=0`,
|
|
316
316
|
{
|
|
317
|
-
method: 'GET'
|
|
318
|
-
}
|
|
317
|
+
method: 'GET'
|
|
318
|
+
}
|
|
319
319
|
)
|
|
320
|
-
.then(
|
|
320
|
+
.then(res => {
|
|
321
321
|
const data = []
|
|
322
322
|
|
|
323
323
|
for (const _data of res.data) {
|
|
@@ -328,7 +328,7 @@ export default class TCaBCIClient {
|
|
|
328
328
|
|
|
329
329
|
return { blocks: data, total_count: res.total_count }
|
|
330
330
|
})
|
|
331
|
-
.catch(
|
|
331
|
+
.catch(e => this._httpClient.handleError(e, new Error(BLOCK_NOT_FOUND)))
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
/**
|
|
@@ -344,15 +344,15 @@ export default class TCaBCIClient {
|
|
|
344
344
|
return this._httpClient
|
|
345
345
|
.request(`/v1/tx/${id}`, {
|
|
346
346
|
method: 'GET',
|
|
347
|
-
headers: { 'X-Signature': signature }
|
|
347
|
+
headers: { 'X-Signature': signature }
|
|
348
348
|
})
|
|
349
|
-
.then(
|
|
349
|
+
.then(res => {
|
|
350
350
|
const { transaction, error } = Transaction.FromObject(res.data)
|
|
351
351
|
if (error) return Promise.reject(error)
|
|
352
352
|
|
|
353
353
|
return { tx: transaction }
|
|
354
354
|
})
|
|
355
|
-
.catch(
|
|
355
|
+
.catch(e => this._httpClient.handleError(e))
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
/**
|
|
@@ -380,7 +380,7 @@ export default class TCaBCIClient {
|
|
|
380
380
|
typ,
|
|
381
381
|
types = null,
|
|
382
382
|
chainName = null,
|
|
383
|
-
chainVersion = null
|
|
383
|
+
chainVersion = null
|
|
384
384
|
}) {
|
|
385
385
|
if (!recipientAddrs && !senderAddrs) {
|
|
386
386
|
return Promise.reject(new Error(INVALID_ARGUMENTS))
|
|
@@ -395,15 +395,15 @@ export default class TCaBCIClient {
|
|
|
395
395
|
recipient_addrs: recipientAddrs,
|
|
396
396
|
sender_addrs: senderAddrs,
|
|
397
397
|
signed_addrs: signedData,
|
|
398
|
-
...(types ? { types: types } : { typ: typ })
|
|
399
|
-
})
|
|
398
|
+
...(types ? { types: types } : { typ: typ })
|
|
399
|
+
})
|
|
400
400
|
})
|
|
401
|
-
.then(
|
|
401
|
+
.then(res => {
|
|
402
402
|
let firstTransaction, lastTransaction
|
|
403
403
|
|
|
404
404
|
if (res.data.first_transaction) {
|
|
405
405
|
const { transaction, error } = Transaction.FromObject(
|
|
406
|
-
res.data.first_transaction
|
|
406
|
+
res.data.first_transaction
|
|
407
407
|
)
|
|
408
408
|
if (error) return Promise.reject(error)
|
|
409
409
|
firstTransaction = transaction
|
|
@@ -411,7 +411,7 @@ export default class TCaBCIClient {
|
|
|
411
411
|
|
|
412
412
|
if (res.data.last_transaction) {
|
|
413
413
|
const { transaction, error: errorTwo } = Transaction.FromObject(
|
|
414
|
-
res.data.last_transaction
|
|
414
|
+
res.data.last_transaction
|
|
415
415
|
)
|
|
416
416
|
if (errorTwo) return Promise.reject(errorTwo)
|
|
417
417
|
lastTransaction = transaction
|
|
@@ -424,10 +424,10 @@ export default class TCaBCIClient {
|
|
|
424
424
|
first_transaction: firstTransaction,
|
|
425
425
|
last_block_height: res.data.last_block_height,
|
|
426
426
|
last_transaction: lastTransaction,
|
|
427
|
-
total_count: res.total_count
|
|
427
|
+
total_count: res.total_count
|
|
428
428
|
}
|
|
429
429
|
})
|
|
430
|
-
.catch(
|
|
430
|
+
.catch(e => this._httpClient.handleError(e))
|
|
431
431
|
}
|
|
432
432
|
|
|
433
433
|
/**
|
|
@@ -465,7 +465,7 @@ export default class TCaBCIClient {
|
|
|
465
465
|
orderField,
|
|
466
466
|
orderBy,
|
|
467
467
|
chainName = null,
|
|
468
|
-
chainVersion = null
|
|
468
|
+
chainVersion = null
|
|
469
469
|
}) {
|
|
470
470
|
return this._httpClient
|
|
471
471
|
.request('/v1/tx_search/p', {
|
|
@@ -484,10 +484,10 @@ export default class TCaBCIClient {
|
|
|
484
484
|
...(offset ? { offset: offset } : {}),
|
|
485
485
|
...(orderField ? { order_field: orderField } : {}),
|
|
486
486
|
...(orderBy ? { order_by: orderBy } : {}),
|
|
487
|
-
...(types ? { types: types } : typ ? { typ: typ } : {})
|
|
488
|
-
})
|
|
487
|
+
...(types ? { types: types } : typ ? { typ: typ } : {})
|
|
488
|
+
})
|
|
489
489
|
})
|
|
490
|
-
.then(
|
|
490
|
+
.then(res => {
|
|
491
491
|
const data = []
|
|
492
492
|
|
|
493
493
|
for (const _data of res.data) {
|
|
@@ -498,10 +498,10 @@ export default class TCaBCIClient {
|
|
|
498
498
|
|
|
499
499
|
return {
|
|
500
500
|
txs: data,
|
|
501
|
-
total_count: res.total_count
|
|
501
|
+
total_count: res.total_count
|
|
502
502
|
}
|
|
503
503
|
})
|
|
504
|
-
.catch(
|
|
504
|
+
.catch(e => this._httpClient.handleError(e))
|
|
505
505
|
}
|
|
506
506
|
|
|
507
507
|
/**
|
|
@@ -523,7 +523,7 @@ export default class TCaBCIClient {
|
|
|
523
523
|
sender_addr,
|
|
524
524
|
recipient_addr,
|
|
525
525
|
sign,
|
|
526
|
-
fee
|
|
526
|
+
fee
|
|
527
527
|
}) {
|
|
528
528
|
return this.broadcast(
|
|
529
529
|
{
|
|
@@ -534,10 +534,10 @@ export default class TCaBCIClient {
|
|
|
534
534
|
sender_addr,
|
|
535
535
|
recipient_addr,
|
|
536
536
|
sign,
|
|
537
|
-
fee
|
|
537
|
+
fee
|
|
538
538
|
},
|
|
539
539
|
false,
|
|
540
|
-
true
|
|
540
|
+
true
|
|
541
541
|
)
|
|
542
542
|
}
|
|
543
543
|
|
|
@@ -564,7 +564,7 @@ export default class TCaBCIClient {
|
|
|
564
564
|
sender_addr,
|
|
565
565
|
recipient_addr,
|
|
566
566
|
sign,
|
|
567
|
-
fee
|
|
567
|
+
fee
|
|
568
568
|
}) {
|
|
569
569
|
return this.broadcast(
|
|
570
570
|
{
|
|
@@ -577,10 +577,10 @@ export default class TCaBCIClient {
|
|
|
577
577
|
sender_addr,
|
|
578
578
|
recipient_addr,
|
|
579
579
|
sign,
|
|
580
|
-
fee
|
|
580
|
+
fee
|
|
581
581
|
},
|
|
582
582
|
true,
|
|
583
|
-
false
|
|
583
|
+
false
|
|
584
584
|
)
|
|
585
585
|
}
|
|
586
586
|
|
|
@@ -607,7 +607,7 @@ export default class TCaBCIClient {
|
|
|
607
607
|
sender_addr,
|
|
608
608
|
recipient_addr,
|
|
609
609
|
sign,
|
|
610
|
-
fee
|
|
610
|
+
fee
|
|
611
611
|
}) {
|
|
612
612
|
return this.broadcast(
|
|
613
613
|
{
|
|
@@ -620,10 +620,10 @@ export default class TCaBCIClient {
|
|
|
620
620
|
sender_addr,
|
|
621
621
|
recipient_addr,
|
|
622
622
|
sign,
|
|
623
|
-
fee
|
|
623
|
+
fee
|
|
624
624
|
},
|
|
625
625
|
false,
|
|
626
|
-
false
|
|
626
|
+
false
|
|
627
627
|
)
|
|
628
628
|
}
|
|
629
629
|
|
|
@@ -638,10 +638,10 @@ export default class TCaBCIClient {
|
|
|
638
638
|
sender_addr,
|
|
639
639
|
recipient_addr,
|
|
640
640
|
sign,
|
|
641
|
-
fee
|
|
641
|
+
fee
|
|
642
642
|
},
|
|
643
643
|
sync = false,
|
|
644
|
-
commit = false
|
|
644
|
+
commit = false
|
|
645
645
|
) {
|
|
646
646
|
if (!TX_TYPE_LIST.includes(type)) {
|
|
647
647
|
throw new Error(TRANSACTION_TYPE_NOT_VALID)
|
|
@@ -660,16 +660,16 @@ export default class TCaBCIClient {
|
|
|
660
660
|
sender_addr,
|
|
661
661
|
recipient_addr,
|
|
662
662
|
sign,
|
|
663
|
-
fee
|
|
664
|
-
})
|
|
663
|
+
fee
|
|
664
|
+
})
|
|
665
665
|
})
|
|
666
|
-
.then(
|
|
666
|
+
.then(res => {
|
|
667
667
|
return { data: res.data }
|
|
668
668
|
})
|
|
669
|
-
.catch(
|
|
669
|
+
.catch(e =>
|
|
670
670
|
this._httpClient.handleError(e, {
|
|
671
|
-
400: new Error(TRANSACTION_NOT_BROADCAST)
|
|
672
|
-
})
|
|
671
|
+
400: new Error(TRANSACTION_NOT_BROADCAST)
|
|
672
|
+
})
|
|
673
673
|
)
|
|
674
674
|
}
|
|
675
675
|
|
|
@@ -687,7 +687,7 @@ export default class TCaBCIClient {
|
|
|
687
687
|
signedData = {},
|
|
688
688
|
maxHeight = null,
|
|
689
689
|
chainName = null,
|
|
690
|
-
chainVersion = null
|
|
690
|
+
chainVersion = null
|
|
691
691
|
) {
|
|
692
692
|
return this._httpClient.request('/v1/bulk_tx', {
|
|
693
693
|
method: 'POST',
|
|
@@ -696,8 +696,8 @@ export default class TCaBCIClient {
|
|
|
696
696
|
chain_version: chainVersion ?? this._chainVersion,
|
|
697
697
|
addresses: addresses,
|
|
698
698
|
signed_addrs: signedData,
|
|
699
|
-
...(maxHeight ? { max_height: maxHeight } : {})
|
|
700
|
-
})
|
|
699
|
+
...(maxHeight ? { max_height: maxHeight } : {})
|
|
700
|
+
})
|
|
701
701
|
})
|
|
702
702
|
}
|
|
703
703
|
|
|
@@ -711,7 +711,7 @@ export default class TCaBCIClient {
|
|
|
711
711
|
|
|
712
712
|
this._ws = new TWebSocket(this._options)
|
|
713
713
|
|
|
714
|
-
this._ws.addErrorListener(
|
|
714
|
+
this._ws.addErrorListener(e => {
|
|
715
715
|
this._setConnected(false)
|
|
716
716
|
this._setSubscribed(false)
|
|
717
717
|
this._setSubscribeAddresses([], false)
|
|
@@ -719,16 +719,16 @@ export default class TCaBCIClient {
|
|
|
719
719
|
this._callErrorCallback(e)
|
|
720
720
|
})
|
|
721
721
|
|
|
722
|
-
this._ws.addOpenListener(
|
|
722
|
+
this._ws.addOpenListener(e => {
|
|
723
723
|
this._setConnected(true)
|
|
724
724
|
this._callSuccessCallback(e)
|
|
725
725
|
})
|
|
726
726
|
|
|
727
|
-
this._ws.addMessageListener(
|
|
727
|
+
this._ws.addMessageListener(message => {
|
|
728
728
|
this._callListenCallback(message.data)
|
|
729
729
|
})
|
|
730
730
|
|
|
731
|
-
this._ws.addCloseListener(
|
|
731
|
+
this._ws.addCloseListener(e => {
|
|
732
732
|
this._setConnected(false)
|
|
733
733
|
this._setSubscribed(false)
|
|
734
734
|
this._setSubscribeAddresses([], false)
|
package/constants.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export declare const READ_NODE_ADDRESS: string,
|
|
2
|
-
READ_NODE_WS_ADDRESS: string
|
|
1
|
+
export declare const READ_NODE_ADDRESS: string, READ_NODE_WS_ADDRESS: string
|
package/errors.js
CHANGED
|
@@ -2,7 +2,7 @@ export const ALREADY_CONNECTED = 'Already connected',
|
|
|
2
2
|
NOT_CONNECTED = 'Not connected',
|
|
3
3
|
ERR_NETWORK = 'Network Error',
|
|
4
4
|
INVALID_ARGUMENTS = 'Check your arguments',
|
|
5
|
-
INVALID_ARGUMENT_WITH_CS =
|
|
5
|
+
INVALID_ARGUMENT_WITH_CS = val => {
|
|
6
6
|
return INVALID_ARGUMENTS + ' ' + val
|
|
7
7
|
},
|
|
8
8
|
NOT_SUBSCRIBED = 'Not subscribed',
|
package/http.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export declare class HTTP {
|
|
|
5
5
|
setBaseURL(baseURL: string): HTTP
|
|
6
6
|
request(uri: string, req: Request): Promise<Record<string, any>>
|
|
7
7
|
handleResponse(response: Response): Promise<any>
|
|
8
|
-
handleError(err: Error, custom: Record<string, any
|
|
8
|
+
handleError(err: Error, custom: Record<string, any> | Error): Promise<any>
|
|
9
9
|
}
|
package/http.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ERR_NETWORK, FetchError, INVALID_ARGUMENTS } from './errors.js'
|
|
2
2
|
import { Breaker } from './breaker.js'
|
|
3
|
+
import { Debug } from '@streetbyters/js-debug'
|
|
3
4
|
|
|
4
5
|
export class HTTP {
|
|
5
6
|
_baseURL
|
|
@@ -20,7 +21,7 @@ export class HTTP {
|
|
|
20
21
|
async request(uri, req) {
|
|
21
22
|
req.cache = 'no-cache'
|
|
22
23
|
req.headers = {
|
|
23
|
-
Client: `tcabaci-read-js-client/${this._version}
|
|
24
|
+
Client: `tcabaci-read-js-client/${this._version}`
|
|
24
25
|
}
|
|
25
26
|
req.priority = 'high'
|
|
26
27
|
|
|
@@ -28,7 +29,7 @@ export class HTTP {
|
|
|
28
29
|
.execute(() => {
|
|
29
30
|
return fetch(this._baseURL + uri, req)
|
|
30
31
|
})
|
|
31
|
-
.then(
|
|
32
|
+
.then(response => this.handleResponse(response))
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
/**
|
|
@@ -46,11 +47,12 @@ export class HTTP {
|
|
|
46
47
|
return Promise.reject(
|
|
47
48
|
new FetchError(data.message)
|
|
48
49
|
.setStatus(response.status)
|
|
49
|
-
.setResponse(data)
|
|
50
|
+
.setResponse(data)
|
|
50
51
|
)
|
|
51
52
|
} catch (e) {
|
|
53
|
+
Debug.error(e)
|
|
52
54
|
return Promise.reject(
|
|
53
|
-
new FetchError(response.statusText).setOriginError(e)
|
|
55
|
+
new FetchError(response.statusText).setOriginError(e)
|
|
54
56
|
)
|
|
55
57
|
}
|
|
56
58
|
}
|
package/message.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare type MessageType = string
|
|
|
5
5
|
export declare const SUBSCRIBEMessage: MessageType,
|
|
6
6
|
UNSUBSCRIBEMessage: MessageType
|
|
7
7
|
|
|
8
|
-
export declare type MType =
|
|
8
|
+
export declare type MType = number
|
|
9
9
|
|
|
10
10
|
export declare const Block: MessageType,
|
|
11
11
|
Transaction: MessageType,
|
|
@@ -15,8 +15,7 @@ export declare const Block: MessageType,
|
|
|
15
15
|
|
|
16
16
|
export declare type MState = number
|
|
17
17
|
|
|
18
|
-
export declare const OK: MState,
|
|
19
|
-
FAIL: MState
|
|
18
|
+
export declare const OK: MState, FAIL: MState
|
|
20
19
|
|
|
21
20
|
export declare class Message {
|
|
22
21
|
constructor({
|
|
@@ -24,7 +23,7 @@ export declare class Message {
|
|
|
24
23
|
type,
|
|
25
24
|
addrs,
|
|
26
25
|
signedData,
|
|
27
|
-
txTypes
|
|
26
|
+
txTypes
|
|
28
27
|
}?: {
|
|
29
28
|
isWeb: boolean
|
|
30
29
|
type: MessageType
|
|
@@ -41,6 +40,9 @@ export declare class Message {
|
|
|
41
40
|
get State(): MState | null
|
|
42
41
|
|
|
43
42
|
static FromJSON(value: string): { message?: Message; error?: Error }
|
|
44
|
-
static FromObject(obj: Record<string, any>): {
|
|
43
|
+
static FromObject(obj: Record<string, any>): {
|
|
44
|
+
message?: Message
|
|
45
|
+
error?: Error
|
|
46
|
+
}
|
|
45
47
|
ToJSON(): string
|
|
46
48
|
}
|
package/message.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { INVALID_ARGUMENT_WITH_CS } from './errors.js'
|
|
2
2
|
import { TX_TYPE_LIST } from './transaction.js'
|
|
3
|
+
import { Debug } from '@streetbyters/js-debug'
|
|
3
4
|
|
|
4
5
|
export const SUBSCRIBEMessage = 'subscribe',
|
|
5
6
|
UNSUBSCRIBEMessage = 'unsubscribe'
|
|
@@ -36,7 +37,7 @@ export default class Message {
|
|
|
36
37
|
addrs,
|
|
37
38
|
signedData = null,
|
|
38
39
|
txTypes = null,
|
|
39
|
-
data = null
|
|
40
|
+
data = null
|
|
40
41
|
} = {}) {
|
|
41
42
|
this._is_web = isWeb
|
|
42
43
|
this._type = type
|
|
@@ -88,6 +89,7 @@ export default class Message {
|
|
|
88
89
|
|
|
89
90
|
return { message: this, error: null }
|
|
90
91
|
} catch (e) {
|
|
92
|
+
Debug.error(e)
|
|
91
93
|
return { message: null, error: e }
|
|
92
94
|
}
|
|
93
95
|
}
|
|
@@ -108,6 +110,7 @@ export default class Message {
|
|
|
108
110
|
|
|
109
111
|
return { message: this, error: null }
|
|
110
112
|
} catch (e) {
|
|
113
|
+
Debug.error(e)
|
|
111
114
|
return { message: null, error: e }
|
|
112
115
|
}
|
|
113
116
|
}
|
|
@@ -123,7 +126,7 @@ export default class Message {
|
|
|
123
126
|
? { signed_addresses: this._signedAddresses }
|
|
124
127
|
: {}),
|
|
125
128
|
...(this._txTypes ? { tx_types: this._txTypes } : {}),
|
|
126
|
-
...(this._data ? { data: this._data } : {})
|
|
129
|
+
...(this._data ? { data: this._data } : {})
|
|
127
130
|
})
|
|
128
131
|
}
|
|
129
132
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tchain/tcabci-read-js-client",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.9",
|
|
4
4
|
"description": "TransferChain Fastest Read Network WebSocket Client",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"homepage": "https://github.com/TransferChain/tcabci-read-js-client#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/TransferChain/tcabci-read-js-client/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"author": "TransferChain A.G <info@transferchain.io>",
|
|
7
11
|
"repository": {
|
|
8
12
|
"type": "git",
|
|
9
13
|
"url": "git+https://github.com/TransferChain/tcabci-read-js-client.git"
|
|
@@ -22,35 +26,30 @@
|
|
|
22
26
|
"websocket.js",
|
|
23
27
|
"websocketOptions.js"
|
|
24
28
|
],
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
+
"type": "module",
|
|
30
|
+
"main": "client.js",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@streetbyters/js-debug": "^0.1.3",
|
|
33
|
+
"cockatiel": "^4.0.0",
|
|
34
|
+
"reconnecting-websocket": "^4.4.0"
|
|
29
35
|
},
|
|
30
|
-
"homepage": "https://github.com/TransferChain/tcabci-read-js-client#readme",
|
|
31
36
|
"devDependencies": {
|
|
32
|
-
"@eslint/js": "^10.0.1",
|
|
33
37
|
"@types/chai": "^5.2.3",
|
|
34
38
|
"chai": "^6.2.2",
|
|
35
|
-
"eslint": "^10.8.0",
|
|
36
|
-
"eslint-config-prettier": "^10.1.8",
|
|
37
|
-
"eslint-plugin-prettier": "^5.5.6",
|
|
38
39
|
"esm": "^3.2.25",
|
|
39
40
|
"express": "^5.2.1",
|
|
40
41
|
"globals": "^16.5.0",
|
|
41
|
-
"mocha": "^11.
|
|
42
|
-
"nyc": "^
|
|
43
|
-
"
|
|
42
|
+
"mocha": "^11.8.0",
|
|
43
|
+
"nyc": "^18.0.0",
|
|
44
|
+
"oxfmt": "^0.63.0",
|
|
45
|
+
"oxlint": "^1.80.0",
|
|
44
46
|
"unit.js": "^2.1.1",
|
|
45
|
-
"ws": "^8.21.
|
|
46
|
-
},
|
|
47
|
-
"dependencies": {
|
|
48
|
-
"cockatiel": "^3.2.1",
|
|
49
|
-
"reconnecting-websocket": "^4.4.0"
|
|
47
|
+
"ws": "^8.21.3"
|
|
50
48
|
},
|
|
51
49
|
"scripts": {
|
|
52
|
-
"format": "
|
|
53
|
-
"lint
|
|
50
|
+
"format": "oxfmt ./",
|
|
51
|
+
"lint": "oxfmt ./ && oxlint --fix ./",
|
|
52
|
+
"lint:check": "oxfmt --check ./ && oxlint ./",
|
|
54
53
|
"test": "export NODE_ENV=test || SET \"NODE_ENV=test\" && mocha --require esm --timeout 5000",
|
|
55
54
|
"test:all": "export NODE_ENV=test || SET \"NODE_ENV=test\" && mocha --require esm --timeout 5000 '*_test.js'",
|
|
56
55
|
"test:coverage": "export NODE_ENV=test || SET \"NODE_ENV=test\" && nyc --reporter=text mocha --require esm --timeout 5000"
|
package/transaction.d.ts
CHANGED
|
@@ -34,6 +34,8 @@ export declare const TX_TYPE_MASTER: TXType,
|
|
|
34
34
|
TX_TYPE_DATA_ROOM_DATA: TXType,
|
|
35
35
|
TX_TYPE_DATA_ROOM_DATA_DELETE: TXType,
|
|
36
36
|
TX_TYPE_DATA_ROOM_DATA_POLICY: TXType,
|
|
37
|
+
TX_TYPE_DATA_ROOME: TXType,
|
|
38
|
+
TX_TYPE_DATA_ROOME_DATA: TXType,
|
|
37
39
|
TX_TYPE_MULTI_DATA_ROOM: TXType,
|
|
38
40
|
TX_TYPE_MULTI_STORAGE: TXType,
|
|
39
41
|
TX_TYPE_MULTI_TRANSFER: TXType,
|
|
@@ -54,7 +56,7 @@ export declare const TX_TYPE_MASTER: TXType,
|
|
|
54
56
|
TX_TYPE_COLLECTION: TXType,
|
|
55
57
|
TX_TYPE_COLLECTION_POLICY: TXType,
|
|
56
58
|
TX_TYPE_DATAV2_COLLECTION: TXType,
|
|
57
|
-
TX_TYPE_DATAV2F: TXType
|
|
59
|
+
TX_TYPE_DATAV2F: TXType
|
|
58
60
|
|
|
59
61
|
export declare const TX_TYPE_LIST: TXType[]
|
|
60
62
|
|
|
@@ -74,7 +76,7 @@ export declare class Transaction {
|
|
|
74
76
|
additionalData,
|
|
75
77
|
cipherData,
|
|
76
78
|
chainName,
|
|
77
|
-
chainVersion
|
|
79
|
+
chainVersion
|
|
78
80
|
}?: Record<string, any>)
|
|
79
81
|
get Order(): number
|
|
80
82
|
get ID(): string
|
package/transaction.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { INVALID_ARGUMENT_WITH_CS } from './errors.js'
|
|
2
|
+
import { Debug } from '@streetbyters/js-debug'
|
|
2
3
|
|
|
3
4
|
export const TX_TYPE_MASTER = 'initial_storage',
|
|
4
5
|
TX_TYPE_ADDRESS = 'interim_storage',
|
|
@@ -34,6 +35,8 @@ export const TX_TYPE_MASTER = 'initial_storage',
|
|
|
34
35
|
TX_TYPE_DATA_ROOM_DATA = 'data_room_data',
|
|
35
36
|
TX_TYPE_DATA_ROOM_DATA_DELETE = 'data_room_data_delete',
|
|
36
37
|
TX_TYPE_DATA_ROOM_DATA_POLICY = 'data_room_data_policy',
|
|
38
|
+
TX_TYPE_DATA_ROOME = 'data_roomE',
|
|
39
|
+
TX_TYPE_DATA_ROOME_DATA = 'data_roomE_data',
|
|
37
40
|
TX_TYPE_MULTI_DATA_ROOM = 'multi_data_room',
|
|
38
41
|
TX_TYPE_MULTI_STORAGE = 'multi_storage',
|
|
39
42
|
TX_TYPE_MULTI_TRANSFER = 'multi_transfer',
|
|
@@ -90,6 +93,8 @@ export const TX_TYPE_MASTER = 'initial_storage',
|
|
|
90
93
|
TX_TYPE_DATA_ROOM_DATA,
|
|
91
94
|
TX_TYPE_DATA_ROOM_DATA_DELETE,
|
|
92
95
|
TX_TYPE_DATA_ROOM_DATA_POLICY,
|
|
96
|
+
TX_TYPE_DATA_ROOME,
|
|
97
|
+
TX_TYPE_DATA_ROOME_DATA,
|
|
93
98
|
TX_TYPE_MULTI_DATA_ROOM,
|
|
94
99
|
TX_TYPE_MULTI_STORAGE,
|
|
95
100
|
TX_TYPE_MULTI_TRANSFER,
|
|
@@ -110,7 +115,7 @@ export const TX_TYPE_MASTER = 'initial_storage',
|
|
|
110
115
|
TX_TYPE_COLLECTION,
|
|
111
116
|
TX_TYPE_COLLECTION_POLICY,
|
|
112
117
|
TX_TYPE_DATAV2_COLLECTION,
|
|
113
|
-
TX_TYPE_DATAV2F
|
|
118
|
+
TX_TYPE_DATAV2F
|
|
114
119
|
]
|
|
115
120
|
|
|
116
121
|
export class Transaction {
|
|
@@ -165,7 +170,7 @@ export class Transaction {
|
|
|
165
170
|
additionalData = null,
|
|
166
171
|
cipherData = null,
|
|
167
172
|
chainName = null,
|
|
168
|
-
chainVersion = null
|
|
173
|
+
chainVersion = null
|
|
169
174
|
} = {}) {
|
|
170
175
|
this._id = id
|
|
171
176
|
this._height = height
|
|
@@ -252,7 +257,7 @@ export class Transaction {
|
|
|
252
257
|
if (typeof value !== 'string')
|
|
253
258
|
return {
|
|
254
259
|
transaction: null,
|
|
255
|
-
error: new Error('invalid json payload')
|
|
260
|
+
error: new Error('invalid json payload')
|
|
256
261
|
}
|
|
257
262
|
|
|
258
263
|
try {
|
|
@@ -287,6 +292,7 @@ export class Transaction {
|
|
|
287
292
|
|
|
288
293
|
return { transaction: tx, error: null }
|
|
289
294
|
} catch (e) {
|
|
295
|
+
Debug.error(e)
|
|
290
296
|
return { transaction: null, error: e }
|
|
291
297
|
}
|
|
292
298
|
}
|
|
@@ -295,7 +301,7 @@ export class Transaction {
|
|
|
295
301
|
if (!obj)
|
|
296
302
|
return {
|
|
297
303
|
transaction: null,
|
|
298
|
-
error: new Error('invalid obj payload')
|
|
304
|
+
error: new Error('invalid obj payload')
|
|
299
305
|
}
|
|
300
306
|
|
|
301
307
|
try {
|
|
@@ -327,6 +333,7 @@ export class Transaction {
|
|
|
327
333
|
|
|
328
334
|
return { transaction: tx, error: null }
|
|
329
335
|
} catch (e) {
|
|
336
|
+
Debug.error(e)
|
|
330
337
|
return { transaction: null, error: e }
|
|
331
338
|
}
|
|
332
339
|
}
|
|
@@ -357,7 +364,7 @@ export class Transaction {
|
|
|
357
364
|
: {}),
|
|
358
365
|
...(this._cipherData ? { cipher_data: this._cipherData } : {}),
|
|
359
366
|
...(this._chainName ? { chain_name: this._chainName } : {}),
|
|
360
|
-
...(this._chainVersion ? { chain_version: this._chainVersion } : {})
|
|
367
|
+
...(this._chainVersion ? { chain_version: this._chainVersion } : {})
|
|
361
368
|
})
|
|
362
369
|
}
|
|
363
370
|
|
|
@@ -387,7 +394,7 @@ export class Transaction {
|
|
|
387
394
|
: {}),
|
|
388
395
|
...(this._cipherData ? { cipher_data: this._cipherData } : {}),
|
|
389
396
|
...(this._chainName ? { chain_name: this._chainName } : {}),
|
|
390
|
-
...(this._chainVersion ? { chain_version: this._chainVersion } : {})
|
|
397
|
+
...(this._chainVersion ? { chain_version: this._chainVersion } : {})
|
|
391
398
|
}
|
|
392
399
|
}
|
|
393
400
|
|
package/util.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function fromJSON(data: string): Record<string, any
|
|
2
|
-
export declare function isJSON(str: string): boolean
|
|
1
|
+
export declare function fromJSON(data: string): Record<string, any>
|
|
2
|
+
export declare function isJSON(str: string): boolean
|
package/util.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Debug } from '@streetbyters/js-debug'
|
|
2
|
+
|
|
1
3
|
export function fromJSON(data) {
|
|
2
4
|
return JSON.parse(data)
|
|
3
5
|
}
|
|
@@ -5,7 +7,8 @@ export function fromJSON(data) {
|
|
|
5
7
|
export function isJSON(str) {
|
|
6
8
|
try {
|
|
7
9
|
JSON.parse(str)
|
|
8
|
-
} catch (
|
|
10
|
+
} catch (e) {
|
|
11
|
+
Debug.error(e)
|
|
9
12
|
return false
|
|
10
13
|
}
|
|
11
14
|
|
package/websocket.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class TWebSocket {
|
|
|
12
12
|
connect(force?: boolean): Awaited<TWebSocket>
|
|
13
13
|
reconnect(code: number): Awaited<TWebSocket>
|
|
14
14
|
disconnect(code: number): Awaited<TWebSocket>
|
|
15
|
-
send(message:
|
|
15
|
+
send(message: string | ArrayBufferLike | Blob | ArrayBufferView): void
|
|
16
16
|
addOpenListener(callback: (event: Event) => void): TWebSocket
|
|
17
17
|
removeOpenListener(callback: (event: Event) => void): TWebSocket
|
|
18
18
|
addMessageListener(callback: (event: Event) => void): TWebSocket
|
package/websocket.js
CHANGED
|
@@ -197,7 +197,7 @@ export class TWebSocket {
|
|
|
197
197
|
if (this[name].length >= MaxListenerSize)
|
|
198
198
|
throw new Error(`listener size must be ${MaxListenerSize}`)
|
|
199
199
|
|
|
200
|
-
if (this[name].findIndex(
|
|
200
|
+
if (this[name].findIndex(v => v === callback) > -1) return this
|
|
201
201
|
|
|
202
202
|
this[name].push(callback)
|
|
203
203
|
|
|
@@ -210,7 +210,7 @@ export class TWebSocket {
|
|
|
210
210
|
* @private
|
|
211
211
|
*/
|
|
212
212
|
_removeListener(name, callback) {
|
|
213
|
-
const idx = this[name].findIndex(
|
|
213
|
+
const idx = this[name].findIndex(v => v === callback)
|
|
214
214
|
|
|
215
215
|
if (idx > -1) {
|
|
216
216
|
this[name].splice(idx, 1)
|
|
@@ -229,7 +229,7 @@ export class TWebSocket {
|
|
|
229
229
|
},
|
|
230
230
|
0,
|
|
231
231
|
callback,
|
|
232
|
-
value
|
|
232
|
+
value
|
|
233
233
|
)
|
|
234
234
|
}
|
|
235
235
|
}
|
|
@@ -258,30 +258,30 @@ export class TWebSocket {
|
|
|
258
258
|
this._client = new ReconnectingWebSocket(
|
|
259
259
|
this._options.url,
|
|
260
260
|
this._options.protocols,
|
|
261
|
-
this._options.make()
|
|
261
|
+
this._options.make()
|
|
262
262
|
)
|
|
263
263
|
|
|
264
|
-
this._openListener =
|
|
264
|
+
this._openListener = e => {
|
|
265
265
|
this._connectionErrorCount = 0
|
|
266
266
|
this._onOpen(e)
|
|
267
267
|
}
|
|
268
268
|
this._client.addEventListener('open', this._openListener)
|
|
269
269
|
|
|
270
|
-
this._closeListener =
|
|
270
|
+
this._closeListener = e => {
|
|
271
271
|
this._onClose(e)
|
|
272
272
|
}
|
|
273
273
|
this._client.addEventListener('close', this._closeListener)
|
|
274
274
|
|
|
275
|
-
this._messageListener =
|
|
275
|
+
this._messageListener = e => {
|
|
276
276
|
this._onMessage(e)
|
|
277
277
|
}
|
|
278
278
|
this._client.addEventListener('message', this._messageListener)
|
|
279
279
|
|
|
280
|
-
this._errorListener =
|
|
280
|
+
this._errorListener = e => {
|
|
281
281
|
this._onError(e)
|
|
282
282
|
if (this._connectionErrorCount > 15) {
|
|
283
283
|
this._onError(new Error('Internet connectivity problem!'))
|
|
284
|
-
this._disconnect().catch(
|
|
284
|
+
this._disconnect().catch(err => {
|
|
285
285
|
this._onError(err)
|
|
286
286
|
})
|
|
287
287
|
|
package/websocketOptions.d.ts
CHANGED
package/websocketOptions.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Debug } from '@streetbyters/js-debug'
|
|
2
|
+
|
|
1
3
|
export const HTTPSPort = 443,
|
|
2
4
|
HTTPPort = 80
|
|
3
5
|
|
|
@@ -13,7 +15,7 @@ export class Options {
|
|
|
13
15
|
_protocols = []
|
|
14
16
|
_customWS
|
|
15
17
|
_endpoints = ['ws', 'longpoll']
|
|
16
|
-
_version = `v2.7.
|
|
18
|
+
_version = `v2.7.9`
|
|
17
19
|
|
|
18
20
|
_maxConnectionDelay = 10000
|
|
19
21
|
_minReconnectionDelay = 1000 + Math.random() * 4000
|
|
@@ -37,7 +39,7 @@ export class Options {
|
|
|
37
39
|
timeout = DefaultTimeout,
|
|
38
40
|
secure = true,
|
|
39
41
|
port = HTTPSPort,
|
|
40
|
-
longpoll = false
|
|
42
|
+
longpoll = false
|
|
41
43
|
) {
|
|
42
44
|
this._host = host
|
|
43
45
|
this._port = port
|
|
@@ -60,6 +62,7 @@ export class Options {
|
|
|
60
62
|
|
|
61
63
|
return true
|
|
62
64
|
} catch (e) {
|
|
65
|
+
Debug.error(e)
|
|
63
66
|
throw e
|
|
64
67
|
}
|
|
65
68
|
}
|
|
@@ -277,8 +280,8 @@ export class Options {
|
|
|
277
280
|
startClosed: this._startClosed,
|
|
278
281
|
debug: this._debug,
|
|
279
282
|
headers: {
|
|
280
|
-
Client: `tcabaci-read-js-client/${this._version}
|
|
281
|
-
}
|
|
283
|
+
Client: `tcabaci-read-js-client/${this._version}`
|
|
284
|
+
}
|
|
282
285
|
}
|
|
283
286
|
}
|
|
284
287
|
}
|