viz-js-lib 0.11.0 → 0.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/.qoder/docs/spec/viz-dns-nameserver-spec.md +982 -0
  2. package/.qoder/docs/viz-cpp-node-docs/data-types.md +322 -0
  3. package/.qoder/docs/viz-cpp-node-docs/index.md +160 -0
  4. package/.qoder/docs/viz-cpp-node-docs/op-account-market.md +236 -0
  5. package/.qoder/docs/viz-cpp-node-docs/op-account.md +199 -0
  6. package/.qoder/docs/viz-cpp-node-docs/op-award.md +162 -0
  7. package/.qoder/docs/viz-cpp-node-docs/op-committee.md +193 -0
  8. package/.qoder/docs/viz-cpp-node-docs/op-content.md +157 -0
  9. package/.qoder/docs/viz-cpp-node-docs/op-escrow.md +224 -0
  10. package/.qoder/docs/viz-cpp-node-docs/op-invite.md +219 -0
  11. package/.qoder/docs/viz-cpp-node-docs/op-proposal.md +229 -0
  12. package/.qoder/docs/viz-cpp-node-docs/op-recovery.md +188 -0
  13. package/.qoder/docs/viz-cpp-node-docs/op-subscription.md +146 -0
  14. package/.qoder/docs/viz-cpp-node-docs/op-transfer-vesting.md +224 -0
  15. package/.qoder/docs/viz-cpp-node-docs/op-witness.md +252 -0
  16. package/.qoder/docs/viz-cpp-node-docs/plugins.md +887 -0
  17. package/.qoder/docs/viz-cpp-node-docs/virtual-operations.md +513 -0
  18. package/.qoder/repowiki/en/content/API Reference/API Reference.md +724 -0
  19. package/.qoder/repowiki/en/content/API Reference/Configuration Options.md +410 -0
  20. package/.qoder/repowiki/en/content/API Reference/Core API Methods.md +547 -0
  21. package/.qoder/repowiki/en/content/API Reference/Streaming APIs.md +380 -0
  22. package/.qoder/repowiki/en/content/API Reference/Transport Layer.md +341 -0
  23. package/.qoder/repowiki/en/content/API Reference/VIZ Blockchain Operations Coverage Status.md +427 -0
  24. package/.qoder/repowiki/en/content/Authentication & Cryptography/Authentication & Cryptography.md +430 -0
  25. package/.qoder/repowiki/en/content/Authentication & Cryptography/Digital Signatures.md +462 -0
  26. package/.qoder/repowiki/en/content/Authentication & Cryptography/Key Management.md +456 -0
  27. package/.qoder/repowiki/en/content/Authentication & Cryptography/Memo Encryption.md +331 -0
  28. package/.qoder/repowiki/en/content/Authentication & Cryptography/Security Practices.md +488 -0
  29. package/.qoder/repowiki/en/content/Broadcast Transactions/Broadcast Transactions.md +432 -0
  30. package/.qoder/repowiki/en/content/Broadcast Transactions/Network Broadcasting.md +418 -0
  31. package/.qoder/repowiki/en/content/Broadcast Transactions/Operation Construction.md +352 -0
  32. package/.qoder/repowiki/en/content/Broadcast Transactions/Transaction Preparation.md +353 -0
  33. package/.qoder/repowiki/en/content/Broadcast Transactions/Transaction Signing.md +404 -0
  34. package/.qoder/repowiki/en/content/Data Serialization/Data Serialization.md +540 -0
  35. package/.qoder/repowiki/en/content/Data Serialization/Encoding & Decoding.md +463 -0
  36. package/.qoder/repowiki/en/content/Data Serialization/Object Templates.md +413 -0
  37. package/.qoder/repowiki/en/content/Data Serialization/Type System.md +514 -0
  38. package/.qoder/repowiki/en/content/Data Serialization/Validation Rules.md +439 -0
  39. package/.qoder/repowiki/en/content/Examples & Tutorials.md +485 -0
  40. package/.qoder/repowiki/en/content/Getting Started.md +345 -0
  41. package/.qoder/repowiki/en/content/Testing & Development.md +637 -0
  42. package/.qoder/repowiki/en/content/Utilities & Helpers.md +557 -0
  43. package/.qoder/repowiki/en/meta/repowiki-metadata.json +1 -0
  44. package/VIZ-JS-LIB-COVERAGE-STATUS.md +356 -0
  45. package/config.json +3 -1
  46. package/dist/statistics.html +1 -1
  47. package/dist/viz-tests.min.js +32 -42
  48. package/dist/viz-tests.min.js.gz +0 -0
  49. package/dist/viz.min.js +8 -18
  50. package/dist/viz.min.js.gz +0 -0
  51. package/lib/api/methods.js +24 -0
  52. package/lib/auth/serializer/src/ChainTypes.js +2 -1
  53. package/lib/auth/serializer/src/operations.js +35 -2
  54. package/lib/broadcast/index.js +29 -15
  55. package/lib/broadcast/operations.js +4 -0
  56. package/lib/dns.js +658 -0
  57. package/lib/index.js +3 -1
  58. package/package.json +3 -2
  59. package/test/dns.test.js +395 -0
  60. package/webpack/makeConfig.js +3 -0
