@eveai/eve-sdk-for-node 0.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 (3) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +490 -0
  3. package/package.json +62 -0
package/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,490 @@
1
+ # Eve.AI Node.js SDK
2
+
3
+ ![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg?style=flat-square)
4
+ ![Version](https://img.shields.io/badge/version-1.0.0-green.svg?style=flat-square)
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
+ Initialize your SDK with your Eve.AI backend endpoint (default: `http://api.eve.ai`):
44
+
45
+ ```javascript
46
+ const { Client, Auth } = require('@eveai/eve-sdk-for-node');
47
+
48
+ const client = new Client();
49
+
50
+ client
51
+ .setEndpoint('https://api.eve.ai') // Your Eve.AI backend endpoint
52
+ .setSelfSigned(true); // Use only in dev mode with self-signed SSL cert
53
+ ```
54
+
55
+ ### Authentication
56
+
57
+ #### Register a New User
58
+
59
+ ```javascript
60
+ const { Client, Auth } = require('@eveai/eve-sdk-for-node');
61
+
62
+ const client = new Client()
63
+ .setEndpoint('https://api.eve.ai');
64
+
65
+ const auth = new Auth(client);
66
+
67
+ try {
68
+ const response = await auth.register('username', 'password');
69
+ console.log('User registered:', response);
70
+ // Response: { status_code: 0, status_msg: 'success', user_id: 123, token: 'xxx' }
71
+
72
+ // Set token for authenticated requests
73
+ client.setToken(response.token);
74
+ } catch (error) {
75
+ console.error('Registration failed:', error);
76
+ }
77
+ ```
78
+
79
+ #### Login
80
+
81
+ ```javascript
82
+ const { Client, Auth } = require('@eveai/eve-sdk-for-node');
83
+
84
+ const client = new Client()
85
+ .setEndpoint('https://api.eve.ai');
86
+
87
+ const auth = new Auth(client);
88
+
89
+ try {
90
+ const response = await auth.login('username', 'password');
91
+ console.log('Login successful:', response);
92
+ // Response: { status_code: 0, status_msg: 'success', user_id: 123, token: 'xxx' }
93
+
94
+ // Set token for authenticated requests
95
+ client.setToken(response.token);
96
+ } catch (error) {
97
+ console.error('Login failed:', error);
98
+ }
99
+ ```
100
+
101
+ ### User Management
102
+
103
+ #### Get User Info
104
+
105
+ ```javascript
106
+ const { UserService } = require('@eveai/eve-sdk-for-node');
107
+
108
+ const userService = new UserService(client);
109
+
110
+ try {
111
+ const user = await userService.getUser(
112
+ 123, // userId - User to query
113
+ 456, // actorId - Current user
114
+ 'token' // Authentication token
115
+ );
116
+ console.log('User info:', user);
117
+ } catch (error) {
118
+ console.error('Failed to get user:', error);
119
+ }
120
+ ```
121
+
122
+ #### Update User Profile
123
+
124
+ ```javascript
125
+ const { UserService } = require('@eveai/eve-sdk-for-node');
126
+
127
+ const userService = new UserService(client);
128
+
129
+ try {
130
+ const response = await userService.updateProfile(
131
+ 123, // userId
132
+ 'token', // Authentication token
133
+ 'https://example.com/avatar.jpg', // avatar (optional)
134
+ 'https://example.com/background.jpg', // backgroundImage (optional)
135
+ 'Hello, I am a Eve.AI user!' // signature (optional)
136
+ );
137
+ console.log('Profile updated:', response);
138
+ } catch (error) {
139
+ console.error('Failed to update profile:', error);
140
+ }
141
+ ```
142
+
143
+ ### Video Feed
144
+
145
+ #### List Videos
146
+
147
+ ```javascript
148
+ const { Feed } = require('@eveai/eve-sdk-for-node');
149
+
150
+ const feed = new Feed(client);
151
+
152
+ try {
153
+ const videos = await feed.listVideos(
154
+ undefined, // latestTime (optional)
155
+ 123 // actorId (optional)
156
+ );
157
+ console.log('Video feed:', videos.video_list);
158
+ } catch (error) {
159
+ console.error('Failed to get feed:', error);
160
+ }
161
+ ```
162
+
163
+ #### Get Video By ID
164
+
165
+ ```javascript
166
+ const { Feed } = require('@eveai/eve-sdk-for-node');
167
+
168
+ const feed = new Feed(client);
169
+
170
+ try {
171
+ const response = await feed.getVideoById(
172
+ 456, // videoId
173
+ 123 // actorId (optional)
174
+ );
175
+ console.log('Video details:', response.video);
176
+ } catch (error) {
177
+ console.error('Failed to get video:', error);
178
+ }
179
+ ```
180
+
181
+ ### Publishing Videos
182
+
183
+ #### Publish a Video
184
+
185
+ 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.
186
+
187
+ ```javascript
188
+ const { Publish } = require('@eveai/eve-sdk-for-node');
189
+ const fs = require('fs');
190
+
191
+ const publish = new Publish(client);
192
+
193
+ try {
194
+ const videoData = fs.readFileSync('video.mp4');
195
+
196
+ const response = await publish.publishVideo(
197
+ 123, // actorId
198
+ 'token', // Authentication token
199
+ videoData, // Video file data (Buffer, Blob, or File)
200
+ 'My Video' // Video title
201
+ );
202
+ console.log('Video published:', response);
203
+ } catch (error) {
204
+ console.error('Failed to publish video:', error);
205
+ }
206
+ ```
207
+
208
+ **How it works:**
209
+ - The SDK automatically converts Buffer/Blob to File for FormData compatibility
210
+ - Query parameters: `token`, `actor_id`
211
+ - Form body fields: `data` (video file), `title` (video title)
212
+ - Content-Type: `multipart/form-data` (automatically set by the SDK)
213
+
214
+ #### Publish a Video with Chunked Upload and Progress Tracking
215
+
216
+ For large video files (>5MB), the SDK automatically uses chunked upload. You can also track upload progress:
217
+
218
+ ```javascript
219
+ const { Publish } = require('@eveai/eve-sdk-for-node');
220
+ const fs = require('fs');
221
+
222
+ const publish = new Publish(client);
223
+
224
+ try {
225
+ const videoData = fs.readFileSync('large-video.mp4');
226
+
227
+ const response = await publish.publishVideo(
228
+ 123, // actorId
229
+ 'token', // Authentication token
230
+ videoData, // Video file data
231
+ 'My Video', // Video title
232
+ (progress) => {
233
+ // Progress callback
234
+ console.log(`Upload progress: ${progress.progress}%`);
235
+ console.log(`Uploaded: ${progress.sizeUploaded} bytes`);
236
+ console.log(`Chunks: ${progress.chunksUploaded}/${progress.chunksTotal}`);
237
+ }
238
+ );
239
+ console.log('Video published:', response);
240
+ } catch (error) {
241
+ console.error('Failed to publish video:', error);
242
+ }
243
+ ```
244
+
245
+ **Features:**
246
+ - Uses **FormData** for multipart/form-data uploads
247
+ - Automatic chunked upload for files larger than 5MB (configurable via `Client.CHUNK_SIZE`)
248
+ - Backend support for chunked uploads with Redis-based temporary storage
249
+ - Progress tracking with detailed upload statistics from both client and server
250
+ - Supports Buffer, Blob, and File types
251
+ - Automatic retry and resume capability through chunk-based uploads
252
+ - Query parameters and form body fields are properly separated
253
+ - Server returns `upload_id`, `chunks_total`, and `chunks_uploaded` for progress tracking
254
+
255
+ **How Chunked Upload Works:**
256
+ 1. SDK splits large files into 5MB chunks
257
+ 2. Each chunk is sent with a `Content-Range` header (e.g., `bytes 0-5242879/10485760`)
258
+ 3. Backend stores chunks temporarily in Redis with 1-hour expiration
259
+ 4. Backend tracks upload progress and returns `upload_id` for subsequent chunks
260
+ 5. When all chunks are received, backend assembles them and creates the video
261
+ 6. Chunks are automatically cleaned up from Redis after successful assembly
262
+
263
+ #### Delete a Video
264
+
265
+ ```javascript
266
+ const { Publish } = require('@eveai/eve-sdk-for-node');
267
+
268
+ const publish = new Publish(client);
269
+
270
+ try {
271
+ const response = await publish.deleteVideo(
272
+ 123, // actorId (must be video owner)
273
+ 456, // videoId
274
+ 'token' // Authentication token
275
+ );
276
+ console.log('Video deleted:', response);
277
+ } catch (error) {
278
+ console.error('Failed to delete video:', error);
279
+ }
280
+ ```
281
+
282
+ ### Comments
283
+
284
+ ```javascript
285
+ const { CommentService } = require('@eveai/eve-sdk-for-node');
286
+
287
+ const commentService = new CommentService(client);
288
+
289
+ // Add a comment
290
+ try {
291
+ const comment = await commentService.addComment(
292
+ 456, // videoId
293
+ 123, // actorId
294
+ 'token', // Authentication token
295
+ 'Great video!' // Comment text
296
+ );
297
+ console.log('Comment added:', comment);
298
+ } catch (error) {
299
+ console.error('Failed to add comment:', error);
300
+ }
301
+
302
+ // List comments
303
+ try {
304
+ const comments = await commentService.listComments(456, 123, 'token');
305
+ console.log('Comments:', comments.comment_list);
306
+ } catch (error) {
307
+ console.error('Failed to list comments:', error);
308
+ }
309
+ ```
310
+
311
+ ### Favorites
312
+
313
+ ```javascript
314
+ const { Favorite } = require('@eveai/eve-sdk-for-node');
315
+
316
+ const favorite = new Favorite(client);
317
+
318
+ // Like a video
319
+ try {
320
+ await favorite.likeVideo(456, 123, 'token');
321
+ console.log('Video liked');
322
+ } catch (error) {
323
+ console.error('Failed to like video:', error);
324
+ }
325
+
326
+ // List favorite videos
327
+ try {
328
+ const favorites = await favorite.listFavorites(123, 123, 'token');
329
+ console.log('Favorite videos:', favorites.video_list);
330
+ } catch (error) {
331
+ console.error('Failed to list favorites:', error);
332
+ }
333
+ ```
334
+
335
+ ### Relations (Follow/Unfollow)
336
+
337
+ ```javascript
338
+ const { Relation } = require('@eveai/eve-sdk-for-node');
339
+
340
+ const relation = new Relation(client);
341
+
342
+ // Follow a user
343
+ try {
344
+ await relation.follow(789, 123, 'token');
345
+ console.log('User followed');
346
+ } catch (error) {
347
+ console.error('Failed to follow user:', error);
348
+ }
349
+
350
+ // Get followers
351
+ try {
352
+ const followers = await relation.getFollowerList(123, 123, 'token');
353
+ console.log('Followers:', followers.user_list);
354
+ } catch (error) {
355
+ console.error('Failed to get followers:', error);
356
+ }
357
+
358
+ // Check if following
359
+ try {
360
+ const isFollowing = await relation.isFollowing(789, 123, 'token');
361
+ console.log('Is following:', isFollowing.result);
362
+ } catch (error) {
363
+ console.error('Failed to check follow status:', error);
364
+ }
365
+ ```
366
+
367
+ ### Messaging
368
+
369
+ ```javascript
370
+ const { MessageService } = require('@eveai/eve-sdk-for-node');
371
+
372
+ const messageService = new MessageService(client);
373
+
374
+ // Send a message
375
+ try {
376
+ await messageService.sendMessage(
377
+ 789, // toUserId
378
+ 123, // actorId
379
+ 'token', // Authentication token
380
+ 'Hello there!' // Message content
381
+ );
382
+ console.log('Message sent');
383
+ } catch (error) {
384
+ console.error('Failed to send message:', error);
385
+ }
386
+
387
+ // List messages
388
+ try {
389
+ const messages = await messageService.listMessages(789, 123, 'token');
390
+ console.log('Messages:', messages.message_list);
391
+ } catch (error) {
392
+ console.error('Failed to list messages:', error);
393
+ }
394
+ ```
395
+
396
+ ### File Storage
397
+
398
+ Upload images directly to Eve.AI storage:
399
+
400
+ ```javascript
401
+ const { GuGoTikStorage } = require('@eveai/eve-sdk-for-node');
402
+ const fs = require('fs');
403
+
404
+ const storage = new GuGoTikStorage(client);
405
+
406
+ try {
407
+ const imageData = fs.readFileSync('avatar.jpg');
408
+
409
+ const response = await storage.uploadFile(imageData);
410
+ console.log('File uploaded:', response.file_url);
411
+ // Use the file_url for user avatar, background image, etc.
412
+ } catch (error) {
413
+ console.error('Failed to upload file:', error);
414
+ }
415
+ ```
416
+
417
+ ## Error Handling
418
+
419
+ The SDK raises `AppwriteException` with `message`, `code`, `type`, and `response` properties. Handle errors appropriately:
420
+
421
+ ```javascript
422
+ const { Auth, AppwriteException } = require('@eveai/eve-sdk-for-node');
423
+
424
+ const auth = new Auth(client);
425
+
426
+ try {
427
+ const response = await auth.login('username', 'password');
428
+ console.log('Login successful:', response);
429
+ } catch (error) {
430
+ if (error instanceof AppwriteException) {
431
+ console.error('Error code:', error.code);
432
+ console.error('Error message:', error.message);
433
+ console.error('Error response:', error.response);
434
+ } else {
435
+ console.error('Unexpected error:', error);
436
+ }
437
+ }
438
+ ```
439
+
440
+ ## TypeScript Support
441
+
442
+ The SDK is written in TypeScript and includes full type definitions:
443
+
444
+ ```typescript
445
+ import { Client, Auth, Feed, Video, User } from '@eveai/eve-sdk-for-node';
446
+
447
+ const client = new Client()
448
+ .setEndpoint('https://api.eve.ai');
449
+
450
+ const auth = new Auth(client);
451
+ const feed = new Feed(client);
452
+
453
+ // Full type safety
454
+ const loginResponse = await auth.login('username', 'password');
455
+ const videos = await feed.listVideos();
456
+
457
+ videos.video_list?.forEach((video: Video) => {
458
+ console.log(`Video: ${video.title} by ${video.author.name}`);
459
+ });
460
+ ```
461
+
462
+ ## API Reference
463
+
464
+ ### Services
465
+
466
+ - **Auth** - User authentication (login, register)
467
+ - **UserService** - User management (get user info, update profile)
468
+ - **Feed** - Video feed (list videos, get video by ID)
469
+ - **Publish** - Video publishing (publish video, delete video, list published videos)
470
+ - **CommentService** - Comment management
471
+ - **Favorite** - Like/favorite videos
472
+ - **Relation** - Follow/unfollow users
473
+ - **MessageService** - Direct messaging
474
+ - **GuGoTikStorage** - File storage (upload images)
475
+
476
+ For detailed API documentation, see the [Eve.AI Backend Documentation](https://github.com/EveAGI/backend).
477
+
478
+ ## Learn More
479
+
480
+ - 📖 [Eve.AI SDK for Node.js Repository](https://github.com/EveAGI/@eveai/eve-sdk-for-node)
481
+ - 🏗️ [Architecture Documentation](https://github.com/EveAGI/backend/blob/main/README.md)
482
+ - 🐛 [Report Issues](https://github.com/EveAGI/backend/issues)
483
+
484
+ ## Contribution
485
+
486
+ Contributions are welcome! Please feel free to submit a Pull Request.
487
+
488
+ ## License
489
+
490
+ Please see the [BSD-3-Clause license](LICENSE) file for more information.
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@eveai/eve-sdk-for-node",
3
+ "homepage": "https://github.com/EveAGI/eve-sdk-for-node",
4
+ "description": "Eve.AI Node.js SDK - Artificial General Intelligence Platform SDK for Node.js applications",
5
+ "version": "0.0.1",
6
+ "license": "BSD-3-Clause",
7
+ "main": "dist/index.js",
8
+ "type": "commonjs",
9
+ "scripts": {
10
+ "build": "tsup"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "import": {
15
+ "types": "./dist/index.d.mts",
16
+ "default": "./dist/index.mjs"
17
+ },
18
+ "require": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ }
22
+ },
23
+ "./file": {
24
+ "import": {
25
+ "types": "./dist/inputFile.d.mts",
26
+ "default": "./dist/inputFile.mjs"
27
+ },
28
+ "require": {
29
+ "types": "./dist/inputFile.d.ts",
30
+ "default": "./dist/inputFile.js"
31
+ }
32
+ }
33
+ },
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "module": "dist/index.mjs",
38
+ "types": "dist/index.d.ts",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/EveAGI/eve-sdk-for-node.git"
42
+ },
43
+ "keywords": [
44
+ "eve",
45
+ "video",
46
+ "social",
47
+ "microservices",
48
+ "sdk",
49
+ "nodejs",
50
+ "typescript"
51
+ ],
52
+ "devDependencies": {
53
+ "@types/node": "20.11.25",
54
+ "tsup": "7.2.0",
55
+ "esbuild-plugin-file-path-extensions": "^2.0.0",
56
+ "tslib": "2.6.2",
57
+ "typescript": "5.4.2"
58
+ },
59
+ "dependencies": {
60
+ "node-fetch-native-with-agent": "1.7.2"
61
+ }
62
+ }