@kookee/sdk 0.0.10 → 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 CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';var c="https://api.kookee.dev",m="Kookee-API-Key",i=class extends Error{constructor(e,o,g){super(o);this.code=e;this.status=g;this.name="KookeeApiError";}},n=class{baseUrl;apiKey;constructor(t,e){this.apiKey=t,this.baseUrl=e??c;}getHeaders(){return {"Content-Type":"application/json",[m]:this.apiKey}}async get(t,e){let o=new URL(`${this.baseUrl}${t}`);if(e){for(let[l,s]of Object.entries(e))if(s!=null)if(Array.isArray(s))for(let h of s)o.searchParams.append(l,String(h));else o.searchParams.set(l,String(s));}let g=await fetch(o.toString(),{method:"GET",headers:this.getHeaders()});return this.handleResponse(g)}async post(t,e){let o=await fetch(`${this.baseUrl}${t}`,{method:"POST",headers:this.getHeaders(),body:e?JSON.stringify(e):void 0});return this.handleResponse(o)}async handleResponse(t){if(!t.ok){let e=null;try{e=await t.json();}catch{}throw new i(e?.code??"UNKNOWN_ERROR",e?.message??`Request failed with status ${t.status}`,t.status)}return t.json()}};var r=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 p=class{http;blog;constructor(t){if(!t.apiKey)throw new Error("apiKey is required");this.http=new n(t.apiKey,t.baseUrl),this.blog=new r(this.http);}};
2
- exports.BlogModule=r;exports.Kookee=p;exports.KookeeApiError=i;//# sourceMappingURL=index.cjs.map
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
@@ -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","item","response","body","errorData","BlogModule","http","slug","id","Kookee","config"],"mappings":"aAEA,IAAMA,CAAAA,CAAmB,wBAAA,CACnBC,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AAA,CAAc,CAAA,qBAAA,EAAwB,mBAAmBA,CAAE,CAAC,CAAA,CAAE,CACjF,CAEA,MAAM,OAAA,EAAuC,CAC3C,OAAO,KAAK,IAAA,CAAK,GAAA,CAAwB,eAAe,CAC1D,CACF,ECtBO,IAAMC,CAAAA,CAAN,KAAa,CACD,IAAA,CAED,IAAA,CAEhB,WAAA,CAAYC,CAAAA,CAAsB,CAChC,GAAI,CAACA,CAAAA,CAAO,MAAA,CACV,MAAM,IAAI,KAAA,CAAM,oBAAoB,CAAA,CAGtC,KAAK,IAAA,CAAO,IAAIjB,CAAAA,CAAWiB,CAAAA,CAAO,OAAQA,CAAAA,CAAO,OAAO,CAAA,CAExD,IAAA,CAAK,KAAO,IAAIL,CAAAA,CAAW,IAAA,CAAK,IAAI,EACtC,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 { HttpClient } from './http-client';\nimport { BlogModule } from './modules/blog';\nimport type { KookeeConfig } from './types';\n\nexport class Kookee {\n private readonly http: HttpClient;\n\n public readonly blog: BlogModule;\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 }\n}\n"]}
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,CAAAA,CAAI,aAAa,GAAA,CAAIC,CAAAA,CAAK,OAAOC,CAAK,CAAC,GAM/C,IAAME,CAAAA,CAAW,MAAM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AAA,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.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
@@ -63,6 +63,19 @@ interface ApiError {
63
63
  code: string;
64
64
  message: string;
65
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
+ }
66
79
 
