@foru-ms/sdk 0.2.0 → 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/LICENSE +21 -0
- package/README.md +147 -102
- package/package.json +17 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Foru.ms
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
The official JavaScript/TypeScript SDK for [Foru.ms](https://foru.ms). Build powerful community features directly into your application.
|
|
4
4
|
|
|
5
|
+
This SDK is fully typed and provides a comprehensive interface to the Foru.ms API.
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
@@ -12,130 +14,173 @@ yarn add @foru-ms/sdk
|
|
|
12
14
|
pnpm add @foru-ms/sdk
|
|
13
15
|
```
|
|
14
16
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
Initialize the client with your API key. You can find your API key in the Foru.ms dashboard.
|
|
17
|
+
## Setup & Initialization
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
20
|
import { ForumClient } from '@foru-ms/sdk';
|
|
21
21
|
|
|
22
22
|
const client = new ForumClient({
|
|
23
23
|
apiKey: 'your_api_key',
|
|
24
|
-
// baseUrl: 'https://api.foru.ms/v1' // Optional
|
|
25
|
-
});
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Authentication
|
|
29
|
-
|
|
30
|
-
Identify the current user to perform actions on their behalf. Use `authToken` obtained via login or your own auth provider integration.
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
// Login with username/password
|
|
34
|
-
const { token } = await client.auth.login({
|
|
35
|
-
login: 'username',
|
|
36
|
-
password: 'password'
|
|
24
|
+
// baseUrl: 'https://api.foru.ms/v1' // Optional
|
|
37
25
|
});
|
|
38
26
|
|
|
39
|
-
//
|
|
40
|
-
client.setToken(
|
|
41
|
-
|
|
42
|
-
// Get current user details
|
|
43
|
-
const me = await client.auth.me();
|
|
27
|
+
// Set an authentication token (JWT) for user-scoped requests
|
|
28
|
+
client.setToken('user_jwt_token');
|
|
44
29
|
```
|
|
45
30
|
|
|
46
|
-
##
|
|
31
|
+
## API Reference
|
|
32
|
+
|
|
33
|
+
### Auth (`client.auth`)
|
|
34
|
+
|
|
35
|
+
* `login(payload: { login: string; password: string })`: Login a user. Returns `{ token: string }`.
|
|
36
|
+
* `register(payload: RegisterPayload)`: Register a new user.
|
|
37
|
+
* `me()`: Get specific details of the currently authenticated user.
|
|
38
|
+
* `forgotPassword(email: string)`: Initiate password reset flow.
|
|
39
|
+
* `resetPassword(payload: { password: string; oldPassword?: string; email?: string; token?: string })`: Reset password using token or old password.
|
|
40
|
+
|
|
41
|
+
### Threads (`client.threads`)
|
|
42
|
+
|
|
43
|
+
* `list(params: { limit?: number; filter?: 'newest' | 'oldest'; tagId?: string; categoryId?: string; cursor?: string })`: List threads.
|
|
44
|
+
* `create(payload: CreateThreadPayload)`: Create a new thread.
|
|
45
|
+
* `retrieve(id: string)`: Get a thread by ID.
|
|
46
|
+
* `update(id: string, payload: UpdateThreadPayload)`: Update a thread.
|
|
47
|
+
* `delete(id: string)`: Delete a thread.
|
|
48
|
+
* `getPosts(id: string, params: { cursor?: string; filter?: 'newest' | 'oldest' })`: Get posts in a thread.
|
|
49
|
+
* `like(id: string, userId: string, extendedData?: any)`: Like a thread.
|
|
50
|
+
* `unlike(id: string, userId: string)`: Unlike a thread.
|
|
51
|
+
* `dislike(id: string, userId: string, extendedData?: any)`: Dislike a thread.
|
|
52
|
+
* `undislike(id: string, userId: string)`: Remove dislike from a thread.
|
|
53
|
+
* `subscribe(id: string, userId: string)`: Subscribe to a thread.
|
|
54
|
+
* `unsubscribe(id: string, userId: string)`: Unsubscribe from a thread.
|
|
55
|
+
* `vote(id: string, userId: string, optionId: string)`: Vote in a thread poll.
|
|
56
|
+
* `voteUpdate(id: string, userId: string, optionId: string)`: Change vote.
|
|
57
|
+
* `unvote(id: string, userId: string)`: Remove vote.
|
|
58
|
+
|
|
59
|
+
### Posts (`client.posts`)
|
|
60
|
+
|
|
61
|
+
* `list(params: { limit?: number; cursor?: string; filter?: 'newest' | 'oldest'; threadId?: string })`: List posts (flat).
|
|
62
|
+
* `create(payload: CreatePostPayload)`: Create a reply.
|
|
63
|
+
* `retrieve(id: string)`: Get a post by ID.
|
|
64
|
+
* `update(id: string, payload: UpdatePostPayload)`: Update a post.
|
|
65
|
+
* `delete(id: string)`: Delete a post.
|
|
66
|
+
* `getChildren(id: string, params: { cursor?: string; filter?: 'newest' | 'oldest' })`: Get child posts (nested replies).
|
|
67
|
+
* `like(id: string, userId: string, extendedData?: any)`: Like a post.
|
|
68
|
+
* `unlike(id: string, userId: string)`: Unlike a post.
|
|
69
|
+
* `dislike(id: string, userId: string, extendedData?: any)`: Dislike a post.
|
|
70
|
+
* `undislike(id: string, userId: string)`: Remove dislike.
|
|
71
|
+
* `upvote(id: string, userId: string, extendedData?: any)`: Upvote a post.
|
|
72
|
+
* `unupvote(id: string, userId: string)`: Remove upvote.
|
|
73
|
+
* `downvote(id: string, userId: string, extendedData?: any)`: Downvote a post.
|
|
74
|
+
* `undownvote(id: string, userId: string)`: Remove downvote.
|
|
75
|
+
|
|
76
|
+
### Users (`client.users`)
|
|
77
|
+
|
|
78
|
+
* `list(params: { query?: string; filter?: 'newest' | 'oldest'; cursor?: string })`: List users.
|
|
79
|
+
* `retrieve(id: string)`: Get user by ID.
|
|
80
|
+
* `create(payload: any)`: Create a user (Admin).
|
|
81
|
+
* `update(id: string, payload: any)`: Update a user.
|
|
82
|
+
* `delete(id: string)`: Delete a user.
|
|
83
|
+
* `getFollowers(id: string, params: { cursor?: string })`: Get user's followers.
|
|
84
|
+
* `getFollowing(id: string, params: { cursor?: string })`: Get who a user follows.
|
|
85
|
+
* `follow(id: string, followerId: string, extendedData?: any)`: Follow a user.
|
|
86
|
+
* `unfollow(id: string, followerId: string)`: Unfollow a user.
|
|
87
|
+
|
|
88
|
+
### Tags (`client.tags`)
|
|
89
|
+
|
|
90
|
+
* `list(params: { query?: string; cursor?: string })`: List tags.
|
|
91
|
+
* `create(payload: { name: string; description?: string; color?: string; extendedData?: any })`: Create a tag.
|
|
92
|
+
* `retrieve(id: string, params?: { userId?: string })`: Get a tag.
|
|
93
|
+
* `update(id: string, payload: any)`: Update a tag.
|
|
94
|
+
* `delete(id: string)`: Delete a tag.
|
|
95
|
+
* `subscribe(id: string, userId: string)`: Subscribe to a tag.
|
|
96
|
+
* `unsubscribe(id: string, userId: string)`: Unsubscribe from a tag.
|
|
97
|
+
* `listSubscribed(params: { userId: string; cursor?: string })`: List tags a user is subscribed to.
|
|
98
|
+
|
|
99
|
+
### Notifications (`client.notifications`)
|
|
100
|
+
|
|
101
|
+
* `list(params: { userId: string; read?: boolean; filter?: string; cursor?: string })`: List notifications.
|
|
102
|
+
* `markAllAsRead(userId: string, read?: boolean)`: Bulk update read status.
|
|
103
|
+
* `create(payload: any)`: Create a notification manually.
|
|
104
|
+
* `retrieve(id: string)`: Get a notification.
|
|
105
|
+
* `update(id: string, payload: { read: boolean })`: Update a notification.
|
|
106
|
+
* `delete(id: string)`: Delete a notification.
|
|
107
|
+
|
|
108
|
+
### Search (`client.search`)
|
|
109
|
+
|
|
110
|
+
* `search(params: { query: string; type: 'threads' | 'posts' | 'users' | 'tags'; cursor?: string })`: Polymorphic search.
|
|
111
|
+
|
|
112
|
+
### Webhooks (`client.webhooks`)
|
|
113
|
+
|
|
114
|
+
* `list()`: List webhooks.
|
|
115
|
+
* `create(payload: { name: string; url: string; events: string[] })`: Create a webhook.
|
|
116
|
+
* `retrieve(id: string)`: Get a webhook.
|
|
117
|
+
* `update(id: string, payload: any)`: Update a webhook.
|
|
118
|
+
* `delete(id: string)`: Delete a webhook.
|
|
119
|
+
* `getDeliveries(id: string, params: { cursor?: string })`: Get webhook delivery history.
|
|
120
|
+
|
|
121
|
+
### Stats (`client.stats`)
|
|
122
|
+
|
|
123
|
+
* `get(params?: { filter?: string; threadCursor?: string; postCursor?: string; ... })`: Get instance statistics.
|
|
124
|
+
|
|
125
|
+
### Integrations (`client.integrations`)
|
|
126
|
+
|
|
127
|
+
* `list()`: Get all configured integrations.
|
|
128
|
+
* `create(payload: { type: string; name: string; config: any })`: Configure an integration (Slack, Discord, etc.).
|
|
129
|
+
* `retrieve(id: string)`: Get integration details.
|
|
130
|
+
* `delete(id: string)`: Remove an integration.
|
|
131
|
+
|
|
132
|
+
### Private Messages (`client.privateMessages`)
|
|
133
|
+
|
|
134
|
+
* `list(params: { userId?: string; cursor?: string })`: List private messages.
|
|
135
|
+
* `create(payload: { title?: string; body: string; recipientId: string; senderId?: string })`: Send a direct message.
|
|
136
|
+
* `retrieve(id: string)`: Get a message thread.
|
|
137
|
+
* `reply(id: string, payload: { body: string; senderId: string; recipientId: string })`: Reply to a message.
|
|
138
|
+
* `delete(id: string)`: Delete a message.
|
|
139
|
+
|
|
140
|
+
### Reports (`client.reports`)
|
|
141
|
+
|
|
142
|
+
* `list(params: { reporterId?: string; reportedId?: string; read?: boolean; cursor?: string })`: List reports.
|
|
143
|
+
* `create(payload: { reporterId: string; type: string; description?: string; ... })`: Submit a report.
|
|
144
|
+
* `batchUpdate(payload: { reportIds: string[]; read: boolean })`: Bulk update status.
|
|
145
|
+
* `retrieve(id: string)`: Get a report.
|
|
146
|
+
* `update(id: string, payload: any)`: Update report details.
|
|
147
|
+
* `delete(id: string)`: Delete a report.
|
|
148
|
+
* `updateStatus(id: string, read: boolean)`: Update read status of a report.
|
|
149
|
+
|
|
150
|
+
### Roles (`client.roles`)
|
|
151
|
+
|
|
152
|
+
* `list(params: { cursor?: string })`: List user roles.
|
|
153
|
+
* `create(payload: { name: string; description?: string; color?: string })`: Create a new role.
|
|
154
|
+
* `retrieve(id: string)`: Get a role.
|
|
155
|
+
* `update(id: string, payload: any)`: Update a role.
|
|
156
|
+
* `delete(id: string)`: Delete a role.
|
|
47
157
|
|
|
48
|
-
###
|
|
158
|
+
### SSO (`client.sso`)
|
|
159
|
+
|
|
160
|
+
* `list()`: List SSO providers.
|
|
161
|
+
* `create(payload: { provider: string; domain: string; config: any })`: Configure SSO.
|
|
162
|
+
* `delete(id: string)`: Remove SSO provider.
|
|
163
|
+
|
|
164
|
+
## Types
|
|
49
165
|
|
|
50
|
-
|
|
51
|
-
// List threads
|
|
52
|
-
const { threads } = await client.threads.list({
|
|
53
|
-
limit: 10,
|
|
54
|
-
filter: 'newest'
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Create a thread
|
|
58
|
-
const newThread = await client.threads.create({
|
|
59
|
-
title: 'Hello World',
|
|
60
|
-
body: 'This is my first thread via the SDK!',
|
|
61
|
-
tags: ['introduction', 'general']
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Interact with a thread
|
|
65
|
-
await client.threads.like(newThread.id, currentUser.id);
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### Posts (Replies)
|
|
166
|
+
Import interfaces directly from the package:
|
|
69
167
|
|
|
70
168
|
```typescript
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// Get replies for a post (threaded view)
|
|
78
|
-
const { posts } = await client.posts.getChildren('post_123');
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### Users & Social
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
// Follow a user
|
|
85
|
-
await client.users.follow('target_user_id', 'current_user_id');
|
|
86
|
-
|
|
87
|
-
// Get user feed/followers
|
|
88
|
-
const { followers } = await client.users.getFollowers('user_123');
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### Real-time Notifications
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
// Get notifications
|
|
95
|
-
const { list } = await client.notifications.list({ userId: 'user_123' });
|
|
96
|
-
|
|
97
|
-
// Mark as read
|
|
98
|
-
await client.notifications.markAllAsRead('user_123');
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
## Resources
|
|
102
|
-
|
|
103
|
-
The SDK covers the full Foru.ms API surface:
|
|
104
|
-
|
|
105
|
-
* `client.auth`: Authentication & Registration
|
|
106
|
-
* `client.threads`: Discussions & Polls
|
|
107
|
-
* `client.posts`: Replies & Nested Comments
|
|
108
|
-
* `client.users`: User Profiles & Social Graph
|
|
109
|
-
* `client.tags`: Categorization & Subscriptions
|
|
110
|
-
* `client.notifications`: Alerts & Activity
|
|
111
|
-
* `client.search`: Unified Search
|
|
112
|
-
* `client.webhooks`: Event Subscriptions
|
|
113
|
-
* `client.stats`: Community Analytics
|
|
114
|
-
* `client.integrations`: 3rd Party Connections (Slack, Discord, etc.)
|
|
115
|
-
* `client.privateMessages`: Direct Messaging
|
|
116
|
-
* `client.reports`: Moderation & Safety
|
|
117
|
-
* `client.roles`: Permission Management
|
|
118
|
-
* `client.sso`: Single Sign-On Configuration
|
|
119
|
-
|
|
120
|
-
## TypeScript Support
|
|
121
|
-
|
|
122
|
-
This SDK is written in TypeScript and provides complete type definitions for all requests and responses.
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
import { Thread, User } from '@foru-ms/sdk';
|
|
126
|
-
|
|
127
|
-
const thread: Thread = await client.threads.retrieve('thread_123');
|
|
169
|
+
import {
|
|
170
|
+
Thread, Post, User, Tag, Notification,
|
|
171
|
+
LoginResponse, RegisterPayload
|
|
172
|
+
} from '@foru-ms/sdk';
|
|
128
173
|
```
|
|
129
174
|
|
|
130
175
|
## Error Handling
|
|
131
176
|
|
|
132
|
-
API
|
|
177
|
+
All methods return a Promise. If the API returns a non-200 status, the Promise rejects with an Error object containing the server message.
|
|
133
178
|
|
|
134
179
|
```typescript
|
|
135
180
|
try {
|
|
136
181
|
await client.threads.create({ ... });
|
|
137
|
-
} catch (
|
|
138
|
-
console.error(
|
|
182
|
+
} catch (err: any) {
|
|
183
|
+
console.error("Error creating thread:", err.message);
|
|
139
184
|
}
|
|
140
185
|
```
|
|
141
186
|
|
package/package.json
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foru-ms/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "JavaScript SDK for Foru.ms",
|
|
4
5
|
"main": "dist/index.js",
|
|
5
6
|
"types": "dist/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"build": "tsc",
|
|
8
9
|
"prepublishOnly": "npm run build"
|
|
9
10
|
},
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/foru-ms/sdk.git"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"forums",
|
|
17
|
+
"sdk",
|
|
18
|
+
"api",
|
|
19
|
+
"community",
|
|
20
|
+
"social",
|
|
21
|
+
"typescript",
|
|
22
|
+
"discussion"
|
|
23
|
+
],
|
|
24
|
+
"author": "Foru.ms",
|
|
25
|
+
"license": "MIT",
|
|
13
26
|
"dependencies": {
|
|
14
27
|
"cross-fetch": "^3.1.5"
|
|
15
28
|
},
|