@foru-ms/sdk 0.2.0 → 1.1.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 +21 -0
  2. package/README.md +205 -98
  3. 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,235 @@ yarn add @foru-ms/sdk
12
14
  pnpm add @foru-ms/sdk
13
15
  ```
14
16
 
15
- ## Getting Started
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, defaults to production URL
24
+ // baseUrl: 'https://api.foru.ms/v1' // Optional
25
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'
37
- });
38
-
39
- // Or set an existing token
40
- client.setToken(token);
41
26
 
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
- ## Usage Examples
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; 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(userId: string)`: Get user by ID.
80
+ * `create(payload: { username: string; email: string; password: string; displayName?: string; emailVerified?: boolean; roles?: string[]; bio?: string; signature?: string; url?: string; extendedData?: Record<string, any> })`: Create a user (Admin).
81
+ * `update(id: string, payload: { username?: string; email?: string; password?: string; displayName?: string; emailVerified?: boolean; roles?: string[]; bio?: string; signature?: string; url?: string; extendedData?: Record<string, any> })`: Update a user.
82
+ * `delete(id: string)`: Delete a user.
83
+ * `getFollowers(id: string, params?: { query?: string; cursor?: string; filter?: 'newest' | 'oldest' })`: Get user's followers.
84
+ * `getFollowing(id: string, params?: { query?: string; cursor?: string; filter?: 'newest' | 'oldest' })`: 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
+
89
+ ### Tags (`client.tags`)
90
+
91
+ * `list(params?: { query?: string; cursor?: string })`: List tags.
92
+ * `create(payload: { name: string; description?: string; color?: string; extendedData?: Record<string, any> })`: Create a tag.
93
+ * `retrieve(id: string, params?: { userId?: string })`: Get a tag.
94
+ * `update(id: string, payload: { name?: string; description?: string; color?: string; extendedData?: Record<string, any> })`: Update a tag.
95
+ * `delete(id: string)`: Delete a tag.
96
+ * `subscribe(id: string, userId: string)`: Subscribe to a tag.
97
+ * `unsubscribe(id: string, userId: string)`: Unsubscribe from a tag.
98
+ * `listSubscribed(params: { userId: string; query?: string; cursor?: string })`: List tags a user is subscribed to.
99
+
100
+
101
+ ### Notifications (`client.notifications`)
102
+
103
+ * `list(params: { userId: string; read?: boolean; filter?: 'newest' | 'oldest'; cursor?: string })`: List notifications.
104
+ * `markAllAsRead(userId: string, read?: boolean)`: Bulk update read status. Default is `true`.
105
+ * `create(payload: { threadId?: string; postId?: string; privateMessageId?: string; notifierId: string; notifiedId: string; type: string; description?: string; extendedData?: Record<string, any> })`: Create a notification manually.
106
+ * `retrieve(id: string)`: Get a notification.
107
+ * `update(id: string, payload: { read: boolean })`: Update a notification.
108
+ * `delete(id: string)`: Delete a notification.
109
+
110
+ ### Search (`client.search`)
111
+
112
+ * `search(params: { query: string; type: 'threads' | 'posts' | 'users' | 'tags'; cursor?: string })`: Polymorphic search.
113
+
114
+ ### Webhooks (`client.webhooks`)
115
+
116
+ * `list()`: List webhooks.
117
+ * `create(payload: { name: string; url: string; events: string[] })`: Create a webhook.
118
+ * `retrieve(id: string)`: Get a webhook.
119
+ * `update(id: string, payload: any)`: Update a webhook.
120
+ * `delete(id: string)`: Delete a webhook.
121
+ * `getDeliveries(id: string, params: { cursor?: string })`: Get webhook delivery history.
122
+
123
+ ### Stats (`client.stats`)
124
+
125
+ * `get(params?: { filter?: string; threadCursor?: string; postCursor?: string; ... })`: Get instance statistics.
126
+
127
+ ### Integrations (`client.integrations`)
128
+
129
+ * `list()`: Get all configured integrations.
130
+ * `create(payload: { type: 'SLACK' | 'DISCORD' | 'SALESFORCE' | 'HUBSPOT' | 'OKTA' | 'AUTH0'; name: string; config: any })`: Configure an integration (Slack, Discord, etc.).
131
+ * `retrieve(id: string)`: Get integration details.
132
+ * `delete(id: string)`: Remove an integration.
133
+
134
+ ### Private Messages (`client.privateMessages`)
135
+
136
+ * `list(params?: { query?: string; userId?: string; filter?: 'newest' | 'oldest'; cursor?: string })`: List private messages.
137
+ * `create(payload: { title?: string; body: string; recipientId: string; senderId?: string; extendedData?: Record<string, any> })`: Send a direct message.
138
+ * `retrieve(id: string)`: Get a message thread.
139
+ * `reply(id: string, payload: { body: string; senderId: string; recipientId: string; extendedData?: Record<string, any> })`: Reply to a message.
140
+ * `delete(id: string)`: Delete a message.
141
+
142
+ ### Reports (`client.reports`)
143
+
144
+ * `list(params?: { reporterId?: string; reportedId?: string; read?: boolean; cursor?: string; filter?: 'newest' | 'oldest' })`: List reports.
145
+ * `create(payload: { reporterId: string; reportedId?: string; threadId?: string; postId?: string; privateMessageId?: string; type?: string; description?: string; extendedData?: Record<string, any> })`: Submit a report.
146
+ * `batchUpdate(payload: { reportIds: string[]; read: boolean })`: Bulk update status.
147
+ * `retrieve(id: string)`: Get a report.
148
+ * `update(id: string, payload: { threadId?: string; postId?: string; privateMessageId?: string; reportedId?: string; reporterId?: string; type?: string; description?: string; read?: boolean; extendedData?: Record<string, any> })`: Update report details.
149
+ * `delete(id: string)`: Delete a report.
150
+ * `updateStatus(id: string, read: boolean)`: Update read status of a report.
47
151
 