67
80
  interface BlogListParams extends PaginationParams {
68
81
  tags?: string[];
@@ -77,10 +90,22 @@ declare class BlogModule {
77
90
  getTags(): Promise<BlogTagWithCount[]>;
78
91
  }
79
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
+
80
104
  declare class Kookee {
81
105
  private readonly http;
82
106
  readonly blog: BlogModule;
107
+ readonly pages: PagesModule;
83
108
  constructor(config: KookeeConfig);
84
109
  }
85
110
 
86
- 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
@@ -63,6 +63,19 @@ interface ApiError {
63
63
  code: string;
64
64
  message: string;
65
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
+ }
66
79
 
67
80
  interface BlogListParams extends PaginationParams {
68
81
  tags?: string[];
@@ -77,10 +90,22 @@ declare class BlogModule {
77
90
  getTags(): Promise<BlogTagWithCount[]>;
78
91
  }
79
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
+
80
104
  declare class Kookee {
81
105
  private readonly http;
82
106
  readonly blog: BlogModule;
107
+ readonly pages: PagesModule;
83
108
  constructor(config: KookeeConfig);
84
109
  }
85
110
 
86
- 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 c="https://api.kookee.dev",m="Kookee-API-Key",i=class extends Error{constructor(e,o,g){super(o);this.code=e;this.status=g;this.name="KookeeApiError";}},n=class{baseUrl;apiKey;constructor(t,e){this.apiKey=t,this.baseUrl=e??c;}getHeaders(){return {"Content-Type":"application/json",[m]:this.apiKey}}async get(t,e){let o=new URL(`${this.baseUrl}${t}`);if(e){for(let[l,s]of Object.entries(e))if(s!=null)if(Array.isArray(s))for(let h of s)o.searchParams.append(l,String(h));else o.searchParams.set(l,String(s));}let g=await fetch(o.toString(),{method:"GET",headers:this.getHeaders()});return this.handleResponse(g)}async post(t,e){let o=await fetch(`${this.baseUrl}${t}`,{method:"POST",headers:this.getHeaders(),body:e?JSON.stringify(e):void 0});return this.handleResponse(o)}async handleResponse(t){if(!t.ok){let e=null;try{e=await t.json();}catch{}throw new i(e?.code??"UNKNOWN_ERROR",e?.message??`Request failed with status ${t.status}`,t.status)}return t.json()}};var r=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 p=class{http;blog;constructor(t){if(!t.apiKey)throw new Error("apiKey is required");this.http=new n(t.apiKey,t.baseUrl),this.blog=new r(this.http);}};
2
- export{r as BlogModule,p as Kookee,i as KookeeApiError};//# sourceMappingURL=index.js.map
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","item","response","body","errorData","BlogModule","http","slug","id","Kookee","config"],"mappings":"AAEA,IAAMA,CAAAA,CAAmB,wBAAA,CACnBC,CAAAA,CAAiB,gBAAA,CAEVC,EAAN,cAA6B,KAAM,CACxC,WAAA,CACkBC,EAChBC,CAAAA,CACgBC,CAAAA,CAChB,CACA,KAAA,CAAMD,CAAO,CAAA,CAJG,IAAA,CAAA,IAAA,CAAAD,CAAAA,CAEA,IAAA,CAAA,MAAA,CAAAE,EAGhB,IAAA,CAAK,IAAA,CAAO,iBACd,CACF,EAEaC,CAAAA,CAAN,KAAiB,CACL,OAAA,CACA,OAEjB,WAAA,CAAYC,CAAAA,CAAgBC,CAAAA,CAAkB,CAC5C,KAAK,MAAA,CAASD,CAAAA,CACd,IAAA,CAAK,OAAA,CAAUC,CAAAA,EAAWR,EAC5B,CAEQ,UAAA,EAAqC,CAC3C,OAAO,CACL,cAAA,CAAgB,kBAAA,CAChB,CAACC,CAAc,EAAG,IAAA,CAAK,MACzB,CACF,CAEA,MAAM,GAAA,CAAOQ,CAAAA,CAAcC,EAA6B,CACtD,IAAMC,CAAAA,CAAM,IAAI,IAAI,CAAA,EAAG,IAAA,CAAK,OAAO,CAAA,EAAGF,CAAI,CAAA,CAAE,CAAA,CAE5C,GAAIC,CAAAA,CAAAA,CACF,OAAW,CAACE,CAAAA,CAAKC,CAAK,CAAA,GAAK,MAAA,CAAO,OAAA,CAAQH,CAAM,CAAA,CAC9C,GAA2BG,CAAAA,EAAU,IAAA,CACnC,GAAI,KAAA,CAAM,QAAQA,CAAK,CAAA,CACrB,IAAA,IAAWC,CAAA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CAEhD,MAAM,IAAA,CAAKT,EAAuE,CAChF,OAAO,IAAA,CAAK,IAAA,CAAK,IAAyC,gBAAA,CAAkBA,CAAM,CACpF,CAEA,MAAM,SAAA,CAAUU,CAAAA,CAAiC,CAC/C,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAc,CAAA,eAAA,EAAkB,mBAAmBA,CAAI,CAAC,CAAA,CAAE,CAC7E,CAEA,MAAM,OAAA,CAAQC,CAAAA,CAA+B,CAC3C,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAc,CAAA,qBAAA,EAAwB,mBAAmBA,CAAE,CAAC,CAAA,CAAE,CACjF,CAEA,MAAM,OAAA,EAAuC,CAC3C,OAAO,KAAK,IAAA,CAAK,GAAA,CAAwB,eAAe,CAC1D,CACF,ECtBO,IAAMC,CAAAA,CAAN,KAAa,CACD,IAAA,CAED,IAAA,CAEhB,WAAA,CAAYC,CAAAA,CAAsB,CAChC,GAAI,CAACA,CAAAA,CAAO,MAAA,CACV,MAAM,IAAI,KAAA,CAAM,oBAAoB,CAAA,CAGtC,KAAK,IAAA,CAAO,IAAIjB,CAAAA,CAAWiB,CAAAA,CAAO,OAAQA,CAAAA,CAAO,OAAO,CAAA,CAExD,IAAA,CAAK,KAAO,IAAIL,CAAAA,CAAW,IAAA,CAAK,IAAI,EACtC,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 { HttpClient } from './http-client';\nimport { BlogModule } from './modules/blog';\nimport type { KookeeConfig } from './types';\n\nexport class Kookee {\n private readonly http: HttpClient;\n\n public readonly blog: BlogModule;\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 }\n}\n"]}
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,Q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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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kookee/sdk",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Official Kookee SDK - Access your blog, changelog, help center, and more",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",