postchain-client 1.16.1 → 1.18.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.
Files changed (65) hide show
  1. package/README.md +50 -3
  2. package/built/cjs/index.js +209 -62
  3. package/built/cjs/index.js.map +1 -1
  4. package/built/esm/index.js +208 -63
  5. package/built/esm/index.js.map +1 -1
  6. package/built/index.d.ts +1 -0
  7. package/built/index.js +1 -0
  8. package/built/index.js.map +1 -1
  9. package/built/{src/mocks → mocks}/handlers.d.ts +2 -0
  10. package/built/{src/mocks → mocks}/handlers.js +22 -8
  11. package/built/mocks/handlers.js.map +1 -0
  12. package/built/mocks/servers.js.map +1 -0
  13. package/built/resources/testData.d.ts +5 -0
  14. package/built/resources/testData.js +24 -0
  15. package/built/resources/testData.js.map +1 -0
  16. package/built/src/ICCF/IccfProofTxMaterialBuilder.d.ts +2 -2
  17. package/built/src/ICCF/IccfProofTxMaterialBuilder.js +2 -2
  18. package/built/src/blockchainClient/blockchainClient.js +25 -13
  19. package/built/src/blockchainClient/blockchainClient.js.map +1 -1
  20. package/built/src/blockchainClient/clientStub.js +7 -0
  21. package/built/src/blockchainClient/clientStub.js.map +1 -1
  22. package/built/src/blockchainClient/errors.js +1 -1
  23. package/built/src/blockchainClient/errors.js.map +1 -1
  24. package/built/src/blockchainClient/interface.d.ts +2 -1
  25. package/built/src/blockchainClient/types.d.ts +39 -0
  26. package/built/src/blockchainClient/utils.d.ts +10 -1
  27. package/built/src/blockchainClient/utils.js +42 -10
  28. package/built/src/blockchainClient/utils.js.map +1 -1
  29. package/built/src/gtx/interfaces.d.ts +2 -2
  30. package/built/src/logger.d.ts +3 -1
  31. package/built/src/logger.js.map +1 -1
  32. package/built/src/merkle/binarytreefactory.js +1 -1
  33. package/built/src/merkle/binarytreefactory.js.map +1 -1
  34. package/built/src/merkle/proof/merkleprooftreefactory.d.ts +2 -2
  35. package/built/src/merkle/proof/merkleprooftreefactory.js +3 -3
  36. package/built/src/merkle/proof/merkleprooftreefactory.js.map +1 -1
  37. package/built/src/restclient/failoverStrategies.d.ts +4 -4
  38. package/built/src/restclient/failoverStrategies.js +16 -9
  39. package/built/src/restclient/failoverStrategies.js.map +1 -1
  40. package/built/src/restclient/interfaces.d.ts +3 -3
  41. package/built/src/restclient/nodeManager.d.ts +20 -0
  42. package/built/src/restclient/nodeManager.js +60 -0
  43. package/built/src/restclient/nodeManager.js.map +1 -0
  44. package/built/src/restclient/restclient.d.ts +1 -1
  45. package/built/src/restclient/restclient.js +16 -12
  46. package/built/src/restclient/restclient.js.map +1 -1
  47. package/built/src/restclient/restclientutil.d.ts +10 -3
  48. package/built/src/restclient/restclientutil.js +9 -12
  49. package/built/src/restclient/restclientutil.js.map +1 -1
  50. package/built/src/restclient/types.d.ts +23 -5
  51. package/built/src/restclient/types.js.map +1 -1
  52. package/built/src/utils/dump.d.ts +4 -0
  53. package/built/src/utils/dump.js +31 -0
  54. package/built/src/utils/dump.js.map +1 -0
  55. package/built/src/utils/dump.test.d.ts +1 -0
  56. package/built/src/utils/dump.test.js +46 -0
  57. package/built/src/utils/dump.test.js.map +1 -0
  58. package/built/umd/index.js +209 -62
  59. package/built/umd/index.js.map +1 -1
  60. package/changelog.md +36 -3
  61. package/package.json +1 -1
  62. package/built/src/mocks/handlers.js.map +0 -1
  63. package/built/src/mocks/servers.js.map +0 -1
  64. /package/built/{src/mocks → mocks}/servers.d.ts +0 -0
  65. /package/built/{src/mocks → mocks}/servers.js +0 -0
package/README.md CHANGED
@@ -52,6 +52,7 @@ Create a Chromia client instance and configures it according to your needs.
52
52
  - `attemptsPerEndpoint` (Optional): Number of consecutive failed attempts allowed for each endpoint before considering it as unreachable. Defaults to 3.
53
53
  - `attemptInterval` (Optional): Interval (in milliseconds) between consecutive retry attempts during failover. Defaults to 5000 ms.
