@psalomo/jsonrpc-client 0.4.0 → 0.5.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/index.d.ts CHANGED
@@ -1,137 +1,7 @@
1
- import { RpcStateChangesInBlockByTypeRequest, RpcStateChangesInBlockResponse, RpcStateChangesInBlockRequest, RpcStateChangesInBlockByTypeResponse, RpcCongestionLevelRequest, RpcCongestionLevelResponse, GenesisConfigRequest, GenesisConfig, RpcLightClientBlockProofRequest, RpcLightClientBlockProofResponse, RpcLightClientExecutionProofRequest, RpcLightClientExecutionProofResponse, RpcMaintenanceWindowsRequest, EXPERIMENTALMaintenanceWindowsResponse, RpcProtocolConfigRequest, RpcProtocolConfigResponse, RpcReceiptRequest, RpcReceiptResponse, RpcSplitStorageInfoRequest, RpcSplitStorageInfoResponse, RpcTransactionStatusRequest, RpcTransactionResponse, RpcValidatorsOrderedRequest, EXPERIMENTALValidatorsOrderedResponse, RpcBlockRequest, RpcBlockResponse, RpcSendTransactionRequest, CryptoHash, RpcChunkRequest, RpcChunkResponse, RpcClientConfigRequest, RpcClientConfigResponse, RpcGasPriceRequest, RpcGasPriceResponse, RpcHealthRequest, RpcHealthResponse, RpcNetworkInfoRequest, RpcNetworkInfoResponse, RpcLightClientNextBlockRequest, RpcLightClientNextBlockResponse, RpcQueryRequest, RpcQueryResponse, RpcStatusRequest, RpcStatusResponse, RpcValidatorRequest, RpcValidatorResponse, AccountView, CallResult, AccessKeyView, RPC_METHODS } from '@near-js/jsonrpc-types';
2
- export { JsonRpcRequestSchema, JsonRpcResponseSchema, RPC_METHODS } from '@near-js/jsonrpc-types';
3
-
4
- interface DynamicRpcMethods {
5
- experimentalChanges(params?: RpcStateChangesInBlockByTypeRequest): Promise<RpcStateChangesInBlockResponse>;
6
- experimentalChangesInBlock(params?: RpcStateChangesInBlockRequest): Promise<RpcStateChangesInBlockByTypeResponse>;
7
- experimentalCongestionLevel(params?: RpcCongestionLevelRequest): Promise<RpcCongestionLevelResponse>;
8
- experimentalGenesisConfig(params?: GenesisConfigRequest): Promise<GenesisConfig>;
9
- experimentalLightClientBlockProof(params?: RpcLightClientBlockProofRequest): Promise<RpcLightClientBlockProofResponse>;
10
- experimentalLightClientProof(params?: RpcLightClientExecutionProofRequest): Promise<RpcLightClientExecutionProofResponse>;
11
- experimentalMaintenanceWindows(params?: RpcMaintenanceWindowsRequest): Promise<EXPERIMENTALMaintenanceWindowsResponse>;
12
- experimentalProtocolConfig(params?: RpcProtocolConfigRequest): Promise<RpcProtocolConfigResponse>;
13
- experimentalReceipt(params?: RpcReceiptRequest): Promise<RpcReceiptResponse>;
14
- experimentalSplitStorageInfo(params?: RpcSplitStorageInfoRequest): Promise<RpcSplitStorageInfoResponse>;
15
- experimentalTxStatus(params?: RpcTransactionStatusRequest): Promise<RpcTransactionResponse>;
16
- experimentalValidatorsOrdered(params?: RpcValidatorsOrderedRequest): Promise<EXPERIMENTALValidatorsOrderedResponse>;
17
- block(params?: RpcBlockRequest): Promise<RpcBlockResponse>;
18
- broadcastTxAsync(params?: RpcSendTransactionRequest): Promise<CryptoHash>;
19
- broadcastTxCommit(params?: RpcSendTransactionRequest): Promise<RpcTransactionResponse>;
20
- changes(params?: RpcStateChangesInBlockByTypeRequest): Promise<RpcStateChangesInBlockResponse>;
21
- chunk(params?: RpcChunkRequest): Promise<RpcChunkResponse>;
22
- clientConfig(params?: RpcClientConfigRequest): Promise<RpcClientConfigResponse>;
23
- gasPrice(params?: RpcGasPriceRequest): Promise<RpcGasPriceResponse>;
24
- health(params?: RpcHealthRequest): Promise<RpcHealthResponse>;
25
- lightClientProof(params?: RpcLightClientExecutionProofRequest): Promise<RpcLightClientExecutionProofResponse>;
26
- networkInfo(params?: RpcNetworkInfoRequest): Promise<RpcNetworkInfoResponse>;
27
- nextLightClientBlock(params?: RpcLightClientNextBlockRequest): Promise<RpcLightClientNextBlockResponse>;
28
- query(params?: RpcQueryRequest): Promise<RpcQueryResponse>;
29
- sendTx(params?: RpcSendTransactionRequest): Promise<RpcTransactionResponse>;
30
- status(params?: RpcStatusRequest): Promise<RpcStatusResponse>;
31
- tx(params?: RpcTransactionStatusRequest): Promise<RpcTransactionResponse>;
32
- validators(params?: RpcValidatorRequest): Promise<RpcValidatorResponse>;
33
- }
34
- interface ConvenienceMethods {
35
- viewAccount(params: {
36
- accountId: string;
37
- finality?: 'final' | 'near-final' | 'optimistic';
38
- blockId?: string | number;
39
- }): Promise<AccountView>;
40
- viewFunction(params: {
41
- accountId: string;
42
- methodName: string;
43
- argsBase64?: string;
44
- finality?: 'final' | 'near-final' | 'optimistic';
45
- blockId?: string | number;
46
- }): Promise<CallResult>;
47
- viewAccessKey(params: {
48
- accountId: string;
49
- publicKey: string;
50
- finality?: 'final' | 'near-final' | 'optimistic';
51
- blockId?: string | number;
52
- }): Promise<AccessKeyView>;
53
- }
54
- interface CompleteClientInterface extends DynamicRpcMethods, ConvenienceMethods {
55
- call<TParams = unknown, TResult = unknown>(method: string, params?: TParams): Promise<TResult>;
56
- }
57
-
58
- type RpcMethod = (typeof RPC_METHODS)[number];
59
- interface ClientConfig {
60
- endpoint: string;
61
- headers?: Record<string, string>;
62
- timeout?: number;
63
- retries?: number;
64
- validateResponses?: boolean;
65
- }
66
- interface JsonRpcRequest<T = unknown> {
67
- jsonrpc: '2.0';
68
- id: string;
69
- method: string;
70
- params?: T;
71
- }
72
- interface JsonRpcResponse<T = unknown> {
73
- jsonrpc: '2.0';
74
- id: string;
75
- result?: T;
76
- error?: JsonRpcError;
77
- }
78
- interface JsonRpcError {
79
- code: number;
80
- message: string;
81
- data?: unknown;
82
- }
83
- declare class JsonRpcClientError extends Error {
84
- code?: number | undefined;
85
- data?: unknown | undefined;
86
- constructor(message: string, code?: number | undefined, data?: unknown | undefined);
87
- }
88
- declare class JsonRpcNetworkError extends Error {
89
- originalError: Error;
90
- constructor(message: string, originalError: Error);
91
- }
92
-
93
- declare class NearRpcClient {
94
- private endpoint;
95
- private headers;
96
- private timeout;
97
- private retries;
98
- private validateResponses;
99
- private requestIdCounter;
100
- constructor(config: string | ClientConfig);
101
- /**
102
- * Generate a unique request ID
103
- */
104
- private generateRequestId;
105
- /**
106
- * Make a raw JSON-RPC call
107
- * This method is public to allow dynamic calls to any RPC method
108
- */
109
- call<TParams = unknown, TResult = unknown>(method: RpcMethod, params?: TParams): Promise<TResult>;
110
- }
111
- interface NearRpcClient extends DynamicRpcMethods, ConvenienceMethods {
112
- }
113
-
114
- interface RpcRequest {
115
- jsonrpc: '2.0';
116
- id: string | number;
117
- method: string;
118
- params: unknown;
119
- }
120
- interface RpcResponse<T = unknown> {
121
- jsonrpc: '2.0';
122
- id: string | number;
123
- result?: T;
124
- error?: RpcError;
125
- }
126
- interface RpcError {
127
- code: number;
128
- message: string;
129
- data?: unknown;
130
- }
131
- declare class NearRpcError extends Error {
132
- code: number;
133
- data?: unknown | undefined;
134
- constructor(code: number, message: string, data?: unknown | undefined);
135
- }
136
-
137
- export { type ClientConfig, type CompleteClientInterface, type ConvenienceMethods, type DynamicRpcMethods, JsonRpcClientError, type JsonRpcError, JsonRpcNetworkError, type JsonRpcRequest, type JsonRpcResponse, NearRpcClient, NearRpcError, type RpcError, type RpcRequest, type RpcResponse, NearRpcClient as default };
1
+ export * from './client';
2
+ export * from './types';
3
+ export * from './generated-types';
4
+ export { JsonRpcRequestSchema, JsonRpcResponseSchema, } from '@near-js/jsonrpc-types';
5
+ export { RPC_METHODS } from '@near-js/jsonrpc-types';
6
+ export { NearRpcClient as default } from './client';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAGlC,OAAO,EACL,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,OAAO,EAAE,aAAa,IAAI,OAAO,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -88,7 +88,6 @@ var NearRpcClient = class {
88
88
  timeout;
89
89
  retries;
90
90
  validateResponses;
91
- requestIdCounter = 0;
92
91
  constructor(config) {
93
92
  if (typeof config === "string") {
94
93
  this.endpoint = config;
@@ -110,17 +109,17 @@ var NearRpcClient = class {
110
109
  }
111
110
  }
112
111
  /**
113
- * Generate a unique request ID
112
+ * Get request ID matching NEAR RPC documentation examples
114
113
  */
115
- generateRequestId() {
116
- return `near-rpc-${Date.now()}-${++this.requestIdCounter}`;
114
+ getRequestId() {
115
+ return "dontcare";
117
116
  }
118
117
  /**
119
118
  * Make a raw JSON-RPC call
120
119
  * This method is public to allow dynamic calls to any RPC method
121
120
  */
122
121
  async call(method, params) {
123
- const requestId = this.generateRequestId();
122
+ const requestId = this.getRequestId();
124
123
  const snakeCaseParams = params ? convertKeysToSnakeCase(params) : void 0;
125
124
  const request = {
126
125
  jsonrpc: "2.0",
@@ -0,0 +1,421 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.mini.ts
21
+ var index_mini_exports = {};
22
+ __export(index_mini_exports, {
23
+ JsonRpcClientError: () => JsonRpcClientError,
24
+ JsonRpcNetworkError: () => JsonRpcNetworkError,
25
+ JsonRpcRequestSchema: () => import_mini2.JsonRpcRequestSchema,
26
+ JsonRpcResponseSchema: () => import_mini2.JsonRpcResponseSchema,
27
+ NearRpcClient: () => NearRpcClient,
28
+ NearRpcError: () => NearRpcError,
29
+ RPC_METHODS: () => import_mini3.RPC_METHODS,
30
+ block: () => block,
31
+ broadcastTxAsync: () => broadcastTxAsync,
32
+ broadcastTxCommit: () => broadcastTxCommit,
33
+ changes: () => changes,
34
+ chunk: () => chunk,
35
+ clientConfig: () => clientConfig,
36
+ default: () => NearRpcClient,
37
+ defaultClient: () => defaultClient,
38
+ enableValidation: () => enableValidation,
39
+ experimentalChanges: () => experimentalChanges,
40
+ experimentalChangesInBlock: () => experimentalChangesInBlock,
41
+ experimentalCongestionLevel: () => experimentalCongestionLevel,
42
+ experimentalGenesisConfig: () => experimentalGenesisConfig,
43
+ experimentalLightClientBlockProof: () => experimentalLightClientBlockProof,
44
+ experimentalLightClientProof: () => experimentalLightClientProof,
45
+ experimentalMaintenanceWindows: () => experimentalMaintenanceWindows,
46
+ experimentalProtocolConfig: () => experimentalProtocolConfig,
47
+ experimentalReceipt: () => experimentalReceipt,
48
+ experimentalSplitStorageInfo: () => experimentalSplitStorageInfo,
49
+ experimentalTxStatus: () => experimentalTxStatus,
50
+ experimentalValidatorsOrdered: () => experimentalValidatorsOrdered,
51
+ gasPrice: () => gasPrice,
52
+ health: () => health,
53
+ lightClientProof: () => lightClientProof,
54
+ networkInfo: () => networkInfo,
55
+ nextLightClientBlock: () => nextLightClientBlock,
56
+ query: () => query,
57
+ sendTx: () => sendTx,
58
+ status: () => status,
59
+ tx: () => tx,
60
+ validators: () => validators,
61
+ viewAccessKey: () => viewAccessKey,
62
+ viewAccount: () => viewAccount,
63
+ viewFunction: () => viewFunction
64
+ });
65
+ module.exports = __toCommonJS(index_mini_exports);
66
+
67
+ // src/client.mini.ts
68
+ function camelToSnake(str) {
69
+ return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
70
+ }
71
+ function snakeToCamel(str) {
72
+ return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
73
+ }
74
+ function convertKeysToSnakeCase(obj) {
75
+ if (obj === null || typeof obj !== "object") {
76
+ return obj;
77
+ }
78
+ if (Array.isArray(obj)) {
79
+ return obj.map(convertKeysToSnakeCase);
80
+ }
81
+ const converted = {};
82
+ for (const [key, value] of Object.entries(obj)) {
83
+ const snakeKey = camelToSnake(key);
84
+ converted[snakeKey] = convertKeysToSnakeCase(value);
85
+ }
86
+ return converted;
87
+ }
88
+ function convertKeysToCamelCase(obj) {
89
+ if (obj === null || typeof obj !== "object") {
90
+ return obj;
91
+ }
92
+ if (Array.isArray(obj)) {
93
+ return obj.map(convertKeysToCamelCase);
94
+ }
95
+ const converted = {};
96
+ for (const [key, value] of Object.entries(obj)) {
97
+ const camelKey = snakeToCamel(key);
98
+ converted[camelKey] = convertKeysToCamelCase(value);
99
+ }
100
+ return converted;
101
+ }
102
+ var REQUEST_ID = "dontcare";
103
+ var JsonRpcClientError = class extends Error {
104
+ constructor(message, code, data) {
105
+ super(message);
106
+ this.code = code;
107
+ this.data = data;
108
+ this.name = "JsonRpcClientError";
109
+ }
110
+ };
111
+ var JsonRpcNetworkError = class extends Error {
112
+ constructor(message, cause) {
113
+ super(message);
114
+ this.cause = cause;
115
+ this.name = "JsonRpcNetworkError";
116
+ }
117
+ };
118
+ var NearRpcClient = class _NearRpcClient {
119
+ endpoint;
120
+ headers;
121
+ timeout;
122
+ retries;
123
+ validation;
124
+ constructor(config) {
125
+ this.endpoint = config.endpoint;
126
+ this.headers = config.headers || {};
127
+ this.timeout = config.timeout || 3e4;
128
+ this.retries = config.retries || 3;
129
+ if (config.validation) {
130
+ this.validation = config.validation;
131
+ }
132
+ }
133
+ /**
134
+ * Make a raw JSON-RPC request
135
+ * This is used internally by the standalone RPC functions
136
+ */
137
+ async makeRequest(method, params) {
138
+ const snakeCaseParams = params ? convertKeysToSnakeCase(params) : params;
139
+ const request = {
140
+ jsonrpc: "2.0",
141
+ id: REQUEST_ID,
142
+ method,
143
+ params: snakeCaseParams
144
+ };
145
+ if (this.validation) {
146
+ this.validation.validateRequest(request);
147
+ }
148
+ let lastError = null;
149
+ for (let attempt = 0; attempt <= this.retries; attempt++) {
150
+ try {
151
+ const controller = new AbortController();
152
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
153
+ const response = await fetch(this.endpoint, {
154
+ method: "POST",
155
+ headers: {
156
+ "Content-Type": "application/json",
157
+ ...this.headers
158
+ },
159
+ body: JSON.stringify(request),
160
+ signal: controller.signal
161
+ });
162
+ clearTimeout(timeoutId);
163
+ if (!response.ok) {
164
+ throw new JsonRpcNetworkError(
165
+ `HTTP error! status: ${response.status}`
166
+ );
167
+ }
168
+ const jsonResponse = await response.json();
169
+ if (this.validation) {
170
+ this.validation.validateResponse(jsonResponse);
171
+ }
172
+ if (jsonResponse.error) {
173
+ throw new JsonRpcClientError(
174
+ jsonResponse.error.message,
175
+ jsonResponse.error.code,
176
+ jsonResponse.error.data
177
+ );
178
+ }
179
+ const camelCaseResult = jsonResponse.result ? convertKeysToCamelCase(jsonResponse.result) : jsonResponse.result;
180
+ return camelCaseResult;
181
+ } catch (error) {
182
+ lastError = error;
183
+ if (error instanceof JsonRpcClientError) {
184
+ throw error;
185
+ }
186
+ if (attempt === this.retries) {
187
+ break;
188
+ }
189
+ await new Promise(
190
+ (resolve) => setTimeout(resolve, Math.pow(2, attempt) * 1e3)
191
+ );
192
+ }
193
+ }
194
+ throw lastError || new JsonRpcNetworkError("Request failed after all retries");
195
+ }
196
+ /**
197
+ * Create a new client with modified configuration
198
+ */
199
+ withConfig(config) {
200
+ return new _NearRpcClient({
201
+ endpoint: config.endpoint ?? this.endpoint,
202
+ headers: config.headers ?? this.headers,
203
+ timeout: config.timeout ?? this.timeout,
204
+ retries: config.retries ?? this.retries,
205
+ ...config.validation !== void 0 ? { validation: config.validation } : this.validation !== void 0 ? { validation: this.validation } : {}
206
+ });
207
+ }
208
+ };
209
+ var defaultClient = new NearRpcClient({
210
+ endpoint: "https://rpc.mainnet.near.org"
211
+ });
212
+
213
+ // src/types.ts
214
+ var NearRpcError = class extends Error {
215
+ constructor(code, message, data) {
216
+ super(message);
217
+ this.code = code;
218
+ this.data = data;
219
+ this.name = "NearRpcError";
220
+ }
221
+ };
222
+
223
+ // src/index.mini.ts
224
+ var import_mini2 = require("@near-js/jsonrpc-types/mini");
225
+ var import_mini3 = require("@near-js/jsonrpc-types/mini");
226
+
227
+ // src/generated-types.mini.ts
228
+ async function experimentalChanges(client, params) {
229
+ return client.makeRequest("EXPERIMENTAL_changes", params);
230
+ }
231
+ async function experimentalChangesInBlock(client, params) {
232
+ return client.makeRequest("EXPERIMENTAL_changes_in_block", params);
233
+ }
234
+ async function experimentalCongestionLevel(client, params) {
235
+ return client.makeRequest("EXPERIMENTAL_congestion_level", params);
236
+ }
237
+ async function experimentalGenesisConfig(client, params) {
238
+ return client.makeRequest("EXPERIMENTAL_genesis_config", params);
239
+ }
240
+ async function experimentalLightClientBlockProof(client, params) {
241
+ return client.makeRequest("EXPERIMENTAL_light_client_block_proof", params);
242
+ }
243
+ async function experimentalLightClientProof(client, params) {
244
+ return client.makeRequest("EXPERIMENTAL_light_client_proof", params);
245
+ }
246
+ async function experimentalMaintenanceWindows(client, params) {
247
+ return client.makeRequest("EXPERIMENTAL_maintenance_windows", params);
248
+ }
249
+ async function experimentalProtocolConfig(client, params) {
250
+ return client.makeRequest("EXPERIMENTAL_protocol_config", params);
251
+ }
252
+ async function experimentalReceipt(client, params) {
253
+ return client.makeRequest("EXPERIMENTAL_receipt", params);
254
+ }
255
+ async function experimentalSplitStorageInfo(client, params) {
256
+ return client.makeRequest("EXPERIMENTAL_split_storage_info", params);
257
+ }
258
+ async function experimentalTxStatus(client, params) {
259
+ return client.makeRequest("EXPERIMENTAL_tx_status", params);
260
+ }
261
+ async function experimentalValidatorsOrdered(client, params) {
262
+ return client.makeRequest("EXPERIMENTAL_validators_ordered", params);
263
+ }
264
+ async function block(client, params) {
265
+ return client.makeRequest("block", params);
266
+ }
267
+ async function broadcastTxAsync(client, params) {
268
+ return client.makeRequest("broadcast_tx_async", params);
269
+ }
270
+ async function broadcastTxCommit(client, params) {
271
+ return client.makeRequest("broadcast_tx_commit", params);
272
+ }
273
+ async function changes(client, params) {
274
+ return client.makeRequest("changes", params);
275
+ }
276
+ async function chunk(client, params) {
277
+ return client.makeRequest("chunk", params);
278
+ }
279
+ async function clientConfig(client, params) {
280
+ return client.makeRequest("client_config", params);
281
+ }
282
+ async function gasPrice(client, params) {
283
+ return client.makeRequest("gas_price", params);
284
+ }
285
+ async function health(client, params) {
286
+ return client.makeRequest("health", params);
287
+ }
288
+ async function lightClientProof(client, params) {
289
+ return client.makeRequest("light_client_proof", params);
290
+ }
291
+ async function networkInfo(client, params) {
292
+ return client.makeRequest("network_info", params);
293
+ }
294
+ async function nextLightClientBlock(client, params) {
295
+ return client.makeRequest("next_light_client_block", params);
296
+ }
297
+ async function query(client, params) {
298
+ return client.makeRequest("query", params);
299
+ }
300
+ async function sendTx(client, params) {
301
+ return client.makeRequest("send_tx", params);
302
+ }
303
+ async function status(client, params) {
304
+ return client.makeRequest("status", params);
305
+ }
306
+ async function tx(client, params) {
307
+ return client.makeRequest("tx", params);
308
+ }
309
+ async function validators(client, params) {
310
+ return client.makeRequest("validators", params);
311
+ }
312
+
313
+ // src/convenience.mini.ts
314
+ async function viewAccount(client, params) {
315
+ const queryParams = params.blockId ? {
316
+ requestType: "view_account",
317
+ accountId: params.accountId,
318
+ blockId: params.blockId
319
+ } : {
320
+ requestType: "view_account",
321
+ accountId: params.accountId,
322
+ finality: params.finality || "final"
323
+ };
324
+ return query(client, queryParams);
325
+ }
326
+ async function viewFunction(client, params) {
327
+ const baseParams = {
328
+ requestType: "call_function",
329
+ accountId: params.accountId,
330
+ methodName: params.methodName,
331
+ argsBase64: params.argsBase64 ?? ""
332
+ // Default to empty string if no arguments
333
+ };
334
+ const queryParams = params.blockId ? { ...baseParams, blockId: params.blockId } : { ...baseParams, finality: params.finality || "final" };
335
+ return query(client, queryParams);
336
+ }
337
+ async function viewAccessKey(client, params) {
338
+ const queryParams = params.blockId ? {
339
+ requestType: "view_access_key",
340
+ accountId: params.accountId,
341
+ publicKey: params.publicKey,
342
+ blockId: params.blockId
343
+ } : {
344
+ requestType: "view_access_key",
345
+ accountId: params.accountId,
346
+ publicKey: params.publicKey,
347
+ finality: params.finality || "final"
348
+ };
349
+ return query(client, queryParams);
350
+ }
351
+
352
+ // src/validation.mini.ts
353
+ var import_mini = require("@near-js/jsonrpc-types/mini");
354
+ function enableValidation() {
355
+ const requestSchema = (0, import_mini.JsonRpcRequestSchema)();
356
+ const responseSchema = (0, import_mini.JsonRpcResponseSchema)();
357
+ return {
358
+ validateRequest: (request) => {
359
+ try {
360
+ requestSchema.parse(request);
361
+ } catch (error) {
362
+ throw new JsonRpcNetworkError(
363
+ `Invalid request format: ${error instanceof Error ? error.message : "Unknown error"}`,
364
+ error
365
+ );
366
+ }
367
+ },
368
+ validateResponse: (response) => {
369
+ try {
370
+ responseSchema.parse(response);
371
+ } catch (error) {
372
+ throw new JsonRpcClientError(
373
+ `Invalid response format: ${error instanceof Error ? error.message : "Unknown error"}`
374
+ );
375
+ }
376
+ }
377
+ };
378
+ }
379
+ // Annotate the CommonJS export names for ESM import in node:
380
+ 0 && (module.exports = {
381
+ JsonRpcClientError,
382
+ JsonRpcNetworkError,
383
+ JsonRpcRequestSchema,
384
+ JsonRpcResponseSchema,
385
+ NearRpcClient,
386
+ NearRpcError,
387
+ RPC_METHODS,
388
+ block,
389
+ broadcastTxAsync,
390
+ broadcastTxCommit,
391
+ changes,
392
+ chunk,
393
+ clientConfig,
394
+ defaultClient,
395
+ enableValidation,
396
+ experimentalChanges,
397
+ experimentalChangesInBlock,
398
+ experimentalCongestionLevel,
399
+ experimentalGenesisConfig,
400
+ experimentalLightClientBlockProof,
401
+ experimentalLightClientProof,
402
+ experimentalMaintenanceWindows,
403
+ experimentalProtocolConfig,
404
+ experimentalReceipt,
405
+ experimentalSplitStorageInfo,
406
+ experimentalTxStatus,
407
+ experimentalValidatorsOrdered,
408
+ gasPrice,
409
+ health,
410
+ lightClientProof,
411
+ networkInfo,
412
+ nextLightClientBlock,
413
+ query,
414
+ sendTx,
415
+ status,
416
+ tx,
417
+ validators,
418
+ viewAccessKey,
419
+ viewAccount,
420
+ viewFunction
421
+ });