itd-sdk-js 1.0.9 → 1.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/API_REFERENCE.md +132 -28
- package/examples/quick-start.js +2 -5
- package/package.json +1 -1
- package/src/auth.js +42 -5
- package/src/client.js +215 -31
- package/src/comments.js +48 -13
- package/src/files.js +41 -1
- package/src/notifications.js +50 -53
- package/src/posts.js +130 -24
- package/src/reports.js +8 -7
- package/src/users.js +68 -11
- package/src/verification.js +50 -0
package/src/posts.js
CHANGED
|
@@ -230,6 +230,38 @@ export class PostsManager {
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Получает лайкнутые посты пользователя.
|
|
235
|
+
* GET /api/posts/user/{username}/liked → { data: { posts: [], pagination: {} } }
|
|
236
|
+
*
|
|
237
|
+
* @param {string} username - Имя пользователя
|
|
238
|
+
* @param {number} limit - Количество постов (по умолчанию 20)
|
|
239
|
+
* @param {string|null} cursor - Курсор для пагинации (pagination.nextCursor)
|
|
240
|
+
* @returns {Promise<Object>} { posts: [], pagination: { limit, nextCursor, hasMore } }
|
|
241
|
+
*/
|
|
242
|
+
async getLikedPosts(username, limit = 20, cursor = null) {
|
|
243
|
+
try {
|
|
244
|
+
const url = `${this.client.baseUrl}/api/posts/user/${encodeURIComponent(username)}/liked`;
|
|
245
|
+
const params = { limit };
|
|
246
|
+
if (cursor) params.cursor = cursor;
|
|
247
|
+
|
|
248
|
+
const response = await this.axios.get(url, { params });
|
|
249
|
+
|
|
250
|
+
if (response.status === 200) {
|
|
251
|
+
const data = response.data;
|
|
252
|
+
const inner = data?.data ?? data;
|
|
253
|
+
return {
|
|
254
|
+
posts: inner?.posts || [],
|
|
255
|
+
pagination: inner?.pagination || {}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return { posts: [], pagination: {} };
|
|
259
|
+
} catch (error) {
|
|
260
|
+
console.error('Ошибка получения лайкнутых постов:', error.message);
|
|
261
|
+
return { posts: [], pagination: {} };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
233
265
|
/**
|
|
234
266
|
* Получает популярные посты (лента популярного)
|
|
235
267
|
*
|
|
@@ -257,6 +289,52 @@ export class PostsManager {
|
|
|
257
289
|
}
|
|
258
290
|
|
|
259
291
|
|
|
292
|
+
/**
|
|
293
|
+
* Отмечает пост как просмотренный. POST /api/posts/{id}/view
|
|
294
|
+
*
|
|
295
|
+
* @param {string} postId - ID поста
|
|
296
|
+
* @returns {Promise<boolean>} True если успешно
|
|
297
|
+
*/
|
|
298
|
+
async viewPost(postId) {
|
|
299
|
+
if (!await this.client.auth.checkAuth()) return false;
|
|
300
|
+
try {
|
|
301
|
+
const url = `${this.client.baseUrl}/api/posts/${postId}/view`;
|
|
302
|
+
const response = await this.axios.post(url);
|
|
303
|
+
return response.status === 200 || response.status === 201 || response.status === 204;
|
|
304
|
+
} catch (error) {
|
|
305
|
+
console.error('Исключение при отметке просмотра:', error.message);
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Получает посты на стене пользователя. GET /api/posts/user/{username}/wall
|
|
312
|
+
*
|
|
313
|
+
* @param {string} username - Имя пользователя
|
|
314
|
+
* @param {number} limit - Количество
|
|
315
|
+
* @param {string|null} cursor - Курсор пагинации
|
|
316
|
+
* @returns {Promise<Object>} { posts: [], pagination: {} }
|
|
317
|
+
*/
|
|
318
|
+
async getWallByUser(username, limit = 20, cursor = null) {
|
|
319
|
+
try {
|
|
320
|
+
const url = `${this.client.baseUrl}/api/posts/user/${encodeURIComponent(username)}/wall`;
|
|
321
|
+
const params = { limit };
|
|
322
|
+
if (cursor) params.cursor = cursor;
|
|
323
|
+
const response = await this.axios.get(url, { params });
|
|
324
|
+
if (response.status === 200) {
|
|
325
|
+
const data = response.data?.data ?? response.data;
|
|
326
|
+
return {
|
|
327
|
+
posts: data?.posts || [],
|
|
328
|
+
pagination: data?.pagination || {}
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
return { posts: [], pagination: {} };
|
|
332
|
+
} catch (error) {
|
|
333
|
+
console.error('Ошибка получения постов со стены:', error.message);
|
|
334
|
+
return { posts: [], pagination: {} };
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
260
338
|
/**
|
|
261
339
|
* Получает конкретный пост по ID
|
|
262
340
|
*
|
|
@@ -348,26 +426,40 @@ export class PostsManager {
|
|
|
348
426
|
|
|
349
427
|
if (response.status === 200 || response.status === 204) {
|
|
350
428
|
return true;
|
|
351
|
-
} else {
|
|
352
|
-
console.error(`Ошибка удаления поста: ${response.status}`);
|
|
353
|
-
if (response.data) {
|
|
354
|
-
console.error('Response data:', response.data);
|
|
355
|
-
}
|
|
356
|
-
return false;
|
|
357
429
|
}
|
|
430
|
+
return false;
|
|
358
431
|
} catch (error) {
|
|
359
432
|
console.error('Исключение при удалении поста:', error.message);
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Восстанавливает удалённый пост.
|
|
439
|
+
* POST /api/posts/{id}/restore — пустой ответ при успехе
|
|
440
|
+
*
|
|
441
|
+
* @param {string} postId - ID поста
|
|
442
|
+
* @returns {Promise<boolean>} True если успешно
|
|
443
|
+
*/
|
|
444
|
+
async restorePost(postId) {
|
|
445
|
+
if (!await this.client.auth.checkAuth()) {
|
|
446
|
+
console.error('Ошибка: необходимо войти в аккаунт');
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
449
|
+
try {
|
|
450
|
+
const url = `${this.client.baseUrl}/api/posts/${postId}/restore`;
|
|
451
|
+
const response = await this.axios.post(url);
|
|
452
|
+
return response.status === 200 || response.status === 201 || response.status === 204;
|
|
453
|
+
} catch (error) {
|
|
454
|
+
console.error('Исключение при восстановлении поста:', error.message);
|
|
364
455
|
return false;
|
|
365
456
|
}
|
|
366
457
|
}
|
|
367
458
|
|
|
368
459
|
/**
|
|
369
|
-
* Закрепляет
|
|
370
|
-
*
|
|
460
|
+
* Закрепляет пост.
|
|
461
|
+
* POST /api/posts/{id}/pin → { success: true, pinnedPostId }
|
|
462
|
+
*
|
|
371
463
|
* @param {string} postId - ID поста
|
|
372
464
|
* @returns {Promise<boolean>} True если успешно
|
|
373
465
|
*/
|
|
@@ -376,27 +468,41 @@ export class PostsManager {
|
|
|
376
468
|
console.error('Ошибка: необходимо войти в аккаунт');
|
|
377
469
|
return false;
|
|
378
470
|
}
|
|
379
|
-
|
|
380
471
|
try {
|
|
381
472
|
const pinUrl = `${this.client.baseUrl}/api/posts/${postId}/pin`;
|
|
382
473
|
const response = await this.axios.post(pinUrl);
|
|
383
|
-
|
|
384
474
|
if (response.status === 200 || response.status === 201) {
|
|
385
|
-
return
|
|
386
|
-
} else {
|
|
387
|
-
console.error(`Ошибка закрепления поста: ${response.status}`);
|
|
388
|
-
if (response.data) {
|
|
389
|
-
console.error('Response data:', response.data);
|
|
390
|
-
}
|
|
391
|
-
return false;
|
|
475
|
+
return response.data?.success !== false;
|
|
392
476
|
}
|
|
477
|
+
return false;
|
|
393
478
|
} catch (error) {
|
|
394
479
|
console.error('Исключение при закреплении поста:', error.message);
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Открепляет пост.
|
|
486
|
+
* DELETE /api/posts/{id}/pin → { success: true, pinnedPostId: null }
|
|
487
|
+
*
|
|
488
|
+
* @param {string} postId - ID поста
|
|
489
|
+
* @returns {Promise<boolean>} True если успешно
|
|
490
|
+
*/
|
|
491
|
+
async unpinPost(postId) {
|
|
492
|
+
if (!await this.client.auth.checkAuth()) {
|
|
493
|
+
console.error('Ошибка: необходимо войти в аккаунт');
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
try {
|
|
497
|
+
const pinUrl = `${this.client.baseUrl}/api/posts/${postId}/pin`;
|
|
498
|
+
const response = await this.axios.delete(pinUrl);
|
|
499
|
+
if (response.status === 200 || response.status === 204) {
|
|
500
|
+
return response.data?.success !== false;
|
|
398
501
|
}
|
|
399
502
|
return false;
|
|
503
|
+
} catch (error) {
|
|
504
|
+
console.error('Исключение при откреплении поста:', error.message);
|
|
505
|
+
return false;
|
|
400
506
|
}
|
|
401
507
|
}
|
|
402
508
|
|
package/src/reports.js
CHANGED
|
@@ -8,11 +8,12 @@ export class ReportsManager {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Отправляет репорт на пост, комментарий или
|
|
12
|
-
*
|
|
11
|
+
* Отправляет репорт на пост, комментарий или пользователя.
|
|
12
|
+
* POST /api/reports → { data: { id, createdAt } }
|
|
13
|
+
*
|
|
13
14
|
* @param {string} targetType - Тип цели: "post", "comment", "user"
|
|
14
15
|
* @param {string} targetId - ID цели (поста, комментария или пользователя)
|
|
15
|
-
* @param {string} reason -
|
|
16
|
+
* @param {string} reason - Причина: "spam", "violence", "hate", "adult", "fraud", "other"
|
|
16
17
|
* @param {string} description - Описание проблемы (опционально)
|
|
17
18
|
* @returns {Promise<Object|null>} { id, createdAt } или null при ошибке
|
|
18
19
|
*/
|
|
@@ -61,9 +62,9 @@ export class ReportsManager {
|
|
|
61
62
|
|
|
62
63
|
/**
|
|
63
64
|
* Отправляет репорт на пост
|
|
64
|
-
*
|
|
65
|
+
*
|
|
65
66
|
* @param {string} postId - ID поста
|
|
66
|
-
* @param {string} reason -
|
|
67
|
+
* @param {string} reason - Причина: "spam", "violence", "hate", "adult", "fraud", "other" (по умолчанию "other")
|
|
67
68
|
* @param {string} description - Описание проблемы
|
|
68
69
|
* @returns {Promise<Object|null>} { id, createdAt } или null при ошибке
|
|
69
70
|
*/
|
|
@@ -75,7 +76,7 @@ export class ReportsManager {
|
|
|
75
76
|
* Отправляет репорт на комментарий
|
|
76
77
|
*
|
|
77
78
|
* @param {string} commentId - ID комментария
|
|
78
|
-
* @param {string} reason -
|
|
79
|
+
* @param {string} reason - Причина: "spam", "violence", "hate", "adult", "fraud", "other"
|
|
79
80
|
* @param {string} description - Описание проблемы
|
|
80
81
|
* @returns {Promise<Object|null>} { id, createdAt } или null при ошибке
|
|
81
82
|
*/
|
|
@@ -87,7 +88,7 @@ export class ReportsManager {
|
|
|
87
88
|
* Отправляет репорт на пользователя
|
|
88
89
|
*
|
|
89
90
|
* @param {string} userId - ID пользователя
|
|
90
|
-
* @param {string} reason -
|
|
91
|
+
* @param {string} reason - Причина: "spam", "violence", "hate", "adult", "fraud", "other"
|
|
91
92
|
* @param {string} description - Описание проблемы
|
|
92
93
|
* @returns {Promise<Object|null>} { id, createdAt } или null при ошибке
|
|
93
94
|
*/
|
package/src/users.js
CHANGED
|
@@ -8,13 +8,16 @@ export class UsersManager {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Обновляет
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* Обновляет профиль текущего пользователя.
|
|
12
|
+
* PUT /api/users/me → { id, username, displayName, bio, updatedAt }
|
|
13
|
+
*
|
|
14
|
+
* @param {string|null} bio - Новое описание профиля (опционально)
|
|
14
15
|
* @param {string|null} displayName - Новое отображаемое имя (опционально)
|
|
16
|
+
* @param {string|null} username - Новый username (опционально)
|
|
17
|
+
* @param {string|null} bannerId - ID загруженного баннера (опционально)
|
|
15
18
|
* @returns {Promise<Object|null>} Обновленные данные профиля или null при ошибке
|
|
16
19
|
*/
|
|
17
|
-
async updateProfile(bio, displayName = null) {
|
|
20
|
+
async updateProfile(bio = null, displayName = null, username = null, bannerId = null) {
|
|
18
21
|
if (!await this.client.auth.checkAuth()) {
|
|
19
22
|
console.error('Ошибка: необходимо войти в аккаунт');
|
|
20
23
|
return null;
|
|
@@ -22,19 +25,19 @@ export class UsersManager {
|
|
|
22
25
|
|
|
23
26
|
try {
|
|
24
27
|
const updateUrl = `${this.client.baseUrl}/api/users/me`;
|
|
25
|
-
|
|
26
28
|
const updateData = {};
|
|
27
|
-
if (bio
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
29
|
+
if (bio != null) updateData.bio = bio;
|
|
30
|
+
if (displayName != null) updateData.displayName = displayName;
|
|
31
|
+
if (username != null) updateData.username = username;
|
|
32
|
+
if (bannerId != null) updateData.bannerId = bannerId;
|
|
33
|
+
if (Object.keys(updateData).length === 0) {
|
|
34
|
+
return await this.getMyProfile();
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
const response = await this.axios.put(updateUrl, updateData);
|
|
35
38
|
|
|
36
39
|
if (response.status === 200) {
|
|
37
|
-
return response.data;
|
|
40
|
+
return response.data?.data ?? response.data;
|
|
38
41
|
} else {
|
|
39
42
|
console.error(`Ошибка обновления профиля: ${response.status}`);
|
|
40
43
|
if (response.data) {
|
|
@@ -86,6 +89,60 @@ export class UsersManager {
|
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Получает настройки приватности текущего пользователя.
|
|
94
|
+
* GET /api/users/me/privacy → { isPrivate, wallClosed }
|
|
95
|
+
*
|
|
96
|
+
* @returns {Promise<Object|null>} { isPrivate, wallClosed } или null при ошибке
|
|
97
|
+
*/
|
|
98
|
+
async getPrivacy() {
|
|
99
|
+
if (!await this.client.auth.checkAuth()) {
|
|
100
|
+
console.error('Ошибка: необходимо войти в аккаунт');
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
const url = `${this.client.baseUrl}/api/users/me/privacy`;
|
|
105
|
+
const response = await this.axios.get(url);
|
|
106
|
+
if (response.status === 200) {
|
|
107
|
+
return response.data?.data ?? response.data;
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error('Ошибка получения приватности:', error.message);
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Обновляет настройки приватности.
|
|
118
|
+
* PUT /api/users/me/privacy → { isPrivate, wallClosed }
|
|
119
|
+
*
|
|
120
|
+
* @param {Object} options - { isPrivate?: boolean, wallClosed?: boolean }
|
|
121
|
+
* @returns {Promise<Object|null>} { isPrivate, wallClosed } или null при ошибке
|
|
122
|
+
*/
|
|
123
|
+
async updatePrivacy(options = {}) {
|
|
124
|
+
if (!await this.client.auth.checkAuth()) {
|
|
125
|
+
console.error('Ошибка: необходимо войти в аккаунт');
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
const url = `${this.client.baseUrl}/api/users/me/privacy`;
|
|
130
|
+
const payload = {};
|
|
131
|
+
if (options.isPrivate != null) payload.isPrivate = options.isPrivate;
|
|
132
|
+
if (options.wallClosed != null) payload.wallClosed = options.wallClosed;
|
|
133
|
+
if (Object.keys(payload).length === 0) return await this.getPrivacy();
|
|
134
|
+
|
|
135
|
+
const response = await this.axios.put(url, payload);
|
|
136
|
+
if (response.status === 200) {
|
|
137
|
+
return response.data?.data ?? response.data;
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.error('Ошибка обновления приватности:', error.message);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
89
146
|
/**
|
|
90
147
|
* Получает профиль пользователя по username
|
|
91
148
|
*
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Модуль верификации аккаунта
|
|
3
|
+
*/
|
|
4
|
+
export class VerificationManager {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
this.axios = client.axios;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Получает статус верификации. GET /api/verification/status
|
|
12
|
+
*
|
|
13
|
+
* @returns {Promise<Object|null>} Статус верификации или null
|
|
14
|
+
*/
|
|
15
|
+
async getStatus() {
|
|
16
|
+
if (!await this.client.auth.checkAuth()) return null;
|
|
17
|
+
try {
|
|
18
|
+
const url = `${this.client.baseUrl}/api/verification/status`;
|
|
19
|
+
const response = await this.axios.get(url);
|
|
20
|
+
if (response.status === 200) {
|
|
21
|
+
return response.data?.data ?? response.data;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error('Ошибка получения статуса верификации:', error.message);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Подаёт заявку на верификацию. POST /api/verification/submit
|
|
32
|
+
*
|
|
33
|
+
* @param {string} videoUrl - URL загруженного видео (из uploadFile)
|
|
34
|
+
* @returns {Promise<Object|null>} { success, request: { id, status, ... } } или null
|
|
35
|
+
*/
|
|
36
|
+
async submit(videoUrl) {
|
|
37
|
+
if (!await this.client.auth.checkAuth()) return null;
|
|
38
|
+
try {
|
|
39
|
+
const url = `${this.client.baseUrl}/api/verification/submit`;
|
|
40
|
+
const response = await this.axios.post(url, { videoUrl });
|
|
41
|
+
if (response.status === 200 || response.status === 201) {
|
|
42
|
+
return response.data?.data ?? response.data;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error('Ошибка подачи заявки на верификацию:', error.message);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|