@psalomo/jsonrpc-client 1.0.2 → 1.1.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.
- package/dist/browser-standalone.js +201 -49
- package/dist/browser-standalone.min.js +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/generated-functions.d.ts +1 -1
- package/dist/generated-functions.d.ts.map +1 -1
- package/dist/generated-types.d.ts +7 -1
- package/dist/generated-types.d.ts.map +1 -1
- package/dist/index.d.mts +9 -3
- package/dist/index.js +46 -5
- package/dist/index.mjs +43 -5
- package/dist/validation.d.ts.map +1 -1
- package/package.json +2 -2
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,
|
@@ -143,20 +146,26 @@ var NearRpcClient = class _NearRpcClient {
|
|
143
146
|
* This is used internally by the standalone RPC functions
|
144
147
|
*/
|
145
148
|
async makeRequest(method, params) {
|
146
|
-
const
|
147
|
-
const request = {
|
149
|
+
const requestForValidation = {
|
148
150
|
jsonrpc: "2.0",
|
149
151
|
id: REQUEST_ID,
|
150
152
|
method,
|
151
|
-
params:
|
153
|
+
params: params !== void 0 ? params : null
|
152
154
|
};
|
153
155
|
if (this.validation) {
|
154
156
|
if ("validateMethodRequest" in this.validation) {
|
155
|
-
this.validation.validateMethodRequest(method,
|
157
|
+
this.validation.validateMethodRequest(method, requestForValidation);
|
156
158
|
} else {
|
157
|
-
this.validation.validateRequest(
|
159
|
+
this.validation.validateRequest(requestForValidation);
|
158
160
|
}
|
159
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
|
+
};
|
160
169
|
let lastError = null;
|
161
170
|
for (let attempt = 0; attempt <= this.retries; attempt++) {
|
162
171
|
try {
|
@@ -205,6 +214,15 @@ var NearRpcClient = class _NearRpcClient {
|
|
205
214
|
this.validation.validateResponse(jsonResponse);
|
206
215
|
}
|
207
216
|
const camelCaseResult = jsonResponse.result ? convertKeysToCamelCase(jsonResponse.result) : jsonResponse.result;
|
217
|
+
if (camelCaseResult && typeof camelCaseResult === "object" && "error" in camelCaseResult) {
|
218
|
+
const errorMessage = camelCaseResult.error;
|
219
|
+
throw new JsonRpcClientError(
|
220
|
+
`RPC Error: ${errorMessage}`,
|
221
|
+
-32e3,
|
222
|
+
// Generic RPC error code
|
223
|
+
camelCaseResult
|
224
|
+
);
|
225
|
+
}
|
208
226
|
if (this.validation && "validateMethodResponse" in this.validation) {
|
209
227
|
const camelCaseResponse = {
|
210
228
|
...jsonResponse,
|
@@ -302,6 +320,9 @@ async function experimentalValidatorsOrdered(client, params) {
|
|
302
320
|
async function block(client, params) {
|
303
321
|
return client.makeRequest("block", params);
|
304
322
|
}
|
323
|
+
async function blockEffects(client, params) {
|
324
|
+
return client.makeRequest("block_effects", params);
|
325
|
+
}
|
305
326
|
async function broadcastTxAsync(client, params) {
|
306
327
|
return client.makeRequest("broadcast_tx_async", params);
|
307
328
|
}
|
@@ -320,12 +341,18 @@ async function clientConfig(client, params) {
|
|
320
341
|
async function gasPrice(client, params) {
|
321
342
|
return client.makeRequest("gas_price", params);
|
322
343
|
}
|
344
|
+
async function genesisConfig(client, params) {
|
345
|
+
return client.makeRequest("genesis_config", params);
|
346
|
+
}
|
323
347
|
async function health(client, params) {
|
324
348
|
return client.makeRequest("health", params);
|
325
349
|
}
|
326
350
|
async function lightClientProof(client, params) {
|
327
351
|
return client.makeRequest("light_client_proof", params);
|
328
352
|
}
|
353
|
+
async function maintenanceWindows(client, params) {
|
354
|
+
return client.makeRequest("maintenance_windows", params);
|
355
|
+
}
|
329
356
|
async function networkInfo(client, params) {
|
330
357
|
return client.makeRequest("network_info", params);
|
331
358
|
}
|
@@ -430,12 +457,23 @@ function enableValidation() {
|
|
430
457
|
validateMethodResponse: (method, response) => {
|
431
458
|
try {
|
432
459
|
responseSchema.parse(response);
|
460
|
+
if (response.result && typeof response.result === "object" && "error" in response.result) {
|
461
|
+
const serverError = response.result.error;
|
462
|
+
throw new JsonRpcClientError(
|
463
|
+
`Server error: ${serverError}`,
|
464
|
+
-32e3,
|
465
|
+
response.result
|
466
|
+
);
|
467
|
+
}
|
433
468
|
const methodSchemas = import_jsonrpc_types.VALIDATION_SCHEMA_MAP[method];
|
434
469
|
if (methodSchemas?.responseSchema) {
|
435
470
|
const methodResponseSchema = methodSchemas.responseSchema();
|
436
471
|
methodResponseSchema.parse(response);
|
437
472
|
}
|
438
473
|
} catch (error) {
|
474
|
+
if (error instanceof JsonRpcClientError) {
|
475
|
+
throw error;
|
476
|
+
}
|
439
477
|
throw new JsonRpcClientError(
|
440
478
|
`Invalid ${method} response: ${error instanceof Error ? error.message : "Unknown error"}`
|
441
479
|
);
|
@@ -453,6 +491,7 @@ function enableValidation() {
|
|
453
491
|
NearRpcError,
|
454
492
|
RPC_METHODS,
|
455
493
|
block,
|
494
|
+
blockEffects,
|
456
495
|
broadcastTxAsync,
|
457
496
|
broadcastTxCommit,
|
458
497
|
changes,
|
@@ -473,8 +512,10 @@ function enableValidation() {
|
|
473
512
|
experimentalTxStatus,
|
474
513
|
experimentalValidatorsOrdered,
|
475
514
|
gasPrice,
|
515
|
+
genesisConfig,
|
476
516
|
health,
|
477
517
|
lightClientProof,
|
518
|
+
maintenanceWindows,
|
478
519
|
networkInfo,
|
479
520
|
nextLightClientBlock,
|
480
521
|
query,
|
package/dist/index.mjs
CHANGED
@@ -77,20 +77,26 @@ var NearRpcClient = class _NearRpcClient {
|
|
77
77
|
* This is used internally by the standalone RPC functions
|
78
78
|
*/
|
79
79
|
async makeRequest(method, params) {
|
80
|
-
const
|
81
|
-
const request = {
|
80
|
+
const requestForValidation = {
|
82
81
|
jsonrpc: "2.0",
|
83
82
|
id: REQUEST_ID,
|
84
83
|
method,
|
85
|
-
params:
|
84
|
+
params: params !== void 0 ? params : null
|
86
85
|
};
|
87
86
|
if (this.validation) {
|
88
87
|
if ("validateMethodRequest" in this.validation) {
|
89
|
-
this.validation.validateMethodRequest(method,
|
88
|
+
this.validation.validateMethodRequest(method, requestForValidation);
|
90
89
|
} else {
|
91
|
-
this.validation.validateRequest(
|
90
|
+
this.validation.validateRequest(requestForValidation);
|
92
91
|
}
|
93
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
|
+
};
|
94
100
|
let lastError = null;
|
95
101
|
for (let attempt = 0; attempt <= this.retries; attempt++) {
|
96
102
|
try {
|
@@ -139,6 +145,15 @@ var NearRpcClient = class _NearRpcClient {
|
|
139
145
|
this.validation.validateResponse(jsonResponse);
|
140
146
|
}
|
141
147
|
const camelCaseResult = jsonResponse.result ? convertKeysToCamelCase(jsonResponse.result) : jsonResponse.result;
|
148
|
+
if (camelCaseResult && typeof camelCaseResult === "object" && "error" in camelCaseResult) {
|
149
|
+
const errorMessage = camelCaseResult.error;
|
150
|
+
throw new JsonRpcClientError(
|
151
|
+
`RPC Error: ${errorMessage}`,
|
152
|
+
-32e3,
|
153
|
+
// Generic RPC error code
|
154
|
+
camelCaseResult
|
155
|
+
);
|
156
|
+
}
|
142
157
|
if (this.validation && "validateMethodResponse" in this.validation) {
|
143
158
|
const camelCaseResponse = {
|
144
159
|
...jsonResponse,
|
@@ -239,6 +254,9 @@ async function experimentalValidatorsOrdered(client, params) {
|
|
239
254
|
async function block(client, params) {
|
240
255
|
return client.makeRequest("block", params);
|
241
256
|
}
|
257
|
+
async function blockEffects(client, params) {
|
258
|
+
return client.makeRequest("block_effects", params);
|
259
|
+
}
|
242
260
|
async function broadcastTxAsync(client, params) {
|
243
261
|
return client.makeRequest("broadcast_tx_async", params);
|
244
262
|
}
|
@@ -257,12 +275,18 @@ async function clientConfig(client, params) {
|
|
257
275
|
async function gasPrice(client, params) {
|
258
276
|
return client.makeRequest("gas_price", params);
|
259
277
|
}
|
278
|
+
async function genesisConfig(client, params) {
|
279
|
+
return client.makeRequest("genesis_config", params);
|
280
|
+
}
|
260
281
|
async function health(client, params) {
|
261
282
|
return client.makeRequest("health", params);
|
262
283
|
}
|
263
284
|
async function lightClientProof(client, params) {
|
264
285
|
return client.makeRequest("light_client_proof", params);
|
265
286
|
}
|
287
|
+
async function maintenanceWindows(client, params) {
|
288
|
+
return client.makeRequest("maintenance_windows", params);
|
289
|
+
}
|
266
290
|
async function networkInfo(client, params) {
|
267
291
|
return client.makeRequest("network_info", params);
|
268
292
|
}
|
@@ -371,12 +395,23 @@ function enableValidation() {
|
|
371
395
|
validateMethodResponse: (method, response) => {
|
372
396
|
try {
|
373
397
|
responseSchema.parse(response);
|
398
|
+
if (response.result && typeof response.result === "object" && "error" in response.result) {
|
399
|
+
const serverError = response.result.error;
|
400
|
+
throw new JsonRpcClientError(
|
401
|
+
`Server error: ${serverError}`,
|
402
|
+
-32e3,
|
403
|
+
response.result
|
404
|
+
);
|
405
|
+
}
|
374
406
|
const methodSchemas = VALIDATION_SCHEMA_MAP[method];
|
375
407
|
if (methodSchemas?.responseSchema) {
|
376
408
|
const methodResponseSchema = methodSchemas.responseSchema();
|
377
409
|
methodResponseSchema.parse(response);
|
378
410
|
}
|
379
411
|
} catch (error) {
|
412
|
+
if (error instanceof JsonRpcClientError) {
|
413
|
+
throw error;
|
414
|
+
}
|
380
415
|
throw new JsonRpcClientError(
|
381
416
|
`Invalid ${method} response: ${error instanceof Error ? error.message : "Unknown error"}`
|
382
417
|
);
|
@@ -393,6 +428,7 @@ export {
|
|
393
428
|
NearRpcError,
|
394
429
|
RPC_METHODS,
|
395
430
|
block,
|
431
|
+
blockEffects,
|
396
432
|
broadcastTxAsync,
|
397
433
|
broadcastTxCommit,
|
398
434
|
changes,
|
@@ -414,8 +450,10 @@ export {
|
|
414
450
|
experimentalTxStatus,
|
415
451
|
experimentalValidatorsOrdered,
|
416
452
|
gasPrice,
|
453
|
+
genesisConfig,
|
417
454
|
health,
|
418
455
|
lightClientProof,
|
456
|
+
maintenanceWindows,
|
419
457
|
networkInfo,
|
420
458
|
nextLightClientBlock,
|
421
459
|
query,
|
package/dist/validation.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,cAAc,EACd,eAAe,EAGhB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IACnD,gBAAgB,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;IACtD,qBAAqB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1E,sBAAsB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;CAC9E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,gBAAgB,
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,cAAc,EACd,eAAe,EAGhB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,gBAAgB;IAC/B,eAAe,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IACnD,gBAAgB,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;IACtD,qBAAqB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1E,sBAAsB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;CAC9E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,gBAAgB,CAoFnD"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@psalomo/jsonrpc-client",
|
3
|
-
"version": "1.0
|
3
|
+
"version": "1.1.0",
|
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
|
33
|
+
"@psalomo/jsonrpc-types": "^1.1.0"
|
34
34
|
},
|
35
35
|
"devDependencies": {
|
36
36
|
"@rollup/plugin-node-resolve": "^16.0.1",
|