@@ -0,0 +1,341 @@
1
+ # Transport Layer
2
+
3
+ <cite>
4
+ **Referenced Files in This Document**
5
+ - [base.js](file://src/api/transports/base.js)
6
+ - [http.js](file://src/api/transports/http.js)
7
+ - [ws.js](file://src/api/transports/ws.js)
8
+ - [index.js](file://src/api/transports/index.js)
9
+ - [index.js](file://src/api/index.js)
10
+ - [config.js](file://src/config.js)
11
+ - [config.json](file://config.json)
12
+ - [index.html](file://examples/index.html)
13
+ - [api.test.js](file://test/api.test.js)
14
+ </cite>
15
+
16
+ ## Table of Contents
17
+ 1. [Introduction](#introduction)
18
+ 2. [Project Structure](#project-structure)
19
+ 3. [Core Components](#core-components)
20
+ 4. [Architecture Overview](#architecture-overview)
21
+ 5. [Detailed Component Analysis](#detailed-component-analysis)
22
+ 6. [Dependency Analysis](#dependency-analysis)
23
+ 7. [Performance Considerations](#performance-considerations)
24
+ 8. [Troubleshooting Guide](#troubleshooting-guide)
25
+ 9. [Conclusion](#conclusion)
26
+ 10. [Appendices](#appendices)
27
+
28
+ ## Introduction
29
+ This document describes the transport layer of the VIZ JavaScript library. It explains the base transport interface and how HTTP and WebSocket transports inherit from it. It covers transport selection logic, connection management, lifecycle handling, request/response processing, error propagation, and retry mechanisms. It also documents configuration options, performance tuning, usage patterns, and troubleshooting steps for common connection issues.
30
+
31
+ ## Project Structure
32
+ The transport layer resides under the API module and is organized by protocol:
33
+ - Base transport interface
34
+ - HTTP transport
35
+ - WebSocket transport
36
+ - Transport registry for selection
37
+
38
+ ```mermaid
39
+ graph TB
40
+ subgraph "API Transports"
41
+ TBase["Transport (base.js)"]
42
+ THttp["HttpTransport (http.js)"]
43
+ TWs["WsTransport (ws.js)"]
44
+ TIndex["Transports Index (index.js)"]
45
+ end
46
+ subgraph "API Consumer"
47
+ VIZ["VIZ (api/index.js)"]
48
+ end
49
+ subgraph "Configuration"
50
+ Cfg["config.js"]
51
+ CfgJson["config.json"]
52
+ end
53
+ VIZ --> TIndex
54
+ TIndex --> THttp
55
+ TIndex --> TWs
56
+ THttp --> TBase
57
+ TWs --> TBase
58
+ VIZ --> Cfg
59
+ Cfg --> CfgJson
60
+ ```
61
+
62
+ **Diagram sources**
63
+ - [base.js](file://src/api/transports/base.js#L1-L34)
64
+ - [http.js](file://src/api/transports/http.js#L1-L53)
65
+ - [ws.js](file://src/api/transports/ws.js#L1-L136)
66
+ - [index.js](file://src/api/transports/index.js#L1-L8)
67
+ - [index.js](file://src/api/index.js#L1-L271)
68
+ - [config.js](file://src/config.js#L1-L10)
69
+ - [config.json](file://config.json#L1-L7)
70
+
71
+ **Section sources**
72
+ - [base.js](file://src/api/transports/base.js#L1-L34)
73
+ - [http.js](file://src/api/transports/http.js#L1-L53)
74
+ - [ws.js](file://src/api/transports/ws.js#L1-L136)
75
+ - [index.js](file://src/api/transports/index.js#L1-L8)
76
+ - [index.js](file://src/api/index.js#L1-L271)
77
+ - [config.js](file://src/config.js#L1-L10)
78
+ - [config.json](file://config.json#L1-L7)
79
+
80
+ ## Core Components
81
+ - Transport (base): Defines the common interface for all transports, including lifecycle hooks and helper utilities.
82
+ - HttpTransport: Implements JSON-RPC over HTTP using cross-fetch.
83
+ - WsTransport: Implements JSON-RPC over WebSocket with request queuing, message routing, and lifecycle events.
84
+ - Transports registry: Exposes HTTP and WebSocket constructors for selection.
85
+ - VIZ consumer: Selects transport based on configured URL and forwards requests.
86
+
87
+ Key responsibilities:
88
+ - Transport selection: VIZ selects HTTP or WebSocket depending on the configured URL scheme.
89
+ - Lifecycle: start/stop controls connection state; setOptions triggers stop to apply changes safely.
90
+ - Request routing: VIZ delegates send to the active transport; transport handles retries and error propagation.
91
+
92
+ **Section sources**
93
+ - [base.js](file://src/api/transports/base.js#L4-L31)
94
+ - [http.js](file://src/api/transports/http.js#L43-L52)
95
+ - [ws.js](file://src/api/transports/ws.js#L18-L136)
96
+ - [index.js](file://src/api/transports/index.js#L4-L7)
97
+ - [index.js](file://src/api/index.js#L34-L62)
98
+
99
+ ## Architecture Overview
100
+ The transport layer sits between the VIZ API client and the backend. VIZ decides the transport based on the configured websocket URL and delegates all send operations to the selected transport. Both HTTP and WebSocket transports normalize JSON-RPC semantics and propagate errors to the caller.
101
+
102
+ ```mermaid
103
+ sequenceDiagram
104
+ participant App as "Application"
105
+ participant VIZ as "VIZ (api/index.js)"
106
+ participant Reg as "Transports Registry (index.js)"
107
+ participant T as "Transport (base.js)"
108
+ participant HT as "HttpTransport (http.js)"
109
+ participant WT as "WsTransport (ws.js)"
110
+ App->>VIZ : "send(api, data, callback)"
111
+ VIZ->>VIZ : "_setTransport(config.get('websocket'))"
112
+ alt "URL starts with http/https"
113
+ VIZ->>Reg : "http"
114
+ Reg-->>VIZ : "HttpTransport"
115
+ VIZ->>HT : "send(api, data, callback)"
116
+ HT->>T : "inherit lifecycle"
117
+ else "URL starts with ws/wss"
118
+ VIZ->>Reg : "ws"
119
+ Reg-->>VIZ : "WsTransport"
120
+ VIZ->>WT : "send(api, data, callback)"
121
+ WT->>T : "inherit lifecycle"
122
+ end
123
+ VIZ-->>App : "callback(err, result)"
124
+ ```
125
+
126
+ **Diagram sources**
127
+ - [index.js](file://src/api/index.js#L34-L62)
128
+ - [index.js](file://src/api/transports/index.js#L4-L7)
129
+ - [base.js](file://src/api/transports/base.js#L4-L31)
130
+ - [http.js](file://src/api/transports/http.js#L43-L52)
131
+ - [ws.js](file://src/api/transports/ws.js#L18-L136)
132
+
133
+ ## Detailed Component Analysis
134
+
135
+ ### Base Transport Interface
136
+ The base class defines the contract and shared utilities:
137
+ - Lifecycle: start(), stop(), setOptions().
138
+ - Helpers: listenTo() for DOM/node event binding.
139
+ - Asynchronous promisification via Bluebird.
140
+
141
+ Design notes:
142
+ - setOptions() calls stop() to safely apply configuration changes.
143
+ - listenTo() abstracts event subscription across environments.
144
+
145
+ **Section sources**
146
+ - [base.js](file://src/api/transports/base.js#L4-L31)
147
+
148
+ ### HTTP Transport
149
+ Responsibilities:
150
+ - Build JSON-RPC payload and issue HTTP POST via cross-fetch.
151
+ - Validate response shape and propagate RPC errors.
152
+ - Use the configured websocket URL endpoint for HTTP calls.
153
+
154
+ Request/Response handling:
155
+ - Payload composition: jsonrpc 2.0, method "call", params [api, method, params].
156
+ - Response validation: HTTP OK, matching id, absence of error field.
157
+ - Error propagation: HTTP errors, invalid id, RPC error objects.
158
+
159
+ Retry mechanisms:
160
+ - Not implemented in HTTP transport. Retries should be handled by the caller or higher-level logic.
161
+
162
+ ```mermaid
163
+ sequenceDiagram
164
+ participant VIZ as "VIZ (api/index.js)"
165
+ participant HT as "HttpTransport (http.js)"
166
+ participant Net as "Network (cross-fetch)"
167
+ participant Cfg as "config.js"
168
+ VIZ->>HT : "send(api, data, callback)"
169
+ HT->>Cfg : "get('websocket')"
170
+ HT->>Net : "POST jsonrpc payload"
171
+ Net-->>HT : "HTTP response"
172
+ HT->>HT : "Validate status, id, error"
173
+ alt "Success"
174
+ HT-->>VIZ : "callback(null, result)"
175
+ else "Error"
176
+ HT-->>VIZ : "callback(RPCError or HTTP error)"
177
+ end
178
+ ```
179
+
180
+ **Diagram sources**
181
+ - [http.js](file://src/api/transports/http.js#L17-L41)
182
+ - [http.js](file://src/api/transports/http.js#L43-L52)
183
+ - [config.js](file://src/config.js#L5-L8)
184
+
185
+ **Section sources**
186
+ - [http.js](file://src/api/transports/http.js#L1-L53)
187
+
188
+ ### WebSocket Transport
189
+ Responsibilities:
190
+ - Establish and manage a persistent WebSocket connection.
191
+ - Queue outgoing requests and correlate responses by id.
192
+ - Emit performance metrics and handle lifecycle events.
193
+
194
+ Connection management:
195
+ - start(): Creates WebSocket, resolves on open, wires error/message/close handlers.
196
+ - stop(): Clears state, closes socket, clears queues.
197
+
198
+ Message handling:
199
+ - send(): Ensures connection, creates request with unique id, stores deferral, sends JSON, tracks inflight.
200
+ - onMessage(): Parses response, validates id presence, resolves/rejects deferral, emits performance metric.
201
+ - onError/onClose: Rejects pending requests and stops transport.
202
+
203
+ Real-time streaming:
204
+ - The transport itself does not implement streaming; it routes messages by id. Streaming is achieved by issuing repeated calls or using higher-level streams built on top of VIZ.
205
+
206
+ Automatic reconnection:
207
+ - The tests demonstrate that VIZ restarts the transport after a close event, enabling transparent reconnection for subsequent calls.
208
+
209
+ ```mermaid
210
+ flowchart TD
211
+ Start(["WsTransport.send"]) --> Ensure["Ensure connection via start()"]
212
+ Ensure --> Build["Build JSON-RPC message<br/>with unique id"]
213
+ Build --> Store["Store deferral and metadata"]
214
+ Store --> SendWS["Send over WebSocket"]
215
+ SendWS --> Wait["Wait for onMessage"]
216
+ Wait --> HasId{"Request id exists?"}
217
+ HasId --> |No| Panic["Throw panic error"]
218
+ HasId --> |Yes| HasErr{"Has error?"}
219
+ HasErr --> |Yes| Reject["Reject with error"]
220
+ HasErr --> |No| Resolve["Resolve with result"]
221
+ Resolve --> Track["Emit performance metric"]
222
+ Reject --> Stop["Stop transport on fatal error"]
223
+ Panic --> Stop
224
+ Stop --> End(["Done"])
225
+ ```
226
+
227
+ **Diagram sources**
228
+ - [ws.js](file://src/api/transports/ws.js#L64-L94)
229
+ - [ws.js](file://src/api/transports/ws.js#L111-L134)
230
+ - [ws.js](file://src/api/transports/ws.js#L96-L109)
231
+
232
+ **Section sources**
233
+ - [ws.js](file://src/api/transports/ws.js#L1-L136)
234
+
235
+ ### Transport Selection Logic
236
+ VIZ selects the transport based on the configured websocket URL:
237
+ - If URL matches http/https, select HTTP transport.
238
+ - If URL matches ws/wss, select WebSocket transport.
239
+ - Otherwise, throw an error indicating unknown transport.
240
+
241
+ This selection occurs during start() and when explicitly setting the WebSocket URL.
242
+
243
+ ```mermaid
244
+ flowchart TD
245
+ A["Get URL from config.get('websocket')"] --> B{"Starts with http/https?"}
246
+ B --> |Yes| H["Use HttpTransport"]
247
+ B --> |No| C{"Starts with ws/wss?"}
248
+ C --> |Yes| W["Use WsTransport"]
249
+ C --> |No| E["Throw error: unknown transport"]
250
+ ```
251
+
252
+ **Diagram sources**
253
+ - [index.js](file://src/api/index.js#L34-L42)
254
+
255
+ **Section sources**
256
+ - [index.js](file://src/api/index.js#L34-L42)
257
+
258
+ ## Dependency Analysis
259
+ - VIZ depends on the transports registry to instantiate the appropriate transport.
260
+ - HttpTransport depends on cross-fetch and the configuration module.
261
+ - WsTransport depends on detect-node to choose the WebSocket implementation and the configuration module.
262
+ - Base transport is a shared dependency for both HTTP and WebSocket.
263
+
264
+ ```mermaid
265
+ graph LR
266
+ VIZ["VIZ (api/index.js)"] --> Reg["Transports Index (index.js)"]
267
+ Reg --> Base["Transport (base.js)"]
268
+ Reg --> Http["HttpTransport (http.js)"]
269
+ Reg --> Ws["WsTransport (ws.js)"]
270
+ Http --> Cfg["config.js"]
271
+ Ws --> Cfg
272
+ Base --> Events["EventEmitter"]
273
+ ```
274
+
275
+ **Diagram sources**
276
+ - [index.js](file://src/api/index.js#L1-L271)
277
+ - [index.js](file://src/api/transports/index.js#L1-L8)
278
+ - [base.js](file://src/api/transports/base.js#L1-L34)
279
+ - [http.js](file://src/api/transports/http.js#L1-L53)
280
+ - [ws.js](file://src/api/transports/ws.js#L1-L136)
281
+ - [config.js](file://src/config.js#L1-L10)
282
+
283
+ **Section sources**
284
+ - [index.js](file://src/api/index.js#L1-L271)
285
+ - [index.js](file://src/api/transports/index.js#L1-L8)
286
+ - [base.js](file://src/api/transports/base.js#L1-L34)
287
+ - [http.js](file://src/api/transports/http.js#L1-L53)
288
+ - [ws.js](file://src/api/transports/ws.js#L1-L136)
289
+ - [config.js](file://src/config.js#L1-L10)
290
+
291
+ ## Performance Considerations
292
+ - WebSocket transport emits performance metrics for resolved requests, enabling monitoring of round-trip latency per method.
293
+ - HTTP transport does not implement retries; callers should implement retry policies if needed.
294
+ - Connection reuse: WebSocket transport maintains a single persistent connection, reducing overhead compared to frequent HTTP connections.
295
+ - Backpressure: WsTransport tracks inflight requests and queues responses by id; avoid excessive concurrent requests to prevent memory pressure.
296
+
297
+ [No sources needed since this section provides general guidance]
298
+
299
+ ## Troubleshooting Guide
300
+ Common issues and resolutions:
301
+ - Unknown transport error: Ensure the configured websocket URL uses a supported scheme (http/https for HTTP transport; ws/wss for WebSocket transport).
302
+ - WebSocket connection failures: Verify the backend endpoint is reachable and supports WebSocket upgrades. Inspect network tab for handshake errors.
303
+ - No response after send: Confirm the transport is started and the connection is open. For WebSocket, check that the socket is not closed unexpectedly.
304
+ - RPC errors: HTTP transport throws structured RPC errors; inspect error code and data fields for diagnostics.
305
+ - Reconnection behavior: The tests show that VIZ restarts the transport after a close event. If you observe repeated failures, validate server-side keepalive and firewall/NAT configurations.
306
+
307
+ **Section sources**
308
+ - [index.js](file://src/api/index.js#L34-L42)
309
+ - [http.js](file://src/api/transports/http.js#L8-L15)
310
+ - [api.test.js](file://test/api.test.js#L168-L200)
311
+
312
+ ## Conclusion
313
+ The VIZ transport layer provides a clean abstraction over HTTP and WebSocket protocols. VIZ selects the transport based on configuration, and both transports adhere to JSON-RPC semantics. WebSocket transport offers persistent connections and performance metrics, while HTTP transport provides a straightforward request/response model. Proper configuration and awareness of lifecycle events are essential for robust connectivity.
314
+
315
+ [No sources needed since this section summarizes without analyzing specific files]
316
+
317
+ ## Appendices
318
+
319
+ ### Configuration Options
320
+ - websocket: Endpoint URL used to select transport and for HTTP calls. Supported schemes:
321
+ - http/https for HTTP transport
322
+ - ws/wss for WebSocket transport
323
+ - address_prefix: Chain-specific address prefix.
324
+ - chain_id: Chain identifier.
325
+ - broadcast_transaction_with_callback: Boolean flag controlling broadcast behavior.
326
+
327
+ **Section sources**
328
+ - [config.json](file://config.json#L1-L7)
329
+ - [config.js](file://src/config.js#L1-L10)
330
+
331
+ ### Usage Patterns
332
+ - Basic usage with preconfigured endpoint:
333
+ - See example HTML invoking API methods.
334
+ - Transport selection:
335
+ - VIZ automatically selects transport based on the configured websocket URL.
336
+ - Real-time streaming:
337
+ - The library exposes streaming helpers built on top of the transport layer; consult the API methods and examples for usage.
338
+
339
+ **Section sources**
340
+ - [index.html](file://examples/index.html#L10-L20)
341
+ - [index.js](file://src/api/index.js#L121-L235)