@caldik/client 0.0.1

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.
@@ -0,0 +1,118 @@
1
+ //#region src/types.d.ts
2
+ interface Category {
3
+ id: string;
4
+ name: string;
5
+ slug: string;
6
+ description: string;
7
+ price: string;
8
+ logo: string;
9
+ banner: string;
10
+ }
11
+ interface CategoriesResponse {
12
+ success: boolean;
13
+ categories: Category[];
14
+ }
15
+ interface CategoryProduct {
16
+ id: string;
17
+ name: string;
18
+ slug: string;
19
+ tags: {
20
+ label: string;
21
+ color: string;
22
+ }[];
23
+ price: string;
24
+ logo: string;
25
+ banner: string;
26
+ }
27
+ interface CategoryDetails {
28
+ id: string;
29
+ name: string;
30
+ description: string;
31
+ products: CategoryProduct[];
32
+ }
33
+ interface CategoryResponse {
34
+ success: boolean;
35
+ category: CategoryDetails;
36
+ }
37
+ interface Store {
38
+ name: string;
39
+ description: string;
40
+ }
41
+ interface StoreResponse {
42
+ success: boolean;
43
+ store: Store;
44
+ }
45
+ interface Review {
46
+ id: string;
47
+ rating: number;
48
+ title: string;
49
+ content: string;
50
+ createdAt: number;
51
+ }
52
+ interface ReviewsResponse {
53
+ success: boolean;
54
+ reviews: Review[];
55
+ }
56
+ interface Product {
57
+ id: string;
58
+ name: string;
59
+ price: number;
60
+ }
61
+ //#endregion
62
+ //#region src/internal/types.d.ts
63
+ interface RequestOptions {
64
+ edgeCache?: boolean;
65
+ }
66
+ //#endregion
67
+ //#region src/internal/client.d.ts
68
+ declare class CaldikHttpClient {
69
+ private publicKey?;
70
+ private apiUrl;
71
+ constructor(publicKey?: string | undefined, apiUrl?: string);
72
+ get<T>(path: string, params?: Record<string, string | number>, options?: RequestOptions): Promise<T>;
73
+ }
74
+ //#endregion
75
+ //#region src/categories.d.ts
76
+ declare class CategoriesApi {
77
+ private client;
78
+ constructor(client: CaldikHttpClient);
79
+ list(limit?: number): Promise<CategoriesResponse>;
80
+ get(categoryId: string): Promise<CategoryResponse>;
81
+ }
82
+ //#endregion
83
+ //#region src/products.d.ts
84
+ declare class ProductsApi {
85
+ private client;
86
+ constructor(client: CaldikHttpClient);
87
+ list(): Promise<Product[]>;
88
+ get(productId: string): Promise<Product>;
89
+ }
90
+ //#endregion
91
+ //#region src/reviews.d.ts
92
+ declare class ReviewsApi {
93
+ private client;
94
+ constructor(client: CaldikHttpClient);
95
+ list(limit?: number): Promise<ReviewsResponse>;
96
+ }
97
+ //#endregion
98
+ //#region src/store.d.ts
99
+ declare class StoreApi {
100
+ private client;
101
+ constructor(client: CaldikHttpClient);
102
+ get(): Promise<StoreResponse>;
103
+ }
104
+ //#endregion
105
+ //#region src/index.d.ts
106
+ interface CaldikClientOptions {
107
+ publicApiKey?: string;
108
+ apiUrl?: string;
109
+ }
110
+ declare class CaldikClient {
111
+ readonly categories: CategoriesApi;
112
+ readonly products: ProductsApi;
113
+ readonly reviews: ReviewsApi;
114
+ readonly store: StoreApi;
115
+ constructor(options?: CaldikClientOptions);
116
+ }
117
+ //#endregion
118
+ export { CaldikClient, CaldikClientOptions };
package/dist/index.mjs ADDED
@@ -0,0 +1,95 @@
1
+ //#region src/config.ts
2
+ const defaultApiUrl = typeof API_URL !== "undefined" ? API_URL : "https://api.caldik.com";
3
+ //#endregion
4
+ //#region src/internal/client.ts
5
+ var CaldikHttpClient = class {
6
+ publicKey;
7
+ apiUrl;
8
+ constructor(publicKey, apiUrl = defaultApiUrl) {
9
+ this.publicKey = publicKey;
10
+ this.apiUrl = apiUrl;
11
+ }
12
+ async get(path, params, options) {
13
+ const baseUrl = this.apiUrl.replace(/\/+$/, "");
14
+ const url = new URL(`${baseUrl}/v1${path}`);
15
+ if (params) for (const [key, value] of Object.entries(params)) url.searchParams.set(key, String(value));
16
+ const headers = {
17
+ "User-Agent": "CaldikClient/0.0.1",
18
+ ...this.publicKey && { Authorization: `Bearer ${this.publicKey}` }
19
+ };
20
+ if (options?.edgeCache) headers["X-Cache-Policy"] = "public";
21
+ const response = await fetch(url, {
22
+ headers,
23
+ cache: "default"
24
+ });
25
+ if (!response.ok) throw new Error(response.statusText);
26
+ return response.json();
27
+ }
28
+ };
29
+ //#endregion
30
+ //#region src/categories.ts
31
+ var CategoriesApi = class {
32
+ client;
33
+ constructor(client) {
34
+ this.client = client;
35
+ }
36
+ list(limit) {
37
+ return this.client.get("/categories", limit ? { limit } : void 0);
38
+ }
39
+ get(categoryId) {
40
+ return this.client.get(`/categories/${categoryId}`);
41
+ }
42
+ };
43
+ //#endregion
44
+ //#region src/products.ts
45
+ var ProductsApi = class {
46
+ client;
47
+ constructor(client) {
48
+ this.client = client;
49
+ }
50
+ list() {
51
+ return this.client.get("/products");
52
+ }
53
+ get(productId) {
54
+ return this.client.get(`/products/${productId}`);
55
+ }
56
+ };
57
+ //#endregion
58
+ //#region src/reviews.ts
59
+ var ReviewsApi = class {
60
+ client;
61
+ constructor(client) {
62
+ this.client = client;
63
+ }
64
+ list(limit) {
65
+ return this.client.get("/reviews", limit ? { limit } : void 0);
66
+ }
67
+ };
68
+ //#endregion
69
+ //#region src/store.ts
70
+ var StoreApi = class {
71
+ client;
72
+ constructor(client) {
73
+ this.client = client;
74
+ }
75
+ get() {
76
+ return this.client.get("");
77
+ }
78
+ };
79
+ //#endregion
80
+ //#region src/index.ts
81
+ var CaldikClient = class {
82
+ categories;
83
+ products;
84
+ reviews;
85
+ store;
86
+ constructor(options = {}) {
87
+ const client = new CaldikHttpClient(options.publicApiKey, options.apiUrl);
88
+ this.categories = new CategoriesApi(client);
89
+ this.products = new ProductsApi(client);
90
+ this.reviews = new ReviewsApi(client);
91
+ this.store = new StoreApi(client);
92
+ }
93
+ };
94
+ //#endregion
95
+ export { CaldikClient };
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@caldik/client",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "./dist/index.mjs",
6
+ "types": "./dist/index.d.mts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.mts",
10
+ "import": "./dist/index.mjs"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "scripts": {
20
+ "build": "tsdown"
21
+ },
22
+ "devDependencies": {
23
+ "tsdown": "^0.22.3",
24
+ "typescript": "^6.0.3"
25
+ }
26
+ }