@zenland/sdk 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zenland
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,246 @@
1
+ # @zenland/sdk
2
+
3
+ Official SDK for interacting with the Zenland escrow protocol indexer.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @zenland/sdk
9
+ # or
10
+ yarn add @zenland/sdk
11
+ # or
12
+ pnpm add @zenland/sdk
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Core SDK (Framework Agnostic)
18
+
19
+ The core SDK works in any JavaScript/TypeScript environment (Node.js, browsers, etc.):
20
+
21
+ ```typescript
22
+ import { createZenlandClient, zenland } from '@zenland/sdk';
23
+
24
+ // Use the default client (production API at https://api.zen.land)
25
+ const escrows = await zenland.escrows.list();
26
+
27
+ // Or create a custom client with a different endpoint
28
+ const client = createZenlandClient({ baseUrl: 'http://localhost:42069' });
29
+
30
+ // Fetch escrows
31
+ const { items, totalCount } = await client.escrows.list({ limit: 10 });
32
+
33
+ // Fetch a specific escrow
34
+ const escrow = await client.escrows.getById('0x...');
35
+
36
+ // Fetch escrows for a user
37
+ const userEscrows = await client.escrows.getByUser('0x...', {
38
+ states: ['ACTIVE', 'PENDING'],
39
+ });
40
+
41
+ // Fetch agents
42
+ const agents = await client.agents.list({ onlyActive: true });
43
+
44
+ // Fetch a specific agent
45
+ const agent = await client.agents.getById('0x...');
46
+
47
+ // Fetch protocol stats
48
+ const stats = await client.protocolStats.get();
49
+
50
+ // Fetch transaction logs for an escrow
51
+ const logs = await client.transactionLogs.getByEscrow('0x...');
52
+ ```
53
+
54
+ ### React Hooks
55
+
56
+ For React applications, use the React integration with built-in caching via React Query:
57
+
58
+ ```tsx
59
+ import { ZenlandProvider, useEscrows, useAgent, useProtocolStats } from '@zenland/sdk/react';
60
+
61
+ // Wrap your app with the provider
62
+ function App() {
63
+ return (
64
+ <ZenlandProvider>
65
+ <MyComponent />
66
+ </ZenlandProvider>
67
+ );
68
+ }
69
+
70
+ // With custom config (e.g., for local development)
71
+ function App() {
72
+ return (
73
+ <ZenlandProvider config={{ baseUrl: 'http://localhost:42069' }}>
74
+ <MyComponent />
75
+ </ZenlandProvider>
76
+ );
77
+ }
78
+
79
+ // Use the hooks in your components
80
+ function MyComponent() {
81
+ // Fetch escrows for a connected user
82
+ const { data: escrows, isLoading } = useEscrows({
83
+ address: '0x...', // User's wallet address
84
+ role: 'buyer', // Filter by role: 'all' | 'buyer' | 'seller' | 'agent'
85
+ stateTab: 'ACTIVE', // Filter by state group
86
+ });
87
+
88
+ // Fetch a single agent
89
+ const { data: agent } = useAgent('0x...');
90
+
91
+ // Fetch protocol stats
92
+ const { data: stats } = useProtocolStats();
93
+
94
+ if (isLoading) return <div>Loading...</div>;
95
+
96
+ return (
97
+ <ul>
98
+ {escrows?.items.map(escrow => (
99
+ <li key={escrow.id}>{escrow.state}</li>
100
+ ))}
101
+ </ul>
102
+ );
103
+ }
104
+ ```
105
+
106
+ ### Peer Dependencies for React
107
+
108
+ When using `@zenland/sdk/react`, you need to have these peer dependencies installed:
109
+
110
+ ```bash
111
+ npm install react @tanstack/react-query
112
+ ```
113
+
114
+ ## API Reference
115
+
116
+ ### Core Client
117
+
118
+ #### `createZenlandClient(config?)`
119
+
120
+ Creates a new Zenland SDK client.
121
+
122
+ ```typescript
123
+ interface ZenlandClientConfig {
124
+ baseUrl?: string; // Default: 'https://api.zen.land'
125
+ }
126
+ ```
127
+
128
+ #### `zenland`
129
+
130
+ A default client instance using the production API.
131
+
132
+ ### Escrows
133
+
134
+ ```typescript
135
+ // List escrows with filters
136
+ client.escrows.list({
137
+ limit?: number,
138
+ offset?: number,
139
+ buyer?: string,
140
+ seller?: string,
141
+ agent?: string,
142
+ user?: string, // Search across all roles
143
+ state?: string,
144
+ states?: string[], // Multiple states
145
+ });
146
+
147
+ // Get a single escrow
148
+ client.escrows.getById(id: string);
149
+
150
+ // Get escrows for a user (all roles)
151
+ client.escrows.getByUser(address: string, options?);
152
+
153
+ // Get escrows by state group
154
+ client.escrows.getByStateGroup('ACTIVE' | 'IN_DISPUTE' | 'COMPLETED', options?);
155
+ ```
156
+
157
+ ### Agents
158
+
159
+ ```typescript
160
+ // List agents
161
+ client.agents.list({
162
+ limit?: number,
163
+ offset?: number,
164
+ onlyActive?: boolean,
165
+ onlyAvailable?: boolean,
166
+ });
167
+
168
+ // Get a single agent
169
+ client.agents.getById(id: string);
170
+
171
+ // Get available agents
172
+ client.agents.getAvailable(options?);
173
+ ```
174
+
175
+ ### Protocol Stats
176
+
177
+ ```typescript
178
+ // Get global protocol statistics
179
+ client.protocolStats.get();
180
+
181
+ // Get raw stats (without BigInt conversion)
182
+ client.protocolStats.getRaw();
183
+ ```
184
+
185
+ ### Transaction Logs
186
+
187
+ ```typescript
188
+ // List transaction logs
189
+ client.transactionLogs.list({
190
+ escrowAddress?: string,
191
+ limit?: number,
192
+ offset?: number,
193
+ });
194
+
195
+ // Get logs for an escrow
196
+ client.transactionLogs.getByEscrow(escrowAddress: string, options?);
197
+
198
+ // Parse event data
199
+ client.transactionLogs.parseEventData(eventData: string);
200
+ ```
201
+
202
+ ## State Groups
203
+
204
+ Escrows can be filtered by state groups:
205
+
206
+ ```typescript
207
+ import { STATE_GROUPS } from '@zenland/sdk';
208
+
209
+ // STATE_GROUPS.ACTIVE = ['PENDING', 'ACTIVE', 'FULFILLED']
210
+ // STATE_GROUPS.IN_DISPUTE = ['DISPUTED', 'AGENT_INVITED']
211
+ // STATE_GROUPS.COMPLETED = ['RELEASED', 'AGENT_RESOLVED', 'REFUNDED', 'SPLIT']
212
+ ```
213
+
214
+ ## Error Handling
215
+
216
+ ```typescript
217
+ import { ZenlandGraphQLError, ZenlandRequestError } from '@zenland/sdk';
218
+
219
+ try {
220
+ const escrow = await client.escrows.getById('0x...');
221
+ } catch (error) {
222
+ if (error instanceof ZenlandGraphQLError) {
223
+ console.error('GraphQL errors:', error.errors);
224
+ } else if (error instanceof ZenlandRequestError) {
225
+ console.error('Request failed:', error.status, error.statusText);
226
+ }
227
+ }
228
+ ```
229
+
230
+ ## TypeScript
231
+
232
+ The SDK is fully typed. You can import types directly:
233
+
234
+ ```typescript
235
+ import type {
236
+ GqlEscrow,
237
+ GqlAgent,
238
+ GqlProtocolStats,
239
+ GqlEscrowPage,
240
+ GqlAgentPage,
241
+ } from '@zenland/sdk';
242
+ ```
243
+
244
+ ## License
245
+
246
+ MIT