@cstar.help/js 0.3.2 → 0.3.4
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/dist/index.cjs +7 -1
- package/dist/index.js +7 -1
- package/dist/library/index.cjs +28 -0
- package/dist/library/index.d.cts +32 -1
- package/dist/library/index.d.ts +32 -1
- package/dist/library/index.js +28 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -137,7 +137,13 @@ var HttpClient = class {
|
|
|
137
137
|
signal: AbortSignal.timeout(this.config.timeout)
|
|
138
138
|
});
|
|
139
139
|
} catch (err) {
|
|
140
|
-
|
|
140
|
+
const networkErr = err instanceof Error ? err : new Error(String(err));
|
|
141
|
+
lastError = new CStarError(0, {
|
|
142
|
+
type: "connection_error",
|
|
143
|
+
code: "network_error",
|
|
144
|
+
message: `Network request failed: ${networkErr.message}`,
|
|
145
|
+
doc_url: "https://www.cstar.help/developers/errors#connection-errors"
|
|
146
|
+
});
|
|
141
147
|
if (attempt < this.config.maxRetries) continue;
|
|
142
148
|
throw lastError;
|
|
143
149
|
}
|
package/dist/index.js
CHANGED
|
@@ -105,7 +105,13 @@ var HttpClient = class {
|
|
|
105
105
|
signal: AbortSignal.timeout(this.config.timeout)
|
|
106
106
|
});
|
|
107
107
|
} catch (err) {
|
|
108
|
-
|
|
108
|
+
const networkErr = err instanceof Error ? err : new Error(String(err));
|
|
109
|
+
lastError = new CStarError(0, {
|
|
110
|
+
type: "connection_error",
|
|
111
|
+
code: "network_error",
|
|
112
|
+
message: `Network request failed: ${networkErr.message}`,
|
|
113
|
+
doc_url: "https://www.cstar.help/developers/errors#connection-errors"
|
|
114
|
+
});
|
|
109
115
|
if (attempt < this.config.maxRetries) continue;
|
|
110
116
|
throw lastError;
|
|
111
117
|
}
|
package/dist/library/index.cjs
CHANGED
|
@@ -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 });
|
package/dist/library/index.d.cts
CHANGED
|
@@ -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 };
|
package/dist/library/index.d.ts
CHANGED
|
@@ -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 };
|
package/dist/library/index.js
CHANGED
|
@@ -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 });
|