@psalomo/jsonrpc-client 0.3.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/README.md +47 -7
- package/dist/__tests__/test-utils.d.ts +5 -0
- package/dist/__tests__/test-utils.d.ts.map +1 -0
- package/dist/browser-standalone-mini.js +1245 -0
- package/dist/browser-standalone-mini.min.js +1 -0
- package/dist/browser-standalone.js +5751 -13538
- package/dist/browser-standalone.min.js +1 -0
- package/dist/client.d.ts +57 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.mini.d.ts +58 -0
- package/dist/client.mini.d.ts.map +1 -0
- package/dist/convenience.mini.d.ts +21 -0
- package/dist/convenience.mini.d.ts.map +1 -0
- package/dist/generated-functions.mini.d.ts +3 -0
- package/dist/generated-functions.mini.d.ts.map +1 -0
- package/dist/generated-types.d.ts +55 -0
- package/dist/generated-types.d.ts.map +1 -0
- package/dist/generated-types.mini.d.ts +84 -0
- package/dist/generated-types.mini.d.ts.map +1 -0
- package/dist/index.d.mts +65 -170
- package/dist/index.d.ts +7 -241
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -161
- package/dist/index.mini.cjs +421 -0
- package/dist/index.mini.d.mts +198 -0
- package/dist/index.mini.d.ts +10 -0
- package/dist/index.mini.d.ts.map +1 -0
- package/dist/index.mini.mjs +361 -0
- package/dist/index.mjs +44 -161
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/validation.mini.d.ts +12 -0
- package/dist/validation.mini.d.ts.map +1 -0
- package/package.json +16 -6
package/dist/index.js
CHANGED
@@ -22,9 +22,11 @@ var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
23
23
|
JsonRpcClientError: () => JsonRpcClientError,
|
24
24
|
JsonRpcNetworkError: () => JsonRpcNetworkError,
|
25
|
+
JsonRpcRequestSchema: () => import_jsonrpc_types2.JsonRpcRequestSchema,
|
26
|
+
JsonRpcResponseSchema: () => import_jsonrpc_types2.JsonRpcResponseSchema,
|
25
27
|
NearRpcClient: () => NearRpcClient,
|
26
28
|
NearRpcError: () => NearRpcError,
|
27
|
-
RPC_METHODS: () =>
|
29
|
+
RPC_METHODS: () => import_jsonrpc_types3.RPC_METHODS,
|
28
30
|
default: () => NearRpcClient
|
29
31
|
});
|
30
32
|
module.exports = __toCommonJS(index_exports);
|
@@ -86,7 +88,6 @@ var NearRpcClient = class {
|
|
86
88
|
timeout;
|
87
89
|
retries;
|
88
90
|
validateResponses;
|
89
|
-
requestIdCounter = 0;
|
90
91
|
constructor(config) {
|
91
92
|
if (typeof config === "string") {
|
92
93
|
this.endpoint = config;
|
@@ -108,16 +109,17 @@ var NearRpcClient = class {
|
|
108
109
|
}
|
109
110
|
}
|
110
111
|
/**
|
111
|
-
*
|
112
|
+
* Get request ID matching NEAR RPC documentation examples
|
112
113
|
*/
|
113
|
-
|
114
|
-
return
|
114
|
+
getRequestId() {
|
115
|
+
return "dontcare";
|
115
116
|
}
|
116
117
|
/**
|
117
118
|
* Make a raw JSON-RPC call
|
119
|
+
* This method is public to allow dynamic calls to any RPC method
|
118
120
|
*/
|
119
121
|
async call(method, params) {
|
120
|
-
const requestId = this.
|
122
|
+
const requestId = this.getRequestId();
|
121
123
|
const snakeCaseParams = params ? convertKeysToSnakeCase(params) : void 0;
|
122
124
|
const request = {
|
123
125
|
jsonrpc: "2.0",
|
@@ -187,162 +189,38 @@ var NearRpcClient = class {
|
|
187
189
|
lastError
|
188
190
|
);
|
189
191
|
}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
*/
|
201
|
-
async block(params) {
|
202
|
-
return this.call("block", params);
|
203
|
-
}
|
204
|
-
/**
|
205
|
-
* Get current gas price
|
206
|
-
*/
|
207
|
-
async gasPrice(params) {
|
208
|
-
return this.call("gas_price", params);
|
209
|
-
}
|
210
|
-
/**
|
211
|
-
* Get chunk information
|
212
|
-
*/
|
213
|
-
async chunk(params) {
|
214
|
-
return this.call("chunk", params);
|
215
|
-
}
|
216
|
-
/**
|
217
|
-
* Health check
|
218
|
-
*/
|
219
|
-
async health() {
|
220
|
-
return this.call("health");
|
221
|
-
}
|
222
|
-
/**
|
223
|
-
* Get network information
|
224
|
-
*/
|
225
|
-
async networkInfo() {
|
226
|
-
return this.call("network_info");
|
227
|
-
}
|
228
|
-
/**
|
229
|
-
* Get current validators
|
230
|
-
*/
|
231
|
-
async validators(params) {
|
232
|
-
return this.call("validators", params);
|
233
|
-
}
|
234
|
-
/**
|
235
|
-
* Get client configuration
|
236
|
-
*/
|
237
|
-
async clientConfig() {
|
238
|
-
return this.call("client_config");
|
239
|
-
}
|
240
|
-
/**
|
241
|
-
* Broadcast transaction asynchronously
|
242
|
-
*/
|
243
|
-
async broadcastTxAsync(params) {
|
244
|
-
return this.call("broadcast_tx_async", params);
|
245
|
-
}
|
246
|
-
/**
|
247
|
-
* Broadcast transaction and wait for commit
|
248
|
-
*/
|
249
|
-
async broadcastTxCommit(params) {
|
250
|
-
return this.call("broadcast_tx_commit", params);
|
251
|
-
}
|
252
|
-
/**
|
253
|
-
* Send transaction
|
254
|
-
*/
|
255
|
-
async sendTx(params) {
|
256
|
-
return await this.call("send_tx", params);
|
257
|
-
}
|
258
|
-
/**
|
259
|
-
* Get transaction status
|
260
|
-
*/
|
261
|
-
async tx(params) {
|
262
|
-
return this.call("tx", params);
|
263
|
-
}
|
264
|
-
/**
|
265
|
-
* Query account/contract state
|
266
|
-
*/
|
267
|
-
async query(params) {
|
268
|
-
return this.call("query", params);
|
269
|
-
}
|
270
|
-
/**
|
271
|
-
* View account information (convenience method)
|
272
|
-
*/
|
273
|
-
async viewAccount(params) {
|
274
|
-
return this.query({
|
275
|
-
requestType: "view_account",
|
276
|
-
...params
|
277
|
-
});
|
278
|
-
}
|
279
|
-
/**
|
280
|
-
* View function call (convenience method)
|
281
|
-
*/
|
282
|
-
async viewFunction(params) {
|
283
|
-
return this.query({
|
284
|
-
requestType: "call_function",
|
285
|
-
...params
|
286
|
-
});
|
287
|
-
}
|
288
|
-
/**
|
289
|
-
* View access key (convenience method)
|
290
|
-
*/
|
291
|
-
async viewAccessKey(params) {
|
292
|
-
return this.query({
|
293
|
-
requestType: "view_access_key",
|
294
|
-
...params
|
295
|
-
});
|
296
|
-
}
|
297
|
-
/**
|
298
|
-
* Get light client proof
|
299
|
-
*/
|
300
|
-
async lightClientProof(params) {
|
301
|
-
return this.call("light_client_proof", params);
|
302
|
-
}
|
303
|
-
// Experimental methods
|
304
|
-
/**
|
305
|
-
* Get state changes (experimental)
|
306
|
-
*/
|
307
|
-
async experimentalChanges(params) {
|
308
|
-
return this.call("EXPERIMENTAL_changes", params);
|
309
|
-
}
|
310
|
-
/**
|
311
|
-
* Get state changes in block (experimental)
|
312
|
-
*/
|
313
|
-
async experimentalChangesInBlock(params) {
|
314
|
-
return this.call("EXPERIMENTAL_changes_in_block", params);
|
315
|
-
}
|
316
|
-
/**
|
317
|
-
* Get ordered validators (experimental)
|
318
|
-
*/
|
319
|
-
async experimentalValidatorsOrdered(params) {
|
320
|
-
return this.call("EXPERIMENTAL_validators_ordered", params);
|
321
|
-
}
|
322
|
-
/**
|
323
|
-
* Get protocol configuration (experimental)
|
324
|
-
*/
|
325
|
-
async experimentalProtocolConfig(params) {
|
326
|
-
return this.call("EXPERIMENTAL_protocol_config", params);
|
327
|
-
}
|
328
|
-
/**
|
329
|
-
* Get genesis configuration (experimental)
|
330
|
-
*/
|
331
|
-
async experimentalGenesisConfig() {
|
332
|
-
return this.call("EXPERIMENTAL_genesis_config");
|
333
|
-
}
|
334
|
-
/**
|
335
|
-
* Get receipt information (experimental)
|
336
|
-
*/
|
337
|
-
async experimentalReceipt(params) {
|
338
|
-
return this.call("EXPERIMENTAL_receipt", params);
|
339
|
-
}
|
340
|
-
/**
|
341
|
-
* Get transaction status (experimental)
|
342
|
-
*/
|
343
|
-
async experimentalTxStatus(params) {
|
344
|
-
return this.call("EXPERIMENTAL_tx_status", params);
|
192
|
+
};
|
193
|
+
import_jsonrpc_types.RPC_METHODS.forEach((method) => {
|
194
|
+
let methodName = method;
|
195
|
+
if (methodName.startsWith("EXPERIMENTAL_")) {
|
196
|
+
methodName = "experimental" + methodName.substring(13).replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^([a-z])/, (_, letter) => letter.toUpperCase());
|
197
|
+
} else {
|
198
|
+
methodName = methodName.replace(
|
199
|
+
/_([a-z])/g,
|
200
|
+
(_, letter) => letter.toUpperCase()
|
201
|
+
);
|
345
202
|
}
|
203
|
+
NearRpcClient.prototype[methodName] = function(params) {
|
204
|
+
return this.call(method, params);
|
205
|
+
};
|
206
|
+
});
|
207
|
+
NearRpcClient.prototype.viewAccount = function(params) {
|
208
|
+
return this.query({
|
209
|
+
requestType: "view_account",
|
210
|
+
...params
|
211
|
+
});
|
212
|
+
};
|
213
|
+
NearRpcClient.prototype.viewFunction = function(params) {
|
214
|
+
return this.query({
|
215
|
+
requestType: "call_function",
|
216
|
+
...params
|
217
|
+
});
|
218
|
+
};
|
219
|
+
NearRpcClient.prototype.viewAccessKey = function(params) {
|
220
|
+
return this.query({
|
221
|
+
requestType: "view_access_key",
|
222
|
+
...params
|
223
|
+
});
|
346
224
|
};
|
347
225
|
|
348
226
|
// src/types.ts
|
@@ -357,10 +235,13 @@ var NearRpcError = class extends Error {
|
|
357
235
|
|
358
236
|
// src/index.ts
|
359
237
|
var import_jsonrpc_types2 = require("@psalomo/jsonrpc-types");
|
238
|
+
var import_jsonrpc_types3 = require("@psalomo/jsonrpc-types");
|
360
239
|
// Annotate the CommonJS export names for ESM import in node:
|
361
240
|
0 && (module.exports = {
|
362
241
|
JsonRpcClientError,
|
363
242
|
JsonRpcNetworkError,
|
243
|
+
JsonRpcRequestSchema,
|
244
|
+
JsonRpcResponseSchema,
|
364
245
|
NearRpcClient,
|
365
246
|
NearRpcError,
|
366
247
|
RPC_METHODS
|
@@ -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
|
+
});
|