48
- ### Threads
152
+ ### Roles (`client.roles`)
49
153
 
50
- ```typescript
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
- });
154
+ * `list(params?: { filter?: 'newest' | 'oldest'; cursor?: string })`: List user roles.
155
+ * `create(payload: { name: string; description?: string; color?: string; extendedData?: Record<string, any> })`: Create a new role.
156
+ * `retrieve(id: string)`: Get a role.
157
+ * `update(id: string, payload: { name?: string; description?: string; color?: string; extendedData?: Record<string, any> })`: Update a role.
158
+ * `delete(id: string)`: Delete a role.
63
159
 
64
- // Interact with a thread
65
- await client.threads.like(newThread.id, currentUser.id);
66
- ```
160
+ ### SSO (`client.sso`)
67
161
 
68
- ### Posts (Replies)
162
+ * `list()`: List SSO providers.
163
+ * `create(payload: { provider: 'OKTA' | 'AUTH0' | 'SAML'; domain: string; config: any })`: Configure SSO.
164
+ * `delete(id: string)`: Remove SSO provider.
69
165
 
70
- ```typescript
71
- // Reply to a thread
72
- const post = await client.posts.create({
73
- threadId: 'thread_123',
74
- body: 'Great discussion!'
75
- });
166
+ ## Types
76
167
 
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.
168
+ Import all available interfaces and types directly from the package:
123
169
 
124
170
  ```typescript
125
- import { Thread, User } from '@foru-ms/sdk';
126
-
127
- const thread: Thread = await client.threads.retrieve('thread_123');
171
+ import {
172
+ // Auth Types
173
+ RegisterPayload,
174
+ User,
175
+ LoginResponse,
176
+
177
+ // Thread Types
178
+ Thread,
179
+ CreateThreadPayload,
180
+ UpdateThreadPayload,
181
+ ThreadListResponse,
182
+ ThreadFilter,
183
+
184
+ // Post Types
185
+ Post,
186
+ CreatePostPayload,
187
+ UpdatePostPayload,
188
+ PostListResponse,
189
+
190
+ // Tag Types
191
+ Tag,
192
+ TagListResponse,
193
+
194
+ // User Types
195
+ UserListResponse,
196
+
197
+ // Notification Types
198
+ Notification,
199
+ NotificationListResponse,
200
+
201
+ // Search Types
202
+ SearchResponse,
203
+
204
+ // Webhook Types
205
+ Webhook,
206
+ WebhookListResponse,
207
+
208
+ // Stats Types
209
+ StatsResponse,
210
+
211
+ // Integration Types
212
+ Integration,
213
+ IntegrationListResponse,
214
+
215
+ // Private Message Types
216
+ PrivateMessage,
217
+ PrivateMessageListResponse,
218
+
219
+ // Report Types
220
+ Report,
221
+ ReportListResponse,
222
+
223
+ // Role Types
224
+ Role,
225
+ RoleListResponse,
226
+
227
+ // SSO Types
228
+ SSOProvider,
229
+ SSOProviderListResponse,
230
+
231
+ // Utility Types
232
+ PaginatedResponse,
233
+ InteractionType
234
+ } from '@foru-ms/sdk';
128
235
  ```
129
236
 
130
237
  ## Error Handling
131
238
 
132
- API errors throw standard JavaScript errors with messages from the server.
239
+ 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
240
 
134
241
  ```typescript
135
242
  try {
136
243
  await client.threads.create({ ... });
137
- } catch (error) {
138
- console.error('API Error:', error.message);
244
+ } catch (err: any) {
245
+ console.error("Error creating thread:", err.message);
139
246
  }
140
247
  ```
141
248
 
package/package.json CHANGED
@@ -1,15 +1,28 @@
1
1
  {
2
2
  "name": "@foru-ms/sdk",
3
- "version": "0.2.0",
3
+ "version": "1.1.1",
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
- "keywords": [],
11
- "author": "",
12
- "license": "ISC",
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
  },