@caldik/client 0.1.5 → 0.1.6
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 +4 -0
- package/dist/index.d.mts +10 -1
- package/dist/index.mjs +6 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -263,6 +263,10 @@ a storefront API proxy). Cookies set only on a separate API hostname are not
|
|
|
263
263
|
included in requests to the storefront server. A private store key does not
|
|
264
264
|
replace a shopper's customer session.
|
|
265
265
|
|
|
266
|
+
Customer and cart cookies are scoped to the storefront origin. When you pass
|
|
267
|
+
`request`, the SDK forwards its `Origin` header, or the request URL's origin when
|
|
268
|
+
that header is absent, so server calls use the same session as the storefront.
|
|
269
|
+
|
|
266
270
|
### Checkout with Explicit Items
|
|
267
271
|
|
|
268
272
|
Use `caldik.checkout.create()` to create an order from explicitly provided items.
|
package/dist/index.d.mts
CHANGED
|
@@ -118,6 +118,7 @@ interface Product {
|
|
|
118
118
|
deliveryType: string;
|
|
119
119
|
minimumQuantity: number | null;
|
|
120
120
|
maximumQuantity: number | null;
|
|
121
|
+
images: ProductImage[];
|
|
121
122
|
variants: ProductVariant[];
|
|
122
123
|
tags: ProductTag[];
|
|
123
124
|
customFields: ProductCustomField[];
|
|
@@ -129,6 +130,13 @@ interface ProductVariant {
|
|
|
129
130
|
position: number;
|
|
130
131
|
price: string;
|
|
131
132
|
compareAtPrice: string | null;
|
|
133
|
+
images: ProductImage[];
|
|
134
|
+
}
|
|
135
|
+
interface ProductImage {
|
|
136
|
+
id: string;
|
|
137
|
+
url: string;
|
|
138
|
+
alt: string | null;
|
|
139
|
+
position: number;
|
|
132
140
|
}
|
|
133
141
|
interface ProductTag {
|
|
134
142
|
label: string;
|
|
@@ -386,6 +394,7 @@ declare class CaldikHttpClient {
|
|
|
386
394
|
private readonly storeId?;
|
|
387
395
|
private readonly cookies;
|
|
388
396
|
private readonly onSetCookie?;
|
|
397
|
+
private readonly storefrontOrigin?;
|
|
389
398
|
private readonly authenticationListeners;
|
|
390
399
|
constructor(options?: HttpClientOptions);
|
|
391
400
|
storeContextId(): string | null;
|
|
@@ -578,4 +587,4 @@ declare class CaldikClient {
|
|
|
578
587
|
constructor(options?: CaldikClientOptions);
|
|
579
588
|
}
|
|
580
589
|
//#endregion
|
|
581
|
-
export { AppliedDiscount, CaldikClient, CaldikClientOptions, CartApi, CartCheckoutInput, CartDiscount, CartItem, CartSnapshot, CategoriesResponse, Category, CategoryDetails, CategoryInclude, CategoryListOptions, CategoryMetadata, CategoryProduct, CategoryResponse, CheckDiscountInput, CheckoutPayment, CheckoutPaymentMethod, CheckoutPaymentMethodsResponse, CheckoutPaymentProviderId, CheckoutSettings, CheckoutSettingsResponse, CommerceItem, CreateOrderInput, CreateSubscriptionInput, CustomerEmailLoginInput, CustomerLoginResponse, CustomerLoginSettings, CustomerLoginSettingsResponse, CustomerLoginVerifyResponse, CustomerPasswordInput, CustomerPasswordResetInput, CustomerPasswordResetResponse, CustomerPasswordResetVerifyResponse, CustomerPasswordResponse, CustomerProfileResponse, CustomerRegistrationInput, CustomerRegistrationResponse, CustomerSessionResponse, DiscountQuoteResponse, DiscountsApi, ManualCommerceItem, OrderResponse, PaymentProviderId, Product, ProductCommerceItem, ProductCustomField, ProductCustomFieldInputType, ProductCustomFieldOption, ProductGetOptions, ProductMetadata, ProductResponse, ProductTag, ProductVariant, ProductsResponse, Review, ReviewsResponse, Store, StoreResponse, StoreSocials, StoreWebhookEvent, StoreWebhookEventName, StorefrontMetadata, StorefrontOrder, SubscriptionPaymentProviderId, SubscriptionResponse, checkoutPaymentProviderIds, paymentProviderIds, storeWebhookEventNames, subscriptionPaymentProviderIds };
|
|
590
|
+
export { AppliedDiscount, CaldikClient, CaldikClientOptions, CartApi, CartCheckoutInput, CartDiscount, CartItem, CartSnapshot, CategoriesResponse, Category, CategoryDetails, CategoryInclude, CategoryListOptions, CategoryMetadata, CategoryProduct, CategoryResponse, CheckDiscountInput, CheckoutPayment, CheckoutPaymentMethod, CheckoutPaymentMethodsResponse, CheckoutPaymentProviderId, CheckoutSettings, CheckoutSettingsResponse, CommerceItem, CreateOrderInput, CreateSubscriptionInput, CustomerEmailLoginInput, CustomerLoginResponse, CustomerLoginSettings, CustomerLoginSettingsResponse, CustomerLoginVerifyResponse, CustomerPasswordInput, CustomerPasswordResetInput, CustomerPasswordResetResponse, CustomerPasswordResetVerifyResponse, CustomerPasswordResponse, CustomerProfileResponse, CustomerRegistrationInput, CustomerRegistrationResponse, CustomerSessionResponse, DiscountQuoteResponse, DiscountsApi, ManualCommerceItem, OrderResponse, PaymentProviderId, Product, ProductCommerceItem, ProductCustomField, ProductCustomFieldInputType, ProductCustomFieldOption, ProductGetOptions, ProductImage, ProductMetadata, ProductResponse, ProductTag, ProductVariant, ProductsResponse, Review, ReviewsResponse, Store, StoreResponse, StoreSocials, StoreWebhookEvent, StoreWebhookEventName, StorefrontMetadata, StorefrontOrder, SubscriptionPaymentProviderId, SubscriptionResponse, checkoutPaymentProviderIds, paymentProviderIds, storeWebhookEventNames, subscriptionPaymentProviderIds };
|
package/dist/index.mjs
CHANGED
|
@@ -47,22 +47,19 @@ function browserRuntimeStoreId() {
|
|
|
47
47
|
const buildStoreId = browserBuildStoreId();
|
|
48
48
|
return buildStoreId && STORE_ID_PATTERN.test(buildStoreId) ? buildStoreId : null;
|
|
49
49
|
}
|
|
50
|
-
function isLocalBrowserRuntime() {
|
|
51
|
-
if (!isBrowserRuntime() || typeof location === "undefined") return false;
|
|
52
|
-
const hostname = location.hostname.toLowerCase();
|
|
53
|
-
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname === "[::1]";
|
|
54
|
-
}
|
|
55
50
|
var CaldikHttpClient = class {
|
|
56
51
|
apiKey;
|
|
57
52
|
apiUrl;
|
|
58
53
|
storeId;
|
|
59
54
|
cookies = /* @__PURE__ */ new Map();
|
|
60
55
|
onSetCookie;
|
|
56
|
+
storefrontOrigin;
|
|
61
57
|
authenticationListeners = /* @__PURE__ */ new Set();
|
|
62
58
|
constructor(options = {}) {
|
|
63
59
|
this.apiKey = options.apiKey?.trim() || void 0;
|
|
64
60
|
this.apiUrl = options.apiUrl || defaultApiUrl(isBrowserRuntime());
|
|
65
61
|
this.onSetCookie = options.onSetCookie;
|
|
62
|
+
if (options.request && !isBrowserRuntime()) this.storefrontOrigin = options.request.headers.get("Origin") || new URL(options.request.url).origin;
|
|
66
63
|
if (!isBrowserRuntime()) for (const part of (options.request?.headers.get("Cookie") || "").split(";")) {
|
|
67
64
|
const separator = part.indexOf("=");
|
|
68
65
|
if (separator > 0) this.cookies.set(part.slice(0, separator).trim(), part.slice(separator + 1).trim());
|
|
@@ -77,7 +74,8 @@ var CaldikHttpClient = class {
|
|
|
77
74
|
return this.storeId || boundRuntimeStoreId();
|
|
78
75
|
}
|
|
79
76
|
hasCartSession() {
|
|
80
|
-
|
|
77
|
+
const prefix = `caldik_cart_session_${this.storeContextId()}`;
|
|
78
|
+
return [...this.cookies.keys()].some((name) => name === prefix || name.startsWith(`${prefix}_`));
|
|
81
79
|
}
|
|
82
80
|
onCustomerAuthentication(listener) {
|
|
83
81
|
this.authenticationListeners.add(listener);
|
|
@@ -118,10 +116,11 @@ var CaldikHttpClient = class {
|
|
|
118
116
|
const url = new URL(`${this.baseUrl()}${path}`);
|
|
119
117
|
if (params) for (const [key, value] of Object.entries(params)) url.searchParams.set(key, String(value));
|
|
120
118
|
const headers = { ...options?.headers };
|
|
119
|
+
if (!isBrowserRuntime() && this.storefrontOrigin) headers.Origin = this.storefrontOrigin;
|
|
121
120
|
if (!isBrowserRuntime()) headers["User-Agent"] = "CaldikClient/0.0.2";
|
|
122
121
|
if (!isBrowserRuntime() && options?.access === "public" && this.cookies.size) headers.Cookie = [...this.cookies].map(([name, value]) => `${name}=${value}`).join("; ");
|
|
123
122
|
if (this.apiKey) headers.Authorization = `Bearer ${this.apiKey}`;
|
|
124
|
-
else if (options?.access === "public"
|
|
123
|
+
else if (options?.access === "public") headers["X-Caldik-Public-Request"] = "1";
|
|
125
124
|
if (input !== void 0) headers["Content-Type"] = "application/json";
|
|
126
125
|
if (options?.edgeCache) headers["X-Cache-Policy"] = "public";
|
|
127
126
|
const response = await fetch(url, {
|