@kookee/sdk 0.0.40 → 0.0.42
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 +12 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +8 -5
- package/dist/index.d.ts +8 -5
- package/dist/index.global.js +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -125,8 +125,11 @@ const articles = await kookee.help.list({ page: 1, limit: 10 });
|
|
|
125
125
|
// Filter by category slug
|
|
126
126
|
const categoryArticles = await kookee.help.list({ category: 'getting-started' });
|
|
127
127
|
|
|
128
|
-
// Semantic search
|
|
128
|
+
// Semantic search — results include a matched text snippet when available
|
|
129
129
|
const results = await kookee.help.search({ query: 'how to reset password', limit: 5 });
|
|
130
|
+
for (const result of results) {
|
|
131
|
+
console.log(result.title, result.matchedChunk); // matched text snippet or null
|
|
132
|
+
}
|
|
130
133
|
|
|
131
134
|
// Get single article
|
|
132
135
|
const article = await kookee.help.getBySlug('getting-started');
|
|
@@ -166,6 +169,9 @@ const entries = await kookee.changelog.list({ page: 1, limit: 10 });
|
|
|
166
169
|
// Search entries
|
|
167
170
|
const results = await kookee.changelog.list({ search: 'authentication' });
|
|
168
171
|
|
|
172
|
+
// Filter by typeSpecific properties (e.g. changelog type)
|
|
173
|
+
const features = await kookee.changelog.list({ filter: { changelogType: 'feature' } });
|
|
174
|
+
|
|
169
175
|
// Get single entry
|
|
170
176
|
const entry = await kookee.changelog.getBySlug('v1-0-0');
|
|
171
177
|
const entryById = await kookee.changelog.getById('entry-uuid');
|
|
@@ -227,6 +233,9 @@ The `entries` module provides low-level access to all entry types through a unif
|
|
|
227
233
|
const blogPosts = await kookee.entries.list({ type: 'blog', page: 1, limit: 10 });
|
|
228
234
|
const articles = await kookee.entries.list({ type: 'help_article', category: 'getting-started' });
|
|
229
235
|
|
|
236
|
+
// Filter by typeSpecific properties
|
|
237
|
+
const features = await kookee.entries.list({ type: 'changelog', filter: { changelogType: 'feature' } });
|
|
238
|
+
|
|
230
239
|
// Get entry by slug or ID
|
|
231
240
|
const entry = await kookee.entries.getBySlug('my-post', { type: 'blog' });
|
|
232
241
|
const entryById = await kookee.entries.getById('entry-uuid');
|
|
@@ -392,7 +401,8 @@ interface PaginatedResponse<T> {
|
|
|
392
401
|
|
|
393
402
|
Entry endpoints come in two flavours with **different shapes**:
|
|
394
403
|
|
|
395
|
-
- **List responses** (`blog.list()`, `
|
|
404
|
+
- **List responses** (`blog.list()`, `entries.list()`, …) return `*ListItem` types — these do **not** include `contentHtml`. Use `excerptHtml` instead for previews.
|
|
405
|
+
- **Search responses** (`help.search()`) return `HelpSearchResult` which extends the list item with `matchedChunk: string | null` — a plain-text snippet from the best matching section of the article.
|
|
396
406
|
- **Detail responses** (`blog.getBySlug()`, `help.getById()`, …) return `*Detail` types — these include `contentHtml` for full content rendering.
|
|
397
407
|
|
|
398
408
|
```typescript
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
`);r=
|
|
1
|
+
'use strict';var x="https://api.kookee.dev",I="Kookee-API-Key",B="Kookee-Project-Id",l=class n extends Error{constructor(t,s,o){super(s);this.code=t;this.status=o;this.name="KookeeApiError",Object.setPrototypeOf(this,n.prototype);}},f=class{baseUrl;apiKey;projectId;constructor(e){this.apiKey=e.apiKey,this.projectId=e.projectId,this.baseUrl=e.baseUrl??x;}getHeaders(){let e={"Content-Type":"application/json"};return this.apiKey&&(e[I]=this.apiKey),this.projectId&&(e[B]=this.projectId),e}async get(e,t){let s=new URL(`${this.baseUrl}${e}`);if(t){for(let[i,r]of Object.entries(t))if(r!=null)if(Array.isArray(r))for(let a of r)s.searchParams.append(i,String(a));else if(typeof r=="object")for(let[a,m]of Object.entries(r))m!=null&&s.searchParams.set(`${i}[${a}]`,String(m));else s.searchParams.set(i,String(r));}let o=await fetch(s.toString(),{method:"GET",headers:this.getHeaders()});return this.handleResponse(o)}async post(e,t){let s=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:this.getHeaders(),body:t?JSON.stringify(t):void 0});return this.handleResponse(s)}async delete(e,t){let s=await fetch(`${this.baseUrl}${e}`,{method:"DELETE",headers:this.getHeaders(),body:t?JSON.stringify(t):void 0});return this.handleResponse(s)}async*streamPost(e,t){let s=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:{...this.getHeaders(),Accept:"text/event-stream"},body:t?JSON.stringify(t):void 0});if(!s.ok){let a=null;try{a=await s.json();}catch{}throw new l(a?.code??"UNKNOWN_ERROR",a?.message??`Request failed with status ${s.status}`,s.status)}if(!s.body)return;let o=s.body.getReader(),i=new TextDecoder,r="";try{for(;;){let{done:a,value:m}=await o.read();if(a)break;r+=i.decode(m,{stream:!0});let b=r.split(`
|
|
2
|
+
`);r=b.pop()??"";for(let R of b){let C=R.trim();if(!(!C||C.startsWith(":"))&&C.startsWith("data: ")){let k=C.slice(6);if(k==="[DONE]")return;yield JSON.parse(k);}}}}finally{o.releaseLock();}}async handleResponse(e){if(!e.ok){let t=null;try{t=await e.json();}catch{}throw new l(t?.code??"UNKNOWN_ERROR",t?.message??`Request failed with status ${e.status}`,e.status)}return e.json()}};var p=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 c=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 g=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 y=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 d=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 P=class{constructor(e,t){this.http=e;this.getUserContext=t;}async getColumns(){return this.http.get("/v1/feedback/columns")}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 s=t.externalUser??this.getUserContext();if(!s)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:s})}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 s=t?.externalId??this.getUserContext()?.externalId;if(!s)throw new Error("No user identified. Call kookee.identify() first or pass externalId in params.");return this.http.delete(`/v1/feedback/${encodeURIComponent(e)}`,{externalId:s})}async deleteComment(e,t){let s=t?.externalId??this.getUserContext()?.externalId;if(!s)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:s})}};var u=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 h=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 E=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 f({apiKey:e.apiKey,projectId:e.projectId,baseUrl:e.baseUrl}),this.entries=new d(this.http),this.announcements=new p(this.entries),this.blog=new c(this.entries),this.changelog=new g(this.entries),this.config=new y(this.http),this.feedback=new P(this.http,()=>this.user),this.help=new u(this.http,this.entries),this.pages=new h(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=p;exports.BlogModule=c;exports.ChangelogModule=g;exports.ConfigModule=y;exports.EntriesModule=d;exports.FeedbackModule=P;exports.HelpModule=u;exports.Kookee=E;exports.KookeeApiError=l;exports.PagesModule=h;
|
package/dist/index.d.cts
CHANGED
|
@@ -360,12 +360,13 @@ type AnyEntryDetail = TypedEntryDetail | GenericEntryDetail;
|
|
|
360
360
|
/**
|
|
361
361
|
* Help search result — returned by `GET /v1/help/search`.
|
|
362
362
|
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
* about both).
|
|
363
|
+
* Extends `HelpArticleListItem` with `matchedChunk` — a plain-text snippet
|
|
364
|
+
* from the article that best matched the search query (via embedding similarity).
|
|
365
|
+
* When the server falls back to text search, `matchedChunk` is `null`.
|
|
367
366
|
*/
|
|
368
|
-
|
|
367
|
+
interface HelpSearchResult extends HelpArticleListItem {
|
|
368
|
+
matchedChunk: string | null;
|
|
369
|
+
}
|
|
369
370
|
/**
|
|
370
371
|
* Translation summary returned by the translations endpoints.
|
|
371
372
|
*
|
|
@@ -408,6 +409,7 @@ interface EntriesListParams extends PaginationParams, LocaleOptions {
|
|
|
408
409
|
tags?: string[];
|
|
409
410
|
category?: string;
|
|
410
411
|
search?: string;
|
|
412
|
+
filter?: Record<string, string>;
|
|
411
413
|
}
|
|
412
414
|
interface EntriesGetByIdParams extends LocaleOptions {
|
|
413
415
|
}
|
|
@@ -472,6 +474,7 @@ declare class BlogModule {
|
|
|
472
474
|
|
|
473
475
|
interface ChangelogListParams extends PaginationParams, LocaleOptions {
|
|
474
476
|
search?: string;
|
|
477
|
+
filter?: Record<string, string>;
|
|
475
478
|
}
|
|
476
479
|
interface ChangelogGetBySlugParams extends LocaleOptions {
|
|
477
480
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -360,12 +360,13 @@ type AnyEntryDetail = TypedEntryDetail | GenericEntryDetail;
|
|
|
360
360
|
/**
|
|
361
361
|
* Help search result — returned by `GET /v1/help/search`.
|
|
362
362
|
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
* about both).
|
|
363
|
+
* Extends `HelpArticleListItem` with `matchedChunk` — a plain-text snippet
|
|
364
|
+
* from the article that best matched the search query (via embedding similarity).
|
|
365
|
+
* When the server falls back to text search, `matchedChunk` is `null`.
|
|
367
366
|
*/
|
|
368
|
-
|
|
367
|
+
interface HelpSearchResult extends HelpArticleListItem {
|
|
368
|
+
matchedChunk: string | null;
|
|
369
|
+
}
|
|
369
370
|
/**
|
|
370
371
|
* Translation summary returned by the translations endpoints.
|
|
371
372
|
*
|
|
@@ -408,6 +409,7 @@ interface EntriesListParams extends PaginationParams, LocaleOptions {
|
|
|
408
409
|
tags?: string[];
|
|
409
410
|
category?: string;
|
|
410
411
|
search?: string;
|
|
412
|
+
filter?: Record<string, string>;
|
|
411
413
|
}
|
|
412
414
|
interface EntriesGetByIdParams extends LocaleOptions {
|
|
413
415
|
}
|
|
@@ -472,6 +474,7 @@ declare class BlogModule {
|
|
|
472
474
|
|
|
473
475
|
interface ChangelogListParams extends PaginationParams, LocaleOptions {
|
|
474
476
|
search?: string;
|
|
477
|
+
filter?: Record<string, string>;
|
|
475
478
|
}
|
|
476
479
|
interface ChangelogGetBySlugParams extends LocaleOptions {
|
|
477
480
|
}
|
package/dist/index.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(exports){'use strict';var
|
|
2
|
-
`);r=
|
|
1
|
+
(function(exports){'use strict';var x="https://api.kookee.dev",I="Kookee-API-Key",B="Kookee-Project-Id",l=class n extends Error{constructor(t,s,o){super(s);this.code=t;this.status=o;this.name="KookeeApiError",Object.setPrototypeOf(this,n.prototype);}},f=class{baseUrl;apiKey;projectId;constructor(e){this.apiKey=e.apiKey,this.projectId=e.projectId,this.baseUrl=e.baseUrl??x;}getHeaders(){let e={"Content-Type":"application/json"};return this.apiKey&&(e[I]=this.apiKey),this.projectId&&(e[B]=this.projectId),e}async get(e,t){let s=new URL(`${this.baseUrl}${e}`);if(t){for(let[i,r]of Object.entries(t))if(r!=null)if(Array.isArray(r))for(let a of r)s.searchParams.append(i,String(a));else if(typeof r=="object")for(let[a,m]of Object.entries(r))m!=null&&s.searchParams.set(`${i}[${a}]`,String(m));else s.searchParams.set(i,String(r));}let o=await fetch(s.toString(),{method:"GET",headers:this.getHeaders()});return this.handleResponse(o)}async post(e,t){let s=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:this.getHeaders(),body:t?JSON.stringify(t):void 0});return this.handleResponse(s)}async delete(e,t){let s=await fetch(`${this.baseUrl}${e}`,{method:"DELETE",headers:this.getHeaders(),body:t?JSON.stringify(t):void 0});return this.handleResponse(s)}async*streamPost(e,t){let s=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:{...this.getHeaders(),Accept:"text/event-stream"},body:t?JSON.stringify(t):void 0});if(!s.ok){let a=null;try{a=await s.json();}catch{}throw new l(a?.code??"UNKNOWN_ERROR",a?.message??`Request failed with status ${s.status}`,s.status)}if(!s.body)return;let o=s.body.getReader(),i=new TextDecoder,r="";try{for(;;){let{done:a,value:m}=await o.read();if(a)break;r+=i.decode(m,{stream:!0});let b=r.split(`
|
|
2
|
+
`);r=b.pop()??"";for(let R of b){let C=R.trim();if(!(!C||C.startsWith(":"))&&C.startsWith("data: ")){let k=C.slice(6);if(k==="[DONE]")return;yield JSON.parse(k);}}}}finally{o.releaseLock();}}async handleResponse(e){if(!e.ok){let t=null;try{t=await e.json();}catch{}throw new l(t?.code??"UNKNOWN_ERROR",t?.message??`Request failed with status ${e.status}`,e.status)}return e.json()}};var p=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 c=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 g=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 y=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 d=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 P=class{constructor(e,t){this.http=e;this.getUserContext=t;}async getColumns(){return this.http.get("/v1/feedback/columns")}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 s=t.externalUser??this.getUserContext();if(!s)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:s})}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 s=t?.externalId??this.getUserContext()?.externalId;if(!s)throw new Error("No user identified. Call kookee.identify() first or pass externalId in params.");return this.http.delete(`/v1/feedback/${encodeURIComponent(e)}`,{externalId:s})}async deleteComment(e,t){let s=t?.externalId??this.getUserContext()?.externalId;if(!s)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:s})}};var u=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 h=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 E=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 f({apiKey:e.apiKey,projectId:e.projectId,baseUrl:e.baseUrl}),this.entries=new d(this.http),this.announcements=new p(this.entries),this.blog=new c(this.entries),this.changelog=new g(this.entries),this.config=new y(this.http),this.feedback=new P(this.http,()=>this.user),this.help=new u(this.http,this.entries),this.pages=new h(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=p;exports.BlogModule=c;exports.ChangelogModule=g;exports.ConfigModule=y;exports.EntriesModule=d;exports.FeedbackModule=P;exports.HelpModule=u;exports.Kookee=E;exports.KookeeApiError=l;exports.PagesModule=h;return exports;})({});
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
`);r=
|
|
1
|
+
var x="https://api.kookee.dev",I="Kookee-API-Key",B="Kookee-Project-Id",l=class n extends Error{constructor(t,s,o){super(s);this.code=t;this.status=o;this.name="KookeeApiError",Object.setPrototypeOf(this,n.prototype);}},f=class{baseUrl;apiKey;projectId;constructor(e){this.apiKey=e.apiKey,this.projectId=e.projectId,this.baseUrl=e.baseUrl??x;}getHeaders(){let e={"Content-Type":"application/json"};return this.apiKey&&(e[I]=this.apiKey),this.projectId&&(e[B]=this.projectId),e}async get(e,t){let s=new URL(`${this.baseUrl}${e}`);if(t){for(let[i,r]of Object.entries(t))if(r!=null)if(Array.isArray(r))for(let a of r)s.searchParams.append(i,String(a));else if(typeof r=="object")for(let[a,m]of Object.entries(r))m!=null&&s.searchParams.set(`${i}[${a}]`,String(m));else s.searchParams.set(i,String(r));}let o=await fetch(s.toString(),{method:"GET",headers:this.getHeaders()});return this.handleResponse(o)}async post(e,t){let s=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:this.getHeaders(),body:t?JSON.stringify(t):void 0});return this.handleResponse(s)}async delete(e,t){let s=await fetch(`${this.baseUrl}${e}`,{method:"DELETE",headers:this.getHeaders(),body:t?JSON.stringify(t):void 0});return this.handleResponse(s)}async*streamPost(e,t){let s=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:{...this.getHeaders(),Accept:"text/event-stream"},body:t?JSON.stringify(t):void 0});if(!s.ok){let a=null;try{a=await s.json();}catch{}throw new l(a?.code??"UNKNOWN_ERROR",a?.message??`Request failed with status ${s.status}`,s.status)}if(!s.body)return;let o=s.body.getReader(),i=new TextDecoder,r="";try{for(;;){let{done:a,value:m}=await o.read();if(a)break;r+=i.decode(m,{stream:!0});let b=r.split(`
|
|
2
|
+
`);r=b.pop()??"";for(let R of b){let C=R.trim();if(!(!C||C.startsWith(":"))&&C.startsWith("data: ")){let k=C.slice(6);if(k==="[DONE]")return;yield JSON.parse(k);}}}}finally{o.releaseLock();}}async handleResponse(e){if(!e.ok){let t=null;try{t=await e.json();}catch{}throw new l(t?.code??"UNKNOWN_ERROR",t?.message??`Request failed with status ${e.status}`,e.status)}return e.json()}};var p=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 c=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 g=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 y=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 d=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 P=class{constructor(e,t){this.http=e;this.getUserContext=t;}async getColumns(){return this.http.get("/v1/feedback/columns")}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 s=t.externalUser??this.getUserContext();if(!s)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:s})}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 s=t?.externalId??this.getUserContext()?.externalId;if(!s)throw new Error("No user identified. Call kookee.identify() first or pass externalId in params.");return this.http.delete(`/v1/feedback/${encodeURIComponent(e)}`,{externalId:s})}async deleteComment(e,t){let s=t?.externalId??this.getUserContext()?.externalId;if(!s)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:s})}};var u=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 h=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 E=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 f({apiKey:e.apiKey,projectId:e.projectId,baseUrl:e.baseUrl}),this.entries=new d(this.http),this.announcements=new p(this.entries),this.blog=new c(this.entries),this.changelog=new g(this.entries),this.config=new y(this.http),this.feedback=new P(this.http,()=>this.user),this.help=new u(this.http,this.entries),this.pages=new h(this.entries);}identify(e){this.user=e;}reset(){this.user=null;}getUser(){return this.user}async health(){return this.http.get("/v1/health")}};export{p as AnnouncementModule,c as BlogModule,g as ChangelogModule,y as ConfigModule,d as EntriesModule,P as FeedbackModule,u as HelpModule,E as Kookee,l as KookeeApiError,h as PagesModule};
|