@psalomo/jsonrpc-client 1.0.1 → 1.0.3

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/dist/index.js CHANGED
@@ -28,6 +28,7 @@ __export(index_exports, {
28
28
  NearRpcError: () => NearRpcError,
29
29
  RPC_METHODS: () => import_jsonrpc_types3.RPC_METHODS,
30
30
  block: () => block,
31
+ blockEffects: () => blockEffects,
31
32
  broadcastTxAsync: () => broadcastTxAsync,
32
33
  broadcastTxCommit: () => broadcastTxCommit,
33
34
  changes: () => changes,
@@ -49,8 +50,10 @@ __export(index_exports, {
49
50
  experimentalTxStatus: () => experimentalTxStatus,
50
51
  experimentalValidatorsOrdered: () => experimentalValidatorsOrdered,
51
52
  gasPrice: () => gasPrice,
53
+ genesisConfig: () => genesisConfig,
52
54
  health: () => health,
53
55
  lightClientProof: () => lightClientProof,
56
+ maintenanceWindows: () => maintenanceWindows,
54
57
  networkInfo: () => networkInfo,
55
58
  nextLightClientBlock: () => nextLightClientBlock,
56
59
  query: () => query,
@@ -109,9 +112,10 @@ var JsonRpcClientError = class extends Error {
109
112
  }
110
113
  };
111
114
  var JsonRpcNetworkError = class extends Error {
112
- constructor(message, originalError) {
115
+ constructor(message, originalError, responseBody) {
113
116
  super(message);
114
117
  this.originalError = originalError;
118
+ this.responseBody = responseBody;
115
119
  this.name = "JsonRpcNetworkError";
116
120
  }
117
121
  };
@@ -142,20 +146,26 @@ var NearRpcClient = class _NearRpcClient {
142
146
  * This is used internally by the standalone RPC functions
143
147
  */
144
148
  async makeRequest(method, params) {
145
- const snakeCaseParams = params ? convertKeysToSnakeCase(params) : params;
146
- const request = {
149
+ const requestForValidation = {
147
150
  jsonrpc: "2.0",
148
151
  id: REQUEST_ID,
149
152
  method,
150
- params: snakeCaseParams
153
+ params: params !== void 0 ? params : null
151
154
  };
152
155
  if (this.validation) {
153
156
  if ("validateMethodRequest" in this.validation) {
154
- this.validation.validateMethodRequest(method, request);
157
+ this.validation.validateMethodRequest(method, requestForValidation);
155
158
  } else {
156
- this.validation.validateRequest(request);
159
+ this.validation.validateRequest(requestForValidation);
157
160
  }
158
161
  }
162
+ const snakeCaseParams = params !== void 0 ? convertKeysToSnakeCase(params) : null;
163
+ const request = {
164
+ jsonrpc: "2.0",
165
+ id: REQUEST_ID,
166
+ method,
167
+ params: snakeCaseParams
168
+ };
159
169
  let lastError = null;
160
170
  for (let attempt = 0; attempt <= this.retries; attempt++) {
161
171
  try {
@@ -171,23 +181,21 @@ var NearRpcClient = class _NearRpcClient {
171
181
  signal: controller.signal
172
182
  });
173
183
  clearTimeout(timeoutId);
174
- if (!response.ok) {
175
- throw new JsonRpcNetworkError(
176
- `HTTP error! status: ${response.status}`
177
- );
178
- }
179
184
  let jsonResponse;
180
185
  try {
181
186
  jsonResponse = await response.json();
182
187
  } catch (parseError) {
188
+ if (!response.ok) {
189
+ throw new JsonRpcNetworkError(
190
+ `HTTP error! status: ${response.status} - Failed to parse JSON response`,
191
+ parseError
192
+ );
193
+ }
183
194
  throw new JsonRpcNetworkError(
184
195
  "Failed to parse JSON response",
185
196
  parseError
186
197
  );
187
198
  }
188
- if (this.validation) {
189
- this.validation.validateResponse(jsonResponse);
190
- }
191
199
  if (jsonResponse.error) {
192
200
  throw new JsonRpcClientError(
193
201
  jsonResponse.error.message,
@@ -195,6 +203,16 @@ var NearRpcClient = class _NearRpcClient {
195
203
  jsonResponse.error.data
196
204
  );
197
205
  }
206
+ if (!response.ok) {
207
+ throw new JsonRpcNetworkError(
208
+ `HTTP error! status: ${response.status}`,
209
+ void 0,
210
+ jsonResponse
211
+ );
212
+ }
213
+ if (this.validation) {
214
+ this.validation.validateResponse(jsonResponse);
215
+ }
198
216
  const camelCaseResult = jsonResponse.result ? convertKeysToCamelCase(jsonResponse.result) : jsonResponse.result;
199
217
  if (this.validation && "validateMethodResponse" in this.validation) {
200
218
  const camelCaseResponse = {
@@ -293,6 +311,9 @@ async function experimentalValidatorsOrdered(client, params) {
293
311
  async function block(client, params) {
294
312
  return client.makeRequest("block", params);
295
313
  }
314
+ async function blockEffects(client, params) {
315
+ return client.makeRequest("block_effects", params);
316
+ }
296
317
  async function broadcastTxAsync(client, params) {
297
318
  return client.makeRequest("broadcast_tx_async", params);
298
319
  }
@@ -311,12 +332,18 @@ async function clientConfig(client, params) {
311
332
  async function gasPrice(client, params) {
312
333
  return client.makeRequest("gas_price", params);
313
334
  }
335
+ async function genesisConfig(client, params) {
336
+ return client.makeRequest("genesis_config", params);
337
+ }
314
338
  async function health(client, params) {
315
339
  return client.makeRequest("health", params);
316
340
  }
317
341
  async function lightClientProof(client, params) {
318
342
  return client.makeRequest("light_client_proof", params);
319
343
  }
344
+ async function maintenanceWindows(client, params) {
345
+ return client.makeRequest("maintenance_windows", params);
346
+ }
320
347
  async function networkInfo(client, params) {
321
348
  return client.makeRequest("network_info", params);
322
349
  }
@@ -444,6 +471,7 @@ function enableValidation() {
444
471
  NearRpcError,
445
472
  RPC_METHODS,
446
473
  block,
474
+ blockEffects,
447
475
  broadcastTxAsync,
448
476
  broadcastTxCommit,
449
477
  changes,
@@ -464,8 +492,10 @@ function enableValidation() {
464
492
  experimentalTxStatus,
465
493
  experimentalValidatorsOrdered,
466
494
  gasPrice,
495
+ genesisConfig,
467
496
  health,
468
497
  lightClientProof,
498
+ maintenanceWindows,
469
499
  networkInfo,
470
500
  nextLightClientBlock,
471
501
  query,
package/dist/index.mjs CHANGED
@@ -43,9 +43,10 @@ var JsonRpcClientError = class extends Error {
43
43
  }
44
44
  };
45
45
  var JsonRpcNetworkError = class extends Error {
46
- constructor(message, originalError) {
46
+ constructor(message, originalError, responseBody) {
47
47
  super(message);
48
48
  this.originalError = originalError;
49
+ this.responseBody = responseBody;
49
50
  this.name = "JsonRpcNetworkError";
50
51
  }
51
52
  };
@@ -76,20 +77,26 @@ var NearRpcClient = class _NearRpcClient {
76
77
  * This is used internally by the standalone RPC functions
77
78
  */
78
79
  async makeRequest(method, params) {
79
- const snakeCaseParams = params ? convertKeysToSnakeCase(params) : params;
80
- const request = {
80
+ const requestForValidation = {
81
81
  jsonrpc: "2.0",
82
82
  id: REQUEST_ID,
83
83
  method,
84
- params: snakeCaseParams
84
+ params: params !== void 0 ? params : null
85
85
  };
86
86
  if (this.validation) {
87
87
  if ("validateMethodRequest" in this.validation) {
88
- this.validation.validateMethodRequest(method, request);
88
+ this.validation.validateMethodRequest(method, requestForValidation);
89
89
  } else {
90
- this.validation.validateRequest(request);
90
+ this.validation.validateRequest(requestForValidation);
91
91
  }
92
92
  }
93
+ const snakeCaseParams = params !== void 0 ? convertKeysToSnakeCase(params) : null;
94
+ const request = {
95
+ jsonrpc: "2.0",
96
+ id: REQUEST_ID,
97
+ method,
98
+ params: snakeCaseParams
99
+ };
93
100
  let lastError = null;
94
101
  for (let attempt = 0; attempt <= this.retries; attempt++) {
95
102
  try {
@@ -105,23 +112,21 @@ var NearRpcClient = class _NearRpcClient {
105
112
  signal: controller.signal
106
113
  });
107
114
  clearTimeout(timeoutId);
108
- if (!response.ok) {
109
- throw new JsonRpcNetworkError(
110
- `HTTP error! status: ${response.status}`
111
- );
112
- }
113
115
  let jsonResponse;
114
116
  try {
115
117
  jsonResponse = await response.json();
116
118
  } catch (parseError) {
119
+ if (!response.ok) {
120
+ throw new JsonRpcNetworkError(
121
+ `HTTP error! status: ${response.status} - Failed to parse JSON response`,
122
+ parseError
123
+ );
124
+ }
117
125
  throw new JsonRpcNetworkError(
118
126
  "Failed to parse JSON response",
119
127
  parseError
120
128
  );
121
129
  }
122
- if (this.validation) {
123
- this.validation.validateResponse(jsonResponse);
124
- }
125
130
  if (jsonResponse.error) {
126
131
  throw new JsonRpcClientError(
127
132
  jsonResponse.error.message,
@@ -129,6 +134,16 @@ var NearRpcClient = class _NearRpcClient {
129
134
  jsonResponse.error.data
130
135
  );
131
136
  }
137
+ if (!response.ok) {
138
+ throw new JsonRpcNetworkError(
139
+ `HTTP error! status: ${response.status}`,
140
+ void 0,
141
+ jsonResponse
142
+ );
143
+ }
144
+ if (this.validation) {
145
+ this.validation.validateResponse(jsonResponse);
146
+ }
132
147
  const camelCaseResult = jsonResponse.result ? convertKeysToCamelCase(jsonResponse.result) : jsonResponse.result;
133
148
  if (this.validation && "validateMethodResponse" in this.validation) {
134
149
  const camelCaseResponse = {
@@ -230,6 +245,9 @@ async function experimentalValidatorsOrdered(client, params) {
230
245
  async function block(client, params) {
231
246
  return client.makeRequest("block", params);
232
247
  }
248
+ async function blockEffects(client, params) {
249
+ return client.makeRequest("block_effects", params);
250
+ }
233
251
  async function broadcastTxAsync(client, params) {
234
252
  return client.makeRequest("broadcast_tx_async", params);
235
253
  }
@@ -248,12 +266,18 @@ async function clientConfig(client, params) {
248
266
  async function gasPrice(client, params) {
249
267
  return client.makeRequest("gas_price", params);
250
268
  }
269
+ async function genesisConfig(client, params) {
270
+ return client.makeRequest("genesis_config", params);
271
+ }
251
272
  async function health(client, params) {
252
273
  return client.makeRequest("health", params);
253
274
  }
254
275
  async function lightClientProof(client, params) {
255
276
  return client.makeRequest("light_client_proof", params);
256
277
  }
278
+ async function maintenanceWindows(client, params) {
279
+ return client.makeRequest("maintenance_windows", params);
280
+ }
257
281
  async function networkInfo(client, params) {
258
282
  return client.makeRequest("network_info", params);
259
283
  }
@@ -384,6 +408,7 @@ export {
384
408
  NearRpcError,
385
409
  RPC_METHODS,
386
410
  block,
411
+ blockEffects,
387
412
  broadcastTxAsync,
388
413
  broadcastTxCommit,
389
414
  changes,
@@ -405,8 +430,10 @@ export {
405
430
  experimentalTxStatus,
406
431
  experimentalValidatorsOrdered,
407
432
  gasPrice,
433
+ genesisConfig,
408
434
  health,
409
435
  lightClientProof,
436
+ maintenanceWindows,
410
437
  networkInfo,
411
438
  nextLightClientBlock,
412
439
  query,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psalomo/jsonrpc-client",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "TypeScript client for NEAR Protocol JSON-RPC API",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -30,7 +30,7 @@
30
30
  "test:coverage": "vitest run --coverage"
31
31
  },
32
32
  "dependencies": {
33
- "@psalomo/jsonrpc-types": "^1.0.1"
33
+ "@psalomo/jsonrpc-types": "^1.0.3"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@rollup/plugin-node-resolve": "^16.0.1",