@eveai/eve-sdk-for-node 0.0.2 → 0.0.3
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.bak +510 -0
- package/README.md.orig +510 -0
- package/dist/client.js +1 -1
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +1 -1
- package/dist/client.mjs.map +1 -1
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -1
- package/dist/services/eveai-chat.d.mts +118 -0
- package/dist/services/eveai-chat.d.ts +118 -0
- package/dist/services/eveai-chat.js +115 -0
- package/dist/services/eveai-chat.js.map +1 -0
- package/dist/services/eveai-chat.mjs +114 -0
- package/dist/services/eveai-chat.mjs.map +1 -0
- package/dist/services/eveai-payment.d.mts +145 -0
- package/dist/services/eveai-payment.d.ts +145 -0
- package/dist/services/eveai-payment.js +132 -0
- package/dist/services/eveai-payment.js.map +1 -0
- package/dist/services/eveai-payment.mjs +131 -0
- package/dist/services/eveai-payment.mjs.map +1 -0
- package/dist/services/eveai-provider-discovery.d.mts +126 -0
- package/dist/services/eveai-provider-discovery.d.ts +126 -0
- package/dist/services/eveai-provider-discovery.js +96 -0
- package/dist/services/eveai-provider-discovery.js.map +1 -0
- package/dist/services/eveai-provider-discovery.mjs +95 -0
- package/dist/services/eveai-provider-discovery.mjs.map +1 -0
- package/dist/services/eveai-task.d.mts +137 -0
- package/dist/services/eveai-task.d.ts +137 -0
- package/dist/services/eveai-task.js +143 -0
- package/dist/services/eveai-task.js.map +1 -0
- package/dist/services/eveai-task.mjs +142 -0
- package/dist/services/eveai-task.mjs.map +1 -0
- package/package.json +16 -2
package/README.md.orig
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
# Eve.AI Node.js SDK
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
**Official Node.js SDK for Eve.AI - Artificial General Intelligence Platform**
|
|
7
|
+
|
|
8
|
+
> This is the Node.js SDK for integrating with Eve.AI backend from your Node.js server-side code.
|
|
9
|
+
|
|
10
|
+
Eve.AI is an Artificial General Intelligence Platform backend developed in Go, Python, JavaScript, and other languages. This SDK provides a simple and intuitive interface to interact with all Eve.AI backend APIs including authentication, user management, video feed, publishing, comments, favorites, relations, and messaging.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- 🔐 **Authentication** - User login and registration
|
|
15
|
+
- 👤 **User Management** - Get user information, update profiles (avatar, background, signature)
|
|
16
|
+
- 📹 **Video Feed** - Browse recommended videos, get video by ID
|
|
17
|
+
- 📤 **Publishing** - Upload and publish videos, delete videos
|
|
18
|
+
- 💬 **Comments** - Add, delete, list, and count comments
|
|
19
|
+
- ❤️ **Favorites** - Like/unlike videos and manage favorites
|
|
20
|
+
- 👥 **Relations** - Follow/unfollow users, get followers and friends
|
|
21
|
+
- 💌 **Messaging** - Send and receive direct messages
|
|
22
|
+
- 📁 **File Storage** - Upload images directly for avatars and backgrounds
|
|
23
|
+
- 🎯 **TypeScript Support** - Full TypeScript definitions included
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
To install via [NPM](https://www.npmjs.com/):
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @eveai/eve-sdk-for-node --save
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or with Yarn:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
yarn add @eveai/eve-sdk-for-node
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Getting Started
|
|
40
|
+
|
|
41
|
+
### Initialize the SDK
|
|
42
|
+
|
|
43
|
+
<<<<<<< HEAD
|
|
44
|
+
Initialize your SDK with your GuGoTik backend endpoint (default: `https://api.eve.ai/v1`):
|
|
45
|
+
=======
|
|
46
|
+
Initialize your SDK with your Eve.AI backend endpoint (default: `http://api.eve.ai`):
|
|
47
|
+
>>>>>>> 836ad7e6f9efd8ec1892686c48347c8a25fcf8f4
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
const { Client, Auth } = require('@eveai/eve-sdk-for-node');
|
|
51
|
+
|
|
52
|
+
const client = new Client();
|
|
53
|
+
|
|
54
|
+
client
|
|
55
|
+
<<<<<<< HEAD
|
|
56
|
+
.setEndpoint('https://api.eve.ai/v1') // Your GuGoTik backend endpoint
|
|
57
|
+
=======
|
|
58
|
+
.setEndpoint('https://api.eve.ai') // Your Eve.AI backend endpoint
|
|
59
|
+
>>>>>>> 836ad7e6f9efd8ec1892686c48347c8a25fcf8f4
|
|
60
|
+
.setSelfSigned(true); // Use only in dev mode with self-signed SSL cert
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Authentication
|
|
64
|
+
|
|
65
|
+
#### Register a New User
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
const { Client, Auth } = require('@eveai/eve-sdk-for-node');
|
|
69
|
+
|
|
70
|
+
const client = new Client()
|
|
71
|
+
<<<<<<< HEAD
|
|
72
|
+
.setEndpoint('https://api.eve.ai/v1');
|
|
73
|
+
=======
|
|
74
|
+
.setEndpoint('https://api.eve.ai');
|
|
75
|
+
>>>>>>> 836ad7e6f9efd8ec1892686c48347c8a25fcf8f4
|
|
76
|
+
|
|
77
|
+
const auth = new Auth(client);
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const response = await auth.register('username', 'password');
|
|
81
|
+
console.log('User registered:', response);
|
|
82
|
+
// Response: { status_code: 0, status_msg: 'success', user_id: 123, token: 'xxx' }
|
|
83
|
+
|
|
84
|
+
// Set token for authenticated requests
|
|
85
|
+
client.setToken(response.token);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error('Registration failed:', error);
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### Login
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
const { Client, Auth } = require('@eveai/eve-sdk-for-node');
|
|
95
|
+
|
|
96
|
+
const client = new Client()
|
|
97
|
+
<<<<<<< HEAD
|
|
98
|
+
.setEndpoint('https://api.eve.ai/v1');
|
|
99
|
+
=======
|
|
100
|
+
.setEndpoint('https://api.eve.ai');
|
|
101
|
+
>>>>>>> 836ad7e6f9efd8ec1892686c48347c8a25fcf8f4
|
|
102
|
+
|
|
103
|
+
const auth = new Auth(client);
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const response = await auth.login('username', 'password');
|
|
107
|
+
console.log('Login successful:', response);
|
|
108
|
+
// Response: { status_code: 0, status_msg: 'success', user_id: 123, token: 'xxx' }
|
|
109
|
+
|
|
110
|
+
// Set token for authenticated requests
|
|
111
|
+
client.setToken(response.token);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error('Login failed:', error);
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### User Management
|
|
118
|
+
|
|
119
|
+
#### Get User Info
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
const { UserService } = require('@eveai/eve-sdk-for-node');
|
|
123
|
+
|
|
124
|
+
const userService = new UserService(client);
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
const user = await userService.getUser(
|
|
128
|
+
123, // userId - User to query
|
|
129
|
+
456, // actorId - Current user
|
|
130
|
+
'token' // Authentication token
|
|
131
|
+
);
|
|
132
|
+
console.log('User info:', user);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error('Failed to get user:', error);
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### Update User Profile
|
|
139
|
+
|
|
140
|
+
```javascript
|
|
141
|
+
const { UserService } = require('@eveai/eve-sdk-for-node');
|
|
142
|
+
|
|
143
|
+
const userService = new UserService(client);
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
const response = await userService.updateProfile(
|
|
147
|
+
123, // userId
|
|
148
|
+
'token', // Authentication token
|
|
149
|
+
'https://example.com/avatar.jpg', // avatar (optional)
|
|
150
|
+
'https://example.com/background.jpg', // backgroundImage (optional)
|
|
151
|
+
'Hello, I am a Eve.AI user!' // signature (optional)
|
|
152
|
+
);
|
|
153
|
+
console.log('Profile updated:', response);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
console.error('Failed to update profile:', error);
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Video Feed
|
|
160
|
+
|
|
161
|
+
#### List Videos
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
const { Feed } = require('@eveai/eve-sdk-for-node');
|
|
165
|
+
|
|
166
|
+
const feed = new Feed(client);
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
const videos = await feed.listVideos(
|
|
170
|
+
undefined, // latestTime (optional)
|
|
171
|
+
123 // actorId (optional)
|
|
172
|
+
);
|
|
173
|
+
console.log('Video feed:', videos.video_list);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
console.error('Failed to get feed:', error);
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### Get Video By ID
|
|
180
|
+
|
|
181
|
+
```javascript
|
|
182
|
+
const { Feed } = require('@eveai/eve-sdk-for-node');
|
|
183
|
+
|
|
184
|
+
const feed = new Feed(client);
|
|
185
|
+
|
|
186
|
+
try {
|
|
187
|
+
const response = await feed.getVideoById(
|
|
188
|
+
456, // videoId
|
|
189
|
+
123 // actorId (optional)
|
|
190
|
+
);
|
|
191
|
+
console.log('Video details:', response.video);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
console.error('Failed to get video:', error);
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Publishing Videos
|
|
198
|
+
|
|
199
|
+
#### Publish a Video
|
|
200
|
+
|
|
201
|
+
The SDK uses **multipart/form-data** (FormData) to upload videos to the backend. The video file and title are sent in the form body, while authentication parameters (token and actor_id) are sent as query parameters.
|
|
202
|
+
|
|
203
|
+
```javascript
|
|
204
|
+
const { Publish } = require('@eveai/eve-sdk-for-node');
|
|
205
|
+
const fs = require('fs');
|
|
206
|
+
|
|
207
|
+
const publish = new Publish(client);
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
const videoData = fs.readFileSync('video.mp4');
|
|
211
|
+
|
|
212
|
+
const response = await publish.publishVideo(
|
|
213
|
+
123, // actorId
|
|
214
|
+
'token', // Authentication token
|
|
215
|
+
videoData, // Video file data (Buffer, Blob, or File)
|
|
216
|
+
'My Video' // Video title
|
|
217
|
+
);
|
|
218
|
+
console.log('Video published:', response);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
console.error('Failed to publish video:', error);
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**How it works:**
|
|
225
|
+
- The SDK automatically converts Buffer/Blob to File for FormData compatibility
|
|
226
|
+
- Query parameters: `token`, `actor_id`
|
|
227
|
+
- Form body fields: `data` (video file), `title` (video title)
|
|
228
|
+
- Content-Type: `multipart/form-data` (automatically set by the SDK)
|
|
229
|
+
|
|
230
|
+
#### Publish a Video with Chunked Upload and Progress Tracking
|
|
231
|
+
|
|
232
|
+
For large video files (>5MB), the SDK automatically uses chunked upload. You can also track upload progress:
|
|
233
|
+
|
|
234
|
+
```javascript
|
|
235
|
+
const { Publish } = require('@eveai/eve-sdk-for-node');
|
|
236
|
+
const fs = require('fs');
|
|
237
|
+
|
|
238
|
+
const publish = new Publish(client);
|
|
239
|
+
|
|
240
|
+
try {
|
|
241
|
+
const videoData = fs.readFileSync('large-video.mp4');
|
|
242
|
+
|
|
243
|
+
const response = await publish.publishVideo(
|
|
244
|
+
123, // actorId
|
|
245
|
+
'token', // Authentication token
|
|
246
|
+
videoData, // Video file data
|
|
247
|
+
'My Video', // Video title
|
|
248
|
+
(progress) => {
|
|
249
|
+
// Progress callback
|
|
250
|
+
console.log(`Upload progress: ${progress.progress}%`);
|
|
251
|
+
console.log(`Uploaded: ${progress.sizeUploaded} bytes`);
|
|
252
|
+
console.log(`Chunks: ${progress.chunksUploaded}/${progress.chunksTotal}`);
|
|
253
|
+
}
|
|
254
|
+
);
|
|
255
|
+
console.log('Video published:', response);
|
|
256
|
+
} catch (error) {
|
|
257
|
+
console.error('Failed to publish video:', error);
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**Features:**
|
|
262
|
+
- Uses **FormData** for multipart/form-data uploads
|
|
263
|
+
- Automatic chunked upload for files larger than 5MB (configurable via `Client.CHUNK_SIZE`)
|
|
264
|
+
- Backend support for chunked uploads with Redis-based temporary storage
|
|
265
|
+
- Progress tracking with detailed upload statistics from both client and server
|
|
266
|
+
- Supports Buffer, Blob, and File types
|
|
267
|
+
- Automatic retry and resume capability through chunk-based uploads
|
|
268
|
+
- Query parameters and form body fields are properly separated
|
|
269
|
+
- Server returns `upload_id`, `chunks_total`, and `chunks_uploaded` for progress tracking
|
|
270
|
+
|
|
271
|
+
**How Chunked Upload Works:**
|
|
272
|
+
1. SDK splits large files into 5MB chunks
|
|
273
|
+
2. Each chunk is sent with a `Content-Range` header (e.g., `bytes 0-5242879/10485760`)
|
|
274
|
+
3. Backend stores chunks temporarily in Redis with 1-hour expiration
|
|
275
|
+
4. Backend tracks upload progress and returns `upload_id` for subsequent chunks
|
|
276
|
+
5. When all chunks are received, backend assembles them and creates the video
|
|
277
|
+
6. Chunks are automatically cleaned up from Redis after successful assembly
|
|
278
|
+
|
|
279
|
+
#### Delete a Video
|
|
280
|
+
|
|
281
|
+
```javascript
|
|
282
|
+
const { Publish } = require('@eveai/eve-sdk-for-node');
|
|
283
|
+
|
|
284
|
+
const publish = new Publish(client);
|
|
285
|
+
|
|
286
|
+
try {
|
|
287
|
+
const response = await publish.deleteVideo(
|
|
288
|
+
123, // actorId (must be video owner)
|
|
289
|
+
456, // videoId
|
|
290
|
+
'token' // Authentication token
|
|
291
|
+
);
|
|
292
|
+
console.log('Video deleted:', response);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
console.error('Failed to delete video:', error);
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Comments
|
|
299
|
+
|
|
300
|
+
```javascript
|
|
301
|
+
const { CommentService } = require('@eveai/eve-sdk-for-node');
|
|
302
|
+
|
|
303
|
+
const commentService = new CommentService(client);
|
|
304
|
+
|
|
305
|
+
// Add a comment
|
|
306
|
+
try {
|
|
307
|
+
const comment = await commentService.addComment(
|
|
308
|
+
456, // videoId
|
|
309
|
+
123, // actorId
|
|
310
|
+
'token', // Authentication token
|
|
311
|
+
'Great video!' // Comment text
|
|
312
|
+
);
|
|
313
|
+
console.log('Comment added:', comment);
|
|
314
|
+
} catch (error) {
|
|
315
|
+
console.error('Failed to add comment:', error);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// List comments
|
|
319
|
+
try {
|
|
320
|
+
const comments = await commentService.listComments(456, 123, 'token');
|
|
321
|
+
console.log('Comments:', comments.comment_list);
|
|
322
|
+
} catch (error) {
|
|
323
|
+
console.error('Failed to list comments:', error);
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Favorites
|
|
328
|
+
|
|
329
|
+
```javascript
|
|
330
|
+
const { Favorite } = require('@eveai/eve-sdk-for-node');
|
|
331
|
+
|
|
332
|
+
const favorite = new Favorite(client);
|
|
333
|
+
|
|
334
|
+
// Like a video
|
|
335
|
+
try {
|
|
336
|
+
await favorite.likeVideo(456, 123, 'token');
|
|
337
|
+
console.log('Video liked');
|
|
338
|
+
} catch (error) {
|
|
339
|
+
console.error('Failed to like video:', error);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// List favorite videos
|
|
343
|
+
try {
|
|
344
|
+
const favorites = await favorite.listFavorites(123, 123, 'token');
|
|
345
|
+
console.log('Favorite videos:', favorites.video_list);
|
|
346
|
+
} catch (error) {
|
|
347
|
+
console.error('Failed to list favorites:', error);
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### Relations (Follow/Unfollow)
|
|
352
|
+
|
|
353
|
+
```javascript
|
|
354
|
+
const { Relation } = require('@eveai/eve-sdk-for-node');
|
|
355
|
+
|
|
356
|
+
const relation = new Relation(client);
|
|
357
|
+
|
|
358
|
+
// Follow a user
|
|
359
|
+
try {
|
|
360
|
+
await relation.follow(789, 123, 'token');
|
|
361
|
+
console.log('User followed');
|
|
362
|
+
} catch (error) {
|
|
363
|
+
console.error('Failed to follow user:', error);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Get followers
|
|
367
|
+
try {
|
|
368
|
+
const followers = await relation.getFollowerList(123, 123, 'token');
|
|
369
|
+
console.log('Followers:', followers.user_list);
|
|
370
|
+
} catch (error) {
|
|
371
|
+
console.error('Failed to get followers:', error);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// Check if following
|
|
375
|
+
try {
|
|
376
|
+
const isFollowing = await relation.isFollowing(789, 123, 'token');
|
|
377
|
+
console.log('Is following:', isFollowing.result);
|
|
378
|
+
} catch (error) {
|
|
379
|
+
console.error('Failed to check follow status:', error);
|
|
380
|
+
}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
### Messaging
|
|
384
|
+
|
|
385
|
+
```javascript
|
|
386
|
+
const { MessageService } = require('@eveai/eve-sdk-for-node');
|
|
387
|
+
|
|
388
|
+
const messageService = new MessageService(client);
|
|
389
|
+
|
|
390
|
+
// Send a message
|
|
391
|
+
try {
|
|
392
|
+
await messageService.sendMessage(
|
|
393
|
+
789, // toUserId
|
|
394
|
+
123, // actorId
|
|
395
|
+
'token', // Authentication token
|
|
396
|
+
'Hello there!' // Message content
|
|
397
|
+
);
|
|
398
|
+
console.log('Message sent');
|
|
399
|
+
} catch (error) {
|
|
400
|
+
console.error('Failed to send message:', error);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// List messages
|
|
404
|
+
try {
|
|
405
|
+
const messages = await messageService.listMessages(789, 123, 'token');
|
|
406
|
+
console.log('Messages:', messages.message_list);
|
|
407
|
+
} catch (error) {
|
|
408
|
+
console.error('Failed to list messages:', error);
|
|
409
|
+
}
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### File Storage
|
|
413
|
+
|
|
414
|
+
Upload images directly to Eve.AI storage:
|
|
415
|
+
|
|
416
|
+
```javascript
|
|
417
|
+
const { GuGoTikStorage } = require('@eveai/eve-sdk-for-node');
|
|
418
|
+
const fs = require('fs');
|
|
419
|
+
|
|
420
|
+
const storage = new GuGoTikStorage(client);
|
|
421
|
+
|
|
422
|
+
try {
|
|
423
|
+
const imageData = fs.readFileSync('avatar.jpg');
|
|
424
|
+
|
|
425
|
+
const response = await storage.uploadFile(imageData);
|
|
426
|
+
console.log('File uploaded:', response.file_url);
|
|
427
|
+
// Use the file_url for user avatar, background image, etc.
|
|
428
|
+
} catch (error) {
|
|
429
|
+
console.error('Failed to upload file:', error);
|
|
430
|
+
}
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
## Error Handling
|
|
434
|
+
|
|
435
|
+
The SDK raises `AppwriteException` with `message`, `code`, `type`, and `response` properties. Handle errors appropriately:
|
|
436
|
+
|
|
437
|
+
```javascript
|
|
438
|
+
const { Auth, AppwriteException } = require('@eveai/eve-sdk-for-node');
|
|
439
|
+
|
|
440
|
+
const auth = new Auth(client);
|
|
441
|
+
|
|
442
|
+
try {
|
|
443
|
+
const response = await auth.login('username', 'password');
|
|
444
|
+
console.log('Login successful:', response);
|
|
445
|
+
} catch (error) {
|
|
446
|
+
if (error instanceof AppwriteException) {
|
|
447
|
+
console.error('Error code:', error.code);
|
|
448
|
+
console.error('Error message:', error.message);
|
|
449
|
+
console.error('Error response:', error.response);
|
|
450
|
+
} else {
|
|
451
|
+
console.error('Unexpected error:', error);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
## TypeScript Support
|
|
457
|
+
|
|
458
|
+
The SDK is written in TypeScript and includes full type definitions:
|
|
459
|
+
|
|
460
|
+
```typescript
|
|
461
|
+
import { Client, Auth, Feed, Video, User } from '@eveai/eve-sdk-for-node';
|
|
462
|
+
|
|
463
|
+
const client = new Client()
|
|
464
|
+
<<<<<<< HEAD
|
|
465
|
+
.setEndpoint('https://api.eve.ai/v1');
|
|
466
|
+
=======
|
|
467
|
+
.setEndpoint('https://api.eve.ai');
|
|
468
|
+
>>>>>>> 836ad7e6f9efd8ec1892686c48347c8a25fcf8f4
|
|
469
|
+
|
|
470
|
+
const auth = new Auth(client);
|
|
471
|
+
const feed = new Feed(client);
|
|
472
|
+
|
|
473
|
+
// Full type safety
|
|
474
|
+
const loginResponse = await auth.login('username', 'password');
|
|
475
|
+
const videos = await feed.listVideos();
|
|
476
|
+
|
|
477
|
+
videos.video_list?.forEach((video: Video) => {
|
|
478
|
+
console.log(`Video: ${video.title} by ${video.author.name}`);
|
|
479
|
+
});
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
## API Reference
|
|
483
|
+
|
|
484
|
+
### Services
|
|
485
|
+
|
|
486
|
+
- **Auth** - User authentication (login, register)
|
|
487
|
+
- **UserService** - User management (get user info, update profile)
|
|
488
|
+
- **Feed** - Video feed (list videos, get video by ID)
|
|
489
|
+
- **Publish** - Video publishing (publish video, delete video, list published videos)
|
|
490
|
+
- **CommentService** - Comment management
|
|
491
|
+
- **Favorite** - Like/favorite videos
|
|
492
|
+
- **Relation** - Follow/unfollow users
|
|
493
|
+
- **MessageService** - Direct messaging
|
|
494
|
+
- **GuGoTikStorage** - File storage (upload images)
|
|
495
|
+
|
|
496
|
+
For detailed API documentation, see the [Eve.AI Backend Documentation](https://github.com/EveAGI/backend).
|
|
497
|
+
|
|
498
|
+
## Learn More
|
|
499
|
+
|
|
500
|
+
- 📖 [Eve.AI SDK for Node.js Repository](https://github.com/EveAGI/@eveai/eve-sdk-for-node)
|
|
501
|
+
- 🏗️ [Architecture Documentation](https://github.com/EveAGI/backend/blob/main/README.md)
|
|
502
|
+
- 🐛 [Report Issues](https://github.com/EveAGI/backend/issues)
|
|
503
|
+
|
|
504
|
+
## Contribution
|
|
505
|
+
|
|
506
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
507
|
+
|
|
508
|
+
## License
|
|
509
|
+
|
|
510
|
+
Please see the [BSD-3-Clause license](LICENSE) file for more information.
|
package/dist/client.js
CHANGED
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"names":[],"mappings":"AAAA,SAAS,OAAO,UAAU,YAAY;AACtC,SAAS,mBAAmB;AAmB5B,MAAM,0BAA0B,MAAM;AAAA,EAIlC,YAAY,SAAiB,OAAe,GAAG,OAAe,IAAI,WAAmB,IAAI;AACrF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAU;AACf,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EACpB;AACJ;AAEA,SAAS,eAAe;AACpB,MAAI,KAAK;AAGT,QAAM,WAAqB,CAAC;AAC5B,MAAI,OAAO,YAAY,aAAa;AAChC,QAAI,OAAO,QAAQ,aAAa;AAAU,eAAS,KAAK,QAAQ,QAAQ;AACxE,QAAI,OAAO,QAAQ,SAAS;AAAU,eAAS,KAAK,QAAQ,IAAI;AAAA,EACpE;AACA,MAAI,SAAS,SAAS,GAAG;AACrB,UAAM,KAAK,SAAS,KAAK,IAAI,CAAC;AAAA,EAClC;AAMA,MAAI,OAAO,cAAc,eAAe,OAAO,UAAU,cAAc,UAAU;AAE7E,UAAM,IAAI,UAAU,SAAS;AAAA,EAGjC,WAAW,OAAO,WAAW,gBAAgB,UAAU;AACnD,UAAM;AAAA,EAGV,WAAW,OAAO,YAAY,eAAe,OAAO,QAAQ,YAAY,UAAU;AAC9E,UAAM,YAAY,QAAQ,OAAO;AAAA,EACrC;AAEA,SAAO;AACX;AAEA,MAAM,UAAN,MAAM,QAAO;AAAA,EAAb;AAGI,kBAAS;AAAA,MACL,UAAU;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EA,UAAI,OAAO,SAAS,QAAQ;AACxB,YAAI,eAAe;AACnB,cAAI,cAAS,QAAQ,IAAI,cAAc,MAAnC,mBAAsC,SAAS,wBAAuB,iBAAiB,eAAe;AACtG,yBAAe,KAAK,UAAU,IAAI;AAAA,QACtC,OAAO;AACH,yBAAe,6BAAM;AAAA,QACzB;AACA,cAAM,IAAI,kBAAkB,6BAAM,SAAS,SAAS,QAAQ,6BAAM,MAAM,YAAY;AAAA,MACxF;AAEA,aAAO;AAAA,IACX,SAAS,OAAY;AACjB,mBAAa,SAAS;AACtB,UAAI,MAAM,SAAS,cAAc;AAC7B,cAAM,IAAI,kBAAkB,yBAAyB,KAAK,OAAO,OAAO,MAAM,KAAK,eAAe;AAAA,MACtG;AACA,YAAM;AAAA,IACV;AAAA,EACJ;AAAA,EAEA,OAAO,QAAQ,MAAe,SAAS,IAAa;AAChD,QAAI,SAAkB,CAAC;AAEvB,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,IAAI,GAAG;AAC7C,UAAI,WAAW,SAAS,SAAS,MAAM,MAAK,MAAM;AAClD,UAAI,MAAM,QAAQ,KAAK,GAAG;AACtB,iBAAS,EAAE,GAAG,QAAQ,GAAG,QAAO,QAAQ,OAAO,QAAQ,EAAE;AAAA,MAC7D,OAAO;AACH,eAAO,QAAQ,IAAI;AAAA,MACvB;AAAA,IACJ;AAEA,WAAO;AAAA,EACX;AACJ;AAvSM,QACK,aAAa,OAAO,OAAO;AADtC,IAAM,SAAN;AA0SA,SAAS,aAAa","sourcesContent":["import { fetch, FormData, File } from 'node-fetch-native-with-agent';\nimport { createAgent } from 'node-fetch-native-with-agent/agent';\nimport { Models } from './models';\n\ntype Payload = {\n [key: string]: any;\n}\n\ntype UploadProgress = {\n $id: string;\n progress: number;\n sizeUploaded: number;\n chunksTotal: number;\n chunksUploaded: number;\n}\n\ntype Headers = {\n [key: string]: string;\n}\n\nclass AppwriteException extends Error {\n code: number;\n response: string;\n type: string;\n constructor(message: string, code: number = 0, type: string = '', response: string = '') {\n super(message);\n this.name = 'AppwriteException';\n this.message = message;\n this.code = code;\n this.type = type;\n this.response = response;\n }\n}\n\nfunction getUserAgent() {\n let ua = 'EveNodeJSSDK/0.0.1';\n\n // `process` is a global in Node.js, but not fully available in all runtimes.\n const platform: string[] = [];\n if (typeof process !== 'undefined') {\n if (typeof process.platform === 'string') platform.push(process.platform);\n if (typeof process.arch === 'string') platform.push(process.arch);\n }\n if (platform.length > 0) {\n ua += ` (${platform.join('; ')})`;\n }\n\n // `navigator.userAgent` is available in Node.js 21 and later.\n // It's also part of the WinterCG spec, so many edge runtimes provide it.\n // https://common-min-api.proposal.wintercg.org/#requirements-for-navigatoruseragent\n // @ts-ignore\n if (typeof navigator !== 'undefined' && typeof navigator.userAgent === 'string') {\n // @ts-ignore\n ua += ` ${navigator.userAgent}`;\n\n // @ts-ignore\n } else if (typeof globalThis.EdgeRuntime === 'string') {\n ua += ` EdgeRuntime`;\n\n // Older Node.js versions don't have `navigator.userAgent`, so we have to use `process.version`.\n } else if (typeof process !== 'undefined' && typeof process.version === 'string') {\n ua += ` Node.js/${process.version}`;\n }\n\n return ua;\n}\n\nclass Client {\n static CHUNK_SIZE = 1024 * 1024 * 5;\n\n config = {\n endpoint: 'http://localhost:37000',\n selfSigned: false,\n token: '',\n timeout: 600000, // 10 minutes default timeout for large video uploads\n };\n headers: Headers = {\n // 'x-sdk-name': 'Node.js',\n // 'x-sdk-platform': 'server',\n // 'x-sdk-language': 'nodejs',\n // 'x-sdk-version': '0.0.1',\n 'user-agent' : getUserAgent(),\n // 'Content-Type': 'application/json',\n };\n\n /**\n * Set Endpoint\n *\n * Your Eve AI API endpoint\n *\n * @param {string} endpoint\n *\n * @returns {this}\n */\n setEndpoint(endpoint: string): this {\n if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {\n throw new AppwriteException('Invalid endpoint URL: ' + endpoint);\n }\n\n this.config.endpoint = endpoint;\n return this;\n }\n\n /**\n * Set Timeout\n *\n * Set the timeout for API requests in milliseconds\n *\n * @param {number} timeout - Timeout in milliseconds\n *\n * @returns {this}\n */\n setTimeout(timeout: number): this {\n this.config.timeout = timeout;\n return this;\n }\n\n /**\n * Set self-signed\n *\n * @param {boolean} selfSigned\n *\n * @returns {this}\n */\n setSelfSigned(selfSigned: boolean): this {\n // @ts-ignore\n if (typeof globalThis.EdgeRuntime !== 'undefined') {\n console.warn('setSelfSigned is not supported in edge runtimes.');\n }\n\n this.config.selfSigned = selfSigned;\n\n return this;\n }\n\n /**\n * Add header\n *\n * @param {string} header\n * @param {string} value\n *\n * @returns {this}\n */\n addHeader(header: string, value: string): this {\n this.headers[header.toLowerCase()] = value;\n\n return this;\n }\n\n /**\n * Set Token\n *\n * Your authentication token\n *\n * @param value string\n *\n * @return {this}\n */\n setToken(value: string): this {\n // this.headers['Authorization'] = `Bearer ${value}`;\n this.config.token = value;\n return this;\n }\n /**\n * Set ForwardedUserAgent\n *\n * The user agent string of the client that made the request\n *\n * @param value string\n *\n * @return {this}\n */\n setForwardedUserAgent(value: string): this {\n this.headers['X-Forwarded-User-Agent'] = value;\n return this;\n }\n\n prepareRequest(method: string, url: URL, headers: Headers = {}, params: Payload = {}): { uri: string, options: RequestInit } {\n method = method.toUpperCase();\n\n headers = Object.assign({}, this.headers, headers);\n\n let options: RequestInit = {\n method,\n headers,\n ...createAgent(this.config.endpoint, { rejectUnauthorized: !this.config.selfSigned }),\n };\n\n if (method === 'GET') {\n for (const [key, value] of Object.entries(Client.flatten(params))) {\n url.searchParams.append(key, value);\n }\n } else {\n switch (headers['content-type']) {\n case 'application/json':\n options.body = JSON.stringify(params);\n break;\n\n case 'multipart/form-data':\n const formData = new FormData();\n\n for (const [key, value] of Object.entries(params)) {\n if (value instanceof File) {\n formData.append(key, value, value.name);\n } else if (Array.isArray(value)) {\n for (const nestedValue of value) {\n formData.append(`${key}[]`, nestedValue);\n }\n } else {\n formData.append(key, value);\n }\n }\n\n options.body = formData;\n // Do NOT set Content-Type header manually when using FormData\n // The 'form-data' package (or native FormData) will automatically set it\n // along with the boundary. \n // headers['content-type'] = 'multipart/form-data';\n delete headers['content-type'];\n break;\n }\n }\n\n return { uri: url.toString(), options };\n }\n\n async chunkedUpload(method: string, url: URL, headers: Headers = {}, originalPayload: Payload = {}, onProgress: (progress: UploadProgress) => void) {\n const [fileParam, file] = Object.entries(originalPayload).find(([_, value]) => value instanceof File) ?? [];\n\n if (!file || !fileParam) {\n throw new Error('File not found in payload');\n }\n\n if (file.size <= Client.CHUNK_SIZE) {\n return await this.call(method, url, headers, originalPayload);\n }\n\n let start = 0;\n let response = null;\n\n while (start < file.size) {\n let end = start + Client.CHUNK_SIZE; // Prepare end for the next chunk\n if (end >= file.size) {\n end = file.size; // Adjust for the last chunk to include the last byte\n }\n\n headers['content-range'] = `bytes ${start}-${end-1}/${file.size}`;\n const chunk = file.slice(start, end);\n\n let payload = { ...originalPayload };\n payload[fileParam] = new File([chunk], file.name);\n\n response = await this.call(method, url, headers, payload);\n\n if (onProgress && typeof onProgress === 'function') {\n onProgress({\n $id: response.upload_id || response.$id,\n progress: Math.round((end / file.size) * 100),\n sizeUploaded: end,\n chunksTotal: response.chunks_total || Math.ceil(file.size / Client.CHUNK_SIZE),\n chunksUploaded: response.chunks_uploaded || Math.ceil(end / Client.CHUNK_SIZE)\n });\n }\n\n // Support both Eve AI (upload_id) and Appwrite ($id) formats\n if (response && response.upload_id) {\n headers['X-Upload-Id'] = response.upload_id;\n } else if (response && response.$id) {\n headers['x-appwrite-id'] = response.$id;\n }\n\n start = end;\n }\n\n return response;\n }\n\n async ping(): Promise<string> {\n return this.call('GET', new URL(this.config.endpoint + '/ping'));\n }\n\n async redirect(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise<string> {\n const { uri, options } = this.prepareRequest(method, url, headers, params);\n \n const response = await fetch(uri, {\n ...options,\n redirect: 'manual'\n });\n\n if (response.status !== 301 && response.status !== 302) {\n throw new AppwriteException('Invalid redirect', response.status);\n }\n\n return response.headers.get('location') || '';\n }\n\n async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}, responseType = 'json'): Promise<any> {\n const { uri, options } = this.prepareRequest(method, url, headers, params);\n\n let data: any = null;\n\n // Create an AbortController for timeout\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);\n\n try {\n const response = await fetch(uri, {\n ...options,\n signal: controller.signal\n });\n\n clearTimeout(timeoutId);\n\n const warnings = response.headers.get('x-appwrite-warning');\n if (warnings) {\n warnings.split(';').forEach((warning: string) => console.warn('Warning: ' + warning));\n }\n\n if (response.headers.get('content-type')?.includes('application/json')) {\n data = await response.json();\n } else if (responseType === 'arrayBuffer') {\n data = await response.arrayBuffer();\n } else {\n data = {\n message: await response.text()\n };\n }\n\n if (400 <= response.status) {\n let responseText = '';\n if (response.headers.get('content-type')?.includes('application/json') || responseType === 'arrayBuffer') {\n responseText = JSON.stringify(data);\n } else {\n responseText = data?.message;\n }\n throw new AppwriteException(data?.message, response.status, data?.type, responseText);\n }\n\n return data;\n } catch (error: any) {\n clearTimeout(timeoutId);\n if (error.name === 'AbortError') {\n throw new AppwriteException(`Request timeout after ${this.config.timeout}ms`, 408, 'timeout_error');\n }\n throw error;\n }\n }\n\n static flatten(data: Payload, prefix = ''): Payload {\n let output: Payload = {};\n\n for (const [key, value] of Object.entries(data)) {\n let finalKey = prefix ? prefix + '[' + key +']' : key;\n if (Array.isArray(value)) {\n output = { ...output, ...Client.flatten(value, finalKey) };\n } else {\n output[finalKey] = value;\n }\n }\n\n return output;\n }\n}\n\nexport { Client, AppwriteException };\nexport { Query } from './query';\nexport type { Models, Payload, UploadProgress };\nexport type { QueryTypes, QueryTypesList } from './query';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":[],"mappings":"AAAA,SAAS,OAAO,UAAU,YAAY;AACtC,SAAS,mBAAmB;AAmB5B,MAAM,0BAA0B,MAAM;AAAA,EAIlC,YAAY,SAAiB,OAAe,GAAG,OAAe,IAAI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,eAAe;AAAA,MACtG;AACA,YAAM;AAAA,IACV;AAAA,EACJ;AAAA,EAEA,OAAO,QAAQ,MAAe,SAAS,IAAa;AAChD,QAAI,SAAkB,CAAC;AAEvB,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,IAAI,GAAG;AAC7C,UAAI,WAAW,SAAS,SAAS,MAAM,MAAK,MAAM;AAClD,UAAI,MAAM,QAAQ,KAAK,GAAG;AACtB,iBAAS,EAAE,GAAG,QAAQ,GAAG,QAAO,QAAQ,OAAO,QAAQ,EAAE;AAAA,MAC7D,OAAO;AACH,eAAO,QAAQ,IAAI;AAAA,MACvB;AAAA,IACJ;AAEA,WAAO;AAAA,EACX;AACJ;AAvSM,QACK,aAAa,OAAO,OAAO;AADtC,IAAM,SAAN;AA0SA,SAAS,aAAa","sourcesContent":["import { fetch, FormData, File } from 'node-fetch-native-with-agent';\nimport { createAgent } from 'node-fetch-native-with-agent/agent';\nimport { Models } from './models';\n\ntype Payload = {\n [key: string]: any;\n}\n\ntype UploadProgress = {\n $id: string;\n progress: number;\n sizeUploaded: number;\n chunksTotal: number;\n chunksUploaded: number;\n}\n\ntype Headers = {\n [key: string]: string;\n}\n\nclass AppwriteException extends Error {\n code: number;\n response: string;\n type: string;\n constructor(message: string, code: number = 0, type: string = '', response: string = '') {\n super(message);\n this.name = 'AppwriteException';\n this.message = message;\n this.code = code;\n this.type = type;\n this.response = response;\n }\n}\n\nfunction getUserAgent() {\n let ua = 'EveNodeJSSDK/0.0.1';\n\n // `process` is a global in Node.js, but not fully available in all runtimes.\n const platform: string[] = [];\n if (typeof process !== 'undefined') {\n if (typeof process.platform === 'string') platform.push(process.platform);\n if (typeof process.arch === 'string') platform.push(process.arch);\n }\n if (platform.length > 0) {\n ua += ` (${platform.join('; ')})`;\n }\n\n // `navigator.userAgent` is available in Node.js 21 and later.\n // It's also part of the WinterCG spec, so many edge runtimes provide it.\n // https://common-min-api.proposal.wintercg.org/#requirements-for-navigatoruseragent\n // @ts-ignore\n if (typeof navigator !== 'undefined' && typeof navigator.userAgent === 'string') {\n // @ts-ignore\n ua += ` ${navigator.userAgent}`;\n\n // @ts-ignore\n } else if (typeof globalThis.EdgeRuntime === 'string') {\n ua += ` EdgeRuntime`;\n\n // Older Node.js versions don't have `navigator.userAgent`, so we have to use `process.version`.\n } else if (typeof process !== 'undefined' && typeof process.version === 'string') {\n ua += ` Node.js/${process.version}`;\n }\n\n return ua;\n}\n\nclass Client {\n static CHUNK_SIZE = 1024 * 1024 * 5;\n\n config = {\n endpoint: 'https://api.eve.ai/v1',\n selfSigned: false,\n token: '',\n timeout: 600000, // 10 minutes default timeout for large video uploads\n };\n headers: Headers = {\n // 'x-sdk-name': 'Node.js',\n // 'x-sdk-platform': 'server',\n // 'x-sdk-language': 'nodejs',\n // 'x-sdk-version': '0.0.1',\n 'user-agent' : getUserAgent(),\n // 'Content-Type': 'application/json',\n };\n\n /**\n * Set Endpoint\n *\n * Your Eve AI API endpoint\n *\n * @param {string} endpoint\n *\n * @returns {this}\n */\n setEndpoint(endpoint: string): this {\n if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {\n throw new AppwriteException('Invalid endpoint URL: ' + endpoint);\n }\n\n this.config.endpoint = endpoint;\n return this;\n }\n\n /**\n * Set Timeout\n *\n * Set the timeout for API requests in milliseconds\n *\n * @param {number} timeout - Timeout in milliseconds\n *\n * @returns {this}\n */\n setTimeout(timeout: number): this {\n this.config.timeout = timeout;\n return this;\n }\n\n /**\n * Set self-signed\n *\n * @param {boolean} selfSigned\n *\n * @returns {this}\n */\n setSelfSigned(selfSigned: boolean): this {\n // @ts-ignore\n if (typeof globalThis.EdgeRuntime !== 'undefined') {\n console.warn('setSelfSigned is not supported in edge runtimes.');\n }\n\n this.config.selfSigned = selfSigned;\n\n return this;\n }\n\n /**\n * Add header\n *\n * @param {string} header\n * @param {string} value\n *\n * @returns {this}\n */\n addHeader(header: string, value: string): this {\n this.headers[header.toLowerCase()] = value;\n\n return this;\n }\n\n /**\n * Set Token\n *\n * Your authentication token\n *\n * @param value string\n *\n * @return {this}\n */\n setToken(value: string): this {\n // this.headers['Authorization'] = `Bearer ${value}`;\n this.config.token = value;\n return this;\n }\n /**\n * Set ForwardedUserAgent\n *\n * The user agent string of the client that made the request\n *\n * @param value string\n *\n * @return {this}\n */\n setForwardedUserAgent(value: string): this {\n this.headers['X-Forwarded-User-Agent'] = value;\n return this;\n }\n\n prepareRequest(method: string, url: URL, headers: Headers = {}, params: Payload = {}): { uri: string, options: RequestInit } {\n method = method.toUpperCase();\n\n headers = Object.assign({}, this.headers, headers);\n\n let options: RequestInit = {\n method,\n headers,\n ...createAgent(this.config.endpoint, { rejectUnauthorized: !this.config.selfSigned }),\n };\n\n if (method === 'GET') {\n for (const [key, value] of Object.entries(Client.flatten(params))) {\n url.searchParams.append(key, value);\n }\n } else {\n switch (headers['content-type']) {\n case 'application/json':\n options.body = JSON.stringify(params);\n break;\n\n case 'multipart/form-data':\n const formData = new FormData();\n\n for (const [key, value] of Object.entries(params)) {\n if (value instanceof File) {\n formData.append(key, value, value.name);\n } else if (Array.isArray(value)) {\n for (const nestedValue of value) {\n formData.append(`${key}[]`, nestedValue);\n }\n } else {\n formData.append(key, value);\n }\n }\n\n options.body = formData;\n // Do NOT set Content-Type header manually when using FormData\n // The 'form-data' package (or native FormData) will automatically set it\n // along with the boundary. \n // headers['content-type'] = 'multipart/form-data';\n delete headers['content-type'];\n break;\n }\n }\n\n return { uri: url.toString(), options };\n }\n\n async chunkedUpload(method: string, url: URL, headers: Headers = {}, originalPayload: Payload = {}, onProgress: (progress: UploadProgress) => void) {\n const [fileParam, file] = Object.entries(originalPayload).find(([_, value]) => value instanceof File) ?? [];\n\n if (!file || !fileParam) {\n throw new Error('File not found in payload');\n }\n\n if (file.size <= Client.CHUNK_SIZE) {\n return await this.call(method, url, headers, originalPayload);\n }\n\n let start = 0;\n let response = null;\n\n while (start < file.size) {\n let end = start + Client.CHUNK_SIZE; // Prepare end for the next chunk\n if (end >= file.size) {\n end = file.size; // Adjust for the last chunk to include the last byte\n }\n\n headers['content-range'] = `bytes ${start}-${end-1}/${file.size}`;\n const chunk = file.slice(start, end);\n\n let payload = { ...originalPayload };\n payload[fileParam] = new File([chunk], file.name);\n\n response = await this.call(method, url, headers, payload);\n\n if (onProgress && typeof onProgress === 'function') {\n onProgress({\n $id: response.upload_id || response.$id,\n progress: Math.round((end / file.size) * 100),\n sizeUploaded: end,\n chunksTotal: response.chunks_total || Math.ceil(file.size / Client.CHUNK_SIZE),\n chunksUploaded: response.chunks_uploaded || Math.ceil(end / Client.CHUNK_SIZE)\n });\n }\n\n // Support both Eve AI (upload_id) and Appwrite ($id) formats\n if (response && response.upload_id) {\n headers['X-Upload-Id'] = response.upload_id;\n } else if (response && response.$id) {\n headers['x-appwrite-id'] = response.$id;\n }\n\n start = end;\n }\n\n return response;\n }\n\n async ping(): Promise<string> {\n return this.call('GET', new URL(this.config.endpoint + '/ping'));\n }\n\n async redirect(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise<string> {\n const { uri, options } = this.prepareRequest(method, url, headers, params);\n \n const response = await fetch(uri, {\n ...options,\n redirect: 'manual'\n });\n\n if (response.status !== 301 && response.status !== 302) {\n throw new AppwriteException('Invalid redirect', response.status);\n }\n\n return response.headers.get('location') || '';\n }\n\n async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}, responseType = 'json'): Promise<any> {\n const { uri, options } = this.prepareRequest(method, url, headers, params);\n\n let data: any = null;\n\n // Create an AbortController for timeout\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);\n\n try {\n const response = await fetch(uri, {\n ...options,\n signal: controller.signal\n });\n\n clearTimeout(timeoutId);\n\n const warnings = response.headers.get('x-appwrite-warning');\n if (warnings) {\n warnings.split(';').forEach((warning: string) => console.warn('Warning: ' + warning));\n }\n\n if (response.headers.get('content-type')?.includes('application/json')) {\n data = await response.json();\n } else if (responseType === 'arrayBuffer') {\n data = await response.arrayBuffer();\n } else {\n data = {\n message: await response.text()\n };\n }\n\n if (400 <= response.status) {\n let responseText = '';\n if (response.headers.get('content-type')?.includes('application/json') || responseType === 'arrayBuffer') {\n responseText = JSON.stringify(data);\n } else {\n responseText = data?.message;\n }\n throw new AppwriteException(data?.message, response.status, data?.type, responseText);\n }\n\n return data;\n } catch (error: any) {\n clearTimeout(timeoutId);\n if (error.name === 'AbortError') {\n throw new AppwriteException(`Request timeout after ${this.config.timeout}ms`, 408, 'timeout_error');\n }\n throw error;\n }\n }\n\n static flatten(data: Payload, prefix = ''): Payload {\n let output: Payload = {};\n\n for (const [key, value] of Object.entries(data)) {\n let finalKey = prefix ? prefix + '[' + key +']' : key;\n if (Array.isArray(value)) {\n output = { ...output, ...Client.flatten(value, finalKey) };\n } else {\n output[finalKey] = value;\n }\n }\n\n return output;\n }\n}\n\nexport { Client, AppwriteException };\nexport { Query } from './query';\nexport type { Models, Payload, UploadProgress };\nexport type { QueryTypes, QueryTypesList } from './query';\n"]}
|