@cstar.help/js 0.3.2 → 0.3.3

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.
@@ -89,6 +89,34 @@ var LibraryClient = class {
89
89
  const body = await response.json();
90
90
  return { viewCount: body.viewCount };
91
91
  }
92
+ /**
93
+ * Submit feedback for an article ("Was this helpful?").
94
+ *
95
+ * ```typescript
96
+ * // User clicked "Yes, helpful"
97
+ * await library.submitFeedback('getting-started', { isHelpful: true });
98
+ *
99
+ * // With optional text and fingerprint to prevent duplicates
100
+ * await library.submitFeedback('getting-started', {
101
+ * isHelpful: false,
102
+ * feedbackText: 'The code example was outdated',
103
+ * userFingerprint: sessionId
104
+ * });
105
+ * ```
106
+ */
107
+ async submitFeedback(slug, params) {
108
+ const url = `${this.baseUrl}/api/library/${this.teamSlug}/articles/${slug}/feedback`;
109
+ const response = await globalThis.fetch(url, {
110
+ method: "POST",
111
+ headers: { "Content-Type": "application/json" },
112
+ body: JSON.stringify(params)
113
+ });
114
+ const body = await response.json();
115
+ if (!response.ok) {
116
+ throw new Error(body.error ?? `Feedback submission failed: ${response.status}`);
117
+ }
118
+ return body;
119
+ }
92
120
  /** Get the most viewed articles, sorted by view count descending. */
