@psalomo/jsonrpc-client 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/README.md +50 -2
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -5,7 +5,7 @@ This package provides a fully-typed, dynamic client for the NEAR Protocol JSON-R
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- pnpm add @near-js/jsonrpc-client
8
+ npm install @near-js/jsonrpc-client
9
9
  ```
10
10
 
11
11
  ## Usage
@@ -74,10 +74,58 @@ const accessKey = await client.viewAccessKey({
74
74
  });
75
75
  ```
76
76
 
77
+ ## Runtime Validation
78
+
79
+ The client supports runtime validation using Zod schemas to ensure both request parameters and server responses conform to the NEAR RPC specification. **We strongly recommend enabling validation** to catch errors early and ensure data integrity.
80
+
81
+ ```typescript
82
+ import { NearRpcClient, status, block, enableValidation } from '@near-js/jsonrpc-client';
83
+
84
+ // Create client with validation enabled (recommended)
85
+ const client = new NearRpcClient({
86
+ endpoint: 'https://rpc.mainnet.near.org',
87
+ validation: enableValidation()
88
+ });
89
+
90
+ // Request parameters are validated before sending
91
+ try {
92
+ await block(client, { blockId: 'invalid' }); // ❌ Throws validation error
93
+ await block(client, { finality: 'final' }); // ✅ Valid parameters
94
+ } catch (error) {
95
+ console.error('Validation error:', error.message);
96
+ // "Invalid block request: Expected finality or block_id"
97
+ }
98
+
99
+ // Server responses are also validated
100
+ const result = await status(client);
101
+ // You can trust that 'result' matches the expected schema
102
+ ```
103
+
104
+ ### Benefits of Validation
105
+
106
+ - **Request Safety**: Catch parameter errors before making network requests
107
+ - **Response Integrity**: Ensure server responses match the expected schema
108
+ - **Better Error Messages**: Get clear, descriptive errors instead of cryptic failures
109
+ - **Development Speed**: Find API usage mistakes immediately during development
110
+ - **Runtime Protection**: Guard against malformed or unexpected server responses
111
+
112
+ ### Disabling Validation
113
+
114
+ For applications where bundle size is critical, validation can be disabled. The validation code is tree-shakable and only included when you import `enableValidation`.
115
+
116
+ ```typescript
117
+ // Client without validation (smaller bundle, but less safe)
118
+ const client = new NearRpcClient({
119
+ endpoint: 'https://rpc.mainnet.near.org'
120
+ // No validation property = no runtime checks
121
+ });
122
+ ```
123
+
77
124
  ## Features
78
125
 
79
126
  - **🔧 Dynamic methods**: All 28+ RPC methods automatically available
80
127
  - **📝 Fully typed**: Complete TypeScript support with proper request/response types
81
128
  - **🔄 Auto-updating**: New API methods appear automatically without code changes
82
- - **✅ Runtime validation**: Built-in parameter validation with helpful error messages
129
+ - **✅ Runtime validation**: Validates both request parameters and server responses
83
130
  - **🎯 Convenience methods**: Simplified methods for common operations like `viewAccount`
131
+ - **🌳 Tree-shakable**: Validation is modular - only included when used
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@psalomo/jsonrpc-client",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "TypeScript client for NEAR Protocol JSON-RPC API",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -30,7 +30,7 @@
30
30
  "test:coverage": "vitest run --coverage"
31
31
  },
32
32
  "dependencies": {
33
- "@psalomo/jsonrpc-types": "^0.1.0"
33
+ "@psalomo/jsonrpc-types": "^1.0.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@rollup/plugin-node-resolve": "^16.0.1",