@atomic-solutions/woocommerce-react 0.5.0 → 0.6.0
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 +162 -63
- 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 +162 -65
- 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 +167 -63
- 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 +165 -65
- 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,14 @@ 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
|
+
statusCode: 500,
|
|
633
|
+
url: "",
|
|
634
|
+
method: "POST",
|
|
635
|
+
originalCode: "unknown_error"
|
|
636
|
+
});
|
|
629
637
|
var useAddToCart = () => {
|
|
630
638
|
const client = useWooCommerceClient();
|
|
631
639
|
const queryKeys = useWooCommerceQueryKeys();
|
|
@@ -644,15 +652,50 @@ var useAddToCart = () => {
|
|
|
644
652
|
},
|
|
645
653
|
onError: (error) => {
|
|
646
654
|
if (emitEvent) {
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
655
|
+
emitEvent(createErrorEvent("cart:item_added", toWooError(error)));
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
};
|
|
660
|
+
var useAddManyToCart = () => {
|
|
661
|
+
const client = useWooCommerceClient();
|
|
662
|
+
const queryKeys = useWooCommerceQueryKeys();
|
|
663
|
+
const queryClient = useQueryClient();
|
|
664
|
+
const emitEvent = useEventEmitter();
|
|
665
|
+
return useMutation({
|
|
666
|
+
mutationKey: queryKeys.cart.mutations.addItems(),
|
|
667
|
+
mutationFn: (input) => client.cart.addItems(input),
|
|
668
|
+
onSuccess: ({ cart, results }) => {
|
|
669
|
+
queryClient.setQueryData(queryKeys.cart.details(), cart);
|
|
670
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.cart.all });
|
|
671
|
+
if (!emitEvent) return;
|
|
672
|
+
results.forEach((result) => {
|
|
673
|
+
if (result.status >= 200 && result.status < 300) {
|
|
674
|
+
const addedItem = cart.items.find((item) => item.id === result.item.id);
|
|
675
|
+
if (addedItem) {
|
|
676
|
+
emitEvent(createSuccessEvent("cart:item_added", { item: addedItem, cart }));
|
|
677
|
+
}
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
emitEvent(
|
|
681
|
+
createErrorEvent(
|
|
682
|
+
"cart:item_added",
|
|
683
|
+
new WooCommerceApiError({
|
|
684
|
+
code: mapWooCommerceCode(result.code),
|
|
685
|
+
originalCode: result.code ?? "unknown_error",
|
|
686
|
+
message: result.message ?? "Failed to add item to cart",
|
|
687
|
+
statusCode: result.status,
|
|
688
|
+
url: "",
|
|
689
|
+
method: "POST",
|
|
690
|
+
requestBody: result.item
|
|
691
|
+
})
|
|
692
|
+
)
|
|
693
|
+
);
|
|
694
|
+
});
|
|
695
|
+
},
|
|
696
|
+
onError: (error) => {
|
|
697
|
+
if (emitEvent) {
|
|
698
|
+
emitEvent(createErrorEvent("cart:item_added", toWooError(error)));
|
|
656
699
|
}
|
|
657
700
|
}
|
|
658
701
|
});
|
|
@@ -675,15 +718,7 @@ var useUpdateCartItem = () => {
|
|
|
675
718
|
},
|
|
676
719
|
onError: (error) => {
|
|
677
720
|
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));
|
|
721
|
+
emitEvent(createErrorEvent("cart:item_updated", toWooError(error)));
|
|
687
722
|
}
|
|
688
723
|
}
|
|
689
724
|
});
|
|
@@ -705,15 +740,7 @@ var useRemoveFromCart = () => {
|
|
|
705
740
|
},
|
|
706
741
|
onError: (error) => {
|
|
707
742
|
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));
|
|
743
|
+
emitEvent(createErrorEvent("cart:item_removed", toWooError(error)));
|
|
717
744
|
}
|
|
718
745
|
}
|
|
719
746
|
});
|
|
@@ -735,15 +762,7 @@ var useApplyCoupon = () => {
|
|
|
735
762
|
},
|
|
736
763
|
onError: (error) => {
|
|
737
764
|
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));
|
|
765
|
+
emitEvent(createErrorEvent("cart:coupon_applied", toWooError(error)));
|
|
747
766
|
}
|
|
748
767
|
}
|
|
749
768
|
});
|
|
@@ -765,15 +784,7 @@ var useRemoveCoupon = () => {
|
|
|
765
784
|
},
|
|
766
785
|
onError: (error) => {
|
|
767
786
|
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));
|
|
787
|
+
emitEvent(createErrorEvent("cart:coupon_removed", toWooError(error)));
|
|
777
788
|
}
|
|
778
789
|
}
|
|
779
790
|
});
|
|
@@ -795,15 +806,7 @@ var useUpdateCustomer = () => {
|
|
|
795
806
|
},
|
|
796
807
|
onError: (error) => {
|
|
797
808
|
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));
|
|
809
|
+
emitEvent(createErrorEvent("cart:customer_updated", toWooError(error)));
|
|
807
810
|
}
|
|
808
811
|
}
|
|
809
812
|
});
|
|
@@ -825,15 +828,7 @@ var useSelectShippingRate = () => {
|
|
|
825
828
|
},
|
|
826
829
|
onError: (error) => {
|
|
827
830
|
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));
|
|
831
|
+
emitEvent(createErrorEvent("cart:shipping_selected", toWooError(error)));
|
|
837
832
|
}
|
|
838
833
|
}
|
|
839
834
|
});
|
|
@@ -910,6 +905,7 @@ var createQueryKeys = (prefix = ["woocommerce"]) => ({
|
|
|
910
905
|
// Mutation keys
|
|
911
906
|
mutations: {
|
|
912
907
|
addItem: () => [...prefix, "cart", "mutation", "addItem"],
|
|
908
|
+
addItems: () => [...prefix, "cart", "mutation", "addItems"],
|
|
913
909
|
updateItem: () => [...prefix, "cart", "mutation", "updateItem"],
|
|
914
910
|
removeItem: () => [...prefix, "cart", "mutation", "removeItem"],
|
|
915
911
|
applyCoupon: () => [...prefix, "cart", "mutation", "applyCoupon"],
|
|
@@ -1303,6 +1299,18 @@ function isPurchasable(status, quantity, manageStock = true) {
|
|
|
1303
1299
|
}
|
|
1304
1300
|
return true;
|
|
1305
1301
|
}
|
|
1302
|
+
function unavailableReason(product) {
|
|
1303
|
+
if (!product.is_in_stock || product.is_on_backorder || product.add_to_cart.maximum <= 0) {
|
|
1304
|
+
return "out_of_stock";
|
|
1305
|
+
}
|
|
1306
|
+
if (!product.is_purchasable) {
|
|
1307
|
+
return "not_purchasable";
|
|
1308
|
+
}
|
|
1309
|
+
return void 0;
|
|
1310
|
+
}
|
|
1311
|
+
function canAddToCart(product) {
|
|
1312
|
+
return !unavailableReason(product);
|
|
1313
|
+
}
|
|
1306
1314
|
function getStockSeverity(status, quantity, lowStockThreshold = 5) {
|
|
1307
1315
|
switch (status) {
|
|
1308
1316
|
case "outofstock":
|
|
@@ -1645,6 +1653,98 @@ function useCartView(options = {}) {
|
|
|
1645
1653
|
isBusy
|
|
1646
1654
|
};
|
|
1647
1655
|
}
|
|
1656
|
+
function useReorderView(items, options = {}) {
|
|
1657
|
+
const { imageSize = "thumbnail" } = options;
|
|
1658
|
+
const storeContext = useContext(WooCommerceStoreContext);
|
|
1659
|
+
const storeConfig = storeContext?.config;
|
|
1660
|
+
const localeTag = options.localeTag ?? storeConfig?.locale?.localeTag ?? DEFAULT_STORE_CONFIG.locale.localeTag;
|
|
1661
|
+
const fallbackImageUrl = options.fallbackImageUrl ?? storeConfig?.fallbackImageUrl;
|
|
1662
|
+
const imageUrlTransformer = storeConfig?.imageUrlTransformer;
|
|
1663
|
+
const productIds = useMemo(() => [...new Set(items.map((item) => item.productId))], [items]);
|
|
1664
|
+
const {
|
|
1665
|
+
data: productsPage,
|
|
1666
|
+
isLoading,
|
|
1667
|
+
error
|
|
1668
|
+
} = useProducts(
|
|
1669
|
+
{ include: productIds, page: 1, per_page: 100 },
|
|
1670
|
+
{ enabled: productIds.length > 0 }
|
|
1671
|
+
);
|
|
1672
|
+
const { data: cart } = useCart();
|
|
1673
|
+
const getProcessedImageUrl = useCallback(
|
|
1674
|
+
(images) => {
|
|
1675
|
+
const baseUrl = getImageUrl(images, imageSize, fallbackImageUrl);
|
|
1676
|
+
if (baseUrl && imageUrlTransformer) {
|
|
1677
|
+
return imageUrlTransformer(baseUrl, imageSize);
|
|
1678
|
+
}
|
|
1679
|
+
return baseUrl;
|
|
1680
|
+
},
|
|
1681
|
+
[imageSize, fallbackImageUrl, imageUrlTransformer]
|
|
1682
|
+
);
|
|
1683
|
+
const views = useMemo(() => {
|
|
1684
|
+
const products = new Map((productsPage?.data ?? []).map((product) => [product.id, product]));
|
|
1685
|
+
return items.map((item) => {
|
|
1686
|
+
const product = products.get(item.productId);
|
|
1687
|
+
if (!product) {
|
|
1688
|
+
return {
|
|
1689
|
+
productId: item.productId,
|
|
1690
|
+
name: "",
|
|
1691
|
+
requestedQuantity: item.quantity,
|
|
1692
|
+
minQuantity: 1,
|
|
1693
|
+
maxQuantity: 0,
|
|
1694
|
+
unitPrice: "-",
|
|
1695
|
+
lineTotal: "-",
|
|
1696
|
+
reason: "missing"
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
const currencyCode = product.prices.currency_code;
|
|
1700
|
+
const minQuantity = product.add_to_cart.minimum || 1;
|
|
1701
|
+
const maxQuantity = product.add_to_cart.maximum;
|
|
1702
|
+
const step = product.add_to_cart.multiple_of || 1;
|
|
1703
|
+
const upperQuantity = maxQuantity > 0 ? maxQuantity : item.quantity;
|
|
1704
|
+
const clampedQuantity = Math.min(Math.max(item.quantity, minQuantity), upperQuantity);
|
|
1705
|
+
const requestedQuantity = step > 1 ? Math.max(step, Math.floor(clampedQuantity / step) * step) : clampedQuantity;
|
|
1706
|
+
const unitAmount = Number(product.prices.price);
|
|
1707
|
+
const reason = unavailableReason(product);
|
|
1708
|
+
return {
|
|
1709
|
+
productId: product.id,
|
|
1710
|
+
name: product.name,
|
|
1711
|
+
imageUrl: getProcessedImageUrl(product.images),
|
|
1712
|
+
requestedQuantity,
|
|
1713
|
+
minQuantity,
|
|
1714
|
+
maxQuantity,
|
|
1715
|
+
unitPrice: formatStoreApiPriceIntl(product.prices.price, currencyCode, localeTag),
|
|
1716
|
+
lineTotal: formatStoreApiPriceIntl(
|
|
1717
|
+
Number.isNaN(unitAmount) ? null : String(unitAmount * requestedQuantity),
|
|
1718
|
+
currencyCode,
|
|
1719
|
+
localeTag
|
|
1720
|
+
),
|
|
1721
|
+
...reason ? { reason } : {},
|
|
1722
|
+
raw: product
|
|
1723
|
+
};
|
|
1724
|
+
});
|
|
1725
|
+
}, [items, productsPage?.data, localeTag, getProcessedImageUrl]);
|
|
1726
|
+
const cartProductIds = useMemo(
|
|
1727
|
+
() => new Set((cart?.items ?? []).map((item) => item.id)),
|
|
1728
|
+
[cart?.items]
|
|
1729
|
+
);
|
|
1730
|
+
const { addable, inCart, unavailable } = useMemo(
|
|
1731
|
+
() => ({
|
|
1732
|
+
addable: views.filter((view) => !view.reason && !cartProductIds.has(view.productId)),
|
|
1733
|
+
inCart: views.filter((view) => !view.reason && cartProductIds.has(view.productId)),
|
|
1734
|
+
unavailable: views.filter((view) => !!view.reason)
|
|
1735
|
+
}),
|
|
1736
|
+
[views, cartProductIds]
|
|
1737
|
+
);
|
|
1738
|
+
return {
|
|
1739
|
+
addable,
|
|
1740
|
+
inCart,
|
|
1741
|
+
unavailable,
|
|
1742
|
+
availableCount: addable.length + inCart.length,
|
|
1743
|
+
totalCount: views.length,
|
|
1744
|
+
isLoading,
|
|
1745
|
+
error
|
|
1746
|
+
};
|
|
1747
|
+
}
|
|
1648
1748
|
var ORDER_STATUS_LABELS = {
|
|
1649
1749
|
pending: "Pending Payment",
|
|
1650
1750
|
processing: "Processing",
|
|
@@ -1761,6 +1861,6 @@ function createAnalyticsHandler(provider) {
|
|
|
1761
1861
|
};
|
|
1762
1862
|
}
|
|
1763
1863
|
|
|
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 };
|
|
1864
|
+
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
1865
|
//# sourceMappingURL=index.js.map
|
|
1766
1866
|
//# sourceMappingURL=index.js.map
|