@kookee/sdk 0.0.8 → 0.0.11
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 +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -2
- package/dist/index.d.ts +28 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
exports.BlogModule=
|
|
1
|
+
'use strict';var P="https://api.kookee.dev",c="Kookee-API-Key",n=class extends Error{constructor(e,s,l){super(s);this.code=e;this.status=l;this.name="KookeeApiError";}},p=class{baseUrl;apiKey;constructor(t,e){this.apiKey=t,this.baseUrl=e??P;}getHeaders(){return {"Content-Type":"application/json",[c]:this.apiKey}}async get(t,e){let s=new URL(`${this.baseUrl}${t}`);if(e){for(let[m,r]of Object.entries(e))if(r!=null)if(Array.isArray(r))for(let h of r)s.searchParams.append(m,String(h));else s.searchParams.set(m,String(r));}let l=await fetch(s.toString(),{method:"GET",headers:this.getHeaders()});return this.handleResponse(l)}async post(t,e){let s=await fetch(`${this.baseUrl}${t}`,{method:"POST",headers:this.getHeaders(),body:e?JSON.stringify(e):void 0});return this.handleResponse(s)}async handleResponse(t){if(!t.ok){let e=null;try{e=await t.json();}catch{}throw new n(e?.code??"UNKNOWN_ERROR",e?.message??`Request failed with status ${t.status}`,t.status)}return t.json()}};var o=class{constructor(t){this.http=t;}async list(t){return this.http.get("/v1/blog/posts",t)}async getBySlug(t){return this.http.get(`/v1/blog/posts/${encodeURIComponent(t)}`)}async getById(t){return this.http.get(`/v1/blog/posts/by-id/${encodeURIComponent(t)}`)}async getTags(){return this.http.get("/v1/blog/tags")}};var a=class{constructor(t){this.http=t;}async list(t){return this.http.get("/v1/pages",t)}async getBySlug(t){return this.http.get(`/v1/pages/${encodeURIComponent(t)}`)}async getById(t){return this.http.get(`/v1/pages/by-id/${encodeURIComponent(t)}`)}};var g=class{http;blog;pages;constructor(t){if(!t.apiKey)throw new Error("apiKey is required");this.http=new p(t.apiKey,t.baseUrl),this.blog=new o(this.http),this.pages=new a(this.http);}};
|
|
2
|
+
exports.BlogModule=o;exports.Kookee=g;exports.KookeeApiError=n;exports.PagesModule=a;//# sourceMappingURL=index.cjs.map
|
|
3
3
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/http-client.ts","../src/lib/modules/blog.ts","../src/lib/client.ts"],"names":["DEFAULT_BASE_URL","API_KEY_HEADER","KookeeApiError","code","message","status","HttpClient","apiKey","baseUrl","path","params","url","key","value","response","body","errorData","BlogModule","http","slug","id","Kookee","config"],"mappings":"aAEA,IAAMA,
|
|
1
|
+
{"version":3,"sources":["../src/lib/http-client.ts","../src/lib/modules/blog.ts","../src/lib/modules/pages.ts","../src/lib/client.ts"],"names":["DEFAULT_BASE_URL","API_KEY_HEADER","KookeeApiError","code","message","status","HttpClient","apiKey","baseUrl","path","params","url","key","value","item","response","body","errorData","BlogModule","http","slug","id","PagesModule","Kookee","config"],"mappings":"aAEA,IAAMA,EAAmB,wBAAA,CACnBC,CAAAA,CAAiB,iBAEVC,CAAAA,CAAN,cAA6B,KAAM,CACxC,WAAA,CACkBC,EAChBC,CAAAA,CACgBC,CAAAA,CAChB,CACA,KAAA,CAAMD,CAAO,EAJG,IAAA,CAAA,IAAA,CAAAD,CAAAA,CAEA,YAAAE,CAAAA,CAGhB,IAAA,CAAK,IAAA,CAAO,iBACd,CACF,CAAA,CAEaC,CAAAA,CAAN,KAAiB,CACL,OAAA,CACA,OAEjB,WAAA,CAAYC,CAAAA,CAAgBC,EAAkB,CAC5C,IAAA,CAAK,OAASD,CAAAA,CACd,IAAA,CAAK,QAAUC,CAAAA,EAAWR,EAC5B,CAEQ,UAAA,EAAqC,CAC3C,OAAO,CACL,eAAgB,kB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,CAAE,CACxE,CACF,EChBO,IAAME,CAAAA,CAAN,KAAa,CACD,IAAA,CAED,KACA,KAAA,CAEhB,WAAA,CAAYC,EAAsB,CAChC,GAAI,CAACA,CAAAA,CAAO,MAAA,CACV,MAAM,IAAI,KAAA,CAAM,oBAAoB,CAAA,CAGtC,IAAA,CAAK,KAAO,IAAIlB,CAAAA,CAAWkB,EAAO,MAAA,CAAQA,CAAAA,CAAO,OAAO,CAAA,CAExD,IAAA,CAAK,KAAO,IAAIN,CAAAA,CAAW,KAAK,IAAI,CAAA,CACpC,KAAK,KAAA,CAAQ,IAAII,EAAY,IAAA,CAAK,IAAI,EACxC,CACF","file":"index.cjs","sourcesContent":["import type { ApiError } from './types';\n\nconst DEFAULT_BASE_URL = 'https://api.kookee.dev';\nconst API_KEY_HEADER = 'Kookee-API-Key';\n\nexport class KookeeApiError extends Error {\n constructor(\n public readonly code: string,\n message: string,\n public readonly status: number\n ) {\n super(message);\n this.name = 'KookeeApiError';\n }\n}\n\nexport class HttpClient {\n private readonly baseUrl: string;\n private readonly apiKey: string;\n\n constructor(apiKey: string, baseUrl?: string) {\n this.apiKey = apiKey;\n this.baseUrl = baseUrl ?? DEFAULT_BASE_URL;\n }\n\n private getHeaders(): Record<string, string> {\n return {\n 'Content-Type': 'application/json',\n [API_KEY_HEADER]: this.apiKey,\n };\n }\n\n async get<T>(path: string, params?: object): Promise<T> {\n const url = new URL(`${this.baseUrl}${path}`);\n\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined && value !== null) {\n if (Array.isArray(value)) {\n for (const item of value) {\n url.searchParams.append(key, String(item));\n }\n } else {\n url.searchParams.set(key, String(value));\n }\n }\n }\n }\n\n const response = await fetch(url.toString(), {\n method: 'GET',\n headers: this.getHeaders(),\n });\n\n return this.handleResponse<T>(response);\n }\n\n async post<T>(path: string, body?: unknown): Promise<T> {\n const response = await fetch(`${this.baseUrl}${path}`, {\n method: 'POST',\n headers: this.getHeaders(),\n body: body ? JSON.stringify(body) : undefined,\n });\n\n return this.handleResponse<T>(response);\n }\n\n private async handleResponse<T>(response: Response): Promise<T> {\n if (!response.ok) {\n let errorData: ApiError | null = null;\n\n try {\n errorData = (await response.json()) as ApiError;\n } catch {\n // Response body is not JSON\n }\n\n throw new KookeeApiError(\n errorData?.code ?? 'UNKNOWN_ERROR',\n errorData?.message ?? `Request failed with status ${response.status}`,\n response.status\n );\n }\n\n return response.json() as Promise<T>;\n }\n}\n","import type { HttpClient } from '../http-client';\nimport type { BlogPost, BlogPostListItem, BlogTagWithCount, PaginatedResponse, PaginationParams } from '../types';\n\nexport interface BlogListParams extends PaginationParams {\n tags?: string[];\n search?: string;\n}\n\nexport class BlogModule {\n constructor(private readonly http: HttpClient) {}\n\n async list(params?: BlogListParams): Promise<PaginatedResponse<BlogPostListItem>> {\n return this.http.get<PaginatedResponse<BlogPostListItem>>('/v1/blog/posts', params);\n }\n\n async getBySlug(slug: string): Promise<BlogPost> {\n return this.http.get<BlogPost>(`/v1/blog/posts/${encodeURIComponent(slug)}`);\n }\n\n async getById(id: string): Promise<BlogPost> {\n return this.http.get<BlogPost>(`/v1/blog/posts/by-id/${encodeURIComponent(id)}`);\n }\n\n async getTags(): Promise<BlogTagWithCount[]> {\n return this.http.get<BlogTagWithCount[]>('/v1/blog/tags');\n }\n}\n","import type { HttpClient } from '../http-client';\nimport type { Page, PageListItem, PaginatedResponse, PaginationParams } from '../types';\n\nexport interface PagesListParams extends PaginationParams {\n search?: string;\n}\n\nexport class PagesModule {\n constructor(private readonly http: HttpClient) {}\n\n async list(params?: PagesListParams): Promise<PaginatedResponse<PageListItem>> {\n return this.http.get<PaginatedResponse<PageListItem>>('/v1/pages', params);\n }\n\n async getBySlug(slug: string): Promise<Page> {\n return this.http.get<Page>(`/v1/pages/${encodeURIComponent(slug)}`);\n }\n\n async getById(id: string): Promise<Page> {\n return this.http.get<Page>(`/v1/pages/by-id/${encodeURIComponent(id)}`);\n }\n}\n","import { HttpClient } from './http-client';\nimport { BlogModule } from './modules/blog';\nimport { PagesModule } from './modules/pages';\nimport type { KookeeConfig } from './types';\n\nexport class Kookee {\n private readonly http: HttpClient;\n\n public readonly blog: BlogModule;\n public readonly pages: PagesModule;\n\n constructor(config: KookeeConfig) {\n if (!config.apiKey) {\n throw new Error('apiKey is required');\n }\n\n this.http = new HttpClient(config.apiKey, config.baseUrl);\n\n this.blog = new BlogModule(this.http);\n this.pages = new PagesModule(this.http);\n }\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -49,6 +49,7 @@ interface BlogPostListItem {
|
|
|
49
49
|
publishedAt: string | null;
|
|
50
50
|
metadata: Record<string, NonNullable<unknown>> | null;
|
|
51
51
|
createdAt: string;
|
|
52
|
+
views: number;
|
|
52
53
|
author: BlogPostAuthor;
|
|
53
54
|
tags: BlogTag[];
|
|
54
55
|
}
|
|
@@ -62,9 +63,22 @@ interface ApiError {
|
|
|
62
63
|
code: string;
|
|
63
64
|
message: string;
|
|
64
65
|
}
|
|
66
|
+
interface PageListItem {
|
|
67
|
+
id: string;
|
|
68
|
+
slug: string;
|
|
69
|
+
title: string;
|
|
70
|
+
createdAt: string;
|
|
71
|
+
updatedAt: string;
|
|
72
|
+
}
|
|
73
|
+
interface Page extends PageListItem {
|
|
74
|
+
contentHtml: string;
|
|
75
|
+
metaTitle: string | null;
|
|
76
|
+
metaDescription: string | null;
|
|
77
|
+
views: number;
|
|
78
|
+
}
|
|
65
79
|
|
|
66
80
|
interface BlogListParams extends PaginationParams {
|
|
67
|
-
|
|
81
|
+
tags?: string[];
|
|
68
82
|
search?: string;
|
|
69
83
|
}
|
|
70
84
|
declare class BlogModule {
|
|
@@ -76,10 +90,22 @@ declare class BlogModule {
|
|
|
76
90
|
getTags(): Promise<BlogTagWithCount[]>;
|
|
77
91
|
}
|
|
78
92
|
|
|
93
|
+
interface PagesListParams extends PaginationParams {
|
|
94
|
+
search?: string;
|
|
95
|
+
}
|
|
96
|
+
declare class PagesModule {
|
|
97
|
+
private readonly http;
|
|
98
|
+
constructor(http: HttpClient);
|
|
99
|
+
list(params?: PagesListParams): Promise<PaginatedResponse<PageListItem>>;
|
|
100
|
+
getBySlug(slug: string): Promise<Page>;
|
|
101
|
+
getById(id: string): Promise<Page>;
|
|
102
|
+
}
|
|
103
|
+
|
|
79
104
|
declare class Kookee {
|
|
80
105
|
private readonly http;
|
|
81
106
|
readonly blog: BlogModule;
|
|
107
|
+
readonly pages: PagesModule;
|
|
82
108
|
constructor(config: KookeeConfig);
|
|
83
109
|
}
|
|
84
110
|
|
|
85
|
-
export { type ApiError, type BlogListParams, BlogModule, type BlogPost, type BlogPostAuthor, type BlogPostListItem, type BlogTag, type BlogTagWithCount, Kookee, KookeeApiError, type KookeeConfig, type PaginatedResponse, type PaginationParams };
|
|
111
|
+
export { type ApiError, type BlogListParams, BlogModule, type BlogPost, type BlogPostAuthor, type BlogPostListItem, type BlogTag, type BlogTagWithCount, Kookee, KookeeApiError, type KookeeConfig, type Page, type PageListItem, type PagesListParams, PagesModule, type PaginatedResponse, type PaginationParams };
|
package/dist/index.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ interface BlogPostListItem {
|
|
|
49
49
|
publishedAt: string | null;
|
|
50
50
|
metadata: Record<string, NonNullable<unknown>> | null;
|
|
51
51
|
createdAt: string;
|
|
52
|
+
views: number;
|
|
52
53
|
author: BlogPostAuthor;
|
|
53
54
|
tags: BlogTag[];
|
|
54
55
|
}
|
|
@@ -62,9 +63,22 @@ interface ApiError {
|
|
|
62
63
|
code: string;
|
|
63
64
|
message: string;
|
|
64
65
|
}
|
|
66
|
+
interface PageListItem {
|
|
67
|
+
id: string;
|
|
68
|
+
slug: string;
|
|
69
|
+
title: string;
|
|
70
|
+
createdAt: string;
|
|
71
|
+
updatedAt: string;
|
|
72
|
+
}
|
|
73
|
+
interface Page extends PageListItem {
|
|
74
|
+
contentHtml: string;
|
|
75
|
+
metaTitle: string | null;
|
|
76
|
+
metaDescription: string | null;
|
|
77
|
+
views: number;
|
|
78
|
+
}
|
|
65
79
|
|
|
66
80
|
interface BlogListParams extends PaginationParams {
|
|
67
|
-
|
|
81
|
+
tags?: string[];
|
|
68
82
|
search?: string;
|
|
69
83
|
}
|
|
70
84
|
declare class BlogModule {
|
|
@@ -76,10 +90,22 @@ declare class BlogModule {
|
|
|
76
90
|
getTags(): Promise<BlogTagWithCount[]>;
|
|
77
91
|
}
|
|
78
92
|
|
|
93
|
+
interface PagesListParams extends PaginationParams {
|
|
94
|
+
search?: string;
|
|
95
|
+
}
|
|
96
|
+
declare class PagesModule {
|
|
97
|
+
private readonly http;
|
|
98
|
+
constructor(http: HttpClient);
|
|
99
|
+
list(params?: PagesListParams): Promise<PaginatedResponse<PageListItem>>;
|
|
100
|
+
getBySlug(slug: string): Promise<Page>;
|
|
101
|
+
getById(id: string): Promise<Page>;
|
|
102
|
+
}
|
|
103
|
+
|
|
79
104
|
declare class Kookee {
|
|
80
105
|
private readonly http;
|
|
81
106
|
readonly blog: BlogModule;
|
|
107
|
+
readonly pages: PagesModule;
|
|
82
108
|
constructor(config: KookeeConfig);
|
|
83
109
|
}
|
|
84
110
|
|
|
85
|
-
export { type ApiError, type BlogListParams, BlogModule, type BlogPost, type BlogPostAuthor, type BlogPostListItem, type BlogTag, type BlogTagWithCount, Kookee, KookeeApiError, type KookeeConfig, type PaginatedResponse, type PaginationParams };
|
|
111
|
+
export { type ApiError, type BlogListParams, BlogModule, type BlogPost, type BlogPostAuthor, type BlogPostListItem, type BlogTag, type BlogTagWithCount, Kookee, KookeeApiError, type KookeeConfig, type Page, type PageListItem, type PagesListParams, PagesModule, type PaginatedResponse, type PaginationParams };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
export{
|
|
1
|
+
var P="https://api.kookee.dev",c="Kookee-API-Key",n=class extends Error{constructor(e,s,l){super(s);this.code=e;this.status=l;this.name="KookeeApiError";}},p=class{baseUrl;apiKey;constructor(t,e){this.apiKey=t,this.baseUrl=e??P;}getHeaders(){return {"Content-Type":"application/json",[c]:this.apiKey}}async get(t,e){let s=new URL(`${this.baseUrl}${t}`);if(e){for(let[m,r]of Object.entries(e))if(r!=null)if(Array.isArray(r))for(let h of r)s.searchParams.append(m,String(h));else s.searchParams.set(m,String(r));}let l=await fetch(s.toString(),{method:"GET",headers:this.getHeaders()});return this.handleResponse(l)}async post(t,e){let s=await fetch(`${this.baseUrl}${t}`,{method:"POST",headers:this.getHeaders(),body:e?JSON.stringify(e):void 0});return this.handleResponse(s)}async handleResponse(t){if(!t.ok){let e=null;try{e=await t.json();}catch{}throw new n(e?.code??"UNKNOWN_ERROR",e?.message??`Request failed with status ${t.status}`,t.status)}return t.json()}};var o=class{constructor(t){this.http=t;}async list(t){return this.http.get("/v1/blog/posts",t)}async getBySlug(t){return this.http.get(`/v1/blog/posts/${encodeURIComponent(t)}`)}async getById(t){return this.http.get(`/v1/blog/posts/by-id/${encodeURIComponent(t)}`)}async getTags(){return this.http.get("/v1/blog/tags")}};var a=class{constructor(t){this.http=t;}async list(t){return this.http.get("/v1/pages",t)}async getBySlug(t){return this.http.get(`/v1/pages/${encodeURIComponent(t)}`)}async getById(t){return this.http.get(`/v1/pages/by-id/${encodeURIComponent(t)}`)}};var g=class{http;blog;pages;constructor(t){if(!t.apiKey)throw new Error("apiKey is required");this.http=new p(t.apiKey,t.baseUrl),this.blog=new o(this.http),this.pages=new a(this.http);}};
|
|
2
|
+
export{o as BlogModule,g as Kookee,n as KookeeApiError,a as PagesModule};//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/http-client.ts","../src/lib/modules/blog.ts","../src/lib/client.ts"],"names":["DEFAULT_BASE_URL","API_KEY_HEADER","KookeeApiError","code","message","status","HttpClient","apiKey","baseUrl","path","params","url","key","value","response","body","errorData","BlogModule","http","slug","id","Kookee","config"],"mappings":"AAEA,IAAMA,
|
|
1
|
+
{"version":3,"sources":["../src/lib/http-client.ts","../src/lib/modules/blog.ts","../src/lib/modules/pages.ts","../src/lib/client.ts"],"names":["DEFAULT_BASE_URL","API_KEY_HEADER","KookeeApiError","code","message","status","HttpClient","apiKey","baseUrl","path","params","url","key","value","item","response","body","errorData","BlogModule","http","slug","id","PagesModule","Kookee","config"],"mappings":"AAEA,IAAMA,EAAmB,wBAAA,CACnBC,CAAAA,CAAiB,iBAEVC,CAAAA,CAAN,cAA6B,KAAM,CACxC,WAAA,CACkBC,EAChBC,CAAAA,CACgBC,CAAAA,CAChB,CACA,KAAA,CAAMD,CAAO,EAJG,IAAA,CAAA,IAAA,CAAAD,CAAAA,CAEA,YAAAE,CAAAA,CAGhB,IAAA,CAAK,IAAA,CAAO,iBACd,CACF,CAAA,CAEaC,CAAAA,CAAN,KAAiB,CACL,OAAA,CACA,OAEjB,WAAA,CAAYC,CAAAA,CAAgBC,EAAkB,CAC5C,IAAA,CAAK,OAASD,CAAAA,CACd,IAAA,CAAK,QAAUC,CAAAA,EAAWR,EAC5B,CAEQ,UAAA,EAAqC,CAC3C,OAAO,CACL,eAAgB,kBAAA,CAChB,CAACC,CAAc,EAAG,IAAA,CAAK,MACzB,CACF,CAEA,MAAM,GAAA,CAAOQ,CAAAA,CAAcC,EAA6B,CACtD,IAAMC,EAAM,IAAI,GAAA,CAAI,GAAG,IAAA,CAAK,OAAO,GAAGF,CAAI,CAAA,CAAE,EAE5C,GAAIC,CAAAA,CAAAA,CACF,OAAW,CAACE,CAAAA,CAAKC,CAAK,CAAA,GAAK,MAAA,CAAO,QAAQH,CAAM,CAAA,CAC9C,GAA2BG,CAAAA,EAAU,IAAA,CACnC,GAAI,KAAA,CAAM,OAAA,CAAQA,CAAK,CAAA,CACrB,IAAA,IAAWC,CAAAA,IAAQD,CAAAA,CACjBF,EAAI,YAAA,CAAa,MAAA,CAAOC,EAAK,MAAA,CAAOE,CAAI,CAAC,CAAA,CAAA,KAG3CH,CA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AI,CAAC,CAAA,CAAE,CAC7E,CAEA,MAAM,OAAA,CAAQC,EAA+B,CAC3C,OAAO,KAAK,IAAA,CAAK,GAAA,CAAc,wBAAwB,kBAAA,CAAmBA,CAAE,CAAC,CAAA,CAAE,CACjF,CAEA,MAAM,OAAA,EAAuC,CAC3C,OAAO,IAAA,CAAK,KAAK,GAAA,CAAwB,eAAe,CAC1D,CACF,MCnBaC,CAAAA,CAAN,KAAkB,CACvB,WAAA,CAA6BH,EAAkB,CAAlB,IAAA,CAAA,IAAA,CAAAA,EAAmB,CAEhD,MAAM,KAAKT,CAAAA,CAAoE,CAC7E,OAAO,IAAA,CAAK,IAAA,CAAK,IAAqC,WAAA,CAAaA,CAAM,CAC3E,CAEA,MAAM,UAAUU,CAAAA,CAA6B,CAC3C,OAAO,IAAA,CAAK,IAAA,CAAK,IAAU,CAAA,UAAA,EAAa,kBAAA,CAAmBA,CAAI,CAAC,CAAA,CAAE,CACpE,CAEA,MAAM,QAAQC,CAAAA,CAA2B,CACvC,OAAO,IAAA,CAAK,IAAA,CAAK,IAAU,CAAA,gBAAA,EAAmB,kBAAA,CAAmBA,CAAE,CAAC,CAAA,CAAE,CACxE,CACF,EChBO,IAAME,CAAAA,CAAN,KAAa,CACD,IAAA,CAED,KACA,KAAA,CAEhB,WAAA,CAAYC,EAAsB,CAChC,GAAI,CAACA,CAAAA,CAAO,MAAA,CACV,MAAM,IAAI,KAAA,CAAM,oBAAoB,CAAA,CAGtC,IAAA,CAAK,KAAO,IAAIlB,CAAAA,CAAWkB,EAAO,MAAA,CAAQA,CAAAA,CAAO,OAAO,CAAA,CAExD,IAAA,CAAK,KAAO,IAAIN,CAAAA,CAAW,KAAK,IAAI,CAAA,CACpC,KAAK,KAAA,CAAQ,IAAII,EAAY,IAAA,CAAK,IAAI,EACxC,CACF","file":"index.js","sourcesContent":["import type { ApiError } from './types';\n\nconst DEFAULT_BASE_URL = 'https://api.kookee.dev';\nconst API_KEY_HEADER = 'Kookee-API-Key';\n\nexport class KookeeApiError extends Error {\n constructor(\n public readonly code: string,\n message: string,\n public readonly status: number\n ) {\n super(message);\n this.name = 'KookeeApiError';\n }\n}\n\nexport class HttpClient {\n private readonly baseUrl: string;\n private readonly apiKey: string;\n\n constructor(apiKey: string, baseUrl?: string) {\n this.apiKey = apiKey;\n this.baseUrl = baseUrl ?? DEFAULT_BASE_URL;\n }\n\n private getHeaders(): Record<string, string> {\n return {\n 'Content-Type': 'application/json',\n [API_KEY_HEADER]: this.apiKey,\n };\n }\n\n async get<T>(path: string, params?: object): Promise<T> {\n const url = new URL(`${this.baseUrl}${path}`);\n\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined && value !== null) {\n if (Array.isArray(value)) {\n for (const item of value) {\n url.searchParams.append(key, String(item));\n }\n } else {\n url.searchParams.set(key, String(value));\n }\n }\n }\n }\n\n const response = await fetch(url.toString(), {\n method: 'GET',\n headers: this.getHeaders(),\n });\n\n return this.handleResponse<T>(response);\n }\n\n async post<T>(path: string, body?: unknown): Promise<T> {\n const response = await fetch(`${this.baseUrl}${path}`, {\n method: 'POST',\n headers: this.getHeaders(),\n body: body ? JSON.stringify(body) : undefined,\n });\n\n return this.handleResponse<T>(response);\n }\n\n private async handleResponse<T>(response: Response): Promise<T> {\n if (!response.ok) {\n let errorData: ApiError | null = null;\n\n try {\n errorData = (await response.json()) as ApiError;\n } catch {\n // Response body is not JSON\n }\n\n throw new KookeeApiError(\n errorData?.code ?? 'UNKNOWN_ERROR',\n errorData?.message ?? `Request failed with status ${response.status}`,\n response.status\n );\n }\n\n return response.json() as Promise<T>;\n }\n}\n","import type { HttpClient } from '../http-client';\nimport type { BlogPost, BlogPostListItem, BlogTagWithCount, PaginatedResponse, PaginationParams } from '../types';\n\nexport interface BlogListParams extends PaginationParams {\n tags?: string[];\n search?: string;\n}\n\nexport class BlogModule {\n constructor(private readonly http: HttpClient) {}\n\n async list(params?: BlogListParams): Promise<PaginatedResponse<BlogPostListItem>> {\n return this.http.get<PaginatedResponse<BlogPostListItem>>('/v1/blog/posts', params);\n }\n\n async getBySlug(slug: string): Promise<BlogPost> {\n return this.http.get<BlogPost>(`/v1/blog/posts/${encodeURIComponent(slug)}`);\n }\n\n async getById(id: string): Promise<BlogPost> {\n return this.http.get<BlogPost>(`/v1/blog/posts/by-id/${encodeURIComponent(id)}`);\n }\n\n async getTags(): Promise<BlogTagWithCount[]> {\n return this.http.get<BlogTagWithCount[]>('/v1/blog/tags');\n }\n}\n","import type { HttpClient } from '../http-client';\nimport type { Page, PageListItem, PaginatedResponse, PaginationParams } from '../types';\n\nexport interface PagesListParams extends PaginationParams {\n search?: string;\n}\n\nexport class PagesModule {\n constructor(private readonly http: HttpClient) {}\n\n async list(params?: PagesListParams): Promise<PaginatedResponse<PageListItem>> {\n return this.http.get<PaginatedResponse<PageListItem>>('/v1/pages', params);\n }\n\n async getBySlug(slug: string): Promise<Page> {\n return this.http.get<Page>(`/v1/pages/${encodeURIComponent(slug)}`);\n }\n\n async getById(id: string): Promise<Page> {\n return this.http.get<Page>(`/v1/pages/by-id/${encodeURIComponent(id)}`);\n }\n}\n","import { HttpClient } from './http-client';\nimport { BlogModule } from './modules/blog';\nimport { PagesModule } from './modules/pages';\nimport type { KookeeConfig } from './types';\n\nexport class Kookee {\n private readonly http: HttpClient;\n\n public readonly blog: BlogModule;\n public readonly pages: PagesModule;\n\n constructor(config: KookeeConfig) {\n if (!config.apiKey) {\n throw new Error('apiKey is required');\n }\n\n this.http = new HttpClient(config.apiKey, config.baseUrl);\n\n this.blog = new BlogModule(this.http);\n this.pages = new PagesModule(this.http);\n }\n}\n"]}
|