@atomic-solutions/woocommerce-api-client 0.1.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/LICENSE +21 -0
- package/README.md +124 -0
- package/dist/client/index.d.mts +9 -0
- package/dist/client/index.d.ts +9 -0
- package/dist/client/index.js +1461 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/index.mjs +1455 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/http/index.d.mts +11 -0
- package/dist/http/index.d.ts +11 -0
- package/dist/http/index.js +638 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/index.mjs +631 -0
- package/dist/http/index.mjs.map +1 -0
- package/dist/index.d.mts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +2152 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2105 -0
- package/dist/index.mjs.map +1 -0
- package/dist/pagination.schema-CdjWGZJr.d.mts +190 -0
- package/dist/pagination.schema-CdjWGZJr.d.ts +190 -0
- package/dist/products-Cxl54crz.d.mts +3412 -0
- package/dist/products-Cxl54crz.d.ts +3412 -0
- package/dist/schemas/admin-api/index.d.mts +5340 -0
- package/dist/schemas/admin-api/index.d.ts +5340 -0
- package/dist/schemas/admin-api/index.js +584 -0
- package/dist/schemas/admin-api/index.js.map +1 -0
- package/dist/schemas/admin-api/index.mjs +545 -0
- package/dist/schemas/admin-api/index.mjs.map +1 -0
- package/dist/schemas/index.d.mts +4 -0
- package/dist/schemas/index.d.ts +4 -0
- package/dist/schemas/index.js +887 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/index.mjs +844 -0
- package/dist/schemas/index.mjs.map +1 -0
- package/dist/schemas/store-api/index.d.mts +1076 -0
- package/dist/schemas/store-api/index.d.ts +1076 -0
- package/dist/schemas/store-api/index.js +887 -0
- package/dist/schemas/store-api/index.js.map +1 -0
- package/dist/schemas/store-api/index.mjs +844 -0
- package/dist/schemas/store-api/index.mjs.map +1 -0
- package/dist/types-B-zy1xrP.d.mts +183 -0
- package/dist/types-qKWtrw7A.d.ts +183 -0
- package/dist/utils/index.d.mts +17 -0
- package/dist/utils/index.d.ts +17 -0
- package/dist/utils/index.js +316 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +308 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +117 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Atomic Solutions
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# @atomic-solutions/woocommerce-utils
|
|
2
|
+
|
|
3
|
+
> Type-safe WooCommerce Store API client with React Query integration
|
|
4
|
+
|
|
5
|
+
**Status:** 🚧 Work in Progress
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- ✅ **Type-Safe** - Full TypeScript support with Zod validation
|
|
10
|
+
- ✅ **WooCommerce Store API v1** - Designed for headless/mobile apps
|
|
11
|
+
- ✅ **React Query Integration** - Optimized caching and state management
|
|
12
|
+
- ✅ **Cart Session Management** - Automatic nonce/cart-token handling
|
|
13
|
+
- ✅ **JWT Authentication** - Secure user authentication support
|
|
14
|
+
- ✅ **Error Handling** - Built-in error classes with optional error reporter injection
|
|
15
|
+
- ✅ **Tree-Shakeable** - Sub-path exports for minimal bundle size
|
|
16
|
+
- ✅ **Platform Agnostic** - Works in React Native, Next.js, and web
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
yarn add @atomic-solutions/woocommerce-utils
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Peer Dependencies
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
yarn add axios @tanstack/react-query zod
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### 1. Create Client
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { createClient } from '@atomic-solutions/woocommerce-utils';
|
|
36
|
+
|
|
37
|
+
// For React Native
|
|
38
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
39
|
+
|
|
40
|
+
const cartHeadersAdapter = {
|
|
41
|
+
get: async () => {
|
|
42
|
+
const nonce = await AsyncStorage.getItem('woo_nonce');
|
|
43
|
+
const cartToken = await AsyncStorage.getItem('woo_cart_token');
|
|
44
|
+
return { nonce, cartToken };
|
|
45
|
+
},
|
|
46
|
+
save: async ({ nonce, cartToken }) => {
|
|
47
|
+
if (nonce) await AsyncStorage.setItem('woo_nonce', nonce);
|
|
48
|
+
if (cartToken) await AsyncStorage.setItem('woo_cart_token', cartToken);
|
|
49
|
+
},
|
|
50
|
+
clear: async () => {
|
|
51
|
+
await AsyncStorage.removeItem('woo_nonce');
|
|
52
|
+
await AsyncStorage.removeItem('woo_cart_token');
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const client = createClient({
|
|
57
|
+
baseURL: 'https://your-store.com/wp-json',
|
|
58
|
+
cartHeaders: cartHeadersAdapter,
|
|
59
|
+
debug: process.env.DEBUG === 'true',
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 2. Setup Provider
|
|
64
|
+
|
|
65
|
+
**Important:** You must provide your own `QueryClientProvider` from `@tanstack/react-query`.
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
69
|
+
import { WooCommerceProvider } from '@atomic-solutions/woocommerce-utils';
|
|
70
|
+
|
|
71
|
+
const queryClient = new QueryClient();
|
|
72
|
+
|
|
73
|
+
function App() {
|
|
74
|
+
return (
|
|
75
|
+
<QueryClientProvider client={queryClient}>
|
|
76
|
+
<WooCommerceProvider client={client}>
|
|
77
|
+
<YourApp />
|
|
78
|
+
</WooCommerceProvider>
|
|
79
|
+
</QueryClientProvider>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 3. Use Hooks
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import { useProducts, useAddToCart } from '@atomic-solutions/woocommerce-utils/hooks';
|
|
88
|
+
|
|
89
|
+
function ProductList() {
|
|
90
|
+
const { data: products, isLoading } = useProducts({
|
|
91
|
+
category: 'electronics',
|
|
92
|
+
per_page: 20,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const addToCart = useAddToCart();
|
|
96
|
+
|
|
97
|
+
if (isLoading) return <Loading />;
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<FlatList
|
|
101
|
+
data={products}
|
|
102
|
+
renderItem={({ item }) => (
|
|
103
|
+
<ProductCard
|
|
104
|
+
product={item}
|
|
105
|
+
onAddToCart={() =>
|
|
106
|
+
addToCart.mutate({
|
|
107
|
+
id: item.id,
|
|
108
|
+
quantity: 1,
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
/>
|
|
112
|
+
)}
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Documentation
|
|
119
|
+
|
|
120
|
+
Coming soon...
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
MIT © Atomic Solutions
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { h as WooCommerceConfig, g as WooCommerceClient } from '../types-B-zy1xrP.mjs';
|
|
2
|
+
export { C as CartAPI, b as CartHeadersAdapter, c as CheckoutAPI, J as JwtTokenAdapter, O as OrdersAPI, d as ProductsAPI } from '../types-B-zy1xrP.mjs';
|
|
3
|
+
import 'axios';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import '../products-Cxl54crz.mjs';
|
|
6
|
+
|
|
7
|
+
declare const createClient: (config: WooCommerceConfig) => WooCommerceClient;
|
|
8
|
+
|
|
9
|
+
export { WooCommerceClient, WooCommerceConfig, createClient };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { h as WooCommerceConfig, g as WooCommerceClient } from '../types-qKWtrw7A.js';
|
|
2
|
+
export { C as CartAPI, b as CartHeadersAdapter, c as CheckoutAPI, J as JwtTokenAdapter, O as OrdersAPI, d as ProductsAPI } from '../types-qKWtrw7A.js';
|
|
3
|
+
import 'axios';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import '../products-Cxl54crz.js';
|
|
6
|
+
|
|
7
|
+
declare const createClient: (config: WooCommerceConfig) => WooCommerceClient;
|
|
8
|
+
|
|
9
|
+
export { WooCommerceClient, WooCommerceConfig, createClient };
|