@syfthub/sdk 0.1.1 → 0.2.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.
- package/dist/index.cjs +1455 -749
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1288 -440
- package/dist/index.d.ts +1288 -440
- package/dist/index.js +1451 -742
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
- package/README.md +0 -276
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syfthub/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "TypeScript SDK for SyftHub API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -61,15 +61,14 @@
|
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@eslint/js": "^9.39.2",
|
|
63
63
|
"@types/node": "^20.17.10",
|
|
64
|
-
"
|
|
65
|
-
"@typescript-eslint/parser": "^8.18.0",
|
|
66
|
-
"eslint": "^9.16.0",
|
|
64
|
+
"eslint": "^9.39.3",
|
|
67
65
|
"eslint-config-prettier": "^10.0.1",
|
|
68
66
|
"prettier": "^3.4.2",
|
|
69
67
|
"tsup": "^8.3.5",
|
|
70
68
|
"typescript": "^5.7.2",
|
|
71
|
-
"typescript-eslint": "^8.
|
|
72
|
-
"
|
|
73
|
-
"
|
|
69
|
+
"typescript-eslint": "^8.56.1",
|
|
70
|
+
"postcss": ">=8.5.10",
|
|
71
|
+
"vite": "^8.0.16",
|
|
72
|
+
"vitest": "^4.1.0"
|
|
74
73
|
}
|
|
75
74
|
}
|
package/README.md
DELETED
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
# SyftHub TypeScript SDK
|
|
2
|
-
|
|
3
|
-
TypeScript SDK for interacting with the SyftHub API programmatically.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# Using npm
|
|
9
|
-
npm install @syfthub/sdk
|
|
10
|
-
|
|
11
|
-
# Using yarn
|
|
12
|
-
yarn add @syfthub/sdk
|
|
13
|
-
|
|
14
|
-
# Using pnpm
|
|
15
|
-
pnpm add @syfthub/sdk
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Quick Start
|
|
19
|
-
|
|
20
|
-
```typescript
|
|
21
|
-
import { SyftHubClient } from '@syfthub/sdk';
|
|
22
|
-
|
|
23
|
-
// Initialize client
|
|
24
|
-
const client = new SyftHubClient({ baseUrl: 'https://hub.syft.com' });
|
|
25
|
-
|
|
26
|
-
// Register a new user
|
|
27
|
-
const user = await client.auth.register({
|
|
28
|
-
username: 'john',
|
|
29
|
-
email: 'john@example.com',
|
|
30
|
-
password: 'secret123',
|
|
31
|
-
fullName: 'John Doe',
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Login
|
|
35
|
-
const loggedIn = await client.auth.login('john', 'secret123');
|
|
36
|
-
console.log(`Logged in as ${loggedIn.username}`);
|
|
37
|
-
|
|
38
|
-
// Get current user
|
|
39
|
-
const me = await client.auth.me();
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Managing Your Endpoints
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
import { EndpointType, Visibility } from '@syfthub/sdk';
|
|
46
|
-
|
|
47
|
-
// List your endpoints (with lazy pagination)
|
|
48
|
-
for await (const endpoint of client.myEndpoints.list()) {
|
|
49
|
-
console.log(`${endpoint.name} (${endpoint.visibility})`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Get just the first page
|
|
53
|
-
const firstPage = await client.myEndpoints.list().firstPage();
|
|
54
|
-
|
|
55
|
-
// Create an endpoint
|
|
56
|
-
const endpoint = await client.myEndpoints.create({
|
|
57
|
-
name: 'My Cool API',
|
|
58
|
-
type: EndpointType.MODEL,
|
|
59
|
-
visibility: Visibility.PUBLIC,
|
|
60
|
-
description: 'A really cool API',
|
|
61
|
-
readme: '# My API\n\nThis is my API documentation.',
|
|
62
|
-
});
|
|
63
|
-
console.log(`Created: ${endpoint.slug}`);
|
|
64
|
-
|
|
65
|
-
// Update an endpoint
|
|
66
|
-
const updated = await client.myEndpoints.update('john/my-cool-api', {
|
|
67
|
-
description: 'Updated description',
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// Delete an endpoint
|
|
71
|
-
await client.myEndpoints.delete('john/my-cool-api');
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Browsing the Hub
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
// Browse public endpoints
|
|
78
|
-
for await (const endpoint of client.hub.browse()) {
|
|
79
|
-
console.log(`${endpoint.ownerUsername}/${endpoint.slug}: ${endpoint.name}`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Get trending endpoints
|
|
83
|
-
for await (const endpoint of client.hub.trending({ minStars: 10 })) {
|
|
84
|
-
console.log(`${endpoint.name} - ${endpoint.starsCount} stars`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Get a specific endpoint by path
|
|
88
|
-
const endpoint = await client.hub.get('alice/cool-api');
|
|
89
|
-
console.log(endpoint.readme);
|
|
90
|
-
|
|
91
|
-
// Star/unstar endpoints (requires auth)
|
|
92
|
-
await client.hub.star('alice/cool-api');
|
|
93
|
-
await client.hub.unstar('alice/cool-api');
|
|
94
|
-
|
|
95
|
-
// Check if you've starred an endpoint
|
|
96
|
-
if (await client.hub.isStarred('alice/cool-api')) {
|
|
97
|
-
console.log("You've starred this!");
|
|
98
|
-
}
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
## User Profile
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
// Update profile
|
|
105
|
-
const user = await client.users.update({
|
|
106
|
-
fullName: 'John D.',
|
|
107
|
-
avatarUrl: 'https://example.com/avatar.png',
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// Check username availability
|
|
111
|
-
if (await client.users.checkUsername('newusername')) {
|
|
112
|
-
console.log('Username is available!');
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Change password
|
|
116
|
-
await client.auth.changePassword('old123', 'new456');
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
## Accounting
|
|
120
|
-
|
|
121
|
-
```typescript
|
|
122
|
-
// Get account balance
|
|
123
|
-
const balance = await client.accounting.balance();
|
|
124
|
-
console.log(`Credits: ${balance.credits} ${balance.currency}`);
|
|
125
|
-
|
|
126
|
-
// List transactions
|
|
127
|
-
for await (const tx of client.accounting.transactions()) {
|
|
128
|
-
console.log(`${tx.createdAt}: ${tx.amount} - ${tx.description}`);
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## Token Persistence
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
// Get tokens for saving
|
|
136
|
-
const tokens = client.getTokens();
|
|
137
|
-
if (tokens) {
|
|
138
|
-
// Save to localStorage, database, etc.
|
|
139
|
-
localStorage.setItem('syfthub_tokens', JSON.stringify(tokens));
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Later, restore session
|
|
143
|
-
const saved = localStorage.getItem('syfthub_tokens');
|
|
144
|
-
if (saved) {
|
|
145
|
-
const tokens = JSON.parse(saved);
|
|
146
|
-
client.setTokens(tokens);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Check if authenticated
|
|
150
|
-
if (client.isAuthenticated) {
|
|
151
|
-
console.log('Session restored!');
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
## Environment Variables
|
|
156
|
-
|
|
157
|
-
| Variable | Description |
|
|
158
|
-
|----------|-------------|
|
|
159
|
-
| `SYFTHUB_URL` | SyftHub API base URL |
|
|
160
|
-
|
|
161
|
-
## Error Handling
|
|
162
|
-
|
|
163
|
-
```typescript
|
|
164
|
-
import {
|
|
165
|
-
SyftHubError,
|
|
166
|
-
AuthenticationError,
|
|
167
|
-
AuthorizationError,
|
|
168
|
-
NotFoundError,
|
|
169
|
-
ValidationError,
|
|
170
|
-
NetworkError,
|
|
171
|
-
} from '@syfthub/sdk';
|
|
172
|
-
|
|
173
|
-
try {
|
|
174
|
-
await client.auth.login('john', 'wrong');
|
|
175
|
-
} catch (error) {
|
|
176
|
-
if (error instanceof AuthenticationError) {
|
|
177
|
-
console.log(`Login failed: ${error.message}`);
|
|
178
|
-
} else if (error instanceof NotFoundError) {
|
|
179
|
-
console.log('User not found');
|
|
180
|
-
} else if (error instanceof ValidationError) {
|
|
181
|
-
console.log(`Validation error: ${error.message}`);
|
|
182
|
-
console.log('Field errors:', error.errors);
|
|
183
|
-
} else if (error instanceof NetworkError) {
|
|
184
|
-
console.log(`Network error: ${error.message}`);
|
|
185
|
-
} else if (error instanceof SyftHubError) {
|
|
186
|
-
console.log(`API error: ${error.message}`);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
## Pagination
|
|
192
|
-
|
|
193
|
-
All list methods return a `PageIterator` for lazy async pagination:
|
|
194
|
-
|
|
195
|
-
```typescript
|
|
196
|
-
// Iterate through all items (fetches pages as needed)
|
|
197
|
-
for await (const endpoint of client.myEndpoints.list()) {
|
|
198
|
-
console.log(endpoint.name);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Get just the first page
|
|
202
|
-
const firstPage = await client.myEndpoints.list().firstPage();
|
|
203
|
-
|
|
204
|
-
// Get all items as an array (loads all into memory)
|
|
205
|
-
const allItems = await client.myEndpoints.list().all();
|
|
206
|
-
|
|
207
|
-
// Get first N items
|
|
208
|
-
const top10 = await client.myEndpoints.list().take(10);
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
## TypeScript Support
|
|
212
|
-
|
|
213
|
-
This SDK is written in TypeScript and provides full type safety:
|
|
214
|
-
|
|
215
|
-
```typescript
|
|
216
|
-
import {
|
|
217
|
-
// Client
|
|
218
|
-
SyftHubClient,
|
|
219
|
-
SyftHubClientOptions,
|
|
220
|
-
|
|
221
|
-
// Enums
|
|
222
|
-
Visibility,
|
|
223
|
-
EndpointType,
|
|
224
|
-
UserRole,
|
|
225
|
-
|
|
226
|
-
// Types
|
|
227
|
-
User,
|
|
228
|
-
Endpoint,
|
|
229
|
-
EndpointPublic,
|
|
230
|
-
Policy,
|
|
231
|
-
Connection,
|
|
232
|
-
AuthTokens,
|
|
233
|
-
|
|
234
|
-
// Input types
|
|
235
|
-
UserRegisterInput,
|
|
236
|
-
EndpointCreateInput,
|
|
237
|
-
EndpointUpdateInput,
|
|
238
|
-
|
|
239
|
-
// Errors
|
|
240
|
-
SyftHubError,
|
|
241
|
-
AuthenticationError,
|
|
242
|
-
ValidationError,
|
|
243
|
-
|
|
244
|
-
// Utilities
|
|
245
|
-
PageIterator,
|
|
246
|
-
getEndpointPublicPath,
|
|
247
|
-
} from '@syfthub/sdk';
|
|
248
|
-
|
|
249
|
-
// All types are properly inferred
|
|
250
|
-
const endpoint: Endpoint = await client.myEndpoints.create({
|
|
251
|
-
name: 'My API',
|
|
252
|
-
type: EndpointType.MODEL,
|
|
253
|
-
});
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
## Comparison with Python SDK
|
|
257
|
-
|
|
258
|
-
| Python | TypeScript |
|
|
259
|
-
|--------|------------|
|
|
260
|
-
| `client.auth.login(username, password)` | `client.auth.login(username, password)` |
|
|
261
|
-
| `client.my_endpoints.list()` | `client.myEndpoints.list()` |
|
|
262
|
-
| `for ep in client.hub.browse()` | `for await (const ep of client.hub.browse())` |
|
|
263
|
-
| `client.get_tokens()` | `client.getTokens()` |
|
|
264
|
-
| `client.set_tokens(tokens)` | `client.setTokens(tokens)` |
|
|
265
|
-
| `client.is_authenticated` | `client.isAuthenticated` |
|
|
266
|
-
|
|
267
|
-
The TypeScript SDK follows JavaScript/TypeScript conventions (camelCase) while providing the same functionality as the Python SDK.
|
|
268
|
-
|
|
269
|
-
## Requirements
|
|
270
|
-
|
|
271
|
-
- Node.js 18+ (for native `fetch` support)
|
|
272
|
-
- Or any modern browser
|
|
273
|
-
|
|
274
|
-
## License
|
|
275
|
-
|
|
276
|
-
MIT
|