54
54
  - `unreachableDuration` (Optional): Duration (in milliseconds) that an endpoint should remain unreachable before reattempting. Defaults to 30000 ms.
55
+ - `useStickyNode`(Optional): A boolean that will make sure that on succefull requests to a node, the client will continue using this node unless it starts failing.
55
56
 
56
57
  ### Returns
57
58
 
@@ -77,6 +78,48 @@ const chromiaClient = await createClient({
77
78
  });
78
79
  ```
79
80
 
81
+ ### Use sticky node
82
+
83
+ #### What is a "sticky node"?
84
+
85
+ _A sticky node is a node that will will continue to be used for requests as long as the requests to it are successful, this means that if the client is making a request to get the block height of a dapp, and it successful, then following requests to get other data eg: dapp transactions will be using the same node, meaning that is "sticks" with the user once selected._
86
+
87
+ #### How does it work?
88
+
89
+ The client will need to be initialized with a `directoryNodeUrlPool` and have the property `useStickyNode` set to `true` in the `settings` parameter for it to be enabled. example:
90
+
91
+ ```typescript
92
+ const client = createClient({
93
+ useStickyNode: true,
94
+ directoryNodeUrlPool: ["http://localhost:7740"],
95
+ ...restSettings,
96
+ });
97
+ ```
98
+
99
+ This will then create internally create a nodeManager, that handles and keeps track of which nodes are available and which one is currently set to be the "sticky node".
100
+
101
+ As a user, when you first make a request with this feature enabled, you will not have any "sticky node" set. Instead whenever you make a request, the client will choose a random node out of the ones available. Should the request to the node be successful, then that node will be set as the "sticky node". This will happen regardless of what failoverStrategy has been set.
102
+
103
+ Any subsequent requests after the first successful one will continue to use "sticky node" as long as it continues to give successful requests. Should the node fail however, then it will be set at unavailable for the duration configured in the client settings (or the default time of 30000ms) and following requests will once again try to use a random available node and if successful set that one as the new "sticky node".
104
+
105
+ #### Setting how long a node should be unavailable
106
+
107
+ The duration that a node is configured as unavailable can be se in the failoverConfig of the client settings:
108
+
109
+ ```typescript
110
+ const client = createClient({
111
+ useStickyNode: true,
112
+ directoryNodeUrlPool: ["http://localhost:7740"],
113
+ failOverConfig: {
114
+ startegy: "abortOnErrror",
115
+ attemptsPerEndpoint: 4,
116
+ attemptInterval: 3000,
117
+ unreachableDuration: 50000,
118
+ }
119
+ ...restSettings
120
+ })
121
+ ```
122
+
80
123
  ### Failover strategies
81
124
 
82
125
  When initializing a client, you have the option to configure the failover strategy for the client. Additionally, you can modify certain parameters within the failover configuration, such as the number of attempts per endpoint and the interval between attempts.
@@ -178,10 +221,10 @@ const signatureProviderA = newSignatureProvider({ privKey: signerPrivKeyA });
178
221
 
179
222
  ### Simple Transaction
180
223
 
181
- The `signAndSendUniqueTransaction` function streamlines the process of sending a transaction in three steps. It adds a "nop" (no operation) with a random number that ensures the transaction is unique, signs it with a signature provider or private key, and sends it. The function generates a receipt that includes a status code, status, and transactionRID. The status code indicates whether the server successfully processed the transaction. The status represents the current stage of the transaction on the blockchain, which can be one of the following: `Waiting`, `Rejected`, `Confirmed`, or `Unknown`.
224
+ The `signAndSendUniqueTransaction` function streamlines the process of sending a transaction in three steps. It adds a "nop" (no operation) with a random number that ensures the transaction is unique, signs it with a signature provider or private key, and sends it. The function generates a receipt that includes a status code, status, and tansactionRid. The status code indicates whether the server successfully processed the transaction. The status represents the current stage of the transaction on the blockchain, which can be one of the following: `Waiting`, `Rejected`, `Confirmed`, or `Unknown`.
182
225
 
183
226
  ```typescript
184
- const { status, statusCode, transactionRID } =
227
+ const { status, statusCode, transactionRid } =
185
228
  await chromiaClient.signAndSendUniqueTransaction(
186
229
  {
187
230
  operations: [
@@ -412,10 +455,14 @@ Integration tests:
412
455
  1. Make sure a postgres database is running. Read more [here](https://docs.chromia.com/getting-started/dev-setup/database-setup).
413
456
  2. Start blockchain
414
457
 
415
- `cd resources`
458
+ `cd resources/testDapp`
416
459
 
417
460
  `chr node start --wipe`
418
461
 
419
462
  3. Run tests
420
463
 
421
464
  `npm run test:integration`
465
+
466
+ ## Release process
467
+
468
+ Guide regarding realease process is [here](docs/release.md)