@kookee/sdk 0.0.32 → 0.0.33
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 +57 -28
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +20 -21
- package/dist/index.d.ts +20 -21
- package/dist/index.global.js +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,6 +44,43 @@ const kookee = new Kookee({
|
|
|
44
44
|
});
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
## User Identification
|
|
48
|
+
|
|
49
|
+
Set user identity once and it's automatically used across all feedback operations:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// Set user identity globally
|
|
53
|
+
kookee.identify({
|
|
54
|
+
externalId: 'user-456',
|
|
55
|
+
name: 'Jane Doe',
|
|
56
|
+
email: 'jane@example.com', // optional
|
|
57
|
+
avatarUrl: 'https://...', // optional
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// All feedback methods now auto-use the identified user
|
|
61
|
+
await kookee.feedback.createPost({ title: 'Feature request', category: 'feature' });
|
|
62
|
+
await kookee.feedback.createComment(postId, { content: 'Great idea!' });
|
|
63
|
+
const myPosts = await kookee.feedback.listMyPosts();
|
|
64
|
+
|
|
65
|
+
// Check current user
|
|
66
|
+
const user = kookee.getUser(); // KookeeUser | null
|
|
67
|
+
|
|
68
|
+
// Clear identity on logout
|
|
69
|
+
kookee.reset();
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### React usage
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (user) {
|
|
77
|
+
kookee.identify({ externalId: user.id, name: user.name, email: user.email });
|
|
78
|
+
} else {
|
|
79
|
+
kookee.reset();
|
|
80
|
+
}
|
|
81
|
+
}, [user]);
|
|
82
|
+
```
|
|
83
|
+
|
|
47
84
|
## Blog
|
|
48
85
|
|
|
49
86
|
```typescript
|
|
@@ -219,48 +256,39 @@ const contributors = await kookee.feedback.getTopContributors({ limit: 10 });
|
|
|
219
256
|
|
|
220
257
|
### Creating and managing feedback
|
|
221
258
|
|
|
222
|
-
These operations require
|
|
259
|
+
These operations require user identification — either globally via `kookee.identify()` or per-call via `externalUser`/`externalId`:
|
|
223
260
|
|
|
224
261
|
```typescript
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const user: ExternalUser = {
|
|
228
|
-
externalId: 'user-123', // your system's user ID
|
|
229
|
-
name: 'Jane Doe',
|
|
230
|
-
email: 'jane@example.com', // optional
|
|
231
|
-
avatarUrl: 'https://...', // optional
|
|
232
|
-
};
|
|
262
|
+
// With global identity (recommended — see User Identification section above)
|
|
263
|
+
kookee.identify({ externalId: 'user-123', name: 'Jane Doe' });
|
|
233
264
|
|
|
234
|
-
// Create a feedback post
|
|
235
265
|
const newPost = await kookee.feedback.createPost({
|
|
236
266
|
title: 'Add dark mode',
|
|
237
267
|
description: 'It would be great to have a dark mode option.',
|
|
238
|
-
category: 'feature',
|
|
239
|
-
externalUser: user,
|
|
268
|
+
category: 'feature',
|
|
240
269
|
});
|
|
241
270
|
|
|
242
|
-
// Add a comment to a post
|
|
243
271
|
const comment = await kookee.feedback.createComment('post-id', {
|
|
244
272
|
content: 'Great idea, I would love this too!',
|
|
245
|
-
externalUser: user,
|
|
246
273
|
});
|
|
247
274
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
search: 'dark mode', // optional search
|
|
256
|
-
sort: 'newest', // optional sort
|
|
257
|
-
});
|
|
275
|
+
const myPosts = await kookee.feedback.listMyPosts();
|
|
276
|
+
|
|
277
|
+
await kookee.feedback.deletePost('post-id');
|
|
278
|
+
await kookee.feedback.deleteComment('comment-id');
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Per-call override still works (takes precedence over global identity):
|
|
258
282
|
|
|
259
|
-
|
|
260
|
-
await kookee.feedback.
|
|
283
|
+
```typescript
|
|
284
|
+
const newPost = await kookee.feedback.createPost({
|
|
285
|
+
title: 'Add dark mode',
|
|
286
|
+
externalUser: { externalId: 'other-user', name: 'John' },
|
|
287
|
+
});
|
|
261
288
|
|
|
262
|
-
|
|
263
|
-
await kookee.feedback.
|
|
289
|
+
const myPosts = await kookee.feedback.listMyPosts({ externalId: 'other-user' });
|
|
290
|
+
await kookee.feedback.deletePost('post-id', { externalId: 'other-user' });
|
|
291
|
+
await kookee.feedback.deleteComment('comment-id', { externalId: 'other-user' });
|
|
264
292
|
```
|
|
265
293
|
|
|
266
294
|
## Config
|
|
@@ -387,6 +415,7 @@ import type {
|
|
|
387
415
|
FeedbackPostListItem,
|
|
388
416
|
FeedbackComment,
|
|
389
417
|
FeedbackTopContributor,
|
|
418
|
+
KookeeUser,
|
|
390
419
|
ExternalUser,
|
|
391
420
|
PublicConfig,
|
|
392
421
|
PaginatedResponse,
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var k="https://api.kookee.dev",
|
|
2
|
-
`);n=
|
|
1
|
+
'use strict';var k="https://api.kookee.dev",B="Kookee-API-Key",I="Kookee-Project-Id",i=class s extends Error{constructor(t,r,o){super(r);this.code=t;this.status=o;this.name="KookeeApiError",Object.setPrototypeOf(this,s.prototype);}},C=class{baseUrl;apiKey;projectId;constructor(e){this.apiKey=e.apiKey,this.projectId=e.projectId,this.baseUrl=e.baseUrl??k;}getHeaders(){let e={"Content-Type":"application/json"};return this.apiKey&&(e[B]=this.apiKey),this.projectId&&(e[I]=this.projectId),e}async get(e,t){let r=new URL(`${this.baseUrl}${e}`);if(t){for(let[h,n]of Object.entries(t))if(n!=null)if(Array.isArray(n))for(let a of n)r.searchParams.append(h,String(a));else r.searchParams.set(h,String(n));}let o=await fetch(r.toString(),{method:"GET",headers:this.getHeaders()});return this.handleResponse(o)}async post(e,t){let r=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:this.getHeaders(),body:t?JSON.stringify(t):void 0});return this.handleResponse(r)}async delete(e,t){let r=await fetch(`${this.baseUrl}${e}`,{method:"DELETE",headers:this.getHeaders(),body:t?JSON.stringify(t):void 0});return this.handleResponse(r)}async*streamPost(e,t){let r=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:{...this.getHeaders(),Accept:"text/event-stream"},body:t?JSON.stringify(t):void 0});if(!r.ok){let a=null;try{a=await r.json();}catch{}throw new i(a?.code??"UNKNOWN_ERROR",a?.message??`Request failed with status ${r.status}`,r.status)}if(!r.body)return;let o=r.body.getReader(),h=new TextDecoder,n="";try{for(;;){let{done:a,value:b}=await o.read();if(a)break;n+=h.decode(b,{stream:!0});let E=n.split(`
|
|
2
|
+
`);n=E.pop()??"";for(let x of E){let u=x.trim();if(!(!u||u.startsWith(":"))&&u.startsWith("data: ")){let R=u.slice(6);if(R==="[DONE]")return;yield JSON.parse(R);}}}}finally{o.releaseLock();}}async handleResponse(e){if(!e.ok){let t=null;try{t=await e.json();}catch{}throw new i(t?.code??"UNKNOWN_ERROR",t?.message??`Request failed with status ${e.status}`,e.status)}return e.json()}};var m=class{constructor(e){this.entries=e;}async list(e){return this.entries.list({type:"announcement",...e})}async getById(e,t){return this.entries.getById(e,t)}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getComments(e,t){return this.entries.getComments(e,t)}};var p=class{constructor(e){this.entries=e;}async list(e){return this.entries.list({type:"blog",...e})}async getBySlug(e,t){return this.entries.getBySlug(e,{type:"blog",...t})}async getById(e,t){return this.entries.getById(e,t)}async getTags(){return this.entries.getTags("blog")}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getTranslationsBySlug(e){return this.entries.getTranslationsBySlug(e)}async getComments(e,t){return this.entries.getComments(e,t)}async react(e,t){return this.entries.react(e,t)}};var c=class{constructor(e){this.entries=e;}async list(e){return this.entries.list({type:"changelog",...e})}async getBySlug(e,t){return this.entries.getBySlug(e,{type:"changelog",...t})}async getById(e,t){return this.entries.getById(e,t)}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getTranslationsBySlug(e){return this.entries.getTranslationsBySlug(e)}async getComments(e,t){return this.entries.getComments(e,t)}async react(e,t){return this.entries.react(e,t)}};var g=class{constructor(e){this.http=e;}async getByKey(e){return this.http.get(`/v1/config/${encodeURIComponent(e)}`)}async list(e){return this.http.get("/v1/config",e)}};var l=class{constructor(e){this.http=e;}async list(e){return this.http.get("/v1/entries",e)}async getById(e,t){return this.http.get(`/v1/entries/by-id/${encodeURIComponent(e)}`,t)}async getBySlug(e,t){return this.http.get(`/v1/entries/${encodeURIComponent(e)}`,t)}async getTranslationsById(e){return this.http.get(`/v1/entries/by-id/${encodeURIComponent(e)}/translations`)}async getTranslationsBySlug(e){return this.http.get(`/v1/entries/${encodeURIComponent(e)}/translations`)}async getComments(e,t){return this.http.get(`/v1/entries/${encodeURIComponent(e)}/comments`,t)}async react(e,t){return this.http.post(`/v1/entries/${encodeURIComponent(e)}/reactions`,t)}async getTags(e){return this.http.get("/v1/tags",{type:e})}async getCategories(e,t){return this.http.get("/v1/categories",{type:e,...t})}};var y=class{constructor(e,t){this.http=e;this.getUserContext=t;}async list(e){return this.http.get("/v1/feedback",e)}async getById(e){return this.http.get(`/v1/feedback/by-id/${encodeURIComponent(e)}`)}async vote(e,t){return this.http.post(`/v1/feedback/${encodeURIComponent(e)}/vote`,t)}async getTopContributors(e){return this.http.get("/v1/feedback/top-contributors",e)}async createPost(e){let t=e.externalUser??this.getUserContext();if(!t)throw new Error("No user identified. Call kookee.identify() first or pass externalUser in params.");return this.http.post("/v1/feedback",{...e,externalUser:t})}async createComment(e,t){let r=t.externalUser??this.getUserContext();if(!r)throw new Error("No user identified. Call kookee.identify() first or pass externalUser in params.");return this.http.post(`/v1/feedback/${encodeURIComponent(e)}/comments`,{...t,externalUser:r})}async listMyPosts(e){let t=e?.externalId??this.getUserContext()?.externalId;if(!t)throw new Error("No user identified. Call kookee.identify() first or pass externalId in params.");return this.http.get("/v1/feedback/mine",{...e,externalId:t})}async deletePost(e,t){let r=t?.externalId??this.getUserContext()?.externalId;if(!r)throw new Error("No user identified. Call kookee.identify() first or pass externalId in params.");return this.http.delete(`/v1/feedback/${encodeURIComponent(e)}`,{externalId:r})}async deleteComment(e,t){let r=t?.externalId??this.getUserContext()?.externalId;if(!r)throw new Error("No user identified. Call kookee.identify() first or pass externalId in params.");return this.http.delete(`/v1/feedback/comments/${encodeURIComponent(e)}`,{externalId:r})}};var d=class{http;entries;constructor(e,t){this.http=e,this.entries=t;}async categories(e){return this.entries.getCategories("help_article",e)}async list(e){return this.entries.list({type:"help_article",...e})}async getBySlug(e,t){return this.entries.getBySlug(e,{type:"help_article",...t})}async getById(e,t){return this.entries.getById(e,t)}async search(e){return this.http.get("/v1/help/search",e)}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getTranslationsBySlug(e){return this.entries.getTranslationsBySlug(e)}async getComments(e,t){return this.entries.getComments(e,t)}async react(e,t){return this.entries.react(e,t)}async chat(e){return this.http.post("/v1/help/chat",e)}chatStream(e){return this.http.streamPost("/v1/help/chat/stream",e)}};var P=class{constructor(e){this.entries=e;}async list(e){return this.entries.list({type:"page",...e})}async getBySlug(e,t){return this.entries.getBySlug(e,{type:"page",...t})}async getById(e,t){return this.entries.getById(e,t)}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getTranslationsBySlug(e){return this.entries.getTranslationsBySlug(e)}async getComments(e,t){return this.entries.getComments(e,t)}};var f=class{http;user=null;entries;announcements;blog;changelog;config;feedback;help;pages;constructor(e){if(!e.apiKey&&!e.projectId)throw new Error("Either apiKey or projectId is required");this.http=new C({apiKey:e.apiKey,projectId:e.projectId,baseUrl:e.baseUrl}),this.entries=new l(this.http),this.announcements=new m(this.entries),this.blog=new p(this.entries),this.changelog=new c(this.entries),this.config=new g(this.http),this.feedback=new y(this.http,()=>this.user),this.help=new d(this.http,this.entries),this.pages=new P(this.entries);}identify(e){this.user=e;}reset(){this.user=null;}getUser(){return this.user}async health(){return this.http.get("/v1/health")}};exports.AnnouncementModule=m;exports.BlogModule=p;exports.ChangelogModule=c;exports.ConfigModule=g;exports.EntriesModule=l;exports.FeedbackModule=y;exports.HelpModule=d;exports.Kookee=f;exports.KookeeApiError=i;exports.PagesModule=P;
|
package/dist/index.d.cts
CHANGED
|
@@ -34,16 +34,12 @@ interface HealthCheckResponse {
|
|
|
34
34
|
}
|
|
35
35
|
type ReactionType = 'fire' | 'heart' | 'rocket' | 'eyes' | 'mindblown';
|
|
36
36
|
interface ReactParams {
|
|
37
|
-
reactionType:
|
|
37
|
+
reactionType: string;
|
|
38
38
|
action: 'add' | 'remove';
|
|
39
39
|
}
|
|
40
40
|
interface ReactResponse {
|
|
41
41
|
reactions: Record<string, number>;
|
|
42
42
|
}
|
|
43
|
-
interface VoteUsefulnessResponse {
|
|
44
|
-
usefulYesCount: number;
|
|
45
|
-
usefulNoCount: number;
|
|
46
|
-
}
|
|
47
43
|
type OrderDirection = 'asc' | 'desc';
|
|
48
44
|
interface HelpChatMessage {
|
|
49
45
|
role: 'user' | 'assistant';
|
|
@@ -94,8 +90,6 @@ interface HelpSearchResult {
|
|
|
94
90
|
};
|
|
95
91
|
locale: string;
|
|
96
92
|
matchedChunk?: string;
|
|
97
|
-
usefulYesCount: number;
|
|
98
|
-
usefulNoCount: number;
|
|
99
93
|
}
|
|
100
94
|
type FeedbackPostStatus = 'open' | 'under_review' | 'planned' | 'in_progress' | 'completed' | 'declined';
|
|
101
95
|
type FeedbackPostCategory = 'feature' | 'improvement' | 'bug' | 'other';
|
|
@@ -145,21 +139,23 @@ interface FeedbackTopContributor {
|
|
|
145
139
|
interface FeedbackVoteResponse {
|
|
146
140
|
voteCount: number;
|
|
147
141
|
}
|
|
148
|
-
interface
|
|
142
|
+
interface KookeeUser {
|
|
149
143
|
externalId: string;
|
|
150
144
|
name: string;
|
|
151
145
|
email?: string;
|
|
152
146
|
avatarUrl?: string;
|
|
147
|
+
[key: string]: unknown;
|
|
153
148
|
}
|
|
149
|
+
type ExternalUser = KookeeUser;
|
|
154
150
|
interface CreateFeedbackPostParams {
|
|
155
151
|
title: string;
|
|
156
152
|
description?: string;
|
|
157
153
|
category?: FeedbackPostCategory;
|
|
158
|
-
externalUser
|
|
154
|
+
externalUser?: ExternalUser;
|
|
159
155
|
}
|
|
160
156
|
interface CreateFeedbackCommentParams {
|
|
161
157
|
content: string;
|
|
162
|
-
externalUser
|
|
158
|
+
externalUser?: ExternalUser;
|
|
163
159
|
}
|
|
164
160
|
interface CreatedFeedbackPost {
|
|
165
161
|
id: string;
|
|
@@ -182,7 +178,7 @@ interface CreatedFeedbackComment {
|
|
|
182
178
|
updatedAt: string;
|
|
183
179
|
}
|
|
184
180
|
interface ListMyFeedbackPostsParams {
|
|
185
|
-
externalId
|
|
181
|
+
externalId?: string;
|
|
186
182
|
page?: number;
|
|
187
183
|
limit?: number;
|
|
188
184
|
status?: FeedbackPostStatus;
|
|
@@ -191,13 +187,13 @@ interface ListMyFeedbackPostsParams {
|
|
|
191
187
|
sort?: FeedbackSortOption;
|
|
192
188
|
}
|
|
193
189
|
interface DeleteFeedbackPostParams {
|
|
194
|
-
externalId
|
|
190
|
+
externalId?: string;
|
|
195
191
|
}
|
|
196
192
|
interface DeleteFeedbackPostResponse {
|
|
197
193
|
success: boolean;
|
|
198
194
|
}
|
|
199
195
|
interface DeleteFeedbackCommentParams {
|
|
200
|
-
externalId
|
|
196
|
+
externalId?: string;
|
|
201
197
|
}
|
|
202
198
|
interface DeleteFeedbackCommentResponse {
|
|
203
199
|
success: boolean;
|
|
@@ -268,8 +264,6 @@ interface PageTypeSpecific {
|
|
|
268
264
|
interface HelpArticleTypeSpecific {
|
|
269
265
|
_type: 'help_article';
|
|
270
266
|
visibility: HelpArticleVisibility;
|
|
271
|
-
usefulYesCount: number;
|
|
272
|
-
usefulNoCount: number;
|
|
273
267
|
}
|
|
274
268
|
interface ChangelogTypeSpecific {
|
|
275
269
|
_type: 'changelog';
|
|
@@ -443,16 +437,17 @@ interface FeedbackTopContributorsParams {
|
|
|
443
437
|
}
|
|
444
438
|
declare class FeedbackModule {
|
|
445
439
|
private readonly http;
|
|
446
|
-
|
|
440
|
+
private readonly getUserContext;
|
|
441
|
+
constructor(http: HttpClient, getUserContext: () => KookeeUser | null);
|
|
447
442
|
list(params?: FeedbackListParams): Promise<PaginatedResponse<FeedbackPostListItem>>;
|
|
448
443
|
getById(id: string): Promise<FeedbackPost>;
|
|
449
444
|
vote(postId: string, params: FeedbackVoteParams): Promise<FeedbackVoteResponse>;
|
|
450
445
|
getTopContributors(params?: FeedbackTopContributorsParams): Promise<FeedbackTopContributor[]>;
|
|
451
446
|
createPost(params: CreateFeedbackPostParams): Promise<CreatedFeedbackPost>;
|
|
452
447
|
createComment(postId: string, params: CreateFeedbackCommentParams): Promise<CreatedFeedbackComment>;
|
|
453
|
-
listMyPosts(params
|
|
454
|
-
deletePost(postId: string, params
|
|
455
|
-
deleteComment(commentId: string, params
|
|
448
|
+
listMyPosts(params?: ListMyFeedbackPostsParams): Promise<PaginatedResponse<FeedbackPostListItem>>;
|
|
449
|
+
deletePost(postId: string, params?: DeleteFeedbackPostParams): Promise<DeleteFeedbackPostResponse>;
|
|
450
|
+
deleteComment(commentId: string, params?: DeleteFeedbackCommentParams): Promise<DeleteFeedbackCommentResponse>;
|
|
456
451
|
}
|
|
457
452
|
|
|
458
453
|
interface HelpCategoriesParams extends LocaleOptions {
|
|
@@ -483,9 +478,9 @@ declare class HelpModule {
|
|
|
483
478
|
getTranslationsById(articleId: string): Promise<Record<string, HelpArticleEntry>>;
|
|
484
479
|
getTranslationsBySlug(slug: string): Promise<Record<string, HelpArticleEntry>>;
|
|
485
480
|
getComments(entryId: string, params?: HelpGetCommentsParams): Promise<PaginatedResponse<EntryComment>>;
|
|
481
|
+
react(articleId: string, params: ReactParams): Promise<ReactResponse>;
|
|
486
482
|
chat(params: HelpChatParams): Promise<HelpChatResponse>;
|
|
487
483
|
chatStream(params: HelpChatParams): AsyncIterable<HelpChatStreamChunk>;
|
|
488
|
-
voteUsefulness(articleId: string, vote: 'yes' | 'no' | null, previousVote?: 'yes' | 'no' | null): Promise<VoteUsefulnessResponse>;
|
|
489
484
|
}
|
|
490
485
|
|
|
491
486
|
interface PagesListParams extends PaginationParams, LocaleOptions {
|
|
@@ -510,6 +505,7 @@ declare class PagesModule {
|
|
|
510
505
|
|
|
511
506
|
declare class Kookee {
|
|
512
507
|
private readonly http;
|
|
508
|
+
private user;
|
|
513
509
|
readonly entries: EntriesModule;
|
|
514
510
|
readonly announcements: AnnouncementModule;
|
|
515
511
|
readonly blog: BlogModule;
|
|
@@ -519,7 +515,10 @@ declare class Kookee {
|
|
|
519
515
|
readonly help: HelpModule;
|
|
520
516
|
readonly pages: PagesModule;
|
|
521
517
|
constructor(config: KookeeConfig);
|
|
518
|
+
identify(user: KookeeUser): void;
|
|
519
|
+
reset(): void;
|
|
520
|
+
getUser(): KookeeUser | null;
|
|
522
521
|
health(): Promise<HealthCheckResponse>;
|
|
523
522
|
}
|
|
524
523
|
|
|
525
|
-
export { type AnnouncementEntry, type AnnouncementGetByIdParams, type AnnouncementGetCommentsParams, type AnnouncementListParams, AnnouncementModule, type AnnouncementType, type AnnouncementTypeSpecific, type AnyEntry, type ApiError, type BaseEntry, type BlogEntry, type BlogGetByIdParams, type BlogGetBySlugParams, type BlogGetCommentsParams, type BlogListParams, BlogModule, type BlogTypeSpecific, type ChangelogEntry, type ChangelogGetByIdParams, type ChangelogGetBySlugParams, type ChangelogGetCommentsParams, type ChangelogListParams, ChangelogModule, type ChangelogType, type ChangelogTypeSpecific, type ConfigListParams, ConfigModule, type CreateFeedbackCommentParams, type CreateFeedbackPostParams, type CreatedFeedbackComment, type CreatedFeedbackPost, type DeleteFeedbackCommentParams, type DeleteFeedbackCommentResponse, type DeleteFeedbackPostParams, type DeleteFeedbackPostResponse, type EntriesGetByIdParams, type EntriesGetBySlugParams, type EntriesGetCategoriesParams, type EntriesGetCommentsParams, type EntriesListParams, EntriesModule, type EntryAuthor, type EntryCategory, type EntryComment, type EntryStatus, type EntryTag, type EntryTagWithCount, type EntryType, type ExternalUser, type FeedbackAssignee, type FeedbackAuthor, type FeedbackComment, type FeedbackListParams, FeedbackModule, type FeedbackPost, type FeedbackPostCategory, type FeedbackPostListItem, type FeedbackPostStatus, type FeedbackSortOption, type FeedbackTopContributor, type FeedbackTopContributorsParams, type FeedbackVoteParams, type FeedbackVoteResponse, type GenericEntry, type HealthCheckResponse, type HelpArticleEntry, type HelpArticleTypeSpecific, type HelpArticleVisibility, type HelpCategoriesParams, type HelpChatMessage, type HelpChatParams, type HelpChatResponse, type HelpChatSource, type HelpChatSourceCategory, type HelpChatStreamChunk, type HelpGetByIdParams, type HelpGetBySlugParams, type HelpGetCommentsParams, type HelpListParams, HelpModule, type HelpSearchParams, type HelpSearchResult, Kookee, KookeeApiError, type KookeeConfig, type ListMyFeedbackPostsParams, type LocaleOptions, type OrderDirection, type PageEntry, type PageTypeSpecific, type PagesGetByIdParams, type PagesGetBySlugParams, type PagesGetCommentsParams, type PagesListParams, PagesModule, type PaginatedResponse, type PaginationParams, type PublicConfig, type ReactParams, type ReactResponse, type ReactionType, type TypeSpecific, type TypedEntry
|
|
524
|
+
export { type AnnouncementEntry, type AnnouncementGetByIdParams, type AnnouncementGetCommentsParams, type AnnouncementListParams, AnnouncementModule, type AnnouncementType, type AnnouncementTypeSpecific, type AnyEntry, type ApiError, type BaseEntry, type BlogEntry, type BlogGetByIdParams, type BlogGetBySlugParams, type BlogGetCommentsParams, type BlogListParams, BlogModule, type BlogTypeSpecific, type ChangelogEntry, type ChangelogGetByIdParams, type ChangelogGetBySlugParams, type ChangelogGetCommentsParams, type ChangelogListParams, ChangelogModule, type ChangelogType, type ChangelogTypeSpecific, type ConfigListParams, ConfigModule, type CreateFeedbackCommentParams, type CreateFeedbackPostParams, type CreatedFeedbackComment, type CreatedFeedbackPost, type DeleteFeedbackCommentParams, type DeleteFeedbackCommentResponse, type DeleteFeedbackPostParams, type DeleteFeedbackPostResponse, type EntriesGetByIdParams, type EntriesGetBySlugParams, type EntriesGetCategoriesParams, type EntriesGetCommentsParams, type EntriesListParams, EntriesModule, type EntryAuthor, type EntryCategory, type EntryComment, type EntryStatus, type EntryTag, type EntryTagWithCount, type EntryType, type ExternalUser, type FeedbackAssignee, type FeedbackAuthor, type FeedbackComment, type FeedbackListParams, FeedbackModule, type FeedbackPost, type FeedbackPostCategory, type FeedbackPostListItem, type FeedbackPostStatus, type FeedbackSortOption, type FeedbackTopContributor, type FeedbackTopContributorsParams, type FeedbackVoteParams, type FeedbackVoteResponse, type GenericEntry, type HealthCheckResponse, type HelpArticleEntry, type HelpArticleTypeSpecific, type HelpArticleVisibility, type HelpCategoriesParams, type HelpChatMessage, type HelpChatParams, type HelpChatResponse, type HelpChatSource, type HelpChatSourceCategory, type HelpChatStreamChunk, type HelpGetByIdParams, type HelpGetBySlugParams, type HelpGetCommentsParams, type HelpListParams, HelpModule, type HelpSearchParams, type HelpSearchResult, Kookee, KookeeApiError, type KookeeConfig, type KookeeUser, type ListMyFeedbackPostsParams, type LocaleOptions, type OrderDirection, type PageEntry, type PageTypeSpecific, type PagesGetByIdParams, type PagesGetBySlugParams, type PagesGetCommentsParams, type PagesListParams, PagesModule, type PaginatedResponse, type PaginationParams, type PublicConfig, type ReactParams, type ReactResponse, type ReactionType, type TypeSpecific, type TypedEntry };
|
package/dist/index.d.ts
CHANGED
|
@@ -34,16 +34,12 @@ interface HealthCheckResponse {
|
|
|
34
34
|
}
|
|
35
35
|
type ReactionType = 'fire' | 'heart' | 'rocket' | 'eyes' | 'mindblown';
|
|
36
36
|
interface ReactParams {
|
|
37
|
-
reactionType:
|
|
37
|
+
reactionType: string;
|
|
38
38
|
action: 'add' | 'remove';
|
|
39
39
|
}
|
|
40
40
|
interface ReactResponse {
|
|
41
41
|
reactions: Record<string, number>;
|
|
42
42
|
}
|
|
43
|
-
interface VoteUsefulnessResponse {
|
|
44
|
-
usefulYesCount: number;
|
|
45
|
-
usefulNoCount: number;
|
|
46
|
-
}
|
|
47
43
|
type OrderDirection = 'asc' | 'desc';
|
|
48
44
|
interface HelpChatMessage {
|
|
49
45
|
role: 'user' | 'assistant';
|
|
@@ -94,8 +90,6 @@ interface HelpSearchResult {
|
|
|
94
90
|
};
|
|
95
91
|
locale: string;
|
|
96
92
|
matchedChunk?: string;
|
|
97
|
-
usefulYesCount: number;
|
|
98
|
-
usefulNoCount: number;
|
|
99
93
|
}
|
|
100
94
|
type FeedbackPostStatus = 'open' | 'under_review' | 'planned' | 'in_progress' | 'completed' | 'declined';
|
|
101
95
|
type FeedbackPostCategory = 'feature' | 'improvement' | 'bug' | 'other';
|
|
@@ -145,21 +139,23 @@ interface FeedbackTopContributor {
|
|
|
145
139
|
interface FeedbackVoteResponse {
|
|
146
140
|
voteCount: number;
|
|
147
141
|
}
|
|
148
|
-
interface
|
|
142
|
+
interface KookeeUser {
|
|
149
143
|
externalId: string;
|
|
150
144
|
name: string;
|
|
151
145
|
email?: string;
|
|
152
146
|
avatarUrl?: string;
|
|
147
|
+
[key: string]: unknown;
|
|
153
148
|
}
|
|
149
|
+
type ExternalUser = KookeeUser;
|
|
154
150
|
interface CreateFeedbackPostParams {
|
|
155
151
|
title: string;
|
|
156
152
|
description?: string;
|
|
157
153
|
category?: FeedbackPostCategory;
|
|
158
|
-
externalUser
|
|
154
|
+
externalUser?: ExternalUser;
|
|
159
155
|
}
|
|
160
156
|
interface CreateFeedbackCommentParams {
|
|
161
157
|
content: string;
|
|
162
|
-
externalUser
|
|
158
|
+
externalUser?: ExternalUser;
|
|
163
159
|
}
|
|
164
160
|
interface CreatedFeedbackPost {
|
|
165
161
|
id: string;
|
|
@@ -182,7 +178,7 @@ interface CreatedFeedbackComment {
|
|
|
182
178
|
updatedAt: string;
|
|
183
179
|
}
|
|
184
180
|
interface ListMyFeedbackPostsParams {
|
|
185
|
-
externalId
|
|
181
|
+
externalId?: string;
|
|
186
182
|
page?: number;
|
|
187
183
|
limit?: number;
|
|
188
184
|
status?: FeedbackPostStatus;
|
|
@@ -191,13 +187,13 @@ interface ListMyFeedbackPostsParams {
|
|
|
191
187
|
sort?: FeedbackSortOption;
|
|
192
188
|
}
|
|
193
189
|
interface DeleteFeedbackPostParams {
|
|
194
|
-
externalId
|
|
190
|
+
externalId?: string;
|
|
195
191
|
}
|
|
196
192
|
interface DeleteFeedbackPostResponse {
|
|
197
193
|
success: boolean;
|
|
198
194
|
}
|
|
199
195
|
interface DeleteFeedbackCommentParams {
|
|
200
|
-
externalId
|
|
196
|
+
externalId?: string;
|
|
201
197
|
}
|
|
202
198
|
interface DeleteFeedbackCommentResponse {
|
|
203
199
|
success: boolean;
|
|
@@ -268,8 +264,6 @@ interface PageTypeSpecific {
|
|
|
268
264
|
interface HelpArticleTypeSpecific {
|
|
269
265
|
_type: 'help_article';
|
|
270
266
|
visibility: HelpArticleVisibility;
|
|
271
|
-
usefulYesCount: number;
|
|
272
|
-
usefulNoCount: number;
|
|
273
267
|
}
|
|
274
268
|
interface ChangelogTypeSpecific {
|
|
275
269
|
_type: 'changelog';
|
|
@@ -443,16 +437,17 @@ interface FeedbackTopContributorsParams {
|
|
|
443
437
|
}
|
|
444
438
|
declare class FeedbackModule {
|
|
445
439
|
private readonly http;
|
|
446
|
-
|
|
440
|
+
private readonly getUserContext;
|
|
441
|
+
constructor(http: HttpClient, getUserContext: () => KookeeUser | null);
|
|
447
442
|
list(params?: FeedbackListParams): Promise<PaginatedResponse<FeedbackPostListItem>>;
|
|
448
443
|
getById(id: string): Promise<FeedbackPost>;
|
|
449
444
|
vote(postId: string, params: FeedbackVoteParams): Promise<FeedbackVoteResponse>;
|
|
450
445
|
getTopContributors(params?: FeedbackTopContributorsParams): Promise<FeedbackTopContributor[]>;
|
|
451
446
|
createPost(params: CreateFeedbackPostParams): Promise<CreatedFeedbackPost>;
|
|
452
447
|
createComment(postId: string, params: CreateFeedbackCommentParams): Promise<CreatedFeedbackComment>;
|
|
453
|
-
listMyPosts(params
|
|
454
|
-
deletePost(postId: string, params
|
|
455
|
-
deleteComment(commentId: string, params
|
|
448
|
+
listMyPosts(params?: ListMyFeedbackPostsParams): Promise<PaginatedResponse<FeedbackPostListItem>>;
|
|
449
|
+
deletePost(postId: string, params?: DeleteFeedbackPostParams): Promise<DeleteFeedbackPostResponse>;
|
|
450
|
+
deleteComment(commentId: string, params?: DeleteFeedbackCommentParams): Promise<DeleteFeedbackCommentResponse>;
|
|
456
451
|
}
|
|
457
452
|
|
|
458
453
|
interface HelpCategoriesParams extends LocaleOptions {
|
|
@@ -483,9 +478,9 @@ declare class HelpModule {
|
|
|
483
478
|
getTranslationsById(articleId: string): Promise<Record<string, HelpArticleEntry>>;
|
|
484
479
|
getTranslationsBySlug(slug: string): Promise<Record<string, HelpArticleEntry>>;
|
|
485
480
|
getComments(entryId: string, params?: HelpGetCommentsParams): Promise<PaginatedResponse<EntryComment>>;
|
|
481
|
+
react(articleId: string, params: ReactParams): Promise<ReactResponse>;
|
|
486
482
|
chat(params: HelpChatParams): Promise<HelpChatResponse>;
|
|
487
483
|
chatStream(params: HelpChatParams): AsyncIterable<HelpChatStreamChunk>;
|
|
488
|
-
voteUsefulness(articleId: string, vote: 'yes' | 'no' | null, previousVote?: 'yes' | 'no' | null): Promise<VoteUsefulnessResponse>;
|
|
489
484
|
}
|
|
490
485
|
|
|
491
486
|
interface PagesListParams extends PaginationParams, LocaleOptions {
|
|
@@ -510,6 +505,7 @@ declare class PagesModule {
|
|
|
510
505
|
|
|
511
506
|
declare class Kookee {
|
|
512
507
|
private readonly http;
|
|
508
|
+
private user;
|
|
513
509
|
readonly entries: EntriesModule;
|
|
514
510
|
readonly announcements: AnnouncementModule;
|
|
515
511
|
readonly blog: BlogModule;
|
|
@@ -519,7 +515,10 @@ declare class Kookee {
|
|
|
519
515
|
readonly help: HelpModule;
|
|
520
516
|
readonly pages: PagesModule;
|
|
521
517
|
constructor(config: KookeeConfig);
|
|
518
|
+
identify(user: KookeeUser): void;
|
|
519
|
+
reset(): void;
|
|
520
|
+
getUser(): KookeeUser | null;
|
|
522
521
|
health(): Promise<HealthCheckResponse>;
|
|
523
522
|
}
|
|
524
523
|
|
|
525
|
-
export { type AnnouncementEntry, type AnnouncementGetByIdParams, type AnnouncementGetCommentsParams, type AnnouncementListParams, AnnouncementModule, type AnnouncementType, type AnnouncementTypeSpecific, type AnyEntry, type ApiError, type BaseEntry, type BlogEntry, type BlogGetByIdParams, type BlogGetBySlugParams, type BlogGetCommentsParams, type BlogListParams, BlogModule, type BlogTypeSpecific, type ChangelogEntry, type ChangelogGetByIdParams, type ChangelogGetBySlugParams, type ChangelogGetCommentsParams, type ChangelogListParams, ChangelogModule, type ChangelogType, type ChangelogTypeSpecific, type ConfigListParams, ConfigModule, type CreateFeedbackCommentParams, type CreateFeedbackPostParams, type CreatedFeedbackComment, type CreatedFeedbackPost, type DeleteFeedbackCommentParams, type DeleteFeedbackCommentResponse, type DeleteFeedbackPostParams, type DeleteFeedbackPostResponse, type EntriesGetByIdParams, type EntriesGetBySlugParams, type EntriesGetCategoriesParams, type EntriesGetCommentsParams, type EntriesListParams, EntriesModule, type EntryAuthor, type EntryCategory, type EntryComment, type EntryStatus, type EntryTag, type EntryTagWithCount, type EntryType, type ExternalUser, type FeedbackAssignee, type FeedbackAuthor, type FeedbackComment, type FeedbackListParams, FeedbackModule, type FeedbackPost, type FeedbackPostCategory, type FeedbackPostListItem, type FeedbackPostStatus, type FeedbackSortOption, type FeedbackTopContributor, type FeedbackTopContributorsParams, type FeedbackVoteParams, type FeedbackVoteResponse, type GenericEntry, type HealthCheckResponse, type HelpArticleEntry, type HelpArticleTypeSpecific, type HelpArticleVisibility, type HelpCategoriesParams, type HelpChatMessage, type HelpChatParams, type HelpChatResponse, type HelpChatSource, type HelpChatSourceCategory, type HelpChatStreamChunk, type HelpGetByIdParams, type HelpGetBySlugParams, type HelpGetCommentsParams, type HelpListParams, HelpModule, type HelpSearchParams, type HelpSearchResult, Kookee, KookeeApiError, type KookeeConfig, type ListMyFeedbackPostsParams, type LocaleOptions, type OrderDirection, type PageEntry, type PageTypeSpecific, type PagesGetByIdParams, type PagesGetBySlugParams, type PagesGetCommentsParams, type PagesListParams, PagesModule, type PaginatedResponse, type PaginationParams, type PublicConfig, type ReactParams, type ReactResponse, type ReactionType, type TypeSpecific, type TypedEntry
|
|
524
|
+
export { type AnnouncementEntry, type AnnouncementGetByIdParams, type AnnouncementGetCommentsParams, type AnnouncementListParams, AnnouncementModule, type AnnouncementType, type AnnouncementTypeSpecific, type AnyEntry, type ApiError, type BaseEntry, type BlogEntry, type BlogGetByIdParams, type BlogGetBySlugParams, type BlogGetCommentsParams, type BlogListParams, BlogModule, type BlogTypeSpecific, type ChangelogEntry, type ChangelogGetByIdParams, type ChangelogGetBySlugParams, type ChangelogGetCommentsParams, type ChangelogListParams, ChangelogModule, type ChangelogType, type ChangelogTypeSpecific, type ConfigListParams, ConfigModule, type CreateFeedbackCommentParams, type CreateFeedbackPostParams, type CreatedFeedbackComment, type CreatedFeedbackPost, type DeleteFeedbackCommentParams, type DeleteFeedbackCommentResponse, type DeleteFeedbackPostParams, type DeleteFeedbackPostResponse, type EntriesGetByIdParams, type EntriesGetBySlugParams, type EntriesGetCategoriesParams, type EntriesGetCommentsParams, type EntriesListParams, EntriesModule, type EntryAuthor, type EntryCategory, type EntryComment, type EntryStatus, type EntryTag, type EntryTagWithCount, type EntryType, type ExternalUser, type FeedbackAssignee, type FeedbackAuthor, type FeedbackComment, type FeedbackListParams, FeedbackModule, type FeedbackPost, type FeedbackPostCategory, type FeedbackPostListItem, type FeedbackPostStatus, type FeedbackSortOption, type FeedbackTopContributor, type FeedbackTopContributorsParams, type FeedbackVoteParams, type FeedbackVoteResponse, type GenericEntry, type HealthCheckResponse, type HelpArticleEntry, type HelpArticleTypeSpecific, type HelpArticleVisibility, type HelpCategoriesParams, type HelpChatMessage, type HelpChatParams, type HelpChatResponse, type HelpChatSource, type HelpChatSourceCategory, type HelpChatStreamChunk, type HelpGetByIdParams, type HelpGetBySlugParams, type HelpGetCommentsParams, type HelpListParams, HelpModule, type HelpSearchParams, type HelpSearchResult, Kookee, KookeeApiError, type KookeeConfig, type KookeeUser, type ListMyFeedbackPostsParams, type LocaleOptions, type OrderDirection, type PageEntry, type PageTypeSpecific, type PagesGetByIdParams, type PagesGetBySlugParams, type PagesGetCommentsParams, type PagesListParams, PagesModule, type PaginatedResponse, type PaginationParams, type PublicConfig, type ReactParams, type ReactResponse, type ReactionType, type TypeSpecific, type TypedEntry };
|
package/dist/index.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(exports){'use strict';var k="https://api.kookee.dev",
|
|
2
|
-
`);n=
|
|
1
|
+
(function(exports){'use strict';var k="https://api.kookee.dev",B="Kookee-API-Key",I="Kookee-Project-Id",i=class s extends Error{constructor(t,r,o){super(r);this.code=t;this.status=o;this.name="KookeeApiError",Object.setPrototypeOf(this,s.prototype);}},C=class{baseUrl;apiKey;projectId;constructor(e){this.apiKey=e.apiKey,this.projectId=e.projectId,this.baseUrl=e.baseUrl??k;}getHeaders(){let e={"Content-Type":"application/json"};return this.apiKey&&(e[B]=this.apiKey),this.projectId&&(e[I]=this.projectId),e}async get(e,t){let r=new URL(`${this.baseUrl}${e}`);if(t){for(let[h,n]of Object.entries(t))if(n!=null)if(Array.isArray(n))for(let a of n)r.searchParams.append(h,String(a));else r.searchParams.set(h,String(n));}let o=await fetch(r.toString(),{method:"GET",headers:this.getHeaders()});return this.handleResponse(o)}async post(e,t){let r=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:this.getHeaders(),body:t?JSON.stringify(t):void 0});return this.handleResponse(r)}async delete(e,t){let r=await fetch(`${this.baseUrl}${e}`,{method:"DELETE",headers:this.getHeaders(),body:t?JSON.stringify(t):void 0});return this.handleResponse(r)}async*streamPost(e,t){let r=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:{...this.getHeaders(),Accept:"text/event-stream"},body:t?JSON.stringify(t):void 0});if(!r.ok){let a=null;try{a=await r.json();}catch{}throw new i(a?.code??"UNKNOWN_ERROR",a?.message??`Request failed with status ${r.status}`,r.status)}if(!r.body)return;let o=r.body.getReader(),h=new TextDecoder,n="";try{for(;;){let{done:a,value:b}=await o.read();if(a)break;n+=h.decode(b,{stream:!0});let E=n.split(`
|
|
2
|
+
`);n=E.pop()??"";for(let x of E){let u=x.trim();if(!(!u||u.startsWith(":"))&&u.startsWith("data: ")){let R=u.slice(6);if(R==="[DONE]")return;yield JSON.parse(R);}}}}finally{o.releaseLock();}}async handleResponse(e){if(!e.ok){let t=null;try{t=await e.json();}catch{}throw new i(t?.code??"UNKNOWN_ERROR",t?.message??`Request failed with status ${e.status}`,e.status)}return e.json()}};var m=class{constructor(e){this.entries=e;}async list(e){return this.entries.list({type:"announcement",...e})}async getById(e,t){return this.entries.getById(e,t)}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getComments(e,t){return this.entries.getComments(e,t)}};var p=class{constructor(e){this.entries=e;}async list(e){return this.entries.list({type:"blog",...e})}async getBySlug(e,t){return this.entries.getBySlug(e,{type:"blog",...t})}async getById(e,t){return this.entries.getById(e,t)}async getTags(){return this.entries.getTags("blog")}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getTranslationsBySlug(e){return this.entries.getTranslationsBySlug(e)}async getComments(e,t){return this.entries.getComments(e,t)}async react(e,t){return this.entries.react(e,t)}};var c=class{constructor(e){this.entries=e;}async list(e){return this.entries.list({type:"changelog",...e})}async getBySlug(e,t){return this.entries.getBySlug(e,{type:"changelog",...t})}async getById(e,t){return this.entries.getById(e,t)}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getTranslationsBySlug(e){return this.entries.getTranslationsBySlug(e)}async getComments(e,t){return this.entries.getComments(e,t)}async react(e,t){return this.entries.react(e,t)}};var g=class{constructor(e){this.http=e;}async getByKey(e){return this.http.get(`/v1/config/${encodeURIComponent(e)}`)}async list(e){return this.http.get("/v1/config",e)}};var l=class{constructor(e){this.http=e;}async list(e){return this.http.get("/v1/entries",e)}async getById(e,t){return this.http.get(`/v1/entries/by-id/${encodeURIComponent(e)}`,t)}async getBySlug(e,t){return this.http.get(`/v1/entries/${encodeURIComponent(e)}`,t)}async getTranslationsById(e){return this.http.get(`/v1/entries/by-id/${encodeURIComponent(e)}/translations`)}async getTranslationsBySlug(e){return this.http.get(`/v1/entries/${encodeURIComponent(e)}/translations`)}async getComments(e,t){return this.http.get(`/v1/entries/${encodeURIComponent(e)}/comments`,t)}async react(e,t){return this.http.post(`/v1/entries/${encodeURIComponent(e)}/reactions`,t)}async getTags(e){return this.http.get("/v1/tags",{type:e})}async getCategories(e,t){return this.http.get("/v1/categories",{type:e,...t})}};var y=class{constructor(e,t){this.http=e;this.getUserContext=t;}async list(e){return this.http.get("/v1/feedback",e)}async getById(e){return this.http.get(`/v1/feedback/by-id/${encodeURIComponent(e)}`)}async vote(e,t){return this.http.post(`/v1/feedback/${encodeURIComponent(e)}/vote`,t)}async getTopContributors(e){return this.http.get("/v1/feedback/top-contributors",e)}async createPost(e){let t=e.externalUser??this.getUserContext();if(!t)throw new Error("No user identified. Call kookee.identify() first or pass externalUser in params.");return this.http.post("/v1/feedback",{...e,externalUser:t})}async createComment(e,t){let r=t.externalUser??this.getUserContext();if(!r)throw new Error("No user identified. Call kookee.identify() first or pass externalUser in params.");return this.http.post(`/v1/feedback/${encodeURIComponent(e)}/comments`,{...t,externalUser:r})}async listMyPosts(e){let t=e?.externalId??this.getUserContext()?.externalId;if(!t)throw new Error("No user identified. Call kookee.identify() first or pass externalId in params.");return this.http.get("/v1/feedback/mine",{...e,externalId:t})}async deletePost(e,t){let r=t?.externalId??this.getUserContext()?.externalId;if(!r)throw new Error("No user identified. Call kookee.identify() first or pass externalId in params.");return this.http.delete(`/v1/feedback/${encodeURIComponent(e)}`,{externalId:r})}async deleteComment(e,t){let r=t?.externalId??this.getUserContext()?.externalId;if(!r)throw new Error("No user identified. Call kookee.identify() first or pass externalId in params.");return this.http.delete(`/v1/feedback/comments/${encodeURIComponent(e)}`,{externalId:r})}};var d=class{http;entries;constructor(e,t){this.http=e,this.entries=t;}async categories(e){return this.entries.getCategories("help_article",e)}async list(e){return this.entries.list({type:"help_article",...e})}async getBySlug(e,t){return this.entries.getBySlug(e,{type:"help_article",...t})}async getById(e,t){return this.entries.getById(e,t)}async search(e){return this.http.get("/v1/help/search",e)}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getTranslationsBySlug(e){return this.entries.getTranslationsBySlug(e)}async getComments(e,t){return this.entries.getComments(e,t)}async react(e,t){return this.entries.react(e,t)}async chat(e){return this.http.post("/v1/help/chat",e)}chatStream(e){return this.http.streamPost("/v1/help/chat/stream",e)}};var P=class{constructor(e){this.entries=e;}async list(e){return this.entries.list({type:"page",...e})}async getBySlug(e,t){return this.entries.getBySlug(e,{type:"page",...t})}async getById(e,t){return this.entries.getById(e,t)}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getTranslationsBySlug(e){return this.entries.getTranslationsBySlug(e)}async getComments(e,t){return this.entries.getComments(e,t)}};var f=class{http;user=null;entries;announcements;blog;changelog;config;feedback;help;pages;constructor(e){if(!e.apiKey&&!e.projectId)throw new Error("Either apiKey or projectId is required");this.http=new C({apiKey:e.apiKey,projectId:e.projectId,baseUrl:e.baseUrl}),this.entries=new l(this.http),this.announcements=new m(this.entries),this.blog=new p(this.entries),this.changelog=new c(this.entries),this.config=new g(this.http),this.feedback=new y(this.http,()=>this.user),this.help=new d(this.http,this.entries),this.pages=new P(this.entries);}identify(e){this.user=e;}reset(){this.user=null;}getUser(){return this.user}async health(){return this.http.get("/v1/health")}};exports.AnnouncementModule=m;exports.BlogModule=p;exports.ChangelogModule=c;exports.ConfigModule=g;exports.EntriesModule=l;exports.FeedbackModule=y;exports.HelpModule=d;exports.Kookee=f;exports.KookeeApiError=i;exports.PagesModule=P;return exports;})({});
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var k="https://api.kookee.dev",
|
|
2
|
-
`);n=
|
|
1
|
+
var k="https://api.kookee.dev",B="Kookee-API-Key",I="Kookee-Project-Id",i=class s extends Error{constructor(t,r,o){super(r);this.code=t;this.status=o;this.name="KookeeApiError",Object.setPrototypeOf(this,s.prototype);}},C=class{baseUrl;apiKey;projectId;constructor(e){this.apiKey=e.apiKey,this.projectId=e.projectId,this.baseUrl=e.baseUrl??k;}getHeaders(){let e={"Content-Type":"application/json"};return this.apiKey&&(e[B]=this.apiKey),this.projectId&&(e[I]=this.projectId),e}async get(e,t){let r=new URL(`${this.baseUrl}${e}`);if(t){for(let[h,n]of Object.entries(t))if(n!=null)if(Array.isArray(n))for(let a of n)r.searchParams.append(h,String(a));else r.searchParams.set(h,String(n));}let o=await fetch(r.toString(),{method:"GET",headers:this.getHeaders()});return this.handleResponse(o)}async post(e,t){let r=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:this.getHeaders(),body:t?JSON.stringify(t):void 0});return this.handleResponse(r)}async delete(e,t){let r=await fetch(`${this.baseUrl}${e}`,{method:"DELETE",headers:this.getHeaders(),body:t?JSON.stringify(t):void 0});return this.handleResponse(r)}async*streamPost(e,t){let r=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:{...this.getHeaders(),Accept:"text/event-stream"},body:t?JSON.stringify(t):void 0});if(!r.ok){let a=null;try{a=await r.json();}catch{}throw new i(a?.code??"UNKNOWN_ERROR",a?.message??`Request failed with status ${r.status}`,r.status)}if(!r.body)return;let o=r.body.getReader(),h=new TextDecoder,n="";try{for(;;){let{done:a,value:b}=await o.read();if(a)break;n+=h.decode(b,{stream:!0});let E=n.split(`
|
|
2
|
+
`);n=E.pop()??"";for(let x of E){let u=x.trim();if(!(!u||u.startsWith(":"))&&u.startsWith("data: ")){let R=u.slice(6);if(R==="[DONE]")return;yield JSON.parse(R);}}}}finally{o.releaseLock();}}async handleResponse(e){if(!e.ok){let t=null;try{t=await e.json();}catch{}throw new i(t?.code??"UNKNOWN_ERROR",t?.message??`Request failed with status ${e.status}`,e.status)}return e.json()}};var m=class{constructor(e){this.entries=e;}async list(e){return this.entries.list({type:"announcement",...e})}async getById(e,t){return this.entries.getById(e,t)}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getComments(e,t){return this.entries.getComments(e,t)}};var p=class{constructor(e){this.entries=e;}async list(e){return this.entries.list({type:"blog",...e})}async getBySlug(e,t){return this.entries.getBySlug(e,{type:"blog",...t})}async getById(e,t){return this.entries.getById(e,t)}async getTags(){return this.entries.getTags("blog")}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getTranslationsBySlug(e){return this.entries.getTranslationsBySlug(e)}async getComments(e,t){return this.entries.getComments(e,t)}async react(e,t){return this.entries.react(e,t)}};var c=class{constructor(e){this.entries=e;}async list(e){return this.entries.list({type:"changelog",...e})}async getBySlug(e,t){return this.entries.getBySlug(e,{type:"changelog",...t})}async getById(e,t){return this.entries.getById(e,t)}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getTranslationsBySlug(e){return this.entries.getTranslationsBySlug(e)}async getComments(e,t){return this.entries.getComments(e,t)}async react(e,t){return this.entries.react(e,t)}};var g=class{constructor(e){this.http=e;}async getByKey(e){return this.http.get(`/v1/config/${encodeURIComponent(e)}`)}async list(e){return this.http.get("/v1/config",e)}};var l=class{constructor(e){this.http=e;}async list(e){return this.http.get("/v1/entries",e)}async getById(e,t){return this.http.get(`/v1/entries/by-id/${encodeURIComponent(e)}`,t)}async getBySlug(e,t){return this.http.get(`/v1/entries/${encodeURIComponent(e)}`,t)}async getTranslationsById(e){return this.http.get(`/v1/entries/by-id/${encodeURIComponent(e)}/translations`)}async getTranslationsBySlug(e){return this.http.get(`/v1/entries/${encodeURIComponent(e)}/translations`)}async getComments(e,t){return this.http.get(`/v1/entries/${encodeURIComponent(e)}/comments`,t)}async react(e,t){return this.http.post(`/v1/entries/${encodeURIComponent(e)}/reactions`,t)}async getTags(e){return this.http.get("/v1/tags",{type:e})}async getCategories(e,t){return this.http.get("/v1/categories",{type:e,...t})}};var y=class{constructor(e,t){this.http=e;this.getUserContext=t;}async list(e){return this.http.get("/v1/feedback",e)}async getById(e){return this.http.get(`/v1/feedback/by-id/${encodeURIComponent(e)}`)}async vote(e,t){return this.http.post(`/v1/feedback/${encodeURIComponent(e)}/vote`,t)}async getTopContributors(e){return this.http.get("/v1/feedback/top-contributors",e)}async createPost(e){let t=e.externalUser??this.getUserContext();if(!t)throw new Error("No user identified. Call kookee.identify() first or pass externalUser in params.");return this.http.post("/v1/feedback",{...e,externalUser:t})}async createComment(e,t){let r=t.externalUser??this.getUserContext();if(!r)throw new Error("No user identified. Call kookee.identify() first or pass externalUser in params.");return this.http.post(`/v1/feedback/${encodeURIComponent(e)}/comments`,{...t,externalUser:r})}async listMyPosts(e){let t=e?.externalId??this.getUserContext()?.externalId;if(!t)throw new Error("No user identified. Call kookee.identify() first or pass externalId in params.");return this.http.get("/v1/feedback/mine",{...e,externalId:t})}async deletePost(e,t){let r=t?.externalId??this.getUserContext()?.externalId;if(!r)throw new Error("No user identified. Call kookee.identify() first or pass externalId in params.");return this.http.delete(`/v1/feedback/${encodeURIComponent(e)}`,{externalId:r})}async deleteComment(e,t){let r=t?.externalId??this.getUserContext()?.externalId;if(!r)throw new Error("No user identified. Call kookee.identify() first or pass externalId in params.");return this.http.delete(`/v1/feedback/comments/${encodeURIComponent(e)}`,{externalId:r})}};var d=class{http;entries;constructor(e,t){this.http=e,this.entries=t;}async categories(e){return this.entries.getCategories("help_article",e)}async list(e){return this.entries.list({type:"help_article",...e})}async getBySlug(e,t){return this.entries.getBySlug(e,{type:"help_article",...t})}async getById(e,t){return this.entries.getById(e,t)}async search(e){return this.http.get("/v1/help/search",e)}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getTranslationsBySlug(e){return this.entries.getTranslationsBySlug(e)}async getComments(e,t){return this.entries.getComments(e,t)}async react(e,t){return this.entries.react(e,t)}async chat(e){return this.http.post("/v1/help/chat",e)}chatStream(e){return this.http.streamPost("/v1/help/chat/stream",e)}};var P=class{constructor(e){this.entries=e;}async list(e){return this.entries.list({type:"page",...e})}async getBySlug(e,t){return this.entries.getBySlug(e,{type:"page",...t})}async getById(e,t){return this.entries.getById(e,t)}async getTranslationsById(e){return this.entries.getTranslationsById(e)}async getTranslationsBySlug(e){return this.entries.getTranslationsBySlug(e)}async getComments(e,t){return this.entries.getComments(e,t)}};var f=class{http;user=null;entries;announcements;blog;changelog;config;feedback;help;pages;constructor(e){if(!e.apiKey&&!e.projectId)throw new Error("Either apiKey or projectId is required");this.http=new C({apiKey:e.apiKey,projectId:e.projectId,baseUrl:e.baseUrl}),this.entries=new l(this.http),this.announcements=new m(this.entries),this.blog=new p(this.entries),this.changelog=new c(this.entries),this.config=new g(this.http),this.feedback=new y(this.http,()=>this.user),this.help=new d(this.http,this.entries),this.pages=new P(this.entries);}identify(e){this.user=e;}reset(){this.user=null;}getUser(){return this.user}async health(){return this.http.get("/v1/health")}};export{m as AnnouncementModule,p as BlogModule,c as ChangelogModule,g as ConfigModule,l as EntriesModule,y as FeedbackModule,d as HelpModule,f as Kookee,i as KookeeApiError,P as PagesModule};
|