@atomic-solutions/woocommerce-react 0.1.0 → 0.2.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 +33 -27
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +3 -3
- package/dist/hooks/index.d.ts +3 -3
- package/dist/hooks/index.js +25 -19
- package/dist/hooks/index.js.map +1 -1
- package/dist/{index-BVhiD2zV.d.ts → index-BCMhB3fU.d.ts} +1379 -1375
- package/dist/{index-DKVISMaw.d.cts → index-CPpVyoLQ.d.cts} +1379 -1375
- package/dist/index.cjs +36 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +26 -20
- package/dist/index.js.map +1 -1
- package/dist/provider/index.cjs +2 -2
- package/dist/provider/index.cjs.map +1 -1
- package/dist/provider/index.d.cts +3 -3
- package/dist/provider/index.d.ts +3 -3
- package/dist/provider/index.js +1 -1
- package/dist/provider/index.js.map +1 -1
- package/dist/{types-wgwJGLQ-.d.cts → types-BDwpAWoN.d.cts} +14 -14
- package/dist/{types-wgwJGLQ-.d.ts → types-BDwpAWoN.d.ts} +14 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
var
|
|
5
|
+
var woocommerceApiClient = require('@atomic-solutions/woocommerce-api-client');
|
|
6
6
|
var reactQuery = require('@tanstack/react-query');
|
|
7
7
|
|
|
8
8
|
// src/provider/WooCommerceProvider.tsx
|
|
@@ -362,7 +362,7 @@ function WooCommerceStoreProvider({
|
|
|
362
362
|
const cartHeadersAdapter = react.useRef(createCartHeadersAdapter());
|
|
363
363
|
const client = react.useMemo(() => {
|
|
364
364
|
const normalizedUrl = normalizeStoreUrl(config.storeUrl);
|
|
365
|
-
return
|
|
365
|
+
return woocommerceApiClient.createClient({
|
|
366
366
|
baseURL: normalizedUrl,
|
|
367
367
|
storeApiVersion: "v1",
|
|
368
368
|
cartHeaders: cartHeadersAdapter.current,
|
|
@@ -488,8 +488,7 @@ var useInfiniteWooQuery = ({
|
|
|
488
488
|
queryFn,
|
|
489
489
|
params,
|
|
490
490
|
perPage = 10,
|
|
491
|
-
|
|
492
|
-
enabled
|
|
491
|
+
options
|
|
493
492
|
}) => {
|
|
494
493
|
const query = reactQuery.useInfiniteQuery({
|
|
495
494
|
queryKey,
|
|
@@ -501,8 +500,8 @@ var useInfiniteWooQuery = ({
|
|
|
501
500
|
initialPageParam: 1,
|
|
502
501
|
getNextPageParam: (lastPage) => lastPage.pagination.nextPage,
|
|
503
502
|
getPreviousPageParam: (firstPage) => firstPage.pagination.prevPage,
|
|
504
|
-
staleTime,
|
|
505
|
-
|
|
503
|
+
staleTime: StaleTimes.infinite,
|
|
504
|
+
...options
|
|
506
505
|
});
|
|
507
506
|
const flatData = query.data?.pages.flatMap((page) => page.data) ?? [];
|
|
508
507
|
return {
|
|
@@ -513,41 +512,45 @@ var useInfiniteWooQuery = ({
|
|
|
513
512
|
};
|
|
514
513
|
|
|
515
514
|
// src/hooks/products.ts
|
|
516
|
-
var useProducts = (params) => {
|
|
515
|
+
var useProducts = (params, options) => {
|
|
517
516
|
const client = useWooCommerceClient();
|
|
518
517
|
const queryKeys = useWooCommerceQueryKeys();
|
|
519
518
|
return reactQuery.useQuery({
|
|
520
519
|
queryKey: queryKeys.products.list(params),
|
|
521
520
|
queryFn: () => client.products.list(params),
|
|
522
|
-
staleTime: StaleTimes.products
|
|
521
|
+
staleTime: StaleTimes.products,
|
|
522
|
+
...options
|
|
523
523
|
});
|
|
524
524
|
};
|
|
525
|
-
var useInfiniteProducts = (params) => {
|
|
525
|
+
var useInfiniteProducts = (params, options) => {
|
|
526
526
|
const client = useWooCommerceClient();
|
|
527
527
|
const queryKeys = useWooCommerceQueryKeys();
|
|
528
528
|
return useInfiniteWooQuery({
|
|
529
529
|
queryKey: queryKeys.products.list(params),
|
|
530
530
|
queryFn: (p) => client.products.list({ ...p, page: p.page ?? 1 }),
|
|
531
531
|
params,
|
|
532
|
-
perPage: params?.per_page ?? 10
|
|
532
|
+
perPage: params?.per_page ?? 10,
|
|
533
|
+
options
|
|
533
534
|
});
|
|
534
535
|
};
|
|
535
|
-
var useProduct = (id) => {
|
|
536
|
+
var useProduct = (id, options) => {
|
|
536
537
|
const client = useWooCommerceClient();
|
|
537
538
|
const queryKeys = useWooCommerceQueryKeys();
|
|
538
539
|
return reactQuery.useQuery({
|
|
539
540
|
queryKey: queryKeys.products.detail(id),
|
|
540
541
|
queryFn: () => client.products.get(id),
|
|
541
|
-
staleTime: StaleTimes.product
|
|
542
|
+
staleTime: StaleTimes.product,
|
|
543
|
+
...options
|
|
542
544
|
});
|
|
543
545
|
};
|
|
544
|
-
var useProductCategories = () => {
|
|
546
|
+
var useProductCategories = (options) => {
|
|
545
547
|
const client = useWooCommerceClient();
|
|
546
548
|
const queryKeys = useWooCommerceQueryKeys();
|
|
547
549
|
return reactQuery.useQuery({
|
|
548
550
|
queryKey: queryKeys.products.categories(),
|
|
549
551
|
queryFn: () => client.products.categories(),
|
|
550
|
-
staleTime: StaleTimes.categories
|
|
552
|
+
staleTime: StaleTimes.categories,
|
|
553
|
+
...options
|
|
551
554
|
});
|
|
552
555
|
};
|
|
553
556
|
var groupBy = (fn, list) => {
|
|
@@ -598,13 +601,14 @@ function createErrorEvent(type, error) {
|
|
|
598
601
|
}
|
|
599
602
|
|
|
600
603
|
// src/hooks/cart.ts
|
|
601
|
-
var useCart = () => {
|
|
604
|
+
var useCart = (options) => {
|
|
602
605
|
const client = useWooCommerceClient();
|
|
603
606
|
const queryKeys = useWooCommerceQueryKeys();
|
|
604
607
|
const query = reactQuery.useQuery({
|
|
605
608
|
queryKey: queryKeys.cart.details(),
|
|
606
609
|
queryFn: () => client.cart.get(),
|
|
607
|
-
staleTime: StaleTimes.cart
|
|
610
|
+
staleTime: StaleTimes.cart,
|
|
611
|
+
...options
|
|
608
612
|
});
|
|
609
613
|
const cart = query.data;
|
|
610
614
|
const isInCart = (productId) => {
|
|
@@ -641,7 +645,7 @@ var useAddToCart = () => {
|
|
|
641
645
|
},
|
|
642
646
|
onError: (error) => {
|
|
643
647
|
if (emitEvent) {
|
|
644
|
-
const wooError = error instanceof
|
|
648
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
645
649
|
code: "unknown_error",
|
|
646
650
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
647
651
|
statusCode: 500,
|
|
@@ -672,7 +676,7 @@ var useUpdateCartItem = () => {
|
|
|
672
676
|
},
|
|
673
677
|
onError: (error) => {
|
|
674
678
|
if (emitEvent) {
|
|
675
|
-
const wooError = error instanceof
|
|
679
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
676
680
|
code: "unknown_error",
|
|
677
681
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
678
682
|
statusCode: 500,
|
|
@@ -702,7 +706,7 @@ var useRemoveFromCart = () => {
|
|
|
702
706
|
},
|
|
703
707
|
onError: (error) => {
|
|
704
708
|
if (emitEvent) {
|
|
705
|
-
const wooError = error instanceof
|
|
709
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
706
710
|
code: "unknown_error",
|
|
707
711
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
708
712
|
statusCode: 500,
|
|
@@ -732,7 +736,7 @@ var useApplyCoupon = () => {
|
|
|
732
736
|
},
|
|
733
737
|
onError: (error) => {
|
|
734
738
|
if (emitEvent) {
|
|
735
|
-
const wooError = error instanceof
|
|
739
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
736
740
|
code: "unknown_error",
|
|
737
741
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
738
742
|
statusCode: 500,
|
|
@@ -762,7 +766,7 @@ var useRemoveCoupon = () => {
|
|
|
762
766
|
},
|
|
763
767
|
onError: (error) => {
|
|
764
768
|
if (emitEvent) {
|
|
765
|
-
const wooError = error instanceof
|
|
769
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
766
770
|
code: "unknown_error",
|
|
767
771
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
768
772
|
statusCode: 500,
|
|
@@ -792,7 +796,7 @@ var useUpdateCustomer = () => {
|
|
|
792
796
|
},
|
|
793
797
|
onError: (error) => {
|
|
794
798
|
if (emitEvent) {
|
|
795
|
-
const wooError = error instanceof
|
|
799
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
796
800
|
code: "unknown_error",
|
|
797
801
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
798
802
|
statusCode: 500,
|
|
@@ -822,7 +826,7 @@ var useSelectShippingRate = () => {
|
|
|
822
826
|
},
|
|
823
827
|
onError: (error) => {
|
|
824
828
|
if (emitEvent) {
|
|
825
|
-
const wooError = error instanceof
|
|
829
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
826
830
|
code: "unknown_error",
|
|
827
831
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
828
832
|
statusCode: 500,
|
|
@@ -835,13 +839,14 @@ var useSelectShippingRate = () => {
|
|
|
835
839
|
}
|
|
836
840
|
});
|
|
837
841
|
};
|
|
838
|
-
var useCheckout = () => {
|
|
842
|
+
var useCheckout = (options) => {
|
|
839
843
|
const client = useWooCommerceClient();
|
|
840
844
|
const queryKeys = useWooCommerceQueryKeys();
|
|
841
845
|
return reactQuery.useQuery({
|
|
842
846
|
queryKey: queryKeys.checkout.details(),
|
|
843
847
|
queryFn: () => client.checkout.get(),
|
|
844
|
-
staleTime: StaleTimes.checkout
|
|
848
|
+
staleTime: StaleTimes.checkout,
|
|
849
|
+
...options
|
|
845
850
|
});
|
|
846
851
|
};
|
|
847
852
|
var useProcessCheckout = () => {
|
|
@@ -861,7 +866,7 @@ var useProcessCheckout = () => {
|
|
|
861
866
|
},
|
|
862
867
|
onError: (error) => {
|
|
863
868
|
if (emitEvent) {
|
|
864
|
-
const wooError = error instanceof
|
|
869
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
865
870
|
code: "unknown_error",
|
|
866
871
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
867
872
|
statusCode: 500,
|
|
@@ -874,13 +879,14 @@ var useProcessCheckout = () => {
|
|
|
874
879
|
}
|
|
875
880
|
});
|
|
876
881
|
};
|
|
877
|
-
var useOrder = (input) => {
|
|
882
|
+
var useOrder = (input, options) => {
|
|
878
883
|
const client = useWooCommerceClient();
|
|
879
884
|
const queryKeys = useWooCommerceQueryKeys();
|
|
880
885
|
return reactQuery.useQuery({
|
|
881
886
|
queryKey: queryKeys.orders.detail(input.id, input.billing_email, input.key),
|
|
882
887
|
queryFn: () => client.orders.get(input),
|
|
883
|
-
staleTime: StaleTimes.orders
|
|
888
|
+
staleTime: StaleTimes.orders,
|
|
889
|
+
...options
|
|
884
890
|
});
|
|
885
891
|
};
|
|
886
892
|
|
|
@@ -1642,11 +1648,11 @@ function useCartView(options = {}) {
|
|
|
1642
1648
|
|
|
1643
1649
|
Object.defineProperty(exports, "addressSchema", {
|
|
1644
1650
|
enumerable: true,
|
|
1645
|
-
get: function () { return
|
|
1651
|
+
get: function () { return woocommerceApiClient.addressSchema; }
|
|
1646
1652
|
});
|
|
1647
1653
|
Object.defineProperty(exports, "checkoutSchema", {
|
|
1648
1654
|
enumerable: true,
|
|
1649
|
-
get: function () { return
|
|
1655
|
+
get: function () { return woocommerceApiClient.checkoutSchema; }
|
|
1650
1656
|
});
|
|
1651
1657
|
exports.DEFAULT_STORE_CONFIG = DEFAULT_STORE_CONFIG;
|
|
1652
1658
|
exports.PLACEHOLDER_IMAGE_URL = PLACEHOLDER_IMAGE_URL;
|