@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/dist/index.d.mts CHANGED
@@ -1,5 +1,61 @@
1
- export { JsonRpcErrorSchema, JsonRpcRequestSchema, JsonRpcResponseSchema, RPC_METHODS } from '@near-js/jsonrpc-types';
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';
2
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];
3
59
  interface ClientConfig {
4
60
  endpoint: string;
5
61
  headers?: Record<string, string>;
@@ -33,186 +89,25 @@ declare class JsonRpcNetworkError extends Error {
33
89
  originalError: Error;
34
90
  constructor(message: string, originalError: Error);
35
91
  }
92
+
36
93
  declare class NearRpcClient {
37
94
  private endpoint;
38
95
  private headers;
39
96
  private timeout;
40
97
  private retries;
41
98
  private validateResponses;
42
- private requestIdCounter;
43
99
  constructor(config: string | ClientConfig);
44
100
  /**
45
- * Generate a unique request ID
101
+ * Get request ID matching NEAR RPC documentation examples
46
102
  */
47
- private generateRequestId;
103
+ private getRequestId;
48
104
  /**
49
105
  * Make a raw JSON-RPC call
106
+ * This method is public to allow dynamic calls to any RPC method
50
107
  */
51
- private call;
52
- /**
53
- * Get node status
54
- */
55
- status(): Promise<any>;
56
- /**
57
- * Get block information
58
- */
59
- block(params?: {
60
- blockId?: string | number;
61
- finality?: 'final' | 'near-final' | 'optimistic';
62
- }): Promise<any>;
63
- /**
64
- * Get current gas price
65
- */
66
- gasPrice(params?: {
67
- blockId?: string | number;
68
- }): Promise<any>;
69
- /**
70
- * Get chunk information
71
- */
72
- chunk(params: {
73
- chunkId: string;
74
- } | {
75
- blockId: string | number;
76
- shardId: number;
77
- }): Promise<any>;
78
- /**
79
- * Health check
80
- */
81
- health(): Promise<any>;
82
- /**
83
- * Get network information
84
- */
85
- networkInfo(): Promise<any>;
86
- /**
87
- * Get current validators
88
- */
89
- validators(params?: {
90
- blockId?: string | number;
91
- }): Promise<any>;
92
- /**
93
- * Get client configuration
94
- */
95
- clientConfig(): Promise<any>;
96
- /**
97
- * Broadcast transaction asynchronously
98
- */
99
- broadcastTxAsync(params: {
100
- signedTxBase64: string;
101
- }): Promise<any>;
102
- /**
103
- * Broadcast transaction and wait for commit
104
- */
105
- broadcastTxCommit(params: {
106
- signedTxBase64: string;
107
- }): Promise<any>;
108
- /**
109
- * Send transaction
110
- */
111
- sendTx(params: {
112
- signedTxBase64: string;
113
- }): Promise<any>;
114
- /**
115
- * Get transaction status
116
- */
117
- tx(params: {
118
- txHash: string;
119
- senderAccountId: string;
120
- }): Promise<any>;
121
- /**
122
- * Query account/contract state
123
- */
124
- query(params: {
125
- requestType: string;
126
- finality?: 'final' | 'near-final' | 'optimistic';
127
- blockId?: string | number;
128
- accountId?: string;
129
- methodName?: string;
130
- argsBase64?: string;
131
- publicKey?: string;
132
- keyType?: string;
133
- }): Promise<any>;
134
- /**
135
- * View account information (convenience method)
136
- */
137
- viewAccount(params: {
138
- accountId: string;
139
- finality?: 'final' | 'near-final' | 'optimistic';
140
- blockId?: string | number;
141
- }): Promise<any>;
142
- /**
143
- * View function call (convenience method)
144
- */
145
- viewFunction(params: {
146
- accountId: string;
147
- methodName: string;
148
- argsBase64?: string;
149
- finality?: 'final' | 'near-final' | 'optimistic';
150
- blockId?: string | number;
151
- }): Promise<any>;
152
- /**
153
- * View access key (convenience method)
154
- */
155
- viewAccessKey(params: {
156
- accountId: string;
157
- publicKey: string;
158
- finality?: 'final' | 'near-final' | 'optimistic';
159
- blockId?: string | number;
160
- }): Promise<any>;
161
- /**
162
- * Get light client proof
163
- */
164
- lightClientProof(params: {
165
- type: string;
166
- lightClientHead: string;
167
- transactionHash?: string;
168
- senderId?: string;
169
- receiptId?: string;
170
- }): Promise<any>;
171
- /**
172
- * Get state changes (experimental)
173
- */
174
- experimentalChanges(params: {
175
- changesType: string;
176
- accountIds?: string[];
177
- keyPrefixBase64?: string;
178
- blockId?: string | number;
179
- }): Promise<any>;
180
- /**
181
- * Get state changes in block (experimental)
182
- */
183
- experimentalChangesInBlock(params: {
184
- blockId: string | number;
185
- }): Promise<any>;
186
- /**
187
- * Get ordered validators (experimental)
188
- */
189
- experimentalValidatorsOrdered(params?: {
190
- blockId?: string | number;
191
- }): Promise<any>;
192
- /**
193
- * Get protocol configuration (experimental)
194
- */
195
- experimentalProtocolConfig(params?: {
196
- blockId?: string | number;
197
- finality?: 'final' | 'near-final' | 'optimistic';
198
- }): Promise<any>;
199
- /**
200
- * Get genesis configuration (experimental)
201
- */
202
- experimentalGenesisConfig(): Promise<any>;
203
- /**
204
- * Get receipt information (experimental)
205
- */
206
- experimentalReceipt(params: {
207
- receiptId: string;
208
- }): Promise<any>;
209
- /**
210
- * Get transaction status (experimental)
211
- */
212
- experimentalTxStatus(params: {
213
- txHash: string;
214
- senderAccountId: string;
215
- }): Promise<any>;
108
+ call<TParams = unknown, TResult = unknown>(method: RpcMethod, params?: TParams): Promise<TResult>;
109
+ }
110
+ interface NearRpcClient extends DynamicRpcMethods, ConvenienceMethods {
216
111
  }
217
112
 
218
113
  interface RpcRequest {
@@ -238,4 +133,4 @@ declare class NearRpcError extends Error {
238
133
  constructor(code: number, message: string, data?: unknown | undefined);
239
134
  }
240
135
 
241
- export { type ClientConfig, JsonRpcClientError, type JsonRpcError, JsonRpcNetworkError, type JsonRpcRequest, type JsonRpcResponse, NearRpcClient, NearRpcError, type RpcError, type RpcRequest, type RpcResponse, NearRpcClient as default };
136
+ 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 };
package/dist/index.d.ts CHANGED
@@ -1,241 +1,7 @@
1
- export { JsonRpcErrorSchema, JsonRpcRequestSchema, JsonRpcResponseSchema, RPC_METHODS } from '@near-js/jsonrpc-types';
2
-
3
- interface ClientConfig {
4
- endpoint: string;
5
- headers?: Record<string, string>;
6
- timeout?: number;
7
- retries?: number;
8
- validateResponses?: boolean;
9
- }
10
- interface JsonRpcRequest<T = unknown> {
11
- jsonrpc: '2.0';
12
- id: string;
13
- method: string;
14
- params?: T;
15
- }
16
- interface JsonRpcResponse<T = unknown> {
17
- jsonrpc: '2.0';
18
- id: string;
19
- result?: T;
20
- error?: JsonRpcError;
21
- }
22
- interface JsonRpcError {
23
- code: number;
24
- message: string;
25
- data?: unknown;
26
- }
27
- declare class JsonRpcClientError extends Error {
28
- code?: number | undefined;
29
- data?: unknown | undefined;
30
- constructor(message: string, code?: number | undefined, data?: unknown | undefined);
31
- }
32
- declare class JsonRpcNetworkError extends Error {
33
- originalError: Error;
34
- constructor(message: string, originalError: Error);
35
- }
36
- declare class NearRpcClient {
37
- private endpoint;
38
- private headers;
39
- private timeout;
40
- private retries;
41
- private validateResponses;
42
- private requestIdCounter;
43
- constructor(config: string | ClientConfig);
44
- /**
45
- * Generate a unique request ID
46
- */
47
- private generateRequestId;
48
- /**
49
- * Make a raw JSON-RPC call
50
- */
51
- private call;
52
- /**
53
- * Get node status
54
- */
55
- status(): Promise<any>;
56
- /**
57
- * Get block information
58
- */
59
- block(params?: {
60
- blockId?: string | number;
61
- finality?: 'final' | 'near-final' | 'optimistic';
62
- }): Promise<any>;
63
- /**
64
- * Get current gas price
65
- */
66
- gasPrice(params?: {
67
- blockId?: string | number;
68
- }): Promise<any>;
69
- /**
70
- * Get chunk information
71
- */
72
- chunk(params: {
73
- chunkId: string;
74
- } | {
75
- blockId: string | number;
76
- shardId: number;
77
- }): Promise<any>;
78
- /**
79
- * Health check
80
- */
81
- health(): Promise<any>;
82
- /**
83
- * Get network information
84
- */
85
- networkInfo(): Promise<any>;
86
- /**
87
- * Get current validators
88
- */
89
- validators(params?: {
90
- blockId?: string | number;
91
- }): Promise<any>;
92
- /**
93
- * Get client configuration
94
- */
95
- clientConfig(): Promise<any>;
96
- /**
97
- * Broadcast transaction asynchronously
98
- */
99
- broadcastTxAsync(params: {
100
- signedTxBase64: string;
101
- }): Promise<any>;
102
- /**
103
- * Broadcast transaction and wait for commit
104
- */
105
- broadcastTxCommit(params: {
106
- signedTxBase64: string;
107
- }): Promise<any>;
108
- /**
109
- * Send transaction
110
- */
111
- sendTx(params: {
112
- signedTxBase64: string;
113
- }): Promise<any>;
114
- /**
115
- * Get transaction status
116
- */
117
- tx(params: {
118
- txHash: string;
119
- senderAccountId: string;
120
- }): Promise<any>;
121
- /**
122
- * Query account/contract state
123
- */
124
- query(params: {
125
- requestType: string;
126
- finality?: 'final' | 'near-final' | 'optimistic';
127
- blockId?: string | number;
128
- accountId?: string;
129
- methodName?: string;
130
- argsBase64?: string;
131
- publicKey?: string;
132
- keyType?: string;
133
- }): Promise<any>;
134
- /**
135
- * View account information (convenience method)
136
- */
137
- viewAccount(params: {
138
- accountId: string;
139
- finality?: 'final' | 'near-final' | 'optimistic';
140
- blockId?: string | number;
141
- }): Promise<any>;
142
- /**
143
- * View function call (convenience method)
144
- */
145
- viewFunction(params: {
146
- accountId: string;
147
- methodName: string;
148
- argsBase64?: string;
149
- finality?: 'final' | 'near-final' | 'optimistic';
150
- blockId?: string | number;
151
- }): Promise<any>;
152
- /**
153
- * View access key (convenience method)
154
- */
155
- viewAccessKey(params: {
156
- accountId: string;
157
- publicKey: string;
158
- finality?: 'final' | 'near-final' | 'optimistic';
159
- blockId?: string | number;
160
- }): Promise<any>;
161
- /**
162
- * Get light client proof
163
- */
164
- lightClientProof(params: {
165
- type: string;
166
- lightClientHead: string;
167
- transactionHash?: string;
168
- senderId?: string;
169
- receiptId?: string;
170
- }): Promise<any>;
171
- /**
172
- * Get state changes (experimental)
173
- */
174
- experimentalChanges(params: {
175
- changesType: string;
176
- accountIds?: string[];
177
- keyPrefixBase64?: string;
178
- blockId?: string | number;
179
- }): Promise<any>;
180
- /**
181
- * Get state changes in block (experimental)
182
- */
183
- experimentalChangesInBlock(params: {
184
- blockId: string | number;
185
- }): Promise<any>;
186
- /**
187
- * Get ordered validators (experimental)
188
- */
189
- experimentalValidatorsOrdered(params?: {
190
- blockId?: string | number;
191
- }): Promise<any>;
192
- /**
193
- * Get protocol configuration (experimental)
194
- */
195
- experimentalProtocolConfig(params?: {
196
- blockId?: string | number;
197
- finality?: 'final' | 'near-final' | 'optimistic';
198
- }): Promise<any>;
199
- /**
200
- * Get genesis configuration (experimental)
201
- */
202
- experimentalGenesisConfig(): Promise<any>;
203
- /**
204
- * Get receipt information (experimental)
205
- */
206
- experimentalReceipt(params: {
207
- receiptId: string;
208
- }): Promise<any>;
209
- /**
210
- * Get transaction status (experimental)
211
- */
212
- experimentalTxStatus(params: {
213
- txHash: string;
214
- senderAccountId: string;
215
- }): Promise<any>;
216
- }
217
-
218
- interface RpcRequest {
219
- jsonrpc: '2.0';
220
- id: string | number;
221
- method: string;
222
- params: unknown;
223
- }
224
- interface RpcResponse<T = unknown> {
225
- jsonrpc: '2.0';
226
- id: string | number;
227
- result?: T;
228
- error?: RpcError;
229
- }
230
- interface RpcError {
231
- code: number;
232
- message: string;
233
- data?: unknown;
234
- }
235
- declare class NearRpcError extends Error {
236
- code: number;
237
- data?: unknown | undefined;
238
- constructor(code: number, message: string, data?: unknown | undefined);
239
- }
240
-
241
- export { type ClientConfig, 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"}