@foru-ms/sdk 1.2.8 → 1.3.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/README.md +16 -9
- package/dist/resources/Auth.d.ts +2 -2
- package/dist/resources/Auth.js +5 -1
- package/dist/resources/Notifications.d.ts +3 -3
- package/dist/resources/Notifications.js +2 -2
- package/dist/resources/PrivateMessages.d.ts +1 -1
- package/dist/resources/Reports.d.ts +4 -4
- package/dist/resources/Reports.js +2 -2
- package/dist/types.d.ts +7 -3
- package/examples/authentication.ts +5 -5
- package/package.json +1 -1
- package/src/resources/Auth.ts +9 -3
- package/src/resources/Notifications.ts +4 -4
- package/src/resources/PrivateMessages.ts +1 -1
- package/src/resources/Reports.ts +5 -5
- package/src/types.ts +8 -3
package/README.md
CHANGED
|
@@ -201,7 +201,7 @@ Check the `/examples` directory for detailed examples:
|
|
|
201
201
|
### Auth (`client.auth`)
|
|
202
202
|
|
|
203
203
|
* `login(payload: { login: string; password: string })`: Login a user. Returns `{ token: string }`.
|
|
204
|
-
* `register(payload: RegisterPayload)`: Register a new user.
|
|
204
|
+
* `register(payload: RegisterPayload)`: Register a new user. Returns `{ user: User, token: string }`. Token is automatically set on the client.
|
|
205
205
|
* `me()`: Get specific details of the currently authenticated user.
|
|
206
206
|
* `forgotPassword(email: string)`: Initiate password reset flow.
|
|
207
207
|
* `resetPassword(payload: { password: string; oldPassword?: string; email?: string; token?: string })`: Reset password using token or old password.
|
|
@@ -301,12 +301,12 @@ Check the `/examples` directory for detailed examples:
|
|
|
301
301
|
|
|
302
302
|
### Notifications (`client.notifications`)
|
|
303
303
|
|
|
304
|
-
* `list(params?: { userId?: string;
|
|
304
|
+
* `list(params?: { userId?: string; status?: string; filter?: 'newest' | 'oldest'; cursor?: string; limit?: number })`: List notifications for a user. `limit` controls page size (1-50, default: 15).
|
|
305
305
|
* `create(payload: { threadId?: string; postId?: string; privateMessageId?: string; notifierId?: string; notifiedId: string; type: string; description?: string; extendedData?: Record<string, any> })`: Create a notification manually.
|
|
306
306
|
* `retrieve(id: string, userId?: string)`: Get a notification by ID.
|
|
307
|
-
* `update(id: string, payload: { userId?: string;
|
|
307
|
+
* `update(id: string, payload: { userId?: string; status: string })`: Update a notification's status.
|
|
308
308
|
* `delete(id: string, userId?: string)`: Delete a notification.
|
|
309
|
-
* `markAllAsRead(userId?: string,
|
|
309
|
+
* `markAllAsRead(userId?: string, status?: string)`: Bulk update status for all of a user's notifications. Default status is `'read'`.
|
|
310
310
|
|
|
311
311
|
### Search (`client.search`)
|
|
312
312
|
|
|
@@ -343,17 +343,17 @@ Check the `/examples` directory for detailed examples:
|
|
|
343
343
|
* `create(payload: { title?: string; body: string; recipientId: string; senderId?: string; extendedData?: Record<string, any> })`: Send a new private message.
|
|
344
344
|
* `retrieve(id: string, userId?: string)`: Get a message by ID.
|
|
345
345
|
* `reply(id: string, payload: { body: string; senderId?: string; title?: string; extendedData?: Record<string, any> })`: Reply to a message thread.
|
|
346
|
-
* `update(id: string, payload: { body?: string; extendedData?: Record<string, any> })`: Update a message (only sender can update).
|
|
346
|
+
* `update(id: string, payload: { status?: string; body?: string; extendedData?: Record<string, any> })`: Update a message (only sender can update).
|
|
347
347
|
* `delete(id: string)`: Delete a message (participants can delete).
|
|
348
348
|
|
|
349
349
|
### Reports (`client.reports`)
|
|
350
350
|
|
|
351
|
-
* `list(params?: { reporterId?: string; reportedId?: string;
|
|
351
|
+
* `list(params?: { reporterId?: string; reportedId?: string; status?: string; cursor?: string; filter?: 'newest' | 'oldest'; limit?: number })`: List reports with filtering options. `limit` controls page size (1-50, default: 15).
|
|
352
352
|
* `create(payload: { reporterId?: string; reportedId?: string; threadId?: string; postId?: string; privateMessageId?: string; type?: string; description?: string; extendedData?: Record<string, any> })`: Submit a new report.
|
|
353
353
|
* `retrieve(id: string)`: Get a report by ID.
|
|
354
|
-
* `update(id: string, payload: { threadId?: string; postId?: string; privateMessageId?: string; reportedId?: string; reporterId?: string; type?: string; description?: string;
|
|
355
|
-
* `updateStatus(id: string,
|
|
356
|
-
* `batchUpdate(payload: { reportIds: string[];
|
|
354
|
+
* `update(id: string, payload: { threadId?: string; postId?: string; privateMessageId?: string; reportedId?: string; reporterId?: string; type?: string; description?: string; status?: string; extendedData?: Record<string, any> })`: Update report details (full update).
|
|
355
|
+
* `updateStatus(id: string, status: string)`: Update status of a report (partial update).
|
|
356
|
+
* `batchUpdate(payload: { reportIds: string[]; status: string })`: Bulk update status for multiple reports.
|
|
357
357
|
* `delete(id: string)`: Delete a report.
|
|
358
358
|
|
|
359
359
|
### Roles (`client.roles`)
|
|
@@ -382,6 +382,7 @@ import {
|
|
|
382
382
|
RegisterPayload,
|
|
383
383
|
User,
|
|
384
384
|
LoginResponse,
|
|
385
|
+
RegisterResponse,
|
|
385
386
|
SecurityInfo,
|
|
386
387
|
|
|
387
388
|
// Thread Types
|
|
@@ -552,6 +553,12 @@ We welcome contributions! Please see our contributing guidelines for more inform
|
|
|
552
553
|
|
|
553
554
|
## Changelog
|
|
554
555
|
|
|
556
|
+
### v1.3.1
|
|
557
|
+
- Updated Notifications, PrivateMessages, Reports to use `status` (string) instead of `read` (boolean)
|
|
558
|
+
|
|
559
|
+
### v1.3.0
|
|
560
|
+
- Added Auth resource, authentication example, and related types
|
|
561
|
+
|
|
555
562
|
### v1.2.8
|
|
556
563
|
- Added Poll resource for poll management
|
|
557
564
|
|
package/dist/resources/Auth.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ForumClient } from '../Client';
|
|
2
|
-
import { LoginResponse } from '../types';
|
|
2
|
+
import { LoginResponse, RegisterResponse } from '../types';
|
|
3
3
|
export declare class AuthResource {
|
|
4
4
|
private client;
|
|
5
5
|
constructor(client: ForumClient);
|
|
@@ -7,7 +7,7 @@ export declare class AuthResource {
|
|
|
7
7
|
login: string;
|
|
8
8
|
password: string;
|
|
9
9
|
}): Promise<LoginResponse>;
|
|
10
|
-
register(payload: import('../types').RegisterPayload): Promise<
|
|
10
|
+
register(payload: import('../types').RegisterPayload): Promise<RegisterResponse>;
|
|
11
11
|
me(): Promise<import('../types').User>;
|
|
12
12
|
forgotPassword(email: string): Promise<{
|
|
13
13
|
resetToken?: string;
|
package/dist/resources/Auth.js
CHANGED
|
@@ -16,10 +16,14 @@ class AuthResource {
|
|
|
16
16
|
return response;
|
|
17
17
|
}
|
|
18
18
|
async register(payload) {
|
|
19
|
-
|
|
19
|
+
const response = await this.client.request('/auth/register', {
|
|
20
20
|
method: 'POST',
|
|
21
21
|
body: JSON.stringify(payload),
|
|
22
22
|
});
|
|
23
|
+
if (response.token) {
|
|
24
|
+
this.client.setToken(response.token);
|
|
25
|
+
}
|
|
26
|
+
return response;
|
|
23
27
|
}
|
|
24
28
|
async me() {
|
|
25
29
|
return this.client.request('/auth/me', {
|
|
@@ -5,17 +5,17 @@ export declare class NotificationsResource {
|
|
|
5
5
|
constructor(client: ForumClient);
|
|
6
6
|
list(params?: {
|
|
7
7
|
userId?: string;
|
|
8
|
-
|
|
8
|
+
status?: string;
|
|
9
9
|
filter?: 'newest' | 'oldest';
|
|
10
10
|
cursor?: string;
|
|
11
11
|
limit?: number;
|
|
12
12
|
}): Promise<NotificationListResponse>;
|
|
13
|
-
markAllAsRead(userId?: string,
|
|
13
|
+
markAllAsRead(userId?: string, status?: string): Promise<{
|
|
14
14
|
count: number;
|
|
15
15
|
}>;
|
|
16
16
|
retrieve(id: string): Promise<Notification>;
|
|
17
17
|
update(id: string, payload: {
|
|
18
|
-
|
|
18
|
+
status: string;
|
|
19
19
|
}): Promise<Notification>;
|
|
20
20
|
delete(id: string): Promise<Notification & {
|
|
21
21
|
deleted: boolean;
|
|
@@ -18,10 +18,10 @@ class NotificationsResource {
|
|
|
18
18
|
method: 'GET',
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
async markAllAsRead(userId,
|
|
21
|
+
async markAllAsRead(userId, status = 'read') {
|
|
22
22
|
return this.client.request('/notifications', {
|
|
23
23
|
method: 'PATCH',
|
|
24
|
-
body: JSON.stringify({ userId,
|
|
24
|
+
body: JSON.stringify({ userId, status }),
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
async retrieve(id) {
|
|
@@ -25,7 +25,7 @@ export declare class PrivateMessagesResource {
|
|
|
25
25
|
extendedData?: Record<string, any>;
|
|
26
26
|
}): Promise<PrivateMessage>;
|
|
27
27
|
update(id: string, payload: {
|
|
28
|
-
|
|
28
|
+
status?: string;
|
|
29
29
|
extendedData?: Record<string, any>;
|
|
30
30
|
}): Promise<PrivateMessage>;
|
|
31
31
|
delete(id: string): Promise<PrivateMessage & {
|
|
@@ -6,7 +6,7 @@ export declare class ReportsResource {
|
|
|
6
6
|
list(params?: {
|
|
7
7
|
reporterId?: string;
|
|
8
8
|
reportedId?: string;
|
|
9
|
-
|
|
9
|
+
status?: string;
|
|
10
10
|
cursor?: string;
|
|
11
11
|
filter?: 'newest' | 'oldest';
|
|
12
12
|
limit?: number;
|
|
@@ -23,7 +23,7 @@ export declare class ReportsResource {
|
|
|
23
23
|
}): Promise<Report>;
|
|
24
24
|
batchUpdate(payload: {
|
|
25
25
|
reportIds: string[];
|
|
26
|
-
|
|
26
|
+
status: string;
|
|
27
27
|
}): Promise<{
|
|
28
28
|
count?: number;
|
|
29
29
|
message?: string;
|
|
@@ -37,11 +37,11 @@ export declare class ReportsResource {
|
|
|
37
37
|
reporterId?: string;
|
|
38
38
|
type?: string;
|
|
39
39
|
description?: string;
|
|
40
|
-
|
|
40
|
+
status?: string;
|
|
41
41
|
extendedData?: Record<string, any>;
|
|
42
42
|
}): Promise<Report>;
|
|
43
43
|
delete(id: string): Promise<Report & {
|
|
44
44
|
deleted: boolean;
|
|
45
45
|
}>;
|
|
46
|
-
updateStatus(id: string,
|
|
46
|
+
updateStatus(id: string, status: string): Promise<Report>;
|
|
47
47
|
}
|
|
@@ -46,10 +46,10 @@ class ReportsResource {
|
|
|
46
46
|
method: 'DELETE',
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
async updateStatus(id,
|
|
49
|
+
async updateStatus(id, status) {
|
|
50
50
|
return this.client.request(`/report/${id}`, {
|
|
51
51
|
method: 'PATCH',
|
|
52
|
-
body: JSON.stringify({
|
|
52
|
+
body: JSON.stringify({ status }),
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -113,6 +113,10 @@ export interface PostListResponse {
|
|
|
113
113
|
export interface LoginResponse {
|
|
114
114
|
token: string;
|
|
115
115
|
}
|
|
116
|
+
export interface RegisterResponse {
|
|
117
|
+
user: User;
|
|
118
|
+
token: string;
|
|
119
|
+
}
|
|
116
120
|
export interface SecurityInfo {
|
|
117
121
|
userId: string;
|
|
118
122
|
username: string;
|
|
@@ -156,7 +160,7 @@ export interface Notification {
|
|
|
156
160
|
notifiedId: string;
|
|
157
161
|
type: string;
|
|
158
162
|
description?: string;
|
|
159
|
-
|
|
163
|
+
status: string;
|
|
160
164
|
createdAt: string;
|
|
161
165
|
extendedData?: Record<string, any>;
|
|
162
166
|
post?: Post;
|
|
@@ -233,7 +237,7 @@ export interface PrivateMessage {
|
|
|
233
237
|
recipientId: string;
|
|
234
238
|
title?: string;
|
|
235
239
|
body: string;
|
|
236
|
-
|
|
240
|
+
status: string;
|
|
237
241
|
parentId?: string;
|
|
238
242
|
children?: PrivateMessage[];
|
|
239
243
|
sender?: User;
|
|
@@ -256,7 +260,7 @@ export interface Report {
|
|
|
256
260
|
privateMessageId?: string;
|
|
257
261
|
type: string;
|
|
258
262
|
description?: string;
|
|
259
|
-
|
|
263
|
+
status: string;
|
|
260
264
|
createdAt: string;
|
|
261
265
|
post?: Post;
|
|
262
266
|
thread?: Thread;
|
|
@@ -14,13 +14,15 @@ async function main() {
|
|
|
14
14
|
try {
|
|
15
15
|
// Example 1: User Registration
|
|
16
16
|
console.log('=== User Registration ===');
|
|
17
|
-
const
|
|
17
|
+
const { user, token } = await client.auth.register({
|
|
18
18
|
username: 'john_doe',
|
|
19
19
|
email: 'john@example.com',
|
|
20
20
|
password: 'securePassword123',
|
|
21
21
|
displayName: 'John Doe',
|
|
22
22
|
});
|
|
23
|
-
console.log('User registered:',
|
|
23
|
+
console.log('User registered:', user);
|
|
24
|
+
console.log('Auth token:', token);
|
|
25
|
+
// Note: Token is automatically set on the client
|
|
24
26
|
|
|
25
27
|
// Example 2: User Login
|
|
26
28
|
console.log('\n=== User Login ===');
|
|
@@ -29,9 +31,7 @@ async function main() {
|
|
|
29
31
|
password: 'securePassword123',
|
|
30
32
|
});
|
|
31
33
|
console.log('Login successful, token:', loginResponse.token);
|
|
32
|
-
|
|
33
|
-
// Store the token for authenticated requests
|
|
34
|
-
client.setToken(loginResponse.token);
|
|
34
|
+
// Note: Token is automatically set on the client
|
|
35
35
|
|
|
36
36
|
// Example 3: Get Current User
|
|
37
37
|
console.log('\n=== Get Current User ===');
|
package/package.json
CHANGED
package/src/resources/Auth.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ForumClient } from '../Client';
|
|
2
|
-
import { LoginResponse } from '../types';
|
|
2
|
+
import { LoginResponse, RegisterResponse } from '../types';
|
|
3
3
|
|
|
4
4
|
export class AuthResource {
|
|
5
5
|
private client: ForumClient;
|
|
@@ -21,11 +21,17 @@ export class AuthResource {
|
|
|
21
21
|
return response;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async register(payload: import('../types').RegisterPayload): Promise<
|
|
25
|
-
|
|
24
|
+
async register(payload: import('../types').RegisterPayload): Promise<RegisterResponse> {
|
|
25
|
+
const response = await this.client.request<RegisterResponse>('/auth/register', {
|
|
26
26
|
method: 'POST',
|
|
27
27
|
body: JSON.stringify(payload),
|
|
28
28
|
});
|
|
29
|
+
|
|
30
|
+
if (response.token) {
|
|
31
|
+
this.client.setToken(response.token);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return response;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
async me(): Promise<import('../types').User> {
|
|
@@ -10,7 +10,7 @@ export class NotificationsResource {
|
|
|
10
10
|
|
|
11
11
|
async list(params?: {
|
|
12
12
|
userId?: string;
|
|
13
|
-
|
|
13
|
+
status?: string;
|
|
14
14
|
filter?: 'newest' | 'oldest';
|
|
15
15
|
cursor?: string;
|
|
16
16
|
limit?: number;
|
|
@@ -29,10 +29,10 @@ export class NotificationsResource {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
async markAllAsRead(userId?: string,
|
|
32
|
+
async markAllAsRead(userId?: string, status: string = 'read'): Promise<{ count: number }> {
|
|
33
33
|
return this.client.request<{ count: number }>('/notifications', {
|
|
34
34
|
method: 'PATCH',
|
|
35
|
-
body: JSON.stringify({ userId,
|
|
35
|
+
body: JSON.stringify({ userId, status }),
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -42,7 +42,7 @@ export class NotificationsResource {
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
async update(id: string, payload: {
|
|
45
|
+
async update(id: string, payload: { status: string }): Promise<Notification> {
|
|
46
46
|
return this.client.request<Notification>(`/notification/${id}`, {
|
|
47
47
|
method: 'PATCH',
|
|
48
48
|
body: JSON.stringify(payload),
|
|
@@ -61,7 +61,7 @@ export class PrivateMessagesResource {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
async update(id: string, payload: {
|
|
64
|
-
|
|
64
|
+
status?: string;
|
|
65
65
|
extendedData?: Record<string, any>;
|
|
66
66
|
}): Promise<PrivateMessage> {
|
|
67
67
|
return this.client.request<PrivateMessage>(`/private-message/${id}`, {
|
package/src/resources/Reports.ts
CHANGED
|
@@ -11,7 +11,7 @@ export class ReportsResource {
|
|
|
11
11
|
async list(params?: {
|
|
12
12
|
reporterId?: string;
|
|
13
13
|
reportedId?: string;
|
|
14
|
-
|
|
14
|
+
status?: string;
|
|
15
15
|
cursor?: string;
|
|
16
16
|
filter?: 'newest' | 'oldest';
|
|
17
17
|
limit?: number;
|
|
@@ -48,7 +48,7 @@ export class ReportsResource {
|
|
|
48
48
|
|
|
49
49
|
async batchUpdate(payload: {
|
|
50
50
|
reportIds: string[];
|
|
51
|
-
|
|
51
|
+
status: string;
|
|
52
52
|
}): Promise<{ count?: number; message?: string }> {
|
|
53
53
|
return this.client.request<{ count?: number; message?: string }>('/reports', {
|
|
54
54
|
method: 'PATCH',
|
|
@@ -70,7 +70,7 @@ export class ReportsResource {
|
|
|
70
70
|
reporterId?: string;
|
|
71
71
|
type?: string;
|
|
72
72
|
description?: string;
|
|
73
|
-
|
|
73
|
+
status?: string;
|
|
74
74
|
extendedData?: Record<string, any>;
|
|
75
75
|
}): Promise<Report> {
|
|
76
76
|
return this.client.request<Report>(`/report/${id}`, {
|
|
@@ -85,10 +85,10 @@ export class ReportsResource {
|
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
async updateStatus(id: string,
|
|
88
|
+
async updateStatus(id: string, status: string): Promise<Report> {
|
|
89
89
|
return this.client.request<Report>(`/report/${id}`, {
|
|
90
90
|
method: 'PATCH',
|
|
91
|
-
body: JSON.stringify({
|
|
91
|
+
body: JSON.stringify({ status }),
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
}
|
package/src/types.ts
CHANGED
|
@@ -128,6 +128,11 @@ export interface LoginResponse {
|
|
|
128
128
|
token: string;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
export interface RegisterResponse {
|
|
132
|
+
user: User;
|
|
133
|
+
token: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
131
136
|
export interface SecurityInfo {
|
|
132
137
|
userId: string;
|
|
133
138
|
username: string;
|
|
@@ -176,7 +181,7 @@ export interface Notification {
|
|
|
176
181
|
notifiedId: string;
|
|
177
182
|
type: string;
|
|
178
183
|
description?: string;
|
|
179
|
-
|
|
184
|
+
status: string;
|
|
180
185
|
createdAt: string;
|
|
181
186
|
extendedData?: Record<string, any>;
|
|
182
187
|
post?: Post;
|
|
@@ -259,7 +264,7 @@ export interface PrivateMessage {
|
|
|
259
264
|
recipientId: string;
|
|
260
265
|
title?: string;
|
|
261
266
|
body: string;
|
|
262
|
-
|
|
267
|
+
status: string;
|
|
263
268
|
parentId?: string;
|
|
264
269
|
children?: PrivateMessage[];
|
|
265
270
|
sender?: User;
|
|
@@ -284,7 +289,7 @@ export interface Report {
|
|
|
284
289
|
privateMessageId?: string;
|
|
285
290
|
type: string;
|
|
286
291
|
description?: string;
|
|
287
|
-
|
|
292
|
+
status: string;
|
|
288
293
|
createdAt: string;
|
|
289
294
|
post?: Post;
|
|
290
295
|
thread?: Thread;
|