@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/hooks/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var reactQuery = require('@tanstack/react-query');
|
|
5
|
-
var
|
|
5
|
+
var woocommerceApiClient = require('@atomic-solutions/woocommerce-api-client');
|
|
6
6
|
|
|
7
7
|
// src/hooks/useWooCommerceClient.ts
|
|
8
8
|
var WooCommerceContext = react.createContext(null);
|
|
@@ -52,8 +52,7 @@ var useInfiniteWooQuery = ({
|
|
|
52
52
|
queryFn,
|
|
53
53
|
params,
|
|
54
54
|
perPage = 10,
|
|
55
|
-
|
|
56
|
-
enabled
|
|
55
|
+
options
|
|
57
56
|
}) => {
|
|
58
57
|
const query = reactQuery.useInfiniteQuery({
|
|
59
58
|
queryKey,
|
|
@@ -65,8 +64,8 @@ var useInfiniteWooQuery = ({
|
|
|
65
64
|
initialPageParam: 1,
|
|
66
65
|
getNextPageParam: (lastPage) => lastPage.pagination.nextPage,
|
|
67
66
|
getPreviousPageParam: (firstPage) => firstPage.pagination.prevPage,
|
|
68
|
-
staleTime,
|
|
69
|
-
|
|
67
|
+
staleTime: StaleTimes.infinite,
|
|
68
|
+
...options
|
|
70
69
|
});
|
|
71
70
|
const flatData = query.data?.pages.flatMap((page) => page.data) ?? [];
|
|
72
71
|
return {
|
|
@@ -77,41 +76,45 @@ var useInfiniteWooQuery = ({
|
|
|
77
76
|
};
|
|
78
77
|
|
|
79
78
|
// src/hooks/products.ts
|
|
80
|
-
var useProducts = (params) => {
|
|
79
|
+
var useProducts = (params, options) => {
|
|
81
80
|
const client = useWooCommerceClient();
|
|
82
81
|
const queryKeys = useWooCommerceQueryKeys();
|
|
83
82
|
return reactQuery.useQuery({
|
|
84
83
|
queryKey: queryKeys.products.list(params),
|
|
85
84
|
queryFn: () => client.products.list(params),
|
|
86
|
-
staleTime: StaleTimes.products
|
|
85
|
+
staleTime: StaleTimes.products,
|
|
86
|
+
...options
|
|
87
87
|
});
|
|
88
88
|
};
|
|
89
|
-
var useInfiniteProducts = (params) => {
|
|
89
|
+
var useInfiniteProducts = (params, options) => {
|
|
90
90
|
const client = useWooCommerceClient();
|
|
91
91
|
const queryKeys = useWooCommerceQueryKeys();
|
|
92
92
|
return useInfiniteWooQuery({
|
|
93
93
|
queryKey: queryKeys.products.list(params),
|
|
94
94
|
queryFn: (p) => client.products.list({ ...p, page: p.page ?? 1 }),
|
|
95
95
|
params,
|
|
96
|
-
perPage: params?.per_page ?? 10
|
|
96
|
+
perPage: params?.per_page ?? 10,
|
|
97
|
+
options
|
|
97
98
|
});
|
|
98
99
|
};
|
|
99
|
-
var useProduct = (id) => {
|
|
100
|
+
var useProduct = (id, options) => {
|
|
100
101
|
const client = useWooCommerceClient();
|
|
101
102
|
const queryKeys = useWooCommerceQueryKeys();
|
|
102
103
|
return reactQuery.useQuery({
|
|
103
104
|
queryKey: queryKeys.products.detail(id),
|
|
104
105
|
queryFn: () => client.products.get(id),
|
|
105
|
-
staleTime: StaleTimes.product
|
|
106
|
+
staleTime: StaleTimes.product,
|
|
107
|
+
...options
|
|
106
108
|
});
|
|
107
109
|
};
|
|
108
|
-
var useProductCategories = () => {
|
|
110
|
+
var useProductCategories = (options) => {
|
|
109
111
|
const client = useWooCommerceClient();
|
|
110
112
|
const queryKeys = useWooCommerceQueryKeys();
|
|
111
113
|
return reactQuery.useQuery({
|
|
112
114
|
queryKey: queryKeys.products.categories(),
|
|
113
115
|
queryFn: () => client.products.categories(),
|
|
114
|
-
staleTime: StaleTimes.categories
|
|
116
|
+
staleTime: StaleTimes.categories,
|
|
117
|
+
...options
|
|
115
118
|
});
|
|
116
119
|
};
|
|
117
120
|
var groupBy = (fn, list) => {
|
|
@@ -166,13 +169,14 @@ function createErrorEvent(type, error) {
|
|
|
166
169
|
}
|
|
167
170
|
|
|
168
171
|
// src/hooks/cart.ts
|
|
169
|
-
var useCart = () => {
|
|
172
|
+
var useCart = (options) => {
|
|
170
173
|
const client = useWooCommerceClient();
|
|
171
174
|
const queryKeys = useWooCommerceQueryKeys();
|
|
172
175
|
const query = reactQuery.useQuery({
|
|
173
176
|
queryKey: queryKeys.cart.details(),
|
|
174
177
|
queryFn: () => client.cart.get(),
|
|
175
|
-
staleTime: StaleTimes.cart
|
|
178
|
+
staleTime: StaleTimes.cart,
|
|
179
|
+
...options
|
|
176
180
|
});
|
|
177
181
|
const cart = query.data;
|
|
178
182
|
const isInCart = (productId) => {
|
|
@@ -209,7 +213,7 @@ var useAddToCart = () => {
|
|
|
209
213
|
},
|
|
210
214
|
onError: (error) => {
|
|
211
215
|
if (emitEvent) {
|
|
212
|
-
const wooError = error instanceof
|
|
216
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
213
217
|
code: "unknown_error",
|
|
214
218
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
215
219
|
statusCode: 500,
|
|
@@ -240,7 +244,7 @@ var useUpdateCartItem = () => {
|
|
|
240
244
|
},
|
|
241
245
|
onError: (error) => {
|
|
242
246
|
if (emitEvent) {
|
|
243
|
-
const wooError = error instanceof
|
|
247
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
244
248
|
code: "unknown_error",
|
|
245
249
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
246
250
|
statusCode: 500,
|
|
@@ -270,7 +274,7 @@ var useRemoveFromCart = () => {
|
|
|
270
274
|
},
|
|
271
275
|
onError: (error) => {
|
|
272
276
|
if (emitEvent) {
|
|
273
|
-
const wooError = error instanceof
|
|
277
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
274
278
|
code: "unknown_error",
|
|
275
279
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
276
280
|
statusCode: 500,
|
|
@@ -300,7 +304,7 @@ var useApplyCoupon = () => {
|
|
|
300
304
|
},
|
|
301
305
|
onError: (error) => {
|
|
302
306
|
if (emitEvent) {
|
|
303
|
-
const wooError = error instanceof
|
|
307
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
304
308
|
code: "unknown_error",
|
|
305
309
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
306
310
|
statusCode: 500,
|
|
@@ -330,7 +334,7 @@ var useRemoveCoupon = () => {
|
|
|
330
334
|
},
|
|
331
335
|
onError: (error) => {
|
|
332
336
|
if (emitEvent) {
|
|
333
|
-
const wooError = error instanceof
|
|
337
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
334
338
|
code: "unknown_error",
|
|
335
339
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
336
340
|
statusCode: 500,
|
|
@@ -360,7 +364,7 @@ var useUpdateCustomer = () => {
|
|
|
360
364
|
},
|
|
361
365
|
onError: (error) => {
|
|
362
366
|
if (emitEvent) {
|
|
363
|
-
const wooError = error instanceof
|
|
367
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
364
368
|
code: "unknown_error",
|
|
365
369
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
366
370
|
statusCode: 500,
|
|
@@ -390,7 +394,7 @@ var useSelectShippingRate = () => {
|
|
|
390
394
|
},
|
|
391
395
|
onError: (error) => {
|
|
392
396
|
if (emitEvent) {
|
|
393
|
-
const wooError = error instanceof
|
|
397
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
394
398
|
code: "unknown_error",
|
|
395
399
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
396
400
|
statusCode: 500,
|
|
@@ -403,13 +407,14 @@ var useSelectShippingRate = () => {
|
|
|
403
407
|
}
|
|
404
408
|
});
|
|
405
409
|
};
|
|
406
|
-
var useCheckout = () => {
|
|
410
|
+
var useCheckout = (options) => {
|
|
407
411
|
const client = useWooCommerceClient();
|
|
408
412
|
const queryKeys = useWooCommerceQueryKeys();
|
|
409
413
|
return reactQuery.useQuery({
|
|
410
414
|
queryKey: queryKeys.checkout.details(),
|
|
411
415
|
queryFn: () => client.checkout.get(),
|
|
412
|
-
staleTime: StaleTimes.checkout
|
|
416
|
+
staleTime: StaleTimes.checkout,
|
|
417
|
+
...options
|
|
413
418
|
});
|
|
414
419
|
};
|
|
415
420
|
var useProcessCheckout = () => {
|
|
@@ -429,7 +434,7 @@ var useProcessCheckout = () => {
|
|
|
429
434
|
},
|
|
430
435
|
onError: (error) => {
|
|
431
436
|
if (emitEvent) {
|
|
432
|
-
const wooError = error instanceof
|
|
437
|
+
const wooError = error instanceof woocommerceApiClient.WooCommerceApiError ? error : new woocommerceApiClient.WooCommerceApiError({
|
|
433
438
|
code: "unknown_error",
|
|
434
439
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
435
440
|
statusCode: 500,
|
|
@@ -442,13 +447,14 @@ var useProcessCheckout = () => {
|
|
|
442
447
|
}
|
|
443
448
|
});
|
|
444
449
|
};
|
|
445
|
-
var useOrder = (input) => {
|
|
450
|
+
var useOrder = (input, options) => {
|
|
446
451
|
const client = useWooCommerceClient();
|
|
447
452
|
const queryKeys = useWooCommerceQueryKeys();
|
|
448
453
|
return reactQuery.useQuery({
|
|
449
454
|
queryKey: queryKeys.orders.detail(input.id, input.billing_email, input.key),
|
|
450
455
|
queryFn: () => client.orders.get(input),
|
|
451
|
-
staleTime: StaleTimes.orders
|
|
456
|
+
staleTime: StaleTimes.orders,
|
|
457
|
+
...options
|
|
452
458
|
});
|
|
453
459
|
};
|
|
454
460
|
|