@foru-ms/sdk 1.2.6 → 1.2.8

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 CHANGED
@@ -552,6 +552,12 @@ We welcome contributions! Please see our contributing guidelines for more inform
552
552
 
553
553
  ## Changelog
554
554
 
555
+ ### v1.2.8
556
+ - Added Poll resource for poll management
557
+
558
+ ### v1.2.7
559
+ - Fixed issue with optional parameters not being optional in typescript
560
+
555
561
  ### v1.2.6
556
562
  - Fixed issue with optional parameters not being optional in typescript
557
563
 
@@ -1,5 +1,6 @@
1
1
  import { ForumClient } from '../Client';
2
2
  import { ThreadListResponse, ThreadFilter, InteractionType } from '../types';
3
+ import { PollResults } from '../response-types';
3
4
  export declare class ThreadsResource {
4
5
  private client;
5
6
  constructor(client: ForumClient);
@@ -57,6 +58,7 @@ export declare class ThreadsResource {
57
58
  limit?: number;
58
59
  }): Promise<any>;
59
60
  getPoll(threadId: string, userId?: string): Promise<any>;
61
+ getPollResults(threadId: string, userId?: string): Promise<PollResults>;
60
62
  vote(id: string, optionId: string, userId?: string): Promise<any>;
61
63
  voteUpdate(id: string, optionId: string, userId?: string): Promise<any>;
62
64
  unvote(id: string, userId?: string): Promise<any>;
@@ -175,6 +175,14 @@ class ThreadsResource {
175
175
  const query = searchParams.toString();
176
176
  return this.client.request(`/thread/${threadId}/poll${query ? `?${query}` : ''}`, { method: 'GET' });
177
177
  }
