@caldik/client 0.0.4 → 0.0.5
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.d.mts +33 -1
- package/dist/index.mjs +4 -2
- package/package.json +2 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
//#region src/types.d.ts
|
|
2
|
+
interface StorefrontMetadata {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
json: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
type ProductMetadata = StorefrontMetadata;
|
|
9
|
+
type CategoryMetadata = StorefrontMetadata;
|
|
2
10
|
interface Category {
|
|
3
11
|
id: string;
|
|
4
12
|
name: string;
|
|
@@ -7,6 +15,7 @@ interface Category {
|
|
|
7
15
|
price: string;
|
|
8
16
|
logo: string | null;
|
|
9
17
|
banner: string | null;
|
|
18
|
+
metadata: CategoryMetadata[];
|
|
10
19
|
}
|
|
11
20
|
interface CategoriesResponse {
|
|
12
21
|
success: boolean;
|
|
@@ -27,7 +36,11 @@ interface CategoryProduct {
|
|
|
27
36
|
interface CategoryDetails {
|
|
28
37
|
id: string;
|
|
29
38
|
name: string;
|
|
39
|
+
slug: string;
|
|
30
40
|
description: string;
|
|
41
|
+
logo: string | null;
|
|
42
|
+
banner: string | null;
|
|
43
|
+
metadata: CategoryMetadata[];
|
|
31
44
|
products: CategoryProduct[];
|
|
32
45
|
}
|
|
33
46
|
interface CategoryResponse {
|
|
@@ -68,6 +81,8 @@ interface Product {
|
|
|
68
81
|
maximumQuantity: number | null;
|
|
69
82
|
variants: ProductVariant[];
|
|
70
83
|
tags: ProductTag[];
|
|
84
|
+
customFields: ProductCustomField[];
|
|
85
|
+
metadata: ProductMetadata[];
|
|
71
86
|
}
|
|
72
87
|
interface ProductVariant {
|
|
73
88
|
id: string;
|
|
@@ -79,6 +94,23 @@ interface ProductTag {
|
|
|
79
94
|
label: string;
|
|
80
95
|
color: string;
|
|
81
96
|
}
|
|
97
|
+
type ProductCustomFieldInputType = "text" | "textarea" | "number" | "dropdown" | "checkbox";
|
|
98
|
+
interface ProductCustomFieldOption {
|
|
99
|
+
id: string;
|
|
100
|
+
label: string;
|
|
101
|
+
value: string;
|
|
102
|
+
position: number;
|
|
103
|
+
}
|
|
104
|
+
interface ProductCustomField {
|
|
105
|
+
id: string;
|
|
106
|
+
name: string;
|
|
107
|
+
inputType: ProductCustomFieldInputType;
|
|
108
|
+
placeholder: string | null;
|
|
109
|
+
position: number;
|
|
110
|
+
defaultValue: string | null;
|
|
111
|
+
requiredEnabled: boolean;
|
|
112
|
+
options: ProductCustomFieldOption[];
|
|
113
|
+
}
|
|
82
114
|
interface ProductsResponse {
|
|
83
115
|
success: boolean;
|
|
84
116
|
products: Product[];
|
|
@@ -268,4 +300,4 @@ declare class CaldikClient {
|
|
|
268
300
|
constructor(options?: CaldikClientOptions);
|
|
269
301
|
}
|
|
270
302
|
//#endregion
|
|
271
|
-
export { CaldikClient, CaldikClientOptions, CategoriesResponse, Category, CategoryDetails, CategoryProduct, CategoryResponse, CheckoutPayment, CommerceItem, CreateOrderInput, CreateSubscriptionInput, CustomerLoginResponse, CustomerLoginVerifyResponse, ManualCommerceItem, OrderResponse, Product, ProductCommerceItem, ProductResponse, ProductTag, ProductVariant, ProductsResponse, Review, ReviewsResponse, Store, StoreResponse, StorefrontOrder, SubscriptionResponse };
|
|
303
|
+
export { CaldikClient, CaldikClientOptions, CategoriesResponse, Category, CategoryDetails, CategoryMetadata, CategoryProduct, CategoryResponse, CheckoutPayment, CommerceItem, CreateOrderInput, CreateSubscriptionInput, CustomerLoginResponse, CustomerLoginVerifyResponse, ManualCommerceItem, OrderResponse, Product, ProductCommerceItem, ProductCustomField, ProductCustomFieldInputType, ProductCustomFieldOption, ProductMetadata, ProductResponse, ProductTag, ProductVariant, ProductsResponse, Review, ReviewsResponse, Store, StoreResponse, StorefrontMetadata, StorefrontOrder, SubscriptionResponse };
|
package/dist/index.mjs
CHANGED
|
@@ -25,7 +25,9 @@ var CaldikHttpClient = class {
|
|
|
25
25
|
baseUrl() {
|
|
26
26
|
if (isBrowserRuntime()) {
|
|
27
27
|
if (typeof location === "undefined") throw new Error("Caldik browser transport requires a browser origin");
|
|
28
|
-
|
|
28
|
+
const storeReference = location.hostname.trim().toLowerCase().replace(/\.$/, "");
|
|
29
|
+
if (!storeReference) throw new Error("Caldik browser transport requires a storefront hostname");
|
|
30
|
+
return `${this.apiUrl.replace(/\/+$/, "")}/v1/stores/${encodeURIComponent(storeReference)}`;
|
|
29
31
|
}
|
|
30
32
|
const boundStoreId = boundRuntimeStoreId();
|
|
31
33
|
if (boundStoreId && this.storeId && boundStoreId !== this.storeId) throw new Error("Caldik storeId does not match the hosted runtime");
|
|
@@ -40,7 +42,7 @@ var CaldikHttpClient = class {
|
|
|
40
42
|
const headers = {};
|
|
41
43
|
if (!isBrowserRuntime()) headers["User-Agent"] = "CaldikClient/0.0.2";
|
|
42
44
|
if (this.apiKey) headers.Authorization = `Bearer ${this.apiKey}`;
|
|
43
|
-
else if (options?.access === "public") headers["X-Caldik-Public-Request"] = "1";
|
|
45
|
+
else if (options?.access === "public" && !isBrowserRuntime()) headers["X-Caldik-Public-Request"] = "1";
|
|
44
46
|
if (input !== void 0) headers["Content-Type"] = "application/json";
|
|
45
47
|
if (options?.edgeCache) headers["X-Cache-Policy"] = "public";
|
|
46
48
|
const response = await fetch(url, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caldik/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.mts",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"test": "bun test"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
+
"@types/bun": "latest",
|
|
24
25
|
"tsdown": "^0.22.3",
|
|
25
26
|
"typescript": "^6.0.3"
|
|
26
27
|
}
|