@atomic-solutions/woocommerce-react 0.5.0 → 0.6.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.
- package/dist/hooks/index.cjs +161 -64
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +161 -66
- package/dist/hooks/index.js.map +1 -1
- package/dist/{index-DdY_1X-C.d.cts → index-DEvJWFSF.d.cts} +96 -34
- package/dist/{index-unbfwba0.d.ts → index-Dmlapl9c.d.ts} +96 -34
- package/dist/index.cjs +166 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -19
- package/dist/index.d.ts +4 -19
- package/dist/index.js +164 -66
- package/dist/index.js.map +1 -1
- package/dist/provider/index.d.cts +2 -2
- package/dist/provider/index.d.ts +2 -2
- package/dist/{types-_8YqnkO-.d.cts → types-Dnq60zh-.d.cts} +3 -0
- package/dist/{types-_8YqnkO-.d.ts → types-Dnq60zh-.d.ts} +3 -0
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -2,10 +2,10 @@ import * as react from 'react';
|
|
|
2
2
|
import react__default from 'react';
|
|
3
3
|
import { WooCommerceClient } from '@atomic-solutions/woocommerce-api-client';
|
|
4
4
|
export { Address, AddressFormMessages, AddressFormValues, BillingAddress, BillingAddressFormValues, Cart, CartHeadersAdapter, CartItem, Checkout, OrderStatus, Product, ProductCategory, ProductImage, ProductParams, StoreApiOrder, addressSchema, checkoutSchema, makeAddressFormSchema, makeBillingAddressFormSchema } from '@atomic-solutions/woocommerce-api-client';
|
|
5
|
-
import { Q as QueryKeys, W as WooCommerceEventHandler, S as StoreLocale, a as StoreValidationResult, R as RateLimitConfig, b as WooCommerceEventType } from './types-
|
|
6
|
-
export { C as CartCouponAppliedEvent, c as CartCouponRemovedEvent, d as CartCustomerUpdatedEvent, e as CartItemAddedEvent, f as CartItemRemovedEvent, g as CartItemUpdatedEvent, h as CartShippingSelectedEvent, i as CheckoutProcessedEvent, D as DEFAULT_STORE_CONFIG, O as OrderFetchedEvent, j as StoreConfig, k as StoreContextValue, l as StoreFeatures, m as StoreGuardrails, n as StoreTheme, o as WooCommerceEvent, p as createQueryKeys } from './types-
|
|
5
|
+
import { Q as QueryKeys, W as WooCommerceEventHandler, S as StoreLocale, a as StoreValidationResult, R as RateLimitConfig, b as WooCommerceEventType } from './types-Dnq60zh-.cjs';
|
|
6
|
+
export { C as CartCouponAppliedEvent, c as CartCouponRemovedEvent, d as CartCustomerUpdatedEvent, e as CartItemAddedEvent, f as CartItemRemovedEvent, g as CartItemUpdatedEvent, h as CartShippingSelectedEvent, i as CheckoutProcessedEvent, D as DEFAULT_STORE_CONFIG, O as OrderFetchedEvent, j as StoreConfig, k as StoreContextValue, l as StoreFeatures, m as StoreGuardrails, n as StoreTheme, o as WooCommerceEvent, p as createQueryKeys } from './types-Dnq60zh-.cjs';
|
|
7
7
|
export { WooCommerceStoreContext, WooCommerceStoreProvider, WooCommerceStoreProviderProps } from './provider/index.cjs';
|
|
8
|
-
export { A as AppliedCoupon, C as CartTotals, I as ImageSize, P as PLACEHOLDER_IMAGE_URL, a as PaymentMethod, b as ProcessedCartItem, c as ProcessedCategory, d as ProcessedOrderDetails, e as ProcessedOrderLineItem, f as ProcessedProduct, g as ProcessedProductDetails, h as ProductCartState, i as ProductCategoryTreeNode, S as ShippingRate, U as UseCartViewOptions,
|
|
8
|
+
export { A as AppliedCoupon, C as CartTotals, I as ImageSize, P as PLACEHOLDER_IMAGE_URL, a as PaymentMethod, b as ProcessedCartItem, c as ProcessedCategory, d as ProcessedOrderDetails, e as ProcessedOrderLineItem, f as ProcessedProduct, g as ProcessedProductDetails, h as ProductCartState, i as ProductCategoryTreeNode, R as ReorderInputItem, j as ReorderItemView, k as ReorderUnavailableReason, S as ShippingRate, l as StockDisplayConfig, m as StockStatus, U as UnavailableReason, n as UseCartViewOptions, o as UseCartViewReturn, p as UseOrderViewOptions, q as UseOrderViewReturn, r as UseProductViewOptions, s as UseProductViewReturn, t as UseProductsFeedOptions, u as UseProductsFeedReturn, v as UseReorderViewOptions, w as UseReorderViewReturn, x as canAddToCart, y as getAllImageUrls, z as getImageUrl, B as getImageUrlOrPlaceholder, D as getMaxAddToCartQuantity, E as getOrderStatusLabel, F as getPrimaryImage, G as getSizedImageUrl, H as getStockSeverity, J as getStockStatusText, K as isLowStock, L as isPurchasable, M as preloadImage, N as preloadImages, O as unavailableReason, Q as useAddManyToCart, T as useAddToCart, V as useApplyCoupon, W as useCart, X as useCartView, Y as useCheckout, Z as useInfiniteProducts, _ as useOrder, $ as useOrderView, a0 as useProcessCheckout, a1 as useProduct, a2 as useProductCategories, a3 as useProductCategoryTree, a4 as useProductView, a5 as useProducts, a6 as useProductsFeed, a7 as useRemoveCoupon, a8 as useRemoveFromCart, a9 as useReorderView, aa as useSelectShippingRate, ab as useStore, ac as useStoreFeatures, ad as useStoreLocale, ae as useStoreTheme, af as useUpdateCartItem, ag as useUpdateCustomer, ah as useWooCommerceClient, ai as useWooCommerceQueryKeys } from './index-DEvJWFSF.cjs';
|
|
9
9
|
import 'react/jsx-runtime';
|
|
10
10
|
import '@tanstack/react-query';
|
|
11
11
|
|
|
@@ -32,21 +32,6 @@ declare function formatDiscountBadge(regularPrice: string | number, salePrice: s
|
|
|
32
32
|
declare function formatStoreApiPriceIntl(priceInMinorUnits: string | undefined | null, currencyCode: string | undefined | null, localeTag?: string): string;
|
|
33
33
|
declare function parseWooCommercePrice(priceString: string): number;
|
|
34
34
|
|
|
35
|
-
type StockStatus = 'instock' | 'outofstock' | 'onbackorder';
|
|
36
|
-
interface StockDisplayConfig {
|
|
37
|
-
inStockText?: string;
|
|
38
|
-
outOfStockText?: string;
|
|
39
|
-
backorderText?: string;
|
|
40
|
-
showQuantity?: boolean;
|
|
41
|
-
lowStockThreshold?: number;
|
|
42
|
-
lowStockText?: string;
|
|
43
|
-
}
|
|
44
|
-
declare function getStockStatusText(status: StockStatus, quantity?: number | null, config?: StockDisplayConfig): string;
|
|
45
|
-
declare function isPurchasable(status: StockStatus, quantity?: number | null, manageStock?: boolean): boolean;
|
|
46
|
-
declare function getStockSeverity(status: StockStatus, quantity?: number | null, lowStockThreshold?: number): 'success' | 'warning' | 'error' | 'info';
|
|
47
|
-
declare function isLowStock(status: StockStatus, quantity?: number | null, threshold?: number): boolean;
|
|
48
|
-
declare function getMaxAddToCartQuantity(status: StockStatus, stockQuantity?: number | null, cartQuantity?: number, maxPurchaseQuantity?: number | null): number;
|
|
49
|
-
|
|
50
35
|
declare function normalizeStoreUrl(url: string): string;
|
|
51
36
|
declare function getBaseUrl(normalizedUrl: string): string;
|
|
52
37
|
declare function validateWooCommerceStore(url: string, options?: {
|
|
@@ -92,4 +77,4 @@ type AnalyticsEventName = 'add_to_cart' | 'remove_from_cart' | 'update_cart_quan
|
|
|
92
77
|
|
|
93
78
|
declare function createAnalyticsHandler(provider: AnalyticsProvider): WooCommerceEventHandler;
|
|
94
79
|
|
|
95
|
-
export { type AnalyticsEventMap, type AnalyticsEventName, type AnalyticsProvider, QueryKeys, RateLimitConfig, RateLimiter,
|
|
80
|
+
export { type AnalyticsEventMap, type AnalyticsEventName, type AnalyticsProvider, QueryKeys, RateLimitConfig, RateLimiter, StoreLocale, StoreValidationResult, WooCommerceContext, type WooCommerceContextValue, WooCommerceEventHandler, WooCommerceEventType, WooCommerceProvider, type WooCommerceProviderProps, calculateDiscount, composeHandlers, configureGlobalRateLimiter, createAnalyticsHandler, formatDiscountBadge, formatPrice, formatPriceRange, formatStoreApiPrice, formatStoreApiPriceIntl, getBaseUrl, getCurrencySymbol, getGlobalRateLimiter, isValidStoreUrlFormat, normalizeStoreUrl, parseWooCommercePrice, resetGlobalRateLimiter, validateWooCommerceStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import * as react from 'react';
|
|
|
2
2
|
import react__default from 'react';
|
|
3
3
|
import { WooCommerceClient } from '@atomic-solutions/woocommerce-api-client';
|
|
4
4
|
export { Address, AddressFormMessages, AddressFormValues, BillingAddress, BillingAddressFormValues, Cart, CartHeadersAdapter, CartItem, Checkout, OrderStatus, Product, ProductCategory, ProductImage, ProductParams, StoreApiOrder, addressSchema, checkoutSchema, makeAddressFormSchema, makeBillingAddressFormSchema } from '@atomic-solutions/woocommerce-api-client';
|
|
5
|
-
import { Q as QueryKeys, W as WooCommerceEventHandler, S as StoreLocale, a as StoreValidationResult, R as RateLimitConfig, b as WooCommerceEventType } from './types-
|
|
6
|
-
export { C as CartCouponAppliedEvent, c as CartCouponRemovedEvent, d as CartCustomerUpdatedEvent, e as CartItemAddedEvent, f as CartItemRemovedEvent, g as CartItemUpdatedEvent, h as CartShippingSelectedEvent, i as CheckoutProcessedEvent, D as DEFAULT_STORE_CONFIG, O as OrderFetchedEvent, j as StoreConfig, k as StoreContextValue, l as StoreFeatures, m as StoreGuardrails, n as StoreTheme, o as WooCommerceEvent, p as createQueryKeys } from './types-
|
|
5
|
+
import { Q as QueryKeys, W as WooCommerceEventHandler, S as StoreLocale, a as StoreValidationResult, R as RateLimitConfig, b as WooCommerceEventType } from './types-Dnq60zh-.js';
|
|
6
|
+
export { C as CartCouponAppliedEvent, c as CartCouponRemovedEvent, d as CartCustomerUpdatedEvent, e as CartItemAddedEvent, f as CartItemRemovedEvent, g as CartItemUpdatedEvent, h as CartShippingSelectedEvent, i as CheckoutProcessedEvent, D as DEFAULT_STORE_CONFIG, O as OrderFetchedEvent, j as StoreConfig, k as StoreContextValue, l as StoreFeatures, m as StoreGuardrails, n as StoreTheme, o as WooCommerceEvent, p as createQueryKeys } from './types-Dnq60zh-.js';
|
|
7
7
|
export { WooCommerceStoreContext, WooCommerceStoreProvider, WooCommerceStoreProviderProps } from './provider/index.js';
|
|
8
|
-
export { A as AppliedCoupon, C as CartTotals, I as ImageSize, P as PLACEHOLDER_IMAGE_URL, a as PaymentMethod, b as ProcessedCartItem, c as ProcessedCategory, d as ProcessedOrderDetails, e as ProcessedOrderLineItem, f as ProcessedProduct, g as ProcessedProductDetails, h as ProductCartState, i as ProductCategoryTreeNode, S as ShippingRate, U as UseCartViewOptions,
|
|
8
|
+
export { A as AppliedCoupon, C as CartTotals, I as ImageSize, P as PLACEHOLDER_IMAGE_URL, a as PaymentMethod, b as ProcessedCartItem, c as ProcessedCategory, d as ProcessedOrderDetails, e as ProcessedOrderLineItem, f as ProcessedProduct, g as ProcessedProductDetails, h as ProductCartState, i as ProductCategoryTreeNode, R as ReorderInputItem, j as ReorderItemView, k as ReorderUnavailableReason, S as ShippingRate, l as StockDisplayConfig, m as StockStatus, U as UnavailableReason, n as UseCartViewOptions, o as UseCartViewReturn, p as UseOrderViewOptions, q as UseOrderViewReturn, r as UseProductViewOptions, s as UseProductViewReturn, t as UseProductsFeedOptions, u as UseProductsFeedReturn, v as UseReorderViewOptions, w as UseReorderViewReturn, x as canAddToCart, y as getAllImageUrls, z as getImageUrl, B as getImageUrlOrPlaceholder, D as getMaxAddToCartQuantity, E as getOrderStatusLabel, F as getPrimaryImage, G as getSizedImageUrl, H as getStockSeverity, J as getStockStatusText, K as isLowStock, L as isPurchasable, M as preloadImage, N as preloadImages, O as unavailableReason, Q as useAddManyToCart, T as useAddToCart, V as useApplyCoupon, W as useCart, X as useCartView, Y as useCheckout, Z as useInfiniteProducts, _ as useOrder, $ as useOrderView, a0 as useProcessCheckout, a1 as useProduct, a2 as useProductCategories, a3 as useProductCategoryTree, a4 as useProductView, a5 as useProducts, a6 as useProductsFeed, a7 as useRemoveCoupon, a8 as useRemoveFromCart, a9 as useReorderView, aa as useSelectShippingRate, ab as useStore, ac as useStoreFeatures, ad as useStoreLocale, ae as useStoreTheme, af as useUpdateCartItem, ag as useUpdateCustomer, ah as useWooCommerceClient, ai as useWooCommerceQueryKeys } from './index-Dmlapl9c.js';
|
|
9
9
|
import 'react/jsx-runtime';
|
|
10
10
|
import '@tanstack/react-query';
|
|
11
11
|
|
|
@@ -32,21 +32,6 @@ declare function formatDiscountBadge(regularPrice: string | number, salePrice: s
|
|
|
32
32
|
declare function formatStoreApiPriceIntl(priceInMinorUnits: string | undefined | null, currencyCode: string | undefined | null, localeTag?: string): string;
|
|
33
33
|
declare function parseWooCommercePrice(priceString: string): number;
|
|
34
34
|
|
|
35
|
-
type StockStatus = 'instock' | 'outofstock' | 'onbackorder';
|
|
36
|
-
interface StockDisplayConfig {
|
|
37
|
-
inStockText?: string;
|
|
38
|
-
outOfStockText?: string;
|
|
39
|
-
backorderText?: string;
|
|
40
|
-
showQuantity?: boolean;
|
|
41
|
-
lowStockThreshold?: number;
|
|
42
|
-
lowStockText?: string;
|
|
43
|
-
}
|
|
44
|
-
declare function getStockStatusText(status: StockStatus, quantity?: number | null, config?: StockDisplayConfig): string;
|
|
45
|
-
declare function isPurchasable(status: StockStatus, quantity?: number | null, manageStock?: boolean): boolean;
|
|
46
|
-
declare function getStockSeverity(status: StockStatus, quantity?: number | null, lowStockThreshold?: number): 'success' | 'warning' | 'error' | 'info';
|
|
47
|
-
declare function isLowStock(status: StockStatus, quantity?: number | null, threshold?: number): boolean;
|
|
48
|
-
declare function getMaxAddToCartQuantity(status: StockStatus, stockQuantity?: number | null, cartQuantity?: number, maxPurchaseQuantity?: number | null): number;
|
|
49
|
-
|
|
50
35
|
declare function normalizeStoreUrl(url: string): string;
|
|
51
36
|
declare function getBaseUrl(normalizedUrl: string): string;
|
|
52
37
|
declare function validateWooCommerceStore(url: string, options?: {
|
|
@@ -92,4 +77,4 @@ type AnalyticsEventName = 'add_to_cart' | 'remove_from_cart' | 'update_cart_quan
|
|
|
92
77
|
|
|
93
78
|
declare function createAnalyticsHandler(provider: AnalyticsProvider): WooCommerceEventHandler;
|
|
94
79
|
|
|
95
|
-
export { type AnalyticsEventMap, type AnalyticsEventName, type AnalyticsProvider, QueryKeys, RateLimitConfig, RateLimiter,
|
|
80
|
+
export { type AnalyticsEventMap, type AnalyticsEventName, type AnalyticsProvider, QueryKeys, RateLimitConfig, RateLimiter, StoreLocale, StoreValidationResult, WooCommerceContext, type WooCommerceContextValue, WooCommerceEventHandler, WooCommerceEventType, WooCommerceProvider, type WooCommerceProviderProps, calculateDiscount, composeHandlers, configureGlobalRateLimiter, createAnalyticsHandler, formatDiscountBadge, formatPrice, formatPriceRange, formatStoreApiPrice, formatStoreApiPriceIntl, getBaseUrl, getCurrencySymbol, getGlobalRateLimiter, isValidStoreUrlFormat, normalizeStoreUrl, parseWooCommercePrice, resetGlobalRateLimiter, validateWooCommerceStore };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext, useMemo, useState, useEffect, useRef, useCallback, useContext } from 'react';
|
|
2
2
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
-
import { createClient, WooCommerceApiError } from '@atomic-solutions/woocommerce-api-client';
|
|
3
|
+
import { createClient, WooCommerceApiError, mapWooCommerceCode } from '@atomic-solutions/woocommerce-api-client';
|
|
4
4
|
export { addressSchema, checkoutSchema, makeAddressFormSchema, makeBillingAddressFormSchema } from '@atomic-solutions/woocommerce-api-client';
|
|
5
5
|
import { useQuery, useQueryClient, useMutation, useInfiniteQuery } from '@tanstack/react-query';
|
|
6
6
|
|
|
@@ -626,6 +626,13 @@ var useCart = (options) => {
|
|
|
626
626
|
getQuantity
|
|
627
627
|
};
|
|
628
628
|
};
|
|
629
|
+
var toWooError = (error) => error instanceof WooCommerceApiError ? error : new WooCommerceApiError({
|
|
630
|
+
code: "unknown_error",
|
|
631
|
+
message: error instanceof Error ? error.message : "Unknown error",
|
|
632
|
+
url: "",
|
|
633
|
+
method: "POST",
|
|
634
|
+
originalCode: "unknown_error"
|
|
635
|
+
});
|
|
629
636
|
var useAddToCart = () => {
|
|
630
637
|
const client = useWooCommerceClient();
|
|
631
638
|
const queryKeys = useWooCommerceQueryKeys();
|
|
@@ -644,15 +651,50 @@ var useAddToCart = () => {
|
|
|
644
651
|
},
|
|
645
652
|
onError: (error) => {
|
|
646
653
|
if (emitEvent) {
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
654
|
+
emitEvent(createErrorEvent("cart:item_added", toWooError(error)));
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
};
|
|
659
|
+
var useAddManyToCart = () => {
|
|
660
|
+
const client = useWooCommerceClient();
|
|
661
|
+
const queryKeys = useWooCommerceQueryKeys();
|
|
662
|
+
const queryClient = useQueryClient();
|
|
663
|
+
const emitEvent = useEventEmitter();
|
|
664
|
+
return useMutation({
|
|
665
|
+
mutationKey: queryKeys.cart.mutations.addItems(),
|
|
666
|
+
mutationFn: (input) => client.cart.addItems(input),
|
|
667
|
+
onSuccess: ({ cart, results }) => {
|
|
668
|
+
queryClient.setQueryData(queryKeys.cart.details(), cart);
|
|
669
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.cart.all });
|
|
670
|
+
if (!emitEvent) return;
|
|
671
|
+
results.forEach((result) => {
|
|
672
|
+
if (result.status >= 200 && result.status < 300) {
|
|
673
|
+
const addedItem = cart.items.find((item) => item.id === result.item.id);
|
|
674
|
+
if (addedItem) {
|
|
675
|
+
emitEvent(createSuccessEvent("cart:item_added", { item: addedItem, cart }));
|
|
676
|
+
}
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
emitEvent(
|
|
680
|
+
createErrorEvent(
|
|
681
|
+
"cart:item_added",
|
|
682
|
+
new WooCommerceApiError({
|
|
683
|
+
code: mapWooCommerceCode(result.code),
|
|
684
|
+
originalCode: result.code ?? "unknown_error",
|
|
685
|
+
message: result.message ?? "Failed to add item to cart",
|
|
686
|
+
statusCode: result.status,
|
|
687
|
+
url: "",
|
|
688
|
+
method: "POST",
|
|
689
|
+
requestBody: result.item
|
|
690
|
+
})
|
|
691
|
+
)
|
|
692
|
+
);
|
|
693
|
+
});
|
|
694
|
+
},
|
|
695
|
+
onError: (error) => {
|
|
696
|
+
if (emitEvent) {
|
|
697
|
+
emitEvent(createErrorEvent("cart:item_added", toWooError(error)));
|
|
656
698
|
}
|
|
657
699
|
}
|
|
658
700
|
});
|
|
@@ -675,15 +717,7 @@ var useUpdateCartItem = () => {
|
|
|
675
717
|
},
|
|
676
718
|
onError: (error) => {
|
|
677
719
|
if (emitEvent) {
|
|
678
|
-
|
|
679
|
-
code: "unknown_error",
|
|
680
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
681
|
-
statusCode: 500,
|
|
682
|
-
url: "",
|
|
683
|
-
method: "POST",
|
|
684
|
-
originalCode: "unknown_error"
|
|
685
|
-
});
|
|
686
|
-
emitEvent(createErrorEvent("cart:item_updated", wooError));
|
|
720
|
+
emitEvent(createErrorEvent("cart:item_updated", toWooError(error)));
|
|
687
721
|
}
|
|
688
722
|
}
|
|
689
723
|
});
|
|
@@ -705,15 +739,7 @@ var useRemoveFromCart = () => {
|
|
|
705
739
|
},
|
|
706
740
|
onError: (error) => {
|
|
707
741
|
if (emitEvent) {
|
|
708
|
-
|
|
709
|
-
code: "unknown_error",
|
|
710
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
711
|
-
statusCode: 500,
|
|
712
|
-
url: "",
|
|
713
|
-
method: "POST",
|
|
714
|
-
originalCode: "unknown_error"
|
|
715
|
-
});
|
|
716
|
-
emitEvent(createErrorEvent("cart:item_removed", wooError));
|
|
742
|
+
emitEvent(createErrorEvent("cart:item_removed", toWooError(error)));
|
|
717
743
|
}
|
|
718
744
|
}
|
|
719
745
|
});
|
|
@@ -735,15 +761,7 @@ var useApplyCoupon = () => {
|
|
|
735
761
|
},
|
|
736
762
|
onError: (error) => {
|
|
737
763
|
if (emitEvent) {
|
|
738
|
-
|
|
739
|
-
code: "unknown_error",
|
|
740
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
741
|
-
statusCode: 500,
|
|
742
|
-
url: "",
|
|
743
|
-
method: "POST",
|
|
744
|
-
originalCode: "unknown_error"
|
|
745
|
-
});
|
|
746
|
-
emitEvent(createErrorEvent("cart:coupon_applied", wooError));
|
|
764
|
+
emitEvent(createErrorEvent("cart:coupon_applied", toWooError(error)));
|
|
747
765
|
}
|
|
748
766
|
}
|
|
749
767
|
});
|
|
@@ -765,15 +783,7 @@ var useRemoveCoupon = () => {
|
|
|
765
783
|
},
|
|
766
784
|
onError: (error) => {
|
|
767
785
|
if (emitEvent) {
|
|
768
|
-
|
|
769
|
-
code: "unknown_error",
|
|
770
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
771
|
-
statusCode: 500,
|
|
772
|
-
url: "",
|
|
773
|
-
method: "POST",
|
|
774
|
-
originalCode: "unknown_error"
|
|
775
|
-
});
|
|
776
|
-
emitEvent(createErrorEvent("cart:coupon_removed", wooError));
|
|
786
|
+
emitEvent(createErrorEvent("cart:coupon_removed", toWooError(error)));
|
|
777
787
|
}
|
|
778
788
|
}
|
|
779
789
|
});
|
|
@@ -795,15 +805,7 @@ var useUpdateCustomer = () => {
|
|
|
795
805
|
},
|
|
796
806
|
onError: (error) => {
|
|
797
807
|
if (emitEvent) {
|
|
798
|
-
|
|
799
|
-
code: "unknown_error",
|
|
800
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
801
|
-
statusCode: 500,
|
|
802
|
-
url: "",
|
|
803
|
-
method: "POST",
|
|
804
|
-
originalCode: "unknown_error"
|
|
805
|
-
});
|
|
806
|
-
emitEvent(createErrorEvent("cart:customer_updated", wooError));
|
|
808
|
+
emitEvent(createErrorEvent("cart:customer_updated", toWooError(error)));
|
|
807
809
|
}
|
|
808
810
|
}
|
|
809
811
|
});
|
|
@@ -825,15 +827,7 @@ var useSelectShippingRate = () => {
|
|
|
825
827
|
},
|
|
826
828
|
onError: (error) => {
|
|
827
829
|
if (emitEvent) {
|
|
828
|
-
|
|
829
|
-
code: "unknown_error",
|
|
830
|
-
message: error instanceof Error ? error.message : "Unknown error",
|
|
831
|
-
statusCode: 500,
|
|
832
|
-
url: "",
|
|
833
|
-
method: "POST",
|
|
834
|
-
originalCode: "unknown_error"
|
|
835
|
-
});
|
|
836
|
-
emitEvent(createErrorEvent("cart:shipping_selected", wooError));
|
|
830
|
+
emitEvent(createErrorEvent("cart:shipping_selected", toWooError(error)));
|
|
837
831
|
}
|
|
838
832
|
}
|
|
839
833
|
});
|
|
@@ -869,7 +863,6 @@ var useProcessCheckout = () => {
|
|
|
869
863
|
const wooError = error instanceof WooCommerceApiError ? error : new WooCommerceApiError({
|
|
870
864
|
code: "unknown_error",
|
|
871
865
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
872
|
-
statusCode: 500,
|
|
873
866
|
url: "",
|
|
874
867
|
method: "POST",
|
|
875
868
|
originalCode: "unknown_error"
|
|
@@ -910,6 +903,7 @@ var createQueryKeys = (prefix = ["woocommerce"]) => ({
|
|
|
910
903
|
// Mutation keys
|
|
911
904
|
mutations: {
|
|
912
905
|
addItem: () => [...prefix, "cart", "mutation", "addItem"],
|
|
906
|
+
addItems: () => [...prefix, "cart", "mutation", "addItems"],
|
|
913
907
|
updateItem: () => [...prefix, "cart", "mutation", "updateItem"],
|
|
914
908
|
removeItem: () => [...prefix, "cart", "mutation", "removeItem"],
|
|
915
909
|
applyCoupon: () => [...prefix, "cart", "mutation", "applyCoupon"],
|
|
@@ -1303,6 +1297,18 @@ function isPurchasable(status, quantity, manageStock = true) {
|
|
|
1303
1297
|
}
|
|
1304
1298
|
return true;
|
|
1305
1299
|
}
|
|
1300
|
+
function unavailableReason(product) {
|
|
1301
|
+
if (!product.is_in_stock || product.is_on_backorder || product.add_to_cart.maximum <= 0) {
|
|
1302
|
+
return "out_of_stock";
|
|
1303
|
+
}
|
|
1304
|
+
if (!product.is_purchasable) {
|
|
1305
|
+
return "not_purchasable";
|
|
1306
|
+
}
|
|
1307
|
+
return void 0;
|
|
1308
|
+
}
|
|
1309
|
+
function canAddToCart(product) {
|
|
1310
|
+
return !unavailableReason(product);
|
|
1311
|
+
}
|
|
1306
1312
|
function getStockSeverity(status, quantity, lowStockThreshold = 5) {
|
|
1307
1313
|
switch (status) {
|
|
1308
1314
|
case "outofstock":
|
|
@@ -1645,6 +1651,98 @@ function useCartView(options = {}) {
|
|
|
1645
1651
|
isBusy
|
|
1646
1652
|
};
|
|
1647
1653
|
}
|
|
1654
|
+
function useReorderView(items, options = {}) {
|
|
1655
|
+
const { imageSize = "thumbnail" } = options;
|
|
1656
|
+
const storeContext = useContext(WooCommerceStoreContext);
|
|
1657
|
+
const storeConfig = storeContext?.config;
|
|
1658
|
+
const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
|
|
1659
|
+
const fallbackImageUrl = options.fallbackImageUrl ?? storeConfig?.fallbackImageUrl;
|
|
1660
|
+
const imageUrlTransformer = storeConfig?.imageUrlTransformer;
|
|
1661
|
+
const productIds = useMemo(() => [...new Set(items.map((item) => item.productId))], [items]);
|
|
1662
|
+
const {
|
|
1663
|
+
data: productsPage,
|
|
1664
|
+
isLoading,
|
|
1665
|
+
error
|
|
1666
|
+
} = useProducts(
|
|
1667
|
+
{ include: productIds, page: 1, per_page: 100 },
|
|
1668
|
+
{ enabled: productIds.length > 0 }
|
|
1669
|
+
);
|
|
1670
|
+
const { data: cart } = useCart();
|
|
1671
|
+
const getProcessedImageUrl = useCallback(
|
|
1672
|
+
(images) => {
|
|
1673
|
+
const baseUrl = getImageUrl(images, imageSize, fallbackImageUrl);
|
|
1674
|
+
if (baseUrl && imageUrlTransformer) {
|
|
1675
|
+
return imageUrlTransformer(baseUrl, imageSize);
|
|
1676
|
+
}
|
|
1677
|
+
return baseUrl;
|
|
1678
|
+
},
|
|
1679
|
+
[imageSize, fallbackImageUrl, imageUrlTransformer]
|
|
1680
|
+
);
|
|
1681
|
+
const views = useMemo(() => {
|
|
1682
|
+
const products = new Map((productsPage?.data ?? []).map((product) => [product.id, product]));
|
|
1683
|
+
return items.map((item) => {
|
|
1684
|
+
const product = products.get(item.productId);
|
|
1685
|
+
if (!product) {
|
|
1686
|
+
return {
|
|
1687
|
+
productId: item.productId,
|
|
1688
|
+
name: "",
|
|
1689
|
+
requestedQuantity: item.quantity,
|
|
1690
|
+
minQuantity: 1,
|
|
1691
|
+
maxQuantity: 0,
|
|
1692
|
+
unitPrice: "-",
|
|
1693
|
+
lineTotal: "-",
|
|
1694
|
+
reason: "missing"
|
|
1695
|
+
};
|
|
1696
|
+
}
|
|
1697
|
+
const currencyCode = product.prices.currency_code;
|
|
1698
|
+
const minQuantity = product.add_to_cart.minimum || 1;
|
|
1699
|
+
const maxQuantity = product.add_to_cart.maximum;
|
|
1700
|
+
const step = product.add_to_cart.multiple_of || 1;
|
|
1701
|
+
const upperQuantity = maxQuantity > 0 ? maxQuantity : item.quantity;
|
|
1702
|
+
const clampedQuantity = Math.min(Math.max(item.quantity, minQuantity), upperQuantity);
|
|
1703
|
+
const requestedQuantity = step > 1 ? Math.max(step, Math.floor(clampedQuantity / step) * step) : clampedQuantity;
|
|
1704
|
+
const unitAmount = Number(product.prices.price);
|
|
1705
|
+
const reason = unavailableReason(product);
|
|
1706
|
+
return {
|
|
1707
|
+
productId: product.id,
|
|
1708
|
+
name: product.name,
|
|
1709
|
+
imageUrl: getProcessedImageUrl(product.images),
|
|
1710
|
+
requestedQuantity,
|
|
1711
|
+
minQuantity,
|
|
1712
|
+
maxQuantity,
|
|
1713
|
+
unitPrice: formatStoreApiPriceIntl(product.prices.price, currencyCode, localeTag),
|
|
1714
|
+
lineTotal: formatStoreApiPriceIntl(
|
|
1715
|
+
Number.isNaN(unitAmount) ? null : String(unitAmount * requestedQuantity),
|
|
1716
|
+
currencyCode,
|
|
1717
|
+
localeTag
|
|
1718
|
+
),
|
|
1719
|
+
...reason ? { reason } : {},
|
|
1720
|
+
raw: product
|
|
1721
|
+
};
|
|
1722
|
+
});
|
|
1723
|
+
}, [items, productsPage?.data, localeTag, getProcessedImageUrl]);
|
|
1724
|
+
const cartProductIds = useMemo(
|
|
1725
|
+
() => new Set((cart?.items ?? []).map((item) => item.id)),
|
|
1726
|
+
[cart?.items]
|
|
1727
|
+
);
|
|
1728
|
+
const { addable, inCart, unavailable } = useMemo(
|
|
1729
|
+
() => ({
|
|
1730
|
+
addable: views.filter((view) => !view.reason && !cartProductIds.has(view.productId)),
|
|
1731
|
+
inCart: views.filter((view) => !view.reason && cartProductIds.has(view.productId)),
|
|
1732
|
+
unavailable: views.filter((view) => !!view.reason)
|
|
1733
|
+
}),
|
|
1734
|
+
[views, cartProductIds]
|
|
1735
|
+
);
|
|
1736
|
+
return {
|
|
1737
|
+
addable,
|
|
1738
|
+
inCart,
|
|
1739
|
+
unavailable,
|
|
1740
|
+
availableCount: addable.length + inCart.length,
|
|
1741
|
+
totalCount: views.length,
|
|
1742
|
+
isLoading,
|
|
1743
|
+
error
|
|
1744
|
+
};
|
|
1745
|
+
}
|
|
1648
1746
|
var ORDER_STATUS_LABELS = {
|
|
1649
1747
|
pending: "Pending Payment",
|
|
1650
1748
|
processing: "Processing",
|
|
@@ -1761,6 +1859,6 @@ function createAnalyticsHandler(provider) {
|
|
|
1761
1859
|
};
|
|
1762
1860
|
}
|
|
1763
1861
|
|
|
1764
|
-
export { DEFAULT_STORE_CONFIG, PLACEHOLDER_IMAGE_URL, RateLimiter, WooCommerceContext, WooCommerceProvider, WooCommerceStoreContext, WooCommerceStoreProvider, calculateDiscount, composeHandlers, configureGlobalRateLimiter, createAnalyticsHandler, createQueryKeys, formatDiscountBadge, formatPrice, formatPriceRange, formatStoreApiPrice, formatStoreApiPriceIntl, getAllImageUrls, getBaseUrl, getCurrencySymbol, getGlobalRateLimiter, getImageUrl, getImageUrlOrPlaceholder, getMaxAddToCartQuantity, getOrderStatusLabel, getPrimaryImage, getSizedImageUrl, getStockSeverity, getStockStatusText, isLowStock, isPurchasable, isValidStoreUrlFormat, normalizeStoreUrl, parseWooCommercePrice, preloadImage, preloadImages, resetGlobalRateLimiter, useAddToCart, useApplyCoupon, useCart, useCartView, useCheckout, useInfiniteProducts, useOrder, useOrderView, useProcessCheckout, useProduct, useProductCategories, useProductCategoryTree, useProductView, useProducts, useProductsFeed, useRemoveCoupon, useRemoveFromCart, useSelectShippingRate, useStore, useStoreFeatures, useStoreLocale, useStoreTheme, useUpdateCartItem, useUpdateCustomer, useWooCommerceClient, useWooCommerceQueryKeys, validateWooCommerceStore };
|
|
1862
|
+
export { DEFAULT_STORE_CONFIG, PLACEHOLDER_IMAGE_URL, RateLimiter, WooCommerceContext, WooCommerceProvider, WooCommerceStoreContext, WooCommerceStoreProvider, calculateDiscount, canAddToCart, composeHandlers, configureGlobalRateLimiter, createAnalyticsHandler, createQueryKeys, formatDiscountBadge, formatPrice, formatPriceRange, formatStoreApiPrice, formatStoreApiPriceIntl, getAllImageUrls, getBaseUrl, getCurrencySymbol, getGlobalRateLimiter, getImageUrl, getImageUrlOrPlaceholder, getMaxAddToCartQuantity, getOrderStatusLabel, getPrimaryImage, getSizedImageUrl, getStockSeverity, getStockStatusText, isLowStock, isPurchasable, isValidStoreUrlFormat, normalizeStoreUrl, parseWooCommercePrice, preloadImage, preloadImages, resetGlobalRateLimiter, unavailableReason, useAddManyToCart, useAddToCart, useApplyCoupon, useCart, useCartView, useCheckout, useInfiniteProducts, useOrder, useOrderView, useProcessCheckout, useProduct, useProductCategories, useProductCategoryTree, useProductView, useProducts, useProductsFeed, useRemoveCoupon, useRemoveFromCart, useReorderView, useSelectShippingRate, useStore, useStoreFeatures, useStoreLocale, useStoreTheme, useUpdateCartItem, useUpdateCustomer, useWooCommerceClient, useWooCommerceQueryKeys, validateWooCommerceStore };
|
|
1765
1863
|
//# sourceMappingURL=index.js.map
|
|
1766
1864
|
//# sourceMappingURL=index.js.map
|