178
+ async getPollResults(threadId, userId) {
179
+ const searchParams = new URLSearchParams();
180
+ if (userId) {
181
+ searchParams.append('userId', userId);
182
+ }
183
+ const query = searchParams.toString();
184
+ return this.client.request(`/thread/${threadId}/poll/results${query ? `?${query}` : ''}`, { method: 'GET' });
185
+ }
178
186
  async vote(id, optionId, userId) {
179
187
  return this.client.request(`/thread/${id}/poll/votes`, {
180
188
  method: 'POST',
@@ -59,8 +59,8 @@ export declare class UsersResource {
59
59
  nextUserCursor?: string;
60
60
  count: number;
61
61
  }>;
62
- follow(id: string, followerId: string, extendedData?: any): Promise<any>;
63
- unfollow(id: string, followerId: string): Promise<any>;
62
+ follow(id: string, followerId?: string, extendedData?: any): Promise<any>;
63
+ unfollow(id: string, followerId?: string): Promise<any>;
64
64
  getFollowing(id: string, params?: {
65
65
  query?: string;
66
66
  cursor?: string;
@@ -86,8 +86,9 @@ class UsersResource {
86
86
  });
87
87
  }
88
88
  async unfollow(id, followerId) {
89
- return this.client.request(`/user/${id}/followers?followerId=${followerId}`, {
89
+ return this.client.request(`/user/${id}/followers`, {
90
90
  method: 'DELETE',
91
+ body: JSON.stringify({ followerId }),
91
92
  });
92
93
  }
93
94
  async getFollowing(id, params) {
@@ -78,6 +78,28 @@ export interface PollOption {
78
78
  /** Extended data */
79
79
  extendedData?: Record<string, any>;
80
80
  }
81
+ /**
82
+ * Simplified poll option for results
83
+ */
84
+ export interface PollOptionResult {
85
+ /** The ID of the poll option */
86
+ id: string;
87
+ /** The title of the poll option */
88
+ title: string;
89
+ /** The color of the poll option */
90
+ color?: string;
91
+ /** The number of votes this option received */
92
+ votes: number;
93
+ }
94
+ /**
95
+ * Poll results data
96
+ */
97
+ export interface PollResults {
98
+ /** List of poll options with results */
99
+ options: PollOptionResult[];
100
+ /** The option ID that the user voted for, or null if they haven't voted */
101
+ userVote?: string | null;
102
+ }
81
103
  /**
82
104
  * Response for batch operations
83
105
  */
@@ -1,3 +1,4 @@
1
+ // @ts-ignore
1
2
  import { ForumClient } from '@foru-ms/sdk';
2
3
 
3
4
  /**
@@ -70,8 +71,12 @@ async function main() {
70
71
  await client.threads.vote(pollThread.id, 'option-id-1', userId);
71
72
  console.log('Vote cast');
72
73
 
74
+ // Get poll
75
+ const poll = await client.threads.getPoll(pollThread.id, userId);
76
+ console.log('Poll:', poll);
77
+
73
78
  // Get poll results
74
- const pollResults = await client.threads.getPoll(pollThread.id, userId);
79
+ const pollResults = await client.threads.getPollResults(pollThread.id, userId);
75
80
  console.log('Poll results:', pollResults);
76
81
 
77
82
  // Example 7: Add Posts to Thread
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foru-ms/sdk",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "JavaScript SDK for Foru.ms",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,6 @@
1
1
  import { ForumClient } from '../Client';
2
2
  import { ThreadListResponse, ThreadFilter, InteractionType } from '../types';
3
+ import { PollResults } from '../response-types';
3
4
 
4
5
  export class ThreadsResource {
5
6
  private client: ForumClient;
@@ -232,6 +233,19 @@ export class ThreadsResource {
232
233
  );
233
234
  }
234
235
 
236
+ async getPollResults(threadId: string, userId?: string): Promise<PollResults> {
237
+ const searchParams = new URLSearchParams();
238
+ if (userId) {
239
+ searchParams.append('userId', userId);
240
+ }
241
+
242
+ const query = searchParams.toString();
243
+ return this.client.request<PollResults>(
244
+ `/thread/${threadId}/poll/results${query ? `?${query}` : ''}`,
245
+ { method: 'GET' }
246
+ );
247
+ }
248
+
235
249
  async vote(id: string, optionId: string, userId?: string): Promise<any> {
236
250
  return this.client.request(`/thread/${id}/poll/votes`, {
237
251
  method: 'POST',
@@ -133,16 +133,17 @@ export class UsersResource {
133
133
  });
134
134
  }
135
135
 
136
- async follow(id: string, followerId: string, extendedData?: any): Promise<any> {
136
+ async follow(id: string, followerId?: string, extendedData?: any): Promise<any> {
137
137
  return this.client.request(`/user/${id}/followers`, {
138
138
  method: 'POST',
139
139
  body: JSON.stringify({ followerId, extendedData }),
140
140
  });
141
141
  }
142
142
 
143
- async unfollow(id: string, followerId: string): Promise<any> {
144
- return this.client.request(`/user/${id}/followers?followerId=${followerId}`, {
143
+ async unfollow(id: string, followerId?: string): Promise<any> {
144
+ return this.client.request(`/user/${id}/followers`, {
145
145
  method: 'DELETE',
146
+ body: JSON.stringify({ followerId }),
146
147
  });
147
148
  }
148
149
 
@@ -85,6 +85,30 @@ export interface PollOption {
85
85
  extendedData?: Record<string, any>;
86
86
  }
87
87
 
88
+ /**
89
+ * Simplified poll option for results
90
+ */
91
+ export interface PollOptionResult {
92
+ /** The ID of the poll option */
93
+ id: string;
94
+ /** The title of the poll option */
95
+ title: string;
96
+ /** The color of the poll option */
97
+ color?: string;
98
+ /** The number of votes this option received */
99
+ votes: number;
100
+ }
101
+
102
+ /**
103
+ * Poll results data
104
+ */
105
+ export interface PollResults {
106
+ /** List of poll options with results */
107
+ options: PollOptionResult[];
108
+ /** The option ID that the user voted for, or null if they haven't voted */
109
+ userVote?: string | null;
110
+ }
111
+
88
112
  /**
89
113
  * Response for batch operations
90
114
  */