@psalomo/jsonrpc-client 1.0.3 → 1.2.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.
@@ -156,6 +156,15 @@ class NearRpcClient {
156
156
  const camelCaseResult = jsonResponse.result
157
157
  ? convertKeysToCamelCase(jsonResponse.result)
158
158
  : jsonResponse.result;
159
+ // Check if the result contains an error field (non-standard NEAR RPC error response)
160
+ // This happens when validation is disabled and certain RPC errors occur
161
+ if (camelCaseResult &&
162
+ typeof camelCaseResult === 'object' &&
163
+ 'error' in camelCaseResult) {
164
+ const errorMessage = camelCaseResult.error;
165
+ throw new JsonRpcClientError(`RPC Error: ${errorMessage}`, -32000, // Generic RPC error code
166
+ camelCaseResult);
167
+ }
159
168
  // Validate method-specific response structure after camelCase conversion
160
169
  if (this.validation && 'validateMethodResponse' in this.validation) {
161
170
  // Create a camelCase version of the response for validation
@@ -4881,138 +4890,168 @@ Object.entries(PATH_TO_METHOD_MAP).forEach(([path, method]) => {
4881
4890
  var RPC_METHODS = Object.values(PATH_TO_METHOD_MAP);
4882
4891
 
4883
4892
  // Auto-generated static RPC functions for tree-shaking
4884
- // Generated at: 2025-07-29T20:18:38.221Z
4893
+ // Generated at: 2025-07-31T19:21:47.589Z
4885
4894
  // Total functions: 31
4886
4895
  //
4887
4896
  // This file is automatically generated by tools/codegen/generate-client-interface.ts
4888
4897
  // Do not edit manually - changes will be overwritten
4889
4898
  // EXPERIMENTAL_changes static function
4890
- async function experimentalChanges(client, params) {
4899
+ async function experimentalChanges$1(client, params) {
4891
4900
  return client.makeRequest('EXPERIMENTAL_changes', params);
4892
4901
  }
4893
4902
  // EXPERIMENTAL_changes_in_block static function
4894
- async function experimentalChangesInBlock(client, params) {
4903
+ async function experimentalChangesInBlock$1(client, params) {
4895
4904
  return client.makeRequest('EXPERIMENTAL_changes_in_block', params);
4896
4905
  }
4897
4906
  // EXPERIMENTAL_congestion_level static function
4898
- async function experimentalCongestionLevel(client, params) {
4907
+ async function experimentalCongestionLevel$1(client, params) {
4899
4908
  return client.makeRequest('EXPERIMENTAL_congestion_level', params);
4900
4909
  }
4901
4910
  // EXPERIMENTAL_genesis_config static function
4902
- async function experimentalGenesisConfig(client, params) {
4911
+ async function experimentalGenesisConfig$1(client, params) {
4903
4912
  return client.makeRequest('EXPERIMENTAL_genesis_config', params);
4904
4913
  }
4905
4914
  // EXPERIMENTAL_light_client_block_proof static function
4906
- async function experimentalLightClientBlockProof(client, params) {
4915
+ async function experimentalLightClientBlockProof$1(client, params) {
4907
4916
  return client.makeRequest('EXPERIMENTAL_light_client_block_proof', params);
4908
4917
  }
4909
4918
  // EXPERIMENTAL_light_client_proof static function
4910
- async function experimentalLightClientProof(client, params) {
4919
+ async function experimentalLightClientProof$1(client, params) {
4911
4920
  return client.makeRequest('EXPERIMENTAL_light_client_proof', params);
4912
4921
  }
4913
4922
  // EXPERIMENTAL_maintenance_windows static function
4914
- async function experimentalMaintenanceWindows(client, params) {
4923
+ async function experimentalMaintenanceWindows$1(client, params) {
4915
4924
  return client.makeRequest('EXPERIMENTAL_maintenance_windows', params);
4916
4925
  }
4917
4926
  // EXPERIMENTAL_protocol_config static function
4918
- async function experimentalProtocolConfig(client, params) {
4927
+ async function experimentalProtocolConfig$1(client, params) {
4919
4928
  return client.makeRequest('EXPERIMENTAL_protocol_config', params);
4920
4929
  }
4921
4930
  // EXPERIMENTAL_receipt static function
4922
- async function experimentalReceipt(client, params) {
4931
+ async function experimentalReceipt$1(client, params) {
4923
4932
  return client.makeRequest('EXPERIMENTAL_receipt', params);
4924
4933
  }
4925
4934
  // EXPERIMENTAL_split_storage_info static function
4926
- async function experimentalSplitStorageInfo(client, params) {
4935
+ async function experimentalSplitStorageInfo$1(client, params) {
4927
4936
  return client.makeRequest('EXPERIMENTAL_split_storage_info', params);
4928
4937
  }
4929
4938
  // EXPERIMENTAL_tx_status static function
4930
- async function experimentalTxStatus(client, params) {
4939
+ async function experimentalTxStatus$1(client, params) {
4931
4940
  return client.makeRequest('EXPERIMENTAL_tx_status', params);
4932
4941
  }
4933
4942
  // EXPERIMENTAL_validators_ordered static function
4934
- async function experimentalValidatorsOrdered(client, params) {
4943
+ async function experimentalValidatorsOrdered$1(client, params) {
4935
4944
  return client.makeRequest('EXPERIMENTAL_validators_ordered', params);
4936
4945
  }
4937
4946
  // block static function
4938
- async function block(client, params) {
4947
+ async function block$1(client, params) {
4939
4948
  return client.makeRequest('block', params);
4940
4949
  }
4941
4950
  // block_effects static function
4942
- async function blockEffects(client, params) {
4951
+ async function blockEffects$1(client, params) {
4943
4952
  return client.makeRequest('block_effects', params);
4944
4953
  }
4945
4954
  // broadcast_tx_async static function
4946
- async function broadcastTxAsync(client, params) {
4955
+ async function broadcastTxAsync$1(client, params) {
4947
4956
  return client.makeRequest('broadcast_tx_async', params);
4948
4957
  }
4949
4958
  // broadcast_tx_commit static function
4950
- async function broadcastTxCommit(client, params) {
4959
+ async function broadcastTxCommit$1(client, params) {
4951
4960
  return client.makeRequest('broadcast_tx_commit', params);
4952
4961
  }
4953
4962
  // changes static function
4954
- async function changes(client, params) {
4963
+ async function changes$1(client, params) {
4955
4964
  return client.makeRequest('changes', params);
4956
4965
  }
4957
4966
  // chunk static function
4958
- async function chunk(client, params) {
4967
+ async function chunk$1(client, params) {
4959
4968
  return client.makeRequest('chunk', params);
4960
4969
  }
4961
4970
  // client_config static function
4962
- async function clientConfig(client, params) {
4971
+ async function clientConfig$1(client, params) {
4963
4972
  return client.makeRequest('client_config', params);
4964
4973
  }
4965
4974
  // gas_price static function
4966
- async function gasPrice(client, params) {
4975
+ async function gasPrice$1(client, params) {
4967
4976
  return client.makeRequest('gas_price', params);
4968
4977
  }
4969
4978
  // genesis_config static function
4970
- async function genesisConfig(client, params) {
4979
+ async function genesisConfig$1(client, params) {
4971
4980
  return client.makeRequest('genesis_config', params);
4972
4981
  }
4973
4982
  // health static function
4974
- async function health(client, params) {
4983
+ async function health$1(client, params) {
4975
4984
  return client.makeRequest('health', params);
4976
4985
  }
4977
4986
  // light_client_proof static function
4978
- async function lightClientProof(client, params) {
4987
+ async function lightClientProof$1(client, params) {
4979
4988
  return client.makeRequest('light_client_proof', params);
4980
4989
  }
4981
4990
  // maintenance_windows static function
4982
- async function maintenanceWindows(client, params) {
4991
+ async function maintenanceWindows$1(client, params) {
4983
4992
  return client.makeRequest('maintenance_windows', params);
4984
4993
  }
4985
4994
  // network_info static function
4986
- async function networkInfo(client, params) {
4995
+ async function networkInfo$1(client, params) {
4987
4996
  return client.makeRequest('network_info', params);
4988
4997
  }
4989
4998
  // next_light_client_block static function
4990
- async function nextLightClientBlock(client, params) {
4999
+ async function nextLightClientBlock$1(client, params) {
4991
5000
  return client.makeRequest('next_light_client_block', params);
4992
5001
  }
4993
5002
  // query static function
4994
- async function query(client, params) {
5003
+ async function query$1(client, params) {
4995
5004
  return client.makeRequest('query', params);
4996
5005
  }
4997
5006
  // send_tx static function
4998
- async function sendTx(client, params) {
5007
+ async function sendTx$1(client, params) {
4999
5008
  return client.makeRequest('send_tx', params);
5000
5009
  }
5001
5010
  // status static function
5002
- async function status(client, params) {
5011
+ async function status$1(client, params) {
5003
5012
  return client.makeRequest('status', params);
5004
5013
  }
5005
5014
  // tx static function
5006
- async function tx(client, params) {
5015
+ async function tx$1(client, params) {
5007
5016
  return client.makeRequest('tx', params);
5008
5017
  }
5009
5018
  // validators static function
5010
- async function validators(client, params) {
5019
+ async function validators$1(client, params) {
5011
5020
  return client.makeRequest('validators', params);
5012
5021
  }
5013
5022
 
5014
- async function viewAccount(client, params) {
5023
+ async function viewFunction$1(client, params) {
5015
5024
  // Construct query parameters: use blockId if provided, otherwise use finality (default 'final')
5025
+ const baseParams = {
5026
+ requestType: 'call_function',
5027
+ accountId: params.accountId,
5028
+ methodName: params.methodName,
5029
+ argsBase64: params.argsBase64 ?? '', // Default to empty string if no arguments
5030
+ };
5031
+ const queryParams = params.blockId
5032
+ ? { ...baseParams, blockId: params.blockId }
5033
+ : { ...baseParams, finality: params.finality || 'final' };
5034
+ return query$1(client, queryParams);
5035
+ }
5036
+ function parseCallResultToJson(callResult) {
5037
+ const bytes = new Uint8Array(callResult.result);
5038
+ const text = new TextDecoder().decode(bytes);
5039
+ return JSON.parse(text);
5040
+ }
5041
+ async function viewFunctionAsJson(client, params) {
5042
+ const result = await viewFunction$1(client, params);
5043
+ return parseCallResultToJson(result);
5044
+ }
5045
+
5046
+ // Auto-generated validation wrapper functions
5047
+ // Generated at: 2025-07-31T19:21:47.592Z
5048
+ // Total functions: 31
5049
+ //
5050
+ // This file is automatically generated by tools/codegen/generate-validation-wrappers.ts
5051
+ // Do not edit manually - changes will be overwritten
5052
+ // Convenience function wrappers with validation
5053
+ async function viewAccount(client, params) {
5054
+ // Use the validated query function
5016
5055
  const queryParams = params.blockId
5017
5056
  ? {
5018
5057
  requestType: 'view_account',
@@ -5027,12 +5066,12 @@ async function viewAccount(client, params) {
5027
5066
  return query(client, queryParams);
5028
5067
  }
5029
5068
  async function viewFunction(client, params) {
5030
- // Construct query parameters: use blockId if provided, otherwise use finality (default 'final')
5069
+ // Use the validated query function
5031
5070
  const baseParams = {
5032
5071
  requestType: 'call_function',
5033
5072
  accountId: params.accountId,
5034
5073
  methodName: params.methodName,
5035
- argsBase64: params.argsBase64 ?? '', // Default to empty string if no arguments
5074
+ argsBase64: params.argsBase64 ?? '',
5036
5075
  };
5037
5076
  const queryParams = params.blockId
5038
5077
  ? { ...baseParams, blockId: params.blockId }
@@ -5040,7 +5079,7 @@ async function viewFunction(client, params) {
5040
5079
  return query(client, queryParams);
5041
5080
  }
5042
5081
  async function viewAccessKey(client, params) {
5043
- // Construct query parameters: use blockId if provided, otherwise use finality (default 'final')
5082
+ // Use the validated query function
5044
5083
  const queryParams = params.blockId
5045
5084
  ? {
5046
5085
  requestType: 'view_access_key',
@@ -5056,6 +5095,721 @@ async function viewAccessKey(client, params) {
5056
5095
  };
5057
5096
  return query(client, queryParams);
5058
5097
  }
5098
+ // Validation wrapper functions
5099
+ async function experimentalChanges(client, params) {
5100
+ // Validate request parameters
5101
+ const requestSchema = RpcStateChangesInBlockByTypeRequestSchema();
5102
+ if (params !== undefined) {
5103
+ try {
5104
+ requestSchema.parse(params);
5105
+ }
5106
+ catch (error) {
5107
+ throw new Error(`Request validation failed: ${error}`);
5108
+ }
5109
+ }
5110
+ // Call the base function
5111
+ const result = await experimentalChanges$1(client, params);
5112
+ // Validate response
5113
+ const responseSchema = RpcStateChangesInBlockResponseSchema();
5114
+ try {
5115
+ // Wrap in JSON-RPC response format for validation
5116
+ responseSchema.parse(result);
5117
+ }
5118
+ catch (error) {
5119
+ throw new Error(`Response validation failed: ${error}`);
5120
+ }
5121
+ return result;
5122
+ }
5123
+ async function experimentalChangesInBlock(client, params) {
5124
+ // Validate request parameters
5125
+ const requestSchema = RpcStateChangesInBlockRequestSchema();
5126
+ if (params !== undefined) {
5127
+ try {
5128
+ requestSchema.parse(params);
5129
+ }
5130
+ catch (error) {
5131
+ throw new Error(`Request validation failed: ${error}`);
5132
+ }
5133
+ }
5134
+ // Call the base function
5135
+ const result = await experimentalChangesInBlock$1(client, params);
5136
+ // Validate response
5137
+ const responseSchema = RpcStateChangesInBlockByTypeResponseSchema();
5138
+ try {
5139
+ // Wrap in JSON-RPC response format for validation
5140
+ responseSchema.parse(result);
5141
+ }
5142
+ catch (error) {
5143
+ throw new Error(`Response validation failed: ${error}`);
5144
+ }
5145
+ return result;
5146
+ }
5147
+ async function experimentalCongestionLevel(client, params) {
5148
+ // Validate request parameters
5149
+ const requestSchema = RpcCongestionLevelRequestSchema();
5150
+ if (params !== undefined) {
5151
+ try {
5152
+ requestSchema.parse(params);
5153
+ }
5154
+ catch (error) {
5155
+ throw new Error(`Request validation failed: ${error}`);
5156
+ }
5157
+ }
5158
+ // Call the base function
5159
+ const result = await experimentalCongestionLevel$1(client, params);
5160
+ // Validate response
5161
+ const responseSchema = RpcCongestionLevelResponseSchema();
5162
+ try {
5163
+ // Wrap in JSON-RPC response format for validation
5164
+ responseSchema.parse(result);
5165
+ }
5166
+ catch (error) {
5167
+ throw new Error(`Response validation failed: ${error}`);
5168
+ }
5169
+ return result;
5170
+ }
5171
+ async function experimentalGenesisConfig(client, params) {
5172
+ // Validate request parameters
5173
+ const requestSchema = GenesisConfigRequestSchema();
5174
+ if (params !== undefined) {
5175
+ try {
5176
+ requestSchema.parse(params);
5177
+ }
5178
+ catch (error) {
5179
+ throw new Error(`Request validation failed: ${error}`);
5180
+ }
5181
+ }
5182
+ // Call the base function
5183
+ const result = await experimentalGenesisConfig$1(client, params);
5184
+ // Validate response
5185
+ const responseSchema = GenesisConfigSchema();
5186
+ try {
5187
+ // Wrap in JSON-RPC response format for validation
5188
+ responseSchema.parse(result);
5189
+ }
5190
+ catch (error) {
5191
+ throw new Error(`Response validation failed: ${error}`);
5192
+ }
5193
+ return result;
5194
+ }
5195
+ async function experimentalLightClientBlockProof(client, params) {
5196
+ // Validate request parameters
5197
+ const requestSchema = RpcLightClientBlockProofRequestSchema();
5198
+ if (params !== undefined) {
5199
+ try {
5200
+ requestSchema.parse(params);
5201
+ }
5202
+ catch (error) {
5203
+ throw new Error(`Request validation failed: ${error}`);
5204
+ }
5205
+ }
5206
+ // Call the base function
5207
+ const result = await experimentalLightClientBlockProof$1(client, params);
5208
+ // Validate response
5209
+ const responseSchema = RpcLightClientBlockProofResponseSchema();
5210
+ try {
5211
+ // Wrap in JSON-RPC response format for validation
5212
+ responseSchema.parse(result);
5213
+ }
5214
+ catch (error) {
5215
+ throw new Error(`Response validation failed: ${error}`);
5216
+ }
5217
+ return result;
5218
+ }
5219
+ async function experimentalLightClientProof(client, params) {
5220
+ // Validate request parameters
5221
+ const requestSchema = RpcLightClientExecutionProofRequestSchema();
5222
+ if (params !== undefined) {
5223
+ try {
5224
+ requestSchema.parse(params);
5225
+ }
5226
+ catch (error) {
5227
+ throw new Error(`Request validation failed: ${error}`);
5228
+ }
5229
+ }
5230
+ // Call the base function
5231
+ const result = await experimentalLightClientProof$1(client, params);
5232
+ // Validate response
5233
+ const responseSchema = RpcLightClientExecutionProofResponseSchema();
5234
+ try {
5235
+ // Wrap in JSON-RPC response format for validation
5236
+ responseSchema.parse(result);
5237
+ }
5238
+ catch (error) {
5239
+ throw new Error(`Response validation failed: ${error}`);
5240
+ }
5241
+ return result;
5242
+ }
5243
+ async function experimentalMaintenanceWindows(client, params) {
5244
+ // Validate request parameters
5245
+ const requestSchema = RpcMaintenanceWindowsRequestSchema();
5246
+ if (params !== undefined) {
5247
+ try {
5248
+ requestSchema.parse(params);
5249
+ }
5250
+ catch (error) {
5251
+ throw new Error(`Request validation failed: ${error}`);
5252
+ }
5253
+ }
5254
+ // Call the base function (no response validation needed)
5255
+ return experimentalMaintenanceWindows$1(client, params);
5256
+ }
5257
+ async function experimentalProtocolConfig(client, params) {
5258
+ // Validate request parameters
5259
+ const requestSchema = RpcProtocolConfigRequestSchema();
5260
+ if (params !== undefined) {
5261
+ try {
5262
+ requestSchema.parse(params);
5263
+ }
5264
+ catch (error) {
5265
+ throw new Error(`Request validation failed: ${error}`);
5266
+ }
5267
+ }
5268
+ // Call the base function
5269
+ const result = await experimentalProtocolConfig$1(client, params);
5270
+ // Validate response
5271
+ const responseSchema = RpcProtocolConfigResponseSchema();
5272
+ try {
5273
+ // Wrap in JSON-RPC response format for validation
5274
+ responseSchema.parse(result);
5275
+ }
5276
+ catch (error) {
5277
+ throw new Error(`Response validation failed: ${error}`);
5278
+ }
5279
+ return result;
5280
+ }
5281
+ async function experimentalReceipt(client, params) {
5282
+ // Validate request parameters
5283
+ const requestSchema = RpcReceiptRequestSchema();
5284
+ if (params !== undefined) {
5285
+ try {
5286
+ requestSchema.parse(params);
5287
+ }
5288
+ catch (error) {
5289
+ throw new Error(`Request validation failed: ${error}`);
5290
+ }
5291
+ }
5292
+ // Call the base function
5293
+ const result = await experimentalReceipt$1(client, params);
5294
+ // Validate response
5295
+ const responseSchema = RpcReceiptResponseSchema();
5296
+ try {
5297
+ // Wrap in JSON-RPC response format for validation
5298
+ responseSchema.parse(result);
5299
+ }
5300
+ catch (error) {
5301
+ throw new Error(`Response validation failed: ${error}`);
5302
+ }
5303
+ return result;
5304
+ }
5305
+ async function experimentalSplitStorageInfo(client, params) {
5306
+ // Validate request parameters
5307
+ const requestSchema = RpcSplitStorageInfoRequestSchema();
5308
+ if (params !== undefined) {
5309
+ try {
5310
+ requestSchema.parse(params);
5311
+ }
5312
+ catch (error) {
5313
+ throw new Error(`Request validation failed: ${error}`);
5314
+ }
5315
+ }
5316
+ // Call the base function
5317
+ const result = await experimentalSplitStorageInfo$1(client, params);
5318
+ // Validate response
5319
+ const responseSchema = RpcSplitStorageInfoResponseSchema();
5320
+ try {
5321
+ // Wrap in JSON-RPC response format for validation
5322
+ responseSchema.parse(result);
5323
+ }
5324
+ catch (error) {
5325
+ throw new Error(`Response validation failed: ${error}`);
5326
+ }
5327
+ return result;
5328
+ }
5329
+ async function experimentalTxStatus(client, params) {
5330
+ // Validate request parameters
5331
+ const requestSchema = RpcTransactionStatusRequestSchema();
5332
+ if (params !== undefined) {
5333
+ try {
5334
+ requestSchema.parse(params);
5335
+ }
5336
+ catch (error) {
5337
+ throw new Error(`Request validation failed: ${error}`);
5338
+ }
5339
+ }
5340
+ // Call the base function
5341
+ const result = await experimentalTxStatus$1(client, params);
5342
+ // Validate response
5343
+ const responseSchema = RpcTransactionResponseSchema();
5344
+ try {
5345
+ // Wrap in JSON-RPC response format for validation
5346
+ responseSchema.parse(result);
5347
+ }
5348
+ catch (error) {
5349
+ throw new Error(`Response validation failed: ${error}`);
5350
+ }
5351
+ return result;
5352
+ }
5353
+ async function experimentalValidatorsOrdered(client, params) {
5354
+ // Validate request parameters
5355
+ const requestSchema = RpcValidatorsOrderedRequestSchema();
5356
+ if (params !== undefined) {
5357
+ try {
5358
+ requestSchema.parse(params);
5359
+ }
5360
+ catch (error) {
5361
+ throw new Error(`Request validation failed: ${error}`);
5362
+ }
5363
+ }
5364
+ // Call the base function (no response validation needed)
5365
+ return experimentalValidatorsOrdered$1(client, params);
5366
+ }
5367
+ async function block(client, params) {
5368
+ // Validate request parameters
5369
+ const requestSchema = RpcBlockRequestSchema();
5370
+ if (params !== undefined) {
5371
+ try {
5372
+ requestSchema.parse(params);
5373
+ }
5374
+ catch (error) {
5375
+ throw new Error(`Request validation failed: ${error}`);
5376
+ }
5377
+ }
5378
+ // Call the base function
5379
+ const result = await block$1(client, params);
5380
+ // Validate response
5381
+ const responseSchema = RpcBlockResponseSchema();
5382
+ try {
5383
+ // Wrap in JSON-RPC response format for validation
5384
+ responseSchema.parse(result);
5385
+ }
5386
+ catch (error) {
5387
+ throw new Error(`Response validation failed: ${error}`);
5388
+ }
5389
+ return result;
5390
+ }
5391
+ async function blockEffects(client, params) {
5392
+ // Validate request parameters
5393
+ const requestSchema = RpcStateChangesInBlockRequestSchema();
5394
+ if (params !== undefined) {
5395
+ try {
5396
+ requestSchema.parse(params);
5397
+ }
5398
+ catch (error) {
5399
+ throw new Error(`Request validation failed: ${error}`);
5400
+ }
5401
+ }
5402
+ // Call the base function
5403
+ const result = await blockEffects$1(client, params);
5404
+ // Validate response
5405
+ const responseSchema = RpcStateChangesInBlockByTypeResponseSchema();
5406
+ try {
5407
+ // Wrap in JSON-RPC response format for validation
5408
+ responseSchema.parse(result);
5409
+ }
5410
+ catch (error) {
5411
+ throw new Error(`Response validation failed: ${error}`);
5412
+ }
5413
+ return result;
5414
+ }
5415
+ async function broadcastTxAsync(client, params) {
5416
+ // Validate request parameters
5417
+ const requestSchema = RpcSendTransactionRequestSchema();
5418
+ if (params !== undefined) {
5419
+ try {
5420
+ requestSchema.parse(params);
5421
+ }
5422
+ catch (error) {
5423
+ throw new Error(`Request validation failed: ${error}`);
5424
+ }
5425
+ }
5426
+ // Call the base function
5427
+ const result = await broadcastTxAsync$1(client, params);
5428
+ // Validate response
5429
+ const responseSchema = CryptoHashSchema();
5430
+ try {
5431
+ // Wrap in JSON-RPC response format for validation
5432
+ responseSchema.parse(result);
5433
+ }
5434
+ catch (error) {
5435
+ throw new Error(`Response validation failed: ${error}`);
5436
+ }
5437
+ return result;
5438
+ }
5439
+ async function broadcastTxCommit(client, params) {
5440
+ // Validate request parameters
5441
+ const requestSchema = RpcSendTransactionRequestSchema();
5442
+ if (params !== undefined) {
5443
+ try {
5444
+ requestSchema.parse(params);
5445
+ }
5446
+ catch (error) {
5447
+ throw new Error(`Request validation failed: ${error}`);
5448
+ }
5449
+ }
5450
+ // Call the base function
5451
+ const result = await broadcastTxCommit$1(client, params);
5452
+ // Validate response
5453
+ const responseSchema = RpcTransactionResponseSchema();
5454
+ try {
5455
+ // Wrap in JSON-RPC response format for validation
5456
+ responseSchema.parse(result);
5457
+ }
5458
+ catch (error) {
5459
+ throw new Error(`Response validation failed: ${error}`);
5460
+ }
5461
+ return result;
5462
+ }
5463
+ async function changes(client, params) {
5464
+ // Validate request parameters
5465
+ const requestSchema = RpcStateChangesInBlockByTypeRequestSchema();
5466
+ if (params !== undefined) {
5467
+ try {
5468
+ requestSchema.parse(params);
5469
+ }
5470
+ catch (error) {
5471
+ throw new Error(`Request validation failed: ${error}`);
5472
+ }
5473
+ }
5474
+ // Call the base function
5475
+ const result = await changes$1(client, params);
5476
+ // Validate response
5477
+ const responseSchema = RpcStateChangesInBlockResponseSchema();
5478
+ try {
5479
+ // Wrap in JSON-RPC response format for validation
5480
+ responseSchema.parse(result);
5481
+ }
5482
+ catch (error) {
5483
+ throw new Error(`Response validation failed: ${error}`);
5484
+ }
5485
+ return result;
5486
+ }
5487
+ async function chunk(client, params) {
5488
+ // Validate request parameters
5489
+ const requestSchema = RpcChunkRequestSchema();
5490
+ if (params !== undefined) {
5491
+ try {
5492
+ requestSchema.parse(params);
5493
+ }
5494
+ catch (error) {
5495
+ throw new Error(`Request validation failed: ${error}`);
5496
+ }
5497
+ }
5498
+ // Call the base function
5499
+ const result = await chunk$1(client, params);
5500
+ // Validate response
5501
+ const responseSchema = RpcChunkResponseSchema();
5502
+ try {
5503
+ // Wrap in JSON-RPC response format for validation
5504
+ responseSchema.parse(result);
5505
+ }
5506
+ catch (error) {
5507
+ throw new Error(`Response validation failed: ${error}`);
5508
+ }
5509
+ return result;
5510
+ }
5511
+ async function clientConfig(client, params) {
5512
+ // Validate request parameters
5513
+ const requestSchema = RpcClientConfigRequestSchema();
5514
+ if (params !== undefined) {
5515
+ try {
5516
+ requestSchema.parse(params);
5517
+ }
5518
+ catch (error) {
5519
+ throw new Error(`Request validation failed: ${error}`);
5520
+ }
5521
+ }
5522
+ // Call the base function
5523
+ const result = await clientConfig$1(client, params);
5524
+ // Validate response
5525
+ const responseSchema = RpcClientConfigResponseSchema();
5526
+ try {
5527
+ // Wrap in JSON-RPC response format for validation
5528
+ responseSchema.parse(result);
5529
+ }
5530
+ catch (error) {
5531
+ throw new Error(`Response validation failed: ${error}`);
5532
+ }
5533
+ return result;
5534
+ }
5535
+ async function gasPrice(client, params) {
5536
+ // Validate request parameters
5537
+ const requestSchema = RpcGasPriceRequestSchema();
5538
+ if (params !== undefined) {
5539
+ try {
5540
+ requestSchema.parse(params);
5541
+ }
5542
+ catch (error) {
5543
+ throw new Error(`Request validation failed: ${error}`);
5544
+ }
5545
+ }
5546
+ // Call the base function
5547
+ const result = await gasPrice$1(client, params);
5548
+ // Validate response
5549
+ const responseSchema = RpcGasPriceResponseSchema();
5550
+ try {
5551
+ // Wrap in JSON-RPC response format for validation
5552
+ responseSchema.parse(result);
5553
+ }
5554
+ catch (error) {
5555
+ throw new Error(`Response validation failed: ${error}`);
5556
+ }
5557
+ return result;
5558
+ }
5559
+ async function genesisConfig(client, params) {
5560
+ // Validate request parameters
5561
+ const requestSchema = GenesisConfigRequestSchema();
5562
+ if (params !== undefined) {
5563
+ try {
5564
+ requestSchema.parse(params);
5565
+ }
5566
+ catch (error) {
5567
+ throw new Error(`Request validation failed: ${error}`);
5568
+ }
5569
+ }
5570
+ // Call the base function
5571
+ const result = await genesisConfig$1(client, params);
5572
+ // Validate response
5573
+ const responseSchema = GenesisConfigSchema();
5574
+ try {
5575
+ // Wrap in JSON-RPC response format for validation
5576
+ responseSchema.parse(result);
5577
+ }
5578
+ catch (error) {
5579
+ throw new Error(`Response validation failed: ${error}`);
5580
+ }
5581
+ return result;
5582
+ }
5583
+ async function health(client, params) {
5584
+ // Validate request parameters
5585
+ const requestSchema = RpcHealthRequestSchema();
5586
+ if (params !== undefined) {
5587
+ try {
5588
+ requestSchema.parse(params);
5589
+ }
5590
+ catch (error) {
5591
+ throw new Error(`Request validation failed: ${error}`);
5592
+ }
5593
+ }
5594
+ // Call the base function
5595
+ const result = await health$1(client, params);
5596
+ // Validate response
5597
+ const responseSchema = RpcHealthResponseSchema();
5598
+ try {
5599
+ // Wrap in JSON-RPC response format for validation
5600
+ responseSchema.parse(result);
5601
+ }
5602
+ catch (error) {
5603
+ throw new Error(`Response validation failed: ${error}`);
5604
+ }
5605
+ return result;
5606
+ }
5607
+ async function lightClientProof(client, params) {
5608
+ // Validate request parameters
5609
+ const requestSchema = RpcLightClientExecutionProofRequestSchema();
5610
+ if (params !== undefined) {
5611
+ try {
5612
+ requestSchema.parse(params);
5613
+ }
5614
+ catch (error) {
5615
+ throw new Error(`Request validation failed: ${error}`);
5616
+ }
5617
+ }
5618
+ // Call the base function
5619
+ const result = await lightClientProof$1(client, params);
5620
+ // Validate response
5621
+ const responseSchema = RpcLightClientExecutionProofResponseSchema();
5622
+ try {
5623
+ // Wrap in JSON-RPC response format for validation
5624
+ responseSchema.parse(result);
5625
+ }
5626
+ catch (error) {
5627
+ throw new Error(`Response validation failed: ${error}`);
5628
+ }
5629
+ return result;
5630
+ }
5631
+ async function maintenanceWindows(client, params) {
5632
+ // Validate request parameters
5633
+ const requestSchema = RpcMaintenanceWindowsRequestSchema();
5634
+ if (params !== undefined) {
5635
+ try {
5636
+ requestSchema.parse(params);
5637
+ }
5638
+ catch (error) {
5639
+ throw new Error(`Request validation failed: ${error}`);
5640
+ }
5641
+ }
5642
+ // Call the base function (no response validation needed)
5643
+ return maintenanceWindows$1(client, params);
5644
+ }
5645
+ async function networkInfo(client, params) {
5646
+ // Validate request parameters
5647
+ const requestSchema = RpcNetworkInfoRequestSchema();
5648
+ if (params !== undefined) {
5649
+ try {
5650
+ requestSchema.parse(params);
5651
+ }
5652
+ catch (error) {
5653
+ throw new Error(`Request validation failed: ${error}`);
5654
+ }
5655
+ }
5656
+ // Call the base function
5657
+ const result = await networkInfo$1(client, params);
5658
+ // Validate response
5659
+ const responseSchema = RpcNetworkInfoResponseSchema();
5660
+ try {
5661
+ // Wrap in JSON-RPC response format for validation
5662
+ responseSchema.parse(result);
5663
+ }
5664
+ catch (error) {
5665
+ throw new Error(`Response validation failed: ${error}`);
5666
+ }
5667
+ return result;
5668
+ }
5669
+ async function nextLightClientBlock(client, params) {
5670
+ // Validate request parameters
5671
+ const requestSchema = RpcLightClientNextBlockRequestSchema();
5672
+ if (params !== undefined) {
5673
+ try {
5674
+ requestSchema.parse(params);
5675
+ }
5676
+ catch (error) {
5677
+ throw new Error(`Request validation failed: ${error}`);
5678
+ }
5679
+ }
5680
+ // Call the base function
5681
+ const result = await nextLightClientBlock$1(client, params);
5682
+ // Validate response
5683
+ const responseSchema = RpcLightClientNextBlockResponseSchema();
5684
+ try {
5685
+ // Wrap in JSON-RPC response format for validation
5686
+ responseSchema.parse(result);
5687
+ }
5688
+ catch (error) {
5689
+ throw new Error(`Response validation failed: ${error}`);
5690
+ }
5691
+ return result;
5692
+ }
5693
+ async function query(client, params) {
5694
+ // Validate request parameters
5695
+ const requestSchema = RpcQueryRequestSchema();
5696
+ if (params !== undefined) {
5697
+ try {
5698
+ requestSchema.parse(params);
5699
+ }
5700
+ catch (error) {
5701
+ throw new Error(`Request validation failed: ${error}`);
5702
+ }
5703
+ }
5704
+ // Call the base function
5705
+ const result = await query$1(client, params);
5706
+ // Validate response
5707
+ const responseSchema = RpcQueryResponseSchema();
5708
+ try {
5709
+ // Wrap in JSON-RPC response format for validation
5710
+ responseSchema.parse(result);
5711
+ }
5712
+ catch (error) {
5713
+ throw new Error(`Response validation failed: ${error}`);
5714
+ }
5715
+ return result;
5716
+ }
5717
+ async function sendTx(client, params) {
5718
+ // Validate request parameters
5719
+ const requestSchema = RpcSendTransactionRequestSchema();
5720
+ if (params !== undefined) {
5721
+ try {
5722
+ requestSchema.parse(params);
5723
+ }
5724
+ catch (error) {
5725
+ throw new Error(`Request validation failed: ${error}`);
5726
+ }
5727
+ }
5728
+ // Call the base function
5729
+ const result = await sendTx$1(client, params);
5730
+ // Validate response
5731
+ const responseSchema = RpcTransactionResponseSchema();
5732
+ try {
5733
+ // Wrap in JSON-RPC response format for validation
5734
+ responseSchema.parse(result);
5735
+ }
5736
+ catch (error) {
5737
+ throw new Error(`Response validation failed: ${error}`);
5738
+ }
5739
+ return result;
5740
+ }
5741
+ async function status(client, params) {
5742
+ // Validate request parameters
5743
+ const requestSchema = RpcStatusRequestSchema();
5744
+ if (params !== undefined) {
5745
+ try {
5746
+ requestSchema.parse(params);
5747
+ }
5748
+ catch (error) {
5749
+ throw new Error(`Request validation failed: ${error}`);
5750
+ }
5751
+ }
5752
+ // Call the base function
5753
+ const result = await status$1(client, params);
5754
+ // Validate response
5755
+ const responseSchema = RpcStatusResponseSchema();
5756
+ try {
5757
+ // Wrap in JSON-RPC response format for validation
5758
+ responseSchema.parse(result);
5759
+ }
5760
+ catch (error) {
5761
+ throw new Error(`Response validation failed: ${error}`);
5762
+ }
5763
+ return result;
5764
+ }
5765
+ async function tx(client, params) {
5766
+ // Validate request parameters
5767
+ const requestSchema = RpcTransactionStatusRequestSchema();
5768
+ if (params !== undefined) {
5769
+ try {
5770
+ requestSchema.parse(params);
5771
+ }
5772
+ catch (error) {
5773
+ throw new Error(`Request validation failed: ${error}`);
5774
+ }
5775
+ }
5776
+ // Call the base function
5777
+ const result = await tx$1(client, params);
5778
+ // Validate response
5779
+ const responseSchema = RpcTransactionResponseSchema();
5780
+ try {
5781
+ // Wrap in JSON-RPC response format for validation
5782
+ responseSchema.parse(result);
5783
+ }
5784
+ catch (error) {
5785
+ throw new Error(`Response validation failed: ${error}`);
5786
+ }
5787
+ return result;
5788
+ }
5789
+ async function validators(client, params) {
5790
+ // Validate request parameters
5791
+ const requestSchema = RpcValidatorRequestSchema();
5792
+ if (params !== undefined) {
5793
+ try {
5794
+ requestSchema.parse(params);
5795
+ }
5796
+ catch (error) {
5797
+ throw new Error(`Request validation failed: ${error}`);
5798
+ }
5799
+ }
5800
+ // Call the base function
5801
+ const result = await validators$1(client, params);
5802
+ // Validate response
5803
+ const responseSchema = RpcValidatorResponseSchema();
5804
+ try {
5805
+ // Wrap in JSON-RPC response format for validation
5806
+ responseSchema.parse(result);
5807
+ }
5808
+ catch (error) {
5809
+ throw new Error(`Response validation failed: ${error}`);
5810
+ }
5811
+ return result;
5812
+ }
5059
5813
 
5060
5814
  // Optional validation for client - only imported when explicitly enabled
5061
5815
  /**
@@ -5102,6 +5856,14 @@ function enableValidation() {
5102
5856
  try {
5103
5857
  // First validate basic JSON-RPC structure
5104
5858
  responseSchema.parse(response);
5859
+ // Check if the result contains an error field before validating the schema
5860
+ // This provides a better error message when NEAR RPC returns non-standard errors
5861
+ if (response.result &&
5862
+ typeof response.result === 'object' &&
5863
+ 'error' in response.result) {
5864
+ const serverError = response.result.error;
5865
+ throw new JsonRpcClientError(`Server error: ${serverError}`, -32000, response.result);
5866
+ }
5105
5867
  // Then validate method-specific response structure if schema exists
5106
5868
  const methodSchemas = VALIDATION_SCHEMA_MAP[method];
5107
5869
  if (methodSchemas?.responseSchema) {
@@ -5110,10 +5872,15 @@ function enableValidation() {
5110
5872
  }
5111
5873
  }
5112
5874
  catch (error) {
5875
+ // If it's already a JsonRpcClientError (from server error check), re-throw it
5876
+ if (error instanceof JsonRpcClientError) {
5877
+ throw error;
5878
+ }
5879
+ // Otherwise, it's a validation error
5113
5880
  throw new JsonRpcClientError(`Invalid ${method} response: ${error instanceof Error ? error.message : 'Unknown error'}`);
5114
5881
  }
5115
5882
  },
5116
5883
  };
5117
5884
  }
5118
5885
 
5119
- export { JsonRpcClientError, JsonRpcNetworkError, JsonRpcRequestSchema, JsonRpcResponseSchema, NearRpcClient, NearRpcError, RPC_METHODS, block, blockEffects, broadcastTxAsync, broadcastTxCommit, changes, chunk, clientConfig, NearRpcClient as default, defaultClient, enableValidation, experimentalChanges, experimentalChangesInBlock, experimentalCongestionLevel, experimentalGenesisConfig, experimentalLightClientBlockProof, experimentalLightClientProof, experimentalMaintenanceWindows, experimentalProtocolConfig, experimentalReceipt, experimentalSplitStorageInfo, experimentalTxStatus, experimentalValidatorsOrdered, gasPrice, genesisConfig, health, lightClientProof, maintenanceWindows, networkInfo, nextLightClientBlock, query, sendTx, status, tx, validators, viewAccessKey, viewAccount, viewFunction };
5886
+ export { JsonRpcClientError, JsonRpcNetworkError, JsonRpcRequestSchema, JsonRpcResponseSchema, NearRpcClient, NearRpcError, RPC_METHODS, block, blockEffects, broadcastTxAsync, broadcastTxCommit, changes, chunk, clientConfig, NearRpcClient as default, defaultClient, enableValidation, experimentalChanges, experimentalChangesInBlock, experimentalCongestionLevel, experimentalGenesisConfig, experimentalLightClientBlockProof, experimentalLightClientProof, experimentalMaintenanceWindows, experimentalProtocolConfig, experimentalReceipt, experimentalSplitStorageInfo, experimentalTxStatus, experimentalValidatorsOrdered, gasPrice, genesisConfig, health, lightClientProof, maintenanceWindows, networkInfo, nextLightClientBlock, parseCallResultToJson, query, sendTx, status, tx, validators, viewAccessKey, viewAccount, viewFunction, viewFunctionAsJson };