93
121
  async popularArticles(limit = 5) {
94
122
  const articles = await this.articles({ limit: 50 });
@@ -56,6 +56,21 @@ interface LibraryStats {
56
56
  totalCategories: number;
57
57
  totalViews: number;
58
58
  }
59
+ /** Parameters for submitting article feedback. */
60
+ interface ArticleFeedbackParams {
61
+ /** Whether the article was helpful. */
62
+ isHelpful: boolean;
63
+ /** Optional text feedback from the user. */
64
+ feedbackText?: string;
65
+ /** Optional fingerprint to prevent duplicate votes (e.g., session ID or hashed IP). */
66
+ userFingerprint?: string;
67
+ }
68
+ /** Result of submitting article feedback. */
69
+ interface ArticleFeedbackResult {
70
+ success: boolean;
71
+ message?: string;
72
+ error?: string;
73
+ }
59
74
 
60
75
  /**
61
76
  * Public knowledge base client. No authentication required.
@@ -94,6 +109,22 @@ declare class LibraryClient {
94
109
  recordView(slug: string): Promise<{
95
110
  viewCount: number;
96
111
  }>;
112
+ /**
113
+ * Submit feedback for an article ("Was this helpful?").
114
+ *
115
+ * ```typescript
116
+ * // User clicked "Yes, helpful"
117
+ * await library.submitFeedback('getting-started', { isHelpful: true });
118
+ *
119
+ * // With optional text and fingerprint to prevent duplicates
120
+ * await library.submitFeedback('getting-started', {
121
+ * isHelpful: false,
122
+ * feedbackText: 'The code example was outdated',
123
+ * userFingerprint: sessionId
124
+ * });
125
+ * ```
126
+ */
127
+ submitFeedback(slug: string, params: ArticleFeedbackParams): Promise<ArticleFeedbackResult>;
97
128
  /** Get the most viewed articles, sorted by view count descending. */
98
129
  popularArticles(limit?: number): Promise<LibraryArticle[]>;
99
130
  /** Get aggregate stats for this knowledge base (article count, category count, total views). */
@@ -101,4 +132,4 @@ declare class LibraryClient {
101
132
  private fetch;
102
133
  }
103
134
 
104
- export { type Category, type LibraryArticle, type LibraryArticleListParams, LibraryClient, type LibraryConfig, type LibrarySearchParams, type LibrarySearchResult, type LibraryStats };
135
+ export { type ArticleFeedbackParams, type ArticleFeedbackResult, type Category, type LibraryArticle, type LibraryArticleListParams, LibraryClient, type LibraryConfig, type LibrarySearchParams, type LibrarySearchResult, type LibraryStats };
@@ -56,6 +56,21 @@ interface LibraryStats {
56
56
  totalCategories: number;
57
57
  totalViews: number;
58
58
  }
59
+ /** Parameters for submitting article feedback. */
60
+ interface ArticleFeedbackParams {
61
+ /** Whether the article was helpful. */
62
+ isHelpful: boolean;
63
+ /** Optional text feedback from the user. */
64
+ feedbackText?: string;
65
+ /** Optional fingerprint to prevent duplicate votes (e.g., session ID or hashed IP). */
66
+ userFingerprint?: string;
67
+ }
68
+ /** Result of submitting article feedback. */
69
+ interface ArticleFeedbackResult {
70
+ success: boolean;
71
+ message?: string;
72
+ error?: string;
73
+ }
59
74
 
60
75
  /**
61
76
  * Public knowledge base client. No authentication required.
@@ -94,6 +109,22 @@ declare class LibraryClient {
94
109
  recordView(slug: string): Promise<{
95
110
  viewCount: number;
96
111
  }>;
112
+ /**
113
+ * Submit feedback for an article ("Was this helpful?").
114
+ *
115
+ * ```typescript
116
+ * // User clicked "Yes, helpful"
117
+ * await library.submitFeedback('getting-started', { isHelpful: true });
118
+ *
119
+ * // With optional text and fingerprint to prevent duplicates
120
+ * await library.submitFeedback('getting-started', {
121
+ * isHelpful: false,
122
+ * feedbackText: 'The code example was outdated',
123
+ * userFingerprint: sessionId
124
+ * });
125
+ * ```
126
+ */
127
+ submitFeedback(slug: string, params: ArticleFeedbackParams): Promise<ArticleFeedbackResult>;
97
128
  /** Get the most viewed articles, sorted by view count descending. */
98
129
  popularArticles(limit?: number): Promise<LibraryArticle[]>;
99
130
  /** Get aggregate stats for this knowledge base (article count, category count, total views). */
@@ -101,4 +132,4 @@ declare class LibraryClient {
101
132
  private fetch;
102
133
  }
103
134
 
104
- export { type Category, type LibraryArticle, type LibraryArticleListParams, LibraryClient, type LibraryConfig, type LibrarySearchParams, type LibrarySearchResult, type LibraryStats };
135
+ export { type ArticleFeedbackParams, type ArticleFeedbackResult, type Category, type LibraryArticle, type LibraryArticleListParams, LibraryClient, type LibraryConfig, type LibrarySearchParams, type LibrarySearchResult, type LibraryStats };
@@ -65,6 +65,34 @@ var LibraryClient = class {
65
65
  const body = await response.json();
66
66
  return { viewCount: body.viewCount };
67
67
  }
68
+ /**
69
+ * Submit feedback for an article ("Was this helpful?").
70
+ *
71
+ * ```typescript
72
+ * // User clicked "Yes, helpful"
73
+ * await library.submitFeedback('getting-started', { isHelpful: true });
74
+ *
75
+ * // With optional text and fingerprint to prevent duplicates
76
+ * await library.submitFeedback('getting-started', {
77
+ * isHelpful: false,
78
+ * feedbackText: 'The code example was outdated',
79
+ * userFingerprint: sessionId
80
+ * });
81
+ * ```
82
+ */
83
+ async submitFeedback(slug, params) {
84
+ const url = `${this.baseUrl}/api/library/${this.teamSlug}/articles/${slug}/feedback`;
85
+ const response = await globalThis.fetch(url, {
86
+ method: "POST",
87
+ headers: { "Content-Type": "application/json" },
88
+ body: JSON.stringify(params)
89
+ });
90
+ const body = await response.json();
91
+ if (!response.ok) {
92
+ throw new Error(body.error ?? `Feedback submission failed: ${response.status}`);
93
+ }
94
+ return body;
95
+ }
68
96
  /** Get the most viewed articles, sorted by view count descending. */
69
97
  async popularArticles(limit = 5) {
70
98
  const articles = await this.articles({ limit: 50 });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cstar.help/js",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Official TypeScript SDK for the cStar customer support platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",