@cstar.help/js 0.5.2 → 0.6.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.
@@ -97,6 +97,13 @@ type MessageCallback = (message: WidgetMessage) => void;
97
97
  /** Callback for typing indicator events. */
98
98
  type TypingCallback = (payload: TypingPayload) => void;
99
99
 
100
+ /** Attachment metadata for community posts and comments (images only, max 5MB each). */
101
+ interface CommunityAttachment {
102
+ filename: string;
103
+ content_type: string;
104
+ size_bytes: number;
105
+ storage_path: string;
106
+ }
100
107
  /** Parameters for creating a post as an identified customer. */
101
108
  interface CommunityCreatePostParams {
102
109
  /** Post title. */
@@ -105,6 +112,8 @@ interface CommunityCreatePostParams {
105
112
  body?: string;
106
113
  /** Topic UUID to post in. */
107
114
  topicId: string;
115
+ /** Image attachments (max 10, images only, 5MB each). */
116
+ attachments?: CommunityAttachment[];
108
117
  }
109
118
  /** Parameters for creating a comment as an identified customer. */
110
119
  interface CommunityCreateCommentParams {
@@ -112,6 +121,8 @@ interface CommunityCreateCommentParams {
112
121
  body: string;
113
122
  /** Parent comment ID for replies (optional, 1-level nesting). */
114
123
  parentCommentId?: string | null;
124
+ /** Image attachments (max 5, images only, 5MB each). */
125
+ attachments?: CommunityAttachment[];
115
126
  }
116
127
  /** Response from creating a post. */
117
128
  interface CommunityCreatedPost {
@@ -97,6 +97,13 @@ type MessageCallback = (message: WidgetMessage) => void;
97
97
  /** Callback for typing indicator events. */
98
98
  type TypingCallback = (payload: TypingPayload) => void;
99
99
 
100
+ /** Attachment metadata for community posts and comments (images only, max 5MB each). */
101
+ interface CommunityAttachment {
102
+ filename: string;
103
+ content_type: string;
104
+ size_bytes: number;
105
+ storage_path: string;
106
+ }
100
107
  /** Parameters for creating a post as an identified customer. */
101
108
  interface CommunityCreatePostParams {
102
109
  /** Post title. */
@@ -105,6 +112,8 @@ interface CommunityCreatePostParams {
105
112
  body?: string;
106
113
  /** Topic UUID to post in. */
107
114
  topicId: string;
115
+ /** Image attachments (max 10, images only, 5MB each). */
116
+ attachments?: CommunityAttachment[];
108
117
  }
109
118
  /** Parameters for creating a comment as an identified customer. */
110
119
  interface CommunityCreateCommentParams {
@@ -112,6 +121,8 @@ interface CommunityCreateCommentParams {
112
121
  body: string;
113
122
  /** Parent comment ID for replies (optional, 1-level nesting). */
114
123
  parentCommentId?: string | null;
124
+ /** Image attachments (max 5, images only, 5MB each). */
125
+ attachments?: CommunityAttachment[];
115
126
  }
116
127
  /** Response from creating a post. */
117
128
  interface CommunityCreatedPost {
@@ -0,0 +1,231 @@
1
+ /** Attachment metadata for community posts and comments (images only, max 5MB each). */
2
+ interface CommunityAttachment {
3
+ filename: string;
4
+ content_type: string;
5
+ size_bytes: number;
6
+ storage_path: string;
7
+ }
8
+ /** Configuration for the CommunityClient. */
9
+ interface CommunityConfig {
10
+ /** Team slug (e.g., 'acme'). Identifies the community to query. */
11
+ teamSlug: string;
12
+ /** Override the base URL (defaults to https://www.cstar.help). */
13
+ baseUrl?: string;
14
+ }
15
+ /** Parameters for creating a post as an identified customer. */
16
+ interface CommunityCreatePostParams {
17
+ /** Post title. */
18
+ title: string;
19
+ /** Post body/content (optional). */
20
+ body?: string;
21
+ /** Topic UUID to post in. */
22
+ topicId: string;
23
+ /** Image attachments (max 10, images only, 5MB each). */
24
+ attachments?: CommunityAttachment[];
25
+ }
26
+ /** Parameters for creating a comment as an identified customer. */
27
+ interface CommunityCreateCommentParams {
28
+ /** Comment body text. */
29
+ body: string;
30
+ /** Parent comment ID for replies (optional, 1-level nesting). */
31
+ parentCommentId?: string | null;
32
+ /** Image attachments (max 5, images only, 5MB each). */
33
+ attachments?: CommunityAttachment[];
34
+ }
35
+ /** Response from creating a post. */
36
+ interface CommunityCreatedPost {
37
+ id: string;
38
+ title: string;
39
+ slug: string;
40
+ body: string;
41
+ status: string;
42
+ visibility: string;
43
+ voteCount: number;
44
+ commentCount: number;
45
+ topicName: string;
46
+ topicSlug: string;
47
+ authorName: string;
48
+ authorAvatar: string;
49
+ isTeamMember: boolean;
50
+ createdAt: string;
51
+ }
52
+ /** Response from creating a comment. */
53
+ interface CommunityCreatedComment {
54
+ id: string;
55
+ body: string;
56
+ isOfficial: boolean;
57
+ voteScore: number;
58
+ parentCommentId: string | null;
59
+ authorName: string;
60
+ authorAvatar: string;
61
+ isTeamMember: boolean;
62
+ createdAt: string;
63
+ }
64
+ /** Response from toggling a vote. */
65
+ interface CommunityVoteResult {
66
+ voted: boolean;
67
+ voteCount: number;
68
+ }
69
+ /** Response from toggling a follow. */
70
+ interface CommunityFollowResult {
71
+ following: boolean;
72
+ }
73
+ /** A discussion topic/category in the community. */
74
+ interface CommunityTopic {
75
+ id: string;
76
+ name: string;
77
+ slug: string;
78
+ description: string | null;
79
+ icon: string;
80
+ visibility: 'public' | 'members_only';
81
+ sort_order: number;
82
+ }
83
+ /** A public community post. */
84
+ interface CommunityPost {
85
+ id: string;
86
+ title: string;
87
+ slug: string;
88
+ body: string;
89
+ status: 'open' | 'answered' | 'officially_answered' | 'planned' | 'not_planned' | 'completed' | 'under_review';
90
+ visibility: 'public' | 'members_only';
91
+ voteCount: number;
92
+ commentCount: number;
93
+ isPinned: boolean;
94
+ isFeatured: boolean;
95
+ isLocked: boolean;
96
+ commentsEnabled: boolean;
97
+ topicName: string;
98
+ topicSlug: string;
99
+ authorName: string;
100
+ authorAvatar: string;
101
+ authorBio: string;
102
+ authorPostCount: number;
103
+ authorCommentCount: number;
104
+ attachments: CommunityAttachment[];
105
+ isTeamMember: boolean;
106
+ lastActivityAt: string;
107
+ createdAt: string;
108
+ }
109
+ /** A comment on a community post. */
110
+ interface CommunityComment {
111
+ id: string;
112
+ body: string;
113
+ isOfficial: boolean;
114
+ voteScore: number;
115
+ parentCommentId: string | null;
116
+ attachments: CommunityAttachment[];
117
+ authorName: string;
118
+ authorAvatar: string;
119
+ authorBio: string;
120
+ authorPostCount: number;
121
+ authorCommentCount: number;
122
+ isTeamMember: boolean;
123
+ createdAt: string;
124
+ }
125
+ /** Parameters for listing posts. */
126
+ interface CommunityPostListParams {
127
+ /** Filter by topic slug. */
128
+ topicSlug?: string;
129
+ /** Filter by status. */
130
+ status?: string;
131
+ /** Sort order (default: 'recent'). */
132
+ sort?: 'recent' | 'votes' | 'comments';
133
+ /** Max results per page. */
134
+ limit?: number;
135
+ /** Pagination offset. */
136
+ offset?: number;
137
+ }
138
+ /** Search results. */
139
+ interface CommunitySearchResult {
140
+ data: CommunityPost[];
141
+ count: number;
142
+ query: string;
143
+ }
144
+ /** A single post with its comments. */
145
+ interface CommunityPostDetail {
146
+ post: CommunityPost;
147
+ comments: CommunityComment[];
148
+ }
149
+
150
+ /**
151
+ * Public community client. No authentication required.
152
+ *
153
+ * ```typescript
154
+ * const community = new CommunityClient({ teamSlug: 'acme' });
155
+ * const topics = await community.topics();
156
+ * const posts = await community.posts({ topicSlug: 'feedback', sort: 'votes' });
157
+ * const post = await community.post('my-feature-request');
158
+ * const results = await community.search('dark mode');
159
+ * ```
160
+ */
161
+ declare class CommunityClient {
162
+ private readonly baseUrl;
163
+ private readonly teamSlug;
164
+ private sessionToken;
165
+ private teamId;
166
+ constructor(config: CommunityConfig);
167
+ /**
168
+ * Set a session token from identity verification.
169
+ * This enables authenticated operations (create posts, vote, comment).
170
+ *
171
+ * The token is the same `sessionToken` returned by `ChatClient.identify()`.
172
+ */
173
+ setSessionToken(token: string, teamId?: string): void;
174
+ /** Clear the session token and return to read-only mode. */
175
+ clearSession(): void;
176
+ /** Whether the client has an active session token. */
177
+ get isAuthenticated(): boolean;
178
+ /** List all public community topics. */
179
+ topics(): Promise<CommunityTopic[]>;
180
+ /** List public posts, optionally filtered by topic, status, or sort order. */
181
+ posts(params?: CommunityPostListParams): Promise<{
182
+ posts: CommunityPost[];
183
+ count: number;
184
+ }>;
185
+ /** Get a single post by slug, including all comments. */
186
+ post(slug: string): Promise<CommunityPostDetail>;
187
+ /**
188
+ * Full-text search across post titles and bodies.
189
+ * Returns matching posts with relevance ranking.
190
+ */
191
+ search(query: string): Promise<CommunitySearchResult>;
192
+ /**
193
+ * Create a new community post. Requires an active session token.
194
+ *
195
+ * @throws Error if no session token is set or the request fails
196
+ */
197
+ createPost(params: CommunityCreatePostParams): Promise<CommunityCreatedPost>;
198
+ /**
199
+ * Toggle vote on a post. Returns new vote state and count.
200
+ * Requires an active session token.
201
+ */
202
+ vote(postId: string): Promise<CommunityVoteResult>;
203
+ /**
204
+ * Add a comment to a post. Requires an active session token.
205
+ */
206
+ comment(postId: string, params: CommunityCreateCommentParams): Promise<CommunityCreatedComment>;
207
+ /**
208
+ * Toggle follow on a post. Requires an active session token.
209
+ */
210
+ follow(postId: string): Promise<CommunityFollowResult>;
211
+ /**
212
+ * Check if the current user has voted on a specific post.
213
+ * Requires an active session token.
214
+ */
215
+ getVoteStatus(postId: string): Promise<boolean>;
216
+ /**
217
+ * Check vote status for multiple posts in a single request.
218
+ * Returns a map of postId → voted boolean.
219
+ * Requires an active session token.
220
+ */
221
+ bulkVoteStatus(postIds: string[]): Promise<Record<string, boolean>>;
222
+ /**
223
+ * Resolve team slug to team ID (cached after first call).
224
+ * For authenticated operations that require teamId.
225
+ */
226
+ private resolveTeamId;
227
+ private authenticatedFetch;
228
+ private fetch;
229
+ }
230
+
231
+ export { CommunityClient, type CommunityComment, type CommunityConfig, type CommunityCreateCommentParams, type CommunityCreatePostParams, type CommunityCreatedComment, type CommunityCreatedPost, type CommunityFollowResult, type CommunityPost, type CommunityPostDetail, type CommunityPostListParams, type CommunitySearchResult, type CommunityTopic, type CommunityVoteResult };
@@ -0,0 +1,231 @@
1
+ /** Attachment metadata for community posts and comments (images only, max 5MB each). */
2
+ interface CommunityAttachment {
3
+ filename: string;
4
+ content_type: string;
5
+ size_bytes: number;
6
+ storage_path: string;
7
+ }
8
+ /** Configuration for the CommunityClient. */
9
+ interface CommunityConfig {
10
+ /** Team slug (e.g., 'acme'). Identifies the community to query. */
11
+ teamSlug: string;
12
+ /** Override the base URL (defaults to https://www.cstar.help). */
13
+ baseUrl?: string;
14
+ }
15
+ /** Parameters for creating a post as an identified customer. */
16
+ interface CommunityCreatePostParams {
17
+ /** Post title. */
18
+ title: string;
19
+ /** Post body/content (optional). */
20
+ body?: string;
21
+ /** Topic UUID to post in. */
22
+ topicId: string;
23
+ /** Image attachments (max 10, images only, 5MB each). */
24
+ attachments?: CommunityAttachment[];
25
+ }
26
+ /** Parameters for creating a comment as an identified customer. */
27
+ interface CommunityCreateCommentParams {
28
+ /** Comment body text. */
29
+ body: string;
30
+ /** Parent comment ID for replies (optional, 1-level nesting). */
31
+ parentCommentId?: string | null;
32
+ /** Image attachments (max 5, images only, 5MB each). */
33
+ attachments?: CommunityAttachment[];
34
+ }
35
+ /** Response from creating a post. */
36
+ interface CommunityCreatedPost {
37
+ id: string;
38
+ title: string;
39
+ slug: string;
40
+ body: string;
41
+ status: string;
42
+ visibility: string;
43
+ voteCount: number;
44
+ commentCount: number;
45
+ topicName: string;
46
+ topicSlug: string;
47
+ authorName: string;
48
+ authorAvatar: string;
49
+ isTeamMember: boolean;
50
+ createdAt: string;
51
+ }
52
+ /** Response from creating a comment. */
53
+ interface CommunityCreatedComment {
54
+ id: string;
55
+ body: string;
56
+ isOfficial: boolean;
57
+ voteScore: number;
58
+ parentCommentId: string | null;
59
+ authorName: string;
60
+ authorAvatar: string;
61
+ isTeamMember: boolean;
62
+ createdAt: string;
63
+ }
64
+ /** Response from toggling a vote. */
65
+ interface CommunityVoteResult {
66
+ voted: boolean;
67
+ voteCount: number;
68
+ }
69
+ /** Response from toggling a follow. */
70
+ interface CommunityFollowResult {
71
+ following: boolean;
72
+ }
73
+ /** A discussion topic/category in the community. */
74
+ interface CommunityTopic {
75
+ id: string;
76
+ name: string;
77
+ slug: string;
78
+ description: string | null;
79
+ icon: string;
80
+ visibility: 'public' | 'members_only';
81
+ sort_order: number;
82
+ }
83
+ /** A public community post. */
84
+ interface CommunityPost {
85
+ id: string;
86
+ title: string;
87
+ slug: string;
88
+ body: string;
89
+ status: 'open' | 'answered' | 'officially_answered' | 'planned' | 'not_planned' | 'completed' | 'under_review';
90
+ visibility: 'public' | 'members_only';
91
+ voteCount: number;
92
+ commentCount: number;
93
+ isPinned: boolean;
94
+ isFeatured: boolean;
95
+ isLocked: boolean;
96
+ commentsEnabled: boolean;
97
+ topicName: string;
98
+ topicSlug: string;
99
+ authorName: string;
100
+ authorAvatar: string;
101
+ authorBio: string;
102
+ authorPostCount: number;
103
+ authorCommentCount: number;
104
+ attachments: CommunityAttachment[];
105
+ isTeamMember: boolean;
106
+ lastActivityAt: string;
107
+ createdAt: string;
108
+ }
109
+ /** A comment on a community post. */
110
+ interface CommunityComment {
111
+ id: string;
112
+ body: string;
113
+ isOfficial: boolean;
114
+ voteScore: number;
115
+ parentCommentId: string | null;
116
+ attachments: CommunityAttachment[];
117
+ authorName: string;
118
+ authorAvatar: string;
119
+ authorBio: string;
120
+ authorPostCount: number;
121
+ authorCommentCount: number;
122
+ isTeamMember: boolean;
123
+ createdAt: string;
124
+ }
125
+ /** Parameters for listing posts. */
126
+ interface CommunityPostListParams {
127
+ /** Filter by topic slug. */
128
+ topicSlug?: string;
129
+ /** Filter by status. */
130
+ status?: string;
131
+ /** Sort order (default: 'recent'). */
132
+ sort?: 'recent' | 'votes' | 'comments';
133
+ /** Max results per page. */
134
+ limit?: number;
135
+ /** Pagination offset. */
136
+ offset?: number;
137
+ }
138
+ /** Search results. */
139
+ interface CommunitySearchResult {
140
+ data: CommunityPost[];
141
+ count: number;
142
+ query: string;
143
+ }
144
+ /** A single post with its comments. */
145
+ interface CommunityPostDetail {
146
+ post: CommunityPost;
147
+ comments: CommunityComment[];
148
+ }
149
+
150
+ /**
151
+ * Public community client. No authentication required.
152
+ *
153
+ * ```typescript
154
+ * const community = new CommunityClient({ teamSlug: 'acme' });
155
+ * const topics = await community.topics();
156
+ * const posts = await community.posts({ topicSlug: 'feedback', sort: 'votes' });
157
+ * const post = await community.post('my-feature-request');
158
+ * const results = await community.search('dark mode');
159
+ * ```
160
+ */
161
+ declare class CommunityClient {
162
+ private readonly baseUrl;
163
+ private readonly teamSlug;
164
+ private sessionToken;
165
+ private teamId;
166
+ constructor(config: CommunityConfig);
167
+ /**
168
+ * Set a session token from identity verification.
169
+ * This enables authenticated operations (create posts, vote, comment).
170
+ *
171
+ * The token is the same `sessionToken` returned by `ChatClient.identify()`.
172
+ */
173
+ setSessionToken(token: string, teamId?: string): void;
174
+ /** Clear the session token and return to read-only mode. */
175
+ clearSession(): void;
176
+ /** Whether the client has an active session token. */
177
+ get isAuthenticated(): boolean;
178
+ /** List all public community topics. */
179
+ topics(): Promise<CommunityTopic[]>;
180
+ /** List public posts, optionally filtered by topic, status, or sort order. */
181
+ posts(params?: CommunityPostListParams): Promise<{
182
+ posts: CommunityPost[];
183
+ count: number;
184
+ }>;
185
+ /** Get a single post by slug, including all comments. */
186
+ post(slug: string): Promise<CommunityPostDetail>;
187
+ /**
188
+ * Full-text search across post titles and bodies.
189
+ * Returns matching posts with relevance ranking.
190
+ */
191
+ search(query: string): Promise<CommunitySearchResult>;
192
+ /**
193
+ * Create a new community post. Requires an active session token.
194
+ *
195
+ * @throws Error if no session token is set or the request fails
196
+ */
197
+ createPost(params: CommunityCreatePostParams): Promise<CommunityCreatedPost>;
198
+ /**
199
+ * Toggle vote on a post. Returns new vote state and count.
200
+ * Requires an active session token.
201
+ */
202
+ vote(postId: string): Promise<CommunityVoteResult>;
203
+ /**
204
+ * Add a comment to a post. Requires an active session token.
205
+ */
206
+ comment(postId: string, params: CommunityCreateCommentParams): Promise<CommunityCreatedComment>;
207
+ /**
208
+ * Toggle follow on a post. Requires an active session token.
209
+ */
210
+ follow(postId: string): Promise<CommunityFollowResult>;
211
+ /**
212
+ * Check if the current user has voted on a specific post.
213
+ * Requires an active session token.
214
+ */
215
+ getVoteStatus(postId: string): Promise<boolean>;
216
+ /**
217
+ * Check vote status for multiple posts in a single request.
218
+ * Returns a map of postId → voted boolean.
219
+ * Requires an active session token.
220
+ */
221
+ bulkVoteStatus(postIds: string[]): Promise<Record<string, boolean>>;
222
+ /**
223
+ * Resolve team slug to team ID (cached after first call).
224
+ * For authenticated operations that require teamId.
225
+ */
226
+ private resolveTeamId;
227
+ private authenticatedFetch;
228
+ private fetch;
229
+ }
230
+
231
+ export { CommunityClient, type CommunityComment, type CommunityConfig, type CommunityCreateCommentParams, type CommunityCreatePostParams, type CommunityCreatedComment, type CommunityCreatedPost, type CommunityFollowResult, type CommunityPost, type CommunityPostDetail, type CommunityPostListParams, type CommunitySearchResult, type CommunityTopic, type CommunityVoteResult };